From 16d7ca2005dab143a4aaf96b38116da4c7a6cbcd Mon Sep 17 00:00:00 2001 From: arcan1s Date: Mon, 17 Nov 2014 10:01:57 +0300 Subject: [PATCH] update extscript to inherit from QDialog --- sources/awesome-widget/CMakeLists.txt | 3 +- sources/awesome-widget/configuration.cpp | 6 +- sources/awesome-widget/desktopconfig.ui | 492 +++++++++++++++++++++++ sources/ext-sysmon/CMakeLists.txt | 5 +- sources/ext-sysmon/extscript.cpp | 15 +- sources/ext-sysmon/extscript.h | 22 +- sources/ext-sysmon/extscript.ui | 67 +++ sources/ext-sysmon/extsysmon.cpp | 2 +- sources/graphicalitem.cpp | 384 ------------------ sources/graphicalitem.h | 87 ---- 10 files changed, 592 insertions(+), 491 deletions(-) create mode 100644 sources/awesome-widget/desktopconfig.ui create mode 100644 sources/ext-sysmon/extscript.ui delete mode 100644 sources/graphicalitem.cpp delete mode 100644 sources/graphicalitem.h diff --git a/sources/awesome-widget/CMakeLists.txt b/sources/awesome-widget/CMakeLists.txt index 943e811..a562b56 100644 --- a/sources/awesome-widget/CMakeLists.txt +++ b/sources/awesome-widget/CMakeLists.txt @@ -16,7 +16,8 @@ include_directories (${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/../ ${PROJECT_TRDPARTY_DIR} - ../ext-sysmon) + ../ext-sysmon + ${CMAKE_CURRENT_BINARY_DIR}/../ext-sysmon) # set sources file (GLOB SUBPROJECT_DESKTOP_IN *.desktop) diff --git a/sources/awesome-widget/configuration.cpp b/sources/awesome-widget/configuration.cpp index f31e3ec..cfc9fa4 100644 --- a/sources/awesome-widget/configuration.cpp +++ b/sources/awesome-widget/configuration.cpp @@ -585,7 +585,7 @@ void AwesomeWidget::configAccepted() deSettings[QString("ACPIPATH")] = uiDEConfig.lineEdit_acpi->text(); QStringList dirs = KGlobal::dirs()->findDirs("data", "plasma_engine_extsysmon/scripts"); for (int i=0; irowCount(); i++) { - ExtScript *script = new ExtScript(uiDEConfig.tableWidget_customCommand->item(i, 0)->text(), dirs, debug); + ExtScript *script = new ExtScript(0, uiDEConfig.tableWidget_customCommand->item(i, 0)->text(), dirs, debug); if (uiDEConfig.tableWidget_customCommand->item(i, 0)->checkState() == Qt::Checked) script->setActive(true); else @@ -862,7 +862,7 @@ void AwesomeWidget::contextMenuCustomCommand(const QPoint pos) } else if (action == remove) { int row = uiDEConfig.tableWidget_customCommand->currentRow(); QStringList dirs = KGlobal::dirs()->findDirs("data", "plasma_engine_extsysmon/scripts"); - ExtScript *script = new ExtScript(uiDEConfig.tableWidget_customCommand->item(row, 0)->text(), dirs, debug); + ExtScript *script = new ExtScript(0, uiDEConfig.tableWidget_customCommand->item(row, 0)->text(), dirs, debug); script->tryDelete(); delete script; uiDEConfig.tableWidget_customCommand->removeRow(row); @@ -976,7 +976,7 @@ QList AwesomeWidget::initScripts() if (names.contains(files[j])) continue; if (debug) qDebug() << PDEBUG << ":" << "Found file" << files[j] << "in" << dirs[i]; names.append(files[j]); - externalScripts.append(new ExtScript(files[j], dirs, debug)); + externalScripts.append(new ExtScript(0, files[j], dirs, debug)); } } diff --git a/sources/awesome-widget/desktopconfig.ui b/sources/awesome-widget/desktopconfig.ui new file mode 100644 index 0000000..817fc65 --- /dev/null +++ b/sources/awesome-widget/desktopconfig.ui @@ -0,0 +1,492 @@ + + + DEWindow + + + + 0 + 0 + 700 + 584 + + + + + 0 + 0 + + + + + 700 + 0 + + + + + 16777215 + 16777215 + + + + DE + + + + + + true + + + + + 0 + 0 + 684 + 568 + + + + + + + + + + 200 + 0 + + + + hddtemp cmd + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + + 200 + 0 + + + + GPU device + + + + + + + + 0 + 0 + + + + + 100 + 0 + + + + + auto + + + + + disable + + + + + nvidia + + + + + ati + + + + + + + + + + + + + 200 + 0 + + + + HDD + + + + + + + + 0 + 0 + + + + + 100 + 0 + + + + + + + + + + + + + 200 + 0 + + + + Music player + + + + + + + + 0 + 0 + + + + + 100 + 0 + + + + + mpris + + + + + mpd + + + + + + + + + + + + + 200 + 0 + + + + MPD port + + + + + + + Qt::Horizontal + + + + 40 + 19 + + + + + + + + + 180 + 0 + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + 0 + + + 50000 + + + 100 + + + 6600 + + + + + + + + + + + + 200 + 0 + + + + MPD address + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + 200 + 0 + + + + ACPI path + + + + + + + "/sys/class/power_supply/" by default + + + + + + + + + Qt::CustomContextMenu + + + QAbstractItemView::SingleSelection + + + true + + + false + + + + Name + + + + + Interval + + + + + Output + + + + + Prefix + + + + + Redirect + + + + + + + + + + <b>NOTE:</b> Player DBus interface should be an active + + + Qt::AlignCenter + + + + + + + + + + 200 + 0 + + + + MPRIS player name + + + + + + + + 0 + 0 + + + + + 100 + 0 + + + + true + + + + auto + + + + + amarok + + + + + audacious + + + + + clementine + + + + + deadbeef + + + + + vlc + + + + + qmmp + + + + + xmms2 + + + + + + + + + + + + + + Qt::CustomContextMenu + + + Editable +del - remove item + + + QAbstractItemView::SingleSelection + + + true + + + false + + + + Package manager + + + + + Null lines + + + + + + + + + + + + + + + diff --git a/sources/ext-sysmon/CMakeLists.txt b/sources/ext-sysmon/CMakeLists.txt index 2bdb51e..7867ba5 100644 --- a/sources/ext-sysmon/CMakeLists.txt +++ b/sources/ext-sysmon/CMakeLists.txt @@ -1,5 +1,7 @@ # set project name set (SUBPROJECT plasma_engine_extsysmon) +set (PLUGIN_NAME ${SUBPROJECT}) +message (STATUS "Subproject ${SUBPROJECT}") # find required libaries find_package (KDE4 REQUIRED) @@ -13,11 +15,11 @@ include_directories (${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/../ ${PROJECT_TRDPARTY_DIR}) -set (PLUGIN_NAME ${SUBPROJECT}) file (GLOB SUBPROJECT_DESKTOP_IN *.desktop) file (RELATIVE_PATH SUBPROJECT_DESKTOP ${CMAKE_SOURCE_DIR} ${SUBPROJECT_DESKTOP_IN}) 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) file (GLOB SUBPROJECT_CONF *.conf) set (SUBPROJECT_SCRIPTS ${CMAKE_CURRENT_SOURCE_DIR}/scripts) @@ -26,6 +28,7 @@ configure_file (${SUBPROJECT_DESKTOP_IN} ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJEC # make qt4_wrap_cpp (TASK_MOC_SOURCE ${TASK_HEADER}) +kde4_add_ui_files (SUBPROJECT_SOURCE ${SUBPROJECT_UI}) kde4_add_plugin (${PLUGIN_NAME} ${SUBPROJECT_SOURCE} ${TASK_MOC_SOURCE}) target_link_libraries (${PLUGIN_NAME} ${KDE4_KDECORE_LIBS} ${KDE4_PLASMA_LIBS}) diff --git a/sources/ext-sysmon/extscript.cpp b/sources/ext-sysmon/extscript.cpp index 83527dd..389d769 100644 --- a/sources/ext-sysmon/extscript.cpp +++ b/sources/ext-sysmon/extscript.cpp @@ -16,6 +16,7 @@ ***************************************************************************/ #include "extscript.h" +#include "ui_extscript.h" #include #include @@ -25,19 +26,23 @@ #include -ExtScript::ExtScript(const QString scriptName, const QStringList directories, const bool debugCmd) - : QObject(0), - name(scriptName), - dirs(directories), - debug(debugCmd) +ExtScript::ExtScript(QWidget *parent, const QString scriptName, const QStringList directories, const bool debugCmd) : + QDialog(parent), + name(scriptName), + dirs(directories), + debug(debugCmd), + ui(new Ui::ExtScript) { readConfiguration(); + ui->setupUi(this); } ExtScript::~ExtScript() { if (debug) qDebug() << PDEBUG; + + delete ui; } diff --git a/sources/ext-sysmon/extscript.h b/sources/ext-sysmon/extscript.h index b24d3a5..a841d3f 100644 --- a/sources/ext-sysmon/extscript.h +++ b/sources/ext-sysmon/extscript.h @@ -18,11 +18,14 @@ #ifndef EXTSCRIPT_H #define EXTSCRIPT_H -#include -#include +#include -class ExtScript : public QObject +namespace Ui { +class ExtScript; +} + +class ExtScript : public QDialog { Q_OBJECT @@ -38,8 +41,8 @@ public: QString output; bool refresh; } ScriptData; - - ExtScript(const QString scriptName, const QStringList directories, const bool debugCmd = false); + explicit ExtScript(QWidget *parent = 0, const QString scriptName = QString(), + const QStringList directories = QStringList(), const bool debugCmd = false); ~ExtScript(); // configuration void addDirectory(const QString dir); @@ -63,21 +66,22 @@ public slots: void tryDelete(); void writeConfiguration(); + private: + QString name; + QStringList dirs; + bool debug; + Ui::ExtScript *ui; // configuration void fromExternalConfiguration(const QMap settings); QMap getConfigurationFromFile(const QString fileName); QMap toExternalConfiguration(); // properties bool active = true; - QString name; - QStringList dirs; int interval = 1; bool output = true; QString prefix = QString(""); Redirect redirect = nothing; - // other - bool debug; }; diff --git a/sources/ext-sysmon/extscript.ui b/sources/ext-sysmon/extscript.ui new file mode 100644 index 0000000..d2dd7df --- /dev/null +++ b/sources/ext-sysmon/extscript.ui @@ -0,0 +1,67 @@ + + ExtScript + + + + 0 + 0 + 240 + 320 + + + + Dialog + + + + + 10 + 270 + 221 + 41 + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + buttonBox + accepted() + ExtScript + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + ExtScript + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/sources/ext-sysmon/extsysmon.cpp b/sources/ext-sysmon/extsysmon.cpp index 68cb1c2..14b643c 100644 --- a/sources/ext-sysmon/extsysmon.cpp +++ b/sources/ext-sysmon/extsysmon.cpp @@ -130,7 +130,7 @@ void ExtendedSysMon::initScripts() if (names.contains(files[j])) continue; if (debug) qDebug() << PDEBUG << ":" << "Found file" << files[j] << "in" << dirs[i]; names.append(files[j]); - externalScripts.append(new ExtScript(files[j], dirs, debug)); + externalScripts.append(new ExtScript(0, files[j], dirs, debug)); times.append(1); } } diff --git a/sources/graphicalitem.cpp b/sources/graphicalitem.cpp deleted file mode 100644 index 4b2e659..0000000 --- a/sources/graphicalitem.cpp +++ /dev/null @@ -1,384 +0,0 @@ -/*************************************************************************** - * This file is part of awesome-widgets * - * * - * awesome-widgets is free software: you can redistribute it and/or * - * modify it under the terms of the GNU General Public License as * - * published by the Free Software Foundation, either version 3 of the * - * License, or (at your option) any later version. * - * * - * awesome-widgets is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * - ***************************************************************************/ - -#include "graphicalitem.h" - -#include -#include -#include -#include -#include -#include -#include - -#include - - -GraphicalItem::GraphicalItem(const QString desktopName, const QStringList directories, const bool debugCmd) - : fileName(desktopName), - dirs(directories), - debug(debugCmd) -{ - readConfiguration(); -} - - -GraphicalItem::~GraphicalItem() -{ - if (debug) qDebug() << PDEBUG; -} - - -QString GraphicalItem::getImage(const float value) -{ - if (debug) qDebug() << PDEBUG; - if (debug) qDebug() << PDEBUG << ":" << "Value" << value; - if (_bar == QString("none")) return QString(""); - - float percent = value / 100.0; - int scale[2] = {1, 1}; - QPen pen = QPen(); - QGraphicsScene *scene = new QGraphicsScene(); - scene->setBackgroundBrush(QBrush(Qt::NoBrush)); - QGraphicsView *view = new QGraphicsView(scene); - view->setStyleSheet(QString("background: transparent")); - view->setContentsMargins(0, 0, 0, 0); - view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - view->resize(_width + 5.0, _height + 5.0); - - // paint - switch(_type) { - case Vertical: - pen.setWidth(_width); - // inactive - 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); - // scale - 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)); - 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)); - circle->setSpanAngle(percent * 360.0 * 16.0); - circle->setStartAngle(180.0 * 16.0); - // scale - scale[0] = (int)_direction; - break; - default: - pen.setWidth(_height); - // inactive - 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); - // scale - scale[0] = (int)_direction; - break; - } - - // convert - QPixmap pixmap = QPixmap::grabWidget(view).transformed(QTransform().scale(scale[0], scale[1])); - QByteArray byteArray; - QBuffer buffer(&byteArray); - pixmap.save(&buffer, "PNG"); - QString url = QString("").arg(QString(byteArray.toBase64())); - delete view; - delete scene; - - return url; -} - - -QString GraphicalItem::getName() -{ - if (debug) qDebug() << PDEBUG; - - return _name; -} - - -QString GraphicalItem::getComment() -{ - if (debug) qDebug() << PDEBUG; - - return _comment; -} - - -QString GraphicalItem::getBar() -{ - if (debug) qDebug() << PDEBUG; - - return _bar; -} - - -QColor GraphicalItem::getActiveColor() -{ - if (debug) qDebug() << PDEBUG; - - return _activeColor; -} - - -QColor GraphicalItem::getInactiveColor() -{ - if (debug) qDebug() << PDEBUG; - - return _inactiveColor; -} - - -GraphicalItem::Type GraphicalItem::getType() -{ - if (debug) qDebug() << PDEBUG; - - return _type; -} - - -GraphicalItem::Direction GraphicalItem::getDirection() -{ - if (debug) qDebug() << PDEBUG; - - return _direction; -} - - -int GraphicalItem::getHeight() -{ - if (debug) qDebug() << PDEBUG; - - return _height; -} - - -int GraphicalItem::getWidth() -{ - if (debug) qDebug() << PDEBUG; - - return _width; -} - - -void GraphicalItem::setName(const QString name) -{ - if (debug) qDebug() << PDEBUG; - if (debug) qDebug() << PDEBUG << ":" << "Name" << name; - - _name = name; -} - - -void GraphicalItem::setComment(const QString comment) -{ - if (debug) qDebug() << PDEBUG; - if (debug) qDebug() << PDEBUG << ":" << "Comment" << comment; - - _comment = comment; -} - - -void GraphicalItem::setBar(const QString bar) -{ - if (debug) qDebug() << PDEBUG; - if (debug) qDebug() << PDEBUG << ":" << "Bar" << bar; - - _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 -#include - - -class GraphicalItem : public QObject -{ - Q_OBJECT - -public: - enum Direction { - RightToLeft = -1, - LeftToRight = 1 - }; - enum Type { - Horizontal = 0, - Vertical, - Circle - }; - - GraphicalItem(const QString desktopName, const QStringList directories, const bool debugCmd = false); - ~GraphicalItem(); - QString getImage(const float value); - // get methods - QString getName(); - QString getComment(); - QString getBar(); - QColor getActiveColor(); - QColor getInactiveColor(); - Type getType(); - Direction getDirection(); - int getHeight(); - int getWidth(); - // set methods - void setName(const QString name); - void setComment(const QString comment); - void setBar(const QString bar); - void setActiveColor(const QColor color); - void setInactiveColor(const QColor color); - void setType(const QString type); - void setDirection(const QString direction); - void setHeight(const int height); - void setWidth(const int width); - -public slots: - void readConfiguration(); - void showConfiguration(); - void tryDelete(); - void writeConfiguration(); - -private: - QString fileName; - QStringList dirs; - bool debug; - // properties - 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; -}; - - -#endif /* GRAPHICALITEM_H */