uisupport: Provide helpers for dealing with widget changes
[quassel.git] / src / common / dccconfig.h
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 #pragma once
22
23 #include "common-export.h"
24
25 #include <QHostAddress>
26
27 #include "syncableobject.h"
28
29 /**
30  * Class holding the core-side DCC configuration.
31  *
32  * @warning Equality and assignment operators are optimized for use in a settings page
33  *          and do not cover all attributes!
34  */
35 class COMMON_EXPORT DccConfig : public SyncableObject
36 {
37     Q_OBJECT
38     SYNCABLE_OBJECT
39
40     /// Whether DCC is enabled
41     Q_PROPERTY(bool dccEnabled READ isDccEnabled WRITE setDccEnabled)
42     /// The IP to use for outgoing traffic
43     Q_PROPERTY(QHostAddress outgoingIp READ outgoingIp WRITE setOutgoingIp)
44     /// The IP detection mode
45     Q_PROPERTY(DccConfig::IpDetectionMode ipDetectionMode READ ipDetectionMode WRITE setIpDetectionMode)
46     /// The port range selection mode
47     Q_PROPERTY(DccConfig::PortSelectionMode portSelectionMode READ portSelectionMode WRITE setPortSelectionMode)
48     /// Minimum port to use for incoming connections
49     Q_PROPERTY(quint16 minPort READ minPort WRITE setMinPort)
50     /// Maximum port to use for incoming connections
51     Q_PROPERTY(quint16 maxPort READ maxPort WRITE setMaxPort)
52     /// The chunk size to be used
53     Q_PROPERTY(int chunkSize READ chunkSize WRITE setChunkSize)
54     /// The timeout for DCC transfers
55     Q_PROPERTY(int sendTimeout READ sendTimeout WRITE setSendTimeout)
56     /// Whether passive (reverse) DCC should be used
57     Q_PROPERTY(bool usePassiveDcc READ usePassiveDcc WRITE setUsePassiveDcc)
58     /// Whether fast sending should be used
59     Q_PROPERTY(bool useFastSend READ useFastSend WRITE setUseFastSend)
60
61 public:
62     /**
63      * Mode for detecting the outgoing IP
64      */
65     enum class IpDetectionMode : quint8 {
66         Automatic,  ///< Automatic detection (network socket or USERHOST)
67         Manual,     ///< Manually specified IP
68     };
69     Q_ENUMS(IpDetectionMode)
70
71     /**
72      * Mode for selecting the port range for DCC
73      */
74     enum class PortSelectionMode : quint8 {
75         Automatic,   ///< Automatic port selection
76         Manual,      ///< Manually specified port range
77     };
78     Q_ENUMS(PortSelectionMode)
79
80     /**
81      * Constructor.
82      *
83      * Initializes the object with useful default values.
84      *
85      * @param[in] parent QObject parent
86      */
87     DccConfig(QObject *parent = nullptr);
88
89     /**
90      * Assignment operator.
91      *
92      * @note Only assigns properties relevant for config management!
93      *
94      * @param[in] other Right-hand side instance
95      * @returns The updated instance
96      */
97     DccConfig &operator=(const DccConfig &other);
98
99     /**
100      * Equality operator.
101      *
102      * @note Only compares properties relevant for config management!
103      *
104      * @param[in] other Right-hand side instance
105      * @returns Whether the two instances have equal properties
106      */
107     bool operator==(const DccConfig &other);
108
109     /// @name Getters
110     /// @{
111     bool isDccEnabled() const;
112     QHostAddress outgoingIp() const;
113     IpDetectionMode ipDetectionMode() const;
114     PortSelectionMode portSelectionMode() const;
115     quint16 minPort() const;
116     quint16 maxPort() const;
117     int chunkSize() const;
118     int sendTimeout() const;
119     bool usePassiveDcc() const;
120     bool useFastSend() const;
121     /// @}
122
123 public slots:
124     /// @name Setters
125     /// @{
126     void setDccEnabled(bool enabled);
127     void setOutgoingIp(const QHostAddress &outgoingIp);
128     void setIpDetectionMode(DccConfig::IpDetectionMode ipDetectionMode);
129     void setPortSelectionMode(DccConfig::PortSelectionMode portSelectionMode);
130     void setMinPort(quint16 port);
131     void setMaxPort(quint16 port);
132     void setChunkSize(int chunkSize);
133     void setSendTimeout(int timeout);
134     void setUsePassiveDcc(bool use);
135     void setUseFastSend(bool use);
136     /// @}
137
138 private:
139     // The given values are used as default for both initialization and settings
140     bool _dccEnabled                     {false};
141     QHostAddress _outgoingIp             {QHostAddress::LocalHost};
142     IpDetectionMode _ipDetectionMode     {IpDetectionMode::Automatic};
143     PortSelectionMode _portSelectionMode {PortSelectionMode::Automatic};
144     quint16 _minPort                     {1024};
145     quint16 _maxPort                     {32767};
146     int _chunkSize                       {16};
147     int _sendTimeout                     {180};
148     bool _usePassiveDcc                  {false};
149     bool _useFastSend                    {false};
150 };