fix bugs caused by integration

This commit is contained in:
arcan1s 2015-09-10 04:59:35 +03:00
parent 9e45b02c8e
commit bf5c500938
14 changed files with 191 additions and 604 deletions

View File

@ -8,7 +8,7 @@ ProjectRootRelative=./
[CMake][CMake Build Directory 0]
Build Directory Path=file:///home/arcanis/Documents/github/awesome-widgets/build
Build Type=Release
Build Type=Debug
CMake Binary=file:///usr/bin/cmake
Environment Profile=
Extra Arguments=

View File

@ -93,14 +93,11 @@ Item {
onNewData: {
if (debug) console.debug("Update source", sourceName)
systemmonitorDE.interval = plasmoid.configuration.interval
awKeys.dataUpdateReceived(sourceName, data, settings)
}
onSourceAdded: {
if (debug) console.debug("Source", source)
awKeys.addDevice(source)
}
}
@ -113,8 +110,7 @@ Item {
onNewData: {
if (debug) console.debug("Update source", sourceName)
extsysmonDE.interval = plasmoid.configuration.interval
// extsysmonDE.interval = plasmoid.configuration.interval
awKeys.dataUpdateReceived(sourceName, data, settings)
}
}
@ -127,7 +123,6 @@ Item {
onNewData: {
if (debug) console.debug("Update source", sourceName)
awKeys.dataUpdateReceived(sourceName, data, settings)
}
}

View File

@ -644,10 +644,6 @@ QString AWKeys::parsePattern() const
void AWKeys::setDataBySource(const QString sourceName, const QVariantMap data,
const QVariantMap params)
{
if (lock) {
lock = (queue > 1);
return;
}
qCDebug(LOG_AW);
qCDebug(LOG_AW) << "Source" << sourceName;
qCDebug(LOG_AW) << "Data" << data;
@ -669,25 +665,24 @@ void AWKeys::setDataBySource(const QString sourceName, const QVariantMap data,
QRegExp mountUsedRegExp = QRegExp(QString("partitions/.*/usedspace"));
QRegExp netRegExp = QRegExp(QString("network/interfaces/.*/(receiver|transmitter)/data$"));
if (sourceName == QString("battery")) {
// battery
foreach(QString key, data.keys()) {
if (key == QString("ac")) {
// notification
if ((values[QString("ac")] == params[QString("acOnline")].toString()) != data[QString("ac")].toBool()) {
if (data[QString("ac")].toBool())
if (sourceName == QString("battery/ac")) {
// AC
if ((values[QString("ac")] == params[QString("acOnline")].toString()) != data[QString("value")].toBool()) {
if (data[QString("value")].toBool())
AWActions::sendNotification(QString("event"), i18n("AC online"), enablePopup);
else
AWActions::sendNotification(QString("event"), i18n("AC offline"), enablePopup);
}
// value
if (data[QString("ac")].toBool())
if (data[QString("value")].toBool())
values[QString("ac")] = params[QString("acOnline")].toString();
else
values[QString("ac")] = params[QString("acOffline")].toString();
} else
values[key] = QString("%1").arg(data[key].toFloat(), 3, 'f', 0);
}
} else if (sourceName.startsWith(QString("battery/"))) {
// battery stats
QString key = sourceName;
key.remove(QString("battery/"));
values[key] = QString("%1").arg(data[QString("value")].toInt(), 3);
} else if (sourceName == QString("cpu/system/TotalLoad")) {
// cpu
// notification
@ -708,14 +703,20 @@ void AWKeys::setDataBySource(const QString sourceName, const QVariantMap data,
QString number = sourceName;
number.remove(QString("cpu/cpu")).remove(QString("/clock"));
values[QString("cpucl") + number] = QString("%1").arg(data[QString("value")].toFloat(), 4, 'f', 0);
} else if (sourceName == QString("custom")) {
} else if (sourceName.startsWith(QString("custom"))) {
// custom
foreach(QString key, data.keys()) values[key] = data[key].toString();
} else if (sourceName == QString("desktop")) {
// desktops
values[QString("desktop")] = data[QString("currentName")].toString();
values[QString("ndesktop")] = QString("%1").arg(data[QString("currentNumber")].toInt());
values[QString("tdesktops")] = QString("%1").arg(data[QString("number")].toInt());
QString key = sourceName;
key.remove(QString("custom/"));
values[key] = data[QString("value")].toString();
} else if (sourceName == QString("desktop/current/name")) {
// current desktop name
values[QString("desktop")] = data[QString("value")].toString();
} else if (sourceName == QString("desktop/current/number")) {
// current desktop number
values[QString("ndesktop")] = QString("%1").arg(data[QString("value")].toInt());
} else if (sourceName == QString("desktop/total/number")) {
// desktop count
values[QString("tdesktops")] = QString("%1").arg(data[QString("value")].toInt());
} else if (sourceName.contains(hddrRegExp)) {
// read speed
QString device = sourceName;
@ -728,14 +729,14 @@ void AWKeys::setDataBySource(const QString sourceName, const QVariantMap data,
device.remove(QString("/Rate/wblk"));
int index = diskDevices.indexOf(device);
values[QString("hddw%1").arg(index)] = QString("%1").arg(data[QString("value")].toFloat(), 5, 'f', 0);
} else if (sourceName == QString("gpu")) {
} else if (sourceName == QString("gpu/load")) {
// gpu load
// notification
if ((data[QString("value")].toFloat() >= 75.0) && (values[QString("gpu")].toFloat() < 75.0))
AWActions::sendNotification(QString("event"), i18n("High GPU load"), enablePopup);
// value
values[QString("gpu")] = QString("%1").arg(data[QString("value")].toFloat(), 5, 'f', 1);
} else if (sourceName == QString("gputemp")) {
} else if (sourceName == QString("gpu/temperature")) {
// gpu temperature
values[QString("gputemp")] = QString("%1").arg(
temperature(data[QString("value")].toFloat(), params[QString("tempUnits")].toString()), 4, 'f', 1);
@ -772,13 +773,13 @@ void AWKeys::setDataBySource(const QString sourceName, const QVariantMap data,
values[QString("hddtotgb%1").arg(index)] = QString("%1").arg(
values[QString("hddfreegb%1").arg(index)].toFloat() +
values[QString("hddgb%1").arg(index)].toFloat(), 5, 'f', 1);
} else if (sourceName == QString("hddtemp")) {
} else if (sourceName.startsWith(QString("hdd/temperature"))) {
// hdd temperature
foreach(QString key, data.keys()) {
int index = hddDevices.indexOf(key);
QString device = sourceName;
device.remove(QString("hdd/temperature"));
int index = hddDevices.indexOf(device);
values[QString("hddtemp%1").arg(index)] = QString("%1").arg(
temperature(data[key].toFloat(), params[QString("tempUnits")].toString()), 4, 'f', 1);
}
temperature(data[QString("value")].toFloat(), params[QString("tempUnits")].toString()), 4, 'f', 1);
} else if (sourceName.startsWith(QString("cpu/system/loadavg"))) {
// load average
QString time = sourceName;
@ -808,7 +809,7 @@ void AWKeys::setDataBySource(const QString sourceName, const QVariantMap data,
AWActions::sendNotification(QString("event"), i18n("High memory usage"), enablePopup);
// value
values[QString("mem")] = QString("%1").arg(value, 5, 'f', 1);
} else if (sourceName == QString("netdev")) {
} else if (sourceName == QString("network/current/name")) {
// network device
// notification
if (values[QString("netdev")] != data[QString("value")].toString())
@ -843,20 +844,30 @@ void AWKeys::setDataBySource(const QString sourceName, const QVariantMap data,
values[type] = simplifiedValue;
values[QString("%1units").arg(type)] = units;
}
} else if (sourceName == QString("pkg")) {
} else if (sourceName.startsWith(QString("upgrade"))) {
// package manager
foreach(QString key, data.keys()) values[key] = QString("%1").arg(data[key].toInt(), 2);
} else if (sourceName == QString("player")) {
QString key = sourceName;
key.remove(QString("upgrade/"));
values[key] = QString("%1").arg(data[QString("value")].toInt(), 2);
} else if (sourceName.startsWith(QString("player"))) {
// player
foreach(QString key, data.keys()) values[key] = data[key].toString();
} else if (sourceName == QString("ps")) {
// ps
values[QString("ps")] = data[QString("ps")].toString();
values[QString("pscount")] = QString("%1").arg(data[QString("pscount")].toInt(), 2);
values[QString("pstotal")] = QString("%1").arg(data[QString("pstotal")].toInt(), 3);
} else if (sourceName == QString("quotes")) {
QString key = sourceName;
key.remove(QString("player/"));
values[key] = data[QString("value")].toString();
} else if (sourceName == QString("ps/running/count")) {
// running processes count
values[QString("pscount")] = QString("%1").arg(data[QString("value")].toInt(), 2);
} else if (sourceName == QString("ps/running/list")) {
// list of running processes
values[QString("ps")] = data[QString("value")].toStringList().join(QChar(','));
} else if (sourceName == QString("ps/total/count")) {
// total processes count
values[QString("pstotal")] = QString("%1").arg(data[QString("value")].toInt(), 3);
} else if (sourceName.startsWith(QString("quotes"))) {
// quotes
foreach(QString key, data.keys()) values[key] = QString("%1").arg(data[key].toFloat(), 7, 'f');
QString key = sourceName;
key.remove(QString("quotes/"));
values[key] = QString("%1").arg(data[QString("value")].toFloat(), 7, 'f');
} else if (sourceName == QString("mem/swap/free")) {
// free swap
values[QString("swapfreemb")] = QString("%1").arg(data[QString("value")].toFloat() / 1024.0, 5, 'f', 0);
@ -911,20 +922,33 @@ void AWKeys::setDataBySource(const QString sourceName, const QVariantMap data,
values[QString("cuptime")].replace(QString("$h"), QString("%1").arg(hours));
values[QString("cuptime")].replace(QString("$mm"), QString("%1").arg(minutes, 2, 10, QChar('0')));
values[QString("cuptime")].replace(QString("$m"), QString("%1").arg(minutes));
} else if (sourceName == QString("weather")) {
foreach(QString key, data.keys()) {
if (key.startsWith(QString("weatherId")))
values[key] = QString("%1").arg(data[key].toInt(), 3);
else if (key.startsWith(QString("weather")))
values[key] = data[key].toString();
else if (key.startsWith(QString("humidity")))
values[key] = QString("%1").arg(data[key].toInt(), 3);
else if (key.startsWith(QString("pressure")))
values[key] = QString("%1").arg(data[key].toInt(), 4);
else if (key.startsWith(QString("temperature")))
values[key] = QString("%1").arg(
temperature(data[key].toFloat(), params[QString("tempUnits")].toString()), 4, 'f', 1);
}
} else if (sourceName.startsWith(QString("weather/weatherId"))) {
// weather ID
QString key = sourceName;
key.remove(QString("weather/"));
values[key] = QString("%1").arg(data[QString("value")].toInt(), 3);
} else if (sourceName.startsWith(QString("weather/weather"))) {
// weather
QString key = sourceName;
key.remove(QString("weather/"));
values[key] = data[QString("value")].toString();
} else if (sourceName.startsWith(QString("weather/humidity"))) {
// humidity
QString key = sourceName;
key.remove(QString("weather/"));
values[key] = QString("%1").arg(data[QString("value")].toInt(), 3);
} else if (sourceName.startsWith(QString("weather/pressure"))) {
// pressure
QString key = sourceName;
key.remove(QString("weather/"));
values[key] = QString("%1").arg(data[QString("value")].toInt(), 4);
} else if (sourceName.startsWith(QString("weather/temperature"))) {
// temperature
QString key = sourceName;
key.remove(QString("weather/"));
values[key] = QString("%1").arg(temperature(data[QString("value")].toFloat(),
params[QString("tempUnits")].toString()),
4, 'f', 1);
} else {
qCDebug(LOG_AW) << "Source" << sourceName << "not found";
emit(dropSourceFromDataengine(sourceName));

View File

@ -91,7 +91,6 @@ private:
ExtItemAggregator<ExtScript> *extScripts;
ExtItemAggregator<ExtUpgrade> *extUpgrade;
ExtItemAggregator<ExtWeather> *extWeather;
bool lock = false;
int queue = 0;
QString pattern;
QStringList foundBars, foundKeys, foundLambdas;

View File

@ -17,28 +17,14 @@
#include "extsysmon.h"
#include <KWindowSystem>
#include <Plasma/DataContainer>
#include <QDBusArgument>
#include <QDBusConnection>
#include <QDBusConnectionInterface>
#include <QDBusMessage>
#include <QDir>
#include <QFile>
#include <QNetworkInterface>
#include <QRegExp>
#include <QTextCodec>
#include <QSettings>
#include <QStandardPaths>
#include <task/taskadds.h>
#include "awdebug.h"
#include "extquotes.h"
#include "extscript.h"
#include "extupgrade.h"
#include "extweather.h"
#include "extsysmonaggregator.h"
#include "version.h"
@ -54,10 +40,10 @@ ExtendedSysMon::ExtendedSysMon(QObject *parent, const QVariantList &args)
setMinimumPollingInterval(333);
readConfiguration();
extQuotes = new ExtItemAggregator<ExtQuotes>(nullptr, QString("quotes"));
extScripts = new ExtItemAggregator<ExtScript>(nullptr, QString("scripts"));
extUpgrade = new ExtItemAggregator<ExtUpgrade>(nullptr, QString("upgrade"));
extWeather = new ExtItemAggregator<ExtWeather>(nullptr, QString("weather"));
// aggregator init
aggregator = new ExtSysMonAggregator(this, configuration);
foreach(QString source, aggregator->sources())
setData(source, aggregator->initialData(source));
}
@ -65,366 +51,7 @@ ExtendedSysMon::~ExtendedSysMon()
{
qCDebug(LOG_ESM);
delete extQuotes;
delete extScripts;
delete extUpgrade;
delete extWeather;
}
QVariantHash ExtendedSysMon::getBattery(const QString acpiPath) const
{
qCDebug(LOG_ESM);
qCDebug(LOG_ESM) << "ACPI path" << acpiPath;
QVariantHash battery;
battery[QString("ac")] = false;
battery[QString("bat")] = 0;
// adaptor
QFile acFile(QString("%1/AC/online").arg(acpiPath));
if (acFile.open(QIODevice::ReadOnly)) {
if (QString(acFile.readLine()).trimmed().toInt() == 1)
battery[QString("ac")] = true;
}
acFile.close();
// batterites
float currentLevel = 0.0;
float fullLevel = 0.0;
QStringList batDevices = QDir(acpiPath).entryList(QStringList() << QString("BAT*"),
QDir::Dirs | QDir::NoDotAndDotDot,
QDir::Name);
for (int i=0; i<batDevices.count(); i++) {
QFile currentLevelFile(QString("%1/%2/energy_now").arg(acpiPath).arg(batDevices.at(i)));
QFile fullLevelFile(QString("%1/%2/energy_full").arg(acpiPath).arg(batDevices.at(i)));
if ((currentLevelFile.open(QIODevice::ReadOnly)) &&
(fullLevelFile.open(QIODevice::ReadOnly))) {
float batCurrent = QString(currentLevelFile.readLine()).trimmed().toFloat();
float batFull = QString(fullLevelFile.readLine()).trimmed().toFloat();
battery[QString("bat%1").arg(i)] = static_cast<int>(100 * batCurrent / batFull);
currentLevel += batCurrent;
fullLevel += batFull;
}
currentLevelFile.close();
fullLevelFile.close();
}
battery[QString("bat")] = static_cast<int>(100 * currentLevel / fullLevel);
return battery;
}
QVariantHash ExtendedSysMon::getCurrentDesktop() const
{
qCDebug(LOG_ESM);
int number = KWindowSystem::currentDesktop();
int total = KWindowSystem::numberOfDesktops();
QVariantHash currentDesktop;
currentDesktop[QString("currentName")] = KWindowSystem::desktopName(number);
currentDesktop[QString("currentNumber")] = number;
currentDesktop[QString("list")] = QStringList();
for (int i=1; i<total+1; i++)
currentDesktop[QString("list")].toStringList().append(KWindowSystem::desktopName(i));
currentDesktop[QString("number")] = total;
return currentDesktop;
}
float ExtendedSysMon::getGpu(const QString device) const
{
qCDebug(LOG_ESM);
qCDebug(LOG_ESM) << "Device" << device;
float value = 0.0;
if ((device != QString("nvidia")) && (device != QString("ati")))
return value;
QString cmd = QString("");
if (device == QString("nvidia"))
cmd = QString("nvidia-smi -q -x");
else if (device == QString("ati"))
cmd = 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;
QString qoutput = QTextCodec::codecForMib(106)->toUnicode(process.output).trimmed();
if (configuration[QString("GPUDEV")] == 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 (configuration[QString("GPUDEV")] == 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 value;
}
float ExtendedSysMon::getGpuTemp(const QString device) const
{
qCDebug(LOG_ESM);
qCDebug(LOG_ESM) << "Device" << device;
float value = 0.0;
if ((device != QString("nvidia")) && (device != QString("ati")))
return value;
QString cmd = QString("");
if (device == QString("nvidia"))
cmd = QString("nvidia-smi -q -x");
else if (device == QString("ati"))
cmd = 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;
QString qoutput = QTextCodec::codecForMib(106)->toUnicode(process.output);
if (configuration[QString("GPUDEV")] == 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 (configuration[QString("GPUDEV")] == 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 value;
}
float ExtendedSysMon::getHddTemp(const QString cmd, const QString device) const
{
qCDebug(LOG_ESM);
qCDebug(LOG_ESM) << "cmd" << cmd;
qCDebug(LOG_ESM) << "Device" << device;
float value = 0.0;
TaskResult process = runTask(QString("%1 %2").arg(cmd).arg(device));
qCInfo(LOG_ESM) << "Cmd returns" << process.exitCode;
qCInfo(LOG_ESM) << "Error" << process.error;
bool smartctl = cmd.contains(QString("smartctl"));
qCInfo(LOG_ESM) << "Parse as smartctl" << smartctl;
QString qoutput = QTextCodec::codecForMib(106)->toUnicode(process.output).trimmed();
if (smartctl) {
foreach(QString str, qoutput.split(QChar('\n'), QString::SkipEmptyParts)) {
if (!str.startsWith(QString("194"))) continue;
if (str.split(QChar(' '), QString::SkipEmptyParts).count() < 9) break;
value = str.split(QChar(' '), QString::SkipEmptyParts).at(9).toFloat();
break;
}
} else {
if (qoutput.split(QChar(':'), QString::SkipEmptyParts).count() >= 3) {
QString temp = qoutput.split(QChar(':'), QString::SkipEmptyParts).at(2);
temp.remove(QChar(0260)).remove(QChar('C'));
value = temp.toFloat();
}
}
return value;
}
QString ExtendedSysMon::getNetworkDevice() const
{
qCDebug(LOG_ESM);
QString device = QString("lo");
QList<QNetworkInterface> rawInterfaceList = QNetworkInterface::allInterfaces();
qCInfo(LOG_ESM) << "Devices" << rawInterfaceList;
foreach(QNetworkInterface interface, rawInterfaceList)
if ((interface.flags().testFlag(QNetworkInterface::IsUp)) &&
(!interface.flags().testFlag(QNetworkInterface::IsLoopBack)) &&
(!interface.flags().testFlag(QNetworkInterface::IsPointToPoint))) {
device = interface.name();
break;
}
return device;
}
QVariantHash ExtendedSysMon::getPlayerInfo(const QString playerName, const QString mpdAddress,
const QString mpdPort, QString mpris) const
{
qCDebug(LOG_ESM);
qCDebug(LOG_ESM) << "player" << playerName;
qCDebug(LOG_ESM) << "MPD" << QString("%1:%2").arg(mpdAddress).arg(mpdPort);
qCDebug(LOG_ESM) << "MPRIS" << mpris;
QVariantHash info;
info[QString("album")] = QString("unknown");
info[QString("artist")] = QString("unknown");
info[QString("duration")] = QString("0");
info[QString("progress")] = QString("0");
info[QString("title")] = QString("unknown");
if (playerName == QString("mpd"))
// mpd
info = getPlayerMpdInfo(mpdAddress, mpdPort);
else if (playerName == QString("mpris")) {
// players which supports mpris
if (mpris == QString("auto")) mpris = getAutoMpris();
if (mpris.isEmpty()) return info;
info = getPlayerMprisInfo(mpris);
}
// dymanic properties
// solid
info[QString("salbum")] = stripString(info[QString("album")].toString(), symbols);
info[QString("sartist")] = stripString(info[QString("artist")].toString(), symbols);
info[QString("stitle")] = stripString(info[QString("title")].toString(), symbols);
// dynamic
Plasma::DataContainer *playerDC = containerDict()["player"];
QVariantHash data = playerDC == nullptr ? info : qvariant_cast<QVariantHash>(playerDC->data());
info[QString("dalbum")] = buildString(data[QString("dalbum")].toString(),
info[QString("album")].toString(), symbols);
info[QString("dartist")] = buildString(data[QString("dartist")].toString(),
info[QString("artist")].toString(), symbols);
info[QString("dtitle")] = buildString(data[QString("dtitle")].toString(),
info[QString("title")].toString(), symbols);
return info;
}
QVariantHash ExtendedSysMon::getPlayerMpdInfo(const QString mpdAddress, const QString mpdPort) const
{
qCDebug(LOG_ESM);
qCDebug(LOG_ESM) << "MPD" << QString("%1:%2").arg(mpdAddress).arg(mpdPort);
QVariantHash info;
info[QString("album")] = QString("unknown");
info[QString("artist")] = QString("unknown");
info[QString("duration")] = QString("0");
info[QString("progress")] = QString("0");
info[QString("title")] = QString("unknown");
QString cmd = QString("bash -c \"echo 'currentsong\nstatus\nclose' | curl --connect-timeout 1 -fsm 3 telnet://%1:%2\"")
.arg(mpdAddress)
.arg(mpdPort);
qCInfo(LOG_ESM) << "cmd" << cmd;
TaskResult process = runTask(cmd);
qCInfo(LOG_ESM) << "Cmd returns" << process.exitCode;
qCInfo(LOG_ESM) << "Error" << process.error;
QString qoutput = QTextCodec::codecForMib(106)->toUnicode(process.output).trimmed();
foreach(QString str, qoutput.split(QChar('\n'), QString::SkipEmptyParts)) {
if (str.split(QString(": "), QString::SkipEmptyParts).count() > 1) {
if (str.split(QString(": "), QString::SkipEmptyParts).first() == QString("Album"))
info[QString("album")] = str.split(QString(": "), QString::SkipEmptyParts)[1].trimmed();
else if (str.split(QString(": "), QString::SkipEmptyParts).first() == QString("Artist"))
info[QString("artist")] = str.split(QString(": "), QString::SkipEmptyParts)[1].trimmed();
else if (str.split(QString(": "), QString::SkipEmptyParts).first() == QString("time")) {
info[QString("duration")] = str.split(QString(": "), QString::SkipEmptyParts)[1].trimmed().split(QString(":"))[0];
info[QString("progress")] = str.split(QString(": "), QString::SkipEmptyParts)[1].trimmed().split(QString(":"))[1];
} else if (str.split(QString(": "), QString::SkipEmptyParts).first() == QString("Title"))
info[QString("title")] = str.split(QString(": "), QString::SkipEmptyParts)[1].trimmed();
}
}
return info;
}
QVariantHash ExtendedSysMon::getPlayerMprisInfo(const QString mpris) const
{
qCDebug(LOG_ESM);
qCDebug(LOG_ESM) << "MPRIS" << mpris;
QVariantHash info;
info[QString("album")] = QString("unknown");
info[QString("artist")] = QString("unknown");
info[QString("duration")] = 0;
info[QString("progress")] = 0;
info[QString("title")] = QString("unknown");
QDBusConnection bus = QDBusConnection::sessionBus();
// comes from the following request:
// qdbus org.mpris.MediaPlayer2.vlc /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get org.mpris.MediaPlayer2.Player Metadata
// or the same but using dbus-send:
// dbus-send --print-reply --session --dest=org.mpris.MediaPlayer2.vlc /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Metadata'
QVariantList args = QVariantList() << QString("org.mpris.MediaPlayer2.Player") << QString("Metadata");
QDBusMessage request = QDBusMessage::createMethodCall(QString("org.mpris.MediaPlayer2.%1").arg(mpris),
QString("/org/mpris/MediaPlayer2"),
QString(""),
QString("Get"));
request.setArguments(args);
QDBusMessage response = bus.call(request, QDBus::BlockWithGui);
if ((response.type() != QDBusMessage::ReplyMessage) || (response.arguments().isEmpty())) {
qCWarning(LOG_ESM) << "Error message" << response.errorMessage();
} else {
// another portion of dirty magic
QVariantHash map = qdbus_cast<QVariantHash>(response.arguments().first()
.value<QDBusVariant>().variant()
.value<QDBusArgument>());
info[QString("album")] = map.value(QString("xesam:album"), QString("unknown"));
// artist is array
info[QString("artist")] = map.value(QString("xesam:artist"), QString("unknown")).toString();
info[QString("duration")] = map.value(QString("mpris:length"), 0).toInt() / (1000 * 1000);
info[QString("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("progress")] = response.arguments().first().value<QDBusVariant>()
.variant().toLongLong() / (1000 * 1000);
return info;
}
QVariantHash ExtendedSysMon::getPsStats() const
{
qCDebug(LOG_ESM);
QStringList allDirectories = QDir(QString("/proc")).entryList(QDir::Dirs | QDir::NoDotAndDotDot,
QDir::Name);
QStringList directories = allDirectories.filter(QRegExp(QString("(\\d+)")));
QStringList running;
foreach(QString dir, directories) {
QFile statusFile(QString("/proc/%1/status").arg(dir));
if (!statusFile.open(QIODevice::ReadOnly)) continue;
QFile cmdFile(QString("/proc/%1/cmdline").arg(dir));
if (!cmdFile.open(QIODevice::ReadOnly)) continue;
QString output = statusFile.readAll();
if (output.contains(QString("running"))) running.append(cmdFile.readAll());
}
QVariantHash psStats;
psStats[QString("pscount")] = running.count();
psStats[QString("ps")] = running.join(QChar(','));
psStats[QString("pstotal")] = directories.count();
return psStats;
delete aggregator;
}
@ -432,23 +59,7 @@ QStringList ExtendedSysMon::sources() const
{
qCDebug(LOG_ESM);
QStringList source;
source.append(QString("battery"));
source.append(QString("custom"));
source.append(QString("desktop"));
source.append(QString("netdev"));
source.append(QString("gpu"));
source.append(QString("gputemp"));
source.append(QString("hddtemp"));
source.append(QString("pkg"));
source.append(QString("player"));
source.append(QString("ps"));
source.append(QString("quotes"));
source.append(QString("update"));
source.append(QString("weather"));
qCInfo(LOG_ESM) << "Sources" << source;
return source;
return aggregator->sources();
}
@ -466,55 +77,8 @@ bool ExtendedSysMon::updateSourceEvent(const QString &source)
qCDebug(LOG_ESM);
qCDebug(LOG_ESM) << "Source" << source;
if (source == QString("battery")) {
QVariantHash battery = getBattery(configuration[QString("ACPIPATH")]);
foreach(QString key, battery.keys()) setData(source, key, battery[key]);
} else if (source == QString("custom")) {
foreach(ExtScript *script, extScripts->activeItems()) {
QVariantHash data = script->run();
foreach(QString key, data.keys()) setData(source, key, data[key]);
}
} else if (source == QString("desktop")) {
QVariantHash desktop = getCurrentDesktop();
foreach(QString key, desktop.keys()) setData(source, key, desktop[key]);
} else if (source == QString("gpu")) {
setData(source, QString("value"), getGpu(configuration[QString("GPUDEV")]));
} else if (source == QString("gputemp")) {
setData(source, QString("value"), getGpuTemp(configuration[QString("GPUDEV")]));
} else if (source == QString("hddtemp")) {
QStringList deviceList = configuration[QString("HDDDEV")].split(QChar(','), QString::SkipEmptyParts);
QStringList allHddDevices = getAllHdd();
foreach(QString device, allHddDevices)
setData(source, device, deviceList.contains(device) ?
getHddTemp(configuration[QString("HDDTEMPCMD")], device) : 0.0);
} else if (source == QString("netdev")) {
setData(source, QString("value"), getNetworkDevice());
} else if (source == QString("pkg")) {
foreach(ExtUpgrade *upgrade, extUpgrade->activeItems()) {
QVariantHash data = upgrade->run();
foreach(QString key, data.keys()) setData(source, key, data[key]);
}
} else if (source == QString("player")) {
QVariantHash player = getPlayerInfo(configuration[QString("PLAYER")],
configuration[QString("MPDADDRESS")],
configuration[QString("MPDPORT")],
configuration[QString("MPRIS")]);
foreach(QString key, player.keys()) setData(source, key, player[key]);
} else if (source == QString("ps")) {
QVariantHash ps = getPsStats();
foreach(QString key, ps.keys()) setData(source, key, ps[key]);
} else if (source == QString("quotes")) {
foreach(ExtQuotes *quote, extQuotes->activeItems()) {
QVariantHash data = quote->run();
foreach(QString key, data.keys()) setData(source, key, data[key]);
}
} else if (source == QString("update")) {
setData(source, QString("value"), true);
} else if (source == QString("weather")) {
foreach(ExtWeather *weather, extWeather->activeItems()) {
QVariantHash data = weather->run();
foreach(QString key, data.keys()) setData(source, key, data[key]);
}
if (aggregator->hasSource(source)) {
setData(source, QString("value"), aggregator->data(source));
} else {
qCWarning(LOG_ESM) << "Unknown source" << source;
return false;
@ -524,22 +88,6 @@ bool ExtendedSysMon::updateSourceEvent(const QString &source)
}
QString ExtendedSysMon::buildString(const QString current, const QString value,
const int s) const
{
qCDebug(LOG_ESM);
qCDebug(LOG_ESM) << "Current value" << current;
qCDebug(LOG_ESM) << "New value" << value;
qCDebug(LOG_ESM) << "Strip after" << s;
int index = value.indexOf(current);
if ((current.isEmpty()) || ((index + s + 1) > value.count()))
return QString("%1").arg(value.left(s), s, QLatin1Char(' '));
else
return QString("%1").arg(value.mid(index + 1, s), s, QLatin1Char(' '));
}
QStringList ExtendedSysMon::getAllHdd() const
{
qCDebug(LOG_ESM);
@ -573,26 +121,6 @@ QString ExtendedSysMon::getAutoGpu() const
}
QString ExtendedSysMon::getAutoMpris() const
{
qCDebug(LOG_ESM);
QDBusMessage listServices = QDBusConnection::sessionBus().interface()->call(QDBus::BlockWithGui, QString("ListNames"));
if (listServices.arguments().isEmpty()) return QString();
QStringList arguments = listServices.arguments().first().toStringList();
foreach(QString arg, arguments) {
qCInfo(LOG_ESM) << "Service found" << arg;
if (!arg.startsWith(QString("org.mpris.MediaPlayer2."))) continue;
QString service = arg;
service.remove(QString("org.mpris.MediaPlayer2."));
return service;
}
return QString();
}
void ExtendedSysMon::readConfiguration()
{
qCDebug(LOG_ESM);
@ -616,18 +144,6 @@ void ExtendedSysMon::readConfiguration()
settings.endGroup();
configuration = updateConfiguration(rawConfig);
symbols = configuration[QString("PLAYERSYMBOLS")].toInt();
}
QString ExtendedSysMon::stripString(const QString value, const int s) const
{
qCDebug(LOG_ESM);
qCDebug(LOG_ESM) << "New value" << value;
qCDebug(LOG_ESM) << "Strip after" << s;
return value.count() > s ? QString("%1\u2026").arg(value.left(s - 1)) :
QString("%1").arg(value, s, QLatin1Char(' '));
}

View File

@ -20,13 +20,8 @@
#include <Plasma/DataEngine>
#include "extitemaggregator.h"
class ExtQuotes;
class ExtScript;
class ExtUpgrade;
class ExtWeather;
class ExtSysMonAggregator;
class ExtendedSysMon : public Plasma::DataEngine
{
@ -35,21 +30,6 @@ class ExtendedSysMon : public Plasma::DataEngine
public:
explicit ExtendedSysMon(QObject *parent, const QVariantList &args);
virtual ~ExtendedSysMon();
// update functions
QVariantHash getBattery(const QString acpiPath) const;
QVariantHash getCurrentDesktop() const;
float getGpu(const QString device) const;
float getGpuTemp(const QString device) const;
float getHddTemp(const QString cmd, const QString device) const;
QString getNetworkDevice() const;
QVariantHash getPlayerInfo(const QString playerName,
const QString mpdAddress = QString(),
const QString mpdPort = QString(),
const QString mpris = QString()) const;
QVariantHash getPlayerMpdInfo(const QString mpdAddress = QString(),
const QString mpdPort = QString()) const;
QVariantHash getPlayerMprisInfo(const QString mpris = QString()) const;
QVariantHash getPsStats() const;
protected:
QStringList sources() const;
@ -58,19 +38,12 @@ protected:
private:
// configuration
ExtSysMonAggregator *aggregator = nullptr;
QHash<QString, QString> configuration;
int symbols = 10;
ExtItemAggregator<ExtQuotes> *extQuotes;
ExtItemAggregator<ExtScript> *extScripts;
ExtItemAggregator<ExtUpgrade> *extUpgrade;
ExtItemAggregator<ExtWeather> *extWeather;
// methods
QString buildString(const QString current, const QString value, const int s) const;
QStringList getAllHdd() const;
QString getAutoGpu() const;
QString getAutoMpris() const;
void readConfiguration();
QString stripString(const QString value, const int s) const;
QHash<QString, QString> updateConfiguration(QHash<QString, QString> rawConfig) const;
};

View File

@ -18,6 +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/networksource.h"
#include "sources/playersource.h"
#include "sources/processessource.h"
#include "sources/quotessource.h"
#include "sources/updatesource.h"
#include "sources/upgradesource.h"
#include "sources/weathersource.h"
ExtSysMonAggregator::ExtSysMonAggregator(QObject *parent, const QHash<QString, QString> config)
@ -42,7 +55,7 @@ QVariant ExtSysMonAggregator::data(const QString source) const
qCDebug(LOG_ESM);
qCDebug(LOG_ESM) << "Source" << source;
return m_map.contains(source) ? m_map[source]->data(source) : QVariant();
return hasSource(source) ? m_map[source]->data(source) : QVariant();
}
@ -51,7 +64,13 @@ AbstractExtSysMonSource *ExtSysMonAggregator::engine(const QString source)
qCDebug(LOG_ESM);
qCDebug(LOG_ESM) << "Source" << source;
return m_map.contains(source) ? m_map[source] : nullptr;
return hasSource(source) ? m_map[source] : nullptr;
}
bool ExtSysMonAggregator::hasSource(const QString source) const
{
return m_map.contains(source);
}
@ -60,7 +79,7 @@ QVariantMap ExtSysMonAggregator::initialData(const QString source) const
qCDebug(LOG_ESM);
qCDebug(LOG_ESM) << "Source" << source;
return m_map.contains(source) ? m_map[source]->initialData(source) : QVariantMap();
return hasSource(source) ? m_map[source]->initialData(source) : QVariantMap();
}
@ -68,11 +87,69 @@ QStringList ExtSysMonAggregator::sources() const
{
qCDebug(LOG_ESM);
return m_map.keys();
QStringList sorted = m_map.keys();
sorted.sort();
return sorted;
}
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())
m_map[source] = batteryItem;
// custom
AbstractExtSysMonSource *customItem = new CustomSource(this, QStringList());
foreach(QString source, customItem->sources())
m_map[source] = customItem;
// desktop
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())
m_map[source] = gpuLoadItem;
// gpu temperature
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())
m_map[source] = hddTempItem;
// network
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())
m_map[source] = playerItem;
// processes
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())
m_map[source] = quotesItem;
// update
AbstractExtSysMonSource *updateItem = new UpdateSource(this, QStringList());
foreach(QString source, updateItem->sources())
m_map[source] = updateItem;
// upgrade
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())
m_map[source] = weatherItem;
}

View File

@ -32,6 +32,7 @@ public:
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;

View File

@ -71,7 +71,7 @@ QVariantMap BatterySource::initialData(QString source) const
} else {
data[QString("min")] = 0;
data[QString("max")] = 100;
data[QString("name")] = QString("Battery %1 usage").arg(source.remove(QString("battery/bat")));
data[QString("name")] = QString("Battery %1 usage").arg(index(source));
data[QString("type")] = QString("integer");
data[QString("units")] = QString("%");
}

View File

@ -31,7 +31,7 @@ HDDTemperatureSource::HDDTemperatureSource(QObject *parent, const QStringList ar
Q_ASSERT(args.count() == 2);
qCDebug(LOG_ESM);
m_devices = args.at(0).split(QChar(','));
m_devices = args.at(0).split(QChar(','), QString::SkipEmptyParts);
m_cmd = args.at(1);
m_smartctl = m_cmd.contains(QString("smartctl"));

View File

@ -235,15 +235,16 @@ QVariantHash PlayerSource::getPlayerMpdInfo(const QString mpdAddress) const
QString qoutput = QTextCodec::codecForMib(106)->toUnicode(process.output).trimmed();
foreach(QString str, qoutput.split(QChar('\n'), QString::SkipEmptyParts)) {
if (str.split(QString(": "), QString::SkipEmptyParts).count() == 1) {
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();
if (metadata == QString("time")) {
// there are one more time...
if ((metadata == QString("time")) && (data.contains(QChar(':')))) {
QStringList times = data.split(QString(":"));
info[QString("player/duration")] = times.at(0).toInt();
info[QString("player/progress")] = times.at(1).toInt();
} else if (metadata == QString("Title")) {
} else if (m_metadata.contains(metadata)) {
info[QString("player/%1").arg(metadata)] = data;
}
}

View File

@ -45,6 +45,7 @@ private:
QString m_mpris;
QString m_player;
int m_symbols;
QStringList m_metadata = QStringList() << QString("album") << QString("artist") << QString("title");
QVariantHash values;
};

View File

@ -50,7 +50,7 @@ QVariantMap UpdateSource::initialData(QString source) const
qCDebug(LOG_ESM) << "Source" << source;
QVariantMap data;
if (source == QString("desktop/current/name")) {
if (source == QString("update")) {
data[QString("min")] = true;
data[QString("max")] = true;
data[QString("name")] = QString("Simple value which is always true");

View File

@ -78,7 +78,7 @@ QVariantMap WeatherSource::initialData(QString source) const
data[QString("name")] = QString("Humidity for '%1'").arg(extWeather->itemByTagNumber(ind)->uniq());
data[QString("type")] = QString("integer");
data[QString("units")] = QString("%");
} else if (source.startsWith(QString("weather/humidity"))) {
} 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());