dolphinsettingsdialog.cpp 7.1 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
13
14
15
#include "general/generalsettingspage.h"
#include "navigation/navigationsettingspage.h"
#include "services/servicessettingspage.h"
#include "startup/startupsettingspage.h"
#include "trash/trashsettingspage.h"
Roman Inflianskas's avatar
Roman Inflianskas committed
16
#include "viewmodes/viewsettingspage.h"
17

18
#include <KAuthorized>
Laurent Montel's avatar
Laurent Montel committed
19
#include <KLocalizedString>
Roman Inflianskas's avatar
Roman Inflianskas committed
20
#include <KWindowConfig>
21
#include <KMessageBox>
22

Antonio Rojas's avatar
Antonio Rojas committed
23
#include <QCloseEvent>
24
25
#include <QPushButton>

Lukáš Tinkl's avatar
Lukáš Tinkl committed
26
DolphinSettingsDialog::DolphinSettingsDialog(const QUrl& url, QWidget* parent) :
27
    KPageDialog(parent),
28
29
    m_pages(),
    m_unsavedChanges(false)
30

31
{
32
    const QSize minSize = minimumSize();
Nate Graham's avatar
Nate Graham committed
33
    setMinimumSize(QSize(540, minSize.height()));
34

35
    setFaceType(List);
36
37
38
39
40
41
    setWindowTitle(i18nc("@title:window", "Dolphin Preferences"));
    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);
42

43
44
45
46
    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
47
48
49
50
    // General
    GeneralSettingsPage* generalSettingsPage = new GeneralSettingsPage(url, this);
    KPageWidgetItem* generalSettingsFrame = addPage(generalSettingsPage,
                                                    i18nc("@title:group General settings", "General"));
51
    generalSettingsFrame->setIcon(QIcon::fromTheme(QStringLiteral("system-file-manager")));
Nate Graham's avatar
Nate Graham committed
52
53
    connect(generalSettingsPage, &GeneralSettingsPage::changed, this, &DolphinSettingsDialog::enableApply);

54
55
    // Startup
    StartupSettingsPage* startupSettingsPage = new StartupSettingsPage(url, this);
56
    KPageWidgetItem* startupSettingsFrame = addPage(startupSettingsPage,
57
                                                    i18nc("@title:group", "Startup"));
58
    startupSettingsFrame->setIcon(QIcon::fromTheme(QStringLiteral("preferences-desktop-launch-feedback")));
59
    connect(startupSettingsPage, &StartupSettingsPage::changed, this, &DolphinSettingsDialog::enableApply);
60

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

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

    // Services
    ServicesSettingsPage* servicesSettingsPage = new ServicesSettingsPage(this);
    KPageWidgetItem* servicesSettingsFrame = addPage(servicesSettingsPage,
                                                       i18nc("@title:group", "Services"));
79
    servicesSettingsFrame->setIcon(QIcon::fromTheme(QStringLiteral("preferences-system-services")));
80
    connect(servicesSettingsPage, &ServicesSettingsPage::changed, this, &DolphinSettingsDialog::enableApply);
81

82
    // Trash
83
84
85
86
    SettingsPageBase* trashSettingsPage = nullptr;
#ifndef Q_OS_WIN
    trashSettingsPage = createTrashSettingsPage(this);
#endif
87
88
89
    if (trashSettingsPage) {
        KPageWidgetItem* trashSettingsFrame = addPage(trashSettingsPage,
                                                     i18nc("@title:group", "Trash"));
90
        trashSettingsFrame->setIcon(QIcon::fromTheme(QStringLiteral("user-trash")));
91
92
        connect(trashSettingsPage, &TrashSettingsPage::changed, this, &DolphinSettingsDialog::enableApply);
    }
93

Nate Graham's avatar
Nate Graham committed
94
    m_pages.append(generalSettingsPage);
95
96
    m_pages.append(startupSettingsPage);
    m_pages.append(viewSettingsPage);
97
98
    m_pages.append(navigationSettingsPage);
    m_pages.append(servicesSettingsPage);
99
100
101
    if (trashSettingsPage) {
        m_pages.append(trashSettingsPage);
    }
102

103
    const KConfigGroup dialogConfig(KSharedConfig::openConfig(QStringLiteral("dolphinrc")), "SettingsDialog");
104
    KWindowConfig::restoreWindowSize(windowHandle(), dialogConfig);
105
106
}

107
108
DolphinSettingsDialog::~DolphinSettingsDialog()
{
109
    KConfigGroup dialogConfig(KSharedConfig::openConfig(QStringLiteral("dolphinrc")), "SettingsDialog");
110
    KWindowConfig::saveWindowSize(windowHandle(), dialogConfig);
111
112
}

113
114
void DolphinSettingsDialog::enableApply()
{
115
    buttonBox()->button(QDialogButtonBox::Apply)->setEnabled(true);
116
    m_unsavedChanges = true;
117
118
}

119
120
void DolphinSettingsDialog::applySettings()
{
121
122
123
    foreach (SettingsPageBase* page, m_pages) {
        page->applySettings();
    }
124

125
126
    emit settingsChanged();

127
    GeneralSettings* settings = GeneralSettings::self();
128
129
    if (settings->modifiedStartupSettings()) {
        // Reset the modified startup settings hint. The changed startup settings
130
        // have been applied already due to emitting settingsChanged().
131
        settings->setModifiedStartupSettings(false);
132
        settings->save();
133
    }
134
    buttonBox()->button(QDialogButtonBox::Apply)->setEnabled(false);
135
    m_unsavedChanges = false;
136
137
}

138
139
void DolphinSettingsDialog::restoreDefaults()
{
140
141
142
    foreach (SettingsPageBase* page, m_pages) {
        page->restoreDefaults();
    }
143
144
}

145
146
147
148
149
150
151
152
void DolphinSettingsDialog::closeEvent(QCloseEvent* event)
{
    if (!m_unsavedChanges) {
        event->accept();
        return;
    }

    const auto response = KMessageBox::warningYesNoCancel(this,
153
                                        i18n("You have unsaved changes. Do you want to apply the changes or discard them?"),
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
                                        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;
    }
}


174
175
176
177
178
179
180
181
SettingsPageBase *DolphinSettingsDialog::createTrashSettingsPage(QWidget *parent)
{
    if (!KAuthorized::authorizeControlModule(QStringLiteral("kcmtrash.desktop"))) {
        return nullptr;
    }

    return new TrashSettingsPage(parent);
}