summaryrefslogtreecommitdiffstats
path: root/application/WonkoGui.cpp
blob: 4d376fdc65c3c315401bf5a63d5f6c127d86d04c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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;
}