]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.cpp
Clear filter bar on clicking current folder in places
[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 view->clearFilterBar(); // Fixes bug 259382.
1418
1419 // We can end up here if the user clicked a device in the Places Panel
1420 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1421 reloadView();
1422 } else {
1423 view->disableUrlNavigatorSelectionRequests();
1424 changeUrl(url);
1425 view->enableUrlNavigatorSelectionRequests();
1426 }
1427 }
1428
1429 void DolphinMainWindow::closedTabsCountChanged(unsigned int count)
1430 {
1431 actionCollection()->action(QStringLiteral("undo_close_tab"))->setEnabled(count > 0);
1432 }
1433
1434 void DolphinMainWindow::activeViewChanged(DolphinViewContainer* viewContainer)
1435 {
1436 DolphinViewContainer* oldViewContainer = m_activeViewContainer;
1437 Q_ASSERT(viewContainer);
1438
1439 m_activeViewContainer = viewContainer;
1440
1441 if (oldViewContainer) {
1442 const QAction* toggleSearchAction = actionCollection()->action(QStringLiteral("toggle_search"));
1443 toggleSearchAction->disconnect(oldViewContainer);
1444
1445 // Disconnect all signals between the old view container (container,
1446 // view and url navigator) and main window.
1447 oldViewContainer->disconnect(this);
1448 oldViewContainer->view()->disconnect(this);
1449 oldViewContainer->urlNavigatorInternalWithHistory()->disconnect(this);
1450 auto navigators = static_cast<DolphinNavigatorsWidgetAction *>
1451 (actionCollection()->action(QStringLiteral("url_navigators")));
1452 navigators->primaryUrlNavigator()->disconnect(this);
1453 if (auto secondaryUrlNavigator = navigators->secondaryUrlNavigator()) {
1454 secondaryUrlNavigator->disconnect(this);
1455 }
1456
1457 // except the requestItemInfo so that on hover the information panel can still be updated
1458 connect(oldViewContainer->view(), &DolphinView::requestItemInfo,
1459 this, &DolphinMainWindow::requestItemInfo);
1460
1461 // Disconnect other slots.
1462 disconnect(nullptr, &DolphinViewContainer::selectionModeChanged,
1463 actionCollection()->action(QStringLiteral("toggle_selection_mode")), &QAction::setChecked);
1464 }
1465
1466 connectViewSignals(viewContainer);
1467
1468 m_actionHandler->setCurrentView(viewContainer->view());
1469
1470 updateHistory();
1471 updateFileAndEditActions();
1472 updatePasteAction();
1473 updateViewActions();
1474 updateGoActions();
1475 updateSearchAction();
1476
1477 const QUrl url = viewContainer->url();
1478 Q_EMIT urlChanged(url);
1479 }
1480
1481 void DolphinMainWindow::tabCountChanged(int count)
1482 {
1483 const bool enableTabActions = (count > 1);
1484 for (int i = 0; i < MaxActivateTabShortcuts; ++i) {
1485 actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i))->setEnabled(enableTabActions);
1486 }
1487 actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions);
1488 actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions);
1489 actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions);
1490 }
1491
1492 void DolphinMainWindow::updateWindowTitle()
1493 {
1494 const QString newTitle = m_activeViewContainer->captionWindowTitle();
1495 if (windowTitle() != newTitle) {
1496 setWindowTitle(newTitle);
1497 }
1498 }
1499
1500 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString& mountPath)
1501 {
1502 connect(m_placesPanel, &PlacesPanel::storageTearDownSuccessful, this, [this, mountPath]() {
1503 setViewsToHomeIfMountPathOpen(mountPath);
1504 });
1505
1506 if (m_terminalPanel && m_terminalPanel->currentWorkingDirectory().startsWith(mountPath)) {
1507 m_tearDownFromPlacesRequested = true;
1508 m_terminalPanel->goHome();
1509 // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
1510 } else {
1511 m_placesPanel->proceedWithTearDown();
1512 }
1513 }
1514
1515 void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString& mountPath)
1516 {
1517 connect(m_placesPanel, &PlacesPanel::storageTearDownSuccessful, this, [this, mountPath]() {
1518 setViewsToHomeIfMountPathOpen(mountPath);
1519 });
1520
1521 if (m_terminalPanel && m_terminalPanel->currentWorkingDirectory().startsWith(mountPath)) {
1522 m_tearDownFromPlacesRequested = false;
1523 m_terminalPanel->goHome();
1524 }
1525 }
1526
1527 void DolphinMainWindow::slotKeyBindings()
1528 {
1529 KShortcutsDialog dialog(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsAllowed, this);
1530 dialog.addCollection(actionCollection());
1531 if (m_terminalPanel) {
1532 KActionCollection *konsolePartActionCollection = m_terminalPanel->actionCollection();
1533 if (konsolePartActionCollection) {
1534 dialog.addCollection(konsolePartActionCollection, QStringLiteral("KonsolePart"));
1535 }
1536 }
1537 dialog.configure();
1538 }
1539
1540 void DolphinMainWindow::setViewsToHomeIfMountPathOpen(const QString& mountPath)
1541 {
1542 const QVector<DolphinViewContainer*> theViewContainers = viewContainers();
1543 for (DolphinViewContainer *viewContainer : theViewContainers) {
1544 if (viewContainer && viewContainer->url().toLocalFile().startsWith(mountPath)) {
1545 viewContainer->setUrl(QUrl::fromLocalFile(QDir::homePath()));
1546 }
1547 }
1548 disconnect(m_placesPanel, &PlacesPanel::storageTearDownSuccessful, nullptr, nullptr);
1549 }
1550
1551 void DolphinMainWindow::setupActions()
1552 {
1553 auto hamburgerMenuAction = KStandardAction::hamburgerMenu(nullptr, nullptr, actionCollection());
1554
1555 // setup 'File' menu
1556 m_newFileMenu = new DolphinNewFileMenu(actionCollection(), this);
1557 QMenu* menu = m_newFileMenu->menu();
1558 menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1559 menu->setIcon(QIcon::fromTheme(QStringLiteral("list-add")));
1560 m_newFileMenu->setPopupMode(QToolButton::InstantPopup);
1561 connect(menu, &QMenu::aboutToShow,
1562 this, &DolphinMainWindow::updateNewMenu);
1563
1564 QAction* newWindow = KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow, actionCollection());
1565 newWindow->setText(i18nc("@action:inmenu File", "New &Window"));
1566 newWindow->setToolTip(i18nc("@info", "Open a new Dolphin window"));
1567 newWindow->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1568 "window just like this one with the current location and view."
1569 "<nl/>You can drag and drop items between windows."));
1570 newWindow->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1571
1572 QAction* newTab = actionCollection()->addAction(QStringLiteral("new_tab"));
1573 newTab->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1574 newTab->setText(i18nc("@action:inmenu File", "New Tab"));
1575 newTab->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1576 "<emphasis>Tab</emphasis> with the current location and view.<nl/>"
1577 "A tab is an additional view within this window. "
1578 "You can drag and drop items between tabs."));
1579 actionCollection()->setDefaultShortcuts(newTab, {Qt::CTRL | Qt::Key_T, Qt::CTRL | Qt::SHIFT | Qt::Key_N});
1580 connect(newTab, &QAction::triggered, this, &DolphinMainWindow::openNewActivatedTab);
1581
1582 QAction* addToPlaces = actionCollection()->addAction(QStringLiteral("add_to_places"));
1583 addToPlaces->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new")));
1584 addToPlaces->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places"));
1585 addToPlaces->setWhatsThis(xi18nc("@info:whatsthis", "This adds the selected folder "
1586 "to the Places panel."));
1587 connect(addToPlaces, &QAction::triggered, this, &DolphinMainWindow::addToPlaces);
1588
1589 QAction* closeTab = KStandardAction::close(m_tabWidget, QOverload<>::of(&DolphinTabWidget::closeTab), actionCollection());
1590 closeTab->setText(i18nc("@action:inmenu File", "Close Tab"));
1591 closeTab->setWhatsThis(i18nc("@info:whatsthis", "This closes the "
1592 "currently viewed tab. If no more tabs are left this window "
1593 "will close instead."));
1594
1595 QAction* quitAction = KStandardAction::quit(this, &DolphinMainWindow::quit, actionCollection());
1596 quitAction->setWhatsThis(i18nc("@info:whatsthis quit", "This closes this window."));
1597
1598 // setup 'Edit' menu
1599 KStandardAction::undo(this,
1600 &DolphinMainWindow::undo,
1601 actionCollection());
1602
1603 // i18n: This will be the last paragraph for the whatsthis for all three:
1604 // Cut, Copy and Paste
1605 const QString cutCopyPastePara = xi18nc("@info:whatsthis", "<para><emphasis>Cut, "
1606 "Copy</emphasis> and <emphasis>Paste</emphasis> work between many "
1607 "applications and are among the most used commands. That's why their "
1608 "<emphasis>keyboard shortcuts</emphasis> are prominently placed right "
1609 "next to each other on the keyboard: <shortcut>Ctrl+X</shortcut>, "
1610 "<shortcut>Ctrl+C</shortcut> and <shortcut>Ctrl+V</shortcut>.</para>");
1611 QAction* cutAction = KStandardAction::cut(this, &DolphinMainWindow::cut, actionCollection());
1612 m_actionTextHelper->registerTextWhenNothingIsSelected(cutAction, i18nc("@action", "Cut…"));
1613 cutAction->setWhatsThis(xi18nc("@info:whatsthis cut", "This copies the items "
1614 "in your current selection to the <emphasis>clipboard</emphasis>.<nl/>"
1615 "Use the <emphasis>Paste</emphasis> action afterwards to copy them from "
1616 "the clipboard to a new location. The items will be removed from their "
1617 "initial location.") + cutCopyPastePara);
1618 QAction* copyAction = KStandardAction::copy(this, &DolphinMainWindow::copy, actionCollection());
1619 m_actionTextHelper->registerTextWhenNothingIsSelected(copyAction, i18nc("@action", "Copy…"));
1620 copyAction->setWhatsThis(xi18nc("@info:whatsthis copy", "This copies the "
1621 "items in your current selection to the <emphasis>clipboard</emphasis>."
1622 "<nl/>Use the <emphasis>Paste</emphasis> action afterwards to copy them "
1623 "from the clipboard to a new location.") + cutCopyPastePara);
1624 QAction* paste = KStandardAction::paste(this, &DolphinMainWindow::paste, actionCollection());
1625 // The text of the paste-action is modified dynamically by Dolphin
1626 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1627 // due to the long text, the text "Paste" is used:
1628 paste->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1629 paste->setWhatsThis(xi18nc("@info:whatsthis paste", "This copies the items from "
1630 "your <emphasis>clipboard</emphasis> to the currently viewed folder.<nl/>"
1631 "If the items were added to the clipboard by the <emphasis>Cut</emphasis> "
1632 "action they are removed from their old location.") + cutCopyPastePara);
1633
1634 QAction* copyToOtherViewAction = actionCollection()->addAction(QStringLiteral("copy_to_inactive_split_view"));
1635 copyToOtherViewAction->setText(i18nc("@action:inmenu", "Copy to Inactive Split View"));
1636 m_actionTextHelper->registerTextWhenNothingIsSelected(copyToOtherViewAction, i18nc("@action:inmenu", "Copy to Inactive Split View…"));
1637 copyToOtherViewAction->setWhatsThis(xi18nc("@info:whatsthis Copy", "This copies the selected items from "
1638 "the <emphasis>active</emphasis> view to the inactive split view."));
1639 copyToOtherViewAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
1640 copyToOtherViewAction->setIconText(i18nc("@action:inmenu Edit", "Copy to Inactive Split View"));
1641 actionCollection()->setDefaultShortcut(copyToOtherViewAction, Qt::SHIFT | Qt::Key_F5 );
1642 connect(copyToOtherViewAction, &QAction::triggered, this, &DolphinMainWindow::copyToInactiveSplitView);
1643
1644 QAction* moveToOtherViewAction = actionCollection()->addAction(QStringLiteral("move_to_inactive_split_view"));
1645 moveToOtherViewAction->setText(i18nc("@action:inmenu", "Move to Inactive Split View"));
1646 m_actionTextHelper->registerTextWhenNothingIsSelected(moveToOtherViewAction, i18nc("@action:inmenu", "Move to Inactive Split View…"));
1647 moveToOtherViewAction->setWhatsThis(xi18nc("@info:whatsthis Move", "This moves the selected items from "
1648 "the <emphasis>active</emphasis> view to the inactive split view."));
1649 moveToOtherViewAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-cut")));
1650 moveToOtherViewAction->setIconText(i18nc("@action:inmenu Edit", "Move to Inactive Split View"));
1651 actionCollection()->setDefaultShortcut(moveToOtherViewAction, Qt::SHIFT | Qt::Key_F6 );
1652 connect(moveToOtherViewAction, &QAction::triggered, this, &DolphinMainWindow::moveToInactiveSplitView);
1653
1654 QAction* showFilterBar = actionCollection()->addAction(QStringLiteral("show_filter_bar"));
1655 showFilterBar->setText(i18nc("@action:inmenu Tools", "Filter..."));
1656 showFilterBar->setToolTip(i18nc("@info:tooltip", "Show Filter Bar"));
1657 showFilterBar->setWhatsThis(xi18nc("@info:whatsthis", "This opens the "
1658 "<emphasis>Filter Bar</emphasis> at the bottom of the window.<nl/> "
1659 "There you can enter a text to filter the files and folders currently displayed. "
1660 "Only those that contain the text in their name will be kept in view."));
1661 showFilterBar->setIcon(QIcon::fromTheme(QStringLiteral("view-filter")));
1662 actionCollection()->setDefaultShortcuts(showFilterBar, {Qt::CTRL | Qt::Key_I, Qt::Key_Slash});
1663 connect(showFilterBar, &QAction::triggered, this, &DolphinMainWindow::showFilterBar);
1664
1665 // toggle_filter acts as a copy of the main showFilterBar to be used mainly
1666 // in the toolbar, with no default shortcut attached, to avoid messing with
1667 // existing workflows (filter bar always open and Ctrl-I to focus)
1668 QAction *toggleFilter = actionCollection()->addAction(QStringLiteral("toggle_filter"));
1669 toggleFilter->setText(i18nc("@action:inmenu", "Toggle Filter Bar"));
1670 toggleFilter->setIconText(i18nc("@action:intoolbar", "Filter"));
1671 toggleFilter->setIcon(showFilterBar->icon());
1672 toggleFilter->setToolTip(showFilterBar->toolTip());
1673 toggleFilter->setWhatsThis(showFilterBar->whatsThis());
1674 toggleFilter->setCheckable(true);
1675 connect(toggleFilter, &QAction::triggered, this, &DolphinMainWindow::toggleFilterBar);
1676
1677 QAction *searchAction = KStandardAction::find(this, &DolphinMainWindow::find, actionCollection());
1678 searchAction->setText(i18n("Search..."));
1679 searchAction->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
1680 searchAction->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This helps you "
1681 "find files and folders by opening a <emphasis>find bar</emphasis>. "
1682 "There you can enter search terms and specify settings to find the "
1683 "objects you are looking for.</para><para>Use this help again on "
1684 "the find bar so we can have a look at it while the settings are "
1685 "explained.</para>"));
1686
1687 // toggle_search acts as a copy of the main searchAction to be used mainly
1688 // in the toolbar, with no default shortcut attached, to avoid messing with
1689 // existing workflows (search bar always open and Ctrl-F to focus)
1690 QAction *toggleSearchAction = actionCollection()->addAction(QStringLiteral("toggle_search"));
1691 toggleSearchAction->setText(i18nc("@action:inmenu", "Toggle Search Bar"));
1692 toggleSearchAction->setIconText(i18nc("@action:intoolbar", "Search"));
1693 toggleSearchAction->setIcon(searchAction->icon());
1694 toggleSearchAction->setToolTip(searchAction->toolTip());
1695 toggleSearchAction->setWhatsThis(searchAction->whatsThis());
1696 toggleSearchAction->setCheckable(true);
1697
1698 QAction *toggleSelectionModeAction = actionCollection()->addAction(QStringLiteral("toggle_selection_mode"));
1699 // i18n: This action toggles a selection mode.
1700 toggleSelectionModeAction->setText(i18nc("@action:inmenu", "Select Files and Folders"));
1701 // i18n: Opens a selection mode for selecting files/folders.
1702 // The text is kept so unspecific because it will be shown on the toolbar where space is at a premium.
1703 toggleSelectionModeAction->setIconText(i18nc("@action:intoolbar", "Select"));
1704 toggleSelectionModeAction->setWhatsThis(xi18nc("@info:whatsthis", "<para>This application only knows which files or folders should be acted on if they are"
1705 " <emphasis>selected</emphasis> first. Press this to toggle a <emphasis>Selection Mode</emphasis> which makes selecting and deselecting as easy as "
1706 "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."
1707 "</para>"));
1708 toggleSelectionModeAction->setIcon(QIcon::fromTheme(QStringLiteral("quickwizard")));
1709 toggleSelectionModeAction->setCheckable(true);
1710 connect(toggleSelectionModeAction, &QAction::triggered, this, &DolphinMainWindow::toggleSelectionMode);
1711
1712 // A special version of the toggleSelectionModeAction for the toolbar that also contains a menu
1713 // with the selectAllAction and invertSelectionAction.
1714 auto *toggleSelectionModeToolBarAction = new KToolBarPopupAction(toggleSelectionModeAction->icon(), toggleSelectionModeAction->iconText(), actionCollection());
1715 toggleSelectionModeToolBarAction->setToolTip(toggleSelectionModeAction->text());
1716 toggleSelectionModeToolBarAction->setWhatsThis(toggleSelectionModeAction->whatsThis());
1717 actionCollection()->addAction(QStringLiteral("toggle_selection_mode_tool_bar"), toggleSelectionModeToolBarAction);
1718 toggleSelectionModeToolBarAction->setCheckable(true);
1719 toggleSelectionModeToolBarAction->setPopupMode(QToolButton::DelayedPopup);
1720 connect(toggleSelectionModeToolBarAction, &QAction::triggered, toggleSelectionModeAction, &QAction::trigger);
1721 connect(toggleSelectionModeAction, &QAction::toggled, toggleSelectionModeToolBarAction, &QAction::setChecked);
1722
1723 QAction* selectAllAction = KStandardAction::selectAll(this, &DolphinMainWindow::selectAll, actionCollection());
1724 selectAllAction->setWhatsThis(xi18nc("@info:whatsthis", "This selects all "
1725 "files and folders in the current location."));
1726
1727 QAction* invertSelection = actionCollection()->addAction(QStringLiteral("invert_selection"));
1728 invertSelection->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1729 invertSelection->setWhatsThis(xi18nc("@info:whatsthis invert", "This selects all "
1730 "objects that you have currently <emphasis>not</emphasis> selected instead."));
1731 invertSelection->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert")));
1732 actionCollection()->setDefaultShortcut(invertSelection, Qt::CTRL | Qt::SHIFT | Qt::Key_A);
1733 connect(invertSelection, &QAction::triggered, this, &DolphinMainWindow::invertSelection);
1734
1735 QMenu *toggleSelectionModeActionMenu = new QMenu(this);
1736 toggleSelectionModeActionMenu->addAction(selectAllAction);
1737 toggleSelectionModeActionMenu->addAction(invertSelection);
1738 toggleSelectionModeToolBarAction->setMenu(toggleSelectionModeActionMenu);
1739
1740 // setup 'View' menu
1741 // (note that most of it is set up in DolphinViewActionHandler)
1742
1743 QAction* split = actionCollection()->addAction(QStringLiteral("split_view"));
1744 split->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This splits "
1745 "the folder view below into two autonomous views.</para><para>This "
1746 "way you can see two locations at once and move items between them "
1747 "quickly.</para>Click this again afterwards to recombine the views."));
1748 actionCollection()->setDefaultShortcut(split, Qt::Key_F3);
1749 connect(split, &QAction::triggered, this, &DolphinMainWindow::toggleSplitView);
1750
1751 QAction* stashSplit = actionCollection()->addAction(QStringLiteral("split_stash"));
1752 actionCollection()->setDefaultShortcut(stashSplit, Qt::CTRL | Qt::Key_S);
1753 stashSplit->setText(i18nc("@action:intoolbar Stash", "Stash"));
1754 stashSplit->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
1755 stashSplit->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
1756 stashSplit->setCheckable(false);
1757 QDBusConnectionInterface *sessionInterface = QDBusConnection::sessionBus().interface();
1758 stashSplit->setVisible(sessionInterface && sessionInterface->isServiceRegistered(QStringLiteral("org.kde.kio.StashNotifier")));
1759 connect(stashSplit, &QAction::triggered, this, &DolphinMainWindow::toggleSplitStash);
1760
1761 KStandardAction::redisplay(this, &DolphinMainWindow::reloadView, actionCollection());
1762
1763 QAction* stop = actionCollection()->addAction(QStringLiteral("stop"));
1764 stop->setText(i18nc("@action:inmenu View", "Stop"));
1765 stop->setToolTip(i18nc("@info", "Stop loading"));
1766 stop->setWhatsThis(i18nc("@info", "This stops the loading of the contents of the current folder."));
1767 stop->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
1768 connect(stop, &QAction::triggered, this, &DolphinMainWindow::stopLoading);
1769
1770 KToggleAction* editableLocation = actionCollection()->add<KToggleAction>(QStringLiteral("editable_location"));
1771 editableLocation->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1772 editableLocation->setWhatsThis(xi18nc("@info:whatsthis",
1773 "This toggles the <emphasis>Location Bar</emphasis> to be "
1774 "editable so you can directly enter a location you want to go to.<nl/>"
1775 "You can also switch to editing by clicking to the right of the "
1776 "location and switch back by confirming the edited location."));
1777 actionCollection()->setDefaultShortcut(editableLocation, Qt::Key_F6);
1778 connect(editableLocation, &KToggleAction::triggered, this, &DolphinMainWindow::toggleEditLocation);
1779
1780 QAction* replaceLocation = actionCollection()->addAction(QStringLiteral("replace_location"));
1781 replaceLocation->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1782 // i18n: "enter" is used both in the meaning of "writing" and "going to" a new location here.
1783 // Both meanings are useful but not necessary to understand the use of "Replace Location".
1784 // So you might want to be more verbose in your language to convey the meaning but it's up to you.
1785 replaceLocation->setWhatsThis(xi18nc("@info:whatsthis",
1786 "This switches to editing the location and selects it "
1787 "so you can quickly enter a different location."));
1788 actionCollection()->setDefaultShortcut(replaceLocation, Qt::CTRL | Qt::Key_L);
1789 connect(replaceLocation, &QAction::triggered, this, &DolphinMainWindow::replaceLocation);
1790
1791 // setup 'Go' menu
1792 {
1793 QScopedPointer<QAction> backAction(KStandardAction::back(nullptr, nullptr, nullptr));
1794 m_backAction = new KToolBarPopupAction(backAction->icon(), backAction->text(), actionCollection());
1795 m_backAction->setObjectName(backAction->objectName());
1796 m_backAction->setShortcuts(backAction->shortcuts());
1797 }
1798 m_backAction->setPopupMode(QToolButton::DelayedPopup);
1799 connect(m_backAction, &QAction::triggered, this, &DolphinMainWindow::goBack);
1800 connect(m_backAction->menu(), &QMenu::aboutToShow, this, &DolphinMainWindow::slotAboutToShowBackPopupMenu);
1801 connect(m_backAction->menu(), &QMenu::triggered, this, &DolphinMainWindow::slotGoBack);
1802 actionCollection()->addAction(m_backAction->objectName(), m_backAction);
1803
1804 auto backShortcuts = m_backAction->shortcuts();
1805 backShortcuts.append(QKeySequence(Qt::Key_Backspace));
1806 actionCollection()->setDefaultShortcuts(m_backAction, backShortcuts);
1807
1808 DolphinRecentTabsMenu* recentTabsMenu = new DolphinRecentTabsMenu(this);
1809 actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu);
1810 connect(m_tabWidget, &DolphinTabWidget::rememberClosedTab,
1811 recentTabsMenu, &DolphinRecentTabsMenu::rememberClosedTab);
1812 connect(recentTabsMenu, &DolphinRecentTabsMenu::restoreClosedTab,
1813 m_tabWidget, &DolphinTabWidget::restoreClosedTab);
1814 connect(recentTabsMenu, &DolphinRecentTabsMenu::closedTabsCountChanged,
1815 this, &DolphinMainWindow::closedTabsCountChanged);
1816
1817 QAction* undoCloseTab = actionCollection()->addAction(QStringLiteral("undo_close_tab"));
1818 undoCloseTab->setText(i18nc("@action:inmenu File", "Undo close tab"));
1819 undoCloseTab->setWhatsThis(i18nc("@info:whatsthis undo close tab",
1820 "This returns you to the previously closed tab."));
1821 actionCollection()->setDefaultShortcut(undoCloseTab, Qt::CTRL | Qt::SHIFT | Qt::Key_T);
1822 undoCloseTab->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
1823 undoCloseTab->setEnabled(false);
1824 connect(undoCloseTab, &QAction::triggered, recentTabsMenu, &DolphinRecentTabsMenu::undoCloseTab);
1825
1826 auto undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo));
1827 undoAction->setWhatsThis(xi18nc("@info:whatsthis", "This undoes "
1828 "the last change you made to files or folders.<nl/>"
1829 "Such changes include <interface>creating, renaming</interface> "
1830 "and <interface>moving</interface> them to a different location "
1831 "or to the <filename>Trash</filename>. <nl/>Changes that can't "
1832 "be undone will ask for your confirmation."));
1833 undoAction->setEnabled(false); // undo should be disabled by default
1834
1835 {
1836 QScopedPointer<QAction> forwardAction(KStandardAction::forward(nullptr, nullptr, nullptr));
1837 m_forwardAction = new KToolBarPopupAction(forwardAction->icon(), forwardAction->text(), actionCollection());
1838 m_forwardAction->setObjectName(forwardAction->objectName());
1839 m_forwardAction->setShortcuts(forwardAction->shortcuts());
1840 }
1841 m_forwardAction->setPopupMode(QToolButton::DelayedPopup);
1842 connect(m_forwardAction, &QAction::triggered, this, &DolphinMainWindow::goForward);
1843 connect(m_forwardAction->menu(), &QMenu::aboutToShow, this, &DolphinMainWindow::slotAboutToShowForwardPopupMenu);
1844 connect(m_forwardAction->menu(), &QMenu::triggered, this, &DolphinMainWindow::slotGoForward);
1845 actionCollection()->addAction(m_forwardAction->objectName(), m_forwardAction);
1846 actionCollection()->setDefaultShortcuts(m_forwardAction, m_forwardAction->shortcuts());
1847
1848 // enable middle-click to open in a new tab
1849 auto *middleClickEventFilter = new MiddleClickActionEventFilter(this);
1850 connect(middleClickEventFilter, &MiddleClickActionEventFilter::actionMiddleClicked, this, &DolphinMainWindow::slotBackForwardActionMiddleClicked);
1851 m_backAction->menu()->installEventFilter(middleClickEventFilter);
1852 m_forwardAction->menu()->installEventFilter(middleClickEventFilter);
1853 KStandardAction::up(this, &DolphinMainWindow::goUp, actionCollection());
1854 QAction* homeAction = KStandardAction::home(this, &DolphinMainWindow::goHome, actionCollection());
1855 homeAction->setWhatsThis(xi18nc("@info:whatsthis", "Go to your "
1856 "<filename>Home</filename> folder.<nl/>Every user account "
1857 "has their own <filename>Home</filename> that contains their data "
1858 "including folders that contain personal application data."));
1859
1860 // setup 'Tools' menu
1861 QAction* compareFiles = actionCollection()->addAction(QStringLiteral("compare_files"));
1862 compareFiles->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1863 compareFiles->setIcon(QIcon::fromTheme(QStringLiteral("kompare")));
1864 compareFiles->setEnabled(false);
1865 connect(compareFiles, &QAction::triggered, this, &DolphinMainWindow::compareFiles);
1866
1867 QAction* openPreferredSearchTool = actionCollection()->addAction(QStringLiteral("open_preferred_search_tool"));
1868 openPreferredSearchTool->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1869 openPreferredSearchTool->setWhatsThis(xi18nc("@info:whatsthis",
1870 "<para>This opens a preferred search tool for the viewed location.</para>"
1871 "<para>Use <emphasis>More Search Tools</emphasis> menu to configure it.</para>"));
1872 openPreferredSearchTool->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1873 actionCollection()->setDefaultShortcut(openPreferredSearchTool, Qt::CTRL | Qt::SHIFT | Qt::Key_F);
1874 connect(openPreferredSearchTool, &QAction::triggered, this, &DolphinMainWindow::openPreferredSearchTool);
1875
1876 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1877 QAction* openTerminal = actionCollection()->addAction(QStringLiteral("open_terminal"));
1878 openTerminal->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1879 openTerminal->setWhatsThis(xi18nc("@info:whatsthis",
1880 "<para>This opens a <emphasis>terminal</emphasis> application for the viewed location.</para>"
1881 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1882 openTerminal->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
1883 actionCollection()->setDefaultShortcut(openTerminal, Qt::SHIFT | Qt::Key_F4);
1884 connect(openTerminal, &QAction::triggered, this, &DolphinMainWindow::openTerminal);
1885
1886 QAction* openTerminalHere = actionCollection()->addAction(QStringLiteral("open_terminal_here"));
1887 // i18n: "Here" refers to the location(s) of the currently selected item(s) or the currently viewed location if nothing is selected.
1888 openTerminalHere->setText(i18nc("@action:inmenu Tools", "Open Terminal Here"));
1889 openTerminalHere->setWhatsThis(xi18nc("@info:whatsthis",
1890 "<para>This opens <emphasis>terminal</emphasis> applications for the selected items' locations.</para>"
1891 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1892 openTerminalHere->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
1893 actionCollection()->setDefaultShortcut(openTerminalHere, Qt::SHIFT | Qt::ALT | Qt::Key_F4);
1894 connect(openTerminalHere, &QAction::triggered, this, &DolphinMainWindow::openTerminalHere);
1895
1896 #if HAVE_TERMINAL
1897 QAction* focusTerminalPanel = actionCollection()->addAction(QStringLiteral("focus_terminal_panel"));
1898 focusTerminalPanel->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
1899 focusTerminalPanel->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
1900 actionCollection()->setDefaultShortcut(focusTerminalPanel, Qt::CTRL | Qt::SHIFT | Qt::Key_F4);
1901 connect(focusTerminalPanel, &QAction::triggered, this, &DolphinMainWindow::focusTerminalPanel);
1902 #endif
1903 }
1904
1905 // setup 'Bookmarks' menu
1906 KActionMenu *bookmarkMenu = new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this);
1907 bookmarkMenu->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks")));
1908 // Make the toolbar button version work properly on click
1909 bookmarkMenu->setPopupMode(QToolButton::InstantPopup);
1910 m_bookmarkHandler = new DolphinBookmarkHandler(this, actionCollection(), bookmarkMenu->menu(), this);
1911 actionCollection()->addAction(QStringLiteral("bookmarks"), bookmarkMenu);
1912
1913 // setup 'Settings' menu
1914 KToggleAction* showMenuBar = KStandardAction::showMenubar(nullptr, nullptr, actionCollection());
1915 showMenuBar->setWhatsThis(xi18nc("@info:whatsthis",
1916 "<para>This switches between having a <emphasis>Menubar</emphasis> "
1917 "and having a <interface>%1</interface> button. Both "
1918 "contain mostly the same actions and configuration options.</para>"
1919 "<para>The Menubar takes up more space but allows for fast and organised access to all "
1920 "actions an application has to offer.</para><para>The <interface>%1</interface> button "
1921 "is simpler and small which makes triggering advanced actions more time consuming.</para>", hamburgerMenuAction->text().replace('&', "")));
1922 connect(showMenuBar, &KToggleAction::triggered, // Fixes #286822
1923 this, &DolphinMainWindow::toggleShowMenuBar, Qt::QueuedConnection);
1924
1925 KToggleAction* showStatusBar = KStandardAction::showStatusbar(nullptr, nullptr, actionCollection());
1926 showStatusBar->setChecked(GeneralSettings::showStatusBar());
1927 connect(GeneralSettings::self(), &GeneralSettings::showStatusBarChanged, showStatusBar, &KToggleAction::setChecked);
1928 connect(showStatusBar, &KToggleAction::triggered, this, [this](bool checked) {
1929 GeneralSettings::setShowStatusBar(checked);
1930 refreshViews();
1931 });
1932
1933 KStandardAction::keyBindings(this, &DolphinMainWindow::slotKeyBindings, actionCollection());
1934 KStandardAction::preferences(this, &DolphinMainWindow::editSettings, actionCollection());
1935
1936 // not in menu actions
1937 QList<QKeySequence> nextTabKeys = KStandardShortcut::tabNext();
1938 nextTabKeys.append(QKeySequence(Qt::CTRL | Qt::Key_Tab));
1939
1940 QList<QKeySequence> prevTabKeys = KStandardShortcut::tabPrev();
1941 prevTabKeys.append(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_Tab));
1942
1943 for (int i = 0; i < MaxActivateTabShortcuts; ++i) {
1944 QAction* activateTab = actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i));
1945 activateTab->setText(i18nc("@action:inmenu", "Activate Tab %1", i + 1));
1946 activateTab->setEnabled(false);
1947 connect(activateTab, &QAction::triggered, this, [this, i]() { m_tabWidget->activateTab(i); });
1948
1949 // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts
1950 if (i < 9) {
1951 actionCollection()->setDefaultShortcut(activateTab, QStringLiteral("Alt+%1").arg(i + 1));
1952 }
1953 }
1954
1955 QAction* activateLastTab = actionCollection()->addAction(QStringLiteral("activate_last_tab"));
1956 activateLastTab->setText(i18nc("@action:inmenu", "Activate Last Tab"));
1957 activateLastTab->setEnabled(false);
1958 connect(activateLastTab, &QAction::triggered, m_tabWidget, &DolphinTabWidget::activateLastTab);
1959 actionCollection()->setDefaultShortcut(activateLastTab, Qt::ALT | Qt::Key_0);
1960
1961 QAction* activateNextTab = actionCollection()->addAction(QStringLiteral("activate_next_tab"));
1962 activateNextTab->setIconText(i18nc("@action:inmenu", "Next Tab"));
1963 activateNextTab->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1964 activateNextTab->setEnabled(false);
1965 connect(activateNextTab, &QAction::triggered, m_tabWidget, &DolphinTabWidget::activateNextTab);
1966 actionCollection()->setDefaultShortcuts(activateNextTab, nextTabKeys);
1967
1968 QAction* activatePrevTab = actionCollection()->addAction(QStringLiteral("activate_prev_tab"));
1969 activatePrevTab->setIconText(i18nc("@action:inmenu", "Previous Tab"));
1970 activatePrevTab->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1971 activatePrevTab->setEnabled(false);
1972 connect(activatePrevTab, &QAction::triggered, m_tabWidget, &DolphinTabWidget::activatePrevTab);
1973 actionCollection()->setDefaultShortcuts(activatePrevTab, prevTabKeys);
1974
1975 // for context menu
1976 QAction* showTarget = actionCollection()->addAction(QStringLiteral("show_target"));
1977 showTarget->setText(i18nc("@action:inmenu", "Show Target"));
1978 showTarget->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
1979 showTarget->setEnabled(false);
1980 connect(showTarget, &QAction::triggered, this, &DolphinMainWindow::showTarget);
1981
1982 QAction* openInNewTab = actionCollection()->addAction(QStringLiteral("open_in_new_tab"));
1983 openInNewTab->setText(i18nc("@action:inmenu", "Open in New Tab"));
1984 openInNewTab->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1985 connect(openInNewTab, &QAction::triggered, this, &DolphinMainWindow::openInNewTab);
1986
1987 QAction* openInNewTabs = actionCollection()->addAction(QStringLiteral("open_in_new_tabs"));
1988 openInNewTabs->setText(i18nc("@action:inmenu", "Open in New Tabs"));
1989 openInNewTabs->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1990 connect(openInNewTabs, &QAction::triggered, this, &DolphinMainWindow::openInNewTab);
1991
1992 QAction* openInNewWindow = actionCollection()->addAction(QStringLiteral("open_in_new_window"));
1993 openInNewWindow->setText(i18nc("@action:inmenu", "Open in New Window"));
1994 openInNewWindow->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1995 connect(openInNewWindow, &QAction::triggered, this, &DolphinMainWindow::openInNewWindow);
1996 }
1997
1998 void DolphinMainWindow::setupDockWidgets()
1999 {
2000 const bool lock = GeneralSettings::lockPanels();
2001
2002 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(lock);
2003
2004 KDualAction* lockLayoutAction = actionCollection()->add<KDualAction>(QStringLiteral("lock_panels"));
2005 lockLayoutAction->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
2006 lockLayoutAction->setActiveIcon(QIcon::fromTheme(QStringLiteral("object-unlocked")));
2007 lockLayoutAction->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
2008 lockLayoutAction->setInactiveIcon(QIcon::fromTheme(QStringLiteral("object-locked")));
2009 lockLayoutAction->setWhatsThis(xi18nc("@info:whatsthis", "This "
2010 "switches between having panels <emphasis>locked</emphasis> or "
2011 "<emphasis>unlocked</emphasis>.<nl/>Unlocked panels can be "
2012 "dragged to the other side of the window and have a close "
2013 "button.<nl/>Locked panels are embedded more cleanly."));
2014 lockLayoutAction->setActive(lock);
2015 connect(lockLayoutAction, &KDualAction::triggered, this, &DolphinMainWindow::togglePanelLockState);
2016
2017 // Setup "Information"
2018 DolphinDockWidget* infoDock = new DolphinDockWidget(i18nc("@title:window", "Information"));
2019 infoDock->setLocked(lock);
2020 infoDock->setObjectName(QStringLiteral("infoDock"));
2021 infoDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
2022
2023 #if HAVE_BALOO
2024 InformationPanel* infoPanel = new InformationPanel(infoDock);
2025 infoPanel->setCustomContextMenuActions({lockLayoutAction});
2026 connect(infoPanel, &InformationPanel::urlActivated, this, &DolphinMainWindow::handleUrl);
2027 infoDock->setWidget(infoPanel);
2028
2029 QAction* infoAction = infoDock->toggleViewAction();
2030 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-information")), Qt::Key_F11, infoAction, QStringLiteral("show_information_panel"));
2031
2032 addDockWidget(Qt::RightDockWidgetArea, infoDock);
2033 connect(this, &DolphinMainWindow::urlChanged,
2034 infoPanel, &InformationPanel::setUrl);
2035 connect(this, &DolphinMainWindow::selectionChanged,
2036 infoPanel, &InformationPanel::setSelection);
2037 connect(this, &DolphinMainWindow::requestItemInfo,
2038 infoPanel, &InformationPanel::requestDelayedItemInfo);
2039 connect(this, &DolphinMainWindow::fileItemsChanged,
2040 infoPanel, &InformationPanel::slotFilesItemChanged);
2041 #endif
2042
2043 // i18n: This is the last paragraph for the "What's This"-texts of all four panels.
2044 const QString panelWhatsThis = xi18nc("@info:whatsthis", "<para>To show or "
2045 "hide panels like this go to <interface>Menu|Panels</interface> "
2046 "or <interface>View|Panels</interface>.</para>");
2047 #if HAVE_BALOO
2048 actionCollection()->action(QStringLiteral("show_information_panel"))
2049 ->setWhatsThis(xi18nc("@info:whatsthis", "<para> This toggles the "
2050 "<emphasis>information</emphasis> panel at the right side of the "
2051 "window.</para><para>The panel provides in-depth information "
2052 "about the items your mouse is hovering over or about the selected "
2053 "items. Otherwise it informs you about the currently viewed folder.<nl/>"
2054 "For single items a preview of their contents is provided.</para>"));
2055 #endif
2056 infoDock->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
2057 "provides in-depth information about the items your mouse is "
2058 "hovering over or about the selected items. Otherwise it informs "
2059 "you about the currently viewed folder.<nl/>For single items a "
2060 "preview of their contents is provided.</para><para>You can configure "
2061 "which and how details are given here by right-clicking.</para>") + panelWhatsThis);
2062
2063 // Setup "Folders"
2064 DolphinDockWidget* foldersDock = new DolphinDockWidget(i18nc("@title:window", "Folders"));
2065 foldersDock->setLocked(lock);
2066 foldersDock->setObjectName(QStringLiteral("foldersDock"));
2067 foldersDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
2068 FoldersPanel* foldersPanel = new FoldersPanel(foldersDock);
2069 foldersPanel->setCustomContextMenuActions({lockLayoutAction});
2070 foldersDock->setWidget(foldersPanel);
2071
2072 QAction* foldersAction = foldersDock->toggleViewAction();
2073 createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7, foldersAction, QStringLiteral("show_folders_panel"));
2074
2075 addDockWidget(Qt::LeftDockWidgetArea, foldersDock);
2076 connect(this, &DolphinMainWindow::urlChanged,
2077 foldersPanel, &FoldersPanel::setUrl);
2078 connect(foldersPanel, &FoldersPanel::folderActivated,
2079 this, &DolphinMainWindow::changeUrl);
2080 connect(foldersPanel, &FoldersPanel::folderInNewTab,
2081 this, &DolphinMainWindow::openNewTab);
2082 connect(foldersPanel, &FoldersPanel::folderInNewActiveTab,
2083 this, &DolphinMainWindow::openNewTabAndActivate);
2084 connect(foldersPanel, &FoldersPanel::errorMessage,
2085 this, &DolphinMainWindow::showErrorMessage);
2086
2087 actionCollection()->action(QStringLiteral("show_folders_panel"))
2088 ->setWhatsThis(xi18nc("@info:whatsthis", "This toggles the "
2089 "<emphasis>folders</emphasis> panel at the left side of the window."
2090 "<nl/><nl/>It shows the folders of the <emphasis>file system"
2091 "</emphasis> in a <emphasis>tree view</emphasis>."));
2092 foldersDock->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
2093 "shows the folders of the <emphasis>file system</emphasis> in a "
2094 "<emphasis>tree view</emphasis>.</para><para>Click a folder to go "
2095 "there. Click the arrow to the left of a folder to see its subfolders. "
2096 "This allows quick switching between any folders.</para>") + panelWhatsThis);
2097
2098 // Setup "Terminal"
2099 #if HAVE_TERMINAL
2100 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
2101 DolphinDockWidget* terminalDock = new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
2102 terminalDock->setLocked(lock);
2103 terminalDock->setObjectName(QStringLiteral("terminalDock"));
2104 m_terminalPanel = new TerminalPanel(terminalDock);
2105 m_terminalPanel->setCustomContextMenuActions({lockLayoutAction});
2106 terminalDock->setWidget(m_terminalPanel);
2107
2108 connect(m_terminalPanel, &TerminalPanel::hideTerminalPanel, terminalDock, &DolphinDockWidget::hide);
2109 connect(m_terminalPanel, &TerminalPanel::changeUrl, this, &DolphinMainWindow::slotTerminalDirectoryChanged);
2110 connect(terminalDock, &DolphinDockWidget::visibilityChanged,
2111 m_terminalPanel, &TerminalPanel::dockVisibilityChanged);
2112 connect(terminalDock, &DolphinDockWidget::visibilityChanged,
2113 this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged);
2114
2115 QAction* terminalAction = terminalDock->toggleViewAction();
2116 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4, terminalAction, QStringLiteral("show_terminal_panel"));
2117
2118 addDockWidget(Qt::BottomDockWidgetArea, terminalDock);
2119 connect(this, &DolphinMainWindow::urlChanged,
2120 m_terminalPanel, &TerminalPanel::setUrl);
2121
2122 if (GeneralSettings::version() < 200) {
2123 terminalDock->hide();
2124 }
2125
2126 actionCollection()->action(QStringLiteral("show_terminal_panel"))
2127 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
2128 "<emphasis>terminal</emphasis> panel at the bottom of the window."
2129 "<nl/>The location in the terminal will always match the folder "
2130 "view so you can navigate using either.</para><para>The terminal "
2131 "panel is not needed for basic computer usage but can be useful "
2132 "for advanced tasks. To learn more about terminals use the help "
2133 "in a standalone terminal application like Konsole.</para>"));
2134 terminalDock->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is "
2135 "the <emphasis>terminal</emphasis> panel. It behaves like a "
2136 "normal terminal but will match the location of the folder view "
2137 "so you can navigate using either.</para><para>The terminal panel "
2138 "is not needed for basic computer usage but can be useful for "
2139 "advanced tasks. To learn more about terminals use the help in a "
2140 "standalone terminal application like Konsole.</para>") + panelWhatsThis);
2141 }
2142 #endif
2143
2144 if (GeneralSettings::version() < 200) {
2145 infoDock->hide();
2146 foldersDock->hide();
2147 }
2148
2149 // Setup "Places"
2150 DolphinDockWidget* placesDock = new DolphinDockWidget(i18nc("@title:window", "Places"));
2151 placesDock->setLocked(lock);
2152 placesDock->setObjectName(QStringLiteral("placesDock"));
2153 placesDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
2154
2155 m_placesPanel = new PlacesPanel(placesDock);
2156 m_placesPanel->setCustomContextMenuActions({lockLayoutAction});
2157 placesDock->setWidget(m_placesPanel);
2158
2159 QAction *placesAction = placesDock->toggleViewAction();
2160 createPanelAction(QIcon::fromTheme(QStringLiteral("compass")), Qt::Key_F9, placesAction, QStringLiteral("show_places_panel"));
2161
2162 addDockWidget(Qt::LeftDockWidgetArea, placesDock);
2163 connect(m_placesPanel, &PlacesPanel::placeActivated,
2164 this, &DolphinMainWindow::slotPlaceActivated);
2165 connect(m_placesPanel, &PlacesPanel::tabRequested,
2166 this, &DolphinMainWindow::openNewTab);
2167 connect(m_placesPanel, &PlacesPanel::activeTabRequested,
2168 this, &DolphinMainWindow::openNewTabAndActivate);
2169 connect(m_placesPanel, &PlacesPanel::newWindowRequested, this, [this](const QUrl &url) {
2170 Dolphin::openNewWindow({url}, this);
2171 });
2172 connect(m_placesPanel, &PlacesPanel::errorMessage,
2173 this, &DolphinMainWindow::showErrorMessage);
2174 connect(this, &DolphinMainWindow::urlChanged,
2175 m_placesPanel, &PlacesPanel::setUrl);
2176 connect(placesDock, &DolphinDockWidget::visibilityChanged,
2177 &DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged);
2178 connect(this, &DolphinMainWindow::settingsChanged,
2179 m_placesPanel, &PlacesPanel::readSettings);
2180 connect(m_placesPanel, &PlacesPanel::storageTearDownRequested,
2181 this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested);
2182 connect(m_placesPanel, &PlacesPanel::storageTearDownExternallyRequested,
2183 this, &DolphinMainWindow::slotStorageTearDownExternallyRequested);
2184 DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged(m_placesPanel->isVisible());
2185
2186 auto actionShowAllPlaces = new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this);
2187 actionShowAllPlaces->setCheckable(true);
2188 actionShowAllPlaces->setDisabled(true);
2189 actionShowAllPlaces->setWhatsThis(i18nc("@info:whatsthis", "This displays "
2190 "all places in the places panel that have been hidden. They will "
2191 "appear semi-transparent unless you uncheck their hide property."));
2192
2193 connect(actionShowAllPlaces, &QAction::triggered, this, [actionShowAllPlaces, this](bool checked){
2194 m_placesPanel->setShowAll(checked);
2195 });
2196 connect(m_placesPanel, &PlacesPanel::allPlacesShownChanged, actionShowAllPlaces, &QAction::setChecked);
2197
2198 actionCollection()->action(QStringLiteral("show_places_panel"))
2199 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
2200 "<emphasis>places</emphasis> panel at the left side of the window."
2201 "</para><para>It allows you to go to locations you have "
2202 "bookmarked and to access disk or media attached to the computer "
2203 "or to the network. It also contains sections to find recently "
2204 "saved files or files of a certain type.</para>"));
2205 placesDock->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2206 "<emphasis>Places</emphasis> panel. It allows you to go to locations "
2207 "you have bookmarked and to access disk or media attached to the "
2208 "computer or to the network. It also contains sections to find "
2209 "recently saved files or files of a certain type.</para><para>"
2210 "Click on an entry to go there. Click with the right mouse button "
2211 "instead to open any entry in a new tab or new window.</para>"
2212 "<para>New entries can be added by dragging folders onto this panel. "
2213 "Right-click any section or entry to hide it. Right-click an empty "
2214 "space on this panel and select <interface>Show Hidden Places"
2215 "</interface> to display it again.</para>") + panelWhatsThis);
2216
2217 // Add actions into the "Panels" menu
2218 KActionMenu* panelsMenu = new KActionMenu(i18nc("@action:inmenu View", "Show Panels"), this);
2219 actionCollection()->addAction(QStringLiteral("panels"), panelsMenu);
2220 panelsMenu->setIcon(QIcon::fromTheme(QStringLiteral("view-sidetree")));
2221 panelsMenu->setPopupMode(QToolButton::InstantPopup);
2222 const KActionCollection* ac = actionCollection();
2223 panelsMenu->addAction(ac->action(QStringLiteral("show_places_panel")));
2224 #if HAVE_BALOO
2225 panelsMenu->addAction(ac->action(QStringLiteral("show_information_panel")));
2226 #endif
2227 panelsMenu->addAction(ac->action(QStringLiteral("show_folders_panel")));
2228 panelsMenu->addAction(ac->action(QStringLiteral("show_terminal_panel")));
2229 panelsMenu->addSeparator();
2230 panelsMenu->addAction(actionShowAllPlaces);
2231 panelsMenu->addAction(lockLayoutAction);
2232
2233 connect(panelsMenu->menu(), &QMenu::aboutToShow, this, [actionShowAllPlaces, this]{
2234 actionShowAllPlaces->setEnabled(DolphinPlacesModelSingleton::instance().placesModel()->hiddenCount());
2235 });
2236 }
2237
2238
2239 void DolphinMainWindow::updateFileAndEditActions()
2240 {
2241 const KFileItemList list = m_activeViewContainer->view()->selectedItems();
2242 const KActionCollection* col = actionCollection();
2243 KFileItemListProperties capabilitiesSource(list);
2244
2245 QAction* renameAction = col->action(KStandardAction::name(KStandardAction::RenameFile));
2246 QAction* moveToTrashAction = col->action(KStandardAction::name(KStandardAction::MoveToTrash));
2247 QAction* deleteAction = col->action(KStandardAction::name(KStandardAction::DeleteFile));
2248 QAction* cutAction = col->action(KStandardAction::name(KStandardAction::Cut));
2249 QAction* duplicateAction = col->action(QStringLiteral("duplicate")); // see DolphinViewActionHandler
2250 QAction* addToPlacesAction = col->action(QStringLiteral("add_to_places"));
2251 QAction* copyToOtherViewAction = col->action(QStringLiteral("copy_to_inactive_split_view"));
2252 QAction* moveToOtherViewAction = col->action(QStringLiteral("move_to_inactive_split_view"));
2253 QAction* copyLocation = col->action(QString("copy_location"));
2254
2255 if (list.isEmpty()) {
2256 stateChanged(QStringLiteral("has_no_selection"));
2257
2258 // All actions that need a selection to function can be enabled because they should trigger selection mode.
2259 renameAction->setEnabled(true);
2260 moveToTrashAction->setEnabled(true);
2261 deleteAction->setEnabled(true);
2262 cutAction->setEnabled(true);
2263 duplicateAction->setEnabled(true);
2264 addToPlacesAction->setEnabled(true);
2265 copyLocation->setEnabled(true);
2266 // Them triggering selection mode and not directly acting on selected items is signified by adding "…" to their text.
2267 m_actionTextHelper->textsWhenNothingIsSelectedEnabled(true);
2268
2269 } else {
2270 m_actionTextHelper->textsWhenNothingIsSelectedEnabled(false);
2271 stateChanged(QStringLiteral("has_selection"));
2272
2273 QAction* deleteWithTrashShortcut = col->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
2274 QAction* showTarget = col->action(QStringLiteral("show_target"));
2275
2276 if (list.length() == 1 && list.first().isDir()) {
2277 addToPlacesAction->setEnabled(true);
2278 } else {
2279 addToPlacesAction->setEnabled(false);
2280 }
2281
2282 const bool enableMoveToTrash = capabilitiesSource.isLocal() && capabilitiesSource.supportsMoving();
2283
2284 renameAction->setEnabled(capabilitiesSource.supportsMoving());
2285 moveToTrashAction->setEnabled(enableMoveToTrash);
2286 deleteAction->setEnabled(capabilitiesSource.supportsDeleting());
2287 deleteWithTrashShortcut->setEnabled(capabilitiesSource.supportsDeleting() && !enableMoveToTrash);
2288 cutAction->setEnabled(capabilitiesSource.supportsMoving());
2289 copyLocation->setEnabled(list.length() == 1);
2290 showTarget->setEnabled(list.length() == 1 && list.at(0).isLink());
2291 duplicateAction->setEnabled(capabilitiesSource.supportsWriting());
2292 }
2293
2294 if (m_tabWidget->currentTabPage()->splitViewEnabled()) {
2295 DolphinTabPage* tabPage = m_tabWidget->currentTabPage();
2296 KFileItem capabilitiesDestination;
2297
2298 if (tabPage->primaryViewActive()) {
2299 capabilitiesDestination = tabPage->secondaryViewContainer()->url();
2300 } else {
2301 capabilitiesDestination = tabPage->primaryViewContainer()->url();
2302 }
2303
2304 copyToOtherViewAction->setEnabled(capabilitiesDestination.isWritable());
2305 moveToOtherViewAction->setEnabled((list.isEmpty() || capabilitiesSource.supportsMoving()) && capabilitiesDestination.isWritable());
2306 } else {
2307 copyToOtherViewAction->setEnabled(false);
2308 moveToOtherViewAction->setEnabled(false);
2309 }
2310 }
2311
2312 void DolphinMainWindow::updateViewActions()
2313 {
2314 m_actionHandler->updateViewActions();
2315
2316 QAction* toggleFilterBarAction = actionCollection()->action(QStringLiteral("toggle_filter"));
2317 toggleFilterBarAction->setChecked(m_activeViewContainer->isFilterBarVisible());
2318
2319 updateSplitAction();
2320 }
2321
2322 void DolphinMainWindow::updateGoActions()
2323 {
2324 QAction* goUpAction = actionCollection()->action(KStandardAction::name(KStandardAction::Up));
2325 const QUrl currentUrl = m_activeViewContainer->url();
2326 // I think this is one of the best places to firstly be confronted
2327 // with a file system and its hierarchy. Talking about the root
2328 // directory might seem too much here but it is the question that
2329 // naturally arises in this context.
2330 goUpAction->setWhatsThis(xi18nc("@info:whatsthis", "<para>Go to "
2331 "the folder that contains the currently viewed one.</para>"
2332 "<para>All files and folders are organized in a hierarchical "
2333 "<emphasis>file system</emphasis>. At the top of this hierarchy is "
2334 "a directory that contains all data connected to this computer"
2335 "—the <emphasis>root directory</emphasis>.</para>"));
2336 goUpAction->setEnabled(KIO::upUrl(currentUrl) != currentUrl);
2337 }
2338
2339 void DolphinMainWindow::refreshViews()
2340 {
2341 m_tabWidget->refreshViews();
2342
2343 if (GeneralSettings::modifiedStartupSettings()) {
2344 updateWindowTitle();
2345 }
2346
2347 updateSplitAction();
2348
2349 Q_EMIT settingsChanged();
2350 }
2351
2352 void DolphinMainWindow::clearStatusBar()
2353 {
2354 m_activeViewContainer->statusBar()->resetToDefaultText();
2355 }
2356
2357 void DolphinMainWindow::connectViewSignals(DolphinViewContainer* container)
2358 {
2359 connect(container, &DolphinViewContainer::showFilterBarChanged,
2360 this, &DolphinMainWindow::updateFilterBarAction);
2361 connect(container, &DolphinViewContainer::writeStateChanged,
2362 this, &DolphinMainWindow::slotWriteStateChanged);
2363 connect(container, &DolphinViewContainer::searchModeEnabledChanged,
2364 this, &DolphinMainWindow::updateSearchAction);
2365 connect(container, &DolphinViewContainer::captionChanged,
2366 this, &DolphinMainWindow::updateWindowTitle);
2367 connect(container, &DolphinViewContainer::tabRequested,
2368 this, &DolphinMainWindow::openNewTab);
2369 connect(container, &DolphinViewContainer::activeTabRequested,
2370 this, &DolphinMainWindow::openNewTabAndActivate);
2371
2372 const QAction* toggleSearchAction = actionCollection()->action(QStringLiteral("toggle_search"));
2373 connect(toggleSearchAction, &QAction::triggered, container, &DolphinViewContainer::setSearchModeEnabled);
2374
2375 // Make the toggled state of the selection mode actions visually follow the selection mode state of the view.
2376 auto toggleSelectionModeAction = actionCollection()->action(QStringLiteral("toggle_selection_mode"));
2377 toggleSelectionModeAction->setChecked(m_activeViewContainer->isSelectionModeEnabled());
2378 connect(m_activeViewContainer, &DolphinViewContainer::selectionModeChanged,
2379 toggleSelectionModeAction, &QAction::setChecked);
2380
2381 const DolphinView* view = container->view();
2382 connect(view, &DolphinView::selectionChanged,
2383 this, &DolphinMainWindow::slotSelectionChanged);
2384 connect(view, &DolphinView::requestItemInfo,
2385 this, &DolphinMainWindow::requestItemInfo);
2386 connect(view, &DolphinView::fileItemsChanged,
2387 this, &DolphinMainWindow::fileItemsChanged);
2388 connect(view, &DolphinView::tabRequested,
2389 this, &DolphinMainWindow::openNewTab);
2390 connect(view, &DolphinView::activeTabRequested,
2391 this, &DolphinMainWindow::openNewTabAndActivate);
2392 connect(view, &DolphinView::windowRequested,
2393 this, &DolphinMainWindow::openNewWindow);
2394 connect(view, &DolphinView::requestContextMenu,
2395 this, &DolphinMainWindow::openContextMenu);
2396 connect(view, &DolphinView::directoryLoadingStarted,
2397 this, &DolphinMainWindow::enableStopAction);
2398 connect(view, &DolphinView::directoryLoadingCompleted,
2399 this, &DolphinMainWindow::disableStopAction);
2400 connect(view, &DolphinView::directoryLoadingCompleted,
2401 this, &DolphinMainWindow::slotDirectoryLoadingCompleted);
2402 connect(view, &DolphinView::goBackRequested,
2403 this, &DolphinMainWindow::goBack);
2404 connect(view, &DolphinView::goForwardRequested,
2405 this, &DolphinMainWindow::goForward);
2406 connect(view, &DolphinView::urlActivated,
2407 this, &DolphinMainWindow::handleUrl);
2408 connect(view, &DolphinView::goUpRequested,
2409 this, &DolphinMainWindow::goUp);
2410
2411 connect(container->urlNavigatorInternalWithHistory(), &KUrlNavigator::urlChanged,
2412 this, &DolphinMainWindow::changeUrl);
2413 connect(container->urlNavigatorInternalWithHistory(), &KUrlNavigator::historyChanged,
2414 this, &DolphinMainWindow::updateHistory);
2415
2416 auto navigators = static_cast<DolphinNavigatorsWidgetAction *>
2417 (actionCollection()->action(QStringLiteral("url_navigators")));
2418 const KUrlNavigator *navigator = m_tabWidget->currentTabPage()->primaryViewActive() ?
2419 navigators->primaryUrlNavigator() :
2420 navigators->secondaryUrlNavigator();
2421
2422 QAction *editableLocactionAction = actionCollection()->action(QStringLiteral("editable_location"));
2423 editableLocactionAction->setChecked(navigator->isUrlEditable());
2424 connect(navigator, &KUrlNavigator::editableStateChanged,
2425 this, &DolphinMainWindow::slotEditableStateChanged);
2426 connect(navigator, &KUrlNavigator::tabRequested,
2427 this, &DolphinMainWindow::openNewTab);
2428 connect(navigator, &KUrlNavigator::activeTabRequested,
2429 this, &DolphinMainWindow::openNewTabAndActivate);
2430 connect(navigator, &KUrlNavigator::newWindowRequested,
2431 this, &DolphinMainWindow::openNewWindow);
2432
2433 }
2434
2435 void DolphinMainWindow::updateSplitAction()
2436 {
2437 QAction* splitAction = actionCollection()->action(QStringLiteral("split_view"));
2438 const DolphinTabPage* tabPage = m_tabWidget->currentTabPage();
2439 if (tabPage->splitViewEnabled()) {
2440 if (GeneralSettings::closeActiveSplitView() ? tabPage->primaryViewActive() : !tabPage->primaryViewActive()) {
2441 splitAction->setText(i18nc("@action:intoolbar Close left view", "Close"));
2442 splitAction->setToolTip(i18nc("@info", "Close left view"));
2443 splitAction->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close")));
2444 } else {
2445 splitAction->setText(i18nc("@action:intoolbar Close right view", "Close"));
2446 splitAction->setToolTip(i18nc("@info", "Close right view"));
2447 splitAction->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close")));
2448 }
2449 } else {
2450 splitAction->setText(i18nc("@action:intoolbar Split view", "Split"));
2451 splitAction->setToolTip(i18nc("@info", "Split view"));
2452 splitAction->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2453 }
2454 }
2455
2456 void DolphinMainWindow::updateAllowedToolbarAreas()
2457 {
2458 auto navigators = static_cast<DolphinNavigatorsWidgetAction *>
2459 (actionCollection()->action(QStringLiteral("url_navigators")));
2460 if (toolBar()->actions().contains(navigators)) {
2461 toolBar()->setAllowedAreas(Qt::TopToolBarArea | Qt::BottomToolBarArea);
2462 if (toolBarArea(toolBar()) == Qt::LeftToolBarArea ||
2463 toolBarArea(toolBar()) == Qt::RightToolBarArea) {
2464 addToolBar(Qt::TopToolBarArea, toolBar());
2465 }
2466 } else {
2467 toolBar()->setAllowedAreas(Qt::AllToolBarAreas);
2468 }
2469 }
2470
2471 bool DolphinMainWindow::isKompareInstalled() const
2472 {
2473 static bool initialized = false;
2474 static bool installed = false;
2475 if (!initialized) {
2476 // TODO: maybe replace this approach later by using a menu
2477 // plugin like kdiff3plugin.cpp
2478 installed = !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty();
2479 initialized = true;
2480 }
2481 return installed;
2482 }
2483
2484 void DolphinMainWindow::createPanelAction(const QIcon& icon,
2485 const QKeySequence& shortcut,
2486 QAction* dockAction,
2487 const QString& actionName)
2488 {
2489 QAction* panelAction = actionCollection()->addAction(actionName);
2490 panelAction->setCheckable(true);
2491 panelAction->setChecked(dockAction->isChecked());
2492 panelAction->setText(dockAction->text());
2493 panelAction->setIcon(icon);
2494 dockAction->setIcon(icon);
2495 actionCollection()->setDefaultShortcut(panelAction, shortcut);
2496
2497 connect(panelAction, &QAction::triggered, dockAction, &QAction::trigger);
2498 connect(dockAction, &QAction::toggled, panelAction, &QAction::setChecked);
2499 }
2500
2501 void DolphinMainWindow::setupWhatsThis()
2502 {
2503 // main widgets
2504 menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2505 "<emphasis>Menubar</emphasis>. It provides access to commands and "
2506 "configuration options. Left-click on any of the menus on this "
2507 "bar to see its contents.</para><para>The Menubar can be hidden "
2508 "by unchecking <interface>Settings|Show Menubar</interface>. Then "
2509 "most of its contents become available through a <interface>Menu"
2510 "</interface> button on the <emphasis>Toolbar</emphasis>.</para>"));
2511 toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2512 "<emphasis>Toolbar</emphasis>. It allows quick access to "
2513 "frequently used actions.</para><para>It is highly customizable. "
2514 "All items you see in the <interface>Menu</interface> or "
2515 "in the <interface>Menubar</interface> can be placed on the "
2516 "Toolbar. Just right-click on it and select <interface>Configure "
2517 "Toolbars…</interface> or find this action within the <interface>"
2518 "menu</interface>."
2519 "</para><para>The location of the bar and the style of its "
2520 "buttons can also be changed in the right-click menu. Right-click "
2521 "a button if you want to show or hide its text.</para>"));
2522 m_tabWidget->setWhatsThis(xi18nc("@info:whatsthis main view",
2523 "<para>Here you can see the <emphasis>folders</emphasis> and "
2524 "<emphasis>files</emphasis> that are at the location described in "
2525 "the <interface>Location Bar</interface> above. This area is the "
2526 "central part of this application where you navigate to the files "
2527 "you want to use.</para><para>For an elaborate and general "
2528 "introduction to this application <link "
2529 "url='https://userbase.kde.org/Dolphin/File_Management#Introduction_to_Dolphin'>"
2530 "click here</link>. This will open an introductory article from "
2531 "the <emphasis>KDE UserBase Wiki</emphasis>.</para><para>For brief "
2532 "explanations of all the features of this <emphasis>view</emphasis> "
2533 "<link url='help:/dolphin/dolphin-view.html'>click here</link> "
2534 "instead. This will open a page from the <emphasis>Handbook"
2535 "</emphasis> that covers the basics.</para>"));
2536
2537 // Settings menu
2538 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings))
2539 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window "
2540 "that lists the <emphasis>keyboard shortcuts</emphasis>.<nl/>"
2541 "There you can set up key combinations to trigger an action when "
2542 "they are pressed simultaneously. All commands in this application can "
2543 "be triggered this way.</para>"));
2544 actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars))
2545 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window in which "
2546 "you can change which buttons appear on the <emphasis>Toolbar</emphasis>.</para>"
2547 "<para>All items you see in the <interface>Menu</interface> can also be placed on the Toolbar.</para>"));
2548 actionCollection()->action(KStandardAction::name(KStandardAction::Preferences))
2549 ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can "
2550 "change a multitude of settings for this application. For an explanation "
2551 "of the various settings go to the chapter <emphasis>Configuring Dolphin"
2552 "</emphasis> in <interface>Help|Dolphin Handbook</interface>."));
2553
2554 // Help menu
2555
2556 // i18n: If the external link isn't available in your language it might make
2557 // sense to state the external link's language in brackets to not
2558 // frustrate the user. If there are multiple languages that the user might
2559 // know with a reasonable chance you might want to have 2 external links.
2560 // The same might be true for any external link you translate.
2561 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>"));
2562 // (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 )
2563
2564 actionCollection()->action(KStandardAction::name(KStandardAction::WhatsThis))->setWhatsThis(
2565 xi18nc("@info:whatsthis whatsthis button",
2566 "<para>This is the button that invokes the help feature you are "
2567 "using right now! Click it, then click any component of this "
2568 "application to ask \"What's this?\" about it. The mouse cursor "
2569 "will change appearance if no help is available for a spot.</para>"
2570 "<para>There are two other ways to get help: "
2571 "The <link url='help:/dolphin/index.html'>Dolphin Handbook</link> and "
2572 "the <link url='https://userbase.kde.org/Dolphin/File_Management'>KDE "
2573 "UserBase Wiki</link>.</para><para>The \"What's this?\" help is "
2574 "missing in most other windows so don't get too used to this.</para>"));
2575
2576 actionCollection()->action(KStandardAction::name(KStandardAction::ReportBug))->setWhatsThis(
2577 xi18nc("@info:whatsthis","<para>This opens a "
2578 "window that will guide you through reporting errors or flaws "
2579 "in this application or in other KDE software.</para>"
2580 "<para>High-quality bug reports are much appreciated. To learn "
2581 "how to make your bug report as effective as possible "
2582 "<link url='https://community.kde.org/Get_Involved/Bug_Reporting'>"
2583 "click here</link>.</para>"));
2584
2585 actionCollection()->action(KStandardAction::name(KStandardAction::Donate))->setWhatsThis(
2586 xi18nc("@info:whatsthis", "<para>This opens a "
2587 "<emphasis>web page</emphasis> where you can donate to "
2588 "support the continued work on this application and many "
2589 "other projects by the <emphasis>KDE</emphasis> community.</para>"
2590 "<para>Donating is the easiest and fastest way to efficiently "
2591 "support KDE and its projects. KDE projects are available for "
2592 "free therefore your donation is needed to cover things that "
2593 "require money like servers, contributor meetings, etc.</para>"
2594 "<para><emphasis>KDE e.V.</emphasis> is the non-profit "
2595 "organization behind the KDE community.</para>"));
2596
2597 actionCollection()->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage))->setWhatsThis(
2598 xi18nc("@info:whatsthis",
2599 "With this you can change the language this application uses."
2600 "<nl/>You can even set secondary languages which will be used "
2601 "if texts are not available in your preferred language."));
2602
2603 actionCollection()->action(KStandardAction::name(KStandardAction::AboutApp))->setWhatsThis(
2604 xi18nc("@info:whatsthis","This opens a "
2605 "window that informs you about the version, license, "
2606 "used libraries and maintainers of this application."));
2607
2608 actionCollection()->action(KStandardAction::name(KStandardAction::AboutKDE))->setWhatsThis(
2609 xi18nc("@info:whatsthis","This opens a "
2610 "window with information about <emphasis>KDE</emphasis>. "
2611 "The KDE community are the people behind this free software."
2612 "<nl/>If you like using this application but don't know "
2613 "about KDE or want to see a cute dragon have a look!"));
2614 }
2615
2616 bool DolphinMainWindow::addHamburgerMenuToToolbar()
2617 {
2618 QDomDocument domDocument = KXMLGUIClient::domDocument();
2619 if (domDocument.isNull()) {
2620 return false;
2621 }
2622 QDomNode toolbar = domDocument.elementsByTagName(QStringLiteral("ToolBar")).at(0);
2623 if (toolbar.isNull()) {
2624 return false;
2625 }
2626
2627 QDomElement hamburgerMenuElement = domDocument.createElement(QStringLiteral("Action"));
2628 hamburgerMenuElement.setAttribute(QStringLiteral("name"), QStringLiteral("hamburger_menu"));
2629 toolbar.appendChild(hamburgerMenuElement);
2630
2631 KXMLGUIFactory::saveConfigFile(domDocument, xmlFile());
2632 reloadXML();
2633 createGUI();
2634 return true;
2635 // Make sure to also remove the <KXMLGUIFactory> and <QDomDocument> include
2636 // whenever this method is removed (maybe in the year ~2026).
2637 }
2638
2639 // Set a sane initial window size
2640 QSize DolphinMainWindow::sizeHint() const
2641 {
2642 return KXmlGuiWindow::sizeHint().expandedTo(QSize(760, 550));
2643 }
2644
2645 void DolphinMainWindow::saveNewToolbarConfig()
2646 {
2647 KXmlGuiWindow::saveNewToolbarConfig(); // Applies the new config. This has to be called first
2648 // because the rest of this method decides things
2649 // based on the new config.
2650 auto navigators = static_cast<DolphinNavigatorsWidgetAction *>
2651 (actionCollection()->action(QStringLiteral("url_navigators")));
2652 if (!toolBar()->actions().contains(navigators)) {
2653 m_tabWidget->currentTabPage()->insertNavigatorsWidget(navigators);
2654 }
2655 updateAllowedToolbarAreas();
2656 (static_cast<KHamburgerMenu *>(actionCollection()->action(KStandardAction::name(
2657 KStandardAction::HamburgerMenu))))->hideActionsOf(toolBar());
2658 }
2659
2660 void DolphinMainWindow::focusTerminalPanel()
2661 {
2662 if (m_terminalPanel->isVisible()) {
2663 if (m_terminalPanel->terminalHasFocus()) {
2664 m_activeViewContainer->view()->setFocus(Qt::FocusReason::ShortcutFocusReason);
2665 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2666 } else {
2667 m_terminalPanel->setFocus(Qt::FocusReason::ShortcutFocusReason);
2668 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2669 }
2670 } else {
2671 actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger();
2672 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2673 }
2674 }
2675
2676 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
2677 KIO::FileUndoManager::UiInterface()
2678 {
2679 }
2680
2681 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2682 {
2683 }
2684
2685 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job* job)
2686 {
2687 DolphinMainWindow* mainWin= qobject_cast<DolphinMainWindow *>(parentWidget());
2688 if (mainWin) {
2689 DolphinViewContainer* container = mainWin->activeViewContainer();
2690 container->showMessage(job->errorString(), DolphinViewContainer::Error);
2691 } else {
2692 KIO::FileUndoManager::UiInterface::jobError(job);
2693 }
2694 }
2695
2696 bool DolphinMainWindow::isUrlOpen(const QString &url)
2697 {
2698 return m_tabWidget->isUrlOpen(QUrl::fromUserInput(url));
2699 }
2700
2701 bool DolphinMainWindow::isItemVisibleInAnyView(const QString &urlOfItem)
2702 {
2703 return m_tabWidget->isItemVisibleInAnyView(QUrl::fromUserInput(urlOfItem));
2704 }