Mark missing settingsKey name as non-translateable
[quassel.git] / src / qtui / settingspages / connectionsettingspage.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-09 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) any later version.                                   *
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  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, 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("Misc"), tr("Connection"), 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 void ConnectionSettingsPage::clientConnected() {
41   if(Client::networkConfig()->isInitialized())
42     initDone();
43   else
44     connect(Client::networkConfig(), SIGNAL(initDone()), SLOT(initDone()));
45 }
46
47 void ConnectionSettingsPage::clientDisconnected() {
48   setEnabled(false);
49   setChangedState(false);
50 }
51
52 void ConnectionSettingsPage::initDone() {
53   setEnabled(true);
54 }
55
56 bool ConnectionSettingsPage::hasDefaults() const {
57   return true;
58 }
59
60 QVariant ConnectionSettingsPage::loadAutoWidgetValue(const QString &widgetName) {
61   if(!isEnabled())
62     return QVariant();
63   NetworkConfig *config = Client::networkConfig();
64   if(widgetName == "pingTimeoutEnabled")
65     return config->pingTimeoutEnabled();
66   if(widgetName == "pingInterval")
67     return config->pingInterval();
68   if(widgetName == "maxPingCount")
69     return config->maxPingCount();
70   if(widgetName == "autoWhoEnabled")
71     return config->autoWhoEnabled();
72   if(widgetName == "autoWhoInterval")
73     return config->autoWhoInterval();
74   if(widgetName == "autoWhoNickLimit")
75     return config->autoWhoNickLimit();
76   if(widgetName == "autoWhoDelay")
77     return config->autoWhoDelay();
78
79   return SettingsPage::loadAutoWidgetValue(widgetName);
80 }
81
82 void ConnectionSettingsPage::saveAutoWidgetValue(const QString &widgetName, const QVariant &value) {
83   if(!isEnabled())
84     return;
85   NetworkConfig *config = Client::networkConfig();
86   if(widgetName == "pingTimeoutEnabled")
87     config->requestSetPingTimeoutEnabled(value.toBool());
88   else if(widgetName == "pingInterval")
89     config->requestSetPingInterval(value.toInt());
90   else if(widgetName == "maxPingCount")
91     config->requestSetMaxPingCount(value.toInt());
92   else if(widgetName == "autoWhoEnabled")
93     config->requestSetAutoWhoEnabled(value.toBool());
94   else if(widgetName == "autoWhoInterval")
95     config->requestSetAutoWhoInterval(value.toInt());
96   else if(widgetName == "autoWhoNickLimit")
97     config->requestSetAutoWhoNickLimit(value.toInt());
98   else if(widgetName == "autoWhoDelay")
99     config->requestSetAutoWhoDelay(value.toInt());
100
101   else
102     SettingsPage::saveAutoWidgetValue(widgetName, value);
103 }
104