summaryrefslogtreecommitdiffstats
path: root/application/WonkoGui.cpp
diff options
context:
space:
mode:
authorJan Dalheimer <jan@dalheimer.de>2016-04-06 23:09:30 +0200
committerPetr Mrázek <peterix@gmail.com>2016-04-30 23:59:23 +0200
commit00e5968bd28ab1df33b3a39dbac8cda99aa2a0d2 (patch)
treec930ca4f0edae9bb2bbd1a9ce2fddb2ca5a7bf32 /application/WonkoGui.cpp
parent5ae3b2c11416eb897a08b0d9531843d0357332f8 (diff)
downloadMultiMC-00e5968bd28ab1df33b3a39dbac8cda99aa2a0d2.tar
MultiMC-00e5968bd28ab1df33b3a39dbac8cda99aa2a0d2.tar.gz
MultiMC-00e5968bd28ab1df33b3a39dbac8cda99aa2a0d2.tar.lz
MultiMC-00e5968bd28ab1df33b3a39dbac8cda99aa2a0d2.tar.xz
MultiMC-00e5968bd28ab1df33b3a39dbac8cda99aa2a0d2.zip
NOISSUE Add a skeleton of the wonko system
Diffstat (limited to 'application/WonkoGui.cpp')
-rw-r--r--application/WonkoGui.cpp74
1 files changed, 74 insertions, 0 deletions
diff --git a/application/WonkoGui.cpp b/application/WonkoGui.cpp
new file mode 100644
index 00000000..4d376fdc
--- /dev/null
+++ b/application/WonkoGui.cpp
@@ -0,0 +1,74 @@
+#include "WonkoGui.h"
+
+#include "dialogs/ProgressDialog.h"
+#include "wonko/WonkoIndex.h"
+#include "wonko/WonkoVersionList.h"
+#include "wonko/WonkoVersion.h"
+#include "Env.h"
+
+WonkoIndexPtr Wonko::ensureIndexLoaded(QWidget *parent)
+{
+ if (!ENV.wonkoIndex()->isLocalLoaded())
+ {
+ ProgressDialog(parent).execWithTask(ENV.wonkoIndex()->localUpdateTask());
+ if (!ENV.wonkoIndex()->isRemoteLoaded() && ENV.wonkoIndex()->lists().size() == 0)
+ {
+ ProgressDialog(parent).execWithTask(ENV.wonkoIndex()->remoteUpdateTask());
+ }
+ }
+ return ENV.wonkoIndex();
+}
+
+WonkoVersionListPtr Wonko::ensureVersionListExists(const QString &uid, QWidget *parent)
+{
+ ensureIndexLoaded(parent);
+ if (!ENV.wonkoIndex()->isRemoteLoaded() && !ENV.wonkoIndex()->hasUid(uid))
+ {
+ ProgressDialog(parent).execWithTask(ENV.wonkoIndex()->remoteUpdateTask());
+ }
+ return ENV.wonkoIndex()->getList(uid);
+}
+WonkoVersionListPtr Wonko::ensureVersionListLoaded(const QString &uid, QWidget *parent)
+{
+ WonkoVersionListPtr list = ensureVersionListExists(uid, parent);
+ if (!list)
+ {
+ return nullptr;
+ }
+ if (!list->isLocalLoaded())
+ {
+ ProgressDialog(parent).execWithTask(list->localUpdateTask());
+ if (!list->isLocalLoaded())
+ {
+ ProgressDialog(parent).execWithTask(list->remoteUpdateTask());
+ }
+ }
+ return list->isComplete() ? list : nullptr;
+}
+
+WonkoVersionPtr Wonko::ensureVersionExists(const QString &uid, const QString &version, QWidget *parent)
+{
+ WonkoVersionListPtr list = ensureVersionListLoaded(uid, parent);
+ if (!list)
+ {
+ return nullptr;
+ }
+ return list->getVersion(version);
+}
+WonkoVersionPtr Wonko::ensureVersionLoaded(const QString &uid, const QString &version, QWidget *parent, const UpdateType update)
+{
+ WonkoVersionPtr vptr = ensureVersionExists(uid, version, parent);
+ if (!vptr)
+ {
+ return nullptr;
+ }
+ if (!vptr->isLocalLoaded() || update == AlwaysUpdate)
+ {
+ ProgressDialog(parent).execWithTask(vptr->localUpdateTask());
+ if (!vptr->isLocalLoaded() || update == AlwaysUpdate)
+ {
+ ProgressDialog(parent).execWithTask(vptr->remoteUpdateTask());
+ }
+ }
+ return vptr->isComplete() ? vptr : nullptr;
+}