-
Notifications
You must be signed in to change notification settings - Fork 0
/
torrentstatus.cpp
203 lines (167 loc) · 5.2 KB
/
torrentstatus.cpp
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#include "torrentstatus.h"
#include "macros/likely.h"
namespace
{
// Icons section
const QIcon &pausedIcon()
{
static const QIcon cached(QStringLiteral(":/icons/torrent_statuses/paused.svg"));
return cached;
};
const QIcon &queuedIcon()
{
static const QIcon cached(QStringLiteral(":/icons/torrent_statuses/queued.svg"));
return cached;
}
const QIcon &downloadingIcon()
{
static const QIcon cached(QStringLiteral(
":/icons/torrent_statuses/downloading.svg"));
return cached;
}
const QIcon &stalledIcon()
{
static const QIcon cached(QStringLiteral(":/icons/torrent_statuses/stalled.svg"));
return cached;
}
const QIcon &finishedIcon()
{
static const QIcon cached(QStringLiteral(
":/icons/torrent_statuses/finished.svg"));
return cached;
}
const QIcon &checkingIcon()
{
static const QIcon cached(QStringLiteral(
":/icons/torrent_statuses/checking.svg"));
return cached;
}
const QIcon &errorIcon()
{
static const QIcon cached(QStringLiteral(":/icons/torrent_statuses/error.svg"));
return cached;
}
// Colors section
// yellow
const QColor &checkingColor()
{
static const QColor cached(214, 197, 64);
return cached;
}
// green
const QColor &downloadingColor()
{
static const QColor cached(111, 172, 61);
return cached;
}
// orange
const QColor &errorColor()
{
static const QColor cached(214, 86, 69);
return cached;
}
// blue
const QColor &finishedColor()
{
static const QColor cached(69, 198, 214);
return cached;
}
// green
const QColor &forcedDownloadingColor()
{
static const QColor cached {downloadingColor()};
return cached;
}
// orange
const QColor &missingFilesColor()
{
static const QColor cached {errorColor()};
return cached;
}
// yellow
const QColor &movingColor()
{
static const QColor cached {checkingColor()};
return cached;
}
// purple
const QColor &pausedColor()
{
static const QColor cached(154, 167, 214);
return cached;
}
// pink
const QColor &queuedColor()
{
static const QColor cached(255, 106, 173);
return cached;
}
// salmon
const QColor &stalledColor()
{
static const QColor cached(255, 128, 128);
return cached;
}
} // namespace
std::shared_ptr<StatusHash> StatusHash::m_instance;
std::shared_ptr<StatusHash> StatusHash::instance()
{
if (m_instance) T_LIKELY
return m_instance;
else T_UNLIKELY
return m_instance = std::shared_ptr<StatusHash>(new StatusHash());
}
void StatusHash::freeInstance()
{
if (m_instance)
m_instance.reset();
}
const QHash<QString, StatusProperties> &StatusHash::getStatusHash() const
{
static const QHash<QString, StatusProperties> cached {
{QStringLiteral("Checking"),
{TorrentStatus::Checking, checkingColor, checkingIcon,
QStringLiteral("Checking Torrent Files")}},
{QStringLiteral("CheckingResumeData"),
{TorrentStatus::CheckingResumeData, checkingColor, checkingIcon,
QStringLiteral("Checking Resume Data")}},
{QStringLiteral("Downloading"),
{TorrentStatus::Downloading, downloadingColor, downloadingIcon,
QStringLiteral("Downloading")}},
{QStringLiteral("Error"),
{TorrentStatus::Error, errorColor, errorIcon,
QStringLiteral("Error")}},
{QStringLiteral("Finished"),
{TorrentStatus::Finished, finishedColor, finishedIcon,
QStringLiteral("Finished")}},
{QStringLiteral("ForcedDownloading"),
{TorrentStatus::ForcedDownloading, forcedDownloadingColor,
downloadingIcon,
QStringLiteral("Forced Downloading")}},
{QStringLiteral("MissingFiles"),
{TorrentStatus::MissingFiles, missingFilesColor, errorIcon,
QStringLiteral("Missing Files")}},
{QStringLiteral("Moving"),
{TorrentStatus::Moving, movingColor, checkingIcon,
QStringLiteral("Moving")}},
{QStringLiteral("Paused"),
{TorrentStatus::Paused, pausedColor, pausedIcon,
QStringLiteral("Paused")}},
{QStringLiteral("Queued"),
{TorrentStatus::Queued, queuedColor, queuedIcon,
QStringLiteral("Queued")}},
{QStringLiteral("Stalled"),
{TorrentStatus::Stalled, stalledColor, stalledIcon,
QStringLiteral("Stalled")}},
{QStringLiteral("Unknown"),
{TorrentStatus::Unknown, errorColor, errorIcon,
QStringLiteral("Unknown")}},
};
return cached;
}
const StatusProperties &StatusHash::operator[](const QString &key) const
{
// Cached reference to statusHash, wtf 😂
static const auto &statusHash {getStatusHash()};
return statusHash.find(key).value();
}