mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-24 15:37:23 +00:00
refactor: simplify sources processing
Also fix desktop source
This commit is contained in:
parent
0bcceefd47
commit
a35b57e5d2
@ -12,7 +12,7 @@ QReplyTimeout::QReplyTimeout(QNetworkReply *reply, const int timeout)
|
|||||||
|
|
||||||
void QReplyTimeout::timeout()
|
void QReplyTimeout::timeout()
|
||||||
{
|
{
|
||||||
auto *reply = dynamic_cast<QNetworkReply *>(parent());
|
auto reply = dynamic_cast<QNetworkReply *>(parent());
|
||||||
if (reply->isRunning())
|
if (reply->isRunning())
|
||||||
reply->close();
|
reply->close();
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,7 @@ void AWAbstractPairConfig::updateUi()
|
|||||||
// remove current selector if it is empty and does not last
|
// remove current selector if it is empty and does not last
|
||||||
if (sender() == m_selectors.last())
|
if (sender() == m_selectors.last())
|
||||||
return;
|
return;
|
||||||
auto *selector = m_selectors.takeAt(index);
|
auto selector = m_selectors.takeAt(index);
|
||||||
ui->verticalLayout->removeWidget(selector);
|
ui->verticalLayout->removeWidget(selector);
|
||||||
selector->deleteLater();
|
selector->deleteLater();
|
||||||
} else {
|
} 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;
|
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);
|
selector->init(_keys, _values, _current);
|
||||||
ui->verticalLayout->insertWidget(ui->verticalLayout->count() - 1, selector);
|
ui->verticalLayout->insertWidget(ui->verticalLayout->count() - 1, selector);
|
||||||
connect(selector, &AWAbstractSelector::selectionChanged, this, &AWAbstractPairConfig::updateUi);
|
connect(selector, &AWAbstractSelector::selectionChanged, this, &AWAbstractPairConfig::updateUi);
|
||||||
|
@ -90,7 +90,7 @@ void AWActions::showReadme()
|
|||||||
|
|
||||||
void AWActions::showLegacyInfo()
|
void AWActions::showLegacyInfo()
|
||||||
{
|
{
|
||||||
auto *msgBox = new QMessageBox(nullptr);
|
auto msgBox = new QMessageBox(nullptr);
|
||||||
msgBox->setAttribute(Qt::WA_DeleteOnClose);
|
msgBox->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
msgBox->setModal(false);
|
msgBox->setModal(false);
|
||||||
msgBox->setWindowTitle(i18n("Not supported"));
|
msgBox->setWindowTitle(i18n("Not supported"));
|
||||||
|
@ -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;
|
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);
|
connect(manager, &QNetworkAccessManager::finished, this, &AWBugReporter::issueReplyReceived);
|
||||||
|
|
||||||
auto request = QNetworkRequest(QUrl(BUGTRACKER_API));
|
auto request = QNetworkRequest(QUrl(BUGTRACKER_API));
|
||||||
@ -121,7 +121,7 @@ void AWBugReporter::showInformation(const int _number, const QString &_url)
|
|||||||
// cache url first
|
// cache url first
|
||||||
m_lastBugUrl = _url;
|
m_lastBugUrl = _url;
|
||||||
|
|
||||||
auto *msgBox = new QMessageBox(nullptr);
|
auto msgBox = new QMessageBox(nullptr);
|
||||||
msgBox->setAttribute(Qt::WA_DeleteOnClose);
|
msgBox->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
msgBox->setModal(false);
|
msgBox->setModal(false);
|
||||||
msgBox->setWindowTitle(i18n("Issue created"));
|
msgBox->setWindowTitle(i18n("Issue created"));
|
||||||
|
@ -72,7 +72,7 @@ bool AWConfigHelper::exportConfiguration(QObject *_nativeConfig, const QString &
|
|||||||
|
|
||||||
QSettings settings(_fileName, QSettings::IniFormat);
|
QSettings settings(_fileName, QSettings::IniFormat);
|
||||||
// plasmoid configuration
|
// plasmoid configuration
|
||||||
const auto *configuration = dynamic_cast<const QQmlPropertyMap *>(_nativeConfig);
|
auto configuration = dynamic_cast<const QQmlPropertyMap *>(_nativeConfig);
|
||||||
settings.beginGroup("plasmoid");
|
settings.beginGroup("plasmoid");
|
||||||
for (auto &key : configuration->keys()) {
|
for (auto &key : configuration->keys()) {
|
||||||
QVariant value = configuration->value(key);
|
QVariant value = configuration->value(key);
|
||||||
|
@ -210,11 +210,11 @@ QString AWKeyOperations::infoByKey(const QString &_key) const
|
|||||||
QString output;
|
QString output;
|
||||||
|
|
||||||
if (_key.startsWith("bar")) {
|
if (_key.startsWith("bar")) {
|
||||||
auto *item = m_graphicalItems->itemByTag(_key, stripped);
|
auto item = m_graphicalItems->itemByTag(_key, stripped);
|
||||||
if (item)
|
if (item)
|
||||||
output = item->uniq();
|
output = item->uniq();
|
||||||
} else if (_key.startsWith("custom")) {
|
} else if (_key.startsWith("custom")) {
|
||||||
auto *item = m_extScripts->itemByTag(_key, stripped);
|
auto item = m_extScripts->itemByTag(_key, stripped);
|
||||||
if (item)
|
if (item)
|
||||||
output = item->uniq();
|
output = item->uniq();
|
||||||
} else if (_key.contains(QRegularExpression("^hdd[rw]"))) {
|
} else if (_key.contains(QRegularExpression("^hdd[rw]"))) {
|
||||||
@ -230,15 +230,15 @@ QString AWKeyOperations::infoByKey(const QString &_key) const
|
|||||||
index.remove(QRegularExpression("^(down|up)"));
|
index.remove(QRegularExpression("^(down|up)"));
|
||||||
output = m_devices["net"][index.toInt()];
|
output = m_devices["net"][index.toInt()];
|
||||||
} else if (_key.startsWith("pkgcount")) {
|
} else if (_key.startsWith("pkgcount")) {
|
||||||
auto *item = m_extUpgrade->itemByTag(_key, stripped);
|
auto item = m_extUpgrade->itemByTag(_key, stripped);
|
||||||
if (item)
|
if (item)
|
||||||
output = item->uniq();
|
output = item->uniq();
|
||||||
} else if (_key.contains(QRegularExpression("(^|perc)(ask|bid|price)(chg|)"))) {
|
} 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)
|
if (item)
|
||||||
output = item->uniq();
|
output = item->uniq();
|
||||||
} else if (_key.contains(QRegularExpression("(weather|weatherId|humidity|pressure|temperature)"))) {
|
} 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)
|
if (item)
|
||||||
output = item->uniq();
|
output = item->uniq();
|
||||||
} else if (_key.startsWith("temp")) {
|
} else if (_key.startsWith("temp")) {
|
||||||
@ -246,7 +246,7 @@ QString AWKeyOperations::infoByKey(const QString &_key) const
|
|||||||
index.remove("temp");
|
index.remove("temp");
|
||||||
output = m_devices["temp"][index.toInt()];
|
output = m_devices["temp"][index.toInt()];
|
||||||
} else if (_key.startsWith("response")) {
|
} else if (_key.startsWith("response")) {
|
||||||
auto *item = m_extNetRequest->itemByTag(_key, stripped);
|
auto item = m_extNetRequest->itemByTag(_key, stripped);
|
||||||
if (item)
|
if (item)
|
||||||
output = item->uniq();
|
output = item->uniq();
|
||||||
} else {
|
} else {
|
||||||
|
@ -37,7 +37,7 @@ AWPairConfigFactory::~AWPairConfigFactory()
|
|||||||
|
|
||||||
void AWPairConfigFactory::showFormatterDialog(const QStringList &_keys)
|
void AWPairConfigFactory::showFormatterDialog(const QStringList &_keys)
|
||||||
{
|
{
|
||||||
auto *config = new AWFormatterConfig(nullptr, _keys);
|
auto config = new AWFormatterConfig(nullptr, _keys);
|
||||||
config->showDialog();
|
config->showDialog();
|
||||||
config->deleteLater();
|
config->deleteLater();
|
||||||
}
|
}
|
||||||
@ -45,7 +45,7 @@ void AWPairConfigFactory::showFormatterDialog(const QStringList &_keys)
|
|||||||
|
|
||||||
void AWPairConfigFactory::showKeysDialog(const QStringList &_keys)
|
void AWPairConfigFactory::showKeysDialog(const QStringList &_keys)
|
||||||
{
|
{
|
||||||
auto *config = new AWCustomKeysConfig(nullptr, _keys);
|
auto config = new AWCustomKeysConfig(nullptr, _keys);
|
||||||
config->showDialog();
|
config->showDialog();
|
||||||
config->deleteLater();
|
config->deleteLater();
|
||||||
}
|
}
|
||||||
|
@ -126,7 +126,7 @@ void AWTelemetryHandler::uploadTelemetry(const QString &_group, const QString &_
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto *manager = new QNetworkAccessManager(nullptr);
|
auto manager = new QNetworkAccessManager(nullptr);
|
||||||
connect(manager, &QNetworkAccessManager::finished, this, &AWTelemetryHandler::telemetryReplyReceived);
|
connect(manager, &QNetworkAccessManager::finished, this, &AWTelemetryHandler::telemetryReplyReceived);
|
||||||
|
|
||||||
QUrl url(REMOTE_TELEMETRY_URL);
|
QUrl url(REMOTE_TELEMETRY_URL);
|
||||||
|
@ -52,7 +52,7 @@ void AWUpdateHelper::checkUpdates(const bool _showAnyway)
|
|||||||
|
|
||||||
// showAnyway options requires to show message if no updates found on direct
|
// showAnyway options requires to show message if no updates found on direct
|
||||||
// request. In case of automatic check no message will be shown
|
// 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,
|
connect(manager, &QNetworkAccessManager::finished,
|
||||||
[_showAnyway, this](QNetworkReply *reply) { return versionReplyReceived(reply, _showAnyway); });
|
[_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;
|
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->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
msgBox->setModal(false);
|
msgBox->setModal(false);
|
||||||
msgBox->setWindowTitle(_title);
|
msgBox->setWindowTitle(_title);
|
||||||
|
@ -65,7 +65,7 @@ public:
|
|||||||
m_activeItems.clear();
|
m_activeItems.clear();
|
||||||
|
|
||||||
m_items = getItems();
|
m_items = getItems();
|
||||||
for (auto &item : m_items) {
|
for (auto item : m_items) {
|
||||||
if (!item->isActive())
|
if (!item->isActive())
|
||||||
continue;
|
continue;
|
||||||
m_activeItems.append(static_cast<T *>(item));
|
m_activeItems.append(static_cast<T *>(item));
|
||||||
@ -77,7 +77,7 @@ public:
|
|||||||
// HACK as soon as per one widget instance we have two objects each of
|
// 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
|
// them will try to control socket, whereas actually only one of them
|
||||||
// should be owner of the socket
|
// should be owner of the socket
|
||||||
for (auto &item : m_items)
|
for (auto item : m_items)
|
||||||
item->initSocket();
|
item->initSocket();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +86,7 @@ public:
|
|||||||
qCDebug(LOG_LIB) << "Tag" << _tag << "with used type" << _type;
|
qCDebug(LOG_LIB) << "Tag" << _tag << "with used type" << _type;
|
||||||
|
|
||||||
T *found = nullptr;
|
T *found = nullptr;
|
||||||
for (auto &item : m_items) {
|
for (auto item : m_items) {
|
||||||
if (item->tag(_type) != _tag)
|
if (item->tag(_type) != _tag)
|
||||||
continue;
|
continue;
|
||||||
found = static_cast<T *>(item);
|
found = static_cast<T *>(item);
|
||||||
@ -103,7 +103,7 @@ public:
|
|||||||
qCDebug(LOG_LIB) << "Number" << _number;
|
qCDebug(LOG_LIB) << "Number" << _number;
|
||||||
|
|
||||||
T *found = nullptr;
|
T *found = nullptr;
|
||||||
for (auto &item : m_items) {
|
for (auto item : m_items) {
|
||||||
if (item->number() != _number)
|
if (item->number() != _number)
|
||||||
continue;
|
continue;
|
||||||
found = static_cast<T *>(item);
|
found = static_cast<T *>(item);
|
||||||
@ -129,7 +129,7 @@ private:
|
|||||||
|
|
||||||
auto dirs = directories();
|
auto dirs = directories();
|
||||||
for (auto &dir : dirs) {
|
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) {
|
for (auto &file : files) {
|
||||||
// check filename
|
// check filename
|
||||||
if (!file.endsWith(".desktop"))
|
if (!file.endsWith(".desktop"))
|
||||||
@ -145,7 +145,7 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// sort items
|
// 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;
|
return items;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -111,8 +111,8 @@ QString DPAdds::toolTipImage(const int _desktop) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
// init
|
// init
|
||||||
auto *toolTipScene = new QGraphicsScene();
|
auto toolTipScene = new QGraphicsScene();
|
||||||
auto *toolTipView = new QGraphicsView(toolTipScene);
|
auto toolTipView = new QGraphicsView(toolTipScene);
|
||||||
toolTipView->setStyleSheet("background: transparent");
|
toolTipView->setStyleSheet("background: transparent");
|
||||||
toolTipView->setContentsMargins(0, 0, 0, 0);
|
toolTipView->setContentsMargins(0, 0, 0, 0);
|
||||||
toolTipView->setFrameShape(QFrame::NoFrame);
|
toolTipView->setFrameShape(QFrame::NoFrame);
|
||||||
|
@ -57,34 +57,33 @@ void ExtSysMonAggregator::init(const QHash<QString, QString> &_config)
|
|||||||
qCDebug(LOG_ESM) << "Configuration" << _config;
|
qCDebug(LOG_ESM) << "Configuration" << _config;
|
||||||
|
|
||||||
// battery
|
// battery
|
||||||
createSensor("battery", i18n("Battery"), new BatterySource(this, {_config["ACPIPATH"]}));
|
createSensor("battery", i18n("Battery"), new BatterySource(this, _config["ACPIPATH"]));
|
||||||
// custom
|
// custom
|
||||||
createSensor("custom", i18n("Scripts"), new CustomSource(this, {}));
|
createSensor("custom", i18n("Scripts"), new CustomSource(this));
|
||||||
// desktop
|
// desktop
|
||||||
// FIXME causes segfault in kde libs
|
createSensor("desktop", i18n("Desktop"), new DesktopSource(this));
|
||||||
// createSensor("desktop", i18n("Desktop"), new DesktopSource(this, {}));
|
|
||||||
// network
|
// network
|
||||||
createSensor("network", i18n("Network"), new NetworkSource(this, {}));
|
createSensor("network", i18n("Network"), new NetworkSource(this));
|
||||||
// player
|
// player
|
||||||
createSensor("player", i18n("Music player"),
|
createSensor("player", i18n("Music player"),
|
||||||
new PlayerSource(this, {_config["PLAYER"], _config["MPDADDRESS"], _config["MPDPORT"], _config["MPRIS"],
|
new PlayerSource(this, _config["PLAYER"], _config["MPDADDRESS"], _config["MPDPORT"].toInt(),
|
||||||
_config["PLAYERSYMBOLS"]}));
|
_config["MPRIS"], _config["PLAYERSYMBOLS"].toInt()));
|
||||||
// processes
|
// processes
|
||||||
createSensor("ps", i18n("Processes"), new ProcessesSource(this, {}));
|
createSensor("ps", i18n("Processes"), new ProcessesSource(this));
|
||||||
// network request
|
// network request
|
||||||
createSensor("requests", i18n("Network requests"), new RequestSource(this, {}));
|
createSensor("requests", i18n("Network requests"), new RequestSource(this));
|
||||||
// quotes
|
// quotes
|
||||||
createSensor("quotes", i18n("Quotes"), new QuotesSource(this, {}));
|
createSensor("quotes", i18n("Quotes"), new QuotesSource(this));
|
||||||
// system
|
// system
|
||||||
createSensor("system", i18n("System"), new SystemInfoSource(this, {}));
|
createSensor("system", i18n("System"), new SystemInfoSource(this));
|
||||||
// current time
|
// current time
|
||||||
createSensor("time", i18n("Time"), new TimeSource(this, {}));
|
createSensor("time", i18n("Time"), new TimeSource(this));
|
||||||
// upgrade
|
// upgrade
|
||||||
createSensor("upgrade", i18n("Upgrades"), new UpgradeSource(this, {}));
|
createSensor("upgrade", i18n("Upgrades"), new UpgradeSource(this));
|
||||||
// weather
|
// weather
|
||||||
createSensor("weather", i18n("Weather"), new WeatherSource(this, {}));
|
createSensor("weather", i18n("Weather"), new WeatherSource(this));
|
||||||
#ifdef BUILD_LOAD
|
#ifdef BUILD_LOAD
|
||||||
// additional load source
|
// additional load source
|
||||||
createSensor("load", i18n("Load"), new LoadSource(this, {}));
|
createSensor("load", i18n("Load"), new LoadSource(this));
|
||||||
#endif /* BUILD_LOAD */
|
#endif /* BUILD_LOAD */
|
||||||
}
|
}
|
||||||
|
@ -17,33 +17,58 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <ksysguard/systemstats/SensorInfo.h>
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
|
||||||
|
|
||||||
namespace KSysGuard
|
|
||||||
{
|
|
||||||
class SensorInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
class AbstractExtSysMonSource : public QObject
|
class AbstractExtSysMonSource : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit AbstractExtSysMonSource(QObject *_parent, const QStringList &)
|
inline static QRegularExpression NUMBER_REGEX = QRegularExpression("\\d+$");
|
||||||
|
|
||||||
|
explicit AbstractExtSysMonSource(QObject *_parent)
|
||||||
: QObject(_parent){};
|
: QObject(_parent){};
|
||||||
~AbstractExtSysMonSource() override = default;
|
~AbstractExtSysMonSource() override = default;
|
||||||
virtual QVariant data(const QString &_source) = 0;
|
virtual QVariant data(const QString &_source) = 0;
|
||||||
[[nodiscard]] virtual KSysGuard::SensorInfo *initialData(const QString &_source) const = 0;
|
[[nodiscard]] virtual QHash<QString, KSysGuard::SensorInfo *> sources() const = 0;
|
||||||
virtual void run() = 0;
|
|
||||||
[[nodiscard]] virtual QStringList sources() const = 0;
|
|
||||||
// used by extensions
|
// 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)
|
static int index(const QString &_source)
|
||||||
{
|
{
|
||||||
QRegularExpression rx("\\d+");
|
auto match = NUMBER_REGEX.match(_source);
|
||||||
return rx.match(_source).captured().toInt();
|
return match.hasMatch() ? match.captured().toInt() : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// safe value extractor
|
||||||
|
template <class T> static QVariantHash dataByItem(T *_extension, const QString &_source)
|
||||||
|
{
|
||||||
|
auto idx = index(_source);
|
||||||
|
if (idx == -1)
|
||||||
|
return {};
|
||||||
|
|
||||||
|
auto item = _extension->itemByTagNumber(idx);
|
||||||
|
return item ? item->run() : QVariantHash();
|
||||||
|
}
|
||||||
|
|
||||||
|
static KSysGuard::SensorInfo *makeSensorInfo(const QString &_name, const QVariant::Type type,
|
||||||
|
const KSysGuard::Unit unit = KSysGuard::UnitNone, const double min = 0,
|
||||||
|
const double max = 0)
|
||||||
|
{
|
||||||
|
auto info = new KSysGuard::SensorInfo();
|
||||||
|
info->name = _name;
|
||||||
|
info->variantType = type;
|
||||||
|
|
||||||
|
info->unit = unit;
|
||||||
|
|
||||||
|
info->min = min;
|
||||||
|
info->max = max;
|
||||||
|
|
||||||
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
@ -15,12 +15,8 @@
|
|||||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#include "batterysource.h"
|
#include "batterysource.h"
|
||||||
|
|
||||||
#include <ksysguard/formatter/Unit.h>
|
|
||||||
#include <ksysguard/systemstats/SensorInfo.h>
|
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
@ -28,51 +24,15 @@
|
|||||||
#include "awdebug.h"
|
#include "awdebug.h"
|
||||||
|
|
||||||
|
|
||||||
BatterySource::BatterySource(QObject *_parent, const QStringList &_args)
|
BatterySource::BatterySource(QObject *_parent, QString _acpiPath)
|
||||||
: AbstractExtSysMonSource(_parent, _args)
|
: 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__;
|
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);
|
auto directory = QDir(m_acpiPath);
|
||||||
|
m_batteriesCount = directory.entryList(QStringList({"BAT*"}), QDir::Dirs | QDir::NoDotAndDotDot).count();
|
||||||
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;
|
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -81,86 +41,11 @@ QVariant BatterySource::data(const QString &_source)
|
|||||||
qCDebug(LOG_ESS) << "Source" << _source;
|
qCDebug(LOG_ESS) << "Source" << _source;
|
||||||
|
|
||||||
if (!m_values.contains(_source))
|
if (!m_values.contains(_source))
|
||||||
run();
|
run(); // syncronous update of all values
|
||||||
return m_values.take(_source);
|
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()
|
void BatterySource::run()
|
||||||
{
|
{
|
||||||
// adaptor
|
// adaptor
|
||||||
@ -203,9 +88,32 @@ void BatterySource::run()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QStringList BatterySource::sources() const
|
QHash<QString, KSysGuard::SensorInfo *> BatterySource::sources() const
|
||||||
{
|
{
|
||||||
return m_sources;
|
auto result = QHash<QString, KSysGuard::SensorInfo *>();
|
||||||
|
|
||||||
|
// 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -30,13 +30,11 @@ class BatterySource : public AbstractExtSysMonSource
|
|||||||
public:
|
public:
|
||||||
const int TREND_LIMIT = 20;
|
const int TREND_LIMIT = 20;
|
||||||
|
|
||||||
explicit BatterySource(QObject *_parent, const QStringList &_args);
|
explicit BatterySource(QObject *_parent, QString _acpiPath);
|
||||||
~BatterySource() override;
|
~BatterySource() override = default;
|
||||||
QStringList getSources();
|
|
||||||
QVariant data(const QString &_source) override;
|
QVariant data(const QString &_source) override;
|
||||||
[[nodiscard]] KSysGuard::SensorInfo *initialData(const QString &_source) const override;
|
void run();
|
||||||
void run() override;
|
[[nodiscard]] QHash<QString, KSysGuard::SensorInfo *> sources() const override;
|
||||||
[[nodiscard]] QStringList sources() const override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static double approximate(const QList<int> &_trend);
|
static double approximate(const QList<int> &_trend);
|
||||||
|
@ -17,28 +17,17 @@
|
|||||||
|
|
||||||
#include "customsource.h"
|
#include "customsource.h"
|
||||||
|
|
||||||
#include <ksysguard/formatter/Unit.h>
|
|
||||||
#include <ksysguard/systemstats/SensorInfo.h>
|
|
||||||
|
|
||||||
#include "awdebug.h"
|
#include "awdebug.h"
|
||||||
#include "extscript.h"
|
#include "extscript.h"
|
||||||
|
|
||||||
|
|
||||||
CustomSource::CustomSource(QObject *_parent, const QStringList &_args)
|
CustomSource::CustomSource(QObject *_parent)
|
||||||
: AbstractExtSysMonSource(_parent, _args)
|
: AbstractExtSysMonSource(_parent)
|
||||||
{
|
{
|
||||||
Q_ASSERT(_args.count() == 0);
|
|
||||||
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
m_extScripts = new ExtItemAggregator<ExtScript>(nullptr, "scripts");
|
m_extScripts = new ExtItemAggregator<ExtScript>(this, "scripts");
|
||||||
m_extScripts->initSockets();
|
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;
|
qCDebug(LOG_ESS) << "Source" << _source;
|
||||||
|
|
||||||
// there are only one value
|
// there are only one value
|
||||||
return m_extScripts->itemByTagNumber(index(_source))->run().values().first();
|
return dataByItem(m_extScripts, _source).values().first();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
KSysGuard::SensorInfo *CustomSource::initialData(const QString &_source) const
|
QHash<QString, KSysGuard::SensorInfo *> CustomSource::sources() const
|
||||||
{
|
{
|
||||||
qCDebug(LOG_ESS) << "Source" << _source;
|
auto result = QHash<QString, KSysGuard::SensorInfo *>();
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QStringList CustomSource::sources() const
|
|
||||||
{
|
|
||||||
return m_sources;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QStringList CustomSource::getSources()
|
|
||||||
{
|
|
||||||
QStringList sources;
|
|
||||||
for (auto &item : m_extScripts->activeItems())
|
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;
|
||||||
}
|
}
|
||||||
|
@ -30,16 +30,12 @@ class CustomSource : public AbstractExtSysMonSource
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit CustomSource(QObject *_parent, const QStringList &_args);
|
explicit CustomSource(QObject *_parent);
|
||||||
~CustomSource() override;
|
~CustomSource() override = default;
|
||||||
QVariant data(const QString &_source) override;
|
QVariant data(const QString &_source) override;
|
||||||
[[nodiscard]] KSysGuard::SensorInfo *initialData(const QString &_source) const override;
|
[[nodiscard]] QHash<QString, KSysGuard::SensorInfo *> sources() const override;
|
||||||
void run() override{};
|
|
||||||
[[nodiscard]] QStringList sources() const override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QStringList getSources();
|
|
||||||
// configuration and values
|
// configuration and values
|
||||||
ExtItemAggregator<ExtScript> *m_extScripts = nullptr;
|
ExtItemAggregator<ExtScript> *m_extScripts = nullptr;
|
||||||
QStringList m_sources;
|
|
||||||
};
|
};
|
||||||
|
@ -17,29 +17,17 @@
|
|||||||
|
|
||||||
#include "desktopsource.h"
|
#include "desktopsource.h"
|
||||||
|
|
||||||
#include <KWindowSystem/KWindowSystem>
|
#include <QDBusConnection>
|
||||||
#include <ksysguard/formatter/Unit.h>
|
#include <QDBusMessage>
|
||||||
#include <ksysguard/systemstats/SensorInfo.h>
|
#include <QDBusVariant>
|
||||||
#include <taskmanager/virtualdesktopinfo.h>
|
|
||||||
|
|
||||||
#include "awdebug.h"
|
#include "awdebug.h"
|
||||||
|
|
||||||
|
|
||||||
DesktopSource::DesktopSource(QObject *_parent, const QStringList &_args)
|
DesktopSource::DesktopSource(QObject *_parent)
|
||||||
: AbstractExtSysMonSource(_parent, _args)
|
: 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__;
|
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
m_vdi->deleteLater();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -47,60 +35,72 @@ QVariant DesktopSource::data(const QString &_source)
|
|||||||
{
|
{
|
||||||
qCDebug(LOG_ESS) << "Source" << _source;
|
qCDebug(LOG_ESS) << "Source" << _source;
|
||||||
|
|
||||||
auto nativeIndex = m_vdi->position(m_vdi->currentDesktop());
|
auto current = getDBusProperty({"org.kde.KWin.VirtualDesktopManager", "current"}).toString();
|
||||||
auto decrement = KWindowSystem::isPlatformX11() ? 1 : 0;
|
auto desktops
|
||||||
auto current = nativeIndex - decrement;
|
= extractDesktops(getDBusProperty({"org.kde.KWin.VirtualDesktopManager", "desktops"}).value<QDBusArgument>());
|
||||||
|
|
||||||
if (_source == "name") {
|
if (_source == "name") {
|
||||||
return m_vdi->desktopNames().at(current);
|
return desktops[current].second;
|
||||||
} else if (_source == "number") {
|
} else if (_source == "number") {
|
||||||
return current + 1;
|
return desktops[current].first + 1;
|
||||||
} else if (_source == "names") {
|
|
||||||
return m_vdi->desktopNames();
|
|
||||||
} else if (_source == "count") {
|
} else if (_source == "count") {
|
||||||
return m_vdi->numberOfDesktops();
|
return desktops.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
KSysGuard::SensorInfo *DesktopSource::initialData(const QString &_source) const
|
QHash<QString, KSysGuard::SensorInfo *> DesktopSource::sources() const
|
||||||
{
|
{
|
||||||
qCDebug(LOG_ESS) << "Source" << _source;
|
auto result = QHash<QString, KSysGuard::SensorInfo *>();
|
||||||
|
|
||||||
auto data = new KSysGuard::SensorInfo();
|
result.insert("name", makeSensorInfo("Current desktop name", QVariant::String));
|
||||||
if (_source == "name") {
|
result.insert("number", makeSensorInfo("Current desktop number", QVariant::Int));
|
||||||
data->name = "Current desktop name";
|
result.insert("count", makeSensorInfo("Desktops count", QVariant::Int));
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
return data;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QStringList DesktopSource::sources() const
|
QHash<QString, QPair<int, QString>> DesktopSource::extractDesktops(const QDBusArgument &_result)
|
||||||
{
|
{
|
||||||
QStringList sources;
|
QHash<QString, QPair<int, QString>> result;
|
||||||
sources.append("name");
|
|
||||||
sources.append("number");
|
|
||||||
sources.append("names");
|
|
||||||
sources.append("count");
|
|
||||||
|
|
||||||
return sources;
|
_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 result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QVariant DesktopSource::getDBusProperty(const QVariantList &_args)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_ESS) << "Get VDI property" << _args;
|
||||||
|
|
||||||
|
auto bus = QDBusConnection::sessionBus();
|
||||||
|
auto request
|
||||||
|
= QDBusMessage::createMethodCall(KWinDBusAdapter, VDIDBusPath, PropertyDBusInterface, PropertyDBusMethod);
|
||||||
|
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 {};
|
||||||
|
} else {
|
||||||
|
auto value = response.arguments().first();
|
||||||
|
return value.value<QDBusVariant>().variant();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,22 +22,23 @@
|
|||||||
#include "abstractextsysmonsource.h"
|
#include "abstractextsysmonsource.h"
|
||||||
|
|
||||||
|
|
||||||
namespace TaskManager
|
|
||||||
{
|
|
||||||
class VirtualDesktopInfo;
|
|
||||||
}
|
|
||||||
class DesktopSource : public AbstractExtSysMonSource
|
class DesktopSource : public AbstractExtSysMonSource
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit DesktopSource(QObject *_parent, const QStringList &_args);
|
static constexpr auto KWinDBusAdapter = "org.kde.KWin";
|
||||||
~DesktopSource() override;
|
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;
|
QVariant data(const QString &_source) override;
|
||||||
[[nodiscard]] KSysGuard::SensorInfo *initialData(const QString &_source) const override;
|
[[nodiscard]] QHash<QString, KSysGuard::SensorInfo *> sources() const override;
|
||||||
void run() override{};
|
|
||||||
[[nodiscard]] QStringList sources() const override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TaskManager::VirtualDesktopInfo *m_vdi = nullptr;
|
static QHash<QString, QPair<int, QString>> extractDesktops(const QDBusArgument &_result);
|
||||||
|
static QVariant getDBusProperty(const QVariantList &_args);
|
||||||
};
|
};
|
||||||
|
@ -33,8 +33,8 @@ ExtSysMonSensor::ExtSysMonSensor(KSysGuard::SensorContainer *_parent, const QStr
|
|||||||
|
|
||||||
loadProperties();
|
loadProperties();
|
||||||
|
|
||||||
connect(this, &SensorObject::subscribedChanged, [this](bool _state) { changeSubscription(_state); });
|
connect(this, &SensorObject::subscribedChanged, this, &ExtSysMonSensor::changeSubscription);
|
||||||
connect(m_timer, &QTimer::timeout, [this]() { update(); });
|
connect(m_timer, &QTimer::timeout, this, &ExtSysMonSensor::update);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -61,21 +61,22 @@ void ExtSysMonSensor::changeSubscription(bool _subscribed)
|
|||||||
|
|
||||||
void ExtSysMonSensor::update()
|
void ExtSysMonSensor::update()
|
||||||
{
|
{
|
||||||
for (auto &source : m_source->sources()) {
|
for (auto sensor : sensors()) {
|
||||||
auto property = sensor(source);
|
if (!sensor->isSubscribed())
|
||||||
if (!property->isSubscribed())
|
|
||||||
continue; // skip properties which are not explicitly subscribed
|
continue; // skip properties which are not explicitly subscribed
|
||||||
|
|
||||||
auto value = m_source->data(source);
|
auto value = m_source->data(sensor->id());
|
||||||
property->setValue(value);
|
sensor->setValue(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ExtSysMonSensor::loadProperties()
|
void ExtSysMonSensor::loadProperties()
|
||||||
{
|
{
|
||||||
for (auto &source : m_source->sources()) {
|
auto sensors = m_source->sources();
|
||||||
auto info = m_source->initialData(source);
|
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);
|
auto property = new KSysGuard::SensorProperty(source, info->name, this);
|
||||||
|
|
||||||
property->setUnit(info->unit);
|
property->setUnit(info->unit);
|
||||||
|
@ -31,6 +31,8 @@ public:
|
|||||||
explicit ExtSysMonSensor(KSysGuard::SensorContainer *_parent, const QString &_id, const QString &_name,
|
explicit ExtSysMonSensor(KSysGuard::SensorContainer *_parent, const QString &_id, const QString &_name,
|
||||||
AbstractExtSysMonSource *_source);
|
AbstractExtSysMonSource *_source);
|
||||||
~ExtSysMonSensor() override;
|
~ExtSysMonSensor() override;
|
||||||
|
|
||||||
|
public slots:
|
||||||
void changeSubscription(bool _subscribed);
|
void changeSubscription(bool _subscribed);
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
|
@ -15,26 +15,15 @@
|
|||||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#include "loadsource.h"
|
#include "loadsource.h"
|
||||||
|
|
||||||
#include <ksysguard/formatter/Unit.h>
|
|
||||||
#include <ksysguard/systemstats/SensorInfo.h>
|
|
||||||
|
|
||||||
#include <QRandomGenerator>
|
#include <QRandomGenerator>
|
||||||
|
|
||||||
#include "awdebug.h"
|
#include "awdebug.h"
|
||||||
|
|
||||||
|
|
||||||
LoadSource::LoadSource(QObject *_parent, const QStringList &_args)
|
LoadSource::LoadSource(QObject *_parent)
|
||||||
: AbstractExtSysMonSource(_parent, _args)
|
: AbstractExtSysMonSource(_parent)
|
||||||
{
|
|
||||||
Q_ASSERT(_args.count() == 0);
|
|
||||||
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
LoadSource::~LoadSource()
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
|
||||||
}
|
}
|
||||||
@ -48,28 +37,12 @@ QVariant LoadSource::data(const QString &_source)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
KSysGuard::SensorInfo *LoadSource::initialData(const QString &_source) const
|
QHash<QString, KSysGuard::SensorInfo *> LoadSource::sources() const
|
||||||
{
|
{
|
||||||
qCDebug(LOG_ESS) << "Source" << _source;
|
auto result = QHash<QString, KSysGuard::SensorInfo *>();
|
||||||
|
|
||||||
auto data = new KSysGuard::SensorInfo();
|
for (auto i = 0; i < 1000; i++)
|
||||||
if (_source.startsWith("load")) {
|
result.insert(QString("load%1").arg(i), makeSensorInfo("Simple sources for load tests", QVariant::Int));
|
||||||
data->min = 0;
|
|
||||||
data->max = 0;
|
return result;
|
||||||
data->name = "Simple sources for load tests";
|
|
||||||
data->variantType = QVariant::Int;
|
|
||||||
data->unit = KSysGuard::UnitNone;
|
|
||||||
}
|
|
||||||
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QStringList LoadSource::sources() const
|
|
||||||
{
|
|
||||||
QStringList sources;
|
|
||||||
for (int i = 0; i < 1000; i++)
|
|
||||||
sources.append(QString("load%1").arg(i));
|
|
||||||
|
|
||||||
return sources;
|
|
||||||
}
|
}
|
||||||
|
@ -27,10 +27,8 @@ class LoadSource : public AbstractExtSysMonSource
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit LoadSource(QObject *_parent, const QStringList &_args);
|
explicit LoadSource(QObject *_parent);
|
||||||
~LoadSource() override;
|
~LoadSource() override = default;
|
||||||
QVariant data(const QString &_source) override;
|
QVariant data(const QString &_source) override;
|
||||||
[[nodiscard]] KSysGuard::SensorInfo *initialData(const QString &_source) const override;
|
[[nodiscard]] QHash<QString, KSysGuard::SensorInfo *> sources() const override;
|
||||||
void run() override{};
|
|
||||||
[[nodiscard]] QStringList sources() const override;
|
|
||||||
};
|
};
|
||||||
|
@ -15,22 +15,17 @@
|
|||||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#include "networksource.h"
|
#include "networksource.h"
|
||||||
|
|
||||||
#include <ksysguard/formatter/Unit.h>
|
|
||||||
#include <ksysguard/systemstats/SensorInfo.h>
|
|
||||||
|
|
||||||
#include <QNetworkInterface>
|
#include <QNetworkInterface>
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
|
|
||||||
#include "awdebug.h"
|
#include "awdebug.h"
|
||||||
|
|
||||||
|
|
||||||
NetworkSource::NetworkSource(QObject *_parent, const QStringList &_args)
|
NetworkSource::NetworkSource(QObject *_parent)
|
||||||
: AbstractExtSysMonSource(_parent, _args)
|
: AbstractExtSysMonSource(_parent)
|
||||||
{
|
{
|
||||||
Q_ASSERT(_args.count() == 0);
|
|
||||||
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
m_process = new QProcess(nullptr);
|
m_process = new QProcess(nullptr);
|
||||||
@ -54,47 +49,26 @@ QVariant NetworkSource::data(const QString &_source)
|
|||||||
{
|
{
|
||||||
qCDebug(LOG_ESS) << "Source" << _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") {
|
if (_source == "device") {
|
||||||
data->name = "Current network device name";
|
return NetworkSource::getCurrentDevice();
|
||||||
data->variantType = QVariant::String;
|
|
||||||
data->unit = KSysGuard::UnitNone;
|
|
||||||
} else if (_source == "ssid") {
|
} else if (_source == "ssid") {
|
||||||
data->name = "Current SSID name";
|
if (m_process->state() == QProcess::ProcessState::NotRunning)
|
||||||
data->variantType = QVariant::String;
|
|
||||||
data->unit = KSysGuard::UnitNone;
|
|
||||||
}
|
|
||||||
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void NetworkSource::run()
|
|
||||||
{
|
|
||||||
m_values["device"] = NetworkSource::getCurrentDevice();
|
|
||||||
if (m_process->state() == QProcess::ProcessState::NotRunning) {
|
|
||||||
m_process->start("iwgetid", {"-r"});
|
m_process->start("iwgetid", {"-r"});
|
||||||
|
return m_currentSsid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QStringList NetworkSource::sources() const
|
QHash<QString, KSysGuard::SensorInfo *> NetworkSource::sources() const
|
||||||
{
|
{
|
||||||
QStringList sources;
|
auto result = QHash<QString, KSysGuard::SensorInfo *>();
|
||||||
sources.append("device");
|
|
||||||
sources.append("ssid");
|
|
||||||
|
|
||||||
return sources;
|
result.insert("device", makeSensorInfo("Current network device name", QVariant::String));
|
||||||
|
result.insert("ssid", makeSensorInfo("Current SSID name", QVariant::String));
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -106,7 +80,7 @@ void NetworkSource::updateSsid()
|
|||||||
QString qoutput = QString::fromUtf8(m_process->readAllStandardOutput()).trimmed();
|
QString qoutput = QString::fromUtf8(m_process->readAllStandardOutput()).trimmed();
|
||||||
qCInfo(LOG_ESS) << "Output" << qoutput;
|
qCInfo(LOG_ESS) << "Output" << qoutput;
|
||||||
|
|
||||||
m_values["ssid"] = qoutput;
|
m_currentSsid = qoutput;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -29,18 +29,17 @@ class NetworkSource : public AbstractExtSysMonSource
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit NetworkSource(QObject *_parent, const QStringList &_args);
|
explicit NetworkSource(QObject *_parent);
|
||||||
~NetworkSource() override;
|
~NetworkSource() override;
|
||||||
QVariant data(const QString &_source) override;
|
QVariant data(const QString &_source) override;
|
||||||
[[nodiscard]] KSysGuard::SensorInfo *initialData(const QString &_source) const override;
|
void run();
|
||||||
void run() override;
|
[[nodiscard]] QHash<QString, KSysGuard::SensorInfo *> sources() const override;
|
||||||
[[nodiscard]] QStringList sources() const override;
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void updateSsid();
|
void updateSsid();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QVariantHash m_values;
|
QString m_currentSsid;
|
||||||
QProcess *m_process = nullptr;
|
QProcess *m_process = nullptr;
|
||||||
static QString getCurrentDevice();
|
static QString getCurrentDevice();
|
||||||
};
|
};
|
||||||
|
@ -15,12 +15,8 @@
|
|||||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#include "playersource.h"
|
#include "playersource.h"
|
||||||
|
|
||||||
#include <ksysguard/formatter/Unit.h>
|
|
||||||
#include <ksysguard/systemstats/SensorInfo.h>
|
|
||||||
|
|
||||||
#include <QDBusArgument>
|
#include <QDBusArgument>
|
||||||
#include <QDBusConnection>
|
#include <QDBusConnection>
|
||||||
#include <QDBusConnectionInterface>
|
#include <QDBusConnectionInterface>
|
||||||
@ -30,18 +26,17 @@
|
|||||||
#include "awdebug.h"
|
#include "awdebug.h"
|
||||||
|
|
||||||
|
|
||||||
PlayerSource::PlayerSource(QObject *_parent, const QStringList &_args)
|
PlayerSource::PlayerSource(QObject *_parent, QString _player, QString _mpdAddress, int _mpdPort, QString _mpris,
|
||||||
: AbstractExtSysMonSource(_parent, _args)
|
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__;
|
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::connected, this, &PlayerSource::mpdSocketConnected);
|
||||||
connect(&m_mpdSocket, &QTcpSocket::readyRead, this, &PlayerSource::mpdSocketReadyRead);
|
connect(&m_mpdSocket, &QTcpSocket::readyRead, this, &PlayerSource::mpdSocketReadyRead);
|
||||||
connect(&m_mpdSocket, &QTcpSocket::bytesWritten, this, &PlayerSource::mpdSocketWritten);
|
connect(&m_mpdSocket, &QTcpSocket::bytesWritten, this, &PlayerSource::mpdSocketWritten);
|
||||||
@ -62,26 +57,25 @@ QVariant PlayerSource::data(const QString &_source)
|
|||||||
qCDebug(LOG_ESS) << "Source" << _source;
|
qCDebug(LOG_ESS) << "Source" << _source;
|
||||||
|
|
||||||
if (!m_values.contains(_source))
|
if (!m_values.contains(_source))
|
||||||
run();
|
run(); // syncronous update of all values
|
||||||
QVariant value = m_values.take(_source);
|
|
||||||
return value;
|
return m_values.take(_source);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString PlayerSource::getAutoMpris()
|
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()) {
|
if (listServices.arguments().isEmpty()) {
|
||||||
qCWarning(LOG_ESS) << "Could not find any DBus service";
|
qCWarning(LOG_ESS) << "Could not find any DBus service";
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
QStringList arguments = listServices.arguments().first().toStringList();
|
auto arguments = listServices.arguments().first().toStringList();
|
||||||
|
|
||||||
for (auto &arg : arguments) {
|
for (auto &service : arguments) {
|
||||||
if (!arg.startsWith("org.mpris.MediaPlayer2."))
|
if (!service.startsWith("org.mpris.MediaPlayer2."))
|
||||||
continue;
|
continue;
|
||||||
qCInfo(LOG_ESS) << "Service found" << arg;
|
qCInfo(LOG_ESS) << "Service found" << service;
|
||||||
QString service = arg;
|
|
||||||
service.remove("org.mpris.MediaPlayer2.");
|
service.remove("org.mpris.MediaPlayer2.");
|
||||||
return service;
|
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()
|
void PlayerSource::run()
|
||||||
{
|
{
|
||||||
// initial data
|
// initial data
|
||||||
@ -176,22 +111,29 @@ void PlayerSource::run()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QStringList PlayerSource::sources() const
|
QHash<QString, KSysGuard::SensorInfo *> PlayerSource::sources() const
|
||||||
{
|
{
|
||||||
QStringList sources;
|
auto result = QHash<QString, KSysGuard::SensorInfo *>();
|
||||||
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;
|
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;
|
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()))
|
if ((_current.isEmpty()) || ((index + _s + 1) > _value.length()))
|
||||||
return QString("%1").arg(_value.left(_s), -_s, QLatin1Char(' '));
|
return QString("%1").arg(_value.left(_s), -_s, QLatin1Char(' '));
|
||||||
else
|
else
|
||||||
@ -230,7 +172,7 @@ void PlayerSource::mpdSocketConnected()
|
|||||||
|
|
||||||
void PlayerSource::mpdSocketReadyRead()
|
void PlayerSource::mpdSocketReadyRead()
|
||||||
{
|
{
|
||||||
QString qoutput = QString::fromUtf8(m_mpdSocket.readAll()).trimmed();
|
auto qoutput = QString::fromUtf8(m_mpdSocket.readAll()).trimmed();
|
||||||
qCInfo(LOG_ESS) << "Output" << qoutput;
|
qCInfo(LOG_ESS) << "Output" << qoutput;
|
||||||
|
|
||||||
// parse
|
// parse
|
||||||
@ -307,9 +249,8 @@ QVariantHash PlayerSource::getPlayerMprisInfo(const QString &_mpris)
|
|||||||
// /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get
|
// /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get
|
||||||
// string:'org.mpris.MediaPlayer2.Player' string:'Metadata'
|
// string:'org.mpris.MediaPlayer2.Player' string:'Metadata'
|
||||||
auto args = QVariantList({"org.mpris.MediaPlayer2.Player", "Metadata"});
|
auto args = QVariantList({"org.mpris.MediaPlayer2.Player", "Metadata"});
|
||||||
QDBusMessage request
|
auto request = QDBusMessage::createMethodCall(QString("org.mpris.MediaPlayer2.%1").arg(_mpris),
|
||||||
= QDBusMessage::createMethodCall(QString("org.mpris.MediaPlayer2.%1").arg(_mpris), "/org/mpris/MediaPlayer2",
|
"/org/mpris/MediaPlayer2", "org.freedesktop.DBus.Properties", "Get");
|
||||||
"org.freedesktop.DBus.Properties", "Get");
|
|
||||||
request.setArguments(args);
|
request.setArguments(args);
|
||||||
auto response = bus.call(request, QDBus::BlockWithGui, REQUEST_TIMEOUT);
|
auto response = bus.call(request, QDBus::BlockWithGui, REQUEST_TIMEOUT);
|
||||||
if ((response.type() != QDBusMessage::ReplyMessage) || (response.arguments().isEmpty())) {
|
if ((response.type() != QDBusMessage::ReplyMessage) || (response.arguments().isEmpty())) {
|
||||||
|
@ -33,13 +33,13 @@ class PlayerSource : public AbstractExtSysMonSource
|
|||||||
public:
|
public:
|
||||||
const char *MPD_STATUS_REQUEST = "currentsong\nstatus\n";
|
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;
|
~PlayerSource() override;
|
||||||
QVariant data(const QString &_source) override;
|
QVariant data(const QString &_source) override;
|
||||||
static QString getAutoMpris();
|
static QString getAutoMpris();
|
||||||
[[nodiscard]] KSysGuard::SensorInfo *initialData(const QString &_source) const override;
|
void run();
|
||||||
void run() override;
|
[[nodiscard]] QHash<QString, KSysGuard::SensorInfo *> sources() const override;
|
||||||
[[nodiscard]] QStringList sources() const override;
|
|
||||||
// additional method to build dynamic tags
|
// additional method to build dynamic tags
|
||||||
static QString buildString(const QString &_current, const QString &_value, int _s);
|
static QString buildString(const QString &_current, const QString &_value, int _s);
|
||||||
static QString stripString(const QString &_value, int _s);
|
static QString stripString(const QString &_value, int _s);
|
||||||
|
@ -15,26 +15,15 @@
|
|||||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#include "processessource.h"
|
#include "processessource.h"
|
||||||
|
|
||||||
#include <ksysguard/formatter/Unit.h>
|
|
||||||
#include <ksysguard/systemstats/SensorInfo.h>
|
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
|
||||||
#include "awdebug.h"
|
#include "awdebug.h"
|
||||||
|
|
||||||
|
|
||||||
ProcessesSource::ProcessesSource(QObject *_parent, const QStringList &_args)
|
ProcessesSource::ProcessesSource(QObject *_parent)
|
||||||
: AbstractExtSysMonSource(_parent, _args)
|
: AbstractExtSysMonSource(_parent)
|
||||||
{
|
|
||||||
Q_ASSERT(_args.count() == 0);
|
|
||||||
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ProcessesSource::~ProcessesSource()
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
|
||||||
}
|
}
|
||||||
@ -45,45 +34,18 @@ QVariant ProcessesSource::data(const QString &_source)
|
|||||||
qCDebug(LOG_ESS) << "Source" << _source;
|
qCDebug(LOG_ESS) << "Source" << _source;
|
||||||
|
|
||||||
if (!m_values.contains(_source))
|
if (!m_values.contains(_source))
|
||||||
run();
|
run(); // syncronous update of all values
|
||||||
QVariant value = m_values.take(_source);
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
return m_values.take(_source);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ProcessesSource::run()
|
void ProcessesSource::run()
|
||||||
{
|
{
|
||||||
QStringList allDirectories = QDir("/proc").entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name);
|
auto allDirectories = QDir("/proc").entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name);
|
||||||
QStringList directories = allDirectories.filter(QRegularExpression("(\\d+)"));
|
auto directories = allDirectories.filter(QRegularExpression("(\\d+)"));
|
||||||
QStringList running;
|
|
||||||
|
|
||||||
|
QStringList running;
|
||||||
for (auto &dir : directories) {
|
for (auto &dir : directories) {
|
||||||
QFile statusFile(QString("/proc/%1/status").arg(dir));
|
QFile statusFile(QString("/proc/%1/status").arg(dir));
|
||||||
if (!statusFile.open(QIODevice::ReadOnly | QIODevice::Text))
|
if (!statusFile.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||||
@ -92,7 +54,7 @@ void ProcessesSource::run()
|
|||||||
if (!cmdFile.open(QIODevice::ReadOnly | QIODevice::Text))
|
if (!cmdFile.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
QString output = statusFile.readAll();
|
auto output = statusFile.readAll();
|
||||||
if (output.contains("running"))
|
if (output.contains("running"))
|
||||||
running.append(cmdFile.readAll());
|
running.append(cmdFile.readAll());
|
||||||
statusFile.close();
|
statusFile.close();
|
||||||
@ -105,12 +67,13 @@ void ProcessesSource::run()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QStringList ProcessesSource::sources() const
|
QHash<QString, KSysGuard::SensorInfo *> ProcessesSource::sources() const
|
||||||
{
|
{
|
||||||
QStringList sources;
|
auto result = QHash<QString, KSysGuard::SensorInfo *>();
|
||||||
sources.append("running");
|
|
||||||
sources.append("list");
|
|
||||||
sources.append("count");
|
|
||||||
|
|
||||||
return sources;
|
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 result;
|
||||||
}
|
}
|
||||||
|
@ -27,12 +27,11 @@ class ProcessesSource : public AbstractExtSysMonSource
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ProcessesSource(QObject *_parent, const QStringList &_args);
|
explicit ProcessesSource(QObject *_parent);
|
||||||
~ProcessesSource() override;
|
~ProcessesSource() override = default;
|
||||||
QVariant data(const QString &_source) override;
|
QVariant data(const QString &_source) override;
|
||||||
[[nodiscard]] KSysGuard::SensorInfo *initialData(const QString &_source) const override;
|
void run();
|
||||||
void run() override;
|
[[nodiscard]] QHash<QString, KSysGuard::SensorInfo *> sources() const override;
|
||||||
[[nodiscard]] QStringList sources() const override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// configuration and values
|
// configuration and values
|
||||||
|
@ -15,31 +15,19 @@
|
|||||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#include "quotessource.h"
|
#include "quotessource.h"
|
||||||
|
|
||||||
#include <ksysguard/formatter/Unit.h>
|
|
||||||
#include <ksysguard/systemstats/SensorInfo.h>
|
|
||||||
|
|
||||||
#include "awdebug.h"
|
#include "awdebug.h"
|
||||||
#include "extquotes.h"
|
#include "extquotes.h"
|
||||||
|
|
||||||
|
|
||||||
QuotesSource::QuotesSource(QObject *_parent, const QStringList &_args)
|
QuotesSource::QuotesSource(QObject *_parent)
|
||||||
: AbstractExtSysMonSource(_parent, _args)
|
: AbstractExtSysMonSource(_parent)
|
||||||
{
|
{
|
||||||
Q_ASSERT(_args.count() == 0);
|
|
||||||
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
m_extQuotes = new ExtItemAggregator<ExtQuotes>(nullptr, "quotes");
|
m_extQuotes = new ExtItemAggregator<ExtQuotes>(nullptr, "quotes");
|
||||||
m_extQuotes->initSockets();
|
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;
|
qCDebug(LOG_ESS) << "Source" << _source;
|
||||||
|
|
||||||
int ind = index(_source);
|
if (!m_values.contains(_source))
|
||||||
if (!m_values.contains(_source)) {
|
m_values = dataByItem(m_extQuotes, _source);
|
||||||
QVariantHash data = m_extQuotes->itemByTagNumber(ind)->run();
|
|
||||||
for (auto &key : data.keys())
|
return m_values.take(_source);
|
||||||
m_values[key] = data[key];
|
|
||||||
}
|
|
||||||
QVariant value = m_values.take(_source);
|
|
||||||
return value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
KSysGuard::SensorInfo *QuotesSource::initialData(const QString &_source) const
|
QHash<QString, KSysGuard::SensorInfo *> QuotesSource::sources() const
|
||||||
{
|
{
|
||||||
qCDebug(LOG_ESS) << "Source" << _source;
|
auto result = QHash<QString, KSysGuard::SensorInfo *>();
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QStringList QuotesSource::sources() const
|
|
||||||
{
|
|
||||||
return m_sources;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QStringList QuotesSource::getSources()
|
|
||||||
{
|
|
||||||
QStringList sources;
|
|
||||||
for (auto &item : m_extQuotes->activeItems()) {
|
for (auto &item : m_extQuotes->activeItems()) {
|
||||||
sources.append(item->tag("price"));
|
result.insert(item->tag("pricechg"),
|
||||||
sources.append(item->tag("pricechg"));
|
makeSensorInfo(QString("Absolute price changes for '%1'").arg(item->uniq()), QVariant::Double));
|
||||||
sources.append(item->tag("percpricechg"));
|
result.insert(item->tag("price"),
|
||||||
sources.append(item->tag("volume"));
|
makeSensorInfo(QString("Price for '%1'").arg(item->uniq()), QVariant::Double));
|
||||||
sources.append(item->tag("volumechg"));
|
result.insert(item->tag("percpricechg"), makeSensorInfo(QString("Price changes for '%1'").arg(item->uniq()),
|
||||||
sources.append(item->tag("percvolumechg"));
|
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;
|
||||||
}
|
}
|
||||||
|
@ -30,17 +30,13 @@ class QuotesSource : public AbstractExtSysMonSource
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit QuotesSource(QObject *_parent, const QStringList &_args);
|
explicit QuotesSource(QObject *_parent);
|
||||||
~QuotesSource() override;
|
~QuotesSource() override = default;
|
||||||
QVariant data(const QString &_source) override;
|
QVariant data(const QString &_source) override;
|
||||||
[[nodiscard]] KSysGuard::SensorInfo *initialData(const QString &_source) const override;
|
[[nodiscard]] QHash<QString, KSysGuard::SensorInfo *> sources() const override;
|
||||||
void run() override{};
|
|
||||||
[[nodiscard]] QStringList sources() const override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QStringList getSources();
|
|
||||||
// configuration and values
|
// configuration and values
|
||||||
ExtItemAggregator<ExtQuotes> *m_extQuotes = nullptr;
|
ExtItemAggregator<ExtQuotes> *m_extQuotes = nullptr;
|
||||||
QStringList m_sources;
|
|
||||||
QVariantHash m_values;
|
QVariantHash m_values;
|
||||||
};
|
};
|
||||||
|
@ -15,31 +15,19 @@
|
|||||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#include "requestsource.h"
|
#include "requestsource.h"
|
||||||
|
|
||||||
#include <ksysguard/formatter/Unit.h>
|
|
||||||
#include <ksysguard/systemstats/SensorInfo.h>
|
|
||||||
|
|
||||||
#include "awdebug.h"
|
#include "awdebug.h"
|
||||||
#include "extnetworkrequest.h"
|
#include "extnetworkrequest.h"
|
||||||
|
|
||||||
|
|
||||||
RequestSource::RequestSource(QObject *_parent, const QStringList &_args)
|
RequestSource::RequestSource(QObject *_parent)
|
||||||
: AbstractExtSysMonSource(_parent, _args)
|
: AbstractExtSysMonSource(_parent)
|
||||||
{
|
{
|
||||||
Q_ASSERT(_args.count() == 0);
|
|
||||||
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
m_extNetRequest = new ExtItemAggregator<ExtNetworkRequest>(nullptr, "requests");
|
m_extNetRequest = new ExtItemAggregator<ExtNetworkRequest>(nullptr, "requests");
|
||||||
m_extNetRequest->initSockets();
|
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;
|
qCDebug(LOG_ESS) << "Source" << _source;
|
||||||
|
|
||||||
int ind = index(_source);
|
// there are only one value
|
||||||
if (!m_values.contains(_source)) {
|
return dataByItem(m_extNetRequest, _source).values().first();
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
KSysGuard::SensorInfo *RequestSource::initialData(const QString &_source) const
|
QHash<QString, KSysGuard::SensorInfo *> RequestSource::sources() const
|
||||||
{
|
{
|
||||||
qCDebug(LOG_ESS) << "Source" << _source;
|
auto result = QHash<QString, KSysGuard::SensorInfo *>();
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QStringList RequestSource::sources() const
|
|
||||||
{
|
|
||||||
return m_sources;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QStringList RequestSource::getSources()
|
|
||||||
{
|
|
||||||
QStringList sources;
|
|
||||||
for (auto &item : m_extNetRequest->activeItems())
|
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;
|
||||||
}
|
}
|
||||||
|
@ -30,17 +30,13 @@ class RequestSource : public AbstractExtSysMonSource
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit RequestSource(QObject *_parent, const QStringList &_args);
|
explicit RequestSource(QObject *_parent);
|
||||||
~RequestSource() override;
|
~RequestSource() override = default;
|
||||||
QVariant data(const QString &_source) override;
|
QVariant data(const QString &_source) override;
|
||||||
[[nodiscard]] KSysGuard::SensorInfo *initialData(const QString &_source) const override;
|
[[nodiscard]] QHash<QString, KSysGuard::SensorInfo *> sources() const override;
|
||||||
void run() override{};
|
|
||||||
[[nodiscard]] QStringList sources() const override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QStringList getSources();
|
|
||||||
// configuration and values
|
// configuration and values
|
||||||
ExtItemAggregator<ExtNetworkRequest> *m_extNetRequest = nullptr;
|
ExtItemAggregator<ExtNetworkRequest> *m_extNetRequest = nullptr;
|
||||||
QStringList m_sources;
|
|
||||||
QVariantHash m_values;
|
QVariantHash m_values;
|
||||||
};
|
};
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#include "systeminfosource.h"
|
#include "systeminfosource.h"
|
||||||
|
|
||||||
#include <ksysguard/formatter/Unit.h>
|
#include <ksysguard/formatter/Unit.h>
|
||||||
@ -30,15 +29,8 @@
|
|||||||
#include "awdebug.h"
|
#include "awdebug.h"
|
||||||
|
|
||||||
|
|
||||||
SystemInfoSource::SystemInfoSource(QObject *_parent, const QStringList &_args)
|
SystemInfoSource::SystemInfoSource(QObject *_parent)
|
||||||
: AbstractExtSysMonSource(_parent, _args)
|
: AbstractExtSysMonSource(_parent)
|
||||||
{
|
|
||||||
Q_ASSERT(_args.count() == 0);
|
|
||||||
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SystemInfoSource::~SystemInfoSource()
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
|
||||||
}
|
}
|
||||||
@ -48,55 +40,30 @@ QVariant SystemInfoSource::data(const QString &_source)
|
|||||||
{
|
{
|
||||||
qCDebug(LOG_ESS) << "Source" << _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") {
|
if (_source == "brightness") {
|
||||||
data->min = 0.0;
|
return SystemInfoSource::getCurrentBrightness();
|
||||||
data->max = 100.0;
|
|
||||||
data->name = "Screen brightness";
|
|
||||||
data->variantType = QVariant::Double;
|
|
||||||
data->unit = KSysGuard::UnitPercent;
|
|
||||||
} else if (_source == "volume") {
|
} else if (_source == "volume") {
|
||||||
data->min = 0.0;
|
return SystemInfoSource::getCurrentVolume();
|
||||||
data->max = 100.0;
|
|
||||||
data->name = "Master volume";
|
|
||||||
data->variantType = QVariant::Double;
|
|
||||||
data->unit = KSysGuard::UnitPercent;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return data;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SystemInfoSource::run()
|
QHash<QString, KSysGuard::SensorInfo *> SystemInfoSource::sources() const
|
||||||
{
|
{
|
||||||
m_values["brightness"] = SystemInfoSource::getCurrentBrightness();
|
auto result = QHash<QString, KSysGuard::SensorInfo *>();
|
||||||
m_values["volume"] = SystemInfoSource::getCurrentVolume();
|
|
||||||
|
result.insert("brightness", makeSensorInfo("Screen brightness", QVariant::Double, KSysGuard::UnitPercent, 0, 100));
|
||||||
|
result.insert("volume", makeSensorInfo("Master volume", QVariant::Double, KSysGuard::UnitNone));
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QStringList SystemInfoSource::sources() const
|
QVariant SystemInfoSource::fromDBusVariant(const QVariant &_value)
|
||||||
{
|
{
|
||||||
QStringList sources;
|
return _value.value<QDBusVariant>().variant();
|
||||||
sources.append("brightness");
|
|
||||||
sources.append("volume");
|
|
||||||
|
|
||||||
return sources;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QVariant SystemInfoSource::fromDBusVariant(const QVariant &value)
|
|
||||||
{
|
|
||||||
return value.value<QDBusVariant>().variant();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -122,9 +89,8 @@ double SystemInfoSource::getCurrentVolume()
|
|||||||
qCDebug(LOG_ESS) << "Get current volume";
|
qCDebug(LOG_ESS) << "Get current volume";
|
||||||
|
|
||||||
// current device first
|
// current device first
|
||||||
auto currentMixer
|
auto currentMixer = fromDBusVariant(sendDBusRequest("org.kde.kmix", "/Mixers", "org.freedesktop.DBus.Properties",
|
||||||
= fromDBusVariant(sendDBusRequest("org.kde.kmix", "/Mixers", "org.freedesktop.DBus.Properties", "Get",
|
"Get", {"org.kde.KMix.MixSet", "currentMasterMixer"}))
|
||||||
QVariantList({"org.kde.KMix.MixSet", "currentMasterMixer"})))
|
|
||||||
.toString();
|
.toString();
|
||||||
|
|
||||||
if (currentMixer.isEmpty()) {
|
if (currentMixer.isEmpty()) {
|
||||||
@ -134,9 +100,8 @@ double SystemInfoSource::getCurrentVolume()
|
|||||||
currentMixer.replace(":", "_").replace(".", "_").replace("-", "_");
|
currentMixer.replace(":", "_").replace(".", "_").replace("-", "_");
|
||||||
|
|
||||||
// get capture device
|
// get capture device
|
||||||
auto currentControl
|
auto currentControl = fromDBusVariant(sendDBusRequest("org.kde.kmix", "/Mixers", "org.freedesktop.DBus.Properties",
|
||||||
= fromDBusVariant(sendDBusRequest("org.kde.kmix", "/Mixers", "org.freedesktop.DBus.Properties", "Get",
|
"Get", {"org.kde.KMix.MixSet", "currentMasterControl"}))
|
||||||
QVariantList({"org.kde.KMix.MixSet", "currentMasterControl"})))
|
|
||||||
.toString();
|
.toString();
|
||||||
if (currentControl.isEmpty()) {
|
if (currentControl.isEmpty()) {
|
||||||
qCWarning(LOG_ESS) << "Control is empty";
|
qCWarning(LOG_ESS) << "Control is empty";
|
||||||
@ -144,28 +109,28 @@ double SystemInfoSource::getCurrentVolume()
|
|||||||
}
|
}
|
||||||
currentControl.replace(":", "_").replace(".", "_").replace("-", "_");
|
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",
|
return fromDBusVariant(sendDBusRequest("org.kde.kmix", path, "org.freedesktop.DBus.Properties", "Get",
|
||||||
QVariantList({"org.kde.KMix.Control", "volume"})))
|
{"org.kde.KMix.Control", "volume"}))
|
||||||
.toDouble();
|
.toDouble();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QVariant SystemInfoSource::sendDBusRequest(const QString &destination, const QString &path, const QString &interface,
|
QVariant SystemInfoSource::sendDBusRequest(const QString &_destination, const QString &_path, const QString &_interface,
|
||||||
const QString &method, const QVariantList &args)
|
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 bus = QDBusConnection::sessionBus();
|
||||||
auto request = QDBusMessage::createMethodCall(destination, path, interface, method);
|
auto request = QDBusMessage::createMethodCall(_destination, _path, _interface, _method);
|
||||||
if (!args.isEmpty())
|
if (!_args.isEmpty())
|
||||||
request.setArguments(args);
|
request.setArguments(_args);
|
||||||
|
|
||||||
auto response = bus.call(request, QDBus::BlockWithGui, REQUEST_TIMEOUT);
|
auto response = bus.call(request, QDBus::BlockWithGui, REQUEST_TIMEOUT);
|
||||||
|
|
||||||
if ((response.type() != QDBusMessage::ReplyMessage) || (response.arguments().isEmpty())) {
|
if ((response.type() != QDBusMessage::ReplyMessage) || (response.arguments().isEmpty())) {
|
||||||
qCWarning(LOG_ESS) << "Error message" << response.errorMessage();
|
qCWarning(LOG_ESS) << "Error message" << response.errorMessage();
|
||||||
return QVariant();
|
return {};
|
||||||
} else {
|
} else {
|
||||||
return response.arguments().first();
|
return response.arguments().first();
|
||||||
}
|
}
|
||||||
|
@ -27,19 +27,16 @@ class SystemInfoSource : public AbstractExtSysMonSource
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit SystemInfoSource(QObject *_parent, const QStringList &_args);
|
explicit SystemInfoSource(QObject *_parent);
|
||||||
~SystemInfoSource() override;
|
~SystemInfoSource() override = default;
|
||||||
QVariant data(const QString &_source) override;
|
QVariant data(const QString &_source) override;
|
||||||
[[nodiscard]] KSysGuard::SensorInfo *initialData(const QString &_source) const override;
|
[[nodiscard]] QHash<QString, KSysGuard::SensorInfo *> sources() const override;
|
||||||
void run() override;
|
|
||||||
[[nodiscard]] QStringList sources() const override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// configuration and values
|
// configuration and values
|
||||||
QVariantHash m_values;
|
static QVariant fromDBusVariant(const QVariant &_value);
|
||||||
static QVariant fromDBusVariant(const QVariant &value);
|
|
||||||
static double getCurrentBrightness();
|
static double getCurrentBrightness();
|
||||||
static double getCurrentVolume();
|
static double getCurrentVolume();
|
||||||
static QVariant sendDBusRequest(const QString &destination, const QString &path, const QString &interface,
|
static QVariant sendDBusRequest(const QString &_destination, const QString &_path, const QString &_interface,
|
||||||
const QString &method, const QVariantList &args = QVariantList());
|
const QString &_method, const QVariantList &_args = {});
|
||||||
};
|
};
|
||||||
|
@ -17,16 +17,12 @@
|
|||||||
|
|
||||||
#include "timesource.h"
|
#include "timesource.h"
|
||||||
|
|
||||||
#include <ksysguard/formatter/Unit.h>
|
|
||||||
#include <ksysguard/systemstats/SensorInfo.h>
|
|
||||||
|
|
||||||
#include "awdebug.h"
|
#include "awdebug.h"
|
||||||
|
|
||||||
|
|
||||||
TimeSource::TimeSource(QObject *_parent, const QStringList &_args)
|
TimeSource::TimeSource(QObject *_parent)
|
||||||
: AbstractExtSysMonSource(_parent, _args)
|
: AbstractExtSysMonSource(_parent)
|
||||||
{
|
{
|
||||||
Q_ASSERT(_args.count() == 0);
|
|
||||||
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,20 +39,11 @@ QVariant TimeSource::data(const QString &_source)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
KSysGuard::SensorInfo *TimeSource::initialData(const QString &_source) const
|
QHash<QString, KSysGuard::SensorInfo *> TimeSource::sources() const
|
||||||
{
|
{
|
||||||
qCDebug(LOG_ESS) << "Source" << _source;
|
auto result = QHash<QString, KSysGuard::SensorInfo *>();
|
||||||
|
|
||||||
auto data = new KSysGuard::SensorInfo();
|
result.insert("now", makeSensorInfo("Current time", QVariant::LongLong, KSysGuard::UnitSecond));
|
||||||
data->name = "Current time";
|
|
||||||
data->variantType = QVariant::LongLong;
|
|
||||||
data->unit = KSysGuard::UnitSecond;
|
|
||||||
|
|
||||||
return data;
|
return result;
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QStringList TimeSource::sources() const
|
|
||||||
{
|
|
||||||
return QStringList({"now"});
|
|
||||||
}
|
}
|
||||||
|
@ -27,9 +27,8 @@ class TimeSource : public AbstractExtSysMonSource
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit TimeSource(QObject *_parent, const QStringList &_args);
|
explicit TimeSource(QObject *_parent);
|
||||||
|
~TimeSource() override = default;
|
||||||
QVariant data(const QString &_source) override;
|
QVariant data(const QString &_source) override;
|
||||||
[[nodiscard]] KSysGuard::SensorInfo *initialData(const QString &_source) const override;
|
[[nodiscard]] QHash<QString, KSysGuard::SensorInfo *> sources() const override;
|
||||||
void run() override{};
|
|
||||||
[[nodiscard]] QStringList sources() const override;
|
|
||||||
};
|
};
|
||||||
|
@ -15,31 +15,19 @@
|
|||||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#include "upgradesource.h"
|
#include "upgradesource.h"
|
||||||
|
|
||||||
#include <ksysguard/formatter/Unit.h>
|
|
||||||
#include <ksysguard/systemstats/SensorInfo.h>
|
|
||||||
|
|
||||||
#include "awdebug.h"
|
#include "awdebug.h"
|
||||||
#include "extupgrade.h"
|
#include "extupgrade.h"
|
||||||
|
|
||||||
|
|
||||||
UpgradeSource::UpgradeSource(QObject *_parent, const QStringList &_args)
|
UpgradeSource::UpgradeSource(QObject *_parent)
|
||||||
: AbstractExtSysMonSource(_parent, _args)
|
: AbstractExtSysMonSource(_parent)
|
||||||
{
|
{
|
||||||
Q_ASSERT(_args.count() == 0);
|
|
||||||
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
m_extUpgrade = new ExtItemAggregator<ExtUpgrade>(nullptr, "upgrade");
|
m_extUpgrade = new ExtItemAggregator<ExtUpgrade>(nullptr, "upgrade");
|
||||||
m_extUpgrade->initSockets();
|
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;
|
qCDebug(LOG_ESS) << "Source" << _source;
|
||||||
|
|
||||||
// there are only one value
|
// 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<QString, KSysGuard::SensorInfo *> UpgradeSource::sources() const
|
||||||
{
|
{
|
||||||
qCDebug(LOG_ESS) << "Source" << _source;
|
auto result = QHash<QString, KSysGuard::SensorInfo *>();
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QStringList UpgradeSource::sources() const
|
|
||||||
{
|
|
||||||
return m_sources;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QStringList UpgradeSource::getSources()
|
|
||||||
{
|
|
||||||
QStringList sources;
|
|
||||||
for (auto &item : m_extUpgrade->activeItems())
|
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;
|
||||||
}
|
}
|
||||||
|
@ -30,16 +30,12 @@ class UpgradeSource : public AbstractExtSysMonSource
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit UpgradeSource(QObject *_parent, const QStringList &_args);
|
explicit UpgradeSource(QObject *_parent);
|
||||||
~UpgradeSource() override;
|
~UpgradeSource() override = default;
|
||||||
QVariant data(const QString &_source) override;
|
QVariant data(const QString &_source) override;
|
||||||
[[nodiscard]] KSysGuard::SensorInfo *initialData(const QString &_source) const override;
|
[[nodiscard]] QHash<QString, KSysGuard::SensorInfo *> sources() const override;
|
||||||
void run() override{};
|
|
||||||
[[nodiscard]] QStringList sources() const override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QStringList getSources();
|
|
||||||
// configuration and values
|
// configuration and values
|
||||||
ExtItemAggregator<ExtUpgrade> *m_extUpgrade = nullptr;
|
ExtItemAggregator<ExtUpgrade> *m_extUpgrade = nullptr;
|
||||||
QStringList m_sources;
|
|
||||||
};
|
};
|
||||||
|
@ -15,31 +15,19 @@
|
|||||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#include "weathersource.h"
|
#include "weathersource.h"
|
||||||
|
|
||||||
#include <ksysguard/formatter/Unit.h>
|
|
||||||
#include <ksysguard/systemstats/SensorInfo.h>
|
|
||||||
|
|
||||||
#include "awdebug.h"
|
#include "awdebug.h"
|
||||||
#include "extweather.h"
|
#include "extweather.h"
|
||||||
|
|
||||||
|
|
||||||
WeatherSource::WeatherSource(QObject *_parent, const QStringList &_args)
|
WeatherSource::WeatherSource(QObject *_parent)
|
||||||
: AbstractExtSysMonSource(_parent, _args)
|
: AbstractExtSysMonSource(_parent)
|
||||||
{
|
{
|
||||||
Q_ASSERT(_args.count() == 0);
|
|
||||||
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
m_extWeather = new ExtItemAggregator<ExtWeather>(nullptr, "weather");
|
m_extWeather = new ExtItemAggregator<ExtWeather>(nullptr, "weather");
|
||||||
m_extWeather->initSockets();
|
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;
|
qCDebug(LOG_ESS) << "Source" << _source;
|
||||||
|
|
||||||
int ind = index(_source);
|
if (!m_values.contains(_source))
|
||||||
if (!m_values.contains(_source)) {
|
m_values = dataByItem(m_extWeather, _source);
|
||||||
auto data = m_extWeather->itemByTagNumber(ind)->run();
|
|
||||||
m_values.insert(data);
|
|
||||||
}
|
|
||||||
return m_values.take(_source);
|
return m_values.take(_source);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
KSysGuard::SensorInfo *WeatherSource::initialData(const QString &_source) const
|
QHash<QString, KSysGuard::SensorInfo *> WeatherSource::sources() const
|
||||||
{
|
{
|
||||||
qCDebug(LOG_ESS) << "Source" << _source;
|
auto result = QHash<QString, KSysGuard::SensorInfo *>();
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QStringList WeatherSource::sources() const
|
|
||||||
{
|
|
||||||
return m_sources;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QStringList WeatherSource::getSources()
|
|
||||||
{
|
|
||||||
QStringList sources;
|
|
||||||
for (auto &item : m_extWeather->activeItems()) {
|
for (auto &item : m_extWeather->activeItems()) {
|
||||||
sources.append(item->tag("weatherId"));
|
result.insert(item->tag("weatherId"), makeSensorInfo(QString("Numeric weather ID for '%1'").arg(item->uniq()),
|
||||||
sources.append(item->tag("weather"));
|
QVariant::Int, KSysGuard::UnitNone, 0, 1000));
|
||||||
sources.append(item->tag("humidity"));
|
result.insert(item->tag("weather"),
|
||||||
sources.append(item->tag("pressure"));
|
makeSensorInfo(QString("ID string map for '%1'").arg(item->uniq()), QVariant::String));
|
||||||
sources.append(item->tag("temperature"));
|
result.insert(item->tag("humidity"), makeSensorInfo(QString("Humidity for '%1'").arg(item->uniq()),
|
||||||
sources.append(item->tag("timestamp"));
|
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;
|
||||||
}
|
}
|
||||||
|
@ -30,17 +30,13 @@ class WeatherSource : public AbstractExtSysMonSource
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit WeatherSource(QObject *_parent, const QStringList &_args);
|
explicit WeatherSource(QObject *_parent);
|
||||||
~WeatherSource() override;
|
~WeatherSource() override = default;
|
||||||
QVariant data(const QString &_source) override;
|
QVariant data(const QString &_source) override;
|
||||||
[[nodiscard]] KSysGuard::SensorInfo *initialData(const QString &_source) const override;
|
[[nodiscard]] QHash<QString, KSysGuard::SensorInfo *> sources() const override;
|
||||||
void run() override{};
|
|
||||||
[[nodiscard]] QStringList sources() const override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QStringList getSources();
|
|
||||||
// configuration and values
|
// configuration and values
|
||||||
ExtItemAggregator<ExtWeather> *m_extWeather = nullptr;
|
ExtItemAggregator<ExtWeather> *m_extWeather = nullptr;
|
||||||
QStringList m_sources;
|
|
||||||
QVariantHash m_values;
|
QVariantHash m_values;
|
||||||
};
|
};
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#include "testabstractextitem.h"
|
#include "testabstractextitem.h"
|
||||||
|
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
@ -75,7 +74,7 @@ void TestAbstractExtItem::test_configuration()
|
|||||||
{
|
{
|
||||||
extItem->writeConfiguration();
|
extItem->writeConfiguration();
|
||||||
|
|
||||||
ExtUpgrade *newExtItem = new ExtUpgrade(nullptr, writeFileName);
|
auto newExtItem = new ExtUpgrade(nullptr, writeFileName);
|
||||||
QCOMPARE(newExtItem->isActive(), extItem->isActive());
|
QCOMPARE(newExtItem->isActive(), extItem->isActive());
|
||||||
QCOMPARE(newExtItem->comment(), extItem->comment());
|
QCOMPARE(newExtItem->comment(), extItem->comment());
|
||||||
QCOMPARE(newExtItem->fileName(), writeFileName);
|
QCOMPARE(newExtItem->fileName(), writeFileName);
|
||||||
@ -98,7 +97,7 @@ void TestAbstractExtItem::test_bumpApi()
|
|||||||
|
|
||||||
void TestAbstractExtItem::test_delete()
|
void TestAbstractExtItem::test_delete()
|
||||||
{
|
{
|
||||||
ExtUpgrade *newExtItem = new ExtUpgrade(nullptr, writeFileName);
|
auto newExtItem = new ExtUpgrade(nullptr, writeFileName);
|
||||||
|
|
||||||
QVERIFY(newExtItem->tryDelete());
|
QVERIFY(newExtItem->tryDelete());
|
||||||
QVERIFY(!QFile::exists(writeFileName));
|
QVERIFY(!QFile::exists(writeFileName));
|
||||||
@ -109,7 +108,7 @@ void TestAbstractExtItem::test_delete()
|
|||||||
|
|
||||||
void TestAbstractExtItem::test_copy()
|
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->isActive(), extItem->isActive());
|
||||||
QCOMPARE(newExtItem->apiVersion(), extItem->apiVersion());
|
QCOMPARE(newExtItem->apiVersion(), extItem->apiVersion());
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#include "testabstractformatter.h"
|
#include "testabstractformatter.h"
|
||||||
|
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
@ -42,7 +41,7 @@ void TestAbstractFormatter::test_values() {}
|
|||||||
|
|
||||||
void TestAbstractFormatter::test_type()
|
void TestAbstractFormatter::test_type()
|
||||||
{
|
{
|
||||||
QString type = AWTestLibrary::randomString();
|
auto type = AWTestLibrary::randomString();
|
||||||
QEXPECT_FAIL("", "Will fail because of invalid format", Continue);
|
QEXPECT_FAIL("", "Will fail because of invalid format", Continue);
|
||||||
formatter->setStrType(type);
|
formatter->setStrType(type);
|
||||||
QCOMPARE(formatter->strType(), type);
|
QCOMPARE(formatter->strType(), type);
|
||||||
@ -54,7 +53,7 @@ void TestAbstractFormatter::test_type()
|
|||||||
|
|
||||||
void TestAbstractFormatter::test_copy()
|
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->type(), formatter->type());
|
||||||
QCOMPARE(newFormatter->name(), formatter->name());
|
QCOMPARE(newFormatter->name(), formatter->name());
|
||||||
|
@ -40,7 +40,7 @@ void TestAWBugReporter::cleanupTestCase()
|
|||||||
void TestAWBugReporter::test_generateText()
|
void TestAWBugReporter::test_generateText()
|
||||||
{
|
{
|
||||||
data = AWTestLibrary::randomStringList(4);
|
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)
|
for (auto &string : data)
|
||||||
QVERIFY(output.contains(string));
|
QVERIFY(output.contains(string));
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#include "testawconfighelper.h"
|
#include "testawconfighelper.h"
|
||||||
|
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
@ -45,7 +44,7 @@ void TestAWConfigHelper::test_configurationDirectory()
|
|||||||
|
|
||||||
void TestAWConfigHelper::test_exportConfiguration()
|
void TestAWConfigHelper::test_exportConfiguration()
|
||||||
{
|
{
|
||||||
QStringList keys = AWTestLibrary::randomStringList();
|
auto keys = AWTestLibrary::randomStringList();
|
||||||
for (auto &key : keys)
|
for (auto &key : keys)
|
||||||
map[key] = AWTestLibrary::randomString();
|
map[key] = AWTestLibrary::randomString();
|
||||||
filename = AWTestLibrary::randomFilenames().first;
|
filename = AWTestLibrary::randomFilenames().first;
|
||||||
@ -56,7 +55,7 @@ void TestAWConfigHelper::test_exportConfiguration()
|
|||||||
|
|
||||||
void TestAWConfigHelper::test_importConfiguration()
|
void TestAWConfigHelper::test_importConfiguration()
|
||||||
{
|
{
|
||||||
QVariantMap imported = plugin->importConfiguration(filename, true, true, true);
|
auto imported = plugin->importConfiguration(filename, true, true, true);
|
||||||
QVariantMap converted;
|
QVariantMap converted;
|
||||||
for (auto &key : map.keys())
|
for (auto &key : map.keys())
|
||||||
converted[key] = map.value(key);
|
converted[key] = map.value(key);
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#include "testawkeycache.h"
|
#include "testawkeycache.h"
|
||||||
|
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#include "testawkeys.h"
|
#include "testawkeys.h"
|
||||||
|
|
||||||
#include <QDBusConnection>
|
#include <QDBusConnection>
|
||||||
@ -82,10 +81,10 @@ void TestAWKeys::test_hddDevices()
|
|||||||
|
|
||||||
void TestAWKeys::test_dictKeys()
|
void TestAWKeys::test_dictKeys()
|
||||||
{
|
{
|
||||||
QStringList keys = plugin->dictKeys();
|
auto keys = plugin->dictKeys();
|
||||||
QVERIFY(!keys.isEmpty());
|
QVERIFY(!keys.isEmpty());
|
||||||
|
|
||||||
QStringList sorted = plugin->dictKeys(true);
|
auto sorted = plugin->dictKeys(true);
|
||||||
QVERIFY(!sorted.isEmpty());
|
QVERIFY(!sorted.isEmpty());
|
||||||
QEXPECT_FAIL("", "Sorted and non-sorted lists should differ", Continue);
|
QEXPECT_FAIL("", "Sorted and non-sorted lists should differ", Continue);
|
||||||
QCOMPARE(keys, sorted);
|
QCOMPARE(keys, sorted);
|
||||||
@ -101,11 +100,11 @@ void TestAWKeys::test_pattern()
|
|||||||
|
|
||||||
QVERIFY(spy.wait(5 * interval));
|
QVERIFY(spy.wait(5 * interval));
|
||||||
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);
|
QEXPECT_FAIL("", "Pattern should be parsed", Continue);
|
||||||
QCOMPARE(text, pattern);
|
QCOMPARE(text, pattern);
|
||||||
QStringList keys = plugin->dictKeys(true);
|
auto keys = plugin->dictKeys(true);
|
||||||
for (auto &key : keys)
|
for (auto &key : keys)
|
||||||
QVERIFY(!text.contains(key));
|
QVERIFY(!text.contains(key));
|
||||||
}
|
}
|
||||||
@ -119,7 +118,7 @@ void TestAWKeys::test_tooltip()
|
|||||||
QSignalSpy spy(plugin, SIGNAL(needToolTipToBeUpdated(const QString)));
|
QSignalSpy spy(plugin, SIGNAL(needToolTipToBeUpdated(const QString)));
|
||||||
|
|
||||||
QVERIFY(spy.wait(5 * interval));
|
QVERIFY(spy.wait(5 * interval));
|
||||||
QString text = spy.takeFirst().at(0).toString();
|
auto text = spy.takeFirst().at(0).toString();
|
||||||
QVERIFY(text.startsWith("<img"));
|
QVERIFY(text.startsWith("<img"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,7 +128,7 @@ void TestAWKeys::test_wrapNewLines()
|
|||||||
QSignalSpy spy(plugin, SIGNAL(needTextToBeUpdated(const QString)));
|
QSignalSpy spy(plugin, SIGNAL(needTextToBeUpdated(const QString)));
|
||||||
|
|
||||||
QVERIFY(spy.wait(5 * interval));
|
QVERIFY(spy.wait(5 * interval));
|
||||||
QString text = spy.takeFirst().at(0).toString();
|
auto text = spy.takeFirst().at(0).toString();
|
||||||
QVERIFY(!text.contains("<br>") && text.contains("\n"));
|
QVERIFY(!text.contains("<br>") && text.contains("\n"));
|
||||||
|
|
||||||
plugin->setWrapNewLines(true);
|
plugin->setWrapNewLines(true);
|
||||||
@ -141,10 +140,10 @@ void TestAWKeys::test_wrapNewLines()
|
|||||||
|
|
||||||
void TestAWKeys::test_infoByKey()
|
void TestAWKeys::test_infoByKey()
|
||||||
{
|
{
|
||||||
int notEmpty = 0;
|
auto notEmpty = 0;
|
||||||
QStringList keys = plugin->dictKeys(true);
|
auto keys = plugin->dictKeys(true);
|
||||||
for (auto &key : keys) {
|
for (auto &key : keys) {
|
||||||
QString info = plugin->infoByKey(key);
|
auto info = plugin->infoByKey(key);
|
||||||
QVERIFY(!info.isEmpty());
|
QVERIFY(!info.isEmpty());
|
||||||
// append non-empty field count
|
// append non-empty field count
|
||||||
if (info != "(none)")
|
if (info != "(none)")
|
||||||
@ -156,8 +155,8 @@ void TestAWKeys::test_infoByKey()
|
|||||||
|
|
||||||
void TestAWKeys::test_valueByKey()
|
void TestAWKeys::test_valueByKey()
|
||||||
{
|
{
|
||||||
int notEmpty = 0;
|
auto notEmpty = 0;
|
||||||
QStringList keys = plugin->dictKeys(true);
|
auto keys = plugin->dictKeys(true);
|
||||||
for (auto &key : keys) {
|
for (auto &key : keys) {
|
||||||
if (!plugin->valueByKey(key).isEmpty())
|
if (!plugin->valueByKey(key).isEmpty())
|
||||||
notEmpty++;
|
notEmpty++;
|
||||||
@ -169,26 +168,25 @@ void TestAWKeys::test_valueByKey()
|
|||||||
void TestAWKeys::test_dbus()
|
void TestAWKeys::test_dbus()
|
||||||
{
|
{
|
||||||
// get id
|
// get id
|
||||||
qlonglong id = reinterpret_cast<qlonglong>(plugin);
|
auto id = reinterpret_cast<qlonglong>(plugin);
|
||||||
|
|
||||||
// create connection and message
|
// create connection and message
|
||||||
QDBusConnection bus = QDBusConnection::sessionBus();
|
auto bus = QDBusConnection::sessionBus();
|
||||||
|
|
||||||
// check if there is active sessions first
|
// check if there is active sessions first
|
||||||
QDBusMessage sessions
|
auto sessions = QDBusMessage::createMethodCall(AWDBUS_SERVICE, AWDBUS_PATH, AWDBUS_SERVICE, "ActiveServices");
|
||||||
= QDBusMessage::createMethodCall(AWDBUS_SERVICE, AWDBUS_PATH, AWDBUS_SERVICE, "ActiveServices");
|
auto sessionsResponse = bus.call(sessions, QDBus::BlockWithGui);
|
||||||
QDBusMessage sessionsResponse = bus.call(sessions, QDBus::BlockWithGui);
|
|
||||||
if (sessionsResponse.arguments().isEmpty())
|
if (sessionsResponse.arguments().isEmpty())
|
||||||
QSKIP("No active sessions found, skip DBus tests");
|
QSKIP("No active sessions found, skip DBus tests");
|
||||||
|
|
||||||
// dbus checks
|
// dbus checks
|
||||||
QDBusMessage request = QDBusMessage::createMethodCall(QString("%1.i%2").arg(AWDBUS_SERVICE).arg(id), AWDBUS_PATH,
|
auto request = QDBusMessage::createMethodCall(QString("%1.i%2").arg(AWDBUS_SERVICE).arg(id), AWDBUS_PATH,
|
||||||
AWDBUS_SERVICE, "WhoAmI");
|
AWDBUS_SERVICE, "WhoAmI");
|
||||||
// send message to dbus
|
// send message to dbus
|
||||||
QDBusMessage response = bus.call(request, QDBus::BlockWithGui);
|
auto response = bus.call(request, QDBus::BlockWithGui);
|
||||||
|
|
||||||
// parse result
|
// parse result
|
||||||
QList<QVariant> arguments = response.arguments();
|
auto arguments = response.arguments();
|
||||||
QVERIFY(!arguments.isEmpty());
|
QVERIFY(!arguments.isEmpty());
|
||||||
QCOMPARE(arguments.at(0).toLongLong(), id);
|
QCOMPARE(arguments.at(0).toLongLong(), id);
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#include "testawpatternfunctions.h"
|
#include "testawpatternfunctions.h"
|
||||||
|
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
@ -36,12 +35,12 @@ void TestAWPatternFunctions::cleanupTestCase() {}
|
|||||||
|
|
||||||
void TestAWPatternFunctions::test_findFunctionCalls()
|
void TestAWPatternFunctions::test_findFunctionCalls()
|
||||||
{
|
{
|
||||||
QString name = QString("aw_%1").arg(AWTestLibrary::randomString(1, 10));
|
auto name = QString("aw_%1").arg(AWTestLibrary::randomString(1, 10));
|
||||||
QString code = AWTestLibrary::randomString(1, 20);
|
auto code = AWTestLibrary::randomString(1, 20);
|
||||||
QStringList args = AWTestLibrary::randomStringList(20);
|
auto args = AWTestLibrary::randomStringList(20);
|
||||||
QString function = QString("$%1<%2>{{%3}}").arg(name).arg(args.join(',')).arg(code);
|
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<AWPatternFunctions::AWFunction> found = AWPatternFunctions::findFunctionCalls(name, pattern);
|
QList<AWPatternFunctions::AWFunction> found = AWPatternFunctions::findFunctionCalls(name, pattern);
|
||||||
QCOMPARE(found.count(), 1);
|
QCOMPARE(found.count(), 1);
|
||||||
@ -54,9 +53,9 @@ void TestAWPatternFunctions::test_findFunctionCalls()
|
|||||||
|
|
||||||
void TestAWPatternFunctions::test_findKeys()
|
void TestAWPatternFunctions::test_findKeys()
|
||||||
{
|
{
|
||||||
int count = AWTestLibrary::randomInt(200);
|
auto count = AWTestLibrary::randomInt(200);
|
||||||
QStringList allKeys;
|
QStringList allKeys;
|
||||||
for (int i = 0; i < count; i++) {
|
for (auto i = 0; i < count; i++) {
|
||||||
auto key = AWTestLibrary::randomString(1, 20);
|
auto key = AWTestLibrary::randomString(1, 20);
|
||||||
while (allKeys.indexOf(QRegularExpression(QString("^%1.*").arg(key))) != -1)
|
while (allKeys.indexOf(QRegularExpression(QString("^%1.*").arg(key))) != -1)
|
||||||
key = AWTestLibrary::randomString(1, 20);
|
key = AWTestLibrary::randomString(1, 20);
|
||||||
@ -65,8 +64,8 @@ void TestAWPatternFunctions::test_findKeys()
|
|||||||
|
|
||||||
auto keys = AWTestLibrary::randomSelect(allKeys);
|
auto keys = AWTestLibrary::randomSelect(allKeys);
|
||||||
auto bars = AWTestLibrary::randomSelect(allKeys);
|
auto bars = AWTestLibrary::randomSelect(allKeys);
|
||||||
std::for_each(bars.begin(), bars.end(), [](QString &bar) { bar.prepend("bar"); });
|
std::for_each(bars.begin(), bars.end(), [](auto &bar) { bar.prepend("bar"); });
|
||||||
QString pattern = QString("$%1 $%2").arg(keys.join(" $")).arg(bars.join(" $"));
|
auto pattern = QString("$%1 $%2").arg(keys.join(" $")).arg(bars.join(" $"));
|
||||||
|
|
||||||
allKeys.append(bars);
|
allKeys.append(bars);
|
||||||
allKeys.sort();
|
allKeys.sort();
|
||||||
@ -74,9 +73,9 @@ void TestAWPatternFunctions::test_findKeys()
|
|||||||
keys.sort();
|
keys.sort();
|
||||||
bars.sort();
|
bars.sort();
|
||||||
|
|
||||||
QStringList foundKeys = AWPatternFunctions::findKeys(pattern, allKeys, false);
|
auto foundKeys = AWPatternFunctions::findKeys(pattern, allKeys, false);
|
||||||
foundKeys.sort();
|
foundKeys.sort();
|
||||||
QStringList foundBars = AWPatternFunctions::findKeys(pattern, allKeys, true);
|
auto foundBars = AWPatternFunctions::findKeys(pattern, allKeys, true);
|
||||||
foundBars.sort();
|
foundBars.sort();
|
||||||
|
|
||||||
QCOMPARE(foundKeys, keys);
|
QCOMPARE(foundKeys, keys);
|
||||||
@ -86,8 +85,8 @@ void TestAWPatternFunctions::test_findKeys()
|
|||||||
|
|
||||||
void TestAWPatternFunctions::test_findLambdas()
|
void TestAWPatternFunctions::test_findLambdas()
|
||||||
{
|
{
|
||||||
QStringList lambdas = AWTestLibrary::randomStringList(20);
|
auto lambdas = AWTestLibrary::randomStringList(20);
|
||||||
QString pattern
|
auto pattern
|
||||||
= AWTestLibrary::randomString() + QString("${{%1}}").arg(lambdas.join("}}${{")) + AWTestLibrary::randomString();
|
= AWTestLibrary::randomString() + QString("${{%1}}").arg(lambdas.join("}}${{")) + AWTestLibrary::randomString();
|
||||||
|
|
||||||
QCOMPARE(AWPatternFunctions::findLambdas(pattern), lambdas);
|
QCOMPARE(AWPatternFunctions::findLambdas(pattern), lambdas);
|
||||||
@ -96,12 +95,12 @@ void TestAWPatternFunctions::test_findLambdas()
|
|||||||
|
|
||||||
void TestAWPatternFunctions::test_expandTemplates()
|
void TestAWPatternFunctions::test_expandTemplates()
|
||||||
{
|
{
|
||||||
int firstValue = AWTestLibrary::randomInt();
|
auto firstValue = AWTestLibrary::randomInt();
|
||||||
int secondValue = AWTestLibrary::randomInt();
|
auto secondValue = AWTestLibrary::randomInt();
|
||||||
int result = firstValue + secondValue;
|
auto result = firstValue + secondValue;
|
||||||
QString code = QString("$template{{%1+%2}}").arg(firstValue).arg(secondValue);
|
auto code = QString("$template{{%1+%2}}").arg(firstValue).arg(secondValue);
|
||||||
QString prefix = AWTestLibrary::randomString();
|
auto prefix = AWTestLibrary::randomString();
|
||||||
QString pattern = prefix + code;
|
auto pattern = prefix + code;
|
||||||
|
|
||||||
QCOMPARE(AWPatternFunctions::expandTemplates(pattern), QString("%1%2").arg(prefix).arg(result));
|
QCOMPARE(AWPatternFunctions::expandTemplates(pattern), QString("%1%2").arg(prefix).arg(result));
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#include "testawtelemetryhandler.h"
|
#include "testawtelemetryhandler.h"
|
||||||
|
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
@ -48,7 +47,7 @@ void TestAWTelemetryHandler::test_put()
|
|||||||
|
|
||||||
void TestAWTelemetryHandler::test_get()
|
void TestAWTelemetryHandler::test_get()
|
||||||
{
|
{
|
||||||
QStringList output = plugin->get(telemetryGroup);
|
auto output = plugin->get(telemetryGroup);
|
||||||
|
|
||||||
QVERIFY(!output.isEmpty());
|
QVERIFY(!output.isEmpty());
|
||||||
QCOMPARE(QSet<QString>(output.cbegin(), output.cend()).count(), output.count());
|
QCOMPARE(QSet<QString>(output.cbegin(), output.cend()).count(), output.count());
|
||||||
@ -70,7 +69,7 @@ void TestAWTelemetryHandler::test_uploadTelemetry()
|
|||||||
plugin->uploadTelemetry(telemetryValidGroup, telemetryData);
|
plugin->uploadTelemetry(telemetryValidGroup, telemetryData);
|
||||||
|
|
||||||
QVERIFY(spy.wait(5000));
|
QVERIFY(spy.wait(5000));
|
||||||
QVariantList arguments = spy.takeFirst();
|
auto arguments = spy.takeFirst();
|
||||||
|
|
||||||
QCOMPARE(arguments.at(0).toString(), telemetryStatus);
|
QCOMPARE(arguments.at(0).toString(), telemetryStatus);
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#include "testawupdatehelper.h"
|
#include "testawupdatehelper.h"
|
||||||
|
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#include "testbatterysource.h"
|
#include "testbatterysource.h"
|
||||||
|
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
@ -29,7 +28,7 @@
|
|||||||
void TestBatterySource::initTestCase()
|
void TestBatterySource::initTestCase()
|
||||||
{
|
{
|
||||||
AWTestLibrary::init();
|
AWTestLibrary::init();
|
||||||
source = new BatterySource(this, QStringList() << acpiPath);
|
source = new BatterySource(this, acpiPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -41,8 +40,7 @@ void TestBatterySource::cleanupTestCase()
|
|||||||
|
|
||||||
void TestBatterySource::test_sources()
|
void TestBatterySource::test_sources()
|
||||||
{
|
{
|
||||||
//
|
QVERIFY(source->sources().count() >= 6);
|
||||||
QVERIFY(source->sources().length() >= 6);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -51,9 +49,9 @@ void TestBatterySource::test_battery()
|
|||||||
if (source->sources().count() == 6)
|
if (source->sources().count() == 6)
|
||||||
QSKIP("No battery found, test will be skipped");
|
QSKIP("No battery found, test will be skipped");
|
||||||
|
|
||||||
QStringList batteries = source->sources();
|
auto batteries = source->sources().keys();
|
||||||
std::for_each(batteries.begin(), batteries.end(), [this](const QString &bat) {
|
std::for_each(batteries.cbegin(), batteries.cend(), [this](auto bat) {
|
||||||
QVariant value = source->data(bat);
|
auto value = source->data(bat);
|
||||||
if (bat == "ac")
|
if (bat == "ac")
|
||||||
QCOMPARE(value.type(), QVariant::Bool);
|
QCOMPARE(value.type(), QVariant::Bool);
|
||||||
else if (bat.startsWith("batrate") || bat.startsWith("batleft"))
|
else if (bat.startsWith("batrate") || bat.startsWith("batleft"))
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#include "testdatetimeformatter.h"
|
#include "testdatetimeformatter.h"
|
||||||
|
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
@ -57,7 +56,7 @@ void TestAWDateTimeFormatter::test_conversion()
|
|||||||
void TestAWDateTimeFormatter::test_copy()
|
void TestAWDateTimeFormatter::test_copy()
|
||||||
{
|
{
|
||||||
formatter->setTranslateString(false);
|
formatter->setTranslateString(false);
|
||||||
auto *newFormatter = formatter->copy("/dev/null", 1);
|
auto newFormatter = formatter->copy("/dev/null", 1);
|
||||||
|
|
||||||
QCOMPARE(newFormatter->format(), formatter->format());
|
QCOMPARE(newFormatter->format(), formatter->format());
|
||||||
QCOMPARE(newFormatter->translateString(), formatter->translateString());
|
QCOMPARE(newFormatter->translateString(), formatter->translateString());
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#include "testdesktopsource.h"
|
#include "testdesktopsource.h"
|
||||||
|
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
@ -27,7 +26,8 @@
|
|||||||
void TestDesktopSource::initTestCase()
|
void TestDesktopSource::initTestCase()
|
||||||
{
|
{
|
||||||
AWTestLibrary::init();
|
AWTestLibrary::init();
|
||||||
source = new DesktopSource(this, QStringList());
|
source = new DesktopSource(this);
|
||||||
|
m_isKwinActive = AWTestLibrary::isKWinActive();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -39,18 +39,18 @@ void TestDesktopSource::cleanupTestCase()
|
|||||||
|
|
||||||
void TestDesktopSource::test_sources()
|
void TestDesktopSource::test_sources()
|
||||||
{
|
{
|
||||||
QCOMPARE(source->sources().count(), 4);
|
QCOMPARE(source->sources().count(), 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void TestDesktopSource::test_values()
|
void TestDesktopSource::test_values()
|
||||||
{
|
{
|
||||||
QSKIP("Tests are failing with current api");
|
if (!m_isKwinActive)
|
||||||
|
QSKIP("KWin inactive, skip desktop tests");
|
||||||
|
|
||||||
QVERIFY(source->data("desktop/current/name").toString().length() > 0);
|
QVERIFY(source->data("name").toString().length() > 0);
|
||||||
QVERIFY(source->data("desktop/current/number").toInt() >= 0);
|
QVERIFY(source->data("number").toInt() >= 0);
|
||||||
QVERIFY(source->data("desktop/total/name").toStringList().count() > 0);
|
QVERIFY(source->data("count").toInt() > 0);
|
||||||
QVERIFY(source->data("desktop/total/number").toInt() > 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -36,4 +36,5 @@ private slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
DesktopSource *source = nullptr;
|
DesktopSource *source = nullptr;
|
||||||
|
bool m_isKwinActive = false;
|
||||||
};
|
};
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#include "testdpplugin.h"
|
#include "testdpplugin.h"
|
||||||
|
|
||||||
#include <KWindowSystem>
|
#include <KWindowSystem>
|
||||||
@ -44,8 +43,8 @@ void TestDPPlugin::test_desktops()
|
|||||||
if (!m_isKwinActive)
|
if (!m_isKwinActive)
|
||||||
QSKIP("KWin inactive, skip Destkop panel tests");
|
QSKIP("KWin inactive, skip Destkop panel tests");
|
||||||
|
|
||||||
int current = plugin->currentDesktop();
|
auto current = plugin->currentDesktop();
|
||||||
int total = plugin->numberOfDesktops();
|
auto total = plugin->numberOfDesktops();
|
||||||
QVERIFY(total != 0);
|
QVERIFY(total != 0);
|
||||||
QVERIFY(current <= total);
|
QVERIFY(current <= total);
|
||||||
|
|
||||||
@ -90,7 +89,7 @@ void TestDPPlugin::test_parsePattern()
|
|||||||
if (!m_isKwinActive)
|
if (!m_isKwinActive)
|
||||||
QSKIP("KWin inactive, skip Destkop panel tests");
|
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.isEmpty());
|
||||||
QVERIFY(result != pattern);
|
QVERIFY(result != pattern);
|
||||||
for (auto &key : plugin->dictKeys())
|
for (auto &key : plugin->dictKeys())
|
||||||
@ -109,7 +108,7 @@ void TestDPPlugin::test_tooltipImage()
|
|||||||
data["tooltipWidth"] = 300;
|
data["tooltipWidth"] = 300;
|
||||||
plugin->setToolTipData(data);
|
plugin->setToolTipData(data);
|
||||||
|
|
||||||
QString image = plugin->toolTipImage(plugin->currentDesktop());
|
auto image = plugin->toolTipImage(plugin->currentDesktop());
|
||||||
QVERIFY(image.startsWith("<img src=\""));
|
QVERIFY(image.startsWith("<img src=\""));
|
||||||
QVERIFY(image.endsWith("\"/>"));
|
QVERIFY(image.endsWith("\"/>"));
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#include "testextitemaggregator.h"
|
#include "testextitemaggregator.h"
|
||||||
|
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#include "testextquotes.h"
|
#include "testextquotes.h"
|
||||||
|
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
@ -54,11 +53,11 @@ void TestExtQuotes::test_run()
|
|||||||
{
|
{
|
||||||
// init spy
|
// init spy
|
||||||
QSignalSpy spy(extQuotes, SIGNAL(dataReceived(const QVariantHash &)));
|
QSignalSpy spy(extQuotes, SIGNAL(dataReceived(const QVariantHash &)));
|
||||||
QVariantHash firstValue = extQuotes->run();
|
auto firstValue = extQuotes->run();
|
||||||
|
|
||||||
// check values
|
// check values
|
||||||
QVERIFY(spy.wait(5000));
|
QVERIFY(spy.wait(5000));
|
||||||
QList<QVariant> arguments = spy.takeFirst();
|
auto arguments = spy.takeFirst();
|
||||||
for (auto &type : types)
|
for (auto &type : types)
|
||||||
cache[type] = arguments.at(0).toHash()[extQuotes->tag(type)];
|
cache[type] = arguments.at(0).toHash()[extQuotes->tag(type)];
|
||||||
|
|
||||||
@ -73,11 +72,11 @@ void TestExtQuotes::test_derivatives()
|
|||||||
{
|
{
|
||||||
// init spy
|
// init spy
|
||||||
QSignalSpy spy(extQuotes, SIGNAL(dataReceived(const QVariantHash &)));
|
QSignalSpy spy(extQuotes, SIGNAL(dataReceived(const QVariantHash &)));
|
||||||
QVariantHash firstValue = extQuotes->run();
|
auto firstValue = extQuotes->run();
|
||||||
|
|
||||||
// check values
|
// check values
|
||||||
QVERIFY(spy.wait(5000));
|
QVERIFY(spy.wait(5000));
|
||||||
QList<QVariant> arguments = spy.takeFirst();
|
auto arguments = spy.takeFirst();
|
||||||
QVariantHash values;
|
QVariantHash values;
|
||||||
for (auto &type : types)
|
for (auto &type : types)
|
||||||
values[type] = arguments.at(0).toHash()[extQuotes->tag(type)];
|
values[type] = arguments.at(0).toHash()[extQuotes->tag(type)];
|
||||||
@ -91,7 +90,7 @@ void TestExtQuotes::test_derivatives()
|
|||||||
|
|
||||||
void TestExtQuotes::test_copy()
|
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->interval(), extQuotes->interval());
|
||||||
QCOMPARE(newExtQuotes->ticker(), extQuotes->ticker());
|
QCOMPARE(newExtQuotes->ticker(), extQuotes->ticker());
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#include "testextscript.h"
|
#include "testextscript.h"
|
||||||
|
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
@ -58,11 +57,11 @@ void TestExtScript::test_run()
|
|||||||
{
|
{
|
||||||
// init spy
|
// init spy
|
||||||
QSignalSpy spy(extScript, SIGNAL(dataReceived(const QVariantHash &)));
|
QSignalSpy spy(extScript, SIGNAL(dataReceived(const QVariantHash &)));
|
||||||
QVariantHash firstValue = extScript->run();
|
auto firstValue = extScript->run();
|
||||||
|
|
||||||
// check values
|
// check values
|
||||||
QVERIFY(spy.wait(5000));
|
QVERIFY(spy.wait(5000));
|
||||||
QList<QVariant> arguments = spy.takeFirst();
|
auto arguments = spy.takeFirst();
|
||||||
|
|
||||||
QCOMPARE(firstValue[extScript->tag("custom")].toString(), QString());
|
QCOMPARE(firstValue[extScript->tag("custom")].toString(), QString());
|
||||||
QCOMPARE(arguments.at(0).toHash()[extScript->tag("custom")].toString(), QString("\n%1").arg(randomString));
|
QCOMPARE(arguments.at(0).toHash()[extScript->tag("custom")].toString(), QString("\n%1").arg(randomString));
|
||||||
@ -81,14 +80,14 @@ void TestExtScript::test_filters()
|
|||||||
|
|
||||||
// check values
|
// check values
|
||||||
QVERIFY(spy.wait(5000));
|
QVERIFY(spy.wait(5000));
|
||||||
QList<QVariant> arguments = spy.takeFirst();
|
auto arguments = spy.takeFirst();
|
||||||
QCOMPARE(arguments.at(0).toHash()[extScript->tag("custom")].toString(), QString("<br>%1").arg(randomString));
|
QCOMPARE(arguments.at(0).toHash()[extScript->tag("custom")].toString(), QString("<br>%1").arg(randomString));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void TestExtScript::test_copy()
|
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->interval(), extScript->interval());
|
||||||
QCOMPARE(newExtScript->executable(), extScript->executable());
|
QCOMPARE(newExtScript->executable(), extScript->executable());
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#include "testextupgrade.h"
|
#include "testextupgrade.h"
|
||||||
|
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
@ -57,11 +56,11 @@ void TestExtUpgrade::test_run()
|
|||||||
{
|
{
|
||||||
// init spy
|
// init spy
|
||||||
QSignalSpy spy(extUpgrade, SIGNAL(dataReceived(const QVariantHash &)));
|
QSignalSpy spy(extUpgrade, SIGNAL(dataReceived(const QVariantHash &)));
|
||||||
QVariantHash firstValue = extUpgrade->run();
|
auto firstValue = extUpgrade->run();
|
||||||
|
|
||||||
// check values
|
// check values
|
||||||
QVERIFY(spy.wait(5000));
|
QVERIFY(spy.wait(5000));
|
||||||
QList<QVariant> arguments = spy.takeFirst();
|
auto arguments = spy.takeFirst();
|
||||||
|
|
||||||
QCOMPARE(firstValue[extUpgrade->tag("pkgcount")].toInt(), 0);
|
QCOMPARE(firstValue[extUpgrade->tag("pkgcount")].toInt(), 0);
|
||||||
QCOMPARE(arguments.at(0).toHash()[extUpgrade->tag("pkgcount")].toInt(), randomStrings.count());
|
QCOMPARE(arguments.at(0).toHash()[extUpgrade->tag("pkgcount")].toInt(), randomStrings.count());
|
||||||
@ -70,21 +69,21 @@ void TestExtUpgrade::test_run()
|
|||||||
|
|
||||||
void TestExtUpgrade::test_null()
|
void TestExtUpgrade::test_null()
|
||||||
{
|
{
|
||||||
int null = AWTestLibrary::randomInt(randomStrings.count());
|
auto null = AWTestLibrary::randomInt(randomStrings.count());
|
||||||
extUpgrade->setNull(null);
|
extUpgrade->setNull(null);
|
||||||
QSignalSpy spy(extUpgrade, SIGNAL(dataReceived(const QVariantHash &)));
|
QSignalSpy spy(extUpgrade, SIGNAL(dataReceived(const QVariantHash &)));
|
||||||
extUpgrade->run();
|
extUpgrade->run();
|
||||||
|
|
||||||
// check values
|
// check values
|
||||||
QVERIFY(spy.wait(5000));
|
QVERIFY(spy.wait(5000));
|
||||||
QList<QVariant> arguments = spy.takeFirst();
|
auto arguments = spy.takeFirst();
|
||||||
QCOMPARE(arguments.at(0).toHash()[extUpgrade->tag("pkgcount")].toInt(), randomStrings.count() - null);
|
QCOMPARE(arguments.at(0).toHash()[extUpgrade->tag("pkgcount")].toInt(), randomStrings.count() - null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void TestExtUpgrade::test_filter()
|
void TestExtUpgrade::test_filter()
|
||||||
{
|
{
|
||||||
QStringList filters = AWTestLibrary::randomSelect(randomStrings);
|
auto filters = AWTestLibrary::randomSelect(randomStrings);
|
||||||
extUpgrade->setFilter(QString("(^%1$)").arg(filters.join("$|^")));
|
extUpgrade->setFilter(QString("(^%1$)").arg(filters.join("$|^")));
|
||||||
// init spy
|
// init spy
|
||||||
QSignalSpy spy(extUpgrade, SIGNAL(dataReceived(const QVariantHash &)));
|
QSignalSpy spy(extUpgrade, SIGNAL(dataReceived(const QVariantHash &)));
|
||||||
@ -92,14 +91,14 @@ void TestExtUpgrade::test_filter()
|
|||||||
|
|
||||||
// check values
|
// check values
|
||||||
QVERIFY(spy.wait(5000));
|
QVERIFY(spy.wait(5000));
|
||||||
QList<QVariant> arguments = spy.takeFirst();
|
auto arguments = spy.takeFirst();
|
||||||
QCOMPARE(arguments.at(0).toHash()[extUpgrade->tag("pkgcount")].toInt(), filters.count());
|
QCOMPARE(arguments.at(0).toHash()[extUpgrade->tag("pkgcount")].toInt(), filters.count());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void TestExtUpgrade::test_copy()
|
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->interval(), extUpgrade->interval());
|
||||||
QCOMPARE(newExtUpgrade->executable(), extUpgrade->executable());
|
QCOMPARE(newExtUpgrade->executable(), extUpgrade->executable());
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#include "testextweather.h"
|
#include "testextweather.h"
|
||||||
|
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
@ -75,18 +74,18 @@ void TestExtWeather::test_image()
|
|||||||
extWeather->setImage(true);
|
extWeather->setImage(true);
|
||||||
// init spy
|
// init spy
|
||||||
QSignalSpy spy(extWeather, SIGNAL(dataReceived(const QVariantHash &)));
|
QSignalSpy spy(extWeather, SIGNAL(dataReceived(const QVariantHash &)));
|
||||||
QVariantHash firstValue = extWeather->run();
|
auto firstValue = extWeather->run();
|
||||||
|
|
||||||
// check values
|
// check values
|
||||||
QVERIFY(spy.wait(5000));
|
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("<img"));
|
QVERIFY(arguments[extWeather->tag("weather")].toString().startsWith("<img"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void TestExtWeather::test_copy()
|
void TestExtWeather::test_copy()
|
||||||
{
|
{
|
||||||
ExtWeather *newExtWeather = extWeather->copy("/dev/null", 1);
|
auto newExtWeather = extWeather->copy("/dev/null", 1);
|
||||||
|
|
||||||
QCOMPARE(newExtWeather->interval(), extWeather->interval());
|
QCOMPARE(newExtWeather->interval(), extWeather->interval());
|
||||||
QCOMPARE(newExtWeather->city(), extWeather->city());
|
QCOMPARE(newExtWeather->city(), extWeather->city());
|
||||||
@ -104,11 +103,11 @@ void TestExtWeather::run()
|
|||||||
{
|
{
|
||||||
// init spy
|
// init spy
|
||||||
QSignalSpy spy(extWeather, SIGNAL(dataReceived(const QVariantHash &)));
|
QSignalSpy spy(extWeather, SIGNAL(dataReceived(const QVariantHash &)));
|
||||||
QVariantHash firstValue = extWeather->run();
|
auto firstValue = extWeather->run();
|
||||||
|
|
||||||
// check values
|
// check values
|
||||||
QVERIFY(spy.wait(5000));
|
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);
|
QEXPECT_FAIL("", "WeatherID should not be 0", Continue);
|
||||||
QCOMPARE(arguments[extWeather->tag("weatherId")].toInt(), 0);
|
QCOMPARE(arguments[extWeather->tag("weatherId")].toInt(), 0);
|
||||||
QVERIFY((arguments[extWeather->tag("humidity")].toInt() >= humidity.first)
|
QVERIFY((arguments[extWeather->tag("humidity")].toInt() >= humidity.first)
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#include "testfloatformatter.h"
|
#include "testfloatformatter.h"
|
||||||
|
|
||||||
#include <QRandomGenerator>
|
#include <QRandomGenerator>
|
||||||
@ -44,12 +43,12 @@ void TestAWFloatFormatter::test_values() {}
|
|||||||
void TestAWFloatFormatter::test_count()
|
void TestAWFloatFormatter::test_count()
|
||||||
{
|
{
|
||||||
// assign
|
// assign
|
||||||
int count = 10 + AWTestLibrary::randomInt();
|
auto count = 10 + AWTestLibrary::randomInt();
|
||||||
formatter->setCount(count);
|
formatter->setCount(count);
|
||||||
QCOMPARE(formatter->count(), count);
|
QCOMPARE(formatter->count(), count);
|
||||||
|
|
||||||
// test
|
// test
|
||||||
QString output = formatter->convert(QRandomGenerator::global()->generateDouble());
|
auto output = formatter->convert(QRandomGenerator::global()->generateDouble());
|
||||||
QCOMPARE(output.length(), count);
|
QCOMPARE(output.length(), count);
|
||||||
|
|
||||||
// reset
|
// reset
|
||||||
@ -60,13 +59,13 @@ void TestAWFloatFormatter::test_count()
|
|||||||
void TestAWFloatFormatter::test_fillChar()
|
void TestAWFloatFormatter::test_fillChar()
|
||||||
{
|
{
|
||||||
// assign
|
// assign
|
||||||
char c = AWTestLibrary::randomChar();
|
auto c = AWTestLibrary::randomChar();
|
||||||
formatter->setFillChar(c);
|
formatter->setFillChar(c);
|
||||||
QCOMPARE(formatter->fillChar(), QChar(c));
|
QCOMPARE(formatter->fillChar(), QChar(c));
|
||||||
formatter->setCount(101);
|
formatter->setCount(101);
|
||||||
|
|
||||||
// test
|
// test
|
||||||
QString output = formatter->convert(AWTestLibrary::randomInt());
|
auto output = formatter->convert(AWTestLibrary::randomInt());
|
||||||
QVERIFY(output.startsWith(c));
|
QVERIFY(output.startsWith(c));
|
||||||
|
|
||||||
// reset
|
// reset
|
||||||
@ -78,13 +77,13 @@ void TestAWFloatFormatter::test_fillChar()
|
|||||||
void TestAWFloatFormatter::test_forceWidth()
|
void TestAWFloatFormatter::test_forceWidth()
|
||||||
{
|
{
|
||||||
// assign
|
// assign
|
||||||
int count = AWTestLibrary::randomInt(6);
|
auto count = AWTestLibrary::randomInt(6);
|
||||||
formatter->setForceWidth(true);
|
formatter->setForceWidth(true);
|
||||||
formatter->setCount(count);
|
formatter->setCount(count);
|
||||||
QCOMPARE(formatter->forceWidth(), true);
|
QCOMPARE(formatter->forceWidth(), true);
|
||||||
|
|
||||||
// test
|
// test
|
||||||
QString output = formatter->convert(QRandomGenerator::global()->generateDouble());
|
auto output = formatter->convert(QRandomGenerator::global()->generateDouble());
|
||||||
QCOMPARE(output.length(), count);
|
QCOMPARE(output.length(), count);
|
||||||
|
|
||||||
// reset
|
// reset
|
||||||
@ -103,7 +102,7 @@ void TestAWFloatFormatter::test_format()
|
|||||||
QCOMPARE(formatter->format(), 'e');
|
QCOMPARE(formatter->format(), 'e');
|
||||||
|
|
||||||
// test
|
// test
|
||||||
QString output = formatter->convert(QRandomGenerator::global()->generateDouble());
|
auto output = formatter->convert(QRandomGenerator::global()->generateDouble());
|
||||||
QVERIFY(output.contains('e'));
|
QVERIFY(output.contains('e'));
|
||||||
|
|
||||||
// reset
|
// reset
|
||||||
@ -114,12 +113,12 @@ void TestAWFloatFormatter::test_format()
|
|||||||
void TestAWFloatFormatter::test_precision()
|
void TestAWFloatFormatter::test_precision()
|
||||||
{
|
{
|
||||||
// assign
|
// assign
|
||||||
int precision = 1 + AWTestLibrary::randomInt(5);
|
auto precision = 1 + AWTestLibrary::randomInt(5);
|
||||||
formatter->setPrecision(precision);
|
formatter->setPrecision(precision);
|
||||||
QCOMPARE(formatter->precision(), precision);
|
QCOMPARE(formatter->precision(), precision);
|
||||||
|
|
||||||
// test
|
// test
|
||||||
QString output = formatter->convert(QRandomGenerator::global()->generateDouble());
|
auto output = formatter->convert(QRandomGenerator::global()->generateDouble());
|
||||||
output.remove("0.");
|
output.remove("0.");
|
||||||
QCOMPARE(output.length(), precision);
|
QCOMPARE(output.length(), precision);
|
||||||
|
|
||||||
@ -133,12 +132,12 @@ void TestAWFloatFormatter::test_multiplier()
|
|||||||
formatter->setPrecision(6);
|
formatter->setPrecision(6);
|
||||||
|
|
||||||
// assign
|
// assign
|
||||||
double multiplier = QRandomGenerator::global()->generateDouble();
|
auto multiplier = QRandomGenerator::global()->generateDouble();
|
||||||
formatter->setMultiplier(multiplier);
|
formatter->setMultiplier(multiplier);
|
||||||
QCOMPARE(formatter->multiplier(), multiplier);
|
QCOMPARE(formatter->multiplier(), multiplier);
|
||||||
|
|
||||||
// test
|
// test
|
||||||
double value = QRandomGenerator::global()->generateDouble();
|
auto value = QRandomGenerator::global()->generateDouble();
|
||||||
QCOMPARE(formatter->convert(value), QString::number(value * multiplier, 'f', 6));
|
QCOMPARE(formatter->convert(value), QString::number(value * multiplier, 'f', 6));
|
||||||
|
|
||||||
// reset
|
// reset
|
||||||
@ -149,12 +148,12 @@ void TestAWFloatFormatter::test_multiplier()
|
|||||||
void TestAWFloatFormatter::test_summand()
|
void TestAWFloatFormatter::test_summand()
|
||||||
{
|
{
|
||||||
// assign
|
// assign
|
||||||
double summand = QRandomGenerator::global()->generateDouble();
|
auto summand = QRandomGenerator::global()->generateDouble();
|
||||||
formatter->setSummand(summand);
|
formatter->setSummand(summand);
|
||||||
QCOMPARE(formatter->summand(), summand);
|
QCOMPARE(formatter->summand(), summand);
|
||||||
|
|
||||||
// test
|
// test
|
||||||
double value = QRandomGenerator::global()->generateDouble();
|
auto value = QRandomGenerator::global()->generateDouble();
|
||||||
QCOMPARE(formatter->convert(value), QString::number(value + summand, 'f', 6));
|
QCOMPARE(formatter->convert(value), QString::number(value + summand, 'f', 6));
|
||||||
|
|
||||||
// reset
|
// reset
|
||||||
@ -165,7 +164,7 @@ void TestAWFloatFormatter::test_summand()
|
|||||||
void TestAWFloatFormatter::test_copy()
|
void TestAWFloatFormatter::test_copy()
|
||||||
{
|
{
|
||||||
doRandom();
|
doRandom();
|
||||||
AWFloatFormatter *newFormatter = formatter->copy("/dev/null", 1);
|
auto newFormatter = formatter->copy("/dev/null", 1);
|
||||||
|
|
||||||
QCOMPARE(newFormatter->count(), formatter->count());
|
QCOMPARE(newFormatter->count(), formatter->count());
|
||||||
QCOMPARE(newFormatter->fillChar(), formatter->fillChar());
|
QCOMPARE(newFormatter->fillChar(), formatter->fillChar());
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#include "testjsonformatter.h"
|
#include "testjsonformatter.h"
|
||||||
|
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
@ -54,7 +53,7 @@ void TestAWJsonFormatter::test_conversion()
|
|||||||
|
|
||||||
void TestAWJsonFormatter::test_copy()
|
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->path(), formatter->path());
|
||||||
QCOMPARE(newFormatter->number(), 1);
|
QCOMPARE(newFormatter->number(), 1);
|
||||||
@ -68,25 +67,25 @@ void TestAWJsonFormatter::generate()
|
|||||||
value = AWTestLibrary::randomString();
|
value = AWTestLibrary::randomString();
|
||||||
|
|
||||||
QVariantMap first;
|
QVariantMap first;
|
||||||
QString firstKey = AWTestLibrary::randomString();
|
auto firstKey = AWTestLibrary::randomString();
|
||||||
first[firstKey] = value;
|
first[firstKey] = value;
|
||||||
|
|
||||||
int listCount = AWTestLibrary::randomInt(5) + 1;
|
auto listCount = AWTestLibrary::randomInt(5) + 1;
|
||||||
int validCount = AWTestLibrary::randomInt(listCount);
|
auto validCount = AWTestLibrary::randomInt(listCount);
|
||||||
QVariantList second;
|
QVariantList second;
|
||||||
for (int i = 0; i < listCount; i++) {
|
for (auto i = 0; i < listCount; i++) {
|
||||||
if (i == validCount) {
|
if (i == validCount) {
|
||||||
second.append(first);
|
second.append(first);
|
||||||
} else {
|
} else {
|
||||||
QString key = AWTestLibrary::randomString();
|
auto key = AWTestLibrary::randomString();
|
||||||
QString val = AWTestLibrary::randomString();
|
auto val = AWTestLibrary::randomString();
|
||||||
QVariantMap dict;
|
QVariantMap dict;
|
||||||
dict[key] = val;
|
dict[key] = val;
|
||||||
second.append(dict);
|
second.append(dict);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString thirdKey = AWTestLibrary::randomString();
|
auto thirdKey = AWTestLibrary::randomString();
|
||||||
QVariantMap output;
|
QVariantMap output;
|
||||||
output[thirdKey] = second;
|
output[thirdKey] = second;
|
||||||
|
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#include "testlistformatter.h"
|
#include "testlistformatter.h"
|
||||||
|
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
@ -50,7 +49,7 @@ void TestAWListFormatter::test_values()
|
|||||||
|
|
||||||
void TestAWListFormatter::test_conversion()
|
void TestAWListFormatter::test_conversion()
|
||||||
{
|
{
|
||||||
QStringList value = AWTestLibrary::randomStringList();
|
auto value = AWTestLibrary::randomStringList();
|
||||||
QCOMPARE(formatter->convert(value), value.join(separator));
|
QCOMPARE(formatter->convert(value), value.join(separator));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,8 +57,8 @@ void TestAWListFormatter::test_conversion()
|
|||||||
void TestAWListFormatter::test_sorted()
|
void TestAWListFormatter::test_sorted()
|
||||||
{
|
{
|
||||||
formatter->setSorted(true);
|
formatter->setSorted(true);
|
||||||
QStringList value = AWTestLibrary::randomStringList();
|
auto value = AWTestLibrary::randomStringList();
|
||||||
QString received = formatter->convert(value);
|
auto received = formatter->convert(value);
|
||||||
|
|
||||||
value.sort();
|
value.sort();
|
||||||
QCOMPARE(received, value.join(separator));
|
QCOMPARE(received, value.join(separator));
|
||||||
@ -68,8 +67,8 @@ void TestAWListFormatter::test_sorted()
|
|||||||
|
|
||||||
void TestAWListFormatter::test_filter()
|
void TestAWListFormatter::test_filter()
|
||||||
{
|
{
|
||||||
QStringList value = AWTestLibrary::randomStringList();
|
auto value = AWTestLibrary::randomStringList();
|
||||||
QStringList filters = AWTestLibrary::randomSelect(value);
|
auto filters = AWTestLibrary::randomSelect(value);
|
||||||
value.sort();
|
value.sort();
|
||||||
formatter->setFilter(QString("(^%1$)").arg(filters.join("$|^")));
|
formatter->setFilter(QString("(^%1$)").arg(filters.join("$|^")));
|
||||||
|
|
||||||
@ -79,7 +78,7 @@ void TestAWListFormatter::test_filter()
|
|||||||
|
|
||||||
void TestAWListFormatter::test_copy()
|
void TestAWListFormatter::test_copy()
|
||||||
{
|
{
|
||||||
AWListFormatter *newFormatter = formatter->copy("/dev/null", 1);
|
auto newFormatter = formatter->copy("/dev/null", 1);
|
||||||
|
|
||||||
QCOMPARE(newFormatter->number(), 1);
|
QCOMPARE(newFormatter->number(), 1);
|
||||||
QCOMPARE(newFormatter->filter(), formatter->filter());
|
QCOMPARE(newFormatter->filter(), formatter->filter());
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#include "testnetworksource.h"
|
#include "testnetworksource.h"
|
||||||
|
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
@ -27,7 +26,7 @@
|
|||||||
void TestNetworkSource::initTestCase()
|
void TestNetworkSource::initTestCase()
|
||||||
{
|
{
|
||||||
AWTestLibrary::init();
|
AWTestLibrary::init();
|
||||||
source = new NetworkSource(this, QStringList());
|
source = new NetworkSource(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -39,7 +38,9 @@ void TestNetworkSource::cleanupTestCase()
|
|||||||
|
|
||||||
void TestNetworkSource::test_sources()
|
void TestNetworkSource::test_sources()
|
||||||
{
|
{
|
||||||
QCOMPARE(source->sources(), QStringList({"device", "ssid"}));
|
auto sources = source->sources();
|
||||||
|
QVERIFY(sources.contains("device"));
|
||||||
|
QVERIFY(sources.contains("ssid"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#include "testnoformatter.h"
|
#include "testnoformatter.h"
|
||||||
|
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
@ -43,19 +42,19 @@ void TestAWNoFormatter::test_values() {}
|
|||||||
void TestAWNoFormatter::test_conversion()
|
void TestAWNoFormatter::test_conversion()
|
||||||
{
|
{
|
||||||
// integer
|
// integer
|
||||||
int randomInt = AWTestLibrary::randomInt();
|
auto randomInt = AWTestLibrary::randomInt();
|
||||||
QCOMPARE(formatter->convert(randomInt), QString::number(randomInt));
|
QCOMPARE(formatter->convert(randomInt), QString::number(randomInt));
|
||||||
// float
|
// float
|
||||||
QWARN("Float conversion isn't tested here due to possible rounding errors");
|
QWARN("Float conversion isn't tested here due to possible rounding errors");
|
||||||
// string
|
// string
|
||||||
QString randomString = AWTestLibrary::randomString();
|
auto randomString = AWTestLibrary::randomString();
|
||||||
QCOMPARE(formatter->convert(randomString), randomString);
|
QCOMPARE(formatter->convert(randomString), randomString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void TestAWNoFormatter::test_copy()
|
void TestAWNoFormatter::test_copy()
|
||||||
{
|
{
|
||||||
AWNoFormatter *newFormatter = formatter->copy("/dev/null", 1);
|
auto newFormatter = formatter->copy("/dev/null", 1);
|
||||||
|
|
||||||
QCOMPARE(newFormatter->number(), 1);
|
QCOMPARE(newFormatter->number(), 1);
|
||||||
|
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#include "testplayersource.h"
|
#include "testplayersource.h"
|
||||||
|
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
@ -41,8 +40,8 @@ void TestPlayerSource::_test_sources(const PlayerSource *_source)
|
|||||||
|
|
||||||
void TestPlayerSource::test_buildString()
|
void TestPlayerSource::test_buildString()
|
||||||
{
|
{
|
||||||
QString randomString = AWTestLibrary::randomString(1, 40);
|
auto randomString = AWTestLibrary::randomString(1, 40);
|
||||||
QString str = PlayerSource::buildString("", randomString, 20);
|
auto str = PlayerSource::buildString("", randomString, 20);
|
||||||
QCOMPARE(str.length(), 20);
|
QCOMPARE(str.length(), 20);
|
||||||
|
|
||||||
str = PlayerSource::buildString(str, randomString, 20);
|
str = PlayerSource::buildString(str, randomString, 20);
|
||||||
@ -55,7 +54,7 @@ void TestPlayerSource::test_buildString()
|
|||||||
|
|
||||||
void TestPlayerSource::test_stripString()
|
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);
|
QCOMPARE(str.length(), 20);
|
||||||
|
|
||||||
str = PlayerSource::buildString("", AWTestLibrary::randomString(1, 10), 20);
|
str = PlayerSource::buildString("", AWTestLibrary::randomString(1, 10), 20);
|
||||||
@ -65,11 +64,9 @@ void TestPlayerSource::test_stripString()
|
|||||||
|
|
||||||
void TestPlayerSource::test_autoMpris()
|
void TestPlayerSource::test_autoMpris()
|
||||||
{
|
{
|
||||||
QStringList args(QStringList() << "mpris" << mpdAddress << QString::number(mpdPort) << "auto"
|
auto source = new PlayerSource(this, "mpris", mpdAddress, mpdPort, "auto", 10);
|
||||||
<< QString::number(10));
|
|
||||||
PlayerSource *source = new PlayerSource(this, args);
|
|
||||||
|
|
||||||
bool empty = source->getAutoMpris().isEmpty();
|
auto empty = source->getAutoMpris().isEmpty();
|
||||||
if (empty)
|
if (empty)
|
||||||
QWARN("No MPRIS found, manual check required");
|
QWARN("No MPRIS found, manual check required");
|
||||||
else
|
else
|
||||||
@ -79,20 +76,19 @@ void TestPlayerSource::test_autoMpris()
|
|||||||
|
|
||||||
void TestPlayerSource::test_mpd()
|
void TestPlayerSource::test_mpd()
|
||||||
{
|
{
|
||||||
QStringList args(QStringList() << "mpd" << mpdAddress << QString::number(mpdPort) << "auto" << QString::number(10));
|
auto source = new PlayerSource(this, "mpd", mpdAddress, mpdPort, "auto", 10);
|
||||||
PlayerSource *source = new PlayerSource(this, args);
|
|
||||||
_test_sources(source);
|
_test_sources(source);
|
||||||
|
|
||||||
// init spy
|
// init spy
|
||||||
QSignalSpy spy(source, SIGNAL(dataReceived(const QVariantHash &)));
|
QSignalSpy spy(source, SIGNAL(dataReceived(const QVariantHash &)));
|
||||||
QVariant firstValue = source->data("title");
|
auto firstValue = source->data("title");
|
||||||
if (!source->isMpdSocketConnected())
|
if (!source->isMpdSocketConnected())
|
||||||
QSKIP("No mpd found");
|
QSKIP("No mpd found");
|
||||||
|
|
||||||
// check values
|
// check values
|
||||||
QVERIFY(spy.wait(5000));
|
QVERIFY(spy.wait(5000));
|
||||||
QList<QVariant> arguments = spy.takeFirst();
|
auto arguments = spy.takeFirst();
|
||||||
QVariantHash secondValue = arguments.at(0).toHash();
|
auto secondValue = arguments.at(0).toHash();
|
||||||
|
|
||||||
// actually nothing to test here just print warning if no information found
|
// actually nothing to test here just print warning if no information found
|
||||||
if (secondValue["title"].toString() == "unknown")
|
if (secondValue["title"].toString() == "unknown")
|
||||||
@ -104,14 +100,12 @@ void TestPlayerSource::test_mpd()
|
|||||||
|
|
||||||
void TestPlayerSource::test_mpris()
|
void TestPlayerSource::test_mpris()
|
||||||
{
|
{
|
||||||
QStringList args(QStringList() << "mpris" << mpdAddress << QString::number(mpdPort) << "auto"
|
auto source = new PlayerSource(this, "mpris", mpdAddress, mpdPort, "auto", 10);
|
||||||
<< QString::number(10));
|
|
||||||
PlayerSource *source = new PlayerSource(this, args);
|
|
||||||
_test_sources(source);
|
_test_sources(source);
|
||||||
|
|
||||||
QString value = source->data("title").toString();
|
auto value = source->data("title").toString();
|
||||||
int progress = source->data("progress").toInt();
|
auto progress = source->data("progress").toInt();
|
||||||
int duration = source->data("duration").toInt();
|
auto duration = source->data("duration").toInt();
|
||||||
|
|
||||||
// actually nothing to test here just print warning if no information found
|
// actually nothing to test here just print warning if no information found
|
||||||
if (value == "unknown")
|
if (value == "unknown")
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#include "testprocessessource.h"
|
#include "testprocessessource.h"
|
||||||
|
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
@ -27,7 +26,7 @@
|
|||||||
void TestProcessesSource::initTestCase()
|
void TestProcessesSource::initTestCase()
|
||||||
{
|
{
|
||||||
AWTestLibrary::init();
|
AWTestLibrary::init();
|
||||||
source = new ProcessesSource(this, QStringList());
|
source = new ProcessesSource(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#include "testscriptformatter.h"
|
#include "testscriptformatter.h"
|
||||||
|
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
@ -52,7 +51,7 @@ void TestAWScriptFormatter::test_values()
|
|||||||
|
|
||||||
void TestAWScriptFormatter::test_conversion()
|
void TestAWScriptFormatter::test_conversion()
|
||||||
{
|
{
|
||||||
QString string = AWTestLibrary::randomString();
|
auto string = AWTestLibrary::randomString();
|
||||||
QCOMPARE(formatter->convert(string), string);
|
QCOMPARE(formatter->convert(string), string);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,7 +92,7 @@ void TestAWScriptFormatter::test_hasReturn()
|
|||||||
|
|
||||||
void TestAWScriptFormatter::test_copy()
|
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->appendCode(), formatter->appendCode());
|
||||||
QCOMPARE(newFormatter->code(), formatter->code());
|
QCOMPARE(newFormatter->code(), formatter->code());
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#include "teststringformatter.h"
|
#include "teststringformatter.h"
|
||||||
|
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
@ -43,7 +42,7 @@ void TestAWStringFormatter::test_values() {}
|
|||||||
void TestAWStringFormatter::test_count()
|
void TestAWStringFormatter::test_count()
|
||||||
{
|
{
|
||||||
// assign
|
// assign
|
||||||
int count = 10 + AWTestLibrary::randomInt();
|
auto count = 10 + AWTestLibrary::randomInt();
|
||||||
formatter->setCount(count);
|
formatter->setCount(count);
|
||||||
QCOMPARE(formatter->count(), count);
|
QCOMPARE(formatter->count(), count);
|
||||||
|
|
||||||
@ -51,7 +50,7 @@ void TestAWStringFormatter::test_count()
|
|||||||
auto testString = AWTestLibrary::randomString();
|
auto testString = AWTestLibrary::randomString();
|
||||||
while (testString.length() > count)
|
while (testString.length() > count)
|
||||||
testString = AWTestLibrary::randomString();
|
testString = AWTestLibrary::randomString();
|
||||||
QString output = formatter->convert(testString);
|
auto output = formatter->convert(testString);
|
||||||
QCOMPARE(output.length(), count);
|
QCOMPARE(output.length(), count);
|
||||||
|
|
||||||
// reset
|
// reset
|
||||||
@ -62,13 +61,13 @@ void TestAWStringFormatter::test_count()
|
|||||||
void TestAWStringFormatter::test_fillChar()
|
void TestAWStringFormatter::test_fillChar()
|
||||||
{
|
{
|
||||||
// assign
|
// assign
|
||||||
char c = AWTestLibrary::randomChar();
|
auto c = AWTestLibrary::randomChar();
|
||||||
formatter->setFillChar(c);
|
formatter->setFillChar(c);
|
||||||
QCOMPARE(formatter->fillChar(), QChar(c));
|
QCOMPARE(formatter->fillChar(), QChar(c));
|
||||||
formatter->setCount(101);
|
formatter->setCount(101);
|
||||||
|
|
||||||
// test
|
// test
|
||||||
QString output = formatter->convert(AWTestLibrary::randomString());
|
auto output = formatter->convert(AWTestLibrary::randomString());
|
||||||
QVERIFY(output.startsWith(c));
|
QVERIFY(output.startsWith(c));
|
||||||
|
|
||||||
// reset
|
// reset
|
||||||
@ -80,13 +79,13 @@ void TestAWStringFormatter::test_fillChar()
|
|||||||
void TestAWStringFormatter::test_forceWidth()
|
void TestAWStringFormatter::test_forceWidth()
|
||||||
{
|
{
|
||||||
// assign
|
// assign
|
||||||
int count = AWTestLibrary::randomInt();
|
auto count = AWTestLibrary::randomInt();
|
||||||
formatter->setForceWidth(true);
|
formatter->setForceWidth(true);
|
||||||
formatter->setCount(count);
|
formatter->setCount(count);
|
||||||
QCOMPARE(formatter->forceWidth(), true);
|
QCOMPARE(formatter->forceWidth(), true);
|
||||||
|
|
||||||
// test
|
// test
|
||||||
QString output = formatter->convert(AWTestLibrary::randomString());
|
auto output = formatter->convert(AWTestLibrary::randomString());
|
||||||
QCOMPARE(output.length(), count);
|
QCOMPARE(output.length(), count);
|
||||||
|
|
||||||
// reset
|
// reset
|
||||||
@ -98,7 +97,7 @@ void TestAWStringFormatter::test_forceWidth()
|
|||||||
void TestAWStringFormatter::test_copy()
|
void TestAWStringFormatter::test_copy()
|
||||||
{
|
{
|
||||||
doRandom();
|
doRandom();
|
||||||
AWStringFormatter *newFormatter = formatter->copy("/dev/null", 1);
|
auto newFormatter = formatter->copy("/dev/null", 1);
|
||||||
|
|
||||||
QCOMPARE(newFormatter->count(), formatter->count());
|
QCOMPARE(newFormatter->count(), formatter->count());
|
||||||
QCOMPARE(newFormatter->fillChar(), formatter->fillChar());
|
QCOMPARE(newFormatter->fillChar(), formatter->fillChar());
|
||||||
|
Loading…
Reference in New Issue
Block a user