Stabilizing commit

* move request timeout settings to the configuration header
* initial support of requiredby dictionary
* add AWPatternFunctions namespace
* improve components communication
* update UI to recent abilities
* rewrite qCDebug messages and update CONTRIBUTING.md accordingly
This commit is contained in:
Evgenii Alekseev 2016-02-01 00:25:28 +07:00
parent c1cf8185a3
commit beb2682b04
31 changed files with 326 additions and 244 deletions

View File

@ -147,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 Available categories should be declared in `awdebug.*` files. The following log
levels should be used: 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. * **info** (`qCInfo()`) - additional information inside methods.
* **warning** (`qCWarning()`) - not critical information, which may be caused by * **warning** (`qCWarning()`) - not critical information, which may be caused by
mistakes in configuration for example. mistakes in configuration for example.
* **error** (`qCError()`) - an error which has been captured in runtime. All errors * **critical** (`qCCritical()`) - a critical error. After this error program may
should have own callback methods.
* **critical** (`qCCritical()`) - a critical error. After this error program will
be terminated. be terminated.
The empty log string (e.g. `qCDebug();`) is not allowed because the method names The empty log string (e.g. `qCDebug();`) is not allowed because the method names

View File

@ -198,7 +198,7 @@ Item {
height: implicitHeight height: implicitHeight
width: parent.width width: parent.width
QtControls.ComboBox { QtControls.ComboBox {
width: parent.width * 1 / 5 width: parent.width * 2 / 5
textRole: "label" textRole: "label"
model: [ model: [
{ {
@ -252,11 +252,20 @@ Item {
{ {
'label': i18n("Weathers"), 'label': i18n("Weathers"),
'regexp': "^(weather(Id)?|humidity|pressure|temperature|timestamp)" 'regexp': "^(weather(Id)?|humidity|pressure|temperature|timestamp)"
},
{
'label': i18n("Functions"),
'regexp': "functions"
} }
] ]
onCurrentIndexChanged: { onCurrentIndexChanged: {
if (debug) console.debug() 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"]) if (debug) console.info("Init model", tags.model, "for", model[currentIndex]["label"])
tags.currentIndex = -1 tags.currentIndex = -1
} }
@ -293,18 +302,6 @@ Item {
awActions.sendNotification("tag", message) 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 { Row {

View File

@ -179,8 +179,7 @@ QVariantMap AWActions::getFont(const QVariantMap defaultFont) const
// to avoid additional object definition this method is static // to avoid additional object definition this method is static
void AWActions::sendNotification(const QString eventId, const QString message) void AWActions::sendNotification(const QString eventId, const QString message)
{ {
qCDebug(LOG_AW) << "Event" << eventId; qCDebug(LOG_AW) << "Event" << eventId << "with message" << message;
qCDebug(LOG_AW) << "Message" << message;
KNotification *notification = KNotification::event( KNotification *notification = KNotification::event(
eventId, QString("Awesome Widget ::: %1").arg(eventId), message); eventId, QString("Awesome Widget ::: %1").arg(eventId), message);
@ -229,9 +228,8 @@ void AWActions::showUpdates(const QString version) const
void AWActions::versionReplyRecieved(QNetworkReply *reply, void AWActions::versionReplyRecieved(QNetworkReply *reply,
const bool showAnyway) const const bool showAnyway) const
{ {
qCDebug(LOG_AW) << "Return code" << reply->error(); qCDebug(LOG_AW) << "Return code" << reply->error() << "with message"
qCDebug(LOG_AW) << "Reply error message" << reply->errorString(); << reply->errorString() << "and show anyway" << showAnyway;
qCDebug(LOG_AW) << "Show anyway" << showAnyway;
QJsonParseError error; QJsonParseError error;
QJsonDocument jsonDoc = QJsonDocument::fromJson(reply->readAll(), &error); QJsonDocument jsonDoc = QJsonDocument::fromJson(reply->readAll(), &error);

View File

@ -216,9 +216,8 @@ void AWConfigHelper::copyExtensions(const QString item, const QString type,
QSettings &settings, QSettings &settings,
const bool inverse) const const bool inverse) const
{ {
qCDebug(LOG_AW) << "Extension" << item; qCDebug(LOG_AW) << "Extension" << item << "has type" << type
qCDebug(LOG_AW) << "Type" << type; << "inverse copying" << inverse;
qCDebug(LOG_AW) << "Inverse" << inverse;
settings.beginGroup(item); settings.beginGroup(item);
QSettings itemSettings( QSettings itemSettings(
@ -247,8 +246,7 @@ void AWConfigHelper::copySettings(QSettings &from, QSettings &to) const
void AWConfigHelper::readFile(QSettings &settings, const QString key, void AWConfigHelper::readFile(QSettings &settings, const QString key,
const QString fileName) const const QString fileName) const
{ {
qCDebug(LOG_AW) << "Key" << key; qCDebug(LOG_AW) << "Key" << key << "from file" << fileName;
qCDebug(LOG_AW) << "File" << fileName;
QFile file(fileName); QFile file(fileName);
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { 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, void AWConfigHelper::writeFile(QSettings &settings, const QString key,
const QString fileName) const const QString fileName) const
{ {
qCDebug(LOG_AW) << "Key" << key; qCDebug(LOG_AW) << "Key" << key << "to file" << fileName;
qCDebug(LOG_AW) << "File" << fileName;
if (!settings.contains(key)) if (!settings.contains(key))
return; return;

View File

@ -90,7 +90,7 @@ void AWDataAggregator::setParameters(QVariantMap settings)
counts += configuration[QString("downTooltip")].toInt(); counts += configuration[QString("downTooltip")].toInt();
counts += configuration[QString("batTooltip")].toInt(); counts += configuration[QString("batTooltip")].toInt();
// resize tooltip image // resize tooltip image
toolTipView->resize(100.0 * counts, 105.0); toolTipView->resize(100 * counts, 105);
boundaries[QString("cpuTooltip")] = 100.0; boundaries[QString("cpuTooltip")] = 100.0;
boundaries[QString("cpuclTooltip")] = 4000.0; boundaries[QString("cpuclTooltip")] = 4000.0;
@ -179,9 +179,8 @@ void AWDataAggregator::dataUpdate(const QHash<QString, QString> &values)
void AWDataAggregator::checkValue(const QString source, const float value, void AWDataAggregator::checkValue(const QString source, const float value,
const float extremum) const const float extremum) const
{ {
qCDebug(LOG_AW) << "Notification source" << source; qCDebug(LOG_AW) << "Notification source" << source << "with value" << value
qCDebug(LOG_AW) << "Value" << value; << "called with extremum" << extremum;
qCDebug(LOG_AW) << "Called with extremum" << extremum;
if (value >= 0.0) { if (value >= 0.0) {
if ((m_enablePopup) && (value > extremum) 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, void AWDataAggregator::checkValue(const QString source, const QString current,
const QString received) const const QString received) const
{ {
qCDebug(LOG_AW) << "Notification source" << source; qCDebug(LOG_AW) << "Notification source" << source << "with current value"
qCDebug(LOG_AW) << "Current value" << current; << current << "and received one" << received;
qCDebug(LOG_AW) << "Received value" << received;
if ((m_enablePopup) && (current != received) && (!received.isEmpty())) if ((m_enablePopup) && (current != received) && (!received.isEmpty()))
return AWActions::sendNotification(QString("event"), return AWActions::sendNotification(QString("event"),
@ -225,8 +223,7 @@ void AWDataAggregator::initScene()
QString AWDataAggregator::notificationText(const QString source, QString AWDataAggregator::notificationText(const QString source,
const float value) const const float value) const
{ {
qCDebug(LOG_AW) << "Notification source" << source; qCDebug(LOG_AW) << "Notification source" << source << "with value" << value;
qCDebug(LOG_AW) << "Value" << value;
QString output; QString output;
if (source == QString("batTooltip")) if (source == QString("batTooltip"))
@ -247,8 +244,7 @@ QString AWDataAggregator::notificationText(const QString source,
QString AWDataAggregator::notificationText(const QString source, QString AWDataAggregator::notificationText(const QString source,
const QString value) const const QString value) const
{ {
qCDebug(LOG_AW) << "Notification source" << source; qCDebug(LOG_AW) << "Notification source" << source << "with value" << value;
qCDebug(LOG_AW) << "Value" << value;
QString output; QString output;
if (source == QString("netdev")) if (source == QString("netdev"))
@ -287,9 +283,8 @@ void AWDataAggregator::setData(const QHash<QString, QString> &values)
void AWDataAggregator::setData(const QString &source, float value, void AWDataAggregator::setData(const QString &source, float value,
const float extremum) const float extremum)
{ {
qCDebug(LOG_AW) << "Source" << source; qCDebug(LOG_AW) << "Source" << source << "to value" << value
qCDebug(LOG_AW) << "Value" << value; << "with extremum" << extremum;
qCDebug(LOG_AW) << "Called with extremum" << extremum;
if (data[source].count() == 0) if (data[source].count() == 0)
data[source].append(0.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, void AWDataAggregator::setData(const bool dontInvert, const QString &source,
float value) float value)
{ {
qCDebug(LOG_AW) << "Do not invert value" << dontInvert; qCDebug(LOG_AW) << "Do not invert" << dontInvert << "value" << value
qCDebug(LOG_AW) << "Source" << source; << "for source" << source;
qCDebug(LOG_AW) << "Value" << value;
// invert values for different battery colours // invert values for different battery colours
value = dontInvert ? value : -value; value = dontInvert ? value : -value;

View File

@ -45,9 +45,9 @@ AWDataEngineAggregator::~AWDataEngineAggregator()
void AWDataEngineAggregator::disconnectSources() void AWDataEngineAggregator::disconnectSources()
{ {
for (auto dataengine : m_dataEngines.keys()) for (auto dataengine : m_dataEngines.values())
for (auto source : m_dataEngines[dataengine]->sources()) for (auto source : dataengine->sources())
m_dataEngines[dataengine]->disconnectSource(source, parent()); dataengine->disconnectSource(source, parent());
} }
@ -93,7 +93,7 @@ void AWDataEngineAggregator::initDataEngines()
// additional method required by systemmonitor structure // additional method required by systemmonitor structure
connect(m_dataEngines[QString("systemmonitor")], connect(m_dataEngines[QString("systemmonitor")],
&Plasma::DataEngine::sourceAdded, [this](const QString source) { &Plasma::DataEngine::sourceAdded, [this](const QString source) {
static_cast<AWKeys *>(parent())->addDevice(source); emit(deviceAdded(source));
m_dataEngines[QString("systemmonitor")]->connectSource( m_dataEngines[QString("systemmonitor")]->connectSource(
source, parent(), m_interval); source, parent(), m_interval);
}); });

View File

@ -38,6 +38,9 @@ public:
// properties // properties
void setInterval(const int _interval); void setInterval(const int _interval);
signals:
void deviceAdded(const QString &source);
public slots: public slots:
void dropSource(const QString source); void dropSource(const QString source);
void reconnectSources(); void reconnectSources();

View File

@ -21,6 +21,7 @@
#include "awactions.h" #include "awactions.h"
#include "awconfighelper.h" #include "awconfighelper.h"
#include "awdataengineaggregator.h"
#include "awkeys.h" #include "awkeys.h"

View File

@ -26,10 +26,9 @@
#include "awdebug.h" #include "awdebug.h"
void AWKeyCache::addKeyToCache(const QString type, const QString key) bool AWKeyCache::addKeyToCache(const QString type, const QString key)
{ {
qCDebug(LOG_AW) << "Key type" << type; qCDebug(LOG_AW) << "Key" << key << "with type" << type;
qCDebug(LOG_AW) << "Key" << key;
QString fileName = QString("%1/awesomewidgets.ndx") QString fileName = QString("%1/awesomewidgets.ndx")
.arg(QStandardPaths::writableLocation( .arg(QStandardPaths::writableLocation(
@ -70,7 +69,7 @@ void AWKeyCache::addKeyToCache(const QString type, const QString key)
} }
} else { } else {
if (cachedValues.contains(key)) if (cachedValues.contains(key))
return; return false;
qCInfo(LOG_AW) << "Found new key" << key << "for type" << type; qCInfo(LOG_AW) << "Found new key" << key << "for type" << type;
cache.setValue( cache.setValue(
QString("%1").arg(cache.allKeys().count(), 3, 10, QChar('0')), key); QString("%1").arg(cache.allKeys().count(), 3, 10, QChar('0')), key);
@ -78,6 +77,7 @@ void AWKeyCache::addKeyToCache(const QString type, const QString key)
cache.endGroup(); cache.endGroup();
cache.sync(); cache.sync();
return true;
} }

View File

@ -25,7 +25,7 @@
namespace AWKeyCache namespace AWKeyCache
{ {
void addKeyToCache(const QString type, const QString key = QString("")); bool addKeyToCache(const QString type, const QString key = QString(""));
QHash<QString, QStringList> loadKeysFromCache(); QHash<QString, QStringList> loadKeysFromCache();
}; };

View File

@ -54,28 +54,6 @@ AWKeyOperations::~AWKeyOperations()
} }
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);
}
}
QStringList AWKeyOperations::devices(const QString type) const QStringList AWKeyOperations::devices(const QString type) const
{ {
qCDebug(LOG_AW) << "Looking for type" << type; qCDebug(LOG_AW) << "Looking for type" << type;
@ -259,6 +237,8 @@ QStringList AWKeyOperations::dictKeys() const
} }
// this method is required to provide GraphicalItem functions (e.g. paint()) to
// parent classes
GraphicalItem *AWKeyOperations::giByKey(const QString key) const GraphicalItem *AWKeyOperations::giByKey(const QString key) const
{ {
qCDebug(LOG_AW) << "Looking for item" << key; qCDebug(LOG_AW) << "Looking for item" << key;
@ -355,14 +335,36 @@ void AWKeyOperations::editItem(const QString type)
} }
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) void AWKeyOperations::addKeyToCache(const QString type, const QString key)
{ {
qCDebug(LOG_AW) << "Key type" << type; qCDebug(LOG_AW) << "Key" << key << "with type" << type;
qCDebug(LOG_AW) << "Key" << key;
AWKeyCache::addKeyToCache(type, key); if (AWKeyCache::addKeyToCache(type, key)) {
m_devices = AWKeyCache::loadKeysFromCache(); m_devices = AWKeyCache::loadKeysFromCache();
reinitKeys(); reinitKeys();
}
} }
@ -391,17 +393,8 @@ void AWKeyOperations::reinitKeys()
// init // init
QStringList allKeys = dictKeys(); QStringList allKeys = dictKeys();
#ifdef BUILD_TESTING
// not documented feature - place all available tags
m_pattern = m_pattern.replace(QString("$ALL"), [allKeys]() {
QStringList strings;
for (auto tag : allKeys)
strings.append(QString("%1: $%1").arg(tag));
return strings.join(QString(" | "));
}());
#endif /* BUILD_TESTING */
// apply aw_* functions // apply aw_* functions
m_pattern = AWPatternFunctions::insertAllKeys(m_pattern, allKeys);
m_pattern = AWPatternFunctions::insertKeyCount(m_pattern, allKeys); m_pattern = AWPatternFunctions::insertKeyCount(m_pattern, allKeys);
m_pattern = AWPatternFunctions::insertKeyNames(m_pattern, allKeys); m_pattern = AWPatternFunctions::insertKeyNames(m_pattern, allKeys);
m_pattern = AWPatternFunctions::insertKeys(m_pattern, allKeys); m_pattern = AWPatternFunctions::insertKeys(m_pattern, allKeys);

View File

@ -45,7 +45,6 @@ class AWKeyOperations : public QObject
public: public:
explicit AWKeyOperations(QObject *parent = nullptr); explicit AWKeyOperations(QObject *parent = nullptr);
virtual ~AWKeyOperations(); virtual ~AWKeyOperations();
void addDevice(const QString source);
QStringList devices(const QString type) const; QStringList devices(const QString type) const;
QHash<QString, QStringList> devices() const; QHash<QString, QStringList> devices() const;
void updateCache(); void updateCache();
@ -62,6 +61,9 @@ public:
signals: signals:
void updateKeys(const QStringList currentKeys); void updateKeys(const QStringList currentKeys);
public slots:
void addDevice(const QString &source);
private: private:
// methods // methods
void addKeyToCache(const QString type, const QString key = QString("")); void addKeyToCache(const QString type, const QString key = QString(""));

View File

@ -27,6 +27,7 @@
#include "awdebug.h" #include "awdebug.h"
#include "awkeyoperations.h" #include "awkeyoperations.h"
#include "awkeysaggregator.h" #include "awkeysaggregator.h"
#include "awpatternfunctions.h"
#include "graphicalitem.h" #include "graphicalitem.h"
#include "version.h" #include "version.h"
@ -79,9 +80,8 @@ void AWKeys::initDataAggregator(const QVariantMap tooltipParams)
void AWKeys::initKeys(const QString currentPattern, const int interval, void AWKeys::initKeys(const QString currentPattern, const int interval,
const int limit) const int limit)
{ {
qCDebug(LOG_AW) << "Pattern" << currentPattern; qCDebug(LOG_AW) << "Pattern" << currentPattern << "with interval"
qCDebug(LOG_AW) << "Interval" << interval; << interval << "and queue limit" << limit;
qCDebug(LOG_AW) << "Queue limit" << limit;
// init // init
keyOperator->setPattern(currentPattern); keyOperator->setPattern(currentPattern);
@ -89,6 +89,9 @@ void AWKeys::initKeys(const QString currentPattern, const int interval,
dataEngineAggregator = new AWDataEngineAggregator(this, interval); dataEngineAggregator = new AWDataEngineAggregator(this, interval);
connect(this, SIGNAL(dropSourceFromDataengine(QString)), connect(this, SIGNAL(dropSourceFromDataengine(QString)),
dataEngineAggregator, SLOT(dropSource(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 } else
dataEngineAggregator->setInterval(interval); dataEngineAggregator->setInterval(interval);
m_threadPool->setMaxThreadCount(limit == 0 ? QThread::idealThreadCount() m_threadPool->setMaxThreadCount(limit == 0 ? QThread::idealThreadCount()
@ -101,8 +104,7 @@ void AWKeys::initKeys(const QString currentPattern, const int interval,
void AWKeys::setAggregatorProperty(const QString key, const QVariant value) void AWKeys::setAggregatorProperty(const QString key, const QVariant value)
{ {
qCDebug(LOG_AW) << "Key" << key; qCDebug(LOG_AW) << "Key" << key << "with value" << value;
qCDebug(LOG_AW) << "Value" << value;
aggregator->setProperty(key.toUtf8().constData(), value); aggregator->setProperty(key.toUtf8().constData(), value);
} }
@ -124,8 +126,8 @@ void AWKeys::updateCache()
QStringList AWKeys::dictKeys(const bool sorted, const QString regexp) const QStringList AWKeys::dictKeys(const bool sorted, const QString regexp) const
{ {
qCDebug(LOG_AW) << "Should be sorted" << sorted; qCDebug(LOG_AW) << "Should be sorted" << sorted << "and filter applied"
qCDebug(LOG_AW) << "Filter" << regexp; << regexp;
QStringList allKeys = keyOperator->dictKeys(); QStringList allKeys = keyOperator->dictKeys();
// sort if required // sort if required
@ -149,7 +151,7 @@ QStringList AWKeys::getHddDevices() const
QString AWKeys::infoByKey(QString key) const QString AWKeys::infoByKey(QString key) const
{ {
qCDebug(LOG_AW) << "Requested key" << key; qCDebug(LOG_AW) << "Requested info for key" << key;
return keyOperator->infoByKey(key); return keyOperator->infoByKey(key);
} }
@ -158,7 +160,7 @@ QString AWKeys::infoByKey(QString key) const
// HACK this method requires to define tag value from bar from UI interface // HACK this method requires to define tag value from bar from UI interface
QString AWKeys::valueByKey(QString key) const 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,}"))), return values.value(key.remove(QRegExp(QString("^bar[0-9]{1,}"))),
QString("")); QString(""));
@ -173,14 +175,6 @@ void AWKeys::editItem(const QString type)
} }
void AWKeys::addDevice(const QString source)
{
qCDebug(LOG_AW) << "Source" << source;
return keyOperator->addDevice(source);
}
void AWKeys::dataUpdated(const QString &sourceName, void AWKeys::dataUpdated(const QString &sourceName,
const Plasma::DataEngine::Data &data) const Plasma::DataEngine::Data &data)
{ {
@ -201,58 +195,11 @@ void AWKeys::reinitKeys(const QStringList currentKeys)
qCDebug(LOG_AW) << "Update found keys by using list" << currentKeys; qCDebug(LOG_AW) << "Update found keys by using list" << currentKeys;
// append lists // append lists
// bars m_foundBars
m_foundBars = [currentKeys](const QString pattern) { = AWPatternFunctions::findBars(keyOperator->pattern(), currentKeys);
QStringList selectedKeys; m_foundKeys
for (auto key : currentKeys) = AWPatternFunctions::findKeys(keyOperator->pattern(), currentKeys);
if ((key.startsWith(QString("bar"))) m_foundLambdas = AWPatternFunctions::findLambdas(keyOperator->pattern());
&& (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;
}(keyOperator->pattern());
// main key list
m_foundKeys = [currentKeys](const QString pattern) {
QStringList selectedKeys;
for (auto key : currentKeys)
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;
}(keyOperator->pattern());
// lambdas
m_foundLambdas = [](const 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 brackets
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;
}(keyOperator->pattern());
// set key data to aggregator // set key data to aggregator
aggregator->setDevices(keyOperator->devices()); aggregator->setDevices(keyOperator->devices());
@ -354,7 +301,7 @@ void AWKeys::calculateValues()
QString AWKeys::parsePattern(QString pattern) const QString AWKeys::parsePattern(QString pattern) const
{ {
// screen sign // screen sign
pattern.replace(QString("$$"), QString("$\\$\\")); pattern.replace(QString("$$"), QString(0x1d));
// lambdas // lambdas
for (auto key : m_foundLambdas) for (auto key : m_foundLambdas)
@ -385,7 +332,7 @@ QString AWKeys::parsePattern(QString pattern) const
} }
// prepare strings // prepare strings
pattern.replace(QString("$\\$\\"), QString("$$")); pattern.replace(QString(0x1d), QString("$"));
if (m_wrapNewLines) if (m_wrapNewLines)
pattern.replace(QString("\n"), QString("<br>")); pattern.replace(QString("\n"), QString("<br>"));
@ -395,8 +342,7 @@ QString AWKeys::parsePattern(QString pattern) const
void AWKeys::setDataBySource(const QString &sourceName, const QVariantMap &data) void AWKeys::setDataBySource(const QString &sourceName, const QVariantMap &data)
{ {
qCDebug(LOG_AW) << "Source" << sourceName; qCDebug(LOG_AW) << "Source" << sourceName << "with data" << data;
qCDebug(LOG_AW) << "Data" << data;
// first list init // first list init
QStringList tags = aggregator->keysFromSource(sourceName); QStringList tags = aggregator->keysFromSource(sourceName);
@ -404,21 +350,18 @@ void AWKeys::setDataBySource(const QString &sourceName, const QVariantMap &data)
tags = aggregator->registerSource(sourceName, tags = aggregator->registerSource(sourceName,
data[QString("units")].toString()); 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()) { if (tags.isEmpty()) {
qCDebug(LOG_AW) << "Source" << sourceName << "not found"; qCInfo(LOG_AW) << "Source" << sourceName << "not found";
emit(dropSourceFromDataengine(sourceName)); return emit(dropSourceFromDataengine(sourceName));
} else {
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();
} }
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();
} }

View File

@ -58,7 +58,6 @@ public:
Q_INVOKABLE void editItem(const QString type); Q_INVOKABLE void editItem(const QString type);
public slots: public slots:
void addDevice(const QString source);
void dataUpdated(const QString &sourceName, void dataUpdated(const QString &sourceName,
const Plasma::DataEngine::Data &data); const Plasma::DataEngine::Data &data);
// dummy method required by DataEngine connections // dummy method required by DataEngine connections

View File

@ -42,8 +42,7 @@ AWKeysAggregator::~AWKeysAggregator()
QString AWKeysAggregator::formater(const QVariant &data, QString AWKeysAggregator::formater(const QVariant &data,
const QString &key) const const QString &key) const
{ {
qCDebug(LOG_AW) << "Data" << data; qCDebug(LOG_AW) << "Data" << data << "for key" << key;
qCDebug(LOG_AW) << "Key" << key;
QString output; QString output;
QLocale loc = m_translate ? QLocale::system() : QLocale::c(); QLocale loc = m_translate ? QLocale::system() : QLocale::c();
@ -135,7 +134,7 @@ QString AWKeysAggregator::formater(const QVariant &data,
return source; return source;
}(m_formater[key] == Uptime ? QString("$ddd$hhh$mmm") }(m_formater[key] == Uptime ? QString("$ddd$hhh$mmm")
: m_customUptime, : m_customUptime,
data.toFloat()); static_cast<int>(data.toFloat()));
break; break;
case NoFormat: case NoFormat:
default: 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) void AWKeysAggregator::setAcOffline(const QString inactive)
{ {
qCDebug(LOG_AW) << "Inactive AC string" << inactive; qCDebug(LOG_AW) << "Inactive AC string" << inactive;
@ -216,8 +224,7 @@ void AWKeysAggregator::setTranslate(const bool translate)
QStringList AWKeysAggregator::registerSource(const QString &source, QStringList AWKeysAggregator::registerSource(const QString &source,
const QString &units) const QString &units)
{ {
qCDebug(LOG_AW) << "Source" << source; qCDebug(LOG_AW) << "Source" << source << "with units" << units;
qCDebug(LOG_AW) << "Units" << units;
// regular expressions // regular expressions
QRegExp cpuRegExp = QRegExp(QString("cpu/cpu.*/TotalLoad")); QRegExp cpuRegExp = QRegExp(QString("cpu/cpu.*/TotalLoad"));
@ -331,6 +338,11 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
key = QString("hddfreegb%1").arg(index); key = QString("hddfreegb%1").arg(index);
m_map.insertMulti(source, key); m_map.insertMulti(source, key);
m_formater[key] = MemGBFormat; 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)) { } else if (source.contains(mountUsedRegExp)) {
// used // used
@ -346,6 +358,11 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
key = QString("hddgb%1").arg(index); key = QString("hddgb%1").arg(index);
m_map.insertMulti(source, key); m_map.insertMulti(source, key);
m_formater[key] = MemGBFormat; 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"))) { } else if (source.startsWith(QString("hdd/temperature"))) {
// hdd temperature // hdd temperature
@ -372,6 +389,8 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
// gb // gb
m_map.insertMulti(source, QString("memgb")); m_map.insertMulti(source, QString("memgb"));
m_formater[QString("memgb")] = MemGBFormat; m_formater[QString("memgb")] = MemGBFormat;
// fill required by list
m_requiredByMap.insertMulti(source, QString("mem"));
} else if (source == QString("mem/physical/free")) { } else if (source == QString("mem/physical/free")) {
// free memory // free memory
// mb // mb
@ -380,6 +399,10 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
// gb // gb
m_map.insertMulti(source, QString("memfreegb")); m_map.insertMulti(source, QString("memfreegb"));
m_formater[QString("memfreegb")] = MemGBFormat; 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")) { } else if (source == QString("mem/physical/used")) {
// used memory // used memory
// mb // mb
@ -388,10 +411,21 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
// gb // gb
m_map.insertMulti(source, QString("memusedgb")); m_map.insertMulti(source, QString("memusedgb"));
m_formater[QString("memusedgb")] = MemGBFormat; 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")) { } else if (source == QString("network/current/name")) {
// network device // network device
m_map[source] = QString("netdev"); m_map[source] = QString("netdev");
m_formater[QString("netdev")] = NoFormat; 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)) { } else if (source.contains(netRegExp)) {
// network speed // network speed
QString type = source.contains(QString("receiver")) ? QString("down") QString type = source.contains(QString("receiver")) ? QString("down")
@ -412,6 +446,13 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
m_map.insertMulti(source, key); m_map.insertMulti(source, key);
m_formater[key] = NetSmartUnits; 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"))) { } else if (source.startsWith(QString("upgrade"))) {
// package manager // package manager
QString key = source; QString key = source;
@ -450,6 +491,10 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
// gb // gb
m_map.insertMulti(source, QString("swapfreegb")); m_map.insertMulti(source, QString("swapfreegb"));
m_formater[QString("swapfreegb")] = MemGBFormat; 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")) { } else if (source == QString("mem/swap/used")) {
// used swap // used swap
// mb // mb
@ -458,6 +503,10 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
// gb // gb
m_map.insertMulti(source, QString("swapgb")); m_map.insertMulti(source, QString("swapgb"));
m_formater[QString("swapgb")] = MemGBFormat; 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/"))) { } else if (source.startsWith(QString("lmsensors/"))) {
// temperature // temperature
int index = m_devices[QString("temp")].indexOf(source); int index = m_devices[QString("temp")].indexOf(source);

View File

@ -67,6 +67,7 @@ public:
// get methods // get methods
QString formater(const QVariant &data, const QString &key) const; QString formater(const QVariant &data, const QString &key) const;
QStringList keysFromSource(const QString &source) const; QStringList keysFromSource(const QString &source) const;
QStringList requiredByKeysFromSource(const QString &source) const;
// set methods // set methods
void setAcOffline(const QString inactive); void setAcOffline(const QString inactive);
void setAcOnline(const QString active); void setAcOnline(const QString active);
@ -90,6 +91,7 @@ private:
QHash<QString, QStringList> m_devices; QHash<QString, QStringList> m_devices;
QHash<QString, FormaterType> m_formater; QHash<QString, FormaterType> m_formater;
QHash<QString, QString> m_map; QHash<QString, QString> m_map;
QHash<QString, QString> m_requiredByMap;
QString m_tempUnits; QString m_tempUnits;
bool m_translate = false; bool m_translate = false;
}; };

View File

@ -28,8 +28,15 @@ QVariantList AWPatternFunctions::findFunctionCalls(const QString function,
{ {
qCDebug(LOG_AW) << "Looking for function" << function << "in" << 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( QRegularExpression regex(
QString("%1\\<(?<args>.*?)\\>\\((?<body>.*?)\\)").arg(function)); QString("\\$%1\\<(?<args>.*?)\\>\\{\\{(?<body>.*?)\\}\\}")
.arg(function));
regex.setPatternOptions(QRegularExpression::DotMatchesEverythingOption); regex.setPatternOptions(QRegularExpression::DotMatchesEverythingOption);
QVariantList foundFunctions; QVariantList foundFunctions;
@ -38,8 +45,20 @@ QVariantList AWPatternFunctions::findFunctionCalls(const QString function,
QRegularExpressionMatch match = it.next(); QRegularExpressionMatch match = it.next();
QVariantHash metadata; QVariantHash metadata;
metadata[QString("args")] // work with args
= match.captured(QString("args")).split(QChar(',')); 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("body")] = match.captured(QString("body"));
metadata[QString("what")] = match.captured(); metadata[QString("what")] = match.captured();
foundFunctions.append(metadata); foundFunctions.append(metadata);
@ -51,27 +70,22 @@ QVariantList AWPatternFunctions::findFunctionCalls(const QString function,
QString AWPatternFunctions::expandTemplates(QString code) QString AWPatternFunctions::expandTemplates(QString code)
{ {
qCDebug(LOG_AW) << "Expand tempaltes in" << code; qCDebug(LOG_AW) << "Expand templates in" << code;
// match the following construction $template{{some code here}} // match the following construction $template{{some code here}}
QRegularExpression templatesRegexp( QRegularExpression templatesRegexp(
QString("\\$template\\{\\{((?!\\$template\\{\\{).)*?\\}\\}")); QString("\\$template\\{\\{(?<body>.*?)\\}\\}"));
templatesRegexp.setPatternOptions( templatesRegexp.setPatternOptions(
QRegularExpression::DotMatchesEverythingOption); QRegularExpression::DotMatchesEverythingOption);
QRegularExpressionMatchIterator it = templatesRegexp.globalMatch(code); QRegularExpressionMatchIterator it = templatesRegexp.globalMatch(code);
while (it.hasNext()) { while (it.hasNext()) {
QRegularExpressionMatch match = it.next(); QRegularExpressionMatch match = it.next();
QString fullTemplate = match.captured(); QString body = match.captured(QString("body"));
// drop additional markers
QString templ = fullTemplate;
templ.remove(QRegExp(QString("^\\$template\\{\\{")));
templ.remove(QRegExp(QString("\\}\\}$")));
QJSEngine engine; QJSEngine engine;
qCInfo(LOG_AW) << "Expression" << templ; qCInfo(LOG_AW) << "Expression" << body;
QJSValue result = engine.evaluate(templ); QJSValue result = engine.evaluate(body);
QString templateResult = QString(""); QString templateResult = QString("");
if (result.isError()) { if (result.isError()) {
qCWarning(LOG_AW) << "Uncaught exception at line" qCWarning(LOG_AW) << "Uncaught exception at line"
@ -82,7 +96,34 @@ QString AWPatternFunctions::expandTemplates(QString code)
} }
// replace template // replace template
code.replace(fullTemplate, templateResult); 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; return code;
@ -111,7 +152,7 @@ QString AWPatternFunctions::insertKeyCount(QString code, const QStringList keys)
QString AWPatternFunctions::insertKeyNames(QString code, const QStringList keys) QString AWPatternFunctions::insertKeyNames(QString code, const QStringList keys)
{ {
qCDebug(LOG_AW) << "Looking for keys in code" << code << "using list" qCDebug(LOG_AW) << "Looking for key names in code" << code << "using list"
<< keys; << keys;
QVariantList found QVariantList found
@ -158,3 +199,69 @@ QString AWPatternFunctions::insertKeys(QString code, const QStringList keys)
return code; 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;
}

View File

@ -25,11 +25,17 @@
namespace AWPatternFunctions namespace AWPatternFunctions
{ {
// insert methods
QString expandTemplates(QString code); QString expandTemplates(QString code);
QVariantList findFunctionCalls(const QString function, const 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 insertKeyCount(QString code, const QStringList keys);
QString insertKeyNames(QString code, const QStringList keys); QString insertKeyNames(QString code, const QStringList keys);
QString insertKeys(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);
}; };

View File

@ -33,8 +33,9 @@ AbstractExtItem::AbstractExtItem(QWidget *parent, const QString desktopName,
, m_dirs(directories) , m_dirs(directories)
{ {
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; 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; m_name = m_fileName;
} }

View File

@ -91,10 +91,8 @@ void AbstractExtItemAggregator::setConfigArgs(const QVariant _configArgs)
} }
void AbstractExtItemAggregator::editItemActivated(QListWidgetItem *item) void AbstractExtItemAggregator::editItemActivated(QListWidgetItem *)
{ {
Q_UNUSED(item)
return editItem(); return editItem();
} }

View File

@ -48,7 +48,7 @@ public:
void setConfigArgs(const QVariant _configArgs); void setConfigArgs(const QVariant _configArgs);
private slots: private slots:
void editItemActivated(QListWidgetItem *item); void editItemActivated(QListWidgetItem *);
void editItemButtonPressed(QAbstractButton *button); void editItemButtonPressed(QAbstractButton *button);
private: private:

View File

@ -37,8 +37,9 @@ public:
{ {
qSetMessagePattern(LOG_FORMAT); qSetMessagePattern(LOG_FORMAT);
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
foreach (const QString metadata, getBuildData()) for (auto metadata : getBuildData())
qCDebug(LOG_LIB) << metadata; qCDebug(LOG_LIB) << metadata;
qCDebug(LOG_LIB) << "Type" << type; qCDebug(LOG_LIB) << "Type" << type;
initItems(); initItems();
@ -66,7 +67,7 @@ public:
qCDebug(LOG_LIB) << "Tag" << _tag; qCDebug(LOG_LIB) << "Tag" << _tag;
T *found = nullptr; T *found = nullptr;
foreach (T *item, m_items) { for (auto item : m_items) {
if (item->tag() != _tag) if (item->tag() != _tag)
continue; continue;
found = item; found = item;
@ -83,7 +84,7 @@ public:
qCDebug(LOG_LIB) << "Number" << _number; qCDebug(LOG_LIB) << "Number" << _number;
T *found = nullptr; T *found = nullptr;
foreach (T *item, m_items) { for (auto item : m_items) {
if (item->number() != _number) if (item->number() != _number)
continue; continue;
found = item; found = item;
@ -102,7 +103,7 @@ public:
return nullptr; return nullptr;
T *found = nullptr; T *found = nullptr;
foreach (T *item, m_items) { for (auto item : m_items) {
if (item->fileName() != widgetItem->text()) if (item->fileName() != widgetItem->text())
continue; continue;
found = item; found = item;
@ -120,7 +121,7 @@ public:
int uniqNumber() const int uniqNumber() const
{ {
QList<int> tagList; QList<int> tagList;
foreach (T *item, m_items) for (auto item : m_items)
tagList.append(item->number()); tagList.append(item->number());
int number = 0; int number = 0;
while (tagList.contains(number)) while (tagList.contains(number))
@ -152,9 +153,9 @@ private:
QStandardPaths::LocateDirectory); QStandardPaths::LocateDirectory);
QStringList names; QStringList names;
QList<T *> items; QList<T *> items;
foreach (QString dir, dirs) { for (auto dir : dirs) {
QStringList files = QDir(dir).entryList(QDir::Files, QDir::Name); QStringList files = QDir(dir).entryList(QDir::Files, QDir::Name);
foreach (QString file, files) { for (auto file : files) {
if ((!file.endsWith(QString(".desktop"))) if ((!file.endsWith(QString(".desktop")))
|| (names.contains(file))) || (names.contains(file)))
continue; continue;
@ -177,7 +178,7 @@ private:
m_activeItems.clear(); m_activeItems.clear();
m_items = getItems(); m_items = getItems();
foreach (T *item, m_items) { for (auto item : m_items) {
if (!item->isActive()) if (!item->isActive())
continue; continue;
m_activeItems.append(item); m_activeItems.append(item);
@ -187,7 +188,7 @@ private:
void repaint() void repaint()
{ {
widgetDialog->clear(); widgetDialog->clear();
foreach (T *_item, m_items) { for (auto _item : m_items) {
QListWidgetItem *item QListWidgetItem *item
= new QListWidgetItem(_item->fileName(), widgetDialog); = new QListWidgetItem(_item->fileName(), widgetDialog);
QStringList tooltip; QStringList tooltip;

View File

@ -150,7 +150,7 @@ QVariantHash ExtQuotes::run()
qCInfo(LOG_LIB) << "Send request"; qCInfo(LOG_LIB) << "Send request";
isRunning = true; isRunning = true;
QNetworkReply *reply = manager->get(QNetworkRequest(QUrl(url()))); QNetworkReply *reply = manager->get(QNetworkRequest(QUrl(url())));
new QReplyTimeout(reply, 1000); new QReplyTimeout(reply, REQUEST_TIMEOUT);
} }
// update value // update value
@ -208,8 +208,8 @@ void ExtQuotes::writeConfiguration() const
void ExtQuotes::quotesReplyReceived(QNetworkReply *reply) void ExtQuotes::quotesReplyReceived(QNetworkReply *reply)
{ {
qCDebug(LOG_LIB) << "Return code" << reply->error(); qCDebug(LOG_LIB) << "Return code" << reply->error() << "with message"
qCDebug(LOG_LIB) << "Reply error message" << reply->errorString(); << reply->errorString();
isRunning = false; isRunning = false;
QJsonParseError error; QJsonParseError error;

View File

@ -64,8 +64,7 @@ ExtScript::~ExtScript()
ExtScript *ExtScript::copy(const QString _fileName, const int _number) ExtScript *ExtScript::copy(const QString _fileName, const int _number)
{ {
qCDebug(LOG_LIB) << "File" << _fileName; qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
qCDebug(LOG_LIB) << "Number" << _number;
ExtScript *item = new ExtScript(static_cast<QWidget *>(parent()), _fileName, ExtScript *item = new ExtScript(static_cast<QWidget *>(parent()), _fileName,
directories()); directories());
@ -206,8 +205,7 @@ QString ExtScript::applyFilters(QString _value) const
void ExtScript::updateFilter(const QString _filter, const bool _add) void ExtScript::updateFilter(const QString _filter, const bool _add)
{ {
qCDebug(LOG_LIB) << "Filter" << _filter; qCDebug(LOG_LIB) << "Should be added filters" << _add << "from" << _filter;
qCDebug(LOG_LIB) << "Should be added" << _add;
if (_add) { if (_add) {
if (m_filters.contains(_filter)) if (m_filters.contains(_filter))

View File

@ -60,8 +60,7 @@ ExtUpgrade::~ExtUpgrade()
ExtUpgrade *ExtUpgrade::copy(const QString _fileName, const int _number) ExtUpgrade *ExtUpgrade::copy(const QString _fileName, const int _number)
{ {
qCDebug(LOG_LIB) << "File" << _fileName; qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
qCDebug(LOG_LIB) << "Number" << _number;
ExtUpgrade *item = new ExtUpgrade(static_cast<QWidget *>(parent()), ExtUpgrade *item = new ExtUpgrade(static_cast<QWidget *>(parent()),
_fileName, directories()); _fileName, directories());

View File

@ -74,8 +74,7 @@ ExtWeather::~ExtWeather()
ExtWeather *ExtWeather::copy(const QString _fileName, const int _number) ExtWeather *ExtWeather::copy(const QString _fileName, const int _number)
{ {
qCDebug(LOG_LIB) << "File" << _fileName; qCDebug(LOG_LIB) << "File" << _fileName << "number" << _number;
qCDebug(LOG_LIB) << "Number" << _number;
ExtWeather *item = new ExtWeather(static_cast<QWidget *>(parent()), ExtWeather *item = new ExtWeather(static_cast<QWidget *>(parent()),
_fileName, directories()); _fileName, directories());
@ -236,7 +235,7 @@ QVariantHash ExtWeather::run()
qCInfo(LOG_LIB) << "Send request"; qCInfo(LOG_LIB) << "Send request";
isRunning = true; isRunning = true;
QNetworkReply *reply = manager->get(QNetworkRequest(QUrl(url()))); QNetworkReply *reply = manager->get(QNetworkRequest(QUrl(url())));
new QReplyTimeout(reply, 5000); new QReplyTimeout(reply, REQUEST_TIMEOUT);
} }
// update value // update value
@ -304,7 +303,7 @@ void ExtWeather::writeConfiguration() const
void ExtWeather::weatherReplyReceived(QNetworkReply *reply) 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(); qCDebug(LOG_LIB) << "Reply error message" << reply->errorString();
isRunning = false; isRunning = false;

View File

@ -65,8 +65,7 @@ GraphicalItem::~GraphicalItem()
GraphicalItem *GraphicalItem::copy(const QString _fileName, const int _number) GraphicalItem *GraphicalItem::copy(const QString _fileName, const int _number)
{ {
qCDebug(LOG_LIB) << "File" << _fileName; qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
qCDebug(LOG_LIB) << "Number" << _number;
GraphicalItem *item = new GraphicalItem(static_cast<QWidget *>(parent()), GraphicalItem *item = new GraphicalItem(static_cast<QWidget *>(parent()),
_fileName, directories()); _fileName, directories());

View File

@ -191,8 +191,7 @@ QString DPAdds::toolTipImage(const int desktop) const
QString DPAdds::parsePattern(const QString pattern, const int desktop) const QString DPAdds::parsePattern(const QString pattern, const int desktop) const
{ {
qCDebug(LOG_DP) << "Pattern" << pattern; qCDebug(LOG_DP) << "Pattern" << pattern << "for desktop" << desktop;
qCDebug(LOG_DP) << "Desktop number" << desktop;
QString parsed = pattern; QString parsed = pattern;
parsed.replace(QString("$$"), QString("$\\$\\")); parsed.replace(QString("$$"), QString("$\\$\\"));
@ -224,8 +223,7 @@ void DPAdds::setToolTipData(const QVariantMap tooltipData)
QString DPAdds::valueByKey(const QString key, int desktop) const QString DPAdds::valueByKey(const QString key, int desktop) const
{ {
qCDebug(LOG_DP) << "Requested key" << key; qCDebug(LOG_DP) << "Requested key" << key << "for desktop" << desktop;
qCDebug(LOG_DP) << "Desktop number" << desktop;
if (desktop == -1) if (desktop == -1)
desktop = currentDesktop(); desktop = currentDesktop();
@ -336,8 +334,7 @@ QVariantMap DPAdds::getFont(const QVariantMap defaultFont) const
// to avoid additional object definition this method is static // to avoid additional object definition this method is static
void DPAdds::sendNotification(const QString eventId, const QString message) void DPAdds::sendNotification(const QString eventId, const QString message)
{ {
qCDebug(LOG_DP) << "Event" << eventId; qCDebug(LOG_DP) << "Event" << eventId << "with message" << message;
qCDebug(LOG_DP) << "Message" << message;
KNotification *notification = KNotification::event( KNotification *notification = KNotification::event(
eventId, QString("Desktop Panel ::: %1").arg(eventId), message); eventId, QString("Desktop Panel ::: %1").arg(eventId), message);

View File

@ -346,9 +346,8 @@ QVariantHash PlayerSource::getPlayerMprisInfo(const QString mpris) const
QString PlayerSource::buildString(const QString current, const QString value, QString PlayerSource::buildString(const QString current, const QString value,
const int s) const const int s) const
{ {
qCDebug(LOG_ESM) << "Current value" << current; qCDebug(LOG_ESM) << "Current value" << current << "received" << value
qCDebug(LOG_ESM) << "New value" << value; << "will be stripped after" << s;
qCDebug(LOG_ESM) << "Strip after" << s;
int index = value.indexOf(current); int index = value.indexOf(current);
if ((current.isEmpty()) || ((index + s + 1) > value.count())) { if ((current.isEmpty()) || ((index + s + 1) > value.count())) {
@ -361,8 +360,7 @@ QString PlayerSource::buildString(const QString current, const QString value,
QString PlayerSource::stripString(const QString value, const int s) const QString PlayerSource::stripString(const QString value, const int s) const
{ {
qCDebug(LOG_ESM) << "New value" << value; qCDebug(LOG_ESM) << "New value" << value << "will be stripped after" << s;
qCDebug(LOG_ESM) << "Strip after" << s;
return value.count() > s ? QString("%1\u2026").arg(value.left(s - 1)) return value.count() > s ? QString("%1\u2026").arg(value.left(s - 1))
: value.leftJustified(s, QLatin1Char(' ')); : value.leftJustified(s, QLatin1Char(' '));

View File

@ -24,6 +24,8 @@
#define AWEUAPI 3 #define AWEUAPI 3
// extweather api version // extweather api version
#define AWEWAPI 2 #define AWEWAPI 2
// network requests timeout, ms
#define REQUEST_TIMEOUT 5000
// available time keys // available time keys
#define TIME_KEYS "dddd,ddd,dd,d,MMMM,MMM,MM,M,yyyy,yy,hh,h,HH,H,mm,m,ss,s,t,ap,a,AP,A" #define TIME_KEYS "dddd,ddd,dd,d,MMMM,MMM,MM,M,yyyy,yy,hh,h,HH,H,mm,m,ss,s,t,ap,a,AP,A"
#cmakedefine BUILD_FUTURE #cmakedefine BUILD_FUTURE