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