mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-07-16 07:09:58 +00:00
add tests for battery and gpuload sources
+ some tests refactoring
This commit is contained in:
@ -40,6 +40,26 @@ BatterySource::~BatterySource()
|
||||
}
|
||||
|
||||
|
||||
|
||||
QStringList BatterySource::getSources()
|
||||
{
|
||||
QStringList sources;
|
||||
sources.append(QString("battery/ac"));
|
||||
sources.append(QString("battery/bat"));
|
||||
m_batteriesCount
|
||||
= QDir(m_acpiPath)
|
||||
.entryList(QStringList() << QString("BAT*"),
|
||||
QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)
|
||||
.count();
|
||||
qCInfo(LOG_ESS) << "Init batteries count as" << m_batteriesCount;
|
||||
for (int i = 0; i < m_batteriesCount; i++)
|
||||
sources.append(QString("battery/bat%1").arg(i));
|
||||
|
||||
qCInfo(LOG_ESS) << "Sources list" << sources;
|
||||
return sources;
|
||||
}
|
||||
|
||||
|
||||
QVariant BatterySource::data(QString source)
|
||||
{
|
||||
qCDebug(LOG_ESS) << "Source" << source;
|
||||
@ -120,22 +140,3 @@ QStringList BatterySource::sources() const
|
||||
{
|
||||
return m_sources;
|
||||
}
|
||||
|
||||
|
||||
QStringList BatterySource::getSources()
|
||||
{
|
||||
QStringList sources;
|
||||
sources.append(QString("battery/ac"));
|
||||
sources.append(QString("battery/bat"));
|
||||
m_batteriesCount
|
||||
= QDir(m_acpiPath)
|
||||
.entryList(QStringList() << QString("BAT*"),
|
||||
QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)
|
||||
.count();
|
||||
qCInfo(LOG_ESS) << "Init batteries count as" << m_batteriesCount;
|
||||
for (int i = 0; i < m_batteriesCount; i++)
|
||||
sources.append(QString("battery/bat%1").arg(i));
|
||||
|
||||
qCInfo(LOG_ESS) << "Sources list" << sources;
|
||||
return sources;
|
||||
}
|
||||
|
@ -28,13 +28,13 @@ class BatterySource : public AbstractExtSysMonSource
|
||||
public:
|
||||
explicit BatterySource(QObject *parent, const QStringList args);
|
||||
virtual ~BatterySource();
|
||||
QStringList getSources();
|
||||
QVariant data(QString source);
|
||||
QVariantMap initialData(QString source) const;
|
||||
void run();
|
||||
QStringList sources() const;
|
||||
|
||||
private:
|
||||
QStringList getSources();
|
||||
// configuration and values
|
||||
int m_batteriesCount = 0;
|
||||
QString m_acpiPath;
|
||||
|
@ -77,7 +77,7 @@ QVariant GPULoadSource::data(QString source)
|
||||
if (source == QString("gpu/load"))
|
||||
run();
|
||||
|
||||
return m_value;
|
||||
return m_values[source];
|
||||
}
|
||||
|
||||
|
||||
@ -140,7 +140,7 @@ void GPULoadSource::updateValue()
|
||||
QString load = str.remove(QString("<gpu_util>"))
|
||||
.remove(QString("</gpu_util>"))
|
||||
.remove(QChar('%'));
|
||||
m_value = load.toFloat();
|
||||
m_values[QString("gpu/load")] = load.toFloat();
|
||||
break;
|
||||
}
|
||||
} else if (m_device == QString("ati")) {
|
||||
@ -150,7 +150,7 @@ void GPULoadSource::updateValue()
|
||||
QString load
|
||||
= str.split(QChar(' '), QString::SkipEmptyParts)[3].remove(
|
||||
QChar('%'));
|
||||
m_value = load.toFloat();
|
||||
m_values[QString("gpu/load")] = load.toFloat();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ private:
|
||||
// configuration and values
|
||||
QString m_device;
|
||||
QProcess *m_process = nullptr;
|
||||
QVariant m_value;
|
||||
QVariantHash m_values;
|
||||
};
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user