diff options
author | Petr Mrázek <peterix@gmail.com> | 2014-05-17 16:23:48 +0200 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2014-05-17 16:23:48 +0200 |
commit | 8a8c4193e6ee7cd55870ef8495cb7cc3b9534e02 (patch) | |
tree | ad53f17dde79b5c23534c7b0e869852f94a66d84 /logic/status | |
parent | 927217c7f06017db23b232f055dd5343e39d871f (diff) | |
download | MultiMC-8a8c4193e6ee7cd55870ef8495cb7cc3b9534e02.tar MultiMC-8a8c4193e6ee7cd55870ef8495cb7cc3b9534e02.tar.gz MultiMC-8a8c4193e6ee7cd55870ef8495cb7cc3b9534e02.tar.lz MultiMC-8a8c4193e6ee7cd55870ef8495cb7cc3b9534e02.tar.xz MultiMC-8a8c4193e6ee7cd55870ef8495cb7cc3b9534e02.zip |
Finish status pills.
Diffstat (limited to 'logic/status')
-rw-r--r-- | logic/status/StatusChecker.cpp | 23 | ||||
-rw-r--r-- | logic/status/StatusChecker.h | 11 |
2 files changed, 26 insertions, 8 deletions
diff --git a/logic/status/StatusChecker.cpp b/logic/status/StatusChecker.cpp index 66f800ae..17053837 100644 --- a/logic/status/StatusChecker.cpp +++ b/logic/status/StatusChecker.cpp @@ -27,6 +27,12 @@ StatusChecker::StatusChecker() } +void StatusChecker::timerEvent(QTimerEvent *e) +{ + QObject::timerEvent(e); + reloadStatus(); +} + void StatusChecker::reloadStatus() { if (isLoadingStatus()) @@ -42,13 +48,14 @@ void StatusChecker::reloadStatus() QObject::connect(job, &NetJob::succeeded, this, &StatusChecker::statusDownloadFinished); QObject::connect(job, &NetJob::failed, this, &StatusChecker::statusDownloadFailed); m_statusNetJob.reset(job); + emit statusLoading(true); job->start(); } void StatusChecker::statusDownloadFinished() { QLOG_DEBUG() << "Finished loading status JSON."; - + m_statusEntries.clear(); QByteArray data; { ByteArrayDownloadPtr dl = std::dynamic_pointer_cast<ByteArrayDownload>(m_statusNetJob->first()); @@ -121,17 +128,27 @@ QString StatusChecker::getLastLoadErrorMsg() const void StatusChecker::succeed() { + if(m_prevEntries != m_statusEntries) + { + emit statusChanged(m_statusEntries); + m_prevEntries = m_statusEntries; + } m_lastLoadError = ""; QLOG_DEBUG() << "Status loading succeeded."; m_statusNetJob.reset(); - emit statusLoaded(); + emit statusLoading(false); } void StatusChecker::fail(const QString& errorMsg) { + if(m_prevEntries != m_statusEntries) + { + emit statusChanged(m_statusEntries); + m_prevEntries = m_statusEntries; + } m_lastLoadError = errorMsg; QLOG_DEBUG() << "Failed to load status:" << errorMsg; m_statusNetJob.reset(); - emit statusLoadingFailed(errorMsg); + emit statusLoading(false); } diff --git a/logic/status/StatusChecker.h b/logic/status/StatusChecker.h index 1cb01836..df0dd06d 100644 --- a/logic/status/StatusChecker.h +++ b/logic/status/StatusChecker.h @@ -29,26 +29,27 @@ public: QString getLastLoadErrorMsg() const; - bool isStatusLoaded() const; - bool isLoadingStatus() const; QMap<QString, QString> getStatusEntries() const; void Q_SLOT reloadStatus(); +protected: + virtual void timerEvent(QTimerEvent *); + signals: - void statusLoaded(); - void statusLoadingFailed(QString errorMsg); + void statusLoading(bool loading); + void statusChanged(QMap<QString, QString> newStatus); protected slots: void statusDownloadFinished(); void statusDownloadFailed(); protected: + QMap<QString, QString> m_prevEntries; QMap<QString, QString> m_statusEntries; NetJobPtr m_statusNetJob; - bool m_loadedStatus; QString m_lastLoadError; void Q_SLOT succeed(); |