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
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

View File

@ -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,10 +252,19 @@ Item {
{
'label': i18n("Weathers"),
'regexp': "^(weather(Id)?|humidity|pressure|temperature|timestamp)"
},
{
'label': i18n("Functions"),
'regexp': "functions"
}
]
onCurrentIndexChanged: {
if (debug) console.debug()
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 {

View File

@ -179,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);
@ -229,9 +228,8 @@ 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);

View File

@ -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(
@ -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;

View File

@ -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;
@ -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;

View File

@ -45,9 +45,9 @@ AWDataEngineAggregator::~AWDataEngineAggregator()
void AWDataEngineAggregator::disconnectSources()
{
for (auto dataengine : m_dataEngines.keys())
for (auto 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());
}
@ -93,7 +93,7 @@ void AWDataEngineAggregator::initDataEngines()
// 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);
});

View File

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

View File

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

View File

@ -26,10 +26,9 @@
#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;
qCDebug(LOG_AW) << "Key" << key << "with type" << type;
QString fileName = QString("%1/awesomewidgets.ndx")
.arg(QStandardPaths::writableLocation(
@ -70,7 +69,7 @@ void AWKeyCache::addKeyToCache(const QString type, const QString key)
}
} else {
if (cachedValues.contains(key))
return;
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);
@ -78,6 +77,7 @@ void AWKeyCache::addKeyToCache(const QString type, const QString key)
cache.endGroup();
cache.sync();
return true;
}

View File

@ -25,7 +25,7 @@
namespace AWKeyCache
{
void addKeyToCache(const QString type, const QString key = QString(""));
bool addKeyToCache(const QString type, const QString key = QString(""));
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
{
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
{
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)
{
qCDebug(LOG_AW) << "Key type" << type;
qCDebug(LOG_AW) << "Key" << key;
qCDebug(LOG_AW) << "Key" << key << "with type" << type;
AWKeyCache::addKeyToCache(type, key);
if (AWKeyCache::addKeyToCache(type, key)) {
m_devices = AWKeyCache::loadKeysFromCache();
reinitKeys();
}
}
@ -391,17 +393,8 @@ void AWKeyOperations::reinitKeys()
// init
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
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);

View File

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

View File

@ -27,6 +27,7 @@
#include "awdebug.h"
#include "awkeyoperations.h"
#include "awkeysaggregator.h"
#include "awpatternfunctions.h"
#include "graphicalitem.h"
#include "version.h"
@ -79,9 +80,8 @@ 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
keyOperator->setPattern(currentPattern);
@ -89,6 +89,9 @@ void AWKeys::initKeys(const QString currentPattern, const int interval,
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);
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)
{
qCDebug(LOG_AW) << "Key" << key;
qCDebug(LOG_AW) << "Value" << value;
qCDebug(LOG_AW) << "Key" << key << "with value" << value;
aggregator->setProperty(key.toUtf8().constData(), value);
}
@ -124,8 +126,8 @@ void AWKeys::updateCache()
QStringList AWKeys::dictKeys(const bool sorted, const QString regexp) const
{
qCDebug(LOG_AW) << "Should be sorted" << sorted;
qCDebug(LOG_AW) << "Filter" << regexp;
qCDebug(LOG_AW) << "Should be sorted" << sorted << "and filter applied"
<< regexp;
QStringList allKeys = keyOperator->dictKeys();
// sort if required
@ -149,7 +151,7 @@ QStringList AWKeys::getHddDevices() 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);
}
@ -158,7 +160,7 @@ QString AWKeys::infoByKey(QString key) const
// 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(""));
@ -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,
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;
// append lists
// bars
m_foundBars = [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 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());
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(keyOperator->devices());
@ -354,7 +301,7 @@ void AWKeys::calculateValues()
QString AWKeys::parsePattern(QString pattern) const
{
// screen sign
pattern.replace(QString("$$"), QString("$\\$\\"));
pattern.replace(QString("$$"), QString(0x1d));
// lambdas
for (auto key : m_foundLambdas)
@ -385,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>"));
@ -395,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);
@ -404,21 +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 {
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")]
// 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) {
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);
public slots:
void addDevice(const QString source);
void dataUpdated(const QString &sourceName,
const Plasma::DataEngine::Data &data);
// dummy method required by DataEngine connections

View File

@ -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();
@ -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);

View File

@ -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;
};

View File

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

View File

@ -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;
}

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();
}

View File

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

View File

@ -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;

View File

@ -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;

View File

@ -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());
@ -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))

View File

@ -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());

View File

@ -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());
@ -236,7 +235,7 @@ QVariantHash ExtWeather::run()
qCInfo(LOG_LIB) << "Send request";
isRunning = true;
QNetworkReply *reply = manager->get(QNetworkRequest(QUrl(url())));
new QReplyTimeout(reply, 5000);
new QReplyTimeout(reply, REQUEST_TIMEOUT);
}
// update value
@ -304,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;

View File

@ -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());

View File

@ -191,8 +191,7 @@ 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("$\\$\\"));
@ -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();
@ -336,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);

View File

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

View File

@ -24,6 +24,8 @@
#define AWEUAPI 3
// extweather api version
#define AWEWAPI 2
// network requests timeout, ms
#define REQUEST_TIMEOUT 5000
// 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"
#cmakedefine BUILD_FUTURE