-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtorrentstatus.h
110 lines (89 loc) · 2.46 KB
/
torrentstatus.h
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
#pragma once
#ifndef TORRENTSTATUS_H
#define TORRENTSTATUS_H
#include <QHash>
#include <QIcon>
enum struct TorrentStatus
{
// Starts from 1 because of MySQL enums starts from 1
Checking = 1,
CheckingResumeData,
Downloading,
Error,
Finished,
ForcedDownloading,
MissingFiles,
Moving,
Paused,
Queued,
Stalled,
Unknown,
};
/*! Torrent status properties. */
struct StatusProperties
{
TorrentStatus status {TorrentStatus::Unknown};
std::function<const QColor &()> color;
std::function<const QIcon &()> icon;
QString title;
inline bool isPaused() const noexcept;
inline bool isForced() const noexcept;
inline bool isMoving() const noexcept;
inline bool isFinished() const noexcept;
inline bool isMissingFiles() const noexcept;
inline bool isError() const noexcept;
inline bool isDownloading() const noexcept;
inline bool isChecking() const noexcept;
};
/*! Maps a TorrentStatus string representation to StatusProperties. */
class StatusHash final
{
Q_DISABLE_COPY(StatusHash)
public:
inline ~StatusHash() = default;
static std::shared_ptr<StatusHash> instance();
static void freeInstance();
const StatusProperties &operator[](const QString &key) const;
private:
StatusHash() = default;
const QHash<QString, StatusProperties> &getStatusHash() const;
static std::shared_ptr<StatusHash> m_instance;
};
/* StatusProperties */
bool StatusProperties::isPaused() const noexcept
{
return status == TorrentStatus::Paused;
}
bool StatusProperties::isForced() const noexcept
{
return status == TorrentStatus::ForcedDownloading;
}
bool StatusProperties::isMoving() const noexcept
{
return status == TorrentStatus::Moving;
}
bool StatusProperties::isFinished() const noexcept
{
return status == TorrentStatus::Finished;
}
bool StatusProperties::isMissingFiles() const noexcept
{
return status == TorrentStatus::MissingFiles;
}
bool StatusProperties::isError() const noexcept
{
return status == TorrentStatus::Error;
}
bool StatusProperties::isDownloading() const noexcept
{
return status == TorrentStatus::Downloading ||
status == TorrentStatus::ForcedDownloading ||
status == TorrentStatus::Stalled ||
status == TorrentStatus::Queued;
}
bool StatusProperties::isChecking() const noexcept
{
return status == TorrentStatus::Checking ||
status == TorrentStatus::CheckingResumeData;
}
#endif // TORRENTSTATUS_H