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