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