diff --git a/sources/CMakeLists.txt b/sources/CMakeLists.txt index e628d3d..fa0dc2c 100644 --- a/sources/CMakeLists.txt +++ b/sources/CMakeLists.txt @@ -66,6 +66,7 @@ endif () set(PROJECT_TRDPARTY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty) set(PROJECT_LIBRARY awesomewidgets) +set(PROJECT_MONITORSOURCES extsysmonsources) include(libraries.cmake) include(clang-format.cmake) include(cppcheck.cmake) @@ -74,6 +75,7 @@ include(coverity.cmake) get_directory_property(CMAKE_DEFINITIONS COMPILE_DEFINITIONS) configure_file(${CMAKE_SOURCE_DIR}/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/version.h) add_subdirectory(awesomewidgets) +add_subdirectory(extsysmonsources) add_subdirectory(extsysmon) if (BUILD_PLASMOIDS) add_subdirectory(awesome-widget) diff --git a/sources/awdebug.cpp b/sources/awdebug.cpp index 2b7ad34..6397383 100644 --- a/sources/awdebug.cpp +++ b/sources/awdebug.cpp @@ -24,6 +24,8 @@ Q_LOGGING_CATEGORY(LOG_AW, "org.kde.plasma.awesomewidget", 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_ESS, "org.kde.plasma.extsysmonsources", + QtMsgType::QtWarningMsg) Q_LOGGING_CATEGORY(LOG_LIB, "org.kde.plasma.awesomewidgets", QtMsgType::QtWarningMsg) @@ -69,7 +71,6 @@ const QStringList getBuildData() .arg(CMAKE_SHARED_LINKER_FLAGS)); // components metadata.append(QString("Components data:")); - metadata.append(QString(" BUILD_COVERAGE: %1").arg(BUILD_COVERAGE)); metadata.append(QString(" BUILD_PLASMOIDS: %1").arg(BUILD_PLASMOIDS)); metadata.append( QString(" BUILD_DEB_PACKAGE: %1").arg(BUILD_DEB_PACKAGE)); diff --git a/sources/awdebug.h b/sources/awdebug.h index 6a3b2dd..bae3ba4 100644 --- a/sources/awdebug.h +++ b/sources/awdebug.h @@ -34,6 +34,7 @@ Q_DECLARE_LOGGING_CATEGORY(LOG_AW) Q_DECLARE_LOGGING_CATEGORY(LOG_DP) Q_DECLARE_LOGGING_CATEGORY(LOG_ESM) +Q_DECLARE_LOGGING_CATEGORY(LOG_ESS) Q_DECLARE_LOGGING_CATEGORY(LOG_LIB) const QStringList getBuildData(); diff --git a/sources/extsysmon/CMakeLists.txt b/sources/extsysmon/CMakeLists.txt index 7e9857a..f078f0b 100644 --- a/sources/extsysmon/CMakeLists.txt +++ b/sources/extsysmon/CMakeLists.txt @@ -6,6 +6,7 @@ include_directories( ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../${PROJECT_LIBRARY}/ + ${CMAKE_CURRENT_SOURCE_DIR}/../${PROJECT_MONITORSOURCES}/ ${PROJECT_TRDPARTY_DIR} ${Qt_INCLUDE} ${Kf5_INCLUDE} @@ -13,15 +14,18 @@ include_directories( file(GLOB SUBPROJECT_DESKTOP_IN *.desktop) file(RELATIVE_PATH SUBPROJECT_DESKTOP ${CMAKE_SOURCE_DIR} ${SUBPROJECT_DESKTOP_IN}) -file(GLOB SUBPROJECT_SOURCE *.cpp sources/*.cpp ${CMAKE_SOURCE_DIR}/*.cpp) +file(GLOB SUBPROJECT_SOURCE *.cpp ${CMAKE_SOURCE_DIR}/*.cpp) +file(GLOB SUBPROJECT_HEADER *.h) file(GLOB SUBPROJECT_CONF *.conf) # prepare configure_file(${SUBPROJECT_DESKTOP_IN} ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT_DESKTOP}) # make -add_library(${SUBPROJECT} MODULE ${SUBPROJECT_SOURCE}) -target_link_libraries(${SUBPROJECT} ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Kf5_LIBRARIES}) +add_library(${SUBPROJECT} MODULE ${SUBPROJECT_SOURCE} ${SUBPROJECT_HEADER}) +target_link_libraries(${SUBPROJECT} + ${PROJECT_LIBRARY} ${PROJECT_MONITORSOURCES} + ${Qt_LIBRARIES} ${Kf5_LIBRARIES}) kcoreaddons_desktop_to_json(${SUBPROJECT} ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT_DESKTOP} SERVICE_TYPES plasma-dataengine.desktop) diff --git a/sources/extsysmon/extsysmon.cpp b/sources/extsysmon/extsysmon.cpp index 6b61d34..69934c4 100644 --- a/sources/extsysmon/extsysmon.cpp +++ b/sources/extsysmon/extsysmon.cpp @@ -17,7 +17,6 @@ #include "extsysmon.h" -#include #include #include #include @@ -25,6 +24,8 @@ #include "awdebug.h" #include "extsysmonaggregator.h" +#include "gputempsource.h" +#include "hddtempsource.h" ExtendedSysMon::ExtendedSysMon(QObject *parent, const QVariantList &args) @@ -83,37 +84,6 @@ bool ExtendedSysMon::updateSourceEvent(const QString &source) } -QStringList ExtendedSysMon::getAllHdd() const -{ - QStringList allDevices - = QDir(QString("/dev")).entryList(QDir::System, QDir::Name); - QStringList devices = allDevices.filter(QRegExp(QString("^[hms]d[a-z]$"))); - for (int i = 0; i < devices.count(); i++) - devices[i] = QString("/dev/%1").arg(devices.at(i)); - - qCInfo(LOG_ESM) << "Device list" << devices; - return devices; -} - - -QString ExtendedSysMon::getAutoGpu() const -{ - QString gpu = QString("disable"); - QFile moduleFile(QString("/proc/modules")); - if (!moduleFile.open(QIODevice::ReadOnly)) - return gpu; - - QString output = moduleFile.readAll(); - if (output.contains(QString("fglrx"))) - gpu = QString("ati"); - else if (output.contains(QString("nvidia"))) - gpu = QString("nvidia"); - - qCInfo(LOG_ESM) << "Device" << gpu; - return gpu; -} - - void ExtendedSysMon::readConfiguration() { QString fileName @@ -161,12 +131,12 @@ ExtendedSysMon::updateConfiguration(QHash rawConfig) const if (rawConfig[QString("GPUDEV")] == QString("disable")) rawConfig[QString("GPUDEV")] = QString("disable"); else if (rawConfig[QString("GPUDEV")] == QString("auto")) - rawConfig[QString("GPUDEV")] = getAutoGpu(); + rawConfig[QString("GPUDEV")] = GPUTemperatureSource::autoGpu(); else if ((rawConfig[QString("GPUDEV")] != QString("ati")) && (rawConfig[QString("GPUDEV")] != QString("nvidia"))) - rawConfig[QString("GPUDEV")] = getAutoGpu(); + rawConfig[QString("GPUDEV")] = GPUTemperatureSource::autoGpu(); // hdddev - QStringList allHddDevices = getAllHdd(); + QStringList allHddDevices = HDDTemperatureSource::allHdd(); if (rawConfig[QString("HDDDEV")] == QString("all")) { rawConfig[QString("HDDDEV")] = allHddDevices.join(QChar(',')); } else if (rawConfig[QString("HDDDEV")] == QString("disable")) { diff --git a/sources/extsysmon/extsysmon.h b/sources/extsysmon/extsysmon.h index 72dc025..7ec57df 100644 --- a/sources/extsysmon/extsysmon.h +++ b/sources/extsysmon/extsysmon.h @@ -41,8 +41,6 @@ private: ExtSysMonAggregator *aggregator = nullptr; QHash configuration; // methods - QStringList getAllHdd() const; - QString getAutoGpu() const; void readConfiguration(); QHash updateConfiguration(QHash rawConfig) const; diff --git a/sources/extsysmon/extsysmonaggregator.cpp b/sources/extsysmon/extsysmonaggregator.cpp index e137548..18a7130 100644 --- a/sources/extsysmon/extsysmonaggregator.cpp +++ b/sources/extsysmon/extsysmonaggregator.cpp @@ -18,19 +18,19 @@ #include "extsysmonaggregator.h" #include "awdebug.h" -#include "sources/batterysource.h" -#include "sources/customsource.h" -#include "sources/desktopsource.h" -#include "sources/gpuloadsource.h" -#include "sources/gputempsource.h" -#include "sources/hddtempsource.h" -#include "sources/loadsource.h" -#include "sources/networksource.h" -#include "sources/playersource.h" -#include "sources/processessource.h" -#include "sources/quotessource.h" -#include "sources/upgradesource.h" -#include "sources/weathersource.h" +#include "batterysource.h" +#include "customsource.h" +#include "desktopsource.h" +#include "gpuloadsource.h" +#include "gputempsource.h" +#include "hddtempsource.h" +#include "loadsource.h" +#include "networksource.h" +#include "playersource.h" +#include "processessource.h" +#include "quotessource.h" +#include "upgradesource.h" +#include "weathersource.h" ExtSysMonAggregator::ExtSysMonAggregator(QObject *parent, diff --git a/sources/extsysmon/extsysmonaggregator.h b/sources/extsysmon/extsysmonaggregator.h index 6918a24..ff7cad9 100644 --- a/sources/extsysmon/extsysmonaggregator.h +++ b/sources/extsysmon/extsysmonaggregator.h @@ -20,7 +20,7 @@ #include -#include "sources/abstractextsysmonsource.h" +#include "abstractextsysmonsource.h" class ExtSysMonAggregator : public QObject diff --git a/sources/extsysmonsources/CMakeLists.txt b/sources/extsysmonsources/CMakeLists.txt new file mode 100644 index 0000000..b5940f7 --- /dev/null +++ b/sources/extsysmonsources/CMakeLists.txt @@ -0,0 +1,18 @@ +set(SUBPROJECT ${PROJECT_MONITORSOURCES}) +message(STATUS "Subproject ${SUBPROJECT}") +add_definitions(-DTRANSLATION_DOMAIN=\"plasma_applet_org.kde.plasma.awesomewidget\") + +include_directories( + ${CMAKE_SOURCE_DIR} + ${CMAKE_BINARY_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/../${PROJECT_LIBRARY}/ + ${PROJECT_TRDPARTY_DIR} + ${Qt_INCLUDE} + ${Kf5_INCLUDE} +) + +file(GLOB SUBPROJECT_SOURCE *.cpp) +file(GLOB SUBPROJECT_HEADER *.h) + +add_library(${SUBPROJECT} STATIC ${SUBPROJECT_SOURCE} ${SUBPROJECT_HEADER}) +target_link_libraries(${SUBPROJECT} ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Kf5_LIBRARIES}) diff --git a/sources/extsysmon/sources/abstractextsysmonsource.h b/sources/extsysmonsources/abstractextsysmonsource.h similarity index 96% rename from sources/extsysmon/sources/abstractextsysmonsource.h rename to sources/extsysmonsources/abstractextsysmonsource.h index 23526cf..00d82fb 100644 --- a/sources/extsysmon/sources/abstractextsysmonsource.h +++ b/sources/extsysmonsources/abstractextsysmonsource.h @@ -25,6 +25,8 @@ class AbstractExtSysMonSource : public QObject { + Q_OBJECT + public: explicit AbstractExtSysMonSource(QObject *parent, const QStringList) : QObject(parent){}; @@ -40,6 +42,9 @@ public: rx.indexIn(source); return rx.cap().toInt(); } + +signals: + void dataReceived(const QVariantHash &); }; diff --git a/sources/extsysmon/sources/batterysource.cpp b/sources/extsysmonsources/batterysource.cpp similarity index 93% rename from sources/extsysmon/sources/batterysource.cpp rename to sources/extsysmonsources/batterysource.cpp index 96dfae2..985f044 100644 --- a/sources/extsysmon/sources/batterysource.cpp +++ b/sources/extsysmonsources/batterysource.cpp @@ -27,7 +27,7 @@ BatterySource::BatterySource(QObject *parent, const QStringList args) : AbstractExtSysMonSource(parent, args) { Q_ASSERT(args.count() == 1); - qCDebug(LOG_ESM) << __PRETTY_FUNCTION__; + qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; m_acpiPath = args.at(0); m_sources = getSources(); @@ -36,13 +36,13 @@ BatterySource::BatterySource(QObject *parent, const QStringList args) BatterySource::~BatterySource() { - qCDebug(LOG_ESM) << __PRETTY_FUNCTION__; + qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; } QVariant BatterySource::data(QString source) { - qCDebug(LOG_ESM) << "Source" << source; + qCDebug(LOG_ESS) << "Source" << source; if (!m_values.contains(source)) run(); @@ -53,7 +53,7 @@ QVariant BatterySource::data(QString source) QVariantMap BatterySource::initialData(QString source) const { - qCDebug(LOG_ESM) << "Source" << source; + qCDebug(LOG_ESS) << "Source" << source; QVariantMap data; if (source == QString("battery/ac")) { @@ -132,10 +132,10 @@ QStringList BatterySource::getSources() .entryList(QStringList() << QString("BAT*"), QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name) .count(); - qCInfo(LOG_ESM) << "Init batteries count as" << m_batteriesCount; + qCInfo(LOG_ESS) << "Init batteries count as" << m_batteriesCount; for (int i = 0; i < m_batteriesCount; i++) sources.append(QString("battery/bat%1").arg(i)); - qCInfo(LOG_ESM) << "Sources list" << sources; + qCInfo(LOG_ESS) << "Sources list" << sources; return sources; } diff --git a/sources/extsysmon/sources/batterysource.h b/sources/extsysmonsources/batterysource.h similarity index 100% rename from sources/extsysmon/sources/batterysource.h rename to sources/extsysmonsources/batterysource.h diff --git a/sources/extsysmon/sources/customsource.cpp b/sources/extsysmonsources/customsource.cpp similarity index 93% rename from sources/extsysmon/sources/customsource.cpp rename to sources/extsysmonsources/customsource.cpp index 26ad6e8..54763f1 100644 --- a/sources/extsysmon/sources/customsource.cpp +++ b/sources/extsysmonsources/customsource.cpp @@ -26,7 +26,7 @@ CustomSource::CustomSource(QObject *parent, const QStringList args) : AbstractExtSysMonSource(parent, args) { Q_ASSERT(args.count() == 0); - qCDebug(LOG_ESM) << __PRETTY_FUNCTION__; + qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; extScripts = new ExtItemAggregator(nullptr, QString("scripts")); m_sources = getSources(); @@ -35,7 +35,7 @@ CustomSource::CustomSource(QObject *parent, const QStringList args) CustomSource::~CustomSource() { - qCDebug(LOG_ESM) << __PRETTY_FUNCTION__; + qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; delete extScripts; } @@ -43,7 +43,7 @@ CustomSource::~CustomSource() QVariant CustomSource::data(QString source) { - qCDebug(LOG_ESM) << "Source" << source; + qCDebug(LOG_ESS) << "Source" << source; // there are only one value return extScripts->itemByTagNumber(index(source))->run().values().first(); @@ -52,7 +52,7 @@ QVariant CustomSource::data(QString source) QVariantMap CustomSource::initialData(QString source) const { - qCDebug(LOG_ESM) << "Source" << source; + qCDebug(LOG_ESS) << "Source" << source; QVariantMap data; data[QString("min")] = QString(""); diff --git a/sources/extsysmon/sources/customsource.h b/sources/extsysmonsources/customsource.h similarity index 100% rename from sources/extsysmon/sources/customsource.h rename to sources/extsysmonsources/customsource.h diff --git a/sources/extsysmon/sources/desktopsource.cpp b/sources/extsysmonsources/desktopsource.cpp similarity index 95% rename from sources/extsysmon/sources/desktopsource.cpp rename to sources/extsysmonsources/desktopsource.cpp index 3c3ec1d..5723557 100644 --- a/sources/extsysmon/sources/desktopsource.cpp +++ b/sources/extsysmonsources/desktopsource.cpp @@ -27,19 +27,19 @@ DesktopSource::DesktopSource(QObject *parent, const QStringList args) : AbstractExtSysMonSource(parent, args) { Q_ASSERT(args.count() == 0); - qCDebug(LOG_ESM) << __PRETTY_FUNCTION__; + qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; } DesktopSource::~DesktopSource() { - qCDebug(LOG_ESM) << __PRETTY_FUNCTION__; + qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; } QVariant DesktopSource::data(QString source) { - qCDebug(LOG_ESM) << "Source" << source; + qCDebug(LOG_ESS) << "Source" << source; int current = KWindowSystem::currentDesktop(); int total = KWindowSystem::numberOfDesktops(); @@ -63,7 +63,7 @@ QVariant DesktopSource::data(QString source) QVariantMap DesktopSource::initialData(QString source) const { - qCDebug(LOG_ESM) << "Source" << source; + qCDebug(LOG_ESS) << "Source" << source; QVariantMap data; if (source == QString("desktop/current/name")) { diff --git a/sources/extsysmon/sources/desktopsource.h b/sources/extsysmonsources/desktopsource.h similarity index 100% rename from sources/extsysmon/sources/desktopsource.h rename to sources/extsysmonsources/desktopsource.h diff --git a/sources/extsysmon/sources/gpuloadsource.cpp b/sources/extsysmonsources/gpuloadsource.cpp similarity index 83% rename from sources/extsysmon/sources/gpuloadsource.cpp rename to sources/extsysmonsources/gpuloadsource.cpp index c7d1396..1a4738d 100644 --- a/sources/extsysmon/sources/gpuloadsource.cpp +++ b/sources/extsysmonsources/gpuloadsource.cpp @@ -18,6 +18,7 @@ #include "gpuloadsource.h" +#include #include #include @@ -28,7 +29,7 @@ GPULoadSource::GPULoadSource(QObject *parent, const QStringList args) : AbstractExtSysMonSource(parent, args) { Q_ASSERT(args.count() == 1); - qCDebug(LOG_ESM) << __PRETTY_FUNCTION__; + qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; m_device = args.at(0); @@ -44,16 +45,34 @@ GPULoadSource::GPULoadSource(QObject *parent, const QStringList args) GPULoadSource::~GPULoadSource() { - qCDebug(LOG_ESM) << __PRETTY_FUNCTION__; + qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; m_process->kill(); m_process->deleteLater(); } +QString GPULoadSource::autoGpu() +{ + QString gpu = QString("disable"); + QFile moduleFile(QString("/proc/modules")); + if (!moduleFile.open(QIODevice::ReadOnly)) + return gpu; + + QString output = moduleFile.readAll(); + if (output.contains(QString("fglrx"))) + gpu = QString("ati"); + else if (output.contains(QString("nvidia"))) + gpu = QString("nvidia"); + + qCInfo(LOG_ESM) << "Device" << gpu; + return gpu; +} + + QVariant GPULoadSource::data(QString source) { - qCDebug(LOG_ESM) << "Source" << source; + qCDebug(LOG_ESS) << "Source" << source; if (source == QString("gpu/load")) run(); @@ -64,7 +83,7 @@ QVariant GPULoadSource::data(QString source) QVariantMap GPULoadSource::initialData(QString source) const { - qCDebug(LOG_ESM) << "Source" << source; + qCDebug(LOG_ESS) << "Source" << source; QVariantMap data; if (source == QString("gpu/load")) { @@ -87,7 +106,7 @@ void GPULoadSource::run() QString cmd = m_device == QString("nvidia") ? QString("nvidia-smi -q -x") : QString("aticonfig --od-getclocks"); - qCInfo(LOG_ESM) << "cmd" << cmd; + qCInfo(LOG_ESS) << "cmd" << cmd; m_process->start(cmd); } @@ -104,15 +123,15 @@ QStringList GPULoadSource::sources() const void GPULoadSource::updateValue() { - qCInfo(LOG_LIB) << "Cmd returns" << m_process->exitCode(); + qCInfo(LOG_ESS) << "Cmd returns" << m_process->exitCode(); QString qdebug = QTextCodec::codecForMib(106) ->toUnicode(m_process->readAllStandardError()) .trimmed(); - qCInfo(LOG_LIB) << "Error" << qdebug; + qCInfo(LOG_ESS) << "Error" << qdebug; QString qoutput = QTextCodec::codecForMib(106) ->toUnicode(m_process->readAllStandardOutput()) .trimmed(); - qCInfo(LOG_LIB) << "Output" << qoutput; + qCInfo(LOG_ESS) << "Output" << qoutput; if (m_device == QString("nvidia")) { for (auto str : qoutput.split(QChar('\n'), QString::SkipEmptyParts)) { diff --git a/sources/extsysmon/sources/gpuloadsource.h b/sources/extsysmonsources/gpuloadsource.h similarity index 98% rename from sources/extsysmon/sources/gpuloadsource.h rename to sources/extsysmonsources/gpuloadsource.h index 38e611b..c213309 100644 --- a/sources/extsysmon/sources/gpuloadsource.h +++ b/sources/extsysmonsources/gpuloadsource.h @@ -30,6 +30,7 @@ class GPULoadSource : public AbstractExtSysMonSource public: explicit GPULoadSource(QObject *parent, const QStringList args); virtual ~GPULoadSource(); + static QString autoGpu(); QVariant data(QString source); QVariantMap initialData(QString source) const; void run(); diff --git a/sources/extsysmon/sources/gputempsource.cpp b/sources/extsysmonsources/gputempsource.cpp similarity index 82% rename from sources/extsysmon/sources/gputempsource.cpp rename to sources/extsysmonsources/gputempsource.cpp index 45cdc4b..e69ff7c 100644 --- a/sources/extsysmon/sources/gputempsource.cpp +++ b/sources/extsysmonsources/gputempsource.cpp @@ -18,6 +18,7 @@ #include "gputempsource.h" +#include #include #include @@ -29,7 +30,7 @@ GPUTemperatureSource::GPUTemperatureSource(QObject *parent, : AbstractExtSysMonSource(parent, args) { Q_ASSERT(args.count() == 1); - qCDebug(LOG_ESM) << __PRETTY_FUNCTION__; + qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; m_device = args.at(0); @@ -45,16 +46,34 @@ GPUTemperatureSource::GPUTemperatureSource(QObject *parent, GPUTemperatureSource::~GPUTemperatureSource() { - qCDebug(LOG_ESM) << __PRETTY_FUNCTION__; + qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; m_process->kill(); m_process->deleteLater(); } +QString GPUTemperatureSource::autoGpu() +{ + QString gpu = QString("disable"); + QFile moduleFile(QString("/proc/modules")); + if (!moduleFile.open(QIODevice::ReadOnly)) + return gpu; + + QString output = moduleFile.readAll(); + if (output.contains(QString("fglrx"))) + gpu = QString("ati"); + else if (output.contains(QString("nvidia"))) + gpu = QString("nvidia"); + + qCInfo(LOG_ESM) << "Device" << gpu; + return gpu; +} + + QVariant GPUTemperatureSource::data(QString source) { - qCDebug(LOG_ESM) << "Source" << source; + qCDebug(LOG_ESS) << "Source" << source; if (source == QString("gpu/temperature")) run(); @@ -65,7 +84,7 @@ QVariant GPUTemperatureSource::data(QString source) QVariantMap GPUTemperatureSource::initialData(QString source) const { - qCDebug(LOG_ESM) << "Source" << source; + qCDebug(LOG_ESS) << "Source" << source; QVariantMap data; if (source == QString("gpu/temperature")) { @@ -88,7 +107,7 @@ void GPUTemperatureSource::run() QString cmd = m_device == QString("nvidia") ? QString("nvidia-smi -q -x") : QString("aticonfig --od-gettemperature"); - qCInfo(LOG_ESM) << "cmd" << cmd; + qCInfo(LOG_ESS) << "cmd" << cmd; m_process->start(cmd); } @@ -105,15 +124,15 @@ QStringList GPUTemperatureSource::sources() const void GPUTemperatureSource::updateValue() { - qCInfo(LOG_LIB) << "Cmd returns" << m_process->exitCode(); + qCInfo(LOG_ESS) << "Cmd returns" << m_process->exitCode(); QString qdebug = QTextCodec::codecForMib(106) ->toUnicode(m_process->readAllStandardError()) .trimmed(); - qCInfo(LOG_LIB) << "Error" << qdebug; + qCInfo(LOG_ESS) << "Error" << qdebug; QString qoutput = QTextCodec::codecForMib(106) ->toUnicode(m_process->readAllStandardOutput()) .trimmed(); - qCInfo(LOG_LIB) << "Output" << qoutput; + qCInfo(LOG_ESS) << "Output" << qoutput; if (m_device == QString("nvidia")) { for (auto str : qoutput.split(QChar('\n'), QString::SkipEmptyParts)) { diff --git a/sources/extsysmon/sources/gputempsource.h b/sources/extsysmonsources/gputempsource.h similarity index 98% rename from sources/extsysmon/sources/gputempsource.h rename to sources/extsysmonsources/gputempsource.h index fc2d7a0..62332c2 100644 --- a/sources/extsysmon/sources/gputempsource.h +++ b/sources/extsysmonsources/gputempsource.h @@ -30,6 +30,7 @@ class GPUTemperatureSource : public AbstractExtSysMonSource public: explicit GPUTemperatureSource(QObject *parent, const QStringList args); virtual ~GPUTemperatureSource(); + static QString autoGpu(); QVariant data(QString source); QVariantMap initialData(QString source) const; void run(); diff --git a/sources/extsysmon/sources/hddtempsource.cpp b/sources/extsysmonsources/hddtempsource.cpp similarity index 78% rename from sources/extsysmon/sources/hddtempsource.cpp rename to sources/extsysmonsources/hddtempsource.cpp index b0774e1..3fffff2 100644 --- a/sources/extsysmon/sources/hddtempsource.cpp +++ b/sources/extsysmonsources/hddtempsource.cpp @@ -18,6 +18,7 @@ #include "hddtempsource.h" +#include #include #include @@ -29,13 +30,13 @@ HDDTemperatureSource::HDDTemperatureSource(QObject *parent, : AbstractExtSysMonSource(parent, args) { Q_ASSERT(args.count() == 2); - qCDebug(LOG_ESM) << __PRETTY_FUNCTION__; + qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; m_devices = args.at(0).split(QChar(','), QString::SkipEmptyParts); m_cmd = args.at(1); m_smartctl = m_cmd.contains(QString("smartctl")); - qCInfo(LOG_ESM) << "Parse as smartctl" << m_smartctl; + qCInfo(LOG_ESS) << "Parse as smartctl" << m_smartctl; for (auto device : m_devices) { m_processes[device] = new QProcess(nullptr); @@ -53,7 +54,7 @@ HDDTemperatureSource::HDDTemperatureSource(QObject *parent, HDDTemperatureSource::~HDDTemperatureSource() { - qCDebug(LOG_ESM) << __PRETTY_FUNCTION__; + qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; for (auto device : m_devices) { m_processes[device]->kill(); @@ -62,9 +63,22 @@ HDDTemperatureSource::~HDDTemperatureSource() } +QStringList HDDTemperatureSource::allHdd() +{ + QStringList allDevices + = QDir(QString("/dev")).entryList(QDir::System, QDir::Name); + QStringList devices = allDevices.filter(QRegExp(QString("^[hms]d[a-z]$"))); + for (int i = 0; i < devices.count(); i++) + devices[i] = QString("/dev/%1").arg(devices.at(i)); + + qCInfo(LOG_ESS) << "Device list" << devices; + return devices; +} + + QVariant HDDTemperatureSource::data(QString source) { - qCDebug(LOG_ESM) << "Source" << source; + qCDebug(LOG_ESS) << "Source" << source; QString device = source.remove(QString("hdd/temperature")); // run cmd @@ -77,7 +91,7 @@ QVariant HDDTemperatureSource::data(QString source) QVariantMap HDDTemperatureSource::initialData(QString source) const { - qCDebug(LOG_ESM) << "Source" << source; + qCDebug(LOG_ESS) << "Source" << source; QString device = source.remove(QString("hdd/temperature")); QVariantMap data; @@ -103,23 +117,24 @@ QStringList HDDTemperatureSource::sources() const void HDDTemperatureSource::updateValue(const QString &device) { - qCDebug(LOG_LIB) << "Called with device" << device; + qCDebug(LOG_ESS) << "Called with device" << device; - qCInfo(LOG_LIB) << "Cmd returns" << m_processes[device]->exitCode(); + qCInfo(LOG_ESS) << "Cmd returns" << m_processes[device]->exitCode(); QString qdebug = QTextCodec::codecForMib(106) ->toUnicode(m_processes[device]->readAllStandardError()) .trimmed(); - qCInfo(LOG_LIB) << "Error" << qdebug; + qCInfo(LOG_ESS) << "Error" << qdebug; QString qoutput = QTextCodec::codecForMib(106) ->toUnicode(m_processes[device]->readAllStandardOutput()) .trimmed(); - qCInfo(LOG_LIB) << "Output" << qoutput; + qCInfo(LOG_ESS) << "Output" << qoutput; // parse if (m_smartctl) { - for (auto str : qoutput.split(QChar('\n'), QString::SkipEmptyParts)) { + QStringList lines = qoutput.split(QChar('\n'), QString::SkipEmptyParts); + for (auto str : lines) { if (!str.startsWith(QString("194"))) continue; if (str.split(QChar(' '), QString::SkipEmptyParts).count() < 9) @@ -130,11 +145,13 @@ void HDDTemperatureSource::updateValue(const QString &device) break; } } else { - if (qoutput.split(QChar(':'), QString::SkipEmptyParts).count() >= 3) { - QString temp - = qoutput.split(QChar(':'), QString::SkipEmptyParts).at(2); + QStringList lines = qoutput.split(QChar(':'), QString::SkipEmptyParts); + if (lines.count() >= 3) { + QString temp = lines.at(2); temp.remove(QChar(0260)).remove(QChar('C')); m_values[device] = temp.toFloat(); } } + + emit(dataReceived(m_values)); } diff --git a/sources/extsysmon/sources/hddtempsource.h b/sources/extsysmonsources/hddtempsource.h similarity index 98% rename from sources/extsysmon/sources/hddtempsource.h rename to sources/extsysmonsources/hddtempsource.h index ffc37b4..2daf711 100644 --- a/sources/extsysmon/sources/hddtempsource.h +++ b/sources/extsysmonsources/hddtempsource.h @@ -30,6 +30,7 @@ class HDDTemperatureSource : public AbstractExtSysMonSource public: explicit HDDTemperatureSource(QObject *parent, const QStringList args); virtual ~HDDTemperatureSource(); + static QStringList allHdd(); QVariant data(QString source); QVariantMap initialData(QString source) const; void run(){}; diff --git a/sources/extsysmon/sources/loadsource.cpp b/sources/extsysmonsources/loadsource.cpp similarity index 92% rename from sources/extsysmon/sources/loadsource.cpp rename to sources/extsysmonsources/loadsource.cpp index e5eff33..7b9d008 100644 --- a/sources/extsysmon/sources/loadsource.cpp +++ b/sources/extsysmonsources/loadsource.cpp @@ -25,19 +25,19 @@ LoadSource::LoadSource(QObject *parent, const QStringList args) : AbstractExtSysMonSource(parent, args) { Q_ASSERT(args.count() == 0); - qCDebug(LOG_ESM) << __PRETTY_FUNCTION__; + qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; } LoadSource::~LoadSource() { - qCDebug(LOG_ESM) << __PRETTY_FUNCTION__; + qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; } QVariant LoadSource::data(QString source) { - qCDebug(LOG_ESM) << "Source" << source; + qCDebug(LOG_ESS) << "Source" << source; source.remove(QString("load/load")); return source.toInt(); @@ -46,7 +46,7 @@ QVariant LoadSource::data(QString source) QVariantMap LoadSource::initialData(QString source) const { - qCDebug(LOG_ESM) << "Source" << source; + qCDebug(LOG_ESS) << "Source" << source; QVariantMap data; if (source.startsWith(QString("load/load"))) { diff --git a/sources/extsysmon/sources/loadsource.h b/sources/extsysmonsources/loadsource.h similarity index 100% rename from sources/extsysmon/sources/loadsource.h rename to sources/extsysmonsources/loadsource.h diff --git a/sources/extsysmon/sources/networksource.cpp b/sources/extsysmonsources/networksource.cpp similarity index 92% rename from sources/extsysmon/sources/networksource.cpp rename to sources/extsysmonsources/networksource.cpp index 45a27ef..249601d 100644 --- a/sources/extsysmon/sources/networksource.cpp +++ b/sources/extsysmonsources/networksource.cpp @@ -27,25 +27,25 @@ NetworkSource::NetworkSource(QObject *parent, const QStringList args) : AbstractExtSysMonSource(parent, args) { Q_ASSERT(args.count() == 0); - qCDebug(LOG_ESM) << __PRETTY_FUNCTION__; + qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; } NetworkSource::~NetworkSource() { - qCDebug(LOG_ESM) << __PRETTY_FUNCTION__; + qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; } QVariant NetworkSource::data(QString source) { - qCDebug(LOG_ESM) << "Source" << source; + qCDebug(LOG_ESS) << "Source" << source; if (source == QString("network/current/name")) { QString device = QString("lo"); QList rawInterfaceList = QNetworkInterface::allInterfaces(); - qCInfo(LOG_ESM) << "Devices" << rawInterfaceList; + qCInfo(LOG_ESS) << "Devices" << rawInterfaceList; for (auto interface : rawInterfaceList) { if ((interface.flags().testFlag(QNetworkInterface::IsLoopBack)) || (interface.flags().testFlag( @@ -65,7 +65,7 @@ QVariant NetworkSource::data(QString source) QVariantMap NetworkSource::initialData(QString source) const { - qCDebug(LOG_ESM) << "Source" << source; + qCDebug(LOG_ESS) << "Source" << source; QVariantMap data; if (source == QString("network/current/name")) { diff --git a/sources/extsysmon/sources/networksource.h b/sources/extsysmonsources/networksource.h similarity index 100% rename from sources/extsysmon/sources/networksource.h rename to sources/extsysmonsources/networksource.h diff --git a/sources/extsysmon/sources/playersource.cpp b/sources/extsysmonsources/playersource.cpp similarity index 95% rename from sources/extsysmon/sources/playersource.cpp rename to sources/extsysmonsources/playersource.cpp index df832e1..80c159b 100644 --- a/sources/extsysmon/sources/playersource.cpp +++ b/sources/extsysmonsources/playersource.cpp @@ -32,7 +32,7 @@ PlayerSource::PlayerSource(QObject *parent, const QStringList args) : AbstractExtSysMonSource(parent, args) { Q_ASSERT(args.count() == 5); - qCDebug(LOG_ESM) << __PRETTY_FUNCTION__; + qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; m_player = args.at(0); m_mpdAddress = QString("%1:%2").arg(args.at(1)).arg(args.at(2)); @@ -52,7 +52,7 @@ PlayerSource::PlayerSource(QObject *parent, const QStringList args) PlayerSource::~PlayerSource() { - qCDebug(LOG_ESM) << __PRETTY_FUNCTION__; + qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; m_mpdProcess->kill(); m_mpdProcess->deleteLater(); @@ -61,7 +61,7 @@ PlayerSource::~PlayerSource() QVariant PlayerSource::data(QString source) { - qCDebug(LOG_ESM) << "Source" << source; + qCDebug(LOG_ESS) << "Source" << source; if (!m_values.contains(source)) run(); @@ -72,7 +72,7 @@ QVariant PlayerSource::data(QString source) QVariantMap PlayerSource::initialData(QString source) const { - qCDebug(LOG_ESM) << "Source" << source; + qCDebug(LOG_ESS) << "Source" << source; QVariantMap data; if (source == QString("player/album")) { @@ -214,15 +214,15 @@ QStringList PlayerSource::sources() const void PlayerSource::updateValue() { - qCInfo(LOG_LIB) << "Cmd returns" << m_mpdProcess->exitCode(); + qCInfo(LOG_ESS) << "Cmd returns" << m_mpdProcess->exitCode(); QString qdebug = QTextCodec::codecForMib(106) ->toUnicode(m_mpdProcess->readAllStandardError()) .trimmed(); - qCInfo(LOG_LIB) << "Error" << qdebug; + qCInfo(LOG_ESS) << "Error" << qdebug; QString qoutput = QTextCodec::codecForMib(106) ->toUnicode(m_mpdProcess->readAllStandardOutput()) .trimmed(); - qCInfo(LOG_LIB) << "Output" << qoutput; + qCInfo(LOG_ESS) << "Output" << qoutput; for (auto str : qoutput.split(QChar('\n'), QString::SkipEmptyParts)) { if (str.split(QString(": "), QString::SkipEmptyParts).count() == 2) { @@ -270,7 +270,7 @@ QString PlayerSource::getAutoMpris() const for (auto arg : arguments) { if (!arg.startsWith(QString("org.mpris.MediaPlayer2."))) continue; - qCInfo(LOG_ESM) << "Service found" << arg; + qCInfo(LOG_ESS) << "Service found" << arg; QString service = arg; service.remove(QString("org.mpris.MediaPlayer2.")); return service; @@ -282,13 +282,13 @@ QString PlayerSource::getAutoMpris() const QVariantHash PlayerSource::getPlayerMpdInfo(const QString mpdAddress) const { - qCDebug(LOG_ESM) << "MPD" << mpdAddress; + qCDebug(LOG_ESS) << "MPD" << mpdAddress; // build cmd QString cmd = QString("bash -c \"echo 'currentsong\nstatus\nclose' | curl " "--connect-timeout 1 -fsm 3 telnet://%1\"") .arg(mpdAddress); - qCInfo(LOG_ESM) << "cmd" << cmd; + qCInfo(LOG_ESS) << "cmd" << cmd; m_mpdProcess->start(cmd); return m_mpdCached; @@ -297,7 +297,7 @@ QVariantHash PlayerSource::getPlayerMpdInfo(const QString mpdAddress) const QVariantHash PlayerSource::getPlayerMprisInfo(const QString mpris) const { - qCDebug(LOG_ESM) << "MPRIS" << mpris; + qCDebug(LOG_ESS) << "MPRIS" << mpris; QVariantHash info = defaultInfo(); if (mpris.isEmpty()) @@ -322,7 +322,7 @@ QVariantHash PlayerSource::getPlayerMprisInfo(const QString mpris) const QDBusMessage response = bus.call(request, QDBus::BlockWithGui); if ((response.type() != QDBusMessage::ReplyMessage) || (response.arguments().isEmpty())) { - qCWarning(LOG_ESM) << "Error message" << response.errorMessage(); + qCWarning(LOG_ESS) << "Error message" << response.errorMessage(); } else { // another portion of dirty magic QVariantHash map @@ -348,7 +348,7 @@ QVariantHash PlayerSource::getPlayerMprisInfo(const QString mpris) const response = bus.call(request, QDBus::BlockWithGui); if ((response.type() != QDBusMessage::ReplyMessage) || (response.arguments().isEmpty())) { - qCWarning(LOG_ESM) << "Error message" << response.errorMessage(); + qCWarning(LOG_ESS) << "Error message" << response.errorMessage(); } else { // this cast is simpler than the previous one ;) info[QString("player/progress")] = response.arguments() @@ -366,7 +366,7 @@ QVariantHash PlayerSource::getPlayerMprisInfo(const QString mpris) const QString PlayerSource::buildString(const QString current, const QString value, const int s) const { - qCDebug(LOG_ESM) << "Current value" << current << "received" << value + qCDebug(LOG_ESS) << "Current value" << current << "received" << value << "will be stripped after" << s; int index = value.indexOf(current); @@ -379,7 +379,7 @@ QString PlayerSource::buildString(const QString current, const QString value, QString PlayerSource::stripString(const QString value, const int s) const { - qCDebug(LOG_ESM) << "New value" << value << "will be stripped after" << s; + qCDebug(LOG_ESS) << "New value" << value << "will be stripped after" << s; return value.count() > s ? QString("%1\u2026").arg(value.left(s - 1)) : value.leftJustified(s, QLatin1Char(' ')); diff --git a/sources/extsysmon/sources/playersource.h b/sources/extsysmonsources/playersource.h similarity index 100% rename from sources/extsysmon/sources/playersource.h rename to sources/extsysmonsources/playersource.h diff --git a/sources/extsysmon/sources/processessource.cpp b/sources/extsysmonsources/processessource.cpp similarity index 95% rename from sources/extsysmon/sources/processessource.cpp rename to sources/extsysmonsources/processessource.cpp index 6054909..7cdcdf3 100644 --- a/sources/extsysmon/sources/processessource.cpp +++ b/sources/extsysmonsources/processessource.cpp @@ -27,19 +27,19 @@ ProcessesSource::ProcessesSource(QObject *parent, const QStringList args) : AbstractExtSysMonSource(parent, args) { Q_ASSERT(args.count() == 0); - qCDebug(LOG_ESM) << __PRETTY_FUNCTION__; + qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; } ProcessesSource::~ProcessesSource() { - qCDebug(LOG_ESM) << __PRETTY_FUNCTION__; + qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; } QVariant ProcessesSource::data(QString source) { - qCDebug(LOG_ESM) << "Source" << source; + qCDebug(LOG_ESS) << "Source" << source; if (!m_values.contains(source)) run(); @@ -50,7 +50,7 @@ QVariant ProcessesSource::data(QString source) QVariantMap ProcessesSource::initialData(QString source) const { - qCDebug(LOG_ESM) << "Source" << source; + qCDebug(LOG_ESS) << "Source" << source; QVariantMap data; if (source == QString("ps/running/count")) { diff --git a/sources/extsysmon/sources/processessource.h b/sources/extsysmonsources/processessource.h similarity index 100% rename from sources/extsysmon/sources/processessource.h rename to sources/extsysmonsources/processessource.h diff --git a/sources/extsysmon/sources/quotessource.cpp b/sources/extsysmonsources/quotessource.cpp similarity index 97% rename from sources/extsysmon/sources/quotessource.cpp rename to sources/extsysmonsources/quotessource.cpp index 4a44b09..238136f 100644 --- a/sources/extsysmon/sources/quotessource.cpp +++ b/sources/extsysmonsources/quotessource.cpp @@ -26,7 +26,7 @@ QuotesSource::QuotesSource(QObject *parent, const QStringList args) : AbstractExtSysMonSource(parent, args) { Q_ASSERT(args.count() == 0); - qCDebug(LOG_ESM) << __PRETTY_FUNCTION__; + qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; extQuotes = new ExtItemAggregator(nullptr, QString("quotes")); m_sources = getSources(); @@ -35,7 +35,7 @@ QuotesSource::QuotesSource(QObject *parent, const QStringList args) QuotesSource::~QuotesSource() { - qCDebug(LOG_ESM) << __PRETTY_FUNCTION__; + qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; delete extQuotes; } @@ -43,7 +43,7 @@ QuotesSource::~QuotesSource() QVariant QuotesSource::data(QString source) { - qCDebug(LOG_ESM) << "Source" << source; + qCDebug(LOG_ESS) << "Source" << source; int ind = index(source); source.remove(QString("quotes/")); @@ -59,7 +59,7 @@ QVariant QuotesSource::data(QString source) QVariantMap QuotesSource::initialData(QString source) const { - qCDebug(LOG_ESM) << "Source" << source; + qCDebug(LOG_ESS) << "Source" << source; int ind = index(source); QVariantMap data; diff --git a/sources/extsysmon/sources/quotessource.h b/sources/extsysmonsources/quotessource.h similarity index 100% rename from sources/extsysmon/sources/quotessource.h rename to sources/extsysmonsources/quotessource.h diff --git a/sources/extsysmon/sources/upgradesource.cpp b/sources/extsysmonsources/upgradesource.cpp similarity index 93% rename from sources/extsysmon/sources/upgradesource.cpp rename to sources/extsysmonsources/upgradesource.cpp index 243c0bd..0103da8 100644 --- a/sources/extsysmon/sources/upgradesource.cpp +++ b/sources/extsysmonsources/upgradesource.cpp @@ -26,7 +26,7 @@ UpgradeSource::UpgradeSource(QObject *parent, const QStringList args) : AbstractExtSysMonSource(parent, args) { Q_ASSERT(args.count() == 0); - qCDebug(LOG_ESM) << __PRETTY_FUNCTION__; + qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; extUpgrade = new ExtItemAggregator(nullptr, QString("upgrade")); m_sources = getSources(); @@ -35,7 +35,7 @@ UpgradeSource::UpgradeSource(QObject *parent, const QStringList args) UpgradeSource::~UpgradeSource() { - qCDebug(LOG_ESM) << __PRETTY_FUNCTION__; + qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; delete extUpgrade; } @@ -43,7 +43,7 @@ UpgradeSource::~UpgradeSource() QVariant UpgradeSource::data(QString source) { - qCDebug(LOG_ESM) << "Source" << source; + qCDebug(LOG_ESS) << "Source" << source; // there are only one value return extUpgrade->itemByTagNumber(index(source))->run().values().first(); @@ -52,7 +52,7 @@ QVariant UpgradeSource::data(QString source) QVariantMap UpgradeSource::initialData(QString source) const { - qCDebug(LOG_ESM) << "Source" << source; + qCDebug(LOG_ESS) << "Source" << source; QVariantMap data; data[QString("min")] = QString(""); diff --git a/sources/extsysmon/sources/upgradesource.h b/sources/extsysmonsources/upgradesource.h similarity index 100% rename from sources/extsysmon/sources/upgradesource.h rename to sources/extsysmonsources/upgradesource.h diff --git a/sources/extsysmon/sources/weathersource.cpp b/sources/extsysmonsources/weathersource.cpp similarity index 96% rename from sources/extsysmon/sources/weathersource.cpp rename to sources/extsysmonsources/weathersource.cpp index 910ad31..1f95a90 100644 --- a/sources/extsysmon/sources/weathersource.cpp +++ b/sources/extsysmonsources/weathersource.cpp @@ -26,7 +26,7 @@ WeatherSource::WeatherSource(QObject *parent, const QStringList args) : AbstractExtSysMonSource(parent, args) { Q_ASSERT(args.count() == 0); - qCDebug(LOG_ESM) << __PRETTY_FUNCTION__; + qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; extWeather = new ExtItemAggregator(nullptr, QString("weather")); m_sources = getSources(); @@ -35,7 +35,7 @@ WeatherSource::WeatherSource(QObject *parent, const QStringList args) WeatherSource::~WeatherSource() { - qCDebug(LOG_ESM) << __PRETTY_FUNCTION__; + qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; delete extWeather; } @@ -43,7 +43,7 @@ WeatherSource::~WeatherSource() QVariant WeatherSource::data(QString source) { - qCDebug(LOG_ESM) << "Source" << source; + qCDebug(LOG_ESS) << "Source" << source; int ind = index(source); source.remove(QString("weather/")); @@ -59,7 +59,7 @@ QVariant WeatherSource::data(QString source) QVariantMap WeatherSource::initialData(QString source) const { - qCDebug(LOG_ESM) << "Source" << source; + qCDebug(LOG_ESS) << "Source" << source; int ind = index(source); QVariantMap data; diff --git a/sources/extsysmon/sources/weathersource.h b/sources/extsysmonsources/weathersource.h similarity index 100% rename from sources/extsysmon/sources/weathersource.h rename to sources/extsysmonsources/weathersource.h diff --git a/sources/test/CMakeLists.txt b/sources/test/CMakeLists.txt index b6032f0..eb944a1 100644 --- a/sources/test/CMakeLists.txt +++ b/sources/test/CMakeLists.txt @@ -7,6 +7,7 @@ include_directories( ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../${PROJECT_LIBRARY}/ + ${CMAKE_CURRENT_SOURCE_DIR}/../${PROJECT_MONITORSOURCES}/ ${PROJECT_TRDPARTY_DIR} ${Qt_INCLUDE} ${Qt5Test_INCLUDE_DIRS} @@ -18,13 +19,14 @@ set(AWTESTLIBRARY_HEADERS awtestlibrary.h) set(AWTESTLIBRARY_SOURCES awtestlibrary.cpp) add_library(${SUBPROJECT}-awtest STATIC ${AWTESTLIBRARY_SOURCES} ${AWTESTLIBRARY_HEADERS}) target_link_libraries(${SUBPROJECT}-awtest ${Qt_LIBRARIES} ${Qt5Test_LIBRARIES}) -set(LIBRARY_TEST_SET ${SUBPROJECT}-awtest ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Qt5Test_LIBRARIES}) +set(LIBRARY_TEST_SET ${SUBPROJECT}-awtest ${PROJECT_LIBRARY} ${PROJECT_MONITORSOURCES} ${Qt_LIBRARIES} ${Qt5Test_LIBRARIES}) ## modules set(TEST_MODULES abstractextitem extquotes extscript extupgrade extweather abstractformatter datetimeformatter floatformatter noformatter scriptformatter - extitemaggregator) + extitemaggregator + hddtempsource) foreach (TEST_MODULE ${TEST_MODULES}) set(${TEST_MODULE}_HEADERS test${TEST_MODULE}.h) set(${TEST_MODULE}_SOURCES test${TEST_MODULE}.cpp) diff --git a/sources/test/testextitemaggregator.h b/sources/test/testextitemaggregator.h index e5fc449..022e501 100644 --- a/sources/test/testextitemaggregator.h +++ b/sources/test/testextitemaggregator.h @@ -21,8 +21,9 @@ #include + class AWNoFormatter; -template class ExtItemAggregator; +template class ExtItemAggregator; class TestExtItemAggregator : public QObject { diff --git a/sources/test/testextweather.cpp b/sources/test/testextweather.cpp index d1d38d9..825ee26 100644 --- a/sources/test/testextweather.cpp +++ b/sources/test/testextweather.cpp @@ -123,13 +123,13 @@ void TestExtWeather::run() QWARN("May fail here for Yahoo! Weather, see " "https://yahoo.uservoice.com/forums/207813-us-weather/suggestions/" "14209233-invalid-pressure-calculation"); - QVERIFY((arguments[extWeather->tag(QString("pressure"))].toFloat() + QVERIFY((arguments[extWeather->tag(QString("pressure"))].toInt() > pressure.first) && (arguments[extWeather->tag(QString("pressure"))].toInt() < pressure.second)); QVERIFY((arguments[extWeather->tag(QString("temperature"))].toFloat() > temp.first) - && (arguments[extWeather->tag(QString("temperature"))].toInt() + && (arguments[extWeather->tag(QString("temperature"))].toFloat() < temp.second)); // image should be only one symbol here QCOMPARE(arguments[extWeather->tag(QString("weather"))].toString().count(), diff --git a/sources/test/testhddtempsource.cpp b/sources/test/testhddtempsource.cpp new file mode 100644 index 0000000..de4914b --- /dev/null +++ b/sources/test/testhddtempsource.cpp @@ -0,0 +1,91 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + + +#include "testhddtempsource.h" + +#include + +#include "awtestlibrary.h" +#include "hddtempsource.h" + + +void TestHDDTemperatureSource::initTestCase() +{ + devices = HDDTemperatureSource::allHdd(); + QVERIFY(devices.count() > 0); + + hddtempSource = new HDDTemperatureSource( + this, QStringList() << devices.join(QChar(',')) << hddtempCmd); + smartctlSource = new HDDTemperatureSource( + this, QStringList() << devices.join(QChar(',')) << smartctlCmd); +} + + +void TestHDDTemperatureSource::cleanupTestCase() +{ + delete hddtempSource; + delete smartctlSource; +} + + +void TestHDDTemperatureSource::test_sources() +{ + std::for_each(devices.begin(), devices.end(), [](QString &device) { + device.prepend(QString("hdd/temperature")); + }); + + QCOMPARE(hddtempSource->sources(), devices); + QCOMPARE(smartctlSource->sources(), devices); +} + + +void TestHDDTemperatureSource::test_hddtemp() +{ + std::for_each(devices.begin(), devices.end(), [this](QString device) { + QSignalSpy spy(hddtempSource, + SIGNAL(dataReceived(const QVariantHash &))); + float firstValue = hddtempSource->data(device).toFloat(); + QCOMPARE(firstValue, 0.0f); + + QVERIFY(spy.wait(5000)); + QVariantHash arguments = spy.takeFirst().at(0).toHash(); + device.remove(QString("hdd/temperature")); + float secondValue = arguments[device].toFloat(); + QVERIFY((secondValue >= temp.first) && (secondValue <= temp.second)); + }); +} + + +void TestHDDTemperatureSource::test_smartctl() +{ + std::for_each(devices.begin(), devices.end(), [this](QString &device) { + QSignalSpy spy(smartctlSource, + SIGNAL(dataReceived(const QVariantHash &))); + float firstValue = smartctlSource->data(device).toFloat(); + QCOMPARE(firstValue, 0.0f); + + QVERIFY(spy.wait(5000)); + QVariantHash arguments = spy.takeFirst().at(0).toHash(); + device.remove(QString("hdd/temperature")); + float secondValue = arguments[device].toFloat(); + QVERIFY((secondValue >= temp.first) && (secondValue <= temp.second)); + }); +} + + +QTEST_MAIN(TestHDDTemperatureSource); diff --git a/sources/test/testhddtempsource.h b/sources/test/testhddtempsource.h new file mode 100644 index 0000000..b558692 --- /dev/null +++ b/sources/test/testhddtempsource.h @@ -0,0 +1,50 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + + +#ifndef TESTHDDTEMPSOURCE_H +#define TESTHDDTEMPSOURCE_H + +#include + + +class HDDTemperatureSource; + +class TestHDDTemperatureSource : public QObject +{ + Q_OBJECT + +private slots: + // initialization + void initTestCase(); + void cleanupTestCase(); + // test + void test_sources(); + void test_hddtemp(); + void test_smartctl(); + +private: + HDDTemperatureSource *hddtempSource = nullptr; + HDDTemperatureSource *smartctlSource = nullptr; + QStringList devices; + QString hddtempCmd = QString("sudo hddtemp"); + QString smartctlCmd = QString("sudo smartctl -a"); + QPair temp = QPair(0.0f, 40.0f); +}; + + +#endif /* TESTHDDTEMPSOURCE_H */