diff --git a/sources/desktop-panel/desktop-panel.cpp b/sources/desktop-panel/desktop-panel.cpp index fa6af0f..62a64c7 100644 --- a/sources/desktop-panel/desktop-panel.cpp +++ b/sources/desktop-panel/desktop-panel.cpp @@ -149,6 +149,38 @@ QStringList DesktopPanel::getDesktopNames() } +QString DesktopPanel::parsePattern(const QString rawLine, const int num) +{ + if (debug) qDebug() << "[PTM-DP]" << "[parsePattern]"; + if (debug) qDebug() << "[PTM-DP]" << "[parsePattern]" << "Run function with raw line" << rawLine; + if (debug) qDebug() << "[PTM-DP]" << "[parsePattern]" << "Run function with number" << num; + + QString line, mark; + line = rawLine; + if (currentDesktop == num + 1) + mark = configuration[QString("mark")]; + else + mark = QString(""); + if (line.split(QString("$mark"))[0] != line) { + if (debug) qDebug() << "[PTM-DP]" << "[parsePattern]" << "Found mark"; + line = line.split(QString("$mark"))[0] + mark + line.split(QString("$mark"))[1]; + } + if (line.split(QString("$name"))[0] != line) { + if (debug) qDebug() << "[PTM-DP]" << "[parsePattern]" << "Found name"; + line = line.split(QString("$name"))[0] + desktopNames[num] + line.split(QString("$name"))[1]; + } + if (line.split(QString("$number"))[0] != line) { + if (debug) qDebug() << "[PTM-DP]" << "[parsePattern]" << "Found number"; + line = line.split(QString("$number"))[0] + QString::number(num + 1) + line.split(QString("$number"))[1]; + } + if (line.split(QString("$total"))[0] != line) { + if (debug) qDebug() << "[PTM-DP]" << "[parsePattern]" << "Found total"; + line = line.split(QString("$total"))[0] + QString::number(desktopNames.count()) + line.split(QString("$total"))[1]; + } + return line; +} + + void DesktopPanel::reinit() { if (debug) qDebug() << "[PTM-DP]" << "[reinit]"; @@ -194,11 +226,13 @@ void DesktopPanel::reinit() int DesktopPanel::setCurrentDesktop(const int number) { if (debug) qDebug() << "[PTM-DP]" << "[setCurrentDesktop]"; - if (debug) qDebug() << "[PTM-DP]" << "[setCurrentDesktop]" << "Set desktop" << number; - if (debug) qDebug() << "[PTM-DP]" << "[setCurrentDesktop]" << "Run cmd " << configuration[QString("desktopcmd")] << QString::number(number+1); + if (debug) qDebug() << "[PTM-DP]" << "[setCurrentDesktop]" << "Set desktop" << number + 1; + + QString cmd = parsePattern(configuration[QString("desktopcmd")], number); + if (debug) qDebug() << "[PTM-DP]" << "[setCurrentDesktop]" << "Run cmd " << cmd; QProcess command; - command.start(configuration[QString("desktopcmd")] + QString(" ") + QString::number(number+1)); + command.start(cmd); command.waitForFinished(-1); int status = command.exitCode(); if (debug) qDebug() << "[PTM-DP]" << "[setCurrentDesktop]" << "Cmd returns " << status; @@ -210,32 +244,10 @@ void DesktopPanel::updateText() { if (debug) qDebug() << "[PTM-DP]" << "[updateText]"; if (labels.isEmpty()) return; - QString line, mark, text; + QString line, text; for (int i=0; i