1
.gitignore
vendored
@ -43,6 +43,7 @@ build
|
||||
*pkg.tar.[gx]z
|
||||
src
|
||||
pkg
|
||||
*.deb
|
||||
|
||||
# clion settings
|
||||
.idea
|
||||
|
@ -1,7 +1,16 @@
|
||||
install:
|
||||
- sudo apt-get update -qq
|
||||
- sudo apt-get install -y cmake extra-cmake-modules g++ git libkf5i18n-dev libkf5notifications-dev libkf5service-dev libkf5windowsystem-dev plasma-framework-dev qtbase5-dev qtdeclarative5-dev
|
||||
- git submobule update --init
|
||||
sudo: required
|
||||
dist: trusty
|
||||
|
||||
language: cpp
|
||||
os:
|
||||
- linux
|
||||
|
||||
before_script:
|
||||
- sudo apt-add-repository -y ppa:kubuntu-ppa/backports
|
||||
- sudo sed -i 's/trusty/wily/g' /etc/apt/sources.list
|
||||
- sudo sed -i 's/trusty/wily/g' /etc/apt/sources.list.d/kubuntu-ppa-backports-trusty.list
|
||||
- sudo apt-get -qq update
|
||||
- sudo apt-get -y -qq -o Dpkg::Options::=--force-confdef -o Dpkg::Options::=--force-confnew install libkf5i18n-dev libkf5notifications-dev libkf5service-dev libkf5windowsystem-dev plasma-framework-dev qtbase5-dev qtdeclarative5-dev extra-cmake-modules cmake g++
|
||||
- rm -rf build
|
||||
- mkdir build
|
||||
|
||||
|
@ -36,14 +36,15 @@ for more details. To avoid manual labor there is automatic cmake target named
|
||||
```
|
||||
|
||||
* `Q_PROPERTY` macro is allowed and recommended for QObject based classes.
|
||||
* Qt macros (e.g. `signals`, `slots`, `Q_OBJECT`, etc) are allowed.
|
||||
* Qt macros (e.g. `signals`, `slots`, `Q_OBJECT`, etc) are allowed. In other hand
|
||||
`Q_FOREACH` (`foreach`) is not allowed use `for (auto foo : bar)` instead.
|
||||
* Current project standard is **C++11**.
|
||||
* Do not use C-like code:
|
||||
* C-like style iteration if possible. Use `Q_FOREACH` (`foreach`) and
|
||||
* C-like style iteration if possible. Use `for (auto foo : bar)` and
|
||||
`std::for_each` instead if possible. It is also recommended to use iterators.
|
||||
* C-like casts, use `const_cast`, `static_cast`, `dymanic_Cast` instead. Using
|
||||
of `reinterpret_cast` is not recommended. It is highly recommended to use
|
||||
`dynamic_Cast` with the exception catching. It is also possible to use
|
||||
`dynamic_cast` with the exception catching. It is also possible to use
|
||||
`qvariant_cast` if required. Exception is class constructors, e.g.:
|
||||
|
||||
```
|
||||
@ -81,7 +82,7 @@ for more details. To avoid manual labor there is automatic cmake target named
|
||||
* Create one file (source and header) per class.
|
||||
* `else if` construction is allowed and recommended.
|
||||
* 'true ? foo : bar' construction is allowed and recommended for one-line assignment.
|
||||
* any global pointer should be assign to `nullptr` after deletion and before
|
||||
* Any global pointer should be assign to `nullptr` after deletion and before
|
||||
initialization. Exception: if object is deleted into class destructor.
|
||||
|
||||
Comments
|
||||
@ -146,13 +147,12 @@ For logging please use [QLoggingCategory](http://doc.qt.io/qt-5/qloggingcategory
|
||||
Available categories should be declared in `awdebug.*` files. The following log
|
||||
levels should be used:
|
||||
|
||||
* **debug** (`qCDebug()`) - method arguments information.
|
||||
* **debug** (`qCDebug()`) - method arguments information. Please note that it
|
||||
is recommended to logging all arguments in the one line.
|
||||
* **info** (`qCInfo()`) - additional information inside methods.
|
||||
* **warning** (`qCWarning()`) - not critical information, which may be caused by
|
||||
mistakes in configuration for example.
|
||||
* **error** (`qCError()`) - an error which has been captured in runtime. All errors
|
||||
should have own callback methods.
|
||||
* **critical** (`qCCritical()`) - a critical error. After this error program will
|
||||
* **critical** (`qCCritical()`) - a critical error. After this error program may
|
||||
be terminated.
|
||||
|
||||
The empty log string (e.g. `qCDebug();`) is not allowed because the method names
|
||||
|
@ -41,14 +41,14 @@ set(CPPCHECK_EXECUTABLE "/usr/bin/cppcheck" CACHE STRING "Path to cppcheck execu
|
||||
|
||||
# flags
|
||||
if (CMAKE_COMPILER_IS_GNUCXX)
|
||||
set(CMAKE_CXX_FLAGS "-Wall -Wno-cpp -std=c++11")
|
||||
set(CMAKE_CXX_FLAGS "-Wall -Wno-cpp -std=c++14")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
|
||||
set(CMAKE_CXX_FLAGS_OPTIMIZATION "-Ofast -DNDEBUG")
|
||||
# avoid newer gcc warnings
|
||||
add_definitions(-D_DEFAULT_SOURCE)
|
||||
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
set(CMAKE_CXX_FLAGS "-Wall -std=c++11 -stdlib=libc++")
|
||||
set(CMAKE_CXX_FLAGS "-Wall -std=c++14 -stdlib=libc++")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
|
||||
set(CMAKE_CXX_FLAGS_OPTIMIZATION "-Ofast -DNDEBUG")
|
||||
|
@ -28,12 +28,6 @@
|
||||
"category}][%{function}] %{message}"
|
||||
#endif /* LOG_FORMAT */
|
||||
|
||||
// redefine info because it doesn't log properly
|
||||
#ifdef qCInfo
|
||||
#undef qCInfo
|
||||
#endif /* qCInfo */
|
||||
#define qCInfo qCDebug
|
||||
|
||||
|
||||
Q_DECLARE_LOGGING_CATEGORY(LOG_AW)
|
||||
Q_DECLARE_LOGGING_CATEGORY(LOG_DP)
|
||||
|
@ -97,6 +97,15 @@ Item {
|
||||
text: awActions.getAboutText("translators")
|
||||
}
|
||||
|
||||
QtControls.Label {
|
||||
QtLayouts.Layout.fillWidth: true
|
||||
wrapMode: Text.WordWrap
|
||||
horizontalAlignment: Text.AlignJustify
|
||||
textFormat: Text.RichText
|
||||
text: awActions.getAboutText("3rdparty")
|
||||
onLinkActivated: Qt.openUrlExternally(link);
|
||||
}
|
||||
|
||||
QtControls.Label {
|
||||
QtLayouts.Layout.fillHeight: true
|
||||
QtLayouts.Layout.fillWidth: true
|
||||
@ -104,7 +113,7 @@ Item {
|
||||
horizontalAlignment: Text.AlignJustify
|
||||
verticalAlignment: Text.AlignTop
|
||||
textFormat: Text.RichText
|
||||
text: awActions.getAboutText("3rdparty")
|
||||
text: awActions.getAboutText("thanks")
|
||||
onLinkActivated: Qt.openUrlExternally(link);
|
||||
}
|
||||
}
|
||||
|
@ -198,7 +198,7 @@ Item {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
QtControls.ComboBox {
|
||||
width: parent.width * 1 / 5
|
||||
width: parent.width * 2 / 5
|
||||
textRole: "label"
|
||||
model: [
|
||||
{
|
||||
@ -252,11 +252,20 @@ Item {
|
||||
{
|
||||
'label': i18n("Weathers"),
|
||||
'regexp': "^(weather(Id)?|humidity|pressure|temperature|timestamp)"
|
||||
},
|
||||
{
|
||||
'label': i18n("Functions"),
|
||||
'regexp': "functions"
|
||||
}
|
||||
]
|
||||
onCurrentIndexChanged: {
|
||||
if (debug) console.debug()
|
||||
tags.model = awKeys.dictKeys(true, model[currentIndex]["regexp"])
|
||||
if (model[currentIndex]["regexp"] == "functions")
|
||||
tags.model = ["{{\n\n}}", "template{{\n\n}}",
|
||||
"aw_all<>()", "aw_count<>()", "aw_keys<>()",
|
||||
"aw_names<>()"]
|
||||
else
|
||||
tags.model = awKeys.dictKeys(true, model[currentIndex]["regexp"])
|
||||
if (debug) console.info("Init model", tags.model, "for", model[currentIndex]["label"])
|
||||
tags.currentIndex = -1
|
||||
}
|
||||
@ -293,18 +302,6 @@ Item {
|
||||
awActions.sendNotification("tag", message)
|
||||
}
|
||||
}
|
||||
QtControls.Button {
|
||||
width: parent.width * 1 / 5
|
||||
text: i18n("Add lambda")
|
||||
|
||||
onClicked: {
|
||||
if (debug) console.debug("Lambda button")
|
||||
var pos = textPattern.cursorPosition
|
||||
var selected = textPattern.selectedText
|
||||
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
|
||||
textPattern.insert(pos, selected + "${{\n\n}}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Row {
|
||||
|
@ -144,6 +144,14 @@ QString AWActions::getAboutText(const QString type) const
|
||||
.arg(trdPartyList.at(i).split(QChar(','))[1])
|
||||
.arg(trdPartyList.at(i).split(QChar(','))[2]);
|
||||
text = i18n("This software uses: %1", trdPartyList.join(QString(", ")));
|
||||
} else if (type == QString("thanks")) {
|
||||
QStringList thanks = QString(SPECIAL_THANKS)
|
||||
.split(QChar(';'), QString::SkipEmptyParts);
|
||||
for (int i = 0; i < thanks.count(); i++)
|
||||
thanks[i] = QString("<a href=\"%2\">%1</a>")
|
||||
.arg(thanks.at(i).split(QChar(','))[0])
|
||||
.arg(thanks.at(i).split(QChar(','))[1]);
|
||||
text = i18n("Special thanks to %1", thanks.join(QString(", ")));
|
||||
}
|
||||
|
||||
return text;
|
||||
@ -171,8 +179,7 @@ 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)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Event" << eventId;
|
||||
qCDebug(LOG_AW) << "Message" << message;
|
||||
qCDebug(LOG_AW) << "Event" << eventId << "with message" << message;
|
||||
|
||||
KNotification *notification = KNotification::event(
|
||||
eventId, QString("Awesome Widget ::: %1").arg(eventId), message);
|
||||
@ -221,18 +228,17 @@ void AWActions::showUpdates(const QString version) const
|
||||
void AWActions::versionReplyRecieved(QNetworkReply *reply,
|
||||
const bool showAnyway) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Return code" << reply->error();
|
||||
qCDebug(LOG_AW) << "Reply error message" << reply->errorString();
|
||||
qCDebug(LOG_AW) << "Show anyway" << showAnyway;
|
||||
qCDebug(LOG_AW) << "Return code" << reply->error() << "with message"
|
||||
<< reply->errorString() << "and show anyway" << showAnyway;
|
||||
|
||||
QJsonParseError error;
|
||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(reply->readAll(), &error);
|
||||
reply->deleteLater();
|
||||
if ((reply->error() != QNetworkReply::NoError)
|
||||
|| (error.error != QJsonParseError::NoError)) {
|
||||
qCWarning(LOG_AW) << "Parse error" << error.errorString();
|
||||
return;
|
||||
}
|
||||
reply->deleteLater();
|
||||
|
||||
// convert to map
|
||||
QVariantMap firstRelease = jsonDoc.toVariant().toList().first().toMap();
|
||||
@ -244,9 +250,9 @@ void AWActions::versionReplyRecieved(QNetworkReply *reply,
|
||||
int old_major = QString(VERSION).split(QChar('.')).at(0).toInt();
|
||||
int old_minor = QString(VERSION).split(QChar('.')).at(1).toInt();
|
||||
int old_patch = QString(VERSION).split(QChar('.')).at(2).toInt();
|
||||
int new_major = QString(version).split(QChar('.')).at(0).toInt();
|
||||
int new_minor = QString(version).split(QChar('.')).at(1).toInt();
|
||||
int new_patch = QString(version).split(QChar('.')).at(2).toInt();
|
||||
int new_major = version.split(QChar('.')).at(0).toInt();
|
||||
int new_minor = version.split(QChar('.')).at(1).toInt();
|
||||
int new_patch = 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)
|
||||
|
@ -61,7 +61,7 @@ bool AWConfigHelper::exportConfiguration(QObject *nativeConfig,
|
||||
QQmlPropertyMap *configuration
|
||||
= static_cast<QQmlPropertyMap *>(nativeConfig);
|
||||
settings.beginGroup(QString("plasmoid"));
|
||||
foreach (QString key, configuration->keys()) {
|
||||
for (auto key : configuration->keys()) {
|
||||
QVariant value = configuration->value(key);
|
||||
if (!value.isValid())
|
||||
continue;
|
||||
@ -70,13 +70,13 @@ bool AWConfigHelper::exportConfiguration(QObject *nativeConfig,
|
||||
settings.endGroup();
|
||||
|
||||
// extensions
|
||||
foreach (QString item, m_dirs) {
|
||||
for (auto 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)
|
||||
for (auto it : items)
|
||||
copyExtensions(it, item, settings, false);
|
||||
settings.endGroup();
|
||||
}
|
||||
@ -112,9 +112,9 @@ QVariantMap AWConfigHelper::importConfiguration(const QString fileName,
|
||||
|
||||
// extensions
|
||||
if (importExtensions) {
|
||||
foreach (QString item, m_dirs) {
|
||||
for (auto item : m_dirs) {
|
||||
settings.beginGroup(item);
|
||||
foreach (QString it, settings.childGroups())
|
||||
for (auto it : settings.childGroups())
|
||||
copyExtensions(it, item, settings, true);
|
||||
settings.endGroup();
|
||||
}
|
||||
@ -137,7 +137,7 @@ QVariantMap AWConfigHelper::importConfiguration(const QString fileName,
|
||||
// plasmoid configuration
|
||||
if (importPlasmoid) {
|
||||
settings.beginGroup(QString("plasmoid"));
|
||||
foreach (QString key, settings.childKeys())
|
||||
for (auto key : settings.childKeys())
|
||||
configuration[key] = settings.value(key);
|
||||
settings.endGroup();
|
||||
}
|
||||
@ -216,9 +216,8 @@ void AWConfigHelper::copyExtensions(const QString item, const QString type,
|
||||
QSettings &settings,
|
||||
const bool inverse) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Extension" << item;
|
||||
qCDebug(LOG_AW) << "Type" << type;
|
||||
qCDebug(LOG_AW) << "Inverse" << inverse;
|
||||
qCDebug(LOG_AW) << "Extension" << item << "has type" << type
|
||||
<< "inverse copying" << inverse;
|
||||
|
||||
settings.beginGroup(item);
|
||||
QSettings itemSettings(
|
||||
@ -239,7 +238,7 @@ void AWConfigHelper::copyExtensions(const QString item, const QString type,
|
||||
|
||||
void AWConfigHelper::copySettings(QSettings &from, QSettings &to) const
|
||||
{
|
||||
foreach (QString key, from.childKeys())
|
||||
for (auto key : from.childKeys())
|
||||
to.setValue(key, from.value(key));
|
||||
}
|
||||
|
||||
@ -247,8 +246,7 @@ void AWConfigHelper::copySettings(QSettings &from, QSettings &to) const
|
||||
void AWConfigHelper::readFile(QSettings &settings, const QString key,
|
||||
const QString fileName) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Key" << key;
|
||||
qCDebug(LOG_AW) << "File" << fileName;
|
||||
qCDebug(LOG_AW) << "Key" << key << "from file" << fileName;
|
||||
|
||||
QFile file(fileName);
|
||||
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
@ -264,8 +262,7 @@ void AWConfigHelper::readFile(QSettings &settings, const QString key,
|
||||
void AWConfigHelper::writeFile(QSettings &settings, const QString key,
|
||||
const QString fileName) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Key" << key;
|
||||
qCDebug(LOG_AW) << "File" << fileName;
|
||||
qCDebug(LOG_AW) << "Key" << key << "to file" << fileName;
|
||||
|
||||
if (!settings.contains(key))
|
||||
return;
|
||||
|
@ -90,7 +90,7 @@ void AWDataAggregator::setParameters(QVariantMap settings)
|
||||
counts += configuration[QString("downTooltip")].toInt();
|
||||
counts += configuration[QString("batTooltip")].toInt();
|
||||
// resize tooltip image
|
||||
toolTipView->resize(100.0 * counts, 105.0);
|
||||
toolTipView->resize(100 * counts, 105);
|
||||
|
||||
boundaries[QString("cpuTooltip")] = 100.0;
|
||||
boundaries[QString("cpuclTooltip")] = 4000.0;
|
||||
@ -131,7 +131,7 @@ QPixmap AWDataAggregator::tooltipImage()
|
||||
toolTipScene->clear();
|
||||
QPen pen;
|
||||
bool down = false;
|
||||
foreach (QString key, requiredKeys) {
|
||||
for (auto key : requiredKeys) {
|
||||
// create frame
|
||||
float normX = 100.0 / static_cast<float>(data[key].count());
|
||||
float normY = 100.0 / (1.5 * boundaries[key]);
|
||||
@ -179,9 +179,8 @@ void AWDataAggregator::dataUpdate(const QHash<QString, QString> &values)
|
||||
void AWDataAggregator::checkValue(const QString source, const float value,
|
||||
const float extremum) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Notification source" << source;
|
||||
qCDebug(LOG_AW) << "Value" << value;
|
||||
qCDebug(LOG_AW) << "Called with extremum" << extremum;
|
||||
qCDebug(LOG_AW) << "Notification source" << source << "with value" << value
|
||||
<< "called with extremum" << extremum;
|
||||
|
||||
if (value >= 0.0) {
|
||||
if ((m_enablePopup) && (value > extremum)
|
||||
@ -200,9 +199,8 @@ void AWDataAggregator::checkValue(const QString source, const float value,
|
||||
void AWDataAggregator::checkValue(const QString source, const QString current,
|
||||
const QString received) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Notification source" << source;
|
||||
qCDebug(LOG_AW) << "Current value" << current;
|
||||
qCDebug(LOG_AW) << "Received value" << received;
|
||||
qCDebug(LOG_AW) << "Notification source" << source << "with current value"
|
||||
<< current << "and received one" << received;
|
||||
|
||||
if ((m_enablePopup) && (current != received) && (!received.isEmpty()))
|
||||
return AWActions::sendNotification(QString("event"),
|
||||
@ -225,8 +223,7 @@ void AWDataAggregator::initScene()
|
||||
QString AWDataAggregator::notificationText(const QString source,
|
||||
const float value) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Notification source" << source;
|
||||
qCDebug(LOG_AW) << "Value" << value;
|
||||
qCDebug(LOG_AW) << "Notification source" << source << "with value" << value;
|
||||
|
||||
QString output;
|
||||
if (source == QString("batTooltip"))
|
||||
@ -247,8 +244,7 @@ QString AWDataAggregator::notificationText(const QString source,
|
||||
QString AWDataAggregator::notificationText(const QString source,
|
||||
const QString value) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Notification source" << source;
|
||||
qCDebug(LOG_AW) << "Value" << value;
|
||||
qCDebug(LOG_AW) << "Notification source" << source << "with value" << value;
|
||||
|
||||
QString output;
|
||||
if (source == QString("netdev"))
|
||||
@ -287,9 +283,8 @@ void AWDataAggregator::setData(const QHash<QString, QString> &values)
|
||||
void AWDataAggregator::setData(const QString &source, float value,
|
||||
const float extremum)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Source" << source;
|
||||
qCDebug(LOG_AW) << "Value" << value;
|
||||
qCDebug(LOG_AW) << "Called with extremum" << extremum;
|
||||
qCDebug(LOG_AW) << "Source" << source << "to value" << value
|
||||
<< "with extremum" << extremum;
|
||||
|
||||
if (data[source].count() == 0)
|
||||
data[source].append(0.0);
|
||||
@ -316,9 +311,8 @@ void AWDataAggregator::setData(const QString &source, float value,
|
||||
void AWDataAggregator::setData(const bool dontInvert, const QString &source,
|
||||
float value)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Do not invert value" << dontInvert;
|
||||
qCDebug(LOG_AW) << "Source" << source;
|
||||
qCDebug(LOG_AW) << "Value" << value;
|
||||
qCDebug(LOG_AW) << "Do not invert" << dontInvert << "value" << value
|
||||
<< "for source" << source;
|
||||
|
||||
// invert values for different battery colours
|
||||
value = dontInvert ? value : -value;
|
||||
|
@ -17,8 +17,6 @@
|
||||
|
||||
#include "awdataengineaggregator.h"
|
||||
|
||||
#include <Plasma/DataEngineConsumer>
|
||||
|
||||
#include "awdebug.h"
|
||||
#include "awkeys.h"
|
||||
|
||||
@ -41,14 +39,15 @@ AWDataEngineAggregator::~AWDataEngineAggregator()
|
||||
// disconnect sources first
|
||||
disconnectSources();
|
||||
m_dataEngines.clear();
|
||||
delete m_consumer;
|
||||
}
|
||||
|
||||
|
||||
void AWDataEngineAggregator::disconnectSources()
|
||||
{
|
||||
foreach (QString dataengine, m_dataEngines.keys())
|
||||
foreach (QString source, m_dataEngines[dataengine]->sources())
|
||||
m_dataEngines[dataengine]->disconnectSource(source, parent());
|
||||
for (auto dataengine : m_dataEngines.values())
|
||||
for (auto source : dataengine->sources())
|
||||
dataengine->disconnectSource(source, parent());
|
||||
}
|
||||
|
||||
|
||||
@ -84,17 +83,17 @@ void AWDataEngineAggregator::reconnectSources()
|
||||
|
||||
void AWDataEngineAggregator::initDataEngines()
|
||||
{
|
||||
Plasma::DataEngineConsumer *deConsumer = new Plasma::DataEngineConsumer();
|
||||
m_consumer = new Plasma::DataEngineConsumer();
|
||||
m_dataEngines[QString("systemmonitor")]
|
||||
= deConsumer->dataEngine(QString("systemmonitor"));
|
||||
= m_consumer->dataEngine(QString("systemmonitor"));
|
||||
m_dataEngines[QString("extsysmon")]
|
||||
= deConsumer->dataEngine(QString("extsysmon"));
|
||||
m_dataEngines[QString("time")] = deConsumer->dataEngine(QString("time"));
|
||||
= m_consumer->dataEngine(QString("extsysmon"));
|
||||
m_dataEngines[QString("time")] = m_consumer->dataEngine(QString("time"));
|
||||
|
||||
// additional method required by systemmonitor structure
|
||||
connect(m_dataEngines[QString("systemmonitor")],
|
||||
&Plasma::DataEngine::sourceAdded, [this](const QString source) {
|
||||
static_cast<AWKeys *>(parent())->addDevice(source);
|
||||
emit(deviceAdded(source));
|
||||
m_dataEngines[QString("systemmonitor")]->connectSource(
|
||||
source, parent(), m_interval);
|
||||
});
|
||||
|
@ -20,6 +20,7 @@
|
||||
#define AWDATAENGINEAGGREGATOR_H
|
||||
|
||||
#include <Plasma/DataEngine>
|
||||
#include <Plasma/DataEngineConsumer>
|
||||
|
||||
#include <QObject>
|
||||
|
||||
@ -37,12 +38,16 @@ public:
|
||||
// properties
|
||||
void setInterval(const int _interval);
|
||||
|
||||
signals:
|
||||
void deviceAdded(const QString &source);
|
||||
|
||||
public slots:
|
||||
void dropSource(const QString source);
|
||||
void reconnectSources();
|
||||
|
||||
private:
|
||||
void initDataEngines();
|
||||
Plasma::DataEngineConsumer *m_consumer = nullptr;
|
||||
QHash<QString, Plasma::DataEngine *> m_dataEngines;
|
||||
int m_interval;
|
||||
};
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
#include "awactions.h"
|
||||
#include "awconfighelper.h"
|
||||
#include "awdataengineaggregator.h"
|
||||
#include "awkeys.h"
|
||||
|
||||
|
||||
|
101
sources/awesome-widget/plugin/awkeycache.cpp
Normal file
@ -0,0 +1,101 @@
|
||||
/***************************************************************************
|
||||
* 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 "awkeycache.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QNetworkInterface>
|
||||
#include <QRegExp>
|
||||
#include <QSettings>
|
||||
#include <QStandardPaths>
|
||||
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
bool AWKeyCache::addKeyToCache(const QString type, const QString key)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Key" << key << "with type" << type;
|
||||
|
||||
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;
|
||||
for (auto 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]$")));
|
||||
for (auto 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);
|
||||
}
|
||||
} else if (type == QString("net")) {
|
||||
QList<QNetworkInterface> rawInterfaceList
|
||||
= QNetworkInterface::allInterfaces();
|
||||
for (auto 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);
|
||||
}
|
||||
} else {
|
||||
if (cachedValues.contains(key))
|
||||
return false;
|
||||
qCInfo(LOG_AW) << "Found new key" << key << "for type" << type;
|
||||
cache.setValue(
|
||||
QString("%1").arg(cache.allKeys().count(), 3, 10, QChar('0')), key);
|
||||
}
|
||||
cache.endGroup();
|
||||
|
||||
cache.sync();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
QHash<QString, QStringList> AWKeyCache::loadKeysFromCache()
|
||||
{
|
||||
QString fileName = QString("%1/awesomewidgets.ndx")
|
||||
.arg(QStandardPaths::writableLocation(
|
||||
QStandardPaths::GenericCacheLocation));
|
||||
qCInfo(LOG_AW) << "Cache file" << fileName;
|
||||
QSettings cache(fileName, QSettings::IniFormat);
|
||||
|
||||
QHash<QString, QStringList> devices;
|
||||
for (auto group : cache.childGroups()) {
|
||||
cache.beginGroup(group);
|
||||
for (auto key : cache.allKeys())
|
||||
devices[group].append(cache.value(key).toString());
|
||||
cache.endGroup();
|
||||
}
|
||||
|
||||
return devices;
|
||||
}
|
33
sources/awesome-widget/plugin/awkeycache.h
Normal file
@ -0,0 +1,33 @@
|
||||
/***************************************************************************
|
||||
* 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 AWKEYCACHE_H
|
||||
#define AWKEYCACHE_H
|
||||
|
||||
#include <QHash>
|
||||
#include <QString>
|
||||
|
||||
|
||||
namespace AWKeyCache
|
||||
{
|
||||
bool addKeyToCache(const QString type, const QString key = QString(""));
|
||||
QHash<QString, QStringList> loadKeysFromCache();
|
||||
};
|
||||
|
||||
|
||||
#endif /* AWKEYCACHE_H */
|
405
sources/awesome-widget/plugin/awkeyoperations.cpp
Normal file
@ -0,0 +1,405 @@
|
||||
/***************************************************************************
|
||||
* 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 "awkeyoperations.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QJSEngine>
|
||||
#include <QRegExp>
|
||||
#include <QThread>
|
||||
|
||||
#include "awdebug.h"
|
||||
#include "awkeycache.h"
|
||||
#include "awpatternfunctions.h"
|
||||
#include "version.h"
|
||||
// extensions
|
||||
#include "extquotes.h"
|
||||
#include "extscript.h"
|
||||
#include "extupgrade.h"
|
||||
#include "extweather.h"
|
||||
#include "graphicalitem.h"
|
||||
|
||||
|
||||
AWKeyOperations::AWKeyOperations(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
}
|
||||
|
||||
|
||||
AWKeyOperations::~AWKeyOperations()
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
|
||||
// extensions
|
||||
delete graphicalItems;
|
||||
delete extQuotes;
|
||||
delete extScripts;
|
||||
delete extUpgrade;
|
||||
delete extWeather;
|
||||
}
|
||||
|
||||
|
||||
QStringList AWKeyOperations::devices(const QString type) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Looking for type" << type;
|
||||
|
||||
return m_devices[type];
|
||||
}
|
||||
|
||||
|
||||
QHash<QString, QStringList> AWKeyOperations::devices() const
|
||||
{
|
||||
return m_devices;
|
||||
}
|
||||
|
||||
|
||||
void AWKeyOperations::updateCache()
|
||||
{
|
||||
// update network and hdd list
|
||||
addKeyToCache(QString("hdd"));
|
||||
addKeyToCache(QString("net"));
|
||||
}
|
||||
|
||||
|
||||
QStringList AWKeyOperations::dictKeys() 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")));
|
||||
}
|
||||
// time
|
||||
allKeys.append(QString("time"));
|
||||
allKeys.append(QString("isotime"));
|
||||
allKeys.append(QString("shorttime"));
|
||||
allKeys.append(QString("longtime"));
|
||||
allKeys.append(QString("ctime"));
|
||||
// uptime
|
||||
allKeys.append(QString("uptime"));
|
||||
allKeys.append(QString("cuptime"));
|
||||
// cpuclock & cpu
|
||||
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--)
|
||||
allKeys.append(QString("temp%1").arg(i));
|
||||
// gputemp
|
||||
allKeys.append(QString("gputemp"));
|
||||
// gpu
|
||||
allKeys.append(QString("gpu"));
|
||||
// memory
|
||||
allKeys.append(QString("memmb"));
|
||||
allKeys.append(QString("memgb"));
|
||||
allKeys.append(QString("memfreemb"));
|
||||
allKeys.append(QString("memfreegb"));
|
||||
allKeys.append(QString("memtotmb"));
|
||||
allKeys.append(QString("memtotgb"));
|
||||
allKeys.append(QString("memusedmb"));
|
||||
allKeys.append(QString("memusedgb"));
|
||||
allKeys.append(QString("mem"));
|
||||
// swap
|
||||
allKeys.append(QString("swapmb"));
|
||||
allKeys.append(QString("swapgb"));
|
||||
allKeys.append(QString("swapfreemb"));
|
||||
allKeys.append(QString("swapfreegb"));
|
||||
allKeys.append(QString("swaptotmb"));
|
||||
allKeys.append(QString("swaptotgb"));
|
||||
allKeys.append(QString("swap"));
|
||||
// hdd
|
||||
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));
|
||||
allKeys.append(QString("hddfreegb%1").arg(i));
|
||||
allKeys.append(QString("hddtotmb%1").arg(i));
|
||||
allKeys.append(QString("hddtotgb%1").arg(i));
|
||||
allKeys.append(QString("hdd%1").arg(i));
|
||||
}
|
||||
// hdd speed
|
||||
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--)
|
||||
allKeys.append(QString("hddtemp%1").arg(i));
|
||||
// network
|
||||
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));
|
||||
allKeys.append(QString("down%1").arg(i));
|
||||
allKeys.append(QString("upkb%1").arg(i));
|
||||
allKeys.append(QString("up%1").arg(i));
|
||||
}
|
||||
allKeys.append(QString("downunits"));
|
||||
allKeys.append(QString("upunits"));
|
||||
allKeys.append(QString("downkb"));
|
||||
allKeys.append(QString("down"));
|
||||
allKeys.append(QString("upkb"));
|
||||
allKeys.append(QString("up"));
|
||||
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--)
|
||||
allKeys.append(QString("bat%1").arg(i));
|
||||
allKeys.append(QString("bat"));
|
||||
// player
|
||||
allKeys.append(QString("album"));
|
||||
allKeys.append(QString("artist"));
|
||||
allKeys.append(QString("duration"));
|
||||
allKeys.append(QString("progress"));
|
||||
allKeys.append(QString("title"));
|
||||
allKeys.append(QString("dalbum"));
|
||||
allKeys.append(QString("dartist"));
|
||||
allKeys.append(QString("dtitle"));
|
||||
allKeys.append(QString("salbum"));
|
||||
allKeys.append(QString("sartist"));
|
||||
allKeys.append(QString("stitle"));
|
||||
// ps
|
||||
allKeys.append(QString("pscount"));
|
||||
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")));
|
||||
// quotes
|
||||
for (int i = extQuotes->activeItems().count() - 1; i >= 0; i--) {
|
||||
allKeys.append(extQuotes->activeItems().at(i)->tag(QString("ask")));
|
||||
allKeys.append(extQuotes->activeItems().at(i)->tag(QString("askchg")));
|
||||
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("price")));
|
||||
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--)
|
||||
allKeys.append(extScripts->activeItems().at(i)->tag(QString("custom")));
|
||||
// desktop
|
||||
allKeys.append(QString("desktop"));
|
||||
allKeys.append(QString("ndesktop"));
|
||||
allKeys.append(QString("tdesktops"));
|
||||
// load average
|
||||
allKeys.append(QString("la15"));
|
||||
allKeys.append(QString("la5"));
|
||||
allKeys.append(QString("la1"));
|
||||
// bars
|
||||
QStringList graphicalItemsKeys;
|
||||
for (auto item : graphicalItems->items())
|
||||
graphicalItemsKeys.append(item->tag());
|
||||
graphicalItemsKeys.sort();
|
||||
for (int i = graphicalItemsKeys.count() - 1; i >= 0; i--)
|
||||
allKeys.append(graphicalItemsKeys.at(i));
|
||||
|
||||
return allKeys;
|
||||
}
|
||||
|
||||
|
||||
// this method is required to provide GraphicalItem functions (e.g. paint()) to
|
||||
// parent classes
|
||||
GraphicalItem *AWKeyOperations::giByKey(const QString key) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Looking for item" << key;
|
||||
|
||||
return graphicalItems->itemByTag(key);
|
||||
}
|
||||
|
||||
|
||||
QString AWKeyOperations::infoByKey(QString key) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Requested key" << key;
|
||||
|
||||
key.remove(QRegExp(QString("^bar[0-9]{1,}")));
|
||||
if (key.startsWith(QString("custom")))
|
||||
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()]);
|
||||
else if (key.startsWith(QString("hddtemp")))
|
||||
return QString("%1").arg(
|
||||
m_devices[QString("hdd")][key.remove(QString("hddtemp")).toInt()]);
|
||||
else if (key.contains(QRegExp(QString("^(down|up)[0-9]"))))
|
||||
return QString("%1").arg(m_devices[QString(
|
||||
"net")][key.remove(QRegExp(QString("^(down|up)"))).toInt()]);
|
||||
else if (key.startsWith(QString("pkgcount")))
|
||||
return extUpgrade->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();
|
||||
else if (key.startsWith(QString("temp")))
|
||||
return QString("%1").arg(
|
||||
m_devices[QString("temp")][key.remove(QString("temp")).toInt()]);
|
||||
|
||||
return QString("(none)");
|
||||
}
|
||||
|
||||
|
||||
QString AWKeyOperations::pattern() const
|
||||
{
|
||||
return m_pattern;
|
||||
}
|
||||
|
||||
|
||||
void AWKeyOperations::setPattern(const QString currentPattern)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Set pattern" << currentPattern;
|
||||
|
||||
m_pattern = currentPattern;
|
||||
}
|
||||
|
||||
|
||||
void AWKeyOperations::editItem(const QString type)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Item type" << type;
|
||||
|
||||
if (type == QString("graphicalitem")) {
|
||||
QStringList keys = dictKeys().filter(QRegExp(
|
||||
QString("^(cpu(?!cl).*|gpu$|mem$|swap$|hdd[0-9].*|bat.*)")));
|
||||
keys.sort();
|
||||
graphicalItems->setConfigArgs(keys);
|
||||
return graphicalItems->editItems();
|
||||
} else if (type == QString("extquotes")) {
|
||||
return extQuotes->editItems();
|
||||
} else if (type == QString("extscript")) {
|
||||
return extScripts->editItems();
|
||||
} else if (type == QString("extupgrade")) {
|
||||
return extUpgrade->editItems();
|
||||
} else if (type == QString("extweather")) {
|
||||
return extWeather->editItems();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AWKeyOperations::addDevice(const QString &source)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Source" << source;
|
||||
|
||||
QRegExp diskRegexp
|
||||
= QRegExp(QString("disk/(?:md|sd|hd)[a-z|0-9]_.*/Rate/(?:rblk)"));
|
||||
QRegExp mountRegexp = QRegExp(QString("partitions/.*/filllevel"));
|
||||
|
||||
if (source.contains(diskRegexp)) {
|
||||
QString device = source;
|
||||
device.remove(QString("/Rate/rblk"));
|
||||
addKeyToCache(QString("disk"), device);
|
||||
} else if (source.contains(mountRegexp)) {
|
||||
QString device = source;
|
||||
device.remove(QString("partitions")).remove(QString("/filllevel"));
|
||||
addKeyToCache(QString("mount"), device);
|
||||
} else if (source.startsWith(QString("lmsensors"))) {
|
||||
addKeyToCache(QString("temp"), source);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AWKeyOperations::addKeyToCache(const QString type, const QString key)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Key" << key << "with type" << type;
|
||||
|
||||
if (AWKeyCache::addKeyToCache(type, key)) {
|
||||
m_devices = AWKeyCache::loadKeysFromCache();
|
||||
reinitKeys();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AWKeyOperations::reinitKeys()
|
||||
{
|
||||
// renew extensions
|
||||
// delete them if any
|
||||
delete graphicalItems;
|
||||
graphicalItems = nullptr;
|
||||
delete extQuotes;
|
||||
extQuotes = nullptr;
|
||||
delete extScripts;
|
||||
extScripts = nullptr;
|
||||
delete extUpgrade;
|
||||
extUpgrade = nullptr;
|
||||
delete extWeather;
|
||||
extWeather = nullptr;
|
||||
// create
|
||||
graphicalItems
|
||||
= new ExtItemAggregator<GraphicalItem>(nullptr, QString("desktops"));
|
||||
extQuotes = new ExtItemAggregator<ExtQuotes>(nullptr, QString("quotes"));
|
||||
extScripts = new ExtItemAggregator<ExtScript>(nullptr, QString("scripts"));
|
||||
extUpgrade = new ExtItemAggregator<ExtUpgrade>(nullptr, QString("upgrade"));
|
||||
extWeather = new ExtItemAggregator<ExtWeather>(nullptr, QString("weather"));
|
||||
|
||||
// init
|
||||
QStringList allKeys = dictKeys();
|
||||
|
||||
// apply aw_* functions
|
||||
m_pattern = AWPatternFunctions::insertAllKeys(m_pattern, allKeys);
|
||||
m_pattern = AWPatternFunctions::insertKeyCount(m_pattern, allKeys);
|
||||
m_pattern = AWPatternFunctions::insertKeyNames(m_pattern, allKeys);
|
||||
m_pattern = AWPatternFunctions::insertKeys(m_pattern, allKeys);
|
||||
// wrap templates
|
||||
m_pattern = AWPatternFunctions::expandTemplates(m_pattern);
|
||||
|
||||
emit(updateKeys(allKeys));
|
||||
}
|
83
sources/awesome-widget/plugin/awkeyoperations.h
Normal file
@ -0,0 +1,83 @@
|
||||
/***************************************************************************
|
||||
* 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 AWKEYOPERATIONS_H
|
||||
#define AWKEYOPERATIONS_H
|
||||
|
||||
#include <Plasma/DataEngine>
|
||||
|
||||
#include <QMutex>
|
||||
#include <QObject>
|
||||
|
||||
#include "extitemaggregator.h"
|
||||
|
||||
|
||||
class AWDataAggregator;
|
||||
class AWDataEngineAggregator;
|
||||
class AWKeysAggregator;
|
||||
class ExtQuotes;
|
||||
class ExtScript;
|
||||
class ExtUpgrade;
|
||||
class ExtWeather;
|
||||
class GraphicalItem;
|
||||
class QThreadPool;
|
||||
|
||||
class AWKeyOperations : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString pattern READ pattern WRITE setPattern)
|
||||
|
||||
public:
|
||||
explicit AWKeyOperations(QObject *parent = nullptr);
|
||||
virtual ~AWKeyOperations();
|
||||
QStringList devices(const QString type) const;
|
||||
QHash<QString, QStringList> devices() const;
|
||||
void updateCache();
|
||||
// keys
|
||||
QStringList dictKeys() const;
|
||||
GraphicalItem *giByKey(const QString key) const;
|
||||
// values
|
||||
QString infoByKey(QString key) const;
|
||||
QString pattern() const;
|
||||
void setPattern(const QString currentPattern);
|
||||
// configuration
|
||||
void editItem(const QString type);
|
||||
|
||||
signals:
|
||||
void updateKeys(const QStringList currentKeys);
|
||||
|
||||
public slots:
|
||||
void addDevice(const QString &source);
|
||||
|
||||
private:
|
||||
// methods
|
||||
void addKeyToCache(const QString type, const QString key = QString(""));
|
||||
void reinitKeys();
|
||||
// objects
|
||||
ExtItemAggregator<GraphicalItem> *graphicalItems = nullptr;
|
||||
ExtItemAggregator<ExtQuotes> *extQuotes = nullptr;
|
||||
ExtItemAggregator<ExtScript> *extScripts = nullptr;
|
||||
ExtItemAggregator<ExtUpgrade> *extUpgrade = nullptr;
|
||||
ExtItemAggregator<ExtWeather> *extWeather = nullptr;
|
||||
// variables
|
||||
QHash<QString, QStringList> m_devices;
|
||||
QString m_pattern;
|
||||
};
|
||||
|
||||
|
||||
#endif /* AWKEYOPERATIONS_H */
|
@ -18,23 +18,16 @@
|
||||
#include "awkeys.h"
|
||||
|
||||
#include <QtConcurrent/QtConcurrent>
|
||||
#include <QDir>
|
||||
#include <QInputDialog>
|
||||
#include <QJSEngine>
|
||||
#include <QNetworkInterface>
|
||||
#include <QRegExp>
|
||||
#include <QSettings>
|
||||
#include <QStandardPaths>
|
||||
#include <QThread>
|
||||
|
||||
#include "awdataaggregator.h"
|
||||
#include "awdataengineaggregator.h"
|
||||
#include "awdebug.h"
|
||||
#include "awkeyoperations.h"
|
||||
#include "awkeysaggregator.h"
|
||||
#include "extquotes.h"
|
||||
#include "extscript.h"
|
||||
#include "extupgrade.h"
|
||||
#include "extweather.h"
|
||||
#include "awpatternfunctions.h"
|
||||
#include "graphicalitem.h"
|
||||
#include "version.h"
|
||||
|
||||
@ -44,16 +37,18 @@ AWKeys::AWKeys(QObject *parent)
|
||||
{
|
||||
qSetMessagePattern(LOG_FORMAT);
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
foreach (const QString metadata, getBuildData())
|
||||
for (auto metadata : getBuildData())
|
||||
qCDebug(LOG_AW) << metadata;
|
||||
|
||||
#ifdef BUILD_FUTURE
|
||||
// thread pool
|
||||
m_threadPool = new QThreadPool(this);
|
||||
#endif /* BUILD_FUTURE */
|
||||
|
||||
aggregator = new AWKeysAggregator(this);
|
||||
dataAggregator = new AWDataAggregator(this);
|
||||
keyOperator = new AWKeyOperations(this);
|
||||
// update key data if required
|
||||
connect(keyOperator, SIGNAL(updateKeys(QStringList)), this,
|
||||
SLOT(reinitKeys(QStringList)));
|
||||
// transfer signal from AWDataAggregator object to QML ui
|
||||
connect(dataAggregator, SIGNAL(toolTipPainted(const QString)), this,
|
||||
SIGNAL(needToolTipToBeUpdated(const QString)));
|
||||
@ -65,18 +60,12 @@ AWKeys::~AWKeys()
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
|
||||
// extensions
|
||||
delete graphicalItems;
|
||||
delete extQuotes;
|
||||
delete extScripts;
|
||||
delete extUpgrade;
|
||||
delete extWeather;
|
||||
|
||||
// core
|
||||
delete dataEngineAggregator;
|
||||
delete m_threadPool;
|
||||
delete aggregator;
|
||||
delete dataAggregator;
|
||||
delete keyOperator;
|
||||
}
|
||||
|
||||
|
||||
@ -91,23 +80,23 @@ void AWKeys::initDataAggregator(const QVariantMap tooltipParams)
|
||||
void AWKeys::initKeys(const QString currentPattern, const int interval,
|
||||
const int limit)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Pattern" << currentPattern;
|
||||
qCDebug(LOG_AW) << "Interval" << interval;
|
||||
qCDebug(LOG_AW) << "Queue limit" << limit;
|
||||
qCDebug(LOG_AW) << "Pattern" << currentPattern << "with interval"
|
||||
<< interval << "and queue limit" << limit;
|
||||
|
||||
// init
|
||||
m_pattern = currentPattern;
|
||||
keyOperator->setPattern(currentPattern);
|
||||
if (dataEngineAggregator == nullptr) {
|
||||
dataEngineAggregator = new AWDataEngineAggregator(this, interval);
|
||||
connect(this, SIGNAL(dropSourceFromDataengine(QString)),
|
||||
dataEngineAggregator, SLOT(dropSource(QString)));
|
||||
// transfer signal from dataengine to update source list
|
||||
connect(dataEngineAggregator, SIGNAL(deviceAdded(const QString &)),
|
||||
keyOperator, SLOT(addDevice(const QString &)));
|
||||
} else
|
||||
dataEngineAggregator->setInterval(interval);
|
||||
#ifdef BUILD_FUTURE
|
||||
m_threadPool->setMaxThreadCount(limit == 0 ? QThread::idealThreadCount()
|
||||
: limit);
|
||||
#endif /* BUILD_FUTURE */
|
||||
updateCache();
|
||||
keyOperator->updateCache();
|
||||
|
||||
return dataEngineAggregator->reconnectSources();
|
||||
}
|
||||
@ -115,8 +104,7 @@ void AWKeys::initKeys(const QString currentPattern, const int interval,
|
||||
|
||||
void AWKeys::setAggregatorProperty(const QString key, const QVariant value)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Key" << key;
|
||||
qCDebug(LOG_AW) << "Value" << value;
|
||||
qCDebug(LOG_AW) << "Key" << key << "with value" << value;
|
||||
|
||||
aggregator->setProperty(key.toUtf8().constData(), value);
|
||||
}
|
||||
@ -132,172 +120,16 @@ void AWKeys::setWrapNewLines(const bool wrap)
|
||||
|
||||
void AWKeys::updateCache()
|
||||
{
|
||||
// update network and hdd list
|
||||
addKeyToCache(QString("hdd"));
|
||||
addKeyToCache(QString("net"));
|
||||
return keyOperator->updateCache();
|
||||
}
|
||||
|
||||
|
||||
QStringList AWKeys::dictKeys(const bool sorted, const QString regexp) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Should be sorted" << sorted;
|
||||
qCDebug(LOG_AW) << "Filter" << regexp;
|
||||
|
||||
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")));
|
||||
}
|
||||
// time
|
||||
allKeys.append(QString("time"));
|
||||
allKeys.append(QString("isotime"));
|
||||
allKeys.append(QString("shorttime"));
|
||||
allKeys.append(QString("longtime"));
|
||||
allKeys.append(QString("ctime"));
|
||||
// uptime
|
||||
allKeys.append(QString("uptime"));
|
||||
allKeys.append(QString("cuptime"));
|
||||
// cpuclock & cpu
|
||||
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--)
|
||||
allKeys.append(QString("temp%1").arg(i));
|
||||
// gputemp
|
||||
allKeys.append(QString("gputemp"));
|
||||
// gpu
|
||||
allKeys.append(QString("gpu"));
|
||||
// memory
|
||||
allKeys.append(QString("memmb"));
|
||||
allKeys.append(QString("memgb"));
|
||||
allKeys.append(QString("memfreemb"));
|
||||
allKeys.append(QString("memfreegb"));
|
||||
allKeys.append(QString("memtotmb"));
|
||||
allKeys.append(QString("memtotgb"));
|
||||
allKeys.append(QString("memusedmb"));
|
||||
allKeys.append(QString("memusedgb"));
|
||||
allKeys.append(QString("mem"));
|
||||
// swap
|
||||
allKeys.append(QString("swapmb"));
|
||||
allKeys.append(QString("swapgb"));
|
||||
allKeys.append(QString("swapfreemb"));
|
||||
allKeys.append(QString("swapfreegb"));
|
||||
allKeys.append(QString("swaptotmb"));
|
||||
allKeys.append(QString("swaptotgb"));
|
||||
allKeys.append(QString("swap"));
|
||||
// hdd
|
||||
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));
|
||||
allKeys.append(QString("hddfreegb%1").arg(i));
|
||||
allKeys.append(QString("hddtotmb%1").arg(i));
|
||||
allKeys.append(QString("hddtotgb%1").arg(i));
|
||||
allKeys.append(QString("hdd%1").arg(i));
|
||||
}
|
||||
// hdd speed
|
||||
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--)
|
||||
allKeys.append(QString("hddtemp%1").arg(i));
|
||||
// network
|
||||
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));
|
||||
allKeys.append(QString("down%1").arg(i));
|
||||
allKeys.append(QString("upkb%1").arg(i));
|
||||
allKeys.append(QString("up%1").arg(i));
|
||||
}
|
||||
allKeys.append(QString("downunits"));
|
||||
allKeys.append(QString("upunits"));
|
||||
allKeys.append(QString("downkb"));
|
||||
allKeys.append(QString("down"));
|
||||
allKeys.append(QString("upkb"));
|
||||
allKeys.append(QString("up"));
|
||||
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--)
|
||||
allKeys.append(QString("bat%1").arg(i));
|
||||
allKeys.append(QString("bat"));
|
||||
// player
|
||||
allKeys.append(QString("album"));
|
||||
allKeys.append(QString("artist"));
|
||||
allKeys.append(QString("duration"));
|
||||
allKeys.append(QString("progress"));
|
||||
allKeys.append(QString("title"));
|
||||
allKeys.append(QString("dalbum"));
|
||||
allKeys.append(QString("dartist"));
|
||||
allKeys.append(QString("dtitle"));
|
||||
allKeys.append(QString("salbum"));
|
||||
allKeys.append(QString("sartist"));
|
||||
allKeys.append(QString("stitle"));
|
||||
// ps
|
||||
allKeys.append(QString("pscount"));
|
||||
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")));
|
||||
// quotes
|
||||
for (int i = extQuotes->activeItems().count() - 1; i >= 0; i--) {
|
||||
allKeys.append(extQuotes->activeItems().at(i)->tag(QString("ask")));
|
||||
allKeys.append(extQuotes->activeItems().at(i)->tag(QString("askchg")));
|
||||
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("price")));
|
||||
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--)
|
||||
allKeys.append(extScripts->activeItems().at(i)->tag(QString("custom")));
|
||||
// desktop
|
||||
allKeys.append(QString("desktop"));
|
||||
allKeys.append(QString("ndesktop"));
|
||||
allKeys.append(QString("tdesktops"));
|
||||
// load average
|
||||
allKeys.append(QString("la15"));
|
||||
allKeys.append(QString("la5"));
|
||||
allKeys.append(QString("la1"));
|
||||
// bars
|
||||
QStringList graphicalItemsKeys;
|
||||
foreach (GraphicalItem *item, graphicalItems->items())
|
||||
graphicalItemsKeys.append(item->tag());
|
||||
graphicalItemsKeys.sort();
|
||||
for (int i = graphicalItemsKeys.count() - 1; i >= 0; i--)
|
||||
allKeys.append(graphicalItemsKeys.at(i));
|
||||
qCDebug(LOG_AW) << "Should be sorted" << sorted << "and filter applied"
|
||||
<< regexp;
|
||||
|
||||
QStringList allKeys = keyOperator->dictKeys();
|
||||
// sort if required
|
||||
if (sorted)
|
||||
allKeys.sort();
|
||||
@ -308,7 +140,7 @@ QStringList AWKeys::dictKeys(const bool sorted, const QString regexp) const
|
||||
|
||||
QStringList AWKeys::getHddDevices() const
|
||||
{
|
||||
QStringList devices = m_devices[QString("hdd")];
|
||||
QStringList devices = keyOperator->devices(QString("hdd"));
|
||||
// required by selector in the UI
|
||||
devices.insert(0, QString("disable"));
|
||||
devices.insert(0, QString("auto"));
|
||||
@ -319,60 +151,16 @@ QStringList AWKeys::getHddDevices() const
|
||||
|
||||
QString AWKeys::infoByKey(QString key) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Requested key" << key;
|
||||
qCDebug(LOG_AW) << "Requested info for key" << key;
|
||||
|
||||
key.remove(QRegExp(QString("^bar[0-9]{1,}")));
|
||||
if (key.startsWith(QString("custom")))
|
||||
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()]);
|
||||
else if (key.startsWith(QString("hddtemp")))
|
||||
return QString("%1").arg(
|
||||
m_devices[QString("hdd")][key.remove(QString("hddtemp")).toInt()]);
|
||||
else if (key.contains(QRegExp(QString("^(down|up)[0-9]"))))
|
||||
return QString("%1").arg(m_devices[QString(
|
||||
"net")][key.remove(QRegExp(QString("^(down|up)"))).toInt()]);
|
||||
else if (key.startsWith(QString("pkgcount")))
|
||||
return extUpgrade->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();
|
||||
else if (key.startsWith(QString("temp")))
|
||||
return QString("%1").arg(
|
||||
m_devices[QString("temp")][key.remove(QString("temp")).toInt()]);
|
||||
|
||||
return QString("(none)");
|
||||
return keyOperator->infoByKey(key);
|
||||
}
|
||||
|
||||
|
||||
// HACK this method requires to define tag value from bar from UI interface
|
||||
QString AWKeys::valueByKey(QString key) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Requested key" << key;
|
||||
qCDebug(LOG_AW) << "Requested value for key" << key;
|
||||
|
||||
return values.value(key.remove(QRegExp(QString("^bar[0-9]{1,}"))),
|
||||
QString(""));
|
||||
@ -383,41 +171,7 @@ 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.*)")));
|
||||
return graphicalItems->editItems();
|
||||
} else if (type == QString("extquotes")) {
|
||||
return extQuotes->editItems();
|
||||
} else if (type == QString("extscript")) {
|
||||
return extScripts->editItems();
|
||||
} else if (type == QString("extupgrade")) {
|
||||
return extUpgrade->editItems();
|
||||
} else if (type == QString("extweather")) {
|
||||
return extWeather->editItems();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AWKeys::addDevice(const QString source)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Source" << source;
|
||||
|
||||
QRegExp diskRegexp
|
||||
= QRegExp(QString("disk/(?:md|sd|hd)[a-z|0-9]_.*/Rate/(?:rblk)"));
|
||||
QRegExp mountRegexp = QRegExp(QString("partitions/.*/filllevel"));
|
||||
|
||||
if (source.contains(diskRegexp)) {
|
||||
QString device = source;
|
||||
device.remove(QString("/Rate/rblk"));
|
||||
addKeyToCache(QString("disk"), device);
|
||||
} else if (source.contains(mountRegexp)) {
|
||||
QString device = source;
|
||||
device.remove(QString("partitions")).remove(QString("/filllevel"));
|
||||
addKeyToCache(QString("mount"), device);
|
||||
} else if (source.startsWith(QString("lmsensors"))) {
|
||||
addKeyToCache(QString("temp"), source);
|
||||
}
|
||||
return keyOperator->editItem(type);
|
||||
}
|
||||
|
||||
|
||||
@ -430,210 +184,48 @@ void AWKeys::dataUpdated(const QString &sourceName,
|
||||
return emit(needToBeUpdated());
|
||||
}
|
||||
|
||||
#ifdef BUILD_FUTURE
|
||||
// run concurrent data update
|
||||
QtConcurrent::run(m_threadPool, this, &AWKeys::setDataBySource, sourceName,
|
||||
data);
|
||||
#else /* BUILD_FUTURE */
|
||||
return setDataBySource(sourceName, data);
|
||||
#endif /* BUILD_FUTURE */
|
||||
}
|
||||
|
||||
|
||||
void AWKeys::loadKeysFromCache()
|
||||
void AWKeys::reinitKeys(const QStringList currentKeys)
|
||||
{
|
||||
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()) {
|
||||
cache.beginGroup(group);
|
||||
m_devices.remove(group);
|
||||
foreach (QString key, cache.allKeys())
|
||||
m_devices[group].append(cache.value(key).toString());
|
||||
cache.endGroup();
|
||||
}
|
||||
|
||||
return reinitKeys();
|
||||
}
|
||||
|
||||
|
||||
void AWKeys::reinitKeys()
|
||||
{
|
||||
// renew extensions
|
||||
// delete them if any
|
||||
delete graphicalItems;
|
||||
graphicalItems = nullptr;
|
||||
delete extQuotes;
|
||||
extQuotes = nullptr;
|
||||
delete extScripts;
|
||||
extScripts = nullptr;
|
||||
delete extUpgrade;
|
||||
extUpgrade = nullptr;
|
||||
delete extWeather;
|
||||
extWeather = nullptr;
|
||||
// create
|
||||
graphicalItems
|
||||
= new ExtItemAggregator<GraphicalItem>(nullptr, QString("desktops"));
|
||||
extQuotes = new ExtItemAggregator<ExtQuotes>(nullptr, QString("quotes"));
|
||||
extScripts = new ExtItemAggregator<ExtScript>(nullptr, QString("scripts"));
|
||||
extUpgrade = new ExtItemAggregator<ExtUpgrade>(nullptr, QString("upgrade"));
|
||||
extWeather = new ExtItemAggregator<ExtWeather>(nullptr, QString("weather"));
|
||||
|
||||
// init
|
||||
QStringList allKeys = dictKeys();
|
||||
|
||||
#ifdef BUILD_TESTING
|
||||
// not documented feature - place all available tags
|
||||
m_pattern = m_pattern.replace(QString("$ALL"), [allKeys]() {
|
||||
QStringList strings;
|
||||
foreach (QString tag, allKeys)
|
||||
strings.append(QString("%1: $%1").arg(tag));
|
||||
return strings.join(QString(" | "));
|
||||
}());
|
||||
#endif /* BUILD_TESTING */
|
||||
qCDebug(LOG_AW) << "Update found keys by using list" << currentKeys;
|
||||
|
||||
// append lists
|
||||
// bars
|
||||
m_foundBars = [allKeys](QString pattern) {
|
||||
QStringList selectedKeys;
|
||||
foreach (QString key, allKeys)
|
||||
if ((key.startsWith(QString("bar")))
|
||||
&& (pattern.contains(QString("$%1").arg(key)))) {
|
||||
qCInfo(LOG_AW) << "Found bar" << key;
|
||||
selectedKeys.append(key);
|
||||
}
|
||||
if (selectedKeys.isEmpty())
|
||||
qCWarning(LOG_AW) << "No bars found";
|
||||
return selectedKeys;
|
||||
}(m_pattern);
|
||||
|
||||
// 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)))) {
|
||||
qCInfo(LOG_AW) << "Found key" << key;
|
||||
selectedKeys.append(key);
|
||||
}
|
||||
if (selectedKeys.isEmpty())
|
||||
qCWarning(LOG_AW) << "No keys found";
|
||||
return selectedKeys;
|
||||
}(m_pattern);
|
||||
|
||||
// lambdas
|
||||
m_foundLambdas = [](QString pattern) {
|
||||
QStringList selectedKeys;
|
||||
// substring inside ${{ }} (with brackets) which should not contain ${{
|
||||
QRegularExpression lambdaRegexp(
|
||||
QString("\\$\\{\\{((?!\\$\\{\\{).)*?\\}\\}"));
|
||||
lambdaRegexp.setPatternOptions(
|
||||
QRegularExpression::DotMatchesEverythingOption);
|
||||
|
||||
QRegularExpressionMatchIterator it = lambdaRegexp.globalMatch(pattern);
|
||||
while (it.hasNext()) {
|
||||
QRegularExpressionMatch match = it.next();
|
||||
QString lambda = match.captured();
|
||||
// drop brakets
|
||||
lambda.remove(QRegExp(QString("^\\$\\{\\{")));
|
||||
lambda.remove(QRegExp(QString("\\}\\}$")));
|
||||
// append
|
||||
qCInfo(LOG_AW) << "Found lambda" << lambda;
|
||||
selectedKeys.append(lambda);
|
||||
}
|
||||
if (selectedKeys.isEmpty())
|
||||
qCWarning(LOG_AW) << "No lambdas found";
|
||||
return selectedKeys;
|
||||
}(m_pattern);
|
||||
m_foundBars
|
||||
= AWPatternFunctions::findBars(keyOperator->pattern(), currentKeys);
|
||||
m_foundKeys
|
||||
= AWPatternFunctions::findKeys(keyOperator->pattern(), currentKeys);
|
||||
m_foundLambdas = AWPatternFunctions::findLambdas(keyOperator->pattern());
|
||||
|
||||
// set key data to aggregator
|
||||
aggregator->setDevices(m_devices);
|
||||
aggregator->setDevices(keyOperator->devices());
|
||||
}
|
||||
|
||||
|
||||
void AWKeys::updateTextData()
|
||||
{
|
||||
#ifdef BUILD_FUTURE
|
||||
QFuture<QString> text = QtConcurrent::run(m_threadPool, [this]() {
|
||||
calculateValues();
|
||||
return parsePattern(m_pattern);
|
||||
return parsePattern(keyOperator->pattern());
|
||||
});
|
||||
#else /* BUILD_FUTURE */
|
||||
calculateValues();
|
||||
QString text = parsePattern(m_pattern);
|
||||
#endif /* BUILD_FUTURE */
|
||||
|
||||
emit(needTextToBeUpdated(text));
|
||||
emit(dataAggregator->updateData(values));
|
||||
}
|
||||
|
||||
|
||||
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));
|
||||
qCInfo(LOG_AW) << "Cache file" << fileName;
|
||||
QSettings cache(fileName, QSettings::IniFormat);
|
||||
|
||||
cache.beginGroup(type);
|
||||
QStringList cachedValues;
|
||||
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) {
|
||||
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);
|
||||
}
|
||||
} else if (type == QString("net")) {
|
||||
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);
|
||||
}
|
||||
} 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.endGroup();
|
||||
|
||||
cache.sync();
|
||||
return loadKeysFromCache();
|
||||
}
|
||||
|
||||
|
||||
// HACK this method is required since I could not define some values by using
|
||||
// specified pattern. Usually they are values which depend on several others
|
||||
void AWKeys::calculateValues()
|
||||
{
|
||||
// hddtot*
|
||||
foreach (QString device, m_devices[QString("mount")]) {
|
||||
int index = m_devices[QString("mount")].indexOf(device);
|
||||
QStringList mountDevices = keyOperator->devices(QString("mount"));
|
||||
for (auto device : mountDevices) {
|
||||
int index = mountDevices.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(),
|
||||
@ -660,7 +252,8 @@ void AWKeys::calculateValues()
|
||||
5, 'f', 1);
|
||||
|
||||
// up, down, upkb, downkb, upunits, downunits
|
||||
int netIndex = m_devices[QString("net")].indexOf(values[QString("netdev")]);
|
||||
int netIndex = keyOperator->devices(QString("net"))
|
||||
.indexOf(values[QString("netdev")]);
|
||||
values[QString("down")] = values[QString("down%1").arg(netIndex)];
|
||||
values[QString("downkb")] = values[QString("downkb%1").arg(netIndex)];
|
||||
values[QString("downunits")] = values[QString("downunits%1").arg(netIndex)];
|
||||
@ -684,12 +277,12 @@ void AWKeys::calculateValues()
|
||||
5, 'f', 1);
|
||||
|
||||
// lambdas
|
||||
foreach (QString key, m_foundLambdas)
|
||||
for (auto key : m_foundLambdas)
|
||||
values[key] = [this](QString key) {
|
||||
QJSEngine engine;
|
||||
// apply $this values
|
||||
key.replace(QString("$this"), values[key]);
|
||||
foreach (QString lambdaKey, m_foundKeys)
|
||||
for (auto lambdaKey : m_foundKeys)
|
||||
key.replace(QString("$%1").arg(lambdaKey), values[lambdaKey]);
|
||||
qCInfo(LOG_AW) << "Expression" << key;
|
||||
QJSValue result = engine.evaluate(key);
|
||||
@ -708,14 +301,14 @@ void AWKeys::calculateValues()
|
||||
QString AWKeys::parsePattern(QString pattern) const
|
||||
{
|
||||
// screen sign
|
||||
pattern.replace(QString("$$"), QString("$\\$\\"));
|
||||
pattern.replace(QString("$$"), QString(0x1d));
|
||||
|
||||
// lambdas
|
||||
foreach (QString key, m_foundLambdas)
|
||||
for (auto key : m_foundLambdas)
|
||||
pattern.replace(QString("${{%1}}").arg(key), values[key]);
|
||||
|
||||
// main keys
|
||||
foreach (QString key, m_foundKeys)
|
||||
for (auto key : m_foundKeys)
|
||||
pattern.replace(QString("$%1").arg(key),
|
||||
[](QString key, QString value) {
|
||||
if ((!key.startsWith(QString("custom")))
|
||||
@ -725,8 +318,8 @@ QString AWKeys::parsePattern(QString pattern) const
|
||||
}(key, values[key]));
|
||||
|
||||
// bars
|
||||
foreach (QString bar, m_foundBars) {
|
||||
GraphicalItem *item = graphicalItems->itemByTag(bar);
|
||||
for (auto bar : m_foundBars) {
|
||||
GraphicalItem *item = keyOperator->giByKey(bar);
|
||||
QString key = bar;
|
||||
key.remove(QRegExp(QString("^bar[0-9]{1,}")));
|
||||
if (item->type() == GraphicalItem::Graph)
|
||||
@ -739,7 +332,7 @@ QString AWKeys::parsePattern(QString pattern) const
|
||||
}
|
||||
|
||||
// prepare strings
|
||||
pattern.replace(QString("$\\$\\"), QString("$$"));
|
||||
pattern.replace(QString(0x1d), QString("$"));
|
||||
if (m_wrapNewLines)
|
||||
pattern.replace(QString("\n"), QString("<br>"));
|
||||
|
||||
@ -749,8 +342,7 @@ QString AWKeys::parsePattern(QString pattern) const
|
||||
|
||||
void AWKeys::setDataBySource(const QString &sourceName, const QVariantMap &data)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Source" << sourceName;
|
||||
qCDebug(LOG_AW) << "Data" << data;
|
||||
qCDebug(LOG_AW) << "Source" << sourceName << "with data" << data;
|
||||
|
||||
// first list init
|
||||
QStringList tags = aggregator->keysFromSource(sourceName);
|
||||
@ -758,25 +350,18 @@ void AWKeys::setDataBySource(const QString &sourceName, const QVariantMap &data)
|
||||
tags = aggregator->registerSource(sourceName,
|
||||
data[QString("units")].toString());
|
||||
|
||||
// update data or drop source if there are no matches
|
||||
// update data or drop source if there are no matches and exit
|
||||
if (tags.isEmpty()) {
|
||||
qCDebug(LOG_AW) << "Source" << sourceName << "not found";
|
||||
emit(dropSourceFromDataengine(sourceName));
|
||||
} else {
|
||||
#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);
|
||||
});
|
||||
#ifdef BUILD_FUTURE
|
||||
m_mutex.unlock();
|
||||
#endif /* BUILD_FUTURE */
|
||||
qCInfo(LOG_AW) << "Source" << sourceName << "not found";
|
||||
return emit(dropSourceFromDataengine(sourceName));
|
||||
}
|
||||
|
||||
m_mutex.lock();
|
||||
// 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);
|
||||
});
|
||||
m_mutex.unlock();
|
||||
}
|
||||
|
@ -24,17 +24,11 @@
|
||||
#include <QMutex>
|
||||
#include <QObject>
|
||||
|
||||
#include "extitemaggregator.h"
|
||||
|
||||
|
||||
class AWDataAggregator;
|
||||
class AWDataEngineAggregator;
|
||||
class AWKeyOperations;
|
||||
class AWKeysAggregator;
|
||||
class ExtQuotes;
|
||||
class ExtScript;
|
||||
class ExtUpgrade;
|
||||
class ExtWeather;
|
||||
class GraphicalItem;
|
||||
class QThreadPool;
|
||||
|
||||
class AWKeys : public QObject
|
||||
@ -50,6 +44,8 @@ public:
|
||||
Q_INVOKABLE void setAggregatorProperty(const QString key,
|
||||
const QVariant value);
|
||||
Q_INVOKABLE void setWrapNewLines(const bool wrap = false);
|
||||
// additional method to force load keys from Qml UI. Used in some
|
||||
// configuration pages
|
||||
Q_INVOKABLE void updateCache();
|
||||
// keys
|
||||
Q_INVOKABLE QStringList dictKeys(const bool sorted = false,
|
||||
@ -62,7 +58,6 @@ public:
|
||||
Q_INVOKABLE void editItem(const QString type);
|
||||
|
||||
public slots:
|
||||
void addDevice(const QString source);
|
||||
void dataUpdated(const QString &sourceName,
|
||||
const Plasma::DataEngine::Data &data);
|
||||
// dummy method required by DataEngine connections
|
||||
@ -75,13 +70,11 @@ signals:
|
||||
void needToBeUpdated();
|
||||
|
||||
private slots:
|
||||
void loadKeysFromCache();
|
||||
void reinitKeys();
|
||||
void reinitKeys(const QStringList currentKeys);
|
||||
void updateTextData();
|
||||
|
||||
private:
|
||||
// methods
|
||||
void addKeyToCache(const QString type, const QString key = QString(""));
|
||||
void calculateValues();
|
||||
QString parsePattern(QString pattern) const;
|
||||
void setDataBySource(const QString &sourceName, const QVariantMap &data);
|
||||
@ -89,15 +82,9 @@ private:
|
||||
AWDataAggregator *dataAggregator = nullptr;
|
||||
AWDataEngineAggregator *dataEngineAggregator = nullptr;
|
||||
AWKeysAggregator *aggregator = nullptr;
|
||||
ExtItemAggregator<GraphicalItem> *graphicalItems = nullptr;
|
||||
ExtItemAggregator<ExtQuotes> *extQuotes = nullptr;
|
||||
ExtItemAggregator<ExtScript> *extScripts = nullptr;
|
||||
ExtItemAggregator<ExtUpgrade> *extUpgrade = nullptr;
|
||||
ExtItemAggregator<ExtWeather> *extWeather = nullptr;
|
||||
AWKeyOperations *keyOperator = nullptr;
|
||||
// variables
|
||||
QHash<QString, QStringList> m_devices;
|
||||
QStringList m_foundBars, m_foundKeys, m_foundLambdas;
|
||||
QString m_pattern;
|
||||
QHash<QString, QString> values;
|
||||
bool m_wrapNewLines = false;
|
||||
// multithread features
|
||||
|
@ -42,8 +42,7 @@ AWKeysAggregator::~AWKeysAggregator()
|
||||
QString AWKeysAggregator::formater(const QVariant &data,
|
||||
const QString &key) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Data" << data;
|
||||
qCDebug(LOG_AW) << "Key" << key;
|
||||
qCDebug(LOG_AW) << "Data" << data << "for key" << key;
|
||||
|
||||
QString output;
|
||||
QLocale loc = m_translate ? QLocale::system() : QLocale::c();
|
||||
@ -102,7 +101,7 @@ QString AWKeysAggregator::formater(const QVariant &data,
|
||||
case TimeCustom:
|
||||
output = m_customTime;
|
||||
[&output, loc, this](const QDateTime dt) {
|
||||
foreach (QString key, timeKeys)
|
||||
for (auto key : timeKeys)
|
||||
output.replace(QString("$%1").arg(key), loc.toString(dt, key));
|
||||
}(data.toDateTime());
|
||||
break;
|
||||
@ -135,7 +134,7 @@ QString AWKeysAggregator::formater(const QVariant &data,
|
||||
return source;
|
||||
}(m_formater[key] == Uptime ? QString("$ddd$hhh$mmm")
|
||||
: m_customUptime,
|
||||
data.toFloat());
|
||||
static_cast<int>(data.toFloat()));
|
||||
break;
|
||||
case NoFormat:
|
||||
default:
|
||||
@ -155,6 +154,15 @@ QStringList AWKeysAggregator::keysFromSource(const QString &source) const
|
||||
}
|
||||
|
||||
|
||||
QStringList
|
||||
AWKeysAggregator::requiredByKeysFromSource(const QString &source) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Search for source" << source;
|
||||
|
||||
return m_requiredByMap.values(source);
|
||||
}
|
||||
|
||||
|
||||
void AWKeysAggregator::setAcOffline(const QString inactive)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Inactive AC string" << inactive;
|
||||
@ -216,8 +224,7 @@ void AWKeysAggregator::setTranslate(const bool translate)
|
||||
QStringList AWKeysAggregator::registerSource(const QString &source,
|
||||
const QString &units)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Source" << source;
|
||||
qCDebug(LOG_AW) << "Units" << units;
|
||||
qCDebug(LOG_AW) << "Source" << source << "with units" << units;
|
||||
|
||||
// regular expressions
|
||||
QRegExp cpuRegExp = QRegExp(QString("cpu/cpu.*/TotalLoad"));
|
||||
@ -331,6 +338,11 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
|
||||
key = QString("hddfreegb%1").arg(index);
|
||||
m_map.insertMulti(source, key);
|
||||
m_formater[key] = MemGBFormat;
|
||||
// fill required by list
|
||||
m_requiredByMap.insertMulti(source,
|
||||
QString("hddtotmb%1").arg(index));
|
||||
m_requiredByMap.insertMulti(source,
|
||||
QString("hddtotgb%1").arg(index));
|
||||
}
|
||||
} else if (source.contains(mountUsedRegExp)) {
|
||||
// used
|
||||
@ -346,6 +358,11 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
|
||||
key = QString("hddgb%1").arg(index);
|
||||
m_map.insertMulti(source, key);
|
||||
m_formater[key] = MemGBFormat;
|
||||
// fill required by list
|
||||
m_requiredByMap.insertMulti(source,
|
||||
QString("hddtotmb%1").arg(index));
|
||||
m_requiredByMap.insertMulti(source,
|
||||
QString("hddtotgb%1").arg(index));
|
||||
}
|
||||
} else if (source.startsWith(QString("hdd/temperature"))) {
|
||||
// hdd temperature
|
||||
@ -372,6 +389,8 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
|
||||
// gb
|
||||
m_map.insertMulti(source, QString("memgb"));
|
||||
m_formater[QString("memgb")] = MemGBFormat;
|
||||
// fill required by list
|
||||
m_requiredByMap.insertMulti(source, QString("mem"));
|
||||
} else if (source == QString("mem/physical/free")) {
|
||||
// free memory
|
||||
// mb
|
||||
@ -380,6 +399,10 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
|
||||
// gb
|
||||
m_map.insertMulti(source, QString("memfreegb"));
|
||||
m_formater[QString("memfreegb")] = MemGBFormat;
|
||||
// fill required by list
|
||||
m_requiredByMap.insertMulti(source, QString("memtotmb"));
|
||||
m_requiredByMap.insertMulti(source, QString("memtotgb"));
|
||||
m_requiredByMap.insertMulti(source, QString("mem"));
|
||||
} else if (source == QString("mem/physical/used")) {
|
||||
// used memory
|
||||
// mb
|
||||
@ -388,10 +411,21 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
|
||||
// gb
|
||||
m_map.insertMulti(source, QString("memusedgb"));
|
||||
m_formater[QString("memusedgb")] = MemGBFormat;
|
||||
// fill required by list
|
||||
m_requiredByMap.insertMulti(source, QString("memtotmb"));
|
||||
m_requiredByMap.insertMulti(source, QString("memtotgb"));
|
||||
m_requiredByMap.insertMulti(source, QString("mem"));
|
||||
} else if (source == QString("network/current/name")) {
|
||||
// network device
|
||||
m_map[source] = QString("netdev");
|
||||
m_formater[QString("netdev")] = NoFormat;
|
||||
// fill required by list
|
||||
m_requiredByMap.insertMulti(source, QString("down"));
|
||||
m_requiredByMap.insertMulti(source, QString("downkb"));
|
||||
m_requiredByMap.insertMulti(source, QString("downunits"));
|
||||
m_requiredByMap.insertMulti(source, QString("up"));
|
||||
m_requiredByMap.insertMulti(source, QString("upkb"));
|
||||
m_requiredByMap.insertMulti(source, QString("upunits"));
|
||||
} else if (source.contains(netRegExp)) {
|
||||
// network speed
|
||||
QString type = source.contains(QString("receiver")) ? QString("down")
|
||||
@ -412,6 +446,13 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
|
||||
m_map.insertMulti(source, key);
|
||||
m_formater[key] = NetSmartUnits;
|
||||
}
|
||||
// fill required by list
|
||||
m_requiredByMap.insertMulti(source, QString("%1").arg(type));
|
||||
m_requiredByMap.insertMulti(source, QString("%1kb").arg(type));
|
||||
m_requiredByMap.insertMulti(source, QString("%1units").arg(type));
|
||||
m_requiredByMap.insertMulti(source, QString("%1").arg(type));
|
||||
m_requiredByMap.insertMulti(source, QString("%1kb").arg(type));
|
||||
m_requiredByMap.insertMulti(source, QString("%1units").arg(type));
|
||||
} else if (source.startsWith(QString("upgrade"))) {
|
||||
// package manager
|
||||
QString key = source;
|
||||
@ -450,6 +491,10 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
|
||||
// gb
|
||||
m_map.insertMulti(source, QString("swapfreegb"));
|
||||
m_formater[QString("swapfreegb")] = MemGBFormat;
|
||||
// fill required by list
|
||||
m_requiredByMap.insertMulti(source, QString("swaptotmb"));
|
||||
m_requiredByMap.insertMulti(source, QString("swaptotgb"));
|
||||
m_requiredByMap.insertMulti(source, QString("swap"));
|
||||
} else if (source == QString("mem/swap/used")) {
|
||||
// used swap
|
||||
// mb
|
||||
@ -458,6 +503,10 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
|
||||
// gb
|
||||
m_map.insertMulti(source, QString("swapgb"));
|
||||
m_formater[QString("swapgb")] = MemGBFormat;
|
||||
// fill required by list
|
||||
m_requiredByMap.insertMulti(source, QString("swaptotmb"));
|
||||
m_requiredByMap.insertMulti(source, QString("swaptotgb"));
|
||||
m_requiredByMap.insertMulti(source, QString("swap"));
|
||||
} else if (source.startsWith(QString("lmsensors/"))) {
|
||||
// temperature
|
||||
int index = m_devices[QString("temp")].indexOf(source);
|
||||
|
@ -67,6 +67,7 @@ public:
|
||||
// get methods
|
||||
QString formater(const QVariant &data, const QString &key) const;
|
||||
QStringList keysFromSource(const QString &source) const;
|
||||
QStringList requiredByKeysFromSource(const QString &source) const;
|
||||
// set methods
|
||||
void setAcOffline(const QString inactive);
|
||||
void setAcOnline(const QString active);
|
||||
@ -90,6 +91,7 @@ private:
|
||||
QHash<QString, QStringList> m_devices;
|
||||
QHash<QString, FormaterType> m_formater;
|
||||
QHash<QString, QString> m_map;
|
||||
QHash<QString, QString> m_requiredByMap;
|
||||
QString m_tempUnits;
|
||||
bool m_translate = false;
|
||||
};
|
||||
|
267
sources/awesome-widget/plugin/awpatternfunctions.cpp
Normal file
@ -0,0 +1,267 @@
|
||||
/***************************************************************************
|
||||
* 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 "awpatternfunctions.h"
|
||||
|
||||
#include <QJSEngine>
|
||||
#include <QRegularExpression>
|
||||
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
QVariantList AWPatternFunctions::findFunctionCalls(const QString function,
|
||||
const QString code)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Looking for function" << function << "in" << code;
|
||||
|
||||
// I suggest the following regex for the internal functions
|
||||
// $aw_function_name<some args here if any>{{function body}}
|
||||
// * args should be always comma separated (e.g. commas are not supported
|
||||
// in this field if they are not screened by $, i.e. '$,'
|
||||
// * body depends on the function name, double brackets (i.e. {{ or }}) are
|
||||
// not supported
|
||||
QRegularExpression regex(
|
||||
QString("\\$%1\\<(?<args>.*?)\\>\\{\\{(?<body>.*?)\\}\\}")
|
||||
.arg(function));
|
||||
regex.setPatternOptions(QRegularExpression::DotMatchesEverythingOption);
|
||||
|
||||
QVariantList foundFunctions;
|
||||
QRegularExpressionMatchIterator it = regex.globalMatch(code);
|
||||
while (it.hasNext()) {
|
||||
QRegularExpressionMatch match = it.next();
|
||||
|
||||
QVariantHash metadata;
|
||||
// work with args
|
||||
QString argsString = match.captured(QString("args"));
|
||||
if (argsString.isEmpty()) {
|
||||
metadata[QString("args")] = QStringList();
|
||||
} else {
|
||||
// replace '$,' to 0x1d
|
||||
argsString.replace(QString("$,"), QString(0x1d));
|
||||
QStringList args = argsString.split(QChar(','));
|
||||
std::for_each(args.begin(), args.end(), [](QString &arg) {
|
||||
arg.replace(QString(0x1d), QString(","));
|
||||
});
|
||||
metadata[QString("args")] = args;
|
||||
}
|
||||
// other variables
|
||||
metadata[QString("body")] = match.captured(QString("body"));
|
||||
metadata[QString("what")] = match.captured();
|
||||
foundFunctions.append(metadata);
|
||||
}
|
||||
|
||||
return foundFunctions;
|
||||
}
|
||||
|
||||
|
||||
QString AWPatternFunctions::expandTemplates(QString code)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Expand templates in" << code;
|
||||
|
||||
// match the following construction $template{{some code here}}
|
||||
QRegularExpression templatesRegexp(
|
||||
QString("\\$template\\{\\{(?<body>.*?)\\}\\}"));
|
||||
templatesRegexp.setPatternOptions(
|
||||
QRegularExpression::DotMatchesEverythingOption);
|
||||
|
||||
QRegularExpressionMatchIterator it = templatesRegexp.globalMatch(code);
|
||||
while (it.hasNext()) {
|
||||
QRegularExpressionMatch match = it.next();
|
||||
QString body = match.captured(QString("body"));
|
||||
|
||||
QJSEngine engine;
|
||||
qCInfo(LOG_AW) << "Expression" << body;
|
||||
QJSValue result = engine.evaluate(body);
|
||||
QString templateResult = QString("");
|
||||
if (result.isError()) {
|
||||
qCWarning(LOG_AW) << "Uncaught exception at line"
|
||||
<< result.property("lineNumber").toInt() << ":"
|
||||
<< result.toString();
|
||||
} else {
|
||||
templateResult = result.toString();
|
||||
}
|
||||
|
||||
// replace template
|
||||
code.replace(match.captured(), templateResult);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
QString AWPatternFunctions::insertAllKeys(QString code, const QStringList keys)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Looking for keys in code" << code << "using list"
|
||||
<< keys;
|
||||
|
||||
QVariantList found
|
||||
= AWPatternFunctions::findFunctionCalls(QString("aw_all"), code);
|
||||
for (auto function : found) {
|
||||
QVariantHash metadata = function.toHash();
|
||||
QString separator
|
||||
= metadata[QString("args")].toStringList().isEmpty()
|
||||
? QString(",")
|
||||
: metadata[QString("args")].toStringList().at(0);
|
||||
QStringList required
|
||||
= keys.filter(QRegExp(metadata[QString("body")].toString()));
|
||||
std::for_each(required.begin(), required.end(), [](QString &value) {
|
||||
value = QString("%1: $%1").arg(value);
|
||||
});
|
||||
|
||||
code.replace(metadata[QString("what")].toString(),
|
||||
required.join(separator));
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
QString AWPatternFunctions::insertKeyCount(QString code, const QStringList keys)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Looking for count in code" << code << "using list"
|
||||
<< keys;
|
||||
|
||||
QVariantList found
|
||||
= AWPatternFunctions::findFunctionCalls(QString("aw_count"), code);
|
||||
for (auto function : found) {
|
||||
QVariantHash metadata = function.toHash();
|
||||
int count = keys.filter(QRegExp(metadata[QString("body")].toString()))
|
||||
.count();
|
||||
|
||||
code.replace(metadata[QString("what")].toString(),
|
||||
QString::number(count));
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
QString AWPatternFunctions::insertKeyNames(QString code, const QStringList keys)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Looking for key names in code" << code << "using list"
|
||||
<< keys;
|
||||
|
||||
QVariantList found
|
||||
= AWPatternFunctions::findFunctionCalls(QString("aw_names"), code);
|
||||
for (auto function : found) {
|
||||
QVariantHash metadata = function.toHash();
|
||||
QString separator
|
||||
= metadata[QString("args")].toStringList().isEmpty()
|
||||
? QString(",")
|
||||
: metadata[QString("args")].toStringList().at(0);
|
||||
QStringList required
|
||||
= keys.filter(QRegExp(metadata[QString("body")].toString()));
|
||||
|
||||
code.replace(metadata[QString("what")].toString(),
|
||||
required.join(separator));
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
QString AWPatternFunctions::insertKeys(QString code, const QStringList keys)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Looking for keys in code" << code << "using list"
|
||||
<< keys;
|
||||
|
||||
QVariantList found
|
||||
= AWPatternFunctions::findFunctionCalls(QString("aw_keys"), code);
|
||||
for (auto function : found) {
|
||||
QVariantHash metadata = function.toHash();
|
||||
QString separator
|
||||
= metadata[QString("args")].toStringList().isEmpty()
|
||||
? QString(",")
|
||||
: metadata[QString("args")].toStringList().at(0);
|
||||
QStringList required
|
||||
= keys.filter(QRegExp(metadata[QString("body")].toString()));
|
||||
std::for_each(required.begin(), required.end(), [](QString &value) {
|
||||
value = QString("$%1").arg(value);
|
||||
});
|
||||
|
||||
code.replace(metadata[QString("what")].toString(),
|
||||
required.join(separator));
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
QStringList AWPatternFunctions::findBars(const QString code,
|
||||
const QStringList keys)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Looking for bars in code" << code << "using list"
|
||||
<< keys;
|
||||
|
||||
QStringList selectedKeys;
|
||||
for (auto key : keys)
|
||||
if ((key.startsWith(QString("bar")))
|
||||
&& (code.contains(QString("$%1").arg(key)))) {
|
||||
qCInfo(LOG_AW) << "Found bar" << key;
|
||||
selectedKeys.append(key);
|
||||
}
|
||||
if (selectedKeys.isEmpty())
|
||||
qCWarning(LOG_AW) << "No bars found";
|
||||
|
||||
return selectedKeys;
|
||||
}
|
||||
|
||||
|
||||
QStringList AWPatternFunctions::findKeys(const QString code,
|
||||
const QStringList keys)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Looking for keys in code" << code << "using list"
|
||||
<< keys;
|
||||
|
||||
QStringList selectedKeys;
|
||||
for (auto key : keys)
|
||||
if ((!key.startsWith(QString("bar")))
|
||||
&& (code.contains(QString("$%1").arg(key)))) {
|
||||
qCInfo(LOG_AW) << "Found key" << key;
|
||||
selectedKeys.append(key);
|
||||
}
|
||||
if (selectedKeys.isEmpty())
|
||||
qCWarning(LOG_AW) << "No keys found";
|
||||
|
||||
return selectedKeys;
|
||||
}
|
||||
|
||||
|
||||
QStringList AWPatternFunctions::findLambdas(const QString code)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Looking for lambdas in code" << code;
|
||||
|
||||
QStringList selectedKeys;
|
||||
// match the following construction ${{some code here}}
|
||||
QRegularExpression lambdaRegexp(QString("\\$\\{\\{(?<body>.*?)\\}\\}"));
|
||||
lambdaRegexp.setPatternOptions(
|
||||
QRegularExpression::DotMatchesEverythingOption);
|
||||
|
||||
QRegularExpressionMatchIterator it = lambdaRegexp.globalMatch(code);
|
||||
while (it.hasNext()) {
|
||||
QRegularExpressionMatch match = it.next();
|
||||
QString lambda = match.captured(QString("body"));
|
||||
|
||||
// append
|
||||
qCInfo(LOG_AW) << "Found lambda" << lambda;
|
||||
selectedKeys.append(lambda);
|
||||
}
|
||||
if (selectedKeys.isEmpty())
|
||||
qCWarning(LOG_AW) << "No lambdas found";
|
||||
|
||||
return selectedKeys;
|
||||
}
|
42
sources/awesome-widget/plugin/awpatternfunctions.h
Normal file
@ -0,0 +1,42 @@
|
||||
/***************************************************************************
|
||||
* 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 AWPATTERNFUNCTIONS_H
|
||||
#define AWPATTERNFUNCTIONS_H
|
||||
|
||||
#include <QString>
|
||||
#include <QVariant>
|
||||
|
||||
|
||||
namespace AWPatternFunctions
|
||||
{
|
||||
// insert methods
|
||||
QString expandTemplates(QString code);
|
||||
QVariantList findFunctionCalls(const QString function, const QString code);
|
||||
QString insertAllKeys(QString code, const QStringList keys);
|
||||
QString insertKeyCount(QString code, const QStringList keys);
|
||||
QString insertKeyNames(QString code, const QStringList keys);
|
||||
QString insertKeys(QString code, const QStringList keys);
|
||||
// find methods
|
||||
QStringList findBars(const QString code, const QStringList keys);
|
||||
QStringList findKeys(const QString code, const QStringList keys);
|
||||
QStringList findLambdas(const QString code);
|
||||
};
|
||||
|
||||
|
||||
#endif /* AWPATTERNFUNCTIONS_H */
|
@ -33,8 +33,9 @@ AbstractExtItem::AbstractExtItem(QWidget *parent, const QString desktopName,
|
||||
, m_dirs(directories)
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
qCDebug(LOG_LIB) << "Desktop name" << desktopName;
|
||||
qCDebug(LOG_LIB) << "Directories" << directories;
|
||||
|
||||
qCDebug(LOG_LIB) << "Desktop name" << desktopName << "directories"
|
||||
<< directories;
|
||||
|
||||
m_name = m_fileName;
|
||||
}
|
||||
@ -193,14 +194,14 @@ void AbstractExtItem::readConfiguration()
|
||||
|
||||
bool AbstractExtItem::tryDelete() const
|
||||
{
|
||||
foreach (QString dir, m_dirs) {
|
||||
for (auto dir : m_dirs) {
|
||||
bool status = QFile::remove(QString("%1/%2").arg(dir).arg(m_fileName));
|
||||
qCInfo(LOG_LIB) << "Remove file"
|
||||
<< QString("%1/%2").arg(dir).arg(m_fileName) << status;
|
||||
}
|
||||
|
||||
// check if exists
|
||||
foreach (QString dir, m_dirs)
|
||||
for (auto dir : m_dirs)
|
||||
if (QFile::exists(QString("%1/%2").arg(dir).arg(m_fileName)))
|
||||
return false;
|
||||
return true;
|
||||
|
@ -91,10 +91,8 @@ void AbstractExtItemAggregator::setConfigArgs(const QVariant _configArgs)
|
||||
}
|
||||
|
||||
|
||||
void AbstractExtItemAggregator::editItemActivated(QListWidgetItem *item)
|
||||
void AbstractExtItemAggregator::editItemActivated(QListWidgetItem *)
|
||||
{
|
||||
Q_UNUSED(item)
|
||||
|
||||
return editItem();
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,7 @@ public:
|
||||
void setConfigArgs(const QVariant _configArgs);
|
||||
|
||||
private slots:
|
||||
void editItemActivated(QListWidgetItem *item);
|
||||
void editItemActivated(QListWidgetItem *);
|
||||
void editItemButtonPressed(QAbstractButton *button);
|
||||
|
||||
private:
|
||||
|
@ -1,139 +1,113 @@
|
||||
{
|
||||
"__url": "http://openweathermap.org/weather-conditions",
|
||||
"__url": "https://developer.yahoo.com/weather/documentation.html",
|
||||
|
||||
"image": {
|
||||
"__comment": "should be described as html image with full path inside",
|
||||
|
||||
"default": "",
|
||||
"default": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/3200.gif\">",
|
||||
|
||||
"800": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/01d.png\">",
|
||||
|
||||
"801": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/02d.png\">",
|
||||
|
||||
"802": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/03d.png\">",
|
||||
"803": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/03d.png\">",
|
||||
|
||||
"804": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/04d.png\">",
|
||||
|
||||
"300": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/09d.png\">",
|
||||
"301": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/09d.png\">",
|
||||
"302": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/09d.png\">",
|
||||
"310": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/09d.png\">",
|
||||
"311": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/09d.png\">",
|
||||
"312": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/09d.png\">",
|
||||
"313": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/09d.png\">",
|
||||
"314": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/09d.png\">",
|
||||
"321": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/09d.png\">",
|
||||
"520": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/09d.png\">",
|
||||
"521": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/09d.png\">",
|
||||
"522": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/09d.png\">",
|
||||
"531": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/09d.png\">",
|
||||
|
||||
"500": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/10d.png\">",
|
||||
"501": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/10d.png\">",
|
||||
"502": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/10d.png\">",
|
||||
"503": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/10d.png\">",
|
||||
"504": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/10d.png\">",
|
||||
|
||||
"200": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/11d.png\">",
|
||||
"201": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/11d.png\">",
|
||||
"202": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/11d.png\">",
|
||||
"210": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/11d.png\">",
|
||||
"211": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/11d.png\">",
|
||||
"212": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/11d.png\">",
|
||||
"221": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/11d.png\">",
|
||||
"230": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/11d.png\">",
|
||||
"231": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/11d.png\">",
|
||||
"232": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/11d.png\">",
|
||||
|
||||
"511": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/13d.png\">",
|
||||
"600": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/13d.png\">",
|
||||
"601": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/13d.png\">",
|
||||
"602": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/13d.png\">",
|
||||
"611": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/13d.png\">",
|
||||
"612": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/13d.png\">",
|
||||
"615": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/13d.png\">",
|
||||
"616": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/13d.png\">",
|
||||
"620": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/13d.png\">",
|
||||
"621": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/13d.png\">",
|
||||
"622": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/13d.png\">",
|
||||
|
||||
"701": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/50d.png\">",
|
||||
"711": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/50d.png\">",
|
||||
"721": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/50d.png\">",
|
||||
"731": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/50d.png\">",
|
||||
"741": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/50d.png\">",
|
||||
"751": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/50d.png\">",
|
||||
"761": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/50d.png\">",
|
||||
"762": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/50d.png\">",
|
||||
"771": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/50d.png\">",
|
||||
"781": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/50d.png\">"
|
||||
"0": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/0.gif\">",
|
||||
"1": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/1.gif\">",
|
||||
"2": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/2.gif\">",
|
||||
"3": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/3.gif\">",
|
||||
"4": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/4.gif\">",
|
||||
"5": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/5.gif\">",
|
||||
"6": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/6.gif\">",
|
||||
"7": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/7.gif\">",
|
||||
"8": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/8.gif\">",
|
||||
"9": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/9.gif\">",
|
||||
"10": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/10.gif\">",
|
||||
"11": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/11.gif\">",
|
||||
"12": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/12.gif\">",
|
||||
"13": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/13.gif\">",
|
||||
"14": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/14.gif\">",
|
||||
"15": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/15.gif\">",
|
||||
"16": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/16.gif\">",
|
||||
"17": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/17.gif\">",
|
||||
"18": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/18.gif\">",
|
||||
"19": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/19.gif\">",
|
||||
"20": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/20.gif\">",
|
||||
"21": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/21.gif\">",
|
||||
"22": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/22.gif\">",
|
||||
"23": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/23.gif\">",
|
||||
"24": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/24.gif\">",
|
||||
"25": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/25.gif\">",
|
||||
"26": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/26.gif\">",
|
||||
"27": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/27.gif\">",
|
||||
"28": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/28.gif\">",
|
||||
"29": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/29.gif\">",
|
||||
"30": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/30.gif\">",
|
||||
"31": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/31.gif\">",
|
||||
"32": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/32.gif\">",
|
||||
"33": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/33.gif\">",
|
||||
"34": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/34.gif\">",
|
||||
"35": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/35.gif\">",
|
||||
"36": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/36.gif\">",
|
||||
"37": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/37.gif\">",
|
||||
"38": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/38.gif\">",
|
||||
"39": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/39.gif\">",
|
||||
"40": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/40.gif\">",
|
||||
"41": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/41.gif\">",
|
||||
"42": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/42.gif\">",
|
||||
"43": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/43.gif\">",
|
||||
"44": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/44.gif\">",
|
||||
"45": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/45.gif\">",
|
||||
"46": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/46.gif\">",
|
||||
"47": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/47.gif\">",
|
||||
"3200": "<img src=\"@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIR@/@PROJECT_NAME@/weather/3200.gif\">"
|
||||
},
|
||||
|
||||
"text": {
|
||||
"default": "\u2604",
|
||||
"3200": "\u2604",
|
||||
|
||||
"800": "\u2600",
|
||||
|
||||
"801": "\u26C5",
|
||||
|
||||
"802": "\u2601",
|
||||
"803": "\u2601",
|
||||
|
||||
"804": "\u2601",
|
||||
|
||||
"300": "\u2602",
|
||||
"301": "\u2602",
|
||||
"302": "\u2602",
|
||||
"310": "\u2602",
|
||||
"311": "\u2602",
|
||||
"312": "\u2602",
|
||||
"313": "\u2602",
|
||||
"314": "\u2602",
|
||||
"321": "\u2602",
|
||||
"520": "\u2602",
|
||||
"521": "\u2602",
|
||||
"522": "\u2602",
|
||||
"531": "\u2602",
|
||||
|
||||
"500": "\u2614",
|
||||
"501": "\u2614",
|
||||
"502": "\u2614",
|
||||
"503": "\u2614",
|
||||
"504": "\u2614",
|
||||
|
||||
"200": "\u2608",
|
||||
"201": "\u2608",
|
||||
"202": "\u2608",
|
||||
"210": "\u2608",
|
||||
"211": "\u2608",
|
||||
"212": "\u2608",
|
||||
"221": "\u2608",
|
||||
"230": "\u2608",
|
||||
"231": "\u2608",
|
||||
"232": "\u2608",
|
||||
|
||||
"511": "\u2603",
|
||||
"600": "\u2603",
|
||||
"601": "\u2603",
|
||||
"602": "\u2603",
|
||||
"611": "\u2603",
|
||||
"612": "\u2603",
|
||||
"615": "\u2603",
|
||||
"616": "\u2603",
|
||||
"620": "\u2603",
|
||||
"621": "\u2603",
|
||||
"622": "\u2603",
|
||||
|
||||
"701": "\u26C5",
|
||||
"711": "\u26C5",
|
||||
"721": "\u26C5",
|
||||
"731": "\u26C5",
|
||||
"741": "\u26C5",
|
||||
"751": "\u26C5",
|
||||
"761": "\u26C5",
|
||||
"762": "\u26C5",
|
||||
"771": "\u26C5",
|
||||
"781": "\u26C5"
|
||||
"0": "\u2604",
|
||||
"1": "\u2604",
|
||||
"2": "\u2604",
|
||||
"3": "\u26C8",
|
||||
"4": "\u26C8",
|
||||
"5": "\u2614",
|
||||
"6": "\u2614",
|
||||
"7": "\u2614",
|
||||
"8": "\u2614",
|
||||
"9": "\u2614",
|
||||
"10": "\u2614",
|
||||
"11": "\u2614",
|
||||
"12": "\u2614",
|
||||
"13": "\u26C4",
|
||||
"14": "\u26C7",
|
||||
"15": "\u26C7",
|
||||
"16": "\u2614",
|
||||
"17": "\u2614",
|
||||
"18": "\u2614",
|
||||
"19": "\u26C5",
|
||||
"20": "\u26C5",
|
||||
"21": "\u26C5",
|
||||
"22": "\u26C5",
|
||||
"23": "\u26C5",
|
||||
"24": "\u26C5",
|
||||
"25": "\u26C5",
|
||||
"26": "\u2601",
|
||||
"27": "\u2601",
|
||||
"28": "\u2601",
|
||||
"29": "\u2601",
|
||||
"30": "\u2601",
|
||||
"31": "\u263D",
|
||||
"32": "\u2600",
|
||||
"33": "\u263D",
|
||||
"34": "\u2600",
|
||||
"35": "\u2614",
|
||||
"36": "\u2600",
|
||||
"37": "\u26C8",
|
||||
"38": "\u26C8",
|
||||
"39": "\u26C8",
|
||||
"40": "\u26C7",
|
||||
"41": "\u26C7",
|
||||
"42": "\u26C7",
|
||||
"43": "\u26C7",
|
||||
"44": "\u2601",
|
||||
"45": "\u26C8",
|
||||
"46": "\u26C7",
|
||||
"47": "\u26C8"
|
||||
}
|
||||
}
|
||||
|
@ -37,8 +37,9 @@ public:
|
||||
{
|
||||
qSetMessagePattern(LOG_FORMAT);
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
foreach (const QString metadata, getBuildData())
|
||||
for (auto metadata : getBuildData())
|
||||
qCDebug(LOG_LIB) << metadata;
|
||||
|
||||
qCDebug(LOG_LIB) << "Type" << type;
|
||||
|
||||
initItems();
|
||||
@ -66,7 +67,7 @@ public:
|
||||
qCDebug(LOG_LIB) << "Tag" << _tag;
|
||||
|
||||
T *found = nullptr;
|
||||
foreach (T *item, m_items) {
|
||||
for (auto item : m_items) {
|
||||
if (item->tag() != _tag)
|
||||
continue;
|
||||
found = item;
|
||||
@ -83,7 +84,7 @@ public:
|
||||
qCDebug(LOG_LIB) << "Number" << _number;
|
||||
|
||||
T *found = nullptr;
|
||||
foreach (T *item, m_items) {
|
||||
for (auto item : m_items) {
|
||||
if (item->number() != _number)
|
||||
continue;
|
||||
found = item;
|
||||
@ -102,7 +103,7 @@ public:
|
||||
return nullptr;
|
||||
|
||||
T *found = nullptr;
|
||||
foreach (T *item, m_items) {
|
||||
for (auto item : m_items) {
|
||||
if (item->fileName() != widgetItem->text())
|
||||
continue;
|
||||
found = item;
|
||||
@ -120,7 +121,7 @@ public:
|
||||
int uniqNumber() const
|
||||
{
|
||||
QList<int> tagList;
|
||||
foreach (T *item, m_items)
|
||||
for (auto item : m_items)
|
||||
tagList.append(item->number());
|
||||
int number = 0;
|
||||
while (tagList.contains(number))
|
||||
@ -152,9 +153,9 @@ private:
|
||||
QStandardPaths::LocateDirectory);
|
||||
QStringList names;
|
||||
QList<T *> items;
|
||||
foreach (QString dir, dirs) {
|
||||
for (auto dir : dirs) {
|
||||
QStringList files = QDir(dir).entryList(QDir::Files, QDir::Name);
|
||||
foreach (QString file, files) {
|
||||
for (auto file : files) {
|
||||
if ((!file.endsWith(QString(".desktop")))
|
||||
|| (names.contains(file)))
|
||||
continue;
|
||||
@ -177,7 +178,7 @@ private:
|
||||
m_activeItems.clear();
|
||||
|
||||
m_items = getItems();
|
||||
foreach (T *item, m_items) {
|
||||
for (auto item : m_items) {
|
||||
if (!item->isActive())
|
||||
continue;
|
||||
m_activeItems.append(item);
|
||||
@ -187,7 +188,7 @@ private:
|
||||
void repaint()
|
||||
{
|
||||
widgetDialog->clear();
|
||||
foreach (T *_item, m_items) {
|
||||
for (auto _item : m_items) {
|
||||
QListWidgetItem *item
|
||||
= new QListWidgetItem(_item->fileName(), widgetDialog);
|
||||
QStringList tooltip;
|
||||
|
@ -150,7 +150,7 @@ QVariantHash ExtQuotes::run()
|
||||
qCInfo(LOG_LIB) << "Send request";
|
||||
isRunning = true;
|
||||
QNetworkReply *reply = manager->get(QNetworkRequest(QUrl(url())));
|
||||
new QReplyTimeout(reply, 1000);
|
||||
new QReplyTimeout(reply, REQUEST_TIMEOUT);
|
||||
}
|
||||
|
||||
// update value
|
||||
@ -208,8 +208,8 @@ void ExtQuotes::writeConfiguration() const
|
||||
|
||||
void ExtQuotes::quotesReplyReceived(QNetworkReply *reply)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Return code" << reply->error();
|
||||
qCDebug(LOG_LIB) << "Reply error message" << reply->errorString();
|
||||
qCDebug(LOG_LIB) << "Return code" << reply->error() << "with message"
|
||||
<< reply->errorString();
|
||||
|
||||
isRunning = false;
|
||||
QJsonParseError error;
|
||||
@ -279,8 +279,7 @@ get quotes for the instrument. Refer to <a href=\"http://finance.yahoo.com/\">\
|
||||
|
||||
QString ExtQuotes::url() const
|
||||
{
|
||||
QString apiUrl = QString(YAHOO_URL);
|
||||
apiUrl.replace(QString("$TICKER"), m_ticker);
|
||||
QString apiUrl = QString(YAHOO_QUOTES_URL).arg(m_ticker);
|
||||
qCInfo(LOG_LIB) << "API url" << apiUrl;
|
||||
|
||||
return apiUrl;
|
||||
|
@ -22,10 +22,10 @@
|
||||
|
||||
#include "abstractextitem.h"
|
||||
|
||||
#define YAHOO_URL \
|
||||
#define YAHOO_QUOTES_URL \
|
||||
"https://query.yahooapis.com/v1/public/yql?q=select * from " \
|
||||
"yahoo.finance.quotes where " \
|
||||
"symbol=\"$TICKER\"&env=store://datatables.org/" \
|
||||
"symbol=\"%1\"&env=store://datatables.org/" \
|
||||
"alltableswithkeys&format=json"
|
||||
|
||||
|
||||
|
@ -64,8 +64,7 @@ ExtScript::~ExtScript()
|
||||
|
||||
ExtScript *ExtScript::copy(const QString _fileName, const int _number)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "File" << _fileName;
|
||||
qCDebug(LOG_LIB) << "Number" << _number;
|
||||
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
||||
|
||||
ExtScript *item = new ExtScript(static_cast<QWidget *>(parent()), _fileName,
|
||||
directories());
|
||||
@ -188,7 +187,7 @@ QString ExtScript::applyFilters(QString _value) const
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Value" << _value;
|
||||
|
||||
foreach (QString filt, m_filters) {
|
||||
for (auto filt : m_filters) {
|
||||
qCInfo(LOG_LIB) << "Found filter" << filt;
|
||||
QVariantMap filter = jsonFilters[filt].toMap();
|
||||
if (filter.isEmpty()) {
|
||||
@ -196,7 +195,7 @@ QString ExtScript::applyFilters(QString _value) const
|
||||
<< "in the json";
|
||||
continue;
|
||||
}
|
||||
foreach (QString f, filter.keys())
|
||||
for (auto f : filter.keys())
|
||||
_value.replace(f, filter[f].toString());
|
||||
}
|
||||
|
||||
@ -206,8 +205,7 @@ QString ExtScript::applyFilters(QString _value) const
|
||||
|
||||
void ExtScript::updateFilter(const QString _filter, const bool _add)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Filter" << _filter;
|
||||
qCDebug(LOG_LIB) << "Should be added" << _add;
|
||||
qCDebug(LOG_LIB) << "Should be added filters" << _add << "from" << _filter;
|
||||
|
||||
if (_add) {
|
||||
if (m_filters.contains(_filter))
|
||||
|
@ -60,8 +60,7 @@ ExtUpgrade::~ExtUpgrade()
|
||||
|
||||
ExtUpgrade *ExtUpgrade::copy(const QString _fileName, const int _number)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "File" << _fileName;
|
||||
qCDebug(LOG_LIB) << "Number" << _number;
|
||||
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
||||
|
||||
ExtUpgrade *item = new ExtUpgrade(static_cast<QWidget *>(parent()),
|
||||
_fileName, directories());
|
||||
|
@ -74,8 +74,7 @@ ExtWeather::~ExtWeather()
|
||||
|
||||
ExtWeather *ExtWeather::copy(const QString _fileName, const int _number)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "File" << _fileName;
|
||||
qCDebug(LOG_LIB) << "Number" << _number;
|
||||
qCDebug(LOG_LIB) << "File" << _fileName << "number" << _number;
|
||||
|
||||
ExtWeather *item = new ExtWeather(static_cast<QWidget *>(parent()),
|
||||
_fileName, directories());
|
||||
@ -235,9 +234,8 @@ QVariantHash ExtWeather::run()
|
||||
if (times == 1) {
|
||||
qCInfo(LOG_LIB) << "Send request";
|
||||
isRunning = true;
|
||||
QNetworkReply *reply
|
||||
= manager->get(QNetworkRequest(QUrl(url(m_ts != 0))));
|
||||
new QReplyTimeout(reply, 1000);
|
||||
QNetworkReply *reply = manager->get(QNetworkRequest(QUrl(url())));
|
||||
new QReplyTimeout(reply, REQUEST_TIMEOUT);
|
||||
}
|
||||
|
||||
// update value
|
||||
@ -305,7 +303,7 @@ void ExtWeather::writeConfiguration() const
|
||||
|
||||
void ExtWeather::weatherReplyReceived(QNetworkReply *reply)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Return code" << reply->error();
|
||||
qCDebug(LOG_LIB) << "Return code" << reply->error() << "with messa";
|
||||
qCDebug(LOG_LIB) << "Reply error message" << reply->errorString();
|
||||
|
||||
isRunning = false;
|
||||
@ -319,51 +317,52 @@ void ExtWeather::weatherReplyReceived(QNetworkReply *reply)
|
||||
}
|
||||
|
||||
// convert to map
|
||||
QVariantMap json = jsonDoc.toVariant().toMap();
|
||||
if (json[QString("cod")].toInt() != 200) {
|
||||
qCWarning(LOG_LIB) << "Invalid OpenWeatherMap return code"
|
||||
<< json[QString("cod")].toInt();
|
||||
QVariantMap json = jsonDoc.toVariant().toMap()[QString("query")].toMap();
|
||||
if (json[QString("count")].toInt() != 1) {
|
||||
qCWarning(LOG_LIB) << "Found data count"
|
||||
<< json[QString("count")].toInt() << "is not 1";
|
||||
return;
|
||||
}
|
||||
QVariantMap results
|
||||
= json[QString("results")].toMap()[QString("channel")].toMap();
|
||||
QVariantMap item = results[QString("item")].toMap();
|
||||
|
||||
QVariantHash data;
|
||||
if (m_ts == 0) {
|
||||
data = parseSingleJson(json);
|
||||
// current weather
|
||||
int id = item[QString("condition")].toMap()[QString("code")].toInt();
|
||||
values[tag(QString("weatherId"))] = id;
|
||||
values[tag(QString("weather"))] = weatherFromInt(id);
|
||||
values[tag(QString("temperature"))]
|
||||
= item[QString("condition")].toMap()[QString("temp")].toInt();
|
||||
values[tag(QString("timestamp"))]
|
||||
= item[QString("condition")].toMap()[QString("date")].toString();
|
||||
values[tag(QString("humidity"))] = results[QString("atmosphere")]
|
||||
.toMap()[QString("humidity")]
|
||||
.toInt();
|
||||
values[tag(QString("pressure"))]
|
||||
= static_cast<int>(results[QString("atmosphere")]
|
||||
.toMap()[QString("pressure")]
|
||||
.toFloat());
|
||||
} else {
|
||||
QVariantList list = json[QString("list")].toList();
|
||||
data = parseSingleJson(list.count() <= m_ts ? list.at(m_ts - 1).toMap()
|
||||
: list.last().toMap());
|
||||
// forecast weather
|
||||
QVariantList weatherList = item[QString("forecast")].toList();
|
||||
QVariantMap weatherMap = weatherList.count() < m_ts
|
||||
? weatherList.last().toMap()
|
||||
: weatherList.at(m_ts).toMap();
|
||||
int id = weatherMap[QString("code")].toInt();
|
||||
values[tag(QString("weatherId"))] = id;
|
||||
values[tag(QString("weather"))] = weatherFromInt(id);
|
||||
values[tag(QString("timestamp"))]
|
||||
= weatherMap[QString("date")].toString();
|
||||
// yahoo provides high and low temperatures. Lets calculate average one
|
||||
values[tag(QString("temperature"))]
|
||||
= (weatherMap[QString("high")].toFloat()
|
||||
+ weatherMap[QString("low")].toFloat())
|
||||
/ 2.0;
|
||||
// ... and no forecast data for humidity and pressure
|
||||
values[tag(QString("humidity"))] = 0;
|
||||
values[tag(QString("pressure"))] = 0.0;
|
||||
}
|
||||
foreach (QString key, data.keys())
|
||||
values[tag(key)] = data[key];
|
||||
}
|
||||
|
||||
|
||||
QVariantHash ExtWeather::parseSingleJson(const QVariantMap json) const
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Single json data" << json;
|
||||
|
||||
QVariantHash output;
|
||||
|
||||
// weather status
|
||||
QVariantList weather = json[QString("weather")].toList();
|
||||
if (!weather.isEmpty()) {
|
||||
int _id = weather.first().toMap()[QString("id")].toInt();
|
||||
output[QString("weatherId")] = _id;
|
||||
output[QString("weather")] = weatherFromInt(_id);
|
||||
}
|
||||
|
||||
// main data
|
||||
QVariantMap mainWeather = json[QString("main")].toMap();
|
||||
if (!weather.isEmpty()) {
|
||||
output[QString("humidity")]
|
||||
= mainWeather[QString("humidity")].toFloat();
|
||||
output[QString("pressure")]
|
||||
= mainWeather[QString("pressure")].toFloat();
|
||||
output[QString("temperature")] = mainWeather[QString("temp")].toFloat();
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
@ -381,13 +380,10 @@ void ExtWeather::translate()
|
||||
}
|
||||
|
||||
|
||||
QString ExtWeather::url(const bool isForecast) const
|
||||
QString ExtWeather::url() const
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Is forecast" << isForecast;
|
||||
|
||||
QString apiUrl = isForecast ? QString(OWM_FORECAST_URL) : QString(OWM_URL);
|
||||
apiUrl.replace(QString("$CITY"), m_city);
|
||||
apiUrl.replace(QString("$COUNTRY"), m_country);
|
||||
QString apiUrl = QString(YAHOO_WEATHER_URL).arg(m_city).arg(m_country);
|
||||
qCInfo(LOG_LIB) << "API url" << apiUrl;
|
||||
|
||||
return apiUrl;
|
||||
|
@ -22,12 +22,10 @@
|
||||
|
||||
#include "abstractextitem.h"
|
||||
|
||||
#define OWM_URL \
|
||||
"http://api.openweathermap.org/data/2.5/" \
|
||||
"weather?q=$CITY,$COUNTRY&units=metric"
|
||||
#define OWM_FORECAST_URL \
|
||||
"http://api.openweathermap.org/data/2.5/" \
|
||||
"forecast?q=$CITY,$COUNTRY&units=metric"
|
||||
#define YAHOO_WEATHER_URL \
|
||||
"https://query.yahooapis.com/v1/public/yql?format=json&q=select * from " \
|
||||
"weather.forecast where u='c' and woeid in (select woeid from " \
|
||||
"geo.places(1) where text='%1, %2')"
|
||||
|
||||
|
||||
namespace Ui
|
||||
@ -76,9 +74,8 @@ private:
|
||||
QNetworkAccessManager *manager;
|
||||
bool isRunning = false;
|
||||
Ui::ExtWeather *ui;
|
||||
QVariantHash parseSingleJson(const QVariantMap json) const;
|
||||
void translate();
|
||||
QString url(const bool isForecast = false) const;
|
||||
QString url() const;
|
||||
// properties
|
||||
QString m_city = QString("London");
|
||||
QString m_country = QString("uk");
|
||||
|
@ -65,8 +65,7 @@ GraphicalItem::~GraphicalItem()
|
||||
|
||||
GraphicalItem *GraphicalItem::copy(const QString _fileName, const int _number)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "File" << _fileName;
|
||||
qCDebug(LOG_LIB) << "Number" << _number;
|
||||
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
||||
|
||||
GraphicalItem *item = new GraphicalItem(static_cast<QWidget *>(parent()),
|
||||
_fileName, directories());
|
||||
|
BIN
sources/awesomewidgets/weather/0.gif
Normal file
After Width: | Height: | Size: 2.6 KiB |
Before Width: | Height: | Size: 2.8 KiB |
Before Width: | Height: | Size: 2.9 KiB |
Before Width: | Height: | Size: 2.5 KiB |
Before Width: | Height: | Size: 2.7 KiB |
Before Width: | Height: | Size: 3.7 KiB |
BIN
sources/awesomewidgets/weather/1.gif
Normal file
After Width: | Height: | Size: 2.4 KiB |
BIN
sources/awesomewidgets/weather/10.gif
Normal file
After Width: | Height: | Size: 2.4 KiB |
Before Width: | Height: | Size: 3.7 KiB |
BIN
sources/awesomewidgets/weather/11.gif
Normal file
After Width: | Height: | Size: 2.3 KiB |
Before Width: | Height: | Size: 3.7 KiB |
BIN
sources/awesomewidgets/weather/12.gif
Normal file
After Width: | Height: | Size: 2.3 KiB |
BIN
sources/awesomewidgets/weather/13.gif
Normal file
After Width: | Height: | Size: 2.0 KiB |
Before Width: | Height: | Size: 3.8 KiB |
BIN
sources/awesomewidgets/weather/14.gif
Normal file
After Width: | Height: | Size: 2.2 KiB |
BIN
sources/awesomewidgets/weather/15.gif
Normal file
After Width: | Height: | Size: 1.8 KiB |
BIN
sources/awesomewidgets/weather/16.gif
Normal file
After Width: | Height: | Size: 2.4 KiB |
BIN
sources/awesomewidgets/weather/17.gif
Normal file
After Width: | Height: | Size: 2.6 KiB |
BIN
sources/awesomewidgets/weather/18.gif
Normal file
After Width: | Height: | Size: 2.4 KiB |
BIN
sources/awesomewidgets/weather/19.gif
Normal file
After Width: | Height: | Size: 2.0 KiB |
BIN
sources/awesomewidgets/weather/2.gif
Normal file
After Width: | Height: | Size: 2.4 KiB |
BIN
sources/awesomewidgets/weather/20.gif
Normal file
After Width: | Height: | Size: 1.8 KiB |
BIN
sources/awesomewidgets/weather/21.gif
Normal file
After Width: | Height: | Size: 2.1 KiB |
BIN
sources/awesomewidgets/weather/22.gif
Normal file
After Width: | Height: | Size: 2.1 KiB |
BIN
sources/awesomewidgets/weather/23.gif
Normal file
After Width: | Height: | Size: 1.8 KiB |
BIN
sources/awesomewidgets/weather/24.gif
Normal file
After Width: | Height: | Size: 1.8 KiB |
BIN
sources/awesomewidgets/weather/25.gif
Normal file
After Width: | Height: | Size: 2.0 KiB |
BIN
sources/awesomewidgets/weather/26.gif
Normal file
After Width: | Height: | Size: 2.1 KiB |
BIN
sources/awesomewidgets/weather/27.gif
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
sources/awesomewidgets/weather/28.gif
Normal file
After Width: | Height: | Size: 2.6 KiB |
BIN
sources/awesomewidgets/weather/29.gif
Normal file
After Width: | Height: | Size: 2.4 KiB |
BIN
sources/awesomewidgets/weather/3.gif
Normal file
After Width: | Height: | Size: 2.6 KiB |
BIN
sources/awesomewidgets/weather/30.gif
Normal file
After Width: | Height: | Size: 2.4 KiB |
BIN
sources/awesomewidgets/weather/31.gif
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
sources/awesomewidgets/weather/32.gif
Normal file
After Width: | Height: | Size: 2.3 KiB |
BIN
sources/awesomewidgets/weather/3200.gif
Normal file
After Width: | Height: | Size: 2.1 KiB |
BIN
sources/awesomewidgets/weather/33.gif
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
sources/awesomewidgets/weather/34.gif
Normal file
After Width: | Height: | Size: 2.4 KiB |
BIN
sources/awesomewidgets/weather/35.gif
Normal file
After Width: | Height: | Size: 2.6 KiB |
BIN
sources/awesomewidgets/weather/36.gif
Normal file
After Width: | Height: | Size: 2.4 KiB |
BIN
sources/awesomewidgets/weather/37.gif
Normal file
After Width: | Height: | Size: 2.3 KiB |
BIN
sources/awesomewidgets/weather/38.gif
Normal file
After Width: | Height: | Size: 2.3 KiB |
BIN
sources/awesomewidgets/weather/39.gif
Normal file
After Width: | Height: | Size: 2.3 KiB |
BIN
sources/awesomewidgets/weather/4.gif
Normal file
After Width: | Height: | Size: 2.6 KiB |
BIN
sources/awesomewidgets/weather/40.gif
Normal file
After Width: | Height: | Size: 2.3 KiB |
BIN
sources/awesomewidgets/weather/41.gif
Normal file
After Width: | Height: | Size: 2.4 KiB |
BIN
sources/awesomewidgets/weather/42.gif
Normal file
After Width: | Height: | Size: 2.4 KiB |
BIN
sources/awesomewidgets/weather/43.gif
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
sources/awesomewidgets/weather/44.gif
Normal file
After Width: | Height: | Size: 2.4 KiB |
BIN
sources/awesomewidgets/weather/45.gif
Normal file
After Width: | Height: | Size: 980 B |
BIN
sources/awesomewidgets/weather/46.gif
Normal file
After Width: | Height: | Size: 996 B |
BIN
sources/awesomewidgets/weather/47.gif
Normal file
After Width: | Height: | Size: 972 B |
BIN
sources/awesomewidgets/weather/5.gif
Normal file
After Width: | Height: | Size: 2.3 KiB |
Before Width: | Height: | Size: 3.3 KiB |
BIN
sources/awesomewidgets/weather/6.gif
Normal file
After Width: | Height: | Size: 2.4 KiB |
BIN
sources/awesomewidgets/weather/7.gif
Normal file
After Width: | Height: | Size: 2.5 KiB |
BIN
sources/awesomewidgets/weather/8.gif
Normal file
After Width: | Height: | Size: 2.1 KiB |
BIN
sources/awesomewidgets/weather/9.gif
Normal file
After Width: | Height: | Size: 2.0 KiB |
@ -98,6 +98,15 @@ Item {
|
||||
text: dpAdds.getAboutText("translators")
|
||||
}
|
||||
|
||||
QtControls.Label {
|
||||
QtLayouts.Layout.fillWidth: true
|
||||
wrapMode: Text.WordWrap
|
||||
horizontalAlignment: Text.AlignJustify
|
||||
textFormat: Text.RichText
|
||||
text: dpAdds.getAboutText("3rdparty")
|
||||
onLinkActivated: Qt.openUrlExternally(link);
|
||||
}
|
||||
|
||||
QtControls.Label {
|
||||
QtLayouts.Layout.fillHeight: true
|
||||
QtLayouts.Layout.fillWidth: true
|
||||
@ -105,7 +114,7 @@ Item {
|
||||
horizontalAlignment: Text.AlignJustify
|
||||
verticalAlignment: Text.AlignTop
|
||||
textFormat: Text.RichText
|
||||
text: dpAdds.getAboutText("3rdparty")
|
||||
text: dpAdds.getAboutText("thanks")
|
||||
onLinkActivated: Qt.openUrlExternally(link);
|
||||
}
|
||||
}
|
||||
|
@ -113,7 +113,7 @@ Item {
|
||||
|
||||
for (var i=0; i<repeater.count; i++) {
|
||||
if (!repeater.itemAt(i)) {
|
||||
if (debug) console.info("Nothing to do here", i)
|
||||
if (debug) console.info("Nothing to do here yet", i)
|
||||
timer.start()
|
||||
return
|
||||
}
|
||||
@ -143,6 +143,12 @@ Item {
|
||||
|
||||
for (var i=0; i<repeater.count; i++) {
|
||||
repeater.itemAt(i).tooltip.text = dpAdds.toolTipImage(i + 1)
|
||||
// resize text tooltip to content size
|
||||
// this hack does not work for images-based tooltips
|
||||
if (tooltipSettings.tooltipType == "names") {
|
||||
repeater.itemAt(i).tooltip.height = repeater.itemAt(i).tooltip.implicitHeight
|
||||
repeater.itemAt(i).tooltip.width = repeater.itemAt(i).tooltip.implicitWidth
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ DPAdds::DPAdds(QObject *parent)
|
||||
{
|
||||
qSetMessagePattern(LOG_FORMAT);
|
||||
qCDebug(LOG_DP) << __PRETTY_FUNCTION__;
|
||||
foreach (const QString metadata, getBuildData())
|
||||
for (auto metadata : getBuildData())
|
||||
qCDebug(LOG_DP) << metadata;
|
||||
|
||||
connect(KWindowSystem::self(), SIGNAL(currentDesktopChanged(int)), this,
|
||||
@ -137,7 +137,7 @@ QString DPAdds::toolTipImage(const int desktop) const
|
||||
QPen pen = QPen();
|
||||
pen.setWidthF(2.0 * info.desktop.width() / 400.0);
|
||||
pen.setColor(QColor(m_tooltipColor));
|
||||
foreach (WindowData data, info.windowsData) {
|
||||
for (auto data : info.windowsData) {
|
||||
QRect rect = data.rect;
|
||||
toolTipScene->addLine(rect.left() + margin, rect.bottom() + margin,
|
||||
rect.left() + margin, rect.top() + margin,
|
||||
@ -191,12 +191,11 @@ QString DPAdds::toolTipImage(const int desktop) const
|
||||
|
||||
QString DPAdds::parsePattern(const QString pattern, const int desktop) const
|
||||
{
|
||||
qCDebug(LOG_DP) << "Pattern" << pattern;
|
||||
qCDebug(LOG_DP) << "Desktop number" << desktop;
|
||||
qCDebug(LOG_DP) << "Pattern" << pattern << "for desktop" << desktop;
|
||||
|
||||
QString parsed = pattern;
|
||||
parsed.replace(QString("$$"), QString("$\\$\\"));
|
||||
foreach (QString key, dictKeys())
|
||||
for (auto key : dictKeys())
|
||||
parsed.replace(QString("$%1").arg(key), valueByKey(key, desktop));
|
||||
parsed.replace(QString("$\\$\\"), QString("$$"));
|
||||
|
||||
@ -224,8 +223,7 @@ void DPAdds::setToolTipData(const QVariantMap tooltipData)
|
||||
|
||||
QString DPAdds::valueByKey(const QString key, int desktop) const
|
||||
{
|
||||
qCDebug(LOG_DP) << "Requested key" << key;
|
||||
qCDebug(LOG_DP) << "Desktop number" << desktop;
|
||||
qCDebug(LOG_DP) << "Requested key" << key << "for desktop" << desktop;
|
||||
if (desktop == -1)
|
||||
desktop = currentDesktop();
|
||||
|
||||
@ -301,6 +299,14 @@ QString DPAdds::getAboutText(const QString type) const
|
||||
.arg(trdPartyList.at(i).split(QChar(',')).at(1))
|
||||
.arg(trdPartyList.at(i).split(QChar(',')).at(2));
|
||||
text = i18n("This software uses: %1", trdPartyList.join(QString(", ")));
|
||||
} else if (type == QString("thanks")) {
|
||||
QStringList thanks = QString(SPECIAL_THANKS)
|
||||
.split(QChar(';'), QString::SkipEmptyParts);
|
||||
for (int i = 0; i < thanks.count(); i++)
|
||||
thanks[i] = QString("<a href=\"%2\">%1</a>")
|
||||
.arg(thanks.at(i).split(QChar(','))[0])
|
||||
.arg(thanks.at(i).split(QChar(','))[1]);
|
||||
text = i18n("Special thanks to %1", thanks.join(QString(", ")));
|
||||
}
|
||||
|
||||
return text;
|
||||
@ -328,8 +334,7 @@ QVariantMap DPAdds::getFont(const QVariantMap defaultFont) const
|
||||
// to avoid additional object definition this method is static
|
||||
void DPAdds::sendNotification(const QString eventId, const QString message)
|
||||
{
|
||||
qCDebug(LOG_DP) << "Event" << eventId;
|
||||
qCDebug(LOG_DP) << "Message" << message;
|
||||
qCDebug(LOG_DP) << "Event" << eventId << "with message" << message;
|
||||
|
||||
KNotification *notification = KNotification::event(
|
||||
eventId, QString("Desktop Panel ::: %1").arg(eventId), message);
|
||||
@ -355,7 +360,7 @@ DPAdds::DesktopWindowsInfo DPAdds::getInfoByDesktop(const int desktop) const
|
||||
DesktopWindowsInfo info;
|
||||
info.desktop = KWindowSystem::workArea(desktop);
|
||||
|
||||
foreach (WId id, KWindowSystem::windows()) {
|
||||
for (auto id : KWindowSystem::windows()) {
|
||||
KWindowInfo winInfo = KWindowInfo(
|
||||
id, NET::Property::WMDesktop | NET::Property::WMGeometry
|
||||
| NET::Property::WMState | NET::Property::WMWindowType
|
||||
|
@ -34,7 +34,7 @@ ExtendedSysMon::ExtendedSysMon(QObject *parent, const QVariantList &args)
|
||||
Q_UNUSED(args)
|
||||
qSetMessagePattern(LOG_FORMAT);
|
||||
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
|
||||
foreach (const QString metadata, getBuildData())
|
||||
for (auto metadata : getBuildData())
|
||||
qCDebug(LOG_ESM) << metadata;
|
||||
|
||||
setMinimumPollingInterval(333);
|
||||
@ -42,7 +42,7 @@ ExtendedSysMon::ExtendedSysMon(QObject *parent, const QVariantList &args)
|
||||
|
||||
// init aggregator
|
||||
aggregator = new ExtSysMonAggregator(this, configuration);
|
||||
foreach (QString source, aggregator->sources())
|
||||
for (auto source : aggregator->sources())
|
||||
setData(source, aggregator->initialData(source));
|
||||
}
|
||||
|
||||
@ -177,7 +177,7 @@ ExtendedSysMon::updateConfiguration(QHash<QString, QString> rawConfig) const
|
||||
QChar(','), QString::SkipEmptyParts);
|
||||
QStringList devices;
|
||||
QRegExp diskRegexp = QRegExp("^/dev/[hms]d[a-z]$");
|
||||
foreach (QString device, deviceList)
|
||||
for (auto device : deviceList)
|
||||
if ((QFile::exists(device)) && (device.contains(diskRegexp)))
|
||||
devices.append(device);
|
||||
if (devices.isEmpty())
|
||||
@ -194,7 +194,7 @@ ExtendedSysMon::updateConfiguration(QHash<QString, QString> rawConfig) const
|
||||
if (rawConfig[QString("PLAYERSYMBOLS")].toInt() <= 0)
|
||||
rawConfig[QString("PLAYERSYMBOLS")] = QString("10");
|
||||
|
||||
foreach (QString key, rawConfig.keys())
|
||||
for (auto key : rawConfig.keys())
|
||||
qCInfo(LOG_ESM) << key << "=" << rawConfig[key];
|
||||
return rawConfig;
|
||||
}
|
||||
|
@ -91,37 +91,37 @@ void ExtSysMonAggregator::init(const QHash<QString, QString> config)
|
||||
// battery
|
||||
AbstractExtSysMonSource *batteryItem
|
||||
= new BatterySource(this, QStringList() << config[QString("ACPIPATH")]);
|
||||
foreach (QString source, batteryItem->sources())
|
||||
for (auto source : batteryItem->sources())
|
||||
m_map[source] = batteryItem;
|
||||
// custom
|
||||
AbstractExtSysMonSource *customItem = new CustomSource(this, QStringList());
|
||||
foreach (QString source, customItem->sources())
|
||||
for (auto source : customItem->sources())
|
||||
m_map[source] = customItem;
|
||||
// desktop
|
||||
AbstractExtSysMonSource *desktopItem
|
||||
= new DesktopSource(this, QStringList());
|
||||
foreach (QString source, desktopItem->sources())
|
||||
for (auto source : desktopItem->sources())
|
||||
m_map[source] = desktopItem;
|
||||
// gpu load
|
||||
AbstractExtSysMonSource *gpuLoadItem
|
||||
= new GPULoadSource(this, QStringList() << config[QString("GPUDEV")]);
|
||||
foreach (QString source, gpuLoadItem->sources())
|
||||
for (auto source : gpuLoadItem->sources())
|
||||
m_map[source] = gpuLoadItem;
|
||||
// gpu temperature
|
||||
AbstractExtSysMonSource *gpuTempItem = new GPUTemperatureSource(
|
||||
this, QStringList() << config[QString("GPUDEV")]);
|
||||
foreach (QString source, gpuTempItem->sources())
|
||||
for (auto source : gpuTempItem->sources())
|
||||
m_map[source] = gpuTempItem;
|
||||
// hdd temperature
|
||||
AbstractExtSysMonSource *hddTempItem = new HDDTemperatureSource(
|
||||
this, QStringList() << config[QString("HDDDEV")]
|
||||
<< config[QString("HDDTEMPCMD")]);
|
||||
foreach (QString source, hddTempItem->sources())
|
||||
for (auto source : hddTempItem->sources())
|
||||
m_map[source] = hddTempItem;
|
||||
// network
|
||||
AbstractExtSysMonSource *networkItem
|
||||
= new NetworkSource(this, QStringList());
|
||||
foreach (QString source, networkItem->sources())
|
||||
for (auto source : networkItem->sources())
|
||||
m_map[source] = networkItem;
|
||||
// player
|
||||
AbstractExtSysMonSource *playerItem = new PlayerSource(
|
||||
@ -129,35 +129,35 @@ void ExtSysMonAggregator::init(const QHash<QString, QString> config)
|
||||
<< config[QString("PLAYER")] << config[QString("MPDADDRESS")]
|
||||
<< config[QString("MPDPORT")] << config[QString("MPRIS")]
|
||||
<< config[QString("PLAYERSYMBOLS")]);
|
||||
foreach (QString source, playerItem->sources())
|
||||
for (auto source : playerItem->sources())
|
||||
m_map[source] = playerItem;
|
||||
// processes
|
||||
AbstractExtSysMonSource *processesItem
|
||||
= new ProcessesSource(this, QStringList());
|
||||
foreach (QString source, processesItem->sources())
|
||||
for (auto source : processesItem->sources())
|
||||
m_map[source] = processesItem;
|
||||
// quotes
|
||||
AbstractExtSysMonSource *quotesItem = new QuotesSource(this, QStringList());
|
||||
foreach (QString source, quotesItem->sources())
|
||||
for (auto source : quotesItem->sources())
|
||||
m_map[source] = quotesItem;
|
||||
// update
|
||||
AbstractExtSysMonSource *updateItem = new UpdateSource(this, QStringList());
|
||||
foreach (QString source, updateItem->sources())
|
||||
for (auto source : updateItem->sources())
|
||||
m_map[source] = updateItem;
|
||||
// upgrade
|
||||
AbstractExtSysMonSource *upgradeItem
|
||||
= new UpgradeSource(this, QStringList());
|
||||
foreach (QString source, upgradeItem->sources())
|
||||
for (auto source : upgradeItem->sources())
|
||||
m_map[source] = upgradeItem;
|
||||
// weather
|
||||
AbstractExtSysMonSource *weatherItem
|
||||
= new WeatherSource(this, QStringList());
|
||||
foreach (QString source, weatherItem->sources())
|
||||
for (auto source : weatherItem->sources())
|
||||
m_map[source] = weatherItem;
|
||||
#ifdef BUILD_TESTING
|
||||
// additional load source
|
||||
AbstractExtSysMonSource *loadItem = new LoadSource(this, QStringList());
|
||||
foreach (QString source, loadItem->sources())
|
||||
for (auto source : loadItem->sources())
|
||||
m_map[source] = loadItem;
|
||||
#endif /* BUILD_TESTING */
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ QStringList CustomSource::sources() const
|
||||
QStringList CustomSource::getSources()
|
||||
{
|
||||
QStringList sources;
|
||||
foreach (ExtScript *item, extScripts->activeItems())
|
||||
for (auto item : extScripts->activeItems())
|
||||
sources.append(QString("custom/%1").arg(item->tag(QString("custom"))));
|
||||
|
||||
return sources;
|
||||
|
@ -61,8 +61,8 @@ QVariant GPULoadSource::data(QString source)
|
||||
QString qoutput
|
||||
= QTextCodec::codecForMib(106)->toUnicode(process.output).trimmed();
|
||||
if (m_device == QString("nvidia")) {
|
||||
foreach (QString str,
|
||||
qoutput.split(QChar('\n'), QString::SkipEmptyParts)) {
|
||||
for (auto str :
|
||||
qoutput.split(QChar('\n'), QString::SkipEmptyParts)) {
|
||||
if (!str.contains(QString("<gpu_util>")))
|
||||
continue;
|
||||
QString load = str.remove(QString("<gpu_util>"))
|
||||
@ -72,8 +72,8 @@ QVariant GPULoadSource::data(QString source)
|
||||
break;
|
||||
}
|
||||
} else if (m_device == QString("ati")) {
|
||||
foreach (QString str,
|
||||
qoutput.split(QChar('\n'), QString::SkipEmptyParts)) {
|
||||
for (auto str :
|
||||
qoutput.split(QChar('\n'), QString::SkipEmptyParts)) {
|
||||
if (!str.contains(QString("load")))
|
||||
continue;
|
||||
QString load
|
||||
|