split formatter into separated singleton classes

This commit is contained in:
Evgenii Alekseev 2024-04-22 17:36:48 +03:00
parent 95572364c1
commit 981fb30935
43 changed files with 1211 additions and 1 deletions

View File

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

View File

@ -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 <QString>
struct AWPluginFormatSettings {
QString acOffline;
QString acOnline;
QString customTime;
QString customUptime;
QString tempUnits;
bool translate = false;
};

View File

@ -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 <QLocale>
#include <QVariant>
#include "awpluginformatsettings.h"
template<typename Formatter> 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;
};
};

View File

@ -0,0 +1,24 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#include "awpluginformatterac.h"
QString AWPluginFormatterAC::format(const QVariant &_value, const AWPluginFormatSettings &_settings)
{
return _value.toBool() ? _settings.acOnline : _settings.acOffline;
}

View File

@ -0,0 +1,27 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#pragma once
#include "awpluginformatter.h"
class AWPluginFormatterAC : public AWPluginFormatter<AWPluginFormatterAC> {
public:
QString format(const QVariant &_value, const AWPluginFormatSettings &_settings) override;
};

View File

@ -0,0 +1,25 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#include "awpluginformatterdouble.h"
QString AWPluginFormatterDouble::format(const QVariant &_value, const AWPluginFormatSettings &)
{
auto output = QString("%1").arg(_value.toDouble(), 0, 'f');
return output.rightJustified(8, QLatin1Char(' '), true);
}

View File

@ -0,0 +1,27 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#pragma once
#include "awpluginformatter.h"
class AWPluginFormatterDouble : public AWPluginFormatter<AWPluginFormatterDouble> {
public:
QString format(const QVariant &_value, const AWPluginFormatSettings &) override;
};

View File

@ -0,0 +1,24 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#include "awpluginformatterfloat.h"
QString AWPluginFormatterFloat::format(const QVariant &_value, const AWPluginFormatSettings &)
{
return QString("%1").arg(_value.toDouble(), 5, 'f', 1);
}

View File

@ -0,0 +1,27 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#pragma once
#include "awpluginformatter.h"
class AWPluginFormatterFloat : public AWPluginFormatter<AWPluginFormatterFloat> {
public:
QString format(const QVariant &_value, const AWPluginFormatSettings &) override;
};

View File

@ -0,0 +1,24 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#include "awpluginformatterfloatprecise.h"
QString AWPluginFormatterFloatPrecise::format(const QVariant &_value, const AWPluginFormatSettings &)
{
return QString("%1").arg(_value.toDouble(), 5, 'f', 2);
}

View File

@ -0,0 +1,27 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#pragma once
#include "awpluginformatter.h"
class AWPluginFormatterFloatPrecise : public AWPluginFormatter<AWPluginFormatterFloatPrecise> {
public:
QString format(const QVariant &_value, const AWPluginFormatSettings &) override;
};

View File

@ -0,0 +1,24 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#include "awpluginformatterinteger.h"
QString AWPluginFormatterInteger::format(const QVariant &_value, const AWPluginFormatSettings &)
{
return QString("%1").arg(_value.toDouble(), 4, 'f', 0);
}

View File

@ -0,0 +1,27 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#pragma once
#include "awpluginformatter.h"
class AWPluginFormatterInteger : public AWPluginFormatter<AWPluginFormatterInteger> {
public:
QString format(const QVariant &_value, const AWPluginFormatSettings &) override;
};

View File

@ -0,0 +1,24 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#include "awpluginformatterintegershort.h"
QString AWPluginFormatterIntegerShort::format(const QVariant &_value, const AWPluginFormatSettings &)
{
return QString("%1").arg(_value.toDouble(), 3, 'f', 0);
}

View File

@ -0,0 +1,27 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#pragma once
#include "awpluginformatter.h"
class AWPluginFormatterIntegerShort : public AWPluginFormatter<AWPluginFormatterIntegerShort> {
public:
QString format(const QVariant &_value, const AWPluginFormatSettings &) override;
};

View File

@ -0,0 +1,24 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#include "awpluginformatterintegerwide.h"
QString AWPluginFormatterIntegerWide::format(const QVariant &_value, const AWPluginFormatSettings &)
{
return QString("%1").arg(_value.toDouble(), 5, 'f', 0);
}

View File

@ -0,0 +1,27 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#pragma once
#include "awpluginformatter.h"
class AWPluginFormatterIntegerWide : public AWPluginFormatter<AWPluginFormatterIntegerWide> {
public:
QString format(const QVariant &_value, const AWPluginFormatSettings &) override;
};

View File

@ -0,0 +1,24 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#include "awpluginformatterlist.h"
QString AWPluginFormatterList::format(const QVariant &_value, const AWPluginFormatSettings &)
{
return _value.toStringList().join(",");
}

View File

@ -0,0 +1,27 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#pragma once
#include "awpluginformatter.h"
class AWPluginFormatterList : public AWPluginFormatter<AWPluginFormatterList> {
public:
QString format(const QVariant &_value, const AWPluginFormatSettings &) override;
};

View File

@ -0,0 +1,24 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#include "awpluginformattermemory.h"
QString AWPluginFormatterMemory::format(const QVariant &_value, const AWPluginFormatSettings &)
{
return QString("%1").arg(_value.toDouble() / KBinBytes, 5, 'f', 0);
}

View File

@ -0,0 +1,27 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#pragma once
#include "awpluginformatter.h"
class AWPluginFormatterMemory : public AWPluginFormatter<AWPluginFormatterMemory> {
public:
QString format(const QVariant &_value, const AWPluginFormatSettings &) override;
};

View File

@ -0,0 +1,24 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#include "awpluginformattermemorygb.h"
QString AWPluginFormatterMemoryGB::format(const QVariant &_value, const AWPluginFormatSettings &)
{
return QString("%1").arg(_value.toDouble() / GBinBytes, 5, 'f', 1);
}

View File

@ -0,0 +1,27 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#pragma once
#include "awpluginformatter.h"
class AWPluginFormatterMemoryGB : public AWPluginFormatter<AWPluginFormatterMemoryGB> {
public:
QString format(const QVariant &_value, const AWPluginFormatSettings &) override;
};

View File

@ -0,0 +1,24 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#include "awpluginformattermemorymb.h"
QString AWPluginFormatterMemoryMB::format(const QVariant &_value, const AWPluginFormatSettings &)
{
return QString("%1").arg(_value.toDouble() / MBinBytes, 5, 'f', 0);
}

View File

@ -0,0 +1,27 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#pragma once
#include "awpluginformatter.h"
class AWPluginFormatterMemoryMB : public AWPluginFormatter<AWPluginFormatterMemoryMB> {
public:
QString format(const QVariant &_value, const AWPluginFormatSettings &) override;
};

View File

@ -0,0 +1,37 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#include "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);
}

View File

@ -0,0 +1,31 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#pragma once
#include "awpluginformatter.h"
class AWPluginFormatterNetDynamic : public AWPluginFormatter<AWPluginFormatterNetDynamic> {
public:
QString format(const QVariant &_value, const AWPluginFormatSettings &) override;
private:
static QString formatKB(const double &_value);
static QString formatMB(const double &_value);
};

View File

@ -0,0 +1,39 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#include "awpluginformatternetunits.h"
#include <KI18n/KLocalizedString>
QString AWPluginFormatterNetUnits::format(const QVariant &_value, const 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";
}

View File

@ -0,0 +1,31 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#pragma once
#include "awpluginformatter.h"
class AWPluginFormatterNetUnits : public AWPluginFormatter<AWPluginFormatterNetUnits> {
public:
QString format(const QVariant &_value, const AWPluginFormatSettings &_settings) override;
private:
static QString formatKB(const AWPluginFormatSettings &_settings);
static QString formatMB(const AWPluginFormatSettings &_settings);
};

View File

@ -0,0 +1,24 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#include "awpluginformatternoformat.h"
QString AWPluginFormatterNoFormat::format(const QVariant &_value, const AWPluginFormatSettings &)
{
return _value.toString();
}

View File

@ -0,0 +1,27 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#pragma once
#include "awpluginformatter.h"
class AWPluginFormatterNoFormat : public AWPluginFormatter<AWPluginFormatterNoFormat> {
public:
QString format(const QVariant &_value, const AWPluginFormatSettings &) override;
};

View File

@ -0,0 +1,47 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#include "awpluginformattertemperature.h"
QString AWPluginFormatterTemperature::format(const QVariant &_value, const 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;
}

View File

@ -0,0 +1,30 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#pragma once
#include "awpluginformatter.h"
class AWPluginFormatterTemperature : public AWPluginFormatter<AWPluginFormatterTemperature> {
public:
QString format(const QVariant &_value, const AWPluginFormatSettings &_settings) override;
private:
static double convert(const double &_value, const QString &_units);
};

View File

@ -0,0 +1,26 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#include "awpluginformattertime.h"
#include <QDateTime>
QString AWPluginFormatterTime::format(const QVariant &_value, const AWPluginFormatSettings &)
{
return QDateTime::fromSecsSinceEpoch(_value.toLongLong()).toString();
}

View File

@ -0,0 +1,27 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#pragma once
#include "awpluginformatter.h"
class AWPluginFormatterTime : public AWPluginFormatter<AWPluginFormatterTime> {
public:
QString format(const QVariant &_value, const AWPluginFormatSettings &) override;
};

View File

@ -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 <QDateTime>
#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;
}

View File

@ -0,0 +1,34 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#pragma once
#include <QDateTime>
#include "awpluginformatter.h"
class AWPluginFormatterTimeCustom : public AWPluginFormatter<AWPluginFormatterTimeCustom> {
public:
QString format(const QVariant &_value, const AWPluginFormatSettings &_settings) override;
void load() override;
private:
QString format(const QDateTime &_value, QString _formatString, const QLocale &_locale);
QStringList m_timeKeys;
};

View File

@ -0,0 +1,26 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#include "awpluginformattertimeiso.h"
#include <QDateTime>
QString AWPluginFormatterTimeISO::format(const QVariant &_value, const AWPluginFormatSettings &)
{
return QDateTime::fromSecsSinceEpoch(_value.toLongLong()).toString(Qt::ISODate);
}

View File

@ -0,0 +1,27 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#pragma once
#include "awpluginformatter.h"
class AWPluginFormatterTimeISO : public AWPluginFormatter<AWPluginFormatterTimeISO> {
public:
QString format(const QVariant &_value, const AWPluginFormatSettings &) override;
};

View File

@ -0,0 +1,26 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#include "awpluginformattertimelong.h"
#include <QDateTime>
QString AWPluginFormatterTimeLong::format(const QVariant &_value, const AWPluginFormatSettings &_settings)
{
return locale(_settings).toString(QDateTime::fromSecsSinceEpoch(_value.toLongLong()), QLocale::LongFormat);
}

View File

@ -0,0 +1,27 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#pragma once
#include "awpluginformatter.h"
class AWPluginFormatterTimeLong : public AWPluginFormatter<AWPluginFormatterTimeLong> {
public:
QString format(const QVariant &_value, const AWPluginFormatSettings &_settings) override;
};

View File

@ -0,0 +1,26 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#include "awpluginformattertimeshort.h"
#include <QDateTime>
QString AWPluginFormatterTimeShort::format(const QVariant &_value, const AWPluginFormatSettings &_settings)
{
return locale(_settings).toString(QDateTime::fromSecsSinceEpoch(_value.toLongLong()), QLocale::ShortFormat);
}

View File

@ -0,0 +1,27 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#pragma once
#include "awpluginformatter.h"
class AWPluginFormatterTimeShort : public AWPluginFormatter<AWPluginFormatterTimeShort> {
public:
QString format(const QVariant &_value, const AWPluginFormatSettings &_settings) override;
};