mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-07-09 20:05:51 +00:00
* create cppcheck and clangformat targets
* apply code style (#67) * send values by reference * fix warnings on plugin destruction by disconnecting dataengines first * fix invalid hddtemp group definition
This commit is contained in:
@ -3,14 +3,14 @@ message(STATUS "Subproject ${SUBPROJECT}")
|
||||
add_definitions(-DTRANSLATION_DOMAIN=\"plasma_applet_org.kde.plasma.awesomewidget\")
|
||||
|
||||
include_directories(
|
||||
${CMAKE_SOURCE_DIR}
|
||||
${CMAKE_BINARY_DIR}
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
${CMAKE_CURRENT_BINARY_DIR}/../
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../${PROJECT_LIBRARY}/
|
||||
${PROJECT_TRDPARTY_DIR}
|
||||
${Qt_INCLUDE}
|
||||
${Kf5_INCLUDE}
|
||||
${CMAKE_SOURCE_DIR}
|
||||
${CMAKE_BINARY_DIR}
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
${CMAKE_CURRENT_BINARY_DIR}/../
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../${PROJECT_LIBRARY}/
|
||||
${PROJECT_TRDPARTY_DIR}
|
||||
${Qt_INCLUDE}
|
||||
${Kf5_INCLUDE}
|
||||
)
|
||||
|
||||
file(GLOB SUBPROJECT_DESKTOP_IN *.desktop)
|
||||
|
@ -42,7 +42,7 @@ ExtendedSysMon::ExtendedSysMon(QObject *parent, const QVariantList &args)
|
||||
|
||||
// init aggregator
|
||||
aggregator = new ExtSysMonAggregator(this, configuration);
|
||||
foreach(QString source, aggregator->sources())
|
||||
foreach (QString source, aggregator->sources())
|
||||
setData(source, aggregator->initialData(source));
|
||||
}
|
||||
|
||||
@ -92,9 +92,10 @@ QStringList ExtendedSysMon::getAllHdd() const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
|
||||
QStringList allDevices = QDir(QString("/dev")).entryList(QDir::System, QDir::Name);
|
||||
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++)
|
||||
for (int i = 0; i < devices.count(); i++)
|
||||
devices[i] = QString("/dev/%1").arg(devices.at(i));
|
||||
|
||||
qCInfo(LOG_ESM) << "Device list" << devices;
|
||||
@ -108,7 +109,8 @@ QString ExtendedSysMon::getAutoGpu() const
|
||||
|
||||
QString gpu = QString("disable");
|
||||
QFile moduleFile(QString("/proc/modules"));
|
||||
if (!moduleFile.open(QIODevice::ReadOnly)) return gpu;
|
||||
if (!moduleFile.open(QIODevice::ReadOnly))
|
||||
return gpu;
|
||||
|
||||
QString output = moduleFile.readAll();
|
||||
if (output.contains(QString("fglrx")))
|
||||
@ -125,29 +127,44 @@ void ExtendedSysMon::readConfiguration()
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
|
||||
QString fileName = QStandardPaths::locate(QStandardPaths::ConfigLocation,
|
||||
QString("plasma-dataengine-extsysmon.conf"));
|
||||
QString fileName
|
||||
= QStandardPaths::locate(QStandardPaths::ConfigLocation,
|
||||
QString("plasma-dataengine-extsysmon.conf"));
|
||||
qCInfo(LOG_ESM) << "Configuration file" << fileName;
|
||||
QSettings settings(fileName, QSettings::IniFormat);
|
||||
QHash<QString, QString> rawConfig;
|
||||
|
||||
settings.beginGroup(QString("Configuration"));
|
||||
rawConfig[QString("ACPIPATH")] = settings.value(QString("ACPIPATH"), QString("/sys/class/power_supply/")).toString();
|
||||
rawConfig[QString("GPUDEV")] = settings.value(QString("GPUDEV"), QString("auto")).toString();
|
||||
rawConfig[QString("HDDDEV")] = settings.value(QString("HDDDEV"), QString("all")).toString();
|
||||
rawConfig[QString("HDDTEMPCMD")] = settings.value(QString("HDDTEMPCMD"), QString("sudo smartctl -a")).toString();
|
||||
rawConfig[QString("MPDADDRESS")] = settings.value(QString("MPDADDRESS"), QString("localhost")).toString();
|
||||
rawConfig[QString("MPDPORT")] = settings.value(QString("MPDPORT"), QString("6600")).toString();
|
||||
rawConfig[QString("MPRIS")] = settings.value(QString("MPRIS"), QString("auto")).toString();
|
||||
rawConfig[QString("PLAYER")] = settings.value(QString("PLAYER"), QString("mpris")).toString();
|
||||
rawConfig[QString("PLAYERSYMBOLS")] = settings.value(QString("PLAYERSYMBOLS"), QString("10")).toString();
|
||||
rawConfig[QString("ACPIPATH")]
|
||||
= settings.value(QString("ACPIPATH"),
|
||||
QString("/sys/class/power_supply/"))
|
||||
.toString();
|
||||
rawConfig[QString("GPUDEV")]
|
||||
= settings.value(QString("GPUDEV"), QString("auto")).toString();
|
||||
rawConfig[QString("HDDDEV")]
|
||||
= settings.value(QString("HDDDEV"), QString("all")).toString();
|
||||
rawConfig[QString("HDDTEMPCMD")]
|
||||
= settings.value(QString("HDDTEMPCMD"), QString("sudo smartctl -a"))
|
||||
.toString();
|
||||
rawConfig[QString("MPDADDRESS")]
|
||||
= settings.value(QString("MPDADDRESS"), QString("localhost"))
|
||||
.toString();
|
||||
rawConfig[QString("MPDPORT")]
|
||||
= settings.value(QString("MPDPORT"), QString("6600")).toString();
|
||||
rawConfig[QString("MPRIS")]
|
||||
= settings.value(QString("MPRIS"), QString("auto")).toString();
|
||||
rawConfig[QString("PLAYER")]
|
||||
= settings.value(QString("PLAYER"), QString("mpris")).toString();
|
||||
rawConfig[QString("PLAYERSYMBOLS")]
|
||||
= settings.value(QString("PLAYERSYMBOLS"), QString("10")).toString();
|
||||
settings.endGroup();
|
||||
|
||||
configuration = updateConfiguration(rawConfig);
|
||||
}
|
||||
|
||||
|
||||
QHash<QString, QString> ExtendedSysMon::updateConfiguration(QHash<QString, QString> rawConfig) const
|
||||
QHash<QString, QString>
|
||||
ExtendedSysMon::updateConfiguration(QHash<QString, QString> rawConfig) const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_ESM) << "Raw configuration" << rawConfig;
|
||||
@ -157,20 +174,21 @@ QHash<QString, QString> ExtendedSysMon::updateConfiguration(QHash<QString, QStri
|
||||
rawConfig[QString("GPUDEV")] = QString("disable");
|
||||
else if (rawConfig[QString("GPUDEV")] == QString("auto"))
|
||||
rawConfig[QString("GPUDEV")] = getAutoGpu();
|
||||
else if ((rawConfig[QString("GPUDEV")] != QString("ati")) &&
|
||||
(rawConfig[QString("GPUDEV")] != QString("nvidia")))
|
||||
else if ((rawConfig[QString("GPUDEV")] != QString("ati"))
|
||||
&& (rawConfig[QString("GPUDEV")] != QString("nvidia")))
|
||||
rawConfig[QString("GPUDEV")] = getAutoGpu();
|
||||
// hdddev
|
||||
QStringList allHddDevices = getAllHdd();
|
||||
if (rawConfig[QString("HDDDEV")] == QString("all"))
|
||||
if (rawConfig[QString("HDDDEV")] == QString("all")) {
|
||||
rawConfig[QString("HDDDEV")] = allHddDevices.join(QChar(','));
|
||||
else if (rawConfig[QString("HDDDEV")] == QString("disable"))
|
||||
} else if (rawConfig[QString("HDDDEV")] == QString("disable")) {
|
||||
rawConfig[QString("HDDDEV")] = QString("");
|
||||
else {
|
||||
QStringList deviceList = rawConfig[QString("HDDDEV")].split(QChar(','), QString::SkipEmptyParts);
|
||||
} else {
|
||||
QStringList deviceList = rawConfig[QString("HDDDEV")].split(
|
||||
QChar(','), QString::SkipEmptyParts);
|
||||
QStringList devices;
|
||||
QRegExp diskRegexp = QRegExp("^/dev/[hms]d[a-z]$");
|
||||
foreach(QString device, deviceList)
|
||||
foreach (QString device, deviceList)
|
||||
if ((QFile::exists(device)) && (device.contains(diskRegexp)))
|
||||
devices.append(device);
|
||||
if (devices.isEmpty())
|
||||
@ -179,20 +197,21 @@ QHash<QString, QString> ExtendedSysMon::updateConfiguration(QHash<QString, QStri
|
||||
rawConfig[QString("HDDDEV")] = devices.join(QChar(','));
|
||||
}
|
||||
// player
|
||||
if ((rawConfig[QString("PLAYER")] != QString("mpd")) &&
|
||||
(rawConfig[QString("PLAYER")] != QString("mpris")) &&
|
||||
(rawConfig[QString("PLAYER")] != QString("disable")))
|
||||
if ((rawConfig[QString("PLAYER")] != QString("mpd"))
|
||||
&& (rawConfig[QString("PLAYER")] != QString("mpris"))
|
||||
&& (rawConfig[QString("PLAYER")] != QString("disable")))
|
||||
rawConfig[QString("PLAYER")] = QString("mpris");
|
||||
// player symbols
|
||||
if (rawConfig[QString("PLAYERSYMBOLS")].toInt() <= 0)
|
||||
rawConfig[QString("PLAYERSYMBOLS")] = QString("10");
|
||||
|
||||
foreach(QString key, rawConfig.keys())
|
||||
foreach (QString key, rawConfig.keys())
|
||||
qCInfo(LOG_ESM) << key << "=" << rawConfig[key];
|
||||
return rawConfig;
|
||||
}
|
||||
|
||||
|
||||
K_EXPORT_PLASMA_DATAENGINE_WITH_JSON(extsysmon, ExtendedSysMon, "plasma-dataengine-extsysmon.json")
|
||||
K_EXPORT_PLASMA_DATAENGINE_WITH_JSON(extsysmon, ExtendedSysMon,
|
||||
"plasma-dataengine-extsysmon.json")
|
||||
|
||||
#include "extsysmon.moc"
|
||||
|
@ -44,7 +44,8 @@ private:
|
||||
QStringList getAllHdd() const;
|
||||
QString getAutoGpu() const;
|
||||
void readConfiguration();
|
||||
QHash<QString, QString> updateConfiguration(QHash<QString, QString> rawConfig) const;
|
||||
QHash<QString, QString>
|
||||
updateConfiguration(QHash<QString, QString> rawConfig) const;
|
||||
};
|
||||
|
||||
|
||||
|
@ -35,7 +35,8 @@
|
||||
#include "sources/weathersource.h"
|
||||
|
||||
|
||||
ExtSysMonAggregator::ExtSysMonAggregator(QObject *parent, const QHash<QString, QString> config)
|
||||
ExtSysMonAggregator::ExtSysMonAggregator(QObject *parent,
|
||||
const QHash<QString, QString> config)
|
||||
: QObject(parent)
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
@ -61,15 +62,6 @@ QVariant ExtSysMonAggregator::data(const QString source) const
|
||||
}
|
||||
|
||||
|
||||
AbstractExtSysMonSource *ExtSysMonAggregator::engine(const QString source)
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_ESM) << "Source" << source;
|
||||
|
||||
return hasSource(source) ? m_map[source] : nullptr;
|
||||
}
|
||||
|
||||
|
||||
bool ExtSysMonAggregator::hasSource(const QString source) const
|
||||
{
|
||||
return m_map.contains(source);
|
||||
@ -81,7 +73,8 @@ QVariantMap ExtSysMonAggregator::initialData(const QString source) const
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_ESM) << "Source" << source;
|
||||
|
||||
return hasSource(source) ? m_map[source]->initialData(source) : QVariantMap();
|
||||
return hasSource(source) ? m_map[source]->initialData(source)
|
||||
: QVariantMap();
|
||||
}
|
||||
|
||||
|
||||
@ -100,64 +93,75 @@ void ExtSysMonAggregator::init(const QHash<QString, QString> config)
|
||||
qCDebug(LOG_ESM);
|
||||
|
||||
// battery
|
||||
AbstractExtSysMonSource *batteryItem = new BatterySource(this, QStringList() << config[QString("ACPIPATH")]);
|
||||
foreach(QString source, batteryItem->sources())
|
||||
AbstractExtSysMonSource *batteryItem
|
||||
= new BatterySource(this, QStringList() << config[QString("ACPIPATH")]);
|
||||
foreach (QString source, batteryItem->sources())
|
||||
m_map[source] = batteryItem;
|
||||
// custom
|
||||
AbstractExtSysMonSource *customItem = new CustomSource(this, QStringList());
|
||||
foreach(QString source, customItem->sources())
|
||||
foreach (QString source, customItem->sources())
|
||||
m_map[source] = customItem;
|
||||
// desktop
|
||||
AbstractExtSysMonSource *desktopItem = new DesktopSource(this, QStringList());
|
||||
foreach(QString source, desktopItem->sources())
|
||||
AbstractExtSysMonSource *desktopItem
|
||||
= new DesktopSource(this, QStringList());
|
||||
foreach (QString source, desktopItem->sources())
|
||||
m_map[source] = desktopItem;
|
||||
// gpu load
|
||||
AbstractExtSysMonSource *gpuLoadItem = new GPULoadSource(this, QStringList() << config[QString("GPUDEV")]);
|
||||
foreach(QString source, gpuLoadItem->sources())
|
||||
AbstractExtSysMonSource *gpuLoadItem
|
||||
= new GPULoadSource(this, QStringList() << config[QString("GPUDEV")]);
|
||||
foreach (QString source, gpuLoadItem->sources())
|
||||
m_map[source] = gpuLoadItem;
|
||||
// gpu temperature
|
||||
AbstractExtSysMonSource *gpuTempItem = new GPUTemperatureSource(this, QStringList() << config[QString("GPUDEV")]);
|
||||
foreach(QString source, gpuTempItem->sources())
|
||||
AbstractExtSysMonSource *gpuTempItem = new GPUTemperatureSource(
|
||||
this, QStringList() << config[QString("GPUDEV")]);
|
||||
foreach (QString source, gpuTempItem->sources())
|
||||
m_map[source] = gpuTempItem;
|
||||
// hdd temperature
|
||||
AbstractExtSysMonSource *hddTempItem = new HDDTemperatureSource(this,
|
||||
QStringList() << config[QString("HDDDEV")] << config[QString("HDDTEMPCMD")]);
|
||||
foreach(QString source, hddTempItem->sources())
|
||||
AbstractExtSysMonSource *hddTempItem = new HDDTemperatureSource(
|
||||
this, QStringList() << config[QString("HDDDEV")]
|
||||
<< config[QString("HDDTEMPCMD")]);
|
||||
foreach (QString source, hddTempItem->sources())
|
||||
m_map[source] = hddTempItem;
|
||||
// network
|
||||
AbstractExtSysMonSource *networkItem = new NetworkSource(this, QStringList());
|
||||
foreach(QString source, networkItem->sources())
|
||||
AbstractExtSysMonSource *networkItem
|
||||
= new NetworkSource(this, QStringList());
|
||||
foreach (QString source, networkItem->sources())
|
||||
m_map[source] = networkItem;
|
||||
// player
|
||||
AbstractExtSysMonSource *playerItem = new PlayerSource(this,
|
||||
QStringList() << config[QString("PLAYER")] << config[QString("MPDADDRESS")]
|
||||
<< config[QString("MPDPORT")] << config[QString("MPRIS")] << config[QString("PLAYERSYMBOLS")]);
|
||||
foreach(QString source, playerItem->sources())
|
||||
AbstractExtSysMonSource *playerItem = new PlayerSource(
|
||||
this, QStringList()
|
||||
<< config[QString("PLAYER")] << config[QString("MPDADDRESS")]
|
||||
<< config[QString("MPDPORT")] << config[QString("MPRIS")]
|
||||
<< config[QString("PLAYERSYMBOLS")]);
|
||||
foreach (QString source, playerItem->sources())
|
||||
m_map[source] = playerItem;
|
||||
// processes
|
||||
AbstractExtSysMonSource *processesItem = new ProcessesSource(this, QStringList());
|
||||
foreach(QString source, processesItem->sources())
|
||||
AbstractExtSysMonSource *processesItem
|
||||
= new ProcessesSource(this, QStringList());
|
||||
foreach (QString source, processesItem->sources())
|
||||
m_map[source] = processesItem;
|
||||
// quotes
|
||||
AbstractExtSysMonSource *quotesItem = new QuotesSource(this, QStringList());
|
||||
foreach(QString source, quotesItem->sources())
|
||||
foreach (QString source, quotesItem->sources())
|
||||
m_map[source] = quotesItem;
|
||||
// update
|
||||
AbstractExtSysMonSource *updateItem = new UpdateSource(this, QStringList());
|
||||
foreach(QString source, updateItem->sources())
|
||||
foreach (QString source, updateItem->sources())
|
||||
m_map[source] = updateItem;
|
||||
// upgrade
|
||||
AbstractExtSysMonSource *upgradeItem = new UpgradeSource(this, QStringList());
|
||||
foreach(QString source, upgradeItem->sources())
|
||||
AbstractExtSysMonSource *upgradeItem
|
||||
= new UpgradeSource(this, QStringList());
|
||||
foreach (QString source, upgradeItem->sources())
|
||||
m_map[source] = upgradeItem;
|
||||
// weather
|
||||
AbstractExtSysMonSource *weatherItem = new WeatherSource(this, QStringList());
|
||||
foreach(QString source, weatherItem->sources())
|
||||
AbstractExtSysMonSource *weatherItem
|
||||
= new WeatherSource(this, QStringList());
|
||||
foreach (QString source, weatherItem->sources())
|
||||
m_map[source] = weatherItem;
|
||||
#ifdef BUILD_TESTING
|
||||
// additional load source
|
||||
AbstractExtSysMonSource *loadItem = new LoadSource(this, QStringList());
|
||||
foreach(QString source, loadItem->sources())
|
||||
foreach (QString source, loadItem->sources())
|
||||
m_map[source] = loadItem;
|
||||
#endif /* BUILD_TESTING */
|
||||
}
|
||||
|
@ -28,10 +28,10 @@ class ExtSysMonAggregator : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ExtSysMonAggregator(QObject *parent, const QHash<QString, QString> config);
|
||||
explicit ExtSysMonAggregator(QObject *parent,
|
||||
const QHash<QString, QString> config);
|
||||
virtual ~ExtSysMonAggregator();
|
||||
QVariant data(const QString source) const;
|
||||
AbstractExtSysMonSource *engine(const QString source);
|
||||
bool hasSource(const QString source) const;
|
||||
QVariantMap initialData(const QString source) const;
|
||||
QStringList sources() const;
|
||||
|
@ -26,8 +26,9 @@
|
||||
class AbstractExtSysMonSource : public QObject
|
||||
{
|
||||
public:
|
||||
explicit AbstractExtSysMonSource(QObject *parent, const QStringList) : QObject(parent) {};
|
||||
virtual ~AbstractExtSysMonSource() {};
|
||||
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;
|
||||
|
@ -45,7 +45,8 @@ QVariant BatterySource::data(QString source)
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_ESM) << "Source" << source;
|
||||
|
||||
if (source == QString("battery/ac")) run();
|
||||
if (source == QString("battery/ac"))
|
||||
run();
|
||||
return values[source];
|
||||
}
|
||||
|
||||
@ -87,27 +88,34 @@ void BatterySource::run()
|
||||
// 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);
|
||||
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<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();
|
||||
values[QString("battery/bat%1").arg(i)] = static_cast<int>(100 * batCurrent / batFull);
|
||||
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();
|
||||
values[QString("battery/bat%1").arg(i)]
|
||||
= static_cast<int>(100 * batCurrent / batFull);
|
||||
currentLevel += batCurrent;
|
||||
fullLevel += batFull;
|
||||
}
|
||||
currentLevelFile.close();
|
||||
fullLevelFile.close();
|
||||
}
|
||||
values[QString("battery/bat")] = static_cast<int>(100 * currentLevel / fullLevel);
|
||||
values[QString("battery/bat")]
|
||||
= static_cast<int>(100 * currentLevel / fullLevel);
|
||||
}
|
||||
|
||||
|
||||
@ -126,13 +134,15 @@ 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();
|
||||
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++)
|
||||
for (int i = 0; i < m_batteriesCount; i++)
|
||||
sources.append(QString("battery/bat%1").arg(i));
|
||||
|
||||
qCInfo(LOG_ESM) << "Sources list" << sources;
|
||||
|
||||
return sources;
|
||||
}
|
||||
|
@ -59,7 +59,9 @@ QVariantMap CustomSource::initialData(QString source) const
|
||||
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("name")]
|
||||
= QString("Custom command '%1' output")
|
||||
.arg(extScripts->itemByTagNumber(index(source))->uniq());
|
||||
data[QString("type")] = QString("QString");
|
||||
data[QString("units")] = QString("");
|
||||
|
||||
@ -80,7 +82,7 @@ QStringList CustomSource::getSources()
|
||||
qCDebug(LOG_ESM);
|
||||
|
||||
QStringList sources;
|
||||
foreach(ExtScript *item, extScripts->activeItems())
|
||||
foreach (ExtScript *item, extScripts->activeItems())
|
||||
sources.append(QString("custom/%1").arg(item->tag(QString("custom"))));
|
||||
|
||||
return sources;
|
||||
|
@ -33,7 +33,7 @@ public:
|
||||
virtual ~CustomSource();
|
||||
QVariant data(QString source);
|
||||
QVariantMap initialData(QString source) const;
|
||||
void run() {};
|
||||
void run(){};
|
||||
QStringList sources() const;
|
||||
|
||||
private:
|
||||
|
@ -51,7 +51,7 @@ QVariant DesktopSource::data(QString source)
|
||||
return current;
|
||||
} else if (source == QString("desktop/total/name")) {
|
||||
QStringList desktops;
|
||||
for (int i=1; i<total+1; i++)
|
||||
for (int i = 1; i < total + 1; i++)
|
||||
desktops.append(KWindowSystem::desktopName(i));
|
||||
return desktops;
|
||||
} else if (source == QString("desktop/total/number")) {
|
||||
|
@ -30,7 +30,7 @@ public:
|
||||
virtual ~DesktopSource();
|
||||
QVariant data(QString source);
|
||||
QVariantMap initialData(QString source) const;
|
||||
void run() {};
|
||||
void run(){};
|
||||
QStringList sources() const;
|
||||
};
|
||||
|
||||
|
@ -51,29 +51,39 @@ QVariant GPULoadSource::data(QString source)
|
||||
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");
|
||||
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("<gpu_util>"))) continue;
|
||||
QString load = str.remove(QString("<gpu_util>")).remove(QString("</gpu_util>"))
|
||||
.remove(QChar('%'));
|
||||
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("<gpu_util>")))
|
||||
continue;
|
||||
QString load = str.remove(QString("<gpu_util>"))
|
||||
.remove(QString("</gpu_util>"))
|
||||
.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('%'));
|
||||
} 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;
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ public:
|
||||
virtual ~GPULoadSource();
|
||||
QVariant data(QString source);
|
||||
QVariantMap initialData(QString source) const;
|
||||
void run() {};
|
||||
void run(){};
|
||||
QStringList sources() const;
|
||||
|
||||
private:
|
||||
|
@ -25,7 +25,8 @@
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
GPUTemperatureSource::GPUTemperatureSource(QObject *parent, const QStringList args)
|
||||
GPUTemperatureSource::GPUTemperatureSource(QObject *parent,
|
||||
const QStringList args)
|
||||
: AbstractExtSysMonSource(parent, args)
|
||||
{
|
||||
Q_ASSERT(args.count() == 1);
|
||||
@ -51,27 +52,37 @@ QVariant GPUTemperatureSource::data(QString source)
|
||||
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");
|
||||
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("<gpu_temp>"))) continue;
|
||||
QString temp = str.remove(QString("<gpu_temp>")).remove(QString("C</gpu_temp>"));
|
||||
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("<gpu_temp>")))
|
||||
continue;
|
||||
QString temp = str.remove(QString("<gpu_temp>"))
|
||||
.remove(QString("C</gpu_temp>"));
|
||||
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);
|
||||
} 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;
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ public:
|
||||
virtual ~GPUTemperatureSource();
|
||||
QVariant data(QString source);
|
||||
QVariantMap initialData(QString source) const;
|
||||
void run() {};
|
||||
void run(){};
|
||||
QStringList sources() const;
|
||||
|
||||
private:
|
||||
|
@ -25,7 +25,8 @@
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
HDDTemperatureSource::HDDTemperatureSource(QObject *parent, const QStringList args)
|
||||
HDDTemperatureSource::HDDTemperatureSource(QObject *parent,
|
||||
const QStringList args)
|
||||
: AbstractExtSysMonSource(parent, args)
|
||||
{
|
||||
Q_ASSERT(args.count() == 2);
|
||||
@ -58,17 +59,24 @@ QVariant HDDTemperatureSource::data(QString source)
|
||||
qCInfo(LOG_ESM) << "Error" << process.error;
|
||||
|
||||
// parse
|
||||
QString qoutput = QTextCodec::codecForMib(106)->toUnicode(process.output).trimmed();
|
||||
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();
|
||||
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);
|
||||
QString temp
|
||||
= qoutput.split(QChar(':'), QString::SkipEmptyParts).at(2);
|
||||
temp.remove(QChar(0260)).remove(QChar('C'));
|
||||
value = temp.toFloat();
|
||||
}
|
||||
@ -100,7 +108,7 @@ QStringList HDDTemperatureSource::sources() const
|
||||
qCDebug(LOG_ESM);
|
||||
|
||||
QStringList sources;
|
||||
foreach(QString device, m_devices)
|
||||
foreach (QString device, m_devices)
|
||||
sources.append(QString("hdd/temperature%1").arg(device));
|
||||
|
||||
return sources;
|
||||
|
@ -30,7 +30,7 @@ public:
|
||||
virtual ~HDDTemperatureSource();
|
||||
QVariant data(QString source);
|
||||
QVariantMap initialData(QString source) const;
|
||||
void run() {};
|
||||
void run(){};
|
||||
QStringList sources() const;
|
||||
|
||||
private:
|
||||
|
@ -68,8 +68,8 @@ QStringList LoadSource::sources() const
|
||||
qCDebug(LOG_ESM);
|
||||
|
||||
QStringList sources;
|
||||
for (int i=0; i<1000; i++)
|
||||
sources.append(QString("load/load%1").arg(i));
|
||||
for (int i = 0; i < 1000; i++)
|
||||
sources.append(QString("load/load%1").arg(i));
|
||||
|
||||
return sources;
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ public:
|
||||
virtual ~LoadSource();
|
||||
QVariant data(QString source);
|
||||
QVariantMap initialData(QString source) const;
|
||||
void run() {};
|
||||
void run(){};
|
||||
QStringList sources() const;
|
||||
};
|
||||
|
||||
|
@ -44,13 +44,16 @@ QVariant NetworkSource::data(QString source)
|
||||
|
||||
if (source == QString("network/current/name")) {
|
||||
QString device = QString("lo");
|
||||
QList<QNetworkInterface> rawInterfaceList = QNetworkInterface::allInterfaces();
|
||||
QList<QNetworkInterface> rawInterfaceList
|
||||
= QNetworkInterface::allInterfaces();
|
||||
qCInfo(LOG_ESM) << "Devices" << rawInterfaceList;
|
||||
foreach(QNetworkInterface interface, rawInterfaceList) {
|
||||
if ((interface.flags().testFlag(QNetworkInterface::IsLoopBack)) ||
|
||||
(interface.flags().testFlag(QNetworkInterface::IsPointToPoint)))
|
||||
foreach (QNetworkInterface interface, rawInterfaceList) {
|
||||
if ((interface.flags().testFlag(QNetworkInterface::IsLoopBack))
|
||||
|| (interface.flags().testFlag(
|
||||
QNetworkInterface::IsPointToPoint)))
|
||||
continue;
|
||||
if (interface.addressEntries().isEmpty())
|
||||
continue;
|
||||
if (interface.addressEntries().isEmpty()) continue;
|
||||
device = interface.name();
|
||||
break;
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ public:
|
||||
virtual ~NetworkSource();
|
||||
QVariant data(QString source);
|
||||
QVariantMap initialData(QString source) const;
|
||||
void run() {};
|
||||
void run(){};
|
||||
QStringList sources() const;
|
||||
};
|
||||
|
||||
|
@ -53,7 +53,8 @@ QVariant PlayerSource::data(QString source)
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_ESM) << "Source" << source;
|
||||
|
||||
if (source == QString("player/title")) run();
|
||||
if (source == QString("player/title"))
|
||||
run();
|
||||
return values[source];
|
||||
}
|
||||
|
||||
@ -73,13 +74,16 @@ QVariantMap PlayerSource::initialData(QString source) const
|
||||
} 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("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("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")) {
|
||||
@ -91,13 +95,16 @@ QVariantMap PlayerSource::initialData(QString source) const
|
||||
} 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("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("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")) {
|
||||
@ -121,13 +128,16 @@ QVariantMap PlayerSource::initialData(QString source) const
|
||||
} 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("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("name")]
|
||||
= QString("Current song title (%1 symbols, dynamic)")
|
||||
.arg(m_symbols);
|
||||
data[QString("type")] = QString("QString");
|
||||
data[QString("units")] = QString("");
|
||||
}
|
||||
@ -144,32 +154,34 @@ void PlayerSource::run()
|
||||
if (m_player == QString("mpd")) {
|
||||
// mpd
|
||||
QHash<QString, QVariant> data = getPlayerMpdInfo(m_mpdAddress);
|
||||
foreach(QString key, data.keys()) values[key] = data[key];
|
||||
foreach (QString key, data.keys())
|
||||
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);
|
||||
foreach(QString key, data.keys()) values[key] = data[key];
|
||||
foreach (QString key, data.keys())
|
||||
values[key] = data[key];
|
||||
}
|
||||
|
||||
// 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);
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@ -211,12 +223,15 @@ QString PlayerSource::getAutoMpris() const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
|
||||
QDBusMessage listServices = QDBusConnection::sessionBus().interface()->call(QDBus::BlockWithGui, QString("ListNames"));
|
||||
if (listServices.arguments().isEmpty()) return QString();
|
||||
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;
|
||||
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."));
|
||||
@ -235,19 +250,25 @@ QVariantHash PlayerSource::getPlayerMpdInfo(const QString mpdAddress) const
|
||||
QVariantHash info = defaultInfo();
|
||||
|
||||
// build cmd
|
||||
QString cmd = QString("bash -c \"echo 'currentsong\nstatus\nclose' | curl --connect-timeout 1 -fsm 3 telnet://%1\"")
|
||||
.arg(mpdAddress);
|
||||
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)) {
|
||||
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() == 2) {
|
||||
// "Metadata: data"
|
||||
QString metadata = str.split(QString(": "), QString::SkipEmptyParts).first().toLower();
|
||||
QString data = str.split(QString(": "), QString::SkipEmptyParts).last().trimmed();
|
||||
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(":"));
|
||||
@ -269,44 +290,63 @@ QVariantHash PlayerSource::getPlayerMprisInfo(const QString mpris) const
|
||||
qCDebug(LOG_ESM) << "MPRIS" << mpris;
|
||||
|
||||
QVariantHash info = defaultInfo();
|
||||
if (mpris.isEmpty()) return info;
|
||||
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
|
||||
// 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"));
|
||||
// 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())) {
|
||||
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"));
|
||||
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"));
|
||||
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())) {
|
||||
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);
|
||||
info[QString("player/progress")] = response.arguments()
|
||||
.first()
|
||||
.value<QDBusVariant>()
|
||||
.variant()
|
||||
.toLongLong()
|
||||
/ (1000 * 1000);
|
||||
}
|
||||
|
||||
return info;
|
||||
@ -322,10 +362,11 @@ QString PlayerSource::buildString(const QString current, const QString value,
|
||||
qCDebug(LOG_ESM) << "Strip after" << s;
|
||||
|
||||
int index = value.indexOf(current);
|
||||
if ((current.isEmpty()) || ((index + s + 1) > value.count()))
|
||||
if ((current.isEmpty()) || ((index + s + 1) > value.count())) {
|
||||
return QString("%1").arg(value.left(s), s, QLatin1Char(' '));
|
||||
else
|
||||
} else {
|
||||
return QString("%1").arg(value.mid(index + 1, s), s, QLatin1Char(' '));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -335,6 +376,6 @@ QString PlayerSource::stripString(const QString value, const int s) const
|
||||
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(' '));
|
||||
return value.count() > s ? QString("%1\u2026").arg(value.left(s - 1))
|
||||
: value.leftJustified(s, QLatin1Char(' '));
|
||||
}
|
||||
|
@ -39,14 +39,17 @@ private:
|
||||
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 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;
|
||||
QStringList m_metadata = QStringList() << QString("album") << QString("artist") << QString("title");
|
||||
QStringList m_metadata = QStringList() << QString("album")
|
||||
<< QString("artist")
|
||||
<< QString("title");
|
||||
QVariantHash values;
|
||||
};
|
||||
|
||||
|
@ -42,7 +42,8 @@ QVariant ProcessesSource::data(QString source)
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_ESM) << "Source" << source;
|
||||
|
||||
if (source == QString("ps/running/count")) run();
|
||||
if (source == QString("ps/running/count"))
|
||||
run();
|
||||
return values[source];
|
||||
}
|
||||
|
||||
@ -81,19 +82,23 @@ void ProcessesSource::run()
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
|
||||
QStringList allDirectories = QDir(QString("/proc")).entryList(QDir::Dirs | QDir::NoDotAndDotDot,
|
||||
QDir::Name);
|
||||
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) {
|
||||
foreach (QString dir, directories) {
|
||||
QFile statusFile(QString("/proc/%1/status").arg(dir));
|
||||
if (!statusFile.open(QIODevice::ReadOnly)) continue;
|
||||
if (!statusFile.open(QIODevice::ReadOnly))
|
||||
continue;
|
||||
QFile cmdFile(QString("/proc/%1/cmdline").arg(dir));
|
||||
if (!cmdFile.open(QIODevice::ReadOnly)) continue;
|
||||
if (!cmdFile.open(QIODevice::ReadOnly))
|
||||
continue;
|
||||
|
||||
QString output = statusFile.readAll();
|
||||
if (output.contains(QString("running"))) running.append(cmdFile.readAll());
|
||||
if (output.contains(QString("running")))
|
||||
running.append(cmdFile.readAll());
|
||||
}
|
||||
|
||||
values[QString("ps/running/count")] = running.count();
|
||||
|
@ -48,7 +48,8 @@ QVariant QuotesSource::data(QString source)
|
||||
|
||||
if (source.startsWith(QString("quotes/percpricechg"))) {
|
||||
QVariantHash data = extQuotes->itemByTagNumber(index(source))->run();
|
||||
foreach(QString key, data.keys()) values[key] = data[key];
|
||||
foreach (QString key, data.keys())
|
||||
values[key] = data[key];
|
||||
}
|
||||
QString key = QString(source).remove(QString("quotes/"));
|
||||
return values[key];
|
||||
@ -65,55 +66,73 @@ QVariantMap QuotesSource::initialData(QString source) const
|
||||
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("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("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("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("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("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("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("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("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("name")]
|
||||
= QString("Price changes for '%1'")
|
||||
.arg(extQuotes->itemByTagNumber(ind)->uniq());
|
||||
data[QString("type")] = QString("double");
|
||||
data[QString("units")] = QString("");
|
||||
}
|
||||
@ -135,16 +154,20 @@ QStringList QuotesSource::getSources()
|
||||
qCDebug(LOG_ESM);
|
||||
|
||||
QStringList sources;
|
||||
foreach(ExtQuotes *item, extQuotes->activeItems()) {
|
||||
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("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("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"))));
|
||||
sources.append(
|
||||
QString("quotes/%1").arg(item->tag(QString("pricechg"))));
|
||||
sources.append(
|
||||
QString("quotes/%1").arg(item->tag(QString("percpricechg"))));
|
||||
}
|
||||
|
||||
return sources;
|
||||
|
@ -33,7 +33,7 @@ public:
|
||||
virtual ~QuotesSource();
|
||||
QVariant data(QString source);
|
||||
QVariantMap initialData(QString source) const;
|
||||
void run() {};
|
||||
void run(){};
|
||||
QStringList sources() const;
|
||||
|
||||
private:
|
||||
|
@ -30,7 +30,7 @@ public:
|
||||
virtual ~UpdateSource();
|
||||
QVariant data(QString source);
|
||||
QVariantMap initialData(QString source) const;
|
||||
void run() {};
|
||||
void run(){};
|
||||
QStringList sources() const;
|
||||
};
|
||||
|
||||
|
@ -59,7 +59,9 @@ QVariantMap UpgradeSource::initialData(QString source) const
|
||||
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("name")]
|
||||
= QString("Package manager '%1' metadata")
|
||||
.arg(extUpgrade->itemByTagNumber(index(source))->uniq());
|
||||
data[QString("type")] = QString("QString");
|
||||
data[QString("units")] = QString("");
|
||||
|
||||
@ -80,8 +82,9 @@ QStringList UpgradeSource::getSources()
|
||||
qCDebug(LOG_ESM);
|
||||
|
||||
QStringList sources;
|
||||
foreach(ExtUpgrade *item, extUpgrade->activeItems())
|
||||
sources.append(QString("upgrade/%1").arg(item->tag(QString("pkgcount"))));
|
||||
foreach (ExtUpgrade *item, extUpgrade->activeItems())
|
||||
sources.append(
|
||||
QString("upgrade/%1").arg(item->tag(QString("pkgcount"))));
|
||||
|
||||
return sources;
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ public:
|
||||
virtual ~UpgradeSource();
|
||||
QVariant data(QString source);
|
||||
QVariantMap initialData(QString source) const;
|
||||
void run() {};
|
||||
void run(){};
|
||||
QStringList sources() const;
|
||||
|
||||
private:
|
||||
|
@ -48,7 +48,8 @@ QVariant WeatherSource::data(QString source)
|
||||
|
||||
if (source.startsWith(QString("weather/weatherId"))) {
|
||||
QVariantHash data = extWeather->itemByTagNumber(index(source))->run();
|
||||
foreach(QString key, data.keys()) values[key] = data[key];
|
||||
foreach (QString key, data.keys())
|
||||
values[key] = data[key];
|
||||
}
|
||||
QString key = QString(source).remove(QString("weather/"));
|
||||
return values[key];
|
||||
@ -65,31 +66,41 @@ QVariantMap WeatherSource::initialData(QString source) const
|
||||
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("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("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("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("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("name")]
|
||||
= QString("Temperature for '%1'")
|
||||
.arg(extWeather->itemByTagNumber(ind)->uniq());
|
||||
data[QString("type")] = QString("float");
|
||||
data[QString("units")] = QString("°C");
|
||||
}
|
||||
@ -111,12 +122,17 @@ 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"))));
|
||||
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;
|
||||
|
@ -33,7 +33,7 @@ public:
|
||||
virtual ~WeatherSource();
|
||||
QVariant data(QString source);
|
||||
QVariantMap initialData(QString source) const;
|
||||
void run() {};
|
||||
void run(){};
|
||||
QStringList sources() const;
|
||||
|
||||
private:
|
||||
|
Reference in New Issue
Block a user