Add test for hddsource, move sources to own library

This commit is contained in:
2016-06-07 14:16:48 +03:00
parent 18789f78b3
commit 5a0541d06d
41 changed files with 344 additions and 143 deletions

View File

@ -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)

View File

@ -17,7 +17,6 @@
#include "extsysmon.h"
#include <QDir>
#include <QFile>
#include <QRegExp>
#include <QSettings>
@ -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<QString, QString> 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")) {

View File

@ -41,8 +41,6 @@ private:
ExtSysMonAggregator *aggregator = nullptr;
QHash<QString, QString> configuration;
// methods
QStringList getAllHdd() const;
QString getAutoGpu() const;
void readConfiguration();
QHash<QString, QString>
updateConfiguration(QHash<QString, QString> rawConfig) const;

View File

@ -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,

View File

@ -20,7 +20,7 @@
#include <QObject>
#include "sources/abstractextsysmonsource.h"
#include "abstractextsysmonsource.h"
class ExtSysMonAggregator : public QObject

View File

@ -1,46 +0,0 @@
/***************************************************************************
* 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 <QObject>
#include <QRegExp>
#include <QVariant>
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 */

View File

@ -1,141 +0,0 @@
/***************************************************************************
* 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 <QDir>
#include "awdebug.h"
BatterySource::BatterySource(QObject *parent, const QStringList args)
: AbstractExtSysMonSource(parent, args)
{
Q_ASSERT(args.count() == 1);
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
m_acpiPath = args.at(0);
m_sources = getSources();
}
BatterySource::~BatterySource()
{
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
}
QVariant BatterySource::data(QString source)
{
qCDebug(LOG_ESM) << "Source" << source;
if (!m_values.contains(source))
run();
QVariant value = m_values.take(source);
return value;
}
QVariantMap BatterySource::initialData(QString source) const
{
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(index(source));
data[QString("type")] = QString("integer");
data[QString("units")] = QString("%");
}
return data;
}
void BatterySource::run()
{
// adaptor
QFile acFile(QString("%1/AC/online").arg(m_acpiPath));
if (acFile.open(QIODevice::ReadOnly))
m_values[QString("battery/ac")]
= (QString(acFile.readLine()).trimmed().toInt() == 1);
acFile.close();
// batteries
float currentLevel = 0.0;
float fullLevel = 0.0;
for (int i = 0; i < m_batteriesCount; i++) {
QFile currentLevelFile(
QString("%1/BAT%2/energy_now").arg(m_acpiPath).arg(i));
QFile fullLevelFile(
QString("%1/BAT%2/energy_full").arg(m_acpiPath).arg(i));
if ((currentLevelFile.open(QIODevice::ReadOnly))
&& (fullLevelFile.open(QIODevice::ReadOnly))) {
float batCurrent
= QString(currentLevelFile.readLine()).trimmed().toFloat();
float batFull
= QString(fullLevelFile.readLine()).trimmed().toFloat();
m_values[QString("battery/bat%1").arg(i)]
= static_cast<int>(100 * batCurrent / batFull);
currentLevel += batCurrent;
fullLevel += batFull;
}
currentLevelFile.close();
fullLevelFile.close();
}
m_values[QString("battery/bat")]
= static_cast<int>(100 * currentLevel / fullLevel);
}
QStringList BatterySource::sources() const
{
return m_sources;
}
QStringList BatterySource::getSources()
{
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 < m_batteriesCount; i++)
sources.append(QString("battery/bat%1").arg(i));
qCInfo(LOG_ESM) << "Sources list" << sources;
return sources;
}

View File

@ -1,46 +0,0 @@
/***************************************************************************
* 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 BATTERYSOURCE_H
#define BATTERYSOURCE_H
#include <QObject>
#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 m_values;
};
#endif /* BATTERYSOURCE_H */

View File

@ -1,83 +0,0 @@
/***************************************************************************
* 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) << __PRETTY_FUNCTION__;
extScripts = new ExtItemAggregator<ExtScript>(nullptr, QString("scripts"));
m_sources = getSources();
}
CustomSource::~CustomSource()
{
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
delete extScripts;
}
QVariant CustomSource::data(QString source)
{
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) << "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
{
return m_sources;
}
QStringList CustomSource::getSources()
{
QStringList sources;
for (auto item : extScripts->activeItems())
sources.append(QString("custom/%1").arg(item->tag(QString("custom"))));
return sources;
}

View File

@ -1,47 +0,0 @@
/***************************************************************************
* 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 <QObject>
#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<ExtScript> *extScripts = nullptr;
QStringList m_sources;
};
#endif /* CUSTOMSOURCE_H */

View File

@ -1,108 +0,0 @@
/***************************************************************************
* 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 <KWindowSystem>
#include "awdebug.h"
DesktopSource::DesktopSource(QObject *parent, const QStringList args)
: AbstractExtSysMonSource(parent, args)
{
Q_ASSERT(args.count() == 0);
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
}
DesktopSource::~DesktopSource()
{
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
}
QVariant DesktopSource::data(QString source)
{
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 < total + 1; i++)
desktops.append(KWindowSystem::desktopName(i));
return desktops;
} else if (source == QString("desktop/total/number")) {
return total;
}
return QVariant();
}
QVariantMap DesktopSource::initialData(QString source) const
{
qCDebug(LOG_ESM) << "Source" << source;
QVariantMap data;
if (source == QString("desktop/current/name")) {
data[QString("min")] = QString("");
data[QString("max")] = QString("");
data[QString("name")] = QString("Current desktop name");
data[QString("type")] = QString("QString");
data[QString("units")] = QString("");
} else if (source == QString("desktop/current/number")) {
data[QString("min")] = 0;
data[QString("max")] = 0;
data[QString("name")] = QString("Current desktop number");
data[QString("type")] = QString("integer");
data[QString("units")] = QString("");
} else if (source == QString("desktop/total/name")) {
data[QString("min")] = QStringList();
data[QString("max")] = QStringList();
data[QString("name")] = QString("All desktops by name");
data[QString("type")] = QString("QStringList");
data[QString("units")] = QString("");
} else if (source == QString("desktop/total/number")) {
data[QString("min")] = 0;
data[QString("max")] = 0;
data[QString("name")] = QString("Desktops count");
data[QString("type")] = QString("integer");
data[QString("units")] = QString("");
}
return data;
}
QStringList DesktopSource::sources() const
{
QStringList sources;
sources.append(QString("desktop/current/name"));
sources.append(QString("desktop/current/number"));
sources.append(QString("desktop/total/name"));
sources.append(QString("desktop/total/number"));
return sources;
}

View File

@ -1,38 +0,0 @@
/***************************************************************************
* 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 DESKTOPSOURCE_H
#define DESKTOPSOURCE_H
#include <QObject>
#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 */

View File

@ -1,138 +0,0 @@
/***************************************************************************
* 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 <QProcess>
#include <QTextCodec>
#include "awdebug.h"
GPULoadSource::GPULoadSource(QObject *parent, const QStringList args)
: AbstractExtSysMonSource(parent, args)
{
Q_ASSERT(args.count() == 1);
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
m_device = args.at(0);
m_process = new QProcess(nullptr);
// fucking magic from http://doc.qt.io/qt-5/qprocess.html#finished
connect(m_process,
static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(
&QProcess::finished),
[this](int, QProcess::ExitStatus) { return updateValue(); });
m_process->waitForFinished(0);
}
GPULoadSource::~GPULoadSource()
{
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
m_process->kill();
m_process->deleteLater();
}
QVariant GPULoadSource::data(QString source)
{
qCDebug(LOG_ESM) << "Source" << source;
if (source == QString("gpu/load"))
run();
return m_value;
}
QVariantMap GPULoadSource::initialData(QString source) const
{
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;
}
void GPULoadSource::run()
{
if ((m_device != QString("nvidia")) && (m_device != QString("ati")))
return;
// build cmd
QString cmd = m_device == QString("nvidia")
? QString("nvidia-smi -q -x")
: QString("aticonfig --od-getclocks");
qCInfo(LOG_ESM) << "cmd" << cmd;
m_process->start(cmd);
}
QStringList GPULoadSource::sources() const
{
QStringList sources;
sources.append(QString("gpu/load"));
return sources;
}
void GPULoadSource::updateValue()
{
qCInfo(LOG_LIB) << "Cmd returns" << m_process->exitCode();
QString qdebug = QTextCodec::codecForMib(106)
->toUnicode(m_process->readAllStandardError())
.trimmed();
qCInfo(LOG_LIB) << "Error" << qdebug;
QString qoutput = QTextCodec::codecForMib(106)
->toUnicode(m_process->readAllStandardOutput())
.trimmed();
qCInfo(LOG_LIB) << "Output" << qoutput;
if (m_device == QString("nvidia")) {
for (auto str : qoutput.split(QChar('\n'), QString::SkipEmptyParts)) {
if (!str.contains(QString("<gpu_util>")))
continue;
QString load = str.remove(QString("<gpu_util>"))
.remove(QString("</gpu_util>"))
.remove(QChar('%'));
m_value = load.toFloat();
break;
}
} else if (m_device == QString("ati")) {
for (auto str : qoutput.split(QChar('\n'), QString::SkipEmptyParts)) {
if (!str.contains(QString("load")))
continue;
QString load
= str.split(QChar(' '), QString::SkipEmptyParts)[3].remove(
QChar('%'));
m_value = load.toFloat();
break;
}
}
}

View File

@ -1,49 +0,0 @@
/***************************************************************************
* 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 <QObject>
#include "abstractextsysmonsource.h"
class QProcess;
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 slots:
void updateValue();
private:
// configuration and values
QString m_device;
QProcess *m_process = nullptr;
QVariant m_value;
};
#endif /* GPULOADSOURCE_H */

View File

@ -1,136 +0,0 @@
/***************************************************************************
* 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 <QProcess>
#include <QTextCodec>
#include "awdebug.h"
GPUTemperatureSource::GPUTemperatureSource(QObject *parent,
const QStringList args)
: AbstractExtSysMonSource(parent, args)
{
Q_ASSERT(args.count() == 1);
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
m_device = args.at(0);
m_process = new QProcess(nullptr);
// fucking magic from http://doc.qt.io/qt-5/qprocess.html#finished
connect(m_process,
static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(
&QProcess::finished),
[this](int, QProcess::ExitStatus) { return updateValue(); });
m_process->waitForFinished(0);
}
GPUTemperatureSource::~GPUTemperatureSource()
{
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
m_process->kill();
m_process->deleteLater();
}
QVariant GPUTemperatureSource::data(QString source)
{
qCDebug(LOG_ESM) << "Source" << source;
if (source == QString("gpu/temperature"))
run();
return m_value;
}
QVariantMap GPUTemperatureSource::initialData(QString source) const
{
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;
}
void GPUTemperatureSource::run()
{
if ((m_device != QString("nvidia")) && (m_device != QString("ati")))
return;
// build cmd
QString cmd = m_device == QString("nvidia")
? QString("nvidia-smi -q -x")
: QString("aticonfig --od-gettemperature");
qCInfo(LOG_ESM) << "cmd" << cmd;
m_process->start(cmd);
}
QStringList GPUTemperatureSource::sources() const
{
QStringList sources;
sources.append(QString("gpu/temperature"));
return sources;
}
void GPUTemperatureSource::updateValue()
{
qCInfo(LOG_LIB) << "Cmd returns" << m_process->exitCode();
QString qdebug = QTextCodec::codecForMib(106)
->toUnicode(m_process->readAllStandardError())
.trimmed();
qCInfo(LOG_LIB) << "Error" << qdebug;
QString qoutput = QTextCodec::codecForMib(106)
->toUnicode(m_process->readAllStandardOutput())
.trimmed();
qCInfo(LOG_LIB) << "Output" << qoutput;
if (m_device == QString("nvidia")) {
for (auto str : qoutput.split(QChar('\n'), QString::SkipEmptyParts)) {
if (!str.contains(QString("<gpu_temp>")))
continue;
QString temp = str.remove(QString("<gpu_temp>"))
.remove(QString("C</gpu_temp>"));
m_value = temp.toFloat();
break;
}
} else if (m_device == QString("ati")) {
for (auto str : qoutput.split(QChar('\n'), QString::SkipEmptyParts)) {
if (!str.contains(QString("Temperature")))
continue;
QString temp = str.split(QChar(' '), QString::SkipEmptyParts).at(4);
m_value = temp.toFloat();
break;
}
}
}

View File

@ -1,49 +0,0 @@
/***************************************************************************
* 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 <QObject>
#include "abstractextsysmonsource.h"
class QProcess;
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 slots:
void updateValue();
private:
// configuration and values
QString m_device;
QProcess *m_process = nullptr;
QVariant m_value;
};
#endif /* GPUTEMPSOURCE_H */

View File

@ -1,140 +0,0 @@
/***************************************************************************
* 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 <QProcess>
#include <QTextCodec>
#include "awdebug.h"
HDDTemperatureSource::HDDTemperatureSource(QObject *parent,
const QStringList args)
: AbstractExtSysMonSource(parent, args)
{
Q_ASSERT(args.count() == 2);
qCDebug(LOG_ESM) << __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;
for (auto device : m_devices) {
m_processes[device] = new QProcess(nullptr);
// fucking magic from http://doc.qt.io/qt-5/qprocess.html#finished
connect(m_processes[device],
static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(
&QProcess::finished),
[this, device](int, QProcess::ExitStatus) {
return updateValue(device);
});
m_processes[device]->waitForFinished(0);
}
}
HDDTemperatureSource::~HDDTemperatureSource()
{
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
for (auto device : m_devices) {
m_processes[device]->kill();
m_processes[device]->deleteLater();
}
}
QVariant HDDTemperatureSource::data(QString source)
{
qCDebug(LOG_ESM) << "Source" << source;
QString device = source.remove(QString("hdd/temperature"));
// run cmd
if (m_processes[device]->state() == QProcess::NotRunning)
m_processes[device]->start(QString("%1 %2").arg(m_cmd).arg(device));
return m_values[device];
}
QVariantMap HDDTemperatureSource::initialData(QString source) const
{
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
{
QStringList sources;
for (auto device : m_devices)
sources.append(QString("hdd/temperature%1").arg(device));
return sources;
}
void HDDTemperatureSource::updateValue(const QString &device)
{
qCDebug(LOG_LIB) << "Called with device" << device;
qCInfo(LOG_LIB) << "Cmd returns" << m_processes[device]->exitCode();
QString qdebug
= QTextCodec::codecForMib(106)
->toUnicode(m_processes[device]->readAllStandardError())
.trimmed();
qCInfo(LOG_LIB) << "Error" << qdebug;
QString qoutput
= QTextCodec::codecForMib(106)
->toUnicode(m_processes[device]->readAllStandardOutput())
.trimmed();
qCInfo(LOG_LIB) << "Output" << qoutput;
// parse
if (m_smartctl) {
for (auto str : qoutput.split(QChar('\n'), QString::SkipEmptyParts)) {
if (!str.startsWith(QString("194")))
continue;
if (str.split(QChar(' '), QString::SkipEmptyParts).count() < 9)
continue;
m_values[device] = 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'));
m_values[device] = temp.toFloat();
}
}
}

View File

@ -1,52 +0,0 @@
/***************************************************************************
* 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 <QObject>
#include "abstractextsysmonsource.h"
class QProcess;
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 slots:
void updateValue(const QString &device);
private:
// properties
QHash<QString, QProcess *> m_processes;
// configuration and values
QString m_cmd;
QStringList m_devices;
bool m_smartctl;
QHash<QString, QVariant> m_values;
};
#endif /* HDDTEMPSOURCE_H */

View File

@ -1,71 +0,0 @@
/***************************************************************************
* 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 "loadsource.h"
#include "awdebug.h"
LoadSource::LoadSource(QObject *parent, const QStringList args)
: AbstractExtSysMonSource(parent, args)
{
Q_ASSERT(args.count() == 0);
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
}
LoadSource::~LoadSource()
{
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
}
QVariant LoadSource::data(QString source)
{
qCDebug(LOG_ESM) << "Source" << source;
source.remove(QString("load/load"));
return source.toInt();
}
QVariantMap LoadSource::initialData(QString source) const
{
qCDebug(LOG_ESM) << "Source" << source;
QVariantMap data;
if (source.startsWith(QString("load/load"))) {
data[QString("min")] = 0;
data[QString("max")] = 0;
data[QString("name")] = QString("Simple sources for load tests");
data[QString("type")] = QString("int");
data[QString("units")] = QString("");
}
return data;
}
QStringList LoadSource::sources() const
{
QStringList sources;
for (int i = 0; i < 1000; i++)
sources.append(QString("load/load%1").arg(i));
return sources;
}

View File

@ -1,38 +0,0 @@
/***************************************************************************
* 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 LOADSOURCE_H
#define LOADSOURCE_H
#include <QObject>
#include "abstractextsysmonsource.h"
class LoadSource : public AbstractExtSysMonSource
{
public:
explicit LoadSource(QObject *parent, const QStringList args);
virtual ~LoadSource();
QVariant data(QString source);
QVariantMap initialData(QString source) const;
void run(){};
QStringList sources() const;
};
#endif /* LOADSOURCE_H */

View File

@ -1,89 +0,0 @@
/***************************************************************************
* 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 <QNetworkInterface>
#include "awdebug.h"
NetworkSource::NetworkSource(QObject *parent, const QStringList args)
: AbstractExtSysMonSource(parent, args)
{
Q_ASSERT(args.count() == 0);
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
}
NetworkSource::~NetworkSource()
{
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
}
QVariant NetworkSource::data(QString source)
{
qCDebug(LOG_ESM) << "Source" << source;
if (source == QString("network/current/name")) {
QString device = QString("lo");
QList<QNetworkInterface> rawInterfaceList
= QNetworkInterface::allInterfaces();
qCInfo(LOG_ESM) << "Devices" << rawInterfaceList;
for (auto interface : rawInterfaceList) {
if ((interface.flags().testFlag(QNetworkInterface::IsLoopBack))
|| (interface.flags().testFlag(
QNetworkInterface::IsPointToPoint)))
continue;
if (interface.addressEntries().isEmpty())
continue;
device = interface.name();
break;
}
return device;
}
return QVariant();
}
QVariantMap NetworkSource::initialData(QString source) const
{
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
{
QStringList sources;
sources.append(QString("network/current/name"));
return sources;
}

View File

@ -1,38 +0,0 @@
/***************************************************************************
* 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 <QObject>
#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 */

View File

@ -1,386 +0,0 @@
/***************************************************************************
* 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 <QDBusArgument>
#include <QDBusConnection>
#include <QDBusConnectionInterface>
#include <QDBusMessage>
#include <QProcess>
#include <QTextCodec>
#include "awdebug.h"
PlayerSource::PlayerSource(QObject *parent, const QStringList args)
: AbstractExtSysMonSource(parent, args)
{
Q_ASSERT(args.count() == 5);
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
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();
m_mpdProcess = new QProcess(nullptr);
// fucking magic from http://doc.qt.io/qt-5/qprocess.html#finished
connect(m_mpdProcess,
static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(
&QProcess::finished),
[this](int, QProcess::ExitStatus) { return updateValue(); });
m_mpdProcess->waitForFinished(0);
m_mpdCached = defaultInfo();
}
PlayerSource::~PlayerSource()
{
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
m_mpdProcess->kill();
m_mpdProcess->deleteLater();
}
QVariant PlayerSource::data(QString source)
{
qCDebug(LOG_ESM) << "Source" << source;
if (!m_values.contains(source))
run();
QVariant value = m_values.take(source);
return value;
}
QVariantMap PlayerSource::initialData(QString source) const
{
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()
{
// initial data
if (m_player == QString("mpd")) {
// mpd
QHash<QString, QVariant> data = getPlayerMpdInfo(m_mpdAddress);
for (auto key : data.keys())
m_values[key] = data[key];
} else if (m_player == QString("mpris")) {
// players which supports mpris
QString mpris = m_mpris == QString("auto") ? getAutoMpris() : m_mpris;
QHash<QString, QVariant> data = getPlayerMprisInfo(mpris);
for (auto key : data.keys())
m_values[key] = data[key];
}
// dymanic properties
// solid
m_values[QString("player/salbum")]
= stripString(m_values[QString("player/album")].toString(), m_symbols);
m_values[QString("player/sartist")]
= stripString(m_values[QString("player/artist")].toString(), m_symbols);
m_values[QString("player/stitle")]
= stripString(m_values[QString("player/title")].toString(), m_symbols);
// dynamic
m_values[QString("player/dalbum")]
= buildString(m_values[QString("player/dalbum")].toString(),
m_values[QString("player/album")].toString(), m_symbols);
m_values[QString("player/dartist")]
= buildString(m_values[QString("player/dartist")].toString(),
m_values[QString("player/artist")].toString(), m_symbols);
m_values[QString("player/dtitle")]
= buildString(m_values[QString("player/dtitle")].toString(),
m_values[QString("player/title")].toString(), m_symbols);
}
QStringList PlayerSource::sources() const
{
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;
}
void PlayerSource::updateValue()
{
qCInfo(LOG_LIB) << "Cmd returns" << m_mpdProcess->exitCode();
QString qdebug = QTextCodec::codecForMib(106)
->toUnicode(m_mpdProcess->readAllStandardError())
.trimmed();
qCInfo(LOG_LIB) << "Error" << qdebug;
QString qoutput = QTextCodec::codecForMib(106)
->toUnicode(m_mpdProcess->readAllStandardOutput())
.trimmed();
qCInfo(LOG_LIB) << "Output" << qoutput;
for (auto str : qoutput.split(QChar('\n'), QString::SkipEmptyParts)) {
if (str.split(QString(": "), QString::SkipEmptyParts).count() == 2) {
// "Metadata: data"
QString metadata = str.split(QString(": "), QString::SkipEmptyParts)
.first()
.toLower();
QString data = str.split(QString(": "), QString::SkipEmptyParts)
.last()
.trimmed();
// there are one more time...
if ((metadata == QString("time")) && (data.contains(QChar(':')))) {
QStringList times = data.split(QString(":"));
m_mpdCached[QString("player/duration")] = times.at(0).toInt();
m_mpdCached[QString("player/progress")] = times.at(1).toInt();
} else if (m_metadata.contains(metadata)) {
m_mpdCached[QString("player/%1").arg(metadata)] = data;
}
}
}
}
QVariantHash PlayerSource::defaultInfo() const
{
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");
return info;
}
QString PlayerSource::getAutoMpris() const
{
QDBusMessage listServices = QDBusConnection::sessionBus().interface()->call(
QDBus::BlockWithGui, QString("ListNames"));
if (listServices.arguments().isEmpty())
return QString();
QStringList arguments = listServices.arguments().first().toStringList();
for (auto 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) << "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;
m_mpdProcess->start(cmd);
return m_mpdCached;
}
QVariantHash PlayerSource::getPlayerMprisInfo(const QString mpris) const
{
qCDebug(LOG_ESM) << "MPRIS" << mpris;
QVariantHash info = defaultInfo();
if (mpris.isEmpty())
return info;
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<QVariantHash>(response.arguments()
.first()
.value<QDBusVariant>()
.variant()
.value<QDBusArgument>());
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<QDBusVariant>()
.variant()
.toLongLong()
/ (1000 * 1000);
}
return info;
}
QString PlayerSource::buildString(const QString current, const QString value,
const int s) const
{
qCDebug(LOG_ESM) << "Current value" << current << "received" << value
<< "will be stripped after" << s;
int index = value.indexOf(current);
if ((current.isEmpty()) || ((index + s + 1) > value.count()))
return QString("%1").arg(value.left(s), 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) << "New value" << value << "will be stripped after" << s;
return value.count() > s ? QString("%1\u2026").arg(value.left(s - 1))
: value.leftJustified(s, QLatin1Char(' '));
}

View File

@ -1,64 +0,0 @@
/***************************************************************************
* 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 <QObject>
#include "abstractextsysmonsource.h"
class QProcess;
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 slots:
void updateValue();
private:
inline QVariantHash defaultInfo() const;
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;
QVariantHash m_mpdCached;
QProcess *m_mpdProcess = nullptr;
QString m_mpris;
QString m_player;
int m_symbols;
QStringList m_metadata = QStringList() << QString("album")
<< QString("artist")
<< QString("title");
QVariantHash m_values;
};
#endif /* PLAYERSOURCE_H */

View File

@ -1,115 +0,0 @@
/***************************************************************************
* 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 <QDir>
#include "awdebug.h"
ProcessesSource::ProcessesSource(QObject *parent, const QStringList args)
: AbstractExtSysMonSource(parent, args)
{
Q_ASSERT(args.count() == 0);
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
}
ProcessesSource::~ProcessesSource()
{
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
}
QVariant ProcessesSource::data(QString source)
{
qCDebug(LOG_ESM) << "Source" << source;
if (!m_values.contains(source))
run();
QVariant value = m_values.take(source);
return value;
}
QVariantMap ProcessesSource::initialData(QString source) const
{
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()
{
QStringList allDirectories
= QDir(QString("/proc"))
.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name);
QStringList directories = allDirectories.filter(QRegExp(QString("(\\d+)")));
QStringList running;
for (auto 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());
}
m_values[QString("ps/running/count")] = running.count();
m_values[QString("ps/running/list")] = running;
m_values[QString("ps/total/count")] = directories.count();
}
QStringList ProcessesSource::sources() const
{
QStringList sources;
sources.append(QString("ps/running/count"));
sources.append(QString("ps/running/list"));
sources.append(QString("ps/total/count"));
return sources;
}

View File

@ -1,42 +0,0 @@
/***************************************************************************
* 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 <QObject>
#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 m_values;
};
#endif /* PROCESSESSOURCE_H */

View File

@ -1,170 +0,0 @@
/***************************************************************************
* 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) << __PRETTY_FUNCTION__;
extQuotes = new ExtItemAggregator<ExtQuotes>(nullptr, QString("quotes"));
m_sources = getSources();
}
QuotesSource::~QuotesSource()
{
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
delete extQuotes;
}
QVariant QuotesSource::data(QString source)
{
qCDebug(LOG_ESM) << "Source" << source;
int ind = index(source);
source.remove(QString("quotes/"));
if (!m_values.contains(source)) {
QVariantHash data = extQuotes->itemByTagNumber(ind)->run();
for (auto key : data.keys())
m_values[key] = data[key];
}
QVariant value = m_values.take(source);
return value;
}
QVariantMap QuotesSource::initialData(QString source) const
{
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("double");
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("double");
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("double");
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("double");
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("double");
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("double");
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("double");
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("double");
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("double");
data[QString("units")] = QString("");
}
return data;
}
QStringList QuotesSource::sources() const
{
return m_sources;
}
QStringList QuotesSource::getSources()
{
QStringList sources;
for (auto 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;
}

View File

@ -1,48 +0,0 @@
/***************************************************************************
* 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 <QObject>
#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> *extQuotes = nullptr;
QStringList m_sources;
QVariantHash m_values;
};
#endif /* QUOTESSOURCE_H */

View File

@ -1,84 +0,0 @@
/***************************************************************************
* 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) << __PRETTY_FUNCTION__;
extUpgrade = new ExtItemAggregator<ExtUpgrade>(nullptr, QString("upgrade"));
m_sources = getSources();
}
UpgradeSource::~UpgradeSource()
{
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
delete extUpgrade;
}
QVariant UpgradeSource::data(QString source)
{
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) << "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
{
return m_sources;
}
QStringList UpgradeSource::getSources()
{
QStringList sources;
for (auto item : extUpgrade->activeItems())
sources.append(
QString("upgrade/%1").arg(item->tag(QString("pkgcount"))));
return sources;
}

View File

@ -1,47 +0,0 @@
/***************************************************************************
* 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 <QObject>
#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> *extUpgrade = nullptr;
QStringList m_sources;
};
#endif /* UPGRADESOURCE_H */

View File

@ -1,145 +0,0 @@
/***************************************************************************
* 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) << __PRETTY_FUNCTION__;
extWeather = new ExtItemAggregator<ExtWeather>(nullptr, QString("weather"));
m_sources = getSources();
}
WeatherSource::~WeatherSource()
{
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
delete extWeather;
}
QVariant WeatherSource::data(QString source)
{
qCDebug(LOG_ESM) << "Source" << source;
int ind = index(source);
source.remove(QString("weather/"));
if (!m_values.contains(source)) {
QVariantHash data = extWeather->itemByTagNumber(ind)->run();
for (auto key : data.keys())
m_values[key] = data[key];
}
QVariant value = m_values.take(source);
return value;
}
QVariantMap WeatherSource::initialData(QString source) const
{
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/pressure"))) {
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("mb");
} 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");
} else if (source.startsWith(QString("weather/timestamp"))) {
data[QString("min")] = QString("");
data[QString("max")] = QString("");
data[QString("name")]
= QString("Timestamp for '%1'")
.arg(extWeather->itemByTagNumber(ind)->uniq());
data[QString("type")] = QString("QString");
data[QString("units")] = QString("");
}
return data;
}
QStringList WeatherSource::sources() const
{
return m_sources;
}
QStringList WeatherSource::getSources()
{
QStringList sources;
for (auto 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"))));
sources.append(
QString("weather/%1").arg(item->tag(QString("timestamp"))));
}
return sources;
}

View File

@ -1,48 +0,0 @@
/***************************************************************************
* 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 <QObject>
#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> *extWeather = nullptr;
QStringList m_sources;
QVariantHash m_values;
};
#endif /* WEATHERSOURCE_H */