summaryrefslogtreecommitdiffstats
path: root/logic
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2015-02-07 12:55:18 +0100
committerPetr Mrázek <peterix@gmail.com>2015-04-12 20:57:17 +0200
commit7a71ecd8af0454e405b25080a4b266fc99306269 (patch)
treee1bb6527d5d968ddb41f2f281b46582dff5b9131 /logic
parent4e94de413ba60a1da91715a41c8ba8caa8474728 (diff)
downloadMultiMC-7a71ecd8af0454e405b25080a4b266fc99306269.tar
MultiMC-7a71ecd8af0454e405b25080a4b266fc99306269.tar.gz
MultiMC-7a71ecd8af0454e405b25080a4b266fc99306269.tar.lz
MultiMC-7a71ecd8af0454e405b25080a4b266fc99306269.tar.xz
MultiMC-7a71ecd8af0454e405b25080a4b266fc99306269.zip
NOISSUE fix notification checker
Diffstat (limited to 'logic')
-rw-r--r--logic/notifications/NotificationChecker.cpp55
-rw-r--r--logic/notifications/NotificationChecker.h13
2 files changed, 42 insertions, 26 deletions
diff --git a/logic/notifications/NotificationChecker.cpp b/logic/notifications/NotificationChecker.cpp
index 3f8b17ba..77721770 100644
--- a/logic/notifications/NotificationChecker.cpp
+++ b/logic/notifications/NotificationChecker.cpp
@@ -3,28 +3,37 @@
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
+#include <QDebug>
#include "logic/Env.h"
-#include "BuildConfig.h"
#include "logic/net/CacheDownload.h"
-#include <QDebug>
+
NotificationChecker::NotificationChecker(QObject *parent)
- : QObject(parent), m_notificationsUrl(QUrl(BuildConfig.NOTIFICATION_URL))
+ : QObject(parent)
{
- // this will call checkForNotifications once the event loop is running
- QMetaObject::invokeMethod(this, "checkForNotifications", Qt::QueuedConnection);
}
-QUrl NotificationChecker::notificationsUrl() const
-{
- return m_notificationsUrl;
-}
void NotificationChecker::setNotificationsUrl(const QUrl &notificationsUrl)
{
m_notificationsUrl = notificationsUrl;
}
+void NotificationChecker::setApplicationChannel(QString channel)
+{
+ m_appVersionChannel = channel;
+}
+
+void NotificationChecker::setApplicationFullVersion(QString version)
+{
+ m_appFullVersion = version;
+}
+
+void NotificationChecker::setApplicationPlatform(QString platform)
+{
+ m_appPlatform = platform;
+}
+
QList<NotificationChecker::NotificationEntry> NotificationChecker::notificationEntries() const
{
return m_entries;
@@ -83,7 +92,8 @@ void NotificationChecker::downloadSucceeded(int)
{
entry.type = NotificationEntry::Information;
}
- m_entries.append(entry);
+ if(entryApplies(entry))
+ m_entries.append(entry);
}
}
@@ -92,19 +102,7 @@ void NotificationChecker::downloadSucceeded(int)
emit notificationCheckFinished();
}
-bool NotificationChecker::NotificationEntry::applies() const
-{
- bool channelApplies = channel.isEmpty() || channel == BuildConfig.VERSION_CHANNEL;
- bool platformApplies = platform.isEmpty() || platform == BuildConfig.BUILD_PLATFORM;
- bool fromApplies =
- from.isEmpty() || from == BuildConfig.FULL_VERSION_STR || !versionLessThan(BuildConfig.FULL_VERSION_STR, from);
- bool toApplies =
- to.isEmpty() || to == BuildConfig.FULL_VERSION_STR || !versionLessThan(to, BuildConfig.FULL_VERSION_STR);
- return channelApplies && platformApplies && fromApplies && toApplies;
-}
-
-bool NotificationChecker::NotificationEntry::versionLessThan(const QString &v1,
- const QString &v2)
+bool versionLessThan(const QString &v1, const QString &v2)
{
QStringList l1 = v1.split('.');
QStringList l2 = v2.split('.');
@@ -119,3 +117,14 @@ bool NotificationChecker::NotificationEntry::versionLessThan(const QString &v1,
}
return false;
}
+
+bool NotificationChecker::entryApplies(const NotificationChecker::NotificationEntry& entry) const
+{
+ bool channelApplies = entry.channel.isEmpty() || entry.channel == m_appVersionChannel;
+ bool platformApplies = entry.platform.isEmpty() || entry.platform == m_appPlatform;
+ bool fromApplies =
+ entry.from.isEmpty() || entry.from == m_appFullVersion || !versionLessThan(m_appFullVersion, entry.from);
+ bool toApplies =
+ entry.to.isEmpty() || entry.to == m_appFullVersion || !versionLessThan(entry.to, m_appFullVersion);
+ return channelApplies && platformApplies && fromApplies && toApplies;
+}
diff --git a/logic/notifications/NotificationChecker.h b/logic/notifications/NotificationChecker.h
index 915ee54d..a3e615db 100644
--- a/logic/notifications/NotificationChecker.h
+++ b/logic/notifications/NotificationChecker.h
@@ -12,8 +12,10 @@ class NotificationChecker : public QObject
public:
explicit NotificationChecker(QObject *parent = 0);
- QUrl notificationsUrl() const;
void setNotificationsUrl(const QUrl &notificationsUrl);
+ void setApplicationPlatform(QString platform);
+ void setApplicationChannel(QString channel);
+ void setApplicationFullVersion(QString version);
struct NotificationEntry
{
@@ -29,8 +31,6 @@ public:
QString platform;
QString from;
QString to;
- bool applies() const;
- static bool versionLessThan(const QString &v1, const QString &v2);
};
QList<NotificationEntry> notificationEntries() const;
@@ -47,8 +47,15 @@ signals:
void notificationCheckFinished();
private:
+ bool entryApplies(const NotificationEntry &entry) const;
+
+private:
QList<NotificationEntry> m_entries;
QUrl m_notificationsUrl;
NetJobPtr m_checkJob;
CacheDownloadPtr m_download;
+
+ QString m_appVersionChannel;
+ QString m_appPlatform;
+ QString m_appFullVersion;
};