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