From 4c27382467e08a8bd362511b614a3f44fdb59946 Mon Sep 17 00:00:00 2001 From: arcan1s Date: Sun, 30 Aug 2015 16:24:00 +0300 Subject: [PATCH] more correct logging, use qt logging for qml as well --- sources/awdebug.cpp | 7 +- sources/awdebug.h | 3 +- .../package/contents/ui/about.qml | 2 +- .../package/contents/ui/advanced.qml | 4 +- .../package/contents/ui/appearance.qml | 9 +- .../package/contents/ui/dataengine.qml | 10 +- .../package/contents/ui/main.qml | 29 +-- .../package/contents/ui/tooltip.qml | 2 +- .../package/contents/ui/widget.qml | 52 ++---- sources/awesome-widget/plugin/awactions.cpp | 16 +- sources/awesome-widget/plugin/awactions.h | 4 +- sources/awesome-widget/plugin/awkeys.cpp | 170 +++++++++--------- sources/awesome-widget/plugin/awkeys.h | 8 +- sources/awesome-widget/plugin/awtooltip.cpp | 33 ++-- sources/awesome-widget/plugin/awtooltip.h | 6 +- sources/awesomewidgets/abstractextitem.cpp | 76 ++++---- sources/awesomewidgets/abstractextitem.h | 5 +- .../abstractextitemaggregator.cpp | 20 +-- .../abstractextitemaggregator.h | 2 +- sources/awesomewidgets/extitemaggregator.h | 80 ++++++--- sources/awesomewidgets/extquotes.cpp | 62 +++---- sources/awesomewidgets/extquotes.h | 5 +- sources/awesomewidgets/extscript.cpp | 114 ++++++------ sources/awesomewidgets/extscript.h | 7 +- sources/awesomewidgets/extupgrade.cpp | 68 +++---- sources/awesomewidgets/extupgrade.h | 7 +- sources/awesomewidgets/extweather.cpp | 79 ++++---- sources/awesomewidgets/extweather.h | 7 +- sources/awesomewidgets/graphicalitem.cpp | 118 ++++++------ sources/awesomewidgets/graphicalitem.h | 7 +- .../package/contents/ui/about.qml | 2 +- .../package/contents/ui/activeapp.qml | 9 +- .../package/contents/ui/advanced.qml | 4 +- .../package/contents/ui/inactiveapp.qml | 9 +- .../package/contents/ui/main.qml | 14 +- .../package/contents/ui/widget.qml | 38 ++-- sources/desktop-panel/plugin/dpadds.cpp | 48 ++--- sources/desktop-panel/plugin/dpadds.h | 4 +- sources/extsysmon/CMakeLists.txt | 2 + sources/extsysmon/awesome-widgets-logging.ini | 17 ++ sources/extsysmon/extsysmon.cpp | 72 ++++---- sources/extsysmon/extsysmon.h | 2 +- 42 files changed, 635 insertions(+), 598 deletions(-) create mode 100644 sources/extsysmon/awesome-widgets-logging.ini diff --git a/sources/awdebug.cpp b/sources/awdebug.cpp index 962a0d6..dec48f3 100644 --- a/sources/awdebug.cpp +++ b/sources/awdebug.cpp @@ -19,6 +19,7 @@ #include "awdebug.h" -Q_LOGGING_CATEGORY(LOG_AW, "org.kde.plasma.awesomewidget") -Q_LOGGING_CATEGORY(LOG_DP, "org.kde.plasma.desktoppanel") -Q_LOGGING_CATEGORY(LOG_ESM, "org.kde.plasma.extsysmon") +Q_LOGGING_CATEGORY(LOG_AW, "org.kde.plasma.awesomewidget", QtMsgType::QtWarningMsg) +Q_LOGGING_CATEGORY(LOG_DP, "org.kde.plasma.desktoppanel", QtMsgType::QtWarningMsg) +Q_LOGGING_CATEGORY(LOG_ESM, "org.kde.plasma.extsysmon", QtMsgType::QtWarningMsg) +Q_LOGGING_CATEGORY(LOG_LIB, "org.kde.plasma.awesomewidgets", QtMsgType::QtWarningMsg) diff --git a/sources/awdebug.h b/sources/awdebug.h index ec81486..2cb4972 100644 --- a/sources/awdebug.h +++ b/sources/awdebug.h @@ -26,16 +26,17 @@ #endif /* LOG_FORMAT */ // define info log level -#define isInfoEnabled isDebugEnabled #if QT_VERSION < QT_VERSION_CHECK(5, 5, 0) #ifndef qCInfo #define qCInfo qCDebug #endif /* qCInfo */ #endif /* QT_VERSION */ + Q_DECLARE_LOGGING_CATEGORY(LOG_AW) Q_DECLARE_LOGGING_CATEGORY(LOG_DP) Q_DECLARE_LOGGING_CATEGORY(LOG_ESM) +Q_DECLARE_LOGGING_CATEGORY(LOG_LIB) #endif /* AWDEBUG_H */ diff --git a/sources/awesome-widget/package/contents/ui/about.qml b/sources/awesome-widget/package/contents/ui/about.qml index f447291..27f6546 100644 --- a/sources/awesome-widget/package/contents/ui/about.qml +++ b/sources/awesome-widget/package/contents/ui/about.qml @@ -110,6 +110,6 @@ Item { } Component.onCompleted: { - if (debug) console.log("") + if (debug) console.debug() } } diff --git a/sources/awesome-widget/package/contents/ui/advanced.qml b/sources/awesome-widget/package/contents/ui/advanced.qml index 5a79f84..1292129 100644 --- a/sources/awesome-widget/package/contents/ui/advanced.qml +++ b/sources/awesome-widget/package/contents/ui/advanced.qml @@ -214,8 +214,10 @@ Item { ] onCurrentIndexChanged: cfg_tempUnits = model[currentIndex]["name"] Component.onCompleted: { + if (debug) console.debug() for (var i = 0; i < model.length; i++) { if (model[i]["name"] == plasmoid.configuration.tempUnits) { + if (debug) console.info("Found", model[i]["name"], "on", i) tempUnits.currentIndex = i; } } @@ -302,6 +304,6 @@ Item { } Component.onCompleted: { - if (debug) console.log("") + if (debug) console.debug() } } diff --git a/sources/awesome-widget/package/contents/ui/appearance.qml b/sources/awesome-widget/package/contents/ui/appearance.qml index 9893e8e..2d102a6 100644 --- a/sources/awesome-widget/package/contents/ui/appearance.qml +++ b/sources/awesome-widget/package/contents/ui/appearance.qml @@ -90,6 +90,7 @@ Item { width: parent.width * 2 / 3 text: plasmoid.configuration.fontFamily onClicked: { + if (debug) console.debug() fontDialog.setFont() fontDialog.visible = true } @@ -154,8 +155,10 @@ Item { ] onCurrentIndexChanged: cfg_fontWeight = model[currentIndex]["name"] Component.onCompleted: { + if (debug) console.debug() for (var i = 0; i < model.length; i++) { if (model[i]["name"] == plasmoid.configuration.fontWeight) { + if (debug) console.info("Found", model[i]["name"], "on", i) fontWeight.currentIndex = i; } } @@ -189,8 +192,10 @@ Item { ] onCurrentIndexChanged: cfg_fontStyle = model[currentIndex]["name"] Component.onCompleted: { + if (debug) console.debug() for (var i = 0; i < model.length; i++) { if (model[i]["name"] == plasmoid.configuration.fontStyle) { + if (debug) console.info("Found", model[i]["name"], "on", i) fontStyle.currentIndex = i; } } @@ -235,12 +240,14 @@ Item { signal setFont onAccepted: { + if (debug) console.debug() selectFont.text = fontDialog.font.family fontSize.value = fontDialog.font.pointSize fontStyle.currentIndex = fontDialog.font.italic ? 1 : 0 fontWeight.currentIndex = weight[fontDialog.font.weight] } onSetFont: { + if (debug) console.debug() fontDialog.font = Qt.font({ family: selectFont.text, pointSize: fontSize.value > 0 ? fontSize.value : 12, @@ -251,6 +258,6 @@ Item { } Component.onCompleted: { - if (debug) console.log("") + if (debug) console.debug() } } diff --git a/sources/awesome-widget/package/contents/ui/dataengine.qml b/sources/awesome-widget/package/contents/ui/dataengine.qml index 1113c55..89afe6f 100644 --- a/sources/awesome-widget/package/contents/ui/dataengine.qml +++ b/sources/awesome-widget/package/contents/ui/dataengine.qml @@ -114,8 +114,10 @@ Item { width: parent.width * 3 / 5 model: ["auto", "disable", "ati", "nvidia"] Component.onCompleted: { + if (debug) console.debug() for (var i=0; i(LOG_AW()).setEnabled(QtMsgType::QtDebugMsg, debug); - qSetMessagePattern(LOG_FORMAT); - qCInfo(LOG_AW) << "simple test" << QT_VERSION_CHECK(5, 5, 0) << QT_VERSION; + qCDebug(LOG_AW); } @@ -158,6 +150,7 @@ QString AWActions::getAboutText(const QString type) const QVariantMap AWActions::getFont(const QVariantMap defaultFont) const { qCDebug(LOG_AW); + qCDebug(LOG_AW) << "Default font is" << defaultFont; QVariantMap fontMap; CFont defaultCFont = CFont(defaultFont[QString("family")].toString(), @@ -178,7 +171,7 @@ QVariantMap AWActions::readDataEngineConfiguration() const qCDebug(LOG_AW); QString fileName = QStandardPaths::locate(QStandardPaths::ConfigLocation, QString("plasma-dataengine-extsysmon.conf")); - qCDebug(LOG_AW) << "Configuration file" << fileName; + qCInfo(LOG_AW) << "Configuration file" << fileName; QSettings settings(fileName, QSettings::IniFormat); QVariantMap configuration; @@ -203,7 +196,7 @@ void AWActions::writeDataEngineConfiguration(const QVariantMap configuration) co QString fileName = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QString("/plasma-dataengine-extsysmon.conf"); QSettings settings(fileName, QSettings::IniFormat); - qCDebug(LOG_AW) << "Configuration file" << settings.fileName(); + qCInfo(LOG_AW) << "Configuration file" << settings.fileName(); settings.beginGroup(QString("Configuration")); settings.setValue(QString("ACPIPATH"), configuration[QString("ACPIPATH")]); @@ -271,6 +264,7 @@ void AWActions::versionReplyRecieved(QNetworkReply *reply) const QVariantMap firstRelease = jsonDoc.toVariant().toList().first().toMap(); QString version = firstRelease[QString("tag_name")].toString(); version.remove(QString("V.")); + qCInfo(LOG_AW) << "Found version" << version; int old_major = QString(VERSION).split(QChar('.')).at(0).toInt(); int old_minor = QString(VERSION).split(QChar('.')).at(1).toInt(); diff --git a/sources/awesome-widget/plugin/awactions.h b/sources/awesome-widget/plugin/awactions.h index 3eae80b..aad01c6 100644 --- a/sources/awesome-widget/plugin/awactions.h +++ b/sources/awesome-widget/plugin/awactions.h @@ -30,8 +30,8 @@ class AWActions : public QObject Q_OBJECT public: - AWActions(QObject *parent = nullptr); - ~AWActions(); + explicit AWActions(QObject *parent = nullptr); + virtual ~AWActions(); Q_INVOKABLE void checkUpdates(); Q_INVOKABLE bool dropCache() const; diff --git a/sources/awesome-widget/plugin/awkeys.cpp b/sources/awesome-widget/plugin/awkeys.cpp index 2a9d2af..bb61cab 100644 --- a/sources/awesome-widget/plugin/awkeys.cpp +++ b/sources/awesome-widget/plugin/awkeys.cpp @@ -24,7 +24,6 @@ #include #include #include -#include #include #include #include @@ -44,21 +43,21 @@ AWKeys::AWKeys(QObject *parent) : QObject(parent) { - // debug - QProcessEnvironment environment = QProcessEnvironment::systemEnvironment(); - QString debugEnv = environment.value(QString("DEBUG"), QString("no")); - bool debug = (debugEnv == QString("yes")); + qCDebug(LOG_AW); // logging - const_cast(LOG_AW()).setEnabled(QtMsgType::QtDebugMsg, debug); + // disable info because QtMsgType has invalid enum order +#if QT_VERSION >= QT_VERSION_CHECK(5, 5, 0) + const_cast(LOG_AW()).setEnabled(QtMsgType::QtInfoMsg, false); +#endif /* QT_VERSION */ qSetMessagePattern(LOG_FORMAT); // backend - graphicalItems = new ExtItemAggregator(nullptr, QString("desktops"), debug); - extQuotes = new ExtItemAggregator(nullptr, QString("quotes"), debug); - extScripts = new ExtItemAggregator(nullptr, QString("scripts"), debug); - extUpgrade = new ExtItemAggregator(nullptr, QString("upgrade"), debug); - extWeather = new ExtItemAggregator(nullptr, QString("weather"), debug); + graphicalItems = new ExtItemAggregator(nullptr, QString("desktops")); + extQuotes = new ExtItemAggregator(nullptr, QString("quotes")); + extScripts = new ExtItemAggregator(nullptr, QString("scripts")); + extUpgrade = new ExtItemAggregator(nullptr, QString("upgrade")); + extWeather = new ExtItemAggregator(nullptr, QString("weather")); connect(this, SIGNAL(needToBeUpdated()), this, SLOT(dataUpdate())); } @@ -80,6 +79,7 @@ AWKeys::~AWKeys() void AWKeys::initKeys(const QString currentPattern) { qCDebug(LOG_AW); + qCDebug(LOG_AW) << "Pattern" << currentPattern; // init pattern = currentPattern; @@ -94,6 +94,7 @@ void AWKeys::initKeys(const QString currentPattern) void AWKeys::initTooltip(const QVariantMap tooltipParams) { qCDebug(LOG_AW); + qCDebug(LOG_AW) << "Tooltip parameters" << tooltipParams; if (toolTip != nullptr) { disconnect(toolTip, SIGNAL(toolTipPainted(QString)), this, SIGNAL(needToolTipToBeUpdated(QString))); @@ -109,6 +110,7 @@ void AWKeys::initTooltip(const QVariantMap tooltipParams) void AWKeys::setPopupEnabled(const bool popup) { qCDebug(LOG_AW); + qCDebug(LOG_AW) << "Is popup enabled" << popup; enablePopup = popup; } @@ -117,6 +119,7 @@ void AWKeys::setPopupEnabled(const bool popup) void AWKeys::setTranslateStrings(const bool translate) { qCDebug(LOG_AW); + qCDebug(LOG_AW) << "Is translation enabled" << translate; translateStrings = translate; } @@ -125,6 +128,7 @@ void AWKeys::setTranslateStrings(const bool translate) void AWKeys::setWrapNewLines(const bool wrap) { qCDebug(LOG_AW); + qCDebug(LOG_AW) << "Is wrapping enabled" << wrap; wrapNewLines = wrap; } @@ -698,15 +702,14 @@ QString AWKeys::valueByKey(QString key) const qCDebug(LOG_AW); qCDebug(LOG_AW) << "Requested key" << key; - key.remove(QRegExp(QString("^bar[0-9]{1,}"))); - - return values[key]; + return values[key.remove(QRegExp(QString("^bar[0-9]{1,}")))]; } void AWKeys::editItem(const QString type) { qCDebug(LOG_AW); + qCDebug(LOG_AW) << "Item type" << type; if (type == QString("graphicalitem")) { graphicalItems->setConfigArgs(dictKeys(true, QString("^(cpu(?!cl).*|gpu$|mem$|swap$|hdd[0-9].*|bat.*)"))); @@ -738,7 +741,7 @@ void AWKeys::loadKeysFromCache() QString fileName = QString("%1/awesomewidgets.ndx") .arg(QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation)); - qCDebug(LOG_AW) << "Cache file" << fileName; + qCInfo(LOG_AW) << "Cache file" << fileName; QSettings cache(fileName, QSettings::IniFormat); cache.beginGroup(QString("Disk")); @@ -777,9 +780,57 @@ void AWKeys::reinitKeys() { qCDebug(LOG_AW); - foundBars = findGraphicalItems(); - foundKeys = findKeys(); - foundLambdas = findLambdas(); + // init + QStringList allKeys = dictKeys(); + + // append lists + // bars + foundBars = [allKeys](QString pattern) { + QStringList selectedKeys; + foreach(QString key, allKeys) + if ((key.startsWith(QString("bar"))) && + (pattern.contains(QString("$%1").arg(key)))) { + qCInfo(LOG_AW) << "Found bar" << key; + selectedKeys.append(key); + } + if (selectedKeys.isEmpty()) qCWarning(LOG_AW) << "No bars found"; + return selectedKeys; + }(pattern); + + // main key list + foundKeys = [allKeys](QString pattern) { + QStringList selectedKeys; + foreach(QString key, allKeys) + if ((!key.startsWith(QString("bar"))) && + (pattern.contains(QString("$%1").arg(key)))) { + qCInfo(LOG_AW) << "Found key" << key; + selectedKeys.append(key); + } + if (selectedKeys.isEmpty()) qCWarning(LOG_AW) << "No keys found"; + return selectedKeys; + }(pattern); + + // lambdas + foundLambdas = [](QString pattern) { + QStringList selectedKeys; + // substring inside ${{ }} (with brackets) which should not contain ${{ + QRegularExpression lambdaRegexp(QString("\\$\\{\\{((?!\\$\\{\\{).)*?\\}\\}")); + lambdaRegexp.setPatternOptions(QRegularExpression::DotMatchesEverythingOption); + + QRegularExpressionMatchIterator it = lambdaRegexp.globalMatch(pattern); + while (it.hasNext()) { + QRegularExpressionMatch match = it.next(); + QString lambda = match.captured(); + // drop brakets + lambda.remove(QRegExp(QString("^\\$\\{\\{"))); + lambda.remove(QRegExp(QString("\\}\\}$"))); + // append + qCInfo(LOG_AW) << "Found lambda" << lambda; + selectedKeys.append(lambda); + } + if (selectedKeys.isEmpty()) qCWarning(LOG_AW) << "No lambdas found"; + return selectedKeys; + }(pattern); } @@ -790,7 +841,7 @@ void AWKeys::addKeyToCache(const QString type, const QString key) qCDebug(LOG_AW) << "Key" << key; QString fileName = QString("%1/awesomewidgets.ndx").arg(QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation)); - qCDebug(LOG_AW) << "Cache file" << fileName; + qCInfo(LOG_AW) << "Cache file" << fileName; QSettings cache(fileName, QSettings::IniFormat); cache.beginGroup(type); @@ -804,7 +855,7 @@ void AWKeys::addKeyToCache(const QString type, const QString key) foreach(QString dev, devices) { QString device = QString("/dev/%1").arg(dev); if (cachedValues.contains(device)) continue; - qCDebug(LOG_AW) << "Found new key" << device << "for type" << type; + 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")) { @@ -812,12 +863,12 @@ void AWKeys::addKeyToCache(const QString type, const QString key) foreach(QNetworkInterface interface, rawInterfaceList) { QString device = interface.name(); if (cachedValues.contains(device)) continue; - qCDebug(LOG_AW) << "Found new key" << device << "for type" << type; + 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 (cachedValues.contains(key)) return; - qCDebug(LOG_AW) << "Found new key" << key << "for type" << type; + qCInfo(LOG_AW) << "Found new key" << key << "for type" << type; cache.setValue(QString("%1").arg(cache.allKeys().count(), 3, 10, QChar('0')), key); } cache.endGroup(); @@ -834,12 +885,14 @@ QString AWKeys::parsePattern() const QString parsed = pattern; parsed.replace(QString("$$"), QString("$\\$\\")); + + // lambdas foreach(QString key, foundLambdas) parsed.replace(QString("${{%1}}").arg(key), [this](QString key) { QScriptEngine engine; foreach(QString lambdaKey, foundKeys) key.replace(QString("$%1").arg(lambdaKey), values[lambdaKey]); - qCDebug(LOG_AW) << "Expression" << key; + qCInfo(LOG_AW) << "Expression" << key; QScriptValue result = engine.evaluate(key); if (engine.hasUncaughtException()) { int line = engine.uncaughtExceptionLineNumber(); @@ -848,17 +901,22 @@ QString AWKeys::parsePattern() const } else return result.toString(); }(key)); + + // main keys foreach(QString key, foundKeys) parsed.replace(QString("$%1").arg(key), [](QString key, QString value) { if (!key.startsWith(QString("custom"))) value.replace(QString(" "), QString(" ")); return value; }(key, values[key])); + + // bars foreach(QString bar, foundBars) parsed.replace(QString("$%1").arg(bar), graphicalItems->itemByTag(bar)->image(valueByKey(bar).toFloat())); + + // prepare strings parsed.replace(QString("$\\$\\"), QString("$$")); - // wrap new lines if required if (wrapNewLines) parsed.replace(QString("\n"), QString("
")); return parsed; @@ -868,6 +926,8 @@ QString AWKeys::parsePattern() const float AWKeys::temperature(const float temp, const QString units) const { qCDebug(LOG_AW); + qCDebug(LOG_AW) << "Temperature value" << temp; + qCDebug(LOG_AW) << "Temperature units" << units; float converted = temp; if (units == QString("Celsius")) @@ -887,65 +947,3 @@ float AWKeys::temperature(const float temp, const QString units) const return converted; } - - -QStringList AWKeys::findGraphicalItems() const -{ - qCDebug(LOG_AW); - - QStringList orderedKeys; - foreach(GraphicalItem *item, graphicalItems->items()) - orderedKeys.append(item->tag()); - orderedKeys.sort(); - - QStringList selectedKeys; - for (int i=orderedKeys.count()-1; i>=0; i--) - if (pattern.contains(QString("$%1").arg(orderedKeys.at(i)))) { - qCDebug(LOG_AW) << "Found bar" << orderedKeys.at(i); - selectedKeys.append(orderedKeys.at(i)); - } - - return selectedKeys; -} - - -QStringList AWKeys::findKeys() const -{ - qCDebug(LOG_AW); - - QStringList selectedKeys; - foreach(QString key, dictKeys()) { - if (key.startsWith(QString("bar"))) continue; - if (pattern.contains(QString("$%1").arg(key))) { - qCDebug(LOG_AW) << "Found key" << key; - selectedKeys.append(key); - } - } - - return selectedKeys; -} - - -QStringList AWKeys::findLambdas() const -{ - qCDebug(LOG_AW); - - QStringList selectedKeys; - // substring inside ${{ }} (with brackets) which should not contain ${{ - QRegularExpression lambdaRegexp(QString("\\$\\{\\{((?!\\$\\{\\{).)*?\\}\\}")); - lambdaRegexp.setPatternOptions(QRegularExpression::DotMatchesEverythingOption); - - QRegularExpressionMatchIterator it = lambdaRegexp.globalMatch(pattern); - while (it.hasNext()) { - QRegularExpressionMatch match = it.next(); - QString lambda = match.captured(); - // drop brakets - lambda.remove(QRegExp(QString("^\\$\\{\\{"))); - lambda.remove(QRegExp(QString("\\}\\}$"))); - // append - qCDebug(LOG_AW) << "Found lambda" << lambda; - selectedKeys.append(lambda); - } - - return selectedKeys; -} diff --git a/sources/awesome-widget/plugin/awkeys.h b/sources/awesome-widget/plugin/awkeys.h index 9505876..e138403 100644 --- a/sources/awesome-widget/plugin/awkeys.h +++ b/sources/awesome-widget/plugin/awkeys.h @@ -40,8 +40,8 @@ class AWKeys : public QObject Q_OBJECT public: - AWKeys(QObject *parent = nullptr); - ~AWKeys(); + explicit AWKeys(QObject *parent = nullptr); + virtual ~AWKeys(); Q_INVOKABLE void initKeys(const QString currentPattern); Q_INVOKABLE void initTooltip(const QVariantMap tooltipParams); @@ -79,10 +79,6 @@ private: void addKeyToCache(const QString type, const QString key = QString("")); QString parsePattern() const; float temperature(const float temp, const QString units) const; - // find methods - QStringList findGraphicalItems() const; - QStringList findKeys() const; - QStringList findLambdas() const; // get methods AWToolTip *toolTip = nullptr; bool enablePopup = false; diff --git a/sources/awesome-widget/plugin/awtooltip.cpp b/sources/awesome-widget/plugin/awtooltip.cpp index 92b28e3..ea80094 100644 --- a/sources/awesome-widget/plugin/awtooltip.cpp +++ b/sources/awesome-widget/plugin/awtooltip.cpp @@ -18,7 +18,6 @@ #include "awtooltip.h" #include -#include #include #include "awdebug.h" @@ -28,14 +27,7 @@ AWToolTip::AWToolTip(QObject *parent, QVariantMap settings) : QObject(parent), configuration(qvariant_cast(settings)) { - // debug - QProcessEnvironment environment = QProcessEnvironment::systemEnvironment(); - QString debugEnv = environment.value(QString("DEBUG"), QString("no")); - bool debug = (debugEnv == QString("yes")); - - // logging - const_cast(LOG_AW()).setEnabled(QtMsgType::QtDebugMsg, debug); - qSetMessagePattern(LOG_FORMAT); + qCDebug(LOG_AW); toolTipScene = new QGraphicsScene(nullptr); toolTipView = new QGraphicsView(toolTipScene); @@ -145,6 +137,7 @@ QPixmap AWToolTip::image() float shift = i * 100.0; if (down) shift -= 100.0; for (int j=0; j netValues = data[QString("downTooltip")] + data[QString("upTooltip")]; + boundaries[QString("downTooltip")] = 1.2 * *std::max_element(netValues.cbegin(), netValues.cend()); boundaries[QString("upTooltip")] = boundaries[QString("downTooltip")]; } } diff --git a/sources/awesome-widget/plugin/awtooltip.h b/sources/awesome-widget/plugin/awtooltip.h index 5c4aa02..3f493b4 100644 --- a/sources/awesome-widget/plugin/awtooltip.h +++ b/sources/awesome-widget/plugin/awtooltip.h @@ -32,8 +32,8 @@ class AWToolTip : public QObject Q_OBJECT public: - AWToolTip(QObject *parent = nullptr, QVariantMap settings = QVariantMap()); - ~AWToolTip(); + explicit AWToolTip(QObject *parent = nullptr, QVariantMap settings = QVariantMap()); + virtual ~AWToolTip(); QSize getSize() const; QString htmlImage(); QPixmap image(); @@ -50,7 +50,7 @@ private: QGraphicsScene *toolTipScene = nullptr; QGraphicsView *toolTipView = nullptr; void setData(const QString source, float value, - const bool ac = true); + const bool dontInvert = true); // variables int counts = 0; QVariantHash configuration; diff --git a/sources/awesomewidgets/abstractextitem.cpp b/sources/awesomewidgets/abstractextitem.cpp index b5ce6ce..e7effa8 100644 --- a/sources/awesomewidgets/abstractextitem.cpp +++ b/sources/awesomewidgets/abstractextitem.cpp @@ -27,14 +27,14 @@ AbstractExtItem::AbstractExtItem(QWidget *parent, const QString desktopName, - const QStringList directories, const bool debugCmd) + const QStringList directories) : QDialog(parent), m_fileName(desktopName), m_dirs(directories) { - // logging - const_cast(LOG_ESM()).setEnabled(QtMsgType::QtDebugMsg, debugCmd); - qSetMessagePattern(LOG_FORMAT); + qCDebug(LOG_LIB); + qCDebug(LOG_LIB) << "Desktop name" << desktopName; + qCDebug(LOG_LIB) << "Directories" << directories; m_name = m_fileName; } @@ -42,16 +42,16 @@ AbstractExtItem::AbstractExtItem(QWidget *parent, const QString desktopName, AbstractExtItem::~AbstractExtItem() { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); } template -T *AbstractExtItem::copy(const QString fileName, const int number) +T *AbstractExtItem::copy(const QString _fileName, const int _number) { - Q_UNUSED(fileName) - Q_UNUSED(number) - qCDebug(LOG_ESM); + Q_UNUSED(_fileName) + Q_UNUSED(_number) + qCDebug(LOG_LIB); // an analog of pure virtual method return new T(); @@ -61,7 +61,7 @@ T *AbstractExtItem::copy(const QString fileName, const int number) int AbstractExtItem::apiVersion() const { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); return m_apiVersion; } @@ -69,7 +69,7 @@ int AbstractExtItem::apiVersion() const QString AbstractExtItem::comment() const { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); return m_comment; } @@ -77,7 +77,7 @@ QString AbstractExtItem::comment() const QStringList AbstractExtItem::directories() const { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); return m_dirs; } @@ -85,7 +85,7 @@ QStringList AbstractExtItem::directories() const QString AbstractExtItem::fileName() const { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); return m_fileName; } @@ -93,7 +93,7 @@ QString AbstractExtItem::fileName() const int AbstractExtItem::interval() const { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); return m_interval; } @@ -101,7 +101,7 @@ int AbstractExtItem::interval() const bool AbstractExtItem::isActive() const { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); return m_active; } @@ -109,7 +109,7 @@ bool AbstractExtItem::isActive() const QString AbstractExtItem::name() const { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); return m_name; } @@ -117,7 +117,7 @@ QString AbstractExtItem::name() const int AbstractExtItem::number() const { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); return m_number; } @@ -125,8 +125,8 @@ int AbstractExtItem::number() const QString AbstractExtItem::tag(const QString _type) const { - qCDebug(LOG_ESM); - qCDebug(LOG_ESM) << "Tag type" << _type; + qCDebug(LOG_LIB); + qCDebug(LOG_LIB) << "Tag type" << _type; return QString("%1%2").arg(_type).arg(m_number); } @@ -134,8 +134,8 @@ QString AbstractExtItem::tag(const QString _type) const void AbstractExtItem::setApiVersion(const int _apiVersion) { - qCDebug(LOG_ESM); - qCDebug(LOG_ESM) << "Version" << _apiVersion; + qCDebug(LOG_LIB); + qCDebug(LOG_LIB) << "Version" << _apiVersion; m_apiVersion = _apiVersion; } @@ -143,8 +143,8 @@ void AbstractExtItem::setApiVersion(const int _apiVersion) void AbstractExtItem::setActive(const bool _state) { - qCDebug(LOG_ESM); - qCDebug(LOG_ESM) << "State" << _state; + qCDebug(LOG_LIB); + qCDebug(LOG_LIB) << "State" << _state; m_active = _state; } @@ -152,8 +152,8 @@ void AbstractExtItem::setActive(const bool _state) void AbstractExtItem::setComment(const QString _comment) { - qCDebug(LOG_ESM); - qCDebug(LOG_ESM) << "Comment" << _comment; + qCDebug(LOG_LIB); + qCDebug(LOG_LIB) << "Comment" << _comment; m_comment = _comment; } @@ -161,8 +161,8 @@ void AbstractExtItem::setComment(const QString _comment) void AbstractExtItem::setInterval(const int _interval) { - qCDebug(LOG_ESM); - qCDebug(LOG_ESM) << "Interval" << _interval; + qCDebug(LOG_LIB); + qCDebug(LOG_LIB) << "Interval" << _interval; if (_interval <= 0) return; m_interval = _interval; @@ -171,8 +171,8 @@ void AbstractExtItem::setInterval(const int _interval) void AbstractExtItem::setName(const QString _name) { - qCDebug(LOG_ESM); - qCDebug(LOG_ESM) << "Name" << _name; + qCDebug(LOG_LIB); + qCDebug(LOG_LIB) << "Name" << _name; m_name = _name; } @@ -180,14 +180,14 @@ void AbstractExtItem::setName(const QString _name) void AbstractExtItem::setNumber(int _number) { - qCDebug(LOG_ESM); - qCDebug(LOG_ESM) << "Number" << _number; + qCDebug(LOG_LIB); + qCDebug(LOG_LIB) << "Number" << _number; if (_number == -1) _number = []() { - qCWarning(LOG_ESM) << "Number is empty, generate new one"; + qCWarning(LOG_LIB) << "Number is empty, generate new one"; qsrand(QTime::currentTime().msec()); int n = qrand() % 1000; - qCDebug(LOG_ESM) << "Generated number is" << n; + qCInfo(LOG_LIB) << "Generated number is" << n; return n; }(); @@ -197,7 +197,7 @@ void AbstractExtItem::setNumber(int _number) void AbstractExtItem::readConfiguration() { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); for (int i=m_dirs.count()-1; i>=0; i--) { if (!QDir(m_dirs.at(i)).entryList(QDir::Files).contains(m_fileName)) continue; @@ -217,11 +217,11 @@ void AbstractExtItem::readConfiguration() bool AbstractExtItem::tryDelete() const { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); foreach(QString dir, m_dirs) { bool status = QFile::remove(QString("%1/%2").arg(dir).arg(m_fileName)); - qCDebug(LOG_ESM) << "Remove file" << QString("%1/%2").arg(dir).arg(m_fileName) << status; + qCInfo(LOG_LIB) << "Remove file" << QString("%1/%2").arg(dir).arg(m_fileName) << status; } // check if exists @@ -233,10 +233,10 @@ bool AbstractExtItem::tryDelete() const void AbstractExtItem::writeConfiguration() const { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); QSettings settings(QString("%1/%2").arg(m_dirs.first()).arg(m_fileName), QSettings::IniFormat); - qCDebug(LOG_ESM) << "Configuration file" << settings.fileName(); + qCInfo(LOG_LIB) << "Configuration file" << settings.fileName(); settings.beginGroup(QString("Desktop Entry")); settings.setValue(QString("Encoding"), QString("UTF-8")); diff --git a/sources/awesomewidgets/abstractextitem.h b/sources/awesomewidgets/abstractextitem.h index fb8321f..ac9d145 100644 --- a/sources/awesomewidgets/abstractextitem.h +++ b/sources/awesomewidgets/abstractextitem.h @@ -38,10 +38,9 @@ class AbstractExtItem : public QDialog public: explicit AbstractExtItem(QWidget *parent = nullptr, const QString desktopName = QString(), - const QStringList directories = QStringList(), - const bool debugCmd = false); + const QStringList directories = QStringList()); virtual ~AbstractExtItem(); - template T *copy(const QString fileName, const int number); + template T *copy(const QString _fileName, const int _number); // get methods int apiVersion() const; QString comment() const; diff --git a/sources/awesomewidgets/abstractextitemaggregator.cpp b/sources/awesomewidgets/abstractextitemaggregator.cpp index 685e964..2889a68 100644 --- a/sources/awesomewidgets/abstractextitemaggregator.cpp +++ b/sources/awesomewidgets/abstractextitemaggregator.cpp @@ -26,12 +26,10 @@ #include "awdebug.h" -AbstractExtItemAggregator::AbstractExtItemAggregator(QWidget *parent, const bool debugCmd) +AbstractExtItemAggregator::AbstractExtItemAggregator(QWidget *parent) : QWidget(parent) { - // logging - const_cast(LOG_ESM()).setEnabled(QtMsgType::QtDebugMsg, debugCmd); - qSetMessagePattern(LOG_FORMAT); + qCDebug(LOG_LIB); dialog = new QDialog(this); widgetDialog = new QListWidget(dialog); @@ -55,7 +53,7 @@ AbstractExtItemAggregator::AbstractExtItemAggregator(QWidget *parent, const bool AbstractExtItemAggregator::~AbstractExtItemAggregator() { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); delete dialog; } @@ -63,7 +61,7 @@ AbstractExtItemAggregator::~AbstractExtItemAggregator() QString AbstractExtItemAggregator::getName() { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); bool ok; QString name = QInputDialog::getText(this, i18n("Enter file name"), @@ -78,7 +76,7 @@ QString AbstractExtItemAggregator::getName() QVariant AbstractExtItemAggregator::configArgs() const { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); return m_configArgs; } @@ -86,8 +84,8 @@ QVariant AbstractExtItemAggregator::configArgs() const void AbstractExtItemAggregator::setConfigArgs(const QVariant _configArgs) { - qCDebug(LOG_ESM); - qCDebug(LOG_ESM) << "Configuration arguments" << _configArgs; + qCDebug(LOG_LIB); + qCDebug(LOG_LIB) << "Configuration arguments" << _configArgs; m_configArgs = _configArgs; } @@ -96,7 +94,7 @@ void AbstractExtItemAggregator::setConfigArgs(const QVariant _configArgs) void AbstractExtItemAggregator::editItemActivated(QListWidgetItem *item) { Q_UNUSED(item) - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); return editItem(); } @@ -104,7 +102,7 @@ void AbstractExtItemAggregator::editItemActivated(QListWidgetItem *item) void AbstractExtItemAggregator::editItemButtonPressed(QAbstractButton *button) { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); if (static_cast(button) == copyButton) return copyItem(); diff --git a/sources/awesomewidgets/abstractextitemaggregator.h b/sources/awesomewidgets/abstractextitemaggregator.h index 0bb8366..7a23e5d 100644 --- a/sources/awesomewidgets/abstractextitemaggregator.h +++ b/sources/awesomewidgets/abstractextitemaggregator.h @@ -33,7 +33,7 @@ class AbstractExtItemAggregator : public QWidget Q_PROPERTY(QVariant configArgs READ configArgs WRITE setConfigArgs) public: - AbstractExtItemAggregator(QWidget *parent = nullptr, const bool debugCmd = false); + explicit AbstractExtItemAggregator(QWidget *parent = nullptr); virtual ~AbstractExtItemAggregator(); QString getName(); // ui diff --git a/sources/awesomewidgets/extitemaggregator.h b/sources/awesomewidgets/extitemaggregator.h index 7a3c25a..d9f0c16 100644 --- a/sources/awesomewidgets/extitemaggregator.h +++ b/sources/awesomewidgets/extitemaggregator.h @@ -33,13 +33,17 @@ template class ExtItemAggregator : public AbstractExtItemAggregator { public: - explicit ExtItemAggregator(QWidget *parent, const QString type, - const bool debugCmd = false) - : AbstractExtItemAggregator(parent, debugCmd), + explicit ExtItemAggregator(QWidget *parent, const QString type) + : AbstractExtItemAggregator(parent), m_type(type) { - // logging - const_cast(LOG_ESM()).setEnabled(QtMsgType::QtDebugMsg, debugCmd); + qCDebug(LOG_LIB); + qCDebug(LOG_LIB) << "Type" << type; + + // disable info because QtMsgType has invalid enum order +#if QT_VERSION >= QT_VERSION_CHECK(5, 5, 0) + const_cast(LOG_LIB()).setEnabled(QtMsgType::QtInfoMsg, false); +#endif /* QT_VERSION */ qSetMessagePattern(LOG_FORMAT); initItems(); @@ -47,23 +51,23 @@ public: virtual ~ExtItemAggregator() { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); m_items.clear(); } void editItems() { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); repaint(); int ret = dialog->exec(); - qCDebug(LOG_ESM) << "Dialog returns" << ret; + qCInfo(LOG_LIB) << "Dialog returns" << ret; }; void initItems() { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); m_items.clear(); m_items = getItems(); @@ -71,7 +75,8 @@ public: T *itemByTag(const QString _tag) const { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); + qCDebug(LOG_LIB) << "Tag" << _tag; T *found = nullptr; foreach(T *item, m_items) { @@ -79,13 +84,16 @@ public: found = item; break; } + if (found == nullptr) + qCWarning(LOG_LIB) << "Could not find item by tag" << _tag; return found; } T *itemByTagNumber(const int _number) const { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); + qCDebug(LOG_LIB) << "Number" << _number; T *found = nullptr; foreach(T *item, m_items) { @@ -93,13 +101,15 @@ public: found = item; break; } + if (found == nullptr) + qCWarning(LOG_LIB) << "Could not find item by number" << _number; return found; } T *itemFromWidget() const { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); QListWidgetItem *widgetItem = widgetDialog->currentItem(); if (widgetItem == nullptr) return nullptr; @@ -110,20 +120,22 @@ public: found = item; break; } + if (found == nullptr) + qCWarning(LOG_LIB) << "Could not find item by name" << widgetItem->text(); return found; }; QList items() const { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); return m_items; }; int uniqNumber() const { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); QList tagList; foreach(T *item, m_items) tagList.append(item->number()); @@ -140,7 +152,7 @@ private: // init method QList getItems() { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); // create directory at $HOME QString localDir = QString("%1/awesomewidgets/%2") @@ -148,7 +160,7 @@ private: .arg(m_type); QDir localDirectory; if (localDirectory.mkpath(localDir)) - qCDebug(LOG_ESM) << "Created directory" << localDir; + qCInfo(LOG_LIB) << "Created directory" << localDir; QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QString("awesomewidgets/%1").arg(m_type), @@ -160,9 +172,9 @@ private: foreach(QString file, files) { if (!file.endsWith(QString(".desktop"))) continue; if (names.contains(file)) continue; - qCDebug(LOG_ESM) << "Found file" << file << "in" << dir; + qCInfo(LOG_LIB) << "Found file" << file << "in" << dir; names.append(file); - items.append(new T(this, file, dirs, LOG_ESM().isDebugEnabled())); + items.append(new T(this, file, dirs)); } } @@ -171,6 +183,8 @@ private: void repaint() { + qCDebug(LOG_LIB); + widgetDialog->clear(); foreach(T *_item, m_items) { QListWidgetItem *item = new QListWidgetItem(_item->fileName(), widgetDialog); @@ -186,12 +200,15 @@ private: // methods void copyItem() { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); T *source = itemFromWidget(); QString fileName = getName(); int number = uniqNumber(); - if ((source == nullptr) || (fileName.isEmpty())) return; + if ((source == nullptr) || (fileName.isEmpty())) { + qCWarning(LOG_LIB) << "Nothing to copy"; + return; + } T *newItem = source->copy(fileName, number); if (newItem->showConfiguration(configArgs()) == 1) { @@ -202,16 +219,19 @@ private: void createItem() { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); QString fileName = getName(); int number = uniqNumber(); QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QString("awesomewidgets/%1").arg(m_type), QStandardPaths::LocateDirectory); - if (fileName.isEmpty()) return; + if (fileName.isEmpty()) { + qCWarning(LOG_LIB) << "Nothing to create"; + return; + }; - T *newItem = new T(this, fileName, dirs, LOG_ESM().isDebugEnabled()); + T *newItem = new T(this, fileName, dirs); newItem->setNumber(number); if (newItem->showConfiguration(configArgs()) == 1) { initItems(); @@ -221,10 +241,13 @@ private: void deleteItem() { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); T *source = itemFromWidget(); - if (source == nullptr) return; + if (source == nullptr) { + qCWarning(LOG_LIB) << "Nothing to delete"; + return; + }; if (source->tryDelete()) { initItems(); @@ -234,10 +257,13 @@ private: void editItem() { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); T *source = itemFromWidget(); - if (source == nullptr) return; + if (source == nullptr) { + qCWarning(LOG_LIB) << "Nothing to edit"; + return; + }; if (source->showConfiguration(configArgs()) == 1) { initItems(); diff --git a/sources/awesomewidgets/extquotes.cpp b/sources/awesomewidgets/extquotes.cpp index f164bfc..bef0fd9 100644 --- a/sources/awesomewidgets/extquotes.cpp +++ b/sources/awesomewidgets/extquotes.cpp @@ -34,13 +34,11 @@ ExtQuotes::ExtQuotes(QWidget *parent, const QString quotesName, - const QStringList directories, const bool debugCmd) - : AbstractExtItem(parent, quotesName, directories, debugCmd), + const QStringList directories) + : AbstractExtItem(parent, quotesName, directories), ui(new Ui::ExtQuotes) { - // logging - const_cast(LOG_ESM()).setEnabled(QtMsgType::QtDebugMsg, debugCmd); - qSetMessagePattern(LOG_FORMAT); + qCDebug(LOG_LIB); readConfiguration(); ui->setupUi(this); @@ -64,7 +62,7 @@ ExtQuotes::ExtQuotes(QWidget *parent, const QString quotesName, ExtQuotes::~ExtQuotes() { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); disconnect(manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(quotesReplyReceived(QNetworkReply *))); @@ -73,18 +71,19 @@ ExtQuotes::~ExtQuotes() } -ExtQuotes *ExtQuotes::copy(const QString fileName, const int number) +ExtQuotes *ExtQuotes::copy(const QString _fileName, const int _number) { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); + qCDebug(LOG_LIB) << "File" << _fileName; + qCDebug(LOG_LIB) << "Number" << _number; - ExtQuotes *item = new ExtQuotes(static_cast(parent()), fileName, - directories(), LOG_ESM().isDebugEnabled()); + ExtQuotes *item = new ExtQuotes(static_cast(parent()), _fileName, directories()); item->setActive(isActive()); item->setApiVersion(apiVersion()); item->setComment(comment()); item->setInterval(interval()); item->setName(name()); - item->setNumber(number); + item->setNumber(_number); item->setTicker(ticker()); return item; @@ -93,7 +92,7 @@ ExtQuotes *ExtQuotes::copy(const QString fileName, const int number) QString ExtQuotes::ticker() const { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); return m_ticker; } @@ -101,7 +100,7 @@ QString ExtQuotes::ticker() const QString ExtQuotes::uniq() const { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); return m_ticker; } @@ -109,8 +108,8 @@ QString ExtQuotes::uniq() const void ExtQuotes::setTicker(const QString _ticker) { - qCDebug(LOG_ESM); - qCDebug(LOG_ESM) << "Ticker" << _ticker; + qCDebug(LOG_LIB); + qCDebug(LOG_LIB) << "Ticker" << _ticker; m_ticker = _ticker; } @@ -118,7 +117,7 @@ void ExtQuotes::setTicker(const QString _ticker) void ExtQuotes::readConfiguration() { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); AbstractExtItem::readConfiguration(); for (int i=directories().count()-1; i>=0; i--) { @@ -132,6 +131,7 @@ void ExtQuotes::readConfiguration() // update for current API if ((apiVersion() > 0) && (apiVersion() < AWEQAPI)) { + qCWarning(LOG_LIB) << "Bump API version from" << apiVersion() << "to" << AWEQAPI; setApiVersion(AWEQAPI); writeConfiguration(); } @@ -140,11 +140,11 @@ void ExtQuotes::readConfiguration() QVariantHash ExtQuotes::run() { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); if ((!isActive()) || (isRunning)) return values; if (times == 1) { - qCDebug(LOG_ESM) << "Send request"; + qCInfo(LOG_LIB) << "Send request"; isRunning = true; QNetworkReply *reply = manager->get(QNetworkRequest(QUrl(url()))); new QReplyTimeout(reply, 1000); @@ -161,7 +161,7 @@ QVariantHash ExtQuotes::run() int ExtQuotes::showConfiguration(const QVariant args) { Q_UNUSED(args) - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); ui->lineEdit_name->setText(name()); ui->lineEdit_comment->setText(comment()); @@ -187,11 +187,11 @@ int ExtQuotes::showConfiguration(const QVariant args) void ExtQuotes::writeConfiguration() const { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); AbstractExtItem::writeConfiguration(); QSettings settings(QString("%1/%2").arg(directories().first()).arg(fileName()), QSettings::IniFormat); - qCDebug(LOG_ESM) << "Configuration file" << settings.fileName(); + qCInfo(LOG_LIB) << "Configuration file" << settings.fileName(); settings.beginGroup(QString("Desktop Entry")); settings.setValue(QString("X-AW-Ticker"), m_ticker); @@ -202,9 +202,9 @@ void ExtQuotes::writeConfiguration() const void ExtQuotes::quotesReplyReceived(QNetworkReply *reply) { - qCDebug(LOG_ESM); - qCDebug(LOG_ESM) << "Return code" << reply->error(); - qCDebug(LOG_ESM) << "Reply error message" << reply->errorString(); + qCDebug(LOG_LIB); + qCDebug(LOG_LIB) << "Return code" << reply->error(); + qCDebug(LOG_LIB) << "Reply error message" << reply->errorString(); isRunning = false; QJsonParseError error; @@ -212,7 +212,7 @@ void ExtQuotes::quotesReplyReceived(QNetworkReply *reply) reply->deleteLater(); if ((reply->error() != QNetworkReply::NoError) || (error.error != QJsonParseError::NoError)) { - qCWarning(LOG_ESM) << "Parse error" << error.errorString(); + qCWarning(LOG_LIB) << "Parse error" << error.errorString(); return; } QVariantMap jsonQuotes = jsonDoc.toVariant().toMap()[QString("query")].toMap(); @@ -222,21 +222,21 @@ void ExtQuotes::quotesReplyReceived(QNetworkReply *reply) // ask value = jsonQuotes[QString("Ask")].toString().toFloat(); values[tag(QString("askchg"))] = values[QString("ask")].toFloat() == 0.0 ? 0.0 : - value - values[QString("ask")].toFloat(); + value - values[QString("ask")].toFloat(); values[tag(QString("percaskchg"))] = 100.0 * values[QString("askchg")].toFloat() / values[QString("ask")].toFloat(); values[tag(QString("ask"))] = value; // bid value = jsonQuotes[QString("Bid")].toString().toFloat(); values[tag(QString("bidchg"))] = values[QString("bid")].toFloat() == 0.0 ? 0.0 : - value - values[QString("bid")].toFloat(); + value - values[QString("bid")].toFloat(); values[tag(QString("percbidchg"))] = 100.0 * values[QString("bidchg")].toFloat() / values[QString("bid")].toFloat(); values[tag(QString("bid"))] = value; // last trade value = jsonQuotes[QString("LastTradePriceOnly")].toString().toFloat(); values[tag(QString("pricechg"))] = values[QString("price")].toFloat() == 0.0 ? 0.0 : - value - values[QString("price")].toFloat(); + value - values[QString("price")].toFloat(); values[tag(QString("percpricechg"))] = 100.0 * values[QString("pricechg")].toFloat() / values[QString("price")].toFloat(); values[tag(QString("price"))] = value; } @@ -244,7 +244,7 @@ void ExtQuotes::quotesReplyReceived(QNetworkReply *reply) void ExtQuotes::translate() { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); ui->label_name->setText(i18n("Name")); ui->label_comment->setText(i18n("Comment")); @@ -258,11 +258,11 @@ void ExtQuotes::translate() QString ExtQuotes::url() const { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); QString apiUrl = QString(YAHOO_URL); apiUrl.replace(QString("$TICKER"), m_ticker); - qCDebug(LOG_ESM) << "API url" << apiUrl; + qCInfo(LOG_LIB) << "API url" << apiUrl; return apiUrl; } diff --git a/sources/awesomewidgets/extquotes.h b/sources/awesomewidgets/extquotes.h index 4b90f05..1e74b54 100644 --- a/sources/awesomewidgets/extquotes.h +++ b/sources/awesomewidgets/extquotes.h @@ -37,10 +37,9 @@ class ExtQuotes : public AbstractExtItem public: explicit ExtQuotes(QWidget *parent = nullptr, const QString quotesName = QString(), - const QStringList directories = QStringList(), - const bool debugCmd = false); + const QStringList directories = QStringList()); virtual ~ExtQuotes(); - ExtQuotes *copy(const QString fileName, const int number); + ExtQuotes *copy(const QString _fileName, const int _number); // get methods QString ticker() const; QString uniq() const; diff --git a/sources/awesomewidgets/extscript.cpp b/sources/awesomewidgets/extscript.cpp index 37735fe..3d36f60 100644 --- a/sources/awesomewidgets/extscript.cpp +++ b/sources/awesomewidgets/extscript.cpp @@ -32,13 +32,11 @@ ExtScript::ExtScript(QWidget *parent, const QString scriptName, - const QStringList directories, const bool debugCmd) - : AbstractExtItem(parent, scriptName, directories, debugCmd), + const QStringList directories) + : AbstractExtItem(parent, scriptName, directories), ui(new Ui::ExtScript) { - // logging - const_cast(LOG_ESM()).setEnabled(QtMsgType::QtDebugMsg, debugCmd); - qSetMessagePattern(LOG_FORMAT); + qCDebug(LOG_LIB); readConfiguration(); readJsonFilters(); @@ -55,7 +53,7 @@ ExtScript::ExtScript(QWidget *parent, const QString scriptName, ExtScript::~ExtScript() { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); process->kill(); delete process; @@ -63,12 +61,13 @@ ExtScript::~ExtScript() } -ExtScript *ExtScript::copy(const QString fileName, const int number) +ExtScript *ExtScript::copy(const QString _fileName, const int _number) { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); + qCDebug(LOG_LIB) << "File" << _fileName; + qCDebug(LOG_LIB) << "Number" << _number; - ExtScript *item = new ExtScript(static_cast(parent()), fileName, - directories(), LOG_ESM().isDebugEnabled()); + ExtScript *item = new ExtScript(static_cast(parent()), _fileName, directories()); item->setActive(isActive()); item->setApiVersion(apiVersion()); item->setComment(comment()); @@ -76,7 +75,7 @@ ExtScript *ExtScript::copy(const QString fileName, const int number) item->setHasOutput(hasOutput()); item->setInterval(interval()); item->setName(name()); - item->setNumber(number); + item->setNumber(_number); item->setPrefix(prefix()); item->setRedirect(redirect()); @@ -86,7 +85,7 @@ ExtScript *ExtScript::copy(const QString fileName, const int number) QString ExtScript::executable() const { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); return m_executable; } @@ -94,7 +93,7 @@ QString ExtScript::executable() const QStringList ExtScript::filters() const { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); return m_filters; } @@ -102,7 +101,7 @@ QStringList ExtScript::filters() const bool ExtScript::hasOutput() const { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); return m_output; } @@ -110,7 +109,7 @@ bool ExtScript::hasOutput() const QString ExtScript::prefix() const { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); return m_prefix; } @@ -118,7 +117,7 @@ QString ExtScript::prefix() const ExtScript::Redirect ExtScript::redirect() const { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); return m_redirect; } @@ -126,7 +125,7 @@ ExtScript::Redirect ExtScript::redirect() const QString ExtScript::uniq() const { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); return m_executable; } @@ -134,7 +133,7 @@ QString ExtScript::uniq() const QString ExtScript::strRedirect() const { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); QString value; switch (m_redirect) { @@ -156,8 +155,8 @@ QString ExtScript::strRedirect() const void ExtScript::setExecutable(const QString _executable) { - qCDebug(LOG_ESM); - qCDebug(LOG_ESM) << "Executable" << _executable; + qCDebug(LOG_LIB); + qCDebug(LOG_LIB) << "Executable" << _executable; m_executable = _executable; } @@ -165,18 +164,20 @@ void ExtScript::setExecutable(const QString _executable) void ExtScript::setFilters(const QStringList _filters) { - qCDebug(LOG_ESM); - qCDebug(LOG_ESM) << "Filters" << _filters; + qCDebug(LOG_LIB); + qCDebug(LOG_LIB) << "Filters" << _filters; - foreach(QString filter, _filters) - updateFilter(filter); + std::for_each(_filters.cbegin(), _filters.cend(), + [this](QString filter) { return updateFilter(filter); }); +// foreach(QString filter, _filters) +// updateFilter(filter); } void ExtScript::setHasOutput(const bool _state) { - qCDebug(LOG_ESM); - qCDebug(LOG_ESM) << "State" << _state; + qCDebug(LOG_LIB); + qCDebug(LOG_LIB) << "State" << _state; m_output = _state; } @@ -184,8 +185,8 @@ void ExtScript::setHasOutput(const bool _state) void ExtScript::setPrefix(const QString _prefix) { - qCDebug(LOG_ESM); - qCDebug(LOG_ESM) << "Prefix" << _prefix; + qCDebug(LOG_LIB); + qCDebug(LOG_LIB) << "Prefix" << _prefix; m_prefix = _prefix; } @@ -193,8 +194,8 @@ void ExtScript::setPrefix(const QString _prefix) void ExtScript::setRedirect(const Redirect _redirect) { - qCDebug(LOG_ESM); - qCDebug(LOG_ESM) << "Redirect" << _redirect; + qCDebug(LOG_LIB); + qCDebug(LOG_LIB) << "Redirect" << _redirect; m_redirect = _redirect; } @@ -202,8 +203,8 @@ void ExtScript::setRedirect(const Redirect _redirect) void ExtScript::setStrRedirect(const QString _redirect) { - qCDebug(LOG_ESM); - qCDebug(LOG_ESM) << "Redirect" << _redirect; + qCDebug(LOG_LIB); + qCDebug(LOG_LIB) << "Redirect" << _redirect; if (_redirect == QString("stdout2sdterr")) m_redirect = stdout2stderr; @@ -216,14 +217,14 @@ void ExtScript::setStrRedirect(const QString _redirect) QString ExtScript::applyFilters(QString _value) const { - qCDebug(LOG_ESM); - qCDebug(LOG_ESM) << "Value" << _value; + qCDebug(LOG_LIB); + qCDebug(LOG_LIB) << "Value" << _value; foreach(QString filt, m_filters) { - qCDebug(LOG_ESM) << "Found filter" << filt; + qCInfo(LOG_LIB) << "Found filter" << filt; QVariantMap filter = jsonFilters[filt].toMap(); if (filter.isEmpty()) { - qCWarning(LOG_ESM) << "Could not find filter in the json"; + qCWarning(LOG_LIB) << "Could not find filter" << _value << "in the json"; continue; } foreach(QString f, filter.keys()) @@ -236,9 +237,9 @@ QString ExtScript::applyFilters(QString _value) const void ExtScript::updateFilter(const QString _filter, const bool _add) { - qCDebug(LOG_ESM); - qCDebug(LOG_ESM) << "Filter" << _filter; - qCDebug(LOG_ESM) << "Should be added" << _add; + qCDebug(LOG_LIB); + qCDebug(LOG_LIB) << "Filter" << _filter; + qCDebug(LOG_LIB) << "Should be added" << _add; if (_add) { if (m_filters.contains(_filter)) return; @@ -251,7 +252,7 @@ void ExtScript::updateFilter(const QString _filter, const bool _add) void ExtScript::readConfiguration() { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); AbstractExtItem::readConfiguration(); for (int i=directories().count()-1; i>=0; i--) { @@ -274,6 +275,7 @@ void ExtScript::readConfiguration() // update for current API if ((apiVersion() > 0) && (apiVersion() < AWESAPI)) { + qCWarning(LOG_LIB) << "Bump API version from" << apiVersion() << "to" << AWESAPI; setApiVersion(AWESAPI); writeConfiguration(); } @@ -282,39 +284,41 @@ void ExtScript::readConfiguration() void ExtScript::readJsonFilters() { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); QString fileName = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QString("awesomewidgets/scripts/awesomewidgets-extscripts-filters.json")); - qCDebug(LOG_ESM) << "Configuration file" << fileName; + qCInfo(LOG_LIB) << "Configuration file" << fileName; QFile jsonFile(fileName); - if (!jsonFile.open(QIODevice::ReadOnly | QIODevice::Text)) + if (!jsonFile.open(QIODevice::ReadOnly | QIODevice::Text)) { + qCWarning(LOG_LIB) << "Could not open" << fileName; return; + } QString jsonText = jsonFile.readAll(); jsonFile.close(); QJsonParseError error; QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonText.toUtf8(), &error); if (error.error != QJsonParseError::NoError) { - qCWarning(LOG_ESM) << "Json parse error" << error.errorString(); + qCWarning(LOG_LIB) << "Parse error" << error.errorString(); return; } jsonFilters = jsonDoc.toVariant().toMap(); - qCDebug(LOG_ESM) << "Filters" << jsonFilters; + qCDebug(LOG_LIB) << "Filters" << jsonFilters; } QVariantHash ExtScript::run() { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); if (!isActive()) return value; if ((times == 1) && (process->state() == QProcess::NotRunning)) { QStringList cmdList; if (!m_prefix.isEmpty()) cmdList.append(m_prefix); cmdList.append(m_executable); - qCDebug(LOG_ESM) << "cmd" << cmdList.join(QChar(' ')); + qCInfo(LOG_LIB) << "Run cmd" << cmdList.join(QChar(' ')); process->start(cmdList.join(QChar(' '))); } else if (times >= interval()) times = 0; @@ -327,7 +331,7 @@ QVariantHash ExtScript::run() int ExtScript::showConfiguration(const QVariant args) { Q_UNUSED(args) - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); ui->lineEdit_name->setText(name()); ui->lineEdit_comment->setText(comment()); @@ -367,11 +371,11 @@ int ExtScript::showConfiguration(const QVariant args) void ExtScript::writeConfiguration() const { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); AbstractExtItem::writeConfiguration(); QSettings settings(QString("%1/%2").arg(directories().first()).arg(fileName()), QSettings::IniFormat); - qCDebug(LOG_ESM) << "Configuration file" << settings.fileName(); + qCInfo(LOG_LIB) << "Configuration file" << settings.fileName(); settings.beginGroup(QString("Desktop Entry")); settings.setValue(QString("Exec"), m_executable); @@ -387,13 +391,13 @@ void ExtScript::writeConfiguration() const void ExtScript::updateValue() { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); - qCDebug(LOG_ESM) << "Cmd returns" << process->exitCode(); + qCInfo(LOG_LIB) << "Cmd returns" << process->exitCode(); QString qdebug = QTextCodec::codecForMib(106)->toUnicode(process->readAllStandardError()).trimmed(); - qCDebug(LOG_ESM) << "Error" << qdebug; + qCInfo(LOG_LIB) << "Error" << qdebug; QString qoutput = QTextCodec::codecForMib(106)->toUnicode(process->readAllStandardOutput()).trimmed(); - qCDebug(LOG_ESM) << "Error" << qoutput; + qCInfo(LOG_LIB) << "Error" << qoutput; QString strValue; switch (m_redirect) { @@ -415,7 +419,7 @@ void ExtScript::updateValue() void ExtScript::translate() { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); ui->label_name->setText(i18n("Name")); ui->label_comment->setText(i18n("Comment")); diff --git a/sources/awesomewidgets/extscript.h b/sources/awesomewidgets/extscript.h index 9a3bd13..399afe3 100644 --- a/sources/awesomewidgets/extscript.h +++ b/sources/awesomewidgets/extscript.h @@ -45,10 +45,9 @@ public: }; explicit ExtScript(QWidget *parent = nullptr, const QString scriptName = QString(), - const QStringList directories = QStringList(), - const bool debugCmd = false); - ~ExtScript(); - ExtScript *copy(const QString fileName, const int number); + const QStringList directories = QStringList()); + virtual ~ExtScript(); + ExtScript *copy(const QString _fileName, const int _number); // get methods QString executable() const; QStringList filters() const; diff --git a/sources/awesomewidgets/extupgrade.cpp b/sources/awesomewidgets/extupgrade.cpp index 31b39bf..2db5d95 100644 --- a/sources/awesomewidgets/extupgrade.cpp +++ b/sources/awesomewidgets/extupgrade.cpp @@ -30,13 +30,11 @@ ExtUpgrade::ExtUpgrade(QWidget *parent, const QString upgradeName, - const QStringList directories, const bool debugCmd) - : AbstractExtItem(parent, upgradeName, directories, debugCmd), + const QStringList directories) + : AbstractExtItem(parent, upgradeName, directories), ui(new Ui::ExtUpgrade) { - // logging - const_cast(LOG_ESM()).setEnabled(QtMsgType::QtDebugMsg, debugCmd); - qSetMessagePattern(LOG_FORMAT); + qCDebug(LOG_LIB); readConfiguration(); ui->setupUi(this); @@ -52,7 +50,7 @@ ExtUpgrade::ExtUpgrade(QWidget *parent, const QString upgradeName, ExtUpgrade::~ExtUpgrade() { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); process->kill(); delete process; @@ -60,12 +58,13 @@ ExtUpgrade::~ExtUpgrade() } -ExtUpgrade *ExtUpgrade::copy(const QString fileName, const int number) +ExtUpgrade *ExtUpgrade::copy(const QString _fileName, const int _number) { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); + qCDebug(LOG_LIB) << "File" << _fileName; + qCDebug(LOG_LIB) << "Number" << _number; - ExtUpgrade *item = new ExtUpgrade(static_cast(parent()), fileName, - directories(), LOG_ESM().isDebugEnabled()); + ExtUpgrade *item = new ExtUpgrade(static_cast(parent()), _fileName, directories()); item->setActive(isActive()); item->setApiVersion(apiVersion()); item->setComment(comment()); @@ -73,7 +72,7 @@ ExtUpgrade *ExtUpgrade::copy(const QString fileName, const int number) item->setFilter(filter()); item->setInterval(interval()); item->setName(name()); - item->setNumber(number); + item->setNumber(_number); item->setNull(null()); return item; @@ -82,7 +81,7 @@ ExtUpgrade *ExtUpgrade::copy(const QString fileName, const int number) QString ExtUpgrade::executable() const { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); return m_executable; } @@ -90,7 +89,7 @@ QString ExtUpgrade::executable() const QString ExtUpgrade::filter() const { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); return m_filter; } @@ -98,7 +97,7 @@ QString ExtUpgrade::filter() const int ExtUpgrade::null() const { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); return m_null; } @@ -106,7 +105,7 @@ int ExtUpgrade::null() const QString ExtUpgrade::uniq() const { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); return m_executable; } @@ -114,8 +113,8 @@ QString ExtUpgrade::uniq() const void ExtUpgrade::setExecutable(const QString _executable) { - qCDebug(LOG_ESM); - qCDebug(LOG_ESM) << "Executable" << _executable; + qCDebug(LOG_LIB); + qCDebug(LOG_LIB) << "Executable" << _executable; m_executable = _executable; } @@ -123,8 +122,8 @@ void ExtUpgrade::setExecutable(const QString _executable) void ExtUpgrade::setFilter(const QString _filter) { - qCDebug(LOG_ESM); - qCDebug(LOG_ESM) << "Filter" << _filter; + qCDebug(LOG_LIB); + qCDebug(LOG_LIB) << "Filter" << _filter; m_filter = _filter; } @@ -132,8 +131,8 @@ void ExtUpgrade::setFilter(const QString _filter) void ExtUpgrade::setNull(const int _null) { - qCDebug(LOG_ESM); - qCDebug(LOG_ESM) << "Null lines" << _null; + qCDebug(LOG_LIB); + qCDebug(LOG_LIB) << "Null lines" << _null; if (_null < 0) return; m_null = _null; @@ -142,7 +141,7 @@ void ExtUpgrade::setNull(const int _null) void ExtUpgrade::readConfiguration() { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); AbstractExtItem::readConfiguration(); for (int i=directories().count()-1; i>=0; i--) { @@ -159,6 +158,7 @@ void ExtUpgrade::readConfiguration() // update for current API if ((apiVersion() > 0) && (apiVersion() < AWEUAPI)) { + qCWarning(LOG_LIB) << "Bump API version from" << apiVersion() << "to" << AWEUAPI; setApiVersion(AWEUAPI); writeConfiguration(); } @@ -167,12 +167,14 @@ void ExtUpgrade::readConfiguration() QVariantHash ExtUpgrade::run() { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); if (!isActive()) return value; - if ((times == 1) && (process->state() == QProcess::NotRunning)) - process->start(QString("sh -c \"%1\"").arg(m_executable)); - else if (times >= interval()) + if ((times == 1) && (process->state() == QProcess::NotRunning)) { + QString cmd = QString("sh -c \"%1\"").arg(m_executable); + qCInfo(LOG_LIB) << "Run cmd" << cmd; + process->start(cmd); + } else if (times >= interval()) times = 0; times++; @@ -183,7 +185,7 @@ QVariantHash ExtUpgrade::run() int ExtUpgrade::showConfiguration(const QVariant args) { Q_UNUSED(args) - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); ui->lineEdit_name->setText(name()); ui->lineEdit_comment->setText(comment()); @@ -213,11 +215,11 @@ int ExtUpgrade::showConfiguration(const QVariant args) void ExtUpgrade::writeConfiguration() const { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); AbstractExtItem::writeConfiguration(); QSettings settings(QString("%1/%2").arg(directories().first()).arg(fileName()), QSettings::IniFormat); - qCDebug(LOG_ESM) << "Configuration file" << settings.fileName(); + qCInfo(LOG_LIB) << "Configuration file" << settings.fileName(); settings.beginGroup(QString("Desktop Entry")); settings.setValue(QString("Exec"), m_executable); @@ -231,10 +233,10 @@ void ExtUpgrade::writeConfiguration() const void ExtUpgrade::updateValue() { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); - qCDebug(LOG_ESM) << "Cmd returns" << process->exitCode(); - qCDebug(LOG_ESM) << "Error" << process->readAllStandardError(); + qCInfo(LOG_LIB) << "Cmd returns" << process->exitCode(); + qCInfo(LOG_LIB) << "Error" << process->readAllStandardError(); QString qoutput = QTextCodec::codecForMib(106)->toUnicode(process->readAllStandardOutput()).trimmed(); value[tag(QString("pkgcount"))] = [this](QString output) { @@ -247,7 +249,7 @@ void ExtUpgrade::updateValue() void ExtUpgrade::translate() { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); ui->label_name->setText(i18n("Name")); ui->label_comment->setText(i18n("Comment")); diff --git a/sources/awesomewidgets/extupgrade.h b/sources/awesomewidgets/extupgrade.h index 4b88560..8b09286 100644 --- a/sources/awesomewidgets/extupgrade.h +++ b/sources/awesomewidgets/extupgrade.h @@ -36,10 +36,9 @@ class ExtUpgrade : public AbstractExtItem public: explicit ExtUpgrade(QWidget *parent = nullptr, const QString upgradeName = QString(), - const QStringList directories = QStringList(), - const bool debugCmd = false); - ~ExtUpgrade(); - ExtUpgrade *copy(const QString fileName, const int number); + const QStringList directories = QStringList()); + virtual ~ExtUpgrade(); + ExtUpgrade *copy(const QString _fileName, const int _number); // get methods QString executable() const; QString filter() const; diff --git a/sources/awesomewidgets/extweather.cpp b/sources/awesomewidgets/extweather.cpp index 4a5df25..49a6068 100644 --- a/sources/awesomewidgets/extweather.cpp +++ b/sources/awesomewidgets/extweather.cpp @@ -34,13 +34,11 @@ ExtWeather::ExtWeather(QWidget *parent, const QString weatherName, - const QStringList directories, const bool debugCmd) - : AbstractExtItem(parent, weatherName, directories, debugCmd), + const QStringList directories) + : AbstractExtItem(parent, weatherName, directories), ui(new Ui::ExtWeather) { - // logging - const_cast(LOG_ESM()).setEnabled(QtMsgType::QtDebugMsg, debugCmd); - qSetMessagePattern(LOG_FORMAT); + qCDebug(LOG_LIB); readConfiguration(); ui->setupUi(this); @@ -60,7 +58,7 @@ ExtWeather::ExtWeather(QWidget *parent, const QString weatherName, ExtWeather::~ExtWeather() { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); disconnect(manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(weatherReplyReceived(QNetworkReply *))); @@ -70,12 +68,13 @@ ExtWeather::~ExtWeather() } -ExtWeather *ExtWeather::copy(const QString fileName, const int number) +ExtWeather *ExtWeather::copy(const QString _fileName, const int _number) { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); + qCDebug(LOG_LIB) << "File" << _fileName; + qCDebug(LOG_LIB) << "Number" << _number; - ExtWeather *item = new ExtWeather(static_cast(parent()), fileName, - directories(), LOG_ESM().isDebugEnabled()); + ExtWeather *item = new ExtWeather(static_cast(parent()), _fileName, directories()); item->setActive(isActive()); item->setApiVersion(apiVersion()); item->setCity(city()); @@ -83,7 +82,7 @@ ExtWeather *ExtWeather::copy(const QString fileName, const int number) item->setCountry(country()); item->setInterval(interval()); item->setName(name()); - item->setNumber(number); + item->setNumber(_number); item->setTs(ts()); return item; @@ -92,8 +91,8 @@ ExtWeather *ExtWeather::copy(const QString fileName, const int number) QString ExtWeather::weatherFromInt(const int _id) const { - qCDebug(LOG_ESM); - qCDebug(LOG_ESM) << "ID" << _id; + qCDebug(LOG_LIB); + qCDebug(LOG_LIB) << "ID" << _id; // refer to http://openweathermap.org/weather-conditions QString weather; @@ -192,7 +191,7 @@ QString ExtWeather::weatherFromInt(const int _id) const QString ExtWeather::city() const { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); return m_city; } @@ -200,7 +199,7 @@ QString ExtWeather::city() const QString ExtWeather::country() const { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); return m_country; } @@ -208,7 +207,7 @@ QString ExtWeather::country() const int ExtWeather::ts() const { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); return m_ts; } @@ -216,7 +215,7 @@ int ExtWeather::ts() const QString ExtWeather::uniq() const { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); return QString("%1 (%2) at %3").arg(m_city).arg(m_country).arg(m_ts); } @@ -224,8 +223,8 @@ QString ExtWeather::uniq() const void ExtWeather::setCity(const QString _city) { - qCDebug(LOG_ESM); - qCDebug(LOG_ESM) << "City" << _city; + qCDebug(LOG_LIB); + qCDebug(LOG_LIB) << "City" << _city; m_city = _city; } @@ -233,8 +232,8 @@ void ExtWeather::setCity(const QString _city) void ExtWeather::setCountry(const QString _country) { - qCDebug(LOG_ESM); - qCDebug(LOG_ESM) << "Country" << _country; + qCDebug(LOG_LIB); + qCDebug(LOG_LIB) << "Country" << _country; m_country = _country; } @@ -242,8 +241,8 @@ void ExtWeather::setCountry(const QString _country) void ExtWeather::setTs(const int _ts) { - qCDebug(LOG_ESM); - qCDebug(LOG_ESM) << "Timestamp" << _ts; + qCDebug(LOG_LIB); + qCDebug(LOG_LIB) << "Timestamp" << _ts; m_ts = _ts; } @@ -251,7 +250,7 @@ void ExtWeather::setTs(const int _ts) void ExtWeather::readConfiguration() { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); AbstractExtItem::readConfiguration(); for (int i=directories().count()-1; i>=0; i--) { @@ -267,6 +266,7 @@ void ExtWeather::readConfiguration() // update for current API if ((apiVersion() > 0) && (apiVersion() < AWEWAPI)) { + qCWarning(LOG_LIB) << "Bump API version from" << apiVersion() << "to" << AWEWAPI; setApiVersion(AWEWAPI); writeConfiguration(); } @@ -275,11 +275,11 @@ void ExtWeather::readConfiguration() QVariantHash ExtWeather::run() { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); if ((!isActive()) || (isRunning)) return values; if (times == 1) { - qCDebug(LOG_ESM) << "Send request"; + qCInfo(LOG_LIB) << "Send request"; isRunning = true; QNetworkReply *reply = manager->get(QNetworkRequest(QUrl(url(m_ts != 0)))); new QReplyTimeout(reply, 1000); @@ -296,7 +296,7 @@ QVariantHash ExtWeather::run() int ExtWeather::showConfiguration(const QVariant args) { Q_UNUSED(args) - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); ui->lineEdit_name->setText(name()); ui->lineEdit_comment->setText(comment()); @@ -326,11 +326,11 @@ int ExtWeather::showConfiguration(const QVariant args) void ExtWeather::writeConfiguration() const { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); AbstractExtItem::writeConfiguration(); QSettings settings(QString("%1/%2").arg(directories().first()).arg(fileName()), QSettings::IniFormat); - qCDebug(LOG_ESM) << "Configuration file" << settings.fileName(); + qCInfo(LOG_LIB) << "Configuration file" << settings.fileName(); settings.beginGroup(QString("Desktop Entry")); settings.setValue(QString("X-AW-City"), m_city); @@ -344,9 +344,9 @@ void ExtWeather::writeConfiguration() const void ExtWeather::weatherReplyReceived(QNetworkReply *reply) { - qCDebug(LOG_ESM); - qCDebug(LOG_ESM) << "Return code" << reply->error(); - qCDebug(LOG_ESM) << "Reply error message" << reply->errorString(); + qCDebug(LOG_LIB); + qCDebug(LOG_LIB) << "Return code" << reply->error(); + qCDebug(LOG_LIB) << "Reply error message" << reply->errorString(); isRunning = false; QJsonParseError error; @@ -354,14 +354,14 @@ void ExtWeather::weatherReplyReceived(QNetworkReply *reply) reply->deleteLater(); if ((reply->error() != QNetworkReply::NoError) || (error.error != QJsonParseError::NoError)) { - qCWarning(LOG_ESM) << "Parse error" << error.errorString(); + qCWarning(LOG_LIB) << "Parse error" << error.errorString(); return; } // convert to map QVariantMap json = jsonDoc.toVariant().toMap(); if (json[QString("cod")].toInt() != 200) { - qCWarning(LOG_ESM) << "Invalid return code"; + qCWarning(LOG_LIB) << "Invalid return code"; return; } @@ -378,7 +378,8 @@ void ExtWeather::weatherReplyReceived(QNetworkReply *reply) QVariantHash ExtWeather::parseSingleJson(const QVariantMap json) const { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); + qCDebug(LOG_LIB) << "Single json data" << json; QVariantHash output; @@ -404,7 +405,7 @@ QVariantHash ExtWeather::parseSingleJson(const QVariantMap json) const void ExtWeather::translate() { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); ui->label_name->setText(i18n("Name")); ui->label_comment->setText(i18n("Comment")); @@ -419,13 +420,13 @@ void ExtWeather::translate() QString ExtWeather::url(const bool isForecast) const { - qCDebug(LOG_ESM); - qCDebug(LOG_ESM) << "Is forecast" << isForecast; + qCDebug(LOG_LIB); + qCDebug(LOG_LIB) << "Is forecast" << isForecast; QString apiUrl = isForecast ? QString(OWM_FORECAST_URL) : QString(OWM_URL); apiUrl.replace(QString("$CITY"), m_city); apiUrl.replace(QString("$COUNTRY"), m_country); - qCDebug(LOG_ESM) << "API url" << apiUrl; + qCInfo(LOG_LIB) << "API url" << apiUrl; return apiUrl; } diff --git a/sources/awesomewidgets/extweather.h b/sources/awesomewidgets/extweather.h index eff2851..d93c697 100644 --- a/sources/awesomewidgets/extweather.h +++ b/sources/awesomewidgets/extweather.h @@ -40,10 +40,9 @@ class ExtWeather : public AbstractExtItem public: explicit ExtWeather(QWidget *parent = nullptr, const QString weatherName = QString(), - const QStringList directories = QStringList(), - const bool debugCmd = false); - ~ExtWeather(); - ExtWeather *copy(const QString fileName, const int number); + const QStringList directories = QStringList()); + virtual ~ExtWeather(); + ExtWeather *copy(const QString _fileName, const int _number); QString weatherFromInt(const int _id) const; // get methods QString city() const; diff --git a/sources/awesomewidgets/graphicalitem.cpp b/sources/awesomewidgets/graphicalitem.cpp index 524b044..9497617 100644 --- a/sources/awesomewidgets/graphicalitem.cpp +++ b/sources/awesomewidgets/graphicalitem.cpp @@ -33,13 +33,11 @@ GraphicalItem::GraphicalItem(QWidget *parent, const QString desktopName, - const QStringList directories, const bool debugCmd) - : AbstractExtItem(parent, desktopName, directories, debugCmd), + const QStringList directories) + : AbstractExtItem(parent, desktopName, directories), ui(new Ui::GraphicalItem) { - // logging - const_cast(LOG_ESM()).setEnabled(QtMsgType::QtDebugMsg, debugCmd); - qSetMessagePattern(LOG_FORMAT); + qCDebug(LOG_LIB); readConfiguration(); ui->setupUi(this); @@ -52,18 +50,19 @@ GraphicalItem::GraphicalItem(QWidget *parent, const QString desktopName, GraphicalItem::~GraphicalItem() { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); delete ui; } -GraphicalItem *GraphicalItem::copy(const QString fileName, const int number) +GraphicalItem *GraphicalItem::copy(const QString _fileName, const int _number) { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); + qCDebug(LOG_LIB) << "File" << _fileName; + qCDebug(LOG_LIB) << "Number" << _number; - GraphicalItem *item = new GraphicalItem(static_cast(parent()), - fileName, directories(), LOG_ESM().isDebugEnabled()); + GraphicalItem *item = new GraphicalItem(static_cast(parent()), _fileName, directories()); item->setActive(isActive()); item->setActiveColor(activeColor()); item->setApiVersion(apiVersion()); @@ -73,8 +72,8 @@ GraphicalItem *GraphicalItem::copy(const QString fileName, const int number) item->setHeight(height()); item->setInactiveColor(inactiveColor()); item->setInterval(interval()); - item->setName(QString("bar%1").arg(number)); - item->setNumber(number); + item->setName(QString("bar%1").arg(_number)); + item->setNumber(_number); item->setType(type()); item->setWidth(width()); @@ -84,14 +83,14 @@ GraphicalItem *GraphicalItem::copy(const QString fileName, const int number) QString GraphicalItem::image(const float value) const { - qCDebug(LOG_ESM); - qCDebug(LOG_ESM) << "Value" << value; + qCDebug(LOG_LIB); + qCDebug(LOG_LIB) << "Value" << value; if (m_bar == QString("none")) return QString(""); QColor active = stringToColor(m_activeColor); QColor inactive = stringToColor(m_inactiveColor); float percent = value / 100.0; - int scale[2] = {1, 1}; + int scale[2] = { 1, 1 }; QPen pen = QPen(); QGraphicsScene *scene = new QGraphicsScene(); scene->setBackgroundBrush(QBrush(Qt::NoBrush)); @@ -164,7 +163,7 @@ QString GraphicalItem::image(const float value) const QString GraphicalItem::bar() const { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); return m_bar; } @@ -172,7 +171,7 @@ QString GraphicalItem::bar() const QString GraphicalItem::activeColor() const { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); return m_activeColor; } @@ -180,7 +179,7 @@ QString GraphicalItem::activeColor() const QString GraphicalItem::inactiveColor() const { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); return m_inactiveColor; } @@ -188,7 +187,7 @@ QString GraphicalItem::inactiveColor() const QString GraphicalItem::tag() const { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); return name() + m_bar; } @@ -196,7 +195,7 @@ QString GraphicalItem::tag() const GraphicalItem::Type GraphicalItem::type() const { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); return m_type; } @@ -204,7 +203,7 @@ GraphicalItem::Type GraphicalItem::type() const QString GraphicalItem::strType() const { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); QString value; switch (m_type) { @@ -225,7 +224,7 @@ QString GraphicalItem::strType() const GraphicalItem::Direction GraphicalItem::direction() const { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); return m_direction; } @@ -233,7 +232,7 @@ GraphicalItem::Direction GraphicalItem::direction() const QString GraphicalItem::strDirection() const { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); QString value; switch (m_direction) { @@ -251,7 +250,7 @@ QString GraphicalItem::strDirection() const int GraphicalItem::height() const { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); return m_height; } @@ -259,7 +258,7 @@ int GraphicalItem::height() const int GraphicalItem::width() const { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); return m_width; } @@ -267,7 +266,7 @@ int GraphicalItem::width() const QString GraphicalItem::uniq() const { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); return m_bar; } @@ -275,25 +274,21 @@ QString GraphicalItem::uniq() const void GraphicalItem::setBar(const QString _bar) { - qCDebug(LOG_ESM); - qCDebug(LOG_ESM) << "Bar" << _bar; + qCDebug(LOG_LIB); + qCDebug(LOG_LIB) << "Bar" << _bar; - if ((!_bar.contains(QRegExp(QString("cpu(?!cl).*")))) && - (!_bar.contains(QRegExp(QString("gpu")))) && - (!_bar.contains(QRegExp(QString("mem")))) && - (!_bar.contains(QRegExp(QString("swap")))) && - (!_bar.contains(QRegExp(QString("hdd[0-9].*")))) && - (!_bar.contains(QRegExp(QString("bat.*"))))) + if (!_bar.contains(QRegExp(QString("^(cpu(?!cl).*|gpu$|mem$|swap$|hdd[0-9].*|bat.*)")))) { + qCWarning(LOG_LIB) << "Unsupported bar type" << _bar; m_bar = QString("none"); - else + } else m_bar = _bar; } void GraphicalItem::setActiveColor(const QString _color) { - qCDebug(LOG_ESM); - qCDebug(LOG_ESM) << "Color" << _color; + qCDebug(LOG_LIB); + qCDebug(LOG_LIB) << "Color" << _color; m_activeColor = _color; } @@ -301,8 +296,8 @@ void GraphicalItem::setActiveColor(const QString _color) void GraphicalItem::setInactiveColor(const QString _color) { - qCDebug(LOG_ESM); - qCDebug(LOG_ESM) << "Color" << _color; + qCDebug(LOG_LIB); + qCDebug(LOG_LIB) << "Color" << _color; m_inactiveColor = _color; } @@ -310,8 +305,8 @@ void GraphicalItem::setInactiveColor(const QString _color) void GraphicalItem::setType(const Type _type) { - qCDebug(LOG_ESM); - qCDebug(LOG_ESM) << "Type" << _type; + qCDebug(LOG_LIB); + qCDebug(LOG_LIB) << "Type" << _type; m_type = _type; } @@ -319,8 +314,8 @@ void GraphicalItem::setType(const Type _type) void GraphicalItem::setStrType(const QString _type) { - qCDebug(LOG_ESM); - qCDebug(LOG_ESM) << "Type" << _type; + qCDebug(LOG_LIB); + qCDebug(LOG_LIB) << "Type" << _type; if (_type == QString("Vertical")) setType(Vertical); @@ -333,8 +328,8 @@ void GraphicalItem::setStrType(const QString _type) void GraphicalItem::setDirection(const Direction _direction) { - qCDebug(LOG_ESM); - qCDebug(LOG_ESM) << "Direction" << _direction; + qCDebug(LOG_LIB); + qCDebug(LOG_LIB) << "Direction" << _direction; m_direction = _direction; } @@ -342,8 +337,8 @@ void GraphicalItem::setDirection(const Direction _direction) void GraphicalItem::setStrDirection(const QString _direction) { - qCDebug(LOG_ESM); - qCDebug(LOG_ESM) << "Direction" << _direction; + qCDebug(LOG_LIB); + qCDebug(LOG_LIB) << "Direction" << _direction; if (_direction == QString("RightToLeft")) setDirection(RightToLeft); @@ -354,8 +349,8 @@ void GraphicalItem::setStrDirection(const QString _direction) void GraphicalItem::setHeight(const int _height) { - qCDebug(LOG_ESM); - qCDebug(LOG_ESM) << "Height" << _height; + qCDebug(LOG_LIB); + qCDebug(LOG_LIB) << "Height" << _height; if (_height <= 0) return; m_height = _height; @@ -364,8 +359,8 @@ void GraphicalItem::setHeight(const int _height) void GraphicalItem::setWidth(const int _width) { - qCDebug(LOG_ESM); - qCDebug(LOG_ESM) << "Width" << _width; + qCDebug(LOG_LIB); + qCDebug(LOG_LIB) << "Width" << _width; if (_width <= 0) return; m_width = _width; @@ -374,7 +369,7 @@ void GraphicalItem::setWidth(const int _width) void GraphicalItem::readConfiguration() { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); AbstractExtItem::readConfiguration(); for (int i=directories().count()-1; i>=0; i--) { @@ -396,6 +391,7 @@ void GraphicalItem::readConfiguration() // update for current API if ((apiVersion() > 0) && (apiVersion() < AWGIAPI)) { + qCWarning(LOG_LIB) << "Bump API version from" << apiVersion() << "to" << AWGIAPI; setApiVersion(AWGIAPI); writeConfiguration(); } @@ -404,7 +400,7 @@ void GraphicalItem::readConfiguration() QVariantHash GraphicalItem::run() { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); // required by abstract class return QVariantHash(); @@ -413,7 +409,8 @@ QVariantHash GraphicalItem::run() int GraphicalItem::showConfiguration(const QVariant args) { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); + qCDebug(LOG_LIB) << "Combobox arguments" << args; QStringList tags = args.toStringList(); ui->label_nameValue->setText(name()); @@ -449,11 +446,11 @@ int GraphicalItem::showConfiguration(const QVariant args) void GraphicalItem::writeConfiguration() const { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); AbstractExtItem::writeConfiguration(); QSettings settings(QString("%1/%2").arg(directories().first()).arg(fileName()), QSettings::IniFormat); - qCDebug(LOG_ESM) << "Configuration file" << settings.fileName(); + qCInfo(LOG_LIB) << "Configuration file" << settings.fileName(); settings.beginGroup(QString("Desktop Entry")); settings.setValue(QString("X-AW-Value"), m_bar); @@ -471,12 +468,13 @@ void GraphicalItem::writeConfiguration() const void GraphicalItem::changeColor() { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); QColor color = stringToColor((static_cast(sender()))->text()); QColor newColor = QColorDialog::getColor(color, this, tr("Select color"), QColorDialog::ShowAlphaChannel); if (!newColor.isValid()) return; + qCInfo(LOG_LIB) << "Selected color" << newColor; QStringList colorText; colorText.append(QString("%1").arg(newColor.red())); @@ -490,8 +488,8 @@ void GraphicalItem::changeColor() QColor GraphicalItem::stringToColor(const QString _color) const { - qCDebug(LOG_ESM); - qCDebug(LOG_ESM) << "Color" << _color; + qCDebug(LOG_LIB); + qCDebug(LOG_LIB) << "Color" << _color; QColor qcolor; QStringList listColor = _color.split(QChar(',')); @@ -508,7 +506,7 @@ QColor GraphicalItem::stringToColor(const QString _color) const void GraphicalItem::translate() { - qCDebug(LOG_ESM); + qCDebug(LOG_LIB); ui->label_name->setText(i18n("Name")); ui->label_comment->setText(i18n("Comment")); diff --git a/sources/awesomewidgets/graphicalitem.h b/sources/awesomewidgets/graphicalitem.h index 46e0067..708f3bb 100644 --- a/sources/awesomewidgets/graphicalitem.h +++ b/sources/awesomewidgets/graphicalitem.h @@ -50,10 +50,9 @@ public: }; explicit GraphicalItem(QWidget *parent = nullptr, const QString desktopName = QString(), - const QStringList directories = QStringList(), - const bool debugCmd = false); - ~GraphicalItem(); - GraphicalItem *copy(const QString fileName, const int number); + const QStringList directories = QStringList()); + virtual ~GraphicalItem(); + GraphicalItem *copy(const QString _fileName, const int _number); QString image(const float value) const; // get methods QString bar() const; diff --git a/sources/desktop-panel/package/contents/ui/about.qml b/sources/desktop-panel/package/contents/ui/about.qml index 703a148..bfab79e 100644 --- a/sources/desktop-panel/package/contents/ui/about.qml +++ b/sources/desktop-panel/package/contents/ui/about.qml @@ -111,6 +111,6 @@ Item { } Component.onCompleted: { - if (debug) console.log("") + if (debug) console.debug() } } diff --git a/sources/desktop-panel/package/contents/ui/activeapp.qml b/sources/desktop-panel/package/contents/ui/activeapp.qml index c75b5e4..f2fbfda 100644 --- a/sources/desktop-panel/package/contents/ui/activeapp.qml +++ b/sources/desktop-panel/package/contents/ui/activeapp.qml @@ -69,6 +69,7 @@ Item { width: parent.width * 2 / 3 text: plasmoid.configuration.currentFontFamily onClicked: { + if (debug) console.debug() fontDialog.setFont() fontDialog.visible = true } @@ -133,8 +134,10 @@ Item { ] onCurrentIndexChanged: cfg_currentFontWeight = model[currentIndex]["name"] Component.onCompleted: { + if (debug) console.debug() for (var i = 0; i < model.length; i++) { if (model[i]["name"] == plasmoid.configuration.currentFontWeight) { + if (debug) console.info("Found", model[i]["name"], "on", i) fontWeight.currentIndex = i; } } @@ -168,8 +171,10 @@ Item { ] onCurrentIndexChanged: cfg_currentFontStyle = model[currentIndex]["name"] Component.onCompleted: { + if (debug) console.debug() for (var i = 0; i < model.length; i++) { if (model[i]["name"] == plasmoid.configuration.currentFontStyle) { + if (debug) console.info("Found", model[i]["name"], "on", i) fontStyle.currentIndex = i; } } @@ -214,12 +219,14 @@ Item { signal setFont onAccepted: { + if (debug) console.debug() selectFont.text = fontDialog.font.family fontSize.value = fontDialog.font.pointSize fontStyle.currentIndex = fontDialog.font.italic ? 1 : 0 fontWeight.currentIndex = weight[fontDialog.font.weight] } onSetFont: { + if (debug) console.debug() fontDialog.font = Qt.font({ family: selectFont.text, pointSize: fontSize.value > 0 ? fontSize.value : 12, @@ -230,6 +237,6 @@ Item { } Component.onCompleted: { - if (debug) console.log("") + if (debug) console.debug() } } diff --git a/sources/desktop-panel/package/contents/ui/advanced.qml b/sources/desktop-panel/package/contents/ui/advanced.qml index 052974c..aec8319 100644 --- a/sources/desktop-panel/package/contents/ui/advanced.qml +++ b/sources/desktop-panel/package/contents/ui/advanced.qml @@ -128,8 +128,10 @@ Item { ] onCurrentIndexChanged: cfg_tooltipType = model[currentIndex]["name"] Component.onCompleted: { + if (debug) console.debug() for (var i = 0; i < model.length; i++) { if (model[i]["name"] == plasmoid.configuration.tooltipType) { + if (debug) console.info("Found", model[i]["name"], "on", i) tooltipType.currentIndex = i; } } @@ -255,6 +257,6 @@ Item { } Component.onCompleted: { - if (debug) console.log("") + if (debug) console.debug() } } diff --git a/sources/desktop-panel/package/contents/ui/inactiveapp.qml b/sources/desktop-panel/package/contents/ui/inactiveapp.qml index ec1bbb4..f974a04 100644 --- a/sources/desktop-panel/package/contents/ui/inactiveapp.qml +++ b/sources/desktop-panel/package/contents/ui/inactiveapp.qml @@ -69,6 +69,7 @@ Item { width: parent.width * 2 / 3 text: plasmoid.configuration.fontFamily onClicked: { + if (debug) console.debug() fontDialog.setFont() fontDialog.visible = true } @@ -133,8 +134,10 @@ Item { ] onCurrentIndexChanged: cfg_fontWeight = model[currentIndex]["name"] Component.onCompleted: { + if (debug) console.debug() for (var i = 0; i < model.length; i++) { if (model[i]["name"] == plasmoid.configuration.fontWeight) { + if (debug) console.info("Found", model[i]["name"], "on", i) fontWeight.currentIndex = i; } } @@ -168,8 +171,10 @@ Item { ] onCurrentIndexChanged: cfg_fontStyle = model[currentIndex]["name"] Component.onCompleted: { + if (debug) console.debug() for (var i = 0; i < model.length; i++) { if (model[i]["name"] == plasmoid.configuration.fontStyle) { + if (debug) console.info("Found", model[i]["name"], "on", i) fontStyle.currentIndex = i; } } @@ -214,12 +219,14 @@ Item { signal setFont onAccepted: { + if (debug) console.debug() selectFont.text = fontDialog.font.family fontSize.value = fontDialog.font.pointSize fontStyle.currentIndex = fontDialog.font.italic ? 1 : 0 fontWeight.currentIndex = weight[fontDialog.font.weight] } onSetFont: { + if (debug) console.debug() fontDialog.font = Qt.font({ family: selectFont.text, pointSize: fontSize.value > 0 ? fontSize.value : 12, @@ -230,6 +237,6 @@ Item { } Component.onCompleted: { - if (debug) console.log("") + if (debug) console.debug() } } diff --git a/sources/desktop-panel/package/contents/ui/main.qml b/sources/desktop-panel/package/contents/ui/main.qml index 1ecaf3d..89fed9d 100644 --- a/sources/desktop-panel/package/contents/ui/main.qml +++ b/sources/desktop-panel/package/contents/ui/main.qml @@ -108,11 +108,11 @@ Item { } onNeedUpdate: { - if (debug) console.log("") + if (debug) console.debug() for (var i=0; i #include #include -#include #include #include @@ -41,13 +40,12 @@ DPAdds::DPAdds(QObject *parent) : QObject(parent) { - // debug - QProcessEnvironment environment = QProcessEnvironment::systemEnvironment(); - QString debugEnv = environment.value(QString("DEBUG"), QString("no")); - bool debug = (debugEnv == QString("yes")); + qCDebug(LOG_DP); // logging - const_cast(LOG_DP()).setEnabled(QtMsgType::QtDebugMsg, debug); +#if QT_VERSION >= QT_VERSION_CHECK(5, 5, 0) + const_cast(LOG_DP()).setEnabled(QtMsgType::QtInfoMsg, false); +#endif /* QT_VERSION */ qSetMessagePattern(LOG_FORMAT); connect(KWindowSystem::self(), SIGNAL(currentDesktopChanged(int)), this, SIGNAL(desktopChanged())); @@ -110,7 +108,8 @@ QString DPAdds::toolTipImage(const int desktop) const DesktopWindowsInfo info = getInfoByDesktop(desktop); if (tooltipType == QString("names")) { QStringList windowList; - foreach(WindowData data, info.windowsData) windowList.append(data.name); + std::for_each(info.windowsData.cbegin(), info.windowsData.cend(), + [&windowList](WindowData data) { windowList.append(data.name); }); return QString("
  • %1
").arg(windowList.join(QString("
  • "))); } // init @@ -151,20 +150,23 @@ QString DPAdds::toolTipImage(const int desktop) const } } else if (tooltipType == QString("clean")) { QScreen *screen = QGuiApplication::primaryScreen(); - foreach(WindowData data, info.desktopsData) { - QPixmap desktop = screen->grabWindow(data.id); - toolTipScene->addPixmap(desktop)->setOffset(data.rect.left(), data.rect.top()); - } + std::for_each(info.desktopsData.cbegin(), info.desktopsData.cend(), + [&toolTipScene, &screen](WindowData data) { + QPixmap desktop = screen->grabWindow(data.id); + toolTipScene->addPixmap(desktop)->setOffset(data.rect.left(), data.rect.top()); + }); } else if (tooltipType == QString("windows")) { QScreen *screen = QGuiApplication::primaryScreen(); - foreach(WindowData data, info.desktopsData) { - QPixmap desktop = screen->grabWindow(data.id); - toolTipScene->addPixmap(desktop)->setOffset(data.rect.left(), data.rect.top()); - } - foreach(WindowData data, info.windowsData) { - QPixmap window = screen->grabWindow(data.id); - toolTipScene->addPixmap(window)->setOffset(data.rect.left(), data.rect.top()); - } + std::for_each(info.desktopsData.cbegin(), info.desktopsData.cend(), + [&toolTipScene, &screen](WindowData data) { + QPixmap desktop = screen->grabWindow(data.id); + toolTipScene->addPixmap(desktop)->setOffset(data.rect.left(), data.rect.top()); + }); + std::for_each(info.windowsData.cbegin(), info.windowsData.cend(), + [&toolTipScene, &screen](WindowData data) { + QPixmap window = screen->grabWindow(data.id); + toolTipScene->addPixmap(window)->setOffset(data.rect.left(), data.rect.top()); + }); } QPixmap image = toolTipView->grab().scaledToWidth(tooltipWidth); @@ -182,6 +184,8 @@ QString DPAdds::toolTipImage(const int desktop) const QString DPAdds::parsePattern(const QString pattern, const int desktop) const { qCDebug(LOG_DP); + qCDebug(LOG_DP) << "Pattern" << pattern; + qCDebug(LOG_DP) << "Desktop number" << desktop; QString parsed = pattern; parsed.replace(QString("$$"), QString("$\\$\\")); @@ -211,7 +215,7 @@ void DPAdds::setPanelsToControl(const QString newPanels) if (newPanels == QString("-1")) { int count = getPanels().count(); for (int i=0; i #include #include -#include #include #include #include @@ -43,27 +42,25 @@ #include "version.h" -ExtendedSysMon::ExtendedSysMon(QObject* parent, const QVariantList &args) +ExtendedSysMon::ExtendedSysMon(QObject *parent, const QVariantList &args) : Plasma::DataEngine(parent, args) { Q_UNUSED(args) - - // debug - QProcessEnvironment environment = QProcessEnvironment::systemEnvironment(); - QString debugEnv = environment.value(QString("DEBUG"), QString("no")); - bool debug = (debugEnv == QString("yes")); + qCDebug(LOG_ESM); // logging - const_cast(LOG_ESM()).setEnabled(QtMsgType::QtDebugMsg, debug); +#if QT_VERSION >= QT_VERSION_CHECK(5, 5, 0) + const_cast(LOG_ESM()).setEnabled(QtMsgType::QtInfoMsg, false); +#endif /* QT_VERSION */ qSetMessagePattern(LOG_FORMAT); setMinimumPollingInterval(333); readConfiguration(); - extQuotes = new ExtItemAggregator(nullptr, QString("quotes"), debug); - extScripts = new ExtItemAggregator(nullptr, QString("scripts"), debug); - extUpgrade = new ExtItemAggregator(nullptr, QString("upgrade"), debug); - extWeather = new ExtItemAggregator(nullptr, QString("weather"), debug); + extQuotes = new ExtItemAggregator(nullptr, QString("quotes")); + extScripts = new ExtItemAggregator(nullptr, QString("scripts")); + extUpgrade = new ExtItemAggregator(nullptr, QString("upgrade")); + extWeather = new ExtItemAggregator(nullptr, QString("weather")); } @@ -87,7 +84,7 @@ QStringList ExtendedSysMon::getAllHdd() const for (int i=0; i rawConfig; @@ -183,6 +180,7 @@ void ExtendedSysMon::readConfiguration() QHash ExtendedSysMon::updateConfiguration(QHash rawConfig) const { qCDebug(LOG_ESM); + qCDebug(LOG_ESM) << "Raw configuration" << rawConfig; // gpudev if (rawConfig[QString("GPUDEV")] == QString("disable")) @@ -190,7 +188,7 @@ QHash ExtendedSysMon::updateConfiguration(QHash ExtendedSysMon::updateConfiguration(QHash -1)) + if ((QFile::exists(device)) && (device.contains(diskRegexp))) devices.append(device); if (devices.isEmpty()) rawConfig[QString("HDDDEV")] = allHddDevices.join(QChar(',')); @@ -217,7 +215,7 @@ QHash ExtendedSysMon::updateConfiguration(QHashtoUnicode(process.output).trimmed(); if (configuration[QString("GPUDEV")] == QString("nvidia")) @@ -336,10 +334,10 @@ float ExtendedSysMon::getGpuTemp(const QString device) const cmd = QString("nvidia-smi -q -x"); else if (device == QString("ati")) cmd = QString("aticonfig --od-gettemperature"); - qCDebug(LOG_ESM) << "cmd" << cmd; + qCInfo(LOG_ESM) << "cmd" << cmd; TaskResult process = runTask(cmd); - qCDebug(LOG_ESM) << "Cmd returns" << process.exitCode; - qCDebug(LOG_ESM) << "Error" << process.error; + qCInfo(LOG_ESM) << "Cmd returns" << process.exitCode; + qCInfo(LOG_ESM) << "Error" << process.error; QString qoutput = QTextCodec::codecForMib(106)->toUnicode(process.output); if (configuration[QString("GPUDEV")] == QString("nvidia")) @@ -369,11 +367,11 @@ float ExtendedSysMon::getHddTemp(const QString cmd, const QString device) const float value = 0.0; TaskResult process = runTask(QString("%1 %2").arg(cmd).arg(device)); - qCDebug(LOG_ESM) << "Cmd returns" << process.exitCode; - qCDebug(LOG_ESM) << "Error" << process.error; + qCInfo(LOG_ESM) << "Cmd returns" << process.exitCode; + qCInfo(LOG_ESM) << "Error" << process.error; bool smartctl = cmd.contains(QString("smartctl")); - qCDebug(LOG_ESM) << "Define smartctl" << smartctl; + qCInfo(LOG_ESM) << "Parse as smartctl" << smartctl; QString qoutput = QTextCodec::codecForMib(106)->toUnicode(process.output).trimmed(); if (smartctl) { @@ -401,6 +399,7 @@ QString ExtendedSysMon::getNetworkDevice() const QString device = QString("lo"); QList rawInterfaceList = QNetworkInterface::allInterfaces(); + qCInfo(LOG_ESM) << "Devices" << rawInterfaceList; foreach(QNetworkInterface interface, rawInterfaceList) if ((interface.flags().testFlag(QNetworkInterface::IsUp)) && (!interface.flags().testFlag(QNetworkInterface::IsLoopBack)) && @@ -457,10 +456,10 @@ QVariantHash ExtendedSysMon::getPlayerMpdInfo(const QString mpdAddress, const QS QString cmd = QString("bash -c \"echo 'currentsong\nstatus\nclose' | curl --connect-timeout 1 -fsm 3 telnet://%1:%2\"") .arg(mpdAddress) .arg(mpdPort); - qCDebug(LOG_ESM) << "cmd" << cmd; + qCInfo(LOG_ESM) << "cmd" << cmd; TaskResult process = runTask(cmd); - qCDebug(LOG_ESM) << "Cmd returns" << process.exitCode; - qCDebug(LOG_ESM) << "Error" << process.error; + qCInfo(LOG_ESM) << "Cmd returns" << process.exitCode; + qCInfo(LOG_ESM) << "Error" << process.error; QString qoutput = QTextCodec::codecForMib(106)->toUnicode(process.output).trimmed(); foreach(QString str, qoutput.split(QChar('\n'), QString::SkipEmptyParts)) { @@ -506,7 +505,7 @@ QVariantHash ExtendedSysMon::getPlayerMprisInfo(const QString mpris) const request.setArguments(args); QDBusMessage response = bus.call(request, QDBus::BlockWithGui); if ((response.type() != QDBusMessage::ReplyMessage) || (response.arguments().isEmpty())) { - qCDebug(LOG_ESM) << "Error message" << response.errorMessage(); + qCWarning(LOG_ESM) << "Error message" << response.errorMessage(); } else { // another portion of dirty magic QVariantHash map = qdbus_cast(response.arguments().first() @@ -524,7 +523,7 @@ QVariantHash ExtendedSysMon::getPlayerMprisInfo(const QString mpris) const request.setArguments(args); response = bus.call(request, QDBus::BlockWithGui); if ((response.type() != QDBusMessage::ReplyMessage) || (response.arguments().isEmpty())) { - qCDebug(LOG_ESM) << "Error message" << response.errorMessage(); + qCWarning(LOG_ESM) << "Error message" << response.errorMessage(); } else // this cast is simpler than the previous one ;) info[QString("progress")] = response.arguments().first().value() @@ -555,7 +554,7 @@ QVariantHash ExtendedSysMon::getPsStats() const QVariantHash psStats; psStats[QString("pscount")] = running.count(); - psStats[QString("ps")] = running.join(QString(",")); + psStats[QString("ps")] = running.join(QChar(',')); psStats[QString("pstotal")] = directories.count(); return psStats; @@ -625,6 +624,9 @@ bool ExtendedSysMon::updateSourceEvent(const QString &source) QVariantHash data = weather->run(); foreach(QString key, data.keys()) setData(source, key, data[key]); } + } else { + qCWarning(LOG_ESM) << "Unknown source" << source; + return false; } return true; diff --git a/sources/extsysmon/extsysmon.h b/sources/extsysmon/extsysmon.h index 95167e9..becc3d7 100644 --- a/sources/extsysmon/extsysmon.h +++ b/sources/extsysmon/extsysmon.h @@ -34,7 +34,7 @@ class ExtendedSysMon : public Plasma::DataEngine public: explicit ExtendedSysMon(QObject *parent, const QVariantList &args); - ~ExtendedSysMon(); + virtual ~ExtendedSysMon(); // update functions QVariantHash getBattery(const QString acpiPath) const; QVariantHash getCurrentDesktop() const;