Release ext-sysmon-1.3

+ added music players support: amarok, mpd and qmmp
This commit is contained in:
arcan1s 2013-11-05 23:01:34 +04:00
parent 60f1cd8c58
commit 7d5803fec8
5 changed files with 112 additions and 8 deletions

View File

@ -1,9 +1,29 @@
/***************************************************************************
* Copyright (C) 2013 by Evgeniy Alekseev <esalekseev@gmail.com> *
* *
* 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 "extsysmon.h"
#include <Plasma/DataContainer> #include <Plasma/DataContainer>
#include <stdio.h> #include <stdio.h>
ExtendedSysMon::ExtendedSysMon(QObject* parent, const QVariantList& args) ExtendedSysMon::ExtendedSysMon(QObject* parent, const QVariantList& args)
: Plasma::DataEngine(parent, args) : Plasma::DataEngine(parent, args)
{ {
@ -41,6 +61,7 @@ QStringList ExtendedSysMon::sources() const
source.append(QString("gpu")); source.append(QString("gpu"));
source.append(QString("gputemp")); source.append(QString("gputemp"));
source.append(QString("hddtemp")); source.append(QString("hddtemp"));
source.append(QString("player"));
return source; return source;
} }
@ -60,7 +81,7 @@ bool ExtendedSysMon::updateSourceEvent(const QString &source)
key = QString("GPU"); key = QString("GPU");
if (gpudev == QString("nvidia")) 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); fgets (output, 256, f_out);
if ((output[0] == '\0') || if ((output[0] == '\0') ||
(QString(output).split(QString(" "), QString::SkipEmptyParts).count() < 2)) (QString(output).split(QString(" "), QString::SkipEmptyParts).count() < 2))
@ -75,7 +96,7 @@ bool ExtendedSysMon::updateSourceEvent(const QString &source)
} }
else if (gpudev == QString("ati")) 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); fgets (output, 256, f_out);
if ((output[0] == '\0') || if ((output[0] == '\0') ||
(QString(output).split(QString(" "), QString::SkipEmptyParts).count() < 3)) (QString(output).split(QString(" "), QString::SkipEmptyParts).count() < 3))
@ -102,7 +123,7 @@ bool ExtendedSysMon::updateSourceEvent(const QString &source)
key = QString("GPUTemp"); key = QString("GPUTemp");
if (gpudev == QString("nvidia")) 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); fgets (output, 256, f_out);
if ((output[0] == '\0') || if ((output[0] == '\0') ||
(QString(output).split(QString(" "), QString::SkipEmptyParts).count() < 2)) (QString(output).split(QString(" "), QString::SkipEmptyParts).count() < 2))
@ -117,7 +138,7 @@ bool ExtendedSysMon::updateSourceEvent(const QString &source)
} }
else if (gpudev == QString("ati")) 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); fgets (output, 256, f_out);
if ((output[0] == '\0') || if ((output[0] == '\0') ||
(QString(output).split(QString(" "), QString::SkipEmptyParts).count() < 4)) (QString(output).split(QString(" "), QString::SkipEmptyParts).count() < 4))
@ -147,7 +168,7 @@ bool ExtendedSysMon::updateSourceEvent(const QString &source)
{ {
qb = hdddev[i].toUtf8(); qb = hdddev[i].toUtf8();
dev = qb.data(); dev = qb.data();
sprintf(command, "hddtemp %s", dev); sprintf(command, "hddtemp %s 2> /dev/null", dev);
f_out = popen(command, "r"); f_out = popen(command, "r");
fgets(output, 256, f_out); fgets(output, 256, f_out);
if ((output[0] == '\0') || if ((output[0] == '\0') ||
@ -166,6 +187,71 @@ bool ExtendedSysMon::updateSourceEvent(const QString &source)
setData(source, hdddev[i], value); 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; return true;
} }

View File

@ -1,3 +1,22 @@
/***************************************************************************
* Copyright (C) 2013 by Evgeniy Alekseev <esalekseev@gmail.com> *
* *
* 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 #ifndef EXTSYSMON_H
#define EXTSYSMON_H #define EXTSYSMON_H

View File

@ -13,7 +13,7 @@ X-Plasma-EngineName=ext-sysmon
X-KDE-PluginInfo-Author=Evgeniy Alekseev aka arcanis X-KDE-PluginInfo-Author=Evgeniy Alekseev aka arcanis
X-KDE-PluginInfo-Email=esalexeev@gmail.com X-KDE-PluginInfo-Email=esalexeev@gmail.com
X-KDE-PluginInfo-Name=ext-sysmon 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-Category=System Information
X-KDE-PluginInfo-Depends= X-KDE-PluginInfo-Depends=
X-KDE-PluginInfo-License=GPL X-KDE-PluginInfo-License=GPL

View File

@ -43,7 +43,6 @@ class PTMNotify:
output = commands.getoutput("grep 'model name' /proc/cpuinfo | head -1") output = commands.getoutput("grep 'model name' /proc/cpuinfo | head -1")
text = text + "Model: %s\n" %(' '.join(output.split()[3:])) text = text + "Model: %s\n" %(' '.join(output.split()[3:]))
output = commands.getoutput("sar -u | tail -1") output = commands.getoutput("sar -u | tail -1")
print "1"
text = text + "CPU Usage: %s%%\n" %(str(100-float(output.split()[-1]))) text = text + "CPU Usage: %s%%\n" %(str(100-float(output.split()[-1])))
output = commands.getoutput("grep MHz /proc/cpuinfo | head -1") output = commands.getoutput("grep MHz /proc/cpuinfo | head -1")
text = text + "CPU Freq: %s MHz\n" %(str(int(float(output.split()[-1])))) text = text + "CPU Freq: %s MHz\n" %(str(int(float(output.split()[-1]))))