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>
6 * SPDX-License-Identifier: GPL-2.0-or-later
9 #include "dolphinmainwindow.h"
11 #include "dolphinmainwindowadaptor.h"
12 #include "config-terminal.h"
14 #include "dolphinbookmarkhandler.h"
15 #include "dolphindockwidget.h"
16 #include "dolphincontextmenu.h"
17 #include "dolphinnavigatorswidgetaction.h"
18 #include "dolphinnewfilemenu.h"
19 #include "dolphinrecenttabsmenu.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/placesitemmodel.h"
26 #include "panels/places/placespanel.h"
27 #include "panels/information/informationpanel.h"
28 #include "panels/terminal/terminalpanel.h"
29 #include "settings/dolphinsettingsdialog.h"
30 #include "statusbar/dolphinstatusbar.h"
31 #include "views/dolphinviewactionhandler.h"
32 #include "views/dolphinremoteencoding.h"
33 #include "views/draganddrophelper.h"
34 #include "views/viewproperties.h"
35 #include "views/dolphinnewfilemenuobserver.h"
36 #include "dolphin_generalsettings.h"
38 #include <KActionCollection>
39 #include <KActionMenu>
40 #include <KAuthorized>
43 #include <KDualAction>
44 #include <KFileItemListProperties>
46 #include <KIO/CommandLauncherJob>
47 #include <KIO/JobUiDelegate>
48 #include <KIO/OpenFileManagerWindowJob>
49 #include <KIO/OpenUrlJob>
50 #include <KJobWidgets>
51 #include <KLocalizedString>
52 #include <KMessageBox>
53 #include <KNS3/KMoreToolsMenuFactory>
54 #include <KProtocolInfo>
55 #include <KProtocolManager>
57 #include <KStandardAction>
58 #include <KStartupInfo>
60 #include <KToggleAction>
62 #include <KToolBarPopupAction>
63 #include <KToolInvocation>
64 #include <KUrlComboBox>
65 #include <KUrlNavigator>
66 #include <KWindowSystem>
68 #include <QApplication>
70 #include <QCloseEvent>
71 #include <QDesktopServices>
76 #include <QPushButton>
78 #include <QStandardPaths>
80 #include <QToolButton>
81 #include <QWhatsThisClickedEvent>
84 // Used for GeneralSettings::version() to determine whether
85 // an updated version of Dolphin is running.
86 const int CurrentDolphinVersion
= 200;
87 // The maximum number of entries in the back/forward popup menu
88 const int MaxNumberOfNavigationentries
= 12;
89 // The maximum number of "Activate Tab" shortcuts
90 const int MaxActivateTabShortcuts
= 9;
93 DolphinMainWindow::DolphinMainWindow() :
94 KXmlGuiWindow(nullptr),
95 m_newFileMenu(nullptr),
98 m_activeViewContainer(nullptr),
99 m_actionHandler(nullptr),
100 m_remoteEncoding(nullptr),
102 m_bookmarkHandler(nullptr),
103 m_controlButton(nullptr),
104 m_updateToolBarTimer(nullptr),
105 m_lastHandleUrlOpenJob(nullptr),
106 m_terminalPanel(nullptr),
107 m_placesPanel(nullptr),
108 m_tearDownFromPlacesRequested(false),
109 m_backAction(nullptr),
110 m_forwardAction(nullptr)
112 Q_INIT_RESOURCE(dolphin
);
114 new MainWindowAdaptor(this);
117 setWindowFlags(Qt::WindowContextHelpButtonHint
);
119 setComponentName(QStringLiteral("dolphin"), QGuiApplication::applicationDisplayName());
120 setObjectName(QStringLiteral("Dolphin#"));
122 connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::errorMessage
,
123 this, &DolphinMainWindow::showErrorMessage
);
125 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
126 undoManager
->setUiInterface(new UndoUiInterface());
128 connect(undoManager
, QOverload
<bool>::of(&KIO::FileUndoManager::undoAvailable
),
129 this, &DolphinMainWindow::slotUndoAvailable
);
130 connect(undoManager
, &KIO::FileUndoManager::undoTextChanged
,
131 this, &DolphinMainWindow::slotUndoTextChanged
);
132 connect(undoManager
, &KIO::FileUndoManager::jobRecordingStarted
,
133 this, &DolphinMainWindow::clearStatusBar
);
134 connect(undoManager
, &KIO::FileUndoManager::jobRecordingFinished
,
135 this, &DolphinMainWindow::showCommand
);
137 GeneralSettings
* generalSettings
= GeneralSettings::self();
138 const bool firstRun
= (generalSettings
->version() < 200);
140 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
143 setAcceptDrops(true);
145 auto *navigatorsWidgetAction
= new DolphinNavigatorsWidgetAction(this);
146 actionCollection()->addAction(QStringLiteral("url_navigators"), navigatorsWidgetAction
);
147 m_tabWidget
= new DolphinTabWidget(navigatorsWidgetAction
, this);
148 m_tabWidget
->setObjectName("tabWidget");
149 connect(m_tabWidget
, &DolphinTabWidget::activeViewChanged
,
150 this, &DolphinMainWindow::activeViewChanged
);
151 connect(m_tabWidget
, &DolphinTabWidget::tabCountChanged
,
152 this, &DolphinMainWindow::tabCountChanged
);
153 connect(m_tabWidget
, &DolphinTabWidget::currentUrlChanged
,
154 this, &DolphinMainWindow::updateWindowTitle
);
155 setCentralWidget(m_tabWidget
);
159 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
160 connect(m_actionHandler
, &DolphinViewActionHandler::actionBeingHandled
, this, &DolphinMainWindow::clearStatusBar
);
161 connect(m_actionHandler
, &DolphinViewActionHandler::createDirectoryTriggered
, this, &DolphinMainWindow::createDirectory
);
163 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
164 connect(this, &DolphinMainWindow::urlChanged
,
165 m_remoteEncoding
, &DolphinRemoteEncoding::slotAboutToOpenUrl
);
169 setupGUI(Keys
| Save
| Create
| ToolBar
);
170 stateChanged(QStringLiteral("new_file"));
172 QClipboard
* clipboard
= QApplication::clipboard();
173 connect(clipboard
, &QClipboard::dataChanged
,
174 this, &DolphinMainWindow::updatePasteAction
);
176 QAction
* showFilterBarAction
= actionCollection()->action(QStringLiteral("show_filter_bar"));
177 showFilterBarAction
->setChecked(generalSettings
->filterBar());
180 menuBar()->setVisible(false);
181 // Assure a proper default size if Dolphin runs the first time
185 const bool showMenu
= !menuBar()->isHidden();
186 QAction
* showMenuBarAction
= actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar
));
187 showMenuBarAction
->setChecked(showMenu
); // workaround for bug #171080
189 createControlButton();
192 updateAllowedToolbarAreas();
194 // enable middle-click on back/forward/up to open in a new tab
195 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
196 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotToolBarActionMiddleClicked
);
197 toolBar()->installEventFilter(middleClickEventFilter
);
201 connect(KSycoca::self(), QOverload
<>::of(&KSycoca::databaseChanged
), this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
203 QTimer::singleShot(0, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
206 DolphinMainWindow::~DolphinMainWindow()
210 QVector
<DolphinViewContainer
*> DolphinMainWindow::viewContainers() const
212 QVector
<DolphinViewContainer
*> viewContainers
;
214 for (int i
= 0; i
< m_tabWidget
->count(); ++i
) {
215 DolphinTabPage
*tabPage
= m_tabWidget
->tabPageAt(i
);
217 viewContainers
<< tabPage
->primaryViewContainer();
218 if (tabPage
->splitViewEnabled()) {
219 viewContainers
<< tabPage
->secondaryViewContainer();
222 return viewContainers
;
225 void DolphinMainWindow::setViewsWithInvalidPathsToHome()
227 const QVector
<DolphinViewContainer
*> theViewContainers
= viewContainers();
228 for (DolphinViewContainer
*viewContainer
: theViewContainers
) {
230 // Only consider local dirs, not remote locations and abstract protocols
231 if (viewContainer
->url().isLocalFile()) {
232 if (!QFileInfo::exists(viewContainer
->url().toLocalFile())) {
233 viewContainer
->setUrl(QUrl::fromLocalFile(QDir::homePath()));
239 void DolphinMainWindow::openDirectories(const QList
<QUrl
>& dirs
, bool splitView
)
241 m_tabWidget
->openDirectories(dirs
, splitView
);
244 void DolphinMainWindow::openDirectories(const QStringList
& dirs
, bool splitView
)
246 openDirectories(QUrl::fromStringList(dirs
), splitView
);
249 void DolphinMainWindow::openFiles(const QList
<QUrl
>& files
, bool splitView
)
251 m_tabWidget
->openFiles(files
, splitView
);
254 bool DolphinMainWindow::isFoldersPanelEnabled() const
256 return actionCollection()->action(QStringLiteral("show_folders_panel"))->isChecked();
259 bool DolphinMainWindow::isInformationPanelEnabled() const
261 return actionCollection()->action(QStringLiteral("show_information_panel"))->isChecked();
264 void DolphinMainWindow::openFiles(const QStringList
& files
, bool splitView
)
266 openFiles(QUrl::fromStringList(files
), splitView
);
269 void DolphinMainWindow::activateWindow()
271 window()->setAttribute(Qt::WA_NativeWindow
, true);
272 KStartupInfo::setNewStartupId(window()->windowHandle(), KStartupInfo::startupId());
273 KWindowSystem::activateWindow(window()->effectiveWinId());
276 void DolphinMainWindow::showCommand(CommandType command
)
278 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
280 case KIO::FileUndoManager::Copy
:
281 statusBar
->setText(i18nc("@info:status", "Successfully copied."));
283 case KIO::FileUndoManager::Move
:
284 statusBar
->setText(i18nc("@info:status", "Successfully moved."));
286 case KIO::FileUndoManager::Link
:
287 statusBar
->setText(i18nc("@info:status", "Successfully linked."));
289 case KIO::FileUndoManager::Trash
:
290 statusBar
->setText(i18nc("@info:status", "Successfully moved to trash."));
292 case KIO::FileUndoManager::Rename
:
293 statusBar
->setText(i18nc("@info:status", "Successfully renamed."));
296 case KIO::FileUndoManager::Mkdir
:
297 statusBar
->setText(i18nc("@info:status", "Created folder."));
305 void DolphinMainWindow::pasteIntoFolder()
307 m_activeViewContainer
->view()->pasteIntoFolder();
310 void DolphinMainWindow::changeUrl(const QUrl
&url
)
312 if (!KProtocolManager::supportsListing(url
)) {
313 // The URL navigator only checks for validity, not
314 // if the URL can be listed. An error message is
315 // shown due to DolphinViewContainer::restoreView().
319 m_activeViewContainer
->setUrl(url
);
320 updateFileAndEditActions();
325 Q_EMIT
urlChanged(url
);
328 void DolphinMainWindow::slotTerminalDirectoryChanged(const QUrl
& url
)
330 if (m_tearDownFromPlacesRequested
&& url
== QUrl::fromLocalFile(QDir::homePath())) {
331 m_placesPanel
->proceedWithTearDown();
332 m_tearDownFromPlacesRequested
= false;
335 m_activeViewContainer
->setAutoGrabFocus(false);
337 m_activeViewContainer
->setAutoGrabFocus(true);
340 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
342 KToggleAction
* editableLocationAction
=
343 static_cast<KToggleAction
*>(actionCollection()->action(QStringLiteral("editable_location")));
344 editableLocationAction
->setChecked(editable
);
347 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
349 updateFileAndEditActions();
351 const int selectedUrlsCount
= m_tabWidget
->currentTabPage()->selectedItemsCount();
353 QAction
* compareFilesAction
= actionCollection()->action(QStringLiteral("compare_files"));
354 if (selectedUrlsCount
== 2) {
355 compareFilesAction
->setEnabled(isKompareInstalled());
357 compareFilesAction
->setEnabled(false);
360 Q_EMIT
selectionChanged(selection
);
363 void DolphinMainWindow::updateHistory()
365 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
366 const int index
= urlNavigator
->historyIndex();
368 QAction
* backAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Back
));
370 backAction
->setToolTip(i18nc("@info", "Go back"));
371 backAction
->setWhatsThis(i18nc("@info:whatsthis go back", "Return to the previously viewed folder."));
372 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
375 QAction
* forwardAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Forward
));
377 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
378 forwardAction
->setWhatsThis(xi18nc("@info:whatsthis go forward",
379 "This undoes a <interface>Go|Back</interface> action."));
380 forwardAction
->setEnabled(index
> 0);
384 void DolphinMainWindow::updateFilterBarAction(bool show
)
386 QAction
* showFilterBarAction
= actionCollection()->action(QStringLiteral("show_filter_bar"));
387 showFilterBarAction
->setChecked(show
);
390 void DolphinMainWindow::openNewMainWindow()
392 Dolphin::openNewWindow({m_activeViewContainer
->url()}, this);
395 void DolphinMainWindow::openNewActivatedTab()
397 m_tabWidget
->openNewActivatedTab();
400 void DolphinMainWindow::addToPlaces()
405 // If nothing is selected, act on the current dir
406 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
407 url
= m_activeViewContainer
->url();
408 name
= m_activeViewContainer
->placesText();
410 const auto dirToAdd
= m_activeViewContainer
->view()->selectedItems().first();
411 url
= dirToAdd
.url();
412 name
= dirToAdd
.name();
415 PlacesItemModel model
;
417 if (m_activeViewContainer
->isSearchModeEnabled()) {
418 icon
= QStringLiteral("folder-saved-search-symbolic");
420 icon
= KIO::iconNameForUrl(url
);
422 model
.createPlacesItem(name
, url
, icon
);
426 void DolphinMainWindow::openNewTab(const QUrl
& url
, DolphinTabWidget::TabPlacement tabPlacement
)
428 m_tabWidget
->openNewTab(url
, QUrl(), tabPlacement
);
431 void DolphinMainWindow::openNewTabAfterCurrentTab(const QUrl
& url
)
433 m_tabWidget
->openNewTab(url
, QUrl(), DolphinTabWidget::AfterCurrentTab
);
436 void DolphinMainWindow::openNewTabAfterLastTab(const QUrl
& url
)
438 m_tabWidget
->openNewTab(url
, QUrl(), DolphinTabWidget::AfterLastTab
);
441 void DolphinMainWindow::openInNewTab()
443 const KFileItemList
& list
= m_activeViewContainer
->view()->selectedItems();
444 bool tabCreated
= false;
446 for (const KFileItem
& item
: list
) {
447 const QUrl
& url
= DolphinView::openItemAsFolderUrl(item
);
448 if (!url
.isEmpty()) {
449 openNewTabAfterCurrentTab(url
);
454 // if no new tab has been created from the selection
455 // open the current directory in a new tab
457 openNewTabAfterCurrentTab(m_activeViewContainer
->url());
461 void DolphinMainWindow::openInNewWindow()
465 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
466 if (list
.isEmpty()) {
467 newWindowUrl
= m_activeViewContainer
->url();
468 } else if (list
.count() == 1) {
469 const KFileItem
& item
= list
.first();
470 newWindowUrl
= DolphinView::openItemAsFolderUrl(item
);
473 if (!newWindowUrl
.isEmpty()) {
474 Dolphin::openNewWindow({newWindowUrl
}, this);
478 void DolphinMainWindow::showTarget()
480 const auto link
= m_activeViewContainer
->view()->selectedItems().at(0);
481 const auto linkLocationDir
= QFileInfo(link
.localPath()).absoluteDir();
482 auto linkDestination
= link
.linkDest();
483 if (QFileInfo(linkDestination
).isRelative()) {
484 linkDestination
= linkLocationDir
.filePath(linkDestination
);
486 if (QFileInfo::exists(linkDestination
)) {
487 KIO::highlightInFileManager({QUrl::fromLocalFile(linkDestination
).adjusted(QUrl::StripTrailingSlash
)});
489 m_activeViewContainer
->showMessage(xi18nc("@info", "Could not access <filename>%1</filename>.", linkDestination
),
490 DolphinViewContainer::Warning
);
494 void DolphinMainWindow::showEvent(QShowEvent
* event
)
496 KXmlGuiWindow::showEvent(event
);
498 if (!event
->spontaneous()) {
499 m_activeViewContainer
->view()->setFocus();
503 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
505 // Find out if Dolphin is closed directly by the user or
506 // by the session manager because the session is closed
507 bool closedByUser
= true;
508 if (qApp
->isSavingSession()) {
509 closedByUser
= false;
512 if (m_tabWidget
->count() > 1
513 && GeneralSettings::confirmClosingMultipleTabs()
514 && !GeneralSettings::rememberOpenedTabs()
516 // Ask the user if he really wants to quit and close all tabs.
517 // Open a confirmation dialog with 3 buttons:
518 // QDialogButtonBox::Yes -> Quit
519 // QDialogButtonBox::No -> Close only the current tab
520 // QDialogButtonBox::Cancel -> do nothing
521 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
522 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
523 dialog
->setModal(true);
524 QDialogButtonBox
* buttons
= new QDialogButtonBox(QDialogButtonBox::Yes
| QDialogButtonBox::No
| QDialogButtonBox::Cancel
);
525 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KGuiItem(i18nc("@action:button 'Quit Dolphin' button", "&Quit %1", QGuiApplication::applicationDisplayName()), QIcon::fromTheme(QStringLiteral("application-exit"))));
526 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("C&lose Current Tab"), QIcon::fromTheme(QStringLiteral("tab-close"))));
527 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
528 buttons
->button(QDialogButtonBox::Yes
)->setDefault(true);
530 bool doNotAskAgainCheckboxResult
= false;
532 const auto result
= KMessageBox::createKMessageBox(dialog
,
534 QMessageBox::Warning
,
535 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
537 i18n("Do not ask again"),
538 &doNotAskAgainCheckboxResult
,
539 KMessageBox::Notify
);
541 if (doNotAskAgainCheckboxResult
) {
542 GeneralSettings::setConfirmClosingMultipleTabs(false);
546 case QDialogButtonBox::Yes
:
549 case QDialogButtonBox::No
:
550 // Close only the current tab
551 m_tabWidget
->closeTab();
559 if (m_terminalPanel
&& m_terminalPanel
->hasProgramRunning() && GeneralSettings::confirmClosingTerminalRunningProgram() && closedByUser
) {
560 // Ask if the user really wants to quit Dolphin with a program that is still running in the Terminal panel
561 // Open a confirmation dialog with 3 buttons:
562 // QDialogButtonBox::Yes -> Quit
563 // QDialogButtonBox::No -> Show Terminal Panel
564 // QDialogButtonBox::Cancel -> do nothing
565 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
566 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
567 dialog
->setModal(true);
568 auto standardButtons
= QDialogButtonBox::Yes
| QDialogButtonBox::Cancel
;
569 if (!m_terminalPanel
->isVisible()) {
570 standardButtons
|= QDialogButtonBox::No
;
572 QDialogButtonBox
*buttons
= new QDialogButtonBox(standardButtons
);
573 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KStandardGuiItem::quit());
574 if (!m_terminalPanel
->isVisible()) {
576 buttons
->button(QDialogButtonBox::No
),
577 KGuiItem(i18n("Show &Terminal Panel"), QIcon::fromTheme(QStringLiteral("dialog-scripts"))));
579 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
581 bool doNotAskAgainCheckboxResult
= false;
583 const auto result
= KMessageBox::createKMessageBox(
586 QMessageBox::Warning
,
587 i18n("The program '%1' is still running in the Terminal panel. Are you sure you want to quit?", m_terminalPanel
->runningProgramName()),
589 i18n("Do not ask again"),
590 &doNotAskAgainCheckboxResult
,
591 KMessageBox::Dangerous
);
593 if (doNotAskAgainCheckboxResult
) {
594 GeneralSettings::setConfirmClosingTerminalRunningProgram(false);
598 case QDialogButtonBox::Yes
:
601 case QDialogButtonBox::No
:
602 actionCollection()->action("show_terminal_panel")->trigger();
603 // Do not quit, ignore quit event
611 if (GeneralSettings::rememberOpenedTabs()) {
612 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
613 KConfig
*config
= KConfigGui::sessionConfig();
614 saveGlobalProperties(config
);
615 savePropertiesInternal(config
, 1);
619 GeneralSettings::setVersion(CurrentDolphinVersion
);
620 GeneralSettings::self()->save();
622 KXmlGuiWindow::closeEvent(event
);
625 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
627 m_tabWidget
->saveProperties(group
);
630 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
632 m_tabWidget
->readProperties(group
);
635 void DolphinMainWindow::updateNewMenu()
637 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
638 m_newFileMenu
->checkUpToDate();
639 m_newFileMenu
->setPopupFiles(QList
<QUrl
>() << activeViewContainer()->url());
642 void DolphinMainWindow::createDirectory()
644 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
645 m_newFileMenu
->setPopupFiles(QList
<QUrl
>() << activeViewContainer()->url());
646 m_newFileMenu
->createDirectory();
649 void DolphinMainWindow::quit()
654 void DolphinMainWindow::showErrorMessage(const QString
& message
)
656 m_activeViewContainer
->showMessage(message
, DolphinViewContainer::Error
);
659 void DolphinMainWindow::slotUndoAvailable(bool available
)
661 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
663 undoAction
->setEnabled(available
);
667 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
669 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
671 undoAction
->setText(text
);
675 void DolphinMainWindow::undo()
678 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
679 KIO::FileUndoManager::self()->undo();
682 void DolphinMainWindow::cut()
684 m_activeViewContainer
->view()->cutSelectedItemsToClipboard();
687 void DolphinMainWindow::copy()
689 m_activeViewContainer
->view()->copySelectedItemsToClipboard();
692 void DolphinMainWindow::paste()
694 m_activeViewContainer
->view()->paste();
697 void DolphinMainWindow::find()
699 m_activeViewContainer
->setSearchModeEnabled(true);
702 void DolphinMainWindow::updateSearchAction()
704 QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
705 toggleSearchAction
->setChecked(m_activeViewContainer
->isSearchModeEnabled());
708 void DolphinMainWindow::updatePasteAction()
710 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
711 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
712 pasteAction
->setEnabled(pasteInfo
.first
);
713 pasteAction
->setText(pasteInfo
.second
);
716 void DolphinMainWindow::slotDirectoryLoadingCompleted()
721 void DolphinMainWindow::slotToolBarActionMiddleClicked(QAction
*action
)
723 if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Back
))) {
725 } else if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Forward
))) {
727 } else if (action
== actionCollection()->action(QStringLiteral("go_up"))) {
729 } else if (action
== actionCollection()->action(QStringLiteral("go_home"))) {
734 void DolphinMainWindow::slotAboutToShowBackPopupMenu()
736 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
738 m_backAction
->menu()->clear();
739 for (int i
= urlNavigator
->historyIndex() + 1; i
< urlNavigator
->historySize() && entries
< MaxNumberOfNavigationentries
; ++i
, ++entries
) {
740 QAction
* action
= new QAction(urlNavigator
->locationUrl(i
).toString(QUrl::PreferLocalFile
), m_backAction
->menu());
742 m_backAction
->menu()->addAction(action
);
746 void DolphinMainWindow::slotGoBack(QAction
* action
)
748 int gotoIndex
= action
->data().value
<int>();
749 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
750 for (int i
= gotoIndex
- urlNavigator
->historyIndex(); i
> 0; --i
) {
755 void DolphinMainWindow::slotBackForwardActionMiddleClicked(QAction
* action
)
758 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
759 openNewTabAfterCurrentTab(urlNavigator
->locationUrl(action
->data().value
<int>()));
763 void DolphinMainWindow::slotAboutToShowForwardPopupMenu()
765 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
767 m_forwardAction
->menu()->clear();
768 for (int i
= urlNavigator
->historyIndex() - 1; i
>= 0 && entries
< MaxNumberOfNavigationentries
; --i
, ++entries
) {
769 QAction
* action
= new QAction(urlNavigator
->locationUrl(i
).toString(QUrl::PreferLocalFile
), m_forwardAction
->menu());
771 m_forwardAction
->menu()->addAction(action
);
775 void DolphinMainWindow::slotGoForward(QAction
* action
)
777 int gotoIndex
= action
->data().value
<int>();
778 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
779 for (int i
= urlNavigator
->historyIndex() - gotoIndex
; i
> 0; --i
) {
784 void DolphinMainWindow::selectAll()
788 // if the URL navigator is editable and focused, select the whole
789 // URL instead of all items of the view
791 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
792 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit();
793 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
794 lineEdit
->hasFocus();
796 lineEdit
->selectAll();
798 m_activeViewContainer
->view()->selectAll();
802 void DolphinMainWindow::invertSelection()
805 m_activeViewContainer
->view()->invertSelection();
808 void DolphinMainWindow::toggleSplitView()
810 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
811 tabPage
->setSplitViewEnabled(!tabPage
->splitViewEnabled());
816 void DolphinMainWindow::toggleSplitStash()
818 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
819 tabPage
->setSplitViewEnabled(false);
820 tabPage
->setSplitViewEnabled(true, QUrl("stash:/"));
823 void DolphinMainWindow::reloadView()
826 m_activeViewContainer
->reload();
827 m_activeViewContainer
->statusBar()->updateSpaceInfo();
830 void DolphinMainWindow::stopLoading()
832 m_activeViewContainer
->view()->stopLoading();
835 void DolphinMainWindow::enableStopAction()
837 actionCollection()->action(QStringLiteral("stop"))->setEnabled(true);
840 void DolphinMainWindow::disableStopAction()
842 actionCollection()->action(QStringLiteral("stop"))->setEnabled(false);
845 void DolphinMainWindow::showFilterBar()
847 m_activeViewContainer
->setFilterBarVisible(true);
850 void DolphinMainWindow::toggleEditLocation()
854 QAction
* action
= actionCollection()->action(QStringLiteral("editable_location"));
855 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
856 urlNavigator
->setUrlEditable(action
->isChecked());
859 void DolphinMainWindow::replaceLocation()
861 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
862 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit();
864 // If the text field currently has focus and everything is selected,
865 // pressing the keyboard shortcut returns the whole thing to breadcrumb mode
866 if (navigator
->isUrlEditable()
867 && lineEdit
->hasFocus()
868 && lineEdit
->selectedText() == lineEdit
->text() ) {
869 navigator
->setUrlEditable(false);
871 navigator
->setUrlEditable(true);
872 navigator
->setFocus();
873 lineEdit
->selectAll();
877 void DolphinMainWindow::togglePanelLockState()
879 const bool newLockState
= !GeneralSettings::lockPanels();
880 const auto childrenObjects
= children();
881 for (QObject
* child
: childrenObjects
) {
882 DolphinDockWidget
* dock
= qobject_cast
<DolphinDockWidget
*>(child
);
884 dock
->setLocked(newLockState
);
888 GeneralSettings::setLockPanels(newLockState
);
891 void DolphinMainWindow::slotTerminalPanelVisibilityChanged()
893 if (m_terminalPanel
->isHiddenInVisibleWindow() && m_activeViewContainer
) {
894 m_activeViewContainer
->view()->setFocus();
898 void DolphinMainWindow::goBack()
900 DolphinUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
901 urlNavigator
->goBack();
903 if (urlNavigator
->locationState().isEmpty()) {
904 // An empty location state indicates a redirection URL,
905 // which must be skipped too
906 urlNavigator
->goBack();
910 void DolphinMainWindow::goForward()
912 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goForward();
915 void DolphinMainWindow::goUp()
917 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goUp();
920 void DolphinMainWindow::goHome()
922 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goHome();
925 void DolphinMainWindow::goBackInNewTab()
927 const KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
928 const int index
= urlNavigator
->historyIndex() + 1;
929 openNewTabAfterCurrentTab(urlNavigator
->locationUrl(index
));
932 void DolphinMainWindow::goForwardInNewTab()
934 const KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
935 const int index
= urlNavigator
->historyIndex() - 1;
936 openNewTabAfterCurrentTab(urlNavigator
->locationUrl(index
));
939 void DolphinMainWindow::goUpInNewTab()
941 const QUrl currentUrl
= activeViewContainer()->urlNavigator()->locationUrl();
942 openNewTabAfterCurrentTab(KIO::upUrl(currentUrl
));
945 void DolphinMainWindow::goHomeInNewTab()
947 openNewTabAfterCurrentTab(Dolphin::homeUrl());
950 void DolphinMainWindow::compareFiles()
952 const KFileItemList items
= m_tabWidget
->currentTabPage()->selectedItems();
953 if (items
.count() != 2) {
954 // The action is disabled in this case, but it could have been triggered
955 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
959 QUrl urlA
= items
.at(0).url();
960 QUrl urlB
= items
.at(1).url();
962 QString
command(QStringLiteral("kompare -c \""));
963 command
.append(urlA
.toDisplayString(QUrl::PreferLocalFile
));
964 command
.append("\" \"");
965 command
.append(urlB
.toDisplayString(QUrl::PreferLocalFile
));
966 command
.append('\"');
968 KIO::CommandLauncherJob
*job
= new KIO::CommandLauncherJob(command
, this);
969 job
->setDesktopName(QStringLiteral("org.kde.kompare"));
973 void DolphinMainWindow::toggleShowMenuBar()
975 const bool visible
= menuBar()->isVisible();
976 menuBar()->setVisible(!visible
);
978 createControlButton();
980 deleteControlButton();
984 QPointer
<QAction
> DolphinMainWindow::preferredSearchTool()
986 m_searchTools
.clear();
987 KMoreToolsMenuFactory("dolphin/search-tools").fillMenuFromGroupingNames(
988 &m_searchTools
, { "files-find" }, m_activeViewContainer
->url()
990 QList
<QAction
*> actions
= m_searchTools
.actions();
991 if (actions
.isEmpty()) {
994 QAction
* action
= actions
.first();
995 if (action
->isSeparator()) {
1001 void DolphinMainWindow::updateOpenPreferredSearchToolAction()
1003 QAction
* openPreferredSearchTool
= actionCollection()->action(QStringLiteral("open_preferred_search_tool"));
1004 if (!openPreferredSearchTool
) {
1007 QPointer
<QAction
> tool
= preferredSearchTool();
1009 openPreferredSearchTool
->setVisible(true);
1010 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open %1", tool
->text()));
1011 openPreferredSearchTool
->setIcon(tool
->icon());
1013 openPreferredSearchTool
->setVisible(false);
1014 // still visible in Shortcuts configuration window
1015 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1016 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1020 void DolphinMainWindow::openPreferredSearchTool()
1022 QPointer
<QAction
> tool
= preferredSearchTool();
1028 void DolphinMainWindow::openTerminal()
1030 const QUrl url
= m_activeViewContainer
->url();
1032 if (url
.isLocalFile()) {
1033 KToolInvocation::invokeTerminal(QString(), url
.toLocalFile());
1037 // Not a local file, with protocol Class ":local", try stat'ing
1038 if (KProtocolInfo::protocolClass(url
.scheme()) == QLatin1String(":local")) {
1039 KIO::StatJob
*job
= KIO::mostLocalUrl(url
);
1040 KJobWidgets::setWindow(job
, this);
1041 connect(job
, &KJob::result
, this, [job
]() {
1043 if (!job
->error()) {
1044 statUrl
= job
->mostLocalUrl();
1047 KToolInvocation::invokeTerminal(QString(), statUrl
.isLocalFile() ? statUrl
.toLocalFile() : QDir::homePath());
1053 // Nothing worked, just use $HOME
1054 KToolInvocation::invokeTerminal(QString(), QDir::homePath());
1057 void DolphinMainWindow::editSettings()
1059 if (!m_settingsDialog
) {
1060 DolphinViewContainer
* container
= activeViewContainer();
1061 container
->view()->writeSettings();
1063 const QUrl url
= container
->url();
1064 DolphinSettingsDialog
* settingsDialog
= new DolphinSettingsDialog(url
, this);
1065 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, this, &DolphinMainWindow::refreshViews
);
1066 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
,
1067 &DolphinUrlNavigatorsController::slotReadSettings
);
1068 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1069 settingsDialog
->show();
1070 m_settingsDialog
= settingsDialog
;
1072 m_settingsDialog
.data()->raise();
1076 void DolphinMainWindow::handleUrl(const QUrl
& url
)
1078 delete m_lastHandleUrlOpenJob
;
1079 m_lastHandleUrlOpenJob
= nullptr;
1081 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1082 activeViewContainer()->setUrl(url
);
1084 m_lastHandleUrlOpenJob
= new KIO::OpenUrlJob(url
);
1085 m_lastHandleUrlOpenJob
->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
1086 m_lastHandleUrlOpenJob
->setRunExecutables(true);
1088 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::mimeTypeFound
, this,
1089 [this, url
](const QString
&mimetype
) {
1090 if (mimetype
== QLatin1String("inode/directory")) {
1091 // If it's a dir, we'll take it from here
1092 m_lastHandleUrlOpenJob
->kill();
1093 m_lastHandleUrlOpenJob
= nullptr;
1094 activeViewContainer()->setUrl(url
);
1098 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::result
, this, [this]() {
1099 m_lastHandleUrlOpenJob
= nullptr;
1102 m_lastHandleUrlOpenJob
->start();
1106 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1108 // trash:/ is writable but we don't want to create new items in it.
1109 // TODO: remove the trash check once https://phabricator.kde.org/T8234 is implemented
1110 newFileMenu()->setEnabled(isFolderWritable
&& m_activeViewContainer
->url().scheme() != QLatin1String("trash"));
1113 void DolphinMainWindow::openContextMenu(const QPoint
& pos
,
1114 const KFileItem
& item
,
1116 const QList
<QAction
*>& customActions
)
1118 QPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, pos
, item
, url
);
1119 contextMenu
.data()->setCustomActions(customActions
);
1120 const DolphinContextMenu::Command command
= contextMenu
.data()->open();
1123 case DolphinContextMenu::OpenParentFolder
:
1124 changeUrl(KIO::upUrl(item
.url()));
1125 m_activeViewContainer
->view()->markUrlsAsSelected({item
.url()});
1126 m_activeViewContainer
->view()->markUrlAsCurrent(item
.url());
1129 case DolphinContextMenu::OpenParentFolderInNewWindow
:
1130 Dolphin::openNewWindow({item
.url()}, this, Dolphin::OpenNewWindowFlag::Select
);
1133 case DolphinContextMenu::OpenParentFolderInNewTab
:
1134 openNewTabAfterLastTab(KIO::upUrl(item
.url()));
1137 case DolphinContextMenu::None
:
1142 // Delete the menu, unless it has been deleted in its own nested event loop already.
1144 contextMenu
->deleteLater();
1148 void DolphinMainWindow::updateControlMenu()
1150 QMenu
* menu
= qobject_cast
<QMenu
*>(sender());
1153 // All actions get cleared by QMenu::clear(). This includes the sub-menus
1154 // because 'menu' is their parent.
1157 KActionCollection
* ac
= actionCollection();
1159 menu
->addMenu(m_newFileMenu
->menu());
1160 addActionToMenu(ac
->action(QStringLiteral("file_new")), menu
);
1161 addActionToMenu(ac
->action(QStringLiteral("new_tab")), menu
);
1162 addActionToMenu(ac
->action(QStringLiteral("closed_tabs")), menu
);
1164 menu
->addSeparator();
1166 // Add "Edit" actions
1167 bool added
= addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Undo
)), menu
) |
1168 addActionToMenu(ac
->action(QString("copy_location")), menu
) |
1169 addActionToMenu(ac
->action(QStringLiteral("copy_to_inactive_split_view")), menu
) |
1170 addActionToMenu(ac
->action(QStringLiteral("move_to_inactive_split_view")), menu
) |
1171 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::SelectAll
)), menu
) |
1172 addActionToMenu(ac
->action(QStringLiteral("invert_selection")), menu
);
1175 menu
->addSeparator();
1178 // Add "View" actions
1179 if (!GeneralSettings::showZoomSlider()) {
1180 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomIn
)), menu
);
1181 addActionToMenu(ac
->action(QStringLiteral("view_zoom_reset")), menu
);
1182 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomOut
)), menu
);
1183 menu
->addSeparator();
1186 added
= addActionToMenu(ac
->action(QStringLiteral("show_preview")), menu
) |
1187 addActionToMenu(ac
->action(QStringLiteral("show_in_groups")), menu
) |
1188 addActionToMenu(ac
->action(QStringLiteral("show_hidden_files")), menu
) |
1189 addActionToMenu(ac
->action(QStringLiteral("additional_info")), menu
) |
1190 addActionToMenu(ac
->action(QStringLiteral("view_properties")), menu
);
1193 menu
->addSeparator();
1196 // Add a curated assortment of items from the "Tools" menu
1197 addActionToMenu(ac
->action(QStringLiteral("show_filter_bar")), menu
);
1198 addActionToMenu(ac
->action(QStringLiteral("open_preferred_search_tool")), menu
);
1199 addActionToMenu(ac
->action(QStringLiteral("open_terminal")), menu
);
1201 menu
->addSeparator();
1203 // Add "Show Panels" menu
1204 addActionToMenu(ac
->action(QStringLiteral("panels")), menu
);
1206 // Add "Settings" menu entries
1207 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)), menu
);
1208 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)), menu
);
1209 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Preferences
)), menu
);
1210 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)), menu
);
1213 auto helpMenu
= m_helpMenu
->menu();
1214 helpMenu
->setIcon(QIcon::fromTheme(QStringLiteral("system-help")));
1215 menu
->addMenu(helpMenu
);
1218 void DolphinMainWindow::updateToolBar()
1220 if (!menuBar()->isVisible()) {
1221 createControlButton();
1225 void DolphinMainWindow::slotControlButtonDeleted()
1227 m_controlButton
= nullptr;
1228 m_updateToolBarTimer
->start();
1231 void DolphinMainWindow::slotPlaceActivated(const QUrl
& url
)
1233 DolphinViewContainer
* view
= activeViewContainer();
1235 if (view
->url() == url
) {
1236 // We can end up here if the user clicked a device in the Places Panel
1237 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1244 void DolphinMainWindow::closedTabsCountChanged(unsigned int count
)
1246 actionCollection()->action(QStringLiteral("undo_close_tab"))->setEnabled(count
> 0);
1249 void DolphinMainWindow::activeViewChanged(DolphinViewContainer
* viewContainer
)
1251 DolphinViewContainer
* oldViewContainer
= m_activeViewContainer
;
1252 Q_ASSERT(viewContainer
);
1254 m_activeViewContainer
= viewContainer
;
1256 if (oldViewContainer
) {
1257 const QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
1258 toggleSearchAction
->disconnect(oldViewContainer
);
1260 // Disconnect all signals between the old view container (container,
1261 // view and url navigator) and main window.
1262 oldViewContainer
->disconnect(this);
1263 oldViewContainer
->view()->disconnect(this);
1264 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
1265 (actionCollection()->action(QStringLiteral("url_navigators")));
1266 navigators
->primaryUrlNavigator()->disconnect(this);
1267 if (auto secondaryUrlNavigator
= navigators
->secondaryUrlNavigator()) {
1268 secondaryUrlNavigator
->disconnect(this);
1271 // except the requestItemInfo so that on hover the information panel can still be updated
1272 connect(oldViewContainer
->view(), &DolphinView::requestItemInfo
,
1273 this, &DolphinMainWindow::requestItemInfo
);
1276 connectViewSignals(viewContainer
);
1278 m_actionHandler
->setCurrentView(viewContainer
->view());
1281 updateFileAndEditActions();
1282 updatePasteAction();
1283 updateViewActions();
1285 updateSearchAction();
1287 const QUrl url
= viewContainer
->url();
1288 Q_EMIT
urlChanged(url
);
1291 void DolphinMainWindow::tabCountChanged(int count
)
1293 const bool enableTabActions
= (count
> 1);
1294 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1295 actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i
))->setEnabled(enableTabActions
);
1297 actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions
);
1298 actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions
);
1299 actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions
);
1302 void DolphinMainWindow::updateWindowTitle()
1304 const QString newTitle
= m_activeViewContainer
->captionWindowTitle();
1305 if (windowTitle() != newTitle
) {
1306 setWindowTitle(newTitle
);
1310 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString
& mountPath
)
1312 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1313 setViewsToHomeIfMountPathOpen(mountPath
);
1316 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectory().startsWith(mountPath
)) {
1317 m_tearDownFromPlacesRequested
= true;
1318 m_terminalPanel
->goHome();
1319 // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
1321 m_placesPanel
->proceedWithTearDown();
1325 void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString
& mountPath
)
1327 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1328 setViewsToHomeIfMountPathOpen(mountPath
);
1331 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectory().startsWith(mountPath
)) {
1332 m_tearDownFromPlacesRequested
= false;
1333 m_terminalPanel
->goHome();
1337 void DolphinMainWindow::setViewsToHomeIfMountPathOpen(const QString
& mountPath
)
1339 const QVector
<DolphinViewContainer
*> theViewContainers
= viewContainers();
1340 for (DolphinViewContainer
*viewContainer
: theViewContainers
) {
1341 if (viewContainer
&& viewContainer
->url().toLocalFile().startsWith(mountPath
)) {
1342 viewContainer
->setUrl(QUrl::fromLocalFile(QDir::homePath()));
1345 disconnect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, nullptr, nullptr);
1348 void DolphinMainWindow::setupActions()
1350 // setup 'File' menu
1351 m_newFileMenu
= new DolphinNewFileMenu(actionCollection(), this);
1352 QMenu
* menu
= m_newFileMenu
->menu();
1353 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1354 menu
->setIcon(QIcon::fromTheme(QStringLiteral("document-new")));
1355 m_newFileMenu
->setDelayed(false);
1356 connect(menu
, &QMenu::aboutToShow
,
1357 this, &DolphinMainWindow::updateNewMenu
);
1359 QAction
* newWindow
= KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow
, actionCollection());
1360 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1361 newWindow
->setToolTip(i18nc("@info", "Open a new Dolphin window"));
1362 newWindow
->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1363 "window just like this one with the current location and view."
1364 "<nl/>You can drag and drop items between windows."));
1365 newWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1367 QAction
* newTab
= actionCollection()->addAction(QStringLiteral("new_tab"));
1368 newTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1369 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1370 newTab
->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1371 "<emphasis>Tab</emphasis> with the current location and view.<nl/>"
1372 "A tab is an additional view within this window. "
1373 "You can drag and drop items between tabs."));
1374 actionCollection()->setDefaultShortcuts(newTab
, {Qt::CTRL
+ Qt::Key_T
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_N
});
1375 connect(newTab
, &QAction::triggered
, this, &DolphinMainWindow::openNewActivatedTab
);
1377 QAction
* addToPlaces
= actionCollection()->addAction(QStringLiteral("add_to_places"));
1378 addToPlaces
->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new")));
1379 addToPlaces
->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places"));
1380 addToPlaces
->setWhatsThis(xi18nc("@info:whatsthis", "This adds the selected folder "
1381 "to the Places panel."));
1382 connect(addToPlaces
, &QAction::triggered
, this, &DolphinMainWindow::addToPlaces
);
1384 QAction
* closeTab
= KStandardAction::close(m_tabWidget
, QOverload
<>::of(&DolphinTabWidget::closeTab
), actionCollection());
1385 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1386 closeTab
->setWhatsThis(i18nc("@info:whatsthis", "This closes the "
1387 "currently viewed tab. If no more tabs are left this window "
1388 "will close instead."));
1390 QAction
* quitAction
= KStandardAction::quit(this, &DolphinMainWindow::quit
, actionCollection());
1391 quitAction
->setWhatsThis(i18nc("@info:whatsthis quit", "This closes this window."));
1393 // setup 'Edit' menu
1394 KStandardAction::undo(this,
1395 &DolphinMainWindow::undo
,
1396 actionCollection());
1398 // i18n: This will be the last paragraph for the whatsthis for all three:
1399 // Cut, Copy and Paste
1400 const QString cutCopyPastePara
= xi18nc("@info:whatsthis", "<para><emphasis>Cut, "
1401 "Copy</emphasis> and <emphasis>Paste</emphasis> work between many "
1402 "applications and are among the most used commands. That's why their "
1403 "<emphasis>keyboard shortcuts</emphasis> are prominently placed right "
1404 "next to each other on the keyboard: <shortcut>Ctrl+X</shortcut>, "
1405 "<shortcut>Ctrl+C</shortcut> and <shortcut>Ctrl+V</shortcut>.</para>");
1406 QAction
* cutAction
= KStandardAction::cut(this, &DolphinMainWindow::cut
, actionCollection());
1407 cutAction
->setWhatsThis(xi18nc("@info:whatsthis cut", "This copies the items "
1408 "in your current selection to the <emphasis>clipboard</emphasis>.<nl/>"
1409 "Use the <emphasis>Paste</emphasis> action afterwards to copy them from "
1410 "the clipboard to a new location. The items will be removed from their "
1411 "initial location.") + cutCopyPastePara
);
1412 QAction
* copyAction
= KStandardAction::copy(this, &DolphinMainWindow::copy
, actionCollection());
1413 copyAction
->setWhatsThis(xi18nc("@info:whatsthis copy", "This copies the "
1414 "items in your current selection to the <emphasis>clipboard</emphasis>."
1415 "<nl/>Use the <emphasis>Paste</emphasis> action afterwards to copy them "
1416 "from the clipboard to a new location.") + cutCopyPastePara
);
1417 QAction
* paste
= KStandardAction::paste(this, &DolphinMainWindow::paste
, actionCollection());
1418 // The text of the paste-action is modified dynamically by Dolphin
1419 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1420 // due to the long text, the text "Paste" is used:
1421 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1422 paste
->setWhatsThis(xi18nc("@info:whatsthis paste", "This copies the items from "
1423 "your <emphasis>clipboard</emphasis> to the currently viewed folder.<nl/>"
1424 "If the items were added to the clipboard by the <emphasis>Cut</emphasis> "
1425 "action they are removed from their old location.") + cutCopyPastePara
);
1427 QAction
* copyToOtherViewAction
= actionCollection()->addAction(QStringLiteral("copy_to_inactive_split_view"));
1428 copyToOtherViewAction
->setText(i18nc("@action:inmenu", "Copy to Inactive Split View"));
1429 copyToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Copy", "This copies the selected items from "
1430 "the <emphasis>active</emphasis> view to the inactive split view."));
1431 copyToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
1432 copyToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Copy to Inactive Split View"));
1433 actionCollection()->setDefaultShortcut(copyToOtherViewAction
, Qt::SHIFT
+ Qt::Key_F5
);
1434 connect(copyToOtherViewAction
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::copyToInactiveSplitView
);
1436 QAction
* moveToOtherViewAction
= actionCollection()->addAction(QStringLiteral("move_to_inactive_split_view"));
1437 moveToOtherViewAction
->setText(i18nc("@action:inmenu", "Move to Inactive Split View"));
1438 moveToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Move", "This moves the selected items from "
1439 "the <emphasis>active</emphasis> view to the inactive split view."));
1440 moveToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-cut")));
1441 moveToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Move to Inactive Split View"));
1442 actionCollection()->setDefaultShortcut(moveToOtherViewAction
, Qt::SHIFT
+ Qt::Key_F6
);
1443 connect(moveToOtherViewAction
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::moveToInactiveSplitView
);
1445 QAction
*searchAction
= KStandardAction::find(this, &DolphinMainWindow::find
, actionCollection());
1446 searchAction
->setText(i18n("Search..."));
1447 searchAction
->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
1448 searchAction
->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This helps you "
1449 "find files and folders by opening a <emphasis>find bar</emphasis>. "
1450 "There you can enter search terms and specify settings to find the "
1451 "objects you are looking for.</para><para>Use this help again on "
1452 "the find bar so we can have a look at it while the settings are "
1453 "explained.</para>"));
1455 // toggle_search acts as a copy of the main searchAction to be used mainly
1456 // in the toolbar, with no default shortcut attached, to avoid messing with
1457 // existing workflows (search bar always open and Ctrl-F to focus)
1458 QAction
*toggleSearchAction
= actionCollection()->addAction(QStringLiteral("toggle_search"));
1459 toggleSearchAction
->setText(i18nc("@action:inmenu", "Toggle Search Bar"));
1460 toggleSearchAction
->setIconText(i18nc("@action:intoolbar", "Search"));
1461 toggleSearchAction
->setIcon(searchAction
->icon());
1462 toggleSearchAction
->setToolTip(searchAction
->toolTip());
1463 toggleSearchAction
->setWhatsThis(searchAction
->whatsThis());
1464 toggleSearchAction
->setCheckable(true);
1466 QAction
* selectAllAction
= KStandardAction::selectAll(this, &DolphinMainWindow::selectAll
, actionCollection());
1467 selectAllAction
->setWhatsThis(xi18nc("@info:whatsthis", "This selects all "
1468 "files and folders in the current location."));
1470 QAction
* invertSelection
= actionCollection()->addAction(QStringLiteral("invert_selection"));
1471 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1472 invertSelection
->setWhatsThis(xi18nc("@info:whatsthis invert", "This selects all "
1473 "objects that you have currently <emphasis>not</emphasis> selected instead."));
1474 invertSelection
->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert")));
1475 actionCollection()->setDefaultShortcut(invertSelection
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_A
);
1476 connect(invertSelection
, &QAction::triggered
, this, &DolphinMainWindow::invertSelection
);
1478 // setup 'View' menu
1479 // (note that most of it is set up in DolphinViewActionHandler)
1481 QAction
* split
= actionCollection()->addAction(QStringLiteral("split_view"));
1482 split
->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This splits "
1483 "the folder view below into two autonomous views.</para><para>This "
1484 "way you can see two locations at once and move items between them "
1485 "quickly.</para>Click this again afterwards to recombine the views."));
1486 actionCollection()->setDefaultShortcut(split
, Qt::Key_F3
);
1487 connect(split
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitView
);
1489 QAction
* stashSplit
= actionCollection()->addAction(QStringLiteral("split_stash"));
1490 actionCollection()->setDefaultShortcut(stashSplit
, Qt::CTRL
+ Qt::Key_S
);
1491 stashSplit
->setText(i18nc("@action:intoolbar Stash", "Stash"));
1492 stashSplit
->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
1493 stashSplit
->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
1494 stashSplit
->setCheckable(false);
1495 stashSplit
->setVisible(KProtocolInfo::isKnownProtocol("stash"));
1496 connect(stashSplit
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitStash
);
1498 KStandardAction::redisplay(this, &DolphinMainWindow::reloadView
, actionCollection());
1500 QAction
* stop
= actionCollection()->addAction(QStringLiteral("stop"));
1501 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1502 stop
->setToolTip(i18nc("@info", "Stop loading"));
1503 stop
->setWhatsThis(i18nc("@info", "This stops the loading of the contents of the current folder."));
1504 stop
->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
1505 connect(stop
, &QAction::triggered
, this, &DolphinMainWindow::stopLoading
);
1507 KToggleAction
* editableLocation
= actionCollection()->add
<KToggleAction
>(QStringLiteral("editable_location"));
1508 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1509 editableLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1510 "This toggles the <emphasis>Location Bar</emphasis> to be "
1511 "editable so you can directly enter a location you want to go to.<nl/>"
1512 "You can also switch to editing by clicking to the right of the "
1513 "location and switch back by confirming the edited location."));
1514 actionCollection()->setDefaultShortcut(editableLocation
, Qt::Key_F6
);
1515 connect(editableLocation
, &KToggleAction::triggered
, this, &DolphinMainWindow::toggleEditLocation
);
1517 QAction
* replaceLocation
= actionCollection()->addAction(QStringLiteral("replace_location"));
1518 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1519 // i18n: "enter" is used both in the meaning of "writing" and "going to" a new location here.
1520 // Both meanings are useful but not necessary to understand the use of "Replace Location".
1521 // So you might want to be more verbose in your language to convey the meaning but it's up to you.
1522 replaceLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1523 "This switches to editing the location and selects it "
1524 "so you can quickly enter a different location."));
1525 actionCollection()->setDefaultShortcut(replaceLocation
, Qt::CTRL
+ Qt::Key_L
);
1526 connect(replaceLocation
, &QAction::triggered
, this, &DolphinMainWindow::replaceLocation
);
1530 QScopedPointer
<QAction
> backAction(KStandardAction::back(nullptr, nullptr, nullptr));
1531 m_backAction
= new KToolBarPopupAction(backAction
->icon(), backAction
->text(), actionCollection());
1532 m_backAction
->setObjectName(backAction
->objectName());
1533 m_backAction
->setShortcuts(backAction
->shortcuts());
1535 m_backAction
->setDelayed(true);
1536 m_backAction
->setStickyMenu(false);
1537 connect(m_backAction
, &QAction::triggered
, this, &DolphinMainWindow::goBack
);
1538 connect(m_backAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowBackPopupMenu
);
1539 connect(m_backAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoBack
);
1540 actionCollection()->addAction(m_backAction
->objectName(), m_backAction
);
1542 auto backShortcuts
= m_backAction
->shortcuts();
1543 backShortcuts
.append(QKeySequence(Qt::Key_Backspace
));
1544 actionCollection()->setDefaultShortcuts(m_backAction
, backShortcuts
);
1546 DolphinRecentTabsMenu
* recentTabsMenu
= new DolphinRecentTabsMenu(this);
1547 actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu
);
1548 connect(m_tabWidget
, &DolphinTabWidget::rememberClosedTab
,
1549 recentTabsMenu
, &DolphinRecentTabsMenu::rememberClosedTab
);
1550 connect(recentTabsMenu
, &DolphinRecentTabsMenu::restoreClosedTab
,
1551 m_tabWidget
, &DolphinTabWidget::restoreClosedTab
);
1552 connect(recentTabsMenu
, &DolphinRecentTabsMenu::closedTabsCountChanged
,
1553 this, &DolphinMainWindow::closedTabsCountChanged
);
1555 QAction
* undoCloseTab
= actionCollection()->addAction(QStringLiteral("undo_close_tab"));
1556 undoCloseTab
->setText(i18nc("@action:inmenu File", "Undo close tab"));
1557 undoCloseTab
->setWhatsThis(i18nc("@info:whatsthis undo close tab",
1558 "This returns you to the previously closed tab."));
1559 actionCollection()->setDefaultShortcut(undoCloseTab
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_T
);
1560 undoCloseTab
->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
1561 undoCloseTab
->setEnabled(false);
1562 connect(undoCloseTab
, &QAction::triggered
, recentTabsMenu
, &DolphinRecentTabsMenu::undoCloseTab
);
1564 auto undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
1565 undoAction
->setWhatsThis(xi18nc("@info:whatsthis", "This undoes "
1566 "the last change you made to files or folders.<nl/>"
1567 "Such changes include <interface>creating, renaming</interface> "
1568 "and <interface>moving</interface> them to a different location "
1569 "or to the <filename>Trash</filename>. <nl/>Changes that can't "
1570 "be undone will ask for your confirmation."));
1571 undoAction
->setEnabled(false); // undo should be disabled by default
1574 QScopedPointer
<QAction
> forwardAction(KStandardAction::forward(nullptr, nullptr, nullptr));
1575 m_forwardAction
= new KToolBarPopupAction(forwardAction
->icon(), forwardAction
->text(), actionCollection());
1576 m_forwardAction
->setObjectName(forwardAction
->objectName());
1577 m_forwardAction
->setShortcuts(forwardAction
->shortcuts());
1579 m_forwardAction
->setDelayed(true);
1580 m_forwardAction
->setStickyMenu(false);
1581 connect(m_forwardAction
, &QAction::triggered
, this, &DolphinMainWindow::goForward
);
1582 connect(m_forwardAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowForwardPopupMenu
);
1583 connect(m_forwardAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoForward
);
1584 actionCollection()->addAction(m_forwardAction
->objectName(), m_forwardAction
);
1585 actionCollection()->setDefaultShortcuts(m_forwardAction
, m_forwardAction
->shortcuts());
1587 // enable middle-click to open in a new tab
1588 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
1589 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotBackForwardActionMiddleClicked
);
1590 m_backAction
->menu()->installEventFilter(middleClickEventFilter
);
1591 m_forwardAction
->menu()->installEventFilter(middleClickEventFilter
);
1592 KStandardAction::up(this, &DolphinMainWindow::goUp
, actionCollection());
1593 QAction
* homeAction
= KStandardAction::home(this, &DolphinMainWindow::goHome
, actionCollection());
1594 homeAction
->setWhatsThis(xi18nc("@info:whatsthis", "Go to your "
1595 "<filename>Home</filename> folder.<nl/>Every user account "
1596 "has their own <filename>Home</filename> that contains their data "
1597 "including folders that contain personal application data."));
1599 // setup 'Tools' menu
1600 QAction
* showFilterBar
= actionCollection()->addAction(QStringLiteral("show_filter_bar"));
1601 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1602 showFilterBar
->setWhatsThis(xi18nc("@info:whatsthis", "This opens the "
1603 "<emphasis>Filter Bar</emphasis> at the bottom of the window.<nl/> "
1604 "There you can enter a text to filter the files and folders currently displayed. "
1605 "Only those that contain the text in their name will be kept in view."));
1606 showFilterBar
->setIcon(QIcon::fromTheme(QStringLiteral("view-filter")));
1607 actionCollection()->setDefaultShortcuts(showFilterBar
, {Qt::CTRL
+ Qt::Key_I
, Qt::Key_Slash
});
1608 connect(showFilterBar
, &QAction::triggered
, this, &DolphinMainWindow::showFilterBar
);
1610 QAction
* compareFiles
= actionCollection()->addAction(QStringLiteral("compare_files"));
1611 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1612 compareFiles
->setIcon(QIcon::fromTheme(QStringLiteral("kompare")));
1613 compareFiles
->setEnabled(false);
1614 connect(compareFiles
, &QAction::triggered
, this, &DolphinMainWindow::compareFiles
);
1616 QAction
* openPreferredSearchTool
= actionCollection()->addAction(QStringLiteral("open_preferred_search_tool"));
1617 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1618 openPreferredSearchTool
->setWhatsThis(xi18nc("@info:whatsthis",
1619 "<para>This opens a preferred search tool for the viewed location.</para>"
1620 "<para>Use <emphasis>More Search Tools</emphasis> menu to configure it.</para>"));
1621 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1622 actionCollection()->setDefaultShortcut(openPreferredSearchTool
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_F
);
1623 connect(openPreferredSearchTool
, &QAction::triggered
, this, &DolphinMainWindow::openPreferredSearchTool
);
1625 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1626 QAction
* openTerminal
= actionCollection()->addAction(QStringLiteral("open_terminal"));
1627 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1628 openTerminal
->setWhatsThis(xi18nc("@info:whatsthis",
1629 "<para>This opens a <emphasis>terminal</emphasis> application for the viewed location.</para>"
1630 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1631 openTerminal
->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
1632 actionCollection()->setDefaultShortcut(openTerminal
, Qt::SHIFT
+ Qt::Key_F4
);
1633 connect(openTerminal
, &QAction::triggered
, this, &DolphinMainWindow::openTerminal
);
1635 #ifdef HAVE_TERMINAL
1636 QAction
* focusTerminalPanel
= actionCollection()->addAction(QStringLiteral("focus_terminal_panel"));
1637 focusTerminalPanel
->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
1638 focusTerminalPanel
->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
1639 actionCollection()->setDefaultShortcut(focusTerminalPanel
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_F4
);
1640 connect(focusTerminalPanel
, &QAction::triggered
, this, &DolphinMainWindow::focusTerminalPanel
);
1644 // setup 'Bookmarks' menu
1645 KActionMenu
*bookmarkMenu
= new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this);
1646 bookmarkMenu
->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks")));
1647 // Make the toolbar button version work properly on click
1648 bookmarkMenu
->setDelayed(false);
1649 m_bookmarkHandler
= new DolphinBookmarkHandler(this, actionCollection(), bookmarkMenu
->menu(), this);
1650 actionCollection()->addAction(QStringLiteral("bookmarks"), bookmarkMenu
);
1652 // setup 'Settings' menu
1653 KToggleAction
* showMenuBar
= KStandardAction::showMenubar(nullptr, nullptr, actionCollection());
1654 showMenuBar
->setWhatsThis(xi18nc("@info:whatsthis",
1655 "This switches between having a <emphasis>Menubar</emphasis> "
1656 "and having a <interface>Control</interface> button. Both "
1657 "contain mostly the same commands and configuration options."));
1658 connect(showMenuBar
, &KToggleAction::triggered
, // Fixes #286822
1659 this, &DolphinMainWindow::toggleShowMenuBar
, Qt::QueuedConnection
);
1660 KStandardAction::preferences(this, &DolphinMainWindow::editSettings
, actionCollection());
1662 // setup 'Help' menu for the m_controlButton. The other one is set up in the base class.
1663 m_helpMenu
= new KHelpMenu(nullptr);
1664 m_helpMenu
->menu()->installEventFilter(this);
1665 // remove duplicate shortcuts
1666 m_helpMenu
->action(KHelpMenu::menuHelpContents
)->setShortcut(QKeySequence());
1667 m_helpMenu
->action(KHelpMenu::menuWhatsThis
)->setShortcut(QKeySequence());
1669 // not in menu actions
1670 QList
<QKeySequence
> nextTabKeys
= KStandardShortcut::tabNext();
1671 nextTabKeys
.append(QKeySequence(Qt::CTRL
+ Qt::Key_Tab
));
1673 QList
<QKeySequence
> prevTabKeys
= KStandardShortcut::tabPrev();
1674 prevTabKeys
.append(QKeySequence(Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_Tab
));
1676 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1677 QAction
* activateTab
= actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i
));
1678 activateTab
->setText(i18nc("@action:inmenu", "Activate Tab %1", i
+ 1));
1679 activateTab
->setEnabled(false);
1680 connect(activateTab
, &QAction::triggered
, this, [this, i
]() { m_tabWidget
->activateTab(i
); });
1682 // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts
1684 actionCollection()->setDefaultShortcut(activateTab
, QStringLiteral("Alt+%1").arg(i
+ 1));
1688 QAction
* activateLastTab
= actionCollection()->addAction(QStringLiteral("activate_last_tab"));
1689 activateLastTab
->setText(i18nc("@action:inmenu", "Activate Last Tab"));
1690 activateLastTab
->setEnabled(false);
1691 connect(activateLastTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateLastTab
);
1692 actionCollection()->setDefaultShortcut(activateLastTab
, Qt::ALT
+ Qt::Key_0
);
1694 QAction
* activateNextTab
= actionCollection()->addAction(QStringLiteral("activate_next_tab"));
1695 activateNextTab
->setIconText(i18nc("@action:inmenu", "Next Tab"));
1696 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1697 activateNextTab
->setEnabled(false);
1698 connect(activateNextTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateNextTab
);
1699 actionCollection()->setDefaultShortcuts(activateNextTab
, nextTabKeys
);
1701 QAction
* activatePrevTab
= actionCollection()->addAction(QStringLiteral("activate_prev_tab"));
1702 activatePrevTab
->setIconText(i18nc("@action:inmenu", "Previous Tab"));
1703 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1704 activatePrevTab
->setEnabled(false);
1705 connect(activatePrevTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activatePrevTab
);
1706 actionCollection()->setDefaultShortcuts(activatePrevTab
, prevTabKeys
);
1709 QAction
* showTarget
= actionCollection()->addAction(QStringLiteral("show_target"));
1710 showTarget
->setText(i18nc("@action:inmenu", "Show Target"));
1711 showTarget
->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
1712 showTarget
->setEnabled(false);
1713 connect(showTarget
, &QAction::triggered
, this, &DolphinMainWindow::showTarget
);
1715 QAction
* openInNewTab
= actionCollection()->addAction(QStringLiteral("open_in_new_tab"));
1716 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1717 openInNewTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1718 connect(openInNewTab
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
1720 QAction
* openInNewTabs
= actionCollection()->addAction(QStringLiteral("open_in_new_tabs"));
1721 openInNewTabs
->setText(i18nc("@action:inmenu", "Open in New Tabs"));
1722 openInNewTabs
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1723 connect(openInNewTabs
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
1725 QAction
* openInNewWindow
= actionCollection()->addAction(QStringLiteral("open_in_new_window"));
1726 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1727 openInNewWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1728 connect(openInNewWindow
, &QAction::triggered
, this, &DolphinMainWindow::openInNewWindow
);
1731 void DolphinMainWindow::setupDockWidgets()
1733 const bool lock
= GeneralSettings::lockPanels();
1735 KDualAction
* lockLayoutAction
= actionCollection()->add
<KDualAction
>(QStringLiteral("lock_panels"));
1736 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1737 lockLayoutAction
->setActiveIcon(QIcon::fromTheme(QStringLiteral("object-unlocked")));
1738 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1739 lockLayoutAction
->setInactiveIcon(QIcon::fromTheme(QStringLiteral("object-locked")));
1740 lockLayoutAction
->setWhatsThis(xi18nc("@info:whatsthis", "This "
1741 "switches between having panels <emphasis>locked</emphasis> or "
1742 "<emphasis>unlocked</emphasis>.<nl/>Unlocked panels can be "
1743 "dragged to the other side of the window and have a close "
1744 "button.<nl/>Locked panels are embedded more cleanly."));
1745 lockLayoutAction
->setActive(lock
);
1746 connect(lockLayoutAction
, &KDualAction::triggered
, this, &DolphinMainWindow::togglePanelLockState
);
1748 // Setup "Information"
1749 DolphinDockWidget
* infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
1750 infoDock
->setLocked(lock
);
1751 infoDock
->setObjectName(QStringLiteral("infoDock"));
1752 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1755 InformationPanel
* infoPanel
= new InformationPanel(infoDock
);
1756 infoPanel
->setCustomContextMenuActions({lockLayoutAction
});
1757 connect(infoPanel
, &InformationPanel::urlActivated
, this, &DolphinMainWindow::handleUrl
);
1758 infoDock
->setWidget(infoPanel
);
1760 QAction
* infoAction
= infoDock
->toggleViewAction();
1761 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-information")), Qt::Key_F11
, infoAction
, QStringLiteral("show_information_panel"));
1763 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1764 connect(this, &DolphinMainWindow::urlChanged
,
1765 infoPanel
, &InformationPanel::setUrl
);
1766 connect(this, &DolphinMainWindow::selectionChanged
,
1767 infoPanel
, &InformationPanel::setSelection
);
1768 connect(this, &DolphinMainWindow::requestItemInfo
,
1769 infoPanel
, &InformationPanel::requestDelayedItemInfo
);
1772 // i18n: This is the last paragraph for the "What's This"-texts of all four panels.
1773 const QString panelWhatsThis
= xi18nc("@info:whatsthis", "<para>To show or "
1774 "hide panels like this go to <interface>Control|Panels</interface> "
1775 "or <interface>View|Panels</interface>.</para>");
1777 actionCollection()->action(QStringLiteral("show_information_panel"))
1778 ->setWhatsThis(xi18nc("@info:whatsthis", "<para> This toggles the "
1779 "<emphasis>information</emphasis> panel at the right side of the "
1780 "window.</para><para>The panel provides in-depth information "
1781 "about the items your mouse is hovering over or about the selected "
1782 "items. Otherwise it informs you about the currently viewed folder.<nl/>"
1783 "For single items a preview of their contents is provided.</para>"));
1785 infoDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
1786 "provides in-depth information about the items your mouse is "
1787 "hovering over or about the selected items. Otherwise it informs "
1788 "you about the currently viewed folder.<nl/>For single items a "
1789 "preview of their contents is provided.</para><para>You can configure "
1790 "which and how details are given here by right-clicking.</para>") + panelWhatsThis
);
1793 DolphinDockWidget
* foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
1794 foldersDock
->setLocked(lock
);
1795 foldersDock
->setObjectName(QStringLiteral("foldersDock"));
1796 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1797 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1798 foldersPanel
->setCustomContextMenuActions({lockLayoutAction
});
1799 foldersDock
->setWidget(foldersPanel
);
1801 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1802 createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7
, foldersAction
, QStringLiteral("show_folders_panel"));
1804 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1805 connect(this, &DolphinMainWindow::urlChanged
,
1806 foldersPanel
, &FoldersPanel::setUrl
);
1807 connect(foldersPanel
, &FoldersPanel::folderActivated
,
1808 this, &DolphinMainWindow::changeUrl
);
1809 connect(foldersPanel
, &FoldersPanel::folderMiddleClicked
,
1810 this, &DolphinMainWindow::openNewTabAfterCurrentTab
);
1811 connect(foldersPanel
, &FoldersPanel::errorMessage
,
1812 this, &DolphinMainWindow::showErrorMessage
);
1814 actionCollection()->action(QStringLiteral("show_folders_panel"))
1815 ->setWhatsThis(xi18nc("@info:whatsthis", "This toggles the "
1816 "<emphasis>folders</emphasis> panel at the left side of the window."
1817 "<nl/><nl/>It shows the folders of the <emphasis>file system"
1818 "</emphasis> in a <emphasis>tree view</emphasis>."));
1819 foldersDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
1820 "shows the folders of the <emphasis>file system</emphasis> in a "
1821 "<emphasis>tree view</emphasis>.</para><para>Click a folder to go "
1822 "there. Click the arrow to the left of a folder to see its subfolders. "
1823 "This allows quick switching between any folders.</para>") + panelWhatsThis
);
1826 #ifdef HAVE_TERMINAL
1827 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1828 DolphinDockWidget
* terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1829 terminalDock
->setLocked(lock
);
1830 terminalDock
->setObjectName(QStringLiteral("terminalDock"));
1831 m_terminalPanel
= new TerminalPanel(terminalDock
);
1832 m_terminalPanel
->setCustomContextMenuActions({lockLayoutAction
});
1833 terminalDock
->setWidget(m_terminalPanel
);
1835 connect(m_terminalPanel
, &TerminalPanel::hideTerminalPanel
, terminalDock
, &DolphinDockWidget::hide
);
1836 connect(m_terminalPanel
, &TerminalPanel::changeUrl
, this, &DolphinMainWindow::slotTerminalDirectoryChanged
);
1837 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
,
1838 m_terminalPanel
, &TerminalPanel::dockVisibilityChanged
);
1839 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
,
1840 this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged
);
1842 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1843 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4
, terminalAction
, QStringLiteral("show_terminal_panel"));
1845 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1846 connect(this, &DolphinMainWindow::urlChanged
,
1847 m_terminalPanel
, &TerminalPanel::setUrl
);
1849 if (GeneralSettings::version() < 200) {
1850 terminalDock
->hide();
1853 actionCollection()->action(QStringLiteral("show_terminal_panel"))
1854 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
1855 "<emphasis>terminal</emphasis> panel at the bottom of the window."
1856 "<nl/>The location in the terminal will always match the folder "
1857 "view so you can navigate using either.</para><para>The terminal "
1858 "panel is not needed for basic computer usage but can be useful "
1859 "for advanced tasks. To learn more about terminals use the help "
1860 "in a standalone terminal application like Konsole.</para>"));
1861 terminalDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is "
1862 "the <emphasis>terminal</emphasis> panel. It behaves like a "
1863 "normal terminal but will match the location of the folder view "
1864 "so you can navigate using either.</para><para>The terminal panel "
1865 "is not needed for basic computer usage but can be useful for "
1866 "advanced tasks. To learn more about terminals use the help in a "
1867 "standalone terminal application like Konsole.</para>") + panelWhatsThis
);
1871 if (GeneralSettings::version() < 200) {
1873 foldersDock
->hide();
1877 DolphinDockWidget
* placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
1878 placesDock
->setLocked(lock
);
1879 placesDock
->setObjectName(QStringLiteral("placesDock"));
1880 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1882 m_placesPanel
= new PlacesPanel(placesDock
);
1883 m_placesPanel
->setCustomContextMenuActions({lockLayoutAction
});
1884 placesDock
->setWidget(m_placesPanel
);
1886 QAction
*placesAction
= placesDock
->toggleViewAction();
1887 createPanelAction(QIcon::fromTheme(QStringLiteral("bookmarks")), Qt::Key_F9
, placesAction
, QStringLiteral("show_places_panel"));
1889 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1890 connect(m_placesPanel
, &PlacesPanel::placeActivated
,
1891 this, &DolphinMainWindow::slotPlaceActivated
);
1892 connect(m_placesPanel
, &PlacesPanel::placeMiddleClicked
,
1893 this, &DolphinMainWindow::openNewTabAfterCurrentTab
);
1894 connect(m_placesPanel
, &PlacesPanel::errorMessage
,
1895 this, &DolphinMainWindow::showErrorMessage
);
1896 connect(this, &DolphinMainWindow::urlChanged
,
1897 m_placesPanel
, &PlacesPanel::setUrl
);
1898 connect(placesDock
, &DolphinDockWidget::visibilityChanged
,
1899 &DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged
);
1900 connect(this, &DolphinMainWindow::settingsChanged
,
1901 m_placesPanel
, &PlacesPanel::readSettings
);
1902 connect(m_placesPanel
, &PlacesPanel::storageTearDownRequested
,
1903 this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested
);
1904 connect(m_placesPanel
, &PlacesPanel::storageTearDownExternallyRequested
,
1905 this, &DolphinMainWindow::slotStorageTearDownExternallyRequested
);
1906 DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged(m_placesPanel
->isVisible());
1908 auto actionShowAllPlaces
= new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this);
1909 actionShowAllPlaces
->setCheckable(true);
1910 actionShowAllPlaces
->setDisabled(true);
1911 actionShowAllPlaces
->setWhatsThis(i18nc("@info:whatsthis", "This displays "
1912 "all places in the places panel that have been hidden. They will "
1913 "appear semi-transparent unless you uncheck their hide property."));
1915 connect(actionShowAllPlaces
, &QAction::triggered
, this, [actionShowAllPlaces
, this](bool checked
){
1916 actionShowAllPlaces
->setIcon(QIcon::fromTheme(checked
? QStringLiteral("view-visible") : QStringLiteral("view-hidden")));
1917 m_placesPanel
->showHiddenEntries(checked
);
1920 connect(m_placesPanel
, &PlacesPanel::showHiddenEntriesChanged
, this, [actionShowAllPlaces
] (bool checked
){
1921 actionShowAllPlaces
->setChecked(checked
);
1922 actionShowAllPlaces
->setIcon(QIcon::fromTheme(checked
? QStringLiteral("view-visible") : QStringLiteral("view-hidden")));
1925 actionCollection()->action(QStringLiteral("show_places_panel"))
1926 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
1927 "<emphasis>places</emphasis> panel at the left side of the window."
1928 "</para><para>It allows you to go to locations you have "
1929 "bookmarked and to access disk or media attached to the computer "
1930 "or to the network. It also contains sections to find recently "
1931 "saved files or files of a certain type.</para>"));
1932 placesDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
1933 "<emphasis>Places</emphasis> panel. It allows you to go to locations "
1934 "you have bookmarked and to access disk or media attached to the "
1935 "computer or to the network. It also contains sections to find "
1936 "recently saved files or files of a certain type.</para><para>"
1937 "Click on an entry to go there. Click with the right mouse button "
1938 "instead to open any entry in a new tab or new window.</para>"
1939 "<para>New entries can be added by dragging folders onto this panel. "
1940 "Right-click any section or entry to hide it. Right-click an empty "
1941 "space on this panel and select <interface>Show Hidden Places"
1942 "</interface> to display it again.</para>") + panelWhatsThis
);
1944 // Add actions into the "Panels" menu
1945 KActionMenu
* panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Show Panels"), this);
1946 actionCollection()->addAction(QStringLiteral("panels"), panelsMenu
);
1947 panelsMenu
->setIcon(QIcon::fromTheme(QStringLiteral("view-sidetree")));
1948 panelsMenu
->setDelayed(false);
1949 const KActionCollection
* ac
= actionCollection();
1950 panelsMenu
->addAction(ac
->action(QStringLiteral("show_places_panel")));
1952 panelsMenu
->addAction(ac
->action(QStringLiteral("show_information_panel")));
1954 panelsMenu
->addAction(ac
->action(QStringLiteral("show_folders_panel")));
1955 panelsMenu
->addAction(ac
->action(QStringLiteral("show_terminal_panel")));
1956 panelsMenu
->addSeparator();
1957 panelsMenu
->addAction(actionShowAllPlaces
);
1958 panelsMenu
->addAction(lockLayoutAction
);
1960 connect(panelsMenu
->menu(), &QMenu::aboutToShow
, this, [actionShowAllPlaces
, this]{
1961 actionShowAllPlaces
->setEnabled(m_placesPanel
->hiddenListCount());
1966 void DolphinMainWindow::updateFileAndEditActions()
1968 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1969 const KActionCollection
* col
= actionCollection();
1970 KFileItemListProperties
capabilitiesSource(list
);
1972 QAction
* addToPlacesAction
= col
->action(QStringLiteral("add_to_places"));
1973 QAction
* copyToOtherViewAction
= col
->action(QStringLiteral("copy_to_inactive_split_view"));
1974 QAction
* moveToOtherViewAction
= col
->action(QStringLiteral("move_to_inactive_split_view"));
1975 QAction
* copyLocation
= col
->action(QString("copy_location"));
1977 if (list
.isEmpty()) {
1978 stateChanged(QStringLiteral("has_no_selection"));
1980 addToPlacesAction
->setEnabled(true);
1981 copyToOtherViewAction
->setEnabled(false);
1982 moveToOtherViewAction
->setEnabled(false);
1983 copyLocation
->setEnabled(false);
1985 stateChanged(QStringLiteral("has_selection"));
1987 QAction
* renameAction
= col
->action(KStandardAction::name(KStandardAction::RenameFile
));
1988 QAction
* moveToTrashAction
= col
->action(KStandardAction::name(KStandardAction::MoveToTrash
));
1989 QAction
* deleteAction
= col
->action(KStandardAction::name(KStandardAction::DeleteFile
));
1990 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1991 QAction
* deleteWithTrashShortcut
= col
->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
1992 QAction
* showTarget
= col
->action(QStringLiteral("show_target"));
1993 QAction
* duplicateAction
= col
->action(QStringLiteral("duplicate")); // see DolphinViewActionHandler
1995 if (list
.length() == 1 && list
.first().isDir()) {
1996 addToPlacesAction
->setEnabled(true);
1998 addToPlacesAction
->setEnabled(false);
2001 if (m_tabWidget
->currentTabPage()->splitViewEnabled()) {
2002 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
2003 KFileItem capabilitiesDestination
;
2005 if (tabPage
->primaryViewActive()) {
2006 capabilitiesDestination
= tabPage
->secondaryViewContainer()->url();
2008 capabilitiesDestination
= tabPage
->primaryViewContainer()->url();
2011 copyToOtherViewAction
->setEnabled(capabilitiesDestination
.isWritable());
2012 moveToOtherViewAction
->setEnabled(capabilitiesSource
.supportsMoving() && capabilitiesDestination
.isWritable());
2014 copyToOtherViewAction
->setEnabled(false);
2015 moveToOtherViewAction
->setEnabled(false);
2018 const bool enableMoveToTrash
= capabilitiesSource
.isLocal() && capabilitiesSource
.supportsMoving();
2020 renameAction
->setEnabled(capabilitiesSource
.supportsMoving());
2021 moveToTrashAction
->setEnabled(enableMoveToTrash
);
2022 deleteAction
->setEnabled(capabilitiesSource
.supportsDeleting());
2023 deleteWithTrashShortcut
->setEnabled(capabilitiesSource
.supportsDeleting() && !enableMoveToTrash
);
2024 cutAction
->setEnabled(capabilitiesSource
.supportsMoving());
2025 copyLocation
->setEnabled(list
.length() == 1);
2026 showTarget
->setEnabled(list
.length() == 1 && list
.at(0).isLink());
2027 duplicateAction
->setEnabled(capabilitiesSource
.supportsWriting());
2031 void DolphinMainWindow::updateViewActions()
2033 m_actionHandler
->updateViewActions();
2035 QAction
* showFilterBarAction
= actionCollection()->action(QStringLiteral("show_filter_bar"));
2036 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
2038 updateSplitAction();
2041 void DolphinMainWindow::updateGoActions()
2043 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
2044 const QUrl currentUrl
= m_activeViewContainer
->url();
2045 // I think this is one of the best places to firstly be confronted
2046 // with a file system and its hierarchy. Talking about the root
2047 // directory might seem too much here but it is the question that
2048 // naturally arises in this context.
2049 goUpAction
->setWhatsThis(xi18nc("@info:whatsthis", "<para>Go to "
2050 "the folder that contains the currently viewed one.</para>"
2051 "<para>All files and folders are organized in a hierarchical "
2052 "<emphasis>file system</emphasis>. At the top of this hierarchy is "
2053 "a directory that contains all data connected to this computer"
2054 "—the <emphasis>root directory</emphasis>.</para>"));
2055 goUpAction
->setEnabled(KIO::upUrl(currentUrl
) != currentUrl
);
2058 void DolphinMainWindow::createControlButton()
2060 if (m_controlButton
) {
2063 Q_ASSERT(!m_controlButton
);
2065 m_controlButton
= new QToolButton(this);
2066 m_controlButton
->setAccessibleName(i18nc("@action:intoolbar", "Control"));
2067 m_controlButton
->setIcon(QIcon::fromTheme(QStringLiteral("application-menu")));
2068 m_controlButton
->setToolTip(i18nc("@action", "Show menu"));
2069 m_controlButton
->setAttribute(Qt::WidgetAttribute::WA_CustomWhatsThis
);
2070 m_controlButton
->setPopupMode(QToolButton::InstantPopup
);
2072 QMenu
* controlMenu
= new QMenu(m_controlButton
);
2073 connect(controlMenu
, &QMenu::aboutToShow
, this, &DolphinMainWindow::updateControlMenu
);
2074 controlMenu
->installEventFilter(this);
2076 m_controlButton
->setMenu(controlMenu
);
2078 toolBar()->addWidget(m_controlButton
);
2079 connect(toolBar(), &KToolBar::iconSizeChanged
,
2080 m_controlButton
, &QToolButton::setIconSize
);
2082 // The added widgets are owned by the toolbar and may get deleted when e.g. the toolbar
2083 // gets edited. In this case we must add them again. The adding is done asynchronously by
2084 // m_updateToolBarTimer.
2085 connect(m_controlButton
, &QToolButton::destroyed
, this, &DolphinMainWindow::slotControlButtonDeleted
);
2086 m_updateToolBarTimer
= new QTimer(this);
2087 m_updateToolBarTimer
->setInterval(500);
2088 connect(m_updateToolBarTimer
, &QTimer::timeout
, this, &DolphinMainWindow::updateToolBar
);
2091 void DolphinMainWindow::deleteControlButton()
2093 delete m_controlButton
;
2094 m_controlButton
= nullptr;
2096 delete m_updateToolBarTimer
;
2097 m_updateToolBarTimer
= nullptr;
2100 bool DolphinMainWindow::addActionToMenu(QAction
* action
, QMenu
* menu
)
2105 const KToolBar
* toolBarWidget
= toolBar();
2106 const auto associatedWidgets
= action
->associatedWidgets();
2107 for (const QWidget
* widget
: associatedWidgets
) {
2108 if (widget
== toolBarWidget
) {
2113 menu
->addAction(action
);
2117 void DolphinMainWindow::refreshViews()
2119 m_tabWidget
->refreshViews();
2121 if (GeneralSettings::modifiedStartupSettings()) {
2122 // The startup settings have been changed by the user (see bug #254947).
2123 // Synchronize the split-view setting with the active view:
2124 const bool splitView
= GeneralSettings::splitView();
2125 m_tabWidget
->currentTabPage()->setSplitViewEnabled(splitView
);
2126 updateSplitAction();
2127 updateWindowTitle();
2130 Q_EMIT
settingsChanged();
2133 void DolphinMainWindow::clearStatusBar()
2135 m_activeViewContainer
->statusBar()->resetToDefaultText();
2138 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
2140 connect(container
, &DolphinViewContainer::showFilterBarChanged
,
2141 this, &DolphinMainWindow::updateFilterBarAction
);
2142 connect(container
, &DolphinViewContainer::writeStateChanged
,
2143 this, &DolphinMainWindow::slotWriteStateChanged
);
2144 connect(container
, &DolphinViewContainer::searchModeEnabledChanged
,
2145 this, &DolphinMainWindow::updateSearchAction
);
2147 const QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
2148 connect(toggleSearchAction
, &QAction::triggered
, container
, &DolphinViewContainer::setSearchModeEnabled
);
2150 const DolphinView
* view
= container
->view();
2151 connect(view
, &DolphinView::selectionChanged
,
2152 this, &DolphinMainWindow::slotSelectionChanged
);
2153 connect(view
, &DolphinView::requestItemInfo
,
2154 this, &DolphinMainWindow::requestItemInfo
);
2155 connect(view
, &DolphinView::tabRequested
,
2156 this, &DolphinMainWindow::openNewTab
);
2157 connect(view
, &DolphinView::requestContextMenu
,
2158 this, &DolphinMainWindow::openContextMenu
);
2159 connect(view
, &DolphinView::directoryLoadingStarted
,
2160 this, &DolphinMainWindow::enableStopAction
);
2161 connect(view
, &DolphinView::directoryLoadingCompleted
,
2162 this, &DolphinMainWindow::disableStopAction
);
2163 connect(view
, &DolphinView::directoryLoadingCompleted
,
2164 this, &DolphinMainWindow::slotDirectoryLoadingCompleted
);
2165 connect(view
, &DolphinView::goBackRequested
,
2166 this, &DolphinMainWindow::goBack
);
2167 connect(view
, &DolphinView::goForwardRequested
,
2168 this, &DolphinMainWindow::goForward
);
2169 connect(view
, &DolphinView::urlActivated
,
2170 this, &DolphinMainWindow::handleUrl
);
2171 connect(view
, &DolphinView::goUpRequested
,
2172 this, &DolphinMainWindow::goUp
);
2174 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
2175 (actionCollection()->action(QStringLiteral("url_navigators")));
2177 const KUrlNavigator
*navigator
= m_tabWidget
->currentTabPage()->primaryViewActive() ?
2178 navigators
->primaryUrlNavigator() :
2179 navigators
->secondaryUrlNavigator();
2181 connect(navigator
, &KUrlNavigator::urlChanged
,
2182 this, &DolphinMainWindow::changeUrl
);
2183 QAction
*editableLocactionAction
= actionCollection()->action(QStringLiteral("editable_location"));
2184 editableLocactionAction
->setChecked(navigator
->isUrlEditable());
2185 connect(navigator
, &KUrlNavigator::editableStateChanged
,
2186 this, &DolphinMainWindow::slotEditableStateChanged
);
2187 connect(navigator
, &KUrlNavigator::tabRequested
,
2188 this, &DolphinMainWindow::openNewTabAfterLastTab
);
2190 disconnect(m_updateHistoryConnection
);
2191 m_updateHistoryConnection
= connect(
2192 container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::historyChanged
,
2193 this, &DolphinMainWindow::updateHistory
);
2196 void DolphinMainWindow::updateSplitAction()
2198 QAction
* splitAction
= actionCollection()->action(QStringLiteral("split_view"));
2199 const DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
2200 if (tabPage
->splitViewEnabled()) {
2201 if (GeneralSettings::closeActiveSplitView() ? tabPage
->primaryViewActive() : !tabPage
->primaryViewActive()) {
2202 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2203 splitAction
->setToolTip(i18nc("@info", "Close left view"));
2204 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close")));
2206 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2207 splitAction
->setToolTip(i18nc("@info", "Close right view"));
2208 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close")));
2211 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2212 splitAction
->setToolTip(i18nc("@info", "Split view"));
2213 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2217 void DolphinMainWindow::updateAllowedToolbarAreas()
2219 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
2220 (actionCollection()->action(QStringLiteral("url_navigators")));
2221 if (toolBar()->actions().contains(navigators
)) {
2222 toolBar()->setAllowedAreas(Qt::TopToolBarArea
| Qt::BottomToolBarArea
);
2223 if (toolBarArea(toolBar()) == Qt::LeftToolBarArea
||
2224 toolBarArea(toolBar()) == Qt::RightToolBarArea
) {
2225 addToolBar(Qt::TopToolBarArea
, toolBar());
2228 toolBar()->setAllowedAreas(Qt::AllToolBarAreas
);
2232 bool DolphinMainWindow::isKompareInstalled() const
2234 static bool initialized
= false;
2235 static bool installed
= false;
2237 // TODO: maybe replace this approach later by using a menu
2238 // plugin like kdiff3plugin.cpp
2239 installed
= !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty();
2245 void DolphinMainWindow::createPanelAction(const QIcon
& icon
,
2246 const QKeySequence
& shortcut
,
2247 QAction
* dockAction
,
2248 const QString
& actionName
)
2250 QAction
* panelAction
= actionCollection()->addAction(actionName
);
2251 panelAction
->setCheckable(true);
2252 panelAction
->setChecked(dockAction
->isChecked());
2253 panelAction
->setText(dockAction
->text());
2254 panelAction
->setIcon(icon
);
2255 actionCollection()->setDefaultShortcut(panelAction
, shortcut
);
2257 connect(panelAction
, &QAction::triggered
, dockAction
, &QAction::trigger
);
2258 connect(dockAction
, &QAction::toggled
, panelAction
, &QAction::setChecked
);
2261 void DolphinMainWindow::setupWhatsThis()
2264 menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2265 "<emphasis>Menubar</emphasis>. It provides access to commands and "
2266 "configuration options. Left-click on any of the menus on this "
2267 "bar to see its contents.</para><para>The Menubar can be hidden "
2268 "by unchecking <interface>Settings|Show Menubar</interface>. Then "
2269 "most of its contents become available through a <interface>Control"
2270 "</interface> button on the <emphasis>Toolbar</emphasis>.</para>"));
2271 toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2272 "<emphasis>Toolbar</emphasis>. It allows quick access to "
2273 "frequently used actions.</para><para>It is highly customizable. "
2274 "All items you see in the <interface>Control</interface> menu or "
2275 "in the <interface>Menubar</interface> can be placed on the "
2276 "Toolbar. Just right-click on it and select <interface>Configure "
2277 "Toolbars…</interface> or find this action in the <interface>"
2278 "Control</interface> or <interface>Settings</interface> menu."
2279 "</para><para>The location of the bar and the style of its "
2280 "buttons can also be changed in the right-click menu. Right-click "
2281 "a button if you want to show or hide its text.</para>"));
2282 m_tabWidget
->setWhatsThis(xi18nc("@info:whatsthis main view",
2283 "<para>Here you can see the <emphasis>folders</emphasis> and "
2284 "<emphasis>files</emphasis> that are at the location described in "
2285 "the <interface>Location Bar</interface> above. This area is the "
2286 "central part of this application where you navigate to the files "
2287 "you want to use.</para><para>For an elaborate and general "
2288 "introduction to this application <link "
2289 "url='https://userbase.kde.org/Dolphin/File_Management#Introduction_to_Dolphin'>"
2290 "click here</link>. This will open an introductory article from "
2291 "the <emphasis>KDE UserBase Wiki</emphasis>.</para><para>For brief "
2292 "explanations of all the features of this <emphasis>view</emphasis> "
2293 "<link url='help:/dolphin/dolphin-view.html'>click here</link> "
2294 "instead. This will open a page from the <emphasis>Handbook"
2295 "</emphasis> that covers the basics.</para>"));
2298 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings
))
2299 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window "
2300 "that lists the <emphasis>keyboard shortcuts</emphasis>.<nl/>"
2301 "There you can set up key combinations to trigger an action when "
2302 "they are pressed simultaneously. All commands in this application can "
2303 "be triggered this way.</para>"));
2304 actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars
))
2305 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window in which "
2306 "you can change which buttons appear on the <emphasis>Toolbar</emphasis>.</para>"
2307 "<para>All items you see in the <interface>Control</interface> menu "
2308 "or in the <interface>Menubar</interface> can also be placed on the Toolbar.</para>"));
2309 actionCollection()->action(KStandardAction::name(KStandardAction::Preferences
))
2310 ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can "
2311 "change a multitude of settings for this application. For an explanation "
2312 "of the various settings go to the chapter <emphasis>Configuring Dolphin"
2313 "</emphasis> in <interface>Help|Dolphin Handbook</interface>."));
2316 // The whatsthis has to be set for the m_helpMenu and for the
2317 // StandardAction separately because both are used in different locations.
2318 // m_helpMenu is only used for createControlButton() button.
2320 // Links do not work within the Menubar so texts without links are provided there.
2322 // i18n: If the external link isn't available in your language you should
2323 // probably state the external link language at least in brackets to not
2324 // frustrate the user. If there are multiple languages that the user might
2325 // know with a reasonable chance you might want to have 2 external links.
2326 // The same is in my opinion true for every external link you translate.
2327 const QString whatsThisHelpContents
= xi18nc("@info:whatsthis handbook",
2328 "<para>This opens the Handbook for this application. It provides "
2329 "explanations for every part of <emphasis>Dolphin</emphasis>.</para>");
2330 actionCollection()->action(KStandardAction::name(KStandardAction::HelpContents
))
2331 ->setWhatsThis(whatsThisHelpContents
2332 + xi18nc("@info:whatsthis second half of handbook hb text without link",
2333 "<para>If you want more elaborate introductions to the "
2334 "different features of <emphasis>Dolphin</emphasis> "
2335 "go to the KDE UserBase Wiki.</para>"));
2336 m_helpMenu
->action(KHelpMenu::menuHelpContents
)->setWhatsThis(whatsThisHelpContents
2337 + xi18nc("@info:whatsthis second half of handbook text with link",
2338 "<para>If you want more elaborate introductions to the "
2339 "different features of <emphasis>Dolphin</emphasis> "
2340 "<link url='https://userbase.kde.org/Dolphin/File_Management'>click here</link>. "
2341 "It will open the dedicated page in the KDE UserBase Wiki.</para>"));
2343 const QString whatsThisWhatsThis
= xi18nc("@info:whatsthis whatsthis button",
2344 "<para>This is the button that invokes the help feature you are "
2345 "using right now! Click it, then click any component of this "
2346 "application to ask \"What's this?\" about it. The mouse cursor "
2347 "will change appearance if no help is available for a spot.</para>");
2348 actionCollection()->action(KStandardAction::name(KStandardAction::WhatsThis
))
2349 ->setWhatsThis(whatsThisWhatsThis
2350 + xi18nc("@info:whatsthis second half of whatsthis button text without link",
2351 "<para>There are two other ways to get help for this application: The "
2352 "<interface>Dolphin Handbook</interface> in the <interface>Help"
2353 "</interface> menu and the <emphasis>KDE UserBase Wiki</emphasis> "
2354 "article about <emphasis>File Management</emphasis> online."
2355 "</para><para>The \"What's this?\" help is "
2356 "missing in most other windows so don't get too used to this.</para>"));
2357 m_helpMenu
->action(KHelpMenu::menuWhatsThis
)->setWhatsThis(whatsThisWhatsThis
2358 + xi18nc("@info:whatsthis second half of whatsthis button text with link",
2359 "<para>There are two other ways to get help: "
2360 "The <link url='help:/dolphin/index.html'>Dolphin Handbook</link> and "
2361 "the <link url='https://userbase.kde.org/Dolphin/File_Management'>KDE "
2362 "UserBase Wiki</link>.</para><para>The \"What's this?\" help is "
2363 "missing in most other windows so don't get too used to this.</para>"));
2365 const QString whatsThisReportBug
= xi18nc("@info:whatsthis","<para>This opens a "
2366 "window that will guide you through reporting errors or flaws "
2367 "in this application or in other KDE software.</para>");
2368 actionCollection()->action(KStandardAction::name(KStandardAction::ReportBug
))
2369 ->setWhatsThis(whatsThisReportBug
);
2370 m_helpMenu
->action(KHelpMenu::menuReportBug
)->setWhatsThis(whatsThisReportBug
2371 + xi18nc("@info:whatsthis second half of reportbug text with link",
2372 "<para>High-quality bug reports are much appreciated. To learn "
2373 "how to make your bug report as effective as possible "
2374 "<link url='https://community.kde.org/Get_Involved/Bug_Reporting'>"
2375 "click here</link>.</para>"));
2377 const QString whatsThisDonate
= xi18nc("@info:whatsthis","<para>This opens a "
2378 "<emphasis>web page</emphasis> where you can donate to "
2379 "support the continued work on this application and many "
2380 "other projects by the <emphasis>KDE</emphasis> community.</para>"
2381 "<para>Donating is the easiest and fastest way to efficiently "
2382 "support KDE and its projects. KDE projects are available for "
2383 "free therefore your donation is needed to cover things that "
2384 "require money like servers, contributor meetings, etc.</para>"
2385 "<para><emphasis>KDE e.V.</emphasis> is the non-profit "
2386 "organization behind the KDE community.</para>");
2387 actionCollection()->action(KStandardAction::name(KStandardAction::Donate
))
2388 ->setWhatsThis(whatsThisDonate
);
2389 m_helpMenu
->action(KHelpMenu::menuDonate
)->setWhatsThis(whatsThisDonate
);
2391 const QString whatsThisSwitchLanguage
= xi18nc("@info:whatsthis",
2392 "With this you can change the language this application uses."
2393 "<nl/>You can even set secondary languages which will be used "
2394 "if texts are not available in your preferred language.");
2395 actionCollection()->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
))
2396 ->setWhatsThis(whatsThisSwitchLanguage
);
2397 m_helpMenu
->action(KHelpMenu::menuSwitchLanguage
)->setWhatsThis(whatsThisSwitchLanguage
);
2399 const QString whatsThisAboutApp
= xi18nc("@info:whatsthis","This opens a "
2400 "window that informs you about the version, license, "
2401 "used libraries and maintainers of this application.");
2402 actionCollection()->action(KStandardAction::name(KStandardAction::AboutApp
))
2403 ->setWhatsThis(whatsThisAboutApp
);
2404 m_helpMenu
->action(KHelpMenu::menuAboutApp
)->setWhatsThis(whatsThisAboutApp
);
2406 const QString whatsThisAboutKDE
= xi18nc("@info:whatsthis","This opens a "
2407 "window with information about <emphasis>KDE</emphasis>. "
2408 "The KDE community are the people behind this free software."
2409 "<nl/>If you like using this application but don't know "
2410 "about KDE or want to see a cute dragon have a look!");
2411 actionCollection()->action(KStandardAction::name(KStandardAction::AboutKDE
))
2412 ->setWhatsThis(whatsThisAboutKDE
);
2413 m_helpMenu
->action(KHelpMenu::menuAboutKDE
)->setWhatsThis(whatsThisAboutKDE
);
2416 bool DolphinMainWindow::event(QEvent
*event
)
2418 if (event
->type() == QEvent::WhatsThisClicked
) {
2420 QWhatsThisClickedEvent
* whatsThisEvent
= dynamic_cast<QWhatsThisClickedEvent
*>(event
);
2421 QDesktopServices::openUrl(QUrl(whatsThisEvent
->href()));
2424 return KXmlGuiWindow::event(event
);
2427 bool DolphinMainWindow::eventFilter(QObject
* obj
, QEvent
* event
)
2430 if (event
->type() == QEvent::WhatsThisClicked
) {
2432 QWhatsThisClickedEvent
* whatsThisEvent
= dynamic_cast<QWhatsThisClickedEvent
*>(event
);
2433 QDesktopServices::openUrl(QUrl(whatsThisEvent
->href()));
2439 void DolphinMainWindow::saveNewToolbarConfig()
2441 KXmlGuiWindow::saveNewToolbarConfig(); // Applies the new config. This has to be called first
2442 // because the rest of this method decides things
2443 // based on the new config.
2444 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
2445 (actionCollection()->action(QStringLiteral("url_navigators")));
2446 if (!toolBar()->actions().contains(navigators
)) {
2447 m_tabWidget
->currentTabPage()->insertNavigatorsWidget(navigators
);
2449 updateAllowedToolbarAreas();
2452 void DolphinMainWindow::focusTerminalPanel()
2454 if (m_terminalPanel
->isVisible()) {
2455 if (m_terminalPanel
->terminalHasFocus()) {
2456 m_activeViewContainer
->view()->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2457 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2459 m_terminalPanel
->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2460 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2463 actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger();
2464 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2468 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
2469 KIO::FileUndoManager::UiInterface()
2473 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2477 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
2479 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2481 DolphinViewContainer
* container
= mainWin
->activeViewContainer();
2482 container
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
2484 KIO::FileUndoManager::UiInterface::jobError(job
);
2488 bool DolphinMainWindow::isUrlOpen(const QString
& url
)
2490 return m_tabWidget
->isUrlOpen(QUrl::fromUserInput((url
)));