diff --git a/sources/CMakeLists.txt b/sources/CMakeLists.txt index 006015e..fe6520f 100644 --- a/sources/CMakeLists.txt +++ b/sources/CMakeLists.txt @@ -45,7 +45,9 @@ endif () 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) +add_subdirectory (awesomewidgets) add_subdirectory (extsysmon) add_subdirectory (awesome-widget) add_subdirectory (desktop-panel) diff --git a/sources/awesome-widget/plugin/CMakeLists.txt b/sources/awesome-widget/plugin/CMakeLists.txt index 003fad5..b287ee4 100644 --- a/sources/awesome-widget/plugin/CMakeLists.txt +++ b/sources/awesome-widget/plugin/CMakeLists.txt @@ -13,27 +13,19 @@ 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} - ../../extsysmon - ${CMAKE_CURRENT_BINARY_DIR}/../../extsysmon ${Qt_INCLUDE} ${Kf5_INCLUDE}) # task source is required by extscripts -file (GLOB_RECURSE SUBPROJECT_SOURCE *.cpp ${PROJECT_TRDPARTY_DIR}/fontdialog/*.cpp - ${PROJECT_TRDPARTY_DIR}/qreplytimeout/*.cpp - ../../extsysmon/abstractextitem.cpp - ../../extsysmon/extquotes.cpp - ../../extsysmon/extscript.cpp - ../../extsysmon/extupgrade.cpp - ../../extsysmon/extweather.cpp - ../../extsysmon/graphicalitem.cpp) +file (GLOB_RECURSE SUBPROJECT_SOURCE *.cpp ${PROJECT_TRDPARTY_DIR}/fontdialog/*.cpp) file (GLOB SUBPROJECT_UI *.ui) file (GLOB SUBPROJECT_NOTIFY *.notifyrc) 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}) +target_link_libraries (${PLUGIN_NAME} ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Kf5_LIBRARIES}) install (TARGETS ${PLUGIN_NAME} DESTINATION ${QML_INSTALL_DIR}/org/kde/plasma/private/awesomewidget) install (FILES qmldir DESTINATION ${QML_INSTALL_DIR}/org/kde/plasma/private/awesomewidget) diff --git a/sources/awesomewidgets/CMakeLists.txt b/sources/awesomewidgets/CMakeLists.txt new file mode 100644 index 0000000..2e598ce --- /dev/null +++ b/sources/awesomewidgets/CMakeLists.txt @@ -0,0 +1,42 @@ +# set project name +set (SUBPROJECT ${PROJECT_LIBRARY}) +message (STATUS "Subproject ${SUBPROJECT}") +add_definitions(-DTRANSLATION_DOMAIN=\"plasma_applet_org.kde.plasma.awesomewidget\") + +# find required libaries +find_package (Qt5 REQUIRED COMPONENTS Core Network Widgets) + +add_definitions (${Qt5Core_DEFINITIONS} ${Qt5DBus_DEFINITIONS} + ${Qt5Network_DEFINITIONS} ${Qt5Widgets_DEFINITIONS}) +set (Qt_INCLUDE ${Qt5Core_INCLUDE_DIRS} ${Qt5DBus_INCLUDE_DIRS} + ${Qt5Network_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS}) + +include_directories (${CMAKE_SOURCE_DIR} + ${CMAKE_BINARY_DIR} + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_BINARY_DIR}/../ + ${PROJECT_TRDPARTY_DIR} + ${Qt_INCLUDE}) + +file (GLOB_RECURSE SUBPROJECT_SOURCE *.cpp ${PROJECT_TRDPARTY_DIR}/qreplytimeout/*.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) + +# make +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} ${Qt5Core_LIBRARIES} ${Qt5Network_LIBRARIES} ${Qt5Widgets_LIBRARIES}) + +# install +install (DIRECTORY ${SUBPROJECT_GRAPHITEMS} DESTINATION share/${PROJECT_NAME}) +install (DIRECTORY ${SUBPROJECT_QUOTES} DESTINATION share/${PROJECT_NAME}) +install (DIRECTORY ${SUBPROJECT_SCRIPTS} DESTINATION share/${PROJECT_NAME}) +install (DIRECTORY ${SUBPROJECT_UPGRADE} DESTINATION share/${PROJECT_NAME}) +install (DIRECTORY ${SUBPROJECT_WEATHER} DESTINATION share/${PROJECT_NAME}) diff --git a/sources/extsysmon/abstractextitem.cpp b/sources/awesomewidgets/abstractextitem.cpp similarity index 97% rename from sources/extsysmon/abstractextitem.cpp rename to sources/awesomewidgets/abstractextitem.cpp index cc585d6..a9dc4aa 100644 --- a/sources/extsysmon/abstractextitem.cpp +++ b/sources/awesomewidgets/abstractextitem.cpp @@ -45,6 +45,18 @@ AbstractExtItem::~AbstractExtItem() } +template +T *AbstractExtItem::copy(const QString fileName, const int number) +{ + Q_UNUSED(fileName) + Q_UNUSED(number) + + // an analog of pure virtual method + return new T(); +} + + + int AbstractExtItem::apiVersion() const { if (debug) qDebug() << PDEBUG; diff --git a/sources/extsysmon/abstractextitem.h b/sources/awesomewidgets/abstractextitem.h similarity index 95% rename from sources/extsysmon/abstractextitem.h rename to sources/awesomewidgets/abstractextitem.h index fe2813d..fbf86cc 100644 --- a/sources/extsysmon/abstractextitem.h +++ b/sources/awesomewidgets/abstractextitem.h @@ -34,12 +34,14 @@ class AbstractExtItem : public QDialog 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 AbstractExtItem(QWidget *parent = nullptr, const QString desktopName = QString(), const QStringList directories = QStringList(), const bool debugCmd = false); virtual ~AbstractExtItem(); + template T *copy(const QString fileName, const int number); // get methods int apiVersion() const; QString comment() const; @@ -50,6 +52,7 @@ public: 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); diff --git a/sources/awesomewidgets/abstractextitemaggregator.cpp b/sources/awesomewidgets/abstractextitemaggregator.cpp new file mode 100644 index 0000000..cfc7256 --- /dev/null +++ b/sources/awesomewidgets/abstractextitemaggregator.cpp @@ -0,0 +1,68 @@ +/*************************************************************************** + * 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 +#include + +#include + + +AbstractExtItemAggregator::AbstractExtItemAggregator(QWidget *parent, const bool debugCmd) + : QWidget(parent), + debug(debugCmd) +{ + dialog = new QDialog(this); + widgetDialog = new QListWidget(dialog); + dialogButtons = new QDialogButtonBox(QDialogButtonBox::Open | QDialogButtonBox::Close, + Qt::Vertical, dialog); + copyButton = dialogButtons->addButton(tr("Copy"), QDialogButtonBox::ActionRole); + createButton = dialogButtons->addButton(tr("Create"), QDialogButtonBox::ActionRole); + deleteButton = dialogButtons->addButton(tr("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())); +} + + +AbstractExtItemAggregator::~AbstractExtItemAggregator() +{ + if (debug) qDebug() << PDEBUG; + + delete dialog; +} + + +void AbstractExtItemAggregator::editItemButtonPressed(QAbstractButton *button) +{ + if (debug) qDebug() << PDEBUG; + + if (static_cast(button) == copyButton) + return copyItem(); + else if (static_cast(button) == createButton) + return createItem(); + else if (dynamic_cast(button) == deleteButton) + return deleteItem(); + else if (dialogButtons->buttonRole(button) == QDialogButtonBox::AcceptRole) + return editItem(); +} diff --git a/sources/awesomewidgets/abstractextitemaggregator.h b/sources/awesomewidgets/abstractextitemaggregator.h new file mode 100644 index 0000000..d1bb0b8 --- /dev/null +++ b/sources/awesomewidgets/abstractextitemaggregator.h @@ -0,0 +1,56 @@ +/*************************************************************************** + * 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 +#include +#include +#include +#include +#include + + +class AbstractExtItemAggregator : public QWidget +{ + Q_OBJECT +public: + AbstractExtItemAggregator(QWidget *parent = nullptr, const bool debugCmd = false); + virtual ~AbstractExtItemAggregator(); + // ui + QDialog *dialog = nullptr; + QListWidget *widgetDialog = nullptr; + QDialogButtonBox *dialogButtons = nullptr; + QPushButton *copyButton = nullptr; + QPushButton *createButton = nullptr; + QPushButton *deleteButton = nullptr; + +private slots: + void editItemButtonPressed(QAbstractButton *button); + +private: + bool debug; + // methods + virtual void copyItem() = 0; + virtual void createItem() = 0; + virtual void deleteItem() = 0; + virtual void editItem() = 0; +}; + + +#endif /* ABSTRACTEXTITEMAGGREGATOR_H */ diff --git a/sources/extsysmon/desktops/aw-bat-bar.desktop b/sources/awesomewidgets/desktops/aw-bat-bar.desktop similarity index 100% rename from sources/extsysmon/desktops/aw-bat-bar.desktop rename to sources/awesomewidgets/desktops/aw-bat-bar.desktop diff --git a/sources/extsysmon/desktops/aw-cpu-bar.desktop b/sources/awesomewidgets/desktops/aw-cpu-bar.desktop similarity index 100% rename from sources/extsysmon/desktops/aw-cpu-bar.desktop rename to sources/awesomewidgets/desktops/aw-cpu-bar.desktop diff --git a/sources/extsysmon/desktops/aw-mem-bar.desktop b/sources/awesomewidgets/desktops/aw-mem-bar.desktop similarity index 100% rename from sources/extsysmon/desktops/aw-mem-bar.desktop rename to sources/awesomewidgets/desktops/aw-mem-bar.desktop diff --git a/sources/extsysmon/desktops/aw-swap-bar.desktop b/sources/awesomewidgets/desktops/aw-swap-bar.desktop similarity index 100% rename from sources/extsysmon/desktops/aw-swap-bar.desktop rename to sources/awesomewidgets/desktops/aw-swap-bar.desktop diff --git a/sources/awesomewidgets/extitemaggregator.h b/sources/awesomewidgets/extitemaggregator.h new file mode 100644 index 0000000..a2a9ad8 --- /dev/null +++ b/sources/awesomewidgets/extitemaggregator.h @@ -0,0 +1,234 @@ +/*************************************************************************** + * 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 +#include +#include +#include +#include +#include + +#include + +#include "abstractextitemaggregator.h" + + +template class ExtItemAggregator : public AbstractExtItemAggregator +{ +public: + explicit ExtItemAggregator(QWidget *parent, const QString type, + const bool debugCmd = false) + : AbstractExtItemAggregator(parent, debugCmd), + debug(debugCmd), + m_type(type) + { + initItems(); + }; + + ~ExtItemAggregator() + { + if (debug) qDebug() << PDEBUG; + + m_items.clear(); + } + + QString getName() const + { + if (debug) qDebug() << PDEBUG; + + bool ok; + QString name = QInputDialog::getText(nullptr, tr("Enter file name"), + tr("File name"), QLineEdit::Normal, + QString(""), &ok); + if ((!ok) || (name.isEmpty())) return QString(""); + if (!name.endsWith(QString(".desktop"))) name += QString(".desktop"); + + return name; + }; + + void editItems() + { + if (debug) qDebug() << PDEBUG; + + repaint(); + int ret = dialog->exec(); + if (debug) qDebug() << PDEBUG << ":" << "Dialog returns" << ret; + }; + + void initItems() + { + if (debug) qDebug() << PDEBUG; + + m_items.clear(); + m_items = getItems(); + }; + + T *itemFromWidget() const + { + if (debug) qDebug() << PDEBUG; + + QListWidgetItem *item = widgetDialog->currentItem(); + if (item == nullptr) return nullptr; + + int originalItem = -1; + for (int i=0; ifileName() != item->text()) continue; + originalItem = i; + break; + } + + return originalItem == -1 ? nullptr : m_items[originalItem]; + }; + + QList items() const + { + if (debug) qDebug() << PDEBUG; + + return m_items; + }; + + int uniqNumber() const + { + if (debug) qDebug() << PDEBUG; + + QList tagList; + for (int i=0; inumber()); + int number = 0; + while (tagList.contains(number)) + number++; + + return number; + }; + +private: + bool debug; + QList m_items; + QString m_type; + // init method + QList getItems() + { + if (debug) qDebug() << PDEBUG; + + // create directory at $HOME + QString localDir = QString("%1/awesomewidgets/%2") + .arg(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)) + .arg(m_type); + QDir localDirectory; + if (localDirectory.mkpath(localDir)) + if (debug) qDebug() << PDEBUG << ":" << "Created directory" << localDir; + + QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, + QString("awesomewidgets/%1").arg(m_type), + QStandardPaths::LocateDirectory); + QStringList names; + QList items; + for (int i=0; iclear(); + for (int i=0; ifileName(), widgetDialog); + QStringList tooltip; + tooltip.append(tr("Name: %1").arg(m_items[i]->name())); + tooltip.append(tr("Comment: %1").arg(m_items[i]->comment())); + tooltip.append(tr("Identity: %1").arg(m_items[i]->uniq())); + item->setToolTip(tooltip.join(QChar('\n'))); + widgetDialog->addItem(item); + } + }; + // methods + void copyItem() + { + if (debug) qDebug() << PDEBUG; + + T *source = itemFromWidget(); + QString fileName = getName(); + int number = uniqNumber(); + if ((source == nullptr) || (fileName.isEmpty())) return; + + T *newItem = source->copy(fileName, number); + if (newItem->showConfiguration() == 1) { + initItems(); + repaint(); + } + }; + + void createItem() + { + if (debug) qDebug() << PDEBUG; + + QString fileName = getName(); + int number = uniqNumber(); + QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, + QString("awesomewidgets/%1").arg(m_type), + QStandardPaths::LocateDirectory); + if (fileName.isEmpty()) return; + + T *newItem = new T(this, fileName, dirs, debug); + newItem->setNumber(number); + if (newItem->showConfiguration() == 1) { + initItems(); + repaint(); + } + }; + + void deleteItem() + { + if (debug) qDebug() << PDEBUG; + + T *source = itemFromWidget(); + if (source == nullptr) return; + + if (source->tryDelete()) { + initItems(); + repaint(); + } + }; + + void editItem() + { + if (debug) qDebug() << PDEBUG; + + T *source = itemFromWidget(); + if (source == nullptr) return; + + if (source->showConfiguration() == 1) { + initItems(); + repaint(); + } + }; +}; + + +#endif /* EXTITEMAGGREGATOR_H */ diff --git a/sources/extsysmon/extquotes.cpp b/sources/awesomewidgets/extquotes.cpp similarity index 92% rename from sources/extsysmon/extquotes.cpp rename to sources/awesomewidgets/extquotes.cpp index c8f98a2..192098f 100644 --- a/sources/extsysmon/extquotes.cpp +++ b/sources/awesomewidgets/extquotes.cpp @@ -68,6 +68,24 @@ ExtQuotes::~ExtQuotes() } +ExtQuotes *ExtQuotes::copy(const QString fileName, const int number) +{ + if (debug) qDebug() << PDEBUG; + + ExtQuotes *item = new ExtQuotes(static_cast(parent()), fileName, + directories(), debug); + 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 { if (debug) qDebug() << PDEBUG; @@ -76,6 +94,14 @@ QString ExtQuotes::ticker() const } +QString ExtQuotes::uniq() const +{ + if (debug) qDebug() << PDEBUG; + + return m_ticker; +} + + void ExtQuotes::setTicker(const QString _ticker) { if (debug) qDebug() << PDEBUG; diff --git a/sources/extsysmon/extquotes.h b/sources/awesomewidgets/extquotes.h similarity index 96% rename from sources/extsysmon/extquotes.h rename to sources/awesomewidgets/extquotes.h index ba5bd51..e9b745b 100644 --- a/sources/extsysmon/extquotes.h +++ b/sources/awesomewidgets/extquotes.h @@ -40,8 +40,10 @@ public: const QStringList directories = QStringList(), const bool debugCmd = false); ~ExtQuotes(); + ExtQuotes *copy(const QString fileName, const int number); // get methods QString ticker() const; + QString uniq() const; // set methods void setTicker(const QString _ticker = QString("EURUSD=X")); diff --git a/sources/extsysmon/extquotes.ui b/sources/awesomewidgets/extquotes.ui similarity index 100% rename from sources/extsysmon/extquotes.ui rename to sources/awesomewidgets/extquotes.ui diff --git a/sources/extsysmon/extscript.cpp b/sources/awesomewidgets/extscript.cpp similarity index 94% rename from sources/extsysmon/extscript.cpp rename to sources/awesomewidgets/extscript.cpp index bef9fc2..a0a8521 100644 --- a/sources/extsysmon/extscript.cpp +++ b/sources/awesomewidgets/extscript.cpp @@ -59,6 +59,27 @@ ExtScript::~ExtScript() } +ExtScript *ExtScript::copy(const QString fileName, const int number) +{ + if (debug) qDebug() << PDEBUG; + + ExtScript *item = new ExtScript(static_cast(parent()), fileName, + directories(), debug); + 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 { if (debug) qDebug() << PDEBUG; @@ -99,6 +120,14 @@ ExtScript::Redirect ExtScript::redirect() const } +QString ExtScript::uniq() const +{ + if (debug) qDebug() << PDEBUG; + + return m_executable; +} + + QString ExtScript::strRedirect() const { if (debug) qDebug() << PDEBUG; diff --git a/sources/extsysmon/extscript.h b/sources/awesomewidgets/extscript.h similarity index 97% rename from sources/extsysmon/extscript.h rename to sources/awesomewidgets/extscript.h index dd8ab45..aea8a6a 100644 --- a/sources/extsysmon/extscript.h +++ b/sources/awesomewidgets/extscript.h @@ -48,12 +48,14 @@ public: const QStringList directories = QStringList(), const bool debugCmd = false); ~ExtScript(); + ExtScript *copy(const QString fileName, const int number); // get methods QString executable() const; QStringList filters() const; bool hasOutput() const; QString prefix() const; Redirect redirect() const; + QString uniq() const; // derivatives QString strRedirect() const; // set methods diff --git a/sources/extsysmon/extscript.ui b/sources/awesomewidgets/extscript.ui similarity index 100% rename from sources/extsysmon/extscript.ui rename to sources/awesomewidgets/extscript.ui diff --git a/sources/extsysmon/extupgrade.cpp b/sources/awesomewidgets/extupgrade.cpp similarity index 89% rename from sources/extsysmon/extupgrade.cpp rename to sources/awesomewidgets/extupgrade.cpp index ecbb83f..83f4757 100644 --- a/sources/extsysmon/extupgrade.cpp +++ b/sources/awesomewidgets/extupgrade.cpp @@ -55,6 +55,25 @@ ExtUpgrade::~ExtUpgrade() } +ExtUpgrade *ExtUpgrade::copy(const QString fileName, const int number) +{ + if (debug) qDebug() << PDEBUG; + + ExtUpgrade *item = new ExtUpgrade(static_cast(parent()), fileName, + directories(), debug); + item->setActive(isActive()); + item->setApiVersion(apiVersion()); + item->setComment(comment()); + item->setExecutable(executable()); + item->setInterval(interval()); + item->setName(name()); + item->setNumber(number); + item->setNull(null()); + + return item; +} + + QString ExtUpgrade::executable() const { if (debug) qDebug() << PDEBUG; @@ -71,6 +90,14 @@ int ExtUpgrade::null() const } +QString ExtUpgrade::uniq() const +{ + if (debug) qDebug() << PDEBUG; + + return m_executable; +} + + void ExtUpgrade::setExecutable(const QString _executable) { if (debug) qDebug() << PDEBUG; diff --git a/sources/extsysmon/extupgrade.h b/sources/awesomewidgets/extupgrade.h similarity index 96% rename from sources/extsysmon/extupgrade.h rename to sources/awesomewidgets/extupgrade.h index b1fe5e9..b5953b3 100644 --- a/sources/extsysmon/extupgrade.h +++ b/sources/awesomewidgets/extupgrade.h @@ -38,9 +38,11 @@ public: const QStringList directories = QStringList(), const bool debugCmd = false); ~ExtUpgrade(); + ExtUpgrade *copy(const QString fileName, const int number); // get methods QString executable() const; int null() const; + QString uniq() const; // set methods void setExecutable(const QString _executable = QString("/usr/bin/true")); void setNull(const int _null = 0); diff --git a/sources/extsysmon/extupgrade.ui b/sources/awesomewidgets/extupgrade.ui similarity index 100% rename from sources/extsysmon/extupgrade.ui rename to sources/awesomewidgets/extupgrade.ui diff --git a/sources/extsysmon/extweather.cpp b/sources/awesomewidgets/extweather.cpp similarity index 93% rename from sources/extsysmon/extweather.cpp rename to sources/awesomewidgets/extweather.cpp index d4ffcf7..649a7e6 100644 --- a/sources/extsysmon/extweather.cpp +++ b/sources/awesomewidgets/extweather.cpp @@ -65,6 +65,26 @@ ExtWeather::~ExtWeather() } +ExtWeather *ExtWeather::copy(const QString fileName, const int number) +{ + if (debug) qDebug() << PDEBUG; + + ExtWeather *item = new ExtWeather(static_cast(parent()), fileName, + directories(), debug); + item->setActive(isActive()); + item->setApiVersion(apiVersion()); + item->setCity(city()); + item->setComment(comment()); + item->setCountry(country()); + item->setInterval(interval()); + item->setName(name()); + item->setNumber(number); + item->setTs(ts()); + + return item; +} + + QString ExtWeather::weatherFromInt(const int _id) const { if (debug) qDebug() << PDEBUG; @@ -189,6 +209,14 @@ int ExtWeather::ts() const } +QString ExtWeather::uniq() const +{ + if (debug) qDebug() << PDEBUG; + + return QString("%1 (%2) at %3").arg(m_city).arg(m_country).arg(m_ts); +} + + void ExtWeather::setCity(const QString _city) { if (debug) qDebug() << PDEBUG; diff --git a/sources/extsysmon/extweather.h b/sources/awesomewidgets/extweather.h similarity index 97% rename from sources/extsysmon/extweather.h rename to sources/awesomewidgets/extweather.h index 80762a6..d91b1ee 100644 --- a/sources/extsysmon/extweather.h +++ b/sources/awesomewidgets/extweather.h @@ -43,11 +43,13 @@ public: const QStringList directories = QStringList(), const bool debugCmd = false); ~ExtWeather(); + ExtWeather *copy(const QString fileName, const int number); QString weatherFromInt(const int _id) const; // get methods QString city() const; QString country() const; int ts() const; + QString uniq() const; // set methods void setCity(const QString _city = QString("London")); void setCountry(const QString _country = QString("uk")); diff --git a/sources/extsysmon/extweather.ui b/sources/awesomewidgets/extweather.ui similarity index 100% rename from sources/extsysmon/extweather.ui rename to sources/awesomewidgets/extweather.ui diff --git a/sources/extsysmon/graphicalitem.cpp b/sources/awesomewidgets/graphicalitem.cpp similarity index 94% rename from sources/extsysmon/graphicalitem.cpp rename to sources/awesomewidgets/graphicalitem.cpp index 25eab8e..99a64e0 100644 --- a/sources/extsysmon/graphicalitem.cpp +++ b/sources/awesomewidgets/graphicalitem.cpp @@ -54,6 +54,30 @@ GraphicalItem::~GraphicalItem() } +GraphicalItem *GraphicalItem::copy(const QString fileName, const int number) +{ + if (debug) qDebug() << PDEBUG; + + GraphicalItem *item = new GraphicalItem(static_cast(parent()), + fileName, directories(), debug); + 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 { if (debug) qDebug() << PDEBUG; @@ -229,6 +253,14 @@ int GraphicalItem::width() const } +QString GraphicalItem::uniq() const +{ + if (debug) qDebug() << PDEBUG; + + return m_bar; +} + + void GraphicalItem::setBar(const QString _bar) { if (debug) qDebug() << PDEBUG; diff --git a/sources/extsysmon/graphicalitem.h b/sources/awesomewidgets/graphicalitem.h similarity index 97% rename from sources/extsysmon/graphicalitem.h rename to sources/awesomewidgets/graphicalitem.h index c31030e..f1c8a6b 100644 --- a/sources/extsysmon/graphicalitem.h +++ b/sources/awesomewidgets/graphicalitem.h @@ -53,6 +53,7 @@ public: const QStringList directories = QStringList(), const bool debugCmd = false); ~GraphicalItem(); + GraphicalItem *copy(const QString fileName, const int number); QString image(const float value) const; // get methods QString bar() const; @@ -64,6 +65,7 @@ public: QString strDirection() const; int height() const; int width() const; + QString uniq() const; // set methods void setBar(const QString _bar = QString("cpu")); void setActiveColor(const QString _color = QString("0,0,0,130")); diff --git a/sources/extsysmon/graphicalitem.ui b/sources/awesomewidgets/graphicalitem.ui similarity index 100% rename from sources/extsysmon/graphicalitem.ui rename to sources/awesomewidgets/graphicalitem.ui diff --git a/sources/extsysmon/quotes/aapl.desktop b/sources/awesomewidgets/quotes/aapl.desktop similarity index 100% rename from sources/extsysmon/quotes/aapl.desktop rename to sources/awesomewidgets/quotes/aapl.desktop diff --git a/sources/extsysmon/quotes/eurrub.desktop b/sources/awesomewidgets/quotes/eurrub.desktop similarity index 100% rename from sources/extsysmon/quotes/eurrub.desktop rename to sources/awesomewidgets/quotes/eurrub.desktop diff --git a/sources/extsysmon/quotes/eurusd.desktop b/sources/awesomewidgets/quotes/eurusd.desktop similarity index 100% rename from sources/extsysmon/quotes/eurusd.desktop rename to sources/awesomewidgets/quotes/eurusd.desktop diff --git a/sources/extsysmon/quotes/goog.desktop b/sources/awesomewidgets/quotes/goog.desktop similarity index 100% rename from sources/extsysmon/quotes/goog.desktop rename to sources/awesomewidgets/quotes/goog.desktop diff --git a/sources/extsysmon/quotes/msft.desktop b/sources/awesomewidgets/quotes/msft.desktop similarity index 100% rename from sources/extsysmon/quotes/msft.desktop rename to sources/awesomewidgets/quotes/msft.desktop diff --git a/sources/extsysmon/quotes/rts.desktop b/sources/awesomewidgets/quotes/rts.desktop similarity index 100% rename from sources/extsysmon/quotes/rts.desktop rename to sources/awesomewidgets/quotes/rts.desktop diff --git a/sources/extsysmon/quotes/snp.desktop b/sources/awesomewidgets/quotes/snp.desktop similarity index 100% rename from sources/extsysmon/quotes/snp.desktop rename to sources/awesomewidgets/quotes/snp.desktop diff --git a/sources/extsysmon/quotes/usdrub.desktop b/sources/awesomewidgets/quotes/usdrub.desktop similarity index 100% rename from sources/extsysmon/quotes/usdrub.desktop rename to sources/awesomewidgets/quotes/usdrub.desktop diff --git a/sources/extsysmon/quotes/vix.desktop b/sources/awesomewidgets/quotes/vix.desktop similarity index 100% rename from sources/extsysmon/quotes/vix.desktop rename to sources/awesomewidgets/quotes/vix.desktop diff --git a/sources/extsysmon/scripts/awesomewidgets-extscripts-filters.json b/sources/awesomewidgets/scripts/awesomewidgets-extscripts-filters.json similarity index 100% rename from sources/extsysmon/scripts/awesomewidgets-extscripts-filters.json rename to sources/awesomewidgets/scripts/awesomewidgets-extscripts-filters.json diff --git a/sources/extsysmon/scripts/get-external-ip.desktop b/sources/awesomewidgets/scripts/get-external-ip.desktop similarity index 100% rename from sources/extsysmon/scripts/get-external-ip.desktop rename to sources/awesomewidgets/scripts/get-external-ip.desktop diff --git a/sources/extsysmon/upgrade/default-arch.desktop b/sources/awesomewidgets/upgrade/default-arch.desktop similarity index 100% rename from sources/extsysmon/upgrade/default-arch.desktop rename to sources/awesomewidgets/upgrade/default-arch.desktop diff --git a/sources/extsysmon/upgrade/default-debian.desktop b/sources/awesomewidgets/upgrade/default-debian.desktop similarity index 100% rename from sources/extsysmon/upgrade/default-debian.desktop rename to sources/awesomewidgets/upgrade/default-debian.desktop diff --git a/sources/extsysmon/upgrade/default-fedora.desktop b/sources/awesomewidgets/upgrade/default-fedora.desktop similarity index 100% rename from sources/extsysmon/upgrade/default-fedora.desktop rename to sources/awesomewidgets/upgrade/default-fedora.desktop diff --git a/sources/extsysmon/upgrade/default-mandriva.desktop b/sources/awesomewidgets/upgrade/default-mandriva.desktop similarity index 100% rename from sources/extsysmon/upgrade/default-mandriva.desktop rename to sources/awesomewidgets/upgrade/default-mandriva.desktop diff --git a/sources/extsysmon/upgrade/default-ubuntu.desktop b/sources/awesomewidgets/upgrade/default-ubuntu.desktop similarity index 100% rename from sources/extsysmon/upgrade/default-ubuntu.desktop rename to sources/awesomewidgets/upgrade/default-ubuntu.desktop diff --git a/sources/extsysmon/weather/london.desktop b/sources/awesomewidgets/weather/london.desktop similarity index 100% rename from sources/extsysmon/weather/london.desktop rename to sources/awesomewidgets/weather/london.desktop diff --git a/sources/extsysmon/CMakeLists.txt b/sources/extsysmon/CMakeLists.txt index ff38802..b629c58 100644 --- a/sources/extsysmon/CMakeLists.txt +++ b/sources/extsysmon/CMakeLists.txt @@ -5,7 +5,7 @@ message (STATUS "Subproject ${SUBPROJECT}") add_definitions(-DTRANSLATION_DOMAIN=\"plasma_applet_org.kde.plasma.awesomewidget\") # find required libaries -find_package (Qt5 REQUIRED COMPONENTS DBus Network Widgets) +find_package (Qt5 REQUIRED COMPONENTS DBus Network) find_package (ECM 0.0.11 REQUIRED NO_MODULE) set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR}) find_package (KF5 REQUIRED COMPONENTS Plasma Service WindowSystem) @@ -15,31 +15,25 @@ include (KDECMakeSettings) include (KDECompilerSettings) add_definitions (${Qt5Core_DEFINITIONS} ${Qt5DBus_DEFINITIONS} - ${Qt5Network_DEFINITIONS} ${Qt5Widgets_DEFINITIONS}) + ${Qt5Network_DEFINITIONS}) set (Qt_INCLUDE ${Qt5Core_INCLUDE_DIRS} ${Qt5DBus_INCLUDE_DIRS} - ${Qt5Network_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS}) + ${Qt5Network_INCLUDE_DIRS}) set (KDE_INCLUDE ${Plasma_INCLUDE_DIR}) 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} ${KDE_INCLUDE}) file (GLOB SUBPROJECT_DESKTOP_IN *.desktop) file (RELATIVE_PATH SUBPROJECT_DESKTOP ${CMAKE_SOURCE_DIR} ${SUBPROJECT_DESKTOP_IN}) -file (GLOB_RECURSE SUBPROJECT_SOURCE *.cpp ${PROJECT_TRDPARTY_DIR}/task/*.cpp - ${PROJECT_TRDPARTY_DIR}/qreplytimeout/*.cpp) +file (GLOB_RECURSE SUBPROJECT_SOURCE *.cpp ${PROJECT_TRDPARTY_DIR}/task/*.cpp) set (TASK_HEADER ${PROJECT_TRDPARTY_DIR}/task/task.h) -file (GLOB SUBPROJECT_UI *.ui) file (GLOB SUBPROJECT_CONF *.conf) -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) # prepare configure_file (${SUBPROJECT_DESKTOP_IN} ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT_DESKTOP}) @@ -48,16 +42,11 @@ configure_file (${SUBPROJECT_DESKTOP_IN} ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJEC qt5_wrap_cpp (TASK_MOC_SOURCE ${TASK_HEADER}) qt5_wrap_ui (SUBPROJECT_UI_HEADER ${SUBPROJECT_UI}) add_library (${PLUGIN_NAME} MODULE ${SUBPROJECT_SOURCE} ${SUBPROJECT_UI_HEADER} ${TASK_MOC_SOURCE}) -target_link_libraries (${PLUGIN_NAME} ${Plasma_LIBRARIES} KF5::WindowSystem - ${Qt5DBus_LIBRARIES} ${Qt5Network_LIBRARIES} ${Qt5Widgets_LIBRARIES} ${Qt5Xml_LIBRARIES}) +target_link_libraries (${PLUGIN_NAME} ${PROJECT_LIBRARY} ${Plasma_LIBRARIES} KF5::WindowSystem + ${Qt5DBus_LIBRARIES} ${Qt5Network_LIBRARIES}) kcoreaddons_desktop_to_json (${PLUGIN_NAME} ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT_DESKTOP}) # install install (TARGETS ${PLUGIN_NAME} DESTINATION ${PLUGIN_INSTALL_DIR}/plasma/dataengine) install (FILES ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT_DESKTOP} DESTINATION ${SERVICES_INSTALL_DIR}) install (FILES ${SUBPROJECT_CONF} DESTINATION ${CONFIG_INSTALL_DIR}) -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}) diff --git a/sources/extsysmon/extsysmon.cpp b/sources/extsysmon/extsysmon.cpp index 24fd076..7606be6 100644 --- a/sources/extsysmon/extsysmon.cpp +++ b/sources/extsysmon/extsysmon.cpp @@ -57,10 +57,11 @@ ExtendedSysMon::ExtendedSysMon(QObject* parent, const QVariantList &args) setMinimumPollingInterval(333); readConfiguration(); - initQuotes(); - initScripts(); - initUpgrade(); - initWeather(); + + externalQuotes = new ExtItemAggregator(nullptr, QString("quotes"), debug); + externalScripts = new ExtItemAggregator(nullptr, QString("scripts"), debug); + externalUpgrade = new ExtItemAggregator(nullptr, QString("upgrade"), debug); + externalWeather = new ExtItemAggregator(nullptr, QString("weather"), debug); } @@ -68,10 +69,10 @@ ExtendedSysMon::~ExtendedSysMon() { if (debug) qDebug() << PDEBUG; - externalQuotes.clear(); - externalScripts.clear(); - externalUpgrade.clear(); - externalWeather.clear(); + delete externalQuotes; + delete externalScripts; + delete externalUpgrade; + delete externalWeather; } @@ -128,122 +129,6 @@ QString ExtendedSysMon::getAutoMpris() const } -void ExtendedSysMon::initQuotes() -{ - if (debug) qDebug() << PDEBUG; - - // create directory at $HOME and create dirs list - QString localDir = QString("%1/awesomewidgets/quotes") - .arg(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)); - QDir localDirectory; - if ((!localDirectory.exists(localDir)) && (localDirectory.mkpath(localDir))) - if (debug) qDebug() << PDEBUG << ":" << "Created directory" << localDir; - - QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, - QString("awesomewidgets/quotes"), - QStandardPaths::LocateDirectory); - - QStringList names; - for (int i=0; itag(QString("custom")), externalScripts[i]->run()[QString("value")]); + for (int i=0; iitems().count(); i++) + setData(source, externalScripts->items()[i]->tag(QString("custom")), + externalScripts->items()[i]->run()[QString("value")]); } else if (source == QString("desktop")) { QVariantMap desktop = getCurrentDesktop(); for (int i=0; itag(QString("pkgcount")), externalUpgrade[i]->run()[QString("value")]); + for (int i=0; iitems().count(); i++) + setData(source, externalUpgrade->items()[i]->tag(QString("pkgcount")), + externalUpgrade->items()[i]->run()[QString("value")]); } else if (source == QString("player")) { QVariantMap player = getPlayerInfo(configuration[QString("PLAYER")], configuration[QString("MPDADDRESS")], @@ -735,18 +622,20 @@ bool ExtendedSysMon::updateSourceEvent(const QString &source) for (int i=0; irun(); + for (int i=0; iitems().count(); i++) { + QVariantMap data = externalQuotes->items()[i]->run(); for (int j=0; jtag(data.keys()[j]), data[data.keys()[j]]); + setData(source, externalQuotes->items()[i]->tag(data.keys()[j]), + data[data.keys()[j]]); } } else if (source == QString("update")) { setData(source, QString("value"), true); } else if (source == QString("weather")) { - for (int i=0; irun(); + for (int i=0; iitems().count(); i++) { + QVariantMap data = externalWeather->items()[i]->run(); for (int j=0; jtag(data.keys()[j]), data[data.keys()[j]]); + setData(source, externalWeather->items()[i]->tag(data.keys()[j]), + data[data.keys()[j]]); } } diff --git a/sources/extsysmon/extsysmon.h b/sources/extsysmon/extsysmon.h index e6018ed..fe40791 100644 --- a/sources/extsysmon/extsysmon.h +++ b/sources/extsysmon/extsysmon.h @@ -20,6 +20,8 @@ #include +#include "extitemaggregator.h" + class ExtQuotes; class ExtScript; @@ -57,19 +59,15 @@ protected: private: // configuration QMap configuration; - QList externalQuotes; - QList externalScripts; - QList externalUpgrade; - QList externalWeather; + ExtItemAggregator *externalQuotes; + ExtItemAggregator *externalScripts; + ExtItemAggregator *externalUpgrade; + ExtItemAggregator *externalWeather; bool debug; // reread configuration QStringList getAllHdd() const; QString getAutoGpu() const; QString getAutoMpris() const; - void initQuotes(); - void initScripts(); - void initUpgrade(); - void initWeather(); void readConfiguration(); QMap updateConfiguration(QMap rawConfig) const; };