mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-07-16 07:09:58 +00:00
split plugin to classes
rewrite extscripts fix building implement several methods
This commit is contained in:
3
sources/awesome-widget-kf5/plugin/.directory
Normal file
3
sources/awesome-widget-kf5/plugin/.directory
Normal file
@ -0,0 +1,3 @@
|
||||
[Dolphin]
|
||||
Timestamp=2015,1,19,23,14,34
|
||||
Version=3
|
@ -17,13 +17,17 @@ include_directories (${CMAKE_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
${CMAKE_CURRENT_BINARY_DIR}/../
|
||||
${PROJECT_TRDPARTY_DIR}
|
||||
../../ext-sysmon
|
||||
${CMAKE_CURRENT_BINARY_DIR}/../../ext-sysmon
|
||||
${Qt_INCLUDE}
|
||||
${Kf5_INCLUDE})
|
||||
|
||||
file (GLOB SUBPROJECT_SOURCE *.cpp)
|
||||
file (GLOB SUBPROJECT_NOTIFY *.notifyrc)
|
||||
file (GLOB SUBPROJECT_UI *.ui)
|
||||
file (GLOB_RECURSE SUBPROJECT_SOURCE *.cpp ${PROJECT_TRDPARTY_DIR}/task/*.cpp)
|
||||
# task source is required by extscripts
|
||||
file (GLOB_RECURSE SUBPROJECT_SOURCE *.cpp ${PROJECT_TRDPARTY_DIR}/task/*.cpp
|
||||
../../ext-sysmon/extscript.cpp)
|
||||
set (TASK_HEADER ${PROJECT_TRDPARTY_DIR}/task/task.h)
|
||||
|
||||
qt5_wrap_cpp (TASK_MOC_SOURCE ${TASK_HEADER})
|
||||
|
210
sources/awesome-widget-kf5/plugin/awactions.cpp
Normal file
210
sources/awesome-widget-kf5/plugin/awactions.cpp
Normal file
@ -0,0 +1,210 @@
|
||||
/***************************************************************************
|
||||
* 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 "awactions.h"
|
||||
|
||||
#include <KI18n/KLocalizedString>
|
||||
#include <KNotifications/KNotification>
|
||||
|
||||
#include <QDebug>
|
||||
#include <QDesktopServices>
|
||||
#include <QMessageBox>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
#include <QProcess>
|
||||
#include <QProcessEnvironment>
|
||||
#include <QSettings>
|
||||
#include <QStandardPaths>
|
||||
#include <QThread>
|
||||
|
||||
#include <pdebug/pdebug.h>
|
||||
|
||||
#include "extscript.h"
|
||||
#include "graphicalitem.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"));
|
||||
}
|
||||
|
||||
|
||||
AWActions::~AWActions()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
}
|
||||
|
||||
|
||||
void AWActions::checkUpdates()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
|
||||
connect(manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(versionReplyRecieved(QNetworkReply *)));
|
||||
|
||||
manager->get(QNetworkRequest(QUrl(VERSION_API)));
|
||||
}
|
||||
|
||||
|
||||
void AWActions::runCmd(const QString cmd)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Cmd" << cmd;
|
||||
|
||||
QProcess command;
|
||||
sendNotification(QString("Info"), i18n("Run %1", cmd));
|
||||
|
||||
command.startDetached(cmd);
|
||||
}
|
||||
|
||||
|
||||
void AWActions::sendNotification(const QString eventId, const QString message)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Event" << eventId;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Message" << message;
|
||||
|
||||
KNotification *notification = KNotification::event(eventId, QString("Awesome Widget ::: ") + eventId, message);
|
||||
notification->setComponentName(QString("plasma-applet-org.kde.plasma.awesome-widget"));
|
||||
}
|
||||
|
||||
|
||||
void AWActions::showReadme()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
QDesktopServices::openUrl(QString(HOMEPAGE));
|
||||
}
|
||||
|
||||
|
||||
QMap<QString, QVariant> AWActions::readDataEngineConfiguration()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
QString fileName = QStandardPaths::locate(QStandardPaths::ConfigLocation, QString("plasma-dataengine-extsysmon.conf"));
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Configuration file" << fileName;
|
||||
QSettings settings(fileName, QSettings::IniFormat);
|
||||
QMap<QString, QVariant> rawConfig;
|
||||
|
||||
settings.beginGroup(QString("Configuration"));
|
||||
rawConfig[QString("ACPIPATH")] = settings.value(QString("ACPIPATH"), QString("/sys/class/power_supply/"));
|
||||
rawConfig[QString("GPUDEV")] = settings.value(QString("GPUDEV"), QString("auto"));
|
||||
rawConfig[QString("HDDDEV")] = settings.value(QString("HDDDEV"), QString("all"));
|
||||
rawConfig[QString("HDDTEMPCMD")] = settings.value(QString("HDDTEMPCMD"), QString("sudo hddtemp"));
|
||||
rawConfig[QString("MPDADDRESS")] = settings.value(QString("MPDADDRESS"), QString("localhost"));
|
||||
rawConfig[QString("MPDPORT")] = settings.value(QString("MPDPORT"), QString("6600"));
|
||||
rawConfig[QString("MPRIS")] = settings.value(QString("MPRIS"), QString("auto"));
|
||||
rawConfig[QString("PKGCMD")] = settings.value(QString("PKGCMD"), QString("pacman -Qu"));
|
||||
rawConfig[QString("PKGNULL")] = settings.value(QString("PKGNULL"), QString("0"));
|
||||
rawConfig[QString("PLAYER")] = settings.value(QString("PLAYER"), QString("mpris"));
|
||||
settings.endGroup();
|
||||
|
||||
return updateDataEngineConfiguration(rawConfig);
|
||||
}
|
||||
|
||||
|
||||
QMap<QString, QVariant> AWActions::updateDataEngineConfiguration(QMap<QString, QVariant> rawConfig)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
for (int i=rawConfig[QString("PKGNULL")].toString().split(QString(","), QString::SkipEmptyParts).count();
|
||||
i<rawConfig[QString("PKGCMD")].toString().split(QString(","), QString::SkipEmptyParts).count()+1;
|
||||
i++)
|
||||
rawConfig[QString("PKGNULL")].toString() += QString(",0");
|
||||
|
||||
for (int i=0; i<rawConfig.keys().count(); i++)
|
||||
if (debug) qDebug() << PDEBUG << ":" <<
|
||||
rawConfig.keys()[i] << QString("=") << rawConfig[rawConfig.keys()[i]];
|
||||
return rawConfig;
|
||||
}
|
||||
|
||||
|
||||
void AWActions::writeDataEngineConfiguration(const QMap<QString, QVariant> configuration)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
QString fileName = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QString("/plasma-dataengine-extsysmon.conf");
|
||||
QSettings settings(fileName, QSettings::IniFormat);
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Configuration file" << settings.fileName();
|
||||
|
||||
settings.beginGroup(QString("Configuration"));
|
||||
settings.setValue(QString("GPUDEV"), configuration[QString("GPUDEV")]);
|
||||
settings.setValue(QString("HDDDEV"), configuration[QString("HDDDEV")]);
|
||||
settings.setValue(QString("HDDTEMPCMD"), configuration[QString("HDDTEMPCMD")]);
|
||||
settings.setValue(QString("MPDADDRESS"), configuration[QString("MPDADDRESS")]);
|
||||
settings.setValue(QString("MPDPORT"), configuration[QString("MPDPORT")]);
|
||||
settings.setValue(QString("MPRIS"), configuration[QString("MPRIS")]);
|
||||
settings.setValue(QString("PKGCMD"), configuration[QString("PKGCMD")]);
|
||||
settings.setValue(QString("PKGNULL"), configuration[QString("PKGNULL")]);
|
||||
settings.setValue(QString("PLAYER"), configuration[QString("PLAYER")]);
|
||||
settings.endGroup();
|
||||
|
||||
settings.sync();
|
||||
}
|
||||
|
||||
|
||||
void AWActions::showUpdates(QString version)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
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);
|
||||
switch(select) {
|
||||
case QMessageBox::Ok:
|
||||
QDesktopServices::openUrl(QString(RELEASES) + version);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AWActions::versionReplyRecieved(QNetworkReply *reply)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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();
|
||||
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);
|
||||
}
|
56
sources/awesome-widget-kf5/plugin/awactions.h
Normal file
56
sources/awesome-widget-kf5/plugin/awactions.h
Normal file
@ -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 AWACTIONS_H
|
||||
#define AWACTIONS_H
|
||||
|
||||
#include <QMap>
|
||||
#include <QObject>
|
||||
#include <QVariant>
|
||||
|
||||
|
||||
class QNetworkReply;
|
||||
|
||||
class AWActions : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
AWActions(QObject *parent = 0);
|
||||
~AWActions();
|
||||
|
||||
Q_INVOKABLE void checkUpdates();
|
||||
Q_INVOKABLE void runCmd(const QString cmd = QString("/usr/bin/true"));
|
||||
Q_INVOKABLE void sendNotification(const QString eventId, const QString message);
|
||||
Q_INVOKABLE void showReadme();
|
||||
// dataengine
|
||||
Q_INVOKABLE QMap<QString, QVariant> readDataEngineConfiguration();
|
||||
Q_INVOKABLE void writeDataEngineConfiguration(const QMap<QString, QVariant> configuration);
|
||||
|
||||
private slots:
|
||||
void showUpdates(QString version);
|
||||
void versionReplyRecieved(QNetworkReply *reply);
|
||||
|
||||
private:
|
||||
QMap<QString, QVariant> updateDataEngineConfiguration(QMap<QString, QVariant> rawConfig);
|
||||
// variables
|
||||
bool debug = false;
|
||||
};
|
||||
|
||||
|
||||
#endif /* AWACTIONS_H */
|
@ -19,15 +19,25 @@
|
||||
|
||||
#include <QtQml>
|
||||
|
||||
#include "awadds.h"
|
||||
#include "awactions.h"
|
||||
#include "awkeys.h"
|
||||
|
||||
|
||||
static QObject *aw_singletontype_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
|
||||
static QObject *awactions_singletontype_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
|
||||
{
|
||||
Q_UNUSED(engine);
|
||||
Q_UNUSED(scriptEngine);
|
||||
|
||||
return new AWAdds();
|
||||
return new AWActions();
|
||||
}
|
||||
|
||||
|
||||
static QObject *awkeys_singletontype_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
|
||||
{
|
||||
Q_UNUSED(engine);
|
||||
Q_UNUSED(scriptEngine);
|
||||
|
||||
return new AWKeys();
|
||||
}
|
||||
|
||||
|
||||
@ -35,5 +45,6 @@ void AWPlugin::registerTypes(const char *uri)
|
||||
{
|
||||
Q_ASSERT(uri == QLatin1String("org.kde.plasma.private.awesome-widget"));
|
||||
|
||||
qmlRegisterSingletonType<AWAdds>(uri, 1, 0, "AWAdds", aw_singletontype_provider);
|
||||
qmlRegisterSingletonType<AWActions>(uri, 1, 0, "AWActions", awactions_singletontype_provider);
|
||||
qmlRegisterSingletonType<AWKeys>(uri, 1, 0, "AWKeys", awkeys_singletontype_provider);
|
||||
}
|
||||
|
@ -15,34 +15,23 @@
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
#include "awadds.h"
|
||||
|
||||
#include <KI18n/KLocalizedString>
|
||||
#include <KNotifications/KNotification>
|
||||
#include "awkeys.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QDesktopServices>
|
||||
#include <QMessageBox>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QDir>
|
||||
#include <QNetworkInterface>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
#include <QProcess>
|
||||
#include <QProcessEnvironment>
|
||||
#include <QSettings>
|
||||
#include <QStandardPaths>
|
||||
#include <QTextCodec>
|
||||
#include <QThread>
|
||||
|
||||
#include <pdebug/pdebug.h>
|
||||
//#include <task/taskadds.h>
|
||||
|
||||
#include "extscript.h"
|
||||
#include "graphicalitem.h"
|
||||
#include "version.h"
|
||||
|
||||
|
||||
AWAdds::AWAdds(QObject *parent)
|
||||
AWKeys::AWKeys(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
// debug
|
||||
@ -54,24 +43,27 @@ AWAdds::AWAdds(QObject *parent)
|
||||
}
|
||||
|
||||
|
||||
AWAdds::~AWAdds()
|
||||
AWKeys::~AWKeys()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
}
|
||||
|
||||
|
||||
void AWAdds::checkUpdates()
|
||||
void AWKeys::initKeys(const QString pattern)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
|
||||
connect(manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(versionReplyRecieved(QNetworkReply *)));
|
||||
// clear
|
||||
foundBars.clear();
|
||||
foundKeys.clear();
|
||||
|
||||
manager->get(QNetworkRequest(QUrl(VERSION_API)));
|
||||
// init
|
||||
foundBars = findGraphicalItems(pattern);
|
||||
foundKeys = findKeys(pattern);
|
||||
}
|
||||
|
||||
|
||||
void AWAdds::initValues()
|
||||
void AWKeys::initValues()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
@ -87,7 +79,7 @@ void AWAdds::initValues()
|
||||
}
|
||||
|
||||
|
||||
bool AWAdds::isDebugEnabled()
|
||||
bool AWKeys::isDebugEnabled()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
@ -95,7 +87,7 @@ bool AWAdds::isDebugEnabled()
|
||||
}
|
||||
|
||||
|
||||
QString AWAdds::networkDevice(const QString custom)
|
||||
QString AWKeys::networkDevice(const QString custom)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Custom device" << custom;
|
||||
@ -117,7 +109,7 @@ QString AWAdds::networkDevice(const QString custom)
|
||||
}
|
||||
|
||||
|
||||
int AWAdds::numberCpus()
|
||||
int AWKeys::numberCpus()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
@ -125,26 +117,35 @@ int AWAdds::numberCpus()
|
||||
}
|
||||
|
||||
|
||||
QString AWAdds::parsePattern(const QString pattern, const QMap<QString, QVariant> dict,
|
||||
const QMap<QString, QVariant> values,
|
||||
const QStringList foundKeys, const QStringList foundBars)
|
||||
QString AWKeys::parsePattern(const QString pattern, const QMap<QString, QVariant> values)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Dictionary" << dict;
|
||||
|
||||
QString parsed = pattern;
|
||||
parsed.replace(QString("$$"), QString("$\\$\\"));
|
||||
for (int i=0; i<foundKeys.count(); i++)
|
||||
parsed.replace(QString("$") + foundKeys[i], values[foundKeys[i]]);
|
||||
parsed.replace(QString("$") + foundKeys[i], values[foundKeys[i]].toString());
|
||||
for (int i=0; i<foundBars.count(); i++)
|
||||
parsed.replace(QString("$") + foundBars[i], getItemByTag(foundBars[i])->getImage(values[foundBars[i]].toFloat()));
|
||||
parsed.replace(QString("$") + foundBars[i], getItemByTag(foundBars[i])->image(values[foundBars[i]].toFloat()));
|
||||
parsed.replace(QString("$\\$\\"), QString("$$"));
|
||||
|
||||
return parsed;
|
||||
}
|
||||
|
||||
|
||||
float AWAdds::tempepature(const float temp, const QString units)
|
||||
QStringList AWKeys::sourcesForDataEngine(const QString pattern, const QString dataEngine)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Pattern" << pattern;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "DataEngine" << dataEngine;
|
||||
|
||||
QStringList sources;
|
||||
|
||||
return sources;
|
||||
}
|
||||
|
||||
|
||||
float AWKeys::temperature(const float temp, const QString units)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
@ -168,7 +169,7 @@ float AWAdds::tempepature(const float temp, const QString units)
|
||||
}
|
||||
|
||||
|
||||
QMap<QString, QVariant> AWAdds::counts()
|
||||
QMap<QString, QVariant> AWKeys::counts()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
@ -194,7 +195,7 @@ QMap<QString, QVariant> AWAdds::counts()
|
||||
}
|
||||
|
||||
|
||||
QStringList AWAdds::dictKeys()
|
||||
QStringList AWKeys::dictKeys()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
@ -298,7 +299,38 @@ QStringList AWAdds::dictKeys()
|
||||
}
|
||||
|
||||
|
||||
QStringList AWAdds::timeKeys()
|
||||
QStringList AWKeys::extScriptsInfo()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
QStringList info;
|
||||
for (int i=0; i<extScripts.count(); i++) {
|
||||
info.append(extScripts[i]->fileName());
|
||||
info.append(extScripts[i]->name());
|
||||
info.append(extScripts[i]->comment());
|
||||
info.append(extScripts[i]->executable());
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
QStringList AWKeys::graphicalItemsInfo()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
QStringList info;
|
||||
for (int i=0; i<graphicalItems.count(); i++) {
|
||||
info.append(graphicalItems[i]->fileName());
|
||||
info.append(graphicalItems[i]->name() + graphicalItems[i]->bar());
|
||||
info.append(graphicalItems[i]->comment());
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
QStringList AWKeys::timeKeys()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
@ -324,13 +356,13 @@ QStringList AWAdds::timeKeys()
|
||||
}
|
||||
|
||||
|
||||
QStringList AWAdds::findGraphicalItems(const QString pattern)
|
||||
QStringList AWKeys::findGraphicalItems(const QString pattern)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
QStringList orderedKeys;
|
||||
for (int i=0; i<graphicalItems.count(); i++)
|
||||
orderedKeys.append(graphicalItems[i]->getName() + graphicalItems[i]->getBar());
|
||||
orderedKeys.append(graphicalItems[i]->name() + graphicalItems[i]->bar());
|
||||
orderedKeys.sort();
|
||||
|
||||
QStringList selectedKeys;
|
||||
@ -344,7 +376,7 @@ QStringList AWAdds::findGraphicalItems(const QString pattern)
|
||||
}
|
||||
|
||||
|
||||
QString AWAdds::findKeys(const QString pattern)
|
||||
QStringList AWKeys::findKeys(const QString pattern)
|
||||
{
|
||||
QStringList selectedKeys;
|
||||
for (int i=0; i<keys.count(); i++)
|
||||
@ -357,151 +389,7 @@ QString AWAdds::findKeys(const QString pattern)
|
||||
}
|
||||
|
||||
|
||||
void AWAdds::runCmd(const QString cmd)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Cmd" << cmd;
|
||||
|
||||
QProcess command;
|
||||
sendNotification(QString("Info"), i18n("Run %1", cmd));
|
||||
|
||||
command.startDetached(cmd);
|
||||
}
|
||||
|
||||
|
||||
void AWAdds::sendNotification(const QString eventId, const QString message)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Event" << eventId;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Message" << message;
|
||||
|
||||
KNotification *notification = KNotification::event(eventId, QString("Awesome Widget ::: ") + eventId, message);
|
||||
notification->setComponentName(QString("plasma-applet-org.kde.plasma.awesome-widget"));
|
||||
}
|
||||
|
||||
|
||||
void AWAdds::showReadme()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
QDesktopServices::openUrl(QString(HOMEPAGE));
|
||||
}
|
||||
|
||||
|
||||
QMap<QString, QVariant> AWAdds::readDataEngineConfiguration()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
QString fileName = QStandardPaths::locate(QStandardPaths::ConfigLocation, QString("plasma-dataengine-extsysmon.conf"));
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Configuration file" << fileName;
|
||||
QSettings settings(fileName, QSettings::IniFormat);
|
||||
QMap<QString, QVariant> rawConfig;
|
||||
|
||||
settings.beginGroup(QString("Configuration"));
|
||||
rawConfig[QString("ACPIPATH")] = settings.value(QString("ACPIPATH"), QString("/sys/class/power_supply/"));
|
||||
rawConfig[QString("GPUDEV")] = settings.value(QString("GPUDEV"), QString("auto"));
|
||||
rawConfig[QString("HDDDEV")] = settings.value(QString("HDDDEV"), QString("all"));
|
||||
rawConfig[QString("HDDTEMPCMD")] = settings.value(QString("HDDTEMPCMD"), QString("sudo hddtemp"));
|
||||
rawConfig[QString("MPDADDRESS")] = settings.value(QString("MPDADDRESS"), QString("localhost"));
|
||||
rawConfig[QString("MPDPORT")] = settings.value(QString("MPDPORT"), QString("6600"));
|
||||
rawConfig[QString("MPRIS")] = settings.value(QString("MPRIS"), QString("auto"));
|
||||
rawConfig[QString("PKGCMD")] = settings.value(QString("PKGCMD"), QString("pacman -Qu"));
|
||||
rawConfig[QString("PKGNULL")] = settings.value(QString("PKGNULL"), QString("0"));
|
||||
rawConfig[QString("PLAYER")] = settings.value(QString("PLAYER"), QString("mpris"));
|
||||
settings.endGroup();
|
||||
|
||||
return updateDataEngineConfiguration(rawConfig);
|
||||
}
|
||||
|
||||
|
||||
QMap<QString, QVariant> AWAdds::updateDataEngineConfiguration(QMap<QString, QVariant> rawConfig)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
for (int i=rawConfig[QString("PKGNULL")].toString().split(QString(","), QString::SkipEmptyParts).count();
|
||||
i<rawConfig[QString("PKGCMD")].toString().split(QString(","), QString::SkipEmptyParts).count()+1;
|
||||
i++)
|
||||
rawConfig[QString("PKGNULL")].toString() += QString(",0");
|
||||
|
||||
for (int i=0; i<rawConfig.keys().count(); i++)
|
||||
if (debug) qDebug() << PDEBUG << ":" <<
|
||||
rawConfig.keys()[i] << QString("=") << rawConfig[rawConfig.keys()[i]];
|
||||
return rawConfig;
|
||||
}
|
||||
|
||||
|
||||
void AWAdds::writeDataEngineConfiguration(const QMap<QString, QVariant> configuration)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
QString fileName = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QString("/plasma-dataengine-extsysmon.conf");
|
||||
QSettings settings(fileName, QSettings::IniFormat);
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Configuration file" << settings.fileName();
|
||||
|
||||
settings.beginGroup(QString("Configuration"));
|
||||
settings.setValue(QString("GPUDEV"), configuration[QString("GPUDEV")]);
|
||||
settings.setValue(QString("HDDDEV"), configuration[QString("HDDDEV")]);
|
||||
settings.setValue(QString("HDDTEMPCMD"), configuration[QString("HDDTEMPCMD")]);
|
||||
settings.setValue(QString("MPDADDRESS"), configuration[QString("MPDADDRESS")]);
|
||||
settings.setValue(QString("MPDPORT"), configuration[QString("MPDPORT")]);
|
||||
settings.setValue(QString("MPRIS"), configuration[QString("MPRIS")]);
|
||||
settings.setValue(QString("PKGCMD"), configuration[QString("PKGCMD")]);
|
||||
settings.setValue(QString("PKGNULL"), configuration[QString("PKGNULL")]);
|
||||
settings.setValue(QString("PLAYER"), configuration[QString("PLAYER")]);
|
||||
settings.endGroup();
|
||||
|
||||
settings.sync();
|
||||
}
|
||||
|
||||
|
||||
void AWAdds::showUpdates(QString version)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
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);
|
||||
switch(select) {
|
||||
case QMessageBox::Ok:
|
||||
QDesktopServices::openUrl(QString(RELEASES) + version);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AWAdds::versionReplyRecieved(QNetworkReply *reply)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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();
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
QList<ExtScript *> AWAdds::getExtScripts()
|
||||
QList<ExtScript *> AWKeys::getExtScripts()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
@ -532,7 +420,7 @@ QList<ExtScript *> AWAdds::getExtScripts()
|
||||
}
|
||||
|
||||
|
||||
QList<GraphicalItem *> AWAdds::getGraphicalItems()
|
||||
QList<GraphicalItem *> AWKeys::getGraphicalItems()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
@ -563,13 +451,13 @@ QList<GraphicalItem *> AWAdds::getGraphicalItems()
|
||||
}
|
||||
|
||||
|
||||
GraphicalItem *AWAdds::getItemByTag(const QString tag)
|
||||
GraphicalItem *AWKeys::getItemByTag(const QString tag)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
GraphicalItem *item = nullptr;
|
||||
for (int i=0; i< graphicalItems.count(); i++) {
|
||||
if ((graphicalItems[i]->getName() + graphicalItems[i]->getBar()) != tag) continue;
|
||||
if ((graphicalItems[i]->name() + graphicalItems[i]->bar()) != tag) continue;
|
||||
item = graphicalItems[i];
|
||||
break;
|
||||
}
|
@ -16,8 +16,8 @@
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef AWADDS_H
|
||||
#define AWADDS_H
|
||||
#ifndef AWKEYS_H
|
||||
#define AWKEYS_H
|
||||
|
||||
#include <QMap>
|
||||
#include <QObject>
|
||||
@ -27,55 +27,43 @@
|
||||
|
||||
class ExtScript;
|
||||
class GraphicalItem;
|
||||
class QNetworkReply;
|
||||
|
||||
class AWAdds : public QObject
|
||||
class AWKeys : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
AWAdds(QObject *parent = 0);
|
||||
~AWAdds();
|
||||
AWKeys(QObject *parent = 0);
|
||||
~AWKeys();
|
||||
|
||||
Q_INVOKABLE void checkUpdates();
|
||||
Q_INVOKABLE void initKeys(const QString pattern);
|
||||
Q_INVOKABLE void initValues();
|
||||
Q_INVOKABLE bool isDebugEnabled();
|
||||
Q_INVOKABLE QString networkDevice(const QString custom = QString(""));
|
||||
Q_INVOKABLE int numberCpus();
|
||||
Q_INVOKABLE QString parsePattern(const QString pattern, const QMap<QString, QVariant> dict,
|
||||
const QMap<QString, QVariant> values,
|
||||
const QStringList foundKeys, const QStringList foundBars);
|
||||
Q_INVOKABLE float tempepature(const float temp, const QString units = QString("Celsius"));
|
||||
Q_INVOKABLE QString parsePattern(const QString pattern, const QMap<QString, QVariant> values);
|
||||
Q_INVOKABLE QStringList sourcesForDataEngine(const QString pattern,
|
||||
const QString dataEngine = QString("systemmonitor"));
|
||||
Q_INVOKABLE float temperature(const float temp, const QString units = QString("Celsius"));
|
||||
// keys
|
||||
Q_INVOKABLE QMap<QString, QVariant> counts();
|
||||
Q_INVOKABLE QStringList dictKeys();
|
||||
// Q_INVOKABLE QStringList graphicalItemsNames();
|
||||
Q_INVOKABLE QStringList extScriptsInfo();
|
||||
Q_INVOKABLE QStringList graphicalItemsInfo();
|
||||
Q_INVOKABLE QStringList timeKeys();
|
||||
Q_INVOKABLE QStringList findGraphicalItems(const QString pattern);
|
||||
Q_INVOKABLE QStringList findKeys(const QString pattern);
|
||||
// actions
|
||||
Q_INVOKABLE void runCmd(const QString cmd = QString("/usr/bin/true"));
|
||||
Q_INVOKABLE void sendNotification(const QString eventId, const QString message);
|
||||
Q_INVOKABLE void showReadme();
|
||||
// dataengine
|
||||
Q_INVOKABLE QMap<QString, QVariant> readDataEngineConfiguration();
|
||||
Q_INVOKABLE void writeDataEngineConfiguration(const QMap<QString, QVariant> configuration);
|
||||
|
||||
private slots:
|
||||
void showUpdates(QString version);
|
||||
void versionReplyRecieved(QNetworkReply *reply);
|
||||
|
||||
private:
|
||||
QList<ExtScript *> getExtScripts();
|
||||
QList<GraphicalItem *> getGraphicalItems();
|
||||
GraphicalItem *getItemByTag(const QString tag);
|
||||
QMap<QString, QVariant> updateDataEngineConfiguration(QMap<QString, QVariant> rawConfig);
|
||||
// variables
|
||||
bool debug = false;
|
||||
QList<GraphicalItem *> graphicalItems;
|
||||
QList<ExtScript *> extScripts;
|
||||
QStringList keys;
|
||||
QStringList foundBars, foundKeys, keys;
|
||||
};
|
||||
|
||||
|
||||
#endif /* AWADDS_H */
|
||||
#endif /* AWKEYS_H */
|
@ -31,6 +31,8 @@
|
||||
|
||||
#include <pdebug/pdebug.h>
|
||||
|
||||
#include "version.h"
|
||||
|
||||
|
||||
GraphicalItem::GraphicalItem(QWidget *parent, const QString desktopName, const QStringList directories, const bool debugCmd)
|
||||
: QDialog(parent),
|
||||
@ -143,6 +145,14 @@ QString GraphicalItem::fileName()
|
||||
}
|
||||
|
||||
|
||||
int GraphicalItem::apiVersion()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
return m_apiVersion;
|
||||
}
|
||||
|
||||
|
||||
QString GraphicalItem::name()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
@ -254,6 +264,15 @@ int GraphicalItem::width()
|
||||
}
|
||||
|
||||
|
||||
void GraphicalItem::setApiVersion(const int _apiVersion)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Version" << _apiVersion;
|
||||
|
||||
m_apiVersion = _apiVersion;
|
||||
}
|
||||
|
||||
|
||||
void GraphicalItem::setName(const QString _name)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
@ -382,6 +401,7 @@ void GraphicalItem::readConfiguration()
|
||||
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());
|
||||
@ -415,6 +435,7 @@ void GraphicalItem::showConfiguration(const QStringList tags)
|
||||
|
||||
setName(ui->label_nameValue->text());
|
||||
setComment(ui->lineEdit_comment->text());
|
||||
setApiVersion(AWGIAPI);
|
||||
setBar(ui->comboBox_value->currentText());
|
||||
setActiveColor(ui->pushButton_activeColor->text().remove(QChar('&')));
|
||||
setInactiveColor(ui->pushButton_inactiveColor->text().remove(QChar('&')));
|
||||
@ -448,6 +469,7 @@ void GraphicalItem::writeConfiguration()
|
||||
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);
|
||||
|
@ -29,8 +29,9 @@ class GraphicalItem;
|
||||
class GraphicalItem : 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 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)
|
||||
@ -56,6 +57,7 @@ public:
|
||||
QString fileName();
|
||||
QString image(const float value);
|
||||
// get methods
|
||||
int apiVersion();
|
||||
QString name();
|
||||
QString comment();
|
||||
QString bar();
|
||||
@ -68,6 +70,7 @@ public:
|
||||
int height();
|
||||
int width();
|
||||
// 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"));
|
||||
@ -96,6 +99,7 @@ private:
|
||||
bool debug;
|
||||
Ui::GraphicalItem *ui;
|
||||
// properties
|
||||
int m_apiVersion = 0;
|
||||
QString m_name = QString("none");
|
||||
QString m_comment = QString("empty");
|
||||
QString m_bar = QString("cpu");
|
||||
|
Reference in New Issue
Block a user