mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-07-10 04:15:51 +00:00
improve work with filters for custom scripts
implement new line filters for widget text fix bug with html parsing implement key sorting in combo boxes
This commit is contained in:
@ -130,11 +130,11 @@ QString AWActions::getAboutText(const QString type)
|
||||
}
|
||||
|
||||
|
||||
QMap<QString, QVariant> AWActions::getFont(const QMap<QString, QVariant> defaultFont)
|
||||
QVariantMap AWActions::getFont(const QVariantMap defaultFont)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
QMap<QString, QVariant> fontMap;
|
||||
QVariantMap fontMap;
|
||||
CFont defaultCFont = CFont(defaultFont[QString("family")].toString(),
|
||||
defaultFont[QString("size")].toInt(),
|
||||
400, false, defaultFont[QString("color")].toString());
|
||||
@ -148,14 +148,14 @@ QMap<QString, QVariant> AWActions::getFont(const QMap<QString, QVariant> default
|
||||
}
|
||||
|
||||
|
||||
QMap<QString, QVariant> AWActions::readDataEngineConfiguration()
|
||||
QVariantMap AWActions::readDataEngineConfiguration()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
QString fileName = QStandardPaths::locate(QStandardPaths::ConfigLocation, QString("plasma-dataengine-extsysmon.conf"));
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Configuration file" << fileName;
|
||||
QSettings settings(fileName, QSettings::IniFormat);
|
||||
QMap<QString, QVariant> configuration;
|
||||
QVariantMap configuration;
|
||||
|
||||
settings.beginGroup(QString("Configuration"));
|
||||
configuration[QString("ACPIPATH")] = settings.value(QString("ACPIPATH"), QString("/sys/class/power_supply/"));
|
||||
@ -172,7 +172,7 @@ QMap<QString, QVariant> AWActions::readDataEngineConfiguration()
|
||||
}
|
||||
|
||||
|
||||
void AWActions::writeDataEngineConfiguration(const QMap<QString, QVariant> configuration)
|
||||
void AWActions::writeDataEngineConfiguration(const QVariantMap configuration)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
|
@ -40,10 +40,10 @@ public:
|
||||
Q_INVOKABLE void showReadme();
|
||||
// configuration slots
|
||||
Q_INVOKABLE QString getAboutText(const QString type = QString("header"));
|
||||
Q_INVOKABLE QMap<QString, QVariant> getFont(const QMap<QString, QVariant> defaultFont);
|
||||
Q_INVOKABLE QVariantMap getFont(const QVariantMap defaultFont);
|
||||
// dataengine
|
||||
Q_INVOKABLE QMap<QString, QVariant> readDataEngineConfiguration();
|
||||
Q_INVOKABLE void writeDataEngineConfiguration(const QMap<QString, QVariant> configuration);
|
||||
Q_INVOKABLE QVariantMap readDataEngineConfiguration();
|
||||
Q_INVOKABLE void writeDataEngineConfiguration(const QVariantMap configuration);
|
||||
|
||||
public slots:
|
||||
Q_INVOKABLE static void sendNotification(const QString eventId, const QString message,
|
||||
|
@ -86,9 +86,7 @@ AWKeys::~AWKeys()
|
||||
}
|
||||
|
||||
|
||||
void AWKeys::initKeys(const QString currentPattern,
|
||||
const QMap<QString, QVariant> tooltipParams,
|
||||
const bool popup)
|
||||
void AWKeys::initKeys(const QString currentPattern)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
@ -100,7 +98,6 @@ void AWKeys::initKeys(const QString currentPattern,
|
||||
keys.clear();
|
||||
foundBars.clear();
|
||||
foundKeys.clear();
|
||||
if (toolTip != nullptr) delete toolTip;
|
||||
|
||||
// init
|
||||
pattern = currentPattern;
|
||||
@ -113,12 +110,34 @@ void AWKeys::initKeys(const QString currentPattern,
|
||||
addKeyToCache(QString("Network"));
|
||||
loadKeysFromCache();
|
||||
reinitKeys();
|
||||
}
|
||||
|
||||
|
||||
void AWKeys::initTooltip(const QVariantMap tooltipParams)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
if (toolTip != nullptr) delete toolTip;
|
||||
toolTip = new AWToolTip(this, tooltipParams);
|
||||
}
|
||||
|
||||
|
||||
void AWKeys::setPopupEnabled(const bool popup)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
enablePopup = popup;
|
||||
}
|
||||
|
||||
|
||||
void AWKeys::setWrapNewLines(const bool wrap)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
wrapNewLines = wrap;
|
||||
}
|
||||
|
||||
|
||||
bool AWKeys::isDebugEnabled()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
@ -135,11 +154,12 @@ QString AWKeys::parsePattern()
|
||||
QString parsed = pattern;
|
||||
parsed.replace(QString("$$"), QString("$\\$\\"));
|
||||
for (int i=0; i<foundKeys.count(); i++)
|
||||
parsed.replace(QString("$%1").arg(foundKeys[i]), valueByKey(foundKeys[i]));
|
||||
parsed.replace(QString(" "), QString(" "));
|
||||
parsed.replace(QString("$%1").arg(foundKeys[i]), htmlValue(foundKeys[i]));
|
||||
for (int i=0; i<foundBars.count(); i++)
|
||||
parsed.replace(QString("$%1").arg(foundBars[i]), getItemByTag(foundBars[i])->image(valueByKey(foundBars[i]).toFloat()));
|
||||
parsed.replace(QString("$\\$\\"), QString("$$"));
|
||||
// wrap new lines if required
|
||||
if (wrapNewLines) parsed.replace(QString("\n"), QString("<br>"));
|
||||
|
||||
return parsed;
|
||||
}
|
||||
@ -148,6 +168,7 @@ QString AWKeys::parsePattern()
|
||||
QString AWKeys::toolTipImage()
|
||||
{
|
||||
if(debug) qDebug() << PDEBUG;
|
||||
if (toolTip == nullptr) return QString("");
|
||||
|
||||
if (keys.isEmpty()) return QString();
|
||||
|
||||
@ -163,6 +184,7 @@ QString AWKeys::toolTipImage()
|
||||
QSize AWKeys::toolTipSize()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (toolTip == nullptr) return QSize();
|
||||
|
||||
return toolTip->getSize();
|
||||
}
|
||||
@ -194,7 +216,7 @@ void AWKeys::addDevice(const QString source)
|
||||
}
|
||||
|
||||
|
||||
QStringList AWKeys::dictKeys()
|
||||
QStringList AWKeys::dictKeys(const bool sorted)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
@ -312,6 +334,9 @@ QStringList AWKeys::dictKeys()
|
||||
for (int i=graphicalItemsKeys.count()-1; i>=0; i--)
|
||||
allKeys.append(graphicalItemsKeys[i]);
|
||||
|
||||
// sort if required
|
||||
if (sorted) allKeys.sort();
|
||||
|
||||
return allKeys;
|
||||
}
|
||||
|
||||
@ -329,9 +354,8 @@ QStringList AWKeys::getHddDevices()
|
||||
}
|
||||
|
||||
|
||||
bool AWKeys::setDataBySource(const QString sourceName,
|
||||
const QMap<QString, QVariant> data,
|
||||
const QMap<QString, QVariant> params)
|
||||
bool AWKeys::setDataBySource(const QString sourceName, const QVariantMap data,
|
||||
const QVariantMap params)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Source" << sourceName;
|
||||
@ -373,7 +397,9 @@ bool AWKeys::setDataBySource(const QString sourceName,
|
||||
values[QString("ac")] = params[QString("acOffline")].toString();
|
||||
} else {
|
||||
values[data.keys()[i]] = QString("%1").arg(data[data.keys()[i]].toFloat(), 3, 'f', 0);
|
||||
toolTip->setData(QString("batTooltip"), data[data.keys()[i]].toFloat(), data[QString("ac")].toBool());
|
||||
if (toolTip != nullptr) toolTip->setData(QString("batTooltip"),
|
||||
data[data.keys()[i]].toFloat(),
|
||||
data[QString("ac")].toBool());
|
||||
}
|
||||
}
|
||||
} else if (sourceName == QString("cpu/system/TotalLoad")) {
|
||||
@ -383,7 +409,8 @@ bool AWKeys::setDataBySource(const QString sourceName,
|
||||
AWActions::sendNotification(QString("event"), i18n("High CPU load"), enablePopup);
|
||||
// value
|
||||
values[QString("cpu")] = QString("%1").arg(data[QString("value")].toFloat(), 5, 'f', 1);
|
||||
toolTip->setData(QString("cpuTooltip"), data[QString("value")].toFloat());
|
||||
if (toolTip != nullptr) toolTip->setData(QString("cpuTooltip"),
|
||||
data[QString("value")].toFloat());
|
||||
} else if (sourceName.contains(cpuRegExp)) {
|
||||
// cpus
|
||||
QString number = sourceName;
|
||||
@ -392,7 +419,8 @@ bool AWKeys::setDataBySource(const QString sourceName,
|
||||
} else if (sourceName == QString("cpu/system/AverageClock")) {
|
||||
// cpucl
|
||||
values[QString("cpucl")] = QString("%1").arg(data[QString("value")].toFloat(), 4, 'f', 0);
|
||||
toolTip->setData(QString("cpuclTooltip"), data[QString("value")].toFloat());
|
||||
if (toolTip != nullptr) toolTip->setData(QString("cpuclTooltip"),
|
||||
data[QString("value")].toFloat());
|
||||
} else if (sourceName.contains(cpuclRegExp)) {
|
||||
// cpucls
|
||||
QString number = sourceName;
|
||||
@ -511,7 +539,8 @@ bool AWKeys::setDataBySource(const QString sourceName,
|
||||
AWActions::sendNotification(QString("event"), i18n("High memory usage"), enablePopup);
|
||||
// value
|
||||
values[QString("mem")] = QString("%1").arg(value, 5, 'f', 1);
|
||||
toolTip->setData(QString("memTooltip"), values[QString("mem")].toFloat());
|
||||
if (toolTip != nullptr) toolTip->setData(QString("memTooltip"),
|
||||
values[QString("mem")].toFloat());
|
||||
} else if (sourceName == QString("netdev")) {
|
||||
// network device
|
||||
// notification
|
||||
@ -533,7 +562,8 @@ bool AWKeys::setDataBySource(const QString sourceName,
|
||||
}
|
||||
if (device == networkDevice()) {
|
||||
values[QString("down")] = QString("%1").arg(data[QString("value")].toFloat(), 4, 'f', 0);
|
||||
toolTip->setData(QString("downTooltip"), data[QString("value")].toFloat());
|
||||
if (toolTip != nullptr) toolTip->setData(QString("downTooltip"),
|
||||
data[QString("value")].toFloat());
|
||||
}
|
||||
} else if (sourceName.contains(netTransRegExp)) {
|
||||
// upload speed
|
||||
@ -547,7 +577,8 @@ bool AWKeys::setDataBySource(const QString sourceName,
|
||||
}
|
||||
if (device == networkDevice()) {
|
||||
values[QString("up")] = QString("%1").arg(data[QString("value")].toFloat(), 4, 'f', 0);
|
||||
toolTip->setData(QString("upTooltip"), data[QString("value")].toFloat());
|
||||
if (toolTip != nullptr) toolTip->setData(QString("upTooltip"),
|
||||
data[QString("value")].toFloat());
|
||||
}
|
||||
} else if (sourceName == QString("pkg")) {
|
||||
// package manager
|
||||
@ -589,7 +620,8 @@ bool AWKeys::setDataBySource(const QString sourceName,
|
||||
AWActions::sendNotification(QString("event"), i18n("Swap is used"), enablePopup);
|
||||
// value
|
||||
values[QString("swap")] = QString("%1").arg(value, 5, 'f', 1);
|
||||
toolTip->setData(QString("swapTooltip"), values[QString("swap")].toFloat());
|
||||
if (toolTip != nullptr) toolTip->setData(QString("swapTooltip"),
|
||||
values[QString("swap")].toFloat());
|
||||
} else if (sourceName.contains(tempRegExp)) {
|
||||
// temperature devices
|
||||
if (data[QString("units")].toString() == QString("rpm")) {
|
||||
@ -646,8 +678,8 @@ void AWKeys::graphicalValueByKey()
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
bool ok;
|
||||
QString tag = QInputDialog::getItem(0, i18n("Select tag"),
|
||||
i18n("Tag"), keys, 0, false, &ok);
|
||||
QString tag = QInputDialog::getItem(0, i18n("Select tag"), i18n("Tag"),
|
||||
dictKeys(true), 0, false, &ok);
|
||||
|
||||
if ((!ok) || (tag.isEmpty())) return;
|
||||
QString message = i18n("Tag: %1", tag);
|
||||
@ -1247,7 +1279,7 @@ void AWKeys::addKeyToCache(const QString type, const QString key)
|
||||
}
|
||||
|
||||
|
||||
bool AWKeys::checkKeys(const QMap<QString, QVariant> data)
|
||||
bool AWKeys::checkKeys(const QVariantMap data)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Data" << data;
|
||||
@ -1256,6 +1288,18 @@ bool AWKeys::checkKeys(const QMap<QString, QVariant> data)
|
||||
}
|
||||
|
||||
|
||||
QString AWKeys::htmlValue(QString key)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Requested key" << key;
|
||||
|
||||
QString value = values[key];
|
||||
if (!key.startsWith(QString("custom")))
|
||||
value.replace(QString(" "), QString(" "));
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
QString AWKeys::networkDevice()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
@ -51,20 +51,20 @@ public:
|
||||
AWKeys(QObject *parent = nullptr);
|
||||
~AWKeys();
|
||||
|
||||
Q_INVOKABLE void initKeys(const QString currentPattern,
|
||||
const QMap<QString, QVariant> tooltipParams,
|
||||
const bool popup = false);
|
||||
Q_INVOKABLE void initKeys(const QString currentPattern);
|
||||
Q_INVOKABLE void initTooltip(const QVariantMap tooltipParams);
|
||||
Q_INVOKABLE void setPopupEnabled(const bool popup = false);
|
||||
Q_INVOKABLE void setWrapNewLines(const bool wrap = false);
|
||||
Q_INVOKABLE bool isDebugEnabled();
|
||||
Q_INVOKABLE QString parsePattern();
|
||||
Q_INVOKABLE QString toolTipImage();
|
||||
Q_INVOKABLE QSize toolTipSize();
|
||||
// keys
|
||||
Q_INVOKABLE void addDevice(const QString source);
|
||||
Q_INVOKABLE QStringList dictKeys();
|
||||
Q_INVOKABLE QStringList dictKeys(const bool sorted = false);
|
||||
Q_INVOKABLE QStringList getHddDevices();
|
||||
Q_INVOKABLE bool setDataBySource(const QString sourceName,
|
||||
const QMap<QString, QVariant> data,
|
||||
const QMap<QString, QVariant> params);
|
||||
Q_INVOKABLE bool setDataBySource(const QString sourceName, const QVariantMap data,
|
||||
const QVariantMap params);
|
||||
// values
|
||||
Q_INVOKABLE void graphicalValueByKey();
|
||||
Q_INVOKABLE QString infoByKey(QString key);
|
||||
@ -85,7 +85,8 @@ private slots:
|
||||
private:
|
||||
// methods
|
||||
void addKeyToCache(const QString type, const QString key = QString(""));
|
||||
bool checkKeys(const QMap<QString, QVariant> data);
|
||||
bool checkKeys(const QVariantMap data);
|
||||
QString htmlValue(QString key);
|
||||
QString networkDevice();
|
||||
int numberCpus();
|
||||
float temperature(const float temp, const QString units);
|
||||
@ -111,6 +112,7 @@ private:
|
||||
// variables
|
||||
bool debug = false;
|
||||
bool enablePopup = false;
|
||||
bool wrapNewLines = false;
|
||||
QList<GraphicalItem *> graphicalItems;
|
||||
QList<ExtQuotes *> extQuotes;
|
||||
QList<ExtScript *> extScripts;
|
||||
|
@ -24,8 +24,7 @@
|
||||
#include <pdebug/pdebug.h>
|
||||
|
||||
|
||||
AWToolTip::AWToolTip(QObject *parent,
|
||||
QMap<QString, QVariant> settings)
|
||||
AWToolTip::AWToolTip(QObject *parent, QVariantMap settings)
|
||||
: QObject(parent),
|
||||
configuration(settings)
|
||||
{
|
||||
|
@ -32,8 +32,7 @@ class AWToolTip : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
AWToolTip(QObject *parent = nullptr,
|
||||
QMap<QString, QVariant> settings = QMap<QString, QVariant>());
|
||||
AWToolTip(QObject *parent = nullptr, QVariantMap settings = QVariantMap());
|
||||
~AWToolTip();
|
||||
|
||||
QSize getSize();
|
||||
@ -48,7 +47,7 @@ private:
|
||||
// variables
|
||||
bool debug = false;
|
||||
int counts = 0;
|
||||
QMap<QString, QVariant> configuration;
|
||||
QVariantMap configuration;
|
||||
QMap<QString, float> boundaries;
|
||||
QMap<QString, QList<float>> data;
|
||||
QStringList requiredKeys;
|
||||
|
Reference in New Issue
Block a user