mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-06-30 07:25:51 +00:00
Compare commits
101 Commits
Author | SHA1 | Date | |
---|---|---|---|
0a723aef82 | |||
271b8d55cf | |||
1afc33abef | |||
6b8244f3c4 | |||
ff2032cca1 | |||
05aafc43e7 | |||
d0c96ce829 | |||
6e62ceaac7 | |||
6e99e262d4 | |||
1b4d1d6944 | |||
8be4cc6e82 | |||
99c750fd0b | |||
fca8019972 | |||
8d3dd0ed96 | |||
4974948151 | |||
9e50ade6a5 | |||
801eea9a8b | |||
1841fb5ed2 | |||
9c8dbdcb41 | |||
53afc07457 | |||
1caecb427b | |||
ea10d526d5 | |||
b818586a23 | |||
a30e6ba21b | |||
fe38d9133b | |||
38c5589c10 | |||
ce09ab753b | |||
10f556e41b | |||
d097e154ff | |||
8979ddf52b | |||
d3dd9b3390 | |||
5615fd3ff9 | |||
cbb8415a95 | |||
8dcdae9611 | |||
bfdaadfc8b | |||
9543122816 | |||
6a24fc3f63 | |||
73d1b0a69f | |||
06f4882a2d | |||
7565ea2e82 | |||
004a97800c | |||
8dfb6b609f | |||
f893b34e19 | |||
a189e1af38 | |||
0332c59daf | |||
26b375254a | |||
89cb4b74fd | |||
ea1d5fca86 | |||
c3c46ff1b1 | |||
87406f70c4 | |||
d520f55afc | |||
77a94aa0c1 | |||
c103986f37 | |||
7568ae2a3b | |||
2ea5824fd7 | |||
47439ef151 | |||
63d19f038c | |||
9d5864aa62 | |||
d74cd645fd | |||
80767c9dbf | |||
57ad8a0a2b | |||
eea636c6f1 | |||
65141ff528 | |||
f882756fad | |||
335fbb137e | |||
fcb698e7fc | |||
f1b5208bb2 | |||
c9f5be6a60 | |||
f7094ca187 | |||
a326ebdabf | |||
3ee1d4c30e | |||
31c129163b | |||
80c994bce0 | |||
8aa6d0c626 | |||
33623fe75e | |||
ecf4be8d9c | |||
7f6a2d8100 | |||
086870e9c2 | |||
1c52cf72be | |||
8e598bbd13 | |||
877f58784b | |||
ee6cf60aa4 | |||
6449465be2 | |||
3403d1de50 | |||
f9ddf690c7 | |||
87652eb774 | |||
a9924a1432 | |||
c5cb5cb359 | |||
65c8f552de | |||
486267256c | |||
94e87ee570 | |||
b17aeb88e3 | |||
7d8036b0e1 | |||
4d1c05d737 | |||
95ede170d9 | |||
80d926290c | |||
5b9984d950 | |||
e5b1102abf | |||
f3f9239984 | |||
18c993c0d5 | |||
a9e3e3f087 |
28
.travis.yml
Normal file
28
.travis.yml
Normal file
@ -0,0 +1,28 @@
|
||||
sudo: required
|
||||
|
||||
arch:
|
||||
packages:
|
||||
- plasma-framework
|
||||
# build deps
|
||||
- cmake
|
||||
- extra-cmake-modules
|
||||
- python
|
||||
# test
|
||||
- xorg-server-xvfb
|
||||
# additional targets
|
||||
- clang
|
||||
- cppcheck
|
||||
script:
|
||||
- export DISPLAY=:99.0
|
||||
- git clone https://github.com/arcan1s/awesome-widgets/
|
||||
- cd awesome-widgets; git submodule update --init --recursive
|
||||
- mkdir awesome-widgets/build
|
||||
- cd awesome-widgets/build; cmake -DKDE_INSTALL_USE_QT_SYS_PATHS=ON -DCMAKE_BUILD_TYPE=Optimization -DCMAKE_INSTALL_PREFIX=/usr -DBUILD_FUTURE=ON -DBUILD_TESTING=ON ../sources
|
||||
- cd awesome-widgets/build; make
|
||||
- cd awesome-widgets/build; make cppcheck
|
||||
- cd awesome-widgets/build; make clangformat && ( [ `git status -s | wc -l` -eq 0 ] || exit 1 )
|
||||
- cd awesome-widgets/build; xvfb-run make test
|
||||
- sleep 3
|
||||
|
||||
script:
|
||||
- "curl -s https://raw.githubusercontent.com/mikkeloscar/arch-travis/master/arch-travis.sh | bash"
|
16
CHANGELOG
16
CHANGELOG
@ -1,3 +1,19 @@
|
||||
Ver.3.3.1:
|
||||
+ add ability to direct issue report (#104)
|
||||
+ add key completion (#105)
|
||||
+ add ability to load historical configuration (#106)
|
||||
+ add ability to upload configuration to remote server (#106)
|
||||
+ add stylish (#112)
|
||||
+ add DBus intergration (#115)
|
||||
+ add cron-like extenstion triggers (`X-AW-Socket` option) (#117)
|
||||
+ add ability to trigger extensions by calling socket (`X-AW-Schedule` option) (#118)
|
||||
+ add source for network requests
|
||||
+ add Json formatter
|
||||
- drop patches provided support for Qt 5.4
|
||||
* use custom signal slot connection for dataengine (`BUILD_FUTURE` flag required)
|
||||
* update UI
|
||||
* refactoring
|
||||
|
||||
Ver.3.2.1:
|
||||
+ add X-AW-Translate option to DateTime formatter
|
||||
+ add formatters to configuration export and import
|
||||
|
@ -37,31 +37,17 @@ for more details. To avoid manual labor there is automatic cmake target named
|
||||
|
||||
* `Q_PROPERTY` macro is allowed and recommended for QObject based classes.
|
||||
* Qt macros (e.g. `signals`, `slots`, `Q_OBJECT`, etc) are allowed. In other hand
|
||||
`Q_FOREACH` (`foreach`) is not allowed use `for (auto foo : bar)` instead.
|
||||
`Q_FOREACH` (`foreach`) is not allowed use `for (auto &foo : bar)` instead.
|
||||
* Current project standard is **C++11**.
|
||||
* Do not use C-like code:
|
||||
* C-like style iteration if possible. Use `for (auto foo : bar)` and
|
||||
* C-like style iteration if possible. Use `for (auto &foo : bar)` and
|
||||
`std::for_each` instead if possible. It is also recommended to use iterators.
|
||||
* C-like casts, use `const_cast`, `static_cast`, `dymanic_Cast` instead. Using
|
||||
of `reinterpret_cast` is not recommended. It is highly recommended to use
|
||||
`dynamic_cast` with the exception catching. It is also possible to use
|
||||
`qvariant_cast` if required. Exception is class constructors, e.g.:
|
||||
|
||||
```
|
||||
char c = 'c';
|
||||
std::string s = "string";
|
||||
qDebug() << QString("some string") << QChar(c) << QString(s);
|
||||
```
|
||||
|
||||
`qvariant_cast` if required.
|
||||
* C-like `NULL`, use `nullptr` instead.
|
||||
* It is highly recommended to avoid implicit casts. Exception `nullptr` casts to
|
||||
boolean, e.g.:
|
||||
|
||||
```
|
||||
if (nullptr)
|
||||
qDebug() << "nullptr is true, wtf";
|
||||
```
|
||||
|
||||
* C-like constant definition, use `const vartype foo = bar` definition instead.
|
||||
* Abstract classes (which have at least one pure virtual method) are allowed.
|
||||
* Templates are allowed and recommended. Templates usually should be described
|
||||
inside header not source code file.
|
||||
@ -91,6 +77,8 @@ for more details. To avoid manual labor there is automatic cmake target named
|
||||
* 'true ? foo : bar' construction is allowed and recommended for one-line assignment.
|
||||
* Any global pointer should be assign to `nullptr` after deletion and before
|
||||
initialization. Exception: if object is deleted into class destructor.
|
||||
* Do not use semicolon in qml files unless it is required.
|
||||
* Any method argument including class constructors should start with `_`.
|
||||
|
||||
Comments
|
||||
--------
|
||||
@ -176,8 +164,7 @@ Testing
|
||||
1. `-DCMAKE_BUILD_TYPE=Debug`.
|
||||
2. `-DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTING=ON`.
|
||||
3. `-DCMAKE_BUILD_TYPE=Release`.
|
||||
* It is recommended to create addition test if possible.
|
||||
* Addition test functions should be declated and used only inside `BUILD_TESTING`
|
||||
* Additional test functions should be declated and used only inside `BUILD_TESTING`
|
||||
definition.
|
||||
|
||||
Tools
|
||||
@ -208,9 +195,9 @@ Tools
|
||||
* Recommended class constructor for QObject based classes:
|
||||
|
||||
```
|
||||
FooClass::FooClass(QObject *parent, const QVariant var)
|
||||
: QObject(parent)
|
||||
, m_var(var)
|
||||
FooClass::FooClass(QObject *_parent, const QVariant _var)
|
||||
: QObject(_parent)
|
||||
, m_var(_var)
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
// some code below if any
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
pkgname=plasma5-applet-awesome-widgets
|
||||
_pkgname=awesome-widgets
|
||||
pkgver=3.2.1
|
||||
pkgver=3.3.1
|
||||
pkgrel=1
|
||||
pkgdesc="Collection of minimalistic Plasmoids which look like Awesome WM widgets (ex-PyTextMonitor)"
|
||||
arch=('i686' 'x86_64')
|
||||
@ -17,7 +17,7 @@ optdepends=("catalyst: for GPU monitor"
|
||||
makedepends=('cmake' 'extra-cmake-modules' 'python')
|
||||
source=(https://github.com/arcan1s/awesome-widgets/releases/download/V.${pkgver}/${_pkgname}-${pkgver}-src.tar.xz)
|
||||
install=${pkgname}.install
|
||||
md5sums=('73da19c31aa95edd428ff5ce7b541ee1')
|
||||
md5sums=('306027b017f940c9c5eaffb65ff82a7f')
|
||||
backup=('etc/xdg/plasma-dataengine-extsysmon.conf')
|
||||
|
||||
prepare() {
|
||||
|
@ -1,402 +0,0 @@
|
||||
diff --git a/sources/awesome-widget/package/contents/ui/advanced.qml b/sources/awesome-widget/package/contents/ui/advanced.qml
|
||||
index 01bcd58..1ec7ba6 100644
|
||||
--- a/sources/awesome-widget/package/contents/ui/advanced.qml
|
||||
+++ b/sources/awesome-widget/package/contents/ui/advanced.qml
|
||||
@@ -17,7 +17,6 @@
|
||||
|
||||
import QtQuick 2.0
|
||||
import QtQuick.Controls 1.3 as QtControls
|
||||
-import QtQuick.Dialogs 1.2 as QtDialogs
|
||||
|
||||
import org.kde.plasma.private.awesomewidget 1.0
|
||||
|
||||
@@ -372,32 +371,7 @@ Item {
|
||||
QtControls.Button {
|
||||
width: parent.width * 3 / 5
|
||||
text: i18n("Export configuration")
|
||||
- onClicked: saveConfigAs.open()
|
||||
- }
|
||||
-
|
||||
- QtDialogs.FileDialog {
|
||||
- id: saveConfigAs
|
||||
- selectExisting: false
|
||||
- title: i18n("Export")
|
||||
- folder: awConfig.configurationDirectory()
|
||||
- onAccepted: {
|
||||
- var status = awConfig.exportConfiguration(
|
||||
- plasmoid.configuration,
|
||||
- saveConfigAs.fileUrl.toString().replace("file://", ""))
|
||||
- if (status) {
|
||||
- messageDialog.title = i18n("Success")
|
||||
- messageDialog.text = i18n("Please note that binary files were not copied")
|
||||
- } else {
|
||||
- messageDialog.title = i18n("Ooops...")
|
||||
- messageDialog.text = i18n("Could not save configuration file")
|
||||
- }
|
||||
- messageDialog.open()
|
||||
- }
|
||||
- }
|
||||
-
|
||||
- QtDialogs.MessageDialog {
|
||||
- id: messageDialog
|
||||
- standardButtons: QtDialogs.StandardButton.Ok
|
||||
+ onClicked: awConfig.exportConfiguration(plasmoid.configuration)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -410,42 +385,9 @@ Item {
|
||||
QtControls.Button {
|
||||
width: parent.width * 3 / 5
|
||||
text: i18n("Import configuration")
|
||||
- onClicked: openConfig.open()
|
||||
- }
|
||||
-
|
||||
- QtDialogs.FileDialog {
|
||||
- id: openConfig
|
||||
- title: i18n("Import")
|
||||
- folder: awConfig.configurationDirectory()
|
||||
- onAccepted: importSelection.open()
|
||||
- }
|
||||
-
|
||||
- QtDialogs.Dialog {
|
||||
- id: importSelection
|
||||
-
|
||||
- Column {
|
||||
- QtControls.CheckBox {
|
||||
- id: importPlasmoid
|
||||
- text: i18n("Import plasmoid settings")
|
||||
- }
|
||||
-
|
||||
- QtControls.CheckBox {
|
||||
- id: importExtensions
|
||||
- text: i18n("Import extensions")
|
||||
- }
|
||||
-
|
||||
- QtControls.CheckBox {
|
||||
- id: importAdds
|
||||
- text: i18n("Import additional files")
|
||||
- }
|
||||
- }
|
||||
-
|
||||
- onAccepted: {
|
||||
+ onClicked: {
|
||||
if (debug) console.debug()
|
||||
- var importConfig = awConfig.importConfiguration(
|
||||
- openConfig.fileUrl.toString().replace("file://", ""),
|
||||
- importPlasmoid.checked, importExtensions.checked,
|
||||
- importAdds.checked)
|
||||
+ var importConfig = awConfig.importConfiguration()
|
||||
for (var key in importConfig)
|
||||
plasmoid.configuration[key] = importConfig[key]
|
||||
}
|
||||
diff --git a/sources/awesome-widget/package/contents/ui/main.qml b/sources/awesome-widget/package/contents/ui/main.qml
|
||||
index 23e9690..ec83b91 100644
|
||||
--- a/sources/awesome-widget/package/contents/ui/main.qml
|
||||
+++ b/sources/awesome-widget/package/contents/ui/main.qml
|
||||
@@ -17,7 +17,6 @@
|
||||
|
||||
import QtQuick 2.4
|
||||
import QtQuick.Controls 1.3 as QtControls
|
||||
-import QtQuick.Dialogs 1.2 as QtDialogs
|
||||
import QtQuick.Layouts 1.1
|
||||
import org.kde.plasma.plasmoid 2.0
|
||||
import org.kde.plasma.core 2.0 as PlasmaCore
|
||||
@@ -110,27 +109,6 @@ Item {
|
||||
}
|
||||
}
|
||||
|
||||
- QtDialogs.Dialog {
|
||||
- id: tagSelector
|
||||
- title: i18n("Select tag")
|
||||
-
|
||||
- QtControls.ComboBox {
|
||||
- id: tagSelectorBox
|
||||
- width: parent.width
|
||||
- editable: true
|
||||
- }
|
||||
-
|
||||
- onAccepted: {
|
||||
- var tag = tagSelectorBox.editText
|
||||
- var message = i18n("Tag: %1", tag)
|
||||
- message += "<br>"
|
||||
- message += i18n("Value: %1", awKeys.valueByKey(tag))
|
||||
- message += "<br>"
|
||||
- message += i18n("Info: %1", awKeys.infoByKey(tag))
|
||||
- awActions.sendNotification("tag", message)
|
||||
- }
|
||||
- }
|
||||
-
|
||||
|
||||
Component.onCompleted: {
|
||||
if (debug) console.debug()
|
||||
@@ -216,7 +194,12 @@ Item {
|
||||
function action_requestKey() {
|
||||
if (debug) console.debug()
|
||||
|
||||
- tagSelectorBox.model = awKeys.dictKeys(true)
|
||||
- return tagSelector.open()
|
||||
+ var tag = awKeys.graphicalKey()
|
||||
+ var message = i18n("Tag: %1", tag)
|
||||
+ message += "<br>"
|
||||
+ message += i18n("Value: %1", awKeys.valueByKey(tag))
|
||||
+ message += "<br>"
|
||||
+ message += i18n("Info: %1", awKeys.infoByKey(tag))
|
||||
+ awActions.sendNotification("tag", message)
|
||||
}
|
||||
}
|
||||
diff --git a/sources/awesome-widget/plugin/awconfighelper.cpp b/sources/awesome-widget/plugin/awconfighelper.cpp
|
||||
index 6263b30..5f61d2a 100644
|
||||
--- a/sources/awesome-widget/plugin/awconfighelper.cpp
|
||||
+++ b/sources/awesome-widget/plugin/awconfighelper.cpp
|
||||
@@ -19,10 +19,15 @@
|
||||
|
||||
#include <KI18n/KLocalizedString>
|
||||
|
||||
+#include <QCheckBox>
|
||||
+#include <QDialogButtonBox>
|
||||
#include <QDir>
|
||||
+#include <QFileDialog>
|
||||
+#include <QMessageBox>
|
||||
#include <QQmlPropertyMap>
|
||||
#include <QSettings>
|
||||
#include <QTextCodec>
|
||||
+#include <QVBoxLayout>
|
||||
|
||||
#include "awdebug.h"
|
||||
|
||||
@@ -50,11 +55,13 @@ bool AWConfigHelper::dropCache() const
|
||||
}
|
||||
|
||||
|
||||
-bool AWConfigHelper::exportConfiguration(const QObject *nativeConfig,
|
||||
- const QString fileName) const
|
||||
+void AWConfigHelper::exportConfiguration(const QObject *nativeConfig) const
|
||||
{
|
||||
- qCDebug(LOG_AW) << "Selected filename" << fileName;
|
||||
-
|
||||
+ // get file path and init settings object
|
||||
+ QString fileName = QFileDialog::getSaveFileName(nullptr, i18n("Export"));
|
||||
+ if (fileName.isEmpty())
|
||||
+ return;
|
||||
+ qCInfo(LOG_AW) << "Selected filename" << fileName;
|
||||
QSettings settings(fileName, QSettings::IniFormat);
|
||||
|
||||
// plasmoid configuration
|
||||
@@ -96,22 +103,33 @@ bool AWConfigHelper::exportConfiguration(QObject *nativeConfig,
|
||||
// sync settings
|
||||
settings.sync();
|
||||
// show additional message
|
||||
- return settings.status() == QSettings::NoError;
|
||||
+ switch (settings.status()) {
|
||||
+ case QSettings::NoError:
|
||||
+ QMessageBox::information(
|
||||
+ nullptr, i18n("Success"),
|
||||
+ i18n("Please note that binary files were not copied"));
|
||||
+ break;
|
||||
+ default:
|
||||
+ QMessageBox::critical(nullptr, i18n("Ooops..."),
|
||||
+ i18n("Could not save configuration file"));
|
||||
+ break;
|
||||
+ }
|
||||
}
|
||||
|
||||
|
||||
-QVariantMap AWConfigHelper::importConfiguration(const QString fileName,
|
||||
- const bool importPlasmoid,
|
||||
- const bool importExtensions,
|
||||
- const bool importAdds) const
|
||||
+QVariantMap AWConfigHelper::importConfiguration() const
|
||||
{
|
||||
- qCDebug(LOG_AW) << "Selected filename" << fileName;
|
||||
-
|
||||
QVariantMap configuration;
|
||||
+ // get file path and init settings object
|
||||
+ QString fileName = QFileDialog::getOpenFileName(nullptr, i18n("Import"));
|
||||
+ if (fileName.isEmpty())
|
||||
+ return configuration;
|
||||
+ qCInfo(LOG_AW) << "Selected filename" << fileName;
|
||||
QSettings settings(fileName, QSettings::IniFormat);
|
||||
+ QHash<QString, bool> selection = selectImport();
|
||||
|
||||
// extensions
|
||||
- if (importExtensions) {
|
||||
+ if (selection[QString("extensions")]) {
|
||||
for (auto item : m_dirs) {
|
||||
settings.beginGroup(item);
|
||||
for (auto it : settings.childGroups())
|
||||
@@ -121,7 +139,7 @@ QVariantMap AWConfigHelper::importConfiguration(const QString fileName,
|
||||
}
|
||||
|
||||
// additional files
|
||||
- if (importAdds) {
|
||||
+ if (selection[QString("adds")]) {
|
||||
settings.beginGroup(QString("json"));
|
||||
// script filters
|
||||
writeFile(settings, QString("filters"),
|
||||
@@ -135,7 +153,7 @@ QVariantMap AWConfigHelper::importConfiguration(const QString fileName,
|
||||
}
|
||||
|
||||
// plasmoid configuration
|
||||
- if (importPlasmoid) {
|
||||
+ if (selection[QString("plasmoid")]) {
|
||||
settings.beginGroup(QString("plasmoid"));
|
||||
for (auto key : settings.childKeys())
|
||||
configuration[key] = settings.value(key);
|
||||
@@ -261,6 +279,50 @@ void AWConfigHelper::readFile(QSettings &settings, const QString key,
|
||||
}
|
||||
|
||||
|
||||
+QHash<QString, bool> AWConfigHelper::selectImport() const
|
||||
+{
|
||||
+ QDialog *dialog = new QDialog(nullptr);
|
||||
+ QCheckBox *importPlasmoidSettings
|
||||
+ = new QCheckBox(i18n("Import plasmoid settings"), dialog);
|
||||
+ importPlasmoidSettings->setChecked(true);
|
||||
+ QCheckBox *importExtensionsSettings
|
||||
+ = new QCheckBox(i18n("Import extensions"), dialog);
|
||||
+ importExtensionsSettings->setChecked(true);
|
||||
+ QCheckBox *importAddsSettings
|
||||
+ = new QCheckBox(i18n("Import additional files"), dialog);
|
||||
+ importAddsSettings->setChecked(true);
|
||||
+ QDialogButtonBox *dialogButtons
|
||||
+ = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
|
||||
+ Qt::Horizontal, dialog);
|
||||
+ QVBoxLayout *layout = new QVBoxLayout(dialog);
|
||||
+ layout->addWidget(importPlasmoidSettings);
|
||||
+ layout->addWidget(importExtensionsSettings);
|
||||
+ layout->addWidget(importAddsSettings);
|
||||
+ layout->addWidget(dialogButtons);
|
||||
+ connect(dialogButtons, SIGNAL(accepted()), dialog, SLOT(accept()));
|
||||
+ connect(dialogButtons, SIGNAL(rejected()), dialog, SLOT(reject()));
|
||||
+
|
||||
+ // get parameters
|
||||
+ QHash<QString, bool> import;
|
||||
+ import[QString("plasmoid")] = false;
|
||||
+ import[QString("extensions")] = false;
|
||||
+ import[QString("adds")] = false;
|
||||
+ switch (dialog->exec()) {
|
||||
+ case QDialog::Accepted:
|
||||
+ import[QString("plasmoid")] = importPlasmoidSettings->isChecked();
|
||||
+ import[QString("extensions")] = importExtensionsSettings->isChecked();
|
||||
+ import[QString("adds")] = importAddsSettings->isChecked();
|
||||
+ break;
|
||||
+ case QDialog::Rejected:
|
||||
+ default:
|
||||
+ break;
|
||||
+ }
|
||||
+ dialog->deleteLater();
|
||||
+
|
||||
+ return import;
|
||||
+}
|
||||
+
|
||||
+
|
||||
void AWConfigHelper::writeFile(QSettings &settings, const QString key,
|
||||
const QString fileName) const
|
||||
{
|
||||
diff --git a/sources/awesome-widget/plugin/awconfighelper.h b/sources/awesome-widget/plugin/awconfighelper.h
|
||||
index 912ac3d..dc51dfb 100644
|
||||
--- a/sources/awesome-widget/plugin/awconfighelper.h
|
||||
+++ b/sources/awesome-widget/plugin/awconfighelper.h
|
||||
@@ -33,13 +33,9 @@ public:
|
||||
explicit AWConfigHelper(QObject *parent = nullptr);
|
||||
virtual ~AWConfigHelper();
|
||||
Q_INVOKABLE QString configurationDirectory() const;
|
||||
Q_INVOKABLE bool dropCache() const;
|
||||
- Q_INVOKABLE bool exportConfiguration(const QObject *nativeConfig,
|
||||
- const QString fileName) const;
|
||||
- Q_INVOKABLE QVariantMap importConfiguration(const QString fileName,
|
||||
- const bool importPlasmoid,
|
||||
- const bool importExtensions,
|
||||
- const bool importAdds) const;
|
||||
+ Q_INVOKABLE void exportConfiguration(const QObject *nativeConfig) const;
|
||||
+ Q_INVOKABLE QVariantMap importConfiguration() const;
|
||||
// dataengine
|
||||
Q_INVOKABLE QVariantMap readDataEngineConfiguration() const;
|
||||
Q_INVOKABLE bool
|
||||
@@ -51,6 +47,7 @@ private:
|
||||
void copySettings(QSettings &from, QSettings &to) const;
|
||||
void readFile(QSettings &settings, const QString key,
|
||||
const QString fileName) const;
|
||||
+ QHash<QString, bool> selectImport() const;
|
||||
void writeFile(QSettings &settings, const QString key,
|
||||
const QString fileName) const;
|
||||
// properties
|
||||
diff --git a/sources/awesome-widget/plugin/awkeys.cpp b/sources/awesome-widget/plugin/awkeys.cpp
|
||||
index e5b9861..039d24e 100644
|
||||
--- a/sources/awesome-widget/plugin/awkeys.cpp
|
||||
+++ b/sources/awesome-widget/plugin/awkeys.cpp
|
||||
@@ -324,6 +324,14 @@ QStringList AWKeys::getHddDevices() const
|
||||
}
|
||||
|
||||
|
||||
+#include <QInputDialog>
|
||||
+QString AWKeys::graphicalKey() const
|
||||
+{
|
||||
+ return QInputDialog::getItem(nullptr, i18n("Select tag"), QString(),
|
||||
+ dictKeys(true), 0, true);
|
||||
+}
|
||||
+
|
||||
+
|
||||
QString AWKeys::infoByKey(QString key) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Requested info for key" << key;
|
||||
diff --git a/sources/awesome-widget/plugin/awkeys.h b/sources/awesome-widget/plugin/awkeys.h
|
||||
index a8300f1..8edc3bd 100644
|
||||
--- a/sources/awesome-widget/plugin/awkeys.h
|
||||
+++ b/sources/awesome-widget/plugin/awkeys.h
|
||||
@@ -55,6 +55,7 @@ public:
|
||||
Q_INVOKABLE QStringList dictKeys(const bool sorted = false,
|
||||
const QString regexp = QString()) const;
|
||||
Q_INVOKABLE QStringList getHddDevices() const;
|
||||
+ Q_INVOKABLE QString graphicalKey() const;
|
||||
// values
|
||||
Q_INVOKABLE QString infoByKey(QString key) const;
|
||||
Q_INVOKABLE QString valueByKey(QString key) const;
|
||||
diff --git a/sources/awdebug.cpp b/sources/awdebug.cpp
|
||||
index eee61e1..9da8dad 100644
|
||||
--- a/sources/awdebug.cpp
|
||||
+++ b/sources/awdebug.cpp
|
||||
@@ -20,15 +20,11 @@
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
-Q_LOGGING_CATEGORY(LOG_AW, "org.kde.plasma.awesomewidget",
|
||||
- QtMsgType::QtWarningMsg)
|
||||
-Q_LOGGING_CATEGORY(LOG_DP, "org.kde.plasma.desktoppanel",
|
||||
- QtMsgType::QtWarningMsg)
|
||||
-Q_LOGGING_CATEGORY(LOG_ESM, "org.kde.plasma.extsysmon", QtMsgType::QtWarningMsg)
|
||||
-Q_LOGGING_CATEGORY(LOG_ESS, "org.kde.plasma.extsysmonsources",
|
||||
- QtMsgType::QtWarningMsg)
|
||||
-Q_LOGGING_CATEGORY(LOG_LIB, "org.kde.plasma.awesomewidgets",
|
||||
- QtMsgType::QtWarningMsg)
|
||||
+Q_LOGGING_CATEGORY(LOG_AW, "org.kde.plasma.awesomewidget")
|
||||
+Q_LOGGING_CATEGORY(LOG_DP, "org.kde.plasma.desktoppanel")
|
||||
+Q_LOGGING_CATEGORY(LOG_ESM, "org.kde.plasma.extsysmon")
|
||||
+Q_LOGGING_CATEGORY(LOG_ESM, "org.kde.plasma.extsysmonsources")
|
||||
+Q_LOGGING_CATEGORY(LOG_LIB, "org.kde.plasma.awesomewidgets")
|
||||
|
||||
|
||||
const QStringList getBuildData()
|
||||
diff --git a/sources/awesome-widget/plugin/awkeys.cpp b/sources/awesome-widget/plugin/awkeys.cpp
|
||||
index e5b9861..eb73073 100644
|
||||
--- a/sources/awesome-widget/plugin/awkeys.cpp
|
||||
+++ b/sources/awesome-widget/plugin/awkeys.cpp
|
||||
@@ -439,4 +439,4 @@ void AWKeys::dataUpdated(const QString &sourceName,
|
||||
{
|
||||
// run concurrent data update
|
||||
- QtConcurrent::run(m_threadPool, this, &AWKeys::setDataBySource, sourceName,
|
||||
+ QtConcurrent::run(this, &AWKeys::setDataBySource, sourceName,
|
||||
data);
|
||||
diff --git a/sources/libraries.cmake b/sources/libraries.cmake
|
||||
index 33192f7..46e2b1e 100644
|
||||
--- a/sources/libraries.cmake
|
||||
+++ b/sources/libraries.cmake
|
||||
@@ -2,7 +2,7 @@
|
||||
find_package(Gettext REQUIRED)
|
||||
|
||||
# main qt libraries
|
||||
-find_package(Qt5 5.4.0 REQUIRED COMPONENTS Core DBus Network Qml Test Widgets)
|
||||
+find_package(Qt5 5.3.0 REQUIRED COMPONENTS Core DBus Network Qml Test Widgets)
|
||||
add_definitions(
|
||||
${Qt5Core_DEFINITIONS} ${Qt5DBus_DEFINITIONS} ${Qt5Network_DEFINITIONS}
|
||||
${Qt5Qml_DEFINITIONS} ${Qt5Widgets_DEFINITIONS}
|
@ -1,5 +1,25 @@
|
||||
diff --git a/sources/awdebug.h b/sources/awdebug.h
|
||||
index 8447c65..9f8e298 100644
|
||||
--- a/sources/awdebug.h
|
||||
+++ b/sources/awdebug.h
|
||||
@@ -23,10 +23,14 @@
|
||||
|
||||
#include "version.h"
|
||||
|
||||
+#ifndef qCInfo
|
||||
+#define qCInfo qCDebug
|
||||
+#endif
|
||||
+
|
||||
namespace AWDebug
|
||||
{
|
||||
const char LOG_FORMAT[] = "[%{time "
|
||||
- "process}][%{if-debug}DD%{endif}%{if-info}II%{endif}%"
|
||||
+ "process}][%{if-debug}DD%{endif}%"
|
||||
"{if-warning}WW%{endif}%{if-critical}CC%{endif}%{if-"
|
||||
"fatal}FF%{endif}][%{category}][%{function}] "
|
||||
"%{message}";
|
||||
diff --git a/sources/awesome-widget/plugin/awkeysaggregator.h b/sources/awesome-widget/plugin/awkeysaggregator.h
|
||||
index f808d03..a056b3f 100644
|
||||
index d29672e..f15a729 100644
|
||||
--- a/sources/awesome-widget/plugin/awkeysaggregator.h
|
||||
+++ b/sources/awesome-widget/plugin/awkeysaggregator.h
|
||||
@@ -21,6 +21,7 @@
|
||||
@ -10,22 +30,3 @@ index f808d03..a056b3f 100644
|
||||
|
||||
#include "version.h"
|
||||
|
||||
diff --git a/sources/awdebug.h b/sources/awdebug.h
|
||||
index 43944ce..c679281 100644
|
||||
--- a/sources/awdebug.h
|
||||
+++ b/sources/awdebug.h
|
||||
@@ -21,9 +21,13 @@
|
||||
|
||||
#include "version.h"
|
||||
|
||||
+#ifndef qCInfo
|
||||
+#define qCInfo qCDebug
|
||||
+#endif
|
||||
+
|
||||
#ifndef LOG_FORMAT
|
||||
#define LOG_FORMAT \
|
||||
- "[%{time process}][%{if-debug}DD%{endif}%{if-info}II%{endif}%{if-" \
|
||||
+ "[%{time process}][%{if-debug}DD%{endif}%{if-" \
|
||||
"warning}WW%{endif}%{if-critical}CC%{endif}%{if-fatal}FF%{endif}][%{" \
|
||||
"category}][%{function}] %{message}"
|
||||
#endif /* LOG_FORMAT */
|
||||
|
@ -1,69 +1,60 @@
|
||||
diff --git a/sources/awesome-widget/plugin/awupdatehelper.cpp b/sources/awesome-widget/plugin/awupdatehelper.cpp
|
||||
index 3698602..42871c8 100644
|
||||
index f6b5338..b5a3163 100644
|
||||
--- a/sources/awesome-widget/plugin/awupdatehelper.cpp
|
||||
+++ b/sources/awesome-widget/plugin/awupdatehelper.cpp
|
||||
@@ -37,7 +37,7 @@ AWUpdateHelper::AWUpdateHelper(QObject *parent)
|
||||
@@ -35,7 +35,7 @@ AWUpdateHelper::AWUpdateHelper(QObject *_parent)
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
|
||||
- m_foundVersion = QVersionNumber::fromString(VERSION);
|
||||
+ m_foundVersion = QString(VERSION);
|
||||
+ m_foundVersion = VERSION;
|
||||
m_genericConfig = QString("%1/awesomewidgets/general.ini")
|
||||
.arg(QStandardPaths::writableLocation(
|
||||
QStandardPaths::GenericDataLocation));
|
||||
@@ -69,15 +69,15 @@ void AWUpdateHelper::checkUpdates(const bool showAnyway)
|
||||
@@ -67,8 +67,7 @@ void AWUpdateHelper::checkUpdates(const bool _showAnyway)
|
||||
bool AWUpdateHelper::checkVersion()
|
||||
{
|
||||
QSettings settings(m_genericConfig, QSettings::IniFormat);
|
||||
- QVersionNumber version = QVersionNumber::fromString(
|
||||
- settings.value(QString("Version"), QString(VERSION)).toString());
|
||||
+ QString version
|
||||
+ = settings.value(QString("Version"), QString(VERSION)).toString();
|
||||
- settings.value("Version", QString(VERSION)).toString());
|
||||
+ QString version = settings.value("Version", VERSION).toString();
|
||||
// update version
|
||||
settings.setValue(QString("Version"), QString(VERSION));
|
||||
settings.setValue("Version", QString(VERSION));
|
||||
settings.sync();
|
||||
qCInfo(LOG_AW) << "Found version" << version << "actual one is"
|
||||
<< m_foundVersion;
|
||||
|
||||
- if ((version != m_foundVersion) && (!QString(CHANGELOG).isEmpty())) {
|
||||
+ if ((version != QString(VERSION)) && (!QString(CHANGELOG).isEmpty())) {
|
||||
genMessageBox(i18n("Changelog of %1", QString(VERSION)),
|
||||
QString(CHANGELOG).replace(QChar('@'), QChar('\n')),
|
||||
QMessageBox::Ok)
|
||||
@@ -90,12 +90,11 @@ bool AWUpdateHelper::checkVersion()
|
||||
@@ -91,12 +90,11 @@ bool AWUpdateHelper::checkVersion()
|
||||
}
|
||||
|
||||
|
||||
-void AWUpdateHelper::showInfo(const QVersionNumber version)
|
||||
+void AWUpdateHelper::showInfo(const QString version)
|
||||
-void AWUpdateHelper::showInfo(const QVersionNumber &_version)
|
||||
+void AWUpdateHelper::showInfo(const QString &_version)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Version" << version;
|
||||
qCDebug(LOG_AW) << "Version" << _version;
|
||||
|
||||
- QString text
|
||||
- = i18n("You are using the actual version %1", version.toString());
|
||||
+ QString text = i18n("You are using the actual version %1", version);
|
||||
- = i18n("You are using the actual version %1", _version.toString());
|
||||
+ QString text = i18n("You are using the actual version %1", _version);
|
||||
if (!QString(COMMIT_SHA).isEmpty())
|
||||
text += QString(" (%1)").arg(QString(COMMIT_SHA));
|
||||
return genMessageBox(i18n("No new version found"), text, QMessageBox::Ok)
|
||||
@@ -103,7 +102,7 @@ void AWUpdateHelper::showInfo(const QVersionNumber version)
|
||||
@@ -104,7 +102,7 @@ void AWUpdateHelper::showInfo(const QVersionNumber &_version)
|
||||
}
|
||||
|
||||
|
||||
-void AWUpdateHelper::showUpdates(const QVersionNumber version)
|
||||
+void AWUpdateHelper::showUpdates(const QString version)
|
||||
-void AWUpdateHelper::showUpdates(const QVersionNumber &_version)
|
||||
+void AWUpdateHelper::showUpdates(const QString &_version)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Version" << version;
|
||||
qCDebug(LOG_AW) << "Version" << _version;
|
||||
|
||||
@@ -112,7 +111,7 @@ void AWUpdateHelper::showUpdates(const QVersionNumber version)
|
||||
@@ -113,7 +111,7 @@ void AWUpdateHelper::showUpdates(const QVersionNumber &_version)
|
||||
text += QString(COMMIT_SHA).isEmpty()
|
||||
? QString("\n")
|
||||
? "\n"
|
||||
: QString(" (%1)\n").arg(QString(COMMIT_SHA));
|
||||
- text += i18n("New version : %1", version.toString()) + QString("\n\n");
|
||||
+ text += i18n("New version : %1", version) + QString("\n\n");
|
||||
- text += i18n("New version : %1", _version.toString()) + "\n\n";
|
||||
+ text += i18n("New version : %1", _version) + "\n\n";
|
||||
text += i18n("Click \"Ok\" to download");
|
||||
|
||||
genMessageBox(i18n("There are updates"), text,
|
||||
@@ -128,8 +127,7 @@ void AWUpdateHelper::userReplyOnUpdates(QAbstractButton *button)
|
||||
@@ -130,8 +128,7 @@ void AWUpdateHelper::userReplyOnUpdates(QAbstractButton *_button)
|
||||
|
||||
switch (ret) {
|
||||
case QMessageBox::AcceptRole:
|
||||
@ -73,10 +64,10 @@ index 3698602..42871c8 100644
|
||||
break;
|
||||
case QMessageBox::RejectRole:
|
||||
default:
|
||||
@@ -157,14 +155,23 @@ void AWUpdateHelper::versionReplyRecieved(QNetworkReply *reply,
|
||||
@@ -162,14 +159,23 @@ void AWUpdateHelper::versionReplyRecieved(QNetworkReply *_reply,
|
||||
QVariantMap firstRelease = jsonDoc.toVariant().toList().first().toMap();
|
||||
QString version = firstRelease[QString("tag_name")].toString();
|
||||
version.remove(QString("V."));
|
||||
QString version = firstRelease["tag_name"].toString();
|
||||
version.remove("V.");
|
||||
- m_foundVersion = QVersionNumber::fromString(version);
|
||||
+ m_foundVersion = version;
|
||||
qCInfo(LOG_AW) << "Update found version to" << m_foundVersion;
|
||||
@ -96,14 +87,14 @@ index 3698602..42871c8 100644
|
||||
+ || ((old_major == new_major) && (old_minor == new_minor)
|
||||
+ && (old_patch < new_patch)))
|
||||
+ return showUpdates(version);
|
||||
else if (showAnyway)
|
||||
else if (_showAnyway)
|
||||
- return showInfo(m_foundVersion);
|
||||
+ return showInfo(version);
|
||||
}
|
||||
|
||||
|
||||
diff --git a/sources/awesome-widget/plugin/awupdatehelper.h b/sources/awesome-widget/plugin/awupdatehelper.h
|
||||
index 359cdb2..9c6a42d 100644
|
||||
index cfd26e7..b311be2 100644
|
||||
--- a/sources/awesome-widget/plugin/awupdatehelper.h
|
||||
+++ b/sources/awesome-widget/plugin/awupdatehelper.h
|
||||
@@ -21,7 +21,6 @@
|
||||
@ -118,23 +109,23 @@ index 359cdb2..9c6a42d 100644
|
||||
bool checkVersion();
|
||||
|
||||
private slots:
|
||||
- void showInfo(const QVersionNumber version);
|
||||
- void showUpdates(const QVersionNumber version);
|
||||
+ void showInfo(const QString version);
|
||||
+ void showUpdates(const QString version);
|
||||
void userReplyOnUpdates(QAbstractButton *button);
|
||||
void versionReplyRecieved(QNetworkReply *reply, const bool showAnyway);
|
||||
- void showInfo(const QVersionNumber &_version);
|
||||
- void showUpdates(const QVersionNumber &_version);
|
||||
+ void showInfo(const QString &_version);
|
||||
+ void showUpdates(const QString &_version);
|
||||
void userReplyOnUpdates(QAbstractButton *_button);
|
||||
void versionReplyRecieved(QNetworkReply *_reply, const bool _showAnyway);
|
||||
|
||||
private:
|
||||
QMessageBox *genMessageBox(const QString title, const QString body,
|
||||
const QMessageBox::StandardButtons buttons);
|
||||
QMessageBox *genMessageBox(const QString &_title, const QString &_body,
|
||||
const QMessageBox::StandardButtons _buttons);
|
||||
- QVersionNumber m_foundVersion;
|
||||
+ QString m_foundVersion;
|
||||
QString m_genericConfig;
|
||||
};
|
||||
|
||||
diff --git a/sources/libraries.cmake b/sources/libraries.cmake
|
||||
index 33192f7..339bb58 100644
|
||||
index 6f171a6..004b39f 100644
|
||||
--- a/sources/libraries.cmake
|
||||
+++ b/sources/libraries.cmake
|
||||
@@ -2,7 +2,7 @@
|
||||
@ -142,7 +133,7 @@ index 33192f7..339bb58 100644
|
||||
|
||||
# main qt libraries
|
||||
-find_package(Qt5 5.6.0 REQUIRED COMPONENTS Core DBus Network Qml Test Widgets)
|
||||
+find_package(Qt5 5.4.0 REQUIRED COMPONENTS Core DBus Network Qml Test Widgets)
|
||||
+find_package(Qt5 5.5.0 REQUIRED COMPONENTS Core DBus Network Qml Test Widgets)
|
||||
add_definitions(
|
||||
${Qt5Core_DEFINITIONS} ${Qt5DBus_DEFINITIONS} ${Qt5Network_DEFINITIONS}
|
||||
${Qt5Qml_DEFINITIONS} ${Qt5Widgets_DEFINITIONS}
|
||||
|
@ -14,7 +14,7 @@ set(PROJECT_AUTHOR "Evgeniy Alekseev")
|
||||
set(PROJECT_CONTACT "esalexeev@gmail.com")
|
||||
set(PROJECT_LICENSE "GPL3")
|
||||
set(PROJECT_VERSION_MAJOR "3")
|
||||
set(PROJECT_VERSION_MINOR "2")
|
||||
set(PROJECT_VERSION_MINOR "3")
|
||||
set(PROJECT_VERSION_PATCH "1")
|
||||
set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
|
||||
# append git version if any
|
||||
@ -50,14 +50,11 @@ if (CMAKE_COMPILER_IS_GNUCXX)
|
||||
# avoid newer gcc warnings
|
||||
add_definitions(-D_DEFAULT_SOURCE)
|
||||
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
set(CMAKE_CXX_FLAGS "-Wall -std=c++11 -stdlib=libc++")
|
||||
set(CMAKE_CXX_FLAGS "-Wall -std=c++11")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
|
||||
set(CMAKE_CXX_FLAGS_OPTIMIZATION "-Ofast -DNDEBUG")
|
||||
# linker flags
|
||||
set(CMAKE_EXE_LINKER_FLAGS "-lc++abi")
|
||||
set(CMAKE_MODULE_LINKER_FLAGS "-lc++abi")
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "-lc++abi")
|
||||
else ()
|
||||
message(FATAL_ERROR "Unknown compiler")
|
||||
endif ()
|
||||
@ -65,6 +62,9 @@ if (CMAKE_BUILD_TYPE MATCHES Debug)
|
||||
set(CMAKE_VERBOSE_MAKEFILE ON)
|
||||
endif ()
|
||||
|
||||
# required by successfully coverity and cppcheck build
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
|
||||
set(PROJECT_TRDPARTY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty)
|
||||
set(PROJECT_LIBRARY awesomewidgets)
|
||||
set(PROJECT_MONITORSOURCES extsysmonsources)
|
||||
@ -79,6 +79,7 @@ add_subdirectory(awesomewidgets)
|
||||
add_subdirectory(extsysmonsources)
|
||||
add_subdirectory(extsysmon)
|
||||
if (BUILD_PLASMOIDS)
|
||||
add_subdirectory(qml)
|
||||
add_subdirectory(awesome-widget)
|
||||
add_subdirectory(desktop-panel)
|
||||
add_subdirectory(translations)
|
||||
@ -89,3 +90,4 @@ if (BUILD_TESTING)
|
||||
endif ()
|
||||
|
||||
include(packages-recipe.cmake)
|
||||
|
||||
|
@ -16,11 +16,14 @@
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#include <KI18n/KLocalizedString>
|
||||
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
Q_LOGGING_CATEGORY(LOG_AW, "org.kde.plasma.awesomewidget",
|
||||
QtMsgType::QtWarningMsg)
|
||||
Q_LOGGING_CATEGORY(LOG_DBUS, "org.kde.plasma.awdbus", QtMsgType::QtWarningMsg)
|
||||
Q_LOGGING_CATEGORY(LOG_DP, "org.kde.plasma.desktoppanel",
|
||||
QtMsgType::QtWarningMsg)
|
||||
Q_LOGGING_CATEGORY(LOG_ESM, "org.kde.plasma.extsysmon", QtMsgType::QtWarningMsg)
|
||||
@ -30,28 +33,100 @@ Q_LOGGING_CATEGORY(LOG_LIB, "org.kde.plasma.awesomewidgets",
|
||||
QtMsgType::QtWarningMsg)
|
||||
|
||||
|
||||
const QStringList getBuildData()
|
||||
QString AWDebug::getAboutText(const QString &_type)
|
||||
{
|
||||
QString text;
|
||||
if (_type == "header") {
|
||||
text = NAME;
|
||||
} else if (_type == "version") {
|
||||
text = i18n("Version %1 (build date %2)", VERSION, BUILD_DATE);
|
||||
if (!QString(COMMIT_SHA).isEmpty())
|
||||
text += QString(" (%1)").arg(COMMIT_SHA);
|
||||
} else if (_type == "description") {
|
||||
text = i18n("A set of minimalistic plasmoid widgets");
|
||||
} else if (_type == "links") {
|
||||
text = i18n("Links:") + "<ul>"
|
||||
+ QString("<li><a href=\"%1\">%2</a></li>")
|
||||
.arg(HOMEPAGE)
|
||||
.arg(i18n("Homepage"))
|
||||
+ QString("<li><a href=\"%1\">%2</a></li>")
|
||||
.arg(REPOSITORY)
|
||||
.arg(i18n("Repository"))
|
||||
+ QString("<li><a href=\"%1\">%2</a></li>")
|
||||
.arg(BUGTRACKER)
|
||||
.arg(i18n("Bugtracker"))
|
||||
+ QString("<li><a href=\"%1\">%2</a></li>")
|
||||
.arg(TRANSLATION)
|
||||
.arg(i18n("Translation issue"))
|
||||
+ QString("<li><a href=\"%1\">%2</a></li>")
|
||||
.arg(AUR_PACKAGES)
|
||||
.arg(i18n("AUR packages"))
|
||||
+ QString("<li><a href=\"%1\">%2</a></li>")
|
||||
.arg(OPENSUSE_PACKAGES)
|
||||
.arg(i18n("openSUSE packages"))
|
||||
+ "</ul>";
|
||||
} else if (_type == "copy") {
|
||||
text = QString("<small>© %1 <a href=\"mailto:%2\">%3</a><br>")
|
||||
.arg(DATE)
|
||||
.arg(EMAIL)
|
||||
.arg(AUTHOR)
|
||||
+ i18n("This software is licensed under %1", LICENSE)
|
||||
+ "</small>";
|
||||
} else if (_type == "translators") {
|
||||
QStringList translatorList = QString(TRANSLATORS).split(',');
|
||||
for (auto &translator : translatorList)
|
||||
translator = QString("<li>%1</li>").arg(translator);
|
||||
text
|
||||
= i18n("Translators:") + "<ul>" + translatorList.join("") + "</ul>";
|
||||
} else if (_type == "3rdparty") {
|
||||
QStringList trdPartyList
|
||||
= QString(TRDPARTY_LICENSE).split(';', QString::SkipEmptyParts);
|
||||
for (int i = 0; i < trdPartyList.count(); i++)
|
||||
trdPartyList[i]
|
||||
= QString("<li><a href=\"%3\">%1</a> (%2 license)</li>")
|
||||
.arg(trdPartyList.at(i).split(',')[0])
|
||||
.arg(trdPartyList.at(i).split(',')[1])
|
||||
.arg(trdPartyList.at(i).split(',')[2]);
|
||||
text = i18n("This software uses:") + "<ul>" + trdPartyList.join("")
|
||||
+ "</ul>";
|
||||
} else if (_type == "thanks") {
|
||||
QStringList thanks
|
||||
= QString(SPECIAL_THANKS).split(';', QString::SkipEmptyParts);
|
||||
for (int i = 0; i < thanks.count(); i++)
|
||||
thanks[i] = QString("<li><a href=\"%2\">%1</a></li>")
|
||||
.arg(thanks.at(i).split(',')[0])
|
||||
.arg(thanks.at(i).split(',')[1]);
|
||||
text = i18n("Special thanks to:") + "<ul>" + thanks.join("") + "</ul>";
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
|
||||
QStringList AWDebug::getBuildData()
|
||||
{
|
||||
QStringList metadata;
|
||||
metadata.append(QString("=== Awesome Widgets configuration details ==="));
|
||||
metadata.append("=== Awesome Widgets configuration details ===");
|
||||
// build information
|
||||
metadata.append(QString("Build details:"));
|
||||
metadata.append("Build details:");
|
||||
metadata.append(QString(" VERSION: %1").arg(VERSION));
|
||||
metadata.append(QString(" COMMIT_SHA: %1").arg(COMMIT_SHA));
|
||||
metadata.append(QString(" BUILD_DATE: %1").arg(BUILD_DATE));
|
||||
// configuration
|
||||
metadata.append(QString("API details:"));
|
||||
metadata.append(QString(" AWGIAPI: %1").arg(AWGIAPI));
|
||||
metadata.append(QString(" AWEQAPI: %1").arg(AWEQAPI));
|
||||
metadata.append(QString(" AWESAPI: %1").arg(AWESAPI));
|
||||
metadata.append(QString(" AWEUAPI: %1").arg(AWEUAPI));
|
||||
metadata.append(QString(" AWEWAPI: %1").arg(AWEWAPI));
|
||||
metadata.append(QString(" AWEFAPI: %1").arg(AWEFAPI));
|
||||
metadata.append("API details:");
|
||||
metadata.append(QString(" AW_GRAPHITEM_API: %1").arg(AW_GRAPHITEM_API));
|
||||
metadata.append(QString(" AW_EXTQUOTES_API: %1").arg(AW_EXTQUOTES_API));
|
||||
metadata.append(QString(" AW_EXTSCRIPT_API: %1").arg(AW_EXTSCRIPT_API));
|
||||
metadata.append(
|
||||
QString(" AW_EXTUPGRADE_API: %1").arg(AW_EXTUPGRADE_API));
|
||||
metadata.append(
|
||||
QString(" AW_EXTWEATHER_API: %1").arg(AW_EXTWEATHER_API));
|
||||
metadata.append(QString(" AW_FORMATTER_API: %1").arg(AW_FORMATTER_API));
|
||||
metadata.append(QString(" REQUEST_TIMEOUT: %1").arg(REQUEST_TIMEOUT));
|
||||
metadata.append(QString(" TIME_KEYS: %1").arg(TIME_KEYS));
|
||||
metadata.append(QString(" STATIC_KEYS: %1").arg(STATIC_KEYS));
|
||||
// cmake properties
|
||||
metadata.append(QString("cmake properties:"));
|
||||
metadata.append("cmake properties:");
|
||||
metadata.append(QString(" CMAKE_BUILD_TYPE: %1").arg(CMAKE_BUILD_TYPE));
|
||||
metadata.append(
|
||||
QString(" CMAKE_CXX_COMPILER: %1").arg(CMAKE_CXX_COMPILER));
|
||||
@ -71,7 +146,7 @@ const QStringList getBuildData()
|
||||
metadata.append(QString(" CMAKE_SHARED_LINKER_FLAGS: %1")
|
||||
.arg(CMAKE_SHARED_LINKER_FLAGS));
|
||||
// components
|
||||
metadata.append(QString("Components data:"));
|
||||
metadata.append("Components data:");
|
||||
metadata.append(QString(" BUILD_PLASMOIDS: %1").arg(BUILD_PLASMOIDS));
|
||||
metadata.append(
|
||||
QString(" BUILD_DEB_PACKAGE: %1").arg(BUILD_DEB_PACKAGE));
|
||||
|
@ -23,21 +23,25 @@
|
||||
|
||||
#include "version.h"
|
||||
|
||||
#ifndef LOG_FORMAT
|
||||
#define LOG_FORMAT \
|
||||
"[%{time process}][%{if-debug}DD%{endif}%{if-info}II%{endif}%{if-" \
|
||||
"warning}WW%{endif}%{if-critical}CC%{endif}%{if-fatal}FF%{endif}][%{" \
|
||||
"category}][%{function}] %{message}"
|
||||
#endif /* LOG_FORMAT */
|
||||
namespace AWDebug
|
||||
{
|
||||
const char LOG_FORMAT[] = "[%{time "
|
||||
"process}][%{if-debug}DD%{endif}%{if-info}II%{endif}%"
|
||||
"{if-warning}WW%{endif}%{if-critical}CC%{endif}%{if-"
|
||||
"fatal}FF%{endif}][%{category}][%{function}] "
|
||||
"%{message}";
|
||||
|
||||
QString getAboutText(const QString &_type);
|
||||
QStringList getBuildData();
|
||||
}
|
||||
|
||||
|
||||
Q_DECLARE_LOGGING_CATEGORY(LOG_AW)
|
||||
Q_DECLARE_LOGGING_CATEGORY(LOG_DBUS)
|
||||
Q_DECLARE_LOGGING_CATEGORY(LOG_DP)
|
||||
Q_DECLARE_LOGGING_CATEGORY(LOG_ESM)
|
||||
Q_DECLARE_LOGGING_CATEGORY(LOG_ESS)
|
||||
Q_DECLARE_LOGGING_CATEGORY(LOG_LIB)
|
||||
|
||||
const QStringList getBuildData();
|
||||
|
||||
|
||||
#endif /* AWDEBUG_H */
|
||||
|
@ -62,6 +62,15 @@
|
||||
<entry name="acOffline" type="string">
|
||||
<default>( )</default>
|
||||
</entry>
|
||||
<entry name="telemetryCount" type="int">
|
||||
<default>100</default>
|
||||
</entry>
|
||||
<entry name="telemetryRemote" type="bool">
|
||||
<default>false</default>
|
||||
</entry>
|
||||
<entry name="telemetryId" type="string">
|
||||
<default></default>
|
||||
</entry>
|
||||
</group>
|
||||
|
||||
<group name="Tooltip">
|
||||
@ -138,6 +147,12 @@
|
||||
<entry name="fontStyle" type="string">
|
||||
<default>normal</default>
|
||||
</entry>
|
||||
<entry name="textStyle" type="string">
|
||||
<default>normal</default>
|
||||
</entry>
|
||||
<entry name="textStyleColor" type="string">
|
||||
<default>#000000</default>
|
||||
</entry>
|
||||
</group>
|
||||
|
||||
</kcfg>
|
||||
|
@ -16,112 +16,24 @@
|
||||
***************************************************************************/
|
||||
|
||||
import QtQuick 2.0
|
||||
import QtQuick.Controls 1.3 as QtControls
|
||||
import QtQuick.Layouts 1.0 as QtLayouts
|
||||
|
||||
import org.kde.plasma.private.awesomewidget 1.0
|
||||
|
||||
|
||||
Item {
|
||||
id: aboutPage
|
||||
// backend
|
||||
AWActions {
|
||||
id: awActions
|
||||
}
|
||||
|
||||
width: childrenRect.width
|
||||
height: childrenRect.height
|
||||
implicitWidth: pageColumn.implicitWidth
|
||||
implicitHeight: pageColumn.implicitHeight
|
||||
|
||||
property bool debug: awActions.isDebugEnabled()
|
||||
|
||||
|
||||
Column {
|
||||
id: pageColumn
|
||||
anchors.fill: parent
|
||||
QtControls.TabView {
|
||||
height: parent.height
|
||||
width: parent.width
|
||||
QtControls.Tab {
|
||||
anchors.margins: 10.0
|
||||
title: i18n("About")
|
||||
|
||||
QtLayouts.ColumnLayout {
|
||||
QtControls.Label {
|
||||
QtLayouts.Layout.fillWidth: true
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
text: awActions.getAboutText("header")
|
||||
}
|
||||
|
||||
QtControls.Label {
|
||||
QtLayouts.Layout.fillWidth: true
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
text: awActions.getAboutText("version")
|
||||
}
|
||||
|
||||
QtControls.Label {
|
||||
QtLayouts.Layout.fillWidth: true
|
||||
horizontalAlignment: Text.AlignJustify
|
||||
text: awActions.getAboutText("description")
|
||||
}
|
||||
|
||||
QtControls.Label {
|
||||
QtLayouts.Layout.fillWidth: true
|
||||
horizontalAlignment: Text.AlignLeft
|
||||
textFormat: Text.RichText
|
||||
text: awActions.getAboutText("links")
|
||||
onLinkActivated: Qt.openUrlExternally(link);
|
||||
}
|
||||
|
||||
QtControls.Label {
|
||||
QtLayouts.Layout.fillHeight: true
|
||||
QtLayouts.Layout.fillWidth: true
|
||||
font.capitalization: Font.SmallCaps
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
verticalAlignment: Text.AlignBottom
|
||||
textFormat: Text.RichText
|
||||
text: awActions.getAboutText("copy")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QtControls.Tab {
|
||||
anchors.margins: 10.0
|
||||
title: i18n("Acknowledgment")
|
||||
|
||||
QtLayouts.ColumnLayout {
|
||||
QtControls.Label {
|
||||
QtLayouts.Layout.fillWidth: true
|
||||
wrapMode: Text.WordWrap
|
||||
horizontalAlignment: Text.AlignJustify
|
||||
text: awActions.getAboutText("translators")
|
||||
}
|
||||
|
||||
QtControls.Label {
|
||||
QtLayouts.Layout.fillWidth: true
|
||||
wrapMode: Text.WordWrap
|
||||
horizontalAlignment: Text.AlignJustify
|
||||
textFormat: Text.RichText
|
||||
text: awActions.getAboutText("3rdparty")
|
||||
onLinkActivated: Qt.openUrlExternally(link);
|
||||
}
|
||||
|
||||
QtControls.Label {
|
||||
QtLayouts.Layout.fillHeight: true
|
||||
QtLayouts.Layout.fillWidth: true
|
||||
wrapMode: Text.WordWrap
|
||||
horizontalAlignment: Text.AlignJustify
|
||||
verticalAlignment: Text.AlignTop
|
||||
textFormat: Text.RichText
|
||||
text: awActions.getAboutText("thanks")
|
||||
onLinkActivated: Qt.openUrlExternally(link);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
AboutTab {
|
||||
textProvider: awActions
|
||||
}
|
||||
|
||||
|
||||
Component.onCompleted: {
|
||||
if (debug) console.debug()
|
||||
}
|
||||
|
@ -17,7 +17,6 @@
|
||||
|
||||
import QtQuick 2.0
|
||||
import QtQuick.Controls 1.3 as QtControls
|
||||
import QtQuick.Dialogs 1.2 as QtDialogs
|
||||
|
||||
import org.kde.plasma.private.awesomewidget 1.0
|
||||
|
||||
@ -28,9 +27,6 @@ Item {
|
||||
AWActions {
|
||||
id: awActions
|
||||
}
|
||||
AWConfigHelper {
|
||||
id: awConfig
|
||||
}
|
||||
|
||||
width: childrenRect.width
|
||||
height: childrenRect.height
|
||||
@ -50,420 +46,210 @@ Item {
|
||||
property alias cfg_width: widgetWidth.value
|
||||
property alias cfg_interval: update.value
|
||||
property alias cfg_queueLimit: queueLimit.value
|
||||
property string cfg_tempUnits: tempUnits.currentText
|
||||
property alias cfg_customTime: customTime.text
|
||||
property alias cfg_customUptime: customUptime.text
|
||||
property alias cfg_acOnline: acOnline.text
|
||||
property alias cfg_acOffline: acOffline.text
|
||||
property string cfg_tempUnits: tempUnits.value
|
||||
property alias cfg_customTime: customTime.value
|
||||
property alias cfg_customUptime: customUptime.value
|
||||
property alias cfg_acOnline: acOnline.value
|
||||
property alias cfg_acOffline: acOffline.value
|
||||
property alias cfg_telemetryCount: telemetryCount.value
|
||||
property alias cfg_telemetryRemote: telemetryRemote.checked
|
||||
property alias cfg_telemetryId: telemetryId.value
|
||||
|
||||
|
||||
Column {
|
||||
id: pageColumn
|
||||
anchors.fill: parent
|
||||
Row {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
QtControls.Label {
|
||||
height: parent.heigth
|
||||
width: parent.width * 2 / 5
|
||||
}
|
||||
QtControls.CheckBox {
|
||||
id: background
|
||||
width: parent.width * 3 / 5
|
||||
text: i18n("Enable background")
|
||||
}
|
||||
|
||||
CheckBoxSelector {
|
||||
id: background
|
||||
text: i18n("Enable background")
|
||||
}
|
||||
|
||||
Row {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
QtControls.Label {
|
||||
height: parent.heigth
|
||||
width: parent.width * 2 / 5
|
||||
}
|
||||
QtControls.CheckBox {
|
||||
id: translate
|
||||
width: parent.width * 3 / 5
|
||||
text: i18n("Translate strings")
|
||||
}
|
||||
CheckBoxSelector {
|
||||
id: translate
|
||||
text: i18n("Translate strings")
|
||||
}
|
||||
|
||||
Row {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
QtControls.Label {
|
||||
height: parent.heigth
|
||||
width: parent.width * 2 / 5
|
||||
}
|
||||
QtControls.CheckBox {
|
||||
id: wrapNewLines
|
||||
width: parent.width * 3 / 5
|
||||
text: i18n("Wrap new lines")
|
||||
}
|
||||
CheckBoxSelector {
|
||||
id: wrapNewLines
|
||||
text: i18n("Wrap new lines")
|
||||
}
|
||||
|
||||
Row {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
QtControls.Label {
|
||||
height: parent.heigth
|
||||
width: parent.width * 2 / 5
|
||||
}
|
||||
QtControls.CheckBox {
|
||||
id: wordWrap
|
||||
width: parent.width * 3 / 5
|
||||
text: i18n("Enable word wrap")
|
||||
}
|
||||
CheckBoxSelector {
|
||||
id: wordWrap
|
||||
text: i18n("Enable word wrap")
|
||||
}
|
||||
|
||||
Row {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
QtControls.Label {
|
||||
height: parent.heigth
|
||||
width: parent.width * 2 / 5
|
||||
}
|
||||
QtControls.CheckBox {
|
||||
id: notify
|
||||
width: parent.width * 3 / 5
|
||||
text: i18n("Enable notifications")
|
||||
}
|
||||
CheckBoxSelector {
|
||||
id: notify
|
||||
text: i18n("Enable notifications")
|
||||
}
|
||||
|
||||
Row {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
QtControls.Label {
|
||||
height: parent.heigth
|
||||
width: parent.width * 2 / 5
|
||||
}
|
||||
QtControls.CheckBox {
|
||||
id: updates
|
||||
width: parent.width * 3 / 5
|
||||
text: i18n("Check updates on startup")
|
||||
}
|
||||
CheckBoxSelector {
|
||||
id: updates
|
||||
text: i18n("Check updates on startup")
|
||||
}
|
||||
|
||||
Row {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
QtControls.Label {
|
||||
height: parent.heigth
|
||||
width: parent.width * 2 / 5
|
||||
}
|
||||
QtControls.CheckBox {
|
||||
id: optimize
|
||||
width: parent.width * 3 / 5
|
||||
text: i18n("Optimize subscription")
|
||||
}
|
||||
CheckBoxSelector {
|
||||
id: optimize
|
||||
text: i18n("Optimize subscription")
|
||||
}
|
||||
|
||||
Row {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
QtControls.Label {
|
||||
height: parent.height
|
||||
width: parent.width * 2 / 5
|
||||
horizontalAlignment: Text.AlignRight
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
text: i18n("Widget height, px")
|
||||
}
|
||||
QtControls.SpinBox {
|
||||
id: widgetHeight
|
||||
width: parent.width * 3 / 5
|
||||
minimumValue: 0
|
||||
maximumValue: 4096
|
||||
stepSize: 50
|
||||
value: plasmoid.configuration.height
|
||||
}
|
||||
IntegerSelector {
|
||||
id: widgetHeight
|
||||
maximumValue: 4096
|
||||
minimumValue: 0
|
||||
stepSize: 50
|
||||
text: i18n("Widget height, px")
|
||||
value: plasmoid.configuration.height
|
||||
}
|
||||
|
||||
Row {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
QtControls.Label {
|
||||
height: parent.height
|
||||
width: parent.width * 2 / 5
|
||||
horizontalAlignment: Text.AlignRight
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
text: i18n("Widget width, px")
|
||||
}
|
||||
QtControls.SpinBox {
|
||||
id: widgetWidth
|
||||
width: parent.width * 3 / 5
|
||||
minimumValue: 0
|
||||
maximumValue: 4096
|
||||
stepSize: 50
|
||||
value: plasmoid.configuration.width
|
||||
}
|
||||
IntegerSelector {
|
||||
id: widgetWidth
|
||||
maximumValue: 4096
|
||||
minimumValue: 0
|
||||
stepSize: 50
|
||||
text: i18n("Widget width, px")
|
||||
value: plasmoid.configuration.width
|
||||
}
|
||||
|
||||
Row {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
QtControls.Label {
|
||||
height: parent.height
|
||||
width: parent.width * 2 / 5
|
||||
horizontalAlignment: Text.AlignRight
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
text: i18n("Time interval")
|
||||
}
|
||||
QtControls.SpinBox {
|
||||
id: update
|
||||
width: parent.width * 3 / 5
|
||||
minimumValue: 1000
|
||||
maximumValue: 10000
|
||||
stepSize: 500
|
||||
value: plasmoid.configuration.interval
|
||||
}
|
||||
IntegerSelector {
|
||||
id: update
|
||||
maximumValue: 10000
|
||||
minimumValue: 1000
|
||||
stepSize: 500
|
||||
text: i18n("Time interval")
|
||||
value: plasmoid.configuration.interval
|
||||
}
|
||||
|
||||
Row {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
QtControls.Label {
|
||||
height: parent.height
|
||||
width: parent.width * 2 / 5
|
||||
horizontalAlignment: Text.AlignRight
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
text: i18n("Messages queue limit")
|
||||
}
|
||||
QtControls.SpinBox {
|
||||
id: queueLimit
|
||||
width: parent.width * 3 / 5
|
||||
minimumValue: 0
|
||||
maximumValue: 99
|
||||
stepSize: 1
|
||||
value: plasmoid.configuration.queueLimit
|
||||
}
|
||||
IntegerSelector {
|
||||
id: queueLimit
|
||||
maximumValue: 99
|
||||
minimumValue: 0
|
||||
stepSize: 1
|
||||
text: i18n("Messages queue limit")
|
||||
value: plasmoid.configuration.queueLimit
|
||||
}
|
||||
|
||||
Row {
|
||||
ComboBoxSelector {
|
||||
id: tempUnits
|
||||
model: [
|
||||
{
|
||||
'label': i18n("Celsius"),
|
||||
'name': "Celsius"
|
||||
},
|
||||
{
|
||||
'label': i18n("Fahrenheit"),
|
||||
'name': "Fahrenheit"
|
||||
},
|
||||
{
|
||||
'label': i18n("Kelvin"),
|
||||
'name': "Kelvin"
|
||||
},
|
||||
{
|
||||
'label': i18n("Reaumur"),
|
||||
'name': "Reaumur"
|
||||
},
|
||||
{
|
||||
'label': i18n("cm^-1"),
|
||||
'name': "cm^-1"
|
||||
},
|
||||
{
|
||||
'label': i18n("kJ/mol"),
|
||||
'name': "kJ/mol"
|
||||
},
|
||||
{
|
||||
'label': i18n("kcal/mol"),
|
||||
'name': "kcal/mol"
|
||||
}
|
||||
]
|
||||
text: i18n("Temperature units")
|
||||
value: plasmoid.configuration.tempUnits
|
||||
onValueEdited: cfg_tempUnits = newValue
|
||||
}
|
||||
|
||||
LineSelector {
|
||||
id: customTime
|
||||
text: i18n("Custom time format")
|
||||
value: plasmoid.configuration.customTime
|
||||
}
|
||||
|
||||
LineSelector {
|
||||
id: customUptime
|
||||
text: i18n("Custom uptime format")
|
||||
value: plasmoid.configuration.customUptime
|
||||
}
|
||||
|
||||
LineSelector {
|
||||
id: acOnline
|
||||
text: i18n("AC online tag")
|
||||
value: plasmoid.configuration.acOnline
|
||||
}
|
||||
|
||||
LineSelector {
|
||||
id: acOffline
|
||||
text: i18n("AC offline tag")
|
||||
value: plasmoid.configuration.acOffline
|
||||
}
|
||||
|
||||
QtControls.GroupBox {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
QtControls.Label {
|
||||
height: parent.height
|
||||
width: parent.width * 2 / 5
|
||||
horizontalAlignment: Text.AlignRight
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
text: i18n("Temperature units")
|
||||
}
|
||||
QtControls.ComboBox {
|
||||
id: tempUnits
|
||||
width: parent.width * 3 / 5
|
||||
textRole: "label"
|
||||
model: [
|
||||
{
|
||||
'label': i18n("Celsius"),
|
||||
'name': "Celsius"
|
||||
},
|
||||
{
|
||||
'label': i18n("Fahrenheit"),
|
||||
'name': "Fahrenheit"
|
||||
},
|
||||
{
|
||||
'label': i18n("Kelvin"),
|
||||
'name': "Kelvin"
|
||||
},
|
||||
{
|
||||
'label': i18n("Reaumur"),
|
||||
'name': "Reaumur"
|
||||
},
|
||||
{
|
||||
'label': i18n("cm^-1"),
|
||||
'name': "cm^-1"
|
||||
},
|
||||
{
|
||||
'label': i18n("kJ/mol"),
|
||||
'name': "kJ/mol"
|
||||
},
|
||||
{
|
||||
'label': i18n("kcal/mol"),
|
||||
'name': "kcal/mol"
|
||||
title: i18n("Actions")
|
||||
|
||||
Column {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
ButtonSelector {
|
||||
value: i18n("Drop key cache")
|
||||
onButtonActivated: awActions.dropCache()
|
||||
}
|
||||
ButtonSelector {
|
||||
ExportDialog {
|
||||
id: saveConfigAs
|
||||
configuration: plasmoid.configuration
|
||||
}
|
||||
]
|
||||
onCurrentIndexChanged: cfg_tempUnits = model[currentIndex]["name"]
|
||||
Component.onCompleted: {
|
||||
if (debug) console.debug()
|
||||
for (var i = 0; i < model.length; i++) {
|
||||
if (model[i]["name"] == plasmoid.configuration.tempUnits) {
|
||||
if (debug) console.info("Found", model[i]["name"], "on", i)
|
||||
tempUnits.currentIndex = i;
|
||||
value: i18n("Export configuration")
|
||||
onButtonActivated: saveConfigAs.open()
|
||||
}
|
||||
ButtonSelector {
|
||||
ImportDialog {
|
||||
id: loadConfigFrom
|
||||
onConfigurationReceived: {
|
||||
for (var key in configuration)
|
||||
plasmoid.configuration[key] = configuration[key]
|
||||
}
|
||||
}
|
||||
value: i18n("Import configuration")
|
||||
onButtonActivated: loadConfigFrom.open()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Row {
|
||||
QtControls.GroupBox {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
QtControls.Label {
|
||||
height: parent.height
|
||||
width: parent.width * 2 / 5
|
||||
horizontalAlignment: Text.AlignRight
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
text: i18n("Custom time format")
|
||||
}
|
||||
QtControls.TextField {
|
||||
id: customTime
|
||||
width: parent.width * 3 / 5
|
||||
text: plasmoid.configuration.customTime
|
||||
}
|
||||
}
|
||||
title: i18n("Telemetry")
|
||||
|
||||
Row {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
QtControls.Label {
|
||||
height: parent.height
|
||||
width: parent.width * 2 / 5
|
||||
horizontalAlignment: Text.AlignRight
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
text: i18n("Custom uptime format")
|
||||
}
|
||||
QtControls.TextField {
|
||||
id: customUptime
|
||||
width: parent.width * 3 / 5
|
||||
text: plasmoid.configuration.customUptime
|
||||
}
|
||||
}
|
||||
|
||||
Row {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
QtControls.Label {
|
||||
height: parent.height
|
||||
width: parent.width * 2 / 5
|
||||
horizontalAlignment: Text.AlignRight
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
text: i18n("AC online tag")
|
||||
}
|
||||
QtControls.TextField {
|
||||
id: acOnline
|
||||
width: parent.width * 3 / 5
|
||||
text: plasmoid.configuration.acOnline
|
||||
}
|
||||
}
|
||||
|
||||
Row {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
QtControls.Label {
|
||||
height: parent.height
|
||||
width: parent.width * 2 / 5
|
||||
horizontalAlignment: Text.AlignRight
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
text: i18n("AC offline tag")
|
||||
}
|
||||
QtControls.TextField {
|
||||
id: acOffline
|
||||
width: parent.width * 3 / 5
|
||||
text: plasmoid.configuration.acOffline
|
||||
}
|
||||
}
|
||||
|
||||
Row {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
QtControls.Label {
|
||||
height: parent.height
|
||||
width: parent.width * 2 / 5
|
||||
}
|
||||
QtControls.Button {
|
||||
width: parent.width * 3 / 5
|
||||
text: i18n("Drop key cache")
|
||||
onClicked: awActions.dropCache()
|
||||
}
|
||||
}
|
||||
|
||||
Row {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
QtControls.Label {
|
||||
height: parent.height
|
||||
width: parent.width * 2 / 5
|
||||
}
|
||||
QtControls.Button {
|
||||
width: parent.width * 3 / 5
|
||||
text: i18n("Export configuration")
|
||||
onClicked: saveConfigAs.open()
|
||||
}
|
||||
|
||||
QtDialogs.FileDialog {
|
||||
id: saveConfigAs
|
||||
selectExisting: false
|
||||
title: i18n("Export")
|
||||
folder: awConfig.configurationDirectory()
|
||||
onAccepted: {
|
||||
var status = awConfig.exportConfiguration(
|
||||
plasmoid.configuration,
|
||||
saveConfigAs.fileUrl.toString().replace("file://", ""))
|
||||
if (status) {
|
||||
messageDialog.title = i18n("Success")
|
||||
messageDialog.text = i18n("Please note that binary files were not copied")
|
||||
} else {
|
||||
messageDialog.title = i18n("Ooops...")
|
||||
messageDialog.text = i18n("Could not save configuration file")
|
||||
}
|
||||
messageDialog.open()
|
||||
Column {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
CheckBoxSelector {
|
||||
id: telemetryRemote
|
||||
text: i18n("Enable remote telemetry")
|
||||
}
|
||||
}
|
||||
|
||||
QtDialogs.MessageDialog {
|
||||
id: messageDialog
|
||||
standardButtons: QtDialogs.StandardButton.Ok
|
||||
}
|
||||
}
|
||||
|
||||
Row {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
QtControls.Label {
|
||||
height: parent.height
|
||||
width: parent.width * 2 / 5
|
||||
}
|
||||
QtControls.Button {
|
||||
width: parent.width * 3 / 5
|
||||
text: i18n("Import configuration")
|
||||
onClicked: openConfig.open()
|
||||
}
|
||||
|
||||
QtDialogs.FileDialog {
|
||||
id: openConfig
|
||||
title: i18n("Import")
|
||||
folder: awConfig.configurationDirectory()
|
||||
onAccepted: importSelection.open()
|
||||
}
|
||||
|
||||
QtDialogs.Dialog {
|
||||
id: importSelection
|
||||
|
||||
Column {
|
||||
QtControls.CheckBox {
|
||||
id: importPlasmoid
|
||||
text: i18n("Import plasmoid settings")
|
||||
}
|
||||
|
||||
QtControls.CheckBox {
|
||||
id: importExtensions
|
||||
text: i18n("Import extensions")
|
||||
}
|
||||
|
||||
QtControls.CheckBox {
|
||||
id: importAdds
|
||||
text: i18n("Import additional files")
|
||||
}
|
||||
IntegerSelector {
|
||||
id: telemetryCount
|
||||
maximumValue: 10000
|
||||
minimumValue: 0
|
||||
stepSize: 50
|
||||
text: i18n("History count")
|
||||
value: plasmoid.configuration.telemetryCount
|
||||
}
|
||||
|
||||
onAccepted: {
|
||||
if (debug) console.debug()
|
||||
var importConfig = awConfig.importConfiguration(
|
||||
openConfig.fileUrl.toString().replace("file://", ""),
|
||||
importPlasmoid.checked, importExtensions.checked,
|
||||
importAdds.checked)
|
||||
for (var key in importConfig)
|
||||
plasmoid.configuration[key] = importConfig[key]
|
||||
LineSelector {
|
||||
id: telemetryId
|
||||
text: i18n("Telemetry ID")
|
||||
value: plasmoid.configuration.telemetryId
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,11 +16,9 @@
|
||||
***************************************************************************/
|
||||
|
||||
import QtQuick 2.0
|
||||
import QtQuick.Controls 1.3 as QtControls
|
||||
import QtQuick.Controls.Styles 1.3 as QtStyles
|
||||
import QtQuick.Dialogs 1.1 as QtDialogs
|
||||
|
||||
import org.kde.plasma.private.awesomewidget 1.0
|
||||
import "."
|
||||
|
||||
|
||||
Item {
|
||||
@ -44,195 +42,68 @@ Item {
|
||||
87: 5
|
||||
}
|
||||
|
||||
property alias cfg_fontFamily: selectFont.text
|
||||
property alias cfg_fontFamily: font.value
|
||||
property alias cfg_fontSize: fontSize.value
|
||||
property string cfg_fontWeight: fontWeight.currentText
|
||||
property string cfg_fontStyle: fontStyle.currentText
|
||||
property alias cfg_fontColor: selectColor.text
|
||||
property string cfg_fontWeight: fontWeight.value
|
||||
property string cfg_fontStyle: fontStyle.value
|
||||
property alias cfg_fontColor: selectColor.value
|
||||
property alias cfg_textStyleColor: selectStyleColor.value
|
||||
property string cfg_textStyle: textStyle.value
|
||||
|
||||
|
||||
Column {
|
||||
id: pageColumn
|
||||
anchors.fill: parent
|
||||
Row {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
QtControls.Label {
|
||||
height: parent.height
|
||||
width: parent.width / 3
|
||||
horizontalAlignment: Text.AlignRight
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
text: i18n("Font")
|
||||
}
|
||||
QtControls.Button {
|
||||
id: selectFont
|
||||
width: parent.width * 2 / 3
|
||||
text: plasmoid.configuration.fontFamily
|
||||
onClicked: {
|
||||
if (debug) console.debug()
|
||||
fontDialog.setFont()
|
||||
fontDialog.visible = true
|
||||
}
|
||||
}
|
||||
|
||||
FontSelector {
|
||||
id: font
|
||||
text: i18n("Font")
|
||||
value: plasmoid.configuration.fontFamily
|
||||
}
|
||||
|
||||
Row {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
QtControls.Label {
|
||||
height: parent.height
|
||||
width: parent.width / 3
|
||||
horizontalAlignment: Text.AlignRight
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
text: i18n("Font size")
|
||||
}
|
||||
QtControls.SpinBox {
|
||||
id: fontSize
|
||||
width: parent.width * 2 / 3
|
||||
minimumValue: 8
|
||||
maximumValue: 32
|
||||
stepSize: 1
|
||||
value: plasmoid.configuration.fontSize
|
||||
}
|
||||
IntegerSelector {
|
||||
id: fontSize
|
||||
maximumValue: 32
|
||||
minimumValue: 8
|
||||
stepSize: 1
|
||||
text: i18n("Font size")
|
||||
value: plasmoid.configuration.fontSize
|
||||
}
|
||||
|
||||
Row {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
QtControls.Label {
|
||||
height: parent.height
|
||||
width: parent.width / 3
|
||||
horizontalAlignment: Text.AlignRight
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
text: i18n("Font weight")
|
||||
}
|
||||
QtControls.ComboBox {
|
||||
id: fontWeight
|
||||
width: parent.width * 2 / 3
|
||||
textRole: "label"
|
||||
model: [
|
||||
{
|
||||
'label': i18n("light"),
|
||||
'name': "light"
|
||||
},
|
||||
{
|
||||
'label': i18n("normal"),
|
||||
'name': "normal"
|
||||
},
|
||||
{
|
||||
'label': i18n("demi bold"),
|
||||
'name': "demibold"
|
||||
},
|
||||
{
|
||||
'label': i18n("bold"),
|
||||
'name': "bold"
|
||||
},
|
||||
{
|
||||
'label': i18n("black"),
|
||||
'name': "black"
|
||||
}
|
||||
]
|
||||
onCurrentIndexChanged: cfg_fontWeight = model[currentIndex]["name"]
|
||||
Component.onCompleted: {
|
||||
if (debug) console.debug()
|
||||
for (var i = 0; i < model.length; i++) {
|
||||
if (model[i]["name"] == plasmoid.configuration.fontWeight) {
|
||||
if (debug) console.info("Found", model[i]["name"], "on", i)
|
||||
fontWeight.currentIndex = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ComboBoxSelector {
|
||||
id: fontWeight
|
||||
model: general.fontWeightModel
|
||||
text: i18n("Font weight")
|
||||
value: plasmoid.configuration.fontWeight
|
||||
onValueEdited: cfg_fontWeight = newValue
|
||||
}
|
||||
|
||||
Row {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
QtControls.Label {
|
||||
height: parent.height
|
||||
width: parent.width / 3
|
||||
horizontalAlignment: Text.AlignRight
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
text: i18n("Font style")
|
||||
}
|
||||
QtControls.ComboBox {
|
||||
id: fontStyle
|
||||
width: parent.width * 2 / 3
|
||||
textRole: "label"
|
||||
model: [
|
||||
{
|
||||
'label': i18n("normal"),
|
||||
'name': "normal"
|
||||
},
|
||||
{
|
||||
'label': i18n("italic"),
|
||||
'name': "italic"
|
||||
}
|
||||
]
|
||||
onCurrentIndexChanged: cfg_fontStyle = model[currentIndex]["name"]
|
||||
Component.onCompleted: {
|
||||
if (debug) console.debug()
|
||||
for (var i = 0; i < model.length; i++) {
|
||||
if (model[i]["name"] == plasmoid.configuration.fontStyle) {
|
||||
if (debug) console.info("Found", model[i]["name"], "on", i)
|
||||
fontStyle.currentIndex = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ComboBoxSelector {
|
||||
id: fontStyle
|
||||
model: general.fontStyleModel
|
||||
text: i18n("Font style")
|
||||
value: plasmoid.configuration.fontStyle
|
||||
onValueEdited: cfg_fontStyle = newValue
|
||||
}
|
||||
|
||||
Row {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
QtControls.Label {
|
||||
height: parent.height
|
||||
width: parent.width / 3
|
||||
horizontalAlignment: Text.AlignRight
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
text: i18n("Font color")
|
||||
}
|
||||
QtControls.Button {
|
||||
id: selectColor
|
||||
width: parent.width * 2 / 3
|
||||
style: QtStyles.ButtonStyle {
|
||||
background: Rectangle {
|
||||
color: plasmoid.configuration.fontColor
|
||||
}
|
||||
}
|
||||
text: plasmoid.configuration.fontColor
|
||||
onClicked: colorDialog.visible = true
|
||||
}
|
||||
ColorSelector {
|
||||
id: selectColor
|
||||
text: i18n("Font color")
|
||||
value: plasmoid.configuration.fontColor
|
||||
}
|
||||
}
|
||||
|
||||
QtDialogs.ColorDialog {
|
||||
id: colorDialog
|
||||
title: i18n("Select a color")
|
||||
color: selectColor.text
|
||||
onAccepted: selectColor.text = colorDialog.color
|
||||
}
|
||||
|
||||
QtDialogs.FontDialog {
|
||||
id: fontDialog
|
||||
title: i18n("Select a font")
|
||||
signal setFont
|
||||
|
||||
onAccepted: {
|
||||
if (debug) console.debug()
|
||||
selectFont.text = fontDialog.font.family
|
||||
fontSize.value = fontDialog.font.pointSize
|
||||
fontStyle.currentIndex = fontDialog.font.italic ? 1 : 0
|
||||
fontWeight.currentIndex = weight[fontDialog.font.weight]
|
||||
ComboBoxSelector {
|
||||
id: textStyle
|
||||
model: general.textStyleModel
|
||||
text: i18n("Style")
|
||||
value: plasmoid.configuration.textStyle
|
||||
onValueEdited: cfg_textStyle = newValue
|
||||
}
|
||||
onSetFont: {
|
||||
if (debug) console.debug()
|
||||
fontDialog.font = Qt.font({
|
||||
family: selectFont.text,
|
||||
pointSize: fontSize.value > 0 ? fontSize.value : 12,
|
||||
italic: fontStyle.currentIndex == 1,
|
||||
weight: Font.Normal,
|
||||
})
|
||||
|
||||
ColorSelector {
|
||||
id: selectStyleColor
|
||||
text: i18n("Style color")
|
||||
value: plasmoid.configuration.textStyleColor
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -52,21 +52,10 @@ Item {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
title: i18n("ACPI")
|
||||
Row {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
QtControls.Label {
|
||||
height: parent.height
|
||||
width: parent.width * 2 / 5
|
||||
horizontalAlignment: Text.AlignRight
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
text: i18n("ACPI path")
|
||||
}
|
||||
QtControls.TextField {
|
||||
width: parent.width * 3 / 5
|
||||
text: cfg_dataengine["ACPIPATH"]
|
||||
onEditingFinished: cfg_dataengine["ACPIPATH"] = text
|
||||
}
|
||||
LineSelector {
|
||||
text: i18n("ACPI path")
|
||||
value: cfg_dataengine["ACPIPATH"]
|
||||
onValueEdited: cfg_dataengine["ACPIPATH"] = newValue
|
||||
}
|
||||
}
|
||||
|
||||
@ -74,30 +63,28 @@ Item {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
title: i18n("GPU")
|
||||
Row {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
QtControls.Label {
|
||||
height: parent.height
|
||||
width: parent.width * 2 / 5
|
||||
horizontalAlignment: Text.AlignRight
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
text: i18n("GPU device")
|
||||
}
|
||||
QtControls.ComboBox {
|
||||
id: gpuDev
|
||||
width: parent.width * 3 / 5
|
||||
model: ["auto", "disable", "ati", "nvidia"]
|
||||
Component.onCompleted: {
|
||||
if (debug) console.debug()
|
||||
for (var i=0; i<model.length; i++) {
|
||||
if (model[i] == cfg_dataengine["GPUDEV"]) {
|
||||
if (debug) console.info("Found", model[i], "on", i)
|
||||
currentIndex = i;
|
||||
}
|
||||
}
|
||||
ComboBoxSelector {
|
||||
model: [
|
||||
{
|
||||
'label': "auto",
|
||||
'name': "auto"
|
||||
},
|
||||
{
|
||||
'label': "disable",
|
||||
'name': "disable"
|
||||
},
|
||||
{
|
||||
'label': "ati",
|
||||
'name': "ati"
|
||||
},
|
||||
{
|
||||
'label': "nvidia",
|
||||
'name': "nvidia"
|
||||
}
|
||||
}
|
||||
]
|
||||
text: i18n("GPU device")
|
||||
value: cfg_dataengine["GPUDEV"]
|
||||
onValueEdited: cfg_dataengine["GPUDEV"] = newValue
|
||||
}
|
||||
}
|
||||
|
||||
@ -108,37 +95,17 @@ Item {
|
||||
Column {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
Row {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
QtControls.Label {
|
||||
height: parent.height
|
||||
width: parent.width * 2 / 5
|
||||
horizontalAlignment: Text.AlignRight
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
text: i18n("HDD")
|
||||
}
|
||||
QtControls.ComboBox {
|
||||
id: hdd
|
||||
width: parent.width * 3 / 5
|
||||
}
|
||||
ComboBoxSelector {
|
||||
id: hdd
|
||||
text: i18n("HDD")
|
||||
value: cfg_dataengine["HDDDEV"]
|
||||
onValueEdited: cfg_dataengine["HDDDEV"] = newValue
|
||||
}
|
||||
|
||||
Row {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
QtControls.Label {
|
||||
height: parent.height
|
||||
width: parent.width * 2 / 5
|
||||
horizontalAlignment: Text.AlignRight
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
text: i18n("hddtemp cmd")
|
||||
}
|
||||
QtControls.TextField {
|
||||
width: parent.width * 3 / 5
|
||||
text: cfg_dataengine["HDDTEMPCMD"]
|
||||
onEditingFinished: cfg_dataengine["HDDTEMPCMD"] = text
|
||||
}
|
||||
LineSelector {
|
||||
text: i18n("hddtemp cmd")
|
||||
value: cfg_dataengine["HDDTEMPCMD"]
|
||||
onValueEdited: cfg_dataengine["HDDTEMPCMD"] = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -150,107 +117,93 @@ Item {
|
||||
Column {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
Row {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
QtControls.Label {
|
||||
height: parent.height
|
||||
width: parent.width * 2 / 5
|
||||
horizontalAlignment: Text.AlignRight
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
text: i18n("Player data symbols")
|
||||
}
|
||||
QtControls.SpinBox {
|
||||
width: parent.width * 3 / 5
|
||||
minimumValue: 1
|
||||
maximumValue: 100
|
||||
stepSize: 1
|
||||
value: cfg_dataengine["PLAYERSYMBOLS"]
|
||||
onEditingFinished: cfg_dataengine["PLAYERSYMBOLS"] = value
|
||||
}
|
||||
IntegerSelector {
|
||||
maximumValue: 100
|
||||
minimumValue: 1
|
||||
stepSize: 1
|
||||
text: i18n("Player data symbols")
|
||||
value: cfg_dataengine["PLAYERSYMBOLS"]
|
||||
onValueEdited: cfg_dataengine["PLAYERSYMBOLS"] = newValue
|
||||
}
|
||||
|
||||
Row {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
QtControls.Label {
|
||||
height: parent.height
|
||||
width: parent.width * 2 / 5
|
||||
horizontalAlignment: Text.AlignRight
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
text: i18n("Music player")
|
||||
}
|
||||
QtControls.ComboBox {
|
||||
id: player
|
||||
width: parent.width * 3 / 5
|
||||
model: ["disable", "mpris", "mpd"]
|
||||
Component.onCompleted: {
|
||||
if (debug) console.debug()
|
||||
for (var i=0; i<model.length; i++) {
|
||||
if (model[i] == cfg_dataengine["PLAYER"]) {
|
||||
if (debug) console.info("Found", model[i], "on", i)
|
||||
player.currentIndex = i;
|
||||
}
|
||||
}
|
||||
ComboBoxSelector {
|
||||
model: [
|
||||
{
|
||||
'label': "disable",
|
||||
'name': "disable"
|
||||
},
|
||||
{
|
||||
'label': "mpris",
|
||||
'name': "mpris"
|
||||
},
|
||||
{
|
||||
'label': "mpd",
|
||||
'name': "mpd"
|
||||
}
|
||||
}
|
||||
]
|
||||
text: i18n("Music player")
|
||||
value: cfg_dataengine["PLAYER"]
|
||||
onValueEdited: cfg_dataengine["PLAYER"] = newValue
|
||||
}
|
||||
|
||||
Row {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
QtControls.Label {
|
||||
height: parent.height
|
||||
width: parent.width * 2 / 5
|
||||
horizontalAlignment: Text.AlignRight
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
text: i18n("MPRIS player name")
|
||||
}
|
||||
QtControls.ComboBox {
|
||||
id: mpris
|
||||
width: parent.width * 3 / 5
|
||||
editable: true
|
||||
model: ["auto", "amarok", "audacious", "clementine", "deadbeef",
|
||||
"vlc", "qmmp", "xmms2", cfg_dataengine["MPRIS"]]
|
||||
currentIndex: model.length - 1
|
||||
}
|
||||
ComboBoxSelector {
|
||||
id: mpris
|
||||
editable: true
|
||||
model: [
|
||||
{
|
||||
'label': 'auto',
|
||||
'name': 'auto'
|
||||
},
|
||||
{
|
||||
'label': 'amarok',
|
||||
'name': 'amarok'
|
||||
},
|
||||
{
|
||||
'label': 'audacious',
|
||||
'name': 'audacious'
|
||||
},
|
||||
{
|
||||
'label': 'clementine',
|
||||
'name': 'clementine'
|
||||
},
|
||||
{
|
||||
'label': 'deadbeef',
|
||||
'name': 'deadbeef'
|
||||
},
|
||||
{
|
||||
'label': 'vlc',
|
||||
'name': 'vlc'
|
||||
},
|
||||
{
|
||||
'label': 'qmmp',
|
||||
'name': 'qmmp'
|
||||
},
|
||||
{
|
||||
'label': 'xmms2',
|
||||
'name': 'xmms2'
|
||||
},
|
||||
{
|
||||
'label': cfg_dataengine["MPRIS"],
|
||||
'name': cfg_dataengine["MPRIS"]
|
||||
}
|
||||
]
|
||||
text: i18n("MPRIS player name")
|
||||
currentIndex: model.length - 1
|
||||
}
|
||||
|
||||
Row {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
QtControls.Label {
|
||||
height: parent.height
|
||||
width: parent.width * 2 / 5
|
||||
horizontalAlignment: Text.AlignRight
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
text: i18n("MPD address")
|
||||
}
|
||||
QtControls.TextField {
|
||||
width: parent.width * 3 / 5
|
||||
text: cfg_dataengine["MPDADDRESS"]
|
||||
onEditingFinished: cfg_dataengine["MPDADDRESS"] = text
|
||||
}
|
||||
LineSelector {
|
||||
text: i18n("MPD address")
|
||||
value: cfg_dataengine["MPDADDRESS"]
|
||||
onValueEdited: cfg_dataengine["MPDADDRESS"] = newValue
|
||||
}
|
||||
|
||||
Row {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
QtControls.Label {
|
||||
height: parent.height
|
||||
width: parent.width * 2 / 5
|
||||
horizontalAlignment: Text.AlignRight
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
text: i18n("MPD port")
|
||||
}
|
||||
QtControls.SpinBox {
|
||||
width: parent.width * 3 / 5
|
||||
minimumValue: 1000
|
||||
maximumValue: 65535
|
||||
stepSize: 1
|
||||
value: cfg_dataengine["MPDPORT"]
|
||||
onEditingFinished: cfg_dataengine["MPDPORT"] = value
|
||||
}
|
||||
IntegerSelector {
|
||||
maximumValue: 65535
|
||||
minimumValue: 1000
|
||||
stepSize: 1
|
||||
text: i18n("MPD port")
|
||||
value: cfg_dataengine["MPDPORT"]
|
||||
onValueEdited: cfg_dataengine["MPDPORT"] = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -262,72 +215,29 @@ Item {
|
||||
Column {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
Row {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
QtControls.Label {
|
||||
height: parent.height
|
||||
width: parent.width * 2 / 5
|
||||
horizontalAlignment: Text.AlignRight
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
text: i18n("Custom scripts")
|
||||
}
|
||||
QtControls.Button {
|
||||
width: parent.width * 3 / 5
|
||||
text: i18n("Edit scripts")
|
||||
onClicked: awKeys.editItem("extscript")
|
||||
}
|
||||
ButtonSelector {
|
||||
value: i18n("Custom scripts")
|
||||
onButtonActivated: awKeys.editItem("extscript")
|
||||
}
|
||||
|
||||
Row {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
QtControls.Label {
|
||||
height: parent.height
|
||||
width: parent.width * 2 / 5
|
||||
horizontalAlignment: Text.AlignRight
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
text: i18n("Quotes monitor")
|
||||
}
|
||||
QtControls.Button {
|
||||
width: parent.width * 3 / 5
|
||||
text: i18n("Edit tickers")
|
||||
onClicked: awKeys.editItem("extquotes")
|
||||
}
|
||||
ButtonSelector {
|
||||
value: i18n("Network requests")
|
||||
onButtonActivated: awKeys.editItem("extnetworkrequest")
|
||||
}
|
||||
|
||||
Row {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
QtControls.Label {
|
||||
height: parent.height
|
||||
width: parent.width * 2 / 5
|
||||
horizontalAlignment: Text.AlignRight
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
text: i18n("Package manager")
|
||||
}
|
||||
QtControls.Button {
|
||||
width: parent.width * 3 / 5
|
||||
text: i18n("Edit command")
|
||||
onClicked: awKeys.editItem("extupgrade")
|
||||
}
|
||||
ButtonSelector {
|
||||
value: i18n("Package manager")
|
||||
onButtonActivated: awKeys.editItem("extupgrade")
|
||||
}
|
||||
|
||||
Row {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
QtControls.Label {
|
||||
height: parent.height
|
||||
width: parent.width * 2 / 5
|
||||
horizontalAlignment: Text.AlignRight
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
text: i18n("Weather")
|
||||
}
|
||||
QtControls.Button {
|
||||
width: parent.width * 3 / 5
|
||||
text: i18n("Edit weather")
|
||||
onClicked: awKeys.editItem("extweather")
|
||||
}
|
||||
ButtonSelector {
|
||||
value: i18n("Quotes monitor")
|
||||
onButtonActivated: awKeys.editItem("extquotes")
|
||||
}
|
||||
|
||||
ButtonSelector {
|
||||
value: i18n("Weather")
|
||||
onButtonActivated: awKeys.editItem("extweather")
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -342,21 +252,13 @@ Item {
|
||||
|
||||
// update hdd model
|
||||
hdd.model = awKeys.getHddDevices()
|
||||
for (var i=0; i<hdd.model.length; i++) {
|
||||
if (hdd.model[i] == cfg_dataengine["HDDDEV"]) {
|
||||
if (debug) console.info("Found", hdd.model[i], "on", i)
|
||||
hdd.currentIndex = i;
|
||||
}
|
||||
}
|
||||
hdd.onCompleted
|
||||
}
|
||||
|
||||
Component.onDestruction: {
|
||||
if (debug) console.debug()
|
||||
|
||||
cfg_dataengine["GPUDEV"] = gpuDev.currentText
|
||||
cfg_dataengine["HDDDEV"] = hdd.currentText
|
||||
cfg_dataengine["PLAYER"] = player.currentText
|
||||
cfg_dataengine["MPRIS"] = mpris.currentText
|
||||
cfg_dataengine["MPRIS"] = mpris.editText
|
||||
awConfig.writeDataEngineConfiguration(cfg_dataengine)
|
||||
}
|
||||
}
|
||||
|
@ -36,6 +36,12 @@ Item {
|
||||
AWActions {
|
||||
id: awActions
|
||||
}
|
||||
AWTelemetryHandler {
|
||||
id: awTelemetryHandler
|
||||
}
|
||||
BugReport {
|
||||
id: bugReport
|
||||
}
|
||||
|
||||
property bool debug: awActions.isDebugEnabled()
|
||||
property variant tooltipSettings: {
|
||||
@ -98,6 +104,9 @@ Item {
|
||||
font.pointSize: plasmoid.configuration.fontSize
|
||||
font.weight: general.fontWeight[plasmoid.configuration.fontWeight]
|
||||
|
||||
style: general.textStyle[plasmoid.configuration.textStyle]
|
||||
styleColor: plasmoid.configuration.textStyleColor
|
||||
|
||||
PlasmaCore.ToolTipArea {
|
||||
height: tooltip.height
|
||||
width: tooltip.width
|
||||
@ -141,6 +150,7 @@ Item {
|
||||
plasmoid.setAction("requestKey", i18n("Request key"), "utilities-system-monitor")
|
||||
plasmoid.setAction("showReadme", i18n("Show README"), "text-x-readme")
|
||||
plasmoid.setAction("checkUpdates", i18n("Check updates"), "system-software-update")
|
||||
plasmoid.setAction("reportBug", i18n("Report bug"), "tools-report-bug")
|
||||
// init submodule
|
||||
Plasmoid.userConfiguringChanged(false)
|
||||
// connect data
|
||||
@ -200,6 +210,15 @@ Item {
|
||||
awKeys.setAggregatorProperty("customUptime", plasmoid.configuration.customUptime)
|
||||
awKeys.setAggregatorProperty("tempUnits", plasmoid.configuration.tempUnits)
|
||||
awKeys.setAggregatorProperty("translate", plasmoid.configuration.translateStrings)
|
||||
// update telemetry ID
|
||||
if (plasmoid.configuration.telemetryId.length == 0)
|
||||
plasmoid.configuration.telemetryId = generateUuid()
|
||||
// save telemetry
|
||||
awTelemetryHandler.init(plasmoid.configuration.telemetryCount,
|
||||
plasmoid.configuration.telemetryRemote,
|
||||
plasmoid.configuration.telemetryId)
|
||||
if (awTelemetryHandler.put("awwidgetconfig", plasmoid.configuration.text))
|
||||
awTelemetryHandler.uploadTelemetry("awwidgetconfig", plasmoid.configuration.text)
|
||||
}
|
||||
|
||||
|
||||
@ -215,10 +234,25 @@ Item {
|
||||
return awActions.showReadme()
|
||||
}
|
||||
|
||||
function action_reportBug() {
|
||||
if (debug) console.debug()
|
||||
|
||||
bugReport.reset()
|
||||
bugReport.open()
|
||||
}
|
||||
|
||||
function action_requestKey() {
|
||||
if (debug) console.debug()
|
||||
|
||||
tagSelectorBox.model = awKeys.dictKeys(true)
|
||||
return tagSelector.open()
|
||||
}
|
||||
|
||||
// code from http://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript
|
||||
function generateUuid() {
|
||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
||||
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
|
||||
return v.toString(16);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1 +1,27 @@
|
||||
singleton general 1.0 general.qml
|
||||
# Do not edit qmldir directly it will be overrided during compilation,
|
||||
# edit qml/qmldir.in file instead.
|
||||
|
||||
|
||||
# common QML constants
|
||||
singleton general 1.0 file:///usr/share/awesomewidgets/qml/general.qml
|
||||
|
||||
# custom QML UI classes
|
||||
AboutTab file:///usr/share/awesomewidgets/qml/AboutTab.qml
|
||||
AWExtensions file:///usr/share/awesomewidgets/qml/AWExtensions.qml
|
||||
AWInfoLabel file:///usr/share/awesomewidgets/qml/AWInfoLabel.qml
|
||||
AWTagSelector file:///usr/share/awesomewidgets/qml/AWTagSelector.qml
|
||||
AWTextEditor file:///usr/share/awesomewidgets/qml/AWTextEditor.qml
|
||||
BugReport file:///usr/share/awesomewidgets/qml/BugReport.qml
|
||||
ButtonSelector file:///usr/share/awesomewidgets/qml/ButtonSelector.qml
|
||||
CheckBoxSelector file:///usr/share/awesomewidgets/qml/CheckBoxSelector.qml
|
||||
ColorSelector file:///usr/share/awesomewidgets/qml/ColorSelector.qml
|
||||
ComboBoxSelector file:///usr/share/awesomewidgets/qml/ComboBoxSelector.qml
|
||||
ExportDialog file:///usr/share/awesomewidgets/qml/ExportDialog.qml
|
||||
FontSelector file:///usr/share/awesomewidgets/qml/FontSelector.qml
|
||||
HtmlDefaultFunctionsBar file:///usr/share/awesomewidgets/qml/HtmlDefaultFunctionsBar.qml
|
||||
HtmlEditorButton file:///usr/share/awesomewidgets/qml/HtmlEditorButton.qml
|
||||
HtmlEditorColor file:///usr/share/awesomewidgets/qml/HtmlEditorColor.qml
|
||||
HtmlEditorFont file:///usr/share/awesomewidgets/qml/HtmlEditorFont.qml
|
||||
ImportDialog file:///usr/share/awesomewidgets/qml/ImportDialog.qml
|
||||
IntegerSelector file:///usr/share/awesomewidgets/qml/IntegerSelector.qml
|
||||
LineSelector file:///usr/share/awesomewidgets/qml/LineSelector.qml
|
||||
|
@ -17,8 +17,6 @@
|
||||
|
||||
import QtQuick 2.0
|
||||
import QtQuick.Controls 1.3 as QtControls
|
||||
import QtQuick.Controls.Styles 1.3 as QtStyles
|
||||
import QtQuick.Dialogs 1.1 as QtDialogs
|
||||
|
||||
import org.kde.plasma.private.awesomewidget 1.0
|
||||
|
||||
@ -39,21 +37,21 @@ Item {
|
||||
|
||||
property alias cfg_tooltipNumber: tooltipNumber.value
|
||||
property alias cfg_useTooltipBackground: useTooltipBackground.checked
|
||||
property alias cfg_tooltipBackground: tooltipBackground.text
|
||||
property alias cfg_tooltipBackground: tooltipBackground.value
|
||||
property alias cfg_cpuTooltip: cpuTooltip.checked
|
||||
property alias cfg_cpuTooltipColor: cpuTooltipColor.text
|
||||
property alias cfg_cpuTooltipColor: cpuTooltipColor.value
|
||||
property alias cfg_cpuclTooltip: cpuclTooltip.checked
|
||||
property alias cfg_cpuclTooltipColor: cpuclTooltipColor.text
|
||||
property alias cfg_cpuclTooltipColor: cpuclTooltipColor.value
|
||||
property alias cfg_memTooltip: memTooltip.checked
|
||||
property alias cfg_memTooltipColor: memTooltipColor.text
|
||||
property alias cfg_memTooltipColor: memTooltipColor.value
|
||||
property alias cfg_swapTooltip: swapTooltip.checked
|
||||
property alias cfg_swapTooltipColor: swapTooltipColor.text
|
||||
property alias cfg_swapTooltipColor: swapTooltipColor.value
|
||||
property alias cfg_downkbTooltip: downkbTooltip.checked
|
||||
property alias cfg_downkbTooltipColor: downkbTooltipColor.text
|
||||
property alias cfg_upkbTooltipColor: upkbTooltipColor.text
|
||||
property alias cfg_downkbTooltipColor: downkbTooltipColor.value
|
||||
property alias cfg_upkbTooltipColor: upkbTooltipColor.value
|
||||
property alias cfg_batTooltip: batTooltip.checked
|
||||
property alias cfg_batTooltipColor: batTooltipColor.text
|
||||
property alias cfg_batInTooltipColor: batInTooltipColor.text
|
||||
property alias cfg_batTooltipColor: batTooltipColor.value
|
||||
property alias cfg_batInTooltipColor: batInTooltipColor.value
|
||||
|
||||
|
||||
Column {
|
||||
@ -67,24 +65,13 @@ Item {
|
||||
text: i18n("CPU, CPU clock, memory, swap and network labels support graphical tooltip. To enable them just make needed checkbox checked.")
|
||||
}
|
||||
|
||||
Row {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
QtControls.Label {
|
||||
height: parent.height
|
||||
width: parent.width * 2 / 5
|
||||
horizontalAlignment: Text.AlignRight
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
text: i18n("Number of values for tooltips")
|
||||
}
|
||||
QtControls.SpinBox {
|
||||
id: tooltipNumber
|
||||
width: parent.width * 3 / 5
|
||||
minimumValue: 50
|
||||
maximumValue: 1000
|
||||
stepSize: 25
|
||||
value: plasmoid.configuration.tooltipNumber
|
||||
}
|
||||
IntegerSelector {
|
||||
id: tooltipNumber
|
||||
maximumValue: 1000
|
||||
minimumValue: 50
|
||||
stepSize: 25
|
||||
text: i18n("Number of values for tooltips")
|
||||
value: plasmoid.configuration.tooltipNumber
|
||||
}
|
||||
|
||||
QtControls.GroupBox {
|
||||
@ -93,34 +80,10 @@ Item {
|
||||
width: parent.width
|
||||
checkable: true
|
||||
title: i18n("Background")
|
||||
Row {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
QtControls.Label {
|
||||
height: parent.height
|
||||
width: parent.width * 2 / 5
|
||||
horizontalAlignment: Text.AlignRight
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
text: i18n("Background color")
|
||||
}
|
||||
QtControls.Button {
|
||||
id: tooltipBackground
|
||||
width: parent.width * 3 / 5
|
||||
style: QtStyles.ButtonStyle {
|
||||
background: Rectangle {
|
||||
color: plasmoid.configuration.tooltipBackground
|
||||
}
|
||||
}
|
||||
text: plasmoid.configuration.tooltipBackground
|
||||
onClicked: tooltipBackgroundDialog.visible = true
|
||||
}
|
||||
|
||||
QtDialogs.ColorDialog {
|
||||
id: tooltipBackgroundDialog
|
||||
title: i18n("Select a color")
|
||||
color: tooltipBackground.text
|
||||
onAccepted: tooltipBackground.text = tooltipBackgroundDialog.color
|
||||
}
|
||||
ColorSelector {
|
||||
id: tooltipBackground
|
||||
text: i18n("Background color")
|
||||
value: plasmoid.configuration.tooltipBackground
|
||||
}
|
||||
}
|
||||
|
||||
@ -130,34 +93,10 @@ Item {
|
||||
width: parent.width
|
||||
checkable: true
|
||||
title: i18n("CPU")
|
||||
Row {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
QtControls.Label {
|
||||
height: parent.height
|
||||
width: parent.width * 2 / 5
|
||||
horizontalAlignment: Text.AlignRight
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
text: i18n("CPU color")
|
||||
}
|
||||
QtControls.Button {
|
||||
id: cpuTooltipColor
|
||||
width: parent.width * 3 / 5
|
||||
style: QtStyles.ButtonStyle {
|
||||
background: Rectangle {
|
||||
color: plasmoid.configuration.cpuTooltipColor
|
||||
}
|
||||
}
|
||||
text: plasmoid.configuration.cpuTooltipColor
|
||||
onClicked: cpuTooltipColorDialog.visible = true
|
||||
}
|
||||
|
||||
QtDialogs.ColorDialog {
|
||||
id: cpuTooltipColorDialog
|
||||
title: i18n("Select a color")
|
||||
color: cpuTooltipColor.text
|
||||
onAccepted: cpuTooltipColor.text = cpuTooltipColorDialog.color
|
||||
}
|
||||
ColorSelector {
|
||||
id: cpuTooltipColor
|
||||
text: i18n("CPU color")
|
||||
value: plasmoid.configuration.cpuTooltipColor
|
||||
}
|
||||
}
|
||||
|
||||
@ -167,34 +106,10 @@ Item {
|
||||
width: parent.width
|
||||
checkable: true
|
||||
title: i18n("CPU clock")
|
||||
Row {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
QtControls.Label {
|
||||
height: parent.height
|
||||
width: parent.width * 2 / 5
|
||||
horizontalAlignment: Text.AlignRight
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
text: i18n("CPU clock color")
|
||||
}
|
||||
QtControls.Button {
|
||||
id: cpuclTooltipColor
|
||||
width: parent.width * 3 / 5
|
||||
style: QtStyles.ButtonStyle {
|
||||
background: Rectangle {
|
||||
color: plasmoid.configuration.cpuclTooltipColor
|
||||
}
|
||||
}
|
||||
text: plasmoid.configuration.cpuclTooltipColor
|
||||
onClicked: cpuclTooltipColorDialog.visible = true
|
||||
}
|
||||
|
||||
QtDialogs.ColorDialog {
|
||||
id: cpuclTooltipColorDialog
|
||||
title: i18n("Select a color")
|
||||
color: cpuclTooltipColor.text
|
||||
onAccepted: cpuclTooltipColor.text = cpuclTooltipColorDialog.color
|
||||
}
|
||||
ColorSelector {
|
||||
id: cpuclTooltipColor
|
||||
text: i18n("CPU clock color")
|
||||
value: plasmoid.configuration.cpuclTooltipColor
|
||||
}
|
||||
}
|
||||
|
||||
@ -204,34 +119,10 @@ Item {
|
||||
width: parent.width
|
||||
checkable: true
|
||||
title: i18n("Memory")
|
||||
Row {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
QtControls.Label {
|
||||
height: parent.height
|
||||
width: parent.width * 2 / 5
|
||||
horizontalAlignment: Text.AlignRight
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
text: i18n("Memory color")
|
||||
}
|
||||
QtControls.Button {
|
||||
id: memTooltipColor
|
||||
width: parent.width * 3 / 5
|
||||
style: QtStyles.ButtonStyle {
|
||||
background: Rectangle {
|
||||
color: plasmoid.configuration.memTooltipColor
|
||||
}
|
||||
}
|
||||
text: plasmoid.configuration.memTooltipColor
|
||||
onClicked: memTooltipColorDialog.visible = true
|
||||
}
|
||||
|
||||
QtDialogs.ColorDialog {
|
||||
id: memTooltipColorDialog
|
||||
title: i18n("Select a color")
|
||||
color: memTooltipColor.text
|
||||
onAccepted: memTooltipColor.text = memTooltipColorDialog.color
|
||||
}
|
||||
ColorSelector {
|
||||
id: memTooltipColor
|
||||
text: i18n("Memory color")
|
||||
value: plasmoid.configuration.memTooltipColor
|
||||
}
|
||||
}
|
||||
|
||||
@ -241,34 +132,10 @@ Item {
|
||||
width: parent.width
|
||||
checkable: true
|
||||
title: i18n("Swap")
|
||||
Row {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
QtControls.Label {
|
||||
height: parent.height
|
||||
width: parent.width * 2 / 5
|
||||
horizontalAlignment: Text.AlignRight
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
text: i18n("Swap color")
|
||||
}
|
||||
QtControls.Button {
|
||||
id: swapTooltipColor
|
||||
width: parent.width * 3 / 5
|
||||
style: QtStyles.ButtonStyle {
|
||||
background: Rectangle {
|
||||
color: plasmoid.configuration.swapTooltipColor
|
||||
}
|
||||
}
|
||||
text: plasmoid.configuration.swapTooltipColor
|
||||
onClicked: swapTooltipColorDialog.visible = true
|
||||
}
|
||||
|
||||
QtDialogs.ColorDialog {
|
||||
id: swapTooltipColorDialog
|
||||
title: i18n("Select a color")
|
||||
color: swapTooltipColor.text
|
||||
onAccepted: swapTooltipColor.text = swapTooltipColorDialog.color
|
||||
}
|
||||
ColorSelector {
|
||||
id: swapTooltipColor
|
||||
text: i18n("Swap color")
|
||||
value: plasmoid.configuration.swapTooltipColor
|
||||
}
|
||||
}
|
||||
|
||||
@ -281,63 +148,15 @@ Item {
|
||||
Column {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
Row {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
QtControls.Label {
|
||||
height: parent.height
|
||||
width: parent.width * 2 / 5
|
||||
horizontalAlignment: Text.AlignRight
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
text: i18n("Download speed color")
|
||||
}
|
||||
QtControls.Button {
|
||||
id: downkbTooltipColor
|
||||
width: parent.width * 3 / 5
|
||||
style: QtStyles.ButtonStyle {
|
||||
background: Rectangle {
|
||||
color: plasmoid.configuration.downkbTooltipColor
|
||||
}
|
||||
}
|
||||
text: plasmoid.configuration.downkbTooltipColor
|
||||
onClicked: downkbTooltipColorDialog.visible = true
|
||||
}
|
||||
|
||||
QtDialogs.ColorDialog {
|
||||
id: downkbTooltipColorDialog
|
||||
title: i18n("Select a color")
|
||||
color: downkbTooltipColor.text
|
||||
onAccepted: downkbTooltipColor.text = downkbTooltipColorDialog.color
|
||||
}
|
||||
ColorSelector {
|
||||
id: downkbTooltipColor
|
||||
text: i18n("Download speed color")
|
||||
value: plasmoid.configuration.downkbTooltipColor
|
||||
}
|
||||
Row {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
QtControls.Label {
|
||||
height: parent.height
|
||||
width: parent.width * 2 / 5
|
||||
horizontalAlignment: Text.AlignRight
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
text: i18n("Upload speed color")
|
||||
}
|
||||
QtControls.Button {
|
||||
id: upkbTooltipColor
|
||||
width: parent.width * 3 / 5
|
||||
style: QtStyles.ButtonStyle {
|
||||
background: Rectangle {
|
||||
color: plasmoid.configuration.upkbTooltipColor
|
||||
}
|
||||
}
|
||||
text: plasmoid.configuration.upkbTooltipColor
|
||||
onClicked: upkbTooltipColorDialog.visible = true
|
||||
}
|
||||
|
||||
QtDialogs.ColorDialog {
|
||||
id: upkbTooltipColorDialog
|
||||
title: i18n("Select a color")
|
||||
color: upkbTooltipColor.text
|
||||
onAccepted: upkbTooltipColor.text = upkbTooltipColorDialog.color
|
||||
}
|
||||
ColorSelector {
|
||||
id: upkbTooltipColor
|
||||
text: i18n("Upload speed color")
|
||||
value: plasmoid.configuration.upkbTooltipColor
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -351,63 +170,15 @@ Item {
|
||||
Column {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
Row {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
QtControls.Label {
|
||||
height: parent.height
|
||||
width: parent.width * 2 / 5
|
||||
horizontalAlignment: Text.AlignRight
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
text: i18n("Battery active color")
|
||||
}
|
||||
QtControls.Button {
|
||||
id: batTooltipColor
|
||||
width: parent.width * 3 / 5
|
||||
style: QtStyles.ButtonStyle {
|
||||
background: Rectangle {
|
||||
color: plasmoid.configuration.batTooltipColor
|
||||
}
|
||||
}
|
||||
text: plasmoid.configuration.batTooltipColor
|
||||
onClicked: batTooltipColorDialog.visible = true
|
||||
}
|
||||
|
||||
QtDialogs.ColorDialog {
|
||||
id: batTooltipColorDialog
|
||||
title: i18n("Select a color")
|
||||
color: batTooltipColor.text
|
||||
onAccepted: batTooltipColor.text = batTooltipColorDialog.color
|
||||
}
|
||||
ColorSelector {
|
||||
id: batTooltipColor
|
||||
text: i18n("Battery active color")
|
||||
value: plasmoid.configuration.batTooltipColor
|
||||
}
|
||||
Row {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
QtControls.Label {
|
||||
height: parent.height
|
||||
width: parent.width * 2 / 5
|
||||
horizontalAlignment: Text.AlignRight
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
text: i18n("Battery inactive color")
|
||||
}
|
||||
QtControls.Button {
|
||||
id: batInTooltipColor
|
||||
width: parent.width * 3 / 5
|
||||
style: QtStyles.ButtonStyle {
|
||||
background: Rectangle {
|
||||
color: plasmoid.configuration.batInTooltipColor
|
||||
}
|
||||
}
|
||||
text: plasmoid.configuration.batInTooltipColor
|
||||
onClicked: batInTooltipColorDialog.visible = true
|
||||
}
|
||||
|
||||
QtDialogs.ColorDialog {
|
||||
id: batInTooltipColorDialog
|
||||
title: i18n("Select a color")
|
||||
color: batInTooltipColor.text
|
||||
onAccepted: batInTooltipColor.text = batInTooltipColorDialog.color
|
||||
}
|
||||
ColorSelector {
|
||||
id: batInTooltipColor
|
||||
text: i18n("Battery inactive color")
|
||||
value: plasmoid.configuration.batInTooltipColor
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,11 +15,10 @@
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
import QtQuick 2.0
|
||||
import QtQuick.Controls 1.3 as QtControls
|
||||
import QtQuick.Dialogs 1.2 as QtDialogs
|
||||
import QtQuick 2.2
|
||||
|
||||
import org.kde.plasma.private.awesomewidget 1.0
|
||||
import "."
|
||||
|
||||
|
||||
Item {
|
||||
@ -31,9 +30,6 @@ Item {
|
||||
AWActions {
|
||||
id: awActions
|
||||
}
|
||||
AWFormatterConfigFactory {
|
||||
id: awFormatter
|
||||
}
|
||||
|
||||
width: childrenRect.width
|
||||
height: childrenRect.height
|
||||
@ -51,313 +47,33 @@ Item {
|
||||
Column {
|
||||
id: pageColumn
|
||||
anchors.fill: parent
|
||||
QtControls.Label {
|
||||
width: parent.width
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
wrapMode: Text.WordWrap
|
||||
text: i18n("Detailed information may be found on <a href=\"https://arcanis.me/projects/awesome-widgets/\">project homepage</a>")
|
||||
onLinkActivated: Qt.openUrlExternally(link);
|
||||
|
||||
AWInfoLabel {}
|
||||
|
||||
HtmlDefaultFunctionsBar {
|
||||
textArea: textPattern
|
||||
}
|
||||
|
||||
Row {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
QtControls.Button {
|
||||
width: parent.width * 3 / 15
|
||||
text: i18n("Bgcolor")
|
||||
|
||||
onClicked: backgroundDialog.visible = true
|
||||
|
||||
QtDialogs.ColorDialog {
|
||||
id: backgroundDialog
|
||||
title: i18n("Select a color")
|
||||
onAccepted: {
|
||||
var text = textPattern.text
|
||||
textPattern.text = "<body bgcolor=\"" +
|
||||
backgroundDialog.color + "\">" +
|
||||
text + "</body>"
|
||||
}
|
||||
}
|
||||
}
|
||||
QtControls.Button {
|
||||
width: parent.width * 3 / 15
|
||||
text: i18n("Font")
|
||||
iconName: "font"
|
||||
|
||||
onClicked: {
|
||||
if (debug) console.debug("Font button")
|
||||
var defaultFont = {
|
||||
"color": plasmoid.configuration.fontColor,
|
||||
"family": plasmoid.configuration.fontFamily,
|
||||
"size": plasmoid.configuration.fontSize
|
||||
}
|
||||
var font = awActions.getFont(defaultFont)
|
||||
if (font.applied != 1) {
|
||||
if (debug) console.debug("No font selected")
|
||||
return
|
||||
}
|
||||
|
||||
var selected = textPattern.selectedText
|
||||
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
|
||||
textPattern.insert(textPattern.cursorPosition,
|
||||
"<span style=\"color:" + font.color +
|
||||
"; font-family:'" + font.family +
|
||||
"'; font-size:" + font.size + "pt;\">" +
|
||||
selected + "</span>")
|
||||
}
|
||||
}
|
||||
QtControls.Button {
|
||||
width: parent.width / 15
|
||||
iconName: "format-indent-more"
|
||||
|
||||
onClicked: {
|
||||
if (debug) console.debug("Indent button")
|
||||
var selected = textPattern.selectedText
|
||||
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
|
||||
textPattern.insert(textPattern.cursorPosition, selected + "<br>\n")
|
||||
}
|
||||
}
|
||||
|
||||
QtControls.Button {
|
||||
width: parent.width / 15
|
||||
iconName: "format-text-bold"
|
||||
|
||||
onClicked: {
|
||||
if (debug) console.debug("Bold button")
|
||||
var selected = textPattern.selectedText
|
||||
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
|
||||
textPattern.insert(textPattern.cursorPosition, "<b>" + selected + "</b>")
|
||||
}
|
||||
}
|
||||
QtControls.Button {
|
||||
width: parent.width / 15
|
||||
iconName: "format-text-italic"
|
||||
|
||||
onClicked: {
|
||||
if (debug) console.debug("Italic button")
|
||||
var selected = textPattern.selectedText
|
||||
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
|
||||
textPattern.insert(textPattern.cursorPosition, "<i>" + selected + "</i>")
|
||||
}
|
||||
}
|
||||
QtControls.Button {
|
||||
width: parent.width / 15
|
||||
iconName: "format-text-underline"
|
||||
|
||||
onClicked: {
|
||||
if (debug) console.debug("Underline button")
|
||||
var selected = textPattern.selectedText
|
||||
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
|
||||
textPattern.insert(textPattern.cursorPosition, "<u>" + selected + "</u>")
|
||||
}
|
||||
}
|
||||
QtControls.Button {
|
||||
width: parent.width / 15
|
||||
iconName: "format-text-strikethrough"
|
||||
|
||||
onClicked: {
|
||||
if (debug) console.debug("Strike button")
|
||||
var selected = textPattern.selectedText
|
||||
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
|
||||
textPattern.insert(textPattern.cursorPosition, "<s>" + selected + "</s>")
|
||||
}
|
||||
}
|
||||
|
||||
QtControls.Button {
|
||||
width: parent.width / 15
|
||||
iconName: "format-justify-left"
|
||||
|
||||
onClicked: {
|
||||
if (debug) console.debug("Left button")
|
||||
var selected = textPattern.selectedText
|
||||
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
|
||||
textPattern.insert(textPattern.cursorPosition, "<p align=\"left\">" + selected + "</p>")
|
||||
}
|
||||
}
|
||||
QtControls.Button {
|
||||
width: parent.width / 15
|
||||
iconName: "format-justify-center"
|
||||
|
||||
onClicked: {
|
||||
if (debug) console.debug("Center button")
|
||||
var selected = textPattern.selectedText
|
||||
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
|
||||
textPattern.insert(textPattern.cursorPosition, "<p align=\"center\">" + selected + "</p>")
|
||||
}
|
||||
}
|
||||
QtControls.Button {
|
||||
width: parent.width / 15
|
||||
iconName: "format-justify-right"
|
||||
|
||||
onClicked: {
|
||||
if (debug) console.debug("Right button")
|
||||
var selected = textPattern.selectedText
|
||||
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
|
||||
textPattern.insert(textPattern.cursorPosition, "<p align=\"right\">" + selected + "</p>")
|
||||
}
|
||||
}
|
||||
QtControls.Button {
|
||||
width: parent.width / 15
|
||||
iconName: "format-justify-fill"
|
||||
|
||||
onClicked: {
|
||||
if (debug) console.debug("Justify button")
|
||||
var selected = textPattern.selectedText
|
||||
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
|
||||
textPattern.insert(textPattern.cursorPosition, "<p align=\"justify\">" + selected + "</p>")
|
||||
}
|
||||
}
|
||||
AWTagSelector {
|
||||
backend: awKeys
|
||||
notifyBackend: awActions
|
||||
textArea: textPattern
|
||||
groups: general.awTagRegexp
|
||||
}
|
||||
|
||||
Row {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
QtControls.ComboBox {
|
||||
width: parent.width * 2 / 5
|
||||
textRole: "label"
|
||||
model: [
|
||||
{
|
||||
'label': i18n("AC"),
|
||||
'regexp': "^(ac|bat).*"
|
||||
},
|
||||
{
|
||||
'label': i18n("Bars"),
|
||||
'regexp': "^bar.*"
|
||||
},
|
||||
{
|
||||
'label': i18n("CPU"),
|
||||
'regexp': "^(cpu|gpu|la|ps|temp(?!erature)).*"
|
||||
},
|
||||
{
|
||||
'label': i18n("Desktops"),
|
||||
'regexp': "^(n|t)?desktop(s)?"
|
||||
},
|
||||
{
|
||||
'label': i18n("HDD"),
|
||||
'regexp': "^hdd.*"
|
||||
},
|
||||
{
|
||||
'label': i18n("Memory"),
|
||||
'regexp': "^(mem|swap).*"
|
||||
},
|
||||
{
|
||||
'label': i18n("Network"),
|
||||
'regexp': "^(netdev|(down|up(?!time)).*)"
|
||||
},
|
||||
{
|
||||
'label': i18n("Music player"),
|
||||
'regexp': "(^|d|s)(album|artist|duration|progress|title)"
|
||||
},
|
||||
{
|
||||
'label': i18n("Scripts"),
|
||||
'regexp': "^custom.*"
|
||||
},
|
||||
{
|
||||
'label': i18n("Time"),
|
||||
'regexp': ".*time$"
|
||||
},
|
||||
{
|
||||
'label': i18n("Quotes"),
|
||||
'regexp': "^(perc)?(ask|bid|price)(chg)?.*"
|
||||
},
|
||||
{
|
||||
'label': i18n("Upgrades"),
|
||||
'regexp': "^pkgcount.*"
|
||||
},
|
||||
{
|
||||
'label': i18n("Weathers"),
|
||||
'regexp': "^(weather(Id)?|humidity|pressure|temperature|timestamp)"
|
||||
},
|
||||
{
|
||||
'label': i18n("Functions"),
|
||||
'regexp': "functions"
|
||||
}
|
||||
]
|
||||
onCurrentIndexChanged: {
|
||||
if (debug) console.debug()
|
||||
if (model[currentIndex]["regexp"] == "functions")
|
||||
tags.model = ["{{\n\n}}", "template{{\n\n}}",
|
||||
"aw_all<>{{}}", "aw_count<>{{}}", "aw_keys<>{{}}",
|
||||
"aw_macro<>{{}}", "aw_names<>{{}}"]
|
||||
else
|
||||
tags.model = awKeys.dictKeys(true, model[currentIndex]["regexp"])
|
||||
if (debug) console.info("Init model", tags.model, "for", model[currentIndex]["label"])
|
||||
tags.currentIndex = -1
|
||||
}
|
||||
}
|
||||
QtControls.ComboBox {
|
||||
id: tags
|
||||
width: parent.width * 1 / 5
|
||||
}
|
||||
QtControls.Button {
|
||||
width: parent.width * 1 / 5
|
||||
text: i18n("Add")
|
||||
|
||||
onClicked: {
|
||||
if (!tags.currentText) return
|
||||
if (debug) console.debug("Add tag button")
|
||||
var selected = textPattern.selectedText
|
||||
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
|
||||
textPattern.insert(textPattern.cursorPosition, selected + "$" + tags.currentText)
|
||||
}
|
||||
}
|
||||
QtControls.Button {
|
||||
width: parent.width * 1 / 5
|
||||
text: i18n("Show value")
|
||||
|
||||
onClicked: {
|
||||
if (!tags.currentText) return
|
||||
if (debug) console.debug("Show tag button")
|
||||
var message = i18n("Tag: %1", tags.currentText)
|
||||
message += "<br>"
|
||||
message += i18n("Value: %1", awKeys.valueByKey(tags.currentText))
|
||||
message += "<br>"
|
||||
message += i18n("Info: %1", awKeys.infoByKey(tags.currentText))
|
||||
awActions.sendNotification("tag", message)
|
||||
}
|
||||
}
|
||||
AWExtensions {
|
||||
id: extensions
|
||||
backend: awKeys
|
||||
textArea: textPattern
|
||||
onUnlock: lock = false
|
||||
}
|
||||
|
||||
Row {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
QtControls.Button {
|
||||
width: parent.width * 3 / 10
|
||||
text: i18n("Edit bars")
|
||||
onClicked: awKeys.editItem("graphicalitem")
|
||||
}
|
||||
QtControls.Button {
|
||||
width: parent.width * 3 / 10
|
||||
text: i18n("Formatters")
|
||||
onClicked: awFormatter.showDialog(awKeys.dictKeys(true))
|
||||
}
|
||||
QtControls.Button {
|
||||
width: parent.width * 2 / 5
|
||||
text: i18n("Preview")
|
||||
onClicked: {
|
||||
lock = false
|
||||
awKeys.initKeys(textPattern.text, plasmoid.configuration.interval,
|
||||
plasmoid.configuration.queueLimit, false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QtControls.TextArea {
|
||||
AWTextEditor {
|
||||
id: textPattern
|
||||
width: parent.width
|
||||
height: parent.height * 4 / 5
|
||||
textFormat: TextEdit.PlainText
|
||||
text: plasmoid.configuration.text
|
||||
backend: awKeys
|
||||
}
|
||||
}
|
||||
|
||||
QtDialogs.MessageDialog {
|
||||
id: compiledText
|
||||
modality: Qt.NonModal
|
||||
title: i18n("Preview")
|
||||
}
|
||||
|
||||
|
||||
Component.onCompleted: {
|
||||
if (debug) console.debug()
|
||||
@ -378,8 +94,7 @@ Item {
|
||||
if (lock) return
|
||||
if (debug) console.debug()
|
||||
|
||||
compiledText.text = newText.replace(/ /g, " ")
|
||||
compiledText.open()
|
||||
lock = true;
|
||||
extensions.showMessage(newText)
|
||||
lock = true
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ X-Plasma-RemoteLocation=
|
||||
X-KDE-PluginInfo-Author=Evgeniy Alekseev aka arcanis
|
||||
X-KDE-PluginInfo-Email=esalexeev@gmail.com
|
||||
X-KDE-PluginInfo-Name=org.kde.plasma.awesomewidget
|
||||
X-KDE-PluginInfo-Version=3.2.1
|
||||
X-KDE-PluginInfo-Version=3.3.1
|
||||
X-KDE-PluginInfo-Website=https://arcanis.me/projects/awesome-widgets/
|
||||
X-KDE-PluginInfo-Category=System Information
|
||||
X-KDE-PluginInfo-Depends=
|
||||
|
@ -21,13 +21,16 @@
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
AWAbstractSelector::AWAbstractSelector(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
AWAbstractSelector::AWAbstractSelector(QWidget *_parent,
|
||||
const QPair<bool, bool> &_editable)
|
||||
: QWidget(_parent)
|
||||
, ui(new Ui::AWAbstractSelector)
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
|
||||
ui->setupUi(this);
|
||||
ui->comboBox_key->setEditable(_editable.first);
|
||||
ui->comboBox_value->setEditable(_editable.second);
|
||||
|
||||
connect(ui->comboBox_key, SIGNAL(currentIndexChanged(int)), this,
|
||||
SIGNAL(selectionChanged()));
|
||||
@ -53,24 +56,26 @@ QPair<QString, QString> AWAbstractSelector::current() const
|
||||
}
|
||||
|
||||
|
||||
void AWAbstractSelector::init(const QStringList keys, const QStringList values,
|
||||
const QPair<QString, QString> current)
|
||||
void AWAbstractSelector::init(const QStringList &_keys,
|
||||
const QStringList &_values,
|
||||
const QPair<QString, QString> &_current)
|
||||
{
|
||||
if ((!keys.contains(current.first)) || (!values.contains(current.second))) {
|
||||
qCWarning(LOG_AW) << "Invalid current value" << current
|
||||
if ((!_keys.contains(_current.first))
|
||||
|| (!_values.contains(_current.second))) {
|
||||
qCWarning(LOG_AW) << "Invalid current value" << _current
|
||||
<< "not found in default ones";
|
||||
return;
|
||||
}
|
||||
qCDebug(LOG_AW) << "Init selector with keys" << keys << "and values"
|
||||
<< values << "and current ones are" << current;
|
||||
qCDebug(LOG_AW) << "Init selector with keys" << _keys << "and values"
|
||||
<< _values << "and current ones are" << _current;
|
||||
|
||||
// set data
|
||||
ui->comboBox_key->clear();
|
||||
ui->comboBox_key->addItems(keys);
|
||||
ui->comboBox_key->addItems(_keys);
|
||||
ui->comboBox_value->clear();
|
||||
ui->comboBox_value->addItems(values);
|
||||
ui->comboBox_value->addItems(_values);
|
||||
|
||||
// set current values
|
||||
ui->comboBox_key->setCurrentText(current.first);
|
||||
ui->comboBox_value->setCurrentText(current.second);
|
||||
ui->comboBox_key->setCurrentText(_current.first);
|
||||
ui->comboBox_value->setCurrentText(_current.second);
|
||||
}
|
||||
|
@ -32,11 +32,13 @@ class AWAbstractSelector : public QWidget
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AWAbstractSelector(QWidget *parent = nullptr);
|
||||
explicit AWAbstractSelector(QWidget *_parent = nullptr,
|
||||
const QPair<bool, bool> &_editable
|
||||
= {false, false});
|
||||
virtual ~AWAbstractSelector();
|
||||
QPair<QString, QString> current() const;
|
||||
void init(const QStringList keys, const QStringList values,
|
||||
const QPair<QString, QString> current);
|
||||
void init(const QStringList &_keys, const QStringList &_values,
|
||||
const QPair<QString, QString> &_current);
|
||||
|
||||
signals:
|
||||
void selectionChanged();
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include <KNotifications/KNotification>
|
||||
|
||||
#include <QDesktopServices>
|
||||
#include <QFile>
|
||||
#include <QProcess>
|
||||
#include <QUrl>
|
||||
|
||||
@ -30,8 +31,8 @@
|
||||
#include "awupdatehelper.h"
|
||||
|
||||
|
||||
AWActions::AWActions(QObject *parent)
|
||||
: QObject(parent)
|
||||
AWActions::AWActions(QObject *_parent)
|
||||
: QObject(_parent)
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
|
||||
@ -47,12 +48,29 @@ AWActions::~AWActions()
|
||||
}
|
||||
|
||||
|
||||
void AWActions::checkUpdates(const bool showAnyway)
|
||||
void AWActions::checkUpdates(const bool _showAnyway)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Show anyway" << showAnyway;
|
||||
qCDebug(LOG_AW) << "Show anyway" << _showAnyway;
|
||||
|
||||
if (!m_updateHelper->checkVersion())
|
||||
m_updateHelper->checkUpdates(showAnyway);
|
||||
m_updateHelper->checkUpdates(_showAnyway);
|
||||
}
|
||||
|
||||
|
||||
QString AWActions::getFileContent(const QString &_path) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Get content from file" << _path;
|
||||
|
||||
QFile inputFile(_path);
|
||||
if (!inputFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
qCWarning(LOG_AW) << "Could not open file as text"
|
||||
<< inputFile.fileName();
|
||||
return "";
|
||||
}
|
||||
|
||||
QString output = inputFile.readAll();
|
||||
inputFile.close();
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
@ -63,13 +81,13 @@ bool AWActions::isDebugEnabled() const
|
||||
}
|
||||
|
||||
|
||||
bool AWActions::runCmd(const QString cmd) const
|
||||
bool AWActions::runCmd(const QString &_cmd) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Cmd" << cmd;
|
||||
qCDebug(LOG_AW) << "Cmd" << _cmd;
|
||||
|
||||
sendNotification(QString("Info"), i18n("Run %1", cmd));
|
||||
sendNotification(QString("Info"), i18n("Run %1", _cmd));
|
||||
|
||||
return QProcess::startDetached(cmd);
|
||||
return QProcess::startDetached(_cmd);
|
||||
}
|
||||
|
||||
|
||||
@ -80,102 +98,59 @@ void AWActions::showReadme() const
|
||||
}
|
||||
|
||||
|
||||
// HACK: this method uses variables from version.h
|
||||
QString AWActions::getAboutText(const QString type) const
|
||||
void AWActions::showLegacyInfo() const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Type" << type;
|
||||
QMessageBox *msgBox = new QMessageBox(nullptr);
|
||||
msgBox->setAttribute(Qt::WA_DeleteOnClose);
|
||||
msgBox->setModal(false);
|
||||
msgBox->setWindowTitle(i18n("Not supported"));
|
||||
msgBox->setText(
|
||||
i18n("You are using mammoth's Qt version, try to update it first"));
|
||||
msgBox->setStandardButtons(QMessageBox::Ok);
|
||||
msgBox->setIcon(QMessageBox::Information);
|
||||
|
||||
QString text;
|
||||
if (type == QString("header")) {
|
||||
text = QString(NAME);
|
||||
} else if (type == QString("version")) {
|
||||
text = i18n("Version %1 (build date %2)", QString(VERSION),
|
||||
QString(BUILD_DATE));
|
||||
if (!QString(COMMIT_SHA).isEmpty())
|
||||
text += QString(" (%1)").arg(QString(COMMIT_SHA));
|
||||
} else if (type == QString("description")) {
|
||||
text = i18n("A set of minimalistic plasmoid widgets");
|
||||
} else if (type == QString("links")) {
|
||||
text = i18n("Links:") + QString("<br>")
|
||||
+ QString("<a href=\"%1\">%2</a><br>")
|
||||
.arg(QString(HOMEPAGE))
|
||||
.arg(i18n("Homepage"))
|
||||
+ QString("<a href=\"%1\">%2</a><br>")
|
||||
.arg(QString(REPOSITORY))
|
||||
.arg(i18n("Repository"))
|
||||
+ QString("<a href=\"%1\">%2</a><br>")
|
||||
.arg(QString(BUGTRACKER))
|
||||
.arg(i18n("Bugtracker"))
|
||||
+ QString("<a href=\"%1\">%2</a><br>")
|
||||
.arg(QString(TRANSLATION))
|
||||
.arg(i18n("Translation issue"))
|
||||
+ QString("<a href=\"%1\">%2</a><br>")
|
||||
.arg(QString(AUR_PACKAGES))
|
||||
.arg(i18n("AUR packages"))
|
||||
+ QString("<a href=\"%1\">%2</a>")
|
||||
.arg(QString(OPENSUSE_PACKAGES))
|
||||
.arg(i18n("openSUSE packages"));
|
||||
} else if (type == QString("copy")) {
|
||||
text = QString("<small>© %1 <a href=\"mailto:%2\">%3</a><br>")
|
||||
.arg(QString(DATE))
|
||||
.arg(QString(EMAIL))
|
||||
.arg(QString(AUTHOR))
|
||||
+ i18n("This software is licensed under %1", QString(LICENSE))
|
||||
+ QString("</small>");
|
||||
} else if (type == QString("translators")) {
|
||||
text = i18n("Translators: %1", QString(TRANSLATORS));
|
||||
} else if (type == QString("3rdparty")) {
|
||||
QStringList trdPartyList
|
||||
= QString(TRDPARTY_LICENSE)
|
||||
.split(QChar(';'), QString::SkipEmptyParts);
|
||||
for (int i = 0; i < trdPartyList.count(); i++)
|
||||
trdPartyList[i] = QString("<a href=\"%3\">%1</a> (%2 license)")
|
||||
.arg(trdPartyList.at(i).split(QChar(','))[0])
|
||||
.arg(trdPartyList.at(i).split(QChar(','))[1])
|
||||
.arg(trdPartyList.at(i).split(QChar(','))[2]);
|
||||
text = i18n("This software uses: %1", trdPartyList.join(QString(", ")));
|
||||
} else if (type == QString("thanks")) {
|
||||
QStringList thanks = QString(SPECIAL_THANKS)
|
||||
.split(QChar(';'), QString::SkipEmptyParts);
|
||||
for (int i = 0; i < thanks.count(); i++)
|
||||
thanks[i] = QString("<a href=\"%2\">%1</a>")
|
||||
.arg(thanks.at(i).split(QChar(','))[0])
|
||||
.arg(thanks.at(i).split(QChar(','))[1]);
|
||||
text = i18n("Special thanks to %1", thanks.join(QString(", ")));
|
||||
}
|
||||
|
||||
return text;
|
||||
msgBox->open();
|
||||
}
|
||||
|
||||
|
||||
QVariantMap AWActions::getFont(const QVariantMap defaultFont) const
|
||||
// HACK: this method uses variables from version.h
|
||||
QString AWActions::getAboutText(const QString &_type) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Default font is" << defaultFont;
|
||||
qCDebug(LOG_AW) << "Type" << _type;
|
||||
|
||||
return AWDebug::getAboutText(_type);
|
||||
}
|
||||
|
||||
|
||||
QVariantMap AWActions::getFont(const QVariantMap &_defaultFont) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Default font is" << _defaultFont;
|
||||
|
||||
QVariantMap fontMap;
|
||||
int ret = 0;
|
||||
CFont defaultCFont = CFont(defaultFont[QString("family")].toString(),
|
||||
defaultFont[QString("size")].toInt(), 400, false,
|
||||
defaultFont[QString("color")].toString());
|
||||
CFont defaultCFont
|
||||
= CFont(_defaultFont["family"].toString(), _defaultFont["size"].toInt(),
|
||||
400, false, _defaultFont["color"].toString());
|
||||
CFont font = CFontDialog::getFont(i18n("Select font"), defaultCFont, false,
|
||||
false, &ret);
|
||||
|
||||
fontMap[QString("applied")] = ret;
|
||||
fontMap[QString("color")] = font.color().name();
|
||||
fontMap[QString("family")] = font.family();
|
||||
fontMap[QString("size")] = font.pointSize();
|
||||
fontMap["applied"] = ret;
|
||||
fontMap["color"] = font.color().name();
|
||||
fontMap["family"] = font.family();
|
||||
fontMap["size"] = font.pointSize();
|
||||
|
||||
return fontMap;
|
||||
}
|
||||
|
||||
|
||||
// to avoid additional object definition this method is static
|
||||
void AWActions::sendNotification(const QString eventId, const QString message)
|
||||
void AWActions::sendNotification(const QString &_eventId,
|
||||
const QString &_message)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Event" << eventId << "with message" << message;
|
||||
qCDebug(LOG_AW) << "Event" << _eventId << "with message" << _message;
|
||||
|
||||
KNotification *notification = KNotification::event(
|
||||
eventId, QString("Awesome Widget ::: %1").arg(eventId), message);
|
||||
_eventId, QString("Awesome Widget ::: %1").arg(_eventId), _message);
|
||||
notification->setComponentName(
|
||||
QString("plasma-applet-org.kde.plasma.awesome-widget"));
|
||||
"plasma-applet-org.kde.plasma.awesome-widget");
|
||||
}
|
||||
|
@ -30,20 +30,21 @@ class AWActions : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AWActions(QObject *parent = nullptr);
|
||||
explicit AWActions(QObject *_parent = nullptr);
|
||||
virtual ~AWActions();
|
||||
Q_INVOKABLE void checkUpdates(const bool showAnyway = false);
|
||||
Q_INVOKABLE void checkUpdates(const bool _showAnyway = false);
|
||||
Q_INVOKABLE QString getFileContent(const QString &_path) const;
|
||||
Q_INVOKABLE bool isDebugEnabled() const;
|
||||
Q_INVOKABLE bool runCmd(const QString cmd = QString("/usr/bin/true")) const;
|
||||
Q_INVOKABLE bool runCmd(const QString &_cmd) const;
|
||||
Q_INVOKABLE void showLegacyInfo() const;
|
||||
Q_INVOKABLE void showReadme() const;
|
||||
// configuration slots
|
||||
Q_INVOKABLE QString getAboutText(const QString type
|
||||
= QString("header")) const;
|
||||
Q_INVOKABLE QVariantMap getFont(const QVariantMap defaultFont) const;
|
||||
Q_INVOKABLE QString getAboutText(const QString &_type) const;
|
||||
Q_INVOKABLE QVariantMap getFont(const QVariantMap &_defaultFont) const;
|
||||
|
||||
public slots:
|
||||
Q_INVOKABLE static void sendNotification(const QString eventId,
|
||||
const QString message);
|
||||
Q_INVOKABLE static void sendNotification(const QString &_eventId,
|
||||
const QString &_message);
|
||||
|
||||
private:
|
||||
AWUpdateHelper *m_updateHelper = nullptr;
|
||||
|
163
sources/awesome-widget/plugin/awbugreporter.cpp
Normal file
163
sources/awesome-widget/plugin/awbugreporter.cpp
Normal file
@ -0,0 +1,163 @@
|
||||
/***************************************************************************
|
||||
* 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 "awbugreporter.h"
|
||||
|
||||
#include <KI18n/KLocalizedString>
|
||||
|
||||
#include <QDesktopServices>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonParseError>
|
||||
#include <QMessageBox>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
#include <QNetworkRequest>
|
||||
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
AWBugReporter::AWBugReporter(QObject *_parent)
|
||||
: QObject(_parent)
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
}
|
||||
|
||||
|
||||
AWBugReporter::~AWBugReporter()
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
}
|
||||
|
||||
|
||||
void AWBugReporter::doConnect()
|
||||
{
|
||||
// additional method for testing needs
|
||||
connect(this, SIGNAL(replyReceived(const int, const QString &)), this,
|
||||
SLOT(showInformation(const int, const QString &)));
|
||||
}
|
||||
|
||||
|
||||
QString AWBugReporter::generateText(const QString &_description,
|
||||
const QString &_reproduce,
|
||||
const QString &_expected,
|
||||
const QString &_logs) const
|
||||
{
|
||||
// do not log _logs here, it may have quite large size
|
||||
qCDebug(LOG_AW) << "Generate text with description" << _description
|
||||
<< "steps" << _reproduce << "and expected result"
|
||||
<< _expected;
|
||||
|
||||
QString output;
|
||||
output += QString("**Description**\n\n%1\n\n").arg(_description);
|
||||
output += QString("**Step to _reproduce**\n\n%1\n\n").arg(_reproduce);
|
||||
output += QString("**Expected result**\n\n%1\n\n").arg(_expected);
|
||||
output += QString("**Version**\n\n%1\n\n")
|
||||
.arg(AWDebug::getBuildData().join(QString("\n")));
|
||||
// append _logs
|
||||
output += QString("**Logs**\n\n%1").arg(_logs);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
void AWBugReporter::sendBugReport(const QString &_title, const QString &_body)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Send bug report with title" << _title << "and body"
|
||||
<< _body;
|
||||
|
||||
QNetworkAccessManager *manager = new QNetworkAccessManager(nullptr);
|
||||
connect(manager, SIGNAL(finished(QNetworkReply *)), this,
|
||||
SLOT(issueReplyRecieved(QNetworkReply *)));
|
||||
|
||||
QNetworkRequest request = QNetworkRequest(QUrl(BUGTRACKER_API));
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||
|
||||
// generate payload
|
||||
QVariantMap payload;
|
||||
payload["title"] = _title;
|
||||
payload["body"] = _body;
|
||||
payload["labels"] = QStringList() << "from application";
|
||||
// convert to QByteArray to send request
|
||||
QByteArray data
|
||||
= QJsonDocument::fromVariant(payload).toJson(QJsonDocument::Compact);
|
||||
qCInfo(LOG_AW) << "Send request with _body" << data.data() << "and size"
|
||||
<< data.size();
|
||||
|
||||
manager->post(request, data);
|
||||
}
|
||||
|
||||
|
||||
void AWBugReporter::issueReplyRecieved(QNetworkReply *_reply)
|
||||
{
|
||||
if (_reply->error() != QNetworkReply::NoError) {
|
||||
qCWarning(LOG_AW) << "An error occurs" << _reply->error()
|
||||
<< "with message" << _reply->errorString();
|
||||
return emit(replyReceived(0, ""));
|
||||
}
|
||||
|
||||
QJsonParseError error;
|
||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(_reply->readAll(), &error);
|
||||
if (error.error != QJsonParseError::NoError) {
|
||||
qCWarning(LOG_AW) << "Parse error" << error.errorString();
|
||||
return emit(replyReceived(0, ""));
|
||||
}
|
||||
_reply->deleteLater();
|
||||
|
||||
// convert to map
|
||||
QVariantMap response = jsonDoc.toVariant().toMap();
|
||||
QString url = response["html_url"].toString();
|
||||
int number = response["number"].toInt();
|
||||
|
||||
return emit(replyReceived(number, url));
|
||||
}
|
||||
|
||||
|
||||
void AWBugReporter::showInformation(const int _number, const QString &_url)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Created issue with number" << _number << "and url"
|
||||
<< _url;
|
||||
|
||||
// cache url first
|
||||
m_lastBugUrl = _url;
|
||||
|
||||
QMessageBox *msgBox = new QMessageBox(nullptr);
|
||||
msgBox->setAttribute(Qt::WA_DeleteOnClose);
|
||||
msgBox->setModal(false);
|
||||
msgBox->setWindowTitle(i18n("Issue created"));
|
||||
msgBox->setText(i18n("Issue %1 has been created", _number));
|
||||
msgBox->setStandardButtons(QMessageBox::Open | QMessageBox::Close);
|
||||
msgBox->setIcon(QMessageBox::Information);
|
||||
|
||||
msgBox->open(this, SLOT(userReplyOnBugReport(QAbstractButton *)));
|
||||
}
|
||||
|
||||
|
||||
void AWBugReporter::userReplyOnBugReport(QAbstractButton *_button)
|
||||
{
|
||||
QMessageBox::ButtonRole ret
|
||||
= static_cast<QMessageBox *>(sender())->buttonRole(_button);
|
||||
qCInfo(LOG_AW) << "User select" << ret;
|
||||
|
||||
switch (ret) {
|
||||
case QMessageBox::AcceptRole:
|
||||
QDesktopServices::openUrl(m_lastBugUrl);
|
||||
break;
|
||||
case QMessageBox::RejectRole:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
55
sources/awesome-widget/plugin/awbugreporter.h
Normal file
55
sources/awesome-widget/plugin/awbugreporter.h
Normal file
@ -0,0 +1,55 @@
|
||||
/***************************************************************************
|
||||
* 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 AWBUGREPORTER_H
|
||||
#define AWBUGREPORTER_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
|
||||
class QAbstractButton;
|
||||
class QNetworkReply;
|
||||
|
||||
class AWBugReporter : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AWBugReporter(QObject *_parent = nullptr);
|
||||
virtual ~AWBugReporter();
|
||||
Q_INVOKABLE void doConnect();
|
||||
Q_INVOKABLE QString generateText(const QString &_description,
|
||||
const QString &_reproduce,
|
||||
const QString &_expected,
|
||||
const QString &_logs) const;
|
||||
Q_INVOKABLE void sendBugReport(const QString &_title, const QString &_body);
|
||||
|
||||
signals:
|
||||
void replyReceived(const int _number, const QString &_url);
|
||||
|
||||
private slots:
|
||||
void issueReplyRecieved(QNetworkReply *_reply);
|
||||
void showInformation(const int _number, const QString &_url);
|
||||
void userReplyOnBugReport(QAbstractButton *_button);
|
||||
|
||||
private:
|
||||
QString m_lastBugUrl;
|
||||
};
|
||||
|
||||
|
||||
#endif /* AWBUGREPORTER_H */
|
@ -27,8 +27,8 @@
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
AWConfigHelper::AWConfigHelper(QObject *parent)
|
||||
: QObject(parent)
|
||||
AWConfigHelper::AWConfigHelper(QObject *_parent)
|
||||
: QObject(_parent)
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
}
|
||||
@ -69,18 +69,17 @@ bool AWConfigHelper::dropCache() const
|
||||
}
|
||||
|
||||
|
||||
bool AWConfigHelper::exportConfiguration(const QObject *nativeConfig,
|
||||
const QString fileName) const
|
||||
bool AWConfigHelper::exportConfiguration(QObject *_nativeConfig,
|
||||
const QString &_fileName) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Selected filename" << fileName;
|
||||
|
||||
QSettings settings(fileName, QSettings::IniFormat);
|
||||
qCDebug(LOG_AW) << "Selected filename" << _fileName;
|
||||
|
||||
QSettings settings(_fileName, QSettings::IniFormat);
|
||||
// plasmoid configuration
|
||||
const QQmlPropertyMap *configuration
|
||||
= static_cast<const QQmlPropertyMap *>(nativeConfig);
|
||||
settings.beginGroup(QString("plasmoid"));
|
||||
for (auto key : configuration->keys()) {
|
||||
= static_cast<const QQmlPropertyMap *>(_nativeConfig);
|
||||
settings.beginGroup("plasmoid");
|
||||
for (auto &key : configuration->keys()) {
|
||||
QVariant value = configuration->value(key);
|
||||
if (!value.isValid())
|
||||
continue;
|
||||
@ -89,29 +88,28 @@ bool AWConfigHelper::exportConfiguration(const QObject *nativeConfig,
|
||||
settings.endGroup();
|
||||
|
||||
// extensions
|
||||
for (auto item : m_dirs) {
|
||||
for (auto &item : m_dirs) {
|
||||
QStringList items
|
||||
= QDir(QString("%1/%2").arg(m_baseDir).arg(item))
|
||||
.entryList(QStringList() << QString("*.desktop"),
|
||||
QDir::Files);
|
||||
.entryList(QStringList() << "*.desktop", QDir::Files);
|
||||
settings.beginGroup(item);
|
||||
for (auto it : items)
|
||||
for (auto &it : items)
|
||||
copyExtensions(it, item, settings, false);
|
||||
settings.endGroup();
|
||||
}
|
||||
|
||||
// additional files
|
||||
settings.beginGroup(QString("json"));
|
||||
settings.beginGroup("json");
|
||||
// script filters
|
||||
readFile(settings, QString("filters"),
|
||||
readFile(settings, "filters",
|
||||
QString("%1/scripts/awesomewidgets-extscripts-filters.json")
|
||||
.arg(m_baseDir));
|
||||
// weather icon settings
|
||||
readFile(settings, QString("weathers"),
|
||||
readFile(settings, "weathers",
|
||||
QString("%1/weather/awesomewidgets-extweather-ids.json")
|
||||
.arg(m_baseDir));
|
||||
// formatter settings
|
||||
readFile(settings, QString("formatters"),
|
||||
readFile(settings, "formatters",
|
||||
QString("%1/formatters/formatters.ini").arg(m_baseDir));
|
||||
settings.endGroup();
|
||||
|
||||
@ -122,47 +120,47 @@ bool AWConfigHelper::exportConfiguration(const QObject *nativeConfig,
|
||||
}
|
||||
|
||||
|
||||
QVariantMap AWConfigHelper::importConfiguration(const QString fileName,
|
||||
const bool importPlasmoid,
|
||||
const bool importExtensions,
|
||||
const bool importAdds) const
|
||||
QVariantMap AWConfigHelper::importConfiguration(const QString &_fileName,
|
||||
const bool _importPlasmoid,
|
||||
const bool _importExtensions,
|
||||
const bool _importAdds) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Selected filename" << fileName;
|
||||
qCDebug(LOG_AW) << "Selected filename" << _fileName;
|
||||
|
||||
QVariantMap configuration;
|
||||
QSettings settings(fileName, QSettings::IniFormat);
|
||||
QSettings settings(_fileName, QSettings::IniFormat);
|
||||
|
||||
// extensions
|
||||
if (importExtensions) {
|
||||
for (auto item : m_dirs) {
|
||||
if (_importExtensions) {
|
||||
for (auto &item : m_dirs) {
|
||||
settings.beginGroup(item);
|
||||
for (auto it : settings.childGroups())
|
||||
for (auto &it : settings.childGroups())
|
||||
copyExtensions(it, item, settings, true);
|
||||
settings.endGroup();
|
||||
}
|
||||
}
|
||||
|
||||
// additional files
|
||||
if (importAdds) {
|
||||
settings.beginGroup(QString("json"));
|
||||
if (_importAdds) {
|
||||
settings.beginGroup("json");
|
||||
// script filters
|
||||
writeFile(settings, QString("filters"),
|
||||
writeFile(settings, "filters",
|
||||
QString("%1/scripts/awesomewidgets-extscripts-filters.json")
|
||||
.arg(m_baseDir));
|
||||
// weather icon settings
|
||||
writeFile(settings, QString("weathers"),
|
||||
writeFile(settings, "weathers",
|
||||
QString("%1/weather/awesomewidgets-extweather-ids.json")
|
||||
.arg(m_baseDir));
|
||||
// formatter settings
|
||||
writeFile(settings, QString("formatters"),
|
||||
writeFile(settings, "formatters",
|
||||
QString("%1/formatters/formatters.ini").arg(m_baseDir));
|
||||
settings.endGroup();
|
||||
}
|
||||
|
||||
// plasmoid configuration
|
||||
if (importPlasmoid) {
|
||||
settings.beginGroup(QString("plasmoid"));
|
||||
for (auto key : settings.childKeys())
|
||||
if (_importPlasmoid) {
|
||||
settings.beginGroup("plasmoid");
|
||||
for (auto &key : settings.childKeys())
|
||||
configuration[key] = settings.value(key);
|
||||
settings.endGroup();
|
||||
}
|
||||
@ -173,32 +171,24 @@ QVariantMap AWConfigHelper::importConfiguration(const QString fileName,
|
||||
|
||||
QVariantMap AWConfigHelper::readDataEngineConfiguration() const
|
||||
{
|
||||
QString fileName
|
||||
= QStandardPaths::locate(QStandardPaths::ConfigLocation,
|
||||
QString("plasma-dataengine-extsysmon.conf"));
|
||||
QString fileName = QStandardPaths::locate(
|
||||
QStandardPaths::ConfigLocation, "plasma-dataengine-extsysmon.conf");
|
||||
qCInfo(LOG_AW) << "Configuration file" << fileName;
|
||||
QSettings settings(fileName, QSettings::IniFormat);
|
||||
QVariantMap configuration;
|
||||
|
||||
settings.beginGroup(QString("Configuration"));
|
||||
configuration[QString("ACPIPATH")] = settings.value(
|
||||
QString("ACPIPATH"), QString("/sys/class/power_supply/"));
|
||||
configuration[QString("GPUDEV")]
|
||||
= settings.value(QString("GPUDEV"), QString("auto"));
|
||||
configuration[QString("HDDDEV")]
|
||||
= settings.value(QString("HDDDEV"), QString("all"));
|
||||
configuration[QString("HDDTEMPCMD")]
|
||||
= settings.value(QString("HDDTEMPCMD"), QString("sudo smartctl -a"));
|
||||
configuration[QString("MPDADDRESS")]
|
||||
= settings.value(QString("MPDADDRESS"), QString("localhost"));
|
||||
configuration[QString("MPDPORT")]
|
||||
= settings.value(QString("MPDPORT"), QString("6600"));
|
||||
configuration[QString("MPRIS")]
|
||||
= settings.value(QString("MPRIS"), QString("auto"));
|
||||
configuration[QString("PLAYER")]
|
||||
= settings.value(QString("PLAYER"), QString("mpris"));
|
||||
configuration[QString("PLAYERSYMBOLS")]
|
||||
= settings.value(QString("PLAYERSYMBOLS"), QString("10"));
|
||||
settings.beginGroup("Configuration");
|
||||
configuration["ACPIPATH"]
|
||||
= settings.value("ACPIPATH", "/sys/class/power_supply/");
|
||||
configuration["GPUDEV"] = settings.value("GPUDEV", "auto");
|
||||
configuration["HDDDEV"] = settings.value("HDDDEV", "all");
|
||||
configuration["HDDTEMPCMD"]
|
||||
= settings.value("HDDTEMPCMD", "sudo smartctl -a");
|
||||
configuration["MPDADDRESS"] = settings.value("MPDADDRESS", "localhost");
|
||||
configuration["MPDPORT"] = settings.value("MPDPORT", "6600");
|
||||
configuration["MPRIS"] = settings.value("MPRIS", "auto");
|
||||
configuration["PLAYER"] = settings.value("PLAYER", "mpris");
|
||||
configuration["PLAYERSYMBOLS"] = settings.value("PLAYERSYMBOLS", "10");
|
||||
settings.endGroup();
|
||||
|
||||
qCInfo(LOG_AW) << "Configuration" << configuration;
|
||||
@ -208,29 +198,26 @@ QVariantMap AWConfigHelper::readDataEngineConfiguration() const
|
||||
|
||||
|
||||
bool AWConfigHelper::writeDataEngineConfiguration(
|
||||
const QVariantMap configuration) const
|
||||
const QVariantMap &_configuration) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Configuration" << configuration;
|
||||
qCDebug(LOG_AW) << "Configuration" << _configuration;
|
||||
|
||||
QString fileName
|
||||
= QStandardPaths::writableLocation(QStandardPaths::ConfigLocation)
|
||||
+ QString("/plasma-dataengine-extsysmon.conf");
|
||||
QString fileName = QString("%1/plasma-dataengine-extsysmon.conf")
|
||||
.arg(QStandardPaths::writableLocation(
|
||||
QStandardPaths::ConfigLocation));
|
||||
QSettings settings(fileName, QSettings::IniFormat);
|
||||
qCInfo(LOG_AW) << "Configuration file" << settings.fileName();
|
||||
|
||||
settings.beginGroup(QString("Configuration"));
|
||||
settings.setValue(QString("ACPIPATH"), configuration[QString("ACPIPATH")]);
|
||||
settings.setValue(QString("GPUDEV"), configuration[QString("GPUDEV")]);
|
||||
settings.setValue(QString("HDDDEV"), configuration[QString("HDDDEV")]);
|
||||
settings.setValue(QString("HDDTEMPCMD"),
|
||||
configuration[QString("HDDTEMPCMD")]);
|
||||
settings.setValue(QString("MPDADDRESS"),
|
||||
configuration[QString("MPDADDRESS")]);
|
||||
settings.setValue(QString("MPDPORT"), configuration[QString("MPDPORT")]);
|
||||
settings.setValue(QString("MPRIS"), configuration[QString("MPRIS")]);
|
||||
settings.setValue(QString("PLAYER"), configuration[QString("PLAYER")]);
|
||||
settings.setValue(QString("PLAYERSYMBOLS"),
|
||||
configuration[QString("PLAYERSYMBOLS")]);
|
||||
settings.beginGroup("Configuration");
|
||||
settings.setValue("ACPIPATH", _configuration["ACPIPATH"]);
|
||||
settings.setValue("GPUDEV", _configuration["GPUDEV"]);
|
||||
settings.setValue("HDDDEV", _configuration["HDDDEV"]);
|
||||
settings.setValue("HDDTEMPCMD", _configuration["HDDTEMPCMD"]);
|
||||
settings.setValue("MPDADDRESS", _configuration["MPDADDRESS"]);
|
||||
settings.setValue("MPDPORT", _configuration["MPDPORT"]);
|
||||
settings.setValue("MPRIS", _configuration["MPRIS"]);
|
||||
settings.setValue("PLAYER", _configuration["PLAYER"]);
|
||||
settings.setValue("PLAYERSYMBOLS", _configuration["PLAYERSYMBOLS"]);
|
||||
settings.endGroup();
|
||||
|
||||
settings.sync();
|
||||
@ -239,19 +226,19 @@ bool AWConfigHelper::writeDataEngineConfiguration(
|
||||
}
|
||||
|
||||
|
||||
void AWConfigHelper::copyConfigs(const QString localDir) const
|
||||
void AWConfigHelper::copyConfigs(const QString &_localDir) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Local directory" << localDir;
|
||||
qCDebug(LOG_AW) << "Local directory" << _localDir;
|
||||
|
||||
QStringList dirs = QStandardPaths::locateAll(
|
||||
QStandardPaths::GenericDataLocation, QString("awesomewidgets/configs"),
|
||||
QStandardPaths::GenericDataLocation, "awesomewidgets/configs",
|
||||
QStandardPaths::LocateDirectory);
|
||||
for (auto dir : dirs) {
|
||||
if (dir == localDir)
|
||||
for (auto &dir : dirs) {
|
||||
if (dir == _localDir)
|
||||
continue;
|
||||
QStringList files = QDir(dir).entryList(QDir::Files);
|
||||
for (auto source : files) {
|
||||
QString destination = QString("%1/%2").arg(localDir).arg(source);
|
||||
for (auto &source : files) {
|
||||
QString destination = QString("%1/%2").arg(_localDir).arg(source);
|
||||
bool status = QFile::copy(QString("%1/%2").arg(dir).arg(source),
|
||||
destination);
|
||||
qCInfo(LOG_AW) << "File" << source << "has been copied to"
|
||||
@ -261,66 +248,66 @@ void AWConfigHelper::copyConfigs(const QString localDir) const
|
||||
}
|
||||
|
||||
|
||||
void AWConfigHelper::copyExtensions(const QString item, const QString type,
|
||||
QSettings &settings,
|
||||
const bool inverse) const
|
||||
void AWConfigHelper::copyExtensions(const QString &_item, const QString &_type,
|
||||
QSettings &_settings,
|
||||
const bool _inverse) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Extension" << item << "has type" << type
|
||||
<< "inverse copying" << inverse;
|
||||
qCDebug(LOG_AW) << "Extension" << _item << "has type" << _type
|
||||
<< "inverse copying" << _inverse;
|
||||
|
||||
settings.beginGroup(item);
|
||||
_settings.beginGroup(_item);
|
||||
QSettings itemSettings(
|
||||
QString("%1/%2/%3").arg(m_baseDir).arg(type).arg(item),
|
||||
QString("%1/%2/%3").arg(m_baseDir).arg(_type).arg(_item),
|
||||
QSettings::IniFormat);
|
||||
itemSettings.beginGroup(QString("Desktop Entry"));
|
||||
if (inverse)
|
||||
copySettings(settings, itemSettings);
|
||||
itemSettings.beginGroup("Desktop Entry");
|
||||
if (_inverse)
|
||||
copySettings(_settings, itemSettings);
|
||||
else
|
||||
copySettings(itemSettings, settings);
|
||||
copySettings(itemSettings, _settings);
|
||||
itemSettings.endGroup();
|
||||
settings.endGroup();
|
||||
_settings.endGroup();
|
||||
|
||||
if (inverse)
|
||||
if (_inverse)
|
||||
itemSettings.sync();
|
||||
}
|
||||
|
||||
|
||||
void AWConfigHelper::copySettings(QSettings &from, QSettings &to) const
|
||||
void AWConfigHelper::copySettings(QSettings &_from, QSettings &_to) const
|
||||
{
|
||||
for (auto key : from.childKeys())
|
||||
to.setValue(key, from.value(key));
|
||||
for (auto &key : _from.childKeys())
|
||||
_to.setValue(key, _from.value(key));
|
||||
}
|
||||
|
||||
|
||||
void AWConfigHelper::readFile(QSettings &settings, const QString key,
|
||||
const QString fileName) const
|
||||
void AWConfigHelper::readFile(QSettings &_settings, const QString &_key,
|
||||
const QString &_fileName) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Key" << key << "from file" << fileName;
|
||||
qCDebug(LOG_AW) << "Key" << _key << "from file" << _fileName;
|
||||
|
||||
QFile file(fileName);
|
||||
QFile file(_fileName);
|
||||
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
QString text = QString::fromUtf8(file.readAll());
|
||||
file.close();
|
||||
settings.setValue(key, text);
|
||||
_settings.setValue(_key, text);
|
||||
} else {
|
||||
qCWarning(LOG_AW) << "Could not open" << file.fileName();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AWConfigHelper::writeFile(QSettings &settings, const QString key,
|
||||
const QString fileName) const
|
||||
void AWConfigHelper::writeFile(QSettings &_settings, const QString &_key,
|
||||
const QString &_fileName) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Key" << key << "to file" << fileName;
|
||||
qCDebug(LOG_AW) << "Key" << _key << "to file" << _fileName;
|
||||
|
||||
if (!settings.contains(key))
|
||||
if (!_settings.contains(_key))
|
||||
return;
|
||||
|
||||
QFile file(fileName);
|
||||
QFile file(_fileName);
|
||||
if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||
QTextStream out(&file);
|
||||
out.setCodec("UTF-8");
|
||||
out << settings.value(key).toString().toUtf8();
|
||||
out << _settings.value(_key).toString().toUtf8();
|
||||
out.flush();
|
||||
file.close();
|
||||
} else {
|
||||
|
@ -31,39 +31,41 @@ class AWConfigHelper : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AWConfigHelper(QObject *parent = nullptr);
|
||||
explicit AWConfigHelper(QObject *_parent = nullptr);
|
||||
virtual ~AWConfigHelper();
|
||||
Q_INVOKABLE QString configurationDirectory() const;
|
||||
Q_INVOKABLE bool dropCache() const;
|
||||
Q_INVOKABLE bool exportConfiguration(const QObject *nativeConfig,
|
||||
const QString fileName) const;
|
||||
Q_INVOKABLE QVariantMap importConfiguration(const QString fileName,
|
||||
const bool importPlasmoid,
|
||||
const bool importExtensions,
|
||||
const bool importAdds) const;
|
||||
Q_INVOKABLE bool exportConfiguration(QObject *_nativeConfig,
|
||||
const QString &_fileName) const;
|
||||
Q_INVOKABLE QVariantMap importConfiguration(const QString &_fileName,
|
||||
const bool _importPlasmoid,
|
||||
const bool _importExtensions,
|
||||
const bool _importAdds) const;
|
||||
// dataengine
|
||||
Q_INVOKABLE QVariantMap readDataEngineConfiguration() const;
|
||||
Q_INVOKABLE bool
|
||||
writeDataEngineConfiguration(const QVariantMap configuration) const;
|
||||
writeDataEngineConfiguration(const QVariantMap &_configuration) const;
|
||||
|
||||
private:
|
||||
// methods
|
||||
void copyConfigs(const QString localDir) const;
|
||||
void copyExtensions(const QString item, const QString type,
|
||||
QSettings &settings, const bool inverse) const;
|
||||
void copySettings(QSettings &from, QSettings &to) const;
|
||||
void readFile(QSettings &settings, const QString key,
|
||||
const QString fileName) const;
|
||||
void writeFile(QSettings &settings, const QString key,
|
||||
const QString fileName) const;
|
||||
void copyConfigs(const QString &_localDir) const;
|
||||
void copyExtensions(const QString &_item, const QString &_type,
|
||||
QSettings &_settings, const bool _inverse) const;
|
||||
void copySettings(QSettings &_from, QSettings &_to) const;
|
||||
void readFile(QSettings &_settings, const QString &_key,
|
||||
const QString &_fileName) const;
|
||||
void writeFile(QSettings &_settings, const QString &_key,
|
||||
const QString &_fileName) const;
|
||||
// properties
|
||||
QString m_baseDir = QString("%1/awesomewidgets")
|
||||
.arg(QStandardPaths::writableLocation(
|
||||
QStandardPaths::GenericDataLocation));
|
||||
QStringList m_dirs = QStringList()
|
||||
<< QString("desktops") << QString("quotes")
|
||||
<< QString("scripts") << QString("upgrade")
|
||||
<< QString("weather") << QString("formatters");
|
||||
QStringList m_dirs = QStringList() << "desktops"
|
||||
<< "quotes"
|
||||
<< "scripts"
|
||||
<< "upgrade"
|
||||
<< "weather"
|
||||
<< "formatters";
|
||||
};
|
||||
|
||||
|
||||
|
@ -23,7 +23,6 @@
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsView>
|
||||
#include <QPixmap>
|
||||
#include <QtConcurrent/QtConcurrent>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
@ -31,18 +30,18 @@
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
AWDataAggregator::AWDataAggregator(QObject *parent)
|
||||
: QObject(parent)
|
||||
AWDataAggregator::AWDataAggregator(QObject *_parent)
|
||||
: QObject(_parent)
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
|
||||
m_boundaries[QString("cpuTooltip")] = 100.0;
|
||||
m_boundaries[QString("cpuclTooltip")] = 4000.0;
|
||||
m_boundaries[QString("memTooltip")] = 100.0;
|
||||
m_boundaries[QString("swapTooltip")] = 100.0;
|
||||
m_boundaries[QString("downkbTooltip")] = 1.0;
|
||||
m_boundaries[QString("upkbTooltip")] = 1.0;
|
||||
m_boundaries[QString("batTooltip")] = 100.0;
|
||||
m_boundaries["cpuTooltip"] = 100.0;
|
||||
m_boundaries["cpuclTooltip"] = 4000.0;
|
||||
m_boundaries["memTooltip"] = 100.0;
|
||||
m_boundaries["swapTooltip"] = 100.0;
|
||||
m_boundaries["downkbTooltip"] = 1.0;
|
||||
m_boundaries["upkbTooltip"] = 1.0;
|
||||
m_boundaries["batTooltip"] = 100.0;
|
||||
|
||||
initScene();
|
||||
connect(this, SIGNAL(updateData(const QVariantHash &)), this,
|
||||
@ -58,67 +57,66 @@ AWDataAggregator::~AWDataAggregator()
|
||||
}
|
||||
|
||||
|
||||
QList<float> AWDataAggregator::getData(const QString key) const
|
||||
QList<float> AWDataAggregator::getData(const QString &_key) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Key" << key;
|
||||
qCDebug(LOG_AW) << "Key" << _key;
|
||||
|
||||
return m_values[QString("%1Tooltip").arg(key)];
|
||||
return m_values[QString("%1Tooltip").arg(_key)];
|
||||
}
|
||||
|
||||
|
||||
QString AWDataAggregator::htmlImage(const QPixmap &source) const
|
||||
QString AWDataAggregator::htmlImage(const QPixmap &_source) const
|
||||
{
|
||||
QByteArray byteArray;
|
||||
QBuffer buffer(&byteArray);
|
||||
source.save(&buffer, "PNG");
|
||||
_source.save(&buffer, "PNG");
|
||||
|
||||
return byteArray.isEmpty()
|
||||
? QString()
|
||||
? ""
|
||||
: QString("<img src=\"data:image/png;base64,%1\"/>")
|
||||
.arg(QString(byteArray.toBase64()));
|
||||
}
|
||||
|
||||
|
||||
void AWDataAggregator::setParameters(QVariantMap settings)
|
||||
void AWDataAggregator::setParameters(const QVariantMap &_settings)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Settings" << settings;
|
||||
qCDebug(LOG_AW) << "Settings" << _settings;
|
||||
|
||||
// cast from QVariantMap to QVariantHash without data lost
|
||||
m_configuration = qvariant_cast<QVariantHash>(settings);
|
||||
m_configuration = qvariant_cast<QVariantHash>(_settings);
|
||||
|
||||
m_enablePopup = m_configuration[QString("notify")].toBool();
|
||||
m_enablePopup = m_configuration["notify"].toBool();
|
||||
|
||||
m_counts = 0;
|
||||
m_counts += m_configuration[QString("cpuTooltip")].toInt();
|
||||
m_counts += m_configuration[QString("cpuclTooltip")].toInt();
|
||||
m_counts += m_configuration[QString("memTooltip")].toInt();
|
||||
m_counts += m_configuration[QString("swapTooltip")].toInt();
|
||||
m_counts += m_configuration[QString("downkbTooltip")].toInt();
|
||||
m_counts += m_configuration[QString("batTooltip")].toInt();
|
||||
m_counts += m_configuration["cpuTooltip"].toInt();
|
||||
m_counts += m_configuration["cpuclTooltip"].toInt();
|
||||
m_counts += m_configuration["memTooltip"].toInt();
|
||||
m_counts += m_configuration["swapTooltip"].toInt();
|
||||
m_counts += m_configuration["downkbTooltip"].toInt();
|
||||
m_counts += m_configuration["batTooltip"].toInt();
|
||||
// resize tooltip image
|
||||
m_toolTipView->resize(100 * m_counts, 105);
|
||||
|
||||
requiredKeys.clear();
|
||||
if (m_configuration[QString("cpuTooltip")].toBool())
|
||||
requiredKeys.append(QString("cpuTooltip"));
|
||||
if (m_configuration[QString("cpuclTooltip")].toBool())
|
||||
requiredKeys.append(QString("cpuclTooltip"));
|
||||
if (m_configuration[QString("memTooltip")].toBool())
|
||||
requiredKeys.append(QString("memTooltip"));
|
||||
if (m_configuration[QString("swapTooltip")].toBool())
|
||||
requiredKeys.append(QString("swapTooltip"));
|
||||
if (m_configuration[QString("downkbTooltip")].toBool())
|
||||
requiredKeys.append(QString("downkbTooltip"));
|
||||
if (m_configuration[QString("upkbTooltip")].toBool())
|
||||
requiredKeys.append(QString("upkbTooltip"));
|
||||
if (m_configuration[QString("batTooltip")].toBool())
|
||||
requiredKeys.append(QString("batTooltip"));
|
||||
if (m_configuration["cpuTooltip"].toBool())
|
||||
requiredKeys.append("cpuTooltip");
|
||||
if (m_configuration["cpuclTooltip"].toBool())
|
||||
requiredKeys.append("cpuclTooltip");
|
||||
if (m_configuration["memTooltip"].toBool())
|
||||
requiredKeys.append("memTooltip");
|
||||
if (m_configuration["swapTooltip"].toBool())
|
||||
requiredKeys.append("swapTooltip");
|
||||
if (m_configuration["downkbTooltip"].toBool())
|
||||
requiredKeys.append("downkbTooltip");
|
||||
if (m_configuration["upkbTooltip"].toBool())
|
||||
requiredKeys.append("upkbTooltip");
|
||||
if (m_configuration["batTooltip"].toBool())
|
||||
requiredKeys.append("batTooltip");
|
||||
|
||||
// background
|
||||
m_toolTipScene->setBackgroundBrush(
|
||||
m_configuration[QString("useTooltipBackground")].toBool()
|
||||
? QBrush(QColor(
|
||||
m_configuration[QString("tooltipBackground")].toString()))
|
||||
m_configuration["useTooltipBackground"].toBool()
|
||||
? QBrush(QColor(m_configuration["tooltipBackground"].toString()))
|
||||
: QBrush(Qt::NoBrush));
|
||||
}
|
||||
|
||||
@ -129,7 +127,7 @@ QPixmap AWDataAggregator::tooltipImage()
|
||||
m_toolTipScene->clear();
|
||||
QPen pen;
|
||||
bool down = false;
|
||||
for (auto key : requiredKeys) {
|
||||
for (auto &key : requiredKeys) {
|
||||
// create frame
|
||||
float normX = 100.0f / static_cast<float>(m_values[key].count());
|
||||
float normY = 100.0f / (1.5f * m_boundaries[key]);
|
||||
@ -137,29 +135,27 @@ QPixmap AWDataAggregator::tooltipImage()
|
||||
if (down)
|
||||
shift -= 100.0;
|
||||
// apply pen color
|
||||
if (key != QString("batTooltip"))
|
||||
if (key != "batTooltip")
|
||||
pen.setColor(QColor(
|
||||
m_configuration[QString("%1Color").arg(key)].toString()));
|
||||
// paint data inside frame
|
||||
for (int j = 0; j < m_values[key].count() - 1; j++) {
|
||||
// some magic here
|
||||
float x1 = j * normX + shift;
|
||||
float y1 = -fabs(m_values[key].at(j)) * normY + 5.0f;
|
||||
float y1 = -std::fabs(m_values[key].at(j)) * normY + 5.0f;
|
||||
float x2 = (j + 1) * normX + shift;
|
||||
float y2 = -fabs(m_values[key].at(j + 1)) * normY + 5.0f;
|
||||
if (key == QString("batTooltip")) {
|
||||
float y2 = -std::fabs(m_values[key].at(j + 1)) * normY + 5.0f;
|
||||
if (key == "batTooltip") {
|
||||
if (m_values[key].at(j + 1) > 0)
|
||||
pen.setColor(
|
||||
QColor(m_configuration[QString("batTooltipColor")]
|
||||
.toString()));
|
||||
QColor(m_configuration["batTooltipColor"].toString()));
|
||||
else
|
||||
pen.setColor(
|
||||
QColor(m_configuration[QString("batInTooltipColor")]
|
||||
.toString()));
|
||||
pen.setColor(QColor(
|
||||
m_configuration["batInTooltipColor"].toString()));
|
||||
}
|
||||
m_toolTipScene->addLine(x1, y1, x2, y2, pen);
|
||||
}
|
||||
if (key == QString("downkbTooltip"))
|
||||
if (key == "downkbTooltip")
|
||||
down = true;
|
||||
}
|
||||
|
||||
@ -167,43 +163,44 @@ QPixmap AWDataAggregator::tooltipImage()
|
||||
}
|
||||
|
||||
|
||||
void AWDataAggregator::dataUpdate(const QVariantHash &values)
|
||||
void AWDataAggregator::dataUpdate(const QVariantHash &_values)
|
||||
{
|
||||
// do not log these arguments
|
||||
setData(values);
|
||||
setData(_values);
|
||||
emit(toolTipPainted(htmlImage(tooltipImage())));
|
||||
}
|
||||
|
||||
|
||||
void AWDataAggregator::checkValue(const QString source, const float value,
|
||||
const float extremum) const
|
||||
void AWDataAggregator::checkValue(const QString &_source, const float _value,
|
||||
const float _extremum) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Notification source" << source << "with value" << value
|
||||
<< "called with extremum" << extremum;
|
||||
qCDebug(LOG_AW) << "Notification source" << _source << "with value"
|
||||
<< _value << "called with extremum" << _extremum;
|
||||
|
||||
if (value >= 0.0) {
|
||||
if ((m_enablePopup) && (value > extremum)
|
||||
&& (m_values[source].last() < extremum))
|
||||
return AWActions::sendNotification(QString("event"),
|
||||
notificationText(source, value));
|
||||
if (_value >= 0.0) {
|
||||
if ((m_enablePopup) && (_value > _extremum)
|
||||
&& (m_values[_source].last() < _extremum))
|
||||
return AWActions::sendNotification(
|
||||
"event", notificationText(_source, _value));
|
||||
} else {
|
||||
if ((m_enablePopup) && (value < extremum)
|
||||
&& (m_values[source].last() > extremum))
|
||||
return AWActions::sendNotification(QString("event"),
|
||||
notificationText(source, value));
|
||||
if ((m_enablePopup) && (_value < _extremum)
|
||||
&& (m_values[_source].last() > _extremum))
|
||||
return AWActions::sendNotification(
|
||||
"event", notificationText(_source, _value));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AWDataAggregator::checkValue(const QString source, const QString current,
|
||||
const QString received) const
|
||||
void AWDataAggregator::checkValue(const QString &_source,
|
||||
const QString &_current,
|
||||
const QString &_received) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Notification source" << source << "with current value"
|
||||
<< current << "and received one" << received;
|
||||
qCDebug(LOG_AW) << "Notification source" << _source << "with current value"
|
||||
<< _current << "and received one" << _received;
|
||||
|
||||
if ((m_enablePopup) && (current != received) && (!received.isEmpty()))
|
||||
return AWActions::sendNotification(QString("event"),
|
||||
notificationText(source, received));
|
||||
if ((m_enablePopup) && (_current != _received) && (!_received.isEmpty()))
|
||||
return AWActions::sendNotification(
|
||||
"event", notificationText(_source, _received));
|
||||
}
|
||||
|
||||
|
||||
@ -211,7 +208,7 @@ void AWDataAggregator::initScene()
|
||||
{
|
||||
m_toolTipScene = new QGraphicsScene(nullptr);
|
||||
m_toolTipView = new QGraphicsView(m_toolTipScene);
|
||||
m_toolTipView->setStyleSheet(QString("background: transparent"));
|
||||
m_toolTipView->setStyleSheet("background: transparent");
|
||||
m_toolTipView->setContentsMargins(0, 0, 0, 0);
|
||||
m_toolTipView->setFrameShape(QFrame::NoFrame);
|
||||
m_toolTipView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
@ -219,105 +216,105 @@ void AWDataAggregator::initScene()
|
||||
}
|
||||
|
||||
|
||||
QString AWDataAggregator::notificationText(const QString source,
|
||||
const float value) const
|
||||
QString AWDataAggregator::notificationText(const QString &_source,
|
||||
const float _value) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Notification source" << source << "with value" << value;
|
||||
qCDebug(LOG_AW) << "Notification source" << _source << "with value"
|
||||
<< _value;
|
||||
|
||||
QString output;
|
||||
if (source == QString("batTooltip"))
|
||||
output = value > 0.0 ? i18n("AC online") : i18n("AC offline");
|
||||
else if (source == QString("cpuTooltip"))
|
||||
if (_source == "batTooltip")
|
||||
output = _value > 0.0 ? i18n("AC online") : i18n("AC offline");
|
||||
else if (_source == "cpuTooltip")
|
||||
output = i18n("High CPU load");
|
||||
else if (source == QString("memTooltip"))
|
||||
else if (_source == "memTooltip")
|
||||
output = i18n("High memory usage");
|
||||
else if (source == QString("swapTooltip"))
|
||||
else if (_source == "swapTooltip")
|
||||
output = i18n("Swap is used");
|
||||
else if (source == QString("gpu"))
|
||||
else if (_source == "gpu")
|
||||
output = i18n("High GPU load");
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
QString AWDataAggregator::notificationText(const QString source,
|
||||
const QString value) const
|
||||
QString AWDataAggregator::notificationText(const QString &_source,
|
||||
const QString &_value) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Notification source" << source << "with value" << value;
|
||||
qCDebug(LOG_AW) << "Notification source" << _source << "with value"
|
||||
<< _value;
|
||||
|
||||
QString output;
|
||||
if (source == QString("netdev"))
|
||||
output = i18n("Network device has been changed to %1", value);
|
||||
if (_source == "netdev")
|
||||
output = i18n("Network device has been changed to %1", _value);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
void AWDataAggregator::setData(const QVariantHash &values)
|
||||
void AWDataAggregator::setData(const QVariantHash &_values)
|
||||
{
|
||||
// do not log these arguments
|
||||
// battery update requires info is AC online or not
|
||||
setData(values[QString("ac")].toString()
|
||||
== m_configuration[QString("acOnline")],
|
||||
QString("batTooltip"), values[QString("bat")].toFloat());
|
||||
setData(_values["ac"].toString() == m_configuration["acOnline"],
|
||||
"batTooltip", _values["bat"].toFloat());
|
||||
// usual case
|
||||
setData(QString("cpuTooltip"), values[QString("cpu")].toFloat(), 90.0);
|
||||
setData(QString("cpuclTooltip"), values[QString("cpucl")].toFloat());
|
||||
setData(QString("memTooltip"), values[QString("mem")].toFloat(), 80.0);
|
||||
setData(QString("swapTooltip"), values[QString("swap")].toFloat(), 0.0);
|
||||
setData(QString("downkbTooltip"), values[QString("downkb")].toFloat());
|
||||
setData(QString("upkbTooltip"), values[QString("upkb")].toFloat());
|
||||
setData("cpuTooltip", _values["cpu"].toFloat(), 90.0);
|
||||
setData("cpuclTooltip", _values["cpucl"].toFloat());
|
||||
setData("memTooltip", _values["mem"].toFloat(), 80.0);
|
||||
setData("swapTooltip", _values["swap"].toFloat(), 0.0);
|
||||
setData("downkbTooltip", _values["downkb"].toFloat());
|
||||
setData("upkbTooltip", _values["upkb"].toFloat());
|
||||
// additional check for network device
|
||||
[this](const QString value) {
|
||||
checkValue(QString("netdev"), m_currentNetworkDevice, value);
|
||||
[this](const QString &value) {
|
||||
checkValue("netdev", m_currentNetworkDevice, value);
|
||||
m_currentNetworkDevice = value;
|
||||
}(values[QString("netdev")].toString());
|
||||
}(_values["netdev"].toString());
|
||||
// additional check for GPU load
|
||||
[this](const float value) {
|
||||
checkValue(QString("gpu"), value, 90.0);
|
||||
checkValue("gpu", value, 90.0);
|
||||
m_currentGPULoad = value;
|
||||
}(values[QString("gpu")].toFloat());
|
||||
}(_values["gpu"].toFloat());
|
||||
}
|
||||
|
||||
|
||||
void AWDataAggregator::setData(const QString &source, float value,
|
||||
const float extremum)
|
||||
void AWDataAggregator::setData(const QString &_source, float _value,
|
||||
const float _extremum)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Source" << source << "to value" << value
|
||||
<< "with extremum" << extremum;
|
||||
qCDebug(LOG_AW) << "Source" << _source << "to value" << _value
|
||||
<< "with extremum" << _extremum;
|
||||
|
||||
if (m_values[source].count() == 0)
|
||||
m_values[source].append(0.0);
|
||||
else if (m_values[source].count()
|
||||
> m_configuration[QString("tooltipNumber")].toInt())
|
||||
m_values[source].removeFirst();
|
||||
if (std::isnan(value))
|
||||
value = 0.0;
|
||||
if (m_values[_source].count() == 0)
|
||||
m_values[_source].append(0.0);
|
||||
else if (m_values[_source].count()
|
||||
> m_configuration["tooltipNumber"].toInt())
|
||||
m_values[_source].removeFirst();
|
||||
if (std::isnan(_value))
|
||||
_value = 0.0;
|
||||
|
||||
// notifications
|
||||
checkValue(source, value, extremum);
|
||||
checkValue(_source, _value, _extremum);
|
||||
|
||||
m_values[source].append(value);
|
||||
if (source == QString("downkbTooltip")) {
|
||||
QList<float> netValues = m_values[QString("downkbTooltip")]
|
||||
+ m_values[QString("upkbTooltip")];
|
||||
m_values[_source].append(_value);
|
||||
if (_source == "downkbTooltip") {
|
||||
QList<float> netValues
|
||||
= m_values["downkbTooltip"] + m_values["upkbTooltip"];
|
||||
// to avoid inf value of normY
|
||||
netValues << 1.0;
|
||||
m_boundaries[QString("downkbTooltip")]
|
||||
m_boundaries["downkbTooltip"]
|
||||
= 1.2f * *std::max_element(netValues.cbegin(), netValues.cend());
|
||||
m_boundaries[QString("upkbTooltip")]
|
||||
= m_boundaries[QString("downkbTooltip")];
|
||||
m_boundaries["upkbTooltip"] = m_boundaries["downkbTooltip"];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AWDataAggregator::setData(const bool dontInvert, const QString &source,
|
||||
float value)
|
||||
void AWDataAggregator::setData(const bool _dontInvert, const QString &_source,
|
||||
float _value)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Do not invert" << dontInvert << "value" << value
|
||||
<< "for source" << source;
|
||||
qCDebug(LOG_AW) << "Do not invert" << _dontInvert << "value" << _value
|
||||
<< "for source" << _source;
|
||||
|
||||
// invert values for different battery colours
|
||||
value = dontInvert ? value : -value;
|
||||
return setData(source, value, 0.0);
|
||||
_value = _dontInvert ? _value : -_value;
|
||||
return setData(_source, _value, 0.0);
|
||||
}
|
||||
|
@ -33,42 +33,43 @@ class AWDataAggregator : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AWDataAggregator(QObject *parent = nullptr);
|
||||
explicit AWDataAggregator(QObject *_parent = nullptr);
|
||||
virtual ~AWDataAggregator();
|
||||
QList<float> getData(const QString key) const;
|
||||
QString htmlImage(const QPixmap &source) const;
|
||||
void setParameters(QVariantMap settings);
|
||||
QList<float> getData(const QString &_key) const;
|
||||
QString htmlImage(const QPixmap &_source) const;
|
||||
void setParameters(const QVariantMap &_settings);
|
||||
QPixmap tooltipImage();
|
||||
|
||||
signals:
|
||||
void updateData(const QVariantHash &values);
|
||||
void toolTipPainted(const QString image) const;
|
||||
void updateData(const QVariantHash &_values);
|
||||
void toolTipPainted(const QString &_image) const;
|
||||
|
||||
private slots:
|
||||
void dataUpdate(const QVariantHash &values);
|
||||
void dataUpdate(const QVariantHash &_values);
|
||||
|
||||
private:
|
||||
// ui
|
||||
QGraphicsScene *m_toolTipScene = nullptr;
|
||||
QGraphicsView *m_toolTipView = nullptr;
|
||||
void checkValue(const QString source, const float value,
|
||||
const float extremum) const;
|
||||
void checkValue(const QString source, const QString current,
|
||||
const QString received) const;
|
||||
void checkValue(const QString &_source, const float _value,
|
||||
const float _extremum) const;
|
||||
void checkValue(const QString &_source, const QString &_current,
|
||||
const QString &_received) const;
|
||||
void initScene();
|
||||
QString notificationText(const QString source, const float value) const;
|
||||
QString notificationText(const QString source, const QString value) const;
|
||||
QString notificationText(const QString &_source, const float _value) const;
|
||||
QString notificationText(const QString &_source,
|
||||
const QString &_value) const;
|
||||
// main method
|
||||
void setData(const QVariantHash &values);
|
||||
void setData(const QString &source, float value,
|
||||
const float extremum = -1.0f);
|
||||
void setData(const QVariantHash &_values);
|
||||
void setData(const QString &_source, float _value,
|
||||
const float _extremum = -1.0f);
|
||||
// different signature for battery device
|
||||
void setData(const bool dontInvert, const QString &source, float value);
|
||||
void setData(const bool _dontInvert, const QString &_source, float _value);
|
||||
// variables
|
||||
int m_counts = 0;
|
||||
QVariantHash m_configuration;
|
||||
float m_currentGPULoad = 0.0;
|
||||
QString m_currentNetworkDevice = QString("lo");
|
||||
float m_currentGPULoad = 0.0f;
|
||||
QString m_currentNetworkDevice = "lo";
|
||||
QHash<QString, float> m_boundaries;
|
||||
QHash<QString, QList<float>> m_values;
|
||||
bool m_enablePopup = false;
|
||||
|
@ -17,14 +17,19 @@
|
||||
|
||||
#include "awdataengineaggregator.h"
|
||||
|
||||
#include <Plasma/DataContainer>
|
||||
|
||||
#include "awdebug.h"
|
||||
#include "awkeys.h"
|
||||
|
||||
|
||||
AWDataEngineAggregator::AWDataEngineAggregator(QObject *parent)
|
||||
: QObject(parent)
|
||||
AWDataEngineAggregator::AWDataEngineAggregator(QObject *_parent)
|
||||
: QObject(_parent)
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
|
||||
// required to define Qt::QueuedConnection for signal-slot connection
|
||||
qRegisterMetaType<Plasma::DataEngine::Data>("Plasma::DataEngine::Data");
|
||||
}
|
||||
|
||||
|
||||
@ -48,54 +53,81 @@ void AWDataEngineAggregator::clear()
|
||||
void AWDataEngineAggregator::disconnectSources()
|
||||
{
|
||||
for (auto dataengine : m_dataEngines.values())
|
||||
for (auto source : dataengine->sources())
|
||||
for (auto &source : dataengine->sources())
|
||||
dataengine->disconnectSource(source, parent());
|
||||
}
|
||||
|
||||
|
||||
void AWDataEngineAggregator::initDataEngines(const int interval)
|
||||
void AWDataEngineAggregator::initDataEngines(const int _interval)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Init dataengines with interval" << interval;
|
||||
qCDebug(LOG_AW) << "Init dataengines with interval" << _interval;
|
||||
|
||||
m_consumer = new Plasma::DataEngineConsumer();
|
||||
m_dataEngines[QString("systemmonitor")]
|
||||
= m_consumer->dataEngine(QString("systemmonitor"));
|
||||
m_dataEngines[QString("extsysmon")]
|
||||
= m_consumer->dataEngine(QString("extsysmon"));
|
||||
m_dataEngines[QString("time")] = m_consumer->dataEngine(QString("time"));
|
||||
m_dataEngines["systemmonitor"] = m_consumer->dataEngine("systemmonitor");
|
||||
m_dataEngines["extsysmon"] = m_consumer->dataEngine("extsysmon");
|
||||
m_dataEngines["time"] = m_consumer->dataEngine("time");
|
||||
|
||||
// additional method required by systemmonitor structure
|
||||
connect(m_dataEngines[QString("systemmonitor")],
|
||||
&Plasma::DataEngine::sourceAdded,
|
||||
[this, interval](const QString source) {
|
||||
connect(m_dataEngines["systemmonitor"], &Plasma::DataEngine::sourceAdded,
|
||||
[this, _interval](const QString source) {
|
||||
emit(deviceAdded(source));
|
||||
m_dataEngines[QString("systemmonitor")]->connectSource(
|
||||
source, parent(), interval);
|
||||
m_dataEngines["systemmonitor"]->connectSource(source, parent(),
|
||||
_interval);
|
||||
});
|
||||
|
||||
return reconnectSources(interval);
|
||||
return reconnectSources(_interval);
|
||||
}
|
||||
|
||||
|
||||
void AWDataEngineAggregator::dropSource(const QString source)
|
||||
void AWDataEngineAggregator::dropSource(const QString &_source)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Source" << source;
|
||||
qCDebug(LOG_AW) << "Source" << _source;
|
||||
|
||||
// HACK there is no possibility to check to which dataengine source
|
||||
// connected we will try to disconnect it from systemmonitor and extsysmon
|
||||
m_dataEngines[QString("systemmonitor")]->disconnectSource(source, parent());
|
||||
m_dataEngines[QString("extsysmon")]->disconnectSource(source, parent());
|
||||
m_dataEngines[QString("time")]->disconnectSource(source, parent());
|
||||
for (auto dataengine : m_dataEngines.values())
|
||||
dataengine->disconnectSource(_source, parent());
|
||||
}
|
||||
|
||||
|
||||
void AWDataEngineAggregator::reconnectSources(const int interval)
|
||||
void AWDataEngineAggregator::reconnectSources(const int _interval)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Reconnect sources with interval" << interval;
|
||||
qCDebug(LOG_AW) << "Reconnect sources with interval" << _interval;
|
||||
|
||||
m_dataEngines[QString("systemmonitor")]->connectAllSources(parent(),
|
||||
interval);
|
||||
m_dataEngines[QString("extsysmon")]->connectAllSources(parent(), interval);
|
||||
m_dataEngines[QString("time")]->connectSource(QString("Local"), parent(),
|
||||
1000);
|
||||
m_dataEngines["systemmonitor"]->connectAllSources(parent(), _interval);
|
||||
m_dataEngines["extsysmon"]->connectAllSources(parent(), _interval);
|
||||
m_dataEngines["time"]->connectSource("Local", parent(), 1000);
|
||||
|
||||
#ifdef BUILD_FUTURE
|
||||
createQueuedConnection();
|
||||
#endif /* BUILD_FUTURE */
|
||||
}
|
||||
|
||||
|
||||
void AWDataEngineAggregator::createQueuedConnection()
|
||||
{
|
||||
// HACK additional method which forces QueuedConnection instead of Auto one
|
||||
// for more details refer to plasma-framework source code
|
||||
for (auto &dataEngine : m_dataEngines.keys()) {
|
||||
// different source set for different engines
|
||||
QStringList sources = dataEngine == "time"
|
||||
? QStringList() << "Local"
|
||||
: m_dataEngines[dataEngine]->sources();
|
||||
// reconnect sources
|
||||
for (auto &source : sources) {
|
||||
Plasma::DataContainer *container
|
||||
= m_dataEngines[dataEngine]->containerForSource(source);
|
||||
// disconnect old connections first
|
||||
disconnect(container,
|
||||
SIGNAL(dataUpdated(QString, Plasma::DataEngine::Data)),
|
||||
parent(),
|
||||
SLOT(dataUpdated(QString, Plasma::DataEngine::Data)));
|
||||
// and now reconnect with Qt::QueuedConnection type
|
||||
connect(container,
|
||||
SIGNAL(dataUpdated(QString, Plasma::DataEngine::Data)),
|
||||
parent(),
|
||||
SLOT(dataUpdated(QString, Plasma::DataEngine::Data)),
|
||||
Qt::QueuedConnection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,20 +30,21 @@ class AWDataEngineAggregator : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AWDataEngineAggregator(QObject *parent = nullptr);
|
||||
explicit AWDataEngineAggregator(QObject *_parent = nullptr);
|
||||
virtual ~AWDataEngineAggregator();
|
||||
void clear();
|
||||
void disconnectSources();
|
||||
void initDataEngines(const int interval);
|
||||
void initDataEngines(const int _interval);
|
||||
|
||||
signals:
|
||||
void deviceAdded(const QString &source);
|
||||
void deviceAdded(const QString &_source);
|
||||
|
||||
public slots:
|
||||
void dropSource(const QString source);
|
||||
void reconnectSources(const int interval);
|
||||
void dropSource(const QString &_source);
|
||||
void reconnectSources(const int _interval);
|
||||
|
||||
private:
|
||||
void createQueuedConnection();
|
||||
Plasma::DataEngineConsumer *m_consumer = nullptr;
|
||||
QHash<QString, Plasma::DataEngine *> m_dataEngines;
|
||||
};
|
||||
|
92
sources/awesome-widget/plugin/awdbusadaptor.cpp
Normal file
92
sources/awesome-widget/plugin/awdbusadaptor.cpp
Normal file
@ -0,0 +1,92 @@
|
||||
/***************************************************************************
|
||||
* 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 "awdbusadaptor.h"
|
||||
|
||||
#include "awdebug.h"
|
||||
#include "awkeys.h"
|
||||
|
||||
|
||||
AWDBusAdaptor::AWDBusAdaptor(AWKeys *_parent)
|
||||
: QDBusAbstractAdaptor(_parent)
|
||||
, m_plugin(_parent)
|
||||
{
|
||||
qCDebug(LOG_DBUS) << __PRETTY_FUNCTION__;
|
||||
}
|
||||
|
||||
|
||||
AWDBusAdaptor::~AWDBusAdaptor()
|
||||
{
|
||||
qCDebug(LOG_DBUS) << __PRETTY_FUNCTION__;
|
||||
}
|
||||
|
||||
|
||||
QString AWDBusAdaptor::Info(const QString &key) const
|
||||
{
|
||||
return m_plugin->infoByKey(key);
|
||||
}
|
||||
|
||||
|
||||
QStringList AWDBusAdaptor::Keys(const QString ®exp) const
|
||||
{
|
||||
return m_plugin->dictKeys(true, regexp);
|
||||
}
|
||||
|
||||
|
||||
QString AWDBusAdaptor::Value(const QString &key) const
|
||||
{
|
||||
return m_plugin->valueByKey(key);
|
||||
}
|
||||
|
||||
|
||||
qlonglong AWDBusAdaptor::WhoAmI() const
|
||||
{
|
||||
return reinterpret_cast<qlonglong>(m_plugin);
|
||||
}
|
||||
|
||||
|
||||
void AWDBusAdaptor::SetLogLevel(const QString &what, const int level)
|
||||
{
|
||||
qCDebug(LOG_DBUS) << "Set log level" << level << "for" << what;
|
||||
|
||||
if (level >= m_logLevels.count()) {
|
||||
qCDebug(LOG_DBUS) << "Invalid logging level" << level
|
||||
<< "should be less than" << m_logLevels.count();
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto &lev : m_logLevels)
|
||||
SetLogLevel(what, lev, m_logLevels.indexOf(lev) >= level);
|
||||
}
|
||||
|
||||
|
||||
void AWDBusAdaptor::SetLogLevel(const QString &what, const QString &level,
|
||||
const bool enabled)
|
||||
{
|
||||
qCDebug(LOG_DBUS) << "Set log level" << level << "enabled" << enabled
|
||||
<< "for" << what;
|
||||
|
||||
if (!m_logLevels.contains(level)) {
|
||||
qCDebug(LOG_DBUS) << "Invalid logging level" << level << "should be in"
|
||||
<< m_logLevels;
|
||||
return;
|
||||
}
|
||||
|
||||
QString state = enabled ? "true" : "false";
|
||||
QLoggingCategory::setFilterRules(
|
||||
QString("%1.%2=%3").arg(what).arg(level).arg(state));
|
||||
}
|
58
sources/awesome-widget/plugin/awdbusadaptor.h
Normal file
58
sources/awesome-widget/plugin/awdbusadaptor.h
Normal file
@ -0,0 +1,58 @@
|
||||
/***************************************************************************
|
||||
* 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 AWDBUSADAPTOR_H
|
||||
#define AWDBUSADAPTOR_H
|
||||
|
||||
#include <QDBusAbstractAdaptor>
|
||||
|
||||
#include "version.h"
|
||||
|
||||
|
||||
class AWKeys;
|
||||
|
||||
class AWDBusAdaptor : public QDBusAbstractAdaptor
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_CLASSINFO("D-Bus Interface", AWDBUS_SERVICE_NAME)
|
||||
|
||||
public:
|
||||
explicit AWDBusAdaptor(AWKeys *_parent = nullptr);
|
||||
virtual ~AWDBusAdaptor();
|
||||
|
||||
public slots:
|
||||
// get methods
|
||||
QString Info(const QString &key) const;
|
||||
QStringList Keys(const QString ®exp) const;
|
||||
QString Value(const QString &key) const;
|
||||
qlonglong WhoAmI() const;
|
||||
// set methods
|
||||
void SetLogLevel(const QString &what, const int level);
|
||||
void SetLogLevel(const QString &what, const QString &level,
|
||||
const bool enabled);
|
||||
|
||||
private:
|
||||
AWKeys *m_plugin = nullptr;
|
||||
QStringList m_logLevels = QStringList() << "debug"
|
||||
<< "info"
|
||||
<< "warning"
|
||||
<< "critical";
|
||||
};
|
||||
|
||||
|
||||
#endif /* AWDBUSADAPTOR_H */
|
@ -20,9 +20,11 @@
|
||||
#include <QtQml>
|
||||
|
||||
#include "awactions.h"
|
||||
#include "awbugreporter.h"
|
||||
#include "awconfighelper.h"
|
||||
#include "awformatterconfigfactory.h"
|
||||
#include "awkeys.h"
|
||||
#include "awtelemetryhandler.h"
|
||||
|
||||
|
||||
void AWPlugin::registerTypes(const char *uri)
|
||||
@ -30,8 +32,10 @@ void AWPlugin::registerTypes(const char *uri)
|
||||
Q_ASSERT(uri == QLatin1String("org.kde.plasma.private.awesomewidget"));
|
||||
|
||||
qmlRegisterType<AWActions>(uri, 1, 0, "AWActions");
|
||||
qmlRegisterType<AWBugReporter>(uri, 1, 0, "AWBugReporter");
|
||||
qmlRegisterType<AWConfigHelper>(uri, 1, 0, "AWConfigHelper");
|
||||
qmlRegisterType<AWFormatterConfigFactory>(uri, 1, 0,
|
||||
"AWFormatterConfigFactory");
|
||||
qmlRegisterType<AWKeys>(uri, 1, 0, "AWKeys");
|
||||
qmlRegisterType<AWTelemetryHandler>(uri, 1, 0, "AWTelemetryHandler");
|
||||
}
|
||||
|
@ -27,10 +27,10 @@
|
||||
#include "awformatterhelper.h"
|
||||
|
||||
|
||||
AWFormatterConfig::AWFormatterConfig(QWidget *parent, const QStringList keys)
|
||||
: QDialog(parent)
|
||||
AWFormatterConfig::AWFormatterConfig(QWidget *_parent, const QStringList &_keys)
|
||||
: QDialog(_parent)
|
||||
, ui(new Ui::AWFormatterConfig)
|
||||
, m_keys(keys)
|
||||
, m_keys(_keys)
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
|
||||
@ -80,12 +80,14 @@ void AWFormatterConfig::updateUi()
|
||||
= m_selectors.indexOf(static_cast<AWAbstractSelector *>(sender()));
|
||||
|
||||
if ((current.first.isEmpty()) && (current.second.isEmpty())) {
|
||||
// remove current selector if it is empty and does not last
|
||||
if (sender() == m_selectors.last())
|
||||
return;
|
||||
AWAbstractSelector *selector = m_selectors.takeAt(index);
|
||||
ui->verticalLayout->removeWidget(selector);
|
||||
selector->deleteLater();
|
||||
} else {
|
||||
// add new selector if something changed
|
||||
if (sender() != m_selectors.last())
|
||||
return;
|
||||
auto keys = initKeys();
|
||||
@ -94,16 +96,16 @@ void AWFormatterConfig::updateUi()
|
||||
}
|
||||
|
||||
|
||||
void AWFormatterConfig::addSelector(const QStringList &keys,
|
||||
const QStringList &values,
|
||||
const QPair<QString, QString> ¤t)
|
||||
void AWFormatterConfig::addSelector(const QStringList &_keys,
|
||||
const QStringList &_values,
|
||||
const QPair<QString, QString> &_current)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Add selector with keys" << keys << "values" << values
|
||||
<< "and current ones" << current;
|
||||
qCDebug(LOG_AW) << "Add selector with keys" << _keys << "values" << _values
|
||||
<< "and current ones" << _current;
|
||||
|
||||
AWAbstractSelector *selector
|
||||
= new AWAbstractSelector(ui->scrollAreaWidgetContents);
|
||||
selector->init(keys, values, current);
|
||||
selector->init(_keys, _values, _current);
|
||||
ui->verticalLayout->insertWidget(ui->verticalLayout->count() - 1, selector);
|
||||
connect(selector, SIGNAL(selectionChanged()), this, SLOT(updateUi()));
|
||||
m_selectors.append(selector);
|
||||
@ -112,7 +114,7 @@ void AWFormatterConfig::addSelector(const QStringList &keys,
|
||||
|
||||
void AWFormatterConfig::clearSelectors()
|
||||
{
|
||||
for (auto selector : m_selectors) {
|
||||
for (auto &selector : m_selectors) {
|
||||
disconnect(selector, SIGNAL(selectionChanged()), this,
|
||||
SLOT(updateUi()));
|
||||
ui->verticalLayout->removeWidget(selector);
|
||||
@ -126,7 +128,7 @@ void AWFormatterConfig::execDialog()
|
||||
{
|
||||
int ret = exec();
|
||||
QHash<QString, QString> data;
|
||||
for (auto selector : m_selectors) {
|
||||
for (auto &selector : m_selectors) {
|
||||
QPair<QString, QString> select = selector->current();
|
||||
if (select.first.isEmpty())
|
||||
continue;
|
||||
@ -140,7 +142,7 @@ void AWFormatterConfig::execDialog()
|
||||
case 1:
|
||||
default:
|
||||
m_helper->writeFormatters(data);
|
||||
m_helper->writeFormatters(data.keys());
|
||||
m_helper->removeUnusedFormatters(data.keys());
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -156,10 +158,10 @@ void AWFormatterConfig::init()
|
||||
QPair<QStringList, QStringList> AWFormatterConfig::initKeys() const
|
||||
{
|
||||
// we are adding empty string at the start
|
||||
QStringList keys = QStringList() << QString("");
|
||||
QStringList keys = QStringList() << "";
|
||||
keys.append(m_keys);
|
||||
keys.sort();
|
||||
QStringList knownFormatters = QStringList() << QString("");
|
||||
QStringList knownFormatters = QStringList() << "";
|
||||
knownFormatters.append(m_helper->knownFormatters());
|
||||
knownFormatters.sort();
|
||||
|
||||
@ -173,7 +175,7 @@ void AWFormatterConfig::updateDialog()
|
||||
QHash<QString, QString> appliedFormatters = m_helper->getFormatters();
|
||||
auto keys = initKeys();
|
||||
|
||||
for (auto key : appliedFormatters.keys())
|
||||
for (auto &key : appliedFormatters.keys())
|
||||
addSelector(keys.first, keys.second,
|
||||
QPair<QString, QString>(key, appliedFormatters[key]));
|
||||
// empty one
|
||||
|
@ -34,8 +34,8 @@ class AWFormatterConfig : public QDialog
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AWFormatterConfig(QWidget *parent = nullptr,
|
||||
const QStringList keys = QStringList());
|
||||
explicit AWFormatterConfig(QWidget *_parent = nullptr,
|
||||
const QStringList &_keys = QStringList());
|
||||
virtual ~AWFormatterConfig();
|
||||
Q_INVOKABLE void showDialog();
|
||||
|
||||
@ -51,8 +51,8 @@ private:
|
||||
// properties
|
||||
QStringList m_keys;
|
||||
// methods
|
||||
void addSelector(const QStringList &keys, const QStringList &values,
|
||||
const QPair<QString, QString> ¤t);
|
||||
void addSelector(const QStringList &_keys, const QStringList &_values,
|
||||
const QPair<QString, QString> &_current);
|
||||
void clearSelectors();
|
||||
void execDialog();
|
||||
void init();
|
||||
|
@ -21,8 +21,8 @@
|
||||
#include "awformatterconfig.h"
|
||||
|
||||
|
||||
AWFormatterConfigFactory::AWFormatterConfigFactory(QObject *parent)
|
||||
: QObject(parent)
|
||||
AWFormatterConfigFactory::AWFormatterConfigFactory(QObject *_parent)
|
||||
: QObject(_parent)
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
}
|
||||
@ -34,9 +34,9 @@ AWFormatterConfigFactory::~AWFormatterConfigFactory()
|
||||
}
|
||||
|
||||
|
||||
void AWFormatterConfigFactory::showDialog(const QStringList keys)
|
||||
void AWFormatterConfigFactory::showDialog(const QStringList &_keys)
|
||||
{
|
||||
AWFormatterConfig *config = new AWFormatterConfig(nullptr, keys);
|
||||
AWFormatterConfig *config = new AWFormatterConfig(nullptr, _keys);
|
||||
config->showDialog();
|
||||
config->deleteLater();
|
||||
}
|
||||
|
@ -27,9 +27,9 @@ class AWFormatterConfigFactory : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AWFormatterConfigFactory(QObject *parent = nullptr);
|
||||
explicit AWFormatterConfigFactory(QObject *_parent = nullptr);
|
||||
virtual ~AWFormatterConfigFactory();
|
||||
Q_INVOKABLE void showDialog(const QStringList keys);
|
||||
Q_INVOKABLE void showDialog(const QStringList &_keys);
|
||||
|
||||
private:
|
||||
};
|
||||
|
@ -26,17 +26,19 @@
|
||||
#include "awdatetimeformatter.h"
|
||||
#include "awdebug.h"
|
||||
#include "awfloatformatter.h"
|
||||
#include "awjsonformatter.h"
|
||||
#include "awlistformatter.h"
|
||||
#include "awnoformatter.h"
|
||||
#include "awscriptformatter.h"
|
||||
#include "awstringformatter.h"
|
||||
|
||||
|
||||
AWFormatterHelper::AWFormatterHelper(QWidget *parent)
|
||||
: AbstractExtItemAggregator(parent, QString("formatters"))
|
||||
AWFormatterHelper::AWFormatterHelper(QWidget *_parent)
|
||||
: AbstractExtItemAggregator(_parent, "formatters")
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
|
||||
m_filePath = "awesomewidgets/formatters/formatters.ini";
|
||||
initItems();
|
||||
}
|
||||
|
||||
@ -50,13 +52,13 @@ AWFormatterHelper::~AWFormatterHelper()
|
||||
}
|
||||
|
||||
|
||||
QString AWFormatterHelper::convert(const QVariant &value,
|
||||
const QString &name) const
|
||||
QString AWFormatterHelper::convert(const QVariant &_value,
|
||||
const QString &_name) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Convert value" << value << "for" << name;
|
||||
qCDebug(LOG_AW) << "Convert value" << _value << "for" << _name;
|
||||
|
||||
return m_formatters.contains(name) ? m_formatters[name]->convert(value)
|
||||
: value.toString();
|
||||
return m_formatters.contains(_name) ? m_formatters[_name]->convert(_value)
|
||||
: _value.toString();
|
||||
}
|
||||
|
||||
|
||||
@ -69,7 +71,7 @@ QStringList AWFormatterHelper::definedFormatters() const
|
||||
QHash<QString, QString> AWFormatterHelper::getFormatters() const
|
||||
{
|
||||
QHash<QString, QString> map;
|
||||
for (auto tag : m_formatters.keys())
|
||||
for (auto &tag : m_formatters.keys())
|
||||
map[tag] = m_formatters[tag]->name();
|
||||
|
||||
return map;
|
||||
@ -79,7 +81,7 @@ QHash<QString, QString> AWFormatterHelper::getFormatters() const
|
||||
QList<AbstractExtItem *> AWFormatterHelper::items() const
|
||||
{
|
||||
QList<AbstractExtItem *> converted;
|
||||
for (auto item : m_formattersClasses.values())
|
||||
for (auto &item : m_formattersClasses.values())
|
||||
converted.append(item);
|
||||
|
||||
return converted;
|
||||
@ -92,20 +94,21 @@ QStringList AWFormatterHelper::knownFormatters() const
|
||||
}
|
||||
|
||||
|
||||
bool AWFormatterHelper::writeFormatters(const QStringList keys) const
|
||||
bool AWFormatterHelper::removeUnusedFormatters(const QStringList &_keys) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Remove formatters" << keys;
|
||||
qCDebug(LOG_AW) << "Remove formatters" << _keys;
|
||||
|
||||
QString fileName = QString("%1/awesomewidgets/formatters/formatters.ini")
|
||||
QString fileName = QString("%1/%2")
|
||||
.arg(QStandardPaths::writableLocation(
|
||||
QStandardPaths::GenericDataLocation));
|
||||
QStandardPaths::GenericDataLocation))
|
||||
.arg(m_filePath);
|
||||
QSettings settings(fileName, QSettings::IniFormat);
|
||||
qCInfo(LOG_AW) << "Configuration file" << fileName;
|
||||
|
||||
settings.beginGroup(QString("Formatters"));
|
||||
settings.beginGroup("Formatters");
|
||||
QStringList foundKeys = settings.childKeys();
|
||||
for (auto key : foundKeys) {
|
||||
if (keys.contains(key))
|
||||
for (auto &key : foundKeys) {
|
||||
if (_keys.contains(key))
|
||||
continue;
|
||||
settings.remove(key);
|
||||
}
|
||||
@ -118,19 +121,20 @@ bool AWFormatterHelper::writeFormatters(const QStringList keys) const
|
||||
|
||||
|
||||
bool AWFormatterHelper::writeFormatters(
|
||||
const QHash<QString, QString> configuration) const
|
||||
const QHash<QString, QString> &_configuration) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Write configuration" << configuration;
|
||||
qCDebug(LOG_AW) << "Write configuration" << _configuration;
|
||||
|
||||
QString fileName = QString("%1/awesomewidgets/formatters/formatters.ini")
|
||||
QString fileName = QString("%1/%2")
|
||||
.arg(QStandardPaths::writableLocation(
|
||||
QStandardPaths::GenericDataLocation));
|
||||
QStandardPaths::GenericDataLocation))
|
||||
.arg(m_filePath);
|
||||
QSettings settings(fileName, QSettings::IniFormat);
|
||||
qCInfo(LOG_AW) << "Configuration file" << fileName;
|
||||
|
||||
settings.beginGroup(QString("Formatters"));
|
||||
for (auto key : configuration.keys())
|
||||
settings.setValue(key, configuration[key]);
|
||||
settings.beginGroup("Formatters");
|
||||
for (auto &key : _configuration.keys())
|
||||
settings.setValue(key, _configuration[key]);
|
||||
settings.endGroup();
|
||||
|
||||
settings.sync();
|
||||
@ -148,26 +152,28 @@ void AWFormatterHelper::editItems()
|
||||
|
||||
|
||||
AWAbstractFormatter::FormatterClass
|
||||
AWFormatterHelper::defineFormatterClass(const QString stringType) const
|
||||
AWFormatterHelper::defineFormatterClass(const QString &_stringType) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Define formatter class for" << stringType;
|
||||
qCDebug(LOG_AW) << "Define formatter class for" << _stringType;
|
||||
|
||||
AWAbstractFormatter::FormatterClass formatter
|
||||
= AWAbstractFormatter::FormatterClass::NoFormat;
|
||||
if (stringType == QString("DateTime"))
|
||||
if (_stringType == "DateTime")
|
||||
formatter = AWAbstractFormatter::FormatterClass::DateTime;
|
||||
else if (stringType == QString("Float"))
|
||||
else if (_stringType == "Float")
|
||||
formatter = AWAbstractFormatter::FormatterClass::Float;
|
||||
else if (stringType == QString("List"))
|
||||
else if (_stringType == "List")
|
||||
formatter = AWAbstractFormatter::FormatterClass::List;
|
||||
else if (stringType == QString("NoFormat"))
|
||||
else if (_stringType == "NoFormat")
|
||||
;
|
||||
else if (stringType == QString("Script"))
|
||||
else if (_stringType == "Script")
|
||||
formatter = AWAbstractFormatter::FormatterClass::Script;
|
||||
else if (stringType == QString("String"))
|
||||
else if (_stringType == "String")
|
||||
formatter = AWAbstractFormatter::FormatterClass::String;
|
||||
else if (_stringType == "Json")
|
||||
formatter = AWAbstractFormatter::FormatterClass::Json;
|
||||
else
|
||||
qCWarning(LOG_AW) << "Unknown formatter" << stringType;
|
||||
qCWarning(LOG_AW) << "Unknown formatter" << _stringType;
|
||||
|
||||
return formatter;
|
||||
}
|
||||
@ -180,8 +186,8 @@ void AWFormatterHelper::initFormatters()
|
||||
for (int i = m_directories.count() - 1; i >= 0; i--) {
|
||||
QStringList files
|
||||
= QDir(m_directories.at(i)).entryList(QDir::Files, QDir::Name);
|
||||
for (auto file : files) {
|
||||
if (!file.endsWith(QString(".desktop")))
|
||||
for (auto &file : files) {
|
||||
if (!file.endsWith(".desktop"))
|
||||
continue;
|
||||
qCInfo(LOG_AW) << "Found file" << file << "in"
|
||||
<< m_directories.at(i);
|
||||
@ -213,6 +219,9 @@ void AWFormatterHelper::initFormatters()
|
||||
m_formattersClasses[name]
|
||||
= new AWStringFormatter(this, filePath);
|
||||
break;
|
||||
case AWAbstractFormatter::FormatterClass::Json:
|
||||
m_formattersClasses[name] = new AWJsonFormatter(this, filePath);
|
||||
break;
|
||||
case AWAbstractFormatter::FormatterClass::NoFormat:
|
||||
m_formattersClasses[name] = new AWNoFormatter(this, filePath);
|
||||
break;
|
||||
@ -227,16 +236,15 @@ void AWFormatterHelper::initKeys()
|
||||
m_formatters.clear();
|
||||
|
||||
QStringList configs = QStandardPaths::locateAll(
|
||||
QStandardPaths::GenericDataLocation,
|
||||
QString("awesomewidgets/formatters/formatters.ini"));
|
||||
QStandardPaths::GenericDataLocation, m_filePath);
|
||||
|
||||
for (auto fileName : configs) {
|
||||
for (auto &fileName : configs) {
|
||||
QSettings settings(fileName, QSettings::IniFormat);
|
||||
qCInfo(LOG_AW) << "Configuration file" << settings.fileName();
|
||||
|
||||
settings.beginGroup(QString("Formatters"));
|
||||
settings.beginGroup("Formatters");
|
||||
QStringList keys = settings.childKeys();
|
||||
for (auto key : keys) {
|
||||
for (auto &key : keys) {
|
||||
QString name = settings.value(key).toString();
|
||||
qCInfo(LOG_AW) << "Found formatter" << name << "for key" << key
|
||||
<< "in" << settings.fileName();
|
||||
@ -245,8 +253,8 @@ void AWFormatterHelper::initKeys()
|
||||
continue;
|
||||
}
|
||||
if (!m_formattersClasses.contains(name)) {
|
||||
qCWarning(LOG_AW) << "Invalid formatter" << name << "found in"
|
||||
<< key;
|
||||
qCWarning(LOG_AW)
|
||||
<< "Invalid formatter" << name << "found in" << key;
|
||||
continue;
|
||||
}
|
||||
m_formatters[key] = m_formattersClasses[name];
|
||||
@ -267,21 +275,20 @@ void AWFormatterHelper::installDirectories()
|
||||
qCInfo(LOG_AW) << "Created directory" << localDir;
|
||||
|
||||
m_directories = QStandardPaths::locateAll(
|
||||
QStandardPaths::GenericDataLocation,
|
||||
QString("awesomewidgets/formatters"), QStandardPaths::LocateDirectory);
|
||||
QStandardPaths::GenericDataLocation, "awesomewidgets/formatters",
|
||||
QStandardPaths::LocateDirectory);
|
||||
}
|
||||
|
||||
|
||||
QPair<QString, AWAbstractFormatter::FormatterClass>
|
||||
AWFormatterHelper::readMetadata(const QString filePath) const
|
||||
AWFormatterHelper::readMetadata(const QString &_filePath) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Read initial parameters from" << filePath;
|
||||
qCDebug(LOG_AW) << "Read initial parameters from" << _filePath;
|
||||
|
||||
QSettings settings(filePath, QSettings::IniFormat);
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
QString name = settings.value(QString("Name"), filePath).toString();
|
||||
QString type
|
||||
= settings.value(QString("X-AW-Type"), QString("NoFormat")).toString();
|
||||
QSettings settings(_filePath, QSettings::IniFormat);
|
||||
settings.beginGroup("Desktop Entry");
|
||||
QString name = settings.value("Name", _filePath).toString();
|
||||
QString type = settings.value("X-AW-Type", "NoFormat").toString();
|
||||
AWAbstractFormatter::FormatterClass formatter = defineFormatterClass(type);
|
||||
settings.endGroup();
|
||||
|
||||
@ -291,10 +298,13 @@ AWFormatterHelper::readMetadata(const QString filePath) const
|
||||
|
||||
void AWFormatterHelper::doCreateItem()
|
||||
{
|
||||
QStringList selection = QStringList()
|
||||
<< QString("NoFormat") << QString("DateTime")
|
||||
<< QString("Float") << QString("List")
|
||||
<< QString("Script") << QString("String");
|
||||
QStringList selection = QStringList() << "NoFormat"
|
||||
<< "DateTime"
|
||||
<< "Float"
|
||||
<< "List"
|
||||
<< "Script"
|
||||
<< "String"
|
||||
<< "Json";
|
||||
bool ok;
|
||||
QString select = QInputDialog::getItem(
|
||||
this, i18n("Select type"), i18n("Type:"), selection, 0, false, &ok);
|
||||
@ -317,6 +327,8 @@ void AWFormatterHelper::doCreateItem()
|
||||
return createItem<AWScriptFormatter>();
|
||||
case AWAbstractFormatter::FormatterClass::String:
|
||||
return createItem<AWStringFormatter>();
|
||||
case AWAbstractFormatter::FormatterClass::Json:
|
||||
return createItem<AWJsonFormatter>();
|
||||
case AWAbstractFormatter::FormatterClass::NoFormat:
|
||||
return createItem<AWNoFormatter>();
|
||||
}
|
||||
|
@ -31,15 +31,15 @@ class AWFormatterHelper : public AbstractExtItemAggregator
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AWFormatterHelper(QWidget *parent = nullptr);
|
||||
explicit AWFormatterHelper(QWidget *_parent = nullptr);
|
||||
virtual ~AWFormatterHelper();
|
||||
QString convert(const QVariant &value, const QString &name) const;
|
||||
QString convert(const QVariant &_value, const QString &_name) const;
|
||||
QStringList definedFormatters() const;
|
||||
QHash<QString, QString> getFormatters() const;
|
||||
QList<AbstractExtItem *> items() const;
|
||||
QStringList knownFormatters() const;
|
||||
bool writeFormatters(const QStringList keys) const;
|
||||
bool writeFormatters(const QHash<QString, QString> configuration) const;
|
||||
bool removeUnusedFormatters(const QStringList &_keys) const;
|
||||
bool writeFormatters(const QHash<QString, QString> &_configuration) const;
|
||||
|
||||
public slots:
|
||||
void editItems();
|
||||
@ -47,17 +47,18 @@ public slots:
|
||||
private:
|
||||
// methods
|
||||
AWAbstractFormatter::FormatterClass
|
||||
defineFormatterClass(const QString stringType) const;
|
||||
defineFormatterClass(const QString &_stringType) const;
|
||||
void initFormatters();
|
||||
void initKeys();
|
||||
void installDirectories();
|
||||
QPair<QString, AWAbstractFormatter::FormatterClass>
|
||||
readMetadata(const QString filePath) const;
|
||||
readMetadata(const QString &_filePath) const;
|
||||
// parent methods
|
||||
void doCreateItem();
|
||||
void initItems();
|
||||
// properties
|
||||
QStringList m_directories;
|
||||
QString m_filePath;
|
||||
QHash<QString, AWAbstractFormatter *> m_formatters;
|
||||
QHash<QString, AWAbstractFormatter *> m_formattersClasses;
|
||||
};
|
||||
|
@ -26,9 +26,9 @@
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
bool AWKeyCache::addKeyToCache(const QString type, const QString key)
|
||||
bool AWKeyCache::addKeyToCache(const QString &_type, const QString &_key)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Key" << key << "with type" << type;
|
||||
qCDebug(LOG_AW) << "Key" << _key << "with type" << _type;
|
||||
|
||||
QString fileName = QString("%1/awesomewidgets.ndx")
|
||||
.arg(QStandardPaths::writableLocation(
|
||||
@ -36,45 +36,45 @@ bool AWKeyCache::addKeyToCache(const QString type, const QString key)
|
||||
qCInfo(LOG_AW) << "Cache file" << fileName;
|
||||
QSettings cache(fileName, QSettings::IniFormat);
|
||||
|
||||
cache.beginGroup(type);
|
||||
cache.beginGroup(_type);
|
||||
QStringList cachedValues;
|
||||
for (auto number : cache.allKeys())
|
||||
for (auto &number : cache.allKeys())
|
||||
cachedValues.append(cache.value(number).toString());
|
||||
|
||||
if (type == QString("hdd")) {
|
||||
if (_type == "hdd") {
|
||||
QStringList allDevices
|
||||
= QDir(QString("/dev")).entryList(QDir::System, QDir::Name);
|
||||
QStringList devices
|
||||
= allDevices.filter(QRegExp(QString("^[hms]d[a-z]$")));
|
||||
for (auto dev : devices) {
|
||||
= QDir("/dev").entryList(QDir::System, QDir::Name);
|
||||
QStringList devices = allDevices.filter(QRegExp("^[hms]d[a-z]$"));
|
||||
for (auto &dev : devices) {
|
||||
QString device = QString("/dev/%1").arg(dev);
|
||||
if (cachedValues.contains(device))
|
||||
continue;
|
||||
qCInfo(LOG_AW) << "Found new key" << device << "for type" << type;
|
||||
qCInfo(LOG_AW) << "Found new key" << device << "for type" << _type;
|
||||
cachedValues.append(device);
|
||||
cache.setValue(
|
||||
QString("%1").arg(cache.allKeys().count(), 3, 10, QChar('0')),
|
||||
device);
|
||||
}
|
||||
} else if (type == QString("net")) {
|
||||
} else if (_type == "net") {
|
||||
QList<QNetworkInterface> rawInterfaceList
|
||||
= QNetworkInterface::allInterfaces();
|
||||
for (auto interface : rawInterfaceList) {
|
||||
for (auto &interface : rawInterfaceList) {
|
||||
QString device = interface.name();
|
||||
if (cachedValues.contains(device))
|
||||
continue;
|
||||
qCInfo(LOG_AW) << "Found new key" << device << "for type" << type;
|
||||
qCInfo(LOG_AW) << "Found new key" << device << "for type" << _type;
|
||||
cachedValues.append(device);
|
||||
cache.setValue(
|
||||
QString("%1").arg(cache.allKeys().count(), 3, 10, QChar('0')),
|
||||
device);
|
||||
}
|
||||
} else {
|
||||
if (cachedValues.contains(key))
|
||||
if (cachedValues.contains(_key))
|
||||
return false;
|
||||
qCInfo(LOG_AW) << "Found new key" << key << "for type" << type;
|
||||
qCInfo(LOG_AW) << "Found new key" << _key << "for type" << _type;
|
||||
cache.setValue(
|
||||
QString("%1").arg(cache.allKeys().count(), 3, 10, QChar('0')), key);
|
||||
QString("%1").arg(cache.allKeys().count(), 3, 10, QChar('0')),
|
||||
_key);
|
||||
}
|
||||
cache.endGroup();
|
||||
|
||||
@ -83,86 +83,89 @@ bool AWKeyCache::addKeyToCache(const QString type, const QString key)
|
||||
}
|
||||
|
||||
|
||||
QStringList AWKeyCache::getRequiredKeys(const QStringList &keys,
|
||||
const QStringList &bars,
|
||||
const QVariantMap &tooltip,
|
||||
const QStringList &allKeys)
|
||||
QStringList AWKeyCache::getRequiredKeys(const QStringList &_keys,
|
||||
const QStringList &_bars,
|
||||
const QVariantMap &_tooltip,
|
||||
const QStringList &_allKeys)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Looking for required keys in" << keys << bars
|
||||
<< "using tooltip settings" << tooltip;
|
||||
qCDebug(LOG_AW) << "Looking for required keys in" << _keys << _bars
|
||||
<< "using tooltip settings" << _tooltip;
|
||||
|
||||
// initial copy
|
||||
QSet<QString> used = QSet<QString>::fromList(keys);
|
||||
used.unite(QSet<QString>::fromList(bars));
|
||||
QSet<QString> used = QSet<QString>::fromList(_keys);
|
||||
used.unite(QSet<QString>::fromList(_bars));
|
||||
// insert keys from tooltip
|
||||
for (auto key : tooltip.keys()) {
|
||||
if ((key.endsWith(QString("Tooltip"))) && (tooltip[key].toBool())) {
|
||||
key.remove(QString("Tooltip"));
|
||||
for (auto &key : _tooltip.keys()) {
|
||||
if ((key.endsWith("Tooltip")) && (_tooltip[key].toBool())) {
|
||||
key.remove("Tooltip");
|
||||
used << key;
|
||||
}
|
||||
}
|
||||
|
||||
// insert depending keys, refer to AWKeys::calculateValues()
|
||||
// hddtotmb*
|
||||
for (auto key : allKeys.filter(QRegExp(QString("^hddtotmb")))) {
|
||||
for (auto &key : _allKeys.filter(QRegExp("^hddtotmb"))) {
|
||||
if (!used.contains(key))
|
||||
continue;
|
||||
key.remove(QString("hddtotmb"));
|
||||
key.remove("hddtotmb");
|
||||
int index = key.toInt();
|
||||
used << QString("hddfreemb%1").arg(index)
|
||||
<< QString("hddmb%1").arg(index);
|
||||
}
|
||||
// hddtotgb*
|
||||
for (auto key : allKeys.filter(QRegExp(QString("^hddtotgb")))) {
|
||||
for (auto &key : _allKeys.filter(QRegExp("^hddtotgb"))) {
|
||||
if (!used.contains(key))
|
||||
continue;
|
||||
key.remove(QString("hddtotgb"));
|
||||
key.remove("hddtotgb");
|
||||
int index = key.toInt();
|
||||
used << QString("hddfreegb%1").arg(index)
|
||||
<< QString("hddgb%1").arg(index);
|
||||
}
|
||||
// mem
|
||||
if (used.contains(QString("mem")))
|
||||
used << QString("memmb") << QString("memtotmb");
|
||||
if (used.contains("mem"))
|
||||
used << "memmb"
|
||||
<< "memtotmb";
|
||||
// memtotmb
|
||||
if (used.contains(QString("memtotmb")))
|
||||
used << QString("memusedmb") << QString("memfreemb");
|
||||
if (used.contains("memtotmb"))
|
||||
used << "memusedmb"
|
||||
<< "memfreemb";
|
||||
// memtotgb
|
||||
if (used.contains(QString("memtotgb")))
|
||||
used << QString("memusedgb") << QString("memfreegb");
|
||||
if (used.contains("memtotgb"))
|
||||
used << "memusedgb"
|
||||
<< "memfreegb";
|
||||
// swap
|
||||
if (used.contains(QString("swap")))
|
||||
used << QString("swapmb") << QString("swaptotmb");
|
||||
if (used.contains("swap"))
|
||||
used << "swapmb"
|
||||
<< "swaptotmb";
|
||||
// swaptotmb
|
||||
if (used.contains(QString("swaptotmb")))
|
||||
used << QString("swapmb") << QString("swapfreemb");
|
||||
if (used.contains("swaptotmb"))
|
||||
used << "swapmb"
|
||||
<< "swapfreemb";
|
||||
// memtotgb
|
||||
if (used.contains(QString("swaptotgb")))
|
||||
used << QString("swapgb") << QString("swapfreegb");
|
||||
if (used.contains("swaptotgb"))
|
||||
used << "swapgb"
|
||||
<< "swapfreegb";
|
||||
// network keys
|
||||
QStringList netKeys(QStringList()
|
||||
<< QString("up") << QString("upkb")
|
||||
<< QString("uptotal") << QString("uptotalkb")
|
||||
<< QString("upunits") << QString("down")
|
||||
<< QString("downkb") << QString("downtotal")
|
||||
<< QString("downtotalkb") << QString("downunits"));
|
||||
for (auto key : netKeys) {
|
||||
QStringList netKeys({"up", "upkb", "uptotal", "uptotalkb", "upunits",
|
||||
"down", "downkb", "downtotal", "downtotalkb",
|
||||
"downunits"});
|
||||
for (auto &key : netKeys) {
|
||||
if (!used.contains(key))
|
||||
continue;
|
||||
QStringList filt
|
||||
= allKeys.filter(QRegExp(QString("^%1[0-9]{1,}").arg(key)));
|
||||
for (auto filtered : filt)
|
||||
= _allKeys.filter(QRegExp(QString("^%1[0-9]{1,}").arg(key)));
|
||||
for (auto &filtered : filt)
|
||||
used << filtered;
|
||||
}
|
||||
// netdev key
|
||||
if (std::any_of(netKeys.cbegin(), netKeys.cend(),
|
||||
[&used](const QString &key) { return used.contains(key); }))
|
||||
used << QString("netdev");
|
||||
used << "netdev";
|
||||
|
||||
// HACK append dummy if there are no other keys. This hack is required
|
||||
// because empty list leads to the same behaviour as skip checking
|
||||
if (used.isEmpty())
|
||||
used << QString("dummy");
|
||||
used << "dummy";
|
||||
|
||||
return used.toList();
|
||||
}
|
||||
@ -177,9 +180,9 @@ QHash<QString, QStringList> AWKeyCache::loadKeysFromCache()
|
||||
QSettings cache(fileName, QSettings::IniFormat);
|
||||
|
||||
QHash<QString, QStringList> devices;
|
||||
for (auto group : cache.childGroups()) {
|
||||
for (auto &group : cache.childGroups()) {
|
||||
cache.beginGroup(group);
|
||||
for (auto key : cache.allKeys())
|
||||
for (auto &key : cache.allKeys())
|
||||
devices[group].append(cache.value(key).toString());
|
||||
cache.endGroup();
|
||||
}
|
||||
|
@ -26,10 +26,10 @@
|
||||
|
||||
namespace AWKeyCache
|
||||
{
|
||||
bool addKeyToCache(const QString type, const QString key = QString(""));
|
||||
QStringList getRequiredKeys(const QStringList &keys, const QStringList &bars,
|
||||
const QVariantMap &tooltip,
|
||||
const QStringList &allKeys);
|
||||
bool addKeyToCache(const QString &_type, const QString &_key = "");
|
||||
QStringList getRequiredKeys(const QStringList &_keys, const QStringList &_bars,
|
||||
const QVariantMap &_tooltip,
|
||||
const QStringList &_allKeys);
|
||||
QHash<QString, QStringList> loadKeysFromCache();
|
||||
};
|
||||
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "awkeycache.h"
|
||||
#include "awpatternfunctions.h"
|
||||
// extensions
|
||||
#include "extnetworkrequest.h"
|
||||
#include "extquotes.h"
|
||||
#include "extscript.h"
|
||||
#include "extupgrade.h"
|
||||
@ -33,8 +34,8 @@
|
||||
#include "graphicalitem.h"
|
||||
|
||||
|
||||
AWKeyOperations::AWKeyOperations(QObject *parent)
|
||||
: QObject(parent)
|
||||
AWKeyOperations::AWKeyOperations(QObject *_parent)
|
||||
: QObject(_parent)
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
}
|
||||
@ -46,6 +47,7 @@ AWKeyOperations::~AWKeyOperations()
|
||||
|
||||
// extensions
|
||||
delete m_graphicalItems;
|
||||
delete m_extNetRequest;
|
||||
delete m_extQuotes;
|
||||
delete m_extScripts;
|
||||
delete m_extUpgrade;
|
||||
@ -53,11 +55,11 @@ AWKeyOperations::~AWKeyOperations()
|
||||
}
|
||||
|
||||
|
||||
QStringList AWKeyOperations::devices(const QString type) const
|
||||
QStringList AWKeyOperations::devices(const QString &_type) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Looking for type" << type;
|
||||
qCDebug(LOG_AW) << "Looking for type" << _type;
|
||||
|
||||
return m_devices[type];
|
||||
return m_devices[_type];
|
||||
}
|
||||
|
||||
|
||||
@ -70,8 +72,8 @@ QHash<QString, QStringList> AWKeyOperations::devices() const
|
||||
void AWKeyOperations::updateCache()
|
||||
{
|
||||
// update network and hdd list
|
||||
addKeyToCache(QString("hdd"));
|
||||
addKeyToCache(QString("net"));
|
||||
addKeyToCache("hdd");
|
||||
addKeyToCache("net");
|
||||
}
|
||||
|
||||
|
||||
@ -79,30 +81,24 @@ QStringList AWKeyOperations::dictKeys() const
|
||||
{
|
||||
QStringList allKeys;
|
||||
// weather
|
||||
for (int i = m_extWeather->activeItems().count() - 1; i >= 0; i--) {
|
||||
allKeys.append(
|
||||
m_extWeather->activeItems().at(i)->tag(QString("weatherId")));
|
||||
allKeys.append(
|
||||
m_extWeather->activeItems().at(i)->tag(QString("weather")));
|
||||
allKeys.append(
|
||||
m_extWeather->activeItems().at(i)->tag(QString("humidity")));
|
||||
allKeys.append(
|
||||
m_extWeather->activeItems().at(i)->tag(QString("pressure")));
|
||||
allKeys.append(
|
||||
m_extWeather->activeItems().at(i)->tag(QString("temperature")));
|
||||
allKeys.append(
|
||||
m_extWeather->activeItems().at(i)->tag(QString("timestamp")));
|
||||
for (auto &item : m_extWeather->activeItems()) {
|
||||
allKeys.append(item->tag("weatherId"));
|
||||
allKeys.append(item->tag("weather"));
|
||||
allKeys.append(item->tag("humidity"));
|
||||
allKeys.append(item->tag("pressure"));
|
||||
allKeys.append(item->tag("temperature"));
|
||||
allKeys.append(item->tag("timestamp"));
|
||||
}
|
||||
// cpuclock & cpu
|
||||
for (int i = QThread::idealThreadCount() - 1; i >= 0; i--) {
|
||||
for (int i = 0; i < QThread::idealThreadCount(); i++) {
|
||||
allKeys.append(QString("cpucl%1").arg(i));
|
||||
allKeys.append(QString("cpu%1").arg(i));
|
||||
}
|
||||
// temperature
|
||||
for (int i = m_devices[QString("temp")].count() - 1; i >= 0; i--)
|
||||
for (int i = 0; i < m_devices["temp"].count(); i++)
|
||||
allKeys.append(QString("temp%1").arg(i));
|
||||
// hdd
|
||||
for (int i = m_devices[QString("mount")].count() - 1; i >= 0; i--) {
|
||||
for (int i = 0; i < m_devices["mount"].count(); i++) {
|
||||
allKeys.append(QString("hddmb%1").arg(i));
|
||||
allKeys.append(QString("hddgb%1").arg(i));
|
||||
allKeys.append(QString("hddfreemb%1").arg(i));
|
||||
@ -112,15 +108,15 @@ QStringList AWKeyOperations::dictKeys() const
|
||||
allKeys.append(QString("hdd%1").arg(i));
|
||||
}
|
||||
// hdd speed
|
||||
for (int i = m_devices[QString("disk")].count() - 1; i >= 0; i--) {
|
||||
for (int i = 0; i < m_devices["disk"].count(); i++) {
|
||||
allKeys.append(QString("hddr%1").arg(i));
|
||||
allKeys.append(QString("hddw%1").arg(i));
|
||||
}
|
||||
// hdd temp
|
||||
for (int i = m_devices[QString("hdd")].count() - 1; i >= 0; i--)
|
||||
for (int i = 0; i < m_devices["hdd"].count(); i++)
|
||||
allKeys.append(QString("hddtemp%1").arg(i));
|
||||
// network
|
||||
for (int i = m_devices[QString("net")].count() - 1; i >= 0; i--) {
|
||||
for (int i = 0; i < m_devices["net"].count(); i++) {
|
||||
allKeys.append(QString("downunits%1").arg(i));
|
||||
allKeys.append(QString("upunits%1").arg(i));
|
||||
allKeys.append(QString("downtotalkb%1").arg(i));
|
||||
@ -134,45 +130,41 @@ QStringList AWKeyOperations::dictKeys() const
|
||||
}
|
||||
// battery
|
||||
QStringList allBatteryDevices
|
||||
= QDir(QString("/sys/class/power_supply"))
|
||||
.entryList(QStringList() << QString("BAT*"),
|
||||
= QDir("/sys/class/power_supply")
|
||||
.entryList(QStringList({"BAT*"}),
|
||||
QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name);
|
||||
for (int i = allBatteryDevices.count() - 1; i >= 0; i--)
|
||||
for (int i = 0; i < allBatteryDevices.count(); i++)
|
||||
allKeys.append(QString("bat%1").arg(i));
|
||||
// package manager
|
||||
for (int i = m_extUpgrade->activeItems().count() - 1; i >= 0; i--)
|
||||
allKeys.append(
|
||||
m_extUpgrade->activeItems().at(i)->tag(QString("pkgcount")));
|
||||
for (auto &item : m_extUpgrade->activeItems())
|
||||
allKeys.append(item->tag("pkgcount"));
|
||||
// quotes
|
||||
for (int i = m_extQuotes->activeItems().count() - 1; i >= 0; i--) {
|
||||
allKeys.append(m_extQuotes->activeItems().at(i)->tag(QString("ask")));
|
||||
allKeys.append(
|
||||
m_extQuotes->activeItems().at(i)->tag(QString("askchg")));
|
||||
allKeys.append(
|
||||
m_extQuotes->activeItems().at(i)->tag(QString("percaskchg")));
|
||||
allKeys.append(m_extQuotes->activeItems().at(i)->tag(QString("bid")));
|
||||
allKeys.append(
|
||||
m_extQuotes->activeItems().at(i)->tag(QString("bidchg")));
|
||||
allKeys.append(
|
||||
m_extQuotes->activeItems().at(i)->tag(QString("percbidchg")));
|
||||
allKeys.append(m_extQuotes->activeItems().at(i)->tag(QString("price")));
|
||||
allKeys.append(
|
||||
m_extQuotes->activeItems().at(i)->tag(QString("pricechg")));
|
||||
allKeys.append(
|
||||
m_extQuotes->activeItems().at(i)->tag(QString("percpricechg")));
|
||||
for (auto &item : m_extQuotes->activeItems()) {
|
||||
allKeys.append(item->tag("ask"));
|
||||
allKeys.append(item->tag("askchg"));
|
||||
allKeys.append(item->tag("percaskchg"));
|
||||
allKeys.append(item->tag("bid"));
|
||||
allKeys.append(item->tag("bidchg"));
|
||||
allKeys.append(item->tag("percbidchg"));
|
||||
allKeys.append(item->tag("price"));
|
||||
allKeys.append(item->tag("pricechg"));
|
||||
allKeys.append(item->tag("percpricechg"));
|
||||
}
|
||||
// custom
|
||||
for (int i = m_extScripts->activeItems().count() - 1; i >= 0; i--)
|
||||
allKeys.append(
|
||||
m_extScripts->activeItems().at(i)->tag(QString("custom")));
|
||||
for (auto &item : m_extScripts->activeItems())
|
||||
allKeys.append(item->tag("custom"));
|
||||
// network requests
|
||||
for (auto &item : m_extNetRequest->activeItems())
|
||||
allKeys.append(item->tag("response"));
|
||||
// bars
|
||||
for (int i = m_graphicalItems->activeItems().count() - 1; i >= 0; i--)
|
||||
allKeys.append(
|
||||
m_graphicalItems->activeItems().at(i)->tag(QString("bar")));
|
||||
for (auto &item : m_graphicalItems->activeItems())
|
||||
allKeys.append(item->tag("bar"));
|
||||
// static keys
|
||||
QStringList staticKeys = QString(STATIC_KEYS).split(QChar(','));
|
||||
std::for_each(staticKeys.cbegin(), staticKeys.cend(),
|
||||
[&allKeys](const QString &key) { allKeys.append(key); });
|
||||
allKeys.append(QString(STATIC_KEYS).split(','));
|
||||
|
||||
// sort in valid order
|
||||
allKeys.sort();
|
||||
std::reverse(allKeys.begin(), allKeys.end());
|
||||
|
||||
return allKeys;
|
||||
}
|
||||
@ -180,66 +172,70 @@ QStringList AWKeyOperations::dictKeys() const
|
||||
|
||||
// this method is required to provide GraphicalItem functions (e.g. paint()) to
|
||||
// parent classes
|
||||
GraphicalItem *AWKeyOperations::giByKey(const QString key) const
|
||||
GraphicalItem *AWKeyOperations::giByKey(const QString &_key) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Looking for item" << key;
|
||||
qCDebug(LOG_AW) << "Looking for item" << _key;
|
||||
|
||||
return m_graphicalItems->itemByTag(key, QString("bar"));
|
||||
return m_graphicalItems->itemByTag(_key, "bar");
|
||||
}
|
||||
|
||||
|
||||
QString AWKeyOperations::infoByKey(QString key) const
|
||||
QString AWKeyOperations::infoByKey(const QString &_key) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Requested key" << key;
|
||||
qCDebug(LOG_AW) << "Requested key" << _key;
|
||||
|
||||
QString stripped = key;
|
||||
stripped.remove(QRegExp(QString("\\d+")));
|
||||
QString stripped = _key;
|
||||
stripped.remove(QRegExp("\\d+"));
|
||||
QString output;
|
||||
|
||||
if (key.startsWith(QString("bar"))) {
|
||||
AbstractExtItem *item = m_graphicalItems->itemByTag(key, stripped);
|
||||
if (_key.startsWith("bar")) {
|
||||
AbstractExtItem *item = m_graphicalItems->itemByTag(_key, stripped);
|
||||
if (item)
|
||||
output = item->uniq();
|
||||
} else if (key.startsWith(QString("custom"))) {
|
||||
AbstractExtItem *item = m_extScripts->itemByTag(key, stripped);
|
||||
} else if (_key.startsWith("custom")) {
|
||||
AbstractExtItem *item = m_extScripts->itemByTag(_key, stripped);
|
||||
if (item)
|
||||
output = item->uniq();
|
||||
} else if (key.contains(QRegExp(QString("^hdd[rw]")))) {
|
||||
output = m_devices[QString("disk")]
|
||||
[key.remove(QRegExp(QString("hdd[rw]"))).toInt()];
|
||||
} else if (key.contains(QRegExp(
|
||||
QString("^hdd([0-9]|mb|gb|freemb|freegb|totmb|totgb)")))) {
|
||||
output
|
||||
= m_devices[QString("mount")]
|
||||
[key
|
||||
.remove(QRegExp(QString(
|
||||
"^hdd([0-9]|mb|gb|freemb|freegb|totmb|totgb)")))
|
||||
.toInt()];
|
||||
} else if (key.startsWith(QString("hddtemp"))) {
|
||||
output
|
||||
= m_devices[QString("hdd")][key.remove(QString("hddtemp")).toInt()];
|
||||
} else if (key.contains(QRegExp(QString("^(down|up)[0-9]")))) {
|
||||
output = m_devices[QString("net")]
|
||||
[key.remove(QRegExp(QString("^(down|up)"))).toInt()];
|
||||
} else if (key.startsWith(QString("pkgcount"))) {
|
||||
AbstractExtItem *item = m_extUpgrade->itemByTag(key, stripped);
|
||||
} else if (_key.contains(QRegExp("^hdd[rw]"))) {
|
||||
QString index = _key;
|
||||
index.remove(QRegExp("hdd[rw]"));
|
||||
output = m_devices["disk"][index.toInt()];
|
||||
} else if (_key.contains(
|
||||
QRegExp("^hdd([0-9]|mb|gb|freemb|freegb|totmb|totgb)"))) {
|
||||
QString index = _key;
|
||||
index.remove(QRegExp("^hdd(|mb|gb|freemb|freegb|totmb|totgb)"));
|
||||
output = m_devices["mount"][index.toInt()];
|
||||
} else if (_key.startsWith("hddtemp")) {
|
||||
QString index = _key;
|
||||
index.remove("hddtemp");
|
||||
output = m_devices["hdd"][index.toInt()];
|
||||
} else if (_key.contains(QRegExp("^(down|up)[0-9]"))) {
|
||||
QString index = _key;
|
||||
index.remove(QRegExp("^(down|up)"));
|
||||
output = m_devices["net"][index.toInt()];
|
||||
} else if (_key.startsWith("pkgcount")) {
|
||||
AbstractExtItem *item = m_extUpgrade->itemByTag(_key, stripped);
|
||||
if (item)
|
||||
output = item->uniq();
|
||||
} else if (key.contains(
|
||||
QRegExp(QString("(^|perc)(ask|bid|price)(chg|)")))) {
|
||||
AbstractExtItem *item = m_extQuotes->itemByTag(key, stripped);
|
||||
} else if (_key.contains(QRegExp("(^|perc)(ask|bid|price)(chg|)"))) {
|
||||
AbstractExtItem *item = m_extQuotes->itemByTag(_key, stripped);
|
||||
if (item)
|
||||
output = item->uniq();
|
||||
} else if (key.contains(QRegExp(QString(
|
||||
"(weather|weatherId|humidity|pressure|temperature)")))) {
|
||||
AbstractExtItem *item = m_extWeather->itemByTag(key, stripped);
|
||||
} else if (_key.contains(QRegExp(
|
||||
"(weather|weatherId|humidity|pressure|temperature)"))) {
|
||||
AbstractExtItem *item = m_extWeather->itemByTag(_key, stripped);
|
||||
if (item)
|
||||
output = item->uniq();
|
||||
} else if (_key.startsWith("temp")) {
|
||||
QString index = _key;
|
||||
index.remove("temp");
|
||||
output = m_devices["temp"][index.toInt()];
|
||||
} else if (_key.startsWith("response")) {
|
||||
AbstractExtItem *item = m_extNetRequest->itemByTag(_key, stripped);
|
||||
if (item)
|
||||
output = item->uniq();
|
||||
} else if (key.startsWith(QString("temp"))) {
|
||||
output
|
||||
= m_devices[QString("temp")][key.remove(QString("temp")).toInt()];
|
||||
} else {
|
||||
output = QString("(none)");
|
||||
output = "(none)";
|
||||
}
|
||||
|
||||
return output;
|
||||
@ -252,63 +248,64 @@ QString AWKeyOperations::pattern() const
|
||||
}
|
||||
|
||||
|
||||
void AWKeyOperations::setPattern(const QString currentPattern)
|
||||
void AWKeyOperations::setPattern(const QString &_currentPattern)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Set pattern" << currentPattern;
|
||||
qCDebug(LOG_AW) << "Set pattern" << _currentPattern;
|
||||
|
||||
m_pattern = currentPattern;
|
||||
m_pattern = _currentPattern;
|
||||
}
|
||||
|
||||
|
||||
void AWKeyOperations::editItem(const QString type)
|
||||
void AWKeyOperations::editItem(const QString &_type)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Item type" << type;
|
||||
qCDebug(LOG_AW) << "Item type" << _type;
|
||||
|
||||
if (type == QString("graphicalitem")) {
|
||||
QStringList keys = dictKeys().filter(QRegExp(
|
||||
QString("^(cpu(?!cl).*|gpu$|mem$|swap$|hdd[0-9].*|bat.*)")));
|
||||
if (_type == "graphicalitem") {
|
||||
QStringList keys = dictKeys().filter(
|
||||
QRegExp("^(cpu(?!cl).*|gpu$|mem$|swap$|hdd[0-9].*|bat.*)"));
|
||||
keys.sort();
|
||||
m_graphicalItems->setConfigArgs(keys);
|
||||
return m_graphicalItems->editItems();
|
||||
} else if (type == QString("extquotes")) {
|
||||
} else if (_type == "extnetworkrequest") {
|
||||
return m_extNetRequest->editItems();
|
||||
} else if (_type == "extquotes") {
|
||||
return m_extQuotes->editItems();
|
||||
} else if (type == QString("extscript")) {
|
||||
} else if (_type == "extscript") {
|
||||
return m_extScripts->editItems();
|
||||
} else if (type == QString("extupgrade")) {
|
||||
} else if (_type == "extupgrade") {
|
||||
return m_extUpgrade->editItems();
|
||||
} else if (type == QString("extweather")) {
|
||||
} else if (_type == "extweather") {
|
||||
return m_extWeather->editItems();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AWKeyOperations::addDevice(const QString &source)
|
||||
void AWKeyOperations::addDevice(const QString &_source)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Source" << source;
|
||||
qCDebug(LOG_AW) << "Source" << _source;
|
||||
|
||||
QRegExp diskRegexp
|
||||
= QRegExp(QString("disk/(?:md|sd|hd)[a-z|0-9]_.*/Rate/(?:rblk)"));
|
||||
QRegExp mountRegexp = QRegExp(QString("partitions/.*/filllevel"));
|
||||
QRegExp diskRegexp = QRegExp("disk/(?:md|sd|hd)[a-z|0-9]_.*/Rate/(?:rblk)");
|
||||
QRegExp mountRegexp = QRegExp("partitions/.*/filllevel");
|
||||
|
||||
if (source.contains(diskRegexp)) {
|
||||
QString device = source;
|
||||
device.remove(QString("/Rate/rblk"));
|
||||
addKeyToCache(QString("disk"), device);
|
||||
} else if (source.contains(mountRegexp)) {
|
||||
QString device = source;
|
||||
device.remove(QString("partitions")).remove(QString("/filllevel"));
|
||||
addKeyToCache(QString("mount"), device);
|
||||
} else if (source.startsWith(QString("lmsensors"))) {
|
||||
addKeyToCache(QString("temp"), source);
|
||||
if (_source.contains(diskRegexp)) {
|
||||
QString device = _source;
|
||||
device.remove("/Rate/rblk");
|
||||
addKeyToCache("disk", device);
|
||||
} else if (_source.contains(mountRegexp)) {
|
||||
QString device = _source;
|
||||
device.remove("partitions").remove("/filllevel");
|
||||
addKeyToCache("mount", device);
|
||||
} else if (_source.startsWith("lmsensors")) {
|
||||
addKeyToCache("temp", _source);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AWKeyOperations::addKeyToCache(const QString type, const QString key)
|
||||
void AWKeyOperations::addKeyToCache(const QString &_type, const QString &_key)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Key" << key << "with type" << type;
|
||||
qCDebug(LOG_AW) << "Key" << _key << "with type" << _type;
|
||||
|
||||
if (AWKeyCache::addKeyToCache(type, key)) {
|
||||
if (AWKeyCache::addKeyToCache(_type, _key)) {
|
||||
m_devices = AWKeyCache::loadKeysFromCache();
|
||||
reinitKeys();
|
||||
}
|
||||
@ -321,6 +318,8 @@ void AWKeyOperations::reinitKeys()
|
||||
// delete them if any
|
||||
delete m_graphicalItems;
|
||||
m_graphicalItems = nullptr;
|
||||
delete m_extNetRequest;
|
||||
m_extNetRequest = nullptr;
|
||||
delete m_extQuotes;
|
||||
m_extQuotes = nullptr;
|
||||
delete m_extScripts;
|
||||
@ -331,14 +330,13 @@ void AWKeyOperations::reinitKeys()
|
||||
m_extWeather = nullptr;
|
||||
// create
|
||||
m_graphicalItems
|
||||
= new ExtItemAggregator<GraphicalItem>(nullptr, QString("desktops"));
|
||||
m_extQuotes = new ExtItemAggregator<ExtQuotes>(nullptr, QString("quotes"));
|
||||
m_extScripts
|
||||
= new ExtItemAggregator<ExtScript>(nullptr, QString("scripts"));
|
||||
m_extUpgrade
|
||||
= new ExtItemAggregator<ExtUpgrade>(nullptr, QString("upgrade"));
|
||||
m_extWeather
|
||||
= new ExtItemAggregator<ExtWeather>(nullptr, QString("weather"));
|
||||
= new ExtItemAggregator<GraphicalItem>(nullptr, "desktops");
|
||||
m_extNetRequest
|
||||
= new ExtItemAggregator<ExtNetworkRequest>(nullptr, "requests");
|
||||
m_extQuotes = new ExtItemAggregator<ExtQuotes>(nullptr, "quotes");
|
||||
m_extScripts = new ExtItemAggregator<ExtScript>(nullptr, "scripts");
|
||||
m_extUpgrade = new ExtItemAggregator<ExtUpgrade>(nullptr, "upgrade");
|
||||
m_extWeather = new ExtItemAggregator<ExtWeather>(nullptr, "weather");
|
||||
|
||||
// init
|
||||
QStringList allKeys = dictKeys();
|
||||
|
@ -30,6 +30,7 @@
|
||||
class AWDataAggregator;
|
||||
class AWDataEngineAggregator;
|
||||
class AWKeysAggregator;
|
||||
class ExtNetworkRequest;
|
||||
class ExtQuotes;
|
||||
class ExtScript;
|
||||
class ExtUpgrade;
|
||||
@ -43,33 +44,34 @@ class AWKeyOperations : public QObject
|
||||
Q_PROPERTY(QString pattern READ pattern WRITE setPattern)
|
||||
|
||||
public:
|
||||
explicit AWKeyOperations(QObject *parent = nullptr);
|
||||
explicit AWKeyOperations(QObject *_parent = nullptr);
|
||||
virtual ~AWKeyOperations();
|
||||
QStringList devices(const QString type) const;
|
||||
QStringList devices(const QString &_type) const;
|
||||
QHash<QString, QStringList> devices() const;
|
||||
void updateCache();
|
||||
// keys
|
||||
QStringList dictKeys() const;
|
||||
GraphicalItem *giByKey(const QString key) const;
|
||||
GraphicalItem *giByKey(const QString &_key) const;
|
||||
// values
|
||||
QString infoByKey(QString key) const;
|
||||
QString infoByKey(const QString &_key) const;
|
||||
QString pattern() const;
|
||||
void setPattern(const QString currentPattern);
|
||||
void setPattern(const QString &_currentPattern);
|
||||
// configuration
|
||||
void editItem(const QString type);
|
||||
void editItem(const QString &_type);
|
||||
|
||||
signals:
|
||||
void updateKeys(const QStringList currentKeys);
|
||||
void updateKeys(const QStringList &_currentKeys);
|
||||
|
||||
public slots:
|
||||
void addDevice(const QString &source);
|
||||
void addDevice(const QString &_source);
|
||||
|
||||
private:
|
||||
// methods
|
||||
void addKeyToCache(const QString type, const QString key = QString(""));
|
||||
void addKeyToCache(const QString &_type, const QString &_key = "");
|
||||
void reinitKeys();
|
||||
// objects
|
||||
ExtItemAggregator<GraphicalItem> *m_graphicalItems = nullptr;
|
||||
ExtItemAggregator<ExtNetworkRequest> *m_extNetRequest = nullptr;
|
||||
ExtItemAggregator<ExtQuotes> *m_extQuotes = nullptr;
|
||||
ExtItemAggregator<ExtScript> *m_extScripts = nullptr;
|
||||
ExtItemAggregator<ExtUpgrade> *m_extUpgrade = nullptr;
|
||||
|
@ -17,7 +17,8 @@
|
||||
|
||||
#include "awkeys.h"
|
||||
|
||||
#include <QJSEngine>
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusError>
|
||||
#include <QRegExp>
|
||||
#include <QThread>
|
||||
#include <QTimer>
|
||||
@ -25,6 +26,7 @@
|
||||
|
||||
#include "awdataaggregator.h"
|
||||
#include "awdataengineaggregator.h"
|
||||
#include "awdbusadaptor.h"
|
||||
#include "awdebug.h"
|
||||
#include "awkeycache.h"
|
||||
#include "awkeyoperations.h"
|
||||
@ -33,12 +35,12 @@
|
||||
#include "graphicalitem.h"
|
||||
|
||||
|
||||
AWKeys::AWKeys(QObject *parent)
|
||||
: QObject(parent)
|
||||
AWKeys::AWKeys(QObject *_parent)
|
||||
: QObject(_parent)
|
||||
{
|
||||
qSetMessagePattern(LOG_FORMAT);
|
||||
qSetMessagePattern(AWDebug::LOG_FORMAT);
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
for (auto metadata : getBuildData())
|
||||
for (auto &metadata : AWDebug::getBuildData())
|
||||
qCDebug(LOG_AW) << metadata;
|
||||
|
||||
// thread pool
|
||||
@ -52,15 +54,17 @@ AWKeys::AWKeys(QObject *parent)
|
||||
m_timer = new QTimer(this);
|
||||
m_timer->setSingleShot(false);
|
||||
|
||||
createDBusInterface();
|
||||
|
||||
// update key data if required
|
||||
connect(m_keyOperator, SIGNAL(updateKeys(QStringList)), this,
|
||||
SLOT(reinitKeys(QStringList)));
|
||||
connect(m_keyOperator, SIGNAL(updateKeys(const QStringList &)), this,
|
||||
SLOT(reinitKeys(const QStringList &)));
|
||||
connect(m_timer, SIGNAL(timeout()), this, SLOT(updateTextData()));
|
||||
// transfer signal from AWDataAggregator object to QML ui
|
||||
connect(m_dataAggregator, SIGNAL(toolTipPainted(const QString)), this,
|
||||
SIGNAL(needToolTipToBeUpdated(const QString)));
|
||||
connect(this, SIGNAL(dropSourceFromDataengine(QString)),
|
||||
m_dataEngineAggregator, SLOT(dropSource(QString)));
|
||||
connect(m_dataAggregator, SIGNAL(toolTipPainted(const QString &)), this,
|
||||
SIGNAL(needToolTipToBeUpdated(const QString &)));
|
||||
connect(this, SIGNAL(dropSourceFromDataengine(const QString &)),
|
||||
m_dataEngineAggregator, SLOT(dropSource(const QString &)));
|
||||
// transfer signal from dataengine to update source list
|
||||
connect(m_dataEngineAggregator, SIGNAL(deviceAdded(const QString &)),
|
||||
m_keyOperator, SLOT(addDevice(const QString &)));
|
||||
@ -74,6 +78,10 @@ AWKeys::~AWKeys()
|
||||
m_timer->stop();
|
||||
delete m_timer;
|
||||
|
||||
// delete dbus session
|
||||
qlonglong id = reinterpret_cast<qlonglong>(this);
|
||||
QDBusConnection::sessionBus().unregisterObject(QString("/%1").arg(id));
|
||||
|
||||
// core
|
||||
delete m_dataEngineAggregator;
|
||||
delete m_threadPool;
|
||||
@ -83,53 +91,59 @@ AWKeys::~AWKeys()
|
||||
}
|
||||
|
||||
|
||||
void AWKeys::initDataAggregator(const QVariantMap tooltipParams)
|
||||
bool AWKeys::isDBusActive() const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Tooltip parameters" << tooltipParams;
|
||||
return m_dbusActive;
|
||||
}
|
||||
|
||||
|
||||
void AWKeys::initDataAggregator(const QVariantMap &_tooltipParams)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Tooltip parameters" << _tooltipParams;
|
||||
|
||||
// store parameters to generate m_requiredKeys
|
||||
m_tooltipParams = tooltipParams;
|
||||
m_tooltipParams = _tooltipParams;
|
||||
m_dataAggregator->setParameters(m_tooltipParams);
|
||||
}
|
||||
|
||||
|
||||
void AWKeys::initKeys(const QString currentPattern, const int interval,
|
||||
const int limit, const bool optimize)
|
||||
void AWKeys::initKeys(const QString &_currentPattern, const int _interval,
|
||||
const int _limit, const bool _optimize)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Pattern" << currentPattern << "with interval"
|
||||
<< interval << "and queue limit" << limit
|
||||
<< "with optimization" << optimize;
|
||||
qCDebug(LOG_AW) << "Pattern" << _currentPattern << "with interval"
|
||||
<< _interval << "and queue limit" << _limit
|
||||
<< "with optimization" << _optimize;
|
||||
|
||||
// init
|
||||
m_optimize = optimize;
|
||||
m_threadPool->setMaxThreadCount(limit == 0 ? QThread::idealThreadCount()
|
||||
: limit);
|
||||
m_optimize = _optimize;
|
||||
m_threadPool->setMaxThreadCount(_limit == 0 ? QThread::idealThreadCount()
|
||||
: _limit);
|
||||
// child objects
|
||||
m_aggregator->initFormatters();
|
||||
m_keyOperator->setPattern(currentPattern);
|
||||
m_keyOperator->setPattern(_currentPattern);
|
||||
m_keyOperator->updateCache();
|
||||
m_dataEngineAggregator->clear();
|
||||
m_dataEngineAggregator->initDataEngines(interval);
|
||||
m_dataEngineAggregator->initDataEngines(_interval);
|
||||
|
||||
// timer
|
||||
m_timer->setInterval(interval);
|
||||
m_timer->setInterval(_interval);
|
||||
m_timer->start();
|
||||
}
|
||||
|
||||
|
||||
void AWKeys::setAggregatorProperty(const QString key, const QVariant value)
|
||||
void AWKeys::setAggregatorProperty(const QString &_key, const QVariant &_value)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Key" << key << "with value" << value;
|
||||
qCDebug(LOG_AW) << "Key" << _key << "with value" << _value;
|
||||
|
||||
m_aggregator->setProperty(key.toUtf8().constData(), value);
|
||||
m_aggregator->setProperty(_key.toUtf8().constData(), _value);
|
||||
}
|
||||
|
||||
|
||||
void AWKeys::setWrapNewLines(const bool wrap)
|
||||
void AWKeys::setWrapNewLines(const bool _wrap)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Is wrapping enabled" << wrap;
|
||||
qCDebug(LOG_AW) << "Is wrapping enabled" << _wrap;
|
||||
|
||||
m_wrapNewLines = wrap;
|
||||
m_wrapNewLines = _wrap;
|
||||
}
|
||||
|
||||
|
||||
@ -139,93 +153,106 @@ void AWKeys::updateCache()
|
||||
}
|
||||
|
||||
|
||||
QStringList AWKeys::dictKeys(const bool sorted, const QString regexp) const
|
||||
QStringList AWKeys::dictKeys(const bool _sorted, const QString &_regexp) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Should be sorted" << sorted << "and filter applied"
|
||||
<< regexp;
|
||||
qCDebug(LOG_AW) << "Should be sorted" << _sorted << "and filter applied"
|
||||
<< _regexp;
|
||||
|
||||
// check if functions asked
|
||||
if (_regexp == "functions")
|
||||
return QString(STATIC_FUNCTIONS).split(',');
|
||||
|
||||
QStringList allKeys = m_keyOperator->dictKeys();
|
||||
// sort if required
|
||||
if (sorted)
|
||||
if (_sorted)
|
||||
allKeys.sort();
|
||||
|
||||
return allKeys.filter(QRegExp(regexp));
|
||||
return allKeys.filter(QRegExp(_regexp));
|
||||
}
|
||||
|
||||
|
||||
QStringList AWKeys::getHddDevices() const
|
||||
QVariantList AWKeys::getHddDevices() const
|
||||
{
|
||||
QStringList devices = m_keyOperator->devices(QString("hdd"));
|
||||
QStringList hddDevices = m_keyOperator->devices("hdd");
|
||||
// required by selector in the UI
|
||||
devices.insert(0, QString("disable"));
|
||||
devices.insert(0, QString("auto"));
|
||||
hddDevices.insert(0, "disable");
|
||||
hddDevices.insert(0, "auto");
|
||||
|
||||
// build model
|
||||
QVariantList devices;
|
||||
for (auto &device : hddDevices) {
|
||||
QVariantMap model;
|
||||
model["label"] = device;
|
||||
model["name"] = device;
|
||||
devices.append(model);
|
||||
}
|
||||
|
||||
return devices;
|
||||
}
|
||||
|
||||
|
||||
QString AWKeys::infoByKey(QString key) const
|
||||
QString AWKeys::infoByKey(const QString &_key) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Requested info for key" << key;
|
||||
qCDebug(LOG_AW) << "Requested info for key" << _key;
|
||||
|
||||
return m_keyOperator->infoByKey(key);
|
||||
return m_keyOperator->infoByKey(_key);
|
||||
}
|
||||
|
||||
|
||||
// HACK this method requires to define tag value from bar from UI interface
|
||||
QString AWKeys::valueByKey(QString key) const
|
||||
QString AWKeys::valueByKey(const QString &_key) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Requested value for key" << key;
|
||||
qCDebug(LOG_AW) << "Requested value for key" << _key;
|
||||
|
||||
QString trueKey
|
||||
= key.startsWith(QString("bar")) ? m_keyOperator->infoByKey(key) : key;
|
||||
= _key.startsWith("bar") ? m_keyOperator->infoByKey(_key) : _key;
|
||||
|
||||
return m_aggregator->formatter(m_values[trueKey], trueKey);
|
||||
}
|
||||
|
||||
|
||||
void AWKeys::editItem(const QString type)
|
||||
void AWKeys::editItem(const QString &_type)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Item type" << type;
|
||||
qCDebug(LOG_AW) << "Item type" << _type;
|
||||
|
||||
return m_keyOperator->editItem(type);
|
||||
return m_keyOperator->editItem(_type);
|
||||
}
|
||||
|
||||
|
||||
void AWKeys::dataUpdated(const QString &sourceName,
|
||||
const Plasma::DataEngine::Data &data)
|
||||
void AWKeys::dataUpdated(const QString &_sourceName,
|
||||
const Plasma::DataEngine::Data &_data)
|
||||
{
|
||||
// run concurrent data update
|
||||
QtConcurrent::run(m_threadPool, this, &AWKeys::setDataBySource, sourceName,
|
||||
data);
|
||||
QtConcurrent::run(m_threadPool, this, &AWKeys::setDataBySource, _sourceName,
|
||||
_data);
|
||||
}
|
||||
|
||||
|
||||
void AWKeys::reinitKeys(const QStringList currentKeys)
|
||||
void AWKeys::reinitKeys(const QStringList &_currentKeys)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Update found keys by using list" << currentKeys;
|
||||
qCDebug(LOG_AW) << "Update found keys by using list" << _currentKeys;
|
||||
|
||||
// append lists
|
||||
m_foundBars = AWPatternFunctions::findKeys(m_keyOperator->pattern(),
|
||||
currentKeys, true);
|
||||
_currentKeys, true);
|
||||
m_foundKeys = AWPatternFunctions::findKeys(m_keyOperator->pattern(),
|
||||
currentKeys, false);
|
||||
_currentKeys, false);
|
||||
m_foundLambdas = AWPatternFunctions::findLambdas(m_keyOperator->pattern());
|
||||
// generate list of required keys for bars
|
||||
QStringList barKeys;
|
||||
for (auto bar : m_foundBars) {
|
||||
for (auto &bar : m_foundBars) {
|
||||
GraphicalItem *item = m_keyOperator->giByKey(bar);
|
||||
if (item->isCustom())
|
||||
item->setUsedKeys(
|
||||
AWPatternFunctions::findKeys(item->bar(), currentKeys, false));
|
||||
AWPatternFunctions::findKeys(item->bar(), _currentKeys, false));
|
||||
else
|
||||
item->setUsedKeys(QStringList() << item->bar());
|
||||
barKeys.append(item->usedKeys());
|
||||
}
|
||||
// get required keys
|
||||
m_requiredKeys
|
||||
= m_optimize ? AWKeyCache::getRequiredKeys(m_foundKeys, barKeys,
|
||||
m_tooltipParams, currentKeys)
|
||||
= m_optimize ? AWKeyCache::getRequiredKeys(
|
||||
m_foundKeys, barKeys, m_tooltipParams, _currentKeys)
|
||||
: QStringList();
|
||||
|
||||
// set key data to m_aggregator
|
||||
@ -251,8 +278,8 @@ void AWKeys::updateTextData()
|
||||
void AWKeys::calculateValues()
|
||||
{
|
||||
// hddtot*
|
||||
QStringList mountDevices = m_keyOperator->devices(QString("mount"));
|
||||
for (auto device : mountDevices) {
|
||||
QStringList mountDevices = m_keyOperator->devices("mount");
|
||||
for (auto &device : mountDevices) {
|
||||
int index = mountDevices.indexOf(device);
|
||||
m_values[QString("hddtotmb%1").arg(index)]
|
||||
= m_values[QString("hddfreemb%1").arg(index)].toFloat()
|
||||
@ -263,112 +290,128 @@ void AWKeys::calculateValues()
|
||||
}
|
||||
|
||||
// memtot*
|
||||
m_values[QString("memtotmb")] = m_values[QString("memusedmb")].toInt()
|
||||
+ m_values[QString("memfreemb")].toInt();
|
||||
m_values[QString("memtotgb")] = m_values[QString("memusedgb")].toFloat()
|
||||
+ m_values[QString("memfreegb")].toFloat();
|
||||
m_values["memtotmb"]
|
||||
= m_values["memusedmb"].toInt() + m_values["memfreemb"].toInt();
|
||||
m_values["memtotgb"]
|
||||
= m_values["memusedgb"].toFloat() + m_values["memfreegb"].toFloat();
|
||||
// mem
|
||||
m_values[QString("mem")] = 100.0f * m_values[QString("memmb")].toFloat()
|
||||
/ m_values[QString("memtotmb")].toFloat();
|
||||
m_values["mem"]
|
||||
= 100.0f * m_values["memmb"].toFloat() / m_values["memtotmb"].toFloat();
|
||||
|
||||
// up, down, upkb, downkb, upunits, downunits
|
||||
int netIndex = m_keyOperator->devices(QString("net"))
|
||||
.indexOf(m_values[QString("netdev")].toString());
|
||||
m_values[QString("down")] = m_values[QString("down%1").arg(netIndex)];
|
||||
m_values[QString("downkb")] = m_values[QString("downkb%1").arg(netIndex)];
|
||||
m_values[QString("downtotal")]
|
||||
= m_values[QString("downtotal%1").arg(netIndex)];
|
||||
m_values[QString("downtotalkb")]
|
||||
= m_values[QString("downtotalkb%1").arg(netIndex)];
|
||||
m_values[QString("downunits")]
|
||||
= m_values[QString("downunits%1").arg(netIndex)];
|
||||
m_values[QString("up")] = m_values[QString("up%1").arg(netIndex)];
|
||||
m_values[QString("upkb")] = m_values[QString("upkb%1").arg(netIndex)];
|
||||
m_values[QString("uptotal")] = m_values[QString("uptotal%1").arg(netIndex)];
|
||||
m_values[QString("uptotalkb")]
|
||||
= m_values[QString("uptotalkb%1").arg(netIndex)];
|
||||
m_values[QString("upunits")] = m_values[QString("upunits%1").arg(netIndex)];
|
||||
int netIndex
|
||||
= m_keyOperator->devices("net").indexOf(m_values["netdev"].toString());
|
||||
m_values["down"] = m_values[QString("down%1").arg(netIndex)];
|
||||
m_values["downkb"] = m_values[QString("downkb%1").arg(netIndex)];
|
||||
m_values["downtotal"] = m_values[QString("downtotal%1").arg(netIndex)];
|
||||
m_values["downtotalkb"] = m_values[QString("downtotalkb%1").arg(netIndex)];
|
||||
m_values["downunits"] = m_values[QString("downunits%1").arg(netIndex)];
|
||||
m_values["up"] = m_values[QString("up%1").arg(netIndex)];
|
||||
m_values["upkb"] = m_values[QString("upkb%1").arg(netIndex)];
|
||||
m_values["uptotal"] = m_values[QString("uptotal%1").arg(netIndex)];
|
||||
m_values["uptotalkb"] = m_values[QString("uptotalkb%1").arg(netIndex)];
|
||||
m_values["upunits"] = m_values[QString("upunits%1").arg(netIndex)];
|
||||
|
||||
// swaptot*
|
||||
m_values[QString("swaptotmb")] = m_values[QString("swapmb")].toInt()
|
||||
+ m_values[QString("swapfreemb")].toInt();
|
||||
m_values[QString("swaptotgb")]
|
||||
= m_values[QString("swapgb")].toFloat()
|
||||
+ m_values[QString("swapfreegb")].toFloat();
|
||||
m_values["swaptotmb"]
|
||||
= m_values["swapmb"].toInt() + m_values["swapfreemb"].toInt();
|
||||
m_values["swaptotgb"]
|
||||
= m_values["swapgb"].toFloat() + m_values["swapfreegb"].toFloat();
|
||||
// swap
|
||||
m_values[QString("swap")] = 100.0f * m_values[QString("swapmb")].toFloat()
|
||||
/ m_values[QString("swaptotmb")].toFloat();
|
||||
m_values["swap"] = 100.0f * m_values["swapmb"].toFloat()
|
||||
/ m_values["swaptotmb"].toFloat();
|
||||
|
||||
// lambdas
|
||||
for (auto key : m_foundLambdas)
|
||||
for (auto &key : m_foundLambdas)
|
||||
m_values[key] = AWPatternFunctions::expandLambdas(
|
||||
key, m_aggregator, m_values, m_foundKeys);
|
||||
}
|
||||
|
||||
|
||||
QString AWKeys::parsePattern(QString pattern) const
|
||||
void AWKeys::createDBusInterface()
|
||||
{
|
||||
// get this object id
|
||||
qlonglong id = reinterpret_cast<qlonglong>(this);
|
||||
|
||||
// create session
|
||||
QDBusConnection bus = QDBusConnection::sessionBus();
|
||||
if (!bus.registerService(AWDBUS_SERVICE))
|
||||
qCWarning(LOG_AW) << "Could not register DBus service, last error"
|
||||
<< bus.lastError().message();
|
||||
if (!bus.registerObject(QString("/%1").arg(id), new AWDBusAdaptor(this),
|
||||
QDBusConnection::ExportAllContents)) {
|
||||
qCWarning(LOG_AW) << "Could not register DBus object, last error"
|
||||
<< bus.lastError().message();
|
||||
m_dbusActive = false;
|
||||
} else {
|
||||
m_dbusActive = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QString AWKeys::parsePattern(QString _pattern) const
|
||||
{
|
||||
// screen sign
|
||||
pattern.replace(QString("$$"), QString(0x1d));
|
||||
_pattern.replace("$$", QString(0x1d));
|
||||
|
||||
// lambdas
|
||||
for (auto key : m_foundLambdas)
|
||||
pattern.replace(QString("${{%1}}").arg(key), m_values[key].toString());
|
||||
for (auto &key : m_foundLambdas)
|
||||
_pattern.replace(QString("${{%1}}").arg(key), m_values[key].toString());
|
||||
|
||||
// main keys
|
||||
for (auto key : m_foundKeys)
|
||||
pattern.replace(QString("$%1").arg(key), [this](const QString &tag,
|
||||
const QVariant &value) {
|
||||
QString strValue = m_aggregator->formatter(value, tag);
|
||||
if ((!tag.startsWith(QString("custom")))
|
||||
&& (!tag.startsWith(QString("weather"))))
|
||||
strValue.replace(QString(" "), QString(" "));
|
||||
return strValue;
|
||||
}(key, m_values[key]));
|
||||
for (auto &key : m_foundKeys)
|
||||
_pattern.replace(
|
||||
QString("$%1").arg(key),
|
||||
[this](const QString &tag, const QVariant &value) {
|
||||
QString strValue = m_aggregator->formatter(value, tag);
|
||||
if ((!tag.startsWith("custom")) && (!tag.startsWith("weather")))
|
||||
strValue.replace(" ", " ");
|
||||
return strValue;
|
||||
}(key, m_values[key]));
|
||||
|
||||
// bars
|
||||
for (auto bar : m_foundBars) {
|
||||
for (auto &bar : m_foundBars) {
|
||||
GraphicalItem *item = m_keyOperator->giByKey(bar);
|
||||
QString image
|
||||
= item->isCustom()
|
||||
? item->image(AWPatternFunctions::expandLambdas(
|
||||
item->bar(), m_aggregator, m_values, item->usedKeys()))
|
||||
: item->image(m_values[item->bar()]);
|
||||
pattern.replace(QString("$%1").arg(bar), image);
|
||||
_pattern.replace(QString("$%1").arg(bar), image);
|
||||
}
|
||||
|
||||
// prepare strings
|
||||
pattern.replace(QString(0x1d), QString("$"));
|
||||
_pattern.replace(QString(0x1d), "$");
|
||||
if (m_wrapNewLines)
|
||||
pattern.replace(QString("\n"), QString("<br>"));
|
||||
_pattern.replace("\n", "<br>");
|
||||
|
||||
return pattern;
|
||||
return _pattern;
|
||||
}
|
||||
|
||||
|
||||
void AWKeys::setDataBySource(const QString &sourceName, const QVariantMap &data)
|
||||
void AWKeys::setDataBySource(const QString &_sourceName,
|
||||
const QVariantMap &_data)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Source" << sourceName << "with data" << data;
|
||||
qCDebug(LOG_AW) << "Source" << _sourceName << "with data" << _data;
|
||||
|
||||
// first list init
|
||||
QStringList tags = m_aggregator->keysFromSource(sourceName);
|
||||
QStringList tags = m_aggregator->keysFromSource(_sourceName);
|
||||
if (tags.isEmpty())
|
||||
tags = m_aggregator->registerSource(
|
||||
sourceName, data[QString("units")].toString(), m_requiredKeys);
|
||||
_sourceName, _data["units"].toString(), m_requiredKeys);
|
||||
|
||||
// update data or drop source if there are no matches and exit
|
||||
if (tags.isEmpty()) {
|
||||
qCInfo(LOG_AW) << "Source" << sourceName << "not found";
|
||||
return emit(dropSourceFromDataengine(sourceName));
|
||||
qCInfo(LOG_AW) << "Source" << _sourceName << "not found";
|
||||
return emit(dropSourceFromDataengine(_sourceName));
|
||||
}
|
||||
|
||||
m_mutex.lock();
|
||||
// HACK workaround for time values which are stored in the different path
|
||||
std::for_each(tags.cbegin(), tags.cend(),
|
||||
[this, &data, &sourceName](const QString &tag) {
|
||||
m_values[tag] = sourceName == QString("Local")
|
||||
? data[QString("DateTime")]
|
||||
: data[QString("value")];
|
||||
[this, &_data, &_sourceName](const QString &tag) {
|
||||
m_values[tag] = _sourceName == "Local" ? _data["DateTime"]
|
||||
: _data["value"];
|
||||
});
|
||||
m_mutex.unlock();
|
||||
}
|
||||
|
@ -37,47 +37,50 @@ class AWKeys : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AWKeys(QObject *parent = nullptr);
|
||||
explicit AWKeys(QObject *_parent = nullptr);
|
||||
virtual ~AWKeys();
|
||||
Q_INVOKABLE void initDataAggregator(const QVariantMap tooltipParams);
|
||||
Q_INVOKABLE void initKeys(const QString currentPattern, const int interval,
|
||||
const int limit, const bool optimize);
|
||||
Q_INVOKABLE void setAggregatorProperty(const QString key,
|
||||
const QVariant value);
|
||||
Q_INVOKABLE void setWrapNewLines(const bool wrap = false);
|
||||
bool isDBusActive() const;
|
||||
Q_INVOKABLE void initDataAggregator(const QVariantMap &_tooltipParams);
|
||||
Q_INVOKABLE void initKeys(const QString &_currentPattern,
|
||||
const int _interval, const int _limit,
|
||||
const bool _optimize);
|
||||
Q_INVOKABLE void setAggregatorProperty(const QString &_key,
|
||||
const QVariant &_value);
|
||||
Q_INVOKABLE void setWrapNewLines(const bool _wrap = false);
|
||||
// additional method to force load keys from Qml UI. Used in some
|
||||
// configuration pages
|
||||
Q_INVOKABLE void updateCache();
|
||||
// keys
|
||||
Q_INVOKABLE QStringList dictKeys(const bool sorted = false,
|
||||
const QString regexp = QString()) const;
|
||||
Q_INVOKABLE QStringList getHddDevices() const;
|
||||
Q_INVOKABLE QStringList dictKeys(const bool _sorted = false,
|
||||
const QString &_regexp = "") const;
|
||||
Q_INVOKABLE QVariantList getHddDevices() const;
|
||||
// values
|
||||
Q_INVOKABLE QString infoByKey(QString key) const;
|
||||
Q_INVOKABLE QString valueByKey(QString key) const;
|
||||
Q_INVOKABLE QString infoByKey(const QString &_key) const;
|
||||
Q_INVOKABLE QString valueByKey(const QString &_key) const;
|
||||
// configuration
|
||||
Q_INVOKABLE void editItem(const QString type);
|
||||
Q_INVOKABLE void editItem(const QString &_type);
|
||||
|
||||
public slots:
|
||||
void dataUpdated(const QString &sourceName,
|
||||
const Plasma::DataEngine::Data &data);
|
||||
void dataUpdated(const QString &_sourceName,
|
||||
const Plasma::DataEngine::Data &_data);
|
||||
// dummy method required by DataEngine connections
|
||||
void modelChanged(QString, QAbstractItemModel *){};
|
||||
|
||||
signals:
|
||||
void dropSourceFromDataengine(const QString source);
|
||||
void needTextToBeUpdated(const QString newText) const;
|
||||
void needToolTipToBeUpdated(const QString newText) const;
|
||||
void dropSourceFromDataengine(const QString &_source);
|
||||
void needTextToBeUpdated(const QString &_newText) const;
|
||||
void needToolTipToBeUpdated(const QString &_newText) const;
|
||||
|
||||
private slots:
|
||||
void reinitKeys(const QStringList currentKeys);
|
||||
void reinitKeys(const QStringList &_currentKeys);
|
||||
void updateTextData();
|
||||
|
||||
private:
|
||||
// methods
|
||||
void calculateValues();
|
||||
QString parsePattern(QString pattern) const;
|
||||
void setDataBySource(const QString &sourceName, const QVariantMap &data);
|
||||
void createDBusInterface();
|
||||
QString parsePattern(QString _pattern) const;
|
||||
void setDataBySource(const QString &_sourceName, const QVariantMap &_data);
|
||||
// objects
|
||||
AWDataAggregator *m_dataAggregator = nullptr;
|
||||
AWDataEngineAggregator *m_dataEngineAggregator = nullptr;
|
||||
@ -85,6 +88,7 @@ private:
|
||||
AWKeyOperations *m_keyOperator = nullptr;
|
||||
QTimer *m_timer = nullptr;
|
||||
// variables
|
||||
bool m_dbusActive = false;
|
||||
QVariantMap m_tooltipParams;
|
||||
QStringList m_foundBars, m_foundKeys, m_foundLambdas, m_requiredKeys;
|
||||
QVariantHash m_values;
|
||||
|
@ -27,27 +27,31 @@
|
||||
#include "awformatterhelper.h"
|
||||
|
||||
|
||||
AWKeysAggregator::AWKeysAggregator(QObject *parent)
|
||||
: QObject(parent)
|
||||
AWKeysAggregator::AWKeysAggregator(QObject *_parent)
|
||||
: QObject(_parent)
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
|
||||
// sort time keys
|
||||
m_timeKeys.sort();
|
||||
std::reverse(m_timeKeys.begin(), m_timeKeys.end());
|
||||
|
||||
// default formatters
|
||||
// memory
|
||||
m_formatter[QString("mem")] = FormatterType::Float;
|
||||
m_formatter[QString("memtotmb")] = FormatterType::MemMBFormat;
|
||||
m_formatter[QString("memtotgb")] = FormatterType::MemGBFormat;
|
||||
m_formatter["mem"] = FormatterType::Float;
|
||||
m_formatter["memtotmb"] = FormatterType::MemMBFormat;
|
||||
m_formatter["memtotgb"] = FormatterType::MemGBFormat;
|
||||
// network
|
||||
m_formatter[QString("down")] = FormatterType::NetSmartFormat;
|
||||
m_formatter[QString("downkb")] = FormatterType::Integer;
|
||||
m_formatter[QString("downunits")] = FormatterType::NetSmartUnits;
|
||||
m_formatter[QString("up")] = FormatterType::NetSmartFormat;
|
||||
m_formatter[QString("upkb")] = FormatterType::Integer;
|
||||
m_formatter[QString("upunits")] = FormatterType::NetSmartUnits;
|
||||
m_formatter["down"] = FormatterType::NetSmartFormat;
|
||||
m_formatter["downkb"] = FormatterType::Integer;
|
||||
m_formatter["downunits"] = FormatterType::NetSmartUnits;
|
||||
m_formatter["up"] = FormatterType::NetSmartFormat;
|
||||
m_formatter["upkb"] = FormatterType::Integer;
|
||||
m_formatter["upunits"] = FormatterType::NetSmartUnits;
|
||||
// swap
|
||||
m_formatter[QString("swap")] = FormatterType::Float;
|
||||
m_formatter[QString("swaptotmb")] = FormatterType::MemMBFormat;
|
||||
m_formatter[QString("swaptotgb")] = FormatterType::MemGBFormat;
|
||||
m_formatter["swap"] = FormatterType::Float;
|
||||
m_formatter["swaptotmb"] = FormatterType::MemMBFormat;
|
||||
m_formatter["swaptotgb"] = FormatterType::MemGBFormat;
|
||||
}
|
||||
|
||||
|
||||
@ -67,42 +71,42 @@ void AWKeysAggregator::initFormatters()
|
||||
}
|
||||
|
||||
|
||||
QString AWKeysAggregator::formatter(const QVariant &data,
|
||||
const QString &key) const
|
||||
QString AWKeysAggregator::formatter(const QVariant &_data,
|
||||
const QString &_key) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Data" << data << "for key" << key;
|
||||
qCDebug(LOG_AW) << "Data" << _data << "for key" << _key;
|
||||
|
||||
QString output;
|
||||
QLocale loc = m_translate ? QLocale::system() : QLocale::c();
|
||||
// case block
|
||||
switch (m_formatter[key]) {
|
||||
switch (m_formatter[_key]) {
|
||||
case FormatterType::Float:
|
||||
output = QString("%1").arg(data.toFloat(), 5, 'f', 1);
|
||||
output = QString("%1").arg(_data.toFloat(), 5, 'f', 1);
|
||||
break;
|
||||
case FormatterType::FloatTwoSymbols:
|
||||
output = QString("%1").arg(data.toFloat(), 5, 'f', 2);
|
||||
output = QString("%1").arg(_data.toFloat(), 5, 'f', 2);
|
||||
break;
|
||||
case FormatterType::Integer:
|
||||
output = QString("%1").arg(data.toFloat(), 4, 'f', 0);
|
||||
output = QString("%1").arg(_data.toFloat(), 4, 'f', 0);
|
||||
break;
|
||||
case FormatterType::IntegerFive:
|
||||
output = QString("%1").arg(data.toFloat(), 5, 'f', 0);
|
||||
output = QString("%1").arg(_data.toFloat(), 5, 'f', 0);
|
||||
break;
|
||||
case FormatterType::IntegerThree:
|
||||
output = QString("%1").arg(data.toFloat(), 3, 'f', 0);
|
||||
output = QString("%1").arg(_data.toFloat(), 3, 'f', 0);
|
||||
break;
|
||||
case FormatterType::List:
|
||||
output = data.toStringList().join(QChar(','));
|
||||
output = _data.toStringList().join(',');
|
||||
break;
|
||||
case FormatterType::ACFormat:
|
||||
output = data.toBool() ? m_acOnline : m_acOffline;
|
||||
output = _data.toBool() ? m_acOnline : m_acOffline;
|
||||
break;
|
||||
case FormatterType::MemGBFormat:
|
||||
output
|
||||
= QString("%1").arg(data.toFloat() / (1024.0 * 1024.0), 5, 'f', 1);
|
||||
= QString("%1").arg(_data.toFloat() / (1024.0 * 1024.0), 5, 'f', 1);
|
||||
break;
|
||||
case FormatterType::MemMBFormat:
|
||||
output = QString("%1").arg(data.toFloat() / 1024.0, 5, 'f', 0);
|
||||
output = QString("%1").arg(_data.toFloat() / 1024.0, 5, 'f', 0);
|
||||
break;
|
||||
case FormatterType::NetSmartFormat:
|
||||
output = [](const float value) {
|
||||
@ -110,44 +114,44 @@ QString AWKeysAggregator::formatter(const QVariant &data,
|
||||
return QString("%1").arg(value / 1024.0, 4, 'f', 1);
|
||||
else
|
||||
return QString("%1").arg(value, 4, 'f', 0);
|
||||
}(data.toFloat());
|
||||
}(_data.toFloat());
|
||||
break;
|
||||
case FormatterType::NetSmartUnits:
|
||||
if (data.toFloat() > 1024.0)
|
||||
output = m_translate ? i18n("MB/s") : QString("MB/s");
|
||||
if (_data.toFloat() > 1024.0)
|
||||
output = m_translate ? i18n("MB/s") : "MB/s";
|
||||
else
|
||||
output = m_translate ? i18n("KB/s") : QString("KB/s");
|
||||
output = m_translate ? i18n("KB/s") : "KB/s";
|
||||
break;
|
||||
case FormatterType::Quotes:
|
||||
// first cast
|
||||
output = QString("%1").arg(data.toDouble(), 0, 'f');
|
||||
output = QString("%1").arg(_data.toDouble(), 0, 'f');
|
||||
output = output.rightJustified(8, QLatin1Char(' '), true);
|
||||
break;
|
||||
case FormatterType::Temperature:
|
||||
output = QString("%1").arg(temperature(data.toFloat()), 5, 'f', 1);
|
||||
output = QString("%1").arg(temperature(_data.toFloat()), 5, 'f', 1);
|
||||
break;
|
||||
case FormatterType::Time:
|
||||
output = data.toDateTime().toString();
|
||||
output = _data.toDateTime().toString();
|
||||
break;
|
||||
case FormatterType::TimeCustom:
|
||||
output = m_customTime;
|
||||
[&output, loc, this](const QDateTime dt) {
|
||||
for (auto key : m_timeKeys)
|
||||
for (auto &key : m_timeKeys)
|
||||
output.replace(QString("$%1").arg(key), loc.toString(dt, key));
|
||||
}(data.toDateTime());
|
||||
}(_data.toDateTime());
|
||||
break;
|
||||
case FormatterType::TimeISO:
|
||||
output = data.toDateTime().toString(Qt::ISODate);
|
||||
output = _data.toDateTime().toString(Qt::ISODate);
|
||||
break;
|
||||
case FormatterType::TimeLong:
|
||||
output = loc.toString(data.toDateTime(), QLocale::LongFormat);
|
||||
output = loc.toString(_data.toDateTime(), QLocale::LongFormat);
|
||||
break;
|
||||
case FormatterType::TimeShort:
|
||||
output = loc.toString(data.toDateTime(), QLocale::ShortFormat);
|
||||
output = loc.toString(_data.toDateTime(), QLocale::ShortFormat);
|
||||
break;
|
||||
case FormatterType::Timestamp:
|
||||
output = QString("%1").arg(
|
||||
data.toDateTime().toMSecsSinceEpoch() / 1000.0, 10, 'f', 0);
|
||||
_data.toDateTime().toMSecsSinceEpoch() / 1000.0, 10, 'f', 0);
|
||||
break;
|
||||
case FormatterType::Uptime:
|
||||
case FormatterType::UptimeCustom:
|
||||
@ -157,27 +161,26 @@ QString AWKeysAggregator::formatter(const QVariant &data,
|
||||
int minutes = seconds / 60 % 60;
|
||||
int hours = ((seconds / 60) - minutes) / 60 % 24;
|
||||
int days = (((seconds / 60) - minutes) / 60 - hours) / 24;
|
||||
source.replace(QString("$dd"),
|
||||
source.replace("$dd",
|
||||
QString("%1").arg(days, 3, 10, QChar('0')));
|
||||
source.replace(QString("$d"), QString("%1").arg(days));
|
||||
source.replace(QString("$hh"),
|
||||
source.replace("$d", QString("%1").arg(days));
|
||||
source.replace("$hh",
|
||||
QString("%1").arg(hours, 2, 10, QChar('0')));
|
||||
source.replace(QString("$h"), QString("%1").arg(hours));
|
||||
source.replace(QString("$mm"),
|
||||
source.replace("$h", QString("%1").arg(hours));
|
||||
source.replace("$mm",
|
||||
QString("%1").arg(minutes, 2, 10, QChar('0')));
|
||||
source.replace(QString("$m"), QString("%1").arg(minutes));
|
||||
source.replace("$m", QString("%1").arg(minutes));
|
||||
return source;
|
||||
}(m_formatter[key] == FormatterType::Uptime
|
||||
? QString("$ddd$hhh$mmm")
|
||||
: m_customUptime,
|
||||
static_cast<int>(data.toFloat()));
|
||||
}(m_formatter[_key] == FormatterType::Uptime ? "$ddd$hhh$mmm"
|
||||
: m_customUptime,
|
||||
static_cast<int>(_data.toFloat()));
|
||||
break;
|
||||
case FormatterType::NoFormat:
|
||||
output = data.toString();
|
||||
output = _data.toString();
|
||||
break;
|
||||
case FormatterType::Custom:
|
||||
if (m_customFormatters)
|
||||
output = m_customFormatters->convert(data, key);
|
||||
output = m_customFormatters->convert(_data, _key);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -185,176 +188,176 @@ QString AWKeysAggregator::formatter(const QVariant &data,
|
||||
}
|
||||
|
||||
|
||||
QStringList AWKeysAggregator::keysFromSource(const QString &source) const
|
||||
QStringList AWKeysAggregator::keysFromSource(const QString &_source) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Search for source" << source;
|
||||
qCDebug(LOG_AW) << "Search for source" << _source;
|
||||
|
||||
return m_map.values(source);
|
||||
return m_map.values(_source);
|
||||
}
|
||||
|
||||
|
||||
void AWKeysAggregator::setAcOffline(const QString inactive)
|
||||
void AWKeysAggregator::setAcOffline(const QString &_inactive)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Inactive AC string" << inactive;
|
||||
qCDebug(LOG_AW) << "Inactive AC string" << _inactive;
|
||||
|
||||
m_acOffline = inactive;
|
||||
m_acOffline = _inactive;
|
||||
}
|
||||
|
||||
|
||||
void AWKeysAggregator::setAcOnline(const QString active)
|
||||
void AWKeysAggregator::setAcOnline(const QString &_active)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Active AC string" << active;
|
||||
qCDebug(LOG_AW) << "Active AC string" << _active;
|
||||
|
||||
m_acOnline = active;
|
||||
m_acOnline = _active;
|
||||
}
|
||||
|
||||
|
||||
void AWKeysAggregator::setCustomTime(const QString customTime)
|
||||
void AWKeysAggregator::setCustomTime(const QString &_customTime)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Format" << customTime;
|
||||
qCDebug(LOG_AW) << "Format" << _customTime;
|
||||
|
||||
m_customTime = customTime;
|
||||
m_customTime = _customTime;
|
||||
}
|
||||
|
||||
|
||||
void AWKeysAggregator::setCustomUptime(const QString customUptime)
|
||||
void AWKeysAggregator::setCustomUptime(const QString &_customUptime)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Format" << customUptime;
|
||||
qCDebug(LOG_AW) << "Format" << _customUptime;
|
||||
|
||||
m_customUptime = customUptime;
|
||||
m_customUptime = _customUptime;
|
||||
}
|
||||
|
||||
|
||||
void AWKeysAggregator::setDevices(const QHash<QString, QStringList> devices)
|
||||
void AWKeysAggregator::setDevices(const QHash<QString, QStringList> &_devices)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Devices" << devices;
|
||||
qCDebug(LOG_AW) << "Devices" << _devices;
|
||||
|
||||
m_devices = devices;
|
||||
m_devices = _devices;
|
||||
}
|
||||
|
||||
|
||||
void AWKeysAggregator::setTempUnits(const QString units)
|
||||
void AWKeysAggregator::setTempUnits(const QString &_units)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Units" << units;
|
||||
qCDebug(LOG_AW) << "Units" << _units;
|
||||
|
||||
m_tempUnits = units;
|
||||
m_tempUnits = _units;
|
||||
}
|
||||
|
||||
|
||||
void AWKeysAggregator::setTranslate(const bool translate)
|
||||
void AWKeysAggregator::setTranslate(const bool _translate)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Translate" << translate;
|
||||
qCDebug(LOG_AW) << "Translate" << _translate;
|
||||
|
||||
m_translate = translate;
|
||||
m_translate = _translate;
|
||||
}
|
||||
|
||||
|
||||
// HACK units required to define should the value be calculated as temperature
|
||||
// or fan data
|
||||
QStringList AWKeysAggregator::registerSource(const QString &source,
|
||||
const QString &units,
|
||||
const QStringList &keys)
|
||||
QStringList AWKeysAggregator::registerSource(const QString &_source,
|
||||
const QString &_units,
|
||||
const QStringList &_keys)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Source" << source << "with units" << units;
|
||||
qCDebug(LOG_AW) << "Source" << _source << "with units" << _units;
|
||||
|
||||
// regular expressions
|
||||
QRegExp cpuRegExp = QRegExp(QString("cpu/cpu.*/TotalLoad"));
|
||||
QRegExp cpuclRegExp = QRegExp(QString("cpu/cpu.*/clock"));
|
||||
QRegExp hddrRegExp = QRegExp(QString("disk/.*/Rate/rblk"));
|
||||
QRegExp hddwRegExp = QRegExp(QString("disk/.*/Rate/wblk"));
|
||||
QRegExp mountFillRegExp = QRegExp(QString("partitions/.*/filllevel"));
|
||||
QRegExp mountFreeRegExp = QRegExp(QString("partitions/.*/freespace"));
|
||||
QRegExp mountUsedRegExp = QRegExp(QString("partitions/.*/usedspace"));
|
||||
QRegExp netRegExp = QRegExp(
|
||||
QString("network/interfaces/.*/(receiver|transmitter)/data$"));
|
||||
QRegExp netTotalRegExp = QRegExp(
|
||||
QString("network/interfaces/.*/(receiver|transmitter)/dataTotal$"));
|
||||
QRegExp cpuRegExp = QRegExp("cpu/cpu.*/TotalLoad");
|
||||
QRegExp cpuclRegExp = QRegExp("cpu/cpu.*/clock");
|
||||
QRegExp hddrRegExp = QRegExp("disk/.*/Rate/rblk");
|
||||
QRegExp hddwRegExp = QRegExp("disk/.*/Rate/wblk");
|
||||
QRegExp mountFillRegExp = QRegExp("partitions/.*/filllevel");
|
||||
QRegExp mountFreeRegExp = QRegExp("partitions/.*/freespace");
|
||||
QRegExp mountUsedRegExp = QRegExp("partitions/.*/usedspace");
|
||||
QRegExp netRegExp
|
||||
= QRegExp("network/interfaces/.*/(receiver|transmitter)/data$");
|
||||
QRegExp netTotalRegExp
|
||||
= QRegExp("network/interfaces/.*/(receiver|transmitter)/dataTotal$");
|
||||
|
||||
if (source == QString("battery/ac")) {
|
||||
if (_source == "battery/ac") {
|
||||
// AC
|
||||
m_map[source] = QString("ac");
|
||||
m_formatter[QString("ac")] = FormatterType::ACFormat;
|
||||
} else if (source.startsWith(QString("battery/"))) {
|
||||
m_map[_source] = "ac";
|
||||
m_formatter["ac"] = FormatterType::ACFormat;
|
||||
} else if (_source.startsWith("battery/")) {
|
||||
// battery stats
|
||||
QString key = source;
|
||||
key.remove(QString("battery/"));
|
||||
m_map[source] = key;
|
||||
QString key = _source;
|
||||
key.remove("battery/");
|
||||
m_map[_source] = key;
|
||||
m_formatter[key] = FormatterType::IntegerThree;
|
||||
} else if (source == QString("cpu/system/TotalLoad")) {
|
||||
} else if (_source == "cpu/system/TotalLoad") {
|
||||
// cpu
|
||||
m_map[source] = QString("cpu");
|
||||
m_formatter[QString("cpu")] = FormatterType::Float;
|
||||
} else if (source.contains(cpuRegExp)) {
|
||||
m_map[_source] = "cpu";
|
||||
m_formatter["cpu"] = FormatterType::Float;
|
||||
} else if (_source.contains(cpuRegExp)) {
|
||||
// cpus
|
||||
QString key = source;
|
||||
key.remove(QString("cpu/")).remove(QString("/TotalLoad"));
|
||||
m_map[source] = key;
|
||||
QString key = _source;
|
||||
key.remove("cpu/").remove("/TotalLoad");
|
||||
m_map[_source] = key;
|
||||
m_formatter[key] = FormatterType::Float;
|
||||
} else if (source == QString("cpu/system/AverageClock")) {
|
||||
} else if (_source == "cpu/system/AverageClock") {
|
||||
// cpucl
|
||||
m_map[source] = QString("cpucl");
|
||||
m_formatter[QString("cpucl")] = FormatterType::Integer;
|
||||
} else if (source.contains(cpuclRegExp)) {
|
||||
m_map[_source] = "cpucl";
|
||||
m_formatter["cpucl"] = FormatterType::Integer;
|
||||
} else if (_source.contains(cpuclRegExp)) {
|
||||
// cpucls
|
||||
QString key = source;
|
||||
key.remove(QString("cpu/cpu")).remove(QString("/clock"));
|
||||
QString key = _source;
|
||||
key.remove("cpu/cpu").remove("/clock");
|
||||
key = QString("cpucl%1").arg(key);
|
||||
m_map[source] = key;
|
||||
m_map[_source] = key;
|
||||
m_formatter[key] = FormatterType::Integer;
|
||||
} else if (source.startsWith(QString("custom"))) {
|
||||
} else if (_source.startsWith("custom")) {
|
||||
// custom
|
||||
QString key = source;
|
||||
key.remove(QString("custom/"));
|
||||
m_map[source] = key;
|
||||
QString key = _source;
|
||||
key.remove("custom/");
|
||||
m_map[_source] = key;
|
||||
m_formatter[key] = FormatterType::NoFormat;
|
||||
} else if (source == QString("desktop/current/name")) {
|
||||
} else if (_source == "desktop/current/name") {
|
||||
// current desktop name
|
||||
m_map[source] = QString("desktop");
|
||||
m_formatter[QString("desktop")] = FormatterType::NoFormat;
|
||||
} else if (source == QString("desktop/current/number")) {
|
||||
m_map[_source] = "desktop";
|
||||
m_formatter["desktop"] = FormatterType::NoFormat;
|
||||
} else if (_source == "desktop/current/number") {
|
||||
// current desktop number
|
||||
m_map[source] = QString("ndesktop");
|
||||
m_formatter[QString("ndesktop")] = FormatterType::NoFormat;
|
||||
} else if (source == QString("desktop/total/number")) {
|
||||
m_map[_source] = "ndesktop";
|
||||
m_formatter["ndesktop"] = FormatterType::NoFormat;
|
||||
} else if (_source == "desktop/total/number") {
|
||||
// desktop count
|
||||
m_map[source] = QString("tdesktops");
|
||||
m_formatter[QString("tdesktops")] = FormatterType::NoFormat;
|
||||
} else if (source.contains(hddrRegExp)) {
|
||||
m_map[_source] = "tdesktops";
|
||||
m_formatter["tdesktops"] = FormatterType::NoFormat;
|
||||
} else if (_source.contains(hddrRegExp)) {
|
||||
// read speed
|
||||
QString device = source;
|
||||
device.remove(QString("/Rate/rblk"));
|
||||
int index = m_devices[QString("disk")].indexOf(device);
|
||||
QString device = _source;
|
||||
device.remove("/Rate/rblk");
|
||||
int index = m_devices["disk"].indexOf(device);
|
||||
if (index > -1) {
|
||||
QString key = QString("hddr%1").arg(index);
|
||||
m_map[source] = key;
|
||||
m_map[_source] = key;
|
||||
m_formatter[key] = FormatterType::Integer;
|
||||
}
|
||||
} else if (source.contains(hddwRegExp)) {
|
||||
} else if (_source.contains(hddwRegExp)) {
|
||||
// write speed
|
||||
QString device = source;
|
||||
device.remove(QString("/Rate/wblk"));
|
||||
int index = m_devices[QString("disk")].indexOf(device);
|
||||
QString device = _source;
|
||||
device.remove("/Rate/wblk");
|
||||
int index = m_devices["disk"].indexOf(device);
|
||||
if (index > -1) {
|
||||
QString key = QString("hddw%1").arg(index);
|
||||
m_map[source] = key;
|
||||
m_map[_source] = key;
|
||||
m_formatter[key] = FormatterType::Integer;
|
||||
}
|
||||
} else if (source == QString("gpu/load")) {
|
||||
} else if (_source == "gpu/load") {
|
||||
// gpu load
|
||||
m_map[source] = QString("gpu");
|
||||
m_formatter[QString("gpu")] = FormatterType::Float;
|
||||
} else if (source == QString("gpu/temperature")) {
|
||||
m_map[_source] = "gpu";
|
||||
m_formatter["gpu"] = FormatterType::Float;
|
||||
} else if (_source == "gpu/temperature") {
|
||||
// gpu temperature
|
||||
m_map[source] = QString("gputemp");
|
||||
m_formatter[QString("gputemp")] = FormatterType::Temperature;
|
||||
} else if (source.contains(mountFillRegExp)) {
|
||||
m_map[_source] = "gputemp";
|
||||
m_formatter["gputemp"] = FormatterType::Temperature;
|
||||
} else if (_source.contains(mountFillRegExp)) {
|
||||
// fill level
|
||||
QString device = source;
|
||||
device.remove(QString("partitions")).remove(QString("/filllevel"));
|
||||
int index = m_devices[QString("mount")].indexOf(device);
|
||||
QString device = _source;
|
||||
device.remove("partitions").remove("/filllevel");
|
||||
int index = m_devices["mount"].indexOf(device);
|
||||
if (index > -1) {
|
||||
QString key = QString("hdd%1").arg(index);
|
||||
m_map[source] = key;
|
||||
m_map[_source] = key;
|
||||
m_formatter[key] = FormatterType::Float;
|
||||
// additional keys
|
||||
m_formatter[QString("hddtotmb%1").arg(index)]
|
||||
@ -362,223 +365,224 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
|
||||
m_formatter[QString("hddtotgb%1").arg(index)]
|
||||
= FormatterType::MemGBFormat;
|
||||
}
|
||||
} else if (source.contains(mountFreeRegExp)) {
|
||||
} else if (_source.contains(mountFreeRegExp)) {
|
||||
// free space
|
||||
QString device = source;
|
||||
device.remove(QString("partitions")).remove(QString("/freespace"));
|
||||
int index = m_devices[QString("mount")].indexOf(device);
|
||||
QString device = _source;
|
||||
device.remove("partitions").remove("/freespace");
|
||||
int index = m_devices["mount"].indexOf(device);
|
||||
if (index > -1) {
|
||||
// mb
|
||||
QString key = QString("hddfreemb%1").arg(index);
|
||||
m_map[source] = key;
|
||||
m_map[_source] = key;
|
||||
m_formatter[key] = FormatterType::MemMBFormat;
|
||||
// gb
|
||||
key = QString("hddfreegb%1").arg(index);
|
||||
m_map.insertMulti(source, key);
|
||||
m_map.insertMulti(_source, key);
|
||||
m_formatter[key] = FormatterType::MemGBFormat;
|
||||
}
|
||||
} else if (source.contains(mountUsedRegExp)) {
|
||||
} else if (_source.contains(mountUsedRegExp)) {
|
||||
// used
|
||||
QString device = source;
|
||||
device.remove(QString("partitions")).remove(QString("/usedspace"));
|
||||
int index = m_devices[QString("mount")].indexOf(device);
|
||||
QString device = _source;
|
||||
device.remove("partitions").remove("/usedspace");
|
||||
int index = m_devices["mount"].indexOf(device);
|
||||
if (index > -1) {
|
||||
// mb
|
||||
QString key = QString("hddmb%1").arg(index);
|
||||
m_map[source] = key;
|
||||
m_map[_source] = key;
|
||||
m_formatter[key] = FormatterType::MemMBFormat;
|
||||
// gb
|
||||
key = QString("hddgb%1").arg(index);
|
||||
m_map.insertMulti(source, key);
|
||||
m_map.insertMulti(_source, key);
|
||||
m_formatter[key] = FormatterType::MemGBFormat;
|
||||
}
|
||||
} else if (source.startsWith(QString("hdd/temperature"))) {
|
||||
} else if (_source.startsWith("hdd/temperature")) {
|
||||
// hdd temperature
|
||||
QString device = source;
|
||||
device.remove(QString("hdd/temperature"));
|
||||
int index = m_devices[QString("hdd")].indexOf(device);
|
||||
QString device = _source;
|
||||
device.remove("hdd/temperature");
|
||||
int index = m_devices["hdd"].indexOf(device);
|
||||
if (index > -1) {
|
||||
QString key = QString("hddtemp%1").arg(index);
|
||||
m_map[source] = key;
|
||||
m_map[_source] = key;
|
||||
m_formatter[key] = FormatterType::Temperature;
|
||||
}
|
||||
} else if (source.startsWith(QString("cpu/system/loadavg"))) {
|
||||
} else if (_source.startsWith("cpu/system/loadavg")) {
|
||||
// load average
|
||||
QString time = source;
|
||||
time.remove(QString("cpu/system/loadavg"));
|
||||
QString time = _source;
|
||||
time.remove("cpu/system/loadavg");
|
||||
QString key = QString("la%1").arg(time);
|
||||
m_map[source] = key;
|
||||
m_map[_source] = key;
|
||||
m_formatter[key] = FormatterType::FloatTwoSymbols;
|
||||
} else if (source == QString("mem/physical/application")) {
|
||||
} else if (_source == "mem/physical/application") {
|
||||
// app memory
|
||||
// mb
|
||||
m_map[source] = QString("memmb");
|
||||
m_formatter[QString("memmb")] = FormatterType::MemMBFormat;
|
||||
m_map[_source] = "memmb";
|
||||
m_formatter["memmb"] = FormatterType::MemMBFormat;
|
||||
// gb
|
||||
m_map.insertMulti(source, QString("memgb"));
|
||||
m_formatter[QString("memgb")] = FormatterType::MemGBFormat;
|
||||
} else if (source == QString("mem/physical/free")) {
|
||||
m_map.insertMulti(_source, "memgb");
|
||||
m_formatter["memgb"] = FormatterType::MemGBFormat;
|
||||
} else if (_source == "mem/physical/free") {
|
||||
// free memory
|
||||
// mb
|
||||
m_map[source] = QString("memfreemb");
|
||||
m_formatter[QString("memfreemb")] = FormatterType::MemMBFormat;
|
||||
m_map[_source] = "memfreemb";
|
||||
m_formatter["memfreemb"] = FormatterType::MemMBFormat;
|
||||
// gb
|
||||
m_map.insertMulti(source, QString("memfreegb"));
|
||||
m_formatter[QString("memfreegb")] = FormatterType::MemGBFormat;
|
||||
} else if (source == QString("mem/physical/used")) {
|
||||
m_map.insertMulti(_source, "memfreegb");
|
||||
m_formatter["memfreegb"] = FormatterType::MemGBFormat;
|
||||
} else if (_source == "mem/physical/used") {
|
||||
// used memory
|
||||
// mb
|
||||
m_map[source] = QString("memusedmb");
|
||||
m_formatter[QString("memusedmb")] = FormatterType::MemMBFormat;
|
||||
m_map[_source] = "memusedmb";
|
||||
m_formatter["memusedmb"] = FormatterType::MemMBFormat;
|
||||
// gb
|
||||
m_map.insertMulti(source, QString("memusedgb"));
|
||||
m_formatter[QString("memusedgb")] = FormatterType::MemGBFormat;
|
||||
} else if (source == QString("network/current/name")) {
|
||||
m_map.insertMulti(_source, "memusedgb");
|
||||
m_formatter["memusedgb"] = FormatterType::MemGBFormat;
|
||||
} else if (_source == "network/current/name") {
|
||||
// network device
|
||||
m_map[source] = QString("netdev");
|
||||
m_formatter[QString("netdev")] = FormatterType::NoFormat;
|
||||
} else if (source.contains(netRegExp)) {
|
||||
m_map[_source] = "netdev";
|
||||
m_formatter["netdev"] = FormatterType::NoFormat;
|
||||
} else if (_source.startsWith("network/response")) {
|
||||
// network response
|
||||
QString key = _source;
|
||||
key.remove("network/");
|
||||
m_map[_source] = key;
|
||||
m_formatter[key] = FormatterType::NoFormat;
|
||||
} else if (_source.contains(netRegExp)) {
|
||||
// network speed
|
||||
QString type = source.contains(QString("receiver")) ? QString("down")
|
||||
: QString("up");
|
||||
int index
|
||||
= m_devices[QString("net")].indexOf(source.split(QChar('/'))[2]);
|
||||
QString type = _source.contains("receiver") ? "down" : "up";
|
||||
int index = m_devices["net"].indexOf(_source.split('/')[2]);
|
||||
if (index > -1) {
|
||||
// kb
|
||||
QString key = QString("%1kb%2").arg(type).arg(index);
|
||||
m_map[source] = key;
|
||||
m_map[_source] = key;
|
||||
m_formatter[key] = FormatterType::Integer;
|
||||
// smart
|
||||
key = QString("%1%2").arg(type).arg(index);
|
||||
m_map.insertMulti(source, key);
|
||||
m_map.insertMulti(_source, key);
|
||||
m_formatter[key] = FormatterType::NetSmartFormat;
|
||||
// units
|
||||
key = QString("%1units%2").arg(type).arg(index);
|
||||
m_map.insertMulti(source, key);
|
||||
m_map.insertMulti(_source, key);
|
||||
m_formatter[key] = FormatterType::NetSmartUnits;
|
||||
}
|
||||
} else if (source.contains(netTotalRegExp)) {
|
||||
} else if (_source.contains(netTotalRegExp)) {
|
||||
// network data total
|
||||
QString type = source.contains(QString("receiver")) ? QString("down")
|
||||
: QString("up");
|
||||
int index
|
||||
= m_devices[QString("net")].indexOf(source.split(QChar('/'))[2]);
|
||||
QString type = _source.contains("receiver") ? "down" : "up";
|
||||
int index = m_devices["net"].indexOf(_source.split('/')[2]);
|
||||
if (index > -1) {
|
||||
// kb
|
||||
QString key = QString("%1totalkb%2").arg(type).arg(index);
|
||||
m_map[source] = key;
|
||||
m_map[_source] = key;
|
||||
m_formatter[key] = FormatterType::Integer;
|
||||
// mb
|
||||
key = QString("%1total%2").arg(type).arg(index);
|
||||
m_map.insertMulti(source, key);
|
||||
m_map.insertMulti(_source, key);
|
||||
m_formatter[key] = FormatterType::MemMBFormat;
|
||||
}
|
||||
} else if (source.startsWith(QString("upgrade"))) {
|
||||
} else if (_source.startsWith("upgrade")) {
|
||||
// package manager
|
||||
QString key = source;
|
||||
key.remove(QString("upgrade/"));
|
||||
m_map[source] = key;
|
||||
QString key = _source;
|
||||
key.remove("upgrade/");
|
||||
m_map[_source] = key;
|
||||
m_formatter[key] = FormatterType::IntegerThree;
|
||||
} else if (source.startsWith(QString("player"))) {
|
||||
} else if (_source.startsWith("player")) {
|
||||
// player
|
||||
QString key = source;
|
||||
key.remove(QString("player/"));
|
||||
m_map[source] = key;
|
||||
QString key = _source;
|
||||
key.remove("player/");
|
||||
m_map[_source] = key;
|
||||
m_formatter[key] = FormatterType::NoFormat;
|
||||
} else if (source == QString("ps/running/count")) {
|
||||
} else if (_source == "ps/running/count") {
|
||||
// running processes count
|
||||
m_map[source] = QString("pscount");
|
||||
m_formatter[QString("pscount")] = FormatterType::NoFormat;
|
||||
} else if (source == QString("ps/running/list")) {
|
||||
m_map[_source] = "pscount";
|
||||
m_formatter["pscount"] = FormatterType::NoFormat;
|
||||
} else if (_source == "ps/running/list") {
|
||||
// list of running processes
|
||||
m_map[source] = QString("ps");
|
||||
m_formatter[QString("ps")] = FormatterType::List;
|
||||
} else if (source == QString("ps/total/count")) {
|
||||
m_map[_source] = "ps";
|
||||
m_formatter["ps"] = FormatterType::List;
|
||||
} else if (_source == "ps/total/count") {
|
||||
// total processes count
|
||||
m_map[source] = QString("pstotal");
|
||||
m_formatter[QString("pstotal")] = FormatterType::NoFormat;
|
||||
} else if (source.startsWith(QString("quotes"))) {
|
||||
m_map[_source] = "pstotal";
|
||||
m_formatter["pstotal"] = FormatterType::NoFormat;
|
||||
} else if (_source.startsWith("quotes")) {
|
||||
// quotes
|
||||
QString key = source;
|
||||
key.remove(QString("quotes/"));
|
||||
m_map[source] = key;
|
||||
QString key = _source;
|
||||
key.remove("quotes/");
|
||||
m_map[_source] = key;
|
||||
m_formatter[key] = FormatterType::Quotes;
|
||||
} else if (source == QString("mem/swap/free")) {
|
||||
} else if (_source == "mem/swap/free") {
|
||||
// free swap
|
||||
// mb
|
||||
m_map[source] = QString("swapfreemb");
|
||||
m_formatter[QString("swapfreemb")] = FormatterType::MemMBFormat;
|
||||
m_map[_source] = "swapfreemb";
|
||||
m_formatter["swapfreemb"] = FormatterType::MemMBFormat;
|
||||
// gb
|
||||
m_map.insertMulti(source, QString("swapfreegb"));
|
||||
m_formatter[QString("swapfreegb")] = FormatterType::MemGBFormat;
|
||||
} else if (source == QString("mem/swap/used")) {
|
||||
m_map.insertMulti(_source, "swapfreegb");
|
||||
m_formatter["swapfreegb"] = FormatterType::MemGBFormat;
|
||||
} else if (_source == "mem/swap/used") {
|
||||
// used swap
|
||||
// mb
|
||||
m_map[source] = QString("swapmb");
|
||||
m_formatter[QString("swapmb")] = FormatterType::MemMBFormat;
|
||||
m_map[_source] = "swapmb";
|
||||
m_formatter["swapmb"] = FormatterType::MemMBFormat;
|
||||
// gb
|
||||
m_map.insertMulti(source, QString("swapgb"));
|
||||
m_formatter[QString("swapgb")] = FormatterType::MemGBFormat;
|
||||
} else if (source.startsWith(QString("lmsensors/"))) {
|
||||
m_map.insertMulti(_source, "swapgb");
|
||||
m_formatter["swapgb"] = FormatterType::MemGBFormat;
|
||||
} else if (_source.startsWith("lmsensors/")) {
|
||||
// temperature
|
||||
int index = m_devices[QString("temp")].indexOf(source);
|
||||
int index = m_devices["temp"].indexOf(_source);
|
||||
// HACK on DE initialization there are no units key
|
||||
if (units.isEmpty())
|
||||
return QStringList() << QString("temp%1").arg(index);
|
||||
if (_units.isEmpty())
|
||||
return QStringList({QString("temp%1").arg(index)});
|
||||
if (index > -1) {
|
||||
QString key = QString("temp%1").arg(index);
|
||||
m_map[source] = key;
|
||||
m_formatter[key] = units == QString("°C")
|
||||
? FormatterType::Temperature
|
||||
: FormatterType::Integer;
|
||||
m_map[_source] = key;
|
||||
m_formatter[key] = _units == "°C" ? FormatterType::Temperature
|
||||
: FormatterType::Integer;
|
||||
}
|
||||
} else if (source == QString("Local")) {
|
||||
} else if (_source == "Local") {
|
||||
// time
|
||||
m_map[source] = QString("time");
|
||||
m_formatter[QString("time")] = FormatterType::Time;
|
||||
m_map[_source] = "time";
|
||||
m_formatter["time"] = FormatterType::Time;
|
||||
// custom time
|
||||
m_map.insertMulti(source, QString("ctime"));
|
||||
m_formatter[QString("ctime")] = FormatterType::TimeCustom;
|
||||
m_map.insertMulti(_source, "ctime");
|
||||
m_formatter["ctime"] = FormatterType::TimeCustom;
|
||||
// ISO time
|
||||
m_map.insertMulti(source, QString("isotime"));
|
||||
m_formatter[QString("isotime")] = FormatterType::TimeISO;
|
||||
m_map.insertMulti(_source, "isotime");
|
||||
m_formatter["isotime"] = FormatterType::TimeISO;
|
||||
// long time
|
||||
m_map.insertMulti(source, QString("longtime"));
|
||||
m_formatter[QString("longtime")] = FormatterType::TimeLong;
|
||||
m_map.insertMulti(_source, "longtime");
|
||||
m_formatter["longtime"] = FormatterType::TimeLong;
|
||||
// short time
|
||||
m_map.insertMulti(source, QString("shorttime"));
|
||||
m_formatter[QString("shorttime")] = FormatterType::TimeShort;
|
||||
m_map.insertMulti(_source, "shorttime");
|
||||
m_formatter["shorttime"] = FormatterType::TimeShort;
|
||||
// timestamp
|
||||
m_map.insertMulti(source, QString("tstime"));
|
||||
m_formatter[QString("tstime")] = FormatterType::Timestamp;
|
||||
} else if (source == QString("system/uptime")) {
|
||||
m_map.insertMulti(_source, "tstime");
|
||||
m_formatter["tstime"] = FormatterType::Timestamp;
|
||||
} else if (_source == "system/uptime") {
|
||||
// uptime
|
||||
m_map[source] = QString("uptime");
|
||||
m_formatter[QString("uptime")] = FormatterType::Uptime;
|
||||
m_map[_source] = "uptime";
|
||||
m_formatter["uptime"] = FormatterType::Uptime;
|
||||
// custom uptime
|
||||
m_map.insertMulti(source, QString("cuptime"));
|
||||
m_formatter[QString("cuptime")] = FormatterType::UptimeCustom;
|
||||
} else if (source.startsWith(QString("weather/temperature"))) {
|
||||
m_map.insertMulti(_source, "cuptime");
|
||||
m_formatter["cuptime"] = FormatterType::UptimeCustom;
|
||||
} else if (_source.startsWith("weather/temperature")) {
|
||||
// temperature
|
||||
QString key = source;
|
||||
key.remove(QString("weather/"));
|
||||
m_map[source] = key;
|
||||
QString key = _source;
|
||||
key.remove("weather/");
|
||||
m_map[_source] = key;
|
||||
m_formatter[key] = FormatterType::Temperature;
|
||||
} else if (source.startsWith(QString("weather/"))) {
|
||||
} else if (_source.startsWith("weather/")) {
|
||||
// other weather
|
||||
QString key = source;
|
||||
key.remove(QString("weather/"));
|
||||
m_map[source] = key;
|
||||
QString key = _source;
|
||||
key.remove("weather/");
|
||||
m_map[_source] = key;
|
||||
m_formatter[key] = FormatterType::NoFormat;
|
||||
} else if (source.startsWith(QString("load/load"))) {
|
||||
} else if (_source.startsWith("load/load")) {
|
||||
// load source
|
||||
QString key = source;
|
||||
key.remove(QString("load/"));
|
||||
m_map[source] = key;
|
||||
QString key = _source;
|
||||
key.remove("load/");
|
||||
m_map[_source] = key;
|
||||
m_formatter[key] = FormatterType::Temperature;
|
||||
}
|
||||
|
||||
QStringList foundKeys = keysFromSource(source);
|
||||
QStringList foundKeys = keysFromSource(_source);
|
||||
|
||||
// rewrite formatters for custom ones
|
||||
QStringList customFormattersKeys;
|
||||
@ -586,26 +590,26 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
|
||||
customFormattersKeys = m_customFormatters->definedFormatters();
|
||||
qCInfo(LOG_AW) << "Looking for fprmatters" << foundKeys << "in"
|
||||
<< customFormattersKeys;
|
||||
for (auto key : foundKeys) {
|
||||
for (auto &key : foundKeys) {
|
||||
if (!customFormattersKeys.contains(key))
|
||||
continue;
|
||||
m_formatter[key] = FormatterType::Custom;
|
||||
}
|
||||
|
||||
// drop key from dictionary if no one user requested key required it
|
||||
qCInfo(LOG_AW) << "Looking for keys" << foundKeys << "in" << keys;
|
||||
qCInfo(LOG_AW) << "Looking for keys" << foundKeys << "in" << _keys;
|
||||
bool required
|
||||
= keys.isEmpty() || std::any_of(foundKeys.cbegin(), foundKeys.cend(),
|
||||
[&keys](const QString &key) {
|
||||
return keys.contains(key);
|
||||
});
|
||||
= _keys.isEmpty() || std::any_of(foundKeys.cbegin(), foundKeys.cend(),
|
||||
[&_keys](const QString &key) {
|
||||
return _keys.contains(key);
|
||||
});
|
||||
if (!required) {
|
||||
m_map.remove(source);
|
||||
for (auto key : foundKeys)
|
||||
m_map.remove(_source);
|
||||
for (auto &key : foundKeys)
|
||||
m_formatter.remove(key);
|
||||
}
|
||||
|
||||
return keysFromSource(source);
|
||||
return keysFromSource(_source);
|
||||
}
|
||||
|
||||
|
||||
@ -614,18 +618,18 @@ float AWKeysAggregator::temperature(const float temp) const
|
||||
qCDebug(LOG_AW) << "Temperature value" << temp;
|
||||
|
||||
float converted = temp;
|
||||
if (m_tempUnits == QString("Celsius")) {
|
||||
} else if (m_tempUnits == QString("Fahrenheit")) {
|
||||
if (m_tempUnits == "Celsius") {
|
||||
} else if (m_tempUnits == "Fahrenheit") {
|
||||
converted = temp * 9.0f / 5.0f + 32.0f;
|
||||
} else if (m_tempUnits == QString("Kelvin")) {
|
||||
} else if (m_tempUnits == "Kelvin") {
|
||||
converted = temp + 273.15f;
|
||||
} else if (m_tempUnits == QString("Reaumur")) {
|
||||
} else if (m_tempUnits == "Reaumur") {
|
||||
converted = temp * 0.8f;
|
||||
} else if (m_tempUnits == QString("cm^-1")) {
|
||||
} else if (m_tempUnits == "cm^-1") {
|
||||
converted = (temp + 273.15f) * 0.695f;
|
||||
} else if (m_tempUnits == QString("kJ/mol")) {
|
||||
} else if (m_tempUnits == "kJ/mol") {
|
||||
converted = (temp + 273.15f) * 8.31f;
|
||||
} else if (m_tempUnits == QString("kcal/mol")) {
|
||||
} else if (m_tempUnits == "kcal/mol") {
|
||||
converted = (temp + 273.15f) * 1.98f;
|
||||
} else {
|
||||
qCWarning(LOG_AW) << "Invalid units" << m_tempUnits;
|
||||
|
@ -67,29 +67,29 @@ class AWKeysAggregator : public QObject
|
||||
};
|
||||
|
||||
public:
|
||||
explicit AWKeysAggregator(QObject *parent = nullptr);
|
||||
explicit AWKeysAggregator(QObject *_parent = nullptr);
|
||||
virtual ~AWKeysAggregator();
|
||||
void initFormatters();
|
||||
// get methods
|
||||
QString formatter(const QVariant &data, const QString &key) const;
|
||||
QStringList keysFromSource(const QString &source) const;
|
||||
QString formatter(const QVariant &_data, const QString &_key) const;
|
||||
QStringList keysFromSource(const QString &_source) const;
|
||||
// set methods
|
||||
void setAcOffline(const QString inactive);
|
||||
void setAcOnline(const QString active);
|
||||
void setCustomTime(const QString customTime);
|
||||
void setCustomUptime(const QString customUptime);
|
||||
void setDevices(const QHash<QString, QStringList> devices);
|
||||
void setTempUnits(const QString units);
|
||||
void setTranslate(const bool translate);
|
||||
void setAcOffline(const QString &_inactive);
|
||||
void setAcOnline(const QString &_active);
|
||||
void setCustomTime(const QString &_customTime);
|
||||
void setCustomUptime(const QString &_customUptime);
|
||||
void setDevices(const QHash<QString, QStringList> &_devices);
|
||||
void setTempUnits(const QString &_units);
|
||||
void setTranslate(const bool _translate);
|
||||
|
||||
public slots:
|
||||
QStringList registerSource(const QString &source, const QString &units,
|
||||
const QStringList &keys);
|
||||
QStringList registerSource(const QString &_source, const QString &_units,
|
||||
const QStringList &_keys);
|
||||
|
||||
private:
|
||||
float temperature(const float temp) const;
|
||||
AWFormatterHelper *m_customFormatters = nullptr;
|
||||
QStringList m_timeKeys = QString(TIME_KEYS).split(QChar(','));
|
||||
QStringList m_timeKeys = QString(TIME_KEYS).split(',');
|
||||
// variables
|
||||
QString m_acOffline;
|
||||
QString m_acOnline;
|
||||
|
@ -24,52 +24,51 @@
|
||||
#include "awkeysaggregator.h"
|
||||
|
||||
|
||||
QString AWPatternFunctions::expandLambdas(QString code,
|
||||
AWKeysAggregator *aggregator,
|
||||
const QVariantHash &metadata,
|
||||
const QStringList &usedKeys)
|
||||
QString AWPatternFunctions::expandLambdas(QString _code,
|
||||
AWKeysAggregator *_aggregator,
|
||||
const QVariantHash &_metadata,
|
||||
const QStringList &_usedKeys)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Expand lamdas in" << code;
|
||||
qCDebug(LOG_AW) << "Expand lamdas in" << _code;
|
||||
|
||||
QJSEngine engine;
|
||||
// apply $this values
|
||||
code.replace(QString("$this"), metadata[code].toString());
|
||||
_code.replace("$this", _metadata[_code].toString());
|
||||
// parsed values
|
||||
for (auto lambdaKey : usedKeys)
|
||||
code.replace(QString("$%1").arg(lambdaKey),
|
||||
aggregator->formatter(metadata[lambdaKey], lambdaKey));
|
||||
qCInfo(LOG_AW) << "Expression" << code;
|
||||
QJSValue result = engine.evaluate(code);
|
||||
for (auto &lambdaKey : _usedKeys)
|
||||
_code.replace(QString("$%1").arg(lambdaKey),
|
||||
_aggregator->formatter(_metadata[lambdaKey], lambdaKey));
|
||||
qCInfo(LOG_AW) << "Expression" << _code;
|
||||
QJSValue result = engine.evaluate(_code);
|
||||
if (result.isError()) {
|
||||
qCWarning(LOG_AW) << "Uncaught exception at line"
|
||||
<< result.property("lineNumber").toInt() << ":"
|
||||
<< result.toString();
|
||||
return QString();
|
||||
return "";
|
||||
} else {
|
||||
return result.toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QString AWPatternFunctions::expandTemplates(QString code)
|
||||
QString AWPatternFunctions::expandTemplates(QString _code)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Expand templates in" << code;
|
||||
qCDebug(LOG_AW) << "Expand templates in" << _code;
|
||||
|
||||
// match the following construction $template{{some code here}}
|
||||
QRegularExpression templatesRegexp(
|
||||
QString("\\$template\\{\\{(?<body>.*?)\\}\\}"));
|
||||
QRegularExpression templatesRegexp("\\$template\\{\\{(?<body>.*?)\\}\\}");
|
||||
templatesRegexp.setPatternOptions(
|
||||
QRegularExpression::DotMatchesEverythingOption);
|
||||
|
||||
QRegularExpressionMatchIterator it = templatesRegexp.globalMatch(code);
|
||||
QRegularExpressionMatchIterator it = templatesRegexp.globalMatch(_code);
|
||||
while (it.hasNext()) {
|
||||
QRegularExpressionMatch match = it.next();
|
||||
QString body = match.captured(QString("body"));
|
||||
QString body = match.captured("body");
|
||||
|
||||
QJSEngine engine;
|
||||
qCInfo(LOG_AW) << "Expression" << body;
|
||||
QJSValue result = engine.evaluate(body);
|
||||
QString templateResult = QString("");
|
||||
QString templateResult = "";
|
||||
if (result.isError()) {
|
||||
qCWarning(LOG_AW) << "Uncaught exception at line"
|
||||
<< result.property("lineNumber").toInt() << ":"
|
||||
@ -79,18 +78,18 @@ QString AWPatternFunctions::expandTemplates(QString code)
|
||||
}
|
||||
|
||||
// replace template
|
||||
code.replace(match.captured(), templateResult);
|
||||
_code.replace(match.captured(), templateResult);
|
||||
}
|
||||
|
||||
return code;
|
||||
return _code;
|
||||
}
|
||||
|
||||
|
||||
QList<AWPatternFunctions::AWFunction>
|
||||
AWPatternFunctions::findFunctionCalls(const QString function,
|
||||
const QString code)
|
||||
AWPatternFunctions::findFunctionCalls(const QString &_function,
|
||||
const QString &_code)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Looking for function" << function << "in" << code;
|
||||
qCDebug(LOG_AW) << "Looking for function" << _function << "in" << _code;
|
||||
|
||||
// I suggest the following regex for the internal functions
|
||||
// $aw_function_name<some args here if any>{{function body}}
|
||||
@ -100,34 +99,34 @@ AWPatternFunctions::findFunctionCalls(const QString function,
|
||||
// by using $, e.g. ${
|
||||
QRegularExpression regex(
|
||||
QString("\\$%1\\<(?<args>.*?)\\>\\{\\{(?<body>.*?)\\}\\}")
|
||||
.arg(function));
|
||||
.arg(_function));
|
||||
regex.setPatternOptions(QRegularExpression::DotMatchesEverythingOption);
|
||||
|
||||
QList<AWPatternFunctions::AWFunction> foundFunctions;
|
||||
QRegularExpressionMatchIterator it = regex.globalMatch(code);
|
||||
QRegularExpressionMatchIterator it = regex.globalMatch(_code);
|
||||
while (it.hasNext()) {
|
||||
QRegularExpressionMatch match = it.next();
|
||||
|
||||
AWPatternFunctions::AWFunction metadata;
|
||||
// work with args
|
||||
QString argsString = match.captured(QString("args"));
|
||||
QString argsString = match.captured("args");
|
||||
if (argsString.isEmpty()) {
|
||||
metadata.args = QStringList();
|
||||
} else {
|
||||
// replace '$,' to 0x1d
|
||||
argsString.replace(QString("$,"), QString(0x1d));
|
||||
QStringList args = argsString.split(QChar(','));
|
||||
argsString.replace("$,", QString(0x1d));
|
||||
QStringList args = argsString.split(',');
|
||||
std::for_each(args.begin(), args.end(), [](QString &arg) {
|
||||
arg.replace(QString(0x1d), QString(","));
|
||||
arg.replace(QString(0x1d), ",");
|
||||
});
|
||||
metadata.args = args;
|
||||
}
|
||||
// other variables
|
||||
metadata.body = match.captured(QString("body"));
|
||||
metadata.body = match.captured("body");
|
||||
metadata.what = match.captured();
|
||||
// replace brackets
|
||||
metadata.body.replace(QString("${"), QString("{"));
|
||||
metadata.body.replace(QString("$}"), QString("}"));
|
||||
metadata.body.replace("${", "{");
|
||||
metadata.body.replace("$}", "}");
|
||||
foundFunctions.append(metadata);
|
||||
}
|
||||
|
||||
@ -135,93 +134,93 @@ AWPatternFunctions::findFunctionCalls(const QString function,
|
||||
}
|
||||
|
||||
|
||||
QString AWPatternFunctions::insertAllKeys(QString code, const QStringList keys)
|
||||
QString AWPatternFunctions::insertAllKeys(QString _code,
|
||||
const QStringList &_keys)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Looking for keys in code" << code << "using list"
|
||||
<< keys;
|
||||
qCDebug(LOG_AW) << "Looking for keys in code" << _code << "using list"
|
||||
<< _keys;
|
||||
|
||||
QList<AWPatternFunctions::AWFunction> found
|
||||
= AWPatternFunctions::findFunctionCalls(QString("aw_all"), code);
|
||||
for (auto function : found) {
|
||||
QString separator
|
||||
= function.args.isEmpty() ? QString(",") : function.args.at(0);
|
||||
QStringList required = keys.filter(QRegExp(function.body));
|
||||
= AWPatternFunctions::findFunctionCalls("aw_all", _code);
|
||||
for (auto &function : found) {
|
||||
QString separator = function.args.isEmpty() ? "," : function.args.at(0);
|
||||
QStringList required = _keys.filter(QRegExp(function.body));
|
||||
std::for_each(required.begin(), required.end(), [](QString &value) {
|
||||
value = QString("%1: $%1").arg(value);
|
||||
});
|
||||
|
||||
code.replace(function.what, required.join(separator));
|
||||
_code.replace(function.what, required.join(separator));
|
||||
}
|
||||
|
||||
return code;
|
||||
return _code;
|
||||
}
|
||||
|
||||
|
||||
QString AWPatternFunctions::insertKeyCount(QString code, const QStringList keys)
|
||||
QString AWPatternFunctions::insertKeyCount(QString _code,
|
||||
const QStringList &_keys)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Looking for count in code" << code << "using list"
|
||||
<< keys;
|
||||
qCDebug(LOG_AW) << "Looking for count in code" << _code << "using list"
|
||||
<< _keys;
|
||||
|
||||
QList<AWPatternFunctions::AWFunction> found
|
||||
= AWPatternFunctions::findFunctionCalls(QString("aw_count"), code);
|
||||
for (auto function : found) {
|
||||
int count = keys.filter(QRegExp(function.body)).count();
|
||||
= AWPatternFunctions::findFunctionCalls("aw_count", _code);
|
||||
for (auto &function : found) {
|
||||
int count = _keys.filter(QRegExp(function.body)).count();
|
||||
|
||||
code.replace(function.what, QString::number(count));
|
||||
_code.replace(function.what, QString::number(count));
|
||||
}
|
||||
|
||||
return code;
|
||||
return _code;
|
||||
}
|
||||
|
||||
|
||||
QString AWPatternFunctions::insertKeyNames(QString code, const QStringList keys)
|
||||
QString AWPatternFunctions::insertKeyNames(QString _code,
|
||||
const QStringList &_keys)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Looking for key names in code" << code << "using list"
|
||||
<< keys;
|
||||
qCDebug(LOG_AW) << "Looking for key names in code" << _code << "using list"
|
||||
<< _keys;
|
||||
|
||||
QList<AWPatternFunctions::AWFunction> found
|
||||
= AWPatternFunctions::findFunctionCalls(QString("aw_names"), code);
|
||||
for (auto function : found) {
|
||||
QString separator
|
||||
= function.args.isEmpty() ? QString(",") : function.args.at(0);
|
||||
QStringList required = keys.filter(QRegExp(function.body));
|
||||
= AWPatternFunctions::findFunctionCalls("aw_names", _code);
|
||||
for (auto &function : found) {
|
||||
QString separator = function.args.isEmpty() ? "," : function.args.at(0);
|
||||
QStringList required = _keys.filter(QRegExp(function.body));
|
||||
|
||||
code.replace(function.what, required.join(separator));
|
||||
_code.replace(function.what, required.join(separator));
|
||||
}
|
||||
|
||||
return code;
|
||||
return _code;
|
||||
}
|
||||
|
||||
|
||||
QString AWPatternFunctions::insertKeys(QString code, const QStringList keys)
|
||||
QString AWPatternFunctions::insertKeys(QString _code, const QStringList &_keys)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Looking for keys in code" << code << "using list"
|
||||
<< keys;
|
||||
qCDebug(LOG_AW) << "Looking for keys in code" << _code << "using list"
|
||||
<< _keys;
|
||||
|
||||
QList<AWPatternFunctions::AWFunction> found
|
||||
= AWPatternFunctions::findFunctionCalls(QString("aw_keys"), code);
|
||||
for (auto function : found) {
|
||||
QString separator
|
||||
= function.args.isEmpty() ? QString(",") : function.args.at(0);
|
||||
QStringList required = keys.filter(QRegExp(function.body));
|
||||
= AWPatternFunctions::findFunctionCalls("aw_keys", _code);
|
||||
for (auto &function : found) {
|
||||
QString separator = function.args.isEmpty() ? "," : function.args.at(0);
|
||||
QStringList required = _keys.filter(QRegExp(function.body));
|
||||
std::for_each(required.begin(), required.end(), [](QString &value) {
|
||||
value = QString("$%1").arg(value);
|
||||
});
|
||||
|
||||
code.replace(function.what, required.join(separator));
|
||||
_code.replace(function.what, required.join(separator));
|
||||
}
|
||||
|
||||
return code;
|
||||
return _code;
|
||||
}
|
||||
|
||||
|
||||
QString AWPatternFunctions::insertMacros(QString code)
|
||||
QString AWPatternFunctions::insertMacros(QString _code)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Looking for macros in code" << code;
|
||||
qCDebug(LOG_AW) << "Looking for macros in code" << _code;
|
||||
|
||||
QList<AWPatternFunctions::AWFunction> found
|
||||
= AWPatternFunctions::findFunctionCalls(QString("aw_macro"), code);
|
||||
for (auto macro : found) {
|
||||
= AWPatternFunctions::findFunctionCalls("aw_macro", _code);
|
||||
for (auto ¯o : found) {
|
||||
// get macro params
|
||||
if (macro.args.isEmpty()) {
|
||||
qCWarning(LOG_AW) << "No macro name found for" << macro.what;
|
||||
@ -231,12 +230,12 @@ QString AWPatternFunctions::insertMacros(QString code)
|
||||
// find macro usage
|
||||
QList<AWPatternFunctions::AWFunction> macroUsage
|
||||
= AWPatternFunctions::findFunctionCalls(
|
||||
QString("aw_macro_%1").arg(name), code);
|
||||
for (auto function : macroUsage) {
|
||||
QString("aw_macro_%1").arg(name), _code);
|
||||
for (auto &function : macroUsage) {
|
||||
if (function.args.count() != macro.args.count()) {
|
||||
qCWarning(LOG_AW) << "Invalid args count found for call"
|
||||
<< function.what << "with macro"
|
||||
<< macro.what;
|
||||
qCWarning(LOG_AW)
|
||||
<< "Invalid args count found for call" << function.what
|
||||
<< "with macro" << macro.what;
|
||||
continue;
|
||||
}
|
||||
// generate body to replace
|
||||
@ -248,31 +247,33 @@ QString AWPatternFunctions::insertMacros(QString code)
|
||||
function.args.at(index));
|
||||
});
|
||||
// do replace
|
||||
code.replace(function.what, result);
|
||||
_code.replace(function.what, result);
|
||||
}
|
||||
|
||||
// remove macro from source pattern
|
||||
code.remove(macro.what);
|
||||
_code.remove(macro.what);
|
||||
}
|
||||
|
||||
return code;
|
||||
return _code;
|
||||
}
|
||||
|
||||
|
||||
QStringList AWPatternFunctions::findKeys(const QString code,
|
||||
const QStringList keys,
|
||||
const bool isBars)
|
||||
QStringList AWPatternFunctions::findKeys(const QString &_code,
|
||||
const QStringList &_keys,
|
||||
const bool _isBars)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Looking for keys in code" << code << "using list"
|
||||
<< keys;
|
||||
qCDebug(LOG_AW) << "Looking for keys in code" << _code << "using list"
|
||||
<< _keys;
|
||||
|
||||
QStringList selectedKeys;
|
||||
for (auto key : keys)
|
||||
if ((key.startsWith(QString("bar")) == isBars)
|
||||
&& (code.contains(QString("$%1").arg(key)))) {
|
||||
QString replacedCode = _code;
|
||||
for (auto &key : _keys)
|
||||
if ((key.startsWith("bar") == _isBars)
|
||||
&& (replacedCode.contains(QString("$%1").arg(key)))) {
|
||||
qCInfo(LOG_AW) << "Found key" << key << "with bar enabled"
|
||||
<< isBars;
|
||||
<< _isBars;
|
||||
selectedKeys.append(key);
|
||||
replacedCode.replace(QString("$%1").arg(key), "");
|
||||
}
|
||||
if (selectedKeys.isEmpty())
|
||||
qCWarning(LOG_AW) << "No keys found";
|
||||
@ -281,20 +282,20 @@ QStringList AWPatternFunctions::findKeys(const QString code,
|
||||
}
|
||||
|
||||
|
||||
QStringList AWPatternFunctions::findLambdas(const QString code)
|
||||
QStringList AWPatternFunctions::findLambdas(const QString &_code)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Looking for lambdas in code" << code;
|
||||
qCDebug(LOG_AW) << "Looking for lambdas in code" << _code;
|
||||
|
||||
QStringList selectedKeys;
|
||||
// match the following construction ${{some code here}}
|
||||
QRegularExpression lambdaRegexp(QString("\\$\\{\\{(?<body>.*?)\\}\\}"));
|
||||
QRegularExpression lambdaRegexp("\\$\\{\\{(?<body>.*?)\\}\\}");
|
||||
lambdaRegexp.setPatternOptions(
|
||||
QRegularExpression::DotMatchesEverythingOption);
|
||||
|
||||
QRegularExpressionMatchIterator it = lambdaRegexp.globalMatch(code);
|
||||
QRegularExpressionMatchIterator it = lambdaRegexp.globalMatch(_code);
|
||||
while (it.hasNext()) {
|
||||
QRegularExpressionMatch match = it.next();
|
||||
QString lambda = match.captured(QString("body"));
|
||||
QString lambda = match.captured("body");
|
||||
|
||||
// append
|
||||
qCInfo(LOG_AW) << "Found lambda" << lambda;
|
||||
|
@ -34,20 +34,21 @@ typedef struct {
|
||||
} AWFunction;
|
||||
|
||||
// insert methods
|
||||
QString expandLambdas(QString code, AWKeysAggregator *aggregator,
|
||||
const QVariantHash &metadata,
|
||||
const QStringList &usedKeys);
|
||||
QString expandTemplates(QString code);
|
||||
QList<AWFunction> findFunctionCalls(const QString function, const QString code);
|
||||
QString insertAllKeys(QString code, const QStringList keys);
|
||||
QString insertKeyCount(QString code, const QStringList keys);
|
||||
QString insertKeyNames(QString code, const QStringList keys);
|
||||
QString insertKeys(QString code, const QStringList keys);
|
||||
QString insertMacros(QString code);
|
||||
QString expandLambdas(QString _code, AWKeysAggregator *_aggregator,
|
||||
const QVariantHash &_metadata,
|
||||
const QStringList &_usedKeys);
|
||||
QString expandTemplates(QString _code);
|
||||
QList<AWFunction> findFunctionCalls(const QString &_function,
|
||||
const QString &_code);
|
||||
QString insertAllKeys(QString _code, const QStringList &_keys);
|
||||
QString insertKeyCount(QString _code, const QStringList &_keys);
|
||||
QString insertKeyNames(QString _code, const QStringList &_keys);
|
||||
QString insertKeys(QString _code, const QStringList &_keys);
|
||||
QString insertMacros(QString _code);
|
||||
// find methods
|
||||
QStringList findKeys(const QString code, const QStringList keys,
|
||||
const bool isBars);
|
||||
QStringList findLambdas(const QString code);
|
||||
QStringList findKeys(const QString &_code, const QStringList &_keys,
|
||||
const bool _isBars);
|
||||
QStringList findLambdas(const QString &_code);
|
||||
};
|
||||
|
||||
|
||||
|
192
sources/awesome-widget/plugin/awtelemetryhandler.cpp
Normal file
192
sources/awesome-widget/plugin/awtelemetryhandler.cpp
Normal file
@ -0,0 +1,192 @@
|
||||
/***************************************************************************
|
||||
* 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 "awtelemetryhandler.h"
|
||||
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonParseError>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
#include <QNetworkRequest>
|
||||
#include <QSettings>
|
||||
#include <QStandardPaths>
|
||||
#include <QUuid>
|
||||
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
AWTelemetryHandler::AWTelemetryHandler(QObject *_parent,
|
||||
const QString &_clientId)
|
||||
: QObject(_parent)
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
|
||||
m_localFile = QString("%1/awesomewidgets/telemetry.ini")
|
||||
.arg(QStandardPaths::writableLocation(
|
||||
QStandardPaths::GenericDataLocation));
|
||||
|
||||
// override client id if any
|
||||
if (!_clientId.isEmpty())
|
||||
m_clientId = _clientId;
|
||||
}
|
||||
|
||||
|
||||
AWTelemetryHandler::~AWTelemetryHandler()
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
}
|
||||
|
||||
|
||||
QStringList AWTelemetryHandler::get(const QString &_group) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Get stored data for group" << _group;
|
||||
|
||||
QStringList values;
|
||||
|
||||
QSettings settings(m_localFile, QSettings::IniFormat);
|
||||
settings.beginGroup(_group);
|
||||
for (auto &key : settings.childKeys())
|
||||
values.append(settings.value(key).toString());
|
||||
settings.endGroup();
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
|
||||
QString AWTelemetryHandler::getLast(const QString &_group) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Get last stored data for group" << _group;
|
||||
|
||||
return get(_group).last();
|
||||
}
|
||||
|
||||
|
||||
void AWTelemetryHandler::init(const int _count, const bool _enableRemote,
|
||||
const QString &_clientId)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Init telemetry with count" << _count << "enable remote"
|
||||
<< _enableRemote << "client ID" << _clientId;
|
||||
|
||||
m_storeCount = _count;
|
||||
m_uploadEnabled = _enableRemote;
|
||||
m_clientId = _clientId;
|
||||
}
|
||||
|
||||
|
||||
bool AWTelemetryHandler::put(const QString &_group, const QString &_value) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Store data with group" << _group << "and value"
|
||||
<< _value;
|
||||
|
||||
QSettings settings(m_localFile, QSettings::IniFormat);
|
||||
settings.beginGroup(_group);
|
||||
// values will be stored as num=value inside specified group
|
||||
// load all values to memory
|
||||
QStringList saved;
|
||||
for (auto &key : settings.childKeys())
|
||||
saved.append(settings.value(key).toString());
|
||||
// check if this value is already saved
|
||||
if (saved.contains(_value)) {
|
||||
qCInfo(LOG_AW) << "Configuration" << _value << "for group" << _group
|
||||
<< "is already saved";
|
||||
return false;
|
||||
}
|
||||
saved.append(_value);
|
||||
// remove old ones
|
||||
while (saved.count() > m_storeCount)
|
||||
saved.takeFirst();
|
||||
// clear group
|
||||
settings.remove("");
|
||||
// and save now
|
||||
for (auto &val : saved) {
|
||||
QString key = getKey(settings.childKeys().count());
|
||||
settings.setValue(key, val);
|
||||
}
|
||||
|
||||
// sync settings
|
||||
settings.endGroup();
|
||||
settings.sync();
|
||||
// return status
|
||||
return (settings.status() == QSettings::NoError);
|
||||
}
|
||||
|
||||
|
||||
void AWTelemetryHandler::uploadTelemetry(const QString &_group,
|
||||
const QString &_value)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Upload data with group" << _group << "and value"
|
||||
<< _value;
|
||||
if (!m_uploadEnabled) {
|
||||
qCInfo(LOG_AW) << "Upload disabled by configuration";
|
||||
return;
|
||||
}
|
||||
|
||||
QNetworkAccessManager *manager = new QNetworkAccessManager(nullptr);
|
||||
connect(manager, SIGNAL(finished(QNetworkReply *)), this,
|
||||
SLOT(telemetryReplyRecieved(QNetworkReply *)));
|
||||
|
||||
QUrl url(REMOTE_TELEMETRY_URL);
|
||||
QNetworkRequest request(url);
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||
|
||||
// generate payload
|
||||
QVariantMap payload;
|
||||
payload["api"] = AW_TELEMETRY_API;
|
||||
payload["client_id"] = m_clientId;
|
||||
payload["metadata"] = _value;
|
||||
payload["type"] = _group;
|
||||
// convert to QByteArray to send request
|
||||
QByteArray data
|
||||
= QJsonDocument::fromVariant(payload).toJson(QJsonDocument::Compact);
|
||||
qCInfo(LOG_AW) << "Send request with body" << data.data() << "and size"
|
||||
<< data.size();
|
||||
|
||||
manager->post(request, data);
|
||||
}
|
||||
|
||||
|
||||
void AWTelemetryHandler::telemetryReplyRecieved(QNetworkReply *_reply)
|
||||
{
|
||||
if (_reply->error() != QNetworkReply::NoError) {
|
||||
qCWarning(LOG_AW) << "An error occurs" << _reply->error()
|
||||
<< "with message" << _reply->errorString();
|
||||
return;
|
||||
}
|
||||
|
||||
QJsonParseError error;
|
||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(_reply->readAll(), &error);
|
||||
if (error.error != QJsonParseError::NoError) {
|
||||
qCWarning(LOG_AW) << "Parse error" << error.errorString();
|
||||
return;
|
||||
}
|
||||
_reply->deleteLater();
|
||||
|
||||
// convert to map
|
||||
QVariantMap response = jsonDoc.toVariant().toMap();
|
||||
QString message = response["message"].toString();
|
||||
qCInfo(LOG_AW) << "Server reply on telemetry" << message;
|
||||
|
||||
return emit(replyReceived(message));
|
||||
}
|
||||
|
||||
|
||||
QString AWTelemetryHandler::getKey(const int _count) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Get key for keys count" << _count;
|
||||
|
||||
return QString("%1").arg(_count, 3, 10, QChar('0'));
|
||||
}
|
62
sources/awesome-widget/plugin/awtelemetryhandler.h
Normal file
62
sources/awesome-widget/plugin/awtelemetryhandler.h
Normal file
@ -0,0 +1,62 @@
|
||||
/***************************************************************************
|
||||
* 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 AWTELEMETRYHANDLER_H
|
||||
#define AWTELEMETRYHANDLER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QtCore/QVariant>
|
||||
|
||||
|
||||
class QAbstractButton;
|
||||
class QNetworkReply;
|
||||
|
||||
class AWTelemetryHandler : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
const char *REMOTE_TELEMETRY_URL = "https://arcanis.me/telemetry";
|
||||
|
||||
explicit AWTelemetryHandler(QObject *_parent = nullptr,
|
||||
const QString &_clientId = "");
|
||||
virtual ~AWTelemetryHandler();
|
||||
Q_INVOKABLE QStringList get(const QString &_group) const;
|
||||
Q_INVOKABLE QString getLast(const QString &_group) const;
|
||||
Q_INVOKABLE void init(const int _count, const bool _enableRemote,
|
||||
const QString &_clientId);
|
||||
Q_INVOKABLE bool put(const QString &_group, const QString &_value) const;
|
||||
Q_INVOKABLE void uploadTelemetry(const QString &_group,
|
||||
const QString &_value);
|
||||
|
||||
signals:
|
||||
void replyReceived(const QString &_message);
|
||||
|
||||
private slots:
|
||||
void telemetryReplyRecieved(QNetworkReply *_reply);
|
||||
|
||||
private:
|
||||
QString getKey(const int _count) const;
|
||||
QString m_clientId;
|
||||
QString m_localFile;
|
||||
int m_storeCount = 0;
|
||||
bool m_uploadEnabled = false;
|
||||
};
|
||||
|
||||
|
||||
#endif /* AWTELEMETRYHANDLER_H */
|
@ -26,13 +26,12 @@
|
||||
#include <QNetworkReply>
|
||||
#include <QNetworkRequest>
|
||||
#include <QSettings>
|
||||
#include <QtConcurrent/QtConcurrent>
|
||||
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
AWUpdateHelper::AWUpdateHelper(QObject *parent)
|
||||
: QObject(parent)
|
||||
AWUpdateHelper::AWUpdateHelper(QObject *_parent)
|
||||
: QObject(_parent)
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
|
||||
@ -49,16 +48,16 @@ AWUpdateHelper::~AWUpdateHelper()
|
||||
}
|
||||
|
||||
|
||||
void AWUpdateHelper::checkUpdates(const bool showAnyway)
|
||||
void AWUpdateHelper::checkUpdates(const bool _showAnyway)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Show anyway" << showAnyway;
|
||||
qCDebug(LOG_AW) << "Show anyway" << _showAnyway;
|
||||
|
||||
// showAnyway options requires to show message if no updates found on direct
|
||||
// request. In case of automatic check no message will be shown
|
||||
QNetworkAccessManager *manager = new QNetworkAccessManager(nullptr);
|
||||
connect(manager, &QNetworkAccessManager::finished,
|
||||
[showAnyway, this](QNetworkReply *reply) {
|
||||
return versionReplyRecieved(reply, showAnyway);
|
||||
[_showAnyway, this](QNetworkReply *reply) {
|
||||
return versionReplyRecieved(reply, _showAnyway);
|
||||
});
|
||||
|
||||
manager->get(QNetworkRequest(QUrl(VERSION_API)));
|
||||
@ -69,17 +68,16 @@ bool AWUpdateHelper::checkVersion()
|
||||
{
|
||||
QSettings settings(m_genericConfig, QSettings::IniFormat);
|
||||
QVersionNumber version = QVersionNumber::fromString(
|
||||
settings.value(QString("Version"), QString(VERSION)).toString());
|
||||
settings.value("Version", QString(VERSION)).toString());
|
||||
// update version
|
||||
settings.setValue(QString("Version"), QString(VERSION));
|
||||
settings.setValue("Version", QString(VERSION));
|
||||
settings.sync();
|
||||
qCInfo(LOG_AW) << "Found version" << version << "actual one is"
|
||||
<< m_foundVersion;
|
||||
|
||||
if ((version != m_foundVersion) && (!QString(CHANGELOG).isEmpty())) {
|
||||
genMessageBox(i18n("Changelog of %1", QString(VERSION)),
|
||||
QString(CHANGELOG).replace(QChar('@'), QChar('\n')),
|
||||
QMessageBox::Ok)
|
||||
genMessageBox(i18n("Changelog of %1", VERSION),
|
||||
QString(CHANGELOG).replace('@', '\n'), QMessageBox::Ok)
|
||||
->open();
|
||||
return true;
|
||||
} else if (version != m_foundVersion) {
|
||||
@ -93,12 +91,12 @@ bool AWUpdateHelper::checkVersion()
|
||||
}
|
||||
|
||||
|
||||
void AWUpdateHelper::showInfo(const QVersionNumber version)
|
||||
void AWUpdateHelper::showInfo(const QVersionNumber &_version)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Version" << version;
|
||||
qCDebug(LOG_AW) << "Version" << _version;
|
||||
|
||||
QString text
|
||||
= i18n("You are using the actual version %1", version.toString());
|
||||
= i18n("You are using the actual version %1", _version.toString());
|
||||
if (!QString(COMMIT_SHA).isEmpty())
|
||||
text += QString(" (%1)").arg(QString(COMMIT_SHA));
|
||||
return genMessageBox(i18n("No new version found"), text, QMessageBox::Ok)
|
||||
@ -106,16 +104,16 @@ void AWUpdateHelper::showInfo(const QVersionNumber version)
|
||||
}
|
||||
|
||||
|
||||
void AWUpdateHelper::showUpdates(const QVersionNumber version)
|
||||
void AWUpdateHelper::showUpdates(const QVersionNumber &_version)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Version" << version;
|
||||
qCDebug(LOG_AW) << "Version" << _version;
|
||||
|
||||
QString text;
|
||||
text += i18n("Current version : %1", QString(VERSION));
|
||||
text += i18n("Current version : %1", VERSION);
|
||||
text += QString(COMMIT_SHA).isEmpty()
|
||||
? QString("\n")
|
||||
? "\n"
|
||||
: QString(" (%1)\n").arg(QString(COMMIT_SHA));
|
||||
text += i18n("New version : %1", version.toString()) + QString("\n\n");
|
||||
text += i18n("New version : %1", _version.toString()) + "\n\n";
|
||||
text += i18n("Click \"Ok\" to download");
|
||||
|
||||
genMessageBox(i18n("There are updates"), text,
|
||||
@ -124,10 +122,10 @@ void AWUpdateHelper::showUpdates(const QVersionNumber version)
|
||||
}
|
||||
|
||||
|
||||
void AWUpdateHelper::userReplyOnUpdates(QAbstractButton *button)
|
||||
void AWUpdateHelper::userReplyOnUpdates(QAbstractButton *_button)
|
||||
{
|
||||
QMessageBox::ButtonRole ret
|
||||
= static_cast<QMessageBox *>(sender())->buttonRole(button);
|
||||
= static_cast<QMessageBox *>(sender())->buttonRole(_button);
|
||||
qCInfo(LOG_AW) << "User select" << ret;
|
||||
|
||||
switch (ret) {
|
||||
@ -142,50 +140,53 @@ void AWUpdateHelper::userReplyOnUpdates(QAbstractButton *button)
|
||||
}
|
||||
|
||||
|
||||
void AWUpdateHelper::versionReplyRecieved(QNetworkReply *reply,
|
||||
const bool showAnyway)
|
||||
void AWUpdateHelper::versionReplyRecieved(QNetworkReply *_reply,
|
||||
const bool _showAnyway)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Return code" << reply->error() << "with message"
|
||||
<< reply->errorString() << "and show anyway" << showAnyway;
|
||||
qCDebug(LOG_AW) << "Show message anyway" << _showAnyway;
|
||||
if (_reply->error() != QNetworkReply::NoError) {
|
||||
qCWarning(LOG_AW) << "An error occurs" << _reply->error()
|
||||
<< "with message" << _reply->errorString();
|
||||
return;
|
||||
}
|
||||
|
||||
QJsonParseError error;
|
||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(reply->readAll(), &error);
|
||||
if ((reply->error() != QNetworkReply::NoError)
|
||||
|| (error.error != QJsonParseError::NoError)) {
|
||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(_reply->readAll(), &error);
|
||||
if (error.error != QJsonParseError::NoError) {
|
||||
qCWarning(LOG_AW) << "Parse error" << error.errorString();
|
||||
return;
|
||||
}
|
||||
reply->deleteLater();
|
||||
_reply->deleteLater();
|
||||
|
||||
// convert to map
|
||||
QVariantMap firstRelease = jsonDoc.toVariant().toList().first().toMap();
|
||||
QString version = firstRelease[QString("tag_name")].toString();
|
||||
version.remove(QString("V."));
|
||||
QString version = firstRelease["tag_name"].toString();
|
||||
version.remove("V.");
|
||||
m_foundVersion = QVersionNumber::fromString(version);
|
||||
qCInfo(LOG_AW) << "Update found version to" << m_foundVersion;
|
||||
|
||||
QVersionNumber oldVersion = QVersionNumber::fromString(VERSION);
|
||||
if (oldVersion < m_foundVersion)
|
||||
return showUpdates(m_foundVersion);
|
||||
else if (showAnyway)
|
||||
else if (_showAnyway)
|
||||
return showInfo(m_foundVersion);
|
||||
}
|
||||
|
||||
|
||||
// additional method which is used to show message box which does not block UI
|
||||
QMessageBox *
|
||||
AWUpdateHelper::genMessageBox(const QString title, const QString body,
|
||||
const QMessageBox::StandardButtons buttons)
|
||||
AWUpdateHelper::genMessageBox(const QString &_title, const QString &_body,
|
||||
const QMessageBox::StandardButtons _buttons)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Construct message box with title" << title << "and body"
|
||||
<< body;
|
||||
qCDebug(LOG_AW) << "Construct message box with title" << _title
|
||||
<< "and body" << _body;
|
||||
|
||||
QMessageBox *msgBox = new QMessageBox(nullptr);
|
||||
msgBox->setAttribute(Qt::WA_DeleteOnClose);
|
||||
msgBox->setModal(false);
|
||||
msgBox->setWindowTitle(title);
|
||||
msgBox->setText(body);
|
||||
msgBox->setStandardButtons(buttons);
|
||||
msgBox->setWindowTitle(_title);
|
||||
msgBox->setText(_body);
|
||||
msgBox->setStandardButtons(_buttons);
|
||||
msgBox->setIcon(QMessageBox::Information);
|
||||
|
||||
return msgBox;
|
||||
|
@ -31,20 +31,20 @@ class AWUpdateHelper : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AWUpdateHelper(QObject *parent = nullptr);
|
||||
explicit AWUpdateHelper(QObject *_parent = nullptr);
|
||||
virtual ~AWUpdateHelper();
|
||||
void checkUpdates(const bool showAnyway = false);
|
||||
void checkUpdates(const bool _showAnyway = false);
|
||||
bool checkVersion();
|
||||
|
||||
private slots:
|
||||
void showInfo(const QVersionNumber version);
|
||||
void showUpdates(const QVersionNumber version);
|
||||
void userReplyOnUpdates(QAbstractButton *button);
|
||||
void versionReplyRecieved(QNetworkReply *reply, const bool showAnyway);
|
||||
void showInfo(const QVersionNumber &_version);
|
||||
void showUpdates(const QVersionNumber &_version);
|
||||
void userReplyOnUpdates(QAbstractButton *_button);
|
||||
void versionReplyRecieved(QNetworkReply *_reply, const bool _showAnyway);
|
||||
|
||||
private:
|
||||
QMessageBox *genMessageBox(const QString title, const QString body,
|
||||
const QMessageBox::StandardButtons buttons);
|
||||
QMessageBox *genMessageBox(const QString &_title, const QString &_body,
|
||||
const QMessageBox::StandardButtons _buttons);
|
||||
QVersionNumber m_foundVersion;
|
||||
QString m_genericConfig;
|
||||
};
|
||||
|
@ -19,6 +19,7 @@ set(SUBPROJECT_FORMATTERS ${CMAKE_CURRENT_SOURCE_DIR}/formatters)
|
||||
set(SUBPROJECT_GRAPHITEMS ${CMAKE_CURRENT_SOURCE_DIR}/desktops)
|
||||
set(SUBPROJECT_QUOTES ${CMAKE_CURRENT_SOURCE_DIR}/quotes)
|
||||
set(SUBPROJECT_SCRIPTS ${CMAKE_CURRENT_SOURCE_DIR}/scripts)
|
||||
set(SUBPROJECT_REQUESTS ${CMAKE_CURRENT_SOURCE_DIR}/requests)
|
||||
set(SUBPROJECT_UPGRADE ${CMAKE_CURRENT_SOURCE_DIR}/upgrade)
|
||||
set(SUBPROJECT_WEATHER ${CMAKE_CURRENT_SOURCE_DIR}/weather)
|
||||
file(GLOB SUBPROJECT_WEATHER_JSON_IN *.json)
|
||||
@ -37,6 +38,7 @@ install(DIRECTORY ${SUBPROJECT_FORMATTERS} DESTINATION ${DATA_INSTALL_DIR}/${PRO
|
||||
install(DIRECTORY ${SUBPROJECT_GRAPHITEMS} DESTINATION ${DATA_INSTALL_DIR}/${PROJECT_NAME})
|
||||
install(DIRECTORY ${SUBPROJECT_QUOTES} DESTINATION ${DATA_INSTALL_DIR}/${PROJECT_NAME})
|
||||
install(DIRECTORY ${SUBPROJECT_SCRIPTS} DESTINATION ${DATA_INSTALL_DIR}/${PROJECT_NAME})
|
||||
install(DIRECTORY ${SUBPROJECT_REQUESTS} DESTINATION ${DATA_INSTALL_DIR}/${PROJECT_NAME})
|
||||
install(DIRECTORY ${SUBPROJECT_UPGRADE} DESTINATION ${DATA_INSTALL_DIR}/${PROJECT_NAME})
|
||||
install(DIRECTORY ${SUBPROJECT_WEATHER} DESTINATION ${DATA_INSTALL_DIR}/${PROJECT_NAME})
|
||||
install(FILES ${SUBPROJECT_INI} DESTINATION ${CONFIG_INSTALL_DIR})
|
||||
|
@ -18,21 +18,23 @@
|
||||
#include "abstractextitem.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QLocalServer>
|
||||
#include <QSettings>
|
||||
#include <QStandardPaths>
|
||||
#include <QTime>
|
||||
|
||||
#include "abstractextitemaggregator.h"
|
||||
#include "awdebug.h"
|
||||
#include "qcronscheduler.h"
|
||||
|
||||
|
||||
AbstractExtItem::AbstractExtItem(QWidget *parent, const QString filePath)
|
||||
: QDialog(parent)
|
||||
, m_fileName(filePath)
|
||||
AbstractExtItem::AbstractExtItem(QWidget *_parent, const QString &_filePath)
|
||||
: QDialog(_parent)
|
||||
, m_fileName(_filePath)
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
qCDebug(LOG_LIB) << "Desktop name" << filePath;
|
||||
qCDebug(LOG_LIB) << "Desktop name" << _filePath;
|
||||
|
||||
m_name = m_fileName;
|
||||
}
|
||||
@ -41,6 +43,12 @@ AbstractExtItem::AbstractExtItem(QWidget *parent, const QString filePath)
|
||||
AbstractExtItem::~AbstractExtItem()
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
if (m_socket) {
|
||||
m_socket->close();
|
||||
m_socket->removeServer(socket());
|
||||
delete m_socket;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -63,8 +71,29 @@ void AbstractExtItem::copyDefaults(AbstractExtItem *_other) const
|
||||
_other->setActive(isActive());
|
||||
_other->setApiVersion(apiVersion());
|
||||
_other->setComment(comment());
|
||||
_other->setCron(cron());
|
||||
_other->setInterval(interval());
|
||||
_other->setName(name());
|
||||
_other->setSocket(socket());
|
||||
}
|
||||
|
||||
|
||||
void AbstractExtItem::startTimer()
|
||||
{
|
||||
if (!socket().isEmpty())
|
||||
// check if there is active socket setup
|
||||
return;
|
||||
else if (!cron().isEmpty())
|
||||
// check if there is active scheduler
|
||||
return;
|
||||
else if (m_times == 1)
|
||||
// check if it is time to update
|
||||
emit(requestDataUpdate());
|
||||
|
||||
// update counter value
|
||||
if (m_times >= interval())
|
||||
m_times = 0;
|
||||
m_times++;
|
||||
}
|
||||
|
||||
|
||||
@ -95,6 +124,12 @@ QString AbstractExtItem::comment() const
|
||||
}
|
||||
|
||||
|
||||
QString AbstractExtItem::cron() const
|
||||
{
|
||||
return m_cron;
|
||||
}
|
||||
|
||||
|
||||
QString AbstractExtItem::fileName() const
|
||||
{
|
||||
return m_fileName;
|
||||
@ -125,7 +160,13 @@ int AbstractExtItem::number() const
|
||||
}
|
||||
|
||||
|
||||
QString AbstractExtItem::tag(const QString _type) const
|
||||
QString AbstractExtItem::socket() const
|
||||
{
|
||||
return m_socketFile;
|
||||
}
|
||||
|
||||
|
||||
QString AbstractExtItem::tag(const QString &_type) const
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Tag type" << _type;
|
||||
|
||||
@ -149,7 +190,7 @@ void AbstractExtItem::setActive(const bool _state)
|
||||
}
|
||||
|
||||
|
||||
void AbstractExtItem::setComment(const QString _comment)
|
||||
void AbstractExtItem::setComment(const QString &_comment)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Comment" << _comment;
|
||||
|
||||
@ -157,6 +198,28 @@ void AbstractExtItem::setComment(const QString _comment)
|
||||
}
|
||||
|
||||
|
||||
void AbstractExtItem::setCron(const QString &_cron)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Cron string" << _cron;
|
||||
// deinit module first
|
||||
if (m_scheduler) {
|
||||
disconnect(m_scheduler, SIGNAL(activated()), this,
|
||||
SIGNAL(requestDataUpdate()));
|
||||
delete m_scheduler;
|
||||
}
|
||||
|
||||
m_cron = _cron;
|
||||
if (cron().isEmpty())
|
||||
return;
|
||||
|
||||
// init scheduler
|
||||
m_scheduler = new QCronScheduler(this);
|
||||
m_scheduler->parse(cron());
|
||||
connect(m_scheduler, SIGNAL(activated()), this,
|
||||
SIGNAL(requestDataUpdate()));
|
||||
}
|
||||
|
||||
|
||||
void AbstractExtItem::setInterval(const int _interval)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Interval" << _interval;
|
||||
@ -167,7 +230,7 @@ void AbstractExtItem::setInterval(const int _interval)
|
||||
}
|
||||
|
||||
|
||||
void AbstractExtItem::setName(const QString _name)
|
||||
void AbstractExtItem::setName(const QString &_name)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Name" << _name;
|
||||
|
||||
@ -196,20 +259,55 @@ void AbstractExtItem::setNumber(int _number)
|
||||
}
|
||||
|
||||
|
||||
void AbstractExtItem::setSocket(const QString &_socket)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Socket" << _socket;
|
||||
// remove old socket first
|
||||
deinitSocket();
|
||||
|
||||
m_socketFile = _socket;
|
||||
}
|
||||
|
||||
|
||||
void AbstractExtItem::deinitSocket()
|
||||
{
|
||||
if (!m_socket)
|
||||
return;
|
||||
|
||||
m_socket->close();
|
||||
m_socket->removeServer(socket());
|
||||
delete m_socket;
|
||||
disconnect(m_socket, SIGNAL(newConnection()), this,
|
||||
SLOT(newConnectionReceived()));
|
||||
}
|
||||
|
||||
|
||||
void AbstractExtItem::initSocket()
|
||||
{
|
||||
// remove old socket first
|
||||
deinitSocket();
|
||||
|
||||
m_socket = new QLocalServer(this);
|
||||
bool listening = m_socket->listen(socket());
|
||||
qCInfo(LOG_LIB) << "Server listening on" << socket() << listening;
|
||||
connect(m_socket, SIGNAL(newConnection()), this,
|
||||
SLOT(newConnectionReceived()));
|
||||
}
|
||||
|
||||
|
||||
void AbstractExtItem::readConfiguration()
|
||||
{
|
||||
QSettings settings(m_fileName, QSettings::IniFormat);
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
setName(settings.value(QString("Name"), name()).toString());
|
||||
setComment(settings.value(QString("Comment"), comment()).toString());
|
||||
setApiVersion(
|
||||
settings.value(QString("X-AW-ApiVersion"), apiVersion()).toInt());
|
||||
setActive(
|
||||
settings.value(QString("X-AW-Active"), QVariant(isActive())).toString()
|
||||
== QString("true"));
|
||||
setInterval(settings.value(QString("X-AW-Interval"), interval()).toInt());
|
||||
setNumber(settings.value(QString("X-AW-Number"), number()).toInt());
|
||||
settings.beginGroup("Desktop Entry");
|
||||
setName(settings.value("Name", name()).toString());
|
||||
setComment(settings.value("Comment", comment()).toString());
|
||||
setApiVersion(settings.value("X-AW-ApiVersion", apiVersion()).toInt());
|
||||
setActive(settings.value("X-AW-Active", isActive()).toBool());
|
||||
setInterval(settings.value("X-AW-Interval", interval()).toInt());
|
||||
setNumber(settings.value("X-AW-Number", number()).toInt());
|
||||
setCron(settings.value("X-AW-Schedule", cron()).toString());
|
||||
setSocket(settings.value("X-AW-Socket", socket()).toString());
|
||||
settings.endGroup();
|
||||
}
|
||||
|
||||
@ -228,15 +326,23 @@ void AbstractExtItem::writeConfiguration() const
|
||||
QSettings settings(writtableConfig(), QSettings::IniFormat);
|
||||
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
settings.setValue(QString("Encoding"), QString("UTF-8"));
|
||||
settings.setValue(QString("Name"), name());
|
||||
settings.setValue(QString("Comment"), comment());
|
||||
settings.setValue(QString("X-AW-ApiVersion"), apiVersion());
|
||||
settings.setValue(QString("X-AW-Active"), QVariant(isActive()).toString());
|
||||
settings.setValue(QString("X-AW-Interval"), interval());
|
||||
settings.setValue(QString("X-AW-Number"), number());
|
||||
settings.beginGroup("Desktop Entry");
|
||||
settings.setValue("Encoding", "UTF-8");
|
||||
settings.setValue("Name", name());
|
||||
settings.setValue("Comment", comment());
|
||||
settings.setValue("X-AW-ApiVersion", apiVersion());
|
||||
settings.setValue("X-AW-Active", isActive());
|
||||
settings.setValue("X-AW-Interval", interval());
|
||||
settings.setValue("X-AW-Number", number());
|
||||
settings.setValue("X-AW-Schedule", cron());
|
||||
settings.setValue("X-AW-Socket", socket());
|
||||
settings.endGroup();
|
||||
|
||||
settings.sync();
|
||||
}
|
||||
|
||||
|
||||
void AbstractExtItem::newConnectionReceived()
|
||||
{
|
||||
emit(requestDataUpdate());
|
||||
}
|
||||
|
@ -22,65 +22,86 @@
|
||||
#include <QVariant>
|
||||
|
||||
|
||||
class QCronScheduler;
|
||||
class QLocalServer;
|
||||
|
||||
class AbstractExtItem : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool active READ isActive WRITE setActive)
|
||||
Q_PROPERTY(int apiVersion READ apiVersion WRITE setApiVersion)
|
||||
Q_PROPERTY(QString comment READ comment WRITE setComment)
|
||||
Q_PROPERTY(QString cron READ cron WRITE setCron)
|
||||
Q_PROPERTY(QString fileName READ fileName)
|
||||
Q_PROPERTY(int interval READ interval WRITE setInterval)
|
||||
Q_PROPERTY(QString name READ name WRITE setName)
|
||||
Q_PROPERTY(int number READ number WRITE setNumber)
|
||||
Q_PROPERTY(QString socket READ socket WRITE setSocket)
|
||||
Q_PROPERTY(QString uniq READ uniq)
|
||||
|
||||
public:
|
||||
explicit AbstractExtItem(QWidget *parent,
|
||||
const QString filePath = QString());
|
||||
explicit AbstractExtItem(QWidget *_parent = nullptr,
|
||||
const QString &_filePath = "");
|
||||
virtual ~AbstractExtItem();
|
||||
virtual void bumpApi(const int _newVer);
|
||||
virtual AbstractExtItem *copy(const QString _fileName, const int _number)
|
||||
virtual AbstractExtItem *copy(const QString &_fileName, const int _number)
|
||||
= 0;
|
||||
virtual void copyDefaults(AbstractExtItem *_other) const;
|
||||
virtual void startTimer();
|
||||
QString writtableConfig() const;
|
||||
// get methods
|
||||
int apiVersion() const;
|
||||
QString comment() const;
|
||||
QString cron() const;
|
||||
QString fileName() const;
|
||||
int interval() const;
|
||||
bool isActive() const;
|
||||
QString name() const;
|
||||
int number() const;
|
||||
QString tag(const QString _type) const;
|
||||
QString socket() const;
|
||||
QString tag(const QString &_type) const;
|
||||
virtual QString uniq() const = 0;
|
||||
// set methods
|
||||
void setApiVersion(const int _apiVersion = 0);
|
||||
void setActive(const bool _state = true);
|
||||
void setComment(const QString _comment = QString("empty"));
|
||||
void setInterval(const int _interval = 1);
|
||||
void setName(const QString _name = QString("none"));
|
||||
void setNumber(int _number = -1);
|
||||
void setApiVersion(const int _apiVersion);
|
||||
void setActive(const bool _state);
|
||||
void setComment(const QString &_comment);
|
||||
void setCron(const QString &_cron);
|
||||
void setInterval(const int _interval);
|
||||
void setName(const QString &_name);
|
||||
void setNumber(int _number);
|
||||
void setSocket(const QString &_socket);
|
||||
|
||||
signals:
|
||||
void dataReceived(const QVariantHash &data);
|
||||
void dataReceived(const QVariantHash &_data);
|
||||
void requestDataUpdate();
|
||||
|
||||
public slots:
|
||||
virtual void deinitSocket();
|
||||
virtual void initSocket();
|
||||
virtual void readConfiguration();
|
||||
virtual QVariantHash run() = 0;
|
||||
virtual int showConfiguration(const QVariant args = QVariant()) = 0;
|
||||
bool tryDelete() const;
|
||||
virtual int showConfiguration(const QVariant &_args) = 0;
|
||||
virtual bool tryDelete() const;
|
||||
virtual void writeConfiguration() const;
|
||||
|
||||
private slots:
|
||||
void newConnectionReceived();
|
||||
|
||||
private:
|
||||
QString m_fileName = QString("/dev/null");
|
||||
QCronScheduler *m_scheduler = nullptr;
|
||||
QString m_fileName = "/dev/null";
|
||||
int m_times = 0;
|
||||
virtual void translate() = 0;
|
||||
// properties
|
||||
int m_apiVersion = 0;
|
||||
bool m_active = true;
|
||||
QString m_comment = QString("empty");
|
||||
QString m_comment = "empty";
|
||||
QString m_cron = "";
|
||||
int m_interval = 1;
|
||||
QString m_name = QString("none");
|
||||
QString m_name = "none";
|
||||
int m_number = -1;
|
||||
QLocalServer *m_socket = nullptr;
|
||||
QString m_socketFile = "";
|
||||
};
|
||||
|
||||
|
||||
|
@ -25,11 +25,11 @@
|
||||
#include <QPushButton>
|
||||
|
||||
|
||||
AbstractExtItemAggregator::AbstractExtItemAggregator(QWidget *parent,
|
||||
const QString type)
|
||||
: QDialog(parent)
|
||||
AbstractExtItemAggregator::AbstractExtItemAggregator(QWidget *_parent,
|
||||
const QString &_type)
|
||||
: QDialog(_parent)
|
||||
, ui(new Ui::AbstractExtItemAggregator)
|
||||
, m_type(type)
|
||||
, m_type(_type)
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
@ -113,13 +113,13 @@ void AbstractExtItemAggregator::editItem()
|
||||
QString AbstractExtItemAggregator::getName()
|
||||
{
|
||||
bool ok;
|
||||
QString name = QInputDialog::getText(this, i18n("Enter file name"),
|
||||
i18n("File name"), QLineEdit::Normal,
|
||||
QString(""), &ok);
|
||||
QString name
|
||||
= QInputDialog::getText(this, i18n("Enter file name"),
|
||||
i18n("File name"), QLineEdit::Normal, "", &ok);
|
||||
if ((!ok) || (name.isEmpty()))
|
||||
return QString("");
|
||||
if (!name.endsWith(QString(".desktop")))
|
||||
name += QString(".desktop");
|
||||
return "";
|
||||
if (!name.endsWith(".desktop"))
|
||||
name += ".desktop";
|
||||
|
||||
return name;
|
||||
}
|
||||
@ -132,7 +132,7 @@ AbstractExtItem *AbstractExtItemAggregator::itemFromWidget()
|
||||
return nullptr;
|
||||
|
||||
AbstractExtItem *found = nullptr;
|
||||
for (auto item : items()) {
|
||||
for (auto &item : items()) {
|
||||
QString fileName = QFileInfo(item->fileName()).fileName();
|
||||
if (fileName != widgetItem->text())
|
||||
continue;
|
||||
@ -150,14 +150,14 @@ AbstractExtItem *AbstractExtItemAggregator::itemFromWidget()
|
||||
void AbstractExtItemAggregator::repaintList()
|
||||
{
|
||||
ui->listWidget->clear();
|
||||
for (auto _item : items()) {
|
||||
for (auto &_item : items()) {
|
||||
QString fileName = QFileInfo(_item->fileName()).fileName();
|
||||
QListWidgetItem *item = new QListWidgetItem(fileName, ui->listWidget);
|
||||
QStringList tooltip;
|
||||
tooltip.append(i18n("Name: %1", _item->name()));
|
||||
tooltip.append(i18n("Comment: %1", _item->comment()));
|
||||
tooltip.append(i18n("Identity: %1", _item->uniq()));
|
||||
item->setToolTip(tooltip.join(QChar('\n')));
|
||||
item->setToolTip(tooltip.join('\n'));
|
||||
ui->listWidget->addItem(item);
|
||||
}
|
||||
}
|
||||
@ -166,7 +166,7 @@ void AbstractExtItemAggregator::repaintList()
|
||||
int AbstractExtItemAggregator::uniqNumber() const
|
||||
{
|
||||
QList<int> tagList;
|
||||
for (auto item : items())
|
||||
for (auto &item : items())
|
||||
tagList.append(item->number());
|
||||
int number = 0;
|
||||
while (tagList.contains(number))
|
||||
@ -188,7 +188,7 @@ QString AbstractExtItemAggregator::type() const
|
||||
}
|
||||
|
||||
|
||||
void AbstractExtItemAggregator::setConfigArgs(const QVariant _configArgs)
|
||||
void AbstractExtItemAggregator::setConfigArgs(const QVariant &_configArgs)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Configuration arguments" << _configArgs;
|
||||
|
||||
@ -202,14 +202,14 @@ void AbstractExtItemAggregator::editItemActivated(QListWidgetItem *)
|
||||
}
|
||||
|
||||
|
||||
void AbstractExtItemAggregator::editItemButtonPressed(QAbstractButton *button)
|
||||
void AbstractExtItemAggregator::editItemButtonPressed(QAbstractButton *_button)
|
||||
{
|
||||
if (static_cast<QPushButton *>(button) == copyButton)
|
||||
if (static_cast<QPushButton *>(_button) == copyButton)
|
||||
return copyItem();
|
||||
else if (static_cast<QPushButton *>(button) == createButton)
|
||||
else if (static_cast<QPushButton *>(_button) == createButton)
|
||||
return doCreateItem();
|
||||
else if (static_cast<QPushButton *>(button) == deleteButton)
|
||||
else if (static_cast<QPushButton *>(_button) == deleteButton)
|
||||
return deleteItem();
|
||||
else if (ui->buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole)
|
||||
else if (ui->buttonBox->buttonRole(_button) == QDialogButtonBox::AcceptRole)
|
||||
return editItem();
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ class AbstractExtItemAggregator : public QDialog
|
||||
Q_PROPERTY(QVariant type READ type)
|
||||
|
||||
public:
|
||||
explicit AbstractExtItemAggregator(QWidget *parent, const QString type);
|
||||
explicit AbstractExtItemAggregator(QWidget *_parent, const QString &_type);
|
||||
virtual ~AbstractExtItemAggregator();
|
||||
// methods
|
||||
void copyItem();
|
||||
@ -75,11 +75,11 @@ public:
|
||||
virtual QList<AbstractExtItem *> items() const = 0;
|
||||
QString type() const;
|
||||
// set methods
|
||||
void setConfigArgs(const QVariant _configArgs);
|
||||
void setConfigArgs(const QVariant &_configArgs);
|
||||
|
||||
private slots:
|
||||
void editItemActivated(QListWidgetItem *);
|
||||
void editItemButtonPressed(QAbstractButton *button);
|
||||
void editItemButtonPressed(QAbstractButton *_button);
|
||||
|
||||
private:
|
||||
// ui
|
||||
|
@ -28,14 +28,14 @@ class AbstractWeatherProvider : public QObject
|
||||
Q_PROPERTY(int number READ number)
|
||||
|
||||
public:
|
||||
explicit AbstractWeatherProvider(QObject *parent, const int number)
|
||||
: QObject(parent)
|
||||
, m_number(number){};
|
||||
explicit AbstractWeatherProvider(QObject *_parent, const int _number)
|
||||
: QObject(_parent)
|
||||
, m_number(_number){};
|
||||
virtual ~AbstractWeatherProvider(){};
|
||||
virtual void initUrl(const QString city, const QString country,
|
||||
const int ts)
|
||||
virtual void initUrl(const QString &_city, const QString &_country,
|
||||
const int _ts)
|
||||
= 0;
|
||||
virtual QVariantHash parse(const QVariantMap &json) const = 0;
|
||||
virtual QVariantHash parse(const QVariantMap &_json) const = 0;
|
||||
virtual QUrl url() const = 0;
|
||||
int number() const { return m_number; };
|
||||
|
||||
|
@ -22,9 +22,9 @@
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
AWAbstractFormatter::AWAbstractFormatter(QWidget *parent,
|
||||
const QString filePath)
|
||||
: AbstractExtItem(parent, filePath)
|
||||
AWAbstractFormatter::AWAbstractFormatter(QWidget *_parent,
|
||||
const QString &_filePath)
|
||||
: AbstractExtItem(_parent, _filePath)
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
}
|
||||
@ -55,22 +55,25 @@ QString AWAbstractFormatter::strType() const
|
||||
QString value;
|
||||
switch (m_type) {
|
||||
case FormatterClass::DateTime:
|
||||
value = QString("DateTime");
|
||||
value = "DateTime";
|
||||
break;
|
||||
case FormatterClass::Float:
|
||||
value = QString("Float");
|
||||
value = "Float";
|
||||
break;
|
||||
case FormatterClass::List:
|
||||
value = QString("List");
|
||||
value = "List";
|
||||
break;
|
||||
case FormatterClass::Script:
|
||||
value = QString("Script");
|
||||
value = "Script";
|
||||
break;
|
||||
case FormatterClass::String:
|
||||
value = QString("String");
|
||||
value = "String";
|
||||
break;
|
||||
case FormatterClass::Json:
|
||||
value = "Json";
|
||||
break;
|
||||
case FormatterClass::NoFormat:
|
||||
value = QString("NoFormat");
|
||||
value = "NoFormat";
|
||||
break;
|
||||
}
|
||||
|
||||
@ -84,20 +87,22 @@ AWAbstractFormatter::FormatterClass AWAbstractFormatter::type() const
|
||||
}
|
||||
|
||||
|
||||
void AWAbstractFormatter::setStrType(const QString _type)
|
||||
void AWAbstractFormatter::setStrType(const QString &_type)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Type" << _type;
|
||||
|
||||
if (_type == QString("DateTime"))
|
||||
if (_type == "DateTime")
|
||||
m_type = FormatterClass::DateTime;
|
||||
else if (_type == QString("Float"))
|
||||
else if (_type == "Float")
|
||||
m_type = FormatterClass::Float;
|
||||
else if (_type == QString("List"))
|
||||
else if (_type == "List")
|
||||
m_type = FormatterClass::List;
|
||||
else if (_type == QString("Script"))
|
||||
else if (_type == "Script")
|
||||
m_type = FormatterClass::Script;
|
||||
else if (_type == QString("String"))
|
||||
else if (_type == "String")
|
||||
m_type = FormatterClass::String;
|
||||
else if (_type == "Json")
|
||||
m_type = FormatterClass::Json;
|
||||
else
|
||||
m_type = FormatterClass::NoFormat;
|
||||
}
|
||||
@ -118,8 +123,8 @@ void AWAbstractFormatter::readConfiguration()
|
||||
|
||||
QSettings settings(fileName(), QSettings::IniFormat);
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
setStrType(settings.value(QString("X-AW-Type"), strType()).toString());
|
||||
settings.beginGroup("Desktop Entry");
|
||||
setStrType(settings.value("X-AW-Type", strType()).toString());
|
||||
settings.endGroup();
|
||||
}
|
||||
|
||||
@ -131,8 +136,8 @@ void AWAbstractFormatter::writeConfiguration() const
|
||||
QSettings settings(writtableConfig(), QSettings::IniFormat);
|
||||
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
settings.setValue(QString("X-AW-Type"), strType());
|
||||
settings.beginGroup("Desktop Entry");
|
||||
settings.setValue("X-AW-Type", strType());
|
||||
settings.endGroup();
|
||||
|
||||
settings.sync();
|
||||
|
@ -34,11 +34,12 @@ public:
|
||||
List,
|
||||
Script,
|
||||
String,
|
||||
NoFormat
|
||||
NoFormat,
|
||||
Json
|
||||
};
|
||||
|
||||
explicit AWAbstractFormatter(QWidget *parent,
|
||||
const QString filePath = QString());
|
||||
explicit AWAbstractFormatter(QWidget *_parent = nullptr,
|
||||
const QString &_filePath = "");
|
||||
virtual ~AWAbstractFormatter();
|
||||
virtual QString convert(const QVariant &_value) const = 0;
|
||||
void copyDefaults(AbstractExtItem *_other) const;
|
||||
@ -46,8 +47,8 @@ public:
|
||||
// properties
|
||||
QString strType() const;
|
||||
FormatterClass type() const;
|
||||
void setStrType(const QString type);
|
||||
void setType(const FormatterClass _type = FormatterClass::NoFormat);
|
||||
void setStrType(const QString &_type);
|
||||
void setType(const FormatterClass _type);
|
||||
|
||||
public slots:
|
||||
virtual void readConfiguration();
|
||||
|
@ -28,14 +28,14 @@
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
AWDateTimeFormatter::AWDateTimeFormatter(QWidget *parent,
|
||||
const QString filePath)
|
||||
: AWAbstractFormatter(parent, filePath)
|
||||
AWDateTimeFormatter::AWDateTimeFormatter(QWidget *_parent,
|
||||
const QString &_filePath)
|
||||
: AWAbstractFormatter(_parent, _filePath)
|
||||
, ui(new Ui::AWDateTimeFormatter)
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
if (!filePath.isEmpty())
|
||||
if (!_filePath.isEmpty())
|
||||
readConfiguration();
|
||||
ui->setupUi(this);
|
||||
translate();
|
||||
@ -58,7 +58,7 @@ QString AWDateTimeFormatter::convert(const QVariant &_value) const
|
||||
}
|
||||
|
||||
|
||||
AWDateTimeFormatter *AWDateTimeFormatter::copy(const QString _fileName,
|
||||
AWDateTimeFormatter *AWDateTimeFormatter::copy(const QString &_fileName,
|
||||
const int _number)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
||||
@ -86,7 +86,7 @@ bool AWDateTimeFormatter::translateString() const
|
||||
}
|
||||
|
||||
|
||||
void AWDateTimeFormatter::setFormat(const QString _format)
|
||||
void AWDateTimeFormatter::setFormat(const QString &_format)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Set format" << _format;
|
||||
|
||||
@ -109,23 +109,23 @@ void AWDateTimeFormatter::readConfiguration()
|
||||
|
||||
QSettings settings(fileName(), QSettings::IniFormat);
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
setFormat(settings.value(QString("X-AW-Format"), format()).toString());
|
||||
settings.beginGroup("Desktop Entry");
|
||||
setFormat(settings.value("X-AW-Format", format()).toString());
|
||||
setTranslateString(
|
||||
settings.value(QString("X-AW-Translate"), translateString()).toBool());
|
||||
settings.value("X-AW-Translate", translateString()).toBool());
|
||||
settings.endGroup();
|
||||
|
||||
bumpApi(AWEFAPI);
|
||||
bumpApi(AW_FORMATTER_API);
|
||||
}
|
||||
|
||||
|
||||
int AWDateTimeFormatter::showConfiguration(const QVariant args)
|
||||
int AWDateTimeFormatter::showConfiguration(const QVariant &_args)
|
||||
{
|
||||
Q_UNUSED(args)
|
||||
Q_UNUSED(_args)
|
||||
|
||||
ui->lineEdit_name->setText(name());
|
||||
ui->lineEdit_comment->setText(comment());
|
||||
ui->label_typeValue->setText(QString("DateTime"));
|
||||
ui->label_typeValue->setText("DateTime");
|
||||
ui->lineEdit_format->setText(format());
|
||||
ui->checkBox_translate->setCheckState(translateString() ? Qt::Checked
|
||||
: Qt::Unchecked);
|
||||
@ -135,7 +135,7 @@ int AWDateTimeFormatter::showConfiguration(const QVariant args)
|
||||
return ret;
|
||||
setName(ui->lineEdit_name->text());
|
||||
setComment(ui->lineEdit_comment->text());
|
||||
setApiVersion(AWEFAPI);
|
||||
setApiVersion(AW_FORMATTER_API);
|
||||
setStrType(ui->label_typeValue->text());
|
||||
setFormat(ui->lineEdit_format->text());
|
||||
setTranslateString(ui->checkBox_translate->checkState() == Qt::Checked);
|
||||
@ -152,9 +152,9 @@ void AWDateTimeFormatter::writeConfiguration() const
|
||||
QSettings settings(writtableConfig(), QSettings::IniFormat);
|
||||
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
settings.setValue(QString("X-AW-Format"), format());
|
||||
settings.setValue(QString("X-AW-Translate"), translateString());
|
||||
settings.beginGroup("Desktop Entry");
|
||||
settings.setValue("X-AW-Format", format());
|
||||
settings.setValue("X-AW-Translate", translateString());
|
||||
settings.endGroup();
|
||||
|
||||
settings.sync();
|
||||
|
@ -35,20 +35,20 @@ class AWDateTimeFormatter : public AWAbstractFormatter
|
||||
bool translateString READ translateString WRITE setTranslateString)
|
||||
|
||||
public:
|
||||
explicit AWDateTimeFormatter(QWidget *parent,
|
||||
const QString filePath = QString());
|
||||
explicit AWDateTimeFormatter(QWidget *_parent = nullptr,
|
||||
const QString &_filePath = "");
|
||||
virtual ~AWDateTimeFormatter();
|
||||
QString convert(const QVariant &_value) const;
|
||||
AWDateTimeFormatter *copy(const QString _fileName, const int _number);
|
||||
AWDateTimeFormatter *copy(const QString &_fileName, const int _number);
|
||||
// properties
|
||||
QString format() const;
|
||||
bool translateString() const;
|
||||
void setFormat(const QString _format);
|
||||
void setFormat(const QString &_format);
|
||||
void setTranslateString(const bool _translate);
|
||||
|
||||
public slots:
|
||||
void readConfiguration();
|
||||
int showConfiguration(const QVariant args = QVariant());
|
||||
int showConfiguration(const QVariant &_args);
|
||||
void writeConfiguration() const;
|
||||
|
||||
private:
|
||||
@ -57,7 +57,7 @@ private:
|
||||
void translate();
|
||||
// properties
|
||||
QLocale m_locale;
|
||||
QString m_format = QString();
|
||||
QString m_format = "";
|
||||
bool m_translate = true;
|
||||
};
|
||||
|
||||
|
@ -27,13 +27,13 @@
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
AWFloatFormatter::AWFloatFormatter(QWidget *parent, const QString filePath)
|
||||
: AWAbstractFormatter(parent, filePath)
|
||||
AWFloatFormatter::AWFloatFormatter(QWidget *_parent, const QString &_filePath)
|
||||
: AWAbstractFormatter(_parent, _filePath)
|
||||
, ui(new Ui::AWFloatFormatter)
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
if (!filePath.isEmpty())
|
||||
if (!_filePath.isEmpty())
|
||||
readConfiguration();
|
||||
ui->setupUi(this);
|
||||
translate();
|
||||
@ -62,7 +62,7 @@ QString AWFloatFormatter::convert(const QVariant &_value) const
|
||||
}
|
||||
|
||||
|
||||
AWFloatFormatter *AWFloatFormatter::copy(const QString _fileName,
|
||||
AWFloatFormatter *AWFloatFormatter::copy(const QString &_fileName,
|
||||
const int _number)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
||||
@ -133,7 +133,7 @@ void AWFloatFormatter::setCount(const int _count)
|
||||
}
|
||||
|
||||
|
||||
void AWFloatFormatter::setFillChar(const QChar _fillChar)
|
||||
void AWFloatFormatter::setFillChar(const QChar &_fillChar)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Set char" << _fillChar;
|
||||
|
||||
@ -193,34 +193,30 @@ void AWFloatFormatter::readConfiguration()
|
||||
|
||||
QSettings settings(fileName(), QSettings::IniFormat);
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
setCount(settings.value(QString("X-AW-Width"), count()).toInt());
|
||||
setFillChar(
|
||||
settings.value(QString("X-AW-FillChar"), fillChar()).toString().at(0));
|
||||
setForceWidth(
|
||||
settings.value(QString("X-AW-ForceWidth"), forceWidth()).toBool());
|
||||
setFormat(settings.value(QString("X-AW-Format"), QString(format()))
|
||||
settings.beginGroup("Desktop Entry");
|
||||
setCount(settings.value("X-AW-Width", count()).toInt());
|
||||
setFillChar(settings.value("X-AW-FillChar", fillChar()).toString().at(0));
|
||||
setForceWidth(settings.value("X-AW-ForceWidth", forceWidth()).toBool());
|
||||
setFormat(settings.value("X-AW-Format", QString(format()))
|
||||
.toString()
|
||||
.at(0)
|
||||
.toLatin1());
|
||||
setMultiplier(
|
||||
settings.value(QString("X-AW-Multiplier"), multiplier()).toDouble());
|
||||
setPrecision(
|
||||
settings.value(QString("X-AW-Precision"), precision()).toInt());
|
||||
setSummand(settings.value(QString("X-AW-Summand"), summand()).toDouble());
|
||||
setMultiplier(settings.value("X-AW-Multiplier", multiplier()).toDouble());
|
||||
setPrecision(settings.value("X-AW-Precision", precision()).toInt());
|
||||
setSummand(settings.value("X-AW-Summand", summand()).toDouble());
|
||||
settings.endGroup();
|
||||
|
||||
bumpApi(AWEFAPI);
|
||||
bumpApi(AW_FORMATTER_API);
|
||||
}
|
||||
|
||||
|
||||
int AWFloatFormatter::showConfiguration(const QVariant args)
|
||||
int AWFloatFormatter::showConfiguration(const QVariant &_args)
|
||||
{
|
||||
Q_UNUSED(args)
|
||||
Q_UNUSED(_args)
|
||||
|
||||
ui->lineEdit_name->setText(name());
|
||||
ui->lineEdit_comment->setText(comment());
|
||||
ui->label_typeValue->setText(QString("Float"));
|
||||
ui->label_typeValue->setText("Float");
|
||||
ui->comboBox_format->setCurrentIndex(
|
||||
ui->comboBox_format->findText(QString(format())));
|
||||
ui->spinBox_precision->setValue(precision());
|
||||
@ -236,7 +232,7 @@ int AWFloatFormatter::showConfiguration(const QVariant args)
|
||||
return ret;
|
||||
setName(ui->lineEdit_name->text());
|
||||
setComment(ui->lineEdit_comment->text());
|
||||
setApiVersion(AWEFAPI);
|
||||
setApiVersion(AW_FORMATTER_API);
|
||||
setStrType(ui->label_typeValue->text());
|
||||
setFormat(ui->comboBox_format->currentText().at(0).toLatin1());
|
||||
setPrecision(ui->spinBox_precision->value());
|
||||
@ -258,14 +254,14 @@ void AWFloatFormatter::writeConfiguration() const
|
||||
QSettings settings(writtableConfig(), QSettings::IniFormat);
|
||||
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
settings.setValue(QString("X-AW-Width"), count());
|
||||
settings.setValue(QString("X-AW-FillChar"), fillChar());
|
||||
settings.setValue(QString("X-AW-Format"), QString(format()));
|
||||
settings.setValue(QString("X-AW-ForceWidth"), forceWidth());
|
||||
settings.setValue(QString("X-AW-Multiplier"), multiplier());
|
||||
settings.setValue(QString("X-AW-Precision"), precision());
|
||||
settings.setValue(QString("X-AW-Summand"), summand());
|
||||
settings.beginGroup("Desktop Entry");
|
||||
settings.setValue("X-AW-Width", count());
|
||||
settings.setValue("X-AW-FillChar", fillChar());
|
||||
settings.setValue("X-AW-Format", QString(format()));
|
||||
settings.setValue("X-AW-ForceWidth", forceWidth());
|
||||
settings.setValue("X-AW-Multiplier", multiplier());
|
||||
settings.setValue("X-AW-Precision", precision());
|
||||
settings.setValue("X-AW-Summand", summand());
|
||||
settings.endGroup();
|
||||
|
||||
settings.sync();
|
||||
|
@ -38,11 +38,11 @@ class AWFloatFormatter : public AWAbstractFormatter
|
||||
Q_PROPERTY(double summand READ summand WRITE setSummand)
|
||||
|
||||
public:
|
||||
explicit AWFloatFormatter(QWidget *parent,
|
||||
const QString filePath = QString());
|
||||
explicit AWFloatFormatter(QWidget *_parent = nullptr,
|
||||
const QString &_filePath = "");
|
||||
virtual ~AWFloatFormatter();
|
||||
QString convert(const QVariant &_value) const;
|
||||
AWFloatFormatter *copy(const QString _fileName, const int _number);
|
||||
AWFloatFormatter *copy(const QString &_fileName, const int _number);
|
||||
// properties
|
||||
int count() const;
|
||||
QChar fillChar() const;
|
||||
@ -52,7 +52,7 @@ public:
|
||||
int precision() const;
|
||||
double summand() const;
|
||||
void setCount(const int _count);
|
||||
void setFillChar(const QChar _fillChar);
|
||||
void setFillChar(const QChar &_fillChar);
|
||||
void setForceWidth(const bool _forceWidth);
|
||||
void setFormat(char _format);
|
||||
void setMultiplier(const double _multiplier);
|
||||
@ -61,7 +61,7 @@ public:
|
||||
|
||||
public slots:
|
||||
void readConfiguration();
|
||||
int showConfiguration(const QVariant args = QVariant());
|
||||
int showConfiguration(const QVariant &_args);
|
||||
void writeConfiguration() const;
|
||||
|
||||
private:
|
||||
|
203
sources/awesomewidgets/awjsonformatter.cpp
Normal file
203
sources/awesomewidgets/awjsonformatter.cpp
Normal file
@ -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 "awjsonformatter.h"
|
||||
#include "ui_awjsonformatter.h"
|
||||
|
||||
#include <KI18n/KLocalizedString>
|
||||
|
||||
#include <QJsonDocument>
|
||||
#include <QSettings>
|
||||
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
AWJsonFormatter::AWJsonFormatter(QWidget *_parent, const QString &_filePath)
|
||||
: AWAbstractFormatter(_parent, _filePath)
|
||||
, ui(new Ui::AWJsonFormatter)
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
if (!_filePath.isEmpty())
|
||||
readConfiguration();
|
||||
ui->setupUi(this);
|
||||
translate();
|
||||
}
|
||||
|
||||
|
||||
AWJsonFormatter::~AWJsonFormatter()
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
||||
QString AWJsonFormatter::convert(const QVariant &_value) const
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Convert value" << _value;
|
||||
|
||||
// check if _value is string and parse first if required
|
||||
QJsonDocument json
|
||||
= _value.type() == QVariant::String
|
||||
? QJsonDocument::fromJson(_value.toString().toUtf8())
|
||||
: QJsonDocument::fromVariant(_value);
|
||||
QVariant converted = json.toVariant();
|
||||
for (auto &element : m_splittedPath)
|
||||
converted = getFromJson(converted, element);
|
||||
|
||||
return converted.toString();
|
||||
}
|
||||
|
||||
|
||||
AWJsonFormatter *AWJsonFormatter::copy(const QString &_fileName,
|
||||
const int _number)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
||||
|
||||
AWJsonFormatter *item
|
||||
= new AWJsonFormatter(static_cast<QWidget *>(parent()), _fileName);
|
||||
AWAbstractFormatter::copyDefaults(item);
|
||||
item->setNumber(_number);
|
||||
item->setPath(path());
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
QString AWJsonFormatter::path() const
|
||||
{
|
||||
return m_path;
|
||||
}
|
||||
|
||||
|
||||
void AWJsonFormatter::setPath(const QString &_path)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Path" << _path;
|
||||
|
||||
m_path = _path;
|
||||
initPath();
|
||||
}
|
||||
|
||||
|
||||
void AWJsonFormatter::readConfiguration()
|
||||
{
|
||||
AWAbstractFormatter::readConfiguration();
|
||||
|
||||
QSettings settings(fileName(), QSettings::IniFormat);
|
||||
|
||||
settings.beginGroup("Desktop Entry");
|
||||
setPath(settings.value("X-AW-Path", path()).toString());
|
||||
settings.endGroup();
|
||||
|
||||
bumpApi(AW_FORMATTER_API);
|
||||
}
|
||||
|
||||
|
||||
int AWJsonFormatter::showConfiguration(const QVariant &args)
|
||||
{
|
||||
Q_UNUSED(args)
|
||||
|
||||
ui->lineEdit_name->setText(name());
|
||||
ui->lineEdit_comment->setText(comment());
|
||||
ui->label_typeValue->setText("Json");
|
||||
ui->lineEdit_path->setText(path());
|
||||
|
||||
int ret = exec();
|
||||
if (ret != 1)
|
||||
return ret;
|
||||
setName(ui->lineEdit_name->text());
|
||||
setComment(ui->lineEdit_comment->text());
|
||||
setApiVersion(AW_FORMATTER_API);
|
||||
setStrType(ui->label_typeValue->text());
|
||||
setPath(ui->lineEdit_path->text());
|
||||
|
||||
writeConfiguration();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void AWJsonFormatter::writeConfiguration() const
|
||||
{
|
||||
AWAbstractFormatter::writeConfiguration();
|
||||
|
||||
QSettings settings(writtableConfig(), QSettings::IniFormat);
|
||||
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
|
||||
|
||||
settings.beginGroup("Desktop Entry");
|
||||
settings.setValue("X-AW-Path", path());
|
||||
settings.endGroup();
|
||||
|
||||
settings.sync();
|
||||
}
|
||||
|
||||
|
||||
QVariant AWJsonFormatter::getFromJson(const QVariant &_value,
|
||||
const QVariant &_element) const
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Looking for element" << _element << "in" << _value;
|
||||
|
||||
if (_element.type() == QVariant::String) {
|
||||
return getFromMap(_value, _element.toString());
|
||||
} else if (_element.type() == QVariant::Int) {
|
||||
return getFromList(_value, _element.toInt());
|
||||
} else {
|
||||
qCWarning(LOG_LIB) << "Unknown type" << _element.typeName();
|
||||
return _value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QVariant AWJsonFormatter::getFromList(const QVariant &_value,
|
||||
const int _index) const
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Looking for index" << _index << "in" << _value;
|
||||
|
||||
return _value.toList()[_index];
|
||||
}
|
||||
|
||||
|
||||
QVariant AWJsonFormatter::getFromMap(const QVariant &_value,
|
||||
const QString &_key) const
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Looking for key" << _key << "in" << _value;
|
||||
|
||||
return _value.toMap()[_key];
|
||||
}
|
||||
|
||||
|
||||
void AWJsonFormatter::initPath()
|
||||
{
|
||||
m_splittedPath.clear();
|
||||
QStringList splittedByDot = m_path.split('.', QString::SkipEmptyParts);
|
||||
|
||||
for (auto &element : splittedByDot) {
|
||||
bool ok;
|
||||
int number = element.toInt(&ok);
|
||||
m_splittedPath.append(ok ? QVariant(number) : QVariant(element));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AWJsonFormatter::translate()
|
||||
{
|
||||
ui->label_name->setText(i18n("Name"));
|
||||
ui->label_comment->setText(i18n("Comment"));
|
||||
ui->label_type->setText(i18n("Type"));
|
||||
ui->label_path->setText(i18n("Path"));
|
||||
}
|
63
sources/awesomewidgets/awjsonformatter.h
Normal file
63
sources/awesomewidgets/awjsonformatter.h
Normal file
@ -0,0 +1,63 @@
|
||||
/***************************************************************************
|
||||
* 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 AWJSONFORMATTER_H
|
||||
#define AWJSONFORMATTER_H
|
||||
|
||||
#include "awabstractformatter.h"
|
||||
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class AWJsonFormatter;
|
||||
}
|
||||
|
||||
class AWJsonFormatter : public AWAbstractFormatter
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString path READ path WRITE setPath)
|
||||
|
||||
public:
|
||||
explicit AWJsonFormatter(QWidget *_parent = nullptr,
|
||||
const QString &_filePath = "");
|
||||
virtual ~AWJsonFormatter();
|
||||
QString convert(const QVariant &_value) const;
|
||||
AWJsonFormatter *copy(const QString &_fileName, const int _number);
|
||||
// properties
|
||||
QString path() const;
|
||||
void setPath(const QString &_path);
|
||||
|
||||
public slots:
|
||||
void readConfiguration();
|
||||
int showConfiguration(const QVariant &_args);
|
||||
void writeConfiguration() const;
|
||||
|
||||
private:
|
||||
Ui::AWJsonFormatter *ui = nullptr;
|
||||
QVariant getFromJson(const QVariant &_value,
|
||||
const QVariant &_element) const;
|
||||
QVariant getFromList(const QVariant &_value, const int _index) const;
|
||||
QVariant getFromMap(const QVariant &_value, const QString &_key) const;
|
||||
void initPath();
|
||||
void translate();
|
||||
// properties
|
||||
QString m_path;
|
||||
QVariantList m_splittedPath;
|
||||
};
|
||||
|
||||
|
||||
#endif /* AWJSONFORMATTER_H */
|
167
sources/awesomewidgets/awjsonformatter.ui
Normal file
167
sources/awesomewidgets/awjsonformatter.ui
Normal file
@ -0,0 +1,167 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>AWJsonFormatter</class>
|
||||
<widget class="QDialog" name="AWJsonFormatter">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>420</width>
|
||||
<height>128</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Configuration</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_name">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_name">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_name"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_comment">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_comment">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Comment</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_comment"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_type">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_type">
|
||||
<property name="text">
|
||||
<string>Type</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_typeValue">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_path">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_path">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Path</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_path"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>AWJsonFormatter</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>AWJsonFormatter</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
@ -26,13 +26,13 @@
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
AWListFormatter::AWListFormatter(QWidget *parent, const QString filePath)
|
||||
: AWAbstractFormatter(parent, filePath)
|
||||
AWListFormatter::AWListFormatter(QWidget *_parent, const QString &_filePath)
|
||||
: AWAbstractFormatter(_parent, _filePath)
|
||||
, ui(new Ui::AWListFormatter)
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
if (!filePath.isEmpty())
|
||||
if (!_filePath.isEmpty())
|
||||
readConfiguration();
|
||||
ui->setupUi(this);
|
||||
translate();
|
||||
@ -59,7 +59,7 @@ QString AWListFormatter::convert(const QVariant &_value) const
|
||||
}
|
||||
|
||||
|
||||
AWListFormatter *AWListFormatter::copy(const QString _fileName,
|
||||
AWListFormatter *AWListFormatter::copy(const QString &_fileName,
|
||||
const int _number)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
||||
@ -94,7 +94,7 @@ QString AWListFormatter::separator() const
|
||||
}
|
||||
|
||||
|
||||
void AWListFormatter::setFilter(const QString _filter)
|
||||
void AWListFormatter::setFilter(const QString &_filter)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Filter" << _filter;
|
||||
|
||||
@ -103,7 +103,7 @@ void AWListFormatter::setFilter(const QString _filter)
|
||||
}
|
||||
|
||||
|
||||
void AWListFormatter::setSeparator(const QString _separator)
|
||||
void AWListFormatter::setSeparator(const QString &_separator)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Separtor" << _separator;
|
||||
|
||||
@ -125,24 +125,23 @@ void AWListFormatter::readConfiguration()
|
||||
|
||||
QSettings settings(fileName(), QSettings::IniFormat);
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
setFilter(settings.value(QString("X-AW-Filter"), filter()).toString());
|
||||
setSeparator(
|
||||
settings.value(QString("X-AW-Separator"), separator()).toString());
|
||||
setSorted(settings.value(QString("X-AW-Sort"), isSorted()).toBool());
|
||||
settings.beginGroup("Desktop Entry");
|
||||
setFilter(settings.value("X-AW-Filter", filter()).toString());
|
||||
setSeparator(settings.value("X-AW-Separator", separator()).toString());
|
||||
setSorted(settings.value("X-AW-Sort", isSorted()).toBool());
|
||||
settings.endGroup();
|
||||
|
||||
bumpApi(AWEFAPI);
|
||||
bumpApi(AW_FORMATTER_API);
|
||||
}
|
||||
|
||||
|
||||
int AWListFormatter::showConfiguration(const QVariant args)
|
||||
int AWListFormatter::showConfiguration(const QVariant &_args)
|
||||
{
|
||||
Q_UNUSED(args)
|
||||
Q_UNUSED(_args)
|
||||
|
||||
ui->lineEdit_name->setText(name());
|
||||
ui->lineEdit_comment->setText(comment());
|
||||
ui->label_typeValue->setText(QString("NoFormat"));
|
||||
ui->label_typeValue->setText("List");
|
||||
ui->lineEdit_filter->setText(filter());
|
||||
ui->lineEdit_separator->setText(separator());
|
||||
ui->checkBox_sorted->setCheckState(isSorted() ? Qt::Checked
|
||||
@ -153,7 +152,7 @@ int AWListFormatter::showConfiguration(const QVariant args)
|
||||
return ret;
|
||||
setName(ui->lineEdit_name->text());
|
||||
setComment(ui->lineEdit_comment->text());
|
||||
setApiVersion(AWEFAPI);
|
||||
setApiVersion(AW_FORMATTER_API);
|
||||
setStrType(ui->label_typeValue->text());
|
||||
setFilter(ui->lineEdit_filter->text());
|
||||
setSeparator(ui->lineEdit_separator->text());
|
||||
@ -171,10 +170,10 @@ void AWListFormatter::writeConfiguration() const
|
||||
QSettings settings(writtableConfig(), QSettings::IniFormat);
|
||||
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
settings.setValue(QString("X-AW-Filter"), filter());
|
||||
settings.setValue(QString("X-AW-Separator"), separator());
|
||||
settings.setValue(QString("X-AW-Sort"), isSorted());
|
||||
settings.beginGroup("Desktop Entry");
|
||||
settings.setValue("X-AW-Filter", filter());
|
||||
settings.setValue("X-AW-Separator", separator());
|
||||
settings.setValue("X-AW-Sort", isSorted());
|
||||
settings.endGroup();
|
||||
|
||||
settings.sync();
|
||||
|
@ -34,30 +34,30 @@ class AWListFormatter : public AWAbstractFormatter
|
||||
Q_PROPERTY(bool sorted READ isSorted WRITE setSorted)
|
||||
|
||||
public:
|
||||
explicit AWListFormatter(QWidget *parent,
|
||||
const QString filePath = QString());
|
||||
explicit AWListFormatter(QWidget *_parent = nullptr,
|
||||
const QString &_filePath = "");
|
||||
virtual ~AWListFormatter();
|
||||
QString convert(const QVariant &_value) const;
|
||||
AWListFormatter *copy(const QString _fileName, const int _number);
|
||||
AWListFormatter *copy(const QString &_fileName, const int _number);
|
||||
// properties
|
||||
QString filter() const;
|
||||
bool isSorted() const;
|
||||
QString separator() const;
|
||||
void setFilter(const QString _filter);
|
||||
void setSeparator(const QString _separator);
|
||||
void setFilter(const QString &_filter);
|
||||
void setSeparator(const QString &_separator);
|
||||
void setSorted(const bool _sorted);
|
||||
|
||||
public slots:
|
||||
void readConfiguration();
|
||||
int showConfiguration(const QVariant args = QVariant());
|
||||
int showConfiguration(const QVariant &_args);
|
||||
void writeConfiguration() const;
|
||||
|
||||
private:
|
||||
Ui::AWListFormatter *ui = nullptr;
|
||||
void translate();
|
||||
// properties
|
||||
QString m_filter = QString();
|
||||
QString m_separator = QString();
|
||||
QString m_filter = "";
|
||||
QString m_separator = "";
|
||||
bool m_sorted = false;
|
||||
QRegExp m_regex;
|
||||
};
|
||||
|
@ -24,13 +24,13 @@
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
AWNoFormatter::AWNoFormatter(QWidget *parent, const QString filePath)
|
||||
: AWAbstractFormatter(parent, filePath)
|
||||
AWNoFormatter::AWNoFormatter(QWidget *_parent, const QString &_filePath)
|
||||
: AWAbstractFormatter(_parent, _filePath)
|
||||
, ui(new Ui::AWNoFormatter)
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
if (!filePath.isEmpty())
|
||||
if (!_filePath.isEmpty())
|
||||
readConfiguration();
|
||||
ui->setupUi(this);
|
||||
translate();
|
||||
@ -53,7 +53,7 @@ QString AWNoFormatter::convert(const QVariant &_value) const
|
||||
}
|
||||
|
||||
|
||||
AWNoFormatter *AWNoFormatter::copy(const QString _fileName, const int _number)
|
||||
AWNoFormatter *AWNoFormatter::copy(const QString &_fileName, const int _number)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
||||
|
||||
@ -66,20 +66,20 @@ AWNoFormatter *AWNoFormatter::copy(const QString _fileName, const int _number)
|
||||
}
|
||||
|
||||
|
||||
int AWNoFormatter::showConfiguration(const QVariant args)
|
||||
int AWNoFormatter::showConfiguration(const QVariant &_args)
|
||||
{
|
||||
Q_UNUSED(args)
|
||||
Q_UNUSED(_args)
|
||||
|
||||
ui->lineEdit_name->setText(name());
|
||||
ui->lineEdit_comment->setText(comment());
|
||||
ui->label_typeValue->setText(QString("NoFormat"));
|
||||
ui->label_typeValue->setText("NoFormat");
|
||||
|
||||
int ret = exec();
|
||||
if (ret != 1)
|
||||
return ret;
|
||||
setName(ui->lineEdit_name->text());
|
||||
setComment(ui->lineEdit_comment->text());
|
||||
setApiVersion(AWEFAPI);
|
||||
setApiVersion(AW_FORMATTER_API);
|
||||
setStrType(ui->label_typeValue->text());
|
||||
|
||||
writeConfiguration();
|
||||
|
@ -31,13 +31,14 @@ class AWNoFormatter : public AWAbstractFormatter
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AWNoFormatter(QWidget *parent, const QString filePath = QString());
|
||||
explicit AWNoFormatter(QWidget *_parent = nullptr,
|
||||
const QString &_filePath = "");
|
||||
virtual ~AWNoFormatter();
|
||||
QString convert(const QVariant &_value) const;
|
||||
AWNoFormatter *copy(const QString _fileName, const int _number);
|
||||
AWNoFormatter *copy(const QString &_fileName, const int _number);
|
||||
|
||||
public slots:
|
||||
int showConfiguration(const QVariant args = QVariant());
|
||||
int showConfiguration(const QVariant &_args);
|
||||
|
||||
private:
|
||||
Ui::AWNoFormatter *ui = nullptr;
|
||||
|
@ -28,13 +28,13 @@
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
AWScriptFormatter::AWScriptFormatter(QWidget *parent, const QString filePath)
|
||||
: AWAbstractFormatter(parent, filePath)
|
||||
AWScriptFormatter::AWScriptFormatter(QWidget *_parent, const QString &_filePath)
|
||||
: AWAbstractFormatter(_parent, _filePath)
|
||||
, ui(new Ui::AWScriptFormatter)
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
if (!filePath.isEmpty())
|
||||
if (!_filePath.isEmpty())
|
||||
readConfiguration();
|
||||
ui->setupUi(this);
|
||||
translate();
|
||||
@ -63,14 +63,14 @@ QString AWScriptFormatter::convert(const QVariant &_value) const
|
||||
qCWarning(LOG_LIB) << "Uncaught exception at line"
|
||||
<< result.property("lineNumber").toInt() << ":"
|
||||
<< result.toString();
|
||||
return QString();
|
||||
return "";
|
||||
} else {
|
||||
return result.toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
AWScriptFormatter *AWScriptFormatter::copy(const QString _fileName,
|
||||
AWScriptFormatter *AWScriptFormatter::copy(const QString &_fileName,
|
||||
const int _number)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
||||
@ -120,7 +120,7 @@ void AWScriptFormatter::setAppendCode(const bool _appendCode)
|
||||
}
|
||||
|
||||
|
||||
void AWScriptFormatter::setCode(const QString _code)
|
||||
void AWScriptFormatter::setCode(const QString &_code)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Set code" << _code;
|
||||
|
||||
@ -144,25 +144,23 @@ void AWScriptFormatter::readConfiguration()
|
||||
|
||||
QSettings settings(fileName(), QSettings::IniFormat);
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
setAppendCode(
|
||||
settings.value(QString("X-AW-AppendCode"), appendCode()).toBool());
|
||||
setCode(settings.value(QString("X-AW-Code"), code()).toString());
|
||||
setHasReturn(
|
||||
settings.value(QString("X-AW-HasReturn"), hasReturn()).toBool());
|
||||
settings.beginGroup("Desktop Entry");
|
||||
setAppendCode(settings.value("X-AW-AppendCode", appendCode()).toBool());
|
||||
setCode(settings.value("X-AW-Code", code()).toString());
|
||||
setHasReturn(settings.value("X-AW-HasReturn", hasReturn()).toBool());
|
||||
settings.endGroup();
|
||||
|
||||
bumpApi(AWEFAPI);
|
||||
bumpApi(AW_FORMATTER_API);
|
||||
}
|
||||
|
||||
|
||||
int AWScriptFormatter::showConfiguration(const QVariant args)
|
||||
int AWScriptFormatter::showConfiguration(const QVariant &_args)
|
||||
{
|
||||
Q_UNUSED(args)
|
||||
Q_UNUSED(_args)
|
||||
|
||||
ui->lineEdit_name->setText(name());
|
||||
ui->lineEdit_comment->setText(comment());
|
||||
ui->label_typeValue->setText(QString("Script"));
|
||||
ui->label_typeValue->setText("Script");
|
||||
ui->checkBox_appendCode->setCheckState(appendCode() ? Qt::Checked
|
||||
: Qt::Unchecked);
|
||||
ui->checkBox_hasReturn->setCheckState(hasReturn() ? Qt::Checked
|
||||
@ -174,7 +172,7 @@ int AWScriptFormatter::showConfiguration(const QVariant args)
|
||||
return ret;
|
||||
setName(ui->lineEdit_name->text());
|
||||
setComment(ui->lineEdit_comment->text());
|
||||
setApiVersion(AWEFAPI);
|
||||
setApiVersion(AW_FORMATTER_API);
|
||||
setStrType(ui->label_typeValue->text());
|
||||
setAppendCode(ui->checkBox_appendCode->checkState() == Qt::Checked);
|
||||
setHasReturn(ui->checkBox_hasReturn->checkState() == Qt::Checked);
|
||||
@ -193,10 +191,10 @@ void AWScriptFormatter::writeConfiguration() const
|
||||
QSettings settings(writtableConfig(), QSettings::IniFormat);
|
||||
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
settings.setValue(QString("X-AW-AppendCode"), appendCode());
|
||||
settings.setValue(QString("X-AW-Code"), code());
|
||||
settings.setValue(QString("X-AW-HasReturn"), hasReturn());
|
||||
settings.beginGroup("Desktop Entry");
|
||||
settings.setValue("X-AW-AppendCode", appendCode());
|
||||
settings.setValue("X-AW-Code", code());
|
||||
settings.setValue("X-AW-HasReturn", hasReturn());
|
||||
settings.endGroup();
|
||||
|
||||
settings.sync();
|
||||
@ -207,10 +205,9 @@ void AWScriptFormatter::initProgram()
|
||||
{
|
||||
// init JS code
|
||||
if (appendCode())
|
||||
m_program
|
||||
= QString("(function(value) { %1%2 })")
|
||||
.arg(code())
|
||||
.arg(hasReturn() ? QString("") : QString("; return output;"));
|
||||
m_program = QString("(function(value) { %1%2 })")
|
||||
.arg(code())
|
||||
.arg(hasReturn() ? "" : "; return output;");
|
||||
else
|
||||
m_program = code();
|
||||
|
||||
|
@ -35,23 +35,23 @@ class AWScriptFormatter : public AWAbstractFormatter
|
||||
Q_PROPERTY(QString program READ program)
|
||||
|
||||
public:
|
||||
explicit AWScriptFormatter(QWidget *parent,
|
||||
const QString filePath = QString());
|
||||
explicit AWScriptFormatter(QWidget *_parent = nullptr,
|
||||
const QString &_filePath = "");
|
||||
virtual ~AWScriptFormatter();
|
||||
QString convert(const QVariant &_value) const;
|
||||
AWScriptFormatter *copy(const QString _fileName, const int _number);
|
||||
AWScriptFormatter *copy(const QString &_fileName, const int _number);
|
||||
// properties
|
||||
bool appendCode() const;
|
||||
QString code() const;
|
||||
bool hasReturn() const;
|
||||
QString program() const;
|
||||
void setAppendCode(const bool _appendCode);
|
||||
void setCode(const QString _code);
|
||||
void setCode(const QString &_code);
|
||||
void setHasReturn(const bool _hasReturn);
|
||||
|
||||
public slots:
|
||||
void readConfiguration();
|
||||
int showConfiguration(const QVariant args = QVariant());
|
||||
int showConfiguration(const QVariant &_args);
|
||||
void writeConfiguration() const;
|
||||
|
||||
private:
|
||||
@ -60,7 +60,7 @@ private:
|
||||
void translate();
|
||||
// properties
|
||||
bool m_appendCode = true;
|
||||
QString m_code = QString();
|
||||
QString m_code = "";
|
||||
bool m_hasReturn = false;
|
||||
QString m_program;
|
||||
};
|
||||
|
@ -27,13 +27,13 @@
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
AWStringFormatter::AWStringFormatter(QWidget *parent, const QString filePath)
|
||||
: AWAbstractFormatter(parent, filePath)
|
||||
AWStringFormatter::AWStringFormatter(QWidget *_parent, const QString &_filePath)
|
||||
: AWAbstractFormatter(_parent, _filePath)
|
||||
, ui(new Ui::AWStringFormatter)
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
if (!filePath.isEmpty())
|
||||
if (!_filePath.isEmpty())
|
||||
readConfiguration();
|
||||
ui->setupUi(this);
|
||||
translate();
|
||||
@ -60,7 +60,7 @@ QString AWStringFormatter::convert(const QVariant &_value) const
|
||||
}
|
||||
|
||||
|
||||
AWStringFormatter *AWStringFormatter::copy(const QString _fileName,
|
||||
AWStringFormatter *AWStringFormatter::copy(const QString &_fileName,
|
||||
const int _number)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
||||
@ -103,7 +103,7 @@ void AWStringFormatter::setCount(const int _count)
|
||||
}
|
||||
|
||||
|
||||
void AWStringFormatter::setFillChar(const QChar _fillChar)
|
||||
void AWStringFormatter::setFillChar(const QChar &_fillChar)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Set char" << _fillChar;
|
||||
|
||||
@ -125,25 +125,23 @@ void AWStringFormatter::readConfiguration()
|
||||
|
||||
QSettings settings(fileName(), QSettings::IniFormat);
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
setCount(settings.value(QString("X-AW-Width"), count()).toInt());
|
||||
setFillChar(
|
||||
settings.value(QString("X-AW-FillChar"), fillChar()).toString().at(0));
|
||||
setForceWidth(
|
||||
settings.value(QString("X-AW-ForceWidth"), forceWidth()).toBool());
|
||||
settings.beginGroup("Desktop Entry");
|
||||
setCount(settings.value("X-AW-Width", count()).toInt());
|
||||
setFillChar(settings.value("X-AW-FillChar", fillChar()).toString().at(0));
|
||||
setForceWidth(settings.value("X-AW-ForceWidth", forceWidth()).toBool());
|
||||
settings.endGroup();
|
||||
|
||||
bumpApi(AWEFAPI);
|
||||
bumpApi(AW_FORMATTER_API);
|
||||
}
|
||||
|
||||
|
||||
int AWStringFormatter::showConfiguration(const QVariant args)
|
||||
int AWStringFormatter::showConfiguration(const QVariant &_args)
|
||||
{
|
||||
Q_UNUSED(args)
|
||||
Q_UNUSED(_args)
|
||||
|
||||
ui->lineEdit_name->setText(name());
|
||||
ui->lineEdit_comment->setText(comment());
|
||||
ui->label_typeValue->setText(QString("String"));
|
||||
ui->label_typeValue->setText("String");
|
||||
ui->spinBox_width->setValue(count());
|
||||
ui->lineEdit_fill->setText(QString(fillChar()));
|
||||
ui->checkBox_forceWidth->setCheckState(forceWidth() ? Qt::Checked
|
||||
@ -154,7 +152,7 @@ int AWStringFormatter::showConfiguration(const QVariant args)
|
||||
return ret;
|
||||
setName(ui->lineEdit_name->text());
|
||||
setComment(ui->lineEdit_comment->text());
|
||||
setApiVersion(AWEFAPI);
|
||||
setApiVersion(AW_FORMATTER_API);
|
||||
setStrType(ui->label_typeValue->text());
|
||||
setCount(ui->spinBox_width->value());
|
||||
setFillChar(ui->lineEdit_fill->text().at(0));
|
||||
@ -172,10 +170,10 @@ void AWStringFormatter::writeConfiguration() const
|
||||
QSettings settings(writtableConfig(), QSettings::IniFormat);
|
||||
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
settings.setValue(QString("X-AW-Width"), count());
|
||||
settings.setValue(QString("X-AW-FillChar"), fillChar());
|
||||
settings.setValue(QString("X-AW-ForceWidth"), forceWidth());
|
||||
settings.beginGroup("Desktop Entry");
|
||||
settings.setValue("X-AW-Width", count());
|
||||
settings.setValue("X-AW-FillChar", fillChar());
|
||||
settings.setValue("X-AW-ForceWidth", forceWidth());
|
||||
settings.endGroup();
|
||||
|
||||
settings.sync();
|
||||
|
@ -34,22 +34,22 @@ class AWStringFormatter : public AWAbstractFormatter
|
||||
Q_PROPERTY(bool forceWidth READ forceWidth WRITE setForceWidth)
|
||||
|
||||
public:
|
||||
explicit AWStringFormatter(QWidget *parent,
|
||||
const QString filePath = QString());
|
||||
explicit AWStringFormatter(QWidget *_parent = nullptr,
|
||||
const QString &_filePath = "");
|
||||
virtual ~AWStringFormatter();
|
||||
QString convert(const QVariant &_value) const;
|
||||
AWStringFormatter *copy(const QString _fileName, const int _number);
|
||||
AWStringFormatter *copy(const QString &_fileName, const int _number);
|
||||
// properties
|
||||
int count() const;
|
||||
QChar fillChar() const;
|
||||
bool forceWidth() const;
|
||||
void setCount(const int _count);
|
||||
void setFillChar(const QChar _fillChar);
|
||||
void setFillChar(const QChar &_fillChar);
|
||||
void setForceWidth(const bool _forceWidth);
|
||||
|
||||
public slots:
|
||||
void readConfiguration();
|
||||
int showConfiguration(const QVariant args = QVariant());
|
||||
int showConfiguration(const QVariant &_args);
|
||||
void writeConfiguration() const;
|
||||
|
||||
private:
|
||||
|
@ -12,5 +12,5 @@ X-AW-Type=Horizontal
|
||||
X-AW-Direction=LeftToRight
|
||||
X-AW-Height=25
|
||||
X-AW-Width=100
|
||||
X-AW-ApiVersion=5
|
||||
X-AW-ApiVersion=6
|
||||
X-AW-Number=3
|
||||
|
@ -12,5 +12,5 @@ X-AW-Type=Horizontal
|
||||
X-AW-Direction=LeftToRight
|
||||
X-AW-Height=25
|
||||
X-AW-Width=100
|
||||
X-AW-ApiVersion=5
|
||||
X-AW-ApiVersion=6
|
||||
X-AW-Number=0
|
||||
|
@ -12,5 +12,5 @@ X-AW-Type=Horizontal
|
||||
X-AW-Direction=LeftToRight
|
||||
X-AW-Height=25
|
||||
X-AW-Width=100
|
||||
X-AW-ApiVersion=5
|
||||
X-AW-ApiVersion=6
|
||||
X-AW-Number=1
|
||||
|
@ -12,5 +12,5 @@ X-AW-Type=Horizontal
|
||||
X-AW-Direction=LeftToRight
|
||||
X-AW-Height=25
|
||||
X-AW-Width=100
|
||||
X-AW-ApiVersion=5
|
||||
X-AW-ApiVersion=6
|
||||
X-AW-Number=2
|
||||
|
@ -31,15 +31,15 @@
|
||||
template <class T> class ExtItemAggregator : public AbstractExtItemAggregator
|
||||
{
|
||||
public:
|
||||
explicit ExtItemAggregator(QWidget *parent, const QString type)
|
||||
: AbstractExtItemAggregator(parent, type)
|
||||
explicit ExtItemAggregator(QWidget *_parent, const QString &_type)
|
||||
: AbstractExtItemAggregator(_parent, _type)
|
||||
{
|
||||
qSetMessagePattern(LOG_FORMAT);
|
||||
qSetMessagePattern(AWDebug::LOG_FORMAT);
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
for (auto metadata : getBuildData())
|
||||
for (auto &metadata : AWDebug::getBuildData())
|
||||
qCDebug(LOG_LIB) << metadata;
|
||||
|
||||
qCDebug(LOG_LIB) << "Type" << type;
|
||||
qCDebug(LOG_LIB) << "Type" << _type;
|
||||
|
||||
initItems();
|
||||
};
|
||||
@ -61,12 +61,21 @@ public:
|
||||
qCInfo(LOG_LIB) << "Dialog returns" << ret;
|
||||
};
|
||||
|
||||
T *itemByTag(const QString _tag, const QString _type) const
|
||||
void initSockets()
|
||||
{
|
||||
// HACK as soon as per one widget instance we have two objects each of
|
||||
// them will try to control socket, whereas actually only one of them
|
||||
// should be owner of the socket
|
||||
for (auto &item : m_items)
|
||||
item->initSocket();
|
||||
}
|
||||
|
||||
T *itemByTag(const QString &_tag, const QString &_type) const
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Tag" << _tag << "with used type" << _type;
|
||||
|
||||
T *found = nullptr;
|
||||
for (auto item : m_items) {
|
||||
for (auto &item : m_items) {
|
||||
if (item->tag(_type) != _tag)
|
||||
continue;
|
||||
found = static_cast<T *>(item);
|
||||
@ -83,7 +92,7 @@ public:
|
||||
qCDebug(LOG_LIB) << "Number" << _number;
|
||||
|
||||
T *found = nullptr;
|
||||
for (auto item : m_items) {
|
||||
for (auto &item : m_items) {
|
||||
if (item->number() != _number)
|
||||
continue;
|
||||
found = static_cast<T *>(item);
|
||||
@ -120,11 +129,10 @@ private:
|
||||
QStandardPaths::LocateDirectory);
|
||||
QStringList names;
|
||||
QList<AbstractExtItem *> items;
|
||||
for (auto dir : dirs) {
|
||||
for (auto &dir : dirs) {
|
||||
QStringList files = QDir(dir).entryList(QDir::Files, QDir::Name);
|
||||
for (auto file : files) {
|
||||
if ((!file.endsWith(QString(".desktop")))
|
||||
|| (names.contains(file)))
|
||||
for (auto &file : files) {
|
||||
if ((!file.endsWith(".desktop")) || (names.contains(file)))
|
||||
continue;
|
||||
qCInfo(LOG_LIB) << "Found file" << file << "in" << dir;
|
||||
names.append(file);
|
||||
@ -147,7 +155,7 @@ private:
|
||||
m_activeItems.clear();
|
||||
|
||||
m_items = getItems();
|
||||
for (auto item : m_items) {
|
||||
for (auto &item : m_items) {
|
||||
if (!item->isActive())
|
||||
continue;
|
||||
m_activeItems.append(static_cast<T *>(item));
|
||||
|
216
sources/awesomewidgets/extnetworkrequest.cpp
Normal file
216
sources/awesomewidgets/extnetworkrequest.cpp
Normal file
@ -0,0 +1,216 @@
|
||||
/***************************************************************************
|
||||
* 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 "extnetworkrequest.h"
|
||||
#include "ui_extnetworkrequest.h"
|
||||
|
||||
#include <KI18n/KLocalizedString>
|
||||
|
||||
#include <QDir>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkRequest>
|
||||
#include <QSettings>
|
||||
#include <QTextCodec>
|
||||
|
||||
#include <qreplytimeout/qreplytimeout.h>
|
||||
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
ExtNetworkRequest::ExtNetworkRequest(QWidget *_parent, const QString &_filePath)
|
||||
: AbstractExtItem(_parent, _filePath)
|
||||
, ui(new Ui::ExtNetworkRequest)
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
if (!_filePath.isEmpty())
|
||||
readConfiguration();
|
||||
ui->setupUi(this);
|
||||
translate();
|
||||
|
||||
m_values[tag("response")] = "";
|
||||
|
||||
// HACK declare as child of nullptr to avoid crash with plasmawindowed
|
||||
// in the destructor
|
||||
m_manager = new QNetworkAccessManager(nullptr);
|
||||
connect(m_manager, SIGNAL(finished(QNetworkReply *)), this,
|
||||
SLOT(networkReplyReceived(QNetworkReply *)));
|
||||
|
||||
connect(this, SIGNAL(requestDataUpdate()), this, SLOT(sendRequest()));
|
||||
}
|
||||
|
||||
|
||||
ExtNetworkRequest::~ExtNetworkRequest()
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
disconnect(m_manager, SIGNAL(finished(QNetworkReply *)), this,
|
||||
SLOT(networkReplyReceived(QNetworkReply *)));
|
||||
disconnect(this, SIGNAL(requestDataUpdate()), this, SLOT(sendRequest()));
|
||||
|
||||
m_manager->deleteLater();
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
||||
ExtNetworkRequest *ExtNetworkRequest::copy(const QString &_fileName,
|
||||
const int _number)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
||||
|
||||
ExtNetworkRequest *item
|
||||
= new ExtNetworkRequest(static_cast<QWidget *>(parent()), _fileName);
|
||||
copyDefaults(item);
|
||||
item->setNumber(_number);
|
||||
item->setStringUrl(stringUrl());
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
QString ExtNetworkRequest::stringUrl() const
|
||||
{
|
||||
return m_stringUrl;
|
||||
}
|
||||
|
||||
|
||||
QString ExtNetworkRequest::uniq() const
|
||||
{
|
||||
return m_url.toString();
|
||||
}
|
||||
|
||||
|
||||
void ExtNetworkRequest::setStringUrl(const QString &_url)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Url" << _url;
|
||||
|
||||
m_stringUrl = _url;
|
||||
initUrl();
|
||||
}
|
||||
|
||||
|
||||
void ExtNetworkRequest::readConfiguration()
|
||||
{
|
||||
AbstractExtItem::readConfiguration();
|
||||
|
||||
QSettings settings(fileName(), QSettings::IniFormat);
|
||||
|
||||
settings.beginGroup("Desktop Entry");
|
||||
setStringUrl(settings.value("X-AW-Url", stringUrl()).toString());
|
||||
settings.endGroup();
|
||||
|
||||
bumpApi(AW_EXTNETREQUEST_API);
|
||||
}
|
||||
|
||||
|
||||
QVariantHash ExtNetworkRequest::run()
|
||||
{
|
||||
if (m_isRunning)
|
||||
return m_values;
|
||||
startTimer();
|
||||
|
||||
return m_values;
|
||||
}
|
||||
|
||||
|
||||
int ExtNetworkRequest::showConfiguration(const QVariant &_args)
|
||||
{
|
||||
Q_UNUSED(_args)
|
||||
|
||||
ui->lineEdit_name->setText(name());
|
||||
ui->lineEdit_comment->setText(comment());
|
||||
ui->label_numberValue->setText(QString("%1").arg(number()));
|
||||
ui->lineEdit_url->setText(stringUrl());
|
||||
ui->checkBox_active->setCheckState(isActive() ? Qt::Checked
|
||||
: Qt::Unchecked);
|
||||
ui->lineEdit_schedule->setText(cron());
|
||||
ui->lineEdit_socket->setText(socket());
|
||||
ui->spinBox_interval->setValue(interval());
|
||||
|
||||
int ret = exec();
|
||||
if (ret != 1)
|
||||
return ret;
|
||||
setName(ui->lineEdit_name->text());
|
||||
setComment(ui->lineEdit_comment->text());
|
||||
setNumber(ui->label_numberValue->text().toInt());
|
||||
setApiVersion(AW_EXTNETREQUEST_API);
|
||||
setStringUrl(ui->lineEdit_url->text());
|
||||
setActive(ui->checkBox_active->checkState() == Qt::Checked);
|
||||
setCron(ui->lineEdit_schedule->text());
|
||||
setSocket(ui->lineEdit_socket->text());
|
||||
setInterval(ui->spinBox_interval->value());
|
||||
|
||||
writeConfiguration();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void ExtNetworkRequest::writeConfiguration() const
|
||||
{
|
||||
AbstractExtItem::writeConfiguration();
|
||||
|
||||
QSettings settings(writtableConfig(), QSettings::IniFormat);
|
||||
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
|
||||
|
||||
settings.beginGroup("Desktop Entry");
|
||||
settings.setValue("X-AW-Url", stringUrl());
|
||||
settings.endGroup();
|
||||
|
||||
settings.sync();
|
||||
}
|
||||
|
||||
void ExtNetworkRequest::networkReplyReceived(QNetworkReply *_reply)
|
||||
{
|
||||
if (_reply->error() != QNetworkReply::NoError) {
|
||||
qCWarning(LOG_AW) << "An error occurs" << _reply->error()
|
||||
<< "with message" << _reply->errorString();
|
||||
return;
|
||||
}
|
||||
|
||||
m_isRunning = false;
|
||||
m_values[tag("response")]
|
||||
= QTextCodec::codecForMib(106)->toUnicode(_reply->readAll()).trimmed();
|
||||
|
||||
emit(dataReceived(m_values));
|
||||
}
|
||||
|
||||
|
||||
void ExtNetworkRequest::sendRequest()
|
||||
{
|
||||
m_isRunning = true;
|
||||
QNetworkReply *reply = m_manager->get(QNetworkRequest(m_url));
|
||||
new QReplyTimeout(reply, REQUEST_TIMEOUT);
|
||||
}
|
||||
|
||||
|
||||
void ExtNetworkRequest::initUrl()
|
||||
{
|
||||
m_url = QUrl(m_stringUrl);
|
||||
}
|
||||
|
||||
|
||||
void ExtNetworkRequest::translate()
|
||||
{
|
||||
ui->label_name->setText(i18n("Name"));
|
||||
ui->label_comment->setText(i18n("Comment"));
|
||||
ui->label_number->setText(i18n("Tag"));
|
||||
ui->label_url->setText(i18n("URL"));
|
||||
ui->checkBox_active->setText(i18n("Active"));
|
||||
ui->label_schedule->setText(i18n("Schedule"));
|
||||
ui->label_socket->setText(i18n("Socket"));
|
||||
ui->label_interval->setText(i18n("Interval"));
|
||||
}
|
71
sources/awesomewidgets/extnetworkrequest.h
Normal file
71
sources/awesomewidgets/extnetworkrequest.h
Normal file
@ -0,0 +1,71 @@
|
||||
/***************************************************************************
|
||||
* 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 EXTNETWORKREQUEST_H
|
||||
#define EXTNETWORKREQUEST_H
|
||||
|
||||
#include <QNetworkReply>
|
||||
|
||||
#include "abstractextitem.h"
|
||||
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class ExtNetworkRequest;
|
||||
}
|
||||
|
||||
class ExtNetworkRequest : public AbstractExtItem
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString stringUrl READ stringUrl WRITE setStringUrl)
|
||||
|
||||
public:
|
||||
explicit ExtNetworkRequest(QWidget *_parent = nullptr,
|
||||
const QString &_filePath = "");
|
||||
virtual ~ExtNetworkRequest();
|
||||
ExtNetworkRequest *copy(const QString &_fileName, const int _number);
|
||||
// get methods
|
||||
QString stringUrl() const;
|
||||
QString uniq() const;
|
||||
// set methods
|
||||
void setStringUrl(const QString &_url);
|
||||
|
||||
public slots:
|
||||
void readConfiguration();
|
||||
QVariantHash run();
|
||||
int showConfiguration(const QVariant &_args);
|
||||
void writeConfiguration() const;
|
||||
|
||||
private slots:
|
||||
void networkReplyReceived(QNetworkReply *_reply);
|
||||
void sendRequest();
|
||||
|
||||
private:
|
||||
QNetworkAccessManager *m_manager = nullptr;
|
||||
QUrl m_url;
|
||||
bool m_isRunning = false;
|
||||
Ui::ExtNetworkRequest *ui = nullptr;
|
||||
void initUrl();
|
||||
void translate();
|
||||
// properties
|
||||
QString m_stringUrl = "https://httpbin.org/get";
|
||||
// values
|
||||
QVariantHash m_values;
|
||||
};
|
||||
|
||||
|
||||
#endif /* EXTNETWORKREQUEST_H */
|
282
sources/awesomewidgets/extnetworkrequest.ui
Normal file
282
sources/awesomewidgets/extnetworkrequest.ui
Normal file
@ -0,0 +1,282 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ExtNetworkRequest</class>
|
||||
<widget class="QDialog" name="ExtNetworkRequest">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>420</width>
|
||||
<height>320</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Configuration</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_name">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_name">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_name"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_comment">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_comment">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Comment</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_comment"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_number">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_number">
|
||||
<property name="text">
|
||||
<string>Tag</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_numberValue">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_url">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_url">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>URL</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_url"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_active">
|
||||
<item>
|
||||
<spacer name="spacer_active">
|
||||
<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="QCheckBox" name="checkBox_active">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Active</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_update">
|
||||
<property name="title">
|
||||
<string>Update</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_interval">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_interval">
|
||||
<property name="text">
|
||||
<string>Interval</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="spinBox_interval">
|
||||
<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>3600</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_schedule">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_schedule">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Schedule</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_schedule"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_socket">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_socket">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Socket</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_socket"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>ExtNetworkRequest</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>ExtNetworkRequest</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
@ -33,32 +33,34 @@
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
ExtQuotes::ExtQuotes(QWidget *parent, const QString filePath)
|
||||
: AbstractExtItem(parent, filePath)
|
||||
ExtQuotes::ExtQuotes(QWidget *_parent, const QString &_filePath)
|
||||
: AbstractExtItem(_parent, _filePath)
|
||||
, ui(new Ui::ExtQuotes)
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
if (!filePath.isEmpty())
|
||||
if (!_filePath.isEmpty())
|
||||
readConfiguration();
|
||||
ui->setupUi(this);
|
||||
translate();
|
||||
|
||||
m_values[tag(QString("ask"))] = 0.0;
|
||||
m_values[tag(QString("askchg"))] = 0.0;
|
||||
m_values[tag(QString("percaskchg"))] = 0.0;
|
||||
m_values[tag(QString("bid"))] = 0.0;
|
||||
m_values[tag(QString("bidchg"))] = 0.0;
|
||||
m_values[tag(QString("percbidchg"))] = 0.0;
|
||||
m_values[tag(QString("price"))] = 0.0;
|
||||
m_values[tag(QString("pricechg"))] = 0.0;
|
||||
m_values[tag(QString("percpricechg"))] = 0.0;
|
||||
m_values[tag("ask")] = 0.0;
|
||||
m_values[tag("askchg")] = 0.0;
|
||||
m_values[tag("percaskchg")] = 0.0;
|
||||
m_values[tag("bid")] = 0.0;
|
||||
m_values[tag("bidchg")] = 0.0;
|
||||
m_values[tag("percbidchg")] = 0.0;
|
||||
m_values[tag("price")] = 0.0;
|
||||
m_values[tag("pricechg")] = 0.0;
|
||||
m_values[tag("percpricechg")] = 0.0;
|
||||
|
||||
// HACK declare as child of nullptr to avoid crash with plasmawindowed
|
||||
// in the destructor
|
||||
m_manager = new QNetworkAccessManager(nullptr);
|
||||
connect(m_manager, SIGNAL(finished(QNetworkReply *)), this,
|
||||
SLOT(quotesReplyReceived(QNetworkReply *)));
|
||||
|
||||
connect(this, SIGNAL(requestDataUpdate()), this, SLOT(sendRequest()));
|
||||
}
|
||||
|
||||
|
||||
@ -68,13 +70,14 @@ ExtQuotes::~ExtQuotes()
|
||||
|
||||
disconnect(m_manager, SIGNAL(finished(QNetworkReply *)), this,
|
||||
SLOT(quotesReplyReceived(QNetworkReply *)));
|
||||
disconnect(this, SIGNAL(requestDataUpdate()), this, SLOT(sendRequest()));
|
||||
|
||||
m_manager->deleteLater();
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
||||
ExtQuotes *ExtQuotes::copy(const QString _fileName, const int _number)
|
||||
ExtQuotes *ExtQuotes::copy(const QString &_fileName, const int _number)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
||||
|
||||
@ -100,7 +103,7 @@ QString ExtQuotes::uniq() const
|
||||
}
|
||||
|
||||
|
||||
void ExtQuotes::setTicker(const QString _ticker)
|
||||
void ExtQuotes::setTicker(const QString &_ticker)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Ticker" << _ticker;
|
||||
|
||||
@ -115,38 +118,27 @@ void ExtQuotes::readConfiguration()
|
||||
|
||||
QSettings settings(fileName(), QSettings::IniFormat);
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
setTicker(settings.value(QString("X-AW-Ticker"), ticker()).toString());
|
||||
settings.beginGroup("Desktop Entry");
|
||||
setTicker(settings.value("X-AW-Ticker", ticker()).toString());
|
||||
settings.endGroup();
|
||||
|
||||
bumpApi(AWEQAPI);
|
||||
bumpApi(AW_EXTQUOTES_API);
|
||||
}
|
||||
|
||||
|
||||
QVariantHash ExtQuotes::run()
|
||||
{
|
||||
if ((!isActive()) || (m_isRunning))
|
||||
if (m_isRunning)
|
||||
return m_values;
|
||||
|
||||
if (m_times == 1) {
|
||||
qCInfo(LOG_LIB) << "Send request";
|
||||
m_isRunning = true;
|
||||
QNetworkReply *reply = m_manager->get(QNetworkRequest(m_url));
|
||||
new QReplyTimeout(reply, REQUEST_TIMEOUT);
|
||||
}
|
||||
|
||||
// update value
|
||||
if (m_times >= interval())
|
||||
m_times = 0;
|
||||
m_times++;
|
||||
startTimer();
|
||||
|
||||
return m_values;
|
||||
}
|
||||
|
||||
|
||||
int ExtQuotes::showConfiguration(const QVariant args)
|
||||
int ExtQuotes::showConfiguration(const QVariant &_args)
|
||||
{
|
||||
Q_UNUSED(args)
|
||||
Q_UNUSED(_args)
|
||||
|
||||
ui->lineEdit_name->setText(name());
|
||||
ui->lineEdit_comment->setText(comment());
|
||||
@ -154,6 +146,8 @@ int ExtQuotes::showConfiguration(const QVariant args)
|
||||
ui->lineEdit_ticker->setText(ticker());
|
||||
ui->checkBox_active->setCheckState(isActive() ? Qt::Checked
|
||||
: Qt::Unchecked);
|
||||
ui->lineEdit_schedule->setText(cron());
|
||||
ui->lineEdit_socket->setText(socket());
|
||||
ui->spinBox_interval->setValue(interval());
|
||||
|
||||
int ret = exec();
|
||||
@ -162,9 +156,11 @@ int ExtQuotes::showConfiguration(const QVariant args)
|
||||
setName(ui->lineEdit_name->text());
|
||||
setComment(ui->lineEdit_comment->text());
|
||||
setNumber(ui->label_numberValue->text().toInt());
|
||||
setApiVersion(AWEQAPI);
|
||||
setApiVersion(AW_EXTQUOTES_API);
|
||||
setTicker(ui->lineEdit_ticker->text());
|
||||
setActive(ui->checkBox_active->checkState() == Qt::Checked);
|
||||
setCron(ui->lineEdit_schedule->text());
|
||||
setSocket(ui->lineEdit_socket->text());
|
||||
setInterval(ui->spinBox_interval->value());
|
||||
|
||||
writeConfiguration();
|
||||
@ -179,80 +175,80 @@ void ExtQuotes::writeConfiguration() const
|
||||
QSettings settings(writtableConfig(), QSettings::IniFormat);
|
||||
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
settings.setValue(QString("X-AW-Ticker"), ticker());
|
||||
settings.beginGroup("Desktop Entry");
|
||||
settings.setValue("X-AW-Ticker", ticker());
|
||||
settings.endGroup();
|
||||
|
||||
settings.sync();
|
||||
}
|
||||
|
||||
void ExtQuotes::quotesReplyReceived(QNetworkReply *reply)
|
||||
void ExtQuotes::quotesReplyReceived(QNetworkReply *_reply)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Return code" << reply->error() << "with message"
|
||||
<< reply->errorString();
|
||||
if (_reply->error() != QNetworkReply::NoError) {
|
||||
qCWarning(LOG_AW) << "An error occurs" << _reply->error()
|
||||
<< "with message" << _reply->errorString();
|
||||
return;
|
||||
}
|
||||
|
||||
m_isRunning = false;
|
||||
QJsonParseError error;
|
||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(reply->readAll(), &error);
|
||||
reply->deleteLater();
|
||||
if ((reply->error() != QNetworkReply::NoError)
|
||||
|| (error.error != QJsonParseError::NoError)) {
|
||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(_reply->readAll(), &error);
|
||||
_reply->deleteLater();
|
||||
if (error.error != QJsonParseError::NoError) {
|
||||
qCWarning(LOG_LIB) << "Parse error" << error.errorString();
|
||||
return;
|
||||
}
|
||||
QVariantMap jsonQuotes
|
||||
= jsonDoc.toVariant().toMap()[QString("query")].toMap();
|
||||
jsonQuotes
|
||||
= jsonQuotes[QString("results")].toMap()[QString("quote")].toMap();
|
||||
QVariantMap jsonQuotes = jsonDoc.toVariant().toMap()["query"].toMap();
|
||||
jsonQuotes = jsonQuotes["results"].toMap()["quote"].toMap();
|
||||
double value;
|
||||
|
||||
// ask
|
||||
value = jsonQuotes[QString("Ask")].toString().toDouble();
|
||||
m_values[tag(QString("askchg"))]
|
||||
= m_values[tag(QString("ask"))].toDouble() == 0.0
|
||||
? 0.0
|
||||
: value - m_values[tag(QString("ask"))].toDouble();
|
||||
m_values[tag(QString("percaskchg"))]
|
||||
= 100.0 * m_values[tag(QString("askchg"))].toDouble()
|
||||
/ m_values[tag(QString("ask"))].toDouble();
|
||||
m_values[tag(QString("ask"))] = value;
|
||||
value = jsonQuotes["Ask"].toString().toDouble();
|
||||
m_values[tag("askchg")] = m_values[tag("ask")].toDouble() == 0.0
|
||||
? 0.0
|
||||
: value - m_values[tag("ask")].toDouble();
|
||||
m_values[tag("percaskchg")] = 100.0 * m_values[tag("askchg")].toDouble()
|
||||
/ m_values[tag("ask")].toDouble();
|
||||
m_values[tag("ask")] = value;
|
||||
|
||||
// bid
|
||||
value = jsonQuotes[QString("Bid")].toString().toDouble();
|
||||
m_values[tag(QString("bidchg"))]
|
||||
= m_values[tag(QString("bid"))].toDouble() == 0.0
|
||||
? 0.0
|
||||
: value - m_values[tag(QString("bid"))].toDouble();
|
||||
m_values[tag(QString("percbidchg"))]
|
||||
= 100.0 * m_values[tag(QString("bidchg"))].toDouble()
|
||||
/ m_values[tag(QString("bid"))].toDouble();
|
||||
m_values[tag(QString("bid"))] = value;
|
||||
value = jsonQuotes["Bid"].toString().toDouble();
|
||||
m_values[tag("bidchg")] = m_values[tag("bid")].toDouble() == 0.0
|
||||
? 0.0
|
||||
: value - m_values[tag("bid")].toDouble();
|
||||
m_values[tag("percbidchg")] = 100.0 * m_values[tag("bidchg")].toDouble()
|
||||
/ m_values[tag("bid")].toDouble();
|
||||
m_values[tag("bid")] = value;
|
||||
|
||||
// last trade
|
||||
value = jsonQuotes[QString("LastTradePriceOnly")].toString().toDouble();
|
||||
m_values[tag(QString("pricechg"))]
|
||||
= m_values[tag(QString("price"))].toDouble() == 0.0
|
||||
? 0.0
|
||||
: value - m_values[tag(QString("price"))].toDouble();
|
||||
m_values[tag(QString("percpricechg"))]
|
||||
= 100.0 * m_values[tag(QString("pricechg"))].toDouble()
|
||||
/ m_values[tag(QString("price"))].toDouble();
|
||||
m_values[tag(QString("price"))] = value;
|
||||
value = jsonQuotes["LastTradePriceOnly"].toString().toDouble();
|
||||
m_values[tag("pricechg")] = m_values[tag("price")].toDouble() == 0.0
|
||||
? 0.0
|
||||
: value - m_values[tag("price")].toDouble();
|
||||
m_values[tag("percpricechg")] = 100.0 * m_values[tag("pricechg")].toDouble()
|
||||
/ m_values[tag("price")].toDouble();
|
||||
m_values[tag("price")] = value;
|
||||
|
||||
emit(dataReceived(m_values));
|
||||
}
|
||||
|
||||
|
||||
void ExtQuotes::sendRequest()
|
||||
{
|
||||
m_isRunning = true;
|
||||
QNetworkReply *reply = m_manager->get(QNetworkRequest(m_url));
|
||||
new QReplyTimeout(reply, REQUEST_TIMEOUT);
|
||||
}
|
||||
|
||||
|
||||
void ExtQuotes::initUrl()
|
||||
{
|
||||
// init query
|
||||
m_url = QUrl(YAHOO_QUOTES_URL);
|
||||
QUrlQuery params;
|
||||
params.addQueryItem(QString("format"), QString("json"));
|
||||
params.addQueryItem(QString("env"),
|
||||
QString("store://datatables.org/alltableswithkeys"));
|
||||
params.addQueryItem(QString("q"),
|
||||
QString(YAHOO_QUOTES_QUERY).arg(ticker()));
|
||||
params.addQueryItem("format", "json");
|
||||
params.addQueryItem("env", "store://datatables.org/alltableswithkeys");
|
||||
params.addQueryItem("q", QString(YAHOO_QUOTES_QUERY).arg(ticker()));
|
||||
m_url.setQuery(params);
|
||||
}
|
||||
|
||||
@ -269,5 +265,7 @@ get quotes for the instrument. Refer to <a href=\"http://finance.yahoo.com/\">\
|
||||
</span></a></p></body></html>"));
|
||||
ui->label_ticker->setText(i18n("Ticker"));
|
||||
ui->checkBox_active->setText(i18n("Active"));
|
||||
ui->label_schedule->setText(i18n("Schedule"));
|
||||
ui->label_socket->setText(i18n("Socket"));
|
||||
ui->label_interval->setText(i18n("Interval"));
|
||||
}
|
||||
|
@ -22,10 +22,6 @@
|
||||
|
||||
#include "abstractextitem.h"
|
||||
|
||||
#define YAHOO_QUOTES_URL "https://query.yahooapis.com/v1/public/yql"
|
||||
#define YAHOO_QUOTES_QUERY \
|
||||
"select * from yahoo.finance.quotes where symbol='%1'"
|
||||
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
@ -38,23 +34,29 @@ class ExtQuotes : public AbstractExtItem
|
||||
Q_PROPERTY(QString ticker READ ticker WRITE setTicker)
|
||||
|
||||
public:
|
||||
explicit ExtQuotes(QWidget *parent, const QString filePath = QString());
|
||||
const char *YAHOO_QUOTES_URL = "https://query.yahooapis.com/v1/public/yql";
|
||||
const char *YAHOO_QUOTES_QUERY
|
||||
= "select * from yahoo.finance.quotes where symbol='%1'";
|
||||
|
||||
explicit ExtQuotes(QWidget *_parent = nullptr,
|
||||
const QString &_filePath = "");
|
||||
virtual ~ExtQuotes();
|
||||
ExtQuotes *copy(const QString _fileName, const int _number);
|
||||
ExtQuotes *copy(const QString &_fileName, const int _number);
|
||||
// get methods
|
||||
QString ticker() const;
|
||||
QString uniq() const;
|
||||
// set methods
|
||||
void setTicker(const QString _ticker = QString("EURUSD=X"));
|
||||
void setTicker(const QString &_ticker);
|
||||
|
||||
public slots:
|
||||
void readConfiguration();
|
||||
QVariantHash run();
|
||||
int showConfiguration(const QVariant args = QVariant());
|
||||
int showConfiguration(const QVariant &_args);
|
||||
void writeConfiguration() const;
|
||||
|
||||
private slots:
|
||||
void quotesReplyReceived(QNetworkReply *reply);
|
||||
void quotesReplyReceived(QNetworkReply *_reply);
|
||||
void sendRequest();
|
||||
|
||||
private:
|
||||
QNetworkAccessManager *m_manager = nullptr;
|
||||
@ -64,9 +66,8 @@ private:
|
||||
void initUrl();
|
||||
void translate();
|
||||
// properties
|
||||
QString m_ticker = QString("EURUSD=X");
|
||||
QString m_ticker = "EURUSD=X";
|
||||
// values
|
||||
int m_times = 0;
|
||||
QVariantHash m_values;
|
||||
};
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>420</width>
|
||||
<height>301</height>
|
||||
<height>378</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -151,34 +151,89 @@
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_interval">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_interval">
|
||||
<property name="text">
|
||||
<string>Interval</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="spinBox_interval">
|
||||
<property name="minimum">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>10000</number>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>60</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
<widget class="QGroupBox" name="groupBox_update">
|
||||
<property name="title">
|
||||
<string>Update</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_interval">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_interval">
|
||||
<property name="text">
|
||||
<string>Interval</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="spinBox_interval">
|
||||
<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>3600</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_schedule">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_schedule">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Schedule</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_schedule"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_socket">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_socket">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Socket</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_socket"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
|
@ -30,24 +30,26 @@
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
ExtScript::ExtScript(QWidget *parent, const QString filePath)
|
||||
: AbstractExtItem(parent, filePath)
|
||||
ExtScript::ExtScript(QWidget *_parent, const QString &_filePath)
|
||||
: AbstractExtItem(_parent, _filePath)
|
||||
, ui(new Ui::ExtScript)
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
if (!filePath.isEmpty())
|
||||
if (!_filePath.isEmpty())
|
||||
readConfiguration();
|
||||
readJsonFilters();
|
||||
ui->setupUi(this);
|
||||
translate();
|
||||
|
||||
m_values[tag(QString("custom"))] = QString("");
|
||||
m_values[tag("custom")] = "";
|
||||
|
||||
m_process = new QProcess(nullptr);
|
||||
connect(m_process, SIGNAL(finished(int, QProcess::ExitStatus)), this,
|
||||
SLOT(updateValue()));
|
||||
m_process->waitForFinished(0);
|
||||
|
||||
connect(this, SIGNAL(requestDataUpdate()), this, SLOT(startProcess()));
|
||||
}
|
||||
|
||||
|
||||
@ -55,13 +57,16 @@ ExtScript::~ExtScript()
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
disconnect(m_process, SIGNAL(finished(int, QProcess::ExitStatus)), this,
|
||||
SLOT(updateValue()));
|
||||
m_process->kill();
|
||||
m_process->deleteLater();
|
||||
disconnect(this, SIGNAL(requestDataUpdate()), this, SLOT(startProcess()));
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
||||
ExtScript *ExtScript::copy(const QString _fileName, const int _number)
|
||||
ExtScript *ExtScript::copy(const QString &_fileName, const int _number)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
||||
|
||||
@ -78,6 +83,17 @@ ExtScript *ExtScript::copy(const QString _fileName, const int _number)
|
||||
}
|
||||
|
||||
|
||||
QString ExtScript::jsonFiltersFile() const
|
||||
{
|
||||
QString fileName = QStandardPaths::locate(
|
||||
QStandardPaths::GenericDataLocation,
|
||||
"awesomewidgets/scripts/awesomewidgets-extscripts-filters.json");
|
||||
qCInfo(LOG_LIB) << "Filters file" << fileName;
|
||||
|
||||
return fileName;
|
||||
}
|
||||
|
||||
|
||||
QString ExtScript::executable() const
|
||||
{
|
||||
return m_executable;
|
||||
@ -113,16 +129,16 @@ QString ExtScript::strRedirect() const
|
||||
QString value;
|
||||
switch (redirect()) {
|
||||
case Redirect::stdout2stderr:
|
||||
value = QString("stdout2stderr");
|
||||
value = "stdout2stderr";
|
||||
break;
|
||||
case Redirect::stderr2stdout:
|
||||
value = QString("stderr2stdout");
|
||||
value = "stderr2stdout";
|
||||
break;
|
||||
case Redirect::swap:
|
||||
value = QString("swap");
|
||||
value = "swap";
|
||||
break;
|
||||
case Redirect::nothing:
|
||||
value = QString("nothing");
|
||||
value = "nothing";
|
||||
break;
|
||||
}
|
||||
|
||||
@ -130,7 +146,7 @@ QString ExtScript::strRedirect() const
|
||||
}
|
||||
|
||||
|
||||
void ExtScript::setExecutable(const QString _executable)
|
||||
void ExtScript::setExecutable(const QString &_executable)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Executable" << _executable;
|
||||
|
||||
@ -138,16 +154,17 @@ void ExtScript::setExecutable(const QString _executable)
|
||||
}
|
||||
|
||||
|
||||
void ExtScript::setFilters(const QStringList _filters)
|
||||
void ExtScript::setFilters(const QStringList &_filters)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Filters" << _filters;
|
||||
|
||||
std::for_each(_filters.cbegin(), _filters.cend(),
|
||||
[this](QString filter) { return updateFilter(filter); });
|
||||
std::for_each(
|
||||
_filters.cbegin(), _filters.cend(),
|
||||
[this](const QString &filter) { return updateFilter(filter, true); });
|
||||
}
|
||||
|
||||
|
||||
void ExtScript::setPrefix(const QString _prefix)
|
||||
void ExtScript::setPrefix(const QString &_prefix)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Prefix" << _prefix;
|
||||
|
||||
@ -163,15 +180,15 @@ void ExtScript::setRedirect(const Redirect _redirect)
|
||||
}
|
||||
|
||||
|
||||
void ExtScript::setStrRedirect(const QString _redirect)
|
||||
void ExtScript::setStrRedirect(const QString &_redirect)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Redirect" << _redirect;
|
||||
|
||||
if (_redirect == QString("stdout2sdterr"))
|
||||
if (_redirect == "stdout2sdterr")
|
||||
setRedirect(Redirect::stdout2stderr);
|
||||
else if (_redirect == QString("stderr2sdtout"))
|
||||
else if (_redirect == "stderr2sdtout")
|
||||
setRedirect(Redirect::stderr2stdout);
|
||||
else if (_redirect == QString("swap"))
|
||||
else if (_redirect == "swap")
|
||||
setRedirect(Redirect::swap);
|
||||
else
|
||||
setRedirect(Redirect::nothing);
|
||||
@ -182,15 +199,15 @@ QString ExtScript::applyFilters(QString _value) const
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Value" << _value;
|
||||
|
||||
for (auto filt : filters()) {
|
||||
for (auto &filt : filters()) {
|
||||
qCInfo(LOG_LIB) << "Found filter" << filt;
|
||||
QVariantMap filter = m_jsonFilters[filt].toMap();
|
||||
if (filter.isEmpty()) {
|
||||
qCWarning(LOG_LIB) << "Could not find filter" << _value
|
||||
<< "in the json";
|
||||
qCWarning(LOG_LIB)
|
||||
<< "Could not find filter" << _value << "in the json";
|
||||
continue;
|
||||
}
|
||||
for (auto f : filter.keys())
|
||||
for (auto &f : filter.keys())
|
||||
_value.replace(f, filter[f].toString());
|
||||
}
|
||||
|
||||
@ -198,7 +215,7 @@ QString ExtScript::applyFilters(QString _value) const
|
||||
}
|
||||
|
||||
|
||||
void ExtScript::updateFilter(const QString _filter, const bool _add)
|
||||
void ExtScript::updateFilter(const QString &_filter, const bool _add)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Should be added filters" << _add << "from" << _filter;
|
||||
|
||||
@ -218,28 +235,23 @@ void ExtScript::readConfiguration()
|
||||
|
||||
QSettings settings(fileName(), QSettings::IniFormat);
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
setExecutable(settings.value(QString("Exec"), executable()).toString());
|
||||
setPrefix(settings.value(QString("X-AW-Prefix"), prefix()).toString());
|
||||
setStrRedirect(
|
||||
settings.value(QString("X-AW-Redirect"), strRedirect()).toString());
|
||||
settings.beginGroup("Desktop Entry");
|
||||
setExecutable(settings.value("Exec", executable()).toString());
|
||||
setPrefix(settings.value("X-AW-Prefix", prefix()).toString());
|
||||
setStrRedirect(settings.value("X-AW-Redirect", strRedirect()).toString());
|
||||
// api == 3
|
||||
setFilters(settings.value(QString("X-AW-Filters"), filters())
|
||||
setFilters(settings.value("X-AW-Filters", filters())
|
||||
.toString()
|
||||
.split(QChar(','), QString::SkipEmptyParts));
|
||||
.split(',', QString::SkipEmptyParts));
|
||||
settings.endGroup();
|
||||
|
||||
bumpApi(AWESAPI);
|
||||
bumpApi(AW_EXTSCRIPT_API);
|
||||
}
|
||||
|
||||
|
||||
void ExtScript::readJsonFilters()
|
||||
{
|
||||
QString fileName = QStandardPaths::locate(
|
||||
QStandardPaths::GenericDataLocation,
|
||||
QString(
|
||||
"awesomewidgets/scripts/awesomewidgets-extscripts-filters.json"));
|
||||
qCInfo(LOG_LIB) << "Filters file" << fileName;
|
||||
QString fileName = jsonFiltersFile();
|
||||
QFile jsonFile(fileName);
|
||||
if (!jsonFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
qCWarning(LOG_LIB) << "Could not open" << fileName;
|
||||
@ -262,33 +274,17 @@ void ExtScript::readJsonFilters()
|
||||
|
||||
QVariantHash ExtScript::run()
|
||||
{
|
||||
if (!isActive())
|
||||
return m_values;
|
||||
if (m_process->state() != QProcess::NotRunning)
|
||||
qCWarning(LOG_LIB) << "Another process is already running"
|
||||
<< m_process->state();
|
||||
|
||||
if ((m_times == 1) && (m_process->state() == QProcess::NotRunning)) {
|
||||
QStringList cmdList;
|
||||
if (!prefix().isEmpty())
|
||||
cmdList.append(prefix());
|
||||
cmdList.append(executable());
|
||||
qCInfo(LOG_LIB) << "Run cmd" << cmdList.join(QChar(' '));
|
||||
m_process->start(cmdList.join(QChar(' ')));
|
||||
}
|
||||
|
||||
// update value
|
||||
if (m_times >= interval())
|
||||
m_times = 0;
|
||||
m_times++;
|
||||
return m_values;
|
||||
startTimer();
|
||||
|
||||
return m_values;
|
||||
}
|
||||
|
||||
|
||||
int ExtScript::showConfiguration(const QVariant args)
|
||||
int ExtScript::showConfiguration(const QVariant &_args)
|
||||
{
|
||||
Q_UNUSED(args)
|
||||
Q_UNUSED(_args)
|
||||
|
||||
ui->lineEdit_name->setText(name());
|
||||
ui->lineEdit_comment->setText(comment());
|
||||
@ -298,14 +294,16 @@ int ExtScript::showConfiguration(const QVariant args)
|
||||
ui->checkBox_active->setCheckState(isActive() ? Qt::Checked
|
||||
: Qt::Unchecked);
|
||||
ui->comboBox_redirect->setCurrentIndex(static_cast<int>(redirect()));
|
||||
ui->lineEdit_schedule->setText(cron());
|
||||
ui->lineEdit_socket->setText(socket());
|
||||
ui->spinBox_interval->setValue(interval());
|
||||
// filters
|
||||
ui->checkBox_colorFilter->setCheckState(
|
||||
filters().contains(QString("color")) ? Qt::Checked : Qt::Unchecked);
|
||||
filters().contains("color") ? Qt::Checked : Qt::Unchecked);
|
||||
ui->checkBox_linesFilter->setCheckState(
|
||||
filters().contains(QString("newline")) ? Qt::Checked : Qt::Unchecked);
|
||||
filters().contains("newline") ? Qt::Checked : Qt::Unchecked);
|
||||
ui->checkBox_spaceFilter->setCheckState(
|
||||
filters().contains(QString("space")) ? Qt::Checked : Qt::Unchecked);
|
||||
filters().contains("space") ? Qt::Checked : Qt::Unchecked);
|
||||
|
||||
int ret = exec();
|
||||
if (ret != 1)
|
||||
@ -313,18 +311,20 @@ int ExtScript::showConfiguration(const QVariant args)
|
||||
setName(ui->lineEdit_name->text());
|
||||
setComment(ui->lineEdit_comment->text());
|
||||
setNumber(ui->label_numberValue->text().toInt());
|
||||
setApiVersion(AWESAPI);
|
||||
setApiVersion(AW_EXTSCRIPT_API);
|
||||
setExecutable(ui->lineEdit_command->text());
|
||||
setPrefix(ui->lineEdit_prefix->text());
|
||||
setActive(ui->checkBox_active->checkState() == Qt::Checked);
|
||||
setRedirect(static_cast<Redirect>(ui->comboBox_redirect->currentIndex()));
|
||||
setCron(ui->lineEdit_schedule->text());
|
||||
setSocket(ui->lineEdit_socket->text());
|
||||
setInterval(ui->spinBox_interval->value());
|
||||
// filters
|
||||
updateFilter(QString("color"),
|
||||
updateFilter("color",
|
||||
ui->checkBox_colorFilter->checkState() == Qt::Checked);
|
||||
updateFilter(QString("newline"),
|
||||
updateFilter("newline",
|
||||
ui->checkBox_linesFilter->checkState() == Qt::Checked);
|
||||
updateFilter(QString("space"),
|
||||
updateFilter("space",
|
||||
ui->checkBox_spaceFilter->checkState() == Qt::Checked);
|
||||
|
||||
writeConfiguration();
|
||||
@ -339,17 +339,28 @@ void ExtScript::writeConfiguration() const
|
||||
QSettings settings(writtableConfig(), QSettings::IniFormat);
|
||||
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
settings.setValue(QString("Exec"), executable());
|
||||
settings.setValue(QString("X-AW-Prefix"), prefix());
|
||||
settings.setValue(QString("X-AW-Redirect"), strRedirect());
|
||||
settings.setValue(QString("X-AW-Filters"), filters().join(QChar(',')));
|
||||
settings.beginGroup("Desktop Entry");
|
||||
settings.setValue("Exec", executable());
|
||||
settings.setValue("X-AW-Prefix", prefix());
|
||||
settings.setValue("X-AW-Redirect", strRedirect());
|
||||
settings.setValue("X-AW-Filters", filters().join(','));
|
||||
settings.endGroup();
|
||||
|
||||
settings.sync();
|
||||
}
|
||||
|
||||
|
||||
void ExtScript::startProcess()
|
||||
{
|
||||
QStringList cmdList;
|
||||
if (!prefix().isEmpty())
|
||||
cmdList.append(prefix());
|
||||
cmdList.append(executable());
|
||||
qCInfo(LOG_LIB) << "Run cmd" << cmdList.join(' ');
|
||||
m_process->start(cmdList.join(' '));
|
||||
}
|
||||
|
||||
|
||||
void ExtScript::updateValue()
|
||||
{
|
||||
qCInfo(LOG_LIB) << "Cmd returns" << m_process->exitCode();
|
||||
@ -378,7 +389,7 @@ void ExtScript::updateValue()
|
||||
}
|
||||
|
||||
// filters
|
||||
m_values[tag(QString("custom"))] = applyFilters(strValue);
|
||||
m_values[tag("custom")] = applyFilters(strValue);
|
||||
emit(dataReceived(m_values));
|
||||
}
|
||||
|
||||
@ -392,6 +403,8 @@ void ExtScript::translate()
|
||||
ui->label_prefix->setText(i18n("Prefix"));
|
||||
ui->checkBox_active->setText(i18n("Active"));
|
||||
ui->label_redirect->setText(i18n("Redirect"));
|
||||
ui->label_schedule->setText(i18n("Schedule"));
|
||||
ui->label_socket->setText(i18n("Socket"));
|
||||
ui->label_interval->setText(i18n("Interval"));
|
||||
ui->groupBox_filters->setTitle(i18n("Additional filters"));
|
||||
ui->checkBox_colorFilter->setText(i18n("Wrap colors"));
|
||||
|
@ -44,9 +44,11 @@ public:
|
||||
swap = 3
|
||||
};
|
||||
|
||||
explicit ExtScript(QWidget *parent, const QString filePath = QString());
|
||||
explicit ExtScript(QWidget *_parent = nullptr,
|
||||
const QString &_filePath = "");
|
||||
virtual ~ExtScript();
|
||||
ExtScript *copy(const QString _fileName, const int _number);
|
||||
ExtScript *copy(const QString &_fileName, const int _number);
|
||||
QString jsonFiltersFile() const;
|
||||
// get methods
|
||||
QString executable() const;
|
||||
QStringList filters() const;
|
||||
@ -56,23 +58,24 @@ public:
|
||||
// derivatives
|
||||
QString strRedirect() const;
|
||||
// set methods
|
||||
void setExecutable(const QString _executable = QString("/usr/bin/true"));
|
||||
void setFilters(const QStringList _filters = QStringList());
|
||||
void setPrefix(const QString _prefix = QString(""));
|
||||
void setRedirect(const Redirect _redirect = Redirect::nothing);
|
||||
void setStrRedirect(const QString _redirect = QString("nothing"));
|
||||
void setExecutable(const QString &_executable);
|
||||
void setFilters(const QStringList &_filters);
|
||||
void setPrefix(const QString &_prefix);
|
||||
void setRedirect(const Redirect _redirect);
|
||||
void setStrRedirect(const QString &_redirect);
|
||||
// filters
|
||||
QString applyFilters(QString _value) const;
|
||||
void updateFilter(const QString _filter, const bool _add = true);
|
||||
void updateFilter(const QString &_filter, const bool _add);
|
||||
|
||||
public slots:
|
||||
void readConfiguration();
|
||||
void readJsonFilters();
|
||||
QVariantHash run();
|
||||
int showConfiguration(const QVariant args = QVariant());
|
||||
int showConfiguration(const QVariant &_args);
|
||||
void writeConfiguration() const;
|
||||
|
||||
private slots:
|
||||
void startProcess();
|
||||
void updateValue();
|
||||
|
||||
private:
|
||||
@ -80,13 +83,12 @@ private:
|
||||
Ui::ExtScript *ui = nullptr;
|
||||
void translate();
|
||||
// properties
|
||||
QString m_executable = QString("/usr/bin/true");
|
||||
QString m_executable = "/usr/bin/true";
|
||||
QStringList m_filters = QStringList();
|
||||
QString m_prefix = QString("");
|
||||
QString m_prefix = "";
|
||||
Redirect m_redirect = Redirect::nothing;
|
||||
// internal properties
|
||||
QVariantMap m_jsonFilters = QVariantMap();
|
||||
int m_times = 0;
|
||||
QVariantMap m_jsonFilters;
|
||||
QVariantHash m_values;
|
||||
};
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>420</width>
|
||||
<height>424</height>
|
||||
<height>506</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -196,28 +196,89 @@
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_interval">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_interval">
|
||||
<property name="text">
|
||||
<string>Interval</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="spinBox_interval">
|
||||
<property name="minimum">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>10000</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
<widget class="QGroupBox" name="groupBox_update">
|
||||
<property name="title">
|
||||
<string>Update</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_interval">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_interval">
|
||||
<property name="text">
|
||||
<string>Interval</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="spinBox_interval">
|
||||
<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>3600</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_schedule">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_schedule">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Schedule</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_schedule"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_socket">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_socket">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Socket</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_socket"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_filters">
|
||||
|
@ -28,22 +28,24 @@
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
ExtUpgrade::ExtUpgrade(QWidget *parent, const QString filePath)
|
||||
: AbstractExtItem(parent, filePath)
|
||||
ExtUpgrade::ExtUpgrade(QWidget *_parent, const QString &_filePath)
|
||||
: AbstractExtItem(_parent, _filePath)
|
||||
, ui(new Ui::ExtUpgrade)
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
if (!filePath.isEmpty())
|
||||
if (!_filePath.isEmpty())
|
||||
readConfiguration();
|
||||
ui->setupUi(this);
|
||||
translate();
|
||||
|
||||
m_values[tag(QString("pkgcount"))] = 0;
|
||||
m_values[tag("pkgcount")] = 0;
|
||||
|
||||
m_process = new QProcess(nullptr);
|
||||
connect(m_process, SIGNAL(finished(int)), this, SLOT(updateValue()));
|
||||
m_process->waitForFinished(0);
|
||||
|
||||
connect(this, SIGNAL(requestDataUpdate()), this, SLOT(startProcess()));
|
||||
}
|
||||
|
||||
|
||||
@ -53,11 +55,12 @@ ExtUpgrade::~ExtUpgrade()
|
||||
|
||||
m_process->kill();
|
||||
m_process->deleteLater();
|
||||
disconnect(this, SIGNAL(requestDataUpdate()), this, SLOT(startProcess()));
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
||||
ExtUpgrade *ExtUpgrade::copy(const QString _fileName, const int _number)
|
||||
ExtUpgrade *ExtUpgrade::copy(const QString &_fileName, const int _number)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
||||
|
||||
@ -97,7 +100,7 @@ QString ExtUpgrade::uniq() const
|
||||
}
|
||||
|
||||
|
||||
void ExtUpgrade::setExecutable(const QString _executable)
|
||||
void ExtUpgrade::setExecutable(const QString &_executable)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Executable" << _executable;
|
||||
|
||||
@ -105,7 +108,7 @@ void ExtUpgrade::setExecutable(const QString _executable)
|
||||
}
|
||||
|
||||
|
||||
void ExtUpgrade::setFilter(const QString _filter)
|
||||
void ExtUpgrade::setFilter(const QString &_filter)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Filter" << _filter;
|
||||
|
||||
@ -129,40 +132,30 @@ void ExtUpgrade::readConfiguration()
|
||||
|
||||
QSettings settings(fileName(), QSettings::IniFormat);
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
setExecutable(settings.value(QString("Exec"), executable()).toString());
|
||||
setNull(settings.value(QString("X-AW-Null"), null()).toInt());
|
||||
settings.beginGroup("Desktop Entry");
|
||||
setExecutable(settings.value("Exec", executable()).toString());
|
||||
setNull(settings.value("X-AW-Null", null()).toInt());
|
||||
// api == 3
|
||||
setFilter(settings.value(QString("X-AW-Filter"), filter()).toString());
|
||||
setFilter(settings.value("X-AW-Filter", filter()).toString());
|
||||
settings.endGroup();
|
||||
|
||||
bumpApi(AWEUAPI);
|
||||
bumpApi(AW_EXTUPGRADE_API);
|
||||
}
|
||||
|
||||
|
||||
QVariantHash ExtUpgrade::run()
|
||||
{
|
||||
if (!isActive())
|
||||
if (m_process->state() != QProcess::NotRunning)
|
||||
return m_values;
|
||||
|
||||
if ((m_times == 1) && (m_process->state() == QProcess::NotRunning)) {
|
||||
QString cmd = QString("sh -c \"%1\"").arg(executable());
|
||||
qCInfo(LOG_LIB) << "Run cmd" << cmd;
|
||||
m_process->start(cmd);
|
||||
}
|
||||
|
||||
// update value
|
||||
if (m_times >= interval())
|
||||
m_times = 0;
|
||||
m_times++;
|
||||
startTimer();
|
||||
|
||||
return m_values;
|
||||
}
|
||||
|
||||
|
||||
int ExtUpgrade::showConfiguration(const QVariant args)
|
||||
int ExtUpgrade::showConfiguration(const QVariant &_args)
|
||||
{
|
||||
Q_UNUSED(args)
|
||||
Q_UNUSED(_args)
|
||||
|
||||
ui->lineEdit_name->setText(name());
|
||||
ui->lineEdit_comment->setText(comment());
|
||||
@ -172,6 +165,8 @@ int ExtUpgrade::showConfiguration(const QVariant args)
|
||||
ui->checkBox_active->setCheckState(isActive() ? Qt::Checked
|
||||
: Qt::Unchecked);
|
||||
ui->spinBox_null->setValue(null());
|
||||
ui->lineEdit_schedule->setText(cron());
|
||||
ui->lineEdit_socket->setText(socket());
|
||||
ui->spinBox_interval->setValue(interval());
|
||||
|
||||
int ret = exec();
|
||||
@ -180,11 +175,13 @@ int ExtUpgrade::showConfiguration(const QVariant args)
|
||||
setName(ui->lineEdit_name->text());
|
||||
setComment(ui->lineEdit_comment->text());
|
||||
setNumber(ui->label_numberValue->text().toInt());
|
||||
setApiVersion(AWEUAPI);
|
||||
setApiVersion(AW_EXTUPGRADE_API);
|
||||
setExecutable(ui->lineEdit_command->text());
|
||||
setFilter(ui->lineEdit_filter->text());
|
||||
setActive(ui->checkBox_active->checkState() == Qt::Checked);
|
||||
setNull(ui->spinBox_null->value());
|
||||
setCron(ui->lineEdit_schedule->text());
|
||||
setSocket(ui->lineEdit_socket->text());
|
||||
setInterval(ui->spinBox_interval->value());
|
||||
|
||||
writeConfiguration();
|
||||
@ -199,16 +196,24 @@ void ExtUpgrade::writeConfiguration() const
|
||||
QSettings settings(writtableConfig(), QSettings::IniFormat);
|
||||
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
settings.setValue(QString("Exec"), executable());
|
||||
settings.setValue(QString("X-AW-Filter"), filter());
|
||||
settings.setValue(QString("X-AW-Null"), null());
|
||||
settings.beginGroup("Desktop Entry");
|
||||
settings.setValue("Exec", executable());
|
||||
settings.setValue("X-AW-Filter", filter());
|
||||
settings.setValue("X-AW-Null", null());
|
||||
settings.endGroup();
|
||||
|
||||
settings.sync();
|
||||
}
|
||||
|
||||
|
||||
void ExtUpgrade::startProcess()
|
||||
{
|
||||
QString cmd = QString("sh -c \"%1\"").arg(executable());
|
||||
qCInfo(LOG_LIB) << "Run cmd" << cmd;
|
||||
m_process->start(cmd);
|
||||
}
|
||||
|
||||
|
||||
void ExtUpgrade::updateValue()
|
||||
{
|
||||
qCInfo(LOG_LIB) << "Cmd returns" << m_process->exitCode();
|
||||
@ -217,11 +222,11 @@ void ExtUpgrade::updateValue()
|
||||
QString qoutput = QTextCodec::codecForMib(106)
|
||||
->toUnicode(m_process->readAllStandardOutput())
|
||||
.trimmed();
|
||||
m_values[tag(QString("pkgcount"))] = [this](QString output) {
|
||||
m_values[tag("pkgcount")] = [this](QString output) {
|
||||
return filter().isEmpty()
|
||||
? output.split(QChar('\n'), QString::SkipEmptyParts).count()
|
||||
? output.split('\n', QString::SkipEmptyParts).count()
|
||||
- null()
|
||||
: output.split(QChar('\n'), QString::SkipEmptyParts)
|
||||
: output.split('\n', QString::SkipEmptyParts)
|
||||
.filter(QRegExp(filter()))
|
||||
.count();
|
||||
}(qoutput);
|
||||
@ -239,5 +244,7 @@ void ExtUpgrade::translate()
|
||||
ui->label_filter->setText(i18n("Filter"));
|
||||
ui->checkBox_active->setText(i18n("Active"));
|
||||
ui->label_null->setText(i18n("Null"));
|
||||
ui->label_socket->setText(i18n("Socket"));
|
||||
ui->label_schedule->setText(i18n("Schedule"));
|
||||
ui->label_interval->setText(i18n("Interval"));
|
||||
}
|
||||
|
@ -36,26 +36,28 @@ class ExtUpgrade : public AbstractExtItem
|
||||
Q_PROPERTY(int null READ null WRITE setNull)
|
||||
|
||||
public:
|
||||
explicit ExtUpgrade(QWidget *parent, const QString filePath = QString());
|
||||
explicit ExtUpgrade(QWidget *_parent = nullptr,
|
||||
const QString &_filePath = "");
|
||||
virtual ~ExtUpgrade();
|
||||
ExtUpgrade *copy(const QString _fileName, const int _number);
|
||||
ExtUpgrade *copy(const QString &_fileName, const int _number);
|
||||
// get methods
|
||||
QString executable() const;
|
||||
QString filter() const;
|
||||
int null() const;
|
||||
QString uniq() const;
|
||||
// set methods
|
||||
void setExecutable(const QString _executable = QString("/usr/bin/true"));
|
||||
void setFilter(const QString _filter = QString());
|
||||
void setNull(const int _null = 0);
|
||||
void setExecutable(const QString &_executable);
|
||||
void setFilter(const QString &_filter);
|
||||
void setNull(const int _null);
|
||||
|
||||
public slots:
|
||||
void readConfiguration();
|
||||
QVariantHash run();
|
||||
int showConfiguration(const QVariant args = QVariant());
|
||||
int showConfiguration(const QVariant &_args);
|
||||
void writeConfiguration() const;
|
||||
|
||||
private slots:
|
||||
void startProcess();
|
||||
void updateValue();
|
||||
|
||||
private:
|
||||
@ -63,11 +65,10 @@ private:
|
||||
Ui::ExtUpgrade *ui = nullptr;
|
||||
void translate();
|
||||
// properties
|
||||
QString m_executable = QString("/usr/bin/true");
|
||||
QString m_filter = QString("");
|
||||
QString m_executable = "/usr/bin/true";
|
||||
QString m_filter = "";
|
||||
int m_null = 0;
|
||||
// internal properties
|
||||
int m_times = 0;
|
||||
QVariantHash m_values;
|
||||
};
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>420</width>
|
||||
<height>301</height>
|
||||
<height>382</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -182,34 +182,89 @@
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_interval">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_interval">
|
||||
<property name="text">
|
||||
<string>Interval</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="spinBox_interval">
|
||||
<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>3600</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
<widget class="QGroupBox" name="groupBox_update">
|
||||
<property name="title">
|
||||
<string>Update</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_interval">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_interval">
|
||||
<property name="text">
|
||||
<string>Interval</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="spinBox_interval">
|
||||
<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>3600</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_schedule">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_schedule">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Schedule</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_schedule"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_socket">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_socket">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Socket</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_socket"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
|
@ -35,29 +35,31 @@
|
||||
#include "yahooweatherprovider.h"
|
||||
|
||||
|
||||
ExtWeather::ExtWeather(QWidget *parent, const QString filePath)
|
||||
: AbstractExtItem(parent, filePath)
|
||||
ExtWeather::ExtWeather(QWidget *_parent, const QString &_filePath)
|
||||
: AbstractExtItem(_parent, _filePath)
|
||||
, ui(new Ui::ExtWeather)
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
if (!filePath.isEmpty())
|
||||
if (!_filePath.isEmpty())
|
||||
readConfiguration();
|
||||
readJsonMap();
|
||||
ui->setupUi(this);
|
||||
translate();
|
||||
|
||||
m_values[tag(QString("weatherId"))] = 0;
|
||||
m_values[tag(QString("weather"))] = QString("");
|
||||
m_values[tag(QString("humidity"))] = 0;
|
||||
m_values[tag(QString("pressure"))] = 0.0;
|
||||
m_values[tag(QString("temperature"))] = 0.0;
|
||||
m_values[tag("weatherId")] = 0;
|
||||
m_values[tag("weather")] = "";
|
||||
m_values[tag("humidity")] = 0;
|
||||
m_values[tag("pressure")] = 0.0;
|
||||
m_values[tag("temperature")] = 0.0;
|
||||
|
||||
// HACK declare as child of nullptr to avoid crash with plasmawindowed
|
||||
// in the destructor
|
||||
m_manager = new QNetworkAccessManager(nullptr);
|
||||
connect(m_manager, SIGNAL(finished(QNetworkReply *)), this,
|
||||
SLOT(weatherReplyReceived(QNetworkReply *)));
|
||||
|
||||
connect(this, SIGNAL(requestDataUpdate()), this, SLOT(sendRequest()));
|
||||
}
|
||||
|
||||
|
||||
@ -67,6 +69,7 @@ ExtWeather::~ExtWeather()
|
||||
|
||||
disconnect(m_manager, SIGNAL(finished(QNetworkReply *)), this,
|
||||
SLOT(weatherReplyReceived(QNetworkReply *)));
|
||||
disconnect(this, SIGNAL(requestDataUpdate()), this, SLOT(sendRequest()));
|
||||
|
||||
m_manager->deleteLater();
|
||||
delete m_providerObject;
|
||||
@ -74,7 +77,7 @@ ExtWeather::~ExtWeather()
|
||||
}
|
||||
|
||||
|
||||
ExtWeather *ExtWeather::copy(const QString _fileName, const int _number)
|
||||
ExtWeather *ExtWeather::copy(const QString &_fileName, const int _number)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "File" << _fileName << "number" << _number;
|
||||
|
||||
@ -92,13 +95,23 @@ ExtWeather *ExtWeather::copy(const QString _fileName, const int _number)
|
||||
}
|
||||
|
||||
|
||||
QString ExtWeather::jsonMapFile() const
|
||||
{
|
||||
QString fileName = QStandardPaths::locate(
|
||||
QStandardPaths::GenericDataLocation,
|
||||
"awesomewidgets/weather/awesomewidgets-extweather-ids.json");
|
||||
qCInfo(LOG_LIB) << "Map file" << fileName;
|
||||
|
||||
return fileName;
|
||||
}
|
||||
|
||||
|
||||
QString ExtWeather::weatherFromInt(const int _id) const
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Weather ID" << _id;
|
||||
|
||||
QVariantMap map
|
||||
= m_jsonMap[m_image ? QString("image") : QString("text")].toMap();
|
||||
return map.value(QString::number(_id), map[QString("default")]).toString();
|
||||
QVariantMap map = m_jsonMap[m_image ? "image" : "text"].toMap();
|
||||
return map.value(QString::number(_id), map["default"]).toString();
|
||||
}
|
||||
|
||||
|
||||
@ -131,10 +144,10 @@ QString ExtWeather::strProvider() const
|
||||
QString value;
|
||||
switch (m_provider) {
|
||||
case Provider::OWM:
|
||||
value = QString("OWM");
|
||||
value = "OWM";
|
||||
break;
|
||||
case Provider::Yahoo:
|
||||
value = QString("Yahoo");
|
||||
value = "Yahoo";
|
||||
break;
|
||||
}
|
||||
|
||||
@ -154,7 +167,7 @@ QString ExtWeather::uniq() const
|
||||
}
|
||||
|
||||
|
||||
void ExtWeather::setCity(const QString _city)
|
||||
void ExtWeather::setCity(const QString &_city)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "City" << _city;
|
||||
|
||||
@ -163,7 +176,7 @@ void ExtWeather::setCity(const QString _city)
|
||||
}
|
||||
|
||||
|
||||
void ExtWeather::setCountry(const QString _country)
|
||||
void ExtWeather::setCountry(const QString &_country)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Country" << _country;
|
||||
|
||||
@ -189,11 +202,11 @@ void ExtWeather::setProvider(const Provider _provider)
|
||||
}
|
||||
|
||||
|
||||
void ExtWeather::setStrProvider(const QString _provider)
|
||||
void ExtWeather::setStrProvider(const QString &_provider)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Provider" << _provider;
|
||||
|
||||
if (_provider == QString("Yahoo"))
|
||||
if (_provider == "Yahoo")
|
||||
setProvider(Provider::Yahoo);
|
||||
else
|
||||
setProvider(Provider::OWM);
|
||||
@ -215,28 +228,23 @@ void ExtWeather::readConfiguration()
|
||||
|
||||
QSettings settings(fileName(), QSettings::IniFormat);
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
setCity(settings.value(QString("X-AW-City"), city()).toString());
|
||||
setCountry(settings.value(QString("X-AW-Country"), country()).toString());
|
||||
setTs(settings.value(QString("X-AW-TS"), ts()).toInt());
|
||||
settings.beginGroup("Desktop Entry");
|
||||
setCity(settings.value("X-AW-City", city()).toString());
|
||||
setCountry(settings.value("X-AW-Country", country()).toString());
|
||||
setTs(settings.value("X-AW-TS", ts()).toInt());
|
||||
// api == 2
|
||||
setImage(settings.value(QString("X-AW-Image"), QVariant(image())).toString()
|
||||
== QString("true"));
|
||||
setImage(settings.value("X-AW-Image", image()).toBool());
|
||||
// api == 3
|
||||
setStrProvider(
|
||||
settings.value(QString("X-AW-Provider"), strProvider()).toString());
|
||||
setStrProvider(settings.value("X-AW-Provider", strProvider()).toString());
|
||||
settings.endGroup();
|
||||
|
||||
bumpApi(AWEWAPI);
|
||||
bumpApi(AW_EXTWEATHER_API);
|
||||
}
|
||||
|
||||
|
||||
void ExtWeather::readJsonMap()
|
||||
{
|
||||
QString fileName = QStandardPaths::locate(
|
||||
QStandardPaths::GenericDataLocation,
|
||||
QString("awesomewidgets/weather/awesomewidgets-extweather-ids.json"));
|
||||
qCInfo(LOG_LIB) << "Map file" << fileName;
|
||||
QString fileName = jsonMapFile();
|
||||
QFile jsonFile(fileName);
|
||||
if (!jsonFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
qCWarning(LOG_LIB) << "Could not open" << fileName;
|
||||
@ -259,29 +267,17 @@ void ExtWeather::readJsonMap()
|
||||
|
||||
QVariantHash ExtWeather::run()
|
||||
{
|
||||
if ((!isActive()) || (m_isRunning))
|
||||
if (m_isRunning)
|
||||
return m_values;
|
||||
|
||||
if (m_times == 1) {
|
||||
qCInfo(LOG_LIB) << "Send request";
|
||||
m_isRunning = true;
|
||||
QNetworkReply *reply
|
||||
= m_manager->get(QNetworkRequest(m_providerObject->url()));
|
||||
new QReplyTimeout(reply, REQUEST_TIMEOUT);
|
||||
}
|
||||
|
||||
// update value
|
||||
if (m_times >= interval())
|
||||
m_times = 0;
|
||||
m_times++;
|
||||
startTimer();
|
||||
|
||||
return m_values;
|
||||
}
|
||||
|
||||
|
||||
int ExtWeather::showConfiguration(const QVariant args)
|
||||
int ExtWeather::showConfiguration(const QVariant &_args)
|
||||
{
|
||||
Q_UNUSED(args)
|
||||
Q_UNUSED(_args)
|
||||
|
||||
ui->lineEdit_name->setText(name());
|
||||
ui->lineEdit_comment->setText(comment());
|
||||
@ -293,6 +289,8 @@ int ExtWeather::showConfiguration(const QVariant args)
|
||||
ui->checkBox_image->setCheckState(image() ? Qt::Checked : Qt::Unchecked);
|
||||
ui->checkBox_active->setCheckState(isActive() ? Qt::Checked
|
||||
: Qt::Unchecked);
|
||||
ui->lineEdit_schedule->setText(cron());
|
||||
ui->lineEdit_socket->setText(socket());
|
||||
ui->spinBox_interval->setValue(interval());
|
||||
|
||||
int ret = exec();
|
||||
@ -301,13 +299,15 @@ int ExtWeather::showConfiguration(const QVariant args)
|
||||
setName(ui->lineEdit_name->text());
|
||||
setComment(ui->lineEdit_comment->text());
|
||||
setNumber(ui->label_numberValue->text().toInt());
|
||||
setApiVersion(AWEWAPI);
|
||||
setApiVersion(AW_EXTWEATHER_API);
|
||||
setCity(ui->lineEdit_city->text());
|
||||
setCountry(ui->lineEdit_country->text());
|
||||
setProvider(static_cast<Provider>(ui->comboBox_provider->currentIndex()));
|
||||
setTs(ui->spinBox_timestamp->value());
|
||||
setImage(ui->checkBox_image->checkState() == Qt::Checked);
|
||||
setActive(ui->checkBox_active->checkState() == Qt::Checked);
|
||||
setCron(ui->lineEdit_schedule->text());
|
||||
setSocket(ui->lineEdit_socket->text());
|
||||
setInterval(ui->spinBox_interval->value());
|
||||
|
||||
writeConfiguration();
|
||||
@ -322,29 +322,40 @@ void ExtWeather::writeConfiguration() const
|
||||
QSettings settings(writtableConfig(), QSettings::IniFormat);
|
||||
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
settings.setValue(QString("X-AW-City"), city());
|
||||
settings.setValue(QString("X-AW-Country"), country());
|
||||
settings.setValue(QString("X-AW-Image"), image());
|
||||
settings.setValue(QString("X-AW-Provider"), strProvider());
|
||||
settings.setValue(QString("X-AW-TS"), ts());
|
||||
settings.beginGroup("Desktop Entry");
|
||||
settings.setValue("X-AW-City", city());
|
||||
settings.setValue("X-AW-Country", country());
|
||||
settings.setValue("X-AW-Image", image());
|
||||
settings.setValue("X-AW-Provider", strProvider());
|
||||
settings.setValue("X-AW-TS", ts());
|
||||
settings.endGroup();
|
||||
|
||||
settings.sync();
|
||||
}
|
||||
|
||||
|
||||
void ExtWeather::weatherReplyReceived(QNetworkReply *reply)
|
||||
void ExtWeather::sendRequest()
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Return code" << reply->error() << "with message"
|
||||
<< reply->errorString();
|
||||
m_isRunning = true;
|
||||
QNetworkReply *reply
|
||||
= m_manager->get(QNetworkRequest(m_providerObject->url()));
|
||||
new QReplyTimeout(reply, REQUEST_TIMEOUT);
|
||||
}
|
||||
|
||||
|
||||
void ExtWeather::weatherReplyReceived(QNetworkReply *_reply)
|
||||
{
|
||||
if (_reply->error() != QNetworkReply::NoError) {
|
||||
qCWarning(LOG_AW) << "An error occurs" << _reply->error()
|
||||
<< "with message" << _reply->errorString();
|
||||
return;
|
||||
}
|
||||
|
||||
m_isRunning = false;
|
||||
QJsonParseError error;
|
||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(reply->readAll(), &error);
|
||||
reply->deleteLater();
|
||||
if ((reply->error() != QNetworkReply::NoError)
|
||||
|| (error.error != QJsonParseError::NoError)) {
|
||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(_reply->readAll(), &error);
|
||||
_reply->deleteLater();
|
||||
if (error.error != QJsonParseError::NoError) {
|
||||
qCWarning(LOG_LIB) << "Parse error" << error.errorString();
|
||||
return;
|
||||
}
|
||||
@ -353,8 +364,8 @@ void ExtWeather::weatherReplyReceived(QNetworkReply *reply)
|
||||
if (data.isEmpty())
|
||||
return;
|
||||
m_values = data;
|
||||
m_values[tag(QString("weather"))]
|
||||
= weatherFromInt(m_values[tag(QString("weatherId"))].toInt());
|
||||
m_values[tag("weather")]
|
||||
= weatherFromInt(m_values[tag("weatherId")].toInt());
|
||||
|
||||
emit(dataReceived(m_values));
|
||||
}
|
||||
@ -388,5 +399,7 @@ void ExtWeather::translate()
|
||||
ui->label_timestamp->setText(i18n("Timestamp"));
|
||||
ui->checkBox_image->setText(i18n("Use images"));
|
||||
ui->checkBox_active->setText(i18n("Active"));
|
||||
ui->label_schedule->setText(i18n("Schedule"));
|
||||
ui->label_socket->setText(i18n("Socket"));
|
||||
ui->label_interval->setText(i18n("Interval"));
|
||||
}
|
||||
|
@ -42,9 +42,11 @@ class ExtWeather : public AbstractExtItem
|
||||
public:
|
||||
enum class Provider { OWM = 0, Yahoo = 1 };
|
||||
|
||||
explicit ExtWeather(QWidget *parent, const QString filePath = QString());
|
||||
explicit ExtWeather(QWidget *_parent = nullptr,
|
||||
const QString &_filePath = "");
|
||||
virtual ~ExtWeather();
|
||||
ExtWeather *copy(const QString _fileName, const int _number);
|
||||
ExtWeather *copy(const QString &_fileName, const int _number);
|
||||
QString jsonMapFile() const;
|
||||
QString weatherFromInt(const int _id) const;
|
||||
// get methods
|
||||
QString city() const;
|
||||
@ -55,22 +57,23 @@ public:
|
||||
int ts() const;
|
||||
QString uniq() const;
|
||||
// set methods
|
||||
void setCity(const QString _city = QString("London"));
|
||||
void setCountry(const QString _country = QString("uk"));
|
||||
void setImage(const bool _image = false);
|
||||
void setProvider(const Provider _provider = Provider::OWM);
|
||||
void setStrProvider(const QString _provider = QString("OWM"));
|
||||
void setTs(const int _ts = 0);
|
||||
void setCity(const QString &_city);
|
||||
void setCountry(const QString &_country);
|
||||
void setImage(const bool _image);
|
||||
void setProvider(const Provider _provider);
|
||||
void setStrProvider(const QString &_provider);
|
||||
void setTs(const int _ts);
|
||||
|
||||
public slots:
|
||||
void readConfiguration();
|
||||
void readJsonMap();
|
||||
QVariantHash run();
|
||||
int showConfiguration(const QVariant args = QVariant());
|
||||
int showConfiguration(const QVariant &_args);
|
||||
void writeConfiguration() const;
|
||||
|
||||
private slots:
|
||||
void weatherReplyReceived(QNetworkReply *reply);
|
||||
void sendRequest();
|
||||
void weatherReplyReceived(QNetworkReply *_reply);
|
||||
|
||||
private:
|
||||
QNetworkAccessManager *m_manager = nullptr;
|
||||
@ -80,14 +83,13 @@ private:
|
||||
void initProvider();
|
||||
void translate();
|
||||
// properties
|
||||
QString m_city = QString("London");
|
||||
QString m_country = QString("uk");
|
||||
QString m_city = "London";
|
||||
QString m_country = "uk";
|
||||
bool m_image = false;
|
||||
Provider m_provider = Provider::OWM;
|
||||
int m_ts = 0;
|
||||
QVariantMap m_jsonMap = QVariantMap();
|
||||
QVariantMap m_jsonMap;
|
||||
// values
|
||||
int m_times = 0;
|
||||
QVariantHash m_values;
|
||||
};
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>420</width>
|
||||
<height>333</height>
|
||||
<height>446</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -249,34 +249,89 @@
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_interval">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_interval">
|
||||
<property name="text">
|
||||
<string>Interval</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="spinBox_interval">
|
||||
<property name="minimum">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>10000</number>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>60</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
<widget class="QGroupBox" name="groupBox_update">
|
||||
<property name="title">
|
||||
<string>Update</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_interval">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_interval">
|
||||
<property name="text">
|
||||
<string>Interval</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="spinBox_interval">
|
||||
<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>3600</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_schedule">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_schedule">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Schedule</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_schedule"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_socket">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_socket">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Socket</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_socket"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
|
@ -3,7 +3,7 @@ Comment=Default float formatter
|
||||
Encoding=UTF-8
|
||||
Name=Float
|
||||
X-AW-Active=true
|
||||
X-AW-ApiVersion=2
|
||||
X-AW-ApiVersion=3
|
||||
X-AW-FillChar=@Variant(\0\0\0\a\0\0)
|
||||
X-AW-ForceWidth=false
|
||||
X-AW-Format=f
|
||||
|
@ -3,7 +3,7 @@ Comment=Default integer formatter
|
||||
Encoding=UTF-8
|
||||
Name=Integer
|
||||
X-AW-Active=true
|
||||
X-AW-ApiVersion=2
|
||||
X-AW-ApiVersion=3
|
||||
X-AW-FillChar=@Variant(\0\0\0\a\0\0)
|
||||
X-AW-ForceWidth=false
|
||||
X-AW-Format=f
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user