Compare commits

...

86 Commits

Author SHA1 Message Date
4bcdb3a7ff release 3.1.2 2016-05-09 00:12:06 +03:00
5ad0c533f0 prerelease updates
* update Ukrainian translation
* update patches
* merge qt5.3-qtconcurrent-and-qlogging-category.patch into
  qt5.4-replace-qml-dialogs.patch
* update cmake files
* update README
2016-05-08 00:07:44 +03:00
d57e54b714 add script formatter 2016-05-07 00:10:06 +03:00
13f2d560d0 Some more changes
* new tag - $tstime
* add summand parameter to float formatter
* drop version.h includes since it has been moved to awdebug.h (e.g. to
  introduce BUILD_FUTURE guards easy in the future)
2016-05-06 01:22:59 +03:00
2220ad6bfe initial creation of custom formatters (#91) 2016-05-05 00:11:31 +03:00
97f2e78308 add transifex integration
* update Spanish translation
* rename nl to nl_NL
2016-05-04 12:40:54 +03:00
3771ce6ec2 rename forma_t_er to forma_tt_er 2016-05-03 05:04:12 +03:00
46db3fee4c add standalone configuration example (#72) 2016-05-01 16:23:37 +03:00
a339f9a743 drop needToBeUpdated call from qml since it is not required 2016-04-30 17:36:01 +03:00
4e52d16f1a prerelese translation bump 2016-04-29 13:01:17 +03:00
097b63415e drop own workaround for update functions
use qtimer instead
2016-04-28 18:18:13 +03:00
77388deab6 initial support of total sent/received data
Tags {up,down}total{,kb}[0-9]?+
2016-04-25 16:06:37 +03:00
d01d8f95e5 fix qpixmap generation 2016-04-23 05:22:54 +03:00
22586811de backport QML code changes from awesome-widgets to deskop-panel 2016-04-22 15:39:36 +03:00
82dda14260 add background configuration dialog 2016-04-21 16:44:21 +03:00
f8e9945bc4 fix configuration dialog error
even if user selects Cancel in font dialog html codes pasted
2016-04-20 15:50:45 +03:00
139554578c fix bug introduced by 5c474e822b
No conversion has been applied for total memory values
2016-04-18 09:33:35 +03:00
1827f641f9 Merge branch 'development' of github.com:arcan1s/awesome-widgets into development 2016-04-17 16:20:12 +03:00
aef1a736c8 code improvements
* drop c++14 requirements since it is not used
* move from enum to enum classes
* more intuitive graph building in GI
* allow X-AW-Direction property works with graphs and bars
2016-04-17 16:18:13 +03:00
27a80274ac add total memory fix patch 2016-04-16 18:29:11 +03:00
0e3f83f361 add bars support to gi
same as graphs but also provides solid background under lines
2016-04-16 03:23:28 +03:00
d30df9dafc fix configuration ui
In some cases text is removed, but no new text is pasted.
2016-04-15 15:02:35 +03:00
f7a6b86cae GI improvements
* add tag information to GI configuration
* change tag identification to avoid keys reorderding
2016-04-14 16:14:26 +03:00
a3e7a84b92 drop another part of pornography in gi
more intuinitve configuration interface in graphicalitem. Improve code
for the future references (in case if new color type will be added).
Change X-AW-*Color values to ones with prefixes (added autoconversion
from old-version api)
2016-04-12 14:22:19 +03:00
354fd3cd0c drop pornography with requests
Actually it has been introduced as temporary solution but I totally
forgot about it
2016-04-10 00:22:12 +03:00
15abe54290 Another fixes
* update translator list
* drop russian changelog at all
* fix changelog building
* fix invalid graphical item UI behaviour
2016-04-09 03:55:52 +03:00
60cbc40e9f implement coverity integration (see #84) 2016-04-08 16:23:59 +03:00
bfa4f9e98e Some small changes
* changelog update
* version metadata update
* bump required Qt version to 5.6 and update patch accordinly
* fix invalid cast in update dialog
2016-04-07 16:52:05 +03:00
e9146b3b6c release 3.1.1
* translation update
* fix broken build with gcc (#87). The issue was reproduced only with
  gcc build and has been resolved by just replacing C-like `isnan` to
  `std::isnan`
2016-04-06 14:42:56 +03:00
d216ee1f79 fix invalid copied file 2016-04-06 01:40:13 +03:00
81ceaa8160 backport zh translation from master for merge 2016-04-06 01:35:07 +03:00
d4c7095d61 release 3.1.0 2016-04-06 01:25:31 +03:00
d9409c25f4 Preparing to prerelease
* apply clangformat
* fix yahoo weather api
2016-04-05 00:24:37 +03:00
7d1e035240 replace own workaround for version checking to QVersionNumber
QVersionNumber has been introduced since Qt-5.6 and it is better to use
it instead of custom version checking
2016-04-04 10:47:12 +03:00
fa795121aa drop task from source tree
Latest commits have removed links to task
2016-03-29 17:01:57 +03:00
b9fda3e1cd drop task library from build, cosmetic changes 2016-03-27 15:39:37 +03:00
1187c43e57 Move to QProcess from Task in GPU and player sources 2016-03-26 12:17:24 +03:00
4a6aaa95b0 Move hddtemp engine to qprocess
in lieu of #83
2016-03-25 18:19:26 +03:00
7e42c8cb49 Improve performance with image generation
To avoid pen creation on each update class properties is used.
2016-03-24 15:53:07 +03:00
88f0ebfe96 Revert bd65e44002 2016-03-23 16:27:05 +03:00
86458b8238 push Polish translation (thanks to Mariusz Kocoń) 2016-03-22 14:37:40 +03:00
bd65e44002 add delayed initialization
This workaround probably will fix issue with the recent plasma when
plasmashell fails to load sometimes.
2016-03-21 12:10:27 +03:00
fe7f82373b Start work on adding ability to use custom image for bars instead of
color
2016-03-19 17:50:51 +03:00
3a6033e676 Cosmetic changes
* fix invalid graph painting - for some reasons graphs are not normed as
  expected.
* fix cppcheck warnings related to no default values
2016-03-18 16:23:53 +03:00
453d4d5149 Small changes
* move logging ini file from dataengine to library
* improve dataengine desktop file
* fix configuration warnings with the newest plasma
2016-03-17 19:19:10 +03:00
07c753b703 add default config to directory
(it mostly requires by current build system)
2016-03-16 18:23:31 +03:00
52b1255d3f move graph data store to graphical item helper
It is required by custom graphs. X-AW-Count parameter (which is only
    recognized by Graph item type) has been introduced
2016-03-14 12:04:38 +03:00
7f665fef77 update to the newest Qt
First it crashes with the newest Qt due to nan values in graphs.
Second it produces several warnings
2016-03-13 22:20:22 +03:00
7ff1515c94 Merge branch 'development' of github.com:arcan1s/awesome-widgets into development 2016-03-11 20:51:19 +03:00
162708295d improve configuration import and export
Special directory for configuration store has been created. In
particular it will allow to realize #72
2016-03-11 20:48:36 +03:00
4a59acae09 change urls in forgotten files 2016-03-08 17:29:54 +03:00
be9203e816 update project url
For some time my site has been moved from arcanis.name to arcanis.me.
Also https protocol forced.
2016-03-05 19:39:26 +03:00
5af4b0c40c fix bug introduced by lazy subscription
Sources in custom dataengine updated only if user subscribe on specified
source. I've implemented drop returing value so if no requested value
found it will return force update event.
2016-03-04 15:06:12 +03:00
071d7fdb78 bump default gi configuration
Bump API version and add new parameters. Also:

1. Fix function combobox in configuration UI.
2. Drop datasource from time engine as well.
3. Small edit abstractdesources class
2016-03-03 19:57:31 +03:00
89d573450a fix #81
As it was found the issue has been caused by parallel access to
QGraphicsScene so it has been cleared before convertion to pixmap. It
has been resolved by deletion concurrent updates in this place (it makes
sense anyway).
2016-03-01 00:58:37 +03:00
50f3ef5bba move gihelper to own class from namespace
This action will allow to store data in the helper class. Also
notification for high memory usage has been changed from 90 to 80.
2016-02-26 20:04:27 +03:00
8cae273ffb split gi to helper and core
Also internal data format has been changed
2016-02-24 20:40:55 +03:00
15d4d7667d change formating
* add *h.in to clang-format configuration
* move static keys definition to header. Probably it may break something
  with key parsing
2016-02-17 09:31:11 +03:00
95a5eec108 Cosmetic commit
* apply clangformat settings
* update translations
* rename settings
2016-02-16 08:46:43 +03:00
362f1fd87e prepare to move to generic bars
This commits series introduces bars which may be calculated from any
custom formula. For a start I've renamed $bar*tag to $bar* and add new
configuration parameters to graphical items.
2016-02-12 09:23:30 +03:00
5c474e822b one more optimization
The previous versions stored values as string, so any (even if they are
not used) values being converted into string, and then (if required)
being converted back to float/int/etc. I've changed the mechanism, so
they are stored as QVariant (native value).

Please note that it is possible that this rewrite may cause crash in
some cases (if I've missed smth).
2016-02-10 10:51:01 +03:00
d856fa8e97 possible fix #75
I've added 'optimize' option (by default true). If it options is set
then sources will be checked if they are required (with dependencies if
any). And if they are not required they will be dropped by using common
mechanism.

Please note that if this option enabled the following features (at the
    moment) will be unavailable:

* key request from context menu (from configuration interface it still works)
* notifications event if sources on which notification is not connected

I suppose this commit will increase performance in about 4-5 times.
2016-02-05 11:08:09 +03:00
54e1545bb1 create update helper class
Move old chechUpdates() method to this class. Create ability to show
ChangeLog after updates (by using global config with version). Changelog
(only for the latest version) will be written to version.h during cmake
run.
2016-02-04 00:02:49 +07:00
384097625c Merge pull request #77 from arcan1s/revert-76-master
Revert "Master update"
2016-01-31 23:35:28 +06:00
5ddf720a57 Revert "Master update" 2016-01-31 23:34:09 +06:00
1610c190b4 Merge pull request #76 from arcan1s/master
Master update
2016-01-31 23:32:29 +06:00
beb2682b04 Stabilizing commit
* move request timeout settings to the configuration header
* initial support of requiredby dictionary
* add AWPatternFunctions namespace
* improve components communication
* update UI to recent abilities
* rewrite qCDebug messages and update CONTRIBUTING.md accordingly
2016-02-01 00:25:28 +07:00
c1cf8185a3 ...and another edit travis.yml 2016-01-31 00:34:31 +07:00
fb7fc4a104 one more edit travis.yml 2016-01-31 00:28:39 +07:00
210415cdff more correct work with kubuntu ppa, less output messages 2016-01-31 00:19:04 +07:00
bfac30c304 add dpkg options to travis.yml 2016-01-31 00:07:40 +07:00
966c6059a0 split some classes to different namespaces to improve code base
No significant changes applied.

* function syntax has been changed to another one, any function may be called
  by using the following construction:

      $aw_function_name<some args here if any>{{function body if any}}

* rewrite travis.yml
2016-01-31 00:00:12 +07:00
1c78e0d779 Initial support of templates and so on (#71)
* Initial syntax is the following:

    * $template{{ some JS code here }} - simple template based on JS
      code inside. It works the same as lambda functions, but calculates
      only once.
    * aw_count(regex) - keys count found for given regex
    * aw_keys(regex, [separator]) - keys found for given regex and
      joined by using given separator
    * aw_names(regex, [separator]) - key names found for given regex and
      joined by using given separator (the same as previous but w\o $)

  The template and function syntax may be changed before release.

* replace `foreach` to `for (auto foo : bar)` and update CONTRIBUTING.md
  accordingly
2016-01-30 00:07:47 +07:00
fba58c27e8 fix #73
I suppose the better way is to move weather adaptor to another open
weather engine despite the fact that OWM has provided me a special FOSS
permissions. I've changed weather provider to Yahoo! Weather because
there is no good way to provide my own API key to end-users except for
being compiled to the source code.

In other hand this solution leads to the fact that humidity and
atmosphere pressure is not available for forecast more. And moreover
pressure units has been changed for current weather.

+ fix possible memory leak in dataengine aggregator
+ add "special thanks" group to acknoledgment tab
2016-01-29 01:31:00 +07:00
4b679ff570 fix #74
Unfortunately there is no good way to resize tooptip dynamically if html
image is used. In other hand if tooltip type set to "names" it is
possible to resize tooptips to content size.

+ update gitignore
2016-01-28 12:44:45 +03:00
d8d2311621 edit dpkg options 2015-11-03 04:51:19 +03:00
809936a563 add --yes 2015-11-03 04:41:56 +03:00
2c1aa1a4c9 add dist upgrade before 2015-11-03 04:40:00 +03:00
02305b93d9 skip asking 2015-11-02 10:10:11 +03:00
aece0e2eff rename ppa accoring to pkgs.org search 2015-11-02 10:06:20 +03:00
c24e41d557 edit adding repo 2015-11-02 09:56:48 +03:00
5be3f9246b try use travis ci again 2015-11-02 09:53:49 +03:00
81d99e66b9 Merge branch 'development' 2015-10-26 18:44:20 +03:00
940ef13ffa add patches to tarball 2015-10-23 05:59:51 +03:00
5ee1cec909 authors update 2015-10-23 00:55:16 +03:00
83ec82debd Merge pull request #70 from arcan1s/development
Master update
2015-10-23 00:27:16 +03:00
193 changed files with 6553 additions and 3114 deletions

1
.gitignore vendored
View File

@ -43,6 +43,7 @@ build
*pkg.tar.[gx]z
src
pkg
*.deb
# clion settings
.idea

6
.gitmodules vendored
View File

@ -1,9 +1,3 @@
[submodule "sources/3rdparty/task"]
path = sources/3rdparty/task
url = https://github.com/arcan1s/qtadds-taskadds-qprocess.git
[submodule "sources/3rdparty/tasks"]
path = sources/3rdparty/tasks
url = https://github.com/mhogomchungu/tasks.git
[submodule "sources/3rdparty/fontdialog"]
path = sources/3rdparty/fontdialog
url = https://github.com/arcan1s/qtadds-fontdialog.git

View File

@ -1,7 +1,16 @@
install:
- sudo apt-get update -qq
- sudo apt-get install -y cmake extra-cmake-modules g++ git libkf5i18n-dev libkf5notifications-dev libkf5service-dev libkf5windowsystem-dev plasma-framework-dev qtbase5-dev qtdeclarative5-dev
- git submobule update --init
sudo: required
dist: trusty
language: cpp
os:
- linux
before_script:
- sudo apt-add-repository -y ppa:kubuntu-ppa/backports
- sudo sed -i 's/trusty/wily/g' /etc/apt/sources.list
- sudo sed -i 's/trusty/wily/g' /etc/apt/sources.list.d/kubuntu-ppa-backports-trusty.list
- sudo apt-get -qq update
- sudo apt-get -y -qq -o Dpkg::Options::=--force-confdef -o Dpkg::Options::=--force-confnew install libkf5i18n-dev libkf5notifications-dev libkf5service-dev libkf5windowsystem-dev plasma-framework-dev qtbase5-dev qtdeclarative5-dev extra-cmake-modules cmake g++
- rm -rf build
- mkdir build

8
.tx/config Normal file
View File

@ -0,0 +1,8 @@
[main]
host = https://www.transifex.com
[awesome-widgets.awesome-widgetspot]
source_file = sources/translations/awesome-widgets.pot
source_lang = en
type = PO
file_filter = sources/translations/<lang>.po

14
AUTHORS
View File

@ -1,9 +1,13 @@
Current developers:
Evgeniy Alekseev aka arcanis <esalexeev (at) gmail (dot) com>
Packagers:
Konstantin Voinov (openSuSe)
Translators:
@Mermouy (French translation)
Ernesto Avilés Vzqz (Spanish translation)
@underr (Brazillian Portuguese translation)
Виктор Слободян (Ukrainian translation)
Steve Lemuel (Chinese translation)
@Mermouy (French)
Ernesto Avilés Vzqz (Spanish)
@underr (Brazillian Portuguese)
Виктор Слободян (Ukrainian)
Steve Lemuel (Chinese)
Mariusz Kocoń (Polish)

View File

@ -1,3 +1,50 @@
Ver.3.1.2:
+ add standalone widget configuration example
+ new tag tstime
+ new tags uptotal* and downtotal*
+ add background configuration button
+ allow X-AW-Direction property works with graphs and bars (graphical items)
+ add bars support to Graphical Items
+ add integration with transifex
+ add integration with coverity
- drop update source (breaking changes if you are using it as developer)
- fix pen generation from file image (graphical items)
- fix bug with which font html parameters will be pasted even if there cancel clicked
- fix bug with invalid total memory formating
- fix bug in configuration UI with which there is no selected text pasted
- fixes in graphical item configuration UI and behaviour
- fix changelog building
- fix invalid cast (found by coverity)
* change text update mechanism
* grahical item improvements
* code improvements
* translation update
Ver.3.1.1:
- fix broken gcc build (#87)
* translation update
Ver.3.1.0:
+ implement templates support (#71)
+ implement special functions (#71)
+ special directory for configs (#72)
+ custom bar images (#80)
+ custom bar values (#80)
+ show changelog after updates
+ add Polish translation (thanks to Mariusz Kocoń)
+ use Qt-5.6 features
- fix invalid tooltip resize in desktop panel (#74)
- fix graphical items blinking (#81)
- drop tasks and move to native QProcess to avoid crash (#83)
- the newest Qt (5.6) fixes
- the newest Plasma fixes
* move from OWM to Yahoo! Weather (#73)
* improve performance by using optimized subscriptions (#75)
* improve performance by storing QVariant instead of frequent casting (#75)
* change bar names semantic to the simplest one (#80, breaking changes)
* high memory usage notifications have been changed from 90 to 80 perc
* a large part of refactoring
Ver.3.0.1:
+ add patches for old Qt versions
- drop `nullptr` checking

View File

@ -1,383 +0,0 @@
Вер.3.0.1:
+ добавлены патчи для старых версий Qt
- убрана проверка на nullptr
* диалоги перемещены в QML
Вер.3.0.0:
+ добавлены теги upunits, downunits, upkb, downkb
+ добавлены теги dalbum, dartist, dtitle, salbum, sartist, stitle
+ добавлена поддержка лямбда функций
+ добавлен голландский перевод (спасибо Heimen Stoffels)
+ добавлена опциональная проверка обновлений на старте
+ добавлена возможность отключить перевод строковых тегов
+ добавлена фильтрация в ExtUpgrade (ApiVer == 3)
+ добавлена возможность смены иконки погоды (ApiVer == 2)
+ показ сообщений, если не найдено обновлений, при прямом запросе
+ добавлено перенаправление swap в ExtScript (ApiVer == 4)
+ добавлена возможность переноса слов
+ добавлена поддержка графиков в GraphicalItems (ApiVer == 3)
+ добавлена возможность показать превью из настроек
+ добавлены импорт и экспорт конфигурации
- исправлен ворнинг для пустых тултипов
- исправлен баг, приводящий к увеличению виджета
- исправлен баг с отсутствием сохранения настроек DE
- исправлен баг с большим размером на старте
- исправлен баг с невозможностью использования более, чем 10 расширений
- убраны уведомления о свободном месте на диске
- убран ключ X-AW-Output в ExtScript (ApiVer == 4)
- исправлен возможное падение при вызове деструктора web-источников
* более удобный интерфейс настройки
* улучшено логирование, применен стиль логирования Qt5
* переключено на конкурентное обновление (-DBUILD_FUTURE=ON)
* немного оптимизаций
* лучшее определение активного сетевого устройства
* значение котировок типа double (ApiVer == 3)
* лучший показ котировок
* больше комментариев в коде
* большее следование стилю кода Qt
* настройки интервала перемещены в другую группу
* работа с DataEngine была перемещена в плагин
* изменен формат данных внутри DataEngine (ломает совместимость)
Вер.2.4.0:
+ добавлена поддержка погоды
+ добавлена поддержка LA (теги la1, la5, la15)
+ добавлена кнопка "Сбросить кеш"
+ добавлена поддержка сборки с clang
+ добавлен ExtItem агрегатор
+ добавлено время в дебаг вывод
+ добавлена возможность отключить монитор плеера
- исправлен баг с неправильным расчетам скорости сети
- исправлен баг с неправильной инициализацией диалога шрифтов
- исправлен баг с отсутствием удаления объектов (#60)
* переписаны ExtItems для использования собственного абстрактного класса
* улучшена работа с обновлениями виджета (#57)
* рисование интерфейса переписано на модель сигнал-слот
* плагин опять стал приватным
* исправлен каст плагина с синглтона (#57)
* изменена логика показа данных в DataEngine
* изменена сборка пакета и прекращена поддержка отдельного пакета с DataEngine
* замена QMap на QHash, если возможно
* замена циклов на итераторы, если возможно
* список рабочий столов сейчас представлен, как QStringList
* рефакторинг
Вер.2.3.3:
* изменен рендеринг с Qt на нативный
Вер.2.3.2:
+ добавлено изменение скорости интернета с KB/s на MB/s, если величина более 1000 KB/s
- пофикшен баг с отсутствием действия при активации ссылки (спасибо infans)
* улучшена поддержка котировок, например пофикшен возможный сегфолт плазмы
* переписать основной виджет к модели сигнал-слот
* улучшена поддержка расчета заряда батареи для нескольких батарей
Вер.2.3.1:
- пофикшен баг с отсутствием обновлений значений из настроек
- убрана поддержка фильтра `\t`
* обновлены переводы
* теги fan были объединены с temp, улучшена поддержка тегов lmsensors
Вер.2.3.0:
+ добавлена поддержка фильтров в ExtScript (ApiVer = 3) (#53)
+ добавлена возможность отображать `\n`, как перенос строки (#53)
+ добавлена сортировка ключей в комбобоксах
+ добавлена поддержка тегов (perc)(bid|ask|price)chg (ApiVer = 2)
+ добавлены таймауты запросов котировок (#54)
- исправлен баг с неправильным парсингом html
* ExtQuotes теперь использует JSON вместо XML (ApiVer = 2)
* более красивый UI настроек
* некоторый рефакторинг
Вер.2.2.2:
+ добавлена поддержка котировок (#46)
+ добавлена поддержка свойств height и width (#47)
+ добавлена поддержка перевода в плагины (#50)
+ добавлено кеширование ключей
+ добавлена поддержка X-AW-Number в ExtScript, ExtUpgrade (ApiVer=2)
+ добавлено переподключение DataEngine (в некоторых случаях отдельные значения не обновляются)
+ добавлено обновление ширины и высоты виджета
- исправлен баг при обновлении Ext* (#49)
- исправлен баг с сохранением настроек GPUDEV, HDDDEV из графического интерфейса
- исправлены настройки Desktop Panel
- исправлен баг с добавлением настроек параграфа
* дропнута поддержка KDE4 версии (отдельная ветка разработки)
* увеличены лимиты для интервалов (#48)
* hddtemp был заменен на smartctl по умолчанию
* плагины были перемещены из private
* более корректное рисование интерфейса
Вер.2.2.1:
+ добавлен ключ X-AW-Interval в ExtUpgrade (ApiVer = 1, default = 3600)
+ добавлено кеширование значений в ExtScript и ExtUpgrade
+ добавлена поддержка isActive в ExtUpgrade
* изменена проверка версий cmake
* улучшена логика работы ExtScript и ExtUpgrade
Вер.2.2.0:
* портирование на Plasma 5
+ добавлена поддержка списка окон в тултипе
+ добавлены уведомления на системные события
+ добавлена возможность показать выбранный тег
+ добавлены теги $downN, $upN
+ добавлен инструмент netdev
+ добавлена поддержка smartctl
- убрана возможность сокрытия панелей
* незначительно изменена логика работы виджета
* исправлена отрисовка превью окон
* обновление кодовой базы KDE4 под новый ABI
* оптимизация работы DataEngine
* PKGCMD были заменены на ExtUpgrade
Вер.2.1.0:
+ добавлена функция автообновления
+ добавлена поддерка кастомных скриптов
+ добавлена поддержка превью рабочего стола для DP
+ добавлена поддержка баров
- удалена поддержка кастомных команд
- фикс #34
* исправлены уведомления
* переписан UI в соответствии со стандартами KDE
* исправлены границы для графических объектов
* переписан DP и DE на использование библиотечных функций
* изменено определение свойств GPU
* изменен поиск регулярных выражений
Вер.2.0.5:
+ добавлен нижний край к тултипу (#30)
* исправлен баг с обновлением сетевого интерфейса
* исправлен баг с тултипом батареи
* отредактирована разметка DP (#31)
Вер.2.0.4:
* более корректная работа с батареями
Вер.2.0.3:
+ добавлена поддержка нескольких тегов $bat
* отредактирована разметка
Вер.2.0.2:
+ добавлены теги $fan*
+ добавлен китайский перевод (спасибо @Lemueler)
+ добавлена проверка сетевых устройств на p2p
- удалено ps stats из уведомлений
* еще один фикс тегов cpu* и cpucl
* переписан конфигурационный интерфейс DP
* исправлены нестандартные единицы температуры
Вер.2.0.1:
+ добавлена поддержка кастомных интерфейсов
* фикс затенения краев поля
* фикс тегов cpu*, cpucl*, gpu*, ps*
Вер.2.0.0:
+ добавлен виджет awesome widget
+ новые теги $hddfreemb, $hddfreegb, $memusedmb, $memusedgb, $memfreemb $memfreegb, $swapfreemb, $swapfreegb
+ новый DataEngine - battery
+ новый тултип - battery
+ новые температурные единицы см^-1, ккал/моль, кДж/моль, Реамюр
+ добавлена возможность скрывать панели по хоткею
- удален виджет pytextmonitor
- убраны отдельные поля
- удалены README
* проект переименован в Awesome Widgets
* тег $custom (время) переименован в $ctime
* тег $custom (время работы) переименован в $cuptime
* тег $time (плеер) переименован в $duration
* тег $number переименован в $ndesktop
* тег $name переименован в $desktop
* тег $total переименован в $tdesktops
* дебаг флаг теперь DEBUG
* проект полностью переписан на C++
* тултип независит теперь от самого виджета
* настройка выравнивания текста теперь осуществляется только HTML тегами
* настройки батареи и адаптора питания вынесены в DataEngine
* изменения в конфигурационном интерфейсе
Вер.1.11.0:
+ добавлена возможность отключения фона
+ добавлен desktop DataEngine
+ добавлен виджет PTM desktop panel
+ добавлено поле текущий рабочий стол (теги $name, $number, $total)
+ добавлена возможность взаимодействия с плеерами через mpris
* добавлено использование сабмодулей
* DataEngine переписан с использованием tasks
* фикс чтения температуры nvidia
Вер.1.10.2:
- фикс ошибки с tempUnits в поле hddtemp
Вер.1.10.1:
- пофикшена ошибка с форматами чисел в поле ps
- пофикшена инициализация значений в DataEngine
- пофикшена проверка qmmp
Вер.1.10.0:
+ добавлены теги $hddtotmb, $hddtotgb
+ добавлены теги $memtotmb, $memtotgb, $swaptotmb, $swaptotgb
+ добавлена возможность форсированного обновления
+ добавлена поддержка clementine
+ добавлена поддержка команды hddtemp
+ добавлены поддержка disable для HDDDEV и GPUDEV
+ добавлена многопоточность в DataEngine
+ добавлена проверка ошибок для переменных DataEngine
+ добавлена возможность отключения всплывающих сообщений
+ добавлена возможность использовать вертикальную разметку
+ добавлена возможность добавить пустое пространство
+ добавлена возможность вывода отладочной информации (установите переменную окружения 'PTM_DEBUG' в 'yes')
+ добавлен перевод Brazillian Portuguese (@underr)
+ добавлена украинская локализация (Виктор Слободян)
- удален util.py
- удалены функции createNotifyrc, поскольку они больше не нужны
* рефакторинг конфигурационного интерфейса
* настройки плеера были перенесены из виджета в DataEngine
* исправлен вызов readme под четырехсимвольное обозначение
* перенос readme с md на html
Вер.1.9.0:
+ добавлена поддержка нескольких кастомных команд ($customN)
+ добавлено поле скорости hdd ($hddrN, $hddwN)
+ добавлены действия в контекстное меню (открыть readme и запустить ksysguard)
* исправлен парсинг поля pkg
- убрано событие по двойному клику
Вер.1.8.3:
+ добавлен испанский перевод (Ernesto Avilés Vzqz)
+ добавлены файлы readme
Вер.1.8.2:
+ добавлены различные температурные единицы (Farenheit и Kelvin)
Вер.1.8.1:
* поле pkg теперь обновляется раз в час
Вер.1.8.0:
+ добавлены скроллбары в конфигурационный интерфейс
+ добавлена настройка значений AC
+ добавлены теги $hddmbN, $hddgbN
+ добавлена поддержка ps (теги $ps, $pscount, $pstotal)
+ добавлена поддержка пакетных менеджеров (теги $pkgcountN)
* рефакторинг DataEngine
Вер.1.7.4:
+ добавлена поддержка более чем 10 тэгов в полях cpu, cpuclock, hdd, hddtemp, temp
- фиксы в форматах
* изменения в кастомном формате аптайма
Вер.1.7.3:
+ добавлены тэги $memgb, $swapgb
+ добавлена директория readme
+ добавлен французский перевод (@Mermouy)
- фикс подсказки для кастомного формата аптайма
- фикс #12
* больше рефакторинга богу рефакторинга
* интервал обновления сетевого интерфейса теперь 30*interval
* тэги $swap, $swapmb и $swapgb теперь работают одновременно (тэги $mem* тоже)
* player_name теперь имеет тип str
Вер.1.7.2:
+ добавлены тэги $dd, $d, $hh, $h, $mm, $m в кастомный формат аптайма
+ добавлено масштабирование в тултипы
+ добавлена конфигурация DE из виджета
+ добавлена кастомная команда в DE
- удалена кастомная команда из виджета
- удалены тэги $ds, $hs, $ms
Вер.1.7.1:
- удалено поле с ошибкой
* пофикшен баг с нулевым значением в тултипе
Вер.1.7.0:
+ добавлена поддержка нескольких тэгов в поле температуры
+ добавлены тэги $cpuN, $cpuclN, $hddN, $tempN, $hddtempN, $up, $down
+ добавлено поле с кастомной командой
+ добавлены тултипы для полей CPU, частоты CPU, памяти, swap и сеть
- удалены тэги @@...@@, $temp, $ccpu, $ccpucl, $net
* изменения в настройках
* виджет не требует больше net-tools
* рефакторинг
Вер.1.6.1:
+ добавлена поддержка нескольких девайсов в поле hddtemp
- фикс #6
Вер.1.6.0:
+ добавлен тэг $custom в поля time и uptime (#8)
+ русский перевод
- фикс #6, #10
* лицензия изменена на GPLv3
* изменения в сборке проекта
Вер.1.5.3:
+ добавлены тэги $album, $progress и $time tags в поле плеера (#7)
- фикс бага с нулевым свопом
Вер.1.5.2:
+ добавлены тэги $isotime, $shorttime и $longtime в поле time
Вер.1.5.1:
+ добавлено поле time
Вер.1.5.0:
+ добавлено поле player
Вер.1.4.0:
+ добавлены уведомления
Вер.1.3.6:
- фикс #1, #2
Вер.1.3.5:
- фикс бага с определением сетевого устройства
Вер.1.3.4:
+ добавлено событие по двойному щелчку
+ добавлен автовыбор сетевого устройства
- фикс еще одного падения Плазмы
Вер.1.3.3:
* редактирование чтения температурного устройства
Вер.1.3.2b:
- фикс падения Плазмы
Вер.1.3.2:
+ добавлены поля GPU, GPU temp, HDD и HDD temp
+ добавлены тэги $ccpu и $ccpucl
- фикс некоторых багов
* оптимизация и рефакторинг
Вер.1.2.2:
+ добавлен тултип в строки
Вер.1.2.1:
* если батарея не существует, возвращает off
* если AC не существует, возвращает '(?)'
Вер.1.2.0:
+ добавлен тэг $ac в поле battery
+ добавлена настройка устройств батареи и AC
+ добавлена проверка ошибок
* тэг $bat теперь читается из /sys/*
Вер.1.1.4:
* изменения в парсинге acpi (поле battery)
Вер.1.1.3:
+ добавлена настройка ширины шрифта
- небольшие фиксы
* отредактирована настройка шрифта. Теперь настройки для шрифта работают нормально
Вер.1.1.2:
+ добавлено поле CPU clock
+ добавлена функция для обновления сетевого интерфейса (100*time_interval)
* изменено обновление слайдеров
Вер.1.1.1:
+ добавлены тэги $swapmb, $memmb, $netdev, @@netdev=...@@
- небольшие фиксы
* виджет теперь состоит из нескольких полей
* отредактирован конфигурационный интерфейс
Вер.1.0:
Первый релиз

View File

@ -36,14 +36,15 @@ for more details. To avoid manual labor there is automatic cmake target named
```
* `Q_PROPERTY` macro is allowed and recommended for QObject based classes.
* Qt macros (e.g. `signals`, `slots`, `Q_OBJECT`, etc) are allowed.
* Qt macros (e.g. `signals`, `slots`, `Q_OBJECT`, etc) are allowed. In other hand
`Q_FOREACH` (`foreach`) is not allowed use `for (auto foo : bar)` instead.
* Current project standard is **C++11**.
* Do not use C-like code:
* C-like style iteration if possible. Use `Q_FOREACH` (`foreach`) and
* C-like style iteration if possible. Use `for (auto foo : bar)` and
`std::for_each` instead if possible. It is also recommended to use iterators.
* C-like casts, use `const_cast`, `static_cast`, `dymanic_Cast` instead. Using
of `reinterpret_cast` is not recommended. It is highly recommended to use
`dynamic_Cast` with the exception catching. It is also possible to use
`dynamic_cast` with the exception catching. It is also possible to use
`qvariant_cast` if required. Exception is class constructors, e.g.:
```
@ -81,7 +82,7 @@ for more details. To avoid manual labor there is automatic cmake target named
* Create one file (source and header) per class.
* `else if` construction is allowed and recommended.
* 'true ? foo : bar' construction is allowed and recommended for one-line assignment.
* any global pointer should be assign to `nullptr` after deletion and before
* Any global pointer should be assign to `nullptr` after deletion and before
initialization. Exception: if object is deleted into class destructor.
Comments
@ -146,13 +147,12 @@ For logging please use [QLoggingCategory](http://doc.qt.io/qt-5/qloggingcategory
Available categories should be declared in `awdebug.*` files. The following log
levels should be used:
* **debug** (`qCDebug()`) - method arguments information.
* **debug** (`qCDebug()`) - method arguments information. Please note that it
is recommended to logging all arguments in the one line.
* **info** (`qCInfo()`) - additional information inside methods.
* **warning** (`qCWarning()`) - not critical information, which may be caused by
mistakes in configuration for example.
* **error** (`qCError()`) - an error which has been captured in runtime. All errors
should have own callback methods.
* **critical** (`qCCritical()`) - a critical error. After this error program will
* **critical** (`qCCritical()`) - a critical error. After this error program may
be terminated.
The empty log string (e.g. `qCDebug();`) is not allowed because the method names

View File

@ -1,6 +1,9 @@
awesome-widgets (ex-pytextmonitor)
==================================
[![Build Status](https://travis-ci.org/arcan1s/awesome-widgets.svg?branch=development)](https://travis-ci.org/arcan1s/awesome-widgets)
[![Coverity Scan Build Status](https://scan.coverity.com/projects/8254/badge.svg)](https://scan.coverity.com/projects/awesome-widgets)
Information
-----------
@ -66,9 +69,9 @@ See [milestones](https://github.com/arcan1s/awesome-widgets/milestones) for more
Links
-----
* [Homepage](http://arcanis.name/projects/awesome-widgets/)
* [Migration to 2.*](http://arcanis.name/en/2014/09/04/migration-to-v2/)
* [Scripts and bars](http://arcanis.name/en/2014/12/19/aw-v21-bells-and-whistles/)
* [Homepage](https://arcanis.me/projects/awesome-widgets/)
* [Migration to 2.*](https://arcanis.me/en/2014/09/04/migration-to-v2/)
* [Scripts and bars](https://arcanis.me/en/2014/12/19/aw-v21-bells-and-whistles/)
* Plasmoid on [kde-look](http://kde-look.org/content/show.php/Awesome+Widgets?content=157124)
* DataEngine on [kde-look](http://kde-look.org/content/show.php/Extended+Systemmonitor+DataEngine?content=158773)
* Archlinux [AUR](https://aur.archlinux.org/packages/plasma5-applet-awesome-widgets/) package

View File

@ -11,8 +11,8 @@ git submodule update --init --recursive
# build widget
ARCHIVE="awesome-widgets"
FILES="AUTHORS CHANGELOG CHANGELOG-RU COPYING"
IGNORELIST="build usr .kdev4 *.kdev4 .idea"
FILES="AUTHORS CHANGELOG COPYING packages patches"
IGNORELIST="build usr .kdev4 *.kdev4 .idea packages/*src.tar.xz"
# create archive
[[ -e ${ARCHIVE}-${VERSION}-src.tar.xz ]] && rm -f "${ARCHIVE}-${VERSION}-src.tar.xz"
[[ -d ${ARCHIVE} ]] && rm -rf "${ARCHIVE}"

View File

@ -2,11 +2,11 @@
pkgname=plasma5-applet-awesome-widgets
_pkgname=awesome-widgets
pkgver=3.0.1
pkgver=3.1.2
pkgrel=1
pkgdesc="Collection of minimalistic Plasmoids which look like Awesome WM widgets (ex-PyTextMonitor)"
arch=('i686' 'x86_64')
url="http://arcanis.name/projects/awesome-widgets"
url="https://arcanis.me/projects/awesome-widgets"
license=('GPL3')
depends=('plasma-framework')
optdepends=("catalyst: for GPU monitor"
@ -14,10 +14,10 @@ optdepends=("catalyst: for GPU monitor"
"smartmontools: for HDD temperature monitor"
"mpd: for music player monitor"
"nvidia-utils: for GPU monitor")
makedepends=('cmake' 'extra-cmake-modules')
makedepends=('cmake' 'extra-cmake-modules' 'python')
source=(https://github.com/arcan1s/awesome-widgets/releases/download/V.${pkgver}/${_pkgname}-${pkgver}-src.tar.xz)
install=${pkgname}.install
md5sums=('71f5b358d443075540377284ee868a93')
md5sums=('99514bf6d1a5ca8660dd0210ee58af28')
backup=('etc/xdg/plasma-dataengine-extsysmon.conf')
prepare() {

View File

@ -6,7 +6,7 @@ pkgver=2.2.1.r15.g78931b3
pkgrel=1
pkgdesc="Collection of minimalistic Plasmoids which look like Awesome WM widgets (ex-PyTextMonitor). Git version"
arch=('i686' 'x86_64')
url="http://arcanis.name/projects/awesome-widgets"
url="https://arcanis.me/projects/awesome-widgets"
license=('GPL3')
depends=('plasma-framework')
optdepends=("amarok: for music player monitor"

View File

@ -1,57 +0,0 @@
diff --git a/sources/awdebug.cpp b/sources/awdebug.cpp
index eee61e1..9da8dad 100644
--- a/sources/awdebug.cpp
+++ b/sources/awdebug.cpp
@@ -20,13 +20,10 @@
#include "version.h"
-Q_LOGGING_CATEGORY(LOG_AW, "org.kde.plasma.awesomewidget",
- QtMsgType::QtWarningMsg)
-Q_LOGGING_CATEGORY(LOG_DP, "org.kde.plasma.desktoppanel",
- QtMsgType::QtWarningMsg)
-Q_LOGGING_CATEGORY(LOG_ESM, "org.kde.plasma.extsysmon", QtMsgType::QtWarningMsg)
-Q_LOGGING_CATEGORY(LOG_LIB, "org.kde.plasma.awesomewidgets",
- QtMsgType::QtWarningMsg)
+Q_LOGGING_CATEGORY(LOG_AW, "org.kde.plasma.awesomewidget")
+Q_LOGGING_CATEGORY(LOG_DP, "org.kde.plasma.desktoppanel")
+Q_LOGGING_CATEGORY(LOG_ESM, "org.kde.plasma.extsysmon")
+Q_LOGGING_CATEGORY(LOG_LIB, "org.kde.plasma.awesomewidgets")
const QStringList getBuildData()
diff --git a/sources/awesome-widget/plugin/awkeys.cpp b/sources/awesome-widget/plugin/awkeys.cpp
index e5b9861..eb73073 100644
--- a/sources/awesome-widget/plugin/awkeys.cpp
+++ b/sources/awesome-widget/plugin/awkeys.cpp
@@ -439,7 +439,7 @@ void AWKeys::dataUpdated(const QString &sourceName,
#ifdef BUILD_FUTURE
// run concurrent data update
- QtConcurrent::run(m_threadPool, this, &AWKeys::setDataBySource, sourceName,
+ QtConcurrent::run(this, &AWKeys::setDataBySource, sourceName,
data);
#else /* BUILD_FUTURE */
return setDataBySource(sourceName, data);
@@ -564,7 +564,7 @@ void AWKeys::reinitKeys()
void AWKeys::updateTextData()
{
#ifdef BUILD_FUTURE
- QFuture<QString> text = QtConcurrent::run(m_threadPool, [this]() {
+ QFuture<QString> text = QtConcurrent::run([this]() {
calculateValues();
return parsePattern(m_pattern);
});
diff --git a/sources/libraries.cmake b/sources/libraries.cmake
index 33192f7..46e2b1e 100644
--- a/sources/libraries.cmake
+++ b/sources/libraries.cmake
@@ -2,7 +2,7 @@
find_package(Gettext REQUIRED)
# main qt libraries
-find_package(Qt5 5.4.0 REQUIRED COMPONENTS Core DBus Network Qml Widgets)
+find_package(Qt5 5.3.0 REQUIRED COMPONENTS Core DBus Network Qml Widgets)
add_definitions(
${Qt5Core_DEFINITIONS} ${Qt5DBus_DEFINITIONS} ${Qt5Network_DEFINITIONS}
${Qt5Qml_DEFINITIONS} ${Qt5Widgets_DEFINITIONS}

7
patches/PATCHING.md Normal file
View File

@ -0,0 +1,7 @@
* Using git tree from root git directory:
git apply path/to/patch
* Using release tarball from root directory:
patch -p2 -i path/to/patch

View File

@ -10,7 +10,7 @@ index 01bcd58..1ec7ba6 100644
import org.kde.plasma.private.awesomewidget 1.0
@@ -372,31 +371,7 @@ Item {
@@ -372,32 +371,7 @@ Item {
QtControls.Button {
width: parent.width * 3 / 5
text: i18n("Export configuration")
@ -21,6 +21,7 @@ index 01bcd58..1ec7ba6 100644
- id: saveConfigAs
- selectExisting: false
- title: i18n("Export")
- folder: awConfig.configurationDirectory()
- onAccepted: {
- var status = awConfig.exportConfiguration(
- plasmoid.configuration,
@ -43,7 +44,7 @@ index 01bcd58..1ec7ba6 100644
}
}
@@ -410,41 +385,9 @@ Item {
@@ -410,42 +385,9 @@ Item {
QtControls.Button {
width: parent.width * 3 / 5
text: i18n("Import configuration")
@ -53,6 +54,7 @@ index 01bcd58..1ec7ba6 100644
- QtDialogs.FileDialog {
- id: openConfig
- title: i18n("Import")
- folder: awConfig.configurationDirectory()
- onAccepted: importSelection.open()
- }
-
@ -219,9 +221,9 @@ index 6263b30..5f61d2a 100644
// extensions
- if (importExtensions) {
+ if (selection[QString("extensions")]) {
foreach (QString item, m_dirs) {
for (auto item : m_dirs) {
settings.beginGroup(item);
foreach (QString it, settings.childGroups())
for (auto it : settings.childGroups())
@@ -121,7 +139,7 @@ QVariantMap AWConfigHelper::importConfiguration(const QString fileName,
}
@ -238,7 +240,7 @@ index 6263b30..5f61d2a 100644
- if (importPlasmoid) {
+ if (selection[QString("plasmoid")]) {
settings.beginGroup(QString("plasmoid"));
foreach (QString key, settings.childKeys())
for (auto key : settings.childKeys())
configuration[key] = settings.value(key);
@@ -261,6 +279,50 @@ void AWConfigHelper::readFile(QSettings &settings, const QString key,
}
@ -295,9 +297,10 @@ diff --git a/sources/awesome-widget/plugin/awconfighelper.h b/sources/awesome-wi
index 912ac3d..dc51dfb 100644
--- a/sources/awesome-widget/plugin/awconfighelper.h
+++ b/sources/awesome-widget/plugin/awconfighelper.h
@@ -33,12 +33,8 @@ public:
@@ -33,13 +33,9 @@ public:
explicit AWConfigHelper(QObject *parent = nullptr);
virtual ~AWConfigHelper();
Q_INVOKABLE QString configurationDirectory() const;
Q_INVOKABLE bool dropCache() const;
- Q_INVOKABLE bool exportConfiguration(QObject *nativeConfig,
- const QString fileName) const;
@ -322,10 +325,11 @@ diff --git a/sources/awesome-widget/plugin/awkeys.cpp b/sources/awesome-widget/p
index e5b9861..039d24e 100644
--- a/sources/awesome-widget/plugin/awkeys.cpp
+++ b/sources/awesome-widget/plugin/awkeys.cpp
@@ -324,6 +324,13 @@ QStringList AWKeys::getHddDevices() const
@@ -324,6 +324,14 @@ QStringList AWKeys::getHddDevices() const
}
+#include <QInputDialog>
+QString AWKeys::graphicalKey() const
+{
+ return QInputDialog::getItem(nullptr, i18n("Select tag"), QString(),
@ -335,7 +339,7 @@ index e5b9861..039d24e 100644
+
QString AWKeys::infoByKey(QString key) const
{
qCDebug(LOG_AW) << "Requested key" << key;
qCDebug(LOG_AW) << "Requested info for key" << key;
diff --git a/sources/awesome-widget/plugin/awkeys.h b/sources/awesome-widget/plugin/awkeys.h
index a8300f1..8edc3bd 100644
--- a/sources/awesome-widget/plugin/awkeys.h
@ -348,3 +352,48 @@ index a8300f1..8edc3bd 100644
// values
Q_INVOKABLE QString infoByKey(QString key) const;
Q_INVOKABLE QString valueByKey(QString key) const;
diff --git a/sources/awdebug.cpp b/sources/awdebug.cpp
index eee61e1..9da8dad 100644
--- a/sources/awdebug.cpp
+++ b/sources/awdebug.cpp
@@ -20,13 +20,10 @@
#include "awdebug.h"
-Q_LOGGING_CATEGORY(LOG_AW, "org.kde.plasma.awesomewidget",
- QtMsgType::QtWarningMsg)
-Q_LOGGING_CATEGORY(LOG_DP, "org.kde.plasma.desktoppanel",
- QtMsgType::QtWarningMsg)
-Q_LOGGING_CATEGORY(LOG_ESM, "org.kde.plasma.extsysmon", QtMsgType::QtWarningMsg)
-Q_LOGGING_CATEGORY(LOG_LIB, "org.kde.plasma.awesomewidgets",
- QtMsgType::QtWarningMsg)
+Q_LOGGING_CATEGORY(LOG_AW, "org.kde.plasma.awesomewidget")
+Q_LOGGING_CATEGORY(LOG_DP, "org.kde.plasma.desktoppanel")
+Q_LOGGING_CATEGORY(LOG_ESM, "org.kde.plasma.extsysmon")
+Q_LOGGING_CATEGORY(LOG_LIB, "org.kde.plasma.awesomewidgets")
const QStringList getBuildData()
diff --git a/sources/awesome-widget/plugin/awkeys.cpp b/sources/awesome-widget/plugin/awkeys.cpp
index e5b9861..eb73073 100644
--- a/sources/awesome-widget/plugin/awkeys.cpp
+++ b/sources/awesome-widget/plugin/awkeys.cpp
@@ -439,4 +439,4 @@ void AWKeys::dataUpdated(const QString &sourceName,
{
// run concurrent data update
- QtConcurrent::run(m_threadPool, this, &AWKeys::setDataBySource, sourceName,
+ QtConcurrent::run(this, &AWKeys::setDataBySource, sourceName,
data);
diff --git a/sources/libraries.cmake b/sources/libraries.cmake
index 33192f7..46e2b1e 100644
--- a/sources/libraries.cmake
+++ b/sources/libraries.cmake
@@ -2,7 +2,7 @@
find_package(Gettext REQUIRED)
# main qt libraries
-find_package(Qt5 5.4.0 REQUIRED COMPONENTS Core DBus Network Qml Widgets)
+find_package(Qt5 5.3.0 REQUIRED COMPONENTS Core DBus Network Qml Widgets)
add_definitions(
${Qt5Core_DEFINITIONS} ${Qt5DBus_DEFINITIONS} ${Qt5Network_DEFINITIONS}
${Qt5Qml_DEFINITIONS} ${Qt5Widgets_DEFINITIONS}

View File

@ -11,19 +11,21 @@ index f808d03..a056b3f 100644
#include "version.h"
diff --git a/sources/awdebug.h b/sources/awdebug.h
index 48dc580..530c0d6 100644
index 43944ce..c679281 100644
--- a/sources/awdebug.h
+++ b/sources/awdebug.h
@@ -23,9 +23,9 @@
@@ -21,9 +21,13 @@
#include "version.h"
+#ifndef qCInfo
+#define qCInfo qCDebug
+#endif
+
#ifndef LOG_FORMAT
#define LOG_FORMAT \
- "[%{time process}][%{if-debug}DD%{endif}%{if-info}II%{endif}%{if-" \
- "warning}WW%{endif}%{if-critical}CC%{endif}%{if-fatal}FF%{endif}][%{" \
- "category}][%{function}] %{message}"
+ "[%{time process}][%{if-debug}DD%{endif}%{if-warning}WW%{endif}%{if-" \
+ "critical}CC%{endif}%{if-fatal}FF%{endif}][%{category}][%{function}] " \
+ "%{message}"
+ "[%{time process}][%{if-debug}DD%{endif}%{if-" \
"warning}WW%{endif}%{if-critical}CC%{endif}%{if-fatal}FF%{endif}][%{" \
"category}][%{function}] %{message}"
#endif /* LOG_FORMAT */
// redefine info because it doesn't log properly

View File

@ -0,0 +1,148 @@
diff --git a/sources/awesome-widget/plugin/awupdatehelper.cpp b/sources/awesome-widget/plugin/awupdatehelper.cpp
index 3698602..42871c8 100644
--- a/sources/awesome-widget/plugin/awupdatehelper.cpp
+++ b/sources/awesome-widget/plugin/awupdatehelper.cpp
@@ -37,7 +37,7 @@ AWUpdateHelper::AWUpdateHelper(QObject *parent)
{
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
- m_foundVersion = QVersionNumber::fromString(VERSION);
+ m_foundVersion = QString(VERSION);
m_genericConfig = QString("%1/awesomewidgets/general.ini")
.arg(QStandardPaths::writableLocation(
QStandardPaths::GenericDataLocation));
@@ -69,15 +69,15 @@ void AWUpdateHelper::checkUpdates(const bool showAnyway)
bool AWUpdateHelper::checkVersion()
{
QSettings settings(m_genericConfig, QSettings::IniFormat);
- QVersionNumber version = QVersionNumber::fromString(
- settings.value(QString("Version"), QString(VERSION)).toString());
+ QString version
+ = settings.value(QString("Version"), QString(VERSION)).toString();
// update version
settings.setValue(QString("Version"), QString(VERSION));
settings.sync();
qCInfo(LOG_AW) << "Found version" << version << "actual one is"
<< m_foundVersion;
- if ((version != m_foundVersion) && (!QString(CHANGELOG).isEmpty())) {
+ if ((version != QString(VERSION)) && (!QString(CHANGELOG).isEmpty())) {
genMessageBox(i18n("Changelog of %1", QString(VERSION)),
QString(CHANGELOG).replace(QChar('@'), QChar('\n')),
QMessageBox::Ok)
@@ -90,12 +90,11 @@ bool AWUpdateHelper::checkVersion()
}
-void AWUpdateHelper::showInfo(const QVersionNumber version)
+void AWUpdateHelper::showInfo(const QString version)
{
qCDebug(LOG_AW) << "Version" << version;
- QString text
- = i18n("You are using the actual version %1", version.toString());
+ QString text = i18n("You are using the actual version %1", version);
if (!QString(COMMIT_SHA).isEmpty())
text += QString(" (%1)").arg(QString(COMMIT_SHA));
return genMessageBox(i18n("No new version found"), text, QMessageBox::Ok)
@@ -103,7 +102,7 @@ void AWUpdateHelper::showInfo(const QVersionNumber version)
}
-void AWUpdateHelper::showUpdates(const QVersionNumber version)
+void AWUpdateHelper::showUpdates(const QString version)
{
qCDebug(LOG_AW) << "Version" << version;
@@ -112,7 +111,7 @@ void AWUpdateHelper::showUpdates(const QVersionNumber version)
text += QString(COMMIT_SHA).isEmpty()
? QString("\n")
: QString(" (%1)\n").arg(QString(COMMIT_SHA));
- text += i18n("New version : %1", version.toString()) + QString("\n\n");
+ text += i18n("New version : %1", version) + QString("\n\n");
text += i18n("Click \"Ok\" to download");
genMessageBox(i18n("There are updates"), text,
@@ -128,8 +127,7 @@ void AWUpdateHelper::userReplyOnUpdates(QAbstractButton *button)
switch (ret) {
case QMessageBox::AcceptRole:
- QDesktopServices::openUrl(QString(RELEASES)
- + m_foundVersion.toString());
+ QDesktopServices::openUrl(QString(RELEASES) + m_foundVersion);
break;
case QMessageBox::RejectRole:
default:
@@ -157,14 +155,23 @@ void AWUpdateHelper::versionReplyRecieved(QNetworkReply *reply,
QVariantMap firstRelease = jsonDoc.toVariant().toList().first().toMap();
QString version = firstRelease[QString("tag_name")].toString();
version.remove(QString("V."));
- m_foundVersion = QVersionNumber::fromString(version);
+ m_foundVersion = version;
qCInfo(LOG_AW) << "Update found version to" << m_foundVersion;
- QVersionNumber oldVersion = QVersionNumber::fromString(VERSION);
- if (oldVersion < m_foundVersion)
- return showUpdates(m_foundVersion);
+ // FIXME: possible there is a better way to check versions
+ int old_major = QString(VERSION).split(QChar('.')).at(0).toInt();
+ int old_minor = QString(VERSION).split(QChar('.')).at(1).toInt();
+ int old_patch = QString(VERSION).split(QChar('.')).at(2).toInt();
+ int new_major = version.split(QChar('.')).at(0).toInt();
+ int new_minor = version.split(QChar('.')).at(1).toInt();
+ int new_patch = version.split(QChar('.')).at(2).toInt();
+ if ((old_major < new_major)
+ || ((old_major == new_major) && (old_minor < new_minor))
+ || ((old_major == new_major) && (old_minor == new_minor)
+ && (old_patch < new_patch)))
+ return showUpdates(version);
else if (showAnyway)
- return showInfo(m_foundVersion);
+ return showInfo(version);
}
diff --git a/sources/awesome-widget/plugin/awupdatehelper.h b/sources/awesome-widget/plugin/awupdatehelper.h
index 359cdb2..9c6a42d 100644
--- a/sources/awesome-widget/plugin/awupdatehelper.h
+++ b/sources/awesome-widget/plugin/awupdatehelper.h
@@ -21,7 +21,6 @@
#include <QMessageBox>
#include <QObject>
-#include <QVersionNumber>
class QNetworkReply;
@@ -37,15 +36,15 @@ public:
bool checkVersion();
private slots:
- void showInfo(const QVersionNumber version);
- void showUpdates(const QVersionNumber version);
+ void showInfo(const QString version);
+ void showUpdates(const QString version);
void userReplyOnUpdates(QAbstractButton *button);
void versionReplyRecieved(QNetworkReply *reply, const bool showAnyway);
private:
QMessageBox *genMessageBox(const QString title, const QString body,
const QMessageBox::StandardButtons buttons);
- QVersionNumber m_foundVersion;
+ QString m_foundVersion;
QString m_genericConfig;
};
diff --git a/sources/libraries.cmake b/sources/libraries.cmake
index 33192f7..339bb58 100644
--- a/sources/libraries.cmake
+++ b/sources/libraries.cmake
@@ -2,7 +2,7 @@
find_package(Gettext REQUIRED)
# main qt libraries
-find_package(Qt5 5.6.0 REQUIRED COMPONENTS Core DBus Network Qml Widgets)
+find_package(Qt5 5.4.0 REQUIRED COMPONENTS Core DBus Network Qml Widgets)
add_definitions(
${Qt5Core_DEFINITIONS} ${Qt5DBus_DEFINITIONS} ${Qt5Network_DEFINITIONS}
${Qt5Qml_DEFINITIONS} ${Qt5Widgets_DEFINITIONS}

Submodule sources/3rdparty/task deleted from d2798204a1

Submodule sources/3rdparty/tasks deleted from 230bdecd2c

View File

@ -14,8 +14,8 @@ set(PROJECT_AUTHOR "Evgeniy Alekseev")
set(PROJECT_CONTACT "esalexeev@gmail.com")
set(PROJECT_LICENSE "GPL3")
set(PROJECT_VERSION_MAJOR "3")
set(PROJECT_VERSION_MINOR "0")
set(PROJECT_VERSION_PATCH "1")
set(PROJECT_VERSION_MINOR "1")
set(PROJECT_VERSION_PATCH "2")
set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
# append git version if any
set(PROJECT_COMMIT_SHA "Commit hash" CACHE INTERNAL "")
@ -35,9 +35,10 @@ option(BUILD_RPM_PACKAGE "Build rpm package" OFF)
# build details
option(BUILD_FUTURE "Build with the features which will be marked as stable later" OFF)
option(BUILD_TESTING "Build with additional test abilities" OFF)
# some additional targets
set(CLANGFORMAT_EXECUTABLE "/usr/bin/clang-format" CACHE STRING "Path to clang-format executable")
set(CPPCHECK_EXECUTABLE "/usr/bin/cppcheck" CACHE STRING "Path to cppcheck executable")
# generate changelog
set(PROJECT_CHANGELOG "Changelog" CACHE INTERNAL "")
include(changelog.cmake)
# flags
if (CMAKE_COMPILER_IS_GNUCXX)
@ -68,6 +69,7 @@ set(PROJECT_LIBRARY awesomewidgets)
include(libraries.cmake)
include(clang-format.cmake)
include(cppcheck.cmake)
include(coverity.cmake)
get_directory_property(CMAKE_DEFINITIONS COMPILE_DEFINITIONS)
configure_file(${CMAKE_SOURCE_DIR}/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/version.h)

View File

@ -17,7 +17,6 @@
#include "awdebug.h"
#include "version.h"
Q_LOGGING_CATEGORY(LOG_AW, "org.kde.plasma.awesomewidget",
@ -46,6 +45,7 @@ const QStringList getBuildData()
metadata.append(QString(" AWEUAPI: %1").arg(AWEUAPI));
metadata.append(QString(" AWEWAPI: %1").arg(AWEWAPI));
metadata.append(QString(" TIME_KEYS: %1").arg(TIME_KEYS));
metadata.append(QString(" STATIC_KEYS: %1").arg(STATIC_KEYS));
// cmake properties
metadata.append(QString("cmake properties:"));
metadata.append(QString(" CMAKE_BUILD_TYPE: %1").arg(CMAKE_BUILD_TYPE));
@ -68,6 +68,7 @@ const QStringList getBuildData()
.arg(CMAKE_SHARED_LINKER_FLAGS));
// components
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_DEB_PACKAGE: %1").arg(BUILD_DEB_PACKAGE));
@ -75,10 +76,18 @@ const QStringList getBuildData()
QString(" BUILD_RPM_PACKAGE: %1").arg(BUILD_RPM_PACKAGE));
metadata.append(
QString(" CLANGFORMAT_EXECUTABLE: %1").arg(CLANGFORMAT_EXECUTABLE));
metadata.append(QString(" COVERITY_COMMENT: %1").arg(COVERITY_COMMENT));
metadata.append(
QString(" COVERITY_DIRECTORY: %1").arg(COVERITY_DIRECTORY));
metadata.append(QString(" COVERITY_EMAIL: %1").arg(COVERITY_EMAIL));
metadata.append(
QString(" COVERITY_EXECUTABLE: %1").arg(COVERITY_EXECUTABLE));
metadata.append(QString(" COVERITY_URL: %1").arg(COVERITY_URL));
metadata.append(
QString(" CPPCHECK_EXECUTABLE: %1").arg(CPPCHECK_EXECUTABLE));
// additional functions
metadata.append(QString(" PROP_FUTURE: %1").arg(PROP_FUTURE));
metadata.append(QString(" PROP_FUTURE: %1").arg(PROP_FUTURE));
metadata.append(QString(" PROP_TEST: %1").arg(PROP_TEST));
return metadata;
}

View File

@ -21,6 +21,8 @@
#include <QLoggingCategory>
#include "version.h"
#ifndef LOG_FORMAT
#define LOG_FORMAT \
"[%{time process}][%{if-debug}DD%{endif}%{if-info}II%{endif}%{if-" \
@ -28,12 +30,6 @@
"category}][%{function}] %{message}"
#endif /* LOG_FORMAT */
// redefine info because it doesn't log properly
#ifdef qCInfo
#undef qCInfo
#endif /* qCInfo */
#define qCInfo qCDebug
Q_DECLARE_LOGGING_CATEGORY(LOG_AW)
Q_DECLARE_LOGGING_CATEGORY(LOG_DP)

View File

@ -21,7 +21,7 @@ X-KDE-PluginInfo-Author=Evgeniy Alekseev aka arcanis
X-KDE-PluginInfo-Email=esalexeev@gmail.com
X-KDE-PluginInfo-Name=org.kde.plasma.awesomewidget
X-KDE-PluginInfo-Version=@PROJECT_VERSION@
X-KDE-PluginInfo-Website=http://arcanis.name/projects/awesome-widgets/
X-KDE-PluginInfo-Website=https://arcanis.me/projects/awesome-widgets/
X-KDE-PluginInfo-Category=System Information
X-KDE-PluginInfo-Depends=
X-KDE-PluginInfo-License=GPLv3

View File

@ -32,6 +32,9 @@
<entry name="checkUpdates" type="bool">
<default>true</default>
</entry>
<entry name="optimize" type="bool">
<default>true</default>
</entry>
<entry name="height" type="int">
<default>0</default>
</entry>
@ -95,13 +98,13 @@
<entry name="swapTooltipColor" type="string">
<default>#ffff00</default>
</entry>
<entry name="downTooltip" type="bool">
<entry name="downkbTooltip" type="bool">
<default>true</default>
</entry>
<entry name="downTooltipColor" type="string">
<entry name="downkbTooltipColor" type="string">
<default>#00ffff</default>
</entry>
<entry name="upTooltipColor" type="string">
<entry name="upkbTooltipColor" type="string">
<default>#ff00ff</default>
</entry>
<entry name="batTooltip" type="bool">

View File

@ -97,6 +97,15 @@ Item {
text: awActions.getAboutText("translators")
}
QtControls.Label {
QtLayouts.Layout.fillWidth: true
wrapMode: Text.WordWrap
horizontalAlignment: Text.AlignJustify
textFormat: Text.RichText
text: awActions.getAboutText("3rdparty")
onLinkActivated: Qt.openUrlExternally(link);
}
QtControls.Label {
QtLayouts.Layout.fillHeight: true
QtLayouts.Layout.fillWidth: true
@ -104,7 +113,7 @@ Item {
horizontalAlignment: Text.AlignJustify
verticalAlignment: Text.AlignTop
textFormat: Text.RichText
text: awActions.getAboutText("3rdparty")
text: awActions.getAboutText("thanks")
onLinkActivated: Qt.openUrlExternally(link);
}
}

View File

@ -45,6 +45,7 @@ Item {
property alias cfg_wrapText: wordWrap.checked
property alias cfg_notify: notify.checked
property alias cfg_checkUpdates: updates.checked
property alias cfg_optimize: optimize.checked
property alias cfg_height: widgetHeight.value
property alias cfg_width: widgetWidth.value
property alias cfg_interval: update.value
@ -143,6 +144,20 @@ Item {
}
}
Row {
height: implicitHeight
width: parent.width
QtControls.Label {
height: parent.heigth
width: parent.width * 2 / 5
}
QtControls.CheckBox {
id: optimize
width: parent.width * 3 / 5
text: i18n("Optimize subscription")
}
}
Row {
height: implicitHeight
width: parent.width
@ -379,6 +394,7 @@ Item {
id: saveConfigAs
selectExisting: false
title: i18n("Export")
folder: awConfig.configurationDirectory()
onAccepted: {
var status = awConfig.exportConfiguration(
plasmoid.configuration,
@ -416,6 +432,7 @@ Item {
QtDialogs.FileDialog {
id: openConfig
title: i18n("Import")
folder: awConfig.configurationDirectory()
onAccepted: importSelection.open()
}

View File

@ -46,15 +46,15 @@ Item {
"cpuclTooltip": plasmoid.configuration.cpuclTooltip,
"memTooltip": plasmoid.configuration.memTooltip,
"swapTooltip": plasmoid.configuration.swapTooltip,
"downTooltip": plasmoid.configuration.downTooltip,
"upTooltip": plasmoid.configuration.downTooltip,
"downkbTooltip": plasmoid.configuration.downkbTooltip,
"upkbTooltip": plasmoid.configuration.downkbTooltip,
"batTooltip": plasmoid.configuration.batTooltip,
"cpuTooltipColor": plasmoid.configuration.cpuTooltipColor,
"cpuclTooltipColor": plasmoid.configuration.cpuclTooltipColor,
"memTooltipColor": plasmoid.configuration.memTooltipColor,
"swapTooltipColor": plasmoid.configuration.swapTooltipColor,
"downTooltipColor": plasmoid.configuration.downTooltipColor,
"upTooltipColor": plasmoid.configuration.upTooltipColor,
"downkbTooltipColor": plasmoid.configuration.downkbTooltipColor,
"upkbTooltipColor": plasmoid.configuration.upkbTooltipColor,
"batTooltipColor": plasmoid.configuration.batTooltipColor,
"batInTooltipColor": plasmoid.configuration.batInTooltipColor,
// additional field to parse AC status
@ -84,7 +84,7 @@ Item {
// ui
Text {
id: text
anchors.fill: parent
anchors.fill: Plasmoid.Layout
renderType: Text.NativeRendering
textFormat: Text.RichText
wrapMode: plasmoid.configuration.wrapText ? Text.WordWrap : Text.NoWrap
@ -136,7 +136,9 @@ Item {
if (debug) console.debug()
// actions
plasmoid.setAction("requestKey", i18n("Request key"), "utilities-system-monitor")
// it makes no sense to use this field with optimization enable
if (!plasmoid.configuration.optimize)
plasmoid.setAction("requestKey", i18n("Request key"), "utilities-system-monitor")
plasmoid.setAction("showReadme", i18n("Show README"), "text-x-readme")
plasmoid.setAction("checkUpdates", i18n("Check updates"), "system-software-update")
// init submodule
@ -187,9 +189,9 @@ Item {
if (debug) console.debug()
// init submodule
awKeys.initKeys(plasmoid.configuration.text, plasmoid.configuration.interval,
plasmoid.configuration.queueLimit)
awKeys.initDataAggregator(tooltipSettings)
awKeys.initKeys(plasmoid.configuration.text, plasmoid.configuration.interval,
plasmoid.configuration.queueLimit, plasmoid.configuration.optimize)
awKeys.setWrapNewLines(plasmoid.configuration.wrapNewLines)
// configure aggregator
awKeys.setAggregatorProperty("acOffline", plasmoid.configuration.acOffline)

View File

@ -48,9 +48,9 @@ Item {
property alias cfg_memTooltipColor: memTooltipColor.text
property alias cfg_swapTooltip: swapTooltip.checked
property alias cfg_swapTooltipColor: swapTooltipColor.text
property alias cfg_downTooltip: downTooltip.checked
property alias cfg_downTooltipColor: downTooltipColor.text
property alias cfg_upTooltipColor: upTooltipColor.text
property alias cfg_downkbTooltip: downkbTooltip.checked
property alias cfg_downkbTooltipColor: downkbTooltipColor.text
property alias cfg_upkbTooltipColor: upkbTooltipColor.text
property alias cfg_batTooltip: batTooltip.checked
property alias cfg_batTooltipColor: batTooltipColor.text
property alias cfg_batInTooltipColor: batInTooltipColor.text
@ -273,7 +273,7 @@ Item {
}
QtControls.GroupBox {
id: downTooltip
id: downkbTooltip
height: implicitHeight
width: parent.width
checkable: true
@ -292,22 +292,22 @@ Item {
text: i18n("Download speed color")
}
QtControls.Button {
id: downTooltipColor
id: downkbTooltipColor
width: parent.width * 3 / 5
style: QtStyles.ButtonStyle {
background: Rectangle {
color: plasmoid.configuration.downTooltipColor
color: plasmoid.configuration.downkbTooltipColor
}
}
text: plasmoid.configuration.downTooltipColor
onClicked: downTooltipColorDialog.visible = true
text: plasmoid.configuration.downkbTooltipColor
onClicked: downkbTooltipColorDialog.visible = true
}
QtDialogs.ColorDialog {
id: downTooltipColorDialog
id: downkbTooltipColorDialog
title: i18n("Select a color")
color: downTooltipColor.text
onAccepted: downTooltipColor.text = downTooltipColorDialog.color
color: downkbTooltipColor.text
onAccepted: downkbTooltipColor.text = downkbTooltipColorDialog.color
}
}
Row {
@ -321,22 +321,22 @@ Item {
text: i18n("Upload speed color")
}
QtControls.Button {
id: upTooltipColor
id: upkbTooltipColor
width: parent.width * 3 / 5
style: QtStyles.ButtonStyle {
background: Rectangle {
color: plasmoid.configuration.upTooltipColor
color: plasmoid.configuration.upkbTooltipColor
}
}
text: plasmoid.configuration.upTooltipColor
onClicked: upTooltipColorDialog.visible = true
text: plasmoid.configuration.upkbTooltipColor
onClicked: upkbTooltipColorDialog.visible = true
}
QtDialogs.ColorDialog {
id: upTooltipColorDialog
id: upkbTooltipColorDialog
title: i18n("Select a color")
color: upTooltipColor.text
onAccepted: upTooltipColor.text = upTooltipColorDialog.color
color: upkbTooltipColor.text
onAccepted: upkbTooltipColor.text = upkbTooltipColorDialog.color
}
}
}

View File

@ -53,7 +53,7 @@ Item {
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
wrapMode: Text.WordWrap
text: i18n("Detailed information may be found on <a href=\"http://arcanis.name/projects/awesome-widgets/\">project homepage</a>")
text: i18n("Detailed information may be found on <a href=\"https://arcanis.me/projects/awesome-widgets/\">project homepage</a>")
onLinkActivated: Qt.openUrlExternally(link);
}
@ -61,7 +61,24 @@ Item {
height: implicitHeight
width: parent.width
QtControls.Button {
width: parent.width * 3 / 12
width: parent.width * 3 / 15
text: i18n("Bgcolor")
onClicked: backgroundDialog.visible = true
QtDialogs.ColorDialog {
id: backgroundDialog
title: i18n("Select a color")
onAccepted: {
var text = textPattern.text
textPattern.text = "<body bgcolor=\"" +
backgroundDialog.color + "\">" +
text + "</body>"
}
}
}
QtControls.Button {
width: parent.width * 3 / 15
text: i18n("Font")
iconName: "font"
@ -73,123 +90,119 @@ Item {
"size": plasmoid.configuration.fontSize
}
var font = awActions.getFont(defaultFont)
var pos = textPattern.cursorPosition
if (font.applied != 1) {
if (debug) console.debug("No font selected")
return
}
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
textPattern.insert(pos, "<span style=\"color:" + font.color +
"; font-family:'" + font.family +
"'; font-size:" + font.size + "pt;\">" +
selected + "</span>")
textPattern.insert(textPattern.cursorPosition,
"<span style=\"color:" + font.color +
"; font-family:'" + font.family +
"'; font-size:" + font.size + "pt;\">" +
selected + "</span>")
}
}
QtControls.Button {
width: parent.width / 12
width: parent.width / 15
iconName: "format-indent-more"
onClicked: {
if (debug) console.debug("Indent button")
var pos = textPattern.cursorPosition
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
textPattern.insert(pos, selected + "<br>\n")
textPattern.insert(textPattern.cursorPosition, selected + "<br>\n")
}
}
QtControls.Button {
width: parent.width / 12
width: parent.width / 15
iconName: "format-text-bold"
onClicked: {
if (debug) console.debug("Bold button")
var pos = textPattern.cursorPosition
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
textPattern.insert(pos, "<b>" + selected + "</b>")
textPattern.insert(textPattern.cursorPosition, "<b>" + selected + "</b>")
}
}
QtControls.Button {
width: parent.width / 12
width: parent.width / 15
iconName: "format-text-italic"
onClicked: {
if (debug) console.debug("Italic button")
var pos = textPattern.cursorPosition
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
textPattern.insert(pos, "<i>" + selected + "</i>")
textPattern.insert(textPattern.cursorPosition, "<i>" + selected + "</i>")
}
}
QtControls.Button {
width: parent.width / 12
width: parent.width / 15
iconName: "format-text-underline"
onClicked: {
if (debug) console.debug("Underline button")
var pos = textPattern.cursorPosition
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
textPattern.insert(pos, "<u>" + selected + "</u>")
textPattern.insert(textPattern.cursorPosition, "<u>" + selected + "</u>")
}
}
QtControls.Button {
width: parent.width / 12
width: parent.width / 15
iconName: "format-text-strikethrough"
onClicked: {
if (debug) console.debug("Strike button")
var pos = textPattern.cursorPosition
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
textPattern.insert(pos, "<s>" + selected + "</s>")
textPattern.insert(textPattern.cursorPosition, "<s>" + selected + "</s>")
}
}
QtControls.Button {
width: parent.width / 12
width: parent.width / 15
iconName: "format-justify-left"
onClicked: {
if (debug) console.debug("Left button")
var pos = textPattern.cursorPosition
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
textPattern.insert(pos, "<p align=\"left\">" + selected + "</p>")
textPattern.insert(textPattern.cursorPosition, "<p align=\"left\">" + selected + "</p>")
}
}
QtControls.Button {
width: parent.width / 12
width: parent.width / 15
iconName: "format-justify-center"
onClicked: {
if (debug) console.debug("Center button")
var pos = textPattern.cursorPosition
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
textPattern.insert(pos, "<p align=\"center\">" + selected + "</p>")
textPattern.insert(textPattern.cursorPosition, "<p align=\"center\">" + selected + "</p>")
}
}
QtControls.Button {
width: parent.width / 12
width: parent.width / 15
iconName: "format-justify-right"
onClicked: {
if (debug) console.debug("Right button")
var pos = textPattern.cursorPosition
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
textPattern.insert(pos, "<p align=\"right\">" + selected + "</p>")
textPattern.insert(textPattern.cursorPosition, "<p align=\"right\">" + selected + "</p>")
}
}
QtControls.Button {
width: parent.width / 12
width: parent.width / 15
iconName: "format-justify-fill"
onClicked: {
if (debug) console.debug("Justify button")
var pos = textPattern.cursorPosition
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
textPattern.insert(pos, "<p align=\"justify\">" + selected + "</p>")
textPattern.insert(textPattern.cursorPosition, "<p align=\"justify\">" + selected + "</p>")
}
}
}
@ -198,7 +211,7 @@ Item {
height: implicitHeight
width: parent.width
QtControls.ComboBox {
width: parent.width * 1 / 5
width: parent.width * 2 / 5
textRole: "label"
model: [
{
@ -252,11 +265,20 @@ Item {
{
'label': i18n("Weathers"),
'regexp': "^(weather(Id)?|humidity|pressure|temperature|timestamp)"
},
{
'label': i18n("Functions"),
'regexp': "functions"
}
]
onCurrentIndexChanged: {
if (debug) console.debug()
tags.model = awKeys.dictKeys(true, model[currentIndex]["regexp"])
if (model[currentIndex]["regexp"] == "functions")
tags.model = ["{{\n\n}}", "template{{\n\n}}",
"aw_all<>{{}}", "aw_count<>{{}}", "aw_keys<>{{}}",
"aw_names<>{{}}"]
else
tags.model = awKeys.dictKeys(true, model[currentIndex]["regexp"])
if (debug) console.info("Init model", tags.model, "for", model[currentIndex]["label"])
tags.currentIndex = -1
}
@ -272,10 +294,9 @@ Item {
onClicked: {
if (!tags.currentText) return
if (debug) console.debug("Add tag button")
var pos = textPattern.cursorPosition
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
textPattern.insert(pos, selected + "$" + tags.currentText)
textPattern.insert(textPattern.cursorPosition, selected + "$" + tags.currentText)
}
}
QtControls.Button {
@ -293,18 +314,6 @@ Item {
awActions.sendNotification("tag", message)
}
}
QtControls.Button {
width: parent.width * 1 / 5
text: i18n("Add lambda")
onClicked: {
if (debug) console.debug("Lambda button")
var pos = textPattern.cursorPosition
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
textPattern.insert(pos, selected + "${{\n\n}}")
}
}
}
Row {
@ -321,8 +330,7 @@ Item {
onClicked: {
lock = false
awKeys.initKeys(textPattern.text, plasmoid.configuration.interval,
plasmoid.configuration.queueLimit)
awKeys.needToBeUpdated()
plasmoid.configuration.queueLimit, false)
}
}
}
@ -349,7 +357,7 @@ Item {
awKeys.needTextToBeUpdated.connect(needTextUpdate)
// init submodule
awKeys.initKeys(plasmoid.configuration.text, plasmoid.configuration.interval,
plasmoid.configuration.queueLimit)
plasmoid.configuration.queueLimit, false)
awKeys.setAggregatorProperty("acOffline", plasmoid.configuration.acOffline)
awKeys.setAggregatorProperty("acOnline", plasmoid.configuration.acOnline)
awKeys.setAggregatorProperty("customTime", plasmoid.configuration.customTime)

View File

@ -20,8 +20,8 @@ X-Plasma-RemoteLocation=
X-KDE-PluginInfo-Author=Evgeniy Alekseev aka arcanis
X-KDE-PluginInfo-Email=esalexeev@gmail.com
X-KDE-PluginInfo-Name=org.kde.plasma.awesomewidget
X-KDE-PluginInfo-Version=3.0.1
X-KDE-PluginInfo-Website=http://arcanis.name/projects/awesome-widgets/
X-KDE-PluginInfo-Version=3.1.2
X-KDE-PluginInfo-Website=https://arcanis.me/projects/awesome-widgets/
X-KDE-PluginInfo-Category=System Information
X-KDE-PluginInfo-Depends=
X-KDE-PluginInfo-License=GPLv3

View File

@ -15,24 +15,23 @@
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#ifndef UPDATESOURCE_H
#define UPDATESOURCE_H
#ifndef AWABSTRACTFORMATTER_H
#define AWABSTRACTFORMATTER_H
#include <QObject>
#include "abstractextsysmonsource.h"
#include <QVariant>
class UpdateSource : public AbstractExtSysMonSource
class AWAbstractFormatter : public QObject
{
public:
explicit UpdateSource(QObject *parent, const QStringList args);
virtual ~UpdateSource();
QVariant data(QString source);
QVariantMap initialData(QString source) const;
void run(){};
QStringList sources() const;
explicit AWAbstractFormatter(QObject *parent, const QString, const QString)
: QObject(parent){};
explicit AWAbstractFormatter(QObject *parent)
: QObject(parent){};
virtual ~AWAbstractFormatter(){};
virtual QString convert(const QVariant &value) const = 0;
};
#endif /* UPDATESOURCE_H */
#endif /* AWABSTRACTFORMATTER_H */

View File

@ -21,32 +21,29 @@
#include <KNotifications/KNotification>
#include <QDesktopServices>
#include <QJsonDocument>
#include <QJsonParseError>
#include <QMessageBox>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QProcess>
#include <QProcessEnvironment>
#include <QStandardPaths>
#include <QUrl>
#include <fontdialog/fontdialog.h>
#include "awdebug.h"
#include "version.h"
#include "awupdatehelper.h"
AWActions::AWActions(QObject *parent)
: QObject(parent)
{
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
m_updateHelper = new AWUpdateHelper(this);
}
AWActions::~AWActions()
{
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
delete m_updateHelper;
}
@ -54,15 +51,8 @@ void AWActions::checkUpdates(const bool showAnyway)
{
qCDebug(LOG_AW) << "Show anyway" << showAnyway;
// showAnyway options requires to show message if no updates found on direct
// request. In case of automatic check no message will be shown
QNetworkAccessManager *manager = new QNetworkAccessManager(nullptr);
connect(manager, &QNetworkAccessManager::finished,
[showAnyway, this](QNetworkReply *reply) {
return versionReplyRecieved(reply, showAnyway);
});
manager->get(QNetworkRequest(QUrl(VERSION_API)));
if (!m_updateHelper->checkVersion())
m_updateHelper->checkUpdates(showAnyway);
}
@ -86,7 +76,7 @@ bool AWActions::runCmd(const QString cmd) const
// HACK: this method uses variable from version.h
void AWActions::showReadme() const
{
QDesktopServices::openUrl(QString(HOMEPAGE));
QDesktopServices::openUrl(QUrl(HOMEPAGE));
}
@ -144,6 +134,14 @@ QString AWActions::getAboutText(const QString type) const
.arg(trdPartyList.at(i).split(QChar(','))[1])
.arg(trdPartyList.at(i).split(QChar(','))[2]);
text = i18n("This software uses: %1", trdPartyList.join(QString(", ")));
} else if (type == QString("thanks")) {
QStringList thanks = QString(SPECIAL_THANKS)
.split(QChar(';'), QString::SkipEmptyParts);
for (int i = 0; i < thanks.count(); i++)
thanks[i] = QString("<a href=\"%2\">%1</a>")
.arg(thanks.at(i).split(QChar(','))[0])
.arg(thanks.at(i).split(QChar(','))[1]);
text = i18n("Special thanks to %1", thanks.join(QString(", ")));
}
return text;
@ -155,11 +153,14 @@ QVariantMap AWActions::getFont(const QVariantMap defaultFont) const
qCDebug(LOG_AW) << "Default font is" << defaultFont;
QVariantMap fontMap;
int ret = 0;
CFont defaultCFont = CFont(defaultFont[QString("family")].toString(),
defaultFont[QString("size")].toInt(), 400, false,
defaultFont[QString("color")].toString());
CFont font
= CFontDialog::getFont(i18n("Select font"), defaultCFont, false, false);
CFont font = CFontDialog::getFont(i18n("Select font"), defaultCFont, false,
false, &ret);
fontMap[QString("applied")] = ret;
fontMap[QString("color")] = font.color().name();
fontMap[QString("family")] = font.family();
fontMap[QString("size")] = font.pointSize();
@ -171,87 +172,10 @@ QVariantMap AWActions::getFont(const QVariantMap defaultFont) const
// to avoid additional object definition this method is static
void AWActions::sendNotification(const QString eventId, const QString message)
{
qCDebug(LOG_AW) << "Event" << eventId;
qCDebug(LOG_AW) << "Message" << message;
qCDebug(LOG_AW) << "Event" << eventId << "with message" << message;
KNotification *notification = KNotification::event(
eventId, QString("Awesome Widget ::: %1").arg(eventId), message);
notification->setComponentName(
QString("plasma-applet-org.kde.plasma.awesome-widget"));
}
void AWActions::showInfo(const QString version) const
{
qCDebug(LOG_AW) << "Version" << version;
QString text = i18n("You are using the actual version %1", version);
if (!QString(COMMIT_SHA).isEmpty())
text += QString(" (%1)").arg(QString(COMMIT_SHA));
QMessageBox::information(nullptr, i18n("No new version found"), text);
}
void AWActions::showUpdates(const QString version) const
{
qCDebug(LOG_AW) << "Version" << version;
QString text;
text += i18n("Current version : %1", QString(VERSION));
text += QString(COMMIT_SHA).isEmpty()
? QString("\n")
: QString(" (%1)\n").arg(QString(COMMIT_SHA));
text += i18n("New version : %1", version) + QString("\n\n");
text += i18n("Click \"Ok\" to download");
int select
= QMessageBox::information(nullptr, i18n("There are updates"), text,
QMessageBox::Ok | QMessageBox::Cancel);
switch (select) {
case QMessageBox::Ok:
QDesktopServices::openUrl(QString(RELEASES) + version);
break;
case QMessageBox::Cancel:
default:
break;
}
}
void AWActions::versionReplyRecieved(QNetworkReply *reply,
const bool showAnyway) const
{
qCDebug(LOG_AW) << "Return code" << reply->error();
qCDebug(LOG_AW) << "Reply error message" << reply->errorString();
qCDebug(LOG_AW) << "Show anyway" << showAnyway;
QJsonParseError error;
QJsonDocument jsonDoc = QJsonDocument::fromJson(reply->readAll(), &error);
reply->deleteLater();
if ((reply->error() != QNetworkReply::NoError)
|| (error.error != QJsonParseError::NoError)) {
qCWarning(LOG_AW) << "Parse error" << error.errorString();
return;
}
// convert to map
QVariantMap firstRelease = jsonDoc.toVariant().toList().first().toMap();
QString version = firstRelease[QString("tag_name")].toString();
version.remove(QString("V."));
qCInfo(LOG_AW) << "Found version" << version;
// FIXME: possible there is a better way to check versions
int old_major = QString(VERSION).split(QChar('.')).at(0).toInt();
int old_minor = QString(VERSION).split(QChar('.')).at(1).toInt();
int old_patch = QString(VERSION).split(QChar('.')).at(2).toInt();
int new_major = QString(version).split(QChar('.')).at(0).toInt();
int new_minor = QString(version).split(QChar('.')).at(1).toInt();
int new_patch = QString(version).split(QChar('.')).at(2).toInt();
if ((old_major < new_major)
|| ((old_major == new_major) && (old_minor < new_minor))
|| ((old_major == new_major) && (old_minor == new_minor)
&& (old_patch < new_patch)))
return showUpdates(version);
else if (showAnyway)
return showInfo(version);
}

View File

@ -22,7 +22,7 @@
#include <QObject>
class QNetworkReply;
class AWUpdateHelper;
class AWActions : public QObject
{
@ -44,11 +44,8 @@ public slots:
Q_INVOKABLE static void sendNotification(const QString eventId,
const QString message);
private slots:
void showInfo(const QString version) const;
void showUpdates(const QString version) const;
void versionReplyRecieved(QNetworkReply *reply,
const bool showAnyway) const;
private:
AWUpdateHelper *m_updateHelper = nullptr;
};

View File

@ -40,6 +40,25 @@ AWConfigHelper::~AWConfigHelper()
}
QString AWConfigHelper::configurationDirectory() const
{
// get readable directory
QString localDir = QString("%1/awesomewidgets/configs")
.arg(QStandardPaths::writableLocation(
QStandardPaths::GenericDataLocation));
// create directory and copy files from default settings
QDir localDirectory;
if ((!localDirectory.exists(localDir))
&& (localDirectory.mkpath(localDir))) {
qCInfo(LOG_AW) << "Created directory" << localDir;
copyConfigs(localDir);
}
return localDir;
}
bool AWConfigHelper::dropCache() const
{
QString fileName = QString("%1/awesomewidgets.ndx")
@ -61,7 +80,7 @@ bool AWConfigHelper::exportConfiguration(QObject *nativeConfig,
QQmlPropertyMap *configuration
= static_cast<QQmlPropertyMap *>(nativeConfig);
settings.beginGroup(QString("plasmoid"));
foreach (QString key, configuration->keys()) {
for (auto key : configuration->keys()) {
QVariant value = configuration->value(key);
if (!value.isValid())
continue;
@ -70,13 +89,13 @@ bool AWConfigHelper::exportConfiguration(QObject *nativeConfig,
settings.endGroup();
// extensions
foreach (QString item, m_dirs) {
for (auto item : m_dirs) {
QStringList items
= QDir(QString("%1/%2").arg(m_baseDir).arg(item))
.entryList(QStringList() << QString("*.desktop"),
QDir::Files);
settings.beginGroup(item);
foreach (QString it, items)
for (auto it : items)
copyExtensions(it, item, settings, false);
settings.endGroup();
}
@ -112,9 +131,9 @@ QVariantMap AWConfigHelper::importConfiguration(const QString fileName,
// extensions
if (importExtensions) {
foreach (QString item, m_dirs) {
for (auto item : m_dirs) {
settings.beginGroup(item);
foreach (QString it, settings.childGroups())
for (auto it : settings.childGroups())
copyExtensions(it, item, settings, true);
settings.endGroup();
}
@ -137,7 +156,7 @@ QVariantMap AWConfigHelper::importConfiguration(const QString fileName,
// plasmoid configuration
if (importPlasmoid) {
settings.beginGroup(QString("plasmoid"));
foreach (QString key, settings.childKeys())
for (auto key : settings.childKeys())
configuration[key] = settings.value(key);
settings.endGroup();
}
@ -212,13 +231,34 @@ void AWConfigHelper::writeDataEngineConfiguration(
}
void AWConfigHelper::copyConfigs(const QString localDir) const
{
qCDebug(LOG_AW) << "Local directory" << localDir;
QStringList dirs = QStandardPaths::locateAll(
QStandardPaths::GenericDataLocation, QString("awesomewidgets/configs"),
QStandardPaths::LocateDirectory);
for (auto dir : dirs) {
if (dir == localDir)
continue;
QStringList files = QDir(dir).entryList(QDir::Files);
for (auto source : files) {
QString destination = QString("%1/%2").arg(localDir).arg(source);
bool status = QFile::copy(QString("%1/%2").arg(dir).arg(source),
destination);
qCInfo(LOG_AW) << "File" << source << "has been copied to"
<< destination << "with status" << status;
}
}
}
void AWConfigHelper::copyExtensions(const QString item, const QString type,
QSettings &settings,
const bool inverse) const
{
qCDebug(LOG_AW) << "Extension" << item;
qCDebug(LOG_AW) << "Type" << type;
qCDebug(LOG_AW) << "Inverse" << inverse;
qCDebug(LOG_AW) << "Extension" << item << "has type" << type
<< "inverse copying" << inverse;
settings.beginGroup(item);
QSettings itemSettings(
@ -239,7 +279,7 @@ void AWConfigHelper::copyExtensions(const QString item, const QString type,
void AWConfigHelper::copySettings(QSettings &from, QSettings &to) const
{
foreach (QString key, from.childKeys())
for (auto key : from.childKeys())
to.setValue(key, from.value(key));
}
@ -247,8 +287,7 @@ void AWConfigHelper::copySettings(QSettings &from, QSettings &to) const
void AWConfigHelper::readFile(QSettings &settings, const QString key,
const QString fileName) const
{
qCDebug(LOG_AW) << "Key" << key;
qCDebug(LOG_AW) << "File" << fileName;
qCDebug(LOG_AW) << "Key" << key << "from file" << fileName;
QFile file(fileName);
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
@ -264,8 +303,7 @@ void AWConfigHelper::readFile(QSettings &settings, const QString key,
void AWConfigHelper::writeFile(QSettings &settings, const QString key,
const QString fileName) const
{
qCDebug(LOG_AW) << "Key" << key;
qCDebug(LOG_AW) << "File" << fileName;
qCDebug(LOG_AW) << "Key" << key << "to file" << fileName;
if (!settings.contains(key))
return;

View File

@ -32,6 +32,7 @@ class AWConfigHelper : public QObject
public:
explicit AWConfigHelper(QObject *parent = nullptr);
virtual ~AWConfigHelper();
Q_INVOKABLE QString configurationDirectory() const;
Q_INVOKABLE bool dropCache() const;
Q_INVOKABLE bool exportConfiguration(QObject *nativeConfig,
const QString fileName) const;
@ -46,6 +47,7 @@ public:
private:
// methods
void copyConfigs(const QString localDir) const;
void copyExtensions(const QString item, const QString type,
QSettings &settings, const bool inverse) const;
void copySettings(QSettings &from, QSettings &to) const;

View File

@ -25,7 +25,7 @@
#include <QGraphicsView>
#include <QPixmap>
#include <math.h>
#include <cmath>
#include "awactions.h"
#include "awdebug.h"
@ -35,12 +35,18 @@ AWDataAggregator::AWDataAggregator(QObject *parent)
: QObject(parent)
{
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
// required by signals
qRegisterMetaType<QHash<QString, QString>>("QHash<QString, QString>");
boundaries[QString("cpuTooltip")] = 100.0;
boundaries[QString("cpuclTooltip")] = 4000.0;
boundaries[QString("memTooltip")] = 100.0;
boundaries[QString("swapTooltip")] = 100.0;
boundaries[QString("downkbTooltip")] = 1.0;
boundaries[QString("upkbTooltip")] = 1.0;
boundaries[QString("batTooltip")] = 100.0;
initScene();
connect(this, SIGNAL(updateData(const QHash<QString, QString> &)), this,
SLOT(dataUpdate(const QHash<QString, QString> &)));
connect(this, SIGNAL(updateData(const QVariantHash &)), this,
SLOT(dataUpdate(const QVariantHash &)));
}
@ -87,18 +93,10 @@ void AWDataAggregator::setParameters(QVariantMap settings)
counts += configuration[QString("cpuclTooltip")].toInt();
counts += configuration[QString("memTooltip")].toInt();
counts += configuration[QString("swapTooltip")].toInt();
counts += configuration[QString("downTooltip")].toInt();
counts += configuration[QString("downkbTooltip")].toInt();
counts += configuration[QString("batTooltip")].toInt();
// resize tooltip image
toolTipView->resize(100.0 * counts, 105.0);
boundaries[QString("cpuTooltip")] = 100.0;
boundaries[QString("cpuclTooltip")] = 4000.0;
boundaries[QString("memTooltip")] = 100.0;
boundaries[QString("swapTooltip")] = 100.0;
boundaries[QString("downTooltip")] = 1.0;
boundaries[QString("upTooltip")] = 1.0;
boundaries[QString("batTooltip")] = 100.0;
toolTipView->resize(100 * counts, 105);
requiredKeys.clear();
if (configuration[QString("cpuTooltip")].toBool())
@ -109,10 +107,10 @@ void AWDataAggregator::setParameters(QVariantMap settings)
requiredKeys.append(QString("memTooltip"));
if (configuration[QString("swapTooltip")].toBool())
requiredKeys.append(QString("swapTooltip"));
if (configuration[QString("downTooltip")].toBool())
requiredKeys.append(QString("downTooltip"));
if (configuration[QString("upTooltip")].toBool())
requiredKeys.append(QString("upTooltip"));
if (configuration[QString("downkbTooltip")].toBool())
requiredKeys.append(QString("downkbTooltip"));
if (configuration[QString("upkbTooltip")].toBool())
requiredKeys.append(QString("upkbTooltip"));
if (configuration[QString("batTooltip")].toBool())
requiredKeys.append(QString("batTooltip"));
@ -131,11 +129,11 @@ QPixmap AWDataAggregator::tooltipImage()
toolTipScene->clear();
QPen pen;
bool down = false;
foreach (QString key, requiredKeys) {
for (auto key : requiredKeys) {
// create frame
float normX = 100.0 / static_cast<float>(data[key].count());
float normY = 100.0 / (1.5 * boundaries[key]);
float shift = requiredKeys.indexOf(key) * 100.0;
float normX = 100.0f / static_cast<float>(data[key].count());
float normY = 100.0f / (1.5f * boundaries[key]);
float shift = requiredKeys.indexOf(key) * 100.0f;
if (down)
shift -= 100.0;
// apply pen color
@ -146,9 +144,9 @@ QPixmap AWDataAggregator::tooltipImage()
for (int j = 0; j < data[key].count() - 1; j++) {
// some magic here
float x1 = j * normX + shift;
float y1 = -fabs(data[key].at(j)) * normY + 5.0;
float y1 = -fabs(data[key].at(j)) * normY + 5.0f;
float x2 = (j + 1) * normX + shift;
float y2 = -fabs(data[key].at(j + 1)) * normY + 5.0;
float y2 = -fabs(data[key].at(j + 1)) * normY + 5.0f;
if (key == QString("batTooltip")) {
if (data[key].at(j + 1) > 0)
pen.setColor(QColor(
@ -160,7 +158,7 @@ QPixmap AWDataAggregator::tooltipImage()
}
toolTipScene->addLine(x1, y1, x2, y2, pen);
}
if (key == QString("downTooltip"))
if (key == QString("downkbTooltip"))
down = true;
}
@ -168,7 +166,7 @@ QPixmap AWDataAggregator::tooltipImage()
}
void AWDataAggregator::dataUpdate(const QHash<QString, QString> &values)
void AWDataAggregator::dataUpdate(const QVariantHash &values)
{
// do not log these arguments
setData(values);
@ -179,9 +177,8 @@ void AWDataAggregator::dataUpdate(const QHash<QString, QString> &values)
void AWDataAggregator::checkValue(const QString source, const float value,
const float extremum) const
{
qCDebug(LOG_AW) << "Notification source" << source;
qCDebug(LOG_AW) << "Value" << value;
qCDebug(LOG_AW) << "Called with extremum" << extremum;
qCDebug(LOG_AW) << "Notification source" << source << "with value" << value
<< "called with extremum" << extremum;
if (value >= 0.0) {
if ((m_enablePopup) && (value > extremum)
@ -200,9 +197,8 @@ void AWDataAggregator::checkValue(const QString source, const float value,
void AWDataAggregator::checkValue(const QString source, const QString current,
const QString received) const
{
qCDebug(LOG_AW) << "Notification source" << source;
qCDebug(LOG_AW) << "Current value" << current;
qCDebug(LOG_AW) << "Received value" << received;
qCDebug(LOG_AW) << "Notification source" << source << "with current value"
<< current << "and received one" << received;
if ((m_enablePopup) && (current != received) && (!received.isEmpty()))
return AWActions::sendNotification(QString("event"),
@ -225,8 +221,7 @@ void AWDataAggregator::initScene()
QString AWDataAggregator::notificationText(const QString source,
const float value) const
{
qCDebug(LOG_AW) << "Notification source" << source;
qCDebug(LOG_AW) << "Value" << value;
qCDebug(LOG_AW) << "Notification source" << source << "with value" << value;
QString output;
if (source == QString("batTooltip"))
@ -247,8 +242,7 @@ QString AWDataAggregator::notificationText(const QString source,
QString AWDataAggregator::notificationText(const QString source,
const QString value) const
{
qCDebug(LOG_AW) << "Notification source" << source;
qCDebug(LOG_AW) << "Value" << value;
qCDebug(LOG_AW) << "Notification source" << source << "with value" << value;
QString output;
if (source == QString("netdev"))
@ -258,24 +252,25 @@ QString AWDataAggregator::notificationText(const QString source,
}
void AWDataAggregator::setData(const QHash<QString, QString> &values)
void AWDataAggregator::setData(const QVariantHash &values)
{
// do not log these arguments
// battery update requires info is AC online or not
setData(values[QString("ac")] == configuration[QString("acOnline")],
setData(values[QString("ac")].toString()
== configuration[QString("acOnline")],
QString("batTooltip"), values[QString("bat")].toFloat());
// usual case
setData(QString("cpuTooltip"), values[QString("cpu")].toFloat(), 90.0);
setData(QString("cpuclTooltip"), values[QString("cpucl")].toFloat());
setData(QString("memTooltip"), values[QString("mem")].toFloat(), 90.0);
setData(QString("memTooltip"), values[QString("mem")].toFloat(), 80.0);
setData(QString("swapTooltip"), values[QString("swap")].toFloat(), 0.0);
setData(QString("downTooltip"), values[QString("downkb")].toFloat());
setData(QString("upTooltip"), values[QString("upkb")].toFloat());
setData(QString("downkbTooltip"), values[QString("downkb")].toFloat());
setData(QString("upkbTooltip"), values[QString("upkb")].toFloat());
// additional check for network device
[this](const QString value) {
checkValue(QString("netdev"), currentNetworkDevice, value);
currentNetworkDevice = value;
}(values[QString("netdev")]);
}(values[QString("netdev")].toString());
// additional check for GPU load
[this](const float value) {
checkValue(QString("gpu"), value, 90.0);
@ -287,28 +282,30 @@ void AWDataAggregator::setData(const QHash<QString, QString> &values)
void AWDataAggregator::setData(const QString &source, float value,
const float extremum)
{
qCDebug(LOG_AW) << "Source" << source;
qCDebug(LOG_AW) << "Value" << value;
qCDebug(LOG_AW) << "Called with extremum" << extremum;
qCDebug(LOG_AW) << "Source" << source << "to value" << value
<< "with extremum" << extremum;
if (data[source].count() == 0)
data[source].append(0.0);
else if (data[source].count()
> configuration[QString("tooltipNumber")].toInt())
data[source].removeFirst();
if (isnan(value))
if (std::isnan(value))
value = 0.0;
// notifications
checkValue(source, value, extremum);
data[source].append(value);
if (source == QString("downTooltip")) {
if (source == QString("downkbTooltip")) {
QList<float> netValues
= data[QString("downTooltip")] + data[QString("upTooltip")];
boundaries[QString("downTooltip")]
= 1.2 * *std::max_element(netValues.cbegin(), netValues.cend());
boundaries[QString("upTooltip")] = boundaries[QString("downTooltip")];
= data[QString("downkbTooltip")] + data[QString("upkbTooltip")];
// to avoid inf value of normY
netValues << 1.0;
boundaries[QString("downkbTooltip")]
= 1.2f * *std::max_element(netValues.cbegin(), netValues.cend());
boundaries[QString("upkbTooltip")]
= boundaries[QString("downkbTooltip")];
}
}
@ -316,9 +313,8 @@ void AWDataAggregator::setData(const QString &source, float value,
void AWDataAggregator::setData(const bool dontInvert, const QString &source,
float value)
{
qCDebug(LOG_AW) << "Do not invert value" << dontInvert;
qCDebug(LOG_AW) << "Source" << source;
qCDebug(LOG_AW) << "Value" << value;
qCDebug(LOG_AW) << "Do not invert" << dontInvert << "value" << value
<< "for source" << source;
// invert values for different battery colours
value = dontInvert ? value : -value;

View File

@ -41,11 +41,11 @@ public:
QPixmap tooltipImage();
signals:
void updateData(const QHash<QString, QString> &values);
void updateData(const QVariantHash &values);
void toolTipPainted(const QString image) const;
public slots:
void dataUpdate(const QHash<QString, QString> &values);
private slots:
void dataUpdate(const QVariantHash &values);
private:
// ui
@ -59,9 +59,9 @@ private:
QString notificationText(const QString source, const float value) const;
QString notificationText(const QString source, const QString value) const;
// main method
void setData(const QHash<QString, QString> &values);
void setData(const QVariantHash &values);
void setData(const QString &source, float value,
const float extremum = -1.0);
const float extremum = -1.0f);
// different signature for battery device
void setData(const bool dontInvert, const QString &source, float value);
// variables

View File

@ -17,20 +17,14 @@
#include "awdataengineaggregator.h"
#include <Plasma/DataEngineConsumer>
#include "awdebug.h"
#include "awkeys.h"
AWDataEngineAggregator::AWDataEngineAggregator(QObject *parent,
const int interval)
AWDataEngineAggregator::AWDataEngineAggregator(QObject *parent)
: QObject(parent)
{
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
setInterval(interval);
initDataEngines();
}
@ -38,25 +32,49 @@ AWDataEngineAggregator::~AWDataEngineAggregator()
{
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
clear();
}
void AWDataEngineAggregator::clear()
{
// disconnect sources first
disconnectSources();
m_dataEngines.clear();
delete m_consumer;
m_consumer = nullptr;
}
void AWDataEngineAggregator::disconnectSources()
{
foreach (QString dataengine, m_dataEngines.keys())
foreach (QString source, m_dataEngines[dataengine]->sources())
m_dataEngines[dataengine]->disconnectSource(source, parent());
for (auto dataengine : m_dataEngines.values())
for (auto source : dataengine->sources())
dataengine->disconnectSource(source, parent());
}
void AWDataEngineAggregator::setInterval(const int _interval)
void AWDataEngineAggregator::initDataEngines(const int interval)
{
qCDebug(LOG_AW) << "Interval" << _interval;
qCDebug(LOG_AW) << "Init dataengines with interval" << interval;
m_interval = _interval;
m_consumer = new Plasma::DataEngineConsumer();
m_dataEngines[QString("systemmonitor")]
= m_consumer->dataEngine(QString("systemmonitor"));
m_dataEngines[QString("extsysmon")]
= m_consumer->dataEngine(QString("extsysmon"));
m_dataEngines[QString("time")] = m_consumer->dataEngine(QString("time"));
// additional method required by systemmonitor structure
connect(m_dataEngines[QString("systemmonitor")],
&Plasma::DataEngine::sourceAdded,
[this, interval](const QString source) {
emit(deviceAdded(source));
m_dataEngines[QString("systemmonitor")]->connectSource(
source, parent(), interval);
});
return reconnectSources(interval);
}
@ -68,34 +86,17 @@ void AWDataEngineAggregator::dropSource(const QString source)
// connected we will try to disconnect it from systemmonitor and extsysmon
m_dataEngines[QString("systemmonitor")]->disconnectSource(source, parent());
m_dataEngines[QString("extsysmon")]->disconnectSource(source, parent());
m_dataEngines[QString("time")]->disconnectSource(source, parent());
}
void AWDataEngineAggregator::reconnectSources()
void AWDataEngineAggregator::reconnectSources(const int interval)
{
qCDebug(LOG_AW) << "Reconnect sources with interval" << interval;
m_dataEngines[QString("systemmonitor")]->connectAllSources(parent(),
m_interval);
m_dataEngines[QString("extsysmon")]->connectAllSources(parent(),
m_interval);
interval);
m_dataEngines[QString("extsysmon")]->connectAllSources(parent(), interval);
m_dataEngines[QString("time")]->connectSource(QString("Local"), parent(),
1000);
}
void AWDataEngineAggregator::initDataEngines()
{
Plasma::DataEngineConsumer *deConsumer = new Plasma::DataEngineConsumer();
m_dataEngines[QString("systemmonitor")]
= deConsumer->dataEngine(QString("systemmonitor"));
m_dataEngines[QString("extsysmon")]
= deConsumer->dataEngine(QString("extsysmon"));
m_dataEngines[QString("time")] = deConsumer->dataEngine(QString("time"));
// additional method required by systemmonitor structure
connect(m_dataEngines[QString("systemmonitor")],
&Plasma::DataEngine::sourceAdded, [this](const QString source) {
static_cast<AWKeys *>(parent())->addDevice(source);
m_dataEngines[QString("systemmonitor")]->connectSource(
source, parent(), m_interval);
});
}

View File

@ -20,6 +20,7 @@
#define AWDATAENGINEAGGREGATOR_H
#include <Plasma/DataEngine>
#include <Plasma/DataEngineConsumer>
#include <QObject>
@ -27,24 +28,24 @@
class AWDataEngineAggregator : public QObject
{
Q_OBJECT
Q_PROPERTY(int interval MEMBER m_interval WRITE setInterval);
public:
explicit AWDataEngineAggregator(QObject *parent = nullptr,
const int interval = 1000);
explicit AWDataEngineAggregator(QObject *parent = nullptr);
virtual ~AWDataEngineAggregator();
void clear();
void disconnectSources();
// properties
void setInterval(const int _interval);
void initDataEngines(const int interval);
signals:
void deviceAdded(const QString &source);
public slots:
void dropSource(const QString source);
void reconnectSources();
void reconnectSources(const int interval);
private:
void initDataEngines();
Plasma::DataEngineConsumer *m_consumer = nullptr;
QHash<QString, Plasma::DataEngine *> m_dataEngines;
int m_interval;
};

View File

@ -0,0 +1,84 @@
/***************************************************************************
* 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();
}

View File

@ -0,0 +1,46 @@
/***************************************************************************
* 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 AWDATETIMEFORMATTER_H
#define AWDATETIMEFORMATTER_H
#include "awabstractformatter.h"
class AWDateTimeFormatter : public AWAbstractFormatter
{
Q_OBJECT
Q_PROPERTY(QString format READ format WRITE setFormat)
public:
explicit AWDateTimeFormatter(QObject *parent, const QString filename,
const QString section);
explicit AWDateTimeFormatter(QObject *parent, const QString format);
virtual ~AWDateTimeFormatter();
QString convert(const QVariant &value) const;
// properties
QString format() const;
void setFormat(const QString _format);
private:
void init(const QString filename, const QString section);
// properties
QString m_format;
};
#endif /* AWDATETIMEFORMATTER_H */

View File

@ -21,6 +21,7 @@
#include "awactions.h"
#include "awconfighelper.h"
#include "awdataengineaggregator.h"
#include "awkeys.h"

View File

@ -0,0 +1,176 @@
/***************************************************************************
* 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();
}

View File

@ -0,0 +1,69 @@
/***************************************************************************
* 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 AWFLOATFORMATTER_H
#define AWFLOATFORMATTER_H
#include "awabstractformatter.h"
class AWFloatFormatter : public AWAbstractFormatter
{
Q_OBJECT
Q_PROPERTY(QChar fillChar READ fillChar WRITE setFillChar)
Q_PROPERTY(char format READ format WRITE setFormat)
Q_PROPERTY(double multiplier READ multiplier WRITE setMultiplier)
Q_PROPERTY(int precision READ precision WRITE setPrecision)
Q_PROPERTY(double summand READ summand WRITE setSummand)
Q_PROPERTY(int width READ width WRITE setWidth)
public:
explicit AWFloatFormatter(QObject *parent, const QString filename,
const QString section);
explicit AWFloatFormatter(QObject *parent, const QChar fillChar,
const char format, const double multiplier,
const int precision, const double summand,
const int width);
virtual ~AWFloatFormatter();
QString convert(const QVariant &value) const;
// properties
QChar fillChar() const;
char format() const;
double multiplier() const;
int precision() const;
double summand() const;
int width() const;
void setFillChar(const QChar _fillChar);
void setFormat(char _format);
void setMultiplier(const double _multiplier);
void setPrecision(const int _precision);
void setSummand(const double _summand);
void setWidth(const int _width);
private:
void init(const QString filename, const QString section);
// properties
QChar m_fillChar;
char m_format;
double m_multiplier;
int m_precision;
double m_summand;
int m_width;
};
#endif /* AWFLOATFORMATTER_H */

View File

@ -0,0 +1,125 @@
/***************************************************************************
* 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 "awformatterhelper.h"
#include <QSettings>
#include <QStandardPaths>
#include "awdebug.h"
#include "awdatetimeformatter.h"
#include "awfloatformatter.h"
#include "awnoformatter.h"
#include "awscriptformatter.h"
AWFormatterHelper::AWFormatterHelper(QObject *parent)
: QObject(parent)
{
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
m_genericConfig = QString("%1/awesomewidgets/general.ini")
.arg(QStandardPaths::writableLocation(
QStandardPaths::GenericDataLocation));
#ifdef BUILD_FUTURE
init();
#endif /* BUILD_FUTURE */
}
AWFormatterHelper::~AWFormatterHelper()
{
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
m_formatters.clear();
}
QString AWFormatterHelper::convert(const QVariant &value,
const QString name) const
{
qCDebug(LOG_AW) << "Convert value" << value << "for" << name;
return m_formatters.contains(name) ? m_formatters[name]->convert(value)
: value.toString();
}
QStringList AWFormatterHelper::definedFormatters() const
{
return m_formatters.keys();
}
AWFormatterHelper::FormatterClass
AWFormatterHelper::defineFormatterClass(const QString name) const
{
qCDebug(LOG_AW) << "Define formatter class for" << name;
QSettings settings(m_genericConfig, QSettings::IniFormat);
settings.beginGroup(name);
QString stringType
= settings.value(QString("Type"), QString("NoFormat")).toString();
settings.endGroup();
FormatterClass formatter = FormatterClass::NoFormat;
if (stringType == QString("DateTime"))
formatter = FormatterClass::DateTime;
else if (stringType == QString("Float"))
formatter = FormatterClass::Float;
else if (stringType == QString("Script"))
formatter = FormatterClass::Script;
else
qCWarning(LOG_AW) << "Unknown formatter" << stringType;
return formatter;
}
void AWFormatterHelper::init()
{
QSettings settings(m_genericConfig, QSettings::IniFormat);
settings.beginGroup(QString("Formatters"));
QStringList keys = settings.childKeys();
for (auto key : keys) {
QString name = settings.value(key).toString();
FormatterClass formatter = defineFormatterClass(name);
qCInfo(LOG_AW) << "Found formatter" << name << "for key" << key
<< "defined as" << static_cast<int>(formatter);
switch (formatter) {
case FormatterClass::DateTime:
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;
}
}
settings.endGroup();
}

View 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 AWFORMATTERHELPER_H
#define AWFORMATTERHELPER_H
#include <QObject>
#include "awabstractformatter.h"
class AWFormatterHelper : public QObject
{
Q_OBJECT
public:
enum class FormatterClass { DateTime, Float, Script, NoFormat };
explicit AWFormatterHelper(QObject *parent = nullptr);
virtual ~AWFormatterHelper();
QString convert(const QVariant &value, const QString name) const;
QStringList definedFormatters() const;
private:
AWFormatterHelper::FormatterClass
defineFormatterClass(const QString name) const;
void init();
// properties
QString m_genericConfig;
QHash<QString, AWAbstractFormatter *> m_formatters;
};
#endif /* AWFORMATTERHELPER_H */

View File

@ -0,0 +1,186 @@
/***************************************************************************
* 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 "awkeycache.h"
#include <QDir>
#include <QNetworkInterface>
#include <QRegExp>
#include <QSettings>
#include <QStandardPaths>
#include "awdebug.h"
bool AWKeyCache::addKeyToCache(const QString type, const QString key)
{
qCDebug(LOG_AW) << "Key" << key << "with type" << type;
QString fileName = QString("%1/awesomewidgets.ndx")
.arg(QStandardPaths::writableLocation(
QStandardPaths::GenericCacheLocation));
qCInfo(LOG_AW) << "Cache file" << fileName;
QSettings cache(fileName, QSettings::IniFormat);
cache.beginGroup(type);
QStringList cachedValues;
for (auto key : cache.allKeys())
cachedValues.append(cache.value(key).toString());
if (type == QString("hdd")) {
QStringList allDevices
= QDir(QString("/dev")).entryList(QDir::System, QDir::Name);
QStringList devices
= allDevices.filter(QRegExp(QString("^[hms]d[a-z]$")));
for (auto dev : devices) {
QString device = QString("/dev/%1").arg(dev);
if (cachedValues.contains(device))
continue;
qCInfo(LOG_AW) << "Found new key" << device << "for type" << type;
cache.setValue(
QString("%1").arg(cache.allKeys().count(), 3, 10, QChar('0')),
device);
}
} else if (type == QString("net")) {
QList<QNetworkInterface> rawInterfaceList
= QNetworkInterface::allInterfaces();
for (auto interface : rawInterfaceList) {
QString device = interface.name();
if (cachedValues.contains(device))
continue;
qCInfo(LOG_AW) << "Found new key" << device << "for type" << type;
cache.setValue(
QString("%1").arg(cache.allKeys().count(), 3, 10, QChar('0')),
device);
}
} else {
if (cachedValues.contains(key))
return false;
qCInfo(LOG_AW) << "Found new key" << key << "for type" << type;
cache.setValue(
QString("%1").arg(cache.allKeys().count(), 3, 10, QChar('0')), key);
}
cache.endGroup();
cache.sync();
return true;
}
QStringList AWKeyCache::getRequiredKeys(const QStringList &keys,
const QStringList &bars,
const QVariantMap &tooltip,
const QStringList &allKeys)
{
qCDebug(LOG_AW) << "Looking for required keys in" << keys << bars
<< "using tooltip settings" << tooltip;
// initial copy
QSet<QString> used = QSet<QString>::fromList(keys);
used.unite(QSet<QString>::fromList(bars));
// insert keys from tooltip
for (auto key : tooltip.keys()) {
if ((key.endsWith(QString("Tooltip"))) && (tooltip[key].toBool())) {
key.remove(QString("Tooltip"));
used << key;
}
}
// insert depending keys, refer to AWKeys::calculateValues()
// hddtotmb*
for (auto key : allKeys.filter(QRegExp(QString("^hddtotmb")))) {
if (!used.contains(key))
continue;
key.remove(QString("hddtotmb"));
int index = key.toInt();
used << QString("hddfreemb%1").arg(index)
<< QString("hddmb%1").arg(index);
}
// hddtotgb*
for (auto key : allKeys.filter(QRegExp(QString("^hddtotgb")))) {
if (!used.contains(key))
continue;
key.remove(QString("hddtotgb"));
int index = key.toInt();
used << QString("hddfreegb%1").arg(index)
<< QString("hddgb%1").arg(index);
}
// mem
if (used.contains(QString("mem")))
used << QString("memmb") << QString("memtotmb");
// memtotmb
if (used.contains(QString("memtotmb")))
used << QString("memusedmb") << QString("memfreemb");
// memtotgb
if (used.contains(QString("memtotgb")))
used << QString("memusedgb") << QString("memfreegb");
// swap
if (used.contains(QString("swap")))
used << QString("swapmb") << QString("swaptotmb");
// swaptotmb
if (used.contains(QString("swaptotmb")))
used << QString("swapmb") << QString("swapfreemb");
// memtotgb
if (used.contains(QString("swaptotgb")))
used << QString("swapgb") << QString("swapfreegb");
// network keys
QStringList netKeys(QStringList()
<< QString("up") << QString("upkb")
<< QString("uptotal") << QString("uptotalkb")
<< QString("upunits") << QString("down")
<< QString("downkb") << QString("downtotal")
<< QString("downtotalkb") << QString("downunits"));
for (auto key : netKeys) {
if (!used.contains(key))
continue;
QStringList filt
= allKeys.filter(QRegExp(QString("^%1[0-9]{1,}").arg(key)));
for (auto filtered : filt)
used << filtered;
}
// netdev key
if (std::any_of(netKeys.cbegin(), netKeys.cend(),
[&used](const QString &key) { return used.contains(key); }))
used << QString("netdev");
// HACK append dummy if there are no other keys. This hack is required
// because empty list leads to the same behaviour as skip checking
if (used.isEmpty())
used << QString("dummy");
return used.toList();
}
QHash<QString, QStringList> AWKeyCache::loadKeysFromCache()
{
QString fileName = QString("%1/awesomewidgets.ndx")
.arg(QStandardPaths::writableLocation(
QStandardPaths::GenericCacheLocation));
qCInfo(LOG_AW) << "Cache file" << fileName;
QSettings cache(fileName, QSettings::IniFormat);
QHash<QString, QStringList> devices;
for (auto group : cache.childGroups()) {
cache.beginGroup(group);
for (auto key : cache.allKeys())
devices[group].append(cache.value(key).toString());
cache.endGroup();
}
return devices;
}

View File

@ -0,0 +1,37 @@
/***************************************************************************
* 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 AWKEYCACHE_H
#define AWKEYCACHE_H
#include <QHash>
#include <QString>
#include <QVariant>
namespace AWKeyCache
{
bool addKeyToCache(const QString type, const QString key = QString(""));
QStringList getRequiredKeys(const QStringList &keys, const QStringList &bars,
const QVariantMap &tooltip,
const QStringList &allKeys);
QHash<QString, QStringList> loadKeysFromCache();
};
#endif /* AWKEYCACHE_H */

View File

@ -0,0 +1,330 @@
/***************************************************************************
* 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 "awkeyoperations.h"
#include <QDir>
#include <QJSEngine>
#include <QRegExp>
#include <QThread>
#include "awdebug.h"
#include "awkeycache.h"
#include "awpatternfunctions.h"
// extensions
#include "extquotes.h"
#include "extscript.h"
#include "extupgrade.h"
#include "extweather.h"
#include "graphicalitem.h"
AWKeyOperations::AWKeyOperations(QObject *parent)
: QObject(parent)
{
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
}
AWKeyOperations::~AWKeyOperations()
{
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
// extensions
delete graphicalItems;
delete extQuotes;
delete extScripts;
delete extUpgrade;
delete extWeather;
}
QStringList AWKeyOperations::devices(const QString type) const
{
qCDebug(LOG_AW) << "Looking for type" << type;
return m_devices[type];
}
QHash<QString, QStringList> AWKeyOperations::devices() const
{
return m_devices;
}
void AWKeyOperations::updateCache()
{
// update network and hdd list
addKeyToCache(QString("hdd"));
addKeyToCache(QString("net"));
}
QStringList AWKeyOperations::dictKeys() const
{
QStringList allKeys;
// weather
for (int i = extWeather->activeItems().count() - 1; i >= 0; i--) {
allKeys.append(
extWeather->activeItems().at(i)->tag(QString("weatherId")));
allKeys.append(
extWeather->activeItems().at(i)->tag(QString("weather")));
allKeys.append(
extWeather->activeItems().at(i)->tag(QString("humidity")));
allKeys.append(
extWeather->activeItems().at(i)->tag(QString("pressure")));
allKeys.append(
extWeather->activeItems().at(i)->tag(QString("temperature")));
allKeys.append(
extWeather->activeItems().at(i)->tag(QString("timestamp")));
}
// cpuclock & cpu
for (int i = QThread::idealThreadCount() - 1; i >= 0; i--) {
allKeys.append(QString("cpucl%1").arg(i));
allKeys.append(QString("cpu%1").arg(i));
}
// temperature
for (int i = m_devices[QString("temp")].count() - 1; i >= 0; i--)
allKeys.append(QString("temp%1").arg(i));
// hdd
for (int i = m_devices[QString("mount")].count() - 1; i >= 0; i--) {
allKeys.append(QString("hddmb%1").arg(i));
allKeys.append(QString("hddgb%1").arg(i));
allKeys.append(QString("hddfreemb%1").arg(i));
allKeys.append(QString("hddfreegb%1").arg(i));
allKeys.append(QString("hddtotmb%1").arg(i));
allKeys.append(QString("hddtotgb%1").arg(i));
allKeys.append(QString("hdd%1").arg(i));
}
// hdd speed
for (int i = m_devices[QString("disk")].count() - 1; i >= 0; i--) {
allKeys.append(QString("hddr%1").arg(i));
allKeys.append(QString("hddw%1").arg(i));
}
// hdd temp
for (int i = m_devices[QString("hdd")].count() - 1; i >= 0; i--)
allKeys.append(QString("hddtemp%1").arg(i));
// network
for (int i = m_devices[QString("net")].count() - 1; i >= 0; i--) {
allKeys.append(QString("downunits%1").arg(i));
allKeys.append(QString("upunits%1").arg(i));
allKeys.append(QString("downtotalkb%1").arg(i));
allKeys.append(QString("downtotal%1").arg(i));
allKeys.append(QString("downkb%1").arg(i));
allKeys.append(QString("down%1").arg(i));
allKeys.append(QString("uptotalkb%1").arg(i));
allKeys.append(QString("uptotal%1").arg(i));
allKeys.append(QString("upkb%1").arg(i));
allKeys.append(QString("up%1").arg(i));
}
// battery
QStringList allBatteryDevices
= QDir(QString("/sys/class/power_supply"))
.entryList(QStringList() << QString("BAT*"),
QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name);
for (int i = allBatteryDevices.count() - 1; i >= 0; i--)
allKeys.append(QString("bat%1").arg(i));
// package manager
for (int i = extUpgrade->activeItems().count() - 1; i >= 0; i--)
allKeys.append(
extUpgrade->activeItems().at(i)->tag(QString("pkgcount")));
// quotes
for (int i = extQuotes->activeItems().count() - 1; i >= 0; i--) {
allKeys.append(extQuotes->activeItems().at(i)->tag(QString("ask")));
allKeys.append(extQuotes->activeItems().at(i)->tag(QString("askchg")));
allKeys.append(
extQuotes->activeItems().at(i)->tag(QString("percaskchg")));
allKeys.append(extQuotes->activeItems().at(i)->tag(QString("bid")));
allKeys.append(extQuotes->activeItems().at(i)->tag(QString("bidchg")));
allKeys.append(
extQuotes->activeItems().at(i)->tag(QString("percbidchg")));
allKeys.append(extQuotes->activeItems().at(i)->tag(QString("price")));
allKeys.append(
extQuotes->activeItems().at(i)->tag(QString("pricechg")));
allKeys.append(
extQuotes->activeItems().at(i)->tag(QString("percpricechg")));
}
// custom
for (int i = extScripts->activeItems().count() - 1; i >= 0; i--)
allKeys.append(extScripts->activeItems().at(i)->tag(QString("custom")));
// bars
for (int i = graphicalItems->activeItems().count() - 1; i >= 0; i--)
allKeys.append(
graphicalItems->activeItems().at(i)->tag(QString("bar")));
// static keys
QStringList staticKeys = QString(STATIC_KEYS).split(QChar(','));
std::for_each(staticKeys.cbegin(), staticKeys.cend(),
[&allKeys](const QString &key) { allKeys.append(key); });
return allKeys;
}
// this method is required to provide GraphicalItem functions (e.g. paint()) to
// parent classes
GraphicalItem *AWKeyOperations::giByKey(const QString key) const
{
qCDebug(LOG_AW) << "Looking for item" << key;
return graphicalItems->itemByTag(key, QString("bar"));
}
QString AWKeyOperations::infoByKey(QString key) const
{
qCDebug(LOG_AW) << "Requested key" << key;
if (key.startsWith(QString("bar")))
return graphicalItems->itemByTag(key, QString("bar"))->uniq();
else if (key.startsWith(QString("custom")))
return extScripts->itemByTag(key, QString("custom"))->uniq();
else if (key.contains(QRegExp(QString("^hdd[rw]"))))
return QString("%1").arg(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)"))))
return QString("%1").arg(m_devices[QString(
"mount")][key
.remove(QRegExp(QString(
"^hdd([0-9]|mb|gb|freemb|freegb|totmb|totgb)")))
.toInt()]);
else if (key.startsWith(QString("hddtemp")))
return QString("%1").arg(
m_devices[QString("hdd")][key.remove(QString("hddtemp")).toInt()]);
else if (key.contains(QRegExp(QString("^(down|up)[0-9]"))))
return QString("%1").arg(m_devices[QString(
"net")][key.remove(QRegExp(QString("^(down|up)"))).toInt()]);
else if (key.startsWith(QString("pkgcount")))
return extUpgrade->itemByTag(key, QString("pkgcount"))->uniq();
else if (key.contains(QRegExp(QString("(^|perc)(ask|bid|price)(chg|)"))))
return extQuotes->itemByTag(key, QString("ask"))->uniq();
else if (key.contains(QRegExp(
QString("(weather|weatherId|humidity|pressure|temperature)"))))
return extWeather->itemByTag(key, QString("weather"))->uniq();
else if (key.startsWith(QString("temp")))
return QString("%1").arg(
m_devices[QString("temp")][key.remove(QString("temp")).toInt()]);
return QString("(none)");
}
QString AWKeyOperations::pattern() const
{
return m_pattern;
}
void AWKeyOperations::setPattern(const QString currentPattern)
{
qCDebug(LOG_AW) << "Set pattern" << currentPattern;
m_pattern = currentPattern;
}
void AWKeyOperations::editItem(const QString type)
{
qCDebug(LOG_AW) << "Item type" << type;
if (type == QString("graphicalitem")) {
QStringList keys = dictKeys().filter(QRegExp(
QString("^(cpu(?!cl).*|gpu$|mem$|swap$|hdd[0-9].*|bat.*)")));
keys.sort();
graphicalItems->setConfigArgs(keys);
return graphicalItems->editItems();
} else if (type == QString("extquotes")) {
return extQuotes->editItems();
} else if (type == QString("extscript")) {
return extScripts->editItems();
} else if (type == QString("extupgrade")) {
return extUpgrade->editItems();
} else if (type == QString("extweather")) {
return extWeather->editItems();
}
}
void AWKeyOperations::addDevice(const QString &source)
{
qCDebug(LOG_AW) << "Source" << source;
QRegExp diskRegexp
= QRegExp(QString("disk/(?:md|sd|hd)[a-z|0-9]_.*/Rate/(?:rblk)"));
QRegExp mountRegexp = QRegExp(QString("partitions/.*/filllevel"));
if (source.contains(diskRegexp)) {
QString device = source;
device.remove(QString("/Rate/rblk"));
addKeyToCache(QString("disk"), device);
} else if (source.contains(mountRegexp)) {
QString device = source;
device.remove(QString("partitions")).remove(QString("/filllevel"));
addKeyToCache(QString("mount"), device);
} else if (source.startsWith(QString("lmsensors"))) {
addKeyToCache(QString("temp"), source);
}
}
void AWKeyOperations::addKeyToCache(const QString type, const QString key)
{
qCDebug(LOG_AW) << "Key" << key << "with type" << type;
if (AWKeyCache::addKeyToCache(type, key)) {
m_devices = AWKeyCache::loadKeysFromCache();
reinitKeys();
}
}
void AWKeyOperations::reinitKeys()
{
// renew extensions
// delete them if any
delete graphicalItems;
graphicalItems = nullptr;
delete extQuotes;
extQuotes = nullptr;
delete extScripts;
extScripts = nullptr;
delete extUpgrade;
extUpgrade = nullptr;
delete extWeather;
extWeather = nullptr;
// create
graphicalItems
= new ExtItemAggregator<GraphicalItem>(nullptr, QString("desktops"));
extQuotes = new ExtItemAggregator<ExtQuotes>(nullptr, QString("quotes"));
extScripts = new ExtItemAggregator<ExtScript>(nullptr, QString("scripts"));
extUpgrade = new ExtItemAggregator<ExtUpgrade>(nullptr, QString("upgrade"));
extWeather = new ExtItemAggregator<ExtWeather>(nullptr, QString("weather"));
// init
QStringList allKeys = dictKeys();
// apply aw_* functions
m_pattern = AWPatternFunctions::insertAllKeys(m_pattern, allKeys);
m_pattern = AWPatternFunctions::insertKeyCount(m_pattern, allKeys);
m_pattern = AWPatternFunctions::insertKeyNames(m_pattern, allKeys);
m_pattern = AWPatternFunctions::insertKeys(m_pattern, allKeys);
// wrap templates
m_pattern = AWPatternFunctions::expandTemplates(m_pattern);
emit(updateKeys(allKeys));
}

View File

@ -0,0 +1,83 @@
/***************************************************************************
* 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 AWKEYOPERATIONS_H
#define AWKEYOPERATIONS_H
#include <Plasma/DataEngine>
#include <QMutex>
#include <QObject>
#include "extitemaggregator.h"
class AWDataAggregator;
class AWDataEngineAggregator;
class AWKeysAggregator;
class ExtQuotes;
class ExtScript;
class ExtUpgrade;
class ExtWeather;
class GraphicalItem;
class QThreadPool;
class AWKeyOperations : public QObject
{
Q_OBJECT
Q_PROPERTY(QString pattern READ pattern WRITE setPattern)
public:
explicit AWKeyOperations(QObject *parent = nullptr);
virtual ~AWKeyOperations();
QStringList devices(const QString type) const;
QHash<QString, QStringList> devices() const;
void updateCache();
// keys
QStringList dictKeys() const;
GraphicalItem *giByKey(const QString key) const;
// values
QString infoByKey(QString key) const;
QString pattern() const;
void setPattern(const QString currentPattern);
// configuration
void editItem(const QString type);
signals:
void updateKeys(const QStringList currentKeys);
public slots:
void addDevice(const QString &source);
private:
// methods
void addKeyToCache(const QString type, const QString key = QString(""));
void reinitKeys();
// objects
ExtItemAggregator<GraphicalItem> *graphicalItems = nullptr;
ExtItemAggregator<ExtQuotes> *extQuotes = nullptr;
ExtItemAggregator<ExtScript> *extScripts = nullptr;
ExtItemAggregator<ExtUpgrade> *extUpgrade = nullptr;
ExtItemAggregator<ExtWeather> *extWeather = nullptr;
// variables
QHash<QString, QStringList> m_devices;
QString m_pattern;
};
#endif /* AWKEYOPERATIONS_H */

View File

@ -18,25 +18,19 @@
#include "awkeys.h"
#include <QtConcurrent/QtConcurrent>
#include <QDir>
#include <QInputDialog>
#include <QJSEngine>
#include <QNetworkInterface>
#include <QRegExp>
#include <QSettings>
#include <QStandardPaths>
#include <QThread>
#include <QTimer>
#include "awdataaggregator.h"
#include "awdataengineaggregator.h"
#include "awdebug.h"
#include "awkeycache.h"
#include "awkeyoperations.h"
#include "awkeysaggregator.h"
#include "extquotes.h"
#include "extscript.h"
#include "extupgrade.h"
#include "extweather.h"
#include "awpatternfunctions.h"
#include "graphicalitem.h"
#include "version.h"
AWKeys::AWKeys(QObject *parent)
@ -44,20 +38,32 @@ AWKeys::AWKeys(QObject *parent)
{
qSetMessagePattern(LOG_FORMAT);
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
foreach (const QString metadata, getBuildData())
for (auto metadata : getBuildData())
qCDebug(LOG_AW) << metadata;
#ifdef BUILD_FUTURE
// thread pool
m_threadPool = new QThreadPool(this);
#endif /* BUILD_FUTURE */
aggregator = new AWKeysAggregator(this);
dataAggregator = new AWDataAggregator(this);
dataEngineAggregator = new AWDataEngineAggregator(this);
keyOperator = new AWKeyOperations(this);
m_timer = new QTimer(this);
m_timer->setSingleShot(false);
// update key data if required
connect(keyOperator, SIGNAL(updateKeys(QStringList)), this,
SLOT(reinitKeys(QStringList)));
connect(m_timer, SIGNAL(timeout()), this, SLOT(updateTextData()));
// transfer signal from AWDataAggregator object to QML ui
connect(dataAggregator, SIGNAL(toolTipPainted(const QString)), this,
SIGNAL(needToolTipToBeUpdated(const QString)));
connect(this, SIGNAL(needToBeUpdated()), this, SLOT(updateTextData()));
connect(this, SIGNAL(dropSourceFromDataengine(QString)),
dataEngineAggregator, SLOT(dropSource(QString)));
// transfer signal from dataengine to update source list
connect(dataEngineAggregator, SIGNAL(deviceAdded(const QString &)),
keyOperator, SLOT(addDevice(const QString &)));
}
@ -65,18 +71,15 @@ AWKeys::~AWKeys()
{
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
// extensions
delete graphicalItems;
delete extQuotes;
delete extScripts;
delete extUpgrade;
delete extWeather;
m_timer->stop();
delete m_timer;
// core
delete dataEngineAggregator;
delete m_threadPool;
delete aggregator;
delete dataAggregator;
delete keyOperator;
}
@ -84,39 +87,39 @@ void AWKeys::initDataAggregator(const QVariantMap tooltipParams)
{
qCDebug(LOG_AW) << "Tooltip parameters" << tooltipParams;
dataAggregator->setParameters(tooltipParams);
// store parameters to generate m_requiredKeys
m_tooltipParams = tooltipParams;
dataAggregator->setParameters(m_tooltipParams);
}
void AWKeys::initKeys(const QString currentPattern, const int interval,
const int limit)
const int limit, const bool optimize)
{
qCDebug(LOG_AW) << "Pattern" << currentPattern;
qCDebug(LOG_AW) << "Interval" << interval;
qCDebug(LOG_AW) << "Queue limit" << limit;
qCDebug(LOG_AW) << "Pattern" << currentPattern << "with interval"
<< interval << "and queue limit" << limit
<< "with optimization" << optimize;
// init
m_pattern = currentPattern;
if (dataEngineAggregator == nullptr) {
dataEngineAggregator = new AWDataEngineAggregator(this, interval);
connect(this, SIGNAL(dropSourceFromDataengine(QString)),
dataEngineAggregator, SLOT(dropSource(QString)));
} else
dataEngineAggregator->setInterval(interval);
#ifdef BUILD_FUTURE
m_optimize = optimize;
m_threadPool->setMaxThreadCount(limit == 0 ? QThread::idealThreadCount()
: limit);
#endif /* BUILD_FUTURE */
updateCache();
// child objects
keyOperator->setPattern(currentPattern);
keyOperator->updateCache();
dataEngineAggregator->clear();
return dataEngineAggregator->reconnectSources();
dataEngineAggregator->initDataEngines(interval);
// timer
m_timer->setInterval(interval);
m_timer->start();
}
void AWKeys::setAggregatorProperty(const QString key, const QVariant value)
{
qCDebug(LOG_AW) << "Key" << key;
qCDebug(LOG_AW) << "Value" << value;
qCDebug(LOG_AW) << "Key" << key << "with value" << value;
aggregator->setProperty(key.toUtf8().constData(), value);
}
@ -132,172 +135,16 @@ void AWKeys::setWrapNewLines(const bool wrap)
void AWKeys::updateCache()
{
// update network and hdd list
addKeyToCache(QString("hdd"));
addKeyToCache(QString("net"));
return keyOperator->updateCache();
}
QStringList AWKeys::dictKeys(const bool sorted, const QString regexp) const
{
qCDebug(LOG_AW) << "Should be sorted" << sorted;
qCDebug(LOG_AW) << "Filter" << regexp;
QStringList allKeys;
// weather
for (int i = extWeather->activeItems().count() - 1; i >= 0; i--) {
allKeys.append(
extWeather->activeItems().at(i)->tag(QString("weatherId")));
allKeys.append(
extWeather->activeItems().at(i)->tag(QString("weather")));
allKeys.append(
extWeather->activeItems().at(i)->tag(QString("humidity")));
allKeys.append(
extWeather->activeItems().at(i)->tag(QString("pressure")));
allKeys.append(
extWeather->activeItems().at(i)->tag(QString("temperature")));
allKeys.append(
extWeather->activeItems().at(i)->tag(QString("timestamp")));
}
// time
allKeys.append(QString("time"));
allKeys.append(QString("isotime"));
allKeys.append(QString("shorttime"));
allKeys.append(QString("longtime"));
allKeys.append(QString("ctime"));
// uptime
allKeys.append(QString("uptime"));
allKeys.append(QString("cuptime"));
// cpuclock & cpu
for (int i = QThread::idealThreadCount() - 1; i >= 0; i--) {
allKeys.append(QString("cpucl%1").arg(i));
allKeys.append(QString("cpu%1").arg(i));
}
allKeys.append(QString("cpucl"));
allKeys.append(QString("cpu"));
// temperature
for (int i = m_devices[QString("temp")].count() - 1; i >= 0; i--)
allKeys.append(QString("temp%1").arg(i));
// gputemp
allKeys.append(QString("gputemp"));
// gpu
allKeys.append(QString("gpu"));
// memory
allKeys.append(QString("memmb"));
allKeys.append(QString("memgb"));
allKeys.append(QString("memfreemb"));
allKeys.append(QString("memfreegb"));
allKeys.append(QString("memtotmb"));
allKeys.append(QString("memtotgb"));
allKeys.append(QString("memusedmb"));
allKeys.append(QString("memusedgb"));
allKeys.append(QString("mem"));
// swap
allKeys.append(QString("swapmb"));
allKeys.append(QString("swapgb"));
allKeys.append(QString("swapfreemb"));
allKeys.append(QString("swapfreegb"));
allKeys.append(QString("swaptotmb"));
allKeys.append(QString("swaptotgb"));
allKeys.append(QString("swap"));
// hdd
for (int i = m_devices[QString("mount")].count() - 1; i >= 0; i--) {
allKeys.append(QString("hddmb%1").arg(i));
allKeys.append(QString("hddgb%1").arg(i));
allKeys.append(QString("hddfreemb%1").arg(i));
allKeys.append(QString("hddfreegb%1").arg(i));
allKeys.append(QString("hddtotmb%1").arg(i));
allKeys.append(QString("hddtotgb%1").arg(i));
allKeys.append(QString("hdd%1").arg(i));
}
// hdd speed
for (int i = m_devices[QString("disk")].count() - 1; i >= 0; i--) {
allKeys.append(QString("hddr%1").arg(i));
allKeys.append(QString("hddw%1").arg(i));
}
// hdd temp
for (int i = m_devices[QString("hdd")].count() - 1; i >= 0; i--)
allKeys.append(QString("hddtemp%1").arg(i));
// network
for (int i = m_devices[QString("net")].count() - 1; i >= 0; i--) {
allKeys.append(QString("downunits%1").arg(i));
allKeys.append(QString("upunits%1").arg(i));
allKeys.append(QString("downkb%1").arg(i));
allKeys.append(QString("down%1").arg(i));
allKeys.append(QString("upkb%1").arg(i));
allKeys.append(QString("up%1").arg(i));
}
allKeys.append(QString("downunits"));
allKeys.append(QString("upunits"));
allKeys.append(QString("downkb"));
allKeys.append(QString("down"));
allKeys.append(QString("upkb"));
allKeys.append(QString("up"));
allKeys.append(QString("netdev"));
// battery
allKeys.append(QString("ac"));
QStringList allBatteryDevices
= QDir(QString("/sys/class/power_supply"))
.entryList(QStringList() << QString("BAT*"),
QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name);
for (int i = allBatteryDevices.count() - 1; i >= 0; i--)
allKeys.append(QString("bat%1").arg(i));
allKeys.append(QString("bat"));
// player
allKeys.append(QString("album"));
allKeys.append(QString("artist"));
allKeys.append(QString("duration"));
allKeys.append(QString("progress"));
allKeys.append(QString("title"));
allKeys.append(QString("dalbum"));
allKeys.append(QString("dartist"));
allKeys.append(QString("dtitle"));
allKeys.append(QString("salbum"));
allKeys.append(QString("sartist"));
allKeys.append(QString("stitle"));
// ps
allKeys.append(QString("pscount"));
allKeys.append(QString("pstotal"));
allKeys.append(QString("ps"));
// package manager
for (int i = extUpgrade->activeItems().count() - 1; i >= 0; i--)
allKeys.append(
extUpgrade->activeItems().at(i)->tag(QString("pkgcount")));
// quotes
for (int i = extQuotes->activeItems().count() - 1; i >= 0; i--) {
allKeys.append(extQuotes->activeItems().at(i)->tag(QString("ask")));
allKeys.append(extQuotes->activeItems().at(i)->tag(QString("askchg")));
allKeys.append(
extQuotes->activeItems().at(i)->tag(QString("percaskchg")));
allKeys.append(extQuotes->activeItems().at(i)->tag(QString("bid")));
allKeys.append(extQuotes->activeItems().at(i)->tag(QString("bidchg")));
allKeys.append(
extQuotes->activeItems().at(i)->tag(QString("percbidchg")));
allKeys.append(extQuotes->activeItems().at(i)->tag(QString("price")));
allKeys.append(
extQuotes->activeItems().at(i)->tag(QString("pricechg")));
allKeys.append(
extQuotes->activeItems().at(i)->tag(QString("percpricechg")));
}
// custom
for (int i = extScripts->activeItems().count() - 1; i >= 0; i--)
allKeys.append(extScripts->activeItems().at(i)->tag(QString("custom")));
// desktop
allKeys.append(QString("desktop"));
allKeys.append(QString("ndesktop"));
allKeys.append(QString("tdesktops"));
// load average
allKeys.append(QString("la15"));
allKeys.append(QString("la5"));
allKeys.append(QString("la1"));
// bars
QStringList graphicalItemsKeys;
foreach (GraphicalItem *item, graphicalItems->items())
graphicalItemsKeys.append(item->tag());
graphicalItemsKeys.sort();
for (int i = graphicalItemsKeys.count() - 1; i >= 0; i--)
allKeys.append(graphicalItemsKeys.at(i));
qCDebug(LOG_AW) << "Should be sorted" << sorted << "and filter applied"
<< regexp;
QStringList allKeys = keyOperator->dictKeys();
// sort if required
if (sorted)
allKeys.sort();
@ -308,7 +155,7 @@ QStringList AWKeys::dictKeys(const bool sorted, const QString regexp) const
QStringList AWKeys::getHddDevices() const
{
QStringList devices = m_devices[QString("hdd")];
QStringList devices = keyOperator->devices(QString("hdd"));
// required by selector in the UI
devices.insert(0, QString("disable"));
devices.insert(0, QString("auto"));
@ -319,63 +166,19 @@ QStringList AWKeys::getHddDevices() const
QString AWKeys::infoByKey(QString key) const
{
qCDebug(LOG_AW) << "Requested key" << key;
qCDebug(LOG_AW) << "Requested info for key" << key;
key.remove(QRegExp(QString("^bar[0-9]{1,}")));
if (key.startsWith(QString("custom")))
return extScripts->itemByTagNumber(
key.remove(QString("custom")).toInt())
->uniq();
else if (key.contains(QRegExp(QString("^hdd[rw]"))))
return QString("%1").arg(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)"))))
return QString("%1").arg(m_devices[QString(
"mount")][key
.remove(QRegExp(QString(
"^hdd([0-9]|mb|gb|freemb|freegb|totmb|totgb)")))
.toInt()]);
else if (key.startsWith(QString("hddtemp")))
return QString("%1").arg(
m_devices[QString("hdd")][key.remove(QString("hddtemp")).toInt()]);
else if (key.contains(QRegExp(QString("^(down|up)[0-9]"))))
return QString("%1").arg(m_devices[QString(
"net")][key.remove(QRegExp(QString("^(down|up)"))).toInt()]);
else if (key.startsWith(QString("pkgcount")))
return extUpgrade->itemByTagNumber(
key.remove(QString("pkgcount")).toInt())
->uniq();
else if (key.contains(QRegExp(QString("(^|perc)(ask|bid|price)(chg|)"))))
return extQuotes->itemByTagNumber(
key.remove(QRegExp(QString(
"(^|perc)(ask|bid|price)(chg|)")))
.toInt())
->uniq();
else if (key.contains(QRegExp(
QString("(weather|weatherId|humidity|pressure|temperature)"))))
return extWeather
->itemByTagNumber(
key
.remove(QRegExp(QString(
"(weather|weatherId|humidity|pressure|temperature)")))
.toInt())
->uniq();
else if (key.startsWith(QString("temp")))
return QString("%1").arg(
m_devices[QString("temp")][key.remove(QString("temp")).toInt()]);
return QString("(none)");
return keyOperator->infoByKey(key);
}
// HACK this method requires to define tag value from bar from UI interface
QString AWKeys::valueByKey(QString key) const
{
qCDebug(LOG_AW) << "Requested key" << key;
qCDebug(LOG_AW) << "Requested value for key" << key;
return values.value(key.remove(QRegExp(QString("^bar[0-9]{1,}"))),
QString(""));
key.remove(QRegExp(QString("^bar[0-9]{1,}")));
return aggregator->formatter(values[key], key);
}
@ -383,363 +186,151 @@ void AWKeys::editItem(const QString type)
{
qCDebug(LOG_AW) << "Item type" << type;
if (type == QString("graphicalitem")) {
graphicalItems->setConfigArgs(dictKeys(
true, QString("^(cpu(?!cl).*|gpu$|mem$|swap$|hdd[0-9].*|bat.*)")));
return graphicalItems->editItems();
} else if (type == QString("extquotes")) {
return extQuotes->editItems();
} else if (type == QString("extscript")) {
return extScripts->editItems();
} else if (type == QString("extupgrade")) {
return extUpgrade->editItems();
} else if (type == QString("extweather")) {
return extWeather->editItems();
}
}
void AWKeys::addDevice(const QString source)
{
qCDebug(LOG_AW) << "Source" << source;
QRegExp diskRegexp
= QRegExp(QString("disk/(?:md|sd|hd)[a-z|0-9]_.*/Rate/(?:rblk)"));
QRegExp mountRegexp = QRegExp(QString("partitions/.*/filllevel"));
if (source.contains(diskRegexp)) {
QString device = source;
device.remove(QString("/Rate/rblk"));
addKeyToCache(QString("disk"), device);
} else if (source.contains(mountRegexp)) {
QString device = source;
device.remove(QString("partitions")).remove(QString("/filllevel"));
addKeyToCache(QString("mount"), device);
} else if (source.startsWith(QString("lmsensors"))) {
addKeyToCache(QString("temp"), source);
}
return keyOperator->editItem(type);
}
void AWKeys::dataUpdated(const QString &sourceName,
const Plasma::DataEngine::Data &data)
{
// do not log these parameters
if (sourceName == QString("update")) {
qCInfo(LOG_AW) << "Update data";
return emit(needToBeUpdated());
}
#ifdef BUILD_FUTURE
// run concurrent data update
QtConcurrent::run(m_threadPool, this, &AWKeys::setDataBySource, sourceName,
data);
#else /* BUILD_FUTURE */
return setDataBySource(sourceName, data);
#endif /* BUILD_FUTURE */
}
void AWKeys::loadKeysFromCache()
void AWKeys::reinitKeys(const QStringList currentKeys)
{
QString fileName = QString("%1/awesomewidgets.ndx")
.arg(QStandardPaths::writableLocation(
QStandardPaths::GenericCacheLocation));
qCInfo(LOG_AW) << "Cache file" << fileName;
QSettings cache(fileName, QSettings::IniFormat);
foreach (QString group, cache.childGroups()) {
cache.beginGroup(group);
m_devices.remove(group);
foreach (QString key, cache.allKeys())
m_devices[group].append(cache.value(key).toString());
cache.endGroup();
}
return reinitKeys();
}
void AWKeys::reinitKeys()
{
// renew extensions
// delete them if any
delete graphicalItems;
graphicalItems = nullptr;
delete extQuotes;
extQuotes = nullptr;
delete extScripts;
extScripts = nullptr;
delete extUpgrade;
extUpgrade = nullptr;
delete extWeather;
extWeather = nullptr;
// create
graphicalItems
= new ExtItemAggregator<GraphicalItem>(nullptr, QString("desktops"));
extQuotes = new ExtItemAggregator<ExtQuotes>(nullptr, QString("quotes"));
extScripts = new ExtItemAggregator<ExtScript>(nullptr, QString("scripts"));
extUpgrade = new ExtItemAggregator<ExtUpgrade>(nullptr, QString("upgrade"));
extWeather = new ExtItemAggregator<ExtWeather>(nullptr, QString("weather"));
// init
QStringList allKeys = dictKeys();
#ifdef BUILD_TESTING
// not documented feature - place all available tags
m_pattern = m_pattern.replace(QString("$ALL"), [allKeys]() {
QStringList strings;
foreach (QString tag, allKeys)
strings.append(QString("%1: $%1").arg(tag));
return strings.join(QString(" | "));
}());
#endif /* BUILD_TESTING */
qCDebug(LOG_AW) << "Update found keys by using list" << currentKeys;
// append lists
// bars
m_foundBars = [allKeys](QString pattern) {
QStringList selectedKeys;
foreach (QString key, allKeys)
if ((key.startsWith(QString("bar")))
&& (pattern.contains(QString("$%1").arg(key)))) {
qCInfo(LOG_AW) << "Found bar" << key;
selectedKeys.append(key);
}
if (selectedKeys.isEmpty())
qCWarning(LOG_AW) << "No bars found";
return selectedKeys;
}(m_pattern);
// main key list
m_foundKeys = [allKeys](QString pattern) {
QStringList selectedKeys;
foreach (QString key, allKeys)
if ((!key.startsWith(QString("bar")))
&& (pattern.contains(QString("$%1").arg(key)))) {
qCInfo(LOG_AW) << "Found key" << key;
selectedKeys.append(key);
}
if (selectedKeys.isEmpty())
qCWarning(LOG_AW) << "No keys found";
return selectedKeys;
}(m_pattern);
// lambdas
m_foundLambdas = [](QString pattern) {
QStringList selectedKeys;
// substring inside ${{ }} (with brackets) which should not contain ${{
QRegularExpression lambdaRegexp(
QString("\\$\\{\\{((?!\\$\\{\\{).)*?\\}\\}"));
lambdaRegexp.setPatternOptions(
QRegularExpression::DotMatchesEverythingOption);
QRegularExpressionMatchIterator it = lambdaRegexp.globalMatch(pattern);
while (it.hasNext()) {
QRegularExpressionMatch match = it.next();
QString lambda = match.captured();
// drop brakets
lambda.remove(QRegExp(QString("^\\$\\{\\{")));
lambda.remove(QRegExp(QString("\\}\\}$")));
// append
qCInfo(LOG_AW) << "Found lambda" << lambda;
selectedKeys.append(lambda);
}
if (selectedKeys.isEmpty())
qCWarning(LOG_AW) << "No lambdas found";
return selectedKeys;
}(m_pattern);
m_foundBars
= AWPatternFunctions::findBars(keyOperator->pattern(), currentKeys);
m_foundKeys
= AWPatternFunctions::findKeys(keyOperator->pattern(), currentKeys);
m_foundLambdas = AWPatternFunctions::findLambdas(keyOperator->pattern());
// generate list of required keys for bars
QStringList barKeys;
for (auto bar : m_foundBars) {
GraphicalItem *item = keyOperator->giByKey(bar);
if (item->isCustom())
item->setUsedKeys(
AWPatternFunctions::findKeys(item->bar(), currentKeys));
else
item->setUsedKeys(QStringList() << item->bar());
barKeys.append(item->usedKeys());
}
// get required keys
m_requiredKeys
= m_optimize ? AWKeyCache::getRequiredKeys(m_foundKeys, barKeys,
m_tooltipParams, currentKeys)
: QStringList();
// set key data to aggregator
aggregator->setDevices(m_devices);
aggregator->setDevices(keyOperator->devices());
}
void AWKeys::updateTextData()
{
#ifdef BUILD_FUTURE
QFuture<QString> text = QtConcurrent::run(m_threadPool, [this]() {
calculateValues();
return parsePattern(m_pattern);
});
#else /* BUILD_FUTURE */
// do not do it in parallel to avoid race condition
calculateValues();
QString text = parsePattern(m_pattern);
#endif /* BUILD_FUTURE */
QString text = parsePattern(keyOperator->pattern());
emit(needTextToBeUpdated(text));
emit(dataAggregator->updateData(values));
}
void AWKeys::addKeyToCache(const QString type, const QString key)
{
qCDebug(LOG_AW) << "Key type" << type;
qCDebug(LOG_AW) << "Key" << key;
QString fileName = QString("%1/awesomewidgets.ndx")
.arg(QStandardPaths::writableLocation(
QStandardPaths::GenericCacheLocation));
qCInfo(LOG_AW) << "Cache file" << fileName;
QSettings cache(fileName, QSettings::IniFormat);
cache.beginGroup(type);
QStringList cachedValues;
foreach (QString key, cache.allKeys())
cachedValues.append(cache.value(key).toString());
if (type == QString("hdd")) {
QStringList allDevices
= QDir(QString("/dev")).entryList(QDir::System, QDir::Name);
QStringList devices
= allDevices.filter(QRegExp(QString("^[hms]d[a-z]$")));
foreach (QString dev, devices) {
QString device = QString("/dev/%1").arg(dev);
if (cachedValues.contains(device))
continue;
qCInfo(LOG_AW) << "Found new key" << device << "for type" << type;
cache.setValue(
QString("%1").arg(cache.allKeys().count(), 3, 10, QChar('0')),
device);
}
} else if (type == QString("net")) {
QList<QNetworkInterface> rawInterfaceList
= QNetworkInterface::allInterfaces();
foreach (QNetworkInterface interface, rawInterfaceList) {
QString device = interface.name();
if (cachedValues.contains(device))
continue;
qCInfo(LOG_AW) << "Found new key" << device << "for type" << type;
cache.setValue(
QString("%1").arg(cache.allKeys().count(), 3, 10, QChar('0')),
device);
}
} else {
if (cachedValues.contains(key))
return;
qCInfo(LOG_AW) << "Found new key" << key << "for type" << type;
cache.setValue(
QString("%1").arg(cache.allKeys().count(), 3, 10, QChar('0')), key);
}
cache.endGroup();
cache.sync();
return loadKeysFromCache();
}
// HACK this method is required since I could not define some values by using
// specified pattern. Usually they are values which depend on several others
void AWKeys::calculateValues()
{
// hddtot*
foreach (QString device, m_devices[QString("mount")]) {
int index = m_devices[QString("mount")].indexOf(device);
values[QString("hddtotmb%1").arg(index)] = QString("%1").arg(
values[QString("hddfreemb%1").arg(index)].toFloat()
+ values[QString("hddmb%1").arg(index)].toFloat(),
5, 'f', 0);
values[QString("hddtotgb%1").arg(index)] = QString("%1").arg(
values[QString("hddfreegb%1").arg(index)].toFloat()
+ values[QString("hddgb%1").arg(index)].toFloat(),
5, 'f', 1);
QStringList mountDevices = keyOperator->devices(QString("mount"));
for (auto device : mountDevices) {
int index = mountDevices.indexOf(device);
values[QString("hddtotmb%1").arg(index)]
= values[QString("hddfreemb%1").arg(index)].toFloat()
+ values[QString("hddmb%1").arg(index)].toFloat();
values[QString("hddtotgb%1").arg(index)]
= values[QString("hddfreegb%1").arg(index)].toFloat()
+ values[QString("hddgb%1").arg(index)].toFloat();
}
// memtot*
values[QString("memtotmb")]
= QString("%1").arg(values[QString("memusedmb")].toInt()
+ values[QString("memfreemb")].toInt(),
5);
values[QString("memtotgb")]
= QString("%1").arg(values[QString("memusedgb")].toFloat()
+ values[QString("memfreegb")].toFloat(),
5, 'f', 1);
values[QString("memtotmb")] = values[QString("memusedmb")].toInt()
+ values[QString("memfreemb")].toInt();
values[QString("memtotgb")] = values[QString("memusedgb")].toFloat()
+ values[QString("memfreegb")].toFloat();
// mem
values[QString("mem")]
= QString("%1").arg(100.0 * values[QString("memmb")].toFloat()
/ values[QString("memtotmb")].toFloat(),
5, 'f', 1);
values[QString("mem")] = 100.0f * values[QString("memmb")].toFloat()
/ values[QString("memtotmb")].toFloat();
// up, down, upkb, downkb, upunits, downunits
int netIndex = m_devices[QString("net")].indexOf(values[QString("netdev")]);
int netIndex = keyOperator->devices(QString("net"))
.indexOf(values[QString("netdev")].toString());
values[QString("down")] = values[QString("down%1").arg(netIndex)];
values[QString("downkb")] = values[QString("downkb%1").arg(netIndex)];
values[QString("downtotal")] = values[QString("downtotal%1").arg(netIndex)];
values[QString("downtotalkb")]
= values[QString("downtotalkb%1").arg(netIndex)];
values[QString("downunits")] = values[QString("downunits%1").arg(netIndex)];
values[QString("up")] = values[QString("up%1").arg(netIndex)];
values[QString("upkb")] = values[QString("upkb%1").arg(netIndex)];
values[QString("uptotal")] = values[QString("uptotal%1").arg(netIndex)];
values[QString("uptotalkb")] = values[QString("uptotalkb%1").arg(netIndex)];
values[QString("upunits")] = values[QString("upunits%1").arg(netIndex)];
// swaptot*
values[QString("swaptotmb")]
= QString("%1").arg(values[QString("swapmb")].toInt()
+ values[QString("swapfreemb")].toInt(),
5);
values[QString("swaptotgb")]
= QString("%1").arg(values[QString("swapgb")].toFloat()
+ values[QString("swapfreegb")].toFloat(),
5, 'f', 1);
values[QString("swaptotmb")] = values[QString("swapmb")].toInt()
+ values[QString("swapfreemb")].toInt();
values[QString("swaptotgb")] = values[QString("swapgb")].toFloat()
+ values[QString("swapfreegb")].toFloat();
// swap
values[QString("swap")]
= QString("%1").arg(100.0 * values[QString("swapmb")].toFloat()
/ values[QString("swaptotmb")].toFloat(),
5, 'f', 1);
values[QString("swap")] = 100.0f * values[QString("swapmb")].toFloat()
/ values[QString("swaptotmb")].toFloat();
// lambdas
foreach (QString key, m_foundLambdas)
values[key] = [this](QString key) {
QJSEngine engine;
// apply $this values
key.replace(QString("$this"), values[key]);
foreach (QString lambdaKey, m_foundKeys)
key.replace(QString("$%1").arg(lambdaKey), values[lambdaKey]);
qCInfo(LOG_AW) << "Expression" << key;
QJSValue result = engine.evaluate(key);
if (result.isError()) {
qCWarning(LOG_AW) << "Uncaught exception at line"
<< result.property("lineNumber").toInt()
<< ":" << result.toString();
return QString();
} else {
return result.toString();
}
}(key);
for (auto key : m_foundLambdas)
values[key] = AWPatternFunctions::expandLambdas(key, aggregator, values,
m_foundKeys);
}
QString AWKeys::parsePattern(QString pattern) const
{
// screen sign
pattern.replace(QString("$$"), QString("$\\$\\"));
pattern.replace(QString("$$"), QString(0x1d));
// lambdas
foreach (QString key, m_foundLambdas)
pattern.replace(QString("${{%1}}").arg(key), values[key]);
for (auto key : m_foundLambdas)
pattern.replace(QString("${{%1}}").arg(key), values[key].toString());
// main keys
foreach (QString key, m_foundKeys)
pattern.replace(QString("$%1").arg(key),
[](QString key, QString value) {
if ((!key.startsWith(QString("custom")))
&& (!key.startsWith(QString("weather"))))
value.replace(QString(" "), QString("&nbsp;"));
return value;
}(key, values[key]));
for (auto key : m_foundKeys)
pattern.replace(QString("$%1").arg(key), [this](const QString &tag,
const QVariant &value) {
QString strValue = aggregator->formatter(value, tag);
if ((!tag.startsWith(QString("custom")))
&& (!tag.startsWith(QString("weather"))))
strValue.replace(QString(" "), QString("&nbsp;"));
return strValue;
}(key, values[key]));
// bars
foreach (QString bar, m_foundBars) {
GraphicalItem *item = graphicalItems->itemByTag(bar);
QString key = bar;
key.remove(QRegExp(QString("^bar[0-9]{1,}")));
if (item->type() == GraphicalItem::Graph)
pattern.replace(QString("$%1").arg(bar),
item->image([](const QList<float> data) {
return QVariant::fromValue<QList<float>>(data);
}(dataAggregator->getData(key))));
else
pattern.replace(QString("$%1").arg(bar), item->image(values[key]));
for (auto bar : m_foundBars) {
GraphicalItem *item = keyOperator->giByKey(bar);
QString image
= item->isCustom()
? item->image(AWPatternFunctions::expandLambdas(
item->bar(), aggregator, values, item->usedKeys()))
: item->image(values[item->bar()]);
pattern.replace(QString("$%1").arg(bar), image);
}
// prepare strings
pattern.replace(QString("$\\$\\"), QString("$$"));
pattern.replace(QString(0x1d), QString("$"));
if (m_wrapNewLines)
pattern.replace(QString("\n"), QString("<br>"));
@ -749,34 +340,27 @@ QString AWKeys::parsePattern(QString pattern) const
void AWKeys::setDataBySource(const QString &sourceName, const QVariantMap &data)
{
qCDebug(LOG_AW) << "Source" << sourceName;
qCDebug(LOG_AW) << "Data" << data;
qCDebug(LOG_AW) << "Source" << sourceName << "with data" << data;
// first list init
QStringList tags = aggregator->keysFromSource(sourceName);
if (tags.isEmpty())
tags = aggregator->registerSource(sourceName,
data[QString("units")].toString());
tags = aggregator->registerSource(
sourceName, data[QString("units")].toString(), m_requiredKeys);
// update data or drop source if there are no matches
// update data or drop source if there are no matches and exit
if (tags.isEmpty()) {
qCDebug(LOG_AW) << "Source" << sourceName << "not found";
emit(dropSourceFromDataengine(sourceName));
} else {
#ifdef BUILD_FUTURE
m_mutex.lock();
#endif /* BUILD_FUTURE */
// HACK workaround for time values which are stored in the different
// path
QVariant value = sourceName == QString("Local")
? data[QString("DateTime")]
: data[QString("value")];
std::for_each(tags.cbegin(), tags.cend(),
[this, value](const QString tag) {
values[tag] = aggregator->formater(value, tag);
});
#ifdef BUILD_FUTURE
m_mutex.unlock();
#endif /* BUILD_FUTURE */
qCInfo(LOG_AW) << "Source" << sourceName << "not found";
return emit(dropSourceFromDataengine(sourceName));
}
m_mutex.lock();
// HACK workaround for time values which are stored in the different path
std::for_each(tags.cbegin(), tags.cend(),
[this, &data, &sourceName](const QString &tag) {
values[tag] = sourceName == QString("Local")
? data[QString("DateTime")]
: data[QString("value")];
});
m_mutex.unlock();
}

View File

@ -24,18 +24,13 @@
#include <QMutex>
#include <QObject>
#include "extitemaggregator.h"
class AWDataAggregator;
class AWDataEngineAggregator;
class AWKeyOperations;
class AWKeysAggregator;
class ExtQuotes;
class ExtScript;
class ExtUpgrade;
class ExtWeather;
class GraphicalItem;
class QThreadPool;
class QTimer;
class AWKeys : public QObject
{
@ -46,10 +41,12 @@ public:
virtual ~AWKeys();
Q_INVOKABLE void initDataAggregator(const QVariantMap tooltipParams);
Q_INVOKABLE void initKeys(const QString currentPattern, const int interval,
const int limit);
const int limit, const bool optimize);
Q_INVOKABLE void setAggregatorProperty(const QString key,
const QVariant value);
Q_INVOKABLE void setWrapNewLines(const bool wrap = false);
// additional method to force load keys from Qml UI. Used in some
// configuration pages
Q_INVOKABLE void updateCache();
// keys
Q_INVOKABLE QStringList dictKeys(const bool sorted = false,
@ -62,7 +59,6 @@ public:
Q_INVOKABLE void editItem(const QString type);
public slots:
void addDevice(const QString source);
void dataUpdated(const QString &sourceName,
const Plasma::DataEngine::Data &data);
// dummy method required by DataEngine connections
@ -72,16 +68,13 @@ signals:
void dropSourceFromDataengine(const QString source);
void needTextToBeUpdated(const QString newText) const;
void needToolTipToBeUpdated(const QString newText) const;
void needToBeUpdated();
private slots:
void loadKeysFromCache();
void reinitKeys();
void reinitKeys(const QStringList currentKeys);
void updateTextData();
private:
// methods
void addKeyToCache(const QString type, const QString key = QString(""));
void calculateValues();
QString parsePattern(QString pattern) const;
void setDataBySource(const QString &sourceName, const QVariantMap &data);
@ -89,16 +82,13 @@ private:
AWDataAggregator *dataAggregator = nullptr;
AWDataEngineAggregator *dataEngineAggregator = nullptr;
AWKeysAggregator *aggregator = nullptr;
ExtItemAggregator<GraphicalItem> *graphicalItems = nullptr;
ExtItemAggregator<ExtQuotes> *extQuotes = nullptr;
ExtItemAggregator<ExtScript> *extScripts = nullptr;
ExtItemAggregator<ExtUpgrade> *extUpgrade = nullptr;
ExtItemAggregator<ExtWeather> *extWeather = nullptr;
AWKeyOperations *keyOperator = nullptr;
QTimer *m_timer = nullptr;
// variables
QHash<QString, QStringList> m_devices;
QStringList m_foundBars, m_foundKeys, m_foundLambdas;
QString m_pattern;
QHash<QString, QString> values;
QVariantMap m_tooltipParams;
QStringList m_foundBars, m_foundKeys, m_foundLambdas, m_requiredKeys;
QVariantHash values;
bool m_optimize = false;
bool m_wrapNewLines = false;
// multithread features
QThreadPool *m_threadPool = nullptr;

View File

@ -24,57 +24,81 @@
#include <QRegExp>
#include "awdebug.h"
#include "awformatterhelper.h"
AWKeysAggregator::AWKeysAggregator(QObject *parent)
: QObject(parent)
{
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
// default formatters
// memory
m_formatter[QString("mem")] = FormatterType::Float;
m_formatter[QString("memtotmb")] = FormatterType::MemMBFormat;
m_formatter[QString("memtotgb")] = FormatterType::MemGBFormat;
// network
m_formatter[QString("down")] = FormatterType::NetSmartFormat;
m_formatter[QString("downkb")] = FormatterType::Integer;
m_formatter[QString("downunits")] = FormatterType::NetSmartUnits;
m_formatter[QString("up")] = FormatterType::NetSmartFormat;
m_formatter[QString("upkb")] = FormatterType::Integer;
m_formatter[QString("upunits")] = FormatterType::NetSmartUnits;
// swap
m_formatter[QString("swap")] = FormatterType::Float;
m_formatter[QString("swaptotmb")] = FormatterType::MemMBFormat;
m_formatter[QString("swaptotgb")] = FormatterType::MemGBFormat;
m_customFormatters = new AWFormatterHelper(this);
}
AWKeysAggregator::~AWKeysAggregator()
{
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
delete m_customFormatters;
}
QString AWKeysAggregator::formater(const QVariant &data,
const QString &key) const
QString AWKeysAggregator::formatter(const QVariant &data,
const QString &key) const
{
qCDebug(LOG_AW) << "Data" << data;
qCDebug(LOG_AW) << "Key" << key;
qCDebug(LOG_AW) << "Data" << data << "for key" << key;
QString output;
QLocale loc = m_translate ? QLocale::system() : QLocale::c();
// case block
switch (m_formater[key]) {
case Float:
switch (m_formatter[key]) {
case FormatterType::Float:
output = QString("%1").arg(data.toFloat(), 5, 'f', 1);
break;
case FloatTwoSymbols:
case FormatterType::FloatTwoSymbols:
output = QString("%1").arg(data.toFloat(), 5, 'f', 2);
break;
case Integer:
case FormatterType::Integer:
output = QString("%1").arg(data.toFloat(), 4, 'f', 0);
break;
case IntegerThree:
case FormatterType::IntegerFive:
output = QString("%1").arg(data.toFloat(), 5, 'f', 0);
break;
case FormatterType::IntegerThree:
output = QString("%1").arg(data.toFloat(), 3, 'f', 0);
break;
case List:
case FormatterType::List:
output = data.toStringList().join(QChar(','));
break;
case ACFormat:
case FormatterType::ACFormat:
output = data.toBool() ? m_acOnline : m_acOffline;
break;
case MemGBFormat:
case FormatterType::MemGBFormat:
output
= QString("%1").arg(data.toFloat() / (1024.0 * 1024.0), 5, 'f', 1);
break;
case MemMBFormat:
case FormatterType::MemMBFormat:
output = QString("%1").arg(data.toFloat() / 1024.0, 5, 'f', 0);
break;
case NetSmartFormat:
case FormatterType::NetSmartFormat:
output = [](const float value) {
if (value > 1024.0)
return QString("%1").arg(value / 1024.0, 4, 'f', 1);
@ -82,41 +106,45 @@ QString AWKeysAggregator::formater(const QVariant &data,
return QString("%1").arg(value, 4, 'f', 0);
}(data.toFloat());
break;
case NetSmartUnits:
case FormatterType::NetSmartUnits:
if (data.toFloat() > 1024.0)
output = m_translate ? i18n("MB/s") : QString("MB/s");
else
output = m_translate ? i18n("KB/s") : QString("KB/s");
break;
case Quotes:
case FormatterType::Quotes:
// first cast
output = QString("%1").arg(data.toDouble(), 0, 'f');
output = output.rightJustified(8, QLatin1Char(' '), true);
break;
case Temperature:
case FormatterType::Temperature:
output = QString("%1").arg(temperature(data.toFloat()), 5, 'f', 1);
break;
case Time:
case FormatterType::Time:
output = data.toDateTime().toString();
break;
case TimeCustom:
case FormatterType::TimeCustom:
output = m_customTime;
[&output, loc, this](const QDateTime dt) {
foreach (QString key, timeKeys)
for (auto key : timeKeys)
output.replace(QString("$%1").arg(key), loc.toString(dt, key));
}(data.toDateTime());
break;
case TimeISO:
case FormatterType::TimeISO:
output = data.toDateTime().toString(Qt::ISODate);
break;
case TimeLong:
case FormatterType::TimeLong:
output = loc.toString(data.toDateTime(), QLocale::LongFormat);
break;
case TimeShort:
case FormatterType::TimeShort:
output = loc.toString(data.toDateTime(), QLocale::ShortFormat);
break;
case Uptime:
case UptimeCustom:
case FormatterType::Timestamp:
output = QString("%1").arg(
data.toDateTime().toMSecsSinceEpoch() / 1000.0, 10, 'f', 0);
break;
case FormatterType::Uptime:
case FormatterType::UptimeCustom:
output =
[](QString source, const int uptime) {
int seconds = uptime - uptime % 60;
@ -133,14 +161,17 @@ QString AWKeysAggregator::formater(const QVariant &data,
QString("%1").arg(minutes, 2, 10, QChar('0')));
source.replace(QString("$m"), QString("%1").arg(minutes));
return source;
}(m_formater[key] == Uptime ? QString("$ddd$hhh$mmm")
: m_customUptime,
data.toFloat());
}(m_formatter[key] == FormatterType::Uptime
? QString("$ddd$hhh$mmm")
: m_customUptime,
static_cast<int>(data.toFloat()));
break;
case NoFormat:
default:
case FormatterType::NoFormat:
output = data.toString();
break;
case FormatterType::Custom:
output = m_customFormatters->convert(data, key);
break;
}
return output;
@ -214,10 +245,10 @@ void AWKeysAggregator::setTranslate(const bool translate)
// HACK units required to define should the value be calculated as temperature
// or fan data
QStringList AWKeysAggregator::registerSource(const QString &source,
const QString &units)
const QString &units,
const QStringList &keys)
{
qCDebug(LOG_AW) << "Source" << source;
qCDebug(LOG_AW) << "Units" << units;
qCDebug(LOG_AW) << "Source" << source << "with units" << units;
// regular expressions
QRegExp cpuRegExp = QRegExp(QString("cpu/cpu.*/TotalLoad"));
@ -229,56 +260,58 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
QRegExp mountUsedRegExp = QRegExp(QString("partitions/.*/usedspace"));
QRegExp netRegExp = QRegExp(
QString("network/interfaces/.*/(receiver|transmitter)/data$"));
QRegExp netTotalRegExp = QRegExp(
QString("network/interfaces/.*/(receiver|transmitter)/dataTotal$"));
if (source == QString("battery/ac")) {
// AC
m_map[source] = QString("ac");
m_formater[QString("ac")] = ACFormat;
m_formatter[QString("ac")] = FormatterType::ACFormat;
} else if (source.startsWith(QString("battery/"))) {
// battery stats
QString key = source;
key.remove(QString("battery/"));
m_map[source] = key;
m_formater[key] = IntegerThree;
m_formatter[key] = FormatterType::IntegerThree;
} else if (source == QString("cpu/system/TotalLoad")) {
// cpu
m_map[source] = QString("cpu");
m_formater[QString("cpu")] = Float;
m_formatter[QString("cpu")] = FormatterType::Float;
} else if (source.contains(cpuRegExp)) {
// cpus
QString key = source;
key.remove(QString("cpu/")).remove(QString("/TotalLoad"));
m_map[source] = key;
m_formater[key] = Float;
m_formatter[key] = FormatterType::Float;
} else if (source == QString("cpu/system/AverageClock")) {
// cpucl
m_map[source] = QString("cpucl");
m_formater[QString("cpucl")] = Integer;
m_formatter[QString("cpucl")] = FormatterType::Integer;
} else if (source.contains(cpuclRegExp)) {
// cpucls
QString key = source;
key.remove(QString("cpu/cpu")).remove(QString("/clock"));
key = QString("cpucl%1").arg(key);
m_map[source] = key;
m_formater[key] = Integer;
m_formatter[key] = FormatterType::Integer;
} else if (source.startsWith(QString("custom"))) {
// custom
QString key = source;
key.remove(QString("custom/"));
m_map[source] = key;
m_formater[key] = NoFormat;
m_formatter[key] = FormatterType::NoFormat;
} else if (source == QString("desktop/current/name")) {
// current desktop name
m_map[source] = QString("desktop");
m_formater[QString("desktop")] = NoFormat;
m_formatter[QString("desktop")] = FormatterType::NoFormat;
} else if (source == QString("desktop/current/number")) {
// current desktop number
m_map[source] = QString("ndesktop");
m_formater[QString("ndesktop")] = NoFormat;
m_formatter[QString("ndesktop")] = FormatterType::NoFormat;
} else if (source == QString("desktop/total/number")) {
// desktop count
m_map[source] = QString("tdesktops");
m_formater[QString("tdesktops")] = NoFormat;
m_formatter[QString("tdesktops")] = FormatterType::NoFormat;
} else if (source.contains(hddrRegExp)) {
// read speed
QString device = source;
@ -287,7 +320,7 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
if (index > -1) {
QString key = QString("hddr%1").arg(index);
m_map[source] = key;
m_formater[key] = Integer;
m_formatter[key] = FormatterType::Integer;
}
} else if (source.contains(hddwRegExp)) {
// write speed
@ -297,16 +330,16 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
if (index > -1) {
QString key = QString("hddw%1").arg(index);
m_map[source] = key;
m_formater[key] = Integer;
m_formatter[key] = FormatterType::Integer;
}
} else if (source == QString("gpu/load")) {
// gpu load
m_map[source] = QString("gpu");
m_formater[QString("gpu")] = Float;
m_formatter[QString("gpu")] = FormatterType::Float;
} else if (source == QString("gpu/temperature")) {
// gpu temperature
m_map[source] = QString("gputemp");
m_formater[QString("gputemp")] = Temperature;
m_formatter[QString("gputemp")] = FormatterType::Temperature;
} else if (source.contains(mountFillRegExp)) {
// fill level
QString device = source;
@ -315,7 +348,12 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
if (index > -1) {
QString key = QString("hdd%1").arg(index);
m_map[source] = key;
m_formater[key] = Float;
m_formatter[key] = FormatterType::Float;
// additional keys
m_formatter[QString("hddtotmb%1").arg(index)]
= FormatterType::MemMBFormat;
m_formatter[QString("hddtotgb%1").arg(index)]
= FormatterType::MemGBFormat;
}
} else if (source.contains(mountFreeRegExp)) {
// free space
@ -326,11 +364,11 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
// mb
QString key = QString("hddfreemb%1").arg(index);
m_map[source] = key;
m_formater[key] = MemMBFormat;
m_formatter[key] = FormatterType::MemMBFormat;
// gb
key = QString("hddfreegb%1").arg(index);
m_map.insertMulti(source, key);
m_formater[key] = MemGBFormat;
m_formatter[key] = FormatterType::MemGBFormat;
}
} else if (source.contains(mountUsedRegExp)) {
// used
@ -341,11 +379,11 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
// mb
QString key = QString("hddmb%1").arg(index);
m_map[source] = key;
m_formater[key] = MemMBFormat;
m_formatter[key] = FormatterType::MemMBFormat;
// gb
key = QString("hddgb%1").arg(index);
m_map.insertMulti(source, key);
m_formater[key] = MemGBFormat;
m_formatter[key] = FormatterType::MemGBFormat;
}
} else if (source.startsWith(QString("hdd/temperature"))) {
// hdd temperature
@ -355,7 +393,7 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
if (index > -1) {
QString key = QString("hddtemp%1").arg(index);
m_map[source] = key;
m_formater[key] = Temperature;
m_formatter[key] = FormatterType::Temperature;
}
} else if (source.startsWith(QString("cpu/system/loadavg"))) {
// load average
@ -363,35 +401,35 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
time.remove(QString("cpu/system/loadavg"));
QString key = QString("la%1").arg(time);
m_map[source] = key;
m_formater[key] = FloatTwoSymbols;
m_formatter[key] = FormatterType::FloatTwoSymbols;
} else if (source == QString("mem/physical/application")) {
// app memory
// mb
m_map[source] = QString("memmb");
m_formater[QString("memmb")] = MemMBFormat;
m_formatter[QString("memmb")] = FormatterType::MemMBFormat;
// gb
m_map.insertMulti(source, QString("memgb"));
m_formater[QString("memgb")] = MemGBFormat;
m_formatter[QString("memgb")] = FormatterType::MemGBFormat;
} else if (source == QString("mem/physical/free")) {
// free memory
// mb
m_map[source] = QString("memfreemb");
m_formater[QString("memfreemb")] = MemMBFormat;
m_formatter[QString("memfreemb")] = FormatterType::MemMBFormat;
// gb
m_map.insertMulti(source, QString("memfreegb"));
m_formater[QString("memfreegb")] = MemGBFormat;
m_formatter[QString("memfreegb")] = FormatterType::MemGBFormat;
} else if (source == QString("mem/physical/used")) {
// used memory
// mb
m_map[source] = QString("memusedmb");
m_formater[QString("memusedmb")] = MemMBFormat;
m_formatter[QString("memusedmb")] = FormatterType::MemMBFormat;
// gb
m_map.insertMulti(source, QString("memusedgb"));
m_formater[QString("memusedgb")] = MemGBFormat;
m_formatter[QString("memusedgb")] = FormatterType::MemGBFormat;
} else if (source == QString("network/current/name")) {
// network device
m_map[source] = QString("netdev");
m_formater[QString("netdev")] = NoFormat;
m_formatter[QString("netdev")] = FormatterType::NoFormat;
} else if (source.contains(netRegExp)) {
// network speed
QString type = source.contains(QString("receiver")) ? QString("down")
@ -402,62 +440,78 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
// kb
QString key = QString("%1kb%2").arg(type).arg(index);
m_map[source] = key;
m_formater[key] = Integer;
m_formatter[key] = FormatterType::Integer;
// smart
key = QString("%1%2").arg(type).arg(index);
m_map.insertMulti(source, key);
m_formater[key] = NetSmartFormat;
m_formatter[key] = FormatterType::NetSmartFormat;
// units
key = QString("%1units%2").arg(type).arg(index);
m_map.insertMulti(source, key);
m_formater[key] = NetSmartUnits;
m_formatter[key] = FormatterType::NetSmartUnits;
}
} else if (source.contains(netTotalRegExp)) {
// network data total
QString type = source.contains(QString("receiver")) ? QString("down")
: QString("up");
int index
= m_devices[QString("net")].indexOf(source.split(QChar('/'))[2]);
if (index > -1) {
// kb
QString key = QString("%1totalkb%2").arg(type).arg(index);
m_map[source] = key;
m_formatter[key] = FormatterType::Integer;
// mb
key = QString("%1total%2").arg(type).arg(index);
m_map.insertMulti(source, key);
m_formatter[key] = FormatterType::MemMBFormat;
}
} else if (source.startsWith(QString("upgrade"))) {
// package manager
QString key = source;
key.remove(QString("upgrade/"));
m_map[source] = key;
m_formater[key] = IntegerThree;
m_formatter[key] = FormatterType::IntegerThree;
} else if (source.startsWith(QString("player"))) {
// player
QString key = source;
key.remove(QString("player/"));
m_map[source] = key;
m_formater[key] = NoFormat;
m_formatter[key] = FormatterType::NoFormat;
} else if (source == QString("ps/running/count")) {
// running processes count
m_map[source] = QString("pscount");
m_formater[QString("pscount")] = NoFormat;
m_formatter[QString("pscount")] = FormatterType::NoFormat;
} else if (source == QString("ps/running/list")) {
// list of running processes
m_map[source] = QString("ps");
m_formater[QString("ps")] = List;
m_formatter[QString("ps")] = FormatterType::List;
} else if (source == QString("ps/total/count")) {
// total processes count
m_map[source] = QString("pstotal");
m_formater[QString("pstotal")] = NoFormat;
m_formatter[QString("pstotal")] = FormatterType::NoFormat;
} else if (source.startsWith(QString("quotes"))) {
// quotes
QString key = source;
key.remove(QString("quotes/"));
m_map[source] = key;
m_formater[key] = Quotes;
m_formatter[key] = FormatterType::Quotes;
} else if (source == QString("mem/swap/free")) {
// free swap
// mb
m_map[source] = QString("swapfreemb");
m_formater[QString("swapfreemb")] = MemMBFormat;
m_formatter[QString("swapfreemb")] = FormatterType::MemMBFormat;
// gb
m_map.insertMulti(source, QString("swapfreegb"));
m_formater[QString("swapfreegb")] = MemGBFormat;
m_formatter[QString("swapfreegb")] = FormatterType::MemGBFormat;
} else if (source == QString("mem/swap/used")) {
// used swap
// mb
m_map[source] = QString("swapmb");
m_formater[QString("swapmb")] = MemMBFormat;
m_formatter[QString("swapmb")] = FormatterType::MemMBFormat;
// gb
m_map.insertMulti(source, QString("swapgb"));
m_formater[QString("swapgb")] = MemGBFormat;
m_formatter[QString("swapgb")] = FormatterType::MemGBFormat;
} else if (source.startsWith(QString("lmsensors/"))) {
// temperature
int index = m_devices[QString("temp")].indexOf(source);
@ -467,49 +521,79 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
if (index > -1) {
QString key = QString("temp%1").arg(index);
m_map[source] = key;
m_formater[key] = units == QString("°C") ? Temperature : Integer;
m_formatter[key] = units == QString("°C")
? FormatterType::Temperature
: FormatterType::Integer;
}
} else if (source == QString("Local")) {
// time
m_map[source] = QString("time");
m_formater[QString("time")] = Time;
m_formatter[QString("time")] = FormatterType::Time;
// custom time
m_map.insertMulti(source, QString("ctime"));
m_formater[QString("ctime")] = TimeCustom;
m_formatter[QString("ctime")] = FormatterType::TimeCustom;
// ISO time
m_map.insertMulti(source, QString("isotime"));
m_formater[QString("isotime")] = TimeISO;
m_formatter[QString("isotime")] = FormatterType::TimeISO;
// long time
m_map.insertMulti(source, QString("longtime"));
m_formater[QString("longtime")] = TimeLong;
m_formatter[QString("longtime")] = FormatterType::TimeLong;
// short time
m_map.insertMulti(source, QString("shorttime"));
m_formater[QString("shorttime")] = TimeShort;
m_formatter[QString("shorttime")] = FormatterType::TimeShort;
// timestamp
m_map.insertMulti(source, QString("tstime"));
m_formatter[QString("tstime")] = FormatterType::Timestamp;
} else if (source == QString("system/uptime")) {
// uptime
m_map[source] = QString("uptime");
m_formater[QString("uptime")] = Uptime;
m_formatter[QString("uptime")] = FormatterType::Uptime;
// custom uptime
m_map.insertMulti(source, QString("cuptime"));
m_formater[QString("cuptime")] = UptimeCustom;
m_formatter[QString("cuptime")] = FormatterType::UptimeCustom;
} else if (source.startsWith(QString("weather/temperature"))) {
// temperature
QString key = source;
key.remove(QString("weather/"));
m_map[source] = key;
m_formater[key] = Temperature;
m_formatter[key] = FormatterType::Temperature;
} else if (source.startsWith(QString("weather/"))) {
// other weather
QString key = source;
key.remove(QString("weather/"));
m_map[source] = key;
m_formater[key] = NoFormat;
m_formatter[key] = FormatterType::NoFormat;
} else if (source.startsWith(QString("load/load"))) {
// load source
QString key = source;
key.remove(QString("load/"));
m_map[source] = key;
m_formater[key] = Temperature;
m_formatter[key] = FormatterType::Temperature;
}
QStringList foundKeys = keysFromSource(source);
// rewrite formatters for custom ones
QStringList customFormattersKeys = m_customFormatters->definedFormatters();
qCInfo(LOG_AW) << "Looking for fprmatters" << foundKeys << "in"
<< customFormattersKeys;
for (auto key : foundKeys) {
if (!customFormattersKeys.contains(key))
continue;
m_formatter[key] = FormatterType::Custom;
}
// drop key from dictionary if no one user requested key required it
qCInfo(LOG_AW) << "Looking for keys" << foundKeys << "in" << keys;
bool required
= keys.isEmpty() || std::any_of(foundKeys.cbegin(), foundKeys.cend(),
[&keys](const QString &key) {
return keys.contains(key);
});
if (!required) {
m_map.remove(source);
for (auto key : foundKeys)
m_formatter.remove(key);
}
return keysFromSource(source);
@ -523,17 +607,17 @@ float AWKeysAggregator::temperature(const float temp) const
float converted = temp;
if (m_tempUnits == QString("Celsius")) {
} else if (m_tempUnits == QString("Fahrenheit")) {
converted = temp * 9.0 / 5.0 + 32.0;
converted = temp * 9.0f / 5.0f + 32.0f;
} else if (m_tempUnits == QString("Kelvin")) {
converted = temp + 273.15;
converted = temp + 273.15f;
} else if (m_tempUnits == QString("Reaumur")) {
converted = temp * 0.8;
converted = temp * 0.8f;
} else if (m_tempUnits == QString("cm^-1")) {
converted = (temp + 273.15) * 0.695;
converted = (temp + 273.15f) * 0.695f;
} else if (m_tempUnits == QString("kJ/mol")) {
converted = (temp + 273.15) * 8.31;
converted = (temp + 273.15f) * 8.31f;
} else if (m_tempUnits == QString("kcal/mol")) {
converted = (temp + 273.15) * 1.98;
converted = (temp + 273.15f) * 1.98f;
} else {
qCWarning(LOG_AW) << "Invalid units" << m_tempUnits;
}

View File

@ -25,6 +25,8 @@
#include "version.h"
class AWFormatterHelper;
class AWKeysAggregator : public QObject
{
Q_OBJECT
@ -36,15 +38,17 @@ class AWKeysAggregator : public QObject
Q_PROPERTY(QString tempUnits MEMBER m_tempUnits WRITE setTempUnits);
Q_PROPERTY(bool translate MEMBER m_translate WRITE setTranslate);
enum FormaterType {
// general formaters
NoFormat = 0,
enum class FormatterType {
// general formatters
Custom,
NoFormat,
Float,
FloatTwoSymbols,
Integer,
IntegerFive,
IntegerThree,
List,
// unit specific formaters
// unit specific formatters
ACFormat,
MemGBFormat,
MemMBFormat,
@ -57,6 +61,7 @@ class AWKeysAggregator : public QObject
TimeISO,
TimeLong,
TimeShort,
Timestamp,
Uptime,
UptimeCustom
};
@ -65,7 +70,7 @@ public:
explicit AWKeysAggregator(QObject *parent = nullptr);
virtual ~AWKeysAggregator();
// get methods
QString formater(const QVariant &data, const QString &key) const;
QString formatter(const QVariant &data, const QString &key) const;
QStringList keysFromSource(const QString &source) const;
// set methods
void setAcOffline(const QString inactive);
@ -77,10 +82,12 @@ public:
void setTranslate(const bool translate);
public slots:
QStringList registerSource(const QString &source, const QString &units);
QStringList registerSource(const QString &source, const QString &units,
const QStringList &keys);
private:
float temperature(const float temp) const;
AWFormatterHelper *m_customFormatters = nullptr;
QStringList timeKeys = QString(TIME_KEYS).split(QChar(','));
// variables
QString m_acOffline;
@ -88,7 +95,7 @@ private:
QString m_customTime;
QString m_customUptime;
QHash<QString, QStringList> m_devices;
QHash<QString, FormaterType> m_formater;
QHash<QString, FormatterType> m_formatter;
QHash<QString, QString> m_map;
QString m_tempUnits;
bool m_translate = false;

View File

@ -16,54 +16,44 @@
***************************************************************************/
#include "updatesource.h"
#include "awnoformatter.h"
#include "awdebug.h"
UpdateSource::UpdateSource(QObject *parent, const QStringList args)
: AbstractExtSysMonSource(parent, args)
AWNoFormatter::AWNoFormatter(QObject *parent, const QString filename,
const QString section)
: AWAbstractFormatter(parent, filename, section)
{
Q_ASSERT(args.count() == 0);
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
init(filename, section);
}
UpdateSource::~UpdateSource()
AWNoFormatter::AWNoFormatter(QObject *parent)
: AWAbstractFormatter(parent)
{
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
}
QVariant UpdateSource::data(QString source)
AWNoFormatter::~AWNoFormatter()
{
qCDebug(LOG_ESM) << "Source" << source;
return true;
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
}
QVariantMap UpdateSource::initialData(QString source) const
QString AWNoFormatter::convert(const QVariant &value) const
{
qCDebug(LOG_ESM) << "Source" << source;
qCDebug(LOG_AW) << "Convert value" << value;
QVariantMap data;
if (source == QString("update")) {
data[QString("min")] = true;
data[QString("max")] = true;
data[QString("name")] = QString("Simple value which is always true");
data[QString("type")] = QString("bool");
data[QString("units")] = QString("");
}
return data;
return value.toString();
}
QStringList UpdateSource::sources() const
void AWNoFormatter::init(const QString filename, const QString section)
{
QStringList sources;
sources.append(QString("update"));
return sources;
qCDebug(LOG_AW) << "Looking for section" << section << "in" << filename;
// dummy method for future references
}

View File

@ -0,0 +1,41 @@
/***************************************************************************
* 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 AWNOFORMATTER_H
#define AWNOFORMATTER_H
#include "awabstractformatter.h"
class AWNoFormatter : public AWAbstractFormatter
{
Q_OBJECT
public:
explicit AWNoFormatter(QObject *parent, const QString filename,
const QString section);
explicit AWNoFormatter(QObject *parent);
virtual ~AWNoFormatter();
QString convert(const QVariant &value) const;
private:
void init(const QString filename, const QString section);
// properties
};
#endif /* AWNOFORMATTER_H */

View File

@ -0,0 +1,295 @@
/***************************************************************************
* 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 "awpatternfunctions.h"
#include <QJSEngine>
#include <QRegularExpression>
#include "awdebug.h"
#include "awkeysaggregator.h"
QString AWPatternFunctions::expandLambdas(QString code,
AWKeysAggregator *aggregator,
const QVariantHash &metadata,
const QStringList &usedKeys)
{
qCDebug(LOG_AW) << "Expand lamdas in" << code;
QJSEngine engine;
// apply $this values
code.replace(QString("$this"), metadata[code].toString());
// parsed values
for (auto lambdaKey : usedKeys)
code.replace(QString("$%1").arg(lambdaKey),
aggregator->formatter(metadata[lambdaKey], lambdaKey));
qCInfo(LOG_AW) << "Expression" << code;
QJSValue result = engine.evaluate(code);
if (result.isError()) {
qCWarning(LOG_AW) << "Uncaught exception at line"
<< result.property("lineNumber").toInt() << ":"
<< result.toString();
return QString();
} else {
return result.toString();
}
}
QString AWPatternFunctions::expandTemplates(QString code)
{
qCDebug(LOG_AW) << "Expand templates in" << code;
// match the following construction $template{{some code here}}
QRegularExpression templatesRegexp(
QString("\\$template\\{\\{(?<body>.*?)\\}\\}"));
templatesRegexp.setPatternOptions(
QRegularExpression::DotMatchesEverythingOption);
QRegularExpressionMatchIterator it = templatesRegexp.globalMatch(code);
while (it.hasNext()) {
QRegularExpressionMatch match = it.next();
QString body = match.captured(QString("body"));
QJSEngine engine;
qCInfo(LOG_AW) << "Expression" << body;
QJSValue result = engine.evaluate(body);
QString templateResult = QString("");
if (result.isError()) {
qCWarning(LOG_AW) << "Uncaught exception at line"
<< result.property("lineNumber").toInt() << ":"
<< result.toString();
} else {
templateResult = result.toString();
}
// replace template
code.replace(match.captured(), templateResult);
}
return code;
}
QVariantList AWPatternFunctions::findFunctionCalls(const QString function,
const QString code)
{
qCDebug(LOG_AW) << "Looking for function" << function << "in" << code;
// I suggest the following regex for the internal functions
// $aw_function_name<some args here if any>{{function body}}
// * args should be always comma separated (e.g. commas are not supported
// in this field if they are not screened by $, i.e. '$,'
// * body depends on the function name, double brackets (i.e. {{ or }}) are
// not supported
QRegularExpression regex(
QString("\\$%1\\<(?<args>.*?)\\>\\{\\{(?<body>.*?)\\}\\}")
.arg(function));
regex.setPatternOptions(QRegularExpression::DotMatchesEverythingOption);
QVariantList foundFunctions;
QRegularExpressionMatchIterator it = regex.globalMatch(code);
while (it.hasNext()) {
QRegularExpressionMatch match = it.next();
QVariantHash metadata;
// work with args
QString argsString = match.captured(QString("args"));
if (argsString.isEmpty()) {
metadata[QString("args")] = QStringList();
} else {
// replace '$,' to 0x1d
argsString.replace(QString("$,"), QString(0x1d));
QStringList args = argsString.split(QChar(','));
std::for_each(args.begin(), args.end(), [](QString &arg) {
arg.replace(QString(0x1d), QString(","));
});
metadata[QString("args")] = args;
}
// other variables
metadata[QString("body")] = match.captured(QString("body"));
metadata[QString("what")] = match.captured();
foundFunctions.append(metadata);
}
return foundFunctions;
}
QString AWPatternFunctions::insertAllKeys(QString code, const QStringList keys)
{
qCDebug(LOG_AW) << "Looking for keys in code" << code << "using list"
<< keys;
QVariantList found
= AWPatternFunctions::findFunctionCalls(QString("aw_all"), code);
for (auto function : found) {
QVariantHash metadata = function.toHash();
QString separator
= metadata[QString("args")].toStringList().isEmpty()
? QString(",")
: metadata[QString("args")].toStringList().at(0);
QStringList required
= keys.filter(QRegExp(metadata[QString("body")].toString()));
std::for_each(required.begin(), required.end(), [](QString &value) {
value = QString("%1: $%1").arg(value);
});
code.replace(metadata[QString("what")].toString(),
required.join(separator));
}
return code;
}
QString AWPatternFunctions::insertKeyCount(QString code, const QStringList keys)
{
qCDebug(LOG_AW) << "Looking for count in code" << code << "using list"
<< keys;
QVariantList found
= AWPatternFunctions::findFunctionCalls(QString("aw_count"), code);
for (auto function : found) {
QVariantHash metadata = function.toHash();
int count = keys.filter(QRegExp(metadata[QString("body")].toString()))
.count();
code.replace(metadata[QString("what")].toString(),
QString::number(count));
}
return code;
}
QString AWPatternFunctions::insertKeyNames(QString code, const QStringList keys)
{
qCDebug(LOG_AW) << "Looking for key names in code" << code << "using list"
<< keys;
QVariantList found
= AWPatternFunctions::findFunctionCalls(QString("aw_names"), code);
for (auto function : found) {
QVariantHash metadata = function.toHash();
QString separator
= metadata[QString("args")].toStringList().isEmpty()
? QString(",")
: metadata[QString("args")].toStringList().at(0);
QStringList required
= keys.filter(QRegExp(metadata[QString("body")].toString()));
code.replace(metadata[QString("what")].toString(),
required.join(separator));
}
return code;
}
QString AWPatternFunctions::insertKeys(QString code, const QStringList keys)
{
qCDebug(LOG_AW) << "Looking for keys in code" << code << "using list"
<< keys;
QVariantList found
= AWPatternFunctions::findFunctionCalls(QString("aw_keys"), code);
for (auto function : found) {
QVariantHash metadata = function.toHash();
QString separator
= metadata[QString("args")].toStringList().isEmpty()
? QString(",")
: metadata[QString("args")].toStringList().at(0);
QStringList required
= keys.filter(QRegExp(metadata[QString("body")].toString()));
std::for_each(required.begin(), required.end(), [](QString &value) {
value = QString("$%1").arg(value);
});
code.replace(metadata[QString("what")].toString(),
required.join(separator));
}
return code;
}
QStringList AWPatternFunctions::findBars(const QString code,
const QStringList keys)
{
qCDebug(LOG_AW) << "Looking for bars in code" << code << "using list"
<< keys;
QStringList selectedKeys;
for (auto key : keys)
if ((key.startsWith(QString("bar")))
&& (code.contains(QString("$%1").arg(key)))) {
qCInfo(LOG_AW) << "Found bar" << key;
selectedKeys.append(key);
}
if (selectedKeys.isEmpty())
qCWarning(LOG_AW) << "No bars found";
return selectedKeys;
}
QStringList AWPatternFunctions::findKeys(const QString code,
const QStringList keys)
{
qCDebug(LOG_AW) << "Looking for keys in code" << code << "using list"
<< keys;
QStringList selectedKeys;
for (auto key : keys)
if ((!key.startsWith(QString("bar")))
&& (code.contains(QString("$%1").arg(key)))) {
qCInfo(LOG_AW) << "Found key" << key;
selectedKeys.append(key);
}
if (selectedKeys.isEmpty())
qCWarning(LOG_AW) << "No keys found";
return selectedKeys;
}
QStringList AWPatternFunctions::findLambdas(const QString code)
{
qCDebug(LOG_AW) << "Looking for lambdas in code" << code;
QStringList selectedKeys;
// match the following construction ${{some code here}}
QRegularExpression lambdaRegexp(QString("\\$\\{\\{(?<body>.*?)\\}\\}"));
lambdaRegexp.setPatternOptions(
QRegularExpression::DotMatchesEverythingOption);
QRegularExpressionMatchIterator it = lambdaRegexp.globalMatch(code);
while (it.hasNext()) {
QRegularExpressionMatch match = it.next();
QString lambda = match.captured(QString("body"));
// append
qCInfo(LOG_AW) << "Found lambda" << lambda;
selectedKeys.append(lambda);
}
if (selectedKeys.isEmpty())
qCWarning(LOG_AW) << "No lambdas found";
return selectedKeys;
}

View 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 AWPATTERNFUNCTIONS_H
#define AWPATTERNFUNCTIONS_H
#include <QString>
#include <QVariant>
class AWKeysAggregator;
namespace AWPatternFunctions
{
// insert methods
QString expandLambdas(QString code, AWKeysAggregator *aggregator,
const QVariantHash &metadata,
const QStringList &usedKeys);
QString expandTemplates(QString code);
QVariantList findFunctionCalls(const QString function, const QString code);
QString insertAllKeys(QString code, const QStringList keys);
QString insertKeyCount(QString code, const QStringList keys);
QString insertKeyNames(QString code, const QStringList keys);
QString insertKeys(QString code, const QStringList keys);
// find methods
QStringList findBars(const QString code, const QStringList keys);
QStringList findKeys(const QString code, const QStringList keys);
QStringList findLambdas(const QString code);
};
#endif /* AWPATTERNFUNCTIONS_H */

View File

@ -0,0 +1,151 @@
/***************************************************************************
* 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;
}

View File

@ -0,0 +1,59 @@
/***************************************************************************
* 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 AWSCRIPTFORMATTER_H
#define AWSCRIPTFORMATTER_H
#include "awabstractformatter.h"
class AWScriptFormatter : public AWAbstractFormatter
{
Q_OBJECT
Q_PROPERTY(bool appendCode READ appendCode WRITE setAppendCode)
Q_PROPERTY(QString code READ code WRITE setCode)
Q_PROPERTY(bool hasReturn READ hasReturn WRITE setHasReturn)
Q_PROPERTY(QString program READ program)
public:
explicit AWScriptFormatter(QObject *parent, const QString filename,
const QString section);
explicit AWScriptFormatter(QObject *parent, const bool appendCode,
const QString code, const bool hasReturn);
virtual ~AWScriptFormatter();
QString convert(const QVariant &value) const;
// properties
bool appendCode() const;
QString code() const;
bool hasReturn() const;
QString program() const;
void setAppendCode(const bool _appendCode);
void setCode(const QString _code);
void setHasReturn(const bool _hasReturn);
private:
void init(const QString filename, const QString section);
void initProgram();
// properties
bool m_appendCode;
QString m_code;
bool m_hasReturn;
QString m_program;
};
#endif /* AWSCRIPTFORMATTER_H */

View 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 "awupdatehelper.h"
#include <KI18n/KLocalizedString>
#include <QtConcurrent/QtConcurrent>
#include <QDesktopServices>
#include <QJsonDocument>
#include <QJsonParseError>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QSettings>
#include "awdebug.h"
AWUpdateHelper::AWUpdateHelper(QObject *parent)
: QObject(parent)
{
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
m_foundVersion = QVersionNumber::fromString(VERSION);
m_genericConfig = QString("%1/awesomewidgets/general.ini")
.arg(QStandardPaths::writableLocation(
QStandardPaths::GenericDataLocation));
}
AWUpdateHelper::~AWUpdateHelper()
{
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
}
void AWUpdateHelper::checkUpdates(const bool showAnyway)
{
qCDebug(LOG_AW) << "Show anyway" << showAnyway;
// showAnyway options requires to show message if no updates found on direct
// request. In case of automatic check no message will be shown
QNetworkAccessManager *manager = new QNetworkAccessManager(nullptr);
connect(manager, &QNetworkAccessManager::finished,
[showAnyway, this](QNetworkReply *reply) {
return versionReplyRecieved(reply, showAnyway);
});
manager->get(QNetworkRequest(QUrl(VERSION_API)));
}
bool AWUpdateHelper::checkVersion()
{
QSettings settings(m_genericConfig, QSettings::IniFormat);
QVersionNumber version = QVersionNumber::fromString(
settings.value(QString("Version"), QString(VERSION)).toString());
// update version
settings.setValue(QString("Version"), QString(VERSION));
settings.sync();
qCInfo(LOG_AW) << "Found version" << version << "actual one is"
<< m_foundVersion;
if ((version != m_foundVersion) && (!QString(CHANGELOG).isEmpty())) {
genMessageBox(i18n("Changelog of %1", QString(VERSION)),
QString(CHANGELOG).replace(QChar('@'), QChar('\n')),
QMessageBox::Ok)
->open();
return true;
} else if (version != m_foundVersion) {
qCWarning(LOG_AW) << "No changelog information provided";
return true;
} else {
qCInfo(LOG_AW) << "No need to update version";
}
return false;
}
void AWUpdateHelper::showInfo(const QVersionNumber version)
{
qCDebug(LOG_AW) << "Version" << version;
QString text
= i18n("You are using the actual version %1", version.toString());
if (!QString(COMMIT_SHA).isEmpty())
text += QString(" (%1)").arg(QString(COMMIT_SHA));
return genMessageBox(i18n("No new version found"), text, QMessageBox::Ok)
->open();
}
void AWUpdateHelper::showUpdates(const QVersionNumber version)
{
qCDebug(LOG_AW) << "Version" << version;
QString text;
text += i18n("Current version : %1", QString(VERSION));
text += QString(COMMIT_SHA).isEmpty()
? QString("\n")
: QString(" (%1)\n").arg(QString(COMMIT_SHA));
text += i18n("New version : %1", version.toString()) + QString("\n\n");
text += i18n("Click \"Ok\" to download");
genMessageBox(i18n("There are updates"), text,
QMessageBox::Ok | QMessageBox::Cancel)
->open(this, SLOT(userReplyOnUpdates(QAbstractButton *)));
}
void AWUpdateHelper::userReplyOnUpdates(QAbstractButton *button)
{
QMessageBox::ButtonRole ret
= static_cast<QMessageBox *>(sender())->buttonRole(button);
qCInfo(LOG_AW) << "User select" << ret;
switch (ret) {
case QMessageBox::AcceptRole:
QDesktopServices::openUrl(QString(RELEASES)
+ m_foundVersion.toString());
break;
case QMessageBox::RejectRole:
default:
break;
}
}
void AWUpdateHelper::versionReplyRecieved(QNetworkReply *reply,
const bool showAnyway)
{
qCDebug(LOG_AW) << "Return code" << reply->error() << "with message"
<< reply->errorString() << "and show anyway" << showAnyway;
QJsonParseError error;
QJsonDocument jsonDoc = QJsonDocument::fromJson(reply->readAll(), &error);
if ((reply->error() != QNetworkReply::NoError)
|| (error.error != QJsonParseError::NoError)) {
qCWarning(LOG_AW) << "Parse error" << error.errorString();
return;
}
reply->deleteLater();
// convert to map
QVariantMap firstRelease = jsonDoc.toVariant().toList().first().toMap();
QString version = firstRelease[QString("tag_name")].toString();
version.remove(QString("V."));
m_foundVersion = QVersionNumber::fromString(version);
qCInfo(LOG_AW) << "Update found version to" << m_foundVersion;
QVersionNumber oldVersion = QVersionNumber::fromString(VERSION);
if (oldVersion < m_foundVersion)
return showUpdates(m_foundVersion);
else if (showAnyway)
return showInfo(m_foundVersion);
}
// additional method which is used to show message box which does not block UI
QMessageBox *
AWUpdateHelper::genMessageBox(const QString title, const QString body,
const QMessageBox::StandardButtons buttons)
{
qCDebug(LOG_AW) << "Construct message box with title" << title << "and body"
<< body;
QMessageBox *msgBox = new QMessageBox(nullptr);
msgBox->setAttribute(Qt::WA_DeleteOnClose);
msgBox->setModal(false);
msgBox->setWindowTitle(title);
msgBox->setText(body);
msgBox->setStandardButtons(buttons);
msgBox->setIcon(QMessageBox::Information);
return msgBox;
}

View File

@ -0,0 +1,53 @@
/***************************************************************************
* 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 AWUPDATEHELPER_H
#define AWUPDATEHELPER_H
#include <QMessageBox>
#include <QObject>
#include <QVersionNumber>
class QNetworkReply;
class AWUpdateHelper : public QObject
{
Q_OBJECT
public:
explicit AWUpdateHelper(QObject *parent = nullptr);
virtual ~AWUpdateHelper();
void checkUpdates(const bool showAnyway = false);
bool checkVersion();
private slots:
void showInfo(const QVersionNumber version);
void showUpdates(const QVersionNumber version);
void userReplyOnUpdates(QAbstractButton *button);
void versionReplyRecieved(QNetworkReply *reply, const bool showAnyway);
private:
QMessageBox *genMessageBox(const QString title, const QString body,
const QMessageBox::StandardButtons buttons);
QVersionNumber m_foundVersion;
QString m_genericConfig;
};
#endif /* AWUPDATEHELPER_H */

View File

@ -13,6 +13,8 @@ include_directories(
file(GLOB SUBPROJECT_SOURCE *.cpp ${PROJECT_TRDPARTY_DIR}/qreplytimeout/*.cpp ${CMAKE_SOURCE_DIR}/*.cpp)
file(GLOB SUBPROJECT_HEADER *.h ${PROJECT_TRDPARTY_DIR}/qreplytimeout/*.h)
file(GLOB SUBPROJECT_UI *.ui)
file(GLOB SUBPROJECT_INI *.ini)
set(SUBPROJECT_CONFIGS ${CMAKE_CURRENT_SOURCE_DIR}/configs)
set(SUBPROJECT_GRAPHITEMS ${CMAKE_CURRENT_SOURCE_DIR}/desktops)
set(SUBPROJECT_QUOTES ${CMAKE_CURRENT_SOURCE_DIR}/quotes)
set(SUBPROJECT_SCRIPTS ${CMAKE_CURRENT_SOURCE_DIR}/scripts)
@ -29,9 +31,11 @@ add_library(${SUBPROJECT} STATIC ${SUBPROJECT_SOURCE} ${SUBPROJECT_HEADER} ${SUB
target_link_libraries(${SUBPROJECT} ${Qt_LIBRARIES} ${Kf5_LIBRARIES})
# install
install(DIRECTORY ${SUBPROJECT_CONFIGS} DESTINATION ${DATA_INSTALL_DIR}/${PROJECT_NAME})
install(DIRECTORY ${SUBPROJECT_GRAPHITEMS} DESTINATION ${DATA_INSTALL_DIR}/${PROJECT_NAME})
install(DIRECTORY ${SUBPROJECT_QUOTES} DESTINATION ${DATA_INSTALL_DIR}/${PROJECT_NAME})
install(DIRECTORY ${SUBPROJECT_SCRIPTS} DESTINATION ${DATA_INSTALL_DIR}/${PROJECT_NAME})
install(DIRECTORY ${SUBPROJECT_UPGRADE} DESTINATION ${DATA_INSTALL_DIR}/${PROJECT_NAME})
install(DIRECTORY ${SUBPROJECT_WEATHER} DESTINATION ${DATA_INSTALL_DIR}/${PROJECT_NAME})
install(FILES ${SUBPROJECT_INI} DESTINATION ${CONFIG_INSTALL_DIR})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT_WEATHER_JSON} DESTINATION ${DATA_INSTALL_DIR}/${PROJECT_NAME}/weather)

View File

@ -23,7 +23,7 @@
#include <QTime>
#include "awdebug.h"
#include "version.h"
#include "abstractextitemaggregator.h"
AbstractExtItem::AbstractExtItem(QWidget *parent, const QString desktopName,
@ -33,8 +33,9 @@ AbstractExtItem::AbstractExtItem(QWidget *parent, const QString desktopName,
, m_dirs(directories)
{
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
qCDebug(LOG_LIB) << "Desktop name" << desktopName;
qCDebug(LOG_LIB) << "Directories" << directories;
qCDebug(LOG_LIB) << "Desktop name" << desktopName << "directories"
<< directories;
m_name = m_fileName;
}
@ -46,10 +47,13 @@ AbstractExtItem::~AbstractExtItem()
}
template <class T> T *AbstractExtItem::copy(const QString, const int)
void AbstractExtItem::copyDefaults(AbstractExtItem *_other) const
{
// an analog of pure virtual method
return new T();
_other->setActive(m_active);
_other->setApiVersion(m_apiVersion);
_other->setComment(m_comment);
_other->setInterval(m_interval);
_other->setName(m_name);
}
@ -193,14 +197,14 @@ void AbstractExtItem::readConfiguration()
bool AbstractExtItem::tryDelete() const
{
foreach (QString dir, m_dirs) {
for (auto dir : m_dirs) {
bool status = QFile::remove(QString("%1/%2").arg(dir).arg(m_fileName));
qCInfo(LOG_LIB) << "Remove file"
<< QString("%1/%2").arg(dir).arg(m_fileName) << status;
}
// check if exists
foreach (QString dir, m_dirs)
for (auto dir : m_dirs)
if (QFile::exists(QString("%1/%2").arg(dir).arg(m_fileName)))
return false;
return true;

View File

@ -40,7 +40,9 @@ public:
const QString desktopName = QString(),
const QStringList directories = QStringList());
virtual ~AbstractExtItem();
template <class T> T *copy(const QString, const int);
virtual AbstractExtItem *copy(const QString _fileName, const int _number)
= 0;
void copyDefaults(AbstractExtItem *_other) const;
// get methods
int apiVersion() const;
QString comment() const;

View File

@ -91,10 +91,8 @@ void AbstractExtItemAggregator::setConfigArgs(const QVariant _configArgs)
}
void AbstractExtItemAggregator::editItemActivated(QListWidgetItem *item)
void AbstractExtItemAggregator::editItemActivated(QListWidgetItem *)
{
Q_UNUSED(item)
return editItem();
}

View File

@ -48,7 +48,7 @@ public:
void setConfigArgs(const QVariant _configArgs);
private slots:
void editItemActivated(QListWidgetItem *item);
void editItemActivated(QListWidgetItem *);
void editItemButtonPressed(QAbstractButton *button);
private:

View File

@ -1,139 +1,113 @@
{
"__url": "http://openweathermap.org/weather-conditions",
"__url": "https://developer.yahoo.com/weather/documentation.html",
"image": {
"__comment": "should be described as html image with full path inside",
"default": "",
"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\">",
"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\">",
"3": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/3.gif\">",
"4": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/4.gif\">",
"5": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/5.gif\">",
"6": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/6.gif\">",
"7": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/7.gif\">",
"8": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/8.gif\">",
"9": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/9.gif\">",
"10": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/10.gif\">",
"11": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/11.gif\">",
"12": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/12.gif\">",
"13": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/13.gif\">",
"14": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/14.gif\">",
"15": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/15.gif\">",
"16": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/16.gif\">",
"17": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/17.gif\">",
"18": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/18.gif\">",
"19": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/19.gif\">",
"20": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/20.gif\">",
"21": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/21.gif\">",
"22": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/22.gif\">",
"23": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/23.gif\">",
"24": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/24.gif\">",
"25": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/25.gif\">",
"26": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/26.gif\">",
"27": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/27.gif\">",
"28": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/28.gif\">",
"29": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/29.gif\">",
"30": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/30.gif\">",
"31": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/31.gif\">",
"32": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/32.gif\">",
"33": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/33.gif\">",
"34": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/34.gif\">",
"35": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/35.gif\">",
"36": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/36.gif\">",
"37": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/37.gif\">",
"38": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/38.gif\">",
"39": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/39.gif\">",
"40": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/40.gif\">",
"41": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/41.gif\">",
"42": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/42.gif\">",
"43": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/43.gif\">",
"44": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/44.gif\">",
"45": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/45.gif\">",
"46": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/46.gif\">",
"47": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/47.gif\">",
"3200": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/3200.gif\">"
},
"text": {
"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"
"0": "\u2604",
"1": "\u2604",
"2": "\u2604",
"3": "\u26C8",
"4": "\u26C8",
"5": "\u2614",
"6": "\u2614",
"7": "\u2614",
"8": "\u2614",
"9": "\u2614",
"10": "\u2614",
"11": "\u2614",
"12": "\u2614",
"13": "\u26C4",
"14": "\u26C7",
"15": "\u26C7",
"16": "\u2614",
"17": "\u2614",
"18": "\u2614",
"19": "\u26C5",
"20": "\u26C5",
"21": "\u26C5",
"22": "\u26C5",
"23": "\u26C5",
"24": "\u26C5",
"25": "\u26C5",
"26": "\u2601",
"27": "\u2601",
"28": "\u2601",
"29": "\u2601",
"30": "\u2601",
"31": "\u263D",
"32": "\u2600",
"33": "\u263D",
"34": "\u2600",
"35": "\u2614",
"36": "\u2600",
"37": "\u26C8",
"38": "\u26C8",
"39": "\u26C8",
"40": "\u26C7",
"41": "\u26C7",
"42": "\u26C7",
"43": "\u26C7",
"44": "\u2601",
"45": "\u26C8",
"46": "\u26C7",
"47": "\u26C8"
}
}

View File

@ -0,0 +1,134 @@
[desktops]
cpu-bar.desktop\Comment=Example cpu bar
cpu-bar.desktop\Encoding=UTF-8
cpu-bar.desktop\Name=cpu-bar.desktop
cpu-bar.desktop\X-AW-Active=true
cpu-bar.desktop\X-AW-ActiveColor="color://0,0,255,255"
cpu-bar.desktop\X-AW-ApiVersion=5
cpu-bar.desktop\X-AW-Count=100
cpu-bar.desktop\X-AW-Custom=false
cpu-bar.desktop\X-AW-Direction=LeftToRight
cpu-bar.desktop\X-AW-Height=10
cpu-bar.desktop\X-AW-InactiveColor="color://0,0,0,255"
cpu-bar.desktop\X-AW-Interval=1
cpu-bar.desktop\X-AW-Max=@Variant(\0\0\0\x87\x42\xc8\0\0)
cpu-bar.desktop\X-AW-Min=@Variant(\0\0\0\x87\0\0\0\0)
cpu-bar.desktop\X-AW-Number=7
cpu-bar.desktop\X-AW-Type=Horizontal
cpu-bar.desktop\X-AW-Value=cpu
cpu-bar.desktop\X-AW-Width=200
down-graph.desktop\Comment=Example download speed graph
down-graph.desktop\Encoding=UTF-8
down-graph.desktop\Name=down-graph.desktop
down-graph.desktop\X-AW-Active=true
down-graph.desktop\X-AW-ActiveColor="color://0,170,0,255"
down-graph.desktop\X-AW-ApiVersion=5
down-graph.desktop\X-AW-Count=100
down-graph.desktop\X-AW-Custom=true
down-graph.desktop\X-AW-Direction=LeftToRight
down-graph.desktop\X-AW-Height=25
down-graph.desktop\X-AW-InactiveColor="color://0,0,0,255"
down-graph.desktop\X-AW-Interval=1
down-graph.desktop\X-AW-Max=100.0
down-graph.desktop\X-AW-Min=@Variant(\0\0\0\x87\0\0\0\0)
down-graph.desktop\X-AW-Number=8
down-graph.desktop\X-AW-Type=Bars
down-graph.desktop\X-AW-Value=$downkb
down-graph.desktop\X-AW-Width=300
ram-bar.desktop\Comment=Example RAM bar
ram-bar.desktop\Encoding=UTF-8
ram-bar.desktop\Name=ram-bar.desktop
ram-bar.desktop\X-AW-Active=true
ram-bar.desktop\X-AW-ActiveColor="color://0,0,255,255"
ram-bar.desktop\X-AW-ApiVersion=5
ram-bar.desktop\X-AW-Count=100
ram-bar.desktop\X-AW-Custom=false
ram-bar.desktop\X-AW-Direction=LeftToRight
ram-bar.desktop\X-AW-Height=10
ram-bar.desktop\X-AW-InactiveColor="color://0,0,0,255"
ram-bar.desktop\X-AW-Interval=1
ram-bar.desktop\X-AW-Max=@Variant(\0\0\0\x87\x42\xc8\0\0)
ram-bar.desktop\X-AW-Min=@Variant(\0\0\0\x87\0\0\0\0)
ram-bar.desktop\X-AW-Number=5
ram-bar.desktop\X-AW-Type=Horizontal
ram-bar.desktop\X-AW-Value=mem
ram-bar.desktop\X-AW-Width=200
swap-bar.desktop\Comment=Example swap bar
swap-bar.desktop\Encoding=UTF-8
swap-bar.desktop\Name=swap-bar.desktop
swap-bar.desktop\X-AW-Active=true
swap-bar.desktop\X-AW-ActiveColor="color://0,0,255,255"
swap-bar.desktop\X-AW-ApiVersion=5
swap-bar.desktop\X-AW-Count=100
swap-bar.desktop\X-AW-Custom=false
swap-bar.desktop\X-AW-Direction=LeftToRight
swap-bar.desktop\X-AW-Height=10
swap-bar.desktop\X-AW-InactiveColor="color://0,0,0,255"
swap-bar.desktop\X-AW-Interval=1
swap-bar.desktop\X-AW-Max=@Variant(\0\0\0\x87\x42\xc8\0\0)
swap-bar.desktop\X-AW-Min=@Variant(\0\0\0\x87\0\0\0\0)
swap-bar.desktop\X-AW-Number=6
swap-bar.desktop\X-AW-Type=Horizontal
swap-bar.desktop\X-AW-Value=swap
swap-bar.desktop\X-AW-Width=200
up-graph.desktop\Comment=Example upload speed graph
up-graph.desktop\Encoding=UTF-8
up-graph.desktop\Name=upload-graph.desktop
up-graph.desktop\X-AW-Active=true
up-graph.desktop\X-AW-ActiveColor="color://0,170,0,255"
up-graph.desktop\X-AW-ApiVersion=5
up-graph.desktop\X-AW-Count=100
up-graph.desktop\X-AW-Custom=true
up-graph.desktop\X-AW-Direction=LeftToRight
up-graph.desktop\X-AW-Height=25
up-graph.desktop\X-AW-InactiveColor="color://0,0,0,255"
up-graph.desktop\X-AW-Interval=1
up-graph.desktop\X-AW-Max=100.0
up-graph.desktop\X-AW-Min=@Variant(\0\0\0\x87\0\0\0\0)
up-graph.desktop\X-AW-Number=9
up-graph.desktop\X-AW-Type=Bars
up-graph.desktop\X-AW-Value=$cpu
up-graph.desktop\X-AW-Width=300
[plasmoid]
acOffline=( )
acOnline=(*)
background=false
batInTooltipColor=#880000
batTooltip=true
batTooltipColor=#008800
checkUpdates=true
cpuTooltip=true
cpuTooltipColor=#ff0000
cpuclTooltip=true
cpuclTooltipColor=#00ff00
customTime=$hh:$mm
customUptime=$ddd $hhh $mmm
downkbTooltip=true
downkbTooltipColor=#00ffff
fontColor=#ffffff
fontFamily=Terminus
fontSize=12
fontStyle=normal
fontWeight=normal
height=400
interval=1000
memTooltip=true
memTooltipColor=#0000ff
notify=true
optimize=true
queueLimit=0
swapTooltip=true
swapTooltipColor=#ffff00
tempUnits=Celsius
text="<body bgcolor=\"#000000\">\n<p align=\"justify\">Uptime: $cuptime<br>\nRAM: &nbsp;$mem&nbsp;&nbsp;$bar5<br>\nSwap: $swap&nbsp;&nbsp;$bar6<br>\nCPU: &nbsp;$cpu&nbsp;&nbsp;$bar7<br>\nCPU Temp: $temp0&deg;C<br>\nDown: $down$downunits&nbsp;&nbsp;&nbsp;&nbsp;$downtotal<br>\n$bar8<br>\nUp:&nbsp;&nbsp; $up$upunits&nbsp;&nbsp;&nbsp;&nbsp;$uptotal<br>\n$bar9<br></p>\n</body>\n"
textAlign=center
tooltipBackground=#ffffff
tooltipNumber=100
translateStrings=true
upkbTooltipColor=#ff00ff
useTooltipBackground=true
width=300
wrapNewLines=false
wrapText=false

View File

@ -0,0 +1,41 @@
[plasmoid]
acOffline=( )
acOnline=(*)
background=true
batInTooltipColor=#880000
batTooltip=true
batTooltipColor=#008800
checkUpdates=true
cpuTooltip=true
cpuTooltipColor=#ff0000
cpuclTooltip=true
cpuclTooltipColor=#00ff00
customTime=$hh:$mm
customUptime="$dd,$hh,$mm"
downkbTooltip=true
downkbTooltipColor=#00ffff
fontColor=#000000
fontFamily=Terminus
fontSize=12
fontStyle=normal
fontWeight=normal
height=0
interval=1000
memTooltip=true
memTooltipColor=#0000ff
notify=true
optimize=true
queueLimit=0
swapTooltip=true
swapTooltipColor=#ffff00
tempUnits=Celsius
text=[cpu: $cpu%] [mem: $mem%] [swap: $swap%] [$netdev: $down/$upKB/s]
textAlign=center
tooltipBackground=#ffffff
tooltipNumber=100
translateStrings=true
upkbTooltipColor=#ff00ff
useTooltipBackground=true
width=0
wrapNewLines=false
wrapText=false

View File

@ -3,11 +3,14 @@ Encoding=UTF-8
Name=bar3
Comment=Simple bat bar
X-AW-Value=bat
X-AW-ActiveColor="0,0,0,255"
X-AW-InactiveColor="255,255,255,255"
X-AW-Custom=false
X-AW-Max=100.0
X-AW-Min=0.0
X-AW-ActiveColor="color://0,0,0,255"
X-AW-InactiveColor="color://255,255,255,255"
X-AW-Type=Horizontal
X-AW-Direction=LeftToRight
X-AW-Height=25
X-AW-Width=100
X-AW-ApiVersion=3
X-AW-ApiVersion=5
X-AW-Number=3

View File

@ -3,11 +3,14 @@ Encoding=UTF-8
Name=bar0
Comment=Simple cpu bar
X-AW-Value=cpu
X-AW-ActiveColor="0,0,0,255"
X-AW-InactiveColor="255,255,255,255"
X-AW-Custom=false
X-AW-Max=100.0
X-AW-Min=0.0
X-AW-ActiveColor="color://0,0,0,255"
X-AW-InactiveColor="color://255,255,255,255"
X-AW-Type=Horizontal
X-AW-Direction=LeftToRight
X-AW-Height=25
X-AW-Width=100
X-AW-ApiVersion=3
X-AW-ApiVersion=5
X-AW-Number=0

View File

@ -3,11 +3,14 @@ Encoding=UTF-8
Name=bar1
Comment=Simple mem bar
X-AW-Value=mem
X-AW-ActiveColor="0,0,0,255"
X-AW-InactiveColor="255,255,255,255"
X-AW-Custom=false
X-AW-Max=100.0
X-AW-Min=0.0
X-AW-ActiveColor="color://0,0,0,255"
X-AW-InactiveColor="color://255,255,255,255"
X-AW-Type=Horizontal
X-AW-Direction=LeftToRight
X-AW-Height=25
X-AW-Width=100
X-AW-ApiVersion=3
X-AW-ApiVersion=5
X-AW-Number=1

View File

@ -3,11 +3,14 @@ Encoding=UTF-8
Name=bar2
Comment=Simple swap bar
X-AW-Value=swap
X-AW-ActiveColor="0,0,0,255"
X-AW-InactiveColor="255,255,255,255"
X-AW-Custom=false
X-AW-Max=100.0
X-AW-Min=0.0
X-AW-ActiveColor="color://0,0,0,255"
X-AW-InactiveColor="color://255,255,255,255"
X-AW-Type=Horizontal
X-AW-Direction=LeftToRight
X-AW-Height=25
X-AW-Width=100
X-AW-ApiVersion=3
X-AW-ApiVersion=5
X-AW-Number=2

View File

@ -37,8 +37,9 @@ public:
{
qSetMessagePattern(LOG_FORMAT);
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
foreach (const QString metadata, getBuildData())
for (auto metadata : getBuildData())
qCDebug(LOG_LIB) << metadata;
qCDebug(LOG_LIB) << "Type" << type;
initItems();
@ -61,13 +62,13 @@ public:
qCInfo(LOG_LIB) << "Dialog returns" << ret;
};
T *itemByTag(const QString _tag) const
T *itemByTag(const QString _tag, const QString _type) const
{
qCDebug(LOG_LIB) << "Tag" << _tag;
qCDebug(LOG_LIB) << "Tag" << _tag << "with used type" << _type;
T *found = nullptr;
foreach (T *item, m_items) {
if (item->tag() != _tag)
for (auto item : m_items) {
if (item->tag(_type) != _tag)
continue;
found = item;
break;
@ -83,7 +84,7 @@ public:
qCDebug(LOG_LIB) << "Number" << _number;
T *found = nullptr;
foreach (T *item, m_items) {
for (auto item : m_items) {
if (item->number() != _number)
continue;
found = item;
@ -102,7 +103,7 @@ public:
return nullptr;
T *found = nullptr;
foreach (T *item, m_items) {
for (auto item : m_items) {
if (item->fileName() != widgetItem->text())
continue;
found = item;
@ -120,7 +121,7 @@ public:
int uniqNumber() const
{
QList<int> tagList;
foreach (T *item, m_items)
for (auto item : m_items)
tagList.append(item->number());
int number = 0;
while (tagList.contains(number))
@ -152,9 +153,9 @@ private:
QStandardPaths::LocateDirectory);
QStringList names;
QList<T *> items;
foreach (QString dir, dirs) {
for (auto dir : dirs) {
QStringList files = QDir(dir).entryList(QDir::Files, QDir::Name);
foreach (QString file, files) {
for (auto file : files) {
if ((!file.endsWith(QString(".desktop")))
|| (names.contains(file)))
continue;
@ -177,7 +178,7 @@ private:
m_activeItems.clear();
m_items = getItems();
foreach (T *item, m_items) {
for (auto item : m_items) {
if (!item->isActive())
continue;
m_activeItems.append(item);
@ -187,7 +188,7 @@ private:
void repaint()
{
widgetDialog->clear();
foreach (T *_item, m_items) {
for (auto _item : m_items) {
QListWidgetItem *item
= new QListWidgetItem(_item->fileName(), widgetDialog);
QStringList tooltip;
@ -210,7 +211,7 @@ private:
return;
}
T *newItem = source->copy(fileName, number);
T *newItem = static_cast<T *>(source->copy(fileName, number));
if (newItem->showConfiguration(configArgs()) == 1) {
initItems();
repaint();

View File

@ -26,11 +26,11 @@
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QSettings>
#include <QUrlQuery>
#include <qreplytimeout/qreplytimeout.h>
#include "awdebug.h"
#include "version.h"
ExtQuotes::ExtQuotes(QWidget *parent, const QString quotesName,
@ -56,8 +56,8 @@ ExtQuotes::ExtQuotes(QWidget *parent, const QString quotesName,
// HACK declare as child of nullptr to avoid crash with plasmawindowed
// in the destructor
manager = new QNetworkAccessManager(nullptr);
connect(manager, SIGNAL(finished(QNetworkReply *)), this,
m_manager = new QNetworkAccessManager(nullptr);
connect(m_manager, SIGNAL(finished(QNetworkReply *)), this,
SLOT(quotesReplyReceived(QNetworkReply *)));
}
@ -66,10 +66,10 @@ ExtQuotes::~ExtQuotes()
{
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
disconnect(manager, SIGNAL(finished(QNetworkReply *)), this,
disconnect(m_manager, SIGNAL(finished(QNetworkReply *)), this,
SLOT(quotesReplyReceived(QNetworkReply *)));
manager->deleteLater();
m_manager->deleteLater();
delete ui;
}
@ -81,11 +81,7 @@ ExtQuotes *ExtQuotes::copy(const QString _fileName, const int _number)
ExtQuotes *item = new ExtQuotes(static_cast<QWidget *>(parent()), _fileName,
directories());
item->setActive(isActive());
item->setApiVersion(apiVersion());
item->setComment(comment());
item->setInterval(interval());
item->setName(name());
copyDefaults(item);
item->setNumber(_number);
item->setTicker(ticker());
@ -138,6 +134,16 @@ void ExtQuotes::readConfiguration()
setApiVersion(AWEQAPI);
writeConfiguration();
}
// 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(m_ticker));
m_url.setQuery(params);
}
@ -149,8 +155,8 @@ QVariantHash ExtQuotes::run()
if (times == 1) {
qCInfo(LOG_LIB) << "Send request";
isRunning = true;
QNetworkReply *reply = manager->get(QNetworkRequest(QUrl(url())));
new QReplyTimeout(reply, 1000);
QNetworkReply *reply = m_manager->get(QNetworkRequest(m_url));
new QReplyTimeout(reply, REQUEST_TIMEOUT);
}
// update value
@ -208,8 +214,8 @@ void ExtQuotes::writeConfiguration() const
void ExtQuotes::quotesReplyReceived(QNetworkReply *reply)
{
qCDebug(LOG_LIB) << "Return code" << reply->error();
qCDebug(LOG_LIB) << "Reply error message" << reply->errorString();
qCDebug(LOG_LIB) << "Return code" << reply->error() << "with message"
<< reply->errorString();
isRunning = false;
QJsonParseError error;
@ -275,13 +281,3 @@ get quotes for the instrument. Refer to <a href=\"http://finance.yahoo.com/\">\
ui->checkBox_active->setText(i18n("Active"));
ui->label_interval->setText(i18n("Interval"));
}
QString ExtQuotes::url() const
{
QString apiUrl = QString(YAHOO_URL);
apiUrl.replace(QString("$TICKER"), m_ticker);
qCInfo(LOG_LIB) << "API url" << apiUrl;
return apiUrl;
}

View File

@ -22,11 +22,9 @@
#include "abstractextitem.h"
#define YAHOO_URL \
"https://query.yahooapis.com/v1/public/yql?q=select * from " \
"yahoo.finance.quotes where " \
"symbol=\"$TICKER\"&env=store://datatables.org/" \
"alltableswithkeys&format=json"
#define YAHOO_QUOTES_URL "https://query.yahooapis.com/v1/public/yql"
#define YAHOO_QUOTES_QUERY \
"select * from yahoo.finance.quotes where symbol='%1'"
namespace Ui
@ -61,11 +59,11 @@ private slots:
void quotesReplyReceived(QNetworkReply *reply);
private:
QNetworkAccessManager *manager;
QNetworkAccessManager *m_manager;
QUrl m_url;
bool isRunning = false;
Ui::ExtQuotes *ui;
void translate();
QString url() const;
// properties
QString m_ticker = QString("EURUSD=X");
// values

View File

@ -28,7 +28,6 @@
#include <QTextCodec>
#include "awdebug.h"
#include "version.h"
ExtScript::ExtScript(QWidget *parent, const QString scriptName,
@ -64,17 +63,12 @@ ExtScript::~ExtScript()
ExtScript *ExtScript::copy(const QString _fileName, const int _number)
{
qCDebug(LOG_LIB) << "File" << _fileName;
qCDebug(LOG_LIB) << "Number" << _number;
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
ExtScript *item = new ExtScript(static_cast<QWidget *>(parent()), _fileName,
directories());
item->setActive(isActive());
item->setApiVersion(apiVersion());
item->setComment(comment());
copyDefaults(item);
item->setExecutable(executable());
item->setInterval(interval());
item->setName(name());
item->setNumber(_number);
item->setPrefix(prefix());
item->setRedirect(redirect());
@ -117,17 +111,16 @@ QString ExtScript::strRedirect() const
{
QString value;
switch (m_redirect) {
case stdout2stderr:
case Redirect::stdout2stderr:
value = QString("stdout2stderr");
break;
case stderr2stdout:
case Redirect::stderr2stdout:
value = QString("stderr2stdout");
break;
case swap:
case Redirect::swap:
value = QString("swap");
break;
case nothing:
default:
case Redirect::nothing:
value = QString("nothing");
break;
}
@ -163,7 +156,7 @@ void ExtScript::setPrefix(const QString _prefix)
void ExtScript::setRedirect(const Redirect _redirect)
{
qCDebug(LOG_LIB) << "Redirect" << _redirect;
qCDebug(LOG_LIB) << "Redirect" << static_cast<int>(_redirect);
m_redirect = _redirect;
}
@ -174,13 +167,13 @@ void ExtScript::setStrRedirect(const QString _redirect)
qCDebug(LOG_LIB) << "Redirect" << _redirect;
if (_redirect == QString("stdout2sdterr"))
m_redirect = stdout2stderr;
m_redirect = Redirect::stdout2stderr;
else if (_redirect == QString("stderr2sdtout"))
m_redirect = stderr2stdout;
m_redirect = Redirect::stderr2stdout;
else if (_redirect == QString("swap"))
m_redirect = swap;
m_redirect = Redirect::swap;
else
m_redirect = nothing;
m_redirect = Redirect::nothing;
}
@ -188,7 +181,7 @@ QString ExtScript::applyFilters(QString _value) const
{
qCDebug(LOG_LIB) << "Value" << _value;
foreach (QString filt, m_filters) {
for (auto filt : m_filters) {
qCInfo(LOG_LIB) << "Found filter" << filt;
QVariantMap filter = jsonFilters[filt].toMap();
if (filter.isEmpty()) {
@ -196,7 +189,7 @@ QString ExtScript::applyFilters(QString _value) const
<< "in the json";
continue;
}
foreach (QString f, filter.keys())
for (auto f : filter.keys())
_value.replace(f, filter[f].toString());
}
@ -206,8 +199,7 @@ QString ExtScript::applyFilters(QString _value) const
void ExtScript::updateFilter(const QString _filter, const bool _add)
{
qCDebug(LOG_LIB) << "Filter" << _filter;
qCDebug(LOG_LIB) << "Should be added" << _add;
qCDebug(LOG_LIB) << "Should be added filters" << _add << "from" << _filter;
if (_add) {
if (m_filters.contains(_filter))
@ -382,16 +374,15 @@ void ExtScript::updateValue()
QString strValue;
switch (m_redirect) {
case stdout2stderr:
case Redirect::stdout2stderr:
break;
case stderr2stdout:
case Redirect::stderr2stdout:
strValue = QString("%1\n%2").arg(qdebug).arg(qoutput);
break;
case swap:
case Redirect::swap:
strValue = qdebug;
break;
case nothing:
default:
case Redirect::nothing:
strValue = qoutput;
break;
}

View File

@ -37,7 +37,7 @@ class ExtScript : public AbstractExtItem
Q_PROPERTY(Redirect redirect READ redirect WRITE setRedirect)
public:
enum Redirect { stdout2stderr = 0, nothing, stderr2stdout, swap };
enum class Redirect { stdout2stderr, nothing, stderr2stdout, swap };
explicit ExtScript(QWidget *parent = nullptr,
const QString scriptName = QString(),
@ -56,7 +56,7 @@ public:
void setExecutable(const QString _executable = QString("/usr/bin/true"));
void setFilters(const QStringList _filters = QStringList());
void setPrefix(const QString _prefix = QString(""));
void setRedirect(const Redirect _redirect = nothing);
void setRedirect(const Redirect _redirect = Redirect::nothing);
void setStrRedirect(const QString _redirect = QString("nothing"));
// filters
QString applyFilters(QString _value) const;
@ -80,9 +80,8 @@ private:
QString m_executable = QString("/usr/bin/true");
QStringList m_filters = QStringList();
QString m_prefix = QString("");
Redirect m_redirect = nothing;
Redirect m_redirect = Redirect::nothing;
// internal properties
Q_PID childProcess = 0;
QVariantMap jsonFilters = QVariantMap();
int times = 0;
QVariantHash value;

View File

@ -26,7 +26,6 @@
#include <QTextCodec>
#include "awdebug.h"
#include "version.h"
ExtUpgrade::ExtUpgrade(QWidget *parent, const QString upgradeName,
@ -60,18 +59,13 @@ ExtUpgrade::~ExtUpgrade()
ExtUpgrade *ExtUpgrade::copy(const QString _fileName, const int _number)
{
qCDebug(LOG_LIB) << "File" << _fileName;
qCDebug(LOG_LIB) << "Number" << _number;
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
ExtUpgrade *item = new ExtUpgrade(static_cast<QWidget *>(parent()),
_fileName, directories());
item->setActive(isActive());
item->setApiVersion(apiVersion());
item->setComment(comment());
copyDefaults(item);
item->setExecutable(executable());
item->setFilter(filter());
item->setInterval(interval());
item->setName(name());
item->setNumber(_number);
item->setNull(null());

View File

@ -27,11 +27,11 @@
#include <QNetworkRequest>
#include <QSettings>
#include <QStandardPaths>
#include <QUrlQuery>
#include <qreplytimeout/qreplytimeout.h>
#include "awdebug.h"
#include "version.h"
ExtWeather::ExtWeather(QWidget *parent, const QString weatherName,
@ -54,8 +54,8 @@ ExtWeather::ExtWeather(QWidget *parent, const QString weatherName,
// HACK declare as child of nullptr to avoid crash with plasmawindowed
// in the destructor
manager = new QNetworkAccessManager(nullptr);
connect(manager, SIGNAL(finished(QNetworkReply *)), this,
m_manager = new QNetworkAccessManager(nullptr);
connect(m_manager, SIGNAL(finished(QNetworkReply *)), this,
SLOT(weatherReplyReceived(QNetworkReply *)));
}
@ -64,29 +64,24 @@ ExtWeather::~ExtWeather()
{
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
disconnect(manager, SIGNAL(finished(QNetworkReply *)), this,
disconnect(m_manager, SIGNAL(finished(QNetworkReply *)), this,
SLOT(weatherReplyReceived(QNetworkReply *)));
manager->deleteLater();
m_manager->deleteLater();
delete ui;
}
ExtWeather *ExtWeather::copy(const QString _fileName, const int _number)
{
qCDebug(LOG_LIB) << "File" << _fileName;
qCDebug(LOG_LIB) << "Number" << _number;
qCDebug(LOG_LIB) << "File" << _fileName << "number" << _number;
ExtWeather *item = new ExtWeather(static_cast<QWidget *>(parent()),
_fileName, directories());
item->setActive(isActive());
item->setApiVersion(apiVersion());
copyDefaults(item);
item->setCity(city());
item->setComment(comment());
item->setCountry(country());
item->setInterval(interval());
item->setImage(image());
item->setName(name());
item->setNumber(_number);
item->setTs(ts());
@ -99,7 +94,7 @@ QString ExtWeather::weatherFromInt(const int _id) const
qCDebug(LOG_LIB) << "Weather ID" << _id;
QVariantMap map
= jsonMap[m_image ? QString("image") : QString("text")].toMap();
= m_jsonMap[m_image ? QString("image") : QString("text")].toMap();
return map.value(QString::number(_id), map[QString("default")]).toString();
}
@ -198,6 +193,16 @@ void ExtWeather::readConfiguration()
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);
}
@ -221,9 +226,9 @@ void ExtWeather::readJsonMap()
qCWarning(LOG_LIB) << "Parse error" << error.errorString();
return;
}
jsonMap = jsonDoc.toVariant().toMap();
m_jsonMap = jsonDoc.toVariant().toMap();
qCInfo(LOG_LIB) << "Weather map" << jsonMap;
qCInfo(LOG_LIB) << "Weather map" << m_jsonMap;
}
@ -235,9 +240,8 @@ QVariantHash ExtWeather::run()
if (times == 1) {
qCInfo(LOG_LIB) << "Send request";
isRunning = true;
QNetworkReply *reply
= manager->get(QNetworkRequest(QUrl(url(m_ts != 0))));
new QReplyTimeout(reply, 1000);
QNetworkReply *reply = m_manager->get(QNetworkRequest(m_url));
new QReplyTimeout(reply, REQUEST_TIMEOUT);
}
// update value
@ -305,8 +309,8 @@ void ExtWeather::writeConfiguration() const
void ExtWeather::weatherReplyReceived(QNetworkReply *reply)
{
qCDebug(LOG_LIB) << "Return code" << reply->error();
qCDebug(LOG_LIB) << "Reply error message" << reply->errorString();
qCDebug(LOG_LIB) << "Return code" << reply->error() << "with message"
<< reply->errorString();
isRunning = false;
QJsonParseError error;
@ -319,51 +323,52 @@ void ExtWeather::weatherReplyReceived(QNetworkReply *reply)
}
// convert to map
QVariantMap json = jsonDoc.toVariant().toMap();
if (json[QString("cod")].toInt() != 200) {
qCWarning(LOG_LIB) << "Invalid OpenWeatherMap return code"
<< json[QString("cod")].toInt();
QVariantMap json = jsonDoc.toVariant().toMap()[QString("query")].toMap();
if (json[QString("count")].toInt() != 1) {
qCWarning(LOG_LIB) << "Found data count"
<< json[QString("count")].toInt() << "is not 1";
return;
}
QVariantMap results
= json[QString("results")].toMap()[QString("channel")].toMap();
QVariantMap item = results[QString("item")].toMap();
QVariantHash data;
if (m_ts == 0) {
data = parseSingleJson(json);
// current weather
int id = item[QString("condition")].toMap()[QString("code")].toInt();
values[tag(QString("weatherId"))] = id;
values[tag(QString("weather"))] = weatherFromInt(id);
values[tag(QString("temperature"))]
= item[QString("condition")].toMap()[QString("temp")].toInt();
values[tag(QString("timestamp"))]
= item[QString("condition")].toMap()[QString("date")].toString();
values[tag(QString("humidity"))] = results[QString("atmosphere")]
.toMap()[QString("humidity")]
.toInt();
values[tag(QString("pressure"))]
= static_cast<int>(results[QString("atmosphere")]
.toMap()[QString("pressure")]
.toFloat());
} else {
QVariantList list = json[QString("list")].toList();
data = parseSingleJson(list.count() <= m_ts ? list.at(m_ts - 1).toMap()
: list.last().toMap());
// 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;
}
foreach (QString key, data.keys())
values[tag(key)] = data[key];
}
QVariantHash ExtWeather::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")] = _id;
output[QString("weather")] = weatherFromInt(_id);
}
// main data
QVariantMap mainWeather = json[QString("main")].toMap();
if (!weather.isEmpty()) {
output[QString("humidity")]
= mainWeather[QString("humidity")].toFloat();
output[QString("pressure")]
= mainWeather[QString("pressure")].toFloat();
output[QString("temperature")] = mainWeather[QString("temp")].toFloat();
}
return output;
}
@ -379,16 +384,3 @@ void ExtWeather::translate()
ui->checkBox_active->setText(i18n("Active"));
ui->label_interval->setText(i18n("Interval"));
}
QString ExtWeather::url(const bool isForecast) const
{
qCDebug(LOG_LIB) << "Is forecast" << isForecast;
QString apiUrl = isForecast ? QString(OWM_FORECAST_URL) : QString(OWM_URL);
apiUrl.replace(QString("$CITY"), m_city);
apiUrl.replace(QString("$COUNTRY"), m_country);
qCInfo(LOG_LIB) << "API url" << apiUrl;
return apiUrl;
}

View File

@ -22,12 +22,10 @@
#include "abstractextitem.h"
#define OWM_URL \
"http://api.openweathermap.org/data/2.5/" \
"weather?q=$CITY,$COUNTRY&units=metric"
#define OWM_FORECAST_URL \
"http://api.openweathermap.org/data/2.5/" \
"forecast?q=$CITY,$COUNTRY&units=metric"
#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')"
namespace Ui
@ -73,18 +71,17 @@ private slots:
void weatherReplyReceived(QNetworkReply *reply);
private:
QNetworkAccessManager *manager;
QNetworkAccessManager *m_manager;
QUrl m_url;
bool isRunning = false;
Ui::ExtWeather *ui;
QVariantHash parseSingleJson(const QVariantMap json) const;
void translate();
QString url(const bool isForecast = false) const;
// properties
QString m_city = QString("London");
QString m_country = QString("uk");
bool m_image = false;
int m_ts = 0;
QVariantMap jsonMap = QVariantMap();
QVariantMap m_jsonMap = QVariantMap();
// values
int times = 0;
QVariantHash values;

View File

@ -23,15 +23,13 @@
#include <QBuffer>
#include <QColorDialog>
#include <QDir>
#include <QGraphicsEllipseItem>
#include <QFileDialog>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QSettings>
#include <math.h>
#include "awdebug.h"
#include "version.h"
#include "graphicalitemhelper.h"
GraphicalItem::GraphicalItem(QWidget *parent, const QString desktopName,
@ -47,9 +45,13 @@ GraphicalItem::GraphicalItem(QWidget *parent, const QString desktopName,
initScene();
connect(ui->pushButton_activeColor, SIGNAL(clicked()), this,
connect(ui->checkBox_custom, SIGNAL(stateChanged(int)), this,
SLOT(changeValue(int)));
connect(ui->comboBox_type, SIGNAL(currentIndexChanged(int)), this,
SLOT(changeCountState(int)));
connect(ui->toolButton_activeColor, SIGNAL(clicked()), this,
SLOT(changeColor()));
connect(ui->pushButton_inactiveColor, SIGNAL(clicked()), this,
connect(ui->toolButton_inactiveColor, SIGNAL(clicked()), this,
SLOT(changeColor()));
}
@ -60,62 +62,67 @@ GraphicalItem::~GraphicalItem()
delete m_scene;
delete ui;
delete m_helper;
}
GraphicalItem *GraphicalItem::copy(const QString _fileName, const int _number)
{
qCDebug(LOG_LIB) << "File" << _fileName;
qCDebug(LOG_LIB) << "Number" << _number;
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
GraphicalItem *item = new GraphicalItem(static_cast<QWidget *>(parent()),
_fileName, directories());
item->setActive(isActive());
item->setActiveColor(activeColor());
item->setApiVersion(apiVersion());
item->setBar(bar());
item->setComment(comment());
item->setDirection(direction());
item->setHeight(height());
item->setInactiveColor(inactiveColor());
item->setInterval(interval());
item->setName(QString("bar%1").arg(_number));
copyDefaults(item);
item->setActiveColor(m_activeColor);
item->setBar(m_bar);
item->setCount(m_count);
item->setCustom(m_custom);
item->setDirection(m_direction);
item->setHeight(m_height);
item->setInactiveColor(m_inactiveColor);
item->setMaxValue(m_maxValue);
item->setMinValue(m_minValue);
item->setNumber(_number);
item->setType(type());
item->setWidth(width());
item->setType(m_type);
item->setWidth(m_width);
return item;
}
QString GraphicalItem::image(const QVariant value)
QString GraphicalItem::image(const QVariant &value)
{
qCDebug(LOG_LIB) << "Value" << value;
if (m_bar == QString("none"))
return QString("");
m_scene->clear();
int scale[2] = {1, 1};
float converted
= m_helper->getPercents(value.toFloat(), m_minValue, m_maxValue);
// paint
switch (m_type) {
case Vertical:
paintVertical(value.toFloat());
case Type::Vertical:
m_helper->paintVertical(converted);
// scale
scale[1] = -2 * static_cast<int>(m_direction) + 1;
break;
case Circle:
paintCircle(value.toFloat());
case Type::Circle:
m_helper->paintCircle(converted);
// scale
scale[0] = -2 * static_cast<int>(m_direction) + 1;
break;
case Graph:
paintGraph(value.value<QList<float>>());
// direction option is not recognized by this GI type
case Type::Graph:
m_helper->paintGraph(converted);
scale[0] = -2 * static_cast<int>(m_direction) + 1;
scale[1] = -1;
break;
case Horizontal:
default:
paintHorizontal(value.toFloat());
case Type::Bars:
m_helper->paintBars(converted);
scale[0] = -2 * static_cast<int>(m_direction) + 1;
scale[1] = -1;
break;
case Type::Horizontal:
m_helper->paintHorizontal(converted);
// scale
scale[0] = -2 * static_cast<int>(m_direction) + 1;
break;
@ -152,9 +159,27 @@ QString GraphicalItem::inactiveColor() const
}
QString GraphicalItem::tag() const
int GraphicalItem::count() const
{
return QString("bar%1%2").arg(number()).arg(m_bar);
return m_count;
}
bool GraphicalItem::isCustom() const
{
return m_custom;
}
float GraphicalItem::maxValue() const
{
return m_maxValue;
}
float GraphicalItem::minValue() const
{
return m_minValue;
}
@ -168,17 +193,19 @@ QString GraphicalItem::strType() const
{
QString value;
switch (m_type) {
case Vertical:
case Type::Vertical:
value = QString("Vertical");
break;
case Circle:
case Type::Circle:
value = QString("Circle");
break;
case Graph:
case Type::Graph:
value = QString("Graph");
break;
case Horizontal:
default:
case Type::Bars:
value = QString("Bars");
break;
case Type::Horizontal:
value = QString("Horizontal");
break;
}
@ -197,11 +224,10 @@ QString GraphicalItem::strDirection() const
{
QString value;
switch (m_direction) {
case RightToLeft:
case Direction::RightToLeft:
value = QString("RightToLeft");
break;
case LeftToRight:
default:
case Direction::LeftToRight:
value = QString("LeftToRight");
break;
}
@ -216,6 +242,12 @@ int GraphicalItem::height() const
}
QStringList GraphicalItem::usedKeys() const
{
return m_usedKeys;
}
int GraphicalItem::width() const
{
return m_width;
@ -232,13 +264,7 @@ void GraphicalItem::setBar(const QString _bar)
{
qCDebug(LOG_LIB) << "Bar" << _bar;
if (!_bar.contains(QRegExp(
QString("^(cpu(?!cl).*|gpu$|mem$|swap$|hdd[0-9].*|bat.*)")))) {
qCWarning(LOG_LIB) << "Unsupported bar type" << _bar;
m_bar = QString("none");
} else {
m_bar = _bar;
}
m_bar = _bar;
}
@ -250,6 +276,24 @@ void GraphicalItem::setActiveColor(const QString _color)
}
void GraphicalItem::setCount(const int _count)
{
qCDebug(LOG_LIB) << "Count" << _count;
if (_count <= 1)
return;
m_count = _count;
}
void GraphicalItem::setCustom(const bool _custom)
{
qCDebug(LOG_LIB) << "Use custom tag" << _custom;
m_custom = _custom;
}
void GraphicalItem::setInactiveColor(const QString _color)
{
qCDebug(LOG_LIB) << "Color" << _color;
@ -258,9 +302,25 @@ void GraphicalItem::setInactiveColor(const QString _color)
}
void GraphicalItem::setMaxValue(const float _value)
{
qCDebug(LOG_LIB) << "Max value" << _value;
m_maxValue = _value;
}
void GraphicalItem::setMinValue(const float _value)
{
qCDebug(LOG_LIB) << "Min value" << _value;
m_minValue = _value;
}
void GraphicalItem::setType(const Type _type)
{
qCDebug(LOG_LIB) << "Type" << _type;
qCDebug(LOG_LIB) << "Type" << static_cast<int>(_type);
m_type = _type;
}
@ -271,19 +331,21 @@ void GraphicalItem::setStrType(const QString _type)
qCDebug(LOG_LIB) << "Type" << _type;
if (_type == QString("Vertical"))
setType(Vertical);
setType(Type::Vertical);
else if (_type == QString("Circle"))
setType(Circle);
setType(Type::Circle);
else if (_type == QString("Graph"))
setType(Graph);
setType(Type::Graph);
else if (_type == QString("Bars"))
setType(Type::Bars);
else
setType(Horizontal);
setType(Type::Horizontal);
}
void GraphicalItem::setDirection(const Direction _direction)
{
qCDebug(LOG_LIB) << "Direction" << _direction;
qCDebug(LOG_LIB) << "Direction" << static_cast<int>(_direction);
m_direction = _direction;
}
@ -294,9 +356,9 @@ void GraphicalItem::setStrDirection(const QString _direction)
qCDebug(LOG_LIB) << "Direction" << _direction;
if (_direction == QString("RightToLeft"))
setDirection(RightToLeft);
setDirection(Direction::RightToLeft);
else
setDirection(LeftToRight);
setDirection(Direction::LeftToRight);
}
@ -310,6 +372,21 @@ void GraphicalItem::setHeight(const int _height)
}
void GraphicalItem::setUsedKeys(const QStringList _usedKeys)
{
qCDebug(LOG_LIB) << "Used keys" << _usedKeys;
// remove dubs
// HACK converting to set may break order
m_usedKeys.clear();
for (auto key : _usedKeys) {
if (m_usedKeys.contains(key))
continue;
m_usedKeys.append(key);
}
}
void GraphicalItem::setWidth(const int _width)
{
qCDebug(LOG_LIB) << "Width" << _width;
@ -334,7 +411,11 @@ void GraphicalItem::readConfiguration()
QSettings::IniFormat);
settings.beginGroup(QString("Desktop Entry"));
setCount(settings.value(QString("X-AW-Count"), m_count).toInt());
setCustom(settings.value(QString("X-AW-Custom"), m_custom).toBool());
setBar(settings.value(QString("X-AW-Value"), m_bar).toString());
setMaxValue(settings.value(QString("X-AW-Max"), m_maxValue).toFloat());
setMinValue(settings.value(QString("X-AW-Min"), m_minValue).toFloat());
setActiveColor(
settings.value(QString("X-AW-ActiveColor"), m_activeColor)
.toString());
@ -347,9 +428,18 @@ void GraphicalItem::readConfiguration()
.toString());
setHeight(settings.value(QString("X-AW-Height"), m_height).toInt());
setWidth(settings.value(QString("X-AW-Width"), m_width).toInt());
// api == 2
if (apiVersion() < 2)
setNumber(bar().remove(QString("bar")).toInt());
// api == 5
if (apiVersion() < 5) {
QString prefix;
prefix = m_activeColor.startsWith(QString("/"))
? QString("file://%1")
: QString("color://%1");
m_activeColor = prefix.arg(m_activeColor);
prefix = m_inactiveColor.startsWith(QString("/"))
? QString("file://%1")
: QString("color://%1");
m_inactiveColor = prefix.arg(m_inactiveColor);
}
settings.endGroup();
}
@ -363,39 +453,59 @@ void GraphicalItem::readConfiguration()
}
QVariantHash GraphicalItem::run()
{
// required by abstract class
return QVariantHash();
}
int GraphicalItem::showConfiguration(const QVariant args)
{
qCDebug(LOG_LIB) << "Combobox arguments" << args;
QStringList tags = args.toStringList();
ui->label_nameValue->setText(name());
ui->lineEdit_name->setText(name());
ui->lineEdit_comment->setText(comment());
ui->label_numberValue->setText(QString("%1").arg(number()));
ui->checkBox_custom->setChecked(m_custom);
ui->comboBox_value->addItems(tags);
ui->comboBox_value->addItem(m_bar);
ui->comboBox_value->setCurrentIndex(ui->comboBox_value->count() - 1);
ui->pushButton_activeColor->setText(m_activeColor);
ui->pushButton_inactiveColor->setText(m_inactiveColor);
if (m_custom) {
ui->lineEdit_customValue->setText(m_bar);
} else {
ui->comboBox_value->addItem(m_bar);
ui->comboBox_value->setCurrentIndex(ui->comboBox_value->count() - 1);
}
ui->doubleSpinBox_max->setValue(m_maxValue);
ui->doubleSpinBox_min->setValue(m_minValue);
ui->spinBox_count->setValue(m_count);
if (m_helper->isColor(m_activeColor))
ui->comboBox_activeImageType->setCurrentIndex(0);
else
ui->comboBox_activeImageType->setCurrentIndex(1);
ui->lineEdit_activeColor->setText(m_activeColor);
if (m_helper->isColor(m_inactiveColor))
ui->comboBox_inactiveImageType->setCurrentIndex(0);
else
ui->comboBox_inactiveImageType->setCurrentIndex(1);
ui->lineEdit_inactiveColor->setText(m_inactiveColor);
ui->comboBox_type->setCurrentIndex(static_cast<int>(m_type));
ui->comboBox_direction->setCurrentIndex(static_cast<int>(m_direction));
ui->spinBox_height->setValue(m_height);
ui->spinBox_width->setValue(m_width);
// update UI
emit(ui->comboBox_type->currentIndexChanged(
ui->comboBox_type->currentIndex()));
emit(ui->checkBox_custom->stateChanged(ui->checkBox_custom->checkState()));
int ret = exec();
if (ret != 1)
return ret;
setName(ui->label_nameValue->text());
setName(ui->lineEdit_name->text());
setComment(ui->lineEdit_comment->text());
setApiVersion(AWGIAPI);
setBar(ui->comboBox_value->currentText());
setActiveColor(ui->pushButton_activeColor->text().remove(QChar('&')));
setInactiveColor(ui->pushButton_inactiveColor->text().remove(QChar('&')));
setCount(ui->spinBox_count->value());
setCustom(ui->checkBox_custom->isChecked());
setBar(m_custom ? ui->lineEdit_customValue->text()
: ui->comboBox_value->currentText());
setMaxValue(ui->doubleSpinBox_max->value());
setMinValue(ui->doubleSpinBox_min->value());
setActiveColor(ui->lineEdit_activeColor->text());
setInactiveColor(ui->lineEdit_inactiveColor->text());
setStrType(ui->comboBox_type->currentText());
setStrDirection(ui->comboBox_direction->currentText());
setHeight(ui->spinBox_height->value());
@ -417,6 +527,10 @@ void GraphicalItem::writeConfiguration() const
settings.beginGroup(QString("Desktop Entry"));
settings.setValue(QString("X-AW-Value"), m_bar);
settings.setValue(QString("X-AW-Count"), m_count);
settings.setValue(QString("X-AW-Custom"), m_custom);
settings.setValue(QString("X-AW-Max"), m_maxValue);
settings.setValue(QString("X-AW-Min"), m_minValue);
settings.setValue(QString("X-AW-ActiveColor"), m_activeColor);
settings.setValue(QString("X-AW-InactiveColor"), m_inactiveColor);
settings.setValue(QString("X-AW-Type"), strType());
@ -431,22 +545,67 @@ void GraphicalItem::writeConfiguration() const
void GraphicalItem::changeColor()
{
QColor color
= stringToColor((static_cast<QPushButton *>(sender()))->text());
QColor newColor = QColorDialog::getColor(color, this, tr("Select color"),
QColorDialog::ShowAlphaChannel);
if (!newColor.isValid())
QLineEdit *lineEdit;
int state;
if (sender() == ui->toolButton_activeColor) {
lineEdit = ui->lineEdit_activeColor;
state = ui->comboBox_activeImageType->currentIndex();
} else {
lineEdit = ui->lineEdit_inactiveColor;
state = ui->comboBox_inactiveImageType->currentIndex();
}
qCInfo(LOG_LIB) << "Using state" << state << "and lineEdit" << lineEdit;
QString outputColor;
if (state == 0) {
QColor color = m_helper->stringToColor(lineEdit->text());
QColor newColor = QColorDialog::getColor(
color, this, tr("Select color"), QColorDialog::ShowAlphaChannel);
if (!newColor.isValid())
return;
qCInfo(LOG_LIB) << "Selected color" << newColor;
QStringList colorText;
colorText.append(QString("%1").arg(newColor.red()));
colorText.append(QString("%1").arg(newColor.green()));
colorText.append(QString("%1").arg(newColor.blue()));
colorText.append(QString("%1").arg(newColor.alpha()));
outputColor = QString("color://%1").arg(colorText.join(QChar(',')));
} else if (state == 1) {
QString path = lineEdit->text();
QString directory = QFileInfo(path).absolutePath();
outputColor = QFileDialog::getOpenFileUrl(
this, tr("Select path"), directory,
tr("Images (*.png *.bpm *.jpg);;All files (*.*)"))
.toString();
qCInfo(LOG_LIB) << "Selected path" << outputColor;
}
if (outputColor.isEmpty()) {
qCWarning(LOG_LIB) << "Empty color selected, skipping";
return;
qCInfo(LOG_LIB) << "Selected color" << newColor;
}
return lineEdit->setText(outputColor);
}
QStringList colorText;
colorText.append(QString("%1").arg(newColor.red()));
colorText.append(QString("%1").arg(newColor.green()));
colorText.append(QString("%1").arg(newColor.blue()));
colorText.append(QString("%1").arg(newColor.alpha()));
return static_cast<QPushButton *>(sender())
->setText(colorText.join(QChar(',')));
void GraphicalItem::changeCountState(const int state)
{
qCDebug(LOG_LIB) << "Current state is" << state;
// 3 is magic number. Actually 3 is Graph mode
ui->widget_count->setHidden(state != 3);
}
void GraphicalItem::changeValue(const int state)
{
qCDebug(LOG_LIB) << "Current state is" << state;
ui->widget_value->setHidden(state != Qt::Unchecked);
ui->widget_customValue->setHidden(state == Qt::Unchecked);
}
@ -454,10 +613,7 @@ void GraphicalItem::initScene()
{
// init scene
m_scene = new QGraphicsScene();
if (m_type == Graph)
m_scene->setBackgroundBrush(stringToColor(m_inactiveColor));
else
m_scene->setBackgroundBrush(QBrush(Qt::NoBrush));
m_scene->setBackgroundBrush(QBrush(Qt::NoBrush));
// init view
m_view = new QGraphicsView(m_scene);
m_view->setStyleSheet(QString("background: transparent"));
@ -465,104 +621,12 @@ void GraphicalItem::initScene()
m_view->setFrameShape(QFrame::NoFrame);
m_view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
m_view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
m_view->resize(m_width + 5.0, m_height + 5.0);
}
m_view->resize(m_width + 5, m_height + 5);
void GraphicalItem::paintCircle(const float value)
{
QPen pen;
pen.setWidth(1.0);
float percent = value / 100.0;
QGraphicsEllipseItem *circle;
QColor inactive = stringToColor(m_inactiveColor);
QColor active = stringToColor(m_activeColor);
// inactive
pen.setColor(inactive);
circle = m_scene->addEllipse(0.0, 0.0, m_width, m_height, pen,
QBrush(inactive, Qt::SolidPattern));
circle->setSpanAngle(-(1.0 - percent) * 360.0 * 16.0);
circle->setStartAngle(90.0 * 16.0 - percent * 360.0 * 16.0);
// active
pen.setColor(active);
circle = m_scene->addEllipse(0.0, 0.0, m_width, m_height, pen,
QBrush(active, Qt::SolidPattern));
circle->setSpanAngle(-percent * 360.0 * 16.0);
circle->setStartAngle(90.0 * 16.0);
}
void GraphicalItem::paintGraph(const QList<float> value)
{
QPen pen;
pen.setColor(stringToColor(m_activeColor));
// default norms
float normX
= static_cast<float>(m_width) / static_cast<float>(value.count());
float normY = static_cast<float>(m_height) / (1.5 * 100.0);
// paint graph
for (int i = 0; i < value.count() - 1; i++) {
// some magic here
float x1 = i * normX;
float y1 = -fabs(value.at(i)) * normY + 5.0;
float x2 = (i + 1) * normX;
float y2 = -fabs(value.at(i + 1)) * normY + 5.0;
m_scene->addLine(x1, y1, x2, y2, pen);
}
}
void GraphicalItem::paintHorizontal(const float value)
{
QPen pen;
float percent = value / 100.0;
pen.setWidth(m_height);
// inactive
pen.setColor(stringToColor(m_inactiveColor));
m_scene->addLine(percent * m_width + 0.5 * m_height, 0.5 * m_height,
m_width + 0.5 * m_height, 0.5 * m_height, pen);
// active
pen.setColor(stringToColor(m_activeColor));
m_scene->addLine(-0.5 * m_height, 0.5 * m_height,
percent * m_width - 0.5 * m_height, 0.5 * m_height, pen);
}
void GraphicalItem::paintVertical(const float value)
{
QPen pen;
float percent = value / 100.0;
pen.setWidth(m_width);
// inactive
pen.setColor(stringToColor(m_inactiveColor));
m_scene->addLine(0.5 * m_width, -0.5 * m_width, 0.5 * m_width,
(1.0 - percent) * m_height - 0.5 * m_width, pen);
// active
pen.setColor(stringToColor(m_activeColor));
m_scene->addLine(0.5 * m_width, (1.0 - percent) * m_height + 0.5 * m_width,
0.5 * m_width, m_height + 0.5 * m_width, pen);
}
QColor GraphicalItem::stringToColor(const QString _color) const
{
qCDebug(LOG_LIB) << "Color" << _color;
QColor qcolor;
QStringList listColor = _color.split(QChar(','));
while (listColor.count() < 4)
listColor.append(QString("0"));
qcolor.setRed(listColor.at(0).toInt());
qcolor.setGreen(listColor.at(1).toInt());
qcolor.setBlue(listColor.at(2).toInt());
qcolor.setAlpha(listColor.at(3).toInt());
return qcolor;
// init helper
m_helper = new GraphicalItemHelper(this, m_scene);
m_helper->setParameters(m_activeColor, m_inactiveColor, m_width, m_height,
m_count);
}
@ -570,11 +634,24 @@ void GraphicalItem::translate()
{
ui->label_name->setText(i18n("Name"));
ui->label_comment->setText(i18n("Comment"));
ui->label_number->setText(i18n("Tag"));
ui->checkBox_custom->setText(i18n("Use custom formula"));
ui->label_value->setText(i18n("Value"));
ui->label_activeColor->setText(i18n("Active color"));
ui->label_inactiveColor->setText(i18n("Inactive color"));
ui->label_customValue->setText(i18n("Value"));
ui->label_max->setText(i18n("Max value"));
ui->label_min->setText(i18n("Min value"));
ui->label_activeImageType->setText(i18n("Active filling type"));
ui->label_inactiveImageType->setText(i18n("Inctive filling type"));
ui->label_type->setText(i18n("Type"));
ui->label_count->setText(i18n("Points count"));
ui->label_direction->setText(i18n("Direction"));
ui->label_height->setText(i18n("Height"));
ui->label_width->setText(i18n("Width"));
ui->comboBox_activeImageType->clear();
ui->comboBox_activeImageType->addItem(i18n("color"));
ui->comboBox_activeImageType->addItem(i18n("image"));
ui->comboBox_inactiveImageType->clear();
ui->comboBox_inactiveImageType->addItem(i18n("color"));
ui->comboBox_inactiveImageType->addItem(i18n("image"));
}

View File

@ -23,6 +23,7 @@
#include "abstractextitem.h"
class GraphicalItemHelper;
class QGraphicsScene;
class QGraphicsView;
@ -36,76 +37,90 @@ class GraphicalItem : public AbstractExtItem
Q_OBJECT
Q_PROPERTY(QString bar READ bar WRITE setBar)
Q_PROPERTY(QString activeColor READ activeColor WRITE setActiveColor)
Q_PROPERTY(int count READ count WRITE setCount)
Q_PROPERTY(bool custom READ isCustom WRITE setCustom)
Q_PROPERTY(QString inactiveColor READ inactiveColor WRITE setInactiveColor)
Q_PROPERTY(Type type READ type WRITE setType)
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 minValue READ minValue WRITE setMinValue)
Q_PROPERTY(QStringList usedKeys READ usedKeys WRITE setUsedKeys)
Q_PROPERTY(int width READ width WRITE setWidth)
public:
enum Direction { LeftToRight = 0, RightToLeft };
enum Type { Horizontal = 0, Vertical, Circle, Graph };
enum class Direction { LeftToRight = 0, RightToLeft = 1 };
enum class Type { Horizontal, Vertical, Circle, Graph, Bars };
explicit GraphicalItem(QWidget *parent = nullptr,
const QString desktopName = QString(),
const QStringList directories = QStringList());
virtual ~GraphicalItem();
GraphicalItem *copy(const QString _fileName, const int _number);
QString image(const QVariant value);
QString image(const QVariant &value);
// get methods
QString bar() const;
QString activeColor() const;
QString inactiveColor() const;
QString tag() const;
int count() const;
bool isCustom() const;
float minValue() const;
float maxValue() const;
Type type() const;
QString strType() const;
Direction direction() const;
QString strDirection() const;
int height() const;
QStringList usedKeys() const;
int width() const;
QString uniq() const;
// set methods
void setBar(const QString _bar = QString("cpu"));
void setActiveColor(const QString _color = QString("0,0,0,130"));
void setInactiveColor(const QString _color = QString("255,255,255,130"));
void setType(const Type _type = Horizontal);
void setActiveColor(const QString _color = QString("color://0,0,0,130"));
void setCount(const int _count = 100);
void setCustom(const bool _custom = false);
void setInactiveColor(const QString _color
= QString("color://255,255,255,130"));
void setMinValue(const float _value = 0.0);
void setMaxValue(const float _value = 100.0);
void setType(const Type _type = Type::Horizontal);
void setStrType(const QString _type = QString("Horizontal"));
void setDirection(const Direction _direction = LeftToRight);
void setDirection(const Direction _direction = Direction::LeftToRight);
void setStrDirection(const QString _direction = QString("LeftToRight"));
void setHeight(const int _height = 100);
void setUsedKeys(const QStringList _usedKeys = QStringList());
void setWidth(const int _width = 100);
public slots:
void readConfiguration();
QVariantHash run();
QVariantHash run() { return QVariantHash(); };
int showConfiguration(const QVariant args = QVariant());
void writeConfiguration() const;
private slots:
void changeColor();
void changeCountState(const int state);
void changeValue(const int state);
private:
QString m_fileName;
QStringList m_dirs;
GraphicalItemHelper *m_helper = nullptr;
QGraphicsScene *m_scene = nullptr;
QGraphicsView *m_view = nullptr;
Ui::GraphicalItem *ui;
void initScene();
// paint methods
void paintCircle(const float value);
void paintGraph(const QList<float> value);
void paintHorizontal(const float value);
void paintVertical(const float value);
// additional method
QColor stringToColor(const QString _color) const;
void translate();
// properties
QString m_bar = QString("cpu");
QString m_activeColor = QString("0,0,0,130");
QString m_inactiveColor = QString("255,255,255,130");
Type m_type = Horizontal;
Direction m_direction = LeftToRight;
int m_count = 100;
bool m_custom = false;
QString m_activeColor = QString("color://0,0,0,130");
QString m_inactiveColor = QString("color://255,255,255,130");
float m_minValue = 0.0f;
float m_maxValue = 100.0f;
Type m_type = Type::Horizontal;
Direction m_direction = Direction::LeftToRight;
int m_height = 100;
QStringList m_usedKeys;
int m_width = 100;
};

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>416</width>
<height>325</height>
<height>569</height>
</rect>
</property>
<property name="windowTitle">
@ -18,6 +18,12 @@
<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>
@ -27,11 +33,7 @@
</widget>
</item>
<item>
<widget class="QLabel" name="label_nameValue">
<property name="text">
<string/>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_name"/>
</item>
</layout>
</item>
@ -59,11 +61,11 @@
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_value">
<layout class="QHBoxLayout" name="layout_number">
<item>
<widget class="QLabel" name="label_value">
<widget class="QLabel" name="label_number">
<property name="text">
<string>Value</string>
<string>Tag</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
@ -71,41 +73,111 @@
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox_value">
<property name="editable">
<bool>false</bool>
<widget class="QLabel" name="label_numberValue">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_activeColor">
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="layout_custom">
<item>
<widget class="QLabel" name="label_activeColor">
<property name="text">
<string>Active color</string>
<spacer name="spacer_custom">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</widget>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton_activeColor">
<widget class="QCheckBox" name="checkBox_custom">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string notr="true"/>
<string>Use custom formula</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_inactiveColor">
<widget class="QWidget" name="widget_value" native="true">
<layout class="QHBoxLayout" name="layout_value">
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_value">
<property name="text">
<string>Value</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox_value">
<property name="editable">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QWidget" name="widget_customValue" native="true">
<layout class="QHBoxLayout" name="layout_customValue">
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_customValue">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Value</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_customValue"/>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="layout_max">
<item>
<widget class="QLabel" name="label_inactiveColor">
<widget class="QLabel" name="label_max">
<property name="text">
<string>Inactive color</string>
<string>Max value</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
@ -113,9 +185,107 @@
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_inactiveColor">
<widget class="QDoubleSpinBox" name="doubleSpinBox_max">
<property name="maximum">
<double>9999.989999999999782</double>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_min">
<item>
<widget class="QLabel" name="label_min">
<property name="text">
<string notr="true"/>
<string>Min value</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="doubleSpinBox_min">
<property name="maximum">
<double>9999.989999999999782</double>
</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_activeImageType">
<item>
<widget class="QLabel" name="label_activeImageType">
<property name="text">
<string>Active filling type</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox_activeImageType"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_activeColorButton">
<item>
<widget class="QLineEdit" name="lineEdit_activeColor">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="toolButton_activeColor">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_inactiveImageType">
<item>
<widget class="QLabel" name="label_inactiveImageType">
<property name="text">
<string>Inactive filling type</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox_inactiveImageType"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_inactiveColorButton">
<item>
<widget class="QLineEdit" name="lineEdit_inactiveColor">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="toolButton_inactiveColor">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
@ -155,6 +325,11 @@
<string notr="true">Graph</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">Bars</string>
</property>
</item>
</widget>
</item>
</layout>
@ -187,6 +362,35 @@
</item>
</layout>
</item>
<item>
<widget class="QWidget" name="widget_count" native="true">
<layout class="QHBoxLayout" name="layout_count">
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_count">
<property name="text">
<string>Points count</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBox_count">
<property name="maximum">
<number>2000</number>
</property>
<property name="singleStep">
<number>25</number>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="layout_height">
<item>

View File

@ -0,0 +1,237 @@
/***************************************************************************
* 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 "graphicalitemhelper.h"
#include <QColor>
#include <QGraphicsEllipseItem>
#include <QGraphicsScene>
#include <QUrl>
#include <cmath>
#include "awdebug.h"
GraphicalItemHelper::GraphicalItemHelper(QObject *parent, QGraphicsScene *scene)
: QObject(parent)
, m_scene(scene)
{
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
}
GraphicalItemHelper::~GraphicalItemHelper()
{
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
}
void GraphicalItemHelper::setParameters(const QString active,
const QString inactive, const int width,
const int height, const int count)
{
qCDebug(LOG_LIB) << "Use active color" << active << ", inactive" << inactive
<< ", width" << width << ", height" << height << ", count"
<< count;
// put images to pens if any otherwise set pen colors
// Images resize to content here as well
if (isColor(active)) {
m_activePen.setBrush(QBrush(stringToColor(active)));
} else {
qCInfo(LOG_LIB) << "Found path, trying to load Pixmap from" << active;
QPixmap pixmap = QPixmap(QUrl(active).toLocalFile());
if (pixmap.isNull()) {
qCWarning(LOG_LIB) << "Invalid pixmap found" << active;
m_activePen.setBrush(QBrush(QColor(0, 0, 0, 130)));
} else {
m_activePen.setBrush(QBrush(pixmap.scaled(width, height)));
}
}
if (isColor(inactive)) {
m_inactivePen.setBrush(QBrush(stringToColor(inactive)));
} else {
qCInfo(LOG_LIB) << "Found path, trying to load Pixmap from" << inactive;
QPixmap pixmap = QPixmap(QUrl(inactive).toLocalFile());
if (pixmap.isNull()) {
qCWarning(LOG_LIB) << "Invalid pixmap found" << inactive;
m_inactivePen.setBrush(QBrush(QColor(255, 255, 255, 130)));
} else {
m_inactivePen.setBrush(QBrush(pixmap.scaled(width, height)));
}
}
m_width = width;
m_height = height;
m_count = count;
}
void GraphicalItemHelper::paintBars(const float &value)
{
qCDebug(LOG_LIB) << "Paint with value" << value;
// refresh background image
m_scene->setBackgroundBrush(m_inactivePen.brush());
storeValue(value);
// default norms
float normX
= static_cast<float>(m_width) / static_cast<float>(m_values.count());
float normY = static_cast<float>(m_height - 1);
// paint graph
for (int i = 0; i < m_values.count(); i++) {
float x = i * normX;
float y = 0.5f;
float width = normX;
float height = m_values.at(i) * normY + 0.5f;
m_scene->addRect(x, y, width, height, m_activePen, m_activePen.brush());
}
}
void GraphicalItemHelper::paintCircle(const float &percent)
{
qCDebug(LOG_LIB) << "Paint with percent" << percent;
m_activePen.setWidth(1);
m_inactivePen.setWidth(1);
QGraphicsEllipseItem *circle;
// 16 is because of qt. From Qt documentation:
// Returns the start angle for an ellipse segment in 16ths of a degree
// inactive
circle = m_scene->addEllipse(0.0, 0.0, m_width, m_height, m_inactivePen,
m_inactivePen.brush());
circle->setSpanAngle(-(1.0f - percent) * 360.0f * 16.0f);
circle->setStartAngle(90.0f * 16.0f - percent * 360.0f * 16.0f);
// active
circle = m_scene->addEllipse(0.0, 0.0, m_width, m_height, m_activePen,
m_activePen.brush());
circle->setSpanAngle(-percent * 360.0f * 16.0f);
circle->setStartAngle(90 * 16);
}
void GraphicalItemHelper::paintGraph(const float &value)
{
qCDebug(LOG_LIB) << "Paint with value" << value;
// refresh background image
m_scene->setBackgroundBrush(m_inactivePen.brush());
storeValue(value);
// default norms
float normX
= static_cast<float>(m_width) / static_cast<float>(m_values.count());
float normY = static_cast<float>(m_height - 1);
// paint graph
for (int i = 0; i < m_values.count() - 1; i++) {
// some magic here
float x1 = i * normX;
float y1 = m_values.at(i) * normY + 0.5f;
float x2 = (i + 1) * normX;
float y2 = m_values.at(i + 1) * normY + 0.5f;
m_scene->addLine(x1, y1, x2, y2, m_activePen);
}
}
void GraphicalItemHelper::paintHorizontal(const float &percent)
{
qCDebug(LOG_LIB) << "Paint with percent" << percent;
m_activePen.setWidth(m_height);
m_inactivePen.setWidth(m_height);
// inactive
m_scene->addLine(percent * m_width + 0.5 * m_height, 0.5 * m_height,
m_width + 0.5 * m_height, 0.5 * m_height, m_inactivePen);
// active
m_scene->addLine(-0.5 * m_height, 0.5 * m_height,
percent * m_width - 0.5 * m_height, 0.5 * m_height,
m_activePen);
}
void GraphicalItemHelper::paintVertical(const float &percent)
{
qCDebug(LOG_LIB) << "Paint with percent" << percent;
m_activePen.setWidth(m_height);
m_inactivePen.setWidth(m_height);
// inactive
m_scene->addLine(0.5 * m_width, -0.5 * m_width, 0.5 * m_width,
(1.0 - percent) * m_height - 0.5 * m_width, m_inactivePen);
// active
m_scene->addLine(0.5 * m_width, (1.0 - percent) * m_height + 0.5 * m_width,
0.5 * m_width, m_height + 0.5 * m_width, m_activePen);
}
float GraphicalItemHelper::getPercents(const float &value, const float &min,
const float &max)
{
qCDebug(LOG_LIB) << "Get percent value from" << value;
// newest Qt crashes here if value is nan
if (std::isnan(value))
return 0.0;
return (value - min) / (max - min);
}
bool GraphicalItemHelper::isColor(const QString &input)
{
qCDebug(LOG_LIB) << "Define input type in" << input;
return input.startsWith(QString("color://"));
}
QColor GraphicalItemHelper::stringToColor(const QString &color)
{
qCDebug(LOG_LIB) << "Color" << color;
QStringList listColor = color.split(QChar(','));
while (listColor.count() < 4)
listColor.append(QString("0"));
// remove prefix
listColor[0].remove(QString("color://"));
// init color
QColor qColor;
qColor.setRed(listColor.at(0).toInt());
qColor.setGreen(listColor.at(1).toInt());
qColor.setBlue(listColor.at(2).toInt());
qColor.setAlpha(listColor.at(3).toInt());
return qColor;
}
void GraphicalItemHelper::storeValue(const float &value)
{
qCDebug(LOG_LIB) << "Save value to array" << value;
if (m_values.count() == 0)
m_values.append(1.0);
else if (m_values.count() > m_count)
m_values.removeFirst();
m_values.append(value);
}

View File

@ -0,0 +1,61 @@
/***************************************************************************
* 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 GRAPHICALITEMHELPER_H
#define GRAPHICALITEMHELPER_H
#include <QColor>
#include <QObject>
#include <QPen>
class QGraphicsScene;
class GraphicalItemHelper : public QObject
{
public:
explicit GraphicalItemHelper(QObject *parent = nullptr,
QGraphicsScene *scene = nullptr);
virtual ~GraphicalItemHelper();
// parameters
void setParameters(const QString active, const QString inactive,
const int width, const int height, const int count);
// paint methods
void paintBars(const float &value);
void paintCircle(const float &percent);
void paintGraph(const float &value);
void paintHorizontal(const float &percent);
void paintVertical(const float &percent);
// additional conversion methods
float getPercents(const float &value, const float &min, const float &max);
bool isColor(const QString &input);
QColor stringToColor(const QString &color);
private:
void storeValue(const float &value);
QGraphicsScene *m_scene = nullptr;
int m_count = 100;
QPen m_activePen;
QPen m_inactivePen;
int m_width = 100;
int m_height = 100;
// list of values which will be used to store data for graph type only
QList<float> m_values;
};
#endif /* GRAPHICALITEMHELPER_H */

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

Some files were not shown because too many files have changed in this diff Show More