some refactoring

* fix undefinded behaviour
* drop dbus timout, use generic timeout insead
* drop load source to own cmake key
* update contributing.md
This commit is contained in:
Evgenii Alekseev 2016-06-30 01:59:06 +03:00
parent 5cd5272f10
commit 8e8ac2f3c7
15 changed files with 75 additions and 65 deletions

View File

@ -54,7 +54,14 @@ for more details. To avoid manual labor there is automatic cmake target named
``` ```
* C-like `NULL`, use `nullptr` instead. * C-like `NULL`, use `nullptr` instead.
* It is highly recommended to avoid implicit casts. * It is highly recommended to avoid implicit casts. Exception `nullptr` casts to
boolean, e.g.:
```
if (nullptr)
qDebug() << "nullptr is true, wtf";
```
* Abstract classes (which have at least one pure virtual method) are allowed. * Abstract classes (which have at least one pure virtual method) are allowed.
* Templates are allowed and recommended. Templates usually should be described * Templates are allowed and recommended. Templates usually should be described
inside header not source code file. inside header not source code file.

View File

@ -34,6 +34,7 @@ option(BUILD_DEB_PACKAGE "Build deb package" OFF)
option(BUILD_RPM_PACKAGE "Build rpm package" OFF) option(BUILD_RPM_PACKAGE "Build rpm package" OFF)
# build details # build details
option(BUILD_FUTURE "Build with the features which will be marked as stable later" OFF) option(BUILD_FUTURE "Build with the features which will be marked as stable later" OFF)
option(BUILD_LOAD "Build with additional load" OFF)
option(BUILD_TESTING "Build with additional test abilities" OFF) option(BUILD_TESTING "Build with additional test abilities" OFF)
# generate changelog # generate changelog

View File

@ -47,6 +47,7 @@ const QStringList getBuildData()
metadata.append(QString(" AWEUAPI: %1").arg(AWEUAPI)); metadata.append(QString(" AWEUAPI: %1").arg(AWEUAPI));
metadata.append(QString(" AWEWAPI: %1").arg(AWEWAPI)); metadata.append(QString(" AWEWAPI: %1").arg(AWEWAPI));
metadata.append(QString(" AWEFAPI: %1").arg(AWEFAPI)); metadata.append(QString(" AWEFAPI: %1").arg(AWEFAPI));
metadata.append(QString(" REQUEST_TIMEOUT: %1").arg(REQUEST_TIMEOUT));
metadata.append(QString(" TIME_KEYS: %1").arg(TIME_KEYS)); metadata.append(QString(" TIME_KEYS: %1").arg(TIME_KEYS));
metadata.append(QString(" STATIC_KEYS: %1").arg(STATIC_KEYS)); metadata.append(QString(" STATIC_KEYS: %1").arg(STATIC_KEYS));
// cmake properties // cmake properties
@ -89,6 +90,7 @@ const QStringList getBuildData()
QString(" CPPCHECK_EXECUTABLE: %1").arg(CPPCHECK_EXECUTABLE)); QString(" CPPCHECK_EXECUTABLE: %1").arg(CPPCHECK_EXECUTABLE));
// additional functions // additional functions
metadata.append(QString(" PROP_FUTURE: %1").arg(PROP_FUTURE)); metadata.append(QString(" PROP_FUTURE: %1").arg(PROP_FUTURE));
metadata.append(QString(" PROP_LOAD: %1").arg(PROP_LOAD));
metadata.append(QString(" PROP_TEST: %1").arg(PROP_TEST)); metadata.append(QString(" PROP_TEST: %1").arg(PROP_TEST));
return metadata; return metadata;

View File

@ -42,7 +42,6 @@ void AWDataEngineAggregator::clear()
disconnectSources(); disconnectSources();
m_dataEngines.clear(); m_dataEngines.clear();
delete m_consumer; delete m_consumer;
m_consumer = nullptr;
} }
@ -82,7 +81,7 @@ void AWDataEngineAggregator::dropSource(const QString source)
{ {
qCDebug(LOG_AW) << "Source" << source; qCDebug(LOG_AW) << "Source" << source;
// FIXME there is no possibility to check to which dataengine source // HACK there is no possibility to check to which dataengine source
// connected we will try to disconnect it from systemmonitor and extsysmon // connected we will try to disconnect it from systemmonitor and extsysmon
m_dataEngines[QString("systemmonitor")]->disconnectSource(source, parent()); m_dataEngines[QString("systemmonitor")]->disconnectSource(source, parent());
m_dataEngines[QString("extsysmon")]->disconnectSource(source, parent()); m_dataEngines[QString("extsysmon")]->disconnectSource(source, parent());

View File

@ -38,8 +38,8 @@ bool AWKeyCache::addKeyToCache(const QString type, const QString key)
cache.beginGroup(type); cache.beginGroup(type);
QStringList cachedValues; QStringList cachedValues;
for (auto key : cache.allKeys()) for (auto number : cache.allKeys())
cachedValues.append(cache.value(key).toString()); cachedValues.append(cache.value(number).toString());
if (type == QString("hdd")) { if (type == QString("hdd")) {
QStringList allDevices QStringList allDevices
@ -51,6 +51,7 @@ bool AWKeyCache::addKeyToCache(const QString type, const QString key)
if (cachedValues.contains(device)) if (cachedValues.contains(device))
continue; continue;
qCInfo(LOG_AW) << "Found new key" << device << "for type" << type; qCInfo(LOG_AW) << "Found new key" << device << "for type" << type;
cachedValues.append(device);
cache.setValue( cache.setValue(
QString("%1").arg(cache.allKeys().count(), 3, 10, QChar('0')), QString("%1").arg(cache.allKeys().count(), 3, 10, QChar('0')),
device); device);
@ -63,6 +64,7 @@ bool AWKeyCache::addKeyToCache(const QString type, const QString key)
if (cachedValues.contains(device)) if (cachedValues.contains(device))
continue; continue;
qCInfo(LOG_AW) << "Found new key" << device << "for type" << type; qCInfo(LOG_AW) << "Found new key" << device << "for type" << type;
cachedValues.append(device);
cache.setValue( cache.setValue(
QString("%1").arg(cache.allKeys().count(), 3, 10, QChar('0')), QString("%1").arg(cache.allKeys().count(), 3, 10, QChar('0')),
device); device);

View File

@ -191,43 +191,53 @@ QString AWKeyOperations::infoByKey(QString key) const
QString stripped = key; QString stripped = key;
stripped.remove(QRegExp(QString("\\d+"))); stripped.remove(QRegExp(QString("\\d+")));
QString output;
QString output = QString("(none)"); if (key.startsWith(QString("bar"))) {
AbstractExtItem *item = graphicalItems->itemByTag(key, stripped);
// FIXME undefined behaviour if (item)
if (key.startsWith(QString("bar"))) output = item->uniq();
return graphicalItems->itemByTag(key, stripped)->uniq(); } else if (key.startsWith(QString("custom"))) {
else if (key.startsWith(QString("custom"))) AbstractExtItem *item = extScripts->itemByTag(key, stripped);
return extScripts->itemByTag(key, stripped)->uniq(); if (item)
else if (key.contains(QRegExp(QString("^hdd[rw]")))) output = item->uniq();
return QString("%1").arg( } else if (key.contains(QRegExp(QString("^hdd[rw]")))) {
m_devices[QString("disk")] output = m_devices[QString("disk")]
[key.remove(QRegExp(QString("hdd[rw]"))).toInt()]); [key.remove(QRegExp(QString("hdd[rw]"))).toInt()];
else if (key.contains(QRegExp( } else if (key.contains(QRegExp(
QString("^hdd([0-9]|mb|gb|freemb|freegb|totmb|totgb)")))) QString("^hdd([0-9]|mb|gb|freemb|freegb|totmb|totgb)")))) {
return QString("%1").arg( output
m_devices[QString("mount")] = m_devices[QString("mount")]
[key [key
.remove(QRegExp(QString( .remove(QRegExp(QString(
"^hdd([0-9]|mb|gb|freemb|freegb|totmb|totgb)"))) "^hdd([0-9]|mb|gb|freemb|freegb|totmb|totgb)")))
.toInt()]); .toInt()];
else if (key.startsWith(QString("hddtemp"))) } else if (key.startsWith(QString("hddtemp"))) {
return QString("%1").arg( output
m_devices[QString("hdd")][key.remove(QString("hddtemp")).toInt()]); = m_devices[QString("hdd")][key.remove(QString("hddtemp")).toInt()];
else if (key.contains(QRegExp(QString("^(down|up)[0-9]")))) } else if (key.contains(QRegExp(QString("^(down|up)[0-9]")))) {
return QString("%1").arg( output = m_devices[QString("net")]
m_devices[QString("net")] [key.remove(QRegExp(QString("^(down|up)"))).toInt()];
[key.remove(QRegExp(QString("^(down|up)"))).toInt()]); } else if (key.startsWith(QString("pkgcount"))) {
else if (key.startsWith(QString("pkgcount"))) AbstractExtItem *item = extUpgrade->itemByTag(key, stripped);
return extUpgrade->itemByTag(key, stripped)->uniq(); if (item)
else if (key.contains(QRegExp(QString("(^|perc)(ask|bid|price)(chg|)")))) output = item->uniq();
return extQuotes->itemByTag(key, stripped)->uniq(); } else if (key.contains(
else if (key.contains(QRegExp( QRegExp(QString("(^|perc)(ask|bid|price)(chg|)")))) {
QString("(weather|weatherId|humidity|pressure|temperature)")))) AbstractExtItem *item = extQuotes->itemByTag(key, stripped);
return extWeather->itemByTag(key, stripped)->uniq(); if (item)
else if (key.startsWith(QString("temp"))) output = item->uniq();
return QString("%1").arg( } else if (key.contains(QRegExp(QString(
m_devices[QString("temp")][key.remove(QString("temp")).toInt()]); "(weather|weatherId|humidity|pressure|temperature)")))) {
AbstractExtItem *item = extWeather->itemByTag(key, stripped);
if (item)
output = item->uniq();
} else if (key.startsWith(QString("temp"))) {
output
= m_devices[QString("temp")][key.remove(QString("temp")).toInt()];
} else {
output = QString("(none)");
}
return output; return output;
} }

View File

@ -515,7 +515,7 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
} else if (source.startsWith(QString("lmsensors/"))) { } else if (source.startsWith(QString("lmsensors/"))) {
// temperature // temperature
int index = m_devices[QString("temp")].indexOf(source); int index = m_devices[QString("temp")].indexOf(source);
// FIXME on DE initialization there are no units key // HACK on DE initialization there are no units key
if (units.isEmpty()) if (units.isEmpty())
return QStringList() << QString("temp%1").arg(index); return QStringList() << QString("temp%1").arg(index);
if (index > -1) { if (index > -1) {

View File

@ -66,7 +66,7 @@ void AbstractExtItemAggregator::copyItem()
.arg(QStandardPaths::writableLocation( .arg(QStandardPaths::writableLocation(
QStandardPaths::GenericDataLocation)) QStandardPaths::GenericDataLocation))
.arg(m_type); .arg(m_type);
if ((source == nullptr) || (fileName.isEmpty())) { if ((!source) || (fileName.isEmpty())) {
qCWarning(LOG_LIB) << "Nothing to copy"; qCWarning(LOG_LIB) << "Nothing to copy";
return; return;
} }
@ -83,7 +83,7 @@ void AbstractExtItemAggregator::copyItem()
void AbstractExtItemAggregator::deleteItem() void AbstractExtItemAggregator::deleteItem()
{ {
AbstractExtItem *source = itemFromWidget(); AbstractExtItem *source = itemFromWidget();
if (source == nullptr) { if (!source) {
qCWarning(LOG_LIB) << "Nothing to delete"; qCWarning(LOG_LIB) << "Nothing to delete";
return; return;
}; };
@ -98,7 +98,7 @@ void AbstractExtItemAggregator::deleteItem()
void AbstractExtItemAggregator::editItem() void AbstractExtItemAggregator::editItem()
{ {
AbstractExtItem *source = itemFromWidget(); AbstractExtItem *source = itemFromWidget();
if (source == nullptr) { if (!source) {
qCWarning(LOG_LIB) << "Nothing to edit"; qCWarning(LOG_LIB) << "Nothing to edit";
return; return;
}; };
@ -128,7 +128,7 @@ QString AbstractExtItemAggregator::getName()
AbstractExtItem *AbstractExtItemAggregator::itemFromWidget() AbstractExtItem *AbstractExtItemAggregator::itemFromWidget()
{ {
QListWidgetItem *widgetItem = ui->listWidget->currentItem(); QListWidgetItem *widgetItem = ui->listWidget->currentItem();
if (widgetItem == nullptr) if (!widgetItem)
return nullptr; return nullptr;
AbstractExtItem *found = nullptr; AbstractExtItem *found = nullptr;
@ -139,7 +139,7 @@ AbstractExtItem *AbstractExtItemAggregator::itemFromWidget()
found = item; found = item;
break; break;
} }
if (found == nullptr) if (!found)
qCWarning(LOG_LIB) << "Could not find item by name" qCWarning(LOG_LIB) << "Could not find item by name"
<< widgetItem->text(); << widgetItem->text();

View File

@ -148,10 +148,10 @@ void ExtSysMonAggregator::init(const QHash<QString, QString> config)
= new WeatherSource(this, QStringList()); = new WeatherSource(this, QStringList());
for (auto source : weatherItem->sources()) for (auto source : weatherItem->sources())
m_map[source] = weatherItem; m_map[source] = weatherItem;
#ifdef BUILD_TESTING #ifdef BUILD_LOAD
// additional load source // additional load source
AbstractExtSysMonSource *loadItem = new LoadSource(this, QStringList()); AbstractExtSysMonSource *loadItem = new LoadSource(this, QStringList());
for (auto source : loadItem->sources()) for (auto source : loadItem->sources())
m_map[source] = loadItem; m_map[source] = loadItem;
#endif /* BUILD_TESTING */ #endif /* BUILD_LOAD */
} }

View File

@ -345,7 +345,7 @@ QVariantHash PlayerSource::getPlayerMprisInfo(const QString mpris) const
QString("/org/mpris/MediaPlayer2"), QString(""), QString("Get")); QString("/org/mpris/MediaPlayer2"), QString(""), QString("Get"));
request.setArguments(args); request.setArguments(args);
QDBusMessage response QDBusMessage response
= bus.call(request, QDBus::BlockWithGui, DBUS_CALL_TIMEOUT); = bus.call(request, QDBus::BlockWithGui, REQUEST_TIMEOUT);
if ((response.type() != QDBusMessage::ReplyMessage) if ((response.type() != QDBusMessage::ReplyMessage)
|| (response.arguments().isEmpty())) { || (response.arguments().isEmpty())) {
qCWarning(LOG_ESS) << "Error message" << response.errorMessage(); qCWarning(LOG_ESS) << "Error message" << response.errorMessage();

View File

@ -24,10 +24,6 @@
#include "abstractextsysmonsource.h" #include "abstractextsysmonsource.h"
#ifndef DBUS_CALL_TIMEOUT
#define DBUS_CALL_TIMEOUT 3000
#endif /* DBUS_CALL_TIMEOUT */
class QProcess; class QProcess;
class PlayerSource : public AbstractExtSysMonSource class PlayerSource : public AbstractExtSysMonSource

View File

@ -95,6 +95,7 @@ void TestAWKeys::test_pattern()
plugin->initKeys(pattern, interval, 0, false); plugin->initKeys(pattern, interval, 0, false);
QSignalSpy spy(plugin, SIGNAL(needTextToBeUpdated(const QString))); QSignalSpy spy(plugin, SIGNAL(needTextToBeUpdated(const QString)));
QVERIFY(spy.wait(5 * interval));
QVERIFY(spy.wait(5 * interval)); QVERIFY(spy.wait(5 * interval));
QString text = spy.takeFirst().at(0).toString(); QString text = spy.takeFirst().at(0).toString();

View File

@ -39,11 +39,6 @@ void TestDesktopSource::cleanupTestCase()
void TestDesktopSource::test_sources() void TestDesktopSource::test_sources()
{ {
QCOMPARE(source->sources().count(), 4); QCOMPARE(source->sources().count(), 4);
// FIXME there is segfault here sometimes o_0
// QVERIFY(std::all_of(
// source->sources().cbegin(), source->sources().cend(),
// [](const QString &src) { return
// src.startsWith(QString("desktop/")); }));
} }

View File

@ -39,11 +39,6 @@ void TestProcessesSource::cleanupTestCase()
void TestProcessesSource::test_sources() void TestProcessesSource::test_sources()
{ {
QCOMPARE(source->sources().count(), 3); QCOMPARE(source->sources().count(), 3);
// FIXME there is segfault here sometimes o_0
// QVERIFY(std::all_of(
// source->sources().cbegin(), source->sources().cend(),
// [](const QString &src) { return src.startsWith(QString("ps/"));
// }));
} }

View File

@ -37,7 +37,7 @@
// formatter api version // formatter api version
#define AWEFAPI 1 #define AWEFAPI 1
// network requests timeout, ms // network requests timeout, ms
#define REQUEST_TIMEOUT 5000 #define REQUEST_TIMEOUT 3000
// available time keys // available time keys
#define TIME_KEYS \ #define TIME_KEYS \
"dddd,ddd,dd,d,MMMM,MMM,MM,M,yyyy,yy,hh,h,HH,H,mm,m,ss,s,t,ap,a,AP,A" "dddd,ddd,dd,d,MMMM,MMM,MM,M,yyyy,yy,hh,h,HH,H,mm,m,ss,s,t,ap,a,AP,A"
@ -51,6 +51,7 @@
"dalbum,dartist,dtitle,salbum,sartist,stitle,pscount,pstotal,ps,desktop," \ "dalbum,dartist,dtitle,salbum,sartist,stitle,pscount,pstotal,ps,desktop," \
"ndesktop,tdesktops,la15,la5,la1" "ndesktop,tdesktops,la15,la5,la1"
#cmakedefine BUILD_FUTURE #cmakedefine BUILD_FUTURE
#cmakedefine BUILD_LOAD
#cmakedefine BUILD_TESTING #cmakedefine BUILD_TESTING
// links // links
@ -94,6 +95,7 @@
#define CPPCHECK_EXECUTABLE "@CPPCHECK_EXECUTABLE@" #define CPPCHECK_EXECUTABLE "@CPPCHECK_EXECUTABLE@"
// additional functions // additional functions
#define PROP_FUTURE "@BUILD_FUTURE@" #define PROP_FUTURE "@BUILD_FUTURE@"
#define PROP_LOAD "@BUILD_LOAD@"
#define PROP_TEST "@BUILD_TESTING@" #define PROP_TEST "@BUILD_TESTING@"