mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-27 00:47:19 +00:00
* Initial syntax is the following: * $template{{ some JS code here }} - simple template based on JS code inside. It works the same as lambda functions, but calculates only once. * aw_count(regex) - keys count found for given regex * aw_keys(regex, [separator]) - keys found for given regex and joined by using given separator * aw_names(regex, [separator]) - key names found for given regex and joined by using given separator (the same as previous but w\o $) The template and function syntax may be changed before release. * replace `foreach` to `for (auto foo : bar)` and update CONTRIBUTING.md accordingly
144 lines
5.3 KiB
C++
144 lines
5.3 KiB
C++
/***************************************************************************
|
|
* This file is part of awesome-widgets *
|
|
* *
|
|
* awesome-widgets is free software: you can redistribute it and/or *
|
|
* modify it under the terms of the GNU General Public License as *
|
|
* published by the Free Software Foundation, either version 3 of the *
|
|
* License, or (at your option) any later version. *
|
|
* *
|
|
* awesome-widgets is distributed in the hope that it will be useful, *
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
* GNU General Public License for more details. *
|
|
* *
|
|
* You should have received a copy of the GNU General Public License *
|
|
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
|
***************************************************************************/
|
|
|
|
|
|
#include "weathersource.h"
|
|
|
|
#include "awdebug.h"
|
|
#include "extweather.h"
|
|
|
|
|
|
WeatherSource::WeatherSource(QObject *parent, const QStringList args)
|
|
: AbstractExtSysMonSource(parent, args)
|
|
{
|
|
Q_ASSERT(args.count() == 0);
|
|
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
|
|
|
|
extWeather = new ExtItemAggregator<ExtWeather>(nullptr, QString("weather"));
|
|
m_sources = getSources();
|
|
}
|
|
|
|
|
|
WeatherSource::~WeatherSource()
|
|
{
|
|
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
|
|
|
|
delete extWeather;
|
|
}
|
|
|
|
|
|
QVariant WeatherSource::data(QString source)
|
|
{
|
|
qCDebug(LOG_ESM) << "Source" << source;
|
|
|
|
if (source.startsWith(QString("weather/weatherId"))) {
|
|
QVariantHash data = extWeather->itemByTagNumber(index(source))->run();
|
|
for (auto key : data.keys())
|
|
values[key] = data[key];
|
|
}
|
|
QString key = QString(source).remove(QString("weather/"));
|
|
return values[key];
|
|
}
|
|
|
|
|
|
QVariantMap WeatherSource::initialData(QString source) const
|
|
{
|
|
qCDebug(LOG_ESM) << "Source" << source;
|
|
|
|
int ind = index(source);
|
|
QVariantMap data;
|
|
if (source.startsWith(QString("weather/weatherId"))) {
|
|
data[QString("min")] = 0;
|
|
data[QString("max")] = 1000;
|
|
data[QString("name")]
|
|
= QString("Numeric weather ID for '%1'")
|
|
.arg(extWeather->itemByTagNumber(ind)->uniq());
|
|
data[QString("type")] = QString("integer");
|
|
data[QString("units")] = QString("");
|
|
} else if (source.startsWith(QString("weather/weather"))) {
|
|
data[QString("min")] = QString("");
|
|
data[QString("max")] = QString("");
|
|
data[QString("name")]
|
|
= QString("ID string map for '%1'")
|
|
.arg(extWeather->itemByTagNumber(ind)->uniq());
|
|
data[QString("type")] = QString("QString");
|
|
data[QString("units")] = QString("");
|
|
} else if (source.startsWith(QString("weather/humidity"))) {
|
|
data[QString("min")] = 0;
|
|
data[QString("max")] = 100;
|
|
data[QString("name")]
|
|
= QString("Humidity for '%1'")
|
|
.arg(extWeather->itemByTagNumber(ind)->uniq());
|
|
data[QString("type")] = QString("integer");
|
|
data[QString("units")] = QString("%");
|
|
} else if (source.startsWith(QString("weather/pressure"))) {
|
|
data[QString("min")] = 0;
|
|
data[QString("max")] = 0;
|
|
data[QString("name")]
|
|
= QString("Atmospheric pressure for '%1'")
|
|
.arg(extWeather->itemByTagNumber(ind)->uniq());
|
|
data[QString("type")] = QString("integer");
|
|
data[QString("units")] = QString("mb");
|
|
} else if (source.startsWith(QString("weather/temperature"))) {
|
|
data[QString("min")] = 0.0;
|
|
data[QString("max")] = 0.0;
|
|
data[QString("name")]
|
|
= QString("Temperature for '%1'")
|
|
.arg(extWeather->itemByTagNumber(ind)->uniq());
|
|
data[QString("type")] = QString("float");
|
|
data[QString("units")] = QString("°C");
|
|
} else if (source.startsWith(QString("weather/timestamp"))) {
|
|
data[QString("min")] = QString("");
|
|
data[QString("max")] = QString("");
|
|
data[QString("name")]
|
|
= QString("Timestamp for '%1'")
|
|
.arg(extWeather->itemByTagNumber(ind)->uniq());
|
|
data[QString("type")] = QString("QString");
|
|
data[QString("units")] = QString("");
|
|
}
|
|
|
|
return data;
|
|
}
|
|
|
|
|
|
QStringList WeatherSource::sources() const
|
|
{
|
|
return m_sources;
|
|
}
|
|
|
|
|
|
QStringList WeatherSource::getSources()
|
|
{
|
|
QStringList sources;
|
|
for (auto item : extWeather->activeItems()) {
|
|
sources.append(
|
|
QString("weather/%1").arg(item->tag(QString("weatherId"))));
|
|
sources.append(
|
|
QString("weather/%1").arg(item->tag(QString("weather"))));
|
|
sources.append(
|
|
QString("weather/%1").arg(item->tag(QString("humidity"))));
|
|
sources.append(
|
|
QString("weather/%1").arg(item->tag(QString("pressure"))));
|
|
sources.append(
|
|
QString("weather/%1").arg(item->tag(QString("temperature"))));
|
|
sources.append(
|
|
QString("weather/%1").arg(item->tag(QString("timestamp"))));
|
|
}
|
|
|
|
return sources;
|
|
}
|