]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/general/confirmationssettingspage.cpp
Remove unused #include
[dolphin.git] / src / settings / general / confirmationssettingspage.cpp
1 /***************************************************************************
2 * Copyright (C) 2012 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 "confirmationssettingspage.h"
21
22 #include "dolphin_generalsettings.h"
23
24 #include <KLocalizedString>
25
26 #include <QCheckBox>
27 #include <QLabel>
28 #include <QVBoxLayout>
29
30 namespace {
31 const bool ConfirmEmptyTrash = true;
32 const bool ConfirmTrash = false;
33 const bool ConfirmDelete = true;
34 const bool ConfirmScriptExecution = true;
35 }
36
37 ConfirmationsSettingsPage::ConfirmationsSettingsPage(QWidget* parent) :
38 SettingsPageBase(parent),
39 m_confirmMoveToTrash(nullptr),
40 m_confirmEmptyTrash(nullptr),
41 m_confirmDelete(nullptr),
42 m_confirmClosingMultipleTabs(nullptr)
43 {
44 QVBoxLayout* topLayout = new QVBoxLayout(this);
45
46 QLabel* confirmLabelKde = new QLabel(i18nc("@title:group", "Ask for confirmation in all KDE applications when:"), this);
47 confirmLabelKde->setWordWrap(true);
48
49 m_confirmMoveToTrash = new QCheckBox(i18nc("@option:check Ask for confirmation when",
50 "Moving files or folders to trash"), this);
51 m_confirmEmptyTrash = new QCheckBox(i18nc("@option:check Ask for confirmation when",
52 "Emptying trash"), this);
53 m_confirmDelete = new QCheckBox(i18nc("@option:check Ask for confirmation when",
54 "Deleting files or folders"), this);
55 m_confirmScriptExecution = new QCheckBox(i18nc("@option:check Ask for confirmation when",
56 "Executing scripts or desktop files"), this);
57
58 QLabel* confirmLabelDolphin = new QLabel(i18nc("@title:group", "Ask for confirmation when:"), this);
59 confirmLabelDolphin->setWordWrap(true);
60
61 m_confirmClosingMultipleTabs = new QCheckBox(i18nc("@option:check Ask for confirmation when",
62 "Closing Dolphin windows with multiple tabs"), this);
63
64 topLayout->addWidget(confirmLabelKde);
65 topLayout->addWidget(m_confirmMoveToTrash);
66 topLayout->addWidget(m_confirmEmptyTrash);
67 topLayout->addWidget(m_confirmDelete);
68 topLayout->addWidget(m_confirmScriptExecution);
69 topLayout->addWidget(confirmLabelDolphin);
70 topLayout->addWidget(m_confirmClosingMultipleTabs);
71 topLayout->addStretch();
72
73 loadSettings();
74
75 connect(m_confirmMoveToTrash, &QCheckBox::toggled, this, &ConfirmationsSettingsPage::changed);
76 connect(m_confirmEmptyTrash, &QCheckBox::toggled, this, &ConfirmationsSettingsPage::changed);
77 connect(m_confirmDelete, &QCheckBox::toggled, this, &ConfirmationsSettingsPage::changed);
78 connect(m_confirmScriptExecution, &QCheckBox::toggled, this, &ConfirmationsSettingsPage::changed);
79 connect(m_confirmClosingMultipleTabs, &QCheckBox::toggled, this, &ConfirmationsSettingsPage::changed);
80 }
81
82 ConfirmationsSettingsPage::~ConfirmationsSettingsPage()
83 {
84 }
85
86 void ConfirmationsSettingsPage::applySettings()
87 {
88 KSharedConfig::Ptr kioConfig = KSharedConfig::openConfig(QStringLiteral("kiorc"), KConfig::NoGlobals);
89 KConfigGroup confirmationGroup(kioConfig, "Confirmations");
90 confirmationGroup.writeEntry("ConfirmTrash", m_confirmMoveToTrash->isChecked());
91 confirmationGroup.writeEntry("ConfirmEmptyTrash", m_confirmEmptyTrash->isChecked());
92 confirmationGroup.writeEntry("ConfirmDelete", m_confirmDelete->isChecked());
93 confirmationGroup.sync();
94
95 if (m_confirmScriptExecution->isChecked()) {
96 KConfigGroup scriptExecutionGroup(kioConfig, "Executable scripts");
97 scriptExecutionGroup.writeEntry("behaviourOnLaunch", "alwaysAsk");
98 scriptExecutionGroup.sync();
99 }
100
101 GeneralSettings* settings = GeneralSettings::self();
102 settings->setConfirmClosingMultipleTabs(m_confirmClosingMultipleTabs->isChecked());
103 settings->save();
104 }
105
106 void ConfirmationsSettingsPage::restoreDefaults()
107 {
108 GeneralSettings* settings = GeneralSettings::self();
109 settings->useDefaults(true);
110 loadSettings();
111 settings->useDefaults(false);
112
113 m_confirmMoveToTrash->setChecked(ConfirmTrash);
114 m_confirmEmptyTrash->setChecked(ConfirmEmptyTrash);
115 m_confirmDelete->setChecked(ConfirmDelete);
116 m_confirmScriptExecution->setChecked(ConfirmScriptExecution);
117 }
118
119 void ConfirmationsSettingsPage::loadSettings()
120 {
121 KSharedConfig::Ptr kioConfig = KSharedConfig::openConfig(QStringLiteral("kiorc"), KConfig::IncludeGlobals);
122 const KConfigGroup confirmationGroup(kioConfig, "Confirmations");
123 m_confirmMoveToTrash->setChecked(confirmationGroup.readEntry("ConfirmTrash", ConfirmTrash));
124 m_confirmEmptyTrash->setChecked(confirmationGroup.readEntry("ConfirmEmptyTrash", ConfirmEmptyTrash));
125 m_confirmDelete->setChecked(confirmationGroup.readEntry("ConfirmDelete", ConfirmDelete));
126
127 const KConfigGroup scriptExecutionGroup(KSharedConfig::openConfig(QStringLiteral("kiorc")), "Executable scripts");
128 const QString value = scriptExecutionGroup.readEntry("behaviourOnLaunch", "alwaysAsk");
129 m_confirmScriptExecution->setChecked(value == QLatin1String("alwaysAsk"));
130
131 m_confirmClosingMultipleTabs->setChecked(GeneralSettings::confirmClosingMultipleTabs());
132 }
133