This repository has been archived by the owner on Oct 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
serversettings.h
162 lines (133 loc) · 5.23 KB
/
serversettings.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
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
// SPDX-FileCopyrightText: 2015-2023 Alexey Rochev
//
// SPDX-License-Identifier: GPL-3.0-or-later
#ifndef LIBTREMOTESF_SERVERSETTINGS_H
#define LIBTREMOTESF_SERVERSETTINGS_H
#include <QObject>
#include <QTime>
#include "formatters.h"
#include "pathutils.h"
class QJsonObject;
namespace libtremotesf {
class Rpc;
struct ServerSettingsData {
Q_GADGET
public:
enum class AlternativeSpeedLimitsDays {
Sunday,
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday,
Weekdays,
Weekends,
All
};
Q_ENUM(AlternativeSpeedLimitsDays)
enum class EncryptionMode { Allowed, Preferred, Required };
Q_ENUM(EncryptionMode)
[[nodiscard]] bool canRenameFiles() const;
[[nodiscard]] bool canShowFreeSpaceForPath() const;
[[nodiscard]] bool hasSessionIdFile() const;
[[nodiscard]] bool hasTableMode() const;
int rpcVersion = 0;
int minimumRpcVersion = 0;
QString configDirectory;
PathOs pathOs = PathOs::Unix;
QString downloadDirectory;
bool startAddedTorrents = false;
bool trashTorrentFiles = false;
bool renameIncompleteFiles = false;
bool incompleteDirectoryEnabled = false;
QString incompleteDirectory;
bool ratioLimited = false;
double ratioLimit = 0.0;
bool idleSeedingLimited = false;
int idleSeedingLimit = 0;
bool downloadQueueEnabled = false;
int downloadQueueSize = 0;
bool seedQueueEnabled = false;
int seedQueueSize = 0;
bool idleQueueLimited = false;
int idleQueueLimit = 0;
bool downloadSpeedLimited = false;
int downloadSpeedLimit = 0;
bool uploadSpeedLimited = false;
int uploadSpeedLimit = 0;
bool alternativeSpeedLimitsEnabled = false;
int alternativeDownloadSpeedLimit = 0;
int alternativeUploadSpeedLimit = 0;
bool alternativeSpeedLimitsScheduled = false;
QTime alternativeSpeedLimitsBeginTime;
QTime alternativeSpeedLimitsEndTime;
AlternativeSpeedLimitsDays alternativeSpeedLimitsDays{};
int peerPort = 0;
bool randomPortEnabled = false;
bool portForwardingEnabled = false;
EncryptionMode encryptionMode{};
bool utpEnabled = false;
bool pexEnabled = false;
bool dhtEnabled = false;
bool lpdEnabled = false;
int maximumPeersPerTorrent = 0;
int maximumPeersGlobally = 0;
};
class ServerSettings final : public QObject {
Q_OBJECT
public:
explicit ServerSettings(Rpc* rpc = nullptr, QObject* parent = nullptr);
void setDownloadDirectory(const QString& directory);
void setStartAddedTorrents(bool start);
void setTrashTorrentFiles(bool trash);
void setRenameIncompleteFiles(bool rename);
void setIncompleteDirectoryEnabled(bool enabled);
void setIncompleteDirectory(const QString& directory);
void setRatioLimited(bool limited);
void setRatioLimit(double limit);
void setIdleSeedingLimited(bool limited);
void setIdleSeedingLimit(int limit);
void setDownloadQueueEnabled(bool enabled);
void setDownloadQueueSize(int size);
void setSeedQueueEnabled(bool enabled);
void setSeedQueueSize(int size);
void setIdleQueueLimited(bool limited);
void setIdleQueueLimit(int limit);
void setDownloadSpeedLimited(bool limited);
void setDownloadSpeedLimit(int limit);
void setUploadSpeedLimited(bool limited);
void setUploadSpeedLimit(int limit);
void setAlternativeSpeedLimitsEnabled(bool enabled);
void setAlternativeDownloadSpeedLimit(int limit); // kB/s
void setAlternativeUploadSpeedLimit(int limit);
void setAlternativeSpeedLimitsScheduled(bool scheduled);
void setAlternativeSpeedLimitsBeginTime(QTime time);
void setAlternativeSpeedLimitsEndTime(QTime time);
void setAlternativeSpeedLimitsDays(libtremotesf::ServerSettingsData::AlternativeSpeedLimitsDays days);
void setPeerPort(int port);
void setRandomPortEnabled(bool enabled);
void setPortForwardingEnabled(bool enabled);
void setEncryptionMode(libtremotesf::ServerSettingsData::EncryptionMode mode);
void setUtpEnabled(bool enabled);
void setPexEnabled(bool enabled);
void setDhtEnabled(bool enabled);
void setLpdEnabled(bool enabled);
void setMaximumPeersPerTorrent(int peers);
void setMaximumPeersGlobally(int peers);
[[nodiscard]] bool saveOnSet() const;
void setSaveOnSet(bool save);
void update(const QJsonObject& serverSettings);
void save() const;
[[nodiscard]] const ServerSettingsData& data() const { return mData; };
private:
Rpc* mRpc;
ServerSettingsData mData;
bool mSaveOnSet;
signals:
void changed();
};
}
SPECIALIZE_FORMATTER_FOR_Q_ENUM(libtremotesf::ServerSettingsData::AlternativeSpeedLimitsDays)
SPECIALIZE_FORMATTER_FOR_Q_ENUM(libtremotesf::ServerSettingsData::EncryptionMode)
#endif // LIBTREMOTESF_SERVERSETTINGS_H