core: Don't store a reference in CoreCertManager
[quassel.git] / src / common / dccconfig.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-2019 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 DccConfig::DccConfig(QObject* parent)
28     : SyncableObject("DccConfig", parent)
29 {
30     static auto regTypes = []() -> bool {
31         qRegisterMetaTypeStreamOperators<IpDetectionMode>("DccConfig::IpDetectionMode");
32         qRegisterMetaTypeStreamOperators<PortSelectionMode>("DccConfig::PortSelectionMode");
33         return true;
34     }();
35     Q_UNUSED(regTypes);
36
37     setAllowClientUpdates(true);
38 }
39
40 DccConfig& DccConfig::operator=(const DccConfig& other)
41 {
42     if (this == &other)
43         return *this;
44
45     SyncableObject::operator=(other);
46
47     static auto propCount = staticMetaObject.propertyCount();
48     for (int i = 0; i < propCount; ++i) {
49         auto propName = staticMetaObject.property(i).name();
50         setProperty(propName, other.property(propName));
51     }
52
53     return *this;
54 }
55
56 bool DccConfig::operator==(const DccConfig& other)
57 {
58     // NOTE: We don't compare the SyncableObject attributes (isInitialized, clientUpdatesAllowed())
59     static auto propCount = staticMetaObject.propertyCount();
60     for (int i = 0; i < propCount; ++i) {
61         auto propName = staticMetaObject.property(i).name();
62         if (QLatin1String(propName) == QLatin1String("objectName"))
63             continue;
64         if (QLatin1String(propName) == QLatin1String("outgoingIp")) {
65             // QVariant can't compare QHostAddress
66             if (property(propName).value<QHostAddress>() != other.property(propName).value<QHostAddress>())
67                 return false;
68         }
69         else if (property(propName) != other.property(propName))
70             return false;
71     }
72     return true;
73 }
74
75 bool DccConfig::isDccEnabled() const
76 {
77     return _dccEnabled;
78 }
79
80 void DccConfig::setDccEnabled(bool enabled)
81 {
82     _dccEnabled = enabled;
83 }
84
85 QHostAddress DccConfig::outgoingIp() const
86 {
87     return _outgoingIp;
88 }
89
90 void DccConfig::setOutgoingIp(const QHostAddress& outgoingIp)
91 {
92     _outgoingIp = outgoingIp;
93 }
94
95 DccConfig::IpDetectionMode DccConfig::ipDetectionMode() const
96 {
97     return _ipDetectionMode;
98 }
99
100 void DccConfig::setIpDetectionMode(DccConfig::IpDetectionMode detectionMode)
101 {
102     _ipDetectionMode = detectionMode;
103 }
104
105 DccConfig::PortSelectionMode DccConfig::portSelectionMode() const
106 {
107     return _portSelectionMode;
108 }
109
110 void DccConfig::setPortSelectionMode(DccConfig::PortSelectionMode portSelectionMode)
111 {
112     _portSelectionMode = portSelectionMode;
113 }
114
115 quint16 DccConfig::minPort() const
116 {
117     return _minPort;
118 }
119
120 void DccConfig::setMinPort(quint16 port)
121 {
122     _minPort = port;
123 }
124
125 quint16 DccConfig::maxPort() const
126 {
127     return _maxPort;
128 }
129
130 void DccConfig::setMaxPort(quint16 port)
131 {
132     _maxPort = port;
133 }
134
135 int DccConfig::chunkSize() const
136 {
137     return _chunkSize;
138 }
139
140 void DccConfig::setChunkSize(int chunkSize)
141 {
142     _chunkSize = chunkSize;
143 }
144
145 int DccConfig::sendTimeout() const
146 {
147     return _sendTimeout;
148 }
149
150 void DccConfig::setSendTimeout(int timeout)
151 {
152     _sendTimeout = timeout;
153 }
154
155 bool DccConfig::usePassiveDcc() const
156 {
157     return _usePassiveDcc;
158 }
159
160 void DccConfig::setUsePassiveDcc(bool use)
161 {
162     _usePassiveDcc = use;
163 }
164
165 bool DccConfig::useFastSend() const
166 {
167     return _useFastSend;
168 }
169
170 void DccConfig::setUseFastSend(bool use)
171 {
172     _useFastSend = use;
173 }