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