mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-12-14 17:13:41 +00:00
refactor: simplify sources processing
This commit is contained in:
@ -15,12 +15,8 @@
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#include "weathersource.h"
|
||||
|
||||
#include <ksysguard/formatter/Unit.h>
|
||||
#include <ksysguard/systemstats/SensorInfo.h>
|
||||
|
||||
#include "awdebug.h"
|
||||
#include "extweather.h"
|
||||
|
||||
@ -37,12 +33,6 @@ WeatherSource::WeatherSource(QObject *_parent, const QStringList &_args)
|
||||
}
|
||||
|
||||
|
||||
WeatherSource::~WeatherSource()
|
||||
{
|
||||
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
|
||||
}
|
||||
|
||||
|
||||
QVariant WeatherSource::data(const QString &_source)
|
||||
{
|
||||
qCDebug(LOG_ESS) << "Source" << _source;
|
||||
@ -56,47 +46,20 @@ QVariant WeatherSource::data(const QString &_source)
|
||||
}
|
||||
|
||||
|
||||
KSysGuard::SensorInfo *WeatherSource::initialData(const QString &_source) const
|
||||
QHash<QString, KSysGuard::SensorInfo *> WeatherSource::initialData() const
|
||||
{
|
||||
qCDebug(LOG_ESS) << "Source" << _source;
|
||||
auto result = QHash<QString, KSysGuard::SensorInfo *>();
|
||||
|
||||
int ind = index(_source);
|
||||
auto data = new KSysGuard::SensorInfo();
|
||||
if (_source.startsWith("weatherId")) {
|
||||
data->min = 0;
|
||||
data->max = 1000;
|
||||
data->name = QString("Numeric weather ID for '%1'").arg(m_extWeather->itemByTagNumber(ind)->uniq());
|
||||
data->variantType = QVariant::Int;
|
||||
data->unit = KSysGuard::UnitNone;
|
||||
} else if (_source.startsWith("weather")) {
|
||||
data->name = QString("ID string map for '%1'").arg(m_extWeather->itemByTagNumber(ind)->uniq());
|
||||
data->variantType = QVariant::String;
|
||||
data->unit = KSysGuard::UnitNone;
|
||||
} else if (_source.startsWith("humidity")) {
|
||||
data->min = 0;
|
||||
data->max = 100;
|
||||
data->name = QString("Humidity for '%1'").arg(m_extWeather->itemByTagNumber(ind)->uniq());
|
||||
data->variantType = QVariant::Int;
|
||||
data->unit = KSysGuard::UnitPercent;
|
||||
} else if (_source.startsWith("pressure")) {
|
||||
data->min = 0;
|
||||
data->max = 0;
|
||||
data->name = QString("Atmospheric pressure for '%1'").arg(m_extWeather->itemByTagNumber(ind)->uniq());
|
||||
data->variantType = QVariant::Int;
|
||||
data->unit = KSysGuard::UnitNone;
|
||||
} else if (_source.startsWith("temperature")) {
|
||||
data->min = 0.0;
|
||||
data->max = 0.0;
|
||||
data->name = QString("Temperature for '%1'").arg(m_extWeather->itemByTagNumber(ind)->uniq());
|
||||
data->variantType = QVariant::Double;
|
||||
data->unit = KSysGuard::UnitCelsius;
|
||||
} else if (_source.startsWith("timestamp")) {
|
||||
data->name = QString("Timestamp for '%1'").arg(m_extWeather->itemByTagNumber(ind)->uniq());
|
||||
data->variantType = QVariant::DateTime;
|
||||
data->unit = KSysGuard::UnitNone;
|
||||
for (auto &item : m_extWeather->activeItems()) {
|
||||
result.insert(item->tag("weatherId"), makeSensorInfo(QString("Numeric weather ID for '%1'").arg(item->uniq()), QVariant::Int, KSysGuard::UnitNone, 0, 1000));
|
||||
result.insert(item->tag("weather"), makeSensorInfo(QString("ID string map for '%1'").arg(item->uniq()), QVariant::String));
|
||||
result.insert(item->tag("humidity"), makeSensorInfo(QString("Humidity for '%1'").arg(item->uniq()), QVariant::Int, KSysGuard::UnitPercent, 0, 100));
|
||||
result.insert(item->tag("pressure"), makeSensorInfo(QString("Atmospheric pressure for '%1'").arg(item->uniq()), QVariant::Int));
|
||||
result.insert(item->tag("temperature"), makeSensorInfo(QString("Temperature for '%1'").arg(item->uniq()), QVariant::Double, KSysGuard::UnitCelsius));
|
||||
result.insert(item->tag("timestamp"), makeSensorInfo(QString("Timestamp for '%1'").arg(item->uniq()), QVariant::DateTime, KSysGuard::UnitNone));
|
||||
}
|
||||
|
||||
return data;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user