]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.cpp
Keep working towards a reviewable state
[dolphin.git] / src / dolphinmainwindow.cpp
1 /*
2 * SPDX-FileCopyrightText: 2006 Peter Penz <peter.penz19@gmail.com>
3 * SPDX-FileCopyrightText: 2006 Stefan Monov <logixoul@gmail.com>
4 * SPDX-FileCopyrightText: 2006 Cvetoslav Ludmiloff <ludmiloff@gmail.com>
5 *
6 * SPDX-License-Identifier: GPL-2.0-or-later
7 */
8
9 #include "dolphinmainwindow.h"
10
11 #include "dolphinmainwindowadaptor.h"
12 #include "global.h"
13 #include "dolphinbookmarkhandler.h"
14 #include "dolphindockwidget.h"
15 #include "dolphincontextmenu.h"
16 #include "dolphinnavigatorswidgetaction.h"
17 #include "dolphinnewfilemenu.h"
18 #include "dolphinrecenttabsmenu.h"
19 #include "dolphinplacesmodelsingleton.h"
20 #include "dolphinurlnavigatorscontroller.h"
21 #include "dolphinviewcontainer.h"
22 #include "dolphintabpage.h"
23 #include "middleclickactioneventfilter.h"
24 #include "panels/folders/folderspanel.h"
25 #include "panels/places/placespanel.h"
26 #include "panels/terminal/terminalpanel.h"
27 #include "settings/dolphinsettingsdialog.h"
28 #include "statusbar/dolphinstatusbar.h"
29 #include "views/dolphinviewactionhandler.h"
30 #include "views/dolphinremoteencoding.h"
31 #include "views/draganddrophelper.h"
32 #include "views/viewproperties.h"
33 #include "views/dolphinnewfilemenuobserver.h"
34 #include "dolphin_generalsettings.h"
35
36 #include <KActionCollection>
37 #include <KActionMenu>
38 #include <KAuthorized>
39 #include <KConfig>
40 #include <KConfigGui>
41 #include <KDualAction>
42 #include <KFileItemListProperties>
43 #include <KHelpMenu>
44 #include <KIO/CommandLauncherJob>
45 #include <KIO/JobUiDelegate>
46 #include <KIO/OpenFileManagerWindowJob>
47 #include <KIO/OpenUrlJob>
48 #include <KJobWidgets>
49 #include <KLocalizedString>
50 #include <KMessageBox>
51 #include <KMoreToolsMenuFactory>
52 #include <KProtocolInfo>
53 #include <KProtocolManager>
54 #include <KShell>
55 #include <KShortcutsDialog>
56 #include <KStandardAction>
57 #include <KStartupInfo>
58 #include <KSycoca>
59 #include <KTerminalLauncherJob>
60 #include <KToggleAction>
61 #include <KToolBar>
62 #include <KToolBarPopupAction>
63 #include <KUrlComboBox>
64 #include <KUrlNavigator>
65 #include <KWindowSystem>
66 #include <KXMLGUIFactory>
67
68 #include <kio_version.h>
69
70 #include <QApplication>
71 #include <QClipboard>
72 #include <QCloseEvent>
73 #include <QDesktopServices>
74 #include <QDialog>
75 #include <QDomDocument>
76 #include <QFileInfo>
77 #include <QLineEdit>
78 #include <QMenuBar>
79 #include <QPushButton>
80 #include <QShowEvent>
81 #include <QStandardPaths>
82 #include <QTimer>
83 #include <QToolButton>
84 #include <QWhatsThisClickedEvent>
85
86 namespace {
87 // Used for GeneralSettings::version() to determine whether
88 // an updated version of Dolphin is running, so as to migrate
89 // removed/renamed ...etc config entries; increment it in such
90 // cases
91 const int CurrentDolphinVersion = 202;
92 // The maximum number of entries in the back/forward popup menu
93 const int MaxNumberOfNavigationentries = 12;
94 // The maximum number of "Activate Tab" shortcuts
95 const int MaxActivateTabShortcuts = 9;
96 }
97
98 DolphinMainWindow::DolphinMainWindow() :
99 KXmlGuiWindow(nullptr),
100 m_newFileMenu(nullptr),
101 m_helpMenu(nullptr),
102 m_tabWidget(nullptr),
103 m_activeViewContainer(nullptr),
104 m_actionHandler(nullptr),
105 m_remoteEncoding(nullptr),
106 m_settingsDialog(),
107 m_bookmarkHandler(nullptr),
108 m_controlButton(nullptr),
109 m_updateToolBarTimer(nullptr),
110 m_lastHandleUrlOpenJob(nullptr),
111 m_terminalPanel(nullptr),
112 m_placesPanel(nullptr),
113 m_tearDownFromPlacesRequested(false),
114 m_backAction(nullptr),
115 m_forwardAction(nullptr)
116 {
117 Q_INIT_RESOURCE(dolphin);
118
119 new MainWindowAdaptor(this);
120
121 #ifndef Q_OS_WIN
122 setWindowFlags(Qt::WindowContextHelpButtonHint);
123 #endif
124 setComponentName(QStringLiteral("dolphin"), QGuiApplication::applicationDisplayName());
125 setObjectName(QStringLiteral("Dolphin#"));
126
127 setStateConfigGroup("State");
128
129 connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::errorMessage,
130 this, &DolphinMainWindow::showErrorMessage);
131
132 KIO::FileUndoManager* undoManager = KIO::FileUndoManager::self();
133 undoManager->setUiInterface(new UndoUiInterface());
134
135 connect(undoManager, &KIO::FileUndoManager::undoAvailable,
136 this, &DolphinMainWindow::slotUndoAvailable);
137 connect(undoManager, &KIO::FileUndoManager::undoTextChanged,
138 this, &DolphinMainWindow::slotUndoTextChanged);
139 connect(undoManager, &KIO::FileUndoManager::jobRecordingStarted,
140 this, &DolphinMainWindow::clearStatusBar);
141 connect(undoManager, &KIO::FileUndoManager::jobRecordingFinished,
142 this, &DolphinMainWindow::showCommand);
143
144 const bool firstRun = (GeneralSettings::version() < 200);
145 if (firstRun) {
146 GeneralSettings::setViewPropsTimestamp(QDateTime::currentDateTime());
147 }
148
149 setAcceptDrops(true);
150
151 auto *navigatorsWidgetAction = new DolphinNavigatorsWidgetAction(this);
152 actionCollection()->addAction(QStringLiteral("url_navigators"), navigatorsWidgetAction);
153 m_tabWidget = new DolphinTabWidget(navigatorsWidgetAction, this);
154 m_tabWidget->setObjectName("tabWidget");
155 connect(m_tabWidget, &DolphinTabWidget::activeViewChanged,
156 this, &DolphinMainWindow::activeViewChanged);
157 connect(m_tabWidget, &DolphinTabWidget::tabCountChanged,
158 this, &DolphinMainWindow::tabCountChanged);
159 connect(m_tabWidget, &DolphinTabWidget::currentUrlChanged,
160 this, &DolphinMainWindow::updateWindowTitle);
161 setCentralWidget(m_tabWidget);
162
163 setupActions();
164
165 m_actionHandler = new DolphinViewActionHandler(actionCollection(), this);
166 connect(m_actionHandler, &DolphinViewActionHandler::actionBeingHandled, this, &DolphinMainWindow::clearStatusBar);
167 connect(m_actionHandler, &DolphinViewActionHandler::createDirectoryTriggered, this, &DolphinMainWindow::createDirectory);
168 connect(m_actionHandler, &DolphinViewActionHandler::setSelectionMode, this, &DolphinMainWindow::slotSetSelectionMode);
169
170 m_remoteEncoding = new DolphinRemoteEncoding(this, m_actionHandler);
171 connect(this, &DolphinMainWindow::urlChanged,
172 m_remoteEncoding, &DolphinRemoteEncoding::slotAboutToOpenUrl);
173
174 setupDockWidgets();
175
176 setupGUI(Save | Create | ToolBar);
177 stateChanged(QStringLiteral("new_file"));
178
179 QClipboard* clipboard = QApplication::clipboard();
180 connect(clipboard, &QClipboard::dataChanged,
181 this, &DolphinMainWindow::updatePasteAction);
182
183 QAction* toggleFilterBarAction = actionCollection()->action(QStringLiteral("toggle_filter"));
184 toggleFilterBarAction->setChecked(GeneralSettings::filterBar());
185
186 if (firstRun) {
187 menuBar()->setVisible(false);
188 }
189
190 const bool showMenu = !menuBar()->isHidden();
191 QAction* showMenuBarAction = actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar));
192 showMenuBarAction->setChecked(showMenu); // workaround for bug #171080
193
194 auto hamburgerMenu = static_cast<KHamburgerMenu *>(actionCollection()->action(
195 KStandardAction::name(KStandardAction::HamburgerMenu)));
196 hamburgerMenu->setMenuBar(menuBar());
197 hamburgerMenu->setShowMenuBarAction(showMenuBarAction);
198 connect(hamburgerMenu, &KHamburgerMenu::aboutToShowMenu,
199 this, &DolphinMainWindow::updateHamburgerMenu);
200 hamburgerMenu->hideActionsOf(toolBar());
201 if (GeneralSettings::version() < 201 && !toolBar()->actions().contains(hamburgerMenu)) {
202 addHamburgerMenuToToolbar();
203 }
204
205 updateAllowedToolbarAreas();
206
207 // enable middle-click on back/forward/up to open in a new tab
208 auto *middleClickEventFilter = new MiddleClickActionEventFilter(this);
209 connect(middleClickEventFilter, &MiddleClickActionEventFilter::actionMiddleClicked, this, &DolphinMainWindow::slotToolBarActionMiddleClicked);
210 toolBar()->installEventFilter(middleClickEventFilter);
211
212 setupWhatsThis();
213
214 connect(KSycoca::self(), &KSycoca::databaseChanged, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction);
215
216 QTimer::singleShot(0, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction);
217
218 m_fileItemActions.setParentWidget(this);
219 connect(&m_fileItemActions, &KFileItemActions::error, this, [this](const QString &errorMessage) {
220 showErrorMessage(errorMessage);
221 });
222
223 connect(GeneralSettings::self(), &GeneralSettings::splitViewChanged,
224 this, &DolphinMainWindow::slotSplitViewChanged);
225 }
226
227 DolphinMainWindow::~DolphinMainWindow()
228 {
229 // This fixes a crash on Wayland when closing the mainwindow while another dialog is open.
230 disconnect(QGuiApplication::clipboard(), &QClipboard::dataChanged, this, &DolphinMainWindow::updatePasteAction);
231 }
232
233 QVector<DolphinViewContainer*> DolphinMainWindow::viewContainers() const
234 {
235 QVector<DolphinViewContainer*> viewContainers;
236
237 for (int i = 0; i < m_tabWidget->count(); ++i) {
238 DolphinTabPage *tabPage = m_tabWidget->tabPageAt(i);
239
240 viewContainers << tabPage->primaryViewContainer();
241 if (tabPage->splitViewEnabled()) {
242 viewContainers << tabPage->secondaryViewContainer();
243 }
244 }
245 return viewContainers;
246 }
247
248 void DolphinMainWindow::openDirectories(const QList<QUrl>& dirs, bool splitView)
249 {
250 m_tabWidget->openDirectories(dirs, splitView);
251 }
252
253 void DolphinMainWindow::openDirectories(const QStringList& dirs, bool splitView)
254 {
255 openDirectories(QUrl::fromStringList(dirs), splitView);
256 }
257
258 void DolphinMainWindow::openFiles(const QList<QUrl>& files, bool splitView)
259 {
260 m_tabWidget->openFiles(files, splitView);
261 }
262
263 bool DolphinMainWindow::isFoldersPanelEnabled() const
264 {
265 return actionCollection()->action(QStringLiteral("show_folders_panel"))->isChecked();
266 }
267
268 bool DolphinMainWindow::isInformationPanelEnabled() const
269 {
270 #if HAVE_BALOO
271 return actionCollection()->action(QStringLiteral("show_information_panel"))->isChecked();
272 #else
273 return false;
274 #endif
275 }
276
277 void DolphinMainWindow::openFiles(const QStringList& files, bool splitView)
278 {
279 openFiles(QUrl::fromStringList(files), splitView);
280 }
281
282 void DolphinMainWindow::activateWindow()
283 {
284 window()->setAttribute(Qt::WA_NativeWindow, true);
285 KStartupInfo::setNewStartupId(window()->windowHandle(), KStartupInfo::startupId());
286 KWindowSystem::activateWindow(window()->effectiveWinId());
287 }
288
289 bool DolphinMainWindow::isActiveWindow()
290 {
291 return window()->isActiveWindow();
292 }
293
294 void DolphinMainWindow::showCommand(CommandType command)
295 {
296 DolphinStatusBar* statusBar = m_activeViewContainer->statusBar();
297 switch (command) {
298 case KIO::FileUndoManager::Copy:
299 statusBar->setText(i18nc("@info:status", "Successfully copied."));
300 break;
301 case KIO::FileUndoManager::Move:
302 statusBar->setText(i18nc("@info:status", "Successfully moved."));
303 break;
304 case KIO::FileUndoManager::Link:
305 statusBar->setText(i18nc("@info:status", "Successfully linked."));
306 break;
307 case KIO::FileUndoManager::Trash:
308 statusBar->setText(i18nc("@info:status", "Successfully moved to trash."));
309 break;
310 case KIO::FileUndoManager::Rename:
311 statusBar->setText(i18nc("@info:status", "Successfully renamed."));
312 break;
313
314 case KIO::FileUndoManager::Mkdir:
315 statusBar->setText(i18nc("@info:status", "Created folder."));
316 break;
317
318 default:
319 break;
320 }
321 }
322
323 void DolphinMainWindow::pasteIntoFolder()
324 {
325 m_activeViewContainer->view()->pasteIntoFolder();
326 }
327
328 void DolphinMainWindow::changeUrl(const QUrl &url)
329 {
330 if (!KProtocolManager::supportsListing(url)) {
331 // The URL navigator only checks for validity, not
332 // if the URL can be listed. An error message is
333 // shown due to DolphinViewContainer::restoreView().
334 return;
335 }
336
337 m_activeViewContainer->setUrl(url);
338 updateFileAndEditActions();
339 updatePasteAction();
340 updateViewActions();
341 updateGoActions();
342
343 Q_EMIT urlChanged(url);
344 }
345
346 void DolphinMainWindow::slotTerminalDirectoryChanged(const QUrl& url)
347 {
348 if (m_tearDownFromPlacesRequested && url == QUrl::fromLocalFile(QDir::homePath())) {
349 m_placesPanel->proceedWithTearDown();
350 m_tearDownFromPlacesRequested = false;
351 }
352
353 m_activeViewContainer->setAutoGrabFocus(false);
354 changeUrl(url);
355 m_activeViewContainer->setAutoGrabFocus(true);
356 }
357
358 void DolphinMainWindow::slotEditableStateChanged(bool editable)
359 {
360 KToggleAction* editableLocationAction =
361 static_cast<KToggleAction*>(actionCollection()->action(QStringLiteral("editable_location")));
362 editableLocationAction->setChecked(editable);
363 }
364
365 void DolphinMainWindow::slotSelectionChanged(const KFileItemList& selection)
366 {
367 updateFileAndEditActions();
368
369 const int selectedUrlsCount = m_tabWidget->currentTabPage()->selectedItemsCount();
370
371 QAction* compareFilesAction = actionCollection()->action(QStringLiteral("compare_files"));
372 if (selectedUrlsCount == 2) {
373 compareFilesAction->setEnabled(isKompareInstalled());
374 } else {
375 compareFilesAction->setEnabled(false);
376 }
377
378 Q_EMIT selectionChanged(selection);
379 }
380
381 void DolphinMainWindow::updateHistory()
382 {
383 const KUrlNavigator *urlNavigator = m_activeViewContainer->urlNavigatorInternalWithHistory();
384 const int index = urlNavigator->historyIndex();
385
386 QAction* backAction = actionCollection()->action(KStandardAction::name(KStandardAction::Back));
387 if (backAction) {
388 backAction->setToolTip(i18nc("@info", "Go back"));
389 backAction->setWhatsThis(i18nc("@info:whatsthis go back", "Return to the previously viewed folder."));
390 backAction->setEnabled(index < urlNavigator->historySize() - 1);
391 }
392
393 QAction* forwardAction = actionCollection()->action(KStandardAction::name(KStandardAction::Forward));
394 if (forwardAction) {
395 forwardAction->setToolTip(i18nc("@info", "Go forward"));
396 forwardAction->setWhatsThis(xi18nc("@info:whatsthis go forward",
397 "This undoes a <interface>Go|Back</interface> action."));
398 forwardAction->setEnabled(index > 0);
399 }
400 }
401
402 void DolphinMainWindow::updateFilterBarAction(bool show)
403 {
404 QAction* toggleFilterBarAction = actionCollection()->action(QStringLiteral("toggle_filter"));
405 toggleFilterBarAction->setChecked(show);
406 }
407
408 void DolphinMainWindow::openNewMainWindow()
409 {
410 Dolphin::openNewWindow({m_activeViewContainer->url()}, this);
411 }
412
413 void DolphinMainWindow::openNewActivatedTab()
414 {
415 // keep browsers compatibility, new tab is always after last one
416 auto openNewTabAfterLastTabConfigured = GeneralSettings::openNewTabAfterLastTab();
417 GeneralSettings::setOpenNewTabAfterLastTab(true);
418 m_tabWidget->openNewActivatedTab();
419 GeneralSettings::setOpenNewTabAfterLastTab(openNewTabAfterLastTabConfigured);
420 }
421
422 void DolphinMainWindow::addToPlaces()
423 {
424 QUrl url;
425 QString name;
426
427 // If nothing is selected, act on the current dir
428 if (m_activeViewContainer->view()->selectedItems().isEmpty()) {
429 url = m_activeViewContainer->url();
430 name = m_activeViewContainer->placesText();
431 } else {
432 const auto dirToAdd = m_activeViewContainer->view()->selectedItems().first();
433 url = dirToAdd.url();
434 name = dirToAdd.name();
435 }
436 if (url.isValid()) {
437 QString icon;
438 if (m_activeViewContainer->isSearchModeEnabled()) {
439 icon = QStringLiteral("folder-saved-search-symbolic");
440 } else {
441 icon = KIO::iconNameForUrl(url);
442 }
443 DolphinPlacesModelSingleton::instance().placesModel()->addPlace(name, url, icon);
444 }
445 }
446
447 void DolphinMainWindow::openNewTab(const QUrl& url)
448 {
449 m_tabWidget->openNewTab(url, QUrl());
450 }
451
452 void DolphinMainWindow::openNewTabAndActivate(const QUrl &url)
453 {
454 m_tabWidget->openNewActivatedTab(url, QUrl());
455 }
456
457 void DolphinMainWindow::openNewWindow(const QUrl &url)
458 {
459 Dolphin::openNewWindow({url}, this);
460 }
461
462 void DolphinMainWindow::slotSplitViewChanged()
463 {
464 m_tabWidget->currentTabPage()->setSplitViewEnabled(GeneralSettings::splitView(), WithAnimation);
465 updateSplitAction();
466 }
467
468 void DolphinMainWindow::openInNewTab()
469 {
470 const KFileItemList& list = m_activeViewContainer->view()->selectedItems();
471 bool tabCreated = false;
472
473 for (const KFileItem& item : list) {
474 const QUrl& url = DolphinView::openItemAsFolderUrl(item);
475 if (!url.isEmpty()) {
476 openNewTab(url);
477 tabCreated = true;
478 }
479 }
480
481 // if no new tab has been created from the selection
482 // open the current directory in a new tab
483 if (!tabCreated) {
484 openNewTab(m_activeViewContainer->url());
485 }
486 }
487
488 void DolphinMainWindow::openInNewWindow()
489 {
490 QUrl newWindowUrl;
491
492 const KFileItemList list = m_activeViewContainer->view()->selectedItems();
493 if (list.isEmpty()) {
494 newWindowUrl = m_activeViewContainer->url();
495 } else if (list.count() == 1) {
496 const KFileItem& item = list.first();
497 newWindowUrl = DolphinView::openItemAsFolderUrl(item);
498 }
499
500 if (!newWindowUrl.isEmpty()) {
501 Dolphin::openNewWindow({newWindowUrl}, this);
502 }
503 }
504
505 void DolphinMainWindow::showTarget()
506 {
507 const auto link = m_activeViewContainer->view()->selectedItems().at(0);
508 const auto linkLocationDir = QFileInfo(link.localPath()).absoluteDir();
509 auto linkDestination = link.linkDest();
510 if (QFileInfo(linkDestination).isRelative()) {
511 linkDestination = linkLocationDir.filePath(linkDestination);
512 }
513 if (QFileInfo::exists(linkDestination)) {
514 KIO::highlightInFileManager({QUrl::fromLocalFile(linkDestination).adjusted(QUrl::StripTrailingSlash)});
515 } else {
516 m_activeViewContainer->showMessage(xi18nc("@info", "Could not access <filename>%1</filename>.", linkDestination),
517 DolphinViewContainer::Warning);
518 }
519 }
520
521 void DolphinMainWindow::showEvent(QShowEvent* event)
522 {
523 KXmlGuiWindow::showEvent(event);
524
525 if (!event->spontaneous()) {
526 m_activeViewContainer->view()->setFocus();
527 }
528 }
529
530 void DolphinMainWindow::closeEvent(QCloseEvent* event)
531 {
532 // Find out if Dolphin is closed directly by the user or
533 // by the session manager because the session is closed
534 bool closedByUser = true;
535 if (qApp->isSavingSession()) {
536 closedByUser = false;
537 }
538
539 if (m_tabWidget->count() > 1
540 && GeneralSettings::confirmClosingMultipleTabs()
541 && !GeneralSettings::rememberOpenedTabs()
542 && closedByUser) {
543 // Ask the user if he really wants to quit and close all tabs.
544 // Open a confirmation dialog with 3 buttons:
545 // QDialogButtonBox::Yes -> Quit
546 // QDialogButtonBox::No -> Close only the current tab
547 // QDialogButtonBox::Cancel -> do nothing
548 QDialog *dialog = new QDialog(this, Qt::Dialog);
549 dialog->setWindowTitle(i18nc("@title:window", "Confirmation"));
550 dialog->setModal(true);
551 QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Yes | QDialogButtonBox::No | QDialogButtonBox::Cancel);
552 KGuiItem::assign(buttons->button(QDialogButtonBox::Yes), KGuiItem(i18nc("@action:button 'Quit Dolphin' button", "&Quit %1", QGuiApplication::applicationDisplayName()), QIcon::fromTheme(QStringLiteral("application-exit"))));
553 KGuiItem::assign(buttons->button(QDialogButtonBox::No), KGuiItem(i18n("C&lose Current Tab"), QIcon::fromTheme(QStringLiteral("tab-close"))));
554 KGuiItem::assign(buttons->button(QDialogButtonBox::Cancel), KStandardGuiItem::cancel());
555 buttons->button(QDialogButtonBox::Yes)->setDefault(true);
556
557 bool doNotAskAgainCheckboxResult = false;
558
559 const auto result = KMessageBox::createKMessageBox(dialog,
560 buttons,
561 QMessageBox::Warning,
562 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
563 QStringList(),
564 i18n("Do not ask again"),
565 &doNotAskAgainCheckboxResult,
566 KMessageBox::Notify);
567
568 if (doNotAskAgainCheckboxResult) {
569 GeneralSettings::setConfirmClosingMultipleTabs(false);
570 }
571
572 switch (result) {
573 case QDialogButtonBox::Yes:
574 // Quit
575 break;
576 case QDialogButtonBox::No:
577 // Close only the current tab
578 m_tabWidget->closeTab();
579 Q_FALLTHROUGH();
580 default:
581 event->ignore();
582 return;
583 }
584 }
585
586 if (m_terminalPanel && m_terminalPanel->hasProgramRunning() && GeneralSettings::confirmClosingTerminalRunningProgram() && closedByUser) {
587 // Ask if the user really wants to quit Dolphin with a program that is still running in the Terminal panel
588 // Open a confirmation dialog with 3 buttons:
589 // QDialogButtonBox::Yes -> Quit
590 // QDialogButtonBox::No -> Show Terminal Panel
591 // QDialogButtonBox::Cancel -> do nothing
592 QDialog *dialog = new QDialog(this, Qt::Dialog);
593 dialog->setWindowTitle(i18nc("@title:window", "Confirmation"));
594 dialog->setModal(true);
595 auto standardButtons = QDialogButtonBox::Yes | QDialogButtonBox::Cancel;
596 if (!m_terminalPanel->isVisible()) {
597 standardButtons |= QDialogButtonBox::No;
598 }
599 QDialogButtonBox *buttons = new QDialogButtonBox(standardButtons);
600 KGuiItem::assign(buttons->button(QDialogButtonBox::Yes), KStandardGuiItem::quit());
601 if (!m_terminalPanel->isVisible()) {
602 KGuiItem::assign(
603 buttons->button(QDialogButtonBox::No),
604 KGuiItem(i18n("Show &Terminal Panel"), QIcon::fromTheme(QStringLiteral("dialog-scripts"))));
605 }
606 KGuiItem::assign(buttons->button(QDialogButtonBox::Cancel), KStandardGuiItem::cancel());
607
608 bool doNotAskAgainCheckboxResult = false;
609
610 const auto result = KMessageBox::createKMessageBox(
611 dialog,
612 buttons,
613 QMessageBox::Warning,
614 i18n("The program '%1' is still running in the Terminal panel. Are you sure you want to quit?", m_terminalPanel->runningProgramName()),
615 QStringList(),
616 i18n("Do not ask again"),
617 &doNotAskAgainCheckboxResult,
618 KMessageBox::Dangerous);
619
620 if (doNotAskAgainCheckboxResult) {
621 GeneralSettings::setConfirmClosingTerminalRunningProgram(false);
622 }
623
624 switch (result) {
625 case QDialogButtonBox::Yes:
626 // Quit
627 break;
628 case QDialogButtonBox::No:
629 actionCollection()->action("show_terminal_panel")->trigger();
630 // Do not quit, ignore quit event
631 Q_FALLTHROUGH();
632 default:
633 event->ignore();
634 return;
635 }
636 }
637
638 if (GeneralSettings::rememberOpenedTabs()) {
639 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
640 KConfig *config = KConfigGui::sessionConfig();
641 saveGlobalProperties(config);
642 savePropertiesInternal(config, 1);
643 config->sync();
644 }
645
646 GeneralSettings::setVersion(CurrentDolphinVersion);
647 GeneralSettings::self()->save();
648
649 KXmlGuiWindow::closeEvent(event);
650 }
651
652 void DolphinMainWindow::saveProperties(KConfigGroup& group)
653 {
654 m_tabWidget->saveProperties(group);
655 }
656
657 void DolphinMainWindow::readProperties(const KConfigGroup& group)
658 {
659 m_tabWidget->readProperties(group);
660 }
661
662 void DolphinMainWindow::updateNewMenu()
663 {
664 m_newFileMenu->checkUpToDate();
665 #if KIO_VERSION >= QT_VERSION_CHECK(5, 97, 0)
666 m_newFileMenu->setWorkingDirectory(activeViewContainer()->url());
667 #else
668 m_newFileMenu->setPopupFiles(QList<QUrl>() << activeViewContainer()->url());
669 #endif
670 }
671
672 void DolphinMainWindow::createDirectory()
673 {
674 #if KIO_VERSION >= QT_VERSION_CHECK(5, 97, 0)
675 m_newFileMenu->setWorkingDirectory(activeViewContainer()->url());
676 #else
677 m_newFileMenu->setPopupFiles(QList<QUrl>() << activeViewContainer()->url());
678 #endif
679 m_newFileMenu->createDirectory();
680 }
681
682 void DolphinMainWindow::quit()
683 {
684 close();
685 }
686
687 void DolphinMainWindow::showErrorMessage(const QString& message)
688 {
689 m_activeViewContainer->showMessage(message, DolphinViewContainer::Error);
690 }
691
692 void DolphinMainWindow::slotUndoAvailable(bool available)
693 {
694 QAction* undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo));
695 if (undoAction) {
696 undoAction->setEnabled(available);
697 }
698 }
699
700 void DolphinMainWindow::slotUndoTextChanged(const QString& text)
701 {
702 QAction* undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo));
703 if (undoAction) {
704 undoAction->setText(text);
705 }
706 }
707
708 void DolphinMainWindow::undo()
709 {
710 clearStatusBar();
711 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
712 KIO::FileUndoManager::self()->undo();
713 }
714
715 void DolphinMainWindow::cut()
716 {
717 if (m_activeViewContainer->view()->selectedItems().isEmpty()) {
718 m_activeViewContainer->setSelectionModeEnabled(true, actionCollection(), SelectionModeBottomBar::Contents::CutContents);
719 } else {
720 m_activeViewContainer->view()->cutSelectedItemsToClipboard();
721 m_activeViewContainer->setSelectionModeEnabled(false);
722 }
723 }
724
725 void DolphinMainWindow::copy()
726 {
727 if (m_activeViewContainer->view()->selectedItems().isEmpty()) {
728 m_activeViewContainer->setSelectionModeEnabled(true, actionCollection(), SelectionModeBottomBar::Contents::CopyContents);
729 } else {
730 m_activeViewContainer->view()->copySelectedItemsToClipboard();
731 m_activeViewContainer->setSelectionModeEnabled(false);
732 }
733 }
734
735 void DolphinMainWindow::paste()
736 {
737 m_activeViewContainer->view()->paste();
738 }
739
740 void DolphinMainWindow::find()
741 {
742 m_activeViewContainer->setSearchModeEnabled(true);
743 }
744
745 void DolphinMainWindow::updateSearchAction()
746 {
747 QAction* toggleSearchAction = actionCollection()->action(QStringLiteral("toggle_search"));
748 toggleSearchAction->setChecked(m_activeViewContainer->isSearchModeEnabled());
749 }
750
751 void DolphinMainWindow::updatePasteAction()
752 {
753 QAction* pasteAction = actionCollection()->action(KStandardAction::name(KStandardAction::Paste));
754 QPair<bool, QString> pasteInfo = m_activeViewContainer->view()->pasteInfo();
755 pasteAction->setEnabled(pasteInfo.first);
756 pasteAction->setText(pasteInfo.second);
757 }
758
759 void DolphinMainWindow::slotDirectoryLoadingCompleted()
760 {
761 updatePasteAction();
762 }
763
764 void DolphinMainWindow::slotToolBarActionMiddleClicked(QAction *action)
765 {
766 if (action == actionCollection()->action(KStandardAction::name(KStandardAction::Back))) {
767 goBackInNewTab();
768 } else if (action == actionCollection()->action(KStandardAction::name(KStandardAction::Forward))) {
769 goForwardInNewTab();
770 } else if (action == actionCollection()->action(QStringLiteral("go_up"))) {
771 goUpInNewTab();
772 } else if (action == actionCollection()->action(QStringLiteral("go_home"))) {
773 goHomeInNewTab();
774 }
775 }
776
777 QAction *DolphinMainWindow::urlNavigatorHistoryAction(const KUrlNavigator *urlNavigator, int historyIndex, QObject *parent)
778 {
779 const QUrl url = urlNavigator->locationUrl(historyIndex);
780
781 QString text = url.toDisplayString(QUrl::PreferLocalFile);
782
783 if (!urlNavigator->showFullPath()) {
784 const KFilePlacesModel *placesModel = DolphinPlacesModelSingleton::instance().placesModel();
785
786 const QModelIndex closestIdx = placesModel->closestItem(url);
787 if (closestIdx.isValid()) {
788 const QUrl placeUrl = placesModel->url(closestIdx);
789
790 text = placesModel->text(closestIdx);
791
792 QString pathInsidePlace = url.path().mid(placeUrl.path().length());
793
794 if (!pathInsidePlace.isEmpty() && !pathInsidePlace.startsWith(QLatin1Char('/'))) {
795 pathInsidePlace.prepend(QLatin1Char('/'));
796 }
797
798 if (pathInsidePlace != QLatin1Char('/')) {
799 text.append(pathInsidePlace);
800 }
801 }
802 }
803
804 QAction *action = new QAction(QIcon::fromTheme(KIO::iconNameForUrl(url)), text, parent);
805 action->setData(historyIndex);
806 return action;
807 }
808
809 void DolphinMainWindow::slotAboutToShowBackPopupMenu()
810 {
811 const KUrlNavigator *urlNavigator = m_activeViewContainer->urlNavigatorInternalWithHistory();
812 int entries = 0;
813 m_backAction->menu()->clear();
814 for (int i = urlNavigator->historyIndex() + 1; i < urlNavigator->historySize() && entries < MaxNumberOfNavigationentries; ++i, ++entries) {
815 QAction *action = urlNavigatorHistoryAction(urlNavigator, i, m_backAction->menu());
816 action->setData(i);
817 m_backAction->menu()->addAction(action);
818 }
819 }
820
821 void DolphinMainWindow::slotGoBack(QAction* action)
822 {
823 int gotoIndex = action->data().value<int>();
824 const KUrlNavigator *urlNavigator = m_activeViewContainer->urlNavigatorInternalWithHistory();
825 for (int i = gotoIndex - urlNavigator->historyIndex(); i > 0; --i) {
826 goBack();
827 }
828 }
829
830 void DolphinMainWindow::slotBackForwardActionMiddleClicked(QAction* action)
831 {
832 if (action) {
833 const KUrlNavigator *urlNavigator = activeViewContainer()->urlNavigatorInternalWithHistory();
834 openNewTab(urlNavigator->locationUrl(action->data().value<int>()));
835 }
836 }
837
838 void DolphinMainWindow::slotAboutToShowForwardPopupMenu()
839 {
840 const KUrlNavigator *urlNavigator = m_activeViewContainer->urlNavigatorInternalWithHistory();
841 int entries = 0;
842 m_forwardAction->menu()->clear();
843 for (int i = urlNavigator->historyIndex() - 1; i >= 0 && entries < MaxNumberOfNavigationentries; --i, ++entries) {
844 QAction *action = urlNavigatorHistoryAction(urlNavigator, i, m_forwardAction->menu());
845 action->setData(i);
846 m_forwardAction->menu()->addAction(action);
847 }
848 }
849
850 void DolphinMainWindow::slotGoForward(QAction* action)
851 {
852 int gotoIndex = action->data().value<int>();
853 const KUrlNavigator *urlNavigator = m_activeViewContainer->urlNavigatorInternalWithHistory();
854 for (int i = urlNavigator->historyIndex() - gotoIndex; i > 0; --i) {
855 goForward();
856 }
857 }
858
859 void DolphinMainWindow::slotSetSelectionMode(bool enabled, SelectionModeBottomBar::Contents bottomBarContents)
860 {
861 m_activeViewContainer->setSelectionModeEnabled(enabled, actionCollection(), bottomBarContents);
862 }
863
864 void DolphinMainWindow::selectAll()
865 {
866 clearStatusBar();
867
868 // if the URL navigator is editable and focused, select the whole
869 // URL instead of all items of the view
870
871 KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
872 QLineEdit* lineEdit = urlNavigator->editor()->lineEdit();
873 const bool selectUrl = urlNavigator->isUrlEditable() &&
874 lineEdit->hasFocus();
875 if (selectUrl) {
876 lineEdit->selectAll();
877 } else {
878 m_activeViewContainer->view()->selectAll();
879 }
880 }
881
882 void DolphinMainWindow::invertSelection()
883 {
884 clearStatusBar();
885 m_activeViewContainer->view()->invertSelection();
886 }
887
888 void DolphinMainWindow::toggleSplitView()
889 {
890 DolphinTabPage* tabPage = m_tabWidget->currentTabPage();
891 tabPage->setSplitViewEnabled(!tabPage->splitViewEnabled(), WithAnimation);
892
893 updateViewActions();
894 }
895
896 void DolphinMainWindow::toggleSplitStash()
897 {
898 DolphinTabPage* tabPage = m_tabWidget->currentTabPage();
899 tabPage->setSplitViewEnabled(false, WithAnimation);
900 tabPage->setSplitViewEnabled(true, WithAnimation, QUrl("stash:/"));
901 }
902
903 void DolphinMainWindow::copyToInactiveSplitView()
904 {
905 if (m_activeViewContainer->view()->selectedItems().isEmpty()) {
906 m_activeViewContainer->setSelectionModeEnabled(true, actionCollection(), SelectionModeBottomBar::Contents::CopyToOtherViewContents);
907 } else {
908 m_tabWidget->copyToInactiveSplitView();
909 m_activeViewContainer->setSelectionModeEnabled(false);
910 }
911 }
912
913 void DolphinMainWindow::moveToInactiveSplitView()
914 {
915 if (m_activeViewContainer->view()->selectedItems().isEmpty()) {
916 m_activeViewContainer->setSelectionModeEnabled(true, actionCollection(), SelectionModeBottomBar::Contents::MoveToOtherViewContents);
917 } else {
918 m_tabWidget->moveToInactiveSplitView();
919 m_activeViewContainer->setSelectionModeEnabled(false);
920 }
921 }
922
923 void DolphinMainWindow::reloadView()
924 {
925 clearStatusBar();
926 m_activeViewContainer->reload();
927 m_activeViewContainer->statusBar()->updateSpaceInfo();
928 }
929
930 void DolphinMainWindow::stopLoading()
931 {
932 m_activeViewContainer->view()->stopLoading();
933 }
934
935 void DolphinMainWindow::enableStopAction()
936 {
937 actionCollection()->action(QStringLiteral("stop"))->setEnabled(true);
938 }
939
940 void DolphinMainWindow::disableStopAction()
941 {
942 actionCollection()->action(QStringLiteral("stop"))->setEnabled(false);
943 }
944
945 void DolphinMainWindow::toggleSelectionMode()
946 {
947 const bool checked = !m_activeViewContainer->isSelectionModeEnabled();
948
949 m_activeViewContainer->setSelectionModeEnabled(checked, actionCollection(), SelectionModeBottomBar::Contents::GeneralContents);
950 actionCollection()->action(QStringLiteral("toggle_selection_mode"))->setChecked(checked);
951 }
952
953 void DolphinMainWindow::showFilterBar()
954 {
955 m_activeViewContainer->setFilterBarVisible(true);
956 }
957
958 void DolphinMainWindow::toggleFilterBar()
959 {
960 const bool checked = !m_activeViewContainer->isFilterBarVisible();
961 m_activeViewContainer->setFilterBarVisible(checked);
962
963 QAction* toggleFilterBarAction = actionCollection()->action(QStringLiteral("toggle_filter"));
964 toggleFilterBarAction->setChecked(checked);
965 }
966
967 void DolphinMainWindow::toggleEditLocation()
968 {
969 clearStatusBar();
970
971 QAction* action = actionCollection()->action(QStringLiteral("editable_location"));
972 KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
973 urlNavigator->setUrlEditable(action->isChecked());
974 }
975
976 void DolphinMainWindow::replaceLocation()
977 {
978 KUrlNavigator* navigator = m_activeViewContainer->urlNavigator();
979 QLineEdit* lineEdit = navigator->editor()->lineEdit();
980
981 // If the text field currently has focus and everything is selected,
982 // pressing the keyboard shortcut returns the whole thing to breadcrumb mode
983 if (navigator->isUrlEditable()
984 && lineEdit->hasFocus()
985 && lineEdit->selectedText() == lineEdit->text() ) {
986 navigator->setUrlEditable(false);
987 } else {
988 navigator->setUrlEditable(true);
989 navigator->setFocus();
990 lineEdit->selectAll();
991 }
992 }
993
994 void DolphinMainWindow::togglePanelLockState()
995 {
996 const bool newLockState = !GeneralSettings::lockPanels();
997 const auto childrenObjects = children();
998 for (QObject* child : childrenObjects) {
999 DolphinDockWidget* dock = qobject_cast<DolphinDockWidget*>(child);
1000 if (dock) {
1001 dock->setLocked(newLockState);
1002 }
1003 }
1004
1005 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(newLockState);
1006
1007 GeneralSettings::setLockPanels(newLockState);
1008 }
1009
1010 void DolphinMainWindow::slotTerminalPanelVisibilityChanged()
1011 {
1012 if (m_terminalPanel->isHiddenInVisibleWindow() && m_activeViewContainer) {
1013 m_activeViewContainer->view()->setFocus();
1014 }
1015 }
1016
1017 void DolphinMainWindow::goBack()
1018 {
1019 DolphinUrlNavigator *urlNavigator = m_activeViewContainer->urlNavigatorInternalWithHistory();
1020 urlNavigator->goBack();
1021
1022 if (urlNavigator->locationState().isEmpty()) {
1023 // An empty location state indicates a redirection URL,
1024 // which must be skipped too
1025 urlNavigator->goBack();
1026 }
1027 }
1028
1029 void DolphinMainWindow::goForward()
1030 {
1031 m_activeViewContainer->urlNavigatorInternalWithHistory()->goForward();
1032 }
1033
1034 void DolphinMainWindow::goUp()
1035 {
1036 m_activeViewContainer->urlNavigatorInternalWithHistory()->goUp();
1037 }
1038
1039 void DolphinMainWindow::goHome()
1040 {
1041 m_activeViewContainer->urlNavigatorInternalWithHistory()->goHome();
1042 }
1043
1044 void DolphinMainWindow::goBackInNewTab()
1045 {
1046 const KUrlNavigator* urlNavigator = activeViewContainer()->urlNavigatorInternalWithHistory();
1047 const int index = urlNavigator->historyIndex() + 1;
1048 openNewTab(urlNavigator->locationUrl(index));
1049 }
1050
1051 void DolphinMainWindow::goForwardInNewTab()
1052 {
1053 const KUrlNavigator* urlNavigator = activeViewContainer()->urlNavigatorInternalWithHistory();
1054 const int index = urlNavigator->historyIndex() - 1;
1055 openNewTab(urlNavigator->locationUrl(index));
1056 }
1057
1058 void DolphinMainWindow::goUpInNewTab()
1059 {
1060 const QUrl currentUrl = activeViewContainer()->urlNavigator()->locationUrl();
1061 openNewTab(KIO::upUrl(currentUrl));
1062 }
1063
1064 void DolphinMainWindow::goHomeInNewTab()
1065 {
1066 openNewTab(Dolphin::homeUrl());
1067 }
1068
1069 void DolphinMainWindow::compareFiles()
1070 {
1071 const KFileItemList items = m_tabWidget->currentTabPage()->selectedItems();
1072 if (items.count() != 2) {
1073 // The action is disabled in this case, but it could have been triggered
1074 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
1075 return;
1076 }
1077
1078 QUrl urlA = items.at(0).url();
1079 QUrl urlB = items.at(1).url();
1080
1081 QString command(QStringLiteral("kompare -c \""));
1082 command.append(urlA.toDisplayString(QUrl::PreferLocalFile));
1083 command.append("\" \"");
1084 command.append(urlB.toDisplayString(QUrl::PreferLocalFile));
1085 command.append('\"');
1086
1087 KIO::CommandLauncherJob *job = new KIO::CommandLauncherJob(command, this);
1088 job->setDesktopName(QStringLiteral("org.kde.kompare"));
1089 job->start();
1090 }
1091
1092 void DolphinMainWindow::toggleShowMenuBar()
1093 {
1094 const bool visible = menuBar()->isVisible();
1095 menuBar()->setVisible(!visible);
1096 }
1097
1098 QPointer<QAction> DolphinMainWindow::preferredSearchTool()
1099 {
1100 m_searchTools.clear();
1101 KMoreToolsMenuFactory("dolphin/search-tools").fillMenuFromGroupingNames(
1102 &m_searchTools, { "files-find" }, m_activeViewContainer->url()
1103 );
1104 QList<QAction*> actions = m_searchTools.actions();
1105 if (actions.isEmpty()) {
1106 return nullptr;
1107 }
1108 QAction* action = actions.first();
1109 if (action->isSeparator()) {
1110 return nullptr;
1111 }
1112 return action;
1113 }
1114
1115 void DolphinMainWindow::updateOpenPreferredSearchToolAction()
1116 {
1117 QAction* openPreferredSearchTool = actionCollection()->action(QStringLiteral("open_preferred_search_tool"));
1118 if (!openPreferredSearchTool) {
1119 return;
1120 }
1121 QPointer<QAction> tool = preferredSearchTool();
1122 if (tool) {
1123 openPreferredSearchTool->setVisible(true);
1124 openPreferredSearchTool->setText(i18nc("@action:inmenu Tools", "Open %1", tool->text()));
1125 // Only override with the app icon if it is the default, i.e. the user hasn't configured one manually
1126 // https://bugs.kde.org/show_bug.cgi?id=442815
1127 if (openPreferredSearchTool->icon().name() == QLatin1String("search")) {
1128 openPreferredSearchTool->setIcon(tool->icon());
1129 }
1130 } else {
1131 openPreferredSearchTool->setVisible(false);
1132 // still visible in Shortcuts configuration window
1133 openPreferredSearchTool->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1134 openPreferredSearchTool->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1135 }
1136 }
1137
1138 void DolphinMainWindow::openPreferredSearchTool()
1139 {
1140 QPointer<QAction> tool = preferredSearchTool();
1141 if (tool) {
1142 tool->trigger();
1143 }
1144 }
1145
1146 void DolphinMainWindow::openTerminal()
1147 {
1148 openTerminalJob(m_activeViewContainer->url());
1149 }
1150
1151 void DolphinMainWindow::openTerminalHere()
1152 {
1153 QList<QUrl> urls = {};
1154
1155 for (const KFileItem& item : m_activeViewContainer->view()->selectedItems()) {
1156 QUrl url = item.targetUrl();
1157 if (item.isFile()) {
1158 url.setPath(QFileInfo(url.path()).absolutePath());
1159 }
1160 if (!urls.contains(url)) {
1161 urls << url;
1162 }
1163 }
1164
1165 // No items are selected. Open a terminal window for the current location.
1166 if (urls.count() == 0) {
1167 openTerminal();
1168 return;
1169 }
1170
1171 if (urls.count() > 5) {
1172 QString question = i18np("Are you sure you want to open 1 terminal window?",
1173 "Are you sure you want to open %1 terminal windows?", urls.count());
1174 const int answer = KMessageBox::warningYesNo(this, question, {},
1175 KGuiItem(i18ncp("@action:button", "Open %1 Terminal", "Open %1 Terminals", urls.count()),
1176 QStringLiteral("utilities-terminal")),
1177 KStandardGuiItem::cancel());
1178 if (answer != KMessageBox::Yes) {
1179 return;
1180 }
1181 }
1182
1183 for (const QUrl& url : urls) {
1184 openTerminalJob(url);
1185 }
1186 }
1187
1188 void DolphinMainWindow::openTerminalJob(const QUrl& url)
1189 {
1190 if (url.isLocalFile()) {
1191 auto job = new KTerminalLauncherJob(QString());
1192 job->setWorkingDirectory(url.toLocalFile());
1193 job->start();
1194 return;
1195 }
1196
1197 // Not a local file, with protocol Class ":local", try stat'ing
1198 if (KProtocolInfo::protocolClass(url.scheme()) == QLatin1String(":local")) {
1199 KIO::StatJob *job = KIO::mostLocalUrl(url);
1200 KJobWidgets::setWindow(job, this);
1201 connect(job, &KJob::result, this, [job]() {
1202 QUrl statUrl;
1203 if (!job->error()) {
1204 statUrl = job->mostLocalUrl();
1205 }
1206
1207 auto job = new KTerminalLauncherJob(QString());
1208 job->setWorkingDirectory(statUrl.isLocalFile() ? statUrl.toLocalFile() : QDir::homePath());
1209 job->start();
1210 });
1211
1212 return;
1213 }
1214
1215 // Nothing worked, just use $HOME
1216 auto job = new KTerminalLauncherJob(QString());
1217 job->setWorkingDirectory(QDir::homePath());
1218 job->start();
1219 }
1220
1221 void DolphinMainWindow::editSettings()
1222 {
1223 if (!m_settingsDialog) {
1224 DolphinViewContainer* container = activeViewContainer();
1225 container->view()->writeSettings();
1226
1227 const QUrl url = container->url();
1228 DolphinSettingsDialog* settingsDialog = new DolphinSettingsDialog(url, this, actionCollection());
1229 connect(settingsDialog, &DolphinSettingsDialog::settingsChanged, this, &DolphinMainWindow::refreshViews);
1230 connect(settingsDialog, &DolphinSettingsDialog::settingsChanged,
1231 &DolphinUrlNavigatorsController::slotReadSettings);
1232 settingsDialog->setAttribute(Qt::WA_DeleteOnClose);
1233 settingsDialog->show();
1234 m_settingsDialog = settingsDialog;
1235 } else {
1236 m_settingsDialog.data()->raise();
1237 }
1238 }
1239
1240 void DolphinMainWindow::handleUrl(const QUrl& url)
1241 {
1242 delete m_lastHandleUrlOpenJob;
1243 m_lastHandleUrlOpenJob = nullptr;
1244
1245 if (url.isLocalFile() && QFileInfo(url.toLocalFile()).isDir()) {
1246 activeViewContainer()->setUrl(url);
1247 } else {
1248 m_lastHandleUrlOpenJob = new KIO::OpenUrlJob(url);
1249 m_lastHandleUrlOpenJob->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this));
1250 m_lastHandleUrlOpenJob->setShowOpenOrExecuteDialog(true);
1251
1252 connect(m_lastHandleUrlOpenJob, &KIO::OpenUrlJob::mimeTypeFound, this,
1253 [this, url](const QString &mimetype) {
1254 if (mimetype == QLatin1String("inode/directory")) {
1255 // If it's a dir, we'll take it from here
1256 m_lastHandleUrlOpenJob->kill();
1257 m_lastHandleUrlOpenJob = nullptr;
1258 activeViewContainer()->setUrl(url);
1259 }
1260 });
1261
1262 connect(m_lastHandleUrlOpenJob, &KIO::OpenUrlJob::result, this, [this]() {
1263 m_lastHandleUrlOpenJob = nullptr;
1264 });
1265
1266 m_lastHandleUrlOpenJob->start();
1267 }
1268 }
1269
1270 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable)
1271 {
1272 // trash:/ is writable but we don't want to create new items in it.
1273 // TODO: remove the trash check once https://phabricator.kde.org/T8234 is implemented
1274 newFileMenu()->setEnabled(isFolderWritable && m_activeViewContainer->url().scheme() != QLatin1String("trash"));
1275 }
1276
1277 void DolphinMainWindow::openContextMenu(const QPoint& pos,
1278 const KFileItem& item,
1279 const KFileItemList &selectedItems,
1280 const QUrl& url)
1281 {
1282 QPointer<DolphinContextMenu> contextMenu = new DolphinContextMenu(this, item, selectedItems, url, &m_fileItemActions);
1283 contextMenu.data()->exec(pos);
1284
1285 // Delete the menu, unless it has been deleted in its own nested event loop already.
1286 if (contextMenu) {
1287 contextMenu->deleteLater();
1288 }
1289 }
1290
1291 QMenu *DolphinMainWindow::createPopupMenu()
1292 {
1293 QMenu *menu = KXmlGuiWindow::createPopupMenu();
1294
1295 menu->addSeparator();
1296 menu->addAction(actionCollection()->action(QStringLiteral("lock_panels")));
1297
1298 return menu;
1299 }
1300
1301 void DolphinMainWindow::updateHamburgerMenu()
1302 {
1303 KActionCollection* ac = actionCollection();
1304 auto hamburgerMenu = static_cast<KHamburgerMenu *>(
1305 ac->action(KStandardAction::name(KStandardAction::HamburgerMenu)));
1306 auto menu = hamburgerMenu->menu();
1307 if (!menu) {
1308 menu = new QMenu(this);
1309 hamburgerMenu->setMenu(menu);
1310 hamburgerMenu->hideActionsOf(ac->action(QStringLiteral("basic_actions"))->menu());
1311 hamburgerMenu->hideActionsOf(ac->action(QStringLiteral("zoom"))->menu());
1312 } else {
1313 menu->clear();
1314 }
1315 const QList<QAction *> toolbarActions = toolBar()->actions();
1316
1317 if (!toolBar()->isVisible()) {
1318 // If neither the menu bar nor the toolbar are visible, these actions should be available.
1319 menu->addAction(ac->action(KStandardAction::name(KStandardAction::ShowMenubar)));
1320 menu->addAction(toolBarMenuAction());
1321 menu->addSeparator();
1322 }
1323
1324 // This group of actions (until the next separator) contains all the most basic actions
1325 // necessary to use Dolphin effectively.
1326 menu->addAction(ac->action(QStringLiteral("go_back")));
1327 menu->addAction(ac->action(QStringLiteral("go_forward")));
1328
1329 menu->addMenu(m_newFileMenu->menu());
1330 if (!toolBar()->isVisible()
1331 || !toolbarActions.contains(ac->action(QStringLiteral("toggle_selection_mode_tool_bar")))
1332 ) {
1333 menu->addAction(ac->action(QStringLiteral("toggle_selection_mode")));
1334 }
1335 menu->addAction(ac->action(QStringLiteral("basic_actions")));
1336 menu->addAction(ac->action(KStandardAction::name(KStandardAction::Undo)));
1337 if (!toolBar()->isVisible()
1338 || (!toolbarActions.contains(ac->action(QStringLiteral("toggle_search")))
1339 && !toolbarActions.contains(ac->action(QStringLiteral("open_preferred_search_tool"))))
1340 ) {
1341 menu->addAction(ac->action(KStandardAction::name(KStandardAction::Find)));
1342 // This way a search action will only be added if none of the three available
1343 // search actions is present on the toolbar.
1344 }
1345 if (!toolBar()->isVisible()
1346 || !toolbarActions.contains(ac->action(QStringLiteral("toggle_filter")))
1347 ) {
1348 menu->addAction(ac->action(QStringLiteral("show_filter_bar")));
1349 // This way a filter action will only be added if none of the two available
1350 // filter actions is present on the toolbar.
1351 }
1352 menu->addSeparator();
1353
1354 // The second group of actions (up until the next separator) contains actions for opening
1355 // additional views to interact with the file system.
1356 menu->addAction(ac->action(QStringLiteral("file_new")));
1357 menu->addAction(ac->action(QStringLiteral("new_tab")));
1358 if (ac->action(QStringLiteral("undo_close_tab"))->isEnabled()) {
1359 menu->addAction(ac->action(QStringLiteral("closed_tabs")));
1360 }
1361 menu->addAction(ac->action(QStringLiteral("open_terminal")));
1362 menu->addSeparator();
1363
1364 // The third group contains actions to change what one sees in the view
1365 // and to change the more general UI.
1366 if (!toolBar()->isVisible()
1367 || (!toolbarActions.contains(ac->action(QStringLiteral("icons")))
1368 && !toolbarActions.contains(ac->action(QStringLiteral("compact")))
1369 && !toolbarActions.contains(ac->action(QStringLiteral("details")))
1370 && !toolbarActions.contains(ac->action(QStringLiteral("view_mode"))))
1371 ) {
1372 menu->addAction(ac->action(QStringLiteral("view_mode")));
1373 }
1374 menu->addAction(ac->action(QStringLiteral("show_hidden_files")));
1375 menu->addAction(ac->action(QStringLiteral("sort")));
1376 menu->addAction(ac->action(QStringLiteral("additional_info")));
1377 if (!GeneralSettings::showStatusBar() || !GeneralSettings::showZoomSlider()) {
1378 menu->addAction(ac->action(QStringLiteral("zoom")));
1379 }
1380 menu->addAction(ac->action(QStringLiteral("panels")));
1381
1382 // The "Configure" menu is not added to the actionCollection() because there is hardly
1383 // a good reason for users to put it on their toolbar.
1384 auto configureMenu = menu->addMenu(QIcon::fromTheme(QStringLiteral("configure")),
1385 i18nc("@action:inmenu menu for configure actions", "Configure"));
1386 configureMenu->addAction(ac->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage)));
1387 configureMenu->addAction(ac->action(KStandardAction::name(KStandardAction::KeyBindings)));
1388 configureMenu->addAction(ac->action(KStandardAction::name(KStandardAction::ConfigureToolbars)));
1389 configureMenu->addAction(ac->action(KStandardAction::name(KStandardAction::Preferences)));
1390 hamburgerMenu->hideActionsOf(configureMenu);
1391 }
1392
1393 void DolphinMainWindow::slotPlaceActivated(const QUrl& url)
1394 {
1395 DolphinViewContainer* view = activeViewContainer();
1396
1397 if (view->url() == url) {
1398 // We can end up here if the user clicked a device in the Places Panel
1399 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1400 reloadView();
1401 } else {
1402 view->disableUrlNavigatorSelectionRequests();
1403 changeUrl(url);
1404 view->enableUrlNavigatorSelectionRequests();
1405 }
1406 }
1407
1408 void DolphinMainWindow::closedTabsCountChanged(unsigned int count)
1409 {
1410 actionCollection()->action(QStringLiteral("undo_close_tab"))->setEnabled(count > 0);
1411 }
1412
1413 void DolphinMainWindow::activeViewChanged(DolphinViewContainer* viewContainer)
1414 {
1415 DolphinViewContainer* oldViewContainer = m_activeViewContainer;
1416 Q_ASSERT(viewContainer);
1417
1418 m_activeViewContainer = viewContainer;
1419
1420 if (oldViewContainer) {
1421 const QAction* toggleSearchAction = actionCollection()->action(QStringLiteral("toggle_search"));
1422 toggleSearchAction->disconnect(oldViewContainer);
1423
1424 // Disconnect all signals between the old view container (container,
1425 // view and url navigator) and main window.
1426 oldViewContainer->disconnect(this);
1427 oldViewContainer->view()->disconnect(this);
1428 oldViewContainer->urlNavigatorInternalWithHistory()->disconnect(this);
1429 auto navigators = static_cast<DolphinNavigatorsWidgetAction *>
1430 (actionCollection()->action(QStringLiteral("url_navigators")));
1431 navigators->primaryUrlNavigator()->disconnect(this);
1432 if (auto secondaryUrlNavigator = navigators->secondaryUrlNavigator()) {
1433 secondaryUrlNavigator->disconnect(this);
1434 }
1435
1436 // except the requestItemInfo so that on hover the information panel can still be updated
1437 connect(oldViewContainer->view(), &DolphinView::requestItemInfo,
1438 this, &DolphinMainWindow::requestItemInfo);
1439 }
1440
1441 connectViewSignals(viewContainer);
1442
1443 m_actionHandler->setCurrentView(viewContainer->view());
1444
1445 updateHistory();
1446 updateFileAndEditActions();
1447 updatePasteAction();
1448 updateViewActions();
1449 updateGoActions();
1450 updateSearchAction();
1451
1452 const QUrl url = viewContainer->url();
1453 Q_EMIT urlChanged(url);
1454 }
1455
1456 void DolphinMainWindow::tabCountChanged(int count)
1457 {
1458 const bool enableTabActions = (count > 1);
1459 for (int i = 0; i < MaxActivateTabShortcuts; ++i) {
1460 actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i))->setEnabled(enableTabActions);
1461 }
1462 actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions);
1463 actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions);
1464 actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions);
1465 }
1466
1467 void DolphinMainWindow::updateWindowTitle()
1468 {
1469 const QString newTitle = m_activeViewContainer->captionWindowTitle();
1470 if (windowTitle() != newTitle) {
1471 setWindowTitle(newTitle);
1472 }
1473 }
1474
1475 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString& mountPath)
1476 {
1477 connect(m_placesPanel, &PlacesPanel::storageTearDownSuccessful, this, [this, mountPath]() {
1478 setViewsToHomeIfMountPathOpen(mountPath);
1479 });
1480
1481 if (m_terminalPanel && m_terminalPanel->currentWorkingDirectory().startsWith(mountPath)) {
1482 m_tearDownFromPlacesRequested = true;
1483 m_terminalPanel->goHome();
1484 // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
1485 } else {
1486 m_placesPanel->proceedWithTearDown();
1487 }
1488 }
1489
1490 void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString& mountPath)
1491 {
1492 connect(m_placesPanel, &PlacesPanel::storageTearDownSuccessful, this, [this, mountPath]() {
1493 setViewsToHomeIfMountPathOpen(mountPath);
1494 });
1495
1496 if (m_terminalPanel && m_terminalPanel->currentWorkingDirectory().startsWith(mountPath)) {
1497 m_tearDownFromPlacesRequested = false;
1498 m_terminalPanel->goHome();
1499 }
1500 }
1501
1502 void DolphinMainWindow::slotKeyBindings()
1503 {
1504 KShortcutsDialog dialog(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsAllowed, this);
1505 dialog.addCollection(actionCollection());
1506 if (m_terminalPanel) {
1507 KActionCollection *konsolePartActionCollection = m_terminalPanel->actionCollection();
1508 if (konsolePartActionCollection) {
1509 dialog.addCollection(konsolePartActionCollection, QStringLiteral("KonsolePart"));
1510 }
1511 }
1512 dialog.configure();
1513 }
1514
1515 void DolphinMainWindow::setViewsToHomeIfMountPathOpen(const QString& mountPath)
1516 {
1517 const QVector<DolphinViewContainer*> theViewContainers = viewContainers();
1518 for (DolphinViewContainer *viewContainer : theViewContainers) {
1519 if (viewContainer && viewContainer->url().toLocalFile().startsWith(mountPath)) {
1520 viewContainer->setUrl(QUrl::fromLocalFile(QDir::homePath()));
1521 }
1522 }
1523 disconnect(m_placesPanel, &PlacesPanel::storageTearDownSuccessful, nullptr, nullptr);
1524 }
1525
1526 void DolphinMainWindow::setupActions()
1527 {
1528 KStandardAction::hamburgerMenu(nullptr, nullptr, actionCollection());
1529
1530 // setup 'File' menu
1531 m_newFileMenu = new DolphinNewFileMenu(actionCollection(), this);
1532 QMenu* menu = m_newFileMenu->menu();
1533 menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1534 menu->setIcon(QIcon::fromTheme(QStringLiteral("list-add")));
1535 m_newFileMenu->setPopupMode(QToolButton::InstantPopup);
1536 connect(menu, &QMenu::aboutToShow,
1537 this, &DolphinMainWindow::updateNewMenu);
1538
1539 QAction* newWindow = KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow, actionCollection());
1540 newWindow->setText(i18nc("@action:inmenu File", "New &Window"));
1541 newWindow->setToolTip(i18nc("@info", "Open a new Dolphin window"));
1542 newWindow->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1543 "window just like this one with the current location and view."
1544 "<nl/>You can drag and drop items between windows."));
1545 newWindow->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1546
1547 QAction* newTab = actionCollection()->addAction(QStringLiteral("new_tab"));
1548 newTab->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1549 newTab->setText(i18nc("@action:inmenu File", "New Tab"));
1550 newTab->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1551 "<emphasis>Tab</emphasis> with the current location and view.<nl/>"
1552 "A tab is an additional view within this window. "
1553 "You can drag and drop items between tabs."));
1554 actionCollection()->setDefaultShortcuts(newTab, {Qt::CTRL | Qt::Key_T, Qt::CTRL | Qt::SHIFT | Qt::Key_N});
1555 connect(newTab, &QAction::triggered, this, &DolphinMainWindow::openNewActivatedTab);
1556
1557 QAction* addToPlaces = actionCollection()->addAction(QStringLiteral("add_to_places"));
1558 addToPlaces->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new")));
1559 addToPlaces->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places"));
1560 addToPlaces->setWhatsThis(xi18nc("@info:whatsthis", "This adds the selected folder "
1561 "to the Places panel."));
1562 connect(addToPlaces, &QAction::triggered, this, &DolphinMainWindow::addToPlaces);
1563
1564 QAction* closeTab = KStandardAction::close(m_tabWidget, QOverload<>::of(&DolphinTabWidget::closeTab), actionCollection());
1565 closeTab->setText(i18nc("@action:inmenu File", "Close Tab"));
1566 closeTab->setWhatsThis(i18nc("@info:whatsthis", "This closes the "
1567 "currently viewed tab. If no more tabs are left this window "
1568 "will close instead."));
1569
1570 QAction* quitAction = KStandardAction::quit(this, &DolphinMainWindow::quit, actionCollection());
1571 quitAction->setWhatsThis(i18nc("@info:whatsthis quit", "This closes this window."));
1572
1573 // setup 'Edit' menu
1574 KStandardAction::undo(this,
1575 &DolphinMainWindow::undo,
1576 actionCollection());
1577
1578 // i18n: This will be the last paragraph for the whatsthis for all three:
1579 // Cut, Copy and Paste
1580 const QString cutCopyPastePara = xi18nc("@info:whatsthis", "<para><emphasis>Cut, "
1581 "Copy</emphasis> and <emphasis>Paste</emphasis> work between many "
1582 "applications and are among the most used commands. That's why their "
1583 "<emphasis>keyboard shortcuts</emphasis> are prominently placed right "
1584 "next to each other on the keyboard: <shortcut>Ctrl+X</shortcut>, "
1585 "<shortcut>Ctrl+C</shortcut> and <shortcut>Ctrl+V</shortcut>.</para>");
1586 QAction* cutAction = KStandardAction::cut(this, &DolphinMainWindow::cut, actionCollection());
1587 cutAction->setWhatsThis(xi18nc("@info:whatsthis cut", "This copies the items "
1588 "in your current selection to the <emphasis>clipboard</emphasis>.<nl/>"
1589 "Use the <emphasis>Paste</emphasis> action afterwards to copy them from "
1590 "the clipboard to a new location. The items will be removed from their "
1591 "initial location.") + cutCopyPastePara);
1592 QAction* copyAction = KStandardAction::copy(this, &DolphinMainWindow::copy, actionCollection());
1593 copyAction->setWhatsThis(xi18nc("@info:whatsthis copy", "This copies the "
1594 "items in your current selection to the <emphasis>clipboard</emphasis>."
1595 "<nl/>Use the <emphasis>Paste</emphasis> action afterwards to copy them "
1596 "from the clipboard to a new location.") + cutCopyPastePara);
1597 QAction* paste = KStandardAction::paste(this, &DolphinMainWindow::paste, actionCollection());
1598 // The text of the paste-action is modified dynamically by Dolphin
1599 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1600 // due to the long text, the text "Paste" is used:
1601 paste->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1602 paste->setWhatsThis(xi18nc("@info:whatsthis paste", "This copies the items from "
1603 "your <emphasis>clipboard</emphasis> to the currently viewed folder.<nl/>"
1604 "If the items were added to the clipboard by the <emphasis>Cut</emphasis> "
1605 "action they are removed from their old location.") + cutCopyPastePara);
1606
1607 QAction* copyToOtherViewAction = actionCollection()->addAction(QStringLiteral("copy_to_inactive_split_view"));
1608 copyToOtherViewAction->setText(i18nc("@action:inmenu", "Copy to Inactive Split View"));
1609 copyToOtherViewAction->setWhatsThis(xi18nc("@info:whatsthis Copy", "This copies the selected items from "
1610 "the <emphasis>active</emphasis> view to the inactive split view."));
1611 copyToOtherViewAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
1612 copyToOtherViewAction->setIconText(i18nc("@action:inmenu Edit", "Copy to Inactive Split View"));
1613 actionCollection()->setDefaultShortcut(copyToOtherViewAction, Qt::SHIFT | Qt::Key_F5 );
1614 connect(copyToOtherViewAction, &QAction::triggered, this, &DolphinMainWindow::copyToInactiveSplitView);
1615
1616 QAction* moveToOtherViewAction = actionCollection()->addAction(QStringLiteral("move_to_inactive_split_view"));
1617 moveToOtherViewAction->setText(i18nc("@action:inmenu", "Move to Inactive Split View"));
1618 moveToOtherViewAction->setWhatsThis(xi18nc("@info:whatsthis Move", "This moves the selected items from "
1619 "the <emphasis>active</emphasis> view to the inactive split view."));
1620 moveToOtherViewAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-cut")));
1621 moveToOtherViewAction->setIconText(i18nc("@action:inmenu Edit", "Move to Inactive Split View"));
1622 actionCollection()->setDefaultShortcut(moveToOtherViewAction, Qt::SHIFT | Qt::Key_F6 );
1623 connect(moveToOtherViewAction, &QAction::triggered, this, &DolphinMainWindow::moveToInactiveSplitView);
1624
1625 QAction* showFilterBar = actionCollection()->addAction(QStringLiteral("show_filter_bar"));
1626 showFilterBar->setText(i18nc("@action:inmenu Tools", "Filter..."));
1627 showFilterBar->setToolTip(i18nc("@info:tooltip", "Show Filter Bar"));
1628 showFilterBar->setWhatsThis(xi18nc("@info:whatsthis", "This opens the "
1629 "<emphasis>Filter Bar</emphasis> at the bottom of the window.<nl/> "
1630 "There you can enter a text to filter the files and folders currently displayed. "
1631 "Only those that contain the text in their name will be kept in view."));
1632 showFilterBar->setIcon(QIcon::fromTheme(QStringLiteral("view-filter")));
1633 actionCollection()->setDefaultShortcuts(showFilterBar, {Qt::CTRL | Qt::Key_I, Qt::Key_Slash});
1634 connect(showFilterBar, &QAction::triggered, this, &DolphinMainWindow::showFilterBar);
1635
1636 // toggle_filter acts as a copy of the main showFilterBar to be used mainly
1637 // in the toolbar, with no default shortcut attached, to avoid messing with
1638 // existing workflows (filter bar always open and Ctrl-I to focus)
1639 QAction *toggleFilter = actionCollection()->addAction(QStringLiteral("toggle_filter"));
1640 toggleFilter->setText(i18nc("@action:inmenu", "Toggle Filter Bar"));
1641 toggleFilter->setIconText(i18nc("@action:intoolbar", "Filter"));
1642 toggleFilter->setIcon(showFilterBar->icon());
1643 toggleFilter->setToolTip(showFilterBar->toolTip());
1644 toggleFilter->setWhatsThis(showFilterBar->whatsThis());
1645 toggleFilter->setCheckable(true);
1646 connect(toggleFilter, &QAction::triggered, this, &DolphinMainWindow::toggleFilterBar);
1647
1648 QAction *searchAction = KStandardAction::find(this, &DolphinMainWindow::find, actionCollection());
1649 searchAction->setText(i18n("Search..."));
1650 searchAction->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
1651 searchAction->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This helps you "
1652 "find files and folders by opening a <emphasis>find bar</emphasis>. "
1653 "There you can enter search terms and specify settings to find the "
1654 "objects you are looking for.</para><para>Use this help again on "
1655 "the find bar so we can have a look at it while the settings are "
1656 "explained.</para>"));
1657
1658 // toggle_search acts as a copy of the main searchAction to be used mainly
1659 // in the toolbar, with no default shortcut attached, to avoid messing with
1660 // existing workflows (search bar always open and Ctrl-F to focus)
1661 QAction *toggleSearchAction = actionCollection()->addAction(QStringLiteral("toggle_search"));
1662 toggleSearchAction->setText(i18nc("@action:inmenu", "Toggle Search Bar"));
1663 toggleSearchAction->setIconText(i18nc("@action:intoolbar", "Search"));
1664 toggleSearchAction->setIcon(searchAction->icon());
1665 toggleSearchAction->setToolTip(searchAction->toolTip());
1666 toggleSearchAction->setWhatsThis(searchAction->whatsThis());
1667 toggleSearchAction->setCheckable(true);
1668
1669 QAction *toggleSelectionModeAction = actionCollection()->addAction(QStringLiteral("toggle_selection_mode"));
1670 // i18n: This action toggles a selection mode.
1671 toggleSelectionModeAction->setText(i18nc("@action:inmenu", "Select Files and Folders"));
1672 // i18n: Opens a selection mode for selecting files/folders and later selecting an action that acts on them.
1673 // So in a way "Select" here is used to mean both "Select files" and also "Select what to do" but mostly the first.
1674 // The text is kept so unspecific because it will be shown on the toolbar where space is at a premium.
1675 toggleSelectionModeAction->setIconText(i18nc("@action:intoolbar", "Select"));
1676 toggleSelectionModeAction->setWhatsThis(xi18nc("@info:whatsthis", "<para>This application only knows which files or folders should be acted on if they are"
1677 " <emphasis>selected</emphasis> first. Press this to toggle a <emphasis>Selection Mode</emphasis> which makes selecting and deselecting as easy as "
1678 "pressing an item once.</para><para>While in this mode, a quick access bar at the bottom shows available actions for the currently selected items."
1679 "</para>"));
1680 toggleSelectionModeAction->setIcon(QIcon::fromTheme(QStringLiteral("quickwizard")));
1681 toggleSelectionModeAction->setCheckable(true);
1682 actionCollection()->setDefaultShortcut(toggleSelectionModeAction, Qt::Key_Space );
1683 connect(toggleSelectionModeAction, &QAction::triggered, this, &DolphinMainWindow::toggleSelectionMode);
1684
1685 // A special version of the toggleSelectionModeAction for the toolbar that also contains a menu
1686 // with the selectAllAction and invertSelectionAction.
1687 auto *toggleSelectionModeToolBarAction = new KToolBarPopupAction(toggleSelectionModeAction->icon(), toggleSelectionModeAction->iconText(), actionCollection());
1688 toggleSelectionModeToolBarAction->setToolTip(toggleSelectionModeAction->text());
1689 toggleSelectionModeToolBarAction->setWhatsThis(toggleSelectionModeAction->whatsThis());
1690 actionCollection()->addAction(QStringLiteral("toggle_selection_mode_tool_bar"), toggleSelectionModeToolBarAction);
1691 toggleSelectionModeToolBarAction->setCheckable(true);
1692 toggleSelectionModeToolBarAction->setPopupMode(QToolButton::DelayedPopup);
1693 connect(toggleSelectionModeToolBarAction, &QAction::triggered, toggleSelectionModeAction, &QAction::trigger);
1694 connect(toggleSelectionModeAction, &QAction::toggled, toggleSelectionModeToolBarAction, &QAction::setChecked);
1695
1696 QAction* selectAllAction = KStandardAction::selectAll(this, &DolphinMainWindow::selectAll, actionCollection());
1697 selectAllAction->setWhatsThis(xi18nc("@info:whatsthis", "This selects all "
1698 "files and folders in the current location."));
1699
1700 QAction* invertSelection = actionCollection()->addAction(QStringLiteral("invert_selection"));
1701 invertSelection->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1702 invertSelection->setWhatsThis(xi18nc("@info:whatsthis invert", "This selects all "
1703 "objects that you have currently <emphasis>not</emphasis> selected instead."));
1704 invertSelection->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert")));
1705 actionCollection()->setDefaultShortcut(invertSelection, Qt::CTRL | Qt::SHIFT | Qt::Key_A);
1706 connect(invertSelection, &QAction::triggered, this, &DolphinMainWindow::invertSelection);
1707
1708 QMenu *toggleSelectionModeActionMenu = new QMenu(this);
1709 toggleSelectionModeActionMenu->addAction(selectAllAction);
1710 toggleSelectionModeActionMenu->addAction(invertSelection);
1711 toggleSelectionModeToolBarAction->setMenu(toggleSelectionModeActionMenu);
1712
1713 // setup 'View' menu
1714 // (note that most of it is set up in DolphinViewActionHandler)
1715
1716 QAction* split = actionCollection()->addAction(QStringLiteral("split_view"));
1717 split->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This splits "
1718 "the folder view below into two autonomous views.</para><para>This "
1719 "way you can see two locations at once and move items between them "
1720 "quickly.</para>Click this again afterwards to recombine the views."));
1721 actionCollection()->setDefaultShortcut(split, Qt::Key_F3);
1722 connect(split, &QAction::triggered, this, &DolphinMainWindow::toggleSplitView);
1723
1724 QAction* stashSplit = actionCollection()->addAction(QStringLiteral("split_stash"));
1725 actionCollection()->setDefaultShortcut(stashSplit, Qt::CTRL | Qt::Key_S);
1726 stashSplit->setText(i18nc("@action:intoolbar Stash", "Stash"));
1727 stashSplit->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
1728 stashSplit->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
1729 stashSplit->setCheckable(false);
1730 QDBusConnectionInterface *sessionInterface = QDBusConnection::sessionBus().interface();
1731 stashSplit->setVisible(sessionInterface && sessionInterface->isServiceRegistered(QStringLiteral("org.kde.kio.StashNotifier")));
1732 connect(stashSplit, &QAction::triggered, this, &DolphinMainWindow::toggleSplitStash);
1733
1734 KStandardAction::redisplay(this, &DolphinMainWindow::reloadView, actionCollection());
1735
1736 QAction* stop = actionCollection()->addAction(QStringLiteral("stop"));
1737 stop->setText(i18nc("@action:inmenu View", "Stop"));
1738 stop->setToolTip(i18nc("@info", "Stop loading"));
1739 stop->setWhatsThis(i18nc("@info", "This stops the loading of the contents of the current folder."));
1740 stop->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
1741 connect(stop, &QAction::triggered, this, &DolphinMainWindow::stopLoading);
1742
1743 KToggleAction* editableLocation = actionCollection()->add<KToggleAction>(QStringLiteral("editable_location"));
1744 editableLocation->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1745 editableLocation->setWhatsThis(xi18nc("@info:whatsthis",
1746 "This toggles the <emphasis>Location Bar</emphasis> to be "
1747 "editable so you can directly enter a location you want to go to.<nl/>"
1748 "You can also switch to editing by clicking to the right of the "
1749 "location and switch back by confirming the edited location."));
1750 actionCollection()->setDefaultShortcut(editableLocation, Qt::Key_F6);
1751 connect(editableLocation, &KToggleAction::triggered, this, &DolphinMainWindow::toggleEditLocation);
1752
1753 QAction* replaceLocation = actionCollection()->addAction(QStringLiteral("replace_location"));
1754 replaceLocation->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1755 // i18n: "enter" is used both in the meaning of "writing" and "going to" a new location here.
1756 // Both meanings are useful but not necessary to understand the use of "Replace Location".
1757 // So you might want to be more verbose in your language to convey the meaning but it's up to you.
1758 replaceLocation->setWhatsThis(xi18nc("@info:whatsthis",
1759 "This switches to editing the location and selects it "
1760 "so you can quickly enter a different location."));
1761 actionCollection()->setDefaultShortcut(replaceLocation, Qt::CTRL | Qt::Key_L);
1762 connect(replaceLocation, &QAction::triggered, this, &DolphinMainWindow::replaceLocation);
1763
1764 // setup 'Go' menu
1765 {
1766 QScopedPointer<QAction> backAction(KStandardAction::back(nullptr, nullptr, nullptr));
1767 m_backAction = new KToolBarPopupAction(backAction->icon(), backAction->text(), actionCollection());
1768 m_backAction->setObjectName(backAction->objectName());
1769 m_backAction->setShortcuts(backAction->shortcuts());
1770 }
1771 m_backAction->setPopupMode(QToolButton::DelayedPopup);
1772 connect(m_backAction, &QAction::triggered, this, &DolphinMainWindow::goBack);
1773 connect(m_backAction->menu(), &QMenu::aboutToShow, this, &DolphinMainWindow::slotAboutToShowBackPopupMenu);
1774 connect(m_backAction->menu(), &QMenu::triggered, this, &DolphinMainWindow::slotGoBack);
1775 actionCollection()->addAction(m_backAction->objectName(), m_backAction);
1776
1777 auto backShortcuts = m_backAction->shortcuts();
1778 backShortcuts.append(QKeySequence(Qt::Key_Backspace));
1779 actionCollection()->setDefaultShortcuts(m_backAction, backShortcuts);
1780
1781 DolphinRecentTabsMenu* recentTabsMenu = new DolphinRecentTabsMenu(this);
1782 actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu);
1783 connect(m_tabWidget, &DolphinTabWidget::rememberClosedTab,
1784 recentTabsMenu, &DolphinRecentTabsMenu::rememberClosedTab);
1785 connect(recentTabsMenu, &DolphinRecentTabsMenu::restoreClosedTab,
1786 m_tabWidget, &DolphinTabWidget::restoreClosedTab);
1787 connect(recentTabsMenu, &DolphinRecentTabsMenu::closedTabsCountChanged,
1788 this, &DolphinMainWindow::closedTabsCountChanged);
1789
1790 QAction* undoCloseTab = actionCollection()->addAction(QStringLiteral("undo_close_tab"));
1791 undoCloseTab->setText(i18nc("@action:inmenu File", "Undo close tab"));
1792 undoCloseTab->setWhatsThis(i18nc("@info:whatsthis undo close tab",
1793 "This returns you to the previously closed tab."));
1794 actionCollection()->setDefaultShortcut(undoCloseTab, Qt::CTRL | Qt::SHIFT | Qt::Key_T);
1795 undoCloseTab->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
1796 undoCloseTab->setEnabled(false);
1797 connect(undoCloseTab, &QAction::triggered, recentTabsMenu, &DolphinRecentTabsMenu::undoCloseTab);
1798
1799 auto undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo));
1800 undoAction->setWhatsThis(xi18nc("@info:whatsthis", "This undoes "
1801 "the last change you made to files or folders.<nl/>"
1802 "Such changes include <interface>creating, renaming</interface> "
1803 "and <interface>moving</interface> them to a different location "
1804 "or to the <filename>Trash</filename>. <nl/>Changes that can't "
1805 "be undone will ask for your confirmation."));
1806 undoAction->setEnabled(false); // undo should be disabled by default
1807
1808 {
1809 QScopedPointer<QAction> forwardAction(KStandardAction::forward(nullptr, nullptr, nullptr));
1810 m_forwardAction = new KToolBarPopupAction(forwardAction->icon(), forwardAction->text(), actionCollection());
1811 m_forwardAction->setObjectName(forwardAction->objectName());
1812 m_forwardAction->setShortcuts(forwardAction->shortcuts());
1813 }
1814 m_forwardAction->setPopupMode(QToolButton::DelayedPopup);
1815 connect(m_forwardAction, &QAction::triggered, this, &DolphinMainWindow::goForward);
1816 connect(m_forwardAction->menu(), &QMenu::aboutToShow, this, &DolphinMainWindow::slotAboutToShowForwardPopupMenu);
1817 connect(m_forwardAction->menu(), &QMenu::triggered, this, &DolphinMainWindow::slotGoForward);
1818 actionCollection()->addAction(m_forwardAction->objectName(), m_forwardAction);
1819 actionCollection()->setDefaultShortcuts(m_forwardAction, m_forwardAction->shortcuts());
1820
1821 // enable middle-click to open in a new tab
1822 auto *middleClickEventFilter = new MiddleClickActionEventFilter(this);
1823 connect(middleClickEventFilter, &MiddleClickActionEventFilter::actionMiddleClicked, this, &DolphinMainWindow::slotBackForwardActionMiddleClicked);
1824 m_backAction->menu()->installEventFilter(middleClickEventFilter);
1825 m_forwardAction->menu()->installEventFilter(middleClickEventFilter);
1826 KStandardAction::up(this, &DolphinMainWindow::goUp, actionCollection());
1827 QAction* homeAction = KStandardAction::home(this, &DolphinMainWindow::goHome, actionCollection());
1828 homeAction->setWhatsThis(xi18nc("@info:whatsthis", "Go to your "
1829 "<filename>Home</filename> folder.<nl/>Every user account "
1830 "has their own <filename>Home</filename> that contains their data "
1831 "including folders that contain personal application data."));
1832
1833 // setup 'Tools' menu
1834 QAction* compareFiles = actionCollection()->addAction(QStringLiteral("compare_files"));
1835 compareFiles->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1836 compareFiles->setIcon(QIcon::fromTheme(QStringLiteral("kompare")));
1837 compareFiles->setEnabled(false);
1838 connect(compareFiles, &QAction::triggered, this, &DolphinMainWindow::compareFiles);
1839
1840 QAction* openPreferredSearchTool = actionCollection()->addAction(QStringLiteral("open_preferred_search_tool"));
1841 openPreferredSearchTool->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1842 openPreferredSearchTool->setWhatsThis(xi18nc("@info:whatsthis",
1843 "<para>This opens a preferred search tool for the viewed location.</para>"
1844 "<para>Use <emphasis>More Search Tools</emphasis> menu to configure it.</para>"));
1845 openPreferredSearchTool->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1846 actionCollection()->setDefaultShortcut(openPreferredSearchTool, Qt::CTRL | Qt::SHIFT | Qt::Key_F);
1847 connect(openPreferredSearchTool, &QAction::triggered, this, &DolphinMainWindow::openPreferredSearchTool);
1848
1849 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1850 QAction* openTerminal = actionCollection()->addAction(QStringLiteral("open_terminal"));
1851 openTerminal->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1852 openTerminal->setWhatsThis(xi18nc("@info:whatsthis",
1853 "<para>This opens a <emphasis>terminal</emphasis> application for the viewed location.</para>"
1854 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1855 openTerminal->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
1856 actionCollection()->setDefaultShortcut(openTerminal, Qt::SHIFT | Qt::Key_F4);
1857 connect(openTerminal, &QAction::triggered, this, &DolphinMainWindow::openTerminal);
1858
1859 QAction* openTerminalHere = actionCollection()->addAction(QStringLiteral("open_terminal_here"));
1860 // i18n: "Here" refers to the location(s) of the currently selected item(s) or the currently viewed location if nothing is selected.
1861 openTerminalHere->setText(i18nc("@action:inmenu Tools", "Open Terminal Here"));
1862 openTerminalHere->setWhatsThis(xi18nc("@info:whatsthis",
1863 "<para>This opens <emphasis>terminal</emphasis> applications for the selected items' locations.</para>"
1864 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1865 openTerminalHere->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
1866 actionCollection()->setDefaultShortcut(openTerminalHere, Qt::SHIFT | Qt::ALT | Qt::Key_F4);
1867 connect(openTerminalHere, &QAction::triggered, this, &DolphinMainWindow::openTerminalHere);
1868
1869 #if HAVE_TERMINAL
1870 QAction* focusTerminalPanel = actionCollection()->addAction(QStringLiteral("focus_terminal_panel"));
1871 focusTerminalPanel->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
1872 focusTerminalPanel->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
1873 actionCollection()->setDefaultShortcut(focusTerminalPanel, Qt::CTRL | Qt::SHIFT | Qt::Key_F4);
1874 connect(focusTerminalPanel, &QAction::triggered, this, &DolphinMainWindow::focusTerminalPanel);
1875 #endif
1876 }
1877
1878 // setup 'Bookmarks' menu
1879 KActionMenu *bookmarkMenu = new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this);
1880 bookmarkMenu->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks")));
1881 // Make the toolbar button version work properly on click
1882 bookmarkMenu->setPopupMode(QToolButton::InstantPopup);
1883 m_bookmarkHandler = new DolphinBookmarkHandler(this, actionCollection(), bookmarkMenu->menu(), this);
1884 actionCollection()->addAction(QStringLiteral("bookmarks"), bookmarkMenu);
1885
1886 // setup 'Settings' menu
1887 KToggleAction* showMenuBar = KStandardAction::showMenubar(nullptr, nullptr, actionCollection());
1888 showMenuBar->setWhatsThis(xi18nc("@info:whatsthis",
1889 "This switches between having a <emphasis>Menubar</emphasis> "
1890 "and having a <interface>Control</interface> button. Both "
1891 "contain mostly the same commands and configuration options."));
1892 connect(showMenuBar, &KToggleAction::triggered, // Fixes #286822
1893 this, &DolphinMainWindow::toggleShowMenuBar, Qt::QueuedConnection);
1894
1895 KToggleAction* showStatusBar = KStandardAction::showStatusbar(nullptr, nullptr, actionCollection());
1896 showStatusBar->setChecked(GeneralSettings::showStatusBar());
1897 connect(GeneralSettings::self(), &GeneralSettings::showStatusBarChanged, showStatusBar, &KToggleAction::setChecked);
1898 connect(showStatusBar, &KToggleAction::triggered, this, [this](bool checked) {
1899 GeneralSettings::setShowStatusBar(checked);
1900 refreshViews();
1901 });
1902
1903 KStandardAction::keyBindings(this, &DolphinMainWindow::slotKeyBindings, actionCollection());
1904 KStandardAction::preferences(this, &DolphinMainWindow::editSettings, actionCollection());
1905
1906 // setup 'Help' menu for the m_controlButton. The other one is set up in the base class.
1907 m_helpMenu = new KHelpMenu(nullptr);
1908 m_helpMenu->menu()->installEventFilter(this);
1909 // remove duplicate shortcuts
1910 auto removeHelpActionShortcut = [this](KHelpMenu::MenuId menuId) {
1911 if (auto *action = m_helpMenu->action(menuId)) {
1912 action->setShortcut(QKeySequence());
1913 }
1914 };
1915 removeHelpActionShortcut(KHelpMenu::menuHelpContents);
1916 removeHelpActionShortcut(KHelpMenu::menuWhatsThis);
1917
1918 // not in menu actions
1919 QList<QKeySequence> nextTabKeys = KStandardShortcut::tabNext();
1920 nextTabKeys.append(QKeySequence(Qt::CTRL | Qt::Key_Tab));
1921
1922 QList<QKeySequence> prevTabKeys = KStandardShortcut::tabPrev();
1923 prevTabKeys.append(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_Tab));
1924
1925 for (int i = 0; i < MaxActivateTabShortcuts; ++i) {
1926 QAction* activateTab = actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i));
1927 activateTab->setText(i18nc("@action:inmenu", "Activate Tab %1", i + 1));
1928 activateTab->setEnabled(false);
1929 connect(activateTab, &QAction::triggered, this, [this, i]() { m_tabWidget->activateTab(i); });
1930
1931 // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts
1932 if (i < 9) {
1933 actionCollection()->setDefaultShortcut(activateTab, QStringLiteral("Alt+%1").arg(i + 1));
1934 }
1935 }
1936
1937 QAction* activateLastTab = actionCollection()->addAction(QStringLiteral("activate_last_tab"));
1938 activateLastTab->setText(i18nc("@action:inmenu", "Activate Last Tab"));
1939 activateLastTab->setEnabled(false);
1940 connect(activateLastTab, &QAction::triggered, m_tabWidget, &DolphinTabWidget::activateLastTab);
1941 actionCollection()->setDefaultShortcut(activateLastTab, Qt::ALT | Qt::Key_0);
1942
1943 QAction* activateNextTab = actionCollection()->addAction(QStringLiteral("activate_next_tab"));
1944 activateNextTab->setIconText(i18nc("@action:inmenu", "Next Tab"));
1945 activateNextTab->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1946 activateNextTab->setEnabled(false);
1947 connect(activateNextTab, &QAction::triggered, m_tabWidget, &DolphinTabWidget::activateNextTab);
1948 actionCollection()->setDefaultShortcuts(activateNextTab, nextTabKeys);
1949
1950 QAction* activatePrevTab = actionCollection()->addAction(QStringLiteral("activate_prev_tab"));
1951 activatePrevTab->setIconText(i18nc("@action:inmenu", "Previous Tab"));
1952 activatePrevTab->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1953 activatePrevTab->setEnabled(false);
1954 connect(activatePrevTab, &QAction::triggered, m_tabWidget, &DolphinTabWidget::activatePrevTab);
1955 actionCollection()->setDefaultShortcuts(activatePrevTab, prevTabKeys);
1956
1957 // for context menu
1958 QAction* showTarget = actionCollection()->addAction(QStringLiteral("show_target"));
1959 showTarget->setText(i18nc("@action:inmenu", "Show Target"));
1960 showTarget->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
1961 showTarget->setEnabled(false);
1962 connect(showTarget, &QAction::triggered, this, &DolphinMainWindow::showTarget);
1963
1964 QAction* openInNewTab = actionCollection()->addAction(QStringLiteral("open_in_new_tab"));
1965 openInNewTab->setText(i18nc("@action:inmenu", "Open in New Tab"));
1966 openInNewTab->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1967 connect(openInNewTab, &QAction::triggered, this, &DolphinMainWindow::openInNewTab);
1968
1969 QAction* openInNewTabs = actionCollection()->addAction(QStringLiteral("open_in_new_tabs"));
1970 openInNewTabs->setText(i18nc("@action:inmenu", "Open in New Tabs"));
1971 openInNewTabs->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1972 connect(openInNewTabs, &QAction::triggered, this, &DolphinMainWindow::openInNewTab);
1973
1974 QAction* openInNewWindow = actionCollection()->addAction(QStringLiteral("open_in_new_window"));
1975 openInNewWindow->setText(i18nc("@action:inmenu", "Open in New Window"));
1976 openInNewWindow->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1977 connect(openInNewWindow, &QAction::triggered, this, &DolphinMainWindow::openInNewWindow);
1978 }
1979
1980 void DolphinMainWindow::setupDockWidgets()
1981 {
1982 const bool lock = GeneralSettings::lockPanels();
1983
1984 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(lock);
1985
1986 KDualAction* lockLayoutAction = actionCollection()->add<KDualAction>(QStringLiteral("lock_panels"));
1987 lockLayoutAction->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1988 lockLayoutAction->setActiveIcon(QIcon::fromTheme(QStringLiteral("object-unlocked")));
1989 lockLayoutAction->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1990 lockLayoutAction->setInactiveIcon(QIcon::fromTheme(QStringLiteral("object-locked")));
1991 lockLayoutAction->setWhatsThis(xi18nc("@info:whatsthis", "This "
1992 "switches between having panels <emphasis>locked</emphasis> or "
1993 "<emphasis>unlocked</emphasis>.<nl/>Unlocked panels can be "
1994 "dragged to the other side of the window and have a close "
1995 "button.<nl/>Locked panels are embedded more cleanly."));
1996 lockLayoutAction->setActive(lock);
1997 connect(lockLayoutAction, &KDualAction::triggered, this, &DolphinMainWindow::togglePanelLockState);
1998
1999 // Setup "Information"
2000 DolphinDockWidget* infoDock = new DolphinDockWidget(i18nc("@title:window", "Information"));
2001 infoDock->setLocked(lock);
2002 infoDock->setObjectName(QStringLiteral("infoDock"));
2003 infoDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
2004
2005 #if HAVE_BALOO
2006 InformationPanel* infoPanel = new InformationPanel(infoDock);
2007 infoPanel->setCustomContextMenuActions({lockLayoutAction});
2008 connect(infoPanel, &InformationPanel::urlActivated, this, &DolphinMainWindow::handleUrl);
2009 infoDock->setWidget(infoPanel);
2010
2011 QAction* infoAction = infoDock->toggleViewAction();
2012 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-information")), Qt::Key_F11, infoAction, QStringLiteral("show_information_panel"));
2013
2014 addDockWidget(Qt::RightDockWidgetArea, infoDock);
2015 connect(this, &DolphinMainWindow::urlChanged,
2016 infoPanel, &InformationPanel::setUrl);
2017 connect(this, &DolphinMainWindow::selectionChanged,
2018 infoPanel, &InformationPanel::setSelection);
2019 connect(this, &DolphinMainWindow::requestItemInfo,
2020 infoPanel, &InformationPanel::requestDelayedItemInfo);
2021 connect(this, &DolphinMainWindow::fileItemsChanged,
2022 infoPanel, &InformationPanel::slotFilesItemChanged);
2023 #endif
2024
2025 // i18n: This is the last paragraph for the "What's This"-texts of all four panels.
2026 const QString panelWhatsThis = xi18nc("@info:whatsthis", "<para>To show or "
2027 "hide panels like this go to <interface>Control|Panels</interface> "
2028 "or <interface>View|Panels</interface>.</para>");
2029 #if HAVE_BALOO
2030 actionCollection()->action(QStringLiteral("show_information_panel"))
2031 ->setWhatsThis(xi18nc("@info:whatsthis", "<para> This toggles the "
2032 "<emphasis>information</emphasis> panel at the right side of the "
2033 "window.</para><para>The panel provides in-depth information "
2034 "about the items your mouse is hovering over or about the selected "
2035 "items. Otherwise it informs you about the currently viewed folder.<nl/>"
2036 "For single items a preview of their contents is provided.</para>"));
2037 #endif
2038 infoDock->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
2039 "provides in-depth information about the items your mouse is "
2040 "hovering over or about the selected items. Otherwise it informs "
2041 "you about the currently viewed folder.<nl/>For single items a "
2042 "preview of their contents is provided.</para><para>You can configure "
2043 "which and how details are given here by right-clicking.</para>") + panelWhatsThis);
2044
2045 // Setup "Folders"
2046 DolphinDockWidget* foldersDock = new DolphinDockWidget(i18nc("@title:window", "Folders"));
2047 foldersDock->setLocked(lock);
2048 foldersDock->setObjectName(QStringLiteral("foldersDock"));
2049 foldersDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
2050 FoldersPanel* foldersPanel = new FoldersPanel(foldersDock);
2051 foldersPanel->setCustomContextMenuActions({lockLayoutAction});
2052 foldersDock->setWidget(foldersPanel);
2053
2054 QAction* foldersAction = foldersDock->toggleViewAction();
2055 createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7, foldersAction, QStringLiteral("show_folders_panel"));
2056
2057 addDockWidget(Qt::LeftDockWidgetArea, foldersDock);
2058 connect(this, &DolphinMainWindow::urlChanged,
2059 foldersPanel, &FoldersPanel::setUrl);
2060 connect(foldersPanel, &FoldersPanel::folderActivated,
2061 this, &DolphinMainWindow::changeUrl);
2062 connect(foldersPanel, &FoldersPanel::folderInNewTab,
2063 this, &DolphinMainWindow::openNewTab);
2064 connect(foldersPanel, &FoldersPanel::folderInNewActiveTab,
2065 this, &DolphinMainWindow::openNewTabAndActivate);
2066 connect(foldersPanel, &FoldersPanel::errorMessage,
2067 this, &DolphinMainWindow::showErrorMessage);
2068
2069 actionCollection()->action(QStringLiteral("show_folders_panel"))
2070 ->setWhatsThis(xi18nc("@info:whatsthis", "This toggles the "
2071 "<emphasis>folders</emphasis> panel at the left side of the window."
2072 "<nl/><nl/>It shows the folders of the <emphasis>file system"
2073 "</emphasis> in a <emphasis>tree view</emphasis>."));
2074 foldersDock->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
2075 "shows the folders of the <emphasis>file system</emphasis> in a "
2076 "<emphasis>tree view</emphasis>.</para><para>Click a folder to go "
2077 "there. Click the arrow to the left of a folder to see its subfolders. "
2078 "This allows quick switching between any folders.</para>") + panelWhatsThis);
2079
2080 // Setup "Terminal"
2081 #if HAVE_TERMINAL
2082 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
2083 DolphinDockWidget* terminalDock = new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
2084 terminalDock->setLocked(lock);
2085 terminalDock->setObjectName(QStringLiteral("terminalDock"));
2086 m_terminalPanel = new TerminalPanel(terminalDock);
2087 m_terminalPanel->setCustomContextMenuActions({lockLayoutAction});
2088 terminalDock->setWidget(m_terminalPanel);
2089
2090 connect(m_terminalPanel, &TerminalPanel::hideTerminalPanel, terminalDock, &DolphinDockWidget::hide);
2091 connect(m_terminalPanel, &TerminalPanel::changeUrl, this, &DolphinMainWindow::slotTerminalDirectoryChanged);
2092 connect(terminalDock, &DolphinDockWidget::visibilityChanged,
2093 m_terminalPanel, &TerminalPanel::dockVisibilityChanged);
2094 connect(terminalDock, &DolphinDockWidget::visibilityChanged,
2095 this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged);
2096
2097 QAction* terminalAction = terminalDock->toggleViewAction();
2098 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4, terminalAction, QStringLiteral("show_terminal_panel"));
2099
2100 addDockWidget(Qt::BottomDockWidgetArea, terminalDock);
2101 connect(this, &DolphinMainWindow::urlChanged,
2102 m_terminalPanel, &TerminalPanel::setUrl);
2103
2104 if (GeneralSettings::version() < 200) {
2105 terminalDock->hide();
2106 }
2107
2108 actionCollection()->action(QStringLiteral("show_terminal_panel"))
2109 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
2110 "<emphasis>terminal</emphasis> panel at the bottom of the window."
2111 "<nl/>The location in the terminal will always match the folder "
2112 "view so you can navigate using either.</para><para>The terminal "
2113 "panel is not needed for basic computer usage but can be useful "
2114 "for advanced tasks. To learn more about terminals use the help "
2115 "in a standalone terminal application like Konsole.</para>"));
2116 terminalDock->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is "
2117 "the <emphasis>terminal</emphasis> panel. It behaves like a "
2118 "normal terminal but will match the location of the folder view "
2119 "so you can navigate using either.</para><para>The terminal panel "
2120 "is not needed for basic computer usage but can be useful for "
2121 "advanced tasks. To learn more about terminals use the help in a "
2122 "standalone terminal application like Konsole.</para>") + panelWhatsThis);
2123 }
2124 #endif
2125
2126 if (GeneralSettings::version() < 200) {
2127 infoDock->hide();
2128 foldersDock->hide();
2129 }
2130
2131 // Setup "Places"
2132 DolphinDockWidget* placesDock = new DolphinDockWidget(i18nc("@title:window", "Places"));
2133 placesDock->setLocked(lock);
2134 placesDock->setObjectName(QStringLiteral("placesDock"));
2135 placesDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
2136
2137 m_placesPanel = new PlacesPanel(placesDock);
2138 m_placesPanel->setCustomContextMenuActions({lockLayoutAction});
2139 placesDock->setWidget(m_placesPanel);
2140
2141 QAction *placesAction = placesDock->toggleViewAction();
2142 createPanelAction(QIcon::fromTheme(QStringLiteral("compass")), Qt::Key_F9, placesAction, QStringLiteral("show_places_panel"));
2143
2144 addDockWidget(Qt::LeftDockWidgetArea, placesDock);
2145 connect(m_placesPanel, &PlacesPanel::placeActivated,
2146 this, &DolphinMainWindow::slotPlaceActivated);
2147 connect(m_placesPanel, &PlacesPanel::tabRequested,
2148 this, &DolphinMainWindow::openNewTab);
2149 connect(m_placesPanel, &PlacesPanel::activeTabRequested,
2150 this, &DolphinMainWindow::openNewTabAndActivate);
2151 connect(m_placesPanel, &PlacesPanel::newWindowRequested, this, [this](const QUrl &url) {
2152 Dolphin::openNewWindow({url}, this);
2153 });
2154 connect(m_placesPanel, &PlacesPanel::errorMessage,
2155 this, &DolphinMainWindow::showErrorMessage);
2156 connect(this, &DolphinMainWindow::urlChanged,
2157 m_placesPanel, &PlacesPanel::setUrl);
2158 connect(placesDock, &DolphinDockWidget::visibilityChanged,
2159 &DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged);
2160 connect(this, &DolphinMainWindow::settingsChanged,
2161 m_placesPanel, &PlacesPanel::readSettings);
2162 connect(m_placesPanel, &PlacesPanel::storageTearDownRequested,
2163 this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested);
2164 connect(m_placesPanel, &PlacesPanel::storageTearDownExternallyRequested,
2165 this, &DolphinMainWindow::slotStorageTearDownExternallyRequested);
2166 DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged(m_placesPanel->isVisible());
2167
2168 auto actionShowAllPlaces = new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this);
2169 actionShowAllPlaces->setCheckable(true);
2170 actionShowAllPlaces->setDisabled(true);
2171 actionShowAllPlaces->setWhatsThis(i18nc("@info:whatsthis", "This displays "
2172 "all places in the places panel that have been hidden. They will "
2173 "appear semi-transparent unless you uncheck their hide property."));
2174
2175 connect(actionShowAllPlaces, &QAction::triggered, this, [actionShowAllPlaces, this](bool checked){
2176 m_placesPanel->setShowAll(checked);
2177 });
2178 connect(m_placesPanel, &PlacesPanel::allPlacesShownChanged, actionShowAllPlaces, &QAction::setChecked);
2179
2180 actionCollection()->action(QStringLiteral("show_places_panel"))
2181 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
2182 "<emphasis>places</emphasis> panel at the left side of the window."
2183 "</para><para>It allows you to go to locations you have "
2184 "bookmarked and to access disk or media attached to the computer "
2185 "or to the network. It also contains sections to find recently "
2186 "saved files or files of a certain type.</para>"));
2187 placesDock->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2188 "<emphasis>Places</emphasis> panel. It allows you to go to locations "
2189 "you have bookmarked and to access disk or media attached to the "
2190 "computer or to the network. It also contains sections to find "
2191 "recently saved files or files of a certain type.</para><para>"
2192 "Click on an entry to go there. Click with the right mouse button "
2193 "instead to open any entry in a new tab or new window.</para>"
2194 "<para>New entries can be added by dragging folders onto this panel. "
2195 "Right-click any section or entry to hide it. Right-click an empty "
2196 "space on this panel and select <interface>Show Hidden Places"
2197 "</interface> to display it again.</para>") + panelWhatsThis);
2198
2199 // Add actions into the "Panels" menu
2200 KActionMenu* panelsMenu = new KActionMenu(i18nc("@action:inmenu View", "Show Panels"), this);
2201 actionCollection()->addAction(QStringLiteral("panels"), panelsMenu);
2202 panelsMenu->setIcon(QIcon::fromTheme(QStringLiteral("view-sidetree")));
2203 panelsMenu->setPopupMode(QToolButton::InstantPopup);
2204 const KActionCollection* ac = actionCollection();
2205 panelsMenu->addAction(ac->action(QStringLiteral("show_places_panel")));
2206 #if HAVE_BALOO
2207 panelsMenu->addAction(ac->action(QStringLiteral("show_information_panel")));
2208 #endif
2209 panelsMenu->addAction(ac->action(QStringLiteral("show_folders_panel")));
2210 panelsMenu->addAction(ac->action(QStringLiteral("show_terminal_panel")));
2211 panelsMenu->addSeparator();
2212 panelsMenu->addAction(actionShowAllPlaces);
2213 panelsMenu->addAction(lockLayoutAction);
2214
2215 connect(panelsMenu->menu(), &QMenu::aboutToShow, this, [actionShowAllPlaces, this]{
2216 actionShowAllPlaces->setEnabled(DolphinPlacesModelSingleton::instance().placesModel()->hiddenCount());
2217 });
2218 }
2219
2220
2221 void DolphinMainWindow::updateFileAndEditActions()
2222 {
2223 const KFileItemList list = m_activeViewContainer->view()->selectedItems();
2224 const KActionCollection* col = actionCollection();
2225 KFileItemListProperties capabilitiesSource(list);
2226
2227 QAction* renameAction = col->action(KStandardAction::name(KStandardAction::RenameFile));
2228 QAction* moveToTrashAction = col->action(KStandardAction::name(KStandardAction::MoveToTrash));
2229 QAction* deleteAction = col->action(KStandardAction::name(KStandardAction::DeleteFile));
2230 QAction* cutAction = col->action(KStandardAction::name(KStandardAction::Cut));
2231 QAction* duplicateAction = col->action(QStringLiteral("duplicate")); // see DolphinViewActionHandler
2232 QAction* addToPlacesAction = col->action(QStringLiteral("add_to_places"));
2233 QAction* copyToOtherViewAction = col->action(QStringLiteral("copy_to_inactive_split_view"));
2234 QAction* moveToOtherViewAction = col->action(QStringLiteral("move_to_inactive_split_view"));
2235 QAction* copyLocation = col->action(QString("copy_location"));
2236
2237 if (list.isEmpty()) {
2238 stateChanged(QStringLiteral("has_no_selection"));
2239
2240 // All actions that need a selection to function can be enabled because they should trigger selection mode.
2241 renameAction->setEnabled(true);
2242 moveToTrashAction->setEnabled(true);
2243 deleteAction->setEnabled(true);
2244 cutAction->setEnabled(true);
2245 duplicateAction->setEnabled(true);
2246 addToPlacesAction->setEnabled(true);
2247 copyLocation->setEnabled(true);
2248 } else {
2249 stateChanged(QStringLiteral("has_selection"));
2250
2251 QAction* deleteWithTrashShortcut = col->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
2252 QAction* showTarget = col->action(QStringLiteral("show_target"));
2253
2254 if (list.length() == 1 && list.first().isDir()) {
2255 addToPlacesAction->setEnabled(true);
2256 } else {
2257 addToPlacesAction->setEnabled(false);
2258 }
2259
2260 const bool enableMoveToTrash = capabilitiesSource.isLocal() && capabilitiesSource.supportsMoving();
2261
2262 renameAction->setEnabled(capabilitiesSource.supportsMoving());
2263 moveToTrashAction->setEnabled(enableMoveToTrash);
2264 deleteAction->setEnabled(capabilitiesSource.supportsDeleting());
2265 deleteWithTrashShortcut->setEnabled(capabilitiesSource.supportsDeleting() && !enableMoveToTrash);
2266 cutAction->setEnabled(capabilitiesSource.supportsMoving());
2267 copyLocation->setEnabled(list.length() == 1);
2268 showTarget->setEnabled(list.length() == 1 && list.at(0).isLink());
2269 duplicateAction->setEnabled(capabilitiesSource.supportsWriting());
2270 }
2271
2272 if (m_tabWidget->currentTabPage()->splitViewEnabled()) {
2273 DolphinTabPage* tabPage = m_tabWidget->currentTabPage();
2274 KFileItem capabilitiesDestination;
2275
2276 if (tabPage->primaryViewActive()) {
2277 capabilitiesDestination = tabPage->secondaryViewContainer()->url();
2278 } else {
2279 capabilitiesDestination = tabPage->primaryViewContainer()->url();
2280 }
2281
2282 copyToOtherViewAction->setEnabled(capabilitiesDestination.isWritable());
2283 moveToOtherViewAction->setEnabled((list.isEmpty() || capabilitiesSource.supportsMoving()) && capabilitiesDestination.isWritable());
2284 } else {
2285 copyToOtherViewAction->setEnabled(false);
2286 moveToOtherViewAction->setEnabled(false);
2287 }
2288 }
2289
2290 void DolphinMainWindow::updateViewActions()
2291 {
2292 m_actionHandler->updateViewActions();
2293
2294 QAction *toggleSelectionModeAction = actionCollection()->action(QStringLiteral("toggle_selection_mode"));
2295 disconnect(nullptr, &DolphinViewContainer::selectionModeChanged,
2296 toggleSelectionModeAction, &QAction::setChecked);
2297 toggleSelectionModeAction->setChecked(m_activeViewContainer->isSelectionModeEnabled());
2298 connect(m_activeViewContainer, &DolphinViewContainer::selectionModeChanged,
2299 toggleSelectionModeAction, &QAction::setChecked);
2300
2301 QAction* toggleFilterBarAction = actionCollection()->action(QStringLiteral("toggle_filter"));
2302 toggleFilterBarAction->setChecked(m_activeViewContainer->isFilterBarVisible());
2303
2304 updateSplitAction();
2305 }
2306
2307 void DolphinMainWindow::updateGoActions()
2308 {
2309 QAction* goUpAction = actionCollection()->action(KStandardAction::name(KStandardAction::Up));
2310 const QUrl currentUrl = m_activeViewContainer->url();
2311 // I think this is one of the best places to firstly be confronted
2312 // with a file system and its hierarchy. Talking about the root
2313 // directory might seem too much here but it is the question that
2314 // naturally arises in this context.
2315 goUpAction->setWhatsThis(xi18nc("@info:whatsthis", "<para>Go to "
2316 "the folder that contains the currently viewed one.</para>"
2317 "<para>All files and folders are organized in a hierarchical "
2318 "<emphasis>file system</emphasis>. At the top of this hierarchy is "
2319 "a directory that contains all data connected to this computer"
2320 "—the <emphasis>root directory</emphasis>.</para>"));
2321 goUpAction->setEnabled(KIO::upUrl(currentUrl) != currentUrl);
2322 }
2323
2324 void DolphinMainWindow::refreshViews()
2325 {
2326 m_tabWidget->refreshViews();
2327
2328 if (GeneralSettings::modifiedStartupSettings()) {
2329 updateWindowTitle();
2330 }
2331
2332 Q_EMIT settingsChanged();
2333 }
2334
2335 void DolphinMainWindow::clearStatusBar()
2336 {
2337 m_activeViewContainer->statusBar()->resetToDefaultText();
2338 }
2339
2340 void DolphinMainWindow::connectViewSignals(DolphinViewContainer* container)
2341 {
2342 connect(container, &DolphinViewContainer::showFilterBarChanged,
2343 this, &DolphinMainWindow::updateFilterBarAction);
2344 connect(container, &DolphinViewContainer::writeStateChanged,
2345 this, &DolphinMainWindow::slotWriteStateChanged);
2346 connect(container, &DolphinViewContainer::searchModeEnabledChanged,
2347 this, &DolphinMainWindow::updateSearchAction);
2348 connect(container, &DolphinViewContainer::captionChanged,
2349 this, &DolphinMainWindow::updateWindowTitle);
2350 connect(container, &DolphinViewContainer::tabRequested,
2351 this, &DolphinMainWindow::openNewTab);
2352 connect(container, &DolphinViewContainer::activeTabRequested,
2353 this, &DolphinMainWindow::openNewTabAndActivate);
2354
2355 const QAction* toggleSearchAction = actionCollection()->action(QStringLiteral("toggle_search"));
2356 connect(toggleSearchAction, &QAction::triggered, container, &DolphinViewContainer::setSearchModeEnabled);
2357
2358 const DolphinView* view = container->view();
2359 connect(view, &DolphinView::selectionChanged,
2360 this, &DolphinMainWindow::slotSelectionChanged);
2361 connect(view, &DolphinView::requestItemInfo,
2362 this, &DolphinMainWindow::requestItemInfo);
2363 connect(view, &DolphinView::fileItemsChanged,
2364 this, &DolphinMainWindow::fileItemsChanged);
2365 connect(view, &DolphinView::tabRequested,
2366 this, &DolphinMainWindow::openNewTab);
2367 connect(view, &DolphinView::activeTabRequested,
2368 this, &DolphinMainWindow::openNewTabAndActivate);
2369 connect(view, &DolphinView::windowRequested,
2370 this, &DolphinMainWindow::openNewWindow);
2371 connect(view, &DolphinView::requestContextMenu,
2372 this, &DolphinMainWindow::openContextMenu);
2373 connect(view, &DolphinView::directoryLoadingStarted,
2374 this, &DolphinMainWindow::enableStopAction);
2375 connect(view, &DolphinView::directoryLoadingCompleted,
2376 this, &DolphinMainWindow::disableStopAction);
2377 connect(view, &DolphinView::directoryLoadingCompleted,
2378 this, &DolphinMainWindow::slotDirectoryLoadingCompleted);
2379 connect(view, &DolphinView::goBackRequested,
2380 this, &DolphinMainWindow::goBack);
2381 connect(view, &DolphinView::goForwardRequested,
2382 this, &DolphinMainWindow::goForward);
2383 connect(view, &DolphinView::urlActivated,
2384 this, &DolphinMainWindow::handleUrl);
2385 connect(view, &DolphinView::goUpRequested,
2386 this, &DolphinMainWindow::goUp);
2387
2388 connect(container->urlNavigatorInternalWithHistory(), &KUrlNavigator::urlChanged,
2389 this, &DolphinMainWindow::changeUrl);
2390 connect(container->urlNavigatorInternalWithHistory(), &KUrlNavigator::historyChanged,
2391 this, &DolphinMainWindow::updateHistory);
2392
2393 auto navigators = static_cast<DolphinNavigatorsWidgetAction *>
2394 (actionCollection()->action(QStringLiteral("url_navigators")));
2395 const KUrlNavigator *navigator = m_tabWidget->currentTabPage()->primaryViewActive() ?
2396 navigators->primaryUrlNavigator() :
2397 navigators->secondaryUrlNavigator();
2398
2399 QAction *editableLocactionAction = actionCollection()->action(QStringLiteral("editable_location"));
2400 editableLocactionAction->setChecked(navigator->isUrlEditable());
2401 connect(navigator, &KUrlNavigator::editableStateChanged,
2402 this, &DolphinMainWindow::slotEditableStateChanged);
2403 connect(navigator, &KUrlNavigator::tabRequested,
2404 this, &DolphinMainWindow::openNewTab);
2405 connect(navigator, &KUrlNavigator::activeTabRequested,
2406 this, &DolphinMainWindow::openNewTabAndActivate);
2407 connect(navigator, &KUrlNavigator::newWindowRequested,
2408 this, &DolphinMainWindow::openNewWindow);
2409
2410 }
2411
2412 void DolphinMainWindow::updateSplitAction()
2413 {
2414 QAction* splitAction = actionCollection()->action(QStringLiteral("split_view"));
2415 const DolphinTabPage* tabPage = m_tabWidget->currentTabPage();
2416 if (tabPage->splitViewEnabled()) {
2417 if (GeneralSettings::closeActiveSplitView() ? tabPage->primaryViewActive() : !tabPage->primaryViewActive()) {
2418 splitAction->setText(i18nc("@action:intoolbar Close left view", "Close"));
2419 splitAction->setToolTip(i18nc("@info", "Close left view"));
2420 splitAction->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close")));
2421 } else {
2422 splitAction->setText(i18nc("@action:intoolbar Close right view", "Close"));
2423 splitAction->setToolTip(i18nc("@info", "Close right view"));
2424 splitAction->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close")));
2425 }
2426 } else {
2427 splitAction->setText(i18nc("@action:intoolbar Split view", "Split"));
2428 splitAction->setToolTip(i18nc("@info", "Split view"));
2429 splitAction->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2430 }
2431 }
2432
2433 void DolphinMainWindow::updateAllowedToolbarAreas()
2434 {
2435 auto navigators = static_cast<DolphinNavigatorsWidgetAction *>
2436 (actionCollection()->action(QStringLiteral("url_navigators")));
2437 if (toolBar()->actions().contains(navigators)) {
2438 toolBar()->setAllowedAreas(Qt::TopToolBarArea | Qt::BottomToolBarArea);
2439 if (toolBarArea(toolBar()) == Qt::LeftToolBarArea ||
2440 toolBarArea(toolBar()) == Qt::RightToolBarArea) {
2441 addToolBar(Qt::TopToolBarArea, toolBar());
2442 }
2443 } else {
2444 toolBar()->setAllowedAreas(Qt::AllToolBarAreas);
2445 }
2446 }
2447
2448 bool DolphinMainWindow::isKompareInstalled() const
2449 {
2450 static bool initialized = false;
2451 static bool installed = false;
2452 if (!initialized) {
2453 // TODO: maybe replace this approach later by using a menu
2454 // plugin like kdiff3plugin.cpp
2455 installed = !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty();
2456 initialized = true;
2457 }
2458 return installed;
2459 }
2460
2461 void DolphinMainWindow::createPanelAction(const QIcon& icon,
2462 const QKeySequence& shortcut,
2463 QAction* dockAction,
2464 const QString& actionName)
2465 {
2466 QAction* panelAction = actionCollection()->addAction(actionName);
2467 panelAction->setCheckable(true);
2468 panelAction->setChecked(dockAction->isChecked());
2469 panelAction->setText(dockAction->text());
2470 panelAction->setIcon(icon);
2471 dockAction->setIcon(icon);
2472 actionCollection()->setDefaultShortcut(panelAction, shortcut);
2473
2474 connect(panelAction, &QAction::triggered, dockAction, &QAction::trigger);
2475 connect(dockAction, &QAction::toggled, panelAction, &QAction::setChecked);
2476 }
2477
2478 void DolphinMainWindow::setupWhatsThis()
2479 {
2480 // main widgets
2481 menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2482 "<emphasis>Menubar</emphasis>. It provides access to commands and "
2483 "configuration options. Left-click on any of the menus on this "
2484 "bar to see its contents.</para><para>The Menubar can be hidden "
2485 "by unchecking <interface>Settings|Show Menubar</interface>. Then "
2486 "most of its contents become available through a <interface>Control"
2487 "</interface> button on the <emphasis>Toolbar</emphasis>.</para>"));
2488 toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2489 "<emphasis>Toolbar</emphasis>. It allows quick access to "
2490 "frequently used actions.</para><para>It is highly customizable. "
2491 "All items you see in the <interface>Control</interface> menu or "
2492 "in the <interface>Menubar</interface> can be placed on the "
2493 "Toolbar. Just right-click on it and select <interface>Configure "
2494 "Toolbars…</interface> or find this action in the <interface>"
2495 "Control</interface> or <interface>Settings</interface> menu."
2496 "</para><para>The location of the bar and the style of its "
2497 "buttons can also be changed in the right-click menu. Right-click "
2498 "a button if you want to show or hide its text.</para>"));
2499 m_tabWidget->setWhatsThis(xi18nc("@info:whatsthis main view",
2500 "<para>Here you can see the <emphasis>folders</emphasis> and "
2501 "<emphasis>files</emphasis> that are at the location described in "
2502 "the <interface>Location Bar</interface> above. This area is the "
2503 "central part of this application where you navigate to the files "
2504 "you want to use.</para><para>For an elaborate and general "
2505 "introduction to this application <link "
2506 "url='https://userbase.kde.org/Dolphin/File_Management#Introduction_to_Dolphin'>"
2507 "click here</link>. This will open an introductory article from "
2508 "the <emphasis>KDE UserBase Wiki</emphasis>.</para><para>For brief "
2509 "explanations of all the features of this <emphasis>view</emphasis> "
2510 "<link url='help:/dolphin/dolphin-view.html'>click here</link> "
2511 "instead. This will open a page from the <emphasis>Handbook"
2512 "</emphasis> that covers the basics.</para>"));
2513
2514 // Settings menu
2515 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings))
2516 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window "
2517 "that lists the <emphasis>keyboard shortcuts</emphasis>.<nl/>"
2518 "There you can set up key combinations to trigger an action when "
2519 "they are pressed simultaneously. All commands in this application can "
2520 "be triggered this way.</para>"));
2521 actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars))
2522 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window in which "
2523 "you can change which buttons appear on the <emphasis>Toolbar</emphasis>.</para>"
2524 "<para>All items you see in the <interface>Control</interface> menu "
2525 "or in the <interface>Menubar</interface> can also be placed on the Toolbar.</para>"));
2526 actionCollection()->action(KStandardAction::name(KStandardAction::Preferences))
2527 ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can "
2528 "change a multitude of settings for this application. For an explanation "
2529 "of the various settings go to the chapter <emphasis>Configuring Dolphin"
2530 "</emphasis> in <interface>Help|Dolphin Handbook</interface>."));
2531
2532 // Help menu
2533 // The whatsthis has to be set for the m_helpMenu and for the
2534 // StandardAction separately because both are used in different locations.
2535 // m_helpMenu is only used for createControlButton() button.
2536
2537 auto setStandardActionWhatsThis = [this](KStandardAction::StandardAction actionId,
2538 const QString &whatsThis) {
2539 if (auto *action = actionCollection()->action(KStandardAction::name(actionId))) {
2540 action->setWhatsThis(whatsThis);
2541 }
2542 };
2543 auto setHelpActionWhatsThis = [this](KHelpMenu::MenuId menuId, const QString &whatsThis) {
2544 if (auto *action = m_helpMenu->action(menuId)) {
2545 action->setWhatsThis(whatsThis);
2546 }
2547 };
2548
2549 // Links do not work within the Menubar so texts without links are provided there.
2550
2551 // i18n: If the external link isn't available in your language you should
2552 // probably state the external link language at least in brackets to not
2553 // frustrate the user. If there are multiple languages that the user might
2554 // know with a reasonable chance you might want to have 2 external links.
2555 // The same is in my opinion true for every external link you translate.
2556 const QString whatsThisHelpContents = xi18nc("@info:whatsthis handbook",
2557 "<para>This opens the Handbook for this application. It provides "
2558 "explanations for every part of <emphasis>Dolphin</emphasis>.</para>");
2559 setStandardActionWhatsThis(KStandardAction::HelpContents, whatsThisHelpContents
2560 + xi18nc("@info:whatsthis second half of handbook hb text without link",
2561 "<para>If you want more elaborate introductions to the "
2562 "different features of <emphasis>Dolphin</emphasis> "
2563 "go to the KDE UserBase Wiki.</para>"));
2564 setHelpActionWhatsThis(KHelpMenu::menuHelpContents, whatsThisHelpContents
2565 + xi18nc("@info:whatsthis second half of handbook text with link",
2566 "<para>If you want more elaborate introductions to the "
2567 "different features of <emphasis>Dolphin</emphasis> "
2568 "<link url='https://userbase.kde.org/Dolphin/File_Management'>click here</link>. "
2569 "It will open the dedicated page in the KDE UserBase Wiki.</para>"));
2570
2571 const QString whatsThisWhatsThis = xi18nc("@info:whatsthis whatsthis button",
2572 "<para>This is the button that invokes the help feature you are "
2573 "using right now! Click it, then click any component of this "
2574 "application to ask \"What's this?\" about it. The mouse cursor "
2575 "will change appearance if no help is available for a spot.</para>");
2576 setStandardActionWhatsThis(KStandardAction::WhatsThis, whatsThisWhatsThis
2577 + xi18nc("@info:whatsthis second half of whatsthis button text without link",
2578 "<para>There are two other ways to get help for this application: The "
2579 "<interface>Dolphin Handbook</interface> in the <interface>Help"
2580 "</interface> menu and the <emphasis>KDE UserBase Wiki</emphasis> "
2581 "article about <emphasis>File Management</emphasis> online."
2582 "</para><para>The \"What's this?\" help is "
2583 "missing in most other windows so don't get too used to this.</para>"));
2584 setHelpActionWhatsThis(KHelpMenu::menuWhatsThis, whatsThisWhatsThis
2585 + xi18nc("@info:whatsthis second half of whatsthis button text with link",
2586 "<para>There are two other ways to get help: "
2587 "The <link url='help:/dolphin/index.html'>Dolphin Handbook</link> and "
2588 "the <link url='https://userbase.kde.org/Dolphin/File_Management'>KDE "
2589 "UserBase Wiki</link>.</para><para>The \"What's this?\" help is "
2590 "missing in most other windows so don't get too used to this.</para>"));
2591
2592 const QString whatsThisReportBug = xi18nc("@info:whatsthis","<para>This opens a "
2593 "window that will guide you through reporting errors or flaws "
2594 "in this application or in other KDE software.</para>");
2595 setStandardActionWhatsThis(KStandardAction::ReportBug, whatsThisReportBug);
2596 setHelpActionWhatsThis(KHelpMenu::menuReportBug, whatsThisReportBug
2597 + xi18nc("@info:whatsthis second half of reportbug text with link",
2598 "<para>High-quality bug reports are much appreciated. To learn "
2599 "how to make your bug report as effective as possible "
2600 "<link url='https://community.kde.org/Get_Involved/Bug_Reporting'>"
2601 "click here</link>.</para>"));
2602
2603 const QString whatsThisDonate = xi18nc("@info:whatsthis","<para>This opens a "
2604 "<emphasis>web page</emphasis> where you can donate to "
2605 "support the continued work on this application and many "
2606 "other projects by the <emphasis>KDE</emphasis> community.</para>"
2607 "<para>Donating is the easiest and fastest way to efficiently "
2608 "support KDE and its projects. KDE projects are available for "
2609 "free therefore your donation is needed to cover things that "
2610 "require money like servers, contributor meetings, etc.</para>"
2611 "<para><emphasis>KDE e.V.</emphasis> is the non-profit "
2612 "organization behind the KDE community.</para>");
2613 setStandardActionWhatsThis(KStandardAction::Donate, whatsThisDonate);
2614 setHelpActionWhatsThis(KHelpMenu::menuDonate, whatsThisDonate);
2615
2616 const QString whatsThisSwitchLanguage = xi18nc("@info:whatsthis",
2617 "With this you can change the language this application uses."
2618 "<nl/>You can even set secondary languages which will be used "
2619 "if texts are not available in your preferred language.");
2620 setStandardActionWhatsThis(KStandardAction::SwitchApplicationLanguage,
2621 whatsThisSwitchLanguage);
2622 setHelpActionWhatsThis(KHelpMenu::menuSwitchLanguage, whatsThisSwitchLanguage);
2623
2624 const QString whatsThisAboutApp = xi18nc("@info:whatsthis","This opens a "
2625 "window that informs you about the version, license, "
2626 "used libraries and maintainers of this application.");
2627 setStandardActionWhatsThis(KStandardAction::AboutApp, whatsThisAboutApp);
2628 setHelpActionWhatsThis(KHelpMenu::menuAboutApp, whatsThisAboutApp);
2629
2630 const QString whatsThisAboutKDE = xi18nc("@info:whatsthis","This opens a "
2631 "window with information about <emphasis>KDE</emphasis>. "
2632 "The KDE community are the people behind this free software."
2633 "<nl/>If you like using this application but don't know "
2634 "about KDE or want to see a cute dragon have a look!");
2635 setStandardActionWhatsThis(KStandardAction::AboutKDE, whatsThisAboutKDE);
2636 setHelpActionWhatsThis(KHelpMenu::menuAboutKDE, whatsThisAboutKDE);
2637 }
2638
2639 bool DolphinMainWindow::addHamburgerMenuToToolbar()
2640 {
2641 QDomDocument domDocument = KXMLGUIClient::domDocument();
2642 if (domDocument.isNull()) {
2643 return false;
2644 }
2645 QDomNode toolbar = domDocument.elementsByTagName(QStringLiteral("ToolBar")).at(0);
2646 if (toolbar.isNull()) {
2647 return false;
2648 }
2649
2650 QDomElement hamburgerMenuElement = domDocument.createElement(QStringLiteral("Action"));
2651 hamburgerMenuElement.setAttribute(QStringLiteral("name"), QStringLiteral("hamburger_menu"));
2652 toolbar.appendChild(hamburgerMenuElement);
2653
2654 KXMLGUIFactory::saveConfigFile(domDocument, xmlFile());
2655 reloadXML();
2656 createGUI();
2657 return true;
2658 // Make sure to also remove the <KXMLGUIFactory> and <QDomDocument> include
2659 // whenever this method is removed (maybe in the year ~2026).
2660 }
2661
2662 bool DolphinMainWindow::event(QEvent *event)
2663 {
2664 if (event->type() == QEvent::WhatsThisClicked) {
2665 event->accept();
2666 QWhatsThisClickedEvent* whatsThisEvent = dynamic_cast<QWhatsThisClickedEvent*>(event);
2667 QDesktopServices::openUrl(QUrl(whatsThisEvent->href()));
2668 return true;
2669 }
2670 return KXmlGuiWindow::event(event);
2671 }
2672
2673 bool DolphinMainWindow::eventFilter(QObject* obj, QEvent* event)
2674 {
2675 Q_UNUSED(obj)
2676 if (event->type() == QEvent::WhatsThisClicked) {
2677 event->accept();
2678 QWhatsThisClickedEvent* whatsThisEvent = dynamic_cast<QWhatsThisClickedEvent*>(event);
2679 QDesktopServices::openUrl(QUrl(whatsThisEvent->href()));
2680 return true;
2681 }
2682 return false;
2683 }
2684
2685 // Set a sane initial window size
2686 QSize DolphinMainWindow::sizeHint() const
2687 {
2688 return KXmlGuiWindow::sizeHint().expandedTo(QSize(760, 550));
2689 }
2690
2691 void DolphinMainWindow::saveNewToolbarConfig()
2692 {
2693 KXmlGuiWindow::saveNewToolbarConfig(); // Applies the new config. This has to be called first
2694 // because the rest of this method decides things
2695 // based on the new config.
2696 auto navigators = static_cast<DolphinNavigatorsWidgetAction *>
2697 (actionCollection()->action(QStringLiteral("url_navigators")));
2698 if (!toolBar()->actions().contains(navigators)) {
2699 m_tabWidget->currentTabPage()->insertNavigatorsWidget(navigators);
2700 }
2701 updateAllowedToolbarAreas();
2702 (static_cast<KHamburgerMenu *>(actionCollection()->action(KStandardAction::name(
2703 KStandardAction::HamburgerMenu))))->hideActionsOf(toolBar());
2704 }
2705
2706 void DolphinMainWindow::focusTerminalPanel()
2707 {
2708 if (m_terminalPanel->isVisible()) {
2709 if (m_terminalPanel->terminalHasFocus()) {
2710 m_activeViewContainer->view()->setFocus(Qt::FocusReason::ShortcutFocusReason);
2711 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2712 } else {
2713 m_terminalPanel->setFocus(Qt::FocusReason::ShortcutFocusReason);
2714 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2715 }
2716 } else {
2717 actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger();
2718 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2719 }
2720 }
2721
2722 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
2723 KIO::FileUndoManager::UiInterface()
2724 {
2725 }
2726
2727 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2728 {
2729 }
2730
2731 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job* job)
2732 {
2733 DolphinMainWindow* mainWin= qobject_cast<DolphinMainWindow *>(parentWidget());
2734 if (mainWin) {
2735 DolphinViewContainer* container = mainWin->activeViewContainer();
2736 container->showMessage(job->errorString(), DolphinViewContainer::Error);
2737 } else {
2738 KIO::FileUndoManager::UiInterface::jobError(job);
2739 }
2740 }
2741
2742 bool DolphinMainWindow::isUrlOpen(const QString &url)
2743 {
2744 return m_tabWidget->isUrlOpen(QUrl::fromUserInput(url));
2745 }
2746
2747 bool DolphinMainWindow::isUrlOrParentOpen(const QString &url)
2748 {
2749 return m_tabWidget->isUrlOrParentOpen(QUrl::fromUserInput(url));
2750 }