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