drop key definition on startup since it blocks several plasmoid

instances (refer to #57)
This commit is contained in:
arcan1s 2015-07-11 15:04:53 +03:00
parent 903a1a454d
commit cd36c4ed68
3 changed files with 15 additions and 58 deletions

View File

@ -181,7 +181,7 @@ Item {
onNeedUpdate: {
if (debug) console.log("[main::onNeedUpdate]")
text.text = AWKeys.parsePattern()
text.text = AWKeys.parsePattern(plasmoid.configuration.text)
tooltip.text = AWKeys.toolTipImage()
sizeUpdate()
@ -211,7 +211,7 @@ Item {
if (debug) console.log("[main::onUserConfiguringChanged]")
// init submodule
AWKeys.initKeys(plasmoid.configuration.text)
AWKeys.initKeys()
AWKeys.initTooltip(tooltipSettings)
AWKeys.setPopupEnabled(plasmoid.configuration.notify)
AWKeys.setWrapNewLines(plasmoid.configuration.wrapNewLines)

View File

@ -86,7 +86,7 @@ AWKeys::~AWKeys()
}
void AWKeys::initKeys(const QString currentPattern)
void AWKeys::initKeys()
{
if (debug) qDebug() << PDEBUG;
@ -96,11 +96,8 @@ void AWKeys::initKeys(const QString currentPattern)
extUpgrade.clear();
graphicalItems.clear();
keys.clear();
foundBars.clear();
foundKeys.clear();
// init
pattern = currentPattern;
extQuotes = getExtQuotes();
extScripts = getExtScripts();
extUpgrade = getExtUpgrade();
@ -146,17 +143,19 @@ bool AWKeys::isDebugEnabled()
}
QString AWKeys::parsePattern()
QString AWKeys::parsePattern(const QString currentPattern)
{
if (debug) qDebug() << PDEBUG;
if (keys.isEmpty()) return pattern;
if (keys.isEmpty()) return currentPattern;
QString parsed = pattern;
QString parsed = currentPattern;
parsed.replace(QString("$$"), QString("$\\$\\"));
for (int i=0; i<foundKeys.count(); i++)
parsed.replace(QString("$%1").arg(foundKeys[i]), htmlValue(foundKeys[i]));
for (int i=0; i<foundBars.count(); i++)
parsed.replace(QString("$%1").arg(foundBars[i]), getItemByTag(foundBars[i])->image(valueByKey(foundBars[i]).toFloat()));
for (int i=0; i<keys.count(); i++) {
if (keys[i].startsWith(QString("bar")))
parsed.replace(QString("$%1").arg(keys[i]), getItemByTag(keys[i])->image(valueByKey(keys[i]).toFloat()));
else
parsed.replace(QString("$%1").arg(keys[i]), htmlValue(keys[i]));
}
parsed.replace(QString("$\\$\\"), QString("$$"));
// wrap new lines if required
if (wrapNewLines) parsed.replace(QString("\n"), QString("<br>"));
@ -849,8 +848,6 @@ void AWKeys::reinitKeys()
if (debug) qDebug() << PDEBUG;
keys = dictKeys();
foundBars = findGraphicalItems();
foundKeys = findKeys();
}
@ -1325,41 +1322,6 @@ float AWKeys::temperature(const float temp, const QString units)
}
QStringList AWKeys::findGraphicalItems()
{
if (debug) qDebug() << PDEBUG;
QStringList orderedKeys;
for (int i=0; i<graphicalItems.count(); i++)
orderedKeys.append(graphicalItems[i]->name() + graphicalItems[i]->bar());
orderedKeys.sort();
QStringList selectedKeys;
for (int i=orderedKeys.count()-1; i>=0; i--)
if (pattern.contains(QString("$%1").arg(orderedKeys[i]))) {
if (debug) qDebug() << PDEBUG << ":" << "Found key" << orderedKeys[i];
selectedKeys.append(orderedKeys[i]);
}
return selectedKeys;
}
QStringList AWKeys::findKeys()
{
QStringList selectedKeys;
for (int i=0; i<keys.count(); i++) {
if (keys[i].startsWith(QString("bar"))) continue;
if (pattern.contains(QString("$%1").arg(keys[i]))) {
if (debug) qDebug() << PDEBUG << ":" << "Found key" << keys[i];
selectedKeys.append(keys[i]);
}
}
return selectedKeys;
}
QList<ExtQuotes *> AWKeys::getExtQuotes()
{
if (debug) qDebug() << PDEBUG;

View File

@ -51,12 +51,12 @@ public:
AWKeys(QObject *parent = nullptr);
~AWKeys();
Q_INVOKABLE void initKeys(const QString currentPattern);
Q_INVOKABLE void initKeys();
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();
Q_INVOKABLE QString parsePattern(const QString currentPattern);
Q_INVOKABLE QString toolTipImage();
Q_INVOKABLE QSize toolTipSize();
// keys
@ -93,9 +93,6 @@ private:
QString htmlValue(QString key);
int numberCpus();
float temperature(const float temp, const QString units);
// find methods
QStringList findGraphicalItems();
QStringList findKeys();
// get methods
QList<ExtQuotes *> getExtQuotes();
QList<ExtScript *> getExtScripts();
@ -120,10 +117,8 @@ private:
QList<ExtQuotes *> extQuotes;
QList<ExtScript *> extScripts;
QList<ExtUpgrade *> extUpgrade;
QStringList foundBars, foundKeys, keys;
QString pattern;
QMap<QString, QString> values;
QStringList diskDevices, hddDevices, mountDevices, networkDevices, tempDevices;
QStringList keys, diskDevices, hddDevices, mountDevices, networkDevices, tempDevices;
};