diff --git a/sources/ext-sysmon/extsysmon.conf b/sources/ext-sysmon/extsysmon.conf index f3de900..7287428 100644 --- a/sources/ext-sysmon/extsysmon.conf +++ b/sources/ext-sysmon/extsysmon.conf @@ -18,6 +18,10 @@ #MPDADDRESS=localhost #MPDPORT=6600 +# MPRIS player name or 'auto'. In the most cases it should be a player name +# DBus path is org.mpris.MediaPlayer2.amarok +#MPRIS=auto + # Package upgrade info ## from vicious ## Arch: PKGCMD=pacman -Qu PKGNULL=0 @@ -31,5 +35,5 @@ # Number of null lines for commands, comma separated #PKGNULL=0 -# Player name. Supported players are amarok, clementine, mpd, qmmp -#PLAYER=amarok +# Player name. Supported players are 'mpd', 'mpris' +#PLAYER=mpris diff --git a/sources/ext-sysmon/extsysmon.cpp b/sources/ext-sysmon/extsysmon.cpp index 7041de3..11f6678 100644 --- a/sources/ext-sysmon/extsysmon.cpp +++ b/sources/ext-sysmon/extsysmon.cpp @@ -52,6 +52,7 @@ ExtendedSysMon::ExtendedSysMon(QObject* parent, const QVariantList& args) QString ExtendedSysMon::getAllHdd() { if (debug) qDebug() << "[DE]" << "[getAllHdd]"; + QProcess command; QStringList devices; QString cmd = QString("find /dev -name [hms]d[a-z]"); @@ -64,6 +65,7 @@ QString ExtendedSysMon::getAllHdd() for (int i=0; itoUnicode(command.readAllStandardOutput()).trimmed(); + mpris = cmdOutput.split(QChar('\n'))[0].split(QChar('.'))[3]; + + if (debug) qDebug() << "[DE]" << "[getAutoMpris]" << ":" << "Player found" << mpris; + return mpris; +} + + QStringList ExtendedSysMon::getDesktopNames() { if (debug) qDebug() << "[DE]" << "[getDesktopNames]"; + QStringList list; QString fileName = KGlobal::dirs()->findResource("config", "kwinrc"); if (debug) qDebug() << "[DE]" << "[getDesktopNames]" << ":" << "Configuration file" << fileName; @@ -120,6 +143,7 @@ QStringList ExtendedSysMon::getDesktopNames() if (configFile.atEnd()) break; } configFile.close(); + return list; } @@ -127,6 +151,7 @@ QStringList ExtendedSysMon::getDesktopNames() QStringList ExtendedSysMon::sources() const { if (debug) qDebug() << "[DE]" << "[sources]"; + QStringList source; source.append(QString("custom")); source.append(QString("desktop")); @@ -137,6 +162,7 @@ QStringList ExtendedSysMon::sources() const source.append(QString("player")); source.append(QString("ps")); if (debug) qDebug() << "[DE]" << "[sources]" << ":" << "Sources" << source; + return source; } @@ -144,6 +170,7 @@ QStringList ExtendedSysMon::sources() const void ExtendedSysMon::initValues() { if (debug) qDebug() << "[DE]" << "[initValues]"; + QStringList sourceList = sources(); for (int i=0; i rawConfig; rawConfig[QString("CUSTOM")] = QString("wget -qO- http://ifconfig.me/ip"); @@ -163,9 +191,10 @@ void ExtendedSysMon::readConfiguration() rawConfig[QString("HDDTEMPCMD")] = QString("sudo hddtemp"); rawConfig[QString("MPDADDRESS")] = QString("localhost"); rawConfig[QString("MPDPORT")] = QString("6600"); + rawConfig[QString("MPRIS")] = QString("auto"); rawConfig[QString("PKGCMD")] = QString("pacman -Qu"); rawConfig[QString("PKGNULL")] = QString("0"); - rawConfig[QString("PLAYER")] = QString("amarok"); + rawConfig[QString("PLAYER")] = QString("mpris"); QString fileName = KGlobal::dirs()->findResource("config", "extsysmon.conf"); if (debug) qDebug() << "[DE]" << "[readConfiguration]" << ":" << "Configuration file" << fileName; @@ -190,6 +219,7 @@ void ExtendedSysMon::readConfiguration() if (configFile.atEnd()) break; } configFile.close(); + configuration = updateConfiguration(rawConfig); } @@ -197,6 +227,7 @@ void ExtendedSysMon::readConfiguration() void ExtendedSysMon::setKeys() { if (debug) qDebug() << "[DE]" << "[setKeys]"; + QString key, source; // custom source = QString("custom"); @@ -254,6 +285,7 @@ void ExtendedSysMon::setKeys() setData(source, key, QString("")); key = QString("psTotal"); setData(source, key, QString("0")); + // initialization of values initValues(); } @@ -262,6 +294,7 @@ void ExtendedSysMon::setKeys() void ExtendedSysMon::setProcesses() { if (debug) qDebug() << "[DE]" << "[setProcesses]"; + // custom for (int i=0; i ExtendedSysMon::updateConfiguration(const QMap rawConfig) { if (debug) qDebug() << "[DE]" << "[updateConfiguration]"; + QMap config; QString key, value; // remove spaces and copy source map @@ -358,15 +392,14 @@ QMap ExtendedSysMon::updateConfiguration(const QMapstate() != QProcess::Running) && (processes[QString("desktop")][0]->state() != QProcess::Starting)) processes[QString("desktop")][0]->start(QString("bash -c \"") + cmd + QString("\"")); @@ -385,9 +419,9 @@ void ExtendedSysMon::getCurrentDesktop(const QString cmd) void ExtendedSysMon::setCurrentDesktop(int exitCode, QProcess::ExitStatus exitStatus) { Q_UNUSED(exitStatus) - if (debug) qDebug() << "[DE]" << "[setCurrentDesktop]"; if (debug) qDebug() << "[DE]" << "[setCurrentDesktop]" << ":" << "Cmd returns" << exitCode; + QString qoutput = QTextCodec::codecForMib(106)->toUnicode(processes[QString("desktop")][0]->readAllStandardOutput()).trimmed(); int number = qoutput.toInt(); QString key, source, value; @@ -410,6 +444,7 @@ void ExtendedSysMon::getCustomCmd(const QString cmd, const int number) if (debug) qDebug() << "[DE]" << "[getCustomCmd]" << ":" << "Run function with cmd" << cmd; if (debug) qDebug() << "[DE]" << "[getCustomCmd]" << ":" << "Run function with number" << number; if (debug) qDebug() << "[DE]" << "[getCustomCmd]" << ":" << "Run cmd" << QString("bash -c \"") + cmd + QString("\""); + if ((processes[QString("custom")][number]->state() != QProcess::Running) && (processes[QString("custom")][number]->state() != QProcess::Starting)) processes[QString("custom")][number]->start(QString("bash -c \"") + cmd + QString("\"")); @@ -419,9 +454,9 @@ void ExtendedSysMon::getCustomCmd(const QString cmd, const int number) void ExtendedSysMon::setCustomCmd(int exitCode, QProcess::ExitStatus exitStatus) { Q_UNUSED(exitStatus) - if (debug) qDebug() << "[DE]" << "[setCustomCmd]"; if (debug) qDebug() << "[DE]" << "[setCustomCmd]" << ":" << "Cmd returns" << exitCode; + for (int i=0; itoUnicode(processes[QString("custom")][i]->readAllStandardOutput()).trimmed(); @@ -440,6 +475,7 @@ void ExtendedSysMon::getGpu(const QString device) { if (debug) qDebug() << "[DE]" << "[getGpu]"; if (debug) qDebug() << "[DE]" << "[getGpu]" << ":" << "Run function with device" << device; + if ((device != QString("nvidia")) && (device != QString("ati"))) return; QString cmd = QString(""); @@ -457,9 +493,9 @@ void ExtendedSysMon::getGpu(const QString device) void ExtendedSysMon::setGpu(int exitCode, QProcess::ExitStatus exitStatus) { Q_UNUSED(exitStatus) - if (debug) qDebug() << "[DE]" << "[setGpu]"; if (debug) qDebug() << "[DE]" << "[setGpu]" << ":" << "Cmd returns" << exitCode; + float value = 0.0; QString qoutput; if (configuration[QString("GPUDEV")] == QString("nvidia")) { @@ -487,6 +523,7 @@ void ExtendedSysMon::setGpu(int exitCode, QProcess::ExitStatus exitStatus) if (debug) qDebug() << "[DE]" << "[setGpu]" << ":" << "Return" << value; QString source = QString("gpu"); QString key = QString("GPU"); + setData(source, key, value); } @@ -495,6 +532,7 @@ void ExtendedSysMon::getGpuTemp(const QString device) { if (debug) qDebug() << "[DE]" << "[getGpuTemp]"; if (debug) qDebug() << "[DE]" << "[getGpuTemp]" << ":" << "Run function with device" << device; + if ((device != QString("nvidia")) && (device != QString("ati"))) return; QString cmd = QString(""); @@ -512,9 +550,9 @@ void ExtendedSysMon::getGpuTemp(const QString device) void ExtendedSysMon::setGpuTemp(int exitCode, QProcess::ExitStatus exitStatus) { Q_UNUSED(exitStatus) - if (debug) qDebug() << "[DE]" << "[setGpuTemp]"; if (debug) qDebug() << "[DE]" << "[setGpuTemp]" << ":" << "Cmd returns" << exitCode; + float value = 0.0; QString qoutput; if (configuration[QString("GPUDEV")] == QString("nvidia")) { @@ -540,6 +578,7 @@ void ExtendedSysMon::setGpuTemp(int exitCode, QProcess::ExitStatus exitStatus) if (debug) qDebug() << "[DE]" << "[setGpuTemp]" << ":" << "Return" << value; QString source = QString("gputemp"); QString key = QString("GPUTemp"); + setData(source, key, value); } @@ -551,6 +590,7 @@ void ExtendedSysMon::getHddTemp(const QString cmd, const QString device, const i if (debug) qDebug() << "[DE]" << "[getHddTemp]" << ":" << "Run function with device" << device; if (debug) qDebug() << "[DE]" << "[getHddTemp]" << ":" << "Run function with number" << number; if (debug) qDebug() << "[DE]" << "[getHddTemp]" << ":" << "Run cmd" << cmd + QString(" ") + device; + if ((processes[QString("hddtemp")][number]->state() != QProcess::Running) && (processes[QString("hddtemp")][number]->state() != QProcess::Starting)) processes[QString("hddtemp")][number]->start(cmd + QString(" ") + device); @@ -560,9 +600,9 @@ void ExtendedSysMon::getHddTemp(const QString cmd, const QString device, const i void ExtendedSysMon::setHddTemp(int exitCode, QProcess::ExitStatus exitStatus) { Q_UNUSED(exitStatus) - if (debug) qDebug() << "[DE]" << "[setHddTemp]"; if (debug) qDebug() << "[DE]" << "[setHddTemp]" << ":" << "Cmd returns" << exitCode; + for (int i=0; istate() != QProcess::Running) && (processes[QString("player")][0]->state() != QProcess::Starting)) @@ -613,9 +654,9 @@ void ExtendedSysMon::getPlayerInfo(const QString playerName, void ExtendedSysMon::setPlayer(int exitCode, QProcess::ExitStatus exitStatus) { Q_UNUSED(exitStatus) - if (debug) qDebug() << "[DE]" << "[setPlayer]"; if (debug) qDebug() << "[DE]" << "[setPlayer]" << ":" << "Cmd returns" << exitCode; + QString playerName = configuration[QString("PLAYER")]; QString qoutput = QString(""); QString qstr = QString(""); @@ -630,7 +671,25 @@ void ExtendedSysMon::setPlayer(int exitCode, QProcess::ExitStatus exitStatus) info.append(QString("0")); // title info.append(QString("unknown")); - if (playerName == QString("amarok")) { + if (playerName == QString("mpd")) { + qoutput = QTextCodec::codecForMib(106)->toUnicode(processes[QString("player")][0]->readAllStandardOutput()); + for (int i=0; i 1) { + if (qstr.split(QString(": "), QString::SkipEmptyParts)[0] == QString("Album")) + info[0] = qstr.split(QString(": "), QString::SkipEmptyParts)[1].trimmed(); + else if (qstr.split(QString(": "), QString::SkipEmptyParts)[0] == QString("Artist")) + info[1] = qstr.split(QString(": "), QString::SkipEmptyParts)[1].trimmed(); + else if (qstr.split(QString(": "), QString::SkipEmptyParts)[0] == QString("time")) { + info[3] = qstr.split(QString(": "), QString::SkipEmptyParts)[1].trimmed().split(QString(":"))[0]; + info[2] = qstr.split(QString(": "), QString::SkipEmptyParts)[1].trimmed().split(QString(":"))[1]; + } + else if (qstr.split(QString(": "), QString::SkipEmptyParts)[0] == QString("Title")) + info[4] = qstr.split(QString(": "), QString::SkipEmptyParts)[1].trimmed(); + } + } + } + else if (playerName == QString("mpris")) { qoutput = QTextCodec::codecForMib(106)->toUnicode(processes[QString("player")][0]->readAllStandardOutput()); if (!qoutput.isEmpty()) { for (int i=0; itoUnicode(processes[QString("player")][0]->readAllStandardOutput()); - if (!qoutput.isEmpty()) { - for (int i=0; i 1) { - if (qstr.split(QString(": "), QString::SkipEmptyParts)[0] == QString("album")) - info[0] = qstr.split(QString(": "), QString::SkipEmptyParts)[1].trimmed(); - else if (qstr.split(QString(": "), QString::SkipEmptyParts)[0] == QString("artist")) - info[1] = qstr.split(QString(": "), QString::SkipEmptyParts)[1].trimmed(); - else if (qstr.split(QString(": "), QString::SkipEmptyParts)[0] == QString("time")) - info[3] = qstr.split(QString(": "), QString::SkipEmptyParts)[1].trimmed(); - else if (qstr.split(QString(": "), QString::SkipEmptyParts)[0] == QString("title")) - info[4] = qstr.split(QString(": "), QString::SkipEmptyParts)[1].trimmed(); - } - else { - int time = qstr.toInt() / 1000; - info[2] = QString::number(time); - } - } - } - } - else if (playerName == QString("mpd")) { - qoutput = QTextCodec::codecForMib(106)->toUnicode(processes[QString("player")][0]->readAllStandardOutput()); - for (int i=0; i 1) { - if (qstr.split(QString(": "), QString::SkipEmptyParts)[0] == QString("Album")) - info[0] = qstr.split(QString(": "), QString::SkipEmptyParts)[1].trimmed(); - else if (qstr.split(QString(": "), QString::SkipEmptyParts)[0] == QString("Artist")) - info[1] = qstr.split(QString(": "), QString::SkipEmptyParts)[1].trimmed(); - else if (qstr.split(QString(": "), QString::SkipEmptyParts)[0] == QString("time")) { - info[3] = qstr.split(QString(": "), QString::SkipEmptyParts)[1].trimmed().split(QString(":"))[0]; - info[2] = qstr.split(QString(": "), QString::SkipEmptyParts)[1].trimmed().split(QString(":"))[1]; - } - else if (qstr.split(QString(": "), QString::SkipEmptyParts)[0] == QString("Title")) - info[4] = qstr.split(QString(": "), QString::SkipEmptyParts)[1].trimmed(); - } - } - } - else if (playerName == QString("qmmp")) { - qoutput = QTextCodec::codecForMib(106)->toUnicode(processes[QString("player")][0]->readAllStandardOutput()); - for (int i=0; itoUnicode(processes[QString("ps")][i]->readAllStandardOutput()).trimmed(); @@ -785,6 +785,7 @@ void ExtendedSysMon::getUpgradeInfo(const QString pkgCommand, const int number) if (debug) qDebug() << "[DE]" << "[getUpgradeInfo]"; if (debug) qDebug() << "[DE]" << "[getUpgradeInfo]" << ":" << "Run function with cmd" << pkgCommand; if (debug) qDebug() << "[DE]" << "[getUpgradeInfo]" << ":" << "Run function with number" << number; + QString cmd = QString("bash -c \"") + pkgCommand + QString(" | wc -l\""); if (debug) qDebug() << "[DE]" << "[getUpgradeInfo]" << ":" << "Run cmd" << cmd; if ((processes[QString("pkg")][number]->state() != QProcess::Running) && @@ -796,9 +797,9 @@ void ExtendedSysMon::getUpgradeInfo(const QString pkgCommand, const int number) void ExtendedSysMon::setUpgradeInfo(int exitCode, QProcess::ExitStatus exitStatus) { Q_UNUSED(exitStatus) - if (debug) qDebug() << "[DE]" << "[setUpgradeInfo]"; if (debug) qDebug() << "[DE]" << "[setUpgradeInfo]" << ":" << "Cmd returns" << exitCode; + for (int i=0; i 0): pos = self.configpage['widget'].sliders[self.defaults['order'][label]].value() - 1 @@ -224,7 +225,7 @@ class ConfigDefinition: deSettings = {'CUSTOM':'wget -qO- http://ifconfig.me/ip', 'DESKTOPCMD':'qdbus org.kde.kwin /KWin currentDesktop', 'GPUDEV':'auto', 'HDDDEV':'all', 'HDDTEMPCMD':'sudo hddtemp', 'MPDADDRESS':'localhost', - 'MPDPORT':'6600', 'PKGCMD':'pacman -Qu', 'PKGNULL':'0', 'PLAYER':'amarok'} + 'MPDPORT':'6600', 'MPRIS':'auto', 'PKGCMD':'pacman -Qu', 'PKGNULL':'0', 'PLAYER':'mpris'} dataengineConfig = unicode(KGlobal.dirs().localkdedir()) + "/share/config/extsysmon.conf" try: with open(dataengineConfig, 'r') as deConfigFile: @@ -252,6 +253,8 @@ class ConfigDefinition: self.configpage['dataengine'].ui.lineEdit_mpdaddress.setText(deSettings['MPDADDRESS']) self.configpage['dataengine'].ui.spinBox_mpdport.setValue(int(deSettings['MPDPORT'])) self.configpage['dataengine'].ui.spinBox_mpdport.setValue(int(deSettings['MPDPORT'])) + index = self.configpage['dataengine'].ui.comboBox_mpris.findText(deSettings['MPRIS']) + self.configpage['dataengine'].ui.comboBox_mpris.setCurrentIndex(index) self.configpage['dataengine'].ui.listWidget_pkgCommand.clear() for i in range(len(deSettings['PKGCMD'].split(','))): try: diff --git a/sources/ptm/contents/ui/deconfig.ui b/sources/ptm/contents/ui/deconfig.ui index 9eb18ad..c11f736 100644 --- a/sources/ptm/contents/ui/deconfig.ui +++ b/sources/ptm/contents/ui/deconfig.ui @@ -288,7 +288,7 @@ del - remove item - + @@ -403,7 +403,7 @@ del - remove item - + @@ -434,12 +434,7 @@ del - remove item - amarok - - - - - clementine + mpris @@ -447,16 +442,11 @@ del - remove item mpd - - - qmmp - - - + Qt::Vertical @@ -493,6 +483,96 @@ del - remove item + + + + + + <b>NOTE:</b> Player DBus interface should be an active + + + Qt::AlignCenter + + + + + + + + + + 200 + 0 + + + + MPRIS player name + + + + + + + + 0 + 0 + + + + + 100 + 0 + + + + true + + + + auto + + + + + amarok + + + + + audacious + + + + + clementine + + + + + deadbeef + + + + + vlc + + + + + qmmp + + + + + xmms2 + + + + + + + + @@ -510,6 +590,7 @@ del - remove item lineEdit_hddtempCmd lineEdit_mpdaddress spinBox_mpdport + comboBox_mpris comboBox_pkgCommand spinBox_pkgCommandNum pushButton_pkgCommand