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