summaryrefslogtreecommitdiff
path: root/ui/updateinfo.h
blob: 9e89b767fc0d1178a1ddb9913bb6c2f7c9d68da6 (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
75
76
77
78
79
80
81
82
#pragma once

#include "uitypes.h"
#include <QString>
#include <QObject>
#include <QVersionNumber>
#include <QDateTime>
#include <memory>
#include "binaryninjaapi.h"

class BINARYNINJAUIAPI UpdateInfoFetcher : public QObject, public std::enable_shared_from_this<UpdateInfoFetcher>
{
	Q_OBJECT

public:
	struct Version
	{
		QString versionStringToGiveToMainWindow;
		QVersionNumber version;
		QDateTime date;
		bool isCurrent = false;
		Version(BNUpdateVersionNew);
	};
	struct ChangelogEntryItem
	{
		QString author;
		QString commit;
		QString body;
		bool isHidden = false;
		ChangelogEntryItem(const QString& author = "", const QString& commit = "", const QString& body = "", const bool isHidden = false)
			: author(author), commit(commit), body(body), isHidden(isHidden) {};
		/// In-struct cache for wrapped text
		mutable QString bodyWrapCache;
	};
	struct ChangelogEntry
	{
		QVersionNumber version;
		QDateTime date;
		bool isNew = false;
		std::vector<ChangelogEntryItem> entryItems;
		ChangelogEntry(BNChangelogEntry);
	};
	struct Channel
	{
		QString name;
		QString description;
		std::vector<Version> versions;
		std::vector<ChangelogEntry> changelog;
		Channel(BNUpdateChannelFullInfo);
		Channel() {};
	};
	enum FetchError
	{
		NoError,
		ConnectionError,
		DeserError
	};

private:
	std::vector<Channel> m_channels;
	std::mutex m_infoMutex;
	std::atomic<bool> m_done = false;

	struct UseCreate {};

public:
	// Instances must be created via `create()`.
	UpdateInfoFetcher(UseCreate) {}

	static std::shared_ptr<UpdateInfoFetcher> create();

	UpdateInfoFetcher(const UpdateInfoFetcher&) = delete;
	UpdateInfoFetcher& operator=(const UpdateInfoFetcher&) = delete;

	bool done() { return m_done; }
	void startFetch();
	const std::vector<Channel>& getChannels();
	const Channel* getActiveChannel();
	std::vector<ChangelogEntry> getFilteredChangelog();
signals:
	void fetchCompleted(const FetchError& error);
};