2 * SPDX-FileCopyrightText: 2006 Peter Penz <peter.penz19@gmail.com>
3 * SPDX-FileCopyrightText: 2006 Stefan Monov <logixoul@gmail.com>
4 * SPDX-FileCopyrightText: 2006 Cvetoslav Ludmiloff <ludmiloff@gmail.com>
6 * SPDX-License-Identifier: GPL-2.0-or-later
9 #include "dolphinmainwindow.h"
11 #include "dolphinmainwindowadaptor.h"
12 #include "config-terminal.h"
14 #include "dolphinbookmarkhandler.h"
15 #include "dolphindockwidget.h"
16 #include "dolphincontextmenu.h"
17 #include "dolphinnavigatorswidgetaction.h"
18 #include "dolphinnewfilemenu.h"
19 #include "dolphinrecenttabsmenu.h"
20 #include "dolphinurlnavigatorscontroller.h"
21 #include "dolphinviewcontainer.h"
22 #include "dolphintabpage.h"
23 #include "middleclickactioneventfilter.h"
24 #include "panels/folders/folderspanel.h"
25 #include "panels/places/placesitemmodel.h"
26 #include "panels/places/placespanel.h"
27 #include "panels/information/informationpanel.h"
28 #include "panels/terminal/terminalpanel.h"
29 #include "settings/dolphinsettingsdialog.h"
30 #include "statusbar/dolphinstatusbar.h"
31 #include "views/dolphinviewactionhandler.h"
32 #include "views/dolphinremoteencoding.h"
33 #include "views/draganddrophelper.h"
34 #include "views/viewproperties.h"
35 #include "views/dolphinnewfilemenuobserver.h"
36 #include "dolphin_generalsettings.h"
38 #include <KActionCollection>
39 #include <KActionMenu>
40 #include <KAuthorized>
43 #include <KDualAction>
44 #include <KFileItemListProperties>
46 #include <KIO/CommandLauncherJob>
47 #include <KIO/JobUiDelegate>
48 #include <KIO/OpenFileManagerWindowJob>
49 #include <KIO/OpenUrlJob>
50 #include <KJobWidgets>
51 #include <KLocalizedString>
52 #include <KMessageBox>
53 #include <KNS3/KMoreToolsMenuFactory>
54 #include <KProtocolInfo>
55 #include <KProtocolManager>
57 #include <KStandardAction>
58 #include <KStartupInfo>
60 #include <KToggleAction>
62 #include <KToolBarPopupAction>
63 #include <KToolInvocation>
64 #include <KUrlComboBox>
65 #include <KUrlNavigator>
66 #include <KWindowSystem>
68 #include <QApplication>
70 #include <QCloseEvent>
71 #include <QDesktopServices>
76 #include <QPushButton>
78 #include <QStandardPaths>
80 #include <QToolButton>
81 #include <QWhatsThisClickedEvent>
84 // Used for GeneralSettings::version() to determine whether
85 // an updated version of Dolphin is running.
86 const int CurrentDolphinVersion
= 200;
87 // The maximum number of entries in the back/forward popup menu
88 const int MaxNumberOfNavigationentries
= 12;
89 // The maximum number of "Activate Tab" shortcuts
90 const int MaxActivateTabShortcuts
= 9;
93 DolphinMainWindow::DolphinMainWindow() :
94 KXmlGuiWindow(nullptr),
95 m_newFileMenu(nullptr),
98 m_activeViewContainer(nullptr),
99 m_actionHandler(nullptr),
100 m_remoteEncoding(nullptr),
102 m_bookmarkHandler(nullptr),
103 m_controlButton(nullptr),
104 m_updateToolBarTimer(nullptr),
105 m_lastHandleUrlOpenJob(nullptr),
106 m_terminalPanel(nullptr),
107 m_placesPanel(nullptr),
108 m_tearDownFromPlacesRequested(false),
109 m_backAction(nullptr),
110 m_forwardAction(nullptr)
112 Q_INIT_RESOURCE(dolphin
);
114 new MainWindowAdaptor(this);
117 setWindowFlags(Qt::WindowContextHelpButtonHint
);
119 setComponentName(QStringLiteral("dolphin"), QGuiApplication::applicationDisplayName());
120 setObjectName(QStringLiteral("Dolphin#"));
122 connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::errorMessage
,
123 this, &DolphinMainWindow::showErrorMessage
);
125 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
126 undoManager
->setUiInterface(new UndoUiInterface());
128 connect(undoManager
, QOverload
<bool>::of(&KIO::FileUndoManager::undoAvailable
),
129 this, &DolphinMainWindow::slotUndoAvailable
);
130 connect(undoManager
, &KIO::FileUndoManager::undoTextChanged
,
131 this, &DolphinMainWindow::slotUndoTextChanged
);
132 connect(undoManager
, &KIO::FileUndoManager::jobRecordingStarted
,
133 this, &DolphinMainWindow::clearStatusBar
);
134 connect(undoManager
, &KIO::FileUndoManager::jobRecordingFinished
,
135 this, &DolphinMainWindow::showCommand
);
137 GeneralSettings
* generalSettings
= GeneralSettings::self();
138 const bool firstRun
= (generalSettings
->version() < 200);
140 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
143 setAcceptDrops(true);
145 auto *navigatorsWidgetAction
= new DolphinNavigatorsWidgetAction(this);
146 actionCollection()->addAction(QStringLiteral("url_navigators"), navigatorsWidgetAction
);
147 m_tabWidget
= new DolphinTabWidget(navigatorsWidgetAction
, this);
148 m_tabWidget
->setObjectName("tabWidget");
149 connect(m_tabWidget
, &DolphinTabWidget::activeViewChanged
,
150 this, &DolphinMainWindow::activeViewChanged
);
151 connect(m_tabWidget
, &DolphinTabWidget::tabCountChanged
,
152 this, &DolphinMainWindow::tabCountChanged
);
153 connect(m_tabWidget
, &DolphinTabWidget::currentUrlChanged
,
154 this, &DolphinMainWindow::updateWindowTitle
);
155 setCentralWidget(m_tabWidget
);
159 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
160 connect(m_actionHandler
, &DolphinViewActionHandler::actionBeingHandled
, this, &DolphinMainWindow::clearStatusBar
);
161 connect(m_actionHandler
, &DolphinViewActionHandler::createDirectoryTriggered
, this, &DolphinMainWindow::createDirectory
);
163 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
164 connect(this, &DolphinMainWindow::urlChanged
,
165 m_remoteEncoding
, &DolphinRemoteEncoding::slotAboutToOpenUrl
);
169 setupGUI(Keys
| Save
| Create
| ToolBar
);
170 stateChanged(QStringLiteral("new_file"));
172 toolBar()->setAllowedAreas(Qt::TopToolBarArea
| Qt::BottomToolBarArea
);
173 toolBar()->setFloatable(false);
174 if (!toolBar()->actions().contains(navigatorsWidgetAction
)) {
175 navigatorsWidgetAction
->addToToolbarAndSave(this);
177 QClipboard
* clipboard
= QApplication::clipboard();
178 connect(clipboard
, &QClipboard::dataChanged
,
179 this, &DolphinMainWindow::updatePasteAction
);
181 QAction
* showFilterBarAction
= actionCollection()->action(QStringLiteral("show_filter_bar"));
182 showFilterBarAction
->setChecked(generalSettings
->filterBar());
185 menuBar()->setVisible(false);
186 // Assure a proper default size if Dolphin runs the first time
190 const bool showMenu
= !menuBar()->isHidden();
191 QAction
* showMenuBarAction
= actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar
));
192 showMenuBarAction
->setChecked(showMenu
); // workaround for bug #171080
194 createControlButton();
197 // enable middle-click on back/forward/up to open in a new tab
198 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
199 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotToolBarActionMiddleClicked
);
200 toolBar()->installEventFilter(middleClickEventFilter
);
204 connect(KSycoca::self(), QOverload
<>::of(&KSycoca::databaseChanged
), this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
206 QTimer::singleShot(0, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
209 DolphinMainWindow::~DolphinMainWindow()
213 QVector
<DolphinViewContainer
*> DolphinMainWindow::viewContainers() const
215 QVector
<DolphinViewContainer
*> viewContainers
;
217 for (int i
= 0; i
< m_tabWidget
->count(); ++i
) {
218 DolphinTabPage
*tabPage
= m_tabWidget
->tabPageAt(i
);
220 viewContainers
<< tabPage
->primaryViewContainer();
221 if (tabPage
->splitViewEnabled()) {
222 viewContainers
<< tabPage
->secondaryViewContainer();
225 return viewContainers
;
228 void DolphinMainWindow::setViewsWithInvalidPathsToHome()
230 const QVector
<DolphinViewContainer
*> theViewContainers
= viewContainers();
231 for (DolphinViewContainer
*viewContainer
: theViewContainers
) {
233 // Only consider local dirs, not remote locations and abstract protocols
234 if (viewContainer
->url().isLocalFile()) {
235 if (!QFileInfo::exists(viewContainer
->url().toLocalFile())) {
236 viewContainer
->setUrl(QUrl::fromLocalFile(QDir::homePath()));
242 void DolphinMainWindow::openDirectories(const QList
<QUrl
>& dirs
, bool splitView
)
244 m_tabWidget
->openDirectories(dirs
, splitView
);
247 void DolphinMainWindow::openDirectories(const QStringList
& dirs
, bool splitView
)
249 openDirectories(QUrl::fromStringList(dirs
), splitView
);
252 void DolphinMainWindow::openFiles(const QList
<QUrl
>& files
, bool splitView
)
254 m_tabWidget
->openFiles(files
, splitView
);
257 bool DolphinMainWindow::isFoldersPanelEnabled() const
259 return actionCollection()->action(QStringLiteral("show_folders_panel"))->isChecked();
262 bool DolphinMainWindow::isInformationPanelEnabled() const
264 return actionCollection()->action(QStringLiteral("show_information_panel"))->isChecked();
267 void DolphinMainWindow::openFiles(const QStringList
& files
, bool splitView
)
269 openFiles(QUrl::fromStringList(files
), splitView
);
272 void DolphinMainWindow::activateWindow()
274 window()->setAttribute(Qt::WA_NativeWindow
, true);
275 KStartupInfo::setNewStartupId(window()->windowHandle(), KStartupInfo::startupId());
276 KWindowSystem::activateWindow(window()->effectiveWinId());
279 void DolphinMainWindow::showCommand(CommandType command
)
281 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
283 case KIO::FileUndoManager::Copy
:
284 statusBar
->setText(i18nc("@info:status", "Successfully copied."));
286 case KIO::FileUndoManager::Move
:
287 statusBar
->setText(i18nc("@info:status", "Successfully moved."));
289 case KIO::FileUndoManager::Link
:
290 statusBar
->setText(i18nc("@info:status", "Successfully linked."));
292 case KIO::FileUndoManager::Trash
:
293 statusBar
->setText(i18nc("@info:status", "Successfully moved to trash."));
295 case KIO::FileUndoManager::Rename
:
296 statusBar
->setText(i18nc("@info:status", "Successfully renamed."));
299 case KIO::FileUndoManager::Mkdir
:
300 statusBar
->setText(i18nc("@info:status", "Created folder."));
308 void DolphinMainWindow::pasteIntoFolder()
310 m_activeViewContainer
->view()->pasteIntoFolder();
313 void DolphinMainWindow::changeUrl(const QUrl
&url
)
315 if (!KProtocolManager::supportsListing(url
)) {
316 // The URL navigator only checks for validity, not
317 // if the URL can be listed. An error message is
318 // shown due to DolphinViewContainer::restoreView().
322 m_activeViewContainer
->setUrl(url
);
323 updateFileAndEditActions();
328 Q_EMIT
urlChanged(url
);
331 void DolphinMainWindow::slotTerminalDirectoryChanged(const QUrl
& url
)
333 if (m_tearDownFromPlacesRequested
&& url
== QUrl::fromLocalFile(QDir::homePath())) {
334 m_placesPanel
->proceedWithTearDown();
335 m_tearDownFromPlacesRequested
= false;
338 m_activeViewContainer
->setAutoGrabFocus(false);
340 m_activeViewContainer
->setAutoGrabFocus(true);
343 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
345 KToggleAction
* editableLocationAction
=
346 static_cast<KToggleAction
*>(actionCollection()->action(QStringLiteral("editable_location")));
347 editableLocationAction
->setChecked(editable
);
350 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
352 updateFileAndEditActions();
354 const int selectedUrlsCount
= m_tabWidget
->currentTabPage()->selectedItemsCount();
356 QAction
* compareFilesAction
= actionCollection()->action(QStringLiteral("compare_files"));
357 if (selectedUrlsCount
== 2) {
358 compareFilesAction
->setEnabled(isKompareInstalled());
360 compareFilesAction
->setEnabled(false);
363 Q_EMIT
selectionChanged(selection
);
366 void DolphinMainWindow::updateHistory()
368 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
369 const int index
= urlNavigator
->historyIndex();
371 QAction
* backAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Back
));
373 backAction
->setToolTip(i18nc("@info", "Go back"));
374 backAction
->setWhatsThis(i18nc("@info:whatsthis go back", "Return to the previously viewed folder."));
375 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
378 QAction
* forwardAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Forward
));
380 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
381 forwardAction
->setWhatsThis(xi18nc("@info:whatsthis go forward",
382 "This undoes a <interface>Go|Back</interface> action."));
383 forwardAction
->setEnabled(index
> 0);
387 void DolphinMainWindow::updateFilterBarAction(bool show
)
389 QAction
* showFilterBarAction
= actionCollection()->action(QStringLiteral("show_filter_bar"));
390 showFilterBarAction
->setChecked(show
);
393 void DolphinMainWindow::openNewMainWindow()
395 Dolphin::openNewWindow({m_activeViewContainer
->url()}, this);
398 void DolphinMainWindow::openNewActivatedTab()
400 m_tabWidget
->openNewActivatedTab();
403 void DolphinMainWindow::addToPlaces()
408 // If nothing is selected, act on the current dir
409 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
410 url
= m_activeViewContainer
->url();
411 name
= m_activeViewContainer
->placesText();
413 const auto dirToAdd
= m_activeViewContainer
->view()->selectedItems().first();
414 url
= dirToAdd
.url();
415 name
= dirToAdd
.name();
418 PlacesItemModel model
;
420 if (m_activeViewContainer
->isSearchModeEnabled()) {
421 icon
= QStringLiteral("folder-saved-search-symbolic");
423 icon
= KIO::iconNameForUrl(url
);
425 model
.createPlacesItem(name
, url
, icon
);
429 void DolphinMainWindow::openNewTab(const QUrl
& url
, DolphinTabWidget::TabPlacement tabPlacement
)
431 m_tabWidget
->openNewTab(url
, QUrl(), tabPlacement
);
434 void DolphinMainWindow::openNewTabAfterCurrentTab(const QUrl
& url
)
436 m_tabWidget
->openNewTab(url
, QUrl(), DolphinTabWidget::AfterCurrentTab
);
439 void DolphinMainWindow::openNewTabAfterLastTab(const QUrl
& url
)
441 m_tabWidget
->openNewTab(url
, QUrl(), DolphinTabWidget::AfterLastTab
);
444 void DolphinMainWindow::openInNewTab()
446 const KFileItemList
& list
= m_activeViewContainer
->view()->selectedItems();
447 bool tabCreated
= false;
449 for (const KFileItem
& item
: list
) {
450 const QUrl
& url
= DolphinView::openItemAsFolderUrl(item
);
451 if (!url
.isEmpty()) {
452 openNewTabAfterCurrentTab(url
);
457 // if no new tab has been created from the selection
458 // open the current directory in a new tab
460 openNewTabAfterCurrentTab(m_activeViewContainer
->url());
464 void DolphinMainWindow::openInNewWindow()
468 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
469 if (list
.isEmpty()) {
470 newWindowUrl
= m_activeViewContainer
->url();
471 } else if (list
.count() == 1) {
472 const KFileItem
& item
= list
.first();
473 newWindowUrl
= DolphinView::openItemAsFolderUrl(item
);
476 if (!newWindowUrl
.isEmpty()) {
477 Dolphin::openNewWindow({newWindowUrl
}, this);
481 void DolphinMainWindow::showTarget()
483 const auto link
= m_activeViewContainer
->view()->selectedItems().at(0);
484 const auto linkLocationDir
= QFileInfo(link
.localPath()).absoluteDir();
485 auto linkDestination
= link
.linkDest();
486 if (QFileInfo(linkDestination
).isRelative()) {
487 linkDestination
= linkLocationDir
.filePath(linkDestination
);
489 if (QFileInfo::exists(linkDestination
)) {
490 KIO::highlightInFileManager({QUrl::fromLocalFile(linkDestination
).adjusted(QUrl::StripTrailingSlash
)});
492 m_activeViewContainer
->showMessage(xi18nc("@info", "Could not access <filename>%1</filename>.", linkDestination
),
493 DolphinViewContainer::Warning
);
497 void DolphinMainWindow::showEvent(QShowEvent
* event
)
499 KXmlGuiWindow::showEvent(event
);
501 if (!event
->spontaneous()) {
502 m_activeViewContainer
->view()->setFocus();
506 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
508 // Find out if Dolphin is closed directly by the user or
509 // by the session manager because the session is closed
510 bool closedByUser
= true;
511 if (qApp
->isSavingSession()) {
512 closedByUser
= false;
515 if (m_tabWidget
->count() > 1
516 && GeneralSettings::confirmClosingMultipleTabs()
517 && !GeneralSettings::rememberOpenedTabs()
519 // Ask the user if he really wants to quit and close all tabs.
520 // Open a confirmation dialog with 3 buttons:
521 // QDialogButtonBox::Yes -> Quit
522 // QDialogButtonBox::No -> Close only the current tab
523 // QDialogButtonBox::Cancel -> do nothing
524 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
525 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
526 dialog
->setModal(true);
527 QDialogButtonBox
* buttons
= new QDialogButtonBox(QDialogButtonBox::Yes
| QDialogButtonBox::No
| QDialogButtonBox::Cancel
);
528 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KGuiItem(i18nc("@action:button 'Quit Dolphin' button", "&Quit %1", QGuiApplication::applicationDisplayName()), QIcon::fromTheme(QStringLiteral("application-exit"))));
529 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("C&lose Current Tab"), QIcon::fromTheme(QStringLiteral("tab-close"))));
530 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
531 buttons
->button(QDialogButtonBox::Yes
)->setDefault(true);
533 bool doNotAskAgainCheckboxResult
= false;
535 const auto result
= KMessageBox::createKMessageBox(dialog
,
537 QMessageBox::Warning
,
538 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
540 i18n("Do not ask again"),
541 &doNotAskAgainCheckboxResult
,
542 KMessageBox::Notify
);
544 if (doNotAskAgainCheckboxResult
) {
545 GeneralSettings::setConfirmClosingMultipleTabs(false);
549 case QDialogButtonBox::Yes
:
552 case QDialogButtonBox::No
:
553 // Close only the current tab
554 m_tabWidget
->closeTab();
562 if (m_terminalPanel
&& m_terminalPanel
->hasProgramRunning() && GeneralSettings::confirmClosingTerminalRunningProgram() && closedByUser
) {
563 // Ask if the user really wants to quit Dolphin with a program that is still running in the Terminal panel
564 // Open a confirmation dialog with 3 buttons:
565 // QDialogButtonBox::Yes -> Quit
566 // QDialogButtonBox::No -> Show Terminal Panel
567 // QDialogButtonBox::Cancel -> do nothing
568 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
569 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
570 dialog
->setModal(true);
571 auto standardButtons
= QDialogButtonBox::Yes
| QDialogButtonBox::Cancel
;
572 if (!m_terminalPanel
->isVisible()) {
573 standardButtons
|= QDialogButtonBox::No
;
575 QDialogButtonBox
*buttons
= new QDialogButtonBox(standardButtons
);
576 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KStandardGuiItem::quit());
577 if (!m_terminalPanel
->isVisible()) {
579 buttons
->button(QDialogButtonBox::No
),
580 KGuiItem(i18n("Show &Terminal Panel"), QIcon::fromTheme(QStringLiteral("dialog-scripts"))));
582 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
584 bool doNotAskAgainCheckboxResult
= false;
586 const auto result
= KMessageBox::createKMessageBox(
589 QMessageBox::Warning
,
590 i18n("The program '%1' is still running in the Terminal panel. Are you sure you want to quit?", m_terminalPanel
->runningProgramName()),
592 i18n("Do not ask again"),
593 &doNotAskAgainCheckboxResult
,
594 KMessageBox::Dangerous
);
596 if (doNotAskAgainCheckboxResult
) {
597 GeneralSettings::setConfirmClosingTerminalRunningProgram(false);
601 case QDialogButtonBox::Yes
:
604 case QDialogButtonBox::No
:
605 actionCollection()->action("show_terminal_panel")->trigger();
606 // Do not quit, ignore quit event
614 if (GeneralSettings::rememberOpenedTabs()) {
615 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
616 KConfig
*config
= KConfigGui::sessionConfig();
617 saveGlobalProperties(config
);
618 savePropertiesInternal(config
, 1);
622 GeneralSettings::setVersion(CurrentDolphinVersion
);
623 GeneralSettings::self()->save();
625 KXmlGuiWindow::closeEvent(event
);
628 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
630 m_tabWidget
->saveProperties(group
);
633 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
635 m_tabWidget
->readProperties(group
);
638 void DolphinMainWindow::updateNewMenu()
640 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
641 m_newFileMenu
->checkUpToDate();
642 m_newFileMenu
->setPopupFiles(QList
<QUrl
>() << activeViewContainer()->url());
645 void DolphinMainWindow::createDirectory()
647 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
648 m_newFileMenu
->setPopupFiles(QList
<QUrl
>() << activeViewContainer()->url());
649 m_newFileMenu
->createDirectory();
652 void DolphinMainWindow::quit()
657 void DolphinMainWindow::showErrorMessage(const QString
& message
)
659 m_activeViewContainer
->showMessage(message
, DolphinViewContainer::Error
);
662 void DolphinMainWindow::slotUndoAvailable(bool available
)
664 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
666 undoAction
->setEnabled(available
);
670 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
672 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
674 undoAction
->setText(text
);
678 void DolphinMainWindow::undo()
681 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
682 KIO::FileUndoManager::self()->undo();
685 void DolphinMainWindow::cut()
687 m_activeViewContainer
->view()->cutSelectedItemsToClipboard();
690 void DolphinMainWindow::copy()
692 m_activeViewContainer
->view()->copySelectedItemsToClipboard();
695 void DolphinMainWindow::paste()
697 m_activeViewContainer
->view()->paste();
700 void DolphinMainWindow::find()
702 m_activeViewContainer
->setSearchModeEnabled(true);
705 void DolphinMainWindow::updateSearchAction()
707 QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
708 toggleSearchAction
->setChecked(m_activeViewContainer
->isSearchModeEnabled());
711 void DolphinMainWindow::updatePasteAction()
713 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
714 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
715 pasteAction
->setEnabled(pasteInfo
.first
);
716 pasteAction
->setText(pasteInfo
.second
);
719 void DolphinMainWindow::slotDirectoryLoadingCompleted()
724 void DolphinMainWindow::slotToolBarActionMiddleClicked(QAction
*action
)
726 if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Back
))) {
728 } else if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Forward
))) {
730 } else if (action
== actionCollection()->action(QStringLiteral("go_up"))) {
732 } else if (action
== actionCollection()->action(QStringLiteral("go_home"))) {
737 void DolphinMainWindow::slotAboutToShowBackPopupMenu()
739 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
741 m_backAction
->menu()->clear();
742 for (int i
= urlNavigator
->historyIndex() + 1; i
< urlNavigator
->historySize() && entries
< MaxNumberOfNavigationentries
; ++i
, ++entries
) {
743 QAction
* action
= new QAction(urlNavigator
->locationUrl(i
).toString(QUrl::PreferLocalFile
), m_backAction
->menu());
745 m_backAction
->menu()->addAction(action
);
749 void DolphinMainWindow::slotGoBack(QAction
* action
)
751 int gotoIndex
= action
->data().value
<int>();
752 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
753 for (int i
= gotoIndex
- urlNavigator
->historyIndex(); i
> 0; --i
) {
758 void DolphinMainWindow::slotBackForwardActionMiddleClicked(QAction
* action
)
761 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
762 openNewTabAfterCurrentTab(urlNavigator
->locationUrl(action
->data().value
<int>()));
766 void DolphinMainWindow::slotAboutToShowForwardPopupMenu()
768 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
770 m_forwardAction
->menu()->clear();
771 for (int i
= urlNavigator
->historyIndex() - 1; i
>= 0 && entries
< MaxNumberOfNavigationentries
; --i
, ++entries
) {
772 QAction
* action
= new QAction(urlNavigator
->locationUrl(i
).toString(QUrl::PreferLocalFile
), m_forwardAction
->menu());
774 m_forwardAction
->menu()->addAction(action
);
778 void DolphinMainWindow::slotGoForward(QAction
* action
)
780 int gotoIndex
= action
->data().value
<int>();
781 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
782 for (int i
= urlNavigator
->historyIndex() - gotoIndex
; i
> 0; --i
) {
787 void DolphinMainWindow::selectAll()
791 // if the URL navigator is editable and focused, select the whole
792 // URL instead of all items of the view
794 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
795 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit();
796 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
797 lineEdit
->hasFocus();
799 lineEdit
->selectAll();
801 m_activeViewContainer
->view()->selectAll();
805 void DolphinMainWindow::invertSelection()
808 m_activeViewContainer
->view()->invertSelection();
811 void DolphinMainWindow::toggleSplitView()
813 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
814 tabPage
->setSplitViewEnabled(!tabPage
->splitViewEnabled());
819 void DolphinMainWindow::toggleSplitStash()
821 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
822 tabPage
->setSplitViewEnabled(false);
823 tabPage
->setSplitViewEnabled(true, QUrl("stash:/"));
826 void DolphinMainWindow::reloadView()
829 m_activeViewContainer
->reload();
830 m_activeViewContainer
->statusBar()->updateSpaceInfo();
833 void DolphinMainWindow::stopLoading()
835 m_activeViewContainer
->view()->stopLoading();
838 void DolphinMainWindow::enableStopAction()
840 actionCollection()->action(QStringLiteral("stop"))->setEnabled(true);
843 void DolphinMainWindow::disableStopAction()
845 actionCollection()->action(QStringLiteral("stop"))->setEnabled(false);
848 void DolphinMainWindow::showFilterBar()
850 m_activeViewContainer
->setFilterBarVisible(true);
853 void DolphinMainWindow::toggleEditLocation()
857 QAction
* action
= actionCollection()->action(QStringLiteral("editable_location"));
858 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
859 urlNavigator
->setUrlEditable(action
->isChecked());
862 void DolphinMainWindow::replaceLocation()
864 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
865 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit();
867 // If the text field currently has focus and everything is selected,
868 // pressing the keyboard shortcut returns the whole thing to breadcrumb mode
869 if (navigator
->isUrlEditable()
870 && lineEdit
->hasFocus()
871 && lineEdit
->selectedText() == lineEdit
->text() ) {
872 navigator
->setUrlEditable(false);
874 navigator
->setUrlEditable(true);
875 navigator
->setFocus();
876 lineEdit
->selectAll();
880 void DolphinMainWindow::togglePanelLockState()
882 const bool newLockState
= !GeneralSettings::lockPanels();
883 const auto childrenObjects
= children();
884 for (QObject
* child
: childrenObjects
) {
885 DolphinDockWidget
* dock
= qobject_cast
<DolphinDockWidget
*>(child
);
887 dock
->setLocked(newLockState
);
891 GeneralSettings::setLockPanels(newLockState
);
894 void DolphinMainWindow::slotTerminalPanelVisibilityChanged()
896 if (m_terminalPanel
->isHiddenInVisibleWindow() && m_activeViewContainer
) {
897 m_activeViewContainer
->view()->setFocus();
901 void DolphinMainWindow::goBack()
903 DolphinUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
904 urlNavigator
->goBack();
906 if (urlNavigator
->locationState().isEmpty()) {
907 // An empty location state indicates a redirection URL,
908 // which must be skipped too
909 urlNavigator
->goBack();
913 void DolphinMainWindow::goForward()
915 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goForward();
918 void DolphinMainWindow::goUp()
920 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goUp();
923 void DolphinMainWindow::goHome()
925 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goHome();
928 void DolphinMainWindow::goBackInNewTab()
930 const KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
931 const int index
= urlNavigator
->historyIndex() + 1;
932 openNewTabAfterCurrentTab(urlNavigator
->locationUrl(index
));
935 void DolphinMainWindow::goForwardInNewTab()
937 const KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
938 const int index
= urlNavigator
->historyIndex() - 1;
939 openNewTabAfterCurrentTab(urlNavigator
->locationUrl(index
));
942 void DolphinMainWindow::goUpInNewTab()
944 const QUrl currentUrl
= activeViewContainer()->urlNavigator()->locationUrl();
945 openNewTabAfterCurrentTab(KIO::upUrl(currentUrl
));
948 void DolphinMainWindow::goHomeInNewTab()
950 openNewTabAfterCurrentTab(Dolphin::homeUrl());
953 void DolphinMainWindow::compareFiles()
955 const KFileItemList items
= m_tabWidget
->currentTabPage()->selectedItems();
956 if (items
.count() != 2) {
957 // The action is disabled in this case, but it could have been triggered
958 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
962 QUrl urlA
= items
.at(0).url();
963 QUrl urlB
= items
.at(1).url();
965 QString
command(QStringLiteral("kompare -c \""));
966 command
.append(urlA
.toDisplayString(QUrl::PreferLocalFile
));
967 command
.append("\" \"");
968 command
.append(urlB
.toDisplayString(QUrl::PreferLocalFile
));
969 command
.append('\"');
971 KIO::CommandLauncherJob
*job
= new KIO::CommandLauncherJob(command
, this);
972 job
->setDesktopName(QStringLiteral("org.kde.kompare"));
976 void DolphinMainWindow::toggleShowMenuBar()
978 const bool visible
= menuBar()->isVisible();
979 menuBar()->setVisible(!visible
);
981 createControlButton();
983 deleteControlButton();
987 QPointer
<QAction
> DolphinMainWindow::preferredSearchTool()
989 m_searchTools
.clear();
990 KMoreToolsMenuFactory("dolphin/search-tools").fillMenuFromGroupingNames(
991 &m_searchTools
, { "files-find" }, m_activeViewContainer
->url()
993 QList
<QAction
*> actions
= m_searchTools
.actions();
994 if (actions
.isEmpty()) {
997 QAction
* action
= actions
.first();
998 if (action
->isSeparator()) {
1004 void DolphinMainWindow::updateOpenPreferredSearchToolAction()
1006 QAction
* openPreferredSearchTool
= actionCollection()->action(QStringLiteral("open_preferred_search_tool"));
1007 if (!openPreferredSearchTool
) {
1010 QPointer
<QAction
> tool
= preferredSearchTool();
1012 openPreferredSearchTool
->setVisible(true);
1013 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open %1", tool
->text()));
1014 openPreferredSearchTool
->setIcon(tool
->icon());
1016 openPreferredSearchTool
->setVisible(false);
1017 // still visible in Shortcuts configuration window
1018 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1019 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1023 void DolphinMainWindow::openPreferredSearchTool()
1025 QPointer
<QAction
> tool
= preferredSearchTool();
1031 void DolphinMainWindow::openTerminal()
1033 const QUrl url
= m_activeViewContainer
->url();
1035 if (url
.isLocalFile()) {
1036 KToolInvocation::invokeTerminal(QString(), url
.toLocalFile());
1040 // Not a local file, with protocol Class ":local", try stat'ing
1041 if (KProtocolInfo::protocolClass(url
.scheme()) == QLatin1String(":local")) {
1042 KIO::StatJob
*job
= KIO::mostLocalUrl(url
);
1043 KJobWidgets::setWindow(job
, this);
1044 connect(job
, &KJob::result
, this, [job
]() {
1046 if (!job
->error()) {
1047 statUrl
= job
->mostLocalUrl();
1050 KToolInvocation::invokeTerminal(QString(), statUrl
.isLocalFile() ? statUrl
.toLocalFile() : QDir::homePath());
1056 // Nothing worked, just use $HOME
1057 KToolInvocation::invokeTerminal(QString(), QDir::homePath());
1060 void DolphinMainWindow::editSettings()
1062 if (!m_settingsDialog
) {
1063 DolphinViewContainer
* container
= activeViewContainer();
1064 container
->view()->writeSettings();
1066 const QUrl url
= container
->url();
1067 DolphinSettingsDialog
* settingsDialog
= new DolphinSettingsDialog(url
, this);
1068 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, this, &DolphinMainWindow::refreshViews
);
1069 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
,
1070 &DolphinUrlNavigatorsController::slotReadSettings
);
1071 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1072 settingsDialog
->show();
1073 m_settingsDialog
= settingsDialog
;
1075 m_settingsDialog
.data()->raise();
1079 void DolphinMainWindow::handleUrl(const QUrl
& url
)
1081 delete m_lastHandleUrlOpenJob
;
1082 m_lastHandleUrlOpenJob
= nullptr;
1084 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1085 activeViewContainer()->setUrl(url
);
1087 m_lastHandleUrlOpenJob
= new KIO::OpenUrlJob(url
);
1088 m_lastHandleUrlOpenJob
->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
1089 m_lastHandleUrlOpenJob
->setRunExecutables(true);
1091 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::mimeTypeFound
, this,
1092 [this, url
](const QString
&mimetype
) {
1093 if (mimetype
== QLatin1String("inode/directory")) {
1094 // If it's a dir, we'll take it from here
1095 m_lastHandleUrlOpenJob
->kill();
1096 m_lastHandleUrlOpenJob
= nullptr;
1097 activeViewContainer()->setUrl(url
);
1101 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::result
, this, [this]() {
1102 m_lastHandleUrlOpenJob
= nullptr;
1105 m_lastHandleUrlOpenJob
->start();
1109 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1111 // trash:/ is writable but we don't want to create new items in it.
1112 // TODO: remove the trash check once https://phabricator.kde.org/T8234 is implemented
1113 newFileMenu()->setEnabled(isFolderWritable
&& m_activeViewContainer
->url().scheme() != QLatin1String("trash"));
1116 void DolphinMainWindow::openContextMenu(const QPoint
& pos
,
1117 const KFileItem
& item
,
1119 const QList
<QAction
*>& customActions
)
1121 QPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, pos
, item
, url
);
1122 contextMenu
.data()->setCustomActions(customActions
);
1123 const DolphinContextMenu::Command command
= contextMenu
.data()->open();
1126 case DolphinContextMenu::OpenParentFolder
:
1127 changeUrl(KIO::upUrl(item
.url()));
1128 m_activeViewContainer
->view()->markUrlsAsSelected({item
.url()});
1129 m_activeViewContainer
->view()->markUrlAsCurrent(item
.url());
1132 case DolphinContextMenu::OpenParentFolderInNewWindow
:
1133 Dolphin::openNewWindow({item
.url()}, this, Dolphin::OpenNewWindowFlag::Select
);
1136 case DolphinContextMenu::OpenParentFolderInNewTab
:
1137 openNewTabAfterLastTab(KIO::upUrl(item
.url()));
1140 case DolphinContextMenu::None
:
1145 // Delete the menu, unless it has been deleted in its own nested event loop already.
1147 contextMenu
->deleteLater();
1151 void DolphinMainWindow::updateControlMenu()
1153 QMenu
* menu
= qobject_cast
<QMenu
*>(sender());
1156 // All actions get cleared by QMenu::clear(). This includes the sub-menus
1157 // because 'menu' is their parent.
1160 KActionCollection
* ac
= actionCollection();
1162 menu
->addMenu(m_newFileMenu
->menu());
1163 addActionToMenu(ac
->action(QStringLiteral("file_new")), menu
);
1164 addActionToMenu(ac
->action(QStringLiteral("new_tab")), menu
);
1165 addActionToMenu(ac
->action(QStringLiteral("closed_tabs")), menu
);
1167 menu
->addSeparator();
1169 // Add "Edit" actions
1170 bool added
= addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Undo
)), menu
) |
1171 addActionToMenu(ac
->action(QString("copy_location")), menu
) |
1172 addActionToMenu(ac
->action(QStringLiteral("copy_to_inactive_split_view")), menu
) |
1173 addActionToMenu(ac
->action(QStringLiteral("move_to_inactive_split_view")), menu
) |
1174 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::SelectAll
)), menu
) |
1175 addActionToMenu(ac
->action(QStringLiteral("invert_selection")), menu
);
1178 menu
->addSeparator();
1181 // Add "View" actions
1182 if (!GeneralSettings::showZoomSlider()) {
1183 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomIn
)), menu
);
1184 addActionToMenu(ac
->action(QStringLiteral("view_zoom_reset")), menu
);
1185 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomOut
)), menu
);
1186 menu
->addSeparator();
1189 added
= addActionToMenu(ac
->action(QStringLiteral("show_preview")), menu
) |
1190 addActionToMenu(ac
->action(QStringLiteral("show_in_groups")), menu
) |
1191 addActionToMenu(ac
->action(QStringLiteral("show_hidden_files")), menu
) |
1192 addActionToMenu(ac
->action(QStringLiteral("additional_info")), menu
) |
1193 addActionToMenu(ac
->action(QStringLiteral("view_properties")), menu
);
1196 menu
->addSeparator();
1199 // Add a curated assortment of items from the "Tools" menu
1200 addActionToMenu(ac
->action(QStringLiteral("show_filter_bar")), menu
);
1201 addActionToMenu(ac
->action(QStringLiteral("open_preferred_search_tool")), menu
);
1202 addActionToMenu(ac
->action(QStringLiteral("open_terminal")), menu
);
1204 menu
->addSeparator();
1206 // Add "Show Panels" menu
1207 addActionToMenu(ac
->action(QStringLiteral("panels")), menu
);
1209 // Add "Settings" menu entries
1210 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)), menu
);
1211 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)), menu
);
1212 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Preferences
)), menu
);
1213 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)), menu
);
1216 auto helpMenu
= m_helpMenu
->menu();
1217 helpMenu
->setIcon(QIcon::fromTheme(QStringLiteral("system-help")));
1218 menu
->addMenu(helpMenu
);
1221 void DolphinMainWindow::updateToolBar()
1223 if (!menuBar()->isVisible()) {
1224 createControlButton();
1228 void DolphinMainWindow::slotControlButtonDeleted()
1230 m_controlButton
= nullptr;
1231 m_updateToolBarTimer
->start();
1234 void DolphinMainWindow::slotPlaceActivated(const QUrl
& url
)
1236 DolphinViewContainer
* view
= activeViewContainer();
1238 if (view
->url() == url
) {
1239 // We can end up here if the user clicked a device in the Places Panel
1240 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1247 void DolphinMainWindow::closedTabsCountChanged(unsigned int count
)
1249 actionCollection()->action(QStringLiteral("undo_close_tab"))->setEnabled(count
> 0);
1252 void DolphinMainWindow::activeViewChanged(DolphinViewContainer
* viewContainer
)
1254 DolphinViewContainer
* oldViewContainer
= m_activeViewContainer
;
1255 Q_ASSERT(viewContainer
);
1257 m_activeViewContainer
= viewContainer
;
1259 if (oldViewContainer
) {
1260 const QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
1261 toggleSearchAction
->disconnect(oldViewContainer
);
1263 // Disconnect all signals between the old view container (container,
1264 // view and url navigator) and main window.
1265 oldViewContainer
->disconnect(this);
1266 oldViewContainer
->view()->disconnect(this);
1267 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
1268 (actionCollection()->action(QStringLiteral("url_navigators")));
1269 navigators
->primaryUrlNavigator()->disconnect(this);
1270 if (auto secondaryUrlNavigator
= navigators
->secondaryUrlNavigator()) {
1271 secondaryUrlNavigator
->disconnect(this);
1274 // except the requestItemInfo so that on hover the information panel can still be updated
1275 connect(oldViewContainer
->view(), &DolphinView::requestItemInfo
,
1276 this, &DolphinMainWindow::requestItemInfo
);
1279 connectViewSignals(viewContainer
);
1281 m_actionHandler
->setCurrentView(viewContainer
->view());
1284 updateFileAndEditActions();
1285 updatePasteAction();
1286 updateViewActions();
1288 updateSearchAction();
1290 const QUrl url
= viewContainer
->url();
1291 Q_EMIT
urlChanged(url
);
1294 void DolphinMainWindow::tabCountChanged(int count
)
1296 const bool enableTabActions
= (count
> 1);
1297 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1298 actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i
))->setEnabled(enableTabActions
);
1300 actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions
);
1301 actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions
);
1302 actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions
);
1305 void DolphinMainWindow::updateWindowTitle()
1307 const QString newTitle
= m_activeViewContainer
->captionWindowTitle();
1308 if (windowTitle() != newTitle
) {
1309 setWindowTitle(newTitle
);
1313 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString
& mountPath
)
1315 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1316 setViewsToHomeIfMountPathOpen(mountPath
);
1319 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectory().startsWith(mountPath
)) {
1320 m_tearDownFromPlacesRequested
= true;
1321 m_terminalPanel
->goHome();
1322 // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
1324 m_placesPanel
->proceedWithTearDown();
1328 void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString
& mountPath
)
1330 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1331 setViewsToHomeIfMountPathOpen(mountPath
);
1334 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectory().startsWith(mountPath
)) {
1335 m_tearDownFromPlacesRequested
= false;
1336 m_terminalPanel
->goHome();
1340 void DolphinMainWindow::setViewsToHomeIfMountPathOpen(const QString
& mountPath
)
1342 const QVector
<DolphinViewContainer
*> theViewContainers
= viewContainers();
1343 for (DolphinViewContainer
*viewContainer
: theViewContainers
) {
1344 if (viewContainer
&& viewContainer
->url().toLocalFile().startsWith(mountPath
)) {
1345 viewContainer
->setUrl(QUrl::fromLocalFile(QDir::homePath()));
1348 disconnect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, nullptr, nullptr);
1351 void DolphinMainWindow::setupActions()
1353 // setup 'File' menu
1354 m_newFileMenu
= new DolphinNewFileMenu(actionCollection(), this);
1355 QMenu
* menu
= m_newFileMenu
->menu();
1356 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1357 menu
->setIcon(QIcon::fromTheme(QStringLiteral("document-new")));
1358 m_newFileMenu
->setDelayed(false);
1359 connect(menu
, &QMenu::aboutToShow
,
1360 this, &DolphinMainWindow::updateNewMenu
);
1362 QAction
* newWindow
= KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow
, actionCollection());
1363 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1364 newWindow
->setToolTip(i18nc("@info", "Open a new Dolphin window"));
1365 newWindow
->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1366 "window just like this one with the current location and view."
1367 "<nl/>You can drag and drop items between windows."));
1368 newWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1370 QAction
* newTab
= actionCollection()->addAction(QStringLiteral("new_tab"));
1371 newTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1372 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1373 newTab
->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1374 "<emphasis>Tab</emphasis> with the current location and view.<nl/>"
1375 "A tab is an additional view within this window. "
1376 "You can drag and drop items between tabs."));
1377 actionCollection()->setDefaultShortcuts(newTab
, {Qt::CTRL
+ Qt::Key_T
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_N
});
1378 connect(newTab
, &QAction::triggered
, this, &DolphinMainWindow::openNewActivatedTab
);
1380 QAction
* addToPlaces
= actionCollection()->addAction(QStringLiteral("add_to_places"));
1381 addToPlaces
->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new")));
1382 addToPlaces
->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places"));
1383 addToPlaces
->setWhatsThis(xi18nc("@info:whatsthis", "This adds the selected folder "
1384 "to the Places panel."));
1385 connect(addToPlaces
, &QAction::triggered
, this, &DolphinMainWindow::addToPlaces
);
1387 QAction
* closeTab
= KStandardAction::close(m_tabWidget
, QOverload
<>::of(&DolphinTabWidget::closeTab
), actionCollection());
1388 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1389 closeTab
->setWhatsThis(i18nc("@info:whatsthis", "This closes the "
1390 "currently viewed tab. If no more tabs are left this window "
1391 "will close instead."));
1393 QAction
* quitAction
= KStandardAction::quit(this, &DolphinMainWindow::quit
, actionCollection());
1394 quitAction
->setWhatsThis(i18nc("@info:whatsthis quit", "This closes this window."));
1396 // setup 'Edit' menu
1397 KStandardAction::undo(this,
1398 &DolphinMainWindow::undo
,
1399 actionCollection());
1401 // i18n: This will be the last paragraph for the whatsthis for all three:
1402 // Cut, Copy and Paste
1403 const QString cutCopyPastePara
= xi18nc("@info:whatsthis", "<para><emphasis>Cut, "
1404 "Copy</emphasis> and <emphasis>Paste</emphasis> work between many "
1405 "applications and are among the most used commands. That's why their "
1406 "<emphasis>keyboard shortcuts</emphasis> are prominently placed right "
1407 "next to each other on the keyboard: <shortcut>Ctrl+X</shortcut>, "
1408 "<shortcut>Ctrl+C</shortcut> and <shortcut>Ctrl+V</shortcut>.</para>");
1409 QAction
* cutAction
= KStandardAction::cut(this, &DolphinMainWindow::cut
, actionCollection());
1410 cutAction
->setWhatsThis(xi18nc("@info:whatsthis cut", "This copies the items "
1411 "in your current selection to the <emphasis>clipboard</emphasis>.<nl/>"
1412 "Use the <emphasis>Paste</emphasis> action afterwards to copy them from "
1413 "the clipboard to a new location. The items will be removed from their "
1414 "initial location.") + cutCopyPastePara
);
1415 QAction
* copyAction
= KStandardAction::copy(this, &DolphinMainWindow::copy
, actionCollection());
1416 copyAction
->setWhatsThis(xi18nc("@info:whatsthis copy", "This copies the "
1417 "items in your current selection to the <emphasis>clipboard</emphasis>."
1418 "<nl/>Use the <emphasis>Paste</emphasis> action afterwards to copy them "
1419 "from the clipboard to a new location.") + cutCopyPastePara
);
1420 QAction
* paste
= KStandardAction::paste(this, &DolphinMainWindow::paste
, actionCollection());
1421 // The text of the paste-action is modified dynamically by Dolphin
1422 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1423 // due to the long text, the text "Paste" is used:
1424 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1425 paste
->setWhatsThis(xi18nc("@info:whatsthis paste", "This copies the items from "
1426 "your <emphasis>clipboard</emphasis> to the currently viewed folder.<nl/>"
1427 "If the items were added to the clipboard by the <emphasis>Cut</emphasis> "
1428 "action they are removed from their old location.") + cutCopyPastePara
);
1430 QAction
* copyToOtherViewAction
= actionCollection()->addAction(QStringLiteral("copy_to_inactive_split_view"));
1431 copyToOtherViewAction
->setText(i18nc("@action:inmenu", "Copy to Inactive Split View"));
1432 copyToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Copy", "This copies the selected items from "
1433 "the <emphasis>active</emphasis> view to the inactive split view."));
1434 copyToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
1435 copyToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Copy to Inactive Split View"));
1436 actionCollection()->setDefaultShortcut(copyToOtherViewAction
, Qt::SHIFT
+ Qt::Key_F5
);
1437 connect(copyToOtherViewAction
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::copyToInactiveSplitView
);
1439 QAction
* moveToOtherViewAction
= actionCollection()->addAction(QStringLiteral("move_to_inactive_split_view"));
1440 moveToOtherViewAction
->setText(i18nc("@action:inmenu", "Move to Inactive Split View"));
1441 moveToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Move", "This moves the selected items from "
1442 "the <emphasis>active</emphasis> view to the inactive split view."));
1443 moveToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-cut")));
1444 moveToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Move to Inactive Split View"));
1445 actionCollection()->setDefaultShortcut(moveToOtherViewAction
, Qt::SHIFT
+ Qt::Key_F6
);
1446 connect(moveToOtherViewAction
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::moveToInactiveSplitView
);
1448 QAction
*searchAction
= KStandardAction::find(this, &DolphinMainWindow::find
, actionCollection());
1449 searchAction
->setText(i18n("Search..."));
1450 searchAction
->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
1451 searchAction
->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This helps you "
1452 "find files and folders by opening a <emphasis>find bar</emphasis>. "
1453 "There you can enter search terms and specify settings to find the "
1454 "objects you are looking for.</para><para>Use this help again on "
1455 "the find bar so we can have a look at it while the settings are "
1456 "explained.</para>"));
1458 // toggle_search acts as a copy of the main searchAction to be used mainly
1459 // in the toolbar, with no default shortcut attached, to avoid messing with
1460 // existing workflows (search bar always open and Ctrl-F to focus)
1461 QAction
*toggleSearchAction
= actionCollection()->addAction(QStringLiteral("toggle_search"));
1462 toggleSearchAction
->setText(i18nc("@action:inmenu", "Toggle Search Bar"));
1463 toggleSearchAction
->setIconText(i18nc("@action:intoolbar", "Search"));
1464 toggleSearchAction
->setIcon(searchAction
->icon());
1465 toggleSearchAction
->setToolTip(searchAction
->toolTip());
1466 toggleSearchAction
->setWhatsThis(searchAction
->whatsThis());
1467 toggleSearchAction
->setCheckable(true);
1469 QAction
* selectAllAction
= KStandardAction::selectAll(this, &DolphinMainWindow::selectAll
, actionCollection());
1470 selectAllAction
->setWhatsThis(xi18nc("@info:whatsthis", "This selects all "
1471 "files and folders in the current location."));
1473 QAction
* invertSelection
= actionCollection()->addAction(QStringLiteral("invert_selection"));
1474 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1475 invertSelection
->setWhatsThis(xi18nc("@info:whatsthis invert", "This selects all "
1476 "objects that you have currently <emphasis>not</emphasis> selected instead."));
1477 invertSelection
->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert")));
1478 actionCollection()->setDefaultShortcut(invertSelection
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_A
);
1479 connect(invertSelection
, &QAction::triggered
, this, &DolphinMainWindow::invertSelection
);
1481 // setup 'View' menu
1482 // (note that most of it is set up in DolphinViewActionHandler)
1484 QAction
* split
= actionCollection()->addAction(QStringLiteral("split_view"));
1485 split
->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This splits "
1486 "the folder view below into two autonomous views.</para><para>This "
1487 "way you can see two locations at once and move items between them "
1488 "quickly.</para>Click this again afterwards to recombine the views."));
1489 actionCollection()->setDefaultShortcut(split
, Qt::Key_F3
);
1490 connect(split
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitView
);
1492 QAction
* stashSplit
= actionCollection()->addAction(QStringLiteral("split_stash"));
1493 actionCollection()->setDefaultShortcut(stashSplit
, Qt::CTRL
+ Qt::Key_S
);
1494 stashSplit
->setText(i18nc("@action:intoolbar Stash", "Stash"));
1495 stashSplit
->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
1496 stashSplit
->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
1497 stashSplit
->setCheckable(false);
1498 stashSplit
->setVisible(KProtocolInfo::isKnownProtocol("stash"));
1499 connect(stashSplit
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitStash
);
1501 KStandardAction::redisplay(this, &DolphinMainWindow::reloadView
, actionCollection());
1503 QAction
* stop
= actionCollection()->addAction(QStringLiteral("stop"));
1504 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1505 stop
->setToolTip(i18nc("@info", "Stop loading"));
1506 stop
->setWhatsThis(i18nc("@info", "This stops the loading of the contents of the current folder."));
1507 stop
->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
1508 connect(stop
, &QAction::triggered
, this, &DolphinMainWindow::stopLoading
);
1510 KToggleAction
* editableLocation
= actionCollection()->add
<KToggleAction
>(QStringLiteral("editable_location"));
1511 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1512 editableLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1513 "This toggles the <emphasis>Location Bar</emphasis> to be "
1514 "editable so you can directly enter a location you want to go to.<nl/>"
1515 "You can also switch to editing by clicking to the right of the "
1516 "location and switch back by confirming the edited location."));
1517 actionCollection()->setDefaultShortcut(editableLocation
, Qt::Key_F6
);
1518 connect(editableLocation
, &KToggleAction::triggered
, this, &DolphinMainWindow::toggleEditLocation
);
1520 QAction
* replaceLocation
= actionCollection()->addAction(QStringLiteral("replace_location"));
1521 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1522 // i18n: "enter" is used both in the meaning of "writing" and "going to" a new location here.
1523 // Both meanings are useful but not necessary to understand the use of "Replace Location".
1524 // So you might want to be more verbose in your language to convey the meaning but it's up to you.
1525 replaceLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1526 "This switches to editing the location and selects it "
1527 "so you can quickly enter a different location."));
1528 actionCollection()->setDefaultShortcut(replaceLocation
, Qt::CTRL
+ Qt::Key_L
);
1529 connect(replaceLocation
, &QAction::triggered
, this, &DolphinMainWindow::replaceLocation
);
1533 QScopedPointer
<QAction
> backAction(KStandardAction::back(nullptr, nullptr, nullptr));
1534 m_backAction
= new KToolBarPopupAction(backAction
->icon(), backAction
->text(), actionCollection());
1535 m_backAction
->setObjectName(backAction
->objectName());
1536 m_backAction
->setShortcuts(backAction
->shortcuts());
1538 m_backAction
->setDelayed(true);
1539 m_backAction
->setStickyMenu(false);
1540 connect(m_backAction
, &QAction::triggered
, this, &DolphinMainWindow::goBack
);
1541 connect(m_backAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowBackPopupMenu
);
1542 connect(m_backAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoBack
);
1543 actionCollection()->addAction(m_backAction
->objectName(), m_backAction
);
1545 auto backShortcuts
= m_backAction
->shortcuts();
1546 backShortcuts
.append(QKeySequence(Qt::Key_Backspace
));
1547 actionCollection()->setDefaultShortcuts(m_backAction
, backShortcuts
);
1549 DolphinRecentTabsMenu
* recentTabsMenu
= new DolphinRecentTabsMenu(this);
1550 actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu
);
1551 connect(m_tabWidget
, &DolphinTabWidget::rememberClosedTab
,
1552 recentTabsMenu
, &DolphinRecentTabsMenu::rememberClosedTab
);
1553 connect(recentTabsMenu
, &DolphinRecentTabsMenu::restoreClosedTab
,
1554 m_tabWidget
, &DolphinTabWidget::restoreClosedTab
);
1555 connect(recentTabsMenu
, &DolphinRecentTabsMenu::closedTabsCountChanged
,
1556 this, &DolphinMainWindow::closedTabsCountChanged
);
1558 QAction
* undoCloseTab
= actionCollection()->addAction(QStringLiteral("undo_close_tab"));
1559 undoCloseTab
->setText(i18nc("@action:inmenu File", "Undo close tab"));
1560 undoCloseTab
->setWhatsThis(i18nc("@info:whatsthis undo close tab",
1561 "This returns you to the previously closed tab."));
1562 actionCollection()->setDefaultShortcut(undoCloseTab
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_T
);
1563 undoCloseTab
->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
1564 undoCloseTab
->setEnabled(false);
1565 connect(undoCloseTab
, &QAction::triggered
, recentTabsMenu
, &DolphinRecentTabsMenu::undoCloseTab
);
1567 auto undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
1568 undoAction
->setWhatsThis(xi18nc("@info:whatsthis", "This undoes "
1569 "the last change you made to files or folders.<nl/>"
1570 "Such changes include <interface>creating, renaming</interface> "
1571 "and <interface>moving</interface> them to a different location "
1572 "or to the <filename>Trash</filename>. <nl/>Changes that can't "
1573 "be undone will ask for your confirmation."));
1574 undoAction
->setEnabled(false); // undo should be disabled by default
1577 QScopedPointer
<QAction
> forwardAction(KStandardAction::forward(nullptr, nullptr, nullptr));
1578 m_forwardAction
= new KToolBarPopupAction(forwardAction
->icon(), forwardAction
->text(), actionCollection());
1579 m_forwardAction
->setObjectName(forwardAction
->objectName());
1580 m_forwardAction
->setShortcuts(forwardAction
->shortcuts());
1582 m_forwardAction
->setDelayed(true);
1583 m_forwardAction
->setStickyMenu(false);
1584 connect(m_forwardAction
, &QAction::triggered
, this, &DolphinMainWindow::goForward
);
1585 connect(m_forwardAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowForwardPopupMenu
);
1586 connect(m_forwardAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoForward
);
1587 actionCollection()->addAction(m_forwardAction
->objectName(), m_forwardAction
);
1588 actionCollection()->setDefaultShortcuts(m_forwardAction
, m_forwardAction
->shortcuts());
1590 // enable middle-click to open in a new tab
1591 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
1592 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotBackForwardActionMiddleClicked
);
1593 m_backAction
->menu()->installEventFilter(middleClickEventFilter
);
1594 m_forwardAction
->menu()->installEventFilter(middleClickEventFilter
);
1595 KStandardAction::up(this, &DolphinMainWindow::goUp
, actionCollection());
1596 QAction
* homeAction
= KStandardAction::home(this, &DolphinMainWindow::goHome
, actionCollection());
1597 homeAction
->setWhatsThis(xi18nc("@info:whatsthis", "Go to your "
1598 "<filename>Home</filename> folder.<nl/>Every user account "
1599 "has their own <filename>Home</filename> that contains their data "
1600 "including folders that contain personal application data."));
1602 // setup 'Tools' menu
1603 QAction
* showFilterBar
= actionCollection()->addAction(QStringLiteral("show_filter_bar"));
1604 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1605 showFilterBar
->setWhatsThis(xi18nc("@info:whatsthis", "This opens the "
1606 "<emphasis>Filter Bar</emphasis> at the bottom of the window.<nl/> "
1607 "There you can enter a text to filter the files and folders currently displayed. "
1608 "Only those that contain the text in their name will be kept in view."));
1609 showFilterBar
->setIcon(QIcon::fromTheme(QStringLiteral("view-filter")));
1610 actionCollection()->setDefaultShortcuts(showFilterBar
, {Qt::CTRL
+ Qt::Key_I
, Qt::Key_Slash
});
1611 connect(showFilterBar
, &QAction::triggered
, this, &DolphinMainWindow::showFilterBar
);
1613 QAction
* compareFiles
= actionCollection()->addAction(QStringLiteral("compare_files"));
1614 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1615 compareFiles
->setIcon(QIcon::fromTheme(QStringLiteral("kompare")));
1616 compareFiles
->setEnabled(false);
1617 connect(compareFiles
, &QAction::triggered
, this, &DolphinMainWindow::compareFiles
);
1619 QAction
* openPreferredSearchTool
= actionCollection()->addAction(QStringLiteral("open_preferred_search_tool"));
1620 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1621 openPreferredSearchTool
->setWhatsThis(xi18nc("@info:whatsthis",
1622 "<para>This opens a preferred search tool for the viewed location.</para>"
1623 "<para>Use <emphasis>More Search Tools</emphasis> menu to configure it.</para>"));
1624 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1625 actionCollection()->setDefaultShortcut(openPreferredSearchTool
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_F
);
1626 connect(openPreferredSearchTool
, &QAction::triggered
, this, &DolphinMainWindow::openPreferredSearchTool
);
1628 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1629 QAction
* openTerminal
= actionCollection()->addAction(QStringLiteral("open_terminal"));
1630 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1631 openTerminal
->setWhatsThis(xi18nc("@info:whatsthis",
1632 "<para>This opens a <emphasis>terminal</emphasis> application for the viewed location.</para>"
1633 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1634 openTerminal
->setIcon(QIcon::fromTheme(QStringLiteral("dialog-scripts")));
1635 actionCollection()->setDefaultShortcut(openTerminal
, Qt::SHIFT
+ Qt::Key_F4
);
1636 connect(openTerminal
, &QAction::triggered
, this, &DolphinMainWindow::openTerminal
);
1638 #ifdef HAVE_TERMINAL
1639 QAction
* focusTerminalPanel
= actionCollection()->addAction(QStringLiteral("focus_terminal_panel"));
1640 focusTerminalPanel
->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
1641 focusTerminalPanel
->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
1642 actionCollection()->setDefaultShortcut(focusTerminalPanel
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_F4
);
1643 connect(focusTerminalPanel
, &QAction::triggered
, this, &DolphinMainWindow::focusTerminalPanel
);
1647 // setup 'Bookmarks' menu
1648 KActionMenu
*bookmarkMenu
= new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this);
1649 bookmarkMenu
->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks")));
1650 // Make the toolbar button version work properly on click
1651 bookmarkMenu
->setDelayed(false);
1652 m_bookmarkHandler
= new DolphinBookmarkHandler(this, actionCollection(), bookmarkMenu
->menu(), this);
1653 actionCollection()->addAction(QStringLiteral("bookmarks"), bookmarkMenu
);
1655 // setup 'Settings' menu
1656 KToggleAction
* showMenuBar
= KStandardAction::showMenubar(nullptr, nullptr, actionCollection());
1657 showMenuBar
->setWhatsThis(xi18nc("@info:whatsthis",
1658 "This switches between having a <emphasis>Menubar</emphasis> "
1659 "and having a <interface>Control</interface> button. Both "
1660 "contain mostly the same commands and configuration options."));
1661 connect(showMenuBar
, &KToggleAction::triggered
, // Fixes #286822
1662 this, &DolphinMainWindow::toggleShowMenuBar
, Qt::QueuedConnection
);
1663 KStandardAction::preferences(this, &DolphinMainWindow::editSettings
, actionCollection());
1665 // setup 'Help' menu for the m_controlButton. The other one is set up in the base class.
1666 m_helpMenu
= new KHelpMenu(nullptr);
1667 m_helpMenu
->menu()->installEventFilter(this);
1668 // remove duplicate shortcuts
1669 m_helpMenu
->action(KHelpMenu::menuHelpContents
)->setShortcut(QKeySequence());
1670 m_helpMenu
->action(KHelpMenu::menuWhatsThis
)->setShortcut(QKeySequence());
1672 // not in menu actions
1673 QList
<QKeySequence
> nextTabKeys
= KStandardShortcut::tabNext();
1674 nextTabKeys
.append(QKeySequence(Qt::CTRL
+ Qt::Key_Tab
));
1676 QList
<QKeySequence
> prevTabKeys
= KStandardShortcut::tabPrev();
1677 prevTabKeys
.append(QKeySequence(Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_Tab
));
1679 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1680 QAction
* activateTab
= actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i
));
1681 activateTab
->setText(i18nc("@action:inmenu", "Activate Tab %1", i
+ 1));
1682 activateTab
->setEnabled(false);
1683 connect(activateTab
, &QAction::triggered
, this, [this, i
]() { m_tabWidget
->activateTab(i
); });
1685 // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts
1687 actionCollection()->setDefaultShortcut(activateTab
, QStringLiteral("Alt+%1").arg(i
+ 1));
1691 QAction
* activateLastTab
= actionCollection()->addAction(QStringLiteral("activate_last_tab"));
1692 activateLastTab
->setText(i18nc("@action:inmenu", "Activate Last Tab"));
1693 activateLastTab
->setEnabled(false);
1694 connect(activateLastTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateLastTab
);
1695 actionCollection()->setDefaultShortcut(activateLastTab
, Qt::ALT
+ Qt::Key_0
);
1697 QAction
* activateNextTab
= actionCollection()->addAction(QStringLiteral("activate_next_tab"));
1698 activateNextTab
->setIconText(i18nc("@action:inmenu", "Next Tab"));
1699 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1700 activateNextTab
->setEnabled(false);
1701 connect(activateNextTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateNextTab
);
1702 actionCollection()->setDefaultShortcuts(activateNextTab
, nextTabKeys
);
1704 QAction
* activatePrevTab
= actionCollection()->addAction(QStringLiteral("activate_prev_tab"));
1705 activatePrevTab
->setIconText(i18nc("@action:inmenu", "Previous Tab"));
1706 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1707 activatePrevTab
->setEnabled(false);
1708 connect(activatePrevTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activatePrevTab
);
1709 actionCollection()->setDefaultShortcuts(activatePrevTab
, prevTabKeys
);
1712 QAction
* showTarget
= actionCollection()->addAction(QStringLiteral("show_target"));
1713 showTarget
->setText(i18nc("@action:inmenu", "Show Target"));
1714 showTarget
->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
1715 showTarget
->setEnabled(false);
1716 connect(showTarget
, &QAction::triggered
, this, &DolphinMainWindow::showTarget
);
1718 QAction
* openInNewTab
= actionCollection()->addAction(QStringLiteral("open_in_new_tab"));
1719 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1720 openInNewTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1721 connect(openInNewTab
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
1723 QAction
* openInNewTabs
= actionCollection()->addAction(QStringLiteral("open_in_new_tabs"));
1724 openInNewTabs
->setText(i18nc("@action:inmenu", "Open in New Tabs"));
1725 openInNewTabs
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1726 connect(openInNewTabs
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
1728 QAction
* openInNewWindow
= actionCollection()->addAction(QStringLiteral("open_in_new_window"));
1729 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1730 openInNewWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1731 connect(openInNewWindow
, &QAction::triggered
, this, &DolphinMainWindow::openInNewWindow
);
1734 void DolphinMainWindow::setupDockWidgets()
1736 const bool lock
= GeneralSettings::lockPanels();
1738 KDualAction
* lockLayoutAction
= actionCollection()->add
<KDualAction
>(QStringLiteral("lock_panels"));
1739 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1740 lockLayoutAction
->setActiveIcon(QIcon::fromTheme(QStringLiteral("object-unlocked")));
1741 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1742 lockLayoutAction
->setInactiveIcon(QIcon::fromTheme(QStringLiteral("object-locked")));
1743 lockLayoutAction
->setWhatsThis(xi18nc("@info:whatsthis", "This "
1744 "switches between having panels <emphasis>locked</emphasis> or "
1745 "<emphasis>unlocked</emphasis>.<nl/>Unlocked panels can be "
1746 "dragged to the other side of the window and have a close "
1747 "button.<nl/>Locked panels are embedded more cleanly."));
1748 lockLayoutAction
->setActive(lock
);
1749 connect(lockLayoutAction
, &KDualAction::triggered
, this, &DolphinMainWindow::togglePanelLockState
);
1751 // Setup "Information"
1752 DolphinDockWidget
* infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
1753 infoDock
->setLocked(lock
);
1754 infoDock
->setObjectName(QStringLiteral("infoDock"));
1755 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1758 InformationPanel
* infoPanel
= new InformationPanel(infoDock
);
1759 infoPanel
->setCustomContextMenuActions({lockLayoutAction
});
1760 connect(infoPanel
, &InformationPanel::urlActivated
, this, &DolphinMainWindow::handleUrl
);
1761 infoDock
->setWidget(infoPanel
);
1763 QAction
* infoAction
= infoDock
->toggleViewAction();
1764 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-information")), Qt::Key_F11
, infoAction
, QStringLiteral("show_information_panel"));
1766 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1767 connect(this, &DolphinMainWindow::urlChanged
,
1768 infoPanel
, &InformationPanel::setUrl
);
1769 connect(this, &DolphinMainWindow::selectionChanged
,
1770 infoPanel
, &InformationPanel::setSelection
);
1771 connect(this, &DolphinMainWindow::requestItemInfo
,
1772 infoPanel
, &InformationPanel::requestDelayedItemInfo
);
1775 // i18n: This is the last paragraph for the "What's This"-texts of all four panels.
1776 const QString panelWhatsThis
= xi18nc("@info:whatsthis", "<para>To show or "
1777 "hide panels like this go to <interface>Control|Panels</interface> "
1778 "or <interface>View|Panels</interface>.</para>");
1780 actionCollection()->action(QStringLiteral("show_information_panel"))
1781 ->setWhatsThis(xi18nc("@info:whatsthis", "<para> This toggles the "
1782 "<emphasis>information</emphasis> panel at the right side of the "
1783 "window.</para><para>The panel provides in-depth information "
1784 "about the items your mouse is hovering over or about the selected "
1785 "items. Otherwise it informs you about the currently viewed folder.<nl/>"
1786 "For single items a preview of their contents is provided.</para>"));
1788 infoDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
1789 "provides in-depth information about the items your mouse is "
1790 "hovering over or about the selected items. Otherwise it informs "
1791 "you about the currently viewed folder.<nl/>For single items a "
1792 "preview of their contents is provided.</para><para>You can configure "
1793 "which and how details are given here by right-clicking.</para>") + panelWhatsThis
);
1796 DolphinDockWidget
* foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
1797 foldersDock
->setLocked(lock
);
1798 foldersDock
->setObjectName(QStringLiteral("foldersDock"));
1799 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1800 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1801 foldersPanel
->setCustomContextMenuActions({lockLayoutAction
});
1802 foldersDock
->setWidget(foldersPanel
);
1804 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1805 createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7
, foldersAction
, QStringLiteral("show_folders_panel"));
1807 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1808 connect(this, &DolphinMainWindow::urlChanged
,
1809 foldersPanel
, &FoldersPanel::setUrl
);
1810 connect(foldersPanel
, &FoldersPanel::folderActivated
,
1811 this, &DolphinMainWindow::changeUrl
);
1812 connect(foldersPanel
, &FoldersPanel::folderMiddleClicked
,
1813 this, &DolphinMainWindow::openNewTabAfterCurrentTab
);
1814 connect(foldersPanel
, &FoldersPanel::errorMessage
,
1815 this, &DolphinMainWindow::showErrorMessage
);
1817 actionCollection()->action(QStringLiteral("show_folders_panel"))
1818 ->setWhatsThis(xi18nc("@info:whatsthis", "This toggles the "
1819 "<emphasis>folders</emphasis> panel at the left side of the window."
1820 "<nl/><nl/>It shows the folders of the <emphasis>file system"
1821 "</emphasis> in a <emphasis>tree view</emphasis>."));
1822 foldersDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
1823 "shows the folders of the <emphasis>file system</emphasis> in a "
1824 "<emphasis>tree view</emphasis>.</para><para>Click a folder to go "
1825 "there. Click the arrow to the left of a folder to see its subfolders. "
1826 "This allows quick switching between any folders.</para>") + panelWhatsThis
);
1829 #ifdef HAVE_TERMINAL
1830 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1831 DolphinDockWidget
* terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1832 terminalDock
->setLocked(lock
);
1833 terminalDock
->setObjectName(QStringLiteral("terminalDock"));
1834 m_terminalPanel
= new TerminalPanel(terminalDock
);
1835 m_terminalPanel
->setCustomContextMenuActions({lockLayoutAction
});
1836 terminalDock
->setWidget(m_terminalPanel
);
1838 connect(m_terminalPanel
, &TerminalPanel::hideTerminalPanel
, terminalDock
, &DolphinDockWidget::hide
);
1839 connect(m_terminalPanel
, &TerminalPanel::changeUrl
, this, &DolphinMainWindow::slotTerminalDirectoryChanged
);
1840 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
,
1841 m_terminalPanel
, &TerminalPanel::dockVisibilityChanged
);
1842 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
,
1843 this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged
);
1845 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1846 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4
, terminalAction
, QStringLiteral("show_terminal_panel"));
1848 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1849 connect(this, &DolphinMainWindow::urlChanged
,
1850 m_terminalPanel
, &TerminalPanel::setUrl
);
1852 if (GeneralSettings::version() < 200) {
1853 terminalDock
->hide();
1856 actionCollection()->action(QStringLiteral("show_terminal_panel"))
1857 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
1858 "<emphasis>terminal</emphasis> panel at the bottom of the window."
1859 "<nl/>The location in the terminal will always match the folder "
1860 "view so you can navigate using either.</para><para>The terminal "
1861 "panel is not needed for basic computer usage but can be useful "
1862 "for advanced tasks. To learn more about terminals use the help "
1863 "in a standalone terminal application like Konsole.</para>"));
1864 terminalDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is "
1865 "the <emphasis>terminal</emphasis> panel. It behaves like a "
1866 "normal terminal but will match the location of the folder view "
1867 "so you can navigate using either.</para><para>The terminal panel "
1868 "is not needed for basic computer usage but can be useful for "
1869 "advanced tasks. To learn more about terminals use the help in a "
1870 "standalone terminal application like Konsole.</para>") + panelWhatsThis
);
1874 if (GeneralSettings::version() < 200) {
1876 foldersDock
->hide();
1880 DolphinDockWidget
* placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
1881 placesDock
->setLocked(lock
);
1882 placesDock
->setObjectName(QStringLiteral("placesDock"));
1883 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1885 m_placesPanel
= new PlacesPanel(placesDock
);
1886 m_placesPanel
->setCustomContextMenuActions({lockLayoutAction
});
1887 placesDock
->setWidget(m_placesPanel
);
1889 QAction
*placesAction
= placesDock
->toggleViewAction();
1890 createPanelAction(QIcon::fromTheme(QStringLiteral("bookmarks")), Qt::Key_F9
, placesAction
, QStringLiteral("show_places_panel"));
1892 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1893 connect(m_placesPanel
, &PlacesPanel::placeActivated
,
1894 this, &DolphinMainWindow::slotPlaceActivated
);
1895 connect(m_placesPanel
, &PlacesPanel::placeMiddleClicked
,
1896 this, &DolphinMainWindow::openNewTabAfterCurrentTab
);
1897 connect(m_placesPanel
, &PlacesPanel::errorMessage
,
1898 this, &DolphinMainWindow::showErrorMessage
);
1899 connect(this, &DolphinMainWindow::urlChanged
,
1900 m_placesPanel
, &PlacesPanel::setUrl
);
1901 connect(placesDock
, &DolphinDockWidget::visibilityChanged
,
1902 &DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged
);
1903 connect(this, &DolphinMainWindow::settingsChanged
,
1904 m_placesPanel
, &PlacesPanel::readSettings
);
1905 connect(m_placesPanel
, &PlacesPanel::storageTearDownRequested
,
1906 this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested
);
1907 connect(m_placesPanel
, &PlacesPanel::storageTearDownExternallyRequested
,
1908 this, &DolphinMainWindow::slotStorageTearDownExternallyRequested
);
1909 DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged(m_placesPanel
->isVisible());
1911 auto actionShowAllPlaces
= new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this);
1912 actionShowAllPlaces
->setCheckable(true);
1913 actionShowAllPlaces
->setDisabled(true);
1914 actionShowAllPlaces
->setWhatsThis(i18nc("@info:whatsthis", "This displays "
1915 "all places in the places panel that have been hidden. They will "
1916 "appear semi-transparent unless you uncheck their hide property."));
1918 connect(actionShowAllPlaces
, &QAction::triggered
, this, [actionShowAllPlaces
, this](bool checked
){
1919 actionShowAllPlaces
->setIcon(QIcon::fromTheme(checked
? QStringLiteral("view-visible") : QStringLiteral("view-hidden")));
1920 m_placesPanel
->showHiddenEntries(checked
);
1923 connect(m_placesPanel
, &PlacesPanel::showHiddenEntriesChanged
, this, [actionShowAllPlaces
] (bool checked
){
1924 actionShowAllPlaces
->setChecked(checked
);
1925 actionShowAllPlaces
->setIcon(QIcon::fromTheme(checked
? QStringLiteral("view-visible") : QStringLiteral("view-hidden")));
1928 actionCollection()->action(QStringLiteral("show_places_panel"))
1929 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
1930 "<emphasis>places</emphasis> panel at the left side of the window."
1931 "</para><para>It allows you to go to locations you have "
1932 "bookmarked and to access disk or media attached to the computer "
1933 "or to the network. It also contains sections to find recently "
1934 "saved files or files of a certain type.</para>"));
1935 placesDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
1936 "<emphasis>Places</emphasis> panel. It allows you to go to locations "
1937 "you have bookmarked and to access disk or media attached to the "
1938 "computer or to the network. It also contains sections to find "
1939 "recently saved files or files of a certain type.</para><para>"
1940 "Click on an entry to go there. Click with the right mouse button "
1941 "instead to open any entry in a new tab or new window.</para>"
1942 "<para>New entries can be added by dragging folders onto this panel. "
1943 "Right-click any section or entry to hide it. Right-click an empty "
1944 "space on this panel and select <interface>Show Hidden Places"
1945 "</interface> to display it again.</para>") + panelWhatsThis
);
1947 // Add actions into the "Panels" menu
1948 KActionMenu
* panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Show Panels"), this);
1949 actionCollection()->addAction(QStringLiteral("panels"), panelsMenu
);
1950 panelsMenu
->setIcon(QIcon::fromTheme(QStringLiteral("view-sidetree")));
1951 panelsMenu
->setDelayed(false);
1952 const KActionCollection
* ac
= actionCollection();
1953 panelsMenu
->addAction(ac
->action(QStringLiteral("show_places_panel")));
1955 panelsMenu
->addAction(ac
->action(QStringLiteral("show_information_panel")));
1957 panelsMenu
->addAction(ac
->action(QStringLiteral("show_folders_panel")));
1958 panelsMenu
->addAction(ac
->action(QStringLiteral("show_terminal_panel")));
1959 panelsMenu
->addSeparator();
1960 panelsMenu
->addAction(actionShowAllPlaces
);
1961 panelsMenu
->addAction(lockLayoutAction
);
1963 connect(panelsMenu
->menu(), &QMenu::aboutToShow
, this, [actionShowAllPlaces
, this]{
1964 actionShowAllPlaces
->setEnabled(m_placesPanel
->hiddenListCount());
1969 void DolphinMainWindow::updateFileAndEditActions()
1971 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1972 const KActionCollection
* col
= actionCollection();
1973 KFileItemListProperties
capabilitiesSource(list
);
1975 QAction
* addToPlacesAction
= col
->action(QStringLiteral("add_to_places"));
1976 QAction
* copyToOtherViewAction
= col
->action(QStringLiteral("copy_to_inactive_split_view"));
1977 QAction
* moveToOtherViewAction
= col
->action(QStringLiteral("move_to_inactive_split_view"));
1978 QAction
* copyLocation
= col
->action(QString("copy_location"));
1980 if (list
.isEmpty()) {
1981 stateChanged(QStringLiteral("has_no_selection"));
1983 addToPlacesAction
->setEnabled(true);
1984 copyToOtherViewAction
->setEnabled(false);
1985 moveToOtherViewAction
->setEnabled(false);
1986 copyLocation
->setEnabled(false);
1988 stateChanged(QStringLiteral("has_selection"));
1990 QAction
* renameAction
= col
->action(KStandardAction::name(KStandardAction::RenameFile
));
1991 QAction
* moveToTrashAction
= col
->action(KStandardAction::name(KStandardAction::MoveToTrash
));
1992 QAction
* deleteAction
= col
->action(KStandardAction::name(KStandardAction::DeleteFile
));
1993 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1994 QAction
* deleteWithTrashShortcut
= col
->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
1995 QAction
* showTarget
= col
->action(QStringLiteral("show_target"));
1996 QAction
* duplicateAction
= col
->action(QStringLiteral("duplicate")); // see DolphinViewActionHandler
1998 if (list
.length() == 1 && list
.first().isDir()) {
1999 addToPlacesAction
->setEnabled(true);
2001 addToPlacesAction
->setEnabled(false);
2004 if (m_tabWidget
->currentTabPage()->splitViewEnabled()) {
2005 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
2006 KFileItem capabilitiesDestination
;
2008 if (tabPage
->primaryViewActive()) {
2009 capabilitiesDestination
= tabPage
->secondaryViewContainer()->url();
2011 capabilitiesDestination
= tabPage
->primaryViewContainer()->url();
2014 copyToOtherViewAction
->setEnabled(capabilitiesDestination
.isWritable());
2015 moveToOtherViewAction
->setEnabled(capabilitiesSource
.supportsMoving() && capabilitiesDestination
.isWritable());
2017 copyToOtherViewAction
->setEnabled(false);
2018 moveToOtherViewAction
->setEnabled(false);
2021 const bool enableMoveToTrash
= capabilitiesSource
.isLocal() && capabilitiesSource
.supportsMoving();
2023 renameAction
->setEnabled(capabilitiesSource
.supportsMoving());
2024 moveToTrashAction
->setEnabled(enableMoveToTrash
);
2025 deleteAction
->setEnabled(capabilitiesSource
.supportsDeleting());
2026 deleteWithTrashShortcut
->setEnabled(capabilitiesSource
.supportsDeleting() && !enableMoveToTrash
);
2027 cutAction
->setEnabled(capabilitiesSource
.supportsMoving());
2028 copyLocation
->setEnabled(list
.length() == 1);
2029 showTarget
->setEnabled(list
.length() == 1 && list
.at(0).isLink());
2030 duplicateAction
->setEnabled(capabilitiesSource
.supportsWriting());
2034 void DolphinMainWindow::updateViewActions()
2036 m_actionHandler
->updateViewActions();
2038 QAction
* showFilterBarAction
= actionCollection()->action(QStringLiteral("show_filter_bar"));
2039 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
2041 updateSplitAction();
2044 void DolphinMainWindow::updateGoActions()
2046 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
2047 const QUrl currentUrl
= m_activeViewContainer
->url();
2048 // I think this is one of the best places to firstly be confronted
2049 // with a file system and its hierarchy. Talking about the root
2050 // directory might seem too much here but it is the question that
2051 // naturally arises in this context.
2052 goUpAction
->setWhatsThis(xi18nc("@info:whatsthis", "<para>Go to "
2053 "the folder that contains the currently viewed one.</para>"
2054 "<para>All files and folders are organized in a hierarchical "
2055 "<emphasis>file system</emphasis>. At the top of this hierarchy is "
2056 "a directory that contains all data connected to this computer"
2057 "—the <emphasis>root directory</emphasis>.</para>"));
2058 goUpAction
->setEnabled(KIO::upUrl(currentUrl
) != currentUrl
);
2061 void DolphinMainWindow::createControlButton()
2063 if (m_controlButton
) {
2066 Q_ASSERT(!m_controlButton
);
2068 m_controlButton
= new QToolButton(this);
2069 m_controlButton
->setAccessibleName(i18nc("@action:intoolbar", "Control"));
2070 m_controlButton
->setIcon(QIcon::fromTheme(QStringLiteral("application-menu")));
2071 m_controlButton
->setToolTip(i18nc("@action", "Show menu"));
2072 m_controlButton
->setAttribute(Qt::WidgetAttribute::WA_CustomWhatsThis
);
2073 m_controlButton
->setPopupMode(QToolButton::InstantPopup
);
2075 QMenu
* controlMenu
= new QMenu(m_controlButton
);
2076 connect(controlMenu
, &QMenu::aboutToShow
, this, &DolphinMainWindow::updateControlMenu
);
2077 controlMenu
->installEventFilter(this);
2079 m_controlButton
->setMenu(controlMenu
);
2081 toolBar()->addWidget(m_controlButton
);
2082 connect(toolBar(), &KToolBar::iconSizeChanged
,
2083 m_controlButton
, &QToolButton::setIconSize
);
2085 // The added widgets are owned by the toolbar and may get deleted when e.g. the toolbar
2086 // gets edited. In this case we must add them again. The adding is done asynchronously by
2087 // m_updateToolBarTimer.
2088 connect(m_controlButton
, &QToolButton::destroyed
, this, &DolphinMainWindow::slotControlButtonDeleted
);
2089 m_updateToolBarTimer
= new QTimer(this);
2090 m_updateToolBarTimer
->setInterval(500);
2091 connect(m_updateToolBarTimer
, &QTimer::timeout
, this, &DolphinMainWindow::updateToolBar
);
2094 void DolphinMainWindow::deleteControlButton()
2096 delete m_controlButton
;
2097 m_controlButton
= nullptr;
2099 delete m_updateToolBarTimer
;
2100 m_updateToolBarTimer
= nullptr;
2103 bool DolphinMainWindow::addActionToMenu(QAction
* action
, QMenu
* menu
)
2108 const KToolBar
* toolBarWidget
= toolBar();
2109 const auto associatedWidgets
= action
->associatedWidgets();
2110 for (const QWidget
* widget
: associatedWidgets
) {
2111 if (widget
== toolBarWidget
) {
2116 menu
->addAction(action
);
2120 void DolphinMainWindow::refreshViews()
2122 m_tabWidget
->refreshViews();
2124 if (GeneralSettings::modifiedStartupSettings()) {
2125 // The startup settings have been changed by the user (see bug #254947).
2126 // Synchronize the split-view setting with the active view:
2127 const bool splitView
= GeneralSettings::splitView();
2128 m_tabWidget
->currentTabPage()->setSplitViewEnabled(splitView
);
2129 updateSplitAction();
2130 updateWindowTitle();
2133 Q_EMIT
settingsChanged();
2136 void DolphinMainWindow::clearStatusBar()
2138 m_activeViewContainer
->statusBar()->resetToDefaultText();
2141 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
2143 connect(container
, &DolphinViewContainer::showFilterBarChanged
,
2144 this, &DolphinMainWindow::updateFilterBarAction
);
2145 connect(container
, &DolphinViewContainer::writeStateChanged
,
2146 this, &DolphinMainWindow::slotWriteStateChanged
);
2147 connect(container
, &DolphinViewContainer::searchModeEnabledChanged
,
2148 this, &DolphinMainWindow::updateSearchAction
);
2150 const QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
2151 connect(toggleSearchAction
, &QAction::triggered
, container
, &DolphinViewContainer::setSearchModeEnabled
);
2153 const DolphinView
* view
= container
->view();
2154 connect(view
, &DolphinView::selectionChanged
,
2155 this, &DolphinMainWindow::slotSelectionChanged
);
2156 connect(view
, &DolphinView::requestItemInfo
,
2157 this, &DolphinMainWindow::requestItemInfo
);
2158 connect(view
, &DolphinView::tabRequested
,
2159 this, &DolphinMainWindow::openNewTab
);
2160 connect(view
, &DolphinView::requestContextMenu
,
2161 this, &DolphinMainWindow::openContextMenu
);
2162 connect(view
, &DolphinView::directoryLoadingStarted
,
2163 this, &DolphinMainWindow::enableStopAction
);
2164 connect(view
, &DolphinView::directoryLoadingCompleted
,
2165 this, &DolphinMainWindow::disableStopAction
);
2166 connect(view
, &DolphinView::directoryLoadingCompleted
,
2167 this, &DolphinMainWindow::slotDirectoryLoadingCompleted
);
2168 connect(view
, &DolphinView::goBackRequested
,
2169 this, &DolphinMainWindow::goBack
);
2170 connect(view
, &DolphinView::goForwardRequested
,
2171 this, &DolphinMainWindow::goForward
);
2172 connect(view
, &DolphinView::urlActivated
,
2173 this, &DolphinMainWindow::handleUrl
);
2174 connect(view
, &DolphinView::goUpRequested
,
2175 this, &DolphinMainWindow::goUp
);
2177 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
2178 (actionCollection()->action(QStringLiteral("url_navigators")));
2180 const KUrlNavigator
*navigator
= m_tabWidget
->currentTabPage()->primaryViewActive() ?
2181 navigators
->primaryUrlNavigator() :
2182 navigators
->secondaryUrlNavigator();
2184 connect(navigator
, &KUrlNavigator::urlChanged
,
2185 this, &DolphinMainWindow::changeUrl
);
2186 QAction
*editableLocactionAction
= actionCollection()->action(QStringLiteral("editable_location"));
2187 editableLocactionAction
->setChecked(navigator
->isUrlEditable());
2188 connect(navigator
, &KUrlNavigator::editableStateChanged
,
2189 this, &DolphinMainWindow::slotEditableStateChanged
);
2190 connect(navigator
, &KUrlNavigator::tabRequested
,
2191 this, &DolphinMainWindow::openNewTabAfterLastTab
);
2193 disconnect(m_updateHistoryConnection
);
2194 m_updateHistoryConnection
= connect(
2195 container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::historyChanged
,
2196 this, &DolphinMainWindow::updateHistory
);
2199 void DolphinMainWindow::updateSplitAction()
2201 QAction
* splitAction
= actionCollection()->action(QStringLiteral("split_view"));
2202 const DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
2203 if (tabPage
->splitViewEnabled()) {
2204 if (GeneralSettings::closeActiveSplitView() ? tabPage
->primaryViewActive() : !tabPage
->primaryViewActive()) {
2205 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2206 splitAction
->setToolTip(i18nc("@info", "Close left view"));
2207 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close")));
2209 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2210 splitAction
->setToolTip(i18nc("@info", "Close right view"));
2211 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close")));
2214 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2215 splitAction
->setToolTip(i18nc("@info", "Split view"));
2216 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2220 bool DolphinMainWindow::isKompareInstalled() const
2222 static bool initialized
= false;
2223 static bool installed
= false;
2225 // TODO: maybe replace this approach later by using a menu
2226 // plugin like kdiff3plugin.cpp
2227 installed
= !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty();
2233 void DolphinMainWindow::createPanelAction(const QIcon
& icon
,
2234 const QKeySequence
& shortcut
,
2235 QAction
* dockAction
,
2236 const QString
& actionName
)
2238 QAction
* panelAction
= actionCollection()->addAction(actionName
);
2239 panelAction
->setCheckable(true);
2240 panelAction
->setChecked(dockAction
->isChecked());
2241 panelAction
->setText(dockAction
->text());
2242 panelAction
->setIcon(icon
);
2243 actionCollection()->setDefaultShortcut(panelAction
, shortcut
);
2245 connect(panelAction
, &QAction::triggered
, dockAction
, &QAction::trigger
);
2246 connect(dockAction
, &QAction::toggled
, panelAction
, &QAction::setChecked
);
2249 void DolphinMainWindow::setupWhatsThis()
2252 menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2253 "<emphasis>Menubar</emphasis>. It provides access to commands and "
2254 "configuration options. Left-click on any of the menus on this "
2255 "bar to see its contents.</para><para>The Menubar can be hidden "
2256 "by unchecking <interface>Settings|Show Menubar</interface>. Then "
2257 "most of its contents become available through a <interface>Control"
2258 "</interface> button on the <emphasis>Toolbar</emphasis>.</para>"));
2259 toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2260 "<emphasis>Toolbar</emphasis>. It allows quick access to "
2261 "frequently used actions.</para><para>It is highly customizable. "
2262 "All items you see in the <interface>Control</interface> menu or "
2263 "in the <interface>Menubar</interface> can be placed on the "
2264 "Toolbar. Just right-click on it and select <interface>Configure "
2265 "Toolbars…</interface> or find this action in the <interface>"
2266 "Control</interface> or <interface>Settings</interface> menu."
2267 "</para><para>The location of the bar and the style of its "
2268 "buttons can also be changed in the right-click menu. Right-click "
2269 "a button if you want to show or hide its text.</para>"));
2270 m_tabWidget
->setWhatsThis(xi18nc("@info:whatsthis main view",
2271 "<para>Here you can see the <emphasis>folders</emphasis> and "
2272 "<emphasis>files</emphasis> that are at the location described in "
2273 "the <interface>Location Bar</interface> above. This area is the "
2274 "central part of this application where you navigate to the files "
2275 "you want to use.</para><para>For an elaborate and general "
2276 "introduction to this application <link "
2277 "url='https://userbase.kde.org/Dolphin/File_Management#Introduction_to_Dolphin'>"
2278 "click here</link>. This will open an introductory article from "
2279 "the <emphasis>KDE UserBase Wiki</emphasis>.</para><para>For brief "
2280 "explanations of all the features of this <emphasis>view</emphasis> "
2281 "<link url='help:/dolphin/dolphin-view.html'>click here</link> "
2282 "instead. This will open a page from the <emphasis>Handbook"
2283 "</emphasis> that covers the basics.</para>"));
2286 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings
))
2287 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window "
2288 "that lists the <emphasis>keyboard shortcuts</emphasis>.<nl/>"
2289 "There you can set up key combinations to trigger an action when "
2290 "they are pressed simultaneously. All commands in this application can "
2291 "be triggered this way.</para>"));
2292 actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars
))
2293 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window in which "
2294 "you can change which buttons appear on the <emphasis>Toolbar</emphasis>.</para>"
2295 "<para>All items you see in the <interface>Control</interface> menu "
2296 "or in the <interface>Menubar</interface> can also be placed on the Toolbar.</para>"));
2297 actionCollection()->action(KStandardAction::name(KStandardAction::Preferences
))
2298 ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can "
2299 "change a multitude of settings for this application. For an explanation "
2300 "of the various settings go to the chapter <emphasis>Configuring Dolphin"
2301 "</emphasis> in <interface>Help|Dolphin Handbook</interface>."));
2304 // The whatsthis has to be set for the m_helpMenu and for the
2305 // StandardAction separately because both are used in different locations.
2306 // m_helpMenu is only used for createControlButton() button.
2308 // Links do not work within the Menubar so texts without links are provided there.
2310 // i18n: If the external link isn't available in your language you should
2311 // probably state the external link language at least in brackets to not
2312 // frustrate the user. If there are multiple languages that the user might
2313 // know with a reasonable chance you might want to have 2 external links.
2314 // The same is in my opinion true for every external link you translate.
2315 const QString whatsThisHelpContents
= xi18nc("@info:whatsthis handbook",
2316 "<para>This opens the Handbook for this application. It provides "
2317 "explanations for every part of <emphasis>Dolphin</emphasis>.</para>");
2318 actionCollection()->action(KStandardAction::name(KStandardAction::HelpContents
))
2319 ->setWhatsThis(whatsThisHelpContents
2320 + xi18nc("@info:whatsthis second half of handbook hb text without link",
2321 "<para>If you want more elaborate introductions to the "
2322 "different features of <emphasis>Dolphin</emphasis> "
2323 "go to the KDE UserBase Wiki.</para>"));
2324 m_helpMenu
->action(KHelpMenu::menuHelpContents
)->setWhatsThis(whatsThisHelpContents
2325 + xi18nc("@info:whatsthis second half of handbook text with link",
2326 "<para>If you want more elaborate introductions to the "
2327 "different features of <emphasis>Dolphin</emphasis> "
2328 "<link url='https://userbase.kde.org/Dolphin/File_Management'>click here</link>. "
2329 "It will open the dedicated page in the KDE UserBase Wiki.</para>"));
2331 const QString whatsThisWhatsThis
= xi18nc("@info:whatsthis whatsthis button",
2332 "<para>This is the button that invokes the help feature you are "
2333 "using right now! Click it, then click any component of this "
2334 "application to ask \"What's this?\" about it. The mouse cursor "
2335 "will change appearance if no help is available for a spot.</para>");
2336 actionCollection()->action(KStandardAction::name(KStandardAction::WhatsThis
))
2337 ->setWhatsThis(whatsThisWhatsThis
2338 + xi18nc("@info:whatsthis second half of whatsthis button text without link",
2339 "<para>There are two other ways to get help for this application: The "
2340 "<interface>Dolphin Handbook</interface> in the <interface>Help"
2341 "</interface> menu and the <emphasis>KDE UserBase Wiki</emphasis> "
2342 "article about <emphasis>File Management</emphasis> online."
2343 "</para><para>The \"What's this?\" help is "
2344 "missing in most other windows so don't get too used to this.</para>"));
2345 m_helpMenu
->action(KHelpMenu::menuWhatsThis
)->setWhatsThis(whatsThisWhatsThis
2346 + xi18nc("@info:whatsthis second half of whatsthis button text with link",
2347 "<para>There are two other ways to get help: "
2348 "The <link url='help:/dolphin/index.html'>Dolphin Handbook</link> and "
2349 "the <link url='https://userbase.kde.org/Dolphin/File_Management'>KDE "
2350 "UserBase Wiki</link>.</para><para>The \"What's this?\" help is "
2351 "missing in most other windows so don't get too used to this.</para>"));
2353 const QString whatsThisReportBug
= xi18nc("@info:whatsthis","<para>This opens a "
2354 "window that will guide you through reporting errors or flaws "
2355 "in this application or in other KDE software.</para>");
2356 actionCollection()->action(KStandardAction::name(KStandardAction::ReportBug
))
2357 ->setWhatsThis(whatsThisReportBug
);
2358 m_helpMenu
->action(KHelpMenu::menuReportBug
)->setWhatsThis(whatsThisReportBug
2359 + xi18nc("@info:whatsthis second half of reportbug text with link",
2360 "<para>High-quality bug reports are much appreciated. To learn "
2361 "how to make your bug report as effective as possible "
2362 "<link url='https://community.kde.org/Get_Involved/Bug_Reporting'>"
2363 "click here</link>.</para>"));
2365 const QString whatsThisDonate
= xi18nc("@info:whatsthis","<para>This opens a "
2366 "<emphasis>web page</emphasis> where you can donate to "
2367 "support the continued work on this application and many "
2368 "other projects by the <emphasis>KDE</emphasis> community.</para>"
2369 "<para>Donating is the easiest and fastest way to efficiently "
2370 "support KDE and its projects. KDE projects are available for "
2371 "free therefore your donation is needed to cover things that "
2372 "require money like servers, contributor meetings, etc.</para>"
2373 "<para><emphasis>KDE e.V.</emphasis> is the non-profit "
2374 "organization behind the KDE community.</para>");
2375 actionCollection()->action(KStandardAction::name(KStandardAction::Donate
))
2376 ->setWhatsThis(whatsThisDonate
);
2377 m_helpMenu
->action(KHelpMenu::menuDonate
)->setWhatsThis(whatsThisDonate
);
2379 const QString whatsThisSwitchLanguage
= xi18nc("@info:whatsthis",
2380 "With this you can change the language this application uses."
2381 "<nl/>You can even set secondary languages which will be used "
2382 "if texts are not available in your preferred language.");
2383 actionCollection()->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
))
2384 ->setWhatsThis(whatsThisSwitchLanguage
);
2385 m_helpMenu
->action(KHelpMenu::menuSwitchLanguage
)->setWhatsThis(whatsThisSwitchLanguage
);
2387 const QString whatsThisAboutApp
= xi18nc("@info:whatsthis","This opens a "
2388 "window that informs you about the version, license, "
2389 "used libraries and maintainers of this application.");
2390 actionCollection()->action(KStandardAction::name(KStandardAction::AboutApp
))
2391 ->setWhatsThis(whatsThisAboutApp
);
2392 m_helpMenu
->action(KHelpMenu::menuAboutApp
)->setWhatsThis(whatsThisAboutApp
);
2394 const QString whatsThisAboutKDE
= xi18nc("@info:whatsthis","This opens a "
2395 "window with information about <emphasis>KDE</emphasis>. "
2396 "The KDE community are the people behind this free software."
2397 "<nl/>If you like using this application but don't know "
2398 "about KDE or want to see a cute dragon have a look!");
2399 actionCollection()->action(KStandardAction::name(KStandardAction::AboutKDE
))
2400 ->setWhatsThis(whatsThisAboutKDE
);
2401 m_helpMenu
->action(KHelpMenu::menuAboutKDE
)->setWhatsThis(whatsThisAboutKDE
);
2404 bool DolphinMainWindow::event(QEvent
*event
)
2406 if (event
->type() == QEvent::WhatsThisClicked
) {
2408 QWhatsThisClickedEvent
* whatsThisEvent
= dynamic_cast<QWhatsThisClickedEvent
*>(event
);
2409 QDesktopServices::openUrl(QUrl(whatsThisEvent
->href()));
2412 return KXmlGuiWindow::event(event
);
2415 bool DolphinMainWindow::eventFilter(QObject
* obj
, QEvent
* event
)
2418 if (event
->type() == QEvent::WhatsThisClicked
) {
2420 QWhatsThisClickedEvent
* whatsThisEvent
= dynamic_cast<QWhatsThisClickedEvent
*>(event
);
2421 QDesktopServices::openUrl(QUrl(whatsThisEvent
->href()));
2427 void DolphinMainWindow::focusTerminalPanel()
2429 if (m_terminalPanel
->isVisible()) {
2430 if (m_terminalPanel
->terminalHasFocus()) {
2431 m_activeViewContainer
->view()->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2432 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2434 m_terminalPanel
->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2435 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2438 actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger();
2439 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2443 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
2444 KIO::FileUndoManager::UiInterface()
2448 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2452 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
2454 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2456 DolphinViewContainer
* container
= mainWin
->activeViewContainer();
2457 container
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
2459 KIO::FileUndoManager::UiInterface::jobError(job
);
2463 bool DolphinMainWindow::isUrlOpen(const QString
& url
)
2465 return m_tabWidget
->isUrlOpen(QUrl::fromUserInput((url
)));