mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-24 23:47:20 +00:00
implement #35
This commit is contained in:
parent
4b90fac0c4
commit
71b3a4e6ab
@ -33,6 +33,7 @@
|
||||
#include <QMouseEvent>
|
||||
#include <QProcessEnvironment>
|
||||
#include <QTextCodec>
|
||||
#include <QTimer>
|
||||
|
||||
#include <fontdialog/fontdialog.h>
|
||||
#include <pdebug/pdebug.h>
|
||||
@ -104,17 +105,19 @@ void DesktopPanel::init()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
extsysmonEngine = dataEngine(QString("ext-sysmon"));
|
||||
|
||||
layout = new QGraphicsGridLayout();
|
||||
layout->setContentsMargins(1, 1, 1, 1);
|
||||
setLayout(layout);
|
||||
|
||||
currentDesktop = 1;
|
||||
|
||||
// read variables
|
||||
configChanged();
|
||||
timer = new QTimer(this);
|
||||
timer->setSingleShot(false);
|
||||
timer->setInterval(2000);
|
||||
connect(timer, SIGNAL(timeout()), this, SLOT(updateTooltip()));
|
||||
timer->start();
|
||||
connect(this, SIGNAL(activate()), this, SLOT(changePanelsState()));
|
||||
connect(KWindowSystem::self(), SIGNAL(currentDesktopChanged(int)), this, SLOT(updateText(int)));
|
||||
}
|
||||
|
||||
|
||||
@ -183,7 +186,7 @@ QString DesktopPanel::parsePattern(const QString rawLine, const int num)
|
||||
|
||||
QString line, fullMark, mark;
|
||||
line = rawLine;
|
||||
if (currentDesktop == num + 1)
|
||||
if (KWindowSystem::currentDesktop() == num + 1)
|
||||
mark = configuration[QString("mark")];
|
||||
else
|
||||
mark = QString("");
|
||||
@ -206,7 +209,6 @@ QString DesktopPanel::parsePattern(const QString rawLine, const int num)
|
||||
void DesktopPanel::reinit()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (desktopNames.isEmpty()) return;
|
||||
|
||||
// clear
|
||||
// labels
|
||||
@ -218,8 +220,12 @@ void DesktopPanel::reinit()
|
||||
}
|
||||
labels.clear();
|
||||
proxyWidgets.clear();
|
||||
desktopNames.clear();
|
||||
|
||||
// add
|
||||
int total = KWindowSystem::numberOfDesktops();
|
||||
for (int i=1; i<total+1; i++)
|
||||
desktopNames.append(KWindowSystem::desktopName(i));
|
||||
// layout
|
||||
if (configuration[QString("background")].toInt() == 0)
|
||||
setBackgroundHints(NoBackground);
|
||||
@ -236,7 +242,7 @@ void DesktopPanel::reinit()
|
||||
layout->addItem(proxyWidgets[i], i, 0);
|
||||
}
|
||||
|
||||
updateText(true);
|
||||
updateText(KWindowSystem::currentDesktop());
|
||||
for (int i=0; i<proxyWidgets.count(); i++) {
|
||||
labels[i]->adjustSize();
|
||||
proxyWidgets[i]->setGeometry(labels[i]->geometry());
|
||||
@ -277,65 +283,23 @@ void DesktopPanel::setCurrentDesktop(const int number)
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Set desktop" << number + 1;
|
||||
|
||||
QString cmd = parsePattern(configuration[QString("desktopcmd")], number);
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Run cmd " << cmd;
|
||||
|
||||
QProcess command;
|
||||
command.startDetached(cmd);
|
||||
KWindowSystem::setCurrentDesktop(number + 1);
|
||||
}
|
||||
|
||||
|
||||
void DesktopPanel::updateText(const bool first)
|
||||
void DesktopPanel::updateText(const int active)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
QString line, text;
|
||||
for (int i=0; i<labels.count(); i++) {
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Label" << i;
|
||||
if (first)
|
||||
line = configuration[QString("pattern")];
|
||||
else
|
||||
line = parsePattern(configuration[QString("pattern")], i);
|
||||
if (currentDesktop == i + 1)
|
||||
line = parsePattern(configuration[QString("pattern")], i);
|
||||
if (active == i + 1)
|
||||
text = currentFormatLine[0] + line + currentFormatLine[1];
|
||||
else
|
||||
text = formatLine[0] + line + formatLine[1];
|
||||
labels[i]->setText(text);
|
||||
|
||||
// update tooltip
|
||||
if (configuration[QString("tooltip")].toInt() == 2) {
|
||||
QGraphicsScene *toolTipScene = new QGraphicsScene();
|
||||
toolTipScene->setBackgroundBrush(QBrush(Qt::NoBrush));
|
||||
QGraphicsView *toolTipView = new QGraphicsView(toolTipScene);
|
||||
toolTipView->setStyleSheet(QString("background: transparent"));
|
||||
toolTipView->setContentsMargins(0, 0, 0, 0);
|
||||
toolTipView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
toolTipView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
// paint
|
||||
DesktopWindowsInfo info = getInfoByDesktop(i + 1);
|
||||
toolTipView->resize(info.desktop.width() * 1.01, info.desktop.height() * 1.03);
|
||||
QPen pen = QPen();
|
||||
pen.setWidthF(2.0 * info.desktop.width() / 400.0);
|
||||
for (int i=0; i<info.windows.count(); i++) {
|
||||
toolTipScene->addLine(info.windows[i].left(), info.windows[i].bottom(),
|
||||
info.windows[i].left(), info.windows[i].top(), pen);
|
||||
toolTipScene->addLine(info.windows[i].left(), info.windows[i].top(),
|
||||
info.windows[i].right(), info.windows[i].top(), pen);
|
||||
toolTipScene->addLine(info.windows[i].right(), info.windows[i].top(),
|
||||
info.windows[i].right(), info.windows[i].bottom(), pen);
|
||||
toolTipScene->addLine(info.windows[i].right(), info.windows[i].bottom(),
|
||||
info.windows[i].left(), info.windows[i].bottom(), pen);
|
||||
}
|
||||
// convert
|
||||
QPixmap pixmap = QPixmap::grabWidget(toolTipView);
|
||||
QByteArray byteArray;
|
||||
QBuffer buffer(&byteArray);
|
||||
pixmap.scaledToWidth(configuration[QString("tooltipWidth")].toInt()).save(&buffer, "PNG");
|
||||
QString url = QString("<html><style type=\"text/css\">body {margin: 0; padding: 0;}</style><body><img src=\"data:image/png;base64,") +
|
||||
byteArray.toBase64() +
|
||||
QString("\"/></body></html>");
|
||||
labels[i]->setToolTip(url);
|
||||
}
|
||||
}
|
||||
int height = 0;
|
||||
int width = 0;
|
||||
@ -356,21 +320,45 @@ void DesktopPanel::updateText(const bool first)
|
||||
}
|
||||
|
||||
|
||||
// data engine interaction
|
||||
void DesktopPanel::dataUpdated(const QString &sourceName, const Plasma::DataEngine::Data &data)
|
||||
void DesktopPanel::updateTooltip()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Source name" << sourceName;
|
||||
if (configuration[QString("tooltip")].toInt() != 2) return;
|
||||
|
||||
if (data.keys().count() == 0)
|
||||
return;
|
||||
if (sourceName == QString("desktop")) {
|
||||
currentDesktop = data[QString("currentNumber")].toInt();
|
||||
if (desktopNames.isEmpty()) {
|
||||
desktopNames = data[QString("list")].toString().split(QString(";;"));
|
||||
reinit();
|
||||
for (int i=0; i<labels.count(); i++) {
|
||||
QGraphicsScene *toolTipScene = new QGraphicsScene();
|
||||
toolTipScene->setBackgroundBrush(QBrush(Qt::NoBrush));
|
||||
QGraphicsView *toolTipView = new QGraphicsView(toolTipScene);
|
||||
toolTipView->setStyleSheet(QString("background: transparent"));
|
||||
toolTipView->setContentsMargins(0, 0, 0, 0);
|
||||
toolTipView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
toolTipView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
// paint
|
||||
DesktopWindowsInfo info = getInfoByDesktop(i + 1);
|
||||
toolTipView->resize(info.desktop.width() * 1.01, info.desktop.height() * 1.03);
|
||||
QPen pen = QPen();
|
||||
pen.setWidthF(2.0 * info.desktop.width() / 400.0);
|
||||
for (int i=0; i<info.windows.count(); i++) {
|
||||
toolTipScene->addLine(info.windows[i].left(), info.windows[i].bottom(),
|
||||
info.windows[i].left(), info.windows[i].top(), pen);
|
||||
toolTipScene->addLine(info.windows[i].left(), info.windows[i].top(),
|
||||
info.windows[i].right(), info.windows[i].top(), pen);
|
||||
toolTipScene->addLine(info.windows[i].right(), info.windows[i].top(),
|
||||
info.windows[i].right(), info.windows[i].bottom(), pen);
|
||||
toolTipScene->addLine(info.windows[i].right(), info.windows[i].bottom(),
|
||||
info.windows[i].left(), info.windows[i].bottom(), pen);
|
||||
}
|
||||
updateText();
|
||||
// convert
|
||||
QPixmap pixmap = QPixmap::grabWidget(toolTipView);
|
||||
QByteArray byteArray;
|
||||
QBuffer buffer(&byteArray);
|
||||
pixmap.scaledToWidth(configuration[QString("tooltipWidth")].toInt()).save(&buffer, "PNG");
|
||||
QString url = QString("<html><style type=\"text/css\">body {margin: 0; padding: 0;}</style><body><img src=\"data:image/png;base64,") +
|
||||
byteArray.toBase64() +
|
||||
QString("\"/></body></html>");
|
||||
labels[i]->setToolTip(url);
|
||||
delete toolTipView;
|
||||
delete toolTipScene;
|
||||
}
|
||||
}
|
||||
|
||||
@ -401,10 +389,8 @@ void DesktopPanel::createConfigurationInterface(KConfigDialog *parent)
|
||||
uiWidConfig.checkBox_layout->setCheckState(Qt::Unchecked);
|
||||
else
|
||||
uiWidConfig.checkBox_layout->setCheckState(Qt::Checked);
|
||||
uiWidConfig.spinBox_interval->setValue(configuration[QString("interval")].toInt());
|
||||
uiWidConfig.comboBox_mark->setItemText(uiWidConfig.comboBox_mark->count()-1, configuration[QString("mark")]);
|
||||
uiWidConfig.comboBox_mark->setCurrentIndex(uiWidConfig.comboBox_mark->count()-1);
|
||||
uiWidConfig.lineEdit_desktopcmd->setText(configuration[QString("desktopcmd")]);
|
||||
|
||||
KConfigGroup cg = config();
|
||||
CFont font(cg.readEntry("currentFontFamily", "Terminus"));
|
||||
@ -473,7 +459,6 @@ void DesktopPanel::configAccepted()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
extsysmonEngine->disconnectSource(QString("desktop"), this);
|
||||
KConfigGroup cg = config();
|
||||
|
||||
cg.writeEntry("pattern", uiWidConfig.textEdit_elements->toPlainText());
|
||||
@ -481,9 +466,7 @@ void DesktopPanel::configAccepted()
|
||||
cg.writeEntry("tooltipWidth", QString::number(uiWidConfig.spinBox_tooltip->value()));
|
||||
cg.writeEntry("background", QString::number(uiWidConfig.checkBox_background->checkState()));
|
||||
cg.writeEntry("layout", QString::number(uiWidConfig.checkBox_layout->checkState()));
|
||||
cg.writeEntry("interval", QString::number(uiWidConfig.spinBox_interval->value()));
|
||||
cg.writeEntry("mark", uiWidConfig.comboBox_mark->currentText());
|
||||
cg.writeEntry("desktopcmd", uiWidConfig.lineEdit_desktopcmd->text());
|
||||
|
||||
cg.writeEntry("currentFontFamily", uiAppConfig.fontComboBox_fontActive->currentFont().family());
|
||||
cg.writeEntry("currentFontSize", uiAppConfig.spinBox_fontSizeActive->value());
|
||||
@ -518,14 +501,10 @@ void DesktopPanel::configChanged()
|
||||
configuration[QString("tooltip")] = cg.readEntry("tooltip", "2");
|
||||
configuration[QString("tooltipWidth")] = cg.readEntry("tooltipWidth", "200");
|
||||
configuration[QString("background")] = cg.readEntry("background", "2");
|
||||
configuration[QString("desktopcmd")] = cg.readEntry("desktopcmd", "qdbus org.kde.kwin /KWin setCurrentDesktop $number");
|
||||
configuration[QString("interval")] = cg.readEntry("interval", "1000");
|
||||
configuration[QString("layout")] = cg.readEntry("layout", "0");
|
||||
configuration[QString("mark")] = cg.readEntry("mark", "¤");
|
||||
configuration[QString("panels")] = cg.readEntry("panels", "-1");
|
||||
|
||||
extsysmonEngine->connectSource(QString("desktop"), this, configuration[QString("interval")].toInt());
|
||||
|
||||
CFont font = CFont(cg.readEntry("currentFontFamily", "Terminus"));
|
||||
font.setPointSize(cg.readEntry("currentFontSize", 10));
|
||||
font.setCurrentColor(QColor(cg.readEntry("currentFontColor", "#ff0000")));
|
||||
|
@ -30,6 +30,7 @@
|
||||
|
||||
class QGraphicsGridLayout;
|
||||
class QGraphicsProxyWidget;
|
||||
class QTimer;
|
||||
class DesktopPanel;
|
||||
|
||||
|
||||
@ -73,8 +74,6 @@ public:
|
||||
QString parsePattern(const QString rawLine, const int num);
|
||||
|
||||
public slots:
|
||||
// dataengine
|
||||
void dataUpdated(const QString &sourceName, const Plasma::DataEngine::Data &data);
|
||||
// configuration interface
|
||||
void configAccepted();
|
||||
void configChanged();
|
||||
@ -86,6 +85,8 @@ private slots:
|
||||
void reinit();
|
||||
void setFontFormating();
|
||||
void setFormating();
|
||||
void updateText(const int active);
|
||||
void updateTooltip();
|
||||
|
||||
protected:
|
||||
void createConfigurationInterface(KConfigDialog *parent);
|
||||
@ -94,17 +95,14 @@ private:
|
||||
// functions
|
||||
QList<Plasma::Containment *> getPanels();
|
||||
QString panelLocationToStr(Plasma::Location loc);
|
||||
void updateText(const bool first = false);
|
||||
// ui
|
||||
QGraphicsGridLayout *layout;
|
||||
QList<QGraphicsProxyWidget *> proxyWidgets;
|
||||
QList<CustomPlasmaLabel *> labels;
|
||||
QTimer *timer;
|
||||
// debug
|
||||
bool debug;
|
||||
// data engine
|
||||
int currentDesktop;
|
||||
int oldState;
|
||||
Plasma::DataEngine *extsysmonEngine;
|
||||
// configuration interface
|
||||
Ui::AppearanceWidget uiAppConfig;
|
||||
Ui::ConfigWindow uiWidConfig;
|
||||
|
@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>723</width>
|
||||
<height>422</height>
|
||||
<width>721</width>
|
||||
<height>420</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
@ -27,93 +27,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="10" column="0">
|
||||
<layout class="QHBoxLayout" name="layout_desktopcmd">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_desktopcmd">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>200</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Command to change desktop</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_desktopcmd">
|
||||
<property name="toolTip">
|
||||
<string>Command which will change the current desktop</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="8" column="0">
|
||||
<layout class="QHBoxLayout" name="layout_interval">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_interval">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>200</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Time interval</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="spacer_interval">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="spinBox_interval">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>180</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>10000</number>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<number>500</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>1000</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QCheckBox" name="checkBox_background">
|
||||
<property name="text">
|
||||
<string>Enable background</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="9" column="0">
|
||||
<layout class="QHBoxLayout" name="layout_mark">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_mark">
|
||||
@ -220,6 +134,62 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QCheckBox" name="checkBox_tooltip">
|
||||
<property name="text">
|
||||
<string>Enable tooltip</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<layout class="QHBoxLayout" name="layout_tooltip">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_tooltip">
|
||||
<property name="text">
|
||||
<string>Tooltip width</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="spacer_tooltip">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="spinBox_tooltip">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>180</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="suffix">
|
||||
<string>px</string>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>100</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>1000</number>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<number>25</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<layout class="QHBoxLayout" name="layput_mainFormating">
|
||||
<item>
|
||||
@ -402,62 +372,13 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QCheckBox" name="checkBox_tooltip">
|
||||
<item row="4" column="0">
|
||||
<widget class="QCheckBox" name="checkBox_background">
|
||||
<property name="text">
|
||||
<string>Enable tooltip</string>
|
||||
<string>Enable background</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<layout class="QHBoxLayout" name="layout_tooltip">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_tooltip">
|
||||
<property name="text">
|
||||
<string>Tooltip width</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="spacer_tooltip">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="spinBox_tooltip">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>180</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="suffix">
|
||||
<string>px</string>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>100</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>1000</number>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<number>25</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
|
@ -4,9 +4,6 @@
|
||||
# ACPI devices
|
||||
#ACPIPATH=/sys/class/power_supply/
|
||||
|
||||
# Command which returns number of the current desktop
|
||||
#DESKTOPCMD=qdbus org.kde.kwin /KWin currentDesktop
|
||||
|
||||
# Set GPU device
|
||||
# May be 'nvidia' (for nvidia), 'ati' (for ATI RADEON), 'disable' or 'auto'
|
||||
#GPUDEV=auto
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include <Plasma/DataContainer>
|
||||
#include <KDE/KGlobal>
|
||||
#include <KDE/KStandardDirs>
|
||||
#include <KDE/KWindowSystem>
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
@ -111,43 +112,6 @@ QString ExtendedSysMon::getAutoMpris()
|
||||
}
|
||||
|
||||
|
||||
QStringList ExtendedSysMon::getDesktopNames()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
QStringList list;
|
||||
QString fileName = KGlobal::dirs()->findResource("config", "kwinrc");
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Configuration file" << fileName;
|
||||
QFile configFile(fileName);
|
||||
if (!configFile.open(QIODevice::ReadOnly)) return list;
|
||||
|
||||
QString fileStr;
|
||||
QStringList value;
|
||||
bool desktopSection = false;
|
||||
while (true) {
|
||||
fileStr = QString(configFile.readLine()).trimmed();
|
||||
if ((fileStr.isEmpty()) && (!configFile.atEnd())) continue;
|
||||
if ((fileStr[0] == QChar('#')) && (!configFile.atEnd())) continue;
|
||||
if ((fileStr[0] == QChar(';')) && (!configFile.atEnd())) continue;
|
||||
if (fileStr[0] == QChar('[')) desktopSection = false;
|
||||
if (fileStr == QString("[Desktops]")) desktopSection = true;
|
||||
if (desktopSection) {
|
||||
if (fileStr.contains(QChar('='))) {
|
||||
value.clear();
|
||||
for (int i=1; i<fileStr.split(QChar('=')).count(); i++)
|
||||
value.append(fileStr.split(QChar('='))[i]);
|
||||
if (fileStr.split(QChar('='))[0].contains(QString("Name_")))
|
||||
list.append(value.join(QChar('=')));
|
||||
}
|
||||
}
|
||||
if (configFile.atEnd()) break;
|
||||
}
|
||||
configFile.close();
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
void ExtendedSysMon::initScripts()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
@ -200,8 +164,6 @@ void ExtendedSysMon::readConfiguration()
|
||||
// pre-setup
|
||||
QMap<QString, QString> rawConfig;
|
||||
rawConfig[QString("ACPIPATH")] = QString("/sys/class/power_supply/");
|
||||
rawConfig[QString("DESKTOP")] = QString("");
|
||||
rawConfig[QString("DESKTOPCMD")] = QString("qdbus org.kde.kwin /KWin currentDesktop");
|
||||
rawConfig[QString("GPUDEV")] = QString("auto");
|
||||
rawConfig[QString("HDDDEV")] = QString("all");
|
||||
rawConfig[QString("HDDTEMPCMD")] = QString("sudo hddtemp");
|
||||
@ -251,15 +213,12 @@ QMap<QString, QString> ExtendedSysMon::updateConfiguration(const QMap<QString, Q
|
||||
key = rawConfig.keys()[i];
|
||||
value = rawConfig[key];
|
||||
key.remove(QChar(' '));
|
||||
if ((key != QString("DESKTOPCMD")) &&
|
||||
(key != QString("HDDTEMPCMD")) &&
|
||||
if ((key != QString("HDDTEMPCMD")) &&
|
||||
(key != QString("PKGCMD")))
|
||||
value.remove(QChar(' '));
|
||||
config[key] = value;
|
||||
}
|
||||
// update values
|
||||
// desktop names
|
||||
config[QString("DESKTOP")] = getDesktopNames().join(QString(";;"));
|
||||
// gpudev
|
||||
if (config[QString("GPUDEV")] == QString("disable"))
|
||||
config[QString("GPUDEV")] = QString("disable");
|
||||
@ -344,21 +303,20 @@ QMap<QString, QVariant> ExtendedSysMon::getBattery(const QString acpiPath)
|
||||
}
|
||||
|
||||
|
||||
QMap<QString, QVariant> ExtendedSysMon::getCurrentDesktop(const QString cmd)
|
||||
QMap<QString, QVariant> ExtendedSysMon::getCurrentDesktop()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "cmd" << cmd;
|
||||
|
||||
TaskResult process = runTask(QString("bash -c \"") + cmd + QString("\""));
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
|
||||
|
||||
QString qoutput = QTextCodec::codecForMib(106)->toUnicode(process.output).trimmed();
|
||||
int number = qoutput.toInt();
|
||||
int number = KWindowSystem::currentDesktop();
|
||||
int total = KWindowSystem::numberOfDesktops();
|
||||
QMap<QString, QVariant> currentDesktop;
|
||||
currentDesktop[QString("currentName")] = configuration[QString("DESKTOP")].split(QString(";;"))[number-1];
|
||||
currentDesktop[QString("currentName")] = KWindowSystem::desktopName(number);
|
||||
currentDesktop[QString("currentNumber")] = number;
|
||||
currentDesktop[QString("list")] = configuration[QString("DESKTOP")];
|
||||
currentDesktop[QString("number")] = configuration[QString("DESKTOP")].split(QString(";;")).count();
|
||||
QStringList list;
|
||||
for (int i=1; i<total+1; i++)
|
||||
list.append(KWindowSystem::desktopName(i));
|
||||
currentDesktop[QString("list")] = list.join(QString(";;"));
|
||||
currentDesktop[QString("number")] = total;
|
||||
|
||||
return currentDesktop;
|
||||
}
|
||||
@ -620,7 +578,7 @@ bool ExtendedSysMon::updateSourceEvent(const QString &source)
|
||||
times[i]++;
|
||||
}
|
||||
} else if (source == QString("desktop")) {
|
||||
QMap<QString, QVariant> desktop = getCurrentDesktop(configuration[QString("DESKTOPCMD")]);
|
||||
QMap<QString, QVariant> desktop = getCurrentDesktop();
|
||||
for (int i=0; i<desktop.keys().count(); i++)
|
||||
setData(source, desktop.keys()[i], desktop[desktop.keys()[i]]);
|
||||
} else if (source == QString("gpu")) {
|
||||
|
@ -32,7 +32,7 @@ public:
|
||||
ExtendedSysMon(QObject *parent, const QVariantList &args);
|
||||
// update functions
|
||||
QMap<QString, QVariant> getBattery(const QString acpiPath);
|
||||
QMap<QString, QVariant> getCurrentDesktop(const QString cmd);
|
||||
QMap<QString, QVariant> getCurrentDesktop();
|
||||
float getGpu(const QString device);
|
||||
float getGpuTemp(const QString device);
|
||||
float getHddTemp(const QString cmd, const QString device);
|
||||
@ -58,7 +58,6 @@ private:
|
||||
QString getAllHdd();
|
||||
QString getAutoGpu();
|
||||
QString getAutoMpris();
|
||||
QStringList getDesktopNames();
|
||||
void initScripts();
|
||||
void readConfiguration();
|
||||
QMap<QString, QString> updateConfiguration(const QMap<QString, QString> rawConfig);
|
||||
|
Loading…
Reference in New Issue
Block a user