1 /***************************************************************************
2 * Copyright (C) 2012 by Peter Penz <peter.penz19@gmail.com> *
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. *
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. *
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 ***************************************************************************/
20 #include "confirmationssettingspage.h"
22 #include <dolphin_generalsettings.h>
24 #include <KLocalizedString>
28 #include <QVBoxLayout>
31 const bool ConfirmEmptyTrash
= true;
32 const bool ConfirmTrash
= false;
33 const bool ConfirmDelete
= true;
34 const bool ConfirmScriptExecution
= true;
37 ConfirmationsSettingsPage::ConfirmationsSettingsPage(QWidget
* parent
) :
38 SettingsPageBase(parent
),
39 m_confirmMoveToTrash(nullptr),
40 m_confirmEmptyTrash(nullptr),
41 m_confirmDelete(nullptr),
42 m_confirmClosingMultipleTabs(nullptr)
44 QVBoxLayout
* topLayout
= new QVBoxLayout(this);
46 QLabel
* confirmLabelKde
= new QLabel(i18nc("@title:group", "Ask for confirmation in all KDE applications when:"), this);
47 confirmLabelKde
->setWordWrap(true);
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);
58 QLabel
* confirmLabelDolphin
= new QLabel(i18nc("@title:group", "Ask for confirmation when:"), this);
59 confirmLabelDolphin
->setWordWrap(true);
61 m_confirmClosingMultipleTabs
= new QCheckBox(i18nc("@option:check Ask for confirmation when",
62 "Closing Dolphin windows with multiple tabs"), this);
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();
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
);
82 ConfirmationsSettingsPage::~ConfirmationsSettingsPage()
86 void ConfirmationsSettingsPage::applySettings()
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();
95 if (m_confirmScriptExecution
->isChecked()) {
96 KConfigGroup
scriptExecutionGroup(kioConfig
, "Executable scripts");
97 scriptExecutionGroup
.writeEntry("behaviourOnLaunch", "alwaysAsk");
98 scriptExecutionGroup
.sync();
101 GeneralSettings
* settings
= GeneralSettings::self();
102 settings
->setConfirmClosingMultipleTabs(m_confirmClosingMultipleTabs
->isChecked());
106 void ConfirmationsSettingsPage::restoreDefaults()
108 GeneralSettings
* settings
= GeneralSettings::self();
109 settings
->useDefaults(true);
111 settings
->useDefaults(false);
113 m_confirmMoveToTrash
->setChecked(ConfirmTrash
);
114 m_confirmEmptyTrash
->setChecked(ConfirmEmptyTrash
);
115 m_confirmDelete
->setChecked(ConfirmDelete
);
116 m_confirmScriptExecution
->setChecked(ConfirmScriptExecution
);
119 void ConfirmationsSettingsPage::loadSettings()
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
));
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"));
131 m_confirmClosingMultipleTabs
->setChecked(GeneralSettings::confirmClosingMultipleTabs());