1 /***************************************************************************
2 * Copyright (C) 2005-2020 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
CoreConnectionSettingsPage(QWidget * parent)23 CoreConnectionSettingsPage::CoreConnectionSettingsPage(QWidget* parent)
24 : SettingsPage(tr("Remote Cores"), tr("Connection"), parent)
25 {
26 ui.setupUi(this);
27
28 initAutoWidgets();
29
30 connect(ui.useQNetworkConfigurationManager, &QAbstractButton::toggled, this, &CoreConnectionSettingsPage::widgetHasChanged);
31 connect(ui.usePingTimeout, &QAbstractButton::toggled, this, &CoreConnectionSettingsPage::widgetHasChanged);
32 connect(ui.useNoTimeout, &QAbstractButton::toggled, this, &CoreConnectionSettingsPage::widgetHasChanged);
33 }
34
widgetHasChanged()35 void CoreConnectionSettingsPage::widgetHasChanged()
36 {
37 bool hasChanged = false;
38 CoreConnectionSettings::NetworkDetectionMode mode = modeFromRadioButtons();
39 if (mode != _detectionMode)
40 hasChanged = true;
41
42 setChangedState(hasChanged);
43 }
44
defaults()45 void CoreConnectionSettingsPage::defaults()
46 {
47 setRadioButtons(CoreConnectionSettings::UseQNetworkConfigurationManager);
48
49 SettingsPage::defaults();
50 }
51
load()52 void CoreConnectionSettingsPage::load()
53 {
54 CoreConnectionSettings s;
55 _detectionMode = s.networkDetectionMode();
56 setRadioButtons(_detectionMode);
57 SettingsPage::load();
58 }
59
save()60 void CoreConnectionSettingsPage::save()
61 {
62 _detectionMode = modeFromRadioButtons();
63 CoreConnectionSettings s;
64 s.setNetworkDetectionMode(_detectionMode);
65 SettingsPage::save();
66 }
67
setRadioButtons(CoreConnectionSettings::NetworkDetectionMode mode)68 void CoreConnectionSettingsPage::setRadioButtons(CoreConnectionSettings::NetworkDetectionMode mode)
69 {
70 switch (mode) {
71 case CoreConnectionSettings::UseQNetworkConfigurationManager:
72 ui.useQNetworkConfigurationManager->setChecked(true);
73 break;
74 case CoreConnectionSettings::UsePingTimeout:
75 ui.usePingTimeout->setChecked(true);
76 break;
77 default:
78 ui.useNoTimeout->setChecked(true);
79 }
80 }
81
modeFromRadioButtons() const82 CoreConnectionSettings::NetworkDetectionMode CoreConnectionSettingsPage::modeFromRadioButtons() const
83 {
84 if (ui.useQNetworkConfigurationManager->isChecked())
85 return CoreConnectionSettings::UseQNetworkConfigurationManager;
86 if (ui.usePingTimeout->isChecked())
87 return CoreConnectionSettings::UsePingTimeout;
88
89 return CoreConnectionSettings::NoActiveDetection;
90 }
91