more correct fix for #57

This commit is contained in:
arcan1s
2015-07-19 00:14:49 +03:00
parent eb63ef5e96
commit c7d998eb12
18 changed files with 172 additions and 127 deletions

View File

@ -23,28 +23,10 @@
#include "awkeys.h"
static QObject *awactions_singletontype_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
{
Q_UNUSED(engine);
Q_UNUSED(scriptEngine);
return new AWActions();
}
static QObject *awkeys_singletontype_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
{
Q_UNUSED(engine);
Q_UNUSED(scriptEngine);
return new AWKeys();
}
void AWPlugin::registerTypes(const char *uri)
{
Q_ASSERT(uri == QLatin1String("org.kde.plasma.private.awesomewidget"));
qmlRegisterSingletonType<AWActions>(uri, 1, 0, "AWActions", awactions_singletontype_provider);
qmlRegisterSingletonType<AWKeys>(uri, 1, 0, "AWKeys", awkeys_singletontype_provider);
qmlRegisterType<AWActions>(uri, 1, 0, "AWActions");
qmlRegisterType<AWKeys>(uri, 1, 0, "AWKeys");
}

View File

@ -86,7 +86,7 @@ AWKeys::~AWKeys()
}
void AWKeys::initKeys()
void AWKeys::initKeys(const QString currentPattern)
{
if (debug) qDebug() << PDEBUG;
@ -100,6 +100,7 @@ void AWKeys::initKeys()
foundKeys.clear();
// init
pattern = currentPattern;
extQuotes = getExtQuotes();
extScripts = getExtScripts();
extUpgrade = getExtUpgrade();
@ -145,18 +146,12 @@ bool AWKeys::isDebugEnabled()
}
QString AWKeys::parsePattern(const QString currentPattern)
QString AWKeys::parsePattern()
{
if (debug) qDebug() << PDEBUG;
if (keys.isEmpty()) return currentPattern;
if (keys.isEmpty()) return pattern;
// get key data
if ((foundBars.isEmpty()) && (foundKeys.isEmpty())) {
foundBars = findGraphicalItems(currentPattern);
foundKeys = findKeys(currentPattern);
}
QString parsed = currentPattern;
QString parsed = pattern;
parsed.replace(QString("$$"), QString("$\\$\\"));
for (int i=0; i<foundKeys.count(); i++)
parsed.replace(QString("$%1").arg(foundKeys[i]), htmlValue(foundKeys[i]));
@ -854,6 +849,8 @@ void AWKeys::reinitKeys()
if (debug) qDebug() << PDEBUG;
keys = dictKeys();
foundBars = findGraphicalItems();
foundKeys = findKeys();
}
@ -1328,7 +1325,7 @@ float AWKeys::temperature(const float temp, const QString units)
}
QStringList AWKeys::findGraphicalItems(const QString pattern)
QStringList AWKeys::findGraphicalItems()
{
if (debug) qDebug() << PDEBUG;
@ -1348,7 +1345,7 @@ QStringList AWKeys::findGraphicalItems(const QString pattern)
}
QStringList AWKeys::findKeys(const QString pattern)
QStringList AWKeys::findKeys()
{
QStringList selectedKeys;
for (int i=0; i<keys.count(); i++) {

View File

@ -51,12 +51,12 @@ public:
AWKeys(QObject *parent = nullptr);
~AWKeys();
Q_INVOKABLE void initKeys();
Q_INVOKABLE void initKeys(const QString currentPattern);
Q_INVOKABLE void initTooltip(const QVariantMap tooltipParams);
Q_INVOKABLE void setPopupEnabled(const bool popup = false);
Q_INVOKABLE void setWrapNewLines(const bool wrap = false);
Q_INVOKABLE bool isDebugEnabled();
Q_INVOKABLE QString parsePattern(const QString currentPattern);
Q_INVOKABLE QString parsePattern();
Q_INVOKABLE QString toolTipImage();
Q_INVOKABLE QSize toolTipSize();
// keys
@ -94,8 +94,8 @@ private:
int numberCpus();
float temperature(const float temp, const QString units);
// find methods
QStringList findGraphicalItems(const QString pattern);
QStringList findKeys(const QString pattern);
QStringList findGraphicalItems();
QStringList findKeys();
// get methods
// get methods
QList<ExtQuotes *> getExtQuotes();
@ -121,6 +121,7 @@ private:
QList<ExtQuotes *> extQuotes;
QList<ExtScript *> extScripts;
QList<ExtUpgrade *> extUpgrade;
QString pattern;
QStringList foundBars, foundKeys, keys;
QMap<QString, QString> values;
QStringList diskDevices, hddDevices, mountDevices, networkDevices, tempDevices;