]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/navigation/navigationsettingspage.cpp
use save() instead of writeConfig()
[dolphin.git] / src / settings / navigation / navigationsettingspage.cpp
1 /***************************************************************************
2 * Copyright (C) 2009 by Peter Penz <peter.penz19@gmail.com> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
19
20 #include "navigationsettingspage.h"
21
22 #include "dolphin_generalsettings.h"
23
24 #include <KDialog>
25 #include <KGlobalSettings>
26 #include <KLocalizedString>
27
28 #include <QCheckBox>
29 #include <QGroupBox>
30 #include <QRadioButton>
31 #include <QVBoxLayout>
32
33 NavigationSettingsPage::NavigationSettingsPage(QWidget* parent) :
34 SettingsPageBase(parent),
35 m_openArchivesAsFolder(0),
36 m_autoExpandFolders(0)
37 {
38 const int spacing = KDialog::spacingHint();
39
40 QVBoxLayout* topLayout = new QVBoxLayout(this);
41 QWidget* vBox = new QWidget(this);
42 QVBoxLayout *vBoxLayout = new QVBoxLayout(vBox);
43 vBoxLayout->setMargin(0);
44 vBoxLayout->setSpacing(spacing);
45 vBoxLayout->setAlignment(Qt::AlignTop);
46
47 // create 'Mouse' group
48 QGroupBox* mouseBox = new QGroupBox(i18nc("@title:group", "Mouse"), vBox);
49 vBoxLayout->addWidget(mouseBox);
50 mouseBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
51 m_singleClick = new QRadioButton(i18nc("@option:check Mouse Settings",
52 "Single-click to open files and folders"), mouseBox);
53 m_doubleClick = new QRadioButton(i18nc("@option:check Mouse Settings",
54 "Double-click to open files and folders"), mouseBox);
55
56 QVBoxLayout* mouseBoxLayout = new QVBoxLayout(mouseBox);
57 mouseBoxLayout->addWidget(m_singleClick);
58 mouseBoxLayout->addWidget(m_doubleClick);
59
60 m_openArchivesAsFolder = new QCheckBox(i18nc("@option:check", "Open archives as folder"), vBox);
61 vBoxLayout->addWidget(m_openArchivesAsFolder);
62
63 m_autoExpandFolders = new QCheckBox(i18nc("option:check", "Open folders during drag operations"), vBox);
64 vBoxLayout->addWidget(m_autoExpandFolders);
65
66 // Add a dummy widget with no restriction regarding
67 // a vertical resizing. This assures that the dialog layout
68 // is not stretched vertically.
69 new QWidget(vBox);
70
71 topLayout->addWidget(vBox);
72
73 loadSettings();
74
75 connect(m_singleClick, &QRadioButton::toggled, this, &NavigationSettingsPage::changed);
76 connect(m_doubleClick, &QRadioButton::toggled, this, &NavigationSettingsPage::changed);
77 connect(m_openArchivesAsFolder, &QCheckBox::toggled, this, &NavigationSettingsPage::changed);
78 connect(m_autoExpandFolders, &QCheckBox::toggled, this, &NavigationSettingsPage::changed);
79 }
80
81 NavigationSettingsPage::~NavigationSettingsPage()
82 {
83 }
84
85 void NavigationSettingsPage::applySettings()
86 {
87 KConfig config("kcminputrc");
88 KConfigGroup group = config.group("KDE");
89 group.writeEntry("SingleClick", m_singleClick->isChecked(), KConfig::Persistent|KConfig::Global);
90 config.sync();
91 KGlobalSettings::self()->emitChange(KGlobalSettings::SettingsChanged, KGlobalSettings::SETTINGS_MOUSE);
92
93 GeneralSettings* settings = GeneralSettings::self();
94 settings->setBrowseThroughArchives(m_openArchivesAsFolder->isChecked());
95 settings->setAutoExpandFolders(m_autoExpandFolders->isChecked());
96
97 settings->save();
98 }
99
100 void NavigationSettingsPage::restoreDefaults()
101 {
102 GeneralSettings* settings = GeneralSettings::self();
103 settings->useDefaults(true);
104 loadSettings();
105 settings->useDefaults(false);
106
107 // The mouse settings stored in KGlobalSettings must be reset to
108 // the default values (= single click) manually.
109 m_singleClick->setChecked(true);
110 m_doubleClick->setChecked(false);
111 }
112
113 void NavigationSettingsPage::loadSettings()
114 {
115 const bool singleClick = KGlobalSettings::singleClick();
116 m_singleClick->setChecked(singleClick);
117 m_doubleClick->setChecked(!singleClick);
118 m_openArchivesAsFolder->setChecked(GeneralSettings::browseThroughArchives());
119 m_autoExpandFolders->setChecked(GeneralSettings::autoExpandFolders());
120 }
121