initial implementation of custom keys

This commit is contained in:
2017-07-07 00:52:16 +03:00
parent 1a7530a847
commit 7a00dce7c5
14 changed files with 264 additions and 63 deletions

View File

@ -22,6 +22,7 @@
#include <QRegExp>
#include <QThread>
#include "awcustomkeyshelper.h"
#include "awdebug.h"
#include "awkeycache.h"
#include "awpatternfunctions.h"
@ -38,6 +39,16 @@ AWKeyOperations::AWKeyOperations(QObject *_parent)
: QObject(_parent)
{
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
m_customKeys = new AWCustomKeysHelper(this);
m_graphicalItems
= new ExtItemAggregator<GraphicalItem>(nullptr, "desktops");
m_extNetRequest
= new ExtItemAggregator<ExtNetworkRequest>(nullptr, "requests");
m_extQuotes = new ExtItemAggregator<ExtQuotes>(nullptr, "quotes");
m_extScripts = new ExtItemAggregator<ExtScript>(nullptr, "scripts");
m_extUpgrade = new ExtItemAggregator<ExtUpgrade>(nullptr, "upgrade");
m_extWeather = new ExtItemAggregator<ExtWeather>(nullptr, "weather");
}
@ -46,6 +57,7 @@ AWKeyOperations::~AWKeyOperations()
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
// extensions
delete m_customKeys;
delete m_graphicalItems;
delete m_extNetRequest;
delete m_extQuotes;
@ -159,6 +171,8 @@ QStringList AWKeyOperations::dictKeys() const
// bars
for (auto &item : m_graphicalItems->activeItems())
allKeys.append(item->tag("bar"));
// user defined keys
allKeys.append(m_customKeys->keys());
// static keys
allKeys.append(QString(STATIC_KEYS).split(','));
@ -180,6 +194,24 @@ GraphicalItem *AWKeyOperations::giByKey(const QString &_key) const
}
QStringList AWKeyOperations::requiredUserKeys() const
{
return m_customKeys->refinedSources();
}
QStringList AWKeyOperations::userKeys() const
{
return m_customKeys->keys();
}
QString AWKeyOperations::userKeySource(const QString &_key) const
{
return m_customKeys->source(_key);
}
QString AWKeyOperations::infoByKey(const QString &_key) const
{
qCDebug(LOG_AW) << "Requested key" << _key;
@ -314,29 +346,13 @@ void AWKeyOperations::addKeyToCache(const QString &_type, const QString &_key)
void AWKeyOperations::reinitKeys()
{
// renew extensions
// delete them if any
delete m_graphicalItems;
m_graphicalItems = nullptr;
delete m_extNetRequest;
m_extNetRequest = nullptr;
delete m_extQuotes;
m_extQuotes = nullptr;
delete m_extScripts;
m_extScripts = nullptr;
delete m_extUpgrade;
m_extUpgrade = nullptr;
delete m_extWeather;
m_extWeather = nullptr;
// create
m_graphicalItems
= new ExtItemAggregator<GraphicalItem>(nullptr, "desktops");
m_extNetRequest
= new ExtItemAggregator<ExtNetworkRequest>(nullptr, "requests");
m_extQuotes = new ExtItemAggregator<ExtQuotes>(nullptr, "quotes");
m_extScripts = new ExtItemAggregator<ExtScript>(nullptr, "scripts");
m_extUpgrade = new ExtItemAggregator<ExtUpgrade>(nullptr, "upgrade");
m_extWeather = new ExtItemAggregator<ExtWeather>(nullptr, "weather");
m_customKeys->initKeys();
m_graphicalItems->initItems();
m_extNetRequest->initItems();
m_extQuotes->initItems();
m_extScripts->initItems();
m_extUpgrade->initItems();
m_extWeather->initItems();
// init
QStringList allKeys = dictKeys();