dcc: Add persistent settings for core-side DCC
[quassel.git] / src / common / dccconfig.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-2016 by the Quassel Project                        *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) version 3.                                           *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
19  ***************************************************************************/
20
21 #include "dccconfig.h"
22
23 #include <QMetaProperty>
24
25 #include "types.h"
26
27 INIT_SYNCABLE_OBJECT(DccConfig)
28
29 DccConfig::DccConfig(QObject *parent)
30     : SyncableObject(parent)
31 {
32     static auto regTypes = []() -> bool {
33         qRegisterMetaTypeStreamOperators<IpDetectionMode>("DccConfig::IpDetectionMode");
34         qRegisterMetaTypeStreamOperators<PortSelectionMode>("DccConfig::PortSelectionMode");
35         return true;
36     }();
37     Q_UNUSED(regTypes);
38
39     renameObject("DccConfig");
40     setAllowClientUpdates(true);
41 }
42
43
44 DccConfig &DccConfig::operator=(const DccConfig &other)
45 {
46     if (this == &other)
47         return *this;
48
49     SyncableObject::operator=(other);
50
51     static auto propCount = staticMetaObject.propertyCount();
52     for (int i = 0; i < propCount; ++i) {
53         auto propName = staticMetaObject.property(i).name();
54         setProperty(propName, other.property(propName));
55     }
56
57     return *this;
58 }
59
60
61 bool DccConfig::operator==(const DccConfig &other)
62 {
63     // NOTE: We don't compare the SyncableObject attributes (isInitialized, clientUpdatesAllowed())
64     static auto propCount = staticMetaObject.propertyCount();
65     for (int i = 0; i < propCount; ++i) {
66         auto propName = staticMetaObject.property(i).name();
67         if (QLatin1String(propName) == QLatin1String("objectName"))
68             continue;
69         if (QLatin1String(propName) == QLatin1String("outgoingIp")) {
70             // QVariant can't compare QHostAddress
71             if (property(propName).value<QHostAddress>() != other.property(propName).value<QHostAddress>())
72                 return false;
73         }
74         else if (property(propName) != other.property(propName))
75                 return false;
76     }
77     return true;
78 }
79
80
81 bool DccConfig::isDccEnabled() const
82 {
83     return _dccEnabled;
84 }
85
86
87 void DccConfig::setDccEnabled(bool enabled)
88 {
89     _dccEnabled = enabled;
90 }
91
92
93 QHostAddress DccConfig::outgoingIp() const
94 {
95     return _outgoingIp;
96 }
97
98
99 void DccConfig::setOutgoingIp(const QHostAddress &outgoingIp)
100 {
101     _outgoingIp = outgoingIp;
102 }
103
104
105 DccConfig::IpDetectionMode DccConfig::ipDetectionMode() const
106 {
107     return _ipDetectionMode;
108 }
109
110
111 void DccConfig::setIpDetectionMode(DccConfig::IpDetectionMode detectionMode)
112 {
113     _ipDetectionMode = detectionMode;
114 }
115
116
117 DccConfig::PortSelectionMode DccConfig::portSelectionMode() const
118 {
119     return _portSelectionMode;
120 }
121
122
123 void DccConfig::setPortSelectionMode(DccConfig::PortSelectionMode portSelectionMode)
124 {
125     _portSelectionMode = portSelectionMode;
126 }
127
128
129 quint16 DccConfig::minPort() const
130 {
131     return _minPort;
132 }
133
134
135 void DccConfig::setMinPort(quint16 port)
136 {
137     _minPort = port;
138 }
139
140
141 quint16 DccConfig::maxPort() const
142 {
143     return _maxPort;
144 }
145
146
147 void DccConfig::setMaxPort(quint16 port)
148 {
149     _maxPort = port;
150 }
151
152
153 int DccConfig::chunkSize() const
154 {
155     return _chunkSize;
156 }
157
158
159 void DccConfig::setChunkSize(int chunkSize)
160 {
161     _chunkSize = chunkSize;
162 }
163
164
165 int DccConfig::sendTimeout() const
166 {
167     return _sendTimeout;
168 }
169
170
171 void DccConfig::setSendTimeout(int timeout)
172 {
173     _sendTimeout = timeout;
174 }
175
176
177 bool DccConfig::usePassiveDcc() const
178 {
179     return _usePassiveDcc;
180 }
181
182
183 void DccConfig::setUsePassiveDcc(bool use)
184 {
185     _usePassiveDcc = use;
186 }
187
188
189 bool DccConfig::useFastSend() const
190 {
191     return _useFastSend;
192 }
193
194
195 void DccConfig::setUseFastSend(bool use)
196 {
197     _useFastSend = use;
198 }