mirror of
				https://github.com/arcan1s/awesome-widgets.git
				synced 2025-10-26 03:13:42 +00:00 
			
		
		
		
	Compare commits
	
		
			1 Commits
		
	
	
		
			master
			...
			84e5b7d64e
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 84e5b7d64e | 
							
								
								
									
										3
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @ -48,6 +48,3 @@ pkg | ||||
| # clion settings | ||||
| .idea | ||||
| cmake-build* | ||||
|  | ||||
| # clang | ||||
| .cache | ||||
|  | ||||
							
								
								
									
										1
									
								
								AUTHORS
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								AUTHORS
									
									
									
									
									
								
							| @ -13,4 +13,3 @@ Steve Lemuel (Chinese) | ||||
| Mariusz Kocoń (Polish) | ||||
| Ibnu Daru Aji (Indonesian) | ||||
| Antonio Vivace (Italian) | ||||
| @daveedmee (German) | ||||
|  | ||||
							
								
								
									
										11
									
								
								CHANGELOG
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								CHANGELOG
									
									
									
									
									
								
							| @ -1,16 +1,5 @@ | ||||
| Ver.4.0.2: | ||||
| + German translation (#172, thanks to daveedmee) | ||||
|  | ||||
| Ver.4.0.1: | ||||
| - temporary disable tooltip painting in main widget | ||||
|  | ||||
| Ver.4.0.0: | ||||
| * migration to plasma 6 | ||||
| * dialog windows have been replaced by notifications | ||||
| + $gpuN keys have been added | ||||
| + new key $ssid | ||||
| - $cuptime key has been removed in favour of $uptime | ||||
| - $gputemp key has been replaced by $gpuN | ||||
|  | ||||
| Ver.3.5.0: | ||||
| + wayland support | ||||
|  | ||||
| @ -75,5 +75,5 @@ Links | ||||
| * [Scripts and bars](https://arcanis.me/en/2014/12/19/aw-v21-bells-and-whistles/) | ||||
| * Plasmoid on [kde-look](http://kde-look.org/content/show.php/Awesome+Widgets?content=157124) | ||||
| * DataEngine on [kde-look](http://kde-look.org/content/show.php/Extended+Systemmonitor+DataEngine?content=158773) | ||||
| * Archlinux [AUR](https://aur.archlinux.org/packages/plasma6-applets-awesome-widgets) package | ||||
| * Archlinux [AUR](https://aur.archlinux.org/packages/plasma5-applet-awesome-widgets/) package | ||||
| * [OpenSuse](http://software.opensuse.org/search?q=awesome-widgets) packages, [KF5 OpenSuse](http://software.opensuse.org/package/plasma5-awesome-widgets) package | ||||
|  | ||||
| @ -5,7 +5,7 @@ VERSION="$(git describe --tags --abbrev=0)" | ||||
|  | ||||
| # build widget | ||||
| ARCHIVE="awesome-widgets" | ||||
| FILES="AUTHORS CHANGELOG COPYING packages patches" | ||||
| FILES="AUTHORS CHANGELOG COPYING packages patches sources" | ||||
| IGNORELIST="build usr .kdev4 *.kdev4 .idea packages/*src.tar.xz" | ||||
| # create archive | ||||
| [[ -e ${ARCHIVE}-${VERSION}-src.tar.xz ]] && rm -f "${ARCHIVE}-${VERSION}-src.tar.xz" | ||||
|  | ||||
| @ -2,7 +2,7 @@ | ||||
|  | ||||
| pkgname=plasma6-applet-awesome-widgets | ||||
| _pkgname=awesome-widgets | ||||
| pkgver=4.0.2 | ||||
| pkgver=4.0.0alpha2 | ||||
| pkgrel=1 | ||||
| pkgdesc="Collection of minimalistic Plasmoids which look like Awesome WM widgets (ex-PyTextMonitor)" | ||||
| arch=('x86_64') | ||||
|  | ||||
| @ -19,7 +19,7 @@ set(PROJECT_CONTACT "esalexeev@gmail.com") | ||||
| set(PROJECT_LICENSE "GPL3") | ||||
| set(PROJECT_VERSION_MAJOR "4") | ||||
| set(PROJECT_VERSION_MINOR "0") | ||||
| set(PROJECT_VERSION_PATCH "2") | ||||
| set(PROJECT_VERSION_PATCH "0") | ||||
| set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}") | ||||
| # append git version if any | ||||
| set(PROJECT_COMMIT_SHA "Commit hash" CACHE INTERNAL "") | ||||
|  | ||||
| @ -15,9 +15,7 @@ | ||||
|  *   along with awesome-widgets. If not, see http://www.gnu.org/licenses/  * | ||||
|  ***************************************************************************/ | ||||
|  | ||||
| #ifndef NDEBUG | ||||
| #define NDEBUG | ||||
| #endif /* NDEBUG */ | ||||
|  | ||||
| #include <KI18n/KLocalizedString> | ||||
|  | ||||
| #include "awdebug.h" | ||||
|  | ||||
| @ -130,7 +130,7 @@ PlasmoidItem { | ||||
|         Plasmoid.userConfiguringChanged(false) | ||||
|         // connect data | ||||
|         awKeys.needTextToBeUpdated.connect(needTextUpdate) | ||||
|         //awKeys.needToolTipToBeUpdated.connect(needToolTipUpdate) | ||||
|         awKeys.needToolTipToBeUpdated.connect(needToolTipUpdate) | ||||
|         // check updates if required | ||||
|         if (plasmoid.configuration.checkUpdates) return awActions.checkUpdates(false) | ||||
|     } | ||||
|  | ||||
| @ -19,7 +19,7 @@ | ||||
|         "Id": "org.kde.plasma.awesomewidget", | ||||
|         "License": "GPLv3", | ||||
|         "Name": "Awesome Widget", | ||||
|         "Version": "4.0.2", | ||||
|         "Version": "4.0.0", | ||||
|         "Website": "https://arcanis.me/projects/awesome-widgets/" | ||||
|     }, | ||||
|     "X-Plasma-API-Minimum-Version": "6.0" | ||||
|  | ||||
| @ -10,11 +10,11 @@ include_directories( | ||||
|         ${Kf6_INCLUDE} | ||||
| ) | ||||
|  | ||||
| file(GLOB SUBPROJECT_SOURCE *.cpp formatters/*.cpp matchers/*.cpp ${PROJECT_TRDPARTY_DIR}/fontdialog/*.cpp ${CMAKE_SOURCE_DIR}/*.cpp) | ||||
| file(GLOB SUBPROJECT_SOURCE *.cpp ${PROJECT_TRDPARTY_DIR}/fontdialog/*.cpp ${CMAKE_SOURCE_DIR}/*.cpp) | ||||
| file(GLOB SUBPROJECT_UI *.ui) | ||||
| file(GLOB SUBPROJECT_NOTIFY *.notifyrc) | ||||
|  | ||||
| qt6_wrap_ui(SUBPROJECT_UI_HEADER ${SUBPROJECT_UI} OPTIONS --translate ui_i18n) | ||||
| qt6_wrap_ui(SUBPROJECT_UI_HEADER ${SUBPROJECT_UI}) | ||||
| add_library(${PLUGIN_NAME} SHARED ${SUBPROJECT_SOURCE} ${SUBPROJECT_UI_HEADER}) | ||||
| target_link_libraries(${PLUGIN_NAME} ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Kf6_LIBRARIES}) | ||||
|  | ||||
|  | ||||
| @ -23,7 +23,7 @@ | ||||
| class QNetworkAccessManager; | ||||
| class QNetworkReply; | ||||
|  | ||||
| class __attribute__((visibility("default"))) AWBugReporter : public QObject | ||||
| class AWBugReporter : public QObject | ||||
| { | ||||
|     Q_OBJECT | ||||
|  | ||||
|  | ||||
| @ -23,7 +23,7 @@ | ||||
|  | ||||
| class QSettings; | ||||
|  | ||||
| class __attribute__((visibility("default"))) AWConfigHelper : public QObject | ||||
| class AWConfigHelper : public QObject | ||||
| { | ||||
|     Q_OBJECT | ||||
|  | ||||
|  | ||||
| @ -17,6 +17,7 @@ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| #include <QObject> | ||||
| #include <QVariant> | ||||
|  | ||||
|  | ||||
|  | ||||
| @ -21,8 +21,6 @@ | ||||
|  | ||||
| #include "awdebug.h" | ||||
| #include "awformatterhelper.h" | ||||
| #include "formatters/formatters.h" | ||||
| #include "matchers/matchers.h" | ||||
|  | ||||
|  | ||||
| AWDataEngineMapper::AWDataEngineMapper(QObject *_parent, AWFormatterHelper *_custom) | ||||
| @ -32,25 +30,33 @@ AWDataEngineMapper::AWDataEngineMapper(QObject *_parent, AWFormatterHelper *_cus | ||||
|     qCDebug(LOG_AW) << __PRETTY_FUNCTION__; | ||||
|  | ||||
|     // default formatters | ||||
|     // memory | ||||
|     m_formatter["mem"] = AWKeysAggregator::FormatterType::Float; | ||||
|     m_formatter["memtotmb"] = AWKeysAggregator::FormatterType::MemMBFormat; | ||||
|     m_formatter["memtotgb"] = AWKeysAggregator::FormatterType::MemGBFormat; | ||||
|     // network | ||||
|     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(); | ||||
|     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; | ||||
|     // swap | ||||
|     m_formatter["swap"] = AWKeysAggregator::FormatterType::Float; | ||||
|     m_formatter["swaptotmb"] = AWKeysAggregator::FormatterType::MemMBFormat; | ||||
|     m_formatter["swaptotgb"] = AWKeysAggregator::FormatterType::MemGBFormat; | ||||
| } | ||||
|  | ||||
|  | ||||
| AWPluginFormaterInterface *AWDataEngineMapper::formatter(const QString &_key) const | ||||
| AWKeysAggregator::FormatterType AWDataEngineMapper::formatter(const QString &_key) const | ||||
| { | ||||
|     qCDebug(LOG_AW) << "Get formatter for key" << _key; | ||||
|  | ||||
|     return m_formatter.value(_key, AWPluginFormatterNoFormat::instance()); | ||||
|     return m_formatter.value(_key, AWKeysAggregator::FormatterType::NoFormat); | ||||
| } | ||||
|  | ||||
|  | ||||
| @ -69,44 +75,376 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const KSy | ||||
| { | ||||
|     qCDebug(LOG_AW) << "Source" << _source << "with units" << _units; | ||||
|  | ||||
|     auto matchers = AWPluginMatchers::matchers; | ||||
|     auto matcher = std::find_if(matchers.cbegin(), matchers.cend(), | ||||
|                                 [&_source](auto matcher) { return matcher->matches(_source); }); | ||||
|     if (matcher == matchers.cend()) | ||||
|         return {}; | ||||
|     // regular expressions | ||||
|     static auto cpuRegExp = QRegularExpression("^cpu/cpu.*/usage$"); | ||||
|     static auto cpuclRegExp = QRegularExpression("^cpu/cpu.*/frequency$"); | ||||
|     static auto cpuTempRegExp = QRegularExpression("^cpu/cpu.*/temperature$"); | ||||
|     static auto gpuRegExp = QRegularExpression("^gpu/gpu.*/usage$"); | ||||
|     static auto gpuTempRegExp = QRegularExpression("^gpu/gpu.*/temperature$"); | ||||
|     static auto hddrRegExp = QRegularExpression("^disk/.*/read$"); | ||||
|     static auto hddwRegExp = QRegularExpression("^disk/.*/write$"); | ||||
|     static auto mountFillRegExp = QRegularExpression("^disk/.*/usedPercent$"); | ||||
|     static auto mountFreeRegExp = QRegularExpression("^disk/.*/free$"); | ||||
|     static auto mountUsedRegExp = QRegularExpression("^disk/.*/used$"); | ||||
|     static auto netRegExp = QRegularExpression("^network/.*/(download|upload)$"); | ||||
|     static auto netTotalRegExp = QRegularExpression("^network/.*/(totalDownload|totalUpload)$"); | ||||
|  | ||||
|     auto foundKeys = (*matcher)->keys(_source, _units, m_settings); | ||||
|     auto keys = foundKeys.keys(); // speedup a little bit | ||||
|     if (_source == "extsysmon/battery/ac") { | ||||
|         // AC | ||||
|         m_map.insert(_source, "ac"); | ||||
|         m_formatter["ac"] = AWKeysAggregator::FormatterType::ACFormat; | ||||
|     } 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; | ||||
|     } else if (_source == "cpu/all/usage") { | ||||
|         // cpu | ||||
|         m_map.insert(_source, "cpu"); | ||||
|         m_formatter["cpu"] = AWKeysAggregator::FormatterType::Float; | ||||
|     } 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; | ||||
|     } else if (_source == "cpu/all/averageFrequency") { | ||||
|         // cpucl | ||||
|         m_map.insert(_source, "cpucl"); | ||||
|         m_formatter["cpucl"] = AWKeysAggregator::FormatterType::Integer; | ||||
|     } 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; | ||||
|     } 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; | ||||
|     } else if (_source == "extsysmon/desktop/name") { | ||||
|         // current desktop name | ||||
|         m_map.insert(_source, "desktop"); | ||||
|         m_formatter["desktop"] = AWKeysAggregator::FormatterType::NoFormat; | ||||
|     } else if (_source == "extsysmon/desktop/number") { | ||||
|         // current desktop number | ||||
|         m_map.insert(_source, "ndesktop"); | ||||
|         m_formatter["ndesktop"] = AWKeysAggregator::FormatterType::NoFormat; | ||||
|     } else if (_source == "extsysmon/desktop/count") { | ||||
|         // desktop count | ||||
|         m_map.insert(_source, "tdesktops"); | ||||
|         m_formatter["tdesktops"] = AWKeysAggregator::FormatterType::NoFormat; | ||||
|     } else if (_source.contains(hddrRegExp)) { | ||||
|         // read speed | ||||
|         auto device = _source; | ||||
|         device.remove("disk/").remove("/read"); | ||||
|         auto index = m_devices["disk"].indexOf(device); | ||||
|         if (index > -1) { | ||||
|             QString key = QString("hddr%1").arg(index); | ||||
|             m_map.insert(_source, key); | ||||
|             m_formatter[key] = AWKeysAggregator::FormatterType::MemKBFormat; | ||||
|         } | ||||
|     } else if (_source.contains(hddwRegExp)) { | ||||
|         // write speed | ||||
|         auto device = _source; | ||||
|         device.remove("disk/").remove("/write"); | ||||
|         auto index = m_devices["disk"].indexOf(device); | ||||
|         if (index > -1) { | ||||
|             QString key = QString("hddw%1").arg(index); | ||||
|             m_map.insert(_source, key); | ||||
|             m_formatter[key] = AWKeysAggregator::FormatterType::MemKBFormat; | ||||
|         } | ||||
|     } else if (_source == "gpu/all/usage") { | ||||
|         // gpu load | ||||
|         m_map.insert(_source, "gpu"); | ||||
|         m_formatter["gpu"] = AWKeysAggregator::FormatterType::Float; | ||||
|     } else if (_source.contains(gpuRegExp)) { | ||||
|         // gpus | ||||
|         auto device = _source; | ||||
|         device.remove("gpu/").remove("/usage"); | ||||
|         auto index = m_devices["gpu"].indexOf(device); | ||||
|         if (index > -1) { | ||||
|             auto key = QString("gpu%1").arg(index); | ||||
|             m_map.insert(_source, key); | ||||
|             m_formatter[key] = AWKeysAggregator::FormatterType::Float; | ||||
|         } | ||||
|     } else if (_source.contains(gpuTempRegExp)) { | ||||
|         // gpus temps | ||||
|         auto device = _source; | ||||
|         device.remove("gpu/").remove("/temperature"); | ||||
|         auto index = m_devices["gpu"].indexOf(device); | ||||
|         if (index > -1) { | ||||
|             auto key = QString("gputemp%1").arg(index); | ||||
|             m_map.insert(_source, key); | ||||
|             m_formatter[key] = AWKeysAggregator::FormatterType::Temperature; | ||||
|         } | ||||
|     } else if (_source.contains(mountFillRegExp)) { | ||||
|         // fill level | ||||
|         auto device = _source; | ||||
|         device.remove("disk/").remove("/usedPercent"); | ||||
|         auto index = m_devices["mount"].indexOf(device); | ||||
|         if (index > -1) { | ||||
|             auto key = QString("hdd%1").arg(index); | ||||
|             m_map.insert(_source, key); | ||||
|             m_formatter[key] = AWKeysAggregator::FormatterType::Float; | ||||
|             // additional keys | ||||
|             m_formatter[QString("hddtotmb%1").arg(index)] = AWKeysAggregator::FormatterType::MemMBFormat; | ||||
|             m_formatter[QString("hddtotgb%1").arg(index)] = AWKeysAggregator::FormatterType::MemGBFormat; | ||||
|         } | ||||
|     } else if (_source.contains(mountFreeRegExp)) { | ||||
|         // free space | ||||
|         auto device = _source; | ||||
|         device.remove("disk/").remove("/free"); | ||||
|         auto index = m_devices["mount"].indexOf(device); | ||||
|         if (index > -1) { | ||||
|             // mb | ||||
|             auto key = QString("hddfreemb%1").arg(index); | ||||
|             m_map.insert(_source, key); | ||||
|             m_formatter[key] = AWKeysAggregator::FormatterType::MemMBFormat; | ||||
|             // gb | ||||
|             key = QString("hddfreegb%1").arg(index); | ||||
|             m_map.insert(_source, key); | ||||
|             m_formatter[key] = AWKeysAggregator::FormatterType::MemGBFormat; | ||||
|         } | ||||
|     } else if (_source.contains(mountUsedRegExp)) { | ||||
|         // used | ||||
|         auto device = _source; | ||||
|         device.remove("disk/").remove("/used"); | ||||
|         auto index = m_devices["mount"].indexOf(device); | ||||
|         if (index > -1) { | ||||
|             // mb | ||||
|             auto key = QString("hddmb%1").arg(index); | ||||
|             m_map.insert(_source, key); | ||||
|             m_formatter[key] = AWKeysAggregator::FormatterType::MemMBFormat; | ||||
|             // gb | ||||
|             key = QString("hddgb%1").arg(index); | ||||
|             m_map.insert(_source, key); | ||||
|             m_formatter[key] = AWKeysAggregator::FormatterType::MemGBFormat; | ||||
|         } | ||||
|     } else if (_source.startsWith("cpu/loadaverages/loadaverage")) { | ||||
|         // load average | ||||
|         auto time = _source; | ||||
|         time.remove("cpu/loadaverages/loadaverage"); | ||||
|         auto key = QString("la%1").arg(time); | ||||
|         m_map.insert(_source, key); | ||||
|         m_formatter[key] = AWKeysAggregator::FormatterType::FloatTwoSymbols; | ||||
|     } else if (_source == "memory/physical/application") { | ||||
|         // app memory | ||||
|         // mb | ||||
|         m_map.insert(_source, "memmb"); | ||||
|         m_formatter["memmb"] = AWKeysAggregator::FormatterType::MemMBFormat; | ||||
|         // gb | ||||
|         m_map.insert(_source, "memgb"); | ||||
|         m_formatter["memgb"] = AWKeysAggregator::FormatterType::MemGBFormat; | ||||
|     } else if (_source == "memory/physical/free") { | ||||
|         // free memory | ||||
|         // mb | ||||
|         m_map.insert(_source, "memfreemb"); | ||||
|         m_formatter["memfreemb"] = AWKeysAggregator::FormatterType::MemMBFormat; | ||||
|         // gb | ||||
|         m_map.insert(_source, "memfreegb"); | ||||
|         m_formatter["memfreegb"] = AWKeysAggregator::FormatterType::MemGBFormat; | ||||
|     } else if (_source == "memory/physical/used") { | ||||
|         // used memory | ||||
|         // mb | ||||
|         m_map.insert(_source, "memusedmb"); | ||||
|         m_formatter["memusedmb"] = AWKeysAggregator::FormatterType::MemMBFormat; | ||||
|         // gb | ||||
|         m_map.insert(_source, "memusedgb"); | ||||
|         m_formatter["memusedgb"] = AWKeysAggregator::FormatterType::MemGBFormat; | ||||
|     } else if (_source == "extsysmon/network/device") { | ||||
|         // network device | ||||
|         m_map.insert(_source, "netdev"); | ||||
|         m_formatter["netdev"] = AWKeysAggregator::FormatterType::NoFormat; | ||||
|     } else if (_source == "extsysmon/network/ssid") { | ||||
|         // current ssid | ||||
|         m_map.insert(_source, "ssid"); | ||||
|         m_formatter["ssid"] = AWKeysAggregator::FormatterType::NoFormat; | ||||
|     } 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; | ||||
|     } else if (_source.contains(netRegExp)) { | ||||
|         // network speed | ||||
|         auto type = _source.endsWith("download") ? "down" : "up"; | ||||
|         auto index = m_devices["net"].indexOf(_source.split('/')[1]); | ||||
|         if (index > -1) { | ||||
|             // kb | ||||
|             auto key = QString("%1kb%2").arg(type).arg(index); | ||||
|             m_map.insert(_source, key); | ||||
|             m_formatter[key] = AWKeysAggregator::FormatterType::MemKBFormat; | ||||
|             // smart | ||||
|             key = QString("%1%2").arg(type).arg(index); | ||||
|             m_map.insert(_source, key); | ||||
|             m_formatter[key] = AWKeysAggregator::FormatterType::NetSmartFormat; | ||||
|             // units | ||||
|             key = QString("%1units%2").arg(type).arg(index); | ||||
|             m_map.insert(_source, key); | ||||
|             m_formatter[key] = AWKeysAggregator::FormatterType::NetSmartUnits; | ||||
|         } | ||||
|     } else if (_source.contains(netTotalRegExp)) { | ||||
|         // network data total | ||||
|         auto type = _source.endsWith("Download") ? "down" : "up"; | ||||
|         auto index = m_devices["net"].indexOf(_source.split('/')[1]); | ||||
|         if (index > -1) { | ||||
|             // kb | ||||
|             auto key = QString("%1totkb%2").arg(type).arg(index); | ||||
|             m_map.insert(_source, key); | ||||
|             m_formatter[key] = AWKeysAggregator::FormatterType::MemKBFormat; | ||||
|             // mb | ||||
|             key = QString("%1tot%2").arg(type).arg(index); | ||||
|             m_map.insert(_source, key); | ||||
|             m_formatter[key] = AWKeysAggregator::FormatterType::MemMBFormat; | ||||
|         } | ||||
|     } 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; | ||||
|     } 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; | ||||
|     } else if (_source == "extsysmon/ps/running") { | ||||
|         // running processes count | ||||
|         m_map.insert(_source, "pscount"); | ||||
|         m_formatter["pscount"] = AWKeysAggregator::FormatterType::NoFormat; | ||||
|     } else if (_source == "extsysmon/ps/list") { | ||||
|         // list of running processes | ||||
|         m_map.insert(_source, "ps"); | ||||
|         m_formatter["ps"] = AWKeysAggregator::FormatterType::List; | ||||
|     } else if (_source == "extsysmon/ps/count") { | ||||
|         // total processes count | ||||
|         m_map.insert(_source, "pstot"); | ||||
|         m_formatter["pstot"] = AWKeysAggregator::FormatterType::NoFormat; | ||||
|     } 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; | ||||
|     } else if (_source == "memory/swap/free") { | ||||
|         // free swap | ||||
|         // mb | ||||
|         m_map.insert(_source, "swapfreemb"); | ||||
|         m_formatter["swapfreemb"] = AWKeysAggregator::FormatterType::MemMBFormat; | ||||
|         // gb | ||||
|         m_map.insert(_source, "swapfreegb"); | ||||
|         m_formatter["swapfreegb"] = AWKeysAggregator::FormatterType::MemGBFormat; | ||||
|     } else if (_source == "memory/swap/used") { | ||||
|         // used swap | ||||
|         // mb | ||||
|         m_map.insert(_source, "swapmb"); | ||||
|         m_formatter["swapmb"] = AWKeysAggregator::FormatterType::MemMBFormat; | ||||
|         // gb | ||||
|         m_map.insert(_source, "swapgb"); | ||||
|         m_formatter["swapgb"] = AWKeysAggregator::FormatterType::MemGBFormat; | ||||
|     } else if (_source.startsWith("lmsensors/") || _source.contains(cpuTempRegExp) | ||||
|                || _source == "cpu/all/averageTemperature") { | ||||
|         // temperature | ||||
|         auto index = m_devices["temp"].indexOf(_source); | ||||
|         // HACK on DE initialization there are no units key | ||||
|         if (_units == KSysGuard::UnitInvalid) | ||||
|             return QStringList({QString("temp%1").arg(index)}); | ||||
|         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; | ||||
|         } | ||||
|     } else if (_source == "extsysmon/time/now") { | ||||
|         // time | ||||
|         m_map.insert(_source, "time"); | ||||
|         m_formatter["time"] = AWKeysAggregator::FormatterType::Time; | ||||
|         // custom time | ||||
|         m_map.insert(_source, "ctime"); | ||||
|         m_formatter["ctime"] = AWKeysAggregator::FormatterType::TimeCustom; | ||||
|         // ISO time | ||||
|         m_map.insert(_source, "isotime"); | ||||
|         m_formatter["isotime"] = AWKeysAggregator::FormatterType::TimeISO; | ||||
|         // long time | ||||
|         m_map.insert(_source, "longtime"); | ||||
|         m_formatter["longtime"] = AWKeysAggregator::FormatterType::TimeLong; | ||||
|         // short time | ||||
|         m_map.insert(_source, "shorttime"); | ||||
|         m_formatter["shorttime"] = AWKeysAggregator::FormatterType::TimeShort; | ||||
|         // timestamp | ||||
|         m_map.insert(_source, "tstime"); | ||||
|         m_formatter["tstime"] = AWKeysAggregator::FormatterType::Timestamp; | ||||
|     } else if (_source == "extsysmon/system/brightness") { | ||||
|         m_map.insert(_source, "brightness"); | ||||
|         m_formatter["brightness"] = AWKeysAggregator::FormatterType::IntegerThree; | ||||
|     } else if (_source == "extsysmon/system/volume") { | ||||
|         m_map.insert(_source, "volume"); | ||||
|         m_formatter["volume"] = AWKeysAggregator::FormatterType::IntegerThree; | ||||
|     } 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; | ||||
|     } 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; | ||||
|     } 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; | ||||
|     } 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; | ||||
|     } | ||||
|  | ||||
|     auto foundKeys = keysFromSource(_source); | ||||
|  | ||||
|     // rewrite formatters for custom ones | ||||
|     QStringList customFormattersKeys; | ||||
|     if (m_customFormatters) | ||||
|         customFormattersKeys = m_customFormatters->definedFormatters(); | ||||
|     qCInfo(LOG_AW) << "Looking for formatters" << keys << "in" << customFormattersKeys; | ||||
|     for (auto &key : keys) { | ||||
|     qCInfo(LOG_AW) << "Looking for formatters" << foundKeys << "in" << customFormattersKeys; | ||||
|     for (auto &key : foundKeys) { | ||||
|         if (!customFormattersKeys.contains(key)) | ||||
|             continue; | ||||
|         foundKeys[key] = AWPluginFormatterCustom::instance(); | ||||
|         m_formatter[key] = AWKeysAggregator::FormatterType::Custom; | ||||
|     } | ||||
|  | ||||
|     // check if keys were actually requested | ||||
|     qCInfo(LOG_AW) << "Looking for keys" << keys << "in" << _keys; | ||||
|     auto required = _keys.isEmpty() | ||||
|                     || std::any_of(keys.cbegin(), keys.cend(), [&_keys](auto &key) { return _keys.contains(key); }); | ||||
|     if (!required) | ||||
|         return {}; | ||||
|  | ||||
|     // insert keys into memory | ||||
|     for (auto [key, formatter] : foundKeys.asKeyValueRange()) { | ||||
|         m_map.insert(_source, key); | ||||
|         m_formatter[key] = formatter; | ||||
|     // drop key from dictionary if no one user requested key required it | ||||
|     qCInfo(LOG_AW) << "Looking for keys" << foundKeys << "in" << _keys; | ||||
|     auto required = _keys.isEmpty() || std::any_of(foundKeys.cbegin(), foundKeys.cend(), [&_keys](auto &key) { | ||||
|                         return _keys.contains(key); | ||||
|                     }); | ||||
|     if (!required) { | ||||
|         m_map.remove(_source); | ||||
|         for (auto &key : foundKeys) | ||||
|             m_formatter.remove(key); | ||||
|     } | ||||
|  | ||||
|     return keys; | ||||
|     return keysFromSource(_source); | ||||
| } | ||||
|  | ||||
|  | ||||
| void AWDataEngineMapper::setDevices(const AWPluginMatcherSettings &_settings) | ||||
| void AWDataEngineMapper::setDevices(const QHash<QString, QStringList> &_devices) | ||||
| { | ||||
|     m_settings = _settings; | ||||
|     qCDebug(LOG_AW) << "Devices" << _devices; | ||||
|  | ||||
|     m_devices = _devices; | ||||
| } | ||||
|  | ||||
| @ -22,8 +22,7 @@ | ||||
| #include <QMultiHash> | ||||
| #include <QObject> | ||||
|  | ||||
| #include "formatters/awpluginformatter.h" | ||||
| #include "matchers/awpluginmatchersettings.h" | ||||
| #include "awkeysaggregator.h" | ||||
|  | ||||
|  | ||||
| class AWFormatterHelper; | ||||
| @ -36,17 +35,16 @@ public: | ||||
|     explicit AWDataEngineMapper(QObject *_parent = nullptr, AWFormatterHelper *_custom = nullptr); | ||||
|     ~AWDataEngineMapper() override = default; | ||||
|     // get methods | ||||
|     [[nodiscard]] AWPluginFormaterInterface *formatter(const QString &_key) const; | ||||
|     [[nodiscard]] AWKeysAggregator::FormatterType 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); | ||||
|     void setDevices(const AWPluginMatcherSettings &_settings); | ||||
|     void setDevices(const QHash<QString, QStringList> &_devices); | ||||
|  | ||||
| private: | ||||
|     AWFormatterHelper *m_customFormatters = nullptr; | ||||
|     AWPluginMatcherSettings m_settings; | ||||
|     // variables | ||||
|     QHash<QString, QStringList> m_devices; | ||||
|     QHash<QString, AWPluginFormaterInterface *> m_formatter; | ||||
|     QHash<QString, AWKeysAggregator::FormatterType> m_formatter; | ||||
|     QMultiHash<QString, QString> m_map; | ||||
| }; | ||||
|  | ||||
| @ -82,7 +82,47 @@ QStringList AWKeyCache::getRequiredKeys(const QStringList &_keys, const QStringL | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     // insert keys which depend on others, refer to AWKeys::calculateValues() | ||||
|     // insert depending keys, refer to AWKeys::calculateValues() | ||||
|     // hddtotmb* | ||||
|     for (auto &key : _allKeys.filter(QRegularExpression("^hddtotmb"))) { | ||||
|         if (!used.contains(key)) | ||||
|             continue; | ||||
|         key.remove("hddtotmb"); | ||||
|         auto index = key.toInt(); | ||||
|         used << QString("hddfreemb%1").arg(index) << QString("hddmb%1").arg(index); | ||||
|     } | ||||
|     // hddtotgb* | ||||
|     for (auto &key : _allKeys.filter(QRegularExpression("^hddtotgb"))) { | ||||
|         if (!used.contains(key)) | ||||
|             continue; | ||||
|         key.remove("hddtotgb"); | ||||
|         auto index = key.toInt(); | ||||
|         used << QString("hddfreegb%1").arg(index) << QString("hddgb%1").arg(index); | ||||
|     } | ||||
|     // mem | ||||
|     if (used.contains("mem")) | ||||
|         used << "memmb" | ||||
|              << "memtotmb"; | ||||
|     // memtotmb | ||||
|     if (used.contains("memtotmb")) | ||||
|         used << "memusedmb" | ||||
|              << "memfreemb"; | ||||
|     // memtotgb | ||||
|     if (used.contains("memtotgb")) | ||||
|         used << "memusedgb" | ||||
|              << "memfreegb"; | ||||
|     // swap | ||||
|     if (used.contains("swap")) | ||||
|         used << "swapmb" | ||||
|              << "swaptotmb"; | ||||
|     // swaptotmb | ||||
|     if (used.contains("swaptotmb")) | ||||
|         used << "swapmb" | ||||
|              << "swapfreemb"; | ||||
|     // memtotgb | ||||
|     if (used.contains("swaptotgb")) | ||||
|         used << "swapgb" | ||||
|              << "swapfreegb"; | ||||
|     // network keys | ||||
|     QStringList netKeys( | ||||
|         {"up", "upkb", "uptot", "uptotkb", "upunits", "down", "downkb", "downtot", "downtotkb", "downunits"}); | ||||
| @ -106,23 +146,18 @@ QStringList AWKeyCache::getRequiredKeys(const QStringList &_keys, const QStringL | ||||
| } | ||||
|  | ||||
|  | ||||
| AWPluginMatcherSettings AWKeyCache::loadKeysFromCache() | ||||
| QHash<QString, QStringList> AWKeyCache::loadKeysFromCache() | ||||
| { | ||||
|     auto fileName | ||||
|         = QString("%1/awesomewidgets.ndx").arg(QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation)); | ||||
|     qCInfo(LOG_AW) << "Cache file" << fileName; | ||||
|     QSettings cache(fileName, QSettings::IniFormat); | ||||
|  | ||||
|     AWPluginMatcherSettings devices; | ||||
|     QHash<QString, QStringList *> groups = { | ||||
|         {"disk", &devices.disk},   {"gpu", &devices.gpu},      {"mount", &devices.mount}, | ||||
|         {"net", &devices.network}, {"temp", &devices.sensors}, | ||||
|     }; | ||||
|  | ||||
|     for (auto [group, list] : groups.asKeyValueRange()) { | ||||
|     QHash<QString, QStringList> devices; | ||||
|     for (auto &group : cache.childGroups()) { | ||||
|         cache.beginGroup(group); | ||||
|         for (auto &key : cache.allKeys()) | ||||
|             list->append(cache.value(key).toString()); | ||||
|             devices[group].append(cache.value(key).toString()); | ||||
|         cache.endGroup(); | ||||
|     } | ||||
|  | ||||
|  | ||||
| @ -17,16 +17,15 @@ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| #include <QHash> | ||||
| #include <QString> | ||||
| #include <QVariant> | ||||
|  | ||||
| #include <matchers/awpluginmatchersettings.h> | ||||
|  | ||||
|  | ||||
| namespace AWKeyCache | ||||
| { | ||||
| bool addKeyToCache(const QString &_type, const QString &_key = ""); | ||||
| QStringList getRequiredKeys(const QStringList &_keys, const QStringList &_bars, const QVariantMap &_tooltip, | ||||
|                             const QStringList &_userKeys, const QStringList &_allKeys); | ||||
| AWPluginMatcherSettings loadKeysFromCache(); | ||||
| QHash<QString, QStringList> loadKeysFromCache(); | ||||
| } // namespace AWKeyCache | ||||
|  | ||||
| @ -49,7 +49,15 @@ AWKeyOperations::AWKeyOperations(QObject *_parent) | ||||
| } | ||||
|  | ||||
|  | ||||
| AWPluginMatcherSettings AWKeyOperations::devices() const | ||||
| QStringList AWKeyOperations::devices(const QString &_type) const | ||||
| { | ||||
|     qCDebug(LOG_AW) << "Looking for type" << _type; | ||||
|  | ||||
|     return m_devices[_type]; | ||||
| } | ||||
|  | ||||
|  | ||||
| QHash<QString, QStringList> AWKeyOperations::devices() const | ||||
| { | ||||
|     return m_devices; | ||||
| } | ||||
| @ -80,15 +88,15 @@ QStringList AWKeyOperations::dictKeys() const | ||||
|         allKeys.append(QString("cpu%1").arg(i)); | ||||
|     } | ||||
|     // temperature | ||||
|     for (auto i = 0; i < m_devices.sensors.count(); ++i) | ||||
|     for (auto i = 0; i < m_devices["temp"].count(); ++i) | ||||
|         allKeys.append(QString("temp%1").arg(i)); | ||||
|     // gpu | ||||
|     for (auto i = 0; i < m_devices.gpu.count(); ++i) { | ||||
|     for (auto i = 0; i < m_devices["gpu"].count(); ++i) { | ||||
|         allKeys.append(QString("gpu%1").arg(i)); | ||||
|         allKeys.append(QString("gputemp%1").arg(i)); | ||||
|     } | ||||
|     // hdd | ||||
|     for (auto i = 0; i < m_devices.mount.count(); ++i) { | ||||
|     for (auto i = 0; i < m_devices["mount"].count(); ++i) { | ||||
|         allKeys.append(QString("hddmb%1").arg(i)); | ||||
|         allKeys.append(QString("hddgb%1").arg(i)); | ||||
|         allKeys.append(QString("hddfreemb%1").arg(i)); | ||||
| @ -98,12 +106,12 @@ QStringList AWKeyOperations::dictKeys() const | ||||
|         allKeys.append(QString("hdd%1").arg(i)); | ||||
|     } | ||||
|     // hdd speed | ||||
|     for (auto i = 0; i < m_devices.disk.count(); ++i) { | ||||
|     for (auto i = 0; i < m_devices["disk"].count(); ++i) { | ||||
|         allKeys.append(QString("hddr%1").arg(i)); | ||||
|         allKeys.append(QString("hddw%1").arg(i)); | ||||
|     } | ||||
|     // network | ||||
|     for (auto i = 0; i < m_devices.network.count(); ++i) { | ||||
|     for (auto i = 0; i < m_devices["net"].count(); ++i) { | ||||
|         allKeys.append(QString("downunits%1").arg(i)); | ||||
|         allKeys.append(QString("upunits%1").arg(i)); | ||||
|         allKeys.append(QString("downtotkb%1").arg(i)); | ||||
| @ -216,15 +224,15 @@ QString AWKeyOperations::infoByKey(const QString &_key) const | ||||
|     } else if (_key.contains(hddrwRegExp)) { | ||||
|         auto index = _key; | ||||
|         index.remove(hddrwRegExp); | ||||
|         output = m_devices.disk[index.toInt()]; | ||||
|         output = m_devices["disk"][index.toInt()]; | ||||
|     } else if (_key.contains(hddMatchRegExp)) { | ||||
|         auto index = _key; | ||||
|         index.remove(hddRegExp); | ||||
|         output = m_devices.mount[index.toInt()]; | ||||
|         output = m_devices["mount"][index.toInt()]; | ||||
|     } else if (_key.contains(netMatchRegExp)) { | ||||
|         auto index = _key; | ||||
|         index.remove(netRegExp); | ||||
|         output = m_devices.network[index.toInt()]; | ||||
|         output = m_devices["net"][index.toInt()]; | ||||
|     } else if (_key.startsWith("pkgcount")) { | ||||
|         auto item = m_extUpgrade->itemByTag(_key, stripped); | ||||
|         if (item) | ||||
| @ -240,7 +248,7 @@ QString AWKeyOperations::infoByKey(const QString &_key) const | ||||
|     } else if (_key.startsWith("temp")) { | ||||
|         auto index = _key; | ||||
|         index.remove("temp"); | ||||
|         output = m_devices.sensors[index.toInt()]; | ||||
|         output = m_devices["temp"][index.toInt()]; | ||||
|     } else if (_key.startsWith("response")) { | ||||
|         auto item = m_extNetRequest->itemByTag(_key, stripped); | ||||
|         if (item) | ||||
|  | ||||
| @ -20,7 +20,6 @@ | ||||
| #include <QObject> | ||||
|  | ||||
| #include "extitemaggregator.h" | ||||
| #include "matchers/awpluginmatchersettings.h" | ||||
|  | ||||
|  | ||||
| class AWCustomKeysHelper; | ||||
| @ -39,7 +38,8 @@ class AWKeyOperations : public QObject | ||||
| public: | ||||
|     explicit AWKeyOperations(QObject *_parent = nullptr); | ||||
|     ~AWKeyOperations() override = default; | ||||
|     [[nodiscard]] AWPluginMatcherSettings devices() const; | ||||
|     [[nodiscard]] QStringList devices(const QString &_type) const; | ||||
|     [[nodiscard]] QHash<QString, QStringList> devices() const; | ||||
|     void updateCache(); | ||||
|     // keys | ||||
|     [[nodiscard]] QStringList dictKeys() const; | ||||
| @ -73,6 +73,6 @@ private: | ||||
|     ExtItemAggregator<ExtUpgrade> *m_extUpgrade = nullptr; | ||||
|     ExtItemAggregator<ExtWeather> *m_extWeather = nullptr; | ||||
|     // variables | ||||
|     AWPluginMatcherSettings m_devices; | ||||
|     QHash<QString, QStringList> m_devices; | ||||
|     QString m_pattern; | ||||
| }; | ||||
|  | ||||
| @ -231,10 +231,24 @@ void AWKeys::updateTextData() | ||||
| // specified pattern. Usually they are values which depend on several others | ||||
| void AWKeys::calculateValues() | ||||
| { | ||||
|     auto devices = m_keyOperator->devices(); | ||||
|     // hddtot* | ||||
|     auto mountDevices = m_keyOperator->devices("mount"); | ||||
|     for (auto &device : mountDevices) { | ||||
|         auto index = mountDevices.indexOf(device); | ||||
|         m_values[QString("hddtotmb%1").arg(index)] = m_values[QString("hddfreemb%1").arg(index)].toDouble() | ||||
|                                                      + m_values[QString("hddmb%1").arg(index)].toDouble(); | ||||
|         m_values[QString("hddtotgb%1").arg(index)] = m_values[QString("hddfreegb%1").arg(index)].toDouble() | ||||
|                                                      + m_values[QString("hddgb%1").arg(index)].toDouble(); | ||||
|     } | ||||
|  | ||||
|     // memtot* | ||||
|     m_values["memtotmb"] = m_values["memusedmb"].toLongLong() + m_values["memfreemb"].toLongLong(); | ||||
|     m_values["memtotgb"] = m_values["memusedgb"].toDouble() + m_values["memfreegb"].toDouble(); | ||||
|     // mem | ||||
|     m_values["mem"] = 100.0 * m_values["memmb"].toDouble() / m_values["memtotmb"].toDouble(); | ||||
|  | ||||
|     // up, down, upkb, downkb, upunits, downunits | ||||
|     auto netIndex = devices.network.indexOf(m_values["netdev"].toString()); | ||||
|     auto netIndex = m_keyOperator->devices("net").indexOf(m_values["netdev"].toString()); | ||||
|     m_values["down"] = m_values[QString("down%1").arg(netIndex)]; | ||||
|     m_values["downkb"] = m_values[QString("downkb%1").arg(netIndex)]; | ||||
|     m_values["downtot"] = m_values[QString("downtot%1").arg(netIndex)]; | ||||
| @ -246,6 +260,12 @@ void AWKeys::calculateValues() | ||||
|     m_values["uptotkb"] = m_values[QString("uptotkb%1").arg(netIndex)]; | ||||
|     m_values["upunits"] = m_values[QString("upunits%1").arg(netIndex)]; | ||||
|  | ||||
|     // swaptot* | ||||
|     m_values["swaptotmb"] = m_values["swapmb"].toLongLong() + m_values["swapfreemb"].toLongLong(); | ||||
|     m_values["swaptotgb"] = m_values["swapgb"].toDouble() + m_values["swapfreegb"].toDouble(); | ||||
|     // swap | ||||
|     m_values["swap"] = 100.0 * m_values["swapmb"].toDouble() / m_values["swaptotmb"].toDouble(); | ||||
|  | ||||
|     // user defined keys | ||||
|     for (auto &key : m_keyOperator->userKeys()) | ||||
|         m_values[key] = m_values[m_keyOperator->userKeySource(key)]; | ||||
|  | ||||
| @ -28,7 +28,7 @@ class AWKeyOperations; | ||||
| class AWKeysAggregator; | ||||
| class QTimer; | ||||
|  | ||||
| class __attribute__((visibility("default"))) AWKeys : public QObject | ||||
| class AWKeys : public QObject | ||||
| { | ||||
|     Q_OBJECT | ||||
|  | ||||
|  | ||||
| @ -17,9 +17,15 @@ | ||||
|  | ||||
| #include "awkeysaggregator.h" | ||||
|  | ||||
| #include <KI18n/KLocalizedString> | ||||
|  | ||||
| #include <QDateTime> | ||||
| #include <QLocale> | ||||
|  | ||||
| #include "awdataenginemapper.h" | ||||
| #include "awdebug.h" | ||||
| #include "awformatterhelper.h" | ||||
| #include "version.h" | ||||
|  | ||||
|  | ||||
| AWKeysAggregator::AWKeysAggregator(QObject *_parent) | ||||
| @ -27,38 +33,19 @@ AWKeysAggregator::AWKeysAggregator(QObject *_parent) | ||||
| { | ||||
|     qCDebug(LOG_AW) << __PRETTY_FUNCTION__; | ||||
|  | ||||
|     m_settings.customFormatters = new AWFormatterHelper(this); | ||||
|     m_mapper = new AWDataEngineMapper(this, m_settings.customFormatters); | ||||
|     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()); | ||||
| } | ||||
|  | ||||
|  | ||||
| void AWKeysAggregator::initFormatters() | ||||
| { | ||||
|     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; | ||||
|     m_customFormatters->initItems(); | ||||
| } | ||||
|  | ||||
|  | ||||
| @ -66,7 +53,113 @@ QString AWKeysAggregator::formatter(const QVariant &_data, const QString &_key, | ||||
| { | ||||
|     qCDebug(LOG_AW) << "Data" << _data << "for key" << _key; | ||||
|  | ||||
|     auto output = m_mapper->formatter(_key)->format(_data, _key, m_settings); | ||||
|     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<int>(_data.toDouble())); | ||||
|         break; | ||||
|     case FormatterType::NoFormat: | ||||
|         output = _data.toString(); | ||||
|         break; | ||||
|     case FormatterType::Custom: | ||||
|         if (m_customFormatters) | ||||
|             output = m_customFormatters->convert(_data, _key); | ||||
|         break; | ||||
|     } | ||||
|  | ||||
|     // replace spaces to non-breakable ones | ||||
|     replaceSpace &= (!_key.startsWith("custom") && (!_key.startsWith("weather"))); | ||||
|     if (replaceSpace) | ||||
| @ -84,23 +177,11 @@ 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_settings.acOffline = _inactive; | ||||
|     m_acOffline = _inactive; | ||||
| } | ||||
|  | ||||
|  | ||||
| @ -108,7 +189,7 @@ void AWKeysAggregator::setAcOnline(const QString &_active) | ||||
| { | ||||
|     qCDebug(LOG_AW) << "Active AC string" << _active; | ||||
|  | ||||
|     m_settings.acOnline = _active; | ||||
|     m_acOnline = _active; | ||||
| } | ||||
|  | ||||
|  | ||||
| @ -116,7 +197,7 @@ void AWKeysAggregator::setCustomTime(const QString &_customTime) | ||||
| { | ||||
|     qCDebug(LOG_AW) << "Format" << _customTime; | ||||
|  | ||||
|     m_settings.customTime = _customTime; | ||||
|     m_customTime = _customTime; | ||||
| } | ||||
|  | ||||
|  | ||||
| @ -124,13 +205,15 @@ void AWKeysAggregator::setCustomUptime(const QString &_customUptime) | ||||
| { | ||||
|     qCDebug(LOG_AW) << "Format" << _customUptime; | ||||
|  | ||||
|     m_settings.customUptime = _customUptime; | ||||
|     m_customUptime = _customUptime; | ||||
| } | ||||
|  | ||||
|  | ||||
| void AWKeysAggregator::setDevices(const AWPluginMatcherSettings &_settings) | ||||
| void AWKeysAggregator::setDevices(const QHash<QString, QStringList> &_devices) | ||||
| { | ||||
|     m_mapper->setDevices(_settings); | ||||
|     qCDebug(LOG_AW) << "Devices" << _devices; | ||||
|  | ||||
|     m_mapper->setDevices(_devices); | ||||
| } | ||||
|  | ||||
|  | ||||
| @ -138,7 +221,7 @@ void AWKeysAggregator::setTempUnits(const QString &_units) | ||||
| { | ||||
|     qCDebug(LOG_AW) << "Units" << _units; | ||||
|  | ||||
|     m_settings.tempUnits = _units; | ||||
|     m_tempUnits = _units; | ||||
| } | ||||
|  | ||||
|  | ||||
| @ -146,7 +229,7 @@ void AWKeysAggregator::setTranslate(const bool _translate) | ||||
| { | ||||
|     qCDebug(LOG_AW) << "Translate" << _translate; | ||||
|  | ||||
|     m_settings.translate = _translate; | ||||
|     m_translate = _translate; | ||||
| } | ||||
|  | ||||
|  | ||||
| @ -157,3 +240,29 @@ 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; | ||||
| } | ||||
|  | ||||
| @ -22,41 +22,66 @@ | ||||
| #include <QHash> | ||||
| #include <QObject> | ||||
|  | ||||
| #include "formatters/awpluginformatsettings.h" | ||||
| #include "matchers/awpluginmatchersettings.h" | ||||
|  | ||||
|  | ||||
| class AWFormatterHelper; | ||||
| class AWDataEngineMapper; | ||||
|  | ||||
| class AWKeysAggregator : public QObject | ||||
| { | ||||
|     Q_OBJECT | ||||
|     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); | ||||
|     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); | ||||
|  | ||||
| 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); | ||||
|     void setCustomTime(const QString &_customTime); | ||||
|     void setCustomUptime(const QString &_customUptime); | ||||
|     void setDevices(const AWPluginMatcherSettings &_settings); | ||||
|     void setDevices(const QHash<QString, QStringList> &_devices); | ||||
|     void setTempUnits(const QString &_units); | ||||
|     void setTranslate(bool _translate); | ||||
|  | ||||
| @ -64,6 +89,15 @@ public slots: | ||||
|     QStringList registerSource(const QString &_source, KSysGuard::Unit _units, const QStringList &_keys); | ||||
|  | ||||
| private: | ||||
|     AWPluginFormatSettings m_settings; | ||||
|     [[nodiscard]] double temperature(double temp) const; | ||||
|     AWFormatterHelper *m_customFormatters = nullptr; | ||||
|     AWDataEngineMapper *m_mapper = nullptr; | ||||
|     QStringList m_timeKeys; | ||||
|     // variables | ||||
|     QString m_acOffline; | ||||
|     QString m_acOnline; | ||||
|     QString m_customTime; | ||||
|     QString m_customUptime; | ||||
|     QString m_tempUnits; | ||||
|     bool m_translate = false; | ||||
| }; | ||||
|  | ||||
| @ -29,4 +29,6 @@ public: | ||||
|     ~AWPairConfigFactory() override = default; | ||||
|     Q_INVOKABLE static void showFormatterDialog(const QStringList &_keys); | ||||
|     Q_INVOKABLE static void showKeysDialog(const QStringList &_keys); | ||||
|  | ||||
| private: | ||||
| }; | ||||
|  | ||||
| @ -23,7 +23,7 @@ | ||||
|  | ||||
| class AWKeysAggregator; | ||||
|  | ||||
| namespace __attribute__((visibility("default"))) AWPatternFunctions | ||||
| namespace AWPatternFunctions | ||||
| { | ||||
| typedef struct { | ||||
|     QStringList args; | ||||
|  | ||||
| @ -20,7 +20,7 @@ | ||||
| #include <QObject> | ||||
|  | ||||
|  | ||||
| class __attribute__((visibility("default"))) AWTelemetryHandler : public QObject | ||||
| class AWTelemetryHandler : public QObject | ||||
| { | ||||
|     Q_OBJECT | ||||
|  | ||||
|  | ||||
| @ -17,9 +17,6 @@ | ||||
|  | ||||
| #include "awupdatehelper.h" | ||||
|  | ||||
| #ifndef NDEBUG | ||||
| #define NDEBUG | ||||
| #endif /* NDEBUG */ | ||||
| #include <KI18n/KLocalizedString> | ||||
| #include <KNotifications/KNotification> | ||||
|  | ||||
|  | ||||
| @ -24,7 +24,7 @@ | ||||
| class KNotification; | ||||
| class QNetworkReply; | ||||
|  | ||||
| class __attribute__((visibility("default"))) AWUpdateHelper : public QObject | ||||
| class AWUpdateHelper : public QObject | ||||
| { | ||||
|     Q_OBJECT | ||||
|  | ||||
|  | ||||
| @ -1,37 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   This file is part of awesome-widgets                                  * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is free software: you can redistribute it and/or      * | ||||
|  *   modify it under the terms of the GNU General Public License as        * | ||||
|  *   published by the Free Software Foundation, either version 3 of the    * | ||||
|  *   License, or (at your option) any later version.                       * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is distributed in the hope that it will be useful,    * | ||||
|  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        * | ||||
|  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         * | ||||
|  *   GNU General Public License for more details.                          * | ||||
|  *                                                                         * | ||||
|  *   You should have received a copy of the GNU General Public License     * | ||||
|  *   along with awesome-widgets. If not, see http://www.gnu.org/licenses/  * | ||||
|  ***************************************************************************/ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| #include <QString> | ||||
|  | ||||
|  | ||||
| class AWFormatterHelper; | ||||
|  | ||||
| struct AWPluginFormatSettings { | ||||
|     QString acOffline; | ||||
|     QString acOnline; | ||||
|  | ||||
|     QString customTime; | ||||
|     QString customUptime; | ||||
|  | ||||
|     QString tempUnits; | ||||
|  | ||||
|     bool translate = false; | ||||
|  | ||||
|     AWFormatterHelper *customFormatters = nullptr; | ||||
| }; | ||||
| @ -1,69 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   This file is part of awesome-widgets                                  * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is free software: you can redistribute it and/or      * | ||||
|  *   modify it under the terms of the GNU General Public License as        * | ||||
|  *   published by the Free Software Foundation, either version 3 of the    * | ||||
|  *   License, or (at your option) any later version.                       * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is distributed in the hope that it will be useful,    * | ||||
|  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        * | ||||
|  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         * | ||||
|  *   GNU General Public License for more details.                          * | ||||
|  *                                                                         * | ||||
|  *   You should have received a copy of the GNU General Public License     * | ||||
|  *   along with awesome-widgets. If not, see http://www.gnu.org/licenses/  * | ||||
|  ***************************************************************************/ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| #include <QLocale> | ||||
| #include <QVariant> | ||||
|  | ||||
| #include <memory> | ||||
|  | ||||
| #include "awpluginformatsettings.h" | ||||
|  | ||||
|  | ||||
| class AWPluginFormaterInterface | ||||
| { | ||||
| public: | ||||
|     virtual ~AWPluginFormaterInterface() = default; | ||||
|     [[nodiscard]] virtual QString format(const QVariant &_value, const QString &_key, | ||||
|                                          const AWPluginFormatSettings &_settings) const | ||||
|         = 0; | ||||
|     virtual void load(){}; | ||||
| }; | ||||
|  | ||||
|  | ||||
| template <typename Formatter> class AWPluginFormatter : public AWPluginFormaterInterface | ||||
| { | ||||
| public: | ||||
|     static constexpr double KBinBytes = 1024.0; | ||||
|     static constexpr double MBinBytes = 1024.0 * KBinBytes; | ||||
|     static constexpr double GBinBytes = 1024.0 * MBinBytes; | ||||
|  | ||||
|     AWPluginFormatter(AWPluginFormatter &) = delete; | ||||
|     void operator=(const AWPluginFormatter &) = delete; | ||||
|  | ||||
|     [[nodiscard]] static Formatter *instance() | ||||
|     { | ||||
|         static auto instance = loadInstance(); | ||||
|         return instance.get(); | ||||
|     }; | ||||
|  | ||||
|     [[nodiscard]] static QLocale locale(const AWPluginFormatSettings &_settings) | ||||
|     { | ||||
|         return _settings.translate ? QLocale::system() : QLocale::c(); | ||||
|     }; | ||||
|  | ||||
| protected: | ||||
|     AWPluginFormatter() = default; | ||||
|  | ||||
|     [[nodiscard]] static std::unique_ptr<Formatter> loadInstance() | ||||
|     { | ||||
|         auto instance = std::make_unique<Formatter>(); | ||||
|         instance->load(); | ||||
|         return instance; | ||||
|     }; | ||||
| }; | ||||
| @ -1,25 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   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; | ||||
| } | ||||
| @ -1,28 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   This file is part of awesome-widgets                                  * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is free software: you can redistribute it and/or      * | ||||
|  *   modify it under the terms of the GNU General Public License as        * | ||||
|  *   published by the Free Software Foundation, either version 3 of the    * | ||||
|  *   License, or (at your option) any later version.                       * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is distributed in the hope that it will be useful,    * | ||||
|  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        * | ||||
|  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         * | ||||
|  *   GNU General Public License for more details.                          * | ||||
|  *                                                                         * | ||||
|  *   You should have received a copy of the GNU General Public License     * | ||||
|  *   along with awesome-widgets. If not, see http://www.gnu.org/licenses/  * | ||||
|  ***************************************************************************/ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| #include "awpluginformatter.h" | ||||
|  | ||||
|  | ||||
| class AWPluginFormatterAC : public AWPluginFormatter<AWPluginFormatterAC> | ||||
| { | ||||
| public: | ||||
|     [[nodiscard]] QString format(const QVariant &_value, const QString &, | ||||
|                                  const AWPluginFormatSettings &_settings) const override; | ||||
| }; | ||||
| @ -1,29 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   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(); | ||||
| } | ||||
| @ -1,28 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   This file is part of awesome-widgets                                  * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is free software: you can redistribute it and/or      * | ||||
|  *   modify it under the terms of the GNU General Public License as        * | ||||
|  *   published by the Free Software Foundation, either version 3 of the    * | ||||
|  *   License, or (at your option) any later version.                       * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is distributed in the hope that it will be useful,    * | ||||
|  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        * | ||||
|  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         * | ||||
|  *   GNU General Public License for more details.                          * | ||||
|  *                                                                         * | ||||
|  *   You should have received a copy of the GNU General Public License     * | ||||
|  *   along with awesome-widgets. If not, see http://www.gnu.org/licenses/  * | ||||
|  ***************************************************************************/ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| #include "awpluginformatter.h" | ||||
|  | ||||
|  | ||||
| class AWPluginFormatterCustom : public AWPluginFormatter<AWPluginFormatterCustom> | ||||
| { | ||||
| public: | ||||
|     [[nodiscard]] QString format(const QVariant &_value, const QString &_key, | ||||
|                                  const AWPluginFormatSettings &_settings) const override; | ||||
| }; | ||||
| @ -1,25 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   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); | ||||
| } | ||||
| @ -1,28 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   This file is part of awesome-widgets                                  * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is free software: you can redistribute it and/or      * | ||||
|  *   modify it under the terms of the GNU General Public License as        * | ||||
|  *   published by the Free Software Foundation, either version 3 of the    * | ||||
|  *   License, or (at your option) any later version.                       * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is distributed in the hope that it will be useful,    * | ||||
|  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        * | ||||
|  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         * | ||||
|  *   GNU General Public License for more details.                          * | ||||
|  *                                                                         * | ||||
|  *   You should have received a copy of the GNU General Public License     * | ||||
|  *   along with awesome-widgets. If not, see http://www.gnu.org/licenses/  * | ||||
|  ***************************************************************************/ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| #include "awpluginformatter.h" | ||||
|  | ||||
|  | ||||
| class AWPluginFormatterDouble : public AWPluginFormatter<AWPluginFormatterDouble> | ||||
| { | ||||
| public: | ||||
|     [[nodiscard]] QString format(const QVariant &_value, const QString &, | ||||
|                                  const AWPluginFormatSettings &) const override; | ||||
| }; | ||||
| @ -1,24 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   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); | ||||
| } | ||||
| @ -1,28 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   This file is part of awesome-widgets                                  * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is free software: you can redistribute it and/or      * | ||||
|  *   modify it under the terms of the GNU General Public License as        * | ||||
|  *   published by the Free Software Foundation, either version 3 of the    * | ||||
|  *   License, or (at your option) any later version.                       * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is distributed in the hope that it will be useful,    * | ||||
|  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        * | ||||
|  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         * | ||||
|  *   GNU General Public License for more details.                          * | ||||
|  *                                                                         * | ||||
|  *   You should have received a copy of the GNU General Public License     * | ||||
|  *   along with awesome-widgets. If not, see http://www.gnu.org/licenses/  * | ||||
|  ***************************************************************************/ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| #include "awpluginformatter.h" | ||||
|  | ||||
|  | ||||
| class AWPluginFormatterFloat : public AWPluginFormatter<AWPluginFormatterFloat> | ||||
| { | ||||
| public: | ||||
|     [[nodiscard]] QString format(const QVariant &_value, const QString &, | ||||
|                                  const AWPluginFormatSettings &) const override; | ||||
| }; | ||||
| @ -1,25 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   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); | ||||
| } | ||||
| @ -1,28 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   This file is part of awesome-widgets                                  * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is free software: you can redistribute it and/or      * | ||||
|  *   modify it under the terms of the GNU General Public License as        * | ||||
|  *   published by the Free Software Foundation, either version 3 of the    * | ||||
|  *   License, or (at your option) any later version.                       * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is distributed in the hope that it will be useful,    * | ||||
|  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        * | ||||
|  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         * | ||||
|  *   GNU General Public License for more details.                          * | ||||
|  *                                                                         * | ||||
|  *   You should have received a copy of the GNU General Public License     * | ||||
|  *   along with awesome-widgets. If not, see http://www.gnu.org/licenses/  * | ||||
|  ***************************************************************************/ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| #include "awpluginformatter.h" | ||||
|  | ||||
|  | ||||
| class AWPluginFormatterFloatPrecise : public AWPluginFormatter<AWPluginFormatterFloatPrecise> | ||||
| { | ||||
| public: | ||||
|     [[nodiscard]] QString format(const QVariant &_value, const QString &, | ||||
|                                  const AWPluginFormatSettings &) const override; | ||||
| }; | ||||
| @ -1,24 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   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); | ||||
| } | ||||
| @ -1,28 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   This file is part of awesome-widgets                                  * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is free software: you can redistribute it and/or      * | ||||
|  *   modify it under the terms of the GNU General Public License as        * | ||||
|  *   published by the Free Software Foundation, either version 3 of the    * | ||||
|  *   License, or (at your option) any later version.                       * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is distributed in the hope that it will be useful,    * | ||||
|  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        * | ||||
|  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         * | ||||
|  *   GNU General Public License for more details.                          * | ||||
|  *                                                                         * | ||||
|  *   You should have received a copy of the GNU General Public License     * | ||||
|  *   along with awesome-widgets. If not, see http://www.gnu.org/licenses/  * | ||||
|  ***************************************************************************/ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| #include "awpluginformatter.h" | ||||
|  | ||||
|  | ||||
| class AWPluginFormatterInteger : public AWPluginFormatter<AWPluginFormatterInteger> | ||||
| { | ||||
| public: | ||||
|     [[nodiscard]] QString format(const QVariant &_value, const QString &, | ||||
|                                  const AWPluginFormatSettings &) const override; | ||||
| }; | ||||
| @ -1,25 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   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); | ||||
| } | ||||
| @ -1,28 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   This file is part of awesome-widgets                                  * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is free software: you can redistribute it and/or      * | ||||
|  *   modify it under the terms of the GNU General Public License as        * | ||||
|  *   published by the Free Software Foundation, either version 3 of the    * | ||||
|  *   License, or (at your option) any later version.                       * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is distributed in the hope that it will be useful,    * | ||||
|  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        * | ||||
|  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         * | ||||
|  *   GNU General Public License for more details.                          * | ||||
|  *                                                                         * | ||||
|  *   You should have received a copy of the GNU General Public License     * | ||||
|  *   along with awesome-widgets. If not, see http://www.gnu.org/licenses/  * | ||||
|  ***************************************************************************/ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| #include "awpluginformatter.h" | ||||
|  | ||||
|  | ||||
| class AWPluginFormatterIntegerShort : public AWPluginFormatter<AWPluginFormatterIntegerShort> | ||||
| { | ||||
| public: | ||||
|     [[nodiscard]] QString format(const QVariant &_value, const QString &, | ||||
|                                  const AWPluginFormatSettings &) const override; | ||||
| }; | ||||
| @ -1,25 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   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); | ||||
| } | ||||
| @ -1,28 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   This file is part of awesome-widgets                                  * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is free software: you can redistribute it and/or      * | ||||
|  *   modify it under the terms of the GNU General Public License as        * | ||||
|  *   published by the Free Software Foundation, either version 3 of the    * | ||||
|  *   License, or (at your option) any later version.                       * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is distributed in the hope that it will be useful,    * | ||||
|  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        * | ||||
|  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         * | ||||
|  *   GNU General Public License for more details.                          * | ||||
|  *                                                                         * | ||||
|  *   You should have received a copy of the GNU General Public License     * | ||||
|  *   along with awesome-widgets. If not, see http://www.gnu.org/licenses/  * | ||||
|  ***************************************************************************/ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| #include "awpluginformatter.h" | ||||
|  | ||||
|  | ||||
| class AWPluginFormatterIntegerWide : public AWPluginFormatter<AWPluginFormatterIntegerWide> | ||||
| { | ||||
| public: | ||||
|     [[nodiscard]] QString format(const QVariant &_value, const QString &, | ||||
|                                  const AWPluginFormatSettings &) const override; | ||||
| }; | ||||
| @ -1,24 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   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(","); | ||||
| } | ||||
| @ -1,28 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   This file is part of awesome-widgets                                  * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is free software: you can redistribute it and/or      * | ||||
|  *   modify it under the terms of the GNU General Public License as        * | ||||
|  *   published by the Free Software Foundation, either version 3 of the    * | ||||
|  *   License, or (at your option) any later version.                       * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is distributed in the hope that it will be useful,    * | ||||
|  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        * | ||||
|  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         * | ||||
|  *   GNU General Public License for more details.                          * | ||||
|  *                                                                         * | ||||
|  *   You should have received a copy of the GNU General Public License     * | ||||
|  *   along with awesome-widgets. If not, see http://www.gnu.org/licenses/  * | ||||
|  ***************************************************************************/ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| #include "awpluginformatter.h" | ||||
|  | ||||
|  | ||||
| class AWPluginFormatterList : public AWPluginFormatter<AWPluginFormatterList> | ||||
| { | ||||
| public: | ||||
|     [[nodiscard]] QString format(const QVariant &_value, const QString &, | ||||
|                                  const AWPluginFormatSettings &) const override; | ||||
| }; | ||||
| @ -1,24 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   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); | ||||
| } | ||||
| @ -1,28 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   This file is part of awesome-widgets                                  * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is free software: you can redistribute it and/or      * | ||||
|  *   modify it under the terms of the GNU General Public License as        * | ||||
|  *   published by the Free Software Foundation, either version 3 of the    * | ||||
|  *   License, or (at your option) any later version.                       * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is distributed in the hope that it will be useful,    * | ||||
|  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        * | ||||
|  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         * | ||||
|  *   GNU General Public License for more details.                          * | ||||
|  *                                                                         * | ||||
|  *   You should have received a copy of the GNU General Public License     * | ||||
|  *   along with awesome-widgets. If not, see http://www.gnu.org/licenses/  * | ||||
|  ***************************************************************************/ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| #include "awpluginformatter.h" | ||||
|  | ||||
|  | ||||
| class AWPluginFormatterMemory : public AWPluginFormatter<AWPluginFormatterMemory> | ||||
| { | ||||
| public: | ||||
|     [[nodiscard]] QString format(const QVariant &_value, const QString &, | ||||
|                                  const AWPluginFormatSettings &) const override; | ||||
| }; | ||||
| @ -1,24 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   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); | ||||
| } | ||||
| @ -1,28 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   This file is part of awesome-widgets                                  * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is free software: you can redistribute it and/or      * | ||||
|  *   modify it under the terms of the GNU General Public License as        * | ||||
|  *   published by the Free Software Foundation, either version 3 of the    * | ||||
|  *   License, or (at your option) any later version.                       * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is distributed in the hope that it will be useful,    * | ||||
|  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        * | ||||
|  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         * | ||||
|  *   GNU General Public License for more details.                          * | ||||
|  *                                                                         * | ||||
|  *   You should have received a copy of the GNU General Public License     * | ||||
|  *   along with awesome-widgets. If not, see http://www.gnu.org/licenses/  * | ||||
|  ***************************************************************************/ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| #include "awpluginformatter.h" | ||||
|  | ||||
|  | ||||
| class AWPluginFormatterMemoryGB : public AWPluginFormatter<AWPluginFormatterMemoryGB> | ||||
| { | ||||
| public: | ||||
|     [[nodiscard]] QString format(const QVariant &_value, const QString &, | ||||
|                                  const AWPluginFormatSettings &) const override; | ||||
| }; | ||||
| @ -1,24 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   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); | ||||
| } | ||||
| @ -1,28 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   This file is part of awesome-widgets                                  * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is free software: you can redistribute it and/or      * | ||||
|  *   modify it under the terms of the GNU General Public License as        * | ||||
|  *   published by the Free Software Foundation, either version 3 of the    * | ||||
|  *   License, or (at your option) any later version.                       * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is distributed in the hope that it will be useful,    * | ||||
|  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        * | ||||
|  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         * | ||||
|  *   GNU General Public License for more details.                          * | ||||
|  *                                                                         * | ||||
|  *   You should have received a copy of the GNU General Public License     * | ||||
|  *   along with awesome-widgets. If not, see http://www.gnu.org/licenses/  * | ||||
|  ***************************************************************************/ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| #include "awpluginformatter.h" | ||||
|  | ||||
|  | ||||
| class AWPluginFormatterMemoryMB : public AWPluginFormatter<AWPluginFormatterMemoryMB> | ||||
| { | ||||
| public: | ||||
|     [[nodiscard]] QString format(const QVariant &_value, const QString &, | ||||
|                                  const AWPluginFormatSettings &) const override; | ||||
| }; | ||||
| @ -1,37 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   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); | ||||
| } | ||||
| @ -1,32 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   This file is part of awesome-widgets                                  * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is free software: you can redistribute it and/or      * | ||||
|  *   modify it under the terms of the GNU General Public License as        * | ||||
|  *   published by the Free Software Foundation, either version 3 of the    * | ||||
|  *   License, or (at your option) any later version.                       * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is distributed in the hope that it will be useful,    * | ||||
|  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        * | ||||
|  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         * | ||||
|  *   GNU General Public License for more details.                          * | ||||
|  *                                                                         * | ||||
|  *   You should have received a copy of the GNU General Public License     * | ||||
|  *   along with awesome-widgets. If not, see http://www.gnu.org/licenses/  * | ||||
|  ***************************************************************************/ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| #include "awpluginformatter.h" | ||||
|  | ||||
|  | ||||
| class AWPluginFormatterNet : public AWPluginFormatter<AWPluginFormatterNet> | ||||
| { | ||||
| public: | ||||
|     [[nodiscard]] QString format(const QVariant &_value, const QString &, | ||||
|                                  const AWPluginFormatSettings &) const override; | ||||
|  | ||||
| private: | ||||
|     [[nodiscard]] static QString formatKB(const double &_value); | ||||
|     [[nodiscard]] static QString formatMB(const double &_value); | ||||
| }; | ||||
| @ -1,40 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   This file is part of awesome-widgets                                  * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is free software: you can redistribute it and/or      * | ||||
|  *   modify it under the terms of the GNU General Public License as        * | ||||
|  *   published by the Free Software Foundation, either version 3 of the    * | ||||
|  *   License, or (at your option) any later version.                       * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is distributed in the hope that it will be useful,    * | ||||
|  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        * | ||||
|  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         * | ||||
|  *   GNU General Public License for more details.                          * | ||||
|  *                                                                         * | ||||
|  *   You should have received a copy of the GNU General Public License     * | ||||
|  *   along with awesome-widgets. If not, see http://www.gnu.org/licenses/  * | ||||
|  ***************************************************************************/ | ||||
|  | ||||
| #include "awpluginformatternetunits.h" | ||||
|  | ||||
| #include <KI18n/KLocalizedString> | ||||
|  | ||||
|  | ||||
| QString AWPluginFormatterNetUnits::format(const QVariant &_value, const QString &, | ||||
|                                           const AWPluginFormatSettings &_settings) const | ||||
| { | ||||
|     auto value = _value.toDouble(); | ||||
|     return (value > MBinBytes) ? formatMB(_settings) : formatKB(_settings); | ||||
| } | ||||
|  | ||||
|  | ||||
| QString AWPluginFormatterNetUnits::formatKB(const AWPluginFormatSettings &_settings) | ||||
| { | ||||
|     return _settings.translate ? i18n("KB/s") : "KB/s"; | ||||
| } | ||||
|  | ||||
|  | ||||
| QString AWPluginFormatterNetUnits::formatMB(const AWPluginFormatSettings &_settings) | ||||
| { | ||||
|     return _settings.translate ? i18n("MB/s") : "MB/s"; | ||||
| } | ||||
| @ -1,32 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   This file is part of awesome-widgets                                  * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is free software: you can redistribute it and/or      * | ||||
|  *   modify it under the terms of the GNU General Public License as        * | ||||
|  *   published by the Free Software Foundation, either version 3 of the    * | ||||
|  *   License, or (at your option) any later version.                       * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is distributed in the hope that it will be useful,    * | ||||
|  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        * | ||||
|  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         * | ||||
|  *   GNU General Public License for more details.                          * | ||||
|  *                                                                         * | ||||
|  *   You should have received a copy of the GNU General Public License     * | ||||
|  *   along with awesome-widgets. If not, see http://www.gnu.org/licenses/  * | ||||
|  ***************************************************************************/ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| #include "awpluginformatter.h" | ||||
|  | ||||
|  | ||||
| class AWPluginFormatterNetUnits : public AWPluginFormatter<AWPluginFormatterNetUnits> | ||||
| { | ||||
| public: | ||||
|     [[nodiscard]] QString format(const QVariant &_value, const QString &, | ||||
|                                  const AWPluginFormatSettings &_settings) const override; | ||||
|  | ||||
| private: | ||||
|     [[nodiscard]] static QString formatKB(const AWPluginFormatSettings &_settings); | ||||
|     [[nodiscard]] static QString formatMB(const AWPluginFormatSettings &_settings); | ||||
| }; | ||||
| @ -1,24 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   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(); | ||||
| } | ||||
| @ -1,28 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   This file is part of awesome-widgets                                  * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is free software: you can redistribute it and/or      * | ||||
|  *   modify it under the terms of the GNU General Public License as        * | ||||
|  *   published by the Free Software Foundation, either version 3 of the    * | ||||
|  *   License, or (at your option) any later version.                       * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is distributed in the hope that it will be useful,    * | ||||
|  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        * | ||||
|  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         * | ||||
|  *   GNU General Public License for more details.                          * | ||||
|  *                                                                         * | ||||
|  *   You should have received a copy of the GNU General Public License     * | ||||
|  *   along with awesome-widgets. If not, see http://www.gnu.org/licenses/  * | ||||
|  ***************************************************************************/ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| #include "awpluginformatter.h" | ||||
|  | ||||
|  | ||||
| class AWPluginFormatterNoFormat : public AWPluginFormatter<AWPluginFormatterNoFormat> | ||||
| { | ||||
| public: | ||||
|     [[nodiscard]] QString format(const QVariant &_value, const QString &, | ||||
|                                  const AWPluginFormatSettings &) const override; | ||||
| }; | ||||
| @ -1,48 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   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; | ||||
| } | ||||
| @ -1,31 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   This file is part of awesome-widgets                                  * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is free software: you can redistribute it and/or      * | ||||
|  *   modify it under the terms of the GNU General Public License as        * | ||||
|  *   published by the Free Software Foundation, either version 3 of the    * | ||||
|  *   License, or (at your option) any later version.                       * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is distributed in the hope that it will be useful,    * | ||||
|  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        * | ||||
|  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         * | ||||
|  *   GNU General Public License for more details.                          * | ||||
|  *                                                                         * | ||||
|  *   You should have received a copy of the GNU General Public License     * | ||||
|  *   along with awesome-widgets. If not, see http://www.gnu.org/licenses/  * | ||||
|  ***************************************************************************/ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| #include "awpluginformatter.h" | ||||
|  | ||||
|  | ||||
| class AWPluginFormatterTemperature : public AWPluginFormatter<AWPluginFormatterTemperature> | ||||
| { | ||||
| public: | ||||
|     [[nodiscard]] QString format(const QVariant &_value, const QString &, | ||||
|                                  const AWPluginFormatSettings &_settings) const override; | ||||
|  | ||||
| private: | ||||
|     [[nodiscard]] static double convert(const double &_value, const QString &_units); | ||||
| }; | ||||
| @ -1,26 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   This file is part of awesome-widgets                                  * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is free software: you can redistribute it and/or      * | ||||
|  *   modify it under the terms of the GNU General Public License as        * | ||||
|  *   published by the Free Software Foundation, either version 3 of the    * | ||||
|  *   License, or (at your option) any later version.                       * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is distributed in the hope that it will be useful,    * | ||||
|  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        * | ||||
|  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         * | ||||
|  *   GNU General Public License for more details.                          * | ||||
|  *                                                                         * | ||||
|  *   You should have received a copy of the GNU General Public License     * | ||||
|  *   along with awesome-widgets. If not, see http://www.gnu.org/licenses/  * | ||||
|  ***************************************************************************/ | ||||
|  | ||||
| #include "awpluginformattertime.h" | ||||
|  | ||||
| #include <QDateTime> | ||||
|  | ||||
|  | ||||
| QString AWPluginFormatterTime::format(const QVariant &_value, const QString &, const AWPluginFormatSettings &) const | ||||
| { | ||||
|     return QDateTime::fromSecsSinceEpoch(_value.toLongLong()).toString(); | ||||
| } | ||||
| @ -1,28 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   This file is part of awesome-widgets                                  * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is free software: you can redistribute it and/or      * | ||||
|  *   modify it under the terms of the GNU General Public License as        * | ||||
|  *   published by the Free Software Foundation, either version 3 of the    * | ||||
|  *   License, or (at your option) any later version.                       * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is distributed in the hope that it will be useful,    * | ||||
|  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        * | ||||
|  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         * | ||||
|  *   GNU General Public License for more details.                          * | ||||
|  *                                                                         * | ||||
|  *   You should have received a copy of the GNU General Public License     * | ||||
|  *   along with awesome-widgets. If not, see http://www.gnu.org/licenses/  * | ||||
|  ***************************************************************************/ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| #include "awpluginformatter.h" | ||||
|  | ||||
|  | ||||
| class AWPluginFormatterTime : public AWPluginFormatter<AWPluginFormatterTime> | ||||
| { | ||||
| public: | ||||
|     [[nodiscard]] QString format(const QVariant &_value, const QString &, | ||||
|                                  const AWPluginFormatSettings &) const override; | ||||
| }; | ||||
| @ -1,46 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   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; | ||||
| } | ||||
| @ -1,35 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   This file is part of awesome-widgets                                  * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is free software: you can redistribute it and/or      * | ||||
|  *   modify it under the terms of the GNU General Public License as        * | ||||
|  *   published by the Free Software Foundation, either version 3 of the    * | ||||
|  *   License, or (at your option) any later version.                       * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is distributed in the hope that it will be useful,    * | ||||
|  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        * | ||||
|  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         * | ||||
|  *   GNU General Public License for more details.                          * | ||||
|  *                                                                         * | ||||
|  *   You should have received a copy of the GNU General Public License     * | ||||
|  *   along with awesome-widgets. If not, see http://www.gnu.org/licenses/  * | ||||
|  ***************************************************************************/ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| #include <QDateTime> | ||||
|  | ||||
| #include "awpluginformatter.h" | ||||
|  | ||||
|  | ||||
| class AWPluginFormatterTimeCustom : public AWPluginFormatter<AWPluginFormatterTimeCustom> | ||||
| { | ||||
| public: | ||||
|     [[nodiscard]] QString format(const QVariant &_value, const QString &, | ||||
|                                  const AWPluginFormatSettings &_settings) const override; | ||||
|     void load() override; | ||||
|  | ||||
| private: | ||||
|     [[nodiscard]] QString format(const QDateTime &_value, QString _formatString, const QLocale &_locale) const; | ||||
|     QStringList m_timeKeys; | ||||
| }; | ||||
| @ -1,26 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   This file is part of awesome-widgets                                  * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is free software: you can redistribute it and/or      * | ||||
|  *   modify it under the terms of the GNU General Public License as        * | ||||
|  *   published by the Free Software Foundation, either version 3 of the    * | ||||
|  *   License, or (at your option) any later version.                       * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is distributed in the hope that it will be useful,    * | ||||
|  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        * | ||||
|  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         * | ||||
|  *   GNU General Public License for more details.                          * | ||||
|  *                                                                         * | ||||
|  *   You should have received a copy of the GNU General Public License     * | ||||
|  *   along with awesome-widgets. If not, see http://www.gnu.org/licenses/  * | ||||
|  ***************************************************************************/ | ||||
|  | ||||
| #include "awpluginformattertimeiso.h" | ||||
|  | ||||
| #include <QDateTime> | ||||
|  | ||||
|  | ||||
| QString AWPluginFormatterTimeISO::format(const QVariant &_value, const QString &, const AWPluginFormatSettings &) const | ||||
| { | ||||
|     return QDateTime::fromSecsSinceEpoch(_value.toLongLong()).toString(Qt::ISODate); | ||||
| } | ||||
| @ -1,28 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   This file is part of awesome-widgets                                  * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is free software: you can redistribute it and/or      * | ||||
|  *   modify it under the terms of the GNU General Public License as        * | ||||
|  *   published by the Free Software Foundation, either version 3 of the    * | ||||
|  *   License, or (at your option) any later version.                       * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is distributed in the hope that it will be useful,    * | ||||
|  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        * | ||||
|  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         * | ||||
|  *   GNU General Public License for more details.                          * | ||||
|  *                                                                         * | ||||
|  *   You should have received a copy of the GNU General Public License     * | ||||
|  *   along with awesome-widgets. If not, see http://www.gnu.org/licenses/  * | ||||
|  ***************************************************************************/ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| #include "awpluginformatter.h" | ||||
|  | ||||
|  | ||||
| class AWPluginFormatterTimeISO : public AWPluginFormatter<AWPluginFormatterTimeISO> | ||||
| { | ||||
| public: | ||||
|     [[nodiscard]] QString format(const QVariant &_value, const QString &, | ||||
|                                  const AWPluginFormatSettings &) const override; | ||||
| }; | ||||
| @ -1,27 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   This file is part of awesome-widgets                                  * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is free software: you can redistribute it and/or      * | ||||
|  *   modify it under the terms of the GNU General Public License as        * | ||||
|  *   published by the Free Software Foundation, either version 3 of the    * | ||||
|  *   License, or (at your option) any later version.                       * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is distributed in the hope that it will be useful,    * | ||||
|  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        * | ||||
|  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         * | ||||
|  *   GNU General Public License for more details.                          * | ||||
|  *                                                                         * | ||||
|  *   You should have received a copy of the GNU General Public License     * | ||||
|  *   along with awesome-widgets. If not, see http://www.gnu.org/licenses/  * | ||||
|  ***************************************************************************/ | ||||
|  | ||||
| #include "awpluginformattertimelong.h" | ||||
|  | ||||
| #include <QDateTime> | ||||
|  | ||||
|  | ||||
| QString AWPluginFormatterTimeLong::format(const QVariant &_value, const QString &, | ||||
|                                           const AWPluginFormatSettings &_settings) const | ||||
| { | ||||
|     return locale(_settings).toString(QDateTime::fromSecsSinceEpoch(_value.toLongLong()), QLocale::LongFormat); | ||||
| } | ||||
| @ -1,28 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   This file is part of awesome-widgets                                  * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is free software: you can redistribute it and/or      * | ||||
|  *   modify it under the terms of the GNU General Public License as        * | ||||
|  *   published by the Free Software Foundation, either version 3 of the    * | ||||
|  *   License, or (at your option) any later version.                       * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is distributed in the hope that it will be useful,    * | ||||
|  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        * | ||||
|  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         * | ||||
|  *   GNU General Public License for more details.                          * | ||||
|  *                                                                         * | ||||
|  *   You should have received a copy of the GNU General Public License     * | ||||
|  *   along with awesome-widgets. If not, see http://www.gnu.org/licenses/  * | ||||
|  ***************************************************************************/ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| #include "awpluginformatter.h" | ||||
|  | ||||
|  | ||||
| class AWPluginFormatterTimeLong : public AWPluginFormatter<AWPluginFormatterTimeLong> | ||||
| { | ||||
| public: | ||||
|     [[nodiscard]] QString format(const QVariant &_value, const QString &, | ||||
|                                  const AWPluginFormatSettings &_settings) const override; | ||||
| }; | ||||
| @ -1,27 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   This file is part of awesome-widgets                                  * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is free software: you can redistribute it and/or      * | ||||
|  *   modify it under the terms of the GNU General Public License as        * | ||||
|  *   published by the Free Software Foundation, either version 3 of the    * | ||||
|  *   License, or (at your option) any later version.                       * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is distributed in the hope that it will be useful,    * | ||||
|  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        * | ||||
|  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         * | ||||
|  *   GNU General Public License for more details.                          * | ||||
|  *                                                                         * | ||||
|  *   You should have received a copy of the GNU General Public License     * | ||||
|  *   along with awesome-widgets. If not, see http://www.gnu.org/licenses/  * | ||||
|  ***************************************************************************/ | ||||
|  | ||||
| #include "awpluginformattertimeshort.h" | ||||
|  | ||||
| #include <QDateTime> | ||||
|  | ||||
|  | ||||
| QString AWPluginFormatterTimeShort::format(const QVariant &_value, const QString &, | ||||
|                                            const AWPluginFormatSettings &_settings) const | ||||
| { | ||||
|     return locale(_settings).toString(QDateTime::fromSecsSinceEpoch(_value.toLongLong()), QLocale::ShortFormat); | ||||
| } | ||||
| @ -1,28 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   This file is part of awesome-widgets                                  * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is free software: you can redistribute it and/or      * | ||||
|  *   modify it under the terms of the GNU General Public License as        * | ||||
|  *   published by the Free Software Foundation, either version 3 of the    * | ||||
|  *   License, or (at your option) any later version.                       * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is distributed in the hope that it will be useful,    * | ||||
|  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        * | ||||
|  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         * | ||||
|  *   GNU General Public License for more details.                          * | ||||
|  *                                                                         * | ||||
|  *   You should have received a copy of the GNU General Public License     * | ||||
|  *   along with awesome-widgets. If not, see http://www.gnu.org/licenses/  * | ||||
|  ***************************************************************************/ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| #include "awpluginformatter.h" | ||||
|  | ||||
|  | ||||
| class AWPluginFormatterTimeShort : public AWPluginFormatter<AWPluginFormatterTimeShort> | ||||
| { | ||||
| public: | ||||
|     [[nodiscard]] QString format(const QVariant &_value, const QString &, | ||||
|                                  const AWPluginFormatSettings &_settings) const override; | ||||
| }; | ||||
| @ -1,44 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   This file is part of awesome-widgets                                  * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is free software: you can redistribute it and/or      * | ||||
|  *   modify it under the terms of the GNU General Public License as        * | ||||
|  *   published by the Free Software Foundation, either version 3 of the    * | ||||
|  *   License, or (at your option) any later version.                       * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is distributed in the hope that it will be useful,    * | ||||
|  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        * | ||||
|  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         * | ||||
|  *   GNU General Public License for more details.                          * | ||||
|  *                                                                         * | ||||
|  *   You should have received a copy of the GNU General Public License     * | ||||
|  *   along with awesome-widgets. If not, see http://www.gnu.org/licenses/  * | ||||
|  ***************************************************************************/ | ||||
|  | ||||
| #include "awpluginformatteruptime.h" | ||||
|  | ||||
|  | ||||
| QString AWPluginFormatterUptime::format(const QVariant &_value, const QString &, | ||||
|                                         const AWPluginFormatSettings &_settings) const | ||||
| { | ||||
|     auto value = static_cast<long>(_value.toDouble()); | ||||
|     return format(value, _settings.customUptime); | ||||
| } | ||||
|  | ||||
|  | ||||
| QString AWPluginFormatterUptime::format(const long &_value, QString _formatString) | ||||
| { | ||||
|     auto seconds = _value - _value % 60; | ||||
|     auto minutes = seconds / 60 % 60; | ||||
|     auto hours = ((seconds / 60) - minutes) / 60 % 24; | ||||
|     auto days = (((seconds / 60) - minutes) / 60 - hours) / 24; | ||||
|  | ||||
|     _formatString.replace("$dd", QString("%1").arg(days, 3, 10, QChar('0'))); | ||||
|     _formatString.replace("$d", QString("%1").arg(days)); | ||||
|     _formatString.replace("$hh", QString("%1").arg(hours, 2, 10, QChar('0'))); | ||||
|     _formatString.replace("$h", QString("%1").arg(hours)); | ||||
|     _formatString.replace("$mm", QString("%1").arg(minutes, 2, 10, QChar('0'))); | ||||
|     _formatString.replace("$m", QString("%1").arg(minutes)); | ||||
|  | ||||
|     return _formatString; | ||||
| } | ||||
| @ -1,31 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   This file is part of awesome-widgets                                  * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is free software: you can redistribute it and/or      * | ||||
|  *   modify it under the terms of the GNU General Public License as        * | ||||
|  *   published by the Free Software Foundation, either version 3 of the    * | ||||
|  *   License, or (at your option) any later version.                       * | ||||
|  *                                                                         * | ||||
|  *   awesome-widgets is distributed in the hope that it will be useful,    * | ||||
|  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        * | ||||
|  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         * | ||||
|  *   GNU General Public License for more details.                          * | ||||
|  *                                                                         * | ||||
|  *   You should have received a copy of the GNU General Public License     * | ||||
|  *   along with awesome-widgets. If not, see http://www.gnu.org/licenses/  * | ||||
|  ***************************************************************************/ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| #include "awpluginformatter.h" | ||||
|  | ||||
|  | ||||
| class AWPluginFormatterUptime : public AWPluginFormatter<AWPluginFormatterUptime> | ||||
| { | ||||
| public: | ||||
|     [[nodiscard]] QString format(const QVariant &_value, const QString &, | ||||
|                                  const AWPluginFormatSettings &_settings) const override; | ||||
|  | ||||
| private: | ||||
|     [[nodiscard]] static QString format(const long &_value, QString _formatString); | ||||
| }; | ||||
| @ -1,39 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   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" | ||||
| @ -1,63 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   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 <ksysguard/formatter/Unit.h> | ||||
|  | ||||
| #include <QHash> | ||||
|  | ||||
| #include <memory> | ||||
|  | ||||
| #include "awpluginmatchersettings.h" | ||||
|  | ||||
|  | ||||
| class AWPluginFormaterInterface; | ||||
|  | ||||
| class AWPluginMatcherInterface | ||||
| { | ||||
| public: | ||||
|     virtual ~AWPluginMatcherInterface() = default; | ||||
|     [[nodiscard]] virtual QHash<QString, AWPluginFormaterInterface *> | ||||
|     keys(const QString &_source, KSysGuard::Unit _units, const AWPluginMatcherSettings &_settings) const = 0; | ||||
|     [[nodiscard]] virtual bool matches(const QString &_source) const = 0; | ||||
| }; | ||||
|  | ||||
|  | ||||
| template <typename Matcher> class AWPluginMatcher : public AWPluginMatcherInterface | ||||
| { | ||||
| public: | ||||
|     AWPluginMatcher(AWPluginMatcher &) = delete; | ||||
|     void operator=(const AWPluginMatcher &) = delete; | ||||
|  | ||||
|     [[nodiscard]] static Matcher *instance() | ||||
|     { | ||||
|         static auto instance = std::make_unique<Matcher>(); | ||||
|         return instance.get(); | ||||
|     }; | ||||
|  | ||||
|     [[nodiscard]] static QString device(const QString &_source) { return _source.split('/')[1]; }; | ||||
|  | ||||
|     [[nodiscard]] static qsizetype index(const QString &_source, const QStringList &_devices) | ||||
|     { | ||||
|         auto device = AWPluginMatcher::device(_source); | ||||
|         return _devices.indexOf(device); | ||||
|     } | ||||
|  | ||||
| protected: | ||||
|     AWPluginMatcher() = default; | ||||
| }; | ||||
| @ -1,33 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   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 "awpluginmatcherac.h" | ||||
|  | ||||
| #include "formatters/formatters.h" | ||||
|  | ||||
|  | ||||
| QHash<QString, AWPluginFormaterInterface *> AWPluginMatcherAC::keys(const QString &, const KSysGuard::Unit, | ||||
|                                                                     const AWPluginMatcherSettings &) const | ||||
| { | ||||
|     return {{"ac", AWPluginFormatterAC::instance()}}; | ||||
| } | ||||
|  | ||||
|  | ||||
| bool AWPluginMatcherAC::matches(const QString &_source) const | ||||
| { | ||||
|     return _source == "extsysmon/battery/ac"; | ||||
| } | ||||
| @ -1,29 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   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 "awpluginmatcher.h" | ||||
|  | ||||
|  | ||||
| class AWPluginMatcherAC : public AWPluginMatcher<AWPluginMatcherAC> | ||||
| { | ||||
| public: | ||||
|     [[nodiscard]] QHash<QString, AWPluginFormaterInterface *> keys(const QString &, KSysGuard::Unit, | ||||
|                                                                    const AWPluginMatcherSettings &) const override; | ||||
|     [[nodiscard]] bool matches(const QString &_source) const override; | ||||
| }; | ||||
| @ -1,38 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   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 "awpluginmatcherbattery.h" | ||||
|  | ||||
| #include "formatters/formatters.h" | ||||
|  | ||||
|  | ||||
| QHash<QString, AWPluginFormaterInterface *> AWPluginMatcherBattery::keys(const QString &_source, const KSysGuard::Unit, | ||||
|                                                                          const AWPluginMatcherSettings &) const | ||||
| { | ||||
|     auto key = _source; | ||||
|     key.remove("extsysmon/battery/"); | ||||
|  | ||||
|     if (key.contains("rate")) | ||||
|         return {{key, AWPluginFormatterFloat::instance()}}; | ||||
|     return {{key, AWPluginFormatterIntegerShort::instance()}}; | ||||
| } | ||||
|  | ||||
|  | ||||
| bool AWPluginMatcherBattery::matches(const QString &_source) const | ||||
| { | ||||
|     return _source.startsWith("extsysmon/battery/"); | ||||
| } | ||||
| @ -1,29 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   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 "awpluginmatcher.h" | ||||
|  | ||||
|  | ||||
| class AWPluginMatcherBattery : public AWPluginMatcher<AWPluginMatcherBattery> | ||||
| { | ||||
| public: | ||||
|     [[nodiscard]] QHash<QString, AWPluginFormaterInterface *> keys(const QString &_source, KSysGuard::Unit, | ||||
|                                                                    const AWPluginMatcherSettings &) const override; | ||||
|     [[nodiscard]] bool matches(const QString &_source) const override; | ||||
| }; | ||||
| @ -1,33 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   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 "awpluginmatcherbrightness.h" | ||||
|  | ||||
| #include "formatters/formatters.h" | ||||
|  | ||||
|  | ||||
| QHash<QString, AWPluginFormaterInterface *> AWPluginMatcherBrightness::keys(const QString &, const KSysGuard::Unit, | ||||
|                                                                             const AWPluginMatcherSettings &) const | ||||
| { | ||||
|     return {{"brightness", AWPluginFormatterIntegerShort::instance()}}; | ||||
| } | ||||
|  | ||||
|  | ||||
| bool AWPluginMatcherBrightness::matches(const QString &_source) const | ||||
| { | ||||
|     return _source == "extsysmon/system/brightness"; | ||||
| } | ||||
| @ -1,29 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   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 "awpluginmatcher.h" | ||||
|  | ||||
|  | ||||
| class AWPluginMatcherBrightness : public AWPluginMatcher<AWPluginMatcherBrightness> | ||||
| { | ||||
| public: | ||||
|     [[nodiscard]] QHash<QString, AWPluginFormaterInterface *> keys(const QString &, KSysGuard::Unit, | ||||
|                                                                    const AWPluginMatcherSettings &) const override; | ||||
|     [[nodiscard]] bool matches(const QString &_source) const override; | ||||
| }; | ||||
| @ -1,33 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   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 "awpluginmatchercpu.h" | ||||
|  | ||||
| #include "formatters/formatters.h" | ||||
|  | ||||
|  | ||||
| QHash<QString, AWPluginFormaterInterface *> AWPluginMatcherCPU::keys(const QString &, const KSysGuard::Unit, | ||||
|                                                                      const AWPluginMatcherSettings &) const | ||||
| { | ||||
|     return {{"cpu", AWPluginFormatterFloat::instance()}}; | ||||
| } | ||||
|  | ||||
|  | ||||
| bool AWPluginMatcherCPU::matches(const QString &_source) const | ||||
| { | ||||
|     return _source == "cpu/all/usage"; | ||||
| } | ||||
| @ -1,29 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   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 "awpluginmatcher.h" | ||||
|  | ||||
|  | ||||
| class AWPluginMatcherCPU : public AWPluginMatcher<AWPluginMatcherCPU> | ||||
| { | ||||
| public: | ||||
|     [[nodiscard]] QHash<QString, AWPluginFormaterInterface *> keys(const QString &, KSysGuard::Unit, | ||||
|                                                                    const AWPluginMatcherSettings &) const override; | ||||
|     [[nodiscard]] bool matches(const QString &_source) const override; | ||||
| }; | ||||
| @ -1,38 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   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 "awpluginmatchercpucore.h" | ||||
|  | ||||
| #include <QRegularExpression> | ||||
|  | ||||
| #include "formatters/formatters.h" | ||||
|  | ||||
|  | ||||
| QHash<QString, AWPluginFormaterInterface *> AWPluginMatcherCPUCore::keys(const QString &_source, const KSysGuard::Unit, | ||||
|                                                                          const AWPluginMatcherSettings &) const | ||||
| { | ||||
|     auto key = _source; | ||||
|     key.remove("cpu/").remove("/usage"); | ||||
|     return {{key, AWPluginFormatterFloat::instance()}}; | ||||
| } | ||||
|  | ||||
|  | ||||
| bool AWPluginMatcherCPUCore::matches(const QString &_source) const | ||||
| { | ||||
|     static auto regexp = QRegularExpression("^cpu/cpu.*/usage$"); | ||||
|     return _source.contains(regexp); | ||||
| } | ||||
| @ -1,29 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   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 "awpluginmatcher.h" | ||||
|  | ||||
|  | ||||
| class AWPluginMatcherCPUCore : public AWPluginMatcher<AWPluginMatcherCPUCore> | ||||
| { | ||||
| public: | ||||
|     [[nodiscard]] QHash<QString, AWPluginFormaterInterface *> keys(const QString &_source, KSysGuard::Unit, | ||||
|                                                                    const AWPluginMatcherSettings &) const override; | ||||
|     [[nodiscard]] bool matches(const QString &_source) const override; | ||||
| }; | ||||
| @ -1,33 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   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 "awpluginmatchercpufrequency.h" | ||||
|  | ||||
| #include "formatters/formatters.h" | ||||
|  | ||||
|  | ||||
| QHash<QString, AWPluginFormaterInterface *> AWPluginMatcherCPUFrequency::keys(const QString &, const KSysGuard::Unit, | ||||
|                                                                               const AWPluginMatcherSettings &) const | ||||
| { | ||||
|     return {{"cpucl", AWPluginFormatterInteger::instance()}}; | ||||
| } | ||||
|  | ||||
|  | ||||
| bool AWPluginMatcherCPUFrequency::matches(const QString &_source) const | ||||
| { | ||||
|     return _source == "cpu/all/averageFrequency"; | ||||
| } | ||||
| @ -1,29 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   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 "awpluginmatcher.h" | ||||
|  | ||||
|  | ||||
| class AWPluginMatcherCPUFrequency : public AWPluginMatcher<AWPluginMatcherCPUFrequency> | ||||
| { | ||||
| public: | ||||
|     [[nodiscard]] QHash<QString, AWPluginFormaterInterface *> keys(const QString &, KSysGuard::Unit, | ||||
|                                                                    const AWPluginMatcherSettings &) const override; | ||||
|     [[nodiscard]] bool matches(const QString &_source) const override; | ||||
| }; | ||||
| @ -1,39 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   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 "awpluginmatchercpufrequencycore.h" | ||||
|  | ||||
| #include <QRegularExpression> | ||||
|  | ||||
| #include "formatters/formatters.h" | ||||
|  | ||||
|  | ||||
| QHash<QString, AWPluginFormaterInterface *> AWPluginMatcherCPUFrequencyCore::keys(const QString &_source, | ||||
|                                                                                   const KSysGuard::Unit, | ||||
|                                                                                   const AWPluginMatcherSettings &) const | ||||
| { | ||||
|     auto index = _source; | ||||
|     index.remove("cpu/cpu").remove("/frequency"); | ||||
|     return {{QString("cpucl%1").arg(index), AWPluginFormatterInteger::instance()}}; | ||||
| } | ||||
|  | ||||
|  | ||||
| bool AWPluginMatcherCPUFrequencyCore::matches(const QString &_source) const | ||||
| { | ||||
|     static auto regexp = QRegularExpression("^cpu/cpu.*/frequency$"); | ||||
|     return _source.contains(regexp); | ||||
| } | ||||
| @ -1,29 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   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 "awpluginmatcher.h" | ||||
|  | ||||
|  | ||||
| class AWPluginMatcherCPUFrequencyCore : public AWPluginMatcher<AWPluginMatcherCPUFrequencyCore> | ||||
| { | ||||
| public: | ||||
|     [[nodiscard]] QHash<QString, AWPluginFormaterInterface *> keys(const QString &_source, KSysGuard::Unit, | ||||
|                                                                    const AWPluginMatcherSettings &) const override; | ||||
|     [[nodiscard]] bool matches(const QString &_source) const override; | ||||
| }; | ||||
| @ -1,35 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   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 "awpluginmatchercustom.h" | ||||
|  | ||||
| #include "formatters/formatters.h" | ||||
|  | ||||
|  | ||||
| QHash<QString, AWPluginFormaterInterface *> AWPluginMatcherCustom::keys(const QString &_source, const KSysGuard::Unit, | ||||
|                                                                         const AWPluginMatcherSettings &) const | ||||
| { | ||||
|     auto key = _source; | ||||
|     key.remove("extsysmon/custom/"); | ||||
|     return {{key, AWPluginFormatterNoFormat::instance()}}; | ||||
| } | ||||
|  | ||||
|  | ||||
| bool AWPluginMatcherCustom::matches(const QString &_source) const | ||||
| { | ||||
|     return _source.startsWith("extsysmon/custom/"); | ||||
| } | ||||
| @ -1,29 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   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 "awpluginmatcher.h" | ||||
|  | ||||
|  | ||||
| class AWPluginMatcherCustom : public AWPluginMatcher<AWPluginMatcherCustom> | ||||
| { | ||||
| public: | ||||
|     [[nodiscard]] QHash<QString, AWPluginFormaterInterface *> keys(const QString &_source, KSysGuard::Unit, | ||||
|                                                                    const AWPluginMatcherSettings &) const override; | ||||
|     [[nodiscard]] bool matches(const QString &_source) const override; | ||||
| }; | ||||
| @ -1,33 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   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 "awpluginmatcherdesktop.h" | ||||
|  | ||||
| #include "formatters/formatters.h" | ||||
|  | ||||
|  | ||||
| QHash<QString, AWPluginFormaterInterface *> AWPluginMatcherDesktop::keys(const QString &, const KSysGuard::Unit, | ||||
|                                                                          const AWPluginMatcherSettings &) const | ||||
| { | ||||
|     return {{"desktop", AWPluginFormatterNoFormat::instance()}}; | ||||
| } | ||||
|  | ||||
|  | ||||
| bool AWPluginMatcherDesktop::matches(const QString &_source) const | ||||
| { | ||||
|     return _source == "extsysmon/desktop/name"; | ||||
| } | ||||
| @ -1,29 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   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 "awpluginmatcher.h" | ||||
|  | ||||
|  | ||||
| class AWPluginMatcherDesktop : public AWPluginMatcher<AWPluginMatcherDesktop> | ||||
| { | ||||
| public: | ||||
|     [[nodiscard]] QHash<QString, AWPluginFormaterInterface *> keys(const QString &, KSysGuard::Unit, | ||||
|                                                                    const AWPluginMatcherSettings &) const override; | ||||
|     [[nodiscard]] bool matches(const QString &_source) const override; | ||||
| }; | ||||
| @ -1,33 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   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 "awpluginmatcherdesktopcount.h" | ||||
|  | ||||
| #include "formatters/formatters.h" | ||||
|  | ||||
|  | ||||
| QHash<QString, AWPluginFormaterInterface *> AWPluginMatcherDesktopCount::keys(const QString &, const KSysGuard::Unit, | ||||
|                                                                               const AWPluginMatcherSettings &) const | ||||
| { | ||||
|     return {{"tdesktops", AWPluginFormatterNoFormat::instance()}}; | ||||
| } | ||||
|  | ||||
|  | ||||
| bool AWPluginMatcherDesktopCount::matches(const QString &_source) const | ||||
| { | ||||
|     return _source == "extsysmon/desktop/count"; | ||||
| } | ||||
| @ -1,29 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   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 "awpluginmatcher.h" | ||||
|  | ||||
|  | ||||
| class AWPluginMatcherDesktopCount : public AWPluginMatcher<AWPluginMatcherDesktopCount> | ||||
| { | ||||
| public: | ||||
|     [[nodiscard]] QHash<QString, AWPluginFormaterInterface *> keys(const QString &, KSysGuard::Unit, | ||||
|                                                                    const AWPluginMatcherSettings &) const override; | ||||
|     [[nodiscard]] bool matches(const QString &_source) const override; | ||||
| }; | ||||
| @ -1,33 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   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 "awpluginmatcherdesktopnumber.h" | ||||
|  | ||||
| #include "formatters/formatters.h" | ||||
|  | ||||
|  | ||||
| QHash<QString, AWPluginFormaterInterface *> AWPluginMatcherDesktopNumber::keys(const QString &, const KSysGuard::Unit, | ||||
|                                                                                const AWPluginMatcherSettings &) const | ||||
| { | ||||
|     return {{"ndesktop", AWPluginFormatterNoFormat::instance()}}; | ||||
| } | ||||
|  | ||||
|  | ||||
| bool AWPluginMatcherDesktopNumber::matches(const QString &_source) const | ||||
| { | ||||
|     return _source == "extsysmon/desktop/number"; | ||||
| } | ||||
| @ -1,29 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   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 "awpluginmatcher.h" | ||||
|  | ||||
|  | ||||
| class AWPluginMatcherDesktopNumber : public AWPluginMatcher<AWPluginMatcherDesktopNumber> | ||||
| { | ||||
| public: | ||||
|     [[nodiscard]] QHash<QString, AWPluginFormaterInterface *> keys(const QString &, KSysGuard::Unit, | ||||
|                                                                    const AWPluginMatcherSettings &) const override; | ||||
|     [[nodiscard]] bool matches(const QString &_source) const override; | ||||
| }; | ||||
| @ -1,33 +0,0 @@ | ||||
| /*************************************************************************** | ||||
|  *   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 "awpluginmatchergpu.h" | ||||
|  | ||||
| #include "formatters/formatters.h" | ||||
|  | ||||
|  | ||||
| QHash<QString, AWPluginFormaterInterface *> AWPluginMatcherGPU::keys(const QString &, const KSysGuard::Unit, | ||||
|                                                                      const AWPluginMatcherSettings &) const | ||||
| { | ||||
|     return {{"gpu", AWPluginFormatterFloat::instance()}}; | ||||
| } | ||||
|  | ||||
|  | ||||
| bool AWPluginMatcherGPU::matches(const QString &_source) const | ||||
| { | ||||
|     return _source == "gpu/all/usage"; | ||||
| } | ||||
Some files were not shown because too many files have changed in this diff Show More
		Reference in New Issue
	
	Block a user