diff --git a/sources/3rdparty/qreplytimeout/qreplytimeout.cpp b/sources/3rdparty/qreplytimeout/qreplytimeout.cpp index ee500bd8..77572690 100644 --- a/sources/3rdparty/qreplytimeout/qreplytimeout.cpp +++ b/sources/3rdparty/qreplytimeout/qreplytimeout.cpp @@ -12,7 +12,7 @@ QReplyTimeout::QReplyTimeout(QNetworkReply *reply, const int timeout) void QReplyTimeout::timeout() { - auto *reply = dynamic_cast(parent()); + auto reply = dynamic_cast(parent()); if (reply->isRunning()) reply->close(); } diff --git a/sources/awesome-widget/plugin/awabstractpairconfig.cpp b/sources/awesome-widget/plugin/awabstractpairconfig.cpp index fc9948b5..07c1a7d4 100644 --- a/sources/awesome-widget/plugin/awabstractpairconfig.cpp +++ b/sources/awesome-widget/plugin/awabstractpairconfig.cpp @@ -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 { @@ -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); diff --git a/sources/awesome-widget/plugin/awactions.cpp b/sources/awesome-widget/plugin/awactions.cpp index b3e50fbf..6a970f19 100644 --- a/sources/awesome-widget/plugin/awactions.cpp +++ b/sources/awesome-widget/plugin/awactions.cpp @@ -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")); diff --git a/sources/awesome-widget/plugin/awbugreporter.cpp b/sources/awesome-widget/plugin/awbugreporter.cpp index fa6f2694..f062a9d9 100644 --- a/sources/awesome-widget/plugin/awbugreporter.cpp +++ b/sources/awesome-widget/plugin/awbugreporter.cpp @@ -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)); @@ -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")); diff --git a/sources/awesome-widget/plugin/awconfighelper.cpp b/sources/awesome-widget/plugin/awconfighelper.cpp index baa369d2..9b9e79eb 100644 --- a/sources/awesome-widget/plugin/awconfighelper.cpp +++ b/sources/awesome-widget/plugin/awconfighelper.cpp @@ -72,7 +72,7 @@ bool AWConfigHelper::exportConfiguration(QObject *_nativeConfig, const QString & QSettings settings(_fileName, QSettings::IniFormat); // plasmoid configuration - const auto *configuration = dynamic_cast(_nativeConfig); + auto configuration = dynamic_cast(_nativeConfig); settings.beginGroup("plasmoid"); for (auto &key : configuration->keys()) { QVariant value = configuration->value(key); diff --git a/sources/awesome-widget/plugin/awkeyoperations.cpp b/sources/awesome-widget/plugin/awkeyoperations.cpp index 663272f3..3f10ef54 100644 --- a/sources/awesome-widget/plugin/awkeyoperations.cpp +++ b/sources/awesome-widget/plugin/awkeyoperations.cpp @@ -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]"))) { @@ -230,15 +230,15 @@ 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")) { @@ -246,7 +246,7 @@ QString AWKeyOperations::infoByKey(const QString &_key) const 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 { diff --git a/sources/awesome-widget/plugin/awpairconfigfactory.cpp b/sources/awesome-widget/plugin/awpairconfigfactory.cpp index 893d9d24..83082542 100644 --- a/sources/awesome-widget/plugin/awpairconfigfactory.cpp +++ b/sources/awesome-widget/plugin/awpairconfigfactory.cpp @@ -37,7 +37,7 @@ AWPairConfigFactory::~AWPairConfigFactory() void AWPairConfigFactory::showFormatterDialog(const QStringList &_keys) { - auto *config = new AWFormatterConfig(nullptr, _keys); + auto config = new AWFormatterConfig(nullptr, _keys); config->showDialog(); config->deleteLater(); } @@ -45,7 +45,7 @@ void AWPairConfigFactory::showFormatterDialog(const QStringList &_keys) void AWPairConfigFactory::showKeysDialog(const QStringList &_keys) { - auto *config = new AWCustomKeysConfig(nullptr, _keys); + auto config = new AWCustomKeysConfig(nullptr, _keys); config->showDialog(); config->deleteLater(); } diff --git a/sources/awesome-widget/plugin/awtelemetryhandler.cpp b/sources/awesome-widget/plugin/awtelemetryhandler.cpp index b3cfa32a..b4738ec0 100644 --- a/sources/awesome-widget/plugin/awtelemetryhandler.cpp +++ b/sources/awesome-widget/plugin/awtelemetryhandler.cpp @@ -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); diff --git a/sources/awesome-widget/plugin/awupdatehelper.cpp b/sources/awesome-widget/plugin/awupdatehelper.cpp index 93db680b..191a9f53 100644 --- a/sources/awesome-widget/plugin/awupdatehelper.cpp +++ b/sources/awesome-widget/plugin/awupdatehelper.cpp @@ -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); }); @@ -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); diff --git a/sources/awesomewidgets/extitemaggregator.h b/sources/awesomewidgets/extitemaggregator.h index 9a59297f..18f9850d 100644 --- a/sources/awesomewidgets/extitemaggregator.h +++ b/sources/awesomewidgets/extitemaggregator.h @@ -65,7 +65,7 @@ template 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(item)); @@ -77,7 +77,7 @@ template 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(); } @@ -86,7 +86,7 @@ template 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(item); @@ -103,7 +103,7 @@ template 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(item); @@ -129,7 +129,7 @@ template 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")) @@ -145,7 +145,7 @@ template 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; }; }; diff --git a/sources/desktop-panel/plugin/dpadds.cpp b/sources/desktop-panel/plugin/dpadds.cpp index ed100301..348712c8 100644 --- a/sources/desktop-panel/plugin/dpadds.cpp +++ b/sources/desktop-panel/plugin/dpadds.cpp @@ -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); diff --git a/sources/extsysmon/extsysmonaggregator.cpp b/sources/extsysmon/extsysmonaggregator.cpp index 93e0280b..71b96aeb 100644 --- a/sources/extsysmon/extsysmonaggregator.cpp +++ b/sources/extsysmon/extsysmonaggregator.cpp @@ -57,34 +57,33 @@ void ExtSysMonAggregator::init(const QHash &_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 */ } diff --git a/sources/extsysmonsources/abstractextsysmonsource.h b/sources/extsysmonsources/abstractextsysmonsource.h index 005afe81..4e4f6fd9 100644 --- a/sources/extsysmonsources/abstractextsysmonsource.h +++ b/sources/extsysmonsources/abstractextsysmonsource.h @@ -17,33 +17,58 @@ #pragma once +#include + #include #include #include - -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 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 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: diff --git a/sources/extsysmonsources/batterysource.cpp b/sources/extsysmonsources/batterysource.cpp index 431ee831..a5cda540 100644 --- a/sources/extsysmonsources/batterysource.cpp +++ b/sources/extsysmonsources/batterysource.cpp @@ -15,12 +15,8 @@ * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * ***************************************************************************/ - #include "batterysource.h" -#include -#include - #include #include @@ -28,51 +24,15 @@ #include "awdebug.h" -BatterySource::BatterySource(QObject *_parent, const QStringList &_args) - : AbstractExtSysMonSource(_parent, _args) +BatterySource::BatterySource(QObject *_parent, QString _acpiPath) + : AbstractExtSysMonSource(_parent) + , m_acpiPath(std::move(_acpiPath)) { - Q_ASSERT(_args.count() == 1); qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; - m_acpiPath = _args.at(0); - m_sources = getSources(); -} - - -BatterySource::~BatterySource() -{ - qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; -} - - -QStringList BatterySource::getSources() -{ - QStringList sources; - sources.append("ac"); - sources.append("bat"); - sources.append("batleft"); - sources.append("batnow"); - sources.append("batrate"); - sources.append("battotal"); - auto directory = QDir(m_acpiPath); - - if (directory.exists()) { - m_batteriesCount - = directory.entryList(QStringList({"BAT*"}), QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name).count(); - qCInfo(LOG_ESS) << "Init batteries count as" << m_batteriesCount; - - for (int i = 0; i < m_batteriesCount; i++) { - sources.append(QString("bat%1").arg(i)); - sources.append(QString("batleft%1").arg(i)); - sources.append(QString("batnow%1").arg(i)); - sources.append(QString("batrate%1").arg(i)); - sources.append(QString("battotal%1").arg(i)); - } - } - - qCInfo(LOG_ESS) << "Sources list" << sources; - return sources; + m_batteriesCount = directory.entryList(QStringList({"BAT*"}), QDir::Dirs | QDir::NoDotAndDotDot).count(); + qCInfo(LOG_ESS) << "Init batteries count as" << m_batteriesCount; } @@ -81,86 +41,11 @@ QVariant BatterySource::data(const QString &_source) qCDebug(LOG_ESS) << "Source" << _source; if (!m_values.contains(_source)) - run(); + run(); // syncronous update of all values return m_values.take(_source); } -KSysGuard::SensorInfo *BatterySource::initialData(const QString &_source) const -{ - qCDebug(LOG_ESS) << "Source" << _source; - - auto data = new KSysGuard::SensorInfo(); - if (_source == "ac") { - data->name = "Is AC online or not"; - data->variantType = QVariant::Bool; - data->unit = KSysGuard::UnitNone; - } else if (_source == "bat") { - data->min = 0; - data->max = 100; - data->name = "Average battery usage"; - data->variantType = QVariant::Int; - data->unit = KSysGuard::UnitPercent; - } else if (_source == "batleft") { - data->min = 0; - data->max = 0; - data->name = "Battery discharge time"; - data->variantType = QVariant::Int; - data->unit = KSysGuard::UnitSecond; - } else if (_source == "batnow") { - data->min = 0; - data->max = 0; - data->name = "Current battery capacity"; - data->variantType = QVariant::Int; - data->unit = KSysGuard::UnitNone; - } else if (_source == "batrate") { - data->min = 0; - data->max = 0; - data->name = "Average battery discharge rate"; - data->variantType = QVariant::Double; - data->unit = KSysGuard::UnitRate; - } else if (_source == "battotal") { - data->min = 0; - data->max = 0; - data->name = "Full battery capacity"; - data->variantType = QVariant::Int; - data->unit = KSysGuard::UnitNone; - } else if (_source.startsWith("batleft")) { - data->min = 0; - data->max = 0; - data->name = QString("Battery %1 discharge time").arg(index(_source)); - data->variantType = QVariant::Int; - data->unit = KSysGuard::UnitSecond; - } else if (_source.startsWith("batnow")) { - data->min = 0; - data->max = 0; - data->name = QString("Battery %1 capacity").arg(index(_source)); - data->variantType = QVariant::Int; - data->unit = KSysGuard::UnitNone; - } else if (_source.startsWith("battotal")) { - data->min = 0; - data->max = 0; - data->name = QString("Battery %1 full capacity").arg(index(_source)); - data->variantType = QVariant::Int; - data->unit = KSysGuard::UnitNone; - } else if (_source.startsWith("batrate")) { - data->min = 0; - data->max = 0; - data->name = QString("Battery %1 discharge rate").arg(index(_source)); - data->variantType = QVariant::Double; - data->unit = KSysGuard::UnitRate; - } else if (_source.startsWith("bat")) { - data->min = 0; - data->max = 100; - data->name = QString("Battery %1 usage").arg(index(_source)); - data->variantType = QVariant::Int; - data->unit = KSysGuard::UnitPercent; - } - - return data; -} - - void BatterySource::run() { // adaptor @@ -203,9 +88,32 @@ void BatterySource::run() } -QStringList BatterySource::sources() const +QHash BatterySource::sources() const { - return m_sources; + auto result = QHash(); + + // fixed fields + result.insert("ac", makeSensorInfo("Is AC online or not", QVariant::Bool)); + result.insert("bat", makeSensorInfo("Average battery usage", QVariant::Int, KSysGuard::UnitPercent, 0, 100)); + result.insert("batleft", makeSensorInfo("Battery discharge time", QVariant::Int, KSysGuard::UnitSecond)); + result.insert("batnow", makeSensorInfo("Current battery capacity", QVariant::Int)); + result.insert("batrate", makeSensorInfo("Average battery discharge rate", QVariant::Double, KSysGuard::UnitRate)); + result.insert("battotal", makeSensorInfo("Full battery capacity", QVariant::Int)); + + // generators + 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), + QVariant::Int, KSysGuard::UnitSecond)); + result.insert(QString("batnow%1").arg(i), makeSensorInfo(QString("Battery %1 capacity").arg(i), QVariant::Int)); + result.insert(QString("batrate%1").arg(i), makeSensorInfo(QString("Battery %1 discharge rate").arg(i), + QVariant::Double, KSysGuard::UnitRate)); + result.insert(QString("battotal%1").arg(i), + makeSensorInfo(QString("Battery %1 full capacity").arg(i), QVariant::Int)); + } + + return result; } diff --git a/sources/extsysmonsources/batterysource.h b/sources/extsysmonsources/batterysource.h index c2466f7d..cf474c73 100644 --- a/sources/extsysmonsources/batterysource.h +++ b/sources/extsysmonsources/batterysource.h @@ -30,13 +30,11 @@ class BatterySource : public AbstractExtSysMonSource public: const int TREND_LIMIT = 20; - explicit BatterySource(QObject *_parent, const QStringList &_args); - ~BatterySource() override; - QStringList getSources(); + explicit BatterySource(QObject *_parent, QString _acpiPath); + ~BatterySource() override = default; QVariant data(const QString &_source) override; - [[nodiscard]] KSysGuard::SensorInfo *initialData(const QString &_source) const override; - void run() override; - [[nodiscard]] QStringList sources() const override; + void run(); + [[nodiscard]] QHash sources() const override; private: static double approximate(const QList &_trend); diff --git a/sources/extsysmonsources/customsource.cpp b/sources/extsysmonsources/customsource.cpp index a03214e9..c592d3ff 100644 --- a/sources/extsysmonsources/customsource.cpp +++ b/sources/extsysmonsources/customsource.cpp @@ -17,28 +17,17 @@ #include "customsource.h" -#include -#include - #include "awdebug.h" #include "extscript.h" -CustomSource::CustomSource(QObject *_parent, const QStringList &_args) - : AbstractExtSysMonSource(_parent, _args) +CustomSource::CustomSource(QObject *_parent) + : AbstractExtSysMonSource(_parent) { - Q_ASSERT(_args.count() == 0); qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; - m_extScripts = new ExtItemAggregator(nullptr, "scripts"); + m_extScripts = new ExtItemAggregator(this, "scripts"); m_extScripts->initSockets(); - m_sources = getSources(); -} - - -CustomSource::~CustomSource() -{ - qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; } @@ -47,34 +36,17 @@ QVariant CustomSource::data(const QString &_source) qCDebug(LOG_ESS) << "Source" << _source; // there are only one value - return m_extScripts->itemByTagNumber(index(_source))->run().values().first(); -} - - -KSysGuard::SensorInfo *CustomSource::initialData(const QString &_source) const -{ - qCDebug(LOG_ESS) << "Source" << _source; - - auto data = new KSysGuard::SensorInfo(); - data->name = QString("Custom command '%1' output").arg(m_extScripts->itemByTagNumber(index(_source))->uniq()); - data->variantType = QVariant::String; - data->unit = KSysGuard::UnitNone; - - return data; + return dataByItem(m_extScripts, _source).values().first(); } -QStringList CustomSource::sources() const +QHash CustomSource::sources() const { - return m_sources; -} + auto result = QHash(); - -QStringList CustomSource::getSources() -{ - QStringList sources; for (auto &item : m_extScripts->activeItems()) - sources.append(item->tag("custom")); + result.insert(item->tag("custom"), + makeSensorInfo(QString("Custom command '%1' output").arg(item->uniq()), QVariant::String)); - return sources; + return result; } diff --git a/sources/extsysmonsources/customsource.h b/sources/extsysmonsources/customsource.h index e24b4b51..e4d59ad6 100644 --- a/sources/extsysmonsources/customsource.h +++ b/sources/extsysmonsources/customsource.h @@ -30,16 +30,12 @@ class CustomSource : public AbstractExtSysMonSource Q_OBJECT public: - explicit CustomSource(QObject *_parent, const QStringList &_args); - ~CustomSource() override; + explicit CustomSource(QObject *_parent); + ~CustomSource() override = default; QVariant data(const QString &_source) override; - [[nodiscard]] KSysGuard::SensorInfo *initialData(const QString &_source) const override; - void run() override{}; - [[nodiscard]] QStringList sources() const override; + [[nodiscard]] QHash sources() const override; private: - QStringList getSources(); // configuration and values ExtItemAggregator *m_extScripts = nullptr; - QStringList m_sources; }; diff --git a/sources/extsysmonsources/desktopsource.cpp b/sources/extsysmonsources/desktopsource.cpp index 149f4751..c880e715 100644 --- a/sources/extsysmonsources/desktopsource.cpp +++ b/sources/extsysmonsources/desktopsource.cpp @@ -17,29 +17,17 @@ #include "desktopsource.h" -#include -#include -#include -#include +#include +#include +#include #include "awdebug.h" -DesktopSource::DesktopSource(QObject *_parent, const QStringList &_args) - : AbstractExtSysMonSource(_parent, _args) +DesktopSource::DesktopSource(QObject *_parent) + : AbstractExtSysMonSource(_parent) { - Q_ASSERT(_args.count() == 0); qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; - - m_vdi = new TaskManager::VirtualDesktopInfo(this); -} - - -DesktopSource::~DesktopSource() -{ - qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; - - m_vdi->deleteLater(); } @@ -47,60 +35,72 @@ QVariant DesktopSource::data(const QString &_source) { qCDebug(LOG_ESS) << "Source" << _source; - auto nativeIndex = m_vdi->position(m_vdi->currentDesktop()); - auto decrement = KWindowSystem::isPlatformX11() ? 1 : 0; - auto current = nativeIndex - decrement; + auto current = getDBusProperty({"org.kde.KWin.VirtualDesktopManager", "current"}).toString(); + auto desktops + = extractDesktops(getDBusProperty({"org.kde.KWin.VirtualDesktopManager", "desktops"}).value()); if (_source == "name") { - return m_vdi->desktopNames().at(current); + return desktops[current].second; } else if (_source == "number") { - return current + 1; - } else if (_source == "names") { - return m_vdi->desktopNames(); + return desktops[current].first + 1; } else if (_source == "count") { - return m_vdi->numberOfDesktops(); + return desktops.count(); } return {}; } -KSysGuard::SensorInfo *DesktopSource::initialData(const QString &_source) const +QHash DesktopSource::sources() const { - qCDebug(LOG_ESS) << "Source" << _source; + auto result = QHash(); - auto data = new KSysGuard::SensorInfo(); - if (_source == "name") { - data->name = "Current desktop name"; - data->variantType = QVariant::String; - data->unit = KSysGuard::UnitNone; - } else if (_source == "number") { - data->min = 0; - data->name = "Current desktop number"; - data->variantType = QVariant::Int; - data->unit = KSysGuard::UnitNone; - } else if (_source == "names") { - data->name = "All desktops by name"; - data->variantType = QVariant::StringList; - data->unit = KSysGuard::UnitNone; - } else if (_source == "count") { - data->min = 0; - data->name = "Desktops count"; - data->variantType = QVariant::Int; - data->unit = KSysGuard::UnitNone; + result.insert("name", makeSensorInfo("Current desktop name", QVariant::String)); + result.insert("number", makeSensorInfo("Current desktop number", QVariant::Int)); + result.insert("count", makeSensorInfo("Desktops count", QVariant::Int)); + + return result; +} + + +QHash> DesktopSource::extractDesktops(const QDBusArgument &_result) +{ + QHash> result; + + _result.beginArray(); + while (!_result.atEnd()) { + _result.beginStructure(); + + int index; + QString uuid, name; + _result >> index >> uuid >> name; + + _result.endStructure(); + + result[uuid] = {index, name}; } + _result.endArray(); - return data; + return result; } -QStringList DesktopSource::sources() const +QVariant DesktopSource::getDBusProperty(const QVariantList &_args) { - QStringList sources; - sources.append("name"); - sources.append("number"); - sources.append("names"); - sources.append("count"); + qCDebug(LOG_ESS) << "Get VDI property" << _args; + + auto bus = QDBusConnection::sessionBus(); + auto request + = QDBusMessage::createMethodCall(KWinDBusAdapter, VDIDBusPath, PropertyDBusInterface, PropertyDBusMethod); + request.setArguments(_args); - return sources; + auto response = bus.call(request, QDBus::BlockWithGui, REQUEST_TIMEOUT); + + if ((response.type() != QDBusMessage::ReplyMessage) || (response.arguments().isEmpty())) { + qCWarning(LOG_ESS) << "Error message" << response.errorMessage(); + return {}; + } else { + auto value = response.arguments().first(); + return value.value().variant(); + } } diff --git a/sources/extsysmonsources/desktopsource.h b/sources/extsysmonsources/desktopsource.h index d7e36cfe..2f8404fb 100644 --- a/sources/extsysmonsources/desktopsource.h +++ b/sources/extsysmonsources/desktopsource.h @@ -22,22 +22,23 @@ #include "abstractextsysmonsource.h" -namespace TaskManager -{ -class VirtualDesktopInfo; -} class DesktopSource : public AbstractExtSysMonSource { Q_OBJECT public: - explicit DesktopSource(QObject *_parent, const QStringList &_args); - ~DesktopSource() override; + static constexpr auto KWinDBusAdapter = "org.kde.KWin"; + static constexpr auto VDIDBusPath = "/VirtualDesktopManager"; + + static constexpr auto PropertyDBusInterface = "org.freedesktop.DBus.Properties"; + static constexpr auto PropertyDBusMethod = "Get"; + + explicit DesktopSource(QObject *_parent); + ~DesktopSource() override = default; QVariant data(const QString &_source) override; - [[nodiscard]] KSysGuard::SensorInfo *initialData(const QString &_source) const override; - void run() override{}; - [[nodiscard]] QStringList sources() const override; + [[nodiscard]] QHash sources() const override; private: - TaskManager::VirtualDesktopInfo *m_vdi = nullptr; + static QHash> extractDesktops(const QDBusArgument &_result); + static QVariant getDBusProperty(const QVariantList &_args); }; diff --git a/sources/extsysmonsources/extsysmonsensor.cpp b/sources/extsysmonsources/extsysmonsensor.cpp index e8b5c502..b910aec4 100644 --- a/sources/extsysmonsources/extsysmonsensor.cpp +++ b/sources/extsysmonsources/extsysmonsensor.cpp @@ -33,8 +33,8 @@ ExtSysMonSensor::ExtSysMonSensor(KSysGuard::SensorContainer *_parent, const QStr loadProperties(); - connect(this, &SensorObject::subscribedChanged, [this](bool _state) { changeSubscription(_state); }); - connect(m_timer, &QTimer::timeout, [this]() { update(); }); + connect(this, &SensorObject::subscribedChanged, this, &ExtSysMonSensor::changeSubscription); + connect(m_timer, &QTimer::timeout, this, &ExtSysMonSensor::update); } @@ -61,21 +61,22 @@ void ExtSysMonSensor::changeSubscription(bool _subscribed) void ExtSysMonSensor::update() { - for (auto &source : m_source->sources()) { - auto property = sensor(source); - if (!property->isSubscribed()) + for (auto sensor : sensors()) { + if (!sensor->isSubscribed()) continue; // skip properties which are not explicitly subscribed - auto value = m_source->data(source); - property->setValue(value); + auto value = m_source->data(sensor->id()); + sensor->setValue(value); } } void ExtSysMonSensor::loadProperties() { - for (auto &source : m_source->sources()) { - auto info = m_source->initialData(source); + auto sensors = m_source->sources(); + for (auto sensor = sensors.cbegin(); sensor != sensors.cend(); ++sensor) { + auto source = sensor.key(); + auto info = sensor.value(); auto property = new KSysGuard::SensorProperty(source, info->name, this); property->setUnit(info->unit); diff --git a/sources/extsysmonsources/extsysmonsensor.h b/sources/extsysmonsources/extsysmonsensor.h index e7fcf23a..26d85f74 100644 --- a/sources/extsysmonsources/extsysmonsensor.h +++ b/sources/extsysmonsources/extsysmonsensor.h @@ -31,6 +31,8 @@ class ExtSysMonSensor : public KSysGuard::SensorObject explicit ExtSysMonSensor(KSysGuard::SensorContainer *_parent, const QString &_id, const QString &_name, AbstractExtSysMonSource *_source); ~ExtSysMonSensor() override; + +public slots: void changeSubscription(bool _subscribed); void update(); diff --git a/sources/extsysmonsources/loadsource.cpp b/sources/extsysmonsources/loadsource.cpp index c2062ff0..acb6198e 100644 --- a/sources/extsysmonsources/loadsource.cpp +++ b/sources/extsysmonsources/loadsource.cpp @@ -15,26 +15,15 @@ * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * ***************************************************************************/ - #include "loadsource.h" -#include -#include - #include #include "awdebug.h" -LoadSource::LoadSource(QObject *_parent, const QStringList &_args) - : AbstractExtSysMonSource(_parent, _args) -{ - Q_ASSERT(_args.count() == 0); - qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; -} - - -LoadSource::~LoadSource() +LoadSource::LoadSource(QObject *_parent) + : AbstractExtSysMonSource(_parent) { qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; } @@ -48,28 +37,12 @@ QVariant LoadSource::data(const QString &_source) } -KSysGuard::SensorInfo *LoadSource::initialData(const QString &_source) const +QHash LoadSource::sources() const { - qCDebug(LOG_ESS) << "Source" << _source; - - auto data = new KSysGuard::SensorInfo(); - if (_source.startsWith("load")) { - data->min = 0; - data->max = 0; - data->name = "Simple sources for load tests"; - data->variantType = QVariant::Int; - data->unit = KSysGuard::UnitNone; - } - - return data; -} - + auto result = QHash(); -QStringList LoadSource::sources() const -{ - QStringList sources; - for (int i = 0; i < 1000; i++) - sources.append(QString("load%1").arg(i)); + for (auto i = 0; i < 1000; i++) + result.insert(QString("load%1").arg(i), makeSensorInfo("Simple sources for load tests", QVariant::Int)); - return sources; + return result; } diff --git a/sources/extsysmonsources/loadsource.h b/sources/extsysmonsources/loadsource.h index 6fdbb633..ca3b0e08 100644 --- a/sources/extsysmonsources/loadsource.h +++ b/sources/extsysmonsources/loadsource.h @@ -27,10 +27,8 @@ class LoadSource : public AbstractExtSysMonSource Q_OBJECT public: - explicit LoadSource(QObject *_parent, const QStringList &_args); - ~LoadSource() override; + explicit LoadSource(QObject *_parent); + ~LoadSource() override = default; QVariant data(const QString &_source) override; - [[nodiscard]] KSysGuard::SensorInfo *initialData(const QString &_source) const override; - void run() override{}; - [[nodiscard]] QStringList sources() const override; + [[nodiscard]] QHash sources() const override; }; diff --git a/sources/extsysmonsources/networksource.cpp b/sources/extsysmonsources/networksource.cpp index 3d62b423..0366bbe0 100644 --- a/sources/extsysmonsources/networksource.cpp +++ b/sources/extsysmonsources/networksource.cpp @@ -15,22 +15,17 @@ * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * ***************************************************************************/ - #include "networksource.h" -#include -#include - #include #include #include "awdebug.h" -NetworkSource::NetworkSource(QObject *_parent, const QStringList &_args) - : AbstractExtSysMonSource(_parent, _args) +NetworkSource::NetworkSource(QObject *_parent) + : AbstractExtSysMonSource(_parent) { - Q_ASSERT(_args.count() == 0); qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; m_process = new QProcess(nullptr); @@ -54,47 +49,26 @@ QVariant NetworkSource::data(const QString &_source) { qCDebug(LOG_ESS) << "Source" << _source; - if (!m_values.contains(_source)) - run(); - return m_values.take(_source); -} - - -KSysGuard::SensorInfo *NetworkSource::initialData(const QString &_source) const -{ - qCDebug(LOG_ESS) << "Source" << _source; - - auto data = new KSysGuard::SensorInfo(); if (_source == "device") { - data->name = "Current network device name"; - data->variantType = QVariant::String; - data->unit = KSysGuard::UnitNone; + return NetworkSource::getCurrentDevice(); } else if (_source == "ssid") { - data->name = "Current SSID name"; - data->variantType = QVariant::String; - data->unit = KSysGuard::UnitNone; + if (m_process->state() == QProcess::ProcessState::NotRunning) + m_process->start("iwgetid", {"-r"}); + return m_currentSsid; } - return data; + return {}; } -void NetworkSource::run() +QHash NetworkSource::sources() const { - m_values["device"] = NetworkSource::getCurrentDevice(); - if (m_process->state() == QProcess::ProcessState::NotRunning) { - m_process->start("iwgetid", {"-r"}); - } -} - + auto result = QHash(); -QStringList NetworkSource::sources() const -{ - QStringList sources; - sources.append("device"); - sources.append("ssid"); + result.insert("device", makeSensorInfo("Current network device name", QVariant::String)); + result.insert("ssid", makeSensorInfo("Current SSID name", QVariant::String)); - return sources; + return result; } @@ -106,7 +80,7 @@ void NetworkSource::updateSsid() QString qoutput = QString::fromUtf8(m_process->readAllStandardOutput()).trimmed(); qCInfo(LOG_ESS) << "Output" << qoutput; - m_values["ssid"] = qoutput; + m_currentSsid = qoutput; } diff --git a/sources/extsysmonsources/networksource.h b/sources/extsysmonsources/networksource.h index 60b42b9b..aba2c188 100644 --- a/sources/extsysmonsources/networksource.h +++ b/sources/extsysmonsources/networksource.h @@ -29,18 +29,17 @@ class NetworkSource : public AbstractExtSysMonSource Q_OBJECT public: - explicit NetworkSource(QObject *_parent, const QStringList &_args); + explicit NetworkSource(QObject *_parent); ~NetworkSource() override; QVariant data(const QString &_source) override; - [[nodiscard]] KSysGuard::SensorInfo *initialData(const QString &_source) const override; - void run() override; - [[nodiscard]] QStringList sources() const override; + void run(); + [[nodiscard]] QHash sources() const override; private slots: void updateSsid(); private: - QVariantHash m_values; + QString m_currentSsid; QProcess *m_process = nullptr; static QString getCurrentDevice(); }; diff --git a/sources/extsysmonsources/playersource.cpp b/sources/extsysmonsources/playersource.cpp index f95f2aa5..c41b5638 100644 --- a/sources/extsysmonsources/playersource.cpp +++ b/sources/extsysmonsources/playersource.cpp @@ -15,12 +15,8 @@ * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * ***************************************************************************/ - #include "playersource.h" -#include -#include - #include #include #include @@ -30,18 +26,17 @@ #include "awdebug.h" -PlayerSource::PlayerSource(QObject *_parent, const QStringList &_args) - : AbstractExtSysMonSource(_parent, _args) +PlayerSource::PlayerSource(QObject *_parent, QString _player, QString _mpdAddress, int _mpdPort, QString _mpris, + int _symbols) + : AbstractExtSysMonSource(_parent) + , m_mpdAddress(std::move(_mpdAddress)) + , m_mpdPort(_mpdPort) + , m_mpris(std::move(_mpris)) + , m_player(std::move(_player)) + , m_symbols(_symbols) { - Q_ASSERT(_args.count() == 5); qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; - m_player = _args.at(0); - m_mpdAddress = _args.at(1); - m_mpdPort = _args.at(2).toInt(); - m_mpris = _args.at(3); - m_symbols = _args.at(4).toInt(); - connect(&m_mpdSocket, &QTcpSocket::connected, this, &PlayerSource::mpdSocketConnected); connect(&m_mpdSocket, &QTcpSocket::readyRead, this, &PlayerSource::mpdSocketReadyRead); connect(&m_mpdSocket, &QTcpSocket::bytesWritten, this, &PlayerSource::mpdSocketWritten); @@ -62,26 +57,25 @@ QVariant PlayerSource::data(const QString &_source) qCDebug(LOG_ESS) << "Source" << _source; if (!m_values.contains(_source)) - run(); - QVariant value = m_values.take(_source); - return value; + run(); // syncronous update of all values + + return m_values.take(_source); } QString PlayerSource::getAutoMpris() { - QDBusMessage listServices = QDBusConnection::sessionBus().interface()->call(QDBus::BlockWithGui, "ListNames"); + auto listServices = QDBusConnection::sessionBus().interface()->call(QDBus::BlockWithGui, "ListNames"); if (listServices.arguments().isEmpty()) { qCWarning(LOG_ESS) << "Could not find any DBus service"; return ""; } - QStringList arguments = listServices.arguments().first().toStringList(); + auto arguments = listServices.arguments().first().toStringList(); - for (auto &arg : arguments) { - if (!arg.startsWith("org.mpris.MediaPlayer2.")) + for (auto &service : arguments) { + if (!service.startsWith("org.mpris.MediaPlayer2.")) continue; - qCInfo(LOG_ESS) << "Service found" << arg; - QString service = arg; + qCInfo(LOG_ESS) << "Service found" << service; service.remove("org.mpris.MediaPlayer2."); return service; } @@ -90,65 +84,6 @@ QString PlayerSource::getAutoMpris() } -KSysGuard::SensorInfo *PlayerSource::initialData(const QString &_source) const -{ - qCDebug(LOG_ESS) << "Source" << _source; - - auto data = new KSysGuard::SensorInfo(); - if (_source == "album") { - data->name = "Current song album"; - data->variantType = QVariant::String; - data->unit = KSysGuard::UnitNone; - } else if (_source == "salbum") { - data->name = QString("Current song album (%1 symbols)").arg(m_symbols); - data->variantType = QVariant::String; - data->unit = KSysGuard::UnitNone; - } else if (_source == "dalbum") { - data->name = QString("Current song album (%1 symbols, dynamic)").arg(m_symbols); - data->variantType = QVariant::String; - data->unit = KSysGuard::UnitNone; - } else if (_source == "artist") { - data->name = "Current song artist"; - data->variantType = QVariant::String; - data->unit = KSysGuard::UnitNone; - } else if (_source == "sartist") { - data->name = QString("Current song artist (%1 symbols)").arg(m_symbols); - data->variantType = QVariant::String; - data->unit = KSysGuard::UnitNone; - } else if (_source == "dartist") { - data->name = QString("Current song artist (%1 symbols, dynamic)").arg(m_symbols); - data->variantType = QVariant::String; - data->unit = KSysGuard::UnitNone; - } else if (_source == "duration") { - data->min = 0; - data->max = 0; - data->name = "Current song duration"; - data->variantType = QVariant::Int; - data->unit = KSysGuard::UnitSecond; - } else if (_source == "progress") { - data->min = 0; - data->max = 0; - data->name = "Current song progress"; - data->variantType = QVariant::Int; - data->unit = KSysGuard::UnitSecond; - } else if (_source == "title") { - data->name = "Current song title"; - data->variantType = QVariant::String; - data->unit = KSysGuard::UnitNone; - } else if (_source == "stitle") { - data->name = QString("Current song title (%1 symbols)").arg(m_symbols); - data->variantType = QVariant::String; - data->unit = KSysGuard::UnitNone; - } else if (_source == "dtitle") { - data->name = QString("Current song title (%1 symbols, dynamic)").arg(m_symbols); - data->variantType = QVariant::String; - data->unit = KSysGuard::UnitNone; - } - - return data; -} - - void PlayerSource::run() { // initial data @@ -176,22 +111,29 @@ void PlayerSource::run() } -QStringList PlayerSource::sources() const +QHash PlayerSource::sources() const { - QStringList sources; - sources.append("album"); - sources.append("dalbum"); - sources.append("salbum"); - sources.append("artist"); - sources.append("dartist"); - sources.append("sartist"); - sources.append("duration"); - sources.append("progress"); - sources.append("title"); - sources.append("dtitle"); - sources.append("stitle"); - - return sources; + auto result = QHash(); + + result.insert("album", makeSensorInfo("Current song album", QVariant::String)); + result.insert("salbum", + makeSensorInfo(QString("Current song album (%1 symbols)").arg(m_symbols), QVariant::String)); + result.insert("dalbum", + makeSensorInfo(QString("Current song album (%1 symbols, dynamic)").arg(m_symbols), QVariant::String)); + result.insert("artist", makeSensorInfo("Current song artist", QVariant::String)); + result.insert("sartist", + makeSensorInfo(QString("Current song artist (%1 symbols)").arg(m_symbols), QVariant::String)); + result.insert("dartist", makeSensorInfo(QString("Current song artist (%1 symbols, dynamic)").arg(m_symbols), + QVariant::String)); + result.insert("duration", makeSensorInfo("Current song duration", QVariant::Int, KSysGuard::UnitSecond)); + result.insert("progress", makeSensorInfo("Current song progress", QVariant::Int, KSysGuard::UnitSecond)); + result.insert("title", makeSensorInfo("Current song title", QVariant::String)); + result.insert("stitle", + makeSensorInfo(QString("Current song title (%1 symbols)").arg(m_symbols), QVariant::String)); + result.insert("dtitle", + makeSensorInfo(QString("Current song title (%1 symbols, dynamic)").arg(m_symbols), QVariant::String)); + + return result; } @@ -199,7 +141,7 @@ QString PlayerSource::buildString(const QString &_current, const QString &_value { qCDebug(LOG_ESS) << "Current value" << _current << "received" << _value << "will be stripped after" << _s; - int index = _value.indexOf(_current); + auto index = _value.indexOf(_current); if ((_current.isEmpty()) || ((index + _s + 1) > _value.length())) return QString("%1").arg(_value.left(_s), -_s, QLatin1Char(' ')); else @@ -230,7 +172,7 @@ void PlayerSource::mpdSocketConnected() void PlayerSource::mpdSocketReadyRead() { - QString qoutput = QString::fromUtf8(m_mpdSocket.readAll()).trimmed(); + auto qoutput = QString::fromUtf8(m_mpdSocket.readAll()).trimmed(); qCInfo(LOG_ESS) << "Output" << qoutput; // parse @@ -307,9 +249,8 @@ QVariantHash PlayerSource::getPlayerMprisInfo(const QString &_mpris) // /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get // string:'org.mpris.MediaPlayer2.Player' string:'Metadata' auto args = QVariantList({"org.mpris.MediaPlayer2.Player", "Metadata"}); - QDBusMessage request - = QDBusMessage::createMethodCall(QString("org.mpris.MediaPlayer2.%1").arg(_mpris), "/org/mpris/MediaPlayer2", - "org.freedesktop.DBus.Properties", "Get"); + auto request = QDBusMessage::createMethodCall(QString("org.mpris.MediaPlayer2.%1").arg(_mpris), + "/org/mpris/MediaPlayer2", "org.freedesktop.DBus.Properties", "Get"); request.setArguments(args); auto response = bus.call(request, QDBus::BlockWithGui, REQUEST_TIMEOUT); if ((response.type() != QDBusMessage::ReplyMessage) || (response.arguments().isEmpty())) { diff --git a/sources/extsysmonsources/playersource.h b/sources/extsysmonsources/playersource.h index 52b13ef1..4642e9c4 100644 --- a/sources/extsysmonsources/playersource.h +++ b/sources/extsysmonsources/playersource.h @@ -33,13 +33,13 @@ class PlayerSource : public AbstractExtSysMonSource public: const char *MPD_STATUS_REQUEST = "currentsong\nstatus\n"; - explicit PlayerSource(QObject *_parent, const QStringList &_args); + explicit PlayerSource(QObject *_parent, QString _player, QString _mpdAddress, int _mpdPort, QString _mpris, + int _symbols); ~PlayerSource() override; QVariant data(const QString &_source) override; static QString getAutoMpris(); - [[nodiscard]] KSysGuard::SensorInfo *initialData(const QString &_source) const override; - void run() override; - [[nodiscard]] QStringList sources() const override; + void run(); + [[nodiscard]] QHash sources() const override; // additional method to build dynamic tags static QString buildString(const QString &_current, const QString &_value, int _s); static QString stripString(const QString &_value, int _s); diff --git a/sources/extsysmonsources/processessource.cpp b/sources/extsysmonsources/processessource.cpp index e5792c01..b97db5eb 100644 --- a/sources/extsysmonsources/processessource.cpp +++ b/sources/extsysmonsources/processessource.cpp @@ -15,26 +15,15 @@ * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * ***************************************************************************/ - #include "processessource.h" -#include -#include - #include #include "awdebug.h" -ProcessesSource::ProcessesSource(QObject *_parent, const QStringList &_args) - : AbstractExtSysMonSource(_parent, _args) -{ - Q_ASSERT(_args.count() == 0); - qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; -} - - -ProcessesSource::~ProcessesSource() +ProcessesSource::ProcessesSource(QObject *_parent) + : AbstractExtSysMonSource(_parent) { qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; } @@ -45,45 +34,18 @@ QVariant ProcessesSource::data(const QString &_source) qCDebug(LOG_ESS) << "Source" << _source; if (!m_values.contains(_source)) - run(); - QVariant value = m_values.take(_source); - return value; -} - + run(); // syncronous update of all values -KSysGuard::SensorInfo *ProcessesSource::initialData(const QString &_source) const -{ - qCDebug(LOG_ESS) << "Source" << _source; - - auto data = new KSysGuard::SensorInfo(); - if (_source == "running") { - data->min = 0; - data->max = 0; - data->name = "Count of running processes"; - data->variantType = QVariant::Int; - data->unit = KSysGuard::UnitNone; - } else if (_source == "list") { - data->name = "All running processes list"; - data->variantType = QVariant::StringList; - data->unit = KSysGuard::UnitNone; - } else if (_source == "count") { - data->min = 0; - data->max = 0; - data->name = "Total count of processes"; - data->variantType = QVariant::Int; - data->unit = KSysGuard::UnitNone; - } - - return data; + return m_values.take(_source); } void ProcessesSource::run() { - QStringList allDirectories = QDir("/proc").entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name); - QStringList directories = allDirectories.filter(QRegularExpression("(\\d+)")); - QStringList running; + auto allDirectories = QDir("/proc").entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name); + auto directories = allDirectories.filter(QRegularExpression("(\\d+)")); + QStringList running; for (auto &dir : directories) { QFile statusFile(QString("/proc/%1/status").arg(dir)); if (!statusFile.open(QIODevice::ReadOnly | QIODevice::Text)) @@ -92,7 +54,7 @@ void ProcessesSource::run() if (!cmdFile.open(QIODevice::ReadOnly | QIODevice::Text)) continue; - QString output = statusFile.readAll(); + auto output = statusFile.readAll(); if (output.contains("running")) running.append(cmdFile.readAll()); statusFile.close(); @@ -105,12 +67,13 @@ void ProcessesSource::run() } -QStringList ProcessesSource::sources() const +QHash ProcessesSource::sources() const { - QStringList sources; - sources.append("running"); - sources.append("list"); - sources.append("count"); + auto result = QHash(); + + result.insert("running", makeSensorInfo("Count of running processes", QVariant::Int)); + result.insert("list", makeSensorInfo("All running processes list", QVariant::StringList)); + result.insert("count", makeSensorInfo("Total count of processes", QVariant::Int)); - return sources; + return result; } diff --git a/sources/extsysmonsources/processessource.h b/sources/extsysmonsources/processessource.h index 45c97b98..3fb05fa6 100644 --- a/sources/extsysmonsources/processessource.h +++ b/sources/extsysmonsources/processessource.h @@ -27,12 +27,11 @@ class ProcessesSource : public AbstractExtSysMonSource Q_OBJECT public: - explicit ProcessesSource(QObject *_parent, const QStringList &_args); - ~ProcessesSource() override; + explicit ProcessesSource(QObject *_parent); + ~ProcessesSource() override = default; QVariant data(const QString &_source) override; - [[nodiscard]] KSysGuard::SensorInfo *initialData(const QString &_source) const override; - void run() override; - [[nodiscard]] QStringList sources() const override; + void run(); + [[nodiscard]] QHash sources() const override; private: // configuration and values diff --git a/sources/extsysmonsources/quotessource.cpp b/sources/extsysmonsources/quotessource.cpp index 042b3674..0a85a34b 100644 --- a/sources/extsysmonsources/quotessource.cpp +++ b/sources/extsysmonsources/quotessource.cpp @@ -15,31 +15,19 @@ * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * ***************************************************************************/ - #include "quotessource.h" -#include -#include - #include "awdebug.h" #include "extquotes.h" -QuotesSource::QuotesSource(QObject *_parent, const QStringList &_args) - : AbstractExtSysMonSource(_parent, _args) +QuotesSource::QuotesSource(QObject *_parent) + : AbstractExtSysMonSource(_parent) { - Q_ASSERT(_args.count() == 0); qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; m_extQuotes = new ExtItemAggregator(nullptr, "quotes"); m_extQuotes->initSockets(); - m_sources = getSources(); -} - - -QuotesSource::~QuotesSource() -{ - qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; } @@ -47,82 +35,31 @@ QVariant QuotesSource::data(const QString &_source) { qCDebug(LOG_ESS) << "Source" << _source; - int ind = index(_source); - if (!m_values.contains(_source)) { - QVariantHash data = m_extQuotes->itemByTagNumber(ind)->run(); - for (auto &key : data.keys()) - m_values[key] = data[key]; - } - QVariant value = m_values.take(_source); - return value; -} - - -KSysGuard::SensorInfo *QuotesSource::initialData(const QString &_source) const -{ - qCDebug(LOG_ESS) << "Source" << _source; - - int ind = index(_source); - auto data = new KSysGuard::SensorInfo; - if (_source.startsWith("pricechg")) { - data->min = 0.0; - data->max = 0.0; - data->name = QString("Absolute price changes for '%1'").arg(m_extQuotes->itemByTagNumber(ind)->uniq()); - data->variantType = QVariant::Double; - data->unit = KSysGuard::UnitNone; - } else if (_source.startsWith("price")) { - data->min = 0.0; - data->max = 0.0; - data->name = QString("Price for '%1'").arg(m_extQuotes->itemByTagNumber(ind)->uniq()); - data->variantType = QVariant::Double; - data->unit = KSysGuard::UnitNone; - } else if (_source.startsWith("percpricechg")) { - data->min = -100.0; - data->max = 100.0; - data->name = QString("Price changes for '%1'").arg(m_extQuotes->itemByTagNumber(ind)->uniq()); - data->variantType = QVariant::Double; - data->unit = KSysGuard::UnitPercent; - } else if (_source.startsWith("volumechg")) { - data->min = 0; - data->max = 0; - data->name = QString("Absolute volume changes for '%1'").arg(m_extQuotes->itemByTagNumber(ind)->uniq()); - data->variantType = QVariant::Int; - data->unit = KSysGuard::UnitNone; - } else if (_source.startsWith("volume")) { - data->min = 0; - data->max = 0; - data->name = QString("Volume for '%1'").arg(m_extQuotes->itemByTagNumber(ind)->uniq()); - data->variantType = QVariant::Int; - data->unit = KSysGuard::UnitNone; - } else if (_source.startsWith("percvolumechg")) { - data->min = -100.0; - data->max = 100.0; - data->name = QString("Volume changes for '%1'").arg(m_extQuotes->itemByTagNumber(ind)->uniq()); - data->variantType = QVariant::Double; - data->unit = KSysGuard::UnitPercent; - } + if (!m_values.contains(_source)) + m_values = dataByItem(m_extQuotes, _source); - return data; + return m_values.take(_source); } -QStringList QuotesSource::sources() const +QHash QuotesSource::sources() const { - return m_sources; -} + auto result = QHash(); - -QStringList QuotesSource::getSources() -{ - QStringList sources; for (auto &item : m_extQuotes->activeItems()) { - sources.append(item->tag("price")); - sources.append(item->tag("pricechg")); - sources.append(item->tag("percpricechg")); - sources.append(item->tag("volume")); - sources.append(item->tag("volumechg")); - sources.append(item->tag("percvolumechg")); + result.insert(item->tag("pricechg"), + makeSensorInfo(QString("Absolute price changes for '%1'").arg(item->uniq()), QVariant::Double)); + result.insert(item->tag("price"), + makeSensorInfo(QString("Price for '%1'").arg(item->uniq()), QVariant::Double)); + result.insert(item->tag("percpricechg"), makeSensorInfo(QString("Price changes for '%1'").arg(item->uniq()), + QVariant::Double, KSysGuard::UnitPercent, 0, 100)); + result.insert(item->tag("volumechg"), + makeSensorInfo(QString("Absolute volume changes for '%1'").arg(item->uniq()), QVariant::Double)); + result.insert(item->tag("volume"), + makeSensorInfo(QString("Volume for '%1'").arg(item->uniq()), QVariant::Double)); + result.insert(item->tag("percvolumechg"), makeSensorInfo(QString("Volume changes for '%1'").arg(item->uniq()), + QVariant::Double, KSysGuard::UnitPercent, 0, 100)); } - return sources; + return result; } diff --git a/sources/extsysmonsources/quotessource.h b/sources/extsysmonsources/quotessource.h index 87ac6339..b3376518 100644 --- a/sources/extsysmonsources/quotessource.h +++ b/sources/extsysmonsources/quotessource.h @@ -30,17 +30,13 @@ class QuotesSource : public AbstractExtSysMonSource Q_OBJECT public: - explicit QuotesSource(QObject *_parent, const QStringList &_args); - ~QuotesSource() override; + explicit QuotesSource(QObject *_parent); + ~QuotesSource() override = default; QVariant data(const QString &_source) override; - [[nodiscard]] KSysGuard::SensorInfo *initialData(const QString &_source) const override; - void run() override{}; - [[nodiscard]] QStringList sources() const override; + [[nodiscard]] QHash sources() const override; private: - QStringList getSources(); // configuration and values ExtItemAggregator *m_extQuotes = nullptr; - QStringList m_sources; QVariantHash m_values; }; diff --git a/sources/extsysmonsources/requestsource.cpp b/sources/extsysmonsources/requestsource.cpp index 2ac9eece..dd1a1fad 100644 --- a/sources/extsysmonsources/requestsource.cpp +++ b/sources/extsysmonsources/requestsource.cpp @@ -15,31 +15,19 @@ * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * ***************************************************************************/ - #include "requestsource.h" -#include -#include - #include "awdebug.h" #include "extnetworkrequest.h" -RequestSource::RequestSource(QObject *_parent, const QStringList &_args) - : AbstractExtSysMonSource(_parent, _args) +RequestSource::RequestSource(QObject *_parent) + : AbstractExtSysMonSource(_parent) { - Q_ASSERT(_args.count() == 0); qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; m_extNetRequest = new ExtItemAggregator(nullptr, "requests"); m_extNetRequest->initSockets(); - m_sources = getSources(); -} - - -RequestSource::~RequestSource() -{ - qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; } @@ -47,44 +35,18 @@ QVariant RequestSource::data(const QString &_source) { qCDebug(LOG_ESS) << "Source" << _source; - int ind = index(_source); - if (!m_values.contains(_source)) { - QVariantHash data = m_extNetRequest->itemByTagNumber(ind)->run(); - for (auto &key : data.keys()) - m_values[key] = data[key]; - } - QVariant value = m_values.take(_source); - return value; + // there are only one value + return dataByItem(m_extNetRequest, _source).values().first(); } -KSysGuard::SensorInfo *RequestSource::initialData(const QString &_source) const +QHash RequestSource::sources() const { - qCDebug(LOG_ESS) << "Source" << _source; - - int ind = index(_source); - auto data = new KSysGuard::SensorInfo(); - if (_source.startsWith("response")) { - data->name = QString("Network response for %1").arg(m_extNetRequest->itemByTagNumber(ind)->uniq()); - data->variantType = QVariant::String; - data->unit = KSysGuard::UnitNone; - } + auto result = QHash(); - return data; -} - - -QStringList RequestSource::sources() const -{ - return m_sources; -} - - -QStringList RequestSource::getSources() -{ - QStringList sources; for (auto &item : m_extNetRequest->activeItems()) - sources.append(item->tag("response")); + result.insert(item->tag("response"), + makeSensorInfo(QString("Network response for %1").arg(item->uniq()), QVariant::String)); - return sources; + return result; } diff --git a/sources/extsysmonsources/requestsource.h b/sources/extsysmonsources/requestsource.h index c63e1ca2..08f4977e 100644 --- a/sources/extsysmonsources/requestsource.h +++ b/sources/extsysmonsources/requestsource.h @@ -30,17 +30,13 @@ class RequestSource : public AbstractExtSysMonSource Q_OBJECT public: - explicit RequestSource(QObject *_parent, const QStringList &_args); - ~RequestSource() override; + explicit RequestSource(QObject *_parent); + ~RequestSource() override = default; QVariant data(const QString &_source) override; - [[nodiscard]] KSysGuard::SensorInfo *initialData(const QString &_source) const override; - void run() override{}; - [[nodiscard]] QStringList sources() const override; + [[nodiscard]] QHash sources() const override; private: - QStringList getSources(); // configuration and values ExtItemAggregator *m_extNetRequest = nullptr; - QStringList m_sources; QVariantHash m_values; }; diff --git a/sources/extsysmonsources/systeminfosource.cpp b/sources/extsysmonsources/systeminfosource.cpp index 4a5dbe16..a77b8a8b 100644 --- a/sources/extsysmonsources/systeminfosource.cpp +++ b/sources/extsysmonsources/systeminfosource.cpp @@ -15,7 +15,6 @@ * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * ***************************************************************************/ - #include "systeminfosource.h" #include @@ -30,15 +29,8 @@ #include "awdebug.h" -SystemInfoSource::SystemInfoSource(QObject *_parent, const QStringList &_args) - : AbstractExtSysMonSource(_parent, _args) -{ - Q_ASSERT(_args.count() == 0); - qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; -} - - -SystemInfoSource::~SystemInfoSource() +SystemInfoSource::SystemInfoSource(QObject *_parent) + : AbstractExtSysMonSource(_parent) { qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; } @@ -48,55 +40,30 @@ QVariant SystemInfoSource::data(const QString &_source) { qCDebug(LOG_ESS) << "Source" << _source; - if (!m_values.contains(_source)) - run(); - return m_values.take(_source); -} - - -KSysGuard::SensorInfo *SystemInfoSource::initialData(const QString &_source) const -{ - qCDebug(LOG_ESS) << "Source" << _source; - - auto data = new KSysGuard::SensorInfo(); if (_source == "brightness") { - data->min = 0.0; - data->max = 100.0; - data->name = "Screen brightness"; - data->variantType = QVariant::Double; - data->unit = KSysGuard::UnitPercent; + return SystemInfoSource::getCurrentBrightness(); } else if (_source == "volume") { - data->min = 0.0; - data->max = 100.0; - data->name = "Master volume"; - data->variantType = QVariant::Double; - data->unit = KSysGuard::UnitPercent; + return SystemInfoSource::getCurrentVolume(); } - return data; + return {}; } -void SystemInfoSource::run() +QHash SystemInfoSource::sources() const { - m_values["brightness"] = SystemInfoSource::getCurrentBrightness(); - m_values["volume"] = SystemInfoSource::getCurrentVolume(); -} - + auto result = QHash(); -QStringList SystemInfoSource::sources() const -{ - QStringList sources; - sources.append("brightness"); - sources.append("volume"); + result.insert("brightness", makeSensorInfo("Screen brightness", QVariant::Double, KSysGuard::UnitPercent, 0, 100)); + result.insert("volume", makeSensorInfo("Master volume", QVariant::Double, KSysGuard::UnitNone)); - return sources; + return result; } -QVariant SystemInfoSource::fromDBusVariant(const QVariant &value) +QVariant SystemInfoSource::fromDBusVariant(const QVariant &_value) { - return value.value().variant(); + return _value.value().variant(); } @@ -122,10 +89,9 @@ double SystemInfoSource::getCurrentVolume() qCDebug(LOG_ESS) << "Get current volume"; // current device first - auto currentMixer - = fromDBusVariant(sendDBusRequest("org.kde.kmix", "/Mixers", "org.freedesktop.DBus.Properties", "Get", - QVariantList({"org.kde.KMix.MixSet", "currentMasterMixer"}))) - .toString(); + auto currentMixer = fromDBusVariant(sendDBusRequest("org.kde.kmix", "/Mixers", "org.freedesktop.DBus.Properties", + "Get", {"org.kde.KMix.MixSet", "currentMasterMixer"})) + .toString(); if (currentMixer.isEmpty()) { qCWarning(LOG_ESS) << "Mixer is empty"; @@ -134,38 +100,37 @@ double SystemInfoSource::getCurrentVolume() currentMixer.replace(":", "_").replace(".", "_").replace("-", "_"); // get capture device - auto currentControl - = fromDBusVariant(sendDBusRequest("org.kde.kmix", "/Mixers", "org.freedesktop.DBus.Properties", "Get", - QVariantList({"org.kde.KMix.MixSet", "currentMasterControl"}))) - .toString(); + auto currentControl = fromDBusVariant(sendDBusRequest("org.kde.kmix", "/Mixers", "org.freedesktop.DBus.Properties", + "Get", {"org.kde.KMix.MixSet", "currentMasterControl"})) + .toString(); if (currentControl.isEmpty()) { qCWarning(LOG_ESS) << "Control is empty"; return std::numeric_limits::quiet_NaN(); } currentControl.replace(":", "_").replace(".", "_").replace("-", "_"); - auto path = QString("/Mixers/%1/%2").arg(currentMixer).arg(currentControl); + auto path = QString("/Mixers/%1/%2").arg(currentMixer, currentControl); return fromDBusVariant(sendDBusRequest("org.kde.kmix", path, "org.freedesktop.DBus.Properties", "Get", - QVariantList({"org.kde.KMix.Control", "volume"}))) + {"org.kde.KMix.Control", "volume"})) .toDouble(); } -QVariant SystemInfoSource::sendDBusRequest(const QString &destination, const QString &path, const QString &interface, - const QString &method, const QVariantList &args) +QVariant SystemInfoSource::sendDBusRequest(const QString &_destination, const QString &_path, const QString &_interface, + const QString &_method, const QVariantList &_args) { - qCDebug(LOG_ESS) << "Send dbus request" << destination << path << interface << method << args; + qCDebug(LOG_ESS) << "Send dbus request" << _destination << _path << _interface << _method << _args; auto bus = QDBusConnection::sessionBus(); - auto request = QDBusMessage::createMethodCall(destination, path, interface, method); - if (!args.isEmpty()) - request.setArguments(args); + auto request = QDBusMessage::createMethodCall(_destination, _path, _interface, _method); + if (!_args.isEmpty()) + request.setArguments(_args); auto response = bus.call(request, QDBus::BlockWithGui, REQUEST_TIMEOUT); if ((response.type() != QDBusMessage::ReplyMessage) || (response.arguments().isEmpty())) { qCWarning(LOG_ESS) << "Error message" << response.errorMessage(); - return QVariant(); + return {}; } else { return response.arguments().first(); } diff --git a/sources/extsysmonsources/systeminfosource.h b/sources/extsysmonsources/systeminfosource.h index b34532ae..2d58dce7 100644 --- a/sources/extsysmonsources/systeminfosource.h +++ b/sources/extsysmonsources/systeminfosource.h @@ -27,19 +27,16 @@ class SystemInfoSource : public AbstractExtSysMonSource Q_OBJECT public: - explicit SystemInfoSource(QObject *_parent, const QStringList &_args); - ~SystemInfoSource() override; + explicit SystemInfoSource(QObject *_parent); + ~SystemInfoSource() override = default; QVariant data(const QString &_source) override; - [[nodiscard]] KSysGuard::SensorInfo *initialData(const QString &_source) const override; - void run() override; - [[nodiscard]] QStringList sources() const override; + [[nodiscard]] QHash sources() const override; private: // configuration and values - QVariantHash m_values; - static QVariant fromDBusVariant(const QVariant &value); + static QVariant fromDBusVariant(const QVariant &_value); static double getCurrentBrightness(); static double getCurrentVolume(); - static QVariant sendDBusRequest(const QString &destination, const QString &path, const QString &interface, - const QString &method, const QVariantList &args = QVariantList()); + static QVariant sendDBusRequest(const QString &_destination, const QString &_path, const QString &_interface, + const QString &_method, const QVariantList &_args = {}); }; diff --git a/sources/extsysmonsources/timesource.cpp b/sources/extsysmonsources/timesource.cpp index 9e02dead..4a7bdd6e 100644 --- a/sources/extsysmonsources/timesource.cpp +++ b/sources/extsysmonsources/timesource.cpp @@ -17,16 +17,12 @@ #include "timesource.h" -#include -#include - #include "awdebug.h" -TimeSource::TimeSource(QObject *_parent, const QStringList &_args) - : AbstractExtSysMonSource(_parent, _args) +TimeSource::TimeSource(QObject *_parent) + : AbstractExtSysMonSource(_parent) { - Q_ASSERT(_args.count() == 0); qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; } @@ -43,20 +39,11 @@ QVariant TimeSource::data(const QString &_source) } -KSysGuard::SensorInfo *TimeSource::initialData(const QString &_source) const +QHash TimeSource::sources() const { - qCDebug(LOG_ESS) << "Source" << _source; - - auto data = new KSysGuard::SensorInfo(); - data->name = "Current time"; - data->variantType = QVariant::LongLong; - data->unit = KSysGuard::UnitSecond; - - return data; -} + auto result = QHash(); + result.insert("now", makeSensorInfo("Current time", QVariant::LongLong, KSysGuard::UnitSecond)); -QStringList TimeSource::sources() const -{ - return QStringList({"now"}); + return result; } diff --git a/sources/extsysmonsources/timesource.h b/sources/extsysmonsources/timesource.h index 18e51e91..dbbd80a5 100644 --- a/sources/extsysmonsources/timesource.h +++ b/sources/extsysmonsources/timesource.h @@ -27,9 +27,8 @@ class TimeSource : public AbstractExtSysMonSource Q_OBJECT public: - explicit TimeSource(QObject *_parent, const QStringList &_args); + explicit TimeSource(QObject *_parent); + ~TimeSource() override = default; QVariant data(const QString &_source) override; - [[nodiscard]] KSysGuard::SensorInfo *initialData(const QString &_source) const override; - void run() override{}; - [[nodiscard]] QStringList sources() const override; + [[nodiscard]] QHash sources() const override; }; diff --git a/sources/extsysmonsources/upgradesource.cpp b/sources/extsysmonsources/upgradesource.cpp index f278bcf1..92207b17 100644 --- a/sources/extsysmonsources/upgradesource.cpp +++ b/sources/extsysmonsources/upgradesource.cpp @@ -15,31 +15,19 @@ * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * ***************************************************************************/ - #include "upgradesource.h" -#include -#include - #include "awdebug.h" #include "extupgrade.h" -UpgradeSource::UpgradeSource(QObject *_parent, const QStringList &_args) - : AbstractExtSysMonSource(_parent, _args) +UpgradeSource::UpgradeSource(QObject *_parent) + : AbstractExtSysMonSource(_parent) { - Q_ASSERT(_args.count() == 0); qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; m_extUpgrade = new ExtItemAggregator(nullptr, "upgrade"); m_extUpgrade->initSockets(); - m_sources = getSources(); -} - - -UpgradeSource::~UpgradeSource() -{ - qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; } @@ -48,34 +36,17 @@ QVariant UpgradeSource::data(const QString &_source) qCDebug(LOG_ESS) << "Source" << _source; // there are only one value - return m_extUpgrade->itemByTagNumber(index(_source))->run().values().first(); + return dataByItem(m_extUpgrade, _source).values().first(); } -KSysGuard::SensorInfo *UpgradeSource::initialData(const QString &_source) const +QHash UpgradeSource::sources() const { - qCDebug(LOG_ESS) << "Source" << _source; - - auto data = new KSysGuard::SensorInfo(); - data->name = QString("Package manager '%1' metadata").arg(m_extUpgrade->itemByTagNumber(index(_source))->uniq()); - data->variantType = QVariant::String; - data->unit = KSysGuard::UnitNone; + auto result = QHash(); - return data; -} - - -QStringList UpgradeSource::sources() const -{ - return m_sources; -} - - -QStringList UpgradeSource::getSources() -{ - QStringList sources; for (auto &item : m_extUpgrade->activeItems()) - sources.append(item->tag("pkgcount")); + result.insert(item->tag("pkgcount"), + makeSensorInfo(QString("Package manager '%1' metadata").arg(item->uniq()), QVariant::Int)); - return sources; + return result; } diff --git a/sources/extsysmonsources/upgradesource.h b/sources/extsysmonsources/upgradesource.h index 566056cd..c80955dc 100644 --- a/sources/extsysmonsources/upgradesource.h +++ b/sources/extsysmonsources/upgradesource.h @@ -30,16 +30,12 @@ class UpgradeSource : public AbstractExtSysMonSource Q_OBJECT public: - explicit UpgradeSource(QObject *_parent, const QStringList &_args); - ~UpgradeSource() override; + explicit UpgradeSource(QObject *_parent); + ~UpgradeSource() override = default; QVariant data(const QString &_source) override; - [[nodiscard]] KSysGuard::SensorInfo *initialData(const QString &_source) const override; - void run() override{}; - [[nodiscard]] QStringList sources() const override; + [[nodiscard]] QHash sources() const override; private: - QStringList getSources(); // configuration and values ExtItemAggregator *m_extUpgrade = nullptr; - QStringList m_sources; }; diff --git a/sources/extsysmonsources/weathersource.cpp b/sources/extsysmonsources/weathersource.cpp index ee76e567..1435aed9 100644 --- a/sources/extsysmonsources/weathersource.cpp +++ b/sources/extsysmonsources/weathersource.cpp @@ -15,31 +15,19 @@ * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * ***************************************************************************/ - #include "weathersource.h" -#include -#include - #include "awdebug.h" #include "extweather.h" -WeatherSource::WeatherSource(QObject *_parent, const QStringList &_args) - : AbstractExtSysMonSource(_parent, _args) +WeatherSource::WeatherSource(QObject *_parent) + : AbstractExtSysMonSource(_parent) { - Q_ASSERT(_args.count() == 0); qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; m_extWeather = new ExtItemAggregator(nullptr, "weather"); m_extWeather->initSockets(); - m_sources = getSources(); -} - - -WeatherSource::~WeatherSource() -{ - qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; } @@ -47,76 +35,31 @@ QVariant WeatherSource::data(const QString &_source) { qCDebug(LOG_ESS) << "Source" << _source; - int ind = index(_source); - if (!m_values.contains(_source)) { - auto data = m_extWeather->itemByTagNumber(ind)->run(); - m_values.insert(data); - } - return m_values.take(_source); -} - - -KSysGuard::SensorInfo *WeatherSource::initialData(const QString &_source) const -{ - qCDebug(LOG_ESS) << "Source" << _source; - - int ind = index(_source); - auto data = new KSysGuard::SensorInfo(); - if (_source.startsWith("weatherId")) { - data->min = 0; - data->max = 1000; - data->name = QString("Numeric weather ID for '%1'").arg(m_extWeather->itemByTagNumber(ind)->uniq()); - data->variantType = QVariant::Int; - data->unit = KSysGuard::UnitNone; - } else if (_source.startsWith("weather")) { - data->name = QString("ID string map for '%1'").arg(m_extWeather->itemByTagNumber(ind)->uniq()); - data->variantType = QVariant::String; - data->unit = KSysGuard::UnitNone; - } else if (_source.startsWith("humidity")) { - data->min = 0; - data->max = 100; - data->name = QString("Humidity for '%1'").arg(m_extWeather->itemByTagNumber(ind)->uniq()); - data->variantType = QVariant::Int; - data->unit = KSysGuard::UnitPercent; - } else if (_source.startsWith("pressure")) { - data->min = 0; - data->max = 0; - data->name = QString("Atmospheric pressure for '%1'").arg(m_extWeather->itemByTagNumber(ind)->uniq()); - data->variantType = QVariant::Int; - data->unit = KSysGuard::UnitNone; - } else if (_source.startsWith("temperature")) { - data->min = 0.0; - data->max = 0.0; - data->name = QString("Temperature for '%1'").arg(m_extWeather->itemByTagNumber(ind)->uniq()); - data->variantType = QVariant::Double; - data->unit = KSysGuard::UnitCelsius; - } else if (_source.startsWith("timestamp")) { - data->name = QString("Timestamp for '%1'").arg(m_extWeather->itemByTagNumber(ind)->uniq()); - data->variantType = QVariant::DateTime; - data->unit = KSysGuard::UnitNone; - } + if (!m_values.contains(_source)) + m_values = dataByItem(m_extWeather, _source); - return data; + return m_values.take(_source); } -QStringList WeatherSource::sources() const +QHash WeatherSource::sources() const { - return m_sources; -} + auto result = QHash(); - -QStringList WeatherSource::getSources() -{ - QStringList sources; for (auto &item : m_extWeather->activeItems()) { - sources.append(item->tag("weatherId")); - sources.append(item->tag("weather")); - sources.append(item->tag("humidity")); - sources.append(item->tag("pressure")); - sources.append(item->tag("temperature")); - sources.append(item->tag("timestamp")); + result.insert(item->tag("weatherId"), makeSensorInfo(QString("Numeric weather ID for '%1'").arg(item->uniq()), + QVariant::Int, KSysGuard::UnitNone, 0, 1000)); + result.insert(item->tag("weather"), + makeSensorInfo(QString("ID string map for '%1'").arg(item->uniq()), QVariant::String)); + result.insert(item->tag("humidity"), makeSensorInfo(QString("Humidity for '%1'").arg(item->uniq()), + QVariant::Int, KSysGuard::UnitPercent, 0, 100)); + result.insert(item->tag("pressure"), + makeSensorInfo(QString("Atmospheric pressure for '%1'").arg(item->uniq()), QVariant::Int)); + result.insert(item->tag("temperature"), makeSensorInfo(QString("Temperature for '%1'").arg(item->uniq()), + QVariant::Double, KSysGuard::UnitCelsius)); + result.insert(item->tag("timestamp"), makeSensorInfo(QString("Timestamp for '%1'").arg(item->uniq()), + QVariant::DateTime, KSysGuard::UnitNone)); } - return sources; + return result; } diff --git a/sources/extsysmonsources/weathersource.h b/sources/extsysmonsources/weathersource.h index d704471b..e69d4d8b 100644 --- a/sources/extsysmonsources/weathersource.h +++ b/sources/extsysmonsources/weathersource.h @@ -30,17 +30,13 @@ class WeatherSource : public AbstractExtSysMonSource Q_OBJECT public: - explicit WeatherSource(QObject *_parent, const QStringList &_args); - ~WeatherSource() override; + explicit WeatherSource(QObject *_parent); + ~WeatherSource() override = default; QVariant data(const QString &_source) override; - [[nodiscard]] KSysGuard::SensorInfo *initialData(const QString &_source) const override; - void run() override{}; - [[nodiscard]] QStringList sources() const override; + [[nodiscard]] QHash sources() const override; private: - QStringList getSources(); // configuration and values ExtItemAggregator *m_extWeather = nullptr; - QStringList m_sources; QVariantHash m_values; }; diff --git a/sources/test/testabstractextitem.cpp b/sources/test/testabstractextitem.cpp index 8dfd9530..f07b2eb0 100644 --- a/sources/test/testabstractextitem.cpp +++ b/sources/test/testabstractextitem.cpp @@ -15,7 +15,6 @@ * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * ***************************************************************************/ - #include "testabstractextitem.h" #include @@ -75,7 +74,7 @@ void TestAbstractExtItem::test_configuration() { extItem->writeConfiguration(); - ExtUpgrade *newExtItem = new ExtUpgrade(nullptr, writeFileName); + auto newExtItem = new ExtUpgrade(nullptr, writeFileName); QCOMPARE(newExtItem->isActive(), extItem->isActive()); QCOMPARE(newExtItem->comment(), extItem->comment()); QCOMPARE(newExtItem->fileName(), writeFileName); @@ -98,7 +97,7 @@ void TestAbstractExtItem::test_bumpApi() void TestAbstractExtItem::test_delete() { - ExtUpgrade *newExtItem = new ExtUpgrade(nullptr, writeFileName); + auto newExtItem = new ExtUpgrade(nullptr, writeFileName); QVERIFY(newExtItem->tryDelete()); QVERIFY(!QFile::exists(writeFileName)); @@ -109,7 +108,7 @@ void TestAbstractExtItem::test_delete() void TestAbstractExtItem::test_copy() { - ExtUpgrade *newExtItem = extItem->copy("/dev/null", 1); + auto newExtItem = extItem->copy("/dev/null", 1); QCOMPARE(newExtItem->isActive(), extItem->isActive()); QCOMPARE(newExtItem->apiVersion(), extItem->apiVersion()); diff --git a/sources/test/testabstractformatter.cpp b/sources/test/testabstractformatter.cpp index 78cc30d3..ccd3fcb8 100644 --- a/sources/test/testabstractformatter.cpp +++ b/sources/test/testabstractformatter.cpp @@ -15,7 +15,6 @@ * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * ***************************************************************************/ - #include "testabstractformatter.h" #include @@ -42,7 +41,7 @@ void TestAbstractFormatter::test_values() {} void TestAbstractFormatter::test_type() { - QString type = AWTestLibrary::randomString(); + auto type = AWTestLibrary::randomString(); QEXPECT_FAIL("", "Will fail because of invalid format", Continue); formatter->setStrType(type); QCOMPARE(formatter->strType(), type); @@ -54,7 +53,7 @@ void TestAbstractFormatter::test_type() void TestAbstractFormatter::test_copy() { - AWNoFormatter *newFormatter = formatter->copy("/dev/null", 1); + auto newFormatter = formatter->copy("/dev/null", 1); QCOMPARE(newFormatter->type(), formatter->type()); QCOMPARE(newFormatter->name(), formatter->name()); diff --git a/sources/test/testawbugreporter.cpp b/sources/test/testawbugreporter.cpp index ed181097..8cf26ee3 100644 --- a/sources/test/testawbugreporter.cpp +++ b/sources/test/testawbugreporter.cpp @@ -40,7 +40,7 @@ void TestAWBugReporter::cleanupTestCase() void TestAWBugReporter::test_generateText() { data = AWTestLibrary::randomStringList(4); - QString output = plugin->generateText(data.at(0), data.at(1), data.at(2), data.at(3)); + auto output = plugin->generateText(data.at(0), data.at(1), data.at(2), data.at(3)); for (auto &string : data) QVERIFY(output.contains(string)); diff --git a/sources/test/testawconfighelper.cpp b/sources/test/testawconfighelper.cpp index 18b7c56a..c10ab4c4 100644 --- a/sources/test/testawconfighelper.cpp +++ b/sources/test/testawconfighelper.cpp @@ -15,7 +15,6 @@ * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * ***************************************************************************/ - #include "testawconfighelper.h" #include @@ -45,7 +44,7 @@ void TestAWConfigHelper::test_configurationDirectory() void TestAWConfigHelper::test_exportConfiguration() { - QStringList keys = AWTestLibrary::randomStringList(); + auto keys = AWTestLibrary::randomStringList(); for (auto &key : keys) map[key] = AWTestLibrary::randomString(); filename = AWTestLibrary::randomFilenames().first; @@ -56,7 +55,7 @@ void TestAWConfigHelper::test_exportConfiguration() void TestAWConfigHelper::test_importConfiguration() { - QVariantMap imported = plugin->importConfiguration(filename, true, true, true); + auto imported = plugin->importConfiguration(filename, true, true, true); QVariantMap converted; for (auto &key : map.keys()) converted[key] = map.value(key); diff --git a/sources/test/testawkeycache.cpp b/sources/test/testawkeycache.cpp index 22c3cfcd..dd799db7 100644 --- a/sources/test/testawkeycache.cpp +++ b/sources/test/testawkeycache.cpp @@ -15,7 +15,6 @@ * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * ***************************************************************************/ - #include "testawkeycache.h" #include diff --git a/sources/test/testawkeys.cpp b/sources/test/testawkeys.cpp index 909753c0..4cea17f0 100644 --- a/sources/test/testawkeys.cpp +++ b/sources/test/testawkeys.cpp @@ -15,7 +15,6 @@ * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * ***************************************************************************/ - #include "testawkeys.h" #include @@ -82,10 +81,10 @@ void TestAWKeys::test_hddDevices() void TestAWKeys::test_dictKeys() { - QStringList keys = plugin->dictKeys(); + auto keys = plugin->dictKeys(); QVERIFY(!keys.isEmpty()); - QStringList sorted = plugin->dictKeys(true); + auto sorted = plugin->dictKeys(true); QVERIFY(!sorted.isEmpty()); QEXPECT_FAIL("", "Sorted and non-sorted lists should differ", Continue); QCOMPARE(keys, sorted); @@ -101,11 +100,11 @@ void TestAWKeys::test_pattern() QVERIFY(spy.wait(5 * interval)); QVERIFY(spy.wait(5 * interval)); - QString text = spy.takeFirst().at(0).toString(); + auto text = spy.takeFirst().at(0).toString(); QEXPECT_FAIL("", "Pattern should be parsed", Continue); QCOMPARE(text, pattern); - QStringList keys = plugin->dictKeys(true); + auto keys = plugin->dictKeys(true); for (auto &key : keys) QVERIFY(!text.contains(key)); } @@ -119,7 +118,7 @@ void TestAWKeys::test_tooltip() QSignalSpy spy(plugin, SIGNAL(needToolTipToBeUpdated(const QString))); QVERIFY(spy.wait(5 * interval)); - QString text = spy.takeFirst().at(0).toString(); + auto text = spy.takeFirst().at(0).toString(); QVERIFY(text.startsWith("") && text.contains("\n")); plugin->setWrapNewLines(true); @@ -141,10 +140,10 @@ void TestAWKeys::test_wrapNewLines() void TestAWKeys::test_infoByKey() { - int notEmpty = 0; - QStringList keys = plugin->dictKeys(true); + auto notEmpty = 0; + auto keys = plugin->dictKeys(true); for (auto &key : keys) { - QString info = plugin->infoByKey(key); + auto info = plugin->infoByKey(key); QVERIFY(!info.isEmpty()); // append non-empty field count if (info != "(none)") @@ -156,8 +155,8 @@ void TestAWKeys::test_infoByKey() void TestAWKeys::test_valueByKey() { - int notEmpty = 0; - QStringList keys = plugin->dictKeys(true); + auto notEmpty = 0; + auto keys = plugin->dictKeys(true); for (auto &key : keys) { if (!plugin->valueByKey(key).isEmpty()) notEmpty++; @@ -169,26 +168,25 @@ void TestAWKeys::test_valueByKey() void TestAWKeys::test_dbus() { // get id - qlonglong id = reinterpret_cast(plugin); + auto id = reinterpret_cast(plugin); // create connection and message - QDBusConnection bus = QDBusConnection::sessionBus(); + auto bus = QDBusConnection::sessionBus(); // check if there is active sessions first - QDBusMessage sessions - = QDBusMessage::createMethodCall(AWDBUS_SERVICE, AWDBUS_PATH, AWDBUS_SERVICE, "ActiveServices"); - QDBusMessage sessionsResponse = bus.call(sessions, QDBus::BlockWithGui); + auto sessions = QDBusMessage::createMethodCall(AWDBUS_SERVICE, AWDBUS_PATH, AWDBUS_SERVICE, "ActiveServices"); + auto sessionsResponse = bus.call(sessions, QDBus::BlockWithGui); if (sessionsResponse.arguments().isEmpty()) QSKIP("No active sessions found, skip DBus tests"); // dbus checks - QDBusMessage request = QDBusMessage::createMethodCall(QString("%1.i%2").arg(AWDBUS_SERVICE).arg(id), AWDBUS_PATH, - AWDBUS_SERVICE, "WhoAmI"); + auto request = QDBusMessage::createMethodCall(QString("%1.i%2").arg(AWDBUS_SERVICE).arg(id), AWDBUS_PATH, + AWDBUS_SERVICE, "WhoAmI"); // send message to dbus - QDBusMessage response = bus.call(request, QDBus::BlockWithGui); + auto response = bus.call(request, QDBus::BlockWithGui); // parse result - QList arguments = response.arguments(); + auto arguments = response.arguments(); QVERIFY(!arguments.isEmpty()); QCOMPARE(arguments.at(0).toLongLong(), id); } diff --git a/sources/test/testawpatternfunctions.cpp b/sources/test/testawpatternfunctions.cpp index bb740380..c4446a76 100644 --- a/sources/test/testawpatternfunctions.cpp +++ b/sources/test/testawpatternfunctions.cpp @@ -15,7 +15,6 @@ * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * ***************************************************************************/ - #include "testawpatternfunctions.h" #include @@ -36,12 +35,12 @@ void TestAWPatternFunctions::cleanupTestCase() {} void TestAWPatternFunctions::test_findFunctionCalls() { - QString name = QString("aw_%1").arg(AWTestLibrary::randomString(1, 10)); - QString code = AWTestLibrary::randomString(1, 20); - QStringList args = AWTestLibrary::randomStringList(20); - QString function = QString("$%1<%2>{{%3}}").arg(name).arg(args.join(',')).arg(code); + auto name = QString("aw_%1").arg(AWTestLibrary::randomString(1, 10)); + auto code = AWTestLibrary::randomString(1, 20); + auto args = AWTestLibrary::randomStringList(20); + auto function = QString("$%1<%2>{{%3}}").arg(name).arg(args.join(',')).arg(code); - QString pattern = AWTestLibrary::randomString() + function + AWTestLibrary::randomString(); + auto pattern = AWTestLibrary::randomString() + function + AWTestLibrary::randomString(); QList found = AWPatternFunctions::findFunctionCalls(name, pattern); QCOMPARE(found.count(), 1); @@ -54,9 +53,9 @@ void TestAWPatternFunctions::test_findFunctionCalls() void TestAWPatternFunctions::test_findKeys() { - int count = AWTestLibrary::randomInt(200); + auto count = AWTestLibrary::randomInt(200); QStringList allKeys; - for (int 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); @@ -65,8 +64,8 @@ void TestAWPatternFunctions::test_findKeys() auto keys = AWTestLibrary::randomSelect(allKeys); auto bars = AWTestLibrary::randomSelect(allKeys); - std::for_each(bars.begin(), bars.end(), [](QString &bar) { bar.prepend("bar"); }); - QString pattern = QString("$%1 $%2").arg(keys.join(" $")).arg(bars.join(" $")); + std::for_each(bars.begin(), bars.end(), [](auto &bar) { bar.prepend("bar"); }); + auto pattern = QString("$%1 $%2").arg(keys.join(" $")).arg(bars.join(" $")); allKeys.append(bars); allKeys.sort(); @@ -74,9 +73,9 @@ void TestAWPatternFunctions::test_findKeys() keys.sort(); bars.sort(); - QStringList foundKeys = AWPatternFunctions::findKeys(pattern, allKeys, false); + auto foundKeys = AWPatternFunctions::findKeys(pattern, allKeys, false); foundKeys.sort(); - QStringList foundBars = AWPatternFunctions::findKeys(pattern, allKeys, true); + auto foundBars = AWPatternFunctions::findKeys(pattern, allKeys, true); foundBars.sort(); QCOMPARE(foundKeys, keys); @@ -86,8 +85,8 @@ void TestAWPatternFunctions::test_findKeys() void TestAWPatternFunctions::test_findLambdas() { - QStringList lambdas = AWTestLibrary::randomStringList(20); - QString pattern + auto lambdas = AWTestLibrary::randomStringList(20); + auto pattern = AWTestLibrary::randomString() + QString("${{%1}}").arg(lambdas.join("}}${{")) + AWTestLibrary::randomString(); QCOMPARE(AWPatternFunctions::findLambdas(pattern), lambdas); @@ -96,12 +95,12 @@ void TestAWPatternFunctions::test_findLambdas() void TestAWPatternFunctions::test_expandTemplates() { - int firstValue = AWTestLibrary::randomInt(); - int secondValue = AWTestLibrary::randomInt(); - int result = firstValue + secondValue; - QString code = QString("$template{{%1+%2}}").arg(firstValue).arg(secondValue); - QString prefix = AWTestLibrary::randomString(); - QString pattern = prefix + code; + auto firstValue = AWTestLibrary::randomInt(); + auto secondValue = AWTestLibrary::randomInt(); + auto result = firstValue + secondValue; + auto code = QString("$template{{%1+%2}}").arg(firstValue).arg(secondValue); + auto prefix = AWTestLibrary::randomString(); + auto pattern = prefix + code; QCOMPARE(AWPatternFunctions::expandTemplates(pattern), QString("%1%2").arg(prefix).arg(result)); } diff --git a/sources/test/testawtelemetryhandler.cpp b/sources/test/testawtelemetryhandler.cpp index dd7da60e..3b53312e 100644 --- a/sources/test/testawtelemetryhandler.cpp +++ b/sources/test/testawtelemetryhandler.cpp @@ -15,7 +15,6 @@ * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * ***************************************************************************/ - #include "testawtelemetryhandler.h" #include @@ -48,7 +47,7 @@ void TestAWTelemetryHandler::test_put() void TestAWTelemetryHandler::test_get() { - QStringList output = plugin->get(telemetryGroup); + auto output = plugin->get(telemetryGroup); QVERIFY(!output.isEmpty()); QCOMPARE(QSet(output.cbegin(), output.cend()).count(), output.count()); @@ -70,7 +69,7 @@ void TestAWTelemetryHandler::test_uploadTelemetry() plugin->uploadTelemetry(telemetryValidGroup, telemetryData); QVERIFY(spy.wait(5000)); - QVariantList arguments = spy.takeFirst(); + auto arguments = spy.takeFirst(); QCOMPARE(arguments.at(0).toString(), telemetryStatus); } diff --git a/sources/test/testawupdatehelper.cpp b/sources/test/testawupdatehelper.cpp index 2585b839..0825da42 100644 --- a/sources/test/testawupdatehelper.cpp +++ b/sources/test/testawupdatehelper.cpp @@ -15,7 +15,6 @@ * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * ***************************************************************************/ - #include "testawupdatehelper.h" #include diff --git a/sources/test/testbatterysource.cpp b/sources/test/testbatterysource.cpp index 6fe2c338..693cb8b5 100644 --- a/sources/test/testbatterysource.cpp +++ b/sources/test/testbatterysource.cpp @@ -15,7 +15,6 @@ * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * ***************************************************************************/ - #include "testbatterysource.h" #include @@ -29,7 +28,7 @@ void TestBatterySource::initTestCase() { AWTestLibrary::init(); - source = new BatterySource(this, QStringList() << acpiPath); + source = new BatterySource(this, acpiPath); } @@ -41,8 +40,7 @@ void TestBatterySource::cleanupTestCase() void TestBatterySource::test_sources() { - // - QVERIFY(source->sources().length() >= 6); + QVERIFY(source->sources().count() >= 6); } @@ -51,9 +49,9 @@ void TestBatterySource::test_battery() if (source->sources().count() == 6) QSKIP("No battery found, test will be skipped"); - QStringList batteries = source->sources(); - std::for_each(batteries.begin(), batteries.end(), [this](const QString &bat) { - QVariant value = source->data(bat); + auto batteries = source->sources().keys(); + std::for_each(batteries.cbegin(), batteries.cend(), [this](auto bat) { + auto value = source->data(bat); if (bat == "ac") QCOMPARE(value.type(), QVariant::Bool); else if (bat.startsWith("batrate") || bat.startsWith("batleft")) diff --git a/sources/test/testdatetimeformatter.cpp b/sources/test/testdatetimeformatter.cpp index f102793b..fd51fd6c 100644 --- a/sources/test/testdatetimeformatter.cpp +++ b/sources/test/testdatetimeformatter.cpp @@ -15,7 +15,6 @@ * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * ***************************************************************************/ - #include "testdatetimeformatter.h" #include @@ -57,7 +56,7 @@ void TestAWDateTimeFormatter::test_conversion() void TestAWDateTimeFormatter::test_copy() { formatter->setTranslateString(false); - auto *newFormatter = formatter->copy("/dev/null", 1); + auto newFormatter = formatter->copy("/dev/null", 1); QCOMPARE(newFormatter->format(), formatter->format()); QCOMPARE(newFormatter->translateString(), formatter->translateString()); diff --git a/sources/test/testdesktopsource.cpp b/sources/test/testdesktopsource.cpp index 0e5b64ea..9c72fe49 100644 --- a/sources/test/testdesktopsource.cpp +++ b/sources/test/testdesktopsource.cpp @@ -15,7 +15,6 @@ * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * ***************************************************************************/ - #include "testdesktopsource.h" #include @@ -27,7 +26,7 @@ void TestDesktopSource::initTestCase() { AWTestLibrary::init(); - source = new DesktopSource(this, QStringList()); + source = new DesktopSource(this); } diff --git a/sources/test/testdpplugin.cpp b/sources/test/testdpplugin.cpp index aa84c3bc..ed312ee3 100644 --- a/sources/test/testdpplugin.cpp +++ b/sources/test/testdpplugin.cpp @@ -15,7 +15,6 @@ * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * ***************************************************************************/ - #include "testdpplugin.h" #include @@ -44,8 +43,8 @@ void TestDPPlugin::test_desktops() if (!m_isKwinActive) QSKIP("KWin inactive, skip Destkop panel tests"); - int current = plugin->currentDesktop(); - int total = plugin->numberOfDesktops(); + auto current = plugin->currentDesktop(); + auto total = plugin->numberOfDesktops(); QVERIFY(total != 0); QVERIFY(current <= total); @@ -90,7 +89,7 @@ void TestDPPlugin::test_parsePattern() if (!m_isKwinActive) QSKIP("KWin inactive, skip Destkop panel tests"); - QString result = plugin->parsePattern(pattern, plugin->currentDesktop()); + auto result = plugin->parsePattern(pattern, plugin->currentDesktop()); QVERIFY(!result.isEmpty()); QVERIFY(result != pattern); for (auto &key : plugin->dictKeys()) @@ -109,7 +108,7 @@ void TestDPPlugin::test_tooltipImage() data["tooltipWidth"] = 300; plugin->setToolTipData(data); - QString image = plugin->toolTipImage(plugin->currentDesktop()); + auto image = plugin->toolTipImage(plugin->currentDesktop()); QVERIFY(image.startsWith("")); } diff --git a/sources/test/testextitemaggregator.cpp b/sources/test/testextitemaggregator.cpp index 926b9271..c25dec64 100644 --- a/sources/test/testextitemaggregator.cpp +++ b/sources/test/testextitemaggregator.cpp @@ -15,7 +15,6 @@ * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * ***************************************************************************/ - #include "testextitemaggregator.h" #include diff --git a/sources/test/testextquotes.cpp b/sources/test/testextquotes.cpp index 21bd4d2d..1491965d 100644 --- a/sources/test/testextquotes.cpp +++ b/sources/test/testextquotes.cpp @@ -15,7 +15,6 @@ * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * ***************************************************************************/ - #include "testextquotes.h" #include @@ -54,11 +53,11 @@ void TestExtQuotes::test_run() { // init spy QSignalSpy spy(extQuotes, SIGNAL(dataReceived(const QVariantHash &))); - QVariantHash firstValue = extQuotes->run(); + auto firstValue = extQuotes->run(); // check values QVERIFY(spy.wait(5000)); - QList arguments = spy.takeFirst(); + auto arguments = spy.takeFirst(); for (auto &type : types) cache[type] = arguments.at(0).toHash()[extQuotes->tag(type)]; @@ -73,11 +72,11 @@ void TestExtQuotes::test_derivatives() { // init spy QSignalSpy spy(extQuotes, SIGNAL(dataReceived(const QVariantHash &))); - QVariantHash firstValue = extQuotes->run(); + auto firstValue = extQuotes->run(); // check values QVERIFY(spy.wait(5000)); - QList arguments = spy.takeFirst(); + auto arguments = spy.takeFirst(); QVariantHash values; for (auto &type : types) values[type] = arguments.at(0).toHash()[extQuotes->tag(type)]; @@ -91,7 +90,7 @@ void TestExtQuotes::test_derivatives() void TestExtQuotes::test_copy() { - ExtQuotes *newExtQuotes = extQuotes->copy("/dev/null", 1); + auto newExtQuotes = extQuotes->copy("/dev/null", 1); QCOMPARE(newExtQuotes->interval(), extQuotes->interval()); QCOMPARE(newExtQuotes->ticker(), extQuotes->ticker()); diff --git a/sources/test/testextscript.cpp b/sources/test/testextscript.cpp index 379fd4ef..ecfc714b 100644 --- a/sources/test/testextscript.cpp +++ b/sources/test/testextscript.cpp @@ -15,7 +15,6 @@ * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * ***************************************************************************/ - #include "testextscript.h" #include @@ -58,11 +57,11 @@ void TestExtScript::test_run() { // init spy QSignalSpy spy(extScript, SIGNAL(dataReceived(const QVariantHash &))); - QVariantHash firstValue = extScript->run(); + auto firstValue = extScript->run(); // check values QVERIFY(spy.wait(5000)); - QList arguments = spy.takeFirst(); + auto arguments = spy.takeFirst(); QCOMPARE(firstValue[extScript->tag("custom")].toString(), QString()); QCOMPARE(arguments.at(0).toHash()[extScript->tag("custom")].toString(), QString("\n%1").arg(randomString)); @@ -81,14 +80,14 @@ void TestExtScript::test_filters() // check values QVERIFY(spy.wait(5000)); - QList arguments = spy.takeFirst(); + auto arguments = spy.takeFirst(); QCOMPARE(arguments.at(0).toHash()[extScript->tag("custom")].toString(), QString("
%1").arg(randomString)); } void TestExtScript::test_copy() { - ExtScript *newExtScript = extScript->copy("/dev/null", 1); + auto newExtScript = extScript->copy("/dev/null", 1); QCOMPARE(newExtScript->interval(), extScript->interval()); QCOMPARE(newExtScript->executable(), extScript->executable()); diff --git a/sources/test/testextupgrade.cpp b/sources/test/testextupgrade.cpp index f3fe2495..a6a9ba73 100644 --- a/sources/test/testextupgrade.cpp +++ b/sources/test/testextupgrade.cpp @@ -15,7 +15,6 @@ * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * ***************************************************************************/ - #include "testextupgrade.h" #include @@ -57,11 +56,11 @@ void TestExtUpgrade::test_run() { // init spy QSignalSpy spy(extUpgrade, SIGNAL(dataReceived(const QVariantHash &))); - QVariantHash firstValue = extUpgrade->run(); + auto firstValue = extUpgrade->run(); // check values QVERIFY(spy.wait(5000)); - QList arguments = spy.takeFirst(); + auto arguments = spy.takeFirst(); QCOMPARE(firstValue[extUpgrade->tag("pkgcount")].toInt(), 0); QCOMPARE(arguments.at(0).toHash()[extUpgrade->tag("pkgcount")].toInt(), randomStrings.count()); @@ -70,21 +69,21 @@ void TestExtUpgrade::test_run() void TestExtUpgrade::test_null() { - int null = AWTestLibrary::randomInt(randomStrings.count()); + auto null = AWTestLibrary::randomInt(randomStrings.count()); extUpgrade->setNull(null); QSignalSpy spy(extUpgrade, SIGNAL(dataReceived(const QVariantHash &))); extUpgrade->run(); // check values QVERIFY(spy.wait(5000)); - QList arguments = spy.takeFirst(); + auto arguments = spy.takeFirst(); QCOMPARE(arguments.at(0).toHash()[extUpgrade->tag("pkgcount")].toInt(), randomStrings.count() - null); } void TestExtUpgrade::test_filter() { - QStringList filters = AWTestLibrary::randomSelect(randomStrings); + auto filters = AWTestLibrary::randomSelect(randomStrings); extUpgrade->setFilter(QString("(^%1$)").arg(filters.join("$|^"))); // init spy QSignalSpy spy(extUpgrade, SIGNAL(dataReceived(const QVariantHash &))); @@ -92,14 +91,14 @@ void TestExtUpgrade::test_filter() // check values QVERIFY(spy.wait(5000)); - QList arguments = spy.takeFirst(); + auto arguments = spy.takeFirst(); QCOMPARE(arguments.at(0).toHash()[extUpgrade->tag("pkgcount")].toInt(), filters.count()); } void TestExtUpgrade::test_copy() { - ExtUpgrade *newExtUpgrade = extUpgrade->copy("/dev/null", 1); + auto newExtUpgrade = extUpgrade->copy("/dev/null", 1); QCOMPARE(newExtUpgrade->interval(), extUpgrade->interval()); QCOMPARE(newExtUpgrade->executable(), extUpgrade->executable()); diff --git a/sources/test/testextweather.cpp b/sources/test/testextweather.cpp index 3c87c2ff..9f581dd8 100644 --- a/sources/test/testextweather.cpp +++ b/sources/test/testextweather.cpp @@ -15,7 +15,6 @@ * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * ***************************************************************************/ - #include "testextweather.h" #include @@ -75,18 +74,18 @@ void TestExtWeather::test_image() extWeather->setImage(true); // init spy QSignalSpy spy(extWeather, SIGNAL(dataReceived(const QVariantHash &))); - QVariantHash firstValue = extWeather->run(); + auto firstValue = extWeather->run(); // check values QVERIFY(spy.wait(5000)); - QVariantHash arguments = spy.takeFirst().at(0).toHash(); + auto arguments = spy.takeFirst().at(0).toHash(); QVERIFY(arguments[extWeather->tag("weather")].toString().startsWith("copy("/dev/null", 1); + auto newExtWeather = extWeather->copy("/dev/null", 1); QCOMPARE(newExtWeather->interval(), extWeather->interval()); QCOMPARE(newExtWeather->city(), extWeather->city()); @@ -104,11 +103,11 @@ void TestExtWeather::run() { // init spy QSignalSpy spy(extWeather, SIGNAL(dataReceived(const QVariantHash &))); - QVariantHash firstValue = extWeather->run(); + auto firstValue = extWeather->run(); // check values QVERIFY(spy.wait(5000)); - QVariantHash arguments = spy.takeFirst().at(0).toHash(); + auto arguments = spy.takeFirst().at(0).toHash(); QEXPECT_FAIL("", "WeatherID should not be 0", Continue); QCOMPARE(arguments[extWeather->tag("weatherId")].toInt(), 0); QVERIFY((arguments[extWeather->tag("humidity")].toInt() >= humidity.first) diff --git a/sources/test/testfloatformatter.cpp b/sources/test/testfloatformatter.cpp index cbce2f39..b0dc410d 100644 --- a/sources/test/testfloatformatter.cpp +++ b/sources/test/testfloatformatter.cpp @@ -15,7 +15,6 @@ * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * ***************************************************************************/ - #include "testfloatformatter.h" #include @@ -44,12 +43,12 @@ void TestAWFloatFormatter::test_values() {} void TestAWFloatFormatter::test_count() { // assign - int count = 10 + AWTestLibrary::randomInt(); + auto count = 10 + AWTestLibrary::randomInt(); formatter->setCount(count); QCOMPARE(formatter->count(), count); // test - QString output = formatter->convert(QRandomGenerator::global()->generateDouble()); + auto output = formatter->convert(QRandomGenerator::global()->generateDouble()); QCOMPARE(output.length(), count); // reset @@ -60,13 +59,13 @@ void TestAWFloatFormatter::test_count() void TestAWFloatFormatter::test_fillChar() { // assign - char c = AWTestLibrary::randomChar(); + auto c = AWTestLibrary::randomChar(); formatter->setFillChar(c); QCOMPARE(formatter->fillChar(), QChar(c)); formatter->setCount(101); // test - QString output = formatter->convert(AWTestLibrary::randomInt()); + auto output = formatter->convert(AWTestLibrary::randomInt()); QVERIFY(output.startsWith(c)); // reset @@ -78,13 +77,13 @@ void TestAWFloatFormatter::test_fillChar() void TestAWFloatFormatter::test_forceWidth() { // assign - int count = AWTestLibrary::randomInt(6); + auto count = AWTestLibrary::randomInt(6); formatter->setForceWidth(true); formatter->setCount(count); QCOMPARE(formatter->forceWidth(), true); // test - QString output = formatter->convert(QRandomGenerator::global()->generateDouble()); + auto output = formatter->convert(QRandomGenerator::global()->generateDouble()); QCOMPARE(output.length(), count); // reset @@ -103,7 +102,7 @@ void TestAWFloatFormatter::test_format() QCOMPARE(formatter->format(), 'e'); // test - QString output = formatter->convert(QRandomGenerator::global()->generateDouble()); + auto output = formatter->convert(QRandomGenerator::global()->generateDouble()); QVERIFY(output.contains('e')); // reset @@ -114,12 +113,12 @@ void TestAWFloatFormatter::test_format() void TestAWFloatFormatter::test_precision() { // assign - int precision = 1 + AWTestLibrary::randomInt(5); + auto precision = 1 + AWTestLibrary::randomInt(5); formatter->setPrecision(precision); QCOMPARE(formatter->precision(), precision); // test - QString output = formatter->convert(QRandomGenerator::global()->generateDouble()); + auto output = formatter->convert(QRandomGenerator::global()->generateDouble()); output.remove("0."); QCOMPARE(output.length(), precision); @@ -133,12 +132,12 @@ void TestAWFloatFormatter::test_multiplier() formatter->setPrecision(6); // assign - double multiplier = QRandomGenerator::global()->generateDouble(); + auto multiplier = QRandomGenerator::global()->generateDouble(); formatter->setMultiplier(multiplier); QCOMPARE(formatter->multiplier(), multiplier); // test - double value = QRandomGenerator::global()->generateDouble(); + auto value = QRandomGenerator::global()->generateDouble(); QCOMPARE(formatter->convert(value), QString::number(value * multiplier, 'f', 6)); // reset @@ -149,12 +148,12 @@ void TestAWFloatFormatter::test_multiplier() void TestAWFloatFormatter::test_summand() { // assign - double summand = QRandomGenerator::global()->generateDouble(); + auto summand = QRandomGenerator::global()->generateDouble(); formatter->setSummand(summand); QCOMPARE(formatter->summand(), summand); // test - double value = QRandomGenerator::global()->generateDouble(); + auto value = QRandomGenerator::global()->generateDouble(); QCOMPARE(formatter->convert(value), QString::number(value + summand, 'f', 6)); // reset @@ -165,7 +164,7 @@ void TestAWFloatFormatter::test_summand() void TestAWFloatFormatter::test_copy() { doRandom(); - AWFloatFormatter *newFormatter = formatter->copy("/dev/null", 1); + auto newFormatter = formatter->copy("/dev/null", 1); QCOMPARE(newFormatter->count(), formatter->count()); QCOMPARE(newFormatter->fillChar(), formatter->fillChar()); diff --git a/sources/test/testjsonformatter.cpp b/sources/test/testjsonformatter.cpp index b9265601..f716d81b 100644 --- a/sources/test/testjsonformatter.cpp +++ b/sources/test/testjsonformatter.cpp @@ -15,7 +15,6 @@ * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * ***************************************************************************/ - #include "testjsonformatter.h" #include @@ -54,7 +53,7 @@ void TestAWJsonFormatter::test_conversion() void TestAWJsonFormatter::test_copy() { - AWJsonFormatter *newFormatter = formatter->copy("/dev/null", 1); + auto newFormatter = formatter->copy("/dev/null", 1); QCOMPARE(newFormatter->path(), formatter->path()); QCOMPARE(newFormatter->number(), 1); @@ -68,25 +67,25 @@ void TestAWJsonFormatter::generate() value = AWTestLibrary::randomString(); QVariantMap first; - QString firstKey = AWTestLibrary::randomString(); + auto firstKey = AWTestLibrary::randomString(); first[firstKey] = value; - int listCount = AWTestLibrary::randomInt(5) + 1; - int validCount = AWTestLibrary::randomInt(listCount); + auto listCount = AWTestLibrary::randomInt(5) + 1; + auto validCount = AWTestLibrary::randomInt(listCount); QVariantList second; - for (int i = 0; i < listCount; i++) { + for (auto i = 0; i < listCount; i++) { if (i == validCount) { second.append(first); } else { - QString key = AWTestLibrary::randomString(); - QString val = AWTestLibrary::randomString(); + auto key = AWTestLibrary::randomString(); + auto val = AWTestLibrary::randomString(); QVariantMap dict; dict[key] = val; second.append(dict); } } - QString thirdKey = AWTestLibrary::randomString(); + auto thirdKey = AWTestLibrary::randomString(); QVariantMap output; output[thirdKey] = second; diff --git a/sources/test/testlistformatter.cpp b/sources/test/testlistformatter.cpp index bbc4f1af..ef72b0a3 100644 --- a/sources/test/testlistformatter.cpp +++ b/sources/test/testlistformatter.cpp @@ -15,7 +15,6 @@ * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * ***************************************************************************/ - #include "testlistformatter.h" #include @@ -50,7 +49,7 @@ void TestAWListFormatter::test_values() void TestAWListFormatter::test_conversion() { - QStringList value = AWTestLibrary::randomStringList(); + auto value = AWTestLibrary::randomStringList(); QCOMPARE(formatter->convert(value), value.join(separator)); } @@ -58,8 +57,8 @@ void TestAWListFormatter::test_conversion() void TestAWListFormatter::test_sorted() { formatter->setSorted(true); - QStringList value = AWTestLibrary::randomStringList(); - QString received = formatter->convert(value); + auto value = AWTestLibrary::randomStringList(); + auto received = formatter->convert(value); value.sort(); QCOMPARE(received, value.join(separator)); @@ -68,8 +67,8 @@ void TestAWListFormatter::test_sorted() void TestAWListFormatter::test_filter() { - QStringList value = AWTestLibrary::randomStringList(); - QStringList filters = AWTestLibrary::randomSelect(value); + auto value = AWTestLibrary::randomStringList(); + auto filters = AWTestLibrary::randomSelect(value); value.sort(); formatter->setFilter(QString("(^%1$)").arg(filters.join("$|^"))); @@ -79,7 +78,7 @@ void TestAWListFormatter::test_filter() void TestAWListFormatter::test_copy() { - AWListFormatter *newFormatter = formatter->copy("/dev/null", 1); + auto newFormatter = formatter->copy("/dev/null", 1); QCOMPARE(newFormatter->number(), 1); QCOMPARE(newFormatter->filter(), formatter->filter()); diff --git a/sources/test/testnetworksource.cpp b/sources/test/testnetworksource.cpp index db41e246..69f74a5b 100644 --- a/sources/test/testnetworksource.cpp +++ b/sources/test/testnetworksource.cpp @@ -15,7 +15,6 @@ * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * ***************************************************************************/ - #include "testnetworksource.h" #include @@ -27,7 +26,7 @@ void TestNetworkSource::initTestCase() { AWTestLibrary::init(); - source = new NetworkSource(this, QStringList()); + source = new NetworkSource(this); } @@ -39,7 +38,9 @@ void TestNetworkSource::cleanupTestCase() void TestNetworkSource::test_sources() { - QCOMPARE(source->sources(), QStringList({"device", "ssid"})); + auto sources = source->sources(); + QVERIFY(sources.contains("device")); + QVERIFY(sources.contains("ssid")); } diff --git a/sources/test/testnoformatter.cpp b/sources/test/testnoformatter.cpp index cb9023ab..9160b1ab 100644 --- a/sources/test/testnoformatter.cpp +++ b/sources/test/testnoformatter.cpp @@ -15,7 +15,6 @@ * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * ***************************************************************************/ - #include "testnoformatter.h" #include @@ -43,19 +42,19 @@ void TestAWNoFormatter::test_values() {} void TestAWNoFormatter::test_conversion() { // integer - int randomInt = AWTestLibrary::randomInt(); + auto randomInt = AWTestLibrary::randomInt(); QCOMPARE(formatter->convert(randomInt), QString::number(randomInt)); // float QWARN("Float conversion isn't tested here due to possible rounding errors"); // string - QString randomString = AWTestLibrary::randomString(); + auto randomString = AWTestLibrary::randomString(); QCOMPARE(formatter->convert(randomString), randomString); } void TestAWNoFormatter::test_copy() { - AWNoFormatter *newFormatter = formatter->copy("/dev/null", 1); + auto newFormatter = formatter->copy("/dev/null", 1); QCOMPARE(newFormatter->number(), 1); diff --git a/sources/test/testplayersource.cpp b/sources/test/testplayersource.cpp index a132f217..25a36870 100644 --- a/sources/test/testplayersource.cpp +++ b/sources/test/testplayersource.cpp @@ -15,7 +15,6 @@ * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * ***************************************************************************/ - #include "testplayersource.h" #include @@ -41,8 +40,8 @@ void TestPlayerSource::_test_sources(const PlayerSource *_source) void TestPlayerSource::test_buildString() { - QString randomString = AWTestLibrary::randomString(1, 40); - QString str = PlayerSource::buildString("", randomString, 20); + auto randomString = AWTestLibrary::randomString(1, 40); + auto str = PlayerSource::buildString("", randomString, 20); QCOMPARE(str.length(), 20); str = PlayerSource::buildString(str, randomString, 20); @@ -55,7 +54,7 @@ void TestPlayerSource::test_buildString() void TestPlayerSource::test_stripString() { - QString str = PlayerSource::buildString("", AWTestLibrary::randomString(1, 40), 20); + auto str = PlayerSource::buildString("", AWTestLibrary::randomString(1, 40), 20); QCOMPARE(str.length(), 20); str = PlayerSource::buildString("", AWTestLibrary::randomString(1, 10), 20); @@ -65,11 +64,9 @@ void TestPlayerSource::test_stripString() void TestPlayerSource::test_autoMpris() { - QStringList args(QStringList() << "mpris" << mpdAddress << QString::number(mpdPort) << "auto" - << QString::number(10)); - PlayerSource *source = new PlayerSource(this, args); + auto source = new PlayerSource(this, "mpris", mpdAddress, mpdPort, "auto", 10); - bool empty = source->getAutoMpris().isEmpty(); + auto empty = source->getAutoMpris().isEmpty(); if (empty) QWARN("No MPRIS found, manual check required"); else @@ -79,20 +76,19 @@ void TestPlayerSource::test_autoMpris() void TestPlayerSource::test_mpd() { - QStringList args(QStringList() << "mpd" << mpdAddress << QString::number(mpdPort) << "auto" << QString::number(10)); - PlayerSource *source = new PlayerSource(this, args); + auto source = new PlayerSource(this, "mpd", mpdAddress, mpdPort, "auto", 10); _test_sources(source); // init spy QSignalSpy spy(source, SIGNAL(dataReceived(const QVariantHash &))); - QVariant firstValue = source->data("title"); + auto firstValue = source->data("title"); if (!source->isMpdSocketConnected()) QSKIP("No mpd found"); // check values QVERIFY(spy.wait(5000)); - QList arguments = spy.takeFirst(); - QVariantHash secondValue = arguments.at(0).toHash(); + auto arguments = spy.takeFirst(); + auto secondValue = arguments.at(0).toHash(); // actually nothing to test here just print warning if no information found if (secondValue["title"].toString() == "unknown") @@ -104,14 +100,12 @@ void TestPlayerSource::test_mpd() void TestPlayerSource::test_mpris() { - QStringList args(QStringList() << "mpris" << mpdAddress << QString::number(mpdPort) << "auto" - << QString::number(10)); - PlayerSource *source = new PlayerSource(this, args); + auto source = new PlayerSource(this, "mpris", mpdAddress, mpdPort, "auto", 10); _test_sources(source); - QString value = source->data("title").toString(); - int progress = source->data("progress").toInt(); - int duration = source->data("duration").toInt(); + auto value = source->data("title").toString(); + auto progress = source->data("progress").toInt(); + auto duration = source->data("duration").toInt(); // actually nothing to test here just print warning if no information found if (value == "unknown") diff --git a/sources/test/testprocessessource.cpp b/sources/test/testprocessessource.cpp index 6272ce2c..d1c1f9b7 100644 --- a/sources/test/testprocessessource.cpp +++ b/sources/test/testprocessessource.cpp @@ -15,7 +15,6 @@ * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * ***************************************************************************/ - #include "testprocessessource.h" #include @@ -27,7 +26,7 @@ void TestProcessesSource::initTestCase() { AWTestLibrary::init(); - source = new ProcessesSource(this, QStringList()); + source = new ProcessesSource(this); } diff --git a/sources/test/testscriptformatter.cpp b/sources/test/testscriptformatter.cpp index 3ae01f5e..14f710e7 100644 --- a/sources/test/testscriptformatter.cpp +++ b/sources/test/testscriptformatter.cpp @@ -15,7 +15,6 @@ * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * ***************************************************************************/ - #include "testscriptformatter.h" #include @@ -52,7 +51,7 @@ void TestAWScriptFormatter::test_values() void TestAWScriptFormatter::test_conversion() { - QString string = AWTestLibrary::randomString(); + auto string = AWTestLibrary::randomString(); QCOMPARE(formatter->convert(string), string); } @@ -93,7 +92,7 @@ void TestAWScriptFormatter::test_hasReturn() void TestAWScriptFormatter::test_copy() { - AWScriptFormatter *newFormatter = formatter->copy("/dev/null", 1); + auto newFormatter = formatter->copy("/dev/null", 1); QCOMPARE(newFormatter->appendCode(), formatter->appendCode()); QCOMPARE(newFormatter->code(), formatter->code()); diff --git a/sources/test/teststringformatter.cpp b/sources/test/teststringformatter.cpp index 848383ee..c6bbaf2c 100644 --- a/sources/test/teststringformatter.cpp +++ b/sources/test/teststringformatter.cpp @@ -15,7 +15,6 @@ * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * ***************************************************************************/ - #include "teststringformatter.h" #include @@ -43,7 +42,7 @@ void TestAWStringFormatter::test_values() {} void TestAWStringFormatter::test_count() { // assign - int count = 10 + AWTestLibrary::randomInt(); + auto count = 10 + AWTestLibrary::randomInt(); formatter->setCount(count); QCOMPARE(formatter->count(), count); @@ -51,7 +50,7 @@ void TestAWStringFormatter::test_count() auto testString = AWTestLibrary::randomString(); while (testString.length() > count) testString = AWTestLibrary::randomString(); - QString output = formatter->convert(testString); + auto output = formatter->convert(testString); QCOMPARE(output.length(), count); // reset @@ -62,13 +61,13 @@ void TestAWStringFormatter::test_count() void TestAWStringFormatter::test_fillChar() { // assign - char c = AWTestLibrary::randomChar(); + auto c = AWTestLibrary::randomChar(); formatter->setFillChar(c); QCOMPARE(formatter->fillChar(), QChar(c)); formatter->setCount(101); // test - QString output = formatter->convert(AWTestLibrary::randomString()); + auto output = formatter->convert(AWTestLibrary::randomString()); QVERIFY(output.startsWith(c)); // reset @@ -80,13 +79,13 @@ void TestAWStringFormatter::test_fillChar() void TestAWStringFormatter::test_forceWidth() { // assign - int count = AWTestLibrary::randomInt(); + auto count = AWTestLibrary::randomInt(); formatter->setForceWidth(true); formatter->setCount(count); QCOMPARE(formatter->forceWidth(), true); // test - QString output = formatter->convert(AWTestLibrary::randomString()); + auto output = formatter->convert(AWTestLibrary::randomString()); QCOMPARE(output.length(), count); // reset @@ -98,7 +97,7 @@ void TestAWStringFormatter::test_forceWidth() void TestAWStringFormatter::test_copy() { doRandom(); - AWStringFormatter *newFormatter = formatter->copy("/dev/null", 1); + auto newFormatter = formatter->copy("/dev/null", 1); QCOMPARE(newFormatter->count(), formatter->count()); QCOMPARE(newFormatter->fillChar(), formatter->fillChar());