From 3a0cbee39ffb9099e0bf7d97731f63b795591691 Mon Sep 17 00:00:00 2001 From: arcan1s Date: Wed, 21 Jan 2015 08:06:48 +0300 Subject: [PATCH] realize keys methods --- sources/.kdev4/sources.kdev4 | 23 ++ .../package/contents/config/config.qml | 29 +++ .../package/contents/config/main.xml | 143 ++++++++++++ .../package/contents/ui/main.qml | 140 ++++++++++++ sources/awesome-widget-kf5/plugin/.directory | 3 - .../awesome-widget-kf5/plugin/awactions.cpp | 2 +- .../awesome-widget-kf5/plugin/awdesources.cpp | 203 ++++++++++++++++++ .../awesome-widget-kf5/plugin/awdesources.h | 54 +++++ sources/awesome-widget-kf5/plugin/awkeys.cpp | 17 +- sources/awesome-widget-kf5/plugin/awkeys.h | 2 + sources/sources.kdev4 | 3 + 11 files changed, 614 insertions(+), 5 deletions(-) create mode 100644 sources/.kdev4/sources.kdev4 create mode 100644 sources/awesome-widget-kf5/package/contents/config/config.qml create mode 100644 sources/awesome-widget-kf5/package/contents/config/main.xml create mode 100644 sources/awesome-widget-kf5/package/contents/ui/main.qml delete mode 100644 sources/awesome-widget-kf5/plugin/.directory create mode 100644 sources/awesome-widget-kf5/plugin/awdesources.cpp create mode 100644 sources/awesome-widget-kf5/plugin/awdesources.h create mode 100644 sources/sources.kdev4 diff --git a/sources/.kdev4/sources.kdev4 b/sources/.kdev4/sources.kdev4 new file mode 100644 index 0000000..69e987e --- /dev/null +++ b/sources/.kdev4/sources.kdev4 @@ -0,0 +1,23 @@ +[Buildset] +BuildItems=@Variant(\x00\x00\x00\t\x00\x00\x00\x00\x01\x00\x00\x00\x0b\x00\x00\x00\x00\x01\x00\x00\x00\x1e\x00a\x00w\x00e\x00s\x00o\x00m\x00e\x00-\x00w\x00i\x00d\x00g\x00e\x00t\x00s) + +[CMake] +Build Directory Count=1 +Current Build Directory Index=0 +ProjectRootRelative=./ + +[CMake][CMake Build Directory 0] +Build Directory Path=file:///home/arcanis/Documents/github/awesome-widgets/build +Build Type=Debug +CMake Binary=file:///usr/bin/cmake +Environment Profile= +Extra Arguments= +Install Directory= + +[Defines And Includes][Compiler] +Name=GCC +Path=gcc +Type=GCC + +[Project] +VersionControlSupport=kdevgit diff --git a/sources/awesome-widget-kf5/package/contents/config/config.qml b/sources/awesome-widget-kf5/package/contents/config/config.qml new file mode 100644 index 0000000..b91a83d --- /dev/null +++ b/sources/awesome-widget-kf5/package/contents/config/config.qml @@ -0,0 +1,29 @@ +/*************************************************************************** + * 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/ * + ***************************************************************************/ + +import QtQuick 2.0 + +import org.kde.plasma.configuration 2.0 + + +ConfigModel { +// ConfigCategory { +// name: i18n("Widget") +// icon: "utilities-system-monitor" +// source: "widget.qml" +// } +} diff --git a/sources/awesome-widget-kf5/package/contents/config/main.xml b/sources/awesome-widget-kf5/package/contents/config/main.xml new file mode 100644 index 0000000..04e44f3 --- /dev/null +++ b/sources/awesome-widget-kf5/package/contents/config/main.xml @@ -0,0 +1,143 @@ + + + + + + + + [cpu: $cpu%] [mem: $mem%] [swap: $swap%] [$netdev: $down/$upKB/s] + + + + + + + true + + + true + + + $hh:$mm + + + $dd,$hh,$mm + + + Celsius + + + + + + + + + / + + + /dev/sda + + + disk/sda_(8:0) + + + + + + (*) + + + ( ) + + + true + + + + + + 100 + + + true + + + #ffffff + + + true + + + #ff0000 + + + true + + + #00ff00 + + + true + + + #0000ff + + + true + + + #ffff00 + + + true + + + #00ffff + + + true + + + #ff00ff + + + true + + + #008800 + + + #880000 + + + + + + + 1000 + + + center + + + Terminus + + + 12 + + + #000000 + + + normal + + + normal + + + + diff --git a/sources/awesome-widget-kf5/package/contents/ui/main.qml b/sources/awesome-widget-kf5/package/contents/ui/main.qml new file mode 100644 index 0000000..35c9653 --- /dev/null +++ b/sources/awesome-widget-kf5/package/contents/ui/main.qml @@ -0,0 +1,140 @@ +/*************************************************************************** + * 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/ * + ***************************************************************************/ + +import QtQuick 2.4 +import QtQuick.Controls 1.3 as QtControls +import org.kde.plasma.plasmoid 2.0 +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.plasma.components 2.0 as PlasmaComponents + +import org.kde.plasma.private.awesome-widget 1.0 + + +Item { + id: main + + // variables + // internal + property bool debug: AWKeys.isDebugEnabled() + property variant fontWeight: { + "light": Font.Light, + "normal": Font.Normal, + "demibold": Font.DemiBold, + "bold": Font.Bold, + "black": Font.Black + } + property variant align: { + "left": Text.AlignLeft, + "center": Text.AlignHCenter, + "right": Text.AlignRight, + "justify": Text.AlignJustify + } + // external + property variant info: { + } + property string pattern: plasmoid.configuration.text + // signals + signal needUpdate + + // init + Plasmoid.icon: "utilities-system-monitor" + Plasmoid.backgroundHints: "DefaultBackground" + Plasmoid.toolTipMainText: "Awesome Widget" + Plasmoid.associatedApplication: "ksysguard" + + PlasmaCore.DataSource { + id: systemmonitorDE + engine: "systemmonitor" + connectedSources: ["active", "current", "extip4", "extip6", "interfaces", "intip4", "intip6", "profiles", "status"] + interval: plasmoid.configuration.interval + + onNewData: { + if (debug) console.log("[main::onNewData] : Update source " + sourceName) + + if ((data.value == "N\\A") || (data.value == "")) return + // update + info[sourceName] = data.value + } + } + + PlasmaCore.DataSource { + id: extsysmonDE + engine: "ext-sysmon" + connectedSources: ["update"] + interval: plasmoid.configuration.interval + + onNewData: { + if (debug) console.log("[main::onNewData] : Update source " + sourceName) + + if (sourceName == "update") needUpdate() + } + } + + // ui + Grid { + id: mainGrid + columns: 1 + + Text { + id: text + color: plasmoid.configuration.fontColor + font.family: plasmoid.configuration.fontFamily + font.italic: plasmoid.configuration.fontStyle == "italic" ? true : false + font.pointSize: plasmoid.configuration.fontSize + font.weight: fontWeight[plasmoid.configuration.fontWeight] + horizontalAlignment: align[plasmoid.configuration.textAlign] + textFormat: Text.RichText + text: plasmoid.configuration.text + } + } + + Component.onCompleted: { + if (debug) console.log("[main::onCompleted]") + + // actions + plasmoid.setAction("showReadme", i18n("Show README"), "text-x-readme") + plasmoid.setAction("updateText", i18n("Update text"), "stock-refresh") + plasmoid.setAction("checkUpdates", i18n("Check updates"), "system-software-update") + } + + onNeedUpdate: { + if (debug) console.log("[main::onNeedUpdate]") + + text.text = AWKeys.parsePattern(pattern, info) + // update geometry + text.update() + height = text.contentHeight + width = text.contentWidth + update() + } + + function action_checkUpdates() { + if (debug) console.log("[main::action_checkUpdates]") + + AWActions.checkUpdates() + } + + function action_showReadme() { + if (debug) console.log("[main::action_showReadme]") + + AWActions.showReadme() + } + + function action_updateText() { + if (debug) console.log("[main::action_updateText]") + } +} diff --git a/sources/awesome-widget-kf5/plugin/.directory b/sources/awesome-widget-kf5/plugin/.directory deleted file mode 100644 index d629f4e..0000000 --- a/sources/awesome-widget-kf5/plugin/.directory +++ /dev/null @@ -1,3 +0,0 @@ -[Dolphin] -Timestamp=2015,1,19,23,14,34 -Version=3 diff --git a/sources/awesome-widget-kf5/plugin/awactions.cpp b/sources/awesome-widget-kf5/plugin/awactions.cpp index fc17d91..7604603 100644 --- a/sources/awesome-widget-kf5/plugin/awactions.cpp +++ b/sources/awesome-widget-kf5/plugin/awactions.cpp @@ -173,7 +173,7 @@ void AWActions::showUpdates(QString version) text += i18n("Click \"Ok\" to download"); int select = QMessageBox::information(0, i18n("There are updates"), text, QMessageBox::Ok | QMessageBox::Cancel); - switch(select) { + switch (select) { case QMessageBox::Ok: QDesktopServices::openUrl(QString(RELEASES) + version); break; diff --git a/sources/awesome-widget-kf5/plugin/awdesources.cpp b/sources/awesome-widget-kf5/plugin/awdesources.cpp new file mode 100644 index 0000000..ab5d0ff --- /dev/null +++ b/sources/awesome-widget-kf5/plugin/awdesources.cpp @@ -0,0 +1,203 @@ +/*************************************************************************** + * 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 "awdesources.h" + +#include +#include +#include + +#include + + +AWDESources::AWDESources(QObject *parent, const QString pattern, + const QStringList foundKeys, + const QStringList foundBars, + const QMap counts, + const QMap paths, + const QMap tooltipBools) + : QObject(parent), + m_pattern(pattern), + m_foundKeys(foundKeys), + m_foundBars(foundBars), + m_counts(counts), + m_paths(paths), + m_tooltipBools(tooltipBools) +{ + // debug + QProcessEnvironment environment = QProcessEnvironment::systemEnvironment(); + QString debugEnv = environment.value(QString("DEBUG"), QString("no")); + debug = (debugEnv == QString("yes")); +} + + +AWDESources::~AWDESources() +{ + if (debug) qDebug() << PDEBUG; +} + + +QStringList AWDESources::getSourcesForExtSystemMonitor() +{ + if (debug) qDebug() << PDEBUG; + + QStringList sources; + QRegExp regExp; + + // battery + regExp = QRegExp(QString("(^|bar[0-9].*)(ac|bat.*)")); + if ((m_foundKeys.indexOf(regExp) > -1) || + (m_foundBars.indexOf(regExp) > -1) || + (m_tooltipBools[QString("batteryTooltip")].toBool())) + sources.append(QString("battery")); + // custom command + regExp = QRegExp(QString("custom.*")); + if (m_foundKeys.indexOf(regExp) > -1) + sources.append(QString("custom")); + // desktop + regExp = QRegExp(QString(".*desktop.*")); + if (m_foundKeys.indexOf(regExp) > -1) + sources.append(QString("desktop")); + // gpu + regExp = QRegExp(QString("(^|bar[0-9].*)gpu")); + if ((m_foundKeys.indexOf(regExp) > -1) || + (m_foundBars.indexOf(regExp) > -1)) + sources.append(QString("gpu")); + // gpu temp + regExp = QRegExp(QString("gputemp")); + if (m_foundKeys.indexOf(regExp) > -1) + sources.append(QString("gputemp")); + // hdd temp + regExp = QRegExp(QString("hddtemp.*")); + if (m_foundKeys.indexOf(regExp) > -1) + sources.append(QString("hddtemp")); + // package manager + regExp = QRegExp(QString("pkgcount.*")); + if (m_foundKeys.indexOf(regExp) > -1) + sources.append(QString("pkg")); + // player + regExp = QRegExp(QString("(album|artist|duration|progress|title)")); + if (m_foundKeys.indexOf(regExp) > -1) + sources.append(QString("player")); + // ps + regExp = QRegExp(QString("ps.*")); + if (m_foundKeys.indexOf(regExp) > -1) + sources.append(QString("ps")); + // update == always true + sources.append(QString("update")); + + return sources; +} + + +QStringList AWDESources::getSourcesForSystemMonitor() +{ + if (debug) qDebug() << PDEBUG; + + QStringList sources; + QRegExp regExp; + + // cpu + regExp = QRegExp(QString("(^|bar[0-9].*)cpu(?!cl).*")); + if ((m_foundKeys.indexOf(regExp) > -1) || + (m_foundBars.indexOf(regExp) > -1) || + (m_tooltipBools[QString("cpuTooltip")].toBool())) { + sources.append(QString("cpu/system/TotalLoad")); + for (int i=0; i -1) || + (m_foundBars.indexOf(regExp) > -1) || + (m_tooltipBools[QString("cpuclTooltip")].toBool())) { + sources.append(QString("cpu/system/AverageClock")); + for (int i=0; i -1) + for (int i=0; i -1) + sources.append(m_paths[QString("fanDevice")].toString().split(QString("@@"))); + // mount + regExp = QRegExp(QString("(^|bar[0-9].*)hdd([0-9]|mb|gb|freemb|freegb|totmb|totgb).*")); + if ((m_foundKeys.indexOf(regExp) > -1) || + (m_foundBars.indexOf(regExp) > -1)) + for (int i=0; i -1) || + (m_foundBars.indexOf(regExp) > -1) || + (m_tooltipBools[QString("memTooltip")].toBool())) { + sources.append(QString("mem/physical/free")); + sources.append(QString("mem/physical/used")); + sources.append(QString("mem/physical/application")); + } + // network + regExp = QRegExp(QString("(down|up|netdev)")); + if ((m_foundKeys.indexOf(regExp) > -1) || + (m_tooltipBools[QString("downTooltip")].toBool())) { + sources.append(QString("network/interfaces/") + m_paths[QString("netdev")].toString() + QString("/transmitter/data")); + sources.append(QString("network/interfaces/") + m_paths[QString("netdev")].toString() + QString("/receiver/data")); + } + // swap + regExp = QRegExp(QString("(^|bar[0-9].*)swap.*")); + if ((m_foundKeys.indexOf(regExp) > -1) || + (m_foundBars.indexOf(regExp) > -1) || + (m_paths[QString("swapTooltip")].toBool())) { + sources.append(QString("mem/swap/free")); + sources.append(QString("mem/swap/used")); + } + // temp + regExp = QRegExp(QString("temp.*")); + if (m_foundKeys.indexOf(regExp) > -1) + sources.append(m_paths[QString("tempDevice")].toString().split(QString("@@"))); + // uptime + regExp = QRegExp(QString("(^|c)uptime")); + if (m_foundKeys.indexOf(regExp) > -1) + sources.append(QString("system/uptime")); + + return sources; +} + + +QStringList AWDESources::getSourcesForTimeMonitor() +{ + if (debug) qDebug() << PDEBUG; + + QStringList sources; + QRegExp regExp; + + // time + regExp = QRegExp(QString("(^|iso|short|long|c)time")); + if (m_foundKeys.indexOf(regExp) > -1) + sources.append(QString("Local")); + + return sources; +} + diff --git a/sources/awesome-widget-kf5/plugin/awdesources.h b/sources/awesome-widget-kf5/plugin/awdesources.h new file mode 100644 index 0000000..5cdf897 --- /dev/null +++ b/sources/awesome-widget-kf5/plugin/awdesources.h @@ -0,0 +1,54 @@ +/*************************************************************************** + * 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/ * + ***************************************************************************/ + + +#ifndef AWDESOURCES_H +#define AWDESOURCES_H + +#include +#include +#include + + +class AWDESources : public QObject +{ + Q_OBJECT + +public: + AWDESources(QObject *parent = 0, + const QString pattern = QString(""), + const QStringList foundKeys = QStringList(), + const QStringList foundBars = QStringList(), + const QMap counts = QMap(), + const QMap paths = QMap(), + const QMap tooltipBools = QMap()); + ~AWDESources(); + + QStringList getSourcesForExtSystemMonitor(); + QStringList getSourcesForSystemMonitor(); + QStringList getSourcesForTimeMonitor(); + +private: + // variables + bool debug = false; + QString m_pattern; + QStringList m_foundKeys, m_foundBars; + QMap m_counts, m_paths, m_tooltipBools; +}; + + +#endif /* AWDESOURCES_H */ diff --git a/sources/awesome-widget-kf5/plugin/awkeys.cpp b/sources/awesome-widget-kf5/plugin/awkeys.cpp index d6009f7..b1369cc 100644 --- a/sources/awesome-widget-kf5/plugin/awkeys.cpp +++ b/sources/awesome-widget-kf5/plugin/awkeys.cpp @@ -26,6 +26,7 @@ #include +#include "awdesources.h" #include "extscript.h" #include "graphicalitem.h" #include "version.h" @@ -133,13 +134,27 @@ QString AWKeys::parsePattern(const QString pattern, const QMap paths, + const QMap tooltipBools, + const QString dataEngine) { if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG << ":" << "Pattern" << pattern; if (debug) qDebug() << PDEBUG << ":" << "DataEngine" << dataEngine; + AWDESources *deSources = new AWDESources(this, pattern, foundKeys, foundBars, + counts(), paths, tooltipBools); + QStringList sources; + if (dataEngine == QString("ext-sysmon")) + sources = deSources->getSourcesForExtSystemMonitor(); + else if (dataEngine == QString("systemmonitor")) + sources = deSources->getSourcesForSystemMonitor(); + else if (dataEngine == QString("time")) + sources = deSources->getSourcesForTimeMonitor(); + delete deSources; + if (debug) qDebug() << PDEBUG << ":" << "Sources" << sources; return sources; } diff --git a/sources/awesome-widget-kf5/plugin/awkeys.h b/sources/awesome-widget-kf5/plugin/awkeys.h index 55a2e50..9d07e15 100644 --- a/sources/awesome-widget-kf5/plugin/awkeys.h +++ b/sources/awesome-widget-kf5/plugin/awkeys.h @@ -43,6 +43,8 @@ public: Q_INVOKABLE int numberCpus(); Q_INVOKABLE QString parsePattern(const QString pattern, const QMap values); Q_INVOKABLE QStringList sourcesForDataEngine(const QString pattern, + const QMap paths, + const QMap tooltipBools, const QString dataEngine = QString("systemmonitor")); Q_INVOKABLE float temperature(const float temp, const QString units = QString("Celsius")); // keys diff --git a/sources/sources.kdev4 b/sources/sources.kdev4 new file mode 100644 index 0000000..6458d9d --- /dev/null +++ b/sources/sources.kdev4 @@ -0,0 +1,3 @@ +[Project] +Manager=KDevCMakeManager +Name=awesome-widgets