mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-06-30 23:45:52 +00:00
Compare commits
94 Commits
Author | SHA1 | Date | |
---|---|---|---|
8f6d9e7ab5 | |||
22dcebe647 | |||
6e087f418f | |||
b76cbb8ce3 | |||
24ad32b6ca | |||
51b7d3aa09 | |||
3674fba669 | |||
f1116d1f83 | |||
bcf757477b | |||
1864dc71d5 | |||
90c33ab24d | |||
052d8a034c | |||
064cd7e44f | |||
9e59b22c32 | |||
89f6661fa5 | |||
7836fbf77f | |||
d90d9e2c6f | |||
927e93b7fc | |||
fbf89f61b4 | |||
4adf457ada | |||
0d4211b2c4 | |||
085eec7a3d | |||
baf5085506 | |||
17a0c61b4a | |||
3497922928 | |||
2f88c7ae60 | |||
8e8ac2f3c7 | |||
5cd5272f10 | |||
bee8e2f180 | |||
bf16e72e1e | |||
faf259e339 | |||
f6a6704fd2 | |||
4a0da3f978 | |||
71ae832bcd | |||
0f1763cb81 | |||
b20a96d32f | |||
75d101cc8b | |||
5d9d551afe | |||
78b7a87c29 | |||
bc2071a493 | |||
5a0541d06d | |||
18789f78b3 | |||
ab01c9fa08 | |||
620c4bd1e3 | |||
4337379177 | |||
69c09d9ff8 | |||
cae9e0d2e3 | |||
7b154af1b3 | |||
fd3ed61191 | |||
2a257de1e6 | |||
6f09737f0f | |||
b73fb19409 | |||
c57a92b687 | |||
72f0d4587b | |||
ea7c15d865 | |||
2dccc92933 | |||
e71da9bdfb | |||
f717c984b7 | |||
906ad56c46 | |||
301a908aed | |||
6bd7788aa9 | |||
51c7299ad0 | |||
326c65528d | |||
14aab3b758 | |||
7c37134aab | |||
734cbe2f4c | |||
4bcdb3a7ff | |||
5ad0c533f0 | |||
d57e54b714 | |||
13f2d560d0 | |||
2220ad6bfe | |||
97f2e78308 | |||
3771ce6ec2 | |||
46db3fee4c | |||
a339f9a743 | |||
4e52d16f1a | |||
097b63415e | |||
77388deab6 | |||
d01d8f95e5 | |||
22586811de | |||
82dda14260 | |||
f8e9945bc4 | |||
139554578c | |||
1827f641f9 | |||
aef1a736c8 | |||
27a80274ac | |||
0e3f83f361 | |||
d30df9dafc | |||
f7a6b86cae | |||
a3e7a84b92 | |||
354fd3cd0c | |||
15abe54290 | |||
60cbc40e9f | |||
bfa4f9e98e |
8
.tx/config
Normal file
8
.tx/config
Normal 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
|
11
AUTHORS
11
AUTHORS
@ -5,8 +5,9 @@ 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)
|
||||
|
51
CHANGELOG
51
CHANGELOG
@ -1,3 +1,54 @@
|
||||
Ver.3.2.1:
|
||||
+ add X-AW-Translate option to DateTime formatter
|
||||
+ add formatters to configuration export and import
|
||||
+ add macro fuction to selector
|
||||
+ add default formatters
|
||||
- add translation reinit (fix #102)
|
||||
- fix invalid float formatter saving
|
||||
- fix missing ApiVersion for formatters
|
||||
* use sockets for MPD data
|
||||
* translation update
|
||||
|
||||
Ver.3.2.0:
|
||||
+ custom formatters (#91)
|
||||
+ add backend tests (#95)
|
||||
+ add OWM weather provider for ExtWeather. It can be switched by using X-AW-Provider (ApiVer 3)
|
||||
+ add DBus timeout for calls (#96)
|
||||
+ add macros support (`$aw_macro` and `$aw_macro_*` for calls)
|
||||
- fix vertical alignment (#94)
|
||||
- fix bug with invalid updates on `X-AW-Interval=1` for ExtScript and ExtUpgrade
|
||||
- fix bug with missing derivate vaules in ExtQuotes
|
||||
- fix possible plasma crash (#96)
|
||||
- fix possible undefined behaviour if no extensions was found by name
|
||||
* split dataengine sources to own library
|
||||
* allow to use screened double brakets inside functions
|
||||
|
||||
Ver.3.1.2:
|
||||
+ 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)
|
||||
|
404
CHANGELOG-RU
404
CHANGELOG-RU
@ -1,404 +0,0 @@
|
||||
Вер.3.1.0:
|
||||
+ добавлена поддержка шаблонов (#71)
|
||||
+ добавлена поддержка специальных функций (#71)
|
||||
+ добавлена отдельная директория для настроек (#72)
|
||||
+ произвольные картинки для баров (#80)
|
||||
+ произвольные значения для баров (#80)
|
||||
+ показывать ченджлог после обновления
|
||||
+ добавлен польский перевод (спасибо Mariusz Kocoń)
|
||||
+ использование Qt-5.6 плюшек
|
||||
- исправлено неправильное обновление размера тултипа в desktop panel (#74)
|
||||
- исправлено мигание баров (#81)
|
||||
- убрано использование tasks в пользу QProcess, чтобы избежать падения (#83)
|
||||
- исправления, вызванные новым Qt (5.6)
|
||||
- исправления, вызванные новой Plasma
|
||||
* вместо OWM теперь используется Yahoo! Weather (#73)
|
||||
* улучшена производительность путем оптимизированной подписки (#75)
|
||||
* улучшена производительность путем хранения QVariant вместо частых кастов (#75)
|
||||
* изменен принцип наименования баров (#80, ломает совместимость)
|
||||
* уведомление о большом использовании памяти изменено с 90 на 80 процентов
|
||||
* много рефакторинга
|
||||
|
||||
Вер.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:
|
||||
Первый релиз
|
@ -6,8 +6,8 @@ for more details. To avoid manual labor there is automatic cmake target named
|
||||
`clangformat` (see below). Some additional detail see below.
|
||||
|
||||
* Indent is only spaces. 4 spaces.
|
||||
* It is highly recommended to name private variables with `m_` prefix (`m_foo`).
|
||||
There is no exceptions for properties.
|
||||
* Any private variable should start with `m_` prefix (`m_foo`). The only one
|
||||
exception is `Ui` object which should be named as `ui`.
|
||||
* Avoid to create a large methods. Exception: if method contains lambda functions.
|
||||
* If some method is called only once, it is recommended to use lambda functions.
|
||||
Exception is `Q_INVOKABLE` methods.
|
||||
@ -54,7 +54,14 @@ for more details. To avoid manual labor there is automatic cmake target named
|
||||
```
|
||||
|
||||
* C-like `NULL`, use `nullptr` instead.
|
||||
* It is highly recommended to avoid implicit casts.
|
||||
* It is highly recommended to avoid implicit casts. Exception `nullptr` casts to
|
||||
boolean, e.g.:
|
||||
|
||||
```
|
||||
if (nullptr)
|
||||
qDebug() << "nullptr is true, wtf";
|
||||
```
|
||||
|
||||
* Abstract classes (which have at least one pure virtual method) are allowed.
|
||||
* Templates are allowed and recommended. Templates usually should be described
|
||||
inside header not source code file.
|
||||
|
@ -1,6 +1,9 @@
|
||||
awesome-widgets (ex-pytextmonitor)
|
||||
==================================
|
||||
|
||||
[](https://travis-ci.org/arcan1s/awesome-widgets)
|
||||
[](https://scan.coverity.com/projects/awesome-widgets)
|
||||
|
||||
Information
|
||||
-----------
|
||||
|
||||
|
@ -11,7 +11,7 @@ git submodule update --init --recursive
|
||||
|
||||
# build widget
|
||||
ARCHIVE="awesome-widgets"
|
||||
FILES="AUTHORS CHANGELOG CHANGELOG-RU COPYING packages patches"
|
||||
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"
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
pkgname=plasma5-applet-awesome-widgets
|
||||
_pkgname=awesome-widgets
|
||||
pkgver=3.1.1
|
||||
pkgver=3.2.1
|
||||
pkgrel=1
|
||||
pkgdesc="Collection of minimalistic Plasmoids which look like Awesome WM widgets (ex-PyTextMonitor)"
|
||||
arch=('i686' 'x86_64')
|
||||
@ -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=('1a4dc1d912b663dfd24d00712ab68f07')
|
||||
md5sums=('73da19c31aa95edd428ff5ce7b541ee1')
|
||||
backup=('etc/xdg/plasma-dataengine-extsysmon.conf')
|
||||
|
||||
prepare() {
|
||||
|
@ -1,45 +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,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}
|
@ -1,4 +1,4 @@
|
||||
diff --git a/sources/awesome-widget/package/contents/ui/advanced.qml b/sources/awesome-widget/package/contents/ui/advanced.qml
|
||||
diff --git a/sources/awesome-widget/package/contents/ui/advanced.qml b/sources/awesome-widget/package/contents/ui/advanced.qml
|
||||
index 01bcd58..1ec7ba6 100644
|
||||
--- a/sources/awesome-widget/package/contents/ui/advanced.qml
|
||||
+++ b/sources/awesome-widget/package/contents/ui/advanced.qml
|
||||
@ -168,9 +168,9 @@ index 6263b30..5f61d2a 100644
|
||||
}
|
||||
|
||||
|
||||
-bool AWConfigHelper::exportConfiguration(QObject *nativeConfig,
|
||||
-bool AWConfigHelper::exportConfiguration(const QObject *nativeConfig,
|
||||
- const QString fileName) const
|
||||
+void AWConfigHelper::exportConfiguration(QObject *nativeConfig) const
|
||||
+void AWConfigHelper::exportConfiguration(const QObject *nativeConfig) const
|
||||
{
|
||||
- qCDebug(LOG_AW) << "Selected filename" << fileName;
|
||||
-
|
||||
@ -302,17 +302,17 @@ index 912ac3d..dc51dfb 100644
|
||||
virtual ~AWConfigHelper();
|
||||
Q_INVOKABLE QString configurationDirectory() const;
|
||||
Q_INVOKABLE bool dropCache() const;
|
||||
- Q_INVOKABLE bool exportConfiguration(QObject *nativeConfig,
|
||||
- Q_INVOKABLE bool exportConfiguration(const QObject *nativeConfig,
|
||||
- const QString fileName) const;
|
||||
- Q_INVOKABLE QVariantMap importConfiguration(const QString fileName,
|
||||
- const bool importPlasmoid,
|
||||
- const bool importExtensions,
|
||||
- const bool importAdds) const;
|
||||
+ Q_INVOKABLE void exportConfiguration(QObject *nativeConfig) const;
|
||||
+ Q_INVOKABLE void exportConfiguration(const QObject *nativeConfig) const;
|
||||
+ Q_INVOKABLE QVariantMap importConfiguration() const;
|
||||
// dataengine
|
||||
Q_INVOKABLE QVariantMap readDataEngineConfiguration() const;
|
||||
Q_INVOKABLE void
|
||||
Q_INVOKABLE bool
|
||||
@@ -51,6 +47,7 @@ private:
|
||||
void copySettings(QSettings &from, QSettings &to) const;
|
||||
void readFile(QSettings &settings, const QString key,
|
||||
@ -352,3 +352,51 @@ 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,15 +20,11 @@
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
-Q_LOGGING_CATEGORY(LOG_AW, "org.kde.plasma.awesomewidget",
|
||||
- QtMsgType::QtWarningMsg)
|
||||
-Q_LOGGING_CATEGORY(LOG_DP, "org.kde.plasma.desktoppanel",
|
||||
- QtMsgType::QtWarningMsg)
|
||||
-Q_LOGGING_CATEGORY(LOG_ESM, "org.kde.plasma.extsysmon", QtMsgType::QtWarningMsg)
|
||||
-Q_LOGGING_CATEGORY(LOG_ESS, "org.kde.plasma.extsysmonsources",
|
||||
- QtMsgType::QtWarningMsg)
|
||||
-Q_LOGGING_CATEGORY(LOG_LIB, "org.kde.plasma.awesomewidgets",
|
||||
- QtMsgType::QtWarningMsg)
|
||||
+Q_LOGGING_CATEGORY(LOG_AW, "org.kde.plasma.awesomewidget")
|
||||
+Q_LOGGING_CATEGORY(LOG_DP, "org.kde.plasma.desktoppanel")
|
||||
+Q_LOGGING_CATEGORY(LOG_ESM, "org.kde.plasma.extsysmon")
|
||||
+Q_LOGGING_CATEGORY(LOG_ESM, "org.kde.plasma.extsysmonsources")
|
||||
+Q_LOGGING_CATEGORY(LOG_LIB, "org.kde.plasma.awesomewidgets")
|
||||
|
||||
|
||||
const QStringList getBuildData()
|
||||
diff --git a/sources/awesome-widget/plugin/awkeys.cpp b/sources/awesome-widget/plugin/awkeys.cpp
|
||||
index e5b9861..eb73073 100644
|
||||
--- a/sources/awesome-widget/plugin/awkeys.cpp
|
||||
+++ b/sources/awesome-widget/plugin/awkeys.cpp
|
||||
@@ -439,4 +439,4 @@ void AWKeys::dataUpdated(const QString &sourceName,
|
||||
{
|
||||
// run concurrent data update
|
||||
- QtConcurrent::run(m_threadPool, this, &AWKeys::setDataBySource, sourceName,
|
||||
+ QtConcurrent::run(this, &AWKeys::setDataBySource, sourceName,
|
||||
data);
|
||||
diff --git a/sources/libraries.cmake b/sources/libraries.cmake
|
||||
index 33192f7..46e2b1e 100644
|
||||
--- a/sources/libraries.cmake
|
||||
+++ b/sources/libraries.cmake
|
||||
@@ -2,7 +2,7 @@
|
||||
find_package(Gettext REQUIRED)
|
||||
|
||||
# main qt libraries
|
||||
-find_package(Qt5 5.4.0 REQUIRED COMPONENTS Core DBus Network Qml Test Widgets)
|
||||
+find_package(Qt5 5.3.0 REQUIRED COMPONENTS Core DBus Network Qml Test Widgets)
|
||||
add_definitions(
|
||||
${Qt5Core_DEFINITIONS} ${Qt5DBus_DEFINITIONS} ${Qt5Network_DEFINITIONS}
|
||||
${Qt5Qml_DEFINITIONS} ${Qt5Widgets_DEFINITIONS}
|
@ -16,7 +16,7 @@ index 43944ce..c679281 100644
|
||||
+++ b/sources/awdebug.h
|
||||
@@ -21,9 +21,13 @@
|
||||
|
||||
#include <QLoggingCategory>
|
||||
#include "version.h"
|
||||
|
||||
+#ifndef qCInfo
|
||||
+#define qCInfo qCDebug
|
||||
|
@ -11,7 +11,7 @@ index 3698602..42871c8 100644
|
||||
m_genericConfig = QString("%1/awesomewidgets/general.ini")
|
||||
.arg(QStandardPaths::writableLocation(
|
||||
QStandardPaths::GenericDataLocation));
|
||||
@@ -69,14 +69,14 @@ void AWUpdateHelper::checkUpdates(const bool showAnyway)
|
||||
@@ -69,15 +69,15 @@ void AWUpdateHelper::checkUpdates(const bool showAnyway)
|
||||
bool AWUpdateHelper::checkVersion()
|
||||
{
|
||||
QSettings settings(m_genericConfig, QSettings::IniFormat);
|
||||
@ -22,10 +22,11 @@ index 3698602..42871c8 100644
|
||||
// update version
|
||||
settings.setValue(QString("Version"), QString(VERSION));
|
||||
settings.sync();
|
||||
qCInfo(LOG_AW) << "Found version" << version << "actual one is"
|
||||
<< m_foundVersion;
|
||||
|
||||
qCInfo(LOG_AW) << "Found version" << version << "actual one is" << VERSION;
|
||||
- if (version != QVersionNumber::fromString(VERSION)) {
|
||||
+ if (version != QString(VERSION)) {
|
||||
- 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)
|
||||
@ -65,12 +66,12 @@ index 3698602..42871c8 100644
|
||||
@@ -128,8 +127,7 @@ void AWUpdateHelper::userReplyOnUpdates(QAbstractButton *button)
|
||||
|
||||
switch (ret) {
|
||||
case QMessageBox::Ok:
|
||||
case QMessageBox::AcceptRole:
|
||||
- QDesktopServices::openUrl(QString(RELEASES)
|
||||
- + m_foundVersion.toString());
|
||||
+ QDesktopServices::openUrl(QString(RELEASES) + m_foundVersion);
|
||||
break;
|
||||
case QMessageBox::Cancel:
|
||||
case QMessageBox::RejectRole:
|
||||
default:
|
||||
@@ -157,14 +155,23 @@ void AWUpdateHelper::versionReplyRecieved(QNetworkReply *reply,
|
||||
QVariantMap firstRelease = jsonDoc.toVariant().toList().first().toMap();
|
||||
@ -132,3 +133,16 @@ index 359cdb2..9c6a42d 100644
|
||||
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 Test Widgets)
|
||||
+find_package(Qt5 5.4.0 REQUIRED COMPONENTS Core DBus Network Qml Test Widgets)
|
||||
add_definitions(
|
||||
${Qt5Core_DEFINITIONS} ${Qt5DBus_DEFINITIONS} ${Qt5Network_DEFINITIONS}
|
||||
${Qt5Qml_DEFINITIONS} ${Qt5Widgets_DEFINITIONS}
|
||||
|
2
sources/3rdparty/fontdialog
vendored
2
sources/3rdparty/fontdialog
vendored
Submodule sources/3rdparty/fontdialog updated: ef47b1146e...e7bcf8ee85
@ -14,7 +14,7 @@ set(PROJECT_AUTHOR "Evgeniy Alekseev")
|
||||
set(PROJECT_CONTACT "esalexeev@gmail.com")
|
||||
set(PROJECT_LICENSE "GPL3")
|
||||
set(PROJECT_VERSION_MAJOR "3")
|
||||
set(PROJECT_VERSION_MINOR "1")
|
||||
set(PROJECT_VERSION_MINOR "2")
|
||||
set(PROJECT_VERSION_PATCH "1")
|
||||
set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
|
||||
# append git version if any
|
||||
@ -34,10 +34,8 @@ option(BUILD_DEB_PACKAGE "Build deb package" OFF)
|
||||
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_LOAD "Build with additional load" 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 "")
|
||||
@ -45,14 +43,14 @@ include(changelog.cmake)
|
||||
|
||||
# flags
|
||||
if (CMAKE_COMPILER_IS_GNUCXX)
|
||||
set(CMAKE_CXX_FLAGS "-Wall -Wno-cpp -std=c++14")
|
||||
set(CMAKE_CXX_FLAGS "-Wall -Wno-cpp -std=c++11")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
|
||||
set(CMAKE_CXX_FLAGS_OPTIMIZATION "-Ofast -DNDEBUG")
|
||||
# avoid newer gcc warnings
|
||||
add_definitions(-D_DEFAULT_SOURCE)
|
||||
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
set(CMAKE_CXX_FLAGS "-Wall -std=c++14 -stdlib=libc++")
|
||||
set(CMAKE_CXX_FLAGS "-Wall -std=c++11 -stdlib=libc++")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
|
||||
set(CMAKE_CXX_FLAGS_OPTIMIZATION "-Ofast -DNDEBUG")
|
||||
@ -69,18 +67,25 @@ endif ()
|
||||
|
||||
set(PROJECT_TRDPARTY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty)
|
||||
set(PROJECT_LIBRARY awesomewidgets)
|
||||
set(PROJECT_MONITORSOURCES extsysmonsources)
|
||||
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)
|
||||
add_subdirectory(awesomewidgets)
|
||||
add_subdirectory(extsysmonsources)
|
||||
add_subdirectory(extsysmon)
|
||||
if (BUILD_PLASMOIDS)
|
||||
add_subdirectory(awesome-widget)
|
||||
add_subdirectory(desktop-panel)
|
||||
add_subdirectory(translations)
|
||||
endif ()
|
||||
if (BUILD_TESTING)
|
||||
enable_testing()
|
||||
add_subdirectory(test)
|
||||
endif ()
|
||||
|
||||
include(packages-recipe.cmake)
|
||||
|
@ -17,7 +17,6 @@
|
||||
|
||||
|
||||
#include "awdebug.h"
|
||||
#include "version.h"
|
||||
|
||||
|
||||
Q_LOGGING_CATEGORY(LOG_AW, "org.kde.plasma.awesomewidget",
|
||||
@ -25,6 +24,8 @@ Q_LOGGING_CATEGORY(LOG_AW, "org.kde.plasma.awesomewidget",
|
||||
Q_LOGGING_CATEGORY(LOG_DP, "org.kde.plasma.desktoppanel",
|
||||
QtMsgType::QtWarningMsg)
|
||||
Q_LOGGING_CATEGORY(LOG_ESM, "org.kde.plasma.extsysmon", QtMsgType::QtWarningMsg)
|
||||
Q_LOGGING_CATEGORY(LOG_ESS, "org.kde.plasma.extsysmonsources",
|
||||
QtMsgType::QtWarningMsg)
|
||||
Q_LOGGING_CATEGORY(LOG_LIB, "org.kde.plasma.awesomewidgets",
|
||||
QtMsgType::QtWarningMsg)
|
||||
|
||||
@ -45,7 +46,10 @@ const QStringList getBuildData()
|
||||
metadata.append(QString(" AWESAPI: %1").arg(AWESAPI));
|
||||
metadata.append(QString(" AWEUAPI: %1").arg(AWEUAPI));
|
||||
metadata.append(QString(" AWEWAPI: %1").arg(AWEWAPI));
|
||||
metadata.append(QString(" AWEFAPI: %1").arg(AWEFAPI));
|
||||
metadata.append(QString(" REQUEST_TIMEOUT: %1").arg(REQUEST_TIMEOUT));
|
||||
metadata.append(QString(" TIME_KEYS: %1").arg(TIME_KEYS));
|
||||
metadata.append(QString(" STATIC_KEYS: %1").arg(STATIC_KEYS));
|
||||
// cmake properties
|
||||
metadata.append(QString("cmake properties:"));
|
||||
metadata.append(QString(" CMAKE_BUILD_TYPE: %1").arg(CMAKE_BUILD_TYPE));
|
||||
@ -75,9 +79,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_LOAD: %1").arg(PROP_LOAD));
|
||||
metadata.append(QString(" PROP_TEST: %1").arg(PROP_TEST));
|
||||
|
||||
return metadata;
|
||||
|
@ -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-" \
|
||||
@ -32,6 +34,7 @@
|
||||
Q_DECLARE_LOGGING_CATEGORY(LOG_AW)
|
||||
Q_DECLARE_LOGGING_CATEGORY(LOG_DP)
|
||||
Q_DECLARE_LOGGING_CATEGORY(LOG_ESM)
|
||||
Q_DECLARE_LOGGING_CATEGORY(LOG_ESS)
|
||||
Q_DECLARE_LOGGING_CATEGORY(LOG_LIB)
|
||||
|
||||
const QStringList getBuildData();
|
||||
|
@ -31,6 +31,9 @@ Item {
|
||||
AWActions {
|
||||
id: awActions
|
||||
}
|
||||
AWFormatterConfigFactory {
|
||||
id: awFormatter
|
||||
}
|
||||
|
||||
width: childrenRect.width
|
||||
height: childrenRect.height
|
||||
@ -61,7 +64,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 +93,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>")
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -263,7 +279,7 @@ Item {
|
||||
if (model[currentIndex]["regexp"] == "functions")
|
||||
tags.model = ["{{\n\n}}", "template{{\n\n}}",
|
||||
"aw_all<>{{}}", "aw_count<>{{}}", "aw_keys<>{{}}",
|
||||
"aw_names<>{{}}"]
|
||||
"aw_macro<>{{}}", "aw_names<>{{}}"]
|
||||
else
|
||||
tags.model = awKeys.dictKeys(true, model[currentIndex]["regexp"])
|
||||
if (debug) console.info("Init model", tags.model, "for", model[currentIndex]["label"])
|
||||
@ -281,10 +297,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 {
|
||||
@ -308,10 +323,15 @@ Item {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
QtControls.Button {
|
||||
width: parent.width * 3 / 5
|
||||
width: parent.width * 3 / 10
|
||||
text: i18n("Edit bars")
|
||||
onClicked: awKeys.editItem("graphicalitem")
|
||||
}
|
||||
QtControls.Button {
|
||||
width: parent.width * 3 / 10
|
||||
text: i18n("Formatters")
|
||||
onClicked: awFormatter.showDialog(awKeys.dictKeys(true))
|
||||
}
|
||||
QtControls.Button {
|
||||
width: parent.width * 2 / 5
|
||||
text: i18n("Preview")
|
||||
@ -319,7 +339,6 @@ Item {
|
||||
lock = false
|
||||
awKeys.initKeys(textPattern.text, plasmoid.configuration.interval,
|
||||
plasmoid.configuration.queueLimit, false)
|
||||
awKeys.needToBeUpdated()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ X-Plasma-RemoteLocation=
|
||||
X-KDE-PluginInfo-Author=Evgeniy Alekseev aka arcanis
|
||||
X-KDE-PluginInfo-Email=esalexeev@gmail.com
|
||||
X-KDE-PluginInfo-Name=org.kde.plasma.awesomewidget
|
||||
X-KDE-PluginInfo-Version=3.1.0
|
||||
X-KDE-PluginInfo-Version=3.2.1
|
||||
X-KDE-PluginInfo-Website=https://arcanis.me/projects/awesome-widgets/
|
||||
X-KDE-PluginInfo-Category=System Information
|
||||
X-KDE-PluginInfo-Depends=
|
||||
|
@ -11,9 +11,11 @@ include_directories(
|
||||
)
|
||||
|
||||
file(GLOB SUBPROJECT_SOURCE *.cpp ${PROJECT_TRDPARTY_DIR}/fontdialog/*.cpp ${CMAKE_SOURCE_DIR}/*.cpp)
|
||||
file(GLOB SUBPROJECT_UI *.ui)
|
||||
file(GLOB SUBPROJECT_NOTIFY *.notifyrc)
|
||||
|
||||
add_library(${PLUGIN_NAME} SHARED ${SUBPROJECT_SOURCE})
|
||||
qt5_wrap_ui(SUBPROJECT_UI_HEADER ${SUBPROJECT_UI})
|
||||
add_library(${PLUGIN_NAME} SHARED ${SUBPROJECT_SOURCE} ${SUBPROJECT_UI_HEADER})
|
||||
target_link_libraries(${PLUGIN_NAME} ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Kf5_LIBRARIES})
|
||||
|
||||
install(TARGETS ${PLUGIN_NAME} DESTINATION ${QML_INSTALL_DIR}/org/kde/plasma/private/awesomewidget)
|
||||
|
76
sources/awesome-widget/plugin/awabstractselector.cpp
Normal file
76
sources/awesome-widget/plugin/awabstractselector.cpp
Normal file
@ -0,0 +1,76 @@
|
||||
/***************************************************************************
|
||||
* This file is part of awesome-widgets *
|
||||
* *
|
||||
* awesome-widgets is free software: you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* awesome-widgets is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
#include "awabstractselector.h"
|
||||
#include "ui_awabstractselector.h"
|
||||
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
AWAbstractSelector::AWAbstractSelector(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, ui(new Ui::AWAbstractSelector)
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
|
||||
ui->setupUi(this);
|
||||
|
||||
connect(ui->comboBox_key, SIGNAL(currentIndexChanged(int)), this,
|
||||
SIGNAL(selectionChanged()));
|
||||
connect(ui->comboBox_value, SIGNAL(currentIndexChanged(int)), this,
|
||||
SIGNAL(selectionChanged()));
|
||||
}
|
||||
|
||||
|
||||
AWAbstractSelector::~AWAbstractSelector()
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
||||
QPair<QString, QString> AWAbstractSelector::current() const
|
||||
{
|
||||
QString key = ui->comboBox_key->currentText();
|
||||
QString value = ui->comboBox_value->currentText();
|
||||
|
||||
return QPair<QString, QString>(key, value);
|
||||
}
|
||||
|
||||
|
||||
void AWAbstractSelector::init(const QStringList keys, const QStringList values,
|
||||
const QPair<QString, QString> current)
|
||||
{
|
||||
if ((!keys.contains(current.first)) || (!values.contains(current.second))) {
|
||||
qCWarning(LOG_AW) << "Invalid current value" << current
|
||||
<< "not found in default ones";
|
||||
return;
|
||||
}
|
||||
qCDebug(LOG_AW) << "Init selector with keys" << keys << "and values"
|
||||
<< values << "and current ones are" << current;
|
||||
|
||||
// set data
|
||||
ui->comboBox_key->clear();
|
||||
ui->comboBox_key->addItems(keys);
|
||||
ui->comboBox_value->clear();
|
||||
ui->comboBox_value->addItems(values);
|
||||
|
||||
// set current values
|
||||
ui->comboBox_key->setCurrentText(current.first);
|
||||
ui->comboBox_value->setCurrentText(current.second);
|
||||
}
|
49
sources/awesome-widget/plugin/awabstractselector.h
Normal file
49
sources/awesome-widget/plugin/awabstractselector.h
Normal file
@ -0,0 +1,49 @@
|
||||
/***************************************************************************
|
||||
* This file is part of awesome-widgets *
|
||||
* *
|
||||
* awesome-widgets is free software: you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* awesome-widgets is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef AWABSTRACTSELECTOR_H
|
||||
#define AWABSTRACTSELECTOR_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class AWAbstractSelector;
|
||||
}
|
||||
|
||||
class AWAbstractSelector : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AWAbstractSelector(QWidget *parent = nullptr);
|
||||
virtual ~AWAbstractSelector();
|
||||
QPair<QString, QString> current() const;
|
||||
void init(const QStringList keys, const QStringList values,
|
||||
const QPair<QString, QString> current);
|
||||
|
||||
signals:
|
||||
void selectionChanged();
|
||||
|
||||
private:
|
||||
Ui::AWAbstractSelector *ui = nullptr;
|
||||
};
|
||||
|
||||
|
||||
#endif /* AWABSTRACTSELECTOR_H */
|
36
sources/awesome-widget/plugin/awabstractselector.ui
Normal file
36
sources/awesome-widget/plugin/awabstractselector.ui
Normal file
@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>AWAbstractSelector</class>
|
||||
<widget class="QWidget" name="AWAbstractSelector">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>25</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QComboBox" name="comboBox_key"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="comboBox_value"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
@ -28,7 +28,6 @@
|
||||
|
||||
#include "awdebug.h"
|
||||
#include "awupdatehelper.h"
|
||||
#include "version.h"
|
||||
|
||||
|
||||
AWActions::AWActions(QObject *parent)
|
||||
@ -154,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();
|
||||
|
@ -19,6 +19,7 @@
|
||||
#ifndef AWACTIONS_H
|
||||
#define AWACTIONS_H
|
||||
|
||||
#include <QMap>
|
||||
#include <QObject>
|
||||
|
||||
|
||||
|
@ -69,7 +69,7 @@ bool AWConfigHelper::dropCache() const
|
||||
}
|
||||
|
||||
|
||||
bool AWConfigHelper::exportConfiguration(QObject *nativeConfig,
|
||||
bool AWConfigHelper::exportConfiguration(const QObject *nativeConfig,
|
||||
const QString fileName) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Selected filename" << fileName;
|
||||
@ -77,8 +77,8 @@ bool AWConfigHelper::exportConfiguration(QObject *nativeConfig,
|
||||
QSettings settings(fileName, QSettings::IniFormat);
|
||||
|
||||
// plasmoid configuration
|
||||
QQmlPropertyMap *configuration
|
||||
= static_cast<QQmlPropertyMap *>(nativeConfig);
|
||||
const QQmlPropertyMap *configuration
|
||||
= static_cast<const QQmlPropertyMap *>(nativeConfig);
|
||||
settings.beginGroup(QString("plasmoid"));
|
||||
for (auto key : configuration->keys()) {
|
||||
QVariant value = configuration->value(key);
|
||||
@ -110,6 +110,9 @@ bool AWConfigHelper::exportConfiguration(QObject *nativeConfig,
|
||||
readFile(settings, QString("weathers"),
|
||||
QString("%1/weather/awesomewidgets-extweather-ids.json")
|
||||
.arg(m_baseDir));
|
||||
// formatter settings
|
||||
readFile(settings, QString("formatters"),
|
||||
QString("%1/formatters/formatters.ini").arg(m_baseDir));
|
||||
settings.endGroup();
|
||||
|
||||
// sync settings
|
||||
@ -150,6 +153,9 @@ QVariantMap AWConfigHelper::importConfiguration(const QString fileName,
|
||||
writeFile(settings, QString("weathers"),
|
||||
QString("%1/weather/awesomewidgets-extweather-ids.json")
|
||||
.arg(m_baseDir));
|
||||
// formatter settings
|
||||
writeFile(settings, QString("formatters"),
|
||||
QString("%1/formatters/formatters.ini").arg(m_baseDir));
|
||||
settings.endGroup();
|
||||
}
|
||||
|
||||
@ -201,7 +207,7 @@ QVariantMap AWConfigHelper::readDataEngineConfiguration() const
|
||||
}
|
||||
|
||||
|
||||
void AWConfigHelper::writeDataEngineConfiguration(
|
||||
bool AWConfigHelper::writeDataEngineConfiguration(
|
||||
const QVariantMap configuration) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Configuration" << configuration;
|
||||
@ -228,6 +234,8 @@ void AWConfigHelper::writeDataEngineConfiguration(
|
||||
settings.endGroup();
|
||||
|
||||
settings.sync();
|
||||
|
||||
return (settings.status() == QSettings::NoError);
|
||||
}
|
||||
|
||||
|
||||
@ -295,7 +303,7 @@ void AWConfigHelper::readFile(QSettings &settings, const QString key,
|
||||
file.close();
|
||||
settings.setValue(key, text);
|
||||
} else {
|
||||
qCWarning(LOG_LIB) << "Could not open" << file.fileName();
|
||||
qCWarning(LOG_AW) << "Could not open" << file.fileName();
|
||||
}
|
||||
}
|
||||
|
||||
@ -316,6 +324,6 @@ void AWConfigHelper::writeFile(QSettings &settings, const QString key,
|
||||
out.flush();
|
||||
file.close();
|
||||
} else {
|
||||
qCWarning(LOG_LIB) << "Could not open" << file.fileName();
|
||||
qCWarning(LOG_AW) << "Could not open" << file.fileName();
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
#include <QObject>
|
||||
#include <QStandardPaths>
|
||||
#include <QVariant>
|
||||
|
||||
|
||||
class QSettings;
|
||||
@ -34,7 +35,7 @@ public:
|
||||
virtual ~AWConfigHelper();
|
||||
Q_INVOKABLE QString configurationDirectory() const;
|
||||
Q_INVOKABLE bool dropCache() const;
|
||||
Q_INVOKABLE bool exportConfiguration(QObject *nativeConfig,
|
||||
Q_INVOKABLE bool exportConfiguration(const QObject *nativeConfig,
|
||||
const QString fileName) const;
|
||||
Q_INVOKABLE QVariantMap importConfiguration(const QString fileName,
|
||||
const bool importPlasmoid,
|
||||
@ -42,7 +43,7 @@ public:
|
||||
const bool importAdds) const;
|
||||
// dataengine
|
||||
Q_INVOKABLE QVariantMap readDataEngineConfiguration() const;
|
||||
Q_INVOKABLE void
|
||||
Q_INVOKABLE bool
|
||||
writeDataEngineConfiguration(const QVariantMap configuration) const;
|
||||
|
||||
private:
|
||||
@ -62,7 +63,7 @@ private:
|
||||
QStringList m_dirs = QStringList()
|
||||
<< QString("desktops") << QString("quotes")
|
||||
<< QString("scripts") << QString("upgrade")
|
||||
<< QString("weather");
|
||||
<< QString("weather") << QString("formatters");
|
||||
};
|
||||
|
||||
|
||||
|
@ -19,11 +19,11 @@
|
||||
|
||||
#include <KI18n/KLocalizedString>
|
||||
|
||||
#include <QtConcurrent/QtConcurrent>
|
||||
#include <QBuffer>
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsView>
|
||||
#include <QPixmap>
|
||||
#include <QtConcurrent/QtConcurrent>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
@ -36,13 +36,13 @@ AWDataAggregator::AWDataAggregator(QObject *parent)
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
|
||||
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;
|
||||
m_boundaries[QString("cpuTooltip")] = 100.0;
|
||||
m_boundaries[QString("cpuclTooltip")] = 4000.0;
|
||||
m_boundaries[QString("memTooltip")] = 100.0;
|
||||
m_boundaries[QString("swapTooltip")] = 100.0;
|
||||
m_boundaries[QString("downkbTooltip")] = 1.0;
|
||||
m_boundaries[QString("upkbTooltip")] = 1.0;
|
||||
m_boundaries[QString("batTooltip")] = 100.0;
|
||||
|
||||
initScene();
|
||||
connect(this, SIGNAL(updateData(const QVariantHash &)), this,
|
||||
@ -54,7 +54,7 @@ AWDataAggregator::~AWDataAggregator()
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
|
||||
delete toolTipScene;
|
||||
delete m_toolTipScene;
|
||||
}
|
||||
|
||||
|
||||
@ -62,7 +62,7 @@ QList<float> AWDataAggregator::getData(const QString key) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Key" << key;
|
||||
|
||||
return data[QString("%1Tooltip").arg(key)];
|
||||
return m_values[QString("%1Tooltip").arg(key)];
|
||||
}
|
||||
|
||||
|
||||
@ -84,41 +84,41 @@ void AWDataAggregator::setParameters(QVariantMap settings)
|
||||
qCDebug(LOG_AW) << "Settings" << settings;
|
||||
|
||||
// cast from QVariantMap to QVariantHash without data lost
|
||||
configuration = qvariant_cast<QVariantHash>(settings);
|
||||
m_configuration = qvariant_cast<QVariantHash>(settings);
|
||||
|
||||
m_enablePopup = configuration[QString("notify")].toBool();
|
||||
m_enablePopup = m_configuration[QString("notify")].toBool();
|
||||
|
||||
counts = 0;
|
||||
counts += configuration[QString("cpuTooltip")].toInt();
|
||||
counts += configuration[QString("cpuclTooltip")].toInt();
|
||||
counts += configuration[QString("memTooltip")].toInt();
|
||||
counts += configuration[QString("swapTooltip")].toInt();
|
||||
counts += configuration[QString("downkbTooltip")].toInt();
|
||||
counts += configuration[QString("batTooltip")].toInt();
|
||||
m_counts = 0;
|
||||
m_counts += m_configuration[QString("cpuTooltip")].toInt();
|
||||
m_counts += m_configuration[QString("cpuclTooltip")].toInt();
|
||||
m_counts += m_configuration[QString("memTooltip")].toInt();
|
||||
m_counts += m_configuration[QString("swapTooltip")].toInt();
|
||||
m_counts += m_configuration[QString("downkbTooltip")].toInt();
|
||||
m_counts += m_configuration[QString("batTooltip")].toInt();
|
||||
// resize tooltip image
|
||||
toolTipView->resize(100 * counts, 105);
|
||||
m_toolTipView->resize(100 * m_counts, 105);
|
||||
|
||||
requiredKeys.clear();
|
||||
if (configuration[QString("cpuTooltip")].toBool())
|
||||
if (m_configuration[QString("cpuTooltip")].toBool())
|
||||
requiredKeys.append(QString("cpuTooltip"));
|
||||
if (configuration[QString("cpuclTooltip")].toBool())
|
||||
if (m_configuration[QString("cpuclTooltip")].toBool())
|
||||
requiredKeys.append(QString("cpuclTooltip"));
|
||||
if (configuration[QString("memTooltip")].toBool())
|
||||
if (m_configuration[QString("memTooltip")].toBool())
|
||||
requiredKeys.append(QString("memTooltip"));
|
||||
if (configuration[QString("swapTooltip")].toBool())
|
||||
if (m_configuration[QString("swapTooltip")].toBool())
|
||||
requiredKeys.append(QString("swapTooltip"));
|
||||
if (configuration[QString("downkbTooltip")].toBool())
|
||||
if (m_configuration[QString("downkbTooltip")].toBool())
|
||||
requiredKeys.append(QString("downkbTooltip"));
|
||||
if (configuration[QString("upkbTooltip")].toBool())
|
||||
if (m_configuration[QString("upkbTooltip")].toBool())
|
||||
requiredKeys.append(QString("upkbTooltip"));
|
||||
if (configuration[QString("batTooltip")].toBool())
|
||||
if (m_configuration[QString("batTooltip")].toBool())
|
||||
requiredKeys.append(QString("batTooltip"));
|
||||
|
||||
// background
|
||||
toolTipScene->setBackgroundBrush(
|
||||
configuration[QString("useTooltipBackground")].toBool()
|
||||
m_toolTipScene->setBackgroundBrush(
|
||||
m_configuration[QString("useTooltipBackground")].toBool()
|
||||
? QBrush(QColor(
|
||||
configuration[QString("tooltipBackground")].toString()))
|
||||
m_configuration[QString("tooltipBackground")].toString()))
|
||||
: QBrush(Qt::NoBrush));
|
||||
}
|
||||
|
||||
@ -126,43 +126,44 @@ void AWDataAggregator::setParameters(QVariantMap settings)
|
||||
QPixmap AWDataAggregator::tooltipImage()
|
||||
{
|
||||
// create image
|
||||
toolTipScene->clear();
|
||||
m_toolTipScene->clear();
|
||||
QPen pen;
|
||||
bool down = false;
|
||||
for (auto key : requiredKeys) {
|
||||
// create frame
|
||||
float normX = 100.0f / static_cast<float>(data[key].count());
|
||||
float normY = 100.0f / (1.5f * boundaries[key]);
|
||||
float normX = 100.0f / static_cast<float>(m_values[key].count());
|
||||
float normY = 100.0f / (1.5f * m_boundaries[key]);
|
||||
float shift = requiredKeys.indexOf(key) * 100.0f;
|
||||
if (down)
|
||||
shift -= 100.0;
|
||||
// apply pen color
|
||||
if (key != QString("batTooltip"))
|
||||
pen.setColor(
|
||||
QColor(configuration[QString("%1Color").arg(key)].toString()));
|
||||
pen.setColor(QColor(
|
||||
m_configuration[QString("%1Color").arg(key)].toString()));
|
||||
// paint data inside frame
|
||||
for (int j = 0; j < data[key].count() - 1; j++) {
|
||||
for (int j = 0; j < m_values[key].count() - 1; j++) {
|
||||
// some magic here
|
||||
float x1 = j * normX + shift;
|
||||
float y1 = -fabs(data[key].at(j)) * normY + 5.0f;
|
||||
float y1 = -fabs(m_values[key].at(j)) * normY + 5.0f;
|
||||
float x2 = (j + 1) * normX + shift;
|
||||
float y2 = -fabs(data[key].at(j + 1)) * normY + 5.0f;
|
||||
float y2 = -fabs(m_values[key].at(j + 1)) * normY + 5.0f;
|
||||
if (key == QString("batTooltip")) {
|
||||
if (data[key].at(j + 1) > 0)
|
||||
pen.setColor(QColor(
|
||||
configuration[QString("batTooltipColor")].toString()));
|
||||
if (m_values[key].at(j + 1) > 0)
|
||||
pen.setColor(
|
||||
QColor(m_configuration[QString("batTooltipColor")]
|
||||
.toString()));
|
||||
else
|
||||
pen.setColor(
|
||||
QColor(configuration[QString("batInTooltipColor")]
|
||||
QColor(m_configuration[QString("batInTooltipColor")]
|
||||
.toString()));
|
||||
}
|
||||
toolTipScene->addLine(x1, y1, x2, y2, pen);
|
||||
m_toolTipScene->addLine(x1, y1, x2, y2, pen);
|
||||
}
|
||||
if (key == QString("downkbTooltip"))
|
||||
down = true;
|
||||
}
|
||||
|
||||
return toolTipView->grab();
|
||||
return m_toolTipView->grab();
|
||||
}
|
||||
|
||||
|
||||
@ -182,12 +183,12 @@ void AWDataAggregator::checkValue(const QString source, const float value,
|
||||
|
||||
if (value >= 0.0) {
|
||||
if ((m_enablePopup) && (value > extremum)
|
||||
&& (data[source].last() < extremum))
|
||||
&& (m_values[source].last() < extremum))
|
||||
return AWActions::sendNotification(QString("event"),
|
||||
notificationText(source, value));
|
||||
} else {
|
||||
if ((m_enablePopup) && (value < extremum)
|
||||
&& (data[source].last() > extremum))
|
||||
&& (m_values[source].last() > extremum))
|
||||
return AWActions::sendNotification(QString("event"),
|
||||
notificationText(source, value));
|
||||
}
|
||||
@ -208,13 +209,13 @@ void AWDataAggregator::checkValue(const QString source, const QString current,
|
||||
|
||||
void AWDataAggregator::initScene()
|
||||
{
|
||||
toolTipScene = new QGraphicsScene(nullptr);
|
||||
toolTipView = new QGraphicsView(toolTipScene);
|
||||
toolTipView->setStyleSheet(QString("background: transparent"));
|
||||
toolTipView->setContentsMargins(0, 0, 0, 0);
|
||||
toolTipView->setFrameShape(QFrame::NoFrame);
|
||||
toolTipView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
toolTipView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
m_toolTipScene = new QGraphicsScene(nullptr);
|
||||
m_toolTipView = new QGraphicsView(m_toolTipScene);
|
||||
m_toolTipView->setStyleSheet(QString("background: transparent"));
|
||||
m_toolTipView->setContentsMargins(0, 0, 0, 0);
|
||||
m_toolTipView->setFrameShape(QFrame::NoFrame);
|
||||
m_toolTipView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
m_toolTipView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
}
|
||||
|
||||
|
||||
@ -257,7 +258,7 @@ void AWDataAggregator::setData(const QVariantHash &values)
|
||||
// do not log these arguments
|
||||
// battery update requires info is AC online or not
|
||||
setData(values[QString("ac")].toString()
|
||||
== configuration[QString("acOnline")],
|
||||
== m_configuration[QString("acOnline")],
|
||||
QString("batTooltip"), values[QString("bat")].toFloat());
|
||||
// usual case
|
||||
setData(QString("cpuTooltip"), values[QString("cpu")].toFloat(), 90.0);
|
||||
@ -268,13 +269,13 @@ void AWDataAggregator::setData(const QVariantHash &values)
|
||||
setData(QString("upkbTooltip"), values[QString("upkb")].toFloat());
|
||||
// additional check for network device
|
||||
[this](const QString value) {
|
||||
checkValue(QString("netdev"), currentNetworkDevice, value);
|
||||
currentNetworkDevice = value;
|
||||
checkValue(QString("netdev"), m_currentNetworkDevice, value);
|
||||
m_currentNetworkDevice = value;
|
||||
}(values[QString("netdev")].toString());
|
||||
// additional check for GPU load
|
||||
[this](const float value) {
|
||||
checkValue(QString("gpu"), value, 90.0);
|
||||
currentGPULoad = value;
|
||||
m_currentGPULoad = value;
|
||||
}(values[QString("gpu")].toFloat());
|
||||
}
|
||||
|
||||
@ -285,27 +286,27 @@ void AWDataAggregator::setData(const QString &source, float value,
|
||||
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 (m_values[source].count() == 0)
|
||||
m_values[source].append(0.0);
|
||||
else if (m_values[source].count()
|
||||
> m_configuration[QString("tooltipNumber")].toInt())
|
||||
m_values[source].removeFirst();
|
||||
if (std::isnan(value))
|
||||
value = 0.0;
|
||||
|
||||
// notifications
|
||||
checkValue(source, value, extremum);
|
||||
|
||||
data[source].append(value);
|
||||
m_values[source].append(value);
|
||||
if (source == QString("downkbTooltip")) {
|
||||
QList<float> netValues
|
||||
= data[QString("downkbTooltip")] + data[QString("upkbTooltip")];
|
||||
QList<float> netValues = m_values[QString("downkbTooltip")]
|
||||
+ m_values[QString("upkbTooltip")];
|
||||
// to avoid inf value of normY
|
||||
netValues << 1.0;
|
||||
boundaries[QString("downkbTooltip")]
|
||||
m_boundaries[QString("downkbTooltip")]
|
||||
= 1.2f * *std::max_element(netValues.cbegin(), netValues.cend());
|
||||
boundaries[QString("upkbTooltip")]
|
||||
= boundaries[QString("downkbTooltip")];
|
||||
m_boundaries[QString("upkbTooltip")]
|
||||
= m_boundaries[QString("downkbTooltip")];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,8 +49,8 @@ private slots:
|
||||
|
||||
private:
|
||||
// ui
|
||||
QGraphicsScene *toolTipScene = nullptr;
|
||||
QGraphicsView *toolTipView = nullptr;
|
||||
QGraphicsScene *m_toolTipScene = nullptr;
|
||||
QGraphicsView *m_toolTipView = nullptr;
|
||||
void checkValue(const QString source, const float value,
|
||||
const float extremum) const;
|
||||
void checkValue(const QString source, const QString current,
|
||||
@ -65,12 +65,12 @@ private:
|
||||
// different signature for battery device
|
||||
void setData(const bool dontInvert, const QString &source, float value);
|
||||
// variables
|
||||
int counts = 0;
|
||||
QVariantHash configuration;
|
||||
float currentGPULoad = 0.0;
|
||||
QString currentNetworkDevice = QString("lo");
|
||||
QHash<QString, float> boundaries;
|
||||
QHash<QString, QList<float>> data;
|
||||
int m_counts = 0;
|
||||
QVariantHash m_configuration;
|
||||
float m_currentGPULoad = 0.0;
|
||||
QString m_currentNetworkDevice = QString("lo");
|
||||
QHash<QString, float> m_boundaries;
|
||||
QHash<QString, QList<float>> m_values;
|
||||
bool m_enablePopup = false;
|
||||
QStringList requiredKeys;
|
||||
};
|
||||
|
@ -42,7 +42,6 @@ void AWDataEngineAggregator::clear()
|
||||
disconnectSources();
|
||||
m_dataEngines.clear();
|
||||
delete m_consumer;
|
||||
m_consumer = nullptr;
|
||||
}
|
||||
|
||||
|
||||
@ -82,7 +81,7 @@ void AWDataEngineAggregator::dropSource(const QString source)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Source" << source;
|
||||
|
||||
// FIXME there is no possibility to check to which dataengine source
|
||||
// HACK there is no possibility to check to which dataengine source
|
||||
// connected we will try to disconnect it from systemmonitor and extsysmon
|
||||
m_dataEngines[QString("systemmonitor")]->disconnectSource(source, parent());
|
||||
m_dataEngines[QString("extsysmon")]->disconnectSource(source, parent());
|
||||
|
@ -21,7 +21,7 @@
|
||||
|
||||
#include "awactions.h"
|
||||
#include "awconfighelper.h"
|
||||
#include "awdataengineaggregator.h"
|
||||
#include "awformatterconfigfactory.h"
|
||||
#include "awkeys.h"
|
||||
|
||||
|
||||
@ -31,5 +31,7 @@ void AWPlugin::registerTypes(const char *uri)
|
||||
|
||||
qmlRegisterType<AWActions>(uri, 1, 0, "AWActions");
|
||||
qmlRegisterType<AWConfigHelper>(uri, 1, 0, "AWConfigHelper");
|
||||
qmlRegisterType<AWFormatterConfigFactory>(uri, 1, 0,
|
||||
"AWFormatterConfigFactory");
|
||||
qmlRegisterType<AWKeys>(uri, 1, 0, "AWKeys");
|
||||
}
|
||||
|
181
sources/awesome-widget/plugin/awformatterconfig.cpp
Normal file
181
sources/awesome-widget/plugin/awformatterconfig.cpp
Normal file
@ -0,0 +1,181 @@
|
||||
/***************************************************************************
|
||||
* This file is part of awesome-widgets *
|
||||
* *
|
||||
* awesome-widgets is free software: you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* awesome-widgets is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
#include "awformatterconfig.h"
|
||||
#include "ui_awformatterconfig.h"
|
||||
|
||||
#include <KI18n/KLocalizedString>
|
||||
|
||||
#include <QPushButton>
|
||||
|
||||
#include "awabstractselector.h"
|
||||
#include "awdebug.h"
|
||||
#include "awformatterhelper.h"
|
||||
|
||||
|
||||
AWFormatterConfig::AWFormatterConfig(QWidget *parent, const QStringList keys)
|
||||
: QDialog(parent)
|
||||
, ui(new Ui::AWFormatterConfig)
|
||||
, m_keys(keys)
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
|
||||
ui->setupUi(this);
|
||||
m_editButton
|
||||
= ui->buttonBox->addButton(i18n("Edit"), QDialogButtonBox::ActionRole);
|
||||
init();
|
||||
|
||||
connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
|
||||
connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
||||
connect(m_editButton, SIGNAL(clicked(bool)), this, SLOT(editFormatters()));
|
||||
}
|
||||
|
||||
|
||||
AWFormatterConfig::~AWFormatterConfig()
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
|
||||
clearSelectors();
|
||||
|
||||
delete m_helper;
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
||||
void AWFormatterConfig::showDialog()
|
||||
{
|
||||
// update dialog
|
||||
updateDialog();
|
||||
// exec dialog
|
||||
return execDialog();
|
||||
}
|
||||
|
||||
|
||||
void AWFormatterConfig::editFormatters()
|
||||
{
|
||||
m_helper->editItems();
|
||||
updateDialog();
|
||||
}
|
||||
|
||||
|
||||
void AWFormatterConfig::updateUi()
|
||||
{
|
||||
QPair<QString, QString> current
|
||||
= static_cast<AWAbstractSelector *>(sender())->current();
|
||||
int index
|
||||
= m_selectors.indexOf(static_cast<AWAbstractSelector *>(sender()));
|
||||
|
||||
if ((current.first.isEmpty()) && (current.second.isEmpty())) {
|
||||
if (sender() == m_selectors.last())
|
||||
return;
|
||||
AWAbstractSelector *selector = m_selectors.takeAt(index);
|
||||
ui->verticalLayout->removeWidget(selector);
|
||||
selector->deleteLater();
|
||||
} else {
|
||||
if (sender() != m_selectors.last())
|
||||
return;
|
||||
auto keys = initKeys();
|
||||
addSelector(keys.first, keys.second, QPair<QString, QString>());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AWFormatterConfig::addSelector(const QStringList &keys,
|
||||
const QStringList &values,
|
||||
const QPair<QString, QString> ¤t)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Add selector with keys" << keys << "values" << values
|
||||
<< "and current ones" << current;
|
||||
|
||||
AWAbstractSelector *selector
|
||||
= new AWAbstractSelector(ui->scrollAreaWidgetContents);
|
||||
selector->init(keys, values, current);
|
||||
ui->verticalLayout->insertWidget(ui->verticalLayout->count() - 1, selector);
|
||||
connect(selector, SIGNAL(selectionChanged()), this, SLOT(updateUi()));
|
||||
m_selectors.append(selector);
|
||||
}
|
||||
|
||||
|
||||
void AWFormatterConfig::clearSelectors()
|
||||
{
|
||||
for (auto selector : m_selectors) {
|
||||
disconnect(selector, SIGNAL(selectionChanged()), this,
|
||||
SLOT(updateUi()));
|
||||
ui->verticalLayout->removeWidget(selector);
|
||||
selector->deleteLater();
|
||||
}
|
||||
m_selectors.clear();
|
||||
}
|
||||
|
||||
|
||||
void AWFormatterConfig::execDialog()
|
||||
{
|
||||
int ret = exec();
|
||||
QHash<QString, QString> data;
|
||||
for (auto selector : m_selectors) {
|
||||
QPair<QString, QString> select = selector->current();
|
||||
if (select.first.isEmpty())
|
||||
continue;
|
||||
data[select.first] = select.second;
|
||||
}
|
||||
|
||||
// save configuration if required
|
||||
switch (ret) {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
default:
|
||||
m_helper->writeFormatters(data);
|
||||
m_helper->writeFormatters(data.keys());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AWFormatterConfig::init()
|
||||
{
|
||||
delete m_helper;
|
||||
m_helper = new AWFormatterHelper(this);
|
||||
}
|
||||
|
||||
|
||||
QPair<QStringList, QStringList> AWFormatterConfig::initKeys() const
|
||||
{
|
||||
// we are adding empty string at the start
|
||||
QStringList keys = QStringList() << QString("");
|
||||
keys.append(m_keys);
|
||||
keys.sort();
|
||||
QStringList knownFormatters = QStringList() << QString("");
|
||||
knownFormatters.append(m_helper->knownFormatters());
|
||||
knownFormatters.sort();
|
||||
|
||||
return QPair<QStringList, QStringList>(keys, knownFormatters);
|
||||
}
|
||||
|
||||
|
||||
void AWFormatterConfig::updateDialog()
|
||||
{
|
||||
clearSelectors();
|
||||
QHash<QString, QString> appliedFormatters = m_helper->getFormatters();
|
||||
auto keys = initKeys();
|
||||
|
||||
for (auto key : appliedFormatters.keys())
|
||||
addSelector(keys.first, keys.second,
|
||||
QPair<QString, QString>(key, appliedFormatters[key]));
|
||||
// empty one
|
||||
addSelector(keys.first, keys.second, QPair<QString, QString>());
|
||||
}
|
64
sources/awesome-widget/plugin/awformatterconfig.h
Normal file
64
sources/awesome-widget/plugin/awformatterconfig.h
Normal file
@ -0,0 +1,64 @@
|
||||
/***************************************************************************
|
||||
* This file is part of awesome-widgets *
|
||||
* *
|
||||
* awesome-widgets is free software: you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* awesome-widgets is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef AWFORMATTERCONFIG_H
|
||||
#define AWFORMATTERCONFIG_H
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
|
||||
class AWAbstractSelector;
|
||||
class AWFormatterHelper;
|
||||
namespace Ui
|
||||
{
|
||||
class AWFormatterConfig;
|
||||
}
|
||||
|
||||
class AWFormatterConfig : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AWFormatterConfig(QWidget *parent = nullptr,
|
||||
const QStringList keys = QStringList());
|
||||
virtual ~AWFormatterConfig();
|
||||
Q_INVOKABLE void showDialog();
|
||||
|
||||
private slots:
|
||||
void editFormatters();
|
||||
void updateUi();
|
||||
|
||||
private:
|
||||
QPushButton *m_editButton = nullptr;
|
||||
Ui::AWFormatterConfig *ui = nullptr;
|
||||
AWFormatterHelper *m_helper = nullptr;
|
||||
QList<AWAbstractSelector *> m_selectors;
|
||||
// properties
|
||||
QStringList m_keys;
|
||||
// methods
|
||||
void addSelector(const QStringList &keys, const QStringList &values,
|
||||
const QPair<QString, QString> ¤t);
|
||||
void clearSelectors();
|
||||
void execDialog();
|
||||
void init();
|
||||
QPair<QStringList, QStringList> initKeys() const;
|
||||
void updateDialog();
|
||||
};
|
||||
|
||||
|
||||
#endif /* AWFORMATTERCONFIG_H */
|
93
sources/awesome-widget/plugin/awformatterconfig.ui
Normal file
93
sources/awesome-widget/plugin/awformatterconfig.ui
Normal file
@ -0,0 +1,93 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>AWFormatterConfig</class>
|
||||
<widget class="QDialog" name="AWFormatterConfig">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QScrollArea" name="scrollArea">
|
||||
<property name="widgetResizable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<widget class="QWidget" name="scrollAreaWidgetContents">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>384</width>
|
||||
<height>249</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Close|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>AWFormatterConfig</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>AWFormatterConfig</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
@ -15,55 +15,28 @@
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#include "updatesource.h"
|
||||
#include "awformatterconfigfactory.h"
|
||||
|
||||
#include "awdebug.h"
|
||||
#include "awformatterconfig.h"
|
||||
|
||||
|
||||
UpdateSource::UpdateSource(QObject *parent, const QStringList args)
|
||||
: AbstractExtSysMonSource(parent, args)
|
||||
AWFormatterConfigFactory::AWFormatterConfigFactory(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
Q_ASSERT(args.count() == 0);
|
||||
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
}
|
||||
|
||||
|
||||
UpdateSource::~UpdateSource()
|
||||
AWFormatterConfigFactory::~AWFormatterConfigFactory()
|
||||
{
|
||||
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
}
|
||||
|
||||
|
||||
QVariant UpdateSource::data(QString source)
|
||||
void AWFormatterConfigFactory::showDialog(const QStringList keys)
|
||||
{
|
||||
qCDebug(LOG_ESM) << "Source" << source;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
QVariantMap UpdateSource::initialData(QString source) const
|
||||
{
|
||||
qCDebug(LOG_ESM) << "Source" << source;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
QStringList UpdateSource::sources() const
|
||||
{
|
||||
QStringList sources;
|
||||
sources.append(QString("update"));
|
||||
|
||||
return sources;
|
||||
AWFormatterConfig *config = new AWFormatterConfig(nullptr, keys);
|
||||
config->showDialog();
|
||||
config->deleteLater();
|
||||
}
|
@ -15,24 +15,24 @@
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef UPDATESOURCE_H
|
||||
#define UPDATESOURCE_H
|
||||
|
||||
#ifndef AWFORMATTERCONFIGFACTORY_H
|
||||
#define AWFORMATTERCONFIGFACTORY_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include "abstractextsysmonsource.h"
|
||||
|
||||
|
||||
class UpdateSource : public AbstractExtSysMonSource
|
||||
class AWFormatterConfigFactory : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
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 AWFormatterConfigFactory(QObject *parent = nullptr);
|
||||
virtual ~AWFormatterConfigFactory();
|
||||
Q_INVOKABLE void showDialog(const QStringList keys);
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif /* UPDATESOURCE_H */
|
||||
#endif /* AWFORMATTERCONFIGFACTORY_H */
|
331
sources/awesome-widget/plugin/awformatterhelper.cpp
Normal file
331
sources/awesome-widget/plugin/awformatterhelper.cpp
Normal file
@ -0,0 +1,331 @@
|
||||
/***************************************************************************
|
||||
* 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 <KI18n/KLocalizedString>
|
||||
|
||||
#include <QDir>
|
||||
#include <QInputDialog>
|
||||
#include <QSettings>
|
||||
|
||||
#include "awdatetimeformatter.h"
|
||||
#include "awdebug.h"
|
||||
#include "awfloatformatter.h"
|
||||
#include "awlistformatter.h"
|
||||
#include "awnoformatter.h"
|
||||
#include "awscriptformatter.h"
|
||||
#include "awstringformatter.h"
|
||||
|
||||
|
||||
AWFormatterHelper::AWFormatterHelper(QWidget *parent)
|
||||
: AbstractExtItemAggregator(parent, QString("formatters"))
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
|
||||
initItems();
|
||||
}
|
||||
|
||||
|
||||
AWFormatterHelper::~AWFormatterHelper()
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
|
||||
m_formatters.clear();
|
||||
m_formattersClasses.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();
|
||||
}
|
||||
|
||||
|
||||
QHash<QString, QString> AWFormatterHelper::getFormatters() const
|
||||
{
|
||||
QHash<QString, QString> map;
|
||||
for (auto tag : m_formatters.keys())
|
||||
map[tag] = m_formatters[tag]->name();
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
QList<AbstractExtItem *> AWFormatterHelper::items() const
|
||||
{
|
||||
QList<AbstractExtItem *> converted;
|
||||
for (auto item : m_formattersClasses.values())
|
||||
converted.append(item);
|
||||
|
||||
return converted;
|
||||
}
|
||||
|
||||
|
||||
QStringList AWFormatterHelper::knownFormatters() const
|
||||
{
|
||||
return m_formattersClasses.keys();
|
||||
}
|
||||
|
||||
|
||||
bool AWFormatterHelper::writeFormatters(const QStringList keys) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Remove formatters" << keys;
|
||||
|
||||
QString fileName = QString("%1/awesomewidgets/formatters/formatters.ini")
|
||||
.arg(QStandardPaths::writableLocation(
|
||||
QStandardPaths::GenericDataLocation));
|
||||
QSettings settings(fileName, QSettings::IniFormat);
|
||||
qCInfo(LOG_AW) << "Configuration file" << fileName;
|
||||
|
||||
settings.beginGroup(QString("Formatters"));
|
||||
QStringList foundKeys = settings.childKeys();
|
||||
for (auto key : foundKeys) {
|
||||
if (keys.contains(key))
|
||||
continue;
|
||||
settings.remove(key);
|
||||
}
|
||||
settings.endGroup();
|
||||
|
||||
settings.sync();
|
||||
|
||||
return (settings.status() == QSettings::NoError);
|
||||
}
|
||||
|
||||
|
||||
bool AWFormatterHelper::writeFormatters(
|
||||
const QHash<QString, QString> configuration) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Write configuration" << configuration;
|
||||
|
||||
QString fileName = QString("%1/awesomewidgets/formatters/formatters.ini")
|
||||
.arg(QStandardPaths::writableLocation(
|
||||
QStandardPaths::GenericDataLocation));
|
||||
QSettings settings(fileName, QSettings::IniFormat);
|
||||
qCInfo(LOG_AW) << "Configuration file" << fileName;
|
||||
|
||||
settings.beginGroup(QString("Formatters"));
|
||||
for (auto key : configuration.keys())
|
||||
settings.setValue(key, configuration[key]);
|
||||
settings.endGroup();
|
||||
|
||||
settings.sync();
|
||||
|
||||
return (settings.status() == QSettings::NoError);
|
||||
}
|
||||
|
||||
|
||||
void AWFormatterHelper::editItems()
|
||||
{
|
||||
repaintList();
|
||||
int ret = exec();
|
||||
qCInfo(LOG_AW) << "Dialog returns" << ret;
|
||||
}
|
||||
|
||||
|
||||
AWAbstractFormatter::FormatterClass
|
||||
AWFormatterHelper::defineFormatterClass(const QString stringType) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Define formatter class for" << stringType;
|
||||
|
||||
AWAbstractFormatter::FormatterClass formatter
|
||||
= AWAbstractFormatter::FormatterClass::NoFormat;
|
||||
if (stringType == QString("DateTime"))
|
||||
formatter = AWAbstractFormatter::FormatterClass::DateTime;
|
||||
else if (stringType == QString("Float"))
|
||||
formatter = AWAbstractFormatter::FormatterClass::Float;
|
||||
else if (stringType == QString("List"))
|
||||
formatter = AWAbstractFormatter::FormatterClass::List;
|
||||
else if (stringType == QString("NoFormat"))
|
||||
;
|
||||
else if (stringType == QString("Script"))
|
||||
formatter = AWAbstractFormatter::FormatterClass::Script;
|
||||
else if (stringType == QString("String"))
|
||||
formatter = AWAbstractFormatter::FormatterClass::String;
|
||||
else
|
||||
qCWarning(LOG_AW) << "Unknown formatter" << stringType;
|
||||
|
||||
return formatter;
|
||||
}
|
||||
|
||||
|
||||
void AWFormatterHelper::initFormatters()
|
||||
{
|
||||
m_formattersClasses.clear();
|
||||
|
||||
for (int i = m_directories.count() - 1; i >= 0; i--) {
|
||||
QStringList files
|
||||
= QDir(m_directories.at(i)).entryList(QDir::Files, QDir::Name);
|
||||
for (auto file : files) {
|
||||
if (!file.endsWith(QString(".desktop")))
|
||||
continue;
|
||||
qCInfo(LOG_AW) << "Found file" << file << "in"
|
||||
<< m_directories.at(i);
|
||||
QString filePath
|
||||
= QString("%1/%2").arg(m_directories.at(i)).arg(file);
|
||||
auto metadata = readMetadata(filePath);
|
||||
QString name = metadata.first;
|
||||
if (m_formattersClasses.contains(name))
|
||||
continue;
|
||||
|
||||
|
||||
switch (metadata.second) {
|
||||
case AWAbstractFormatter::FormatterClass::DateTime:
|
||||
m_formattersClasses[name]
|
||||
= new AWDateTimeFormatter(this, filePath);
|
||||
break;
|
||||
case AWAbstractFormatter::FormatterClass::Float:
|
||||
m_formattersClasses[name]
|
||||
= new AWFloatFormatter(this, filePath);
|
||||
break;
|
||||
case AWAbstractFormatter::FormatterClass::List:
|
||||
m_formattersClasses[name] = new AWListFormatter(this, filePath);
|
||||
break;
|
||||
case AWAbstractFormatter::FormatterClass::Script:
|
||||
m_formattersClasses[name]
|
||||
= new AWScriptFormatter(this, filePath);
|
||||
break;
|
||||
case AWAbstractFormatter::FormatterClass::String:
|
||||
m_formattersClasses[name]
|
||||
= new AWStringFormatter(this, filePath);
|
||||
break;
|
||||
case AWAbstractFormatter::FormatterClass::NoFormat:
|
||||
m_formattersClasses[name] = new AWNoFormatter(this, filePath);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AWFormatterHelper::initKeys()
|
||||
{
|
||||
m_formatters.clear();
|
||||
|
||||
QStringList configs = QStandardPaths::locateAll(
|
||||
QStandardPaths::GenericDataLocation,
|
||||
QString("awesomewidgets/formatters/formatters.ini"));
|
||||
|
||||
for (auto fileName : configs) {
|
||||
QSettings settings(fileName, QSettings::IniFormat);
|
||||
qCInfo(LOG_AW) << "Configuration file" << settings.fileName();
|
||||
|
||||
settings.beginGroup(QString("Formatters"));
|
||||
QStringList keys = settings.childKeys();
|
||||
for (auto key : keys) {
|
||||
QString name = settings.value(key).toString();
|
||||
qCInfo(LOG_AW) << "Found formatter" << name << "for key" << key
|
||||
<< "in" << settings.fileName();
|
||||
if (name.isEmpty()) {
|
||||
qCInfo(LOG_AW) << "Skip empty formatter for" << key;
|
||||
continue;
|
||||
}
|
||||
if (!m_formattersClasses.contains(name)) {
|
||||
qCWarning(LOG_AW) << "Invalid formatter" << name << "found in"
|
||||
<< key;
|
||||
continue;
|
||||
}
|
||||
m_formatters[key] = m_formattersClasses[name];
|
||||
}
|
||||
settings.endGroup();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AWFormatterHelper::installDirectories()
|
||||
{
|
||||
// create directory at $HOME
|
||||
QString localDir = QString("%1/awesomewidgets/formatters")
|
||||
.arg(QStandardPaths::writableLocation(
|
||||
QStandardPaths::GenericDataLocation));
|
||||
QDir localDirectory;
|
||||
if (localDirectory.mkpath(localDir))
|
||||
qCInfo(LOG_AW) << "Created directory" << localDir;
|
||||
|
||||
m_directories = QStandardPaths::locateAll(
|
||||
QStandardPaths::GenericDataLocation,
|
||||
QString("awesomewidgets/formatters"), QStandardPaths::LocateDirectory);
|
||||
}
|
||||
|
||||
|
||||
QPair<QString, AWAbstractFormatter::FormatterClass>
|
||||
AWFormatterHelper::readMetadata(const QString filePath) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Read initial parameters from" << filePath;
|
||||
|
||||
QSettings settings(filePath, QSettings::IniFormat);
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
QString name = settings.value(QString("Name"), filePath).toString();
|
||||
QString type
|
||||
= settings.value(QString("X-AW-Type"), QString("NoFormat")).toString();
|
||||
AWAbstractFormatter::FormatterClass formatter = defineFormatterClass(type);
|
||||
settings.endGroup();
|
||||
|
||||
return QPair<QString, AWAbstractFormatter::FormatterClass>(name, formatter);
|
||||
}
|
||||
|
||||
|
||||
void AWFormatterHelper::doCreateItem()
|
||||
{
|
||||
QStringList selection = QStringList()
|
||||
<< QString("NoFormat") << QString("DateTime")
|
||||
<< QString("Float") << QString("List")
|
||||
<< QString("Script") << QString("String");
|
||||
bool ok;
|
||||
QString select = QInputDialog::getItem(
|
||||
this, i18n("Select type"), i18n("Type:"), selection, 0, false, &ok);
|
||||
if (!ok) {
|
||||
qCWarning(LOG_AW) << "No type selected";
|
||||
return;
|
||||
}
|
||||
|
||||
qCInfo(LOG_AW) << "Selected type" << select;
|
||||
AWAbstractFormatter::FormatterClass formatter
|
||||
= defineFormatterClass(select);
|
||||
switch (formatter) {
|
||||
case AWAbstractFormatter::FormatterClass::DateTime:
|
||||
return createItem<AWDateTimeFormatter>();
|
||||
case AWAbstractFormatter::FormatterClass::Float:
|
||||
return createItem<AWFloatFormatter>();
|
||||
case AWAbstractFormatter::FormatterClass::List:
|
||||
return createItem<AWListFormatter>();
|
||||
case AWAbstractFormatter::FormatterClass::Script:
|
||||
return createItem<AWScriptFormatter>();
|
||||
case AWAbstractFormatter::FormatterClass::String:
|
||||
return createItem<AWStringFormatter>();
|
||||
case AWAbstractFormatter::FormatterClass::NoFormat:
|
||||
return createItem<AWNoFormatter>();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AWFormatterHelper::initItems()
|
||||
{
|
||||
installDirectories();
|
||||
initFormatters();
|
||||
initKeys();
|
||||
}
|
66
sources/awesome-widget/plugin/awformatterhelper.h
Normal file
66
sources/awesome-widget/plugin/awformatterhelper.h
Normal file
@ -0,0 +1,66 @@
|
||||
/***************************************************************************
|
||||
* This file is part of awesome-widgets *
|
||||
* *
|
||||
* awesome-widgets is free software: you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* awesome-widgets is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef AWFORMATTERHELPER_H
|
||||
#define AWFORMATTERHELPER_H
|
||||
|
||||
#include "abstractextitemaggregator.h"
|
||||
|
||||
#include "awabstractformatter.h"
|
||||
|
||||
|
||||
class AWAbstractFormatter;
|
||||
|
||||
class AWFormatterHelper : public AbstractExtItemAggregator
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AWFormatterHelper(QWidget *parent = nullptr);
|
||||
virtual ~AWFormatterHelper();
|
||||
QString convert(const QVariant &value, const QString &name) const;
|
||||
QStringList definedFormatters() const;
|
||||
QHash<QString, QString> getFormatters() const;
|
||||
QList<AbstractExtItem *> items() const;
|
||||
QStringList knownFormatters() const;
|
||||
bool writeFormatters(const QStringList keys) const;
|
||||
bool writeFormatters(const QHash<QString, QString> configuration) const;
|
||||
|
||||
public slots:
|
||||
void editItems();
|
||||
|
||||
private:
|
||||
// methods
|
||||
AWAbstractFormatter::FormatterClass
|
||||
defineFormatterClass(const QString stringType) const;
|
||||
void initFormatters();
|
||||
void initKeys();
|
||||
void installDirectories();
|
||||
QPair<QString, AWAbstractFormatter::FormatterClass>
|
||||
readMetadata(const QString filePath) const;
|
||||
// parent methods
|
||||
void doCreateItem();
|
||||
void initItems();
|
||||
// properties
|
||||
QStringList m_directories;
|
||||
QHash<QString, AWAbstractFormatter *> m_formatters;
|
||||
QHash<QString, AWAbstractFormatter *> m_formattersClasses;
|
||||
};
|
||||
|
||||
|
||||
#endif /* AWFORMATTERHELPER_H */
|
@ -38,8 +38,8 @@ bool AWKeyCache::addKeyToCache(const QString type, const QString key)
|
||||
|
||||
cache.beginGroup(type);
|
||||
QStringList cachedValues;
|
||||
for (auto key : cache.allKeys())
|
||||
cachedValues.append(cache.value(key).toString());
|
||||
for (auto number : cache.allKeys())
|
||||
cachedValues.append(cache.value(number).toString());
|
||||
|
||||
if (type == QString("hdd")) {
|
||||
QStringList allDevices
|
||||
@ -51,6 +51,7 @@ bool AWKeyCache::addKeyToCache(const QString type, const QString key)
|
||||
if (cachedValues.contains(device))
|
||||
continue;
|
||||
qCInfo(LOG_AW) << "Found new key" << device << "for type" << type;
|
||||
cachedValues.append(device);
|
||||
cache.setValue(
|
||||
QString("%1").arg(cache.allKeys().count(), 3, 10, QChar('0')),
|
||||
device);
|
||||
@ -63,6 +64,7 @@ bool AWKeyCache::addKeyToCache(const QString type, const QString key)
|
||||
if (cachedValues.contains(device))
|
||||
continue;
|
||||
qCInfo(LOG_AW) << "Found new key" << device << "for type" << type;
|
||||
cachedValues.append(device);
|
||||
cache.setValue(
|
||||
QString("%1").arg(cache.allKeys().count(), 3, 10, QChar('0')),
|
||||
device);
|
||||
@ -138,10 +140,12 @@ QStringList AWKeyCache::getRequiredKeys(const QStringList &keys,
|
||||
if (used.contains(QString("swaptotgb")))
|
||||
used << QString("swapgb") << QString("swapfreegb");
|
||||
// network keys
|
||||
QStringList netKeys(QStringList() << QString("up") << QString("upkb")
|
||||
<< QString("upunits") << QString("down")
|
||||
<< QString("downkb")
|
||||
<< QString("downunits"));
|
||||
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;
|
||||
|
@ -25,7 +25,6 @@
|
||||
#include "awdebug.h"
|
||||
#include "awkeycache.h"
|
||||
#include "awpatternfunctions.h"
|
||||
#include "version.h"
|
||||
// extensions
|
||||
#include "extquotes.h"
|
||||
#include "extscript.h"
|
||||
@ -46,11 +45,11 @@ AWKeyOperations::~AWKeyOperations()
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
|
||||
// extensions
|
||||
delete graphicalItems;
|
||||
delete extQuotes;
|
||||
delete extScripts;
|
||||
delete extUpgrade;
|
||||
delete extWeather;
|
||||
delete m_graphicalItems;
|
||||
delete m_extQuotes;
|
||||
delete m_extScripts;
|
||||
delete m_extUpgrade;
|
||||
delete m_extWeather;
|
||||
}
|
||||
|
||||
|
||||
@ -80,19 +79,19 @@ QStringList AWKeyOperations::dictKeys() const
|
||||
{
|
||||
QStringList allKeys;
|
||||
// weather
|
||||
for (int i = extWeather->activeItems().count() - 1; i >= 0; i--) {
|
||||
for (int i = m_extWeather->activeItems().count() - 1; i >= 0; i--) {
|
||||
allKeys.append(
|
||||
extWeather->activeItems().at(i)->tag(QString("weatherId")));
|
||||
m_extWeather->activeItems().at(i)->tag(QString("weatherId")));
|
||||
allKeys.append(
|
||||
extWeather->activeItems().at(i)->tag(QString("weather")));
|
||||
m_extWeather->activeItems().at(i)->tag(QString("weather")));
|
||||
allKeys.append(
|
||||
extWeather->activeItems().at(i)->tag(QString("humidity")));
|
||||
m_extWeather->activeItems().at(i)->tag(QString("humidity")));
|
||||
allKeys.append(
|
||||
extWeather->activeItems().at(i)->tag(QString("pressure")));
|
||||
m_extWeather->activeItems().at(i)->tag(QString("pressure")));
|
||||
allKeys.append(
|
||||
extWeather->activeItems().at(i)->tag(QString("temperature")));
|
||||
m_extWeather->activeItems().at(i)->tag(QString("temperature")));
|
||||
allKeys.append(
|
||||
extWeather->activeItems().at(i)->tag(QString("timestamp")));
|
||||
m_extWeather->activeItems().at(i)->tag(QString("timestamp")));
|
||||
}
|
||||
// cpuclock & cpu
|
||||
for (int i = QThread::idealThreadCount() - 1; i >= 0; i--) {
|
||||
@ -124,8 +123,12 @@ QStringList AWKeyOperations::dictKeys() const
|
||||
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));
|
||||
}
|
||||
@ -137,32 +140,35 @@ QStringList AWKeyOperations::dictKeys() const
|
||||
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--)
|
||||
for (int i = m_extUpgrade->activeItems().count() - 1; i >= 0; i--)
|
||||
allKeys.append(
|
||||
extUpgrade->activeItems().at(i)->tag(QString("pkgcount")));
|
||||
m_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")));
|
||||
for (int i = m_extQuotes->activeItems().count() - 1; i >= 0; i--) {
|
||||
allKeys.append(m_extQuotes->activeItems().at(i)->tag(QString("ask")));
|
||||
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")));
|
||||
m_extQuotes->activeItems().at(i)->tag(QString("askchg")));
|
||||
allKeys.append(
|
||||
extQuotes->activeItems().at(i)->tag(QString("percbidchg")));
|
||||
allKeys.append(extQuotes->activeItems().at(i)->tag(QString("price")));
|
||||
m_extQuotes->activeItems().at(i)->tag(QString("percaskchg")));
|
||||
allKeys.append(m_extQuotes->activeItems().at(i)->tag(QString("bid")));
|
||||
allKeys.append(
|
||||
extQuotes->activeItems().at(i)->tag(QString("pricechg")));
|
||||
m_extQuotes->activeItems().at(i)->tag(QString("bidchg")));
|
||||
allKeys.append(
|
||||
extQuotes->activeItems().at(i)->tag(QString("percpricechg")));
|
||||
m_extQuotes->activeItems().at(i)->tag(QString("percbidchg")));
|
||||
allKeys.append(m_extQuotes->activeItems().at(i)->tag(QString("price")));
|
||||
allKeys.append(
|
||||
m_extQuotes->activeItems().at(i)->tag(QString("pricechg")));
|
||||
allKeys.append(
|
||||
m_extQuotes->activeItems().at(i)->tag(QString("percpricechg")));
|
||||
}
|
||||
// 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--)
|
||||
for (int i = m_extScripts->activeItems().count() - 1; i >= 0; i--)
|
||||
allKeys.append(
|
||||
graphicalItems->activeItems().at(i)->tag(QString("bar")));
|
||||
m_extScripts->activeItems().at(i)->tag(QString("custom")));
|
||||
// bars
|
||||
for (int i = m_graphicalItems->activeItems().count() - 1; i >= 0; i--)
|
||||
allKeys.append(
|
||||
m_graphicalItems->activeItems().at(i)->tag(QString("bar")));
|
||||
// static keys
|
||||
QStringList staticKeys = QString(STATIC_KEYS).split(QChar(','));
|
||||
std::for_each(staticKeys.cbegin(), staticKeys.cend(),
|
||||
@ -178,7 +184,7 @@ GraphicalItem *AWKeyOperations::giByKey(const QString key) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Looking for item" << key;
|
||||
|
||||
return graphicalItems->itemByTag(key, QString("bar"));
|
||||
return m_graphicalItems->itemByTag(key, QString("bar"));
|
||||
}
|
||||
|
||||
|
||||
@ -186,38 +192,57 @@ 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()]);
|
||||
QString stripped = key;
|
||||
stripped.remove(QRegExp(QString("\\d+")));
|
||||
QString output;
|
||||
|
||||
return QString("(none)");
|
||||
if (key.startsWith(QString("bar"))) {
|
||||
AbstractExtItem *item = m_graphicalItems->itemByTag(key, stripped);
|
||||
if (item)
|
||||
output = item->uniq();
|
||||
} else if (key.startsWith(QString("custom"))) {
|
||||
AbstractExtItem *item = m_extScripts->itemByTag(key, stripped);
|
||||
if (item)
|
||||
output = item->uniq();
|
||||
} else if (key.contains(QRegExp(QString("^hdd[rw]")))) {
|
||||
output = m_devices[QString("disk")]
|
||||
[key.remove(QRegExp(QString("hdd[rw]"))).toInt()];
|
||||
} else if (key.contains(QRegExp(
|
||||
QString("^hdd([0-9]|mb|gb|freemb|freegb|totmb|totgb)")))) {
|
||||
output
|
||||
= m_devices[QString("mount")]
|
||||
[key
|
||||
.remove(QRegExp(QString(
|
||||
"^hdd([0-9]|mb|gb|freemb|freegb|totmb|totgb)")))
|
||||
.toInt()];
|
||||
} else if (key.startsWith(QString("hddtemp"))) {
|
||||
output
|
||||
= m_devices[QString("hdd")][key.remove(QString("hddtemp")).toInt()];
|
||||
} else if (key.contains(QRegExp(QString("^(down|up)[0-9]")))) {
|
||||
output = m_devices[QString("net")]
|
||||
[key.remove(QRegExp(QString("^(down|up)"))).toInt()];
|
||||
} else if (key.startsWith(QString("pkgcount"))) {
|
||||
AbstractExtItem *item = m_extUpgrade->itemByTag(key, stripped);
|
||||
if (item)
|
||||
output = item->uniq();
|
||||
} else if (key.contains(
|
||||
QRegExp(QString("(^|perc)(ask|bid|price)(chg|)")))) {
|
||||
AbstractExtItem *item = m_extQuotes->itemByTag(key, stripped);
|
||||
if (item)
|
||||
output = item->uniq();
|
||||
} else if (key.contains(QRegExp(QString(
|
||||
"(weather|weatherId|humidity|pressure|temperature)")))) {
|
||||
AbstractExtItem *item = m_extWeather->itemByTag(key, stripped);
|
||||
if (item)
|
||||
output = item->uniq();
|
||||
} else if (key.startsWith(QString("temp"))) {
|
||||
output
|
||||
= m_devices[QString("temp")][key.remove(QString("temp")).toInt()];
|
||||
} else {
|
||||
output = QString("(none)");
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
@ -243,16 +268,16 @@ void AWKeyOperations::editItem(const QString type)
|
||||
QStringList keys = dictKeys().filter(QRegExp(
|
||||
QString("^(cpu(?!cl).*|gpu$|mem$|swap$|hdd[0-9].*|bat.*)")));
|
||||
keys.sort();
|
||||
graphicalItems->setConfigArgs(keys);
|
||||
return graphicalItems->editItems();
|
||||
m_graphicalItems->setConfigArgs(keys);
|
||||
return m_graphicalItems->editItems();
|
||||
} else if (type == QString("extquotes")) {
|
||||
return extQuotes->editItems();
|
||||
return m_extQuotes->editItems();
|
||||
} else if (type == QString("extscript")) {
|
||||
return extScripts->editItems();
|
||||
return m_extScripts->editItems();
|
||||
} else if (type == QString("extupgrade")) {
|
||||
return extUpgrade->editItems();
|
||||
return m_extUpgrade->editItems();
|
||||
} else if (type == QString("extweather")) {
|
||||
return extWeather->editItems();
|
||||
return m_extWeather->editItems();
|
||||
}
|
||||
}
|
||||
|
||||
@ -294,23 +319,26 @@ 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;
|
||||
delete m_graphicalItems;
|
||||
m_graphicalItems = nullptr;
|
||||
delete m_extQuotes;
|
||||
m_extQuotes = nullptr;
|
||||
delete m_extScripts;
|
||||
m_extScripts = nullptr;
|
||||
delete m_extUpgrade;
|
||||
m_extUpgrade = nullptr;
|
||||
delete m_extWeather;
|
||||
m_extWeather = nullptr;
|
||||
// create
|
||||
graphicalItems
|
||||
m_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"));
|
||||
m_extQuotes = new ExtItemAggregator<ExtQuotes>(nullptr, QString("quotes"));
|
||||
m_extScripts
|
||||
= new ExtItemAggregator<ExtScript>(nullptr, QString("scripts"));
|
||||
m_extUpgrade
|
||||
= new ExtItemAggregator<ExtUpgrade>(nullptr, QString("upgrade"));
|
||||
m_extWeather
|
||||
= new ExtItemAggregator<ExtWeather>(nullptr, QString("weather"));
|
||||
|
||||
// init
|
||||
QStringList allKeys = dictKeys();
|
||||
@ -320,6 +348,7 @@ void AWKeyOperations::reinitKeys()
|
||||
m_pattern = AWPatternFunctions::insertKeyCount(m_pattern, allKeys);
|
||||
m_pattern = AWPatternFunctions::insertKeyNames(m_pattern, allKeys);
|
||||
m_pattern = AWPatternFunctions::insertKeys(m_pattern, allKeys);
|
||||
m_pattern = AWPatternFunctions::insertMacros(m_pattern);
|
||||
// wrap templates
|
||||
m_pattern = AWPatternFunctions::expandTemplates(m_pattern);
|
||||
|
||||
|
@ -69,11 +69,11 @@ private:
|
||||
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;
|
||||
ExtItemAggregator<GraphicalItem> *m_graphicalItems = nullptr;
|
||||
ExtItemAggregator<ExtQuotes> *m_extQuotes = nullptr;
|
||||
ExtItemAggregator<ExtScript> *m_extScripts = nullptr;
|
||||
ExtItemAggregator<ExtUpgrade> *m_extUpgrade = nullptr;
|
||||
ExtItemAggregator<ExtWeather> *m_extWeather = nullptr;
|
||||
// variables
|
||||
QHash<QString, QStringList> m_devices;
|
||||
QString m_pattern;
|
||||
|
@ -17,10 +17,11 @@
|
||||
|
||||
#include "awkeys.h"
|
||||
|
||||
#include <QtConcurrent/QtConcurrent>
|
||||
#include <QJSEngine>
|
||||
#include <QRegExp>
|
||||
#include <QThread>
|
||||
#include <QTimer>
|
||||
#include <QtConcurrent/QtConcurrent>
|
||||
|
||||
#include "awdataaggregator.h"
|
||||
#include "awdataengineaggregator.h"
|
||||
@ -30,7 +31,6 @@
|
||||
#include "awkeysaggregator.h"
|
||||
#include "awpatternfunctions.h"
|
||||
#include "graphicalitem.h"
|
||||
#include "version.h"
|
||||
|
||||
|
||||
AWKeys::AWKeys(QObject *parent)
|
||||
@ -44,23 +44,26 @@ AWKeys::AWKeys(QObject *parent)
|
||||
// thread pool
|
||||
m_threadPool = new QThreadPool(this);
|
||||
|
||||
aggregator = new AWKeysAggregator(this);
|
||||
dataAggregator = new AWDataAggregator(this);
|
||||
dataEngineAggregator = new AWDataEngineAggregator(this);
|
||||
keyOperator = new AWKeyOperations(this);
|
||||
m_aggregator = new AWKeysAggregator(this);
|
||||
m_dataAggregator = new AWDataAggregator(this);
|
||||
m_dataEngineAggregator = new AWDataEngineAggregator(this);
|
||||
m_keyOperator = new AWKeyOperations(this);
|
||||
|
||||
m_timer = new QTimer(this);
|
||||
m_timer->setSingleShot(false);
|
||||
|
||||
// update key data if required
|
||||
connect(keyOperator, SIGNAL(updateKeys(QStringList)), this,
|
||||
connect(m_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,
|
||||
connect(m_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)));
|
||||
m_dataEngineAggregator, SLOT(dropSource(QString)));
|
||||
// transfer signal from dataengine to update source list
|
||||
connect(dataEngineAggregator, SIGNAL(deviceAdded(const QString &)),
|
||||
keyOperator, SLOT(addDevice(const QString &)));
|
||||
connect(m_dataEngineAggregator, SIGNAL(deviceAdded(const QString &)),
|
||||
m_keyOperator, SLOT(addDevice(const QString &)));
|
||||
}
|
||||
|
||||
|
||||
@ -68,12 +71,15 @@ AWKeys::~AWKeys()
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
|
||||
m_timer->stop();
|
||||
delete m_timer;
|
||||
|
||||
// core
|
||||
delete dataEngineAggregator;
|
||||
delete m_dataEngineAggregator;
|
||||
delete m_threadPool;
|
||||
delete aggregator;
|
||||
delete dataAggregator;
|
||||
delete keyOperator;
|
||||
delete m_aggregator;
|
||||
delete m_dataAggregator;
|
||||
delete m_keyOperator;
|
||||
}
|
||||
|
||||
|
||||
@ -83,7 +89,7 @@ void AWKeys::initDataAggregator(const QVariantMap tooltipParams)
|
||||
|
||||
// store parameters to generate m_requiredKeys
|
||||
m_tooltipParams = tooltipParams;
|
||||
dataAggregator->setParameters(m_tooltipParams);
|
||||
m_dataAggregator->setParameters(m_tooltipParams);
|
||||
}
|
||||
|
||||
|
||||
@ -99,11 +105,15 @@ void AWKeys::initKeys(const QString currentPattern, const int interval,
|
||||
m_threadPool->setMaxThreadCount(limit == 0 ? QThread::idealThreadCount()
|
||||
: limit);
|
||||
// child objects
|
||||
keyOperator->setPattern(currentPattern);
|
||||
keyOperator->updateCache();
|
||||
dataEngineAggregator->clear();
|
||||
m_aggregator->initFormatters();
|
||||
m_keyOperator->setPattern(currentPattern);
|
||||
m_keyOperator->updateCache();
|
||||
m_dataEngineAggregator->clear();
|
||||
m_dataEngineAggregator->initDataEngines(interval);
|
||||
|
||||
return dataEngineAggregator->initDataEngines(interval);
|
||||
// timer
|
||||
m_timer->setInterval(interval);
|
||||
m_timer->start();
|
||||
}
|
||||
|
||||
|
||||
@ -111,7 +121,7 @@ void AWKeys::setAggregatorProperty(const QString key, const QVariant value)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Key" << key << "with value" << value;
|
||||
|
||||
aggregator->setProperty(key.toUtf8().constData(), value);
|
||||
m_aggregator->setProperty(key.toUtf8().constData(), value);
|
||||
}
|
||||
|
||||
|
||||
@ -125,7 +135,7 @@ void AWKeys::setWrapNewLines(const bool wrap)
|
||||
|
||||
void AWKeys::updateCache()
|
||||
{
|
||||
return keyOperator->updateCache();
|
||||
return m_keyOperator->updateCache();
|
||||
}
|
||||
|
||||
|
||||
@ -134,7 +144,7 @@ QStringList AWKeys::dictKeys(const bool sorted, const QString regexp) const
|
||||
qCDebug(LOG_AW) << "Should be sorted" << sorted << "and filter applied"
|
||||
<< regexp;
|
||||
|
||||
QStringList allKeys = keyOperator->dictKeys();
|
||||
QStringList allKeys = m_keyOperator->dictKeys();
|
||||
// sort if required
|
||||
if (sorted)
|
||||
allKeys.sort();
|
||||
@ -145,7 +155,7 @@ QStringList AWKeys::dictKeys(const bool sorted, const QString regexp) const
|
||||
|
||||
QStringList AWKeys::getHddDevices() const
|
||||
{
|
||||
QStringList devices = keyOperator->devices(QString("hdd"));
|
||||
QStringList devices = m_keyOperator->devices(QString("hdd"));
|
||||
// required by selector in the UI
|
||||
devices.insert(0, QString("disable"));
|
||||
devices.insert(0, QString("auto"));
|
||||
@ -158,7 +168,7 @@ QString AWKeys::infoByKey(QString key) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Requested info for key" << key;
|
||||
|
||||
return keyOperator->infoByKey(key);
|
||||
return m_keyOperator->infoByKey(key);
|
||||
}
|
||||
|
||||
|
||||
@ -167,8 +177,10 @@ QString AWKeys::valueByKey(QString key) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Requested value for key" << key;
|
||||
|
||||
key.remove(QRegExp(QString("^bar[0-9]{1,}")));
|
||||
return aggregator->formater(values[key], key);
|
||||
QString trueKey
|
||||
= key.startsWith(QString("bar")) ? m_keyOperator->infoByKey(key) : key;
|
||||
|
||||
return m_aggregator->formatter(m_values[trueKey], trueKey);
|
||||
}
|
||||
|
||||
|
||||
@ -176,19 +188,13 @@ void AWKeys::editItem(const QString type)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Item type" << type;
|
||||
|
||||
return keyOperator->editItem(type);
|
||||
return m_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());
|
||||
}
|
||||
|
||||
// run concurrent data update
|
||||
QtConcurrent::run(m_threadPool, this, &AWKeys::setDataBySource, sourceName,
|
||||
data);
|
||||
@ -200,18 +206,18 @@ void AWKeys::reinitKeys(const QStringList currentKeys)
|
||||
qCDebug(LOG_AW) << "Update found keys by using list" << currentKeys;
|
||||
|
||||
// append lists
|
||||
m_foundBars
|
||||
= AWPatternFunctions::findBars(keyOperator->pattern(), currentKeys);
|
||||
m_foundKeys
|
||||
= AWPatternFunctions::findKeys(keyOperator->pattern(), currentKeys);
|
||||
m_foundLambdas = AWPatternFunctions::findLambdas(keyOperator->pattern());
|
||||
m_foundBars = AWPatternFunctions::findKeys(m_keyOperator->pattern(),
|
||||
currentKeys, true);
|
||||
m_foundKeys = AWPatternFunctions::findKeys(m_keyOperator->pattern(),
|
||||
currentKeys, false);
|
||||
m_foundLambdas = AWPatternFunctions::findLambdas(m_keyOperator->pattern());
|
||||
// generate list of required keys for bars
|
||||
QStringList barKeys;
|
||||
for (auto bar : m_foundBars) {
|
||||
GraphicalItem *item = keyOperator->giByKey(bar);
|
||||
GraphicalItem *item = m_keyOperator->giByKey(bar);
|
||||
if (item->isCustom())
|
||||
item->setUsedKeys(
|
||||
AWPatternFunctions::findKeys(item->bar(), currentKeys));
|
||||
AWPatternFunctions::findKeys(item->bar(), currentKeys, false));
|
||||
else
|
||||
item->setUsedKeys(QStringList() << item->bar());
|
||||
barKeys.append(item->usedKeys());
|
||||
@ -222,19 +228,21 @@ void AWKeys::reinitKeys(const QStringList currentKeys)
|
||||
m_tooltipParams, currentKeys)
|
||||
: QStringList();
|
||||
|
||||
// set key data to aggregator
|
||||
aggregator->setDevices(keyOperator->devices());
|
||||
// set key data to m_aggregator
|
||||
m_aggregator->setDevices(m_keyOperator->devices());
|
||||
}
|
||||
|
||||
|
||||
void AWKeys::updateTextData()
|
||||
{
|
||||
// do not do it in parallel to avoid race condition
|
||||
m_mutex.lock();
|
||||
calculateValues();
|
||||
QString text = parsePattern(keyOperator->pattern());
|
||||
QString text = parsePattern(m_keyOperator->pattern());
|
||||
m_mutex.unlock();
|
||||
|
||||
emit(needTextToBeUpdated(text));
|
||||
emit(dataAggregator->updateData(values));
|
||||
emit(m_dataAggregator->updateData(m_values));
|
||||
}
|
||||
|
||||
|
||||
@ -243,49 +251,58 @@ void AWKeys::updateTextData()
|
||||
void AWKeys::calculateValues()
|
||||
{
|
||||
// hddtot*
|
||||
QStringList mountDevices = keyOperator->devices(QString("mount"));
|
||||
QStringList mountDevices = m_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();
|
||||
m_values[QString("hddtotmb%1").arg(index)]
|
||||
= m_values[QString("hddfreemb%1").arg(index)].toFloat()
|
||||
+ m_values[QString("hddmb%1").arg(index)].toFloat();
|
||||
m_values[QString("hddtotgb%1").arg(index)]
|
||||
= m_values[QString("hddfreegb%1").arg(index)].toFloat()
|
||||
+ m_values[QString("hddgb%1").arg(index)].toFloat();
|
||||
}
|
||||
|
||||
// memtot*
|
||||
values[QString("memtotmb")] = values[QString("memusedmb")].toInt()
|
||||
+ values[QString("memfreemb")].toInt();
|
||||
values[QString("memtotgb")] = values[QString("memusedgb")].toFloat()
|
||||
+ values[QString("memfreegb")].toFloat();
|
||||
m_values[QString("memtotmb")] = m_values[QString("memusedmb")].toInt()
|
||||
+ m_values[QString("memfreemb")].toInt();
|
||||
m_values[QString("memtotgb")] = m_values[QString("memusedgb")].toFloat()
|
||||
+ m_values[QString("memfreegb")].toFloat();
|
||||
// mem
|
||||
values[QString("mem")] = 100.0f * values[QString("memmb")].toFloat()
|
||||
/ values[QString("memtotmb")].toFloat();
|
||||
m_values[QString("mem")] = 100.0f * m_values[QString("memmb")].toFloat()
|
||||
/ m_values[QString("memtotmb")].toFloat();
|
||||
|
||||
// up, down, upkb, downkb, upunits, downunits
|
||||
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("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("upunits")] = values[QString("upunits%1").arg(netIndex)];
|
||||
int netIndex = m_keyOperator->devices(QString("net"))
|
||||
.indexOf(m_values[QString("netdev")].toString());
|
||||
m_values[QString("down")] = m_values[QString("down%1").arg(netIndex)];
|
||||
m_values[QString("downkb")] = m_values[QString("downkb%1").arg(netIndex)];
|
||||
m_values[QString("downtotal")]
|
||||
= m_values[QString("downtotal%1").arg(netIndex)];
|
||||
m_values[QString("downtotalkb")]
|
||||
= m_values[QString("downtotalkb%1").arg(netIndex)];
|
||||
m_values[QString("downunits")]
|
||||
= m_values[QString("downunits%1").arg(netIndex)];
|
||||
m_values[QString("up")] = m_values[QString("up%1").arg(netIndex)];
|
||||
m_values[QString("upkb")] = m_values[QString("upkb%1").arg(netIndex)];
|
||||
m_values[QString("uptotal")] = m_values[QString("uptotal%1").arg(netIndex)];
|
||||
m_values[QString("uptotalkb")]
|
||||
= m_values[QString("uptotalkb%1").arg(netIndex)];
|
||||
m_values[QString("upunits")] = m_values[QString("upunits%1").arg(netIndex)];
|
||||
|
||||
// swaptot*
|
||||
values[QString("swaptotmb")] = values[QString("swapmb")].toInt()
|
||||
+ values[QString("swapfreemb")].toInt();
|
||||
values[QString("swaptotgb")] = values[QString("swapgb")].toFloat()
|
||||
+ values[QString("swapfreegb")].toFloat();
|
||||
m_values[QString("swaptotmb")] = m_values[QString("swapmb")].toInt()
|
||||
+ m_values[QString("swapfreemb")].toInt();
|
||||
m_values[QString("swaptotgb")]
|
||||
= m_values[QString("swapgb")].toFloat()
|
||||
+ m_values[QString("swapfreegb")].toFloat();
|
||||
// swap
|
||||
values[QString("swap")] = 100.0f * values[QString("swapmb")].toFloat()
|
||||
/ values[QString("swaptotmb")].toFloat();
|
||||
m_values[QString("swap")] = 100.0f * m_values[QString("swapmb")].toFloat()
|
||||
/ m_values[QString("swaptotmb")].toFloat();
|
||||
|
||||
// lambdas
|
||||
for (auto key : m_foundLambdas)
|
||||
values[key] = AWPatternFunctions::expandLambdas(key, aggregator, values,
|
||||
m_foundKeys);
|
||||
m_values[key] = AWPatternFunctions::expandLambdas(
|
||||
key, m_aggregator, m_values, m_foundKeys);
|
||||
}
|
||||
|
||||
|
||||
@ -296,30 +313,28 @@ QString AWKeys::parsePattern(QString pattern) const
|
||||
|
||||
// lambdas
|
||||
for (auto key : m_foundLambdas)
|
||||
pattern.replace(QString("${{%1}}").arg(key), values[key].toString());
|
||||
pattern.replace(QString("${{%1}}").arg(key), m_values[key].toString());
|
||||
|
||||
// main keys
|
||||
for (auto key : m_foundKeys)
|
||||
pattern.replace(QString("$%1").arg(key), [this](const QString &tag,
|
||||
const QVariant &value) {
|
||||
QString strValue = aggregator->formater(value, tag);
|
||||
QString strValue = m_aggregator->formatter(value, tag);
|
||||
if ((!tag.startsWith(QString("custom")))
|
||||
&& (!tag.startsWith(QString("weather"))))
|
||||
strValue.replace(QString(" "), QString(" "));
|
||||
return strValue;
|
||||
}(key, values[key]));
|
||||
}(key, m_values[key]));
|
||||
|
||||
// bars
|
||||
for (auto bar : m_foundBars) {
|
||||
GraphicalItem *item = keyOperator->giByKey(bar);
|
||||
if (item->isCustom())
|
||||
pattern.replace(
|
||||
QString("$%1").arg(bar),
|
||||
item->image(AWPatternFunctions::expandLambdas(
|
||||
item->bar(), aggregator, values, item->usedKeys())));
|
||||
else
|
||||
pattern.replace(QString("$%1").arg(bar),
|
||||
item->image(values[item->bar()]));
|
||||
GraphicalItem *item = m_keyOperator->giByKey(bar);
|
||||
QString image
|
||||
= item->isCustom()
|
||||
? item->image(AWPatternFunctions::expandLambdas(
|
||||
item->bar(), m_aggregator, m_values, item->usedKeys()))
|
||||
: item->image(m_values[item->bar()]);
|
||||
pattern.replace(QString("$%1").arg(bar), image);
|
||||
}
|
||||
|
||||
// prepare strings
|
||||
@ -336,9 +351,9 @@ void AWKeys::setDataBySource(const QString &sourceName, const QVariantMap &data)
|
||||
qCDebug(LOG_AW) << "Source" << sourceName << "with data" << data;
|
||||
|
||||
// first list init
|
||||
QStringList tags = aggregator->keysFromSource(sourceName);
|
||||
QStringList tags = m_aggregator->keysFromSource(sourceName);
|
||||
if (tags.isEmpty())
|
||||
tags = aggregator->registerSource(
|
||||
tags = m_aggregator->registerSource(
|
||||
sourceName, data[QString("units")].toString(), m_requiredKeys);
|
||||
|
||||
// update data or drop source if there are no matches and exit
|
||||
@ -351,9 +366,9 @@ void AWKeys::setDataBySource(const QString &sourceName, const QVariantMap &data)
|
||||
// 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_values[tag] = sourceName == QString("Local")
|
||||
? data[QString("DateTime")]
|
||||
: data[QString("value")];
|
||||
});
|
||||
m_mutex.unlock();
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ class AWDataEngineAggregator;
|
||||
class AWKeyOperations;
|
||||
class AWKeysAggregator;
|
||||
class QThreadPool;
|
||||
class QTimer;
|
||||
|
||||
class AWKeys : public QObject
|
||||
{
|
||||
@ -67,7 +68,6 @@ signals:
|
||||
void dropSourceFromDataengine(const QString source);
|
||||
void needTextToBeUpdated(const QString newText) const;
|
||||
void needToolTipToBeUpdated(const QString newText) const;
|
||||
void needToBeUpdated();
|
||||
|
||||
private slots:
|
||||
void reinitKeys(const QStringList currentKeys);
|
||||
@ -79,14 +79,15 @@ private:
|
||||
QString parsePattern(QString pattern) const;
|
||||
void setDataBySource(const QString &sourceName, const QVariantMap &data);
|
||||
// objects
|
||||
AWDataAggregator *dataAggregator = nullptr;
|
||||
AWDataEngineAggregator *dataEngineAggregator = nullptr;
|
||||
AWKeysAggregator *aggregator = nullptr;
|
||||
AWKeyOperations *keyOperator = nullptr;
|
||||
AWDataAggregator *m_dataAggregator = nullptr;
|
||||
AWDataEngineAggregator *m_dataEngineAggregator = nullptr;
|
||||
AWKeysAggregator *m_aggregator = nullptr;
|
||||
AWKeyOperations *m_keyOperator = nullptr;
|
||||
QTimer *m_timer = nullptr;
|
||||
// variables
|
||||
QVariantMap m_tooltipParams;
|
||||
QStringList m_foundBars, m_foundKeys, m_foundLambdas, m_requiredKeys;
|
||||
QVariantHash values;
|
||||
QVariantHash m_values;
|
||||
bool m_optimize = false;
|
||||
bool m_wrapNewLines = false;
|
||||
// multithread features
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include <QRegExp>
|
||||
|
||||
#include "awdebug.h"
|
||||
#include "awformatterhelper.h"
|
||||
|
||||
|
||||
AWKeysAggregator::AWKeysAggregator(QObject *parent)
|
||||
@ -31,69 +32,79 @@ AWKeysAggregator::AWKeysAggregator(QObject *parent)
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
|
||||
// default formaters
|
||||
// default formatters
|
||||
// memory
|
||||
m_formater[QString("mem")] = Float;
|
||||
m_formater[QString("memtotmb")] = IntegerFive;
|
||||
m_formater[QString("memtotgb")] = Float;
|
||||
m_formatter[QString("mem")] = FormatterType::Float;
|
||||
m_formatter[QString("memtotmb")] = FormatterType::MemMBFormat;
|
||||
m_formatter[QString("memtotgb")] = FormatterType::MemGBFormat;
|
||||
// network
|
||||
m_formater[QString("down")] = NetSmartFormat;
|
||||
m_formater[QString("downkb")] = Integer;
|
||||
m_formater[QString("downunits")] = NetSmartUnits;
|
||||
m_formater[QString("up")] = NetSmartFormat;
|
||||
m_formater[QString("upkb")] = Integer;
|
||||
m_formater[QString("upunits")] = NetSmartUnits;
|
||||
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_formater[QString("swap")] = Float;
|
||||
m_formater[QString("swaptotmb")] = IntegerFive;
|
||||
m_formater[QString("swaptotgb")] = Float;
|
||||
m_formatter[QString("swap")] = FormatterType::Float;
|
||||
m_formatter[QString("swaptotmb")] = FormatterType::MemMBFormat;
|
||||
m_formatter[QString("swaptotgb")] = FormatterType::MemGBFormat;
|
||||
}
|
||||
|
||||
|
||||
AWKeysAggregator::~AWKeysAggregator()
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
|
||||
delete m_customFormatters;
|
||||
}
|
||||
|
||||
|
||||
QString AWKeysAggregator::formater(const QVariant &data,
|
||||
const QString &key) const
|
||||
void AWKeysAggregator::initFormatters()
|
||||
{
|
||||
if (m_customFormatters)
|
||||
delete m_customFormatters;
|
||||
m_customFormatters = new AWFormatterHelper(nullptr);
|
||||
}
|
||||
|
||||
|
||||
QString AWKeysAggregator::formatter(const QVariant &data,
|
||||
const QString &key) const
|
||||
{
|
||||
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 IntegerFive:
|
||||
case FormatterType::IntegerFive:
|
||||
output = QString("%1").arg(data.toFloat(), 5, 'f', 0);
|
||||
break;
|
||||
case IntegerThree:
|
||||
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);
|
||||
@ -101,41 +112,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) {
|
||||
for (auto key : timeKeys)
|
||||
for (auto key : m_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;
|
||||
@ -152,15 +167,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,
|
||||
}(m_formatter[key] == FormatterType::Uptime
|
||||
? QString("$ddd$hhh$mmm")
|
||||
: m_customUptime,
|
||||
static_cast<int>(data.toFloat()));
|
||||
break;
|
||||
case NoFormat:
|
||||
case FormatterType::NoFormat:
|
||||
output = data.toString();
|
||||
break;
|
||||
default:
|
||||
output = QString();
|
||||
case FormatterType::Custom:
|
||||
if (m_customFormatters)
|
||||
output = m_customFormatters->convert(data, key);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -250,56 +267,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;
|
||||
@ -308,7 +327,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
|
||||
@ -318,16 +337,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;
|
||||
@ -336,10 +355,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_formater[QString("hddtotmb%1").arg(index)] = IntegerFive;
|
||||
m_formater[QString("hddtotgb%1").arg(index)] = Float;
|
||||
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
|
||||
@ -350,11 +371,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
|
||||
@ -365,11 +386,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
|
||||
@ -379,7 +400,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
|
||||
@ -387,35 +408,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")
|
||||
@ -426,128 +447,163 @@ 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);
|
||||
// FIXME on DE initialization there are no units key
|
||||
// HACK on DE initialization there are no units key
|
||||
if (units.isEmpty())
|
||||
return QStringList() << QString("temp%1").arg(index);
|
||||
if (index > -1) {
|
||||
QString key = QString("temp%1").arg(index);
|
||||
m_map[source] = key;
|
||||
m_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;
|
||||
if (m_customFormatters)
|
||||
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
|
||||
QStringList foundKeys = keysFromSource(source);
|
||||
qCInfo(LOG_AW) << "Looking for keys" << foundKeys << "in" << keys;
|
||||
// this source is required if list is empty (which means skip checking)
|
||||
// or if key in required key list
|
||||
bool required
|
||||
= keys.isEmpty() || std::any_of(foundKeys.cbegin(), foundKeys.cend(),
|
||||
[&keys](const QString &key) {
|
||||
return keys.contains(key);
|
||||
});
|
||||
if (!required)
|
||||
if (!required) {
|
||||
m_map.remove(source);
|
||||
for (auto key : foundKeys)
|
||||
m_formatter.remove(key);
|
||||
}
|
||||
|
||||
return keysFromSource(source);
|
||||
}
|
||||
|
@ -25,6 +25,8 @@
|
||||
#include "version.h"
|
||||
|
||||
|
||||
class AWFormatterHelper;
|
||||
|
||||
class AWKeysAggregator : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -36,16 +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,
|
||||
@ -58,6 +61,7 @@ class AWKeysAggregator : public QObject
|
||||
TimeISO,
|
||||
TimeLong,
|
||||
TimeShort,
|
||||
Timestamp,
|
||||
Uptime,
|
||||
UptimeCustom
|
||||
};
|
||||
@ -65,8 +69,9 @@ class AWKeysAggregator : public QObject
|
||||
public:
|
||||
explicit AWKeysAggregator(QObject *parent = nullptr);
|
||||
virtual ~AWKeysAggregator();
|
||||
void initFormatters();
|
||||
// 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);
|
||||
@ -83,14 +88,15 @@ public slots:
|
||||
|
||||
private:
|
||||
float temperature(const float temp) const;
|
||||
QStringList timeKeys = QString(TIME_KEYS).split(QChar(','));
|
||||
AWFormatterHelper *m_customFormatters = nullptr;
|
||||
QStringList m_timeKeys = QString(TIME_KEYS).split(QChar(','));
|
||||
// variables
|
||||
QString m_acOffline;
|
||||
QString m_acOnline;
|
||||
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;
|
||||
|
@ -37,7 +37,7 @@ QString AWPatternFunctions::expandLambdas(QString code,
|
||||
// parsed values
|
||||
for (auto lambdaKey : usedKeys)
|
||||
code.replace(QString("$%1").arg(lambdaKey),
|
||||
aggregator->formater(metadata[lambdaKey], lambdaKey));
|
||||
aggregator->formatter(metadata[lambdaKey], lambdaKey));
|
||||
qCInfo(LOG_AW) << "Expression" << code;
|
||||
QJSValue result = engine.evaluate(code);
|
||||
if (result.isError()) {
|
||||
@ -86,8 +86,9 @@ QString AWPatternFunctions::expandTemplates(QString code)
|
||||
}
|
||||
|
||||
|
||||
QVariantList AWPatternFunctions::findFunctionCalls(const QString function,
|
||||
const QString code)
|
||||
QList<AWPatternFunctions::AWFunction>
|
||||
AWPatternFunctions::findFunctionCalls(const QString function,
|
||||
const QString code)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Looking for function" << function << "in" << code;
|
||||
|
||||
@ -95,23 +96,23 @@ QVariantList AWPatternFunctions::findFunctionCalls(const QString function,
|
||||
// $aw_function_name<some args here if any>{{function body}}
|
||||
// * 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
|
||||
// * body depends on the function name, double brackets should be screened
|
||||
// by using $, e.g. ${
|
||||
QRegularExpression regex(
|
||||
QString("\\$%1\\<(?<args>.*?)\\>\\{\\{(?<body>.*?)\\}\\}")
|
||||
.arg(function));
|
||||
regex.setPatternOptions(QRegularExpression::DotMatchesEverythingOption);
|
||||
|
||||
QVariantList foundFunctions;
|
||||
QList<AWPatternFunctions::AWFunction> foundFunctions;
|
||||
QRegularExpressionMatchIterator it = regex.globalMatch(code);
|
||||
while (it.hasNext()) {
|
||||
QRegularExpressionMatch match = it.next();
|
||||
|
||||
QVariantHash metadata;
|
||||
AWPatternFunctions::AWFunction metadata;
|
||||
// work with args
|
||||
QString argsString = match.captured(QString("args"));
|
||||
if (argsString.isEmpty()) {
|
||||
metadata[QString("args")] = QStringList();
|
||||
metadata.args = QStringList();
|
||||
} else {
|
||||
// replace '$,' to 0x1d
|
||||
argsString.replace(QString("$,"), QString(0x1d));
|
||||
@ -119,11 +120,14 @@ QVariantList AWPatternFunctions::findFunctionCalls(const QString function,
|
||||
std::for_each(args.begin(), args.end(), [](QString &arg) {
|
||||
arg.replace(QString(0x1d), QString(","));
|
||||
});
|
||||
metadata[QString("args")] = args;
|
||||
metadata.args = args;
|
||||
}
|
||||
// other variables
|
||||
metadata[QString("body")] = match.captured(QString("body"));
|
||||
metadata[QString("what")] = match.captured();
|
||||
metadata.body = match.captured(QString("body"));
|
||||
metadata.what = match.captured();
|
||||
// replace brackets
|
||||
metadata.body.replace(QString("${"), QString("{"));
|
||||
metadata.body.replace(QString("$}"), QString("}"));
|
||||
foundFunctions.append(metadata);
|
||||
}
|
||||
|
||||
@ -136,22 +140,17 @@ QString AWPatternFunctions::insertAllKeys(QString code, const QStringList keys)
|
||||
qCDebug(LOG_AW) << "Looking for keys in code" << code << "using list"
|
||||
<< keys;
|
||||
|
||||
QVariantList found
|
||||
QList<AWPatternFunctions::AWFunction> 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()));
|
||||
= function.args.isEmpty() ? QString(",") : function.args.at(0);
|
||||
QStringList required = keys.filter(QRegExp(function.body));
|
||||
std::for_each(required.begin(), required.end(), [](QString &value) {
|
||||
value = QString("%1: $%1").arg(value);
|
||||
});
|
||||
|
||||
code.replace(metadata[QString("what")].toString(),
|
||||
required.join(separator));
|
||||
code.replace(function.what, required.join(separator));
|
||||
}
|
||||
|
||||
return code;
|
||||
@ -163,15 +162,12 @@ QString AWPatternFunctions::insertKeyCount(QString code, const QStringList keys)
|
||||
qCDebug(LOG_AW) << "Looking for count in code" << code << "using list"
|
||||
<< keys;
|
||||
|
||||
QVariantList found
|
||||
QList<AWPatternFunctions::AWFunction> 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();
|
||||
int count = keys.filter(QRegExp(function.body)).count();
|
||||
|
||||
code.replace(metadata[QString("what")].toString(),
|
||||
QString::number(count));
|
||||
code.replace(function.what, QString::number(count));
|
||||
}
|
||||
|
||||
return code;
|
||||
@ -183,19 +179,14 @@ QString AWPatternFunctions::insertKeyNames(QString code, const QStringList keys)
|
||||
qCDebug(LOG_AW) << "Looking for key names in code" << code << "using list"
|
||||
<< keys;
|
||||
|
||||
QVariantList found
|
||||
QList<AWPatternFunctions::AWFunction> 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()));
|
||||
= function.args.isEmpty() ? QString(",") : function.args.at(0);
|
||||
QStringList required = keys.filter(QRegExp(function.body));
|
||||
|
||||
code.replace(metadata[QString("what")].toString(),
|
||||
required.join(separator));
|
||||
code.replace(function.what, required.join(separator));
|
||||
}
|
||||
|
||||
return code;
|
||||
@ -207,59 +198,80 @@ QString AWPatternFunctions::insertKeys(QString code, const QStringList keys)
|
||||
qCDebug(LOG_AW) << "Looking for keys in code" << code << "using list"
|
||||
<< keys;
|
||||
|
||||
QVariantList found
|
||||
QList<AWPatternFunctions::AWFunction> 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()));
|
||||
= function.args.isEmpty() ? QString(",") : function.args.at(0);
|
||||
QStringList required = keys.filter(QRegExp(function.body));
|
||||
std::for_each(required.begin(), required.end(), [](QString &value) {
|
||||
value = QString("$%1").arg(value);
|
||||
});
|
||||
|
||||
code.replace(metadata[QString("what")].toString(),
|
||||
required.join(separator));
|
||||
code.replace(function.what, required.join(separator));
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
QStringList AWPatternFunctions::findBars(const QString code,
|
||||
const QStringList keys)
|
||||
QString AWPatternFunctions::insertMacros(QString code)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Looking for bars in code" << code << "using list"
|
||||
<< keys;
|
||||
qCDebug(LOG_AW) << "Looking for macros in code" << code;
|
||||
|
||||
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);
|
||||
QList<AWPatternFunctions::AWFunction> found
|
||||
= AWPatternFunctions::findFunctionCalls(QString("aw_macro"), code);
|
||||
for (auto macro : found) {
|
||||
// get macro params
|
||||
if (macro.args.isEmpty()) {
|
||||
qCWarning(LOG_AW) << "No macro name found for" << macro.what;
|
||||
continue;
|
||||
}
|
||||
QString name = macro.args.takeFirst();
|
||||
// find macro usage
|
||||
QList<AWPatternFunctions::AWFunction> macroUsage
|
||||
= AWPatternFunctions::findFunctionCalls(
|
||||
QString("aw_macro_%1").arg(name), code);
|
||||
for (auto function : macroUsage) {
|
||||
if (function.args.count() != macro.args.count()) {
|
||||
qCWarning(LOG_AW) << "Invalid args count found for call"
|
||||
<< function.what << "with macro"
|
||||
<< macro.what;
|
||||
continue;
|
||||
}
|
||||
// generate body to replace
|
||||
QString result = macro.body;
|
||||
std::for_each(macro.args.cbegin(), macro.args.cend(),
|
||||
[&result, macro, function](const QString &arg) {
|
||||
int index = macro.args.indexOf(arg);
|
||||
result.replace(QString("$%1").arg(arg),
|
||||
function.args.at(index));
|
||||
});
|
||||
// do replace
|
||||
code.replace(function.what, result);
|
||||
}
|
||||
if (selectedKeys.isEmpty())
|
||||
qCWarning(LOG_AW) << "No bars found";
|
||||
|
||||
return selectedKeys;
|
||||
// remove macro from source pattern
|
||||
code.remove(macro.what);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
QStringList AWPatternFunctions::findKeys(const QString code,
|
||||
const QStringList keys)
|
||||
const QStringList keys,
|
||||
const bool isBars)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Looking for keys in code" << code << "using list"
|
||||
<< keys;
|
||||
|
||||
QStringList selectedKeys;
|
||||
for (auto key : keys)
|
||||
if ((!key.startsWith(QString("bar")))
|
||||
if ((key.startsWith(QString("bar")) == isBars)
|
||||
&& (code.contains(QString("$%1").arg(key)))) {
|
||||
qCInfo(LOG_AW) << "Found key" << key;
|
||||
qCInfo(LOG_AW) << "Found key" << key << "with bar enabled"
|
||||
<< isBars;
|
||||
selectedKeys.append(key);
|
||||
}
|
||||
if (selectedKeys.isEmpty())
|
||||
|
@ -27,19 +27,26 @@ class AWKeysAggregator;
|
||||
|
||||
namespace AWPatternFunctions
|
||||
{
|
||||
typedef struct {
|
||||
QStringList args;
|
||||
QString body;
|
||||
QString what;
|
||||
} AWFunction;
|
||||
|
||||
// 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);
|
||||
QList<AWFunction> findFunctionCalls(const QString function, const QString code);
|
||||
QString insertAllKeys(QString code, const QStringList keys);
|
||||
QString insertKeyCount(QString code, const QStringList keys);
|
||||
QString insertKeyNames(QString code, const QStringList keys);
|
||||
QString insertKeys(QString code, const QStringList keys);
|
||||
QString insertMacros(QString code);
|
||||
// find methods
|
||||
QStringList findBars(const QString code, const QStringList keys);
|
||||
QStringList findKeys(const QString code, const QStringList keys);
|
||||
QStringList findKeys(const QString code, const QStringList keys,
|
||||
const bool isBars);
|
||||
QStringList findLambdas(const QString code);
|
||||
};
|
||||
|
||||
|
@ -19,17 +19,16 @@
|
||||
|
||||
#include <KI18n/KLocalizedString>
|
||||
|
||||
#include <QtConcurrent/QtConcurrent>
|
||||
#include <QDesktopServices>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonParseError>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
#include <QNetworkRequest>
|
||||
#include <QSettings>
|
||||
#include <QtConcurrent/QtConcurrent>
|
||||
|
||||
#include "awdebug.h"
|
||||
#include "version.h"
|
||||
|
||||
|
||||
AWUpdateHelper::AWUpdateHelper(QObject *parent)
|
||||
@ -74,14 +73,18 @@ bool AWUpdateHelper::checkVersion()
|
||||
// update version
|
||||
settings.setValue(QString("Version"), QString(VERSION));
|
||||
settings.sync();
|
||||
qCInfo(LOG_AW) << "Found version" << version << "actual one is"
|
||||
<< m_foundVersion;
|
||||
|
||||
qCInfo(LOG_AW) << "Found version" << version << "actual one is" << VERSION;
|
||||
if (version != QVersionNumber::fromString(VERSION)) {
|
||||
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";
|
||||
}
|
||||
@ -123,15 +126,16 @@ void AWUpdateHelper::showUpdates(const QVersionNumber version)
|
||||
|
||||
void AWUpdateHelper::userReplyOnUpdates(QAbstractButton *button)
|
||||
{
|
||||
int ret = static_cast<QMessageBox *>(sender())->buttonRole(button);
|
||||
QMessageBox::ButtonRole ret
|
||||
= static_cast<QMessageBox *>(sender())->buttonRole(button);
|
||||
qCInfo(LOG_AW) << "User select" << ret;
|
||||
|
||||
switch (ret) {
|
||||
case QMessageBox::Ok:
|
||||
case QMessageBox::AcceptRole:
|
||||
QDesktopServices::openUrl(QString(RELEASES)
|
||||
+ m_foundVersion.toString());
|
||||
break;
|
||||
case QMessageBox::Cancel:
|
||||
case QMessageBox::RejectRole:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ 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_FORMATTERS ${CMAKE_CURRENT_SOURCE_DIR}/formatters)
|
||||
set(SUBPROJECT_GRAPHITEMS ${CMAKE_CURRENT_SOURCE_DIR}/desktops)
|
||||
set(SUBPROJECT_QUOTES ${CMAKE_CURRENT_SOURCE_DIR}/quotes)
|
||||
set(SUBPROJECT_SCRIPTS ${CMAKE_CURRENT_SOURCE_DIR}/scripts)
|
||||
@ -32,6 +33,7 @@ target_link_libraries(${SUBPROJECT} ${Qt_LIBRARIES} ${Kf5_LIBRARIES})
|
||||
|
||||
# install
|
||||
install(DIRECTORY ${SUBPROJECT_CONFIGS} DESTINATION ${DATA_INSTALL_DIR}/${PROJECT_NAME})
|
||||
install(DIRECTORY ${SUBPROJECT_FORMATTERS} 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})
|
||||
|
@ -22,21 +22,17 @@
|
||||
#include <QStandardPaths>
|
||||
#include <QTime>
|
||||
|
||||
#include "awdebug.h"
|
||||
#include "version.h"
|
||||
#include "abstractextitemaggregator.h"
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
AbstractExtItem::AbstractExtItem(QWidget *parent, const QString desktopName,
|
||||
const QStringList directories)
|
||||
AbstractExtItem::AbstractExtItem(QWidget *parent, const QString filePath)
|
||||
: QDialog(parent)
|
||||
, m_fileName(desktopName)
|
||||
, m_dirs(directories)
|
||||
, m_fileName(filePath)
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
qCDebug(LOG_LIB) << "Desktop name" << desktopName << "directories"
|
||||
<< directories;
|
||||
qCDebug(LOG_LIB) << "Desktop name" << filePath;
|
||||
|
||||
m_name = m_fileName;
|
||||
}
|
||||
@ -48,13 +44,42 @@ AbstractExtItem::~AbstractExtItem()
|
||||
}
|
||||
|
||||
|
||||
void AbstractExtItem::bumpApi(const int _newVer)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Bump API using new version" << _newVer;
|
||||
|
||||
// update for current API
|
||||
if ((apiVersion() > 0) && (apiVersion() < _newVer)) {
|
||||
qCWarning(LOG_LIB) << "Bump API version from" << apiVersion() << "to"
|
||||
<< _newVer;
|
||||
setApiVersion(_newVer);
|
||||
writeConfiguration();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AbstractExtItem::copyDefaults(AbstractExtItem *_other) const
|
||||
{
|
||||
_other->setActive(m_active);
|
||||
_other->setApiVersion(m_apiVersion);
|
||||
_other->setComment(m_comment);
|
||||
_other->setInterval(m_interval);
|
||||
_other->setName(m_name);
|
||||
_other->setActive(isActive());
|
||||
_other->setApiVersion(apiVersion());
|
||||
_other->setComment(comment());
|
||||
_other->setInterval(interval());
|
||||
_other->setName(name());
|
||||
}
|
||||
|
||||
|
||||
QString AbstractExtItem::writtableConfig() const
|
||||
{
|
||||
QString path = m_fileName;
|
||||
QString name = QFileInfo(path).fileName();
|
||||
path.remove(path.count() - name.count() - 1, name.count() + 1);
|
||||
QString dir = QFileInfo(path).fileName();
|
||||
|
||||
return QString("%1/awesomewidgets/%2/%3")
|
||||
.arg(QStandardPaths::writableLocation(
|
||||
QStandardPaths::GenericDataLocation))
|
||||
.arg(dir)
|
||||
.arg(name);
|
||||
}
|
||||
|
||||
|
||||
@ -70,12 +95,6 @@ QString AbstractExtItem::comment() const
|
||||
}
|
||||
|
||||
|
||||
QStringList AbstractExtItem::directories() const
|
||||
{
|
||||
return m_dirs;
|
||||
}
|
||||
|
||||
|
||||
QString AbstractExtItem::fileName() const
|
||||
{
|
||||
return m_fileName;
|
||||
@ -110,7 +129,7 @@ QString AbstractExtItem::tag(const QString _type) const
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Tag type" << _type;
|
||||
|
||||
return QString("%1%2").arg(_type).arg(m_number);
|
||||
return QString("%1%2").arg(_type).arg(number());
|
||||
}
|
||||
|
||||
|
||||
@ -159,73 +178,64 @@ void AbstractExtItem::setName(const QString _name)
|
||||
void AbstractExtItem::setNumber(int _number)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Number" << _number;
|
||||
if (_number == -1)
|
||||
bool generateNumber = (_number == -1);
|
||||
if (generateNumber) {
|
||||
_number = []() {
|
||||
qCWarning(LOG_LIB) << "Number is empty, generate new one";
|
||||
qsrand(QTime::currentTime().msec());
|
||||
// we suppose that currentTIme().msec() is always valid time
|
||||
qsrand(static_cast<uint>(QTime::currentTime().msec()));
|
||||
int n = qrand() % 1000;
|
||||
qCInfo(LOG_LIB) << "Generated number is" << n;
|
||||
return n;
|
||||
}();
|
||||
}
|
||||
|
||||
m_number = _number;
|
||||
if (generateNumber)
|
||||
writeConfiguration();
|
||||
}
|
||||
|
||||
|
||||
void AbstractExtItem::readConfiguration()
|
||||
{
|
||||
for (int i = m_dirs.count() - 1; i >= 0; i--) {
|
||||
if (!QDir(m_dirs.at(i)).entryList(QDir::Files).contains(m_fileName))
|
||||
continue;
|
||||
QSettings settings(QString("%1/%2").arg(m_dirs.at(i)).arg(m_fileName),
|
||||
QSettings::IniFormat);
|
||||
QSettings settings(m_fileName, QSettings::IniFormat);
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
setName(settings.value(QString("Name"), m_name).toString());
|
||||
setComment(settings.value(QString("Comment"), m_comment).toString());
|
||||
setApiVersion(
|
||||
settings.value(QString("X-AW-ApiVersion"), m_apiVersion).toInt());
|
||||
setActive(settings.value(QString("X-AW-Active"), QVariant(m_active))
|
||||
.toString()
|
||||
== QString("true"));
|
||||
setInterval(
|
||||
settings.value(QString("X-AW-Interval"), m_interval).toInt());
|
||||
setNumber(settings.value(QString("X-AW-Number"), m_number).toInt());
|
||||
settings.endGroup();
|
||||
}
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
setName(settings.value(QString("Name"), name()).toString());
|
||||
setComment(settings.value(QString("Comment"), comment()).toString());
|
||||
setApiVersion(
|
||||
settings.value(QString("X-AW-ApiVersion"), apiVersion()).toInt());
|
||||
setActive(
|
||||
settings.value(QString("X-AW-Active"), QVariant(isActive())).toString()
|
||||
== QString("true"));
|
||||
setInterval(settings.value(QString("X-AW-Interval"), interval()).toInt());
|
||||
setNumber(settings.value(QString("X-AW-Number"), number()).toInt());
|
||||
settings.endGroup();
|
||||
}
|
||||
|
||||
|
||||
bool AbstractExtItem::tryDelete() const
|
||||
{
|
||||
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;
|
||||
}
|
||||
bool status = QFile::remove(m_fileName);
|
||||
qCInfo(LOG_LIB) << "Remove file" << m_fileName << status;
|
||||
|
||||
// check if exists
|
||||
for (auto dir : m_dirs)
|
||||
if (QFile::exists(QString("%1/%2").arg(dir).arg(m_fileName)))
|
||||
return false;
|
||||
return true;
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
void AbstractExtItem::writeConfiguration() const
|
||||
{
|
||||
QSettings settings(QString("%1/%2").arg(m_dirs.first()).arg(m_fileName),
|
||||
QSettings::IniFormat);
|
||||
QSettings settings(writtableConfig(), QSettings::IniFormat);
|
||||
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
settings.setValue(QString("Encoding"), QString("UTF-8"));
|
||||
settings.setValue(QString("Name"), m_name);
|
||||
settings.setValue(QString("Comment"), m_comment);
|
||||
settings.setValue(QString("X-AW-ApiVersion"), m_apiVersion);
|
||||
settings.setValue(QString("X-AW-Active"), QVariant(m_active).toString());
|
||||
settings.setValue(QString("X-AW-Interval"), m_interval);
|
||||
settings.setValue(QString("X-AW-Number"), m_number);
|
||||
settings.setValue(QString("Name"), name());
|
||||
settings.setValue(QString("Comment"), comment());
|
||||
settings.setValue(QString("X-AW-ApiVersion"), apiVersion());
|
||||
settings.setValue(QString("X-AW-Active"), QVariant(isActive()).toString());
|
||||
settings.setValue(QString("X-AW-Interval"), interval());
|
||||
settings.setValue(QString("X-AW-Number"), number());
|
||||
settings.endGroup();
|
||||
|
||||
settings.sync();
|
||||
|
@ -28,7 +28,6 @@ class AbstractExtItem : public QDialog
|
||||
Q_PROPERTY(bool active READ isActive WRITE setActive)
|
||||
Q_PROPERTY(int apiVersion READ apiVersion WRITE setApiVersion)
|
||||
Q_PROPERTY(QString comment READ comment WRITE setComment)
|
||||
Q_PROPERTY(QStringList directories READ directories)
|
||||
Q_PROPERTY(QString fileName READ fileName)
|
||||
Q_PROPERTY(int interval READ interval WRITE setInterval)
|
||||
Q_PROPERTY(QString name READ name WRITE setName)
|
||||
@ -36,17 +35,17 @@ class AbstractExtItem : public QDialog
|
||||
Q_PROPERTY(QString uniq READ uniq)
|
||||
|
||||
public:
|
||||
explicit AbstractExtItem(QWidget *parent = nullptr,
|
||||
const QString desktopName = QString(),
|
||||
const QStringList directories = QStringList());
|
||||
explicit AbstractExtItem(QWidget *parent,
|
||||
const QString filePath = QString());
|
||||
virtual ~AbstractExtItem();
|
||||
virtual void bumpApi(const int _newVer);
|
||||
virtual AbstractExtItem *copy(const QString _fileName, const int _number)
|
||||
= 0;
|
||||
void copyDefaults(AbstractExtItem *_other) const;
|
||||
virtual void copyDefaults(AbstractExtItem *_other) const;
|
||||
QString writtableConfig() const;
|
||||
// get methods
|
||||
int apiVersion() const;
|
||||
QString comment() const;
|
||||
QStringList directories() const;
|
||||
QString fileName() const;
|
||||
int interval() const;
|
||||
bool isActive() const;
|
||||
@ -62,6 +61,9 @@ public:
|
||||
void setName(const QString _name = QString("none"));
|
||||
void setNumber(int _number = -1);
|
||||
|
||||
signals:
|
||||
void dataReceived(const QVariantHash &data);
|
||||
|
||||
public slots:
|
||||
virtual void readConfiguration();
|
||||
virtual QVariantHash run() = 0;
|
||||
@ -70,8 +72,7 @@ public slots:
|
||||
virtual void writeConfiguration() const;
|
||||
|
||||
private:
|
||||
QString m_fileName;
|
||||
QStringList m_dirs;
|
||||
QString m_fileName = QString("/dev/null");
|
||||
virtual void translate() = 0;
|
||||
// properties
|
||||
int m_apiVersion = 0;
|
||||
|
@ -16,40 +16,35 @@
|
||||
***************************************************************************/
|
||||
|
||||
#include "abstractextitemaggregator.h"
|
||||
#include "ui_abstractextitemaggregator.h"
|
||||
|
||||
#include <KI18n/KLocalizedString>
|
||||
|
||||
#include <QHBoxLayout>
|
||||
#include <QFileInfo>
|
||||
#include <QInputDialog>
|
||||
#include <QLineEdit>
|
||||
|
||||
#include "awdebug.h"
|
||||
#include <QPushButton>
|
||||
|
||||
|
||||
AbstractExtItemAggregator::AbstractExtItemAggregator(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
AbstractExtItemAggregator::AbstractExtItemAggregator(QWidget *parent,
|
||||
const QString type)
|
||||
: QDialog(parent)
|
||||
, ui(new Ui::AbstractExtItemAggregator)
|
||||
, m_type(type)
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
dialog = new QDialog(this);
|
||||
widgetDialog = new QListWidget(dialog);
|
||||
dialogButtons = new QDialogButtonBox(
|
||||
QDialogButtonBox::Open | QDialogButtonBox::Close, Qt::Vertical, dialog);
|
||||
ui->setupUi(this);
|
||||
copyButton
|
||||
= dialogButtons->addButton(i18n("Copy"), QDialogButtonBox::ActionRole);
|
||||
createButton = dialogButtons->addButton(i18n("Create"),
|
||||
= ui->buttonBox->addButton(i18n("Copy"), QDialogButtonBox::ActionRole);
|
||||
createButton = ui->buttonBox->addButton(i18n("Create"),
|
||||
QDialogButtonBox::ActionRole);
|
||||
deleteButton = dialogButtons->addButton(i18n("Remove"),
|
||||
deleteButton = ui->buttonBox->addButton(i18n("Remove"),
|
||||
QDialogButtonBox::ActionRole);
|
||||
QHBoxLayout *layout = new QHBoxLayout(dialog);
|
||||
layout->addWidget(widgetDialog);
|
||||
layout->addWidget(dialogButtons);
|
||||
dialog->setLayout(layout);
|
||||
|
||||
connect(dialogButtons, SIGNAL(clicked(QAbstractButton *)), this,
|
||||
connect(ui->buttonBox, SIGNAL(clicked(QAbstractButton *)), this,
|
||||
SLOT(editItemButtonPressed(QAbstractButton *)));
|
||||
connect(dialogButtons, SIGNAL(rejected()), dialog, SLOT(reject()));
|
||||
connect(widgetDialog, SIGNAL(itemActivated(QListWidgetItem *)), this,
|
||||
connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
||||
connect(ui->listWidget, SIGNAL(itemActivated(QListWidgetItem *)), this,
|
||||
SLOT(editItemActivated(QListWidgetItem *)));
|
||||
}
|
||||
|
||||
@ -58,7 +53,60 @@ AbstractExtItemAggregator::~AbstractExtItemAggregator()
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
delete dialog;
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
||||
void AbstractExtItemAggregator::copyItem()
|
||||
{
|
||||
AbstractExtItem *source = itemFromWidget();
|
||||
QString fileName = getName();
|
||||
int number = uniqNumber();
|
||||
QString dir = QString("%1/awesomewidgets/%2")
|
||||
.arg(QStandardPaths::writableLocation(
|
||||
QStandardPaths::GenericDataLocation))
|
||||
.arg(m_type);
|
||||
if ((!source) || (fileName.isEmpty())) {
|
||||
qCWarning(LOG_LIB) << "Nothing to copy";
|
||||
return;
|
||||
}
|
||||
QString filePath = QString("%1/%2").arg(dir).arg(fileName);
|
||||
|
||||
AbstractExtItem *newItem = source->copy(filePath, number);
|
||||
if (newItem->showConfiguration(configArgs()) == 1) {
|
||||
initItems();
|
||||
repaintList();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AbstractExtItemAggregator::deleteItem()
|
||||
{
|
||||
AbstractExtItem *source = itemFromWidget();
|
||||
if (!source) {
|
||||
qCWarning(LOG_LIB) << "Nothing to delete";
|
||||
return;
|
||||
};
|
||||
|
||||
if (source->tryDelete()) {
|
||||
initItems();
|
||||
repaintList();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AbstractExtItemAggregator::editItem()
|
||||
{
|
||||
AbstractExtItem *source = itemFromWidget();
|
||||
if (!source) {
|
||||
qCWarning(LOG_LIB) << "Nothing to edit";
|
||||
return;
|
||||
};
|
||||
|
||||
if (source->showConfiguration(configArgs()) == 1) {
|
||||
initItems();
|
||||
repaintList();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -77,12 +125,69 @@ QString AbstractExtItemAggregator::getName()
|
||||
}
|
||||
|
||||
|
||||
AbstractExtItem *AbstractExtItemAggregator::itemFromWidget()
|
||||
{
|
||||
QListWidgetItem *widgetItem = ui->listWidget->currentItem();
|
||||
if (!widgetItem)
|
||||
return nullptr;
|
||||
|
||||
AbstractExtItem *found = nullptr;
|
||||
for (auto item : items()) {
|
||||
QString fileName = QFileInfo(item->fileName()).fileName();
|
||||
if (fileName != widgetItem->text())
|
||||
continue;
|
||||
found = item;
|
||||
break;
|
||||
}
|
||||
if (!found)
|
||||
qCWarning(LOG_LIB) << "Could not find item by name"
|
||||
<< widgetItem->text();
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
|
||||
void AbstractExtItemAggregator::repaintList()
|
||||
{
|
||||
ui->listWidget->clear();
|
||||
for (auto _item : items()) {
|
||||
QString fileName = QFileInfo(_item->fileName()).fileName();
|
||||
QListWidgetItem *item = new QListWidgetItem(fileName, ui->listWidget);
|
||||
QStringList tooltip;
|
||||
tooltip.append(i18n("Name: %1", _item->name()));
|
||||
tooltip.append(i18n("Comment: %1", _item->comment()));
|
||||
tooltip.append(i18n("Identity: %1", _item->uniq()));
|
||||
item->setToolTip(tooltip.join(QChar('\n')));
|
||||
ui->listWidget->addItem(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int AbstractExtItemAggregator::uniqNumber() const
|
||||
{
|
||||
QList<int> tagList;
|
||||
for (auto item : items())
|
||||
tagList.append(item->number());
|
||||
int number = 0;
|
||||
while (tagList.contains(number))
|
||||
number++;
|
||||
|
||||
return number;
|
||||
}
|
||||
|
||||
|
||||
QVariant AbstractExtItemAggregator::configArgs() const
|
||||
{
|
||||
return m_configArgs;
|
||||
}
|
||||
|
||||
|
||||
QString AbstractExtItemAggregator::type() const
|
||||
{
|
||||
return m_type;
|
||||
}
|
||||
|
||||
|
||||
void AbstractExtItemAggregator::setConfigArgs(const QVariant _configArgs)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Configuration arguments" << _configArgs;
|
||||
@ -102,9 +207,9 @@ void AbstractExtItemAggregator::editItemButtonPressed(QAbstractButton *button)
|
||||
if (static_cast<QPushButton *>(button) == copyButton)
|
||||
return copyItem();
|
||||
else if (static_cast<QPushButton *>(button) == createButton)
|
||||
return createItem();
|
||||
return doCreateItem();
|
||||
else if (static_cast<QPushButton *>(button) == deleteButton)
|
||||
return deleteItem();
|
||||
else if (dialogButtons->buttonRole(button) == QDialogButtonBox::AcceptRole)
|
||||
else if (ui->buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole)
|
||||
return editItem();
|
||||
}
|
||||
|
@ -19,31 +19,61 @@
|
||||
#define ABSTRACTEXTITEMAGGREGATOR_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QListWidget>
|
||||
#include <QPushButton>
|
||||
#include <QWidget>
|
||||
#include <QStandardPaths>
|
||||
|
||||
#include "abstractextitem.h"
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
// additional class since QObject macro does not allow class templates
|
||||
class AbstractExtItemAggregator : public QWidget
|
||||
class QAbstractButton;
|
||||
class QListWidgetItem;
|
||||
namespace Ui
|
||||
{
|
||||
class AbstractExtItemAggregator;
|
||||
}
|
||||
|
||||
class AbstractExtItemAggregator : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QVariant configArgs READ configArgs WRITE setConfigArgs)
|
||||
Q_PROPERTY(QVariant type READ type)
|
||||
|
||||
public:
|
||||
explicit AbstractExtItemAggregator(QWidget *parent = nullptr);
|
||||
explicit AbstractExtItemAggregator(QWidget *parent, const QString type);
|
||||
virtual ~AbstractExtItemAggregator();
|
||||
// methods
|
||||
void copyItem();
|
||||
template <class T> void createItem()
|
||||
{
|
||||
QString fileName = getName();
|
||||
int number = uniqNumber();
|
||||
QString dir = QString("%1/awesomewidgets/%2")
|
||||
.arg(QStandardPaths::writableLocation(
|
||||
QStandardPaths::GenericDataLocation))
|
||||
.arg(m_type);
|
||||
if (fileName.isEmpty()) {
|
||||
qCWarning(LOG_LIB) << "Nothing to create";
|
||||
return;
|
||||
};
|
||||
QString filePath = QString("%1/%2").arg(dir).arg(fileName);
|
||||
|
||||
T *newItem = new T(this, filePath);
|
||||
newItem->setNumber(number);
|
||||
if (newItem->showConfiguration(configArgs()) == 1) {
|
||||
initItems();
|
||||
repaintList();
|
||||
};
|
||||
};
|
||||
void deleteItem();
|
||||
void editItem();
|
||||
QString getName();
|
||||
// ui
|
||||
QDialog *dialog = nullptr;
|
||||
QListWidget *widgetDialog = nullptr;
|
||||
QDialogButtonBox *dialogButtons = nullptr;
|
||||
QPushButton *copyButton = nullptr;
|
||||
QPushButton *createButton = nullptr;
|
||||
QPushButton *deleteButton = nullptr;
|
||||
AbstractExtItem *itemFromWidget();
|
||||
void repaintList();
|
||||
int uniqNumber() const;
|
||||
// get methods
|
||||
QVariant configArgs() const;
|
||||
virtual QList<AbstractExtItem *> items() const = 0;
|
||||
QString type() const;
|
||||
// set methods
|
||||
void setConfigArgs(const QVariant _configArgs);
|
||||
|
||||
@ -52,12 +82,17 @@ private slots:
|
||||
void editItemButtonPressed(QAbstractButton *button);
|
||||
|
||||
private:
|
||||
// ui
|
||||
Ui::AbstractExtItemAggregator *ui = nullptr;
|
||||
QPushButton *copyButton = nullptr;
|
||||
QPushButton *createButton = nullptr;
|
||||
QPushButton *deleteButton = nullptr;
|
||||
// properties
|
||||
QVariant m_configArgs;
|
||||
// methods
|
||||
virtual void copyItem() = 0;
|
||||
virtual void createItem() = 0;
|
||||
virtual void deleteItem() = 0;
|
||||
virtual void editItem() = 0;
|
||||
QString m_type;
|
||||
// ui methods
|
||||
virtual void doCreateItem() = 0;
|
||||
virtual void initItems() = 0;
|
||||
};
|
||||
|
||||
|
||||
|
64
sources/awesomewidgets/abstractextitemaggregator.ui
Normal file
64
sources/awesomewidgets/abstractextitemaggregator.ui
Normal file
@ -0,0 +1,64 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>AbstractExtItemAggregator</class>
|
||||
<widget class="QDialog" name="AbstractExtItemAggregator">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QListWidget" name="listWidget"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Close|QDialogButtonBox::Open</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>AbstractExtItemAggregator</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>AbstractExtItemAggregator</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
47
sources/awesomewidgets/abstractweatherprovider.h
Normal file
47
sources/awesomewidgets/abstractweatherprovider.h
Normal file
@ -0,0 +1,47 @@
|
||||
/***************************************************************************
|
||||
* This file is part of awesome-widgets *
|
||||
* *
|
||||
* awesome-widgets is free software: you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* awesome-widgets is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef ABSTRACTWEATHERPROVIDER_H
|
||||
#define ABSTRACTWEATHERPROVIDER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QUrl>
|
||||
|
||||
|
||||
class AbstractWeatherProvider : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(int number READ number)
|
||||
|
||||
public:
|
||||
explicit AbstractWeatherProvider(QObject *parent, const int number)
|
||||
: QObject(parent)
|
||||
, m_number(number){};
|
||||
virtual ~AbstractWeatherProvider(){};
|
||||
virtual void initUrl(const QString city, const QString country,
|
||||
const int ts)
|
||||
= 0;
|
||||
virtual QVariantHash parse(const QVariantMap &json) const = 0;
|
||||
virtual QUrl url() const = 0;
|
||||
int number() const { return m_number; };
|
||||
|
||||
private:
|
||||
int m_number;
|
||||
};
|
||||
|
||||
|
||||
#endif /* ABSTRACTWEATHERPROVIDER_H */
|
139
sources/awesomewidgets/awabstractformatter.cpp
Normal file
139
sources/awesomewidgets/awabstractformatter.cpp
Normal file
@ -0,0 +1,139 @@
|
||||
/***************************************************************************
|
||||
* This file is part of awesome-widgets *
|
||||
* *
|
||||
* awesome-widgets is free software: you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* awesome-widgets is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
#include "awabstractformatter.h"
|
||||
|
||||
#include <QSettings>
|
||||
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
AWAbstractFormatter::AWAbstractFormatter(QWidget *parent,
|
||||
const QString filePath)
|
||||
: AbstractExtItem(parent, filePath)
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
}
|
||||
|
||||
|
||||
AWAbstractFormatter::~AWAbstractFormatter()
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
}
|
||||
|
||||
|
||||
void AWAbstractFormatter::copyDefaults(AbstractExtItem *_other) const
|
||||
{
|
||||
AbstractExtItem::copyDefaults(_other);
|
||||
|
||||
static_cast<AWAbstractFormatter *>(_other)->setType(type());
|
||||
}
|
||||
|
||||
|
||||
QString AWAbstractFormatter::uniq() const
|
||||
{
|
||||
return QString("%1(%2)").arg(name()).arg(strType());
|
||||
}
|
||||
|
||||
|
||||
QString AWAbstractFormatter::strType() const
|
||||
{
|
||||
QString value;
|
||||
switch (m_type) {
|
||||
case FormatterClass::DateTime:
|
||||
value = QString("DateTime");
|
||||
break;
|
||||
case FormatterClass::Float:
|
||||
value = QString("Float");
|
||||
break;
|
||||
case FormatterClass::List:
|
||||
value = QString("List");
|
||||
break;
|
||||
case FormatterClass::Script:
|
||||
value = QString("Script");
|
||||
break;
|
||||
case FormatterClass::String:
|
||||
value = QString("String");
|
||||
break;
|
||||
case FormatterClass::NoFormat:
|
||||
value = QString("NoFormat");
|
||||
break;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
AWAbstractFormatter::FormatterClass AWAbstractFormatter::type() const
|
||||
{
|
||||
return m_type;
|
||||
}
|
||||
|
||||
|
||||
void AWAbstractFormatter::setStrType(const QString _type)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Type" << _type;
|
||||
|
||||
if (_type == QString("DateTime"))
|
||||
m_type = FormatterClass::DateTime;
|
||||
else if (_type == QString("Float"))
|
||||
m_type = FormatterClass::Float;
|
||||
else if (_type == QString("List"))
|
||||
m_type = FormatterClass::List;
|
||||
else if (_type == QString("Script"))
|
||||
m_type = FormatterClass::Script;
|
||||
else if (_type == QString("String"))
|
||||
m_type = FormatterClass::String;
|
||||
else
|
||||
m_type = FormatterClass::NoFormat;
|
||||
}
|
||||
|
||||
|
||||
void AWAbstractFormatter::setType(
|
||||
const AWAbstractFormatter::FormatterClass _type)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Type" << static_cast<int>(_type);
|
||||
|
||||
m_type = _type;
|
||||
}
|
||||
|
||||
|
||||
void AWAbstractFormatter::readConfiguration()
|
||||
{
|
||||
AbstractExtItem::readConfiguration();
|
||||
|
||||
QSettings settings(fileName(), QSettings::IniFormat);
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
setStrType(settings.value(QString("X-AW-Type"), strType()).toString());
|
||||
settings.endGroup();
|
||||
}
|
||||
|
||||
|
||||
void AWAbstractFormatter::writeConfiguration() const
|
||||
{
|
||||
AbstractExtItem::writeConfiguration();
|
||||
|
||||
QSettings settings(writtableConfig(), QSettings::IniFormat);
|
||||
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
settings.setValue(QString("X-AW-Type"), strType());
|
||||
settings.endGroup();
|
||||
|
||||
settings.sync();
|
||||
}
|
63
sources/awesomewidgets/awabstractformatter.h
Normal file
63
sources/awesomewidgets/awabstractformatter.h
Normal file
@ -0,0 +1,63 @@
|
||||
/***************************************************************************
|
||||
* This file is part of awesome-widgets *
|
||||
* *
|
||||
* awesome-widgets is free software: you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* awesome-widgets is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef AWABSTRACTFORMATTER_H
|
||||
#define AWABSTRACTFORMATTER_H
|
||||
|
||||
#include "abstractextitem.h"
|
||||
|
||||
|
||||
class AWAbstractFormatter : public AbstractExtItem
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(FormatterClass type READ type WRITE setType)
|
||||
Q_PROPERTY(QString strType READ strType WRITE setStrType)
|
||||
|
||||
public:
|
||||
enum class FormatterClass {
|
||||
DateTime,
|
||||
Float,
|
||||
List,
|
||||
Script,
|
||||
String,
|
||||
NoFormat
|
||||
};
|
||||
|
||||
explicit AWAbstractFormatter(QWidget *parent,
|
||||
const QString filePath = QString());
|
||||
virtual ~AWAbstractFormatter();
|
||||
virtual QString convert(const QVariant &_value) const = 0;
|
||||
void copyDefaults(AbstractExtItem *_other) const;
|
||||
QString uniq() const;
|
||||
// properties
|
||||
QString strType() const;
|
||||
FormatterClass type() const;
|
||||
void setStrType(const QString type);
|
||||
void setType(const FormatterClass _type = FormatterClass::NoFormat);
|
||||
|
||||
public slots:
|
||||
virtual void readConfiguration();
|
||||
QVariantHash run() { return QVariantHash(); };
|
||||
virtual void writeConfiguration() const;
|
||||
|
||||
private:
|
||||
// properties
|
||||
FormatterClass m_type = FormatterClass::NoFormat;
|
||||
};
|
||||
|
||||
|
||||
#endif /* AWABSTRACTFORMATTER_H */
|
177
sources/awesomewidgets/awdatetimeformatter.cpp
Normal file
177
sources/awesomewidgets/awdatetimeformatter.cpp
Normal file
@ -0,0 +1,177 @@
|
||||
/***************************************************************************
|
||||
* This file is part of awesome-widgets *
|
||||
* *
|
||||
* awesome-widgets is free software: you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* awesome-widgets is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#include "awdatetimeformatter.h"
|
||||
#include "ui_awdatetimeformatter.h"
|
||||
|
||||
#include <KI18n/KLocalizedString>
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QDir>
|
||||
#include <QSettings>
|
||||
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
AWDateTimeFormatter::AWDateTimeFormatter(QWidget *parent,
|
||||
const QString filePath)
|
||||
: AWAbstractFormatter(parent, filePath)
|
||||
, ui(new Ui::AWDateTimeFormatter)
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
if (!filePath.isEmpty())
|
||||
readConfiguration();
|
||||
ui->setupUi(this);
|
||||
translate();
|
||||
}
|
||||
|
||||
|
||||
AWDateTimeFormatter::~AWDateTimeFormatter()
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
||||
QString AWDateTimeFormatter::convert(const QVariant &_value) const
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Convert value" << _value;
|
||||
|
||||
return m_locale.toString(_value.toDateTime(), m_format);
|
||||
}
|
||||
|
||||
|
||||
AWDateTimeFormatter *AWDateTimeFormatter::copy(const QString _fileName,
|
||||
const int _number)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
||||
|
||||
AWDateTimeFormatter *item
|
||||
= new AWDateTimeFormatter(static_cast<QWidget *>(parent()), _fileName);
|
||||
AWAbstractFormatter::copyDefaults(item);
|
||||
item->setFormat(format());
|
||||
item->setTranslateString(translateString());
|
||||
item->setNumber(_number);
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
QString AWDateTimeFormatter::format() const
|
||||
{
|
||||
return m_format;
|
||||
}
|
||||
|
||||
|
||||
bool AWDateTimeFormatter::translateString() const
|
||||
{
|
||||
return m_translate;
|
||||
}
|
||||
|
||||
|
||||
void AWDateTimeFormatter::setFormat(const QString _format)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Set format" << _format;
|
||||
|
||||
m_format = _format;
|
||||
}
|
||||
|
||||
|
||||
void AWDateTimeFormatter::setTranslateString(const bool _translate)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Set translate string" << _translate;
|
||||
|
||||
m_translate = _translate;
|
||||
initLocale();
|
||||
}
|
||||
|
||||
|
||||
void AWDateTimeFormatter::readConfiguration()
|
||||
{
|
||||
AWAbstractFormatter::readConfiguration();
|
||||
|
||||
QSettings settings(fileName(), QSettings::IniFormat);
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
setFormat(settings.value(QString("X-AW-Format"), format()).toString());
|
||||
setTranslateString(
|
||||
settings.value(QString("X-AW-Translate"), translateString()).toBool());
|
||||
settings.endGroup();
|
||||
|
||||
bumpApi(AWEFAPI);
|
||||
}
|
||||
|
||||
|
||||
int AWDateTimeFormatter::showConfiguration(const QVariant args)
|
||||
{
|
||||
Q_UNUSED(args)
|
||||
|
||||
ui->lineEdit_name->setText(name());
|
||||
ui->lineEdit_comment->setText(comment());
|
||||
ui->label_typeValue->setText(QString("DateTime"));
|
||||
ui->lineEdit_format->setText(format());
|
||||
ui->checkBox_translate->setCheckState(translateString() ? Qt::Checked
|
||||
: Qt::Unchecked);
|
||||
|
||||
int ret = exec();
|
||||
if (ret != 1)
|
||||
return ret;
|
||||
setName(ui->lineEdit_name->text());
|
||||
setComment(ui->lineEdit_comment->text());
|
||||
setApiVersion(AWEFAPI);
|
||||
setStrType(ui->label_typeValue->text());
|
||||
setFormat(ui->lineEdit_format->text());
|
||||
setTranslateString(ui->checkBox_translate->checkState() == Qt::Checked);
|
||||
|
||||
writeConfiguration();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void AWDateTimeFormatter::writeConfiguration() const
|
||||
{
|
||||
AWAbstractFormatter::writeConfiguration();
|
||||
|
||||
QSettings settings(writtableConfig(), QSettings::IniFormat);
|
||||
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
settings.setValue(QString("X-AW-Format"), format());
|
||||
settings.setValue(QString("X-AW-Translate"), translateString());
|
||||
settings.endGroup();
|
||||
|
||||
settings.sync();
|
||||
}
|
||||
|
||||
|
||||
void AWDateTimeFormatter::initLocale()
|
||||
{
|
||||
m_locale = m_translate ? QLocale::system() : QLocale::c();
|
||||
}
|
||||
|
||||
|
||||
void AWDateTimeFormatter::translate()
|
||||
{
|
||||
ui->label_name->setText(i18n("Name"));
|
||||
ui->label_comment->setText(i18n("Comment"));
|
||||
ui->label_type->setText(i18n("Type"));
|
||||
ui->label_format->setText(i18n("Format"));
|
||||
ui->checkBox_translate->setText(i18n("Translate strings"));
|
||||
}
|
65
sources/awesomewidgets/awdatetimeformatter.h
Normal file
65
sources/awesomewidgets/awdatetimeformatter.h
Normal file
@ -0,0 +1,65 @@
|
||||
/***************************************************************************
|
||||
* This file is part of awesome-widgets *
|
||||
* *
|
||||
* awesome-widgets is free software: you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* awesome-widgets is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef AWDATETIMEFORMATTER_H
|
||||
#define AWDATETIMEFORMATTER_H
|
||||
|
||||
#include "awabstractformatter.h"
|
||||
#include <QLocale>
|
||||
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class AWDateTimeFormatter;
|
||||
}
|
||||
|
||||
class AWDateTimeFormatter : public AWAbstractFormatter
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString format READ format WRITE setFormat)
|
||||
Q_PROPERTY(
|
||||
bool translateString READ translateString WRITE setTranslateString)
|
||||
|
||||
public:
|
||||
explicit AWDateTimeFormatter(QWidget *parent,
|
||||
const QString filePath = QString());
|
||||
virtual ~AWDateTimeFormatter();
|
||||
QString convert(const QVariant &_value) const;
|
||||
AWDateTimeFormatter *copy(const QString _fileName, const int _number);
|
||||
// properties
|
||||
QString format() const;
|
||||
bool translateString() const;
|
||||
void setFormat(const QString _format);
|
||||
void setTranslateString(const bool _translate);
|
||||
|
||||
public slots:
|
||||
void readConfiguration();
|
||||
int showConfiguration(const QVariant args = QVariant());
|
||||
void writeConfiguration() const;
|
||||
|
||||
private:
|
||||
Ui::AWDateTimeFormatter *ui = nullptr;
|
||||
void initLocale();
|
||||
void translate();
|
||||
// properties
|
||||
QLocale m_locale;
|
||||
QString m_format = QString();
|
||||
bool m_translate = true;
|
||||
};
|
||||
|
||||
|
||||
#endif /* AWDATETIMEFORMATTER_H */
|
197
sources/awesomewidgets/awdatetimeformatter.ui
Normal file
197
sources/awesomewidgets/awdatetimeformatter.ui
Normal file
@ -0,0 +1,197 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>AWDateTimeFormatter</class>
|
||||
<widget class="QDialog" name="AWDateTimeFormatter">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>420</width>
|
||||
<height>185</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Configuration</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_name">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_name">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_name"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_comment">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_comment">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Comment</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_comment"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_type">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_type">
|
||||
<property name="text">
|
||||
<string>Type</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_typeValue">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_format">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_format">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Format</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_format"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_translate">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_translate">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Translate strings</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>AWDateTimeFormatter</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>AWDateTimeFormatter</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
@ -1,11 +1,75 @@
|
||||
{
|
||||
"__url": "https://developer.yahoo.com/weather/documentation.html",
|
||||
"__url-yahoo": "https://developer.yahoo.com/weather/documentation.html",
|
||||
"__url-owm": "http://openweathermap.org/weather-conditions",
|
||||
|
||||
"image": {
|
||||
"__comment": "should be described as html image with full path inside",
|
||||
|
||||
"default": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/3200.gif\">",
|
||||
|
||||
"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\">",
|
||||
@ -59,8 +123,71 @@
|
||||
|
||||
"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",
|
||||
|
||||
"3200": "\u2604",
|
||||
"0": "\u2604",
|
||||
"1": "\u2604",
|
||||
"2": "\u2604",
|
||||
|
287
sources/awesomewidgets/awfloatformatter.cpp
Normal file
287
sources/awesomewidgets/awfloatformatter.cpp
Normal file
@ -0,0 +1,287 @@
|
||||
/***************************************************************************
|
||||
* This file is part of awesome-widgets *
|
||||
* *
|
||||
* awesome-widgets is free software: you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* awesome-widgets is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#include "awfloatformatter.h"
|
||||
#include "ui_awfloatformatter.h"
|
||||
|
||||
#include <KI18n/KLocalizedString>
|
||||
|
||||
#include <QDir>
|
||||
#include <QSettings>
|
||||
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
AWFloatFormatter::AWFloatFormatter(QWidget *parent, const QString filePath)
|
||||
: AWAbstractFormatter(parent, filePath)
|
||||
, ui(new Ui::AWFloatFormatter)
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
if (!filePath.isEmpty())
|
||||
readConfiguration();
|
||||
ui->setupUi(this);
|
||||
translate();
|
||||
}
|
||||
|
||||
|
||||
AWFloatFormatter::~AWFloatFormatter()
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
||||
QString AWFloatFormatter::convert(const QVariant &_value) const
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Convert value" << _value;
|
||||
|
||||
QString output
|
||||
= QString("%1").arg(_value.toDouble() * multiplier() + summand(),
|
||||
count(), format(), precision(), fillChar());
|
||||
if (forceWidth())
|
||||
output = output.left(count());
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
AWFloatFormatter *AWFloatFormatter::copy(const QString _fileName,
|
||||
const int _number)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
||||
|
||||
AWFloatFormatter *item
|
||||
= new AWFloatFormatter(static_cast<QWidget *>(parent()), _fileName);
|
||||
AWAbstractFormatter::copyDefaults(item);
|
||||
item->setCount(count());
|
||||
item->setFormat(format());
|
||||
item->setFillChar(fillChar());
|
||||
item->setForceWidth(forceWidth());
|
||||
item->setMultiplier(multiplier());
|
||||
item->setNumber(_number);
|
||||
item->setPrecision(precision());
|
||||
item->setSummand(summand());
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
int AWFloatFormatter::count() const
|
||||
{
|
||||
return m_count;
|
||||
}
|
||||
|
||||
|
||||
QChar AWFloatFormatter::fillChar() const
|
||||
{
|
||||
return m_fillChar;
|
||||
}
|
||||
|
||||
|
||||
bool AWFloatFormatter::forceWidth() const
|
||||
{
|
||||
return m_forceWidth;
|
||||
}
|
||||
|
||||
|
||||
char AWFloatFormatter::format() const
|
||||
{
|
||||
return m_format;
|
||||
}
|
||||
|
||||
|
||||
double AWFloatFormatter::multiplier() const
|
||||
{
|
||||
return m_multiplier;
|
||||
}
|
||||
|
||||
|
||||
int AWFloatFormatter::precision() const
|
||||
{
|
||||
return m_precision;
|
||||
}
|
||||
|
||||
|
||||
double AWFloatFormatter::summand() const
|
||||
{
|
||||
return m_summand;
|
||||
}
|
||||
|
||||
|
||||
void AWFloatFormatter::setCount(const int _count)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Set width" << _count;
|
||||
|
||||
m_count = _count;
|
||||
}
|
||||
|
||||
|
||||
void AWFloatFormatter::setFillChar(const QChar _fillChar)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Set char" << _fillChar;
|
||||
|
||||
m_fillChar = _fillChar;
|
||||
}
|
||||
|
||||
|
||||
void AWFloatFormatter::setForceWidth(const bool _forceWidth)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Set force strip" << _forceWidth;
|
||||
|
||||
m_forceWidth = _forceWidth;
|
||||
}
|
||||
|
||||
|
||||
void AWFloatFormatter::setFormat(char _format)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Set format" << _format;
|
||||
// http://doc.qt.io/qt-5/qstring.html#argument-formats
|
||||
if ((_format != 'e') && (_format != 'E') && (_format != 'f')
|
||||
&& (_format != 'g') && (_format != 'G')) {
|
||||
qCWarning(LOG_LIB) << "Invalid format" << _format;
|
||||
_format = 'f';
|
||||
}
|
||||
|
||||
m_format = _format;
|
||||
}
|
||||
|
||||
|
||||
void AWFloatFormatter::setMultiplier(const double _multiplier)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Set multiplier" << _multiplier;
|
||||
|
||||
m_multiplier = _multiplier;
|
||||
}
|
||||
|
||||
|
||||
void AWFloatFormatter::setPrecision(const int _precision)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Set precision" << _precision;
|
||||
|
||||
m_precision = _precision;
|
||||
}
|
||||
|
||||
|
||||
void AWFloatFormatter::setSummand(const double _summand)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Set summand" << _summand;
|
||||
|
||||
m_summand = _summand;
|
||||
}
|
||||
|
||||
|
||||
void AWFloatFormatter::readConfiguration()
|
||||
{
|
||||
AWAbstractFormatter::readConfiguration();
|
||||
|
||||
QSettings settings(fileName(), QSettings::IniFormat);
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
setCount(settings.value(QString("X-AW-Width"), count()).toInt());
|
||||
setFillChar(
|
||||
settings.value(QString("X-AW-FillChar"), fillChar()).toString().at(0));
|
||||
setForceWidth(
|
||||
settings.value(QString("X-AW-ForceWidth"), forceWidth()).toBool());
|
||||
setFormat(settings.value(QString("X-AW-Format"), QString(format()))
|
||||
.toString()
|
||||
.at(0)
|
||||
.toLatin1());
|
||||
setMultiplier(
|
||||
settings.value(QString("X-AW-Multiplier"), multiplier()).toDouble());
|
||||
setPrecision(
|
||||
settings.value(QString("X-AW-Precision"), precision()).toInt());
|
||||
setSummand(settings.value(QString("X-AW-Summand"), summand()).toDouble());
|
||||
settings.endGroup();
|
||||
|
||||
bumpApi(AWEFAPI);
|
||||
}
|
||||
|
||||
|
||||
int AWFloatFormatter::showConfiguration(const QVariant args)
|
||||
{
|
||||
Q_UNUSED(args)
|
||||
|
||||
ui->lineEdit_name->setText(name());
|
||||
ui->lineEdit_comment->setText(comment());
|
||||
ui->label_typeValue->setText(QString("Float"));
|
||||
ui->comboBox_format->setCurrentIndex(
|
||||
ui->comboBox_format->findText(QString(format())));
|
||||
ui->spinBox_precision->setValue(precision());
|
||||
ui->spinBox_width->setValue(count());
|
||||
ui->lineEdit_fill->setText(QString(fillChar()));
|
||||
ui->checkBox_forceWidth->setCheckState(forceWidth() ? Qt::Checked
|
||||
: Qt::Unchecked);
|
||||
ui->doubleSpinBox_multiplier->setValue(multiplier());
|
||||
ui->doubleSpinBox_summand->setValue(summand());
|
||||
|
||||
int ret = exec();
|
||||
if (ret != 1)
|
||||
return ret;
|
||||
setName(ui->lineEdit_name->text());
|
||||
setComment(ui->lineEdit_comment->text());
|
||||
setApiVersion(AWEFAPI);
|
||||
setStrType(ui->label_typeValue->text());
|
||||
setFormat(ui->comboBox_format->currentText().at(0).toLatin1());
|
||||
setPrecision(ui->spinBox_precision->value());
|
||||
setCount(ui->spinBox_width->value());
|
||||
setFillChar(ui->lineEdit_fill->text().at(0));
|
||||
setForceWidth(ui->checkBox_forceWidth->checkState() == Qt::Checked);
|
||||
setMultiplier(ui->doubleSpinBox_multiplier->value());
|
||||
setSummand(ui->doubleSpinBox_summand->value());
|
||||
|
||||
writeConfiguration();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void AWFloatFormatter::writeConfiguration() const
|
||||
{
|
||||
AWAbstractFormatter::writeConfiguration();
|
||||
|
||||
QSettings settings(writtableConfig(), QSettings::IniFormat);
|
||||
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
settings.setValue(QString("X-AW-Width"), count());
|
||||
settings.setValue(QString("X-AW-FillChar"), fillChar());
|
||||
settings.setValue(QString("X-AW-Format"), QString(format()));
|
||||
settings.setValue(QString("X-AW-ForceWidth"), forceWidth());
|
||||
settings.setValue(QString("X-AW-Multiplier"), multiplier());
|
||||
settings.setValue(QString("X-AW-Precision"), precision());
|
||||
settings.setValue(QString("X-AW-Summand"), summand());
|
||||
settings.endGroup();
|
||||
|
||||
settings.sync();
|
||||
}
|
||||
|
||||
|
||||
void AWFloatFormatter::translate()
|
||||
{
|
||||
ui->label_name->setText(i18n("Name"));
|
||||
ui->label_comment->setText(i18n("Comment"));
|
||||
ui->label_type->setText(i18n("Type"));
|
||||
ui->label_format->setText(i18n("Format"));
|
||||
ui->label_precision->setText(i18n("Precision"));
|
||||
ui->label_width->setText(i18n("Width"));
|
||||
ui->label_fill->setText(i18n("Fill char"));
|
||||
ui->checkBox_forceWidth->setText(i18n("Force width"));
|
||||
ui->label_multiplier->setText(i18n("Multiplier"));
|
||||
ui->label_summand->setText(i18n("Summand"));
|
||||
}
|
81
sources/awesomewidgets/awfloatformatter.h
Normal file
81
sources/awesomewidgets/awfloatformatter.h
Normal file
@ -0,0 +1,81 @@
|
||||
/***************************************************************************
|
||||
* 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"
|
||||
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class AWFloatFormatter;
|
||||
}
|
||||
|
||||
class AWFloatFormatter : public AWAbstractFormatter
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(int count READ count WRITE setCount)
|
||||
Q_PROPERTY(QChar fillChar READ fillChar WRITE setFillChar)
|
||||
Q_PROPERTY(bool forceWidth READ forceWidth WRITE setForceWidth)
|
||||
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)
|
||||
|
||||
public:
|
||||
explicit AWFloatFormatter(QWidget *parent,
|
||||
const QString filePath = QString());
|
||||
virtual ~AWFloatFormatter();
|
||||
QString convert(const QVariant &_value) const;
|
||||
AWFloatFormatter *copy(const QString _fileName, const int _number);
|
||||
// properties
|
||||
int count() const;
|
||||
QChar fillChar() const;
|
||||
bool forceWidth() const;
|
||||
char format() const;
|
||||
double multiplier() const;
|
||||
int precision() const;
|
||||
double summand() const;
|
||||
void setCount(const int _count);
|
||||
void setFillChar(const QChar _fillChar);
|
||||
void setForceWidth(const bool _forceWidth);
|
||||
void setFormat(char _format);
|
||||
void setMultiplier(const double _multiplier);
|
||||
void setPrecision(const int _precision);
|
||||
void setSummand(const double _summand);
|
||||
|
||||
public slots:
|
||||
void readConfiguration();
|
||||
int showConfiguration(const QVariant args = QVariant());
|
||||
void writeConfiguration() const;
|
||||
|
||||
private:
|
||||
Ui::AWFloatFormatter *ui = nullptr;
|
||||
void translate();
|
||||
// properties
|
||||
int m_count = 0;
|
||||
QChar m_fillChar = QChar();
|
||||
bool m_forceWidth = false;
|
||||
char m_format = 'f';
|
||||
double m_multiplier = 1.0;
|
||||
int m_precision = -1;
|
||||
double m_summand = 0.0;
|
||||
};
|
||||
|
||||
|
||||
#endif /* AWFLOATFORMATTER_H */
|
347
sources/awesomewidgets/awfloatformatter.ui
Normal file
347
sources/awesomewidgets/awfloatformatter.ui
Normal file
@ -0,0 +1,347 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>AWFloatFormatter</class>
|
||||
<widget class="QDialog" name="AWFloatFormatter">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>420</width>
|
||||
<height>362</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Configuration</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_name">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_name">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_name"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_comment">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_comment">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Comment</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_comment"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_type">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_type">
|
||||
<property name="text">
|
||||
<string>Type</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_typeValue">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_format">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_format">
|
||||
<property name="text">
|
||||
<string>Format</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="comboBox_format">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string notr="true">e</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string notr="true">E</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string notr="true">f</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string notr="true">g</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string notr="true">G</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_precision">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_precision">
|
||||
<property name="text">
|
||||
<string>Precision</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="spinBox_precision">
|
||||
<property name="minimum">
|
||||
<number>-1</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>10000</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_width">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_width">
|
||||
<property name="text">
|
||||
<string>Width</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="spinBox_width">
|
||||
<property name="minimum">
|
||||
<number>-10000</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>10000</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_fill">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_fill">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Fill char</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_fill">
|
||||
<property name="maxLength">
|
||||
<number>1</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_forceWIdth">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_forceWidth">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Force width</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_multiplier">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_multiplier">
|
||||
<property name="text">
|
||||
<string>Multiplier</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDoubleSpinBox" name="doubleSpinBox_multiplier">
|
||||
<property name="minimum">
|
||||
<double>-1000000000.000000000000000</double>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>1000000000.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_summand">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_summand">
|
||||
<property name="text">
|
||||
<string>Summand</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDoubleSpinBox" name="doubleSpinBox_summand">
|
||||
<property name="minimum">
|
||||
<double>-1000000000.000000000000000</double>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>1000000000.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>AWFloatFormatter</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>AWFloatFormatter</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
192
sources/awesomewidgets/awlistformatter.cpp
Normal file
192
sources/awesomewidgets/awlistformatter.cpp
Normal file
@ -0,0 +1,192 @@
|
||||
/***************************************************************************
|
||||
* This file is part of awesome-widgets *
|
||||
* *
|
||||
* awesome-widgets is free software: you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* awesome-widgets is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#include "awlistformatter.h"
|
||||
#include "ui_awlistformatter.h"
|
||||
|
||||
#include <KI18n/KLocalizedString>
|
||||
|
||||
#include <QSettings>
|
||||
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
AWListFormatter::AWListFormatter(QWidget *parent, const QString filePath)
|
||||
: AWAbstractFormatter(parent, filePath)
|
||||
, ui(new Ui::AWListFormatter)
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
if (!filePath.isEmpty())
|
||||
readConfiguration();
|
||||
ui->setupUi(this);
|
||||
translate();
|
||||
}
|
||||
|
||||
|
||||
AWListFormatter::~AWListFormatter()
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
||||
QString AWListFormatter::convert(const QVariant &_value) const
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Convert value" << _value;
|
||||
|
||||
QStringList output = _value.toStringList();
|
||||
if (isSorted())
|
||||
output.sort();
|
||||
|
||||
return output.filter(m_regex).join(separator());
|
||||
}
|
||||
|
||||
|
||||
AWListFormatter *AWListFormatter::copy(const QString _fileName,
|
||||
const int _number)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
||||
|
||||
AWListFormatter *item
|
||||
= new AWListFormatter(static_cast<QWidget *>(parent()), _fileName);
|
||||
AWAbstractFormatter::copyDefaults(item);
|
||||
item->setFilter(filter());
|
||||
item->setSeparator(separator());
|
||||
item->setSorted(isSorted());
|
||||
item->setNumber(_number);
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
QString AWListFormatter::filter() const
|
||||
{
|
||||
return m_filter;
|
||||
}
|
||||
|
||||
|
||||
bool AWListFormatter::isSorted() const
|
||||
{
|
||||
return m_sorted;
|
||||
}
|
||||
|
||||
|
||||
QString AWListFormatter::separator() const
|
||||
{
|
||||
return m_separator;
|
||||
}
|
||||
|
||||
|
||||
void AWListFormatter::setFilter(const QString _filter)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Filter" << _filter;
|
||||
|
||||
m_filter = _filter;
|
||||
m_regex = QRegExp(m_filter);
|
||||
}
|
||||
|
||||
|
||||
void AWListFormatter::setSeparator(const QString _separator)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Separtor" << _separator;
|
||||
|
||||
m_separator = _separator;
|
||||
}
|
||||
|
||||
|
||||
void AWListFormatter::setSorted(const bool _sorted)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Sorting" << _sorted;
|
||||
|
||||
m_sorted = _sorted;
|
||||
}
|
||||
|
||||
|
||||
void AWListFormatter::readConfiguration()
|
||||
{
|
||||
AWAbstractFormatter::readConfiguration();
|
||||
|
||||
QSettings settings(fileName(), QSettings::IniFormat);
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
setFilter(settings.value(QString("X-AW-Filter"), filter()).toString());
|
||||
setSeparator(
|
||||
settings.value(QString("X-AW-Separator"), separator()).toString());
|
||||
setSorted(settings.value(QString("X-AW-Sort"), isSorted()).toBool());
|
||||
settings.endGroup();
|
||||
|
||||
bumpApi(AWEFAPI);
|
||||
}
|
||||
|
||||
|
||||
int AWListFormatter::showConfiguration(const QVariant args)
|
||||
{
|
||||
Q_UNUSED(args)
|
||||
|
||||
ui->lineEdit_name->setText(name());
|
||||
ui->lineEdit_comment->setText(comment());
|
||||
ui->label_typeValue->setText(QString("NoFormat"));
|
||||
ui->lineEdit_filter->setText(filter());
|
||||
ui->lineEdit_separator->setText(separator());
|
||||
ui->checkBox_sorted->setCheckState(isSorted() ? Qt::Checked
|
||||
: Qt::Unchecked);
|
||||
|
||||
int ret = exec();
|
||||
if (ret != 1)
|
||||
return ret;
|
||||
setName(ui->lineEdit_name->text());
|
||||
setComment(ui->lineEdit_comment->text());
|
||||
setApiVersion(AWEFAPI);
|
||||
setStrType(ui->label_typeValue->text());
|
||||
setFilter(ui->lineEdit_filter->text());
|
||||
setSeparator(ui->lineEdit_separator->text());
|
||||
setSorted(ui->checkBox_sorted->checkState() == Qt::Checked);
|
||||
|
||||
writeConfiguration();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void AWListFormatter::writeConfiguration() const
|
||||
{
|
||||
AWAbstractFormatter::writeConfiguration();
|
||||
|
||||
QSettings settings(writtableConfig(), QSettings::IniFormat);
|
||||
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
settings.setValue(QString("X-AW-Filter"), filter());
|
||||
settings.setValue(QString("X-AW-Separator"), separator());
|
||||
settings.setValue(QString("X-AW-Sort"), isSorted());
|
||||
settings.endGroup();
|
||||
|
||||
settings.sync();
|
||||
}
|
||||
|
||||
|
||||
void AWListFormatter::translate()
|
||||
{
|
||||
ui->label_name->setText(i18n("Name"));
|
||||
ui->label_comment->setText(i18n("Comment"));
|
||||
ui->label_type->setText(i18n("Type"));
|
||||
ui->label_filter->setText(i18n("Filter"));
|
||||
ui->label_separator->setText(i18n("Separator"));
|
||||
ui->checkBox_sorted->setText(i18n("Sort"));
|
||||
}
|
66
sources/awesomewidgets/awlistformatter.h
Normal file
66
sources/awesomewidgets/awlistformatter.h
Normal file
@ -0,0 +1,66 @@
|
||||
/***************************************************************************
|
||||
* This file is part of awesome-widgets *
|
||||
* *
|
||||
* awesome-widgets is free software: you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* awesome-widgets is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef AWLISTFORMATTER_H
|
||||
#define AWLISTFORMATTER_H
|
||||
|
||||
#include "awabstractformatter.h"
|
||||
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class AWListFormatter;
|
||||
}
|
||||
|
||||
class AWListFormatter : public AWAbstractFormatter
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString filter READ filter WRITE setFilter)
|
||||
Q_PROPERTY(QString separator READ separator WRITE setSeparator)
|
||||
Q_PROPERTY(bool sorted READ isSorted WRITE setSorted)
|
||||
|
||||
public:
|
||||
explicit AWListFormatter(QWidget *parent,
|
||||
const QString filePath = QString());
|
||||
virtual ~AWListFormatter();
|
||||
QString convert(const QVariant &_value) const;
|
||||
AWListFormatter *copy(const QString _fileName, const int _number);
|
||||
// properties
|
||||
QString filter() const;
|
||||
bool isSorted() const;
|
||||
QString separator() const;
|
||||
void setFilter(const QString _filter);
|
||||
void setSeparator(const QString _separator);
|
||||
void setSorted(const bool _sorted);
|
||||
|
||||
public slots:
|
||||
void readConfiguration();
|
||||
int showConfiguration(const QVariant args = QVariant());
|
||||
void writeConfiguration() const;
|
||||
|
||||
private:
|
||||
Ui::AWListFormatter *ui = nullptr;
|
||||
void translate();
|
||||
// properties
|
||||
QString m_filter = QString();
|
||||
QString m_separator = QString();
|
||||
bool m_sorted = false;
|
||||
QRegExp m_regex;
|
||||
};
|
||||
|
||||
|
||||
#endif /* AWLISTFORMATTER_H */
|
220
sources/awesomewidgets/awlistformatter.ui
Normal file
220
sources/awesomewidgets/awlistformatter.ui
Normal file
@ -0,0 +1,220 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>AWListFormatter</class>
|
||||
<widget class="QDialog" name="AWListFormatter">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>420</width>
|
||||
<height>225</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Configuration</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_name">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_name">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_name"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_comment">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_comment">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Comment</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_comment"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_type">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_type">
|
||||
<property name="text">
|
||||
<string>Type</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_typeValue">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_filter">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_filter">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Filter</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_filter"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_separator">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_separator">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Separator</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_separator"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_sorted">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_sorted">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Sort</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>AWListFormatter</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>AWListFormatter</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
95
sources/awesomewidgets/awnoformatter.cpp
Normal file
95
sources/awesomewidgets/awnoformatter.cpp
Normal file
@ -0,0 +1,95 @@
|
||||
/***************************************************************************
|
||||
* This file is part of awesome-widgets *
|
||||
* *
|
||||
* awesome-widgets is free software: you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* awesome-widgets is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#include "awnoformatter.h"
|
||||
#include "ui_awnoformatter.h"
|
||||
|
||||
#include <KI18n/KLocalizedString>
|
||||
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
AWNoFormatter::AWNoFormatter(QWidget *parent, const QString filePath)
|
||||
: AWAbstractFormatter(parent, filePath)
|
||||
, ui(new Ui::AWNoFormatter)
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
if (!filePath.isEmpty())
|
||||
readConfiguration();
|
||||
ui->setupUi(this);
|
||||
translate();
|
||||
}
|
||||
|
||||
|
||||
AWNoFormatter::~AWNoFormatter()
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
||||
QString AWNoFormatter::convert(const QVariant &_value) const
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Convert value" << _value;
|
||||
|
||||
return _value.toString();
|
||||
}
|
||||
|
||||
|
||||
AWNoFormatter *AWNoFormatter::copy(const QString _fileName, const int _number)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
||||
|
||||
AWNoFormatter *item
|
||||
= new AWNoFormatter(static_cast<QWidget *>(parent()), _fileName);
|
||||
AWAbstractFormatter::copyDefaults(item);
|
||||
item->setNumber(_number);
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
int AWNoFormatter::showConfiguration(const QVariant args)
|
||||
{
|
||||
Q_UNUSED(args)
|
||||
|
||||
ui->lineEdit_name->setText(name());
|
||||
ui->lineEdit_comment->setText(comment());
|
||||
ui->label_typeValue->setText(QString("NoFormat"));
|
||||
|
||||
int ret = exec();
|
||||
if (ret != 1)
|
||||
return ret;
|
||||
setName(ui->lineEdit_name->text());
|
||||
setComment(ui->lineEdit_comment->text());
|
||||
setApiVersion(AWEFAPI);
|
||||
setStrType(ui->label_typeValue->text());
|
||||
|
||||
writeConfiguration();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void AWNoFormatter::translate()
|
||||
{
|
||||
ui->label_name->setText(i18n("Name"));
|
||||
ui->label_comment->setText(i18n("Comment"));
|
||||
ui->label_type->setText(i18n("Type"));
|
||||
}
|
49
sources/awesomewidgets/awnoformatter.h
Normal file
49
sources/awesomewidgets/awnoformatter.h
Normal file
@ -0,0 +1,49 @@
|
||||
/***************************************************************************
|
||||
* This file is part of awesome-widgets *
|
||||
* *
|
||||
* awesome-widgets is free software: you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* awesome-widgets is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef AWNOFORMATTER_H
|
||||
#define AWNOFORMATTER_H
|
||||
|
||||
#include "awabstractformatter.h"
|
||||
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class AWNoFormatter;
|
||||
}
|
||||
|
||||
class AWNoFormatter : public AWAbstractFormatter
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AWNoFormatter(QWidget *parent, const QString filePath = QString());
|
||||
virtual ~AWNoFormatter();
|
||||
QString convert(const QVariant &_value) const;
|
||||
AWNoFormatter *copy(const QString _fileName, const int _number);
|
||||
|
||||
public slots:
|
||||
int showConfiguration(const QVariant args = QVariant());
|
||||
|
||||
private:
|
||||
Ui::AWNoFormatter *ui = nullptr;
|
||||
void translate();
|
||||
// properties
|
||||
};
|
||||
|
||||
|
||||
#endif /* AWNOFORMATTER_H */
|
144
sources/awesomewidgets/awnoformatter.ui
Normal file
144
sources/awesomewidgets/awnoformatter.ui
Normal file
@ -0,0 +1,144 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>AWNoFormatter</class>
|
||||
<widget class="QDialog" name="AWNoFormatter">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>420</width>
|
||||
<height>128</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Configuration</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_name">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_name">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_name"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_comment">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_comment">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Comment</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_comment"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_type">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_type">
|
||||
<property name="text">
|
||||
<string>Type</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_typeValue">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>AWNoFormatter</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>AWNoFormatter</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
229
sources/awesomewidgets/awscriptformatter.cpp
Normal file
229
sources/awesomewidgets/awscriptformatter.cpp
Normal file
@ -0,0 +1,229 @@
|
||||
/***************************************************************************
|
||||
* This file is part of awesome-widgets *
|
||||
* *
|
||||
* awesome-widgets is free software: you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* awesome-widgets is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#include "awscriptformatter.h"
|
||||
#include "ui_awscriptformatter.h"
|
||||
|
||||
#include <KI18n/KLocalizedString>
|
||||
|
||||
#include <QDir>
|
||||
#include <QJSEngine>
|
||||
#include <QSettings>
|
||||
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
AWScriptFormatter::AWScriptFormatter(QWidget *parent, const QString filePath)
|
||||
: AWAbstractFormatter(parent, filePath)
|
||||
, ui(new Ui::AWScriptFormatter)
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
if (!filePath.isEmpty())
|
||||
readConfiguration();
|
||||
ui->setupUi(this);
|
||||
translate();
|
||||
}
|
||||
|
||||
|
||||
AWScriptFormatter::~AWScriptFormatter()
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
||||
QString AWScriptFormatter::convert(const QVariant &_value) const
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Convert value" << _value;
|
||||
|
||||
// init engine
|
||||
QJSEngine engine;
|
||||
QJSValue fn = engine.evaluate(m_program);
|
||||
QJSValueList args = QJSValueList() << _value.toString();
|
||||
QJSValue result = fn.call(args);
|
||||
|
||||
if (result.isError()) {
|
||||
qCWarning(LOG_LIB) << "Uncaught exception at line"
|
||||
<< result.property("lineNumber").toInt() << ":"
|
||||
<< result.toString();
|
||||
return QString();
|
||||
} else {
|
||||
return result.toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
AWScriptFormatter *AWScriptFormatter::copy(const QString _fileName,
|
||||
const int _number)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
||||
|
||||
AWScriptFormatter *item
|
||||
= new AWScriptFormatter(static_cast<QWidget *>(parent()), _fileName);
|
||||
AWAbstractFormatter::copyDefaults(item);
|
||||
item->setAppendCode(appendCode());
|
||||
item->setCode(code());
|
||||
item->setHasReturn(hasReturn());
|
||||
item->setNumber(_number);
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
bool AWScriptFormatter::appendCode() const
|
||||
{
|
||||
return m_appendCode;
|
||||
}
|
||||
|
||||
|
||||
QString AWScriptFormatter::code() const
|
||||
{
|
||||
return m_code;
|
||||
}
|
||||
|
||||
|
||||
bool AWScriptFormatter::hasReturn() const
|
||||
{
|
||||
return m_hasReturn;
|
||||
}
|
||||
|
||||
|
||||
QString AWScriptFormatter::program() const
|
||||
{
|
||||
return m_program;
|
||||
}
|
||||
|
||||
|
||||
void AWScriptFormatter::setAppendCode(const bool _appendCode)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Set append code" << _appendCode;
|
||||
|
||||
m_appendCode = _appendCode;
|
||||
initProgram();
|
||||
}
|
||||
|
||||
|
||||
void AWScriptFormatter::setCode(const QString _code)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Set code" << _code;
|
||||
|
||||
m_code = _code;
|
||||
initProgram();
|
||||
}
|
||||
|
||||
|
||||
void AWScriptFormatter::setHasReturn(const bool _hasReturn)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Set has return" << _hasReturn;
|
||||
|
||||
m_hasReturn = _hasReturn;
|
||||
initProgram();
|
||||
}
|
||||
|
||||
|
||||
void AWScriptFormatter::readConfiguration()
|
||||
{
|
||||
AWAbstractFormatter::readConfiguration();
|
||||
|
||||
QSettings settings(fileName(), QSettings::IniFormat);
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
setAppendCode(
|
||||
settings.value(QString("X-AW-AppendCode"), appendCode()).toBool());
|
||||
setCode(settings.value(QString("X-AW-Code"), code()).toString());
|
||||
setHasReturn(
|
||||
settings.value(QString("X-AW-HasReturn"), hasReturn()).toBool());
|
||||
settings.endGroup();
|
||||
|
||||
bumpApi(AWEFAPI);
|
||||
}
|
||||
|
||||
|
||||
int AWScriptFormatter::showConfiguration(const QVariant args)
|
||||
{
|
||||
Q_UNUSED(args)
|
||||
|
||||
ui->lineEdit_name->setText(name());
|
||||
ui->lineEdit_comment->setText(comment());
|
||||
ui->label_typeValue->setText(QString("Script"));
|
||||
ui->checkBox_appendCode->setCheckState(appendCode() ? Qt::Checked
|
||||
: Qt::Unchecked);
|
||||
ui->checkBox_hasReturn->setCheckState(hasReturn() ? Qt::Checked
|
||||
: Qt::Unchecked);
|
||||
ui->textEdit_code->setPlainText(code());
|
||||
|
||||
int ret = exec();
|
||||
if (ret != 1)
|
||||
return ret;
|
||||
setName(ui->lineEdit_name->text());
|
||||
setComment(ui->lineEdit_comment->text());
|
||||
setApiVersion(AWEFAPI);
|
||||
setStrType(ui->label_typeValue->text());
|
||||
setAppendCode(ui->checkBox_appendCode->checkState() == Qt::Checked);
|
||||
setHasReturn(ui->checkBox_hasReturn->checkState() == Qt::Checked);
|
||||
setCode(ui->textEdit_code->toPlainText());
|
||||
initProgram();
|
||||
|
||||
writeConfiguration();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void AWScriptFormatter::writeConfiguration() const
|
||||
{
|
||||
AWAbstractFormatter::writeConfiguration();
|
||||
|
||||
QSettings settings(writtableConfig(), QSettings::IniFormat);
|
||||
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
settings.setValue(QString("X-AW-AppendCode"), appendCode());
|
||||
settings.setValue(QString("X-AW-Code"), code());
|
||||
settings.setValue(QString("X-AW-HasReturn"), hasReturn());
|
||||
settings.endGroup();
|
||||
|
||||
settings.sync();
|
||||
}
|
||||
|
||||
|
||||
void AWScriptFormatter::initProgram()
|
||||
{
|
||||
// init JS code
|
||||
if (appendCode())
|
||||
m_program
|
||||
= QString("(function(value) { %1%2 })")
|
||||
.arg(code())
|
||||
.arg(hasReturn() ? QString("") : QString("; return output;"));
|
||||
else
|
||||
m_program = code();
|
||||
|
||||
qCInfo(LOG_LIB) << "Create JS engine with code" << m_program;
|
||||
}
|
||||
|
||||
|
||||
void AWScriptFormatter::translate()
|
||||
{
|
||||
ui->label_name->setText(i18n("Name"));
|
||||
ui->label_comment->setText(i18n("Comment"));
|
||||
ui->label_type->setText(i18n("Type"));
|
||||
ui->checkBox_appendCode->setText(i18n("Append code"));
|
||||
ui->checkBox_hasReturn->setText(i18n("Has return"));
|
||||
ui->label_code->setText(i18n("Code"));
|
||||
}
|
69
sources/awesomewidgets/awscriptformatter.h
Normal file
69
sources/awesomewidgets/awscriptformatter.h
Normal 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 AWSCRIPTFORMATTER_H
|
||||
#define AWSCRIPTFORMATTER_H
|
||||
|
||||
#include "awabstractformatter.h"
|
||||
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class AWScriptFormatter;
|
||||
}
|
||||
|
||||
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(QWidget *parent,
|
||||
const QString filePath = QString());
|
||||
virtual ~AWScriptFormatter();
|
||||
QString convert(const QVariant &_value) const;
|
||||
AWScriptFormatter *copy(const QString _fileName, const int _number);
|
||||
// properties
|
||||
bool appendCode() const;
|
||||
QString code() const;
|
||||
bool hasReturn() const;
|
||||
QString program() const;
|
||||
void setAppendCode(const bool _appendCode);
|
||||
void setCode(const QString _code);
|
||||
void setHasReturn(const bool _hasReturn);
|
||||
|
||||
public slots:
|
||||
void readConfiguration();
|
||||
int showConfiguration(const QVariant args = QVariant());
|
||||
void writeConfiguration() const;
|
||||
|
||||
private:
|
||||
Ui::AWScriptFormatter *ui = nullptr;
|
||||
void initProgram();
|
||||
void translate();
|
||||
// properties
|
||||
bool m_appendCode = true;
|
||||
QString m_code = QString();
|
||||
bool m_hasReturn = false;
|
||||
QString m_program;
|
||||
};
|
||||
|
||||
|
||||
#endif /* AWSCRIPTFORMATTER_H */
|
212
sources/awesomewidgets/awscriptformatter.ui
Normal file
212
sources/awesomewidgets/awscriptformatter.ui
Normal file
@ -0,0 +1,212 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>AWScriptFormatter</class>
|
||||
<widget class="QDialog" name="AWScriptFormatter">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>420</width>
|
||||
<height>315</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Configuration</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_name">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_name">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_name"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_comment">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_comment">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Comment</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_comment"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_type">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_type">
|
||||
<property name="text">
|
||||
<string>Type</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_typeValue">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_appendCode">
|
||||
<item>
|
||||
<spacer name="spacer_appendCode">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_appendCode">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Append code</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_hasReturn">
|
||||
<item>
|
||||
<spacer name="spacer_hasReturn">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_hasReturn">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Has return</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="layout_code">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_code">
|
||||
<property name="text">
|
||||
<string>Code</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTextEdit" name="textEdit_code"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>AWScriptFormatter</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>AWScriptFormatter</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
193
sources/awesomewidgets/awstringformatter.cpp
Normal file
193
sources/awesomewidgets/awstringformatter.cpp
Normal file
@ -0,0 +1,193 @@
|
||||
/***************************************************************************
|
||||
* This file is part of awesome-widgets *
|
||||
* *
|
||||
* awesome-widgets is free software: you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* awesome-widgets is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#include "awstringformatter.h"
|
||||
#include "ui_awstringformatter.h"
|
||||
|
||||
#include <KI18n/KLocalizedString>
|
||||
|
||||
#include <QDir>
|
||||
#include <QSettings>
|
||||
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
AWStringFormatter::AWStringFormatter(QWidget *parent, const QString filePath)
|
||||
: AWAbstractFormatter(parent, filePath)
|
||||
, ui(new Ui::AWStringFormatter)
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
if (!filePath.isEmpty())
|
||||
readConfiguration();
|
||||
ui->setupUi(this);
|
||||
translate();
|
||||
}
|
||||
|
||||
|
||||
AWStringFormatter::~AWStringFormatter()
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
||||
QString AWStringFormatter::convert(const QVariant &_value) const
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Convert value" << _value;
|
||||
|
||||
QString output = QString("%1").arg(_value.toString(), count(), fillChar());
|
||||
if (forceWidth())
|
||||
output = output.left(count());
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
AWStringFormatter *AWStringFormatter::copy(const QString _fileName,
|
||||
const int _number)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
||||
|
||||
AWStringFormatter *item
|
||||
= new AWStringFormatter(static_cast<QWidget *>(parent()), _fileName);
|
||||
AWAbstractFormatter::copyDefaults(item);
|
||||
item->setCount(count());
|
||||
item->setFillChar(fillChar());
|
||||
item->setForceWidth(forceWidth());
|
||||
item->setNumber(_number);
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
int AWStringFormatter::count() const
|
||||
{
|
||||
return m_count;
|
||||
}
|
||||
|
||||
|
||||
QChar AWStringFormatter::fillChar() const
|
||||
{
|
||||
return m_fillChar;
|
||||
}
|
||||
|
||||
|
||||
bool AWStringFormatter::forceWidth() const
|
||||
{
|
||||
return m_forceWidth;
|
||||
}
|
||||
|
||||
|
||||
void AWStringFormatter::setCount(const int _count)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Set width" << _count;
|
||||
|
||||
m_count = _count;
|
||||
}
|
||||
|
||||
|
||||
void AWStringFormatter::setFillChar(const QChar _fillChar)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Set char" << _fillChar;
|
||||
|
||||
m_fillChar = _fillChar;
|
||||
}
|
||||
|
||||
|
||||
void AWStringFormatter::setForceWidth(const bool _forceWidth)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Set force strip" << _forceWidth;
|
||||
|
||||
m_forceWidth = _forceWidth;
|
||||
}
|
||||
|
||||
|
||||
void AWStringFormatter::readConfiguration()
|
||||
{
|
||||
AWAbstractFormatter::readConfiguration();
|
||||
|
||||
QSettings settings(fileName(), QSettings::IniFormat);
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
setCount(settings.value(QString("X-AW-Width"), count()).toInt());
|
||||
setFillChar(
|
||||
settings.value(QString("X-AW-FillChar"), fillChar()).toString().at(0));
|
||||
setForceWidth(
|
||||
settings.value(QString("X-AW-ForceWidth"), forceWidth()).toBool());
|
||||
settings.endGroup();
|
||||
|
||||
bumpApi(AWEFAPI);
|
||||
}
|
||||
|
||||
|
||||
int AWStringFormatter::showConfiguration(const QVariant args)
|
||||
{
|
||||
Q_UNUSED(args)
|
||||
|
||||
ui->lineEdit_name->setText(name());
|
||||
ui->lineEdit_comment->setText(comment());
|
||||
ui->label_typeValue->setText(QString("String"));
|
||||
ui->spinBox_width->setValue(count());
|
||||
ui->lineEdit_fill->setText(QString(fillChar()));
|
||||
ui->checkBox_forceWidth->setCheckState(forceWidth() ? Qt::Checked
|
||||
: Qt::Unchecked);
|
||||
|
||||
int ret = exec();
|
||||
if (ret != 1)
|
||||
return ret;
|
||||
setName(ui->lineEdit_name->text());
|
||||
setComment(ui->lineEdit_comment->text());
|
||||
setApiVersion(AWEFAPI);
|
||||
setStrType(ui->label_typeValue->text());
|
||||
setCount(ui->spinBox_width->value());
|
||||
setFillChar(ui->lineEdit_fill->text().at(0));
|
||||
setForceWidth(ui->checkBox_forceWidth->checkState() == Qt::Checked);
|
||||
|
||||
writeConfiguration();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void AWStringFormatter::writeConfiguration() const
|
||||
{
|
||||
AWAbstractFormatter::writeConfiguration();
|
||||
|
||||
QSettings settings(writtableConfig(), QSettings::IniFormat);
|
||||
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
settings.setValue(QString("X-AW-Width"), count());
|
||||
settings.setValue(QString("X-AW-FillChar"), fillChar());
|
||||
settings.setValue(QString("X-AW-ForceWidth"), forceWidth());
|
||||
settings.endGroup();
|
||||
|
||||
settings.sync();
|
||||
}
|
||||
|
||||
|
||||
void AWStringFormatter::translate()
|
||||
{
|
||||
ui->label_name->setText(i18n("Name"));
|
||||
ui->label_comment->setText(i18n("Comment"));
|
||||
ui->label_type->setText(i18n("Type"));
|
||||
ui->label_width->setText(i18n("Width"));
|
||||
ui->label_fill->setText(i18n("Fill char"));
|
||||
ui->checkBox_forceWidth->setText(i18n("Force width"));
|
||||
}
|
65
sources/awesomewidgets/awstringformatter.h
Normal file
65
sources/awesomewidgets/awstringformatter.h
Normal file
@ -0,0 +1,65 @@
|
||||
/***************************************************************************
|
||||
* This file is part of awesome-widgets *
|
||||
* *
|
||||
* awesome-widgets is free software: you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* awesome-widgets is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef AWSTRINGFORMATTER_H
|
||||
#define AWSTRINGFORMATTER_H
|
||||
|
||||
#include "awabstractformatter.h"
|
||||
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class AWStringFormatter;
|
||||
}
|
||||
|
||||
class AWStringFormatter : public AWAbstractFormatter
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(int count READ count WRITE setCount)
|
||||
Q_PROPERTY(QChar fillChar READ fillChar WRITE setFillChar)
|
||||
Q_PROPERTY(bool forceWidth READ forceWidth WRITE setForceWidth)
|
||||
|
||||
public:
|
||||
explicit AWStringFormatter(QWidget *parent,
|
||||
const QString filePath = QString());
|
||||
virtual ~AWStringFormatter();
|
||||
QString convert(const QVariant &_value) const;
|
||||
AWStringFormatter *copy(const QString _fileName, const int _number);
|
||||
// properties
|
||||
int count() const;
|
||||
QChar fillChar() const;
|
||||
bool forceWidth() const;
|
||||
void setCount(const int _count);
|
||||
void setFillChar(const QChar _fillChar);
|
||||
void setForceWidth(const bool _forceWidth);
|
||||
|
||||
public slots:
|
||||
void readConfiguration();
|
||||
int showConfiguration(const QVariant args = QVariant());
|
||||
void writeConfiguration() const;
|
||||
|
||||
private:
|
||||
Ui::AWStringFormatter *ui = nullptr;
|
||||
void translate();
|
||||
// properties
|
||||
int m_count = 0;
|
||||
QChar m_fillChar = QChar();
|
||||
bool m_forceWidth = false;
|
||||
};
|
||||
|
||||
|
||||
#endif /* AWSTRINGFORMATTER_H */
|
225
sources/awesomewidgets/awstringformatter.ui
Normal file
225
sources/awesomewidgets/awstringformatter.ui
Normal file
@ -0,0 +1,225 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>AWStringFormatter</class>
|
||||
<widget class="QDialog" name="AWStringFormatter">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>420</width>
|
||||
<height>225</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Configuration</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_name">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_name">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_name"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_comment">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_comment">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Comment</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_comment"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_type">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_type">
|
||||
<property name="text">
|
||||
<string>Type</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_typeValue">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_width">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_width">
|
||||
<property name="text">
|
||||
<string>Width</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="spinBox_width">
|
||||
<property name="minimum">
|
||||
<number>-10000</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>10000</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_fill">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_fill">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Fill char</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_fill">
|
||||
<property name="maxLength">
|
||||
<number>1</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_forceWIdth">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_forceWidth">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Force width</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>AWStringFormatter</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>AWStringFormatter</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
134
sources/awesomewidgets/configs/aw-example-standalonerc
Normal file
134
sources/awesomewidgets/configs/aw-example-standalonerc
Normal 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: $mem $bar5<br>\nSwap: $swap $bar6<br>\nCPU: $cpu $bar7<br>\nCPU Temp: $temp0°C<br>\nDown: $down$downunits $downtotal<br>\n$bar8<br>\nUp: $up$upunits $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
|
||||
|
@ -6,11 +6,11 @@ X-AW-Value=bat
|
||||
X-AW-Custom=false
|
||||
X-AW-Max=100.0
|
||||
X-AW-Min=0.0
|
||||
X-AW-ActiveColor="0,0,0,255"
|
||||
X-AW-InactiveColor="255,255,255,255"
|
||||
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=4
|
||||
X-AW-ApiVersion=5
|
||||
X-AW-Number=3
|
||||
|
@ -6,11 +6,11 @@ X-AW-Value=cpu
|
||||
X-AW-Custom=false
|
||||
X-AW-Max=100.0
|
||||
X-AW-Min=0.0
|
||||
X-AW-ActiveColor="0,0,0,255"
|
||||
X-AW-InactiveColor="255,255,255,255"
|
||||
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=4
|
||||
X-AW-ApiVersion=5
|
||||
X-AW-Number=0
|
||||
|
@ -6,11 +6,11 @@ X-AW-Value=mem
|
||||
X-AW-Custom=false
|
||||
X-AW-Max=100.0
|
||||
X-AW-Min=0.0
|
||||
X-AW-ActiveColor="0,0,0,255"
|
||||
X-AW-InactiveColor="255,255,255,255"
|
||||
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=4
|
||||
X-AW-ApiVersion=5
|
||||
X-AW-Number=1
|
||||
|
@ -6,11 +6,11 @@ X-AW-Value=swap
|
||||
X-AW-Custom=false
|
||||
X-AW-Max=100.0
|
||||
X-AW-Min=0.0
|
||||
X-AW-ActiveColor="0,0,0,255"
|
||||
X-AW-InactiveColor="255,255,255,255"
|
||||
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=4
|
||||
X-AW-ApiVersion=5
|
||||
X-AW-Number=2
|
||||
|
@ -32,8 +32,7 @@ template <class T> class ExtItemAggregator : public AbstractExtItemAggregator
|
||||
{
|
||||
public:
|
||||
explicit ExtItemAggregator(QWidget *parent, const QString type)
|
||||
: AbstractExtItemAggregator(parent)
|
||||
, m_type(type)
|
||||
: AbstractExtItemAggregator(parent, type)
|
||||
{
|
||||
qSetMessagePattern(LOG_FORMAT);
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
@ -57,8 +56,8 @@ public:
|
||||
|
||||
void editItems()
|
||||
{
|
||||
repaint();
|
||||
int ret = dialog->exec();
|
||||
repaintList();
|
||||
int ret = exec();
|
||||
qCInfo(LOG_LIB) << "Dialog returns" << ret;
|
||||
};
|
||||
|
||||
@ -70,7 +69,7 @@ public:
|
||||
for (auto item : m_items) {
|
||||
if (item->tag(_type) != _tag)
|
||||
continue;
|
||||
found = item;
|
||||
found = static_cast<T *>(item);
|
||||
break;
|
||||
}
|
||||
if (found == nullptr)
|
||||
@ -87,7 +86,7 @@ public:
|
||||
for (auto item : m_items) {
|
||||
if (item->number() != _number)
|
||||
continue;
|
||||
found = item;
|
||||
found = static_cast<T *>(item);
|
||||
break;
|
||||
}
|
||||
if (found == nullptr)
|
||||
@ -96,63 +95,31 @@ public:
|
||||
return found;
|
||||
};
|
||||
|
||||
T *itemFromWidget() const
|
||||
{
|
||||
QListWidgetItem *widgetItem = widgetDialog->currentItem();
|
||||
if (widgetItem == nullptr)
|
||||
return nullptr;
|
||||
|
||||
T *found = nullptr;
|
||||
for (auto item : m_items) {
|
||||
if (item->fileName() != widgetItem->text())
|
||||
continue;
|
||||
found = item;
|
||||
break;
|
||||
}
|
||||
if (found == nullptr)
|
||||
qCWarning(LOG_LIB) << "Could not find item by name"
|
||||
<< widgetItem->text();
|
||||
|
||||
return found;
|
||||
};
|
||||
|
||||
QList<T *> items() const { return m_items; };
|
||||
|
||||
int uniqNumber() const
|
||||
{
|
||||
QList<int> tagList;
|
||||
for (auto item : m_items)
|
||||
tagList.append(item->number());
|
||||
int number = 0;
|
||||
while (tagList.contains(number))
|
||||
number++;
|
||||
|
||||
return number;
|
||||
};
|
||||
QList<AbstractExtItem *> items() const { return m_items; };
|
||||
|
||||
private:
|
||||
QList<T *> m_items;
|
||||
QList<AbstractExtItem *> m_items;
|
||||
QList<T *> m_activeItems;
|
||||
QString m_type;
|
||||
|
||||
// init method
|
||||
QList<T *> getItems()
|
||||
void doCreateItem() { return createItem<T>(); }
|
||||
|
||||
QList<AbstractExtItem *> getItems()
|
||||
{
|
||||
// create directory at $HOME
|
||||
QString localDir = QString("%1/awesomewidgets/%2")
|
||||
.arg(QStandardPaths::writableLocation(
|
||||
QStandardPaths::GenericDataLocation))
|
||||
.arg(m_type);
|
||||
.arg(type());
|
||||
QDir localDirectory;
|
||||
if (localDirectory.mkpath(localDir))
|
||||
qCInfo(LOG_LIB) << "Created directory" << localDir;
|
||||
|
||||
QStringList dirs = QStandardPaths::locateAll(
|
||||
QStandardPaths::GenericDataLocation,
|
||||
QString("awesomewidgets/%1").arg(m_type),
|
||||
QString("awesomewidgets/%1").arg(type()),
|
||||
QStandardPaths::LocateDirectory);
|
||||
QStringList names;
|
||||
QList<T *> items;
|
||||
QList<AbstractExtItem *> items;
|
||||
for (auto dir : dirs) {
|
||||
QStringList files = QDir(dir).entryList(QDir::Files, QDir::Name);
|
||||
for (auto file : files) {
|
||||
@ -161,14 +128,16 @@ private:
|
||||
continue;
|
||||
qCInfo(LOG_LIB) << "Found file" << file << "in" << dir;
|
||||
names.append(file);
|
||||
items.append(new T(this, file, dirs));
|
||||
QString filePath = QString("%1/%2").arg(dir).arg(file);
|
||||
items.append(new T(this, filePath));
|
||||
}
|
||||
}
|
||||
|
||||
// sort items
|
||||
std::sort(items.begin(), items.end(), [](const T *lhs, const T *rhs) {
|
||||
return lhs->number() < rhs->number();
|
||||
});
|
||||
std::sort(items.begin(), items.end(),
|
||||
[](const AbstractExtItem *lhs, const AbstractExtItem *rhs) {
|
||||
return lhs->number() < rhs->number();
|
||||
});
|
||||
return items;
|
||||
};
|
||||
|
||||
@ -181,89 +150,7 @@ private:
|
||||
for (auto item : m_items) {
|
||||
if (!item->isActive())
|
||||
continue;
|
||||
m_activeItems.append(item);
|
||||
}
|
||||
};
|
||||
|
||||
void repaint()
|
||||
{
|
||||
widgetDialog->clear();
|
||||
for (auto _item : m_items) {
|
||||
QListWidgetItem *item
|
||||
= new QListWidgetItem(_item->fileName(), widgetDialog);
|
||||
QStringList tooltip;
|
||||
tooltip.append(i18n("Name: %1", _item->name()));
|
||||
tooltip.append(i18n("Comment: %1", _item->comment()));
|
||||
tooltip.append(i18n("Identity: %1", _item->uniq()));
|
||||
item->setToolTip(tooltip.join(QChar('\n')));
|
||||
widgetDialog->addItem(item);
|
||||
}
|
||||
};
|
||||
|
||||
// methods
|
||||
void copyItem()
|
||||
{
|
||||
T *source = itemFromWidget();
|
||||
QString fileName = getName();
|
||||
int number = uniqNumber();
|
||||
if ((source == nullptr) || (fileName.isEmpty())) {
|
||||
qCWarning(LOG_LIB) << "Nothing to copy";
|
||||
return;
|
||||
}
|
||||
|
||||
T *newItem = static_cast<T *>(source->copy(fileName, number));
|
||||
if (newItem->showConfiguration(configArgs()) == 1) {
|
||||
initItems();
|
||||
repaint();
|
||||
}
|
||||
};
|
||||
|
||||
void createItem()
|
||||
{
|
||||
QString fileName = getName();
|
||||
int number = uniqNumber();
|
||||
QStringList dirs = QStandardPaths::locateAll(
|
||||
QStandardPaths::GenericDataLocation,
|
||||
QString("awesomewidgets/%1").arg(m_type),
|
||||
QStandardPaths::LocateDirectory);
|
||||
if (fileName.isEmpty()) {
|
||||
qCWarning(LOG_LIB) << "Nothing to create";
|
||||
return;
|
||||
};
|
||||
|
||||
T *newItem = new T(this, fileName, dirs);
|
||||
newItem->setNumber(number);
|
||||
if (newItem->showConfiguration(configArgs()) == 1) {
|
||||
initItems();
|
||||
repaint();
|
||||
}
|
||||
};
|
||||
|
||||
void deleteItem()
|
||||
{
|
||||
T *source = itemFromWidget();
|
||||
if (source == nullptr) {
|
||||
qCWarning(LOG_LIB) << "Nothing to delete";
|
||||
return;
|
||||
};
|
||||
|
||||
if (source->tryDelete()) {
|
||||
initItems();
|
||||
repaint();
|
||||
}
|
||||
};
|
||||
|
||||
void editItem()
|
||||
{
|
||||
T *source = itemFromWidget();
|
||||
if (source == nullptr) {
|
||||
qCWarning(LOG_LIB) << "Nothing to edit";
|
||||
return;
|
||||
};
|
||||
|
||||
if (source->showConfiguration(configArgs()) == 1) {
|
||||
initItems();
|
||||
repaint();
|
||||
m_activeItems.append(static_cast<T *>(item));
|
||||
}
|
||||
};
|
||||
};
|
||||
|
@ -26,38 +26,38 @@
|
||||
#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,
|
||||
const QStringList directories)
|
||||
: AbstractExtItem(parent, quotesName, directories)
|
||||
ExtQuotes::ExtQuotes(QWidget *parent, const QString filePath)
|
||||
: AbstractExtItem(parent, filePath)
|
||||
, ui(new Ui::ExtQuotes)
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
readConfiguration();
|
||||
if (!filePath.isEmpty())
|
||||
readConfiguration();
|
||||
ui->setupUi(this);
|
||||
translate();
|
||||
|
||||
values[tag(QString("ask"))] = 0.0;
|
||||
values[tag(QString("askchg"))] = 0.0;
|
||||
values[tag(QString("percaskchg"))] = 0.0;
|
||||
values[tag(QString("bid"))] = 0.0;
|
||||
values[tag(QString("bidchg"))] = 0.0;
|
||||
values[tag(QString("percbidchg"))] = 0.0;
|
||||
values[tag(QString("price"))] = 0.0;
|
||||
values[tag(QString("pricechg"))] = 0.0;
|
||||
values[tag(QString("percpricechg"))] = 0.0;
|
||||
m_values[tag(QString("ask"))] = 0.0;
|
||||
m_values[tag(QString("askchg"))] = 0.0;
|
||||
m_values[tag(QString("percaskchg"))] = 0.0;
|
||||
m_values[tag(QString("bid"))] = 0.0;
|
||||
m_values[tag(QString("bidchg"))] = 0.0;
|
||||
m_values[tag(QString("percbidchg"))] = 0.0;
|
||||
m_values[tag(QString("price"))] = 0.0;
|
||||
m_values[tag(QString("pricechg"))] = 0.0;
|
||||
m_values[tag(QString("percpricechg"))] = 0.0;
|
||||
|
||||
// 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,21 +66,20 @@ 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;
|
||||
}
|
||||
|
||||
|
||||
ExtQuotes *ExtQuotes::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;
|
||||
|
||||
ExtQuotes *item = new ExtQuotes(static_cast<QWidget *>(parent()), _fileName,
|
||||
directories());
|
||||
ExtQuotes *item
|
||||
= new ExtQuotes(static_cast<QWidget *>(parent()), _fileName);
|
||||
copyDefaults(item);
|
||||
item->setNumber(_number);
|
||||
item->setTicker(ticker());
|
||||
@ -97,7 +96,7 @@ QString ExtQuotes::ticker() const
|
||||
|
||||
QString ExtQuotes::uniq() const
|
||||
{
|
||||
return m_ticker;
|
||||
return ticker();
|
||||
}
|
||||
|
||||
|
||||
@ -106,6 +105,7 @@ void ExtQuotes::setTicker(const QString _ticker)
|
||||
qCDebug(LOG_LIB) << "Ticker" << _ticker;
|
||||
|
||||
m_ticker = _ticker;
|
||||
initUrl();
|
||||
}
|
||||
|
||||
|
||||
@ -113,48 +113,34 @@ void ExtQuotes::readConfiguration()
|
||||
{
|
||||
AbstractExtItem::readConfiguration();
|
||||
|
||||
for (int i = directories().count() - 1; i >= 0; i--) {
|
||||
if (!QDir(directories().at(i))
|
||||
.entryList(QDir::Files)
|
||||
.contains(fileName()))
|
||||
continue;
|
||||
QSettings settings(
|
||||
QString("%1/%2").arg(directories().at(i)).arg(fileName()),
|
||||
QSettings::IniFormat);
|
||||
QSettings settings(fileName(), QSettings::IniFormat);
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
setTicker(settings.value(QString("X-AW-Ticker"), m_ticker).toString());
|
||||
settings.endGroup();
|
||||
}
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
setTicker(settings.value(QString("X-AW-Ticker"), ticker()).toString());
|
||||
settings.endGroup();
|
||||
|
||||
// update for current API
|
||||
if ((apiVersion() > 0) && (apiVersion() < AWEQAPI)) {
|
||||
qCWarning(LOG_LIB) << "Bump API version from" << apiVersion() << "to"
|
||||
<< AWEQAPI;
|
||||
setApiVersion(AWEQAPI);
|
||||
writeConfiguration();
|
||||
}
|
||||
bumpApi(AWEQAPI);
|
||||
}
|
||||
|
||||
|
||||
QVariantHash ExtQuotes::run()
|
||||
{
|
||||
if ((!isActive()) || (isRunning))
|
||||
return values;
|
||||
if ((!isActive()) || (m_isRunning))
|
||||
return m_values;
|
||||
|
||||
if (times == 1) {
|
||||
if (m_times == 1) {
|
||||
qCInfo(LOG_LIB) << "Send request";
|
||||
isRunning = true;
|
||||
QNetworkReply *reply = manager->get(QNetworkRequest(QUrl(url())));
|
||||
m_isRunning = true;
|
||||
QNetworkReply *reply = m_manager->get(QNetworkRequest(m_url));
|
||||
new QReplyTimeout(reply, REQUEST_TIMEOUT);
|
||||
}
|
||||
|
||||
// update value
|
||||
if (times >= interval())
|
||||
times = 0;
|
||||
times++;
|
||||
if (m_times >= interval())
|
||||
m_times = 0;
|
||||
m_times++;
|
||||
|
||||
return values;
|
||||
return m_values;
|
||||
}
|
||||
|
||||
|
||||
@ -165,7 +151,7 @@ int ExtQuotes::showConfiguration(const QVariant args)
|
||||
ui->lineEdit_name->setText(name());
|
||||
ui->lineEdit_comment->setText(comment());
|
||||
ui->label_numberValue->setText(QString("%1").arg(number()));
|
||||
ui->lineEdit_ticker->setText(m_ticker);
|
||||
ui->lineEdit_ticker->setText(ticker());
|
||||
ui->checkBox_active->setCheckState(isActive() ? Qt::Checked
|
||||
: Qt::Unchecked);
|
||||
ui->spinBox_interval->setValue(interval());
|
||||
@ -190,13 +176,11 @@ void ExtQuotes::writeConfiguration() const
|
||||
{
|
||||
AbstractExtItem::writeConfiguration();
|
||||
|
||||
QSettings settings(
|
||||
QString("%1/%2").arg(directories().first()).arg(fileName()),
|
||||
QSettings::IniFormat);
|
||||
QSettings settings(writtableConfig(), QSettings::IniFormat);
|
||||
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
settings.setValue(QString("X-AW-Ticker"), m_ticker);
|
||||
settings.setValue(QString("X-AW-Ticker"), ticker());
|
||||
settings.endGroup();
|
||||
|
||||
settings.sync();
|
||||
@ -207,7 +191,7 @@ void ExtQuotes::quotesReplyReceived(QNetworkReply *reply)
|
||||
qCDebug(LOG_LIB) << "Return code" << reply->error() << "with message"
|
||||
<< reply->errorString();
|
||||
|
||||
isRunning = false;
|
||||
m_isRunning = false;
|
||||
QJsonParseError error;
|
||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(reply->readAll(), &error);
|
||||
reply->deleteLater();
|
||||
@ -224,36 +208,52 @@ void ExtQuotes::quotesReplyReceived(QNetworkReply *reply)
|
||||
|
||||
// ask
|
||||
value = jsonQuotes[QString("Ask")].toString().toDouble();
|
||||
values[tag(QString("askchg"))]
|
||||
= values[QString("ask")].toDouble() == 0.0
|
||||
m_values[tag(QString("askchg"))]
|
||||
= m_values[tag(QString("ask"))].toDouble() == 0.0
|
||||
? 0.0
|
||||
: value - values[QString("ask")].toDouble();
|
||||
values[tag(QString("percaskchg"))] = 100.0
|
||||
* values[QString("askchg")].toDouble()
|
||||
/ values[QString("ask")].toDouble();
|
||||
values[tag(QString("ask"))] = value;
|
||||
: value - m_values[tag(QString("ask"))].toDouble();
|
||||
m_values[tag(QString("percaskchg"))]
|
||||
= 100.0 * m_values[tag(QString("askchg"))].toDouble()
|
||||
/ m_values[tag(QString("ask"))].toDouble();
|
||||
m_values[tag(QString("ask"))] = value;
|
||||
|
||||
// bid
|
||||
value = jsonQuotes[QString("Bid")].toString().toDouble();
|
||||
values[tag(QString("bidchg"))]
|
||||
= values[QString("bid")].toDouble() == 0.0
|
||||
m_values[tag(QString("bidchg"))]
|
||||
= m_values[tag(QString("bid"))].toDouble() == 0.0
|
||||
? 0.0
|
||||
: value - values[QString("bid")].toDouble();
|
||||
values[tag(QString("percbidchg"))] = 100.0
|
||||
* values[QString("bidchg")].toDouble()
|
||||
/ values[QString("bid")].toDouble();
|
||||
values[tag(QString("bid"))] = value;
|
||||
: value - m_values[tag(QString("bid"))].toDouble();
|
||||
m_values[tag(QString("percbidchg"))]
|
||||
= 100.0 * m_values[tag(QString("bidchg"))].toDouble()
|
||||
/ m_values[tag(QString("bid"))].toDouble();
|
||||
m_values[tag(QString("bid"))] = value;
|
||||
|
||||
// last trade
|
||||
value = jsonQuotes[QString("LastTradePriceOnly")].toString().toDouble();
|
||||
values[tag(QString("pricechg"))]
|
||||
= values[QString("price")].toDouble() == 0.0
|
||||
m_values[tag(QString("pricechg"))]
|
||||
= m_values[tag(QString("price"))].toDouble() == 0.0
|
||||
? 0.0
|
||||
: value - values[QString("price")].toDouble();
|
||||
values[tag(QString("percpricechg"))]
|
||||
= 100.0 * values[QString("pricechg")].toDouble()
|
||||
/ values[QString("price")].toDouble();
|
||||
values[tag(QString("price"))] = value;
|
||||
: value - m_values[tag(QString("price"))].toDouble();
|
||||
m_values[tag(QString("percpricechg"))]
|
||||
= 100.0 * m_values[tag(QString("pricechg"))].toDouble()
|
||||
/ m_values[tag(QString("price"))].toDouble();
|
||||
m_values[tag(QString("price"))] = value;
|
||||
|
||||
emit(dataReceived(m_values));
|
||||
}
|
||||
|
||||
|
||||
void ExtQuotes::initUrl()
|
||||
{
|
||||
// init query
|
||||
m_url = QUrl(YAHOO_QUOTES_URL);
|
||||
QUrlQuery params;
|
||||
params.addQueryItem(QString("format"), QString("json"));
|
||||
params.addQueryItem(QString("env"),
|
||||
QString("store://datatables.org/alltableswithkeys"));
|
||||
params.addQueryItem(QString("q"),
|
||||
QString(YAHOO_QUOTES_QUERY).arg(ticker()));
|
||||
m_url.setQuery(params);
|
||||
}
|
||||
|
||||
|
||||
@ -271,12 +271,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_QUOTES_URL).arg(m_ticker);
|
||||
qCInfo(LOG_LIB) << "API url" << apiUrl;
|
||||
|
||||
return apiUrl;
|
||||
}
|
||||
|
@ -22,11 +22,9 @@
|
||||
|
||||
#include "abstractextitem.h"
|
||||
|
||||
#define YAHOO_QUOTES_URL \
|
||||
"https://query.yahooapis.com/v1/public/yql?q=select * from " \
|
||||
"yahoo.finance.quotes where " \
|
||||
"symbol=\"%1\"&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
|
||||
@ -40,9 +38,7 @@ class ExtQuotes : public AbstractExtItem
|
||||
Q_PROPERTY(QString ticker READ ticker WRITE setTicker)
|
||||
|
||||
public:
|
||||
explicit ExtQuotes(QWidget *parent = nullptr,
|
||||
const QString quotesName = QString(),
|
||||
const QStringList directories = QStringList());
|
||||
explicit ExtQuotes(QWidget *parent, const QString filePath = QString());
|
||||
virtual ~ExtQuotes();
|
||||
ExtQuotes *copy(const QString _fileName, const int _number);
|
||||
// get methods
|
||||
@ -61,16 +57,17 @@ private slots:
|
||||
void quotesReplyReceived(QNetworkReply *reply);
|
||||
|
||||
private:
|
||||
QNetworkAccessManager *manager;
|
||||
bool isRunning = false;
|
||||
Ui::ExtQuotes *ui;
|
||||
QNetworkAccessManager *m_manager = nullptr;
|
||||
QUrl m_url;
|
||||
bool m_isRunning = false;
|
||||
Ui::ExtQuotes *ui = nullptr;
|
||||
void initUrl();
|
||||
void translate();
|
||||
QString url() const;
|
||||
// properties
|
||||
QString m_ticker = QString("EURUSD=X");
|
||||
// values
|
||||
int times = 0;
|
||||
QVariantHash values;
|
||||
int m_times = 0;
|
||||
QVariantHash m_values;
|
||||
};
|
||||
|
||||
|
||||
|
@ -28,27 +28,26 @@
|
||||
#include <QTextCodec>
|
||||
|
||||
#include "awdebug.h"
|
||||
#include "version.h"
|
||||
|
||||
|
||||
ExtScript::ExtScript(QWidget *parent, const QString scriptName,
|
||||
const QStringList directories)
|
||||
: AbstractExtItem(parent, scriptName, directories)
|
||||
ExtScript::ExtScript(QWidget *parent, const QString filePath)
|
||||
: AbstractExtItem(parent, filePath)
|
||||
, ui(new Ui::ExtScript)
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
readConfiguration();
|
||||
if (!filePath.isEmpty())
|
||||
readConfiguration();
|
||||
readJsonFilters();
|
||||
ui->setupUi(this);
|
||||
translate();
|
||||
|
||||
value[tag(QString("custom"))] = QString("");
|
||||
m_values[tag(QString("custom"))] = QString("");
|
||||
|
||||
process = new QProcess(nullptr);
|
||||
connect(process, SIGNAL(finished(int, QProcess::ExitStatus)), this,
|
||||
m_process = new QProcess(nullptr);
|
||||
connect(m_process, SIGNAL(finished(int, QProcess::ExitStatus)), this,
|
||||
SLOT(updateValue()));
|
||||
process->waitForFinished(0);
|
||||
m_process->waitForFinished(0);
|
||||
}
|
||||
|
||||
|
||||
@ -56,8 +55,8 @@ ExtScript::~ExtScript()
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
process->kill();
|
||||
process->deleteLater();
|
||||
m_process->kill();
|
||||
m_process->deleteLater();
|
||||
delete ui;
|
||||
}
|
||||
|
||||
@ -66,13 +65,14 @@ ExtScript *ExtScript::copy(const QString _fileName, const int _number)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
||||
|
||||
ExtScript *item = new ExtScript(static_cast<QWidget *>(parent()), _fileName,
|
||||
directories());
|
||||
ExtScript *item
|
||||
= new ExtScript(static_cast<QWidget *>(parent()), _fileName);
|
||||
copyDefaults(item);
|
||||
item->setExecutable(executable());
|
||||
item->setNumber(_number);
|
||||
item->setPrefix(prefix());
|
||||
item->setRedirect(redirect());
|
||||
item->setFilters(filters());
|
||||
|
||||
return item;
|
||||
}
|
||||
@ -104,25 +104,24 @@ ExtScript::Redirect ExtScript::redirect() const
|
||||
|
||||
QString ExtScript::uniq() const
|
||||
{
|
||||
return m_executable;
|
||||
return executable();
|
||||
}
|
||||
|
||||
|
||||
QString ExtScript::strRedirect() const
|
||||
{
|
||||
QString value;
|
||||
switch (m_redirect) {
|
||||
case stdout2stderr:
|
||||
switch (redirect()) {
|
||||
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;
|
||||
}
|
||||
@ -158,7 +157,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;
|
||||
}
|
||||
@ -169,13 +168,13 @@ void ExtScript::setStrRedirect(const QString _redirect)
|
||||
qCDebug(LOG_LIB) << "Redirect" << _redirect;
|
||||
|
||||
if (_redirect == QString("stdout2sdterr"))
|
||||
m_redirect = stdout2stderr;
|
||||
setRedirect(Redirect::stdout2stderr);
|
||||
else if (_redirect == QString("stderr2sdtout"))
|
||||
m_redirect = stderr2stdout;
|
||||
setRedirect(Redirect::stderr2stdout);
|
||||
else if (_redirect == QString("swap"))
|
||||
m_redirect = swap;
|
||||
setRedirect(Redirect::swap);
|
||||
else
|
||||
m_redirect = nothing;
|
||||
setRedirect(Redirect::nothing);
|
||||
}
|
||||
|
||||
|
||||
@ -183,9 +182,9 @@ QString ExtScript::applyFilters(QString _value) const
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Value" << _value;
|
||||
|
||||
for (auto filt : m_filters) {
|
||||
for (auto filt : filters()) {
|
||||
qCInfo(LOG_LIB) << "Found filter" << filt;
|
||||
QVariantMap filter = jsonFilters[filt].toMap();
|
||||
QVariantMap filter = m_jsonFilters[filt].toMap();
|
||||
if (filter.isEmpty()) {
|
||||
qCWarning(LOG_LIB) << "Could not find filter" << _value
|
||||
<< "in the json";
|
||||
@ -204,7 +203,7 @@ void ExtScript::updateFilter(const QString _filter, const bool _add)
|
||||
qCDebug(LOG_LIB) << "Should be added filters" << _add << "from" << _filter;
|
||||
|
||||
if (_add) {
|
||||
if (m_filters.contains(_filter))
|
||||
if (filters().contains(_filter))
|
||||
return;
|
||||
m_filters.append(_filter);
|
||||
} else {
|
||||
@ -217,34 +216,20 @@ void ExtScript::readConfiguration()
|
||||
{
|
||||
AbstractExtItem::readConfiguration();
|
||||
|
||||
for (int i = directories().count() - 1; i >= 0; i--) {
|
||||
if (!QDir(directories().at(i))
|
||||
.entryList(QDir::Files)
|
||||
.contains(fileName()))
|
||||
continue;
|
||||
QSettings settings(
|
||||
QString("%1/%2").arg(directories().at(i)).arg(fileName()),
|
||||
QSettings::IniFormat);
|
||||
QSettings settings(fileName(), QSettings::IniFormat);
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
setExecutable(settings.value(QString("Exec"), m_executable).toString());
|
||||
setPrefix(settings.value(QString("X-AW-Prefix"), m_prefix).toString());
|
||||
setStrRedirect(
|
||||
settings.value(QString("X-AW-Redirect"), strRedirect()).toString());
|
||||
// api == 3
|
||||
setFilters(settings.value(QString("X-AW-Filters"), m_filters)
|
||||
.toString()
|
||||
.split(QChar(','), QString::SkipEmptyParts));
|
||||
settings.endGroup();
|
||||
}
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
setExecutable(settings.value(QString("Exec"), executable()).toString());
|
||||
setPrefix(settings.value(QString("X-AW-Prefix"), prefix()).toString());
|
||||
setStrRedirect(
|
||||
settings.value(QString("X-AW-Redirect"), strRedirect()).toString());
|
||||
// api == 3
|
||||
setFilters(settings.value(QString("X-AW-Filters"), filters())
|
||||
.toString()
|
||||
.split(QChar(','), QString::SkipEmptyParts));
|
||||
settings.endGroup();
|
||||
|
||||
// update for current API
|
||||
if ((apiVersion() > 0) && (apiVersion() < AWESAPI)) {
|
||||
qCWarning(LOG_LIB) << "Bump API version from" << apiVersion() << "to"
|
||||
<< AWESAPI;
|
||||
setApiVersion(AWESAPI);
|
||||
writeConfiguration();
|
||||
}
|
||||
bumpApi(AWESAPI);
|
||||
}
|
||||
|
||||
|
||||
@ -269,30 +254,35 @@ void ExtScript::readJsonFilters()
|
||||
qCWarning(LOG_LIB) << "Parse error" << error.errorString();
|
||||
return;
|
||||
}
|
||||
jsonFilters = jsonDoc.toVariant().toMap();
|
||||
m_jsonFilters = jsonDoc.toVariant().toMap();
|
||||
|
||||
qCInfo(LOG_LIB) << "Filters" << jsonFilters;
|
||||
qCInfo(LOG_LIB) << "Filters" << m_jsonFilters;
|
||||
}
|
||||
|
||||
|
||||
QVariantHash ExtScript::run()
|
||||
{
|
||||
if (!isActive())
|
||||
return value;
|
||||
return m_values;
|
||||
if (m_process->state() != QProcess::NotRunning)
|
||||
qCWarning(LOG_LIB) << "Another process is already running"
|
||||
<< m_process->state();
|
||||
|
||||
if ((times == 1) && (process->state() == QProcess::NotRunning)) {
|
||||
if ((m_times == 1) && (m_process->state() == QProcess::NotRunning)) {
|
||||
QStringList cmdList;
|
||||
if (!m_prefix.isEmpty())
|
||||
cmdList.append(m_prefix);
|
||||
cmdList.append(m_executable);
|
||||
if (!prefix().isEmpty())
|
||||
cmdList.append(prefix());
|
||||
cmdList.append(executable());
|
||||
qCInfo(LOG_LIB) << "Run cmd" << cmdList.join(QChar(' '));
|
||||
process->start(cmdList.join(QChar(' ')));
|
||||
} else if (times >= interval()) {
|
||||
times = 0;
|
||||
m_process->start(cmdList.join(QChar(' ')));
|
||||
}
|
||||
times++;
|
||||
|
||||
return value;
|
||||
// update value
|
||||
if (m_times >= interval())
|
||||
m_times = 0;
|
||||
m_times++;
|
||||
|
||||
return m_values;
|
||||
}
|
||||
|
||||
|
||||
@ -303,19 +293,19 @@ int ExtScript::showConfiguration(const QVariant args)
|
||||
ui->lineEdit_name->setText(name());
|
||||
ui->lineEdit_comment->setText(comment());
|
||||
ui->label_numberValue->setText(QString("%1").arg(number()));
|
||||
ui->lineEdit_command->setText(m_executable);
|
||||
ui->lineEdit_prefix->setText(m_prefix);
|
||||
ui->lineEdit_command->setText(executable());
|
||||
ui->lineEdit_prefix->setText(prefix());
|
||||
ui->checkBox_active->setCheckState(isActive() ? Qt::Checked
|
||||
: Qt::Unchecked);
|
||||
ui->comboBox_redirect->setCurrentIndex(static_cast<int>(m_redirect));
|
||||
ui->comboBox_redirect->setCurrentIndex(static_cast<int>(redirect()));
|
||||
ui->spinBox_interval->setValue(interval());
|
||||
// filters
|
||||
ui->checkBox_colorFilter->setCheckState(
|
||||
m_filters.contains(QString("color")) ? Qt::Checked : Qt::Unchecked);
|
||||
filters().contains(QString("color")) ? Qt::Checked : Qt::Unchecked);
|
||||
ui->checkBox_linesFilter->setCheckState(
|
||||
m_filters.contains(QString("newline")) ? Qt::Checked : Qt::Unchecked);
|
||||
filters().contains(QString("newline")) ? Qt::Checked : Qt::Unchecked);
|
||||
ui->checkBox_spaceFilter->setCheckState(
|
||||
m_filters.contains(QString("space")) ? Qt::Checked : Qt::Unchecked);
|
||||
filters().contains(QString("space")) ? Qt::Checked : Qt::Unchecked);
|
||||
|
||||
int ret = exec();
|
||||
if (ret != 1)
|
||||
@ -327,7 +317,7 @@ int ExtScript::showConfiguration(const QVariant args)
|
||||
setExecutable(ui->lineEdit_command->text());
|
||||
setPrefix(ui->lineEdit_prefix->text());
|
||||
setActive(ui->checkBox_active->checkState() == Qt::Checked);
|
||||
setStrRedirect(ui->comboBox_redirect->currentText());
|
||||
setRedirect(static_cast<Redirect>(ui->comboBox_redirect->currentIndex()));
|
||||
setInterval(ui->spinBox_interval->value());
|
||||
// filters
|
||||
updateFilter(QString("color"),
|
||||
@ -346,16 +336,14 @@ void ExtScript::writeConfiguration() const
|
||||
{
|
||||
AbstractExtItem::writeConfiguration();
|
||||
|
||||
QSettings settings(
|
||||
QString("%1/%2").arg(directories().first()).arg(fileName()),
|
||||
QSettings::IniFormat);
|
||||
QSettings settings(writtableConfig(), QSettings::IniFormat);
|
||||
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
settings.setValue(QString("Exec"), m_executable);
|
||||
settings.setValue(QString("X-AW-Prefix"), m_prefix);
|
||||
settings.setValue(QString("Exec"), executable());
|
||||
settings.setValue(QString("X-AW-Prefix"), prefix());
|
||||
settings.setValue(QString("X-AW-Redirect"), strRedirect());
|
||||
settings.setValue(QString("X-AW-Filters"), m_filters.join(QChar(',')));
|
||||
settings.setValue(QString("X-AW-Filters"), filters().join(QChar(',')));
|
||||
settings.endGroup();
|
||||
|
||||
settings.sync();
|
||||
@ -364,34 +352,34 @@ void ExtScript::writeConfiguration() const
|
||||
|
||||
void ExtScript::updateValue()
|
||||
{
|
||||
qCInfo(LOG_LIB) << "Cmd returns" << process->exitCode();
|
||||
qCInfo(LOG_LIB) << "Cmd returns" << m_process->exitCode();
|
||||
QString qdebug = QTextCodec::codecForMib(106)
|
||||
->toUnicode(process->readAllStandardError())
|
||||
->toUnicode(m_process->readAllStandardError())
|
||||
.trimmed();
|
||||
qCInfo(LOG_LIB) << "Error" << qdebug;
|
||||
QString qoutput = QTextCodec::codecForMib(106)
|
||||
->toUnicode(process->readAllStandardOutput())
|
||||
->toUnicode(m_process->readAllStandardOutput())
|
||||
.trimmed();
|
||||
qCInfo(LOG_LIB) << "Output" << qoutput;
|
||||
QString strValue;
|
||||
|
||||
switch (m_redirect) {
|
||||
case stdout2stderr:
|
||||
switch (redirect()) {
|
||||
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;
|
||||
}
|
||||
|
||||
// filters
|
||||
value[tag(QString("custom"))] = applyFilters(strValue);
|
||||
m_values[tag(QString("custom"))] = applyFilters(strValue);
|
||||
emit(dataReceived(m_values));
|
||||
}
|
||||
|
||||
|
||||
|
@ -37,11 +37,14 @@ class ExtScript : public AbstractExtItem
|
||||
Q_PROPERTY(Redirect redirect READ redirect WRITE setRedirect)
|
||||
|
||||
public:
|
||||
enum Redirect { stdout2stderr = 0, nothing, stderr2stdout, swap };
|
||||
enum class Redirect {
|
||||
stdout2stderr = 0,
|
||||
nothing = 1,
|
||||
stderr2stdout = 2,
|
||||
swap = 3
|
||||
};
|
||||
|
||||
explicit ExtScript(QWidget *parent = nullptr,
|
||||
const QString scriptName = QString(),
|
||||
const QStringList directories = QStringList());
|
||||
explicit ExtScript(QWidget *parent, const QString filePath = QString());
|
||||
virtual ~ExtScript();
|
||||
ExtScript *copy(const QString _fileName, const int _number);
|
||||
// get methods
|
||||
@ -56,7 +59,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;
|
||||
@ -73,18 +76,18 @@ private slots:
|
||||
void updateValue();
|
||||
|
||||
private:
|
||||
QProcess *process = nullptr;
|
||||
Ui::ExtScript *ui;
|
||||
QProcess *m_process = nullptr;
|
||||
Ui::ExtScript *ui = nullptr;
|
||||
void translate();
|
||||
// properties
|
||||
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
|
||||
QVariantMap jsonFilters = QVariantMap();
|
||||
int times = 0;
|
||||
QVariantHash value;
|
||||
QVariantMap m_jsonFilters = QVariantMap();
|
||||
int m_times = 0;
|
||||
QVariantHash m_values;
|
||||
};
|
||||
|
||||
|
||||
|
@ -26,25 +26,24 @@
|
||||
#include <QTextCodec>
|
||||
|
||||
#include "awdebug.h"
|
||||
#include "version.h"
|
||||
|
||||
|
||||
ExtUpgrade::ExtUpgrade(QWidget *parent, const QString upgradeName,
|
||||
const QStringList directories)
|
||||
: AbstractExtItem(parent, upgradeName, directories)
|
||||
ExtUpgrade::ExtUpgrade(QWidget *parent, const QString filePath)
|
||||
: AbstractExtItem(parent, filePath)
|
||||
, ui(new Ui::ExtUpgrade)
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
readConfiguration();
|
||||
if (!filePath.isEmpty())
|
||||
readConfiguration();
|
||||
ui->setupUi(this);
|
||||
translate();
|
||||
|
||||
value[tag(QString("pkgcount"))] = 0;
|
||||
m_values[tag(QString("pkgcount"))] = 0;
|
||||
|
||||
process = new QProcess(nullptr);
|
||||
connect(process, SIGNAL(finished(int)), this, SLOT(updateValue()));
|
||||
process->waitForFinished(0);
|
||||
m_process = new QProcess(nullptr);
|
||||
connect(m_process, SIGNAL(finished(int)), this, SLOT(updateValue()));
|
||||
m_process->waitForFinished(0);
|
||||
}
|
||||
|
||||
|
||||
@ -52,8 +51,8 @@ ExtUpgrade::~ExtUpgrade()
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
process->kill();
|
||||
process->deleteLater();
|
||||
m_process->kill();
|
||||
m_process->deleteLater();
|
||||
delete ui;
|
||||
}
|
||||
|
||||
@ -62,8 +61,8 @@ ExtUpgrade *ExtUpgrade::copy(const QString _fileName, const int _number)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
||||
|
||||
ExtUpgrade *item = new ExtUpgrade(static_cast<QWidget *>(parent()),
|
||||
_fileName, directories());
|
||||
ExtUpgrade *item
|
||||
= new ExtUpgrade(static_cast<QWidget *>(parent()), _fileName);
|
||||
copyDefaults(item);
|
||||
item->setExecutable(executable());
|
||||
item->setFilter(filter());
|
||||
@ -94,7 +93,7 @@ int ExtUpgrade::null() const
|
||||
|
||||
QString ExtUpgrade::uniq() const
|
||||
{
|
||||
return m_executable;
|
||||
return executable();
|
||||
}
|
||||
|
||||
|
||||
@ -128,48 +127,36 @@ void ExtUpgrade::readConfiguration()
|
||||
{
|
||||
AbstractExtItem::readConfiguration();
|
||||
|
||||
for (int i = directories().count() - 1; i >= 0; i--) {
|
||||
if (!QDir(directories().at(i))
|
||||
.entryList(QDir::Files)
|
||||
.contains(fileName()))
|
||||
continue;
|
||||
QSettings settings(
|
||||
QString("%1/%2").arg(directories().at(i)).arg(fileName()),
|
||||
QSettings::IniFormat);
|
||||
QSettings settings(fileName(), QSettings::IniFormat);
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
setExecutable(settings.value(QString("Exec"), m_executable).toString());
|
||||
setNull(settings.value(QString("X-AW-Null"), m_null).toInt());
|
||||
// api == 3
|
||||
setFilter(settings.value(QString("X-AW-Filter"), m_filter).toString());
|
||||
settings.endGroup();
|
||||
}
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
setExecutable(settings.value(QString("Exec"), executable()).toString());
|
||||
setNull(settings.value(QString("X-AW-Null"), null()).toInt());
|
||||
// api == 3
|
||||
setFilter(settings.value(QString("X-AW-Filter"), filter()).toString());
|
||||
settings.endGroup();
|
||||
|
||||
// update for current API
|
||||
if ((apiVersion() > 0) && (apiVersion() < AWEUAPI)) {
|
||||
qCWarning(LOG_LIB) << "Bump API version from" << apiVersion() << "to"
|
||||
<< AWEUAPI;
|
||||
setApiVersion(AWEUAPI);
|
||||
writeConfiguration();
|
||||
}
|
||||
bumpApi(AWEUAPI);
|
||||
}
|
||||
|
||||
|
||||
QVariantHash ExtUpgrade::run()
|
||||
{
|
||||
if (!isActive())
|
||||
return value;
|
||||
return m_values;
|
||||
|
||||
if ((times == 1) && (process->state() == QProcess::NotRunning)) {
|
||||
QString cmd = QString("sh -c \"%1\"").arg(m_executable);
|
||||
if ((m_times == 1) && (m_process->state() == QProcess::NotRunning)) {
|
||||
QString cmd = QString("sh -c \"%1\"").arg(executable());
|
||||
qCInfo(LOG_LIB) << "Run cmd" << cmd;
|
||||
process->start(cmd);
|
||||
} else if (times >= interval()) {
|
||||
times = 0;
|
||||
m_process->start(cmd);
|
||||
}
|
||||
times++;
|
||||
|
||||
return value;
|
||||
// update value
|
||||
if (m_times >= interval())
|
||||
m_times = 0;
|
||||
m_times++;
|
||||
|
||||
return m_values;
|
||||
}
|
||||
|
||||
|
||||
@ -180,11 +167,11 @@ int ExtUpgrade::showConfiguration(const QVariant args)
|
||||
ui->lineEdit_name->setText(name());
|
||||
ui->lineEdit_comment->setText(comment());
|
||||
ui->label_numberValue->setText(QString("%1").arg(number()));
|
||||
ui->lineEdit_command->setText(m_executable);
|
||||
ui->lineEdit_filter->setText(m_filter);
|
||||
ui->lineEdit_command->setText(executable());
|
||||
ui->lineEdit_filter->setText(filter());
|
||||
ui->checkBox_active->setCheckState(isActive() ? Qt::Checked
|
||||
: Qt::Unchecked);
|
||||
ui->spinBox_null->setValue(m_null);
|
||||
ui->spinBox_null->setValue(null());
|
||||
ui->spinBox_interval->setValue(interval());
|
||||
|
||||
int ret = exec();
|
||||
@ -209,15 +196,13 @@ void ExtUpgrade::writeConfiguration() const
|
||||
{
|
||||
AbstractExtItem::writeConfiguration();
|
||||
|
||||
QSettings settings(
|
||||
QString("%1/%2").arg(directories().first()).arg(fileName()),
|
||||
QSettings::IniFormat);
|
||||
QSettings settings(writtableConfig(), QSettings::IniFormat);
|
||||
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
settings.setValue(QString("Exec"), m_executable);
|
||||
settings.setValue(QString("X-AW-Filter"), m_filter);
|
||||
settings.setValue(QString("X-AW-Null"), m_null);
|
||||
settings.setValue(QString("Exec"), executable());
|
||||
settings.setValue(QString("X-AW-Filter"), filter());
|
||||
settings.setValue(QString("X-AW-Null"), null());
|
||||
settings.endGroup();
|
||||
|
||||
settings.sync();
|
||||
@ -226,20 +211,22 @@ void ExtUpgrade::writeConfiguration() const
|
||||
|
||||
void ExtUpgrade::updateValue()
|
||||
{
|
||||
qCInfo(LOG_LIB) << "Cmd returns" << process->exitCode();
|
||||
qCInfo(LOG_LIB) << "Error" << process->readAllStandardError();
|
||||
qCInfo(LOG_LIB) << "Cmd returns" << m_process->exitCode();
|
||||
qCInfo(LOG_LIB) << "Error" << m_process->readAllStandardError();
|
||||
|
||||
QString qoutput = QTextCodec::codecForMib(106)
|
||||
->toUnicode(process->readAllStandardOutput())
|
||||
->toUnicode(m_process->readAllStandardOutput())
|
||||
.trimmed();
|
||||
value[tag(QString("pkgcount"))] = [this](QString output) {
|
||||
return m_filter.isEmpty()
|
||||
m_values[tag(QString("pkgcount"))] = [this](QString output) {
|
||||
return filter().isEmpty()
|
||||
? output.split(QChar('\n'), QString::SkipEmptyParts).count()
|
||||
- m_null
|
||||
- null()
|
||||
: output.split(QChar('\n'), QString::SkipEmptyParts)
|
||||
.filter(QRegExp(m_filter))
|
||||
.filter(QRegExp(filter()))
|
||||
.count();
|
||||
}(qoutput);
|
||||
|
||||
emit(dataReceived(m_values));
|
||||
}
|
||||
|
||||
|
||||
|
@ -36,9 +36,7 @@ class ExtUpgrade : public AbstractExtItem
|
||||
Q_PROPERTY(int null READ null WRITE setNull)
|
||||
|
||||
public:
|
||||
explicit ExtUpgrade(QWidget *parent = nullptr,
|
||||
const QString upgradeName = QString(),
|
||||
const QStringList directories = QStringList());
|
||||
explicit ExtUpgrade(QWidget *parent, const QString filePath = QString());
|
||||
virtual ~ExtUpgrade();
|
||||
ExtUpgrade *copy(const QString _fileName, const int _number);
|
||||
// get methods
|
||||
@ -61,16 +59,16 @@ private slots:
|
||||
void updateValue();
|
||||
|
||||
private:
|
||||
QProcess *process = nullptr;
|
||||
Ui::ExtUpgrade *ui;
|
||||
QProcess *m_process = nullptr;
|
||||
Ui::ExtUpgrade *ui = nullptr;
|
||||
void translate();
|
||||
// properties
|
||||
QString m_executable = QString("/usr/bin/true");
|
||||
QString m_filter = QString("");
|
||||
int m_null = 0;
|
||||
// internal properties
|
||||
int times = 0;
|
||||
QVariantHash value;
|
||||
int m_times = 0;
|
||||
QVariantHash m_values;
|
||||
};
|
||||
|
||||
|
||||
|
@ -31,31 +31,32 @@
|
||||
#include <qreplytimeout/qreplytimeout.h>
|
||||
|
||||
#include "awdebug.h"
|
||||
#include "version.h"
|
||||
#include "owmweatherprovider.h"
|
||||
#include "yahooweatherprovider.h"
|
||||
|
||||
|
||||
ExtWeather::ExtWeather(QWidget *parent, const QString weatherName,
|
||||
const QStringList directories)
|
||||
: AbstractExtItem(parent, weatherName, directories)
|
||||
ExtWeather::ExtWeather(QWidget *parent, const QString filePath)
|
||||
: AbstractExtItem(parent, filePath)
|
||||
, ui(new Ui::ExtWeather)
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
readConfiguration();
|
||||
if (!filePath.isEmpty())
|
||||
readConfiguration();
|
||||
readJsonMap();
|
||||
ui->setupUi(this);
|
||||
translate();
|
||||
|
||||
values[tag(QString("weatherId"))] = 0;
|
||||
values[tag(QString("weather"))] = QString("");
|
||||
values[tag(QString("humidity"))] = 0;
|
||||
values[tag(QString("pressure"))] = 0.0;
|
||||
values[tag(QString("temperature"))] = 0.0;
|
||||
m_values[tag(QString("weatherId"))] = 0;
|
||||
m_values[tag(QString("weather"))] = QString("");
|
||||
m_values[tag(QString("humidity"))] = 0;
|
||||
m_values[tag(QString("pressure"))] = 0.0;
|
||||
m_values[tag(QString("temperature"))] = 0.0;
|
||||
|
||||
// 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,10 +65,11 @@ 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 m_providerObject;
|
||||
delete ui;
|
||||
}
|
||||
|
||||
@ -76,13 +78,14 @@ ExtWeather *ExtWeather::copy(const QString _fileName, const int _number)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "File" << _fileName << "number" << _number;
|
||||
|
||||
ExtWeather *item = new ExtWeather(static_cast<QWidget *>(parent()),
|
||||
_fileName, directories());
|
||||
ExtWeather *item
|
||||
= new ExtWeather(static_cast<QWidget *>(parent()), _fileName);
|
||||
copyDefaults(item);
|
||||
item->setCity(city());
|
||||
item->setCountry(country());
|
||||
item->setImage(image());
|
||||
item->setNumber(_number);
|
||||
item->setProvider(provider());
|
||||
item->setTs(ts());
|
||||
|
||||
return item;
|
||||
@ -94,7 +97,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();
|
||||
}
|
||||
|
||||
@ -117,6 +120,28 @@ bool ExtWeather::image() const
|
||||
}
|
||||
|
||||
|
||||
ExtWeather::Provider ExtWeather::provider() const
|
||||
{
|
||||
return m_provider;
|
||||
}
|
||||
|
||||
|
||||
QString ExtWeather::strProvider() const
|
||||
{
|
||||
QString value;
|
||||
switch (m_provider) {
|
||||
case Provider::OWM:
|
||||
value = QString("OWM");
|
||||
break;
|
||||
case Provider::Yahoo:
|
||||
value = QString("Yahoo");
|
||||
break;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
int ExtWeather::ts() const
|
||||
{
|
||||
return m_ts;
|
||||
@ -125,7 +150,7 @@ int ExtWeather::ts() const
|
||||
|
||||
QString ExtWeather::uniq() const
|
||||
{
|
||||
return QString("%1 (%2) at %3").arg(m_city).arg(m_country).arg(m_ts);
|
||||
return QString("%1 (%2) at %3").arg(city()).arg(country()).arg(ts());
|
||||
}
|
||||
|
||||
|
||||
@ -134,6 +159,7 @@ void ExtWeather::setCity(const QString _city)
|
||||
qCDebug(LOG_LIB) << "City" << _city;
|
||||
|
||||
m_city = _city;
|
||||
initProvider();
|
||||
}
|
||||
|
||||
|
||||
@ -142,6 +168,7 @@ void ExtWeather::setCountry(const QString _country)
|
||||
qCDebug(LOG_LIB) << "Country" << _country;
|
||||
|
||||
m_country = _country;
|
||||
initProvider();
|
||||
}
|
||||
|
||||
|
||||
@ -153,11 +180,32 @@ void ExtWeather::setImage(const bool _image)
|
||||
}
|
||||
|
||||
|
||||
void ExtWeather::setProvider(const Provider _provider)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Provider" << static_cast<int>(_provider);
|
||||
|
||||
m_provider = _provider;
|
||||
initProvider();
|
||||
}
|
||||
|
||||
|
||||
void ExtWeather::setStrProvider(const QString _provider)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Provider" << _provider;
|
||||
|
||||
if (_provider == QString("Yahoo"))
|
||||
setProvider(Provider::Yahoo);
|
||||
else
|
||||
setProvider(Provider::OWM);
|
||||
}
|
||||
|
||||
|
||||
void ExtWeather::setTs(const int _ts)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Timestamp" << _ts;
|
||||
|
||||
m_ts = _ts;
|
||||
initProvider();
|
||||
}
|
||||
|
||||
|
||||
@ -165,34 +213,21 @@ void ExtWeather::readConfiguration()
|
||||
{
|
||||
AbstractExtItem::readConfiguration();
|
||||
|
||||
for (int i = directories().count() - 1; i >= 0; i--) {
|
||||
if (!QDir(directories().at(i))
|
||||
.entryList(QDir::Files)
|
||||
.contains(fileName()))
|
||||
continue;
|
||||
QSettings settings(
|
||||
QString("%1/%2").arg(directories().at(i)).arg(fileName()),
|
||||
QSettings::IniFormat);
|
||||
QSettings settings(fileName(), QSettings::IniFormat);
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
setCity(settings.value(QString("X-AW-City"), m_city).toString());
|
||||
setCountry(
|
||||
settings.value(QString("X-AW-Country"), m_country).toString());
|
||||
setTs(settings.value(QString("X-AW-TS"), m_ts).toInt());
|
||||
// api == 2
|
||||
setImage(
|
||||
settings.value(QString("X-AW-Image"), QVariant(m_image)).toString()
|
||||
== QString("true"));
|
||||
settings.endGroup();
|
||||
}
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
setCity(settings.value(QString("X-AW-City"), city()).toString());
|
||||
setCountry(settings.value(QString("X-AW-Country"), country()).toString());
|
||||
setTs(settings.value(QString("X-AW-TS"), ts()).toInt());
|
||||
// api == 2
|
||||
setImage(settings.value(QString("X-AW-Image"), QVariant(image())).toString()
|
||||
== QString("true"));
|
||||
// api == 3
|
||||
setStrProvider(
|
||||
settings.value(QString("X-AW-Provider"), strProvider()).toString());
|
||||
settings.endGroup();
|
||||
|
||||
// update for current API
|
||||
if ((apiVersion() > 0) && (apiVersion() < AWEWAPI)) {
|
||||
qCWarning(LOG_LIB) << "Bump API version from" << apiVersion() << "to"
|
||||
<< AWEWAPI;
|
||||
setApiVersion(AWEWAPI);
|
||||
writeConfiguration();
|
||||
}
|
||||
bumpApi(AWEWAPI);
|
||||
}
|
||||
|
||||
|
||||
@ -216,30 +251,31 @@ 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;
|
||||
}
|
||||
|
||||
|
||||
QVariantHash ExtWeather::run()
|
||||
{
|
||||
if ((!isActive()) || (isRunning))
|
||||
return values;
|
||||
if ((!isActive()) || (m_isRunning))
|
||||
return m_values;
|
||||
|
||||
if (times == 1) {
|
||||
if (m_times == 1) {
|
||||
qCInfo(LOG_LIB) << "Send request";
|
||||
isRunning = true;
|
||||
QNetworkReply *reply = manager->get(QNetworkRequest(QUrl(url())));
|
||||
m_isRunning = true;
|
||||
QNetworkReply *reply
|
||||
= m_manager->get(QNetworkRequest(m_providerObject->url()));
|
||||
new QReplyTimeout(reply, REQUEST_TIMEOUT);
|
||||
}
|
||||
|
||||
// update value
|
||||
if (times >= interval())
|
||||
times = 0;
|
||||
times++;
|
||||
if (m_times >= interval())
|
||||
m_times = 0;
|
||||
m_times++;
|
||||
|
||||
return values;
|
||||
return m_values;
|
||||
}
|
||||
|
||||
|
||||
@ -250,10 +286,11 @@ int ExtWeather::showConfiguration(const QVariant args)
|
||||
ui->lineEdit_name->setText(name());
|
||||
ui->lineEdit_comment->setText(comment());
|
||||
ui->label_numberValue->setText(QString("%1").arg(number()));
|
||||
ui->lineEdit_city->setText(m_city);
|
||||
ui->lineEdit_country->setText(m_country);
|
||||
ui->spinBox_timestamp->setValue(m_ts);
|
||||
ui->checkBox_image->setCheckState(m_image ? Qt::Checked : Qt::Unchecked);
|
||||
ui->comboBox_provider->setCurrentIndex(static_cast<int>(provider()));
|
||||
ui->lineEdit_city->setText(city());
|
||||
ui->lineEdit_country->setText(country());
|
||||
ui->spinBox_timestamp->setValue(ts());
|
||||
ui->checkBox_image->setCheckState(image() ? Qt::Checked : Qt::Unchecked);
|
||||
ui->checkBox_active->setCheckState(isActive() ? Qt::Checked
|
||||
: Qt::Unchecked);
|
||||
ui->spinBox_interval->setValue(interval());
|
||||
@ -267,6 +304,7 @@ int ExtWeather::showConfiguration(const QVariant args)
|
||||
setApiVersion(AWEWAPI);
|
||||
setCity(ui->lineEdit_city->text());
|
||||
setCountry(ui->lineEdit_country->text());
|
||||
setProvider(static_cast<Provider>(ui->comboBox_provider->currentIndex()));
|
||||
setTs(ui->spinBox_timestamp->value());
|
||||
setImage(ui->checkBox_image->checkState() == Qt::Checked);
|
||||
setActive(ui->checkBox_active->checkState() == Qt::Checked);
|
||||
@ -281,16 +319,15 @@ void ExtWeather::writeConfiguration() const
|
||||
{
|
||||
AbstractExtItem::writeConfiguration();
|
||||
|
||||
QSettings settings(
|
||||
QString("%1/%2").arg(directories().first()).arg(fileName()),
|
||||
QSettings::IniFormat);
|
||||
QSettings settings(writtableConfig(), QSettings::IniFormat);
|
||||
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
settings.setValue(QString("X-AW-City"), m_city);
|
||||
settings.setValue(QString("X-AW-Country"), m_country);
|
||||
settings.setValue(QString("X-AW-Image"), m_image);
|
||||
settings.setValue(QString("X-AW-TS"), m_ts);
|
||||
settings.setValue(QString("X-AW-City"), city());
|
||||
settings.setValue(QString("X-AW-Country"), country());
|
||||
settings.setValue(QString("X-AW-Image"), image());
|
||||
settings.setValue(QString("X-AW-Provider"), strProvider());
|
||||
settings.setValue(QString("X-AW-TS"), ts());
|
||||
settings.endGroup();
|
||||
|
||||
settings.sync();
|
||||
@ -302,7 +339,7 @@ void ExtWeather::weatherReplyReceived(QNetworkReply *reply)
|
||||
qCDebug(LOG_LIB) << "Return code" << reply->error() << "with message"
|
||||
<< reply->errorString();
|
||||
|
||||
isRunning = false;
|
||||
m_isRunning = false;
|
||||
QJsonParseError error;
|
||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(reply->readAll(), &error);
|
||||
reply->deleteLater();
|
||||
@ -312,53 +349,31 @@ void ExtWeather::weatherReplyReceived(QNetworkReply *reply)
|
||||
return;
|
||||
}
|
||||
|
||||
// convert to map
|
||||
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";
|
||||
QVariantHash data = m_providerObject->parse(jsonDoc.toVariant().toMap());
|
||||
if (data.isEmpty())
|
||||
return;
|
||||
}
|
||||
QVariantMap results
|
||||
= json[QString("results")].toMap()[QString("channel")].toMap();
|
||||
QVariantMap item = results[QString("item")].toMap();
|
||||
m_values = data;
|
||||
m_values[tag(QString("weather"))]
|
||||
= weatherFromInt(m_values[tag(QString("weatherId"))].toInt());
|
||||
|
||||
if (m_ts == 0) {
|
||||
// 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 {
|
||||
// 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;
|
||||
emit(dataReceived(m_values));
|
||||
}
|
||||
|
||||
|
||||
void ExtWeather::initProvider()
|
||||
{
|
||||
delete m_providerObject;
|
||||
|
||||
switch (m_provider) {
|
||||
case Provider::OWM:
|
||||
m_providerObject = new OWMWeatherProvider(this, number());
|
||||
break;
|
||||
case Provider::Yahoo:
|
||||
m_providerObject = new YahooWeatherProvider(this, number());
|
||||
break;
|
||||
}
|
||||
|
||||
return m_providerObject->initUrl(city(), country(), ts());
|
||||
}
|
||||
|
||||
|
||||
@ -367,6 +382,7 @@ void ExtWeather::translate()
|
||||
ui->label_name->setText(i18n("Name"));
|
||||
ui->label_comment->setText(i18n("Comment"));
|
||||
ui->label_number->setText(i18n("Tag"));
|
||||
ui->label_provider->setText(i18n("Provider"));
|
||||
ui->label_city->setText(i18n("City"));
|
||||
ui->label_country->setText(i18n("Country"));
|
||||
ui->label_timestamp->setText(i18n("Timestamp"));
|
||||
@ -374,13 +390,3 @@ void ExtWeather::translate()
|
||||
ui->checkBox_active->setText(i18n("Active"));
|
||||
ui->label_interval->setText(i18n("Interval"));
|
||||
}
|
||||
|
||||
|
||||
QString ExtWeather::url() const
|
||||
{
|
||||
|
||||
QString apiUrl = QString(YAHOO_WEATHER_URL).arg(m_city).arg(m_country);
|
||||
qCInfo(LOG_LIB) << "API url" << apiUrl;
|
||||
|
||||
return apiUrl;
|
||||
}
|
||||
|
@ -22,12 +22,8 @@
|
||||
|
||||
#include "abstractextitem.h"
|
||||
|
||||
#define YAHOO_WEATHER_URL \
|
||||
"https://query.yahooapis.com/v1/public/yql?format=json&env=store://" \
|
||||
"datatables.org/alltableswithkeys&q=select * from weather.forecast where " \
|
||||
"u='c' and woeid in (select woeid from geo.places(1) where text='%1, %2')"
|
||||
|
||||
|
||||
class AbstractWeatherProvider;
|
||||
namespace Ui
|
||||
{
|
||||
class ExtWeather;
|
||||
@ -39,12 +35,14 @@ class ExtWeather : public AbstractExtItem
|
||||
Q_PROPERTY(QString city READ city WRITE setCity)
|
||||
Q_PROPERTY(QString country READ country WRITE setCountry)
|
||||
Q_PROPERTY(bool image READ image WRITE setImage)
|
||||
Q_PROPERTY(Provider povider READ provider WRITE setProvider)
|
||||
Q_PROPERTY(QString strPovider READ strProvider WRITE setStrProvider)
|
||||
Q_PROPERTY(int ts READ ts WRITE setTs)
|
||||
|
||||
public:
|
||||
explicit ExtWeather(QWidget *parent = nullptr,
|
||||
const QString weatherName = QString(),
|
||||
const QStringList directories = QStringList());
|
||||
enum class Provider { OWM = 0, Yahoo = 1 };
|
||||
|
||||
explicit ExtWeather(QWidget *parent, const QString filePath = QString());
|
||||
virtual ~ExtWeather();
|
||||
ExtWeather *copy(const QString _fileName, const int _number);
|
||||
QString weatherFromInt(const int _id) const;
|
||||
@ -52,12 +50,16 @@ public:
|
||||
QString city() const;
|
||||
QString country() const;
|
||||
bool image() const;
|
||||
Provider provider() const;
|
||||
QString strProvider() const;
|
||||
int ts() const;
|
||||
QString uniq() const;
|
||||
// set methods
|
||||
void setCity(const QString _city = QString("London"));
|
||||
void setCountry(const QString _country = QString("uk"));
|
||||
void setImage(const bool _image = false);
|
||||
void setProvider(const Provider _provider = Provider::OWM);
|
||||
void setStrProvider(const QString _provider = QString("OWM"));
|
||||
void setTs(const int _ts = 0);
|
||||
|
||||
public slots:
|
||||
@ -71,20 +73,22 @@ private slots:
|
||||
void weatherReplyReceived(QNetworkReply *reply);
|
||||
|
||||
private:
|
||||
QNetworkAccessManager *manager;
|
||||
bool isRunning = false;
|
||||
Ui::ExtWeather *ui;
|
||||
QNetworkAccessManager *m_manager = nullptr;
|
||||
AbstractWeatherProvider *m_providerObject = nullptr;
|
||||
bool m_isRunning = false;
|
||||
Ui::ExtWeather *ui = nullptr;
|
||||
void initProvider();
|
||||
void translate();
|
||||
QString url() const;
|
||||
// properties
|
||||
QString m_city = QString("London");
|
||||
QString m_country = QString("uk");
|
||||
bool m_image = false;
|
||||
Provider m_provider = Provider::OWM;
|
||||
int m_ts = 0;
|
||||
QVariantMap jsonMap = QVariantMap();
|
||||
QVariantMap m_jsonMap = QVariantMap();
|
||||
// values
|
||||
int times = 0;
|
||||
QVariantHash values;
|
||||
int m_times = 0;
|
||||
QVariantHash m_values;
|
||||
};
|
||||
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>420</width>
|
||||
<height>301</height>
|
||||
<height>333</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -81,6 +81,46 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_provider">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_provider">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Provider</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="comboBox_provider">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string notr="true">OWM</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string notr="true">Yahoo</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_city">
|
||||
<item>
|
||||
|
16
sources/awesomewidgets/formatters/default-float.desktop
Normal file
16
sources/awesomewidgets/formatters/default-float.desktop
Normal file
@ -0,0 +1,16 @@
|
||||
[Desktop%20Entry]
|
||||
Comment=Default float formatter
|
||||
Encoding=UTF-8
|
||||
Name=Float
|
||||
X-AW-Active=true
|
||||
X-AW-ApiVersion=2
|
||||
X-AW-FillChar=@Variant(\0\0\0\a\0\0)
|
||||
X-AW-ForceWidth=false
|
||||
X-AW-Format=f
|
||||
X-AW-Interval=1
|
||||
X-AW-Multiplier=1
|
||||
X-AW-Number=0
|
||||
X-AW-Precision=1
|
||||
X-AW-Summand=0
|
||||
X-AW-Type=Float
|
||||
X-AW-Width=5
|
16
sources/awesomewidgets/formatters/default-integer.desktop
Normal file
16
sources/awesomewidgets/formatters/default-integer.desktop
Normal file
@ -0,0 +1,16 @@
|
||||
[Desktop%20Entry]
|
||||
Comment=Default integer formatter
|
||||
Encoding=UTF-8
|
||||
Name=Integer
|
||||
X-AW-Active=true
|
||||
X-AW-ApiVersion=2
|
||||
X-AW-FillChar=@Variant(\0\0\0\a\0\0)
|
||||
X-AW-ForceWidth=false
|
||||
X-AW-Format=f
|
||||
X-AW-Interval=1
|
||||
X-AW-Multiplier=1
|
||||
X-AW-Number=2
|
||||
X-AW-Precision=0
|
||||
X-AW-Summand=0
|
||||
X-AW-Type=Float
|
||||
X-AW-Width=4
|
12
sources/awesomewidgets/formatters/default-list.desktop
Normal file
12
sources/awesomewidgets/formatters/default-list.desktop
Normal file
@ -0,0 +1,12 @@
|
||||
[Desktop%20Entry]
|
||||
Comment=Default list formatter
|
||||
Encoding=UTF-8
|
||||
Name=List
|
||||
X-AW-Active=true
|
||||
X-AW-ApiVersion=2
|
||||
X-AW-Filter=
|
||||
X-AW-Interval=1
|
||||
X-AW-Number=5
|
||||
X-AW-Separator=","
|
||||
X-AW-Sort=false
|
||||
X-AW-Type=NoFormat
|
16
sources/awesomewidgets/formatters/float-two-symbols.desktop
Normal file
16
sources/awesomewidgets/formatters/float-two-symbols.desktop
Normal file
@ -0,0 +1,16 @@
|
||||
[Desktop%20Entry]
|
||||
Comment=Float formatter with two symbols
|
||||
Encoding=UTF-8
|
||||
Name=FloatTwoSymbols
|
||||
X-AW-Active=true
|
||||
X-AW-ApiVersion=2
|
||||
X-AW-FillChar=@Variant(\0\0\0\a\0\0)
|
||||
X-AW-ForceWidth=false
|
||||
X-AW-Format=f
|
||||
X-AW-Interval=1
|
||||
X-AW-Multiplier=1
|
||||
X-AW-Number=1
|
||||
X-AW-Precision=2
|
||||
X-AW-Summand=0
|
||||
X-AW-Type=Float
|
||||
X-AW-Width=5
|
16
sources/awesomewidgets/formatters/long-integer.desktop
Normal file
16
sources/awesomewidgets/formatters/long-integer.desktop
Normal file
@ -0,0 +1,16 @@
|
||||
[Desktop%20Entry]
|
||||
Comment=Long integer formatter
|
||||
Encoding=UTF-8
|
||||
Name=LongInteger
|
||||
X-AW-Active=true
|
||||
X-AW-ApiVersion=2
|
||||
X-AW-FillChar=@Variant(\0\0\0\a\0\0)
|
||||
X-AW-ForceWidth=false
|
||||
X-AW-Format=f
|
||||
X-AW-Interval=1
|
||||
X-AW-Multiplier=1
|
||||
X-AW-Number=3
|
||||
X-AW-Precision=0
|
||||
X-AW-Summand=0
|
||||
X-AW-Type=Float
|
||||
X-AW-Width=5
|
16
sources/awesomewidgets/formatters/memory-gb.desktop
Normal file
16
sources/awesomewidgets/formatters/memory-gb.desktop
Normal file
@ -0,0 +1,16 @@
|
||||
[Desktop%20Entry]
|
||||
Comment=Memory in GB formatter
|
||||
Encoding=UTF-8
|
||||
Name=MemGB
|
||||
X-AW-Active=true
|
||||
X-AW-ApiVersion=2
|
||||
X-AW-FillChar=@Variant(\0\0\0\a\0\0)
|
||||
X-AW-ForceWidth=false
|
||||
X-AW-Format=f
|
||||
X-AW-Interval=1
|
||||
X-AW-Multiplier=1048576
|
||||
X-AW-Number=6
|
||||
X-AW-Precision=1
|
||||
X-AW-Summand=0
|
||||
X-AW-Type=Float
|
||||
X-AW-Width=5
|
16
sources/awesomewidgets/formatters/memory-mb.desktop
Normal file
16
sources/awesomewidgets/formatters/memory-mb.desktop
Normal file
@ -0,0 +1,16 @@
|
||||
[Desktop%20Entry]
|
||||
Comment=Memory in MB formatter
|
||||
Encoding=UTF-8
|
||||
Name=MemMB
|
||||
X-AW-Active=true
|
||||
X-AW-ApiVersion=2
|
||||
X-AW-FillChar=@Variant(\0\0\0\a\0\0)
|
||||
X-AW-ForceWidth=false
|
||||
X-AW-Format=f
|
||||
X-AW-Interval=1
|
||||
X-AW-Multiplier=1024
|
||||
X-AW-Number=7
|
||||
X-AW-Precision=0
|
||||
X-AW-Summand=0
|
||||
X-AW-Type=Float
|
||||
X-AW-Width=5
|
16
sources/awesomewidgets/formatters/short-integer.desktop
Normal file
16
sources/awesomewidgets/formatters/short-integer.desktop
Normal file
@ -0,0 +1,16 @@
|
||||
[Desktop%20Entry]
|
||||
Comment=Short integer formatter
|
||||
Encoding=UTF-8
|
||||
Name=ShortInteger
|
||||
X-AW-Active=true
|
||||
X-AW-ApiVersion=2
|
||||
X-AW-FillChar=@Variant(\0\0\0\a\0\0)
|
||||
X-AW-ForceWidth=false
|
||||
X-AW-Format=f
|
||||
X-AW-Interval=1
|
||||
X-AW-Multiplier=1
|
||||
X-AW-Number=4
|
||||
X-AW-Precision=0
|
||||
X-AW-Summand=0
|
||||
X-AW-Type=Float
|
||||
X-AW-Width=3
|
@ -30,38 +30,27 @@
|
||||
|
||||
#include "awdebug.h"
|
||||
#include "graphicalitemhelper.h"
|
||||
#include "version.h"
|
||||
|
||||
|
||||
GraphicalItem::GraphicalItem(QWidget *parent, const QString desktopName,
|
||||
const QStringList directories)
|
||||
: AbstractExtItem(parent, desktopName, directories)
|
||||
GraphicalItem::GraphicalItem(QWidget *parent, const QString filePath)
|
||||
: AbstractExtItem(parent, filePath)
|
||||
, ui(new Ui::GraphicalItem)
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
readConfiguration();
|
||||
if (!filePath.isEmpty())
|
||||
readConfiguration();
|
||||
ui->setupUi(this);
|
||||
translate();
|
||||
|
||||
initScene();
|
||||
|
||||
connect(ui->checkBox_custom, SIGNAL(stateChanged(int)), this,
|
||||
SLOT(changeValue(int)));
|
||||
connect(ui->checkBox_activeCheck, SIGNAL(stateChanged(int)), this,
|
||||
SLOT(changeColorState(int)));
|
||||
connect(ui->checkBox_inactiveCheck, SIGNAL(stateChanged(int)), this,
|
||||
SLOT(changeColorState(int)));
|
||||
connect(ui->comboBox_type, SIGNAL(currentIndexChanged(int)), this,
|
||||
SLOT(changeCountState(int)));
|
||||
connect(ui->pushButton_activeColor, SIGNAL(clicked()), this,
|
||||
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()));
|
||||
connect(ui->pushButton_activeImage, SIGNAL(clicked()), this,
|
||||
SLOT(changeImage()));
|
||||
connect(ui->pushButton_inactiveImage, SIGNAL(clicked()), this,
|
||||
SLOT(changeImage()));
|
||||
}
|
||||
|
||||
|
||||
@ -79,21 +68,21 @@ GraphicalItem *GraphicalItem::copy(const QString _fileName, const int _number)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
||||
|
||||
GraphicalItem *item = new GraphicalItem(static_cast<QWidget *>(parent()),
|
||||
_fileName, directories());
|
||||
GraphicalItem *item
|
||||
= new GraphicalItem(static_cast<QWidget *>(parent()), _fileName);
|
||||
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->setActiveColor(activeColor());
|
||||
item->setBar(bar());
|
||||
item->setCount(count());
|
||||
item->setCustom(isCustom());
|
||||
item->setDirection(direction());
|
||||
item->setItemHeight(itemHeight());
|
||||
item->setInactiveColor(inactiveColor());
|
||||
item->setMaxValue(maxValue());
|
||||
item->setMinValue(minValue());
|
||||
item->setNumber(_number);
|
||||
item->setType(m_type);
|
||||
item->setWidth(m_width);
|
||||
item->setType(type());
|
||||
item->setItemWidth(itemWidth());
|
||||
|
||||
return item;
|
||||
}
|
||||
@ -106,29 +95,34 @@ QString GraphicalItem::image(const QVariant &value)
|
||||
m_scene->clear();
|
||||
int scale[2] = {1, 1};
|
||||
float converted
|
||||
= m_helper->getPercents(value.toFloat(), m_minValue, m_maxValue);
|
||||
= m_helper->getPercents(value.toFloat(), minValue(), maxValue());
|
||||
|
||||
// paint
|
||||
switch (m_type) {
|
||||
case Vertical:
|
||||
case Type::Vertical:
|
||||
m_helper->paintVertical(converted);
|
||||
// scale
|
||||
scale[1] = -2 * static_cast<int>(m_direction) + 1;
|
||||
scale[1] = -2 * static_cast<int>(direction()) + 1;
|
||||
break;
|
||||
case Circle:
|
||||
case Type::Circle:
|
||||
m_helper->paintCircle(converted);
|
||||
// scale
|
||||
scale[0] = -2 * static_cast<int>(m_direction) + 1;
|
||||
scale[0] = -2 * static_cast<int>(direction()) + 1;
|
||||
break;
|
||||
case Graph:
|
||||
case Type::Graph:
|
||||
m_helper->paintGraph(converted);
|
||||
// direction option is not recognized by this GI type
|
||||
scale[0] = -2 * static_cast<int>(direction()) + 1;
|
||||
scale[1] = -1;
|
||||
break;
|
||||
case Horizontal:
|
||||
default:
|
||||
case Type::Bars:
|
||||
m_helper->paintBars(converted);
|
||||
scale[0] = -2 * static_cast<int>(direction()) + 1;
|
||||
scale[1] = -1;
|
||||
break;
|
||||
case Type::Horizontal:
|
||||
m_helper->paintHorizontal(converted);
|
||||
// scale
|
||||
scale[0] = -2 * static_cast<int>(m_direction) + 1;
|
||||
scale[0] = -2 * static_cast<int>(direction()) + 1;
|
||||
break;
|
||||
}
|
||||
|
||||
@ -145,6 +139,31 @@ QString GraphicalItem::image(const QVariant &value)
|
||||
}
|
||||
|
||||
|
||||
void GraphicalItem::initScene()
|
||||
{
|
||||
// cleanup
|
||||
delete m_helper;
|
||||
delete m_scene;
|
||||
|
||||
// init scene
|
||||
m_scene = new QGraphicsScene();
|
||||
m_scene->setBackgroundBrush(QBrush(Qt::NoBrush));
|
||||
// init view
|
||||
m_view = new QGraphicsView(m_scene);
|
||||
m_view->setStyleSheet(QString("background: transparent"));
|
||||
m_view->setContentsMargins(0, 0, 0, 0);
|
||||
m_view->setFrameShape(QFrame::NoFrame);
|
||||
m_view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
m_view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
m_view->resize(m_width + 5, m_height + 5);
|
||||
|
||||
// init helper
|
||||
m_helper = new GraphicalItemHelper(this, m_scene);
|
||||
m_helper->setParameters(activeColor(), inactiveColor(), itemWidth(),
|
||||
itemHeight(), count());
|
||||
}
|
||||
|
||||
|
||||
QString GraphicalItem::bar() const
|
||||
{
|
||||
return m_bar;
|
||||
@ -157,24 +176,36 @@ QString GraphicalItem::activeColor() const
|
||||
}
|
||||
|
||||
|
||||
QString GraphicalItem::inactiveColor() const
|
||||
{
|
||||
return m_inactiveColor;
|
||||
}
|
||||
|
||||
|
||||
int GraphicalItem::count() const
|
||||
{
|
||||
return m_count;
|
||||
}
|
||||
|
||||
|
||||
QString GraphicalItem::inactiveColor() const
|
||||
{
|
||||
return m_inactiveColor;
|
||||
}
|
||||
|
||||
|
||||
bool GraphicalItem::isCustom() const
|
||||
{
|
||||
return m_custom;
|
||||
}
|
||||
|
||||
|
||||
int GraphicalItem::itemHeight() const
|
||||
{
|
||||
return m_height;
|
||||
}
|
||||
|
||||
|
||||
int GraphicalItem::itemWidth() const
|
||||
{
|
||||
return m_width;
|
||||
}
|
||||
|
||||
|
||||
float GraphicalItem::maxValue() const
|
||||
{
|
||||
return m_maxValue;
|
||||
@ -196,18 +227,20 @@ GraphicalItem::Type GraphicalItem::type() const
|
||||
QString GraphicalItem::strType() const
|
||||
{
|
||||
QString value;
|
||||
switch (m_type) {
|
||||
case Vertical:
|
||||
switch (type()) {
|
||||
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;
|
||||
}
|
||||
@ -225,12 +258,11 @@ GraphicalItem::Direction GraphicalItem::direction() const
|
||||
QString GraphicalItem::strDirection() const
|
||||
{
|
||||
QString value;
|
||||
switch (m_direction) {
|
||||
case RightToLeft:
|
||||
switch (direction()) {
|
||||
case Direction::RightToLeft:
|
||||
value = QString("RightToLeft");
|
||||
break;
|
||||
case LeftToRight:
|
||||
default:
|
||||
case Direction::LeftToRight:
|
||||
value = QString("LeftToRight");
|
||||
break;
|
||||
}
|
||||
@ -239,27 +271,15 @@ QString GraphicalItem::strDirection() const
|
||||
}
|
||||
|
||||
|
||||
int GraphicalItem::height() const
|
||||
{
|
||||
return m_height;
|
||||
}
|
||||
|
||||
|
||||
QStringList GraphicalItem::usedKeys() const
|
||||
{
|
||||
return m_usedKeys;
|
||||
}
|
||||
|
||||
|
||||
int GraphicalItem::width() const
|
||||
{
|
||||
return m_width;
|
||||
}
|
||||
|
||||
|
||||
QString GraphicalItem::uniq() const
|
||||
{
|
||||
return m_bar;
|
||||
return bar();
|
||||
}
|
||||
|
||||
|
||||
@ -305,6 +325,26 @@ void GraphicalItem::setInactiveColor(const QString _color)
|
||||
}
|
||||
|
||||
|
||||
void GraphicalItem::setItemHeight(const int _height)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Height" << _height;
|
||||
if (_height <= 0)
|
||||
return;
|
||||
|
||||
m_height = _height;
|
||||
}
|
||||
|
||||
|
||||
void GraphicalItem::setItemWidth(const int _width)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Width" << _width;
|
||||
if (_width <= 0)
|
||||
return;
|
||||
|
||||
m_width = _width;
|
||||
}
|
||||
|
||||
|
||||
void GraphicalItem::setMaxValue(const float _value)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Max value" << _value;
|
||||
@ -323,7 +363,7 @@ void GraphicalItem::setMinValue(const float _value)
|
||||
|
||||
void GraphicalItem::setType(const Type _type)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Type" << _type;
|
||||
qCDebug(LOG_LIB) << "Type" << static_cast<int>(_type);
|
||||
|
||||
m_type = _type;
|
||||
}
|
||||
@ -334,19 +374,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;
|
||||
}
|
||||
@ -357,19 +399,9 @@ void GraphicalItem::setStrDirection(const QString _direction)
|
||||
qCDebug(LOG_LIB) << "Direction" << _direction;
|
||||
|
||||
if (_direction == QString("RightToLeft"))
|
||||
setDirection(RightToLeft);
|
||||
setDirection(Direction::RightToLeft);
|
||||
else
|
||||
setDirection(LeftToRight);
|
||||
}
|
||||
|
||||
|
||||
void GraphicalItem::setHeight(const int _height)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Height" << _height;
|
||||
if (_height <= 0)
|
||||
return;
|
||||
|
||||
m_height = _height;
|
||||
setDirection(Direction::LeftToRight);
|
||||
}
|
||||
|
||||
|
||||
@ -378,17 +410,13 @@ void GraphicalItem::setUsedKeys(const QStringList _usedKeys)
|
||||
qCDebug(LOG_LIB) << "Used keys" << _usedKeys;
|
||||
|
||||
// remove dubs
|
||||
m_usedKeys = QSet<QString>::fromList(_usedKeys).toList();
|
||||
}
|
||||
|
||||
|
||||
void GraphicalItem::setWidth(const int _width)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Width" << _width;
|
||||
if (_width <= 0)
|
||||
return;
|
||||
|
||||
m_width = _width;
|
||||
// HACK converting to set may break order
|
||||
usedKeys().clear();
|
||||
for (auto key : _usedKeys) {
|
||||
if (usedKeys().contains(key))
|
||||
continue;
|
||||
usedKeys().append(key);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -396,46 +424,39 @@ void GraphicalItem::readConfiguration()
|
||||
{
|
||||
AbstractExtItem::readConfiguration();
|
||||
|
||||
for (int i = directories().count() - 1; i >= 0; i--) {
|
||||
if (!QDir(directories().at(i))
|
||||
.entryList(QDir::Files)
|
||||
.contains(fileName()))
|
||||
continue;
|
||||
QSettings settings(
|
||||
QString("%1/%2").arg(directories().at(i)).arg(fileName()),
|
||||
QSettings::IniFormat);
|
||||
QSettings settings(fileName(), 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());
|
||||
setInactiveColor(
|
||||
settings.value(QString("X-AW-InactiveColor"), m_inactiveColor)
|
||||
.toString());
|
||||
setStrType(settings.value(QString("X-AW-Type"), strType()).toString());
|
||||
setStrDirection(
|
||||
settings.value(QString("X-AW-Direction"), strDirection())
|
||||
.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());
|
||||
settings.endGroup();
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
setCount(settings.value(QString("X-AW-Count"), count()).toInt());
|
||||
setCustom(settings.value(QString("X-AW-Custom"), isCustom()).toBool());
|
||||
setBar(settings.value(QString("X-AW-Value"), bar()).toString());
|
||||
setMaxValue(settings.value(QString("X-AW-Max"), maxValue()).toFloat());
|
||||
setMinValue(settings.value(QString("X-AW-Min"), minValue()).toFloat());
|
||||
setActiveColor(
|
||||
settings.value(QString("X-AW-ActiveColor"), activeColor()).toString());
|
||||
setInactiveColor(
|
||||
settings.value(QString("X-AW-InactiveColor"), inactiveColor())
|
||||
.toString());
|
||||
setStrType(settings.value(QString("X-AW-Type"), strType()).toString());
|
||||
setStrDirection(
|
||||
settings.value(QString("X-AW-Direction"), strDirection()).toString());
|
||||
setItemHeight(settings.value(QString("X-AW-Height"), itemHeight()).toInt());
|
||||
setItemWidth(settings.value(QString("X-AW-Width"), itemWidth()).toInt());
|
||||
// api == 5
|
||||
if (apiVersion() < 5) {
|
||||
QString prefix;
|
||||
prefix = activeColor().startsWith(QString("/")) ? QString("file://%1")
|
||||
: QString("color://%1");
|
||||
m_activeColor = prefix.arg(activeColor());
|
||||
prefix = inactiveColor().startsWith(QString("/"))
|
||||
? QString("file://%1")
|
||||
: QString("color://%1");
|
||||
m_inactiveColor = prefix.arg(inactiveColor());
|
||||
}
|
||||
settings.endGroup();
|
||||
|
||||
// update for current API
|
||||
if ((apiVersion() > 0) && (apiVersion() < AWGIAPI)) {
|
||||
qCWarning(LOG_LIB) << "Bump API version from" << apiVersion() << "to"
|
||||
<< AWGIAPI;
|
||||
setApiVersion(AWGIAPI);
|
||||
writeConfiguration();
|
||||
}
|
||||
bumpApi(AWGIAPI);
|
||||
initScene();
|
||||
}
|
||||
|
||||
|
||||
@ -446,27 +467,37 @@ int GraphicalItem::showConfiguration(const QVariant args)
|
||||
|
||||
ui->lineEdit_name->setText(name());
|
||||
ui->lineEdit_comment->setText(comment());
|
||||
ui->checkBox_custom->setChecked(m_custom);
|
||||
ui->label_numberValue->setText(QString("%1").arg(number()));
|
||||
ui->checkBox_custom->setChecked(isCustom());
|
||||
ui->comboBox_value->addItems(tags);
|
||||
if (m_custom) {
|
||||
ui->lineEdit_customValue->setText(m_bar);
|
||||
if (isCustom()) {
|
||||
ui->lineEdit_customValue->setText(bar());
|
||||
} else {
|
||||
ui->comboBox_value->addItem(m_bar);
|
||||
ui->comboBox_value->addItem(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);
|
||||
ui->pushButton_activeColor->setText(m_activeColor);
|
||||
ui->pushButton_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);
|
||||
ui->doubleSpinBox_max->setValue(maxValue());
|
||||
ui->doubleSpinBox_min->setValue(minValue());
|
||||
ui->spinBox_count->setValue(count());
|
||||
if (m_helper->isColor(activeColor()))
|
||||
ui->comboBox_activeImageType->setCurrentIndex(0);
|
||||
else
|
||||
ui->comboBox_activeImageType->setCurrentIndex(1);
|
||||
ui->lineEdit_activeColor->setText(activeColor());
|
||||
if (m_helper->isColor(inactiveColor()))
|
||||
ui->comboBox_inactiveImageType->setCurrentIndex(0);
|
||||
else
|
||||
ui->comboBox_inactiveImageType->setCurrentIndex(1);
|
||||
ui->lineEdit_inactiveColor->setText(inactiveColor());
|
||||
ui->comboBox_type->setCurrentIndex(static_cast<int>(type()));
|
||||
ui->comboBox_direction->setCurrentIndex(static_cast<int>(direction()));
|
||||
ui->spinBox_height->setValue(itemHeight());
|
||||
ui->spinBox_width->setValue(itemWidth());
|
||||
|
||||
// update UI
|
||||
changeCountState(ui->comboBox_type->currentIndex());
|
||||
changeValue(ui->checkBox_custom->checkState());
|
||||
emit(ui->comboBox_type->currentIndexChanged(
|
||||
ui->comboBox_type->currentIndex()));
|
||||
emit(ui->checkBox_custom->stateChanged(ui->checkBox_custom->checkState()));
|
||||
|
||||
int ret = exec();
|
||||
if (ret != 1)
|
||||
@ -480,12 +511,13 @@ int GraphicalItem::showConfiguration(const QVariant args)
|
||||
: ui->comboBox_value->currentText());
|
||||
setMaxValue(ui->doubleSpinBox_max->value());
|
||||
setMinValue(ui->doubleSpinBox_min->value());
|
||||
setActiveColor(ui->pushButton_activeColor->text().remove(QChar('&')));
|
||||
setInactiveColor(ui->pushButton_inactiveColor->text().remove(QChar('&')));
|
||||
setStrType(ui->comboBox_type->currentText());
|
||||
setStrDirection(ui->comboBox_direction->currentText());
|
||||
setHeight(ui->spinBox_height->value());
|
||||
setWidth(ui->spinBox_width->value());
|
||||
setActiveColor(ui->lineEdit_activeColor->text());
|
||||
setInactiveColor(ui->lineEdit_inactiveColor->text());
|
||||
setType(static_cast<Type>(ui->comboBox_type->currentIndex()));
|
||||
setDirection(
|
||||
static_cast<Direction>(ui->comboBox_direction->currentIndex()));
|
||||
setItemHeight(ui->spinBox_height->value());
|
||||
setItemWidth(ui->spinBox_width->value());
|
||||
|
||||
writeConfiguration();
|
||||
return ret;
|
||||
@ -496,23 +528,21 @@ void GraphicalItem::writeConfiguration() const
|
||||
{
|
||||
AbstractExtItem::writeConfiguration();
|
||||
|
||||
QSettings settings(
|
||||
QString("%1/%2").arg(directories().first()).arg(fileName()),
|
||||
QSettings::IniFormat);
|
||||
QSettings settings(writtableConfig(), QSettings::IniFormat);
|
||||
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
|
||||
|
||||
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-Value"), bar());
|
||||
settings.setValue(QString("X-AW-Count"), count());
|
||||
settings.setValue(QString("X-AW-Custom"), isCustom());
|
||||
settings.setValue(QString("X-AW-Max"), maxValue());
|
||||
settings.setValue(QString("X-AW-Min"), minValue());
|
||||
settings.setValue(QString("X-AW-ActiveColor"), activeColor());
|
||||
settings.setValue(QString("X-AW-InactiveColor"), inactiveColor());
|
||||
settings.setValue(QString("X-AW-Type"), strType());
|
||||
settings.setValue(QString("X-AW-Direction"), strDirection());
|
||||
settings.setValue(QString("X-AW-Height"), m_height);
|
||||
settings.setValue(QString("X-AW-Width"), m_width);
|
||||
settings.setValue(QString("X-AW-Height"), itemHeight());
|
||||
settings.setValue(QString("X-AW-Width"), itemWidth());
|
||||
settings.endGroup();
|
||||
|
||||
settings.sync();
|
||||
@ -521,38 +551,49 @@ void GraphicalItem::writeConfiguration() const
|
||||
|
||||
void GraphicalItem::changeColor()
|
||||
{
|
||||
QColor color = m_helper->stringToColor(
|
||||
(static_cast<QPushButton *>(sender()))->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()));
|
||||
|
||||
return static_cast<QPushButton *>(sender())
|
||||
->setText(colorText.join(QChar(',')));
|
||||
}
|
||||
|
||||
|
||||
void GraphicalItem::changeColorState(const int state)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Current color state is" << state;
|
||||
|
||||
if (sender() == ui->checkBox_activeCheck) {
|
||||
qCInfo(LOG_LIB) << "Change active color state";
|
||||
ui->widget_activeColor->setHidden(state == Qt::Unchecked);
|
||||
ui->widget_activeImage->setHidden(state != Qt::Unchecked);
|
||||
} else if (sender() == ui->checkBox_inactiveCheck) {
|
||||
qCInfo(LOG_LIB) << "Change inactive color state";
|
||||
ui->widget_inactiveColor->setHidden(state == Qt::Unchecked);
|
||||
ui->widget_inactiveImage->setHidden(state != Qt::Unchecked);
|
||||
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;
|
||||
}
|
||||
return lineEdit->setText(outputColor);
|
||||
}
|
||||
|
||||
|
||||
@ -565,20 +606,6 @@ void GraphicalItem::changeCountState(const int state)
|
||||
}
|
||||
|
||||
|
||||
void GraphicalItem::changeImage()
|
||||
{
|
||||
QString path = static_cast<QPushButton *>(sender())->text();
|
||||
QString directory = QFileInfo(path).absolutePath();
|
||||
QString newPath = QFileDialog::getOpenFileName(
|
||||
this, tr("Select path"), directory,
|
||||
tr("Images (*.png *.bpm *.jpg);;All files (*.*)"));
|
||||
|
||||
qCInfo(LOG_LIB) << "Selected path" << newPath;
|
||||
|
||||
return static_cast<QPushButton *>(sender())->setText(newPath);
|
||||
}
|
||||
|
||||
|
||||
void GraphicalItem::changeValue(const int state)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Current state is" << state;
|
||||
@ -588,45 +615,28 @@ void GraphicalItem::changeValue(const int state)
|
||||
}
|
||||
|
||||
|
||||
void GraphicalItem::initScene()
|
||||
{
|
||||
// init scene
|
||||
m_scene = new QGraphicsScene();
|
||||
m_scene->setBackgroundBrush(QBrush(Qt::NoBrush));
|
||||
// init view
|
||||
m_view = new QGraphicsView(m_scene);
|
||||
m_view->setStyleSheet(QString("background: transparent"));
|
||||
m_view->setContentsMargins(0, 0, 0, 0);
|
||||
m_view->setFrameShape(QFrame::NoFrame);
|
||||
m_view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
m_view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
m_view->resize(m_width + 5, m_height + 5);
|
||||
|
||||
// init helper
|
||||
m_helper = new GraphicalItemHelper(this, m_scene);
|
||||
m_helper->setParameters(m_activeColor, m_inactiveColor, m_width, m_height,
|
||||
m_count);
|
||||
}
|
||||
|
||||
|
||||
void GraphicalItem::translate()
|
||||
{
|
||||
ui->label_name->setText(i18n("Name"));
|
||||
ui->label_comment->setText(i18n("Comment"));
|
||||
ui->label_count->setText(i18n("Points count"));
|
||||
ui->label_number->setText(i18n("Tag"));
|
||||
ui->checkBox_custom->setText(i18n("Use custom formula"));
|
||||
ui->label_value->setText(i18n("Value"));
|
||||
ui->label_customValue->setText(i18n("Value"));
|
||||
ui->label_max->setText(i18n("Max value"));
|
||||
ui->label_min->setText(i18n("Min value"));
|
||||
ui->checkBox_activeCheck->setText(i18n("Use image for active"));
|
||||
ui->label_activeColor->setText(i18n("Active color"));
|
||||
ui->label_activeImage->setText(i18n("Active image"));
|
||||
ui->checkBox_inactiveCheck->setText(i18n("Use image for inactive"));
|
||||
ui->label_inactiveColor->setText(i18n("Inactive color"));
|
||||
ui->label_inactiveImage->setText(i18n("Inactive image"));
|
||||
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"));
|
||||
}
|
||||
|
@ -40,55 +40,61 @@ class GraphicalItem : public AbstractExtItem
|
||||
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(int itemHeight READ itemHeight WRITE setItemHeight)
|
||||
Q_PROPERTY(int itemWidth READ itemWidth WRITE setItemWidth)
|
||||
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 = 0,
|
||||
Vertical = 1,
|
||||
Circle = 2,
|
||||
Graph = 3,
|
||||
Bars = 4
|
||||
};
|
||||
|
||||
explicit GraphicalItem(QWidget *parent = nullptr,
|
||||
const QString desktopName = QString(),
|
||||
const QStringList directories = QStringList());
|
||||
explicit GraphicalItem(QWidget *parent, const QString filePath = QString());
|
||||
virtual ~GraphicalItem();
|
||||
GraphicalItem *copy(const QString _fileName, const int _number);
|
||||
QString image(const QVariant &value);
|
||||
void initScene();
|
||||
// get methods
|
||||
QString bar() const;
|
||||
QString activeColor() const;
|
||||
QString inactiveColor() const;
|
||||
int count() const;
|
||||
QString inactiveColor() const;
|
||||
bool isCustom() const;
|
||||
int itemHeight() const;
|
||||
int itemWidth() 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 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("255,255,255,130"));
|
||||
void setInactiveColor(const QString _color
|
||||
= QString("color://255,255,255,130"));
|
||||
void setItemHeight(const int _height = 100);
|
||||
void setItemWidth(const int _width = 100);
|
||||
void setMinValue(const float _value = 0.0);
|
||||
void setMaxValue(const float _value = 100.0);
|
||||
void setType(const Type _type = Horizontal);
|
||||
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();
|
||||
@ -98,28 +104,25 @@ public slots:
|
||||
|
||||
private slots:
|
||||
void changeColor();
|
||||
void changeColorState(const int state);
|
||||
void changeCountState(const int state);
|
||||
void changeImage();
|
||||
void changeValue(const int state);
|
||||
|
||||
private:
|
||||
GraphicalItemHelper *m_helper = nullptr;
|
||||
QGraphicsScene *m_scene = nullptr;
|
||||
QGraphicsView *m_view = nullptr;
|
||||
Ui::GraphicalItem *ui;
|
||||
void initScene();
|
||||
Ui::GraphicalItem *ui = nullptr;
|
||||
void translate();
|
||||
// properties
|
||||
QString m_bar = QString("cpu");
|
||||
int m_count = 100;
|
||||
bool m_custom = false;
|
||||
QString m_activeColor;
|
||||
QString m_inactiveColor;
|
||||
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 = Horizontal;
|
||||
Direction m_direction = LeftToRight;
|
||||
Type m_type = Type::Horizontal;
|
||||
Direction m_direction = Direction::LeftToRight;
|
||||
int m_height = 100;
|
||||
QStringList m_usedKeys;
|
||||
int m_width = 100;
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user