mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-25 16:07:19 +00:00
implement #35
This commit is contained in:
parent
4b90fac0c4
commit
71b3a4e6ab
@ -33,6 +33,7 @@
|
|||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <QProcessEnvironment>
|
#include <QProcessEnvironment>
|
||||||
#include <QTextCodec>
|
#include <QTextCodec>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
#include <fontdialog/fontdialog.h>
|
#include <fontdialog/fontdialog.h>
|
||||||
#include <pdebug/pdebug.h>
|
#include <pdebug/pdebug.h>
|
||||||
@ -104,17 +105,19 @@ void DesktopPanel::init()
|
|||||||
{
|
{
|
||||||
if (debug) qDebug() << PDEBUG;
|
if (debug) qDebug() << PDEBUG;
|
||||||
|
|
||||||
extsysmonEngine = dataEngine(QString("ext-sysmon"));
|
|
||||||
|
|
||||||
layout = new QGraphicsGridLayout();
|
layout = new QGraphicsGridLayout();
|
||||||
layout->setContentsMargins(1, 1, 1, 1);
|
layout->setContentsMargins(1, 1, 1, 1);
|
||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
|
|
||||||
currentDesktop = 1;
|
|
||||||
|
|
||||||
// read variables
|
// read variables
|
||||||
configChanged();
|
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(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;
|
QString line, fullMark, mark;
|
||||||
line = rawLine;
|
line = rawLine;
|
||||||
if (currentDesktop == num + 1)
|
if (KWindowSystem::currentDesktop() == num + 1)
|
||||||
mark = configuration[QString("mark")];
|
mark = configuration[QString("mark")];
|
||||||
else
|
else
|
||||||
mark = QString("");
|
mark = QString("");
|
||||||
@ -206,7 +209,6 @@ QString DesktopPanel::parsePattern(const QString rawLine, const int num)
|
|||||||
void DesktopPanel::reinit()
|
void DesktopPanel::reinit()
|
||||||
{
|
{
|
||||||
if (debug) qDebug() << PDEBUG;
|
if (debug) qDebug() << PDEBUG;
|
||||||
if (desktopNames.isEmpty()) return;
|
|
||||||
|
|
||||||
// clear
|
// clear
|
||||||
// labels
|
// labels
|
||||||
@ -218,8 +220,12 @@ void DesktopPanel::reinit()
|
|||||||
}
|
}
|
||||||
labels.clear();
|
labels.clear();
|
||||||
proxyWidgets.clear();
|
proxyWidgets.clear();
|
||||||
|
desktopNames.clear();
|
||||||
|
|
||||||
// add
|
// add
|
||||||
|
int total = KWindowSystem::numberOfDesktops();
|
||||||
|
for (int i=1; i<total+1; i++)
|
||||||
|
desktopNames.append(KWindowSystem::desktopName(i));
|
||||||
// layout
|
// layout
|
||||||
if (configuration[QString("background")].toInt() == 0)
|
if (configuration[QString("background")].toInt() == 0)
|
||||||
setBackgroundHints(NoBackground);
|
setBackgroundHints(NoBackground);
|
||||||
@ -236,7 +242,7 @@ void DesktopPanel::reinit()
|
|||||||
layout->addItem(proxyWidgets[i], i, 0);
|
layout->addItem(proxyWidgets[i], i, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateText(true);
|
updateText(KWindowSystem::currentDesktop());
|
||||||
for (int i=0; i<proxyWidgets.count(); i++) {
|
for (int i=0; i<proxyWidgets.count(); i++) {
|
||||||
labels[i]->adjustSize();
|
labels[i]->adjustSize();
|
||||||
proxyWidgets[i]->setGeometry(labels[i]->geometry());
|
proxyWidgets[i]->setGeometry(labels[i]->geometry());
|
||||||
@ -277,65 +283,23 @@ void DesktopPanel::setCurrentDesktop(const int number)
|
|||||||
if (debug) qDebug() << PDEBUG;
|
if (debug) qDebug() << PDEBUG;
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Set desktop" << number + 1;
|
if (debug) qDebug() << PDEBUG << ":" << "Set desktop" << number + 1;
|
||||||
|
|
||||||
QString cmd = parsePattern(configuration[QString("desktopcmd")], number);
|
KWindowSystem::setCurrentDesktop(number + 1);
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Run cmd " << cmd;
|
|
||||||
|
|
||||||
QProcess command;
|
|
||||||
command.startDetached(cmd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DesktopPanel::updateText(const bool first)
|
void DesktopPanel::updateText(const int active)
|
||||||
{
|
{
|
||||||
if (debug) qDebug() << PDEBUG;
|
if (debug) qDebug() << PDEBUG;
|
||||||
|
|
||||||
QString line, text;
|
QString line, text;
|
||||||
for (int i=0; i<labels.count(); i++) {
|
for (int i=0; i<labels.count(); i++) {
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Label" << i;
|
if (debug) qDebug() << PDEBUG << ":" << "Label" << i;
|
||||||
if (first)
|
line = parsePattern(configuration[QString("pattern")], i);
|
||||||
line = configuration[QString("pattern")];
|
if (active == i + 1)
|
||||||
else
|
|
||||||
line = parsePattern(configuration[QString("pattern")], i);
|
|
||||||
if (currentDesktop == i + 1)
|
|
||||||
text = currentFormatLine[0] + line + currentFormatLine[1];
|
text = currentFormatLine[0] + line + currentFormatLine[1];
|
||||||
else
|
else
|
||||||
text = formatLine[0] + line + formatLine[1];
|
text = formatLine[0] + line + formatLine[1];
|
||||||
labels[i]->setText(text);
|
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 height = 0;
|
||||||
int width = 0;
|
int width = 0;
|
||||||
@ -356,21 +320,45 @@ void DesktopPanel::updateText(const bool first)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// data engine interaction
|
void DesktopPanel::updateTooltip()
|
||||||
void DesktopPanel::dataUpdated(const QString &sourceName, const Plasma::DataEngine::Data &data)
|
|
||||||
{
|
{
|
||||||
if (debug) qDebug() << PDEBUG;
|
if (debug) qDebug() << PDEBUG;
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Source name" << sourceName;
|
if (configuration[QString("tooltip")].toInt() != 2) return;
|
||||||
|
|
||||||
if (data.keys().count() == 0)
|
for (int i=0; i<labels.count(); i++) {
|
||||||
return;
|
QGraphicsScene *toolTipScene = new QGraphicsScene();
|
||||||
if (sourceName == QString("desktop")) {
|
toolTipScene->setBackgroundBrush(QBrush(Qt::NoBrush));
|
||||||
currentDesktop = data[QString("currentNumber")].toInt();
|
QGraphicsView *toolTipView = new QGraphicsView(toolTipScene);
|
||||||
if (desktopNames.isEmpty()) {
|
toolTipView->setStyleSheet(QString("background: transparent"));
|
||||||
desktopNames = data[QString("list")].toString().split(QString(";;"));
|
toolTipView->setContentsMargins(0, 0, 0, 0);
|
||||||
reinit();
|
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);
|
uiWidConfig.checkBox_layout->setCheckState(Qt::Unchecked);
|
||||||
else
|
else
|
||||||
uiWidConfig.checkBox_layout->setCheckState(Qt::Checked);
|
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->setItemText(uiWidConfig.comboBox_mark->count()-1, configuration[QString("mark")]);
|
||||||
uiWidConfig.comboBox_mark->setCurrentIndex(uiWidConfig.comboBox_mark->count()-1);
|
uiWidConfig.comboBox_mark->setCurrentIndex(uiWidConfig.comboBox_mark->count()-1);
|
||||||
uiWidConfig.lineEdit_desktopcmd->setText(configuration[QString("desktopcmd")]);
|
|
||||||
|
|
||||||
KConfigGroup cg = config();
|
KConfigGroup cg = config();
|
||||||
CFont font(cg.readEntry("currentFontFamily", "Terminus"));
|
CFont font(cg.readEntry("currentFontFamily", "Terminus"));
|
||||||
@ -473,7 +459,6 @@ void DesktopPanel::configAccepted()
|
|||||||
{
|
{
|
||||||
if (debug) qDebug() << PDEBUG;
|
if (debug) qDebug() << PDEBUG;
|
||||||
|
|
||||||
extsysmonEngine->disconnectSource(QString("desktop"), this);
|
|
||||||
KConfigGroup cg = config();
|
KConfigGroup cg = config();
|
||||||
|
|
||||||
cg.writeEntry("pattern", uiWidConfig.textEdit_elements->toPlainText());
|
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("tooltipWidth", QString::number(uiWidConfig.spinBox_tooltip->value()));
|
||||||
cg.writeEntry("background", QString::number(uiWidConfig.checkBox_background->checkState()));
|
cg.writeEntry("background", QString::number(uiWidConfig.checkBox_background->checkState()));
|
||||||
cg.writeEntry("layout", QString::number(uiWidConfig.checkBox_layout->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("mark", uiWidConfig.comboBox_mark->currentText());
|
||||||
cg.writeEntry("desktopcmd", uiWidConfig.lineEdit_desktopcmd->text());
|
|
||||||
|
|
||||||
cg.writeEntry("currentFontFamily", uiAppConfig.fontComboBox_fontActive->currentFont().family());
|
cg.writeEntry("currentFontFamily", uiAppConfig.fontComboBox_fontActive->currentFont().family());
|
||||||
cg.writeEntry("currentFontSize", uiAppConfig.spinBox_fontSizeActive->value());
|
cg.writeEntry("currentFontSize", uiAppConfig.spinBox_fontSizeActive->value());
|
||||||
@ -518,14 +501,10 @@ void DesktopPanel::configChanged()
|
|||||||
configuration[QString("tooltip")] = cg.readEntry("tooltip", "2");
|
configuration[QString("tooltip")] = cg.readEntry("tooltip", "2");
|
||||||
configuration[QString("tooltipWidth")] = cg.readEntry("tooltipWidth", "200");
|
configuration[QString("tooltipWidth")] = cg.readEntry("tooltipWidth", "200");
|
||||||
configuration[QString("background")] = cg.readEntry("background", "2");
|
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("layout")] = cg.readEntry("layout", "0");
|
||||||
configuration[QString("mark")] = cg.readEntry("mark", "¤");
|
configuration[QString("mark")] = cg.readEntry("mark", "¤");
|
||||||
configuration[QString("panels")] = cg.readEntry("panels", "-1");
|
configuration[QString("panels")] = cg.readEntry("panels", "-1");
|
||||||
|
|
||||||
extsysmonEngine->connectSource(QString("desktop"), this, configuration[QString("interval")].toInt());
|
|
||||||
|
|
||||||
CFont font = CFont(cg.readEntry("currentFontFamily", "Terminus"));
|
CFont font = CFont(cg.readEntry("currentFontFamily", "Terminus"));
|
||||||
font.setPointSize(cg.readEntry("currentFontSize", 10));
|
font.setPointSize(cg.readEntry("currentFontSize", 10));
|
||||||
font.setCurrentColor(QColor(cg.readEntry("currentFontColor", "#ff0000")));
|
font.setCurrentColor(QColor(cg.readEntry("currentFontColor", "#ff0000")));
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
|
|
||||||
class QGraphicsGridLayout;
|
class QGraphicsGridLayout;
|
||||||
class QGraphicsProxyWidget;
|
class QGraphicsProxyWidget;
|
||||||
|
class QTimer;
|
||||||
class DesktopPanel;
|
class DesktopPanel;
|
||||||
|
|
||||||
|
|
||||||
@ -73,8 +74,6 @@ public:
|
|||||||
QString parsePattern(const QString rawLine, const int num);
|
QString parsePattern(const QString rawLine, const int num);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
// dataengine
|
|
||||||
void dataUpdated(const QString &sourceName, const Plasma::DataEngine::Data &data);
|
|
||||||
// configuration interface
|
// configuration interface
|
||||||
void configAccepted();
|
void configAccepted();
|
||||||
void configChanged();
|
void configChanged();
|
||||||
@ -86,6 +85,8 @@ private slots:
|
|||||||
void reinit();
|
void reinit();
|
||||||
void setFontFormating();
|
void setFontFormating();
|
||||||
void setFormating();
|
void setFormating();
|
||||||
|
void updateText(const int active);
|
||||||
|
void updateTooltip();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void createConfigurationInterface(KConfigDialog *parent);
|
void createConfigurationInterface(KConfigDialog *parent);
|
||||||
@ -94,17 +95,14 @@ private:
|
|||||||
// functions
|
// functions
|
||||||
QList<Plasma::Containment *> getPanels();
|
QList<Plasma::Containment *> getPanels();
|
||||||
QString panelLocationToStr(Plasma::Location loc);
|
QString panelLocationToStr(Plasma::Location loc);
|
||||||
void updateText(const bool first = false);
|
|
||||||
// ui
|
// ui
|
||||||
QGraphicsGridLayout *layout;
|
QGraphicsGridLayout *layout;
|
||||||
QList<QGraphicsProxyWidget *> proxyWidgets;
|
QList<QGraphicsProxyWidget *> proxyWidgets;
|
||||||
QList<CustomPlasmaLabel *> labels;
|
QList<CustomPlasmaLabel *> labels;
|
||||||
|
QTimer *timer;
|
||||||
// debug
|
// debug
|
||||||
bool debug;
|
bool debug;
|
||||||
// data engine
|
|
||||||
int currentDesktop;
|
|
||||||
int oldState;
|
int oldState;
|
||||||
Plasma::DataEngine *extsysmonEngine;
|
|
||||||
// configuration interface
|
// configuration interface
|
||||||
Ui::AppearanceWidget uiAppConfig;
|
Ui::AppearanceWidget uiAppConfig;
|
||||||
Ui::ConfigWindow uiWidConfig;
|
Ui::ConfigWindow uiWidConfig;
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>723</width>
|
<width>721</width>
|
||||||
<height>422</height>
|
<height>420</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="minimumSize">
|
<property name="minimumSize">
|
||||||
@ -27,93 +27,7 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</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">
|
<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">
|
<layout class="QHBoxLayout" name="layout_mark">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="label_mark">
|
<widget class="QLabel" name="label_mark">
|
||||||
@ -220,6 +134,62 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</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">
|
<item row="0" column="0">
|
||||||
<layout class="QHBoxLayout" name="layput_mainFormating">
|
<layout class="QHBoxLayout" name="layput_mainFormating">
|
||||||
<item>
|
<item>
|
||||||
@ -402,62 +372,13 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="0">
|
<item row="4" column="0">
|
||||||
<widget class="QCheckBox" name="checkBox_tooltip">
|
<widget class="QCheckBox" name="checkBox_background">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Enable tooltip</string>
|
<string>Enable background</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</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>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
|
@ -4,9 +4,6 @@
|
|||||||
# ACPI devices
|
# ACPI devices
|
||||||
#ACPIPATH=/sys/class/power_supply/
|
#ACPIPATH=/sys/class/power_supply/
|
||||||
|
|
||||||
# Command which returns number of the current desktop
|
|
||||||
#DESKTOPCMD=qdbus org.kde.kwin /KWin currentDesktop
|
|
||||||
|
|
||||||
# Set GPU device
|
# Set GPU device
|
||||||
# May be 'nvidia' (for nvidia), 'ati' (for ATI RADEON), 'disable' or 'auto'
|
# May be 'nvidia' (for nvidia), 'ati' (for ATI RADEON), 'disable' or 'auto'
|
||||||
#GPUDEV=auto
|
#GPUDEV=auto
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include <Plasma/DataContainer>
|
#include <Plasma/DataContainer>
|
||||||
#include <KDE/KGlobal>
|
#include <KDE/KGlobal>
|
||||||
#include <KDE/KStandardDirs>
|
#include <KDE/KStandardDirs>
|
||||||
|
#include <KDE/KWindowSystem>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFile>
|
#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()
|
void ExtendedSysMon::initScripts()
|
||||||
{
|
{
|
||||||
if (debug) qDebug() << PDEBUG;
|
if (debug) qDebug() << PDEBUG;
|
||||||
@ -200,8 +164,6 @@ void ExtendedSysMon::readConfiguration()
|
|||||||
// pre-setup
|
// pre-setup
|
||||||
QMap<QString, QString> rawConfig;
|
QMap<QString, QString> rawConfig;
|
||||||
rawConfig[QString("ACPIPATH")] = QString("/sys/class/power_supply/");
|
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("GPUDEV")] = QString("auto");
|
||||||
rawConfig[QString("HDDDEV")] = QString("all");
|
rawConfig[QString("HDDDEV")] = QString("all");
|
||||||
rawConfig[QString("HDDTEMPCMD")] = QString("sudo hddtemp");
|
rawConfig[QString("HDDTEMPCMD")] = QString("sudo hddtemp");
|
||||||
@ -251,15 +213,12 @@ QMap<QString, QString> ExtendedSysMon::updateConfiguration(const QMap<QString, Q
|
|||||||
key = rawConfig.keys()[i];
|
key = rawConfig.keys()[i];
|
||||||
value = rawConfig[key];
|
value = rawConfig[key];
|
||||||
key.remove(QChar(' '));
|
key.remove(QChar(' '));
|
||||||
if ((key != QString("DESKTOPCMD")) &&
|
if ((key != QString("HDDTEMPCMD")) &&
|
||||||
(key != QString("HDDTEMPCMD")) &&
|
|
||||||
(key != QString("PKGCMD")))
|
(key != QString("PKGCMD")))
|
||||||
value.remove(QChar(' '));
|
value.remove(QChar(' '));
|
||||||
config[key] = value;
|
config[key] = value;
|
||||||
}
|
}
|
||||||
// update values
|
// update values
|
||||||
// desktop names
|
|
||||||
config[QString("DESKTOP")] = getDesktopNames().join(QString(";;"));
|
|
||||||
// gpudev
|
// gpudev
|
||||||
if (config[QString("GPUDEV")] == QString("disable"))
|
if (config[QString("GPUDEV")] == QString("disable"))
|
||||||
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;
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "cmd" << cmd;
|
|
||||||
|
|
||||||
TaskResult process = runTask(QString("bash -c \"") + cmd + QString("\""));
|
int number = KWindowSystem::currentDesktop();
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
|
int total = KWindowSystem::numberOfDesktops();
|
||||||
|
|
||||||
QString qoutput = QTextCodec::codecForMib(106)->toUnicode(process.output).trimmed();
|
|
||||||
int number = qoutput.toInt();
|
|
||||||
QMap<QString, QVariant> currentDesktop;
|
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("currentNumber")] = number;
|
||||||
currentDesktop[QString("list")] = configuration[QString("DESKTOP")];
|
QStringList list;
|
||||||
currentDesktop[QString("number")] = configuration[QString("DESKTOP")].split(QString(";;")).count();
|
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;
|
return currentDesktop;
|
||||||
}
|
}
|
||||||
@ -620,7 +578,7 @@ bool ExtendedSysMon::updateSourceEvent(const QString &source)
|
|||||||
times[i]++;
|
times[i]++;
|
||||||
}
|
}
|
||||||
} else if (source == QString("desktop")) {
|
} 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++)
|
for (int i=0; i<desktop.keys().count(); i++)
|
||||||
setData(source, desktop.keys()[i], desktop[desktop.keys()[i]]);
|
setData(source, desktop.keys()[i], desktop[desktop.keys()[i]]);
|
||||||
} else if (source == QString("gpu")) {
|
} else if (source == QString("gpu")) {
|
||||||
|
@ -32,7 +32,7 @@ public:
|
|||||||
ExtendedSysMon(QObject *parent, const QVariantList &args);
|
ExtendedSysMon(QObject *parent, const QVariantList &args);
|
||||||
// update functions
|
// update functions
|
||||||
QMap<QString, QVariant> getBattery(const QString acpiPath);
|
QMap<QString, QVariant> getBattery(const QString acpiPath);
|
||||||
QMap<QString, QVariant> getCurrentDesktop(const QString cmd);
|
QMap<QString, QVariant> getCurrentDesktop();
|
||||||
float getGpu(const QString device);
|
float getGpu(const QString device);
|
||||||
float getGpuTemp(const QString device);
|
float getGpuTemp(const QString device);
|
||||||
float getHddTemp(const QString cmd, const QString device);
|
float getHddTemp(const QString cmd, const QString device);
|
||||||
@ -58,7 +58,6 @@ private:
|
|||||||
QString getAllHdd();
|
QString getAllHdd();
|
||||||
QString getAutoGpu();
|
QString getAutoGpu();
|
||||||
QString getAutoMpris();
|
QString getAutoMpris();
|
||||||
QStringList getDesktopNames();
|
|
||||||
void initScripts();
|
void initScripts();
|
||||||
void readConfiguration();
|
void readConfiguration();
|
||||||
QMap<QString, QString> updateConfiguration(const QMap<QString, QString> rawConfig);
|
QMap<QString, QString> updateConfiguration(const QMap<QString, QString> rawConfig);
|
||||||
|
Loading…
Reference in New Issue
Block a user