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 "dolphinnewfilemenu.h"
18 #include "dolphinrecenttabsmenu.h"
19 #include "dolphinviewcontainer.h"
20 #include "dolphintabpage.h"
21 #include "middleclickactioneventfilter.h"
22 #include "panels/folders/folderspanel.h"
23 #include "panels/places/placesitemmodel.h"
24 #include "panels/places/placespanel.h"
25 #include "panels/information/informationpanel.h"
26 #include "panels/terminal/terminalpanel.h"
27 #include "settings/dolphinsettingsdialog.h"
28 #include "statusbar/dolphinstatusbar.h"
29 #include "views/dolphinviewactionhandler.h"
30 #include "views/dolphinremoteencoding.h"
31 #include "views/draganddrophelper.h"
32 #include "views/viewproperties.h"
33 #include "views/dolphinnewfilemenuobserver.h"
34 #include "dolphinnavigatorswidgetaction.h"
35 #include "dolphin_generalsettings.h"
37 #include <KActionCollection>
38 #include <KActionMenu>
39 #include <KAuthorized>
42 #include <KDualAction>
43 #include <KFileItemListProperties>
45 #include <KIO/CommandLauncherJob>
46 #include <KIO/JobUiDelegate>
47 #include <KIO/OpenFileManagerWindowJob>
48 #include <KIO/OpenUrlJob>
49 #include <KJobWidgets>
50 #include <KLocalizedString>
51 #include <KMessageBox>
52 #include <KNS3/KMoreToolsMenuFactory>
53 #include <KProtocolInfo>
54 #include <KProtocolManager>
56 #include <KStandardAction>
57 #include <KStartupInfo>
59 #include <KToggleAction>
61 #include <KToolBarPopupAction>
62 #include <KToolInvocation>
63 #include <KUrlComboBox>
64 #include <KUrlNavigator>
65 #include <KWindowSystem>
67 #include <QApplication>
69 #include <QCloseEvent>
70 #include <QDesktopServices>
75 #include <QPushButton>
77 #include <QStandardPaths>
79 #include <QToolButton>
80 #include <QWhatsThisClickedEvent>
83 // Used for GeneralSettings::version() to determine whether
84 // an updated version of Dolphin is running.
85 const int CurrentDolphinVersion
= 200;
86 // The maximum number of entries in the back/forward popup menu
87 const int MaxNumberOfNavigationentries
= 12;
88 // The maximum number of "Activate Tab" shortcuts
89 const int MaxActivateTabShortcuts
= 9;
92 DolphinMainWindow::DolphinMainWindow() :
93 KXmlGuiWindow(nullptr),
94 m_newFileMenu(nullptr),
97 m_activeViewContainer(nullptr),
98 m_actionHandler(nullptr),
99 m_remoteEncoding(nullptr),
101 m_bookmarkHandler(nullptr),
102 m_controlButton(nullptr),
103 m_updateToolBarTimer(nullptr),
104 m_lastHandleUrlOpenJob(nullptr),
105 m_terminalPanel(nullptr),
106 m_placesPanel(nullptr),
107 m_tearDownFromPlacesRequested(false),
108 m_backAction(nullptr),
109 m_forwardAction(nullptr),
110 m_updateHistoryConnection
{}
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 navigatorsWidgetAction
->setText(i18nc(
147 "@action:inmenu When split view is enabled there are two otherwise one.",
148 "Url Navigator(s)"));
149 actionCollection()->addAction(QStringLiteral("url_navigators"), navigatorsWidgetAction
);
150 m_tabWidget
= new DolphinTabWidget(navigatorsWidgetAction
, this);
151 m_tabWidget
->setObjectName("tabWidget");
152 connect(m_tabWidget
, &DolphinTabWidget::activeViewChanged
,
153 this, &DolphinMainWindow::activeViewChanged
);
154 connect(m_tabWidget
, &DolphinTabWidget::tabCountChanged
,
155 this, &DolphinMainWindow::tabCountChanged
);
156 connect(m_tabWidget
, &DolphinTabWidget::currentUrlChanged
,
157 this, &DolphinMainWindow::updateWindowTitle
);
158 setCentralWidget(m_tabWidget
);
162 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
163 connect(m_actionHandler
, &DolphinViewActionHandler::actionBeingHandled
, this, &DolphinMainWindow::clearStatusBar
);
164 connect(m_actionHandler
, &DolphinViewActionHandler::createDirectoryTriggered
, this, &DolphinMainWindow::createDirectory
);
166 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
167 connect(this, &DolphinMainWindow::urlChanged
,
168 m_remoteEncoding
, &DolphinRemoteEncoding::slotAboutToOpenUrl
);
172 setupGUI(Keys
| Save
| Create
| ToolBar
);
173 stateChanged(QStringLiteral("new_file"));
175 toolBar()->setAllowedAreas(Qt::TopToolBarArea
| Qt::BottomToolBarArea
);
176 toolBar()->setFloatable(false);
177 if (!toolBar()->actions().contains(navigatorsWidgetAction
)) {
178 navigatorsWidgetAction
->addToToolbarAndSave(this);
180 QClipboard
* clipboard
= QApplication::clipboard();
181 connect(clipboard
, &QClipboard::dataChanged
,
182 this, &DolphinMainWindow::updatePasteAction
);
184 QAction
* showFilterBarAction
= actionCollection()->action(QStringLiteral("show_filter_bar"));
185 showFilterBarAction
->setChecked(generalSettings
->filterBar());
188 menuBar()->setVisible(false);
189 // Assure a proper default size if Dolphin runs the first time
193 const bool showMenu
= !menuBar()->isHidden();
194 QAction
* showMenuBarAction
= actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar
));
195 showMenuBarAction
->setChecked(showMenu
); // workaround for bug #171080
197 createControlButton();
200 // enable middle-click on back/forward/up to open in a new tab
201 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
202 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotToolBarActionMiddleClicked
);
203 toolBar()->installEventFilter(middleClickEventFilter
);
207 connect(KSycoca::self(), QOverload
<>::of(&KSycoca::databaseChanged
), this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
209 QTimer::singleShot(0, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
212 DolphinMainWindow::~DolphinMainWindow()
216 QVector
<DolphinViewContainer
*> DolphinMainWindow::viewContainers() const
218 QVector
<DolphinViewContainer
*> viewContainers
;
220 for (int i
= 0; i
< m_tabWidget
->count(); ++i
) {
221 DolphinTabPage
*tabPage
= m_tabWidget
->tabPageAt(i
);
223 viewContainers
<< tabPage
->primaryViewContainer();
224 if (tabPage
->splitViewEnabled()) {
225 viewContainers
<< tabPage
->secondaryViewContainer();
228 return viewContainers
;
231 void DolphinMainWindow::setViewsWithInvalidPathsToHome()
233 const QVector
<DolphinViewContainer
*> theViewContainers
= viewContainers();
234 for (DolphinViewContainer
*viewContainer
: theViewContainers
) {
236 // Only consider local dirs, not remote locations and abstract protocols
237 if (viewContainer
->url().isLocalFile()) {
238 if (!QFileInfo::exists(viewContainer
->url().toLocalFile())) {
239 viewContainer
->setUrl(QUrl::fromLocalFile(QDir::homePath()));
245 void DolphinMainWindow::openDirectories(const QList
<QUrl
>& dirs
, bool splitView
)
247 m_tabWidget
->openDirectories(dirs
, splitView
);
250 void DolphinMainWindow::openDirectories(const QStringList
& dirs
, bool splitView
)
252 openDirectories(QUrl::fromStringList(dirs
), splitView
);
255 void DolphinMainWindow::openFiles(const QList
<QUrl
>& files
, bool splitView
)
257 m_tabWidget
->openFiles(files
, splitView
);
260 bool DolphinMainWindow::isFoldersPanelEnabled() const
262 return actionCollection()->action(QStringLiteral("show_folders_panel"))->isChecked();
265 bool DolphinMainWindow::isInformationPanelEnabled() const
267 return actionCollection()->action(QStringLiteral("show_information_panel"))->isChecked();
270 void DolphinMainWindow::openFiles(const QStringList
& files
, bool splitView
)
272 openFiles(QUrl::fromStringList(files
), splitView
);
275 void DolphinMainWindow::activateWindow()
277 window()->setAttribute(Qt::WA_NativeWindow
, true);
278 KStartupInfo::setNewStartupId(window()->windowHandle(), KStartupInfo::startupId());
279 KWindowSystem::activateWindow(window()->effectiveWinId());
282 void DolphinMainWindow::showCommand(CommandType command
)
284 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
286 case KIO::FileUndoManager::Copy
:
287 statusBar
->setText(i18nc("@info:status", "Successfully copied."));
289 case KIO::FileUndoManager::Move
:
290 statusBar
->setText(i18nc("@info:status", "Successfully moved."));
292 case KIO::FileUndoManager::Link
:
293 statusBar
->setText(i18nc("@info:status", "Successfully linked."));
295 case KIO::FileUndoManager::Trash
:
296 statusBar
->setText(i18nc("@info:status", "Successfully moved to trash."));
298 case KIO::FileUndoManager::Rename
:
299 statusBar
->setText(i18nc("@info:status", "Successfully renamed."));
302 case KIO::FileUndoManager::Mkdir
:
303 statusBar
->setText(i18nc("@info:status", "Created folder."));
311 void DolphinMainWindow::pasteIntoFolder()
313 m_activeViewContainer
->view()->pasteIntoFolder();
316 void DolphinMainWindow::changeUrl(const QUrl
&url
)
318 if (!KProtocolManager::supportsListing(url
)) {
319 // The URL navigator only checks for validity, not
320 // if the URL can be listed. An error message is
321 // shown due to DolphinViewContainer::restoreView().
325 m_activeViewContainer
->setUrl(url
);
326 updateFileAndEditActions();
331 Q_EMIT
urlChanged(url
);
334 void DolphinMainWindow::slotTerminalDirectoryChanged(const QUrl
& url
)
336 if (m_tearDownFromPlacesRequested
&& url
== QUrl::fromLocalFile(QDir::homePath())) {
337 m_placesPanel
->proceedWithTearDown();
338 m_tearDownFromPlacesRequested
= false;
341 m_activeViewContainer
->setAutoGrabFocus(false);
343 m_activeViewContainer
->setAutoGrabFocus(true);
346 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
348 KToggleAction
* editableLocationAction
=
349 static_cast<KToggleAction
*>(actionCollection()->action(QStringLiteral("editable_location")));
350 editableLocationAction
->setChecked(editable
);
353 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
355 updateFileAndEditActions();
357 const int selectedUrlsCount
= m_tabWidget
->currentTabPage()->selectedItemsCount();
359 QAction
* compareFilesAction
= actionCollection()->action(QStringLiteral("compare_files"));
360 if (selectedUrlsCount
== 2) {
361 compareFilesAction
->setEnabled(isKompareInstalled());
363 compareFilesAction
->setEnabled(false);
366 Q_EMIT
selectionChanged(selection
);
369 void DolphinMainWindow::updateHistory()
371 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
372 const int index
= urlNavigator
->historyIndex();
374 QAction
* backAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Back
));
376 backAction
->setToolTip(i18nc("@info", "Go back"));
377 backAction
->setWhatsThis(i18nc("@info:whatsthis go back", "Return to the previously viewed folder."));
378 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
381 QAction
* forwardAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Forward
));
383 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
384 forwardAction
->setWhatsThis(xi18nc("@info:whatsthis go forward",
385 "This undoes a <interface>Go|Back</interface> action."));
386 forwardAction
->setEnabled(index
> 0);
390 void DolphinMainWindow::updateFilterBarAction(bool show
)
392 QAction
* showFilterBarAction
= actionCollection()->action(QStringLiteral("show_filter_bar"));
393 showFilterBarAction
->setChecked(show
);
396 void DolphinMainWindow::openNewMainWindow()
398 Dolphin::openNewWindow({m_activeViewContainer
->url()}, this);
401 void DolphinMainWindow::openNewActivatedTab()
403 m_tabWidget
->openNewActivatedTab();
406 void DolphinMainWindow::addToPlaces()
411 // If nothing is selected, act on the current dir
412 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
413 url
= m_activeViewContainer
->url();
414 name
= m_activeViewContainer
->placesText();
416 const auto dirToAdd
= m_activeViewContainer
->view()->selectedItems().first();
417 url
= dirToAdd
.url();
418 name
= dirToAdd
.name();
421 PlacesItemModel model
;
423 if (m_activeViewContainer
->isSearchModeEnabled()) {
424 icon
= QStringLiteral("folder-saved-search-symbolic");
426 icon
= KIO::iconNameForUrl(url
);
428 model
.createPlacesItem(name
, url
, icon
);
432 void DolphinMainWindow::openNewTab(const QUrl
& url
, DolphinTabWidget::TabPlacement tabPlacement
)
434 m_tabWidget
->openNewTab(url
, QUrl(), tabPlacement
);
437 void DolphinMainWindow::openNewTabAfterCurrentTab(const QUrl
& url
)
439 m_tabWidget
->openNewTab(url
, QUrl(), DolphinTabWidget::AfterCurrentTab
);
442 void DolphinMainWindow::openNewTabAfterLastTab(const QUrl
& url
)
444 m_tabWidget
->openNewTab(url
, QUrl(), DolphinTabWidget::AfterLastTab
);
447 void DolphinMainWindow::openInNewTab()
449 const KFileItemList
& list
= m_activeViewContainer
->view()->selectedItems();
450 bool tabCreated
= false;
452 for (const KFileItem
& item
: list
) {
453 const QUrl
& url
= DolphinView::openItemAsFolderUrl(item
);
454 if (!url
.isEmpty()) {
455 openNewTabAfterCurrentTab(url
);
460 // if no new tab has been created from the selection
461 // open the current directory in a new tab
463 openNewTabAfterCurrentTab(m_activeViewContainer
->url());
467 void DolphinMainWindow::openInNewWindow()
471 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
472 if (list
.isEmpty()) {
473 newWindowUrl
= m_activeViewContainer
->url();
474 } else if (list
.count() == 1) {
475 const KFileItem
& item
= list
.first();
476 newWindowUrl
= DolphinView::openItemAsFolderUrl(item
);
479 if (!newWindowUrl
.isEmpty()) {
480 Dolphin::openNewWindow({newWindowUrl
}, this);
484 void DolphinMainWindow::showTarget()
486 const auto link
= m_activeViewContainer
->view()->selectedItems().at(0);
487 const auto linkLocationDir
= QFileInfo(link
.localPath()).absoluteDir();
488 auto linkDestination
= link
.linkDest();
489 if (QFileInfo(linkDestination
).isRelative()) {
490 linkDestination
= linkLocationDir
.filePath(linkDestination
);
492 if (QFileInfo::exists(linkDestination
)) {
493 KIO::highlightInFileManager({QUrl::fromLocalFile(linkDestination
).adjusted(QUrl::StripTrailingSlash
)});
495 m_activeViewContainer
->showMessage(xi18nc("@info", "Could not access <filename>%1</filename>.", linkDestination
),
496 DolphinViewContainer::Warning
);
500 void DolphinMainWindow::showEvent(QShowEvent
* event
)
502 KXmlGuiWindow::showEvent(event
);
504 if (!event
->spontaneous()) {
505 m_activeViewContainer
->view()->setFocus();
509 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
511 // Find out if Dolphin is closed directly by the user or
512 // by the session manager because the session is closed
513 bool closedByUser
= true;
514 if (qApp
->isSavingSession()) {
515 closedByUser
= false;
518 if (m_tabWidget
->count() > 1
519 && GeneralSettings::confirmClosingMultipleTabs()
520 && !GeneralSettings::rememberOpenedTabs()
522 // Ask the user if he really wants to quit and close all tabs.
523 // Open a confirmation dialog with 3 buttons:
524 // QDialogButtonBox::Yes -> Quit
525 // QDialogButtonBox::No -> Close only the current tab
526 // QDialogButtonBox::Cancel -> do nothing
527 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
528 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
529 dialog
->setModal(true);
530 QDialogButtonBox
* buttons
= new QDialogButtonBox(QDialogButtonBox::Yes
| QDialogButtonBox::No
| QDialogButtonBox::Cancel
);
531 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KGuiItem(i18nc("@action:button 'Quit Dolphin' button", "&Quit %1", QGuiApplication::applicationDisplayName()), QIcon::fromTheme(QStringLiteral("application-exit"))));
532 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("C&lose Current Tab"), QIcon::fromTheme(QStringLiteral("tab-close"))));
533 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
534 buttons
->button(QDialogButtonBox::Yes
)->setDefault(true);
536 bool doNotAskAgainCheckboxResult
= false;
538 const auto result
= KMessageBox::createKMessageBox(dialog
,
540 QMessageBox::Warning
,
541 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
543 i18n("Do not ask again"),
544 &doNotAskAgainCheckboxResult
,
545 KMessageBox::Notify
);
547 if (doNotAskAgainCheckboxResult
) {
548 GeneralSettings::setConfirmClosingMultipleTabs(false);
552 case QDialogButtonBox::Yes
:
555 case QDialogButtonBox::No
:
556 // Close only the current tab
557 m_tabWidget
->closeTab();
565 if (m_terminalPanel
&& m_terminalPanel
->hasProgramRunning() && GeneralSettings::confirmClosingTerminalRunningProgram() && closedByUser
) {
566 // Ask if the user really wants to quit Dolphin with a program that is still running in the Terminal panel
567 // Open a confirmation dialog with 3 buttons:
568 // QDialogButtonBox::Yes -> Quit
569 // QDialogButtonBox::No -> Show Terminal Panel
570 // QDialogButtonBox::Cancel -> do nothing
571 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
572 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
573 dialog
->setModal(true);
574 auto standardButtons
= QDialogButtonBox::Yes
| QDialogButtonBox::Cancel
;
575 if (!m_terminalPanel
->isVisible()) {
576 standardButtons
|= QDialogButtonBox::No
;
578 QDialogButtonBox
*buttons
= new QDialogButtonBox(standardButtons
);
579 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KStandardGuiItem::quit());
580 if (!m_terminalPanel
->isVisible()) {
582 buttons
->button(QDialogButtonBox::No
),
583 KGuiItem(i18n("Show &Terminal Panel"), QIcon::fromTheme(QStringLiteral("dialog-scripts"))));
585 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
587 bool doNotAskAgainCheckboxResult
= false;
589 const auto result
= KMessageBox::createKMessageBox(
592 QMessageBox::Warning
,
593 i18n("The program '%1' is still running in the Terminal panel. Are you sure you want to quit?", m_terminalPanel
->runningProgramName()),
595 i18n("Do not ask again"),
596 &doNotAskAgainCheckboxResult
,
597 KMessageBox::Dangerous
);
599 if (doNotAskAgainCheckboxResult
) {
600 GeneralSettings::setConfirmClosingTerminalRunningProgram(false);
604 case QDialogButtonBox::Yes
:
607 case QDialogButtonBox::No
:
608 actionCollection()->action("show_terminal_panel")->trigger();
609 // Do not quit, ignore quit event
617 if (GeneralSettings::rememberOpenedTabs()) {
618 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
619 KConfig
*config
= KConfigGui::sessionConfig();
620 saveGlobalProperties(config
);
621 savePropertiesInternal(config
, 1);
625 GeneralSettings::setVersion(CurrentDolphinVersion
);
626 GeneralSettings::self()->save();
628 KXmlGuiWindow::closeEvent(event
);
631 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
633 m_tabWidget
->saveProperties(group
);
636 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
638 m_tabWidget
->readProperties(group
);
641 void DolphinMainWindow::updateNewMenu()
643 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
644 m_newFileMenu
->checkUpToDate();
645 m_newFileMenu
->setPopupFiles(QList
<QUrl
>() << activeViewContainer()->url());
648 void DolphinMainWindow::createDirectory()
650 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
651 m_newFileMenu
->setPopupFiles(QList
<QUrl
>() << activeViewContainer()->url());
652 m_newFileMenu
->createDirectory();
655 void DolphinMainWindow::quit()
660 void DolphinMainWindow::showErrorMessage(const QString
& message
)
662 m_activeViewContainer
->showMessage(message
, DolphinViewContainer::Error
);
665 void DolphinMainWindow::slotUndoAvailable(bool available
)
667 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
669 undoAction
->setEnabled(available
);
673 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
675 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
677 undoAction
->setText(text
);
681 void DolphinMainWindow::undo()
684 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
685 KIO::FileUndoManager::self()->undo();
688 void DolphinMainWindow::cut()
690 m_activeViewContainer
->view()->cutSelectedItemsToClipboard();
693 void DolphinMainWindow::copy()
695 m_activeViewContainer
->view()->copySelectedItemsToClipboard();
698 void DolphinMainWindow::paste()
700 m_activeViewContainer
->view()->paste();
703 void DolphinMainWindow::find()
705 m_activeViewContainer
->setSearchModeEnabled(true);
708 void DolphinMainWindow::updateSearchAction()
710 QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
711 toggleSearchAction
->setChecked(m_activeViewContainer
->isSearchModeEnabled());
714 void DolphinMainWindow::updatePasteAction()
716 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
717 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
718 pasteAction
->setEnabled(pasteInfo
.first
);
719 pasteAction
->setText(pasteInfo
.second
);
722 void DolphinMainWindow::slotDirectoryLoadingCompleted()
727 void DolphinMainWindow::slotToolBarActionMiddleClicked(QAction
*action
)
729 if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Back
))) {
731 } else if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Forward
))) {
733 } else if (action
== actionCollection()->action(QStringLiteral("go_up"))) {
735 } else if (action
== actionCollection()->action(QStringLiteral("go_home"))) {
740 void DolphinMainWindow::slotAboutToShowBackPopupMenu()
742 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
744 m_backAction
->menu()->clear();
745 for (int i
= urlNavigator
->historyIndex() + 1; i
< urlNavigator
->historySize() && entries
< MaxNumberOfNavigationentries
; ++i
, ++entries
) {
746 QAction
* action
= new QAction(urlNavigator
->locationUrl(i
).toString(QUrl::PreferLocalFile
), m_backAction
->menu());
748 m_backAction
->menu()->addAction(action
);
752 void DolphinMainWindow::slotGoBack(QAction
* action
)
754 int gotoIndex
= action
->data().value
<int>();
755 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
756 for (int i
= gotoIndex
- urlNavigator
->historyIndex(); i
> 0; --i
) {
761 void DolphinMainWindow::slotBackForwardActionMiddleClicked(QAction
* action
)
764 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
765 openNewTabAfterCurrentTab(urlNavigator
->locationUrl(action
->data().value
<int>()));
769 void DolphinMainWindow::slotAboutToShowForwardPopupMenu()
771 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
773 m_forwardAction
->menu()->clear();
774 for (int i
= urlNavigator
->historyIndex() - 1; i
>= 0 && entries
< MaxNumberOfNavigationentries
; --i
, ++entries
) {
775 QAction
* action
= new QAction(urlNavigator
->locationUrl(i
).toString(QUrl::PreferLocalFile
), m_forwardAction
->menu());
777 m_forwardAction
->menu()->addAction(action
);
781 void DolphinMainWindow::slotGoForward(QAction
* action
)
783 int gotoIndex
= action
->data().value
<int>();
784 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
785 for (int i
= urlNavigator
->historyIndex() - gotoIndex
; i
> 0; --i
) {
790 void DolphinMainWindow::selectAll()
794 // if the URL navigator is editable and focused, select the whole
795 // URL instead of all items of the view
797 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
798 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit();
799 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
800 lineEdit
->hasFocus();
802 lineEdit
->selectAll();
804 m_activeViewContainer
->view()->selectAll();
808 void DolphinMainWindow::invertSelection()
811 m_activeViewContainer
->view()->invertSelection();
814 void DolphinMainWindow::toggleSplitView()
816 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
817 tabPage
->setSplitViewEnabled(!tabPage
->splitViewEnabled());
822 void DolphinMainWindow::toggleSplitStash()
824 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
825 tabPage
->setSplitViewEnabled(false);
826 tabPage
->setSplitViewEnabled(true, QUrl("stash:/"));
829 void DolphinMainWindow::reloadView()
832 m_activeViewContainer
->reload();
833 m_activeViewContainer
->statusBar()->updateSpaceInfo();
836 void DolphinMainWindow::stopLoading()
838 m_activeViewContainer
->view()->stopLoading();
841 void DolphinMainWindow::enableStopAction()
843 actionCollection()->action(QStringLiteral("stop"))->setEnabled(true);
846 void DolphinMainWindow::disableStopAction()
848 actionCollection()->action(QStringLiteral("stop"))->setEnabled(false);
851 void DolphinMainWindow::showFilterBar()
853 m_activeViewContainer
->setFilterBarVisible(true);
856 void DolphinMainWindow::toggleEditLocation()
860 QAction
* action
= actionCollection()->action(QStringLiteral("editable_location"));
861 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
862 urlNavigator
->setUrlEditable(action
->isChecked());
865 void DolphinMainWindow::replaceLocation()
867 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
868 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit();
870 // If the text field currently has focus and everything is selected,
871 // pressing the keyboard shortcut returns the whole thing to breadcrumb mode
872 if (navigator
->isUrlEditable()
873 && lineEdit
->hasFocus()
874 && lineEdit
->selectedText() == lineEdit
->text() ) {
875 navigator
->setUrlEditable(false);
877 navigator
->setUrlEditable(true);
878 navigator
->setFocus();
879 lineEdit
->selectAll();
883 void DolphinMainWindow::togglePanelLockState()
885 const bool newLockState
= !GeneralSettings::lockPanels();
886 const auto childrenObjects
= children();
887 for (QObject
* child
: childrenObjects
) {
888 DolphinDockWidget
* dock
= qobject_cast
<DolphinDockWidget
*>(child
);
890 dock
->setLocked(newLockState
);
894 GeneralSettings::setLockPanels(newLockState
);
897 void DolphinMainWindow::slotTerminalPanelVisibilityChanged()
899 if (m_terminalPanel
->isHiddenInVisibleWindow() && m_activeViewContainer
) {
900 m_activeViewContainer
->view()->setFocus();
904 void DolphinMainWindow::goBack()
906 DolphinUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
907 urlNavigator
->goBack();
909 if (urlNavigator
->locationState().isEmpty()) {
910 // An empty location state indicates a redirection URL,
911 // which must be skipped too
912 urlNavigator
->goBack();
916 void DolphinMainWindow::goForward()
918 m_activeViewContainer
->urlNavigator()->goForward();
921 void DolphinMainWindow::goUp()
923 m_activeViewContainer
->urlNavigator()->goUp();
926 void DolphinMainWindow::goHome()
928 m_activeViewContainer
->urlNavigator()->goHome();
931 void DolphinMainWindow::goBackInNewTab()
933 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
934 const int index
= urlNavigator
->historyIndex() + 1;
935 openNewTabAfterCurrentTab(urlNavigator
->locationUrl(index
));
938 void DolphinMainWindow::goForwardInNewTab()
940 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
941 const int index
= urlNavigator
->historyIndex() - 1;
942 openNewTabAfterCurrentTab(urlNavigator
->locationUrl(index
));
945 void DolphinMainWindow::goUpInNewTab()
947 const QUrl currentUrl
= activeViewContainer()->urlNavigator()->locationUrl();
948 openNewTabAfterCurrentTab(KIO::upUrl(currentUrl
));
951 void DolphinMainWindow::goHomeInNewTab()
953 openNewTabAfterCurrentTab(Dolphin::homeUrl());
956 void DolphinMainWindow::compareFiles()
958 const KFileItemList items
= m_tabWidget
->currentTabPage()->selectedItems();
959 if (items
.count() != 2) {
960 // The action is disabled in this case, but it could have been triggered
961 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
965 QUrl urlA
= items
.at(0).url();
966 QUrl urlB
= items
.at(1).url();
968 QString
command(QStringLiteral("kompare -c \""));
969 command
.append(urlA
.toDisplayString(QUrl::PreferLocalFile
));
970 command
.append("\" \"");
971 command
.append(urlB
.toDisplayString(QUrl::PreferLocalFile
));
972 command
.append('\"');
974 KIO::CommandLauncherJob
*job
= new KIO::CommandLauncherJob(command
, this);
975 job
->setDesktopName(QStringLiteral("org.kde.kompare"));
979 void DolphinMainWindow::toggleShowMenuBar()
981 const bool visible
= menuBar()->isVisible();
982 menuBar()->setVisible(!visible
);
984 createControlButton();
986 deleteControlButton();
990 QPointer
<QAction
> DolphinMainWindow::preferredSearchTool()
992 m_searchTools
.clear();
993 KMoreToolsMenuFactory("dolphin/search-tools").fillMenuFromGroupingNames(
994 &m_searchTools
, { "files-find" }, m_activeViewContainer
->url()
996 QList
<QAction
*> actions
= m_searchTools
.actions();
997 if (actions
.isEmpty()) {
1000 QAction
* action
= actions
.first();
1001 if (action
->isSeparator()) {
1007 void DolphinMainWindow::updateOpenPreferredSearchToolAction()
1009 QAction
* openPreferredSearchTool
= actionCollection()->action(QStringLiteral("open_preferred_search_tool"));
1010 if (!openPreferredSearchTool
) {
1013 QPointer
<QAction
> tool
= preferredSearchTool();
1015 openPreferredSearchTool
->setVisible(true);
1016 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open %1", tool
->text()));
1017 openPreferredSearchTool
->setIcon(tool
->icon());
1019 openPreferredSearchTool
->setVisible(false);
1020 // still visible in Shortcuts configuration window
1021 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1022 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1026 void DolphinMainWindow::openPreferredSearchTool()
1028 QPointer
<QAction
> tool
= preferredSearchTool();
1034 void DolphinMainWindow::openTerminal()
1036 const QUrl url
= m_activeViewContainer
->url();
1038 if (url
.isLocalFile()) {
1039 KToolInvocation::invokeTerminal(QString(), url
.toLocalFile());
1043 // Not a local file, with protocol Class ":local", try stat'ing
1044 if (KProtocolInfo::protocolClass(url
.scheme()) == QLatin1String(":local")) {
1045 KIO::StatJob
*job
= KIO::mostLocalUrl(url
);
1046 KJobWidgets::setWindow(job
, this);
1047 connect(job
, &KJob::result
, this, [job
]() {
1049 if (!job
->error()) {
1050 statUrl
= job
->mostLocalUrl();
1053 KToolInvocation::invokeTerminal(QString(), statUrl
.isLocalFile() ? statUrl
.toLocalFile() : QDir::homePath());
1059 // Nothing worked, just use $HOME
1060 KToolInvocation::invokeTerminal(QString(), QDir::homePath());
1063 void DolphinMainWindow::editSettings()
1065 if (!m_settingsDialog
) {
1066 DolphinViewContainer
* container
= activeViewContainer();
1067 container
->view()->writeSettings();
1069 const QUrl url
= container
->url();
1070 DolphinSettingsDialog
* settingsDialog
= new DolphinSettingsDialog(url
, this);
1071 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, this, &DolphinMainWindow::refreshViews
);
1072 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, &DolphinUrlNavigator::slotReadSettings
);
1073 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1074 settingsDialog
->show();
1075 m_settingsDialog
= settingsDialog
;
1077 m_settingsDialog
.data()->raise();
1081 void DolphinMainWindow::handleUrl(const QUrl
& url
)
1083 delete m_lastHandleUrlOpenJob
;
1084 m_lastHandleUrlOpenJob
= nullptr;
1086 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1087 activeViewContainer()->setUrl(url
);
1089 m_lastHandleUrlOpenJob
= new KIO::OpenUrlJob(url
);
1090 m_lastHandleUrlOpenJob
->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
1091 m_lastHandleUrlOpenJob
->setRunExecutables(true);
1093 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::mimeTypeFound
, this,
1094 [this, url
](const QString
&mimetype
) {
1095 if (mimetype
== QLatin1String("inode/directory")) {
1096 // If it's a dir, we'll take it from here
1097 m_lastHandleUrlOpenJob
->kill();
1098 m_lastHandleUrlOpenJob
= nullptr;
1099 activeViewContainer()->setUrl(url
);
1103 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::result
, this, [this]() {
1104 m_lastHandleUrlOpenJob
= nullptr;
1107 m_lastHandleUrlOpenJob
->start();
1111 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1113 // trash:/ is writable but we don't want to create new items in it.
1114 // TODO: remove the trash check once https://phabricator.kde.org/T8234 is implemented
1115 newFileMenu()->setEnabled(isFolderWritable
&& m_activeViewContainer
->url().scheme() != QLatin1String("trash"));
1118 void DolphinMainWindow::openContextMenu(const QPoint
& pos
,
1119 const KFileItem
& item
,
1121 const QList
<QAction
*>& customActions
)
1123 QPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, pos
, item
, url
);
1124 contextMenu
.data()->setCustomActions(customActions
);
1125 const DolphinContextMenu::Command command
= contextMenu
.data()->open();
1128 case DolphinContextMenu::OpenParentFolder
:
1129 changeUrl(KIO::upUrl(item
.url()));
1130 m_activeViewContainer
->view()->markUrlsAsSelected({item
.url()});
1131 m_activeViewContainer
->view()->markUrlAsCurrent(item
.url());
1134 case DolphinContextMenu::OpenParentFolderInNewWindow
:
1135 Dolphin::openNewWindow({item
.url()}, this, Dolphin::OpenNewWindowFlag::Select
);
1138 case DolphinContextMenu::OpenParentFolderInNewTab
:
1139 openNewTabAfterLastTab(KIO::upUrl(item
.url()));
1142 case DolphinContextMenu::None
:
1147 // Delete the menu, unless it has been deleted in its own nested event loop already.
1149 contextMenu
->deleteLater();
1153 void DolphinMainWindow::updateControlMenu()
1155 QMenu
* menu
= qobject_cast
<QMenu
*>(sender());
1158 // All actions get cleared by QMenu::clear(). This includes the sub-menus
1159 // because 'menu' is their parent.
1162 KActionCollection
* ac
= actionCollection();
1164 menu
->addMenu(m_newFileMenu
->menu());
1165 addActionToMenu(ac
->action(QStringLiteral("file_new")), menu
);
1166 addActionToMenu(ac
->action(QStringLiteral("new_tab")), menu
);
1167 addActionToMenu(ac
->action(QStringLiteral("closed_tabs")), menu
);
1169 menu
->addSeparator();
1171 // Add "Edit" actions
1172 bool added
= addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Undo
)), menu
) |
1173 addActionToMenu(ac
->action(QString("copy_location")), menu
) |
1174 addActionToMenu(ac
->action(QStringLiteral("copy_to_inactive_split_view")), menu
) |
1175 addActionToMenu(ac
->action(QStringLiteral("move_to_inactive_split_view")), menu
) |
1176 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::SelectAll
)), menu
) |
1177 addActionToMenu(ac
->action(QStringLiteral("invert_selection")), menu
);
1180 menu
->addSeparator();
1183 // Add "View" actions
1184 if (!GeneralSettings::showZoomSlider()) {
1185 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomIn
)), menu
);
1186 addActionToMenu(ac
->action(QStringLiteral("view_zoom_reset")), menu
);
1187 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomOut
)), menu
);
1188 menu
->addSeparator();
1191 added
= addActionToMenu(ac
->action(QStringLiteral("show_preview")), menu
) |
1192 addActionToMenu(ac
->action(QStringLiteral("show_in_groups")), menu
) |
1193 addActionToMenu(ac
->action(QStringLiteral("show_hidden_files")), menu
) |
1194 addActionToMenu(ac
->action(QStringLiteral("additional_info")), menu
) |
1195 addActionToMenu(ac
->action(QStringLiteral("view_properties")), menu
);
1198 menu
->addSeparator();
1201 // Add a curated assortment of items from the "Tools" menu
1202 addActionToMenu(ac
->action(QStringLiteral("show_filter_bar")), menu
);
1203 addActionToMenu(ac
->action(QStringLiteral("open_preferred_search_tool")), menu
);
1204 addActionToMenu(ac
->action(QStringLiteral("open_terminal")), menu
);
1206 menu
->addSeparator();
1208 // Add "Show Panels" menu
1209 addActionToMenu(ac
->action(QStringLiteral("panels")), menu
);
1211 // Add "Settings" menu entries
1212 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)), menu
);
1213 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)), menu
);
1214 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Preferences
)), menu
);
1215 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)), menu
);
1218 auto helpMenu
= m_helpMenu
->menu();
1219 helpMenu
->setIcon(QIcon::fromTheme(QStringLiteral("system-help")));
1220 menu
->addMenu(helpMenu
);
1223 void DolphinMainWindow::updateToolBar()
1225 if (!menuBar()->isVisible()) {
1226 createControlButton();
1230 void DolphinMainWindow::slotControlButtonDeleted()
1232 m_controlButton
= nullptr;
1233 m_updateToolBarTimer
->start();
1236 void DolphinMainWindow::slotPlaceActivated(const QUrl
& url
)
1238 DolphinViewContainer
* view
= activeViewContainer();
1240 if (view
->url() == url
) {
1241 // We can end up here if the user clicked a device in the Places Panel
1242 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1249 void DolphinMainWindow::closedTabsCountChanged(unsigned int count
)
1251 actionCollection()->action(QStringLiteral("undo_close_tab"))->setEnabled(count
> 0);
1254 void DolphinMainWindow::activeViewChanged(DolphinViewContainer
* viewContainer
)
1256 DolphinViewContainer
* oldViewContainer
= m_activeViewContainer
;
1257 Q_ASSERT(viewContainer
);
1259 m_activeViewContainer
= viewContainer
;
1261 if (oldViewContainer
) {
1262 const QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
1263 toggleSearchAction
->disconnect(oldViewContainer
);
1265 // Disconnect all signals between the old view container (container,
1266 // view and url navigator) and main window.
1267 oldViewContainer
->disconnect(this);
1268 oldViewContainer
->view()->disconnect(this);
1269 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
1270 (actionCollection()->action(QStringLiteral("url_navigators")));
1271 navigators
->primaryUrlNavigator()->disconnect(this);
1272 if (auto secondaryUrlNavigator
= navigators
->secondaryUrlNavigator()) {
1273 secondaryUrlNavigator
->disconnect(this);
1276 // except the requestItemInfo so that on hover the information panel can still be updated
1277 connect(oldViewContainer
->view(), &DolphinView::requestItemInfo
,
1278 this, &DolphinMainWindow::requestItemInfo
);
1281 connectViewSignals(viewContainer
);
1283 m_actionHandler
->setCurrentView(viewContainer
->view());
1286 updateFileAndEditActions();
1287 updatePasteAction();
1288 updateViewActions();
1290 updateSearchAction();
1292 const QUrl url
= viewContainer
->url();
1293 Q_EMIT
urlChanged(url
);
1296 void DolphinMainWindow::tabCountChanged(int count
)
1298 const bool enableTabActions
= (count
> 1);
1299 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1300 actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i
))->setEnabled(enableTabActions
);
1302 actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions
);
1303 actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions
);
1304 actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions
);
1307 void DolphinMainWindow::updateWindowTitle()
1309 const QString newTitle
= m_activeViewContainer
->captionWindowTitle();
1310 if (windowTitle() != newTitle
) {
1311 setWindowTitle(newTitle
);
1315 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString
& mountPath
)
1317 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1318 setViewsToHomeIfMountPathOpen(mountPath
);
1321 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectory().startsWith(mountPath
)) {
1322 m_tearDownFromPlacesRequested
= true;
1323 m_terminalPanel
->goHome();
1324 // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
1326 m_placesPanel
->proceedWithTearDown();
1330 void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString
& mountPath
)
1332 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1333 setViewsToHomeIfMountPathOpen(mountPath
);
1336 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectory().startsWith(mountPath
)) {
1337 m_tearDownFromPlacesRequested
= false;
1338 m_terminalPanel
->goHome();
1342 void DolphinMainWindow::setViewsToHomeIfMountPathOpen(const QString
& mountPath
)
1344 const QVector
<DolphinViewContainer
*> theViewContainers
= viewContainers();
1345 for (DolphinViewContainer
*viewContainer
: theViewContainers
) {
1346 if (viewContainer
&& viewContainer
->url().toLocalFile().startsWith(mountPath
)) {
1347 viewContainer
->setUrl(QUrl::fromLocalFile(QDir::homePath()));
1350 disconnect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, nullptr, nullptr);
1353 void DolphinMainWindow::setupActions()
1355 // setup 'File' menu
1356 m_newFileMenu
= new DolphinNewFileMenu(actionCollection(), this);
1357 QMenu
* menu
= m_newFileMenu
->menu();
1358 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1359 menu
->setIcon(QIcon::fromTheme(QStringLiteral("document-new")));
1360 m_newFileMenu
->setDelayed(false);
1361 connect(menu
, &QMenu::aboutToShow
,
1362 this, &DolphinMainWindow::updateNewMenu
);
1364 QAction
* newWindow
= KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow
, actionCollection());
1365 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1366 newWindow
->setToolTip(i18nc("@info", "Open a new Dolphin window"));
1367 newWindow
->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1368 "window just like this one with the current location and view."
1369 "<nl/>You can drag and drop items between windows."));
1370 newWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1372 QAction
* newTab
= actionCollection()->addAction(QStringLiteral("new_tab"));
1373 newTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1374 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1375 newTab
->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1376 "<emphasis>Tab</emphasis> with the current location and view.<nl/>"
1377 "A tab is an additional view within this window. "
1378 "You can drag and drop items between tabs."));
1379 actionCollection()->setDefaultShortcuts(newTab
, {Qt::CTRL
+ Qt::Key_T
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_N
});
1380 connect(newTab
, &QAction::triggered
, this, &DolphinMainWindow::openNewActivatedTab
);
1382 QAction
* addToPlaces
= actionCollection()->addAction(QStringLiteral("add_to_places"));
1383 addToPlaces
->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new")));
1384 addToPlaces
->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places"));
1385 addToPlaces
->setWhatsThis(xi18nc("@info:whatsthis", "This adds the selected folder "
1386 "to the Places panel."));
1387 connect(addToPlaces
, &QAction::triggered
, this, &DolphinMainWindow::addToPlaces
);
1389 QAction
* closeTab
= KStandardAction::close(m_tabWidget
, QOverload
<>::of(&DolphinTabWidget::closeTab
), actionCollection());
1390 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1391 closeTab
->setWhatsThis(i18nc("@info:whatsthis", "This closes the "
1392 "currently viewed tab. If no more tabs are left this window "
1393 "will close instead."));
1395 QAction
* quitAction
= KStandardAction::quit(this, &DolphinMainWindow::quit
, actionCollection());
1396 quitAction
->setWhatsThis(i18nc("@info:whatsthis quit", "This closes this window."));
1398 // setup 'Edit' menu
1399 KStandardAction::undo(this,
1400 &DolphinMainWindow::undo
,
1401 actionCollection());
1403 // i18n: This will be the last paragraph for the whatsthis for all three:
1404 // Cut, Copy and Paste
1405 const QString cutCopyPastePara
= xi18nc("@info:whatsthis", "<para><emphasis>Cut, "
1406 "Copy</emphasis> and <emphasis>Paste</emphasis> work between many "
1407 "applications and are among the most used commands. That's why their "
1408 "<emphasis>keyboard shortcuts</emphasis> are prominently placed right "
1409 "next to each other on the keyboard: <shortcut>Ctrl+X</shortcut>, "
1410 "<shortcut>Ctrl+C</shortcut> and <shortcut>Ctrl+V</shortcut>.</para>");
1411 QAction
* cutAction
= KStandardAction::cut(this, &DolphinMainWindow::cut
, actionCollection());
1412 cutAction
->setWhatsThis(xi18nc("@info:whatsthis cut", "This copies the items "
1413 "in your current selection to the <emphasis>clipboard</emphasis>.<nl/>"
1414 "Use the <emphasis>Paste</emphasis> action afterwards to copy them from "
1415 "the clipboard to a new location. The items will be removed from their "
1416 "initial location.") + cutCopyPastePara
);
1417 QAction
* copyAction
= KStandardAction::copy(this, &DolphinMainWindow::copy
, actionCollection());
1418 copyAction
->setWhatsThis(xi18nc("@info:whatsthis copy", "This copies the "
1419 "items in your current selection to the <emphasis>clipboard</emphasis>."
1420 "<nl/>Use the <emphasis>Paste</emphasis> action afterwards to copy them "
1421 "from the clipboard to a new location.") + cutCopyPastePara
);
1422 QAction
* paste
= KStandardAction::paste(this, &DolphinMainWindow::paste
, actionCollection());
1423 // The text of the paste-action is modified dynamically by Dolphin
1424 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1425 // due to the long text, the text "Paste" is used:
1426 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1427 paste
->setWhatsThis(xi18nc("@info:whatsthis paste", "This copies the items from "
1428 "your <emphasis>clipboard</emphasis> to the currently viewed folder.<nl/>"
1429 "If the items were added to the clipboard by the <emphasis>Cut</emphasis> "
1430 "action they are removed from their old location.") + cutCopyPastePara
);
1432 QAction
* copyToOtherViewAction
= actionCollection()->addAction(QStringLiteral("copy_to_inactive_split_view"));
1433 copyToOtherViewAction
->setText(i18nc("@action:inmenu", "Copy to Inactive Split View"));
1434 copyToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Copy", "This copies the selected items from "
1435 "the <emphasis>active</emphasis> view to the inactive split view."));
1436 copyToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
1437 copyToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Copy to Inactive Split View"));
1438 actionCollection()->setDefaultShortcut(copyToOtherViewAction
, Qt::SHIFT
+ Qt::Key_F5
);
1439 connect(copyToOtherViewAction
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::copyToInactiveSplitView
);
1441 QAction
* moveToOtherViewAction
= actionCollection()->addAction(QStringLiteral("move_to_inactive_split_view"));
1442 moveToOtherViewAction
->setText(i18nc("@action:inmenu", "Move to Inactive Split View"));
1443 moveToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Move", "This moves the selected items from "
1444 "the <emphasis>active</emphasis> view to the inactive split view."));
1445 moveToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-cut")));
1446 moveToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Move to Inactive Split View"));
1447 actionCollection()->setDefaultShortcut(moveToOtherViewAction
, Qt::SHIFT
+ Qt::Key_F6
);
1448 connect(moveToOtherViewAction
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::moveToInactiveSplitView
);
1450 QAction
*searchAction
= KStandardAction::find(this, &DolphinMainWindow::find
, actionCollection());
1451 searchAction
->setText(i18n("Search..."));
1452 searchAction
->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
1453 searchAction
->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This helps you "
1454 "find files and folders by opening a <emphasis>find bar</emphasis>. "
1455 "There you can enter search terms and specify settings to find the "
1456 "objects you are looking for.</para><para>Use this help again on "
1457 "the find bar so we can have a look at it while the settings are "
1458 "explained.</para>"));
1460 // toggle_search acts as a copy of the main searchAction to be used mainly
1461 // in the toolbar, with no default shortcut attached, to avoid messing with
1462 // existing workflows (search bar always open and Ctrl-F to focus)
1463 QAction
*toggleSearchAction
= actionCollection()->addAction(QStringLiteral("toggle_search"));
1464 toggleSearchAction
->setText(i18nc("@action:inmenu", "Toggle Search Bar"));
1465 toggleSearchAction
->setIconText(i18nc("@action:intoolbar", "Search"));
1466 toggleSearchAction
->setIcon(searchAction
->icon());
1467 toggleSearchAction
->setToolTip(searchAction
->toolTip());
1468 toggleSearchAction
->setWhatsThis(searchAction
->whatsThis());
1469 toggleSearchAction
->setCheckable(true);
1471 QAction
* selectAllAction
= KStandardAction::selectAll(this, &DolphinMainWindow::selectAll
, actionCollection());
1472 selectAllAction
->setWhatsThis(xi18nc("@info:whatsthis", "This selects all "
1473 "files and folders in the current location."));
1475 QAction
* invertSelection
= actionCollection()->addAction(QStringLiteral("invert_selection"));
1476 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1477 invertSelection
->setWhatsThis(xi18nc("@info:whatsthis invert", "This selects all "
1478 "objects that you have currently <emphasis>not</emphasis> selected instead."));
1479 invertSelection
->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert")));
1480 actionCollection()->setDefaultShortcut(invertSelection
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_A
);
1481 connect(invertSelection
, &QAction::triggered
, this, &DolphinMainWindow::invertSelection
);
1483 // setup 'View' menu
1484 // (note that most of it is set up in DolphinViewActionHandler)
1486 QAction
* split
= actionCollection()->addAction(QStringLiteral("split_view"));
1487 split
->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This splits "
1488 "the folder view below into two autonomous views.</para><para>This "
1489 "way you can see two locations at once and move items between them "
1490 "quickly.</para>Click this again afterwards to recombine the views."));
1491 actionCollection()->setDefaultShortcut(split
, Qt::Key_F3
);
1492 connect(split
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitView
);
1494 QAction
* stashSplit
= actionCollection()->addAction(QStringLiteral("split_stash"));
1495 actionCollection()->setDefaultShortcut(stashSplit
, Qt::CTRL
+ Qt::Key_S
);
1496 stashSplit
->setText(i18nc("@action:intoolbar Stash", "Stash"));
1497 stashSplit
->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
1498 stashSplit
->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
1499 stashSplit
->setCheckable(false);
1500 stashSplit
->setVisible(KProtocolInfo::isKnownProtocol("stash"));
1501 connect(stashSplit
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitStash
);
1503 KStandardAction::redisplay(this, &DolphinMainWindow::reloadView
, actionCollection());
1505 QAction
* stop
= actionCollection()->addAction(QStringLiteral("stop"));
1506 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1507 stop
->setToolTip(i18nc("@info", "Stop loading"));
1508 stop
->setWhatsThis(i18nc("@info", "This stops the loading of the contents of the current folder."));
1509 stop
->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
1510 connect(stop
, &QAction::triggered
, this, &DolphinMainWindow::stopLoading
);
1512 KToggleAction
* editableLocation
= actionCollection()->add
<KToggleAction
>(QStringLiteral("editable_location"));
1513 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1514 editableLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1515 "This toggles the <emphasis>Location Bar</emphasis> to be "
1516 "editable so you can directly enter a location you want to go to.<nl/>"
1517 "You can also switch to editing by clicking to the right of the "
1518 "location and switch back by confirming the edited location."));
1519 actionCollection()->setDefaultShortcut(editableLocation
, Qt::Key_F6
);
1520 connect(editableLocation
, &KToggleAction::triggered
, this, &DolphinMainWindow::toggleEditLocation
);
1522 QAction
* replaceLocation
= actionCollection()->addAction(QStringLiteral("replace_location"));
1523 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1524 // i18n: "enter" is used both in the meaning of "writing" and "going to" a new location here.
1525 // Both meanings are useful but not necessary to understand the use of "Replace Location".
1526 // So you might want to be more verbose in your language to convey the meaning but it's up to you.
1527 replaceLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1528 "This switches to editing the location and selects it "
1529 "so you can quickly enter a different location."));
1530 actionCollection()->setDefaultShortcut(replaceLocation
, Qt::CTRL
+ Qt::Key_L
);
1531 connect(replaceLocation
, &QAction::triggered
, this, &DolphinMainWindow::replaceLocation
);
1535 QScopedPointer
<QAction
> backAction(KStandardAction::back(nullptr, nullptr, nullptr));
1536 m_backAction
= new KToolBarPopupAction(backAction
->icon(), backAction
->text(), actionCollection());
1537 m_backAction
->setObjectName(backAction
->objectName());
1538 m_backAction
->setShortcuts(backAction
->shortcuts());
1540 m_backAction
->setDelayed(true);
1541 m_backAction
->setStickyMenu(false);
1542 connect(m_backAction
, &QAction::triggered
, this, &DolphinMainWindow::goBack
);
1543 connect(m_backAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowBackPopupMenu
);
1544 connect(m_backAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoBack
);
1545 actionCollection()->addAction(m_backAction
->objectName(), m_backAction
);
1547 auto backShortcuts
= m_backAction
->shortcuts();
1548 backShortcuts
.append(QKeySequence(Qt::Key_Backspace
));
1549 actionCollection()->setDefaultShortcuts(m_backAction
, backShortcuts
);
1551 DolphinRecentTabsMenu
* recentTabsMenu
= new DolphinRecentTabsMenu(this);
1552 actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu
);
1553 connect(m_tabWidget
, &DolphinTabWidget::rememberClosedTab
,
1554 recentTabsMenu
, &DolphinRecentTabsMenu::rememberClosedTab
);
1555 connect(recentTabsMenu
, &DolphinRecentTabsMenu::restoreClosedTab
,
1556 m_tabWidget
, &DolphinTabWidget::restoreClosedTab
);
1557 connect(recentTabsMenu
, &DolphinRecentTabsMenu::closedTabsCountChanged
,
1558 this, &DolphinMainWindow::closedTabsCountChanged
);
1560 QAction
* undoCloseTab
= actionCollection()->addAction(QStringLiteral("undo_close_tab"));
1561 undoCloseTab
->setText(i18nc("@action:inmenu File", "Undo close tab"));
1562 undoCloseTab
->setWhatsThis(i18nc("@info:whatsthis undo close tab",
1563 "This returns you to the previously closed tab."));
1564 actionCollection()->setDefaultShortcut(undoCloseTab
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_T
);
1565 undoCloseTab
->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
1566 undoCloseTab
->setEnabled(false);
1567 connect(undoCloseTab
, &QAction::triggered
, recentTabsMenu
, &DolphinRecentTabsMenu::undoCloseTab
);
1569 auto undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
1570 undoAction
->setWhatsThis(xi18nc("@info:whatsthis", "This undoes "
1571 "the last change you made to files or folders.<nl/>"
1572 "Such changes include <interface>creating, renaming</interface> "
1573 "and <interface>moving</interface> them to a different location "
1574 "or to the <filename>Trash</filename>. <nl/>Changes that can't "
1575 "be undone will ask for your confirmation."));
1576 undoAction
->setEnabled(false); // undo should be disabled by default
1579 QScopedPointer
<QAction
> forwardAction(KStandardAction::forward(nullptr, nullptr, nullptr));
1580 m_forwardAction
= new KToolBarPopupAction(forwardAction
->icon(), forwardAction
->text(), actionCollection());
1581 m_forwardAction
->setObjectName(forwardAction
->objectName());
1582 m_forwardAction
->setShortcuts(forwardAction
->shortcuts());
1584 m_forwardAction
->setDelayed(true);
1585 m_forwardAction
->setStickyMenu(false);
1586 connect(m_forwardAction
, &QAction::triggered
, this, &DolphinMainWindow::goForward
);
1587 connect(m_forwardAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowForwardPopupMenu
);
1588 connect(m_forwardAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoForward
);
1589 actionCollection()->addAction(m_forwardAction
->objectName(), m_forwardAction
);
1590 actionCollection()->setDefaultShortcuts(m_forwardAction
, m_forwardAction
->shortcuts());
1592 // enable middle-click to open in a new tab
1593 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
1594 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotBackForwardActionMiddleClicked
);
1595 m_backAction
->menu()->installEventFilter(middleClickEventFilter
);
1596 m_forwardAction
->menu()->installEventFilter(middleClickEventFilter
);
1597 KStandardAction::up(this, &DolphinMainWindow::goUp
, actionCollection());
1598 QAction
* homeAction
= KStandardAction::home(this, &DolphinMainWindow::goHome
, actionCollection());
1599 homeAction
->setWhatsThis(xi18nc("@info:whatsthis", "Go to your "
1600 "<filename>Home</filename> folder.<nl/>Every user account "
1601 "has their own <filename>Home</filename> that contains their data "
1602 "including folders that contain personal application data."));
1604 // setup 'Tools' menu
1605 QAction
* showFilterBar
= actionCollection()->addAction(QStringLiteral("show_filter_bar"));
1606 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1607 showFilterBar
->setWhatsThis(xi18nc("@info:whatsthis", "This opens the "
1608 "<emphasis>Filter Bar</emphasis> at the bottom of the window.<nl/> "
1609 "There you can enter a text to filter the files and folders currently displayed. "
1610 "Only those that contain the text in their name will be kept in view."));
1611 showFilterBar
->setIcon(QIcon::fromTheme(QStringLiteral("view-filter")));
1612 actionCollection()->setDefaultShortcuts(showFilterBar
, {Qt::CTRL
+ Qt::Key_I
, Qt::Key_Slash
});
1613 connect(showFilterBar
, &QAction::triggered
, this, &DolphinMainWindow::showFilterBar
);
1615 QAction
* compareFiles
= actionCollection()->addAction(QStringLiteral("compare_files"));
1616 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1617 compareFiles
->setIcon(QIcon::fromTheme(QStringLiteral("kompare")));
1618 compareFiles
->setEnabled(false);
1619 connect(compareFiles
, &QAction::triggered
, this, &DolphinMainWindow::compareFiles
);
1621 QAction
* openPreferredSearchTool
= actionCollection()->addAction(QStringLiteral("open_preferred_search_tool"));
1622 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1623 openPreferredSearchTool
->setWhatsThis(xi18nc("@info:whatsthis",
1624 "<para>This opens a preferred search tool for the viewed location.</para>"
1625 "<para>Use <emphasis>More Search Tools</emphasis> menu to configure it.</para>"));
1626 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1627 actionCollection()->setDefaultShortcut(openPreferredSearchTool
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_F
);
1628 connect(openPreferredSearchTool
, &QAction::triggered
, this, &DolphinMainWindow::openPreferredSearchTool
);
1630 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1631 QAction
* openTerminal
= actionCollection()->addAction(QStringLiteral("open_terminal"));
1632 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1633 openTerminal
->setWhatsThis(xi18nc("@info:whatsthis",
1634 "<para>This opens a <emphasis>terminal</emphasis> application for the viewed location.</para>"
1635 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1636 openTerminal
->setIcon(QIcon::fromTheme(QStringLiteral("dialog-scripts")));
1637 actionCollection()->setDefaultShortcut(openTerminal
, Qt::SHIFT
+ Qt::Key_F4
);
1638 connect(openTerminal
, &QAction::triggered
, this, &DolphinMainWindow::openTerminal
);
1640 #ifdef HAVE_TERMINAL
1641 QAction
* focusTerminalPanel
= actionCollection()->addAction(QStringLiteral("focus_terminal_panel"));
1642 focusTerminalPanel
->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
1643 focusTerminalPanel
->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
1644 actionCollection()->setDefaultShortcut(focusTerminalPanel
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_F4
);
1645 connect(focusTerminalPanel
, &QAction::triggered
, this, &DolphinMainWindow::focusTerminalPanel
);
1649 // setup 'Bookmarks' menu
1650 KActionMenu
*bookmarkMenu
= new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this);
1651 bookmarkMenu
->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks")));
1652 // Make the toolbar button version work properly on click
1653 bookmarkMenu
->setDelayed(false);
1654 m_bookmarkHandler
= new DolphinBookmarkHandler(this, actionCollection(), bookmarkMenu
->menu(), this);
1655 actionCollection()->addAction(QStringLiteral("bookmarks"), bookmarkMenu
);
1657 // setup 'Settings' menu
1658 KToggleAction
* showMenuBar
= KStandardAction::showMenubar(nullptr, nullptr, actionCollection());
1659 showMenuBar
->setWhatsThis(xi18nc("@info:whatsthis",
1660 "This switches between having a <emphasis>Menubar</emphasis> "
1661 "and having a <interface>Control</interface> button. Both "
1662 "contain mostly the same commands and configuration options."));
1663 connect(showMenuBar
, &KToggleAction::triggered
, // Fixes #286822
1664 this, &DolphinMainWindow::toggleShowMenuBar
, Qt::QueuedConnection
);
1665 KStandardAction::preferences(this, &DolphinMainWindow::editSettings
, actionCollection());
1667 // setup 'Help' menu for the m_controlButton. The other one is set up in the base class.
1668 m_helpMenu
= new KHelpMenu(nullptr);
1669 m_helpMenu
->menu()->installEventFilter(this);
1670 // remove duplicate shortcuts
1671 m_helpMenu
->action(KHelpMenu::menuHelpContents
)->setShortcut(QKeySequence());
1672 m_helpMenu
->action(KHelpMenu::menuWhatsThis
)->setShortcut(QKeySequence());
1674 // not in menu actions
1675 QList
<QKeySequence
> nextTabKeys
= KStandardShortcut::tabNext();
1676 nextTabKeys
.append(QKeySequence(Qt::CTRL
+ Qt::Key_Tab
));
1678 QList
<QKeySequence
> prevTabKeys
= KStandardShortcut::tabPrev();
1679 prevTabKeys
.append(QKeySequence(Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_Tab
));
1681 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1682 QAction
* activateTab
= actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i
));
1683 activateTab
->setText(i18nc("@action:inmenu", "Activate Tab %1", i
+ 1));
1684 activateTab
->setEnabled(false);
1685 connect(activateTab
, &QAction::triggered
, this, [this, i
]() { m_tabWidget
->activateTab(i
); });
1687 // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts
1689 actionCollection()->setDefaultShortcut(activateTab
, QStringLiteral("Alt+%1").arg(i
+ 1));
1693 QAction
* activateLastTab
= actionCollection()->addAction(QStringLiteral("activate_last_tab"));
1694 activateLastTab
->setText(i18nc("@action:inmenu", "Activate Last Tab"));
1695 activateLastTab
->setEnabled(false);
1696 connect(activateLastTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateLastTab
);
1697 actionCollection()->setDefaultShortcut(activateLastTab
, Qt::ALT
+ Qt::Key_0
);
1699 QAction
* activateNextTab
= actionCollection()->addAction(QStringLiteral("activate_next_tab"));
1700 activateNextTab
->setIconText(i18nc("@action:inmenu", "Next Tab"));
1701 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1702 activateNextTab
->setEnabled(false);
1703 connect(activateNextTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateNextTab
);
1704 actionCollection()->setDefaultShortcuts(activateNextTab
, nextTabKeys
);
1706 QAction
* activatePrevTab
= actionCollection()->addAction(QStringLiteral("activate_prev_tab"));
1707 activatePrevTab
->setIconText(i18nc("@action:inmenu", "Previous Tab"));
1708 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1709 activatePrevTab
->setEnabled(false);
1710 connect(activatePrevTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activatePrevTab
);
1711 actionCollection()->setDefaultShortcuts(activatePrevTab
, prevTabKeys
);
1714 QAction
* showTarget
= actionCollection()->addAction(QStringLiteral("show_target"));
1715 showTarget
->setText(i18nc("@action:inmenu", "Show Target"));
1716 showTarget
->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
1717 showTarget
->setEnabled(false);
1718 connect(showTarget
, &QAction::triggered
, this, &DolphinMainWindow::showTarget
);
1720 QAction
* openInNewTab
= actionCollection()->addAction(QStringLiteral("open_in_new_tab"));
1721 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1722 openInNewTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1723 connect(openInNewTab
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
1725 QAction
* openInNewTabs
= actionCollection()->addAction(QStringLiteral("open_in_new_tabs"));
1726 openInNewTabs
->setText(i18nc("@action:inmenu", "Open in New Tabs"));
1727 openInNewTabs
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1728 connect(openInNewTabs
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
1730 QAction
* openInNewWindow
= actionCollection()->addAction(QStringLiteral("open_in_new_window"));
1731 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1732 openInNewWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1733 connect(openInNewWindow
, &QAction::triggered
, this, &DolphinMainWindow::openInNewWindow
);
1736 void DolphinMainWindow::setupDockWidgets()
1738 const bool lock
= GeneralSettings::lockPanels();
1740 KDualAction
* lockLayoutAction
= actionCollection()->add
<KDualAction
>(QStringLiteral("lock_panels"));
1741 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1742 lockLayoutAction
->setActiveIcon(QIcon::fromTheme(QStringLiteral("object-unlocked")));
1743 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1744 lockLayoutAction
->setInactiveIcon(QIcon::fromTheme(QStringLiteral("object-locked")));
1745 lockLayoutAction
->setWhatsThis(xi18nc("@info:whatsthis", "This "
1746 "switches between having panels <emphasis>locked</emphasis> or "
1747 "<emphasis>unlocked</emphasis>.<nl/>Unlocked panels can be "
1748 "dragged to the other side of the window and have a close "
1749 "button.<nl/>Locked panels are embedded more cleanly."));
1750 lockLayoutAction
->setActive(lock
);
1751 connect(lockLayoutAction
, &KDualAction::triggered
, this, &DolphinMainWindow::togglePanelLockState
);
1753 // Setup "Information"
1754 DolphinDockWidget
* infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
1755 infoDock
->setLocked(lock
);
1756 infoDock
->setObjectName(QStringLiteral("infoDock"));
1757 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1760 InformationPanel
* infoPanel
= new InformationPanel(infoDock
);
1761 infoPanel
->setCustomContextMenuActions({lockLayoutAction
});
1762 connect(infoPanel
, &InformationPanel::urlActivated
, this, &DolphinMainWindow::handleUrl
);
1763 infoDock
->setWidget(infoPanel
);
1765 QAction
* infoAction
= infoDock
->toggleViewAction();
1766 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-information")), Qt::Key_F11
, infoAction
, QStringLiteral("show_information_panel"));
1768 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1769 connect(this, &DolphinMainWindow::urlChanged
,
1770 infoPanel
, &InformationPanel::setUrl
);
1771 connect(this, &DolphinMainWindow::selectionChanged
,
1772 infoPanel
, &InformationPanel::setSelection
);
1773 connect(this, &DolphinMainWindow::requestItemInfo
,
1774 infoPanel
, &InformationPanel::requestDelayedItemInfo
);
1777 // i18n: This is the last paragraph for the "What's This"-texts of all four panels.
1778 const QString panelWhatsThis
= xi18nc("@info:whatsthis", "<para>To show or "
1779 "hide panels like this go to <interface>Control|Panels</interface> "
1780 "or <interface>View|Panels</interface>.</para>");
1782 actionCollection()->action(QStringLiteral("show_information_panel"))
1783 ->setWhatsThis(xi18nc("@info:whatsthis", "<para> This toggles the "
1784 "<emphasis>information</emphasis> panel at the right side of the "
1785 "window.</para><para>The panel provides in-depth information "
1786 "about the items your mouse is hovering over or about the selected "
1787 "items. Otherwise it informs you about the currently viewed folder.<nl/>"
1788 "For single items a preview of their contents is provided.</para>"));
1790 infoDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
1791 "provides in-depth information about the items your mouse is "
1792 "hovering over or about the selected items. Otherwise it informs "
1793 "you about the currently viewed folder.<nl/>For single items a "
1794 "preview of their contents is provided.</para><para>You can configure "
1795 "which and how details are given here by right-clicking.</para>") + panelWhatsThis
);
1798 DolphinDockWidget
* foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
1799 foldersDock
->setLocked(lock
);
1800 foldersDock
->setObjectName(QStringLiteral("foldersDock"));
1801 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1802 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1803 foldersPanel
->setCustomContextMenuActions({lockLayoutAction
});
1804 foldersDock
->setWidget(foldersPanel
);
1806 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1807 createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7
, foldersAction
, QStringLiteral("show_folders_panel"));
1809 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1810 connect(this, &DolphinMainWindow::urlChanged
,
1811 foldersPanel
, &FoldersPanel::setUrl
);
1812 connect(foldersPanel
, &FoldersPanel::folderActivated
,
1813 this, &DolphinMainWindow::changeUrl
);
1814 connect(foldersPanel
, &FoldersPanel::folderMiddleClicked
,
1815 this, &DolphinMainWindow::openNewTabAfterCurrentTab
);
1816 connect(foldersPanel
, &FoldersPanel::errorMessage
,
1817 this, &DolphinMainWindow::showErrorMessage
);
1819 actionCollection()->action(QStringLiteral("show_folders_panel"))
1820 ->setWhatsThis(xi18nc("@info:whatsthis", "This toggles the "
1821 "<emphasis>folders</emphasis> panel at the left side of the window."
1822 "<nl/><nl/>It shows the folders of the <emphasis>file system"
1823 "</emphasis> in a <emphasis>tree view</emphasis>."));
1824 foldersDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
1825 "shows the folders of the <emphasis>file system</emphasis> in a "
1826 "<emphasis>tree view</emphasis>.</para><para>Click a folder to go "
1827 "there. Click the arrow to the left of a folder to see its subfolders. "
1828 "This allows quick switching between any folders.</para>") + panelWhatsThis
);
1831 #ifdef HAVE_TERMINAL
1832 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1833 DolphinDockWidget
* terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1834 terminalDock
->setLocked(lock
);
1835 terminalDock
->setObjectName(QStringLiteral("terminalDock"));
1836 m_terminalPanel
= new TerminalPanel(terminalDock
);
1837 m_terminalPanel
->setCustomContextMenuActions({lockLayoutAction
});
1838 terminalDock
->setWidget(m_terminalPanel
);
1840 connect(m_terminalPanel
, &TerminalPanel::hideTerminalPanel
, terminalDock
, &DolphinDockWidget::hide
);
1841 connect(m_terminalPanel
, &TerminalPanel::changeUrl
, this, &DolphinMainWindow::slotTerminalDirectoryChanged
);
1842 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
,
1843 m_terminalPanel
, &TerminalPanel::dockVisibilityChanged
);
1844 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
,
1845 this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged
);
1847 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1848 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4
, terminalAction
, QStringLiteral("show_terminal_panel"));
1850 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1851 connect(this, &DolphinMainWindow::urlChanged
,
1852 m_terminalPanel
, &TerminalPanel::setUrl
);
1854 if (GeneralSettings::version() < 200) {
1855 terminalDock
->hide();
1858 actionCollection()->action(QStringLiteral("show_terminal_panel"))
1859 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
1860 "<emphasis>terminal</emphasis> panel at the bottom of the window."
1861 "<nl/>The location in the terminal will always match the folder "
1862 "view so you can navigate using either.</para><para>The terminal "
1863 "panel is not needed for basic computer usage but can be useful "
1864 "for advanced tasks. To learn more about terminals use the help "
1865 "in a standalone terminal application like Konsole.</para>"));
1866 terminalDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is "
1867 "the <emphasis>terminal</emphasis> panel. It behaves like a "
1868 "normal terminal but will match the location of the folder view "
1869 "so you can navigate using either.</para><para>The terminal panel "
1870 "is not needed for basic computer usage but can be useful for "
1871 "advanced tasks. To learn more about terminals use the help in a "
1872 "standalone terminal application like Konsole.</para>") + panelWhatsThis
);
1876 if (GeneralSettings::version() < 200) {
1878 foldersDock
->hide();
1882 DolphinDockWidget
* placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
1883 placesDock
->setLocked(lock
);
1884 placesDock
->setObjectName(QStringLiteral("placesDock"));
1885 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1887 m_placesPanel
= new PlacesPanel(placesDock
);
1888 m_placesPanel
->setCustomContextMenuActions({lockLayoutAction
});
1889 placesDock
->setWidget(m_placesPanel
);
1891 QAction
*placesAction
= placesDock
->toggleViewAction();
1892 createPanelAction(QIcon::fromTheme(QStringLiteral("bookmarks")), Qt::Key_F9
, placesAction
, QStringLiteral("show_places_panel"));
1894 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1895 connect(m_placesPanel
, &PlacesPanel::placeActivated
,
1896 this, &DolphinMainWindow::slotPlaceActivated
);
1897 connect(m_placesPanel
, &PlacesPanel::placeMiddleClicked
,
1898 this, &DolphinMainWindow::openNewTabAfterCurrentTab
);
1899 connect(m_placesPanel
, &PlacesPanel::errorMessage
,
1900 this, &DolphinMainWindow::showErrorMessage
);
1901 connect(this, &DolphinMainWindow::urlChanged
,
1902 m_placesPanel
, &PlacesPanel::setUrl
);
1903 connect(placesDock
, &DolphinDockWidget::visibilityChanged
,
1904 &DolphinUrlNavigator::slotPlacesPanelVisibilityChanged
);
1905 connect(this, &DolphinMainWindow::settingsChanged
,
1906 m_placesPanel
, &PlacesPanel::readSettings
);
1907 connect(m_placesPanel
, &PlacesPanel::storageTearDownRequested
,
1908 this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested
);
1909 connect(m_placesPanel
, &PlacesPanel::storageTearDownExternallyRequested
,
1910 this, &DolphinMainWindow::slotStorageTearDownExternallyRequested
);
1911 DolphinUrlNavigator::slotPlacesPanelVisibilityChanged(m_placesPanel
->isVisible());
1913 auto actionShowAllPlaces
= new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this);
1914 actionShowAllPlaces
->setCheckable(true);
1915 actionShowAllPlaces
->setDisabled(true);
1916 actionShowAllPlaces
->setWhatsThis(i18nc("@info:whatsthis", "This displays "
1917 "all places in the places panel that have been hidden. They will "
1918 "appear semi-transparent unless you uncheck their hide property."));
1920 connect(actionShowAllPlaces
, &QAction::triggered
, this, [actionShowAllPlaces
, this](bool checked
){
1921 actionShowAllPlaces
->setIcon(QIcon::fromTheme(checked
? QStringLiteral("view-visible") : QStringLiteral("view-hidden")));
1922 m_placesPanel
->showHiddenEntries(checked
);
1925 connect(m_placesPanel
, &PlacesPanel::showHiddenEntriesChanged
, this, [actionShowAllPlaces
] (bool checked
){
1926 actionShowAllPlaces
->setChecked(checked
);
1927 actionShowAllPlaces
->setIcon(QIcon::fromTheme(checked
? QStringLiteral("view-visible") : QStringLiteral("view-hidden")));
1930 actionCollection()->action(QStringLiteral("show_places_panel"))
1931 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
1932 "<emphasis>places</emphasis> panel at the left side of the window."
1933 "</para><para>It allows you to go to locations you have "
1934 "bookmarked and to access disk or media attached to the computer "
1935 "or to the network. It also contains sections to find recently "
1936 "saved files or files of a certain type.</para>"));
1937 placesDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
1938 "<emphasis>Places</emphasis> panel. It allows you to go to locations "
1939 "you have bookmarked and to access disk or media attached to the "
1940 "computer or to the network. It also contains sections to find "
1941 "recently saved files or files of a certain type.</para><para>"
1942 "Click on an entry to go there. Click with the right mouse button "
1943 "instead to open any entry in a new tab or new window.</para>"
1944 "<para>New entries can be added by dragging folders onto this panel. "
1945 "Right-click any section or entry to hide it. Right-click an empty "
1946 "space on this panel and select <interface>Show Hidden Places"
1947 "</interface> to display it again.</para>") + panelWhatsThis
);
1949 // Add actions into the "Panels" menu
1950 KActionMenu
* panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Show Panels"), this);
1951 actionCollection()->addAction(QStringLiteral("panels"), panelsMenu
);
1952 panelsMenu
->setIcon(QIcon::fromTheme(QStringLiteral("view-sidetree")));
1953 panelsMenu
->setDelayed(false);
1954 const KActionCollection
* ac
= actionCollection();
1955 panelsMenu
->addAction(ac
->action(QStringLiteral("show_places_panel")));
1957 panelsMenu
->addAction(ac
->action(QStringLiteral("show_information_panel")));
1959 panelsMenu
->addAction(ac
->action(QStringLiteral("show_folders_panel")));
1960 panelsMenu
->addAction(ac
->action(QStringLiteral("show_terminal_panel")));
1961 panelsMenu
->addSeparator();
1962 panelsMenu
->addAction(actionShowAllPlaces
);
1963 panelsMenu
->addAction(lockLayoutAction
);
1965 connect(panelsMenu
->menu(), &QMenu::aboutToShow
, this, [actionShowAllPlaces
, this]{
1966 actionShowAllPlaces
->setEnabled(m_placesPanel
->hiddenListCount());
1971 void DolphinMainWindow::updateFileAndEditActions()
1973 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1974 const KActionCollection
* col
= actionCollection();
1975 KFileItemListProperties
capabilitiesSource(list
);
1977 QAction
* addToPlacesAction
= col
->action(QStringLiteral("add_to_places"));
1978 QAction
* copyToOtherViewAction
= col
->action(QStringLiteral("copy_to_inactive_split_view"));
1979 QAction
* moveToOtherViewAction
= col
->action(QStringLiteral("move_to_inactive_split_view"));
1980 QAction
* copyLocation
= col
->action(QString("copy_location"));
1982 if (list
.isEmpty()) {
1983 stateChanged(QStringLiteral("has_no_selection"));
1985 addToPlacesAction
->setEnabled(true);
1986 copyToOtherViewAction
->setEnabled(false);
1987 moveToOtherViewAction
->setEnabled(false);
1988 copyLocation
->setEnabled(false);
1990 stateChanged(QStringLiteral("has_selection"));
1992 QAction
* renameAction
= col
->action(KStandardAction::name(KStandardAction::RenameFile
));
1993 QAction
* moveToTrashAction
= col
->action(KStandardAction::name(KStandardAction::MoveToTrash
));
1994 QAction
* deleteAction
= col
->action(KStandardAction::name(KStandardAction::DeleteFile
));
1995 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1996 QAction
* deleteWithTrashShortcut
= col
->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
1997 QAction
* showTarget
= col
->action(QStringLiteral("show_target"));
1998 QAction
* duplicateAction
= col
->action(QStringLiteral("duplicate")); // see DolphinViewActionHandler
2000 if (list
.length() == 1 && list
.first().isDir()) {
2001 addToPlacesAction
->setEnabled(true);
2003 addToPlacesAction
->setEnabled(false);
2006 if (m_tabWidget
->currentTabPage()->splitViewEnabled()) {
2007 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
2008 KFileItem capabilitiesDestination
;
2010 if (tabPage
->primaryViewActive()) {
2011 capabilitiesDestination
= tabPage
->secondaryViewContainer()->url();
2013 capabilitiesDestination
= tabPage
->primaryViewContainer()->url();
2016 copyToOtherViewAction
->setEnabled(capabilitiesDestination
.isWritable());
2017 moveToOtherViewAction
->setEnabled(capabilitiesSource
.supportsMoving() && capabilitiesDestination
.isWritable());
2019 copyToOtherViewAction
->setEnabled(false);
2020 moveToOtherViewAction
->setEnabled(false);
2023 const bool enableMoveToTrash
= capabilitiesSource
.isLocal() && capabilitiesSource
.supportsMoving();
2025 renameAction
->setEnabled(capabilitiesSource
.supportsMoving());
2026 moveToTrashAction
->setEnabled(enableMoveToTrash
);
2027 deleteAction
->setEnabled(capabilitiesSource
.supportsDeleting());
2028 deleteWithTrashShortcut
->setEnabled(capabilitiesSource
.supportsDeleting() && !enableMoveToTrash
);
2029 cutAction
->setEnabled(capabilitiesSource
.supportsMoving());
2030 copyLocation
->setEnabled(list
.length() == 1);
2031 showTarget
->setEnabled(list
.length() == 1 && list
.at(0).isLink());
2032 duplicateAction
->setEnabled(capabilitiesSource
.supportsWriting());
2036 void DolphinMainWindow::updateViewActions()
2038 m_actionHandler
->updateViewActions();
2040 QAction
* showFilterBarAction
= actionCollection()->action(QStringLiteral("show_filter_bar"));
2041 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
2043 updateSplitAction();
2046 void DolphinMainWindow::updateGoActions()
2048 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
2049 const QUrl currentUrl
= m_activeViewContainer
->url();
2050 // I think this is one of the best places to firstly be confronted
2051 // with a file system and its hierarchy. Talking about the root
2052 // directory might seem too much here but it is the question that
2053 // naturally arises in this context.
2054 goUpAction
->setWhatsThis(xi18nc("@info:whatsthis", "<para>Go to "
2055 "the folder that contains the currently viewed one.</para>"
2056 "<para>All files and folders are organized in a hierarchical "
2057 "<emphasis>file system</emphasis>. At the top of this hierarchy is "
2058 "a directory that contains all data connected to this computer"
2059 "—the <emphasis>root directory</emphasis>.</para>"));
2060 goUpAction
->setEnabled(KIO::upUrl(currentUrl
) != currentUrl
);
2063 void DolphinMainWindow::createControlButton()
2065 if (m_controlButton
) {
2068 Q_ASSERT(!m_controlButton
);
2070 m_controlButton
= new QToolButton(this);
2071 m_controlButton
->setAccessibleName(i18nc("@action:intoolbar", "Control"));
2072 m_controlButton
->setIcon(QIcon::fromTheme(QStringLiteral("application-menu")));
2073 m_controlButton
->setToolTip(i18nc("@action", "Show menu"));
2074 m_controlButton
->setAttribute(Qt::WidgetAttribute::WA_CustomWhatsThis
);
2075 m_controlButton
->setPopupMode(QToolButton::InstantPopup
);
2077 QMenu
* controlMenu
= new QMenu(m_controlButton
);
2078 connect(controlMenu
, &QMenu::aboutToShow
, this, &DolphinMainWindow::updateControlMenu
);
2079 controlMenu
->installEventFilter(this);
2081 m_controlButton
->setMenu(controlMenu
);
2083 toolBar()->addWidget(m_controlButton
);
2084 connect(toolBar(), &KToolBar::iconSizeChanged
,
2085 m_controlButton
, &QToolButton::setIconSize
);
2087 // The added widgets are owned by the toolbar and may get deleted when e.g. the toolbar
2088 // gets edited. In this case we must add them again. The adding is done asynchronously by
2089 // m_updateToolBarTimer.
2090 connect(m_controlButton
, &QToolButton::destroyed
, this, &DolphinMainWindow::slotControlButtonDeleted
);
2091 m_updateToolBarTimer
= new QTimer(this);
2092 m_updateToolBarTimer
->setInterval(500);
2093 connect(m_updateToolBarTimer
, &QTimer::timeout
, this, &DolphinMainWindow::updateToolBar
);
2096 void DolphinMainWindow::deleteControlButton()
2098 delete m_controlButton
;
2099 m_controlButton
= nullptr;
2101 delete m_updateToolBarTimer
;
2102 m_updateToolBarTimer
= nullptr;
2105 bool DolphinMainWindow::addActionToMenu(QAction
* action
, QMenu
* menu
)
2110 const KToolBar
* toolBarWidget
= toolBar();
2111 const auto associatedWidgets
= action
->associatedWidgets();
2112 for (const QWidget
* widget
: associatedWidgets
) {
2113 if (widget
== toolBarWidget
) {
2118 menu
->addAction(action
);
2122 void DolphinMainWindow::refreshViews()
2124 m_tabWidget
->refreshViews();
2126 if (GeneralSettings::modifiedStartupSettings()) {
2127 // The startup settings have been changed by the user (see bug #254947).
2128 // Synchronize the split-view setting with the active view:
2129 const bool splitView
= GeneralSettings::splitView();
2130 m_tabWidget
->currentTabPage()->setSplitViewEnabled(splitView
);
2131 updateSplitAction();
2132 updateWindowTitle();
2135 Q_EMIT
settingsChanged();
2138 void DolphinMainWindow::clearStatusBar()
2140 m_activeViewContainer
->statusBar()->resetToDefaultText();
2143 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
2145 connect(container
, &DolphinViewContainer::showFilterBarChanged
,
2146 this, &DolphinMainWindow::updateFilterBarAction
);
2147 connect(container
, &DolphinViewContainer::writeStateChanged
,
2148 this, &DolphinMainWindow::slotWriteStateChanged
);
2149 connect(container
, &DolphinViewContainer::searchModeEnabledChanged
,
2150 this, &DolphinMainWindow::updateSearchAction
);
2152 const QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
2153 connect(toggleSearchAction
, &QAction::triggered
, container
, &DolphinViewContainer::setSearchModeEnabled
);
2155 const DolphinView
* view
= container
->view();
2156 connect(view
, &DolphinView::selectionChanged
,
2157 this, &DolphinMainWindow::slotSelectionChanged
);
2158 connect(view
, &DolphinView::requestItemInfo
,
2159 this, &DolphinMainWindow::requestItemInfo
);
2160 connect(view
, &DolphinView::tabRequested
,
2161 this, &DolphinMainWindow::openNewTab
);
2162 connect(view
, &DolphinView::requestContextMenu
,
2163 this, &DolphinMainWindow::openContextMenu
);
2164 connect(view
, &DolphinView::directoryLoadingStarted
,
2165 this, &DolphinMainWindow::enableStopAction
);
2166 connect(view
, &DolphinView::directoryLoadingCompleted
,
2167 this, &DolphinMainWindow::disableStopAction
);
2168 connect(view
, &DolphinView::directoryLoadingCompleted
,
2169 this, &DolphinMainWindow::slotDirectoryLoadingCompleted
);
2170 connect(view
, &DolphinView::goBackRequested
,
2171 this, &DolphinMainWindow::goBack
);
2172 connect(view
, &DolphinView::goForwardRequested
,
2173 this, &DolphinMainWindow::goForward
);
2174 connect(view
, &DolphinView::urlActivated
,
2175 this, &DolphinMainWindow::handleUrl
);
2176 connect(view
, &DolphinView::goUpRequested
,
2177 this, &DolphinMainWindow::goUp
);
2179 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
2180 (actionCollection()->action(QStringLiteral("url_navigators")));
2182 KUrlNavigator
*navigator
= m_tabWidget
->currentTabPage()->primaryViewActive() ?
2183 navigators
->primaryUrlNavigator() :
2184 navigators
->secondaryUrlNavigator();
2186 connect(navigator
, &KUrlNavigator::urlChanged
,
2187 this, &DolphinMainWindow::changeUrl
);
2188 QAction
* editableLocactionAction
= actionCollection()->action(QStringLiteral("editable_location"));
2189 editableLocactionAction
->setChecked(navigator
->isUrlEditable());
2190 connect(navigator
, &KUrlNavigator::editableStateChanged
,
2191 this, &DolphinMainWindow::slotEditableStateChanged
);
2192 connect(navigator
, &KUrlNavigator::tabRequested
,
2193 this, &DolphinMainWindow::openNewTabAfterLastTab
);
2195 disconnect(m_updateHistoryConnection
);
2196 m_updateHistoryConnection
= connect(
2197 container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::historyChanged
,
2198 this, &DolphinMainWindow::updateHistory
);
2201 void DolphinMainWindow::updateSplitAction()
2203 QAction
* splitAction
= actionCollection()->action(QStringLiteral("split_view"));
2204 const DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
2205 if (tabPage
->splitViewEnabled()) {
2206 if (GeneralSettings::closeActiveSplitView() ? tabPage
->primaryViewActive() : !tabPage
->primaryViewActive()) {
2207 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2208 splitAction
->setToolTip(i18nc("@info", "Close left view"));
2209 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close")));
2211 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2212 splitAction
->setToolTip(i18nc("@info", "Close right view"));
2213 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close")));
2216 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2217 splitAction
->setToolTip(i18nc("@info", "Split view"));
2218 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2222 bool DolphinMainWindow::isKompareInstalled() const
2224 static bool initialized
= false;
2225 static bool installed
= false;
2227 // TODO: maybe replace this approach later by using a menu
2228 // plugin like kdiff3plugin.cpp
2229 installed
= !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty();
2235 void DolphinMainWindow::createPanelAction(const QIcon
& icon
,
2236 const QKeySequence
& shortcut
,
2237 QAction
* dockAction
,
2238 const QString
& actionName
)
2240 QAction
* panelAction
= actionCollection()->addAction(actionName
);
2241 panelAction
->setCheckable(true);
2242 panelAction
->setChecked(dockAction
->isChecked());
2243 panelAction
->setText(dockAction
->text());
2244 panelAction
->setIcon(icon
);
2245 actionCollection()->setDefaultShortcut(panelAction
, shortcut
);
2247 connect(panelAction
, &QAction::triggered
, dockAction
, &QAction::trigger
);
2248 connect(dockAction
, &QAction::toggled
, panelAction
, &QAction::setChecked
);
2251 void DolphinMainWindow::setupWhatsThis()
2254 menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2255 "<emphasis>Menubar</emphasis>. It provides access to commands and "
2256 "configuration options. Left-click on any of the menus on this "
2257 "bar to see its contents.</para><para>The Menubar can be hidden "
2258 "by unchecking <interface>Settings|Show Menubar</interface>. Then "
2259 "most of its contents become available through a <interface>Control"
2260 "</interface> button on the <emphasis>Toolbar</emphasis>.</para>"));
2261 toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2262 "<emphasis>Toolbar</emphasis>. It allows quick access to "
2263 "frequently used actions.</para><para>It is highly customizable. "
2264 "All items you see in the <interface>Control</interface> menu or "
2265 "in the <interface>Menubar</interface> can be placed on the "
2266 "Toolbar. Just right-click on it and select <interface>Configure "
2267 "Toolbars…</interface> or find this action in the <interface>"
2268 "Control</interface> or <interface>Settings</interface> menu."
2269 "</para><para>The location of the bar and the style of its "
2270 "buttons can also be changed in the right-click menu. Right-click "
2271 "a button if you want to show or hide its text.</para>"));
2272 m_tabWidget
->setWhatsThis(xi18nc("@info:whatsthis main view",
2273 "<para>Here you can see the <emphasis>folders</emphasis> and "
2274 "<emphasis>files</emphasis> that are at the location described in "
2275 "the <interface>Location Bar</interface> above. This area is the "
2276 "central part of this application where you navigate to the files "
2277 "you want to use.</para><para>For an elaborate and general "
2278 "introduction to this application <link "
2279 "url='https://userbase.kde.org/Dolphin/File_Management#Introduction_to_Dolphin'>"
2280 "click here</link>. This will open an introductory article from "
2281 "the <emphasis>KDE UserBase Wiki</emphasis>.</para><para>For brief "
2282 "explanations of all the features of this <emphasis>view</emphasis> "
2283 "<link url='help:/dolphin/dolphin-view.html'>click here</link> "
2284 "instead. This will open a page from the <emphasis>Handbook"
2285 "</emphasis> that covers the basics.</para>"));
2288 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings
))
2289 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window "
2290 "that lists the <emphasis>keyboard shortcuts</emphasis>.<nl/>"
2291 "There you can set up key combinations to trigger an action when "
2292 "they are pressed simultaneously. All commands in this application can "
2293 "be triggered this way.</para>"));
2294 actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars
))
2295 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window in which "
2296 "you can change which buttons appear on the <emphasis>Toolbar</emphasis>.</para>"
2297 "<para>All items you see in the <interface>Control</interface> menu "
2298 "or in the <interface>Menubar</interface> can also be placed on the Toolbar.</para>"));
2299 actionCollection()->action(KStandardAction::name(KStandardAction::Preferences
))
2300 ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can "
2301 "change a multitude of settings for this application. For an explanation "
2302 "of the various settings go to the chapter <emphasis>Configuring Dolphin"
2303 "</emphasis> in <interface>Help|Dolphin Handbook</interface>."));
2306 // The whatsthis has to be set for the m_helpMenu and for the
2307 // StandardAction separately because both are used in different locations.
2308 // m_helpMenu is only used for createControlButton() button.
2310 // Links do not work within the Menubar so texts without links are provided there.
2312 // i18n: If the external link isn't available in your language you should
2313 // probably state the external link language at least in brackets to not
2314 // frustrate the user. If there are multiple languages that the user might
2315 // know with a reasonable chance you might want to have 2 external links.
2316 // The same is in my opinion true for every external link you translate.
2317 const QString whatsThisHelpContents
= xi18nc("@info:whatsthis handbook",
2318 "<para>This opens the Handbook for this application. It provides "
2319 "explanations for every part of <emphasis>Dolphin</emphasis>.</para>");
2320 actionCollection()->action(KStandardAction::name(KStandardAction::HelpContents
))
2321 ->setWhatsThis(whatsThisHelpContents
2322 + xi18nc("@info:whatsthis second half of handbook hb text without link",
2323 "<para>If you want more elaborate introductions to the "
2324 "different features of <emphasis>Dolphin</emphasis> "
2325 "go to the KDE UserBase Wiki.</para>"));
2326 m_helpMenu
->action(KHelpMenu::menuHelpContents
)->setWhatsThis(whatsThisHelpContents
2327 + xi18nc("@info:whatsthis second half of handbook text with link",
2328 "<para>If you want more elaborate introductions to the "
2329 "different features of <emphasis>Dolphin</emphasis> "
2330 "<link url='https://userbase.kde.org/Dolphin/File_Management'>click here</link>. "
2331 "It will open the dedicated page in the KDE UserBase Wiki.</para>"));
2333 const QString whatsThisWhatsThis
= xi18nc("@info:whatsthis whatsthis button",
2334 "<para>This is the button that invokes the help feature you are "
2335 "using right now! Click it, then click any component of this "
2336 "application to ask \"What's this?\" about it. The mouse cursor "
2337 "will change appearance if no help is available for a spot.</para>");
2338 actionCollection()->action(KStandardAction::name(KStandardAction::WhatsThis
))
2339 ->setWhatsThis(whatsThisWhatsThis
2340 + xi18nc("@info:whatsthis second half of whatsthis button text without link",
2341 "<para>There are two other ways to get help for this application: The "
2342 "<interface>Dolphin Handbook</interface> in the <interface>Help"
2343 "</interface> menu and the <emphasis>KDE UserBase Wiki</emphasis> "
2344 "article about <emphasis>File Management</emphasis> online."
2345 "</para><para>The \"What's this?\" help is "
2346 "missing in most other windows so don't get too used to this.</para>"));
2347 m_helpMenu
->action(KHelpMenu::menuWhatsThis
)->setWhatsThis(whatsThisWhatsThis
2348 + xi18nc("@info:whatsthis second half of whatsthis button text with link",
2349 "<para>There are two other ways to get help: "
2350 "The <link url='help:/dolphin/index.html'>Dolphin Handbook</link> and "
2351 "the <link url='https://userbase.kde.org/Dolphin/File_Management'>KDE "
2352 "UserBase Wiki</link>.</para><para>The \"What's this?\" help is "
2353 "missing in most other windows so don't get too used to this.</para>"));
2355 const QString whatsThisReportBug
= xi18nc("@info:whatsthis","<para>This opens a "
2356 "window that will guide you through reporting errors or flaws "
2357 "in this application or in other KDE software.</para>");
2358 actionCollection()->action(KStandardAction::name(KStandardAction::ReportBug
))
2359 ->setWhatsThis(whatsThisReportBug
);
2360 m_helpMenu
->action(KHelpMenu::menuReportBug
)->setWhatsThis(whatsThisReportBug
2361 + xi18nc("@info:whatsthis second half of reportbug text with link",
2362 "<para>High-quality bug reports are much appreciated. To learn "
2363 "how to make your bug report as effective as possible "
2364 "<link url='https://community.kde.org/Get_Involved/Bug_Reporting'>"
2365 "click here</link>.</para>"));
2367 const QString whatsThisDonate
= xi18nc("@info:whatsthis","<para>This opens a "
2368 "<emphasis>web page</emphasis> where you can donate to "
2369 "support the continued work on this application and many "
2370 "other projects by the <emphasis>KDE</emphasis> community.</para>"
2371 "<para>Donating is the easiest and fastest way to efficiently "
2372 "support KDE and its projects. KDE projects are available for "
2373 "free therefore your donation is needed to cover things that "
2374 "require money like servers, contributor meetings, etc.</para>"
2375 "<para><emphasis>KDE e.V.</emphasis> is the non-profit "
2376 "organization behind the KDE community.</para>");
2377 actionCollection()->action(KStandardAction::name(KStandardAction::Donate
))
2378 ->setWhatsThis(whatsThisDonate
);
2379 m_helpMenu
->action(KHelpMenu::menuDonate
)->setWhatsThis(whatsThisDonate
);
2381 const QString whatsThisSwitchLanguage
= xi18nc("@info:whatsthis",
2382 "With this you can change the language this application uses."
2383 "<nl/>You can even set secondary languages which will be used "
2384 "if texts are not available in your preferred language.");
2385 actionCollection()->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
))
2386 ->setWhatsThis(whatsThisSwitchLanguage
);
2387 m_helpMenu
->action(KHelpMenu::menuSwitchLanguage
)->setWhatsThis(whatsThisSwitchLanguage
);
2389 const QString whatsThisAboutApp
= xi18nc("@info:whatsthis","This opens a "
2390 "window that informs you about the version, license, "
2391 "used libraries and maintainers of this application.");
2392 actionCollection()->action(KStandardAction::name(KStandardAction::AboutApp
))
2393 ->setWhatsThis(whatsThisAboutApp
);
2394 m_helpMenu
->action(KHelpMenu::menuAboutApp
)->setWhatsThis(whatsThisAboutApp
);
2396 const QString whatsThisAboutKDE
= xi18nc("@info:whatsthis","This opens a "
2397 "window with information about <emphasis>KDE</emphasis>. "
2398 "The KDE community are the people behind this free software."
2399 "<nl/>If you like using this application but don't know "
2400 "about KDE or want to see a cute dragon have a look!");
2401 actionCollection()->action(KStandardAction::name(KStandardAction::AboutKDE
))
2402 ->setWhatsThis(whatsThisAboutKDE
);
2403 m_helpMenu
->action(KHelpMenu::menuAboutKDE
)->setWhatsThis(whatsThisAboutKDE
);
2406 bool DolphinMainWindow::event(QEvent
*event
)
2408 if (event
->type() == QEvent::WhatsThisClicked
) {
2410 QWhatsThisClickedEvent
* whatsThisEvent
= dynamic_cast<QWhatsThisClickedEvent
*>(event
);
2411 QDesktopServices::openUrl(QUrl(whatsThisEvent
->href()));
2414 return KXmlGuiWindow::event(event
);
2417 bool DolphinMainWindow::eventFilter(QObject
* obj
, QEvent
* event
)
2420 if (event
->type() == QEvent::WhatsThisClicked
) {
2422 QWhatsThisClickedEvent
* whatsThisEvent
= dynamic_cast<QWhatsThisClickedEvent
*>(event
);
2423 QDesktopServices::openUrl(QUrl(whatsThisEvent
->href()));
2429 void DolphinMainWindow::focusTerminalPanel()
2431 if (m_terminalPanel
->isVisible()) {
2432 if (m_terminalPanel
->terminalHasFocus()) {
2433 m_activeViewContainer
->view()->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2434 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2436 m_terminalPanel
->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2437 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2440 actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger();
2441 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2445 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
2446 KIO::FileUndoManager::UiInterface()
2450 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2454 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
2456 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2458 DolphinViewContainer
* container
= mainWin
->activeViewContainer();
2459 container
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
2461 KIO::FileUndoManager::UiInterface::jobError(job
);
2465 bool DolphinMainWindow::isUrlOpen(const QString
& url
)
2467 return m_tabWidget
->isUrlOpen(QUrl::fromUserInput((url
)));