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