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