1 | /*************************************************************************** |
2 | * Copyright (C) 2005-2014 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(), SIGNAL(connected()), this, SLOT(clientConnected())); |
33 | connect(Client::instance(), SIGNAL(disconnected()), this, SLOT(clientDisconnected())); |
34 | |
35 | setEnabled(false); |
36 | if (Client::isConnected()) |
37 | clientConnected(); |
38 | } |
39 | |
40 | |
41 | void ConnectionSettingsPage::clientConnected() |
42 | { |
43 | if (Client::networkConfig()->isInitialized()) |
44 | initDone(); |
45 | else |
46 | connect(Client::networkConfig(), SIGNAL(initDone()), SLOT(initDone())); |
47 | } |
48 | |
49 | |
50 | void ConnectionSettingsPage::clientDisconnected() |
51 | { |
52 | setEnabled(false); |
53 | setChangedState(false); |
54 | } |
55 | |
56 | |
57 | void ConnectionSettingsPage::initDone() |
58 | { |
59 | setEnabled(true); |
60 | } |
61 | |
62 | |
63 | bool ConnectionSettingsPage::hasDefaults() const |
64 | { |
65 | return true; |
66 | } |
67 | |
68 | |
69 | QVariant ConnectionSettingsPage::loadAutoWidgetValue(const QString &widgetName) |
70 | { |
71 | if (!isEnabled()) |
72 | return QVariant(); |
73 | NetworkConfig *config = Client::networkConfig(); |
74 | if (widgetName == "pingTimeoutEnabled" ) |
75 | return config->pingTimeoutEnabled(); |
76 | if (widgetName == "pingInterval" ) |
77 | return config->pingInterval(); |
78 | if (widgetName == "maxPingCount" ) |
79 | return config->maxPingCount(); |
80 | if (widgetName == "autoWhoEnabled" ) |
81 | return config->autoWhoEnabled(); |
82 | if (widgetName == "autoWhoInterval" ) |
83 | return config->autoWhoInterval(); |
84 | if (widgetName == "autoWhoNickLimit" ) |
85 | return config->autoWhoNickLimit(); |
86 | if (widgetName == "autoWhoDelay" ) |
87 | return config->autoWhoDelay(); |
88 | if (widgetName == "standardCtcp" ) |
89 | return config->standardCtcp(); |
90 | |
91 | return SettingsPage::loadAutoWidgetValue(widgetName); |
92 | } |
93 | |
94 | |
95 | void ConnectionSettingsPage::saveAutoWidgetValue(const QString &widgetName, const QVariant &value) |
96 | { |
97 | if (!isEnabled()) |
98 | return; |
99 | NetworkConfig *config = Client::networkConfig(); |
100 | if (widgetName == "pingTimeoutEnabled" ) |
101 | config->requestSetPingTimeoutEnabled(value.toBool()); |
102 | else if (widgetName == "pingInterval" ) |
103 | config->requestSetPingInterval(value.toInt()); |
104 | else if (widgetName == "maxPingCount" ) |
105 | config->requestSetMaxPingCount(value.toInt()); |
106 | else if (widgetName == "autoWhoEnabled" ) |
107 | config->requestSetAutoWhoEnabled(value.toBool()); |
108 | else if (widgetName == "autoWhoInterval" ) |
109 | config->requestSetAutoWhoInterval(value.toInt()); |
110 | else if (widgetName == "autoWhoNickLimit" ) |
111 | config->requestSetAutoWhoNickLimit(value.toInt()); |
112 | else if (widgetName == "autoWhoDelay" ) |
113 | config->requestSetAutoWhoDelay(value.toInt()); |
114 | else if (widgetName == "standardCtcp" ) |
115 | config->requestSetStandardCtcp(value.toBool()); |
116 | |
117 | else |
118 | SettingsPage::saveAutoWidgetValue(widgetName, value); |
119 | } |
120 | |