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