mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-07-06 18:35:52 +00:00
initial support of weather
This commit is contained in:
@ -41,6 +41,7 @@
|
||||
#include "extquotes.h"
|
||||
#include "extscript.h"
|
||||
#include "extupgrade.h"
|
||||
#include "extweather.h"
|
||||
#include "version.h"
|
||||
|
||||
|
||||
@ -59,6 +60,7 @@ ExtendedSysMon::ExtendedSysMon(QObject* parent, const QVariantList &args)
|
||||
initQuotes();
|
||||
initScripts();
|
||||
initUpgrade();
|
||||
initWeather();
|
||||
}
|
||||
|
||||
|
||||
@ -69,6 +71,7 @@ ExtendedSysMon::~ExtendedSysMon()
|
||||
externalQuotes.clear();
|
||||
externalScripts.clear();
|
||||
externalUpgrade.clear();
|
||||
externalWeather.clear();
|
||||
}
|
||||
|
||||
|
||||
@ -148,7 +151,7 @@ void ExtendedSysMon::initQuotes()
|
||||
if (names.contains(files[j])) continue;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Found file" << files[j] << "in" << dirs[i];
|
||||
names.append(files[j]);
|
||||
externalQuotes.append(new ExtQuotes(0, files[j], dirs, debug));
|
||||
externalQuotes.append(new ExtQuotes(nullptr, files[j], dirs, debug));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -177,7 +180,7 @@ void ExtendedSysMon::initScripts()
|
||||
if (names.contains(files[j])) continue;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Found file" << files[j] << "in" << dirs[i];
|
||||
names.append(files[j]);
|
||||
externalScripts.append(new ExtScript(0, files[j], dirs, debug));
|
||||
externalScripts.append(new ExtScript(nullptr, files[j], dirs, debug));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -206,7 +209,36 @@ void ExtendedSysMon::initUpgrade()
|
||||
if (names.contains(files[j])) continue;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Found file" << files[j] << "in" << dirs[i];
|
||||
names.append(files[j]);
|
||||
externalUpgrade.append(new ExtUpgrade(0, files[j], dirs, debug));
|
||||
externalUpgrade.append(new ExtUpgrade(nullptr, files[j], dirs, debug));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ExtendedSysMon::initWeather()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
// create directory at $HOME and create dirs list
|
||||
QString localDir = QString("%1/awesomewidgets/weather")
|
||||
.arg(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation));
|
||||
QDir localDirectory;
|
||||
if ((!localDirectory.exists(localDir)) && (localDirectory.mkpath(localDir)))
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Created directory" << localDir;
|
||||
|
||||
QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation,
|
||||
QString("awesomewidgets/weather"),
|
||||
QStandardPaths::LocateDirectory);
|
||||
|
||||
QStringList names;
|
||||
for (int i=0; i<dirs.count(); i++) {
|
||||
QStringList files = QDir(dirs[i]).entryList(QDir::Files, QDir::Name);
|
||||
for (int j=0; j<files.count(); j++) {
|
||||
if (!files[j].endsWith(QString(".desktop"))) continue;
|
||||
if (names.contains(files[j])) continue;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Found file" << files[j] << "in" << dirs[i];
|
||||
names.append(files[j]);
|
||||
externalWeather.append(new ExtWeather(nullptr, files[j], dirs, debug));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -229,6 +261,7 @@ QStringList ExtendedSysMon::sources() const
|
||||
source.append(QString("ps"));
|
||||
source.append(QString("quotes"));
|
||||
source.append(QString("update"));
|
||||
source.append(QString("weather"));
|
||||
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Sources" << source;
|
||||
return source;
|
||||
@ -668,8 +701,10 @@ bool ExtendedSysMon::updateSourceEvent(const QString &source)
|
||||
for (int i=0; i<battery.keys().count(); i++)
|
||||
setData(source, battery.keys()[i], battery[battery.keys()[i]]);
|
||||
} else if (source == QString("custom")) {
|
||||
for (int i=0; i<externalScripts.count(); i++)
|
||||
for (int i=0; i<externalScripts.count(); i++) {
|
||||
if (!externalScripts[i]->isActive()) continue;
|
||||
setData(source, externalScripts[i]->tag(), externalScripts[i]->run());
|
||||
}
|
||||
} else if (source == QString("desktop")) {
|
||||
QVariantMap desktop = getCurrentDesktop();
|
||||
for (int i=0; i<desktop.keys().count(); i++)
|
||||
@ -690,8 +725,10 @@ bool ExtendedSysMon::updateSourceEvent(const QString &source)
|
||||
} else if (source == QString("netdev")) {
|
||||
setData(source, QString("value"), getNetworkDevice());
|
||||
} else if (source == QString("pkg")) {
|
||||
for (int i=0; i<externalUpgrade.count(); i++)
|
||||
for (int i=0; i<externalUpgrade.count(); i++) {
|
||||
if (!externalUpgrade[i]->isActive()) continue;
|
||||
setData(source, externalUpgrade[i]->tag(), externalUpgrade[i]->run());
|
||||
}
|
||||
} else if (source == QString("player")) {
|
||||
QVariantMap player = getPlayerInfo(configuration[QString("PLAYER")],
|
||||
configuration[QString("MPDADDRESS")],
|
||||
@ -705,19 +742,20 @@ bool ExtendedSysMon::updateSourceEvent(const QString &source)
|
||||
setData(source, ps.keys()[i], ps[ps.keys()[i]]);
|
||||
} else if (source == QString("quotes")) {
|
||||
for (int i=0; i<externalQuotes.count(); i++) {
|
||||
if (!externalQuotes[i]->isActive()) continue;
|
||||
QMap<QString, float> data = externalQuotes[i]->run();
|
||||
setData(source, externalQuotes[i]->tag(QString("ask")), data[QString("ask")]);
|
||||
setData(source, externalQuotes[i]->tag(QString("askchg")), data[QString("askchg")]);
|
||||
setData(source, externalQuotes[i]->tag(QString("percaskchg")), data[QString("percaskchg")]);
|
||||
setData(source, externalQuotes[i]->tag(QString("bid")), data[QString("bid")]);
|
||||
setData(source, externalQuotes[i]->tag(QString("bidchg")), data[QString("bidchg")]);
|
||||
setData(source, externalQuotes[i]->tag(QString("percbidchg")), data[QString("percbidchg")]);
|
||||
setData(source, externalQuotes[i]->tag(QString("price")), data[QString("price")]);
|
||||
setData(source, externalQuotes[i]->tag(QString("pricechg")), data[QString("pricechg")]);
|
||||
setData(source, externalQuotes[i]->tag(QString("percpricechg")), data[QString("percpricechg")]);
|
||||
for (int j=0; j<data.keys().count(); j++)
|
||||
setData(source, externalQuotes[i]->tag(data.keys()[j]), data[data.keys()[j]]);
|
||||
}
|
||||
} else if (source == QString("update")) {
|
||||
setData(source, QString("value"), true);
|
||||
} else if (source == QString("weather")) {
|
||||
for (int i=0; i<externalWeather.count(); i++) {
|
||||
if (!externalWeather[i]->isActive()) continue;
|
||||
QVariantMap data = externalWeather[i]->run();
|
||||
for (int j=0; j<data.keys().count(); j++)
|
||||
setData(source, externalWeather[i]->tag(data.keys()[j]), data[data.keys()[j]]);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
Reference in New Issue
Block a user