From 95b6b2d9e93357345b5e21a0e7ed13248a2a0d13 Mon Sep 17 00:00:00 2001 From: arcan1s Date: Tue, 15 Sep 2015 00:02:59 +0300 Subject: [PATCH] * add preview function * more comments inside * variables renaming * unite several lists to one hash * add build_future definition checking to source code --- .../package/contents/ui/widget.qml | 38 ++- sources/awesome-widget/plugin/awactions.cpp | 16 +- sources/awesome-widget/plugin/awactions.h | 4 +- .../plugin/awdataaggregator.cpp | 41 ++- .../awesome-widget/plugin/awdataaggregator.h | 10 +- sources/awesome-widget/plugin/awkeys.cpp | 233 +++++++----------- sources/awesome-widget/plugin/awkeys.h | 16 +- .../plugin/awkeysaggregator.cpp | 6 +- .../awesome-widget/plugin/awkeysaggregator.h | 2 +- sources/translations/awesome-widgets.pot | 5 +- sources/translations/en.po | 7 +- sources/translations/es.po | 5 +- sources/translations/fr.po | 5 +- sources/translations/nl.po | 5 +- sources/translations/pt_BR.po | 5 +- sources/translations/ru.po | 7 +- sources/translations/uk.po | 5 +- sources/translations/zh.po | 5 +- 18 files changed, 204 insertions(+), 211 deletions(-) diff --git a/sources/awesome-widget/package/contents/ui/widget.qml b/sources/awesome-widget/package/contents/ui/widget.qml index 198eb29..29a5b1f 100644 --- a/sources/awesome-widget/package/contents/ui/widget.qml +++ b/sources/awesome-widget/package/contents/ui/widget.qml @@ -17,6 +17,7 @@ import QtQuick 2.0 import QtQuick.Controls 1.3 as QtControls +import QtQuick.Dialogs 1.2 as QtDialogs import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.private.awesomewidget 1.0 @@ -42,6 +43,7 @@ Item { property alias cfg_text: textPattern.text signal dropSource(string sourceName) + signal needTextUpdate(string newText) Column { @@ -197,7 +199,7 @@ Item { height: implicitHeight width: parent.width QtControls.ComboBox { - width: (parent.width - addTagButton.width - showValueButton.width - addLambdaButton.width) / 2 + width: parent.width * 1 / 5 textRole: "label" model: [ { @@ -262,10 +264,10 @@ Item { } QtControls.ComboBox { id: tags - width: (parent.width - addTagButton.width - showValueButton.width - addLambdaButton.width) / 2 + width: parent.width * 1 / 5 } QtControls.Button { - id: addTagButton + width: parent.width * 1 / 5 text: i18n("Add") onClicked: { @@ -278,7 +280,7 @@ Item { } } QtControls.Button { - id: showValueButton + width: parent.width * 1 / 5 text: i18n("Show value") onClicked: { @@ -293,7 +295,7 @@ Item { } } QtControls.Button { - id: addLambdaButton + width: parent.width * 1 / 5 text: i18n("Add lambda") onClicked: { @@ -310,10 +312,18 @@ Item { height: implicitHeight width: parent.width QtControls.Button { - width: parent.width + width: parent.width * 3 / 5 text: i18n("Edit bars") onClicked: awKeys.editItem("graphicalitem") } + QtControls.Button { + width: parent.width * 2 / 5 + text: i18n("Preview") + onClicked: { + awKeys.initKeys(textPattern.text) + awKeys.needToBeUpdated() + } + } } QtControls.TextArea { @@ -325,6 +335,12 @@ Item { } } + QtDialogs.MessageDialog { + id: compiledText + modality: Qt.NonModal + title: i18n("Preview") + } + // we need to initializate DataEngines here too // because we need to get keys and values PlasmaCore.DataSource { @@ -346,6 +362,8 @@ Item { interval: 5000 onNewData: { + // even after a disconnect it is possible that we'll receive an update + if (sourceName == "update") return if (debug) console.debug("Update source", sourceName) awKeys.dataUpdateReceived(sourceName, data) } @@ -369,6 +387,7 @@ Item { // drop "update" source which does not required by this page extsysmonDE.disconnectSource("update") awKeys.dropSourceFromDataengine.connect(dropSource) + awKeys.needTextToBeUpdated.connect(needTextUpdate) // init submodule awKeys.initKeys(plasmoid.configuration.text) awKeys.setAggregatorProperty("acOffline", plasmoid.configuration.acOffline) @@ -385,4 +404,11 @@ Item { systemmonitorDE.disconnectSource(sourceName) } + + onNeedTextUpdate: { + if (debug) console.debug() + + compiledText.text = newText.replace(/ /g, " ") + compiledText.open() + } } diff --git a/sources/awesome-widget/plugin/awactions.cpp b/sources/awesome-widget/plugin/awactions.cpp index d21e8aa..1388b93 100644 --- a/sources/awesome-widget/plugin/awactions.cpp +++ b/sources/awesome-widget/plugin/awactions.cpp @@ -55,7 +55,10 @@ AWActions::~AWActions() void AWActions::checkUpdates(const bool showAnyway) { qCDebug(LOG_AW); + qCDebug(LOG_AW) << "Show anyway" << showAnyway; + // showAnyway options requires to show message if no updates found on direct + // request. In case of automatic check no message will be shown QNetworkAccessManager *manager = new QNetworkAccessManager(this); connect(manager, &QNetworkAccessManager::finished, [showAnyway, this](QNetworkReply *reply) { @@ -77,6 +80,7 @@ bool AWActions::dropCache() const } +// HACK: since QML could not use QLoggingCategory I need this hack bool AWActions::isDebugEnabled() const { qCDebug(LOG_AW); @@ -85,18 +89,18 @@ bool AWActions::isDebugEnabled() const } -void AWActions::runCmd(const QString cmd) const +bool AWActions::runCmd(const QString cmd) const { qCDebug(LOG_AW); qCDebug(LOG_AW) << "Cmd" << cmd; - QProcess command; sendNotification(QString("Info"), i18n("Run %1", cmd)); - command.startDetached(cmd); + return QProcess::startDetached(cmd); } +// HACK: this method uses variable from version.h void AWActions::showReadme() const { qCDebug(LOG_AW); @@ -105,6 +109,7 @@ void AWActions::showReadme() const } +// HACK: this method uses variables from version.h QString AWActions::getAboutText(const QString type) const { qCDebug(LOG_AW); @@ -184,6 +189,8 @@ QVariantMap AWActions::readDataEngineConfiguration() const configuration[QString("PLAYERSYMBOLS")] = settings.value(QString("PLAYERSYMBOLS"), QString("10")); settings.endGroup(); + qCInfo(LOG_AW) << "Configuration" << configuration; + return configuration; } @@ -212,6 +219,7 @@ void AWActions::writeDataEngineConfiguration(const QVariantMap configuration) co } +// to avoid additional object definition this method is static void AWActions::sendNotification(const QString eventId, const QString message) { qCDebug(LOG_AW); @@ -259,6 +267,7 @@ void AWActions::versionReplyRecieved(QNetworkReply *reply, const bool showAnyway qCDebug(LOG_AW); qCDebug(LOG_AW) << "Return code" << reply->error(); qCDebug(LOG_AW) << "Reply error message" << reply->errorString(); + qCDebug(LOG_AW) << "Show anyway" << showAnyway; QJsonParseError error; QJsonDocument jsonDoc = QJsonDocument::fromJson(reply->readAll(), &error); @@ -275,6 +284,7 @@ void AWActions::versionReplyRecieved(QNetworkReply *reply, const bool showAnyway version.remove(QString("V.")); qCInfo(LOG_AW) << "Found version" << version; + // FIXME: possible there is a better way to check versions int old_major = QString(VERSION).split(QChar('.')).at(0).toInt(); int old_minor = QString(VERSION).split(QChar('.')).at(1).toInt(); int old_patch = QString(VERSION).split(QChar('.')).at(2).toInt(); diff --git a/sources/awesome-widget/plugin/awactions.h b/sources/awesome-widget/plugin/awactions.h index b60eee3..92cb420 100644 --- a/sources/awesome-widget/plugin/awactions.h +++ b/sources/awesome-widget/plugin/awactions.h @@ -36,7 +36,7 @@ public: Q_INVOKABLE void checkUpdates(const bool showAnyway = false); Q_INVOKABLE bool dropCache() const; Q_INVOKABLE bool isDebugEnabled() const; - Q_INVOKABLE void runCmd(const QString cmd = QString("/usr/bin/true")) const; + Q_INVOKABLE bool runCmd(const QString cmd = QString("/usr/bin/true")) const; Q_INVOKABLE void showReadme() const; // configuration slots Q_INVOKABLE QString getAboutText(const QString type = QString("header")) const; @@ -52,8 +52,6 @@ private slots: void showInfo(const QString version) const; void showUpdates(const QString version) const; void versionReplyRecieved(QNetworkReply *reply, const bool showAnyway) const; - -private: }; diff --git a/sources/awesome-widget/plugin/awdataaggregator.cpp b/sources/awesome-widget/plugin/awdataaggregator.cpp index e517391..11d0079 100644 --- a/sources/awesome-widget/plugin/awdataaggregator.cpp +++ b/sources/awesome-widget/plugin/awdataaggregator.cpp @@ -34,8 +34,8 @@ AWDataAggregator::AWDataAggregator(QObject *parent) initScene(); - connect(this, SIGNAL(updateData(QHash)), - this, SLOT(dataUpdate(QHash))); + connect(this, SIGNAL(const updateData(QHash)), + this, SLOT(const dataUpdate(QHash))); } @@ -56,14 +56,6 @@ QList AWDataAggregator::getData(const QString key) const } -QSize AWDataAggregator::getTooltipSize() const -{ - qCDebug(LOG_AW); - - return size; -} - - QString AWDataAggregator::htmlImage(const QPixmap source) const { qCDebug(LOG_AW); @@ -82,9 +74,10 @@ void AWDataAggregator::setParameters(QVariantMap settings) qCDebug(LOG_AW); qCDebug(LOG_AW) << "Settings" << settings; + // cast from QVariantMap to QVariantHash without data lost configuration = qvariant_cast(settings); - enablePopup = configuration[QString("notify")].toBool(); + m_enablePopup = configuration[QString("notify")].toBool(); counts += configuration[QString("cpuTooltip")].toInt(); counts += configuration[QString("cpuclTooltip")].toInt(); @@ -92,6 +85,8 @@ void AWDataAggregator::setParameters(QVariantMap settings) counts += configuration[QString("swapTooltip")].toInt(); counts += configuration[QString("downTooltip")].toInt(); counts += configuration[QString("batTooltip")].toInt(); + // resize tooltip image + toolTipView->resize(100.0 * counts, 105.0); boundaries[QString("cpuTooltip")] = 100.0; boundaries[QString("cpuclTooltip")] = 4000.0; @@ -100,8 +95,6 @@ void AWDataAggregator::setParameters(QVariantMap settings) boundaries[QString("downTooltip")] = 1.0; boundaries[QString("upTooltip")] = 1.0; boundaries[QString("batTooltip")] = 100.0; - size.setHeight(105.0); - size.setWidth(100.0 * counts); if (configuration[QString("cpuTooltip")].toBool()) requiredKeys.append(QString("cpuTooltip")); if (configuration[QString("cpuclTooltip")].toBool()) requiredKeys.append(QString("cpuclTooltip")); @@ -122,10 +115,9 @@ QPixmap AWDataAggregator::tooltipImage() { qCDebug(LOG_AW); - toolTipView->resize(size); // create image toolTipScene->clear(); - QPen pen = QPen(); + QPen pen; bool down = false; foreach(QString key, requiredKeys) { // create frame @@ -158,7 +150,7 @@ QPixmap AWDataAggregator::tooltipImage() } -void AWDataAggregator::dataUpdate(QHash values) +void AWDataAggregator::dataUpdate(const QHash values) { qCDebug(LOG_AW); @@ -187,7 +179,8 @@ void AWDataAggregator::dataUpdate(QHash values) } -void AWDataAggregator::checkValue(const QString source, const float value, const float extremum) const +void AWDataAggregator::checkValue(const QString source, const float value, + const float extremum) const { qCDebug(LOG_AW); qCDebug(LOG_AW) << "Notification source" << source; @@ -195,23 +188,24 @@ void AWDataAggregator::checkValue(const QString source, const float value, const qCDebug(LOG_AW) << "Called with extremum" << extremum; if (value >= 0.0) { - if ((enablePopup) && (value > extremum) && (data[source].last() < extremum)) + if ((m_enablePopup) && (value > extremum) && (data[source].last() < extremum)) return AWActions::sendNotification(QString("event"), notificationText(source, value)); } else { - if ((enablePopup) && (value < extremum) && (data[source].last() > extremum)) + if ((m_enablePopup) && (value < extremum) && (data[source].last() > extremum)) return AWActions::sendNotification(QString("event"), notificationText(source, value)); } } -void AWDataAggregator::checkValue(const QString source, const QString current, const QString received) const +void AWDataAggregator::checkValue(const QString source, const QString current, + const QString received) const { qCDebug(LOG_AW); qCDebug(LOG_AW) << "Notification source" << source; qCDebug(LOG_AW) << "Current value" << current; qCDebug(LOG_AW) << "Received value" << received; - if ((enablePopup) && (current != received)) + if ((m_enablePopup) && (current != received)) return AWActions::sendNotification(QString("event"), notificationText(source, received)); } @@ -238,10 +232,7 @@ QString AWDataAggregator::notificationText(const QString source, const float val QString output; if (source == QString("batTooltip")) { - if (value > 0.0) - output = i18n("AC online"); - else - output = i18n("AC offline"); + output = value > 0.0 ? i18n("AC online") : i18n("AC offline"); } else if (source == QString("cpuTooltip")) { output = i18n("High CPU load"); } else if (source == QString("memTooltip")) { diff --git a/sources/awesome-widget/plugin/awdataaggregator.h b/sources/awesome-widget/plugin/awdataaggregator.h index 96a2214..810ff6f 100644 --- a/sources/awesome-widget/plugin/awdataaggregator.h +++ b/sources/awesome-widget/plugin/awdataaggregator.h @@ -35,17 +35,16 @@ public: explicit AWDataAggregator(QObject *parent = nullptr); virtual ~AWDataAggregator(); QList getData(const QString key) const; - QSize getTooltipSize() const; QString htmlImage(const QPixmap source) const; void setParameters(QVariantMap settings); QPixmap tooltipImage(); signals: - void updateData(QHash values); - void toolTipPainted(QString image); + void updateData(const QHash values); + void toolTipPainted(const QString image) const; private slots: - void dataUpdate(QHash values); + void dataUpdate(const QHash values); private: // ui @@ -66,9 +65,8 @@ private: QString currentNetworkDevice = QString("lo"); QHash boundaries; QHash> data; - bool enablePopup = false; + bool m_enablePopup = false; QStringList requiredKeys; - QSize size; }; diff --git a/sources/awesome-widget/plugin/awkeys.cpp b/sources/awesome-widget/plugin/awkeys.cpp index 53fbb28..1fe73d8 100644 --- a/sources/awesome-widget/plugin/awkeys.cpp +++ b/sources/awesome-widget/plugin/awkeys.cpp @@ -49,8 +49,8 @@ AWKeys::AWKeys(QObject *parent) dataAggregator = new AWDataAggregator(this); connect(this, SIGNAL(needToBeUpdated()), this, SLOT(dataUpdate())); // transfer signal from AWDataAggregator object to QML ui - connect(dataAggregator, SIGNAL(toolTipPainted(QString)), - this, SIGNAL(needToolTipToBeUpdated(QString))); + connect(dataAggregator, SIGNAL(toolTipPainted(const QString)), + this, SIGNAL(needToolTipToBeUpdated(const QString))); } @@ -84,10 +84,10 @@ void AWKeys::initKeys(const QString currentPattern) qCDebug(LOG_AW) << "Pattern" << currentPattern; // init - pattern = currentPattern; + m_pattern = currentPattern; // update network and hdd list - addKeyToCache(QString("Hdd")); - addKeyToCache(QString("Network")); + addKeyToCache(QString("hdd")); + addKeyToCache(QString("net")); loadKeysFromCache(); } @@ -100,30 +100,12 @@ void AWKeys::setAggregatorProperty(const QString key, const QVariant value) } - -void AWKeys::setPopupEnabled(const bool popup) -{ - qCDebug(LOG_AW); - qCDebug(LOG_AW) << "Is popup enabled" << popup; - - enablePopup = popup; -} - - void AWKeys::setWrapNewLines(const bool wrap) { qCDebug(LOG_AW); qCDebug(LOG_AW) << "Is wrapping enabled" << wrap; - wrapNewLines = wrap; -} - - -QSize AWKeys::toolTipSize() const -{ - qCDebug(LOG_AW); - - return dataAggregator->getTooltipSize(); + m_wrapNewLines = wrap; } @@ -138,13 +120,13 @@ void AWKeys::addDevice(const QString source) if (source.contains(diskRegexp)) { QString device = source; device.remove(QString("/Rate/rblk")); - addKeyToCache(QString("Disk"), device); + addKeyToCache(QString("disk"), device); } else if (source.contains(mountRegexp)) { QString device = source; device.remove(QString("partitions")).remove(QString("/filllevel")); - addKeyToCache(QString("Mount"), device); + addKeyToCache(QString("mount"), device); } else if (source.startsWith(QString("lmsensors"))) { - addKeyToCache(QString("Temp"), source); + addKeyToCache(QString("temp"), source); } } @@ -182,7 +164,7 @@ QStringList AWKeys::dictKeys(const bool sorted, const QString regexp) const allKeys.append(QString("cpucl")); allKeys.append(QString("cpu")); // temperature - for (int i=tempDevices.count()-1; i>=0; i--) + for (int i=m_devices[QString("temp")].count()-1; i>=0; i--) allKeys.append(QString("temp%1").arg(i)); // gputemp allKeys.append(QString("gputemp")); @@ -207,7 +189,7 @@ QStringList AWKeys::dictKeys(const bool sorted, const QString regexp) const allKeys.append(QString("swaptotgb")); allKeys.append(QString("swap")); // hdd - for (int i=mountDevices.count()-1; i>=0; i--) { + for (int i=m_devices[QString("mount")].count()-1; i>=0; i--) { allKeys.append(QString("hddmb%1").arg(i)); allKeys.append(QString("hddgb%1").arg(i)); allKeys.append(QString("hddfreemb%1").arg(i)); @@ -217,15 +199,15 @@ QStringList AWKeys::dictKeys(const bool sorted, const QString regexp) const allKeys.append(QString("hdd%1").arg(i)); } // hdd speed - for (int i=diskDevices.count()-1; i>=0; i--) { + for (int i=m_devices[QString("disk")].count()-1; i>=0; i--) { allKeys.append(QString("hddr%1").arg(i)); allKeys.append(QString("hddw%1").arg(i)); } // hdd temp - for (int i=hddDevices.count()-1; i>=0; i--) + for (int i=m_devices[QString("hdd")].count()-1; i>=0; i--) allKeys.append(QString("hddtemp%1").arg(i)); // network - for (int i=networkDevices.count()-1; i>=0; i--) { + for (int i=m_devices[QString("net")].count()-1; i>=0; i--) { allKeys.append(QString("downunits%1").arg(i)); allKeys.append(QString("upunits%1").arg(i)); allKeys.append(QString("downkb%1").arg(i)); @@ -310,8 +292,8 @@ QStringList AWKeys::getHddDevices() const { qCDebug(LOG_AW); - QStringList devices = hddDevices; - // required by ui interface + QStringList devices = m_devices[QString("hdd")]; + // required by selector in the UI devices.insert(0, QString("disable")); devices.insert(0, QString("auto")); @@ -325,11 +307,14 @@ void AWKeys::dataUpdateReceived(const QString sourceName, const QVariantMap data qCDebug(LOG_AW) << "Source" << sourceName; qCDebug(LOG_AW) << "Data" << data; - if (sourceName == QString("update")) return emit(needToBeUpdated()); - + // run concurrent data update +#ifdef BUILD_FUTURE QtConcurrent::run([this, sourceName, data]() { return setDataBySource(sourceName, data); }); +#else /* BUILD_FUTURE */ + return setDataBySource(sourceName, data); +#endif /* BUILD_FUTURE */ } @@ -340,35 +325,29 @@ QString AWKeys::infoByKey(QString key) const key.remove(QRegExp(QString("^bar[0-9]{1,}"))); if (key.startsWith(QString("custom"))) - foreach(ExtScript *item, extScripts->items()) { - if (item->tag(QString("custom")) != key) continue; - return item->executable(); - } + return extScripts->itemByTagNumber(key.remove(QString("custom")).toInt())->uniq(); else if (key.contains(QRegExp(QString("^hdd[rw]")))) - return QString("%1").arg(diskDevices[key.remove(QRegExp(QString("hdd[rw]"))).toInt()]); + return QString("%1").arg(m_devices[QString("disk")][key.remove(QRegExp(QString("hdd[rw]"))).toInt()]); else if (key.contains(QRegExp(QString("^hdd([0-9]|mb|gb|freemb|freegb|totmb|totgb)")))) - return QString("%1").arg(mountDevices[key.remove(QRegExp(QString("^hdd([0-9]|mb|gb|freemb|freegb|totmb|totgb)"))).toInt()]); + return QString("%1").arg(m_devices[QString("mount")][key.remove(QRegExp(QString("^hdd([0-9]|mb|gb|freemb|freegb|totmb|totgb)"))).toInt()]); else if (key.startsWith(QString("hddtemp"))) - return QString("%1").arg(hddDevices[key.remove(QString("hddtemp")).toInt()]); + return QString("%1").arg(m_devices[QString("hdd")][key.remove(QString("hddtemp")).toInt()]); else if (key.contains(QRegExp(QString("^(down|up)[0-9]")))) - return QString("%1").arg(networkDevices[key.remove(QRegExp(QString("^(down|up)"))).toInt()]); + return QString("%1").arg(m_devices[QString("net")][key.remove(QRegExp(QString("^(down|up)"))).toInt()]); else if (key.startsWith(QString("pkgcount"))) - foreach(ExtUpgrade *item, extUpgrade->items()) { - if (item->tag(QString("pkgcount")) != key) continue; - return item->executable(); - } + return extUpgrade->itemByTagNumber(key.remove(QString("pkgcount")).toInt())->uniq(); else if (key.contains(QRegExp(QString("(^|perc)(ask|bid|price)(chg|)")))) - foreach(ExtQuotes *item, extQuotes->items()) { - if (item->number() != key.remove(QRegExp(QString("(^|perc)(ask|bid|price)(chg|)"))).toInt()) continue; - return item->ticker(); - } + return extQuotes->itemByTagNumber(key.remove(QRegExp(QString("(^|perc)(ask|bid|price)(chg|)"))).toInt())->uniq(); + else if (key.contains(QRegExp(QString("(weather|weatherId|humidity|pressure|temperature)")))) + return extWeather->itemByTagNumber(key.remove(QRegExp(QString("(weather|weatherId|humidity|pressure|temperature)"))).toInt())->uniq(); else if (key.startsWith(QString("temp"))) - return QString("%1").arg(tempDevices[key.remove(QString("temp")).toInt()]); + return QString("%1").arg(m_devices[QString("temp")][key.remove(QString("temp")).toInt()]); return QString("(none)"); } +// HACK this method requires to define tag value from bar from UI interface QString AWKeys::valueByKey(QString key) const { qCDebug(LOG_AW); @@ -403,8 +382,7 @@ void AWKeys::dataUpdate() qCDebug(LOG_AW); calculateValues(); - calculateLambdas(); - emit(needTextToBeUpdated(parsePattern())); + emit(needTextToBeUpdated(parsePattern(m_pattern))); emit(dataAggregator->updateData(values)); } @@ -418,35 +396,13 @@ void AWKeys::loadKeysFromCache() qCInfo(LOG_AW) << "Cache file" << fileName; QSettings cache(fileName, QSettings::IniFormat); - cache.beginGroup(QString("Disk")); - diskDevices.clear(); - foreach(QString key, cache.allKeys()) - diskDevices.append(cache.value(key).toString()); - cache.endGroup(); - - cache.beginGroup(QString("Hdd")); - hddDevices.clear(); - foreach(QString key, cache.allKeys()) - hddDevices.append(cache.value(key).toString()); - cache.endGroup(); - - cache.beginGroup(QString("Mount")); - mountDevices.clear(); - foreach(QString key, cache.allKeys()) - mountDevices.append(cache.value(key).toString()); - cache.endGroup(); - - cache.beginGroup(QString("Network")); - networkDevices.clear(); - foreach(QString key, cache.allKeys()) - networkDevices.append(cache.value(key).toString()); - cache.endGroup(); - - cache.beginGroup(QString("Temp")); - tempDevices.clear(); - foreach(QString key, cache.allKeys()) - tempDevices.append(cache.value(key).toString()); - cache.endGroup(); + foreach(QString group, cache.childGroups()) { + cache.beginGroup(group); + m_devices.remove(group); + foreach(QString key, cache.allKeys()) + m_devices[group].append(cache.value(key).toString()); + cache.endGroup(); + } return reinitKeys(); } @@ -474,7 +430,7 @@ void AWKeys::reinitKeys() QStringList allKeys = dictKeys(); // not documented feature - place all available tags - pattern = pattern.replace(QString("$ALL"), [allKeys](){ + m_pattern = m_pattern.replace(QString("$ALL"), [allKeys](){ QStringList strings; foreach(QString tag, allKeys) strings.append(QString("%1: $%1").arg(tag)); @@ -483,7 +439,7 @@ void AWKeys::reinitKeys() // append lists // bars - foundBars = [allKeys](QString pattern) { + m_foundBars = [allKeys](QString pattern) { QStringList selectedKeys; foreach(QString key, allKeys) if ((key.startsWith(QString("bar"))) && @@ -493,10 +449,10 @@ void AWKeys::reinitKeys() } if (selectedKeys.isEmpty()) qCWarning(LOG_AW) << "No bars found"; return selectedKeys; - }(pattern); + }(m_pattern); // main key list - foundKeys = [allKeys](QString pattern) { + m_foundKeys = [allKeys](QString pattern) { QStringList selectedKeys; foreach(QString key, allKeys) if ((!key.startsWith(QString("bar"))) && @@ -506,10 +462,10 @@ void AWKeys::reinitKeys() } if (selectedKeys.isEmpty()) qCWarning(LOG_AW) << "No keys found"; return selectedKeys; - }(pattern); + }(m_pattern); // lambdas - foundLambdas = [](QString pattern) { + m_foundLambdas = [](QString pattern) { QStringList selectedKeys; // substring inside ${{ }} (with brackets) which should not contain ${{ QRegularExpression lambdaRegexp(QString("\\$\\{\\{((?!\\$\\{\\{).)*?\\}\\}")); @@ -528,18 +484,10 @@ void AWKeys::reinitKeys() } if (selectedKeys.isEmpty()) qCWarning(LOG_AW) << "No lambdas found"; return selectedKeys; - }(pattern); + }(m_pattern); // set key data to aggregator - aggregator->setDevices([this]() { - QHash deviceList; - deviceList[QString("disk")] = diskDevices; - deviceList[QString("hdd")] = hddDevices; - deviceList[QString("mount")] = mountDevices; - deviceList[QString("net")] = networkDevices; - deviceList[QString("temp")] = tempDevices; - return deviceList; - }()); + aggregator->setDevices(m_devices); } @@ -558,7 +506,7 @@ void AWKeys::addKeyToCache(const QString type, const QString key) foreach(QString key, cache.allKeys()) cachedValues.append(cache.value(key).toString()); - if (type == QString("Hdd")) { + if (type == QString("hdd")) { QStringList allDevices = QDir(QString("/dev")).entryList(QDir::System, QDir::Name); QStringList devices = allDevices.filter(QRegExp(QString("^[hms]d[a-z]$"))); foreach(QString dev, devices) { @@ -567,7 +515,7 @@ void AWKeys::addKeyToCache(const QString type, const QString key) qCInfo(LOG_AW) << "Found new key" << device << "for type" << type; cache.setValue(QString("%1").arg(cache.allKeys().count(), 3, 10, QChar('0')), device); } - } else if (type == QString("Network")) { + } else if (type == QString("net")) { QList rawInterfaceList = QNetworkInterface::allInterfaces(); foreach(QNetworkInterface interface, rawInterfaceList) { QString device = interface.name(); @@ -587,29 +535,6 @@ void AWKeys::addKeyToCache(const QString type, const QString key) } -void AWKeys::calculateLambdas() -{ - qCDebug(LOG_AW); - - foreach(QString key, foundLambdas) - values[key] = [this](QString key) { - QScriptEngine engine; - // apply $this values - key.replace(QString("$this"), values[key]); - foreach(QString lambdaKey, foundKeys) - key.replace(QString("$%1").arg(lambdaKey), values[lambdaKey]); - qCInfo(LOG_AW) << "Expression" << key; - QScriptValue result = engine.evaluate(key); - if (engine.hasUncaughtException()) { - int line = engine.uncaughtExceptionLineNumber(); - qCWarning(LOG_AW) << "Uncaught exception at line" << line << ":" << result.toString(); - return QString(); - } else - return result.toString(); - }(key); -} - - // HACK this method is required since I could not define some values by using // specified pattern. Usually they are values which depend on several others void AWKeys::calculateValues() @@ -617,8 +542,8 @@ void AWKeys::calculateValues() qCDebug(LOG_AW); // hddtot* - foreach(QString device, hddDevices) { - int index = hddDevices.indexOf(device); + foreach(QString device, m_devices[QString("mount")]) { + int index = m_devices[QString("mount")].indexOf(device); values[QString("hddtotmb%1").arg(index)] = QString("%1").arg( values[QString("hddfreemb%1").arg(index)].toFloat() + values[QString("hddmb%1").arg(index)].toFloat(), 5, 'f', 0); @@ -638,7 +563,7 @@ void AWKeys::calculateValues() 5, 'f', 1); // up, down, upkb, downkb, upunits, downunits - int netIndex = networkDevices.indexOf(values[QString("netdev")]); + int netIndex = m_devices[QString("net")].indexOf(values[QString("netdev")]); values[QString("down")] = values[QString("down%1").arg(netIndex)]; values[QString("downkb")] = values[QString("downkb%1").arg(netIndex)]; values[QString("downunits")] = values[QString("downunits%1").arg(netIndex)]; @@ -655,23 +580,41 @@ void AWKeys::calculateValues() values[QString("swap")] = QString("%1").arg( 100.0 * values[QString("swapmb")].toFloat() / values[QString("swaptotmb")].toFloat(), 5, 'f', 1); + + // lambdas + foreach(QString key, m_foundLambdas) + values[key] = [this](QString key) { + QScriptEngine engine; + // apply $this values + key.replace(QString("$this"), values[key]); + foreach(QString lambdaKey, m_foundKeys) + key.replace(QString("$%1").arg(lambdaKey), values[lambdaKey]); + qCInfo(LOG_AW) << "Expression" << key; + QScriptValue result = engine.evaluate(key); + if (engine.hasUncaughtException()) { + int line = engine.uncaughtExceptionLineNumber(); + qCWarning(LOG_AW) << "Uncaught exception at line" << line << ":" << result.toString(); + return QString(); + } else + return result.toString(); + }(key); } -QString AWKeys::parsePattern() const +QString AWKeys::parsePattern(QString pattern) const { qCDebug(LOG_AW); - QString parsed = pattern; - parsed.replace(QString("$$"), QString("$\\$\\")); + // screen sign + pattern.replace(QString("$$"), QString("$\\$\\")); // lambdas - foreach(QString key, foundLambdas) - parsed.replace(QString("${{%1}}").arg(key), values[key]); + foreach(QString key, m_foundLambdas) + pattern.replace(QString("${{%1}}").arg(key), values[key]); // main keys - foreach(QString key, foundKeys) - parsed.replace(QString("$%1").arg(key), [](QString key, QString value) { + foreach(QString key, m_foundKeys) + pattern.replace(QString("$%1").arg(key), [](QString key, QString value) { if ((!key.startsWith(QString("custom"))) && (!key.startsWith(QString("weather")))) value.replace(QString(" "), QString(" ")); @@ -679,37 +622,41 @@ QString AWKeys::parsePattern() const }(key, values[key])); // bars - foreach(QString bar, foundBars) { + foreach(QString bar,m_foundBars) { GraphicalItem *item = graphicalItems->itemByTag(bar); QString key = bar; key.remove(QRegExp(QString("^bar[0-9]{1,}"))); if (item->type() == GraphicalItem::Graph) - parsed.replace(QString("$%1").arg(bar), item->image([](const QList data) { + pattern.replace(QString("$%1").arg(bar), item->image([](const QList data) { return QVariant::fromValue>(data); }(dataAggregator->getData(key)))); else - parsed.replace(QString("$%1").arg(bar), item->image(values[key])); + pattern.replace(QString("$%1").arg(bar), item->image(values[key])); } - // prepare strings - parsed.replace(QString("$\\$\\"), QString("$$")); - if (wrapNewLines) parsed.replace(QString("\n"), QString("
")); + pattern.replace(QString("$\\$\\"), QString("$$")); + if (m_wrapNewLines) pattern.replace(QString("\n"), QString("
")); - return parsed; + return pattern; } void AWKeys::setDataBySource(const QString sourceName, const QVariantMap data) { +#ifdef BUILD_FUTURE // check if data stream is locked lock = ((lock) && (queue > 0)); if (lock) return; +#endif /* BUILD_FUTURE */ qCDebug(LOG_AW); qCDebug(LOG_AW) << "Source" << sourceName; qCDebug(LOG_AW) << "Data" << data; + // update + if (sourceName == QString("update")) return emit(needToBeUpdated()); + // drop if limits are reached if (++queue > QUEUE_LIMIT) { qCWarning(LOG_AW) << "Messages queue" << queue-- << "more than limits" << QUEUE_LIMIT << ", lock"; @@ -718,7 +665,7 @@ void AWKeys::setDataBySource(const QString sourceName, const QVariantMap data) } // first list init - QStringList tags = aggregator->keyFromSource(sourceName); + QStringList tags = aggregator->keysFromSource(sourceName); if (tags.isEmpty()) tags = aggregator->registerSource(sourceName, data[QString("units")].toString()); diff --git a/sources/awesome-widget/plugin/awkeys.h b/sources/awesome-widget/plugin/awkeys.h index 57ed163..e9528f7 100644 --- a/sources/awesome-widget/plugin/awkeys.h +++ b/sources/awesome-widget/plugin/awkeys.h @@ -42,12 +42,10 @@ public: explicit AWKeys(QObject *parent = nullptr); virtual ~AWKeys(); - Q_INVOKABLE void initKeys(const QString currentPattern); Q_INVOKABLE void initDataAggregator(const QVariantMap tooltipParams); + Q_INVOKABLE void initKeys(const QString currentPattern); Q_INVOKABLE void setAggregatorProperty(const QString key, const QVariant value); - Q_INVOKABLE void setPopupEnabled(const bool popup = false); Q_INVOKABLE void setWrapNewLines(const bool wrap = false); - Q_INVOKABLE QSize toolTipSize() const; // keys Q_INVOKABLE void addDevice(const QString source); Q_INVOKABLE QStringList dictKeys(const bool sorted = false, @@ -74,14 +72,12 @@ private slots: private: // methods void addKeyToCache(const QString type, const QString key = QString("")); - void calculateLambdas(); void calculateValues(); - QString parsePattern() const; + QString parsePattern(QString pattern) const; void setDataBySource(const QString sourceName, const QVariantMap data); AWKeysAggregator *aggregator = nullptr; AWDataAggregator *dataAggregator = nullptr; - bool enablePopup = false; - bool wrapNewLines = false; + bool m_wrapNewLines = false; ExtItemAggregator *graphicalItems = nullptr; ExtItemAggregator *extQuotes = nullptr; ExtItemAggregator *extScripts = nullptr; @@ -89,10 +85,10 @@ private: ExtItemAggregator *extWeather = nullptr; bool lock = false; int queue = 0; - QString pattern; - QStringList foundBars, foundKeys, foundLambdas; + QString m_pattern; + QStringList m_foundBars, m_foundKeys, m_foundLambdas; QHash values; - QStringList diskDevices, hddDevices, mountDevices, networkDevices, tempDevices; + QHash m_devices; }; diff --git a/sources/awesome-widget/plugin/awkeysaggregator.cpp b/sources/awesome-widget/plugin/awkeysaggregator.cpp index 0c41263..b1b0279 100644 --- a/sources/awesome-widget/plugin/awkeysaggregator.cpp +++ b/sources/awesome-widget/plugin/awkeysaggregator.cpp @@ -90,7 +90,7 @@ QString AWKeysAggregator::formater(const QVariant data, const QString key) const case Quotes: // first cast output = QString("%1").arg(data.toDouble(), 0, 'f'); - output = output.leftJustified(8, QLatin1Char(' '), true); + output = output.rightJustified(8, QLatin1Char(' '), true); break; case Temperature: output = QString("%1").arg(temperature(data.toFloat()), 5, 'f', 1); @@ -140,7 +140,7 @@ QString AWKeysAggregator::formater(const QVariant data, const QString key) const } -QStringList AWKeysAggregator::keyFromSource(const QString source) const +QStringList AWKeysAggregator::keysFromSource(const QString source) const { qCDebug(LOG_AW); qCDebug(LOG_AW) << "Search for source" << source; @@ -502,7 +502,7 @@ QStringList AWKeysAggregator::registerSource(const QString source, const QString m_formater[key] = NoFormat; } - return keyFromSource(source); + return keysFromSource(source); } diff --git a/sources/awesome-widget/plugin/awkeysaggregator.h b/sources/awesome-widget/plugin/awkeysaggregator.h index 5b34a95..6fa3ab1 100644 --- a/sources/awesome-widget/plugin/awkeysaggregator.h +++ b/sources/awesome-widget/plugin/awkeysaggregator.h @@ -65,7 +65,7 @@ public: virtual ~AWKeysAggregator(); // get methods QString formater(const QVariant data, const QString key) const; - QStringList keyFromSource(const QString source) const; + QStringList keysFromSource(const QString source) const; // set methods void setAcOffline(const QString inactive); void setAcOnline(const QString active); diff --git a/sources/translations/awesome-widgets.pot b/sources/translations/awesome-widgets.pot index bce2f02..4862f0d 100644 --- a/sources/translations/awesome-widgets.pot +++ b/sources/translations/awesome-widgets.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: https://github.com/arcan1s/awesome-widgets/issues\n" -"POT-Creation-Date: 2015-09-11 22:03+0300\n" +"POT-Creation-Date: 2015-09-14 10:03+0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -312,6 +312,9 @@ msgstr "" msgid "Edit bars" msgstr "" +msgid "Preview" +msgstr "" + msgid "Run %1" msgstr "" diff --git a/sources/translations/en.po b/sources/translations/en.po index 83bd1fc..28e598a 100644 --- a/sources/translations/en.po +++ b/sources/translations/en.po @@ -6,8 +6,8 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: https://github.com/arcan1s/awesome-widgets/issues\n" -"POT-Creation-Date: 2015-09-11 22:03+0300\n" -"PO-Revision-Date: 2015-09-11 22:03+0300\n" +"POT-Creation-Date: 2015-09-14 10:03+0300\n" +"PO-Revision-Date: 2015-09-14 10:04+0300\n" "Last-Translator: Evgeniy Alekseev \n" "Language-Team: English \n" "Language: ru\n" @@ -317,6 +317,9 @@ msgstr "Add lambda" msgid "Edit bars" msgstr "Edit bars" +msgid "Preview" +msgstr "Preview" + msgid "Run %1" msgstr "Run %1" diff --git a/sources/translations/es.po b/sources/translations/es.po index 3b57345..3b2ef50 100644 --- a/sources/translations/es.po +++ b/sources/translations/es.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: https://github.com/arcan1s/awesome-widgets/issues\n" -"POT-Creation-Date: 2015-09-11 22:03+0300\n" +"POT-Creation-Date: 2015-09-14 10:03+0300\n" "PO-Revision-Date: 2015-07-31 22:13+0300\n" "Last-Translator: Evgeniy Alekseev \n" "Language-Team: Spanish \n" @@ -328,6 +328,9 @@ msgstr "" msgid "Edit bars" msgstr "Editar barras" +msgid "Preview" +msgstr "" + msgid "Run %1" msgstr "Ejecutar %1" diff --git a/sources/translations/fr.po b/sources/translations/fr.po index d461ca4..19d90be 100644 --- a/sources/translations/fr.po +++ b/sources/translations/fr.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: https://github.com/arcan1s/awesome-widgets/issues\n" -"POT-Creation-Date: 2015-09-11 22:03+0300\n" +"POT-Creation-Date: 2015-09-14 10:03+0300\n" "PO-Revision-Date: 2015-07-31 22:16+0300\n" "Last-Translator: Evgeniy Alekseev \n" "Language-Team: French \n" @@ -330,6 +330,9 @@ msgstr "" msgid "Edit bars" msgstr "Modifier les barres" +msgid "Preview" +msgstr "" + msgid "Run %1" msgstr "Éxecuter %1" diff --git a/sources/translations/nl.po b/sources/translations/nl.po index 07d53ef..d79ba0f 100644 --- a/sources/translations/nl.po +++ b/sources/translations/nl.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Awesome widgets\n" "Report-Msgid-Bugs-To: https://github.com/arcan1s/awesome-widgets/issues\n" -"POT-Creation-Date: 2015-09-11 22:03+0300\n" +"POT-Creation-Date: 2015-09-14 10:03+0300\n" "PO-Revision-Date: 2015-08-20 22:52+0300\n" "Last-Translator: Evgeniy Alekseev \n" "Language-Team: Dutch \n" @@ -329,6 +329,9 @@ msgstr "" msgid "Edit bars" msgstr "Balken bewerken" +msgid "Preview" +msgstr "" + msgid "Run %1" msgstr "%1 uitvoeren" diff --git a/sources/translations/pt_BR.po b/sources/translations/pt_BR.po index cb96a62..b215cc2 100644 --- a/sources/translations/pt_BR.po +++ b/sources/translations/pt_BR.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: https://github.com/arcan1s/awesome-widgets/issues\n" -"POT-Creation-Date: 2015-09-11 22:03+0300\n" +"POT-Creation-Date: 2015-09-14 10:03+0300\n" "PO-Revision-Date: 2015-07-31 22:21+0300\n" "Last-Translator: Evgeniy Alekseev \n" "Language-Team: Russian \n" @@ -328,6 +328,9 @@ msgstr "" msgid "Edit bars" msgstr "Editar barras" +msgid "Preview" +msgstr "" + msgid "Run %1" msgstr "Rodar %1" diff --git a/sources/translations/ru.po b/sources/translations/ru.po index 680908e..157f92c 100644 --- a/sources/translations/ru.po +++ b/sources/translations/ru.po @@ -6,8 +6,8 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: https://github.com/arcan1s/awesome-widgets/issues\n" -"POT-Creation-Date: 2015-09-11 22:03+0300\n" -"PO-Revision-Date: 2015-09-11 22:03+0300\n" +"POT-Creation-Date: 2015-09-14 10:03+0300\n" +"PO-Revision-Date: 2015-09-14 10:04+0300\n" "Last-Translator: Evgeniy Alekseev \n" "Language-Team: Russian \n" "Language: ru\n" @@ -317,6 +317,9 @@ msgstr "Добавить лямбду" msgid "Edit bars" msgstr "Редактировать бары" +msgid "Preview" +msgstr "Предварительный просмотр" + msgid "Run %1" msgstr "Запуск %1" diff --git a/sources/translations/uk.po b/sources/translations/uk.po index c7cb655..e10d2f8 100644 --- a/sources/translations/uk.po +++ b/sources/translations/uk.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: https://github.com/arcan1s/awesome-widgets/issues\n" -"POT-Creation-Date: 2015-09-11 22:03+0300\n" +"POT-Creation-Date: 2015-09-14 10:03+0300\n" "PO-Revision-Date: 2015-07-31 22:23+0300\n" "Last-Translator: Evgeniy Alekseev \n" "Language-Team: Ukrainian \n" @@ -328,6 +328,9 @@ msgstr "" msgid "Edit bars" msgstr "Редагувати бари" +msgid "Preview" +msgstr "" + msgid "Run %1" msgstr "Запуск %1" diff --git a/sources/translations/zh.po b/sources/translations/zh.po index b8fcbd3..17a9619 100644 --- a/sources/translations/zh.po +++ b/sources/translations/zh.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: https://github.com/arcan1s/awesome-widgets/issues\n" -"POT-Creation-Date: 2015-09-11 22:03+0300\n" +"POT-Creation-Date: 2015-09-14 10:03+0300\n" "PO-Revision-Date: 2015-07-31 22:24+0300\n" "Last-Translator: Evgeniy Alekseev \n" "Language-Team: Russian \n" @@ -330,6 +330,9 @@ msgstr "" msgid "Edit bars" msgstr "可编辑的" +msgid "Preview" +msgstr "" + msgid "Run %1" msgstr ""