Skip to content

Commit

Permalink
refactor: simplify sources processing
Browse files Browse the repository at this point in the history
Also fix desktop source
  • Loading branch information
arcan1s committed Mar 30, 2024
1 parent 0bcceef commit aeda6c7
Show file tree
Hide file tree
Showing 68 changed files with 542 additions and 1,079 deletions.
2 changes: 1 addition & 1 deletion sources/3rdparty/qreplytimeout/qreplytimeout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ QReplyTimeout::QReplyTimeout(QNetworkReply *reply, const int timeout)

void QReplyTimeout::timeout()
{
auto *reply = dynamic_cast<QNetworkReply *>(parent());
auto reply = dynamic_cast<QNetworkReply *>(parent());
if (reply->isRunning())
reply->close();
}
4 changes: 2 additions & 2 deletions sources/awesome-widget/plugin/awabstractpairconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void AWAbstractPairConfig::updateUi()
// remove current selector if it is empty and does not last
if (sender() == m_selectors.last())
return;
auto *selector = m_selectors.takeAt(index);
auto selector = m_selectors.takeAt(index);
ui->verticalLayout->removeWidget(selector);
selector->deleteLater();
} else {
Expand All @@ -109,7 +109,7 @@ void AWAbstractPairConfig::addSelector(const QStringList &_keys, const QStringLi
{
qCDebug(LOG_AW) << "Add selector with keys" << _keys << "values" << _values << "and current ones" << _current;

auto *selector = new AWAbstractSelector(ui->scrollAreaWidgetContents, m_editable);
auto selector = new AWAbstractSelector(ui->scrollAreaWidgetContents, m_editable);
selector->init(_keys, _values, _current);
ui->verticalLayout->insertWidget(ui->verticalLayout->count() - 1, selector);
connect(selector, &AWAbstractSelector::selectionChanged, this, &AWAbstractPairConfig::updateUi);
Expand Down
2 changes: 1 addition & 1 deletion sources/awesome-widget/plugin/awactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void AWActions::showReadme()

void AWActions::showLegacyInfo()
{
auto *msgBox = new QMessageBox(nullptr);
auto msgBox = new QMessageBox(nullptr);
msgBox->setAttribute(Qt::WA_DeleteOnClose);
msgBox->setModal(false);
msgBox->setWindowTitle(i18n("Not supported"));
Expand Down
4 changes: 2 additions & 2 deletions sources/awesome-widget/plugin/awbugreporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void AWBugReporter::sendBugReport(const QString &_title, const QString &_body)
{
qCDebug(LOG_AW) << "Send bug report with title" << _title << "and body" << _body;

auto *manager = new QNetworkAccessManager(nullptr);
auto manager = new QNetworkAccessManager(nullptr);
connect(manager, &QNetworkAccessManager::finished, this, &AWBugReporter::issueReplyReceived);

auto request = QNetworkRequest(QUrl(BUGTRACKER_API));
Expand Down Expand Up @@ -121,7 +121,7 @@ void AWBugReporter::showInformation(const int _number, const QString &_url)
// cache url first
m_lastBugUrl = _url;

auto *msgBox = new QMessageBox(nullptr);
auto msgBox = new QMessageBox(nullptr);
msgBox->setAttribute(Qt::WA_DeleteOnClose);
msgBox->setModal(false);
msgBox->setWindowTitle(i18n("Issue created"));
Expand Down
2 changes: 1 addition & 1 deletion sources/awesome-widget/plugin/awconfighelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ bool AWConfigHelper::exportConfiguration(QObject *_nativeConfig, const QString &

QSettings settings(_fileName, QSettings::IniFormat);
// plasmoid configuration
const auto *configuration = dynamic_cast<const QQmlPropertyMap *>(_nativeConfig);
auto configuration = dynamic_cast<const QQmlPropertyMap *>(_nativeConfig);
settings.beginGroup("plasmoid");
for (auto &key : configuration->keys()) {
QVariant value = configuration->value(key);
Expand Down
12 changes: 6 additions & 6 deletions sources/awesome-widget/plugin/awkeyoperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,11 @@ QString AWKeyOperations::infoByKey(const QString &_key) const
QString output;

if (_key.startsWith("bar")) {
auto *item = m_graphicalItems->itemByTag(_key, stripped);
auto item = m_graphicalItems->itemByTag(_key, stripped);
if (item)
output = item->uniq();
} else if (_key.startsWith("custom")) {
auto *item = m_extScripts->itemByTag(_key, stripped);
auto item = m_extScripts->itemByTag(_key, stripped);
if (item)
output = item->uniq();
} else if (_key.contains(QRegularExpression("^hdd[rw]"))) {
Expand All @@ -230,23 +230,23 @@ QString AWKeyOperations::infoByKey(const QString &_key) const
index.remove(QRegularExpression("^(down|up)"));
output = m_devices["net"][index.toInt()];
} else if (_key.startsWith("pkgcount")) {
auto *item = m_extUpgrade->itemByTag(_key, stripped);
auto item = m_extUpgrade->itemByTag(_key, stripped);
if (item)
output = item->uniq();
} else if (_key.contains(QRegularExpression("(^|perc)(ask|bid|price)(chg|)"))) {
auto *item = m_extQuotes->itemByTag(_key, stripped);
auto item = m_extQuotes->itemByTag(_key, stripped);
if (item)
output = item->uniq();
} else if (_key.contains(QRegularExpression("(weather|weatherId|humidity|pressure|temperature)"))) {
auto *item = m_extWeather->itemByTag(_key, stripped);
auto item = m_extWeather->itemByTag(_key, stripped);
if (item)
output = item->uniq();
} else if (_key.startsWith("temp")) {
auto index = _key;
index.remove("temp");
output = m_devices["temp"][index.toInt()];
} else if (_key.startsWith("response")) {
auto *item = m_extNetRequest->itemByTag(_key, stripped);
auto item = m_extNetRequest->itemByTag(_key, stripped);
if (item)
output = item->uniq();
} else {
Expand Down
4 changes: 2 additions & 2 deletions sources/awesome-widget/plugin/awpairconfigfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ AWPairConfigFactory::~AWPairConfigFactory()

void AWPairConfigFactory::showFormatterDialog(const QStringList &_keys)
{
auto *config = new AWFormatterConfig(nullptr, _keys);
auto config = new AWFormatterConfig(nullptr, _keys);
config->showDialog();
config->deleteLater();
}


void AWPairConfigFactory::showKeysDialog(const QStringList &_keys)
{
auto *config = new AWCustomKeysConfig(nullptr, _keys);
auto config = new AWCustomKeysConfig(nullptr, _keys);
config->showDialog();
config->deleteLater();
}
2 changes: 1 addition & 1 deletion sources/awesome-widget/plugin/awtelemetryhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ void AWTelemetryHandler::uploadTelemetry(const QString &_group, const QString &_
return;
}

auto *manager = new QNetworkAccessManager(nullptr);
auto manager = new QNetworkAccessManager(nullptr);
connect(manager, &QNetworkAccessManager::finished, this, &AWTelemetryHandler::telemetryReplyReceived);

QUrl url(REMOTE_TELEMETRY_URL);
Expand Down
4 changes: 2 additions & 2 deletions sources/awesome-widget/plugin/awupdatehelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void AWUpdateHelper::checkUpdates(const bool _showAnyway)

// showAnyway options requires to show message if no updates found on direct
// request. In case of automatic check no message will be shown
auto *manager = new QNetworkAccessManager(nullptr);
auto manager = new QNetworkAccessManager(nullptr);
connect(manager, &QNetworkAccessManager::finished,
[_showAnyway, this](QNetworkReply *reply) { return versionReplyReceived(reply, _showAnyway); });

Expand Down Expand Up @@ -163,7 +163,7 @@ QMessageBox *AWUpdateHelper::genMessageBox(const QString &_title, const QString
{
qCDebug(LOG_AW) << "Construct message box with title" << _title << "and body" << _body;

auto *msgBox = new QMessageBox(nullptr);
auto msgBox = new QMessageBox(nullptr);
msgBox->setAttribute(Qt::WA_DeleteOnClose);
msgBox->setModal(false);
msgBox->setWindowTitle(_title);
Expand Down
12 changes: 6 additions & 6 deletions sources/awesomewidgets/extitemaggregator.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ template <class T> class ExtItemAggregator : public AbstractExtItemAggregator
m_activeItems.clear();

m_items = getItems();
for (auto &item : m_items) {
for (auto item : m_items) {
if (!item->isActive())
continue;
m_activeItems.append(static_cast<T *>(item));
Expand All @@ -77,7 +77,7 @@ template <class T> class ExtItemAggregator : public AbstractExtItemAggregator
// HACK as soon as per one widget instance we have two objects each of
// them will try to control socket, whereas actually only one of them
// should be owner of the socket
for (auto &item : m_items)
for (auto item : m_items)
item->initSocket();
}

Expand All @@ -86,7 +86,7 @@ template <class T> class ExtItemAggregator : public AbstractExtItemAggregator
qCDebug(LOG_LIB) << "Tag" << _tag << "with used type" << _type;

T *found = nullptr;
for (auto &item : m_items) {
for (auto item : m_items) {
if (item->tag(_type) != _tag)
continue;
found = static_cast<T *>(item);
Expand All @@ -103,7 +103,7 @@ template <class T> class ExtItemAggregator : public AbstractExtItemAggregator
qCDebug(LOG_LIB) << "Number" << _number;

T *found = nullptr;
for (auto &item : m_items) {
for (auto item : m_items) {
if (item->number() != _number)
continue;
found = static_cast<T *>(item);
Expand All @@ -129,7 +129,7 @@ template <class T> class ExtItemAggregator : public AbstractExtItemAggregator

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"))
Expand All @@ -145,7 +145,7 @@ template <class T> class ExtItemAggregator : public AbstractExtItemAggregator
}

// sort items
std::sort(items.begin(), items.end(), [](auto *lhs, auto *rhs) { return lhs->number() < rhs->number(); });
std::sort(items.begin(), items.end(), [](auto lhs, auto rhs) { return lhs->number() < rhs->number(); });
return items;
};
};
4 changes: 2 additions & 2 deletions sources/desktop-panel/plugin/dpadds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ QString DPAdds::toolTipImage(const int _desktop) const
}

// init
auto *toolTipScene = new QGraphicsScene();
auto *toolTipView = new QGraphicsView(toolTipScene);
auto toolTipScene = new QGraphicsScene();
auto toolTipView = new QGraphicsView(toolTipScene);
toolTipView->setStyleSheet("background: transparent");
toolTipView->setContentsMargins(0, 0, 0, 0);
toolTipView->setFrameShape(QFrame::NoFrame);
Expand Down
29 changes: 14 additions & 15 deletions sources/extsysmon/extsysmonaggregator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,34 +57,33 @@ void ExtSysMonAggregator::init(const QHash<QString, QString> &_config)
qCDebug(LOG_ESM) << "Configuration" << _config;

// battery
createSensor("battery", i18n("Battery"), new BatterySource(this, {_config["ACPIPATH"]}));
createSensor("battery", i18n("Battery"), new BatterySource(this, _config["ACPIPATH"]));
// custom
createSensor("custom", i18n("Scripts"), new CustomSource(this, {}));
createSensor("custom", i18n("Scripts"), new CustomSource(this));
// desktop
// FIXME causes segfault in kde libs
// createSensor("desktop", i18n("Desktop"), new DesktopSource(this, {}));
createSensor("desktop", i18n("Desktop"), new DesktopSource(this));
// network
createSensor("network", i18n("Network"), new NetworkSource(this, {}));
createSensor("network", i18n("Network"), new NetworkSource(this));
// player
createSensor("player", i18n("Music player"),
new PlayerSource(this, {_config["PLAYER"], _config["MPDADDRESS"], _config["MPDPORT"], _config["MPRIS"],
_config["PLAYERSYMBOLS"]}));
new PlayerSource(this, _config["PLAYER"], _config["MPDADDRESS"], _config["MPDPORT"].toInt(),
_config["MPRIS"], _config["PLAYERSYMBOLS"].toInt()));
// processes
createSensor("ps", i18n("Processes"), new ProcessesSource(this, {}));
createSensor("ps", i18n("Processes"), new ProcessesSource(this));
// network request
createSensor("requests", i18n("Network requests"), new RequestSource(this, {}));
createSensor("requests", i18n("Network requests"), new RequestSource(this));
// quotes
createSensor("quotes", i18n("Quotes"), new QuotesSource(this, {}));
createSensor("quotes", i18n("Quotes"), new QuotesSource(this));
// system
createSensor("system", i18n("System"), new SystemInfoSource(this, {}));
createSensor("system", i18n("System"), new SystemInfoSource(this));
// current time
createSensor("time", i18n("Time"), new TimeSource(this, {}));
createSensor("time", i18n("Time"), new TimeSource(this));
// upgrade
createSensor("upgrade", i18n("Upgrades"), new UpgradeSource(this, {}));
createSensor("upgrade", i18n("Upgrades"), new UpgradeSource(this));
// weather
createSensor("weather", i18n("Weather"), new WeatherSource(this, {}));
createSensor("weather", i18n("Weather"), new WeatherSource(this));
#ifdef BUILD_LOAD
// additional load source
createSensor("load", i18n("Load"), new LoadSource(this, {}));
createSensor("load", i18n("Load"), new LoadSource(this));
#endif /* BUILD_LOAD */
}
49 changes: 37 additions & 12 deletions sources/extsysmonsources/abstractextsysmonsource.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,58 @@

#pragma once

#include <ksysguard/systemstats/SensorInfo.h>

#include <QObject>
#include <QRegularExpression>
#include <QVariant>


namespace KSysGuard
{
class SensorInfo;
}

class AbstractExtSysMonSource : public QObject
{
Q_OBJECT

public:
explicit AbstractExtSysMonSource(QObject *_parent, const QStringList &)
inline static QRegularExpression NUMBER_REGEX = QRegularExpression("\\d+$");

explicit AbstractExtSysMonSource(QObject *_parent)
: QObject(_parent){};
~AbstractExtSysMonSource() override = default;
virtual QVariant data(const QString &_source) = 0;
[[nodiscard]] virtual KSysGuard::SensorInfo *initialData(const QString &_source) const = 0;
virtual void run() = 0;
[[nodiscard]] virtual QStringList sources() const = 0;
[[nodiscard]] virtual QHash<QString, KSysGuard::SensorInfo *> sources() const = 0;

// used by extensions
// This method returns -1 in case of invalid source name (like if there is no number)
static int index(const QString &_source)
{
QRegularExpression rx("\\d+");
return rx.match(_source).captured().toInt();
auto match = NUMBER_REGEX.match(_source);
return match.hasMatch() ? match.captured().toInt() : -1;
}

// safe value extractor
template <class T> static QVariantHash dataByItem(T *_extension, const QString &_source)
{
auto idx = index(_source);
if (idx == -1)
return {};

auto item = _extension->itemByTagNumber(idx);
return item ? item->run() : QVariantHash();
}

static KSysGuard::SensorInfo *makeSensorInfo(const QString &_name, const QVariant::Type type,
const KSysGuard::Unit unit = KSysGuard::UnitNone, const double min = 0,
const double max = 0)
{
auto info = new KSysGuard::SensorInfo();
info->name = _name;
info->variantType = type;

info->unit = unit;

info->min = min;
info->max = max;

return info;
}

signals:
Expand Down
Loading

0 comments on commit aeda6c7

Please sign in to comment.