drop task library from build, cosmetic changes

This commit is contained in:
Evgenii Alekseev 2016-03-27 15:39:37 +03:00
parent 1187c43e57
commit b9fda3e1cd
12 changed files with 100 additions and 76 deletions

View File

@ -13,16 +13,14 @@ include_directories(
file(GLOB SUBPROJECT_DESKTOP_IN *.desktop) file(GLOB SUBPROJECT_DESKTOP_IN *.desktop)
file(RELATIVE_PATH SUBPROJECT_DESKTOP ${CMAKE_SOURCE_DIR} ${SUBPROJECT_DESKTOP_IN}) file(RELATIVE_PATH SUBPROJECT_DESKTOP ${CMAKE_SOURCE_DIR} ${SUBPROJECT_DESKTOP_IN})
file(GLOB SUBPROJECT_SOURCE *.cpp sources/*.cpp ${PROJECT_TRDPARTY_DIR}/task/*.cpp ${CMAKE_SOURCE_DIR}/*.cpp) file(GLOB SUBPROJECT_SOURCE *.cpp sources/*.cpp ${CMAKE_SOURCE_DIR}/*.cpp)
set(TASK_HEADER ${PROJECT_TRDPARTY_DIR}/task/task.h)
file(GLOB SUBPROJECT_CONF *.conf) file(GLOB SUBPROJECT_CONF *.conf)
# prepare # prepare
configure_file(${SUBPROJECT_DESKTOP_IN} ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT_DESKTOP}) configure_file(${SUBPROJECT_DESKTOP_IN} ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT_DESKTOP})
# make # make
qt5_wrap_cpp(TASK_MOC_SOURCE ${TASK_HEADER}) add_library(${SUBPROJECT} MODULE ${SUBPROJECT_SOURCE})
add_library(${SUBPROJECT} MODULE ${SUBPROJECT_SOURCE} ${TASK_MOC_SOURCE})
target_link_libraries(${SUBPROJECT} ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Kf5_LIBRARIES}) target_link_libraries(${SUBPROJECT} ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Kf5_LIBRARIES})
kcoreaddons_desktop_to_json(${SUBPROJECT} ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT_DESKTOP} kcoreaddons_desktop_to_json(${SUBPROJECT} ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT_DESKTOP}
SERVICE_TYPES plasma-dataengine.desktop) SERVICE_TYPES plasma-dataengine.desktop)

View File

@ -44,9 +44,9 @@ QVariant BatterySource::data(QString source)
{ {
qCDebug(LOG_ESM) << "Source" << source; qCDebug(LOG_ESM) << "Source" << source;
if (!values.contains(source)) if (!m_values.contains(source))
run(); run();
QVariant value = values.take(source); QVariant value = m_values.take(source);
return value; return value;
} }
@ -85,7 +85,7 @@ void BatterySource::run()
// adaptor // adaptor
QFile acFile(QString("%1/AC/online").arg(m_acpiPath)); QFile acFile(QString("%1/AC/online").arg(m_acpiPath));
if (acFile.open(QIODevice::ReadOnly)) if (acFile.open(QIODevice::ReadOnly))
values[QString("battery/ac")] m_values[QString("battery/ac")]
= (QString(acFile.readLine()).trimmed().toInt() == 1); = (QString(acFile.readLine()).trimmed().toInt() == 1);
acFile.close(); acFile.close();
@ -103,7 +103,7 @@ void BatterySource::run()
= QString(currentLevelFile.readLine()).trimmed().toFloat(); = QString(currentLevelFile.readLine()).trimmed().toFloat();
float batFull float batFull
= QString(fullLevelFile.readLine()).trimmed().toFloat(); = QString(fullLevelFile.readLine()).trimmed().toFloat();
values[QString("battery/bat%1").arg(i)] m_values[QString("battery/bat%1").arg(i)]
= static_cast<int>(100 * batCurrent / batFull); = static_cast<int>(100 * batCurrent / batFull);
currentLevel += batCurrent; currentLevel += batCurrent;
fullLevel += batFull; fullLevel += batFull;
@ -111,7 +111,7 @@ void BatterySource::run()
currentLevelFile.close(); currentLevelFile.close();
fullLevelFile.close(); fullLevelFile.close();
} }
values[QString("battery/bat")] m_values[QString("battery/bat")]
= static_cast<int>(100 * currentLevel / fullLevel); = static_cast<int>(100 * currentLevel / fullLevel);
} }

View File

@ -39,7 +39,7 @@ private:
int m_batteriesCount = 0; int m_batteriesCount = 0;
QString m_acpiPath; QString m_acpiPath;
QStringList m_sources; QStringList m_sources;
QVariantHash values; QVariantHash m_values;
}; };

View File

@ -22,10 +22,9 @@
#include <QDBusConnection> #include <QDBusConnection>
#include <QDBusConnectionInterface> #include <QDBusConnectionInterface>
#include <QDBusMessage> #include <QDBusMessage>
#include <QProcess>
#include <QTextCodec> #include <QTextCodec>
#include <task/taskadds.h>
#include "awdebug.h" #include "awdebug.h"
@ -39,12 +38,24 @@ PlayerSource::PlayerSource(QObject *parent, const QStringList args)
m_mpdAddress = QString("%1:%2").arg(args.at(1)).arg(args.at(2)); m_mpdAddress = QString("%1:%2").arg(args.at(1)).arg(args.at(2));
m_mpris = args.at(3); m_mpris = args.at(3);
m_symbols = args.at(4).toInt(); m_symbols = args.at(4).toInt();
m_mpdProcess = new QProcess(nullptr);
// fucking magic from http://doc.qt.io/qt-5/qprocess.html#finished
connect(m_mpdProcess,
static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(
&QProcess::finished),
[this](int, QProcess::ExitStatus) { return updateValue(); });
m_mpdProcess->waitForFinished(0);
m_mpdCached = defaultInfo();
} }
PlayerSource::~PlayerSource() PlayerSource::~PlayerSource()
{ {
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__; qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
m_mpdProcess->kill();
m_mpdProcess->deleteLater();
} }
@ -52,9 +63,9 @@ QVariant PlayerSource::data(QString source)
{ {
qCDebug(LOG_ESM) << "Source" << source; qCDebug(LOG_ESM) << "Source" << source;
if (!values.contains(source)) if (!m_values.contains(source))
run(); run();
QVariant value = values.take(source); QVariant value = m_values.take(source);
return value; return value;
} }
@ -152,33 +163,33 @@ void PlayerSource::run()
// mpd // mpd
QHash<QString, QVariant> data = getPlayerMpdInfo(m_mpdAddress); QHash<QString, QVariant> data = getPlayerMpdInfo(m_mpdAddress);
for (auto key : data.keys()) for (auto key : data.keys())
values[key] = data[key]; m_values[key] = data[key];
} else if (m_player == QString("mpris")) { } else if (m_player == QString("mpris")) {
// players which supports mpris // players which supports mpris
QString mpris = m_mpris == QString("auto") ? getAutoMpris() : m_mpris; QString mpris = m_mpris == QString("auto") ? getAutoMpris() : m_mpris;
QHash<QString, QVariant> data = getPlayerMprisInfo(mpris); QHash<QString, QVariant> data = getPlayerMprisInfo(mpris);
for (auto key : data.keys()) for (auto key : data.keys())
values[key] = data[key]; m_values[key] = data[key];
} }
// dymanic properties // dymanic properties
// solid // solid
values[QString("player/salbum")] m_values[QString("player/salbum")]
= stripString(values[QString("player/album")].toString(), m_symbols); = stripString(m_values[QString("player/album")].toString(), m_symbols);
values[QString("player/sartist")] m_values[QString("player/sartist")]
= stripString(values[QString("player/artist")].toString(), m_symbols); = stripString(m_values[QString("player/artist")].toString(), m_symbols);
values[QString("player/stitle")] m_values[QString("player/stitle")]
= stripString(values[QString("player/title")].toString(), m_symbols); = stripString(m_values[QString("player/title")].toString(), m_symbols);
// dynamic // dynamic
values[QString("player/dalbum")] m_values[QString("player/dalbum")]
= buildString(values[QString("player/dalbum")].toString(), = buildString(m_values[QString("player/dalbum")].toString(),
values[QString("player/album")].toString(), m_symbols); m_values[QString("player/album")].toString(), m_symbols);
values[QString("player/dartist")] m_values[QString("player/dartist")]
= buildString(values[QString("player/dartist")].toString(), = buildString(m_values[QString("player/dartist")].toString(),
values[QString("player/artist")].toString(), m_symbols); m_values[QString("player/artist")].toString(), m_symbols);
values[QString("player/dtitle")] m_values[QString("player/dtitle")]
= buildString(values[QString("player/dtitle")].toString(), = buildString(m_values[QString("player/dtitle")].toString(),
values[QString("player/title")].toString(), m_symbols); m_values[QString("player/title")].toString(), m_symbols);
} }
@ -201,6 +212,40 @@ QStringList PlayerSource::sources() const
} }
void PlayerSource::updateValue()
{
qCInfo(LOG_LIB) << "Cmd returns" << m_mpdProcess->exitCode();
QString qdebug = QTextCodec::codecForMib(106)
->toUnicode(m_mpdProcess->readAllStandardError())
.trimmed();
qCInfo(LOG_LIB) << "Error" << qdebug;
QString qoutput = QTextCodec::codecForMib(106)
->toUnicode(m_mpdProcess->readAllStandardOutput())
.trimmed();
qCInfo(LOG_LIB) << "Output" << qoutput;
for (auto str : qoutput.split(QChar('\n'), QString::SkipEmptyParts)) {
if (str.split(QString(": "), QString::SkipEmptyParts).count() == 2) {
// "Metadata: data"
QString metadata = str.split(QString(": "), QString::SkipEmptyParts)
.first()
.toLower();
QString data = str.split(QString(": "), QString::SkipEmptyParts)
.last()
.trimmed();
// there are one more time...
if ((metadata == QString("time")) && (data.contains(QChar(':')))) {
QStringList times = data.split(QString(":"));
m_mpdCached[QString("player/duration")] = times.at(0).toInt();
m_mpdCached[QString("player/progress")] = times.at(1).toInt();
} else if (m_metadata.contains(metadata)) {
m_mpdCached[QString("player/%1").arg(metadata)] = data;
}
}
}
}
QVariantHash PlayerSource::defaultInfo() const QVariantHash PlayerSource::defaultInfo() const
{ {
QVariantHash info; QVariantHash info;
@ -239,40 +284,14 @@ QVariantHash PlayerSource::getPlayerMpdInfo(const QString mpdAddress) const
{ {
qCDebug(LOG_ESM) << "MPD" << mpdAddress; qCDebug(LOG_ESM) << "MPD" << mpdAddress;
QVariantHash info = defaultInfo();
// build cmd // build cmd
QString cmd = QString("bash -c \"echo 'currentsong\nstatus\nclose' | curl " QString cmd = QString("bash -c \"echo 'currentsong\nstatus\nclose' | curl "
"--connect-timeout 1 -fsm 3 telnet://%1\"") "--connect-timeout 1 -fsm 3 telnet://%1\"")
.arg(mpdAddress); .arg(mpdAddress);
qCInfo(LOG_ESM) << "cmd" << cmd; qCInfo(LOG_ESM) << "cmd" << cmd;
TaskResult process = runTask(cmd); m_mpdProcess->start(cmd);
qCInfo(LOG_ESM) << "Cmd returns" << process.exitCode;
qCInfo(LOG_ESM) << "Error" << process.error;
QString qoutput return m_mpdCached;
= QTextCodec::codecForMib(106)->toUnicode(process.output).trimmed();
for (auto str : qoutput.split(QChar('\n'), QString::SkipEmptyParts)) {
if (str.split(QString(": "), QString::SkipEmptyParts).count() == 2) {
// "Metadata: data"
QString metadata = str.split(QString(": "), QString::SkipEmptyParts)
.first()
.toLower();
QString data = str.split(QString(": "), QString::SkipEmptyParts)
.last()
.trimmed();
// there are one more time...
if ((metadata == QString("time")) && (data.contains(QChar(':')))) {
QStringList times = data.split(QString(":"));
info[QString("player/duration")] = times.at(0).toInt();
info[QString("player/progress")] = times.at(1).toInt();
} else if (m_metadata.contains(metadata)) {
info[QString("player/%1").arg(metadata)] = data;
}
}
}
return info;
} }
@ -351,7 +370,7 @@ QString PlayerSource::buildString(const QString current, const QString value,
<< "will be stripped after" << s; << "will be stripped after" << s;
int index = value.indexOf(current); int index = value.indexOf(current);
if ((current.isEmpty()) || ((index + s + 1) > value.count()))x if ((current.isEmpty()) || ((index + s + 1) > value.count()))
return QString("%1").arg(value.left(s), s, QLatin1Char(' ')); return QString("%1").arg(value.left(s), s, QLatin1Char(' '));
else else
return QString("%1").arg(value.mid(index + 1, s), s, QLatin1Char(' ')); return QString("%1").arg(value.mid(index + 1, s), s, QLatin1Char(' '));

View File

@ -23,6 +23,8 @@
#include "abstractextsysmonsource.h" #include "abstractextsysmonsource.h"
class QProcess;
class PlayerSource : public AbstractExtSysMonSource class PlayerSource : public AbstractExtSysMonSource
{ {
public: public:
@ -33,6 +35,9 @@ public:
void run(); void run();
QStringList sources() const; QStringList sources() const;
private slots:
void updateValue();
private: private:
inline QVariantHash defaultInfo() const; inline QVariantHash defaultInfo() const;
QString getAutoMpris() const; QString getAutoMpris() const;
@ -44,13 +49,15 @@ private:
QString stripString(const QString value, const int s) const; QString stripString(const QString value, const int s) const;
// configuration and values // configuration and values
QString m_mpdAddress; QString m_mpdAddress;
QVariantHash m_mpdCached;
QProcess *m_mpdProcess = nullptr;
QString m_mpris; QString m_mpris;
QString m_player; QString m_player;
int m_symbols; int m_symbols;
QStringList m_metadata = QStringList() << QString("album") QStringList m_metadata = QStringList() << QString("album")
<< QString("artist") << QString("artist")
<< QString("title"); << QString("title");
QVariantHash values; QVariantHash m_values;
}; };

View File

@ -41,9 +41,9 @@ QVariant ProcessesSource::data(QString source)
{ {
qCDebug(LOG_ESM) << "Source" << source; qCDebug(LOG_ESM) << "Source" << source;
if (!values.contains(source)) if (!m_values.contains(source))
run(); run();
QVariant value = values.take(source); QVariant value = m_values.take(source);
return value; return value;
} }
@ -98,9 +98,9 @@ void ProcessesSource::run()
running.append(cmdFile.readAll()); running.append(cmdFile.readAll());
} }
values[QString("ps/running/count")] = running.count(); m_values[QString("ps/running/count")] = running.count();
values[QString("ps/running/list")] = running; m_values[QString("ps/running/list")] = running;
values[QString("ps/total/count")] = directories.count(); m_values[QString("ps/total/count")] = directories.count();
} }

View File

@ -35,7 +35,7 @@ public:
private: private:
// configuration and values // configuration and values
QVariantHash values; QVariantHash m_values;
}; };

View File

@ -47,12 +47,12 @@ QVariant QuotesSource::data(QString source)
int ind = index(source); int ind = index(source);
source.remove(QString("quotes/")); source.remove(QString("quotes/"));
if (!values.contains(source)) { if (!m_values.contains(source)) {
QVariantHash data = extQuotes->itemByTagNumber(ind)->run(); QVariantHash data = extQuotes->itemByTagNumber(ind)->run();
for (auto key : data.keys()) for (auto key : data.keys())
values[key] = data[key]; m_values[key] = data[key];
} }
QVariant value = values.take(source); QVariant value = m_values.take(source);
return value; return value;
} }

View File

@ -41,7 +41,7 @@ private:
// configuration and values // configuration and values
ExtItemAggregator<ExtQuotes> *extQuotes; ExtItemAggregator<ExtQuotes> *extQuotes;
QStringList m_sources; QStringList m_sources;
QVariantHash values; QVariantHash m_values;
}; };

View File

@ -47,12 +47,12 @@ QVariant WeatherSource::data(QString source)
int ind = index(source); int ind = index(source);
source.remove(QString("weather/")); source.remove(QString("weather/"));
if (!values.contains(source)) { if (!m_values.contains(source)) {
QVariantHash data = extWeather->itemByTagNumber(ind)->run(); QVariantHash data = extWeather->itemByTagNumber(ind)->run();
for (auto key : data.keys()) for (auto key : data.keys())
values[key] = data[key]; m_values[key] = data[key];
} }
QVariant value = values.take(source); QVariant value = m_values.take(source);
return value; return value;
} }

View File

@ -41,7 +41,7 @@ private:
// configuration and values // configuration and values
ExtItemAggregator<ExtWeather> *extWeather; ExtItemAggregator<ExtWeather> *extWeather;
QStringList m_sources; QStringList m_sources;
QVariantHash values; QVariantHash m_values;
}; };

View File

@ -14,7 +14,7 @@
#define EMAIL "@PROJECT_CONTACT@" #define EMAIL "@PROJECT_CONTACT@"
#define LICENSE "@PROJECT_LICENSE@" #define LICENSE "@PROJECT_LICENSE@"
#define TRDPARTY_LICENSE \ #define TRDPARTY_LICENSE \
"tasks,BSD,https://github.com/mhogomchungu/tasks;QReplyTimeout " \ "QReplyTimeout " \
"wrapper,no,http://codereview.stackexchange.com/questions/30031/" \ "wrapper,no,http://codereview.stackexchange.com/questions/30031/" \
"qnetworkreply-network-reply-timeout-helper" "qnetworkreply-network-reply-timeout-helper"
#define SPECIAL_THANKS \ #define SPECIAL_THANKS \