Compare commits

...

83 Commits

Author SHA1 Message Date
ae4e7deddd create pkgbuild for the last stable archive in 2.4.0 branch 2015-09-09 06:57:49 +03:00
be26033ff7 edit log format line 2015-09-04 00:18:46 +03:00
70020d0aef Merge branch 'master' of github.com:arcan1s/awesome-widgets 2015-09-03 00:31:07 +03:00
7218defe19 add '$this' feature to lambda functions
fix large size on startup
fix invalid key parsing
2015-09-03 00:30:10 +03:00
200ecc7196 translation update 2015-09-02 00:19:28 +03:00
6689bea9a7 implement dynamic tags 2015-09-02 00:05:11 +03:00
5940ec4531 update awdebug 2015-09-01 01:45:25 +03:00
2716f77eb2 revert 2015-09-01 01:40:48 +03:00
cfdcaae036 drop script from deps 2015-09-01 01:40:15 +03:00
82c1839634 drop hidding method 2015-09-01 01:12:10 +03:00
08dae3b02b small patch to avoid notifications on nan 2015-08-31 01:43:39 +03:00
cc2b1b7b8a add images feature to extweather (apiver == 2) 2015-08-31 00:16:04 +03:00
4c27382467 more correct logging, use qt logging for qml as well 2015-08-30 16:24:00 +03:00
aacb50c946 start moving to qt5 style logging 2015-08-29 00:58:39 +03:00
466faf53fa some refactoring, prepare to moving to qt5 style logging 2015-08-28 00:15:25 +03:00
8228d1d06b Add filter feature to ExtUpgrade (ApiVer = 3) 2015-08-26 00:24:55 +03:00
37726370ee Add additional column to configuraion ui to better tag selection 2015-08-25 00:07:23 +03:00
07305d7578 no kf5 on ubuntu 12.04 2015-08-23 02:26:12 +03:00
b97c821c8f try to upgrade ubuntu first 2015-08-23 02:16:22 +03:00
b50c1d2363 add ability to do not translate strings 2015-08-23 02:14:55 +03:00
713aa611d9 drop travis since it uses ubuntu-12.04 2015-08-22 23:11:09 +03:00
319755179f #2 2015-08-22 22:30:52 +03:00
9509d87962 try to get it working 2015-08-22 22:27:27 +03:00
6d58a3f05c add repo 2015-08-22 14:59:44 +03:00
2cca290630 try add travis-ci 2015-08-22 14:55:50 +03:00
29b75e2b12 update additional files
update translations
add "Add lambda" button to ui
2015-08-22 00:40:14 +03:00
835eb00f0d add lambda support 2015-08-21 00:05:15 +03:00
a5e9b32b28 implement support of network speed units tags
fix warning for empty tooltip image
2015-08-18 01:17:51 +03:00
fbdc9112aa update archive generator 2015-08-16 15:48:43 +03:00
b3fc0501ba unify build, allow cross build 2015-08-16 03:24:44 +03:00
a74c65a2a3 fix typo 2015-08-16 02:41:26 +03:00
4858c9dbcd add rpm recipe 2015-08-16 02:38:24 +03:00
3601b4246d add build requirements for deb packages 2015-08-16 01:54:49 +03:00
241e13ffd8 add experimental debian build 2015-08-16 01:22:28 +03:00
7a5d2d5dd4 add forgoten line to CHANGELOG
drop default active script
2015-08-11 00:05:23 +03:00
24b143f43a release 2.4.0 2015-08-10 00:09:31 +03:00
df473c53b5 move plugins to iterators 2015-08-08 00:22:25 +03:00
3122c2fa8c rewrite to iterators library part 2015-08-07 07:21:55 +03:00
08cb7d9abe fix #60
some hash improvements
2015-08-06 01:23:43 +03:00
e38863ebc2 add disable key to player monitor 2015-08-05 01:14:09 +03:00
1cddf6f14d some map replacing 2015-08-04 00:15:19 +03:00
7405b2ba1d work with extendedsysmon
* fix mpris info getting
* replace qmap to qhash if possible
* some at()/[] repalcements
* add time logging
2015-08-03 00:01:14 +03:00
6fbe897b27 fix CMake policy setup 2015-08-02 14:24:49 +03:00
5f7c35a37c edit translations build
translation update
2015-08-02 00:40:23 +03:00
6173b60806 edit cmake files
edit font dialog
2015-08-01 00:10:18 +03:00
4c9e39ec9b translation update 2015-07-31 00:48:01 +03:00
429393998c update translations cmakelists as well 2015-07-30 00:01:13 +03:00
c9acb0bdcd edit build, create a separate cmake include file 2015-07-29 23:59:42 +03:00
16305a91c4 rewrite tooltip class 2015-07-29 00:03:12 +03:00
bbb9aa0747 fix library translations 2015-07-28 00:22:34 +03:00
983b808247 move aw plugin to template-based system
bump graphicalitems to ApiVer 2 (add number property)
2015-07-27 00:05:15 +03:00
c61a5ac092 create a static library for backend items
move backend items to template-based mechanism
2015-07-26 12:58:59 +03:00
3b6df44489 more correct methods naming, prepare to move to templates 2015-07-25 00:03:45 +03:00
4742617e3e * fix building
* add clang build
* more correct method types
2015-07-24 00:18:21 +03:00
880a986782 add abstactextitem class (building is broken atm) 2015-07-23 00:07:21 +03:00
b699095f38 initial support of weather 2015-07-22 00:44:39 +03:00
a065e96bc3 * move isDebugEnabled method to AWActions
* add "Drop key cache" button
2015-07-21 00:24:50 +03:00
1110929b14 improve update events 2015-07-20 00:21:39 +03:00
c7d998eb12 more correct fix for #57 2015-07-19 00:14:49 +03:00
eb63ef5e96 Merge branch 'key-filtering-feature' 2015-07-18 00:51:21 +03:00
327d5a7ff9 more correct fix for #57 2015-07-17 09:44:44 +03:00
2b9505207c Merge branch 'memory-load-fix' 2015-07-16 00:34:18 +03:00
cd36c4ed68 drop key definition on startup since it blocks several plasmoid
instances (refer to #57)
2015-07-15 19:50:12 +03:00
903a1a454d move plugin back to private 2015-07-15 19:49:54 +03:00
cf5d713d2e Revert "drop key definition on startup since it blocks several plasmoid"
This reverts commit 4e78e0e1dd.
2015-07-15 19:34:19 +03:00
467a3bf508 fix network speed calculation for $down and $up tags 2015-07-14 00:18:29 +03:00
4e78e0e1dd drop key definition on startup since it blocks several plasmoid
instances (refer to #57)
2015-07-11 15:04:53 +03:00
d01fb91e36 bump to 2.3.2 2015-07-09 00:28:47 +03:00
61ed3a444f change text rendering 2015-07-08 12:20:01 +03:00
494590475a release 2.3.2 2015-07-04 02:35:09 +03:00
27ab7d9cd7 fix cast int as float 2015-07-03 00:05:47 +03:00
1869a68122 fix bug with no actions
set network speed units as MB/s if the value more than 1k KB/s
2015-07-03 00:04:03 +03:00
aa0a4b417d improve battery support 2015-07-01 01:14:04 +03:00
41deb8ef72 fix plasma crash with extquotes
rewrite main widget to use signal-slot model
2015-06-30 07:13:58 +03:00
aa15e13713 update fr translations 2015-06-14 17:19:38 +03:00
ad63f78929 update links to opensuse packages 2015-06-12 15:05:56 +03:00
224e558a98 release 2.3.1 2015-06-11 01:49:22 +03:00
a391df2804 - fix bug with invalid values updates from configuration UI
* merge fan tags to temp ones for better handling
2015-06-10 10:31:41 +03:00
755d0b39f8 Merge pull request #56 from underr/master
Update PT-BR translations
2015-06-06 13:18:40 +03:00
fcd612880f Update PT-BR translations 2015-06-05 21:54:24 -03:00
5aff2d2e4e update Spain translations 2015-06-05 00:19:02 +03:00
5a52c056a7 update Ukrainian translation 2015-06-04 01:54:26 +03:00
42615a6fdc update translation, fix #53 2015-06-02 01:21:03 +03:00
141 changed files with 8436 additions and 9148 deletions

3
.gitmodules vendored
View File

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

11
.travis.yml.bckp Normal file
View File

@ -0,0 +1,11 @@
install:
- sudo apt-get update -qq
- sudo apt-get install -y cmake extra-cmake-modules g++ git libkf5i18n-dev libkf5notifications-dev libkf5service-dev libkf5windowsystem-dev plasma-framework-dev qtbase5-dev qtdeclarative5-dev
- git submobule update --init
- rm -rf build
- mkdir build
script:
- cd build
- cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Release -DKDE_INSTALL_USE_QT_SYS_PATHS=ON ../sources
- make

View File

@ -1,3 +1,45 @@
+ add tags upunits, downunits
- fix warning for empty tooltip image
Ver.2.4.0:
+ add support of weather items
+ add support of load average (la1, la5, la15 tags)
+ add "drop key cache" button
+ add support of clang building
+ create ExtItems aggregator
+ add time to debug information
+ add ability to disable player monitor
- fix bug with invalid network data calculation
- fix warning with fond dialog init
- fix bug with no object deletions (#60)
* rewrite ExtItems to use own abstract class
* improve work with data updating (#57)
* move to signal-slot interface painting
* move plugin part back to private
* cast plugin as type, not signleton (#57)
* change logic in data building inside DataEngine
* edit build and drop different DataEngine packaging
* rewrite QMap to QHash if possible
* rewrite to use iterators if possible
* list of desktops is now represented as QStringList
* refactoring
Ver.2.3.3:
* change text rendering from Qt to native
Ver.2.3.2:
+ change network speed units from KB/s to MB/s if value is more than 1000 KB/s (metrics are the same)
- fix bug with no actions on link activation (thanks to infans)
* improve quotes support, e.g. fix plasma crash
* rewrite main widget to signal-slot update model
* improve battery calculation for system which has several batteries
Ver.2.3.1:
- fix bug with no updates from configuration UI
- fix invalid vertical tab parsing
* translation update
* merge fan tags to temp ones, improve lmsensors tags handling
Ver.2.3.0:
+ implement fitlers support to ExtScripts (ApiVer = 3) (#53)
+ implement ability to wrap `\n` as new lines (#53)
@ -21,7 +63,7 @@ Ver.2.2.2:
- fix bug with GPUDEV, HDDDEV settings saving from UI
- fix Desktop Panel settings
- fix bug with adding paragraph settings
* drop support of KDE4 support, created a separate branch
* drop support of KDE4 support, created a separated branch
* increase intervals limits (#48)
* hddtemp was replaced to smartctl by default
* plugins were moved from private

View File

@ -1,3 +1,42 @@
Вер.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)

View File

@ -35,7 +35,7 @@ Optional dependencies
* proprietary video driver
* hddtemp
* smartmontools
* music player (mpd or supported MPRIS)
* music player (mpd or MPRIS supported)
Make dependencies
-----------------
@ -53,7 +53,7 @@ Installation
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr ../
make && sudo make install
**NOTE** on Plasma 5 it may require `-DKDE_INSTALL_USE_QT_SYS_PATHS=ON` flag
**NOTE** on Plasma 5 it very likely requires `-DKDE_INSTALL_USE_QT_SYS_PATHS=ON` flag
Additional information
======================
@ -72,4 +72,4 @@ Links
* Plasmoid on [kde-look](http://kde-look.org/content/show.php/Awesome+Widgets?content=157124)
* DataEngine on [kde-look](http://kde-look.org/content/show.php/Extended+Systemmonitor+DataEngine?content=158773)
* Archlinux [AUR](https://aur.archlinux.org/packages/plasma5-applet-awesome-widgets/) package
* [OpenSuse](http://software.opensuse.org/package/awesome-widgets) package
* [OpenSuse](http://software.opensuse.org/search?q=awesome-widgets) packages, [KF5 OpenSuse](http://software.opensuse.org/package/plasma5-awesome-widgets) package

View File

@ -1,43 +0,0 @@
# Maintainer: Evgeniy Alekseev <arcanis at archlinux dot org>
pkgname=plasma5-applet-awesome-widgets
_pkgname=awesome-widgets
pkgver=2.3.0
pkgrel=1
pkgdesc="Collection of minimalistic Plasmoids which look like Awesome WM widgets (ex-PyTextMonitor)"
arch=('i686' 'x86_64')
url="http://arcanis.name/projects/awesome-widgets"
license=('GPL3')
depends=('plasma-framework')
optdepends=("amarok: for music player monitor"
"clementine: for music player monitor"
"catalyst: for GPU monitor"
"hddtemp: for HDD temperature monitor"
"smartmontools: for HDD temperature monitor"
"mpd: for music player monitor"
"nvidia-utils: for GPU monitor"
"qmmp: for music player monitor")
makedepends=('cmake' 'extra-cmake-modules')
source=(https://github.com/arcan1s/awesome-widgets/releases/download/V.${pkgver}/${_pkgname}-${pkgver}-src.tar.xz)
install=${pkgname}.install
md5sums=('3c79159d6de7b737d386d8ab7eb1ccf0')
backup=('etc/xdg/plasma-dataengine-extsysmon.conf')
prepare() {
rm -rf "${srcdir}/build"
mkdir "${srcdir}/build"
}
build () {
cd "${srcdir}/build"
cmake -DKDE_INSTALL_USE_QT_SYS_PATHS=ON \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/usr \
"../${_pkgname}"
make
}
package() {
cd "${srcdir}/build"
make DESTDIR="${pkgdir}" install
}

View File

@ -1,23 +1,14 @@
#!/bin/bash
SRCDIR="sources"
MAJOR=$(grep -m1 PROJECT_VERSION_MAJOR sources/CMakeLists.txt | awk '{print $3}' | sed 's/.$//g')
MINOR=$(grep -m1 PROJECT_VERSION_MINOR sources/CMakeLists.txt | awk '{print $3}' | sed 's/.$//g')
PATCH=$(grep -m1 PROJECT_VERSION_PATCH sources/CMakeLists.txt | awk '{print $3}' | sed 's/.$//g')
MAJOR=$(grep -m1 PROJECT_VERSION_MAJOR sources/CMakeLists.txt | awk '{print $2}' | sed 's/^.\(.*\)..$/\1/')
MINOR=$(grep -m1 PROJECT_VERSION_MINOR sources/CMakeLists.txt | awk '{print $2}' | sed 's/^.\(.*\)..$/\1/')
PATCH=$(grep -m1 PROJECT_VERSION_PATCH sources/CMakeLists.txt | awk '{print $2}' | sed 's/^.\(.*\)..$/\1/')
VERSION="${MAJOR}.${MINOR}.${PATCH}"
# update submodules
git submodule update --init --recursive
# build dataengine
ARCHIVE="extsysmon"
# create archive
[[ -e ${ARCHIVE}-${VERSION}-src.tar.xz ]] && rm -f ${ARCHIVE}-${VERSION}-src.tar.xz
[[ -d ${ARCHIVE} ]] && rm -rf "${ARCHIVE}"
cp -r "${SRCDIR}/${ARCHIVE}" "${ARCHIVE}"
tar cJf "${ARCHIVE}-${VERSION}-src.tar.xz" "${ARCHIVE}"
rm -rf "${ARCHIVE}"
# build widget
ARCHIVE="awesome-widgets"
FILES="AUTHORS CHANGELOG CHANGELOG-RU COPYING"
@ -29,13 +20,13 @@ cp -r "${SRCDIR}" "${ARCHIVE}"
for FILE in ${FILES[*]}; do cp -r "$FILE" "${ARCHIVE}"; done
for FILE in ${IGNORELIST[*]}; do rm -rf "${ARCHIVE}/${FILE}"; done
tar cJf "${ARCHIVE}-${VERSION}-src.tar.xz" "${ARCHIVE}"
ln -sf "../${ARCHIVE}-${VERSION}-src.tar.xz" arch
ln -sf "../${ARCHIVE}-${VERSION}-src.tar.xz" packages
rm -rf "${ARCHIVE}"
# update md5sum
MD5SUMS=$(md5sum ${ARCHIVE}-${VERSION}-src.tar.xz | awk '{print $1}')
sed -i "/md5sums=('[0-9A-Fa-f]*/s/[^'][^)]*/md5sums=('${MD5SUMS}'/" arch/PKGBUILD
sed -i "s/pkgver=[0-9.]*/pkgver=${VERSION}/" arch/PKGBUILD
sed -i "/md5sums=('[0-9A-Fa-f]*/s/[^'][^)]*/md5sums=('${MD5SUMS}'/" packages/PKGBUILD
sed -i "s/pkgver=[0-9.]*/pkgver=${VERSION}/" packages/PKGBUILD
# clear
find . -type f -name '*src.tar.xz' -not -name "*${VERSION}-src.tar.xz" -exec rm -rf {} \;
find arch -type l -xtype l -exec rm -rf {} \;
find packages -type l -xtype l -exec rm -rf {} \;

View File

@ -2,7 +2,7 @@
pkgname=plasma5-applet-awesome-widgets
_pkgname=awesome-widgets
pkgver=2.2.1.r15.g78931b3
pkgver=2.4.0.r34.gbe26033
pkgrel=1
pkgdesc="Collection of minimalistic Plasmoids which look like Awesome WM widgets (ex-PyTextMonitor). Git version"
arch=('i686' 'x86_64')
@ -17,8 +17,8 @@ optdepends=("amarok: for music player monitor"
"mpd: for music player monitor"
"nvidia-utils: for GPU monitor"
"qmmp: for music player monitor")
makedepends=('cmake' 'extra-cmake-modules')
source=(${_pkgname}::git+https://github.com/arcan1s/awesome-widgets/)
makedepends=('cmake' 'extra-cmake-modules' 'git')
source=(${_pkgname}::git+https://github.com/arcan1s/awesome-widgets.git#branch=release-2.4.0)
install=${pkgname}.install
md5sums=('SKIP')
backup=('etc/xdg/plasma-dataengine-extsysmon.conf')

View File

@ -0,0 +1,11 @@
cmake
extra-cmake-modules
g++
git
libkf5i18n-dev
libkf5notifications-dev
libkf5service-dev
libkf5windowsystem-dev
plasma-framework-dev
qtbase5-dev
qtdeclarative5-dev

View File

View File

@ -19,5 +19,8 @@ Name=GCC
Path=gcc
Type=GCC
[Launch]
Launch Configurations=
[Project]
VersionControlSupport=kdevgit

Submodule sources/3rdparty/pdebug deleted from 294a590bb9

View File

@ -0,0 +1,18 @@
#include "qreplytimeout.h"
#include <QTimer>
QReplyTimeout::QReplyTimeout(QNetworkReply *reply, const int timeout)
: QObject(reply)
{
QTimer::singleShot(timeout, this, SLOT(timeout()));
}
void QReplyTimeout::timeout()
{
QNetworkReply *reply = static_cast<QNetworkReply *>(parent());
if (reply->isRunning())
reply->close();
}

View File

@ -0,0 +1,17 @@
// from here http://codereview.stackexchange.com/questions/30031/qnetworkreply-network-reply-timeout-helper
// no license provided
#include <QNetworkReply>
#include <QObject>
class QReplyTimeout : public QObject
{
Q_OBJECT
public:
explicit QReplyTimeout(QNetworkReply *reply, const int timeout);
public slots:
void timeout();
};

View File

@ -1,46 +1,67 @@
cmake_minimum_required (VERSION 2.8.12)
cmake_minimum_required(VERSION 2.8.12)
cmake_policy (SET CMP0003 OLD)
cmake_policy (SET CMP0002 OLD)
cmake_policy (SET CMP0011 NEW)
cmake_policy (SET CMP0015 NEW)
# some fucking magic
cmake_policy(SET CMP0003 OLD)
cmake_policy(SET CMP0002 OLD)
cmake_policy(SET CMP0011 NEW)
cmake_policy(SET CMP0015 NEW)
if (POLICY CMP0063)
cmake_policy(SET CMP0063 OLD)
endif()
project (awesomewidgets)
set (PROJECT_AUTHOR "Evgeniy Alekseev")
set (PROJECT_CONTACT "esalexeev@gmail.com")
set (PROJECT_LICENSE "GPLv3")
set (PROJECT_VERSION_MAJOR 2)
set (PROJECT_VERSION_MINOR 3)
set (PROJECT_VERSION_PATCH 0)
set (PROJECT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH})
project(awesomewidgets)
set(PROJECT_AUTHOR "Evgeniy Alekseev")
set(PROJECT_CONTACT "esalexeev@gmail.com")
set(PROJECT_LICENSE "GPL3")
set(PROJECT_VERSION_MAJOR "2")
set(PROJECT_VERSION_MINOR "4")
set(PROJECT_VERSION_PATCH "0")
set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
string (TIMESTAMP CURRENT_DATE "%Y-%m-%d %H:%M" UTC)
string (TIMESTAMP CURRENT_YEAR "%Y")
string(TIMESTAMP CURRENT_DATE "%Y-%m-%d %H:%M" UTC)
string(TIMESTAMP CURRENT_YEAR "%Y")
message (STATUS "Project: ${PROJECT_NAME}")
message (STATUS "Version: ${PROJECT_VERSION}")
message (STATUS "Build date: ${CURRENT_DATE}")
message(STATUS "Project: ${PROJECT_NAME}")
message(STATUS "Version: ${PROJECT_VERSION}")
message(STATUS "Build date: ${CURRENT_DATE}")
option(BUILD_PLASMOIDS "Build plasmoids" ON)
option(BUILD_DEB_PACKAGE "Build deb package" OFF)
option(BUILD_RPM_PACKAGE "Build rpm package" OFF)
# flags
if (CMAKE_COMPILER_IS_GNUCXX)
set (CMAKE_CXX_FLAGS "-Wall -Wno-cpp -std=c++11")
set (CMAKE_CXX_FLAGS_DEBUG "-g -O0")
set (CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
# avoid newer gcc warnings
add_definitions (-D_DEFAULT_SOURCE)
else ()
message (STATUS "Unknown compiler")
endif ()
if (CMAKE_BUILD_TYPE MATCHES Debug)
set (CMAKE_VERBOSE_MAKEFILE ON)
endif ()
if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "-Wall -Wno-cpp -std=c++11")
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
# avoid newer gcc warnings
add_definitions(-D_DEFAULT_SOURCE)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_CXX_FLAGS "-Wall -std=c++11 -stdlib=libc++")
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
# linker flags
set(CMAKE_EXE_LINKER_FLAGS "-lc++abi")
set(CMAKE_MODULE_LINKER_FLAGS "-lc++abi")
set(CMAKE_SHARED_LINKER_FLAGS "-lc++abi")
else()
message(FATAL_ERROR "Unknown compiler")
endif()
if(CMAKE_BUILD_TYPE MATCHES Debug)
set(CMAKE_VERBOSE_MAKEFILE ON)
endif()
configure_file (${CMAKE_SOURCE_DIR}/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/version.h)
set (PROJECT_TRDPARTY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty)
configure_file(${CMAKE_SOURCE_DIR}/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/version.h)
set(PROJECT_TRDPARTY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty)
set(PROJECT_LIBRARY awesomewidgets)
include(libraries.cmake)
add_subdirectory (extsysmon)
add_subdirectory (awesome-widget)
add_subdirectory (desktop-panel)
add_subdirectory(awesomewidgets)
add_subdirectory(extsysmon)
if(BUILD_PLASMOIDS)
add_subdirectory(awesome-widget)
add_subdirectory(desktop-panel)
add_subdirectory(translations)
endif()
# translations
add_subdirectory (translations)
include(packages-recipe.cmake)

25
sources/awdebug.cpp Normal file
View File

@ -0,0 +1,25 @@
/***************************************************************************
* 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 "awdebug.h"
Q_LOGGING_CATEGORY(LOG_AW, "org.kde.plasma.awesomewidget", QtMsgType::QtWarningMsg)
Q_LOGGING_CATEGORY(LOG_DP, "org.kde.plasma.desktoppanel", QtMsgType::QtWarningMsg)
Q_LOGGING_CATEGORY(LOG_ESM, "org.kde.plasma.extsysmon", QtMsgType::QtWarningMsg)
Q_LOGGING_CATEGORY(LOG_LIB, "org.kde.plasma.awesomewidgets", QtMsgType::QtWarningMsg)

45
sources/awdebug.h Normal file
View File

@ -0,0 +1,45 @@
/***************************************************************************
* 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 AWDEBUG_H
#define AWDEBUG_H
#include <QLoggingCategory>
#ifndef LOG_FORMAT
#define LOG_FORMAT "[%{time yyyy-MM-ddTHH:mm:ss.zzz}][%{if-debug}DD%{endif}%{if-info}II%{endif}%{if-warning}WW%{endif}%{if-critical}CC%{endif}%{if-fatal}FF%{endif}][%{category}][%{function}] %{message}"
#endif /* LOG_FORMAT */
// define info log level
// #if QT_VERSION < QT_VERSION_CHECK(5, 5, 0)
// #ifndef qCInfo
// redefine info because it doesn't log properly
#ifdef qCInfo
#undef qCInfo
#endif /* qCInfo */
#define qCInfo qCDebug
// #endif /* QT_VERSION */
Q_DECLARE_LOGGING_CATEGORY(LOG_AW)
Q_DECLARE_LOGGING_CATEGORY(LOG_DP)
Q_DECLARE_LOGGING_CATEGORY(LOG_ESM)
Q_DECLARE_LOGGING_CATEGORY(LOG_LIB)
#endif /* AWDEBUG_H */

View File

@ -1,19 +1,7 @@
# set project name
set (SUBPROJECT plasma_applet_awesome-widget)
message (STATUS "Subproject ${SUBPROJECT}")
set(SUBPROJECT plasma_applet_awesome-widget)
message(STATUS "Subproject ${SUBPROJECT}")
# prepare
configure_file (metadata.desktop ${CMAKE_CURRENT_SOURCE_DIR}/package/metadata.desktop)
configure_file(metadata.desktop ${CMAKE_CURRENT_SOURCE_DIR}/package/metadata.desktop)
find_package (ECM 0.0.12 REQUIRED NO_MODULE)
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR})
find_package (Qt5 REQUIRED COMPONENTS Core Network Qml)
find_package (KF5 REQUIRED COMPONENTS I18n Notifications Plasma)
include (KDEInstallDirs)
include (KDECMakeSettings)
include (KDECompilerSettings)
add_subdirectory (plugin)
plasma_install_package (package org.kde.plasma.awesomewidget)
add_subdirectory(plugin)
plasma_install_package(package org.kde.plasma.awesomewidget)

View File

@ -47,6 +47,9 @@
<entry name="checkUpdates" type="bool">
<default>true</default>
</entry>
<entry name="translateStrings" type="bool">
<default>true</default>
</entry>
</group>
<group name="Tooltip">

View File

@ -19,17 +19,21 @@ import QtQuick 2.0
import QtQuick.Controls 1.3 as QtControls
import QtQuick.Layouts 1.0 as QtLayouts
import org.kde.plasma.awesomewidget 1.0
import org.kde.plasma.private.awesomewidget 1.0
Item {
id: aboutPage
AWActions {
id: awActions;
}
width: childrenRect.width
height: childrenRect.height
implicitWidth: pageColumn.implicitWidth
implicitHeight: pageColumn.implicitHeight
property bool debug: AWKeys.isDebugEnabled()
property bool debug: awActions.isDebugEnabled()
Column {
@ -45,26 +49,27 @@ Item {
QtControls.Label {
QtLayouts.Layout.fillWidth: true
horizontalAlignment: Text.AlignHCenter
text: AWActions.getAboutText("header")
text: awActions.getAboutText("header")
}
QtControls.Label {
QtLayouts.Layout.fillWidth: true
horizontalAlignment: Text.AlignHCenter
text: AWActions.getAboutText("version")
text: awActions.getAboutText("version")
}
QtControls.Label {
QtLayouts.Layout.fillWidth: true
horizontalAlignment: Text.AlignJustify
text: AWActions.getAboutText("description")
text: awActions.getAboutText("description")
}
QtControls.Label {
QtLayouts.Layout.fillWidth: true
horizontalAlignment: Text.AlignLeft
textFormat: Text.RichText
text: AWActions.getAboutText("links")
text: awActions.getAboutText("links")
onLinkActivated: Qt.openUrlExternally(link);
}
QtControls.Label {
@ -74,7 +79,7 @@ Item {
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignBottom
textFormat: Text.RichText
text: AWActions.getAboutText("copy")
text: awActions.getAboutText("copy")
}
}
}
@ -87,7 +92,7 @@ Item {
QtLayouts.Layout.fillWidth: true
wrapMode: Text.WordWrap
horizontalAlignment: Text.AlignJustify
text: AWActions.getAboutText("translators")
text: awActions.getAboutText("translators")
}
QtControls.Label {
@ -96,7 +101,8 @@ Item {
horizontalAlignment: Text.AlignJustify
verticalAlignment: Text.AlignTop
textFormat: Text.RichText
text: AWActions.getAboutText("3rdparty")
text: awActions.getAboutText("3rdparty")
onLinkActivated: Qt.openUrlExternally(link);
}
}
}
@ -104,6 +110,6 @@ Item {
}
Component.onCompleted: {
if (debug) console.log("[about::onCompleted]")
if (debug) console.debug()
}
}

View File

@ -18,17 +18,22 @@
import QtQuick 2.0
import QtQuick.Controls 1.3 as QtControls
import org.kde.plasma.awesomewidget 1.0
import org.kde.plasma.private.awesomewidget 1.0
Item {
id: advancedPage
// backend
AWActions {
id: awActions;
}
width: childrenRect.width
height: childrenRect.height
implicitWidth: pageColumn.implicitWidth
implicitHeight: pageColumn.implicitHeight
property bool debug: AWKeys.isDebugEnabled()
property bool debug: awActions.isDebugEnabled()
property alias cfg_height: widgetHeight.value
property alias cfg_width: widgetWidth.value
@ -40,6 +45,8 @@ Item {
property string cfg_tempUnits: tempUnits.currentText
property alias cfg_acOnline: acOnline.text
property alias cfg_acOffline: acOffline.text
property alias cfg_checkUpdates: updates.checked
property alias cfg_translateStrings: translate.checked
Column {
@ -207,8 +214,10 @@ Item {
]
onCurrentIndexChanged: cfg_tempUnits = model[currentIndex]["name"]
Component.onCompleted: {
if (debug) console.debug()
for (var i = 0; i < model.length; i++) {
if (model[i]["name"] == plasmoid.configuration.tempUnits) {
if (debug) console.info("Found", model[i]["name"], "on", i)
tempUnits.currentIndex = i;
}
}
@ -249,9 +258,52 @@ Item {
text: plasmoid.configuration.acOffline
}
}
Row {
height: implicitHeight
width: parent.width
QtControls.Label {
height: parent.heigth
width: parent.width * 2 / 5
}
QtControls.CheckBox {
id: updates
width: parent.width * 3 / 5
text: i18n("Check updates on startup")
}
}
Row {
height: implicitHeight
width: parent.width
QtControls.Label {
height: parent.heigth
width: parent.width * 2 / 5
}
QtControls.CheckBox {
id: translate
width: parent.width * 3 / 5
text: i18n("Translate strings")
}
}
Row {
height: implicitHeight
width: parent.width
QtControls.Label {
height: parent.height
width: parent.width * 2 / 5
}
QtControls.Button {
id: selectFont
width: parent.width * 3 / 5
text: i18n("Drop key cache")
onClicked: awActions.dropCache()
}
}
}
Component.onCompleted: {
if (debug) console.log("[advanced::onCompleted]")
if (debug) console.debug()
}
}

View File

@ -20,17 +20,22 @@ import QtQuick.Controls 1.3 as QtControls
import QtQuick.Controls.Styles 1.3 as QtStyles
import QtQuick.Dialogs 1.1 as QtDialogs
import org.kde.plasma.awesomewidget 1.0
import org.kde.plasma.private.awesomewidget 1.0
Item {
id: appearancePage
// backend
AWActions {
id: awActions;
}
width: childrenRect.width
height: childrenRect.height
implicitWidth: pageColumn.implicitWidth
implicitHeight: pageColumn.implicitHeight
property bool debug: AWKeys.isDebugEnabled()
property bool debug: awActions.isDebugEnabled()
property variant weight: {
25: 0,
50: 1,
@ -84,7 +89,11 @@ Item {
id: selectFont
width: parent.width * 2 / 3
text: plasmoid.configuration.fontFamily
onClicked: fontDialog.visible = true
onClicked: {
if (debug) console.debug()
fontDialog.setFont()
fontDialog.visible = true
}
}
}
@ -146,8 +155,10 @@ Item {
]
onCurrentIndexChanged: cfg_fontWeight = model[currentIndex]["name"]
Component.onCompleted: {
if (debug) console.debug()
for (var i = 0; i < model.length; i++) {
if (model[i]["name"] == plasmoid.configuration.fontWeight) {
if (debug) console.info("Found", model[i]["name"], "on", i)
fontWeight.currentIndex = i;
}
}
@ -181,8 +192,10 @@ Item {
]
onCurrentIndexChanged: cfg_fontStyle = model[currentIndex]["name"]
Component.onCompleted: {
if (debug) console.debug()
for (var i = 0; i < model.length; i++) {
if (model[i]["name"] == plasmoid.configuration.fontStyle) {
if (debug) console.info("Found", model[i]["name"], "on", i)
fontStyle.currentIndex = i;
}
}
@ -224,16 +237,27 @@ Item {
QtDialogs.FontDialog {
id: fontDialog
title: i18n("Select a font")
font: Qt.font({ family: selectFont.text, pointSize: fontSize.value, weight: Font.Normal })
signal setFont
onAccepted: {
if (debug) console.debug()
selectFont.text = fontDialog.font.family
fontSize.value = fontDialog.font.pointSize
fontStyle.currentIndex = fontDialog.font.italic ? 1 : 0
fontWeight.currentIndex = weight[fontDialog.font.weight]
}
onSetFont: {
if (debug) console.debug()
fontDialog.font = Qt.font({
family: selectFont.text,
pointSize: fontSize.value > 0 ? fontSize.value : 12,
italic: fontStyle.currentIndex == 1,
weight: Font.Normal,
})
}
}
Component.onCompleted: {
if (debug) console.log("[appearance::onCompleted]")
if (debug) console.debug()
}
}

View File

@ -21,39 +21,27 @@ import QtQuick.Dialogs 1.1 as QtDialogs
import QtQuick.Layouts 1.0 as QtLayouts
import QtQuick.Controls.Styles 1.3 as QtStyles
import org.kde.plasma.awesomewidget 1.0
import org.kde.plasma.private.awesomewidget 1.0
Item {
id: dataenginePage
// backend
AWKeys {
id: awKeys;
}
AWActions {
id: awActions;
}
width: childrenRect.width
height: childrenRect.height
implicitWidth: pageColumn.implicitWidth
implicitHeight: pageColumn.implicitHeight
property bool debug: AWKeys.isDebugEnabled()
property variant tooltipSettings: {
"tooltipNumber": plasmoid.configuration.tooltipNumber,
"useTooltipBackground": plasmoid.configuration.useTooltipBackground,
"tooltipBackgroung": plasmoid.configuration.tooltipBackgroung,
"cpuTooltip": plasmoid.configuration.cpuTooltip,
"cpuclTooltip": plasmoid.configuration.cpuclTooltip,
"memTooltip": plasmoid.configuration.memTooltip,
"swapTooltip": plasmoid.configuration.swapTooltip,
"downTooltip": plasmoid.configuration.downTooltip,
"upTooltip": plasmoid.configuration.downTooltip,
"batTooltip": plasmoid.configuration.batTooltip,
"cpuTooltipColor": plasmoid.configuration.cpuTooltipColor,
"cpuclTooltipColor": plasmoid.configuration.cpuclTooltipColor,
"memTooltipColor": plasmoid.configuration.memTooltipColor,
"swapTooltipColor": plasmoid.configuration.swapTooltipColor,
"downTooltipColor": plasmoid.configuration.downTooltipColor,
"upTooltipColor": plasmoid.configuration.upTooltipColor,
"batTooltipColor": plasmoid.configuration.batTooltipColor,
"batInTooltipColor": plasmoid.configuration.batInTooltipColor
}
property bool debug: awActions.isDebugEnabled()
property variant cfg_dataengine: AWActions.readDataEngineConfiguration()
property variant cfg_dataengine: awActions.readDataEngineConfiguration()
Column {
id: pageColumn
@ -71,23 +59,7 @@ Item {
QtControls.TextField {
width: parent.width * 3 / 5
text: cfg_dataengine["ACPIPATH"]
}
}
Row {
height: implicitHeight
width: parent.width
QtControls.Label {
height: parent.height
width: parent.width * 2 / 5
horizontalAlignment: Text.AlignRight
verticalAlignment: Text.AlignVCenter
text: i18n("Custom scripts")
}
QtControls.Button {
width: parent.width * 3 / 5
text: i18n("Edit scripts")
onClicked: AWKeys.editItem("extscript")
onEditingFinished: cfg_dataengine["ACPIPATH"] = text
}
}
@ -106,8 +78,10 @@ Item {
width: parent.width * 3 / 5
model: ["auto", "disable", "ati", "nvidia"]
Component.onCompleted: {
if (debug) console.debug()
for (var i=0; i<model.length; i++) {
if (model[i] == cfg_dataengine["GPUDEV"]) {
if (debug) console.info("Found", model[i], "on", i)
currentIndex = i;
}
}
@ -128,10 +102,12 @@ Item {
QtControls.ComboBox {
id: hdd
width: parent.width * 3 / 5
model: AWKeys.getHddDevices(true)
model: awKeys.getHddDevices(true)
Component.onCompleted: {
if (debug) console.debug()
for (var i=0; i<model.length; i++) {
if (model[i] == cfg_dataengine["HDDDEV"]) {
if (debug) console.info("Found", model[i], "on", i)
hdd.currentIndex = i;
}
}
@ -152,6 +128,7 @@ Item {
QtControls.TextField {
width: parent.width * 3 / 5
text: cfg_dataengine["HDDTEMPCMD"]
onEditingFinished: cfg_dataengine["HDDTEMPCMD"] = text
}
}
@ -168,6 +145,7 @@ Item {
QtControls.TextField {
width: parent.width * 3 / 5
text: cfg_dataengine["MPDADDRESS"]
onEditingFinished: cfg_dataengine["MPDADDRESS"] = text
}
}
@ -187,6 +165,7 @@ Item {
maximumValue: 65535
stepSize: 1
value: cfg_dataengine["MPDPORT"]
onEditingFinished: cfg_dataengine["MPDPORT"] = value
}
}
@ -223,10 +202,12 @@ Item {
QtControls.ComboBox {
id: player
width: parent.width * 3 / 5
model: ["mpris", "mpd"]
model: ["disable", "mpris", "mpd"]
Component.onCompleted: {
if (debug) console.debug()
for (var i=0; i<model.length; i++) {
if (model[i] == cfg_dataengine["PLAYER"]) {
if (debug) console.info("Found", model[i], "on", i)
player.currentIndex = i;
}
}
@ -234,6 +215,43 @@ Item {
}
}
Row {
height: implicitHeight
width: parent.width
QtControls.Label {
height: parent.height
width: parent.width * 2 / 5
horizontalAlignment: Text.AlignRight
verticalAlignment: Text.AlignVCenter
text: i18n("Player data symbols")
}
QtControls.SpinBox {
width: parent.width * 3 / 5
minimumValue: 1
maximumValue: 100
stepSize: 1
value: cfg_dataengine["PLAYERSYMBOLS"]
onEditingFinished: cfg_dataengine["PLAYERSYMBOLS"] = value
}
}
Row {
height: implicitHeight
width: parent.width
QtControls.Label {
height: parent.height
width: parent.width * 2 / 5
horizontalAlignment: Text.AlignRight
verticalAlignment: Text.AlignVCenter
text: i18n("Custom scripts")
}
QtControls.Button {
width: parent.width * 3 / 5
text: i18n("Edit scripts")
onClicked: awKeys.editItem("extscript")
}
}
Row {
height: implicitHeight
width: parent.width
@ -247,7 +265,7 @@ Item {
QtControls.Button {
width: parent.width * 3 / 5
text: i18n("Edit tickers")
onClicked: AWKeys.editItem("extquotes")
onClicked: awKeys.editItem("extquotes")
}
}
@ -264,25 +282,42 @@ Item {
QtControls.Button {
width: parent.width * 3 / 5
text: i18n("Edit command")
onClicked: AWKeys.editItem("extupgrade")
onClicked: awKeys.editItem("extupgrade")
}
}
Row {
height: implicitHeight
width: parent.width
QtControls.Label {
height: parent.height
width: parent.width * 2 / 5
horizontalAlignment: Text.AlignRight
verticalAlignment: Text.AlignVCenter
text: i18n("Weather")
}
QtControls.Button {
width: parent.width * 3 / 5
text: i18n("Edit weather")
onClicked: awKeys.editItem("extweather")
}
}
}
Component.onCompleted: {
if (debug) console.log("[dataengine::onCompleted]")
if (debug) console.debug()
// init submodule
AWKeys.initKeys(plasmoid.configuration.text)
awKeys.initKeys(plasmoid.configuration.text)
}
Component.onDestruction: {
if (debug) console.log("[dataengine::onDestruction]")
if (debug) console.debug()
cfg_dataengine["GPUDEV"] = gpuDev.currentText
cfg_dataengine["HDDDEV"] = hdd.currentText
cfg_dataengine["PLAYER"] = player.currentText
cfg_dataengine["MPRIS"] = mpris.currentText
AWActions.writeDataEngineConfiguration(cfg_dataengine)
awActions.writeDataEngineConfiguration(cfg_dataengine)
}
}

View File

@ -22,14 +22,21 @@ import org.kde.plasma.plasmoid 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.plasma.awesomewidget 1.0
import org.kde.plasma.private.awesomewidget 1.0
import "."
Item {
id: main
// backend
AWKeys {
id: awKeys;
}
AWActions {
id: awActions;
}
property bool debug: AWKeys.isDebugEnabled()
property bool debug: awActions.isDebugEnabled()
property variant settings: {
"customTime": plasmoid.configuration.customTime,
"customUptime": plasmoid.configuration.customUptime,
@ -55,10 +62,14 @@ Item {
"downTooltipColor": plasmoid.configuration.downTooltipColor,
"upTooltipColor": plasmoid.configuration.upTooltipColor,
"batTooltipColor": plasmoid.configuration.batTooltipColor,
"batInTooltipColor": plasmoid.configuration.batInTooltipColor
"batInTooltipColor": plasmoid.configuration.batInTooltipColor,
// additinal field to parse AC status
"acOnline": plasmoid.configuration.acOnline
}
signal needUpdate
signal dropSource(string sourceName)
signal needTextUpdate(string newText)
signal needToolTipUpdate(string newText)
signal sizeUpdate
@ -81,17 +92,16 @@ Item {
interval: plasmoid.configuration.interval
onNewData: {
if (debug) console.log("[main::onNewData] : Update source " + sourceName)
// FIXME: ugly workaround to make some sources working
if (debug) console.debug("Update source", sourceName)
systemmonitorDE.interval = plasmoid.configuration.interval
if (AWKeys.setDataBySource(sourceName, data, settings)) disconnectSource(sourceName)
awKeys.setDataBySource(sourceName, data, settings)
}
onSourceAdded: {
if (debug) console.log("[main::onSourceAdded] : Source " + source)
if (debug) console.debug("Source", source)
AWKeys.addDevice(source)
awKeys.addDevice(source)
}
}
@ -102,11 +112,10 @@ Item {
interval: plasmoid.configuration.interval
onNewData: {
if (debug) console.log("[main::onNewData] : Update source " + sourceName)
// FIXME: ugly workaround to make some sources working
if (debug) console.debug("Update source", sourceName)
extsysmonDE.interval = plasmoid.configuration.interval
if (AWKeys.setDataBySource(sourceName, data, settings)) needUpdate()
awKeys.setDataBySource(sourceName, data, settings)
}
}
@ -117,9 +126,9 @@ Item {
interval: 1000
onNewData: {
if (debug) console.log("[main::onNewData] : Update source " + sourceName)
if (debug) console.debug("Update source", sourceName)
AWKeys.setDataBySource(sourceName, data, settings)
awKeys.setDataBySource(sourceName, data, settings)
}
}
@ -128,6 +137,7 @@ Item {
Text {
id: text
anchors.fill: parent
renderType: Text.NativeRendering
textFormat: Text.RichText
wrapMode: Text.NoWrap
@ -140,8 +150,6 @@ Item {
font.pointSize: plasmoid.configuration.fontSize
font.weight: general.fontWeight[plasmoid.configuration.fontWeight]
text: plasmoid.configuration.text
PlasmaCore.ToolTipArea {
height: tooltip.height
width: tooltip.width
@ -155,7 +163,7 @@ Item {
}
Component.onCompleted: {
if (debug) console.log("[main::onCompleted]")
if (debug) console.debug()
// actions
plasmoid.setAction("requestKey", i18n("Request key"), "utilities-system-monitor")
@ -164,29 +172,48 @@ Item {
// plasmoid.setAction("report", i18n("Mail to developers"), "email")
// init submodule
Plasmoid.userConfiguringChanged(false)
// connect data
awKeys.dropSourceFromDataengine.connect(dropSource)
awKeys.needTextToBeUpdated.connect(needTextUpdate)
awKeys.needToolTipToBeUpdated.connect(needToolTipUpdate)
// check updates if required
if (plasmoid.configuration.checkUpdates) return action_checkUpdates()
}
onNeedUpdate: {
if (debug) console.log("[main::onNeedUpdate]")
onDropSource: {
if (debug) console.debug()
if (debug) console.debug("Source", sourceName)
text.text = AWKeys.parsePattern()
tooltip.text = AWKeys.toolTipImage()
systemmonitorDE.disconnectSource(sourceName)
}
onNeedTextUpdate: {
if (debug) console.debug()
text.text = newText
sizeUpdate()
}
onNeedToolTipUpdate: {
if (debug) console.debug()
tooltip.text = newText
}
onSizeUpdate: {
if (debug) console.log("[main::onSizeUpdate]")
if (debug) console.debug()
// 16 is a magic number
// in other case plasmoid will increase own size on each update
if (plasmoid.configuration.height == 0) {
Layout.minimumHeight = text.contentHeight
Layout.minimumHeight = text.contentHeight - 16
Layout.maximumHeight = -1
} else {
Layout.minimumHeight = plasmoid.configuration.height
Layout.maximumHeight = plasmoid.configuration.height
}
if (plasmoid.configuration.width == 0) {
Layout.minimumWidth = text.contentWidth
Layout.minimumWidth = text.contentWidth - 16
Layout.maximumWidth = -1
} else {
Layout.minimumWidth = plasmoid.configuration.width
@ -196,38 +223,37 @@ Item {
Plasmoid.onUserConfiguringChanged: {
if (plasmoid.userConfiguring) return
if (debug) console.log("[main::onUserConfiguringChanged]")
if (debug) console.debug()
// init submodule
AWKeys.initKeys(plasmoid.configuration.text)
AWKeys.initTooltip(tooltipSettings)
AWKeys.setPopupEnabled(plasmoid.configuration.notify)
AWKeys.setWrapNewLines(plasmoid.configuration.wrapNewLines)
needUpdate()
awKeys.initKeys(plasmoid.configuration.text)
awKeys.initTooltip(tooltipSettings)
awKeys.setPopupEnabled(plasmoid.configuration.notify)
awKeys.setTranslateStrings(plasmoid.configuration.translateStrings)
awKeys.setWrapNewLines(plasmoid.configuration.wrapNewLines)
}
function action_checkUpdates() {
if (debug) console.log("[main::action_checkUpdates]")
if (debug) console.debug()
AWActions.checkUpdates()
return awActions.checkUpdates()
}
function action_showReadme() {
if (debug) console.log("[main::action_showReadme]")
if (debug) console.debug()
AWActions.showReadme()
return awActions.showReadme()
}
function action_report() {
if (debug) console.log("[main::action_report]")
if (debug) console.debug()
AWActions.sendEmail()
return awActions.sendEmail()
}
function action_requestKey() {
if (debug) console.log("[main::action_requestKey]")
if (debug) console.debug()
AWKeys.graphicalValueByKey()
return awKeys.graphicalValueByKey()
}
}

View File

@ -1 +1 @@
singleton general general.qml
singleton general 1.0 general.qml

View File

@ -20,17 +20,22 @@ import QtQuick.Controls 1.3 as QtControls
import QtQuick.Controls.Styles 1.3 as QtStyles
import QtQuick.Dialogs 1.1 as QtDialogs
import org.kde.plasma.awesomewidget 1.0
import org.kde.plasma.private.awesomewidget 1.0
Item {
id: tooltipPage
// backend
AWActions {
id: awActions;
}
width: childrenRect.width
height: childrenRect.height
implicitWidth: pageColumn.implicitWidth
implicitHeight: pageColumn.implicitHeight
property bool debug: AWKeys.isDebugEnabled()
property bool debug: awActions.isDebugEnabled()
property alias cfg_tooltipNumber: tooltipNumber.value
property alias cfg_useTooltipBackground: useTooltipBackground.checked
@ -508,6 +513,6 @@ Item {
}
Component.onCompleted: {
if (debug) console.log("[tooltip::onCompleted]")
if (debug) console.debug()
}
}

View File

@ -19,17 +19,25 @@ import QtQuick 2.0
import QtQuick.Controls 1.3 as QtControls
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.awesomewidget 1.0
import org.kde.plasma.private.awesomewidget 1.0
Item {
id: widgetPage
// backend
AWKeys {
id: awKeys;
}
AWActions {
id: awActions;
}
width: childrenRect.width
height: childrenRect.height
implicitWidth: pageColumn.implicitWidth
implicitHeight: pageColumn.implicitHeight
property bool debug: AWKeys.isDebugEnabled()
property bool debug: awActions.isDebugEnabled()
property variant settings: {
"customTime": plasmoid.configuration.customTime,
"customUptime": plasmoid.configuration.customUptime,
@ -70,6 +78,7 @@ Item {
verticalAlignment: Text.AlignVCenter
wrapMode: Text.WordWrap
text: i18n("Detailed information may be found on <a href=\"http://arcanis.name/projects/awesome-widgets/\">project homepage</a>")
onLinkActivated: Qt.openUrlExternally(link);
}
Row {
@ -81,14 +90,13 @@ Item {
iconName: "font"
onClicked: {
if (debug) console.log("[widget::onClicked] : Font button")
if (debug) console.debug("Font button")
var defaultFont = {
"color": plasmoid.configuration.fontColor,
"family": plasmoid.configuration.fontFamily,
"size": plasmoid.configuration.fontSize
}
var font = AWActions.getFont(defaultFont)
var font = awActions.getFont(defaultFont)
var pos = textPattern.cursorPosition
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
@ -103,8 +111,7 @@ Item {
iconName: "format-indent-more"
onClicked: {
if (debug) console.log("[widget::onClicked] : Indent button")
if (debug) console.debug("Indent button")
var pos = textPattern.cursorPosition
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
@ -117,8 +124,7 @@ Item {
iconName: "format-text-bold"
onClicked: {
if (debug) console.log("[widget::onClicked] : Bold button")
if (debug) console.debug("Bold button")
var pos = textPattern.cursorPosition
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
@ -130,8 +136,7 @@ Item {
iconName: "format-text-italic"
onClicked: {
if (debug) console.log("[widget::onClicked] : Italic button")
if (debug) console.debug("Italic button")
var pos = textPattern.cursorPosition
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
@ -143,8 +148,7 @@ Item {
iconName: "format-text-underline"
onClicked: {
if (debug) console.log("[widget::onClicked] : Underline button")
if (debug) console.debug("Underline button")
var pos = textPattern.cursorPosition
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
@ -156,8 +160,7 @@ Item {
iconName: "format-text-strikethrough"
onClicked: {
if (debug) console.log("[widget::onClicked] : Strike button")
if (debug) console.debug("Strike button")
var pos = textPattern.cursorPosition
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
@ -170,8 +173,7 @@ Item {
iconName: "format-justify-left"
onClicked: {
if (debug) console.log("[widget::onClicked] : Left button")
if (debug) console.debug("Left button")
var pos = textPattern.cursorPosition
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
@ -183,8 +185,7 @@ Item {
iconName: "format-justify-center"
onClicked: {
if (debug) console.log("[widget::onClicked] : Center button")
if (debug) console.debug("Center button")
var pos = textPattern.cursorPosition
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
@ -196,8 +197,7 @@ Item {
iconName: "format-justify-right"
onClicked: {
if (debug) console.log("[widget::onClicked] : Right button")
if (debug) console.debug("Right button")
var pos = textPattern.cursorPosition
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
@ -209,8 +209,7 @@ Item {
iconName: "format-justify-fill"
onClicked: {
if (debug) console.log("[widget::onClicked] : Justify button")
if (debug) console.debug("Justify button")
var pos = textPattern.cursorPosition
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
@ -222,17 +221,81 @@ Item {
Row {
height: implicitHeight
width: parent.width
QtControls.ComboBox {
width: (parent.width - addTagButton.width - showValueButton.width - addLambdaButton.width) / 2
textRole: "label"
model: [
{
'label': i18n("AC"),
'regexp': "^(ac|bat).*"
},
{
'label': i18n("Bars"),
'regexp': "^bar.*"
},
{
'label': i18n("CPU"),
'regexp': "^(cpu|gpu|la|ps|temp(?!erature)).*"
},
{
'label': i18n("Desktops"),
'regexp': "^(n|t)?desktop(s)?"
},
{
'label': i18n("HDD"),
'regexp': "^hdd.*"
},
{
'label': i18n("Memory"),
'regexp': "^(mem|swap).*"
},
{
'label': i18n("Network"),
'regexp': "^(netdev|(down|up(?!time)).*)"
},
{
'label': i18n("Music player"),
'regexp': "(^|d|s)(album|artist|duration|progress|title)"
},
{
'label': i18n("Scripts"),
'regexp': "^custom.*"
},
{
'label': i18n("Time"),
'regexp': ".*time$"
},
{
'label': i18n("Quotes"),
'regexp': "^(perc)?(ask|bid|price)(chg)?.*"
},
{
'label': i18n("Upgrades"),
'regexp': "^pkgcount.*"
},
{
'label': i18n("Weathers"),
'regexp': "^(weather(Id)?|humidity|pressure|temperature|timestamp)"
}
]
onCurrentIndexChanged: {
if (debug) console.debug()
tags.model = awKeys.dictKeys(true, model[currentIndex]["regexp"])
if (debug) console.info("Init model", tags.model, "for", model[currentIndex]["label"])
tags.currentIndex = -1
}
}
QtControls.ComboBox {
id: tags
width: parent.width - addTagButton.width - showValueButton.width
width: (parent.width - addTagButton.width - showValueButton.width - addLambdaButton.width) / 2
}
QtControls.Button {
id: addTagButton
text: i18n("Add")
onClicked: {
if (debug) console.log("[widget::onClicked] : Add tag button")
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)
@ -244,14 +307,26 @@ Item {
text: i18n("Show value")
onClicked: {
if (debug) console.log("[widget::onClicked] : Show tag button")
if (!tags.currentText) return
if (debug) console.debug("Show tag button")
var message = i18n("Tag: %1", tags.currentText)
message += "<br>"
message += i18n("Value: %1", AWKeys.valueByKey(tags.currentText))
message += i18n("Value: %1", awKeys.valueByKey(tags.currentText))
message += "<br>"
message += i18n("Info: %1", AWKeys.infoByKey(tags.currentText))
AWActions.sendNotification("tag", message)
message += i18n("Info: %1", awKeys.infoByKey(tags.currentText))
awActions.sendNotification("tag", message)
}
}
QtControls.Button {
id: addLambdaButton
text: i18n("Add lambda")
onClicked: {
if (debug) console.debug("Lambda button")
var pos = textPattern.cursorPosition
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
textPattern.insert(pos, selected + "${{\n\n}}")
}
}
}
@ -262,7 +337,7 @@ Item {
QtControls.Button {
width: parent.width
text: i18n("Edit bars")
onClicked: AWKeys.editItem("graphicalitem")
onClicked: awKeys.editItem("graphicalitem")
}
}
@ -284,9 +359,8 @@ Item {
interval: 5000
onNewData: {
if (debug) console.log("[widget::onNewData] : Update source " + sourceName)
AWKeys.setDataBySource(sourceName, data, settings)
if (debug) console.debug("Update source", sourceName)
awKeys.setDataBySource(sourceName, data, settings)
}
}
@ -297,9 +371,8 @@ Item {
interval: 5000
onNewData: {
if (debug) console.log("[widget::onNewData] : Update source " + sourceName)
AWKeys.setDataBySource(sourceName, data, settings)
if (debug) console.debug("Update source", sourceName)
awKeys.setDataBySource(sourceName, data, settings)
}
}
@ -310,17 +383,15 @@ Item {
interval: 5000
onNewData: {
if (debug) console.log("[widget::onNewData] : Update source " + sourceName)
AWKeys.setDataBySource(sourceName, data, settings)
if (debug) console.debug("Update source", sourceName)
awKeys.setDataBySource(sourceName, data, settings)
}
}
Component.onCompleted: {
if (debug) console.log("[widget::onCompleted]")
if (debug) console.debug()
// init submodule
AWKeys.initKeys(plasmoid.configuration.text)
tags.model = AWKeys.dictKeys(true)
awKeys.initKeys(plasmoid.configuration.text)
}
}

View File

@ -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=2.2.2
X-KDE-PluginInfo-Version=2.4.0
X-KDE-PluginInfo-Website=http://arcanis.name/projects/awesome-widgets/
X-KDE-PluginInfo-Category=System Information
X-KDE-PluginInfo-Depends=

View File

@ -1,38 +1,25 @@
set (PLUGIN_NAME awplugin)
set(PLUGIN_NAME awplugin)
add_definitions(-DTRANSLATION_DOMAIN=\"plasma_applet_org.kde.plasma.awesomewidget\")
add_definitions (${Qt5Core_DEFINITIONS} ${Qt5Network_DEFINITIONS})
set (Qt_INCLUDE ${Qt5Core_INCLUDE_DIRS} ${Qt5Network_INCLUDE_DIRS} ${Qt5Qml_INCLUDE_DIRS})
set (Qt_LIBRARIES ${Qt5Core_LIBRARIES} ${Qt5Network_LIBRARIES} ${Qt5Qml_LIBRARIES})
set (Kf5_INCLUDE ${I18n_INCLUDE_DIR}
${Notifications_INCLUDE_DIR})
set (Kf5_LIBRARIES KF5::I18n
KF5::Notifications)
include_directories(
${CMAKE_SOURCE_DIR}
${CMAKE_BINARY_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_BINARY_DIR}/../
${CMAKE_CURRENT_SOURCE_DIR}/../../${PROJECT_LIBRARY}/
${PROJECT_TRDPARTY_DIR}
${Qt_INCLUDE}
${Kf5_INCLUDE}
)
include_directories (${CMAKE_SOURCE_DIR}
${CMAKE_BINARY_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_BINARY_DIR}/../
${PROJECT_TRDPARTY_DIR}
../../extsysmon
${CMAKE_CURRENT_BINARY_DIR}/../../extsysmon
${Qt_INCLUDE}
${Kf5_INCLUDE})
file(GLOB SUBPROJECT_SOURCE *.cpp ${PROJECT_TRDPARTY_DIR}/fontdialog/*.cpp ${CMAKE_SOURCE_DIR}/*.cpp)
file(GLOB SUBPROJECT_UI *.ui)
file(GLOB SUBPROJECT_NOTIFY *.notifyrc)
# task source is required by extscripts
file (GLOB_RECURSE SUBPROJECT_SOURCE *.cpp ${PROJECT_TRDPARTY_DIR}/fontdialog/*.cpp
../../extsysmon/extquotes.cpp
../../extsysmon/extscript.cpp
../../extsysmon/extupgrade.cpp)
file (GLOB SUBPROJECT_UI *.ui)
file (GLOB SUBPROJECT_NOTIFY *.notifyrc)
set (SUBPROJECT_DESKTOP ${CMAKE_CURRENT_SOURCE_DIR}/desktops)
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})
qt5_wrap_ui (SUBPROJECT_UI_HEADER ${SUBPROJECT_UI})
add_library (${PLUGIN_NAME} SHARED ${SUBPROJECT_SOURCE} ${SUBPROJECT_UI_HEADER})
target_link_libraries (${PLUGIN_NAME} ${Qt_LIBRARIES} ${Kf5_LIBRARIES})
install (TARGETS ${PLUGIN_NAME} DESTINATION ${QML_INSTALL_DIR}/org/kde/plasma/awesomewidget)
install (FILES qmldir DESTINATION ${QML_INSTALL_DIR}/org/kde/plasma/awesomewidget)
install (FILES ${SUBPROJECT_NOTIFY} DESTINATION ${KNOTIFYRC_INSTALL_DIR})
install (DIRECTORY ${SUBPROJECT_DESKTOP} DESTINATION ${DATA_INSTALL_DIR}/${PROJECT_NAME})
install(TARGETS ${PLUGIN_NAME} DESTINATION ${QML_INSTALL_DIR}/org/kde/plasma/private/awesomewidget)
install(FILES qmldir DESTINATION ${QML_INSTALL_DIR}/org/kde/plasma/private/awesomewidget)
install(FILES ${SUBPROJECT_NOTIFY} DESTINATION ${KNOTIFYRC_INSTALL_DIR})

View File

@ -20,9 +20,10 @@
#include <KI18n/KLocalizedString>
#include <KNotifications/KNotification>
#include <QDebug>
#include <QDesktopServices>
#include <QDir>
#include <QJsonDocument>
#include <QJsonParseError>
#include <QMessageBox>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
@ -33,32 +34,27 @@
#include <QStandardPaths>
#include <fontdialog/fontdialog.h>
#include <pdebug/pdebug.h>
#include "extscript.h"
#include "graphicalitem.h"
#include "awdebug.h"
#include "version.h"
AWActions::AWActions(QObject *parent)
: QObject(parent)
{
// debug
QProcessEnvironment environment = QProcessEnvironment::systemEnvironment();
QString debugEnv = environment.value(QString("DEBUG"), QString("no"));
debug = (debugEnv == QString("yes"));
qCDebug(LOG_AW);
}
AWActions::~AWActions()
{
if (debug) qDebug() << PDEBUG;
qCDebug(LOG_AW);
}
void AWActions::checkUpdates()
{
if (debug) qDebug() << PDEBUG;
qCDebug(LOG_AW);
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(versionReplyRecieved(QNetworkReply *)));
@ -67,10 +63,29 @@ void AWActions::checkUpdates()
}
void AWActions::runCmd(const QString cmd)
bool AWActions::dropCache() const
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Cmd" << cmd;
qCDebug(LOG_AW);
QString fileName = QString("%1/awesomewidgets.ndx")
.arg(QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation));
return QFile(fileName).remove();
}
bool AWActions::isDebugEnabled() const
{
qCDebug(LOG_AW);
return LOG_AW().isDebugEnabled();
}
void AWActions::runCmd(const QString cmd) const
{
qCDebug(LOG_AW);
qCDebug(LOG_AW) << "Cmd" << cmd;
QProcess command;
sendNotification(QString("Info"), i18n("Run %1", cmd));
@ -79,24 +94,24 @@ void AWActions::runCmd(const QString cmd)
}
void AWActions::sendEmail()
void AWActions::sendEmail() const
{
if (debug) qDebug() << PDEBUG;
qCDebug(LOG_AW);
}
void AWActions::showReadme()
void AWActions::showReadme() const
{
if (debug) qDebug() << PDEBUG;
qCDebug(LOG_AW);
QDesktopServices::openUrl(QString(HOMEPAGE));
}
QString AWActions::getAboutText(const QString type)
QString AWActions::getAboutText(const QString type) const
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Type" << type;
qCDebug(LOG_AW);
qCDebug(LOG_AW) << "Type" << type;
QString text;
if (type == QString("header"))
@ -122,9 +137,9 @@ QString AWActions::getAboutText(const QString type)
QStringList trdPartyList = QString(TRDPARTY_LICENSE).split(QChar(';'), QString::SkipEmptyParts);
for (int i=0; i<trdPartyList.count(); i++)
trdPartyList[i] = QString("<a href=\"%3\">%1</a> (%2 license)")
.arg(trdPartyList[i].split(QChar(','))[0])
.arg(trdPartyList[i].split(QChar(','))[1])
.arg(trdPartyList[i].split(QChar(','))[2]);
.arg(trdPartyList.at(i).split(QChar(','))[0])
.arg(trdPartyList.at(i).split(QChar(','))[1])
.arg(trdPartyList.at(i).split(QChar(','))[2]);
text = i18n("This software uses: %1", trdPartyList.join(QString(", ")));
}
@ -132,9 +147,10 @@ QString AWActions::getAboutText(const QString type)
}
QVariantMap AWActions::getFont(const QVariantMap defaultFont)
QVariantMap AWActions::getFont(const QVariantMap defaultFont) const
{
if (debug) qDebug() << PDEBUG;
qCDebug(LOG_AW);
qCDebug(LOG_AW) << "Default font is" << defaultFont;
QVariantMap fontMap;
CFont defaultCFont = CFont(defaultFont[QString("family")].toString(),
@ -150,12 +166,12 @@ QVariantMap AWActions::getFont(const QVariantMap defaultFont)
}
QVariantMap AWActions::readDataEngineConfiguration()
QVariantMap AWActions::readDataEngineConfiguration() const
{
if (debug) qDebug() << PDEBUG;
qCDebug(LOG_AW);
QString fileName = QStandardPaths::locate(QStandardPaths::ConfigLocation, QString("plasma-dataengine-extsysmon.conf"));
if (debug) qDebug() << PDEBUG << ":" << "Configuration file" << fileName;
qCInfo(LOG_AW) << "Configuration file" << fileName;
QSettings settings(fileName, QSettings::IniFormat);
QVariantMap configuration;
@ -168,19 +184,20 @@ QVariantMap AWActions::readDataEngineConfiguration()
configuration[QString("MPDPORT")] = settings.value(QString("MPDPORT"), QString("6600"));
configuration[QString("MPRIS")] = settings.value(QString("MPRIS"), QString("auto"));
configuration[QString("PLAYER")] = settings.value(QString("PLAYER"), QString("mpris"));
configuration[QString("PLAYERSYMBOLS")] = settings.value(QString("PLAYERSYMBOLS"), QString("10"));
settings.endGroup();
return configuration;
}
void AWActions::writeDataEngineConfiguration(const QVariantMap configuration)
void AWActions::writeDataEngineConfiguration(const QVariantMap configuration) const
{
if (debug) qDebug() << PDEBUG;
qCDebug(LOG_AW);
QString fileName = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QString("/plasma-dataengine-extsysmon.conf");
QSettings settings(fileName, QSettings::IniFormat);
if (debug) qDebug() << PDEBUG << ":" << "Configuration file" << settings.fileName();
qCInfo(LOG_AW) << "Configuration file" << settings.fileName();
settings.beginGroup(QString("Configuration"));
settings.setValue(QString("ACPIPATH"), configuration[QString("ACPIPATH")]);
@ -191,14 +208,19 @@ void AWActions::writeDataEngineConfiguration(const QVariantMap configuration)
settings.setValue(QString("MPDPORT"), configuration[QString("MPDPORT")]);
settings.setValue(QString("MPRIS"), configuration[QString("MPRIS")]);
settings.setValue(QString("PLAYER"), configuration[QString("PLAYER")]);
settings.setValue(QString("PLAYERSYMBOLS"), configuration[QString("PLAYERSYMBOLS")]);
settings.endGroup();
settings.sync();
}
void AWActions::sendNotification(const QString eventId, const QString message, const bool enablePopup)
void AWActions::sendNotification(const QString eventId, const QString message,
const bool enablePopup)
{
qCDebug(LOG_AW);
qCDebug(LOG_AW) << "Event" << eventId;
qCDebug(LOG_AW) << "Message" << message;
if ((eventId == QString("event")) && (!enablePopup)) return;
KNotification *notification = KNotification::event(eventId, QString("Awesome Widget ::: %1").arg(eventId), message);
@ -206,16 +228,17 @@ void AWActions::sendNotification(const QString eventId, const QString message, c
}
void AWActions::showUpdates(QString version)
void AWActions::showUpdates(QString version) const
{
if (debug) qDebug() << PDEBUG;
qCDebug(LOG_AW);
QString text;
text += i18n("Current version : %1", QString(VERSION)) + QString("\n");
text += i18n("New version : %1", version) + QString("\n\n");
text += i18n("Click \"Ok\" to download");
int select = QMessageBox::information(0, i18n("There are updates"), text, QMessageBox::Ok | QMessageBox::Cancel);
int select = QMessageBox::information(nullptr, i18n("There are updates"), text,
QMessageBox::Ok | QMessageBox::Cancel);
switch (select) {
case QMessageBox::Ok:
QDesktopServices::openUrl(QString(RELEASES) + version);
@ -224,30 +247,35 @@ void AWActions::showUpdates(QString version)
}
void AWActions::versionReplyRecieved(QNetworkReply *reply)
void AWActions::versionReplyRecieved(QNetworkReply *reply) const
{
if (debug) qDebug() << PDEBUG;
qCDebug(LOG_AW);
qCDebug(LOG_AW) << "Return code" << reply->error();
qCDebug(LOG_AW) << "Reply error message" << reply->errorString();
QString answer = reply->readAll();
if (!answer.contains(QString("tag_name"))) return;
QString version = QString(VERSION);
if (debug) qDebug() << PDEBUG << answer;
for (int i=0; i<answer.split(QString("tag_name")).count(); i++) {
version = answer.split(QString("tag_name"))[1].split(QChar(','))[0];
version.remove(QChar('"'));
version.remove(QChar(':'));
version.remove(QString("V."));
break;
QJsonParseError error;
QJsonDocument jsonDoc = QJsonDocument::fromJson(reply->readAll(), &error);
reply->deleteLater();
if ((reply->error() != QNetworkReply::NoError) ||
(error.error != QJsonParseError::NoError)) {
qCWarning(LOG_AW) << "Parse error" << error.errorString();
return;
}
int old_major = QString(VERSION).split(QChar('.'))[0].toInt();
int old_minor = QString(VERSION).split(QChar('.'))[1].toInt();
int old_patch = QString(VERSION).split(QChar('.'))[2].toInt();
int new_major = QString(version).split(QChar('.'))[0].toInt();
int new_minor = QString(version).split(QChar('.'))[1].toInt();
int new_patch = QString(version).split(QChar('.'))[2].toInt();
// convert to map
QVariantMap firstRelease = jsonDoc.toVariant().toList().first().toMap();
QString version = firstRelease[QString("tag_name")].toString();
version.remove(QString("V."));
qCInfo(LOG_AW) << "Found version" << version;
int old_major = QString(VERSION).split(QChar('.')).at(0).toInt();
int old_minor = QString(VERSION).split(QChar('.')).at(1).toInt();
int old_patch = QString(VERSION).split(QChar('.')).at(2).toInt();
int new_major = QString(version).split(QChar('.')).at(0).toInt();
int new_minor = QString(version).split(QChar('.')).at(1).toInt();
int new_patch = QString(version).split(QChar('.')).at(2).toInt();
if ((old_major < new_major) ||
((old_major == new_major) && (old_minor < new_minor)) ||
((old_major == new_major) && (old_minor == new_minor) && (old_patch < new_patch)))
showUpdates(version);
return showUpdates(version);
}

View File

@ -19,7 +19,6 @@
#ifndef AWACTIONS_H
#define AWACTIONS_H
#include <QMap>
#include <QObject>
#include <QVariant>
@ -31,31 +30,31 @@ class AWActions : public QObject
Q_OBJECT
public:
AWActions(QObject *parent = nullptr);
~AWActions();
explicit AWActions(QObject *parent = nullptr);
virtual ~AWActions();
Q_INVOKABLE void checkUpdates();
Q_INVOKABLE void runCmd(const QString cmd = QString("/usr/bin/true"));
Q_INVOKABLE void sendEmail();
Q_INVOKABLE void showReadme();
Q_INVOKABLE bool dropCache() const;
Q_INVOKABLE bool isDebugEnabled() const;
Q_INVOKABLE void runCmd(const QString cmd = QString("/usr/bin/true")) const;
Q_INVOKABLE void sendEmail() const;
Q_INVOKABLE void showReadme() const;
// configuration slots
Q_INVOKABLE QString getAboutText(const QString type = QString("header"));
Q_INVOKABLE QVariantMap getFont(const QVariantMap defaultFont);
Q_INVOKABLE QString getAboutText(const QString type = QString("header")) const;
Q_INVOKABLE QVariantMap getFont(const QVariantMap defaultFont) const;
// dataengine
Q_INVOKABLE QVariantMap readDataEngineConfiguration();
Q_INVOKABLE void writeDataEngineConfiguration(const QVariantMap configuration);
Q_INVOKABLE QVariantMap readDataEngineConfiguration() const;
Q_INVOKABLE void writeDataEngineConfiguration(const QVariantMap configuration) const;
public slots:
Q_INVOKABLE static void sendNotification(const QString eventId, const QString message,
const bool enablePopup = false);
private slots:
void showUpdates(QString version);
void versionReplyRecieved(QNetworkReply *reply);
void showUpdates(QString version) const;
void versionReplyRecieved(QNetworkReply *reply) const;
private:
// variables
bool debug = false;
};

View File

@ -23,28 +23,10 @@
#include "awkeys.h"
static QObject *awactions_singletontype_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
{
Q_UNUSED(engine);
Q_UNUSED(scriptEngine);
return new AWActions();
}
static QObject *awkeys_singletontype_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
{
Q_UNUSED(engine);
Q_UNUSED(scriptEngine);
return new AWKeys();
}
void AWPlugin::registerTypes(const char *uri)
{
Q_ASSERT(uri == QLatin1String("org.kde.plasma.awesomewidget"));
Q_ASSERT(uri == QLatin1String("org.kde.plasma.private.awesomewidget"));
qmlRegisterSingletonType<AWActions>(uri, 1, 0, "AWActions", awactions_singletontype_provider);
qmlRegisterSingletonType<AWKeys>(uri, 1, 0, "AWKeys", awkeys_singletontype_provider);
qmlRegisterType<AWActions>(uri, 1, 0, "AWActions");
qmlRegisterType<AWKeys>(uri, 1, 0, "AWKeys");
}

File diff suppressed because it is too large Load Diff

View File

@ -19,107 +19,82 @@
#ifndef AWKEYS_H
#define AWKEYS_H
#include <QDialog>
#include <QDialogButtonBox>
#include <QListWidget>
#include <QMap>
#include <QHash>
#include <QObject>
#include <QStringList>
#include <QPushButton>
#include <QVariant>
#include "extitemaggregator.h"
#include "version.h"
class AWToolTip;
class ExtQuotes;
class ExtScript;
class ExtUpgrade;
class ExtWeather;
class GraphicalItem;
class AWKeys : public QObject
{
Q_OBJECT
enum RequestedItem {
Nothing,
RequestedGraphicalItem,
RequestedExtQuotes,
RequestedExtScript,
RequestedExtUpgrade
};
public:
AWKeys(QObject *parent = nullptr);
~AWKeys();
explicit AWKeys(QObject *parent = nullptr);
virtual ~AWKeys();
Q_INVOKABLE void initKeys(const QString currentPattern);
Q_INVOKABLE void initTooltip(const QVariantMap tooltipParams);
Q_INVOKABLE void setPopupEnabled(const bool popup = false);
Q_INVOKABLE void setTranslateStrings(const bool translate = false);
Q_INVOKABLE void setWrapNewLines(const bool wrap = false);
Q_INVOKABLE bool isDebugEnabled();
Q_INVOKABLE QString parsePattern();
Q_INVOKABLE QString toolTipImage();
Q_INVOKABLE QSize toolTipSize();
Q_INVOKABLE QSize toolTipSize() const;
// keys
Q_INVOKABLE void addDevice(const QString source);
Q_INVOKABLE QStringList dictKeys(const bool sorted = false);
Q_INVOKABLE QStringList getHddDevices();
Q_INVOKABLE bool setDataBySource(const QString sourceName, const QVariantMap data,
Q_INVOKABLE QStringList dictKeys(const bool sorted = false,
const QString regexp = QString()) const;
Q_INVOKABLE QStringList getHddDevices() const;
Q_INVOKABLE void setDataBySource(const QString sourceName, const QVariantMap data,
const QVariantMap params);
// values
Q_INVOKABLE void graphicalValueByKey();
Q_INVOKABLE QString infoByKey(QString key);
Q_INVOKABLE QString valueByKey(QString key);
Q_INVOKABLE void graphicalValueByKey() const;
Q_INVOKABLE QString infoByKey(QString key) const;
Q_INVOKABLE QString valueByKey(QString key) const;
// configuration
Q_INVOKABLE void editItem(const QString type);
signals:
void dropSourceFromDataengine(const QString source);
void needTextToBeUpdated(const QString newText) const;
void needToolTipToBeUpdated(const QString newText) const;
void needToBeUpdated();
private slots:
void dataUpdate();
void loadKeysFromCache();
void reinitKeys();
// editor
void editItemButtonPressed(QAbstractButton *button);
void copyBar(const QString original);
void copyQuotes(const QString original);
void copyScript(const QString original);
void copyUpgrade(const QString original);
private:
// methods
void addKeyToCache(const QString type, const QString key = QString(""));
bool checkKeys(const QVariantMap data);
QString htmlValue(QString key);
int numberCpus();
float temperature(const float temp, const QString units);
// find methods
QStringList findGraphicalItems();
QStringList findKeys();
void calculateLambdas();
QString parsePattern() const;
float temperature(const float temp, const QString units) const;
// get methods
QList<ExtQuotes *> getExtQuotes();
QList<ExtScript *> getExtScripts();
QList<ExtUpgrade *> getExtUpgrade();
QList<GraphicalItem *> getGraphicalItems();
GraphicalItem *getItemByTag(const QString tag);
QStringList getTimeKeys();
AWToolTip *toolTip = nullptr;
// graphical elements
QDialog *dialog = nullptr;
QListWidget *widgetDialog = nullptr;
QDialogButtonBox *dialogButtons = nullptr;
QPushButton *copyButton = nullptr;
QPushButton *createButton = nullptr;
QPushButton *deleteButton = nullptr;
RequestedItem requestedItem = Nothing;
// variables
bool debug = false;
bool enablePopup = false;
bool translateStrings = false;
bool wrapNewLines = false;
QList<GraphicalItem *> graphicalItems;
QList<ExtQuotes *> extQuotes;
QList<ExtScript *> extScripts;
QList<ExtUpgrade *> extUpgrade;
QStringList foundBars, foundKeys, keys;
ExtItemAggregator<GraphicalItem> *graphicalItems;
ExtItemAggregator<ExtQuotes> *extQuotes;
ExtItemAggregator<ExtScript> *extScripts;
ExtItemAggregator<ExtUpgrade> *extUpgrade;
ExtItemAggregator<ExtWeather> *extWeather;
QString pattern;
QMap<QString, QString> values;
QStringList diskDevices, fanDevices, hddDevices, mountDevices, networkDevices, tempDevices;
QStringList foundBars, foundKeys, foundLambdas;
QStringList timeKeys = QString(TIME_KEYS).split(QChar(','));
QHash<QString, QString> values;
QStringList diskDevices, hddDevices, mountDevices, networkDevices, tempDevices;
};

View File

@ -17,23 +17,19 @@
#include "awtooltip.h"
#include <QDebug>
#include <QProcessEnvironment>
#include <QBuffer>
#include <math.h>
#include <pdebug/pdebug.h>
#include "awdebug.h"
AWToolTip::AWToolTip(QObject *parent, QVariantMap settings)
: QObject(parent),
configuration(settings)
configuration(qvariant_cast<QVariantHash>(settings))
{
// debug
QProcessEnvironment environment = QProcessEnvironment::systemEnvironment();
QString debugEnv = environment.value(QString("DEBUG"), QString("no"));
debug = (debugEnv == QString("yes"));
qCDebug(LOG_AW);
toolTipScene = new QGraphicsScene();
toolTipScene = new QGraphicsScene(nullptr);
toolTipView = new QGraphicsView(toolTipScene);
toolTipView->setStyleSheet(QString("background: transparent"));
toolTipView->setContentsMargins(0, 0, 0, 0);
@ -65,70 +61,108 @@ AWToolTip::AWToolTip(QObject *parent, QVariantMap settings)
if (configuration[QString("downTooltip")].toBool()) requiredKeys.append(QString("downTooltip"));
if (configuration[QString("upTooltip")].toBool()) requiredKeys.append(QString("upTooltip"));
if (configuration[QString("batTooltip")].toBool()) requiredKeys.append(QString("batTooltip"));
connect(this, SIGNAL(updateData(QHash<QString, QString>)),
this, SLOT(dataUpdate(QHash<QString, QString>)));
}
AWToolTip::~AWToolTip()
{
if (debug) qDebug() << PDEBUG;
qCDebug(LOG_AW);
delete toolTipView;
delete toolTipScene;
}
QSize AWToolTip::getSize()
void AWToolTip::dataUpdate(QHash<QString, QString> values)
{
if (debug) qDebug() << PDEBUG;
qCDebug(LOG_AW);
// battery update requires info is AC online or not
setData(QString("batTooltip"), values[QString("bat")].toFloat(),
values[QString("ac")] == configuration[QString("acOnline")]);
// usual case
setData(QString("cpuTooltip"), values[QString("cpu")].toFloat());
setData(QString("cpuclTooltip"), values[QString("cpucl")].toFloat());
setData(QString("memTooltip"), values[QString("mem")].toFloat());
setData(QString("swapTooltip"), values[QString("swap")].toFloat());
setData(QString("downTooltip"), values[QString("downkb")].toFloat());
setData(QString("upTooltip"), values[QString("upkb")].toFloat());
emit(toolTipPainted(htmlImage()));
}
QSize AWToolTip::getSize() const
{
qCDebug(LOG_AW);
return size;
}
QString AWToolTip::htmlImage()
{
qCDebug(LOG_AW);
QPixmap rawImage = image();
QByteArray byteArray;
QBuffer buffer(&byteArray);
rawImage.save(&buffer, "PNG");
return byteArray.isEmpty() ? QString() :
QString("<img src=\"data:image/png;base64,%1\"/>").arg(QString(byteArray.toBase64()));
}
QPixmap AWToolTip::image()
{
if (debug) qDebug() << PDEBUG;
qCDebug(LOG_AW);
toolTipView->resize(size);
// create image
toolTipScene->clear();
QPen pen = QPen();
// background
if (configuration[QString("useTooltipBackground")].toBool())
toolTipScene->setBackgroundBrush(QBrush(QColor(configuration[QString("tooltipBackground")].toString())));
else
toolTipScene->setBackgroundBrush(QBrush(Qt::NoBrush));
toolTipScene->setBackgroundBrush(configuration[QString("useTooltipBackground")].toBool() ?
QBrush(QColor(configuration[QString("tooltipBackground")].toString())) :
QBrush(Qt::NoBrush));
bool down = false;
for (int i=0; i<requiredKeys.count(); i++) {
float normX = 100.0 / static_cast<float>(data[requiredKeys[i]].count());
float normY = 100.0 / (1.5 * boundaries[requiredKeys[i]]);
if (requiredKeys[i] != QString("batTooltip"))
pen.setColor(QColor(configuration[QString("%1Color").arg(requiredKeys[i])].toString()));
float normX = 100.0 / static_cast<float>(data[requiredKeys.at(i)].count());
float normY = 100.0 / (1.5 * boundaries[requiredKeys.at(i)]);
if (requiredKeys.at(i) != QString("batTooltip"))
pen.setColor(QColor(configuration[QString("%1Color").arg(requiredKeys.at(i))].toString()));
float shift = i * 100.0;
if (down) shift -= 100.0;
for (int j=0; j<data[requiredKeys[i]].count()-1; j++) {
for (int j=0; j<data[requiredKeys.at(i)].count()-1; j++) {
// some magic here
float x1 = j * normX + shift;
float y1 = - fabs(data[requiredKeys[i]][j]) * normY + 5.0;
float y1 = - fabs(data[requiredKeys.at(i)].at(j)) * normY + 5.0;
float x2 = (j + 1) * normX + shift;
float y2 = - fabs(data[requiredKeys[i]][j+1]) * normY + 5.0;
if (requiredKeys[i] == QString("batTooltip")) {
if (data[requiredKeys[i]][j+1] > 0)
float y2 = - fabs(data[requiredKeys.at(i)].at(j+1)) * normY + 5.0;
if (requiredKeys.at(i) == QString("batTooltip")) {
if (data[requiredKeys.at(i)].at(j+1) > 0)
pen.setColor(QColor(configuration[QString("batTooltipColor")].toString()));
else
pen.setColor(QColor(configuration[QString("batInTooltipColor")].toString()));
}
toolTipScene->addLine(x1, y1, x2, y2, pen);
}
if (requiredKeys[i] == QString("downTooltip")) down = true;
if (requiredKeys.at(i) == QString("downTooltip")) down = true;
}
return toolTipView->grab();
}
void AWToolTip::setData(const QString source, float value, const bool ac)
void AWToolTip::setData(const QString source, float value, const bool dontInvert)
{
if (debug) qDebug() << PDEBUG;
qCDebug(LOG_AW);
qCDebug(LOG_AW) << "Source" << source;
qCDebug(LOG_AW) << "Value" << value;
qCDebug(LOG_AW) << "Do not invert value" << dontInvert;
if (data[source].count() == 0)
data[source].append(0.0);
@ -136,19 +170,12 @@ void AWToolTip::setData(const QString source, float value, const bool ac)
data[source].takeFirst();
if (isnan(value)) value = 0.0;
if (ac)
data[source].append(value);
else
data[source].append(-value);
// invert values for different battery colours
data[source].append(dontInvert ? value : -value);
if ((source == QString("downTooltip")) || (source == QString("upTooltip"))) {
for (int i=0; i<data[QString("downTooltip")].count(); i++)
if (boundaries[QString("downTooltip")] < data[QString("downTooltip")][i])
boundaries[QString("downTooltip")] = data[QString("downTooltip")][i];
for (int i=0; i<data[QString("upTooltip")].count(); i++)
if (boundaries[QString("downTooltip")] < data[QString("upTooltip")][i])
boundaries[QString("downTooltip")] = data[QString("upTooltip")][i];
boundaries[QString("downTooltip")] *= 1.2;
if (source == QString("downTooltip")) {
QList<float> netValues = data[QString("downTooltip")] + data[QString("upTooltip")];
boundaries[QString("downTooltip")] = 1.2 * *std::max_element(netValues.cbegin(), netValues.cend());
boundaries[QString("upTooltip")] = boundaries[QString("downTooltip")];
}
}

View File

@ -21,7 +21,7 @@
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QMap>
#include <QHash>
#include <QObject>
#include <QPixmap>
#include <QVariant>
@ -32,24 +32,30 @@ class AWToolTip : public QObject
Q_OBJECT
public:
AWToolTip(QObject *parent = nullptr, QVariantMap settings = QVariantMap());
~AWToolTip();
QSize getSize();
explicit AWToolTip(QObject *parent = nullptr, QVariantMap settings = QVariantMap());
virtual ~AWToolTip();
QSize getSize() const;
QString htmlImage();
QPixmap image();
void setData(const QString source, float value,
const bool ac = true);
signals:
void updateData(QHash<QString, QString> values);
void toolTipPainted(QString image);
private slots:
void dataUpdate(QHash<QString, QString> values);
private:
// ui
QGraphicsScene *toolTipScene = nullptr;
QGraphicsView *toolTipView = nullptr;
void setData(const QString source, float value,
const bool dontInvert = true);
// variables
bool debug = false;
int counts = 0;
QVariantMap configuration;
QMap<QString, float> boundaries;
QMap<QString, QList<float>> data;
QVariantHash configuration;
QHash<QString, float> boundaries;
QHash<QString, QList<float>> data;
QStringList requiredKeys;
QSize size;
};

View File

@ -1,3 +1,2 @@
module org.kde.plasma.awesomewidget
module org.kde.plasma.private.awesomewidget
plugin awplugin

View File

@ -0,0 +1,41 @@
set(SUBPROJECT ${PROJECT_LIBRARY})
message(STATUS "Subproject ${SUBPROJECT}")
add_definitions(-DTRANSLATION_DOMAIN=\"plasma_applet_org.kde.plasma.awesomewidget\")
include_directories(
${CMAKE_SOURCE_DIR}
${CMAKE_BINARY_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_BINARY_DIR}/../
${PROJECT_TRDPARTY_DIR}
${Qt_INCLUDE}
${Kf5_INCLUDE}
)
file(GLOB SUBPROJECT_SOURCE *.cpp ${PROJECT_TRDPARTY_DIR}/qreplytimeout/*.cpp ${CMAKE_SOURCE_DIR}/*.cpp)
file(GLOB SUBPROJECT_HEADER *.h ${PROJECT_TRDPARTY_DIR}/qreplytimeout/*.h)
file(GLOB SUBPROJECT_UI *.ui)
set(SUBPROJECT_GRAPHITEMS ${CMAKE_CURRENT_SOURCE_DIR}/desktops)
set(SUBPROJECT_QUOTES ${CMAKE_CURRENT_SOURCE_DIR}/quotes)
set(SUBPROJECT_SCRIPTS ${CMAKE_CURRENT_SOURCE_DIR}/scripts)
set(SUBPROJECT_UPGRADE ${CMAKE_CURRENT_SOURCE_DIR}/upgrade)
set(SUBPROJECT_WEATHER ${CMAKE_CURRENT_SOURCE_DIR}/weather)
file(GLOB SUBPROJECT_WEATHER_JSON_IN *.json)
file(RELATIVE_PATH SUBPROJECT_WEATHER_JSON ${CMAKE_SOURCE_DIR} ${SUBPROJECT_WEATHER_JSON_IN})
# prepare
configure_file(${SUBPROJECT_WEATHER_JSON_IN} ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT_WEATHER_JSON})
qt5_wrap_cpp(SUBPROJECT_MOC_SOURCE ${SUBPROJECT_HEADER})
qt5_wrap_ui(SUBPROJECT_UI_HEADER ${SUBPROJECT_UI})
add_library(${SUBPROJECT} STATIC ${SUBPROJECT_SOURCE} ${SUBPROJECT_MOC_SOURCE}
${SUBPROJECT_HEADER} ${SUBPROJECT_UI_HEADER})
target_link_libraries(${SUBPROJECT} ${Qt_LIBRARIES} ${Kf5_LIBRARIES})
# install
install(DIRECTORY ${SUBPROJECT_GRAPHITEMS} DESTINATION ${DATA_INSTALL_DIR}/${PROJECT_NAME})
install(DIRECTORY ${SUBPROJECT_QUOTES} DESTINATION ${DATA_INSTALL_DIR}/${PROJECT_NAME})
install(DIRECTORY ${SUBPROJECT_SCRIPTS} DESTINATION ${DATA_INSTALL_DIR}/${PROJECT_NAME})
install(DIRECTORY ${SUBPROJECT_UPGRADE} DESTINATION ${DATA_INSTALL_DIR}/${PROJECT_NAME})
install(DIRECTORY ${SUBPROJECT_WEATHER} DESTINATION ${DATA_INSTALL_DIR}/${PROJECT_NAME})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT_WEATHER_JSON} DESTINATION ${DATA_INSTALL_DIR}/${PROJECT_NAME}/weather)

View File

@ -0,0 +1,252 @@
/***************************************************************************
* 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 "abstractextitem.h"
#include <QDir>
#include <QSettings>
#include <QStandardPaths>
#include <QTime>
#include "awdebug.h"
#include "version.h"
AbstractExtItem::AbstractExtItem(QWidget *parent, const QString desktopName,
const QStringList directories)
: QDialog(parent),
m_fileName(desktopName),
m_dirs(directories)
{
qCDebug(LOG_LIB);
qCDebug(LOG_LIB) << "Desktop name" << desktopName;
qCDebug(LOG_LIB) << "Directories" << directories;
m_name = m_fileName;
}
AbstractExtItem::~AbstractExtItem()
{
qCDebug(LOG_LIB);
}
template <class T>
T *AbstractExtItem::copy(const QString _fileName, const int _number)
{
Q_UNUSED(_fileName)
Q_UNUSED(_number)
qCDebug(LOG_LIB);
// an analog of pure virtual method
return new T();
}
int AbstractExtItem::apiVersion() const
{
qCDebug(LOG_LIB);
return m_apiVersion;
}
QString AbstractExtItem::comment() const
{
qCDebug(LOG_LIB);
return m_comment;
}
QStringList AbstractExtItem::directories() const
{
qCDebug(LOG_LIB);
return m_dirs;
}
QString AbstractExtItem::fileName() const
{
qCDebug(LOG_LIB);
return m_fileName;
}
int AbstractExtItem::interval() const
{
qCDebug(LOG_LIB);
return m_interval;
}
bool AbstractExtItem::isActive() const
{
qCDebug(LOG_LIB);
return m_active;
}
QString AbstractExtItem::name() const
{
qCDebug(LOG_LIB);
return m_name;
}
int AbstractExtItem::number() const
{
qCDebug(LOG_LIB);
return m_number;
}
QString AbstractExtItem::tag(const QString _type) const
{
qCDebug(LOG_LIB);
qCDebug(LOG_LIB) << "Tag type" << _type;
return QString("%1%2").arg(_type).arg(m_number);
}
void AbstractExtItem::setApiVersion(const int _apiVersion)
{
qCDebug(LOG_LIB);
qCDebug(LOG_LIB) << "Version" << _apiVersion;
m_apiVersion = _apiVersion;
}
void AbstractExtItem::setActive(const bool _state)
{
qCDebug(LOG_LIB);
qCDebug(LOG_LIB) << "State" << _state;
m_active = _state;
}
void AbstractExtItem::setComment(const QString _comment)
{
qCDebug(LOG_LIB);
qCDebug(LOG_LIB) << "Comment" << _comment;
m_comment = _comment;
}
void AbstractExtItem::setInterval(const int _interval)
{
qCDebug(LOG_LIB);
qCDebug(LOG_LIB) << "Interval" << _interval;
if (_interval <= 0) return;
m_interval = _interval;
}
void AbstractExtItem::setName(const QString _name)
{
qCDebug(LOG_LIB);
qCDebug(LOG_LIB) << "Name" << _name;
m_name = _name;
}
void AbstractExtItem::setNumber(int _number)
{
qCDebug(LOG_LIB);
qCDebug(LOG_LIB) << "Number" << _number;
if (_number == -1)
_number = []() {
qCWarning(LOG_LIB) << "Number is empty, generate new one";
qsrand(QTime::currentTime().msec());
int n = qrand() % 1000;
qCInfo(LOG_LIB) << "Generated number is" << n;
return n;
}();
m_number = _number;
}
void AbstractExtItem::readConfiguration()
{
qCDebug(LOG_LIB);
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);
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();
}
}
bool AbstractExtItem::tryDelete() const
{
qCDebug(LOG_LIB);
foreach(QString dir, m_dirs) {
bool status = QFile::remove(QString("%1/%2").arg(dir).arg(m_fileName));
qCInfo(LOG_LIB) << "Remove file" << QString("%1/%2").arg(dir).arg(m_fileName) << status;
}
// check if exists
foreach(QString dir, m_dirs)
if (QFile::exists(QString("%1/%2").arg(dir).arg(m_fileName))) return false;
return true;
}
void AbstractExtItem::writeConfiguration() const
{
qCDebug(LOG_LIB);
QSettings settings(QString("%1/%2").arg(m_dirs.first()).arg(m_fileName), 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.endGroup();
settings.sync();
}

View File

@ -15,82 +15,70 @@
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#ifndef EXTUPGRADE_H
#define EXTUPGRADE_H
#ifndef ABSTRACTEXTITEM_H
#define ABSTRACTEXTITEM_H
#include <QDialog>
#include <QProcess>
#include <QInputDialog>
#include <QVariant>
namespace Ui {
class ExtUpgrade;
}
class ExtUpgrade : public QDialog
class AbstractExtItem : public QDialog
{
Q_OBJECT
Q_PROPERTY(int apiVersion READ apiVersion WRITE setApiVersion)
Q_PROPERTY(QString name READ name WRITE setName)
Q_PROPERTY(QString comment READ comment WRITE setComment)
Q_PROPERTY(QString executable READ executable WRITE setExecutable)
Q_PROPERTY(int null READ null WRITE setNull)
Q_PROPERTY(int number READ number WRITE setNumber)
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)
Q_PROPERTY(int number READ number WRITE setNumber)
Q_PROPERTY(QString uniq READ uniq)
public:
explicit ExtUpgrade(QWidget *parent = nullptr, const QString upgradeName = QString(),
const QStringList directories = QStringList(), const bool debugCmd = false);
~ExtUpgrade();
explicit AbstractExtItem(QWidget *parent = nullptr, const QString desktopName = QString(),
const QStringList directories = QStringList());
virtual ~AbstractExtItem();
template <class T> T *copy(const QString _fileName, const int _number);
// get methods
int apiVersion();
QString comment();
QString executable();
QString fileName();
int interval();
QString name();
int null();
int number();
QString tag();
bool isActive();
int apiVersion() const;
QString comment() const;
QStringList directories() const;
QString fileName() const;
int interval() const;
bool isActive() const;
QString name() const;
int number() const;
QString tag(const QString _type) const;
virtual QString uniq() const = 0;
// set methods
void setApiVersion(const int _apiVersion = 0);
void setActive(const bool _state = true);
void setComment(const QString _comment = QString("empty"));
void setExecutable(const QString _executable = QString("/usr/bin/true"));
void setInterval(const int _interval = 1);
void setName(const QString _name = QString("none"));
void setNull(const int _null = 0);
void setNumber(int _number = -1);
void setInterval(const int _interval = 0);
public slots:
void readConfiguration();
int run();
int showConfiguration();
bool tryDelete();
void writeConfiguration();
private slots:
void updateValue();
virtual void readConfiguration();
virtual QVariantHash run() = 0;
virtual int showConfiguration(const QVariant args = QVariant()) = 0;
bool tryDelete() const;
virtual void writeConfiguration() const;
private:
QString m_fileName;
QStringList m_dirs;
bool debug;
QProcess *process = nullptr;
Ui::ExtUpgrade *ui;
virtual void translate() = 0;
// properties
int m_apiVersion = 0;
bool m_active = true;
QString m_comment = QString("empty");
QString m_executable = QString("/usr/bin/true");
int m_interval = 1;
QString m_name = QString("none");
int m_null = 0;
int m_number = -1;
int m_interval = 3600;
int times = 0;
int value = 0;
};
#endif /* EXTUPGRADE_H */
#endif /* ABSTRACTEXTITEM_H */

View File

@ -0,0 +1,115 @@
/***************************************************************************
* 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 "abstractextitemaggregator.h"
#include <KI18n/KLocalizedString>
#include <QHBoxLayout>
#include <QInputDialog>
#include <QLineEdit>
#include "awdebug.h"
AbstractExtItemAggregator::AbstractExtItemAggregator(QWidget *parent)
: QWidget(parent)
{
qCDebug(LOG_LIB);
dialog = new QDialog(this);
widgetDialog = new QListWidget(dialog);
dialogButtons = new QDialogButtonBox(QDialogButtonBox::Open | QDialogButtonBox::Close,
Qt::Vertical, dialog);
copyButton = dialogButtons->addButton(i18n("Copy"), QDialogButtonBox::ActionRole);
createButton = dialogButtons->addButton(i18n("Create"), QDialogButtonBox::ActionRole);
deleteButton = dialogButtons->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, SLOT(editItemButtonPressed(QAbstractButton *)));
connect(dialogButtons, SIGNAL(rejected()), dialog, SLOT(reject()));
connect(widgetDialog, SIGNAL(itemActivated(QListWidgetItem *)),
this, SLOT(editItemActivated(QListWidgetItem *)));
}
AbstractExtItemAggregator::~AbstractExtItemAggregator()
{
qCDebug(LOG_LIB);
delete dialog;
}
QString AbstractExtItemAggregator::getName()
{
qCDebug(LOG_LIB);
bool ok;
QString name = QInputDialog::getText(this, i18n("Enter file name"),
i18n("File name"), QLineEdit::Normal,
QString(""), &ok);
if ((!ok) || (name.isEmpty())) return QString("");
if (!name.endsWith(QString(".desktop"))) name += QString(".desktop");
return name;
}
QVariant AbstractExtItemAggregator::configArgs() const
{
qCDebug(LOG_LIB);
return m_configArgs;
}
void AbstractExtItemAggregator::setConfigArgs(const QVariant _configArgs)
{
qCDebug(LOG_LIB);
qCDebug(LOG_LIB) << "Configuration arguments" << _configArgs;
m_configArgs = _configArgs;
}
void AbstractExtItemAggregator::editItemActivated(QListWidgetItem *item)
{
Q_UNUSED(item)
qCDebug(LOG_LIB);
return editItem();
}
void AbstractExtItemAggregator::editItemButtonPressed(QAbstractButton *button)
{
qCDebug(LOG_LIB);
if (static_cast<QPushButton *>(button) == copyButton)
return copyItem();
else if (static_cast<QPushButton *>(button) == createButton)
return createItem();
else if (static_cast<QPushButton *>(button) == deleteButton)
return deleteItem();
else if (dialogButtons->buttonRole(button) == QDialogButtonBox::AcceptRole)
return editItem();
}

View 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 ABSTRACTEXTITEMAGGREGATOR_H
#define ABSTRACTEXTITEMAGGREGATOR_H
#include <QDialog>
#include <QDialogButtonBox>
#include <QListWidget>
#include <QObject>
#include <QPushButton>
#include <QWidget>
// additinal class since QObject macro does not allow class templates
class AbstractExtItemAggregator : public QWidget
{
Q_OBJECT
Q_PROPERTY(QVariant configArgs READ configArgs WRITE setConfigArgs)
public:
explicit AbstractExtItemAggregator(QWidget *parent = nullptr);
virtual ~AbstractExtItemAggregator();
QString getName();
// ui
QDialog *dialog = nullptr;
QListWidget *widgetDialog = nullptr;
QDialogButtonBox *dialogButtons = nullptr;
QPushButton *copyButton = nullptr;
QPushButton *createButton = nullptr;
QPushButton *deleteButton = nullptr;
// get methods
QVariant configArgs() const;
// set methods
void setConfigArgs(const QVariant _configArgs);
private slots:
void editItemActivated(QListWidgetItem *item);
void editItemButtonPressed(QAbstractButton *button);
private:
QVariant m_configArgs;
// methods
virtual void copyItem() = 0;
virtual void createItem() = 0;
virtual void deleteItem() = 0;
virtual void editItem() = 0;
};
#endif /* ABSTRACTEXTITEMAGGREGATOR_H */

View File

@ -0,0 +1,139 @@
{
"__url": "http://openweathermap.org/weather-conditions",
"image": {
"__comment": "should be described as html image with full path inside",
"default": "",
"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\">"
},
"text": {
"default": "\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"
}
}

View File

@ -9,4 +9,5 @@ X-AW-Type=Horizontal
X-AW-Direction=LeftToRight
X-AW-Height=25
X-AW-Width=100
X-AW-ApiVersion=1
X-AW-ApiVersion=2
X-AW-Number=3

View File

@ -9,4 +9,5 @@ X-AW-Type=Horizontal
X-AW-Direction=LeftToRight
X-AW-Height=25
X-AW-Width=100
X-AW-ApiVersion=1
X-AW-ApiVersion=2
X-AW-Number=0

View File

@ -9,4 +9,5 @@ X-AW-Type=Horizontal
X-AW-Direction=LeftToRight
X-AW-Height=25
X-AW-Width=100
X-AW-ApiVersion=1
X-AW-ApiVersion=2
X-AW-Number=1

View File

@ -9,4 +9,5 @@ X-AW-Type=Horizontal
X-AW-Direction=LeftToRight
X-AW-Height=25
X-AW-Width=100
X-AW-ApiVersion=1
X-AW-ApiVersion=2
X-AW-Number=2

View File

@ -0,0 +1,276 @@
/***************************************************************************
* 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 EXTITEMAGGREGATOR_H
#define EXTITEMAGGREGATOR_H
#include <KI18n/KLocalizedString>
#include <QDir>
#include <QSettings>
#include <QStandardPaths>
#include "awdebug.h"
#include "abstractextitemaggregator.h"
template <class T>
class ExtItemAggregator : public AbstractExtItemAggregator
{
public:
explicit ExtItemAggregator(QWidget *parent, const QString type)
: AbstractExtItemAggregator(parent),
m_type(type)
{
qCDebug(LOG_LIB);
qCDebug(LOG_LIB) << "Type" << type;
qSetMessagePattern(LOG_FORMAT);
initItems();
};
virtual ~ExtItemAggregator()
{
qCDebug(LOG_LIB);
m_items.clear();
}
void editItems()
{
qCDebug(LOG_LIB);
repaint();
int ret = dialog->exec();
qCInfo(LOG_LIB) << "Dialog returns" << ret;
};
void initItems()
{
qCDebug(LOG_LIB);
m_items.clear();
m_items = getItems();
};
T *itemByTag(const QString _tag) const
{
qCDebug(LOG_LIB);
qCDebug(LOG_LIB) << "Tag" << _tag;
T *found = nullptr;
foreach(T *item, m_items) {
if (item->tag() != _tag) continue;
found = item;
break;
}
if (found == nullptr)
qCWarning(LOG_LIB) << "Could not find item by tag" << _tag;
return found;
}
T *itemByTagNumber(const int _number) const
{
qCDebug(LOG_LIB);
qCDebug(LOG_LIB) << "Number" << _number;
T *found = nullptr;
foreach(T *item, m_items) {
if (item->number() != _number) continue;
found = item;
break;
}
if (found == nullptr)
qCWarning(LOG_LIB) << "Could not find item by number" << _number;
return found;
}
T *itemFromWidget() const
{
qCDebug(LOG_LIB);
QListWidgetItem *widgetItem = widgetDialog->currentItem();
if (widgetItem == nullptr) return nullptr;
T *found = nullptr;
foreach(T *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
{
qCDebug(LOG_LIB);
return m_items;
};
int uniqNumber() const
{
qCDebug(LOG_LIB);
QList<int> tagList;
foreach(T *item, m_items) tagList.append(item->number());
int number = 0;
while (tagList.contains(number)) number++;
return number;
};
private:
QList<T *> m_items;
QString m_type;
// init method
QList<T *> getItems()
{
qCDebug(LOG_LIB);
// create directory at $HOME
QString localDir = QString("%1/awesomewidgets/%2")
.arg(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation))
.arg(m_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),
QStandardPaths::LocateDirectory);
QStringList names;
QList<T *> items;
foreach(QString dir, dirs) {
QStringList files = QDir(dir).entryList(QDir::Files, QDir::Name);
foreach(QString file, files) {
if (!file.endsWith(QString(".desktop"))) continue;
if (names.contains(file)) continue;
qCInfo(LOG_LIB) << "Found file" << file << "in" << dir;
names.append(file);
items.append(new T(this, file, dirs));
}
}
// sort items
std::sort(items.begin(), items.end(), [](const T *lhs, const T *rhs){
return lhs->number() < rhs->number();
});
return items;
};
void repaint()
{
qCDebug(LOG_LIB);
widgetDialog->clear();
foreach(T *_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()
{
qCDebug(LOG_LIB);
T *source = itemFromWidget();
QString fileName = getName();
int number = uniqNumber();
if ((source == nullptr) || (fileName.isEmpty())) {
qCWarning(LOG_LIB) << "Nothing to copy";
return;
}
T *newItem = source->copy(fileName, number);
if (newItem->showConfiguration(configArgs()) == 1) {
initItems();
repaint();
}
};
void createItem()
{
qCDebug(LOG_LIB);
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()
{
qCDebug(LOG_LIB);
T *source = itemFromWidget();
if (source == nullptr) {
qCWarning(LOG_LIB) << "Nothing to delete";
return;
};
if (source->tryDelete()) {
initItems();
repaint();
}
};
void editItem()
{
qCDebug(LOG_LIB);
T *source = itemFromWidget();
if (source == nullptr) {
qCWarning(LOG_LIB) << "Nothing to edit";
return;
};
if (source->showConfiguration(configArgs()) == 1) {
initItems();
repaint();
}
};
};
#endif /* EXTITEMAGGREGATOR_H */

View File

@ -0,0 +1,268 @@
/***************************************************************************
* 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 "extquotes.h"
#include "ui_extquotes.h"
#include <KI18n/KLocalizedString>
#include <QDir>
#include <QJsonDocument>
#include <QJsonParseError>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QSettings>
#include <qreplytimeout/qreplytimeout.h>
#include "awdebug.h"
#include "version.h"
ExtQuotes::ExtQuotes(QWidget *parent, const QString quotesName,
const QStringList directories)
: AbstractExtItem(parent, quotesName, directories),
ui(new Ui::ExtQuotes)
{
qCDebug(LOG_LIB);
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;
manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply *)),
this, SLOT(quotesReplyReceived(QNetworkReply *)));
}
ExtQuotes::~ExtQuotes()
{
qCDebug(LOG_LIB);
disconnect(manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(quotesReplyReceived(QNetworkReply *)));
delete manager;
delete ui;
}
ExtQuotes *ExtQuotes::copy(const QString _fileName, const int _number)
{
qCDebug(LOG_LIB);
qCDebug(LOG_LIB) << "File" << _fileName;
qCDebug(LOG_LIB) << "Number" << _number;
ExtQuotes *item = new ExtQuotes(static_cast<QWidget *>(parent()), _fileName, directories());
item->setActive(isActive());
item->setApiVersion(apiVersion());
item->setComment(comment());
item->setInterval(interval());
item->setName(name());
item->setNumber(_number);
item->setTicker(ticker());
return item;
}
QString ExtQuotes::ticker() const
{
qCDebug(LOG_LIB);
return m_ticker;
}
QString ExtQuotes::uniq() const
{
qCDebug(LOG_LIB);
return m_ticker;
}
void ExtQuotes::setTicker(const QString _ticker)
{
qCDebug(LOG_LIB);
qCDebug(LOG_LIB) << "Ticker" << _ticker;
m_ticker = _ticker;
}
void ExtQuotes::readConfiguration()
{
qCDebug(LOG_LIB);
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);
settings.beginGroup(QString("Desktop Entry"));
setTicker(settings.value(QString("X-AW-Ticker"), m_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();
}
}
QVariantHash ExtQuotes::run()
{
qCDebug(LOG_LIB);
if ((!isActive()) || (isRunning)) return values;
if (times == 1) {
qCInfo(LOG_LIB) << "Send request";
isRunning = true;
QNetworkReply *reply = manager->get(QNetworkRequest(QUrl(url())));
new QReplyTimeout(reply, 1000);
}
// update value
if (times >= interval()) times = 0;
times++;
return values;
}
int ExtQuotes::showConfiguration(const QVariant args)
{
Q_UNUSED(args)
qCDebug(LOG_LIB);
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->checkBox_active->setCheckState(isActive() ? Qt::Checked : Qt::Unchecked);
ui->spinBox_interval->setValue(interval());
int ret = exec();
if (ret != 1) return ret;
setName(ui->lineEdit_name->text());
setComment(ui->lineEdit_comment->text());
setNumber(ui->label_numberValue->text().toInt());
setApiVersion(AWEQAPI);
setTicker(ui->lineEdit_ticker->text());
setActive(ui->checkBox_active->checkState() == Qt::Checked);
setInterval(ui->spinBox_interval->value());
writeConfiguration();
return ret;
}
void ExtQuotes::writeConfiguration() const
{
qCDebug(LOG_LIB);
AbstractExtItem::writeConfiguration();
QSettings settings(QString("%1/%2").arg(directories().first()).arg(fileName()), QSettings::IniFormat);
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
settings.beginGroup(QString("Desktop Entry"));
settings.setValue(QString("X-AW-Ticker"), m_ticker);
settings.endGroup();
settings.sync();
}
void ExtQuotes::quotesReplyReceived(QNetworkReply *reply)
{
qCDebug(LOG_LIB);
qCDebug(LOG_LIB) << "Return code" << reply->error();
qCDebug(LOG_LIB) << "Reply error message" << reply->errorString();
isRunning = false;
QJsonParseError error;
QJsonDocument jsonDoc = QJsonDocument::fromJson(reply->readAll(), &error);
reply->deleteLater();
if ((reply->error() != QNetworkReply::NoError) ||
(error.error != QJsonParseError::NoError)) {
qCWarning(LOG_LIB) << "Parse error" << error.errorString();
return;
}
QVariantMap jsonQuotes = jsonDoc.toVariant().toMap()[QString("query")].toMap();
jsonQuotes = jsonQuotes[QString("results")].toMap()[QString("quote")].toMap();
float value;
// ask
value = jsonQuotes[QString("Ask")].toString().toFloat();
values[tag(QString("askchg"))] = values[QString("ask")].toFloat() == 0.0 ? 0.0 :
value - values[QString("ask")].toFloat();
values[tag(QString("percaskchg"))] = 100.0 * values[QString("askchg")].toFloat() / values[QString("ask")].toFloat();
values[tag(QString("ask"))] = value;
// bid
value = jsonQuotes[QString("Bid")].toString().toFloat();
values[tag(QString("bidchg"))] = values[QString("bid")].toFloat() == 0.0 ? 0.0 :
value - values[QString("bid")].toFloat();
values[tag(QString("percbidchg"))] = 100.0 * values[QString("bidchg")].toFloat() / values[QString("bid")].toFloat();
values[tag(QString("bid"))] = value;
// last trade
value = jsonQuotes[QString("LastTradePriceOnly")].toString().toFloat();
values[tag(QString("pricechg"))] = values[QString("price")].toFloat() == 0.0 ? 0.0 :
value - values[QString("price")].toFloat();
values[tag(QString("percpricechg"))] = 100.0 * values[QString("pricechg")].toFloat() / values[QString("price")].toFloat();
values[tag(QString("price"))] = value;
}
void ExtQuotes::translate()
{
qCDebug(LOG_LIB);
ui->label_name->setText(i18n("Name"));
ui->label_comment->setText(i18n("Comment"));
ui->label_number->setText(i18n("Tag"));
ui->label->setText(i18n("<html><head/><body><p>Use YAHOO! finance ticker to get quotes for the instrument. Refer to <a href=\"http://finance.yahoo.com/\"><span style=\" text-decoration: underline; color:#0057ae;\">http://finance.yahoo.com/</span></a></p></body></html>"));
ui->label_ticker->setText(i18n("Ticker"));
ui->checkBox_active->setText(i18n("Active"));
ui->label_interval->setText(i18n("Interval"));
}
QString ExtQuotes::url() const
{
qCDebug(LOG_LIB);
QString apiUrl = QString(YAHOO_URL);
apiUrl.replace(QString("$TICKER"), m_ticker);
qCInfo(LOG_LIB) << "API url" << apiUrl;
return apiUrl;
}

View File

@ -18,97 +18,54 @@
#ifndef EXTQUOTES_H
#define EXTQUOTES_H
#include <QDialog>
#include <QMap>
#include <QNetworkReply>
#include <QTimer>
#include "abstractextitem.h"
#define YAHOO_URL "https://query.yahooapis.com/v1/public/yql?q=select * from yahoo.finance.quotes where symbol=\"$TICKER\"&env=store://datatables.org/alltableswithkeys&format=json"
class QReplyTimeout : public QObject
{
Q_OBJECT
public:
QReplyTimeout(QNetworkReply *reply, const int timeout) : QObject(reply)
{
QTimer::singleShot(timeout, this, SLOT(timeout()));
}
public slots:
void timeout()
{
QNetworkReply *reply = static_cast<QNetworkReply *>(parent());
if (reply->isRunning()) reply->close();
}
};
namespace Ui {
class ExtQuotes;
}
class ExtQuotes : public QDialog
class ExtQuotes : public AbstractExtItem
{
Q_OBJECT
Q_PROPERTY(int apiVersion READ apiVersion WRITE setApiVersion)
Q_PROPERTY(QString name READ name WRITE setName)
Q_PROPERTY(QString comment READ comment WRITE setComment)
Q_PROPERTY(int interval READ interval WRITE setInterval)
Q_PROPERTY(bool active READ isActive WRITE setActive)
Q_PROPERTY(int number READ number WRITE setNumber)
Q_PROPERTY(QString ticker READ ticker WRITE setTicker)
public:
explicit ExtQuotes(QWidget *parent = nullptr, const QString quotesName = QString(),
const QStringList directories = QStringList(), const bool debugCmd = false);
~ExtQuotes();
const QStringList directories = QStringList());
virtual ~ExtQuotes();
ExtQuotes *copy(const QString _fileName, const int _number);
// get methods
int apiVersion();
QString comment();
QString fileName();
int interval();
bool isActive();
QString name();
int number();
QString tag(const QString _type = QString("price"));
QString ticker();
QString ticker() const;
QString uniq() const;
// set methods
void setApiVersion(const int _apiVersion = 0);
void setActive(const bool _state = true);
void setComment(const QString _comment = QString("empty"));
void setInterval(const int _interval = 0);
void setName(const QString _name = QString("none"));
void setNumber(int _number = -1);
void setTicker(const QString _ticker = QString("EURUSD=X"));
public slots:
void readConfiguration();
QMap<QString, float> run();
int showConfiguration();
bool tryDelete();
void writeConfiguration();
QVariantHash run();
int showConfiguration(const QVariant args = QVariant());
void writeConfiguration() const;
private slots:
void quotesReplyReceived(QNetworkReply *reply);
private:
QString m_fileName;
QStringList m_dirs;
bool debug;
QNetworkAccessManager *manager;
bool isRunning = false;
Ui::ExtQuotes *ui;
QString url();
void translate();
QString url() const;
// properties
int m_apiVersion = 0;
bool m_active = true;
QString m_comment = QString("empty");
int m_interval = 60;
QString m_name = QString("none");
int m_number = -1;
QString m_ticker = QString("EURUSD=X");
// values
int times = 0;
QMap<QString, float> values;
QVariantHash values;
};

View File

@ -0,0 +1,437 @@
/***************************************************************************
* 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 "extscript.h"
#include "ui_extscript.h"
#include <KI18n/KLocalizedString>
#include <QDir>
#include <QJsonDocument>
#include <QJsonParseError>
#include <QSettings>
#include <QStandardPaths>
#include <QTextCodec>
#include "awdebug.h"
#include "version.h"
ExtScript::ExtScript(QWidget *parent, const QString scriptName,
const QStringList directories)
: AbstractExtItem(parent, scriptName, directories),
ui(new Ui::ExtScript)
{
qCDebug(LOG_LIB);
readConfiguration();
readJsonFilters();
ui->setupUi(this);
translate();
value[tag(QString("custom"))] = QString("");
process = new QProcess(this);
connect(process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(updateValue()));
process->waitForFinished(0);
}
ExtScript::~ExtScript()
{
qCDebug(LOG_LIB);
process->kill();
delete process;
delete ui;
}
ExtScript *ExtScript::copy(const QString _fileName, const int _number)
{
qCDebug(LOG_LIB);
qCDebug(LOG_LIB) << "File" << _fileName;
qCDebug(LOG_LIB) << "Number" << _number;
ExtScript *item = new ExtScript(static_cast<QWidget *>(parent()), _fileName, directories());
item->setActive(isActive());
item->setApiVersion(apiVersion());
item->setComment(comment());
item->setExecutable(executable());
item->setHasOutput(hasOutput());
item->setInterval(interval());
item->setName(name());
item->setNumber(_number);
item->setPrefix(prefix());
item->setRedirect(redirect());
return item;
}
QString ExtScript::executable() const
{
qCDebug(LOG_LIB);
return m_executable;
}
QStringList ExtScript::filters() const
{
qCDebug(LOG_LIB);
return m_filters;
}
bool ExtScript::hasOutput() const
{
qCDebug(LOG_LIB);
return m_output;
}
QString ExtScript::prefix() const
{
qCDebug(LOG_LIB);
return m_prefix;
}
ExtScript::Redirect ExtScript::redirect() const
{
qCDebug(LOG_LIB);
return m_redirect;
}
QString ExtScript::uniq() const
{
qCDebug(LOG_LIB);
return m_executable;
}
QString ExtScript::strRedirect() const
{
qCDebug(LOG_LIB);
QString value;
switch (m_redirect) {
case stdout2stderr:
value = QString("stdout2stderr");
break;
case stderr2stdout:
value = QString("stderr2stdout");
break;
case nothing:
default:
value = QString("nothing");
break;
}
return value;
}
void ExtScript::setExecutable(const QString _executable)
{
qCDebug(LOG_LIB);
qCDebug(LOG_LIB) << "Executable" << _executable;
m_executable = _executable;
}
void ExtScript::setFilters(const QStringList _filters)
{
qCDebug(LOG_LIB);
qCDebug(LOG_LIB) << "Filters" << _filters;
std::for_each(_filters.cbegin(), _filters.cend(),
[this](QString filter) { return updateFilter(filter); });
// foreach(QString filter, _filters)
// updateFilter(filter);
}
void ExtScript::setHasOutput(const bool _state)
{
qCDebug(LOG_LIB);
qCDebug(LOG_LIB) << "State" << _state;
m_output = _state;
}
void ExtScript::setPrefix(const QString _prefix)
{
qCDebug(LOG_LIB);
qCDebug(LOG_LIB) << "Prefix" << _prefix;
m_prefix = _prefix;
}
void ExtScript::setRedirect(const Redirect _redirect)
{
qCDebug(LOG_LIB);
qCDebug(LOG_LIB) << "Redirect" << _redirect;
m_redirect = _redirect;
}
void ExtScript::setStrRedirect(const QString _redirect)
{
qCDebug(LOG_LIB);
qCDebug(LOG_LIB) << "Redirect" << _redirect;
if (_redirect == QString("stdout2sdterr"))
m_redirect = stdout2stderr;
else if (_redirect == QString("stderr2sdtout"))
m_redirect = stderr2stdout;
else
m_redirect = nothing;
}
QString ExtScript::applyFilters(QString _value) const
{
qCDebug(LOG_LIB);
qCDebug(LOG_LIB) << "Value" << _value;
foreach(QString filt, m_filters) {
qCInfo(LOG_LIB) << "Found filter" << filt;
QVariantMap filter = jsonFilters[filt].toMap();
if (filter.isEmpty()) {
qCWarning(LOG_LIB) << "Could not find filter" << _value << "in the json";
continue;
}
foreach(QString f, filter.keys())
_value.replace(f, filter[f].toString());
}
return _value;
}
void ExtScript::updateFilter(const QString _filter, const bool _add)
{
qCDebug(LOG_LIB);
qCDebug(LOG_LIB) << "Filter" << _filter;
qCDebug(LOG_LIB) << "Should be added" << _add;
if (_add) {
if (m_filters.contains(_filter)) return;
m_filters.append(_filter);
} else {
m_filters.removeOne(_filter);
}
}
void ExtScript::readConfiguration()
{
qCDebug(LOG_LIB);
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);
settings.beginGroup(QString("Desktop Entry"));
setExecutable(settings.value(QString("Exec"), m_executable).toString());
setPrefix(settings.value(QString("X-AW-Prefix"), m_prefix).toString());
setHasOutput(settings.value(QString("X-AW-Output"), QVariant(m_output)).toString() == QString("true"));
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();
}
if (!m_output)
setRedirect(stdout2stderr);
// update for current API
if ((apiVersion() > 0) && (apiVersion() < AWESAPI)) {
qCWarning(LOG_LIB) << "Bump API version from" << apiVersion() << "to" << AWESAPI;
setApiVersion(AWESAPI);
writeConfiguration();
}
}
void ExtScript::readJsonFilters()
{
qCDebug(LOG_LIB);
QString fileName = QStandardPaths::locate(QStandardPaths::GenericDataLocation,
QString("awesomewidgets/scripts/awesomewidgets-extscripts-filters.json"));
qCInfo(LOG_LIB) << "Filters file" << fileName;
QFile jsonFile(fileName);
if (!jsonFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
qCWarning(LOG_LIB) << "Could not open" << fileName;
return;
}
QString jsonText = jsonFile.readAll();
jsonFile.close();
QJsonParseError error;
QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonText.toUtf8(), &error);
if (error.error != QJsonParseError::NoError) {
qCWarning(LOG_LIB) << "Parse error" << error.errorString();
return;
}
jsonFilters = jsonDoc.toVariant().toMap();
qCInfo(LOG_LIB) << "Filters" << jsonFilters;
}
QVariantHash ExtScript::run()
{
qCDebug(LOG_LIB);
if (!isActive()) return value;
if ((times == 1) && (process->state() == QProcess::NotRunning)) {
QStringList cmdList;
if (!m_prefix.isEmpty()) cmdList.append(m_prefix);
cmdList.append(m_executable);
qCInfo(LOG_LIB) << "Run cmd" << cmdList.join(QChar(' '));
process->start(cmdList.join(QChar(' ')));
} else if (times >= interval())
times = 0;
times++;
return value;
}
int ExtScript::showConfiguration(const QVariant args)
{
Q_UNUSED(args)
qCDebug(LOG_LIB);
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->checkBox_active->setCheckState(isActive() ? Qt::Checked : Qt::Unchecked);
ui->checkBox_output->setCheckState(m_output ? Qt::Checked : Qt::Unchecked);
ui->comboBox_redirect->setCurrentIndex(static_cast<int>(m_redirect));
ui->spinBox_interval->setValue(interval());
// filters
ui->checkBox_colorFilter->setCheckState(m_filters.contains(QString("color")) ? Qt::Checked : Qt::Unchecked);
ui->checkBox_linesFilter->setCheckState(m_filters.contains(QString("newline")) ? Qt::Checked : Qt::Unchecked);
ui->checkBox_spaceFilter->setCheckState(m_filters.contains(QString("space")) ? Qt::Checked : Qt::Unchecked);
int ret = exec();
if (ret != 1) return ret;
setName(ui->lineEdit_name->text());
setComment(ui->lineEdit_comment->text());
setNumber(ui->label_numberValue->text().toInt());
setApiVersion(AWESAPI);
setExecutable(ui->lineEdit_command->text());
setPrefix(ui->lineEdit_prefix->text());
setActive(ui->checkBox_active->checkState() == Qt::Checked);
setHasOutput(ui->checkBox_output->checkState() == Qt::Checked);
setStrRedirect(ui->comboBox_redirect->currentText());
setInterval(ui->spinBox_interval->value());
// filters
updateFilter(QString("color"), ui->checkBox_colorFilter->checkState() == Qt::Checked);
updateFilter(QString("newline"), ui->checkBox_linesFilter->checkState() == Qt::Checked);
updateFilter(QString("space"), ui->checkBox_spaceFilter->checkState() == Qt::Checked);
writeConfiguration();
return ret;
}
void ExtScript::writeConfiguration() const
{
qCDebug(LOG_LIB);
AbstractExtItem::writeConfiguration();
QSettings settings(QString("%1/%2").arg(directories().first()).arg(fileName()), 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("X-AW-Output"), QVariant(m_output).toString());
settings.setValue(QString("X-AW-Redirect"), strRedirect());
settings.setValue(QString("X-AW-Filters"), m_filters.join(QChar(',')));
settings.endGroup();
settings.sync();
}
void ExtScript::updateValue()
{
qCDebug(LOG_LIB);
qCInfo(LOG_LIB) << "Cmd returns" << process->exitCode();
QString qdebug = QTextCodec::codecForMib(106)->toUnicode(process->readAllStandardError()).trimmed();
qCInfo(LOG_LIB) << "Error" << qdebug;
QString qoutput = QTextCodec::codecForMib(106)->toUnicode(process->readAllStandardOutput()).trimmed();
qCInfo(LOG_LIB) << "Error" << qoutput;
QString strValue;
switch (m_redirect) {
case stdout2stderr:
break;
case stderr2stdout:
strValue = QString("%1\n%2").arg(qdebug).arg(qoutput);
break;
case nothing:
default:
strValue = qoutput;
break;
}
// filters
value[tag(QString("custom"))] = applyFilters(strValue);
}
void ExtScript::translate()
{
qCDebug(LOG_LIB);
ui->label_name->setText(i18n("Name"));
ui->label_comment->setText(i18n("Comment"));
ui->label_number->setText(i18n("Tag"));
ui->label_command->setText(i18n("Command"));
ui->label_prefix->setText(i18n("Prefix"));
ui->checkBox_active->setText(i18n("Active"));
ui->checkBox_output->setText(i18n("Has output"));
ui->label_redirect->setText(i18n("Redirect"));
ui->label_interval->setText(i18n("Interval"));
ui->groupBox_filters->setTitle(i18n("Additional filters"));
ui->checkBox_colorFilter->setText(i18n("Wrap colors"));
ui->checkBox_linesFilter->setText(i18n("Wrap new lines"));
ui->checkBox_spaceFilter->setText(i18n("Wrap spaces"));
}

View File

@ -18,26 +18,21 @@
#ifndef EXTSCRIPT_H
#define EXTSCRIPT_H
#include <QDialog>
#include <QMap>
#include <QProcess>
#include "abstractextitem.h"
namespace Ui {
class ExtScript;
}
class ExtScript : public QDialog
class ExtScript : public AbstractExtItem
{
Q_OBJECT
Q_PROPERTY(bool active READ isActive WRITE setActive)
Q_PROPERTY(int apiVersion READ apiVersion WRITE setApiVersion)
Q_PROPERTY(QString comment READ comment WRITE setComment)
Q_PROPERTY(QString executable READ executable WRITE setExecutable)
Q_PROPERTY(QStringList filters READ filters WRITE setFilters)
Q_PROPERTY(int interval READ interval WRITE setInterval)
Q_PROPERTY(QString name READ name WRITE setName)
Q_PROPERTY(int number READ number WRITE setNumber)
Q_PROPERTY(bool output READ hasOutput WRITE setHasOutput)
Q_PROPERTY(QString prefix READ prefix WRITE setPrefix)
Q_PROPERTY(Redirect redirect READ redirect WRITE setRedirect)
@ -50,67 +45,46 @@ public:
};
explicit ExtScript(QWidget *parent = nullptr, const QString scriptName = QString(),
const QStringList directories = QStringList(), const bool debugCmd = false);
~ExtScript();
const QStringList directories = QStringList());
virtual ~ExtScript();
ExtScript *copy(const QString _fileName, const int _number);
// get methods
int apiVersion();
QString comment();
QString executable();
QString fileName();
QStringList filters();
bool hasOutput();
int interval();
bool isActive();
QString name();
int number();
QString prefix();
Redirect redirect();
QString executable() const;
QStringList filters() const;
bool hasOutput() const;
QString prefix() const;
Redirect redirect() const;
QString uniq() const;
// derivatives
QString strRedirect();
QString tag();
QString strRedirect() const;
// set methods
void setApiVersion(const int _apiVersion = 0);
void setActive(const bool _state = true);
void setComment(const QString _comment = QString("empty"));
void setExecutable(const QString _executable = QString("/usr/bin/true"));
void setFilters(const QStringList _filters = QStringList());
void setHasOutput(const bool _state = true);
void setInterval(const int _interval = 1);
void setName(const QString _name = QString("none"));
void setNumber(int _number = -1);
void setPrefix(const QString _prefix = QString(""));
void setRedirect(const Redirect _redirect = nothing);
void setStrRedirect(const QString _redirect = QString("nothing"));
// filters
QString applyFilters(QString _value);
QString applyFilters(QString _value) const;
void updateFilter(const QString _filter, const bool _add = true);
public slots:
void readConfiguration();
void readJsonFilters();
QString run();
int showConfiguration();
bool tryDelete();
void writeConfiguration();
QVariantHash run();
int showConfiguration(const QVariant args = QVariant());
void writeConfiguration() const;
private slots:
void updateValue();
private:
QString m_fileName;
QStringList m_dirs;
bool debug;
QProcess *process = nullptr;
Ui::ExtScript *ui;
void translate();
// properties
int m_apiVersion = 0;
bool m_active = true;
QString m_comment = QString("empty");
QString m_executable = QString("/usr/bin/true");
QStringList m_filters = QStringList();
int m_interval = 1;
QString m_name = QString("none");
int m_number = -1;
bool m_output = true;
QString m_prefix = QString("");
Redirect m_redirect = nothing;
@ -118,7 +92,7 @@ private:
Q_PID childProcess = 0;
QVariantMap jsonFilters = QVariantMap();
int times = 0;
QString value = QString();
QVariantHash value;
};

View File

@ -0,0 +1,262 @@
/***************************************************************************
* 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 "extupgrade.h"
#include "ui_extupgrade.h"
#include <KI18n/KLocalizedString>
#include <QDir>
#include <QRegExp>
#include <QSettings>
#include <QTextCodec>
#include "awdebug.h"
#include "version.h"
ExtUpgrade::ExtUpgrade(QWidget *parent, const QString upgradeName,
const QStringList directories)
: AbstractExtItem(parent, upgradeName, directories),
ui(new Ui::ExtUpgrade)
{
qCDebug(LOG_LIB);
readConfiguration();
ui->setupUi(this);
translate();
value[tag(QString("pkgcount"))] = 0;
process = new QProcess(this);
connect(process, SIGNAL(finished(int)), this, SLOT(updateValue()));
process->waitForFinished(0);
}
ExtUpgrade::~ExtUpgrade()
{
qCDebug(LOG_LIB);
process->kill();
delete process;
delete ui;
}
ExtUpgrade *ExtUpgrade::copy(const QString _fileName, const int _number)
{
qCDebug(LOG_LIB);
qCDebug(LOG_LIB) << "File" << _fileName;
qCDebug(LOG_LIB) << "Number" << _number;
ExtUpgrade *item = new ExtUpgrade(static_cast<QWidget *>(parent()), _fileName, directories());
item->setActive(isActive());
item->setApiVersion(apiVersion());
item->setComment(comment());
item->setExecutable(executable());
item->setFilter(filter());
item->setInterval(interval());
item->setName(name());
item->setNumber(_number);
item->setNull(null());
return item;
}
QString ExtUpgrade::executable() const
{
qCDebug(LOG_LIB);
return m_executable;
}
QString ExtUpgrade::filter() const
{
qCDebug(LOG_LIB);
return m_filter;
}
int ExtUpgrade::null() const
{
qCDebug(LOG_LIB);
return m_null;
}
QString ExtUpgrade::uniq() const
{
qCDebug(LOG_LIB);
return m_executable;
}
void ExtUpgrade::setExecutable(const QString _executable)
{
qCDebug(LOG_LIB);
qCDebug(LOG_LIB) << "Executable" << _executable;
m_executable = _executable;
}
void ExtUpgrade::setFilter(const QString _filter)
{
qCDebug(LOG_LIB);
qCDebug(LOG_LIB) << "Filter" << _filter;
m_filter = _filter;
}
void ExtUpgrade::setNull(const int _null)
{
qCDebug(LOG_LIB);
qCDebug(LOG_LIB) << "Null lines" << _null;
if (_null < 0) return;
m_null = _null;
}
void ExtUpgrade::readConfiguration()
{
qCDebug(LOG_LIB);
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);
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();
}
// update for current API
if ((apiVersion() > 0) && (apiVersion() < AWEUAPI)) {
qCWarning(LOG_LIB) << "Bump API version from" << apiVersion() << "to" << AWEUAPI;
setApiVersion(AWEUAPI);
writeConfiguration();
}
}
QVariantHash ExtUpgrade::run()
{
qCDebug(LOG_LIB);
if (!isActive()) return value;
if ((times == 1) && (process->state() == QProcess::NotRunning)) {
QString cmd = QString("sh -c \"%1\"").arg(m_executable);
qCInfo(LOG_LIB) << "Run cmd" << cmd;
process->start(cmd);
} else if (times >= interval())
times = 0;
times++;
return value;
}
int ExtUpgrade::showConfiguration(const QVariant args)
{
Q_UNUSED(args)
qCDebug(LOG_LIB);
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->checkBox_active->setCheckState(isActive() ? Qt::Checked : Qt::Unchecked);
ui->spinBox_null->setValue(m_null);
ui->spinBox_interval->setValue(interval());
int ret = exec();
if (ret != 1) return ret;
setName(ui->lineEdit_name->text());
setComment(ui->lineEdit_comment->text());
setNumber(ui->label_numberValue->text().toInt());
setApiVersion(AWEUAPI);
setExecutable(ui->lineEdit_command->text());
setFilter(ui->lineEdit_filter->text());
setActive(ui->checkBox_active->checkState() == Qt::Checked);
setNull(ui->spinBox_null->value());
setInterval(ui->spinBox_interval->value());
writeConfiguration();
return ret;
}
void ExtUpgrade::writeConfiguration() const
{
qCDebug(LOG_LIB);
AbstractExtItem::writeConfiguration();
QSettings settings(QString("%1/%2").arg(directories().first()).arg(fileName()), 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.endGroup();
settings.sync();
}
void ExtUpgrade::updateValue()
{
qCDebug(LOG_LIB);
qCInfo(LOG_LIB) << "Cmd returns" << process->exitCode();
qCInfo(LOG_LIB) << "Error" << process->readAllStandardError();
QString qoutput = QTextCodec::codecForMib(106)->toUnicode(process->readAllStandardOutput()).trimmed();
value[tag(QString("pkgcount"))] = [this](QString output) {
return m_filter.isEmpty() ?
output.split(QChar('\n'), QString::SkipEmptyParts).count() - m_null :
output.split(QChar('\n'), QString::SkipEmptyParts).filter(QRegExp(m_filter)).count();
}(qoutput);
}
void ExtUpgrade::translate()
{
qCDebug(LOG_LIB);
ui->label_name->setText(i18n("Name"));
ui->label_comment->setText(i18n("Comment"));
ui->label_number->setText(i18n("Tag"));
ui->label_command->setText(i18n("Command"));
ui->label_filter->setText(i18n("Filter"));
ui->checkBox_active->setText(i18n("Active"));
ui->label_null->setText(i18n("Null"));
ui->label_interval->setText(i18n("Interval"));
}

View File

@ -0,0 +1,75 @@
/***************************************************************************
* 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 EXTUPGRADE_H
#define EXTUPGRADE_H
#include <QProcess>
#include "abstractextitem.h"
namespace Ui {
class ExtUpgrade;
}
class ExtUpgrade : public AbstractExtItem
{
Q_OBJECT
Q_PROPERTY(QString executable READ executable WRITE setExecutable)
Q_PROPERTY(QString filter READ filter WRITE setFilter)
Q_PROPERTY(int null READ null WRITE setNull)
public:
explicit ExtUpgrade(QWidget *parent = nullptr, const QString upgradeName = QString(),
const QStringList directories = QStringList());
virtual ~ExtUpgrade();
ExtUpgrade *copy(const QString _fileName, const int _number);
// get methods
QString executable() const;
QString filter() const;
int null() const;
QString uniq() const;
// set methods
void setExecutable(const QString _executable = QString("/usr/bin/true"));
void setFilter(const QString _filter = QString());
void setNull(const int _null = 0);
public slots:
void readConfiguration();
QVariantHash run();
int showConfiguration(const QVariant args = QVariant());
void writeConfiguration() const;
private slots:
void updateValue();
private:
QProcess *process = nullptr;
Ui::ExtUpgrade *ui;
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;
};
#endif /* EXTUPGRADE_H */

View File

@ -104,6 +104,29 @@
</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_active">
<item>

View File

@ -0,0 +1,395 @@
/***************************************************************************
* 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 "extweather.h"
#include "ui_extweather.h"
#include <KI18n/KLocalizedString>
#include <QDir>
#include <QJsonDocument>
#include <QJsonParseError>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QSettings>
#include <QStandardPaths>
#include <qreplytimeout/qreplytimeout.h>
#include "awdebug.h"
#include "version.h"
ExtWeather::ExtWeather(QWidget *parent, const QString weatherName,
const QStringList directories)
: AbstractExtItem(parent, weatherName, directories),
ui(new Ui::ExtWeather)
{
qCDebug(LOG_LIB);
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;
manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply *)),
this, SLOT(weatherReplyReceived(QNetworkReply *)));
}
ExtWeather::~ExtWeather()
{
qCDebug(LOG_LIB);
disconnect(manager, SIGNAL(finished(QNetworkReply *)),
this, SLOT(weatherReplyReceived(QNetworkReply *)));
delete manager;
delete ui;
}
ExtWeather *ExtWeather::copy(const QString _fileName, const int _number)
{
qCDebug(LOG_LIB);
qCDebug(LOG_LIB) << "File" << _fileName;
qCDebug(LOG_LIB) << "Number" << _number;
ExtWeather *item = new ExtWeather(static_cast<QWidget *>(parent()), _fileName, directories());
item->setActive(isActive());
item->setApiVersion(apiVersion());
item->setCity(city());
item->setComment(comment());
item->setCountry(country());
item->setInterval(interval());
item->setImage(image());
item->setName(name());
item->setNumber(_number);
item->setTs(ts());
return item;
}
QString ExtWeather::weatherFromInt(const int _id) const
{
qCDebug(LOG_LIB);
qCDebug(LOG_LIB) << "Weather ID" << _id;
QVariantMap map = jsonMap[m_image ? QString("image") : QString("text")].toMap();
return map.value(QString::number(_id), map[QString("default")]).toString();
}
QString ExtWeather::city() const
{
qCDebug(LOG_LIB);
return m_city;
}
QString ExtWeather::country() const
{
qCDebug(LOG_LIB);
return m_country;
}
bool ExtWeather::image() const
{
qCDebug(LOG_LIB);
return m_image;
}
int ExtWeather::ts() const
{
qCDebug(LOG_LIB);
return m_ts;
}
QString ExtWeather::uniq() const
{
qCDebug(LOG_LIB);
return QString("%1 (%2) at %3").arg(m_city).arg(m_country).arg(m_ts);
}
void ExtWeather::setCity(const QString _city)
{
qCDebug(LOG_LIB);
qCDebug(LOG_LIB) << "City" << _city;
m_city = _city;
}
void ExtWeather::setCountry(const QString _country)
{
qCDebug(LOG_LIB);
qCDebug(LOG_LIB) << "Country" << _country;
m_country = _country;
}
void ExtWeather::setImage(const bool _image)
{
qCDebug(LOG_LIB);
qCDebug(LOG_LIB) << "Use image" << _image;
m_image = _image;
}
void ExtWeather::setTs(const int _ts)
{
qCDebug(LOG_LIB);
qCDebug(LOG_LIB) << "Timestamp" << _ts;
m_ts = _ts;
}
void ExtWeather::readConfiguration()
{
qCDebug(LOG_LIB);
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);
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();
}
// update for current API
if ((apiVersion() > 0) && (apiVersion() < AWEWAPI)) {
qCWarning(LOG_LIB) << "Bump API version from" << apiVersion() << "to" << AWEWAPI;
setApiVersion(AWEWAPI);
writeConfiguration();
}
}
void ExtWeather::readJsonMap()
{
qCDebug(LOG_LIB);
QString fileName = QStandardPaths::locate(QStandardPaths::GenericDataLocation,
QString("awesomewidgets/weather/awesomewidgets-extweather-ids.json"));
qCInfo(LOG_LIB) << "Map file" << fileName;
QFile jsonFile(fileName);
if (!jsonFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
qCWarning(LOG_LIB) << "Could not open" << fileName;
return;
}
QString jsonText = jsonFile.readAll();
jsonFile.close();
QJsonParseError error;
QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonText.toUtf8(), &error);
if (error.error != QJsonParseError::NoError) {
qCWarning(LOG_LIB) << "Parse error" << error.errorString();
return;
}
jsonMap = jsonDoc.toVariant().toMap();
qCInfo(LOG_LIB) << "Weather map" << jsonMap;
}
QVariantHash ExtWeather::run()
{
qCDebug(LOG_LIB);
if ((!isActive()) || (isRunning)) return values;
if (times == 1) {
qCInfo(LOG_LIB) << "Send request";
isRunning = true;
QNetworkReply *reply = manager->get(QNetworkRequest(QUrl(url(m_ts != 0))));
new QReplyTimeout(reply, 1000);
}
// update value
if (times >= interval()) times = 0;
times++;
return values;
}
int ExtWeather::showConfiguration(const QVariant args)
{
Q_UNUSED(args)
qCDebug(LOG_LIB);
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->checkBox_active->setCheckState(isActive() ? Qt::Checked : Qt::Unchecked);
ui->spinBox_interval->setValue(interval());
int ret = exec();
if (ret != 1) return ret;
setName(ui->lineEdit_name->text());
setComment(ui->lineEdit_comment->text());
setNumber(ui->label_numberValue->text().toInt());
setApiVersion(AWEWAPI);
setCity(ui->lineEdit_city->text());
setCountry(ui->lineEdit_country->text());
setTs(ui->spinBox_timestamp->value());
setImage(ui->checkBox_image->checkState() == Qt::Checked);
setActive(ui->checkBox_active->checkState() == Qt::Checked);
setInterval(ui->spinBox_interval->value());
writeConfiguration();
return ret;
}
void ExtWeather::writeConfiguration() const
{
qCDebug(LOG_LIB);
AbstractExtItem::writeConfiguration();
QSettings settings(QString("%1/%2").arg(directories().first()).arg(fileName()), 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.endGroup();
settings.sync();
}
void ExtWeather::weatherReplyReceived(QNetworkReply *reply)
{
qCDebug(LOG_LIB);
qCDebug(LOG_LIB) << "Return code" << reply->error();
qCDebug(LOG_LIB) << "Reply error message" << reply->errorString();
isRunning = false;
QJsonParseError error;
QJsonDocument jsonDoc = QJsonDocument::fromJson(reply->readAll(), &error);
reply->deleteLater();
if ((reply->error() != QNetworkReply::NoError) ||
(error.error != QJsonParseError::NoError)) {
qCWarning(LOG_LIB) << "Parse error" << error.errorString();
return;
}
// convert to map
QVariantMap json = jsonDoc.toVariant().toMap();
if (json[QString("cod")].toInt() != 200) {
qCWarning(LOG_LIB) << "Invalid return code";
return;
}
QVariantHash data;
if (m_ts == 0)
data = parseSingleJson(json);
else {
QVariantList list = json[QString("list")].toList();
data = parseSingleJson(list.count() <= m_ts ? list.at(m_ts-1).toMap() : list.last().toMap());
}
foreach(QString key, data.keys()) values[tag(key)] = data[key];
}
QVariantHash ExtWeather::parseSingleJson(const QVariantMap json) const
{
qCDebug(LOG_LIB);
qCDebug(LOG_LIB) << "Single json data" << json;
QVariantHash output;
// weather status
QVariantList weather = json[QString("weather")].toList();
if (!weather.isEmpty()) {
int _id = weather.first().toMap()[QString("id")].toInt();
output[QString("weatherId")] = _id;
output[QString("weather")] = weatherFromInt(_id);
}
// main data
QVariantMap mainWeather = json[QString("main")].toMap();
if (!weather.isEmpty()) {
output[QString("humidity")] = mainWeather[QString("humidity")].toFloat();
output[QString("pressure")] = mainWeather[QString("pressure")].toFloat();
output[QString("temperature")] = mainWeather[QString("temp")].toFloat();
}
return output;
}
void ExtWeather::translate()
{
qCDebug(LOG_LIB);
ui->label_name->setText(i18n("Name"));
ui->label_comment->setText(i18n("Comment"));
ui->label_number->setText(i18n("Tag"));
ui->label_city->setText(i18n("City"));
ui->label_country->setText(i18n("Country"));
ui->label_timestamp->setText(i18n("Timestamp"));
ui->checkBox_image->setText(i18n("Use images"));
ui->checkBox_active->setText(i18n("Active"));
ui->label_interval->setText(i18n("Interval"));
}
QString ExtWeather::url(const bool isForecast) const
{
qCDebug(LOG_LIB);
qCDebug(LOG_LIB) << "Is forecast" << isForecast;
QString apiUrl = isForecast ? QString(OWM_FORECAST_URL) : QString(OWM_URL);
apiUrl.replace(QString("$CITY"), m_city);
apiUrl.replace(QString("$COUNTRY"), m_country);
qCInfo(LOG_LIB) << "API url" << apiUrl;
return apiUrl;
}

View File

@ -0,0 +1,89 @@
/***************************************************************************
* 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 EXTWEATHER_H
#define EXTWEATHER_H
#include <QMap>
#include <QNetworkReply>
#include "abstractextitem.h"
#define OWM_URL "http://api.openweathermap.org/data/2.5/weather?q=$CITY,$COUNTRY&units=metric"
#define OWM_FORECAST_URL "http://api.openweathermap.org/data/2.5/forecast?q=$CITY,$COUNTRY&units=metric"
namespace Ui {
class ExtWeather;
}
class ExtWeather : public AbstractExtItem
{
Q_OBJECT
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(int ts READ ts WRITE setTs)
public:
explicit ExtWeather(QWidget *parent = nullptr, const QString weatherName = QString(),
const QStringList directories = QStringList());
virtual ~ExtWeather();
ExtWeather *copy(const QString _fileName, const int _number);
QString weatherFromInt(const int _id) const;
// get methods
QString city() const;
QString country() const;
bool image() 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 setTs(const int _ts = 0);
public slots:
void readConfiguration();
void readJsonMap();
QVariantHash run();
int showConfiguration(const QVariant args = QVariant());
void writeConfiguration() const;
private slots:
void weatherReplyReceived(QNetworkReply *reply);
private:
QNetworkAccessManager *manager;
bool isRunning = false;
Ui::ExtWeather *ui;
QVariantHash parseSingleJson(const QVariantMap json) const;
void translate();
QString url(const bool isForecast = false) const;
// properties
QString m_city = QString("London");
QString m_country = QString("uk");
bool m_image = false;
int m_ts = 0;
QVariantMap jsonMap = QVariantMap();
// values
int times = 0;
QVariantHash values;
};
#endif /* EXTWEATHER_H */

View File

@ -0,0 +1,301 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ExtWeather</class>
<widget class="QDialog" name="ExtWeather">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>420</width>
<height>301</height>
</rect>
</property>
<property name="windowTitle">
<string>Configuration</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="layout_name">
<item>
<widget class="QLabel" name="label_name">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Name</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_name"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_comment">
<item>
<widget class="QLabel" name="label_comment">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Comment</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_comment"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_number">
<item>
<widget class="QLabel" name="label_number">
<property name="text">
<string>Tag</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_numberValue">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_city">
<item>
<widget class="QLabel" name="label_city">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>City</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_city"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_country">
<item>
<widget class="QLabel" name="label_country">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Country</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_country"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_timestamp">
<item>
<widget class="QLabel" name="label_timestamp">
<property name="text">
<string>Timestamp</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBox_timestamp">
<property name="maximum">
<number>40</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_image">
<item>
<spacer name="spacer_image">
<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_image">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Use images</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_active">
<item>
<spacer name="spacer_active">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="checkBox_active">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Active</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_interval">
<item>
<widget class="QLabel" name="label_interval">
<property name="text">
<string>Interval</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBox_interval">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>10000</number>
</property>
<property name="singleStep">
<number>10</number>
</property>
<property name="value">
<number>60</number>
</property>
</widget>
</item>
</layout>
</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>ExtWeather</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>ExtWeather</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>

View File

@ -22,28 +22,27 @@
#include <QBuffer>
#include <QColorDialog>
#include <QDebug>
#include <QDir>
#include <QGraphicsEllipseItem>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QSettings>
#include <pdebug/pdebug.h>
#include "awdebug.h"
#include "version.h"
GraphicalItem::GraphicalItem(QWidget *parent, const QString desktopName, const QStringList directories, const bool debugCmd)
: QDialog(parent),
m_fileName(desktopName),
m_dirs(directories),
debug(debugCmd),
GraphicalItem::GraphicalItem(QWidget *parent, const QString desktopName,
const QStringList directories)
: AbstractExtItem(parent, desktopName, directories),
ui(new Ui::GraphicalItem)
{
readConfiguration();
qCDebug(LOG_LIB);
readConfiguration();
ui->setupUi(this);
translate();
connect(ui->pushButton_activeColor, SIGNAL(clicked()), this, SLOT(changeColor()));
connect(ui->pushButton_inactiveColor, SIGNAL(clicked()), this, SLOT(changeColor()));
}
@ -51,22 +50,47 @@ GraphicalItem::GraphicalItem(QWidget *parent, const QString desktopName, const Q
GraphicalItem::~GraphicalItem()
{
if (debug) qDebug() << PDEBUG;
qCDebug(LOG_LIB);
delete ui;
}
QString GraphicalItem::image(const float value)
GraphicalItem *GraphicalItem::copy(const QString _fileName, const int _number)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Value" << value;
qCDebug(LOG_LIB);
qCDebug(LOG_LIB) << "File" << _fileName;
qCDebug(LOG_LIB) << "Number" << _number;
GraphicalItem *item = new GraphicalItem(static_cast<QWidget *>(parent()), _fileName, directories());
item->setActive(isActive());
item->setActiveColor(activeColor());
item->setApiVersion(apiVersion());
item->setBar(bar());
item->setComment(comment());
item->setDirection(direction());
item->setHeight(height());
item->setInactiveColor(inactiveColor());
item->setInterval(interval());
item->setName(QString("bar%1").arg(_number));
item->setNumber(_number);
item->setType(type());
item->setWidth(width());
return item;
}
QString GraphicalItem::image(const float value) const
{
qCDebug(LOG_LIB);
qCDebug(LOG_LIB) << "Value" << value;
if (m_bar == QString("none")) return QString("");
QColor active = stringToColor(m_activeColor);
QColor inactive = stringToColor(m_inactiveColor);
float percent = value / 100.0;
int scale[2] = {1, 1};
int scale[2] = { 1, 1 };
QPen pen = QPen();
QGraphicsScene *scene = new QGraphicsScene();
scene->setBackgroundBrush(QBrush(Qt::NoBrush));
@ -137,73 +161,49 @@ QString GraphicalItem::image(const float value)
}
QString GraphicalItem::fileName()
QString GraphicalItem::bar() const
{
if (debug) qDebug() << PDEBUG;
return m_fileName;
}
int GraphicalItem::apiVersion()
{
if (debug) qDebug() << PDEBUG;
return m_apiVersion;
}
QString GraphicalItem::name()
{
if (debug) qDebug() << PDEBUG;
return m_name;
}
QString GraphicalItem::comment()
{
if (debug) qDebug() << PDEBUG;
return m_comment;
}
QString GraphicalItem::bar()
{
if (debug) qDebug() << PDEBUG;
qCDebug(LOG_LIB);
return m_bar;
}
QString GraphicalItem::activeColor()
QString GraphicalItem::activeColor() const
{
if (debug) qDebug() << PDEBUG;
qCDebug(LOG_LIB);
return m_activeColor;
}
QString GraphicalItem::inactiveColor()
QString GraphicalItem::inactiveColor() const
{
if (debug) qDebug() << PDEBUG;
qCDebug(LOG_LIB);
return m_inactiveColor;
}
GraphicalItem::Type GraphicalItem::type()
QString GraphicalItem::tag() const
{
if (debug) qDebug() << PDEBUG;
qCDebug(LOG_LIB);
return name() + m_bar;
}
GraphicalItem::Type GraphicalItem::type() const
{
qCDebug(LOG_LIB);
return m_type;
}
QString GraphicalItem::strType()
QString GraphicalItem::strType() const
{
if (debug) qDebug() << PDEBUG;
qCDebug(LOG_LIB);
QString value;
switch (m_type) {
@ -222,17 +222,17 @@ QString GraphicalItem::strType()
}
GraphicalItem::Direction GraphicalItem::direction()
GraphicalItem::Direction GraphicalItem::direction() const
{
if (debug) qDebug() << PDEBUG;
qCDebug(LOG_LIB);
return m_direction;
}
QString GraphicalItem::strDirection()
QString GraphicalItem::strDirection() const
{
if (debug) qDebug() << PDEBUG;
qCDebug(LOG_LIB);
QString value;
switch (m_direction) {
@ -248,70 +248,47 @@ QString GraphicalItem::strDirection()
}
int GraphicalItem::height()
int GraphicalItem::height() const
{
if (debug) qDebug() << PDEBUG;
qCDebug(LOG_LIB);
return m_height;
}
int GraphicalItem::width()
int GraphicalItem::width() const
{
if (debug) qDebug() << PDEBUG;
qCDebug(LOG_LIB);
return m_width;
}
void GraphicalItem::setApiVersion(const int _apiVersion)
QString GraphicalItem::uniq() const
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Version" << _apiVersion;
qCDebug(LOG_LIB);
m_apiVersion = _apiVersion;
}
void GraphicalItem::setName(const QString _name)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Name" << _name;
m_name = _name;
}
void GraphicalItem::setComment(const QString _comment)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Comment" << _comment;
m_comment = _comment;
return m_bar;
}
void GraphicalItem::setBar(const QString _bar)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Bar" << _bar;
qCDebug(LOG_LIB);
qCDebug(LOG_LIB) << "Bar" << _bar;
if ((!_bar.contains(QRegExp(QString("cpu(?!cl).*")))) &&
(!_bar.contains(QRegExp(QString("gpu")))) &&
(!_bar.contains(QRegExp(QString("mem")))) &&
(!_bar.contains(QRegExp(QString("swap")))) &&
(!_bar.contains(QRegExp(QString("hdd[0-9].*")))) &&
(!_bar.contains(QRegExp(QString("bat.*")))))
if (!_bar.contains(QRegExp(QString("^(cpu(?!cl).*|gpu$|mem$|swap$|hdd[0-9].*|bat.*)")))) {
qCWarning(LOG_LIB) << "Unsupported bar type" << _bar;
m_bar = QString("none");
else
} else
m_bar = _bar;
}
void GraphicalItem::setActiveColor(const QString _color)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Color" << _color;
qCDebug(LOG_LIB);
qCDebug(LOG_LIB) << "Color" << _color;
m_activeColor = _color;
}
@ -319,8 +296,8 @@ void GraphicalItem::setActiveColor(const QString _color)
void GraphicalItem::setInactiveColor(const QString _color)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Color" << _color;
qCDebug(LOG_LIB);
qCDebug(LOG_LIB) << "Color" << _color;
m_inactiveColor = _color;
}
@ -328,8 +305,8 @@ void GraphicalItem::setInactiveColor(const QString _color)
void GraphicalItem::setType(const Type _type)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Type" << _type;
qCDebug(LOG_LIB);
qCDebug(LOG_LIB) << "Type" << _type;
m_type = _type;
}
@ -337,8 +314,8 @@ void GraphicalItem::setType(const Type _type)
void GraphicalItem::setStrType(const QString _type)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Type" << _type;
qCDebug(LOG_LIB);
qCDebug(LOG_LIB) << "Type" << _type;
if (_type == QString("Vertical"))
setType(Vertical);
@ -351,8 +328,8 @@ void GraphicalItem::setStrType(const QString _type)
void GraphicalItem::setDirection(const Direction _direction)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Direction" << _direction;
qCDebug(LOG_LIB);
qCDebug(LOG_LIB) << "Direction" << _direction;
m_direction = _direction;
}
@ -360,8 +337,8 @@ void GraphicalItem::setDirection(const Direction _direction)
void GraphicalItem::setStrDirection(const QString _direction)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Direction" << _direction;
qCDebug(LOG_LIB);
qCDebug(LOG_LIB) << "Direction" << _direction;
if (_direction == QString("RightToLeft"))
setDirection(RightToLeft);
@ -372,8 +349,8 @@ void GraphicalItem::setStrDirection(const QString _direction)
void GraphicalItem::setHeight(const int _height)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Height" << _height;
qCDebug(LOG_LIB);
qCDebug(LOG_LIB) << "Height" << _height;
if (_height <= 0) return;
m_height = _height;
@ -382,8 +359,8 @@ void GraphicalItem::setHeight(const int _height)
void GraphicalItem::setWidth(const int _width)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Width" << _width;
qCDebug(LOG_LIB);
qCDebug(LOG_LIB) << "Width" << _width;
if (_width <= 0) return;
m_width = _width;
@ -392,16 +369,14 @@ void GraphicalItem::setWidth(const int _width)
void GraphicalItem::readConfiguration()
{
if (debug) qDebug() << PDEBUG;
qCDebug(LOG_LIB);
AbstractExtItem::readConfiguration();
for (int i=m_dirs.count()-1; i>=0; i--) {
if (!QDir(m_dirs[i]).entryList(QDir::Files).contains(m_fileName)) continue;
QSettings settings(QString("%1/%2").arg(m_dirs[i]).arg(m_fileName), QSettings::IniFormat);
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);
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"), AWGIAPI).toInt());
setBar(settings.value(QString("X-AW-Value"), m_bar).toString());
setActiveColor(settings.value(QString("X-AW-ActiveColor"), m_activeColor).toString());
setInactiveColor(settings.value(QString("X-AW-InactiveColor"), m_inactiveColor).toString());
@ -409,17 +384,37 @@ void GraphicalItem::readConfiguration()
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();
}
// update for current API
if ((apiVersion() > 0) && (apiVersion() < AWGIAPI)) {
qCWarning(LOG_LIB) << "Bump API version from" << apiVersion() << "to" << AWGIAPI;
setApiVersion(AWGIAPI);
writeConfiguration();
}
}
int GraphicalItem::showConfiguration(const QStringList tags)
QVariantHash GraphicalItem::run()
{
if (debug) qDebug() << PDEBUG;
qCDebug(LOG_LIB);
ui->label_nameValue->setText(m_name);
ui->lineEdit_comment->setText(m_comment);
// required by abstract class
return QVariantHash();
}
int GraphicalItem::showConfiguration(const QVariant args)
{
qCDebug(LOG_LIB);
qCDebug(LOG_LIB) << "Combobox arguments" << args;
QStringList tags = args.toStringList();
ui->label_nameValue->setText(name());
ui->lineEdit_comment->setText(comment());
ui->comboBox_value->addItems(tags);
ui->comboBox_value->addItem(m_bar);
ui->comboBox_value->setCurrentIndex(ui->comboBox_value->count() - 1);
@ -449,33 +444,15 @@ int GraphicalItem::showConfiguration(const QStringList tags)
}
bool GraphicalItem::tryDelete()
void GraphicalItem::writeConfiguration() const
{
if (debug) qDebug() << PDEBUG;
qCDebug(LOG_LIB);
AbstractExtItem::writeConfiguration();
for (int i=0; i<m_dirs.count(); i++)
if (debug) qDebug() << PDEBUG << ":" << "Remove file" << QString("%1/%2").arg(m_dirs[i]).arg(m_fileName) <<
QFile::remove(QString("%1/%2").arg(m_dirs[i]).arg(m_fileName));
// check if exists
for (int i=0; i<m_dirs.count(); i++)
if (QFile::exists(QString("%1/%2").arg(m_dirs[i]).arg(m_fileName))) return false;
return true;
}
void GraphicalItem::writeConfiguration()
{
if (debug) qDebug() << PDEBUG;
QSettings settings(QString("%1/%2").arg(m_dirs[0]).arg(m_fileName), QSettings::IniFormat);
if (debug) qDebug() << PDEBUG << ":" << "Configuration file" << settings.fileName();
QSettings settings(QString("%1/%2").arg(directories().first()).arg(fileName()), 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-Value"), m_bar);
settings.setValue(QString("X-AW-ActiveColor"), m_activeColor);
settings.setValue(QString("X-AW-InactiveColor"), m_inactiveColor);
@ -491,35 +468,53 @@ void GraphicalItem::writeConfiguration()
void GraphicalItem::changeColor()
{
if (debug) qDebug() << PDEBUG;
qCDebug(LOG_LIB);
QColor color = stringToColor((dynamic_cast<QPushButton *>(sender()))->text());
QColor newColor = QColorDialog::getColor(color, 0, i18n("Select color"),
QColor color = 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()));
dynamic_cast<QPushButton *>(sender())->setText(colorText.join(QChar(',')));
return static_cast<QPushButton *>(sender())->setText(colorText.join(QChar(',')));
}
QColor GraphicalItem::stringToColor(const QString _color)
QColor GraphicalItem::stringToColor(const QString _color) const
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Color" << _color;
qCDebug(LOG_LIB);
qCDebug(LOG_LIB) << "Color" << _color;
QColor qcolor;
QStringList listColor = _color.split(QChar(','));
while (listColor.count() < 4)
listColor.append(QString("0"));
qcolor.setRed(listColor[0].toInt());
qcolor.setGreen(listColor[1].toInt());
qcolor.setBlue(listColor[2].toInt());
qcolor.setAlpha(listColor[3].toInt());
qcolor.setRed(listColor.at(0).toInt());
qcolor.setGreen(listColor.at(1).toInt());
qcolor.setBlue(listColor.at(2).toInt());
qcolor.setAlpha(listColor.at(3).toInt());
return qcolor;
}
void GraphicalItem::translate()
{
qCDebug(LOG_LIB);
ui->label_name->setText(i18n("Name"));
ui->label_comment->setText(i18n("Comment"));
ui->label_value->setText(i18n("Value"));
ui->label_activeColor->setText(i18n("Active color"));
ui->label_inactiveColor->setText(i18n("Inactive color"));
ui->label_type->setText(i18n("Type"));
ui->label_direction->setText(i18n("Direction"));
ui->label_height->setText(i18n("Height"));
ui->label_width->setText(i18n("Width"));
}

View File

@ -19,19 +19,17 @@
#define GRAPHICALITEM_H
#include <QColor>
#include <QDialog>
#include "abstractextitem.h"
namespace Ui {
class GraphicalItem;
}
class GraphicalItem : public QDialog
class GraphicalItem : public AbstractExtItem
{
Q_OBJECT
Q_PROPERTY(int apiVersion READ apiVersion WRITE setApiVersion)
Q_PROPERTY(QString name READ name WRITE setName)
Q_PROPERTY(QString comment READ comment WRITE setComment)
Q_PROPERTY(QString bar READ bar WRITE setBar)
Q_PROPERTY(QString activeColor READ activeColor WRITE setActiveColor)
Q_PROPERTY(QString inactiveColor READ inactiveColor WRITE setInactiveColor)
@ -52,27 +50,23 @@ public:
};
explicit GraphicalItem(QWidget *parent = nullptr, const QString desktopName = QString(),
const QStringList directories = QStringList(), const bool debugCmd = false);
~GraphicalItem();
QString fileName();
QString image(const float value);
const QStringList directories = QStringList());
virtual ~GraphicalItem();
GraphicalItem *copy(const QString _fileName, const int _number);
QString image(const float value) const;
// get methods
int apiVersion();
QString name();
QString comment();
QString bar();
QString activeColor();
QString inactiveColor();
Type type();
QString strType();
Direction direction();
QString strDirection();
int height();
int width();
QString bar() const;
QString activeColor() const;
QString inactiveColor() const;
QString tag() const;
Type type() const;
QString strType() const;
Direction direction() const;
QString strDirection() const;
int height() const;
int width() const;
QString uniq() const;
// set methods
void setApiVersion(const int _apiVersion = 0);
void setName(const QString _name = QString("none"));
void setComment(const QString _comment = QString("empty"));
void setBar(const QString _bar = QString("cpu"));
void setActiveColor(const QString _color = QString("0,0,0,130"));
void setInactiveColor(const QString _color = QString("255,255,255,130"));
@ -85,23 +79,20 @@ public:
public slots:
void readConfiguration();
int showConfiguration(const QStringList tags = QStringList());
bool tryDelete();
void writeConfiguration();
QVariantHash run();
int showConfiguration(const QVariant args = QVariant());
void writeConfiguration() const;
private slots:
void changeColor();
private:
QColor stringToColor(const QString _color);
QString m_fileName;
QStringList m_dirs;
bool debug;
Ui::GraphicalItem *ui;
QColor stringToColor(const QString _color) const;
void translate();
// properties
int m_apiVersion = 0;
QString m_name = QString("none");
QString m_comment = QString("empty");
QString m_bar = QString("cpu");
QString m_activeColor = QString("0,0,0,130");
QString m_inactiveColor = QString("255,255,255,130");

View File

@ -21,8 +21,7 @@
"newline": {
"\n": "<br>",
"\n\r": "<br>",
"\t": "&#09;",
"\v": "&#11;"
"\t": "&#09;"
},
"space": {
" ": "&nbsp;"

View File

@ -4,7 +4,7 @@ Name=aw-get-external-ip
Comment=Custom command to get external IP
Exec=curl ip4.telize.com
X-AW-Prefix=
X-AW-Active=true
X-AW-Active=false
X-AW-Output=true
X-AW-Redirect=nothing
X-AW-Interval=1

View File

@ -4,7 +4,8 @@ Name=default-arch
Comment=Archlinux upgrade info
Exec=pacman -Qu
X-AW-Active=false
X-AW-Filter=
X-AW-Null=0
X-AW-Interval=3600
X-AW-ApiVersion=2
X-AW-ApiVersion=3
X-AW-Number=0

View File

@ -4,7 +4,8 @@ Name=default-debian
Comment=Debian upgrade info
Exec=apt-show-versions -u -b
X-AW-Active=false
X-AW-Filter=
X-AW-Null=0
X-AW-Interval=3600
X-AW-ApiVersion=2
X-AW-ApiVersion=3
X-AW-Number=1

View File

@ -4,7 +4,8 @@ Name=default-fedora
Comment=Fedora upgrade info
Exec=yum list updates
X-AW-Active=false
X-AW-Filter=
X-AW-Null=3
X-AW-Interval=3600
X-AW-ApiVersion=2
X-AW-ApiVersion=3
X-AW-Number=2

View File

@ -4,7 +4,8 @@ Name=default-mandriva
Comment=Mandriva upgrade info
Exec=urpmq --auto-select
X-AW-Active=false
X-AW-Filter=
X-AW-Null=0
X-AW-Interval=3600
X-AW-ApiVersion=2
X-AW-ApiVersion=3
X-AW-Number=3

View File

@ -4,7 +4,8 @@ Name=default-ubuntu
Comment=Ubuntu upgrade info
Exec=aptitude search '~U'
X-AW-Active=false
X-AW-Filter=
X-AW-Null=0
X-AW-Interval=3600
X-AW-ApiVersion=2
X-AW-ApiVersion=3
X-AW-Number=4

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

View File

@ -0,0 +1,12 @@
[Desktop Entry]
Comment=London current weather
Encoding=UTF-8
Name=London current
X-AW-Active=false
X-AW-ApiVersion=2
X-AW-City=London
X-AW-Country=uk
X-AW-Image=false
X-AW-Interval=3600
X-AW-Number=0
X-AW-TS=0

View File

@ -1,19 +1,7 @@
# set project name
set (SUBPROJECT plasma_applet_desktop-panel)
message (STATUS "Subproject ${SUBPROJECT}")
set(SUBPROJECT plasma_applet_desktop-panel)
message(STATUS "Subproject ${SUBPROJECT}")
# prepare
configure_file (metadata.desktop ${CMAKE_CURRENT_SOURCE_DIR}/package/metadata.desktop)
configure_file(metadata.desktop ${CMAKE_CURRENT_SOURCE_DIR}/package/metadata.desktop)
find_package (ECM 0.0.12 REQUIRED NO_MODULE)
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR})
find_package (Qt5 REQUIRED COMPONENTS Core Qml)
find_package (KF5 REQUIRED COMPONENTS I18n Notifications Plasma Service WindowSystem)
include (KDEInstallDirs)
include (KDECMakeSettings)
include (KDECompilerSettings)
add_subdirectory (plugin)
plasma_install_package (package org.kde.plasma.desktoppanel)
add_subdirectory(plugin)
plasma_install_package(package org.kde.plasma.desktoppanel)

View File

@ -38,9 +38,6 @@
<entry name="mark" type="string">
<default>¤</default>
</entry>
<entry name="panels" type="int">
<default>-1</default>
</entry>
</group>
<group name="Appearance">

View File

@ -19,17 +19,22 @@ import QtQuick 2.0
import QtQuick.Controls 1.3 as QtControls
import QtQuick.Layouts 1.0 as QtLayouts
import org.kde.plasma.desktoppanel 1.0
import org.kde.plasma.private.desktoppanel 1.0
Item {
id: aboutPage
// backend
DPAdds {
id: dpAdds;
}
width: childrenRect.width
height: childrenRect.height
implicitWidth: pageColumn.implicitWidth
implicitHeight: pageColumn.implicitHeight
property bool debug: DPAdds.isDebugEnabled()
property bool debug: dpAdds.isDebugEnabled()
Column {
@ -45,26 +50,27 @@ Item {
QtControls.Label {
QtLayouts.Layout.fillWidth: true
horizontalAlignment: Text.AlignHCenter
text: DPAdds.getAboutText("header")
text: dpAdds.getAboutText("header")
}
QtControls.Label {
QtLayouts.Layout.fillWidth: true
horizontalAlignment: Text.AlignHCenter
text: DPAdds.getAboutText("version")
text: dpAdds.getAboutText("version")
}
QtControls.Label {
QtLayouts.Layout.fillWidth: true
horizontalAlignment: Text.AlignJustify
text: DPAdds.getAboutText("description")
text: dpAdds.getAboutText("description")
}
QtControls.Label {
QtLayouts.Layout.fillWidth: true
horizontalAlignment: Text.AlignLeft
textFormat: Text.RichText
text: DPAdds.getAboutText("links")
text: dpAdds.getAboutText("links")
onLinkActivated: Qt.openUrlExternally(link);
}
QtControls.Label {
@ -74,7 +80,7 @@ Item {
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignBottom
textFormat: Text.RichText
text: DPAdds.getAboutText("copy")
text: dpAdds.getAboutText("copy")
}
}
}
@ -87,7 +93,7 @@ Item {
QtLayouts.Layout.fillWidth: true
wrapMode: Text.WordWrap
horizontalAlignment: Text.AlignJustify
text: DPAdds.getAboutText("translators")
text: dpAdds.getAboutText("translators")
}
QtControls.Label {
@ -96,7 +102,8 @@ Item {
horizontalAlignment: Text.AlignJustify
verticalAlignment: Text.AlignTop
textFormat: Text.RichText
text: DPAdds.getAboutText("3rdparty")
text: dpAdds.getAboutText("3rdparty")
onLinkActivated: Qt.openUrlExternally(link);
}
}
}
@ -104,6 +111,6 @@ Item {
}
Component.onCompleted: {
if (debug) console.log("[about::onCompleted]")
if (debug) console.debug()
}
}

View File

@ -20,17 +20,22 @@ import QtQuick.Controls 1.3 as QtControls
import QtQuick.Controls.Styles 1.3 as QtStyles
import QtQuick.Dialogs 1.1 as QtDialogs
import org.kde.plasma.desktoppanel 1.0
import org.kde.plasma.private.desktoppanel 1.0
Item {
id: activeAppearancePage
// backend
DPAdds {
id: dpAdds;
}
width: childrenRect.width
height: childrenRect.height
implicitWidth: pageColumn.implicitWidth
implicitHeight: pageColumn.implicitHeight
property bool debug: DPAdds.isDebugEnabled()
property bool debug: dpAdds.isDebugEnabled()
property variant weight: {
25: 0,
50: 1,
@ -63,7 +68,11 @@ Item {
id: selectFont
width: parent.width * 2 / 3
text: plasmoid.configuration.currentFontFamily
onClicked: fontDialog.visible = true
onClicked: {
if (debug) console.debug()
fontDialog.setFont()
fontDialog.visible = true
}
}
}
@ -125,8 +134,10 @@ Item {
]
onCurrentIndexChanged: cfg_currentFontWeight = model[currentIndex]["name"]
Component.onCompleted: {
if (debug) console.debug()
for (var i = 0; i < model.length; i++) {
if (model[i]["name"] == plasmoid.configuration.currentFontWeight) {
if (debug) console.info("Found", model[i]["name"], "on", i)
fontWeight.currentIndex = i;
}
}
@ -160,8 +171,10 @@ Item {
]
onCurrentIndexChanged: cfg_currentFontStyle = model[currentIndex]["name"]
Component.onCompleted: {
if (debug) console.debug()
for (var i = 0; i < model.length; i++) {
if (model[i]["name"] == plasmoid.configuration.currentFontStyle) {
if (debug) console.info("Found", model[i]["name"], "on", i)
fontStyle.currentIndex = i;
}
}
@ -203,16 +216,27 @@ Item {
QtDialogs.FontDialog {
id: fontDialog
title: i18n("Select a font")
font: Qt.font({ family: selectFont.text, pointSize: fontSize.value, weight: Font.Normal })
signal setFont
onAccepted: {
if (debug) console.debug()
selectFont.text = fontDialog.font.family
fontSize.value = fontDialog.font.pointSize
fontStyle.currentIndex = fontDialog.font.italic ? 1 : 0
fontWeight.currentIndex = weight[fontDialog.font.weight]
}
onSetFont: {
if (debug) console.debug()
fontDialog.font = Qt.font({
family: selectFont.text,
pointSize: fontSize.value > 0 ? fontSize.value : 12,
italic: fontStyle.currentIndex == 1,
weight: Font.Normal,
})
}
}
Component.onCompleted: {
if (debug) console.log("[activeapp::onCompleted]")
if (debug) console.debug()
}
}

View File

@ -20,17 +20,22 @@ import QtQuick.Controls 1.3 as QtControls
import QtQuick.Controls.Styles 1.3 as QtStyles
import QtQuick.Dialogs 1.1 as QtDialogs
import org.kde.plasma.desktoppanel 1.0
import org.kde.plasma.private.desktoppanel 1.0
Item {
id: advancedPage
// backend
DPAdds {
id: dpAdds;
}
width: childrenRect.width
height: childrenRect.height
implicitWidth: pageColumn.implicitWidth
implicitHeight: pageColumn.implicitHeight
property bool debug: DPAdds.isDebugEnabled()
property bool debug: dpAdds.isDebugEnabled()
property alias cfg_height: widgetHeight.value
property alias cfg_width: widgetWidth.value
@ -123,8 +128,10 @@ Item {
]
onCurrentIndexChanged: cfg_tooltipType = model[currentIndex]["name"]
Component.onCompleted: {
if (debug) console.debug()
for (var i = 0; i < model.length; i++) {
if (model[i]["name"] == plasmoid.configuration.tooltipType) {
if (debug) console.info("Found", model[i]["name"], "on", i)
tooltipType.currentIndex = i;
}
}
@ -223,23 +230,6 @@ Item {
onCurrentIndexChanged: cfg_mark = currentText
}
}
// Row {
// height: implicitHeight
// width: parent.width
// QtControls.Label {
// height: parent.height
// width: parent.width * 2 / 5
// horizontalAlignment: Text.AlignRight
// verticalAlignment: Text.AlignVCenter
// text: i18n("Panels to be hidden")
// }
// QtControls.Button {
// width: parent.width * 3 / 5
// text: i18n("Edit panels")
// onClicked: cfg_panels = DPAdds.editPanelsToContol(plasmoid.configuration.panels)
// }
// }
}
QtDialogs.ColorDialog {
@ -250,6 +240,6 @@ Item {
}
Component.onCompleted: {
if (debug) console.log("[advanced::onCompleted]")
if (debug) console.debug()
}
}

View File

@ -20,17 +20,22 @@ import QtQuick.Controls 1.3 as QtControls
import QtQuick.Controls.Styles 1.3 as QtStyles
import QtQuick.Dialogs 1.1 as QtDialogs
import org.kde.plasma.desktoppanel 1.0
import org.kde.plasma.private.desktoppanel 1.0
Item {
id: inactiveAppearancePage
// backend
DPAdds {
id: dpAdds;
}
width: childrenRect.width
height: childrenRect.height
implicitWidth: pageColumn.implicitWidth
implicitHeight: pageColumn.implicitHeight
property bool debug: AWKeys.isDebugEnabled()
property bool debug: dpAdds.isDebugEnabled()
property variant weight: {
25: 0,
50: 1,
@ -63,7 +68,11 @@ Item {
id: selectFont
width: parent.width * 2 / 3
text: plasmoid.configuration.fontFamily
onClicked: fontDialog.visible = true
onClicked: {
if (debug) console.debug()
fontDialog.setFont()
fontDialog.visible = true
}
}
}
@ -125,8 +134,10 @@ Item {
]
onCurrentIndexChanged: cfg_fontWeight = model[currentIndex]["name"]
Component.onCompleted: {
if (debug) console.debug()
for (var i = 0; i < model.length; i++) {
if (model[i]["name"] == plasmoid.configuration.fontWeight) {
if (debug) console.info("Found", model[i]["name"], "on", i)
fontWeight.currentIndex = i;
}
}
@ -160,8 +171,10 @@ Item {
]
onCurrentIndexChanged: cfg_fontStyle = model[currentIndex]["name"]
Component.onCompleted: {
if (debug) console.debug()
for (var i = 0; i < model.length; i++) {
if (model[i]["name"] == plasmoid.configuration.fontStyle) {
if (debug) console.info("Found", model[i]["name"], "on", i)
fontStyle.currentIndex = i;
}
}
@ -203,16 +216,27 @@ Item {
QtDialogs.FontDialog {
id: fontDialog
title: i18n("Select a font")
font: Qt.font({ family: selectFont.text, pointSize: fontSize.value, weight: Font.Normal })
signal setFont
onAccepted: {
if (debug) console.debug()
selectFont.text = fontDialog.font.family
fontSize.value = fontDialog.font.pointSize
fontStyle.currentIndex = fontDialog.font.italic ? 1 : 0
fontWeight.currentIndex = weight[fontDialog.font.weight]
}
onSetFont: {
if (debug) console.debug()
fontDialog.font = Qt.font({
family: selectFont.text,
pointSize: fontSize.value > 0 ? fontSize.value : 12,
italic: fontStyle.currentIndex == 1,
weight: Font.Normal,
})
}
}
Component.onCompleted: {
if (debug) console.log("[inactiveapp::onCompleted]")
if (debug) console.debug()
}
}

View File

@ -22,14 +22,18 @@ import org.kde.plasma.plasmoid 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.plasma.desktoppanel 1.0
import org.kde.plasma.private.desktoppanel 1.0
import "."
Item {
id: main
// backend
DPAdds {
id: dpAdds;
}
property bool debug: DPAdds.isDebugEnabled()
property bool debug: dpAdds.isDebugEnabled()
property variant tooltipSettings: {
"tooltipColor": plasmoid.configuration.tooltipColor,
"tooltipType": plasmoid.configuration.tooltipType,
@ -54,31 +58,32 @@ Item {
// ui
GridLayout {
anchors.fill: parent
columns: plasmoid.configuration.verticalLayout ? 1 : DPAdds.numberOfDesktops()
rows: plasmoid.configuration.verticalLayout ? DPAdds.numberOfDesktops() : 1
columns: plasmoid.configuration.verticalLayout ? 1 : dpAdds.numberOfDesktops()
rows: plasmoid.configuration.verticalLayout ? dpAdds.numberOfDesktops() : 1
Repeater {
id: repeater
Layout.columnSpan: 0
Layout.rowSpan: 0
model: DPAdds.numberOfDesktops()
model: dpAdds.numberOfDesktops()
Text {
id: text
height: contentHeight
width: contentWidth
renderType: Text.NativeRendering
textFormat: Text.RichText
wrapMode: Text.NoWrap
verticalAlignment: Text.AlignVCenter
text: DPAdds.parsePattern(plasmoid.configuration.text, index + 1)
text: dpAdds.parsePattern(plasmoid.configuration.text, index + 1)
property alias tooltip: tooltip
MouseArea {
hoverEnabled: true
anchors.fill: parent
onClicked: DPAdds.setCurrentDesktop(index + 1);
onClicked: dpAdds.setCurrentDesktop(index + 1);
onEntered: needTooltipUpdate()
}
@ -103,16 +108,16 @@ Item {
}
onNeedUpdate: {
if (debug) console.log("[main::onNeedUpdate]")
if (debug) console.debug()
for (var i=0; i<repeater.count; i++) {
if (!repeater.itemAt(i)) {
if (debug) console.log("[main::onNeedUpdate] : Nothing to do here " + i)
if (debug) console.info("Nothing to do here", i)
timer.start()
return
}
repeater.itemAt(i).text = DPAdds.parsePattern(plasmoid.configuration.text, i + 1)
if (DPAdds.currentDesktop() == i + 1) {
repeater.itemAt(i).text = dpAdds.parsePattern(plasmoid.configuration.text, i + 1)
if (dpAdds.currentDesktop() == i + 1) {
repeater.itemAt(i).color = plasmoid.configuration.currentFontColor
repeater.itemAt(i).font.family = plasmoid.configuration.currentFontFamily
repeater.itemAt(i).font.italic = plasmoid.configuration.currentFontStyle == "italic" ? true : false
@ -133,15 +138,15 @@ Item {
}
onNeedTooltipUpdate: {
if (debug) console.log("[main::onNeedTooltipUpdate]")
if (debug) console.debug()
for (var i=0; i<repeater.count; i++) {
repeater.itemAt(i).tooltip.text = DPAdds.toolTipImage(i + 1)
repeater.itemAt(i).tooltip.text = dpAdds.toolTipImage(i + 1)
}
}
onSizeUpdate: {
if (debug) console.log("[main::onSizeUpdate]")
if (debug) console.debug()
if (plasmoid.configuration.height == 0) {
var newHeight = 0
@ -165,29 +170,22 @@ Item {
}
}
Plasmoid.onActivated: {
if (debug) console.log("[main::onActivated]")
// DPAdds.changePanelsState()
}
Plasmoid.onUserConfiguringChanged: {
if (plasmoid.userConfiguring) return
if (debug) console.log("[main::onUserConfiguringChanged]")
if (debug) console.debug()
DPAdds.setMark(plasmoid.configuration.mark)
DPAdds.setPanelsToControl(plasmoid.configuration.panels)
DPAdds.setToolTipData(tooltipSettings)
dpAdds.setMark(plasmoid.configuration.mark)
dpAdds.setToolTipData(tooltipSettings)
needUpdate()
}
Component.onCompleted: {
if (debug) console.log("[main::onCompleted]")
if (debug) console.debug()
// init submodule
Plasmoid.userConfiguringChanged(false)
DPAdds.desktopChanged.connect(needUpdate)
DPAdds.windowListChanged.connect(needTooltipUpdate)
dpAdds.desktopChanged.connect(needUpdate)
dpAdds.windowListChanged.connect(needTooltipUpdate)
}
}

View File

@ -1 +1 @@
singleton general general.qml
singleton general 1.0 general.qml

View File

@ -18,17 +18,22 @@
import QtQuick 2.0
import QtQuick.Controls 1.3 as QtControls
import org.kde.plasma.desktoppanel 1.0
import org.kde.plasma.private.desktoppanel 1.0
Item {
id: widgetPage
// backend
DPAdds {
id: dpAdds;
}
width: childrenRect.width
height: childrenRect.height
implicitWidth: pageColumn.implicitWidth
implicitHeight: pageColumn.implicitHeight
property bool debug: DPAdds.isDebugEnabled()
property bool debug: dpAdds.isDebugEnabled()
property alias cfg_text: textPattern.text
@ -42,6 +47,7 @@ Item {
verticalAlignment: Text.AlignVCenter
wrapMode: Text.WordWrap
text: i18n("Detailed information may be found on <a href=\"http://arcanis.name/projects/awesome-widgets/\">project homepage</a>")
onLinkActivated: Qt.openUrlExternally(link);
}
Row {
@ -53,14 +59,13 @@ Item {
iconName: "font"
onClicked: {
if (debug) console.log("[widget::onClicked] : Font button")
if (debug) console.debug("Font button")
var defaultFont = {
"color": plasmoid.configuration.fontColor,
"family": plasmoid.configuration.fontFamily,
"size": plasmoid.configuration.fontSize
}
var font = DPAdds.getFont(defaultFont)
var font = dpAdds.getFont(defaultFont)
var pos = textPattern.cursorPosition
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
@ -75,8 +80,7 @@ Item {
iconName: "format-indent-more"
onClicked: {
if (debug) console.log("[widget::onClicked] : Indent button")
if (debug) console.debug("Indent button")
var pos = textPattern.cursorPosition
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
@ -89,8 +93,7 @@ Item {
iconName: "format-text-bold"
onClicked: {
if (debug) console.log("[widget::onClicked] : Bold button")
if (debug) console.debug("Bold button")
var pos = textPattern.cursorPosition
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
@ -102,8 +105,7 @@ Item {
iconName: "format-text-italic"
onClicked: {
if (debug) console.log("[widget::onClicked] : Italic button")
if (debug) console.debug("Italic button")
var pos = textPattern.cursorPosition
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
@ -115,8 +117,7 @@ Item {
iconName: "format-text-underline"
onClicked: {
if (debug) console.log("[widget::onClicked] : Underline button")
if (debug) console.debug("Underline button")
var pos = textPattern.cursorPosition
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
@ -128,8 +129,7 @@ Item {
iconName: "format-text-strikethrough"
onClicked: {
if (debug) console.log("[widget::onClicked] : Strike button")
if (debug) console.debug("Strike button")
var pos = textPattern.cursorPosition
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
@ -142,8 +142,7 @@ Item {
iconName: "format-justify-left"
onClicked: {
if (debug) console.log("[widget::onClicked] : Left button")
if (debug) console.debug("Left button")
var pos = textPattern.cursorPosition
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
@ -155,8 +154,7 @@ Item {
iconName: "format-justify-center"
onClicked: {
if (debug) console.log("[widget::onClicked] : Center button")
if (debug) console.debug("Center button")
var pos = textPattern.cursorPosition
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
@ -168,8 +166,7 @@ Item {
iconName: "format-justify-right"
onClicked: {
if (debug) console.log("[widget::onClicked] : Right button")
if (debug) console.debug("Right button")
var pos = textPattern.cursorPosition
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
@ -181,8 +178,7 @@ Item {
iconName: "format-justify-fill"
onClicked: {
if (debug) console.log("[widget::onClicked] : Justify button")
if (debug) console.debug("Justify button")
var pos = textPattern.cursorPosition
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
@ -197,15 +193,14 @@ Item {
QtControls.ComboBox {
id: tags
width: parent.width - addTagButton.width - showValueButton.width
model: DPAdds.dictKeys()
model: dpAdds.dictKeys()
}
QtControls.Button {
id: addTagButton
text: i18n("Add")
onClicked: {
if (debug) console.log("[widget::onClicked] : Add tag button")
if (debug) console.debug("Add tag button")
var pos = textPattern.cursorPosition
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
@ -217,12 +212,11 @@ Item {
text: i18n("Show value")
onClicked: {
if (debug) console.log("[widget::onClicked] : Show tag button")
if (debug) console.debug("Show tag button")
var message = i18n("Tag: %1", tags.currentText)
message += "<br>"
message += i18n("Value: %1", DPAdds.valueByKey(tags.currentText))
DPAdds.sendNotification("tag", message)
message += i18n("Value: %1", dpAdds.valueByKey(tags.currentText))
dpAdds.sendNotification("tag", message)
}
}
}
@ -238,6 +232,6 @@ Item {
Component.onCompleted: {
if (debug) console.log("[widget::onCompleted]")
if (debug) console.debug()
}
}

View File

@ -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.desktoppanel
X-KDE-PluginInfo-Version=2.2.2
X-KDE-PluginInfo-Version=2.4.0
X-KDE-PluginInfo-Website=http://arcanis.name/projects/awesome-widgets/
X-KDE-PluginInfo-Category=System Information
X-KDE-PluginInfo-Depends=

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