mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-07-10 04:15:51 +00:00
* create cppcheck and clangformat targets
* apply code style (#67) * send values by reference * fix warnings on plugin destruction by disconnecting dataengines first * fix invalid hddtemp group definition
This commit is contained in:
@ -2,14 +2,14 @@ set(PLUGIN_NAME awplugin)
|
||||
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}/../
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../${PROJECT_LIBRARY}/
|
||||
${PROJECT_TRDPARTY_DIR}
|
||||
${Qt_INCLUDE}
|
||||
${Kf5_INCLUDE}
|
||||
${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}
|
||||
)
|
||||
|
||||
file(GLOB SUBPROJECT_SOURCE *.cpp ${PROJECT_TRDPARTY_DIR}/fontdialog/*.cpp ${CMAKE_SOURCE_DIR}/*.cpp)
|
||||
|
@ -57,7 +57,7 @@ void AWActions::checkUpdates(const bool showAnyway)
|
||||
|
||||
// showAnyway options requires to show message if no updates found on direct
|
||||
// request. In case of automatic check no message will be shown
|
||||
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
|
||||
QNetworkAccessManager *manager = new QNetworkAccessManager(nullptr);
|
||||
connect(manager, &QNetworkAccessManager::finished,
|
||||
[showAnyway, this](QNetworkReply *reply) {
|
||||
return versionReplyRecieved(reply, showAnyway);
|
||||
@ -106,32 +106,50 @@ QString AWActions::getAboutText(const QString type) const
|
||||
if (type == QString("header")) {
|
||||
text = QString(NAME);
|
||||
} else if (type == QString("version")) {
|
||||
text = i18n("Version %1 (build date %2)", QString(VERSION), QString(BUILD_DATE));
|
||||
if (!QString(COMMIT_SHA).isEmpty()) text += QString(" (%1)").arg(QString(COMMIT_SHA));
|
||||
text = i18n("Version %1 (build date %2)", QString(VERSION),
|
||||
QString(BUILD_DATE));
|
||||
if (!QString(COMMIT_SHA).isEmpty())
|
||||
text += QString(" (%1)").arg(QString(COMMIT_SHA));
|
||||
} else if (type == QString("description")) {
|
||||
text = i18n("A set of minimalistic plasmoid widgets");
|
||||
} else if (type == QString("links")) {
|
||||
text = i18n("Links:") + QString("<br>")
|
||||
+ QString("<a href=\"%1\">%2</a><br>").arg(QString(HOMEPAGE)).arg(i18n("Homepage"))
|
||||
+ QString("<a href=\"%1\">%2</a><br>").arg(QString(REPOSITORY)).arg(i18n("Repository"))
|
||||
+ QString("<a href=\"%1\">%2</a><br>").arg(QString(BUGTRACKER)).arg(i18n("Bugtracker"))
|
||||
+ QString("<a href=\"%1\">%2</a><br>").arg(QString(TRANSLATION)).arg(i18n("Translation issue"))
|
||||
+ QString("<a href=\"%1\">%2</a><br>").arg(QString(AUR_PACKAGES)).arg(i18n("AUR packages"))
|
||||
+ QString("<a href=\"%1\">%2</a>").arg(QString(OPENSUSE_PACKAGES)).arg(i18n("openSUSE packages"));
|
||||
+ QString("<a href=\"%1\">%2</a><br>")
|
||||
.arg(QString(HOMEPAGE))
|
||||
.arg(i18n("Homepage"))
|
||||
+ QString("<a href=\"%1\">%2</a><br>")
|
||||
.arg(QString(REPOSITORY))
|
||||
.arg(i18n("Repository"))
|
||||
+ QString("<a href=\"%1\">%2</a><br>")
|
||||
.arg(QString(BUGTRACKER))
|
||||
.arg(i18n("Bugtracker"))
|
||||
+ QString("<a href=\"%1\">%2</a><br>")
|
||||
.arg(QString(TRANSLATION))
|
||||
.arg(i18n("Translation issue"))
|
||||
+ QString("<a href=\"%1\">%2</a><br>")
|
||||
.arg(QString(AUR_PACKAGES))
|
||||
.arg(i18n("AUR packages"))
|
||||
+ QString("<a href=\"%1\">%2</a>")
|
||||
.arg(QString(OPENSUSE_PACKAGES))
|
||||
.arg(i18n("openSUSE packages"));
|
||||
} else if (type == QString("copy")) {
|
||||
text = QString("<small>© %1 <a href=\"mailto:%2\">%3</a><br>").
|
||||
arg(QString(DATE)).arg(QString(EMAIL)).arg(QString(AUTHOR))
|
||||
+ i18n("This software is licensed under %1", QString(LICENSE))
|
||||
+ QString("</small>");
|
||||
text = QString("<small>© %1 <a href=\"mailto:%2\">%3</a><br>")
|
||||
.arg(QString(DATE))
|
||||
.arg(QString(EMAIL))
|
||||
.arg(QString(AUTHOR))
|
||||
+ i18n("This software is licensed under %1", QString(LICENSE))
|
||||
+ QString("</small>");
|
||||
} else if (type == QString("translators")) {
|
||||
text = i18n("Translators: %1", QString(TRANSLATORS));
|
||||
} else if (type == QString("3rdparty")) {
|
||||
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.at(i).split(QChar(','))[0]).
|
||||
arg(trdPartyList.at(i).split(QChar(','))[1]).
|
||||
arg(trdPartyList.at(i).split(QChar(','))[2]);
|
||||
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.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(", ")));
|
||||
}
|
||||
|
||||
@ -146,10 +164,10 @@ QVariantMap AWActions::getFont(const QVariantMap defaultFont) const
|
||||
|
||||
QVariantMap fontMap;
|
||||
CFont defaultCFont = CFont(defaultFont[QString("family")].toString(),
|
||||
defaultFont[QString("size")].toInt(),
|
||||
400, false, defaultFont[QString("color")].toString());
|
||||
CFont font = CFontDialog::getFont(i18n("Select font"), defaultCFont,
|
||||
false, false);
|
||||
defaultFont[QString("size")].toInt(), 400, false,
|
||||
defaultFont[QString("color")].toString());
|
||||
CFont font
|
||||
= CFontDialog::getFont(i18n("Select font"), defaultCFont, false, false);
|
||||
fontMap[QString("color")] = font.color().name();
|
||||
fontMap[QString("family")] = font.family();
|
||||
fontMap[QString("size")] = font.pointSize();
|
||||
@ -158,7 +176,6 @@ QVariantMap AWActions::getFont(const QVariantMap defaultFont) const
|
||||
}
|
||||
|
||||
|
||||
|
||||
// to avoid additional object definition this method is static
|
||||
void AWActions::sendNotification(const QString eventId, const QString message)
|
||||
{
|
||||
@ -166,10 +183,10 @@ void AWActions::sendNotification(const QString eventId, const QString message)
|
||||
qCDebug(LOG_AW) << "Event" << eventId;
|
||||
qCDebug(LOG_AW) << "Message" << message;
|
||||
|
||||
KNotification *notification = KNotification::event(eventId,
|
||||
QString("Awesome Widget ::: %1").arg(eventId),
|
||||
message);
|
||||
notification->setComponentName(QString("plasma-applet-org.kde.plasma.awesome-widget"));
|
||||
KNotification *notification = KNotification::event(
|
||||
eventId, QString("Awesome Widget ::: %1").arg(eventId), message);
|
||||
notification->setComponentName(
|
||||
QString("plasma-applet-org.kde.plasma.awesome-widget"));
|
||||
}
|
||||
|
||||
|
||||
@ -185,7 +202,6 @@ void AWActions::showInfo(const QString version) const
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AWActions::showUpdates(const QString version) const
|
||||
{
|
||||
qCDebug(LOG_AW);
|
||||
@ -193,12 +209,15 @@ void AWActions::showUpdates(const QString version) const
|
||||
|
||||
QString text;
|
||||
text += i18n("Current version : %1", QString(VERSION));
|
||||
text += QString(COMMIT_SHA).isEmpty() ? QString("\n") : QString(" (%1)\n").arg(QString(COMMIT_SHA));
|
||||
text += QString(COMMIT_SHA).isEmpty()
|
||||
? QString("\n")
|
||||
: QString(" (%1)\n").arg(QString(COMMIT_SHA));
|
||||
text += i18n("New version : %1", version) + QString("\n\n");
|
||||
text += i18n("Click \"Ok\" to download");
|
||||
|
||||
int select = QMessageBox::information(nullptr, i18n("There are updates"), text,
|
||||
QMessageBox::Ok | QMessageBox::Cancel);
|
||||
int select
|
||||
= QMessageBox::information(nullptr, i18n("There are updates"), text,
|
||||
QMessageBox::Ok | QMessageBox::Cancel);
|
||||
switch (select) {
|
||||
case QMessageBox::Ok:
|
||||
QDesktopServices::openUrl(QString(RELEASES) + version);
|
||||
@ -210,7 +229,8 @@ void AWActions::showUpdates(const QString version) const
|
||||
}
|
||||
|
||||
|
||||
void AWActions::versionReplyRecieved(QNetworkReply *reply, const bool showAnyway) const
|
||||
void AWActions::versionReplyRecieved(QNetworkReply *reply,
|
||||
const bool showAnyway) const
|
||||
{
|
||||
qCDebug(LOG_AW);
|
||||
qCDebug(LOG_AW) << "Return code" << reply->error();
|
||||
@ -241,7 +261,8 @@ void AWActions::versionReplyRecieved(QNetworkReply *reply, const bool showAnyway
|
||||
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)))
|
||||
|| ((old_major == new_major) && (old_minor == new_minor)
|
||||
&& (old_patch < new_patch)))
|
||||
return showUpdates(version);
|
||||
else if (showAnyway)
|
||||
return showInfo(version);
|
||||
|
@ -36,16 +36,19 @@ public:
|
||||
Q_INVOKABLE bool runCmd(const QString cmd = QString("/usr/bin/true")) const;
|
||||
Q_INVOKABLE void showReadme() const;
|
||||
// configuration slots
|
||||
Q_INVOKABLE QString getAboutText(const QString type = QString("header")) const;
|
||||
Q_INVOKABLE QString getAboutText(const QString type
|
||||
= QString("header")) const;
|
||||
Q_INVOKABLE QVariantMap getFont(const QVariantMap defaultFont) const;
|
||||
|
||||
public slots:
|
||||
Q_INVOKABLE static void sendNotification(const QString eventId, const QString message);
|
||||
Q_INVOKABLE static void sendNotification(const QString eventId,
|
||||
const QString message);
|
||||
|
||||
private slots:
|
||||
void showInfo(const QString version) const;
|
||||
void showUpdates(const QString version) const;
|
||||
void versionReplyRecieved(QNetworkReply *reply, const bool showAnyway) const;
|
||||
void versionReplyRecieved(QNetworkReply *reply,
|
||||
const bool showAnyway) const;
|
||||
};
|
||||
|
||||
|
||||
|
@ -48,8 +48,9 @@ bool AWConfigHelper::dropCache() const
|
||||
{
|
||||
qCDebug(LOG_AW);
|
||||
|
||||
QString fileName = QString("%1/awesomewidgets.ndx").
|
||||
arg(QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation));
|
||||
QString fileName = QString("%1/awesomewidgets.ndx")
|
||||
.arg(QStandardPaths::writableLocation(
|
||||
QStandardPaths::GenericCacheLocation));
|
||||
|
||||
return QFile(fileName).remove();
|
||||
}
|
||||
@ -67,9 +68,10 @@ void AWConfigHelper::exportConfiguration(QObject *nativeConfig) const
|
||||
QSettings settings(fileName, QSettings::IniFormat);
|
||||
|
||||
// plasmoid configuration
|
||||
QQmlPropertyMap *configuration = static_cast<QQmlPropertyMap *>(nativeConfig);
|
||||
QQmlPropertyMap *configuration
|
||||
= static_cast<QQmlPropertyMap *>(nativeConfig);
|
||||
settings.beginGroup(QString("plasmoid"));
|
||||
foreach(QString key, configuration->keys()) {
|
||||
foreach (QString key, configuration->keys()) {
|
||||
QVariant value = configuration->value(key);
|
||||
if (!value.isValid())
|
||||
continue;
|
||||
@ -77,12 +79,14 @@ void AWConfigHelper::exportConfiguration(QObject *nativeConfig) const
|
||||
}
|
||||
settings.endGroup();
|
||||
|
||||
// extenstions
|
||||
foreach(QString item, m_dirs) {
|
||||
QStringList items = QDir(QString("%1/%2").arg(m_baseDir).arg(item)).entryList(
|
||||
QStringList() << QString("*.desktop"), QDir::Files);
|
||||
// extensions
|
||||
foreach (QString item, m_dirs) {
|
||||
QStringList items
|
||||
= QDir(QString("%1/%2").arg(m_baseDir).arg(item))
|
||||
.entryList(QStringList() << QString("*.desktop"),
|
||||
QDir::Files);
|
||||
settings.beginGroup(item);
|
||||
foreach(QString it, items)
|
||||
foreach (QString it, items)
|
||||
copyExtensions(it, item, settings, false);
|
||||
settings.endGroup();
|
||||
}
|
||||
@ -91,10 +95,12 @@ void AWConfigHelper::exportConfiguration(QObject *nativeConfig) const
|
||||
settings.beginGroup(QString("json"));
|
||||
// script filters
|
||||
readFile(settings, QString("filters"),
|
||||
QString("%1/scripts/awesomewidgets-extscripts-filters.json").arg(m_baseDir));
|
||||
QString("%1/scripts/awesomewidgets-extscripts-filters.json")
|
||||
.arg(m_baseDir));
|
||||
// weather icon settings
|
||||
readFile(settings, QString("weathers"),
|
||||
QString("%1/weather/awesomewidgets-extweather-ids.json").arg(m_baseDir));
|
||||
QString("%1/weather/awesomewidgets-extweather-ids.json")
|
||||
.arg(m_baseDir));
|
||||
settings.endGroup();
|
||||
|
||||
// sync settings
|
||||
@ -115,11 +121,11 @@ QVariantMap AWConfigHelper::importConfiguration() const
|
||||
QSettings settings(fileName, QSettings::IniFormat);
|
||||
QHash<QString, bool> selection = selectImport();
|
||||
|
||||
// extenstions
|
||||
if (selection[QString("extenstions")]) {
|
||||
foreach(QString item, m_dirs) {
|
||||
// extensions
|
||||
if (selection[QString("extensions")]) {
|
||||
foreach (QString item, m_dirs) {
|
||||
settings.beginGroup(item);
|
||||
foreach(QString it, settings.childGroups())
|
||||
foreach (QString it, settings.childGroups())
|
||||
copyExtensions(it, item, settings, true);
|
||||
settings.endGroup();
|
||||
}
|
||||
@ -130,17 +136,19 @@ QVariantMap AWConfigHelper::importConfiguration() const
|
||||
settings.beginGroup(QString("json"));
|
||||
// script filters
|
||||
writeFile(settings, QString("filters"),
|
||||
QString("%1/scripts/awesomewidgets-extscripts-filters.json").arg(m_baseDir));
|
||||
QString("%1/scripts/awesomewidgets-extscripts-filters.json")
|
||||
.arg(m_baseDir));
|
||||
// weather icon settings
|
||||
writeFile(settings, QString("weathers"),
|
||||
QString("%1/weather/awesomewidgets-extweather-ids.json").arg(m_baseDir));
|
||||
QString("%1/weather/awesomewidgets-extweather-ids.json")
|
||||
.arg(m_baseDir));
|
||||
settings.endGroup();
|
||||
}
|
||||
|
||||
// plasmoid configuration
|
||||
if (selection[QString("plasmoid")]) {
|
||||
settings.beginGroup(QString("plasmoid"));
|
||||
foreach(QString key, settings.childKeys())
|
||||
foreach (QString key, settings.childKeys())
|
||||
configuration[key] = settings.value(key);
|
||||
settings.endGroup();
|
||||
}
|
||||
@ -153,22 +161,32 @@ QVariantMap AWConfigHelper::readDataEngineConfiguration() const
|
||||
{
|
||||
qCDebug(LOG_AW);
|
||||
|
||||
QString fileName = QStandardPaths::locate(QStandardPaths::ConfigLocation,
|
||||
QString("plasma-dataengine-extsysmon.conf"));
|
||||
QString fileName
|
||||
= QStandardPaths::locate(QStandardPaths::ConfigLocation,
|
||||
QString("plasma-dataengine-extsysmon.conf"));
|
||||
qCInfo(LOG_AW) << "Configuration file" << fileName;
|
||||
QSettings settings(fileName, QSettings::IniFormat);
|
||||
QVariantMap configuration;
|
||||
|
||||
settings.beginGroup(QString("Configuration"));
|
||||
configuration[QString("ACPIPATH")] = settings.value(QString("ACPIPATH"), QString("/sys/class/power_supply/"));
|
||||
configuration[QString("GPUDEV")] = settings.value(QString("GPUDEV"), QString("auto"));
|
||||
configuration[QString("HDDDEV")] = settings.value(QString("HDDDEV"), QString("all"));
|
||||
configuration[QString("HDDTEMPCMD")] = settings.value(QString("HDDTEMPCMD"), QString("sudo smartctl -a"));
|
||||
configuration[QString("MPDADDRESS")] = settings.value(QString("MPDADDRESS"), QString("localhost"));
|
||||
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"));
|
||||
configuration[QString("ACPIPATH")] = settings.value(
|
||||
QString("ACPIPATH"), QString("/sys/class/power_supply/"));
|
||||
configuration[QString("GPUDEV")]
|
||||
= settings.value(QString("GPUDEV"), QString("auto"));
|
||||
configuration[QString("HDDDEV")]
|
||||
= settings.value(QString("HDDDEV"), QString("all"));
|
||||
configuration[QString("HDDTEMPCMD")]
|
||||
= settings.value(QString("HDDTEMPCMD"), QString("sudo smartctl -a"));
|
||||
configuration[QString("MPDADDRESS")]
|
||||
= settings.value(QString("MPDADDRESS"), QString("localhost"));
|
||||
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();
|
||||
|
||||
qCInfo(LOG_AW) << "Configuration" << configuration;
|
||||
@ -177,12 +195,14 @@ QVariantMap AWConfigHelper::readDataEngineConfiguration() const
|
||||
}
|
||||
|
||||
|
||||
void AWConfigHelper::writeDataEngineConfiguration(const QVariantMap configuration) const
|
||||
void AWConfigHelper::writeDataEngineConfiguration(
|
||||
const QVariantMap configuration) const
|
||||
{
|
||||
qCDebug(LOG_AW);
|
||||
|
||||
QString fileName = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation)
|
||||
+ QString("/plasma-dataengine-extsysmon.conf");
|
||||
QString fileName
|
||||
= QStandardPaths::writableLocation(QStandardPaths::ConfigLocation)
|
||||
+ QString("/plasma-dataengine-extsysmon.conf");
|
||||
QSettings settings(fileName, QSettings::IniFormat);
|
||||
qCInfo(LOG_AW) << "Configuration file" << settings.fileName();
|
||||
|
||||
@ -190,12 +210,15 @@ void AWConfigHelper::writeDataEngineConfiguration(const QVariantMap configuratio
|
||||
settings.setValue(QString("ACPIPATH"), configuration[QString("ACPIPATH")]);
|
||||
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("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("PLAYER"), configuration[QString("PLAYER")]);
|
||||
settings.setValue(QString("PLAYERSYMBOLS"), configuration[QString("PLAYERSYMBOLS")]);
|
||||
settings.setValue(QString("PLAYERSYMBOLS"),
|
||||
configuration[QString("PLAYERSYMBOLS")]);
|
||||
settings.endGroup();
|
||||
|
||||
settings.sync();
|
||||
@ -203,7 +226,8 @@ void AWConfigHelper::writeDataEngineConfiguration(const QVariantMap configuratio
|
||||
|
||||
|
||||
void AWConfigHelper::copyExtensions(const QString item, const QString type,
|
||||
QSettings &settings, const bool inverse) const
|
||||
QSettings &settings,
|
||||
const bool inverse) const
|
||||
{
|
||||
qCDebug(LOG_AW);
|
||||
qCDebug(LOG_AW) << "Extension" << item;
|
||||
@ -211,7 +235,9 @@ void AWConfigHelper::copyExtensions(const QString item, const QString type,
|
||||
qCDebug(LOG_AW) << "Inverse" << inverse;
|
||||
|
||||
settings.beginGroup(item);
|
||||
QSettings itemSettings(QString("%1/%2/%3").arg(m_baseDir).arg(type).arg(item), QSettings::IniFormat);
|
||||
QSettings itemSettings(
|
||||
QString("%1/%2/%3").arg(m_baseDir).arg(type).arg(item),
|
||||
QSettings::IniFormat);
|
||||
itemSettings.beginGroup(QString("Desktop Entry"));
|
||||
if (inverse)
|
||||
copySettings(settings, itemSettings);
|
||||
@ -229,12 +255,13 @@ void AWConfigHelper::copySettings(QSettings &from, QSettings &to) const
|
||||
{
|
||||
qCDebug(LOG_AW);
|
||||
|
||||
foreach(QString key, from.childKeys())
|
||||
foreach (QString key, from.childKeys())
|
||||
to.setValue(key, from.value(key));
|
||||
}
|
||||
|
||||
|
||||
void AWConfigHelper::readFile(QSettings &settings, const QString key, const QString fileName) const
|
||||
void AWConfigHelper::readFile(QSettings &settings, const QString key,
|
||||
const QString fileName) const
|
||||
{
|
||||
qCDebug(LOG_AW);
|
||||
qCDebug(LOG_AW) << "Key" << key;
|
||||
@ -256,14 +283,18 @@ QHash<QString, bool> AWConfigHelper::selectImport() const
|
||||
qCDebug(LOG_AW);
|
||||
|
||||
QDialog *dialog = new QDialog(nullptr);
|
||||
QCheckBox *importPlasmoidSettings = new QCheckBox(i18n("Import plasmoid settings"), dialog);
|
||||
QCheckBox *importPlasmoidSettings
|
||||
= new QCheckBox(i18n("Import plasmoid settings"), dialog);
|
||||
importPlasmoidSettings->setChecked(true);
|
||||
QCheckBox *importExtensionsSettings = new QCheckBox(i18n("Import extenstions"), dialog);
|
||||
QCheckBox *importExtensionsSettings
|
||||
= new QCheckBox(i18n("Import extensions"), dialog);
|
||||
importExtensionsSettings->setChecked(true);
|
||||
QCheckBox *importAddsSettings = new QCheckBox(i18n("Import additional files"), dialog);
|
||||
QCheckBox *importAddsSettings
|
||||
= new QCheckBox(i18n("Import additional files"), dialog);
|
||||
importAddsSettings->setChecked(true);
|
||||
QDialogButtonBox *dialogButtons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
|
||||
Qt::Horizontal, dialog);
|
||||
QDialogButtonBox *dialogButtons
|
||||
= new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
|
||||
Qt::Horizontal, dialog);
|
||||
QVBoxLayout *layout = new QVBoxLayout(dialog);
|
||||
layout->addWidget(importPlasmoidSettings);
|
||||
layout->addWidget(importExtensionsSettings);
|
||||
@ -275,12 +306,12 @@ QHash<QString, bool> AWConfigHelper::selectImport() const
|
||||
// get parameters
|
||||
QHash<QString, bool> import;
|
||||
import[QString("plasmoid")] = false;
|
||||
import[QString("extenstions")] = false;
|
||||
import[QString("extensions")] = false;
|
||||
import[QString("adds")] = false;
|
||||
switch(int ret = dialog->exec()) {
|
||||
switch (int ret = dialog->exec()) {
|
||||
case QDialog::Accepted:
|
||||
import[QString("plasmoid")] = importPlasmoidSettings->isChecked();
|
||||
import[QString("extenstions")] = importExtensionsSettings->isChecked();
|
||||
import[QString("extensions")] = importExtensionsSettings->isChecked();
|
||||
import[QString("adds")] = importAddsSettings->isChecked();
|
||||
break;
|
||||
case QDialog::Rejected:
|
||||
@ -293,7 +324,8 @@ QHash<QString, bool> AWConfigHelper::selectImport() const
|
||||
}
|
||||
|
||||
|
||||
void AWConfigHelper::writeFile(QSettings &settings, const QString key, const QString fileName) const
|
||||
void AWConfigHelper::writeFile(QSettings &settings, const QString key,
|
||||
const QString fileName) const
|
||||
{
|
||||
qCDebug(LOG_AW);
|
||||
qCDebug(LOG_AW) << "Key" << key;
|
||||
|
@ -37,21 +37,27 @@ public:
|
||||
Q_INVOKABLE QVariantMap importConfiguration() const;
|
||||
// dataengine
|
||||
Q_INVOKABLE QVariantMap readDataEngineConfiguration() const;
|
||||
Q_INVOKABLE void writeDataEngineConfiguration(const QVariantMap configuration) const;
|
||||
Q_INVOKABLE void
|
||||
writeDataEngineConfiguration(const QVariantMap configuration) const;
|
||||
|
||||
private:
|
||||
// methods
|
||||
void copyExtensions(const QString item, const QString type,
|
||||
QSettings &settings, const bool inverse) const;
|
||||
void copySettings(QSettings &from, QSettings &to) const;
|
||||
void readFile(QSettings &settings, const QString key, const QString fileName) const;
|
||||
void readFile(QSettings &settings, const QString key,
|
||||
const QString fileName) const;
|
||||
QHash<QString, bool> selectImport() const;
|
||||
void writeFile(QSettings &settings, const QString key, const QString fileName) const;
|
||||
void writeFile(QSettings &settings, const QString key,
|
||||
const QString fileName) const;
|
||||
// properties
|
||||
QString m_baseDir = QString("%1/awesomewidgets").
|
||||
arg(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation));
|
||||
QStringList m_dirs = QStringList() << QString("desktops") << QString("quotes")
|
||||
<< QString("scripts") << QString("upgrade") << QString("weather");
|
||||
QString m_baseDir = QString("%1/awesomewidgets")
|
||||
.arg(QStandardPaths::writableLocation(
|
||||
QStandardPaths::GenericDataLocation));
|
||||
QStringList m_dirs = QStringList()
|
||||
<< QString("desktops") << QString("quotes")
|
||||
<< QString("scripts") << QString("upgrade")
|
||||
<< QString("weather");
|
||||
};
|
||||
|
||||
|
||||
|
@ -39,8 +39,8 @@ AWDataAggregator::AWDataAggregator(QObject *parent)
|
||||
qRegisterMetaType<QHash<QString, QString>>("QHash<QString, QString>");
|
||||
|
||||
initScene();
|
||||
connect(this, SIGNAL(updateData(const QHash<QString, QString>)),
|
||||
this, SLOT(dataUpdate(const QHash<QString, QString>)));
|
||||
connect(this, SIGNAL(updateData(const QHash<QString, QString> &)), this,
|
||||
SLOT(dataUpdate(const QHash<QString, QString> &)));
|
||||
}
|
||||
|
||||
|
||||
@ -61,7 +61,7 @@ QList<float> AWDataAggregator::getData(const QString key) const
|
||||
}
|
||||
|
||||
|
||||
QString AWDataAggregator::htmlImage(const QPixmap source) const
|
||||
QString AWDataAggregator::htmlImage(const QPixmap &source) const
|
||||
{
|
||||
qCDebug(LOG_AW);
|
||||
|
||||
@ -70,8 +70,9 @@ QString AWDataAggregator::htmlImage(const QPixmap source) const
|
||||
source.save(&buffer, "PNG");
|
||||
|
||||
return byteArray.isEmpty()
|
||||
? QString()
|
||||
: QString("<img src=\"data:image/png;base64,%1\"/>").arg(QString(byteArray.toBase64()));
|
||||
? QString()
|
||||
: QString("<img src=\"data:image/png;base64,%1\"/>")
|
||||
.arg(QString(byteArray.toBase64()));
|
||||
}
|
||||
|
||||
|
||||
@ -104,18 +105,27 @@ void AWDataAggregator::setParameters(QVariantMap settings)
|
||||
boundaries[QString("batTooltip")] = 100.0;
|
||||
|
||||
requiredKeys.clear();
|
||||
if (configuration[QString("cpuTooltip")].toBool()) requiredKeys.append(QString("cpuTooltip"));
|
||||
if (configuration[QString("cpuclTooltip")].toBool()) requiredKeys.append(QString("cpuclTooltip"));
|
||||
if (configuration[QString("memTooltip")].toBool()) requiredKeys.append(QString("memTooltip"));
|
||||
if (configuration[QString("swapTooltip")].toBool()) requiredKeys.append(QString("swapTooltip"));
|
||||
if (configuration[QString("downTooltip")].toBool()) requiredKeys.append(QString("downTooltip"));
|
||||
if (configuration[QString("upTooltip")].toBool()) requiredKeys.append(QString("upTooltip"));
|
||||
if (configuration[QString("batTooltip")].toBool()) requiredKeys.append(QString("batTooltip"));
|
||||
if (configuration[QString("cpuTooltip")].toBool())
|
||||
requiredKeys.append(QString("cpuTooltip"));
|
||||
if (configuration[QString("cpuclTooltip")].toBool())
|
||||
requiredKeys.append(QString("cpuclTooltip"));
|
||||
if (configuration[QString("memTooltip")].toBool())
|
||||
requiredKeys.append(QString("memTooltip"));
|
||||
if (configuration[QString("swapTooltip")].toBool())
|
||||
requiredKeys.append(QString("swapTooltip"));
|
||||
if (configuration[QString("downTooltip")].toBool())
|
||||
requiredKeys.append(QString("downTooltip"));
|
||||
if (configuration[QString("upTooltip")].toBool())
|
||||
requiredKeys.append(QString("upTooltip"));
|
||||
if (configuration[QString("batTooltip")].toBool())
|
||||
requiredKeys.append(QString("batTooltip"));
|
||||
|
||||
// background
|
||||
toolTipScene->setBackgroundBrush(configuration[QString("useTooltipBackground")].toBool()
|
||||
? QBrush(QColor(configuration[QString("tooltipBackground")].toString()))
|
||||
: QBrush(Qt::NoBrush));
|
||||
toolTipScene->setBackgroundBrush(
|
||||
configuration[QString("useTooltipBackground")].toBool()
|
||||
? QBrush(QColor(
|
||||
configuration[QString("tooltipBackground")].toString()))
|
||||
: QBrush(Qt::NoBrush));
|
||||
}
|
||||
|
||||
|
||||
@ -127,7 +137,7 @@ QPixmap AWDataAggregator::tooltipImage()
|
||||
toolTipScene->clear();
|
||||
QPen pen;
|
||||
bool down = false;
|
||||
foreach(QString key, requiredKeys) {
|
||||
foreach (QString key, requiredKeys) {
|
||||
// create frame
|
||||
float normX = 100.0 / static_cast<float>(data[key].count());
|
||||
float normY = 100.0 / (1.5 * boundaries[key]);
|
||||
@ -136,19 +146,23 @@ QPixmap AWDataAggregator::tooltipImage()
|
||||
shift -= 100.0;
|
||||
// apply pen color
|
||||
if (key != QString("batTooltip"))
|
||||
pen.setColor(QColor(configuration[QString("%1Color").arg(key)].toString()));
|
||||
pen.setColor(
|
||||
QColor(configuration[QString("%1Color").arg(key)].toString()));
|
||||
// paint data inside frame
|
||||
for (int j=0; j<data[key].count()-1; j++) {
|
||||
for (int j = 0; j < data[key].count() - 1; j++) {
|
||||
// some magic here
|
||||
float x1 = j * normX + shift;
|
||||
float y1 = - fabs(data[key].at(j)) * normY + 5.0;
|
||||
float y1 = -fabs(data[key].at(j)) * normY + 5.0;
|
||||
float x2 = (j + 1) * normX + shift;
|
||||
float y2 = - fabs(data[key].at(j+1)) * normY + 5.0;
|
||||
float y2 = -fabs(data[key].at(j + 1)) * normY + 5.0;
|
||||
if (key == QString("batTooltip")) {
|
||||
if (data[key].at(j+1) > 0)
|
||||
pen.setColor(QColor(configuration[QString("batTooltipColor")].toString()));
|
||||
if (data[key].at(j + 1) > 0)
|
||||
pen.setColor(QColor(
|
||||
configuration[QString("batTooltipColor")].toString()));
|
||||
else
|
||||
pen.setColor(QColor(configuration[QString("batInTooltipColor")].toString()));
|
||||
pen.setColor(
|
||||
QColor(configuration[QString("batInTooltipColor")]
|
||||
.toString()));
|
||||
}
|
||||
toolTipScene->addLine(x1, y1, x2, y2, pen);
|
||||
}
|
||||
@ -160,7 +174,7 @@ QPixmap AWDataAggregator::tooltipImage()
|
||||
}
|
||||
|
||||
|
||||
void AWDataAggregator::dataUpdate(const QHash<QString, QString> values)
|
||||
void AWDataAggregator::dataUpdate(const QHash<QString, QString> &values)
|
||||
{
|
||||
qCDebug(LOG_AW);
|
||||
|
||||
@ -178,11 +192,15 @@ void AWDataAggregator::checkValue(const QString source, const float value,
|
||||
qCDebug(LOG_AW) << "Called with extremum" << extremum;
|
||||
|
||||
if (value >= 0.0) {
|
||||
if ((m_enablePopup) && (value > extremum) && (data[source].last() < extremum))
|
||||
return AWActions::sendNotification(QString("event"), notificationText(source, value));
|
||||
if ((m_enablePopup) && (value > extremum)
|
||||
&& (data[source].last() < extremum))
|
||||
return AWActions::sendNotification(QString("event"),
|
||||
notificationText(source, value));
|
||||
} else {
|
||||
if ((m_enablePopup) && (value < extremum) && (data[source].last() > extremum))
|
||||
return AWActions::sendNotification(QString("event"), notificationText(source, value));
|
||||
if ((m_enablePopup) && (value < extremum)
|
||||
&& (data[source].last() > extremum))
|
||||
return AWActions::sendNotification(QString("event"),
|
||||
notificationText(source, value));
|
||||
}
|
||||
}
|
||||
|
||||
@ -196,7 +214,8 @@ void AWDataAggregator::checkValue(const QString source, const QString current,
|
||||
qCDebug(LOG_AW) << "Received value" << received;
|
||||
|
||||
if ((m_enablePopup) && (current != received) && (!received.isEmpty()))
|
||||
return AWActions::sendNotification(QString("event"), notificationText(source, received));
|
||||
return AWActions::sendNotification(QString("event"),
|
||||
notificationText(source, received));
|
||||
}
|
||||
|
||||
|
||||
@ -214,7 +233,8 @@ void AWDataAggregator::initScene()
|
||||
}
|
||||
|
||||
|
||||
QString AWDataAggregator::notificationText(const QString source, const float value) const
|
||||
QString AWDataAggregator::notificationText(const QString source,
|
||||
const float value) const
|
||||
{
|
||||
qCDebug(LOG_AW);
|
||||
qCDebug(LOG_AW) << "Notification source" << source;
|
||||
@ -236,7 +256,8 @@ QString AWDataAggregator::notificationText(const QString source, const float val
|
||||
}
|
||||
|
||||
|
||||
QString AWDataAggregator::notificationText(const QString source, const QString value) const
|
||||
QString AWDataAggregator::notificationText(const QString source,
|
||||
const QString value) const
|
||||
{
|
||||
qCDebug(LOG_AW);
|
||||
qCDebug(LOG_AW) << "Notification source" << source;
|
||||
@ -250,7 +271,7 @@ QString AWDataAggregator::notificationText(const QString source, const QString v
|
||||
}
|
||||
|
||||
|
||||
void AWDataAggregator::setData(const QHash< QString, QString > values)
|
||||
void AWDataAggregator::setData(const QHash<QString, QString> &values)
|
||||
{
|
||||
qCDebug(LOG_AW);
|
||||
|
||||
@ -277,7 +298,8 @@ void AWDataAggregator::setData(const QHash< QString, QString > values)
|
||||
}
|
||||
|
||||
|
||||
void AWDataAggregator::setData(const QString source, float value, const float extremum)
|
||||
void AWDataAggregator::setData(const QString &source, float value,
|
||||
const float extremum)
|
||||
{
|
||||
qCDebug(LOG_AW);
|
||||
qCDebug(LOG_AW) << "Source" << source;
|
||||
@ -286,7 +308,8 @@ void AWDataAggregator::setData(const QString source, float value, const float ex
|
||||
|
||||
if (data[source].count() == 0)
|
||||
data[source].append(0.0);
|
||||
else if (data[source].count() > configuration[QString("tooltipNumber")].toInt())
|
||||
else if (data[source].count()
|
||||
> configuration[QString("tooltipNumber")].toInt())
|
||||
data[source].removeFirst();
|
||||
if (isnan(value))
|
||||
value = 0.0;
|
||||
@ -296,14 +319,17 @@ void AWDataAggregator::setData(const QString source, float value, const float ex
|
||||
|
||||
data[source].append(value);
|
||||
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());
|
||||
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")];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AWDataAggregator::setData(const bool dontInvert, const QString source, float value)
|
||||
void AWDataAggregator::setData(const bool dontInvert, const QString &source,
|
||||
float value)
|
||||
{
|
||||
qCDebug(LOG_AW);
|
||||
qCDebug(LOG_AW) << "Do not invert value" << dontInvert;
|
||||
|
@ -36,31 +36,34 @@ public:
|
||||
explicit AWDataAggregator(QObject *parent = nullptr);
|
||||
virtual ~AWDataAggregator();
|
||||
QList<float> getData(const QString key) const;
|
||||
QString htmlImage(const QPixmap source) const;
|
||||
QString htmlImage(const QPixmap &source) const;
|
||||
void setParameters(QVariantMap settings);
|
||||
QPixmap tooltipImage();
|
||||
|
||||
signals:
|
||||
void updateData(const QHash<QString, QString> values);
|
||||
void updateData(const QHash<QString, QString> &values);
|
||||
void toolTipPainted(const QString image) const;
|
||||
|
||||
public slots:
|
||||
void dataUpdate(const QHash<QString, QString> values);
|
||||
void dataUpdate(const QHash<QString, QString> &values);
|
||||
|
||||
private:
|
||||
// ui
|
||||
QGraphicsScene *toolTipScene = nullptr;
|
||||
QGraphicsView *toolTipView = nullptr;
|
||||
void checkValue(const QString source, const float value, const float extremum) const;
|
||||
void checkValue(const QString source, const QString current, const QString received) const;
|
||||
void checkValue(const QString source, const float value,
|
||||
const float extremum) const;
|
||||
void checkValue(const QString source, const QString current,
|
||||
const QString received) const;
|
||||
void initScene();
|
||||
QString notificationText(const QString source, const float value) const;
|
||||
QString notificationText(const QString source, const QString value) const;
|
||||
// main method
|
||||
void setData(const QHash<QString, QString> values);
|
||||
void setData(const QString source, float value, const float extremum = -1.0);
|
||||
void setData(const QHash<QString, QString> &values);
|
||||
void setData(const QString &source, float value,
|
||||
const float extremum = -1.0);
|
||||
// different signature for battery device
|
||||
void setData(const bool dontInvert, const QString source, float value);
|
||||
void setData(const bool dontInvert, const QString &source, float value);
|
||||
// variables
|
||||
int counts = 0;
|
||||
QVariantHash configuration;
|
||||
|
@ -23,7 +23,8 @@
|
||||
#include "awkeys.h"
|
||||
|
||||
|
||||
AWDataEngineAggregator::AWDataEngineAggregator(QObject *parent, const int interval)
|
||||
AWDataEngineAggregator::AWDataEngineAggregator(QObject *parent,
|
||||
const int interval)
|
||||
: QObject(parent)
|
||||
{
|
||||
qCDebug(LOG_AW);
|
||||
@ -37,10 +38,22 @@ AWDataEngineAggregator::~AWDataEngineAggregator()
|
||||
{
|
||||
qCDebug(LOG_AW);
|
||||
|
||||
// disconnect sources first
|
||||
disconnectSources();
|
||||
m_dataEngines.clear();
|
||||
}
|
||||
|
||||
|
||||
void AWDataEngineAggregator::disconnectSources()
|
||||
{
|
||||
qCDebug(LOG_AW);
|
||||
|
||||
foreach (QString dataengine, m_dataEngines.keys())
|
||||
foreach (QString source, m_dataEngines[dataengine]->sources())
|
||||
m_dataEngines[dataengine]->disconnectSource(source, parent());
|
||||
}
|
||||
|
||||
|
||||
void AWDataEngineAggregator::setInterval(const int _interval)
|
||||
{
|
||||
qCDebug(LOG_AW);
|
||||
@ -55,7 +68,8 @@ void AWDataEngineAggregator::dropSource(const QString source)
|
||||
qCDebug(LOG_AW);
|
||||
qCDebug(LOG_AW) << "Source" << source;
|
||||
|
||||
// FIXME there is no possiblibity to check to which dataengine source connected
|
||||
// FIXME there is no possibility to check to which dataengine source
|
||||
// connected
|
||||
// we will try to disconnect it from systemmonitor and extsysmon
|
||||
m_dataEngines[QString("systemmonitor")]->disconnectSource(source, parent());
|
||||
m_dataEngines[QString("extsysmon")]->disconnectSource(source, parent());
|
||||
@ -66,9 +80,12 @@ void AWDataEngineAggregator::reconnectSources()
|
||||
{
|
||||
qCDebug(LOG_AW);
|
||||
|
||||
m_dataEngines[QString("systemmonitor")]->connectAllSources(parent(), m_interval);
|
||||
m_dataEngines[QString("extsysmon")]->connectAllSources(parent(), m_interval);
|
||||
m_dataEngines[QString("time")]->connectSource(QString("Local"), parent(), 1000);
|
||||
m_dataEngines[QString("systemmonitor")]->connectAllSources(parent(),
|
||||
m_interval);
|
||||
m_dataEngines[QString("extsysmon")]->connectAllSources(parent(),
|
||||
m_interval);
|
||||
m_dataEngines[QString("time")]->connectSource(QString("Local"), parent(),
|
||||
1000);
|
||||
}
|
||||
|
||||
|
||||
@ -77,14 +94,17 @@ void AWDataEngineAggregator::initDataEngines()
|
||||
qCDebug(LOG_AW);
|
||||
|
||||
Plasma::DataEngineConsumer *deConsumer = new Plasma::DataEngineConsumer();
|
||||
m_dataEngines[QString("systemmonitor")] = deConsumer->dataEngine(QString("systemmonitor"));
|
||||
m_dataEngines[QString("extsysmon")] = deConsumer->dataEngine(QString("extsysmon"));
|
||||
m_dataEngines[QString("systemmonitor")]
|
||||
= deConsumer->dataEngine(QString("systemmonitor"));
|
||||
m_dataEngines[QString("extsysmon")]
|
||||
= deConsumer->dataEngine(QString("extsysmon"));
|
||||
m_dataEngines[QString("time")] = deConsumer->dataEngine(QString("time"));
|
||||
|
||||
// additional method required by systemmonitor structure
|
||||
connect(m_dataEngines[QString("systemmonitor")], &Plasma::DataEngine::sourceAdded,
|
||||
[this](const QString source) {
|
||||
connect(m_dataEngines[QString("systemmonitor")],
|
||||
&Plasma::DataEngine::sourceAdded, [this](const QString source) {
|
||||
static_cast<AWKeys *>(parent())->addDevice(source);
|
||||
m_dataEngines[QString("systemmonitor")]->connectSource(source, parent(), m_interval);
|
||||
m_dataEngines[QString("systemmonitor")]->connectSource(
|
||||
source, parent(), m_interval);
|
||||
});
|
||||
}
|
||||
|
@ -29,8 +29,10 @@ class AWDataEngineAggregator : public QObject
|
||||
Q_PROPERTY(int interval MEMBER m_interval WRITE setInterval);
|
||||
|
||||
public:
|
||||
explicit AWDataEngineAggregator(QObject *parent = nullptr, const int interval = 1000);
|
||||
explicit AWDataEngineAggregator(QObject *parent = nullptr,
|
||||
const int interval = 1000);
|
||||
virtual ~AWDataEngineAggregator();
|
||||
void disconnectSources();
|
||||
// properties
|
||||
void setInterval(const int _interval);
|
||||
|
||||
|
@ -55,8 +55,8 @@ AWKeys::AWKeys(QObject *parent)
|
||||
aggregator = new AWKeysAggregator(this);
|
||||
dataAggregator = new AWDataAggregator(this);
|
||||
// transfer signal from AWDataAggregator object to QML ui
|
||||
connect(dataAggregator, SIGNAL(toolTipPainted(const QString)),
|
||||
this, SIGNAL(needToolTipToBeUpdated(const QString)));
|
||||
connect(dataAggregator, SIGNAL(toolTipPainted(const QString)), this,
|
||||
SIGNAL(needToolTipToBeUpdated(const QString)));
|
||||
connect(this, SIGNAL(needToBeUpdated()), this, SLOT(updateTextData()));
|
||||
}
|
||||
|
||||
@ -66,15 +66,22 @@ AWKeys::~AWKeys()
|
||||
qCDebug(LOG_AW);
|
||||
|
||||
// extensions
|
||||
if (graphicalItems != nullptr) delete graphicalItems;
|
||||
if (extQuotes != nullptr) delete extQuotes;
|
||||
if (extScripts != nullptr) delete extScripts;
|
||||
if (extUpgrade != nullptr) delete extUpgrade;
|
||||
if (extWeather != nullptr) delete extWeather;
|
||||
if (graphicalItems != nullptr)
|
||||
delete graphicalItems;
|
||||
if (extQuotes != nullptr)
|
||||
delete extQuotes;
|
||||
if (extScripts != nullptr)
|
||||
delete extScripts;
|
||||
if (extUpgrade != nullptr)
|
||||
delete extUpgrade;
|
||||
if (extWeather != nullptr)
|
||||
delete extWeather;
|
||||
|
||||
// core
|
||||
if (dataEngineAggregator != nullptr) delete dataEngineAggregator;
|
||||
if (m_threadPool != nullptr) delete m_threadPool;
|
||||
if (dataEngineAggregator != nullptr)
|
||||
delete dataEngineAggregator;
|
||||
if (m_threadPool != nullptr)
|
||||
delete m_threadPool;
|
||||
delete aggregator;
|
||||
delete dataAggregator;
|
||||
}
|
||||
@ -89,7 +96,8 @@ void AWKeys::initDataAggregator(const QVariantMap tooltipParams)
|
||||
}
|
||||
|
||||
|
||||
void AWKeys::initKeys(const QString currentPattern, const int interval, const int limit)
|
||||
void AWKeys::initKeys(const QString currentPattern, const int interval,
|
||||
const int limit)
|
||||
{
|
||||
qCDebug(LOG_AW);
|
||||
qCDebug(LOG_AW) << "Pattern" << currentPattern;
|
||||
@ -105,7 +113,8 @@ void AWKeys::initKeys(const QString currentPattern, const int interval, const in
|
||||
} else
|
||||
dataEngineAggregator->setInterval(interval);
|
||||
#ifdef BUILD_FUTURE
|
||||
m_threadPool->setMaxThreadCount(limit == 0 ? QThread::idealThreadCount() : limit);
|
||||
m_threadPool->setMaxThreadCount(limit == 0 ? QThread::idealThreadCount()
|
||||
: limit);
|
||||
#endif /* BUILD_FUTURE */
|
||||
updateCache();
|
||||
|
||||
@ -148,13 +157,19 @@ QStringList AWKeys::dictKeys(const bool sorted, const QString regexp) const
|
||||
|
||||
QStringList allKeys;
|
||||
// weather
|
||||
for (int i=extWeather->activeItems().count()-1; i>=0; i--) {
|
||||
allKeys.append(extWeather->activeItems().at(i)->tag(QString("weatherId")));
|
||||
allKeys.append(extWeather->activeItems().at(i)->tag(QString("weather")));
|
||||
allKeys.append(extWeather->activeItems().at(i)->tag(QString("humidity")));
|
||||
allKeys.append(extWeather->activeItems().at(i)->tag(QString("pressure")));
|
||||
allKeys.append(extWeather->activeItems().at(i)->tag(QString("temperature")));
|
||||
allKeys.append(extWeather->activeItems().at(i)->tag(QString("timestamp")));
|
||||
for (int i = extWeather->activeItems().count() - 1; i >= 0; i--) {
|
||||
allKeys.append(
|
||||
extWeather->activeItems().at(i)->tag(QString("weatherId")));
|
||||
allKeys.append(
|
||||
extWeather->activeItems().at(i)->tag(QString("weather")));
|
||||
allKeys.append(
|
||||
extWeather->activeItems().at(i)->tag(QString("humidity")));
|
||||
allKeys.append(
|
||||
extWeather->activeItems().at(i)->tag(QString("pressure")));
|
||||
allKeys.append(
|
||||
extWeather->activeItems().at(i)->tag(QString("temperature")));
|
||||
allKeys.append(
|
||||
extWeather->activeItems().at(i)->tag(QString("timestamp")));
|
||||
}
|
||||
// time
|
||||
allKeys.append(QString("time"));
|
||||
@ -166,14 +181,14 @@ QStringList AWKeys::dictKeys(const bool sorted, const QString regexp) const
|
||||
allKeys.append(QString("uptime"));
|
||||
allKeys.append(QString("cuptime"));
|
||||
// cpuclock & cpu
|
||||
for (int i=QThread::idealThreadCount()-1; i>=0; i--) {
|
||||
for (int i = QThread::idealThreadCount() - 1; i >= 0; i--) {
|
||||
allKeys.append(QString("cpucl%1").arg(i));
|
||||
allKeys.append(QString("cpu%1").arg(i));
|
||||
}
|
||||
allKeys.append(QString("cpucl"));
|
||||
allKeys.append(QString("cpu"));
|
||||
// temperature
|
||||
for (int i=m_devices[QString("temp")].count()-1; i>=0; i--)
|
||||
for (int i = m_devices[QString("temp")].count() - 1; i >= 0; i--)
|
||||
allKeys.append(QString("temp%1").arg(i));
|
||||
// gputemp
|
||||
allKeys.append(QString("gputemp"));
|
||||
@ -198,7 +213,7 @@ QStringList AWKeys::dictKeys(const bool sorted, const QString regexp) const
|
||||
allKeys.append(QString("swaptotgb"));
|
||||
allKeys.append(QString("swap"));
|
||||
// hdd
|
||||
for (int i=m_devices[QString("mount")].count()-1; i>=0; i--) {
|
||||
for (int i = m_devices[QString("mount")].count() - 1; i >= 0; i--) {
|
||||
allKeys.append(QString("hddmb%1").arg(i));
|
||||
allKeys.append(QString("hddgb%1").arg(i));
|
||||
allKeys.append(QString("hddfreemb%1").arg(i));
|
||||
@ -208,15 +223,15 @@ QStringList AWKeys::dictKeys(const bool sorted, const QString regexp) const
|
||||
allKeys.append(QString("hdd%1").arg(i));
|
||||
}
|
||||
// hdd speed
|
||||
for (int i=m_devices[QString("disk")].count()-1; i>=0; i--) {
|
||||
for (int i = m_devices[QString("disk")].count() - 1; i >= 0; i--) {
|
||||
allKeys.append(QString("hddr%1").arg(i));
|
||||
allKeys.append(QString("hddw%1").arg(i));
|
||||
}
|
||||
// hdd temp
|
||||
for (int i=m_devices[QString("hdd")].count()-1; i>=0; i--)
|
||||
for (int i = m_devices[QString("hdd")].count() - 1; i >= 0; i--)
|
||||
allKeys.append(QString("hddtemp%1").arg(i));
|
||||
// network
|
||||
for (int i=m_devices[QString("net")].count()-1; i>=0; i--) {
|
||||
for (int i = m_devices[QString("net")].count() - 1; i >= 0; i--) {
|
||||
allKeys.append(QString("downunits%1").arg(i));
|
||||
allKeys.append(QString("upunits%1").arg(i));
|
||||
allKeys.append(QString("downkb%1").arg(i));
|
||||
@ -233,11 +248,11 @@ QStringList AWKeys::dictKeys(const bool sorted, const QString regexp) const
|
||||
allKeys.append(QString("netdev"));
|
||||
// battery
|
||||
allKeys.append(QString("ac"));
|
||||
QStringList allBatteryDevices = QDir(QString("/sys/class/power_supply")).
|
||||
entryList(QStringList() << QString("BAT*"),
|
||||
QDir::Dirs | QDir::NoDotAndDotDot,
|
||||
QDir::Name);
|
||||
for (int i=allBatteryDevices.count()-1; i>=0; i--)
|
||||
QStringList allBatteryDevices
|
||||
= QDir(QString("/sys/class/power_supply"))
|
||||
.entryList(QStringList() << QString("BAT*"),
|
||||
QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name);
|
||||
for (int i = allBatteryDevices.count() - 1; i >= 0; i--)
|
||||
allKeys.append(QString("bat%1").arg(i));
|
||||
allKeys.append(QString("bat"));
|
||||
// player
|
||||
@ -257,22 +272,27 @@ QStringList AWKeys::dictKeys(const bool sorted, const QString regexp) const
|
||||
allKeys.append(QString("pstotal"));
|
||||
allKeys.append(QString("ps"));
|
||||
// package manager
|
||||
for (int i=extUpgrade->activeItems().count()-1; i>=0; i--)
|
||||
allKeys.append(extUpgrade->activeItems().at(i)->tag(QString("pkgcount")));
|
||||
for (int i = extUpgrade->activeItems().count() - 1; i >= 0; i--)
|
||||
allKeys.append(
|
||||
extUpgrade->activeItems().at(i)->tag(QString("pkgcount")));
|
||||
// quotes
|
||||
for (int i=extQuotes->activeItems().count()-1; i>=0; i--) {
|
||||
for (int i = extQuotes->activeItems().count() - 1; i >= 0; i--) {
|
||||
allKeys.append(extQuotes->activeItems().at(i)->tag(QString("ask")));
|
||||
allKeys.append(extQuotes->activeItems().at(i)->tag(QString("askchg")));
|
||||
allKeys.append(extQuotes->activeItems().at(i)->tag(QString("percaskchg")));
|
||||
allKeys.append(
|
||||
extQuotes->activeItems().at(i)->tag(QString("percaskchg")));
|
||||
allKeys.append(extQuotes->activeItems().at(i)->tag(QString("bid")));
|
||||
allKeys.append(extQuotes->activeItems().at(i)->tag(QString("bidchg")));
|
||||
allKeys.append(extQuotes->activeItems().at(i)->tag(QString("percbidchg")));
|
||||
allKeys.append(
|
||||
extQuotes->activeItems().at(i)->tag(QString("percbidchg")));
|
||||
allKeys.append(extQuotes->activeItems().at(i)->tag(QString("price")));
|
||||
allKeys.append(extQuotes->activeItems().at(i)->tag(QString("pricechg")));
|
||||
allKeys.append(extQuotes->activeItems().at(i)->tag(QString("percpricechg")));
|
||||
allKeys.append(
|
||||
extQuotes->activeItems().at(i)->tag(QString("pricechg")));
|
||||
allKeys.append(
|
||||
extQuotes->activeItems().at(i)->tag(QString("percpricechg")));
|
||||
}
|
||||
// custom
|
||||
for (int i=extScripts->activeItems().count()-1; i>=0; i--)
|
||||
for (int i = extScripts->activeItems().count() - 1; i >= 0; i--)
|
||||
allKeys.append(extScripts->activeItems().at(i)->tag(QString("custom")));
|
||||
// desktop
|
||||
allKeys.append(QString("desktop"));
|
||||
@ -284,10 +304,10 @@ QStringList AWKeys::dictKeys(const bool sorted, const QString regexp) const
|
||||
allKeys.append(QString("la1"));
|
||||
// bars
|
||||
QStringList graphicalItemsKeys;
|
||||
foreach(GraphicalItem *item, graphicalItems->items())
|
||||
foreach (GraphicalItem *item, graphicalItems->items())
|
||||
graphicalItemsKeys.append(item->tag());
|
||||
graphicalItemsKeys.sort();
|
||||
for (int i=graphicalItemsKeys.count()-1; i>=0; i--)
|
||||
for (int i = graphicalItemsKeys.count() - 1; i >= 0; i--)
|
||||
allKeys.append(graphicalItemsKeys.at(i));
|
||||
|
||||
// sort if required
|
||||
@ -318,23 +338,47 @@ QString AWKeys::infoByKey(QString key) const
|
||||
|
||||
key.remove(QRegExp(QString("^bar[0-9]{1,}")));
|
||||
if (key.startsWith(QString("custom")))
|
||||
return extScripts->itemByTagNumber(key.remove(QString("custom")).toInt())->uniq();
|
||||
return extScripts->itemByTagNumber(
|
||||
key.remove(QString("custom")).toInt())
|
||||
->uniq();
|
||||
else if (key.contains(QRegExp(QString("^hdd[rw]"))))
|
||||
return QString("%1").arg(m_devices[QString("disk")][key.remove(QRegExp(QString("hdd[rw]"))).toInt()]);
|
||||
else if (key.contains(QRegExp(QString("^hdd([0-9]|mb|gb|freemb|freegb|totmb|totgb)"))))
|
||||
return QString("%1").arg(m_devices[QString("mount")][key.remove(QRegExp(QString("^hdd([0-9]|mb|gb|freemb|freegb|totmb|totgb)"))).toInt()]);
|
||||
return QString("%1").arg(m_devices[QString(
|
||||
"disk")][key.remove(QRegExp(QString("hdd[rw]"))).toInt()]);
|
||||
else if (key.contains(QRegExp(
|
||||
QString("^hdd([0-9]|mb|gb|freemb|freegb|totmb|totgb)"))))
|
||||
return QString("%1").arg(m_devices[QString(
|
||||
"mount")][key
|
||||
.remove(QRegExp(QString(
|
||||
"^hdd([0-9]|mb|gb|freemb|freegb|totmb|totgb)")))
|
||||
.toInt()]);
|
||||
else if (key.startsWith(QString("hddtemp")))
|
||||
return QString("%1").arg(m_devices[QString("hdd")][key.remove(QString("hddtemp")).toInt()]);
|
||||
return QString("%1").arg(
|
||||
m_devices[QString("hdd")][key.remove(QString("hddtemp")).toInt()]);
|
||||
else if (key.contains(QRegExp(QString("^(down|up)[0-9]"))))
|
||||
return QString("%1").arg(m_devices[QString("net")][key.remove(QRegExp(QString("^(down|up)"))).toInt()]);
|
||||
return QString("%1").arg(m_devices[QString(
|
||||
"net")][key.remove(QRegExp(QString("^(down|up)"))).toInt()]);
|
||||
else if (key.startsWith(QString("pkgcount")))
|
||||
return extUpgrade->itemByTagNumber(key.remove(QString("pkgcount")).toInt())->uniq();
|
||||
return extUpgrade->itemByTagNumber(
|
||||
key.remove(QString("pkgcount")).toInt())
|
||||
->uniq();
|
||||
else if (key.contains(QRegExp(QString("(^|perc)(ask|bid|price)(chg|)"))))
|
||||
return extQuotes->itemByTagNumber(key.remove(QRegExp(QString("(^|perc)(ask|bid|price)(chg|)"))).toInt())->uniq();
|
||||
else if (key.contains(QRegExp(QString("(weather|weatherId|humidity|pressure|temperature)"))))
|
||||
return extWeather->itemByTagNumber(key.remove(QRegExp(QString("(weather|weatherId|humidity|pressure|temperature)"))).toInt())->uniq();
|
||||
return extQuotes->itemByTagNumber(
|
||||
key.remove(QRegExp(QString(
|
||||
"(^|perc)(ask|bid|price)(chg|)")))
|
||||
.toInt())
|
||||
->uniq();
|
||||
else if (key.contains(QRegExp(
|
||||
QString("(weather|weatherId|humidity|pressure|temperature)"))))
|
||||
return extWeather
|
||||
->itemByTagNumber(
|
||||
key
|
||||
.remove(QRegExp(QString(
|
||||
"(weather|weatherId|humidity|pressure|temperature)")))
|
||||
.toInt())
|
||||
->uniq();
|
||||
else if (key.startsWith(QString("temp")))
|
||||
return QString("%1").arg(m_devices[QString("temp")][key.remove(QString("temp")).toInt()]);
|
||||
return QString("%1").arg(
|
||||
m_devices[QString("temp")][key.remove(QString("temp")).toInt()]);
|
||||
|
||||
return QString("(none)");
|
||||
}
|
||||
@ -346,7 +390,8 @@ QString AWKeys::valueByKey(QString key) const
|
||||
qCDebug(LOG_AW);
|
||||
qCDebug(LOG_AW) << "Requested key" << key;
|
||||
|
||||
return values.value(key.remove(QRegExp(QString("^bar[0-9]{1,}"))), QString(""));
|
||||
return values.value(key.remove(QRegExp(QString("^bar[0-9]{1,}"))),
|
||||
QString(""));
|
||||
}
|
||||
|
||||
|
||||
@ -356,7 +401,8 @@ void AWKeys::editItem(const QString type)
|
||||
qCDebug(LOG_AW) << "Item type" << type;
|
||||
|
||||
if (type == QString("graphicalitem")) {
|
||||
graphicalItems->setConfigArgs(dictKeys(true, QString("^(cpu(?!cl).*|gpu$|mem$|swap$|hdd[0-9].*|bat.*)")));
|
||||
graphicalItems->setConfigArgs(dictKeys(
|
||||
true, QString("^(cpu(?!cl).*|gpu$|mem$|swap$|hdd[0-9].*|bat.*)")));
|
||||
return graphicalItems->editItems();
|
||||
} else if (type == QString("extquotes")) {
|
||||
return extQuotes->editItems();
|
||||
@ -375,7 +421,8 @@ void AWKeys::addDevice(const QString source)
|
||||
qCDebug(LOG_AW);
|
||||
qCDebug(LOG_AW) << "Source" << source;
|
||||
|
||||
QRegExp diskRegexp = QRegExp(QString("disk/(?:md|sd|hd)[a-z|0-9]_.*/Rate/(?:rblk)"));
|
||||
QRegExp diskRegexp
|
||||
= QRegExp(QString("disk/(?:md|sd|hd)[a-z|0-9]_.*/Rate/(?:rblk)"));
|
||||
QRegExp mountRegexp = QRegExp(QString("partitions/.*/filllevel"));
|
||||
|
||||
if (source.contains(diskRegexp)) {
|
||||
@ -392,7 +439,8 @@ void AWKeys::addDevice(const QString source)
|
||||
}
|
||||
|
||||
|
||||
void AWKeys::dataUpdated(const QString &sourceName, const Plasma::DataEngine::Data &data)
|
||||
void AWKeys::dataUpdated(const QString &sourceName,
|
||||
const Plasma::DataEngine::Data &data)
|
||||
{
|
||||
qCDebug(LOG_AW);
|
||||
qCDebug(LOG_AW) << "Source" << sourceName;
|
||||
@ -403,8 +451,9 @@ void AWKeys::dataUpdated(const QString &sourceName, const Plasma::DataEngine::Da
|
||||
|
||||
#ifdef BUILD_FUTURE
|
||||
// run concurrent data update
|
||||
QtConcurrent::run(m_threadPool, this, &AWKeys::setDataBySource, sourceName, data);
|
||||
#else /* BUILD_FUTURE */
|
||||
QtConcurrent::run(m_threadPool, this, &AWKeys::setDataBySource, sourceName,
|
||||
data);
|
||||
#else /* BUILD_FUTURE */
|
||||
return setDataBySource(sourceName, data);
|
||||
#endif /* BUILD_FUTURE */
|
||||
}
|
||||
@ -414,15 +463,16 @@ void AWKeys::loadKeysFromCache()
|
||||
{
|
||||
qCDebug(LOG_AW);
|
||||
|
||||
QString fileName = QString("%1/awesomewidgets.ndx").
|
||||
arg(QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation));
|
||||
QString fileName = QString("%1/awesomewidgets.ndx")
|
||||
.arg(QStandardPaths::writableLocation(
|
||||
QStandardPaths::GenericCacheLocation));
|
||||
qCInfo(LOG_AW) << "Cache file" << fileName;
|
||||
QSettings cache(fileName, QSettings::IniFormat);
|
||||
|
||||
foreach(QString group, cache.childGroups()) {
|
||||
foreach (QString group, cache.childGroups()) {
|
||||
cache.beginGroup(group);
|
||||
m_devices.remove(group);
|
||||
foreach(QString key, cache.allKeys())
|
||||
foreach (QString key, cache.allKeys())
|
||||
m_devices[group].append(cache.value(key).toString());
|
||||
cache.endGroup();
|
||||
}
|
||||
@ -437,13 +487,19 @@ void AWKeys::reinitKeys()
|
||||
|
||||
// renew extensions
|
||||
// delete them if any
|
||||
if (graphicalItems != nullptr) delete graphicalItems;
|
||||
if (extQuotes != nullptr) delete extQuotes;
|
||||
if (extScripts != nullptr) delete extScripts;
|
||||
if (extUpgrade != nullptr) delete extUpgrade;
|
||||
if (extWeather != nullptr) delete extWeather;
|
||||
if (graphicalItems != nullptr)
|
||||
delete graphicalItems;
|
||||
if (extQuotes != nullptr)
|
||||
delete extQuotes;
|
||||
if (extScripts != nullptr)
|
||||
delete extScripts;
|
||||
if (extUpgrade != nullptr)
|
||||
delete extUpgrade;
|
||||
if (extWeather != nullptr)
|
||||
delete extWeather;
|
||||
// create
|
||||
graphicalItems = new ExtItemAggregator<GraphicalItem>(nullptr, QString("desktops"));
|
||||
graphicalItems
|
||||
= new ExtItemAggregator<GraphicalItem>(nullptr, QString("desktops"));
|
||||
extQuotes = new ExtItemAggregator<ExtQuotes>(nullptr, QString("quotes"));
|
||||
extScripts = new ExtItemAggregator<ExtScript>(nullptr, QString("scripts"));
|
||||
extUpgrade = new ExtItemAggregator<ExtUpgrade>(nullptr, QString("upgrade"));
|
||||
@ -456,7 +512,7 @@ void AWKeys::reinitKeys()
|
||||
// not documented feature - place all available tags
|
||||
m_pattern = m_pattern.replace(QString("$ALL"), [allKeys]() {
|
||||
QStringList strings;
|
||||
foreach(QString tag, allKeys)
|
||||
foreach (QString tag, allKeys)
|
||||
strings.append(QString("%1: $%1").arg(tag));
|
||||
return strings.join(QString(" | "));
|
||||
}());
|
||||
@ -466,9 +522,9 @@ void AWKeys::reinitKeys()
|
||||
// bars
|
||||
m_foundBars = [allKeys](QString pattern) {
|
||||
QStringList selectedKeys;
|
||||
foreach(QString key, allKeys)
|
||||
if ((key.startsWith(QString("bar"))) &&
|
||||
(pattern.contains(QString("$%1").arg(key)))) {
|
||||
foreach (QString key, allKeys)
|
||||
if ((key.startsWith(QString("bar")))
|
||||
&& (pattern.contains(QString("$%1").arg(key)))) {
|
||||
qCInfo(LOG_AW) << "Found bar" << key;
|
||||
selectedKeys.append(key);
|
||||
}
|
||||
@ -480,9 +536,9 @@ void AWKeys::reinitKeys()
|
||||
// main key list
|
||||
m_foundKeys = [allKeys](QString pattern) {
|
||||
QStringList selectedKeys;
|
||||
foreach(QString key, allKeys)
|
||||
if ((!key.startsWith(QString("bar"))) &&
|
||||
(pattern.contains(QString("$%1").arg(key)))) {
|
||||
foreach (QString key, allKeys)
|
||||
if ((!key.startsWith(QString("bar")))
|
||||
&& (pattern.contains(QString("$%1").arg(key)))) {
|
||||
qCInfo(LOG_AW) << "Found key" << key;
|
||||
selectedKeys.append(key);
|
||||
}
|
||||
@ -495,8 +551,10 @@ void AWKeys::reinitKeys()
|
||||
m_foundLambdas = [](QString pattern) {
|
||||
QStringList selectedKeys;
|
||||
// substring inside ${{ }} (with brackets) which should not contain ${{
|
||||
QRegularExpression lambdaRegexp(QString("\\$\\{\\{((?!\\$\\{\\{).)*?\\}\\}"));
|
||||
lambdaRegexp.setPatternOptions(QRegularExpression::DotMatchesEverythingOption);
|
||||
QRegularExpression lambdaRegexp(
|
||||
QString("\\$\\{\\{((?!\\$\\{\\{).)*?\\}\\}"));
|
||||
lambdaRegexp.setPatternOptions(
|
||||
QRegularExpression::DotMatchesEverythingOption);
|
||||
|
||||
QRegularExpressionMatchIterator it = lambdaRegexp.globalMatch(pattern);
|
||||
while (it.hasNext()) {
|
||||
@ -535,40 +593,49 @@ void AWKeys::addKeyToCache(const QString type, const QString key)
|
||||
qCDebug(LOG_AW) << "Key type" << type;
|
||||
qCDebug(LOG_AW) << "Key" << key;
|
||||
|
||||
QString fileName = QString("%1/awesomewidgets.ndx").
|
||||
arg(QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation));
|
||||
QString fileName = QString("%1/awesomewidgets.ndx")
|
||||
.arg(QStandardPaths::writableLocation(
|
||||
QStandardPaths::GenericCacheLocation));
|
||||
qCInfo(LOG_AW) << "Cache file" << fileName;
|
||||
QSettings cache(fileName, QSettings::IniFormat);
|
||||
|
||||
cache.beginGroup(type);
|
||||
QStringList cachedValues;
|
||||
foreach(QString key, cache.allKeys())
|
||||
foreach (QString key, cache.allKeys())
|
||||
cachedValues.append(cache.value(key).toString());
|
||||
|
||||
if (type == QString("hdd")) {
|
||||
QStringList allDevices = QDir(QString("/dev")).entryList(QDir::System, QDir::Name);
|
||||
QStringList devices = allDevices.filter(QRegExp(QString("^[hms]d[a-z]$")));
|
||||
foreach(QString dev, devices) {
|
||||
QStringList allDevices
|
||||
= QDir(QString("/dev")).entryList(QDir::System, QDir::Name);
|
||||
QStringList devices
|
||||
= allDevices.filter(QRegExp(QString("^[hms]d[a-z]$")));
|
||||
foreach (QString dev, devices) {
|
||||
QString device = QString("/dev/%1").arg(dev);
|
||||
if (cachedValues.contains(device))
|
||||
continue;
|
||||
qCInfo(LOG_AW) << "Found new key" << device << "for type" << type;
|
||||
cache.setValue(QString("%1").arg(cache.allKeys().count(), 3, 10, QChar('0')), device);
|
||||
cache.setValue(
|
||||
QString("%1").arg(cache.allKeys().count(), 3, 10, QChar('0')),
|
||||
device);
|
||||
}
|
||||
} else if (type == QString("net")) {
|
||||
QList<QNetworkInterface> rawInterfaceList = QNetworkInterface::allInterfaces();
|
||||
foreach(QNetworkInterface interface, rawInterfaceList) {
|
||||
QList<QNetworkInterface> rawInterfaceList
|
||||
= QNetworkInterface::allInterfaces();
|
||||
foreach (QNetworkInterface interface, rawInterfaceList) {
|
||||
QString device = interface.name();
|
||||
if (cachedValues.contains(device))
|
||||
continue;
|
||||
qCInfo(LOG_AW) << "Found new key" << device << "for type" << type;
|
||||
cache.setValue(QString("%1").arg(cache.allKeys().count(), 3, 10, QChar('0')), device);
|
||||
cache.setValue(
|
||||
QString("%1").arg(cache.allKeys().count(), 3, 10, QChar('0')),
|
||||
device);
|
||||
}
|
||||
} else {
|
||||
if (cachedValues.contains(key))
|
||||
return;
|
||||
qCInfo(LOG_AW) << "Found new key" << key << "for type" << type;
|
||||
cache.setValue(QString("%1").arg(cache.allKeys().count(), 3, 10, QChar('0')), key);
|
||||
cache.setValue(
|
||||
QString("%1").arg(cache.allKeys().count(), 3, 10, QChar('0')), key);
|
||||
}
|
||||
cache.endGroup();
|
||||
|
||||
@ -584,25 +651,32 @@ void AWKeys::calculateValues()
|
||||
qCDebug(LOG_AW);
|
||||
|
||||
// hddtot*
|
||||
foreach(QString device, m_devices[QString("mount")]) {
|
||||
foreach (QString device, m_devices[QString("mount")]) {
|
||||
int index = m_devices[QString("mount")].indexOf(device);
|
||||
values[QString("hddtotmb%1").arg(index)] = QString("%1").
|
||||
arg(values[QString("hddfreemb%1").arg(index)].toFloat()
|
||||
+ values[QString("hddmb%1").arg(index)].toFloat(), 5, 'f', 0);
|
||||
values[QString("hddtotgb%1").arg(index)] = QString("%1").
|
||||
arg(values[QString("hddfreegb%1").arg(index)].toFloat()
|
||||
+ values[QString("hddgb%1").arg(index)].toFloat(), 5, 'f', 1);
|
||||
values[QString("hddtotmb%1").arg(index)] = QString("%1").arg(
|
||||
values[QString("hddfreemb%1").arg(index)].toFloat()
|
||||
+ values[QString("hddmb%1").arg(index)].toFloat(),
|
||||
5, 'f', 0);
|
||||
values[QString("hddtotgb%1").arg(index)] = QString("%1").arg(
|
||||
values[QString("hddfreegb%1").arg(index)].toFloat()
|
||||
+ values[QString("hddgb%1").arg(index)].toFloat(),
|
||||
5, 'f', 1);
|
||||
}
|
||||
|
||||
// memtot*
|
||||
values[QString("memtotmb")] = QString("%1").
|
||||
arg(values[QString("memusedmb")].toInt() + values[QString("memfreemb")].toInt(), 5);
|
||||
values[QString("memtotgb")] = QString("%1").
|
||||
arg(values[QString("memusedgb")].toFloat() + values[QString("memfreegb")].toFloat(), 5, 'f', 1);
|
||||
values[QString("memtotmb")]
|
||||
= QString("%1").arg(values[QString("memusedmb")].toInt()
|
||||
+ values[QString("memfreemb")].toInt(),
|
||||
5);
|
||||
values[QString("memtotgb")]
|
||||
= QString("%1").arg(values[QString("memusedgb")].toFloat()
|
||||
+ values[QString("memfreegb")].toFloat(),
|
||||
5, 'f', 1);
|
||||
// mem
|
||||
values[QString("mem")] = QString("%1").
|
||||
arg(100.0 * values[QString("memmb")].toFloat() / values[QString("memtotmb")].toFloat(),
|
||||
5, 'f', 1);
|
||||
values[QString("mem")]
|
||||
= QString("%1").arg(100.0 * values[QString("memmb")].toFloat()
|
||||
/ values[QString("memtotmb")].toFloat(),
|
||||
5, 'f', 1);
|
||||
|
||||
// up, down, upkb, downkb, upunits, downunits
|
||||
int netIndex = m_devices[QString("net")].indexOf(values[QString("netdev")]);
|
||||
@ -614,27 +688,33 @@ void AWKeys::calculateValues()
|
||||
values[QString("upunits")] = values[QString("upunits%1").arg(netIndex)];
|
||||
|
||||
// swaptot*
|
||||
values[QString("swaptotmb")] = QString("%1").
|
||||
arg(values[QString("swapmb")].toInt() + values[QString("swapfreemb")].toInt(), 5);
|
||||
values[QString("swaptotgb")] = QString("%1").
|
||||
arg(values[QString("swapgb")].toFloat() + values[QString("swapfreegb")].toFloat(), 5, 'f', 1);
|
||||
values[QString("swaptotmb")]
|
||||
= QString("%1").arg(values[QString("swapmb")].toInt()
|
||||
+ values[QString("swapfreemb")].toInt(),
|
||||
5);
|
||||
values[QString("swaptotgb")]
|
||||
= QString("%1").arg(values[QString("swapgb")].toFloat()
|
||||
+ values[QString("swapfreegb")].toFloat(),
|
||||
5, 'f', 1);
|
||||
// swap
|
||||
values[QString("swap")] = QString("%1").
|
||||
arg(100.0 * values[QString("swapmb")].toFloat() / values[QString("swaptotmb")].toFloat(),
|
||||
5, 'f', 1);
|
||||
values[QString("swap")]
|
||||
= QString("%1").arg(100.0 * values[QString("swapmb")].toFloat()
|
||||
/ values[QString("swaptotmb")].toFloat(),
|
||||
5, 'f', 1);
|
||||
|
||||
// lambdas
|
||||
foreach(QString key, m_foundLambdas)
|
||||
foreach (QString key, m_foundLambdas)
|
||||
values[key] = [this](QString key) {
|
||||
QJSEngine engine;
|
||||
// apply $this values
|
||||
key.replace(QString("$this"), values[key]);
|
||||
foreach(QString lambdaKey, m_foundKeys)
|
||||
foreach (QString lambdaKey, m_foundKeys)
|
||||
key.replace(QString("$%1").arg(lambdaKey), values[lambdaKey]);
|
||||
qCInfo(LOG_AW) << "Expression" << key;
|
||||
QJSValue result = engine.evaluate(key);
|
||||
if (result.isError()) {
|
||||
qCWarning(LOG_AW) << "Uncaught exception at line" << result.property("lineNumber").toInt()
|
||||
qCWarning(LOG_AW) << "Uncaught exception at line"
|
||||
<< result.property("lineNumber").toInt()
|
||||
<< ":" << result.toString();
|
||||
return QString();
|
||||
} else {
|
||||
@ -652,27 +732,29 @@ QString AWKeys::parsePattern(QString pattern) const
|
||||
pattern.replace(QString("$$"), QString("$\\$\\"));
|
||||
|
||||
// lambdas
|
||||
foreach(QString key, m_foundLambdas)
|
||||
foreach (QString key, m_foundLambdas)
|
||||
pattern.replace(QString("${{%1}}").arg(key), values[key]);
|
||||
|
||||
// main keys
|
||||
foreach(QString key, m_foundKeys)
|
||||
pattern.replace(QString("$%1").arg(key), [](QString key, QString value) {
|
||||
if ((!key.startsWith(QString("custom")))
|
||||
&& (!key.startsWith(QString("weather"))))
|
||||
value.replace(QString(" "), QString(" "));
|
||||
return value;
|
||||
}(key, values[key]));
|
||||
foreach (QString key, m_foundKeys)
|
||||
pattern.replace(QString("$%1").arg(key),
|
||||
[](QString key, QString value) {
|
||||
if ((!key.startsWith(QString("custom")))
|
||||
&& (!key.startsWith(QString("weather"))))
|
||||
value.replace(QString(" "), QString(" "));
|
||||
return value;
|
||||
}(key, values[key]));
|
||||
|
||||
// bars
|
||||
foreach(QString bar,m_foundBars) {
|
||||
foreach (QString bar, m_foundBars) {
|
||||
GraphicalItem *item = graphicalItems->itemByTag(bar);
|
||||
QString key = bar;
|
||||
key.remove(QRegExp(QString("^bar[0-9]{1,}")));
|
||||
if (item->type() == GraphicalItem::Graph)
|
||||
pattern.replace(QString("$%1").arg(bar), item->image([](const QList<float> data) {
|
||||
return QVariant::fromValue<QList<float>>(data);
|
||||
}(dataAggregator->getData(key))));
|
||||
pattern.replace(QString("$%1").arg(bar),
|
||||
item->image([](const QList<float> data) {
|
||||
return QVariant::fromValue<QList<float>>(data);
|
||||
}(dataAggregator->getData(key))));
|
||||
else
|
||||
pattern.replace(QString("$%1").arg(bar), item->image(values[key]));
|
||||
}
|
||||
@ -695,7 +777,8 @@ void AWKeys::setDataBySource(const QString &sourceName, const QVariantMap &data)
|
||||
// first list init
|
||||
QStringList tags = aggregator->keysFromSource(sourceName);
|
||||
if (tags.isEmpty())
|
||||
tags = aggregator->registerSource(sourceName, data[QString("units")].toString());
|
||||
tags = aggregator->registerSource(sourceName,
|
||||
data[QString("units")].toString());
|
||||
|
||||
// update data or drop source if there are no matches
|
||||
if (tags.isEmpty()) {
|
||||
@ -705,11 +788,15 @@ void AWKeys::setDataBySource(const QString &sourceName, const QVariantMap &data)
|
||||
#ifdef BUILD_FUTURE
|
||||
m_mutex.lock();
|
||||
#endif /* BUILD_FUTURE */
|
||||
// HACK workaround for time values which are stored in the different path
|
||||
QVariant value = sourceName == QString("Local") ? data[QString("DateTime")] : data[QString("value")];
|
||||
std::for_each(tags.cbegin(), tags.cend(), [this, value](const QString tag) {
|
||||
values[tag] = aggregator->formater(value, tag);
|
||||
});
|
||||
// HACK workaround for time values which are stored in the different
|
||||
// path
|
||||
QVariant value = sourceName == QString("Local")
|
||||
? data[QString("DateTime")]
|
||||
: data[QString("value")];
|
||||
std::for_each(tags.cbegin(), tags.cend(),
|
||||
[this, value](const QString tag) {
|
||||
values[tag] = aggregator->formater(value, tag);
|
||||
});
|
||||
#ifdef BUILD_FUTURE
|
||||
m_mutex.unlock();
|
||||
#endif /* BUILD_FUTURE */
|
||||
|
@ -46,7 +46,8 @@ public:
|
||||
Q_INVOKABLE void initDataAggregator(const QVariantMap tooltipParams);
|
||||
Q_INVOKABLE void initKeys(const QString currentPattern, const int interval,
|
||||
const int limit);
|
||||
Q_INVOKABLE void setAggregatorProperty(const QString key, const QVariant value);
|
||||
Q_INVOKABLE void setAggregatorProperty(const QString key,
|
||||
const QVariant value);
|
||||
Q_INVOKABLE void setWrapNewLines(const bool wrap = false);
|
||||
Q_INVOKABLE void updateCache();
|
||||
// keys
|
||||
@ -61,9 +62,10 @@ public:
|
||||
|
||||
public slots:
|
||||
void addDevice(const QString source);
|
||||
void dataUpdated(const QString &sourceName, const Plasma::DataEngine::Data &data);
|
||||
void dataUpdated(const QString &sourceName,
|
||||
const Plasma::DataEngine::Data &data);
|
||||
// dummy method required by DataEngine connections
|
||||
void modelChanged(QString, QAbstractItemModel *) {};
|
||||
void modelChanged(QString, QAbstractItemModel *){};
|
||||
|
||||
signals:
|
||||
void dropSourceFromDataengine(const QString source);
|
||||
|
@ -39,7 +39,8 @@ AWKeysAggregator::~AWKeysAggregator()
|
||||
}
|
||||
|
||||
|
||||
QString AWKeysAggregator::formater(const QVariant data, const QString key) const
|
||||
QString AWKeysAggregator::formater(const QVariant &data,
|
||||
const QString &key) const
|
||||
{
|
||||
qCDebug(LOG_AW);
|
||||
qCDebug(LOG_AW) << "Data" << data;
|
||||
@ -68,7 +69,8 @@ QString AWKeysAggregator::formater(const QVariant data, const QString key) const
|
||||
output = data.toBool() ? m_acOnline : m_acOffline;
|
||||
break;
|
||||
case MemGBFormat:
|
||||
output = QString("%1").arg(data.toFloat() / (1024.0 * 1024.0), 5, 'f', 1);
|
||||
output
|
||||
= QString("%1").arg(data.toFloat() / (1024.0 * 1024.0), 5, 'f', 1);
|
||||
break;
|
||||
case MemMBFormat:
|
||||
output = QString("%1").arg(data.toFloat() / 1024.0, 5, 'f', 0);
|
||||
@ -101,7 +103,7 @@ QString AWKeysAggregator::formater(const QVariant data, const QString key) const
|
||||
case TimeCustom:
|
||||
output = m_customTime;
|
||||
[&output, loc, this](const QDateTime dt) {
|
||||
foreach(QString key, timeKeys)
|
||||
foreach (QString key, timeKeys)
|
||||
output.replace(QString("$%1").arg(key), loc.toString(dt, key));
|
||||
}(data.toDateTime());
|
||||
break;
|
||||
@ -116,19 +118,25 @@ QString AWKeysAggregator::formater(const QVariant data, const QString key) const
|
||||
break;
|
||||
case Uptime:
|
||||
case UptimeCustom:
|
||||
output = [](QString source, const int uptime) {
|
||||
int seconds = uptime - uptime % 60;
|
||||
int minutes = seconds / 60 % 60;
|
||||
int hours = ((seconds / 60) - minutes) / 60 % 24;
|
||||
int days = (((seconds / 60) - minutes) / 60 - hours) / 24;
|
||||
source.replace(QString("$dd"), QString("%1").arg(days, 3, 10, QChar('0')));
|
||||
source.replace(QString("$d"), QString("%1").arg(days));
|
||||
source.replace(QString("$hh"), QString("%1").arg(hours, 2, 10, QChar('0')));
|
||||
source.replace(QString("$h"), QString("%1").arg(hours));
|
||||
source.replace(QString("$mm"), QString("%1").arg(minutes, 2, 10, QChar('0')));
|
||||
source.replace(QString("$m"), QString("%1").arg(minutes));
|
||||
return source;
|
||||
}(m_formater[key] == Uptime ? QString("$ddd$hhh$mmm") : m_customUptime, data.toFloat());
|
||||
output =
|
||||
[](QString source, const int uptime) {
|
||||
int seconds = uptime - uptime % 60;
|
||||
int minutes = seconds / 60 % 60;
|
||||
int hours = ((seconds / 60) - minutes) / 60 % 24;
|
||||
int days = (((seconds / 60) - minutes) / 60 - hours) / 24;
|
||||
source.replace(QString("$dd"),
|
||||
QString("%1").arg(days, 3, 10, QChar('0')));
|
||||
source.replace(QString("$d"), QString("%1").arg(days));
|
||||
source.replace(QString("$hh"),
|
||||
QString("%1").arg(hours, 2, 10, QChar('0')));
|
||||
source.replace(QString("$h"), QString("%1").arg(hours));
|
||||
source.replace(QString("$mm"),
|
||||
QString("%1").arg(minutes, 2, 10, QChar('0')));
|
||||
source.replace(QString("$m"), QString("%1").arg(minutes));
|
||||
return source;
|
||||
}(m_formater[key] == Uptime ? QString("$ddd$hhh$mmm")
|
||||
: m_customUptime,
|
||||
data.toFloat());
|
||||
break;
|
||||
case NoFormat:
|
||||
default:
|
||||
@ -140,7 +148,7 @@ QString AWKeysAggregator::formater(const QVariant data, const QString key) const
|
||||
}
|
||||
|
||||
|
||||
QStringList AWKeysAggregator::keysFromSource(const QString source) const
|
||||
QStringList AWKeysAggregator::keysFromSource(const QString &source) const
|
||||
{
|
||||
qCDebug(LOG_AW);
|
||||
qCDebug(LOG_AW) << "Search for source" << source;
|
||||
@ -212,8 +220,10 @@ void AWKeysAggregator::setTranslate(const bool translate)
|
||||
}
|
||||
|
||||
|
||||
// HACK units required to define should the value be calculated as temperature or fan data
|
||||
QStringList AWKeysAggregator::registerSource(const QString source, const QString units)
|
||||
// HACK units required to define should the value be calculated as temperature
|
||||
// or fan data
|
||||
QStringList AWKeysAggregator::registerSource(const QString &source,
|
||||
const QString &units)
|
||||
{
|
||||
qCDebug(LOG_AW);
|
||||
qCDebug(LOG_AW) << "Source" << source;
|
||||
@ -227,7 +237,8 @@ QStringList AWKeysAggregator::registerSource(const QString source, const QString
|
||||
QRegExp mountFillRegExp = QRegExp(QString("partitions/.*/filllevel"));
|
||||
QRegExp mountFreeRegExp = QRegExp(QString("partitions/.*/freespace"));
|
||||
QRegExp mountUsedRegExp = QRegExp(QString("partitions/.*/usedspace"));
|
||||
QRegExp netRegExp = QRegExp(QString("network/interfaces/.*/(receiver|transmitter)/data$"));
|
||||
QRegExp netRegExp = QRegExp(
|
||||
QString("network/interfaces/.*/(receiver|transmitter)/data$"));
|
||||
|
||||
if (source == QString("battery/ac")) {
|
||||
// AC
|
||||
@ -393,8 +404,10 @@ QStringList AWKeysAggregator::registerSource(const QString source, const QString
|
||||
m_formater[QString("netdev")] = NoFormat;
|
||||
} else if (source.contains(netRegExp)) {
|
||||
// network speed
|
||||
QString type = source.contains(QString("receiver")) ? QString("down") : QString("up");
|
||||
int index = m_devices[QString("net")].indexOf(source.split(QChar('/'))[2]);
|
||||
QString type = source.contains(QString("receiver")) ? QString("down")
|
||||
: QString("up");
|
||||
int index
|
||||
= m_devices[QString("net")].indexOf(source.split(QChar('/'))[2]);
|
||||
if (index > -1) {
|
||||
// kb
|
||||
QString key = QString("%1kb%2").arg(type).arg(index);
|
||||
@ -459,7 +472,8 @@ QStringList AWKeysAggregator::registerSource(const QString source, const QString
|
||||
// temperature
|
||||
int index = m_devices[QString("temp")].indexOf(source);
|
||||
// FIXME on DE initialization there are no units key
|
||||
if (units.isEmpty()) return QStringList() << QString("temp%1").arg(index);
|
||||
if (units.isEmpty())
|
||||
return QStringList() << QString("temp%1").arg(index);
|
||||
if (index > -1) {
|
||||
QString key = QString("temp%1").arg(index);
|
||||
m_map[source] = key;
|
||||
|
@ -31,7 +31,8 @@ class AWKeysAggregator : public QObject
|
||||
Q_PROPERTY(QString acOffline MEMBER m_acOffline WRITE setAcOffline);
|
||||
Q_PROPERTY(QString acOnline MEMBER m_acOnline WRITE setAcOnline);
|
||||
Q_PROPERTY(QString customTime MEMBER m_customTime WRITE setCustomTime);
|
||||
Q_PROPERTY(QString customUptime MEMBER m_customUptime WRITE setCustomUptime);
|
||||
Q_PROPERTY(
|
||||
QString customUptime MEMBER m_customUptime WRITE setCustomUptime);
|
||||
Q_PROPERTY(QString tempUnits MEMBER m_tempUnits WRITE setTempUnits);
|
||||
Q_PROPERTY(bool translate MEMBER m_translate WRITE setTranslate);
|
||||
|
||||
@ -64,8 +65,8 @@ public:
|
||||
explicit AWKeysAggregator(QObject *parent = nullptr);
|
||||
virtual ~AWKeysAggregator();
|
||||
// get methods
|
||||
QString formater(const QVariant data, const QString key) const;
|
||||
QStringList keysFromSource(const QString source) const;
|
||||
QString formater(const QVariant &data, const QString &key) const;
|
||||
QStringList keysFromSource(const QString &source) const;
|
||||
// set methods
|
||||
void setAcOffline(const QString inactive);
|
||||
void setAcOnline(const QString active);
|
||||
@ -76,7 +77,7 @@ public:
|
||||
void setTranslate(const bool translate);
|
||||
|
||||
public slots:
|
||||
QStringList registerSource(const QString source, const QString units);
|
||||
QStringList registerSource(const QString &source, const QString &units);
|
||||
|
||||
private:
|
||||
float temperature(const float temp) const;
|
||||
@ -90,7 +91,7 @@ private:
|
||||
QHash<QString, FormaterType> m_formater;
|
||||
QHash<QString, QString> m_map;
|
||||
QString m_tempUnits;
|
||||
bool m_translate;
|
||||
bool m_translate = false;
|
||||
};
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user