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