cmake: avoid de-duplication of user's CXXFLAGS
[quassel.git] / src / qtui / settingspages / connectionsettingspage.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-2022 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 "connectionsettingspage.h"
22
23 #include "client.h"
24 #include "networkconfig.h"
25
26 ConnectionSettingsPage::ConnectionSettingsPage(QWidget* parent)
27     : SettingsPage(tr("IRC"), QString(), parent)
28 {
29     ui.setupUi(this);
30     initAutoWidgets();
31
32     connect(Client::instance(), &Client::connected, this, &ConnectionSettingsPage::clientConnected);
33     connect(Client::instance(), &Client::disconnected, this, &ConnectionSettingsPage::clientDisconnected);
34
35     setEnabled(false);
36     if (Client::isConnected())
37         clientConnected();
38 }
39
40 void ConnectionSettingsPage::clientConnected()
41 {
42     if (Client::networkConfig()->isInitialized())
43         initDone();
44     else
45         connect(Client::networkConfig(), &SyncableObject::initDone, this, &ConnectionSettingsPage::initDone);
46 }
47
48 void ConnectionSettingsPage::clientDisconnected()
49 {
50     setEnabled(false);
51     setChangedState(false);
52 }
53
54 void ConnectionSettingsPage::initDone()
55 {
56     setEnabled(true);
57 }
58
59 bool ConnectionSettingsPage::hasDefaults() const
60 {
61     return true;
62 }
63
64 QVariant ConnectionSettingsPage::loadAutoWidgetValue(const QString& widgetName)
65 {
66     if (!isEnabled())
67         return QVariant();
68     NetworkConfig* config = Client::networkConfig();
69     if (widgetName == "pingTimeoutEnabled")
70         return config->pingTimeoutEnabled();
71     if (widgetName == "pingInterval")
72         return config->pingInterval();
73     if (widgetName == "maxPingCount")
74         return config->maxPingCount();
75     if (widgetName == "autoWhoEnabled")
76         return config->autoWhoEnabled();
77     if (widgetName == "autoWhoInterval")
78         return config->autoWhoInterval();
79     if (widgetName == "autoWhoNickLimit")
80         return config->autoWhoNickLimit();
81     if (widgetName == "autoWhoDelay")
82         return config->autoWhoDelay();
83     if (widgetName == "standardCtcp")
84         return config->standardCtcp();
85
86     return SettingsPage::loadAutoWidgetValue(widgetName);
87 }
88
89 void ConnectionSettingsPage::saveAutoWidgetValue(const QString& widgetName, const QVariant& value)
90 {
91     if (!isEnabled())
92         return;
93     NetworkConfig* config = Client::networkConfig();
94     if (widgetName == "pingTimeoutEnabled")
95         config->requestSetPingTimeoutEnabled(value.toBool());
96     else if (widgetName == "pingInterval")
97         config->requestSetPingInterval(value.toInt());
98     else if (widgetName == "maxPingCount")
99         config->requestSetMaxPingCount(value.toInt());
100     else if (widgetName == "autoWhoEnabled")
101         config->requestSetAutoWhoEnabled(value.toBool());
102     else if (widgetName == "autoWhoInterval")
103         config->requestSetAutoWhoInterval(value.toInt());
104     else if (widgetName == "autoWhoNickLimit")
105         config->requestSetAutoWhoNickLimit(value.toInt());
106     else if (widgetName == "autoWhoDelay")
107         config->requestSetAutoWhoDelay(value.toInt());
108     else if (widgetName == "standardCtcp")
109         config->requestSetStandardCtcp(value.toBool());
110
111     else
112         SettingsPage::saveAutoWidgetValue(widgetName, value);
113 }