dolphinsettingsdialog.cpp 8.26 KB
Newer Older
1
2
3
4
5
/*
 * SPDX-FileCopyrightText: 2006 Peter Penz <peter.penz@gmx.at>
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */
6
7

#include "dolphinsettingsdialog.h"
8

9
#include "dolphin_generalsettings.h"
Roman Inflianskas's avatar
Roman Inflianskas committed
10
#include "dolphinmainwindow.h"
11
12
#include "general/generalsettingspage.h"
#include "navigation/navigationsettingspage.h"
13
#include "contextmenu/contextmenusettingspage.h"
14
15
#include "startup/startupsettingspage.h"
#include "trash/trashsettingspage.h"
Roman Inflianskas's avatar
Roman Inflianskas committed
16
#include "viewmodes/viewsettingspage.h"
17
18
19
20
21
#include "config-kuserfeedback.h"
#ifdef HAVE_KUSERFEEDBACK
#include "userfeedback/dolphinfeedbackprovider.h"
#include "userfeedback/userfeedbacksettingspage.h"
#endif
22

23
#include <KAuthorized>
Laurent Montel's avatar
Laurent Montel committed
24
#include <KLocalizedString>
Roman Inflianskas's avatar
Roman Inflianskas committed
25
#include <KWindowConfig>
26
#include <KMessageBox>
27

Antonio Rojas's avatar
Antonio Rojas committed
28
#include <QCloseEvent>
29
30
#include <QPushButton>

31
DolphinSettingsDialog::DolphinSettingsDialog(const QUrl& url, QWidget* parent, KActionCollection* actions) :
32
    KPageDialog(parent),
33
34
    m_pages(),
    m_unsavedChanges(false)
35

36
{
37
    const QSize minSize = minimumSize();
Nate Graham's avatar
Nate Graham committed
38
    setMinimumSize(QSize(540, minSize.height()));
39

40
    setFaceType(List);
41
    setWindowTitle(i18nc("@title:window", "Configure"));
42
43
44
45
46
    QDialogButtonBox* box = new QDialogButtonBox(QDialogButtonBox::Ok
            | QDialogButtonBox::Apply | QDialogButtonBox::Cancel | QDialogButtonBox::RestoreDefaults);
    box->button(QDialogButtonBox::Apply)->setEnabled(false);
    box->button(QDialogButtonBox::Ok)->setDefault(true);
    setButtonBox(box);
47

48
49
50
51
    connect(box->button(QDialogButtonBox::Ok), &QAbstractButton::clicked, this, &DolphinSettingsDialog::applySettings);
    connect(box->button(QDialogButtonBox::Apply), &QAbstractButton::clicked, this, &DolphinSettingsDialog::applySettings);
    connect(box->button(QDialogButtonBox::RestoreDefaults), &QAbstractButton::clicked, this, &DolphinSettingsDialog::restoreDefaults);

Nate Graham's avatar
Nate Graham committed
52
53
54
55
    // General
    GeneralSettingsPage* generalSettingsPage = new GeneralSettingsPage(url, this);
    KPageWidgetItem* generalSettingsFrame = addPage(generalSettingsPage,
                                                    i18nc("@title:group General settings", "General"));
56
    generalSettingsFrame->setIcon(QIcon::fromTheme(QStringLiteral("system-file-manager")));
Nate Graham's avatar
Nate Graham committed
57
58
    connect(generalSettingsPage, &GeneralSettingsPage::changed, this, &DolphinSettingsDialog::enableApply);

59
60
    // Startup
    StartupSettingsPage* startupSettingsPage = new StartupSettingsPage(url, this);
61
    KPageWidgetItem* startupSettingsFrame = addPage(startupSettingsPage,
62
                                                    i18nc("@title:group", "Startup"));
63
    startupSettingsFrame->setIcon(QIcon::fromTheme(QStringLiteral("preferences-desktop-launch-feedback")));
64
    connect(startupSettingsPage, &StartupSettingsPage::changed, this, &DolphinSettingsDialog::enableApply);
65

66
67
    // View Modes
    ViewSettingsPage* viewSettingsPage = new ViewSettingsPage(this);
68
    KPageWidgetItem* viewSettingsFrame = addPage(viewSettingsPage,
Peter Penz's avatar
Peter Penz committed
69
                                                 i18nc("@title:group", "View Modes"));
70
    viewSettingsFrame->setIcon(QIcon::fromTheme(QStringLiteral("preferences-desktop-icons")));
71
    connect(viewSettingsPage, &ViewSettingsPage::changed, this, &DolphinSettingsDialog::enableApply);
Peter Penz's avatar
Peter Penz committed
72

73
74
75
76
    // Navigation
    NavigationSettingsPage* navigationSettingsPage = new NavigationSettingsPage(this);
    KPageWidgetItem* navigationSettingsFrame = addPage(navigationSettingsPage,
                                                       i18nc("@title:group", "Navigation"));
77
    navigationSettingsFrame->setIcon(QIcon::fromTheme(QStringLiteral("preferences-desktop-navigation")));
78
    connect(navigationSettingsPage, &NavigationSettingsPage::changed, this, &DolphinSettingsDialog::enableApply);
79

80
    // Context Menu
81
82
83
84
85
86
87
    auto contextMenuSettingsPage = new ContextMenuSettingsPage(this, actions, {
        QStringLiteral("add_to_places"),
        QStringLiteral("sort"),
        QStringLiteral("view_mode"),
        QStringLiteral("open_in_new_tab"),
        QStringLiteral("open_in_new_window"),
        QStringLiteral("copy_location"),
88
89
        QStringLiteral("duplicate"),
        QStringLiteral("open_terminal"),
90
    });
91
92
    KPageWidgetItem* contextMenuSettingsFrame = addPage(contextMenuSettingsPage,
                                                        i18nc("@title:group", "Context Menu"));
93
    contextMenuSettingsFrame->setIcon(QIcon::fromTheme(QStringLiteral("preferences-desktop-menu-edit")));
94
    connect(contextMenuSettingsPage, &ContextMenuSettingsPage::changed, this, &DolphinSettingsDialog::enableApply);
95

96
    // Trash
97
98
99
100
    SettingsPageBase* trashSettingsPage = nullptr;
#ifndef Q_OS_WIN
    trashSettingsPage = createTrashSettingsPage(this);
#endif
101
    if (trashSettingsPage) {
102
        trashSettings = addPage(trashSettingsPage,
103
                                                     i18nc("@title:group", "Trash"));
104
        trashSettings->setIcon(QIcon::fromTheme(QStringLiteral("user-trash")));
105
106
        connect(trashSettingsPage, &TrashSettingsPage::changed, this, &DolphinSettingsDialog::enableApply);
    }
107

108
109
110
111
112
113
114
115
116
117
118
#ifdef HAVE_KUSERFEEDBACK
    // User Feedback
    UserFeedbackSettingsPage* feedbackSettingsPage = nullptr;
    if (DolphinFeedbackProvider::instance()->isEnabled()) {
        feedbackSettingsPage = new UserFeedbackSettingsPage(this);
        auto feedbackSettingsFrame = addPage(feedbackSettingsPage, i18nc("@title:group", "User Feedback"));
        feedbackSettingsFrame->setIcon(QIcon::fromTheme(QStringLiteral("preferences-desktop-locale")));
        connect(feedbackSettingsPage, &UserFeedbackSettingsPage::changed, this, &DolphinSettingsDialog::enableApply);
    }
#endif

Nate Graham's avatar
Nate Graham committed
119
    m_pages.append(generalSettingsPage);
120
121
    m_pages.append(startupSettingsPage);
    m_pages.append(viewSettingsPage);
122
    m_pages.append(navigationSettingsPage);
123
    m_pages.append(contextMenuSettingsPage);
124
125
126
    if (trashSettingsPage) {
        m_pages.append(trashSettingsPage);
    }
127
128
129
130
131
#ifdef HAVE_KUSERFEEDBACK
    if (feedbackSettingsPage) {
        m_pages.append(feedbackSettingsPage);
    }
#endif
132

133
    const KConfigGroup dialogConfig(KSharedConfig::openStateConfig(), "SettingsDialog");
134
    KWindowConfig::restoreWindowSize(windowHandle(), dialogConfig);
135
136
}

137
138
DolphinSettingsDialog::~DolphinSettingsDialog()
{
139
    KConfigGroup dialogConfig(KSharedConfig::openStateConfig(), "SettingsDialog");
140
    KWindowConfig::saveWindowSize(windowHandle(), dialogConfig);
141
142
}

143
144
void DolphinSettingsDialog::enableApply()
{
145
    buttonBox()->button(QDialogButtonBox::Apply)->setEnabled(true);
146
    m_unsavedChanges = true;
147
148
}

149
150
void DolphinSettingsDialog::applySettings()
{
Alexander Lohnau's avatar
Alexander Lohnau committed
151
    for (SettingsPageBase* page : qAsConst(m_pages)) {
152
153
        page->applySettings();
    }
154

Alexander Lohnau's avatar
Alexander Lohnau committed
155
    Q_EMIT settingsChanged();
156

157
    GeneralSettings* settings = GeneralSettings::self();
158
159
    if (settings->modifiedStartupSettings()) {
        // Reset the modified startup settings hint. The changed startup settings
160
        // have been applied already due to emitting settingsChanged().
161
        settings->setModifiedStartupSettings(false);
162
        settings->save();
163
    }
164
    buttonBox()->button(QDialogButtonBox::Apply)->setEnabled(false);
165
    m_unsavedChanges = false;
166
167
}

168
169
void DolphinSettingsDialog::restoreDefaults()
{
Alexander Lohnau's avatar
Alexander Lohnau committed
170
    for (SettingsPageBase* page : qAsConst(m_pages)) {
171
172
        page->restoreDefaults();
    }
173
174
}

175
176
177
178
179
180
181
182
void DolphinSettingsDialog::closeEvent(QCloseEvent* event)
{
    if (!m_unsavedChanges) {
        event->accept();
        return;
    }

    const auto response = KMessageBox::warningYesNoCancel(this,
183
                                        i18n("You have unsaved changes. Do you want to apply the changes or discard them?"),
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
                                        i18n("Warning"),
                                        KStandardGuiItem::save(),
                                        KStandardGuiItem::discard(),
                                        KStandardGuiItem::cancel());
    switch (response) {
        case KMessageBox::Yes:
            applySettings();
            Q_FALLTHROUGH();
        case KMessageBox::No:
            event->accept();
            break;
        case KMessageBox::Cancel:
            event->ignore();
            break;
        default:
            break;
    }
}


204
205
206
207
208
209
210
211
SettingsPageBase *DolphinSettingsDialog::createTrashSettingsPage(QWidget *parent)
{
    if (!KAuthorized::authorizeControlModule(QStringLiteral("kcmtrash.desktop"))) {
        return nullptr;
    }

    return new TrashSettingsPage(parent);
}