From 8aafdb6fc49d2a69a8537c90bc1d2e253b4c54df Mon Sep 17 00:00:00 2001 From: arcan1s Date: Fri, 14 Nov 2014 04:19:53 +0300 Subject: [PATCH] update gi to use desktop conf files --- sources/awesome-widget/CMakeLists.txt | 2 + sources/awesome-widget/awesome-widget.cpp | 4 +- .../desktops/aw-bat-bar.desktop | 11 + .../desktops/aw-cpu-bar.desktop | 11 + .../desktops/aw-mem-bar.desktop | 11 + .../desktops/aw-swap-bar.desktop | 11 + sources/awesome-widget/graphicalitem.cpp | 307 ++++++++++++------ sources/awesome-widget/graphicalitem.h | 37 ++- 8 files changed, 282 insertions(+), 112 deletions(-) create mode 100644 sources/awesome-widget/desktops/aw-bat-bar.desktop create mode 100644 sources/awesome-widget/desktops/aw-cpu-bar.desktop create mode 100644 sources/awesome-widget/desktops/aw-mem-bar.desktop create mode 100644 sources/awesome-widget/desktops/aw-swap-bar.desktop diff --git a/sources/awesome-widget/CMakeLists.txt b/sources/awesome-widget/CMakeLists.txt index 52254eb..943e811 100644 --- a/sources/awesome-widget/CMakeLists.txt +++ b/sources/awesome-widget/CMakeLists.txt @@ -27,6 +27,7 @@ file (GLOB_RECURSE SUBPROJECT_SOURCE *.cpp ${PROJECT_TRDPARTY_DIR}/task/*.cpp set (TASK_HEADER ${PROJECT_TRDPARTY_DIR}/task/task.h) file (GLOB SUBPROJECT_UI *.ui ${PROJECT_TRDPARTY_DIR}/about/*.ui) file (GLOB SUBPROJECT_NOTIFY *.notifyrc) +set (SUBPROJECT_DESKTOPS ${CMAKE_CURRENT_SOURCE_DIR}/desktops) # prepare configure_file (${SUBPROJECT_DESKTOP_IN} ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT_DESKTOP}) @@ -41,3 +42,4 @@ target_link_libraries (${PLUGIN_NAME} ${KDE4_PLASMA_LIBS} ${KDE4_KDEUI_LIBS} ${K install (TARGETS ${PLUGIN_NAME} DESTINATION ${PLUGIN_INSTALL_DIR}) install (FILES ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT_DESKTOP} DESTINATION ${SERVICES_INSTALL_DIR}) install (FILES ${SUBPROJECT_NOTIFY} DESTINATION ${DATA_INSTALL_DIR}/${PLUGIN_NAME}) +install (DIRECTORY ${SUBPROJECT_DESKTOPS} DESTINATION ${DATA_INSTALL_DIR}/${PLUGIN_NAME}) diff --git a/sources/awesome-widget/awesome-widget.cpp b/sources/awesome-widget/awesome-widget.cpp index ce4a6b5..0395018 100644 --- a/sources/awesome-widget/awesome-widget.cpp +++ b/sources/awesome-widget/awesome-widget.cpp @@ -59,8 +59,8 @@ AwesomeWidget::AwesomeWidget(QObject *parent, const QVariantList &args) // text format init formatLine.append(QString("")); formatLine.append(QString("")); - GraphicalItem *item = new GraphicalItem(this, QString("test"), QString("${cpu;255,0,0,255;0,255,0,255;2;-1;300;500}"), true); - qDebug() << item->getImage(75.0); +// GraphicalItem *item = new GraphicalItem(this, QString("test"), QString("${cpu;255,0,0,255;0,255,0,255;2;-1;300;500}"), true); +// qDebug() << item->getImage(75.0); } diff --git a/sources/awesome-widget/desktops/aw-bat-bar.desktop b/sources/awesome-widget/desktops/aw-bat-bar.desktop new file mode 100644 index 0000000..d03d5de --- /dev/null +++ b/sources/awesome-widget/desktops/aw-bat-bar.desktop @@ -0,0 +1,11 @@ +[Desktop Entry] +Encoding=UTF-8 +Name=bar3 +Comment=Simple bat bar +X-AW-Value=bat +X-AW-ActiveColor="255,255,255,0" +X-AW-InactiveColor="255,255,255,255" +X-AW-Type=Horizontal +X-AW-Direction=LeftToRight +X-AW-Height=25 +X-AW-Width=100 diff --git a/sources/awesome-widget/desktops/aw-cpu-bar.desktop b/sources/awesome-widget/desktops/aw-cpu-bar.desktop new file mode 100644 index 0000000..3009a06 --- /dev/null +++ b/sources/awesome-widget/desktops/aw-cpu-bar.desktop @@ -0,0 +1,11 @@ +[Desktop Entry] +Encoding=UTF-8 +Name=bar0 +Comment=Simple cpu bar +X-AW-Value=cpu +X-AW-ActiveColor="255,255,255,0" +X-AW-InactiveColor="255,255,255,255" +X-AW-Type=Horizontal +X-AW-Direction=LeftToRight +X-AW-Height=25 +X-AW-Width=100 diff --git a/sources/awesome-widget/desktops/aw-mem-bar.desktop b/sources/awesome-widget/desktops/aw-mem-bar.desktop new file mode 100644 index 0000000..fdab752 --- /dev/null +++ b/sources/awesome-widget/desktops/aw-mem-bar.desktop @@ -0,0 +1,11 @@ +[Desktop Entry] +Encoding=UTF-8 +Name=bar1 +Comment=Simple mem bar +X-AW-Value=mem +X-AW-ActiveColor="255,255,255,0" +X-AW-InactiveColor="255,255,255,255" +X-AW-Type=Horizontal +X-AW-Direction=LeftToRight +X-AW-Height=25 +X-AW-Width=100 diff --git a/sources/awesome-widget/desktops/aw-swap-bar.desktop b/sources/awesome-widget/desktops/aw-swap-bar.desktop new file mode 100644 index 0000000..04a4c7b --- /dev/null +++ b/sources/awesome-widget/desktops/aw-swap-bar.desktop @@ -0,0 +1,11 @@ +[Desktop Entry] +Encoding=UTF-8 +Name=bar2 +Comment=Simple swap bar +X-AW-Value=swap +X-AW-ActiveColor="255,255,255,0" +X-AW-InactiveColor="255,255,255,255" +X-AW-Type=Horizontal +X-AW-Direction=LeftToRight +X-AW-Height=25 +X-AW-Width=100 diff --git a/sources/awesome-widget/graphicalitem.cpp b/sources/awesome-widget/graphicalitem.cpp index a3aa87f..3e0e5d5 100644 --- a/sources/awesome-widget/graphicalitem.cpp +++ b/sources/awesome-widget/graphicalitem.cpp @@ -19,21 +19,22 @@ #include #include +#include #include #include #include - +#include #include -GraphicalItem::GraphicalItem(QObject *wid, const QString assignName, const QString tag, const bool debugCmd) +GraphicalItem::GraphicalItem(QObject *wid, const QString desktopName, const QStringList directories, const bool debugCmd) : QObject(wid), - name(assignName), + fileName(desktopName), + dirs(directories), debug(debugCmd) { - if (debug) qDebug() << PDEBUG << ":" << "Name" << name; - parseTag(tag); + readConfiguration(); } @@ -47,7 +48,7 @@ QString GraphicalItem::getImage(const float value) { if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG << ":" << "Value" << value; - if (bar == QString("none")) return QString(""); + if (_bar == QString("none")) return QString(""); float percent = value / 100.0; int scale[2] = {1, 1}; @@ -59,47 +60,47 @@ QString GraphicalItem::getImage(const float value) view->setContentsMargins(0, 0, 0, 0); view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - view->resize(width + 5.0, height + 5.0); + view->resize(_width + 5.0, _height + 5.0); // paint - switch(type) { + switch(_type) { case Vertical: - pen.setWidth(width); + pen.setWidth(_width); // inactive - pen.setColor(inactiveColor); - scene->addLine(0.5 * width, 0.0, 0.5 * width, height, pen); + pen.setColor(_inactiveColor); + scene->addLine(0.5 * _width, 0.0, 0.5 * _width, _height, pen); // active - pen.setColor(activeColor); - scene->addLine(0.5 * width, (1.0 - percent) * height + 0.5 * width, 0.5 * width, height + 0.5 * width, pen); + pen.setColor(_activeColor); + scene->addLine(0.5 * _width, (1.0 - percent) * _height + 0.5 * _width, 0.5 * _width, _height + 0.5 * _width, pen); // scale - scale[1] = (int)direction; + scale[1] = (int)_direction; break; case Circle: QGraphicsEllipseItem *circle; pen.setWidth(1.0); // inactive - pen.setColor(inactiveColor); - circle = scene->addEllipse(0.0, 0.0, width, height, pen, QBrush(inactiveColor, Qt::SolidPattern)); + pen.setColor(_inactiveColor); + circle = scene->addEllipse(0.0, 0.0, _width, _height, pen, QBrush(_inactiveColor, Qt::SolidPattern)); circle->setSpanAngle((1.0 - percent) * 360.0 * 16.0); circle->setStartAngle(180.0 * 16.0 - (1.0 - percent) * 360.0 * 16.0); // active - pen.setColor(activeColor); - circle = scene->addEllipse(0.0, 0.0, width, height, pen, QBrush(activeColor, Qt::SolidPattern)); + pen.setColor(_activeColor); + circle = scene->addEllipse(0.0, 0.0, _width, _height, pen, QBrush(_activeColor, Qt::SolidPattern)); circle->setSpanAngle(percent * 360.0 * 16.0); circle->setStartAngle(180.0 * 16.0); // scale - scale[0] = (int)direction; + scale[0] = (int)_direction; break; default: - pen.setWidth(height); + pen.setWidth(_height); // inactive - pen.setColor(inactiveColor); - scene->addLine(0.0, 0.5 * height, width, 0.5 * height, pen); + pen.setColor(_inactiveColor); + scene->addLine(0.0, 0.5 * _height, _width, 0.5 * _height, pen); // active - pen.setColor(activeColor); - scene->addLine(-0.5 * height, 0.5 * height, percent * width - 0.5 * height, 0.5 * height, pen); + pen.setColor(_activeColor); + scene->addLine(-0.5 * _height, 0.5 * _height, percent * _width - 0.5 * _height, 0.5 * _height, pen); // scale - scale[0] = (int)direction; + scale[0] = (int)_direction; break; } @@ -120,7 +121,15 @@ QString GraphicalItem::getName() { if (debug) qDebug() << PDEBUG; - return name; + return _name; +} + + +QString GraphicalItem::getComment() +{ + if (debug) qDebug() << PDEBUG; + + return _comment; } @@ -128,7 +137,7 @@ QString GraphicalItem::getBar() { if (debug) qDebug() << PDEBUG; - return bar; + return _bar; } @@ -136,7 +145,7 @@ QColor GraphicalItem::getActiveColor() { if (debug) qDebug() << PDEBUG; - return activeColor; + return _activeColor; } @@ -144,7 +153,7 @@ QColor GraphicalItem::getInactiveColor() { if (debug) qDebug() << PDEBUG; - return inactiveColor; + return _inactiveColor; } @@ -152,7 +161,7 @@ GraphicalItem::Type GraphicalItem::getType() { if (debug) qDebug() << PDEBUG; - return type; + return _type; } @@ -160,7 +169,7 @@ GraphicalItem::Direction GraphicalItem::getDirection() { if (debug) qDebug() << PDEBUG; - return direction; + return _direction; } @@ -168,7 +177,7 @@ int GraphicalItem::getHeight() { if (debug) qDebug() << PDEBUG; - return height; + return _height; } @@ -176,86 +185,186 @@ int GraphicalItem::getWidth() { if (debug) qDebug() << PDEBUG; - return width; + return _width; } -QList GraphicalItem::parseColor(const QString stringColor) +void GraphicalItem::setName(const QString name) { if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Name" << name; - QList color; - color.append(0); - color.append(0); - color.append(0); - color.append(0); - - QStringList colors = stringColor.split(QChar(',')); - for (int i=0; i 0) - bar = parsedTag[0]; - if (parsedTag.count() > 1) { - QList color = parseColor(parsedTag[1]); - activeColor = QColor(color[0], color[1], color[2], color[3]); - } - if (parsedTag.count() > 2) { - QList color = parseColor(parsedTag[2]); - inactiveColor = QColor(color[0], color[1], color[2], color[3]); - } - if (parsedTag.count() > 3) - switch(parsedTag[3].toInt()) { - case Vertical: - type = Vertical; - break; - case Circle: - type = Circle; - break; - default: - type = Horizontal; - break; - } - if (parsedTag.count() > 4) - switch (parsedTag[4].toInt()) { - case RightToLeft: - direction = RightToLeft; - break; - default: - direction = LeftToRight; - break; - } - if (parsedTag.count() > 5) - height = parsedTag[5].toInt(); - if (parsedTag.count() > 6) - width = parsedTag[6].toInt(); - - if ((!bar.contains(QRegExp(QString("cpu(?!cl).*")))) && - (!bar.contains(QRegExp(QString("gpu")))) && - (!bar.contains(QRegExp(QString("mem")))) && - (!bar.contains(QRegExp(QString("swap")))) && - (!bar.contains(QRegExp(QString("hdd[0-9].*")))) && - (!bar.contains(QRegExp(QString("bat.*"))))) - bar = QString("none"); +void GraphicalItem::setBar(const QString bar) +{ + if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG << ":" << "Bar" << bar; - if (debug) qDebug() << PDEBUG << ":" << "Active color" << activeColor; - if (debug) qDebug() << PDEBUG << ":" << "Inactive color" << inactiveColor; - if (debug) qDebug() << PDEBUG << ":" << "Type" << type; - if (debug) qDebug() << PDEBUG << ":" << "Direction" << direction; - if (debug) qDebug() << PDEBUG << ":" << "Size" << height << width; + + _bar = bar; + if ((!_bar.contains(QRegExp(QString("cpu(?!cl).*")))) && + (!_bar.contains(QRegExp(QString("gpu")))) && + (!_bar.contains(QRegExp(QString("mem")))) && + (!_bar.contains(QRegExp(QString("swap")))) && + (!_bar.contains(QRegExp(QString("hdd[0-9].*")))) && + (!_bar.contains(QRegExp(QString("bat.*"))))) + _bar = QString("none"); +} + + +void GraphicalItem::setActiveColor(const QColor color) +{ + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Color" << color; + + _activeColor = color; +} + + +void GraphicalItem::setInactiveColor(const QColor color) +{ + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Color" << color; + + _inactiveColor = color; +} + + +void GraphicalItem::setType(const QString type) +{ + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Type" << type; + + if (type == QString("Vertical")) + _type = Vertical; + else if (type == QString("Circle")) + _type = Circle; + else + _type = Horizontal; +} + + +void GraphicalItem::setDirection(const QString direction) +{ + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Direction" << direction; + + if (direction == QString("RightToLeft")) + _direction = RightToLeft; + else + _direction = LeftToRight; +} + + +void GraphicalItem::setHeight(const int height) +{ + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Height" << height; + + _height = height; +} + + +void GraphicalItem::setWidth(const int width) +{ + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Width" << width; + + _width = width; +} + + +void GraphicalItem::readConfiguration() +{ + if (debug) qDebug() << PDEBUG; + + for (int i=dirs.count()-1; i>=0; i--) { + if (!QDir(dirs[i]).entryList(QDir::Files).contains(fileName)) continue; + QSettings settings(dirs[i] + QDir::separator() + fileName, QSettings::IniFormat); + settings.beginGroup(QString("Desktop Entry")); + QStringList childKeys = settings.childKeys(); + for (int i=0; i parseColor(const QString stringColor); - QString name; + QString fileName; + QStringList dirs; bool debug; // properties - QString bar = QString("cpu"); - QColor activeColor = QColor(QString("#ffffff")); - QColor inactiveColor = QColor(QString("#000000")); - Type type = Horizontal; - Direction direction; - int height = 100; - int width = 100; + QString _name = QString("none"); + QString _comment = QString("empty"); + QString _bar = QString("cpu"); + QColor _activeColor = QColor(255, 255, 255, 0); + QColor _inactiveColor = QColor(255, 255, 255, 255); + Type _type = Horizontal; + Direction _direction = LeftToRight; + int _height = 100; + int _width = 100; };