Compare commits
62 Commits
Author | SHA1 | Date | |
---|---|---|---|
53918f4528 | |||
927e93b7fc | |||
fbf89f61b4 | |||
77675a8e2f | |||
4adf457ada | |||
0d4211b2c4 | |||
085eec7a3d | |||
baf5085506 | |||
17a0c61b4a | |||
3497922928 | |||
2f88c7ae60 | |||
8e8ac2f3c7 | |||
5cd5272f10 | |||
bee8e2f180 | |||
bf16e72e1e | |||
faf259e339 | |||
f6a6704fd2 | |||
4a0da3f978 | |||
e4e8f299c0 | |||
71ae832bcd | |||
1465657648 | |||
0f1763cb81 | |||
b20a96d32f | |||
75d101cc8b | |||
5d9d551afe | |||
78b7a87c29 | |||
bc2071a493 | |||
5a0541d06d | |||
18789f78b3 | |||
ab01c9fa08 | |||
620c4bd1e3 | |||
4337379177 | |||
69c09d9ff8 | |||
cae9e0d2e3 | |||
7b154af1b3 | |||
fd3ed61191 | |||
2a257de1e6 | |||
6f09737f0f | |||
b73fb19409 | |||
c57a92b687 | |||
72f0d4587b | |||
ea7c15d865 | |||
2dccc92933 | |||
e71da9bdfb | |||
f717c984b7 | |||
906ad56c46 | |||
301a908aed | |||
6bd7788aa9 | |||
51c7299ad0 | |||
326c65528d | |||
14aab3b758 | |||
7c37134aab | |||
734cbe2f4c | |||
082efcc127 | |||
24d45c6d48 | |||
7eb82c8c8d | |||
48e98239d9 | |||
2514dcc74d | |||
4a499a6157 | |||
6916c8f992 | |||
2c7b072829 | |||
636978b442 |
14
CHANGELOG
@ -1,3 +1,17 @@
|
|||||||
|
Ver.3.2.0:
|
||||||
|
+ custom formatters (#91)
|
||||||
|
+ add backend tests (#95)
|
||||||
|
+ add OWM weather provider for ExtWeather. It can be switched by using X-AW-Provider (ApiVer 3)
|
||||||
|
+ add DBus timeout for calls (#96)
|
||||||
|
+ add macros support (`$aw_macro` and `$aw_macro_*` for calls)
|
||||||
|
- fix vertical alignment (#94)
|
||||||
|
- fix bug with invalid updates on `X-AW-Interval=1` for ExtScript and ExtUpgrade
|
||||||
|
- fix bug with missing derivate vaules in ExtQuotes
|
||||||
|
- fix possible plasma crash (#96)
|
||||||
|
- fix possible undefined behaviour if no extensions was found by name
|
||||||
|
* split dataengine sources to own library
|
||||||
|
* allow to use screened double brakets inside functions
|
||||||
|
|
||||||
Ver.3.1.2:
|
Ver.3.1.2:
|
||||||
+ add standalone widget configuration example
|
+ add standalone widget configuration example
|
||||||
+ new tag tstime
|
+ new tag tstime
|
||||||
|
@ -54,7 +54,14 @@ for more details. To avoid manual labor there is automatic cmake target named
|
|||||||
```
|
```
|
||||||
|
|
||||||
* C-like `NULL`, use `nullptr` instead.
|
* C-like `NULL`, use `nullptr` instead.
|
||||||
* It is highly recommended to avoid implicit casts.
|
* It is highly recommended to avoid implicit casts. Exception `nullptr` casts to
|
||||||
|
boolean, e.g.:
|
||||||
|
|
||||||
|
```
|
||||||
|
if (nullptr)
|
||||||
|
qDebug() << "nullptr is true, wtf";
|
||||||
|
```
|
||||||
|
|
||||||
* Abstract classes (which have at least one pure virtual method) are allowed.
|
* Abstract classes (which have at least one pure virtual method) are allowed.
|
||||||
* Templates are allowed and recommended. Templates usually should be described
|
* Templates are allowed and recommended. Templates usually should be described
|
||||||
inside header not source code file.
|
inside header not source code file.
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
pkgname=plasma5-applet-awesome-widgets
|
pkgname=plasma5-applet-awesome-widgets
|
||||||
_pkgname=awesome-widgets
|
_pkgname=awesome-widgets
|
||||||
pkgver=3.1.2
|
pkgver=3.2.0
|
||||||
pkgrel=1
|
pkgrel=1
|
||||||
pkgdesc="Collection of minimalistic Plasmoids which look like Awesome WM widgets (ex-PyTextMonitor)"
|
pkgdesc="Collection of minimalistic Plasmoids which look like Awesome WM widgets (ex-PyTextMonitor)"
|
||||||
arch=('i686' 'x86_64')
|
arch=('i686' 'x86_64')
|
||||||
@ -17,7 +17,7 @@ optdepends=("catalyst: for GPU monitor"
|
|||||||
makedepends=('cmake' 'extra-cmake-modules' 'python')
|
makedepends=('cmake' 'extra-cmake-modules' 'python')
|
||||||
source=(https://github.com/arcan1s/awesome-widgets/releases/download/V.${pkgver}/${_pkgname}-${pkgver}-src.tar.xz)
|
source=(https://github.com/arcan1s/awesome-widgets/releases/download/V.${pkgver}/${_pkgname}-${pkgver}-src.tar.xz)
|
||||||
install=${pkgname}.install
|
install=${pkgname}.install
|
||||||
md5sums=('99514bf6d1a5ca8660dd0210ee58af28')
|
md5sums=('81a85890d519bd8c5791d0d99cffc9c1')
|
||||||
backup=('etc/xdg/plasma-dataengine-extsysmon.conf')
|
backup=('etc/xdg/plasma-dataengine-extsysmon.conf')
|
||||||
|
|
||||||
prepare() {
|
prepare() {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
diff --git a/sources/awesome-widget/package/contents/ui/advanced.qml b/sources/awesome-widget/package/contents/ui/advanced.qml
|
diff --git a/sources/awesome-widget/package/contents/ui/advanced.qml b/sources/awesome-widget/package/contents/ui/advanced.qml
|
||||||
index 01bcd58..1ec7ba6 100644
|
index 01bcd58..1ec7ba6 100644
|
||||||
--- a/sources/awesome-widget/package/contents/ui/advanced.qml
|
--- a/sources/awesome-widget/package/contents/ui/advanced.qml
|
||||||
+++ b/sources/awesome-widget/package/contents/ui/advanced.qml
|
+++ b/sources/awesome-widget/package/contents/ui/advanced.qml
|
||||||
@ -168,9 +168,9 @@ index 6263b30..5f61d2a 100644
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
-bool AWConfigHelper::exportConfiguration(QObject *nativeConfig,
|
-bool AWConfigHelper::exportConfiguration(const QObject *nativeConfig,
|
||||||
- const QString fileName) const
|
- const QString fileName) const
|
||||||
+void AWConfigHelper::exportConfiguration(QObject *nativeConfig) const
|
+void AWConfigHelper::exportConfiguration(const QObject *nativeConfig) const
|
||||||
{
|
{
|
||||||
- qCDebug(LOG_AW) << "Selected filename" << fileName;
|
- qCDebug(LOG_AW) << "Selected filename" << fileName;
|
||||||
-
|
-
|
||||||
@ -302,17 +302,17 @@ index 912ac3d..dc51dfb 100644
|
|||||||
virtual ~AWConfigHelper();
|
virtual ~AWConfigHelper();
|
||||||
Q_INVOKABLE QString configurationDirectory() const;
|
Q_INVOKABLE QString configurationDirectory() const;
|
||||||
Q_INVOKABLE bool dropCache() const;
|
Q_INVOKABLE bool dropCache() const;
|
||||||
- Q_INVOKABLE bool exportConfiguration(QObject *nativeConfig,
|
- Q_INVOKABLE bool exportConfiguration(const QObject *nativeConfig,
|
||||||
- const QString fileName) const;
|
- const QString fileName) const;
|
||||||
- Q_INVOKABLE QVariantMap importConfiguration(const QString fileName,
|
- Q_INVOKABLE QVariantMap importConfiguration(const QString fileName,
|
||||||
- const bool importPlasmoid,
|
- const bool importPlasmoid,
|
||||||
- const bool importExtensions,
|
- const bool importExtensions,
|
||||||
- const bool importAdds) const;
|
- const bool importAdds) const;
|
||||||
+ Q_INVOKABLE void exportConfiguration(QObject *nativeConfig) const;
|
+ Q_INVOKABLE void exportConfiguration(const QObject *nativeConfig) const;
|
||||||
+ Q_INVOKABLE QVariantMap importConfiguration() const;
|
+ Q_INVOKABLE QVariantMap importConfiguration() const;
|
||||||
// dataengine
|
// dataengine
|
||||||
Q_INVOKABLE QVariantMap readDataEngineConfiguration() const;
|
Q_INVOKABLE QVariantMap readDataEngineConfiguration() const;
|
||||||
Q_INVOKABLE void
|
Q_INVOKABLE bool
|
||||||
@@ -51,6 +47,7 @@ private:
|
@@ -51,6 +47,7 @@ private:
|
||||||
void copySettings(QSettings &from, QSettings &to) const;
|
void copySettings(QSettings &from, QSettings &to) const;
|
||||||
void readFile(QSettings &settings, const QString key,
|
void readFile(QSettings &settings, const QString key,
|
||||||
@ -356,7 +356,7 @@ diff --git a/sources/awdebug.cpp b/sources/awdebug.cpp
|
|||||||
index eee61e1..9da8dad 100644
|
index eee61e1..9da8dad 100644
|
||||||
--- a/sources/awdebug.cpp
|
--- a/sources/awdebug.cpp
|
||||||
+++ b/sources/awdebug.cpp
|
+++ b/sources/awdebug.cpp
|
||||||
@@ -20,13 +20,10 @@
|
@@ -20,15 +20,11 @@
|
||||||
#include "awdebug.h"
|
#include "awdebug.h"
|
||||||
|
|
||||||
|
|
||||||
@ -365,11 +365,14 @@ index eee61e1..9da8dad 100644
|
|||||||
-Q_LOGGING_CATEGORY(LOG_DP, "org.kde.plasma.desktoppanel",
|
-Q_LOGGING_CATEGORY(LOG_DP, "org.kde.plasma.desktoppanel",
|
||||||
- QtMsgType::QtWarningMsg)
|
- QtMsgType::QtWarningMsg)
|
||||||
-Q_LOGGING_CATEGORY(LOG_ESM, "org.kde.plasma.extsysmon", 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",
|
-Q_LOGGING_CATEGORY(LOG_LIB, "org.kde.plasma.awesomewidgets",
|
||||||
- QtMsgType::QtWarningMsg)
|
- QtMsgType::QtWarningMsg)
|
||||||
+Q_LOGGING_CATEGORY(LOG_AW, "org.kde.plasma.awesomewidget")
|
+Q_LOGGING_CATEGORY(LOG_AW, "org.kde.plasma.awesomewidget")
|
||||||
+Q_LOGGING_CATEGORY(LOG_DP, "org.kde.plasma.desktoppanel")
|
+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.extsysmon")
|
||||||
|
+Q_LOGGING_CATEGORY(LOG_ESM, "org.kde.plasma.extsysmonsources")
|
||||||
+Q_LOGGING_CATEGORY(LOG_LIB, "org.kde.plasma.awesomewidgets")
|
+Q_LOGGING_CATEGORY(LOG_LIB, "org.kde.plasma.awesomewidgets")
|
||||||
|
|
||||||
|
|
||||||
@ -392,8 +395,8 @@ index 33192f7..46e2b1e 100644
|
|||||||
find_package(Gettext REQUIRED)
|
find_package(Gettext REQUIRED)
|
||||||
|
|
||||||
# main qt libraries
|
# main qt libraries
|
||||||
-find_package(Qt5 5.4.0 REQUIRED COMPONENTS Core DBus Network Qml Widgets)
|
-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 Widgets)
|
+find_package(Qt5 5.3.0 REQUIRED COMPONENTS Core DBus Network Qml Test Widgets)
|
||||||
add_definitions(
|
add_definitions(
|
||||||
${Qt5Core_DEFINITIONS} ${Qt5DBus_DEFINITIONS} ${Qt5Network_DEFINITIONS}
|
${Qt5Core_DEFINITIONS} ${Qt5DBus_DEFINITIONS} ${Qt5Network_DEFINITIONS}
|
||||||
${Qt5Qml_DEFINITIONS} ${Qt5Widgets_DEFINITIONS}
|
${Qt5Qml_DEFINITIONS} ${Qt5Widgets_DEFINITIONS}
|
||||||
|
@ -141,8 +141,8 @@ index 33192f7..339bb58 100644
|
|||||||
find_package(Gettext REQUIRED)
|
find_package(Gettext REQUIRED)
|
||||||
|
|
||||||
# main qt libraries
|
# main qt libraries
|
||||||
-find_package(Qt5 5.6.0 REQUIRED COMPONENTS Core DBus Network Qml Widgets)
|
-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 Widgets)
|
+find_package(Qt5 5.4.0 REQUIRED COMPONENTS Core DBus Network Qml Test Widgets)
|
||||||
add_definitions(
|
add_definitions(
|
||||||
${Qt5Core_DEFINITIONS} ${Qt5DBus_DEFINITIONS} ${Qt5Network_DEFINITIONS}
|
${Qt5Core_DEFINITIONS} ${Qt5DBus_DEFINITIONS} ${Qt5Network_DEFINITIONS}
|
||||||
${Qt5Qml_DEFINITIONS} ${Qt5Widgets_DEFINITIONS}
|
${Qt5Qml_DEFINITIONS} ${Qt5Widgets_DEFINITIONS}
|
||||||
|
@ -14,8 +14,8 @@ set(PROJECT_AUTHOR "Evgeniy Alekseev")
|
|||||||
set(PROJECT_CONTACT "esalexeev@gmail.com")
|
set(PROJECT_CONTACT "esalexeev@gmail.com")
|
||||||
set(PROJECT_LICENSE "GPL3")
|
set(PROJECT_LICENSE "GPL3")
|
||||||
set(PROJECT_VERSION_MAJOR "3")
|
set(PROJECT_VERSION_MAJOR "3")
|
||||||
set(PROJECT_VERSION_MINOR "1")
|
set(PROJECT_VERSION_MINOR "2")
|
||||||
set(PROJECT_VERSION_PATCH "2")
|
set(PROJECT_VERSION_PATCH "0")
|
||||||
set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
|
set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
|
||||||
# append git version if any
|
# append git version if any
|
||||||
set(PROJECT_COMMIT_SHA "Commit hash" CACHE INTERNAL "")
|
set(PROJECT_COMMIT_SHA "Commit hash" CACHE INTERNAL "")
|
||||||
@ -34,6 +34,7 @@ option(BUILD_DEB_PACKAGE "Build deb package" OFF)
|
|||||||
option(BUILD_RPM_PACKAGE "Build rpm package" OFF)
|
option(BUILD_RPM_PACKAGE "Build rpm package" OFF)
|
||||||
# build details
|
# build details
|
||||||
option(BUILD_FUTURE "Build with the features which will be marked as stable later" OFF)
|
option(BUILD_FUTURE "Build with the features which will be marked as stable later" OFF)
|
||||||
|
option(BUILD_LOAD "Build with additional load" OFF)
|
||||||
option(BUILD_TESTING "Build with additional test abilities" OFF)
|
option(BUILD_TESTING "Build with additional test abilities" OFF)
|
||||||
|
|
||||||
# generate changelog
|
# generate changelog
|
||||||
@ -66,6 +67,7 @@ endif ()
|
|||||||
|
|
||||||
set(PROJECT_TRDPARTY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty)
|
set(PROJECT_TRDPARTY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty)
|
||||||
set(PROJECT_LIBRARY awesomewidgets)
|
set(PROJECT_LIBRARY awesomewidgets)
|
||||||
|
set(PROJECT_MONITORSOURCES extsysmonsources)
|
||||||
include(libraries.cmake)
|
include(libraries.cmake)
|
||||||
include(clang-format.cmake)
|
include(clang-format.cmake)
|
||||||
include(cppcheck.cmake)
|
include(cppcheck.cmake)
|
||||||
@ -74,11 +76,16 @@ include(coverity.cmake)
|
|||||||
get_directory_property(CMAKE_DEFINITIONS COMPILE_DEFINITIONS)
|
get_directory_property(CMAKE_DEFINITIONS COMPILE_DEFINITIONS)
|
||||||
configure_file(${CMAKE_SOURCE_DIR}/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/version.h)
|
configure_file(${CMAKE_SOURCE_DIR}/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/version.h)
|
||||||
add_subdirectory(awesomewidgets)
|
add_subdirectory(awesomewidgets)
|
||||||
|
add_subdirectory(extsysmonsources)
|
||||||
add_subdirectory(extsysmon)
|
add_subdirectory(extsysmon)
|
||||||
if (BUILD_PLASMOIDS)
|
if (BUILD_PLASMOIDS)
|
||||||
add_subdirectory(awesome-widget)
|
add_subdirectory(awesome-widget)
|
||||||
add_subdirectory(desktop-panel)
|
add_subdirectory(desktop-panel)
|
||||||
add_subdirectory(translations)
|
add_subdirectory(translations)
|
||||||
endif ()
|
endif ()
|
||||||
|
if (BUILD_TESTING)
|
||||||
|
enable_testing()
|
||||||
|
add_subdirectory(test)
|
||||||
|
endif ()
|
||||||
|
|
||||||
include(packages-recipe.cmake)
|
include(packages-recipe.cmake)
|
||||||
|
@ -24,6 +24,8 @@ Q_LOGGING_CATEGORY(LOG_AW, "org.kde.plasma.awesomewidget",
|
|||||||
Q_LOGGING_CATEGORY(LOG_DP, "org.kde.plasma.desktoppanel",
|
Q_LOGGING_CATEGORY(LOG_DP, "org.kde.plasma.desktoppanel",
|
||||||
QtMsgType::QtWarningMsg)
|
QtMsgType::QtWarningMsg)
|
||||||
Q_LOGGING_CATEGORY(LOG_ESM, "org.kde.plasma.extsysmon", 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",
|
Q_LOGGING_CATEGORY(LOG_LIB, "org.kde.plasma.awesomewidgets",
|
||||||
QtMsgType::QtWarningMsg)
|
QtMsgType::QtWarningMsg)
|
||||||
|
|
||||||
@ -44,6 +46,8 @@ const QStringList getBuildData()
|
|||||||
metadata.append(QString(" AWESAPI: %1").arg(AWESAPI));
|
metadata.append(QString(" AWESAPI: %1").arg(AWESAPI));
|
||||||
metadata.append(QString(" AWEUAPI: %1").arg(AWEUAPI));
|
metadata.append(QString(" AWEUAPI: %1").arg(AWEUAPI));
|
||||||
metadata.append(QString(" AWEWAPI: %1").arg(AWEWAPI));
|
metadata.append(QString(" AWEWAPI: %1").arg(AWEWAPI));
|
||||||
|
metadata.append(QString(" AWEFAPI: %1").arg(AWEFAPI));
|
||||||
|
metadata.append(QString(" REQUEST_TIMEOUT: %1").arg(REQUEST_TIMEOUT));
|
||||||
metadata.append(QString(" TIME_KEYS: %1").arg(TIME_KEYS));
|
metadata.append(QString(" TIME_KEYS: %1").arg(TIME_KEYS));
|
||||||
metadata.append(QString(" STATIC_KEYS: %1").arg(STATIC_KEYS));
|
metadata.append(QString(" STATIC_KEYS: %1").arg(STATIC_KEYS));
|
||||||
// cmake properties
|
// cmake properties
|
||||||
@ -68,7 +72,6 @@ const QStringList getBuildData()
|
|||||||
.arg(CMAKE_SHARED_LINKER_FLAGS));
|
.arg(CMAKE_SHARED_LINKER_FLAGS));
|
||||||
// components
|
// components
|
||||||
metadata.append(QString("Components data:"));
|
metadata.append(QString("Components data:"));
|
||||||
metadata.append(QString(" BUILD_COVERAGE: %1").arg(BUILD_COVERAGE));
|
|
||||||
metadata.append(QString(" BUILD_PLASMOIDS: %1").arg(BUILD_PLASMOIDS));
|
metadata.append(QString(" BUILD_PLASMOIDS: %1").arg(BUILD_PLASMOIDS));
|
||||||
metadata.append(
|
metadata.append(
|
||||||
QString(" BUILD_DEB_PACKAGE: %1").arg(BUILD_DEB_PACKAGE));
|
QString(" BUILD_DEB_PACKAGE: %1").arg(BUILD_DEB_PACKAGE));
|
||||||
@ -87,6 +90,7 @@ const QStringList getBuildData()
|
|||||||
QString(" CPPCHECK_EXECUTABLE: %1").arg(CPPCHECK_EXECUTABLE));
|
QString(" CPPCHECK_EXECUTABLE: %1").arg(CPPCHECK_EXECUTABLE));
|
||||||
// additional functions
|
// additional functions
|
||||||
metadata.append(QString(" PROP_FUTURE: %1").arg(PROP_FUTURE));
|
metadata.append(QString(" PROP_FUTURE: %1").arg(PROP_FUTURE));
|
||||||
|
metadata.append(QString(" PROP_LOAD: %1").arg(PROP_LOAD));
|
||||||
metadata.append(QString(" PROP_TEST: %1").arg(PROP_TEST));
|
metadata.append(QString(" PROP_TEST: %1").arg(PROP_TEST));
|
||||||
|
|
||||||
return metadata;
|
return metadata;
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
Q_DECLARE_LOGGING_CATEGORY(LOG_AW)
|
Q_DECLARE_LOGGING_CATEGORY(LOG_AW)
|
||||||
Q_DECLARE_LOGGING_CATEGORY(LOG_DP)
|
Q_DECLARE_LOGGING_CATEGORY(LOG_DP)
|
||||||
Q_DECLARE_LOGGING_CATEGORY(LOG_ESM)
|
Q_DECLARE_LOGGING_CATEGORY(LOG_ESM)
|
||||||
|
Q_DECLARE_LOGGING_CATEGORY(LOG_ESS)
|
||||||
Q_DECLARE_LOGGING_CATEGORY(LOG_LIB)
|
Q_DECLARE_LOGGING_CATEGORY(LOG_LIB)
|
||||||
|
|
||||||
const QStringList getBuildData();
|
const QStringList getBuildData();
|
||||||
|
@ -84,7 +84,7 @@ Item {
|
|||||||
// ui
|
// ui
|
||||||
Text {
|
Text {
|
||||||
id: text
|
id: text
|
||||||
anchors.fill: Plasmoid.Layout
|
anchors.fill: parent
|
||||||
renderType: Text.NativeRendering
|
renderType: Text.NativeRendering
|
||||||
textFormat: Text.RichText
|
textFormat: Text.RichText
|
||||||
wrapMode: plasmoid.configuration.wrapText ? Text.WordWrap : Text.NoWrap
|
wrapMode: plasmoid.configuration.wrapText ? Text.WordWrap : Text.NoWrap
|
||||||
|
@ -31,6 +31,9 @@ Item {
|
|||||||
AWActions {
|
AWActions {
|
||||||
id: awActions
|
id: awActions
|
||||||
}
|
}
|
||||||
|
AWFormatterConfigFactory {
|
||||||
|
id: awFormatter
|
||||||
|
}
|
||||||
|
|
||||||
width: childrenRect.width
|
width: childrenRect.width
|
||||||
height: childrenRect.height
|
height: childrenRect.height
|
||||||
@ -320,10 +323,15 @@ Item {
|
|||||||
height: implicitHeight
|
height: implicitHeight
|
||||||
width: parent.width
|
width: parent.width
|
||||||
QtControls.Button {
|
QtControls.Button {
|
||||||
width: parent.width * 3 / 5
|
width: parent.width * 3 / 10
|
||||||
text: i18n("Edit bars")
|
text: i18n("Edit bars")
|
||||||
onClicked: awKeys.editItem("graphicalitem")
|
onClicked: awKeys.editItem("graphicalitem")
|
||||||
}
|
}
|
||||||
|
QtControls.Button {
|
||||||
|
width: parent.width * 3 / 10
|
||||||
|
text: i18n("Formatters")
|
||||||
|
onClicked: awFormatter.showDialog(awKeys.dictKeys(true))
|
||||||
|
}
|
||||||
QtControls.Button {
|
QtControls.Button {
|
||||||
width: parent.width * 2 / 5
|
width: parent.width * 2 / 5
|
||||||
text: i18n("Preview")
|
text: i18n("Preview")
|
||||||
|
@ -11,9 +11,11 @@ include_directories(
|
|||||||
)
|
)
|
||||||
|
|
||||||
file(GLOB SUBPROJECT_SOURCE *.cpp ${PROJECT_TRDPARTY_DIR}/fontdialog/*.cpp ${CMAKE_SOURCE_DIR}/*.cpp)
|
file(GLOB SUBPROJECT_SOURCE *.cpp ${PROJECT_TRDPARTY_DIR}/fontdialog/*.cpp ${CMAKE_SOURCE_DIR}/*.cpp)
|
||||||
|
file(GLOB SUBPROJECT_UI *.ui)
|
||||||
file(GLOB SUBPROJECT_NOTIFY *.notifyrc)
|
file(GLOB SUBPROJECT_NOTIFY *.notifyrc)
|
||||||
|
|
||||||
add_library(${PLUGIN_NAME} SHARED ${SUBPROJECT_SOURCE})
|
qt5_wrap_ui(SUBPROJECT_UI_HEADER ${SUBPROJECT_UI})
|
||||||
|
add_library(${PLUGIN_NAME} SHARED ${SUBPROJECT_SOURCE} ${SUBPROJECT_UI_HEADER})
|
||||||
target_link_libraries(${PLUGIN_NAME} ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Kf5_LIBRARIES})
|
target_link_libraries(${PLUGIN_NAME} ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Kf5_LIBRARIES})
|
||||||
|
|
||||||
install(TARGETS ${PLUGIN_NAME} DESTINATION ${QML_INSTALL_DIR}/org/kde/plasma/private/awesomewidget)
|
install(TARGETS ${PLUGIN_NAME} DESTINATION ${QML_INSTALL_DIR}/org/kde/plasma/private/awesomewidget)
|
||||||
|
76
sources/awesome-widget/plugin/awabstractselector.cpp
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* 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 "awabstractselector.h"
|
||||||
|
#include "ui_awabstractselector.h"
|
||||||
|
|
||||||
|
#include "awdebug.h"
|
||||||
|
|
||||||
|
|
||||||
|
AWAbstractSelector::AWAbstractSelector(QWidget *parent)
|
||||||
|
: QWidget(parent)
|
||||||
|
, ui(new Ui::AWAbstractSelector)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
connect(ui->comboBox_key, SIGNAL(currentIndexChanged(int)), this,
|
||||||
|
SIGNAL(selectionChanged()));
|
||||||
|
connect(ui->comboBox_value, SIGNAL(currentIndexChanged(int)), this,
|
||||||
|
SIGNAL(selectionChanged()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
AWAbstractSelector::~AWAbstractSelector()
|
||||||
|
{
|
||||||
|
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QPair<QString, QString> AWAbstractSelector::current() const
|
||||||
|
{
|
||||||
|
QString key = ui->comboBox_key->currentText();
|
||||||
|
QString value = ui->comboBox_value->currentText();
|
||||||
|
|
||||||
|
return QPair<QString, QString>(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
<< "not found in default ones";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
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_value->clear();
|
||||||
|
ui->comboBox_value->addItems(values);
|
||||||
|
|
||||||
|
// set current values
|
||||||
|
ui->comboBox_key->setCurrentText(current.first);
|
||||||
|
ui->comboBox_value->setCurrentText(current.second);
|
||||||
|
}
|
49
sources/awesome-widget/plugin/awabstractselector.h
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* 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 AWABSTRACTSELECTOR_H
|
||||||
|
#define AWABSTRACTSELECTOR_H
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
|
||||||
|
namespace Ui
|
||||||
|
{
|
||||||
|
class AWAbstractSelector;
|
||||||
|
}
|
||||||
|
|
||||||
|
class AWAbstractSelector : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit AWAbstractSelector(QWidget *parent = nullptr);
|
||||||
|
virtual ~AWAbstractSelector();
|
||||||
|
QPair<QString, QString> current() const;
|
||||||
|
void init(const QStringList keys, const QStringList values,
|
||||||
|
const QPair<QString, QString> current);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void selectionChanged();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ui::AWAbstractSelector *ui = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* AWABSTRACTSELECTOR_H */
|
36
sources/awesome-widget/plugin/awabstractselector.ui
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>AWAbstractSelector</class>
|
||||||
|
<widget class="QWidget" name="AWAbstractSelector">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>400</width>
|
||||||
|
<height>25</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<widget class="QComboBox" name="comboBox_key"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QComboBox" name="comboBox_value"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
@ -19,6 +19,7 @@
|
|||||||
#ifndef AWACTIONS_H
|
#ifndef AWACTIONS_H
|
||||||
#define AWACTIONS_H
|
#define AWACTIONS_H
|
||||||
|
|
||||||
|
#include <QMap>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ bool AWConfigHelper::dropCache() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool AWConfigHelper::exportConfiguration(QObject *nativeConfig,
|
bool AWConfigHelper::exportConfiguration(const QObject *nativeConfig,
|
||||||
const QString fileName) const
|
const QString fileName) const
|
||||||
{
|
{
|
||||||
qCDebug(LOG_AW) << "Selected filename" << fileName;
|
qCDebug(LOG_AW) << "Selected filename" << fileName;
|
||||||
@ -77,8 +77,8 @@ bool AWConfigHelper::exportConfiguration(QObject *nativeConfig,
|
|||||||
QSettings settings(fileName, QSettings::IniFormat);
|
QSettings settings(fileName, QSettings::IniFormat);
|
||||||
|
|
||||||
// plasmoid configuration
|
// plasmoid configuration
|
||||||
QQmlPropertyMap *configuration
|
const QQmlPropertyMap *configuration
|
||||||
= static_cast<QQmlPropertyMap *>(nativeConfig);
|
= static_cast<const QQmlPropertyMap *>(nativeConfig);
|
||||||
settings.beginGroup(QString("plasmoid"));
|
settings.beginGroup(QString("plasmoid"));
|
||||||
for (auto key : configuration->keys()) {
|
for (auto key : configuration->keys()) {
|
||||||
QVariant value = configuration->value(key);
|
QVariant value = configuration->value(key);
|
||||||
@ -201,7 +201,7 @@ QVariantMap AWConfigHelper::readDataEngineConfiguration() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AWConfigHelper::writeDataEngineConfiguration(
|
bool AWConfigHelper::writeDataEngineConfiguration(
|
||||||
const QVariantMap configuration) const
|
const QVariantMap configuration) const
|
||||||
{
|
{
|
||||||
qCDebug(LOG_AW) << "Configuration" << configuration;
|
qCDebug(LOG_AW) << "Configuration" << configuration;
|
||||||
@ -228,6 +228,8 @@ void AWConfigHelper::writeDataEngineConfiguration(
|
|||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
|
||||||
settings.sync();
|
settings.sync();
|
||||||
|
|
||||||
|
return (settings.status() == QSettings::NoError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -295,7 +297,7 @@ void AWConfigHelper::readFile(QSettings &settings, const QString key,
|
|||||||
file.close();
|
file.close();
|
||||||
settings.setValue(key, text);
|
settings.setValue(key, text);
|
||||||
} else {
|
} else {
|
||||||
qCWarning(LOG_LIB) << "Could not open" << file.fileName();
|
qCWarning(LOG_AW) << "Could not open" << file.fileName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -316,6 +318,6 @@ void AWConfigHelper::writeFile(QSettings &settings, const QString key,
|
|||||||
out.flush();
|
out.flush();
|
||||||
file.close();
|
file.close();
|
||||||
} else {
|
} else {
|
||||||
qCWarning(LOG_LIB) << "Could not open" << file.fileName();
|
qCWarning(LOG_AW) << "Could not open" << file.fileName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
|
#include <QVariant>
|
||||||
|
|
||||||
|
|
||||||
class QSettings;
|
class QSettings;
|
||||||
@ -34,7 +35,7 @@ public:
|
|||||||
virtual ~AWConfigHelper();
|
virtual ~AWConfigHelper();
|
||||||
Q_INVOKABLE QString configurationDirectory() const;
|
Q_INVOKABLE QString configurationDirectory() const;
|
||||||
Q_INVOKABLE bool dropCache() const;
|
Q_INVOKABLE bool dropCache() const;
|
||||||
Q_INVOKABLE bool exportConfiguration(QObject *nativeConfig,
|
Q_INVOKABLE bool exportConfiguration(const QObject *nativeConfig,
|
||||||
const QString fileName) const;
|
const QString fileName) const;
|
||||||
Q_INVOKABLE QVariantMap importConfiguration(const QString fileName,
|
Q_INVOKABLE QVariantMap importConfiguration(const QString fileName,
|
||||||
const bool importPlasmoid,
|
const bool importPlasmoid,
|
||||||
@ -42,7 +43,7 @@ public:
|
|||||||
const bool importAdds) const;
|
const bool importAdds) const;
|
||||||
// dataengine
|
// dataengine
|
||||||
Q_INVOKABLE QVariantMap readDataEngineConfiguration() const;
|
Q_INVOKABLE QVariantMap readDataEngineConfiguration() const;
|
||||||
Q_INVOKABLE void
|
Q_INVOKABLE bool
|
||||||
writeDataEngineConfiguration(const QVariantMap configuration) const;
|
writeDataEngineConfiguration(const QVariantMap configuration) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -19,11 +19,11 @@
|
|||||||
|
|
||||||
#include <KI18n/KLocalizedString>
|
#include <KI18n/KLocalizedString>
|
||||||
|
|
||||||
#include <QtConcurrent/QtConcurrent>
|
|
||||||
#include <QBuffer>
|
#include <QBuffer>
|
||||||
#include <QGraphicsScene>
|
#include <QGraphicsScene>
|
||||||
#include <QGraphicsView>
|
#include <QGraphicsView>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
|
#include <QtConcurrent/QtConcurrent>
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
|
@ -42,7 +42,6 @@ void AWDataEngineAggregator::clear()
|
|||||||
disconnectSources();
|
disconnectSources();
|
||||||
m_dataEngines.clear();
|
m_dataEngines.clear();
|
||||||
delete m_consumer;
|
delete m_consumer;
|
||||||
m_consumer = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -82,7 +81,7 @@ void AWDataEngineAggregator::dropSource(const QString source)
|
|||||||
{
|
{
|
||||||
qCDebug(LOG_AW) << "Source" << source;
|
qCDebug(LOG_AW) << "Source" << source;
|
||||||
|
|
||||||
// FIXME there is no possibility to check to which dataengine source
|
// HACK there is no possibility to check to which dataengine source
|
||||||
// connected we will try to disconnect it from systemmonitor and extsysmon
|
// connected we will try to disconnect it from systemmonitor and extsysmon
|
||||||
m_dataEngines[QString("systemmonitor")]->disconnectSource(source, parent());
|
m_dataEngines[QString("systemmonitor")]->disconnectSource(source, parent());
|
||||||
m_dataEngines[QString("extsysmon")]->disconnectSource(source, parent());
|
m_dataEngines[QString("extsysmon")]->disconnectSource(source, parent());
|
||||||
|
@ -1,84 +0,0 @@
|
|||||||
/***************************************************************************
|
|
||||||
* This file is part of awesome-widgets *
|
|
||||||
* *
|
|
||||||
* awesome-widgets is free software: you can redistribute it and/or *
|
|
||||||
* modify it under the terms of the GNU General Public License as *
|
|
||||||
* published by the Free Software Foundation, either version 3 of the *
|
|
||||||
* License, or (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* awesome-widgets is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
||||||
* GNU General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU General Public License *
|
|
||||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
|
||||||
***************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
#include "awdatetimeformatter.h"
|
|
||||||
|
|
||||||
#include <QDateTime>
|
|
||||||
#include <QSettings>
|
|
||||||
|
|
||||||
#include "awdebug.h"
|
|
||||||
|
|
||||||
|
|
||||||
AWDateTimeFormatter::AWDateTimeFormatter(QObject *parent,
|
|
||||||
const QString filename,
|
|
||||||
const QString section)
|
|
||||||
: AWAbstractFormatter(parent, filename, section)
|
|
||||||
{
|
|
||||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
|
||||||
|
|
||||||
init(filename, section);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
AWDateTimeFormatter::AWDateTimeFormatter(QObject *parent, const QString format)
|
|
||||||
: AWAbstractFormatter(parent)
|
|
||||||
{
|
|
||||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
|
||||||
|
|
||||||
setFormat(format);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
AWDateTimeFormatter::~AWDateTimeFormatter()
|
|
||||||
{
|
|
||||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QString AWDateTimeFormatter::convert(const QVariant &value) const
|
|
||||||
{
|
|
||||||
qCDebug(LOG_AW) << "Convert value" << value;
|
|
||||||
|
|
||||||
return value.toDateTime().toString(m_format);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QString AWDateTimeFormatter::format() const
|
|
||||||
{
|
|
||||||
return m_format;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void AWDateTimeFormatter::setFormat(const QString _format)
|
|
||||||
{
|
|
||||||
qCDebug(LOG_AW) << "Set format" << _format;
|
|
||||||
|
|
||||||
m_format = _format;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void AWDateTimeFormatter::init(const QString filename, const QString section)
|
|
||||||
{
|
|
||||||
qCDebug(LOG_AW) << "Looking for section" << section << "in" << filename;
|
|
||||||
|
|
||||||
QSettings settings(filename, QSettings::IniFormat);
|
|
||||||
|
|
||||||
settings.beginGroup(section);
|
|
||||||
setFormat(settings.value(QString("Format"), QString()).toString());
|
|
||||||
settings.endGroup();
|
|
||||||
}
|
|
@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
#include "awactions.h"
|
#include "awactions.h"
|
||||||
#include "awconfighelper.h"
|
#include "awconfighelper.h"
|
||||||
#include "awdataengineaggregator.h"
|
#include "awformatterconfigfactory.h"
|
||||||
#include "awkeys.h"
|
#include "awkeys.h"
|
||||||
|
|
||||||
|
|
||||||
@ -31,5 +31,7 @@ void AWPlugin::registerTypes(const char *uri)
|
|||||||
|
|
||||||
qmlRegisterType<AWActions>(uri, 1, 0, "AWActions");
|
qmlRegisterType<AWActions>(uri, 1, 0, "AWActions");
|
||||||
qmlRegisterType<AWConfigHelper>(uri, 1, 0, "AWConfigHelper");
|
qmlRegisterType<AWConfigHelper>(uri, 1, 0, "AWConfigHelper");
|
||||||
|
qmlRegisterType<AWFormatterConfigFactory>(uri, 1, 0,
|
||||||
|
"AWFormatterConfigFactory");
|
||||||
qmlRegisterType<AWKeys>(uri, 1, 0, "AWKeys");
|
qmlRegisterType<AWKeys>(uri, 1, 0, "AWKeys");
|
||||||
}
|
}
|
||||||
|
@ -1,176 +0,0 @@
|
|||||||
/***************************************************************************
|
|
||||||
* This file is part of awesome-widgets *
|
|
||||||
* *
|
|
||||||
* awesome-widgets is free software: you can redistribute it and/or *
|
|
||||||
* modify it under the terms of the GNU General Public License as *
|
|
||||||
* published by the Free Software Foundation, either version 3 of the *
|
|
||||||
* License, or (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* awesome-widgets is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
||||||
* GNU General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU General Public License *
|
|
||||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
|
||||||
***************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
#include "awfloatformatter.h"
|
|
||||||
|
|
||||||
#include <QSettings>
|
|
||||||
|
|
||||||
#include "awdebug.h"
|
|
||||||
|
|
||||||
|
|
||||||
AWFloatFormatter::AWFloatFormatter(QObject *parent, const QString filename,
|
|
||||||
const QString section)
|
|
||||||
: AWAbstractFormatter(parent, filename, section)
|
|
||||||
{
|
|
||||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
|
||||||
|
|
||||||
init(filename, section);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
AWFloatFormatter::AWFloatFormatter(QObject *parent, const QChar fillChar,
|
|
||||||
const char format, const double multiplier,
|
|
||||||
const int precision, const double summand,
|
|
||||||
const int width)
|
|
||||||
: AWAbstractFormatter(parent)
|
|
||||||
{
|
|
||||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
|
||||||
|
|
||||||
setFillChar(fillChar);
|
|
||||||
setFormat(format);
|
|
||||||
setMultiplier(multiplier);
|
|
||||||
setPrecision(precision);
|
|
||||||
setSummand(summand);
|
|
||||||
setWidth(width);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
AWFloatFormatter::~AWFloatFormatter()
|
|
||||||
{
|
|
||||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QString AWFloatFormatter::convert(const QVariant &value) const
|
|
||||||
{
|
|
||||||
qCDebug(LOG_AW) << "Convert value" << value;
|
|
||||||
|
|
||||||
return QString("%1").arg(value.toDouble() * m_multiplier + m_summand,
|
|
||||||
m_width, m_format, m_precision, m_fillChar);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QChar AWFloatFormatter::fillChar() const
|
|
||||||
{
|
|
||||||
return m_fillChar;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
char AWFloatFormatter::format() const
|
|
||||||
{
|
|
||||||
return m_format;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
double AWFloatFormatter::multiplier() const
|
|
||||||
{
|
|
||||||
return m_multiplier;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int AWFloatFormatter::precision() const
|
|
||||||
{
|
|
||||||
return m_precision;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
double AWFloatFormatter::summand() const
|
|
||||||
{
|
|
||||||
return m_summand;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int AWFloatFormatter::width() const
|
|
||||||
{
|
|
||||||
return m_width;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void AWFloatFormatter::setFillChar(const QChar _fillChar)
|
|
||||||
{
|
|
||||||
qCDebug(LOG_AW) << "Set char" << _fillChar;
|
|
||||||
|
|
||||||
m_fillChar = _fillChar;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void AWFloatFormatter::setFormat(char _format)
|
|
||||||
{
|
|
||||||
qCDebug(LOG_AW) << "Set format" << _format;
|
|
||||||
// http://doc.qt.io/qt-5/qstring.html#argument-formats
|
|
||||||
if ((_format != 'e') && (_format != 'E') && (_format != 'f')
|
|
||||||
&& (_format != 'g') && (_format != 'G')) {
|
|
||||||
qCWarning(LOG_AW) << "Invalid format" << _format;
|
|
||||||
_format = 'f';
|
|
||||||
}
|
|
||||||
|
|
||||||
m_format = _format;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void AWFloatFormatter::setMultiplier(const double _multiplier)
|
|
||||||
{
|
|
||||||
qCDebug(LOG_AW) << "Set multiplier" << _multiplier;
|
|
||||||
|
|
||||||
m_multiplier = _multiplier;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void AWFloatFormatter::setPrecision(const int _precision)
|
|
||||||
{
|
|
||||||
qCDebug(LOG_AW) << "Set precision" << _precision;
|
|
||||||
|
|
||||||
m_precision = _precision;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void AWFloatFormatter::setSummand(const double _summand)
|
|
||||||
{
|
|
||||||
qCDebug(LOG_AW) << "Set summand" << _summand;
|
|
||||||
|
|
||||||
m_summand = _summand;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void AWFloatFormatter::setWidth(const int _width)
|
|
||||||
{
|
|
||||||
qCDebug(LOG_AW) << "Set width" << _width;
|
|
||||||
|
|
||||||
m_width = _width;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void AWFloatFormatter::init(const QString filename, const QString section)
|
|
||||||
{
|
|
||||||
qCDebug(LOG_AW) << "Looking for section" << section << "in" << filename;
|
|
||||||
|
|
||||||
QSettings settings(filename, QSettings::IniFormat);
|
|
||||||
|
|
||||||
settings.beginGroup(section);
|
|
||||||
setFillChar(
|
|
||||||
settings.value(QString("FillChar"), QString()).toString().at(0));
|
|
||||||
setFormat(settings.value(QString("Format"), QString("f"))
|
|
||||||
.toString()
|
|
||||||
.at(0)
|
|
||||||
.toLatin1());
|
|
||||||
setMultiplier(settings.value(QString("Multiplier"), 1.0).toDouble());
|
|
||||||
setPrecision(settings.value(QString("Precision"), -1).toInt());
|
|
||||||
setSummand(settings.value(QString("Summand"), 0.0).toDouble());
|
|
||||||
setWidth(settings.value(QString("Width"), 0).toInt());
|
|
||||||
settings.endGroup();
|
|
||||||
}
|
|
181
sources/awesome-widget/plugin/awformatterconfig.cpp
Normal file
@ -0,0 +1,181 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* 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 "awformatterconfig.h"
|
||||||
|
#include "ui_awformatterconfig.h"
|
||||||
|
|
||||||
|
#include <KI18n/KLocalizedString>
|
||||||
|
|
||||||
|
#include <QPushButton>
|
||||||
|
|
||||||
|
#include "awabstractselector.h"
|
||||||
|
#include "awdebug.h"
|
||||||
|
#include "awformatterhelper.h"
|
||||||
|
|
||||||
|
|
||||||
|
AWFormatterConfig::AWFormatterConfig(QWidget *parent, const QStringList keys)
|
||||||
|
: QDialog(parent)
|
||||||
|
, ui(new Ui::AWFormatterConfig)
|
||||||
|
, m_keys(keys)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
|
ui->setupUi(this);
|
||||||
|
editButton
|
||||||
|
= ui->buttonBox->addButton(i18n("Edit"), QDialogButtonBox::ActionRole);
|
||||||
|
init();
|
||||||
|
|
||||||
|
connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
|
||||||
|
connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
||||||
|
connect(editButton, SIGNAL(clicked(bool)), this, SLOT(editFormatters()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
AWFormatterConfig::~AWFormatterConfig()
|
||||||
|
{
|
||||||
|
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
|
clearSelectors();
|
||||||
|
|
||||||
|
delete m_helper;
|
||||||
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWFormatterConfig::showDialog()
|
||||||
|
{
|
||||||
|
// update dialog
|
||||||
|
updateDialog();
|
||||||
|
// exec dialog
|
||||||
|
return execDialog();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWFormatterConfig::editFormatters()
|
||||||
|
{
|
||||||
|
m_helper->editItems();
|
||||||
|
updateDialog();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWFormatterConfig::updateUi()
|
||||||
|
{
|
||||||
|
QPair<QString, QString> current
|
||||||
|
= static_cast<AWAbstractSelector *>(sender())->current();
|
||||||
|
int index
|
||||||
|
= m_selectors.indexOf(static_cast<AWAbstractSelector *>(sender()));
|
||||||
|
|
||||||
|
if ((current.first.isEmpty()) && (current.second.isEmpty())) {
|
||||||
|
if (sender() == m_selectors.last())
|
||||||
|
return;
|
||||||
|
AWAbstractSelector *selector = m_selectors.takeAt(index);
|
||||||
|
ui->verticalLayout->removeWidget(selector);
|
||||||
|
selector->deleteLater();
|
||||||
|
} else {
|
||||||
|
if (sender() != m_selectors.last())
|
||||||
|
return;
|
||||||
|
auto keys = initKeys();
|
||||||
|
addSelector(keys.first, keys.second, QPair<QString, QString>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWFormatterConfig::addSelector(const QStringList &keys,
|
||||||
|
const QStringList &values,
|
||||||
|
const QPair<QString, QString> ¤t)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
ui->verticalLayout->insertWidget(ui->verticalLayout->count() - 1, selector);
|
||||||
|
connect(selector, SIGNAL(selectionChanged()), this, SLOT(updateUi()));
|
||||||
|
m_selectors.append(selector);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWFormatterConfig::clearSelectors()
|
||||||
|
{
|
||||||
|
for (auto selector : m_selectors) {
|
||||||
|
disconnect(selector, SIGNAL(selectionChanged()), this,
|
||||||
|
SLOT(updateUi()));
|
||||||
|
ui->verticalLayout->removeWidget(selector);
|
||||||
|
selector->deleteLater();
|
||||||
|
}
|
||||||
|
m_selectors.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWFormatterConfig::execDialog()
|
||||||
|
{
|
||||||
|
int ret = exec();
|
||||||
|
QHash<QString, QString> data;
|
||||||
|
for (auto selector : m_selectors) {
|
||||||
|
QPair<QString, QString> select = selector->current();
|
||||||
|
if (select.first.isEmpty())
|
||||||
|
continue;
|
||||||
|
data[select.first] = select.second;
|
||||||
|
}
|
||||||
|
|
||||||
|
// save configuration if required
|
||||||
|
switch (ret) {
|
||||||
|
case 0:
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
default:
|
||||||
|
m_helper->writeFormatters(data);
|
||||||
|
m_helper->writeFormatters(data.keys());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWFormatterConfig::init()
|
||||||
|
{
|
||||||
|
delete m_helper;
|
||||||
|
m_helper = new AWFormatterHelper(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QPair<QStringList, QStringList> AWFormatterConfig::initKeys() const
|
||||||
|
{
|
||||||
|
// we are adding empty string at the start
|
||||||
|
QStringList keys = QStringList() << QString("");
|
||||||
|
keys.append(m_keys);
|
||||||
|
keys.sort();
|
||||||
|
QStringList knownFormatters = QStringList() << QString("");
|
||||||
|
knownFormatters.append(m_helper->knownFormatters());
|
||||||
|
knownFormatters.sort();
|
||||||
|
|
||||||
|
return QPair<QStringList, QStringList>(keys, knownFormatters);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWFormatterConfig::updateDialog()
|
||||||
|
{
|
||||||
|
clearSelectors();
|
||||||
|
QHash<QString, QString> appliedFormatters = m_helper->getFormatters();
|
||||||
|
auto keys = initKeys();
|
||||||
|
|
||||||
|
for (auto key : appliedFormatters.keys())
|
||||||
|
addSelector(keys.first, keys.second,
|
||||||
|
QPair<QString, QString>(key, appliedFormatters[key]));
|
||||||
|
// empty one
|
||||||
|
addSelector(keys.first, keys.second, QPair<QString, QString>());
|
||||||
|
}
|
64
sources/awesome-widget/plugin/awformatterconfig.h
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* 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 AWFORMATTERCONFIG_H
|
||||||
|
#define AWFORMATTERCONFIG_H
|
||||||
|
|
||||||
|
#include <QDialog>
|
||||||
|
|
||||||
|
|
||||||
|
class AWAbstractSelector;
|
||||||
|
class AWFormatterHelper;
|
||||||
|
namespace Ui
|
||||||
|
{
|
||||||
|
class AWFormatterConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
class AWFormatterConfig : public QDialog
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit AWFormatterConfig(QWidget *parent = nullptr,
|
||||||
|
const QStringList keys = QStringList());
|
||||||
|
virtual ~AWFormatterConfig();
|
||||||
|
Q_INVOKABLE void showDialog();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void editFormatters();
|
||||||
|
void updateUi();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QPushButton *editButton = nullptr;
|
||||||
|
Ui::AWFormatterConfig *ui = nullptr;
|
||||||
|
AWFormatterHelper *m_helper = nullptr;
|
||||||
|
QList<AWAbstractSelector *> m_selectors;
|
||||||
|
// properties
|
||||||
|
QStringList m_keys;
|
||||||
|
// methods
|
||||||
|
void addSelector(const QStringList &keys, const QStringList &values,
|
||||||
|
const QPair<QString, QString> ¤t);
|
||||||
|
void clearSelectors();
|
||||||
|
void execDialog();
|
||||||
|
void init();
|
||||||
|
QPair<QStringList, QStringList> initKeys() const;
|
||||||
|
void updateDialog();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* AWFORMATTERCONFIG_H */
|
93
sources/awesome-widget/plugin/awformatterconfig.ui
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>AWFormatterConfig</class>
|
||||||
|
<widget class="QDialog" name="AWFormatterConfig">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>400</width>
|
||||||
|
<height>300</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
|
<item>
|
||||||
|
<widget class="QScrollArea" name="scrollArea">
|
||||||
|
<property name="widgetResizable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="scrollAreaWidgetContents">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>384</width>
|
||||||
|
<height>249</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<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>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="standardButtons">
|
||||||
|
<set>QDialogButtonBox::Close|QDialogButtonBox::Ok</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>accepted()</signal>
|
||||||
|
<receiver>AWFormatterConfig</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>AWFormatterConfig</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>
|
@ -15,45 +15,28 @@
|
|||||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
#include "awformatterconfigfactory.h"
|
||||||
#include "awnoformatter.h"
|
|
||||||
|
|
||||||
#include "awdebug.h"
|
#include "awdebug.h"
|
||||||
|
#include "awformatterconfig.h"
|
||||||
|
|
||||||
|
|
||||||
AWNoFormatter::AWNoFormatter(QObject *parent, const QString filename,
|
AWFormatterConfigFactory::AWFormatterConfigFactory(QObject *parent)
|
||||||
const QString section)
|
: QObject(parent)
|
||||||
: AWAbstractFormatter(parent, filename, section)
|
|
||||||
{
|
|
||||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
|
||||||
|
|
||||||
init(filename, section);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
AWNoFormatter::AWNoFormatter(QObject *parent)
|
|
||||||
: AWAbstractFormatter(parent)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
AWNoFormatter::~AWNoFormatter()
|
AWFormatterConfigFactory::~AWFormatterConfigFactory()
|
||||||
{
|
{
|
||||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString AWNoFormatter::convert(const QVariant &value) const
|
void AWFormatterConfigFactory::showDialog(const QStringList keys)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_AW) << "Convert value" << value;
|
AWFormatterConfig *config = new AWFormatterConfig(nullptr, keys);
|
||||||
|
config->showDialog();
|
||||||
return value.toString();
|
config->deleteLater();
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void AWNoFormatter::init(const QString filename, const QString section)
|
|
||||||
{
|
|
||||||
qCDebug(LOG_AW) << "Looking for section" << section << "in" << filename;
|
|
||||||
// dummy method for future references
|
|
||||||
}
|
}
|
@ -15,23 +15,24 @@
|
|||||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
#ifndef AWABSTRACTFORMATTER_H
|
|
||||||
#define AWABSTRACTFORMATTER_H
|
#ifndef AWFORMATTERCONFIGFACTORY_H
|
||||||
|
#define AWFORMATTERCONFIGFACTORY_H
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QVariant>
|
|
||||||
|
|
||||||
|
|
||||||
class AWAbstractFormatter : public QObject
|
class AWFormatterConfigFactory : public QObject
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit AWAbstractFormatter(QObject *parent, const QString, const QString)
|
explicit AWFormatterConfigFactory(QObject *parent = nullptr);
|
||||||
: QObject(parent){};
|
virtual ~AWFormatterConfigFactory();
|
||||||
explicit AWAbstractFormatter(QObject *parent)
|
Q_INVOKABLE void showDialog(const QStringList keys);
|
||||||
: QObject(parent){};
|
|
||||||
virtual ~AWAbstractFormatter(){};
|
private:
|
||||||
virtual QString convert(const QVariant &value) const = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif /* AWABSTRACTFORMATTER_H */
|
#endif /* AWFORMATTERCONFIGFACTORY_H */
|
@ -17,27 +17,27 @@
|
|||||||
|
|
||||||
#include "awformatterhelper.h"
|
#include "awformatterhelper.h"
|
||||||
|
|
||||||
#include <QSettings>
|
#include <KI18n/KLocalizedString>
|
||||||
#include <QStandardPaths>
|
|
||||||
|
#include <QDir>
|
||||||
|
#include <QInputDialog>
|
||||||
|
#include <QSettings>
|
||||||
|
|
||||||
#include "awdebug.h"
|
|
||||||
#include "awdatetimeformatter.h"
|
#include "awdatetimeformatter.h"
|
||||||
|
#include "awdebug.h"
|
||||||
#include "awfloatformatter.h"
|
#include "awfloatformatter.h"
|
||||||
|
#include "awlistformatter.h"
|
||||||
#include "awnoformatter.h"
|
#include "awnoformatter.h"
|
||||||
#include "awscriptformatter.h"
|
#include "awscriptformatter.h"
|
||||||
|
#include "awstringformatter.h"
|
||||||
|
|
||||||
|
|
||||||
AWFormatterHelper::AWFormatterHelper(QObject *parent)
|
AWFormatterHelper::AWFormatterHelper(QWidget *parent)
|
||||||
: QObject(parent)
|
: AbstractExtItemAggregator(parent, QString("formatters"))
|
||||||
{
|
{
|
||||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
m_genericConfig = QString("%1/awesomewidgets/general.ini")
|
initItems();
|
||||||
.arg(QStandardPaths::writableLocation(
|
|
||||||
QStandardPaths::GenericDataLocation));
|
|
||||||
#ifdef BUILD_FUTURE
|
|
||||||
init();
|
|
||||||
#endif /* BUILD_FUTURE */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -46,11 +46,12 @@ AWFormatterHelper::~AWFormatterHelper()
|
|||||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
m_formatters.clear();
|
m_formatters.clear();
|
||||||
|
m_formattersClasses.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString AWFormatterHelper::convert(const QVariant &value,
|
QString AWFormatterHelper::convert(const QVariant &value,
|
||||||
const QString name) const
|
const QString &name) const
|
||||||
{
|
{
|
||||||
qCDebug(LOG_AW) << "Convert value" << value << "for" << name;
|
qCDebug(LOG_AW) << "Convert value" << value << "for" << name;
|
||||||
|
|
||||||
@ -65,25 +66,106 @@ QStringList AWFormatterHelper::definedFormatters() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
AWFormatterHelper::FormatterClass
|
QHash<QString, QString> AWFormatterHelper::getFormatters() const
|
||||||
AWFormatterHelper::defineFormatterClass(const QString name) const
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_AW) << "Define formatter class for" << name;
|
QHash<QString, QString> map;
|
||||||
|
for (auto tag : m_formatters.keys())
|
||||||
|
map[tag] = m_formatters[tag]->name();
|
||||||
|
|
||||||
QSettings settings(m_genericConfig, QSettings::IniFormat);
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
settings.beginGroup(name);
|
|
||||||
QString stringType
|
QList<AbstractExtItem *> AWFormatterHelper::items() const
|
||||||
= settings.value(QString("Type"), QString("NoFormat")).toString();
|
{
|
||||||
|
QList<AbstractExtItem *> converted;
|
||||||
|
for (auto item : m_formattersClasses.values())
|
||||||
|
converted.append(item);
|
||||||
|
|
||||||
|
return converted;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QStringList AWFormatterHelper::knownFormatters() const
|
||||||
|
{
|
||||||
|
return m_formattersClasses.keys();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool AWFormatterHelper::writeFormatters(const QStringList keys) const
|
||||||
|
{
|
||||||
|
qCDebug(LOG_AW) << "Remove formatters" << keys;
|
||||||
|
|
||||||
|
QString fileName = QString("%1/awesomewidgets/formatters/formatters.ini")
|
||||||
|
.arg(QStandardPaths::writableLocation(
|
||||||
|
QStandardPaths::GenericDataLocation));
|
||||||
|
QSettings settings(fileName, QSettings::IniFormat);
|
||||||
|
qCInfo(LOG_AW) << "Configuration file" << fileName;
|
||||||
|
|
||||||
|
settings.beginGroup(QString("Formatters"));
|
||||||
|
QStringList foundKeys = settings.childKeys();
|
||||||
|
for (auto key : foundKeys) {
|
||||||
|
if (keys.contains(key))
|
||||||
|
continue;
|
||||||
|
settings.remove(key);
|
||||||
|
}
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
|
||||||
FormatterClass formatter = FormatterClass::NoFormat;
|
settings.sync();
|
||||||
|
|
||||||
|
return (settings.status() == QSettings::NoError);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool AWFormatterHelper::writeFormatters(
|
||||||
|
const QHash<QString, QString> configuration) const
|
||||||
|
{
|
||||||
|
qCDebug(LOG_AW) << "Write configuration" << configuration;
|
||||||
|
|
||||||
|
QString fileName = QString("%1/awesomewidgets/formatters/formatters.ini")
|
||||||
|
.arg(QStandardPaths::writableLocation(
|
||||||
|
QStandardPaths::GenericDataLocation));
|
||||||
|
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.endGroup();
|
||||||
|
|
||||||
|
settings.sync();
|
||||||
|
|
||||||
|
return (settings.status() == QSettings::NoError);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWFormatterHelper::editItems()
|
||||||
|
{
|
||||||
|
repaintList();
|
||||||
|
int ret = exec();
|
||||||
|
qCInfo(LOG_AW) << "Dialog returns" << ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
AWAbstractFormatter::FormatterClass
|
||||||
|
AWFormatterHelper::defineFormatterClass(const QString stringType) const
|
||||||
|
{
|
||||||
|
qCDebug(LOG_AW) << "Define formatter class for" << stringType;
|
||||||
|
|
||||||
|
AWAbstractFormatter::FormatterClass formatter
|
||||||
|
= AWAbstractFormatter::FormatterClass::NoFormat;
|
||||||
if (stringType == QString("DateTime"))
|
if (stringType == QString("DateTime"))
|
||||||
formatter = FormatterClass::DateTime;
|
formatter = AWAbstractFormatter::FormatterClass::DateTime;
|
||||||
else if (stringType == QString("Float"))
|
else if (stringType == QString("Float"))
|
||||||
formatter = FormatterClass::Float;
|
formatter = AWAbstractFormatter::FormatterClass::Float;
|
||||||
|
else if (stringType == QString("List"))
|
||||||
|
formatter = AWAbstractFormatter::FormatterClass::List;
|
||||||
|
else if (stringType == QString("NoFormat"))
|
||||||
|
;
|
||||||
else if (stringType == QString("Script"))
|
else if (stringType == QString("Script"))
|
||||||
formatter = FormatterClass::Script;
|
formatter = AWAbstractFormatter::FormatterClass::Script;
|
||||||
|
else if (stringType == QString("String"))
|
||||||
|
formatter = AWAbstractFormatter::FormatterClass::String;
|
||||||
else
|
else
|
||||||
qCWarning(LOG_AW) << "Unknown formatter" << stringType;
|
qCWarning(LOG_AW) << "Unknown formatter" << stringType;
|
||||||
|
|
||||||
@ -91,35 +173,159 @@ AWFormatterHelper::defineFormatterClass(const QString name) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AWFormatterHelper::init()
|
void AWFormatterHelper::initFormatters()
|
||||||
{
|
{
|
||||||
QSettings settings(m_genericConfig, QSettings::IniFormat);
|
m_formattersClasses.clear();
|
||||||
|
|
||||||
|
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")))
|
||||||
|
continue;
|
||||||
|
qCInfo(LOG_AW) << "Found file" << file << "in"
|
||||||
|
<< m_directories.at(i);
|
||||||
|
QString filePath
|
||||||
|
= QString("%1/%2").arg(m_directories.at(i)).arg(file);
|
||||||
|
auto metadata = readMetadata(filePath);
|
||||||
|
QString name = metadata.first;
|
||||||
|
if (m_formattersClasses.contains(name))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
|
||||||
|
switch (metadata.second) {
|
||||||
|
case AWAbstractFormatter::FormatterClass::DateTime:
|
||||||
|
m_formattersClasses[name]
|
||||||
|
= new AWDateTimeFormatter(this, filePath);
|
||||||
|
break;
|
||||||
|
case AWAbstractFormatter::FormatterClass::Float:
|
||||||
|
m_formattersClasses[name]
|
||||||
|
= new AWFloatFormatter(this, filePath);
|
||||||
|
break;
|
||||||
|
case AWAbstractFormatter::FormatterClass::List:
|
||||||
|
m_formattersClasses[name] = new AWListFormatter(this, filePath);
|
||||||
|
break;
|
||||||
|
case AWAbstractFormatter::FormatterClass::Script:
|
||||||
|
m_formattersClasses[name]
|
||||||
|
= new AWScriptFormatter(this, filePath);
|
||||||
|
break;
|
||||||
|
case AWAbstractFormatter::FormatterClass::String:
|
||||||
|
m_formattersClasses[name]
|
||||||
|
= new AWStringFormatter(this, filePath);
|
||||||
|
break;
|
||||||
|
case AWAbstractFormatter::FormatterClass::NoFormat:
|
||||||
|
m_formattersClasses[name] = new AWNoFormatter(this, filePath);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWFormatterHelper::initKeys()
|
||||||
|
{
|
||||||
|
m_formatters.clear();
|
||||||
|
|
||||||
|
QStringList configs = QStandardPaths::locateAll(
|
||||||
|
QStandardPaths::GenericDataLocation,
|
||||||
|
QString("awesomewidgets/formatters/formatters.ini"));
|
||||||
|
|
||||||
|
for (auto fileName : configs) {
|
||||||
|
QSettings settings(fileName, QSettings::IniFormat);
|
||||||
|
qCInfo(LOG_AW) << "Configuration file" << settings.fileName();
|
||||||
|
|
||||||
settings.beginGroup(QString("Formatters"));
|
settings.beginGroup(QString("Formatters"));
|
||||||
QStringList keys = settings.childKeys();
|
QStringList keys = settings.childKeys();
|
||||||
for (auto key : keys) {
|
for (auto key : keys) {
|
||||||
QString name = settings.value(key).toString();
|
QString name = settings.value(key).toString();
|
||||||
FormatterClass formatter = defineFormatterClass(name);
|
|
||||||
qCInfo(LOG_AW) << "Found formatter" << name << "for key" << key
|
qCInfo(LOG_AW) << "Found formatter" << name << "for key" << key
|
||||||
<< "defined as" << static_cast<int>(formatter);
|
<< "in" << settings.fileName();
|
||||||
|
if (name.isEmpty()) {
|
||||||
switch (formatter) {
|
qCInfo(LOG_AW) << "Skip empty formatter for" << key;
|
||||||
case FormatterClass::DateTime:
|
continue;
|
||||||
m_formatters[key]
|
|
||||||
= new AWDateTimeFormatter(this, m_genericConfig, name);
|
|
||||||
break;
|
|
||||||
case FormatterClass::Float:
|
|
||||||
m_formatters[key]
|
|
||||||
= new AWFloatFormatter(this, m_genericConfig, name);
|
|
||||||
break;
|
|
||||||
case FormatterClass::Script:
|
|
||||||
m_formatters[key]
|
|
||||||
= new AWScriptFormatter(this, m_genericConfig, name);
|
|
||||||
break;
|
|
||||||
case FormatterClass::NoFormat:
|
|
||||||
m_formatters[key] = new AWNoFormatter(this, m_genericConfig, name);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
if (!m_formattersClasses.contains(name)) {
|
||||||
|
qCWarning(LOG_AW) << "Invalid formatter" << name << "found in"
|
||||||
|
<< key;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
m_formatters[key] = m_formattersClasses[name];
|
||||||
}
|
}
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWFormatterHelper::installDirectories()
|
||||||
|
{
|
||||||
|
// create directory at $HOME
|
||||||
|
QString localDir = QString("%1/awesomewidgets/formatters")
|
||||||
|
.arg(QStandardPaths::writableLocation(
|
||||||
|
QStandardPaths::GenericDataLocation));
|
||||||
|
QDir localDirectory;
|
||||||
|
if (localDirectory.mkpath(localDir))
|
||||||
|
qCInfo(LOG_AW) << "Created directory" << localDir;
|
||||||
|
|
||||||
|
m_directories = QStandardPaths::locateAll(
|
||||||
|
QStandardPaths::GenericDataLocation,
|
||||||
|
QString("awesomewidgets/formatters"), QStandardPaths::LocateDirectory);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QPair<QString, AWAbstractFormatter::FormatterClass>
|
||||||
|
AWFormatterHelper::readMetadata(const QString filePath) const
|
||||||
|
{
|
||||||
|
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();
|
||||||
|
AWAbstractFormatter::FormatterClass formatter = defineFormatterClass(type);
|
||||||
|
settings.endGroup();
|
||||||
|
|
||||||
|
return QPair<QString, AWAbstractFormatter::FormatterClass>(name, formatter);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWFormatterHelper::doCreateItem()
|
||||||
|
{
|
||||||
|
QStringList selection = QStringList()
|
||||||
|
<< QString("NoFormat") << QString("DateTime")
|
||||||
|
<< QString("Float") << QString("List")
|
||||||
|
<< QString("Script") << QString("String");
|
||||||
|
bool ok;
|
||||||
|
QString select = QInputDialog::getItem(
|
||||||
|
this, i18n("Select type"), i18n("Type:"), selection, 0, false, &ok);
|
||||||
|
if (!ok) {
|
||||||
|
qCWarning(LOG_AW) << "No type selected";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
qCInfo(LOG_AW) << "Selected type" << select;
|
||||||
|
AWAbstractFormatter::FormatterClass formatter
|
||||||
|
= defineFormatterClass(select);
|
||||||
|
switch (formatter) {
|
||||||
|
case AWAbstractFormatter::FormatterClass::DateTime:
|
||||||
|
return createItem<AWDateTimeFormatter>();
|
||||||
|
case AWAbstractFormatter::FormatterClass::Float:
|
||||||
|
return createItem<AWFloatFormatter>();
|
||||||
|
case AWAbstractFormatter::FormatterClass::List:
|
||||||
|
return createItem<AWListFormatter>();
|
||||||
|
case AWAbstractFormatter::FormatterClass::Script:
|
||||||
|
return createItem<AWScriptFormatter>();
|
||||||
|
case AWAbstractFormatter::FormatterClass::String:
|
||||||
|
return createItem<AWStringFormatter>();
|
||||||
|
case AWAbstractFormatter::FormatterClass::NoFormat:
|
||||||
|
return createItem<AWNoFormatter>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWFormatterHelper::initItems()
|
||||||
|
{
|
||||||
|
installDirectories();
|
||||||
|
initFormatters();
|
||||||
|
initKeys();
|
||||||
}
|
}
|
||||||
|
@ -19,30 +19,47 @@
|
|||||||
#ifndef AWFORMATTERHELPER_H
|
#ifndef AWFORMATTERHELPER_H
|
||||||
#define AWFORMATTERHELPER_H
|
#define AWFORMATTERHELPER_H
|
||||||
|
|
||||||
#include <QObject>
|
#include "abstractextitemaggregator.h"
|
||||||
|
|
||||||
#include "awabstractformatter.h"
|
#include "awabstractformatter.h"
|
||||||
|
|
||||||
|
|
||||||
class AWFormatterHelper : public QObject
|
class AWAbstractFormatter;
|
||||||
|
|
||||||
|
class AWFormatterHelper : public AbstractExtItemAggregator
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum class FormatterClass { DateTime, Float, Script, NoFormat };
|
explicit AWFormatterHelper(QWidget *parent = nullptr);
|
||||||
|
|
||||||
explicit AWFormatterHelper(QObject *parent = nullptr);
|
|
||||||
virtual ~AWFormatterHelper();
|
virtual ~AWFormatterHelper();
|
||||||
QString convert(const QVariant &value, const QString name) const;
|
QString convert(const QVariant &value, const QString &name) const;
|
||||||
QStringList definedFormatters() 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;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void editItems();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AWFormatterHelper::FormatterClass
|
// methods
|
||||||
defineFormatterClass(const QString name) const;
|
AWAbstractFormatter::FormatterClass
|
||||||
void init();
|
defineFormatterClass(const QString stringType) const;
|
||||||
|
void initFormatters();
|
||||||
|
void initKeys();
|
||||||
|
void installDirectories();
|
||||||
|
QPair<QString, AWAbstractFormatter::FormatterClass>
|
||||||
|
readMetadata(const QString filePath) const;
|
||||||
|
// parent methods
|
||||||
|
void doCreateItem();
|
||||||
|
void initItems();
|
||||||
// properties
|
// properties
|
||||||
QString m_genericConfig;
|
QStringList m_directories;
|
||||||
QHash<QString, AWAbstractFormatter *> m_formatters;
|
QHash<QString, AWAbstractFormatter *> m_formatters;
|
||||||
|
QHash<QString, AWAbstractFormatter *> m_formattersClasses;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -38,8 +38,8 @@ bool AWKeyCache::addKeyToCache(const QString type, const QString key)
|
|||||||
|
|
||||||
cache.beginGroup(type);
|
cache.beginGroup(type);
|
||||||
QStringList cachedValues;
|
QStringList cachedValues;
|
||||||
for (auto key : cache.allKeys())
|
for (auto number : cache.allKeys())
|
||||||
cachedValues.append(cache.value(key).toString());
|
cachedValues.append(cache.value(number).toString());
|
||||||
|
|
||||||
if (type == QString("hdd")) {
|
if (type == QString("hdd")) {
|
||||||
QStringList allDevices
|
QStringList allDevices
|
||||||
@ -51,6 +51,7 @@ bool AWKeyCache::addKeyToCache(const QString type, const QString key)
|
|||||||
if (cachedValues.contains(device))
|
if (cachedValues.contains(device))
|
||||||
continue;
|
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(
|
cache.setValue(
|
||||||
QString("%1").arg(cache.allKeys().count(), 3, 10, QChar('0')),
|
QString("%1").arg(cache.allKeys().count(), 3, 10, QChar('0')),
|
||||||
device);
|
device);
|
||||||
@ -63,6 +64,7 @@ bool AWKeyCache::addKeyToCache(const QString type, const QString key)
|
|||||||
if (cachedValues.contains(device))
|
if (cachedValues.contains(device))
|
||||||
continue;
|
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(
|
cache.setValue(
|
||||||
QString("%1").arg(cache.allKeys().count(), 3, 10, QChar('0')),
|
QString("%1").arg(cache.allKeys().count(), 3, 10, QChar('0')),
|
||||||
device);
|
device);
|
||||||
|
@ -189,38 +189,57 @@ QString AWKeyOperations::infoByKey(QString key) const
|
|||||||
{
|
{
|
||||||
qCDebug(LOG_AW) << "Requested key" << key;
|
qCDebug(LOG_AW) << "Requested key" << key;
|
||||||
|
|
||||||
if (key.startsWith(QString("bar")))
|
QString stripped = key;
|
||||||
return graphicalItems->itemByTag(key, QString("bar"))->uniq();
|
stripped.remove(QRegExp(QString("\\d+")));
|
||||||
else if (key.startsWith(QString("custom")))
|
QString output;
|
||||||
return extScripts->itemByTag(key, QString("custom"))->uniq();
|
|
||||||
else if (key.contains(QRegExp(QString("^hdd[rw]"))))
|
if (key.startsWith(QString("bar"))) {
|
||||||
return QString("%1").arg(m_devices[QString(
|
AbstractExtItem *item = graphicalItems->itemByTag(key, stripped);
|
||||||
"disk")][key.remove(QRegExp(QString("hdd[rw]"))).toInt()]);
|
if (item)
|
||||||
else if (key.contains(QRegExp(
|
output = item->uniq();
|
||||||
QString("^hdd([0-9]|mb|gb|freemb|freegb|totmb|totgb)"))))
|
} else if (key.startsWith(QString("custom"))) {
|
||||||
return QString("%1").arg(m_devices[QString(
|
AbstractExtItem *item = extScripts->itemByTag(key, stripped);
|
||||||
"mount")][key
|
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(
|
.remove(QRegExp(QString(
|
||||||
"^hdd([0-9]|mb|gb|freemb|freegb|totmb|totgb)")))
|
"^hdd([0-9]|mb|gb|freemb|freegb|totmb|totgb)")))
|
||||||
.toInt()]);
|
.toInt()];
|
||||||
else if (key.startsWith(QString("hddtemp")))
|
} else if (key.startsWith(QString("hddtemp"))) {
|
||||||
return QString("%1").arg(
|
output
|
||||||
m_devices[QString("hdd")][key.remove(QString("hddtemp")).toInt()]);
|
= m_devices[QString("hdd")][key.remove(QString("hddtemp")).toInt()];
|
||||||
else if (key.contains(QRegExp(QString("^(down|up)[0-9]"))))
|
} else if (key.contains(QRegExp(QString("^(down|up)[0-9]")))) {
|
||||||
return QString("%1").arg(m_devices[QString(
|
output = m_devices[QString("net")]
|
||||||
"net")][key.remove(QRegExp(QString("^(down|up)"))).toInt()]);
|
[key.remove(QRegExp(QString("^(down|up)"))).toInt()];
|
||||||
else if (key.startsWith(QString("pkgcount")))
|
} else if (key.startsWith(QString("pkgcount"))) {
|
||||||
return extUpgrade->itemByTag(key, QString("pkgcount"))->uniq();
|
AbstractExtItem *item = extUpgrade->itemByTag(key, stripped);
|
||||||
else if (key.contains(QRegExp(QString("(^|perc)(ask|bid|price)(chg|)"))))
|
if (item)
|
||||||
return extQuotes->itemByTag(key, QString("ask"))->uniq();
|
output = item->uniq();
|
||||||
else if (key.contains(QRegExp(
|
} else if (key.contains(
|
||||||
QString("(weather|weatherId|humidity|pressure|temperature)"))))
|
QRegExp(QString("(^|perc)(ask|bid|price)(chg|)")))) {
|
||||||
return extWeather->itemByTag(key, QString("weather"))->uniq();
|
AbstractExtItem *item = extQuotes->itemByTag(key, stripped);
|
||||||
else if (key.startsWith(QString("temp")))
|
if (item)
|
||||||
return QString("%1").arg(
|
output = item->uniq();
|
||||||
m_devices[QString("temp")][key.remove(QString("temp")).toInt()]);
|
} else if (key.contains(QRegExp(QString(
|
||||||
|
"(weather|weatherId|humidity|pressure|temperature)")))) {
|
||||||
|
AbstractExtItem *item = extWeather->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)");
|
||||||
|
}
|
||||||
|
|
||||||
return QString("(none)");
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -323,6 +342,7 @@ void AWKeyOperations::reinitKeys()
|
|||||||
m_pattern = AWPatternFunctions::insertKeyCount(m_pattern, allKeys);
|
m_pattern = AWPatternFunctions::insertKeyCount(m_pattern, allKeys);
|
||||||
m_pattern = AWPatternFunctions::insertKeyNames(m_pattern, allKeys);
|
m_pattern = AWPatternFunctions::insertKeyNames(m_pattern, allKeys);
|
||||||
m_pattern = AWPatternFunctions::insertKeys(m_pattern, allKeys);
|
m_pattern = AWPatternFunctions::insertKeys(m_pattern, allKeys);
|
||||||
|
m_pattern = AWPatternFunctions::insertMacros(m_pattern);
|
||||||
// wrap templates
|
// wrap templates
|
||||||
m_pattern = AWPatternFunctions::expandTemplates(m_pattern);
|
m_pattern = AWPatternFunctions::expandTemplates(m_pattern);
|
||||||
|
|
||||||
|
@ -17,11 +17,11 @@
|
|||||||
|
|
||||||
#include "awkeys.h"
|
#include "awkeys.h"
|
||||||
|
|
||||||
#include <QtConcurrent/QtConcurrent>
|
|
||||||
#include <QJSEngine>
|
#include <QJSEngine>
|
||||||
#include <QRegExp>
|
#include <QRegExp>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <QtConcurrent/QtConcurrent>
|
||||||
|
|
||||||
#include "awdataaggregator.h"
|
#include "awdataaggregator.h"
|
||||||
#include "awdataengineaggregator.h"
|
#include "awdataengineaggregator.h"
|
||||||
@ -177,8 +177,10 @@ QString AWKeys::valueByKey(QString key) const
|
|||||||
{
|
{
|
||||||
qCDebug(LOG_AW) << "Requested value for key" << key;
|
qCDebug(LOG_AW) << "Requested value for key" << key;
|
||||||
|
|
||||||
key.remove(QRegExp(QString("^bar[0-9]{1,}")));
|
QString trueKey
|
||||||
return aggregator->formatter(values[key], key);
|
= key.startsWith(QString("bar")) ? keyOperator->infoByKey(key) : key;
|
||||||
|
|
||||||
|
return aggregator->formatter(values[trueKey], trueKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -204,10 +206,10 @@ 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
|
// append lists
|
||||||
m_foundBars
|
m_foundBars = AWPatternFunctions::findKeys(keyOperator->pattern(),
|
||||||
= AWPatternFunctions::findBars(keyOperator->pattern(), currentKeys);
|
currentKeys, true);
|
||||||
m_foundKeys
|
m_foundKeys = AWPatternFunctions::findKeys(keyOperator->pattern(),
|
||||||
= AWPatternFunctions::findKeys(keyOperator->pattern(), currentKeys);
|
currentKeys, false);
|
||||||
m_foundLambdas = AWPatternFunctions::findLambdas(keyOperator->pattern());
|
m_foundLambdas = AWPatternFunctions::findLambdas(keyOperator->pattern());
|
||||||
// generate list of required keys for bars
|
// generate list of required keys for bars
|
||||||
QStringList barKeys;
|
QStringList barKeys;
|
||||||
@ -215,7 +217,7 @@ void AWKeys::reinitKeys(const QStringList currentKeys)
|
|||||||
GraphicalItem *item = keyOperator->giByKey(bar);
|
GraphicalItem *item = keyOperator->giByKey(bar);
|
||||||
if (item->isCustom())
|
if (item->isCustom())
|
||||||
item->setUsedKeys(
|
item->setUsedKeys(
|
||||||
AWPatternFunctions::findKeys(item->bar(), currentKeys));
|
AWPatternFunctions::findKeys(item->bar(), currentKeys, false));
|
||||||
else
|
else
|
||||||
item->setUsedKeys(QStringList() << item->bar());
|
item->setUsedKeys(QStringList() << item->bar());
|
||||||
barKeys.append(item->usedKeys());
|
barKeys.append(item->usedKeys());
|
||||||
@ -234,8 +236,10 @@ void AWKeys::reinitKeys(const QStringList currentKeys)
|
|||||||
void AWKeys::updateTextData()
|
void AWKeys::updateTextData()
|
||||||
{
|
{
|
||||||
// do not do it in parallel to avoid race condition
|
// do not do it in parallel to avoid race condition
|
||||||
|
m_mutex.lock();
|
||||||
calculateValues();
|
calculateValues();
|
||||||
QString text = parsePattern(keyOperator->pattern());
|
QString text = parsePattern(keyOperator->pattern());
|
||||||
|
m_mutex.unlock();
|
||||||
|
|
||||||
emit(needTextToBeUpdated(text));
|
emit(needTextToBeUpdated(text));
|
||||||
emit(dataAggregator->updateData(values));
|
emit(dataAggregator->updateData(values));
|
||||||
|
@ -49,7 +49,7 @@ AWKeysAggregator::AWKeysAggregator(QObject *parent)
|
|||||||
m_formatter[QString("swaptotmb")] = FormatterType::MemMBFormat;
|
m_formatter[QString("swaptotmb")] = FormatterType::MemMBFormat;
|
||||||
m_formatter[QString("swaptotgb")] = FormatterType::MemGBFormat;
|
m_formatter[QString("swaptotgb")] = FormatterType::MemGBFormat;
|
||||||
|
|
||||||
m_customFormatters = new AWFormatterHelper(this);
|
m_customFormatters = new AWFormatterHelper(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -515,7 +515,7 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
|
|||||||
} else if (source.startsWith(QString("lmsensors/"))) {
|
} else if (source.startsWith(QString("lmsensors/"))) {
|
||||||
// temperature
|
// temperature
|
||||||
int index = m_devices[QString("temp")].indexOf(source);
|
int index = m_devices[QString("temp")].indexOf(source);
|
||||||
// FIXME on DE initialization there are no units key
|
// HACK on DE initialization there are no units key
|
||||||
if (units.isEmpty())
|
if (units.isEmpty())
|
||||||
return QStringList() << QString("temp%1").arg(index);
|
return QStringList() << QString("temp%1").arg(index);
|
||||||
if (index > -1) {
|
if (index > -1) {
|
||||||
|
@ -86,7 +86,8 @@ QString AWPatternFunctions::expandTemplates(QString code)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QVariantList AWPatternFunctions::findFunctionCalls(const QString function,
|
QList<AWPatternFunctions::AWFunction>
|
||||||
|
AWPatternFunctions::findFunctionCalls(const QString function,
|
||||||
const QString code)
|
const QString code)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_AW) << "Looking for function" << function << "in" << code;
|
qCDebug(LOG_AW) << "Looking for function" << function << "in" << code;
|
||||||
@ -95,23 +96,23 @@ QVariantList AWPatternFunctions::findFunctionCalls(const QString function,
|
|||||||
// $aw_function_name<some args here if any>{{function body}}
|
// $aw_function_name<some args here if any>{{function body}}
|
||||||
// * args should be always comma separated (e.g. commas are not supported
|
// * args should be always comma separated (e.g. commas are not supported
|
||||||
// in this field if they are not screened by $, i.e. '$,'
|
// in this field if they are not screened by $, i.e. '$,'
|
||||||
// * body depends on the function name, double brackets (i.e. {{ or }}) are
|
// * body depends on the function name, double brackets should be screened
|
||||||
// not supported
|
// by using $, e.g. ${
|
||||||
QRegularExpression regex(
|
QRegularExpression regex(
|
||||||
QString("\\$%1\\<(?<args>.*?)\\>\\{\\{(?<body>.*?)\\}\\}")
|
QString("\\$%1\\<(?<args>.*?)\\>\\{\\{(?<body>.*?)\\}\\}")
|
||||||
.arg(function));
|
.arg(function));
|
||||||
regex.setPatternOptions(QRegularExpression::DotMatchesEverythingOption);
|
regex.setPatternOptions(QRegularExpression::DotMatchesEverythingOption);
|
||||||
|
|
||||||
QVariantList foundFunctions;
|
QList<AWPatternFunctions::AWFunction> foundFunctions;
|
||||||
QRegularExpressionMatchIterator it = regex.globalMatch(code);
|
QRegularExpressionMatchIterator it = regex.globalMatch(code);
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
QRegularExpressionMatch match = it.next();
|
QRegularExpressionMatch match = it.next();
|
||||||
|
|
||||||
QVariantHash metadata;
|
AWPatternFunctions::AWFunction metadata;
|
||||||
// work with args
|
// work with args
|
||||||
QString argsString = match.captured(QString("args"));
|
QString argsString = match.captured(QString("args"));
|
||||||
if (argsString.isEmpty()) {
|
if (argsString.isEmpty()) {
|
||||||
metadata[QString("args")] = QStringList();
|
metadata.args = QStringList();
|
||||||
} else {
|
} else {
|
||||||
// replace '$,' to 0x1d
|
// replace '$,' to 0x1d
|
||||||
argsString.replace(QString("$,"), QString(0x1d));
|
argsString.replace(QString("$,"), QString(0x1d));
|
||||||
@ -119,11 +120,14 @@ QVariantList AWPatternFunctions::findFunctionCalls(const QString function,
|
|||||||
std::for_each(args.begin(), args.end(), [](QString &arg) {
|
std::for_each(args.begin(), args.end(), [](QString &arg) {
|
||||||
arg.replace(QString(0x1d), QString(","));
|
arg.replace(QString(0x1d), QString(","));
|
||||||
});
|
});
|
||||||
metadata[QString("args")] = args;
|
metadata.args = args;
|
||||||
}
|
}
|
||||||
// other variables
|
// other variables
|
||||||
metadata[QString("body")] = match.captured(QString("body"));
|
metadata.body = match.captured(QString("body"));
|
||||||
metadata[QString("what")] = match.captured();
|
metadata.what = match.captured();
|
||||||
|
// replace brackets
|
||||||
|
metadata.body.replace(QString("${"), QString("{"));
|
||||||
|
metadata.body.replace(QString("$}"), QString("}"));
|
||||||
foundFunctions.append(metadata);
|
foundFunctions.append(metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,22 +140,17 @@ QString AWPatternFunctions::insertAllKeys(QString code, const QStringList keys)
|
|||||||
qCDebug(LOG_AW) << "Looking for keys in code" << code << "using list"
|
qCDebug(LOG_AW) << "Looking for keys in code" << code << "using list"
|
||||||
<< keys;
|
<< keys;
|
||||||
|
|
||||||
QVariantList found
|
QList<AWPatternFunctions::AWFunction> found
|
||||||
= AWPatternFunctions::findFunctionCalls(QString("aw_all"), code);
|
= AWPatternFunctions::findFunctionCalls(QString("aw_all"), code);
|
||||||
for (auto function : found) {
|
for (auto function : found) {
|
||||||
QVariantHash metadata = function.toHash();
|
|
||||||
QString separator
|
QString separator
|
||||||
= metadata[QString("args")].toStringList().isEmpty()
|
= function.args.isEmpty() ? QString(",") : function.args.at(0);
|
||||||
? QString(",")
|
QStringList required = keys.filter(QRegExp(function.body));
|
||||||
: metadata[QString("args")].toStringList().at(0);
|
|
||||||
QStringList required
|
|
||||||
= keys.filter(QRegExp(metadata[QString("body")].toString()));
|
|
||||||
std::for_each(required.begin(), required.end(), [](QString &value) {
|
std::for_each(required.begin(), required.end(), [](QString &value) {
|
||||||
value = QString("%1: $%1").arg(value);
|
value = QString("%1: $%1").arg(value);
|
||||||
});
|
});
|
||||||
|
|
||||||
code.replace(metadata[QString("what")].toString(),
|
code.replace(function.what, required.join(separator));
|
||||||
required.join(separator));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
@ -163,15 +162,12 @@ QString AWPatternFunctions::insertKeyCount(QString code, const QStringList keys)
|
|||||||
qCDebug(LOG_AW) << "Looking for count in code" << code << "using list"
|
qCDebug(LOG_AW) << "Looking for count in code" << code << "using list"
|
||||||
<< keys;
|
<< keys;
|
||||||
|
|
||||||
QVariantList found
|
QList<AWPatternFunctions::AWFunction> found
|
||||||
= AWPatternFunctions::findFunctionCalls(QString("aw_count"), code);
|
= AWPatternFunctions::findFunctionCalls(QString("aw_count"), code);
|
||||||
for (auto function : found) {
|
for (auto function : found) {
|
||||||
QVariantHash metadata = function.toHash();
|
int count = keys.filter(QRegExp(function.body)).count();
|
||||||
int count = keys.filter(QRegExp(metadata[QString("body")].toString()))
|
|
||||||
.count();
|
|
||||||
|
|
||||||
code.replace(metadata[QString("what")].toString(),
|
code.replace(function.what, QString::number(count));
|
||||||
QString::number(count));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
@ -183,19 +179,14 @@ QString AWPatternFunctions::insertKeyNames(QString code, const QStringList keys)
|
|||||||
qCDebug(LOG_AW) << "Looking for key names in code" << code << "using list"
|
qCDebug(LOG_AW) << "Looking for key names in code" << code << "using list"
|
||||||
<< keys;
|
<< keys;
|
||||||
|
|
||||||
QVariantList found
|
QList<AWPatternFunctions::AWFunction> found
|
||||||
= AWPatternFunctions::findFunctionCalls(QString("aw_names"), code);
|
= AWPatternFunctions::findFunctionCalls(QString("aw_names"), code);
|
||||||
for (auto function : found) {
|
for (auto function : found) {
|
||||||
QVariantHash metadata = function.toHash();
|
|
||||||
QString separator
|
QString separator
|
||||||
= metadata[QString("args")].toStringList().isEmpty()
|
= function.args.isEmpty() ? QString(",") : function.args.at(0);
|
||||||
? QString(",")
|
QStringList required = keys.filter(QRegExp(function.body));
|
||||||
: metadata[QString("args")].toStringList().at(0);
|
|
||||||
QStringList required
|
|
||||||
= keys.filter(QRegExp(metadata[QString("body")].toString()));
|
|
||||||
|
|
||||||
code.replace(metadata[QString("what")].toString(),
|
code.replace(function.what, required.join(separator));
|
||||||
required.join(separator));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
@ -207,59 +198,80 @@ QString AWPatternFunctions::insertKeys(QString code, const QStringList keys)
|
|||||||
qCDebug(LOG_AW) << "Looking for keys in code" << code << "using list"
|
qCDebug(LOG_AW) << "Looking for keys in code" << code << "using list"
|
||||||
<< keys;
|
<< keys;
|
||||||
|
|
||||||
QVariantList found
|
QList<AWPatternFunctions::AWFunction> found
|
||||||
= AWPatternFunctions::findFunctionCalls(QString("aw_keys"), code);
|
= AWPatternFunctions::findFunctionCalls(QString("aw_keys"), code);
|
||||||
for (auto function : found) {
|
for (auto function : found) {
|
||||||
QVariantHash metadata = function.toHash();
|
|
||||||
QString separator
|
QString separator
|
||||||
= metadata[QString("args")].toStringList().isEmpty()
|
= function.args.isEmpty() ? QString(",") : function.args.at(0);
|
||||||
? QString(",")
|
QStringList required = keys.filter(QRegExp(function.body));
|
||||||
: metadata[QString("args")].toStringList().at(0);
|
|
||||||
QStringList required
|
|
||||||
= keys.filter(QRegExp(metadata[QString("body")].toString()));
|
|
||||||
std::for_each(required.begin(), required.end(), [](QString &value) {
|
std::for_each(required.begin(), required.end(), [](QString &value) {
|
||||||
value = QString("$%1").arg(value);
|
value = QString("$%1").arg(value);
|
||||||
});
|
});
|
||||||
|
|
||||||
code.replace(metadata[QString("what")].toString(),
|
code.replace(function.what, required.join(separator));
|
||||||
required.join(separator));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QStringList AWPatternFunctions::findBars(const QString code,
|
QString AWPatternFunctions::insertMacros(QString code)
|
||||||
const QStringList keys)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_AW) << "Looking for bars in code" << code << "using list"
|
qCDebug(LOG_AW) << "Looking for macros in code" << code;
|
||||||
<< keys;
|
|
||||||
|
|
||||||
QStringList selectedKeys;
|
QList<AWPatternFunctions::AWFunction> found
|
||||||
for (auto key : keys)
|
= AWPatternFunctions::findFunctionCalls(QString("aw_macro"), code);
|
||||||
if ((key.startsWith(QString("bar")))
|
for (auto macro : found) {
|
||||||
&& (code.contains(QString("$%1").arg(key)))) {
|
// get macro params
|
||||||
qCInfo(LOG_AW) << "Found bar" << key;
|
if (macro.args.isEmpty()) {
|
||||||
selectedKeys.append(key);
|
qCWarning(LOG_AW) << "No macro name found for" << macro.what;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
QString name = macro.args.takeFirst();
|
||||||
|
// find macro usage
|
||||||
|
QList<AWPatternFunctions::AWFunction> macroUsage
|
||||||
|
= AWPatternFunctions::findFunctionCalls(
|
||||||
|
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;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// generate body to replace
|
||||||
|
QString result = macro.body;
|
||||||
|
std::for_each(macro.args.cbegin(), macro.args.cend(),
|
||||||
|
[&result, macro, function](const QString &arg) {
|
||||||
|
int index = macro.args.indexOf(arg);
|
||||||
|
result.replace(QString("$%1").arg(arg),
|
||||||
|
function.args.at(index));
|
||||||
|
});
|
||||||
|
// do replace
|
||||||
|
code.replace(function.what, result);
|
||||||
}
|
}
|
||||||
if (selectedKeys.isEmpty())
|
|
||||||
qCWarning(LOG_AW) << "No bars found";
|
|
||||||
|
|
||||||
return selectedKeys;
|
// remove macro from source pattern
|
||||||
|
code.remove(macro.what);
|
||||||
|
}
|
||||||
|
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QStringList AWPatternFunctions::findKeys(const QString code,
|
QStringList AWPatternFunctions::findKeys(const QString code,
|
||||||
const QStringList keys)
|
const QStringList keys,
|
||||||
|
const bool isBars)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_AW) << "Looking for keys in code" << code << "using list"
|
qCDebug(LOG_AW) << "Looking for keys in code" << code << "using list"
|
||||||
<< keys;
|
<< keys;
|
||||||
|
|
||||||
QStringList selectedKeys;
|
QStringList selectedKeys;
|
||||||
for (auto key : keys)
|
for (auto key : keys)
|
||||||
if ((!key.startsWith(QString("bar")))
|
if ((key.startsWith(QString("bar")) == isBars)
|
||||||
&& (code.contains(QString("$%1").arg(key)))) {
|
&& (code.contains(QString("$%1").arg(key)))) {
|
||||||
qCInfo(LOG_AW) << "Found key" << key;
|
qCInfo(LOG_AW) << "Found key" << key << "with bar enabled"
|
||||||
|
<< isBars;
|
||||||
selectedKeys.append(key);
|
selectedKeys.append(key);
|
||||||
}
|
}
|
||||||
if (selectedKeys.isEmpty())
|
if (selectedKeys.isEmpty())
|
||||||
|
@ -27,19 +27,26 @@ class AWKeysAggregator;
|
|||||||
|
|
||||||
namespace AWPatternFunctions
|
namespace AWPatternFunctions
|
||||||
{
|
{
|
||||||
|
typedef struct {
|
||||||
|
QStringList args;
|
||||||
|
QString body;
|
||||||
|
QString what;
|
||||||
|
} AWFunction;
|
||||||
|
|
||||||
// insert methods
|
// insert methods
|
||||||
QString expandLambdas(QString code, AWKeysAggregator *aggregator,
|
QString expandLambdas(QString code, AWKeysAggregator *aggregator,
|
||||||
const QVariantHash &metadata,
|
const QVariantHash &metadata,
|
||||||
const QStringList &usedKeys);
|
const QStringList &usedKeys);
|
||||||
QString expandTemplates(QString code);
|
QString expandTemplates(QString code);
|
||||||
QVariantList findFunctionCalls(const QString function, const QString code);
|
QList<AWFunction> findFunctionCalls(const QString function, const QString code);
|
||||||
QString insertAllKeys(QString code, const QStringList keys);
|
QString insertAllKeys(QString code, const QStringList keys);
|
||||||
QString insertKeyCount(QString code, const QStringList keys);
|
QString insertKeyCount(QString code, const QStringList keys);
|
||||||
QString insertKeyNames(QString code, const QStringList keys);
|
QString insertKeyNames(QString code, const QStringList keys);
|
||||||
QString insertKeys(QString code, const QStringList keys);
|
QString insertKeys(QString code, const QStringList keys);
|
||||||
|
QString insertMacros(QString code);
|
||||||
// find methods
|
// find methods
|
||||||
QStringList findBars(const QString code, const QStringList keys);
|
QStringList findKeys(const QString code, const QStringList keys,
|
||||||
QStringList findKeys(const QString code, const QStringList keys);
|
const bool isBars);
|
||||||
QStringList findLambdas(const QString code);
|
QStringList findLambdas(const QString code);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,151 +0,0 @@
|
|||||||
/***************************************************************************
|
|
||||||
* This file is part of awesome-widgets *
|
|
||||||
* *
|
|
||||||
* awesome-widgets is free software: you can redistribute it and/or *
|
|
||||||
* modify it under the terms of the GNU General Public License as *
|
|
||||||
* published by the Free Software Foundation, either version 3 of the *
|
|
||||||
* License, or (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* awesome-widgets is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
||||||
* GNU General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU General Public License *
|
|
||||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
|
||||||
***************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
#include "awscriptformatter.h"
|
|
||||||
|
|
||||||
#include <QJSEngine>
|
|
||||||
#include <QSettings>
|
|
||||||
|
|
||||||
#include "awdebug.h"
|
|
||||||
|
|
||||||
|
|
||||||
AWScriptFormatter::AWScriptFormatter(QObject *parent, const QString filename,
|
|
||||||
const QString section)
|
|
||||||
: AWAbstractFormatter(parent, filename, section)
|
|
||||||
{
|
|
||||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
|
||||||
|
|
||||||
init(filename, section);
|
|
||||||
initProgram();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
AWScriptFormatter::AWScriptFormatter(QObject *parent, const bool appendCode,
|
|
||||||
const QString code, const bool hasReturn)
|
|
||||||
: AWAbstractFormatter(parent)
|
|
||||||
{
|
|
||||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
|
||||||
|
|
||||||
setAppendCode(appendCode);
|
|
||||||
setCode(code);
|
|
||||||
setHasReturn(hasReturn);
|
|
||||||
initProgram();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
AWScriptFormatter::~AWScriptFormatter()
|
|
||||||
{
|
|
||||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QString AWScriptFormatter::convert(const QVariant &value) const
|
|
||||||
{
|
|
||||||
qCDebug(LOG_AW) << "Convert value" << value;
|
|
||||||
|
|
||||||
// init engine
|
|
||||||
QJSEngine engine;
|
|
||||||
QJSValue fn = engine.evaluate(m_program);
|
|
||||||
QJSValueList args = QJSValueList() << value.toString();
|
|
||||||
QJSValue result = fn.call(args);
|
|
||||||
|
|
||||||
if (result.isError()) {
|
|
||||||
qCWarning(LOG_AW) << "Uncaught exception at line"
|
|
||||||
<< result.property("lineNumber").toInt() << ":"
|
|
||||||
<< result.toString();
|
|
||||||
return QString();
|
|
||||||
} else {
|
|
||||||
return result.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool AWScriptFormatter::appendCode() const
|
|
||||||
{
|
|
||||||
return m_appendCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QString AWScriptFormatter::code() const
|
|
||||||
{
|
|
||||||
return m_code;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool AWScriptFormatter::hasReturn() const
|
|
||||||
{
|
|
||||||
return m_hasReturn;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QString AWScriptFormatter::program() const
|
|
||||||
{
|
|
||||||
return m_program;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void AWScriptFormatter::setAppendCode(const bool _appendCode)
|
|
||||||
{
|
|
||||||
qCDebug(LOG_AW) << "Set append code" << _appendCode;
|
|
||||||
|
|
||||||
m_appendCode = _appendCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void AWScriptFormatter::setCode(const QString _code)
|
|
||||||
{
|
|
||||||
qCDebug(LOG_AW) << "Set code" << _code;
|
|
||||||
|
|
||||||
m_code = _code;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void AWScriptFormatter::setHasReturn(const bool _hasReturn)
|
|
||||||
{
|
|
||||||
qCDebug(LOG_AW) << "Set has return" << _hasReturn;
|
|
||||||
|
|
||||||
m_hasReturn = _hasReturn;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void AWScriptFormatter::init(const QString filename, const QString section)
|
|
||||||
{
|
|
||||||
qCDebug(LOG_AW) << "Looking for section" << section << "in" << filename;
|
|
||||||
|
|
||||||
QSettings settings(filename, QSettings::IniFormat);
|
|
||||||
|
|
||||||
settings.beginGroup(section);
|
|
||||||
setAppendCode(settings.value(QString("AppendCode"), true).toBool());
|
|
||||||
setCode(settings.value(QString("Code"), QString()).toString());
|
|
||||||
setHasReturn(settings.value(QString("HasReturn"), false).toBool());
|
|
||||||
settings.endGroup();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void AWScriptFormatter::initProgram()
|
|
||||||
{
|
|
||||||
if (m_appendCode)
|
|
||||||
m_program
|
|
||||||
= QString("(function(value) { %1%2 })")
|
|
||||||
.arg(m_code)
|
|
||||||
.arg(m_hasReturn ? QString("") : QString("; return output;"));
|
|
||||||
else
|
|
||||||
m_program = m_code;
|
|
||||||
|
|
||||||
qCInfo(LOG_AW) << "Create JS engine with code" << m_program;
|
|
||||||
}
|
|
@ -19,14 +19,14 @@
|
|||||||
|
|
||||||
#include <KI18n/KLocalizedString>
|
#include <KI18n/KLocalizedString>
|
||||||
|
|
||||||
#include <QtConcurrent/QtConcurrent>
|
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonParseError>
|
#include <QJsonParseError>
|
||||||
#include <QNetworkAccessManager>
|
#include <QNetworkAccessManager>
|
||||||
#include <QNetworkRequest>
|
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
|
#include <QNetworkRequest>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
|
#include <QtConcurrent/QtConcurrent>
|
||||||
|
|
||||||
#include "awdebug.h"
|
#include "awdebug.h"
|
||||||
|
|
||||||
|
@ -22,20 +22,17 @@
|
|||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
#include <QTime>
|
#include <QTime>
|
||||||
|
|
||||||
#include "awdebug.h"
|
|
||||||
#include "abstractextitemaggregator.h"
|
#include "abstractextitemaggregator.h"
|
||||||
|
#include "awdebug.h"
|
||||||
|
|
||||||
|
|
||||||
AbstractExtItem::AbstractExtItem(QWidget *parent, const QString desktopName,
|
AbstractExtItem::AbstractExtItem(QWidget *parent, const QString filePath)
|
||||||
const QStringList directories)
|
|
||||||
: QDialog(parent)
|
: QDialog(parent)
|
||||||
, m_fileName(desktopName)
|
, m_fileName(filePath)
|
||||||
, m_dirs(directories)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
qCDebug(LOG_LIB) << "Desktop name" << desktopName << "directories"
|
qCDebug(LOG_LIB) << "Desktop name" << filePath;
|
||||||
<< directories;
|
|
||||||
|
|
||||||
m_name = m_fileName;
|
m_name = m_fileName;
|
||||||
}
|
}
|
||||||
@ -47,13 +44,42 @@ AbstractExtItem::~AbstractExtItem()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AbstractExtItem::bumpApi(const int _newVer)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Bump API using new version" << _newVer;
|
||||||
|
|
||||||
|
// update for current API
|
||||||
|
if ((apiVersion() > 0) && (apiVersion() < _newVer)) {
|
||||||
|
qCWarning(LOG_LIB) << "Bump API version from" << apiVersion() << "to"
|
||||||
|
<< _newVer;
|
||||||
|
setApiVersion(_newVer);
|
||||||
|
writeConfiguration();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void AbstractExtItem::copyDefaults(AbstractExtItem *_other) const
|
void AbstractExtItem::copyDefaults(AbstractExtItem *_other) const
|
||||||
{
|
{
|
||||||
_other->setActive(m_active);
|
_other->setActive(isActive());
|
||||||
_other->setApiVersion(m_apiVersion);
|
_other->setApiVersion(apiVersion());
|
||||||
_other->setComment(m_comment);
|
_other->setComment(comment());
|
||||||
_other->setInterval(m_interval);
|
_other->setInterval(interval());
|
||||||
_other->setName(m_name);
|
_other->setName(name());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString AbstractExtItem::writtableConfig() const
|
||||||
|
{
|
||||||
|
QString path = m_fileName;
|
||||||
|
QString name = QFileInfo(path).fileName();
|
||||||
|
path.remove(path.count() - name.count() - 1, name.count() + 1);
|
||||||
|
QString dir = QFileInfo(path).fileName();
|
||||||
|
|
||||||
|
return QString("%1/awesomewidgets/%2/%3")
|
||||||
|
.arg(QStandardPaths::writableLocation(
|
||||||
|
QStandardPaths::GenericDataLocation))
|
||||||
|
.arg(dir)
|
||||||
|
.arg(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -69,12 +95,6 @@ QString AbstractExtItem::comment() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QStringList AbstractExtItem::directories() const
|
|
||||||
{
|
|
||||||
return m_dirs;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QString AbstractExtItem::fileName() const
|
QString AbstractExtItem::fileName() const
|
||||||
{
|
{
|
||||||
return m_fileName;
|
return m_fileName;
|
||||||
@ -109,7 +129,7 @@ QString AbstractExtItem::tag(const QString _type) const
|
|||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Tag type" << _type;
|
qCDebug(LOG_LIB) << "Tag type" << _type;
|
||||||
|
|
||||||
return QString("%1%2").arg(_type).arg(m_number);
|
return QString("%1%2").arg(_type).arg(number());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -158,73 +178,64 @@ void AbstractExtItem::setName(const QString _name)
|
|||||||
void AbstractExtItem::setNumber(int _number)
|
void AbstractExtItem::setNumber(int _number)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Number" << _number;
|
qCDebug(LOG_LIB) << "Number" << _number;
|
||||||
if (_number == -1)
|
bool generateNumber = (_number == -1);
|
||||||
|
if (generateNumber) {
|
||||||
_number = []() {
|
_number = []() {
|
||||||
qCWarning(LOG_LIB) << "Number is empty, generate new one";
|
qCWarning(LOG_LIB) << "Number is empty, generate new one";
|
||||||
qsrand(QTime::currentTime().msec());
|
// we suppose that currentTIme().msec() is always valid time
|
||||||
|
qsrand(static_cast<uint>(QTime::currentTime().msec()));
|
||||||
int n = qrand() % 1000;
|
int n = qrand() % 1000;
|
||||||
qCInfo(LOG_LIB) << "Generated number is" << n;
|
qCInfo(LOG_LIB) << "Generated number is" << n;
|
||||||
return n;
|
return n;
|
||||||
}();
|
}();
|
||||||
|
}
|
||||||
|
|
||||||
m_number = _number;
|
m_number = _number;
|
||||||
|
if (generateNumber)
|
||||||
|
writeConfiguration();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AbstractExtItem::readConfiguration()
|
void AbstractExtItem::readConfiguration()
|
||||||
{
|
{
|
||||||
for (int i = m_dirs.count() - 1; i >= 0; i--) {
|
QSettings settings(m_fileName, QSettings::IniFormat);
|
||||||
if (!QDir(m_dirs.at(i)).entryList(QDir::Files).contains(m_fileName))
|
|
||||||
continue;
|
|
||||||
QSettings settings(QString("%1/%2").arg(m_dirs.at(i)).arg(m_fileName),
|
|
||||||
QSettings::IniFormat);
|
|
||||||
|
|
||||||
settings.beginGroup(QString("Desktop Entry"));
|
settings.beginGroup(QString("Desktop Entry"));
|
||||||
setName(settings.value(QString("Name"), m_name).toString());
|
setName(settings.value(QString("Name"), name()).toString());
|
||||||
setComment(settings.value(QString("Comment"), m_comment).toString());
|
setComment(settings.value(QString("Comment"), comment()).toString());
|
||||||
setApiVersion(
|
setApiVersion(
|
||||||
settings.value(QString("X-AW-ApiVersion"), m_apiVersion).toInt());
|
settings.value(QString("X-AW-ApiVersion"), apiVersion()).toInt());
|
||||||
setActive(settings.value(QString("X-AW-Active"), QVariant(m_active))
|
setActive(
|
||||||
.toString()
|
settings.value(QString("X-AW-Active"), QVariant(isActive())).toString()
|
||||||
== QString("true"));
|
== QString("true"));
|
||||||
setInterval(
|
setInterval(settings.value(QString("X-AW-Interval"), interval()).toInt());
|
||||||
settings.value(QString("X-AW-Interval"), m_interval).toInt());
|
setNumber(settings.value(QString("X-AW-Number"), number()).toInt());
|
||||||
setNumber(settings.value(QString("X-AW-Number"), m_number).toInt());
|
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool AbstractExtItem::tryDelete() const
|
bool AbstractExtItem::tryDelete() const
|
||||||
{
|
{
|
||||||
for (auto dir : m_dirs) {
|
bool status = QFile::remove(m_fileName);
|
||||||
bool status = QFile::remove(QString("%1/%2").arg(dir).arg(m_fileName));
|
qCInfo(LOG_LIB) << "Remove file" << m_fileName << status;
|
||||||
qCInfo(LOG_LIB) << "Remove file"
|
|
||||||
<< QString("%1/%2").arg(dir).arg(m_fileName) << status;
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if exists
|
return status;
|
||||||
for (auto dir : m_dirs)
|
|
||||||
if (QFile::exists(QString("%1/%2").arg(dir).arg(m_fileName)))
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AbstractExtItem::writeConfiguration() const
|
void AbstractExtItem::writeConfiguration() const
|
||||||
{
|
{
|
||||||
QSettings settings(QString("%1/%2").arg(m_dirs.first()).arg(m_fileName),
|
QSettings settings(writtableConfig(), QSettings::IniFormat);
|
||||||
QSettings::IniFormat);
|
|
||||||
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
|
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
|
||||||
|
|
||||||
settings.beginGroup(QString("Desktop Entry"));
|
settings.beginGroup(QString("Desktop Entry"));
|
||||||
settings.setValue(QString("Encoding"), QString("UTF-8"));
|
settings.setValue(QString("Encoding"), QString("UTF-8"));
|
||||||
settings.setValue(QString("Name"), m_name);
|
settings.setValue(QString("Name"), name());
|
||||||
settings.setValue(QString("Comment"), m_comment);
|
settings.setValue(QString("Comment"), comment());
|
||||||
settings.setValue(QString("X-AW-ApiVersion"), m_apiVersion);
|
settings.setValue(QString("X-AW-ApiVersion"), apiVersion());
|
||||||
settings.setValue(QString("X-AW-Active"), QVariant(m_active).toString());
|
settings.setValue(QString("X-AW-Active"), QVariant(isActive()).toString());
|
||||||
settings.setValue(QString("X-AW-Interval"), m_interval);
|
settings.setValue(QString("X-AW-Interval"), interval());
|
||||||
settings.setValue(QString("X-AW-Number"), m_number);
|
settings.setValue(QString("X-AW-Number"), number());
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
|
||||||
settings.sync();
|
settings.sync();
|
||||||
|
@ -28,7 +28,6 @@ class AbstractExtItem : public QDialog
|
|||||||
Q_PROPERTY(bool active READ isActive WRITE setActive)
|
Q_PROPERTY(bool active READ isActive WRITE setActive)
|
||||||
Q_PROPERTY(int apiVersion READ apiVersion WRITE setApiVersion)
|
Q_PROPERTY(int apiVersion READ apiVersion WRITE setApiVersion)
|
||||||
Q_PROPERTY(QString comment READ comment WRITE setComment)
|
Q_PROPERTY(QString comment READ comment WRITE setComment)
|
||||||
Q_PROPERTY(QStringList directories READ directories)
|
|
||||||
Q_PROPERTY(QString fileName READ fileName)
|
Q_PROPERTY(QString fileName READ fileName)
|
||||||
Q_PROPERTY(int interval READ interval WRITE setInterval)
|
Q_PROPERTY(int interval READ interval WRITE setInterval)
|
||||||
Q_PROPERTY(QString name READ name WRITE setName)
|
Q_PROPERTY(QString name READ name WRITE setName)
|
||||||
@ -36,17 +35,17 @@ class AbstractExtItem : public QDialog
|
|||||||
Q_PROPERTY(QString uniq READ uniq)
|
Q_PROPERTY(QString uniq READ uniq)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit AbstractExtItem(QWidget *parent = nullptr,
|
explicit AbstractExtItem(QWidget *parent,
|
||||||
const QString desktopName = QString(),
|
const QString filePath = QString());
|
||||||
const QStringList directories = QStringList());
|
|
||||||
virtual ~AbstractExtItem();
|
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;
|
= 0;
|
||||||
void copyDefaults(AbstractExtItem *_other) const;
|
virtual void copyDefaults(AbstractExtItem *_other) const;
|
||||||
|
QString writtableConfig() const;
|
||||||
// get methods
|
// get methods
|
||||||
int apiVersion() const;
|
int apiVersion() const;
|
||||||
QString comment() const;
|
QString comment() const;
|
||||||
QStringList directories() const;
|
|
||||||
QString fileName() const;
|
QString fileName() const;
|
||||||
int interval() const;
|
int interval() const;
|
||||||
bool isActive() const;
|
bool isActive() const;
|
||||||
@ -62,6 +61,9 @@ public:
|
|||||||
void setName(const QString _name = QString("none"));
|
void setName(const QString _name = QString("none"));
|
||||||
void setNumber(int _number = -1);
|
void setNumber(int _number = -1);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void dataReceived(const QVariantHash &data);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
virtual void readConfiguration();
|
virtual void readConfiguration();
|
||||||
virtual QVariantHash run() = 0;
|
virtual QVariantHash run() = 0;
|
||||||
@ -70,8 +72,7 @@ public slots:
|
|||||||
virtual void writeConfiguration() const;
|
virtual void writeConfiguration() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_fileName;
|
QString m_fileName = QString("/dev/null");
|
||||||
QStringList m_dirs;
|
|
||||||
virtual void translate() = 0;
|
virtual void translate() = 0;
|
||||||
// properties
|
// properties
|
||||||
int m_apiVersion = 0;
|
int m_apiVersion = 0;
|
||||||
|
@ -16,40 +16,35 @@
|
|||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
#include "abstractextitemaggregator.h"
|
#include "abstractextitemaggregator.h"
|
||||||
|
#include "ui_abstractextitemaggregator.h"
|
||||||
|
|
||||||
#include <KI18n/KLocalizedString>
|
#include <KI18n/KLocalizedString>
|
||||||
|
|
||||||
#include <QHBoxLayout>
|
#include <QFileInfo>
|
||||||
#include <QInputDialog>
|
#include <QInputDialog>
|
||||||
#include <QLineEdit>
|
#include <QPushButton>
|
||||||
|
|
||||||
#include "awdebug.h"
|
|
||||||
|
|
||||||
|
|
||||||
AbstractExtItemAggregator::AbstractExtItemAggregator(QWidget *parent)
|
AbstractExtItemAggregator::AbstractExtItemAggregator(QWidget *parent,
|
||||||
: QWidget(parent)
|
const QString type)
|
||||||
|
: QDialog(parent)
|
||||||
|
, ui(new Ui::AbstractExtItemAggregator)
|
||||||
|
, m_type(type)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
dialog = new QDialog(this);
|
ui->setupUi(this);
|
||||||
widgetDialog = new QListWidget(dialog);
|
|
||||||
dialogButtons = new QDialogButtonBox(
|
|
||||||
QDialogButtonBox::Open | QDialogButtonBox::Close, Qt::Vertical, dialog);
|
|
||||||
copyButton
|
copyButton
|
||||||
= dialogButtons->addButton(i18n("Copy"), QDialogButtonBox::ActionRole);
|
= ui->buttonBox->addButton(i18n("Copy"), QDialogButtonBox::ActionRole);
|
||||||
createButton = dialogButtons->addButton(i18n("Create"),
|
createButton = ui->buttonBox->addButton(i18n("Create"),
|
||||||
QDialogButtonBox::ActionRole);
|
QDialogButtonBox::ActionRole);
|
||||||
deleteButton = dialogButtons->addButton(i18n("Remove"),
|
deleteButton = ui->buttonBox->addButton(i18n("Remove"),
|
||||||
QDialogButtonBox::ActionRole);
|
QDialogButtonBox::ActionRole);
|
||||||
QHBoxLayout *layout = new QHBoxLayout(dialog);
|
|
||||||
layout->addWidget(widgetDialog);
|
|
||||||
layout->addWidget(dialogButtons);
|
|
||||||
dialog->setLayout(layout);
|
|
||||||
|
|
||||||
connect(dialogButtons, SIGNAL(clicked(QAbstractButton *)), this,
|
connect(ui->buttonBox, SIGNAL(clicked(QAbstractButton *)), this,
|
||||||
SLOT(editItemButtonPressed(QAbstractButton *)));
|
SLOT(editItemButtonPressed(QAbstractButton *)));
|
||||||
connect(dialogButtons, SIGNAL(rejected()), dialog, SLOT(reject()));
|
connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
||||||
connect(widgetDialog, SIGNAL(itemActivated(QListWidgetItem *)), this,
|
connect(ui->listWidget, SIGNAL(itemActivated(QListWidgetItem *)), this,
|
||||||
SLOT(editItemActivated(QListWidgetItem *)));
|
SLOT(editItemActivated(QListWidgetItem *)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,7 +53,60 @@ AbstractExtItemAggregator::~AbstractExtItemAggregator()
|
|||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
delete dialog;
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AbstractExtItemAggregator::copyItem()
|
||||||
|
{
|
||||||
|
AbstractExtItem *source = itemFromWidget();
|
||||||
|
QString fileName = getName();
|
||||||
|
int number = uniqNumber();
|
||||||
|
QString dir = QString("%1/awesomewidgets/%2")
|
||||||
|
.arg(QStandardPaths::writableLocation(
|
||||||
|
QStandardPaths::GenericDataLocation))
|
||||||
|
.arg(m_type);
|
||||||
|
if ((!source) || (fileName.isEmpty())) {
|
||||||
|
qCWarning(LOG_LIB) << "Nothing to copy";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
QString filePath = QString("%1/%2").arg(dir).arg(fileName);
|
||||||
|
|
||||||
|
AbstractExtItem *newItem = source->copy(filePath, number);
|
||||||
|
if (newItem->showConfiguration(configArgs()) == 1) {
|
||||||
|
initItems();
|
||||||
|
repaintList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AbstractExtItemAggregator::deleteItem()
|
||||||
|
{
|
||||||
|
AbstractExtItem *source = itemFromWidget();
|
||||||
|
if (!source) {
|
||||||
|
qCWarning(LOG_LIB) << "Nothing to delete";
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (source->tryDelete()) {
|
||||||
|
initItems();
|
||||||
|
repaintList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AbstractExtItemAggregator::editItem()
|
||||||
|
{
|
||||||
|
AbstractExtItem *source = itemFromWidget();
|
||||||
|
if (!source) {
|
||||||
|
qCWarning(LOG_LIB) << "Nothing to edit";
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (source->showConfiguration(configArgs()) == 1) {
|
||||||
|
initItems();
|
||||||
|
repaintList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -77,12 +125,69 @@ QString AbstractExtItemAggregator::getName()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
AbstractExtItem *AbstractExtItemAggregator::itemFromWidget()
|
||||||
|
{
|
||||||
|
QListWidgetItem *widgetItem = ui->listWidget->currentItem();
|
||||||
|
if (!widgetItem)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
AbstractExtItem *found = nullptr;
|
||||||
|
for (auto item : items()) {
|
||||||
|
QString fileName = QFileInfo(item->fileName()).fileName();
|
||||||
|
if (fileName != widgetItem->text())
|
||||||
|
continue;
|
||||||
|
found = item;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!found)
|
||||||
|
qCWarning(LOG_LIB) << "Could not find item by name"
|
||||||
|
<< widgetItem->text();
|
||||||
|
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AbstractExtItemAggregator::repaintList()
|
||||||
|
{
|
||||||
|
ui->listWidget->clear();
|
||||||
|
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')));
|
||||||
|
ui->listWidget->addItem(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int AbstractExtItemAggregator::uniqNumber() const
|
||||||
|
{
|
||||||
|
QList<int> tagList;
|
||||||
|
for (auto item : items())
|
||||||
|
tagList.append(item->number());
|
||||||
|
int number = 0;
|
||||||
|
while (tagList.contains(number))
|
||||||
|
number++;
|
||||||
|
|
||||||
|
return number;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QVariant AbstractExtItemAggregator::configArgs() const
|
QVariant AbstractExtItemAggregator::configArgs() const
|
||||||
{
|
{
|
||||||
return m_configArgs;
|
return m_configArgs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString AbstractExtItemAggregator::type() const
|
||||||
|
{
|
||||||
|
return m_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void AbstractExtItemAggregator::setConfigArgs(const QVariant _configArgs)
|
void AbstractExtItemAggregator::setConfigArgs(const QVariant _configArgs)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Configuration arguments" << _configArgs;
|
qCDebug(LOG_LIB) << "Configuration arguments" << _configArgs;
|
||||||
@ -102,9 +207,9 @@ void AbstractExtItemAggregator::editItemButtonPressed(QAbstractButton *button)
|
|||||||
if (static_cast<QPushButton *>(button) == copyButton)
|
if (static_cast<QPushButton *>(button) == copyButton)
|
||||||
return copyItem();
|
return copyItem();
|
||||||
else if (static_cast<QPushButton *>(button) == createButton)
|
else if (static_cast<QPushButton *>(button) == createButton)
|
||||||
return createItem();
|
return doCreateItem();
|
||||||
else if (static_cast<QPushButton *>(button) == deleteButton)
|
else if (static_cast<QPushButton *>(button) == deleteButton)
|
||||||
return deleteItem();
|
return deleteItem();
|
||||||
else if (dialogButtons->buttonRole(button) == QDialogButtonBox::AcceptRole)
|
else if (ui->buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole)
|
||||||
return editItem();
|
return editItem();
|
||||||
}
|
}
|
||||||
|
@ -19,31 +19,61 @@
|
|||||||
#define ABSTRACTEXTITEMAGGREGATOR_H
|
#define ABSTRACTEXTITEMAGGREGATOR_H
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include <QDialogButtonBox>
|
#include <QStandardPaths>
|
||||||
#include <QListWidget>
|
|
||||||
#include <QPushButton>
|
#include "abstractextitem.h"
|
||||||
#include <QWidget>
|
#include "awdebug.h"
|
||||||
|
|
||||||
|
|
||||||
// additional class since QObject macro does not allow class templates
|
class QAbstractButton;
|
||||||
class AbstractExtItemAggregator : public QWidget
|
class QListWidgetItem;
|
||||||
|
namespace Ui
|
||||||
|
{
|
||||||
|
class AbstractExtItemAggregator;
|
||||||
|
}
|
||||||
|
|
||||||
|
class AbstractExtItemAggregator : public QDialog
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QVariant configArgs READ configArgs WRITE setConfigArgs)
|
Q_PROPERTY(QVariant configArgs READ configArgs WRITE setConfigArgs)
|
||||||
|
Q_PROPERTY(QVariant type READ type)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit AbstractExtItemAggregator(QWidget *parent = nullptr);
|
explicit AbstractExtItemAggregator(QWidget *parent, const QString type);
|
||||||
virtual ~AbstractExtItemAggregator();
|
virtual ~AbstractExtItemAggregator();
|
||||||
|
// methods
|
||||||
|
void copyItem();
|
||||||
|
template <class T> void createItem()
|
||||||
|
{
|
||||||
|
QString fileName = getName();
|
||||||
|
int number = uniqNumber();
|
||||||
|
QString dir = QString("%1/awesomewidgets/%2")
|
||||||
|
.arg(QStandardPaths::writableLocation(
|
||||||
|
QStandardPaths::GenericDataLocation))
|
||||||
|
.arg(m_type);
|
||||||
|
if (fileName.isEmpty()) {
|
||||||
|
qCWarning(LOG_LIB) << "Nothing to create";
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
QString filePath = QString("%1/%2").arg(dir).arg(fileName);
|
||||||
|
|
||||||
|
T *newItem = new T(this, filePath);
|
||||||
|
newItem->setNumber(number);
|
||||||
|
if (newItem->showConfiguration(configArgs()) == 1) {
|
||||||
|
initItems();
|
||||||
|
repaintList();
|
||||||
|
};
|
||||||
|
};
|
||||||
|
void deleteItem();
|
||||||
|
void editItem();
|
||||||
QString getName();
|
QString getName();
|
||||||
// ui
|
AbstractExtItem *itemFromWidget();
|
||||||
QDialog *dialog = nullptr;
|
void repaintList();
|
||||||
QListWidget *widgetDialog = nullptr;
|
int uniqNumber() const;
|
||||||
QDialogButtonBox *dialogButtons = nullptr;
|
|
||||||
QPushButton *copyButton = nullptr;
|
|
||||||
QPushButton *createButton = nullptr;
|
|
||||||
QPushButton *deleteButton = nullptr;
|
|
||||||
// get methods
|
// get methods
|
||||||
QVariant configArgs() const;
|
QVariant configArgs() const;
|
||||||
|
virtual QList<AbstractExtItem *> items() const = 0;
|
||||||
|
QString type() const;
|
||||||
// set methods
|
// set methods
|
||||||
void setConfigArgs(const QVariant _configArgs);
|
void setConfigArgs(const QVariant _configArgs);
|
||||||
|
|
||||||
@ -52,12 +82,17 @@ private slots:
|
|||||||
void editItemButtonPressed(QAbstractButton *button);
|
void editItemButtonPressed(QAbstractButton *button);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// ui
|
||||||
|
Ui::AbstractExtItemAggregator *ui = nullptr;
|
||||||
|
QPushButton *copyButton = nullptr;
|
||||||
|
QPushButton *createButton = nullptr;
|
||||||
|
QPushButton *deleteButton = nullptr;
|
||||||
|
// properties
|
||||||
QVariant m_configArgs;
|
QVariant m_configArgs;
|
||||||
// methods
|
QString m_type;
|
||||||
virtual void copyItem() = 0;
|
// ui methods
|
||||||
virtual void createItem() = 0;
|
virtual void doCreateItem() = 0;
|
||||||
virtual void deleteItem() = 0;
|
virtual void initItems() = 0;
|
||||||
virtual void editItem() = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
64
sources/awesomewidgets/abstractextitemaggregator.ui
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>AbstractExtItemAggregator</class>
|
||||||
|
<widget class="QDialog" name="AbstractExtItemAggregator">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>400</width>
|
||||||
|
<height>300</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QListWidget" name="listWidget"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
<property name="standardButtons">
|
||||||
|
<set>QDialogButtonBox::Close|QDialogButtonBox::Open</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>accepted()</signal>
|
||||||
|
<receiver>AbstractExtItemAggregator</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>AbstractExtItemAggregator</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>
|
47
sources/awesomewidgets/abstractweatherprovider.h
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* 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 ABSTRACTWEATHERPROVIDER_H
|
||||||
|
#define ABSTRACTWEATHERPROVIDER_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QUrl>
|
||||||
|
|
||||||
|
|
||||||
|
class AbstractWeatherProvider : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(int number READ number)
|
||||||
|
|
||||||
|
public:
|
||||||
|
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)
|
||||||
|
= 0;
|
||||||
|
virtual QVariantHash parse(const QVariantMap &json) const = 0;
|
||||||
|
virtual QUrl url() const = 0;
|
||||||
|
int number() const { return m_number; };
|
||||||
|
|
||||||
|
private:
|
||||||
|
int m_number;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* ABSTRACTWEATHERPROVIDER_H */
|
139
sources/awesomewidgets/awabstractformatter.cpp
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* 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 "awabstractformatter.h"
|
||||||
|
|
||||||
|
#include <QSettings>
|
||||||
|
|
||||||
|
#include "awdebug.h"
|
||||||
|
|
||||||
|
|
||||||
|
AWAbstractFormatter::AWAbstractFormatter(QWidget *parent,
|
||||||
|
const QString filePath)
|
||||||
|
: AbstractExtItem(parent, filePath)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
AWAbstractFormatter::~AWAbstractFormatter()
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWAbstractFormatter::copyDefaults(AbstractExtItem *_other) const
|
||||||
|
{
|
||||||
|
AbstractExtItem::copyDefaults(_other);
|
||||||
|
|
||||||
|
static_cast<AWAbstractFormatter *>(_other)->setType(type());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString AWAbstractFormatter::uniq() const
|
||||||
|
{
|
||||||
|
return QString("%1(%2)").arg(name()).arg(strType());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString AWAbstractFormatter::strType() const
|
||||||
|
{
|
||||||
|
QString value;
|
||||||
|
switch (m_type) {
|
||||||
|
case FormatterClass::DateTime:
|
||||||
|
value = QString("DateTime");
|
||||||
|
break;
|
||||||
|
case FormatterClass::Float:
|
||||||
|
value = QString("Float");
|
||||||
|
break;
|
||||||
|
case FormatterClass::List:
|
||||||
|
value = QString("List");
|
||||||
|
break;
|
||||||
|
case FormatterClass::Script:
|
||||||
|
value = QString("Script");
|
||||||
|
break;
|
||||||
|
case FormatterClass::String:
|
||||||
|
value = QString("String");
|
||||||
|
break;
|
||||||
|
case FormatterClass::NoFormat:
|
||||||
|
value = QString("NoFormat");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
AWAbstractFormatter::FormatterClass AWAbstractFormatter::type() const
|
||||||
|
{
|
||||||
|
return m_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWAbstractFormatter::setStrType(const QString _type)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Type" << _type;
|
||||||
|
|
||||||
|
if (_type == QString("DateTime"))
|
||||||
|
m_type = FormatterClass::DateTime;
|
||||||
|
else if (_type == QString("Float"))
|
||||||
|
m_type = FormatterClass::Float;
|
||||||
|
else if (_type == QString("List"))
|
||||||
|
m_type = FormatterClass::List;
|
||||||
|
else if (_type == QString("Script"))
|
||||||
|
m_type = FormatterClass::Script;
|
||||||
|
else if (_type == QString("String"))
|
||||||
|
m_type = FormatterClass::String;
|
||||||
|
else
|
||||||
|
m_type = FormatterClass::NoFormat;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWAbstractFormatter::setType(
|
||||||
|
const AWAbstractFormatter::FormatterClass _type)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Type" << static_cast<int>(_type);
|
||||||
|
|
||||||
|
m_type = _type;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWAbstractFormatter::readConfiguration()
|
||||||
|
{
|
||||||
|
AbstractExtItem::readConfiguration();
|
||||||
|
|
||||||
|
QSettings settings(fileName(), QSettings::IniFormat);
|
||||||
|
|
||||||
|
settings.beginGroup(QString("Desktop Entry"));
|
||||||
|
setStrType(settings.value(QString("X-AW-Type"), strType()).toString());
|
||||||
|
settings.endGroup();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWAbstractFormatter::writeConfiguration() const
|
||||||
|
{
|
||||||
|
AbstractExtItem::writeConfiguration();
|
||||||
|
|
||||||
|
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.endGroup();
|
||||||
|
|
||||||
|
settings.sync();
|
||||||
|
}
|
63
sources/awesomewidgets/awabstractformatter.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 AWABSTRACTFORMATTER_H
|
||||||
|
#define AWABSTRACTFORMATTER_H
|
||||||
|
|
||||||
|
#include "abstractextitem.h"
|
||||||
|
|
||||||
|
|
||||||
|
class AWAbstractFormatter : public AbstractExtItem
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(FormatterClass type READ type WRITE setType)
|
||||||
|
Q_PROPERTY(QString strType READ strType WRITE setStrType)
|
||||||
|
|
||||||
|
public:
|
||||||
|
enum class FormatterClass {
|
||||||
|
DateTime,
|
||||||
|
Float,
|
||||||
|
List,
|
||||||
|
Script,
|
||||||
|
String,
|
||||||
|
NoFormat
|
||||||
|
};
|
||||||
|
|
||||||
|
explicit AWAbstractFormatter(QWidget *parent,
|
||||||
|
const QString filePath = QString());
|
||||||
|
virtual ~AWAbstractFormatter();
|
||||||
|
virtual QString convert(const QVariant &_value) const = 0;
|
||||||
|
void copyDefaults(AbstractExtItem *_other) const;
|
||||||
|
QString uniq() const;
|
||||||
|
// properties
|
||||||
|
QString strType() const;
|
||||||
|
FormatterClass type() const;
|
||||||
|
void setStrType(const QString type);
|
||||||
|
void setType(const FormatterClass _type = FormatterClass::NoFormat);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
virtual void readConfiguration();
|
||||||
|
QVariantHash run() { return QVariantHash(); };
|
||||||
|
virtual void writeConfiguration() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
// properties
|
||||||
|
FormatterClass m_type = FormatterClass::NoFormat;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* AWABSTRACTFORMATTER_H */
|
147
sources/awesomewidgets/awdatetimeformatter.cpp
Normal file
@ -0,0 +1,147 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* 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 "awdatetimeformatter.h"
|
||||||
|
#include "ui_awdatetimeformatter.h"
|
||||||
|
|
||||||
|
#include <KI18n/KLocalizedString>
|
||||||
|
|
||||||
|
#include <QDateTime>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QSettings>
|
||||||
|
|
||||||
|
#include "awdebug.h"
|
||||||
|
|
||||||
|
|
||||||
|
AWDateTimeFormatter::AWDateTimeFormatter(QWidget *parent,
|
||||||
|
const QString filePath)
|
||||||
|
: AWAbstractFormatter(parent, filePath)
|
||||||
|
, ui(new Ui::AWDateTimeFormatter)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
|
if (!filePath.isEmpty())
|
||||||
|
readConfiguration();
|
||||||
|
ui->setupUi(this);
|
||||||
|
translate();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
AWDateTimeFormatter::~AWDateTimeFormatter()
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString AWDateTimeFormatter::convert(const QVariant &_value) const
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Convert value" << _value;
|
||||||
|
|
||||||
|
return _value.toDateTime().toString(m_format);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
AWDateTimeFormatter *AWDateTimeFormatter::copy(const QString _fileName,
|
||||||
|
const int _number)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
||||||
|
|
||||||
|
AWDateTimeFormatter *item
|
||||||
|
= new AWDateTimeFormatter(static_cast<QWidget *>(parent()), _fileName);
|
||||||
|
AWAbstractFormatter::copyDefaults(item);
|
||||||
|
item->setFormat(format());
|
||||||
|
item->setNumber(_number);
|
||||||
|
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString AWDateTimeFormatter::format() const
|
||||||
|
{
|
||||||
|
return m_format;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWDateTimeFormatter::setFormat(const QString _format)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Set format" << _format;
|
||||||
|
|
||||||
|
m_format = _format;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWDateTimeFormatter::readConfiguration()
|
||||||
|
{
|
||||||
|
AWAbstractFormatter::readConfiguration();
|
||||||
|
|
||||||
|
QSettings settings(fileName(), QSettings::IniFormat);
|
||||||
|
|
||||||
|
settings.beginGroup(QString("Desktop Entry"));
|
||||||
|
setFormat(settings.value(QString("X-AW-Format"), format()).toString());
|
||||||
|
settings.endGroup();
|
||||||
|
|
||||||
|
bumpApi(AWEFAPI);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int AWDateTimeFormatter::showConfiguration(const QVariant args)
|
||||||
|
{
|
||||||
|
Q_UNUSED(args)
|
||||||
|
|
||||||
|
ui->lineEdit_name->setText(name());
|
||||||
|
ui->lineEdit_comment->setText(comment());
|
||||||
|
ui->label_typeValue->setText(QString("DateTime"));
|
||||||
|
ui->lineEdit_format->setText(format());
|
||||||
|
|
||||||
|
int ret = exec();
|
||||||
|
if (ret != 1)
|
||||||
|
return ret;
|
||||||
|
setName(ui->lineEdit_name->text());
|
||||||
|
setComment(ui->lineEdit_comment->text());
|
||||||
|
setStrType(ui->label_typeValue->text());
|
||||||
|
setFormat(ui->lineEdit_format->text());
|
||||||
|
|
||||||
|
writeConfiguration();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWDateTimeFormatter::writeConfiguration() const
|
||||||
|
{
|
||||||
|
AWAbstractFormatter::writeConfiguration();
|
||||||
|
|
||||||
|
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.endGroup();
|
||||||
|
|
||||||
|
settings.sync();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWDateTimeFormatter::translate()
|
||||||
|
{
|
||||||
|
ui->label_name->setText(i18n("Name"));
|
||||||
|
ui->label_comment->setText(i18n("Comment"));
|
||||||
|
ui->label_type->setText(i18n("Type"));
|
||||||
|
ui->label_format->setText(i18n("Format"));
|
||||||
|
}
|
@ -21,25 +21,36 @@
|
|||||||
#include "awabstractformatter.h"
|
#include "awabstractformatter.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Ui
|
||||||
|
{
|
||||||
|
class AWDateTimeFormatter;
|
||||||
|
}
|
||||||
|
|
||||||
class AWDateTimeFormatter : public AWAbstractFormatter
|
class AWDateTimeFormatter : public AWAbstractFormatter
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QString format READ format WRITE setFormat)
|
Q_PROPERTY(QString format READ format WRITE setFormat)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit AWDateTimeFormatter(QObject *parent, const QString filename,
|
explicit AWDateTimeFormatter(QWidget *parent,
|
||||||
const QString section);
|
const QString filePath = QString());
|
||||||
explicit AWDateTimeFormatter(QObject *parent, const QString format);
|
|
||||||
virtual ~AWDateTimeFormatter();
|
virtual ~AWDateTimeFormatter();
|
||||||
QString convert(const QVariant &value) const;
|
QString convert(const QVariant &_value) const;
|
||||||
|
AWDateTimeFormatter *copy(const QString _fileName, const int _number);
|
||||||
// properties
|
// properties
|
||||||
QString format() const;
|
QString format() const;
|
||||||
void setFormat(const QString _format);
|
void setFormat(const QString _format);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void readConfiguration();
|
||||||
|
int showConfiguration(const QVariant args = QVariant());
|
||||||
|
void writeConfiguration() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void init(const QString filename, const QString section);
|
Ui::AWDateTimeFormatter *ui = nullptr;
|
||||||
|
void translate();
|
||||||
// properties
|
// properties
|
||||||
QString m_format;
|
QString m_format = QString();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
167
sources/awesomewidgets/awdatetimeformatter.ui
Normal file
@ -0,0 +1,167 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>AWDateTimeFormatter</class>
|
||||||
|
<widget class="QDialog" name="AWDateTimeFormatter">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>420</width>
|
||||||
|
<height>157</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_format">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_format">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Format</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="lineEdit_format"/>
|
||||||
|
</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>AWDateTimeFormatter</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>AWDateTimeFormatter</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>
|
@ -1,11 +1,75 @@
|
|||||||
{
|
{
|
||||||
"__url": "https://developer.yahoo.com/weather/documentation.html",
|
"__url-yahoo": "https://developer.yahoo.com/weather/documentation.html",
|
||||||
|
"__url-owm": "http://openweathermap.org/weather-conditions",
|
||||||
|
|
||||||
"image": {
|
"image": {
|
||||||
"__comment": "should be described as html image with full path inside",
|
"__comment": "should be described as html image with full path inside",
|
||||||
|
|
||||||
"default": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/3200.gif\">",
|
"default": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/3200.gif\">",
|
||||||
|
|
||||||
|
"800": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/01d.png\">",
|
||||||
|
|
||||||
|
"801": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/02d.png\">",
|
||||||
|
|
||||||
|
"802": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/03d.png\">",
|
||||||
|
"803": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/03d.png\">",
|
||||||
|
|
||||||
|
"804": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/04d.png\">",
|
||||||
|
|
||||||
|
"300": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/09d.png\">",
|
||||||
|
"301": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/09d.png\">",
|
||||||
|
"302": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/09d.png\">",
|
||||||
|
"310": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/09d.png\">",
|
||||||
|
"311": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/09d.png\">",
|
||||||
|
"312": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/09d.png\">",
|
||||||
|
"313": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/09d.png\">",
|
||||||
|
"314": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/09d.png\">",
|
||||||
|
"321": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/09d.png\">",
|
||||||
|
"520": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/09d.png\">",
|
||||||
|
"521": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/09d.png\">",
|
||||||
|
"522": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/09d.png\">",
|
||||||
|
"531": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/09d.png\">",
|
||||||
|
|
||||||
|
"500": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/10d.png\">",
|
||||||
|
"501": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/10d.png\">",
|
||||||
|
"502": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/10d.png\">",
|
||||||
|
"503": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/10d.png\">",
|
||||||
|
"504": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/10d.png\">",
|
||||||
|
|
||||||
|
"200": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/11d.png\">",
|
||||||
|
"201": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/11d.png\">",
|
||||||
|
"202": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/11d.png\">",
|
||||||
|
"210": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/11d.png\">",
|
||||||
|
"211": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/11d.png\">",
|
||||||
|
"212": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/11d.png\">",
|
||||||
|
"221": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/11d.png\">",
|
||||||
|
"230": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/11d.png\">",
|
||||||
|
"231": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/11d.png\">",
|
||||||
|
"232": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/11d.png\">",
|
||||||
|
|
||||||
|
"511": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/13d.png\">",
|
||||||
|
"600": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/13d.png\">",
|
||||||
|
"601": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/13d.png\">",
|
||||||
|
"602": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/13d.png\">",
|
||||||
|
"611": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/13d.png\">",
|
||||||
|
"612": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/13d.png\">",
|
||||||
|
"615": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/13d.png\">",
|
||||||
|
"616": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/13d.png\">",
|
||||||
|
"620": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/13d.png\">",
|
||||||
|
"621": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/13d.png\">",
|
||||||
|
"622": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/13d.png\">",
|
||||||
|
|
||||||
|
"701": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/50d.png\">",
|
||||||
|
"711": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/50d.png\">",
|
||||||
|
"721": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/50d.png\">",
|
||||||
|
"731": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/50d.png\">",
|
||||||
|
"741": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/50d.png\">",
|
||||||
|
"751": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/50d.png\">",
|
||||||
|
"761": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/50d.png\">",
|
||||||
|
"762": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/50d.png\">",
|
||||||
|
"771": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/50d.png\">",
|
||||||
|
"781": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/50d.png\">",
|
||||||
|
|
||||||
"0": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/0.gif\">",
|
"0": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/0.gif\">",
|
||||||
"1": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/1.gif\">",
|
"1": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/1.gif\">",
|
||||||
"2": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/2.gif\">",
|
"2": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/2.gif\">",
|
||||||
@ -59,8 +123,71 @@
|
|||||||
|
|
||||||
"text": {
|
"text": {
|
||||||
"default": "\u2604",
|
"default": "\u2604",
|
||||||
"3200": "\u2604",
|
|
||||||
|
|
||||||
|
"800": "\u2600",
|
||||||
|
|
||||||
|
"801": "\u26C5",
|
||||||
|
|
||||||
|
"802": "\u2601",
|
||||||
|
"803": "\u2601",
|
||||||
|
|
||||||
|
"804": "\u2601",
|
||||||
|
|
||||||
|
"300": "\u2602",
|
||||||
|
"301": "\u2602",
|
||||||
|
"302": "\u2602",
|
||||||
|
"310": "\u2602",
|
||||||
|
"311": "\u2602",
|
||||||
|
"312": "\u2602",
|
||||||
|
"313": "\u2602",
|
||||||
|
"314": "\u2602",
|
||||||
|
"321": "\u2602",
|
||||||
|
"520": "\u2602",
|
||||||
|
"521": "\u2602",
|
||||||
|
"522": "\u2602",
|
||||||
|
"531": "\u2602",
|
||||||
|
|
||||||
|
"500": "\u2614",
|
||||||
|
"501": "\u2614",
|
||||||
|
"502": "\u2614",
|
||||||
|
"503": "\u2614",
|
||||||
|
"504": "\u2614",
|
||||||
|
|
||||||
|
"200": "\u2608",
|
||||||
|
"201": "\u2608",
|
||||||
|
"202": "\u2608",
|
||||||
|
"210": "\u2608",
|
||||||
|
"211": "\u2608",
|
||||||
|
"212": "\u2608",
|
||||||
|
"221": "\u2608",
|
||||||
|
"230": "\u2608",
|
||||||
|
"231": "\u2608",
|
||||||
|
"232": "\u2608",
|
||||||
|
|
||||||
|
"511": "\u2603",
|
||||||
|
"600": "\u2603",
|
||||||
|
"601": "\u2603",
|
||||||
|
"602": "\u2603",
|
||||||
|
"611": "\u2603",
|
||||||
|
"612": "\u2603",
|
||||||
|
"615": "\u2603",
|
||||||
|
"616": "\u2603",
|
||||||
|
"620": "\u2603",
|
||||||
|
"621": "\u2603",
|
||||||
|
"622": "\u2603",
|
||||||
|
|
||||||
|
"701": "\u26C5",
|
||||||
|
"711": "\u26C5",
|
||||||
|
"721": "\u26C5",
|
||||||
|
"731": "\u26C5",
|
||||||
|
"741": "\u26C5",
|
||||||
|
"751": "\u26C5",
|
||||||
|
"761": "\u26C5",
|
||||||
|
"762": "\u26C5",
|
||||||
|
"771": "\u26C5",
|
||||||
|
"781": "\u26C5",
|
||||||
|
|
||||||
|
"3200": "\u2604",
|
||||||
"0": "\u2604",
|
"0": "\u2604",
|
||||||
"1": "\u2604",
|
"1": "\u2604",
|
||||||
"2": "\u2604",
|
"2": "\u2604",
|
||||||
|
286
sources/awesomewidgets/awfloatformatter.cpp
Normal file
@ -0,0 +1,286 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* 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 "awfloatformatter.h"
|
||||||
|
#include "ui_awfloatformatter.h"
|
||||||
|
|
||||||
|
#include <KI18n/KLocalizedString>
|
||||||
|
|
||||||
|
#include <QDir>
|
||||||
|
#include <QSettings>
|
||||||
|
|
||||||
|
#include "awdebug.h"
|
||||||
|
|
||||||
|
|
||||||
|
AWFloatFormatter::AWFloatFormatter(QWidget *parent, const QString filePath)
|
||||||
|
: AWAbstractFormatter(parent, filePath)
|
||||||
|
, ui(new Ui::AWFloatFormatter)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
|
if (!filePath.isEmpty())
|
||||||
|
readConfiguration();
|
||||||
|
ui->setupUi(this);
|
||||||
|
translate();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
AWFloatFormatter::~AWFloatFormatter()
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString AWFloatFormatter::convert(const QVariant &_value) const
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Convert value" << _value;
|
||||||
|
|
||||||
|
QString output
|
||||||
|
= QString("%1").arg(_value.toDouble() * multiplier() + summand(),
|
||||||
|
count(), format(), precision(), fillChar());
|
||||||
|
if (forceWidth())
|
||||||
|
output = output.left(count());
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
AWFloatFormatter *AWFloatFormatter::copy(const QString _fileName,
|
||||||
|
const int _number)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
||||||
|
|
||||||
|
AWFloatFormatter *item
|
||||||
|
= new AWFloatFormatter(static_cast<QWidget *>(parent()), _fileName);
|
||||||
|
AWAbstractFormatter::copyDefaults(item);
|
||||||
|
item->setCount(count());
|
||||||
|
item->setFormat(format());
|
||||||
|
item->setFillChar(fillChar());
|
||||||
|
item->setForceWidth(forceWidth());
|
||||||
|
item->setMultiplier(multiplier());
|
||||||
|
item->setNumber(_number);
|
||||||
|
item->setPrecision(precision());
|
||||||
|
item->setSummand(summand());
|
||||||
|
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int AWFloatFormatter::count() const
|
||||||
|
{
|
||||||
|
return m_count;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QChar AWFloatFormatter::fillChar() const
|
||||||
|
{
|
||||||
|
return m_fillChar;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool AWFloatFormatter::forceWidth() const
|
||||||
|
{
|
||||||
|
return m_forceWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
char AWFloatFormatter::format() const
|
||||||
|
{
|
||||||
|
return m_format;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
double AWFloatFormatter::multiplier() const
|
||||||
|
{
|
||||||
|
return m_multiplier;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int AWFloatFormatter::precision() const
|
||||||
|
{
|
||||||
|
return m_precision;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
double AWFloatFormatter::summand() const
|
||||||
|
{
|
||||||
|
return m_summand;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWFloatFormatter::setCount(const int _count)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Set width" << _count;
|
||||||
|
|
||||||
|
m_count = _count;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWFloatFormatter::setFillChar(const QChar _fillChar)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Set char" << _fillChar;
|
||||||
|
|
||||||
|
m_fillChar = _fillChar;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWFloatFormatter::setForceWidth(const bool _forceWidth)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Set force strip" << _forceWidth;
|
||||||
|
|
||||||
|
m_forceWidth = _forceWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWFloatFormatter::setFormat(char _format)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Set format" << _format;
|
||||||
|
// http://doc.qt.io/qt-5/qstring.html#argument-formats
|
||||||
|
if ((_format != 'e') && (_format != 'E') && (_format != 'f')
|
||||||
|
&& (_format != 'g') && (_format != 'G')) {
|
||||||
|
qCWarning(LOG_LIB) << "Invalid format" << _format;
|
||||||
|
_format = 'f';
|
||||||
|
}
|
||||||
|
|
||||||
|
m_format = _format;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWFloatFormatter::setMultiplier(const double _multiplier)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Set multiplier" << _multiplier;
|
||||||
|
|
||||||
|
m_multiplier = _multiplier;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWFloatFormatter::setPrecision(const int _precision)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Set precision" << _precision;
|
||||||
|
|
||||||
|
m_precision = _precision;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWFloatFormatter::setSummand(const double _summand)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Set summand" << _summand;
|
||||||
|
|
||||||
|
m_summand = _summand;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWFloatFormatter::readConfiguration()
|
||||||
|
{
|
||||||
|
AWAbstractFormatter::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()))
|
||||||
|
.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());
|
||||||
|
settings.endGroup();
|
||||||
|
|
||||||
|
bumpApi(AWEFAPI);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int AWFloatFormatter::showConfiguration(const QVariant args)
|
||||||
|
{
|
||||||
|
Q_UNUSED(args)
|
||||||
|
|
||||||
|
ui->lineEdit_name->setText(name());
|
||||||
|
ui->lineEdit_comment->setText(comment());
|
||||||
|
ui->label_typeValue->setText(QString("Float"));
|
||||||
|
ui->comboBox_format->setCurrentIndex(
|
||||||
|
ui->comboBox_format->findText(QString(format())));
|
||||||
|
ui->spinBox_precision->setValue(precision());
|
||||||
|
ui->spinBox_width->setValue(count());
|
||||||
|
ui->lineEdit_fill->setText(QString(fillChar()));
|
||||||
|
ui->checkBox_forceWidth->setCheckState(forceWidth() ? Qt::Checked
|
||||||
|
: Qt::Unchecked);
|
||||||
|
ui->doubleSpinBox_multiplier->setValue(multiplier());
|
||||||
|
ui->doubleSpinBox_summand->setValue(summand());
|
||||||
|
|
||||||
|
int ret = exec();
|
||||||
|
if (ret != 1)
|
||||||
|
return ret;
|
||||||
|
setName(ui->lineEdit_name->text());
|
||||||
|
setComment(ui->lineEdit_comment->text());
|
||||||
|
setStrType(ui->label_typeValue->text());
|
||||||
|
setFormat(ui->comboBox_format->currentText().at(0).toLatin1());
|
||||||
|
setPrecision(ui->spinBox_precision->value());
|
||||||
|
setCount(ui->spinBox_width->value());
|
||||||
|
setFillChar(ui->lineEdit_fill->text().at(0));
|
||||||
|
setForceWidth(ui->checkBox_forceWidth->checkState() == Qt::Checked);
|
||||||
|
setMultiplier(ui->doubleSpinBox_multiplier->value());
|
||||||
|
setSummand(ui->doubleSpinBox_summand->value());
|
||||||
|
|
||||||
|
writeConfiguration();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWFloatFormatter::writeConfiguration() const
|
||||||
|
{
|
||||||
|
AWAbstractFormatter::writeConfiguration();
|
||||||
|
|
||||||
|
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"), 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.endGroup();
|
||||||
|
|
||||||
|
settings.sync();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWFloatFormatter::translate()
|
||||||
|
{
|
||||||
|
ui->label_name->setText(i18n("Name"));
|
||||||
|
ui->label_comment->setText(i18n("Comment"));
|
||||||
|
ui->label_type->setText(i18n("Type"));
|
||||||
|
ui->label_format->setText(i18n("Format"));
|
||||||
|
ui->label_precision->setText(i18n("Precision"));
|
||||||
|
ui->label_width->setText(i18n("Width"));
|
||||||
|
ui->label_fill->setText(i18n("Fill char"));
|
||||||
|
ui->checkBox_forceWidth->setText(i18n("Force width"));
|
||||||
|
ui->label_multiplier->setText(i18n("Multiplier"));
|
||||||
|
ui->label_summand->setText(i18n("Summand"));
|
||||||
|
}
|
@ -21,48 +21,60 @@
|
|||||||
#include "awabstractformatter.h"
|
#include "awabstractformatter.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Ui
|
||||||
|
{
|
||||||
|
class AWFloatFormatter;
|
||||||
|
}
|
||||||
|
|
||||||
class AWFloatFormatter : public AWAbstractFormatter
|
class AWFloatFormatter : public AWAbstractFormatter
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(int count READ count WRITE setCount)
|
||||||
Q_PROPERTY(QChar fillChar READ fillChar WRITE setFillChar)
|
Q_PROPERTY(QChar fillChar READ fillChar WRITE setFillChar)
|
||||||
|
Q_PROPERTY(bool forceWidth READ forceWidth WRITE setForceWidth)
|
||||||
Q_PROPERTY(char format READ format WRITE setFormat)
|
Q_PROPERTY(char format READ format WRITE setFormat)
|
||||||
Q_PROPERTY(double multiplier READ multiplier WRITE setMultiplier)
|
Q_PROPERTY(double multiplier READ multiplier WRITE setMultiplier)
|
||||||
Q_PROPERTY(int precision READ precision WRITE setPrecision)
|
Q_PROPERTY(int precision READ precision WRITE setPrecision)
|
||||||
Q_PROPERTY(double summand READ summand WRITE setSummand)
|
Q_PROPERTY(double summand READ summand WRITE setSummand)
|
||||||
Q_PROPERTY(int width READ width WRITE setWidth)
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit AWFloatFormatter(QObject *parent, const QString filename,
|
explicit AWFloatFormatter(QWidget *parent,
|
||||||
const QString section);
|
const QString filePath = QString());
|
||||||
explicit AWFloatFormatter(QObject *parent, const QChar fillChar,
|
|
||||||
const char format, const double multiplier,
|
|
||||||
const int precision, const double summand,
|
|
||||||
const int width);
|
|
||||||
virtual ~AWFloatFormatter();
|
virtual ~AWFloatFormatter();
|
||||||
QString convert(const QVariant &value) const;
|
QString convert(const QVariant &_value) const;
|
||||||
|
AWFloatFormatter *copy(const QString _fileName, const int _number);
|
||||||
// properties
|
// properties
|
||||||
|
int count() const;
|
||||||
QChar fillChar() const;
|
QChar fillChar() const;
|
||||||
|
bool forceWidth() const;
|
||||||
char format() const;
|
char format() const;
|
||||||
double multiplier() const;
|
double multiplier() const;
|
||||||
int precision() const;
|
int precision() const;
|
||||||
double summand() const;
|
double summand() const;
|
||||||
int width() 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 setFormat(char _format);
|
||||||
void setMultiplier(const double _multiplier);
|
void setMultiplier(const double _multiplier);
|
||||||
void setPrecision(const int _precision);
|
void setPrecision(const int _precision);
|
||||||
void setSummand(const double _summand);
|
void setSummand(const double _summand);
|
||||||
void setWidth(const int _width);
|
|
||||||
|
public slots:
|
||||||
|
void readConfiguration();
|
||||||
|
int showConfiguration(const QVariant args = QVariant());
|
||||||
|
void writeConfiguration() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void init(const QString filename, const QString section);
|
Ui::AWFloatFormatter *ui = nullptr;
|
||||||
|
void translate();
|
||||||
// properties
|
// properties
|
||||||
QChar m_fillChar;
|
int m_count = 0;
|
||||||
char m_format;
|
QChar m_fillChar = QChar();
|
||||||
double m_multiplier;
|
bool m_forceWidth = false;
|
||||||
int m_precision;
|
char m_format = 'f';
|
||||||
double m_summand;
|
double m_multiplier = 1.0;
|
||||||
int m_width;
|
int m_precision = -1;
|
||||||
|
double m_summand = 0.0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
347
sources/awesomewidgets/awfloatformatter.ui
Normal file
@ -0,0 +1,347 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>AWFloatFormatter</class>
|
||||||
|
<widget class="QDialog" name="AWFloatFormatter">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>420</width>
|
||||||
|
<height>362</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_format">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_format">
|
||||||
|
<property name="text">
|
||||||
|
<string>Format</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QComboBox" name="comboBox_format">
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string notr="true">e</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string notr="true">E</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string notr="true">f</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string notr="true">g</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string notr="true">G</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="layout_precision">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_precision">
|
||||||
|
<property name="text">
|
||||||
|
<string>Precision</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QSpinBox" name="spinBox_precision">
|
||||||
|
<property name="minimum">
|
||||||
|
<number>-1</number>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<number>10000</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="layout_width">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_width">
|
||||||
|
<property name="text">
|
||||||
|
<string>Width</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QSpinBox" name="spinBox_width">
|
||||||
|
<property name="minimum">
|
||||||
|
<number>-10000</number>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<number>10000</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="layout_fill">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_fill">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Fill char</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="lineEdit_fill">
|
||||||
|
<property name="maxLength">
|
||||||
|
<number>1</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="layout_forceWIdth">
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer">
|
||||||
|
<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_forceWidth">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Force width</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="Line" name="line">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="layout_multiplier">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_multiplier">
|
||||||
|
<property name="text">
|
||||||
|
<string>Multiplier</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QDoubleSpinBox" name="doubleSpinBox_multiplier">
|
||||||
|
<property name="minimum">
|
||||||
|
<double>-1000000000.000000000000000</double>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<double>1000000000.000000000000000</double>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="layout_summand">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_summand">
|
||||||
|
<property name="text">
|
||||||
|
<string>Summand</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QDoubleSpinBox" name="doubleSpinBox_summand">
|
||||||
|
<property name="minimum">
|
||||||
|
<double>-1000000000.000000000000000</double>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<double>1000000000.000000000000000</double>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</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>AWFloatFormatter</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>AWFloatFormatter</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>
|
191
sources/awesomewidgets/awlistformatter.cpp
Normal file
@ -0,0 +1,191 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* 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 "awlistformatter.h"
|
||||||
|
#include "ui_awlistformatter.h"
|
||||||
|
|
||||||
|
#include <KI18n/KLocalizedString>
|
||||||
|
|
||||||
|
#include <QSettings>
|
||||||
|
|
||||||
|
#include "awdebug.h"
|
||||||
|
|
||||||
|
|
||||||
|
AWListFormatter::AWListFormatter(QWidget *parent, const QString filePath)
|
||||||
|
: AWAbstractFormatter(parent, filePath)
|
||||||
|
, ui(new Ui::AWListFormatter)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
|
if (!filePath.isEmpty())
|
||||||
|
readConfiguration();
|
||||||
|
ui->setupUi(this);
|
||||||
|
translate();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
AWListFormatter::~AWListFormatter()
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString AWListFormatter::convert(const QVariant &_value) const
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Convert value" << _value;
|
||||||
|
|
||||||
|
QStringList output = _value.toStringList();
|
||||||
|
if (isSorted())
|
||||||
|
output.sort();
|
||||||
|
|
||||||
|
return output.filter(m_regex).join(separator());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
AWListFormatter *AWListFormatter::copy(const QString _fileName,
|
||||||
|
const int _number)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
||||||
|
|
||||||
|
AWListFormatter *item
|
||||||
|
= new AWListFormatter(static_cast<QWidget *>(parent()), _fileName);
|
||||||
|
AWAbstractFormatter::copyDefaults(item);
|
||||||
|
item->setFilter(filter());
|
||||||
|
item->setSeparator(separator());
|
||||||
|
item->setSorted(isSorted());
|
||||||
|
item->setNumber(_number);
|
||||||
|
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString AWListFormatter::filter() const
|
||||||
|
{
|
||||||
|
return m_filter;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool AWListFormatter::isSorted() const
|
||||||
|
{
|
||||||
|
return m_sorted;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString AWListFormatter::separator() const
|
||||||
|
{
|
||||||
|
return m_separator;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWListFormatter::setFilter(const QString _filter)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Filter" << _filter;
|
||||||
|
|
||||||
|
m_filter = _filter;
|
||||||
|
m_regex = QRegExp(m_filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWListFormatter::setSeparator(const QString _separator)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Separtor" << _separator;
|
||||||
|
|
||||||
|
m_separator = _separator;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWListFormatter::setSorted(const bool _sorted)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Sorting" << _sorted;
|
||||||
|
|
||||||
|
m_sorted = _sorted;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWListFormatter::readConfiguration()
|
||||||
|
{
|
||||||
|
AWAbstractFormatter::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.endGroup();
|
||||||
|
|
||||||
|
bumpApi(AWEFAPI);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int AWListFormatter::showConfiguration(const QVariant args)
|
||||||
|
{
|
||||||
|
Q_UNUSED(args)
|
||||||
|
|
||||||
|
ui->lineEdit_name->setText(name());
|
||||||
|
ui->lineEdit_comment->setText(comment());
|
||||||
|
ui->label_typeValue->setText(QString("NoFormat"));
|
||||||
|
ui->lineEdit_filter->setText(filter());
|
||||||
|
ui->lineEdit_separator->setText(separator());
|
||||||
|
ui->checkBox_sorted->setCheckState(isSorted() ? Qt::Checked
|
||||||
|
: Qt::Unchecked);
|
||||||
|
|
||||||
|
int ret = exec();
|
||||||
|
if (ret != 1)
|
||||||
|
return ret;
|
||||||
|
setName(ui->lineEdit_name->text());
|
||||||
|
setComment(ui->lineEdit_comment->text());
|
||||||
|
setStrType(ui->label_typeValue->text());
|
||||||
|
setFilter(ui->lineEdit_filter->text());
|
||||||
|
setSeparator(ui->lineEdit_separator->text());
|
||||||
|
setSorted(ui->checkBox_sorted->checkState() == Qt::Checked);
|
||||||
|
|
||||||
|
writeConfiguration();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWListFormatter::writeConfiguration() const
|
||||||
|
{
|
||||||
|
AWAbstractFormatter::writeConfiguration();
|
||||||
|
|
||||||
|
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.endGroup();
|
||||||
|
|
||||||
|
settings.sync();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWListFormatter::translate()
|
||||||
|
{
|
||||||
|
ui->label_name->setText(i18n("Name"));
|
||||||
|
ui->label_comment->setText(i18n("Comment"));
|
||||||
|
ui->label_type->setText(i18n("Type"));
|
||||||
|
ui->label_filter->setText(i18n("Filter"));
|
||||||
|
ui->label_separator->setText(i18n("Separator"));
|
||||||
|
ui->checkBox_sorted->setText(i18n("Sort"));
|
||||||
|
}
|
66
sources/awesomewidgets/awlistformatter.h
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* 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 AWLISTFORMATTER_H
|
||||||
|
#define AWLISTFORMATTER_H
|
||||||
|
|
||||||
|
#include "awabstractformatter.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Ui
|
||||||
|
{
|
||||||
|
class AWListFormatter;
|
||||||
|
}
|
||||||
|
|
||||||
|
class AWListFormatter : public AWAbstractFormatter
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(QString filter READ filter WRITE setFilter)
|
||||||
|
Q_PROPERTY(QString separator READ separator WRITE setSeparator)
|
||||||
|
Q_PROPERTY(bool sorted READ isSorted WRITE setSorted)
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit AWListFormatter(QWidget *parent,
|
||||||
|
const QString filePath = QString());
|
||||||
|
virtual ~AWListFormatter();
|
||||||
|
QString convert(const QVariant &_value) const;
|
||||||
|
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 setSorted(const bool _sorted);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void readConfiguration();
|
||||||
|
int showConfiguration(const QVariant args = QVariant());
|
||||||
|
void writeConfiguration() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ui::AWListFormatter *ui = nullptr;
|
||||||
|
void translate();
|
||||||
|
// properties
|
||||||
|
QString m_filter = QString();
|
||||||
|
QString m_separator = QString();
|
||||||
|
bool m_sorted = false;
|
||||||
|
QRegExp m_regex;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* AWLISTFORMATTER_H */
|
220
sources/awesomewidgets/awlistformatter.ui
Normal file
@ -0,0 +1,220 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>AWListFormatter</class>
|
||||||
|
<widget class="QDialog" name="AWListFormatter">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>420</width>
|
||||||
|
<height>225</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_filter">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_filter">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Filter</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="lineEdit_filter"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="layout_separator">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_separator">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Separator</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="lineEdit_separator"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="layout_sorted">
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer">
|
||||||
|
<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_sorted">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Sort</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</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>AWListFormatter</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>AWListFormatter</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>
|
94
sources/awesomewidgets/awnoformatter.cpp
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* 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 "awnoformatter.h"
|
||||||
|
#include "ui_awnoformatter.h"
|
||||||
|
|
||||||
|
#include <KI18n/KLocalizedString>
|
||||||
|
|
||||||
|
#include "awdebug.h"
|
||||||
|
|
||||||
|
|
||||||
|
AWNoFormatter::AWNoFormatter(QWidget *parent, const QString filePath)
|
||||||
|
: AWAbstractFormatter(parent, filePath)
|
||||||
|
, ui(new Ui::AWNoFormatter)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
|
if (!filePath.isEmpty())
|
||||||
|
readConfiguration();
|
||||||
|
ui->setupUi(this);
|
||||||
|
translate();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
AWNoFormatter::~AWNoFormatter()
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString AWNoFormatter::convert(const QVariant &_value) const
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Convert value" << _value;
|
||||||
|
|
||||||
|
return _value.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
AWNoFormatter *AWNoFormatter::copy(const QString _fileName, const int _number)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
||||||
|
|
||||||
|
AWNoFormatter *item
|
||||||
|
= new AWNoFormatter(static_cast<QWidget *>(parent()), _fileName);
|
||||||
|
AWAbstractFormatter::copyDefaults(item);
|
||||||
|
item->setNumber(_number);
|
||||||
|
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int AWNoFormatter::showConfiguration(const QVariant args)
|
||||||
|
{
|
||||||
|
Q_UNUSED(args)
|
||||||
|
|
||||||
|
ui->lineEdit_name->setText(name());
|
||||||
|
ui->lineEdit_comment->setText(comment());
|
||||||
|
ui->label_typeValue->setText(QString("NoFormat"));
|
||||||
|
|
||||||
|
int ret = exec();
|
||||||
|
if (ret != 1)
|
||||||
|
return ret;
|
||||||
|
setName(ui->lineEdit_name->text());
|
||||||
|
setComment(ui->lineEdit_comment->text());
|
||||||
|
setStrType(ui->label_typeValue->text());
|
||||||
|
|
||||||
|
writeConfiguration();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWNoFormatter::translate()
|
||||||
|
{
|
||||||
|
ui->label_name->setText(i18n("Name"));
|
||||||
|
ui->label_comment->setText(i18n("Comment"));
|
||||||
|
ui->label_type->setText(i18n("Type"));
|
||||||
|
}
|
@ -21,19 +21,27 @@
|
|||||||
#include "awabstractformatter.h"
|
#include "awabstractformatter.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Ui
|
||||||
|
{
|
||||||
|
class AWNoFormatter;
|
||||||
|
}
|
||||||
|
|
||||||
class AWNoFormatter : public AWAbstractFormatter
|
class AWNoFormatter : public AWAbstractFormatter
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit AWNoFormatter(QObject *parent, const QString filename,
|
explicit AWNoFormatter(QWidget *parent, const QString filePath = QString());
|
||||||
const QString section);
|
|
||||||
explicit AWNoFormatter(QObject *parent);
|
|
||||||
virtual ~AWNoFormatter();
|
virtual ~AWNoFormatter();
|
||||||
QString convert(const QVariant &value) const;
|
QString convert(const QVariant &_value) const;
|
||||||
|
AWNoFormatter *copy(const QString _fileName, const int _number);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
int showConfiguration(const QVariant args = QVariant());
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void init(const QString filename, const QString section);
|
Ui::AWNoFormatter *ui = nullptr;
|
||||||
|
void translate();
|
||||||
// properties
|
// properties
|
||||||
};
|
};
|
||||||
|
|
144
sources/awesomewidgets/awnoformatter.ui
Normal file
@ -0,0 +1,144 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>AWNoFormatter</class>
|
||||||
|
<widget class="QDialog" name="AWNoFormatter">
|
||||||
|
<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>
|
||||||
|
<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>AWNoFormatter</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>AWNoFormatter</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>
|
228
sources/awesomewidgets/awscriptformatter.cpp
Normal file
@ -0,0 +1,228 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* 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 "awscriptformatter.h"
|
||||||
|
#include "ui_awscriptformatter.h"
|
||||||
|
|
||||||
|
#include <KI18n/KLocalizedString>
|
||||||
|
|
||||||
|
#include <QDir>
|
||||||
|
#include <QJSEngine>
|
||||||
|
#include <QSettings>
|
||||||
|
|
||||||
|
#include "awdebug.h"
|
||||||
|
|
||||||
|
|
||||||
|
AWScriptFormatter::AWScriptFormatter(QWidget *parent, const QString filePath)
|
||||||
|
: AWAbstractFormatter(parent, filePath)
|
||||||
|
, ui(new Ui::AWScriptFormatter)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
|
if (!filePath.isEmpty())
|
||||||
|
readConfiguration();
|
||||||
|
ui->setupUi(this);
|
||||||
|
translate();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
AWScriptFormatter::~AWScriptFormatter()
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString AWScriptFormatter::convert(const QVariant &_value) const
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Convert value" << _value;
|
||||||
|
|
||||||
|
// init engine
|
||||||
|
QJSEngine engine;
|
||||||
|
QJSValue fn = engine.evaluate(m_program);
|
||||||
|
QJSValueList args = QJSValueList() << _value.toString();
|
||||||
|
QJSValue result = fn.call(args);
|
||||||
|
|
||||||
|
if (result.isError()) {
|
||||||
|
qCWarning(LOG_LIB) << "Uncaught exception at line"
|
||||||
|
<< result.property("lineNumber").toInt() << ":"
|
||||||
|
<< result.toString();
|
||||||
|
return QString();
|
||||||
|
} else {
|
||||||
|
return result.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
AWScriptFormatter *AWScriptFormatter::copy(const QString _fileName,
|
||||||
|
const int _number)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
||||||
|
|
||||||
|
AWScriptFormatter *item
|
||||||
|
= new AWScriptFormatter(static_cast<QWidget *>(parent()), _fileName);
|
||||||
|
AWAbstractFormatter::copyDefaults(item);
|
||||||
|
item->setAppendCode(appendCode());
|
||||||
|
item->setCode(code());
|
||||||
|
item->setHasReturn(hasReturn());
|
||||||
|
item->setNumber(_number);
|
||||||
|
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool AWScriptFormatter::appendCode() const
|
||||||
|
{
|
||||||
|
return m_appendCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString AWScriptFormatter::code() const
|
||||||
|
{
|
||||||
|
return m_code;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool AWScriptFormatter::hasReturn() const
|
||||||
|
{
|
||||||
|
return m_hasReturn;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString AWScriptFormatter::program() const
|
||||||
|
{
|
||||||
|
return m_program;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWScriptFormatter::setAppendCode(const bool _appendCode)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Set append code" << _appendCode;
|
||||||
|
|
||||||
|
m_appendCode = _appendCode;
|
||||||
|
initProgram();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWScriptFormatter::setCode(const QString _code)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Set code" << _code;
|
||||||
|
|
||||||
|
m_code = _code;
|
||||||
|
initProgram();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWScriptFormatter::setHasReturn(const bool _hasReturn)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Set has return" << _hasReturn;
|
||||||
|
|
||||||
|
m_hasReturn = _hasReturn;
|
||||||
|
initProgram();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWScriptFormatter::readConfiguration()
|
||||||
|
{
|
||||||
|
AWAbstractFormatter::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.endGroup();
|
||||||
|
|
||||||
|
bumpApi(AWEFAPI);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int AWScriptFormatter::showConfiguration(const QVariant args)
|
||||||
|
{
|
||||||
|
Q_UNUSED(args)
|
||||||
|
|
||||||
|
ui->lineEdit_name->setText(name());
|
||||||
|
ui->lineEdit_comment->setText(comment());
|
||||||
|
ui->label_typeValue->setText(QString("Script"));
|
||||||
|
ui->checkBox_appendCode->setCheckState(appendCode() ? Qt::Checked
|
||||||
|
: Qt::Unchecked);
|
||||||
|
ui->checkBox_hasReturn->setCheckState(hasReturn() ? Qt::Checked
|
||||||
|
: Qt::Unchecked);
|
||||||
|
ui->textEdit_code->setPlainText(code());
|
||||||
|
|
||||||
|
int ret = exec();
|
||||||
|
if (ret != 1)
|
||||||
|
return ret;
|
||||||
|
setName(ui->lineEdit_name->text());
|
||||||
|
setComment(ui->lineEdit_comment->text());
|
||||||
|
setStrType(ui->label_typeValue->text());
|
||||||
|
setAppendCode(ui->checkBox_appendCode->checkState() == Qt::Checked);
|
||||||
|
setHasReturn(ui->checkBox_hasReturn->checkState() == Qt::Checked);
|
||||||
|
setCode(ui->textEdit_code->toPlainText());
|
||||||
|
initProgram();
|
||||||
|
|
||||||
|
writeConfiguration();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWScriptFormatter::writeConfiguration() const
|
||||||
|
{
|
||||||
|
AWAbstractFormatter::writeConfiguration();
|
||||||
|
|
||||||
|
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.endGroup();
|
||||||
|
|
||||||
|
settings.sync();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWScriptFormatter::initProgram()
|
||||||
|
{
|
||||||
|
// init JS code
|
||||||
|
if (appendCode())
|
||||||
|
m_program
|
||||||
|
= QString("(function(value) { %1%2 })")
|
||||||
|
.arg(code())
|
||||||
|
.arg(hasReturn() ? QString("") : QString("; return output;"));
|
||||||
|
else
|
||||||
|
m_program = code();
|
||||||
|
|
||||||
|
qCInfo(LOG_LIB) << "Create JS engine with code" << m_program;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWScriptFormatter::translate()
|
||||||
|
{
|
||||||
|
ui->label_name->setText(i18n("Name"));
|
||||||
|
ui->label_comment->setText(i18n("Comment"));
|
||||||
|
ui->label_type->setText(i18n("Type"));
|
||||||
|
ui->checkBox_appendCode->setText(i18n("Append code"));
|
||||||
|
ui->checkBox_hasReturn->setText(i18n("Has return"));
|
||||||
|
ui->label_code->setText(i18n("Code"));
|
||||||
|
}
|
@ -21,6 +21,11 @@
|
|||||||
#include "awabstractformatter.h"
|
#include "awabstractformatter.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Ui
|
||||||
|
{
|
||||||
|
class AWScriptFormatter;
|
||||||
|
}
|
||||||
|
|
||||||
class AWScriptFormatter : public AWAbstractFormatter
|
class AWScriptFormatter : public AWAbstractFormatter
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -30,12 +35,11 @@ class AWScriptFormatter : public AWAbstractFormatter
|
|||||||
Q_PROPERTY(QString program READ program)
|
Q_PROPERTY(QString program READ program)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit AWScriptFormatter(QObject *parent, const QString filename,
|
explicit AWScriptFormatter(QWidget *parent,
|
||||||
const QString section);
|
const QString filePath = QString());
|
||||||
explicit AWScriptFormatter(QObject *parent, const bool appendCode,
|
|
||||||
const QString code, const bool hasReturn);
|
|
||||||
virtual ~AWScriptFormatter();
|
virtual ~AWScriptFormatter();
|
||||||
QString convert(const QVariant &value) const;
|
QString convert(const QVariant &_value) const;
|
||||||
|
AWScriptFormatter *copy(const QString _fileName, const int _number);
|
||||||
// properties
|
// properties
|
||||||
bool appendCode() const;
|
bool appendCode() const;
|
||||||
QString code() const;
|
QString code() const;
|
||||||
@ -45,13 +49,19 @@ public:
|
|||||||
void setCode(const QString _code);
|
void setCode(const QString _code);
|
||||||
void setHasReturn(const bool _hasReturn);
|
void setHasReturn(const bool _hasReturn);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void readConfiguration();
|
||||||
|
int showConfiguration(const QVariant args = QVariant());
|
||||||
|
void writeConfiguration() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void init(const QString filename, const QString section);
|
Ui::AWScriptFormatter *ui = nullptr;
|
||||||
void initProgram();
|
void initProgram();
|
||||||
|
void translate();
|
||||||
// properties
|
// properties
|
||||||
bool m_appendCode;
|
bool m_appendCode = true;
|
||||||
QString m_code;
|
QString m_code = QString();
|
||||||
bool m_hasReturn;
|
bool m_hasReturn = false;
|
||||||
QString m_program;
|
QString m_program;
|
||||||
};
|
};
|
||||||
|
|
212
sources/awesomewidgets/awscriptformatter.ui
Normal file
@ -0,0 +1,212 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>AWScriptFormatter</class>
|
||||||
|
<widget class="QDialog" name="AWScriptFormatter">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>420</width>
|
||||||
|
<height>315</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_appendCode">
|
||||||
|
<item>
|
||||||
|
<spacer name="spacer_appendCode">
|
||||||
|
<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_appendCode">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Append code</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="layout_hasReturn">
|
||||||
|
<item>
|
||||||
|
<spacer name="spacer_hasReturn">
|
||||||
|
<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_hasReturn">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Has return</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="Line" name="line">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QVBoxLayout" name="layout_code">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_code">
|
||||||
|
<property name="text">
|
||||||
|
<string>Code</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QTextEdit" name="textEdit_code"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</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>AWScriptFormatter</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>AWScriptFormatter</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>
|
192
sources/awesomewidgets/awstringformatter.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 "awstringformatter.h"
|
||||||
|
#include "ui_awstringformatter.h"
|
||||||
|
|
||||||
|
#include <KI18n/KLocalizedString>
|
||||||
|
|
||||||
|
#include <QDir>
|
||||||
|
#include <QSettings>
|
||||||
|
|
||||||
|
#include "awdebug.h"
|
||||||
|
|
||||||
|
|
||||||
|
AWStringFormatter::AWStringFormatter(QWidget *parent, const QString filePath)
|
||||||
|
: AWAbstractFormatter(parent, filePath)
|
||||||
|
, ui(new Ui::AWStringFormatter)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
|
if (!filePath.isEmpty())
|
||||||
|
readConfiguration();
|
||||||
|
ui->setupUi(this);
|
||||||
|
translate();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
AWStringFormatter::~AWStringFormatter()
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString AWStringFormatter::convert(const QVariant &_value) const
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Convert value" << _value;
|
||||||
|
|
||||||
|
QString output = QString("%1").arg(_value.toString(), count(), fillChar());
|
||||||
|
if (forceWidth())
|
||||||
|
output = output.left(count());
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
AWStringFormatter *AWStringFormatter::copy(const QString _fileName,
|
||||||
|
const int _number)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
||||||
|
|
||||||
|
AWStringFormatter *item
|
||||||
|
= new AWStringFormatter(static_cast<QWidget *>(parent()), _fileName);
|
||||||
|
AWAbstractFormatter::copyDefaults(item);
|
||||||
|
item->setCount(count());
|
||||||
|
item->setFillChar(fillChar());
|
||||||
|
item->setForceWidth(forceWidth());
|
||||||
|
item->setNumber(_number);
|
||||||
|
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int AWStringFormatter::count() const
|
||||||
|
{
|
||||||
|
return m_count;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QChar AWStringFormatter::fillChar() const
|
||||||
|
{
|
||||||
|
return m_fillChar;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool AWStringFormatter::forceWidth() const
|
||||||
|
{
|
||||||
|
return m_forceWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWStringFormatter::setCount(const int _count)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Set width" << _count;
|
||||||
|
|
||||||
|
m_count = _count;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWStringFormatter::setFillChar(const QChar _fillChar)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Set char" << _fillChar;
|
||||||
|
|
||||||
|
m_fillChar = _fillChar;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWStringFormatter::setForceWidth(const bool _forceWidth)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Set force strip" << _forceWidth;
|
||||||
|
|
||||||
|
m_forceWidth = _forceWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWStringFormatter::readConfiguration()
|
||||||
|
{
|
||||||
|
AWAbstractFormatter::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.endGroup();
|
||||||
|
|
||||||
|
bumpApi(AWEFAPI);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int AWStringFormatter::showConfiguration(const QVariant args)
|
||||||
|
{
|
||||||
|
Q_UNUSED(args)
|
||||||
|
|
||||||
|
ui->lineEdit_name->setText(name());
|
||||||
|
ui->lineEdit_comment->setText(comment());
|
||||||
|
ui->label_typeValue->setText(QString("String"));
|
||||||
|
ui->spinBox_width->setValue(count());
|
||||||
|
ui->lineEdit_fill->setText(QString(fillChar()));
|
||||||
|
ui->checkBox_forceWidth->setCheckState(forceWidth() ? Qt::Checked
|
||||||
|
: Qt::Unchecked);
|
||||||
|
|
||||||
|
int ret = exec();
|
||||||
|
if (ret != 1)
|
||||||
|
return ret;
|
||||||
|
setName(ui->lineEdit_name->text());
|
||||||
|
setComment(ui->lineEdit_comment->text());
|
||||||
|
setStrType(ui->label_typeValue->text());
|
||||||
|
setCount(ui->spinBox_width->value());
|
||||||
|
setFillChar(ui->lineEdit_fill->text().at(0));
|
||||||
|
setForceWidth(ui->checkBox_forceWidth->checkState() == Qt::Checked);
|
||||||
|
|
||||||
|
writeConfiguration();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWStringFormatter::writeConfiguration() const
|
||||||
|
{
|
||||||
|
AWAbstractFormatter::writeConfiguration();
|
||||||
|
|
||||||
|
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.endGroup();
|
||||||
|
|
||||||
|
settings.sync();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWStringFormatter::translate()
|
||||||
|
{
|
||||||
|
ui->label_name->setText(i18n("Name"));
|
||||||
|
ui->label_comment->setText(i18n("Comment"));
|
||||||
|
ui->label_type->setText(i18n("Type"));
|
||||||
|
ui->label_width->setText(i18n("Width"));
|
||||||
|
ui->label_fill->setText(i18n("Fill char"));
|
||||||
|
ui->checkBox_forceWidth->setText(i18n("Force width"));
|
||||||
|
}
|
65
sources/awesomewidgets/awstringformatter.h
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* 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 AWSTRINGFORMATTER_H
|
||||||
|
#define AWSTRINGFORMATTER_H
|
||||||
|
|
||||||
|
#include "awabstractformatter.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Ui
|
||||||
|
{
|
||||||
|
class AWStringFormatter;
|
||||||
|
}
|
||||||
|
|
||||||
|
class AWStringFormatter : public AWAbstractFormatter
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(int count READ count WRITE setCount)
|
||||||
|
Q_PROPERTY(QChar fillChar READ fillChar WRITE setFillChar)
|
||||||
|
Q_PROPERTY(bool forceWidth READ forceWidth WRITE setForceWidth)
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit AWStringFormatter(QWidget *parent,
|
||||||
|
const QString filePath = QString());
|
||||||
|
virtual ~AWStringFormatter();
|
||||||
|
QString convert(const QVariant &_value) const;
|
||||||
|
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 setForceWidth(const bool _forceWidth);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void readConfiguration();
|
||||||
|
int showConfiguration(const QVariant args = QVariant());
|
||||||
|
void writeConfiguration() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ui::AWStringFormatter *ui = nullptr;
|
||||||
|
void translate();
|
||||||
|
// properties
|
||||||
|
int m_count = 0;
|
||||||
|
QChar m_fillChar = QChar();
|
||||||
|
bool m_forceWidth = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* AWSTRINGFORMATTER_H */
|
225
sources/awesomewidgets/awstringformatter.ui
Normal file
@ -0,0 +1,225 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>AWStringFormatter</class>
|
||||||
|
<widget class="QDialog" name="AWStringFormatter">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>420</width>
|
||||||
|
<height>225</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_width">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_width">
|
||||||
|
<property name="text">
|
||||||
|
<string>Width</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QSpinBox" name="spinBox_width">
|
||||||
|
<property name="minimum">
|
||||||
|
<number>-10000</number>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<number>10000</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="layout_fill">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_fill">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Fill char</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="lineEdit_fill">
|
||||||
|
<property name="maxLength">
|
||||||
|
<number>1</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="layout_forceWIdth">
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer">
|
||||||
|
<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_forceWidth">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Force width</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</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>AWStringFormatter</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>AWStringFormatter</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>
|
@ -32,8 +32,7 @@ template <class T> class ExtItemAggregator : public AbstractExtItemAggregator
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit ExtItemAggregator(QWidget *parent, const QString type)
|
explicit ExtItemAggregator(QWidget *parent, const QString type)
|
||||||
: AbstractExtItemAggregator(parent)
|
: AbstractExtItemAggregator(parent, type)
|
||||||
, m_type(type)
|
|
||||||
{
|
{
|
||||||
qSetMessagePattern(LOG_FORMAT);
|
qSetMessagePattern(LOG_FORMAT);
|
||||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
@ -57,8 +56,8 @@ public:
|
|||||||
|
|
||||||
void editItems()
|
void editItems()
|
||||||
{
|
{
|
||||||
repaint();
|
repaintList();
|
||||||
int ret = dialog->exec();
|
int ret = exec();
|
||||||
qCInfo(LOG_LIB) << "Dialog returns" << ret;
|
qCInfo(LOG_LIB) << "Dialog returns" << ret;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -70,7 +69,7 @@ public:
|
|||||||
for (auto item : m_items) {
|
for (auto item : m_items) {
|
||||||
if (item->tag(_type) != _tag)
|
if (item->tag(_type) != _tag)
|
||||||
continue;
|
continue;
|
||||||
found = item;
|
found = static_cast<T *>(item);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (found == nullptr)
|
if (found == nullptr)
|
||||||
@ -87,7 +86,7 @@ public:
|
|||||||
for (auto item : m_items) {
|
for (auto item : m_items) {
|
||||||
if (item->number() != _number)
|
if (item->number() != _number)
|
||||||
continue;
|
continue;
|
||||||
found = item;
|
found = static_cast<T *>(item);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (found == nullptr)
|
if (found == nullptr)
|
||||||
@ -96,63 +95,31 @@ public:
|
|||||||
return found;
|
return found;
|
||||||
};
|
};
|
||||||
|
|
||||||
T *itemFromWidget() const
|
QList<AbstractExtItem *> items() const { return m_items; };
|
||||||
{
|
|
||||||
QListWidgetItem *widgetItem = widgetDialog->currentItem();
|
|
||||||
if (widgetItem == nullptr)
|
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
T *found = nullptr;
|
|
||||||
for (auto item : m_items) {
|
|
||||||
if (item->fileName() != widgetItem->text())
|
|
||||||
continue;
|
|
||||||
found = item;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (found == nullptr)
|
|
||||||
qCWarning(LOG_LIB) << "Could not find item by name"
|
|
||||||
<< widgetItem->text();
|
|
||||||
|
|
||||||
return found;
|
|
||||||
};
|
|
||||||
|
|
||||||
QList<T *> items() const { return m_items; };
|
|
||||||
|
|
||||||
int uniqNumber() const
|
|
||||||
{
|
|
||||||
QList<int> tagList;
|
|
||||||
for (auto item : m_items)
|
|
||||||
tagList.append(item->number());
|
|
||||||
int number = 0;
|
|
||||||
while (tagList.contains(number))
|
|
||||||
number++;
|
|
||||||
|
|
||||||
return number;
|
|
||||||
};
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<T *> m_items;
|
QList<AbstractExtItem *> m_items;
|
||||||
QList<T *> m_activeItems;
|
QList<T *> m_activeItems;
|
||||||
QString m_type;
|
|
||||||
|
|
||||||
// init method
|
void doCreateItem() { return createItem<T>(); }
|
||||||
QList<T *> getItems()
|
|
||||||
|
QList<AbstractExtItem *> getItems()
|
||||||
{
|
{
|
||||||
// create directory at $HOME
|
// create directory at $HOME
|
||||||
QString localDir = QString("%1/awesomewidgets/%2")
|
QString localDir = QString("%1/awesomewidgets/%2")
|
||||||
.arg(QStandardPaths::writableLocation(
|
.arg(QStandardPaths::writableLocation(
|
||||||
QStandardPaths::GenericDataLocation))
|
QStandardPaths::GenericDataLocation))
|
||||||
.arg(m_type);
|
.arg(type());
|
||||||
QDir localDirectory;
|
QDir localDirectory;
|
||||||
if (localDirectory.mkpath(localDir))
|
if (localDirectory.mkpath(localDir))
|
||||||
qCInfo(LOG_LIB) << "Created directory" << localDir;
|
qCInfo(LOG_LIB) << "Created directory" << localDir;
|
||||||
|
|
||||||
QStringList dirs = QStandardPaths::locateAll(
|
QStringList dirs = QStandardPaths::locateAll(
|
||||||
QStandardPaths::GenericDataLocation,
|
QStandardPaths::GenericDataLocation,
|
||||||
QString("awesomewidgets/%1").arg(m_type),
|
QString("awesomewidgets/%1").arg(type()),
|
||||||
QStandardPaths::LocateDirectory);
|
QStandardPaths::LocateDirectory);
|
||||||
QStringList names;
|
QStringList names;
|
||||||
QList<T *> items;
|
QList<AbstractExtItem *> items;
|
||||||
for (auto dir : dirs) {
|
for (auto dir : dirs) {
|
||||||
QStringList files = QDir(dir).entryList(QDir::Files, QDir::Name);
|
QStringList files = QDir(dir).entryList(QDir::Files, QDir::Name);
|
||||||
for (auto file : files) {
|
for (auto file : files) {
|
||||||
@ -161,12 +128,14 @@ private:
|
|||||||
continue;
|
continue;
|
||||||
qCInfo(LOG_LIB) << "Found file" << file << "in" << dir;
|
qCInfo(LOG_LIB) << "Found file" << file << "in" << dir;
|
||||||
names.append(file);
|
names.append(file);
|
||||||
items.append(new T(this, file, dirs));
|
QString filePath = QString("%1/%2").arg(dir).arg(file);
|
||||||
|
items.append(new T(this, filePath));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// sort items
|
// sort items
|
||||||
std::sort(items.begin(), items.end(), [](const T *lhs, const T *rhs) {
|
std::sort(items.begin(), items.end(),
|
||||||
|
[](const AbstractExtItem *lhs, const AbstractExtItem *rhs) {
|
||||||
return lhs->number() < rhs->number();
|
return lhs->number() < rhs->number();
|
||||||
});
|
});
|
||||||
return items;
|
return items;
|
||||||
@ -181,89 +150,7 @@ private:
|
|||||||
for (auto item : m_items) {
|
for (auto item : m_items) {
|
||||||
if (!item->isActive())
|
if (!item->isActive())
|
||||||
continue;
|
continue;
|
||||||
m_activeItems.append(item);
|
m_activeItems.append(static_cast<T *>(item));
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
void repaint()
|
|
||||||
{
|
|
||||||
widgetDialog->clear();
|
|
||||||
for (auto _item : m_items) {
|
|
||||||
QListWidgetItem *item
|
|
||||||
= new QListWidgetItem(_item->fileName(), widgetDialog);
|
|
||||||
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')));
|
|
||||||
widgetDialog->addItem(item);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// methods
|
|
||||||
void copyItem()
|
|
||||||
{
|
|
||||||
T *source = itemFromWidget();
|
|
||||||
QString fileName = getName();
|
|
||||||
int number = uniqNumber();
|
|
||||||
if ((source == nullptr) || (fileName.isEmpty())) {
|
|
||||||
qCWarning(LOG_LIB) << "Nothing to copy";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
T *newItem = static_cast<T *>(source->copy(fileName, number));
|
|
||||||
if (newItem->showConfiguration(configArgs()) == 1) {
|
|
||||||
initItems();
|
|
||||||
repaint();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
void createItem()
|
|
||||||
{
|
|
||||||
QString fileName = getName();
|
|
||||||
int number = uniqNumber();
|
|
||||||
QStringList dirs = QStandardPaths::locateAll(
|
|
||||||
QStandardPaths::GenericDataLocation,
|
|
||||||
QString("awesomewidgets/%1").arg(m_type),
|
|
||||||
QStandardPaths::LocateDirectory);
|
|
||||||
if (fileName.isEmpty()) {
|
|
||||||
qCWarning(LOG_LIB) << "Nothing to create";
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
T *newItem = new T(this, fileName, dirs);
|
|
||||||
newItem->setNumber(number);
|
|
||||||
if (newItem->showConfiguration(configArgs()) == 1) {
|
|
||||||
initItems();
|
|
||||||
repaint();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
void deleteItem()
|
|
||||||
{
|
|
||||||
T *source = itemFromWidget();
|
|
||||||
if (source == nullptr) {
|
|
||||||
qCWarning(LOG_LIB) << "Nothing to delete";
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
if (source->tryDelete()) {
|
|
||||||
initItems();
|
|
||||||
repaint();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
void editItem()
|
|
||||||
{
|
|
||||||
T *source = itemFromWidget();
|
|
||||||
if (source == nullptr) {
|
|
||||||
qCWarning(LOG_LIB) << "Nothing to edit";
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
if (source->showConfiguration(configArgs()) == 1) {
|
|
||||||
initItems();
|
|
||||||
repaint();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -33,13 +33,13 @@
|
|||||||
#include "awdebug.h"
|
#include "awdebug.h"
|
||||||
|
|
||||||
|
|
||||||
ExtQuotes::ExtQuotes(QWidget *parent, const QString quotesName,
|
ExtQuotes::ExtQuotes(QWidget *parent, const QString filePath)
|
||||||
const QStringList directories)
|
: AbstractExtItem(parent, filePath)
|
||||||
: AbstractExtItem(parent, quotesName, directories)
|
|
||||||
, ui(new Ui::ExtQuotes)
|
, ui(new Ui::ExtQuotes)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
|
if (!filePath.isEmpty())
|
||||||
readConfiguration();
|
readConfiguration();
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
translate();
|
translate();
|
||||||
@ -76,11 +76,10 @@ ExtQuotes::~ExtQuotes()
|
|||||||
|
|
||||||
ExtQuotes *ExtQuotes::copy(const QString _fileName, const int _number)
|
ExtQuotes *ExtQuotes::copy(const QString _fileName, const int _number)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "File" << _fileName;
|
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
||||||
qCDebug(LOG_LIB) << "Number" << _number;
|
|
||||||
|
|
||||||
ExtQuotes *item = new ExtQuotes(static_cast<QWidget *>(parent()), _fileName,
|
ExtQuotes *item
|
||||||
directories());
|
= new ExtQuotes(static_cast<QWidget *>(parent()), _fileName);
|
||||||
copyDefaults(item);
|
copyDefaults(item);
|
||||||
item->setNumber(_number);
|
item->setNumber(_number);
|
||||||
item->setTicker(ticker());
|
item->setTicker(ticker());
|
||||||
@ -97,7 +96,7 @@ QString ExtQuotes::ticker() const
|
|||||||
|
|
||||||
QString ExtQuotes::uniq() const
|
QString ExtQuotes::uniq() const
|
||||||
{
|
{
|
||||||
return m_ticker;
|
return ticker();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -106,6 +105,7 @@ void ExtQuotes::setTicker(const QString _ticker)
|
|||||||
qCDebug(LOG_LIB) << "Ticker" << _ticker;
|
qCDebug(LOG_LIB) << "Ticker" << _ticker;
|
||||||
|
|
||||||
m_ticker = _ticker;
|
m_ticker = _ticker;
|
||||||
|
initUrl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -113,19 +113,11 @@ void ExtQuotes::readConfiguration()
|
|||||||
{
|
{
|
||||||
AbstractExtItem::readConfiguration();
|
AbstractExtItem::readConfiguration();
|
||||||
|
|
||||||
for (int i = directories().count() - 1; i >= 0; i--) {
|
QSettings settings(fileName(), QSettings::IniFormat);
|
||||||
if (!QDir(directories().at(i))
|
|
||||||
.entryList(QDir::Files)
|
|
||||||
.contains(fileName()))
|
|
||||||
continue;
|
|
||||||
QSettings settings(
|
|
||||||
QString("%1/%2").arg(directories().at(i)).arg(fileName()),
|
|
||||||
QSettings::IniFormat);
|
|
||||||
|
|
||||||
settings.beginGroup(QString("Desktop Entry"));
|
settings.beginGroup(QString("Desktop Entry"));
|
||||||
setTicker(settings.value(QString("X-AW-Ticker"), m_ticker).toString());
|
setTicker(settings.value(QString("X-AW-Ticker"), ticker()).toString());
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
}
|
|
||||||
|
|
||||||
// update for current API
|
// update for current API
|
||||||
if ((apiVersion() > 0) && (apiVersion() < AWEQAPI)) {
|
if ((apiVersion() > 0) && (apiVersion() < AWEQAPI)) {
|
||||||
@ -135,15 +127,7 @@ void ExtQuotes::readConfiguration()
|
|||||||
writeConfiguration();
|
writeConfiguration();
|
||||||
}
|
}
|
||||||
|
|
||||||
// init query
|
bumpApi(AWEQAPI);
|
||||||
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(m_ticker));
|
|
||||||
m_url.setQuery(params);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -175,7 +159,7 @@ int ExtQuotes::showConfiguration(const QVariant args)
|
|||||||
ui->lineEdit_name->setText(name());
|
ui->lineEdit_name->setText(name());
|
||||||
ui->lineEdit_comment->setText(comment());
|
ui->lineEdit_comment->setText(comment());
|
||||||
ui->label_numberValue->setText(QString("%1").arg(number()));
|
ui->label_numberValue->setText(QString("%1").arg(number()));
|
||||||
ui->lineEdit_ticker->setText(m_ticker);
|
ui->lineEdit_ticker->setText(ticker());
|
||||||
ui->checkBox_active->setCheckState(isActive() ? Qt::Checked
|
ui->checkBox_active->setCheckState(isActive() ? Qt::Checked
|
||||||
: Qt::Unchecked);
|
: Qt::Unchecked);
|
||||||
ui->spinBox_interval->setValue(interval());
|
ui->spinBox_interval->setValue(interval());
|
||||||
@ -200,13 +184,11 @@ void ExtQuotes::writeConfiguration() const
|
|||||||
{
|
{
|
||||||
AbstractExtItem::writeConfiguration();
|
AbstractExtItem::writeConfiguration();
|
||||||
|
|
||||||
QSettings settings(
|
QSettings settings(writtableConfig(), QSettings::IniFormat);
|
||||||
QString("%1/%2").arg(directories().first()).arg(fileName()),
|
|
||||||
QSettings::IniFormat);
|
|
||||||
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
|
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
|
||||||
|
|
||||||
settings.beginGroup(QString("Desktop Entry"));
|
settings.beginGroup(QString("Desktop Entry"));
|
||||||
settings.setValue(QString("X-AW-Ticker"), m_ticker);
|
settings.setValue(QString("X-AW-Ticker"), ticker());
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
|
||||||
settings.sync();
|
settings.sync();
|
||||||
@ -235,35 +217,51 @@ void ExtQuotes::quotesReplyReceived(QNetworkReply *reply)
|
|||||||
// ask
|
// ask
|
||||||
value = jsonQuotes[QString("Ask")].toString().toDouble();
|
value = jsonQuotes[QString("Ask")].toString().toDouble();
|
||||||
values[tag(QString("askchg"))]
|
values[tag(QString("askchg"))]
|
||||||
= values[QString("ask")].toDouble() == 0.0
|
= values[tag(QString("ask"))].toDouble() == 0.0
|
||||||
? 0.0
|
? 0.0
|
||||||
: value - values[QString("ask")].toDouble();
|
: value - values[tag(QString("ask"))].toDouble();
|
||||||
values[tag(QString("percaskchg"))] = 100.0
|
values[tag(QString("percaskchg"))]
|
||||||
* values[QString("askchg")].toDouble()
|
= 100.0 * values[tag(QString("askchg"))].toDouble()
|
||||||
/ values[QString("ask")].toDouble();
|
/ values[tag(QString("ask"))].toDouble();
|
||||||
values[tag(QString("ask"))] = value;
|
values[tag(QString("ask"))] = value;
|
||||||
|
|
||||||
// bid
|
// bid
|
||||||
value = jsonQuotes[QString("Bid")].toString().toDouble();
|
value = jsonQuotes[QString("Bid")].toString().toDouble();
|
||||||
values[tag(QString("bidchg"))]
|
values[tag(QString("bidchg"))]
|
||||||
= values[QString("bid")].toDouble() == 0.0
|
= values[tag(QString("bid"))].toDouble() == 0.0
|
||||||
? 0.0
|
? 0.0
|
||||||
: value - values[QString("bid")].toDouble();
|
: value - values[tag(QString("bid"))].toDouble();
|
||||||
values[tag(QString("percbidchg"))] = 100.0
|
values[tag(QString("percbidchg"))]
|
||||||
* values[QString("bidchg")].toDouble()
|
= 100.0 * values[tag(QString("bidchg"))].toDouble()
|
||||||
/ values[QString("bid")].toDouble();
|
/ values[tag(QString("bid"))].toDouble();
|
||||||
values[tag(QString("bid"))] = value;
|
values[tag(QString("bid"))] = value;
|
||||||
|
|
||||||
// last trade
|
// last trade
|
||||||
value = jsonQuotes[QString("LastTradePriceOnly")].toString().toDouble();
|
value = jsonQuotes[QString("LastTradePriceOnly")].toString().toDouble();
|
||||||
values[tag(QString("pricechg"))]
|
values[tag(QString("pricechg"))]
|
||||||
= values[QString("price")].toDouble() == 0.0
|
= values[tag(QString("price"))].toDouble() == 0.0
|
||||||
? 0.0
|
? 0.0
|
||||||
: value - values[QString("price")].toDouble();
|
: value - values[tag(QString("price"))].toDouble();
|
||||||
values[tag(QString("percpricechg"))]
|
values[tag(QString("percpricechg"))]
|
||||||
= 100.0 * values[QString("pricechg")].toDouble()
|
= 100.0 * values[tag(QString("pricechg"))].toDouble()
|
||||||
/ values[QString("price")].toDouble();
|
/ values[tag(QString("price"))].toDouble();
|
||||||
values[tag(QString("price"))] = value;
|
values[tag(QString("price"))] = value;
|
||||||
|
|
||||||
|
emit(dataReceived(values));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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()));
|
||||||
|
m_url.setQuery(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -38,9 +38,7 @@ class ExtQuotes : public AbstractExtItem
|
|||||||
Q_PROPERTY(QString ticker READ ticker WRITE setTicker)
|
Q_PROPERTY(QString ticker READ ticker WRITE setTicker)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ExtQuotes(QWidget *parent = nullptr,
|
explicit ExtQuotes(QWidget *parent, const QString filePath = QString());
|
||||||
const QString quotesName = QString(),
|
|
||||||
const QStringList directories = QStringList());
|
|
||||||
virtual ~ExtQuotes();
|
virtual ~ExtQuotes();
|
||||||
ExtQuotes *copy(const QString _fileName, const int _number);
|
ExtQuotes *copy(const QString _fileName, const int _number);
|
||||||
// get methods
|
// get methods
|
||||||
@ -59,10 +57,11 @@ private slots:
|
|||||||
void quotesReplyReceived(QNetworkReply *reply);
|
void quotesReplyReceived(QNetworkReply *reply);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QNetworkAccessManager *m_manager;
|
QNetworkAccessManager *m_manager = nullptr;
|
||||||
QUrl m_url;
|
QUrl m_url;
|
||||||
bool isRunning = false;
|
bool isRunning = false;
|
||||||
Ui::ExtQuotes *ui;
|
Ui::ExtQuotes *ui = nullptr;
|
||||||
|
void initUrl();
|
||||||
void translate();
|
void translate();
|
||||||
// properties
|
// properties
|
||||||
QString m_ticker = QString("EURUSD=X");
|
QString m_ticker = QString("EURUSD=X");
|
||||||
|
@ -30,13 +30,13 @@
|
|||||||
#include "awdebug.h"
|
#include "awdebug.h"
|
||||||
|
|
||||||
|
|
||||||
ExtScript::ExtScript(QWidget *parent, const QString scriptName,
|
ExtScript::ExtScript(QWidget *parent, const QString filePath)
|
||||||
const QStringList directories)
|
: AbstractExtItem(parent, filePath)
|
||||||
: AbstractExtItem(parent, scriptName, directories)
|
|
||||||
, ui(new Ui::ExtScript)
|
, ui(new Ui::ExtScript)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
|
if (!filePath.isEmpty())
|
||||||
readConfiguration();
|
readConfiguration();
|
||||||
readJsonFilters();
|
readJsonFilters();
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
@ -65,13 +65,14 @@ ExtScript *ExtScript::copy(const QString _fileName, const int _number)
|
|||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
||||||
|
|
||||||
ExtScript *item = new ExtScript(static_cast<QWidget *>(parent()), _fileName,
|
ExtScript *item
|
||||||
directories());
|
= new ExtScript(static_cast<QWidget *>(parent()), _fileName);
|
||||||
copyDefaults(item);
|
copyDefaults(item);
|
||||||
item->setExecutable(executable());
|
item->setExecutable(executable());
|
||||||
item->setNumber(_number);
|
item->setNumber(_number);
|
||||||
item->setPrefix(prefix());
|
item->setPrefix(prefix());
|
||||||
item->setRedirect(redirect());
|
item->setRedirect(redirect());
|
||||||
|
item->setFilters(filters());
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
@ -103,14 +104,14 @@ ExtScript::Redirect ExtScript::redirect() const
|
|||||||
|
|
||||||
QString ExtScript::uniq() const
|
QString ExtScript::uniq() const
|
||||||
{
|
{
|
||||||
return m_executable;
|
return executable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString ExtScript::strRedirect() const
|
QString ExtScript::strRedirect() const
|
||||||
{
|
{
|
||||||
QString value;
|
QString value;
|
||||||
switch (m_redirect) {
|
switch (redirect()) {
|
||||||
case Redirect::stdout2stderr:
|
case Redirect::stdout2stderr:
|
||||||
value = QString("stdout2stderr");
|
value = QString("stdout2stderr");
|
||||||
break;
|
break;
|
||||||
@ -167,13 +168,13 @@ void ExtScript::setStrRedirect(const QString _redirect)
|
|||||||
qCDebug(LOG_LIB) << "Redirect" << _redirect;
|
qCDebug(LOG_LIB) << "Redirect" << _redirect;
|
||||||
|
|
||||||
if (_redirect == QString("stdout2sdterr"))
|
if (_redirect == QString("stdout2sdterr"))
|
||||||
m_redirect = Redirect::stdout2stderr;
|
setRedirect(Redirect::stdout2stderr);
|
||||||
else if (_redirect == QString("stderr2sdtout"))
|
else if (_redirect == QString("stderr2sdtout"))
|
||||||
m_redirect = Redirect::stderr2stdout;
|
setRedirect(Redirect::stderr2stdout);
|
||||||
else if (_redirect == QString("swap"))
|
else if (_redirect == QString("swap"))
|
||||||
m_redirect = Redirect::swap;
|
setRedirect(Redirect::swap);
|
||||||
else
|
else
|
||||||
m_redirect = Redirect::nothing;
|
setRedirect(Redirect::nothing);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -181,7 +182,7 @@ QString ExtScript::applyFilters(QString _value) const
|
|||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Value" << _value;
|
qCDebug(LOG_LIB) << "Value" << _value;
|
||||||
|
|
||||||
for (auto filt : m_filters) {
|
for (auto filt : filters()) {
|
||||||
qCInfo(LOG_LIB) << "Found filter" << filt;
|
qCInfo(LOG_LIB) << "Found filter" << filt;
|
||||||
QVariantMap filter = jsonFilters[filt].toMap();
|
QVariantMap filter = jsonFilters[filt].toMap();
|
||||||
if (filter.isEmpty()) {
|
if (filter.isEmpty()) {
|
||||||
@ -202,7 +203,7 @@ void ExtScript::updateFilter(const QString _filter, const bool _add)
|
|||||||
qCDebug(LOG_LIB) << "Should be added filters" << _add << "from" << _filter;
|
qCDebug(LOG_LIB) << "Should be added filters" << _add << "from" << _filter;
|
||||||
|
|
||||||
if (_add) {
|
if (_add) {
|
||||||
if (m_filters.contains(_filter))
|
if (filters().contains(_filter))
|
||||||
return;
|
return;
|
||||||
m_filters.append(_filter);
|
m_filters.append(_filter);
|
||||||
} else {
|
} else {
|
||||||
@ -215,34 +216,20 @@ void ExtScript::readConfiguration()
|
|||||||
{
|
{
|
||||||
AbstractExtItem::readConfiguration();
|
AbstractExtItem::readConfiguration();
|
||||||
|
|
||||||
for (int i = directories().count() - 1; i >= 0; i--) {
|
QSettings settings(fileName(), QSettings::IniFormat);
|
||||||
if (!QDir(directories().at(i))
|
|
||||||
.entryList(QDir::Files)
|
|
||||||
.contains(fileName()))
|
|
||||||
continue;
|
|
||||||
QSettings settings(
|
|
||||||
QString("%1/%2").arg(directories().at(i)).arg(fileName()),
|
|
||||||
QSettings::IniFormat);
|
|
||||||
|
|
||||||
settings.beginGroup(QString("Desktop Entry"));
|
settings.beginGroup(QString("Desktop Entry"));
|
||||||
setExecutable(settings.value(QString("Exec"), m_executable).toString());
|
setExecutable(settings.value(QString("Exec"), executable()).toString());
|
||||||
setPrefix(settings.value(QString("X-AW-Prefix"), m_prefix).toString());
|
setPrefix(settings.value(QString("X-AW-Prefix"), prefix()).toString());
|
||||||
setStrRedirect(
|
setStrRedirect(
|
||||||
settings.value(QString("X-AW-Redirect"), strRedirect()).toString());
|
settings.value(QString("X-AW-Redirect"), strRedirect()).toString());
|
||||||
// api == 3
|
// api == 3
|
||||||
setFilters(settings.value(QString("X-AW-Filters"), m_filters)
|
setFilters(settings.value(QString("X-AW-Filters"), filters())
|
||||||
.toString()
|
.toString()
|
||||||
.split(QChar(','), QString::SkipEmptyParts));
|
.split(QChar(','), QString::SkipEmptyParts));
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
}
|
|
||||||
|
|
||||||
// update for current API
|
bumpApi(AWESAPI);
|
||||||
if ((apiVersion() > 0) && (apiVersion() < AWESAPI)) {
|
|
||||||
qCWarning(LOG_LIB) << "Bump API version from" << apiVersion() << "to"
|
|
||||||
<< AWESAPI;
|
|
||||||
setApiVersion(AWESAPI);
|
|
||||||
writeConfiguration();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -277,17 +264,22 @@ QVariantHash ExtScript::run()
|
|||||||
{
|
{
|
||||||
if (!isActive())
|
if (!isActive())
|
||||||
return value;
|
return value;
|
||||||
|
if (process->state() != QProcess::NotRunning)
|
||||||
|
qCWarning(LOG_LIB) << "Another process is already running"
|
||||||
|
<< process->state();
|
||||||
|
|
||||||
if ((times == 1) && (process->state() == QProcess::NotRunning)) {
|
if ((times == 1) && (process->state() == QProcess::NotRunning)) {
|
||||||
QStringList cmdList;
|
QStringList cmdList;
|
||||||
if (!m_prefix.isEmpty())
|
if (!prefix().isEmpty())
|
||||||
cmdList.append(m_prefix);
|
cmdList.append(prefix());
|
||||||
cmdList.append(m_executable);
|
cmdList.append(executable());
|
||||||
qCInfo(LOG_LIB) << "Run cmd" << cmdList.join(QChar(' '));
|
qCInfo(LOG_LIB) << "Run cmd" << cmdList.join(QChar(' '));
|
||||||
process->start(cmdList.join(QChar(' ')));
|
process->start(cmdList.join(QChar(' ')));
|
||||||
} else if (times >= interval()) {
|
|
||||||
times = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// update value
|
||||||
|
if (times >= interval())
|
||||||
|
times = 0;
|
||||||
times++;
|
times++;
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
@ -301,19 +293,19 @@ int ExtScript::showConfiguration(const QVariant args)
|
|||||||
ui->lineEdit_name->setText(name());
|
ui->lineEdit_name->setText(name());
|
||||||
ui->lineEdit_comment->setText(comment());
|
ui->lineEdit_comment->setText(comment());
|
||||||
ui->label_numberValue->setText(QString("%1").arg(number()));
|
ui->label_numberValue->setText(QString("%1").arg(number()));
|
||||||
ui->lineEdit_command->setText(m_executable);
|
ui->lineEdit_command->setText(executable());
|
||||||
ui->lineEdit_prefix->setText(m_prefix);
|
ui->lineEdit_prefix->setText(prefix());
|
||||||
ui->checkBox_active->setCheckState(isActive() ? Qt::Checked
|
ui->checkBox_active->setCheckState(isActive() ? Qt::Checked
|
||||||
: Qt::Unchecked);
|
: Qt::Unchecked);
|
||||||
ui->comboBox_redirect->setCurrentIndex(static_cast<int>(m_redirect));
|
ui->comboBox_redirect->setCurrentIndex(static_cast<int>(redirect()));
|
||||||
ui->spinBox_interval->setValue(interval());
|
ui->spinBox_interval->setValue(interval());
|
||||||
// filters
|
// filters
|
||||||
ui->checkBox_colorFilter->setCheckState(
|
ui->checkBox_colorFilter->setCheckState(
|
||||||
m_filters.contains(QString("color")) ? Qt::Checked : Qt::Unchecked);
|
filters().contains(QString("color")) ? Qt::Checked : Qt::Unchecked);
|
||||||
ui->checkBox_linesFilter->setCheckState(
|
ui->checkBox_linesFilter->setCheckState(
|
||||||
m_filters.contains(QString("newline")) ? Qt::Checked : Qt::Unchecked);
|
filters().contains(QString("newline")) ? Qt::Checked : Qt::Unchecked);
|
||||||
ui->checkBox_spaceFilter->setCheckState(
|
ui->checkBox_spaceFilter->setCheckState(
|
||||||
m_filters.contains(QString("space")) ? Qt::Checked : Qt::Unchecked);
|
filters().contains(QString("space")) ? Qt::Checked : Qt::Unchecked);
|
||||||
|
|
||||||
int ret = exec();
|
int ret = exec();
|
||||||
if (ret != 1)
|
if (ret != 1)
|
||||||
@ -325,7 +317,7 @@ int ExtScript::showConfiguration(const QVariant args)
|
|||||||
setExecutable(ui->lineEdit_command->text());
|
setExecutable(ui->lineEdit_command->text());
|
||||||
setPrefix(ui->lineEdit_prefix->text());
|
setPrefix(ui->lineEdit_prefix->text());
|
||||||
setActive(ui->checkBox_active->checkState() == Qt::Checked);
|
setActive(ui->checkBox_active->checkState() == Qt::Checked);
|
||||||
setStrRedirect(ui->comboBox_redirect->currentText());
|
setRedirect(static_cast<Redirect>(ui->comboBox_redirect->currentIndex()));
|
||||||
setInterval(ui->spinBox_interval->value());
|
setInterval(ui->spinBox_interval->value());
|
||||||
// filters
|
// filters
|
||||||
updateFilter(QString("color"),
|
updateFilter(QString("color"),
|
||||||
@ -344,16 +336,14 @@ void ExtScript::writeConfiguration() const
|
|||||||
{
|
{
|
||||||
AbstractExtItem::writeConfiguration();
|
AbstractExtItem::writeConfiguration();
|
||||||
|
|
||||||
QSettings settings(
|
QSettings settings(writtableConfig(), QSettings::IniFormat);
|
||||||
QString("%1/%2").arg(directories().first()).arg(fileName()),
|
|
||||||
QSettings::IniFormat);
|
|
||||||
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
|
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
|
||||||
|
|
||||||
settings.beginGroup(QString("Desktop Entry"));
|
settings.beginGroup(QString("Desktop Entry"));
|
||||||
settings.setValue(QString("Exec"), m_executable);
|
settings.setValue(QString("Exec"), executable());
|
||||||
settings.setValue(QString("X-AW-Prefix"), m_prefix);
|
settings.setValue(QString("X-AW-Prefix"), prefix());
|
||||||
settings.setValue(QString("X-AW-Redirect"), strRedirect());
|
settings.setValue(QString("X-AW-Redirect"), strRedirect());
|
||||||
settings.setValue(QString("X-AW-Filters"), m_filters.join(QChar(',')));
|
settings.setValue(QString("X-AW-Filters"), filters().join(QChar(',')));
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
|
||||||
settings.sync();
|
settings.sync();
|
||||||
@ -373,7 +363,7 @@ void ExtScript::updateValue()
|
|||||||
qCInfo(LOG_LIB) << "Output" << qoutput;
|
qCInfo(LOG_LIB) << "Output" << qoutput;
|
||||||
QString strValue;
|
QString strValue;
|
||||||
|
|
||||||
switch (m_redirect) {
|
switch (redirect()) {
|
||||||
case Redirect::stdout2stderr:
|
case Redirect::stdout2stderr:
|
||||||
break;
|
break;
|
||||||
case Redirect::stderr2stdout:
|
case Redirect::stderr2stdout:
|
||||||
@ -389,6 +379,7 @@ void ExtScript::updateValue()
|
|||||||
|
|
||||||
// filters
|
// filters
|
||||||
value[tag(QString("custom"))] = applyFilters(strValue);
|
value[tag(QString("custom"))] = applyFilters(strValue);
|
||||||
|
emit(dataReceived(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -37,11 +37,14 @@ class ExtScript : public AbstractExtItem
|
|||||||
Q_PROPERTY(Redirect redirect READ redirect WRITE setRedirect)
|
Q_PROPERTY(Redirect redirect READ redirect WRITE setRedirect)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum class Redirect { stdout2stderr, nothing, stderr2stdout, swap };
|
enum class Redirect {
|
||||||
|
stdout2stderr = 0,
|
||||||
|
nothing = 1,
|
||||||
|
stderr2stdout = 2,
|
||||||
|
swap = 3
|
||||||
|
};
|
||||||
|
|
||||||
explicit ExtScript(QWidget *parent = nullptr,
|
explicit ExtScript(QWidget *parent, const QString filePath = QString());
|
||||||
const QString scriptName = QString(),
|
|
||||||
const QStringList directories = QStringList());
|
|
||||||
virtual ~ExtScript();
|
virtual ~ExtScript();
|
||||||
ExtScript *copy(const QString _fileName, const int _number);
|
ExtScript *copy(const QString _fileName, const int _number);
|
||||||
// get methods
|
// get methods
|
||||||
@ -74,7 +77,7 @@ private slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QProcess *process = nullptr;
|
QProcess *process = nullptr;
|
||||||
Ui::ExtScript *ui;
|
Ui::ExtScript *ui = nullptr;
|
||||||
void translate();
|
void translate();
|
||||||
// properties
|
// properties
|
||||||
QString m_executable = QString("/usr/bin/true");
|
QString m_executable = QString("/usr/bin/true");
|
||||||
|
@ -28,13 +28,13 @@
|
|||||||
#include "awdebug.h"
|
#include "awdebug.h"
|
||||||
|
|
||||||
|
|
||||||
ExtUpgrade::ExtUpgrade(QWidget *parent, const QString upgradeName,
|
ExtUpgrade::ExtUpgrade(QWidget *parent, const QString filePath)
|
||||||
const QStringList directories)
|
: AbstractExtItem(parent, filePath)
|
||||||
: AbstractExtItem(parent, upgradeName, directories)
|
|
||||||
, ui(new Ui::ExtUpgrade)
|
, ui(new Ui::ExtUpgrade)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
|
if (!filePath.isEmpty())
|
||||||
readConfiguration();
|
readConfiguration();
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
translate();
|
translate();
|
||||||
@ -61,8 +61,8 @@ ExtUpgrade *ExtUpgrade::copy(const QString _fileName, const int _number)
|
|||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
||||||
|
|
||||||
ExtUpgrade *item = new ExtUpgrade(static_cast<QWidget *>(parent()),
|
ExtUpgrade *item
|
||||||
_fileName, directories());
|
= new ExtUpgrade(static_cast<QWidget *>(parent()), _fileName);
|
||||||
copyDefaults(item);
|
copyDefaults(item);
|
||||||
item->setExecutable(executable());
|
item->setExecutable(executable());
|
||||||
item->setFilter(filter());
|
item->setFilter(filter());
|
||||||
@ -93,7 +93,7 @@ int ExtUpgrade::null() const
|
|||||||
|
|
||||||
QString ExtUpgrade::uniq() const
|
QString ExtUpgrade::uniq() const
|
||||||
{
|
{
|
||||||
return m_executable;
|
return executable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -127,30 +127,16 @@ void ExtUpgrade::readConfiguration()
|
|||||||
{
|
{
|
||||||
AbstractExtItem::readConfiguration();
|
AbstractExtItem::readConfiguration();
|
||||||
|
|
||||||
for (int i = directories().count() - 1; i >= 0; i--) {
|
QSettings settings(fileName(), QSettings::IniFormat);
|
||||||
if (!QDir(directories().at(i))
|
|
||||||
.entryList(QDir::Files)
|
|
||||||
.contains(fileName()))
|
|
||||||
continue;
|
|
||||||
QSettings settings(
|
|
||||||
QString("%1/%2").arg(directories().at(i)).arg(fileName()),
|
|
||||||
QSettings::IniFormat);
|
|
||||||
|
|
||||||
settings.beginGroup(QString("Desktop Entry"));
|
settings.beginGroup(QString("Desktop Entry"));
|
||||||
setExecutable(settings.value(QString("Exec"), m_executable).toString());
|
setExecutable(settings.value(QString("Exec"), executable()).toString());
|
||||||
setNull(settings.value(QString("X-AW-Null"), m_null).toInt());
|
setNull(settings.value(QString("X-AW-Null"), null()).toInt());
|
||||||
// api == 3
|
// api == 3
|
||||||
setFilter(settings.value(QString("X-AW-Filter"), m_filter).toString());
|
setFilter(settings.value(QString("X-AW-Filter"), filter()).toString());
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
}
|
|
||||||
|
|
||||||
// update for current API
|
bumpApi(AWEUAPI);
|
||||||
if ((apiVersion() > 0) && (apiVersion() < AWEUAPI)) {
|
|
||||||
qCWarning(LOG_LIB) << "Bump API version from" << apiVersion() << "to"
|
|
||||||
<< AWEUAPI;
|
|
||||||
setApiVersion(AWEUAPI);
|
|
||||||
writeConfiguration();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -160,12 +146,14 @@ QVariantHash ExtUpgrade::run()
|
|||||||
return value;
|
return value;
|
||||||
|
|
||||||
if ((times == 1) && (process->state() == QProcess::NotRunning)) {
|
if ((times == 1) && (process->state() == QProcess::NotRunning)) {
|
||||||
QString cmd = QString("sh -c \"%1\"").arg(m_executable);
|
QString cmd = QString("sh -c \"%1\"").arg(executable());
|
||||||
qCInfo(LOG_LIB) << "Run cmd" << cmd;
|
qCInfo(LOG_LIB) << "Run cmd" << cmd;
|
||||||
process->start(cmd);
|
process->start(cmd);
|
||||||
} else if (times >= interval()) {
|
|
||||||
times = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// update value
|
||||||
|
if (times >= interval())
|
||||||
|
times = 0;
|
||||||
times++;
|
times++;
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
@ -179,11 +167,11 @@ int ExtUpgrade::showConfiguration(const QVariant args)
|
|||||||
ui->lineEdit_name->setText(name());
|
ui->lineEdit_name->setText(name());
|
||||||
ui->lineEdit_comment->setText(comment());
|
ui->lineEdit_comment->setText(comment());
|
||||||
ui->label_numberValue->setText(QString("%1").arg(number()));
|
ui->label_numberValue->setText(QString("%1").arg(number()));
|
||||||
ui->lineEdit_command->setText(m_executable);
|
ui->lineEdit_command->setText(executable());
|
||||||
ui->lineEdit_filter->setText(m_filter);
|
ui->lineEdit_filter->setText(filter());
|
||||||
ui->checkBox_active->setCheckState(isActive() ? Qt::Checked
|
ui->checkBox_active->setCheckState(isActive() ? Qt::Checked
|
||||||
: Qt::Unchecked);
|
: Qt::Unchecked);
|
||||||
ui->spinBox_null->setValue(m_null);
|
ui->spinBox_null->setValue(null());
|
||||||
ui->spinBox_interval->setValue(interval());
|
ui->spinBox_interval->setValue(interval());
|
||||||
|
|
||||||
int ret = exec();
|
int ret = exec();
|
||||||
@ -208,15 +196,13 @@ void ExtUpgrade::writeConfiguration() const
|
|||||||
{
|
{
|
||||||
AbstractExtItem::writeConfiguration();
|
AbstractExtItem::writeConfiguration();
|
||||||
|
|
||||||
QSettings settings(
|
QSettings settings(writtableConfig(), QSettings::IniFormat);
|
||||||
QString("%1/%2").arg(directories().first()).arg(fileName()),
|
|
||||||
QSettings::IniFormat);
|
|
||||||
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
|
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
|
||||||
|
|
||||||
settings.beginGroup(QString("Desktop Entry"));
|
settings.beginGroup(QString("Desktop Entry"));
|
||||||
settings.setValue(QString("Exec"), m_executable);
|
settings.setValue(QString("Exec"), executable());
|
||||||
settings.setValue(QString("X-AW-Filter"), m_filter);
|
settings.setValue(QString("X-AW-Filter"), filter());
|
||||||
settings.setValue(QString("X-AW-Null"), m_null);
|
settings.setValue(QString("X-AW-Null"), null());
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
|
||||||
settings.sync();
|
settings.sync();
|
||||||
@ -232,13 +218,15 @@ void ExtUpgrade::updateValue()
|
|||||||
->toUnicode(process->readAllStandardOutput())
|
->toUnicode(process->readAllStandardOutput())
|
||||||
.trimmed();
|
.trimmed();
|
||||||
value[tag(QString("pkgcount"))] = [this](QString output) {
|
value[tag(QString("pkgcount"))] = [this](QString output) {
|
||||||
return m_filter.isEmpty()
|
return filter().isEmpty()
|
||||||
? output.split(QChar('\n'), QString::SkipEmptyParts).count()
|
? output.split(QChar('\n'), QString::SkipEmptyParts).count()
|
||||||
- m_null
|
- null()
|
||||||
: output.split(QChar('\n'), QString::SkipEmptyParts)
|
: output.split(QChar('\n'), QString::SkipEmptyParts)
|
||||||
.filter(QRegExp(m_filter))
|
.filter(QRegExp(filter()))
|
||||||
.count();
|
.count();
|
||||||
}(qoutput);
|
}(qoutput);
|
||||||
|
|
||||||
|
emit(dataReceived(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -36,9 +36,7 @@ class ExtUpgrade : public AbstractExtItem
|
|||||||
Q_PROPERTY(int null READ null WRITE setNull)
|
Q_PROPERTY(int null READ null WRITE setNull)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ExtUpgrade(QWidget *parent = nullptr,
|
explicit ExtUpgrade(QWidget *parent, const QString filePath = QString());
|
||||||
const QString upgradeName = QString(),
|
|
||||||
const QStringList directories = QStringList());
|
|
||||||
virtual ~ExtUpgrade();
|
virtual ~ExtUpgrade();
|
||||||
ExtUpgrade *copy(const QString _fileName, const int _number);
|
ExtUpgrade *copy(const QString _fileName, const int _number);
|
||||||
// get methods
|
// get methods
|
||||||
@ -62,7 +60,7 @@ private slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QProcess *process = nullptr;
|
QProcess *process = nullptr;
|
||||||
Ui::ExtUpgrade *ui;
|
Ui::ExtUpgrade *ui = nullptr;
|
||||||
void translate();
|
void translate();
|
||||||
// properties
|
// properties
|
||||||
QString m_executable = QString("/usr/bin/true");
|
QString m_executable = QString("/usr/bin/true");
|
||||||
|
@ -27,20 +27,21 @@
|
|||||||
#include <QNetworkRequest>
|
#include <QNetworkRequest>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
#include <QUrlQuery>
|
|
||||||
|
|
||||||
#include <qreplytimeout/qreplytimeout.h>
|
#include <qreplytimeout/qreplytimeout.h>
|
||||||
|
|
||||||
#include "awdebug.h"
|
#include "awdebug.h"
|
||||||
|
#include "owmweatherprovider.h"
|
||||||
|
#include "yahooweatherprovider.h"
|
||||||
|
|
||||||
|
|
||||||
ExtWeather::ExtWeather(QWidget *parent, const QString weatherName,
|
ExtWeather::ExtWeather(QWidget *parent, const QString filePath)
|
||||||
const QStringList directories)
|
: AbstractExtItem(parent, filePath)
|
||||||
: AbstractExtItem(parent, weatherName, directories)
|
|
||||||
, ui(new Ui::ExtWeather)
|
, ui(new Ui::ExtWeather)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
|
if (!filePath.isEmpty())
|
||||||
readConfiguration();
|
readConfiguration();
|
||||||
readJsonMap();
|
readJsonMap();
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
@ -68,6 +69,7 @@ ExtWeather::~ExtWeather()
|
|||||||
SLOT(weatherReplyReceived(QNetworkReply *)));
|
SLOT(weatherReplyReceived(QNetworkReply *)));
|
||||||
|
|
||||||
m_manager->deleteLater();
|
m_manager->deleteLater();
|
||||||
|
delete m_providerObject;
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,13 +78,14 @@ ExtWeather *ExtWeather::copy(const QString _fileName, const int _number)
|
|||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "File" << _fileName << "number" << _number;
|
qCDebug(LOG_LIB) << "File" << _fileName << "number" << _number;
|
||||||
|
|
||||||
ExtWeather *item = new ExtWeather(static_cast<QWidget *>(parent()),
|
ExtWeather *item
|
||||||
_fileName, directories());
|
= new ExtWeather(static_cast<QWidget *>(parent()), _fileName);
|
||||||
copyDefaults(item);
|
copyDefaults(item);
|
||||||
item->setCity(city());
|
item->setCity(city());
|
||||||
item->setCountry(country());
|
item->setCountry(country());
|
||||||
item->setImage(image());
|
item->setImage(image());
|
||||||
item->setNumber(_number);
|
item->setNumber(_number);
|
||||||
|
item->setProvider(provider());
|
||||||
item->setTs(ts());
|
item->setTs(ts());
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
@ -117,6 +120,28 @@ bool ExtWeather::image() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ExtWeather::Provider ExtWeather::provider() const
|
||||||
|
{
|
||||||
|
return m_provider;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString ExtWeather::strProvider() const
|
||||||
|
{
|
||||||
|
QString value;
|
||||||
|
switch (m_provider) {
|
||||||
|
case Provider::OWM:
|
||||||
|
value = QString("OWM");
|
||||||
|
break;
|
||||||
|
case Provider::Yahoo:
|
||||||
|
value = QString("Yahoo");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int ExtWeather::ts() const
|
int ExtWeather::ts() const
|
||||||
{
|
{
|
||||||
return m_ts;
|
return m_ts;
|
||||||
@ -125,7 +150,7 @@ int ExtWeather::ts() const
|
|||||||
|
|
||||||
QString ExtWeather::uniq() const
|
QString ExtWeather::uniq() const
|
||||||
{
|
{
|
||||||
return QString("%1 (%2) at %3").arg(m_city).arg(m_country).arg(m_ts);
|
return QString("%1 (%2) at %3").arg(city()).arg(country()).arg(ts());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -134,6 +159,7 @@ void ExtWeather::setCity(const QString _city)
|
|||||||
qCDebug(LOG_LIB) << "City" << _city;
|
qCDebug(LOG_LIB) << "City" << _city;
|
||||||
|
|
||||||
m_city = _city;
|
m_city = _city;
|
||||||
|
initProvider();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -142,6 +168,7 @@ void ExtWeather::setCountry(const QString _country)
|
|||||||
qCDebug(LOG_LIB) << "Country" << _country;
|
qCDebug(LOG_LIB) << "Country" << _country;
|
||||||
|
|
||||||
m_country = _country;
|
m_country = _country;
|
||||||
|
initProvider();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -153,11 +180,32 @@ void ExtWeather::setImage(const bool _image)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ExtWeather::setProvider(const Provider _provider)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Provider" << static_cast<int>(_provider);
|
||||||
|
|
||||||
|
m_provider = _provider;
|
||||||
|
initProvider();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ExtWeather::setStrProvider(const QString _provider)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Provider" << _provider;
|
||||||
|
|
||||||
|
if (_provider == QString("Yahoo"))
|
||||||
|
setProvider(Provider::Yahoo);
|
||||||
|
else
|
||||||
|
setProvider(Provider::OWM);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void ExtWeather::setTs(const int _ts)
|
void ExtWeather::setTs(const int _ts)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Timestamp" << _ts;
|
qCDebug(LOG_LIB) << "Timestamp" << _ts;
|
||||||
|
|
||||||
m_ts = _ts;
|
m_ts = _ts;
|
||||||
|
initProvider();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -165,44 +213,21 @@ void ExtWeather::readConfiguration()
|
|||||||
{
|
{
|
||||||
AbstractExtItem::readConfiguration();
|
AbstractExtItem::readConfiguration();
|
||||||
|
|
||||||
for (int i = directories().count() - 1; i >= 0; i--) {
|
QSettings settings(fileName(), QSettings::IniFormat);
|
||||||
if (!QDir(directories().at(i))
|
|
||||||
.entryList(QDir::Files)
|
|
||||||
.contains(fileName()))
|
|
||||||
continue;
|
|
||||||
QSettings settings(
|
|
||||||
QString("%1/%2").arg(directories().at(i)).arg(fileName()),
|
|
||||||
QSettings::IniFormat);
|
|
||||||
|
|
||||||
settings.beginGroup(QString("Desktop Entry"));
|
settings.beginGroup(QString("Desktop Entry"));
|
||||||
setCity(settings.value(QString("X-AW-City"), m_city).toString());
|
setCity(settings.value(QString("X-AW-City"), city()).toString());
|
||||||
setCountry(
|
setCountry(settings.value(QString("X-AW-Country"), country()).toString());
|
||||||
settings.value(QString("X-AW-Country"), m_country).toString());
|
setTs(settings.value(QString("X-AW-TS"), ts()).toInt());
|
||||||
setTs(settings.value(QString("X-AW-TS"), m_ts).toInt());
|
|
||||||
// api == 2
|
// api == 2
|
||||||
setImage(
|
setImage(settings.value(QString("X-AW-Image"), QVariant(image())).toString()
|
||||||
settings.value(QString("X-AW-Image"), QVariant(m_image)).toString()
|
|
||||||
== QString("true"));
|
== QString("true"));
|
||||||
|
// api == 3
|
||||||
|
setStrProvider(
|
||||||
|
settings.value(QString("X-AW-Provider"), strProvider()).toString());
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
}
|
|
||||||
|
|
||||||
// update for current API
|
bumpApi(AWEWAPI);
|
||||||
if ((apiVersion() > 0) && (apiVersion() < AWEWAPI)) {
|
|
||||||
qCWarning(LOG_LIB) << "Bump API version from" << apiVersion() << "to"
|
|
||||||
<< AWEWAPI;
|
|
||||||
setApiVersion(AWEWAPI);
|
|
||||||
writeConfiguration();
|
|
||||||
}
|
|
||||||
|
|
||||||
// init query
|
|
||||||
m_url = QUrl(YAHOO_WEATHER_URL);
|
|
||||||
QUrlQuery params;
|
|
||||||
params.addQueryItem(QString("format"), QString("json"));
|
|
||||||
params.addQueryItem(QString("env"),
|
|
||||||
QString("store://datatables.org/alltableswithkeys"));
|
|
||||||
params.addQueryItem(QString("q"),
|
|
||||||
QString(YAHOO_WEATHER_QUERY).arg(m_city, m_country));
|
|
||||||
m_url.setQuery(params);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -240,7 +265,8 @@ QVariantHash ExtWeather::run()
|
|||||||
if (times == 1) {
|
if (times == 1) {
|
||||||
qCInfo(LOG_LIB) << "Send request";
|
qCInfo(LOG_LIB) << "Send request";
|
||||||
isRunning = true;
|
isRunning = true;
|
||||||
QNetworkReply *reply = m_manager->get(QNetworkRequest(m_url));
|
QNetworkReply *reply
|
||||||
|
= m_manager->get(QNetworkRequest(m_providerObject->url()));
|
||||||
new QReplyTimeout(reply, REQUEST_TIMEOUT);
|
new QReplyTimeout(reply, REQUEST_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -260,10 +286,11 @@ int ExtWeather::showConfiguration(const QVariant args)
|
|||||||
ui->lineEdit_name->setText(name());
|
ui->lineEdit_name->setText(name());
|
||||||
ui->lineEdit_comment->setText(comment());
|
ui->lineEdit_comment->setText(comment());
|
||||||
ui->label_numberValue->setText(QString("%1").arg(number()));
|
ui->label_numberValue->setText(QString("%1").arg(number()));
|
||||||
ui->lineEdit_city->setText(m_city);
|
ui->comboBox_provider->setCurrentIndex(static_cast<int>(provider()));
|
||||||
ui->lineEdit_country->setText(m_country);
|
ui->lineEdit_city->setText(city());
|
||||||
ui->spinBox_timestamp->setValue(m_ts);
|
ui->lineEdit_country->setText(country());
|
||||||
ui->checkBox_image->setCheckState(m_image ? Qt::Checked : Qt::Unchecked);
|
ui->spinBox_timestamp->setValue(ts());
|
||||||
|
ui->checkBox_image->setCheckState(image() ? Qt::Checked : Qt::Unchecked);
|
||||||
ui->checkBox_active->setCheckState(isActive() ? Qt::Checked
|
ui->checkBox_active->setCheckState(isActive() ? Qt::Checked
|
||||||
: Qt::Unchecked);
|
: Qt::Unchecked);
|
||||||
ui->spinBox_interval->setValue(interval());
|
ui->spinBox_interval->setValue(interval());
|
||||||
@ -277,6 +304,7 @@ int ExtWeather::showConfiguration(const QVariant args)
|
|||||||
setApiVersion(AWEWAPI);
|
setApiVersion(AWEWAPI);
|
||||||
setCity(ui->lineEdit_city->text());
|
setCity(ui->lineEdit_city->text());
|
||||||
setCountry(ui->lineEdit_country->text());
|
setCountry(ui->lineEdit_country->text());
|
||||||
|
setProvider(static_cast<Provider>(ui->comboBox_provider->currentIndex()));
|
||||||
setTs(ui->spinBox_timestamp->value());
|
setTs(ui->spinBox_timestamp->value());
|
||||||
setImage(ui->checkBox_image->checkState() == Qt::Checked);
|
setImage(ui->checkBox_image->checkState() == Qt::Checked);
|
||||||
setActive(ui->checkBox_active->checkState() == Qt::Checked);
|
setActive(ui->checkBox_active->checkState() == Qt::Checked);
|
||||||
@ -291,16 +319,15 @@ void ExtWeather::writeConfiguration() const
|
|||||||
{
|
{
|
||||||
AbstractExtItem::writeConfiguration();
|
AbstractExtItem::writeConfiguration();
|
||||||
|
|
||||||
QSettings settings(
|
QSettings settings(writtableConfig(), QSettings::IniFormat);
|
||||||
QString("%1/%2").arg(directories().first()).arg(fileName()),
|
|
||||||
QSettings::IniFormat);
|
|
||||||
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
|
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
|
||||||
|
|
||||||
settings.beginGroup(QString("Desktop Entry"));
|
settings.beginGroup(QString("Desktop Entry"));
|
||||||
settings.setValue(QString("X-AW-City"), m_city);
|
settings.setValue(QString("X-AW-City"), city());
|
||||||
settings.setValue(QString("X-AW-Country"), m_country);
|
settings.setValue(QString("X-AW-Country"), country());
|
||||||
settings.setValue(QString("X-AW-Image"), m_image);
|
settings.setValue(QString("X-AW-Image"), image());
|
||||||
settings.setValue(QString("X-AW-TS"), m_ts);
|
settings.setValue(QString("X-AW-Provider"), strProvider());
|
||||||
|
settings.setValue(QString("X-AW-TS"), ts());
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
|
||||||
settings.sync();
|
settings.sync();
|
||||||
@ -322,53 +349,31 @@ void ExtWeather::weatherReplyReceived(QNetworkReply *reply)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert to map
|
QVariantHash data = m_providerObject->parse(jsonDoc.toVariant().toMap());
|
||||||
QVariantMap json = jsonDoc.toVariant().toMap()[QString("query")].toMap();
|
if (data.isEmpty())
|
||||||
if (json[QString("count")].toInt() != 1) {
|
|
||||||
qCWarning(LOG_LIB) << "Found data count"
|
|
||||||
<< json[QString("count")].toInt() << "is not 1";
|
|
||||||
return;
|
return;
|
||||||
}
|
values = data;
|
||||||
QVariantMap results
|
values[tag(QString("weather"))]
|
||||||
= json[QString("results")].toMap()[QString("channel")].toMap();
|
= weatherFromInt(values[tag(QString("weatherId"))].toInt());
|
||||||
QVariantMap item = results[QString("item")].toMap();
|
|
||||||
|
|
||||||
if (m_ts == 0) {
|
emit(dataReceived(values));
|
||||||
// current weather
|
}
|
||||||
int id = item[QString("condition")].toMap()[QString("code")].toInt();
|
|
||||||
values[tag(QString("weatherId"))] = id;
|
|
||||||
values[tag(QString("weather"))] = weatherFromInt(id);
|
void ExtWeather::initProvider()
|
||||||
values[tag(QString("temperature"))]
|
{
|
||||||
= item[QString("condition")].toMap()[QString("temp")].toInt();
|
delete m_providerObject;
|
||||||
values[tag(QString("timestamp"))]
|
|
||||||
= item[QString("condition")].toMap()[QString("date")].toString();
|
switch (m_provider) {
|
||||||
values[tag(QString("humidity"))] = results[QString("atmosphere")]
|
case Provider::OWM:
|
||||||
.toMap()[QString("humidity")]
|
m_providerObject = new OWMWeatherProvider(this, number());
|
||||||
.toInt();
|
break;
|
||||||
values[tag(QString("pressure"))]
|
case Provider::Yahoo:
|
||||||
= static_cast<int>(results[QString("atmosphere")]
|
m_providerObject = new YahooWeatherProvider(this, number());
|
||||||
.toMap()[QString("pressure")]
|
break;
|
||||||
.toFloat());
|
|
||||||
} else {
|
|
||||||
// forecast weather
|
|
||||||
QVariantList weatherList = item[QString("forecast")].toList();
|
|
||||||
QVariantMap weatherMap = weatherList.count() < m_ts
|
|
||||||
? weatherList.last().toMap()
|
|
||||||
: weatherList.at(m_ts).toMap();
|
|
||||||
int id = weatherMap[QString("code")].toInt();
|
|
||||||
values[tag(QString("weatherId"))] = id;
|
|
||||||
values[tag(QString("weather"))] = weatherFromInt(id);
|
|
||||||
values[tag(QString("timestamp"))]
|
|
||||||
= weatherMap[QString("date")].toString();
|
|
||||||
// yahoo provides high and low temperatures. Lets calculate average one
|
|
||||||
values[tag(QString("temperature"))]
|
|
||||||
= (weatherMap[QString("high")].toFloat()
|
|
||||||
+ weatherMap[QString("low")].toFloat())
|
|
||||||
/ 2.0;
|
|
||||||
// ... and no forecast data for humidity and pressure
|
|
||||||
values[tag(QString("humidity"))] = 0;
|
|
||||||
values[tag(QString("pressure"))] = 0.0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return m_providerObject->initUrl(city(), country(), ts());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -377,6 +382,7 @@ void ExtWeather::translate()
|
|||||||
ui->label_name->setText(i18n("Name"));
|
ui->label_name->setText(i18n("Name"));
|
||||||
ui->label_comment->setText(i18n("Comment"));
|
ui->label_comment->setText(i18n("Comment"));
|
||||||
ui->label_number->setText(i18n("Tag"));
|
ui->label_number->setText(i18n("Tag"));
|
||||||
|
ui->label_provider->setText(i18n("Provider"));
|
||||||
ui->label_city->setText(i18n("City"));
|
ui->label_city->setText(i18n("City"));
|
||||||
ui->label_country->setText(i18n("Country"));
|
ui->label_country->setText(i18n("Country"));
|
||||||
ui->label_timestamp->setText(i18n("Timestamp"));
|
ui->label_timestamp->setText(i18n("Timestamp"));
|
||||||
|
@ -22,12 +22,8 @@
|
|||||||
|
|
||||||
#include "abstractextitem.h"
|
#include "abstractextitem.h"
|
||||||
|
|
||||||
#define YAHOO_WEATHER_URL "https://query.yahooapis.com/v1/public/yql"
|
|
||||||
#define YAHOO_WEATHER_QUERY \
|
|
||||||
"select * from weather.forecast where u='c' and woeid in (select woeid " \
|
|
||||||
"from geo.places(1) where text='%1, %2')"
|
|
||||||
|
|
||||||
|
|
||||||
|
class AbstractWeatherProvider;
|
||||||
namespace Ui
|
namespace Ui
|
||||||
{
|
{
|
||||||
class ExtWeather;
|
class ExtWeather;
|
||||||
@ -39,12 +35,14 @@ class ExtWeather : public AbstractExtItem
|
|||||||
Q_PROPERTY(QString city READ city WRITE setCity)
|
Q_PROPERTY(QString city READ city WRITE setCity)
|
||||||
Q_PROPERTY(QString country READ country WRITE setCountry)
|
Q_PROPERTY(QString country READ country WRITE setCountry)
|
||||||
Q_PROPERTY(bool image READ image WRITE setImage)
|
Q_PROPERTY(bool image READ image WRITE setImage)
|
||||||
|
Q_PROPERTY(Provider povider READ provider WRITE setProvider)
|
||||||
|
Q_PROPERTY(QString strPovider READ strProvider WRITE setStrProvider)
|
||||||
Q_PROPERTY(int ts READ ts WRITE setTs)
|
Q_PROPERTY(int ts READ ts WRITE setTs)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ExtWeather(QWidget *parent = nullptr,
|
enum class Provider { OWM = 0, Yahoo = 1 };
|
||||||
const QString weatherName = QString(),
|
|
||||||
const QStringList directories = QStringList());
|
explicit ExtWeather(QWidget *parent, const QString filePath = QString());
|
||||||
virtual ~ExtWeather();
|
virtual ~ExtWeather();
|
||||||
ExtWeather *copy(const QString _fileName, const int _number);
|
ExtWeather *copy(const QString _fileName, const int _number);
|
||||||
QString weatherFromInt(const int _id) const;
|
QString weatherFromInt(const int _id) const;
|
||||||
@ -52,12 +50,16 @@ public:
|
|||||||
QString city() const;
|
QString city() const;
|
||||||
QString country() const;
|
QString country() const;
|
||||||
bool image() const;
|
bool image() const;
|
||||||
|
Provider provider() const;
|
||||||
|
QString strProvider() const;
|
||||||
int ts() const;
|
int ts() const;
|
||||||
QString uniq() const;
|
QString uniq() const;
|
||||||
// set methods
|
// set methods
|
||||||
void setCity(const QString _city = QString("London"));
|
void setCity(const QString _city = QString("London"));
|
||||||
void setCountry(const QString _country = QString("uk"));
|
void setCountry(const QString _country = QString("uk"));
|
||||||
void setImage(const bool _image = false);
|
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 setTs(const int _ts = 0);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
@ -71,15 +73,17 @@ private slots:
|
|||||||
void weatherReplyReceived(QNetworkReply *reply);
|
void weatherReplyReceived(QNetworkReply *reply);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QNetworkAccessManager *m_manager;
|
QNetworkAccessManager *m_manager = nullptr;
|
||||||
QUrl m_url;
|
AbstractWeatherProvider *m_providerObject = nullptr;
|
||||||
bool isRunning = false;
|
bool isRunning = false;
|
||||||
Ui::ExtWeather *ui;
|
Ui::ExtWeather *ui = nullptr;
|
||||||
|
void initProvider();
|
||||||
void translate();
|
void translate();
|
||||||
// properties
|
// properties
|
||||||
QString m_city = QString("London");
|
QString m_city = QString("London");
|
||||||
QString m_country = QString("uk");
|
QString m_country = QString("uk");
|
||||||
bool m_image = false;
|
bool m_image = false;
|
||||||
|
Provider m_provider = Provider::OWM;
|
||||||
int m_ts = 0;
|
int m_ts = 0;
|
||||||
QVariantMap m_jsonMap = QVariantMap();
|
QVariantMap m_jsonMap = QVariantMap();
|
||||||
// values
|
// values
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>420</width>
|
<width>420</width>
|
||||||
<height>301</height>
|
<height>333</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
@ -81,6 +81,46 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="layout_provider">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_provider">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Provider</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QComboBox" name="comboBox_provider">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string notr="true">OWM</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string notr="true">Yahoo</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="layout_city">
|
<layout class="QHBoxLayout" name="layout_city">
|
||||||
<item>
|
<item>
|
||||||
|
@ -32,19 +32,17 @@
|
|||||||
#include "graphicalitemhelper.h"
|
#include "graphicalitemhelper.h"
|
||||||
|
|
||||||
|
|
||||||
GraphicalItem::GraphicalItem(QWidget *parent, const QString desktopName,
|
GraphicalItem::GraphicalItem(QWidget *parent, const QString filePath)
|
||||||
const QStringList directories)
|
: AbstractExtItem(parent, filePath)
|
||||||
: AbstractExtItem(parent, desktopName, directories)
|
|
||||||
, ui(new Ui::GraphicalItem)
|
, ui(new Ui::GraphicalItem)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
|
if (!filePath.isEmpty())
|
||||||
readConfiguration();
|
readConfiguration();
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
translate();
|
translate();
|
||||||
|
|
||||||
initScene();
|
|
||||||
|
|
||||||
connect(ui->checkBox_custom, SIGNAL(stateChanged(int)), this,
|
connect(ui->checkBox_custom, SIGNAL(stateChanged(int)), this,
|
||||||
SLOT(changeValue(int)));
|
SLOT(changeValue(int)));
|
||||||
connect(ui->comboBox_type, SIGNAL(currentIndexChanged(int)), this,
|
connect(ui->comboBox_type, SIGNAL(currentIndexChanged(int)), this,
|
||||||
@ -70,21 +68,21 @@ GraphicalItem *GraphicalItem::copy(const QString _fileName, const int _number)
|
|||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
||||||
|
|
||||||
GraphicalItem *item = new GraphicalItem(static_cast<QWidget *>(parent()),
|
GraphicalItem *item
|
||||||
_fileName, directories());
|
= new GraphicalItem(static_cast<QWidget *>(parent()), _fileName);
|
||||||
copyDefaults(item);
|
copyDefaults(item);
|
||||||
item->setActiveColor(m_activeColor);
|
item->setActiveColor(activeColor());
|
||||||
item->setBar(m_bar);
|
item->setBar(bar());
|
||||||
item->setCount(m_count);
|
item->setCount(count());
|
||||||
item->setCustom(m_custom);
|
item->setCustom(isCustom());
|
||||||
item->setDirection(m_direction);
|
item->setDirection(direction());
|
||||||
item->setHeight(m_height);
|
item->setItemHeight(itemHeight());
|
||||||
item->setInactiveColor(m_inactiveColor);
|
item->setInactiveColor(inactiveColor());
|
||||||
item->setMaxValue(m_maxValue);
|
item->setMaxValue(maxValue());
|
||||||
item->setMinValue(m_minValue);
|
item->setMinValue(minValue());
|
||||||
item->setNumber(_number);
|
item->setNumber(_number);
|
||||||
item->setType(m_type);
|
item->setType(type());
|
||||||
item->setWidth(m_width);
|
item->setItemWidth(itemWidth());
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
@ -97,34 +95,34 @@ QString GraphicalItem::image(const QVariant &value)
|
|||||||
m_scene->clear();
|
m_scene->clear();
|
||||||
int scale[2] = {1, 1};
|
int scale[2] = {1, 1};
|
||||||
float converted
|
float converted
|
||||||
= m_helper->getPercents(value.toFloat(), m_minValue, m_maxValue);
|
= m_helper->getPercents(value.toFloat(), minValue(), maxValue());
|
||||||
|
|
||||||
// paint
|
// paint
|
||||||
switch (m_type) {
|
switch (m_type) {
|
||||||
case Type::Vertical:
|
case Type::Vertical:
|
||||||
m_helper->paintVertical(converted);
|
m_helper->paintVertical(converted);
|
||||||
// scale
|
// scale
|
||||||
scale[1] = -2 * static_cast<int>(m_direction) + 1;
|
scale[1] = -2 * static_cast<int>(direction()) + 1;
|
||||||
break;
|
break;
|
||||||
case Type::Circle:
|
case Type::Circle:
|
||||||
m_helper->paintCircle(converted);
|
m_helper->paintCircle(converted);
|
||||||
// scale
|
// scale
|
||||||
scale[0] = -2 * static_cast<int>(m_direction) + 1;
|
scale[0] = -2 * static_cast<int>(direction()) + 1;
|
||||||
break;
|
break;
|
||||||
case Type::Graph:
|
case Type::Graph:
|
||||||
m_helper->paintGraph(converted);
|
m_helper->paintGraph(converted);
|
||||||
scale[0] = -2 * static_cast<int>(m_direction) + 1;
|
scale[0] = -2 * static_cast<int>(direction()) + 1;
|
||||||
scale[1] = -1;
|
scale[1] = -1;
|
||||||
break;
|
break;
|
||||||
case Type::Bars:
|
case Type::Bars:
|
||||||
m_helper->paintBars(converted);
|
m_helper->paintBars(converted);
|
||||||
scale[0] = -2 * static_cast<int>(m_direction) + 1;
|
scale[0] = -2 * static_cast<int>(direction()) + 1;
|
||||||
scale[1] = -1;
|
scale[1] = -1;
|
||||||
break;
|
break;
|
||||||
case Type::Horizontal:
|
case Type::Horizontal:
|
||||||
m_helper->paintHorizontal(converted);
|
m_helper->paintHorizontal(converted);
|
||||||
// scale
|
// scale
|
||||||
scale[0] = -2 * static_cast<int>(m_direction) + 1;
|
scale[0] = -2 * static_cast<int>(direction()) + 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,6 +139,31 @@ QString GraphicalItem::image(const QVariant &value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void GraphicalItem::initScene()
|
||||||
|
{
|
||||||
|
// cleanup
|
||||||
|
delete m_helper;
|
||||||
|
delete m_scene;
|
||||||
|
|
||||||
|
// init scene
|
||||||
|
m_scene = new QGraphicsScene();
|
||||||
|
m_scene->setBackgroundBrush(QBrush(Qt::NoBrush));
|
||||||
|
// init view
|
||||||
|
m_view = new QGraphicsView(m_scene);
|
||||||
|
m_view->setStyleSheet(QString("background: transparent"));
|
||||||
|
m_view->setContentsMargins(0, 0, 0, 0);
|
||||||
|
m_view->setFrameShape(QFrame::NoFrame);
|
||||||
|
m_view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
|
m_view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
|
m_view->resize(m_width + 5, m_height + 5);
|
||||||
|
|
||||||
|
// init helper
|
||||||
|
m_helper = new GraphicalItemHelper(this, m_scene);
|
||||||
|
m_helper->setParameters(activeColor(), inactiveColor(), itemWidth(),
|
||||||
|
itemHeight(), count());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QString GraphicalItem::bar() const
|
QString GraphicalItem::bar() const
|
||||||
{
|
{
|
||||||
return m_bar;
|
return m_bar;
|
||||||
@ -153,24 +176,36 @@ QString GraphicalItem::activeColor() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString GraphicalItem::inactiveColor() const
|
|
||||||
{
|
|
||||||
return m_inactiveColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int GraphicalItem::count() const
|
int GraphicalItem::count() const
|
||||||
{
|
{
|
||||||
return m_count;
|
return m_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString GraphicalItem::inactiveColor() const
|
||||||
|
{
|
||||||
|
return m_inactiveColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool GraphicalItem::isCustom() const
|
bool GraphicalItem::isCustom() const
|
||||||
{
|
{
|
||||||
return m_custom;
|
return m_custom;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int GraphicalItem::itemHeight() const
|
||||||
|
{
|
||||||
|
return m_height;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int GraphicalItem::itemWidth() const
|
||||||
|
{
|
||||||
|
return m_width;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
float GraphicalItem::maxValue() const
|
float GraphicalItem::maxValue() const
|
||||||
{
|
{
|
||||||
return m_maxValue;
|
return m_maxValue;
|
||||||
@ -192,7 +227,7 @@ GraphicalItem::Type GraphicalItem::type() const
|
|||||||
QString GraphicalItem::strType() const
|
QString GraphicalItem::strType() const
|
||||||
{
|
{
|
||||||
QString value;
|
QString value;
|
||||||
switch (m_type) {
|
switch (type()) {
|
||||||
case Type::Vertical:
|
case Type::Vertical:
|
||||||
value = QString("Vertical");
|
value = QString("Vertical");
|
||||||
break;
|
break;
|
||||||
@ -223,7 +258,7 @@ GraphicalItem::Direction GraphicalItem::direction() const
|
|||||||
QString GraphicalItem::strDirection() const
|
QString GraphicalItem::strDirection() const
|
||||||
{
|
{
|
||||||
QString value;
|
QString value;
|
||||||
switch (m_direction) {
|
switch (direction()) {
|
||||||
case Direction::RightToLeft:
|
case Direction::RightToLeft:
|
||||||
value = QString("RightToLeft");
|
value = QString("RightToLeft");
|
||||||
break;
|
break;
|
||||||
@ -236,27 +271,15 @@ QString GraphicalItem::strDirection() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int GraphicalItem::height() const
|
|
||||||
{
|
|
||||||
return m_height;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QStringList GraphicalItem::usedKeys() const
|
QStringList GraphicalItem::usedKeys() const
|
||||||
{
|
{
|
||||||
return m_usedKeys;
|
return m_usedKeys;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int GraphicalItem::width() const
|
|
||||||
{
|
|
||||||
return m_width;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QString GraphicalItem::uniq() const
|
QString GraphicalItem::uniq() const
|
||||||
{
|
{
|
||||||
return m_bar;
|
return bar();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -302,6 +325,26 @@ void GraphicalItem::setInactiveColor(const QString _color)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void GraphicalItem::setItemHeight(const int _height)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Height" << _height;
|
||||||
|
if (_height <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_height = _height;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void GraphicalItem::setItemWidth(const int _width)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Width" << _width;
|
||||||
|
if (_width <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_width = _width;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void GraphicalItem::setMaxValue(const float _value)
|
void GraphicalItem::setMaxValue(const float _value)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Max value" << _value;
|
qCDebug(LOG_LIB) << "Max value" << _value;
|
||||||
@ -362,94 +405,58 @@ void GraphicalItem::setStrDirection(const QString _direction)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void GraphicalItem::setHeight(const int _height)
|
|
||||||
{
|
|
||||||
qCDebug(LOG_LIB) << "Height" << _height;
|
|
||||||
if (_height <= 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
m_height = _height;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void GraphicalItem::setUsedKeys(const QStringList _usedKeys)
|
void GraphicalItem::setUsedKeys(const QStringList _usedKeys)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Used keys" << _usedKeys;
|
qCDebug(LOG_LIB) << "Used keys" << _usedKeys;
|
||||||
|
|
||||||
// remove dubs
|
// remove dubs
|
||||||
// HACK converting to set may break order
|
// HACK converting to set may break order
|
||||||
m_usedKeys.clear();
|
usedKeys().clear();
|
||||||
for (auto key : _usedKeys) {
|
for (auto key : _usedKeys) {
|
||||||
if (m_usedKeys.contains(key))
|
if (usedKeys().contains(key))
|
||||||
continue;
|
continue;
|
||||||
m_usedKeys.append(key);
|
usedKeys().append(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void GraphicalItem::setWidth(const int _width)
|
|
||||||
{
|
|
||||||
qCDebug(LOG_LIB) << "Width" << _width;
|
|
||||||
if (_width <= 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
m_width = _width;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void GraphicalItem::readConfiguration()
|
void GraphicalItem::readConfiguration()
|
||||||
{
|
{
|
||||||
AbstractExtItem::readConfiguration();
|
AbstractExtItem::readConfiguration();
|
||||||
|
|
||||||
for (int i = directories().count() - 1; i >= 0; i--) {
|
QSettings settings(fileName(), QSettings::IniFormat);
|
||||||
if (!QDir(directories().at(i))
|
|
||||||
.entryList(QDir::Files)
|
|
||||||
.contains(fileName()))
|
|
||||||
continue;
|
|
||||||
QSettings settings(
|
|
||||||
QString("%1/%2").arg(directories().at(i)).arg(fileName()),
|
|
||||||
QSettings::IniFormat);
|
|
||||||
|
|
||||||
settings.beginGroup(QString("Desktop Entry"));
|
settings.beginGroup(QString("Desktop Entry"));
|
||||||
setCount(settings.value(QString("X-AW-Count"), m_count).toInt());
|
setCount(settings.value(QString("X-AW-Count"), count()).toInt());
|
||||||
setCustom(settings.value(QString("X-AW-Custom"), m_custom).toBool());
|
setCustom(settings.value(QString("X-AW-Custom"), isCustom()).toBool());
|
||||||
setBar(settings.value(QString("X-AW-Value"), m_bar).toString());
|
setBar(settings.value(QString("X-AW-Value"), bar()).toString());
|
||||||
setMaxValue(settings.value(QString("X-AW-Max"), m_maxValue).toFloat());
|
setMaxValue(settings.value(QString("X-AW-Max"), maxValue()).toFloat());
|
||||||
setMinValue(settings.value(QString("X-AW-Min"), m_minValue).toFloat());
|
setMinValue(settings.value(QString("X-AW-Min"), minValue()).toFloat());
|
||||||
setActiveColor(
|
setActiveColor(
|
||||||
settings.value(QString("X-AW-ActiveColor"), m_activeColor)
|
settings.value(QString("X-AW-ActiveColor"), activeColor()).toString());
|
||||||
.toString());
|
|
||||||
setInactiveColor(
|
setInactiveColor(
|
||||||
settings.value(QString("X-AW-InactiveColor"), m_inactiveColor)
|
settings.value(QString("X-AW-InactiveColor"), inactiveColor())
|
||||||
.toString());
|
.toString());
|
||||||
setStrType(settings.value(QString("X-AW-Type"), strType()).toString());
|
setStrType(settings.value(QString("X-AW-Type"), strType()).toString());
|
||||||
setStrDirection(
|
setStrDirection(
|
||||||
settings.value(QString("X-AW-Direction"), strDirection())
|
settings.value(QString("X-AW-Direction"), strDirection()).toString());
|
||||||
.toString());
|
setItemHeight(settings.value(QString("X-AW-Height"), itemHeight()).toInt());
|
||||||
setHeight(settings.value(QString("X-AW-Height"), m_height).toInt());
|
setItemWidth(settings.value(QString("X-AW-Width"), itemWidth()).toInt());
|
||||||
setWidth(settings.value(QString("X-AW-Width"), m_width).toInt());
|
|
||||||
// api == 5
|
// api == 5
|
||||||
if (apiVersion() < 5) {
|
if (apiVersion() < 5) {
|
||||||
QString prefix;
|
QString prefix;
|
||||||
prefix = m_activeColor.startsWith(QString("/"))
|
prefix = activeColor().startsWith(QString("/")) ? QString("file://%1")
|
||||||
|
: QString("color://%1");
|
||||||
|
m_activeColor = prefix.arg(activeColor());
|
||||||
|
prefix = inactiveColor().startsWith(QString("/"))
|
||||||
? QString("file://%1")
|
? QString("file://%1")
|
||||||
: QString("color://%1");
|
: QString("color://%1");
|
||||||
m_activeColor = prefix.arg(m_activeColor);
|
m_inactiveColor = prefix.arg(inactiveColor());
|
||||||
prefix = m_inactiveColor.startsWith(QString("/"))
|
|
||||||
? QString("file://%1")
|
|
||||||
: QString("color://%1");
|
|
||||||
m_inactiveColor = prefix.arg(m_inactiveColor);
|
|
||||||
}
|
}
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
}
|
|
||||||
|
|
||||||
// update for current API
|
bumpApi(AWGIAPI);
|
||||||
if ((apiVersion() > 0) && (apiVersion() < AWGIAPI)) {
|
initScene();
|
||||||
qCWarning(LOG_LIB) << "Bump API version from" << apiVersion() << "to"
|
|
||||||
<< AWGIAPI;
|
|
||||||
setApiVersion(AWGIAPI);
|
|
||||||
writeConfiguration();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -461,31 +468,31 @@ int GraphicalItem::showConfiguration(const QVariant args)
|
|||||||
ui->lineEdit_name->setText(name());
|
ui->lineEdit_name->setText(name());
|
||||||
ui->lineEdit_comment->setText(comment());
|
ui->lineEdit_comment->setText(comment());
|
||||||
ui->label_numberValue->setText(QString("%1").arg(number()));
|
ui->label_numberValue->setText(QString("%1").arg(number()));
|
||||||
ui->checkBox_custom->setChecked(m_custom);
|
ui->checkBox_custom->setChecked(isCustom());
|
||||||
ui->comboBox_value->addItems(tags);
|
ui->comboBox_value->addItems(tags);
|
||||||
if (m_custom) {
|
if (isCustom()) {
|
||||||
ui->lineEdit_customValue->setText(m_bar);
|
ui->lineEdit_customValue->setText(bar());
|
||||||
} else {
|
} else {
|
||||||
ui->comboBox_value->addItem(m_bar);
|
ui->comboBox_value->addItem(bar());
|
||||||
ui->comboBox_value->setCurrentIndex(ui->comboBox_value->count() - 1);
|
ui->comboBox_value->setCurrentIndex(ui->comboBox_value->count() - 1);
|
||||||
}
|
}
|
||||||
ui->doubleSpinBox_max->setValue(m_maxValue);
|
ui->doubleSpinBox_max->setValue(maxValue());
|
||||||
ui->doubleSpinBox_min->setValue(m_minValue);
|
ui->doubleSpinBox_min->setValue(minValue());
|
||||||
ui->spinBox_count->setValue(m_count);
|
ui->spinBox_count->setValue(count());
|
||||||
if (m_helper->isColor(m_activeColor))
|
if (m_helper->isColor(activeColor()))
|
||||||
ui->comboBox_activeImageType->setCurrentIndex(0);
|
ui->comboBox_activeImageType->setCurrentIndex(0);
|
||||||
else
|
else
|
||||||
ui->comboBox_activeImageType->setCurrentIndex(1);
|
ui->comboBox_activeImageType->setCurrentIndex(1);
|
||||||
ui->lineEdit_activeColor->setText(m_activeColor);
|
ui->lineEdit_activeColor->setText(activeColor());
|
||||||
if (m_helper->isColor(m_inactiveColor))
|
if (m_helper->isColor(inactiveColor()))
|
||||||
ui->comboBox_inactiveImageType->setCurrentIndex(0);
|
ui->comboBox_inactiveImageType->setCurrentIndex(0);
|
||||||
else
|
else
|
||||||
ui->comboBox_inactiveImageType->setCurrentIndex(1);
|
ui->comboBox_inactiveImageType->setCurrentIndex(1);
|
||||||
ui->lineEdit_inactiveColor->setText(m_inactiveColor);
|
ui->lineEdit_inactiveColor->setText(inactiveColor());
|
||||||
ui->comboBox_type->setCurrentIndex(static_cast<int>(m_type));
|
ui->comboBox_type->setCurrentIndex(static_cast<int>(type()));
|
||||||
ui->comboBox_direction->setCurrentIndex(static_cast<int>(m_direction));
|
ui->comboBox_direction->setCurrentIndex(static_cast<int>(direction()));
|
||||||
ui->spinBox_height->setValue(m_height);
|
ui->spinBox_height->setValue(itemHeight());
|
||||||
ui->spinBox_width->setValue(m_width);
|
ui->spinBox_width->setValue(itemWidth());
|
||||||
|
|
||||||
// update UI
|
// update UI
|
||||||
emit(ui->comboBox_type->currentIndexChanged(
|
emit(ui->comboBox_type->currentIndexChanged(
|
||||||
@ -506,10 +513,11 @@ int GraphicalItem::showConfiguration(const QVariant args)
|
|||||||
setMinValue(ui->doubleSpinBox_min->value());
|
setMinValue(ui->doubleSpinBox_min->value());
|
||||||
setActiveColor(ui->lineEdit_activeColor->text());
|
setActiveColor(ui->lineEdit_activeColor->text());
|
||||||
setInactiveColor(ui->lineEdit_inactiveColor->text());
|
setInactiveColor(ui->lineEdit_inactiveColor->text());
|
||||||
setStrType(ui->comboBox_type->currentText());
|
setType(static_cast<Type>(ui->comboBox_type->currentIndex()));
|
||||||
setStrDirection(ui->comboBox_direction->currentText());
|
setDirection(
|
||||||
setHeight(ui->spinBox_height->value());
|
static_cast<Direction>(ui->comboBox_direction->currentIndex()));
|
||||||
setWidth(ui->spinBox_width->value());
|
setItemHeight(ui->spinBox_height->value());
|
||||||
|
setItemWidth(ui->spinBox_width->value());
|
||||||
|
|
||||||
writeConfiguration();
|
writeConfiguration();
|
||||||
return ret;
|
return ret;
|
||||||
@ -520,23 +528,21 @@ void GraphicalItem::writeConfiguration() const
|
|||||||
{
|
{
|
||||||
AbstractExtItem::writeConfiguration();
|
AbstractExtItem::writeConfiguration();
|
||||||
|
|
||||||
QSettings settings(
|
QSettings settings(writtableConfig(), QSettings::IniFormat);
|
||||||
QString("%1/%2").arg(directories().first()).arg(fileName()),
|
|
||||||
QSettings::IniFormat);
|
|
||||||
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
|
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
|
||||||
|
|
||||||
settings.beginGroup(QString("Desktop Entry"));
|
settings.beginGroup(QString("Desktop Entry"));
|
||||||
settings.setValue(QString("X-AW-Value"), m_bar);
|
settings.setValue(QString("X-AW-Value"), bar());
|
||||||
settings.setValue(QString("X-AW-Count"), m_count);
|
settings.setValue(QString("X-AW-Count"), count());
|
||||||
settings.setValue(QString("X-AW-Custom"), m_custom);
|
settings.setValue(QString("X-AW-Custom"), isCustom());
|
||||||
settings.setValue(QString("X-AW-Max"), m_maxValue);
|
settings.setValue(QString("X-AW-Max"), maxValue());
|
||||||
settings.setValue(QString("X-AW-Min"), m_minValue);
|
settings.setValue(QString("X-AW-Min"), minValue());
|
||||||
settings.setValue(QString("X-AW-ActiveColor"), m_activeColor);
|
settings.setValue(QString("X-AW-ActiveColor"), activeColor());
|
||||||
settings.setValue(QString("X-AW-InactiveColor"), m_inactiveColor);
|
settings.setValue(QString("X-AW-InactiveColor"), inactiveColor());
|
||||||
settings.setValue(QString("X-AW-Type"), strType());
|
settings.setValue(QString("X-AW-Type"), strType());
|
||||||
settings.setValue(QString("X-AW-Direction"), strDirection());
|
settings.setValue(QString("X-AW-Direction"), strDirection());
|
||||||
settings.setValue(QString("X-AW-Height"), m_height);
|
settings.setValue(QString("X-AW-Height"), itemHeight());
|
||||||
settings.setValue(QString("X-AW-Width"), m_width);
|
settings.setValue(QString("X-AW-Width"), itemWidth());
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
|
||||||
settings.sync();
|
settings.sync();
|
||||||
@ -609,27 +615,6 @@ void GraphicalItem::changeValue(const int state)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void GraphicalItem::initScene()
|
|
||||||
{
|
|
||||||
// init scene
|
|
||||||
m_scene = new QGraphicsScene();
|
|
||||||
m_scene->setBackgroundBrush(QBrush(Qt::NoBrush));
|
|
||||||
// init view
|
|
||||||
m_view = new QGraphicsView(m_scene);
|
|
||||||
m_view->setStyleSheet(QString("background: transparent"));
|
|
||||||
m_view->setContentsMargins(0, 0, 0, 0);
|
|
||||||
m_view->setFrameShape(QFrame::NoFrame);
|
|
||||||
m_view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
||||||
m_view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
||||||
m_view->resize(m_width + 5, m_height + 5);
|
|
||||||
|
|
||||||
// init helper
|
|
||||||
m_helper = new GraphicalItemHelper(this, m_scene);
|
|
||||||
m_helper->setParameters(m_activeColor, m_inactiveColor, m_width, m_height,
|
|
||||||
m_count);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void GraphicalItem::translate()
|
void GraphicalItem::translate()
|
||||||
{
|
{
|
||||||
ui->label_name->setText(i18n("Name"));
|
ui->label_name->setText(i18n("Name"));
|
||||||
|
@ -40,39 +40,44 @@ class GraphicalItem : public AbstractExtItem
|
|||||||
Q_PROPERTY(int count READ count WRITE setCount)
|
Q_PROPERTY(int count READ count WRITE setCount)
|
||||||
Q_PROPERTY(bool custom READ isCustom WRITE setCustom)
|
Q_PROPERTY(bool custom READ isCustom WRITE setCustom)
|
||||||
Q_PROPERTY(QString inactiveColor READ inactiveColor WRITE setInactiveColor)
|
Q_PROPERTY(QString inactiveColor READ inactiveColor WRITE setInactiveColor)
|
||||||
|
Q_PROPERTY(int itemHeight READ itemHeight WRITE setItemHeight)
|
||||||
|
Q_PROPERTY(int itemWidth READ itemWidth WRITE setItemWidth)
|
||||||
Q_PROPERTY(Type type READ type WRITE setType)
|
Q_PROPERTY(Type type READ type WRITE setType)
|
||||||
Q_PROPERTY(Direction direction READ direction WRITE setDirection)
|
Q_PROPERTY(Direction direction READ direction WRITE setDirection)
|
||||||
Q_PROPERTY(int height READ height WRITE setHeight)
|
|
||||||
Q_PROPERTY(float maxValue READ maxValue WRITE setMaxValue)
|
Q_PROPERTY(float maxValue READ maxValue WRITE setMaxValue)
|
||||||
Q_PROPERTY(float minValue READ minValue WRITE setMinValue)
|
Q_PROPERTY(float minValue READ minValue WRITE setMinValue)
|
||||||
Q_PROPERTY(QStringList usedKeys READ usedKeys WRITE setUsedKeys)
|
Q_PROPERTY(QStringList usedKeys READ usedKeys WRITE setUsedKeys)
|
||||||
Q_PROPERTY(int width READ width WRITE setWidth)
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum class Direction { LeftToRight = 0, RightToLeft = 1 };
|
enum class Direction { LeftToRight = 0, RightToLeft = 1 };
|
||||||
enum class Type { Horizontal, Vertical, Circle, Graph, Bars };
|
enum class Type {
|
||||||
|
Horizontal = 0,
|
||||||
|
Vertical = 1,
|
||||||
|
Circle = 2,
|
||||||
|
Graph = 3,
|
||||||
|
Bars = 4
|
||||||
|
};
|
||||||
|
|
||||||
explicit GraphicalItem(QWidget *parent = nullptr,
|
explicit GraphicalItem(QWidget *parent, const QString filePath = QString());
|
||||||
const QString desktopName = QString(),
|
|
||||||
const QStringList directories = QStringList());
|
|
||||||
virtual ~GraphicalItem();
|
virtual ~GraphicalItem();
|
||||||
GraphicalItem *copy(const QString _fileName, const int _number);
|
GraphicalItem *copy(const QString _fileName, const int _number);
|
||||||
QString image(const QVariant &value);
|
QString image(const QVariant &value);
|
||||||
|
void initScene();
|
||||||
// get methods
|
// get methods
|
||||||
QString bar() const;
|
QString bar() const;
|
||||||
QString activeColor() const;
|
QString activeColor() const;
|
||||||
QString inactiveColor() const;
|
|
||||||
int count() const;
|
int count() const;
|
||||||
|
QString inactiveColor() const;
|
||||||
bool isCustom() const;
|
bool isCustom() const;
|
||||||
|
int itemHeight() const;
|
||||||
|
int itemWidth() const;
|
||||||
float minValue() const;
|
float minValue() const;
|
||||||
float maxValue() const;
|
float maxValue() const;
|
||||||
Type type() const;
|
Type type() const;
|
||||||
QString strType() const;
|
QString strType() const;
|
||||||
Direction direction() const;
|
Direction direction() const;
|
||||||
QString strDirection() const;
|
QString strDirection() const;
|
||||||
int height() const;
|
|
||||||
QStringList usedKeys() const;
|
QStringList usedKeys() const;
|
||||||
int width() const;
|
|
||||||
QString uniq() const;
|
QString uniq() const;
|
||||||
// set methods
|
// set methods
|
||||||
void setBar(const QString _bar = QString("cpu"));
|
void setBar(const QString _bar = QString("cpu"));
|
||||||
@ -81,15 +86,15 @@ public:
|
|||||||
void setCustom(const bool _custom = false);
|
void setCustom(const bool _custom = false);
|
||||||
void setInactiveColor(const QString _color
|
void setInactiveColor(const QString _color
|
||||||
= QString("color://255,255,255,130"));
|
= QString("color://255,255,255,130"));
|
||||||
|
void setItemHeight(const int _height = 100);
|
||||||
|
void setItemWidth(const int _width = 100);
|
||||||
void setMinValue(const float _value = 0.0);
|
void setMinValue(const float _value = 0.0);
|
||||||
void setMaxValue(const float _value = 100.0);
|
void setMaxValue(const float _value = 100.0);
|
||||||
void setType(const Type _type = Type::Horizontal);
|
void setType(const Type _type = Type::Horizontal);
|
||||||
void setStrType(const QString _type = QString("Horizontal"));
|
void setStrType(const QString _type = QString("Horizontal"));
|
||||||
void setDirection(const Direction _direction = Direction::LeftToRight);
|
void setDirection(const Direction _direction = Direction::LeftToRight);
|
||||||
void setStrDirection(const QString _direction = QString("LeftToRight"));
|
void setStrDirection(const QString _direction = QString("LeftToRight"));
|
||||||
void setHeight(const int _height = 100);
|
|
||||||
void setUsedKeys(const QStringList _usedKeys = QStringList());
|
void setUsedKeys(const QStringList _usedKeys = QStringList());
|
||||||
void setWidth(const int _width = 100);
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void readConfiguration();
|
void readConfiguration();
|
||||||
@ -106,8 +111,7 @@ private:
|
|||||||
GraphicalItemHelper *m_helper = nullptr;
|
GraphicalItemHelper *m_helper = nullptr;
|
||||||
QGraphicsScene *m_scene = nullptr;
|
QGraphicsScene *m_scene = nullptr;
|
||||||
QGraphicsView *m_view = nullptr;
|
QGraphicsView *m_view = nullptr;
|
||||||
Ui::GraphicalItem *ui;
|
Ui::GraphicalItem *ui = nullptr;
|
||||||
void initScene();
|
|
||||||
void translate();
|
void translate();
|
||||||
// properties
|
// properties
|
||||||
QString m_bar = QString("cpu");
|
QString m_bar = QString("cpu");
|
||||||
|
112
sources/awesomewidgets/owmweatherprovider.cpp
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* 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 "owmweatherprovider.h"
|
||||||
|
|
||||||
|
#include <QDateTime>
|
||||||
|
#include <QUrlQuery>
|
||||||
|
|
||||||
|
#include "awdebug.h"
|
||||||
|
|
||||||
|
|
||||||
|
OWMWeatherProvider::OWMWeatherProvider(QObject *parent, const int number)
|
||||||
|
: AbstractWeatherProvider(parent, number)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
OWMWeatherProvider::~OWMWeatherProvider()
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void OWMWeatherProvider::initUrl(const QString city, const QString country,
|
||||||
|
const int ts)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Init query for" << city << country << "with ts" << ts;
|
||||||
|
|
||||||
|
m_ts = ts;
|
||||||
|
|
||||||
|
if (m_ts == 0)
|
||||||
|
m_url = QUrl(OWM_WEATHER_URL);
|
||||||
|
else
|
||||||
|
m_url = QUrl(OWM_FORECAST_URL);
|
||||||
|
QUrlQuery params;
|
||||||
|
params.addQueryItem(QString("q"), QString("%1,%2").arg(city, country));
|
||||||
|
params.addQueryItem(QString("units"), QString("metric"));
|
||||||
|
m_url.setQuery(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QVariantHash OWMWeatherProvider::parse(const QVariantMap &json) const
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Parse json" << json;
|
||||||
|
|
||||||
|
if (json[QString("cod")].toInt() != 200) {
|
||||||
|
qCWarning(LOG_LIB) << "Invalid OpenWeatherMap return code"
|
||||||
|
<< json[QString("cod")].toInt();
|
||||||
|
return QVariantHash();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_ts == 0) {
|
||||||
|
return parseSingleJson(json);
|
||||||
|
} else {
|
||||||
|
QVariantList list = json[QString("list")].toList();
|
||||||
|
return parseSingleJson(list.count() <= m_ts ? list.at(m_ts - 1).toMap()
|
||||||
|
: list.last().toMap());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QUrl OWMWeatherProvider::url() const
|
||||||
|
{
|
||||||
|
return m_url;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QVariantHash OWMWeatherProvider::parseSingleJson(const QVariantMap &json) const
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Single json data" << json;
|
||||||
|
|
||||||
|
QVariantHash output;
|
||||||
|
|
||||||
|
// weather status
|
||||||
|
QVariantList weather = json[QString("weather")].toList();
|
||||||
|
if (!weather.isEmpty()) {
|
||||||
|
int id = weather.first().toMap()[QString("id")].toInt();
|
||||||
|
output[QString("weatherId%1").arg(number())] = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
// main data
|
||||||
|
QVariantMap mainWeather = json[QString("main")].toMap();
|
||||||
|
if (!weather.isEmpty()) {
|
||||||
|
output[QString("humidity%1").arg(number())]
|
||||||
|
= mainWeather[QString("humidity")].toFloat();
|
||||||
|
output[QString("pressure%1").arg(number())]
|
||||||
|
= mainWeather[QString("pressure")].toFloat();
|
||||||
|
output[QString("temperature%1").arg(number())]
|
||||||
|
= mainWeather[QString("temp")].toFloat();
|
||||||
|
}
|
||||||
|
|
||||||
|
// timestamp
|
||||||
|
output[QString("timestamp%1").arg(number())]
|
||||||
|
= QDateTime::fromTime_t(json[QString("dt")].toUInt()).toUTC();
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
43
sources/awesomewidgets/owmweatherprovider.h
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* 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 OWMWEATHERPROVIDER_H
|
||||||
|
#define OWMWEATHERPROVIDER_H
|
||||||
|
|
||||||
|
#include "abstractweatherprovider.h"
|
||||||
|
|
||||||
|
#define OWM_WEATHER_URL "http://arcanis.me/weather"
|
||||||
|
#define OWM_FORECAST_URL "http://arcanis.me/forecast"
|
||||||
|
|
||||||
|
|
||||||
|
class OWMWeatherProvider : public AbstractWeatherProvider
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit OWMWeatherProvider(QObject *parent, const int number);
|
||||||
|
virtual ~OWMWeatherProvider();
|
||||||
|
void initUrl(const QString city, const QString country, const int);
|
||||||
|
QVariantHash parse(const QVariantMap &json) const;
|
||||||
|
QUrl url() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QVariantHash parseSingleJson(const QVariantMap &json) const;
|
||||||
|
int m_ts = 0;
|
||||||
|
QUrl m_url;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* OWMWEATHERPROVIDER_H */
|
BIN
sources/awesomewidgets/weather/01d.png
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
sources/awesomewidgets/weather/02d.png
Normal file
After Width: | Height: | Size: 2.9 KiB |
BIN
sources/awesomewidgets/weather/03d.png
Normal file
After Width: | Height: | Size: 2.5 KiB |
BIN
sources/awesomewidgets/weather/04d.png
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
sources/awesomewidgets/weather/09d.png
Normal file
After Width: | Height: | Size: 3.7 KiB |
BIN
sources/awesomewidgets/weather/10d.png
Normal file
After Width: | Height: | Size: 3.7 KiB |
BIN
sources/awesomewidgets/weather/11d.png
Normal file
After Width: | Height: | Size: 3.7 KiB |
BIN
sources/awesomewidgets/weather/13d.png
Normal file
After Width: | Height: | Size: 3.8 KiB |
BIN
sources/awesomewidgets/weather/50d.png
Normal file
After Width: | Height: | Size: 3.3 KiB |
@ -3,10 +3,11 @@ Comment=London current weather
|
|||||||
Encoding=UTF-8
|
Encoding=UTF-8
|
||||||
Name=London current
|
Name=London current
|
||||||
X-AW-Active=false
|
X-AW-Active=false
|
||||||
X-AW-ApiVersion=2
|
X-AW-ApiVersion=3
|
||||||
X-AW-City=London
|
X-AW-City=London
|
||||||
X-AW-Country=uk
|
X-AW-Country=uk
|
||||||
X-AW-Image=false
|
X-AW-Image=false
|
||||||
X-AW-Interval=3600
|
X-AW-Interval=3600
|
||||||
X-AW-Number=0
|
X-AW-Number=0
|
||||||
|
X-AW-Provider=OWM
|
||||||
X-AW-TS=0
|
X-AW-TS=0
|
||||||
|
126
sources/awesomewidgets/yahooweatherprovider.cpp
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* 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 "yahooweatherprovider.h"
|
||||||
|
|
||||||
|
#include <QUrlQuery>
|
||||||
|
|
||||||
|
#include "awdebug.h"
|
||||||
|
|
||||||
|
|
||||||
|
YahooWeatherProvider::YahooWeatherProvider(QObject *parent, const int number)
|
||||||
|
: AbstractWeatherProvider(parent, number)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
YahooWeatherProvider::~YahooWeatherProvider()
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void YahooWeatherProvider::initUrl(const QString city, const QString country,
|
||||||
|
const int ts)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Init query for" << city << country << "with ts" << ts;
|
||||||
|
|
||||||
|
m_ts = ts;
|
||||||
|
|
||||||
|
m_url = QUrl(YAHOO_WEATHER_URL);
|
||||||
|
QUrlQuery params;
|
||||||
|
params.addQueryItem(QString("format"), QString("json"));
|
||||||
|
params.addQueryItem(QString("env"),
|
||||||
|
QString("store://datatables.org/alltableswithkeys"));
|
||||||
|
params.addQueryItem(QString("q"),
|
||||||
|
QString(YAHOO_WEATHER_QUERY).arg(city, country));
|
||||||
|
m_url.setQuery(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QVariantHash YahooWeatherProvider::parse(const QVariantMap &json) const
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Parse json" << json;
|
||||||
|
|
||||||
|
QVariantMap jsonMap = json[QString("query")].toMap();
|
||||||
|
if (jsonMap[QString("count")].toInt() != 1) {
|
||||||
|
qCWarning(LOG_LIB) << "Found data count"
|
||||||
|
<< json[QString("count")].toInt() << "is not 1";
|
||||||
|
return QVariantHash();
|
||||||
|
}
|
||||||
|
QVariantMap results
|
||||||
|
= jsonMap[QString("results")].toMap()[QString("channel")].toMap();
|
||||||
|
QVariantMap item = results[QString("item")].toMap();
|
||||||
|
QVariantMap atmosphere = results[QString("atmosphere")].toMap();
|
||||||
|
|
||||||
|
return m_ts == 0 ? parseCurrent(item, atmosphere) : parseForecast(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QUrl YahooWeatherProvider::url() const
|
||||||
|
{
|
||||||
|
return m_url;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QVariantHash
|
||||||
|
YahooWeatherProvider::parseCurrent(const QVariantMap &json,
|
||||||
|
const QVariantMap &atmosphere) const
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Parse current weather from" << json;
|
||||||
|
|
||||||
|
QVariantHash values;
|
||||||
|
int id = json[QString("condition")].toMap()[QString("code")].toInt();
|
||||||
|
values[QString("weatherId%1").arg(number())] = id;
|
||||||
|
values[QString("temperature%1").arg(number())]
|
||||||
|
= json[QString("condition")].toMap()[QString("temp")].toInt();
|
||||||
|
values[QString("timestamp%1").arg(number())]
|
||||||
|
= json[QString("condition")].toMap()[QString("date")].toString();
|
||||||
|
values[QString("humidity%1").arg(number())]
|
||||||
|
= atmosphere[QString("humidity")].toInt();
|
||||||
|
values[QString("pressure%1").arg(number())]
|
||||||
|
= static_cast<int>(atmosphere[QString("pressure")].toFloat());
|
||||||
|
|
||||||
|
return values;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QVariantHash YahooWeatherProvider::parseForecast(const QVariantMap &json) const
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Parse forecast from" << json;
|
||||||
|
|
||||||
|
QVariantHash values;
|
||||||
|
QVariantList weatherList = json[QString("forecast")].toList();
|
||||||
|
QVariantMap weatherMap = weatherList.count() < m_ts
|
||||||
|
? weatherList.last().toMap()
|
||||||
|
: weatherList.at(m_ts).toMap();
|
||||||
|
int id = weatherMap[QString("code")].toInt();
|
||||||
|
values[QString("weatherId%1").arg(number())] = id;
|
||||||
|
values[QString("timestamp%1").arg(number())]
|
||||||
|
= weatherMap[QString("date")].toString();
|
||||||
|
// yahoo provides high and low temperatures. Lets calculate average one
|
||||||
|
values[QString("temperature%1").arg(number())]
|
||||||
|
= (weatherMap[QString("high")].toFloat()
|
||||||
|
+ weatherMap[QString("low")].toFloat())
|
||||||
|
/ 2.0;
|
||||||
|
// ... and no forecast data for humidity and pressure
|
||||||
|
values[QString("humidity%1").arg(number())] = 0;
|
||||||
|
values[QString("pressure%1").arg(number())] = 0.0;
|
||||||
|
|
||||||
|
return values;
|
||||||
|
}
|
47
sources/awesomewidgets/yahooweatherprovider.h
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* 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 YAHOOWEATHERPROVIDER_H
|
||||||
|
#define YAHOOWEATHERPROVIDER_H
|
||||||
|
|
||||||
|
#include "abstractweatherprovider.h"
|
||||||
|
|
||||||
|
#define YAHOO_WEATHER_URL "https://query.yahooapis.com/v1/public/yql"
|
||||||
|
#define YAHOO_WEATHER_QUERY \
|
||||||
|
"select * from weather.forecast where u='c' and woeid in (select woeid " \
|
||||||
|
"from geo.places(1) where text='%1, %2')"
|
||||||
|
|
||||||
|
|
||||||
|
class YahooWeatherProvider : public AbstractWeatherProvider
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit YahooWeatherProvider(QObject *parent, const int number);
|
||||||
|
virtual ~YahooWeatherProvider();
|
||||||
|
void initUrl(const QString city, const QString country, const int);
|
||||||
|
QVariantHash parse(const QVariantMap &json) const;
|
||||||
|
QUrl url() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QVariantHash parseCurrent(const QVariantMap &json,
|
||||||
|
const QVariantMap &atmosphere) const;
|
||||||
|
QVariantHash parseForecast(const QVariantMap &json) const;
|
||||||
|
int m_ts = 0;
|
||||||
|
QUrl m_url;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* YAHOOWEATHERPROVIDER_H */
|
@ -57,7 +57,7 @@ Item {
|
|||||||
|
|
||||||
// ui
|
// ui
|
||||||
GridLayout {
|
GridLayout {
|
||||||
anchors.fill: Plasmoid.Layout
|
anchors.fill: parent
|
||||||
columns: plasmoid.configuration.verticalLayout ? 1 : dpAdds.numberOfDesktops()
|
columns: plasmoid.configuration.verticalLayout ? 1 : dpAdds.numberOfDesktops()
|
||||||
rows: plasmoid.configuration.verticalLayout ? dpAdds.numberOfDesktops() : 1
|
rows: plasmoid.configuration.verticalLayout ? dpAdds.numberOfDesktops() : 1
|
||||||
|
|
||||||
|
@ -156,22 +156,22 @@ QString DPAdds::toolTipImage(const int desktop) const
|
|||||||
std::for_each(info.desktopsData.cbegin(), info.desktopsData.cend(),
|
std::for_each(info.desktopsData.cbegin(), info.desktopsData.cend(),
|
||||||
[&toolTipScene, &screen](WindowData data) {
|
[&toolTipScene, &screen](WindowData data) {
|
||||||
QPixmap desktop = screen->grabWindow(data.id);
|
QPixmap desktop = screen->grabWindow(data.id);
|
||||||
toolTipScene->addPixmap(desktop)
|
toolTipScene->addPixmap(desktop)->setOffset(
|
||||||
->setOffset(data.rect.left(), data.rect.top());
|
data.rect.left(), data.rect.top());
|
||||||
});
|
});
|
||||||
} else if (m_tooltipType == QString("windows")) {
|
} else if (m_tooltipType == QString("windows")) {
|
||||||
QScreen *screen = QGuiApplication::primaryScreen();
|
QScreen *screen = QGuiApplication::primaryScreen();
|
||||||
std::for_each(info.desktopsData.cbegin(), info.desktopsData.cend(),
|
std::for_each(info.desktopsData.cbegin(), info.desktopsData.cend(),
|
||||||
[&toolTipScene, &screen](WindowData data) {
|
[&toolTipScene, &screen](WindowData data) {
|
||||||
QPixmap desktop = screen->grabWindow(data.id);
|
QPixmap desktop = screen->grabWindow(data.id);
|
||||||
toolTipScene->addPixmap(desktop)
|
toolTipScene->addPixmap(desktop)->setOffset(
|
||||||
->setOffset(data.rect.left(), data.rect.top());
|
data.rect.left(), data.rect.top());
|
||||||
});
|
});
|
||||||
std::for_each(info.windowsData.cbegin(), info.windowsData.cend(),
|
std::for_each(info.windowsData.cbegin(), info.windowsData.cend(),
|
||||||
[&toolTipScene, &screen](WindowData data) {
|
[&toolTipScene, &screen](WindowData data) {
|
||||||
QPixmap window = screen->grabWindow(data.id);
|
QPixmap window = screen->grabWindow(data.id);
|
||||||
toolTipScene->addPixmap(window)
|
toolTipScene->addPixmap(window)->setOffset(
|
||||||
->setOffset(data.rect.left(), data.rect.top());
|
data.rect.left(), data.rect.top());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -232,8 +232,8 @@ QString DPAdds::valueByKey(const QString key, int desktop) const
|
|||||||
.arg(currentMark, m_mark.count(), QLatin1Char(' '))
|
.arg(currentMark, m_mark.count(), QLatin1Char(' '))
|
||||||
.replace(QString(" "), QString(" "));
|
.replace(QString(" "), QString(" "));
|
||||||
else if (key == QString("name"))
|
else if (key == QString("name"))
|
||||||
return KWindowSystem::desktopName(desktop)
|
return KWindowSystem::desktopName(desktop).replace(QString(" "),
|
||||||
.replace(QString(" "), QString(" "));
|
QString(" "));
|
||||||
else if (key == QString("number"))
|
else if (key == QString("number"))
|
||||||
return QString::number(desktop);
|
return QString::number(desktop);
|
||||||
else if (key == QString("total"))
|
else if (key == QString("total"))
|
||||||
|
@ -6,6 +6,7 @@ include_directories(
|
|||||||
${CMAKE_SOURCE_DIR}
|
${CMAKE_SOURCE_DIR}
|
||||||
${CMAKE_BINARY_DIR}
|
${CMAKE_BINARY_DIR}
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/../${PROJECT_LIBRARY}/
|
${CMAKE_CURRENT_SOURCE_DIR}/../${PROJECT_LIBRARY}/
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/../${PROJECT_MONITORSOURCES}/
|
||||||
${PROJECT_TRDPARTY_DIR}
|
${PROJECT_TRDPARTY_DIR}
|
||||||
${Qt_INCLUDE}
|
${Qt_INCLUDE}
|
||||||
${Kf5_INCLUDE}
|
${Kf5_INCLUDE}
|
||||||
@ -13,15 +14,18 @@ include_directories(
|
|||||||
|
|
||||||
file(GLOB SUBPROJECT_DESKTOP_IN *.desktop)
|
file(GLOB SUBPROJECT_DESKTOP_IN *.desktop)
|
||||||
file(RELATIVE_PATH SUBPROJECT_DESKTOP ${CMAKE_SOURCE_DIR} ${SUBPROJECT_DESKTOP_IN})
|
file(RELATIVE_PATH SUBPROJECT_DESKTOP ${CMAKE_SOURCE_DIR} ${SUBPROJECT_DESKTOP_IN})
|
||||||
file(GLOB SUBPROJECT_SOURCE *.cpp sources/*.cpp ${CMAKE_SOURCE_DIR}/*.cpp)
|
file(GLOB SUBPROJECT_SOURCE *.cpp ${CMAKE_SOURCE_DIR}/*.cpp)
|
||||||
|
file(GLOB SUBPROJECT_HEADER *.h)
|
||||||
file(GLOB SUBPROJECT_CONF *.conf)
|
file(GLOB SUBPROJECT_CONF *.conf)
|
||||||
|
|
||||||
# prepare
|
# prepare
|
||||||
configure_file(${SUBPROJECT_DESKTOP_IN} ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT_DESKTOP})
|
configure_file(${SUBPROJECT_DESKTOP_IN} ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT_DESKTOP})
|
||||||
|
|
||||||
# make
|
# make
|
||||||
add_library(${SUBPROJECT} MODULE ${SUBPROJECT_SOURCE})
|
add_library(${SUBPROJECT} MODULE ${SUBPROJECT_SOURCE} ${SUBPROJECT_HEADER})
|
||||||
target_link_libraries(${SUBPROJECT} ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Kf5_LIBRARIES})
|
target_link_libraries(${SUBPROJECT}
|
||||||
|
${PROJECT_LIBRARY} ${PROJECT_MONITORSOURCES}
|
||||||
|
${Qt_LIBRARIES} ${Kf5_LIBRARIES})
|
||||||
kcoreaddons_desktop_to_json(${SUBPROJECT} ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT_DESKTOP}
|
kcoreaddons_desktop_to_json(${SUBPROJECT} ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT_DESKTOP}
|
||||||
SERVICE_TYPES plasma-dataengine.desktop)
|
SERVICE_TYPES plasma-dataengine.desktop)
|
||||||
|
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
|
|
||||||
#include "extsysmon.h"
|
#include "extsysmon.h"
|
||||||
|
|
||||||
#include <QDir>
|
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QRegExp>
|
#include <QRegExp>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
@ -25,6 +24,8 @@
|
|||||||
|
|
||||||
#include "awdebug.h"
|
#include "awdebug.h"
|
||||||
#include "extsysmonaggregator.h"
|
#include "extsysmonaggregator.h"
|
||||||
|
#include "gputempsource.h"
|
||||||
|
#include "hddtempsource.h"
|
||||||
|
|
||||||
|
|
||||||
ExtendedSysMon::ExtendedSysMon(QObject *parent, const QVariantList &args)
|
ExtendedSysMon::ExtendedSysMon(QObject *parent, const QVariantList &args)
|
||||||
@ -73,7 +74,10 @@ bool ExtendedSysMon::updateSourceEvent(const QString &source)
|
|||||||
qCDebug(LOG_ESM) << "Source" << source;
|
qCDebug(LOG_ESM) << "Source" << source;
|
||||||
|
|
||||||
if (aggregator->hasSource(source)) {
|
if (aggregator->hasSource(source)) {
|
||||||
setData(source, QString("value"), aggregator->data(source));
|
QVariant data = aggregator->data(source);
|
||||||
|
if (data.isNull())
|
||||||
|
return false;
|
||||||
|
setData(source, QString("value"), data);
|
||||||
} else {
|
} else {
|
||||||
qCWarning(LOG_ESM) << "Unknown source" << source;
|
qCWarning(LOG_ESM) << "Unknown source" << source;
|
||||||
return false;
|
return false;
|
||||||
@ -83,37 +87,6 @@ bool ExtendedSysMon::updateSourceEvent(const QString &source)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QStringList ExtendedSysMon::getAllHdd() const
|
|
||||||
{
|
|
||||||
QStringList allDevices
|
|
||||||
= QDir(QString("/dev")).entryList(QDir::System, QDir::Name);
|
|
||||||
QStringList devices = allDevices.filter(QRegExp(QString("^[hms]d[a-z]$")));
|
|
||||||
for (int i = 0; i < devices.count(); i++)
|
|
||||||
devices[i] = QString("/dev/%1").arg(devices.at(i));
|
|
||||||
|
|
||||||
qCInfo(LOG_ESM) << "Device list" << devices;
|
|
||||||
return devices;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QString ExtendedSysMon::getAutoGpu() const
|
|
||||||
{
|
|
||||||
QString gpu = QString("disable");
|
|
||||||
QFile moduleFile(QString("/proc/modules"));
|
|
||||||
if (!moduleFile.open(QIODevice::ReadOnly))
|
|
||||||
return gpu;
|
|
||||||
|
|
||||||
QString output = moduleFile.readAll();
|
|
||||||
if (output.contains(QString("fglrx")))
|
|
||||||
gpu = QString("ati");
|
|
||||||
else if (output.contains(QString("nvidia")))
|
|
||||||
gpu = QString("nvidia");
|
|
||||||
|
|
||||||
qCInfo(LOG_ESM) << "Device" << gpu;
|
|
||||||
return gpu;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ExtendedSysMon::readConfiguration()
|
void ExtendedSysMon::readConfiguration()
|
||||||
{
|
{
|
||||||
QString fileName
|
QString fileName
|
||||||
@ -125,8 +98,8 @@ void ExtendedSysMon::readConfiguration()
|
|||||||
|
|
||||||
settings.beginGroup(QString("Configuration"));
|
settings.beginGroup(QString("Configuration"));
|
||||||
rawConfig[QString("ACPIPATH")]
|
rawConfig[QString("ACPIPATH")]
|
||||||
= settings.value(QString("ACPIPATH"),
|
= settings
|
||||||
QString("/sys/class/power_supply/"))
|
.value(QString("ACPIPATH"), QString("/sys/class/power_supply/"))
|
||||||
.toString();
|
.toString();
|
||||||
rawConfig[QString("GPUDEV")]
|
rawConfig[QString("GPUDEV")]
|
||||||
= settings.value(QString("GPUDEV"), QString("auto")).toString();
|
= settings.value(QString("GPUDEV"), QString("auto")).toString();
|
||||||
@ -161,12 +134,12 @@ ExtendedSysMon::updateConfiguration(QHash<QString, QString> rawConfig) const
|
|||||||
if (rawConfig[QString("GPUDEV")] == QString("disable"))
|
if (rawConfig[QString("GPUDEV")] == QString("disable"))
|
||||||
rawConfig[QString("GPUDEV")] = QString("disable");
|
rawConfig[QString("GPUDEV")] = QString("disable");
|
||||||
else if (rawConfig[QString("GPUDEV")] == QString("auto"))
|
else if (rawConfig[QString("GPUDEV")] == QString("auto"))
|
||||||
rawConfig[QString("GPUDEV")] = getAutoGpu();
|
rawConfig[QString("GPUDEV")] = GPUTemperatureSource::autoGpu();
|
||||||
else if ((rawConfig[QString("GPUDEV")] != QString("ati"))
|
else if ((rawConfig[QString("GPUDEV")] != QString("ati"))
|
||||||
&& (rawConfig[QString("GPUDEV")] != QString("nvidia")))
|
&& (rawConfig[QString("GPUDEV")] != QString("nvidia")))
|
||||||
rawConfig[QString("GPUDEV")] = getAutoGpu();
|
rawConfig[QString("GPUDEV")] = GPUTemperatureSource::autoGpu();
|
||||||
// hdddev
|
// hdddev
|
||||||
QStringList allHddDevices = getAllHdd();
|
QStringList allHddDevices = HDDTemperatureSource::allHdd();
|
||||||
if (rawConfig[QString("HDDDEV")] == QString("all")) {
|
if (rawConfig[QString("HDDDEV")] == QString("all")) {
|
||||||
rawConfig[QString("HDDDEV")] = allHddDevices.join(QChar(','));
|
rawConfig[QString("HDDDEV")] = allHddDevices.join(QChar(','));
|
||||||
} else if (rawConfig[QString("HDDDEV")] == QString("disable")) {
|
} else if (rawConfig[QString("HDDDEV")] == QString("disable")) {
|
||||||
|
@ -41,8 +41,6 @@ private:
|
|||||||
ExtSysMonAggregator *aggregator = nullptr;
|
ExtSysMonAggregator *aggregator = nullptr;
|
||||||
QHash<QString, QString> configuration;
|
QHash<QString, QString> configuration;
|
||||||
// methods
|
// methods
|
||||||
QStringList getAllHdd() const;
|
|
||||||
QString getAutoGpu() const;
|
|
||||||
void readConfiguration();
|
void readConfiguration();
|
||||||
QHash<QString, QString>
|
QHash<QString, QString>
|
||||||
updateConfiguration(QHash<QString, QString> rawConfig) const;
|
updateConfiguration(QHash<QString, QString> rawConfig) const;
|
||||||
|
@ -18,19 +18,19 @@
|
|||||||
#include "extsysmonaggregator.h"
|
#include "extsysmonaggregator.h"
|
||||||
|
|
||||||
#include "awdebug.h"
|
#include "awdebug.h"
|
||||||
#include "sources/batterysource.h"
|
#include "batterysource.h"
|
||||||
#include "sources/customsource.h"
|
#include "customsource.h"
|
||||||
#include "sources/desktopsource.h"
|
#include "desktopsource.h"
|
||||||
#include "sources/gpuloadsource.h"
|
#include "gpuloadsource.h"
|
||||||
#include "sources/gputempsource.h"
|
#include "gputempsource.h"
|
||||||
#include "sources/hddtempsource.h"
|
#include "hddtempsource.h"
|
||||||
#include "sources/loadsource.h"
|
#include "loadsource.h"
|
||||||
#include "sources/networksource.h"
|
#include "networksource.h"
|
||||||
#include "sources/playersource.h"
|
#include "playersource.h"
|
||||||
#include "sources/processessource.h"
|
#include "processessource.h"
|
||||||
#include "sources/quotessource.h"
|
#include "quotessource.h"
|
||||||
#include "sources/upgradesource.h"
|
#include "upgradesource.h"
|
||||||
#include "sources/weathersource.h"
|
#include "weathersource.h"
|
||||||
|
|
||||||
|
|
||||||
ExtSysMonAggregator::ExtSysMonAggregator(QObject *parent,
|
ExtSysMonAggregator::ExtSysMonAggregator(QObject *parent,
|
||||||
@ -148,10 +148,10 @@ void ExtSysMonAggregator::init(const QHash<QString, QString> config)
|
|||||||
= new WeatherSource(this, QStringList());
|
= new WeatherSource(this, QStringList());
|
||||||
for (auto source : weatherItem->sources())
|
for (auto source : weatherItem->sources())
|
||||||
m_map[source] = weatherItem;
|
m_map[source] = weatherItem;
|
||||||
#ifdef BUILD_TESTING
|
#ifdef BUILD_LOAD
|
||||||
// additional load source
|
// additional load source
|
||||||
AbstractExtSysMonSource *loadItem = new LoadSource(this, QStringList());
|
AbstractExtSysMonSource *loadItem = new LoadSource(this, QStringList());
|
||||||
for (auto source : loadItem->sources())
|
for (auto source : loadItem->sources())
|
||||||
m_map[source] = loadItem;
|
m_map[source] = loadItem;
|
||||||
#endif /* BUILD_TESTING */
|
#endif /* BUILD_LOAD */
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
#include "sources/abstractextsysmonsource.h"
|
#include "abstractextsysmonsource.h"
|
||||||
|
|
||||||
|
|
||||||
class ExtSysMonAggregator : public QObject
|
class ExtSysMonAggregator : public QObject
|
||||||
|
18
sources/extsysmonsources/CMakeLists.txt
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
set(SUBPROJECT ${PROJECT_MONITORSOURCES})
|
||||||
|
message(STATUS "Subproject ${SUBPROJECT}")
|
||||||
|
add_definitions(-DTRANSLATION_DOMAIN=\"plasma_applet_org.kde.plasma.awesomewidget\")
|
||||||
|
|
||||||
|
include_directories(
|
||||||
|
${CMAKE_SOURCE_DIR}
|
||||||
|
${CMAKE_BINARY_DIR}
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/../${PROJECT_LIBRARY}/
|
||||||
|
${PROJECT_TRDPARTY_DIR}
|
||||||
|
${Qt_INCLUDE}
|
||||||
|
${Kf5_INCLUDE}
|
||||||
|
)
|
||||||
|
|
||||||
|
file(GLOB SUBPROJECT_SOURCE *.cpp)
|
||||||
|
file(GLOB SUBPROJECT_HEADER *.h)
|
||||||
|
|
||||||
|
add_library(${SUBPROJECT} STATIC ${SUBPROJECT_SOURCE} ${SUBPROJECT_HEADER})
|
||||||
|
target_link_libraries(${SUBPROJECT} ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Kf5_LIBRARIES})
|
@ -25,6 +25,8 @@
|
|||||||
|
|
||||||
class AbstractExtSysMonSource : public QObject
|
class AbstractExtSysMonSource : public QObject
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit AbstractExtSysMonSource(QObject *parent, const QStringList)
|
explicit AbstractExtSysMonSource(QObject *parent, const QStringList)
|
||||||
: QObject(parent){};
|
: QObject(parent){};
|
||||||
@ -40,6 +42,9 @@ public:
|
|||||||
rx.indexIn(source);
|
rx.indexIn(source);
|
||||||
return rx.cap().toInt();
|
return rx.cap().toInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void dataReceived(const QVariantHash &);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -27,7 +27,7 @@ BatterySource::BatterySource(QObject *parent, const QStringList args)
|
|||||||
: AbstractExtSysMonSource(parent, args)
|
: AbstractExtSysMonSource(parent, args)
|
||||||
{
|
{
|
||||||
Q_ASSERT(args.count() == 1);
|
Q_ASSERT(args.count() == 1);
|
||||||
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
m_acpiPath = args.at(0);
|
m_acpiPath = args.at(0);
|
||||||
m_sources = getSources();
|
m_sources = getSources();
|
||||||
@ -36,13 +36,32 @@ BatterySource::BatterySource(QObject *parent, const QStringList args)
|
|||||||
|
|
||||||
BatterySource::~BatterySource()
|
BatterySource::~BatterySource()
|
||||||
{
|
{
|
||||||
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QStringList BatterySource::getSources()
|
||||||
|
{
|
||||||
|
QStringList sources;
|
||||||
|
sources.append(QString("battery/ac"));
|
||||||
|
sources.append(QString("battery/bat"));
|
||||||
|
m_batteriesCount
|
||||||
|
= QDir(m_acpiPath)
|
||||||
|
.entryList(QStringList() << QString("BAT*"),
|
||||||
|
QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)
|
||||||
|
.count();
|
||||||
|
qCInfo(LOG_ESS) << "Init batteries count as" << m_batteriesCount;
|
||||||
|
for (int i = 0; i < m_batteriesCount; i++)
|
||||||
|
sources.append(QString("battery/bat%1").arg(i));
|
||||||
|
|
||||||
|
qCInfo(LOG_ESS) << "Sources list" << sources;
|
||||||
|
return sources;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QVariant BatterySource::data(QString source)
|
QVariant BatterySource::data(QString source)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_ESM) << "Source" << source;
|
qCDebug(LOG_ESS) << "Source" << source;
|
||||||
|
|
||||||
if (!m_values.contains(source))
|
if (!m_values.contains(source))
|
||||||
run();
|
run();
|
||||||
@ -53,7 +72,7 @@ QVariant BatterySource::data(QString source)
|
|||||||
|
|
||||||
QVariantMap BatterySource::initialData(QString source) const
|
QVariantMap BatterySource::initialData(QString source) const
|
||||||
{
|
{
|
||||||
qCDebug(LOG_ESM) << "Source" << source;
|
qCDebug(LOG_ESS) << "Source" << source;
|
||||||
|
|
||||||
QVariantMap data;
|
QVariantMap data;
|
||||||
if (source == QString("battery/ac")) {
|
if (source == QString("battery/ac")) {
|
||||||
@ -120,22 +139,3 @@ QStringList BatterySource::sources() const
|
|||||||
{
|
{
|
||||||
return m_sources;
|
return m_sources;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QStringList BatterySource::getSources()
|
|
||||||
{
|
|
||||||
QStringList sources;
|
|
||||||
sources.append(QString("battery/ac"));
|
|
||||||
sources.append(QString("battery/bat"));
|
|
||||||
m_batteriesCount
|
|
||||||
= QDir(m_acpiPath)
|
|
||||||
.entryList(QStringList() << QString("BAT*"),
|
|
||||||
QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)
|
|
||||||
.count();
|
|
||||||
qCInfo(LOG_ESM) << "Init batteries count as" << m_batteriesCount;
|
|
||||||
for (int i = 0; i < m_batteriesCount; i++)
|
|
||||||
sources.append(QString("battery/bat%1").arg(i));
|
|
||||||
|
|
||||||
qCInfo(LOG_ESM) << "Sources list" << sources;
|
|
||||||
return sources;
|
|
||||||
}
|
|