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