diff options
author | Gatis Paeglis <gatis.paeglis@qt.io> | 2016-06-22 17:29:35 +0200 |
---|---|---|
committer | Gatis Paeglis <gatis.paeglis@qt.io> | 2016-06-24 10:36:37 +0000 |
commit | f3f17eebfbff4f91eee5c01ced7ebe6bc7799fc3 (patch) | |
tree | e6a1113d4e72e28c0078c048ea49605a8b309616 /src | |
parent | 22163cc84cf41091e41851104912281d0fd12849 (diff) |
Add ::statusString() API.
Change-Id: Ic404ab9095e42cce4b6580f621239cdb03795572
Reviewed-by: Gatis Paeglis <gatis.paeglis@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/imports/pluginmain.cpp | 14 | ||||
-rw-r--r-- | src/lib/qotaclient.cpp | 29 | ||||
-rw-r--r-- | src/lib/qotaclient.h | 3 | ||||
-rw-r--r-- | src/lib/qotaclient_p.h | 2 | ||||
-rw-r--r-- | src/lib/qotaclientasync.cpp | 20 | ||||
-rw-r--r-- | src/lib/qotaclientasync_p.h | 3 |
6 files changed, 62 insertions, 9 deletions
diff --git a/src/imports/pluginmain.cpp b/src/imports/pluginmain.cpp index d0712ab..e2e231a 100644 --- a/src/imports/pluginmain.cpp +++ b/src/imports/pluginmain.cpp @@ -229,6 +229,20 @@ QT_BEGIN_NAMESPACE */ /*! + \qmlproperty string OTAClient::status + \readonly + + This property holds a string containing the last status message. Only + selected operations update this property. +*/ + +/*! + \qmlsignal OTAClient::statusChanged(string status); + + \include qotaclient.cpp statusstringchanged-description +*/ + +/*! \qmlproperty string OTAClient::error \readonly diff --git a/src/lib/qotaclient.cpp b/src/lib/qotaclient.cpp index 721eb24..2315a2b 100644 --- a/src/lib/qotaclient.cpp +++ b/src/lib/qotaclient.cpp @@ -147,6 +147,13 @@ void QOTAClientPrivate::rollbackFinished(const QString &defaultRev, bool success emit q->rollbackFinished(success); } +void QOTAClientPrivate::statusStringChanged(const QString &status) +{ + Q_Q(QOTAClient); + m_status = status; + emit q->statusStringChanged(m_status); +} + void QOTAClientPrivate::errorOccurred(const QString &error) { Q_Q(QOTAClient); @@ -332,6 +339,15 @@ QString QOTAClientPrivate::revision(QueryTarget target) const */ /*! + \fn void QOTAClient::statusStringChanged(const QString &status) +//! [statusstringchanged-description] + This signal is emitted when an additional status information is available + (for example, when a program is busy performing a long operation). The + \a status argument holds the status message. +//! [statusstringchanged-description] +*/ + +/*! \fn void QOTAClient::errorOccurred(const QString &error) This signal is emitted when an error occurs. The \a error argument holds @@ -357,6 +373,7 @@ QOTAClient::QOTAClient(QObject *parent) : QObject(parent), connect(async, &QOTAClientAsync::updateFinished, d, &QOTAClientPrivate::updateFinished); connect(async, &QOTAClientAsync::rollbackFinished, d, &QOTAClientPrivate::rollbackFinished); connect(async, &QOTAClientAsync::errorOccurred, d, &QOTAClientPrivate::errorOccurred); + connect(async, &QOTAClientAsync::statusStringChanged, d, &QOTAClientPrivate::statusStringChanged); connect(async, &QOTAClientAsync::rollbackChanged, d, &QOTAClientPrivate::rollbackChanged); d->m_otaAsync->initialize(); } @@ -470,6 +487,18 @@ QString QOTAClient::errorString() const } /*! + \property QOTAClient::status + \brief a string containing the last status message. + + Only selected operations update this property. +*/ +QString QOTAClient::statusString() const +{ + Q_D(const QOTAClient); + return d->m_status; +} + +/*! \property QOTAClient::updateAvailable \brief whether a system update is available. diff --git a/src/lib/qotaclient.h b/src/lib/qotaclient.h index fbac67f..8e433bf 100644 --- a/src/lib/qotaclient.h +++ b/src/lib/qotaclient.h @@ -45,6 +45,7 @@ class Q_DECL_EXPORT QOTAClient : public QObject Q_PROPERTY(bool updateAvailable READ updateAvailable NOTIFY updateAvailableChanged) Q_PROPERTY(bool restartRequired READ restartRequired NOTIFY restartRequiredChanged) Q_PROPERTY(QString error READ errorString NOTIFY errorOccurred) + Q_PROPERTY(QString status READ statusString NOTIFY statusStringChanged) Q_PROPERTY(QString clientVersion READ clientVersion NOTIFY initializationFinished) Q_PROPERTY(QString clientDescription READ clientDescription NOTIFY initializationFinished) Q_PROPERTY(QString clientRevision READ clientRevision NOTIFY initializationFinished) @@ -66,6 +67,7 @@ public: bool otaEnabled() const; bool initialized() const; QString errorString() const; + QString statusString() const; Q_INVOKABLE bool fetchServerInfo() const; Q_INVOKABLE bool update() const; @@ -91,6 +93,7 @@ Q_SIGNALS: void rollbackInfoChanged(); void updateAvailableChanged(bool available); void restartRequiredChanged(bool required); + void statusStringChanged(const QString &status); void errorOccurred(const QString &error); void initializationFinished(); diff --git a/src/lib/qotaclient_p.h b/src/lib/qotaclient_p.h index f9b3a8d..a4fe721 100644 --- a/src/lib/qotaclient_p.h +++ b/src/lib/qotaclient_p.h @@ -65,6 +65,7 @@ public: void fetchServerInfoFinished(const QString &serverRev, const QJsonDocument &serverInfo, bool success); void updateFinished(const QString &defaultRev, bool success); void rollbackFinished(const QString &defaultRev, bool success); + void statusStringChanged(const QString &status); void errorOccurred(const QString &error); void rollbackChanged(const QString &rollbackRev, const QJsonDocument &rollbackInfo); @@ -81,6 +82,7 @@ public: bool m_updateAvailable; bool m_restartRequired; bool m_otaEnabled; + QString m_status; QString m_error; QThread *m_otaAsyncThread; QScopedPointer<QOTAClientAsync> m_otaAsync; diff --git a/src/lib/qotaclientasync.cpp b/src/lib/qotaclientasync.cpp index 108fffc..b2a25e3 100644 --- a/src/lib/qotaclientasync.cpp +++ b/src/lib/qotaclientasync.cpp @@ -57,7 +57,7 @@ QOTAClientAsync::~QOTAClientAsync() g_object_unref (m_sysroot); } -QString QOTAClientAsync::ostree(const QString &command, bool *ok) +QString QOTAClientAsync::ostree(const QString &command, bool *ok, bool updateStatus) { qCDebug(otaLog) << command; if (!m_ostree) { @@ -67,21 +67,25 @@ QString QOTAClientAsync::ostree(const QString &command, bool *ok) m_ostree->start(command); m_ostree->waitForStarted(); - QByteArray output; + QString output; do { m_ostree->waitForReadyRead(); QByteArray bytesRead = m_ostree->readAll().trimmed(); if (!bytesRead.isEmpty()) { - qCDebug(otaLog) << bytesRead; - if (bytesRead.startsWith("error:")) { + QString line = QString::fromUtf8(bytesRead); + qCDebug(otaLog) << line; + if (line.startsWith(QStringLiteral("error:"))) { *ok = false; - emit errorOccurred(QString::fromUtf8(bytesRead)); + emit errorOccurred(line); + } else { + if (updateStatus) + emit statusStringChanged(line); } - output.append(bytesRead); + output.append(line); } } while (m_ostree->state() != QProcess::NotRunning); - return QString::fromUtf8(output); + return output; } QJsonDocument QOTAClientAsync::info(QOTAClientPrivate::QueryTarget target, bool *ok, const QString &rev) @@ -174,7 +178,7 @@ void QOTAClientAsync::_fetchServerInfo() void QOTAClientAsync::_update(const QString &updateToRev) { bool ok = true; - ostree(QString(QStringLiteral("ostree admin upgrade --override-commit=%1")).arg(updateToRev), &ok); + ostree(QString(QStringLiteral("ostree admin upgrade --override-commit=%1")).arg(updateToRev), &ok, true); if (!ok) { emit updateFinished(QStringLiteral(""), ok); return; diff --git a/src/lib/qotaclientasync_p.h b/src/lib/qotaclientasync_p.h index 6d89221..66b2e34 100644 --- a/src/lib/qotaclientasync_p.h +++ b/src/lib/qotaclientasync_p.h @@ -60,9 +60,10 @@ signals: void rollbackFinished(const QString &defaultRev, bool success); void rollbackChanged(const QString &rollbackRev, const QJsonDocument &rollbackInfo); void errorOccurred(const QString &error); + void statusStringChanged(const QString &status); protected: - QString ostree(const QString &command, bool *ok); + QString ostree(const QString &command, bool *ok, bool updateStatus = false); QJsonDocument info(QOTAClientPrivate::QueryTarget target, bool *ok, const QString &rev = QString()); void multiprocessLock(const QString &method); void multiprocessUnlock(); |