split formatter into separated singleton classes

This commit is contained in:
Evgenii Alekseev 2024-04-22 17:36:48 +03:00
parent 95572364c1
commit 3db85cb38f
54 changed files with 1538 additions and 292 deletions

View File

@ -10,7 +10,7 @@ include_directories(
${Kf6_INCLUDE} ${Kf6_INCLUDE}
) )
file(GLOB SUBPROJECT_SOURCE *.cpp ${PROJECT_TRDPARTY_DIR}/fontdialog/*.cpp ${CMAKE_SOURCE_DIR}/*.cpp) file(GLOB SUBPROJECT_SOURCE *.cpp formatters/*.cpp ${PROJECT_TRDPARTY_DIR}/fontdialog/*.cpp ${CMAKE_SOURCE_DIR}/*.cpp)
file(GLOB SUBPROJECT_UI *.ui) file(GLOB SUBPROJECT_UI *.ui)
file(GLOB SUBPROJECT_NOTIFY *.notifyrc) file(GLOB SUBPROJECT_NOTIFY *.notifyrc)

View File

@ -21,6 +21,7 @@
#include "awdebug.h" #include "awdebug.h"
#include "awformatterhelper.h" #include "awformatterhelper.h"
#include "formatters/formatters.h"
AWDataEngineMapper::AWDataEngineMapper(QObject *_parent, AWFormatterHelper *_custom) AWDataEngineMapper::AWDataEngineMapper(QObject *_parent, AWFormatterHelper *_custom)
@ -31,32 +32,32 @@ AWDataEngineMapper::AWDataEngineMapper(QObject *_parent, AWFormatterHelper *_cus
// default formatters // default formatters
// memory // memory
m_formatter["mem"] = AWKeysAggregator::FormatterType::Float; m_formatter["mem"] = AWPluginFormatterFloat::instance();
m_formatter["memtotmb"] = AWKeysAggregator::FormatterType::MemMBFormat; m_formatter["memtotmb"] = AWPluginFormatterMemoryMB::instance();
m_formatter["memtotgb"] = AWKeysAggregator::FormatterType::MemGBFormat; m_formatter["memtotgb"] = AWPluginFormatterMemoryGB::instance();
// network // network
m_formatter["down"] = AWKeysAggregator::FormatterType::NetSmartFormat; m_formatter["down"] = AWPluginFormatterNet::instance();
m_formatter["downkb"] = AWKeysAggregator::FormatterType::Integer; m_formatter["downkb"] = AWPluginFormatterMemory::instance();
m_formatter["downtot"] = AWKeysAggregator::FormatterType::MemMBFormat; m_formatter["downtot"] = AWPluginFormatterMemoryMB::instance();
m_formatter["downtotkb"] = AWKeysAggregator::FormatterType::Integer; m_formatter["downtotkb"] = AWPluginFormatterMemory::instance();
m_formatter["downunits"] = AWKeysAggregator::FormatterType::NetSmartUnits; m_formatter["downunits"] = AWPluginFormatterNetUnits::instance();
m_formatter["up"] = AWKeysAggregator::FormatterType::NetSmartFormat; m_formatter["up"] = AWPluginFormatterNet::instance();
m_formatter["upkb"] = AWKeysAggregator::FormatterType::Integer; m_formatter["upkb"] = AWPluginFormatterMemory::instance();
m_formatter["uptot"] = AWKeysAggregator::FormatterType::MemMBFormat; m_formatter["uptot"] = AWPluginFormatterMemoryMB::instance();
m_formatter["uptotkb"] = AWKeysAggregator::FormatterType::Integer; m_formatter["uptotkb"] = AWPluginFormatterMemory::instance();
m_formatter["upunits"] = AWKeysAggregator::FormatterType::NetSmartUnits; m_formatter["upunits"] = AWPluginFormatterNetUnits::instance();
// swap // swap
m_formatter["swap"] = AWKeysAggregator::FormatterType::Float; m_formatter["swap"] = AWPluginFormatterFloat::instance();
m_formatter["swaptotmb"] = AWKeysAggregator::FormatterType::MemMBFormat; m_formatter["swaptotmb"] = AWPluginFormatterMemoryMB::instance();
m_formatter["swaptotgb"] = AWKeysAggregator::FormatterType::MemGBFormat; m_formatter["swaptotgb"] = AWPluginFormatterMemoryGB::instance();
} }
AWKeysAggregator::FormatterType AWDataEngineMapper::formatter(const QString &_key) const AWPluginFormaterInterface *AWDataEngineMapper::formatter(const QString &_key) const
{ {
qCDebug(LOG_AW) << "Get formatter for key" << _key; qCDebug(LOG_AW) << "Get formatter for key" << _key;
return m_formatter.value(_key, AWKeysAggregator::FormatterType::NoFormat); return m_formatter.value(_key, AWPluginFormatterNoFormat::instance());
} }
@ -92,53 +93,55 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const KSy
if (_source == "extsysmon/battery/ac") { if (_source == "extsysmon/battery/ac") {
// AC // AC
m_map.insert(_source, "ac"); m_map.insert(_source, "ac");
m_formatter["ac"] = AWKeysAggregator::FormatterType::ACFormat; m_formatter["ac"] = AWPluginFormatterAC::instance();
} else if (_source.startsWith("extsysmon/battery/")) { } else if (_source.startsWith("extsysmon/battery/")) {
// battery stats // battery stats
auto key = _source; auto key = _source;
key.remove("extsysmon/battery/"); key.remove("extsysmon/battery/");
m_map.insert(_source, key); m_map.insert(_source, key);
m_formatter[key] = _source.contains("rate") ? AWKeysAggregator::FormatterType::Float if (_source.contains("rate"))
: AWKeysAggregator::FormatterType::IntegerThree; m_formatter[key] = AWPluginFormatterFloat::instance();
else
m_formatter[key] = AWPluginFormatterIntegerShort::instance();
} else if (_source == "cpu/all/usage") { } else if (_source == "cpu/all/usage") {
// cpu // cpu
m_map.insert(_source, "cpu"); m_map.insert(_source, "cpu");
m_formatter["cpu"] = AWKeysAggregator::FormatterType::Float; m_formatter["cpu"] = AWPluginFormatterFloat::instance();
} else if (_source.contains(cpuRegExp)) { } else if (_source.contains(cpuRegExp)) {
// cpus // cpus
auto key = _source; auto key = _source;
key.remove("cpu/").remove("/usage"); key.remove("cpu/").remove("/usage");
m_map.insert(_source, key); m_map.insert(_source, key);
m_formatter[key] = AWKeysAggregator::FormatterType::Float; m_formatter[key] = AWPluginFormatterFloat::instance();
} else if (_source == "cpu/all/averageFrequency") { } else if (_source == "cpu/all/averageFrequency") {
// cpucl // cpucl
m_map.insert(_source, "cpucl"); m_map.insert(_source, "cpucl");
m_formatter["cpucl"] = AWKeysAggregator::FormatterType::Integer; m_formatter["cpucl"] = AWPluginFormatterInteger::instance();
} else if (_source.contains(cpuclRegExp)) { } else if (_source.contains(cpuclRegExp)) {
// cpucls // cpucls
auto key = _source; auto key = _source;
key.remove("cpu/cpu").remove("/frequency"); key.remove("cpu/cpu").remove("/frequency");
key = QString("cpucl%1").arg(key); key = QString("cpucl%1").arg(key);
m_map.insert(_source, key); m_map.insert(_source, key);
m_formatter[key] = AWKeysAggregator::FormatterType::Integer; m_formatter[key] = AWPluginFormatterInteger::instance();
} else if (_source.startsWith("extsysmon/custom")) { } else if (_source.startsWith("extsysmon/custom")) {
// custom // custom
auto key = _source; auto key = _source;
key.remove("extsysmon/custom/"); key.remove("extsysmon/custom/");
m_map.insert(_source, key); m_map.insert(_source, key);
m_formatter[key] = AWKeysAggregator::FormatterType::NoFormat; m_formatter[key] = AWPluginFormatterNoFormat::instance();
} else if (_source == "extsysmon/desktop/name") { } else if (_source == "extsysmon/desktop/name") {
// current desktop name // current desktop name
m_map.insert(_source, "desktop"); m_map.insert(_source, "desktop");
m_formatter["desktop"] = AWKeysAggregator::FormatterType::NoFormat; m_formatter["desktop"] = AWPluginFormatterNoFormat::instance();
} else if (_source == "extsysmon/desktop/number") { } else if (_source == "extsysmon/desktop/number") {
// current desktop number // current desktop number
m_map.insert(_source, "ndesktop"); m_map.insert(_source, "ndesktop");
m_formatter["ndesktop"] = AWKeysAggregator::FormatterType::NoFormat; m_formatter["ndesktop"] = AWPluginFormatterNoFormat::instance();
} else if (_source == "extsysmon/desktop/count") { } else if (_source == "extsysmon/desktop/count") {
// desktop count // desktop count
m_map.insert(_source, "tdesktops"); m_map.insert(_source, "tdesktops");
m_formatter["tdesktops"] = AWKeysAggregator::FormatterType::NoFormat; m_formatter["tdesktops"] = AWPluginFormatterNoFormat::instance();
} else if (_source.contains(hddrRegExp)) { } else if (_source.contains(hddrRegExp)) {
// read speed // read speed
auto device = _source; auto device = _source;
@ -147,7 +150,7 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const KSy
if (index > -1) { if (index > -1) {
QString key = QString("hddr%1").arg(index); QString key = QString("hddr%1").arg(index);
m_map.insert(_source, key); m_map.insert(_source, key);
m_formatter[key] = AWKeysAggregator::FormatterType::MemKBFormat; m_formatter[key] = AWPluginFormatterMemory::instance();
} }
} else if (_source.contains(hddwRegExp)) { } else if (_source.contains(hddwRegExp)) {
// write speed // write speed
@ -157,12 +160,12 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const KSy
if (index > -1) { if (index > -1) {
QString key = QString("hddw%1").arg(index); QString key = QString("hddw%1").arg(index);
m_map.insert(_source, key); m_map.insert(_source, key);
m_formatter[key] = AWKeysAggregator::FormatterType::MemKBFormat; m_formatter[key] = AWPluginFormatterMemory::instance();
} }
} else if (_source == "gpu/all/usage") { } else if (_source == "gpu/all/usage") {
// gpu load // gpu load
m_map.insert(_source, "gpu"); m_map.insert(_source, "gpu");
m_formatter["gpu"] = AWKeysAggregator::FormatterType::Float; m_formatter["gpu"] = AWPluginFormatterFloat::instance();
} else if (_source.contains(gpuRegExp)) { } else if (_source.contains(gpuRegExp)) {
// gpus // gpus
auto device = _source; auto device = _source;
@ -171,7 +174,7 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const KSy
if (index > -1) { if (index > -1) {
auto key = QString("gpu%1").arg(index); auto key = QString("gpu%1").arg(index);
m_map.insert(_source, key); m_map.insert(_source, key);
m_formatter[key] = AWKeysAggregator::FormatterType::Float; m_formatter[key] = AWPluginFormatterFloat::instance();
} }
} else if (_source.contains(gpuTempRegExp)) { } else if (_source.contains(gpuTempRegExp)) {
// gpus temps // gpus temps
@ -181,7 +184,7 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const KSy
if (index > -1) { if (index > -1) {
auto key = QString("gputemp%1").arg(index); auto key = QString("gputemp%1").arg(index);
m_map.insert(_source, key); m_map.insert(_source, key);
m_formatter[key] = AWKeysAggregator::FormatterType::Temperature; m_formatter[key] = AWPluginFormatterTemperature::instance();
} }
} else if (_source.contains(mountFillRegExp)) { } else if (_source.contains(mountFillRegExp)) {
// fill level // fill level
@ -191,10 +194,10 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const KSy
if (index > -1) { if (index > -1) {
auto key = QString("hdd%1").arg(index); auto key = QString("hdd%1").arg(index);
m_map.insert(_source, key); m_map.insert(_source, key);
m_formatter[key] = AWKeysAggregator::FormatterType::Float; m_formatter[key] = AWPluginFormatterFloat::instance();
// additional keys // additional keys
m_formatter[QString("hddtotmb%1").arg(index)] = AWKeysAggregator::FormatterType::MemMBFormat; m_formatter[QString("hddtotmb%1").arg(index)] = AWPluginFormatterMemoryMB::instance();
m_formatter[QString("hddtotgb%1").arg(index)] = AWKeysAggregator::FormatterType::MemGBFormat; m_formatter[QString("hddtotgb%1").arg(index)] = AWPluginFormatterMemoryGB::instance();
} }
} else if (_source.contains(mountFreeRegExp)) { } else if (_source.contains(mountFreeRegExp)) {
// free space // free space
@ -205,11 +208,11 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const KSy
// mb // mb
auto key = QString("hddfreemb%1").arg(index); auto key = QString("hddfreemb%1").arg(index);
m_map.insert(_source, key); m_map.insert(_source, key);
m_formatter[key] = AWKeysAggregator::FormatterType::MemMBFormat; m_formatter[key] = AWPluginFormatterMemoryMB::instance();
// gb // gb
key = QString("hddfreegb%1").arg(index); key = QString("hddfreegb%1").arg(index);
m_map.insert(_source, key); m_map.insert(_source, key);
m_formatter[key] = AWKeysAggregator::FormatterType::MemGBFormat; m_formatter[key] = AWPluginFormatterMemoryGB::instance();
} }
} else if (_source.contains(mountUsedRegExp)) { } else if (_source.contains(mountUsedRegExp)) {
// used // used
@ -220,11 +223,11 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const KSy
// mb // mb
auto key = QString("hddmb%1").arg(index); auto key = QString("hddmb%1").arg(index);
m_map.insert(_source, key); m_map.insert(_source, key);
m_formatter[key] = AWKeysAggregator::FormatterType::MemMBFormat; m_formatter[key] = AWPluginFormatterMemoryMB::instance();
// gb // gb
key = QString("hddgb%1").arg(index); key = QString("hddgb%1").arg(index);
m_map.insert(_source, key); m_map.insert(_source, key);
m_formatter[key] = AWKeysAggregator::FormatterType::MemGBFormat; m_formatter[key] = AWPluginFormatterMemoryGB::instance();
} }
} else if (_source.startsWith("cpu/loadaverages/loadaverage")) { } else if (_source.startsWith("cpu/loadaverages/loadaverage")) {
// load average // load average
@ -232,45 +235,45 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const KSy
time.remove("cpu/loadaverages/loadaverage"); time.remove("cpu/loadaverages/loadaverage");
auto key = QString("la%1").arg(time); auto key = QString("la%1").arg(time);
m_map.insert(_source, key); m_map.insert(_source, key);
m_formatter[key] = AWKeysAggregator::FormatterType::FloatTwoSymbols; m_formatter[key] = AWPluginFormatterFloatPrecise::instance();
} else if (_source == "memory/physical/application") { } else if (_source == "memory/physical/application") {
// app memory // app memory
// mb // mb
m_map.insert(_source, "memmb"); m_map.insert(_source, "memmb");
m_formatter["memmb"] = AWKeysAggregator::FormatterType::MemMBFormat; m_formatter["memmb"] = AWPluginFormatterMemoryMB::instance();
// gb // gb
m_map.insert(_source, "memgb"); m_map.insert(_source, "memgb");
m_formatter["memgb"] = AWKeysAggregator::FormatterType::MemGBFormat; m_formatter["memgb"] = AWPluginFormatterMemoryGB::instance();
} else if (_source == "memory/physical/free") { } else if (_source == "memory/physical/free") {
// free memory // free memory
// mb // mb
m_map.insert(_source, "memfreemb"); m_map.insert(_source, "memfreemb");
m_formatter["memfreemb"] = AWKeysAggregator::FormatterType::MemMBFormat; m_formatter["memfreemb"] = AWPluginFormatterMemoryMB::instance();
// gb // gb
m_map.insert(_source, "memfreegb"); m_map.insert(_source, "memfreegb");
m_formatter["memfreegb"] = AWKeysAggregator::FormatterType::MemGBFormat; m_formatter["memfreegb"] = AWPluginFormatterMemoryGB::instance();
} else if (_source == "memory/physical/used") { } else if (_source == "memory/physical/used") {
// used memory // used memory
// mb // mb
m_map.insert(_source, "memusedmb"); m_map.insert(_source, "memusedmb");
m_formatter["memusedmb"] = AWKeysAggregator::FormatterType::MemMBFormat; m_formatter["memusedmb"] = AWPluginFormatterMemoryMB::instance();
// gb // gb
m_map.insert(_source, "memusedgb"); m_map.insert(_source, "memusedgb");
m_formatter["memusedgb"] = AWKeysAggregator::FormatterType::MemGBFormat; m_formatter["memusedgb"] = AWPluginFormatterMemoryGB::instance();
} else if (_source == "extsysmon/network/device") { } else if (_source == "extsysmon/network/device") {
// network device // network device
m_map.insert(_source, "netdev"); m_map.insert(_source, "netdev");
m_formatter["netdev"] = AWKeysAggregator::FormatterType::NoFormat; m_formatter["netdev"] = AWPluginFormatterNoFormat::instance();
} else if (_source == "extsysmon/network/ssid") { } else if (_source == "extsysmon/network/ssid") {
// current ssid // current ssid
m_map.insert(_source, "ssid"); m_map.insert(_source, "ssid");
m_formatter["ssid"] = AWKeysAggregator::FormatterType::NoFormat; m_formatter["ssid"] = AWPluginFormatterNoFormat::instance();
} else if (_source.startsWith("extsysmon/requests/response")) { } else if (_source.startsWith("extsysmon/requests/response")) {
// network response // network response
auto key = _source; auto key = _source;
key.remove("extsysmon/requests/"); key.remove("extsysmon/requests/");
m_map.insert(_source, key); m_map.insert(_source, key);
m_formatter[key] = AWKeysAggregator::FormatterType::NoFormat; m_formatter[key] = AWPluginFormatterNoFormat::instance();
} else if (_source.contains(netRegExp)) { } else if (_source.contains(netRegExp)) {
// network speed // network speed
auto type = _source.endsWith("download") ? "down" : "up"; auto type = _source.endsWith("download") ? "down" : "up";
@ -279,15 +282,15 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const KSy
// kb // kb
auto key = QString("%1kb%2").arg(type).arg(index); auto key = QString("%1kb%2").arg(type).arg(index);
m_map.insert(_source, key); m_map.insert(_source, key);
m_formatter[key] = AWKeysAggregator::FormatterType::MemKBFormat; m_formatter[key] = AWPluginFormatterMemory::instance();
// smart // smart
key = QString("%1%2").arg(type).arg(index); key = QString("%1%2").arg(type).arg(index);
m_map.insert(_source, key); m_map.insert(_source, key);
m_formatter[key] = AWKeysAggregator::FormatterType::NetSmartFormat; m_formatter[key] = AWPluginFormatterNet::instance();
// units // units
key = QString("%1units%2").arg(type).arg(index); key = QString("%1units%2").arg(type).arg(index);
m_map.insert(_source, key); m_map.insert(_source, key);
m_formatter[key] = AWKeysAggregator::FormatterType::NetSmartUnits; m_formatter[key] = AWPluginFormatterNetUnits::instance();
} }
} else if (_source.contains(netTotalRegExp)) { } else if (_source.contains(netTotalRegExp)) {
// network data total // network data total
@ -297,58 +300,58 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const KSy
// kb // kb
auto key = QString("%1totkb%2").arg(type).arg(index); auto key = QString("%1totkb%2").arg(type).arg(index);
m_map.insert(_source, key); m_map.insert(_source, key);
m_formatter[key] = AWKeysAggregator::FormatterType::MemKBFormat; m_formatter[key] = AWPluginFormatterMemory::instance();
// mb // mb
key = QString("%1tot%2").arg(type).arg(index); key = QString("%1tot%2").arg(type).arg(index);
m_map.insert(_source, key); m_map.insert(_source, key);
m_formatter[key] = AWKeysAggregator::FormatterType::MemMBFormat; m_formatter[key] = AWPluginFormatterMemoryMB::instance();
} }
} else if (_source.startsWith("extsysmon/upgrade")) { } else if (_source.startsWith("extsysmon/upgrade")) {
// package manager // package manager
auto key = _source; auto key = _source;
key.remove("extsysmon/upgrade/"); key.remove("extsysmon/upgrade/");
m_map.insert(_source, key); m_map.insert(_source, key);
m_formatter[key] = AWKeysAggregator::FormatterType::IntegerThree; m_formatter[key] = AWPluginFormatterIntegerShort::instance();
} else if (_source.startsWith("extsysmon/player")) { } else if (_source.startsWith("extsysmon/player")) {
// player // player
auto key = _source; auto key = _source;
key.remove("extsysmon/player/"); key.remove("extsysmon/player/");
m_map.insert(_source, key); m_map.insert(_source, key);
m_formatter[key] = AWKeysAggregator::FormatterType::NoFormat; m_formatter[key] = AWPluginFormatterNoFormat::instance();
} else if (_source == "extsysmon/ps/running") { } else if (_source == "extsysmon/ps/running") {
// running processes count // running processes count
m_map.insert(_source, "pscount"); m_map.insert(_source, "pscount");
m_formatter["pscount"] = AWKeysAggregator::FormatterType::NoFormat; m_formatter["pscount"] = AWPluginFormatterNoFormat::instance();
} else if (_source == "extsysmon/ps/list") { } else if (_source == "extsysmon/ps/list") {
// list of running processes // list of running processes
m_map.insert(_source, "ps"); m_map.insert(_source, "ps");
m_formatter["ps"] = AWKeysAggregator::FormatterType::List; m_formatter["ps"] = AWPluginFormatterList::instance();
} else if (_source == "extsysmon/ps/count") { } else if (_source == "extsysmon/ps/count") {
// total processes count // total processes count
m_map.insert(_source, "pstot"); m_map.insert(_source, "pstot");
m_formatter["pstot"] = AWKeysAggregator::FormatterType::NoFormat; m_formatter["pstot"] = AWPluginFormatterNoFormat::instance();
} else if (_source.startsWith("extsysmon/quotes")) { } else if (_source.startsWith("extsysmon/quotes")) {
// quotes // quotes
auto key = _source; auto key = _source;
key.remove("extsysmon/quotes/"); key.remove("extsysmon/quotes/");
m_map.insert(_source, key); m_map.insert(_source, key);
m_formatter[key] = AWKeysAggregator::FormatterType::Quotes; m_formatter[key] = AWPluginFormatterDouble::instance();
} else if (_source == "memory/swap/free") { } else if (_source == "memory/swap/free") {
// free swap // free swap
// mb // mb
m_map.insert(_source, "swapfreemb"); m_map.insert(_source, "swapfreemb");
m_formatter["swapfreemb"] = AWKeysAggregator::FormatterType::MemMBFormat; m_formatter["swapfreemb"] = AWPluginFormatterMemoryMB::instance();
// gb // gb
m_map.insert(_source, "swapfreegb"); m_map.insert(_source, "swapfreegb");
m_formatter["swapfreegb"] = AWKeysAggregator::FormatterType::MemGBFormat; m_formatter["swapfreegb"] = AWPluginFormatterMemoryGB::instance();
} else if (_source == "memory/swap/used") { } else if (_source == "memory/swap/used") {
// used swap // used swap
// mb // mb
m_map.insert(_source, "swapmb"); m_map.insert(_source, "swapmb");
m_formatter["swapmb"] = AWKeysAggregator::FormatterType::MemMBFormat; m_formatter["swapmb"] = AWPluginFormatterMemoryMB::instance();
// gb // gb
m_map.insert(_source, "swapgb"); m_map.insert(_source, "swapgb");
m_formatter["swapgb"] = AWKeysAggregator::FormatterType::MemGBFormat; m_formatter["swapgb"] = AWPluginFormatterMemoryGB::instance();
} else if (_source.startsWith("lmsensors/") || _source.contains(cpuTempRegExp) } else if (_source.startsWith("lmsensors/") || _source.contains(cpuTempRegExp)
|| _source == "cpu/all/averageTemperature") { || _source == "cpu/all/averageTemperature") {
// temperature // temperature
@ -359,59 +362,58 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const KSy
if (index > -1) { if (index > -1) {
auto key = QString("temp%1").arg(index); auto key = QString("temp%1").arg(index);
m_map.insert(_source, key); m_map.insert(_source, key);
m_formatter[key] = _units == KSysGuard::UnitCelsius ? AWKeysAggregator::FormatterType::Temperature if (_units == KSysGuard::UnitCelsius)
: AWKeysAggregator::FormatterType::Integer; m_formatter[key] = AWPluginFormatterTemperature::instance();
else
m_formatter[key] = AWPluginFormatterInteger::instance();
} }
} else if (_source == "extsysmon/time/now") { } 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"] = AWPluginFormatterTime::instance();
// custom time // custom time
m_map.insert(_source, "ctime"); m_map.insert(_source, "ctime");
m_formatter["ctime"] = AWKeysAggregator::FormatterType::TimeCustom; m_formatter["ctime"] = AWPluginFormatterTimeCustom::instance();
// ISO time // ISO time
m_map.insert(_source, "isotime"); m_map.insert(_source, "isotime");
m_formatter["isotime"] = AWKeysAggregator::FormatterType::TimeISO; m_formatter["isotime"] = AWPluginFormatterTimeISO::instance();
// long time // long time
m_map.insert(_source, "longtime"); m_map.insert(_source, "longtime");
m_formatter["longtime"] = AWKeysAggregator::FormatterType::TimeLong; m_formatter["longtime"] = AWPluginFormatterTimeLong::instance();
// short time // short time
m_map.insert(_source, "shorttime"); m_map.insert(_source, "shorttime");
m_formatter["shorttime"] = AWKeysAggregator::FormatterType::TimeShort; m_formatter["shorttime"] = AWPluginFormatterTimeShort::instance();
// timestamp // timestamp
m_map.insert(_source, "tstime"); m_map.insert(_source, "tstime");
m_formatter["tstime"] = AWKeysAggregator::FormatterType::Timestamp; m_formatter["tstime"] = AWPluginFormatterNoFormat::instance();
} else if (_source == "extsysmon/system/brightness") { } else if (_source == "extsysmon/system/brightness") {
m_map.insert(_source, "brightness"); m_map.insert(_source, "brightness");
m_formatter["brightness"] = AWKeysAggregator::FormatterType::IntegerThree; m_formatter["brightness"] = AWPluginFormatterIntegerShort::instance();
} else if (_source == "extsysmon/system/volume") { } else if (_source == "extsysmon/system/volume") {
m_map.insert(_source, "volume"); m_map.insert(_source, "volume");
m_formatter["volume"] = AWKeysAggregator::FormatterType::IntegerThree; m_formatter["volume"] = AWPluginFormatterIntegerShort::instance();
} else if (_source == "os/system/uptime") { } else if (_source == "os/system/uptime") {
// uptime // uptime
m_map.insert(_source, "uptime"); m_map.insert(_source, "uptime");
m_formatter["uptime"] = AWKeysAggregator::FormatterType::Uptime; m_formatter["uptime"] = AWPluginFormatterUptime::instance();
// custom uptime
m_map.insert(_source, "cuptime");
m_formatter["cuptime"] = AWKeysAggregator::FormatterType::UptimeCustom;
} else if (_source.startsWith("extsysmon/weather/temperature")) { } else if (_source.startsWith("extsysmon/weather/temperature")) {
// temperature // temperature
auto key = _source; auto key = _source;
key.remove("extsysmon/weather/"); key.remove("extsysmon/weather/");
m_map.insert(_source, key); m_map.insert(_source, key);
m_formatter[key] = AWKeysAggregator::FormatterType::Temperature; m_formatter[key] = AWPluginFormatterTemperature::instance();
} else if (_source.startsWith("extsysmon/weather/")) { } else if (_source.startsWith("extsysmon/weather/")) {
// other weather // other weather
auto key = _source; auto key = _source;
key.remove("extsysmon/weather/"); key.remove("extsysmon/weather/");
m_map.insert(_source, key); m_map.insert(_source, key);
m_formatter[key] = AWKeysAggregator::FormatterType::NoFormat; m_formatter[key] = AWPluginFormatterNoFormat::instance();
} else if (_source.startsWith("extsysmon/load/load")) { } else if (_source.startsWith("extsysmon/load/load")) {
// load source // load source
auto key = _source; auto key = _source;
key.remove("extsysmon/load/"); key.remove("extsysmon/load/");
m_map.insert(_source, key); m_map.insert(_source, key);
m_formatter[key] = AWKeysAggregator::FormatterType::Temperature; m_formatter[key] = AWPluginFormatterTemperature::instance();
} }
auto foundKeys = keysFromSource(_source); auto foundKeys = keysFromSource(_source);
@ -424,7 +426,7 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const KSy
for (auto &key : foundKeys) { for (auto &key : foundKeys) {
if (!customFormattersKeys.contains(key)) if (!customFormattersKeys.contains(key))
continue; continue;
m_formatter[key] = AWKeysAggregator::FormatterType::Custom; m_formatter[key] = AWPluginFormatterCustom::instance();
} }
// drop key from dictionary if no one user requested key required it // drop key from dictionary if no one user requested key required it

View File

@ -22,7 +22,7 @@
#include <QMultiHash> #include <QMultiHash>
#include <QObject> #include <QObject>
#include "awkeysaggregator.h" #include "formatters/awpluginformatter.h"
class AWFormatterHelper; class AWFormatterHelper;
@ -35,7 +35,7 @@ public:
explicit AWDataEngineMapper(QObject *_parent = nullptr, AWFormatterHelper *_custom = nullptr); explicit AWDataEngineMapper(QObject *_parent = nullptr, AWFormatterHelper *_custom = nullptr);
~AWDataEngineMapper() override = default; ~AWDataEngineMapper() override = default;
// get methods // get methods
[[nodiscard]] AWKeysAggregator::FormatterType formatter(const QString &_key) const; [[nodiscard]] AWPluginFormaterInterface *formatter(const QString &_key) const;
[[nodiscard]] QStringList keysFromSource(const QString &_source) const; [[nodiscard]] QStringList keysFromSource(const QString &_source) const;
// set methods // set methods
QStringList registerSource(const QString &_source, KSysGuard::Unit _units, const QStringList &_keys); QStringList registerSource(const QString &_source, KSysGuard::Unit _units, const QStringList &_keys);
@ -45,6 +45,6 @@ private:
AWFormatterHelper *m_customFormatters = nullptr; AWFormatterHelper *m_customFormatters = nullptr;
// variables // variables
QHash<QString, QStringList> m_devices; QHash<QString, QStringList> m_devices;
QHash<QString, AWKeysAggregator::FormatterType> m_formatter; QHash<QString, AWPluginFormaterInterface *> m_formatter;
QMultiHash<QString, QString> m_map; QMultiHash<QString, QString> m_map;
}; };

View File

@ -17,15 +17,9 @@
#include "awkeysaggregator.h" #include "awkeysaggregator.h"
#include <KI18n/KLocalizedString>
#include <QDateTime>
#include <QLocale>
#include "awdataenginemapper.h" #include "awdataenginemapper.h"
#include "awdebug.h" #include "awdebug.h"
#include "awformatterhelper.h" #include "awformatterhelper.h"
#include "version.h"
AWKeysAggregator::AWKeysAggregator(QObject *_parent) AWKeysAggregator::AWKeysAggregator(QObject *_parent)
@ -33,19 +27,38 @@ AWKeysAggregator::AWKeysAggregator(QObject *_parent)
{ {
qCDebug(LOG_AW) << __PRETTY_FUNCTION__; qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
m_customFormatters = new AWFormatterHelper(this); m_settings.customFormatters = new AWFormatterHelper(this);
m_mapper = new AWDataEngineMapper(this, m_customFormatters); m_mapper = new AWDataEngineMapper(this, m_settings.customFormatters);
// sort time keys
m_timeKeys = QString(TIME_KEYS).split(',');
m_timeKeys.sort();
std::reverse(m_timeKeys.begin(), m_timeKeys.end());
} }
void AWKeysAggregator::initFormatters() void AWKeysAggregator::initFormatters()
{ {
m_customFormatters->initItems(); m_settings.customFormatters->initItems();
}
QString AWKeysAggregator::acOffline() const
{
return m_settings.acOffline;
}
QString AWKeysAggregator::acOnline() const
{
return m_settings.acOnline;
}
QString AWKeysAggregator::customTime() const
{
return m_settings.customTime;
}
QString AWKeysAggregator::customUptime() const
{
return m_settings.customUptime;
} }
@ -53,113 +66,7 @@ QString AWKeysAggregator::formatter(const QVariant &_data, const QString &_key,
{ {
qCDebug(LOG_AW) << "Data" << _data << "for key" << _key; qCDebug(LOG_AW) << "Data" << _data << "for key" << _key;
QString output; auto output = m_mapper->formatter(_key)->format(_data, _key, m_settings);
QLocale loc = m_translate ? QLocale::system() : QLocale::c();
// case block
switch (m_mapper->formatter(_key)) {
case FormatterType::Float:
output = QString("%1").arg(_data.toDouble(), 5, 'f', 1);
break;
case FormatterType::FloatTwoSymbols:
output = QString("%1").arg(_data.toDouble(), 5, 'f', 2);
break;
case FormatterType::Integer:
output = QString("%1").arg(_data.toDouble(), 4, 'f', 0);
break;
case FormatterType::IntegerFive:
output = QString("%1").arg(_data.toDouble(), 5, 'f', 0);
break;
case FormatterType::IntegerThree:
output = QString("%1").arg(_data.toDouble(), 3, 'f', 0);
break;
case FormatterType::List:
output = _data.toStringList().join(',');
break;
case FormatterType::ACFormat:
output = _data.toBool() ? m_acOnline : m_acOffline;
break;
case FormatterType::MemGBFormat:
output = QString("%1").arg(_data.toDouble() / GBinBytes, 5, 'f', 1);
break;
case FormatterType::MemMBFormat:
output = QString("%1").arg(_data.toDouble() / MBinBytes, 5, 'f', 0);
break;
case FormatterType::MemKBFormat:
output = QString("%1").arg(_data.toDouble() / KBinBytes, 5, 'f', 0);
break;
case FormatterType::NetSmartFormat:
output = [](const double value) {
if (value > MBinBytes)
return QString("%1").arg(value / MBinBytes, 4, 'f', 1);
else
return QString("%1").arg(value / KBinBytes, 4, 'f', 0);
}(_data.toDouble());
break;
case FormatterType::NetSmartUnits:
if (_data.toDouble() > MBinBytes)
output = m_translate ? i18n("MB/s") : "MB/s";
else
output = m_translate ? i18n("KB/s") : "KB/s";
break;
case FormatterType::Quotes:
// first cast
output = QString("%1").arg(_data.toDouble(), 0, 'f');
output = output.rightJustified(8, QLatin1Char(' '), true);
break;
case FormatterType::Temperature:
output = QString("%1").arg(temperature(_data.toDouble()), 5, 'f', 1);
break;
case FormatterType::Time:
output = QDateTime::fromSecsSinceEpoch(_data.toLongLong()).toString();
break;
case FormatterType::TimeCustom:
output = m_customTime;
[&output, loc, this](const QDateTime &dt) {
for (auto &key : m_timeKeys)
output.replace(QString("$%1").arg(key), loc.toString(dt, key));
}(QDateTime::fromSecsSinceEpoch(_data.toLongLong()));
break;
case FormatterType::TimeISO:
output = QDateTime::fromSecsSinceEpoch(_data.toLongLong()).toString(Qt::ISODate);
break;
case FormatterType::TimeLong:
output = loc.toString(QDateTime::fromSecsSinceEpoch(_data.toLongLong()), QLocale::LongFormat);
break;
case FormatterType::TimeShort:
output = loc.toString(QDateTime::fromSecsSinceEpoch(_data.toLongLong()), QLocale::ShortFormat);
break;
case FormatterType::Timestamp:
output = _data.toString();
break;
case FormatterType::Uptime:
case FormatterType::UptimeCustom:
output =
[](auto source, auto uptime) {
auto seconds = uptime - uptime % 60;
auto minutes = seconds / 60 % 60;
auto hours = ((seconds / 60) - minutes) / 60 % 24;
auto days = (((seconds / 60) - minutes) / 60 - hours) / 24;
source.replace("$dd", QString("%1").arg(days, 3, 10, QChar('0')));
source.replace("$d", QString("%1").arg(days));
source.replace("$hh", QString("%1").arg(hours, 2, 10, QChar('0')));
source.replace("$h", QString("%1").arg(hours));
source.replace("$mm", QString("%1").arg(minutes, 2, 10, QChar('0')));
source.replace("$m", QString("%1").arg(minutes));
return source;
}(m_mapper->formatter(_key) == FormatterType::Uptime ? "$ddd$hhh$mmm" : m_customUptime,
static_cast<int>(_data.toDouble()));
break;
case FormatterType::NoFormat:
output = _data.toString();
break;
case FormatterType::Custom:
if (m_customFormatters)
output = m_customFormatters->convert(_data, _key);
break;
}
// replace spaces to non-breakable ones // replace spaces to non-breakable ones
replaceSpace &= (!_key.startsWith("custom") && (!_key.startsWith("weather"))); replaceSpace &= (!_key.startsWith("custom") && (!_key.startsWith("weather")));
if (replaceSpace) if (replaceSpace)
@ -177,11 +84,23 @@ QStringList AWKeysAggregator::keysFromSource(const QString &_source) const
} }
QString AWKeysAggregator::tempUnits() const
{
return m_settings.tempUnits;
}
bool AWKeysAggregator::translate() const
{
return m_settings.translate;
}
void AWKeysAggregator::setAcOffline(const QString &_inactive) void AWKeysAggregator::setAcOffline(const QString &_inactive)
{ {
qCDebug(LOG_AW) << "Inactive AC string" << _inactive; qCDebug(LOG_AW) << "Inactive AC string" << _inactive;
m_acOffline = _inactive; m_settings.acOffline = _inactive;
} }
@ -189,7 +108,7 @@ void AWKeysAggregator::setAcOnline(const QString &_active)
{ {
qCDebug(LOG_AW) << "Active AC string" << _active; qCDebug(LOG_AW) << "Active AC string" << _active;
m_acOnline = _active; m_settings.acOnline = _active;
} }
@ -197,7 +116,7 @@ void AWKeysAggregator::setCustomTime(const QString &_customTime)
{ {
qCDebug(LOG_AW) << "Format" << _customTime; qCDebug(LOG_AW) << "Format" << _customTime;
m_customTime = _customTime; m_settings.customTime = _customTime;
} }
@ -205,7 +124,7 @@ void AWKeysAggregator::setCustomUptime(const QString &_customUptime)
{ {
qCDebug(LOG_AW) << "Format" << _customUptime; qCDebug(LOG_AW) << "Format" << _customUptime;
m_customUptime = _customUptime; m_settings.customUptime = _customUptime;
} }
@ -221,7 +140,7 @@ void AWKeysAggregator::setTempUnits(const QString &_units)
{ {
qCDebug(LOG_AW) << "Units" << _units; qCDebug(LOG_AW) << "Units" << _units;
m_tempUnits = _units; m_settings.tempUnits = _units;
} }
@ -229,7 +148,7 @@ void AWKeysAggregator::setTranslate(const bool _translate)
{ {
qCDebug(LOG_AW) << "Translate" << _translate; qCDebug(LOG_AW) << "Translate" << _translate;
m_translate = _translate; m_settings.translate = _translate;
} }
@ -240,29 +159,3 @@ QStringList AWKeysAggregator::registerSource(const QString &_source, const KSysG
return m_mapper->registerSource(_source, _units, _keys); return m_mapper->registerSource(_source, _units, _keys);
} }
double AWKeysAggregator::temperature(const double temp) const
{
qCDebug(LOG_AW) << "Temperature value" << temp;
auto converted = temp;
if (m_tempUnits == "Celsius") {
} else if (m_tempUnits == "Fahrenheit") {
converted = temp * 9.0f / 5.0 + 32.0;
} else if (m_tempUnits == "Kelvin") {
converted = temp + 273.15;
} else if (m_tempUnits == "Reaumur") {
converted = temp * 0.8;
} else if (m_tempUnits == "cm^-1") {
converted = (temp + 273.15) * 0.695;
} else if (m_tempUnits == "kJ/mol") {
converted = (temp + 273.15) * 8.31;
} else if (m_tempUnits == "kcal/mol") {
converted = (temp + 273.15) * 1.98;
} else {
qCWarning(LOG_AW) << "Invalid units" << m_tempUnits;
}
return converted;
}

View File

@ -22,60 +22,35 @@
#include <QHash> #include <QHash>
#include <QObject> #include <QObject>
#include "formatters/awpluginformatsettings.h"
class AWFormatterHelper;
class AWDataEngineMapper; class AWDataEngineMapper;
class AWKeysAggregator : public QObject class AWKeysAggregator : public QObject
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QString acOffline MEMBER m_acOffline WRITE setAcOffline); Q_PROPERTY(QString acOffline READ acOffline WRITE setAcOffline);
Q_PROPERTY(QString acOnline MEMBER m_acOnline WRITE setAcOnline); Q_PROPERTY(QString acOnline READ acOnline WRITE setAcOnline);
Q_PROPERTY(QString customTime MEMBER m_customTime WRITE setCustomTime); Q_PROPERTY(QString customTime READ customTime WRITE setCustomTime);
Q_PROPERTY(QString customUptime MEMBER m_customUptime WRITE setCustomUptime); Q_PROPERTY(QString customUptime READ customUptime WRITE setCustomUptime);
Q_PROPERTY(QString tempUnits MEMBER m_tempUnits WRITE setTempUnits); Q_PROPERTY(QString tempUnits READ tempUnits WRITE setTempUnits);
Q_PROPERTY(bool translate MEMBER m_translate WRITE setTranslate); Q_PROPERTY(bool translate READ translate WRITE setTranslate);
public: public:
enum class FormatterType {
// general formatters
Custom,
NoFormat,
Float,
FloatTwoSymbols,
Integer,
IntegerFive,
IntegerThree,
List,
// unit specific formatters
ACFormat,
MemGBFormat,
MemMBFormat,
MemKBFormat,
NetSmartFormat,
NetSmartUnits,
Quotes,
Temperature,
Time,
TimeCustom,
TimeISO,
TimeLong,
TimeShort,
Timestamp,
Uptime,
UptimeCustom
};
static constexpr double KBinBytes = 1024.0;
static constexpr double MBinBytes = 1024.0 * KBinBytes;
static constexpr double GBinBytes = 1024.0 * MBinBytes;
explicit AWKeysAggregator(QObject *_parent = nullptr); explicit AWKeysAggregator(QObject *_parent = nullptr);
~AWKeysAggregator() override = default; ~AWKeysAggregator() override = default;
void initFormatters(); void initFormatters();
// get methods // get methods
[[nodiscard]] QString acOffline() const;
[[nodiscard]] QString acOnline() const;
[[nodiscard]] QString customTime() const;
[[nodiscard]] QString customUptime() const;
[[nodiscard]] QString formatter(const QVariant &_data, const QString &_key, bool replaceSpace) const; [[nodiscard]] QString formatter(const QVariant &_data, const QString &_key, bool replaceSpace) const;
[[nodiscard]] QStringList keysFromSource(const QString &_source) const; [[nodiscard]] QStringList keysFromSource(const QString &_source) const;
[[nodiscard]] QString tempUnits() const;
[[nodiscard]] bool translate() const;
// set methods // set methods
void setAcOffline(const QString &_inactive); void setAcOffline(const QString &_inactive);
void setAcOnline(const QString &_active); void setAcOnline(const QString &_active);
@ -89,15 +64,6 @@ public slots:
QStringList registerSource(const QString &_source, KSysGuard::Unit _units, const QStringList &_keys); QStringList registerSource(const QString &_source, KSysGuard::Unit _units, const QStringList &_keys);
private: private:
[[nodiscard]] double temperature(double temp) const; AWPluginFormatSettings m_settings;
AWFormatterHelper *m_customFormatters = nullptr;
AWDataEngineMapper *m_mapper = nullptr; AWDataEngineMapper *m_mapper = nullptr;
QStringList m_timeKeys;
// variables
QString m_acOffline;
QString m_acOnline;
QString m_customTime;
QString m_customUptime;
QString m_tempUnits;
bool m_translate = false;
}; };

View File

@ -0,0 +1,37 @@
/***************************************************************************
* 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 <QString>
class AWFormatterHelper;
struct AWPluginFormatSettings {
QString acOffline;
QString acOnline;
QString customTime;
QString customUptime;
QString tempUnits;
bool translate = false;
AWFormatterHelper *customFormatters = nullptr;
};

View File

@ -0,0 +1,64 @@
/***************************************************************************
* 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 <QLocale>
#include <QVariant>
#include <memory>
#include "awpluginformatsettings.h"
class AWPluginFormaterInterface {
public:
virtual ~AWPluginFormaterInterface() = default;
virtual QString format(const QVariant &_value, const QString &_key, const AWPluginFormatSettings &_settings) const = 0;
virtual void load() {};
};
template<typename Formatter> class AWPluginFormatter : public AWPluginFormaterInterface {
public:
static constexpr double KBinBytes = 1024.0;
static constexpr double MBinBytes = 1024.0 * KBinBytes;
static constexpr double GBinBytes = 1024.0 * MBinBytes;
AWPluginFormatter(AWPluginFormatter &) = delete;
void operator=(const AWPluginFormatter &) = delete;
static Formatter *instance()
{
static auto instance = loadInstance();
return instance.get();
};
static QLocale locale(const AWPluginFormatSettings &_settings)
{
return _settings.translate ? QLocale::system() : QLocale::c();
};
protected:
AWPluginFormatter() = default;
static std::unique_ptr<Formatter> loadInstance()
{
auto instance = std::make_unique<Formatter>();
instance->load();
return instance;
};
};

View File

@ -0,0 +1,24 @@
/***************************************************************************
* 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 "awpluginformatterac.h"
QString AWPluginFormatterAC::format(const QVariant &_value, const QString &, const AWPluginFormatSettings &_settings) const
{
return _value.toBool() ? _settings.acOnline : _settings.acOffline;
}

View File

@ -0,0 +1,27 @@
/***************************************************************************
* 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 "awpluginformatter.h"
class AWPluginFormatterAC : public AWPluginFormatter<AWPluginFormatterAC> {
public:
QString format(const QVariant &_value, const QString &, const AWPluginFormatSettings &_settings) const override;
};

View File

@ -0,0 +1,28 @@
/***************************************************************************
* 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 "awpluginformattercustom.h"
#include "awformatterhelper.h"
QString AWPluginFormatterCustom::format(const QVariant &_value, const QString &_key, const AWPluginFormatSettings &_settings) const
{
if (_settings.customFormatters)
return _settings.customFormatters->convert(_value, _key);
return _value.toString();
}

View File

@ -0,0 +1,27 @@
/***************************************************************************
* 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 "awpluginformatter.h"
class AWPluginFormatterCustom : public AWPluginFormatter<AWPluginFormatterCustom> {
public:
QString format(const QVariant &_value, const QString &_key, const AWPluginFormatSettings &_settings) const override;
};

View File

@ -0,0 +1,25 @@
/***************************************************************************
* 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 "awpluginformatterdouble.h"
QString AWPluginFormatterDouble::format(const QVariant &_value, const QString &, const AWPluginFormatSettings &) const
{
auto output = QString("%1").arg(_value.toDouble(), 0, 'f');
return output.rightJustified(8, QLatin1Char(' '), true);
}

View File

@ -0,0 +1,27 @@
/***************************************************************************
* 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 "awpluginformatter.h"
class AWPluginFormatterDouble : public AWPluginFormatter<AWPluginFormatterDouble> {
public:
QString format(const QVariant &_value, const QString &, const AWPluginFormatSettings &) const override;
};

View File

@ -0,0 +1,24 @@
/***************************************************************************
* 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 "awpluginformatterfloat.h"
QString AWPluginFormatterFloat::format(const QVariant &_value, const QString &, const AWPluginFormatSettings &) const
{
return QString("%1").arg(_value.toDouble(), 5, 'f', 1);
}

View File

@ -0,0 +1,27 @@
/***************************************************************************
* 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 "awpluginformatter.h"
class AWPluginFormatterFloat : public AWPluginFormatter<AWPluginFormatterFloat>{
public:
QString format(const QVariant &_value, const QString &, const AWPluginFormatSettings &) const override;
};

View File

@ -0,0 +1,24 @@
/***************************************************************************
* 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 "awpluginformatterfloatprecise.h"
QString AWPluginFormatterFloatPrecise::format(const QVariant &_value, const QString &, const AWPluginFormatSettings &) const
{
return QString("%1").arg(_value.toDouble(), 5, 'f', 2);
}

View File

@ -0,0 +1,27 @@
/***************************************************************************
* 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 "awpluginformatter.h"
class AWPluginFormatterFloatPrecise : public AWPluginFormatter<AWPluginFormatterFloatPrecise> {
public:
QString format(const QVariant &_value, const QString &, const AWPluginFormatSettings &) const override;
};

View File

@ -0,0 +1,24 @@
/***************************************************************************
* 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 "awpluginformatterinteger.h"
QString AWPluginFormatterInteger::format(const QVariant &_value, const QString &, const AWPluginFormatSettings &) const
{
return QString("%1").arg(_value.toDouble(), 4, 'f', 0);
}

View File

@ -0,0 +1,27 @@
/***************************************************************************
* 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 "awpluginformatter.h"
class AWPluginFormatterInteger : public AWPluginFormatter<AWPluginFormatterInteger> {
public:
QString format(const QVariant &_value, const QString &, const AWPluginFormatSettings &) const override;
};

View File

@ -0,0 +1,24 @@
/***************************************************************************
* 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 "awpluginformatterintegershort.h"
QString AWPluginFormatterIntegerShort::format(const QVariant &_value, const QString &, const AWPluginFormatSettings &) const
{
return QString("%1").arg(_value.toDouble(), 3, 'f', 0);
}

View File

@ -0,0 +1,27 @@
/***************************************************************************
* 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 "awpluginformatter.h"
class AWPluginFormatterIntegerShort : public AWPluginFormatter<AWPluginFormatterIntegerShort> {
public:
QString format(const QVariant &_value, const QString &, const AWPluginFormatSettings &) const override;
};

View File

@ -0,0 +1,24 @@
/***************************************************************************
* 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 "awpluginformatterintegerwide.h"
QString AWPluginFormatterIntegerWide::format(const QVariant &_value, const QString &, const AWPluginFormatSettings &) const
{
return QString("%1").arg(_value.toDouble(), 5, 'f', 0);
}

View File

@ -0,0 +1,27 @@
/***************************************************************************
* 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 "awpluginformatter.h"
class AWPluginFormatterIntegerWide : public AWPluginFormatter<AWPluginFormatterIntegerWide> {
public:
QString format(const QVariant &_value, const QString &, const AWPluginFormatSettings &) const override;
};

View File

@ -0,0 +1,24 @@
/***************************************************************************
* 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 "awpluginformatterlist.h"
QString AWPluginFormatterList::format(const QVariant &_value, const QString &, const AWPluginFormatSettings &) const
{
return _value.toStringList().join(",");
}

View File

@ -0,0 +1,27 @@
/***************************************************************************
* 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 "awpluginformatter.h"
class AWPluginFormatterList : public AWPluginFormatter<AWPluginFormatterList> {
public:
QString format(const QVariant &_value, const QString &, const AWPluginFormatSettings &) const override;
};

View File

@ -0,0 +1,24 @@
/***************************************************************************
* 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 "awpluginformattermemory.h"
QString AWPluginFormatterMemory::format(const QVariant &_value, const QString &, const AWPluginFormatSettings &) const
{
return QString("%1").arg(_value.toDouble() / KBinBytes, 5, 'f', 0);
}

View File

@ -0,0 +1,27 @@
/***************************************************************************
* 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 "awpluginformatter.h"
class AWPluginFormatterMemory : public AWPluginFormatter<AWPluginFormatterMemory> {
public:
QString format(const QVariant &_value, const QString &, const AWPluginFormatSettings &) const override;
};

View File

@ -0,0 +1,24 @@
/***************************************************************************
* 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 "awpluginformattermemorygb.h"
QString AWPluginFormatterMemoryGB::format(const QVariant &_value, const QString &, const AWPluginFormatSettings &) const
{
return QString("%1").arg(_value.toDouble() / GBinBytes, 5, 'f', 1);
}

View File

@ -0,0 +1,27 @@
/***************************************************************************
* 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 "awpluginformatter.h"
class AWPluginFormatterMemoryGB : public AWPluginFormatter<AWPluginFormatterMemoryGB> {
public:
QString format(const QVariant &_value, const QString &, const AWPluginFormatSettings &) const override;
};

View File

@ -0,0 +1,24 @@
/***************************************************************************
* 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 "awpluginformattermemorymb.h"
QString AWPluginFormatterMemoryMB::format(const QVariant &_value, const QString &, const AWPluginFormatSettings &) const
{
return QString("%1").arg(_value.toDouble() / MBinBytes, 5, 'f', 0);
}

View File

@ -0,0 +1,27 @@
/***************************************************************************
* 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 "awpluginformatter.h"
class AWPluginFormatterMemoryMB : public AWPluginFormatter<AWPluginFormatterMemoryMB> {
public:
QString format(const QVariant &_value, const QString &, const AWPluginFormatSettings &) const override;
};

View File

@ -0,0 +1,37 @@
/***************************************************************************
* 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 "awpluginformatternet.h"
QString AWPluginFormatterNet::format(const QVariant &_value, const QString &, const AWPluginFormatSettings &) const
{
auto value = _value.toDouble();
return (value > MBinBytes) ? formatMB(value) : formatKB(value);
}
QString AWPluginFormatterNet::formatKB(const double &_value)
{
return QString("%1").arg(_value / KBinBytes, 4, 'f', 0);
}
QString AWPluginFormatterNet::formatMB(const double &_value)
{
return QString("%1").arg(_value / MBinBytes, 4, 'f', 1);
}

View File

@ -0,0 +1,31 @@
/***************************************************************************
* 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 "awpluginformatter.h"
class AWPluginFormatterNet : public AWPluginFormatter<AWPluginFormatterNet> {
public:
QString format(const QVariant &_value, const QString &, const AWPluginFormatSettings &) const override;
private:
static QString formatKB(const double &_value);
static QString formatMB(const double &_value);
};

View File

@ -0,0 +1,39 @@
/***************************************************************************
* 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 "awpluginformatternetunits.h"
#include <KI18n/KLocalizedString>
QString AWPluginFormatterNetUnits::format(const QVariant &_value, const QString &, const AWPluginFormatSettings &_settings) const
{
auto value = _value.toDouble();
return (value > MBinBytes) ? formatMB(_settings) : formatKB(_settings);
}
QString AWPluginFormatterNetUnits::formatKB(const AWPluginFormatSettings &_settings)
{
return _settings.translate ? i18n("KB/s") : "KB/s";
}
QString AWPluginFormatterNetUnits::formatMB(const AWPluginFormatSettings &_settings)
{
return _settings.translate ? i18n("MB/s") : "MB/s";
}

View File

@ -0,0 +1,31 @@
/***************************************************************************
* 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 "awpluginformatter.h"
class AWPluginFormatterNetUnits : public AWPluginFormatter<AWPluginFormatterNetUnits> {
public:
QString format(const QVariant &_value, const QString &, const AWPluginFormatSettings &_settings) const override;
private:
static QString formatKB(const AWPluginFormatSettings &_settings);
static QString formatMB(const AWPluginFormatSettings &_settings);
};

View File

@ -0,0 +1,24 @@
/***************************************************************************
* 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 "awpluginformatternoformat.h"
QString AWPluginFormatterNoFormat::format(const QVariant &_value, const QString &, const AWPluginFormatSettings &) const
{
return _value.toString();
}

View File

@ -0,0 +1,27 @@
/***************************************************************************
* 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 "awpluginformatter.h"
class AWPluginFormatterNoFormat : public AWPluginFormatter<AWPluginFormatterNoFormat> {
public:
QString format(const QVariant &_value, const QString &, const AWPluginFormatSettings &) const override;
};

View File

@ -0,0 +1,47 @@
/***************************************************************************
* 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 "awpluginformattertemperature.h"
QString AWPluginFormatterTemperature::format(const QVariant &_value, const QString &, const AWPluginFormatSettings &_settings) const
{
auto converted = convert(_value.toDouble(), _settings.tempUnits);
return QString("%1").arg(converted, 5, 'f', 1);
}
double AWPluginFormatterTemperature::convert(const double &_value, const QString &_units)
{
auto converted = _value;
if (_units == "Celsius") {
} else if (_units == "Fahrenheit") {
converted = _value * 9.0f / 5.0 + 32.0;
} else if (_units == "Kelvin") {
converted = _value + 273.15;
} else if (_units == "Reaumur") {
converted = _value * 0.8;
} else if (_units == "cm^-1") {
converted = (_value + 273.15) * 0.695;
} else if (_units == "kJ/mol") {
converted = (_value + 273.15) * 8.31;
} else if (_units == "kcal/mol") {
converted = (_value + 273.15) * 1.98;
}
return converted;
}

View File

@ -0,0 +1,30 @@
/***************************************************************************
* 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 "awpluginformatter.h"
class AWPluginFormatterTemperature : public AWPluginFormatter<AWPluginFormatterTemperature> {
public:
QString format(const QVariant &_value, const QString &, const AWPluginFormatSettings &_settings) const override;
private:
static double convert(const double &_value, const QString &_units);
};

View File

@ -0,0 +1,26 @@
/***************************************************************************
* 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 "awpluginformattertime.h"
#include <QDateTime>
QString AWPluginFormatterTime::format(const QVariant &_value, const QString &, const AWPluginFormatSettings &) const
{
return QDateTime::fromSecsSinceEpoch(_value.toLongLong()).toString();
}

View File

@ -0,0 +1,27 @@
/***************************************************************************
* 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 "awpluginformatter.h"
class AWPluginFormatterTime : public AWPluginFormatter<AWPluginFormatterTime> {
public:
QString format(const QVariant &_value, const QString &, const AWPluginFormatSettings &) const override;
};

View File

@ -0,0 +1,44 @@
/***************************************************************************
* 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 "awpluginformattertimecustom.h"
#include "awdebug.h"
QString AWPluginFormatterTimeCustom::format(const QVariant &_value, const QString &, const AWPluginFormatSettings &_settings) const
{
auto value = QDateTime::fromSecsSinceEpoch(_value.toLongLong());
return format(value, _settings.customTime, locale(_settings));
}
void AWPluginFormatterTimeCustom::load()
{
m_timeKeys = QString(TIME_KEYS).split(',');
m_timeKeys.sort();
std::reverse(m_timeKeys.begin(), m_timeKeys.end());
}
QString AWPluginFormatterTimeCustom::format(const QDateTime &_value, QString _formatString, const QLocale &_locale) const
{
for (auto &key : m_timeKeys)
_formatString.replace(QString("$%1").arg(key), _locale.toString(_value, key));
return _formatString;
}

View File

@ -0,0 +1,34 @@
/***************************************************************************
* 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 <QDateTime>
#include "awpluginformatter.h"
class AWPluginFormatterTimeCustom : public AWPluginFormatter<AWPluginFormatterTimeCustom> {
public:
QString format(const QVariant &_value, const QString &, const AWPluginFormatSettings &_settings) const override;
void load() override;
private:
QString format(const QDateTime &_value, QString _formatString, const QLocale &_locale) const;
QStringList m_timeKeys;
};

View File

@ -0,0 +1,26 @@
/***************************************************************************
* 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 "awpluginformattertimeiso.h"
#include <QDateTime>
QString AWPluginFormatterTimeISO::format(const QVariant &_value, const QString &, const AWPluginFormatSettings &) const
{
return QDateTime::fromSecsSinceEpoch(_value.toLongLong()).toString(Qt::ISODate);
}

View File

@ -0,0 +1,27 @@
/***************************************************************************
* 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 "awpluginformatter.h"
class AWPluginFormatterTimeISO : public AWPluginFormatter<AWPluginFormatterTimeISO> {
public:
QString format(const QVariant &_value, const QString &, const AWPluginFormatSettings &) const override;
};

View File

@ -0,0 +1,26 @@
/***************************************************************************
* 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 "awpluginformattertimelong.h"
#include <QDateTime>
QString AWPluginFormatterTimeLong::format(const QVariant &_value, const QString &, const AWPluginFormatSettings &_settings) const
{
return locale(_settings).toString(QDateTime::fromSecsSinceEpoch(_value.toLongLong()), QLocale::LongFormat);
}

View File

@ -0,0 +1,27 @@
/***************************************************************************
* 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 "awpluginformatter.h"
class AWPluginFormatterTimeLong : public AWPluginFormatter<AWPluginFormatterTimeLong> {
public:
QString format(const QVariant &_value, const QString &, const AWPluginFormatSettings &_settings) const override;
};

View File

@ -0,0 +1,26 @@
/***************************************************************************
* 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 "awpluginformattertimeshort.h"
#include <QDateTime>
QString AWPluginFormatterTimeShort::format(const QVariant &_value, const QString &, const AWPluginFormatSettings &_settings) const
{
return locale(_settings).toString(QDateTime::fromSecsSinceEpoch(_value.toLongLong()), QLocale::ShortFormat);
}

View File

@ -0,0 +1,27 @@
/***************************************************************************
* 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 "awpluginformatter.h"
class AWPluginFormatterTimeShort : public AWPluginFormatter<AWPluginFormatterTimeShort> {
public:
QString format(const QVariant &_value, const QString &, const AWPluginFormatSettings &_settings) const override;
};

View File

@ -0,0 +1,43 @@
/***************************************************************************
* 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 "awpluginformatteruptime.h"
QString AWPluginFormatterUptime::format(const QVariant &_value, const QString &, const AWPluginFormatSettings &_settings) const
{
auto value = static_cast<long>(_value.toDouble());
return format(value, _settings.customUptime);
}
QString AWPluginFormatterUptime::format(const long &_value, QString _formatString)
{
auto seconds = _value - _value % 60;
auto minutes = seconds / 60 % 60;
auto hours = ((seconds / 60) - minutes) / 60 % 24;
auto days = (((seconds / 60) - minutes) / 60 - hours) / 24;
_formatString.replace("$dd", QString("%1").arg(days, 3, 10, QChar('0')));
_formatString.replace("$d", QString("%1").arg(days));
_formatString.replace("$hh", QString("%1").arg(hours, 2, 10, QChar('0')));
_formatString.replace("$h", QString("%1").arg(hours));
_formatString.replace("$mm", QString("%1").arg(minutes, 2, 10, QChar('0')));
_formatString.replace("$m", QString("%1").arg(minutes));
return _formatString;
}

View File

@ -0,0 +1,30 @@
/***************************************************************************
* 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 "awpluginformatter.h"
class AWPluginFormatterUptime : public AWPluginFormatter<AWPluginFormatterUptime> {
public:
QString format(const QVariant &_value, const QString &, const AWPluginFormatSettings &_settings) const override;
private:
static QString format(const long &_value, QString _formatString);
};

View File

@ -0,0 +1,39 @@
/***************************************************************************
* 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 "awpluginformatterac.h"
#include "awpluginformattercustom.h"
#include "awpluginformatterdouble.h"
#include "awpluginformatterfloat.h"
#include "awpluginformatterfloatprecise.h"
#include "awpluginformatterinteger.h"
#include "awpluginformatterintegershort.h"
#include "awpluginformatterintegerwide.h"
#include "awpluginformatterlist.h"
#include "awpluginformattermemory.h"
#include "awpluginformattermemorygb.h"
#include "awpluginformattermemorymb.h"
#include "awpluginformatternet.h"
#include "awpluginformatternetunits.h"
#include "awpluginformatternoformat.h"
#include "awpluginformattertemperature.h"
#include "awpluginformattertime.h"
#include "awpluginformattertimecustom.h"
#include "awpluginformattertimeiso.h"
#include "awpluginformattertimelong.h"
#include "awpluginformattertimeshort.h"
#include "awpluginformatteruptime.h"

View File

@ -121,7 +121,7 @@ queueLimit=0
swapTooltip=true swapTooltip=true
swapTooltipColor=#ffff00 swapTooltipColor=#ffff00
tempUnits=Celsius tempUnits=Celsius
text="<body bgcolor=\"#000000\">\n<p align=\"justify\">Uptime: $cuptime<br>\nRAM: &nbsp;$mem&nbsp;&nbsp;$bar5<br>\nSwap: $swap&nbsp;&nbsp;$bar6<br>\nCPU: &nbsp;$cpu&nbsp;&nbsp;$bar7<br>\nCPU Temp: $temp0&deg;C<br>\nDown: $down$downunits&nbsp;&nbsp;&nbsp;&nbsp;$downtot<br>\n$bar8<br>\nUp:&nbsp;&nbsp; $up$upunits&nbsp;&nbsp;&nbsp;&nbsp;$uptot<br>\n$bar9<br></p>\n</body>\n" text="<body bgcolor=\"#000000\">\n<p align=\"justify\">Uptime: $uptime<br>\nRAM: &nbsp;$mem&nbsp;&nbsp;$bar5<br>\nSwap: $swap&nbsp;&nbsp;$bar6<br>\nCPU: &nbsp;$cpu&nbsp;&nbsp;$bar7<br>\nCPU Temp: $temp0&deg;C<br>\nDown: $down$downunits&nbsp;&nbsp;&nbsp;&nbsp;$downtot<br>\n$bar8<br>\nUp:&nbsp;&nbsp; $up$upunits&nbsp;&nbsp;&nbsp;&nbsp;$uptot<br>\n$bar9<br></p>\n</body>\n"
textAlign=center textAlign=center
tooltipBackground=#ffffff tooltipBackground=#ffffff
tooltipNumber=100 tooltipNumber=100

View File

@ -67,7 +67,6 @@ static const char STATIC_KEYS[] = "time,"
"tstime," "tstime,"
"ctime," "ctime,"
"uptime," "uptime,"
"cuptime,"
"cpucl," "cpucl,"
"cpu," "cpu,"
"gpu," "gpu,"