From 24eb548bb3e78bd61c8ed2d874e67fa89624ca25 Mon Sep 17 00:00:00 2001 From: arcan1s Date: Thu, 17 Sep 2015 01:10:55 +0300 Subject: [PATCH] * limit messages queue to ideal thread count * move from QtScript to QJSEngine (first is deprecated since 5.6) * drop unneeded includes in headers * some changes inside queue managing --- sources/CMakeLists.txt | 2 +- sources/awesome-widget/plugin/awactions.h | 1 - .../plugin/awdataaggregator.cpp | 4 +-- .../awesome-widget/plugin/awdataaggregator.h | 2 -- sources/awesome-widget/plugin/awkeys.cpp | 28 +++++++++------- sources/awesome-widget/plugin/awkeys.h | 21 ++++++++---- .../awesome-widget/plugin/awkeysaggregator.h | 2 +- sources/desktop-panel/plugin/dpadds.cpp | 32 +++++++++++-------- sources/desktop-panel/plugin/dpadds.h | 16 ++++------ sources/libraries.cmake | 8 ++--- 10 files changed, 64 insertions(+), 52 deletions(-) diff --git a/sources/CMakeLists.txt b/sources/CMakeLists.txt index 6bfc6cf..0d3527c 100644 --- a/sources/CMakeLists.txt +++ b/sources/CMakeLists.txt @@ -29,7 +29,7 @@ option(BUILD_FUTURE "Build with the features which will be marked as stable late option(BUILD_PLASMOIDS "Build plasmoids" ON) option(BUILD_DEB_PACKAGE "Build deb package" OFF) option(BUILD_RPM_PACKAGE "Build rpm package" OFF) -set(QUEUE_LIMIT 10 CACHE INTEGER "Limit data queue to this value") +set(QUEUE_LIMIT 0 CACHE INTEGER "Limit data queue to this value") # flags if(CMAKE_COMPILER_IS_GNUCXX) diff --git a/sources/awesome-widget/plugin/awactions.h b/sources/awesome-widget/plugin/awactions.h index 92cb420..e9cd859 100644 --- a/sources/awesome-widget/plugin/awactions.h +++ b/sources/awesome-widget/plugin/awactions.h @@ -20,7 +20,6 @@ #define AWACTIONS_H #include -#include class QNetworkReply; diff --git a/sources/awesome-widget/plugin/awdataaggregator.cpp b/sources/awesome-widget/plugin/awdataaggregator.cpp index 11d0079..c149754 100644 --- a/sources/awesome-widget/plugin/awdataaggregator.cpp +++ b/sources/awesome-widget/plugin/awdataaggregator.cpp @@ -34,8 +34,8 @@ AWDataAggregator::AWDataAggregator(QObject *parent) initScene(); - connect(this, SIGNAL(const updateData(QHash)), - this, SLOT(const dataUpdate(QHash))); + connect(this, SIGNAL(updateData(const QHash)), + this, SLOT(dataUpdate(const QHash))); } diff --git a/sources/awesome-widget/plugin/awdataaggregator.h b/sources/awesome-widget/plugin/awdataaggregator.h index 810ff6f..c62651a 100644 --- a/sources/awesome-widget/plugin/awdataaggregator.h +++ b/sources/awesome-widget/plugin/awdataaggregator.h @@ -21,10 +21,8 @@ #include #include -#include #include #include -#include class AWDataAggregator : public QObject diff --git a/sources/awesome-widget/plugin/awkeys.cpp b/sources/awesome-widget/plugin/awkeys.cpp index 1fe73d8..80d6872 100644 --- a/sources/awesome-widget/plugin/awkeys.cpp +++ b/sources/awesome-widget/plugin/awkeys.cpp @@ -20,12 +20,11 @@ #include #include #include +#include #include #include -#include #include #include -#include #include "awdebug.h" #include "awkeysaggregator.h" @@ -584,16 +583,16 @@ void AWKeys::calculateValues() // lambdas foreach(QString key, m_foundLambdas) values[key] = [this](QString key) { - QScriptEngine engine; + QJSEngine engine; // apply $this values key.replace(QString("$this"), values[key]); foreach(QString lambdaKey, m_foundKeys) key.replace(QString("$%1").arg(lambdaKey), values[lambdaKey]); qCInfo(LOG_AW) << "Expression" << key; - QScriptValue result = engine.evaluate(key); - if (engine.hasUncaughtException()) { - int line = engine.uncaughtExceptionLineNumber(); - qCWarning(LOG_AW) << "Uncaught exception at line" << line << ":" << result.toString(); + QJSValue result = engine.evaluate(key); + if (result.isError()) { + qCWarning(LOG_AW) << "Uncaught exception at line" << result.property("lineNumber").toInt() + << ":" << result.toString(); return QString(); } else return result.toString(); @@ -646,8 +645,7 @@ void AWKeys::setDataBySource(const QString sourceName, const QVariantMap data) { #ifdef BUILD_FUTURE // check if data stream is locked - lock = ((lock) && (queue > 0)); - if (lock) return; +// if ((lock = ((lock) && (queue > 0)))) return; #endif /* BUILD_FUTURE */ qCDebug(LOG_AW); @@ -658,9 +656,11 @@ void AWKeys::setDataBySource(const QString sourceName, const QVariantMap data) if (sourceName == QString("update")) return emit(needToBeUpdated()); // drop if limits are reached - if (++queue > QUEUE_LIMIT) { - qCWarning(LOG_AW) << "Messages queue" << queue-- << "more than limits" << QUEUE_LIMIT << ", lock"; - lock = true; +// qDebug() << ++queue; +// if (queue > queueLimit) { + if (++queue > queueLimit) { + qCWarning(LOG_AW) << "Messages queue" << queue-- << "more than limits" << queueLimit; +// lock = true; return; } @@ -681,5 +681,9 @@ void AWKeys::setDataBySource(const QString sourceName, const QVariantMap data) }); } +// volatile float n = 1.0; +// for (volatile float i=1.0; i<100000.0; i++) +// n *= i; +// qDebug() << queue-- << queueLimit; queue--; } diff --git a/sources/awesome-widget/plugin/awkeys.h b/sources/awesome-widget/plugin/awkeys.h index e9528f7..cead73e 100644 --- a/sources/awesome-widget/plugin/awkeys.h +++ b/sources/awesome-widget/plugin/awkeys.h @@ -19,11 +19,11 @@ #ifndef AWKEYS_H #define AWKEYS_H -#include #include -#include +#include #include "extitemaggregator.h" +#include "version.h" class AWDataAggregator; @@ -75,20 +75,27 @@ private: void calculateValues(); QString parsePattern(QString pattern) const; void setDataBySource(const QString sourceName, const QVariantMap data); + // objects AWKeysAggregator *aggregator = nullptr; AWDataAggregator *dataAggregator = nullptr; - bool m_wrapNewLines = false; ExtItemAggregator *graphicalItems = nullptr; ExtItemAggregator *extQuotes = nullptr; ExtItemAggregator *extScripts = nullptr; ExtItemAggregator *extUpgrade = nullptr; ExtItemAggregator *extWeather = nullptr; + // variables + QHash m_devices; + QStringList m_foundBars, m_foundKeys, m_foundLambdas; + QString m_pattern; + QHash values; + bool m_wrapNewLines = false; + // queue and stream lock properties bool lock = false; int queue = 0; - QString m_pattern; - QStringList m_foundBars, m_foundKeys, m_foundLambdas; - QHash values; - QHash m_devices; + // queue limit. It may be configured by using QUEUE_LIMIT cmake limit flag. + // In other hand since I'm using global thread pool, it makes sense to limit + // queue by QThread::idealThreadCount() value + const int queueLimit = QUEUE_LIMIT == 0 ? QThread::idealThreadCount() : QUEUE_LIMIT; }; diff --git a/sources/awesome-widget/plugin/awkeysaggregator.h b/sources/awesome-widget/plugin/awkeysaggregator.h index 6fa3ab1..aedf150 100644 --- a/sources/awesome-widget/plugin/awkeysaggregator.h +++ b/sources/awesome-widget/plugin/awkeysaggregator.h @@ -19,8 +19,8 @@ #ifndef AWKEYSAGGREGATOR_H #define AWKEYSAGGREGATOR_H +#include #include -#include #include "version.h" diff --git a/sources/desktop-panel/plugin/dpadds.cpp b/sources/desktop-panel/plugin/dpadds.cpp index fa419bc..b269420 100644 --- a/sources/desktop-panel/plugin/dpadds.cpp +++ b/sources/desktop-panel/plugin/dpadds.cpp @@ -57,6 +57,7 @@ DPAdds::~DPAdds() } +// HACK: since QML could not use QLoggingCategory I need this hack bool DPAdds::isDebugEnabled() const { qCDebug(LOG_DP); @@ -99,11 +100,13 @@ QString DPAdds::toolTipImage(const int desktop) const { qCDebug(LOG_DP); qCDebug(LOG_DP) << "Desktop" << desktop; - if (tooltipType == QString("none")) return QString(); + // drop if no tooltip required + if (m_tooltipType == QString("none")) return QString(); // prepare DesktopWindowsInfo info = getInfoByDesktop(desktop); - if (tooltipType == QString("names")) { + // special tooltip format for names + if (m_tooltipType == QString("names")) { QStringList windowList; std::for_each(info.windowsData.cbegin(), info.windowsData.cend(), [&windowList](WindowData data) { windowList.append(data.name); }); @@ -130,10 +133,10 @@ QString DPAdds::toolTipImage(const int desktop) const info.desktop.width() + 2.0 * margin, 0); toolTipScene->addLine(info.desktop.width() + 2.0 * margin, 0, 0, 0); - if (tooltipType == QString("contours")) { + if (m_tooltipType == QString("contours")) { QPen pen = QPen(); pen.setWidthF(2.0 * info.desktop.width() / 400.0); - pen.setColor(QColor(tooltipColor)); + pen.setColor(QColor(m_tooltipColor)); foreach(WindowData data, info.windowsData) { QRect rect = data.rect; toolTipScene->addLine(rect.left() + margin, rect.bottom() + margin, @@ -145,14 +148,14 @@ QString DPAdds::toolTipImage(const int desktop) const toolTipScene->addLine(rect.right() + margin, rect.bottom() + margin, rect.left() + margin, rect.bottom() + margin, pen); } - } else if (tooltipType == QString("clean")) { + } else if (m_tooltipType == QString("clean")) { QScreen *screen = QGuiApplication::primaryScreen(); 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")) { + } else if (m_tooltipType == QString("windows")) { QScreen *screen = QGuiApplication::primaryScreen(); std::for_each(info.desktopsData.cbegin(), info.desktopsData.cend(), [&toolTipScene, &screen](WindowData data) { @@ -166,7 +169,7 @@ QString DPAdds::toolTipImage(const int desktop) const }); } - QPixmap image = toolTipView->grab().scaledToWidth(tooltipWidth); + QPixmap image = toolTipView->grab().scaledToWidth(m_tooltipWidth); QByteArray byteArray; QBuffer buffer(&byteArray); image.save(&buffer, "PNG"); @@ -199,7 +202,7 @@ void DPAdds::setMark(const QString newMark) qCDebug(LOG_DP); qCDebug(LOG_DP) << "Mark" << newMark; - mark = newMark; + m_mark = newMark; } @@ -208,9 +211,9 @@ void DPAdds::setToolTipData(const QVariantMap tooltipData) qCDebug(LOG_DP); qCDebug(LOG_DP) << "Data" << tooltipData; - tooltipColor = tooltipData[QString("tooltipColor")].toString(); - tooltipType = tooltipData[QString("tooltipType")].toString(); - tooltipWidth = tooltipData[QString("tooltipWidth")].toInt(); + m_tooltipColor = tooltipData[QString("tooltipColor")].toString(); + m_tooltipType = tooltipData[QString("tooltipType")].toString(); + m_tooltipWidth = tooltipData[QString("tooltipWidth")].toInt(); } @@ -221,9 +224,9 @@ QString DPAdds::valueByKey(const QString key, int desktop) const qCDebug(LOG_DP) << "Desktop number" << desktop; if (desktop == -1) desktop = currentDesktop(); - QString currentMark = currentDesktop() == desktop ? mark : QString(""); + QString currentMark = currentDesktop() == desktop ? m_mark : QString(""); if (key == QString("mark")) - return QString("%1").arg(currentMark, mark.count(), QLatin1Char(' ')) + return QString("%1").arg(currentMark, m_mark.count(), QLatin1Char(' ')) .replace(QString(" "), QString(" ")); else if (key == QString("name")) return KWindowSystem::desktopName(desktop).replace(QString(" "), QString(" ")); @@ -236,6 +239,7 @@ QString DPAdds::valueByKey(const QString key, int desktop) const } +// HACK: this method uses variables from version.h QString DPAdds::getAboutText(const QString type) const { qCDebug(LOG_DP); @@ -294,6 +298,7 @@ QVariantMap DPAdds::getFont(const QVariantMap defaultFont) const } +// to avoid additional object definition this method is static void DPAdds::sendNotification(const QString eventId, const QString message) { qCDebug(LOG_DP); @@ -305,6 +310,7 @@ void DPAdds::sendNotification(const QString eventId, const QString message) } +// slot for mouse click void DPAdds::setCurrentDesktop(const int desktop) const { qCDebug(LOG_DP); diff --git a/sources/desktop-panel/plugin/dpadds.h b/sources/desktop-panel/plugin/dpadds.h index 5345397..c5499f7 100644 --- a/sources/desktop-panel/plugin/dpadds.h +++ b/sources/desktop-panel/plugin/dpadds.h @@ -19,11 +19,9 @@ #ifndef DPADDS_H #define DPADDS_H -#include - -#include -#include -#include +// ui library required by WId definition +#include +#include class DPAdds : public QObject @@ -71,10 +69,10 @@ public slots: private: DesktopWindowsInfo getInfoByDesktop(const int desktop) const; // variables - int tooltipWidth = 200; - QString mark = QString("*"); - QString tooltipColor = QString("#000000"); - QString tooltipType = QString("none"); + int m_tooltipWidth = 200; + QString m_mark = QString("*"); + QString m_tooltipColor = QString("#000000"); + QString m_tooltipType = QString("none"); }; diff --git a/sources/libraries.cmake b/sources/libraries.cmake index 38100aa..21c1a6b 100644 --- a/sources/libraries.cmake +++ b/sources/libraries.cmake @@ -2,18 +2,18 @@ find_package(Gettext REQUIRED) # main qt libraries -find_package(Qt5 5.4.0 REQUIRED COMPONENTS Core DBus Network Script Qml Widgets) +find_package(Qt5 5.4.0 REQUIRED COMPONENTS Core DBus Network Qml Widgets) add_definitions( ${Qt5Core_DEFINITIONS} ${Qt5DBus_DEFINITIONS} ${Qt5Network_DEFINITIONS} - ${Qt5Script_DEFINITIONS} ${Qt5Qml_DEFINITIONS} ${Qt5Widgets_DEFINITIONS} + ${Qt5Qml_DEFINITIONS} ${Qt5Widgets_DEFINITIONS} ) set(Qt_INCLUDE ${Qt5Core_INCLUDE_DIRS} ${Qt5DBus_INCLUDE_DIRS} ${Qt5Network_INCLUDE_DIRS} - ${Qt5Script_INCLUDE_DIRS} ${Qt5Qml_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS} + ${Qt5Qml_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS} ) set(Qt_LIBRARIES ${Qt5Core_LIBRARIES} ${Qt5DBus_LIBRARIES} ${Qt5Network_LIBRARIES} - ${Qt5Script_LIBRARIES} ${Qt5Qml_LIBRARIES} ${Qt5Widgets_LIBRARIES} + ${Qt5Qml_LIBRARIES} ${Qt5Widgets_LIBRARIES} ) # kf5 libraries