]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/navigation/navigationsettingspage.cpp
10e009faa12e343a80b25c14d0add014d57ebc42
[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 #include <KVBox>
28
29 #include <QCheckBox>
30 #include <QGroupBox>
31 #include <QLabel>
32 #include <QRadioButton>
33 #include <QVBoxLayout>
34
35 NavigationSettingsPage::NavigationSettingsPage(QWidget* parent) :
36 SettingsPageBase(parent),
37 m_openArchivesAsFolder(0),
38 m_autoExpandFolders(0)
39 {
40 const int spacing = KDialog::spacingHint();
41
42 QVBoxLayout* topLayout = new QVBoxLayout(this);
43 KVBox* vBox = new KVBox(this);
44 vBox->setSpacing(spacing);
45
46 // create 'Mouse' group
47 QGroupBox* mouseBox = new QGroupBox(i18nc("@title:group", "Mouse"), vBox);
48 mouseBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
49 m_singleClick = new QRadioButton(i18nc("@option:check Mouse Settings",
50 "Single-click to open files and folders"), mouseBox);
51 m_doubleClick = new QRadioButton(i18nc("@option:check Mouse Settings",
52 "Double-click to open files and folders"), mouseBox);
53
54 QVBoxLayout* mouseBoxLayout = new QVBoxLayout(mouseBox);
55 mouseBoxLayout->addWidget(m_singleClick);
56 mouseBoxLayout->addWidget(m_doubleClick);
57
58 m_openArchivesAsFolder = new QCheckBox(i18nc("@option:check", "Open archives as folder"), vBox);
59
60 m_autoExpandFolders = new QCheckBox(i18nc("option:check", "Open folders during drag operations"), vBox);
61
62 // Add a dummy widget with no restriction regarding
63 // a vertical resizing. This assures that the dialog layout
64 // is not stretched vertically.
65 new QWidget(vBox);
66
67 topLayout->addWidget(vBox);
68
69 loadSettings();
70
71 connect(m_singleClick, &QRadioButton::toggled, this, &NavigationSettingsPage::changed);
72 connect(m_doubleClick, &QRadioButton::toggled, this, &NavigationSettingsPage::changed);
73 connect(m_openArchivesAsFolder, &QCheckBox::toggled, this, &NavigationSettingsPage::changed);
74 connect(m_autoExpandFolders, &QCheckBox::toggled, this, &NavigationSettingsPage::changed);
75 }
76
77 NavigationSettingsPage::~NavigationSettingsPage()
78 {
79 }
80
81 void NavigationSettingsPage::applySettings()
82 {
83 KConfig config("kcminputrc");
84 KConfigGroup group = config.group("KDE");
85 group.writeEntry("SingleClick", m_singleClick->isChecked(), KConfig::Persistent|KConfig::Global);
86 config.sync();
87 KGlobalSettings::self()->emitChange(KGlobalSettings::SettingsChanged, KGlobalSettings::SETTINGS_MOUSE);
88
89 GeneralSettings* settings = GeneralSettings::self();
90 settings->setBrowseThroughArchives(m_openArchivesAsFolder->isChecked());
91 settings->setAutoExpandFolders(m_autoExpandFolders->isChecked());
92
93 settings->writeConfig();
94 }
95
96 void NavigationSettingsPage::restoreDefaults()
97 {
98 GeneralSettings* settings = GeneralSettings::self();
99 settings->useDefaults(true);
100 loadSettings();
101 settings->useDefaults(false);
102
103 // The mouse settings stored in KGlobalSettings must be reset to
104 // the default values (= single click) manually.
105 m_singleClick->setChecked(true);
106 m_doubleClick->setChecked(false);
107 }
108
109 void NavigationSettingsPage::loadSettings()
110 {
111 const bool singleClick = KGlobalSettings::singleClick();
112 m_singleClick->setChecked(singleClick);
113 m_doubleClick->setChecked(!singleClick);
114 m_openArchivesAsFolder->setChecked(GeneralSettings::browseThroughArchives());
115 m_autoExpandFolders->setChecked(GeneralSettings::autoExpandFolders());
116 }
117