diff --git a/sources/awesome-widget/plugin/CMakeLists.txt b/sources/awesome-widget/plugin/CMakeLists.txt index b33c698..866a8db 100644 --- a/sources/awesome-widget/plugin/CMakeLists.txt +++ b/sources/awesome-widget/plugin/CMakeLists.txt @@ -10,7 +10,7 @@ include_directories( ${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_NOTIFY *.notifyrc) diff --git a/sources/awesome-widget/plugin/awdataenginemapper.cpp b/sources/awesome-widget/plugin/awdataenginemapper.cpp index fa2b371..fa4db54 100644 --- a/sources/awesome-widget/plugin/awdataenginemapper.cpp +++ b/sources/awesome-widget/plugin/awdataenginemapper.cpp @@ -21,6 +21,7 @@ #include "awdebug.h" #include "awformatterhelper.h" +#include "formatters/formatters.h" AWDataEngineMapper::AWDataEngineMapper(QObject *_parent, AWFormatterHelper *_custom) @@ -31,32 +32,32 @@ AWDataEngineMapper::AWDataEngineMapper(QObject *_parent, AWFormatterHelper *_cus // default formatters // memory - m_formatter["mem"] = AWKeysAggregator::FormatterType::Float; - m_formatter["memtotmb"] = AWKeysAggregator::FormatterType::MemMBFormat; - m_formatter["memtotgb"] = AWKeysAggregator::FormatterType::MemGBFormat; + m_formatter["mem"] = AWPluginFormatterFloat::instance(); + m_formatter["memtotmb"] = AWPluginFormatterMemoryMB::instance(); + m_formatter["memtotgb"] = AWPluginFormatterMemoryGB::instance(); // network - m_formatter["down"] = AWKeysAggregator::FormatterType::NetSmartFormat; - m_formatter["downkb"] = AWKeysAggregator::FormatterType::Integer; - m_formatter["downtot"] = AWKeysAggregator::FormatterType::MemMBFormat; - m_formatter["downtotkb"] = AWKeysAggregator::FormatterType::Integer; - m_formatter["downunits"] = AWKeysAggregator::FormatterType::NetSmartUnits; - m_formatter["up"] = AWKeysAggregator::FormatterType::NetSmartFormat; - m_formatter["upkb"] = AWKeysAggregator::FormatterType::Integer; - m_formatter["uptot"] = AWKeysAggregator::FormatterType::MemMBFormat; - m_formatter["uptotkb"] = AWKeysAggregator::FormatterType::Integer; - m_formatter["upunits"] = AWKeysAggregator::FormatterType::NetSmartUnits; + m_formatter["down"] = AWPluginFormatterNet::instance(); + m_formatter["downkb"] = AWPluginFormatterMemory::instance(); + m_formatter["downtot"] = AWPluginFormatterMemoryMB::instance(); + m_formatter["downtotkb"] = AWPluginFormatterMemory::instance(); + m_formatter["downunits"] = AWPluginFormatterNetUnits::instance(); + m_formatter["up"] = AWPluginFormatterNet::instance(); + m_formatter["upkb"] = AWPluginFormatterMemory::instance(); + m_formatter["uptot"] = AWPluginFormatterMemoryMB::instance(); + m_formatter["uptotkb"] = AWPluginFormatterMemory::instance(); + m_formatter["upunits"] = AWPluginFormatterNetUnits::instance(); // swap - m_formatter["swap"] = AWKeysAggregator::FormatterType::Float; - m_formatter["swaptotmb"] = AWKeysAggregator::FormatterType::MemMBFormat; - m_formatter["swaptotgb"] = AWKeysAggregator::FormatterType::MemGBFormat; + m_formatter["swap"] = AWPluginFormatterFloat::instance(); + m_formatter["swaptotmb"] = AWPluginFormatterMemoryMB::instance(); + 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; - 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") { // AC m_map.insert(_source, "ac"); - m_formatter["ac"] = AWKeysAggregator::FormatterType::ACFormat; + m_formatter["ac"] = AWPluginFormatterAC::instance(); } else if (_source.startsWith("extsysmon/battery/")) { // battery stats auto key = _source; key.remove("extsysmon/battery/"); m_map.insert(_source, key); - m_formatter[key] = _source.contains("rate") ? AWKeysAggregator::FormatterType::Float - : AWKeysAggregator::FormatterType::IntegerThree; + if (_source.contains("rate")) + m_formatter[key] = AWPluginFormatterFloat::instance(); + else + m_formatter[key] = AWPluginFormatterIntegerShort::instance(); } else if (_source == "cpu/all/usage") { // cpu m_map.insert(_source, "cpu"); - m_formatter["cpu"] = AWKeysAggregator::FormatterType::Float; + m_formatter["cpu"] = AWPluginFormatterFloat::instance(); } else if (_source.contains(cpuRegExp)) { // cpus auto key = _source; key.remove("cpu/").remove("/usage"); m_map.insert(_source, key); - m_formatter[key] = AWKeysAggregator::FormatterType::Float; + m_formatter[key] = AWPluginFormatterFloat::instance(); } else if (_source == "cpu/all/averageFrequency") { // cpucl m_map.insert(_source, "cpucl"); - m_formatter["cpucl"] = AWKeysAggregator::FormatterType::Integer; + m_formatter["cpucl"] = AWPluginFormatterInteger::instance(); } else if (_source.contains(cpuclRegExp)) { // cpucls auto key = _source; key.remove("cpu/cpu").remove("/frequency"); key = QString("cpucl%1").arg(key); m_map.insert(_source, key); - m_formatter[key] = AWKeysAggregator::FormatterType::Integer; + m_formatter[key] = AWPluginFormatterInteger::instance(); } else if (_source.startsWith("extsysmon/custom")) { // custom auto key = _source; key.remove("extsysmon/custom/"); m_map.insert(_source, key); - m_formatter[key] = AWKeysAggregator::FormatterType::NoFormat; + m_formatter[key] = AWPluginFormatterNoFormat::instance(); } else if (_source == "extsysmon/desktop/name") { // current desktop name m_map.insert(_source, "desktop"); - m_formatter["desktop"] = AWKeysAggregator::FormatterType::NoFormat; + m_formatter["desktop"] = AWPluginFormatterNoFormat::instance(); } else if (_source == "extsysmon/desktop/number") { // current desktop number m_map.insert(_source, "ndesktop"); - m_formatter["ndesktop"] = AWKeysAggregator::FormatterType::NoFormat; + m_formatter["ndesktop"] = AWPluginFormatterNoFormat::instance(); } else if (_source == "extsysmon/desktop/count") { // desktop count m_map.insert(_source, "tdesktops"); - m_formatter["tdesktops"] = AWKeysAggregator::FormatterType::NoFormat; + m_formatter["tdesktops"] = AWPluginFormatterNoFormat::instance(); } else if (_source.contains(hddrRegExp)) { // read speed auto device = _source; @@ -147,7 +150,7 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const KSy if (index > -1) { QString key = QString("hddr%1").arg(index); m_map.insert(_source, key); - m_formatter[key] = AWKeysAggregator::FormatterType::MemKBFormat; + m_formatter[key] = AWPluginFormatterMemory::instance(); } } else if (_source.contains(hddwRegExp)) { // write speed @@ -157,12 +160,12 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const KSy if (index > -1) { QString key = QString("hddw%1").arg(index); m_map.insert(_source, key); - m_formatter[key] = AWKeysAggregator::FormatterType::MemKBFormat; + m_formatter[key] = AWPluginFormatterMemory::instance(); } } else if (_source == "gpu/all/usage") { // gpu load m_map.insert(_source, "gpu"); - m_formatter["gpu"] = AWKeysAggregator::FormatterType::Float; + m_formatter["gpu"] = AWPluginFormatterFloat::instance(); } else if (_source.contains(gpuRegExp)) { // gpus auto device = _source; @@ -171,7 +174,7 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const KSy if (index > -1) { auto key = QString("gpu%1").arg(index); m_map.insert(_source, key); - m_formatter[key] = AWKeysAggregator::FormatterType::Float; + m_formatter[key] = AWPluginFormatterFloat::instance(); } } else if (_source.contains(gpuTempRegExp)) { // gpus temps @@ -181,7 +184,7 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const KSy if (index > -1) { auto key = QString("gputemp%1").arg(index); m_map.insert(_source, key); - m_formatter[key] = AWKeysAggregator::FormatterType::Temperature; + m_formatter[key] = AWPluginFormatterTemperature::instance(); } } else if (_source.contains(mountFillRegExp)) { // fill level @@ -191,10 +194,10 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const KSy if (index > -1) { auto key = QString("hdd%1").arg(index); m_map.insert(_source, key); - m_formatter[key] = AWKeysAggregator::FormatterType::Float; + m_formatter[key] = AWPluginFormatterFloat::instance(); // additional keys - m_formatter[QString("hddtotmb%1").arg(index)] = AWKeysAggregator::FormatterType::MemMBFormat; - m_formatter[QString("hddtotgb%1").arg(index)] = AWKeysAggregator::FormatterType::MemGBFormat; + m_formatter[QString("hddtotmb%1").arg(index)] = AWPluginFormatterMemoryMB::instance(); + m_formatter[QString("hddtotgb%1").arg(index)] = AWPluginFormatterMemoryGB::instance(); } } else if (_source.contains(mountFreeRegExp)) { // free space @@ -205,11 +208,11 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const KSy // mb auto key = QString("hddfreemb%1").arg(index); m_map.insert(_source, key); - m_formatter[key] = AWKeysAggregator::FormatterType::MemMBFormat; + m_formatter[key] = AWPluginFormatterMemoryMB::instance(); // gb key = QString("hddfreegb%1").arg(index); m_map.insert(_source, key); - m_formatter[key] = AWKeysAggregator::FormatterType::MemGBFormat; + m_formatter[key] = AWPluginFormatterMemoryGB::instance(); } } else if (_source.contains(mountUsedRegExp)) { // used @@ -220,11 +223,11 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const KSy // mb auto key = QString("hddmb%1").arg(index); m_map.insert(_source, key); - m_formatter[key] = AWKeysAggregator::FormatterType::MemMBFormat; + m_formatter[key] = AWPluginFormatterMemoryMB::instance(); // gb key = QString("hddgb%1").arg(index); m_map.insert(_source, key); - m_formatter[key] = AWKeysAggregator::FormatterType::MemGBFormat; + m_formatter[key] = AWPluginFormatterMemoryGB::instance(); } } else if (_source.startsWith("cpu/loadaverages/loadaverage")) { // load average @@ -232,45 +235,45 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const KSy time.remove("cpu/loadaverages/loadaverage"); auto key = QString("la%1").arg(time); m_map.insert(_source, key); - m_formatter[key] = AWKeysAggregator::FormatterType::FloatTwoSymbols; + m_formatter[key] = AWPluginFormatterFloatPrecise::instance(); } else if (_source == "memory/physical/application") { // app memory // mb m_map.insert(_source, "memmb"); - m_formatter["memmb"] = AWKeysAggregator::FormatterType::MemMBFormat; + m_formatter["memmb"] = AWPluginFormatterMemoryMB::instance(); // gb m_map.insert(_source, "memgb"); - m_formatter["memgb"] = AWKeysAggregator::FormatterType::MemGBFormat; + m_formatter["memgb"] = AWPluginFormatterMemoryGB::instance(); } else if (_source == "memory/physical/free") { // free memory // mb m_map.insert(_source, "memfreemb"); - m_formatter["memfreemb"] = AWKeysAggregator::FormatterType::MemMBFormat; + m_formatter["memfreemb"] = AWPluginFormatterMemoryMB::instance(); // gb m_map.insert(_source, "memfreegb"); - m_formatter["memfreegb"] = AWKeysAggregator::FormatterType::MemGBFormat; + m_formatter["memfreegb"] = AWPluginFormatterMemoryGB::instance(); } else if (_source == "memory/physical/used") { // used memory // mb m_map.insert(_source, "memusedmb"); - m_formatter["memusedmb"] = AWKeysAggregator::FormatterType::MemMBFormat; + m_formatter["memusedmb"] = AWPluginFormatterMemoryMB::instance(); // gb m_map.insert(_source, "memusedgb"); - m_formatter["memusedgb"] = AWKeysAggregator::FormatterType::MemGBFormat; + m_formatter["memusedgb"] = AWPluginFormatterMemoryGB::instance(); } else if (_source == "extsysmon/network/device") { // network device m_map.insert(_source, "netdev"); - m_formatter["netdev"] = AWKeysAggregator::FormatterType::NoFormat; + m_formatter["netdev"] = AWPluginFormatterNoFormat::instance(); } else if (_source == "extsysmon/network/ssid") { // current ssid m_map.insert(_source, "ssid"); - m_formatter["ssid"] = AWKeysAggregator::FormatterType::NoFormat; + m_formatter["ssid"] = AWPluginFormatterNoFormat::instance(); } else if (_source.startsWith("extsysmon/requests/response")) { // network response auto key = _source; key.remove("extsysmon/requests/"); m_map.insert(_source, key); - m_formatter[key] = AWKeysAggregator::FormatterType::NoFormat; + m_formatter[key] = AWPluginFormatterNoFormat::instance(); } else if (_source.contains(netRegExp)) { // network speed auto type = _source.endsWith("download") ? "down" : "up"; @@ -279,15 +282,15 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const KSy // kb auto key = QString("%1kb%2").arg(type).arg(index); m_map.insert(_source, key); - m_formatter[key] = AWKeysAggregator::FormatterType::MemKBFormat; + m_formatter[key] = AWPluginFormatterMemory::instance(); // smart key = QString("%1%2").arg(type).arg(index); m_map.insert(_source, key); - m_formatter[key] = AWKeysAggregator::FormatterType::NetSmartFormat; + m_formatter[key] = AWPluginFormatterNet::instance(); // units key = QString("%1units%2").arg(type).arg(index); m_map.insert(_source, key); - m_formatter[key] = AWKeysAggregator::FormatterType::NetSmartUnits; + m_formatter[key] = AWPluginFormatterNetUnits::instance(); } } else if (_source.contains(netTotalRegExp)) { // network data total @@ -297,58 +300,58 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const KSy // kb auto key = QString("%1totkb%2").arg(type).arg(index); m_map.insert(_source, key); - m_formatter[key] = AWKeysAggregator::FormatterType::MemKBFormat; + m_formatter[key] = AWPluginFormatterMemory::instance(); // mb key = QString("%1tot%2").arg(type).arg(index); m_map.insert(_source, key); - m_formatter[key] = AWKeysAggregator::FormatterType::MemMBFormat; + m_formatter[key] = AWPluginFormatterMemoryMB::instance(); } } else if (_source.startsWith("extsysmon/upgrade")) { // package manager auto key = _source; key.remove("extsysmon/upgrade/"); m_map.insert(_source, key); - m_formatter[key] = AWKeysAggregator::FormatterType::IntegerThree; + m_formatter[key] = AWPluginFormatterIntegerShort::instance(); } else if (_source.startsWith("extsysmon/player")) { // player auto key = _source; key.remove("extsysmon/player/"); m_map.insert(_source, key); - m_formatter[key] = AWKeysAggregator::FormatterType::NoFormat; + m_formatter[key] = AWPluginFormatterNoFormat::instance(); } else if (_source == "extsysmon/ps/running") { // running processes count m_map.insert(_source, "pscount"); - m_formatter["pscount"] = AWKeysAggregator::FormatterType::NoFormat; + m_formatter["pscount"] = AWPluginFormatterNoFormat::instance(); } else if (_source == "extsysmon/ps/list") { // list of running processes m_map.insert(_source, "ps"); - m_formatter["ps"] = AWKeysAggregator::FormatterType::List; + m_formatter["ps"] = AWPluginFormatterList::instance(); } else if (_source == "extsysmon/ps/count") { // total processes count m_map.insert(_source, "pstot"); - m_formatter["pstot"] = AWKeysAggregator::FormatterType::NoFormat; + m_formatter["pstot"] = AWPluginFormatterNoFormat::instance(); } else if (_source.startsWith("extsysmon/quotes")) { // quotes auto key = _source; key.remove("extsysmon/quotes/"); m_map.insert(_source, key); - m_formatter[key] = AWKeysAggregator::FormatterType::Quotes; + m_formatter[key] = AWPluginFormatterDouble::instance(); } else if (_source == "memory/swap/free") { // free swap // mb m_map.insert(_source, "swapfreemb"); - m_formatter["swapfreemb"] = AWKeysAggregator::FormatterType::MemMBFormat; + m_formatter["swapfreemb"] = AWPluginFormatterMemoryMB::instance(); // gb m_map.insert(_source, "swapfreegb"); - m_formatter["swapfreegb"] = AWKeysAggregator::FormatterType::MemGBFormat; + m_formatter["swapfreegb"] = AWPluginFormatterMemoryGB::instance(); } else if (_source == "memory/swap/used") { // used swap // mb m_map.insert(_source, "swapmb"); - m_formatter["swapmb"] = AWKeysAggregator::FormatterType::MemMBFormat; + m_formatter["swapmb"] = AWPluginFormatterMemoryMB::instance(); // gb m_map.insert(_source, "swapgb"); - m_formatter["swapgb"] = AWKeysAggregator::FormatterType::MemGBFormat; + m_formatter["swapgb"] = AWPluginFormatterMemoryGB::instance(); } else if (_source.startsWith("lmsensors/") || _source.contains(cpuTempRegExp) || _source == "cpu/all/averageTemperature") { // temperature @@ -359,59 +362,58 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const KSy if (index > -1) { auto key = QString("temp%1").arg(index); m_map.insert(_source, key); - m_formatter[key] = _units == KSysGuard::UnitCelsius ? AWKeysAggregator::FormatterType::Temperature - : AWKeysAggregator::FormatterType::Integer; + if (_units == KSysGuard::UnitCelsius) + m_formatter[key] = AWPluginFormatterTemperature::instance(); + else + m_formatter[key] = AWPluginFormatterInteger::instance(); } } else if (_source == "extsysmon/time/now") { // time m_map.insert(_source, "time"); - m_formatter["time"] = AWKeysAggregator::FormatterType::Time; + m_formatter["time"] = AWPluginFormatterTime::instance(); // custom time m_map.insert(_source, "ctime"); - m_formatter["ctime"] = AWKeysAggregator::FormatterType::TimeCustom; + m_formatter["ctime"] = AWPluginFormatterTimeCustom::instance(); // ISO time m_map.insert(_source, "isotime"); - m_formatter["isotime"] = AWKeysAggregator::FormatterType::TimeISO; + m_formatter["isotime"] = AWPluginFormatterTimeISO::instance(); // long time m_map.insert(_source, "longtime"); - m_formatter["longtime"] = AWKeysAggregator::FormatterType::TimeLong; + m_formatter["longtime"] = AWPluginFormatterTimeLong::instance(); // short time m_map.insert(_source, "shorttime"); - m_formatter["shorttime"] = AWKeysAggregator::FormatterType::TimeShort; + m_formatter["shorttime"] = AWPluginFormatterTimeShort::instance(); // timestamp m_map.insert(_source, "tstime"); - m_formatter["tstime"] = AWKeysAggregator::FormatterType::Timestamp; + m_formatter["tstime"] = AWPluginFormatterNoFormat::instance(); } else if (_source == "extsysmon/system/brightness") { m_map.insert(_source, "brightness"); - m_formatter["brightness"] = AWKeysAggregator::FormatterType::IntegerThree; + m_formatter["brightness"] = AWPluginFormatterIntegerShort::instance(); } else if (_source == "extsysmon/system/volume") { m_map.insert(_source, "volume"); - m_formatter["volume"] = AWKeysAggregator::FormatterType::IntegerThree; + m_formatter["volume"] = AWPluginFormatterIntegerShort::instance(); } else if (_source == "os/system/uptime") { // uptime m_map.insert(_source, "uptime"); - m_formatter["uptime"] = AWKeysAggregator::FormatterType::Uptime; - // custom uptime - m_map.insert(_source, "cuptime"); - m_formatter["cuptime"] = AWKeysAggregator::FormatterType::UptimeCustom; + m_formatter["uptime"] = AWPluginFormatterUptime::instance(); } else if (_source.startsWith("extsysmon/weather/temperature")) { // temperature auto key = _source; key.remove("extsysmon/weather/"); m_map.insert(_source, key); - m_formatter[key] = AWKeysAggregator::FormatterType::Temperature; + m_formatter[key] = AWPluginFormatterTemperature::instance(); } else if (_source.startsWith("extsysmon/weather/")) { // other weather auto key = _source; key.remove("extsysmon/weather/"); m_map.insert(_source, key); - m_formatter[key] = AWKeysAggregator::FormatterType::NoFormat; + m_formatter[key] = AWPluginFormatterNoFormat::instance(); } else if (_source.startsWith("extsysmon/load/load")) { // load source auto key = _source; key.remove("extsysmon/load/"); m_map.insert(_source, key); - m_formatter[key] = AWKeysAggregator::FormatterType::Temperature; + m_formatter[key] = AWPluginFormatterTemperature::instance(); } auto foundKeys = keysFromSource(_source); @@ -424,7 +426,7 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const KSy for (auto &key : foundKeys) { if (!customFormattersKeys.contains(key)) continue; - m_formatter[key] = AWKeysAggregator::FormatterType::Custom; + m_formatter[key] = AWPluginFormatterCustom::instance(); } // drop key from dictionary if no one user requested key required it diff --git a/sources/awesome-widget/plugin/awdataenginemapper.h b/sources/awesome-widget/plugin/awdataenginemapper.h index 6f88af3..72c5ebe 100644 --- a/sources/awesome-widget/plugin/awdataenginemapper.h +++ b/sources/awesome-widget/plugin/awdataenginemapper.h @@ -22,7 +22,7 @@ #include #include -#include "awkeysaggregator.h" +#include "formatters/awpluginformatter.h" class AWFormatterHelper; @@ -35,7 +35,7 @@ public: explicit AWDataEngineMapper(QObject *_parent = nullptr, AWFormatterHelper *_custom = nullptr); ~AWDataEngineMapper() override = default; // get methods - [[nodiscard]] AWKeysAggregator::FormatterType formatter(const QString &_key) const; + [[nodiscard]] AWPluginFormaterInterface *formatter(const QString &_key) const; [[nodiscard]] QStringList keysFromSource(const QString &_source) const; // set methods QStringList registerSource(const QString &_source, KSysGuard::Unit _units, const QStringList &_keys); @@ -45,6 +45,6 @@ private: AWFormatterHelper *m_customFormatters = nullptr; // variables QHash m_devices; - QHash m_formatter; + QHash m_formatter; QMultiHash m_map; }; diff --git a/sources/awesome-widget/plugin/awkeysaggregator.cpp b/sources/awesome-widget/plugin/awkeysaggregator.cpp index 9562993..ebcad5b 100644 --- a/sources/awesome-widget/plugin/awkeysaggregator.cpp +++ b/sources/awesome-widget/plugin/awkeysaggregator.cpp @@ -17,15 +17,9 @@ #include "awkeysaggregator.h" -#include - -#include -#include - #include "awdataenginemapper.h" #include "awdebug.h" #include "awformatterhelper.h" -#include "version.h" AWKeysAggregator::AWKeysAggregator(QObject *_parent) @@ -33,19 +27,38 @@ AWKeysAggregator::AWKeysAggregator(QObject *_parent) { qCDebug(LOG_AW) << __PRETTY_FUNCTION__; - m_customFormatters = new AWFormatterHelper(this); - m_mapper = new AWDataEngineMapper(this, m_customFormatters); - - // sort time keys - m_timeKeys = QString(TIME_KEYS).split(','); - m_timeKeys.sort(); - std::reverse(m_timeKeys.begin(), m_timeKeys.end()); + m_settings.customFormatters = new AWFormatterHelper(this); + m_mapper = new AWDataEngineMapper(this, m_settings.customFormatters); } 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; - QString output; - 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(_data.toDouble())); - break; - case FormatterType::NoFormat: - output = _data.toString(); - break; - case FormatterType::Custom: - if (m_customFormatters) - output = m_customFormatters->convert(_data, _key); - break; - } - + auto output = m_mapper->formatter(_key)->format(_data, _key, m_settings); // replace spaces to non-breakable ones replaceSpace &= (!_key.startsWith("custom") && (!_key.startsWith("weather"))); 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) { 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; - m_acOnline = _active; + m_settings.acOnline = _active; } @@ -197,7 +116,7 @@ void AWKeysAggregator::setCustomTime(const QString &_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; - m_customUptime = _customUptime; + m_settings.customUptime = _customUptime; } @@ -221,7 +140,7 @@ void AWKeysAggregator::setTempUnits(const QString &_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; - 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); } - - -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; -} diff --git a/sources/awesome-widget/plugin/awkeysaggregator.h b/sources/awesome-widget/plugin/awkeysaggregator.h index e6fbca1..f51dca1 100644 --- a/sources/awesome-widget/plugin/awkeysaggregator.h +++ b/sources/awesome-widget/plugin/awkeysaggregator.h @@ -22,60 +22,35 @@ #include #include +#include "formatters/awpluginformatsettings.h" + -class AWFormatterHelper; class AWDataEngineMapper; class AWKeysAggregator : public QObject { Q_OBJECT - Q_PROPERTY(QString acOffline MEMBER m_acOffline WRITE setAcOffline); - Q_PROPERTY(QString acOnline MEMBER m_acOnline WRITE setAcOnline); - Q_PROPERTY(QString customTime MEMBER m_customTime WRITE setCustomTime); - Q_PROPERTY(QString customUptime MEMBER m_customUptime WRITE setCustomUptime); - Q_PROPERTY(QString tempUnits MEMBER m_tempUnits WRITE setTempUnits); - Q_PROPERTY(bool translate MEMBER m_translate WRITE setTranslate); + Q_PROPERTY(QString acOffline READ acOffline WRITE setAcOffline); + Q_PROPERTY(QString acOnline READ acOnline WRITE setAcOnline); + Q_PROPERTY(QString customTime READ customTime WRITE setCustomTime); + Q_PROPERTY(QString customUptime READ customUptime WRITE setCustomUptime); + Q_PROPERTY(QString tempUnits READ tempUnits WRITE setTempUnits); + Q_PROPERTY(bool translate READ translate WRITE setTranslate); 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); ~AWKeysAggregator() override = default; void initFormatters(); // 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]] QStringList keysFromSource(const QString &_source) const; + [[nodiscard]] QString tempUnits() const; + [[nodiscard]] bool translate() const; // set methods void setAcOffline(const QString &_inactive); void setAcOnline(const QString &_active); @@ -89,15 +64,6 @@ public slots: QStringList registerSource(const QString &_source, KSysGuard::Unit _units, const QStringList &_keys); private: - [[nodiscard]] double temperature(double temp) const; - AWFormatterHelper *m_customFormatters = nullptr; + AWPluginFormatSettings m_settings; 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; }; diff --git a/sources/awesome-widget/plugin/formatters/awpluginformatsettings.h b/sources/awesome-widget/plugin/formatters/awpluginformatsettings.h new file mode 100644 index 0000000..e3e76dd --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformatsettings.h @@ -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 + + +class AWFormatterHelper; + +struct AWPluginFormatSettings { + QString acOffline; + QString acOnline; + + QString customTime; + QString customUptime; + + QString tempUnits; + + bool translate = false; + + AWFormatterHelper *customFormatters = nullptr; +}; diff --git a/sources/awesome-widget/plugin/formatters/awpluginformatter.h b/sources/awesome-widget/plugin/formatters/awpluginformatter.h new file mode 100644 index 0000000..7a47d09 --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformatter.h @@ -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 +#include + +#include + +#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 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 loadInstance() + { + auto instance = std::make_unique(); + instance->load(); + return instance; + }; +}; diff --git a/sources/awesome-widget/plugin/formatters/awpluginformatterac.cpp b/sources/awesome-widget/plugin/formatters/awpluginformatterac.cpp new file mode 100644 index 0000000..c0c33d7 --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformatterac.cpp @@ -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; +} diff --git a/sources/awesome-widget/plugin/formatters/awpluginformatterac.h b/sources/awesome-widget/plugin/formatters/awpluginformatterac.h new file mode 100644 index 0000000..54ebaad --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformatterac.h @@ -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 { + +public: + QString format(const QVariant &_value, const QString &, const AWPluginFormatSettings &_settings) const override; +}; diff --git a/sources/awesome-widget/plugin/formatters/awpluginformattercustom.cpp b/sources/awesome-widget/plugin/formatters/awpluginformattercustom.cpp new file mode 100644 index 0000000..7858f3b --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformattercustom.cpp @@ -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(); +} diff --git a/sources/awesome-widget/plugin/formatters/awpluginformattercustom.h b/sources/awesome-widget/plugin/formatters/awpluginformattercustom.h new file mode 100644 index 0000000..2fab7ff --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformattercustom.h @@ -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 { + +public: + QString format(const QVariant &_value, const QString &_key, const AWPluginFormatSettings &_settings) const override; +}; diff --git a/sources/awesome-widget/plugin/formatters/awpluginformatterdouble.cpp b/sources/awesome-widget/plugin/formatters/awpluginformatterdouble.cpp new file mode 100644 index 0000000..ef31c47 --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformatterdouble.cpp @@ -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); +} diff --git a/sources/awesome-widget/plugin/formatters/awpluginformatterdouble.h b/sources/awesome-widget/plugin/formatters/awpluginformatterdouble.h new file mode 100644 index 0000000..de8fdc7 --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformatterdouble.h @@ -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 { + +public: + QString format(const QVariant &_value, const QString &, const AWPluginFormatSettings &) const override; +}; diff --git a/sources/awesome-widget/plugin/formatters/awpluginformatterfloat.cpp b/sources/awesome-widget/plugin/formatters/awpluginformatterfloat.cpp new file mode 100644 index 0000000..231cba3 --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformatterfloat.cpp @@ -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); +} diff --git a/sources/awesome-widget/plugin/formatters/awpluginformatterfloat.h b/sources/awesome-widget/plugin/formatters/awpluginformatterfloat.h new file mode 100644 index 0000000..fba42bf --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformatterfloat.h @@ -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{ + +public: + QString format(const QVariant &_value, const QString &, const AWPluginFormatSettings &) const override; +}; diff --git a/sources/awesome-widget/plugin/formatters/awpluginformatterfloatprecise.cpp b/sources/awesome-widget/plugin/formatters/awpluginformatterfloatprecise.cpp new file mode 100644 index 0000000..bd8a222 --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformatterfloatprecise.cpp @@ -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); +} diff --git a/sources/awesome-widget/plugin/formatters/awpluginformatterfloatprecise.h b/sources/awesome-widget/plugin/formatters/awpluginformatterfloatprecise.h new file mode 100644 index 0000000..18a638d --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformatterfloatprecise.h @@ -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 { + +public: + QString format(const QVariant &_value, const QString &, const AWPluginFormatSettings &) const override; +}; diff --git a/sources/awesome-widget/plugin/formatters/awpluginformatterinteger.cpp b/sources/awesome-widget/plugin/formatters/awpluginformatterinteger.cpp new file mode 100644 index 0000000..411bd2d --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformatterinteger.cpp @@ -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); +} diff --git a/sources/awesome-widget/plugin/formatters/awpluginformatterinteger.h b/sources/awesome-widget/plugin/formatters/awpluginformatterinteger.h new file mode 100644 index 0000000..253e485 --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformatterinteger.h @@ -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 { + +public: + QString format(const QVariant &_value, const QString &, const AWPluginFormatSettings &) const override; +}; diff --git a/sources/awesome-widget/plugin/formatters/awpluginformatterintegershort.cpp b/sources/awesome-widget/plugin/formatters/awpluginformatterintegershort.cpp new file mode 100644 index 0000000..1d8db28 --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformatterintegershort.cpp @@ -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); +} diff --git a/sources/awesome-widget/plugin/formatters/awpluginformatterintegershort.h b/sources/awesome-widget/plugin/formatters/awpluginformatterintegershort.h new file mode 100644 index 0000000..1b1aec7 --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformatterintegershort.h @@ -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 { + +public: + QString format(const QVariant &_value, const QString &, const AWPluginFormatSettings &) const override; +}; diff --git a/sources/awesome-widget/plugin/formatters/awpluginformatterintegerwide.cpp b/sources/awesome-widget/plugin/formatters/awpluginformatterintegerwide.cpp new file mode 100644 index 0000000..d27a56d --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformatterintegerwide.cpp @@ -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); +} diff --git a/sources/awesome-widget/plugin/formatters/awpluginformatterintegerwide.h b/sources/awesome-widget/plugin/formatters/awpluginformatterintegerwide.h new file mode 100644 index 0000000..bcd5faa --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformatterintegerwide.h @@ -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 { + +public: + QString format(const QVariant &_value, const QString &, const AWPluginFormatSettings &) const override; +}; diff --git a/sources/awesome-widget/plugin/formatters/awpluginformatterlist.cpp b/sources/awesome-widget/plugin/formatters/awpluginformatterlist.cpp new file mode 100644 index 0000000..d998bdb --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformatterlist.cpp @@ -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(","); +} diff --git a/sources/awesome-widget/plugin/formatters/awpluginformatterlist.h b/sources/awesome-widget/plugin/formatters/awpluginformatterlist.h new file mode 100644 index 0000000..3c53742 --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformatterlist.h @@ -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 { + +public: + QString format(const QVariant &_value, const QString &, const AWPluginFormatSettings &) const override; +}; diff --git a/sources/awesome-widget/plugin/formatters/awpluginformattermemory.cpp b/sources/awesome-widget/plugin/formatters/awpluginformattermemory.cpp new file mode 100644 index 0000000..de33493 --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformattermemory.cpp @@ -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); +} diff --git a/sources/awesome-widget/plugin/formatters/awpluginformattermemory.h b/sources/awesome-widget/plugin/formatters/awpluginformattermemory.h new file mode 100644 index 0000000..bd9b53f --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformattermemory.h @@ -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 { + +public: + QString format(const QVariant &_value, const QString &, const AWPluginFormatSettings &) const override; +}; diff --git a/sources/awesome-widget/plugin/formatters/awpluginformattermemorygb.cpp b/sources/awesome-widget/plugin/formatters/awpluginformattermemorygb.cpp new file mode 100644 index 0000000..aea5064 --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformattermemorygb.cpp @@ -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); +} diff --git a/sources/awesome-widget/plugin/formatters/awpluginformattermemorygb.h b/sources/awesome-widget/plugin/formatters/awpluginformattermemorygb.h new file mode 100644 index 0000000..8819f87 --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformattermemorygb.h @@ -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 { + +public: + QString format(const QVariant &_value, const QString &, const AWPluginFormatSettings &) const override; +}; diff --git a/sources/awesome-widget/plugin/formatters/awpluginformattermemorymb.cpp b/sources/awesome-widget/plugin/formatters/awpluginformattermemorymb.cpp new file mode 100644 index 0000000..7ad05c7 --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformattermemorymb.cpp @@ -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); +} diff --git a/sources/awesome-widget/plugin/formatters/awpluginformattermemorymb.h b/sources/awesome-widget/plugin/formatters/awpluginformattermemorymb.h new file mode 100644 index 0000000..f6e9866 --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformattermemorymb.h @@ -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 { + +public: + QString format(const QVariant &_value, const QString &, const AWPluginFormatSettings &) const override; +}; diff --git a/sources/awesome-widget/plugin/formatters/awpluginformatternet.cpp b/sources/awesome-widget/plugin/formatters/awpluginformatternet.cpp new file mode 100644 index 0000000..fe684b8 --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformatternet.cpp @@ -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); +} diff --git a/sources/awesome-widget/plugin/formatters/awpluginformatternet.h b/sources/awesome-widget/plugin/formatters/awpluginformatternet.h new file mode 100644 index 0000000..fd1b43f --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformatternet.h @@ -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 { + +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); +}; diff --git a/sources/awesome-widget/plugin/formatters/awpluginformatternetunits.cpp b/sources/awesome-widget/plugin/formatters/awpluginformatternetunits.cpp new file mode 100644 index 0000000..b544641 --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformatternetunits.cpp @@ -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 + + +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"; +} diff --git a/sources/awesome-widget/plugin/formatters/awpluginformatternetunits.h b/sources/awesome-widget/plugin/formatters/awpluginformatternetunits.h new file mode 100644 index 0000000..805e3e8 --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformatternetunits.h @@ -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 { + +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); +}; diff --git a/sources/awesome-widget/plugin/formatters/awpluginformatternoformat.cpp b/sources/awesome-widget/plugin/formatters/awpluginformatternoformat.cpp new file mode 100644 index 0000000..56572ed --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformatternoformat.cpp @@ -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(); +} diff --git a/sources/awesome-widget/plugin/formatters/awpluginformatternoformat.h b/sources/awesome-widget/plugin/formatters/awpluginformatternoformat.h new file mode 100644 index 0000000..11cd5dc --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformatternoformat.h @@ -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 { + +public: + QString format(const QVariant &_value, const QString &, const AWPluginFormatSettings &) const override; +}; diff --git a/sources/awesome-widget/plugin/formatters/awpluginformattertemperature.cpp b/sources/awesome-widget/plugin/formatters/awpluginformattertemperature.cpp new file mode 100644 index 0000000..35ecd89 --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformattertemperature.cpp @@ -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; +} diff --git a/sources/awesome-widget/plugin/formatters/awpluginformattertemperature.h b/sources/awesome-widget/plugin/formatters/awpluginformattertemperature.h new file mode 100644 index 0000000..a2d6c07 --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformattertemperature.h @@ -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 { + +public: + QString format(const QVariant &_value, const QString &, const AWPluginFormatSettings &_settings) const override; + +private: + static double convert(const double &_value, const QString &_units); +}; diff --git a/sources/awesome-widget/plugin/formatters/awpluginformattertime.cpp b/sources/awesome-widget/plugin/formatters/awpluginformattertime.cpp new file mode 100644 index 0000000..8a9c194 --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformattertime.cpp @@ -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 + + +QString AWPluginFormatterTime::format(const QVariant &_value, const QString &, const AWPluginFormatSettings &) const +{ + return QDateTime::fromSecsSinceEpoch(_value.toLongLong()).toString(); +} diff --git a/sources/awesome-widget/plugin/formatters/awpluginformattertime.h b/sources/awesome-widget/plugin/formatters/awpluginformattertime.h new file mode 100644 index 0000000..06c0c9e --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformattertime.h @@ -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 { + +public: + QString format(const QVariant &_value, const QString &, const AWPluginFormatSettings &) const override; +}; diff --git a/sources/awesome-widget/plugin/formatters/awpluginformattertimecustom.cpp b/sources/awesome-widget/plugin/formatters/awpluginformattertimecustom.cpp new file mode 100644 index 0000000..ada72b9 --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformattertimecustom.cpp @@ -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; +} diff --git a/sources/awesome-widget/plugin/formatters/awpluginformattertimecustom.h b/sources/awesome-widget/plugin/formatters/awpluginformattertimecustom.h new file mode 100644 index 0000000..c90ba50 --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformattertimecustom.h @@ -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 + +#include "awpluginformatter.h" + + +class AWPluginFormatterTimeCustom : public AWPluginFormatter { + +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; +}; diff --git a/sources/awesome-widget/plugin/formatters/awpluginformattertimeiso.cpp b/sources/awesome-widget/plugin/formatters/awpluginformattertimeiso.cpp new file mode 100644 index 0000000..abc9f64 --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformattertimeiso.cpp @@ -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 + + +QString AWPluginFormatterTimeISO::format(const QVariant &_value, const QString &, const AWPluginFormatSettings &) const +{ + return QDateTime::fromSecsSinceEpoch(_value.toLongLong()).toString(Qt::ISODate); +} diff --git a/sources/awesome-widget/plugin/formatters/awpluginformattertimeiso.h b/sources/awesome-widget/plugin/formatters/awpluginformattertimeiso.h new file mode 100644 index 0000000..4309368 --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformattertimeiso.h @@ -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 { + +public: + QString format(const QVariant &_value, const QString &, const AWPluginFormatSettings &) const override; +}; diff --git a/sources/awesome-widget/plugin/formatters/awpluginformattertimelong.cpp b/sources/awesome-widget/plugin/formatters/awpluginformattertimelong.cpp new file mode 100644 index 0000000..aef6f5f --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformattertimelong.cpp @@ -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 + + +QString AWPluginFormatterTimeLong::format(const QVariant &_value, const QString &, const AWPluginFormatSettings &_settings) const +{ + return locale(_settings).toString(QDateTime::fromSecsSinceEpoch(_value.toLongLong()), QLocale::LongFormat); +} diff --git a/sources/awesome-widget/plugin/formatters/awpluginformattertimelong.h b/sources/awesome-widget/plugin/formatters/awpluginformattertimelong.h new file mode 100644 index 0000000..e80a060 --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformattertimelong.h @@ -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 { + +public: + QString format(const QVariant &_value, const QString &, const AWPluginFormatSettings &_settings) const override; +}; diff --git a/sources/awesome-widget/plugin/formatters/awpluginformattertimeshort.cpp b/sources/awesome-widget/plugin/formatters/awpluginformattertimeshort.cpp new file mode 100644 index 0000000..e6c88b6 --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformattertimeshort.cpp @@ -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 + + +QString AWPluginFormatterTimeShort::format(const QVariant &_value, const QString &, const AWPluginFormatSettings &_settings) const +{ + return locale(_settings).toString(QDateTime::fromSecsSinceEpoch(_value.toLongLong()), QLocale::ShortFormat); +} diff --git a/sources/awesome-widget/plugin/formatters/awpluginformattertimeshort.h b/sources/awesome-widget/plugin/formatters/awpluginformattertimeshort.h new file mode 100644 index 0000000..7947bda --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformattertimeshort.h @@ -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 { + +public: + QString format(const QVariant &_value, const QString &, const AWPluginFormatSettings &_settings) const override; +}; diff --git a/sources/awesome-widget/plugin/formatters/awpluginformatteruptime.cpp b/sources/awesome-widget/plugin/formatters/awpluginformatteruptime.cpp new file mode 100644 index 0000000..5073f10 --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformatteruptime.cpp @@ -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(_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; +} diff --git a/sources/awesome-widget/plugin/formatters/awpluginformatteruptime.h b/sources/awesome-widget/plugin/formatters/awpluginformatteruptime.h new file mode 100644 index 0000000..e0fdc1a --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformatteruptime.h @@ -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 { + +public: + QString format(const QVariant &_value, const QString &, const AWPluginFormatSettings &_settings) const override; + +private: + static QString format(const long &_value, QString _formatString); +}; diff --git a/sources/awesome-widget/plugin/formatters/formatters.h b/sources/awesome-widget/plugin/formatters/formatters.h new file mode 100644 index 0000000..06153a5 --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/formatters.h @@ -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" diff --git a/sources/awesomewidgets/configs/aw-example-standalonerc b/sources/awesomewidgets/configs/aw-example-standalonerc index 666c91e..bb494cb 100644 --- a/sources/awesomewidgets/configs/aw-example-standalonerc +++ b/sources/awesomewidgets/configs/aw-example-standalonerc @@ -121,7 +121,7 @@ queueLimit=0 swapTooltip=true swapTooltipColor=#ffff00 tempUnits=Celsius -text="\n

Uptime: $cuptime
\nRAM:  $mem  $bar5
\nSwap: $swap  $bar6
\nCPU:  $cpu  $bar7
\nCPU Temp: $temp0°C
\nDown: $down$downunits    $downtot
\n$bar8
\nUp:   $up$upunits    $uptot
\n$bar9

\n\n" +text="\n

Uptime: $uptime
\nRAM:  $mem  $bar5
\nSwap: $swap  $bar6
\nCPU:  $cpu  $bar7
\nCPU Temp: $temp0°C
\nDown: $down$downunits    $downtot
\n$bar8
\nUp:   $up$upunits    $uptot
\n$bar9

\n\n" textAlign=center tooltipBackground=#ffffff tooltipNumber=100 diff --git a/sources/version.h.in b/sources/version.h.in index d974b40..9d834ac 100644 --- a/sources/version.h.in +++ b/sources/version.h.in @@ -67,7 +67,6 @@ static const char STATIC_KEYS[] = "time," "tstime," "ctime," "uptime," - "cuptime," "cpucl," "cpu," "gpu,"