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