From 981fb30935ff593e3416542b7511cd6ae91d3f33 Mon Sep 17 00:00:00 2001 From: Evgenii Alekseev Date: Mon, 22 Apr 2024 17:36:48 +0300 Subject: [PATCH] split formatter into separated singleton classes --- sources/awesome-widget/plugin/CMakeLists.txt | 2 +- .../formatters/awpluginformatsettings.h | 33 +++++++++++ .../plugin/formatters/awpluginformatter.h | 57 +++++++++++++++++++ .../plugin/formatters/awpluginformatterac.cpp | 24 ++++++++ .../plugin/formatters/awpluginformatterac.h | 27 +++++++++ .../formatters/awpluginformatterdouble.cpp | 25 ++++++++ .../formatters/awpluginformatterdouble.h | 27 +++++++++ .../formatters/awpluginformatterfloat.cpp | 24 ++++++++ .../formatters/awpluginformatterfloat.h | 27 +++++++++ .../awpluginformatterfloatprecise.cpp | 24 ++++++++ .../awpluginformatterfloatprecise.h | 27 +++++++++ .../formatters/awpluginformatterinteger.cpp | 24 ++++++++ .../formatters/awpluginformatterinteger.h | 27 +++++++++ .../awpluginformatterintegershort.cpp | 24 ++++++++ .../awpluginformatterintegershort.h | 27 +++++++++ .../awpluginformatterintegerwide.cpp | 24 ++++++++ .../formatters/awpluginformatterintegerwide.h | 27 +++++++++ .../formatters/awpluginformatterlist.cpp | 24 ++++++++ .../plugin/formatters/awpluginformatterlist.h | 27 +++++++++ .../formatters/awpluginformattermemory.cpp | 24 ++++++++ .../formatters/awpluginformattermemory.h | 27 +++++++++ .../formatters/awpluginformattermemorygb.cpp | 24 ++++++++ .../formatters/awpluginformattermemorygb.h | 27 +++++++++ .../formatters/awpluginformattermemorymb.cpp | 24 ++++++++ .../formatters/awpluginformattermemorymb.h | 27 +++++++++ .../awpluginformatternetdynamic.cpp | 37 ++++++++++++ .../formatters/awpluginformatternetdynamic.h | 31 ++++++++++ .../formatters/awpluginformatternetunits.cpp | 39 +++++++++++++ .../formatters/awpluginformatternetunits.h | 31 ++++++++++ .../formatters/awpluginformatternoformat.cpp | 24 ++++++++ .../formatters/awpluginformatternoformat.h | 27 +++++++++ .../awpluginformattertemperature.cpp | 47 +++++++++++++++ .../formatters/awpluginformattertemperature.h | 30 ++++++++++ .../formatters/awpluginformattertime.cpp | 26 +++++++++ .../plugin/formatters/awpluginformattertime.h | 27 +++++++++ .../awpluginformattertimecustom.cpp | 46 +++++++++++++++ .../formatters/awpluginformattertimecustom.h | 34 +++++++++++ .../formatters/awpluginformattertimeiso.cpp | 26 +++++++++ .../formatters/awpluginformattertimeiso.h | 27 +++++++++ .../formatters/awpluginformattertimelong.cpp | 26 +++++++++ .../formatters/awpluginformattertimelong.h | 27 +++++++++ .../formatters/awpluginformattertimeshort.cpp | 26 +++++++++ .../formatters/awpluginformattertimeshort.h | 27 +++++++++ 43 files changed, 1211 insertions(+), 1 deletion(-) create mode 100644 sources/awesome-widget/plugin/formatters/awpluginformatsettings.h create mode 100644 sources/awesome-widget/plugin/formatters/awpluginformatter.h create mode 100644 sources/awesome-widget/plugin/formatters/awpluginformatterac.cpp create mode 100644 sources/awesome-widget/plugin/formatters/awpluginformatterac.h create mode 100644 sources/awesome-widget/plugin/formatters/awpluginformatterdouble.cpp create mode 100644 sources/awesome-widget/plugin/formatters/awpluginformatterdouble.h create mode 100644 sources/awesome-widget/plugin/formatters/awpluginformatterfloat.cpp create mode 100644 sources/awesome-widget/plugin/formatters/awpluginformatterfloat.h create mode 100644 sources/awesome-widget/plugin/formatters/awpluginformatterfloatprecise.cpp create mode 100644 sources/awesome-widget/plugin/formatters/awpluginformatterfloatprecise.h create mode 100644 sources/awesome-widget/plugin/formatters/awpluginformatterinteger.cpp create mode 100644 sources/awesome-widget/plugin/formatters/awpluginformatterinteger.h create mode 100644 sources/awesome-widget/plugin/formatters/awpluginformatterintegershort.cpp create mode 100644 sources/awesome-widget/plugin/formatters/awpluginformatterintegershort.h create mode 100644 sources/awesome-widget/plugin/formatters/awpluginformatterintegerwide.cpp create mode 100644 sources/awesome-widget/plugin/formatters/awpluginformatterintegerwide.h create mode 100644 sources/awesome-widget/plugin/formatters/awpluginformatterlist.cpp create mode 100644 sources/awesome-widget/plugin/formatters/awpluginformatterlist.h create mode 100644 sources/awesome-widget/plugin/formatters/awpluginformattermemory.cpp create mode 100644 sources/awesome-widget/plugin/formatters/awpluginformattermemory.h create mode 100644 sources/awesome-widget/plugin/formatters/awpluginformattermemorygb.cpp create mode 100644 sources/awesome-widget/plugin/formatters/awpluginformattermemorygb.h create mode 100644 sources/awesome-widget/plugin/formatters/awpluginformattermemorymb.cpp create mode 100644 sources/awesome-widget/plugin/formatters/awpluginformattermemorymb.h create mode 100644 sources/awesome-widget/plugin/formatters/awpluginformatternetdynamic.cpp create mode 100644 sources/awesome-widget/plugin/formatters/awpluginformatternetdynamic.h create mode 100644 sources/awesome-widget/plugin/formatters/awpluginformatternetunits.cpp create mode 100644 sources/awesome-widget/plugin/formatters/awpluginformatternetunits.h create mode 100644 sources/awesome-widget/plugin/formatters/awpluginformatternoformat.cpp create mode 100644 sources/awesome-widget/plugin/formatters/awpluginformatternoformat.h create mode 100644 sources/awesome-widget/plugin/formatters/awpluginformattertemperature.cpp create mode 100644 sources/awesome-widget/plugin/formatters/awpluginformattertemperature.h create mode 100644 sources/awesome-widget/plugin/formatters/awpluginformattertime.cpp create mode 100644 sources/awesome-widget/plugin/formatters/awpluginformattertime.h create mode 100644 sources/awesome-widget/plugin/formatters/awpluginformattertimecustom.cpp create mode 100644 sources/awesome-widget/plugin/formatters/awpluginformattertimecustom.h create mode 100644 sources/awesome-widget/plugin/formatters/awpluginformattertimeiso.cpp create mode 100644 sources/awesome-widget/plugin/formatters/awpluginformattertimeiso.h create mode 100644 sources/awesome-widget/plugin/formatters/awpluginformattertimelong.cpp create mode 100644 sources/awesome-widget/plugin/formatters/awpluginformattertimelong.h create mode 100644 sources/awesome-widget/plugin/formatters/awpluginformattertimeshort.cpp create mode 100644 sources/awesome-widget/plugin/formatters/awpluginformattertimeshort.h diff --git a/sources/awesome-widget/plugin/CMakeLists.txt b/sources/awesome-widget/plugin/CMakeLists.txt index b33c698..866a8db 100644 --- a/sources/awesome-widget/plugin/CMakeLists.txt +++ b/sources/awesome-widget/plugin/CMakeLists.txt @@ -10,7 +10,7 @@ include_directories( ${Kf6_INCLUDE} ) -file(GLOB SUBPROJECT_SOURCE *.cpp ${PROJECT_TRDPARTY_DIR}/fontdialog/*.cpp ${CMAKE_SOURCE_DIR}/*.cpp) +file(GLOB SUBPROJECT_SOURCE *.cpp formatters/*.cpp ${PROJECT_TRDPARTY_DIR}/fontdialog/*.cpp ${CMAKE_SOURCE_DIR}/*.cpp) file(GLOB SUBPROJECT_UI *.ui) file(GLOB SUBPROJECT_NOTIFY *.notifyrc) diff --git a/sources/awesome-widget/plugin/formatters/awpluginformatsettings.h b/sources/awesome-widget/plugin/formatters/awpluginformatsettings.h new file mode 100644 index 0000000..794ce95 --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformatsettings.h @@ -0,0 +1,33 @@ +/*************************************************************************** + * 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 + + +struct AWPluginFormatSettings { + QString acOffline; + QString acOnline; + + QString customTime; + QString customUptime; + + QString tempUnits; + + bool translate = false; +}; diff --git a/sources/awesome-widget/plugin/formatters/awpluginformatter.h b/sources/awesome-widget/plugin/formatters/awpluginformatter.h new file mode 100644 index 0000000..ce13c55 --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformatter.h @@ -0,0 +1,57 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#pragma once + +#include +#include + +#include "awpluginformatsettings.h" + + +template class AWPluginFormatter { + +public: + static constexpr double KBinBytes = 1024.0; + static constexpr double MBinBytes = 1024.0 * KBinBytes; + static constexpr double GBinBytes = 1024.0 * MBinBytes; + + virtual ~AWPluginFormatter() = default; + AWPluginFormatter(AWPluginFormatter &) = delete; + void operator=(const AWPluginFormatter &) = delete; + + virtual QString format(const QVariant &_value, const AWPluginFormatSettings &_settings) = 0; + static Formatter &instance() + { + static auto instance = loadInstance(); + return instance; + }; + virtual void load() {}; + static QLocale locale(const AWPluginFormatSettings &_settings) + { + return _settings.translate ? QLocale::system() : QLocale::c(); + } + +protected: + AWPluginFormatter() = default; + static Formatter loadInstance() + { + auto instance = Formatter(); + instance.load(); + return instance; + }; +}; diff --git a/sources/awesome-widget/plugin/formatters/awpluginformatterac.cpp b/sources/awesome-widget/plugin/formatters/awpluginformatterac.cpp new file mode 100644 index 0000000..6210e97 --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformatterac.cpp @@ -0,0 +1,24 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#include "awpluginformatterac.h" + + +QString AWPluginFormatterAC::format(const QVariant &_value, const AWPluginFormatSettings &_settings) +{ + return _value.toBool() ? _settings.acOnline : _settings.acOffline; +} diff --git a/sources/awesome-widget/plugin/formatters/awpluginformatterac.h b/sources/awesome-widget/plugin/formatters/awpluginformatterac.h new file mode 100644 index 0000000..174580f --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformatterac.h @@ -0,0 +1,27 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#pragma once + +#include "awpluginformatter.h" + + +class AWPluginFormatterAC : public AWPluginFormatter { + +public: + QString format(const QVariant &_value, const AWPluginFormatSettings &_settings) override; +}; diff --git a/sources/awesome-widget/plugin/formatters/awpluginformatterdouble.cpp b/sources/awesome-widget/plugin/formatters/awpluginformatterdouble.cpp new file mode 100644 index 0000000..ef1fdff --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformatterdouble.cpp @@ -0,0 +1,25 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#include "awpluginformatterdouble.h" + + +QString AWPluginFormatterDouble::format(const QVariant &_value, const AWPluginFormatSettings &) +{ + auto output = QString("%1").arg(_value.toDouble(), 0, 'f'); + return output.rightJustified(8, QLatin1Char(' '), true); +} diff --git a/sources/awesome-widget/plugin/formatters/awpluginformatterdouble.h b/sources/awesome-widget/plugin/formatters/awpluginformatterdouble.h new file mode 100644 index 0000000..4646ace --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformatterdouble.h @@ -0,0 +1,27 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#pragma once + +#include "awpluginformatter.h" + + +class AWPluginFormatterDouble : public AWPluginFormatter { + +public: + QString format(const QVariant &_value, const AWPluginFormatSettings &) override; +}; diff --git a/sources/awesome-widget/plugin/formatters/awpluginformatterfloat.cpp b/sources/awesome-widget/plugin/formatters/awpluginformatterfloat.cpp new file mode 100644 index 0000000..58bba36 --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformatterfloat.cpp @@ -0,0 +1,24 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#include "awpluginformatterfloat.h" + + +QString AWPluginFormatterFloat::format(const QVariant &_value, const AWPluginFormatSettings &) +{ + return QString("%1").arg(_value.toDouble(), 5, 'f', 1); +} diff --git a/sources/awesome-widget/plugin/formatters/awpluginformatterfloat.h b/sources/awesome-widget/plugin/formatters/awpluginformatterfloat.h new file mode 100644 index 0000000..6daa36d --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformatterfloat.h @@ -0,0 +1,27 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#pragma once + +#include "awpluginformatter.h" + + +class AWPluginFormatterFloat : public AWPluginFormatter { + +public: + QString format(const QVariant &_value, const AWPluginFormatSettings &) override; +}; diff --git a/sources/awesome-widget/plugin/formatters/awpluginformatterfloatprecise.cpp b/sources/awesome-widget/plugin/formatters/awpluginformatterfloatprecise.cpp new file mode 100644 index 0000000..24820a7 --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformatterfloatprecise.cpp @@ -0,0 +1,24 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#include "awpluginformatterfloatprecise.h" + + +QString AWPluginFormatterFloatPrecise::format(const QVariant &_value, const AWPluginFormatSettings &) +{ + return QString("%1").arg(_value.toDouble(), 5, 'f', 2); +} diff --git a/sources/awesome-widget/plugin/formatters/awpluginformatterfloatprecise.h b/sources/awesome-widget/plugin/formatters/awpluginformatterfloatprecise.h new file mode 100644 index 0000000..7f45470 --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformatterfloatprecise.h @@ -0,0 +1,27 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#pragma once + +#include "awpluginformatter.h" + + +class AWPluginFormatterFloatPrecise : public AWPluginFormatter { + +public: + QString format(const QVariant &_value, const AWPluginFormatSettings &) override; +}; diff --git a/sources/awesome-widget/plugin/formatters/awpluginformatterinteger.cpp b/sources/awesome-widget/plugin/formatters/awpluginformatterinteger.cpp new file mode 100644 index 0000000..0fb33d8 --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformatterinteger.cpp @@ -0,0 +1,24 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#include "awpluginformatterinteger.h" + + +QString AWPluginFormatterInteger::format(const QVariant &_value, const AWPluginFormatSettings &) +{ + return QString("%1").arg(_value.toDouble(), 4, 'f', 0); +} diff --git a/sources/awesome-widget/plugin/formatters/awpluginformatterinteger.h b/sources/awesome-widget/plugin/formatters/awpluginformatterinteger.h new file mode 100644 index 0000000..67adb9d --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformatterinteger.h @@ -0,0 +1,27 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#pragma once + +#include "awpluginformatter.h" + + +class AWPluginFormatterInteger : public AWPluginFormatter { + +public: + QString format(const QVariant &_value, const AWPluginFormatSettings &) override; +}; diff --git a/sources/awesome-widget/plugin/formatters/awpluginformatterintegershort.cpp b/sources/awesome-widget/plugin/formatters/awpluginformatterintegershort.cpp new file mode 100644 index 0000000..045571a --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformatterintegershort.cpp @@ -0,0 +1,24 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#include "awpluginformatterintegershort.h" + + +QString AWPluginFormatterIntegerShort::format(const QVariant &_value, const AWPluginFormatSettings &) +{ + return QString("%1").arg(_value.toDouble(), 3, 'f', 0); +} diff --git a/sources/awesome-widget/plugin/formatters/awpluginformatterintegershort.h b/sources/awesome-widget/plugin/formatters/awpluginformatterintegershort.h new file mode 100644 index 0000000..0d2e9c1 --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformatterintegershort.h @@ -0,0 +1,27 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#pragma once + +#include "awpluginformatter.h" + + +class AWPluginFormatterIntegerShort : public AWPluginFormatter { + +public: + QString format(const QVariant &_value, const AWPluginFormatSettings &) override; +}; diff --git a/sources/awesome-widget/plugin/formatters/awpluginformatterintegerwide.cpp b/sources/awesome-widget/plugin/formatters/awpluginformatterintegerwide.cpp new file mode 100644 index 0000000..c34f8d1 --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformatterintegerwide.cpp @@ -0,0 +1,24 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#include "awpluginformatterintegerwide.h" + + +QString AWPluginFormatterIntegerWide::format(const QVariant &_value, const AWPluginFormatSettings &) +{ + return QString("%1").arg(_value.toDouble(), 5, 'f', 0); +} diff --git a/sources/awesome-widget/plugin/formatters/awpluginformatterintegerwide.h b/sources/awesome-widget/plugin/formatters/awpluginformatterintegerwide.h new file mode 100644 index 0000000..e503145 --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformatterintegerwide.h @@ -0,0 +1,27 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#pragma once + +#include "awpluginformatter.h" + + +class AWPluginFormatterIntegerWide : public AWPluginFormatter { + +public: + QString format(const QVariant &_value, const AWPluginFormatSettings &) override; +}; diff --git a/sources/awesome-widget/plugin/formatters/awpluginformatterlist.cpp b/sources/awesome-widget/plugin/formatters/awpluginformatterlist.cpp new file mode 100644 index 0000000..f39e78a --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformatterlist.cpp @@ -0,0 +1,24 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#include "awpluginformatterlist.h" + + +QString AWPluginFormatterList::format(const QVariant &_value, const AWPluginFormatSettings &) +{ + return _value.toStringList().join(","); +} diff --git a/sources/awesome-widget/plugin/formatters/awpluginformatterlist.h b/sources/awesome-widget/plugin/formatters/awpluginformatterlist.h new file mode 100644 index 0000000..995b510 --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformatterlist.h @@ -0,0 +1,27 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#pragma once + +#include "awpluginformatter.h" + + +class AWPluginFormatterList : public AWPluginFormatter { + +public: + QString format(const QVariant &_value, const AWPluginFormatSettings &) override; +}; diff --git a/sources/awesome-widget/plugin/formatters/awpluginformattermemory.cpp b/sources/awesome-widget/plugin/formatters/awpluginformattermemory.cpp new file mode 100644 index 0000000..67b1be5 --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformattermemory.cpp @@ -0,0 +1,24 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#include "awpluginformattermemory.h" + + +QString AWPluginFormatterMemory::format(const QVariant &_value, const AWPluginFormatSettings &) +{ + return QString("%1").arg(_value.toDouble() / KBinBytes, 5, 'f', 0); +} diff --git a/sources/awesome-widget/plugin/formatters/awpluginformattermemory.h b/sources/awesome-widget/plugin/formatters/awpluginformattermemory.h new file mode 100644 index 0000000..66a1184 --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformattermemory.h @@ -0,0 +1,27 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#pragma once + +#include "awpluginformatter.h" + + +class AWPluginFormatterMemory : public AWPluginFormatter { + +public: + QString format(const QVariant &_value, const AWPluginFormatSettings &) override; +}; diff --git a/sources/awesome-widget/plugin/formatters/awpluginformattermemorygb.cpp b/sources/awesome-widget/plugin/formatters/awpluginformattermemorygb.cpp new file mode 100644 index 0000000..384971a --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformattermemorygb.cpp @@ -0,0 +1,24 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#include "awpluginformattermemorygb.h" + + +QString AWPluginFormatterMemoryGB::format(const QVariant &_value, const AWPluginFormatSettings &) +{ + return QString("%1").arg(_value.toDouble() / GBinBytes, 5, 'f', 1); +} diff --git a/sources/awesome-widget/plugin/formatters/awpluginformattermemorygb.h b/sources/awesome-widget/plugin/formatters/awpluginformattermemorygb.h new file mode 100644 index 0000000..b3c0080 --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformattermemorygb.h @@ -0,0 +1,27 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#pragma once + +#include "awpluginformatter.h" + + +class AWPluginFormatterMemoryGB : public AWPluginFormatter { + +public: + QString format(const QVariant &_value, const AWPluginFormatSettings &) override; +}; diff --git a/sources/awesome-widget/plugin/formatters/awpluginformattermemorymb.cpp b/sources/awesome-widget/plugin/formatters/awpluginformattermemorymb.cpp new file mode 100644 index 0000000..486ca62 --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformattermemorymb.cpp @@ -0,0 +1,24 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#include "awpluginformattermemorymb.h" + + +QString AWPluginFormatterMemoryMB::format(const QVariant &_value, const AWPluginFormatSettings &) +{ + return QString("%1").arg(_value.toDouble() / MBinBytes, 5, 'f', 0); +} diff --git a/sources/awesome-widget/plugin/formatters/awpluginformattermemorymb.h b/sources/awesome-widget/plugin/formatters/awpluginformattermemorymb.h new file mode 100644 index 0000000..837a7f4 --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformattermemorymb.h @@ -0,0 +1,27 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#pragma once + +#include "awpluginformatter.h" + + +class AWPluginFormatterMemoryMB : public AWPluginFormatter { + +public: + QString format(const QVariant &_value, const AWPluginFormatSettings &) override; +}; diff --git a/sources/awesome-widget/plugin/formatters/awpluginformatternetdynamic.cpp b/sources/awesome-widget/plugin/formatters/awpluginformatternetdynamic.cpp new file mode 100644 index 0000000..e3c7898 --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformatternetdynamic.cpp @@ -0,0 +1,37 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#include "awpluginformatternetdynamic.h" + + +QString AWPluginFormatterNetDynamic::format(const QVariant &_value, const AWPluginFormatSettings &) +{ + auto value = _value.toDouble(); + return (value > MBinBytes) ? formatMB(value) : formatKB(value); +} + + +QString AWPluginFormatterNetDynamic::formatKB(const double &_value) +{ + return QString("%1").arg(_value / KBinBytes, 4, 'f', 0); +} + + +QString AWPluginFormatterNetDynamic::formatMB(const double &_value) +{ + return QString("%1").arg(_value / MBinBytes, 4, 'f', 1); +} diff --git a/sources/awesome-widget/plugin/formatters/awpluginformatternetdynamic.h b/sources/awesome-widget/plugin/formatters/awpluginformatternetdynamic.h new file mode 100644 index 0000000..416b37c --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformatternetdynamic.h @@ -0,0 +1,31 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#pragma once + +#include "awpluginformatter.h" + + +class AWPluginFormatterNetDynamic : public AWPluginFormatter { + +public: + QString format(const QVariant &_value, const AWPluginFormatSettings &) override; + +private: + static QString formatKB(const double &_value); + static QString formatMB(const double &_value); +}; diff --git a/sources/awesome-widget/plugin/formatters/awpluginformatternetunits.cpp b/sources/awesome-widget/plugin/formatters/awpluginformatternetunits.cpp new file mode 100644 index 0000000..1f0e79c --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformatternetunits.cpp @@ -0,0 +1,39 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#include "awpluginformatternetunits.h" + +#include + + +QString AWPluginFormatterNetUnits::format(const QVariant &_value, const AWPluginFormatSettings &_settings) +{ + auto value = _value.toDouble(); + return (value > MBinBytes) ? formatMB(_settings) : formatKB(_settings); +} + + +QString AWPluginFormatterNetUnits::formatKB(const AWPluginFormatSettings &_settings) +{ + return _settings.translate ? i18n("KB/s") : "KB/s"; +} + + +QString AWPluginFormatterNetUnits::formatMB(const AWPluginFormatSettings &_settings) +{ + return _settings.translate ? i18n("MB/s") : "MB/s"; +} diff --git a/sources/awesome-widget/plugin/formatters/awpluginformatternetunits.h b/sources/awesome-widget/plugin/formatters/awpluginformatternetunits.h new file mode 100644 index 0000000..7cb0f23 --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformatternetunits.h @@ -0,0 +1,31 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#pragma once + +#include "awpluginformatter.h" + + +class AWPluginFormatterNetUnits : public AWPluginFormatter { + +public: + QString format(const QVariant &_value, const AWPluginFormatSettings &_settings) override; + +private: + static QString formatKB(const AWPluginFormatSettings &_settings); + static QString formatMB(const AWPluginFormatSettings &_settings); +}; diff --git a/sources/awesome-widget/plugin/formatters/awpluginformatternoformat.cpp b/sources/awesome-widget/plugin/formatters/awpluginformatternoformat.cpp new file mode 100644 index 0000000..2d445a4 --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformatternoformat.cpp @@ -0,0 +1,24 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#include "awpluginformatternoformat.h" + + +QString AWPluginFormatterNoFormat::format(const QVariant &_value, const AWPluginFormatSettings &) +{ + return _value.toString(); +} diff --git a/sources/awesome-widget/plugin/formatters/awpluginformatternoformat.h b/sources/awesome-widget/plugin/formatters/awpluginformatternoformat.h new file mode 100644 index 0000000..ab709c4 --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformatternoformat.h @@ -0,0 +1,27 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#pragma once + +#include "awpluginformatter.h" + + +class AWPluginFormatterNoFormat : public AWPluginFormatter { + +public: + QString format(const QVariant &_value, const AWPluginFormatSettings &) override; +}; diff --git a/sources/awesome-widget/plugin/formatters/awpluginformattertemperature.cpp b/sources/awesome-widget/plugin/formatters/awpluginformattertemperature.cpp new file mode 100644 index 0000000..31420af --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformattertemperature.cpp @@ -0,0 +1,47 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#include "awpluginformattertemperature.h" + + +QString AWPluginFormatterTemperature::format(const QVariant &_value, const AWPluginFormatSettings &_settings) +{ + auto converted = convert(_value.toDouble(), _settings.tempUnits); + return QString("%1").arg(converted, 5, 'f', 1); +} + + +double AWPluginFormatterTemperature::convert(const double &_value, const QString &_units) +{ + auto converted = _value; + if (_units == "Celsius") { + } else if (_units == "Fahrenheit") { + converted = _value * 9.0f / 5.0 + 32.0; + } else if (_units == "Kelvin") { + converted = _value + 273.15; + } else if (_units == "Reaumur") { + converted = _value * 0.8; + } else if (_units == "cm^-1") { + converted = (_value + 273.15) * 0.695; + } else if (_units == "kJ/mol") { + converted = (_value + 273.15) * 8.31; + } else if (_units == "kcal/mol") { + converted = (_value + 273.15) * 1.98; + } + + return converted; +} diff --git a/sources/awesome-widget/plugin/formatters/awpluginformattertemperature.h b/sources/awesome-widget/plugin/formatters/awpluginformattertemperature.h new file mode 100644 index 0000000..cb18abb --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformattertemperature.h @@ -0,0 +1,30 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#pragma once + +#include "awpluginformatter.h" + + +class AWPluginFormatterTemperature : public AWPluginFormatter { + +public: + QString format(const QVariant &_value, const AWPluginFormatSettings &_settings) override; + +private: + static double convert(const double &_value, const QString &_units); +}; diff --git a/sources/awesome-widget/plugin/formatters/awpluginformattertime.cpp b/sources/awesome-widget/plugin/formatters/awpluginformattertime.cpp new file mode 100644 index 0000000..b2c93ea --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformattertime.cpp @@ -0,0 +1,26 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#include "awpluginformattertime.h" + +#include + + +QString AWPluginFormatterTime::format(const QVariant &_value, const AWPluginFormatSettings &) +{ + return QDateTime::fromSecsSinceEpoch(_value.toLongLong()).toString(); +} diff --git a/sources/awesome-widget/plugin/formatters/awpluginformattertime.h b/sources/awesome-widget/plugin/formatters/awpluginformattertime.h new file mode 100644 index 0000000..33613fb --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformattertime.h @@ -0,0 +1,27 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#pragma once + +#include "awpluginformatter.h" + + +class AWPluginFormatterTime : public AWPluginFormatter { + +public: + QString format(const QVariant &_value, const AWPluginFormatSettings &) override; +}; diff --git a/sources/awesome-widget/plugin/formatters/awpluginformattertimecustom.cpp b/sources/awesome-widget/plugin/formatters/awpluginformattertimecustom.cpp new file mode 100644 index 0000000..64b8d3b --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformattertimecustom.cpp @@ -0,0 +1,46 @@ +/*************************************************************************** + * 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 + +#include "awdebug.h" + + +QString AWPluginFormatterTimeCustom::format(const QVariant &_value, const AWPluginFormatSettings &_settings) +{ + 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) +{ + for (auto &key : m_timeKeys) + _formatString.replace(QString("$%1").arg(key), _locale.toString(_value, key)); + + return _formatString; +} diff --git a/sources/awesome-widget/plugin/formatters/awpluginformattertimecustom.h b/sources/awesome-widget/plugin/formatters/awpluginformattertimecustom.h new file mode 100644 index 0000000..315f923 --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformattertimecustom.h @@ -0,0 +1,34 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#pragma once + +#include + +#include "awpluginformatter.h" + + +class AWPluginFormatterTimeCustom : public AWPluginFormatter { + +public: + QString format(const QVariant &_value, const AWPluginFormatSettings &_settings) override; + void load() override; + +private: + QString format(const QDateTime &_value, QString _formatString, const QLocale &_locale); + QStringList m_timeKeys; +}; diff --git a/sources/awesome-widget/plugin/formatters/awpluginformattertimeiso.cpp b/sources/awesome-widget/plugin/formatters/awpluginformattertimeiso.cpp new file mode 100644 index 0000000..3f8f179 --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformattertimeiso.cpp @@ -0,0 +1,26 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#include "awpluginformattertimeiso.h" + +#include + + +QString AWPluginFormatterTimeISO::format(const QVariant &_value, const AWPluginFormatSettings &) +{ + return QDateTime::fromSecsSinceEpoch(_value.toLongLong()).toString(Qt::ISODate); +} diff --git a/sources/awesome-widget/plugin/formatters/awpluginformattertimeiso.h b/sources/awesome-widget/plugin/formatters/awpluginformattertimeiso.h new file mode 100644 index 0000000..80c3001 --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformattertimeiso.h @@ -0,0 +1,27 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#pragma once + +#include "awpluginformatter.h" + + +class AWPluginFormatterTimeISO : public AWPluginFormatter { + +public: + QString format(const QVariant &_value, const AWPluginFormatSettings &) override; +}; diff --git a/sources/awesome-widget/plugin/formatters/awpluginformattertimelong.cpp b/sources/awesome-widget/plugin/formatters/awpluginformattertimelong.cpp new file mode 100644 index 0000000..6a44020 --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformattertimelong.cpp @@ -0,0 +1,26 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#include "awpluginformattertimelong.h" + +#include + + +QString AWPluginFormatterTimeLong::format(const QVariant &_value, const AWPluginFormatSettings &_settings) +{ + return locale(_settings).toString(QDateTime::fromSecsSinceEpoch(_value.toLongLong()), QLocale::LongFormat); +} diff --git a/sources/awesome-widget/plugin/formatters/awpluginformattertimelong.h b/sources/awesome-widget/plugin/formatters/awpluginformattertimelong.h new file mode 100644 index 0000000..70da0aa --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformattertimelong.h @@ -0,0 +1,27 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#pragma once + +#include "awpluginformatter.h" + + +class AWPluginFormatterTimeLong : public AWPluginFormatter { + +public: + QString format(const QVariant &_value, const AWPluginFormatSettings &_settings) override; +}; diff --git a/sources/awesome-widget/plugin/formatters/awpluginformattertimeshort.cpp b/sources/awesome-widget/plugin/formatters/awpluginformattertimeshort.cpp new file mode 100644 index 0000000..270a71d --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformattertimeshort.cpp @@ -0,0 +1,26 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#include "awpluginformattertimeshort.h" + +#include + + +QString AWPluginFormatterTimeShort::format(const QVariant &_value, const AWPluginFormatSettings &_settings) +{ + return locale(_settings).toString(QDateTime::fromSecsSinceEpoch(_value.toLongLong()), QLocale::ShortFormat); +} diff --git a/sources/awesome-widget/plugin/formatters/awpluginformattertimeshort.h b/sources/awesome-widget/plugin/formatters/awpluginformattertimeshort.h new file mode 100644 index 0000000..83dff8e --- /dev/null +++ b/sources/awesome-widget/plugin/formatters/awpluginformattertimeshort.h @@ -0,0 +1,27 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#pragma once + +#include "awpluginformatter.h" + + +class AWPluginFormatterTimeShort : public AWPluginFormatter { + +public: + QString format(const QVariant &_value, const AWPluginFormatSettings &_settings) override; +};