Add Qt-based connection detection
[quassel.git] / src / qtui / settingspages / coreconnectionsettingspage.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-2015 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 "coreconnectionsettingspage.h"
22
23 CoreConnectionSettingsPage::CoreConnectionSettingsPage(QWidget *parent)
24     : SettingsPage(tr("Remote Cores"), tr("Connection"), parent)
25 {
26     ui.setupUi(this);
27 #ifndef HAVE_KDE4
28     ui.useSolid->hide();
29 #endif
30
31     initAutoWidgets();
32
33     connect(ui.useSolid, SIGNAL(toggled(bool)), SLOT(widgetHasChanged()));
34     connect(ui.useQNetworkConfigurationManager, SIGNAL(toggled(bool)), SLOT(widgetHasChanged()));
35     connect(ui.usePingTimeout, SIGNAL(toggled(bool)), SLOT(widgetHasChanged()));
36     connect(ui.useNoTimeout, SIGNAL(toggled(bool)), SLOT(widgetHasChanged()));
37 }
38
39
40 void CoreConnectionSettingsPage::widgetHasChanged()
41 {
42     bool hasChanged = false;
43     CoreConnectionSettings::NetworkDetectionMode mode = modeFromRadioButtons();
44     if (mode != _detectionMode)
45         hasChanged = true;
46
47     setChangedState(hasChanged);
48 }
49
50
51 void CoreConnectionSettingsPage::defaults()
52 {
53 #ifdef HAVE_KDE4
54     setRadioButtons(CoreConnectionSettings::UseSolid);
55 #else
56     setRadioButtons(CoreConnectionSettings::UseQNetworkConfigurationManager);
57 #endif
58
59     SettingsPage::defaults();
60 }
61
62
63 void CoreConnectionSettingsPage::load()
64 {
65     CoreConnectionSettings s;
66     _detectionMode = s.networkDetectionMode();
67     setRadioButtons(_detectionMode);
68     SettingsPage::load();
69 }
70
71
72 void CoreConnectionSettingsPage::save()
73 {
74     _detectionMode = modeFromRadioButtons();
75     CoreConnectionSettings s;
76     s.setNetworkDetectionMode(_detectionMode);
77     SettingsPage::save();
78 }
79
80
81 void CoreConnectionSettingsPage::setRadioButtons(CoreConnectionSettings::NetworkDetectionMode mode)
82 {
83     switch (mode) {
84 #ifdef HAVE_KDE4
85     case CoreConnectionSettings::UseSolid:
86         ui.useSolid->setChecked(true);
87         break;
88 #endif
89     case CoreConnectionSettings::UseQNetworkConfigurationManager:
90         ui.useQNetworkConfigurationManager->setChecked(true);
91         break;
92     case CoreConnectionSettings::UsePingTimeout:
93         ui.usePingTimeout->setChecked(true);
94         break;
95     default:
96         ui.useNoTimeout->setChecked(true);
97     }
98 }
99
100
101 CoreConnectionSettings::NetworkDetectionMode CoreConnectionSettingsPage::modeFromRadioButtons() const
102 {
103 #ifdef HAVE_KDE4
104     if (ui.useSolid->isChecked())
105         return CoreConnectionSettings::UseSolid;
106 #endif
107     if (ui.useQNetworkConfigurationManager->isChecked())
108         return CoreConnectionSettings::UseQNetworkConfigurationManager;
109     if (ui.usePingTimeout->isChecked())
110         return CoreConnectionSettings::UsePingTimeout;
111
112     return CoreConnectionSettings::NoActiveDetection;
113 }