Changeset View
Changeset View
Standalone View
Standalone View
src/settings/startup/startupsettingspage.cpp
Show All 21 Lines | |||||
22 | #include "dolphin_generalsettings.h" | 22 | #include "dolphin_generalsettings.h" | ||
23 | #include "dolphinmainwindow.h" | 23 | #include "dolphinmainwindow.h" | ||
24 | #include "dolphinviewcontainer.h" | 24 | #include "dolphinviewcontainer.h" | ||
25 | #include "global.h" | 25 | #include "global.h" | ||
26 | 26 | | |||
27 | #include <KLocalizedString> | 27 | #include <KLocalizedString> | ||
28 | #include <KMessageBox> | 28 | #include <KMessageBox> | ||
29 | 29 | | |||
30 | #include <QButtonGroup> | ||||
30 | #include <QCheckBox> | 31 | #include <QCheckBox> | ||
31 | #include <QFileDialog> | 32 | #include <QFileDialog> | ||
32 | #include <QLineEdit> | 33 | #include <QLineEdit> | ||
33 | #include <QPushButton> | 34 | #include <QPushButton> | ||
35 | #include <QRadioButton> | ||||
34 | #include <QFormLayout> | 36 | #include <QFormLayout> | ||
37 | #include <QGridLayout> | ||||
35 | #include <QHBoxLayout> | 38 | #include <QHBoxLayout> | ||
36 | #include <QVBoxLayout> | | |||
37 | 39 | | |||
38 | StartupSettingsPage::StartupSettingsPage(const QUrl& url, QWidget* parent) : | 40 | StartupSettingsPage::StartupSettingsPage(const QUrl& url, QWidget* parent) : | ||
39 | SettingsPageBase(parent), | 41 | SettingsPageBase(parent), | ||
40 | m_url(url), | 42 | m_url(url), | ||
41 | m_homeUrl(nullptr), | 43 | m_homeUrl(nullptr), | ||
44 | m_homeUrlBoxLayoutContainer(nullptr), | ||||
45 | m_buttonBoxLayoutContainer(nullptr), | ||||
46 | m_rememberOpenedTabsRadioButton(nullptr), | ||||
47 | m_homeUrlRadioButton(nullptr), | ||||
42 | m_splitView(nullptr), | 48 | m_splitView(nullptr), | ||
43 | m_editableUrl(nullptr), | 49 | m_editableUrl(nullptr), | ||
44 | m_showFullPath(nullptr), | 50 | m_showFullPath(nullptr), | ||
45 | m_filterBar(nullptr), | 51 | m_filterBar(nullptr), | ||
46 | m_showFullPathInTitlebar(nullptr), | 52 | m_showFullPathInTitlebar(nullptr), | ||
47 | m_openExternallyCalledFolderInNewTab(nullptr) | 53 | m_openExternallyCalledFolderInNewTab(nullptr) | ||
48 | { | 54 | { | ||
49 | QFormLayout* topLayout = new QFormLayout(this); | 55 | QFormLayout* topLayout = new QFormLayout(this); | ||
50 | 56 | | |||
57 | m_rememberOpenedTabsRadioButton = new QRadioButton(i18nc("@option:radio Startup Settings", "Folders, tabs, and window state from last time")); | ||||
meven: "Folders and tabs that were open before" => "Folders and tabs as they were opened before" Since… | |||||
58 | m_homeUrlRadioButton = new QRadioButton(); | ||||
59 | | ||||
60 | QButtonGroup* initialViewGroup = new QButtonGroup(this); | ||||
61 | initialViewGroup->addButton(m_rememberOpenedTabsRadioButton); | ||||
62 | initialViewGroup->addButton(m_homeUrlRadioButton); | ||||
63 | | ||||
51 | 64 | | |||
52 | // create 'Home URL' editor | 65 | // create 'Home URL' editor | ||
53 | QHBoxLayout* homeUrlBoxLayout = new QHBoxLayout(); | 66 | m_homeUrlBoxLayoutContainer = new QWidget(this); | ||
67 | QHBoxLayout* homeUrlBoxLayout = new QHBoxLayout(m_homeUrlBoxLayoutContainer); | ||||
feverfew: Does this compile? Shouldn't `QWidget` actually be `QWidget()`? | |||||
54 | homeUrlBoxLayout->setContentsMargins(0, 0, 0, 0); | 68 | homeUrlBoxLayout->setContentsMargins(0, 0, 0, 0); | ||
55 | 69 | | |||
56 | m_homeUrl = new QLineEdit(); | 70 | m_homeUrl = new QLineEdit(); | ||
57 | m_homeUrl->setClearButtonEnabled(true); | 71 | m_homeUrl->setClearButtonEnabled(true); | ||
58 | homeUrlBoxLayout->addWidget(m_homeUrl); | 72 | homeUrlBoxLayout->addWidget(m_homeUrl); | ||
59 | 73 | | |||
60 | QPushButton* selectHomeUrlButton = new QPushButton(QIcon::fromTheme(QStringLiteral("folder-open")), QString()); | 74 | QPushButton* selectHomeUrlButton = new QPushButton(QIcon::fromTheme(QStringLiteral("folder-open")), QString()); | ||
61 | homeUrlBoxLayout->addWidget(selectHomeUrlButton); | 75 | homeUrlBoxLayout->addWidget(selectHomeUrlButton); | ||
62 | 76 | | |||
63 | #ifndef QT_NO_ACCESSIBILITY | 77 | #ifndef QT_NO_ACCESSIBILITY | ||
64 | selectHomeUrlButton->setAccessibleName(i18nc("@action:button", "Select Home Location")); | 78 | selectHomeUrlButton->setAccessibleName(i18nc("@action:button", "Select Home Location")); | ||
65 | #endif | 79 | #endif | ||
66 | 80 | | |||
67 | connect(selectHomeUrlButton, &QPushButton::clicked, | 81 | connect(selectHomeUrlButton, &QPushButton::clicked, | ||
68 | this, &StartupSettingsPage::selectHomeUrl); | 82 | this, &StartupSettingsPage::selectHomeUrl); | ||
69 | 83 | | |||
70 | QHBoxLayout* buttonBoxLayout = new QHBoxLayout(); | 84 | m_buttonBoxLayoutContainer = new QWidget(this); | ||
85 | QHBoxLayout* buttonBoxLayout = new QHBoxLayout(m_buttonBoxLayoutContainer); | ||||
feverfew: Same question here | |||||
71 | buttonBoxLayout->setContentsMargins(0, 0, 0, 0); | 86 | buttonBoxLayout->setContentsMargins(0, 0, 0, 0); | ||
72 | 87 | | |||
73 | QPushButton* useCurrentButton = new QPushButton(i18nc("@action:button", "Use Current Location")); | 88 | QPushButton* useCurrentButton = new QPushButton(i18nc("@action:button", "Use Current Location")); | ||
74 | buttonBoxLayout->addWidget(useCurrentButton); | 89 | buttonBoxLayout->addWidget(useCurrentButton); | ||
75 | connect(useCurrentButton, &QPushButton::clicked, | 90 | connect(useCurrentButton, &QPushButton::clicked, | ||
76 | this, &StartupSettingsPage::useCurrentLocation); | 91 | this, &StartupSettingsPage::useCurrentLocation); | ||
77 | QPushButton* useDefaultButton = new QPushButton(i18nc("@action:button", "Use Default Location")); | 92 | QPushButton* useDefaultButton = new QPushButton(i18nc("@action:button", "Use Default Location")); | ||
78 | buttonBoxLayout->addWidget(useDefaultButton); | 93 | buttonBoxLayout->addWidget(useDefaultButton); | ||
79 | connect(useDefaultButton, &QPushButton::clicked, | 94 | connect(useDefaultButton, &QPushButton::clicked, | ||
80 | this, &StartupSettingsPage::useDefaultLocation); | 95 | this, &StartupSettingsPage::useDefaultLocation); | ||
81 | 96 | | |||
82 | QVBoxLayout* homeBoxLayout = new QVBoxLayout(); | 97 | QGridLayout* startInLocationLayout = new QGridLayout(); | ||
83 | homeBoxLayout->setContentsMargins(0, 0, 0, 0); | 98 | startInLocationLayout->setContentsMargins(0, 0, 0, 0); | ||
84 | homeBoxLayout->addLayout(homeUrlBoxLayout); | 99 | startInLocationLayout->addWidget(m_homeUrlRadioButton, 0, 0); | ||
85 | homeBoxLayout->addLayout(buttonBoxLayout); | 100 | startInLocationLayout->addWidget(m_homeUrlBoxLayoutContainer, 0, 1); | ||
101 | startInLocationLayout->addWidget(m_buttonBoxLayoutContainer, 1, 1); | ||||
86 | 102 | | |||
87 | topLayout->addRow(i18nc("@label:textbox", "Start in:"), homeBoxLayout); | 103 | topLayout->addRow(i18nc("@label:textbox", "Show on startup:"), m_rememberOpenedTabsRadioButton); | ||
104 | topLayout->addRow(QString(), startInLocationLayout); | ||||
88 | 105 | | |||
89 | 106 | | |||
90 | topLayout->addItem(new QSpacerItem(0, Dolphin::VERTICAL_SPACER_HEIGHT, QSizePolicy::Fixed, QSizePolicy::Fixed)); | 107 | topLayout->addItem(new QSpacerItem(0, Dolphin::VERTICAL_SPACER_HEIGHT, QSizePolicy::Fixed, QSizePolicy::Fixed)); | ||
91 | 108 | | |||
92 | 109 | m_splitView = new QCheckBox(i18nc("@option:check Startup Settings", "Begin in split view mode")); | |||
broulik: This wording could be improved (can't think of one right now) | |||||
93 | // create 'Split view', 'Show full path', 'Editable location' and 'Filter bar' checkboxes | 110 | topLayout->addRow(i18n("New windows:"), m_splitView); | ||
94 | m_splitView = new QCheckBox(i18nc("@option:check Startup Settings", "Split view mode")); | 111 | m_filterBar = new QCheckBox(i18nc("@option:check Startup Settings", "Show filter bar")); | ||
95 | topLayout->addRow(i18nc("@label:checkbox", "Window options:"), m_splitView); | 112 | topLayout->addRow(QString(), m_filterBar); | ||
96 | m_editableUrl = new QCheckBox(i18nc("@option:check Startup Settings", "Editable location bar")); | 113 | m_editableUrl = new QCheckBox(i18nc("@option:check Startup Settings", "Make location bar editable")); | ||
97 | topLayout->addRow(QString(), m_editableUrl); | 114 | topLayout->addRow(QString(), m_editableUrl); | ||
115 | | ||||
116 | topLayout->addItem(new QSpacerItem(0, Dolphin::VERTICAL_SPACER_HEIGHT, QSizePolicy::Fixed, QSizePolicy::Fixed)); | ||||
117 | | ||||
118 | m_openExternallyCalledFolderInNewTab = new QCheckBox(i18nc("@option:check Startup Settings", "Open new folders in tabs")); | ||||
119 | topLayout->addRow(i18nc("@label:checkbox", "General:"), m_openExternallyCalledFolderInNewTab); | ||||
98 | m_showFullPath = new QCheckBox(i18nc("@option:check Startup Settings", "Show full path inside location bar")); | 120 | m_showFullPath = new QCheckBox(i18nc("@option:check Startup Settings", "Show full path inside location bar")); | ||
99 | topLayout->addRow(QString(), m_showFullPath); | 121 | topLayout->addRow(QString(), m_showFullPath); | ||
100 | m_filterBar = new QCheckBox(i18nc("@option:check Startup Settings", "Show filter bar")); | | |||
101 | topLayout->addRow(QString(), m_filterBar); | | |||
102 | m_showFullPathInTitlebar = new QCheckBox(i18nc("@option:check Startup Settings", "Show full path in title bar")); | 122 | m_showFullPathInTitlebar = new QCheckBox(i18nc("@option:check Startup Settings", "Show full path in title bar")); | ||
103 | topLayout->addRow(QString(), m_showFullPathInTitlebar); | 123 | topLayout->addRow(QString(), m_showFullPathInTitlebar); | ||
104 | m_openExternallyCalledFolderInNewTab = new QCheckBox(i18nc("@option:check Startup Settings", "Open new folders in tabs")); | | |||
105 | topLayout->addRow(QString(), m_openExternallyCalledFolderInNewTab); | | |||
106 | | ||||
107 | 124 | | |||
108 | loadSettings(); | 125 | loadSettings(); | ||
109 | 126 | | |||
127 | updateInitialViewOptions(); | ||||
128 | | ||||
110 | connect(m_homeUrl, &QLineEdit::textChanged, this, &StartupSettingsPage::slotSettingsChanged); | 129 | connect(m_homeUrl, &QLineEdit::textChanged, this, &StartupSettingsPage::slotSettingsChanged); | ||
130 | connect(m_rememberOpenedTabsRadioButton, &QRadioButton::toggled, this, &StartupSettingsPage::slotSettingsChanged); | ||||
131 | connect(m_homeUrlRadioButton, &QRadioButton::toggled, this, &StartupSettingsPage::slotSettingsChanged); | ||||
132 | | ||||
elvisangelaccio: Please use a single line. | |||||
111 | connect(m_splitView, &QCheckBox::toggled, this, &StartupSettingsPage::slotSettingsChanged); | 133 | connect(m_splitView, &QCheckBox::toggled, this, &StartupSettingsPage::slotSettingsChanged); | ||
112 | connect(m_editableUrl, &QCheckBox::toggled, this, &StartupSettingsPage::slotSettingsChanged); | 134 | connect(m_editableUrl, &QCheckBox::toggled, this, &StartupSettingsPage::slotSettingsChanged); | ||
113 | connect(m_showFullPath, &QCheckBox::toggled, this, &StartupSettingsPage::slotSettingsChanged); | | |||
114 | connect(m_filterBar, &QCheckBox::toggled, this, &StartupSettingsPage::slotSettingsChanged); | 135 | connect(m_filterBar, &QCheckBox::toggled, this, &StartupSettingsPage::slotSettingsChanged); | ||
115 | connect(m_showFullPathInTitlebar, &QCheckBox::toggled, this, &StartupSettingsPage::slotSettingsChanged); | 136 | | ||
116 | connect(m_openExternallyCalledFolderInNewTab, &QCheckBox::toggled, this, &StartupSettingsPage::slotSettingsChanged); | 137 | connect(m_openExternallyCalledFolderInNewTab, &QCheckBox::toggled, this, &StartupSettingsPage::slotSettingsChanged); | ||
138 | connect(m_showFullPath, &QCheckBox::toggled, this, &StartupSettingsPage::slotSettingsChanged); | ||||
139 | connect(m_showFullPathInTitlebar, &QCheckBox::toggled, this, &StartupSettingsPage::slotSettingsChanged); | ||||
117 | } | 140 | } | ||
118 | 141 | | |||
119 | StartupSettingsPage::~StartupSettingsPage() | 142 | StartupSettingsPage::~StartupSettingsPage() | ||
120 | { | 143 | { | ||
121 | } | 144 | } | ||
122 | 145 | | |||
123 | void StartupSettingsPage::applySettings() | 146 | void StartupSettingsPage::applySettings() | ||
124 | { | 147 | { | ||
125 | GeneralSettings* settings = GeneralSettings::self(); | 148 | GeneralSettings* settings = GeneralSettings::self(); | ||
126 | 149 | | |||
127 | const QUrl url(QUrl::fromUserInput(m_homeUrl->text(), QString(), QUrl::AssumeLocalFile)); | 150 | const QUrl url(QUrl::fromUserInput(m_homeUrl->text(), QString(), QUrl::AssumeLocalFile)); | ||
128 | KFileItem fileItem(url); | 151 | KFileItem fileItem(url); | ||
129 | if ((url.isValid() && fileItem.isDir()) || (url.scheme() == QLatin1String("timeline"))) { | 152 | if ((url.isValid() && fileItem.isDir()) || (url.scheme() == QLatin1String("timeline"))) { | ||
130 | settings->setHomeUrl(url.toDisplayString(QUrl::PreferLocalFile)); | 153 | settings->setHomeUrl(url.toDisplayString(QUrl::PreferLocalFile)); | ||
131 | } else { | 154 | } else { | ||
132 | KMessageBox::error(this, i18nc("@info", "The location for the home folder is invalid or does not exist, it will not be applied.")); | 155 | KMessageBox::error(this, i18nc("@info", "The location for the home folder is invalid or does not exist, it will not be applied.")); | ||
133 | } | 156 | } | ||
134 | 157 | | |||
158 | // Remove saved state if "remember open tabs" has been turned off | ||||
feverfew: `state state`? | |||||
159 | if (!m_rememberOpenedTabsRadioButton->isChecked()) { | ||||
160 | KConfigGroup windowState{KSharedConfig::openConfig(QStringLiteral("dolphinrc")), "WindowState"}; | ||||
161 | if (windowState.exists()) { | ||||
162 | windowState.deleteGroup(); | ||||
163 | } | ||||
164 | } | ||||
165 | | ||||
166 | settings->setRememberOpenedTabs(m_rememberOpenedTabsRadioButton->isChecked()); | ||||
135 | settings->setSplitView(m_splitView->isChecked()); | 167 | settings->setSplitView(m_splitView->isChecked()); | ||
136 | settings->setEditableUrl(m_editableUrl->isChecked()); | 168 | settings->setEditableUrl(m_editableUrl->isChecked()); | ||
137 | settings->setShowFullPath(m_showFullPath->isChecked()); | | |||
138 | settings->setFilterBar(m_filterBar->isChecked()); | 169 | settings->setFilterBar(m_filterBar->isChecked()); | ||
139 | settings->setShowFullPathInTitlebar(m_showFullPathInTitlebar->isChecked()); | | |||
140 | settings->setOpenExternallyCalledFolderInNewTab(m_openExternallyCalledFolderInNewTab->isChecked()); | 170 | settings->setOpenExternallyCalledFolderInNewTab(m_openExternallyCalledFolderInNewTab->isChecked()); | ||
171 | settings->setShowFullPath(m_showFullPath->isChecked()); | ||||
172 | settings->setShowFullPathInTitlebar(m_showFullPathInTitlebar->isChecked()); | ||||
141 | settings->save(); | 173 | settings->save(); | ||
142 | } | 174 | } | ||
143 | 175 | | |||
144 | void StartupSettingsPage::restoreDefaults() | 176 | void StartupSettingsPage::restoreDefaults() | ||
145 | { | 177 | { | ||
146 | GeneralSettings* settings = GeneralSettings::self(); | 178 | GeneralSettings* settings = GeneralSettings::self(); | ||
147 | settings->useDefaults(true); | 179 | settings->useDefaults(true); | ||
148 | loadSettings(); | 180 | loadSettings(); | ||
149 | settings->useDefaults(false); | 181 | settings->useDefaults(false); | ||
150 | } | 182 | } | ||
151 | 183 | | |||
152 | void StartupSettingsPage::slotSettingsChanged() | 184 | void StartupSettingsPage::slotSettingsChanged() | ||
153 | { | 185 | { | ||
154 | // Provide a hint that the startup settings have been changed. This allows the views | 186 | // Provide a hint that the startup settings have been changed. This allows the views | ||
155 | // to apply the startup settings only if they have been explicitly changed by the user | 187 | // to apply the startup settings only if they have been explicitly changed by the user | ||
156 | // (see bug #254947). | 188 | // (see bug #254947). | ||
157 | GeneralSettings::setModifiedStartupSettings(true); | 189 | GeneralSettings::setModifiedStartupSettings(true); | ||
190 | | ||||
191 | // Enable and disable home URL controls appropriately | ||||
192 | updateInitialViewOptions(); | ||||
158 | emit changed(); | 193 | emit changed(); | ||
159 | } | 194 | } | ||
160 | 195 | | |||
196 | void StartupSettingsPage::updateInitialViewOptions() | ||||
197 | { | ||||
198 | m_homeUrlBoxLayoutContainer->setEnabled(m_homeUrlRadioButton->isChecked()); | ||||
199 | m_buttonBoxLayoutContainer->setEnabled(m_homeUrlRadioButton->isChecked()); | ||||
200 | } | ||||
201 | | ||||
161 | void StartupSettingsPage::selectHomeUrl() | 202 | void StartupSettingsPage::selectHomeUrl() | ||
162 | { | 203 | { | ||
163 | const QUrl homeUrl(QUrl::fromUserInput(m_homeUrl->text(), QString(), QUrl::AssumeLocalFile)); | 204 | const QUrl homeUrl(QUrl::fromUserInput(m_homeUrl->text(), QString(), QUrl::AssumeLocalFile)); | ||
164 | QUrl url = QFileDialog::getExistingDirectoryUrl(this, QString(), homeUrl); | 205 | QUrl url = QFileDialog::getExistingDirectoryUrl(this, QString(), homeUrl); | ||
165 | if (!url.isEmpty()) { | 206 | if (!url.isEmpty()) { | ||
166 | m_homeUrl->setText(url.toDisplayString(QUrl::PreferLocalFile)); | 207 | m_homeUrl->setText(url.toDisplayString(QUrl::PreferLocalFile)); | ||
167 | slotSettingsChanged(); | 208 | slotSettingsChanged(); | ||
168 | } | 209 | } | ||
169 | } | 210 | } | ||
170 | 211 | | |||
171 | void StartupSettingsPage::useCurrentLocation() | 212 | void StartupSettingsPage::useCurrentLocation() | ||
172 | { | 213 | { | ||
173 | m_homeUrl->setText(m_url.toDisplayString(QUrl::PreferLocalFile)); | 214 | m_homeUrl->setText(m_url.toDisplayString(QUrl::PreferLocalFile)); | ||
174 | } | 215 | } | ||
175 | 216 | | |||
176 | void StartupSettingsPage::useDefaultLocation() | 217 | void StartupSettingsPage::useDefaultLocation() | ||
177 | { | 218 | { | ||
178 | m_homeUrl->setText(QDir::homePath()); | 219 | m_homeUrl->setText(QDir::homePath()); | ||
179 | } | 220 | } | ||
180 | 221 | | |||
181 | void StartupSettingsPage::loadSettings() | 222 | void StartupSettingsPage::loadSettings() | ||
182 | { | 223 | { | ||
183 | const QUrl url(Dolphin::homeUrl()); | 224 | const QUrl url(Dolphin::homeUrl()); | ||
184 | m_homeUrl->setText(url.toDisplayString(QUrl::PreferLocalFile)); | 225 | m_homeUrl->setText(url.toDisplayString(QUrl::PreferLocalFile)); | ||
226 | m_rememberOpenedTabsRadioButton->setChecked(GeneralSettings::rememberOpenedTabs()); | ||||
227 | m_homeUrlRadioButton->setChecked(!GeneralSettings::rememberOpenedTabs()); | ||||
185 | m_splitView->setChecked(GeneralSettings::splitView()); | 228 | m_splitView->setChecked(GeneralSettings::splitView()); | ||
186 | m_editableUrl->setChecked(GeneralSettings::editableUrl()); | 229 | m_editableUrl->setChecked(GeneralSettings::editableUrl()); | ||
187 | m_showFullPath->setChecked(GeneralSettings::showFullPath()); | 230 | m_showFullPath->setChecked(GeneralSettings::showFullPath()); | ||
188 | m_filterBar->setChecked(GeneralSettings::filterBar()); | 231 | m_filterBar->setChecked(GeneralSettings::filterBar()); | ||
189 | m_showFullPathInTitlebar->setChecked(GeneralSettings::showFullPathInTitlebar()); | 232 | m_showFullPathInTitlebar->setChecked(GeneralSettings::showFullPathInTitlebar()); | ||
190 | m_openExternallyCalledFolderInNewTab->setChecked(GeneralSettings::openExternallyCalledFolderInNewTab()); | 233 | m_openExternallyCalledFolderInNewTab->setChecked(GeneralSettings::openExternallyCalledFolderInNewTab()); | ||
191 | } | 234 | } |
"Folders and tabs that were open before" => "Folders and tabs as they were opened before" Since we also restore split view and such. ?