From 9e45b02c8e16ad8f6d604020d089d9295e3b5d8a Mon Sep 17 00:00:00 2001 From: arcan1s Date: Wed, 9 Sep 2015 01:48:09 +0300 Subject: [PATCH] move extsysmon and plugin to the new source model --- sources/extsysmon/CMakeLists.txt | 2 +- sources/extsysmon/extsysmonaggregator.cpp | 78 ++++ sources/extsysmon/extsysmonaggregator.h | 44 +++ .../sources/abstractextsysmonsource.h | 45 +++ sources/extsysmon/sources/batterysource.cpp | 138 ++++++++ sources/extsysmon/sources/batterysource.h | 46 +++ sources/extsysmon/sources/customsource.cpp | 87 +++++ sources/extsysmon/sources/customsource.h | 47 +++ sources/extsysmon/sources/desktopsource.cpp | 112 ++++++ sources/extsysmon/sources/desktopsource.h | 38 ++ sources/extsysmon/sources/gpuloadsource.cpp | 111 ++++++ sources/extsysmon/sources/gpuloadsource.h | 42 +++ sources/extsysmon/sources/gputempsource.cpp | 109 ++++++ sources/extsysmon/sources/gputempsource.h | 42 +++ sources/extsysmon/sources/hddtempsource.cpp | 107 ++++++ sources/extsysmon/sources/hddtempsource.h | 44 +++ sources/extsysmon/sources/networksource.cpp | 89 +++++ sources/extsysmon/sources/networksource.h | 38 ++ sources/extsysmon/sources/playersource.cpp | 334 ++++++++++++++++++ sources/extsysmon/sources/playersource.h | 52 +++ sources/extsysmon/sources/processessource.cpp | 115 ++++++ sources/extsysmon/sources/processessource.h | 42 +++ sources/extsysmon/sources/quotessource.cpp | 149 ++++++++ sources/extsysmon/sources/quotessource.h | 48 +++ sources/extsysmon/sources/updatesource.cpp | 73 ++++ sources/extsysmon/sources/updatesource.h | 38 ++ sources/extsysmon/sources/upgradesource.cpp | 87 +++++ sources/extsysmon/sources/upgradesource.h | 47 +++ sources/extsysmon/sources/weathersource.cpp | 121 +++++++ sources/extsysmon/sources/weathersource.h | 48 +++ 30 files changed, 2372 insertions(+), 1 deletion(-) create mode 100644 sources/extsysmon/extsysmonaggregator.cpp create mode 100644 sources/extsysmon/extsysmonaggregator.h create mode 100644 sources/extsysmon/sources/abstractextsysmonsource.h create mode 100644 sources/extsysmon/sources/batterysource.cpp create mode 100644 sources/extsysmon/sources/batterysource.h create mode 100644 sources/extsysmon/sources/customsource.cpp create mode 100644 sources/extsysmon/sources/customsource.h create mode 100644 sources/extsysmon/sources/desktopsource.cpp create mode 100644 sources/extsysmon/sources/desktopsource.h create mode 100644 sources/extsysmon/sources/gpuloadsource.cpp create mode 100644 sources/extsysmon/sources/gpuloadsource.h create mode 100644 sources/extsysmon/sources/gputempsource.cpp create mode 100644 sources/extsysmon/sources/gputempsource.h create mode 100644 sources/extsysmon/sources/hddtempsource.cpp create mode 100644 sources/extsysmon/sources/hddtempsource.h create mode 100644 sources/extsysmon/sources/networksource.cpp create mode 100644 sources/extsysmon/sources/networksource.h create mode 100644 sources/extsysmon/sources/playersource.cpp create mode 100644 sources/extsysmon/sources/playersource.h create mode 100644 sources/extsysmon/sources/processessource.cpp create mode 100644 sources/extsysmon/sources/processessource.h create mode 100644 sources/extsysmon/sources/quotessource.cpp create mode 100644 sources/extsysmon/sources/quotessource.h create mode 100644 sources/extsysmon/sources/updatesource.cpp create mode 100644 sources/extsysmon/sources/updatesource.h create mode 100644 sources/extsysmon/sources/upgradesource.cpp create mode 100644 sources/extsysmon/sources/upgradesource.h create mode 100644 sources/extsysmon/sources/weathersource.cpp create mode 100644 sources/extsysmon/sources/weathersource.h diff --git a/sources/extsysmon/CMakeLists.txt b/sources/extsysmon/CMakeLists.txt index c3789fc..6f46bb1 100644 --- a/sources/extsysmon/CMakeLists.txt +++ b/sources/extsysmon/CMakeLists.txt @@ -16,7 +16,7 @@ include_directories( file(GLOB SUBPROJECT_DESKTOP_IN *.desktop) file(RELATIVE_PATH SUBPROJECT_DESKTOP ${CMAKE_SOURCE_DIR} ${SUBPROJECT_DESKTOP_IN}) -file(GLOB SUBPROJECT_SOURCE *.cpp ${PROJECT_TRDPARTY_DIR}/task/*.cpp ${CMAKE_SOURCE_DIR}/*.cpp) +file(GLOB SUBPROJECT_SOURCE *.cpp sources/*.cpp ${PROJECT_TRDPARTY_DIR}/task/*.cpp ${CMAKE_SOURCE_DIR}/*.cpp) set(TASK_HEADER ${PROJECT_TRDPARTY_DIR}/task/task.h) file(GLOB SUBPROJECT_CONF *.conf) file(GLOB SUBPROJECT_INI *.ini) diff --git a/sources/extsysmon/extsysmonaggregator.cpp b/sources/extsysmon/extsysmonaggregator.cpp new file mode 100644 index 0000000..de35edd --- /dev/null +++ b/sources/extsysmon/extsysmonaggregator.cpp @@ -0,0 +1,78 @@ +/*************************************************************************** + * 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 "extsysmonaggregator.h" + +#include "awdebug.h" + + +ExtSysMonAggregator::ExtSysMonAggregator(QObject *parent, const QHash config) + : QObject(parent) +{ + qCDebug(LOG_ESM); + + init(config); +} + + +ExtSysMonAggregator::~ExtSysMonAggregator() +{ + qCDebug(LOG_ESM); + + m_map.clear(); +} + + +QVariant ExtSysMonAggregator::data(const QString source) const +{ + qCDebug(LOG_ESM); + qCDebug(LOG_ESM) << "Source" << source; + + return m_map.contains(source) ? m_map[source]->data(source) : QVariant(); +} + + +AbstractExtSysMonSource *ExtSysMonAggregator::engine(const QString source) +{ + qCDebug(LOG_ESM); + qCDebug(LOG_ESM) << "Source" << source; + + return m_map.contains(source) ? m_map[source] : nullptr; +} + + +QVariantMap ExtSysMonAggregator::initialData(const QString source) const +{ + qCDebug(LOG_ESM); + qCDebug(LOG_ESM) << "Source" << source; + + return m_map.contains(source) ? m_map[source]->initialData(source) : QVariantMap(); +} + + +QStringList ExtSysMonAggregator::sources() const +{ + qCDebug(LOG_ESM); + + return m_map.keys(); +} + + +void ExtSysMonAggregator::init(const QHash config) +{ + qCDebug(LOG_ESM); +} diff --git a/sources/extsysmon/extsysmonaggregator.h b/sources/extsysmon/extsysmonaggregator.h new file mode 100644 index 0000000..5f1fb32 --- /dev/null +++ b/sources/extsysmon/extsysmonaggregator.h @@ -0,0 +1,44 @@ +/*************************************************************************** + * 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 EXTSYSMONAGGREGATOR_H +#define EXTSYSMONAGGREGATOR_H + +#include + +#include "sources/abstractextsysmonsource.h" + + +class ExtSysMonAggregator : public QObject +{ + Q_OBJECT + +public: + explicit ExtSysMonAggregator(QObject *parent, const QHash config); + virtual ~ExtSysMonAggregator(); + QVariant data(const QString source) const; + AbstractExtSysMonSource *engine(const QString source); + QVariantMap initialData(const QString source) const; + QStringList sources() const; + +private: + void init(const QHash config); + QHash m_map; +}; + + +#endif /* EXTSYSMONAGGREGATOR_H */ diff --git a/sources/extsysmon/sources/abstractextsysmonsource.h b/sources/extsysmon/sources/abstractextsysmonsource.h new file mode 100644 index 0000000..a2b9b00 --- /dev/null +++ b/sources/extsysmon/sources/abstractextsysmonsource.h @@ -0,0 +1,45 @@ +/*************************************************************************** + * 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 ABSTRACTEXTSYSMONSOURCE_H +#define ABSTRACTEXTSYSMONSOURCE_H + +#include +#include +#include + + +class AbstractExtSysMonSource : public QObject +{ +public: + explicit AbstractExtSysMonSource(QObject *parent, const QStringList) : QObject(parent) {}; + virtual ~AbstractExtSysMonSource() {}; + virtual QVariant data(QString source) = 0; + virtual QVariantMap initialData(QString source) const = 0; + virtual void run() = 0; + virtual QStringList sources() const = 0; + // used by extensions + int index(const QString source) const + { + QRegExp rx(QString("\\d+")); + rx.indexIn(source); + return rx.cap().toInt(); + } +}; + + +#endif /* ABSTRACTEXTSYSMONSOURCE_H */ diff --git a/sources/extsysmon/sources/batterysource.cpp b/sources/extsysmon/sources/batterysource.cpp new file mode 100644 index 0000000..cc90e2c --- /dev/null +++ b/sources/extsysmon/sources/batterysource.cpp @@ -0,0 +1,138 @@ +/*************************************************************************** + * 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 "batterysource.h" + +#include + +#include "awdebug.h" + + +BatterySource::BatterySource(QObject *parent, const QStringList args) + : AbstractExtSysMonSource(parent, args) +{ + Q_ASSERT(args.count() == 1); + qCDebug(LOG_ESM); + + m_acpiPath = args.at(0); + m_sources = getSources(); +} + + +BatterySource::~BatterySource() +{ + qCDebug(LOG_ESM); +} + + +QVariant BatterySource::data(QString source) +{ + qCDebug(LOG_ESM); + qCDebug(LOG_ESM) << "Source" << source; + + if (source == QString("battery/ac")) run(); + return values[source]; +} + + +QVariantMap BatterySource::initialData(QString source) const +{ + qCDebug(LOG_ESM); + qCDebug(LOG_ESM) << "Source" << source; + + QVariantMap data; + if (source == QString("battery/ac")) { + data[QString("min")] = false; + data[QString("max")] = true; + data[QString("name")] = QString("Is AC online or not"); + data[QString("type")] = QString("bool"); + data[QString("units")] = QString(""); + } else if (source == QString("battery/bat")) { + data[QString("min")] = 0; + data[QString("max")] = 100; + data[QString("name")] = QString("Average battery usage"); + data[QString("type")] = QString("integer"); + data[QString("units")] = QString("%"); + } else { + data[QString("min")] = 0; + data[QString("max")] = 100; + data[QString("name")] = QString("Battery %1 usage").arg(source.remove(QString("battery/bat"))); + data[QString("type")] = QString("integer"); + data[QString("units")] = QString("%"); + } + + return data; +} + + +void BatterySource::run() +{ + qCDebug(LOG_ESM); + + // adaptor + QFile acFile(QString("%1/AC/online").arg(m_acpiPath)); + if (acFile.open(QIODevice::ReadOnly)) + values[QString("battery/ac")] = (QString(acFile.readLine()).trimmed().toInt() == 1); + acFile.close(); + + // batterites + float currentLevel = 0.0; + float fullLevel = 0.0; + for (int i=0; i(100 * batCurrent / batFull); + currentLevel += batCurrent; + fullLevel += batFull; + } + currentLevelFile.close(); + fullLevelFile.close(); + } + values[QString("battery/bat")] = static_cast(100 * currentLevel / fullLevel); +} + + +QStringList BatterySource::sources() const +{ + qCDebug(LOG_ESM); + + return m_sources; +} + + +QStringList BatterySource::getSources() +{ + qCDebug(LOG_ESM); + + QStringList sources; + sources.append(QString("battery/ac")); + sources.append(QString("battery/bat")); + m_batteriesCount = QDir(m_acpiPath).entryList(QStringList() << QString("BAT*"), + QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name).count(); + qCInfo(LOG_ESM) << "Init batteries count as" << m_batteriesCount; + for (int i=0; i + +#include "abstractextsysmonsource.h" + + +class BatterySource : public AbstractExtSysMonSource +{ +public: + explicit BatterySource(QObject *parent, const QStringList args); + virtual ~BatterySource(); + QVariant data(QString source); + QVariantMap initialData(QString source) const; + void run(); + QStringList sources() const; + +private: + QStringList getSources(); + // configuration and values + int m_batteriesCount = 0; + QString m_acpiPath; + QStringList m_sources; + QVariantHash values; +}; + + +#endif /* BATTERYSOURCE_H */ diff --git a/sources/extsysmon/sources/customsource.cpp b/sources/extsysmon/sources/customsource.cpp new file mode 100644 index 0000000..f5a357a --- /dev/null +++ b/sources/extsysmon/sources/customsource.cpp @@ -0,0 +1,87 @@ +/*************************************************************************** + * 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 "customsource.h" + +#include "awdebug.h" +#include "extscript.h" + + +CustomSource::CustomSource(QObject *parent, const QStringList args) + : AbstractExtSysMonSource(parent, args) +{ + Q_ASSERT(args.count() == 0); + qCDebug(LOG_ESM); + + extScripts = new ExtItemAggregator(nullptr, QString("scripts")); + m_sources = getSources(); +} + + +CustomSource::~CustomSource() +{ + qCDebug(LOG_ESM); + + delete extScripts; +} + + +QVariant CustomSource::data(QString source) +{ + qCDebug(LOG_ESM); + qCDebug(LOG_ESM) << "Source" << source; + + // there are only one value + return extScripts->itemByTagNumber(index(source))->run().values().first(); +} + + +QVariantMap CustomSource::initialData(QString source) const +{ + qCDebug(LOG_ESM); + qCDebug(LOG_ESM) << "Source" << source; + + QVariantMap data; + data[QString("min")] = QString(""); + data[QString("max")] = QString(""); + data[QString("name")] = QString("Custom command '%1' output").arg(extScripts->itemByTagNumber(index(source))->uniq()); + data[QString("type")] = QString("QString"); + data[QString("units")] = QString(""); + + return data; +} + + +QStringList CustomSource::sources() const +{ + qCDebug(LOG_ESM); + + return m_sources; +} + + +QStringList CustomSource::getSources() +{ + qCDebug(LOG_ESM); + + QStringList sources; + foreach(ExtScript *item, extScripts->activeItems()) + sources.append(QString("custom/%1").arg(item->tag(QString("custom")))); + + return sources; +} diff --git a/sources/extsysmon/sources/customsource.h b/sources/extsysmon/sources/customsource.h new file mode 100644 index 0000000..474c912 --- /dev/null +++ b/sources/extsysmon/sources/customsource.h @@ -0,0 +1,47 @@ +/*************************************************************************** + * 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 CUSTOMSOURCE_H +#define CUSTOMSOURCE_H + +#include + +#include "abstractextsysmonsource.h" +#include "extitemaggregator.h" + + +class ExtScript; + +class CustomSource : public AbstractExtSysMonSource +{ +public: + explicit CustomSource(QObject *parent, const QStringList args); + virtual ~CustomSource(); + QVariant data(QString source); + QVariantMap initialData(QString source) const; + void run() {}; + QStringList sources() const; + +private: + QStringList getSources(); + // configuration and values + ExtItemAggregator *extScripts; + QStringList m_sources; +}; + + +#endif /* CUSTOMSOURCE_H */ diff --git a/sources/extsysmon/sources/desktopsource.cpp b/sources/extsysmon/sources/desktopsource.cpp new file mode 100644 index 0000000..7f6de3a --- /dev/null +++ b/sources/extsysmon/sources/desktopsource.cpp @@ -0,0 +1,112 @@ +/*************************************************************************** + * 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 "desktopsource.h" + +#include + +#include "awdebug.h" + + +DesktopSource::DesktopSource(QObject *parent, const QStringList args) + : AbstractExtSysMonSource(parent, args) +{ + Q_ASSERT(args.count() == 0); + qCDebug(LOG_ESM); +} + + +DesktopSource::~DesktopSource() +{ + qCDebug(LOG_ESM); +} + + +QVariant DesktopSource::data(QString source) +{ + qCDebug(LOG_ESM); + qCDebug(LOG_ESM) << "Source" << source; + + int current = KWindowSystem::currentDesktop(); + int total = KWindowSystem::numberOfDesktops(); + + if (source == QString("desktop/current/name")) { + return KWindowSystem::desktopName(current); + } else if (source == QString("desktop/current/number")) { + return current; + } else if (source == QString("desktop/total/name")) { + QStringList desktops; + for (int i=1; i + +#include "abstractextsysmonsource.h" + + +class DesktopSource : public AbstractExtSysMonSource +{ +public: + explicit DesktopSource(QObject *parent, const QStringList args); + virtual ~DesktopSource(); + QVariant data(QString source); + QVariantMap initialData(QString source) const; + void run() {}; + QStringList sources() const; +}; + + +#endif /* DESKTOPSOURCE_H */ diff --git a/sources/extsysmon/sources/gpuloadsource.cpp b/sources/extsysmon/sources/gpuloadsource.cpp new file mode 100644 index 0000000..146ab7e --- /dev/null +++ b/sources/extsysmon/sources/gpuloadsource.cpp @@ -0,0 +1,111 @@ +/*************************************************************************** + * 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 "gpuloadsource.h" + +#include + +#include + +#include "awdebug.h" + + +GPULoadSource::GPULoadSource(QObject *parent, const QStringList args) + : AbstractExtSysMonSource(parent, args) +{ + Q_ASSERT(args.count() == 1); + qCDebug(LOG_ESM); + + m_device = args.at(0); +} + + +GPULoadSource::~GPULoadSource() +{ + qCDebug(LOG_ESM); +} + + +QVariant GPULoadSource::data(QString source) +{ + qCDebug(LOG_ESM); + qCDebug(LOG_ESM) << "Source" << source; + + if (source == QString("gpu/load")) { + float value = 0.0; + if ((m_device != QString("nvidia")) && (m_device != QString("ati"))) + return value; + // build cmd + QString cmd = m_device == QString("nvidia") ? QString("nvidia-smi -q -x") : QString("aticonfig --od-getclocks"); + qCInfo(LOG_ESM) << "cmd" << cmd; + TaskResult process = runTask(cmd); + qCInfo(LOG_ESM) << "Cmd returns" << process.exitCode; + qCInfo(LOG_ESM) << "Error" << process.error; + // parse + QString qoutput = QTextCodec::codecForMib(106)->toUnicode(process.output).trimmed(); + if (m_device == QString("nvidia")) + foreach(QString str, qoutput.split(QChar('\n'), QString::SkipEmptyParts)) { + if (!str.contains(QString(""))) continue; + QString load = str.remove(QString("")).remove(QString("")) + .remove(QChar('%')); + value = load.toFloat(); + break; + } + else if (m_device == QString("ati")) + foreach(QString str, qoutput.split(QChar('\n'), QString::SkipEmptyParts)) { + if (!str.contains(QString("load"))) continue; + QString load = str.split(QChar(' '), QString::SkipEmptyParts)[3] + .remove(QChar('%')); + value = load.toFloat(); + break; + } + // return + return value; + } + + return QVariant(); +} + + +QVariantMap GPULoadSource::initialData(QString source) const +{ + qCDebug(LOG_ESM); + qCDebug(LOG_ESM) << "Source" << source; + + QVariantMap data; + if (source == QString("gpu/load")) { + data[QString("min")] = 0.0; + data[QString("max")] = 100.0; + data[QString("name")] = QString("GPU usage"); + data[QString("type")] = QString("float"); + data[QString("units")] = QString("%"); + } + + return data; +} + + +QStringList GPULoadSource::sources() const +{ + qCDebug(LOG_ESM); + + QStringList sources; + sources.append(QString("gpu/load")); + + return sources; +} diff --git a/sources/extsysmon/sources/gpuloadsource.h b/sources/extsysmon/sources/gpuloadsource.h new file mode 100644 index 0000000..51a983a --- /dev/null +++ b/sources/extsysmon/sources/gpuloadsource.h @@ -0,0 +1,42 @@ +/*************************************************************************** + * 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 GPULOADSOURCE_H +#define GPULOADSOURCE_H + +#include + +#include "abstractextsysmonsource.h" + + +class GPULoadSource : public AbstractExtSysMonSource +{ +public: + explicit GPULoadSource(QObject *parent, const QStringList args); + virtual ~GPULoadSource(); + QVariant data(QString source); + QVariantMap initialData(QString source) const; + void run() {}; + QStringList sources() const; + +private: + // configuration and values + QString m_device; +}; + + +#endif /* GPULOADSOURCE_H */ diff --git a/sources/extsysmon/sources/gputempsource.cpp b/sources/extsysmon/sources/gputempsource.cpp new file mode 100644 index 0000000..dd3436f --- /dev/null +++ b/sources/extsysmon/sources/gputempsource.cpp @@ -0,0 +1,109 @@ +/*************************************************************************** + * 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 "gputempsource.h" + +#include + +#include + +#include "awdebug.h" + + +GPUTemperatureSource::GPUTemperatureSource(QObject *parent, const QStringList args) + : AbstractExtSysMonSource(parent, args) +{ + Q_ASSERT(args.count() == 1); + qCDebug(LOG_ESM); + + m_device = args.at(0); +} + + +GPUTemperatureSource::~GPUTemperatureSource() +{ + qCDebug(LOG_ESM); +} + + +QVariant GPUTemperatureSource::data(QString source) +{ + qCDebug(LOG_ESM); + qCDebug(LOG_ESM) << "Source" << source; + + if (source == QString("gpu/temperature")) { + float value = 0.0; + if ((m_device != QString("nvidia")) && (m_device != QString("ati"))) + return value; + // build cmd + QString cmd = m_device == QString("nvidia") ? QString("nvidia-smi -q -x") : QString("aticonfig --od-gettemperature"); + qCInfo(LOG_ESM) << "cmd" << cmd; + TaskResult process = runTask(cmd); + qCInfo(LOG_ESM) << "Cmd returns" << process.exitCode; + qCInfo(LOG_ESM) << "Error" << process.error; + // parse + QString qoutput = QTextCodec::codecForMib(106)->toUnicode(process.output).trimmed(); + if (m_device == QString("nvidia")) + foreach(QString str, qoutput.split(QChar('\n'), QString::SkipEmptyParts)) { + if (!str.contains(QString(""))) continue; + QString temp = str.remove(QString("")).remove(QString("C")); + value = temp.toFloat(); + break; + } + else if (m_device == QString("ati")) + foreach(QString str, qoutput.split(QChar('\n'), QString::SkipEmptyParts)) { + if (!str.contains(QString("Temperature"))) continue; + QString temp = str.split(QChar(' '), QString::SkipEmptyParts).at(4); + value = temp.toFloat(); + break; + } + // return + return value; + } + + return QVariant(); +} + + +QVariantMap GPUTemperatureSource::initialData(QString source) const +{ + qCDebug(LOG_ESM); + qCDebug(LOG_ESM) << "Source" << source; + + QVariantMap data; + if (source == QString("gpu/temperature")) { + data[QString("min")] = 0.0; + data[QString("max")] = 0.0; + data[QString("name")] = QString("GPU temperature"); + data[QString("type")] = QString("float"); + data[QString("units")] = QString("°C"); + } + + return data; +} + + +QStringList GPUTemperatureSource::sources() const +{ + qCDebug(LOG_ESM); + + QStringList sources; + sources.append(QString("gpu/temperature")); + + return sources; +} diff --git a/sources/extsysmon/sources/gputempsource.h b/sources/extsysmon/sources/gputempsource.h new file mode 100644 index 0000000..4196fd4 --- /dev/null +++ b/sources/extsysmon/sources/gputempsource.h @@ -0,0 +1,42 @@ +/*************************************************************************** + * 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 GPUTEMPSOURCE_H +#define GPUTEMPSOURCE_H + +#include + +#include "abstractextsysmonsource.h" + + +class GPUTemperatureSource : public AbstractExtSysMonSource +{ +public: + explicit GPUTemperatureSource(QObject *parent, const QStringList args); + virtual ~GPUTemperatureSource(); + QVariant data(QString source); + QVariantMap initialData(QString source) const; + void run() {}; + QStringList sources() const; + +private: + // configuration and values + QString m_device; +}; + + +#endif /* GPUTEMPSOURCE_H */ diff --git a/sources/extsysmon/sources/hddtempsource.cpp b/sources/extsysmon/sources/hddtempsource.cpp new file mode 100644 index 0000000..e831f85 --- /dev/null +++ b/sources/extsysmon/sources/hddtempsource.cpp @@ -0,0 +1,107 @@ +/*************************************************************************** + * 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 "hddtempsource.h" + +#include + +#include + +#include "awdebug.h" + + +HDDTemperatureSource::HDDTemperatureSource(QObject *parent, const QStringList args) + : AbstractExtSysMonSource(parent, args) +{ + Q_ASSERT(args.count() == 2); + qCDebug(LOG_ESM); + + m_devices = args.at(0).split(QChar(',')); + m_cmd = args.at(1); + + m_smartctl = m_cmd.contains(QString("smartctl")); + qCInfo(LOG_ESM) << "Parse as smartctl" << m_smartctl; +} + + +HDDTemperatureSource::~HDDTemperatureSource() +{ + qCDebug(LOG_ESM); +} + + +QVariant HDDTemperatureSource::data(QString source) +{ + qCDebug(LOG_ESM); + qCDebug(LOG_ESM) << "Source" << source; + + QString device = source.remove(QString("hdd/temperature")); + float value = 0.0; + // run cmd + TaskResult process = runTask(QString("%1 %2").arg(m_cmd).arg(device)); + qCInfo(LOG_ESM) << "Cmd returns" << process.exitCode; + qCInfo(LOG_ESM) << "Error" << process.error; + + // parse + QString qoutput = QTextCodec::codecForMib(106)->toUnicode(process.output).trimmed(); + if (m_smartctl) { + foreach(QString str, qoutput.split(QChar('\n'), QString::SkipEmptyParts)) { + if (!str.startsWith(QString("194"))) continue; + if (str.split(QChar(' '), QString::SkipEmptyParts).count() < 9) break; + value = str.split(QChar(' '), QString::SkipEmptyParts).at(9).toFloat(); + break; + } + } else { + if (qoutput.split(QChar(':'), QString::SkipEmptyParts).count() >= 3) { + QString temp = qoutput.split(QChar(':'), QString::SkipEmptyParts).at(2); + temp.remove(QChar(0260)).remove(QChar('C')); + value = temp.toFloat(); + } + } + + return value; +} + + +QVariantMap HDDTemperatureSource::initialData(QString source) const +{ + qCDebug(LOG_ESM); + qCDebug(LOG_ESM) << "Source" << source; + + QString device = source.remove(QString("hdd/temperature")); + QVariantMap data; + data[QString("min")] = 0.0; + data[QString("max")] = 0.0; + data[QString("name")] = QString("HDD '%1' temperature").arg(device); + data[QString("type")] = QString("float"); + data[QString("units")] = QString("°C"); + + return data; +} + + +QStringList HDDTemperatureSource::sources() const +{ + qCDebug(LOG_ESM); + + QStringList sources; + foreach(QString device, m_devices) + sources.append(QString("hdd/temperature%1").arg(device)); + + return sources; +} diff --git a/sources/extsysmon/sources/hddtempsource.h b/sources/extsysmon/sources/hddtempsource.h new file mode 100644 index 0000000..dcd9dd4 --- /dev/null +++ b/sources/extsysmon/sources/hddtempsource.h @@ -0,0 +1,44 @@ +/*************************************************************************** + * 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 HDDTEMPSOURCE_H +#define HDDTEMPSOURCE_H + +#include + +#include "abstractextsysmonsource.h" + + +class HDDTemperatureSource : public AbstractExtSysMonSource +{ +public: + explicit HDDTemperatureSource(QObject *parent, const QStringList args); + virtual ~HDDTemperatureSource(); + QVariant data(QString source); + QVariantMap initialData(QString source) const; + void run() {}; + QStringList sources() const; + +private: + // configuration and values + QString m_cmd; + QStringList m_devices; + bool m_smartctl; +}; + + +#endif /* HDDTEMPSOURCE_H */ diff --git a/sources/extsysmon/sources/networksource.cpp b/sources/extsysmon/sources/networksource.cpp new file mode 100644 index 0000000..e83b5fe --- /dev/null +++ b/sources/extsysmon/sources/networksource.cpp @@ -0,0 +1,89 @@ +/*************************************************************************** + * 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 "networksource.h" + +#include + +#include "awdebug.h" + + +NetworkSource::NetworkSource(QObject *parent, const QStringList args) + : AbstractExtSysMonSource(parent, args) +{ + Q_ASSERT(args.count() == 0); + qCDebug(LOG_ESM); +} + + +NetworkSource::~NetworkSource() +{ + qCDebug(LOG_ESM); +} + + +QVariant NetworkSource::data(QString source) +{ + qCDebug(LOG_ESM); + qCDebug(LOG_ESM) << "Source" << source; + + if (source == QString("network/current/name")) { + 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)) && + (!interface.flags().testFlag(QNetworkInterface::IsPointToPoint))) { + device = interface.name(); + break; + } + return device; + } + + return QVariant(); +} + + +QVariantMap NetworkSource::initialData(QString source) const +{ + qCDebug(LOG_ESM); + qCDebug(LOG_ESM) << "Source" << source; + + QVariantMap data; + if (source == QString("network/current/name")) { + data[QString("min")] = QString(""); + data[QString("max")] = QString(""); + data[QString("name")] = QString("Current network device name"); + data[QString("type")] = QString("QString"); + data[QString("units")] = QString(""); + } + + return data; +} + + +QStringList NetworkSource::sources() const +{ + qCDebug(LOG_ESM); + + QStringList sources; + sources.append(QString("network/current/name")); + + return sources; +} diff --git a/sources/extsysmon/sources/networksource.h b/sources/extsysmon/sources/networksource.h new file mode 100644 index 0000000..e83c606 --- /dev/null +++ b/sources/extsysmon/sources/networksource.h @@ -0,0 +1,38 @@ +/*************************************************************************** + * 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 NETWORKSOURCE_H +#define NETWORKSOURCE_H + +#include + +#include "abstractextsysmonsource.h" + + +class NetworkSource : public AbstractExtSysMonSource +{ +public: + explicit NetworkSource(QObject *parent, const QStringList args); + virtual ~NetworkSource(); + QVariant data(QString source); + QVariantMap initialData(QString source) const; + void run() {}; + QStringList sources() const; +}; + + +#endif /* NETWORKSOURCE_H */ diff --git a/sources/extsysmon/sources/playersource.cpp b/sources/extsysmon/sources/playersource.cpp new file mode 100644 index 0000000..db7ae5e --- /dev/null +++ b/sources/extsysmon/sources/playersource.cpp @@ -0,0 +1,334 @@ +/*************************************************************************** + * 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 "playersource.h" + +#include +#include +#include +#include +#include + +#include + +#include "awdebug.h" + + +PlayerSource::PlayerSource(QObject *parent, const QStringList args) + : AbstractExtSysMonSource(parent, args) +{ + Q_ASSERT(args.count() == 5); + qCDebug(LOG_ESM); + + m_player = args.at(0); + m_mpdAddress = QString("%1:%2").arg(args.at(1)).arg(args.at(2)); + m_mpris = args.at(3); + m_symbols = args.at(4).toInt(); +} + + +PlayerSource::~PlayerSource() +{ + qCDebug(LOG_ESM); +} + + +QVariant PlayerSource::data(QString source) +{ + qCDebug(LOG_ESM); + qCDebug(LOG_ESM) << "Source" << source; + + if (source == QString("player/title")) run(); + return values[source]; +} + + +QVariantMap PlayerSource::initialData(QString source) const +{ + qCDebug(LOG_ESM); + qCDebug(LOG_ESM) << "Source" << source; + + QVariantMap data; + if (source == QString("player/album")) { + data[QString("min")] = QString(""); + data[QString("max")] = QString(""); + data[QString("name")] = QString("Current song album"); + data[QString("type")] = QString("QString"); + data[QString("units")] = QString(""); + } else if (source == QString("player/salbum")) { + data[QString("min")] = QString(""); + data[QString("max")] = QString(""); + data[QString("name")] = QString("Current song album (%1 symbols)").arg(m_symbols); + data[QString("type")] = QString("QString"); + data[QString("units")] = QString(""); + } else if (source == QString("player/dalbum")) { + data[QString("min")] = QString(""); + data[QString("max")] = QString(""); + data[QString("name")] = QString("Current song album (%1 symbols, dynamic)").arg(m_symbols); + data[QString("type")] = QString("QString"); + data[QString("units")] = QString(""); + } else if (source == QString("player/artist")) { + data[QString("min")] = QString(""); + data[QString("max")] = QString(""); + data[QString("name")] = QString("Current song artist"); + data[QString("type")] = QString("QString"); + data[QString("units")] = QString(""); + } else if (source == QString("player/sartist")) { + data[QString("min")] = QString(""); + data[QString("max")] = QString(""); + data[QString("name")] = QString("Current song artist (%1 symbols)").arg(m_symbols); + data[QString("type")] = QString("QString"); + data[QString("units")] = QString(""); + } else if (source == QString("player/dartist")) { + data[QString("min")] = QString(""); + data[QString("max")] = QString(""); + data[QString("name")] = QString("Current song artist (%1 symbols, dynamic)").arg(m_symbols); + data[QString("type")] = QString("QString"); + data[QString("units")] = QString(""); + } else if (source == QString("player/duration")) { + data[QString("min")] = 0; + data[QString("max")] = 0; + data[QString("name")] = QString("Current song duration"); + data[QString("type")] = QString("integer"); + data[QString("units")] = QString("s"); + } else if (source == QString("player/progress")) { + data[QString("min")] = 0; + data[QString("max")] = 0; + data[QString("name")] = QString("Current song progress"); + data[QString("type")] = QString("integer"); + data[QString("units")] = QString("s"); + } else if (source == QString("player/title")) { + data[QString("min")] = QString(""); + data[QString("max")] = QString(""); + data[QString("name")] = QString("Current song title"); + data[QString("type")] = QString("QString"); + data[QString("units")] = QString(""); + } else if (source == QString("player/stitle")) { + data[QString("min")] = QString(""); + data[QString("max")] = QString(""); + data[QString("name")] = QString("Current song title (%1 symbols)").arg(m_symbols); + data[QString("type")] = QString("QString"); + data[QString("units")] = QString(""); + } else if (source == QString("player/dtitle")) { + data[QString("min")] = QString(""); + data[QString("max")] = QString(""); + data[QString("name")] = QString("Current song title (%1 symbols, dynamic)").arg(m_symbols); + data[QString("type")] = QString("QString"); + data[QString("units")] = QString(""); + } + + return data; +} + + +void PlayerSource::run() +{ + qCDebug(LOG_ESM); + + // initial data + if (m_player == QString("mpd")) { + // mpd + values = getPlayerMpdInfo(m_mpdAddress); + } else if (m_player == QString("mpris")) { + // players which supports mpris + QString mpris = m_mpris == QString("auto") ? getAutoMpris() : m_mpris; + if (mpris.isEmpty()) return; + values = getPlayerMprisInfo(mpris); + } + + // dymanic properties + // solid + values[QString("player/salbum")] = stripString(values[QString("player/album")].toString(), + m_symbols); + values[QString("player/sartist")] = stripString(values[QString("player/artist")].toString(), + m_symbols); + values[QString("player/stitle")] = stripString(values[QString("player/title")].toString(), + m_symbols); + // dynamic + values[QString("player/dalbum")] = buildString(values[QString("player/dalbum")].toString(), + values[QString("player/album")].toString(), + m_symbols); + values[QString("player/dartist")] = buildString(values[QString("player/dartist")].toString(), + values[QString("player/artist")].toString(), + m_symbols); + values[QString("player/dtitle")] = buildString(values[QString("player/dtitle")].toString(), + values[QString("player/title")].toString(), + m_symbols); +} + + +QStringList PlayerSource::sources() const +{ + qCDebug(LOG_ESM); + + QStringList sources; + sources.append(QString("player/album")); + sources.append(QString("player/dalbum")); + sources.append(QString("player/salbum")); + sources.append(QString("player/artist")); + sources.append(QString("player/dartist")); + sources.append(QString("player/sartist")); + sources.append(QString("player/duration")); + sources.append(QString("player/progress")); + sources.append(QString("player/title")); + sources.append(QString("player/dtitle")); + sources.append(QString("player/stitle")); + + return sources; +} + + +QString PlayerSource::getAutoMpris() const +{ + qCDebug(LOG_ESM); + + QDBusMessage listServices = QDBusConnection::sessionBus().interface()->call(QDBus::BlockWithGui, QString("ListNames")); + if (listServices.arguments().isEmpty()) return QString(); + QStringList arguments = listServices.arguments().first().toStringList(); + + foreach(QString arg, arguments) { + if (!arg.startsWith(QString("org.mpris.MediaPlayer2."))) continue; + qCInfo(LOG_ESM) << "Service found" << arg; + QString service = arg; + service.remove(QString("org.mpris.MediaPlayer2.")); + return service; + } + + return QString(); +} + + +QVariantHash PlayerSource::getPlayerMpdInfo(const QString mpdAddress) const +{ + qCDebug(LOG_ESM); + qCDebug(LOG_ESM) << "MPD" << mpdAddress; + + QVariantHash info; + info[QString("player/album")] = QString("unknown"); + info[QString("player/artist")] = QString("unknown"); + info[QString("player/duration")] = 0; + info[QString("player/progress")] = 0; + info[QString("player/title")] = QString("unknown"); + + // 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; + TaskResult process = runTask(cmd); + 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)) { + if (str.split(QString(": "), QString::SkipEmptyParts).count() == 1) { + // "Metadata: data" + QString metadata = str.split(QString(": "), QString::SkipEmptyParts).first().toLower(); + QString data = str.split(QString(": "), QString::SkipEmptyParts).last().trimmed(); + if (metadata == QString("time")) { + QStringList times = data.split(QString(":")); + info[QString("player/duration")] = times.at(0).toInt(); + info[QString("player/progress")] = times.at(1).toInt(); + } else if (metadata == QString("Title")) { + info[QString("player/%1").arg(metadata)] = data; + } + } + } + + return info; +} + + +QVariantHash PlayerSource::getPlayerMprisInfo(const QString mpris) const +{ + qCDebug(LOG_ESM); + qCDebug(LOG_ESM) << "MPRIS" << mpris; + + QVariantHash info; + info[QString("player/album")] = QString("unknown"); + info[QString("player/artist")] = QString("unknown"); + info[QString("player/duration")] = 0; + info[QString("player/progress")] = 0; + info[QString("player/title")] = QString("unknown"); + + QDBusConnection bus = QDBusConnection::sessionBus(); + // comes from the following request: + // qdbus org.mpris.MediaPlayer2.vlc /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get org.mpris.MediaPlayer2.Player Metadata + // or the same but using dbus-send: + // dbus-send --print-reply --session --dest=org.mpris.MediaPlayer2.vlc /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Metadata' + QVariantList args = QVariantList() << QString("org.mpris.MediaPlayer2.Player") << QString("Metadata"); + QDBusMessage request = QDBusMessage::createMethodCall(QString("org.mpris.MediaPlayer2.%1").arg(mpris), + QString("/org/mpris/MediaPlayer2"), + QString(""), + QString("Get")); + request.setArguments(args); + QDBusMessage response = bus.call(request, QDBus::BlockWithGui); + if ((response.type() != QDBusMessage::ReplyMessage) || (response.arguments().isEmpty())) { + qCWarning(LOG_ESM) << "Error message" << response.errorMessage(); + } else { + // another portion of dirty magic + QVariantHash map = qdbus_cast(response.arguments().first() + .value().variant() + .value()); + info[QString("player/album")] = map.value(QString("xesam:album"), QString("unknown")); + // artist is array + info[QString("player/artist")] = map.value(QString("xesam:artist"), QString("unknown")).toString(); + info[QString("player/duration")] = map.value(QString("mpris:length"), 0).toInt() / (1000 * 1000); + info[QString("player/title")] = map.value(QString("xesam:title"), QString("unknown")); + } + + // position + args[1] = QString("Position"); + request.setArguments(args); + response = bus.call(request, QDBus::BlockWithGui); + if ((response.type() != QDBusMessage::ReplyMessage) || (response.arguments().isEmpty())) { + qCWarning(LOG_ESM) << "Error message" << response.errorMessage(); + } else { + // this cast is simpler than the previous one ;) + info[QString("player/progress")] = response.arguments().first().value() + .variant().toLongLong() / (1000 * 1000); + } + + return info; +} + + +QString PlayerSource::buildString(const QString current, const QString value, + const int s) const +{ + qCDebug(LOG_ESM); + qCDebug(LOG_ESM) << "Current value" << current; + qCDebug(LOG_ESM) << "New value" << value; + qCDebug(LOG_ESM) << "Strip after" << s; + + int index = value.indexOf(current); + if ((current.isEmpty()) || ((index + s + 1) > value.count())) + return value.leftJustified(s, QLatin1Char(' ')); + else + return QString("%1").arg(value.mid(index + 1, s), s, QLatin1Char(' ')); +} + + +QString PlayerSource::stripString(const QString value, const int s) const +{ + qCDebug(LOG_ESM); + qCDebug(LOG_ESM) << "New value" << value; + qCDebug(LOG_ESM) << "Strip 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/extsysmon/sources/playersource.h new file mode 100644 index 0000000..9ff6d81 --- /dev/null +++ b/sources/extsysmon/sources/playersource.h @@ -0,0 +1,52 @@ +/*************************************************************************** + * 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 PLAYERSOURCE_H +#define PLAYERSOURCE_H + +#include + +#include "abstractextsysmonsource.h" + + +class PlayerSource : public AbstractExtSysMonSource +{ +public: + explicit PlayerSource(QObject *parent, const QStringList args); + virtual ~PlayerSource(); + QVariant data(QString source); + QVariantMap initialData(QString source) const; + void run(); + QStringList sources() const; + +private: + QString getAutoMpris() const; + QVariantHash getPlayerMpdInfo(const QString mpdAddress) const; + QVariantHash getPlayerMprisInfo(const QString mpris) const; + // additional method to build dynamic tags + QString buildString(const QString current, const QString value, const int s) const; + QString stripString(const QString value, const int s) const; + // configuration and values + QString m_mpdAddress; + QString m_mpris; + QString m_player; + int m_symbols; + QVariantHash values; +}; + + +#endif /* PLAYERSOURCE_H */ diff --git a/sources/extsysmon/sources/processessource.cpp b/sources/extsysmon/sources/processessource.cpp new file mode 100644 index 0000000..9d1c79c --- /dev/null +++ b/sources/extsysmon/sources/processessource.cpp @@ -0,0 +1,115 @@ +/*************************************************************************** + * 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 "processessource.h" + +#include + +#include "awdebug.h" + + +ProcessesSource::ProcessesSource(QObject *parent, const QStringList args) + : AbstractExtSysMonSource(parent, args) +{ + Q_ASSERT(args.count() == 0); + qCDebug(LOG_ESM); +} + + +ProcessesSource::~ProcessesSource() +{ + qCDebug(LOG_ESM); +} + + +QVariant ProcessesSource::data(QString source) +{ + qCDebug(LOG_ESM); + qCDebug(LOG_ESM) << "Source" << source; + + if (source == QString("ps/running/count")) run(); + return values[source]; +} + + +QVariantMap ProcessesSource::initialData(QString source) const +{ + qCDebug(LOG_ESM); + qCDebug(LOG_ESM) << "Source" << source; + + QVariantMap data; + if (source == QString("ps/running/count")) { + data[QString("min")] = 0; + data[QString("max")] = 0; + data[QString("name")] = QString("Count of running processes"); + data[QString("type")] = QString("integer"); + data[QString("units")] = QString(""); + } else if (source == QString("ps/running/list")) { + data[QString("min")] = QStringList(); + data[QString("max")] = QStringList(); + data[QString("name")] = QString("All running processes list"); + data[QString("type")] = QString("QStringList"); + data[QString("units")] = QString(""); + } else if (source == QString("ps/total/count")) { + data[QString("min")] = 0; + data[QString("max")] = 0; + data[QString("name")] = QString("Total count of processes"); + data[QString("type")] = QString("integer"); + data[QString("units")] = QString(""); + } + + return data; +} + + +void ProcessesSource::run() +{ + qCDebug(LOG_ESM); + + QStringList allDirectories = QDir(QString("/proc")).entryList(QDir::Dirs | QDir::NoDotAndDotDot, + QDir::Name); + QStringList directories = allDirectories.filter(QRegExp(QString("(\\d+)"))); + QStringList running; + + foreach(QString dir, directories) { + QFile statusFile(QString("/proc/%1/status").arg(dir)); + if (!statusFile.open(QIODevice::ReadOnly)) continue; + QFile cmdFile(QString("/proc/%1/cmdline").arg(dir)); + if (!cmdFile.open(QIODevice::ReadOnly)) continue; + + QString output = statusFile.readAll(); + if (output.contains(QString("running"))) running.append(cmdFile.readAll()); + } + + values[QString("ps/running/count")] = running.count(); + values[QString("ps/running/list")] = running; + values[QString("ps/total/count")] = directories.count(); +} + + +QStringList ProcessesSource::sources() const +{ + qCDebug(LOG_ESM); + + QStringList sources; + sources.append(QString("ps/running/count")); + sources.append(QString("ps/running/list")); + sources.append(QString("ps/total/count")); + + return sources; +} diff --git a/sources/extsysmon/sources/processessource.h b/sources/extsysmon/sources/processessource.h new file mode 100644 index 0000000..e9e12df --- /dev/null +++ b/sources/extsysmon/sources/processessource.h @@ -0,0 +1,42 @@ +/*************************************************************************** + * 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 PROCESSESSOURCE_H +#define PROCESSESSOURCE_H + +#include + +#include "abstractextsysmonsource.h" + + +class ProcessesSource : public AbstractExtSysMonSource +{ +public: + explicit ProcessesSource(QObject *parent, const QStringList args); + virtual ~ProcessesSource(); + QVariant data(QString source); + QVariantMap initialData(QString source) const; + void run(); + QStringList sources() const; + +private: + // configuration and values + QVariantHash values; +}; + + +#endif /* PROCESSESSOURCE_H */ diff --git a/sources/extsysmon/sources/quotessource.cpp b/sources/extsysmon/sources/quotessource.cpp new file mode 100644 index 0000000..96e437b --- /dev/null +++ b/sources/extsysmon/sources/quotessource.cpp @@ -0,0 +1,149 @@ +/*************************************************************************** + * 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 "quotessource.h" + +#include "awdebug.h" +#include "extquotes.h" + + +QuotesSource::QuotesSource(QObject *parent, const QStringList args) + : AbstractExtSysMonSource(parent, args) +{ + Q_ASSERT(args.count() == 0); + qCDebug(LOG_ESM); + + extQuotes = new ExtItemAggregator(nullptr, QString("quotes")); + m_sources = getSources(); +} + + +QuotesSource::~QuotesSource() +{ + qCDebug(LOG_ESM); + + delete extQuotes; +} + + +QVariant QuotesSource::data(QString source) +{ + qCDebug(LOG_ESM); + qCDebug(LOG_ESM) << "Source" << source; + + if (source.startsWith(QString("quotes/percpricechg"))) + values[source] = extQuotes->itemByTagNumber(index(source))->run(); + QString base = QString(source).remove(QString("quotes/")); + return values[source][base]; +} + + +QVariantMap QuotesSource::initialData(QString source) const +{ + qCDebug(LOG_ESM); + qCDebug(LOG_ESM) << "Source" << source; + + int ind = index(source); + QVariantMap data; + if (source.startsWith(QString("quotes/askchg"))) { + data[QString("min")] = 0.0; + data[QString("max")] = 0.0; + data[QString("name")] = QString("Absolute ask changes for '%1'").arg(extQuotes->itemByTagNumber(ind)->uniq()); + data[QString("type")] = QString("float"); + data[QString("units")] = QString(""); + } else if (source.startsWith(QString("quotes/ask"))) { + data[QString("min")] = 0.0; + data[QString("max")] = 0.0; + data[QString("name")] = QString("Ask for '%1'").arg(extQuotes->itemByTagNumber(ind)->uniq()); + data[QString("type")] = QString("float"); + data[QString("units")] = QString(""); + } else if (source.startsWith(QString("quotes/percaskchg"))) { + data[QString("min")] = -100.0; + data[QString("max")] = 100.0; + data[QString("name")] = QString("Ask changes for '%1'").arg(extQuotes->itemByTagNumber(ind)->uniq()); + data[QString("type")] = QString("float"); + data[QString("units")] = QString(""); + } else if (source.startsWith(QString("quotes/bidchg"))) { + data[QString("min")] = 0.0; + data[QString("max")] = 0.0; + data[QString("name")] = QString("Absolute bid changes for '%1'").arg(extQuotes->itemByTagNumber(ind)->uniq()); + data[QString("type")] = QString("float"); + data[QString("units")] = QString(""); + } else if (source.startsWith(QString("quotes/bid"))) { + data[QString("min")] = 0.0; + data[QString("max")] = 0.0; + data[QString("name")] = QString("Bid for '%1'").arg(extQuotes->itemByTagNumber(ind)->uniq()); + data[QString("type")] = QString("float"); + data[QString("units")] = QString(""); + } else if (source.startsWith(QString("quotes/percbidchg"))) { + data[QString("min")] = -100.0; + data[QString("max")] = 100.0; + data[QString("name")] = QString("Bid changes for '%1'").arg(extQuotes->itemByTagNumber(ind)->uniq()); + data[QString("type")] = QString("float"); + data[QString("units")] = QString(""); + } else if (source.startsWith(QString("quotes/pricechg"))) { + data[QString("min")] = 0.0; + data[QString("max")] = 0.0; + data[QString("name")] = QString("Absolute prie changes for '%1'").arg(extQuotes->itemByTagNumber(ind)->uniq()); + data[QString("type")] = QString("float"); + data[QString("units")] = QString(""); + } else if (source.startsWith(QString("quotes/price"))) { + data[QString("min")] = 0.0; + data[QString("max")] = 0.0; + data[QString("name")] = QString("Price for '%1'").arg(extQuotes->itemByTagNumber(ind)->uniq()); + data[QString("type")] = QString("float"); + data[QString("units")] = QString(""); + } else if (source.startsWith(QString("quotes/percpricechg"))) { + data[QString("min")] = -100.0; + data[QString("max")] = 100.0; + data[QString("name")] = QString("Price changes for '%1'").arg(extQuotes->itemByTagNumber(ind)->uniq()); + data[QString("type")] = QString("float"); + data[QString("units")] = QString(""); + } + + return data; +} + + +QStringList QuotesSource::sources() const +{ + qCDebug(LOG_ESM); + + return m_sources; +} + + +QStringList QuotesSource::getSources() +{ + qCDebug(LOG_ESM); + + QStringList sources; + foreach(ExtQuotes *item, extQuotes->activeItems()) { + sources.append(QString("quotes/%1").arg(item->tag(QString("ask")))); + sources.append(QString("quotes/%1").arg(item->tag(QString("askchg")))); + sources.append(QString("quotes/%1").arg(item->tag(QString("percaskchg")))); + sources.append(QString("quotes/%1").arg(item->tag(QString("bid")))); + sources.append(QString("quotes/%1").arg(item->tag(QString("bidchg")))); + sources.append(QString("quotes/%1").arg(item->tag(QString("percbidchg")))); + sources.append(QString("quotes/%1").arg(item->tag(QString("price")))); + sources.append(QString("quotes/%1").arg(item->tag(QString("pricechg")))); + sources.append(QString("quotes/%1").arg(item->tag(QString("percpricechg")))); + } + + return sources; +} diff --git a/sources/extsysmon/sources/quotessource.h b/sources/extsysmon/sources/quotessource.h new file mode 100644 index 0000000..e2161ae --- /dev/null +++ b/sources/extsysmon/sources/quotessource.h @@ -0,0 +1,48 @@ +/*************************************************************************** + * 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 QUOTESSOURCE_H +#define QUOTESSOURCE_H + +#include + +#include "abstractextsysmonsource.h" +#include "extitemaggregator.h" + + +class ExtQuotes; + +class QuotesSource : public AbstractExtSysMonSource +{ +public: + explicit QuotesSource(QObject *parent, const QStringList args); + virtual ~QuotesSource(); + QVariant data(QString source); + QVariantMap initialData(QString source) const; + void run() {}; + QStringList sources() const; + +private: + QStringList getSources(); + // configuration and values + ExtItemAggregator *extQuotes; + QStringList m_sources; + QHash values; +}; + + +#endif /* QUOTESSOURCE_H */ diff --git a/sources/extsysmon/sources/updatesource.cpp b/sources/extsysmon/sources/updatesource.cpp new file mode 100644 index 0000000..b438c0f --- /dev/null +++ b/sources/extsysmon/sources/updatesource.cpp @@ -0,0 +1,73 @@ +/*************************************************************************** + * 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 "updatesource.h" + +#include "awdebug.h" + + +UpdateSource::UpdateSource(QObject *parent, const QStringList args) + : AbstractExtSysMonSource(parent, args) +{ + Q_ASSERT(args.count() == 0); + qCDebug(LOG_ESM); +} + + +UpdateSource::~UpdateSource() +{ + qCDebug(LOG_ESM); +} + + +QVariant UpdateSource::data(QString source) +{ + qCDebug(LOG_ESM); + qCDebug(LOG_ESM) << "Source" << source; + + return true; +} + + +QVariantMap UpdateSource::initialData(QString source) const +{ + qCDebug(LOG_ESM); + qCDebug(LOG_ESM) << "Source" << source; + + QVariantMap data; + if (source == QString("desktop/current/name")) { + data[QString("min")] = true; + data[QString("max")] = true; + data[QString("name")] = QString("Simple value which is always true"); + data[QString("type")] = QString("bool"); + data[QString("units")] = QString(""); + } + + return data; +} + + +QStringList UpdateSource::sources() const +{ + qCDebug(LOG_ESM); + + QStringList sources; + sources.append(QString("update")); + + return sources; +} diff --git a/sources/extsysmon/sources/updatesource.h b/sources/extsysmon/sources/updatesource.h new file mode 100644 index 0000000..20f962c --- /dev/null +++ b/sources/extsysmon/sources/updatesource.h @@ -0,0 +1,38 @@ +/*************************************************************************** + * 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 UPDATESOURCE_H +#define UPDATESOURCE_H + +#include + +#include "abstractextsysmonsource.h" + + +class UpdateSource : public AbstractExtSysMonSource +{ +public: + explicit UpdateSource(QObject *parent, const QStringList args); + virtual ~UpdateSource(); + QVariant data(QString source); + QVariantMap initialData(QString source) const; + void run() {}; + QStringList sources() const; +}; + + +#endif /* UPDATESOURCE_H */ diff --git a/sources/extsysmon/sources/upgradesource.cpp b/sources/extsysmon/sources/upgradesource.cpp new file mode 100644 index 0000000..dfefc5d --- /dev/null +++ b/sources/extsysmon/sources/upgradesource.cpp @@ -0,0 +1,87 @@ +/*************************************************************************** + * 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 "upgradesource.h" + +#include "awdebug.h" +#include "extupgrade.h" + + +UpgradeSource::UpgradeSource(QObject *parent, const QStringList args) + : AbstractExtSysMonSource(parent, args) +{ + Q_ASSERT(args.count() == 0); + qCDebug(LOG_ESM); + + extUpgrade = new ExtItemAggregator(nullptr, QString("upgrade")); + m_sources = getSources(); +} + + +UpgradeSource::~UpgradeSource() +{ + qCDebug(LOG_ESM); + + delete extUpgrade; +} + + +QVariant UpgradeSource::data(QString source) +{ + qCDebug(LOG_ESM); + qCDebug(LOG_ESM) << "Source" << source; + + // there are only one value + return extUpgrade->itemByTagNumber(index(source))->run().values().first(); +} + + +QVariantMap UpgradeSource::initialData(QString source) const +{ + qCDebug(LOG_ESM); + qCDebug(LOG_ESM) << "Source" << source; + + QVariantMap data; + data[QString("min")] = QString(""); + data[QString("max")] = QString(""); + data[QString("name")] = QString("Package manager '%1' metadata").arg(extUpgrade->itemByTagNumber(index(source))->uniq()); + data[QString("type")] = QString("QString"); + data[QString("units")] = QString(""); + + return data; +} + + +QStringList UpgradeSource::sources() const +{ + qCDebug(LOG_ESM); + + return m_sources; +} + + +QStringList UpgradeSource::getSources() +{ + qCDebug(LOG_ESM); + + QStringList sources; + foreach(ExtUpgrade *item, extUpgrade->activeItems()) + sources.append(QString("upgrade/%1").arg(item->tag(QString("pkgcount")))); + + return sources; +} diff --git a/sources/extsysmon/sources/upgradesource.h b/sources/extsysmon/sources/upgradesource.h new file mode 100644 index 0000000..60200ac --- /dev/null +++ b/sources/extsysmon/sources/upgradesource.h @@ -0,0 +1,47 @@ +/*************************************************************************** + * 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 UPGRADESOURCE_H +#define UPGRADESOURCE_H + +#include + +#include "abstractextsysmonsource.h" +#include "extitemaggregator.h" + + +class ExtUpgrade; + +class UpgradeSource : public AbstractExtSysMonSource +{ +public: + explicit UpgradeSource(QObject *parent, const QStringList args); + virtual ~UpgradeSource(); + QVariant data(QString source); + QVariantMap initialData(QString source) const; + void run() {}; + QStringList sources() const; + +private: + QStringList getSources(); + // configuration and values + ExtItemAggregator *extUpgrade; + QStringList m_sources; +}; + + +#endif /* UPGRADESOURCE_H */ diff --git a/sources/extsysmon/sources/weathersource.cpp b/sources/extsysmon/sources/weathersource.cpp new file mode 100644 index 0000000..a259c13 --- /dev/null +++ b/sources/extsysmon/sources/weathersource.cpp @@ -0,0 +1,121 @@ +/*************************************************************************** + * 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 "weathersource.h" + +#include "awdebug.h" +#include "extweather.h" + + +WeatherSource::WeatherSource(QObject *parent, const QStringList args) + : AbstractExtSysMonSource(parent, args) +{ + Q_ASSERT(args.count() == 0); + qCDebug(LOG_ESM); + + extWeather = new ExtItemAggregator(nullptr, QString("weather")); + m_sources = getSources(); +} + + +WeatherSource::~WeatherSource() +{ + qCDebug(LOG_ESM); + + delete extWeather; +} + + +QVariant WeatherSource::data(QString source) +{ + qCDebug(LOG_ESM); + qCDebug(LOG_ESM) << "Source" << source; + + if (source.startsWith(QString("weather/weatherId"))) + values[source] = extWeather->itemByTagNumber(index(source))->run(); + QString base = QString(source).remove(QString("weather/")); + return values[source][base]; +} + + +QVariantMap WeatherSource::initialData(QString source) const +{ + qCDebug(LOG_ESM); + qCDebug(LOG_ESM) << "Source" << source; + + int ind = index(source); + QVariantMap data; + if (source.startsWith(QString("weather/weatherId"))) { + data[QString("min")] = 0; + data[QString("max")] = 1000; + data[QString("name")] = QString("Numeric weather ID for '%1'").arg(extWeather->itemByTagNumber(ind)->uniq()); + data[QString("type")] = QString("integer"); + data[QString("units")] = QString(""); + } else if (source.startsWith(QString("weather/weather"))) { + data[QString("min")] = QString(""); + data[QString("max")] = QString(""); + data[QString("name")] = QString("ID string map for '%1'").arg(extWeather->itemByTagNumber(ind)->uniq()); + data[QString("type")] = QString("QString"); + data[QString("units")] = QString(""); + } else if (source.startsWith(QString("weather/humidity"))) { + data[QString("min")] = 0; + data[QString("max")] = 100; + data[QString("name")] = QString("Humidity for '%1'").arg(extWeather->itemByTagNumber(ind)->uniq()); + data[QString("type")] = QString("integer"); + data[QString("units")] = QString("%"); + } else if (source.startsWith(QString("weather/humidity"))) { + data[QString("min")] = 0; + data[QString("max")] = 0; + data[QString("name")] = QString("Atmospheric pressure for '%1'").arg(extWeather->itemByTagNumber(ind)->uniq()); + data[QString("type")] = QString("integer"); + data[QString("units")] = QString("hPa"); + } else if (source.startsWith(QString("weather/temperature"))) { + data[QString("min")] = 0.0; + data[QString("max")] = 0.0; + data[QString("name")] = QString("Temperature for '%1'").arg(extWeather->itemByTagNumber(ind)->uniq()); + data[QString("type")] = QString("float"); + data[QString("units")] = QString("°C"); + } + + return data; +} + + +QStringList WeatherSource::sources() const +{ + qCDebug(LOG_ESM); + + return m_sources; +} + + +QStringList WeatherSource::getSources() +{ + qCDebug(LOG_ESM); + + QStringList sources; + foreach(ExtWeather *item, extWeather->activeItems()) { + sources.append(QString("weather/%1").arg(item->tag(QString("weatherId")))); + sources.append(QString("weather/%1").arg(item->tag(QString("weather")))); + sources.append(QString("weather/%1").arg(item->tag(QString("humidity")))); + sources.append(QString("weather/%1").arg(item->tag(QString("pressure")))); + sources.append(QString("weather/%1").arg(item->tag(QString("temperature")))); + } + + return sources; +} diff --git a/sources/extsysmon/sources/weathersource.h b/sources/extsysmon/sources/weathersource.h new file mode 100644 index 0000000..2f6e4aa --- /dev/null +++ b/sources/extsysmon/sources/weathersource.h @@ -0,0 +1,48 @@ +/*************************************************************************** + * 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 WEATHERSOURCE_H +#define WEATHERSOURCE_H + +#include + +#include "abstractextsysmonsource.h" +#include "extitemaggregator.h" + + +class ExtWeather; + +class WeatherSource : public AbstractExtSysMonSource +{ +public: + explicit WeatherSource(QObject *parent, const QStringList args); + virtual ~WeatherSource(); + QVariant data(QString source); + QVariantMap initialData(QString source) const; + void run() {}; + QStringList sources() const; + +private: + QStringList getSources(); + // configuration and values + ExtItemAggregator *extWeather; + QStringList m_sources; + QHash values; +}; + + +#endif /* WEATHERSOURCE_H */