Add test for hddsource, move sources to own library

This commit is contained in:
Evgenii Alekseev 2016-06-07 14:16:48 +03:00
parent 18789f78b3
commit 5a0541d06d
41 changed files with 344 additions and 143 deletions

View File

@ -66,6 +66,7 @@ endif ()
set(PROJECT_TRDPARTY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty)
set(PROJECT_LIBRARY awesomewidgets)
set(PROJECT_MONITORSOURCES extsysmonsources)
include(libraries.cmake)
include(clang-format.cmake)
include(cppcheck.cmake)
@ -74,6 +75,7 @@ include(coverity.cmake)
get_directory_property(CMAKE_DEFINITIONS COMPILE_DEFINITIONS)
configure_file(${CMAKE_SOURCE_DIR}/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/version.h)
add_subdirectory(awesomewidgets)
add_subdirectory(extsysmonsources)
add_subdirectory(extsysmon)
if (BUILD_PLASMOIDS)
add_subdirectory(awesome-widget)

View File

@ -24,6 +24,8 @@ Q_LOGGING_CATEGORY(LOG_AW, "org.kde.plasma.awesomewidget",
Q_LOGGING_CATEGORY(LOG_DP, "org.kde.plasma.desktoppanel",
QtMsgType::QtWarningMsg)
Q_LOGGING_CATEGORY(LOG_ESM, "org.kde.plasma.extsysmon", QtMsgType::QtWarningMsg)
Q_LOGGING_CATEGORY(LOG_ESS, "org.kde.plasma.extsysmonsources",
QtMsgType::QtWarningMsg)
Q_LOGGING_CATEGORY(LOG_LIB, "org.kde.plasma.awesomewidgets",
QtMsgType::QtWarningMsg)
@ -69,7 +71,6 @@ const QStringList getBuildData()
.arg(CMAKE_SHARED_LINKER_FLAGS));
// components
metadata.append(QString("Components data:"));
metadata.append(QString(" BUILD_COVERAGE: %1").arg(BUILD_COVERAGE));
metadata.append(QString(" BUILD_PLASMOIDS: %1").arg(BUILD_PLASMOIDS));
metadata.append(
QString(" BUILD_DEB_PACKAGE: %1").arg(BUILD_DEB_PACKAGE));

View File

@ -34,6 +34,7 @@
Q_DECLARE_LOGGING_CATEGORY(LOG_AW)
Q_DECLARE_LOGGING_CATEGORY(LOG_DP)
Q_DECLARE_LOGGING_CATEGORY(LOG_ESM)
Q_DECLARE_LOGGING_CATEGORY(LOG_ESS)
Q_DECLARE_LOGGING_CATEGORY(LOG_LIB)
const QStringList getBuildData();

View File

@ -6,6 +6,7 @@ include_directories(
${CMAKE_SOURCE_DIR}
${CMAKE_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../${PROJECT_LIBRARY}/
${CMAKE_CURRENT_SOURCE_DIR}/../${PROJECT_MONITORSOURCES}/
${PROJECT_TRDPARTY_DIR}
${Qt_INCLUDE}
${Kf5_INCLUDE}
@ -13,15 +14,18 @@ include_directories(
file(GLOB SUBPROJECT_DESKTOP_IN *.desktop)
file(RELATIVE_PATH SUBPROJECT_DESKTOP ${CMAKE_SOURCE_DIR} ${SUBPROJECT_DESKTOP_IN})
file(GLOB SUBPROJECT_SOURCE *.cpp sources/*.cpp ${CMAKE_SOURCE_DIR}/*.cpp)
file(GLOB SUBPROJECT_SOURCE *.cpp ${CMAKE_SOURCE_DIR}/*.cpp)
file(GLOB SUBPROJECT_HEADER *.h)
file(GLOB SUBPROJECT_CONF *.conf)
# prepare
configure_file(${SUBPROJECT_DESKTOP_IN} ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT_DESKTOP})
# make
add_library(${SUBPROJECT} MODULE ${SUBPROJECT_SOURCE})
target_link_libraries(${SUBPROJECT} ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Kf5_LIBRARIES})
add_library(${SUBPROJECT} MODULE ${SUBPROJECT_SOURCE} ${SUBPROJECT_HEADER})
target_link_libraries(${SUBPROJECT}
${PROJECT_LIBRARY} ${PROJECT_MONITORSOURCES}
${Qt_LIBRARIES} ${Kf5_LIBRARIES})
kcoreaddons_desktop_to_json(${SUBPROJECT} ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT_DESKTOP}
SERVICE_TYPES plasma-dataengine.desktop)

View File

@ -17,7 +17,6 @@
#include "extsysmon.h"
#include <QDir>
#include <QFile>
#include <QRegExp>
#include <QSettings>
@ -25,6 +24,8 @@
#include "awdebug.h"
#include "extsysmonaggregator.h"
#include "gputempsource.h"
#include "hddtempsource.h"
ExtendedSysMon::ExtendedSysMon(QObject *parent, const QVariantList &args)
@ -83,37 +84,6 @@ bool ExtendedSysMon::updateSourceEvent(const QString &source)
}
QStringList ExtendedSysMon::getAllHdd() const
{
QStringList allDevices
= QDir(QString("/dev")).entryList(QDir::System, QDir::Name);
QStringList devices = allDevices.filter(QRegExp(QString("^[hms]d[a-z]$")));
for (int i = 0; i < devices.count(); i++)
devices[i] = QString("/dev/%1").arg(devices.at(i));
qCInfo(LOG_ESM) << "Device list" << devices;
return devices;
}
QString ExtendedSysMon::getAutoGpu() const
{
QString gpu = QString("disable");
QFile moduleFile(QString("/proc/modules"));
if (!moduleFile.open(QIODevice::ReadOnly))
return gpu;
QString output = moduleFile.readAll();
if (output.contains(QString("fglrx")))
gpu = QString("ati");
else if (output.contains(QString("nvidia")))
gpu = QString("nvidia");
qCInfo(LOG_ESM) << "Device" << gpu;
return gpu;
}
void ExtendedSysMon::readConfiguration()
{
QString fileName
@ -161,12 +131,12 @@ ExtendedSysMon::updateConfiguration(QHash<QString, QString> rawConfig) const
if (rawConfig[QString("GPUDEV")] == QString("disable"))
rawConfig[QString("GPUDEV")] = QString("disable");
else if (rawConfig[QString("GPUDEV")] == QString("auto"))
rawConfig[QString("GPUDEV")] = getAutoGpu();
rawConfig[QString("GPUDEV")] = GPUTemperatureSource::autoGpu();
else if ((rawConfig[QString("GPUDEV")] != QString("ati"))
&& (rawConfig[QString("GPUDEV")] != QString("nvidia")))
rawConfig[QString("GPUDEV")] = getAutoGpu();
rawConfig[QString("GPUDEV")] = GPUTemperatureSource::autoGpu();
// hdddev
QStringList allHddDevices = getAllHdd();
QStringList allHddDevices = HDDTemperatureSource::allHdd();
if (rawConfig[QString("HDDDEV")] == QString("all")) {
rawConfig[QString("HDDDEV")] = allHddDevices.join(QChar(','));
} else if (rawConfig[QString("HDDDEV")] == QString("disable")) {

View File

@ -41,8 +41,6 @@ private:
ExtSysMonAggregator *aggregator = nullptr;
QHash<QString, QString> configuration;
// methods
QStringList getAllHdd() const;
QString getAutoGpu() const;
void readConfiguration();
QHash<QString, QString>
updateConfiguration(QHash<QString, QString> rawConfig) const;

View File

@ -18,19 +18,19 @@
#include "extsysmonaggregator.h"
#include "awdebug.h"
#include "sources/batterysource.h"
#include "sources/customsource.h"
#include "sources/desktopsource.h"
#include "sources/gpuloadsource.h"
#include "sources/gputempsource.h"
#include "sources/hddtempsource.h"
#include "sources/loadsource.h"
#include "sources/networksource.h"
#include "sources/playersource.h"
#include "sources/processessource.h"
#include "sources/quotessource.h"
#include "sources/upgradesource.h"
#include "sources/weathersource.h"
#include "batterysource.h"
#include "customsource.h"
#include "desktopsource.h"
#include "gpuloadsource.h"
#include "gputempsource.h"
#include "hddtempsource.h"
#include "loadsource.h"
#include "networksource.h"
#include "playersource.h"
#include "processessource.h"
#include "quotessource.h"
#include "upgradesource.h"
#include "weathersource.h"
ExtSysMonAggregator::ExtSysMonAggregator(QObject *parent,

View File

@ -20,7 +20,7 @@
#include <QObject>
#include "sources/abstractextsysmonsource.h"
#include "abstractextsysmonsource.h"
class ExtSysMonAggregator : public QObject

View File

@ -0,0 +1,18 @@
set(SUBPROJECT ${PROJECT_MONITORSOURCES})
message(STATUS "Subproject ${SUBPROJECT}")
add_definitions(-DTRANSLATION_DOMAIN=\"plasma_applet_org.kde.plasma.awesomewidget\")
include_directories(
${CMAKE_SOURCE_DIR}
${CMAKE_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../${PROJECT_LIBRARY}/
${PROJECT_TRDPARTY_DIR}
${Qt_INCLUDE}
${Kf5_INCLUDE}
)
file(GLOB SUBPROJECT_SOURCE *.cpp)
file(GLOB SUBPROJECT_HEADER *.h)
add_library(${SUBPROJECT} STATIC ${SUBPROJECT_SOURCE} ${SUBPROJECT_HEADER})
target_link_libraries(${SUBPROJECT} ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Kf5_LIBRARIES})

View File

@ -25,6 +25,8 @@
class AbstractExtSysMonSource : public QObject
{
Q_OBJECT
public:
explicit AbstractExtSysMonSource(QObject *parent, const QStringList)
: QObject(parent){};
@ -40,6 +42,9 @@ public:
rx.indexIn(source);
return rx.cap().toInt();
}
signals:
void dataReceived(const QVariantHash &);
};

View File

@ -27,7 +27,7 @@ BatterySource::BatterySource(QObject *parent, const QStringList args)
: AbstractExtSysMonSource(parent, args)
{
Q_ASSERT(args.count() == 1);
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
m_acpiPath = args.at(0);
m_sources = getSources();
@ -36,13 +36,13 @@ BatterySource::BatterySource(QObject *parent, const QStringList args)
BatterySource::~BatterySource()
{
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
}
QVariant BatterySource::data(QString source)
{
qCDebug(LOG_ESM) << "Source" << source;
qCDebug(LOG_ESS) << "Source" << source;
if (!m_values.contains(source))
run();
@ -53,7 +53,7 @@ QVariant BatterySource::data(QString source)
QVariantMap BatterySource::initialData(QString source) const
{
qCDebug(LOG_ESM) << "Source" << source;
qCDebug(LOG_ESS) << "Source" << source;
QVariantMap data;
if (source == QString("battery/ac")) {
@ -132,10 +132,10 @@ QStringList BatterySource::getSources()
.entryList(QStringList() << QString("BAT*"),
QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)
.count();
qCInfo(LOG_ESM) << "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("battery/bat%1").arg(i));
qCInfo(LOG_ESM) << "Sources list" << sources;
qCInfo(LOG_ESS) << "Sources list" << sources;
return sources;
}

View File

@ -26,7 +26,7 @@ CustomSource::CustomSource(QObject *parent, const QStringList args)
: AbstractExtSysMonSource(parent, args)
{
Q_ASSERT(args.count() == 0);
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
extScripts = new ExtItemAggregator<ExtScript>(nullptr, QString("scripts"));
m_sources = getSources();
@ -35,7 +35,7 @@ CustomSource::CustomSource(QObject *parent, const QStringList args)
CustomSource::~CustomSource()
{
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
delete extScripts;
}
@ -43,7 +43,7 @@ CustomSource::~CustomSource()
QVariant CustomSource::data(QString source)
{
qCDebug(LOG_ESM) << "Source" << source;
qCDebug(LOG_ESS) << "Source" << source;
// there are only one value
return extScripts->itemByTagNumber(index(source))->run().values().first();
@ -52,7 +52,7 @@ QVariant CustomSource::data(QString source)
QVariantMap CustomSource::initialData(QString source) const
{
qCDebug(LOG_ESM) << "Source" << source;
qCDebug(LOG_ESS) << "Source" << source;
QVariantMap data;
data[QString("min")] = QString("");

View File

@ -27,19 +27,19 @@ DesktopSource::DesktopSource(QObject *parent, const QStringList args)
: AbstractExtSysMonSource(parent, args)
{
Q_ASSERT(args.count() == 0);
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
}
DesktopSource::~DesktopSource()
{
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
}
QVariant DesktopSource::data(QString source)
{
qCDebug(LOG_ESM) << "Source" << source;
qCDebug(LOG_ESS) << "Source" << source;
int current = KWindowSystem::currentDesktop();
int total = KWindowSystem::numberOfDesktops();
@ -63,7 +63,7 @@ QVariant DesktopSource::data(QString source)
QVariantMap DesktopSource::initialData(QString source) const
{
qCDebug(LOG_ESM) << "Source" << source;
qCDebug(LOG_ESS) << "Source" << source;
QVariantMap data;
if (source == QString("desktop/current/name")) {

View File

@ -18,6 +18,7 @@
#include "gpuloadsource.h"
#include <QFile>
#include <QProcess>
#include <QTextCodec>
@ -28,7 +29,7 @@ GPULoadSource::GPULoadSource(QObject *parent, const QStringList args)
: AbstractExtSysMonSource(parent, args)
{
Q_ASSERT(args.count() == 1);
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
m_device = args.at(0);
@ -44,16 +45,34 @@ GPULoadSource::GPULoadSource(QObject *parent, const QStringList args)
GPULoadSource::~GPULoadSource()
{
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
m_process->kill();
m_process->deleteLater();
}
QString GPULoadSource::autoGpu()
{
QString gpu = QString("disable");
QFile moduleFile(QString("/proc/modules"));
if (!moduleFile.open(QIODevice::ReadOnly))
return gpu;
QString output = moduleFile.readAll();
if (output.contains(QString("fglrx")))
gpu = QString("ati");
else if (output.contains(QString("nvidia")))
gpu = QString("nvidia");
qCInfo(LOG_ESM) << "Device" << gpu;
return gpu;
}
QVariant GPULoadSource::data(QString source)
{
qCDebug(LOG_ESM) << "Source" << source;
qCDebug(LOG_ESS) << "Source" << source;
if (source == QString("gpu/load"))
run();
@ -64,7 +83,7 @@ QVariant GPULoadSource::data(QString source)
QVariantMap GPULoadSource::initialData(QString source) const
{
qCDebug(LOG_ESM) << "Source" << source;
qCDebug(LOG_ESS) << "Source" << source;
QVariantMap data;
if (source == QString("gpu/load")) {
@ -87,7 +106,7 @@ void GPULoadSource::run()
QString cmd = m_device == QString("nvidia")
? QString("nvidia-smi -q -x")
: QString("aticonfig --od-getclocks");
qCInfo(LOG_ESM) << "cmd" << cmd;
qCInfo(LOG_ESS) << "cmd" << cmd;
m_process->start(cmd);
}
@ -104,15 +123,15 @@ QStringList GPULoadSource::sources() const
void GPULoadSource::updateValue()
{
qCInfo(LOG_LIB) << "Cmd returns" << m_process->exitCode();
qCInfo(LOG_ESS) << "Cmd returns" << m_process->exitCode();
QString qdebug = QTextCodec::codecForMib(106)
->toUnicode(m_process->readAllStandardError())
.trimmed();
qCInfo(LOG_LIB) << "Error" << qdebug;
qCInfo(LOG_ESS) << "Error" << qdebug;
QString qoutput = QTextCodec::codecForMib(106)
->toUnicode(m_process->readAllStandardOutput())
.trimmed();
qCInfo(LOG_LIB) << "Output" << qoutput;
qCInfo(LOG_ESS) << "Output" << qoutput;
if (m_device == QString("nvidia")) {
for (auto str : qoutput.split(QChar('\n'), QString::SkipEmptyParts)) {

View File

@ -30,6 +30,7 @@ class GPULoadSource : public AbstractExtSysMonSource
public:
explicit GPULoadSource(QObject *parent, const QStringList args);
virtual ~GPULoadSource();
static QString autoGpu();
QVariant data(QString source);
QVariantMap initialData(QString source) const;
void run();

View File

@ -18,6 +18,7 @@
#include "gputempsource.h"
#include <QFile>
#include <QProcess>
#include <QTextCodec>
@ -29,7 +30,7 @@ GPUTemperatureSource::GPUTemperatureSource(QObject *parent,
: AbstractExtSysMonSource(parent, args)
{
Q_ASSERT(args.count() == 1);
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
m_device = args.at(0);
@ -45,16 +46,34 @@ GPUTemperatureSource::GPUTemperatureSource(QObject *parent,
GPUTemperatureSource::~GPUTemperatureSource()
{
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
m_process->kill();
m_process->deleteLater();
}
QString GPUTemperatureSource::autoGpu()
{
QString gpu = QString("disable");
QFile moduleFile(QString("/proc/modules"));
if (!moduleFile.open(QIODevice::ReadOnly))
return gpu;
QString output = moduleFile.readAll();
if (output.contains(QString("fglrx")))
gpu = QString("ati");
else if (output.contains(QString("nvidia")))
gpu = QString("nvidia");
qCInfo(LOG_ESM) << "Device" << gpu;
return gpu;
}
QVariant GPUTemperatureSource::data(QString source)
{
qCDebug(LOG_ESM) << "Source" << source;
qCDebug(LOG_ESS) << "Source" << source;
if (source == QString("gpu/temperature"))
run();
@ -65,7 +84,7 @@ QVariant GPUTemperatureSource::data(QString source)
QVariantMap GPUTemperatureSource::initialData(QString source) const
{
qCDebug(LOG_ESM) << "Source" << source;
qCDebug(LOG_ESS) << "Source" << source;
QVariantMap data;
if (source == QString("gpu/temperature")) {
@ -88,7 +107,7 @@ void GPUTemperatureSource::run()
QString cmd = m_device == QString("nvidia")
? QString("nvidia-smi -q -x")
: QString("aticonfig --od-gettemperature");
qCInfo(LOG_ESM) << "cmd" << cmd;
qCInfo(LOG_ESS) << "cmd" << cmd;
m_process->start(cmd);
}
@ -105,15 +124,15 @@ QStringList GPUTemperatureSource::sources() const
void GPUTemperatureSource::updateValue()
{
qCInfo(LOG_LIB) << "Cmd returns" << m_process->exitCode();
qCInfo(LOG_ESS) << "Cmd returns" << m_process->exitCode();
QString qdebug = QTextCodec::codecForMib(106)
->toUnicode(m_process->readAllStandardError())
.trimmed();
qCInfo(LOG_LIB) << "Error" << qdebug;
qCInfo(LOG_ESS) << "Error" << qdebug;
QString qoutput = QTextCodec::codecForMib(106)
->toUnicode(m_process->readAllStandardOutput())
.trimmed();
qCInfo(LOG_LIB) << "Output" << qoutput;
qCInfo(LOG_ESS) << "Output" << qoutput;
if (m_device == QString("nvidia")) {
for (auto str : qoutput.split(QChar('\n'), QString::SkipEmptyParts)) {

View File

@ -30,6 +30,7 @@ class GPUTemperatureSource : public AbstractExtSysMonSource
public:
explicit GPUTemperatureSource(QObject *parent, const QStringList args);
virtual ~GPUTemperatureSource();
static QString autoGpu();
QVariant data(QString source);
QVariantMap initialData(QString source) const;
void run();

View File

@ -18,6 +18,7 @@
#include "hddtempsource.h"
#include <QDir>
#include <QProcess>
#include <QTextCodec>
@ -29,13 +30,13 @@ HDDTemperatureSource::HDDTemperatureSource(QObject *parent,
: AbstractExtSysMonSource(parent, args)
{
Q_ASSERT(args.count() == 2);
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
m_devices = args.at(0).split(QChar(','), QString::SkipEmptyParts);
m_cmd = args.at(1);
m_smartctl = m_cmd.contains(QString("smartctl"));
qCInfo(LOG_ESM) << "Parse as smartctl" << m_smartctl;
qCInfo(LOG_ESS) << "Parse as smartctl" << m_smartctl;
for (auto device : m_devices) {
m_processes[device] = new QProcess(nullptr);
@ -53,7 +54,7 @@ HDDTemperatureSource::HDDTemperatureSource(QObject *parent,
HDDTemperatureSource::~HDDTemperatureSource()
{
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
for (auto device : m_devices) {
m_processes[device]->kill();
@ -62,9 +63,22 @@ HDDTemperatureSource::~HDDTemperatureSource()
}
QStringList HDDTemperatureSource::allHdd()
{
QStringList allDevices
= QDir(QString("/dev")).entryList(QDir::System, QDir::Name);
QStringList devices = allDevices.filter(QRegExp(QString("^[hms]d[a-z]$")));
for (int i = 0; i < devices.count(); i++)
devices[i] = QString("/dev/%1").arg(devices.at(i));
qCInfo(LOG_ESS) << "Device list" << devices;
return devices;
}
QVariant HDDTemperatureSource::data(QString source)
{
qCDebug(LOG_ESM) << "Source" << source;
qCDebug(LOG_ESS) << "Source" << source;
QString device = source.remove(QString("hdd/temperature"));
// run cmd
@ -77,7 +91,7 @@ QVariant HDDTemperatureSource::data(QString source)
QVariantMap HDDTemperatureSource::initialData(QString source) const
{
qCDebug(LOG_ESM) << "Source" << source;
qCDebug(LOG_ESS) << "Source" << source;
QString device = source.remove(QString("hdd/temperature"));
QVariantMap data;
@ -103,23 +117,24 @@ QStringList HDDTemperatureSource::sources() const
void HDDTemperatureSource::updateValue(const QString &device)
{
qCDebug(LOG_LIB) << "Called with device" << device;
qCDebug(LOG_ESS) << "Called with device" << device;
qCInfo(LOG_LIB) << "Cmd returns" << m_processes[device]->exitCode();
qCInfo(LOG_ESS) << "Cmd returns" << m_processes[device]->exitCode();
QString qdebug
= QTextCodec::codecForMib(106)
->toUnicode(m_processes[device]->readAllStandardError())
.trimmed();
qCInfo(LOG_LIB) << "Error" << qdebug;
qCInfo(LOG_ESS) << "Error" << qdebug;
QString qoutput
= QTextCodec::codecForMib(106)
->toUnicode(m_processes[device]->readAllStandardOutput())
.trimmed();
qCInfo(LOG_LIB) << "Output" << qoutput;
qCInfo(LOG_ESS) << "Output" << qoutput;
// parse
if (m_smartctl) {
for (auto str : qoutput.split(QChar('\n'), QString::SkipEmptyParts)) {
QStringList lines = qoutput.split(QChar('\n'), QString::SkipEmptyParts);
for (auto str : lines) {
if (!str.startsWith(QString("194")))
continue;
if (str.split(QChar(' '), QString::SkipEmptyParts).count() < 9)
@ -130,11 +145,13 @@ void HDDTemperatureSource::updateValue(const QString &device)
break;
}
} else {
if (qoutput.split(QChar(':'), QString::SkipEmptyParts).count() >= 3) {
QString temp
= qoutput.split(QChar(':'), QString::SkipEmptyParts).at(2);
QStringList lines = qoutput.split(QChar(':'), QString::SkipEmptyParts);
if (lines.count() >= 3) {
QString temp = lines.at(2);
temp.remove(QChar(0260)).remove(QChar('C'));
m_values[device] = temp.toFloat();
}
}
emit(dataReceived(m_values));
}

View File

@ -30,6 +30,7 @@ class HDDTemperatureSource : public AbstractExtSysMonSource
public:
explicit HDDTemperatureSource(QObject *parent, const QStringList args);
virtual ~HDDTemperatureSource();
static QStringList allHdd();
QVariant data(QString source);
QVariantMap initialData(QString source) const;
void run(){};

View File

@ -25,19 +25,19 @@ LoadSource::LoadSource(QObject *parent, const QStringList args)
: AbstractExtSysMonSource(parent, args)
{
Q_ASSERT(args.count() == 0);
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
}
LoadSource::~LoadSource()
{
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
}
QVariant LoadSource::data(QString source)
{
qCDebug(LOG_ESM) << "Source" << source;
qCDebug(LOG_ESS) << "Source" << source;
source.remove(QString("load/load"));
return source.toInt();
@ -46,7 +46,7 @@ QVariant LoadSource::data(QString source)
QVariantMap LoadSource::initialData(QString source) const
{
qCDebug(LOG_ESM) << "Source" << source;
qCDebug(LOG_ESS) << "Source" << source;
QVariantMap data;
if (source.startsWith(QString("load/load"))) {

View File

@ -27,25 +27,25 @@ NetworkSource::NetworkSource(QObject *parent, const QStringList args)
: AbstractExtSysMonSource(parent, args)
{
Q_ASSERT(args.count() == 0);
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
}
NetworkSource::~NetworkSource()
{
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
}
QVariant NetworkSource::data(QString source)
{
qCDebug(LOG_ESM) << "Source" << source;
qCDebug(LOG_ESS) << "Source" << source;
if (source == QString("network/current/name")) {
QString device = QString("lo");
QList<QNetworkInterface> rawInterfaceList
= QNetworkInterface::allInterfaces();
qCInfo(LOG_ESM) << "Devices" << rawInterfaceList;
qCInfo(LOG_ESS) << "Devices" << rawInterfaceList;
for (auto interface : rawInterfaceList) {
if ((interface.flags().testFlag(QNetworkInterface::IsLoopBack))
|| (interface.flags().testFlag(
@ -65,7 +65,7 @@ QVariant NetworkSource::data(QString source)
QVariantMap NetworkSource::initialData(QString source) const
{
qCDebug(LOG_ESM) << "Source" << source;
qCDebug(LOG_ESS) << "Source" << source;
QVariantMap data;
if (source == QString("network/current/name")) {

View File

@ -32,7 +32,7 @@ PlayerSource::PlayerSource(QObject *parent, const QStringList args)
: AbstractExtSysMonSource(parent, args)
{
Q_ASSERT(args.count() == 5);
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
m_player = args.at(0);
m_mpdAddress = QString("%1:%2").arg(args.at(1)).arg(args.at(2));
@ -52,7 +52,7 @@ PlayerSource::PlayerSource(QObject *parent, const QStringList args)
PlayerSource::~PlayerSource()
{
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
m_mpdProcess->kill();
m_mpdProcess->deleteLater();
@ -61,7 +61,7 @@ PlayerSource::~PlayerSource()
QVariant PlayerSource::data(QString source)
{
qCDebug(LOG_ESM) << "Source" << source;
qCDebug(LOG_ESS) << "Source" << source;
if (!m_values.contains(source))
run();
@ -72,7 +72,7 @@ QVariant PlayerSource::data(QString source)
QVariantMap PlayerSource::initialData(QString source) const
{
qCDebug(LOG_ESM) << "Source" << source;
qCDebug(LOG_ESS) << "Source" << source;
QVariantMap data;
if (source == QString("player/album")) {
@ -214,15 +214,15 @@ QStringList PlayerSource::sources() const
void PlayerSource::updateValue()
{
qCInfo(LOG_LIB) << "Cmd returns" << m_mpdProcess->exitCode();
qCInfo(LOG_ESS) << "Cmd returns" << m_mpdProcess->exitCode();
QString qdebug = QTextCodec::codecForMib(106)
->toUnicode(m_mpdProcess->readAllStandardError())
.trimmed();
qCInfo(LOG_LIB) << "Error" << qdebug;
qCInfo(LOG_ESS) << "Error" << qdebug;
QString qoutput = QTextCodec::codecForMib(106)
->toUnicode(m_mpdProcess->readAllStandardOutput())
.trimmed();
qCInfo(LOG_LIB) << "Output" << qoutput;
qCInfo(LOG_ESS) << "Output" << qoutput;
for (auto str : qoutput.split(QChar('\n'), QString::SkipEmptyParts)) {
if (str.split(QString(": "), QString::SkipEmptyParts).count() == 2) {
@ -270,7 +270,7 @@ QString PlayerSource::getAutoMpris() const
for (auto arg : arguments) {
if (!arg.startsWith(QString("org.mpris.MediaPlayer2.")))
continue;
qCInfo(LOG_ESM) << "Service found" << arg;
qCInfo(LOG_ESS) << "Service found" << arg;
QString service = arg;
service.remove(QString("org.mpris.MediaPlayer2."));
return service;
@ -282,13 +282,13 @@ QString PlayerSource::getAutoMpris() const
QVariantHash PlayerSource::getPlayerMpdInfo(const QString mpdAddress) const
{
qCDebug(LOG_ESM) << "MPD" << mpdAddress;
qCDebug(LOG_ESS) << "MPD" << mpdAddress;
// build cmd
QString cmd = QString("bash -c \"echo 'currentsong\nstatus\nclose' | curl "
"--connect-timeout 1 -fsm 3 telnet://%1\"")
.arg(mpdAddress);
qCInfo(LOG_ESM) << "cmd" << cmd;
qCInfo(LOG_ESS) << "cmd" << cmd;
m_mpdProcess->start(cmd);
return m_mpdCached;
@ -297,7 +297,7 @@ QVariantHash PlayerSource::getPlayerMpdInfo(const QString mpdAddress) const
QVariantHash PlayerSource::getPlayerMprisInfo(const QString mpris) const
{
qCDebug(LOG_ESM) << "MPRIS" << mpris;
qCDebug(LOG_ESS) << "MPRIS" << mpris;
QVariantHash info = defaultInfo();
if (mpris.isEmpty())
@ -322,7 +322,7 @@ QVariantHash PlayerSource::getPlayerMprisInfo(const QString mpris) const
QDBusMessage response = bus.call(request, QDBus::BlockWithGui);
if ((response.type() != QDBusMessage::ReplyMessage)
|| (response.arguments().isEmpty())) {
qCWarning(LOG_ESM) << "Error message" << response.errorMessage();
qCWarning(LOG_ESS) << "Error message" << response.errorMessage();
} else {
// another portion of dirty magic
QVariantHash map
@ -348,7 +348,7 @@ QVariantHash PlayerSource::getPlayerMprisInfo(const QString mpris) const
response = bus.call(request, QDBus::BlockWithGui);
if ((response.type() != QDBusMessage::ReplyMessage)
|| (response.arguments().isEmpty())) {
qCWarning(LOG_ESM) << "Error message" << response.errorMessage();
qCWarning(LOG_ESS) << "Error message" << response.errorMessage();
} else {
// this cast is simpler than the previous one ;)
info[QString("player/progress")] = response.arguments()
@ -366,7 +366,7 @@ QVariantHash PlayerSource::getPlayerMprisInfo(const QString mpris) const
QString PlayerSource::buildString(const QString current, const QString value,
const int s) const
{
qCDebug(LOG_ESM) << "Current value" << current << "received" << value
qCDebug(LOG_ESS) << "Current value" << current << "received" << value
<< "will be stripped after" << s;
int index = value.indexOf(current);
@ -379,7 +379,7 @@ QString PlayerSource::buildString(const QString current, const QString value,
QString PlayerSource::stripString(const QString value, const int s) const
{
qCDebug(LOG_ESM) << "New value" << value << "will be stripped after" << s;
qCDebug(LOG_ESS) << "New value" << value << "will be stripped after" << s;
return value.count() > s ? QString("%1\u2026").arg(value.left(s - 1))
: value.leftJustified(s, QLatin1Char(' '));

View File

@ -27,19 +27,19 @@ ProcessesSource::ProcessesSource(QObject *parent, const QStringList args)
: AbstractExtSysMonSource(parent, args)
{
Q_ASSERT(args.count() == 0);
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
}
ProcessesSource::~ProcessesSource()
{
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
}
QVariant ProcessesSource::data(QString source)
{
qCDebug(LOG_ESM) << "Source" << source;
qCDebug(LOG_ESS) << "Source" << source;
if (!m_values.contains(source))
run();
@ -50,7 +50,7 @@ QVariant ProcessesSource::data(QString source)
QVariantMap ProcessesSource::initialData(QString source) const
{
qCDebug(LOG_ESM) << "Source" << source;
qCDebug(LOG_ESS) << "Source" << source;
QVariantMap data;
if (source == QString("ps/running/count")) {

View File

@ -26,7 +26,7 @@ QuotesSource::QuotesSource(QObject *parent, const QStringList args)
: AbstractExtSysMonSource(parent, args)
{
Q_ASSERT(args.count() == 0);
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
extQuotes = new ExtItemAggregator<ExtQuotes>(nullptr, QString("quotes"));
m_sources = getSources();
@ -35,7 +35,7 @@ QuotesSource::QuotesSource(QObject *parent, const QStringList args)
QuotesSource::~QuotesSource()
{
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
delete extQuotes;
}
@ -43,7 +43,7 @@ QuotesSource::~QuotesSource()
QVariant QuotesSource::data(QString source)
{
qCDebug(LOG_ESM) << "Source" << source;
qCDebug(LOG_ESS) << "Source" << source;
int ind = index(source);
source.remove(QString("quotes/"));
@ -59,7 +59,7 @@ QVariant QuotesSource::data(QString source)
QVariantMap QuotesSource::initialData(QString source) const
{
qCDebug(LOG_ESM) << "Source" << source;
qCDebug(LOG_ESS) << "Source" << source;
int ind = index(source);
QVariantMap data;

View File

@ -26,7 +26,7 @@ UpgradeSource::UpgradeSource(QObject *parent, const QStringList args)
: AbstractExtSysMonSource(parent, args)
{
Q_ASSERT(args.count() == 0);
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
extUpgrade = new ExtItemAggregator<ExtUpgrade>(nullptr, QString("upgrade"));
m_sources = getSources();
@ -35,7 +35,7 @@ UpgradeSource::UpgradeSource(QObject *parent, const QStringList args)
UpgradeSource::~UpgradeSource()
{
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
delete extUpgrade;
}
@ -43,7 +43,7 @@ UpgradeSource::~UpgradeSource()
QVariant UpgradeSource::data(QString source)
{
qCDebug(LOG_ESM) << "Source" << source;
qCDebug(LOG_ESS) << "Source" << source;
// there are only one value
return extUpgrade->itemByTagNumber(index(source))->run().values().first();
@ -52,7 +52,7 @@ QVariant UpgradeSource::data(QString source)
QVariantMap UpgradeSource::initialData(QString source) const
{
qCDebug(LOG_ESM) << "Source" << source;
qCDebug(LOG_ESS) << "Source" << source;
QVariantMap data;
data[QString("min")] = QString("");

View File

@ -26,7 +26,7 @@ WeatherSource::WeatherSource(QObject *parent, const QStringList args)
: AbstractExtSysMonSource(parent, args)
{
Q_ASSERT(args.count() == 0);
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
extWeather = new ExtItemAggregator<ExtWeather>(nullptr, QString("weather"));
m_sources = getSources();
@ -35,7 +35,7 @@ WeatherSource::WeatherSource(QObject *parent, const QStringList args)
WeatherSource::~WeatherSource()
{
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
delete extWeather;
}
@ -43,7 +43,7 @@ WeatherSource::~WeatherSource()
QVariant WeatherSource::data(QString source)
{
qCDebug(LOG_ESM) << "Source" << source;
qCDebug(LOG_ESS) << "Source" << source;
int ind = index(source);
source.remove(QString("weather/"));
@ -59,7 +59,7 @@ QVariant WeatherSource::data(QString source)
QVariantMap WeatherSource::initialData(QString source) const
{
qCDebug(LOG_ESM) << "Source" << source;
qCDebug(LOG_ESS) << "Source" << source;
int ind = index(source);
QVariantMap data;

View File

@ -7,6 +7,7 @@ include_directories(
${CMAKE_SOURCE_DIR}
${CMAKE_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../${PROJECT_LIBRARY}/
${CMAKE_CURRENT_SOURCE_DIR}/../${PROJECT_MONITORSOURCES}/
${PROJECT_TRDPARTY_DIR}
${Qt_INCLUDE}
${Qt5Test_INCLUDE_DIRS}
@ -18,13 +19,14 @@ set(AWTESTLIBRARY_HEADERS awtestlibrary.h)
set(AWTESTLIBRARY_SOURCES awtestlibrary.cpp)
add_library(${SUBPROJECT}-awtest STATIC ${AWTESTLIBRARY_SOURCES} ${AWTESTLIBRARY_HEADERS})
target_link_libraries(${SUBPROJECT}-awtest ${Qt_LIBRARIES} ${Qt5Test_LIBRARIES})
set(LIBRARY_TEST_SET ${SUBPROJECT}-awtest ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Qt5Test_LIBRARIES})
set(LIBRARY_TEST_SET ${SUBPROJECT}-awtest ${PROJECT_LIBRARY} ${PROJECT_MONITORSOURCES} ${Qt_LIBRARIES} ${Qt5Test_LIBRARIES})
## modules
set(TEST_MODULES
abstractextitem extquotes extscript extupgrade extweather
abstractformatter datetimeformatter floatformatter noformatter scriptformatter
extitemaggregator)
extitemaggregator
hddtempsource)
foreach (TEST_MODULE ${TEST_MODULES})
set(${TEST_MODULE}_HEADERS test${TEST_MODULE}.h)
set(${TEST_MODULE}_SOURCES test${TEST_MODULE}.cpp)

View File

@ -21,8 +21,9 @@
#include <QObject>
class AWNoFormatter;
template<class T> class ExtItemAggregator;
template <class T> class ExtItemAggregator;
class TestExtItemAggregator : public QObject
{

View File

@ -123,13 +123,13 @@ void TestExtWeather::run()
QWARN("May fail here for Yahoo! Weather, see "
"https://yahoo.uservoice.com/forums/207813-us-weather/suggestions/"
"14209233-invalid-pressure-calculation");
QVERIFY((arguments[extWeather->tag(QString("pressure"))].toFloat()
QVERIFY((arguments[extWeather->tag(QString("pressure"))].toInt()
> pressure.first)
&& (arguments[extWeather->tag(QString("pressure"))].toInt()
< pressure.second));
QVERIFY((arguments[extWeather->tag(QString("temperature"))].toFloat()
> temp.first)
&& (arguments[extWeather->tag(QString("temperature"))].toInt()
&& (arguments[extWeather->tag(QString("temperature"))].toFloat()
< temp.second));
// image should be only one symbol here
QCOMPARE(arguments[extWeather->tag(QString("weather"))].toString().count(),

View File

@ -0,0 +1,91 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#include "testhddtempsource.h"
#include <QtTest>
#include "awtestlibrary.h"
#include "hddtempsource.h"
void TestHDDTemperatureSource::initTestCase()
{
devices = HDDTemperatureSource::allHdd();
QVERIFY(devices.count() > 0);
hddtempSource = new HDDTemperatureSource(
this, QStringList() << devices.join(QChar(',')) << hddtempCmd);
smartctlSource = new HDDTemperatureSource(
this, QStringList() << devices.join(QChar(',')) << smartctlCmd);
}
void TestHDDTemperatureSource::cleanupTestCase()
{
delete hddtempSource;
delete smartctlSource;
}
void TestHDDTemperatureSource::test_sources()
{
std::for_each(devices.begin(), devices.end(), [](QString &device) {
device.prepend(QString("hdd/temperature"));
});
QCOMPARE(hddtempSource->sources(), devices);
QCOMPARE(smartctlSource->sources(), devices);
}
void TestHDDTemperatureSource::test_hddtemp()
{
std::for_each(devices.begin(), devices.end(), [this](QString device) {
QSignalSpy spy(hddtempSource,
SIGNAL(dataReceived(const QVariantHash &)));
float firstValue = hddtempSource->data(device).toFloat();
QCOMPARE(firstValue, 0.0f);
QVERIFY(spy.wait(5000));
QVariantHash arguments = spy.takeFirst().at(0).toHash();
device.remove(QString("hdd/temperature"));
float secondValue = arguments[device].toFloat();
QVERIFY((secondValue >= temp.first) && (secondValue <= temp.second));
});
}
void TestHDDTemperatureSource::test_smartctl()
{
std::for_each(devices.begin(), devices.end(), [this](QString &device) {
QSignalSpy spy(smartctlSource,
SIGNAL(dataReceived(const QVariantHash &)));
float firstValue = smartctlSource->data(device).toFloat();
QCOMPARE(firstValue, 0.0f);
QVERIFY(spy.wait(5000));
QVariantHash arguments = spy.takeFirst().at(0).toHash();
device.remove(QString("hdd/temperature"));
float secondValue = arguments[device].toFloat();
QVERIFY((secondValue >= temp.first) && (secondValue <= temp.second));
});
}
QTEST_MAIN(TestHDDTemperatureSource);

View File

@ -0,0 +1,50 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#ifndef TESTHDDTEMPSOURCE_H
#define TESTHDDTEMPSOURCE_H
#include <QObject>
class HDDTemperatureSource;
class TestHDDTemperatureSource : public QObject
{
Q_OBJECT
private slots:
// initialization
void initTestCase();
void cleanupTestCase();
// test
void test_sources();
void test_hddtemp();
void test_smartctl();
private:
HDDTemperatureSource *hddtempSource = nullptr;
HDDTemperatureSource *smartctlSource = nullptr;
QStringList devices;
QString hddtempCmd = QString("sudo hddtemp");
QString smartctlCmd = QString("sudo smartctl -a");
QPair<float, float> temp = QPair<float, float>(0.0f, 40.0f);
};
#endif /* TESTHDDTEMPSOURCE_H */