mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-24 15:37:23 +00:00
refactor: refresh aw plugin
This commit is contained in:
parent
54acc5f780
commit
397b523180
@ -56,15 +56,15 @@ QString AWDebug::getAboutText(const QString &_type)
|
||||
translator = QString("<li>%1</li>").arg(translator);
|
||||
text = i18n("Translators:") + "<ul>" + translatorList.join("") + "</ul>";
|
||||
} else if (_type == "3rdparty") {
|
||||
QStringList trdPartyList = QString(TRDPARTY_LICENSE).split(';', Qt::SkipEmptyParts);
|
||||
for (int i = 0; i < trdPartyList.count(); i++)
|
||||
auto trdPartyList = QString(TRDPARTY_LICENSE).split(';', Qt::SkipEmptyParts);
|
||||
for (auto i = 0; i < trdPartyList.count(); ++i)
|
||||
trdPartyList[i] = QString("<li><a href=\"%3\">%1</a> (%2 license)</li>")
|
||||
.arg(trdPartyList.at(i).split(',')[0], trdPartyList.at(i).split(',')[1],
|
||||
trdPartyList.at(i).split(',')[2]);
|
||||
text = i18n("This software uses:") + "<ul>" + trdPartyList.join("") + "</ul>";
|
||||
} else if (_type == "thanks") {
|
||||
QStringList thanks = QString(SPECIAL_THANKS).split(';', Qt::SkipEmptyParts);
|
||||
for (int i = 0; i < thanks.count(); i++)
|
||||
auto thanks = QString(SPECIAL_THANKS).split(';', Qt::SkipEmptyParts);
|
||||
for (auto i = 0; i < thanks.count(); ++i)
|
||||
thanks[i]
|
||||
= QString("<li><a href=\"%2\">%1</a></li>").arg(thanks.at(i).split(',')[0], thanks.at(i).split(',')[1]);
|
||||
text = i18n("Special thanks to:") + "<ul>" + thanks.join("") + "</ul>";
|
||||
|
@ -119,7 +119,7 @@ void AWAbstractPairConfig::addSelector(const QStringList &_keys, const QStringLi
|
||||
|
||||
void AWAbstractPairConfig::clearSelectors()
|
||||
{
|
||||
for (auto &selector : m_selectors) {
|
||||
for (auto selector : m_selectors) {
|
||||
disconnect(selector, &AWAbstractSelector::selectionChanged, this, &AWAbstractPairConfig::updateUi);
|
||||
ui->verticalLayout->removeWidget(selector);
|
||||
selector->deleteLater();
|
||||
@ -130,9 +130,9 @@ void AWAbstractPairConfig::clearSelectors()
|
||||
|
||||
void AWAbstractPairConfig::execDialog()
|
||||
{
|
||||
int ret = exec();
|
||||
auto ret = exec();
|
||||
QHash<QString, QString> data;
|
||||
for (auto &selector : m_selectors) {
|
||||
for (auto selector : m_selectors) {
|
||||
QPair<QString, QString> select = selector->current();
|
||||
if (select.first.isEmpty())
|
||||
continue;
|
||||
@ -160,6 +160,7 @@ QPair<QStringList, QStringList> AWAbstractPairConfig::initKeys() const
|
||||
QStringList left = {""};
|
||||
left.append(m_helper->leftKeys().isEmpty() ? m_keys : m_helper->leftKeys());
|
||||
left.sort();
|
||||
|
||||
QStringList right = {""};
|
||||
right.append(m_helper->rightKeys().isEmpty() ? m_keys : m_helper->rightKeys());
|
||||
right.sort();
|
||||
@ -175,7 +176,7 @@ void AWAbstractPairConfig::updateDialog()
|
||||
auto keys = initKeys();
|
||||
|
||||
for (auto &key : m_helper->keys())
|
||||
addSelector(keys.first, keys.second, QPair<QString, QString>(key, pairs[key]));
|
||||
addSelector(keys.first, keys.second, {key, pairs[key]});
|
||||
// empty one
|
||||
addSelector(keys.first, keys.second, QPair<QString, QString>());
|
||||
addSelector(keys.first, keys.second, {});
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ class AWAbstractPairConfig : public QDialog
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AWAbstractPairConfig(QWidget *_parent = nullptr, bool _hasEdit = false, QStringList _keys = QStringList());
|
||||
explicit AWAbstractPairConfig(QWidget *_parent = nullptr, bool _hasEdit = false, QStringList _keys = {});
|
||||
~AWAbstractPairConfig() override;
|
||||
template <class T> void initHelper()
|
||||
{
|
||||
|
@ -34,12 +34,6 @@ AWAbstractPairHelper::AWAbstractPairHelper(QString _filePath, QString _section)
|
||||
}
|
||||
|
||||
|
||||
AWAbstractPairHelper::~AWAbstractPairHelper()
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
}
|
||||
|
||||
|
||||
QStringList AWAbstractPairHelper::keys() const
|
||||
{
|
||||
return m_pairs.keys();
|
||||
@ -69,16 +63,16 @@ void AWAbstractPairHelper::initItems()
|
||||
{
|
||||
m_pairs.clear();
|
||||
|
||||
QStringList configs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, m_filePath);
|
||||
auto configs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, m_filePath);
|
||||
|
||||
for (auto &fileName : configs) {
|
||||
QSettings settings(fileName, QSettings::IniFormat);
|
||||
qCInfo(LOG_AW) << "Configuration file" << settings.fileName();
|
||||
|
||||
settings.beginGroup(m_section);
|
||||
QStringList keys = settings.childKeys();
|
||||
auto keys = settings.childKeys();
|
||||
for (auto &key : keys) {
|
||||
QString value = settings.value(key).toString();
|
||||
auto value = settings.value(key).toString();
|
||||
qCInfo(LOG_AW) << "Found key" << key << "for value" << value << "in" << settings.fileName();
|
||||
if (value.isEmpty()) {
|
||||
qCInfo(LOG_AW) << "Skip empty value for" << key;
|
||||
@ -95,8 +89,8 @@ bool AWAbstractPairHelper::writeItems(const QHash<QString, QString> &_configurat
|
||||
{
|
||||
qCDebug(LOG_AW) << "Write configuration" << _configuration;
|
||||
|
||||
QString fileName
|
||||
= QString("%1/%2").arg(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)).arg(m_filePath);
|
||||
auto fileName
|
||||
= QString("%1/%2").arg(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation), m_filePath);
|
||||
QSettings settings(fileName, QSettings::IniFormat);
|
||||
qCInfo(LOG_AW) << "Configuration file" << fileName;
|
||||
|
||||
@ -107,7 +101,7 @@ bool AWAbstractPairHelper::writeItems(const QHash<QString, QString> &_configurat
|
||||
|
||||
settings.sync();
|
||||
|
||||
return (settings.status() == QSettings::NoError);
|
||||
return settings.status() == QSettings::NoError;
|
||||
}
|
||||
|
||||
|
||||
@ -115,14 +109,13 @@ bool AWAbstractPairHelper::removeUnusedKeys(const QStringList &_keys) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Remove keys" << _keys;
|
||||
|
||||
QString fileName
|
||||
= QString("%1/%2").arg(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)).arg(m_filePath);
|
||||
auto fileName
|
||||
= QString("%1/%2").arg(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation), m_filePath);
|
||||
QSettings settings(fileName, QSettings::IniFormat);
|
||||
qCInfo(LOG_AW) << "Configuration file" << fileName;
|
||||
|
||||
settings.beginGroup(m_section);
|
||||
QStringList foundKeys = settings.childKeys();
|
||||
for (auto &key : foundKeys) {
|
||||
for (auto &key : settings.childKeys()) {
|
||||
if (_keys.contains(key))
|
||||
continue;
|
||||
settings.remove(key);
|
||||
@ -131,5 +124,5 @@ bool AWAbstractPairHelper::removeUnusedKeys(const QStringList &_keys) const
|
||||
|
||||
settings.sync();
|
||||
|
||||
return (settings.status() == QSettings::NoError);
|
||||
return settings.status() == QSettings::NoError;
|
||||
}
|
@ -24,7 +24,7 @@ class AWAbstractPairHelper
|
||||
{
|
||||
public:
|
||||
explicit AWAbstractPairHelper(QString _filePath = "", QString _section = "");
|
||||
virtual ~AWAbstractPairHelper();
|
||||
virtual ~AWAbstractPairHelper() = default;
|
||||
[[nodiscard]] QStringList keys() const;
|
||||
[[nodiscard]] QHash<QString, QString> pairs() const;
|
||||
[[nodiscard]] QStringList values() const;
|
||||
|
@ -31,8 +31,8 @@ AWAbstractSelector::AWAbstractSelector(QWidget *_parent, const QPair<bool, bool>
|
||||
ui->comboBox_key->setEditable(_editable.first);
|
||||
ui->comboBox_value->setEditable(_editable.second);
|
||||
|
||||
connect(ui->comboBox_key, SIGNAL(currentIndexChanged(int)), this, SIGNAL(selectionChanged()));
|
||||
connect(ui->comboBox_value, SIGNAL(currentIndexChanged(int)), this, SIGNAL(selectionChanged()));
|
||||
connect(ui->comboBox_key, &QComboBox::currentIndexChanged, this, &AWAbstractSelector::selectionChanged);
|
||||
connect(ui->comboBox_value, &QComboBox::currentIndexChanged, this, &AWAbstractSelector::selectionChanged);
|
||||
}
|
||||
|
||||
|
||||
@ -46,10 +46,10 @@ AWAbstractSelector::~AWAbstractSelector()
|
||||
|
||||
QPair<QString, QString> AWAbstractSelector::current() const
|
||||
{
|
||||
QString key = ui->comboBox_key->currentText();
|
||||
QString value = ui->comboBox_value->currentText();
|
||||
auto key = ui->comboBox_key->currentText();
|
||||
auto value = ui->comboBox_value->currentText();
|
||||
|
||||
return QPair<QString, QString>(key, value);
|
||||
return {key, value};
|
||||
}
|
||||
|
||||
|
||||
|
@ -40,12 +40,6 @@ AWActions::AWActions(QObject *_parent)
|
||||
}
|
||||
|
||||
|
||||
AWActions::~AWActions()
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
}
|
||||
|
||||
|
||||
void AWActions::checkUpdates(const bool _showAnyway)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Show anyway" << _showAnyway;
|
||||
@ -65,7 +59,7 @@ QString AWActions::getFileContent(const QString &_path)
|
||||
return "";
|
||||
}
|
||||
|
||||
QString output = inputFile.readAll();
|
||||
auto output = inputFile.readAll();
|
||||
inputFile.close();
|
||||
return output;
|
||||
}
|
||||
@ -102,10 +96,10 @@ QVariantMap AWActions::getFont(const QVariantMap &_defaultFont)
|
||||
qCDebug(LOG_AW) << "Default font is" << _defaultFont;
|
||||
|
||||
QVariantMap fontMap;
|
||||
int ret = 0;
|
||||
CFont defaultCFont = CFont(_defaultFont["family"].toString(), _defaultFont["size"].toInt(), 400, false,
|
||||
_defaultFont["color"].toString());
|
||||
CFont font = CFontDialog::getFont(i18n("Select font"), defaultCFont, false, false, &ret);
|
||||
auto ret = 0;
|
||||
auto defaultCFont = CFont(_defaultFont["family"].toString(), _defaultFont["size"].toInt(), 400, false,
|
||||
_defaultFont["color"].toString());
|
||||
auto font = CFontDialog::getFont(i18n("Select font"), defaultCFont, false, false, &ret);
|
||||
|
||||
fontMap["applied"] = ret;
|
||||
fontMap["color"] = font.color().name();
|
||||
|
@ -29,7 +29,7 @@ class AWActions : public QObject
|
||||
|
||||
public:
|
||||
explicit AWActions(QObject *_parent = nullptr);
|
||||
~AWActions() override;
|
||||
~AWActions() override = default;
|
||||
Q_INVOKABLE void checkUpdates(bool _showAnyway = false);
|
||||
Q_INVOKABLE static QString getFileContent(const QString &_path);
|
||||
Q_INVOKABLE static bool runCmd(const QString &_cmd, const QStringList &_args);
|
||||
|
@ -20,7 +20,6 @@
|
||||
#include <QObject>
|
||||
|
||||
|
||||
class QAbstractButton;
|
||||
class QNetworkReply;
|
||||
|
||||
class AWBugReporter : public QObject
|
||||
|
@ -34,17 +34,11 @@ AWConfigHelper::AWConfigHelper(QObject *_parent)
|
||||
}
|
||||
|
||||
|
||||
AWConfigHelper::~AWConfigHelper()
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
}
|
||||
|
||||
|
||||
QString AWConfigHelper::configurationDirectory()
|
||||
{
|
||||
// get readable directory
|
||||
QString localDir = QString("%1/awesomewidgets/configs")
|
||||
.arg(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation));
|
||||
auto localDir = QString("%1/awesomewidgets/configs")
|
||||
.arg(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation));
|
||||
|
||||
// create directory and copy files from default settings
|
||||
QDir localDirectory;
|
||||
@ -59,7 +53,7 @@ QString AWConfigHelper::configurationDirectory()
|
||||
|
||||
bool AWConfigHelper::dropCache()
|
||||
{
|
||||
QString fileName
|
||||
auto fileName
|
||||
= QString("%1/awesomewidgets.ndx").arg(QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation));
|
||||
|
||||
return QFile(fileName).remove();
|
||||
@ -75,7 +69,7 @@ bool AWConfigHelper::exportConfiguration(QObject *_nativeConfig, const QString &
|
||||
auto configuration = dynamic_cast<const QQmlPropertyMap *>(_nativeConfig);
|
||||
settings.beginGroup("plasmoid");
|
||||
for (auto &key : configuration->keys()) {
|
||||
QVariant value = configuration->value(key);
|
||||
auto value = configuration->value(key);
|
||||
if (!value.isValid())
|
||||
continue;
|
||||
settings.setValue(key, value);
|
||||
@ -84,7 +78,7 @@ bool AWConfigHelper::exportConfiguration(QObject *_nativeConfig, const QString &
|
||||
|
||||
// extensions
|
||||
for (auto &item : m_dirs) {
|
||||
QStringList items = QDir(QString("%1/%2").arg(m_baseDir, item)).entryList({"*.desktop"}, QDir::Files);
|
||||
auto items = QDir(QString("%1/%2").arg(m_baseDir, item)).entryList({"*.desktop"}, QDir::Files);
|
||||
settings.beginGroup(item);
|
||||
for (auto &it : items)
|
||||
copyExtensions(it, item, settings, false);
|
||||
@ -162,7 +156,7 @@ QVariantMap AWConfigHelper::importConfiguration(const QString &_fileName, const
|
||||
|
||||
QVariantMap AWConfigHelper::readDataEngineConfiguration()
|
||||
{
|
||||
QString fileName = QStandardPaths::locate(QStandardPaths::ConfigLocation, "plasma-dataengine-extsysmon.conf");
|
||||
auto fileName = QStandardPaths::locate(QStandardPaths::ConfigLocation, "plasma-dataengine-extsysmon.conf");
|
||||
qCInfo(LOG_AW) << "Configuration file" << fileName;
|
||||
QSettings settings(fileName, QSettings::IniFormat);
|
||||
QVariantMap configuration;
|
||||
@ -186,8 +180,8 @@ bool AWConfigHelper::writeDataEngineConfiguration(const QVariantMap &_configurat
|
||||
{
|
||||
qCDebug(LOG_AW) << "Configuration" << _configuration;
|
||||
|
||||
QString fileName = QString("%1/plasma-dataengine-extsysmon.conf")
|
||||
.arg(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation));
|
||||
auto fileName = QString("%1/plasma-dataengine-extsysmon.conf")
|
||||
.arg(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation));
|
||||
QSettings settings(fileName, QSettings::IniFormat);
|
||||
qCInfo(LOG_AW) << "Configuration file" << settings.fileName();
|
||||
|
||||
@ -210,15 +204,15 @@ void AWConfigHelper::copyConfigs(const QString &_localDir)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Local directory" << _localDir;
|
||||
|
||||
QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, "awesomewidgets/configs",
|
||||
QStandardPaths::LocateDirectory);
|
||||
auto dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, "awesomewidgets/configs",
|
||||
QStandardPaths::LocateDirectory);
|
||||
for (auto &dir : dirs) {
|
||||
if (dir == _localDir)
|
||||
continue;
|
||||
QStringList files = QDir(dir).entryList(QDir::Files);
|
||||
auto files = QDir(dir).entryList(QDir::Files);
|
||||
for (auto &source : files) {
|
||||
QString destination = QString("%1/%2").arg(_localDir).arg(source);
|
||||
bool status = QFile::copy(QString("%1/%2").arg(dir).arg(source), destination);
|
||||
auto destination = QString("%1/%2").arg(_localDir, source);
|
||||
auto status = QFile::copy(QString("%1/%2").arg(dir, source), destination);
|
||||
qCInfo(LOG_AW) << "File" << source << "has been copied to" << destination << "with status" << status;
|
||||
}
|
||||
}
|
||||
@ -231,7 +225,7 @@ void AWConfigHelper::copyExtensions(const QString &_item, const QString &_type,
|
||||
qCDebug(LOG_AW) << "Extension" << _item << "has type" << _type << "inverse copying" << _inverse;
|
||||
|
||||
_settings.beginGroup(_item);
|
||||
QSettings itemSettings(QString("%1/%2/%3").arg(m_baseDir).arg(_type).arg(_item), QSettings::IniFormat);
|
||||
QSettings itemSettings(QString("%1/%2/%3").arg(m_baseDir, _type, _item), QSettings::IniFormat);
|
||||
itemSettings.beginGroup("Desktop Entry");
|
||||
if (_inverse)
|
||||
copySettings(_settings, itemSettings);
|
||||
@ -258,7 +252,7 @@ void AWConfigHelper::readFile(QSettings &_settings, const QString &_key, const Q
|
||||
|
||||
QFile file(_fileName);
|
||||
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
QString text = QString::fromUtf8(file.readAll());
|
||||
auto text = QString::fromUtf8(file.readAll());
|
||||
file.close();
|
||||
_settings.setValue(_key, text);
|
||||
} else {
|
||||
|
@ -29,7 +29,7 @@ class AWConfigHelper : public QObject
|
||||
|
||||
public:
|
||||
explicit AWConfigHelper(QObject *_parent = nullptr);
|
||||
~AWConfigHelper() override;
|
||||
~AWConfigHelper() override = default;
|
||||
Q_INVOKABLE [[nodiscard]] static QString configurationDirectory();
|
||||
Q_INVOKABLE static bool dropCache();
|
||||
Q_INVOKABLE bool exportConfiguration(QObject *_nativeConfig, const QString &_fileName) const;
|
||||
|
@ -29,9 +29,3 @@ AWCustomKeysConfig::AWCustomKeysConfig(QWidget *_parent, const QStringList &_key
|
||||
setEditable(true, false);
|
||||
initHelper<AWCustomKeysHelper>();
|
||||
}
|
||||
|
||||
|
||||
AWCustomKeysConfig::~AWCustomKeysConfig()
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
}
|
||||
|
@ -26,5 +26,5 @@ class AWCustomKeysConfig : public AWAbstractPairConfig
|
||||
|
||||
public:
|
||||
explicit AWCustomKeysConfig(QWidget *_parent = nullptr, const QStringList &_keys = QStringList());
|
||||
~AWCustomKeysConfig() override;
|
||||
~AWCustomKeysConfig() override = default;
|
||||
};
|
||||
|
@ -30,12 +30,6 @@ AWCustomKeysHelper::AWCustomKeysHelper(QObject *_parent)
|
||||
}
|
||||
|
||||
|
||||
AWCustomKeysHelper::~AWCustomKeysHelper()
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
}
|
||||
|
||||
|
||||
QString AWCustomKeysHelper::source(const QString &_key) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Get source by key" << _key;
|
||||
|
@ -28,7 +28,7 @@ class AWCustomKeysHelper : public QObject, public AWAbstractPairHelper
|
||||
|
||||
public:
|
||||
explicit AWCustomKeysHelper(QObject *_parent = nullptr);
|
||||
~AWCustomKeysHelper() override;
|
||||
~AWCustomKeysHelper() override = default;
|
||||
// get
|
||||
[[nodiscard]] QString source(const QString &_key) const;
|
||||
[[nodiscard]] QStringList sources() const;
|
||||
@ -37,6 +37,4 @@ public:
|
||||
void editPairs() override{};
|
||||
QStringList leftKeys() override;
|
||||
QStringList rightKeys() override;
|
||||
|
||||
private:
|
||||
};
|
||||
|
@ -84,26 +84,26 @@ void AWDataAggregator::setParameters(const QVariantMap &_settings)
|
||||
// resize tooltip image
|
||||
m_toolTipView->resize(100 * m_counts, 105);
|
||||
|
||||
requiredKeys.clear();
|
||||
m_requiredKeys.clear();
|
||||
if (m_configuration["cpuTooltip"].toBool())
|
||||
requiredKeys.append("cpuTooltip");
|
||||
m_requiredKeys.append("cpuTooltip");
|
||||
if (m_configuration["cpuclTooltip"].toBool())
|
||||
requiredKeys.append("cpuclTooltip");
|
||||
m_requiredKeys.append("cpuclTooltip");
|
||||
if (m_configuration["memTooltip"].toBool())
|
||||
requiredKeys.append("memTooltip");
|
||||
m_requiredKeys.append("memTooltip");
|
||||
if (m_configuration["swapTooltip"].toBool())
|
||||
requiredKeys.append("swapTooltip");
|
||||
m_requiredKeys.append("swapTooltip");
|
||||
if (m_configuration["downkbTooltip"].toBool())
|
||||
requiredKeys.append("downkbTooltip");
|
||||
m_requiredKeys.append("downkbTooltip");
|
||||
if (m_configuration["upkbTooltip"].toBool())
|
||||
requiredKeys.append("upkbTooltip");
|
||||
m_requiredKeys.append("upkbTooltip");
|
||||
if (m_configuration["batTooltip"].toBool())
|
||||
requiredKeys.append("batTooltip");
|
||||
m_requiredKeys.append("batTooltip");
|
||||
|
||||
// background
|
||||
m_toolTipScene->setBackgroundBrush(m_configuration["useTooltipBackground"].toBool()
|
||||
? QBrush(QColor(m_configuration["tooltipBackground"].toString()))
|
||||
: QBrush(Qt::NoBrush));
|
||||
? QColor(m_configuration["tooltipBackground"].toString())
|
||||
: Qt::NoBrush);
|
||||
}
|
||||
|
||||
|
||||
@ -112,34 +112,42 @@ QPixmap AWDataAggregator::tooltipImage()
|
||||
// create image
|
||||
m_toolTipScene->clear();
|
||||
QPen pen;
|
||||
bool down = false;
|
||||
for (auto &key : requiredKeys) {
|
||||
auto shift = 0.0;
|
||||
|
||||
for (auto i = 0; i < m_requiredKeys.count(); ++i) {
|
||||
auto key = m_requiredKeys[i];
|
||||
|
||||
// create frame
|
||||
float normX = 100.0f / static_cast<float>(m_values[key].count());
|
||||
float normY = 100.0f / (1.5f * m_boundaries[key]);
|
||||
float shift = static_cast<float>(requiredKeys.indexOf(key)) * 100.0f;
|
||||
if (down)
|
||||
shift -= 100.0;
|
||||
auto normX = 100.0 / static_cast<float>(m_values[key].count());
|
||||
auto normY = 100.0 / (1.5 * m_boundaries[key]);
|
||||
|
||||
// apply pen color
|
||||
if (key != "batTooltip")
|
||||
pen.setColor(QColor(m_configuration[QString("%1Color").arg(key)].toString()));
|
||||
pen.setColor(m_configuration[QString("%1Color").arg(key)].toString());
|
||||
|
||||
// paint data inside frame
|
||||
for (int j = 0; j < m_values[key].count() - 1; j++) {
|
||||
// some magic here
|
||||
float x1 = j * normX + shift;
|
||||
float y1 = -std::fabs(m_values[key].at(j)) * normY + 5.0f;
|
||||
float x2 = (j + 1) * normX + shift;
|
||||
float y2 = -std::fabs(m_values[key].at(j + 1)) * normY + 5.0f;
|
||||
auto x1 = j * normX + shift;
|
||||
auto y1 = -std::fabs(m_values[key].at(j)) * normY + 5.0;
|
||||
auto x2 = (j + 1) * normX + shift;
|
||||
auto y2 = -std::fabs(m_values[key].at(j + 1)) * normY + 5.0;
|
||||
// apply color for the battery tooltip based on charge/discharge
|
||||
if (key == "batTooltip") {
|
||||
if (m_values[key].at(j + 1) > 0)
|
||||
pen.setColor(QColor(m_configuration["batTooltipColor"].toString()));
|
||||
else
|
||||
pen.setColor(QColor(m_configuration["batInTooltipColor"].toString()));
|
||||
}
|
||||
|
||||
m_toolTipScene->addLine(x1, y1, x2, y2, pen);
|
||||
}
|
||||
if (key == "downkbTooltip")
|
||||
down = true;
|
||||
|
||||
// increase frame shift if not downkbtooltip
|
||||
// Additional workaround is required because there is frame (uokb and downkb) which contains two charts
|
||||
// with the same shift
|
||||
if (key != "downkbTooltip")
|
||||
shift += 100.0;
|
||||
}
|
||||
|
||||
return m_toolTipView->grab();
|
||||
@ -154,7 +162,7 @@ void AWDataAggregator::dataUpdate(const QVariantHash &_values)
|
||||
}
|
||||
|
||||
|
||||
void AWDataAggregator::checkValue(const QString &_source, const float _value, const float _extremum) const
|
||||
void AWDataAggregator::checkValue(const QString &_source, const double _value, const double _extremum) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Notification source" << _source << "with value" << _value << "called with extremum"
|
||||
<< _extremum;
|
||||
@ -227,25 +235,27 @@ void AWDataAggregator::setData(const QVariantHash &_values)
|
||||
{
|
||||
// do not log these arguments
|
||||
// battery update requires info is AC online or not
|
||||
setData(_values["ac"].toString() == m_configuration["acOnline"], "batTooltip", _values["bat"].toFloat());
|
||||
setData(_values["ac"].toString() == m_configuration["acOnline"], "batTooltip", _values["bat"].toDouble());
|
||||
|
||||
// usual case
|
||||
setData("cpuTooltip", _values["cpu"].toFloat(), 90.0);
|
||||
setData("cpuclTooltip", _values["cpucl"].toFloat());
|
||||
setData("memTooltip", _values["mem"].toFloat(), 80.0);
|
||||
setData("swapTooltip", _values["swap"].toFloat(), 0.0);
|
||||
setData("downkbTooltip", _values["downkb"].toFloat());
|
||||
setData("upkbTooltip", _values["upkb"].toFloat());
|
||||
setData("cpuTooltip", _values["cpu"].toDouble(), 90.0);
|
||||
setData("cpuclTooltip", _values["cpucl"].toDouble());
|
||||
setData("memTooltip", _values["mem"].toDouble(), 80.0);
|
||||
setData("swapTooltip", _values["swap"].toDouble(), 0.0);
|
||||
setData("downkbTooltip", _values["downkb"].toDouble());
|
||||
setData("upkbTooltip", _values["upkb"].toDouble());
|
||||
|
||||
// additional check for network device
|
||||
[this](const QString &value) {
|
||||
checkValue("netdev", m_currentNetworkDevice, value);
|
||||
m_currentNetworkDevice = value;
|
||||
}(_values["netdev"].toString());
|
||||
auto currentNetworkDevice = _values["netdev"].toString();
|
||||
checkValue("netdev", m_currentNetworkDevice, currentNetworkDevice);
|
||||
m_currentNetworkDevice = currentNetworkDevice;
|
||||
|
||||
// additional check for GPU load
|
||||
[this](const float value) { checkValue("gpu", value, 90.0); }(_values["gpu"].toFloat());
|
||||
checkValue("gpu", _values["gpu"].toDouble(), 90.0);
|
||||
}
|
||||
|
||||
|
||||
void AWDataAggregator::setData(const QString &_source, float _value, const float _extremum)
|
||||
void AWDataAggregator::setData(const QString &_source, double _value, const double _extremum)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Source" << _source << "to value" << _value << "with extremum" << _extremum;
|
||||
|
||||
@ -261,16 +271,20 @@ void AWDataAggregator::setData(const QString &_source, float _value, const float
|
||||
|
||||
m_values[_source].append(_value);
|
||||
if (_source == "downkbTooltip") {
|
||||
QList<float> netValues = m_values["downkbTooltip"] + m_values["upkbTooltip"];
|
||||
// to avoid inf value of normY
|
||||
netValues << 1.0;
|
||||
m_boundaries["downkbTooltip"] = 1.2f * *std::max_element(netValues.cbegin(), netValues.cend());
|
||||
m_boundaries["upkbTooltip"] = m_boundaries["downkbTooltip"];
|
||||
// to avoid copying of objects to another list we find max elements in each sequence and compare them
|
||||
auto downMax = m_values["downkbTooltip"].empty()
|
||||
? 1.0
|
||||
: *std::max_element(m_values["downkbTooltip"].cbegin(), m_values["downkbTooltip"].cend());
|
||||
auto upMax = m_values["upkbTooltip"].empty()
|
||||
? 1.0
|
||||
: *std::max_element(m_values["upkbTooltip"].cbegin(), m_values["upkbTooltip"].cend());
|
||||
// assign both
|
||||
m_boundaries["upkbTooltip"] = m_boundaries["downkbTooltip"] = 1.2 * std::max(downMax, upMax);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AWDataAggregator::setData(const bool _dontInvert, const QString &_source, float _value)
|
||||
void AWDataAggregator::setData(const bool _dontInvert, const QString &_source, double _value)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Do not invert" << _dontInvert << "value" << _value << "for source" << _source;
|
||||
|
||||
|
@ -47,22 +47,22 @@ private:
|
||||
// ui
|
||||
QGraphicsScene *m_toolTipScene = nullptr;
|
||||
QGraphicsView *m_toolTipView = nullptr;
|
||||
void checkValue(const QString &_source, float _value, float _extremum) const;
|
||||
void checkValue(const QString &_source, double _value, double _extremum) const;
|
||||
void checkValue(const QString &_source, const QString &_current, const QString &_received) const;
|
||||
void initScene();
|
||||
static QString notificationText(const QString &_source, float _value);
|
||||
static QString notificationText(const QString &_source, const QString &_value);
|
||||
// main method
|
||||
void setData(const QVariantHash &_values);
|
||||
void setData(const QString &_source, float _value, float _extremum = -1.0f);
|
||||
void setData(const QString &_source, double _value, double _extremum = -1.0);
|
||||
// different signature for battery device
|
||||
void setData(bool _dontInvert, const QString &_source, float _value);
|
||||
void setData(bool _dontInvert, const QString &_source, double _value);
|
||||
// variables
|
||||
int m_counts = 0;
|
||||
QVariantHash m_configuration;
|
||||
QString m_currentNetworkDevice = "lo";
|
||||
QHash<QString, float> m_boundaries;
|
||||
QHash<QString, QList<float>> m_values;
|
||||
QHash<QString, double> m_boundaries;
|
||||
QHash<QString, QList<double>> m_values;
|
||||
bool m_enablePopup = false;
|
||||
QStringList requiredKeys;
|
||||
QStringList m_requiredKeys;
|
||||
};
|
||||
|
@ -52,12 +52,6 @@ AWDataEngineMapper::AWDataEngineMapper(QObject *_parent, AWFormatterHelper *_cus
|
||||
}
|
||||
|
||||
|
||||
AWDataEngineMapper::~AWDataEngineMapper()
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
}
|
||||
|
||||
|
||||
AWKeysAggregator::FormatterType AWDataEngineMapper::formatter(const QString &_key) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Get formatter for key" << _key;
|
||||
@ -82,18 +76,18 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const KSy
|
||||
qCDebug(LOG_AW) << "Source" << _source << "with units" << _units;
|
||||
|
||||
// regular expressions
|
||||
auto cpuRegExp = QRegularExpression("^cpu/cpu.*/usage$");
|
||||
auto cpuclRegExp = QRegularExpression("^cpu/cpu.*/frequency$");
|
||||
auto cpuTempRegExp = QRegularExpression("^cpu/cpu.*/temperature$");
|
||||
auto gpuRegExp = QRegularExpression("^gpu/gpu.*/usage$");
|
||||
auto gpuTempRegExp = QRegularExpression("^gpu/gpu.*/temperature$");
|
||||
auto hddrRegExp = QRegularExpression("^disk/.*/read$");
|
||||
auto hddwRegExp = QRegularExpression("^disk/.*/write$");
|
||||
auto mountFillRegExp = QRegularExpression("^disk/.*/usedPercent$");
|
||||
auto mountFreeRegExp = QRegularExpression("^disk/.*/free$");
|
||||
auto mountUsedRegExp = QRegularExpression("^disk/.*/used$");
|
||||
auto netRegExp = QRegularExpression("^network/.*/(download|upload)$");
|
||||
auto netTotalRegExp = QRegularExpression("^network/.*/(totalDownload|totalUpload)$");
|
||||
static auto cpuRegExp = QRegularExpression("^cpu/cpu.*/usage$");
|
||||
static auto cpuclRegExp = QRegularExpression("^cpu/cpu.*/frequency$");
|
||||
static auto cpuTempRegExp = QRegularExpression("^cpu/cpu.*/temperature$");
|
||||
static auto gpuRegExp = QRegularExpression("^gpu/gpu.*/usage$");
|
||||
static auto gpuTempRegExp = QRegularExpression("^gpu/gpu.*/temperature$");
|
||||
static auto hddrRegExp = QRegularExpression("^disk/.*/read$");
|
||||
static auto hddwRegExp = QRegularExpression("^disk/.*/write$");
|
||||
static auto mountFillRegExp = QRegularExpression("^disk/.*/usedPercent$");
|
||||
static auto mountFreeRegExp = QRegularExpression("^disk/.*/free$");
|
||||
static auto mountUsedRegExp = QRegularExpression("^disk/.*/used$");
|
||||
static auto netRegExp = QRegularExpression("^network/.*/(download|upload)$");
|
||||
static auto netTotalRegExp = QRegularExpression("^network/.*/(totalDownload|totalUpload)$");
|
||||
|
||||
if (_source == "extsysmon/battery/ac") {
|
||||
// AC
|
||||
@ -209,7 +203,7 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const KSy
|
||||
auto index = m_devices["mount"].indexOf(device);
|
||||
if (index > -1) {
|
||||
// mb
|
||||
QString key = QString("hddfreemb%1").arg(index);
|
||||
auto key = QString("hddfreemb%1").arg(index);
|
||||
m_map.insert(_source, key);
|
||||
m_formatter[key] = AWKeysAggregator::FormatterType::MemMBFormat;
|
||||
// gb
|
||||
@ -224,7 +218,7 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const KSy
|
||||
auto index = m_devices["mount"].indexOf(device);
|
||||
if (index > -1) {
|
||||
// mb
|
||||
QString key = QString("hddmb%1").arg(index);
|
||||
auto key = QString("hddmb%1").arg(index);
|
||||
m_map.insert(_source, key);
|
||||
m_formatter[key] = AWKeysAggregator::FormatterType::MemMBFormat;
|
||||
// gb
|
||||
@ -435,7 +429,7 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const KSy
|
||||
|
||||
// drop key from dictionary if no one user requested key required it
|
||||
qCInfo(LOG_AW) << "Looking for keys" << foundKeys << "in" << _keys;
|
||||
auto required = _keys.isEmpty() || std::any_of(foundKeys.cbegin(), foundKeys.cend(), [&_keys](const QString &key) {
|
||||
auto required = _keys.isEmpty() || std::any_of(foundKeys.cbegin(), foundKeys.cend(), [&_keys](auto &key) {
|
||||
return _keys.contains(key);
|
||||
});
|
||||
if (!required) {
|
||||
|
@ -33,7 +33,7 @@ class AWDataEngineMapper : public QObject
|
||||
|
||||
public:
|
||||
explicit AWDataEngineMapper(QObject *_parent = nullptr, AWFormatterHelper *_custom = nullptr);
|
||||
~AWDataEngineMapper() override;
|
||||
~AWDataEngineMapper() override = default;
|
||||
// get methods
|
||||
[[nodiscard]] AWKeysAggregator::FormatterType formatter(const QString &_key) const;
|
||||
[[nodiscard]] QStringList keysFromSource(const QString &_source) const;
|
||||
|
@ -32,27 +32,20 @@ AWDBusAdaptor::AWDBusAdaptor(AWKeys *_parent)
|
||||
}
|
||||
|
||||
|
||||
AWDBusAdaptor::~AWDBusAdaptor()
|
||||
{
|
||||
qCDebug(LOG_DBUS) << __PRETTY_FUNCTION__;
|
||||
}
|
||||
|
||||
|
||||
QStringList AWDBusAdaptor::ActiveServices()
|
||||
{
|
||||
QDBusMessage listServices = QDBusConnection::sessionBus().interface()->call(QDBus::BlockWithGui, "ListNames");
|
||||
auto listServices = QDBusConnection::sessionBus().interface()->call(QDBus::BlockWithGui, "ListNames");
|
||||
if (listServices.arguments().isEmpty()) {
|
||||
qCWarning(LOG_DBUS) << "Could not find any DBus service";
|
||||
return {};
|
||||
}
|
||||
QStringList arguments = listServices.arguments().first().toStringList();
|
||||
auto arguments = listServices.arguments().first().toStringList();
|
||||
|
||||
return std::accumulate(arguments.cbegin(), arguments.cend(), QStringList(),
|
||||
[](QStringList source, const QString &service) {
|
||||
if (service.startsWith(AWDBUS_SERVICE))
|
||||
source.append(service);
|
||||
return source;
|
||||
});
|
||||
return std::accumulate(arguments.cbegin(), arguments.cend(), QStringList(), [](auto source, auto &service) {
|
||||
if (service.startsWith(AWDBUS_SERVICE))
|
||||
source.append(service);
|
||||
return source;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -103,6 +96,6 @@ void AWDBusAdaptor::SetLogLevel(const QString &what, const QString &level, const
|
||||
return;
|
||||
}
|
||||
|
||||
QString state = enabled ? "true" : "false";
|
||||
QLoggingCategory::setFilterRules(QString("%1.%2=%3").arg(what).arg(level).arg(state));
|
||||
auto state = enabled ? "true" : "false";
|
||||
QLoggingCategory::setFilterRules(QString("%1.%2=%3").arg(what, level, state));
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ class AWDBusAdaptor : public QDBusAbstractAdaptor
|
||||
|
||||
public:
|
||||
explicit AWDBusAdaptor(AWKeys *_parent = nullptr);
|
||||
~AWDBusAdaptor() override;
|
||||
~AWDBusAdaptor() override = default;
|
||||
|
||||
public slots:
|
||||
// get methods
|
||||
|
@ -29,9 +29,3 @@ AWFormatterConfig::AWFormatterConfig(QWidget *_parent, const QStringList &_keys)
|
||||
setEditable(false, false);
|
||||
initHelper<AWFormatterHelper>();
|
||||
}
|
||||
|
||||
|
||||
AWFormatterConfig::~AWFormatterConfig()
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
}
|
||||
|
@ -26,5 +26,5 @@ class AWFormatterConfig : public AWAbstractPairConfig
|
||||
|
||||
public:
|
||||
explicit AWFormatterConfig(QWidget *_parent = nullptr, const QStringList &_keys = QStringList());
|
||||
~AWFormatterConfig() override;
|
||||
~AWFormatterConfig() override = default;
|
||||
};
|
||||
|
@ -58,8 +58,7 @@ void AWFormatterHelper::initItems()
|
||||
|
||||
// assign internal storage
|
||||
m_formatters.clear();
|
||||
for (auto &key : pairs().keys()) {
|
||||
auto name = pairs()[key];
|
||||
for (auto [key, name] : pairs().asKeyValueRange()) {
|
||||
if (!m_formattersClasses.contains(name)) {
|
||||
qCWarning(LOG_AW) << "Invalid formatter" << name << "found in" << key;
|
||||
continue;
|
||||
@ -87,7 +86,7 @@ QStringList AWFormatterHelper::definedFormatters() const
|
||||
QList<AbstractExtItem *> AWFormatterHelper::items() const
|
||||
{
|
||||
QList<AbstractExtItem *> converted;
|
||||
for (auto &item : m_formattersClasses.values())
|
||||
for (auto item : m_formattersClasses.values())
|
||||
converted.append(item);
|
||||
|
||||
return converted;
|
||||
@ -123,7 +122,7 @@ AWAbstractFormatter::FormatterClass AWFormatterHelper::defineFormatterClass(cons
|
||||
{
|
||||
qCDebug(LOG_AW) << "Define formatter class for" << _stringType;
|
||||
|
||||
AWAbstractFormatter::FormatterClass formatter = AWAbstractFormatter::FormatterClass::NoFormat;
|
||||
auto formatter = AWAbstractFormatter::FormatterClass::NoFormat;
|
||||
if (_stringType == "DateTime")
|
||||
formatter = AWAbstractFormatter::FormatterClass::DateTime;
|
||||
else if (_stringType == "Float")
|
||||
@ -151,17 +150,17 @@ void AWFormatterHelper::initFormatters()
|
||||
|
||||
auto dirs = directories();
|
||||
for (auto &dir : dirs) {
|
||||
QStringList files = QDir(dir).entryList(QDir::Files, QDir::Name);
|
||||
auto files = QDir(dir).entryList(QDir::Files, QDir::Name);
|
||||
for (auto &file : files) {
|
||||
// check filename
|
||||
if (!file.endsWith(".desktop"))
|
||||
continue;
|
||||
qCInfo(LOG_AW) << "Found file" << file << "in" << dir;
|
||||
QString filePath = QString("%1/%2").arg(dir).arg(file);
|
||||
auto filePath = QString("%1/%2").arg(dir, file);
|
||||
// check if already exists
|
||||
auto values = m_formattersClasses.values();
|
||||
if (std::any_of(values.cbegin(), values.cend(),
|
||||
[&filePath](const AWAbstractFormatter *item) { return (item->filePath() == filePath); }))
|
||||
[&filePath](auto item) { return (item->filePath() == filePath); }))
|
||||
continue;
|
||||
|
||||
auto metadata = readMetadata(filePath);
|
||||
@ -198,13 +197,14 @@ QPair<QString, AWAbstractFormatter::FormatterClass> AWFormatterHelper::readMetad
|
||||
qCDebug(LOG_AW) << "Read initial parameters from" << _filePath;
|
||||
|
||||
QSettings settings(_filePath, QSettings::IniFormat);
|
||||
|
||||
settings.beginGroup("Desktop Entry");
|
||||
auto name = settings.value("Name", _filePath).toString();
|
||||
auto type = settings.value("X-AW-Type", "NoFormat").toString();
|
||||
auto formatter = defineFormatterClass(type);
|
||||
settings.endGroup();
|
||||
|
||||
return QPair<QString, AWAbstractFormatter::FormatterClass>(name, formatter);
|
||||
return {name, formatter};
|
||||
}
|
||||
|
||||
|
||||
@ -219,7 +219,7 @@ void AWFormatterHelper::doCreateItem(QListWidget *_widget)
|
||||
}
|
||||
|
||||
qCInfo(LOG_AW) << "Selected type" << select;
|
||||
AWAbstractFormatter::FormatterClass formatter = defineFormatterClass(select);
|
||||
auto formatter = defineFormatterClass(select);
|
||||
switch (formatter) {
|
||||
case AWAbstractFormatter::FormatterClass::DateTime:
|
||||
return createItem<AWDateTimeFormatter>(_widget);
|
||||
|
@ -44,7 +44,7 @@ bool AWKeyCache::addKeyToCache(const QString &_type, const QString &_key)
|
||||
if (_type == "net") {
|
||||
auto rawInterfaceList = QNetworkInterface::allInterfaces();
|
||||
for (auto &interface : rawInterfaceList) {
|
||||
QString device = interface.name();
|
||||
auto device = interface.name();
|
||||
if (cachedValues.contains(device))
|
||||
continue;
|
||||
qCInfo(LOG_AW) << "Found new key" << device << "for type" << _type;
|
||||
@ -74,10 +74,11 @@ QStringList AWKeyCache::getRequiredKeys(const QStringList &_keys, const QStringL
|
||||
used.unite(QSet(_bars.cbegin(), _bars.cend()));
|
||||
used.unite(QSet(_userKeys.cbegin(), _userKeys.cend()));
|
||||
// insert keys from tooltip
|
||||
for (auto &key : _tooltip.keys()) {
|
||||
if ((key.endsWith("Tooltip")) && (_tooltip[key].toBool())) {
|
||||
key.remove("Tooltip");
|
||||
used << key;
|
||||
for (auto [key, value] : _tooltip.asKeyValueRange()) {
|
||||
if ((key.endsWith("Tooltip")) && value.toBool()) {
|
||||
auto local = key;
|
||||
local.remove("Tooltip");
|
||||
used << local;
|
||||
}
|
||||
}
|
||||
|
||||
@ -133,7 +134,7 @@ QStringList AWKeyCache::getRequiredKeys(const QStringList &_keys, const QStringL
|
||||
used << filtered;
|
||||
}
|
||||
// netdev key
|
||||
if (std::any_of(netKeys.cbegin(), netKeys.cend(), [&used](const QString &key) { return used.contains(key); }))
|
||||
if (std::any_of(netKeys.cbegin(), netKeys.cend(), [&used](auto &key) { return used.contains(key); }))
|
||||
used << "netdev";
|
||||
|
||||
// HACK append dummy if there are no other keys. This hack is required
|
||||
|
@ -49,12 +49,6 @@ AWKeyOperations::AWKeyOperations(QObject *_parent)
|
||||
}
|
||||
|
||||
|
||||
AWKeyOperations::~AWKeyOperations()
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
}
|
||||
|
||||
|
||||
QStringList AWKeyOperations::devices(const QString &_type) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Looking for type" << _type;
|
||||
@ -89,20 +83,20 @@ QStringList AWKeyOperations::dictKeys() const
|
||||
allKeys.append(item->tag("timestamp"));
|
||||
}
|
||||
// cpuclock & cpu
|
||||
for (auto i = 0; i < QThread::idealThreadCount(); i++) {
|
||||
for (auto i = 0; i < QThread::idealThreadCount(); ++i) {
|
||||
allKeys.append(QString("cpucl%1").arg(i));
|
||||
allKeys.append(QString("cpu%1").arg(i));
|
||||
}
|
||||
// temperature
|
||||
for (auto i = 0; i < m_devices["temp"].count(); i++)
|
||||
for (auto i = 0; i < m_devices["temp"].count(); ++i)
|
||||
allKeys.append(QString("temp%1").arg(i));
|
||||
// gpu
|
||||
for (auto i = 0; i < m_devices["gpu"].count(); i++) {
|
||||
for (auto i = 0; i < m_devices["gpu"].count(); ++i) {
|
||||
allKeys.append(QString("gpu%1").arg(i));
|
||||
allKeys.append(QString("gputemp%1").arg(i));
|
||||
}
|
||||
// hdd
|
||||
for (auto i = 0; i < m_devices["mount"].count(); i++) {
|
||||
for (auto i = 0; i < m_devices["mount"].count(); ++i) {
|
||||
allKeys.append(QString("hddmb%1").arg(i));
|
||||
allKeys.append(QString("hddgb%1").arg(i));
|
||||
allKeys.append(QString("hddfreemb%1").arg(i));
|
||||
@ -112,12 +106,12 @@ QStringList AWKeyOperations::dictKeys() const
|
||||
allKeys.append(QString("hdd%1").arg(i));
|
||||
}
|
||||
// hdd speed
|
||||
for (auto i = 0; i < m_devices["disk"].count(); i++) {
|
||||
for (auto i = 0; i < m_devices["disk"].count(); ++i) {
|
||||
allKeys.append(QString("hddr%1").arg(i));
|
||||
allKeys.append(QString("hddw%1").arg(i));
|
||||
}
|
||||
// network
|
||||
for (auto i = 0; i < m_devices["net"].count(); i++) {
|
||||
for (auto i = 0; i < m_devices["net"].count(); ++i) {
|
||||
allKeys.append(QString("downunits%1").arg(i));
|
||||
allKeys.append(QString("upunits%1").arg(i));
|
||||
allKeys.append(QString("downtotkb%1").arg(i));
|
||||
@ -132,7 +126,7 @@ QStringList AWKeyOperations::dictKeys() const
|
||||
// battery
|
||||
auto allBatteryDevices = QDir("/sys/class/power_supply")
|
||||
.entryList(QStringList({"BAT*"}), QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name);
|
||||
for (int i = 0; i < allBatteryDevices.count(); i++) {
|
||||
for (int i = 0; i < allBatteryDevices.count(); ++i) {
|
||||
allKeys.append(QString("bat%1").arg(i));
|
||||
allKeys.append(QString("batleft%1").arg(i));
|
||||
allKeys.append(QString("batnow%1").arg(i));
|
||||
@ -205,10 +199,20 @@ QString AWKeyOperations::infoByKey(const QString &_key) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Requested key" << _key;
|
||||
|
||||
static auto numberRegExp = QRegularExpression("\\d+");
|
||||
|
||||
auto stripped = _key;
|
||||
stripped.remove(QRegularExpression("\\d+"));
|
||||
stripped.remove(numberRegExp);
|
||||
QString output;
|
||||
|
||||
static auto hddRegExp = QRegularExpression("^hdd(|mb|gb|freemb|freegb|totmb|totgb)");
|
||||
static auto hddrwRegExp = QRegularExpression("^hdd[rw]");
|
||||
static auto hddMatchRegExp = QRegularExpression("^hdd([0-9]|mb|gb|freemb|freegb|totmb|totgb)");
|
||||
static auto netRegExp = QRegularExpression("^(down|up)");
|
||||
static auto netMatchRegExp = QRegularExpression("^(down|up)[0-9]");
|
||||
static auto quotesRegExp = QRegularExpression("^(|perc)(ask|bid|price)(chg|)");
|
||||
static auto weatherRegExp = QRegularExpression("^(weather|weatherId|humidity|pressure|temperature)");
|
||||
|
||||
if (_key.startsWith("bar")) {
|
||||
auto item = m_graphicalItems->itemByTag(_key, stripped);
|
||||
if (item)
|
||||
@ -217,27 +221,27 @@ QString AWKeyOperations::infoByKey(const QString &_key) const
|
||||
auto item = m_extScripts->itemByTag(_key, stripped);
|
||||
if (item)
|
||||
output = item->uniq();
|
||||
} else if (_key.contains(QRegularExpression("^hdd[rw]"))) {
|
||||
} else if (_key.contains(hddrwRegExp)) {
|
||||
auto index = _key;
|
||||
index.remove(QRegularExpression("hdd[rw]"));
|
||||
index.remove(hddrwRegExp);
|
||||
output = m_devices["disk"][index.toInt()];
|
||||
} else if (_key.contains(QRegularExpression("^hdd([0-9]|mb|gb|freemb|freegb|totmb|totgb)"))) {
|
||||
} else if (_key.contains(hddMatchRegExp)) {
|
||||
auto index = _key;
|
||||
index.remove(QRegularExpression("^hdd(|mb|gb|freemb|freegb|totmb|totgb)"));
|
||||
index.remove(hddRegExp);
|
||||
output = m_devices["mount"][index.toInt()];
|
||||
} else if (_key.contains(QRegularExpression("^(down|up)[0-9]"))) {
|
||||
} else if (_key.contains(netMatchRegExp)) {
|
||||
auto index = _key;
|
||||
index.remove(QRegularExpression("^(down|up)"));
|
||||
index.remove(netRegExp);
|
||||
output = m_devices["net"][index.toInt()];
|
||||
} else if (_key.startsWith("pkgcount")) {
|
||||
auto item = m_extUpgrade->itemByTag(_key, stripped);
|
||||
if (item)
|
||||
output = item->uniq();
|
||||
} else if (_key.contains(QRegularExpression("(^|perc)(ask|bid|price)(chg|)"))) {
|
||||
} else if (_key.contains(quotesRegExp)) {
|
||||
auto item = m_extQuotes->itemByTag(_key, stripped);
|
||||
if (item)
|
||||
output = item->uniq();
|
||||
} else if (_key.contains(QRegularExpression("(weather|weatherId|humidity|pressure|temperature)"))) {
|
||||
} else if (_key.contains(weatherRegExp)) {
|
||||
auto item = m_extWeather->itemByTag(_key, stripped);
|
||||
if (item)
|
||||
output = item->uniq();
|
||||
@ -275,8 +279,10 @@ void AWKeyOperations::editItem(const QString &_type)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Item type" << _type;
|
||||
|
||||
static auto supportsGraphicalRegExp = QRegularExpression("^(cpu(?!cl).*|gpu$|mem$|swap$|hdd[0-9].*|bat.*)");
|
||||
|
||||
if (_type == "graphicalitem") {
|
||||
QStringList keys = dictKeys().filter(QRegularExpression("^(cpu(?!cl).*|gpu$|mem$|swap$|hdd[0-9].*|bat.*)"));
|
||||
auto keys = dictKeys().filter(supportsGraphicalRegExp);
|
||||
keys.sort();
|
||||
m_graphicalItems->setConfigArgs(keys);
|
||||
return m_graphicalItems->editItems();
|
||||
@ -298,10 +304,10 @@ void AWKeyOperations::addDevice(const QString &_source)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Source" << _source;
|
||||
|
||||
auto diskRegexp = QRegularExpression("^disk/.*/read$");
|
||||
auto mountRegexp = QRegularExpression("^disk/.*/usedPercent$");
|
||||
auto cpuTempRegExp = QRegularExpression("^cpu/cpu.*/temperature$");
|
||||
auto gpuRegExp = QRegularExpression("^gpu/gpu.*/usage$");
|
||||
static auto diskRegexp = QRegularExpression("^disk/.*/read$");
|
||||
static auto mountRegexp = QRegularExpression("^disk/.*/usedPercent$");
|
||||
static auto cpuTempRegExp = QRegularExpression("^cpu/cpu.*/temperature$");
|
||||
static auto gpuRegExp = QRegularExpression("^gpu/gpu.*/usage$");
|
||||
|
||||
if (_source.contains(diskRegexp)) {
|
||||
auto device = _source;
|
||||
@ -344,7 +350,7 @@ void AWKeyOperations::reinitKeys()
|
||||
m_extWeather->initItems();
|
||||
|
||||
// init
|
||||
QStringList allKeys = dictKeys();
|
||||
auto allKeys = dictKeys();
|
||||
|
||||
// apply aw_* functions
|
||||
m_pattern = AWPatternFunctions::insertAllKeys(m_pattern, allKeys);
|
||||
|
@ -37,7 +37,7 @@ class AWKeyOperations : public QObject
|
||||
|
||||
public:
|
||||
explicit AWKeyOperations(QObject *_parent = nullptr);
|
||||
~AWKeyOperations() override;
|
||||
~AWKeyOperations() override = default;
|
||||
[[nodiscard]] QStringList devices(const QString &_type) const;
|
||||
[[nodiscard]] QHash<QString, QStringList> devices() const;
|
||||
void updateCache();
|
||||
|
@ -43,12 +43,6 @@ AWKeysAggregator::AWKeysAggregator(QObject *_parent)
|
||||
}
|
||||
|
||||
|
||||
AWKeysAggregator::~AWKeysAggregator()
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
}
|
||||
|
||||
|
||||
void AWKeysAggregator::initFormatters()
|
||||
{
|
||||
m_customFormatters->initItems();
|
||||
@ -140,17 +134,19 @@ QString AWKeysAggregator::formatter(const QVariant &_data, const QString &_key,
|
||||
case FormatterType::Uptime:
|
||||
case FormatterType::UptimeCustom:
|
||||
output =
|
||||
[](QString source, const int uptime) {
|
||||
int seconds = uptime - uptime % 60;
|
||||
int minutes = seconds / 60 % 60;
|
||||
int hours = ((seconds / 60) - minutes) / 60 % 24;
|
||||
int days = (((seconds / 60) - minutes) / 60 - hours) / 24;
|
||||
[](auto source, auto uptime) {
|
||||
auto seconds = uptime - uptime % 60;
|
||||
auto minutes = seconds / 60 % 60;
|
||||
auto hours = ((seconds / 60) - minutes) / 60 % 24;
|
||||
auto days = (((seconds / 60) - minutes) / 60 - hours) / 24;
|
||||
|
||||
source.replace("$dd", QString("%1").arg(days, 3, 10, QChar('0')));
|
||||
source.replace("$d", QString("%1").arg(days));
|
||||
source.replace("$hh", QString("%1").arg(hours, 2, 10, QChar('0')));
|
||||
source.replace("$h", QString("%1").arg(hours));
|
||||
source.replace("$mm", QString("%1").arg(minutes, 2, 10, QChar('0')));
|
||||
source.replace("$m", QString("%1").arg(minutes));
|
||||
|
||||
return source;
|
||||
}(m_mapper->formatter(_key) == FormatterType::Uptime ? "$ddd$hhh$mmm" : m_customUptime,
|
||||
static_cast<int>(_data.toDouble()));
|
||||
|
@ -71,7 +71,7 @@ public:
|
||||
static constexpr double GBinBytes = 1024.0 * MBinBytes;
|
||||
|
||||
explicit AWKeysAggregator(QObject *_parent = nullptr);
|
||||
~AWKeysAggregator() override;
|
||||
~AWKeysAggregator() override = default;
|
||||
void initFormatters();
|
||||
// get methods
|
||||
[[nodiscard]] QString formatter(const QVariant &_data, const QString &_key, bool replaceSpace) const;
|
||||
|
@ -29,12 +29,6 @@ AWPairConfigFactory::AWPairConfigFactory(QObject *_parent)
|
||||
}
|
||||
|
||||
|
||||
AWPairConfigFactory::~AWPairConfigFactory()
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
}
|
||||
|
||||
|
||||
void AWPairConfigFactory::showFormatterDialog(const QStringList &_keys)
|
||||
{
|
||||
auto config = new AWFormatterConfig(nullptr, _keys);
|
||||
|
@ -26,7 +26,7 @@ class AWPairConfigFactory : public QObject
|
||||
|
||||
public:
|
||||
explicit AWPairConfigFactory(QObject *_parent = nullptr);
|
||||
~AWPairConfigFactory() override;
|
||||
~AWPairConfigFactory() override = default;
|
||||
Q_INVOKABLE static void showFormatterDialog(const QStringList &_keys);
|
||||
Q_INVOKABLE static void showKeysDialog(const QStringList &_keys);
|
||||
|
||||
|
@ -36,7 +36,7 @@ QString AWPatternFunctions::expandLambdas(QString _code, AWKeysAggregator *_aggr
|
||||
for (auto &lambdaKey : _usedKeys)
|
||||
_code.replace(QString("$%1").arg(lambdaKey), _aggregator->formatter(_metadata[lambdaKey], lambdaKey, false));
|
||||
qCInfo(LOG_AW) << "Expression" << _code;
|
||||
QJSValue result = engine.evaluate(_code);
|
||||
auto result = engine.evaluate(_code);
|
||||
if (result.isError()) {
|
||||
qCWarning(LOG_AW) << "Uncaught exception at line" << result.property("lineNumber").toInt() << ":"
|
||||
<< result.toString();
|
||||
@ -52,17 +52,17 @@ QString AWPatternFunctions::expandTemplates(QString _code)
|
||||
qCDebug(LOG_AW) << "Expand templates in" << _code;
|
||||
|
||||
// match the following construction $template{{some code here}}
|
||||
QRegularExpression templatesRegexp(R"(\$template\{\{(?<body>.*?)\}\})");
|
||||
static QRegularExpression templatesRegexp(R"(\$template\{\{(?<body>.*?)\}\})");
|
||||
templatesRegexp.setPatternOptions(QRegularExpression::DotMatchesEverythingOption);
|
||||
|
||||
QRegularExpressionMatchIterator it = templatesRegexp.globalMatch(_code);
|
||||
auto it = templatesRegexp.globalMatch(_code);
|
||||
while (it.hasNext()) {
|
||||
QRegularExpressionMatch match = it.next();
|
||||
QString body = match.captured("body");
|
||||
auto match = it.next();
|
||||
auto body = match.captured("body");
|
||||
|
||||
QJSEngine engine;
|
||||
qCInfo(LOG_AW) << "Expression" << body;
|
||||
QJSValue result = engine.evaluate(body);
|
||||
auto result = engine.evaluate(body);
|
||||
QString templateResult = "";
|
||||
if (result.isError()) {
|
||||
qCWarning(LOG_AW) << "Uncaught exception at line" << result.property("lineNumber").toInt() << ":"
|
||||
@ -94,20 +94,20 @@ QList<AWPatternFunctions::AWFunction> AWPatternFunctions::findFunctionCalls(cons
|
||||
regex.setPatternOptions(QRegularExpression::DotMatchesEverythingOption);
|
||||
|
||||
QList<AWPatternFunctions::AWFunction> foundFunctions;
|
||||
QRegularExpressionMatchIterator it = regex.globalMatch(_code);
|
||||
auto it = regex.globalMatch(_code);
|
||||
while (it.hasNext()) {
|
||||
QRegularExpressionMatch match = it.next();
|
||||
auto match = it.next();
|
||||
|
||||
AWPatternFunctions::AWFunction metadata;
|
||||
// work with args
|
||||
QString argsString = match.captured("args");
|
||||
auto argsString = match.captured("args");
|
||||
if (argsString.isEmpty()) {
|
||||
metadata.args = QStringList();
|
||||
} else {
|
||||
// replace '$,' to 0x1d
|
||||
argsString.replace("$,", QChar(0x1d));
|
||||
QStringList args = argsString.split(',');
|
||||
std::for_each(args.begin(), args.end(), [](QString &arg) { arg.replace(QChar(0x1d), ","); });
|
||||
auto args = argsString.split(',');
|
||||
std::for_each(args.begin(), args.end(), [](auto &arg) { arg.replace(QChar(0x1d), ","); });
|
||||
metadata.args = args;
|
||||
}
|
||||
// other variables
|
||||
@ -127,11 +127,11 @@ QString AWPatternFunctions::insertAllKeys(QString _code, const QStringList &_key
|
||||
{
|
||||
qCDebug(LOG_AW) << "Looking for keys in code" << _code << "using list" << _keys;
|
||||
|
||||
QList<AWPatternFunctions::AWFunction> found = AWPatternFunctions::findFunctionCalls("aw_all", _code);
|
||||
auto found = AWPatternFunctions::findFunctionCalls("aw_all", _code);
|
||||
for (auto &function : found) {
|
||||
QString separator = function.args.isEmpty() ? "," : function.args.at(0);
|
||||
QStringList required = _keys.filter(QRegularExpression(function.body));
|
||||
std::for_each(required.begin(), required.end(), [](QString &value) { value = QString("%1: $%1").arg(value); });
|
||||
auto separator = function.args.isEmpty() ? "," : function.args.at(0);
|
||||
auto required = _keys.filter(QRegularExpression(function.body));
|
||||
std::for_each(required.begin(), required.end(), [](auto &value) { value = QString("%1: $%1").arg(value); });
|
||||
|
||||
_code.replace(function.what, required.join(separator));
|
||||
}
|
||||
@ -144,9 +144,9 @@ QString AWPatternFunctions::insertKeyCount(QString _code, const QStringList &_ke
|
||||
{
|
||||
qCDebug(LOG_AW) << "Looking for count in code" << _code << "using list" << _keys;
|
||||
|
||||
QList<AWPatternFunctions::AWFunction> found = AWPatternFunctions::findFunctionCalls("aw_count", _code);
|
||||
auto found = AWPatternFunctions::findFunctionCalls("aw_count", _code);
|
||||
for (auto &function : found) {
|
||||
int count = _keys.filter(QRegularExpression(function.body)).count();
|
||||
auto count = _keys.filter(QRegularExpression(function.body)).count();
|
||||
|
||||
_code.replace(function.what, QString::number(count));
|
||||
}
|
||||
@ -159,10 +159,10 @@ QString AWPatternFunctions::insertKeyNames(QString _code, const QStringList &_ke
|
||||
{
|
||||
qCDebug(LOG_AW) << "Looking for key names in code" << _code << "using list" << _keys;
|
||||
|
||||
QList<AWPatternFunctions::AWFunction> found = AWPatternFunctions::findFunctionCalls("aw_names", _code);
|
||||
auto found = AWPatternFunctions::findFunctionCalls("aw_names", _code);
|
||||
for (auto &function : found) {
|
||||
QString separator = function.args.isEmpty() ? "," : function.args.at(0);
|
||||
QStringList required = _keys.filter(QRegularExpression(function.body));
|
||||
auto separator = function.args.isEmpty() ? "," : function.args.at(0);
|
||||
auto required = _keys.filter(QRegularExpression(function.body));
|
||||
|
||||
_code.replace(function.what, required.join(separator));
|
||||
}
|
||||
@ -175,11 +175,11 @@ QString AWPatternFunctions::insertKeys(QString _code, const QStringList &_keys)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Looking for keys in code" << _code << "using list" << _keys;
|
||||
|
||||
QList<AWPatternFunctions::AWFunction> found = AWPatternFunctions::findFunctionCalls("aw_keys", _code);
|
||||
auto found = AWPatternFunctions::findFunctionCalls("aw_keys", _code);
|
||||
for (auto &function : found) {
|
||||
QString separator = function.args.isEmpty() ? "," : function.args.at(0);
|
||||
QStringList required = _keys.filter(QRegularExpression(function.body));
|
||||
std::for_each(required.begin(), required.end(), [](QString &value) { value = QString("$%1").arg(value); });
|
||||
auto separator = function.args.isEmpty() ? "," : function.args.at(0);
|
||||
auto required = _keys.filter(QRegularExpression(function.body));
|
||||
std::for_each(required.begin(), required.end(), [](auto &value) { value = QString("$%1").arg(value); });
|
||||
|
||||
_code.replace(function.what, required.join(separator));
|
||||
}
|
||||
@ -192,26 +192,25 @@ QString AWPatternFunctions::insertMacros(QString _code)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Looking for macros in code" << _code;
|
||||
|
||||
QList<AWPatternFunctions::AWFunction> found = AWPatternFunctions::findFunctionCalls("aw_macro", _code);
|
||||
auto found = AWPatternFunctions::findFunctionCalls("aw_macro", _code);
|
||||
for (auto ¯o : found) {
|
||||
// get macro params
|
||||
if (macro.args.isEmpty()) {
|
||||
qCWarning(LOG_AW) << "No macro name found for" << macro.what;
|
||||
continue;
|
||||
}
|
||||
QString name = macro.args.takeFirst();
|
||||
auto name = macro.args.takeFirst();
|
||||
// find macro usage
|
||||
QList<AWPatternFunctions::AWFunction> macroUsage
|
||||
= AWPatternFunctions::findFunctionCalls(QString("aw_macro_%1").arg(name), _code);
|
||||
auto macroUsage = AWPatternFunctions::findFunctionCalls(QString("aw_macro_%1").arg(name), _code);
|
||||
for (auto &function : macroUsage) {
|
||||
if (function.args.count() != macro.args.count()) {
|
||||
qCWarning(LOG_AW) << "Invalid args count found for call" << function.what << "with macro" << macro.what;
|
||||
continue;
|
||||
}
|
||||
// generate body to replace
|
||||
QString result = macro.body;
|
||||
std::for_each(macro.args.cbegin(), macro.args.cend(), [&result, macro, function](const QString &arg) {
|
||||
int index = macro.args.indexOf(arg);
|
||||
auto result = macro.body;
|
||||
std::for_each(macro.args.cbegin(), macro.args.cend(), [&result, macro, function](auto &arg) {
|
||||
auto index = macro.args.indexOf(arg);
|
||||
result.replace(QString("$%1").arg(arg), function.args.at(index));
|
||||
});
|
||||
// do replace
|
||||
@ -231,7 +230,7 @@ QStringList AWPatternFunctions::findKeys(const QString &_code, const QStringList
|
||||
qCDebug(LOG_AW) << "Looking for keys in code" << _code << "using list" << _keys;
|
||||
|
||||
QStringList selectedKeys;
|
||||
QString replacedCode = _code;
|
||||
auto replacedCode = _code;
|
||||
for (auto &key : _keys)
|
||||
if ((key.startsWith("bar") == _isBars) && (replacedCode.contains(QString("$%1").arg(key)))) {
|
||||
qCInfo(LOG_AW) << "Found key" << key << "with bar enabled" << _isBars;
|
||||
@ -251,13 +250,13 @@ QStringList AWPatternFunctions::findLambdas(const QString &_code)
|
||||
|
||||
QStringList selectedKeys;
|
||||
// match the following construction ${{some code here}}
|
||||
QRegularExpression lambdaRegexp(R"(\$\{\{(?<body>.*?)\}\})");
|
||||
static QRegularExpression lambdaRegexp(R"(\$\{\{(?<body>.*?)\}\})");
|
||||
lambdaRegexp.setPatternOptions(QRegularExpression::DotMatchesEverythingOption);
|
||||
|
||||
QRegularExpressionMatchIterator it = lambdaRegexp.globalMatch(_code);
|
||||
auto it = lambdaRegexp.globalMatch(_code);
|
||||
while (it.hasNext()) {
|
||||
QRegularExpressionMatch match = it.next();
|
||||
QString lambda = match.captured("body");
|
||||
auto match = it.next();
|
||||
auto lambda = match.captured("body");
|
||||
|
||||
// append
|
||||
qCInfo(LOG_AW) << "Found lambda" << lambda;
|
||||
|
@ -41,12 +41,6 @@ AWTelemetryHandler::AWTelemetryHandler(QObject *_parent, const QString &_clientI
|
||||
}
|
||||
|
||||
|
||||
AWTelemetryHandler::~AWTelemetryHandler()
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
}
|
||||
|
||||
|
||||
QStringList AWTelemetryHandler::get(const QString &_group) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Get stored data for group" << _group;
|
||||
@ -106,7 +100,7 @@ bool AWTelemetryHandler::put(const QString &_group, const QString &_value) const
|
||||
settings.remove("");
|
||||
// and save now
|
||||
for (auto &val : saved) {
|
||||
QString key = getKey(settings.childKeys().count());
|
||||
auto key = getKey(settings.childKeys().count());
|
||||
settings.setValue(key, val);
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ public:
|
||||
const char *REMOTE_TELEMETRY_URL = "https://arcanis.me/telemetry";
|
||||
|
||||
explicit AWTelemetryHandler(QObject *_parent = nullptr, const QString &_clientId = "");
|
||||
~AWTelemetryHandler() override;
|
||||
~AWTelemetryHandler() override = default;
|
||||
Q_INVOKABLE [[nodiscard]] QStringList get(const QString &_group) const;
|
||||
Q_INVOKABLE [[nodiscard]] QString getLast(const QString &_group) const;
|
||||
Q_INVOKABLE void init(int _count, bool _enableRemote, const QString &_clientId);
|
||||
|
@ -41,12 +41,6 @@ AWUpdateHelper::AWUpdateHelper(QObject *_parent)
|
||||
}
|
||||
|
||||
|
||||
AWUpdateHelper::~AWUpdateHelper()
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
}
|
||||
|
||||
|
||||
void AWUpdateHelper::checkUpdates(const bool _showAnyway)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Show anyway" << _showAnyway;
|
||||
|
@ -30,7 +30,7 @@ class AWUpdateHelper : public QObject
|
||||
|
||||
public:
|
||||
explicit AWUpdateHelper(QObject *_parent = nullptr);
|
||||
~AWUpdateHelper() override;
|
||||
~AWUpdateHelper() override = default;
|
||||
void checkUpdates(bool _showAnyway = false);
|
||||
bool checkVersion();
|
||||
|
||||
|
@ -55,8 +55,8 @@ void BatterySource::run()
|
||||
acFile.close();
|
||||
|
||||
// batteries
|
||||
float currentLevel = 0.0, fullLevel = 0.0;
|
||||
for (int i = 0; i < m_batteriesCount; i++) {
|
||||
auto currentLevel = 0.0, fullLevel = 0.0;
|
||||
for (auto i = 0; i < m_batteriesCount; ++i) {
|
||||
// current level
|
||||
QFile currentLevelFile(QString("%1/BAT%2/energy_now").arg(m_acpiPath).arg(i));
|
||||
if (currentLevelFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
@ -101,7 +101,7 @@ QHash<QString, KSysGuard::SensorInfo *> BatterySource::sources() const
|
||||
result.insert("battotal", makeSensorInfo("Full battery capacity", QVariant::Int));
|
||||
|
||||
// generators
|
||||
for (auto i = 0; i < m_batteriesCount; i++) {
|
||||
for (auto i = 0; i < m_batteriesCount; ++i) {
|
||||
result.insert(QString("bat%1").arg(i), makeSensorInfo(QString("Battery %1 usage").arg(i), QVariant::Int,
|
||||
KSysGuard::UnitPercent, 0, 100));
|
||||
result.insert(QString("batleft%1").arg(i), makeSensorInfo(QString("Battery %1 discharge time").arg(i),
|
||||
@ -124,7 +124,7 @@ double BatterySource::approximate(const QList<int> &_trend)
|
||||
auto count = _trend.count();
|
||||
|
||||
auto sumxy = 0;
|
||||
for (int i = 0; i < count; i++)
|
||||
for (auto i = 0; i < count; ++i)
|
||||
sumxy += _trend.at(i) * (i + 1);
|
||||
|
||||
auto sumx = count * (count + 1) / 2;
|
||||
@ -149,7 +149,7 @@ void BatterySource::calculateRates()
|
||||
qCDebug(LOG_AW) << interval;
|
||||
m_timestamp.swap(now);
|
||||
|
||||
for (int i = 0; i < m_batteriesCount; i++) {
|
||||
for (auto i = 0; i < m_batteriesCount; ++i) {
|
||||
auto approx = approximate(m_trend[i + 1]);
|
||||
m_values[QString("batrate%1").arg(i)] = approx / interval;
|
||||
m_values[QString("batleft%1").arg(i)] = interval * m_values[QString("batnow%1").arg(i)].toFloat() / approx;
|
||||
|
@ -41,7 +41,7 @@ QHash<QString, KSysGuard::SensorInfo *> LoadSource::sources() const
|
||||
{
|
||||
auto result = QHash<QString, KSysGuard::SensorInfo *>();
|
||||
|
||||
for (auto i = 0; i < 1000; i++)
|
||||
for (auto i = 0; i < 1000; ++i)
|
||||
result.insert(QString("load%1").arg(i), makeSensorInfo("Simple sources for load tests", QVariant::Int));
|
||||
|
||||
return result;
|
||||
|
@ -73,7 +73,7 @@ QString AWTestLibrary::randomString(const int _min, const int _max)
|
||||
QString output;
|
||||
|
||||
auto count = _min + randomInt(_max - _min);
|
||||
for (auto i = 0; i < count; i++)
|
||||
for (auto i = 0; i < count; ++i)
|
||||
output += randomChar();
|
||||
|
||||
return output;
|
||||
@ -85,7 +85,7 @@ QStringList AWTestLibrary::randomStringList(const int _max)
|
||||
QStringList output;
|
||||
|
||||
auto count = 1 + randomInt(_max);
|
||||
for (auto i = 0; i < count; i++)
|
||||
for (auto i = 0; i < count; ++i)
|
||||
output.append(randomString());
|
||||
|
||||
return output;
|
||||
@ -97,7 +97,7 @@ QStringList AWTestLibrary::randomSelect(const QStringList &_available)
|
||||
QSet<QString> output;
|
||||
|
||||
auto count = 1 + randomInt(_available.count());
|
||||
for (auto i = 0; i < count; i++) {
|
||||
for (auto i = 0; i < count; ++i) {
|
||||
auto index = randomInt(_available.count());
|
||||
output << _available.at(index);
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ void TestAWPatternFunctions::test_findKeys()
|
||||
{
|
||||
auto count = AWTestLibrary::randomInt(200);
|
||||
QStringList allKeys;
|
||||
for (auto i = 0; i < count; i++) {
|
||||
for (auto i = 0; i < count; ++i) {
|
||||
auto key = AWTestLibrary::randomString(1, 20);
|
||||
while (allKeys.indexOf(QRegularExpression(QString("^%1.*").arg(key))) != -1)
|
||||
key = AWTestLibrary::randomString(1, 20);
|
||||
|
@ -73,7 +73,7 @@ void TestAWJsonFormatter::generate()
|
||||
auto listCount = AWTestLibrary::randomInt(5) + 1;
|
||||
auto validCount = AWTestLibrary::randomInt(listCount);
|
||||
QVariantList second;
|
||||
for (auto i = 0; i < listCount; i++) {
|
||||
for (auto i = 0; i < listCount; ++i) {
|
||||
if (i == validCount) {
|
||||
second.append(first);
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user