mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-25 07:57:19 +00:00
add mpris support
This commit is contained in:
parent
edf3a72564
commit
5ea8c97094
@ -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
|
||||
|
@ -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; i<qoutput.split(QChar('\n'), QString::SkipEmptyParts).count(); i++)
|
||||
devices.append(qoutput.split(QChar('\n'), QString::SkipEmptyParts)[i]);
|
||||
if (debug) qDebug() << "[DE]" << "[getAllHdd]" << ":" << "Device list" << devices;
|
||||
|
||||
return devices.join(QChar(','));
|
||||
}
|
||||
|
||||
@ -71,6 +73,7 @@ QString ExtendedSysMon::getAllHdd()
|
||||
QString ExtendedSysMon::getAutoGpu()
|
||||
{
|
||||
if (debug) qDebug() << "[DE]" << "[getAutoGpu]";
|
||||
|
||||
QProcess command;
|
||||
QString gpu = QString("disable");
|
||||
QString cmd = QString("lspci");
|
||||
@ -85,13 +88,33 @@ QString ExtendedSysMon::getAutoGpu()
|
||||
else if (qoutput.toLower().contains("radeon"))
|
||||
gpu = QString("ati");
|
||||
if (debug) qDebug() << "[DE]" << "[getAutoGpu]" << ":" << "Device" << gpu;
|
||||
|
||||
return gpu;
|
||||
}
|
||||
|
||||
|
||||
QString ExtendedSysMon::getAutoMpris()
|
||||
{
|
||||
if (debug) qDebug() << "[DE]" << "[getAutoMpris]";
|
||||
|
||||
QProcess command;
|
||||
QString mpris;
|
||||
QString cmd = QString("bash -c \"qdbus 'org.mpris.MediaPlayer2.*'\"");
|
||||
if (debug) qDebug() << "[DE]" << "[getAutoMpris]" << ":" << "Run cmd" << cmd;
|
||||
command.start(cmd);
|
||||
command.waitForFinished(-1);
|
||||
QString cmdOutput = QTextCodec::codecForMib(106)->toUnicode(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<sourceList.count(); i++)
|
||||
sourceRequestEvent(sourceList[i]);
|
||||
@ -153,6 +180,7 @@ void ExtendedSysMon::initValues()
|
||||
void ExtendedSysMon::readConfiguration()
|
||||
{
|
||||
if (debug) qDebug() << "[DE]" << "[readConfiguration]";
|
||||
|
||||
// pre-setup
|
||||
QMap<QString, QString> 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<configuration[QString("CUSTOM")].split(QString("@@"), QString::SkipEmptyParts).count(); i++) {
|
||||
processes[QString("custom")].append(new QProcess);
|
||||
@ -309,6 +342,7 @@ void ExtendedSysMon::setProcesses()
|
||||
QMap<QString, QString> ExtendedSysMon::updateConfiguration(const QMap<QString, QString> rawConfig)
|
||||
{
|
||||
if (debug) qDebug() << "[DE]" << "[updateConfiguration]";
|
||||
|
||||
QMap<QString, QString> config;
|
||||
QString key, value;
|
||||
// remove spaces and copy source map
|
||||
@ -358,15 +392,14 @@ QMap<QString, QString> ExtendedSysMon::updateConfiguration(const QMap<QString, Q
|
||||
i++)
|
||||
config[QString("PKGNULL")] += QString(",0");
|
||||
// player
|
||||
if ((config[QString("PLAYER")] != QString("amarok")) &&
|
||||
(config[QString("PLAYER")] != QString("clementine")) &&
|
||||
(config[QString("PLAYER")] != QString("mpd")) &&
|
||||
(config[QString("PLAYER")] != QString("qmmp")))
|
||||
config[QString("PLAYER")] = QString("amarok");
|
||||
if ((config[QString("PLAYER")] != QString("mpd")) &&
|
||||
(config[QString("PLAYER")] != QString("mpris")))
|
||||
config[QString("PLAYER")] = QString("mpris");
|
||||
|
||||
for (int i=0; i<config.keys().count(); i++)
|
||||
if (debug) qDebug() << "[DE]" << "[updateConfiguration]" << ":" <<
|
||||
config.keys()[i] + QString("=") + config[config.keys()[i]];
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
@ -376,6 +409,7 @@ void ExtendedSysMon::getCurrentDesktop(const QString cmd)
|
||||
if (debug) qDebug() << "[DE]" << "[getCurrentDesktop]";
|
||||
if (debug) qDebug() << "[DE]" << "[getCurrentDesktop]" << ":" << "Run function with cmd" << cmd;
|
||||
if (debug) qDebug() << "[DE]" << "[getCurrentDesktop]" << ":" << "Run cmd" << QString("bash -c \"") + cmd + QString("\"");
|
||||
|
||||
if ((processes[QString("desktop")][0]->state() != 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; i<processes[QString("custom")].count(); i++) {
|
||||
QString value = QString("");
|
||||
value = QTextCodec::codecForMib(106)->toUnicode(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; i<processes[QString("hddtemp")].count(); i++) {
|
||||
float value = 0.0;
|
||||
QString qoutput = QString("");
|
||||
@ -583,26 +623,27 @@ void ExtendedSysMon::setHddTemp(int exitCode, QProcess::ExitStatus exitStatus)
|
||||
|
||||
void ExtendedSysMon::getPlayerInfo(const QString playerName,
|
||||
const QString mpdAddress,
|
||||
const QString mpdPort)
|
||||
const QString mpdPort,
|
||||
QString mpris)
|
||||
{
|
||||
if (debug) qDebug() << "[DE]" << "[getPlayerInfo]";
|
||||
if (debug) qDebug() << "[DE]" << "[getPlayerInfo]" << ":" << "Run function with player" << playerName;
|
||||
if (debug) qDebug() << "[DE]" << "[getPlayerInfo]" << ":" << "Run function with MPD parameters" <<
|
||||
mpdAddress + QString(":") + mpdPort;
|
||||
if (debug) qDebug() << "[DE]" << "[getPlayerInfo]" << ":" << "Run function with MPRIS" << mpris;
|
||||
|
||||
QString cmd;
|
||||
if (playerName == QString("amarok"))
|
||||
// amarok
|
||||
cmd = QString("bash -c \"qdbus org.kde.amarok /Player GetMetadata && qdbus org.kde.amarok /Player PositionGet\"");
|
||||
else if (playerName == QString("clementine"))
|
||||
// clementine
|
||||
cmd = QString("bash -c \"qdbus org.mpris.clementine /Player GetMetadata && qdbus org.mpris.clementine /Player PositionGet\"");
|
||||
else if (playerName == QString("mpd"))
|
||||
if (playerName == QString("mpd"))
|
||||
// mpd
|
||||
cmd = QString("bash -c \"echo 'currentsong\nstatus\nclose' | curl --connect-timeout 1 -fsm 3 telnet://") +
|
||||
mpdAddress + QString(":") + mpdPort + QString("\"");
|
||||
else if (playerName == QString("qmmp"))
|
||||
// qmmp
|
||||
cmd = QString("bash -c \"pgrep qmmp && qmmp --status || echo 'null'\"");
|
||||
else if (playerName == QString("mpris")) {
|
||||
// players which supports mpris
|
||||
if (mpris == "auto")
|
||||
mpris = getAutoMpris();
|
||||
cmd = QString("bash -c \"qdbus org.mpris.%1 /Player GetMetadata && qdbus org.mpris.%1 /Player PositionGet\"")
|
||||
.arg(mpris);
|
||||
}
|
||||
if (debug) qDebug() << "[DE]" << "[getPlayerInfo]" << ":" << "Run cmd" << cmd;
|
||||
if ((processes[QString("player")][0]->state() != 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<qoutput.split(QChar('\n'), QString::SkipEmptyParts).count(); i++) {
|
||||
qstr = qoutput.split(QChar('\n'), QString::SkipEmptyParts)[i];
|
||||
if (qstr.split(QString(": "), QString::SkipEmptyParts).count() > 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; i<qoutput.split(QChar('\n'), QString::SkipEmptyParts).count(); i++) {
|
||||
@ -652,67 +711,7 @@ void ExtendedSysMon::setPlayer(int exitCode, QProcess::ExitStatus exitStatus)
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (playerName == QString("clementine")) {
|
||||
qoutput = QTextCodec::codecForMib(106)->toUnicode(processes[QString("player")][0]->readAllStandardOutput());
|
||||
if (!qoutput.isEmpty()) {
|
||||
for (int i=0; i<qoutput.split(QChar('\n'), QString::SkipEmptyParts).count(); i++) {
|
||||
qstr = qoutput.split(QChar('\n'), QString::SkipEmptyParts)[i];
|
||||
if (qstr.split(QString(": "), QString::SkipEmptyParts).count() > 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<qoutput.split(QChar('\n'), QString::SkipEmptyParts).count(); i++) {
|
||||
qstr = qoutput.split(QChar('\n'), QString::SkipEmptyParts)[i];
|
||||
if (qstr.split(QString(": "), QString::SkipEmptyParts).count() > 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; i<qoutput.split(QChar('\n'), QString::SkipEmptyParts).count(); i++) {
|
||||
qstr = qoutput.split(QChar('\n'), QString::SkipEmptyParts)[i];
|
||||
if ((qstr.split(QString(" = "), QString::SkipEmptyParts).count() > 1) || (qstr.at(0) == QChar('['))) {
|
||||
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.at(0) == QChar('[')) && (!qstr.contains("[stopped]"))) {
|
||||
QString time = qstr.split(QString(" "), QString::SkipEmptyParts)[2].trimmed();
|
||||
info[2] = QString::number(time.split(QString("/"), QString::SkipEmptyParts)[0].split(QString(":"), QString::SkipEmptyParts)[0].toInt() * 60 +
|
||||
time.split(QString("/"), QString::SkipEmptyParts)[0].split(QString(":"), QString::SkipEmptyParts)[1].toInt());
|
||||
info[3] = QString::number(time.split(QString("/"), QString::SkipEmptyParts)[1].split(QString(":"), QString::SkipEmptyParts)[0].toInt() * 60 +
|
||||
time.split(QString("/"), QString::SkipEmptyParts)[1].split(QString(":"), QString::SkipEmptyParts)[1].toInt());
|
||||
}
|
||||
else if (qstr.split(QString(" = "), QString::SkipEmptyParts)[0] == QString("TITLE"))
|
||||
info[4] = qstr.split(QString(" = "), QString::SkipEmptyParts)[1].trimmed();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QString source = QString("player");
|
||||
QString key;
|
||||
key = QString("album");
|
||||
@ -731,6 +730,7 @@ void ExtendedSysMon::setPlayer(int exitCode, QProcess::ExitStatus exitStatus)
|
||||
void ExtendedSysMon::getPsStats()
|
||||
{
|
||||
if (debug) qDebug() << "[DE]" << "[getPsStats]";
|
||||
|
||||
QString cmd;
|
||||
cmd = QString("ps --no-headers -o command");
|
||||
if (debug) qDebug() << "[DE]" << "[getPsStats]" << ":" << "Run cmd" << cmd;
|
||||
@ -748,9 +748,9 @@ void ExtendedSysMon::getPsStats()
|
||||
void ExtendedSysMon::setPs(int exitCode, QProcess::ExitStatus exitStatus)
|
||||
{
|
||||
Q_UNUSED(exitStatus)
|
||||
|
||||
if (debug) qDebug() << "[DE]" << "[setPs]";
|
||||
if (debug) qDebug() << "[DE]" << "[setPs]" << ":" << "Cmd returns" << exitCode;
|
||||
|
||||
QString qoutput = QString("");
|
||||
for (int i=0; i<processes[QString("ps")].count(); i++) {
|
||||
qoutput = QTextCodec::codecForMib(106)->toUnicode(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<processes[QString("pkg")].count(); i++) {
|
||||
int pkgNull = 0;
|
||||
int value = 0;
|
||||
@ -821,6 +822,7 @@ bool ExtendedSysMon::sourceRequestEvent(const QString &name)
|
||||
{
|
||||
if (debug) qDebug() << "[DE]" << "[sourceRequestEvent]";
|
||||
if (debug) qDebug() << "[DE]" << "[sourceRequestEvent]" << ":" << "Run function with source name" << name;
|
||||
|
||||
return updateSourceEvent(name);
|
||||
}
|
||||
|
||||
@ -829,6 +831,7 @@ bool ExtendedSysMon::updateSourceEvent(const QString &source)
|
||||
{
|
||||
if (debug) qDebug() << "[DE]" << "[updateSourceEvent]";
|
||||
if (debug) qDebug() << "[DE]" << "[updateSourceEvent]" << ":" << "Run function with source name" << source;
|
||||
|
||||
if (source == QString("custom")) {
|
||||
for (int i=0; i<configuration[QString("CUSTOM")].split(QString("@@"), QString::SkipEmptyParts).count(); i++)
|
||||
getCustomCmd(configuration[QString("CUSTOM")].split(QString("@@"), QString::SkipEmptyParts)[i], i);
|
||||
@ -854,11 +857,13 @@ bool ExtendedSysMon::updateSourceEvent(const QString &source)
|
||||
else if (source == QString("player")) {
|
||||
getPlayerInfo(configuration[QString("PLAYER")],
|
||||
configuration[QString("MPDADDRESS")],
|
||||
configuration[QString("MPDPORT")]);
|
||||
configuration[QString("MPDPORT")],
|
||||
configuration[QString("MPRIS")]);
|
||||
}
|
||||
else if (source == QString("ps")) {
|
||||
getPsStats();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,8 @@ public:
|
||||
const int number = 0);
|
||||
void getPlayerInfo(const QString playerName,
|
||||
const QString mpdAddress = 0,
|
||||
const QString mpdPort = 0);
|
||||
const QString mpdPort = 0,
|
||||
QString mpris = 0);
|
||||
void getPsStats();
|
||||
void getUpgradeInfo(const QString pkgCommand,
|
||||
const int number = 0);
|
||||
@ -66,6 +67,7 @@ private:
|
||||
// reread configuration
|
||||
QString getAllHdd();
|
||||
QString getAutoGpu();
|
||||
QString getAutoMpris();
|
||||
QStringList getDesktopNames();
|
||||
void initValues();
|
||||
void readConfiguration();
|
||||
|
@ -104,6 +104,7 @@ class ConfigDefinition:
|
||||
deConfigFile.write("HDDTEMPCMD=" + str(self.configpage['dataengine'].ui.lineEdit_hddtempCmd.text()) + "\n")
|
||||
deConfigFile.write("MPDADDRESS=" + str(self.configpage['dataengine'].ui.lineEdit_mpdaddress.text()) + "\n")
|
||||
deConfigFile.write("MPDPORT=" + str(self.configpage['dataengine'].ui.spinBox_mpdport.value()) + "\n")
|
||||
deConfigFile.write("MPRIS=" + str(self.configpage['dataengine'].ui.comboBox_mpris.currentText()) + "\n")
|
||||
item = QStringList()
|
||||
for i in range(self.configpage['dataengine'].ui.listWidget_pkgCommand.count()):
|
||||
item.append(self.configpage['dataengine'].ui.listWidget_pkgCommand.item(i).text())
|
||||
@ -125,7 +126,7 @@ class ConfigDefinition:
|
||||
# disconnecting from source and clear layout
|
||||
self.parent.disconnectFromSource()
|
||||
|
||||
labelOrder = "----------------"
|
||||
labelOrder = "--------------------"
|
||||
for label in self.defaults['order'].keys():
|
||||
if (self.configpage['widget'].checkboxes[self.defaults['order'][label]].checkState() > 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:
|
||||
|
@ -288,7 +288,7 @@ del - remove item</string>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="7" column="0">
|
||||
<item row="8" column="0">
|
||||
<layout class="QVBoxLayout" name="layout_pkgCommand">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_pkgCommandSelect">
|
||||
@ -403,7 +403,7 @@ del - remove item</string>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="8" column="0">
|
||||
<item row="9" column="0">
|
||||
<layout class="QHBoxLayout" name="layout_playerSelect">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_playerSelect">
|
||||
@ -434,12 +434,7 @@ del - remove item</string>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string notr="true">amarok</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string notr="true">clementine</string>
|
||||
<string notr="true">mpris</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
@ -447,16 +442,11 @@ del - remove item</string>
|
||||
<string notr="true">mpd</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string notr="true">qmmp</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="9" column="0">
|
||||
<item row="10" column="0">
|
||||
<spacer name="spacer_dataengine">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
@ -493,6 +483,96 @@ del - remove item</string>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="7" column="0">
|
||||
<layout class="QVBoxLayout" name="layout_mpris">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_mprisInfo">
|
||||
<property name="text">
|
||||
<string><b>NOTE:</b> Player DBus interface should be an active</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_mprisSelect">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_mpris">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>200</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>MPRIS player name</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="comboBox_mpris">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>100</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="editable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string notr="true">auto</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string notr="true">amarok</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string notr="true">audacious</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string notr="true">clementine</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string notr="true">deadbeef</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>vlc</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string notr="true">qmmp</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>xmms2</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
@ -510,6 +590,7 @@ del - remove item</string>
|
||||
<tabstop>lineEdit_hddtempCmd</tabstop>
|
||||
<tabstop>lineEdit_mpdaddress</tabstop>
|
||||
<tabstop>spinBox_mpdport</tabstop>
|
||||
<tabstop>comboBox_mpris</tabstop>
|
||||
<tabstop>comboBox_pkgCommand</tabstop>
|
||||
<tabstop>spinBox_pkgCommandNum</tabstop>
|
||||
<tabstop>pushButton_pkgCommand</tabstop>
|
||||
|
Loading…
Reference in New Issue
Block a user