From 7d5803fec8751ed546a94c2ac0a4413c99da92a6 Mon Sep 17 00:00:00 2001 From: arcan1s Date: Tue, 5 Nov 2013 23:01:34 +0400 Subject: [PATCH] Release ext-sysmon-1.3 + added music players support: amarok, mpd and qmmp --- ext-sysmon/extsysmon.cpp | 98 ++++++++++++++++-- ext-sysmon/extsysmon.h | 19 ++++ ext-sysmon/plasma-engine-extsysmon.desktop | 2 +- .../ext-sysmon-1.2.zip | Bin sources/contents/code/ptmnotify.py | 1 - 5 files changed, 112 insertions(+), 8 deletions(-) rename ext-sysmon-1.2.zip => old_versions/ext-sysmon-1.2.zip (100%) diff --git a/ext-sysmon/extsysmon.cpp b/ext-sysmon/extsysmon.cpp index 767b91a..051efe0 100644 --- a/ext-sysmon/extsysmon.cpp +++ b/ext-sysmon/extsysmon.cpp @@ -1,9 +1,29 @@ +/*************************************************************************** + * Copyright (C) 2013 by Evgeniy Alekseev * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + #include "extsysmon.h" #include #include + ExtendedSysMon::ExtendedSysMon(QObject* parent, const QVariantList& args) : Plasma::DataEngine(parent, args) { @@ -41,6 +61,7 @@ QStringList ExtendedSysMon::sources() const source.append(QString("gpu")); source.append(QString("gputemp")); source.append(QString("hddtemp")); + source.append(QString("player")); return source; } @@ -60,7 +81,7 @@ bool ExtendedSysMon::updateSourceEvent(const QString &source) key = QString("GPU"); if (gpudev == QString("nvidia")) { - f_out = popen("nvidia-smi -q -d UTILIZATION | grep Gpu | tail -n1 2>&1", "r"); + f_out = popen("nvidia-smi -q -d UTILIZATION 2> /dev/null | grep Gpu | tail -n1", "r"); fgets (output, 256, f_out); if ((output[0] == '\0') || (QString(output).split(QString(" "), QString::SkipEmptyParts).count() < 2)) @@ -75,7 +96,7 @@ bool ExtendedSysMon::updateSourceEvent(const QString &source) } else if (gpudev == QString("ati")) { - f_out = popen("aticonfig --od-getclocks | grep load | tail -n1 2>&1", "r"); + f_out = popen("aticonfig --od-getclocks 2> /dev/null | grep load | tail -n1", "r"); fgets (output, 256, f_out); if ((output[0] == '\0') || (QString(output).split(QString(" "), QString::SkipEmptyParts).count() < 3)) @@ -102,7 +123,7 @@ bool ExtendedSysMon::updateSourceEvent(const QString &source) key = QString("GPUTemp"); if (gpudev == QString("nvidia")) { - f_out = popen("nvidia-smi -q -d TEMPERATURE | grep Gpu | tail -n1 2>&1", "r"); + f_out = popen("nvidia-smi -q -d TEMPERATURE 2> /dev/null | grep Gpu | tail -n1", "r"); fgets (output, 256, f_out); if ((output[0] == '\0') || (QString(output).split(QString(" "), QString::SkipEmptyParts).count() < 2)) @@ -117,7 +138,7 @@ bool ExtendedSysMon::updateSourceEvent(const QString &source) } else if (gpudev == QString("ati")) { - f_out = popen("aticonfig --od-gettemperature | grep Temperature | tail -n1 2>&1", "r"); + f_out = popen("aticonfig --od-gettemperature 2> /dev/null | grep Temperature | tail -n1", "r"); fgets (output, 256, f_out); if ((output[0] == '\0') || (QString(output).split(QString(" "), QString::SkipEmptyParts).count() < 4)) @@ -147,7 +168,7 @@ bool ExtendedSysMon::updateSourceEvent(const QString &source) { qb = hdddev[i].toUtf8(); dev = qb.data(); - sprintf(command, "hddtemp %s", dev); + sprintf(command, "hddtemp %s 2> /dev/null", dev); f_out = popen(command, "r"); fgets(output, 256, f_out); if ((output[0] == '\0') || @@ -166,10 +187,75 @@ bool ExtendedSysMon::updateSourceEvent(const QString &source) setData(source, hdddev[i], value); } } + else if (source == QString("player")) + { + // qmmp + output[0] = '\0'; + key = QString("qmmp_artist"); + f_out = popen("qmmp --nowplaying '%if(%p,%p,Unknown)' 2> /dev/null", "r"); + fgets(output, 256, f_out); + if (output[0] == '\0') + value = QString("N\\A"); + else + value = QString(output).split(QString("\n"), QString::SkipEmptyParts)[0]; + pclose(f_out); + setData(source, key, value); + output[0] = '\0'; + key = QString("qmmp_title"); + f_out = popen("qmmp --nowplaying '%if(%t,%t,Unknown)' 2> /dev/null", "r"); + fgets(output, 256, f_out); + if (output[0] == '\0') + value = QString("N\\A"); + else + value = QString(output).split(QString("\n"), QString::SkipEmptyParts)[0]; + pclose(f_out); + setData(source, key, value); + // amarok + output[0] = '\0'; + key = QString("amarok_artist"); + f_out = popen("qdbus org.kde.amarok /Player GetMetadata 2> /dev/null | grep albumartist: | cut -c14-", "r"); + fgets(output, 256, f_out); + if (output[0] == '\0') + value = QString("N\\A"); + else + value = QString(output).split(QString("\n"), QString::SkipEmptyParts)[0]; + pclose(f_out); + setData(source, key, value); + output[0] = '\0'; + key = QString("amarok_title"); + f_out = popen("qdbus org.kde.amarok /Player GetMetadata 2> /dev/null | grep title: | cut -c8-", "r"); + fgets(output, 256, f_out); + if (output[0] == '\0') + value = QString("N\\A"); + else + value = QString(output).split(QString("\n"), QString::SkipEmptyParts)[0]; + pclose(f_out); + setData(source, key, value); + // mpd + QString value_artist; + value = QString("N\\A"); + value_artist = QString("N\\A"); + f_out = popen("echo 'currentsong\nclose' | curl --connect-timeout 1 -fsm 3 telnet://localhost:6600 2> /dev/null", "r"); + while (true) + { + fgets(output, 256, f_out); + if (feof (f_out)) + break; + if (QString(output).split(QString(": "), QString::SkipEmptyParts)[0] == QString("Artist")) + value_artist = QString(output).split(QString(": "), QString::SkipEmptyParts)[1].split(QString("\n"), QString::SkipEmptyParts)[0]; + else if (QString(output).split(QString(": "), QString::SkipEmptyParts)[0] == QString("Title")) + value = QString(output).split(QString(": "), QString::SkipEmptyParts)[1].split(QString("\n"), QString::SkipEmptyParts)[0]; + } + pclose(f_out); + key = QString("mpd_artist"); + setData(source, key, value_artist); + key = QString("mpd_title"); + setData(source, key, value); + } return true; } K_EXPORT_PLASMA_DATAENGINE(extsysmon, ExtendedSysMon) -#include "extsysmon.moc" +#include "extsysmon.moc" diff --git a/ext-sysmon/extsysmon.h b/ext-sysmon/extsysmon.h index 5a38081..c82646d 100644 --- a/ext-sysmon/extsysmon.h +++ b/ext-sysmon/extsysmon.h @@ -1,3 +1,22 @@ +/*************************************************************************** + * Copyright (C) 2013 by Evgeniy Alekseev * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + #ifndef EXTSYSMON_H #define EXTSYSMON_H diff --git a/ext-sysmon/plasma-engine-extsysmon.desktop b/ext-sysmon/plasma-engine-extsysmon.desktop index 693a027..8b41988 100644 --- a/ext-sysmon/plasma-engine-extsysmon.desktop +++ b/ext-sysmon/plasma-engine-extsysmon.desktop @@ -13,7 +13,7 @@ X-Plasma-EngineName=ext-sysmon X-KDE-PluginInfo-Author=Evgeniy Alekseev aka arcanis X-KDE-PluginInfo-Email=esalexeev@gmail.com X-KDE-PluginInfo-Name=ext-sysmon -X-KDE-PluginInfo-Version=1.2 +X-KDE-PluginInfo-Version=1.3 X-KDE-PluginInfo-Category=System Information X-KDE-PluginInfo-Depends= X-KDE-PluginInfo-License=GPL diff --git a/ext-sysmon-1.2.zip b/old_versions/ext-sysmon-1.2.zip similarity index 100% rename from ext-sysmon-1.2.zip rename to old_versions/ext-sysmon-1.2.zip diff --git a/sources/contents/code/ptmnotify.py b/sources/contents/code/ptmnotify.py index 9f02df1..991a199 100644 --- a/sources/contents/code/ptmnotify.py +++ b/sources/contents/code/ptmnotify.py @@ -43,7 +43,6 @@ class PTMNotify: output = commands.getoutput("grep 'model name' /proc/cpuinfo | head -1") text = text + "Model: %s\n" %(' '.join(output.split()[3:])) output = commands.getoutput("sar -u | tail -1") - print "1" text = text + "CPU Usage: %s%%\n" %(str(100-float(output.split()[-1]))) output = commands.getoutput("grep MHz /proc/cpuinfo | head -1") text = text + "CPU Freq: %s MHz\n" %(str(int(float(output.split()[-1]))))