mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-24 23:47:20 +00:00
add time source
This commit is contained in:
parent
23e197789f
commit
0555185044
@ -9,8 +9,7 @@ arch=('i686' 'x86_64')
|
|||||||
url="https://arcanis.me/projects/awesome-widgets"
|
url="https://arcanis.me/projects/awesome-widgets"
|
||||||
license=('GPL3')
|
license=('GPL3')
|
||||||
depends=('ksysguard' 'plasma-framework')
|
depends=('ksysguard' 'plasma-framework')
|
||||||
optdepends=("catalyst: for GPU monitor"
|
optdepends=("hddtemp: for HDD temperature monitor"
|
||||||
"hddtemp: for HDD temperature monitor"
|
|
||||||
"smartmontools: for HDD temperature monitor"
|
"smartmontools: for HDD temperature monitor"
|
||||||
"mpd: for music player monitor"
|
"mpd: for music player monitor"
|
||||||
"nvidia-utils: for GPU monitor")
|
"nvidia-utils: for GPU monitor")
|
||||||
@ -20,22 +19,14 @@ install=${pkgname}.install
|
|||||||
md5sums=('5953ba518191bb6fff83cdb8633c735c')
|
md5sums=('5953ba518191bb6fff83cdb8633c735c')
|
||||||
backup=('etc/xdg/plasma-dataengine-extsysmon.conf')
|
backup=('etc/xdg/plasma-dataengine-extsysmon.conf')
|
||||||
|
|
||||||
prepare() {
|
|
||||||
rm -rf "${srcdir}/build"
|
|
||||||
mkdir "${srcdir}/build"
|
|
||||||
}
|
|
||||||
|
|
||||||
build () {
|
build () {
|
||||||
cd "${srcdir}/build"
|
cmake -B build -S "${_pkgname}" \
|
||||||
cmake -DKDE_INSTALL_USE_QT_SYS_PATHS=ON \
|
|
||||||
-DCMAKE_BUILD_TYPE=Optimization \
|
-DCMAKE_BUILD_TYPE=Optimization \
|
||||||
-DCMAKE_INSTALL_PREFIX=/usr \
|
|
||||||
-DBUILD_FUTURE=ON \
|
-DBUILD_FUTURE=ON \
|
||||||
"../${_pkgname}"
|
-DBUILD_TESTING=OFF
|
||||||
make
|
cmake --build build
|
||||||
}
|
}
|
||||||
|
|
||||||
package() {
|
package() {
|
||||||
cd "${srcdir}/build"
|
DESTDIR="$pkgdir" cmake --install build
|
||||||
make DESTDIR="${pkgdir}" install
|
|
||||||
}
|
}
|
||||||
|
@ -358,7 +358,7 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const KSy
|
|||||||
m_formatter[key] = _units == KSysGuard::UnitCelsius ? AWKeysAggregator::FormatterType::Temperature
|
m_formatter[key] = _units == KSysGuard::UnitCelsius ? AWKeysAggregator::FormatterType::Temperature
|
||||||
: AWKeysAggregator::FormatterType::Integer;
|
: AWKeysAggregator::FormatterType::Integer;
|
||||||
}
|
}
|
||||||
} else if (_source == "Local") {
|
} else if (_source == "extsysmon/time/now") {
|
||||||
// time
|
// time
|
||||||
m_map.insert(_source, "time");
|
m_map.insert(_source, "time");
|
||||||
m_formatter["time"] = AWKeysAggregator::FormatterType::Time;
|
m_formatter["time"] = AWKeysAggregator::FormatterType::Time;
|
||||||
@ -410,7 +410,7 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const KSy
|
|||||||
m_formatter[key] = AWKeysAggregator::FormatterType::Temperature;
|
m_formatter[key] = AWKeysAggregator::FormatterType::Temperature;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList foundKeys = keysFromSource(_source);
|
auto foundKeys = keysFromSource(_source);
|
||||||
|
|
||||||
// rewrite formatters for custom ones
|
// rewrite formatters for custom ones
|
||||||
QStringList customFormattersKeys;
|
QStringList customFormattersKeys;
|
||||||
@ -425,7 +425,7 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const KSy
|
|||||||
|
|
||||||
// drop key from dictionary if no one user requested key required it
|
// drop key from dictionary if no one user requested key required it
|
||||||
qCInfo(LOG_AW) << "Looking for keys" << foundKeys << "in" << _keys;
|
qCInfo(LOG_AW) << "Looking for keys" << foundKeys << "in" << _keys;
|
||||||
bool required = _keys.isEmpty() || std::any_of(foundKeys.cbegin(), foundKeys.cend(), [&_keys](const QString &key) {
|
auto required = _keys.isEmpty() || std::any_of(foundKeys.cbegin(), foundKeys.cend(), [&_keys](const QString &key) {
|
||||||
return _keys.contains(key);
|
return _keys.contains(key);
|
||||||
});
|
});
|
||||||
if (!required) {
|
if (!required) {
|
||||||
|
@ -373,7 +373,6 @@ void AWKeys::setDataBySource(const QString &_source, const KSysGuard::SensorInfo
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_mutex.lock();
|
m_mutex.lock();
|
||||||
// HACK workaround for time values which are stored in the different path
|
|
||||||
std::for_each(tags.cbegin(), tags.cend(), [this, &_data](const QString &tag) { m_values[tag] = _data.payload; });
|
std::for_each(tags.cbegin(), tags.cend(), [this, &_data](const QString &tag) { m_values[tag] = _data.payload; });
|
||||||
m_mutex.unlock();
|
m_mutex.unlock();
|
||||||
}
|
}
|
||||||
|
@ -113,26 +113,26 @@ QString AWKeysAggregator::formatter(const QVariant &_data, const QString &_key,
|
|||||||
output = QString("%1").arg(temperature(_data.toDouble()), 5, 'f', 1);
|
output = QString("%1").arg(temperature(_data.toDouble()), 5, 'f', 1);
|
||||||
break;
|
break;
|
||||||
case FormatterType::Time:
|
case FormatterType::Time:
|
||||||
output = _data.toDateTime().toString();
|
output = QDateTime::fromSecsSinceEpoch(_data.toLongLong()).toString();
|
||||||
break;
|
break;
|
||||||
case FormatterType::TimeCustom:
|
case FormatterType::TimeCustom:
|
||||||
output = m_customTime;
|
output = m_customTime;
|
||||||
[&output, loc, this](const QDateTime &dt) {
|
[&output, loc, this](const QDateTime &dt) {
|
||||||
for (auto &key : m_timeKeys)
|
for (auto &key : m_timeKeys)
|
||||||
output.replace(QString("$%1").arg(key), loc.toString(dt, key));
|
output.replace(QString("$%1").arg(key), loc.toString(dt, key));
|
||||||
}(_data.toDateTime());
|
}(QDateTime::fromSecsSinceEpoch(_data.toLongLong()));
|
||||||
break;
|
break;
|
||||||
case FormatterType::TimeISO:
|
case FormatterType::TimeISO:
|
||||||
output = _data.toDateTime().toString(Qt::ISODate);
|
output = QDateTime::fromSecsSinceEpoch(_data.toLongLong()).toString(Qt::ISODate);
|
||||||
break;
|
break;
|
||||||
case FormatterType::TimeLong:
|
case FormatterType::TimeLong:
|
||||||
output = loc.toString(_data.toDateTime(), QLocale::LongFormat);
|
output = loc.toString(QDateTime::fromSecsSinceEpoch(_data.toLongLong()), QLocale::LongFormat);
|
||||||
break;
|
break;
|
||||||
case FormatterType::TimeShort:
|
case FormatterType::TimeShort:
|
||||||
output = loc.toString(_data.toDateTime(), QLocale::ShortFormat);
|
output = loc.toString(QDateTime::fromSecsSinceEpoch(_data.toLongLong()), QLocale::ShortFormat);
|
||||||
break;
|
break;
|
||||||
case FormatterType::Timestamp:
|
case FormatterType::Timestamp:
|
||||||
output = QString("%1").arg(_data.toDateTime().toMSecsSinceEpoch() / 1000.0, 10, 'f', 0);
|
output = _data.toString();
|
||||||
break;
|
break;
|
||||||
case FormatterType::Uptime:
|
case FormatterType::Uptime:
|
||||||
case FormatterType::UptimeCustom:
|
case FormatterType::UptimeCustom:
|
||||||
|
@ -93,9 +93,9 @@ QVariantHash OWMWeatherProvider::parseSingleJson(const QVariantMap &_json) const
|
|||||||
// main data
|
// main data
|
||||||
QVariantMap mainWeather = _json["main"].toMap();
|
QVariantMap mainWeather = _json["main"].toMap();
|
||||||
if (!weather.isEmpty()) {
|
if (!weather.isEmpty()) {
|
||||||
output[tag("humidity")] = mainWeather["humidity"].toFloat();
|
output[tag("humidity")] = mainWeather["humidity"].toDouble();
|
||||||
output[tag("pressure")] = mainWeather["pressure"].toFloat();
|
output[tag("pressure")] = mainWeather["pressure"].toDouble();
|
||||||
output[tag("temperature")] = mainWeather["temp"].toFloat();
|
output[tag("temperature")] = mainWeather["temp"].toDouble();
|
||||||
}
|
}
|
||||||
|
|
||||||
// timestamp
|
// timestamp
|
||||||
|
@ -86,7 +86,7 @@ QVariantHash YahooWeatherProvider::parseCurrent(const QVariantMap &_json, const
|
|||||||
values[tag("timestamp")] = condition["date"].toString();
|
values[tag("timestamp")] = condition["date"].toString();
|
||||||
values[tag("humidity")] = _atmosphere["humidity"].toInt();
|
values[tag("humidity")] = _atmosphere["humidity"].toInt();
|
||||||
// HACK temporary fix of invalid values on Yahoo! side
|
// HACK temporary fix of invalid values on Yahoo! side
|
||||||
values[tag("pressure")] = static_cast<int>(_atmosphere["pressure"].toFloat() / 33.863753);
|
values[tag("pressure")] = static_cast<int>(_atmosphere["pressure"].toDouble() / 33.863753);
|
||||||
|
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
@ -103,7 +103,7 @@ QVariantHash YahooWeatherProvider::parseForecast(const QVariantMap &_json) const
|
|||||||
values[tag("weatherId")] = id;
|
values[tag("weatherId")] = id;
|
||||||
values[tag("timestamp")] = weatherMap["date"].toString();
|
values[tag("timestamp")] = weatherMap["date"].toString();
|
||||||
// yahoo provides high and low temperatures. Lets calculate average one
|
// yahoo provides high and low temperatures. Lets calculate average one
|
||||||
values[tag("temperature")] = (weatherMap["high"].toFloat() + weatherMap["low"].toFloat()) / 2.0;
|
values[tag("temperature")] = (weatherMap["high"].toDouble() + weatherMap["low"].toDouble()) / 2.0;
|
||||||
// ... and no forecast data for humidity and pressure
|
// ... and no forecast data for humidity and pressure
|
||||||
values[tag("humidity")] = 0;
|
values[tag("humidity")] = 0;
|
||||||
values[tag("pressure")] = 0.0;
|
values[tag("pressure")] = 0.0;
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
#include "quotessource.h"
|
#include "quotessource.h"
|
||||||
#include "requestsource.h"
|
#include "requestsource.h"
|
||||||
#include "systeminfosource.h"
|
#include "systeminfosource.h"
|
||||||
|
#include "timesource.h"
|
||||||
#include "upgradesource.h"
|
#include "upgradesource.h"
|
||||||
#include "weathersource.h"
|
#include "weathersource.h"
|
||||||
|
|
||||||
@ -86,6 +87,8 @@ void ExtSysMonAggregator::init(const QHash<QString, QString> &_config)
|
|||||||
createSensor("quotes", i18n("Quotes"), new QuotesSource(this, {}));
|
createSensor("quotes", i18n("Quotes"), new QuotesSource(this, {}));
|
||||||
// system
|
// system
|
||||||
createSensor("system", i18n("System"), new SystemInfoSource(this, {}));
|
createSensor("system", i18n("System"), new SystemInfoSource(this, {}));
|
||||||
|
// current time
|
||||||
|
createSensor("time", i18n("Time"), new TimeSource(this, {}));
|
||||||
// upgrade
|
// upgrade
|
||||||
createSensor("upgrade", i18n("Upgrades"), new UpgradeSource(this, {}));
|
createSensor("upgrade", i18n("Upgrades"), new UpgradeSource(this, {}));
|
||||||
// weather
|
// weather
|
||||||
|
@ -15,8 +15,7 @@
|
|||||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
#ifndef EXTSYSMONAGGREGATOR_H
|
#pragma once
|
||||||
#define EXTSYSMONAGGREGATOR_H
|
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <ksysguard/systemstats/SensorContainer.h>
|
#include <ksysguard/systemstats/SensorContainer.h>
|
||||||
@ -39,6 +38,3 @@ private:
|
|||||||
void createSensor(const QString &_id, const QString &_name, AbstractExtSysMonSource *_source);
|
void createSensor(const QString &_id, const QString &_name, AbstractExtSysMonSource *_source);
|
||||||
void init(const QHash<QString, QString> &_config);
|
void init(const QHash<QString, QString> &_config);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif /* EXTSYSMONAGGREGATOR_H */
|
|
||||||
|
62
sources/extsysmonsources/timesource.cpp
Normal file
62
sources/extsysmonsources/timesource.cpp
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* 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 "timesource.h"
|
||||||
|
|
||||||
|
#include <ksysguard/formatter/Unit.h>
|
||||||
|
#include <ksysguard/systemstats/SensorInfo.h>
|
||||||
|
|
||||||
|
#include "awdebug.h"
|
||||||
|
|
||||||
|
|
||||||
|
TimeSource::TimeSource(QObject *_parent, const QStringList &_args)
|
||||||
|
: AbstractExtSysMonSource(_parent, _args)
|
||||||
|
{
|
||||||
|
Q_ASSERT(_args.count() == 0);
|
||||||
|
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QVariant TimeSource::data(const QString &_source)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_ESS) << "Source" << _source;
|
||||||
|
|
||||||
|
if (_source == "now") {
|
||||||
|
return QDateTime::currentSecsSinceEpoch();
|
||||||
|
}
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
KSysGuard::SensorInfo *TimeSource::initialData(const QString &_source) const
|
||||||
|
{
|
||||||
|
qCDebug(LOG_ESS) << "Source" << _source;
|
||||||
|
|
||||||
|
auto data = new KSysGuard::SensorInfo();
|
||||||
|
data->name = "Current time";
|
||||||
|
data->variantType = QVariant::LongLong;
|
||||||
|
data->unit = KSysGuard::UnitSecond;
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QStringList TimeSource::sources() const
|
||||||
|
{
|
||||||
|
return QStringList({"now"});
|
||||||
|
}
|
36
sources/extsysmonsources/timesource.h
Normal file
36
sources/extsysmonsources/timesource.h
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* 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/ *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
#include "abstractextsysmonsource.h"
|
||||||
|
#include "extitemaggregator.h"
|
||||||
|
|
||||||
|
|
||||||
|
class TimeSource : public AbstractExtSysMonSource
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit TimeSource(QObject *_parent, const QStringList &_args);
|
||||||
|
QVariant data(const QString &_source) override;
|
||||||
|
[[nodiscard]] KSysGuard::SensorInfo *initialData(const QString &_source) const override;
|
||||||
|
void run() override{};
|
||||||
|
[[nodiscard]] QStringList sources() const override;
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user