2 * SPDX-FileCopyrightText: 2006 Peter Penz <peter.penz19@gmail.com>
3 * SPDX-FileCopyrightText: 2006 Stefan Monov <logixoul@gmail.com>
4 * SPDX-FileCopyrightText: 2006 Cvetoslav Ludmiloff <ludmiloff@gmail.com>
6 * SPDX-License-Identifier: GPL-2.0-or-later
9 #include "dolphinmainwindow.h"
11 #include "dolphinmainwindowadaptor.h"
12 #include "config-terminal.h"
14 #include "dolphinbookmarkhandler.h"
15 #include "dolphindockwidget.h"
16 #include "dolphincontextmenu.h"
17 #include "dolphinnavigatorswidgetaction.h"
18 #include "dolphinnewfilemenu.h"
19 #include "dolphinrecenttabsmenu.h"
20 #include "dolphinurlnavigatorscontroller.h"
21 #include "dolphinviewcontainer.h"
22 #include "dolphintabpage.h"
23 #include "middleclickactioneventfilter.h"
24 #include "panels/folders/folderspanel.h"
25 #include "panels/places/placesitemmodel.h"
26 #include "panels/places/placespanel.h"
27 #include "panels/information/informationpanel.h"
28 #include "panels/terminal/terminalpanel.h"
29 #include "settings/dolphinsettingsdialog.h"
30 #include "statusbar/dolphinstatusbar.h"
31 #include "views/dolphinviewactionhandler.h"
32 #include "views/dolphinremoteencoding.h"
33 #include "views/draganddrophelper.h"
34 #include "views/viewproperties.h"
35 #include "views/dolphinnewfilemenuobserver.h"
36 #include "dolphin_generalsettings.h"
38 #include <KActionCollection>
39 #include <KActionMenu>
40 #include <KAuthorized>
43 #include <KDualAction>
44 #include <KFileItemListProperties>
46 #include <KIO/CommandLauncherJob>
47 #include <KIO/JobUiDelegate>
48 #include <KIO/OpenFileManagerWindowJob>
49 #include <KIO/OpenUrlJob>
50 #include <KJobWidgets>
51 #include <KLocalizedString>
52 #include <KMessageBox>
53 #include <KNS3/KMoreToolsMenuFactory>
54 #include <KProtocolInfo>
55 #include <KProtocolManager>
57 #include <KStandardAction>
58 #include <KStartupInfo>
60 #include <KToggleAction>
62 #include <KToolBarPopupAction>
63 #include <KToolInvocation>
64 #include <KUrlComboBox>
65 #include <KUrlNavigator>
66 #include <KWindowSystem>
68 #include <QApplication>
70 #include <QCloseEvent>
71 #include <QDesktopServices>
76 #include <QPushButton>
78 #include <QStandardPaths>
80 #include <QToolButton>
81 #include <QWhatsThisClickedEvent>
84 // Used for GeneralSettings::version() to determine whether
85 // an updated version of Dolphin is running.
86 const int CurrentDolphinVersion
= 200;
87 // The maximum number of entries in the back/forward popup menu
88 const int MaxNumberOfNavigationentries
= 12;
89 // The maximum number of "Activate Tab" shortcuts
90 const int MaxActivateTabShortcuts
= 9;
93 DolphinMainWindow::DolphinMainWindow() :
94 KXmlGuiWindow(nullptr),
95 m_newFileMenu(nullptr),
98 m_activeViewContainer(nullptr),
99 m_actionHandler(nullptr),
100 m_remoteEncoding(nullptr),
102 m_bookmarkHandler(nullptr),
103 m_controlButton(nullptr),
104 m_updateToolBarTimer(nullptr),
105 m_lastHandleUrlOpenJob(nullptr),
106 m_terminalPanel(nullptr),
107 m_placesPanel(nullptr),
108 m_tearDownFromPlacesRequested(false),
109 m_backAction(nullptr),
110 m_forwardAction(nullptr)
112 Q_INIT_RESOURCE(dolphin
);
114 new MainWindowAdaptor(this);
117 setWindowFlags(Qt::WindowContextHelpButtonHint
);
119 setComponentName(QStringLiteral("dolphin"), QGuiApplication::applicationDisplayName());
120 setObjectName(QStringLiteral("Dolphin#"));
122 connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::errorMessage
,
123 this, &DolphinMainWindow::showErrorMessage
);
125 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
126 undoManager
->setUiInterface(new UndoUiInterface());
128 connect(undoManager
, QOverload
<bool>::of(&KIO::FileUndoManager::undoAvailable
),
129 this, &DolphinMainWindow::slotUndoAvailable
);
130 connect(undoManager
, &KIO::FileUndoManager::undoTextChanged
,
131 this, &DolphinMainWindow::slotUndoTextChanged
);
132 connect(undoManager
, &KIO::FileUndoManager::jobRecordingStarted
,
133 this, &DolphinMainWindow::clearStatusBar
);
134 connect(undoManager
, &KIO::FileUndoManager::jobRecordingFinished
,
135 this, &DolphinMainWindow::showCommand
);
137 GeneralSettings
* generalSettings
= GeneralSettings::self();
138 const bool firstRun
= (generalSettings
->version() < 200);
140 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
143 setAcceptDrops(true);
145 auto *navigatorsWidgetAction
= new DolphinNavigatorsWidgetAction(this);
146 actionCollection()->addAction(QStringLiteral("url_navigators"), navigatorsWidgetAction
);
147 m_tabWidget
= new DolphinTabWidget(navigatorsWidgetAction
, this);
148 m_tabWidget
->setObjectName("tabWidget");
149 connect(m_tabWidget
, &DolphinTabWidget::activeViewChanged
,
150 this, &DolphinMainWindow::activeViewChanged
);
151 connect(m_tabWidget
, &DolphinTabWidget::tabCountChanged
,
152 this, &DolphinMainWindow::tabCountChanged
);
153 connect(m_tabWidget
, &DolphinTabWidget::currentUrlChanged
,
154 this, &DolphinMainWindow::updateWindowTitle
);
155 setCentralWidget(m_tabWidget
);
159 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
160 connect(m_actionHandler
, &DolphinViewActionHandler::actionBeingHandled
, this, &DolphinMainWindow::clearStatusBar
);
161 connect(m_actionHandler
, &DolphinViewActionHandler::createDirectoryTriggered
, this, &DolphinMainWindow::createDirectory
);
163 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
164 connect(this, &DolphinMainWindow::urlChanged
,
165 m_remoteEncoding
, &DolphinRemoteEncoding::slotAboutToOpenUrl
);
169 setupGUI(Keys
| Save
| Create
| ToolBar
);
170 stateChanged(QStringLiteral("new_file"));
172 QClipboard
* clipboard
= QApplication::clipboard();
173 connect(clipboard
, &QClipboard::dataChanged
,
174 this, &DolphinMainWindow::updatePasteAction
);
176 QAction
* showFilterBarAction
= actionCollection()->action(QStringLiteral("show_filter_bar"));
177 showFilterBarAction
->setChecked(generalSettings
->filterBar());
180 menuBar()->setVisible(false);
181 // Assure a proper default size if Dolphin runs the first time
185 const bool showMenu
= !menuBar()->isHidden();
186 QAction
* showMenuBarAction
= actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar
));
187 showMenuBarAction
->setChecked(showMenu
); // workaround for bug #171080
189 createControlButton();
192 updateAllowedToolbarAreas();
194 // enable middle-click on back/forward/up to open in a new tab
195 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
196 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotToolBarActionMiddleClicked
);
197 toolBar()->installEventFilter(middleClickEventFilter
);
201 connect(KSycoca::self(), QOverload
<>::of(&KSycoca::databaseChanged
), this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
203 QTimer::singleShot(0, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
206 DolphinMainWindow::~DolphinMainWindow()
210 QVector
<DolphinViewContainer
*> DolphinMainWindow::viewContainers() const
212 QVector
<DolphinViewContainer
*> viewContainers
;
214 for (int i
= 0; i
< m_tabWidget
->count(); ++i
) {
215 DolphinTabPage
*tabPage
= m_tabWidget
->tabPageAt(i
);
217 viewContainers
<< tabPage
->primaryViewContainer();
218 if (tabPage
->splitViewEnabled()) {
219 viewContainers
<< tabPage
->secondaryViewContainer();
222 return viewContainers
;
225 void DolphinMainWindow::setViewsWithInvalidPathsToHome()
227 const QVector
<DolphinViewContainer
*> theViewContainers
= viewContainers();
228 for (DolphinViewContainer
*viewContainer
: theViewContainers
) {
230 // Only consider local dirs, not remote locations and abstract protocols
231 if (viewContainer
->url().isLocalFile()) {
232 if (!QFileInfo::exists(viewContainer
->url().toLocalFile())) {
233 viewContainer
->setUrl(QUrl::fromLocalFile(QDir::homePath()));
239 void DolphinMainWindow::openDirectories(const QList
<QUrl
>& dirs
, bool splitView
)
241 m_tabWidget
->openDirectories(dirs
, splitView
);
244 void DolphinMainWindow::openDirectories(const QStringList
& dirs
, bool splitView
)
246 openDirectories(QUrl::fromStringList(dirs
), splitView
);
249 void DolphinMainWindow::openFiles(const QList
<QUrl
>& files
, bool splitView
)
251 m_tabWidget
->openFiles(files
, splitView
);
254 bool DolphinMainWindow::isFoldersPanelEnabled() const
256 return actionCollection()->action(QStringLiteral("show_folders_panel"))->isChecked();
259 bool DolphinMainWindow::isInformationPanelEnabled() const
262 return actionCollection()->action(QStringLiteral("show_information_panel"))->isChecked();
268 void DolphinMainWindow::openFiles(const QStringList
& files
, bool splitView
)
270 openFiles(QUrl::fromStringList(files
), splitView
);
273 void DolphinMainWindow::activateWindow()
275 window()->setAttribute(Qt::WA_NativeWindow
, true);
276 KStartupInfo::setNewStartupId(window()->windowHandle(), KStartupInfo::startupId());
277 KWindowSystem::activateWindow(window()->effectiveWinId());
280 void DolphinMainWindow::showCommand(CommandType command
)
282 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
284 case KIO::FileUndoManager::Copy
:
285 statusBar
->setText(i18nc("@info:status", "Successfully copied."));
287 case KIO::FileUndoManager::Move
:
288 statusBar
->setText(i18nc("@info:status", "Successfully moved."));
290 case KIO::FileUndoManager::Link
:
291 statusBar
->setText(i18nc("@info:status", "Successfully linked."));
293 case KIO::FileUndoManager::Trash
:
294 statusBar
->setText(i18nc("@info:status", "Successfully moved to trash."));
296 case KIO::FileUndoManager::Rename
:
297 statusBar
->setText(i18nc("@info:status", "Successfully renamed."));
300 case KIO::FileUndoManager::Mkdir
:
301 statusBar
->setText(i18nc("@info:status", "Created folder."));
309 void DolphinMainWindow::pasteIntoFolder()
311 m_activeViewContainer
->view()->pasteIntoFolder();
314 void DolphinMainWindow::changeUrl(const QUrl
&url
)
316 if (!KProtocolManager::supportsListing(url
)) {
317 // The URL navigator only checks for validity, not
318 // if the URL can be listed. An error message is
319 // shown due to DolphinViewContainer::restoreView().
323 m_activeViewContainer
->setUrl(url
);
324 updateFileAndEditActions();
329 Q_EMIT
urlChanged(url
);
332 void DolphinMainWindow::slotTerminalDirectoryChanged(const QUrl
& url
)
334 if (m_tearDownFromPlacesRequested
&& url
== QUrl::fromLocalFile(QDir::homePath())) {
335 m_placesPanel
->proceedWithTearDown();
336 m_tearDownFromPlacesRequested
= false;
339 m_activeViewContainer
->setAutoGrabFocus(false);
341 m_activeViewContainer
->setAutoGrabFocus(true);
344 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
346 KToggleAction
* editableLocationAction
=
347 static_cast<KToggleAction
*>(actionCollection()->action(QStringLiteral("editable_location")));
348 editableLocationAction
->setChecked(editable
);
351 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
353 updateFileAndEditActions();
355 const int selectedUrlsCount
= m_tabWidget
->currentTabPage()->selectedItemsCount();
357 QAction
* compareFilesAction
= actionCollection()->action(QStringLiteral("compare_files"));
358 if (selectedUrlsCount
== 2) {
359 compareFilesAction
->setEnabled(isKompareInstalled());
361 compareFilesAction
->setEnabled(false);
364 Q_EMIT
selectionChanged(selection
);
367 void DolphinMainWindow::updateHistory()
369 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
370 const int index
= urlNavigator
->historyIndex();
372 QAction
* backAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Back
));
374 backAction
->setToolTip(i18nc("@info", "Go back"));
375 backAction
->setWhatsThis(i18nc("@info:whatsthis go back", "Return to the previously viewed folder."));
376 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
379 QAction
* forwardAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Forward
));
381 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
382 forwardAction
->setWhatsThis(xi18nc("@info:whatsthis go forward",
383 "This undoes a <interface>Go|Back</interface> action."));
384 forwardAction
->setEnabled(index
> 0);
388 void DolphinMainWindow::updateFilterBarAction(bool show
)
390 QAction
* showFilterBarAction
= actionCollection()->action(QStringLiteral("show_filter_bar"));
391 showFilterBarAction
->setChecked(show
);
394 void DolphinMainWindow::openNewMainWindow()
396 Dolphin::openNewWindow({m_activeViewContainer
->url()}, this);
399 void DolphinMainWindow::openNewActivatedTab()
401 m_tabWidget
->openNewActivatedTab();
404 void DolphinMainWindow::addToPlaces()
409 // If nothing is selected, act on the current dir
410 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
411 url
= m_activeViewContainer
->url();
412 name
= m_activeViewContainer
->placesText();
414 const auto dirToAdd
= m_activeViewContainer
->view()->selectedItems().first();
415 url
= dirToAdd
.url();
416 name
= dirToAdd
.name();
419 PlacesItemModel model
;
421 if (m_activeViewContainer
->isSearchModeEnabled()) {
422 icon
= QStringLiteral("folder-saved-search-symbolic");
424 icon
= KIO::iconNameForUrl(url
);
426 model
.createPlacesItem(name
, url
, icon
);
430 void DolphinMainWindow::openNewTab(const QUrl
& url
, DolphinTabWidget::TabPlacement tabPlacement
)
432 m_tabWidget
->openNewTab(url
, QUrl(), tabPlacement
);
435 void DolphinMainWindow::openNewTabAfterCurrentTab(const QUrl
& url
)
437 m_tabWidget
->openNewTab(url
, QUrl(), DolphinTabWidget::AfterCurrentTab
);
440 void DolphinMainWindow::openNewTabAfterLastTab(const QUrl
& url
)
442 m_tabWidget
->openNewTab(url
, QUrl(), DolphinTabWidget::AfterLastTab
);
445 void DolphinMainWindow::openInNewTab()
447 const KFileItemList
& list
= m_activeViewContainer
->view()->selectedItems();
448 bool tabCreated
= false;
450 for (const KFileItem
& item
: list
) {
451 const QUrl
& url
= DolphinView::openItemAsFolderUrl(item
);
452 if (!url
.isEmpty()) {
453 openNewTabAfterCurrentTab(url
);
458 // if no new tab has been created from the selection
459 // open the current directory in a new tab
461 openNewTabAfterCurrentTab(m_activeViewContainer
->url());
465 void DolphinMainWindow::openInNewWindow()
469 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
470 if (list
.isEmpty()) {
471 newWindowUrl
= m_activeViewContainer
->url();
472 } else if (list
.count() == 1) {
473 const KFileItem
& item
= list
.first();
474 newWindowUrl
= DolphinView::openItemAsFolderUrl(item
);
477 if (!newWindowUrl
.isEmpty()) {
478 Dolphin::openNewWindow({newWindowUrl
}, this);
482 void DolphinMainWindow::showTarget()
484 const auto link
= m_activeViewContainer
->view()->selectedItems().at(0);
485 const auto linkLocationDir
= QFileInfo(link
.localPath()).absoluteDir();
486 auto linkDestination
= link
.linkDest();
487 if (QFileInfo(linkDestination
).isRelative()) {
488 linkDestination
= linkLocationDir
.filePath(linkDestination
);
490 if (QFileInfo::exists(linkDestination
)) {
491 KIO::highlightInFileManager({QUrl::fromLocalFile(linkDestination
).adjusted(QUrl::StripTrailingSlash
)});
493 m_activeViewContainer
->showMessage(xi18nc("@info", "Could not access <filename>%1</filename>.", linkDestination
),
494 DolphinViewContainer::Warning
);
498 void DolphinMainWindow::showEvent(QShowEvent
* event
)
500 KXmlGuiWindow::showEvent(event
);
502 if (!event
->spontaneous()) {
503 m_activeViewContainer
->view()->setFocus();
507 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
509 // Find out if Dolphin is closed directly by the user or
510 // by the session manager because the session is closed
511 bool closedByUser
= true;
512 if (qApp
->isSavingSession()) {
513 closedByUser
= false;
516 if (m_tabWidget
->count() > 1
517 && GeneralSettings::confirmClosingMultipleTabs()
518 && !GeneralSettings::rememberOpenedTabs()
520 // Ask the user if he really wants to quit and close all tabs.
521 // Open a confirmation dialog with 3 buttons:
522 // QDialogButtonBox::Yes -> Quit
523 // QDialogButtonBox::No -> Close only the current tab
524 // QDialogButtonBox::Cancel -> do nothing
525 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
526 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
527 dialog
->setModal(true);
528 QDialogButtonBox
* buttons
= new QDialogButtonBox(QDialogButtonBox::Yes
| QDialogButtonBox::No
| QDialogButtonBox::Cancel
);
529 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KGuiItem(i18nc("@action:button 'Quit Dolphin' button", "&Quit %1", QGuiApplication::applicationDisplayName()), QIcon::fromTheme(QStringLiteral("application-exit"))));
530 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("C&lose Current Tab"), QIcon::fromTheme(QStringLiteral("tab-close"))));
531 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
532 buttons
->button(QDialogButtonBox::Yes
)->setDefault(true);
534 bool doNotAskAgainCheckboxResult
= false;
536 const auto result
= KMessageBox::createKMessageBox(dialog
,
538 QMessageBox::Warning
,
539 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
541 i18n("Do not ask again"),
542 &doNotAskAgainCheckboxResult
,
543 KMessageBox::Notify
);
545 if (doNotAskAgainCheckboxResult
) {
546 GeneralSettings::setConfirmClosingMultipleTabs(false);
550 case QDialogButtonBox::Yes
:
553 case QDialogButtonBox::No
:
554 // Close only the current tab
555 m_tabWidget
->closeTab();
563 if (m_terminalPanel
&& m_terminalPanel
->hasProgramRunning() && GeneralSettings::confirmClosingTerminalRunningProgram() && closedByUser
) {
564 // Ask if the user really wants to quit Dolphin with a program that is still running in the Terminal panel
565 // Open a confirmation dialog with 3 buttons:
566 // QDialogButtonBox::Yes -> Quit
567 // QDialogButtonBox::No -> Show Terminal Panel
568 // QDialogButtonBox::Cancel -> do nothing
569 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
570 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
571 dialog
->setModal(true);
572 auto standardButtons
= QDialogButtonBox::Yes
| QDialogButtonBox::Cancel
;
573 if (!m_terminalPanel
->isVisible()) {
574 standardButtons
|= QDialogButtonBox::No
;
576 QDialogButtonBox
*buttons
= new QDialogButtonBox(standardButtons
);
577 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KStandardGuiItem::quit());
578 if (!m_terminalPanel
->isVisible()) {
580 buttons
->button(QDialogButtonBox::No
),
581 KGuiItem(i18n("Show &Terminal Panel"), QIcon::fromTheme(QStringLiteral("dialog-scripts"))));
583 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
585 bool doNotAskAgainCheckboxResult
= false;
587 const auto result
= KMessageBox::createKMessageBox(
590 QMessageBox::Warning
,
591 i18n("The program '%1' is still running in the Terminal panel. Are you sure you want to quit?", m_terminalPanel
->runningProgramName()),
593 i18n("Do not ask again"),
594 &doNotAskAgainCheckboxResult
,
595 KMessageBox::Dangerous
);
597 if (doNotAskAgainCheckboxResult
) {
598 GeneralSettings::setConfirmClosingTerminalRunningProgram(false);
602 case QDialogButtonBox::Yes
:
605 case QDialogButtonBox::No
:
606 actionCollection()->action("show_terminal_panel")->trigger();
607 // Do not quit, ignore quit event
615 if (GeneralSettings::rememberOpenedTabs()) {
616 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
617 KConfig
*config
= KConfigGui::sessionConfig();
618 saveGlobalProperties(config
);
619 savePropertiesInternal(config
, 1);
623 GeneralSettings::setVersion(CurrentDolphinVersion
);
624 GeneralSettings::self()->save();
626 KXmlGuiWindow::closeEvent(event
);
629 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
631 m_tabWidget
->saveProperties(group
);
634 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
636 m_tabWidget
->readProperties(group
);
639 void DolphinMainWindow::updateNewMenu()
641 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
642 m_newFileMenu
->checkUpToDate();
643 m_newFileMenu
->setPopupFiles(QList
<QUrl
>() << activeViewContainer()->url());
646 void DolphinMainWindow::createDirectory()
648 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
649 m_newFileMenu
->setPopupFiles(QList
<QUrl
>() << activeViewContainer()->url());
650 m_newFileMenu
->createDirectory();
653 void DolphinMainWindow::quit()
658 void DolphinMainWindow::showErrorMessage(const QString
& message
)
660 m_activeViewContainer
->showMessage(message
, DolphinViewContainer::Error
);
663 void DolphinMainWindow::slotUndoAvailable(bool available
)
665 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
667 undoAction
->setEnabled(available
);
671 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
673 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
675 undoAction
->setText(text
);
679 void DolphinMainWindow::undo()
682 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
683 KIO::FileUndoManager::self()->undo();
686 void DolphinMainWindow::cut()
688 m_activeViewContainer
->view()->cutSelectedItemsToClipboard();
691 void DolphinMainWindow::copy()
693 m_activeViewContainer
->view()->copySelectedItemsToClipboard();
696 void DolphinMainWindow::paste()
698 m_activeViewContainer
->view()->paste();
701 void DolphinMainWindow::find()
703 m_activeViewContainer
->setSearchModeEnabled(true);
706 void DolphinMainWindow::updateSearchAction()
708 QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
709 toggleSearchAction
->setChecked(m_activeViewContainer
->isSearchModeEnabled());
712 void DolphinMainWindow::updatePasteAction()
714 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
715 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
716 pasteAction
->setEnabled(pasteInfo
.first
);
717 pasteAction
->setText(pasteInfo
.second
);
720 void DolphinMainWindow::slotDirectoryLoadingCompleted()
725 void DolphinMainWindow::slotToolBarActionMiddleClicked(QAction
*action
)
727 if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Back
))) {
729 } else if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Forward
))) {
731 } else if (action
== actionCollection()->action(QStringLiteral("go_up"))) {
733 } else if (action
== actionCollection()->action(QStringLiteral("go_home"))) {
738 void DolphinMainWindow::slotAboutToShowBackPopupMenu()
740 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
742 m_backAction
->menu()->clear();
743 for (int i
= urlNavigator
->historyIndex() + 1; i
< urlNavigator
->historySize() && entries
< MaxNumberOfNavigationentries
; ++i
, ++entries
) {
744 QAction
* action
= new QAction(urlNavigator
->locationUrl(i
).toString(QUrl::PreferLocalFile
), m_backAction
->menu());
746 m_backAction
->menu()->addAction(action
);
750 void DolphinMainWindow::slotGoBack(QAction
* action
)
752 int gotoIndex
= action
->data().value
<int>();
753 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
754 for (int i
= gotoIndex
- urlNavigator
->historyIndex(); i
> 0; --i
) {
759 void DolphinMainWindow::slotBackForwardActionMiddleClicked(QAction
* action
)
762 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
763 openNewTabAfterCurrentTab(urlNavigator
->locationUrl(action
->data().value
<int>()));
767 void DolphinMainWindow::slotAboutToShowForwardPopupMenu()
769 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
771 m_forwardAction
->menu()->clear();
772 for (int i
= urlNavigator
->historyIndex() - 1; i
>= 0 && entries
< MaxNumberOfNavigationentries
; --i
, ++entries
) {
773 QAction
* action
= new QAction(urlNavigator
->locationUrl(i
).toString(QUrl::PreferLocalFile
), m_forwardAction
->menu());
775 m_forwardAction
->menu()->addAction(action
);
779 void DolphinMainWindow::slotGoForward(QAction
* action
)
781 int gotoIndex
= action
->data().value
<int>();
782 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
783 for (int i
= urlNavigator
->historyIndex() - gotoIndex
; i
> 0; --i
) {
788 void DolphinMainWindow::selectAll()
792 // if the URL navigator is editable and focused, select the whole
793 // URL instead of all items of the view
795 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
796 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit();
797 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
798 lineEdit
->hasFocus();
800 lineEdit
->selectAll();
802 m_activeViewContainer
->view()->selectAll();
806 void DolphinMainWindow::invertSelection()
809 m_activeViewContainer
->view()->invertSelection();
812 void DolphinMainWindow::toggleSplitView()
814 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
815 tabPage
->setSplitViewEnabled(!tabPage
->splitViewEnabled());
820 void DolphinMainWindow::toggleSplitStash()
822 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
823 tabPage
->setSplitViewEnabled(false);
824 tabPage
->setSplitViewEnabled(true, QUrl("stash:/"));
827 void DolphinMainWindow::reloadView()
830 m_activeViewContainer
->reload();
831 m_activeViewContainer
->statusBar()->updateSpaceInfo();
834 void DolphinMainWindow::stopLoading()
836 m_activeViewContainer
->view()->stopLoading();
839 void DolphinMainWindow::enableStopAction()
841 actionCollection()->action(QStringLiteral("stop"))->setEnabled(true);
844 void DolphinMainWindow::disableStopAction()
846 actionCollection()->action(QStringLiteral("stop"))->setEnabled(false);
849 void DolphinMainWindow::showFilterBar()
851 m_activeViewContainer
->setFilterBarVisible(true);
854 void DolphinMainWindow::toggleEditLocation()
858 QAction
* action
= actionCollection()->action(QStringLiteral("editable_location"));
859 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
860 urlNavigator
->setUrlEditable(action
->isChecked());
863 void DolphinMainWindow::replaceLocation()
865 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
866 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit();
868 // If the text field currently has focus and everything is selected,
869 // pressing the keyboard shortcut returns the whole thing to breadcrumb mode
870 if (navigator
->isUrlEditable()
871 && lineEdit
->hasFocus()
872 && lineEdit
->selectedText() == lineEdit
->text() ) {
873 navigator
->setUrlEditable(false);
875 navigator
->setUrlEditable(true);
876 navigator
->setFocus();
877 lineEdit
->selectAll();
881 void DolphinMainWindow::togglePanelLockState()
883 const bool newLockState
= !GeneralSettings::lockPanels();
884 const auto childrenObjects
= children();
885 for (QObject
* child
: childrenObjects
) {
886 DolphinDockWidget
* dock
= qobject_cast
<DolphinDockWidget
*>(child
);
888 dock
->setLocked(newLockState
);
892 GeneralSettings::setLockPanels(newLockState
);
895 void DolphinMainWindow::slotTerminalPanelVisibilityChanged()
897 if (m_terminalPanel
->isHiddenInVisibleWindow() && m_activeViewContainer
) {
898 m_activeViewContainer
->view()->setFocus();
902 void DolphinMainWindow::goBack()
904 DolphinUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
905 urlNavigator
->goBack();
907 if (urlNavigator
->locationState().isEmpty()) {
908 // An empty location state indicates a redirection URL,
909 // which must be skipped too
910 urlNavigator
->goBack();
914 void DolphinMainWindow::goForward()
916 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goForward();
919 void DolphinMainWindow::goUp()
921 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goUp();
924 void DolphinMainWindow::goHome()
926 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goHome();
929 void DolphinMainWindow::goBackInNewTab()
931 const KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
932 const int index
= urlNavigator
->historyIndex() + 1;
933 openNewTabAfterCurrentTab(urlNavigator
->locationUrl(index
));
936 void DolphinMainWindow::goForwardInNewTab()
938 const KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
939 const int index
= urlNavigator
->historyIndex() - 1;
940 openNewTabAfterCurrentTab(urlNavigator
->locationUrl(index
));
943 void DolphinMainWindow::goUpInNewTab()
945 const QUrl currentUrl
= activeViewContainer()->urlNavigator()->locationUrl();
946 openNewTabAfterCurrentTab(KIO::upUrl(currentUrl
));
949 void DolphinMainWindow::goHomeInNewTab()
951 openNewTabAfterCurrentTab(Dolphin::homeUrl());
954 void DolphinMainWindow::compareFiles()
956 const KFileItemList items
= m_tabWidget
->currentTabPage()->selectedItems();
957 if (items
.count() != 2) {
958 // The action is disabled in this case, but it could have been triggered
959 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
963 QUrl urlA
= items
.at(0).url();
964 QUrl urlB
= items
.at(1).url();
966 QString
command(QStringLiteral("kompare -c \""));
967 command
.append(urlA
.toDisplayString(QUrl::PreferLocalFile
));
968 command
.append("\" \"");
969 command
.append(urlB
.toDisplayString(QUrl::PreferLocalFile
));
970 command
.append('\"');
972 KIO::CommandLauncherJob
*job
= new KIO::CommandLauncherJob(command
, this);
973 job
->setDesktopName(QStringLiteral("org.kde.kompare"));
977 void DolphinMainWindow::toggleShowMenuBar()
979 const bool visible
= menuBar()->isVisible();
980 menuBar()->setVisible(!visible
);
982 createControlButton();
984 deleteControlButton();
988 QPointer
<QAction
> DolphinMainWindow::preferredSearchTool()
990 m_searchTools
.clear();
991 KMoreToolsMenuFactory("dolphin/search-tools").fillMenuFromGroupingNames(
992 &m_searchTools
, { "files-find" }, m_activeViewContainer
->url()
994 QList
<QAction
*> actions
= m_searchTools
.actions();
995 if (actions
.isEmpty()) {
998 QAction
* action
= actions
.first();
999 if (action
->isSeparator()) {
1005 void DolphinMainWindow::updateOpenPreferredSearchToolAction()
1007 QAction
* openPreferredSearchTool
= actionCollection()->action(QStringLiteral("open_preferred_search_tool"));
1008 if (!openPreferredSearchTool
) {
1011 QPointer
<QAction
> tool
= preferredSearchTool();
1013 openPreferredSearchTool
->setVisible(true);
1014 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open %1", tool
->text()));
1015 openPreferredSearchTool
->setIcon(tool
->icon());
1017 openPreferredSearchTool
->setVisible(false);
1018 // still visible in Shortcuts configuration window
1019 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1020 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1024 void DolphinMainWindow::openPreferredSearchTool()
1026 QPointer
<QAction
> tool
= preferredSearchTool();
1032 void DolphinMainWindow::openTerminal()
1034 const QUrl url
= m_activeViewContainer
->url();
1036 if (url
.isLocalFile()) {
1037 KToolInvocation::invokeTerminal(QString(), url
.toLocalFile());
1041 // Not a local file, with protocol Class ":local", try stat'ing
1042 if (KProtocolInfo::protocolClass(url
.scheme()) == QLatin1String(":local")) {
1043 KIO::StatJob
*job
= KIO::mostLocalUrl(url
);
1044 KJobWidgets::setWindow(job
, this);
1045 connect(job
, &KJob::result
, this, [job
]() {
1047 if (!job
->error()) {
1048 statUrl
= job
->mostLocalUrl();
1051 KToolInvocation::invokeTerminal(QString(), statUrl
.isLocalFile() ? statUrl
.toLocalFile() : QDir::homePath());
1057 // Nothing worked, just use $HOME
1058 KToolInvocation::invokeTerminal(QString(), QDir::homePath());
1061 void DolphinMainWindow::editSettings()
1063 if (!m_settingsDialog
) {
1064 DolphinViewContainer
* container
= activeViewContainer();
1065 container
->view()->writeSettings();
1067 const QUrl url
= container
->url();
1068 DolphinSettingsDialog
* settingsDialog
= new DolphinSettingsDialog(url
, this);
1069 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, this, &DolphinMainWindow::refreshViews
);
1070 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
,
1071 &DolphinUrlNavigatorsController::slotReadSettings
);
1072 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1073 settingsDialog
->show();
1074 m_settingsDialog
= settingsDialog
;
1076 m_settingsDialog
.data()->raise();
1080 void DolphinMainWindow::handleUrl(const QUrl
& url
)
1082 delete m_lastHandleUrlOpenJob
;
1083 m_lastHandleUrlOpenJob
= nullptr;
1085 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1086 activeViewContainer()->setUrl(url
);
1088 m_lastHandleUrlOpenJob
= new KIO::OpenUrlJob(url
);
1089 m_lastHandleUrlOpenJob
->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
1090 m_lastHandleUrlOpenJob
->setShowOpenOrExecuteDialog(true);
1092 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::mimeTypeFound
, this,
1093 [this, url
](const QString
&mimetype
) {
1094 if (mimetype
== QLatin1String("inode/directory")) {
1095 // If it's a dir, we'll take it from here
1096 m_lastHandleUrlOpenJob
->kill();
1097 m_lastHandleUrlOpenJob
= nullptr;
1098 activeViewContainer()->setUrl(url
);
1102 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::result
, this, [this]() {
1103 m_lastHandleUrlOpenJob
= nullptr;
1106 m_lastHandleUrlOpenJob
->start();
1110 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1112 // trash:/ is writable but we don't want to create new items in it.
1113 // TODO: remove the trash check once https://phabricator.kde.org/T8234 is implemented
1114 newFileMenu()->setEnabled(isFolderWritable
&& m_activeViewContainer
->url().scheme() != QLatin1String("trash"));
1117 void DolphinMainWindow::openContextMenu(const QPoint
& pos
,
1118 const KFileItem
& item
,
1120 const QList
<QAction
*>& customActions
)
1122 QPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, pos
, item
, url
);
1123 contextMenu
.data()->setCustomActions(customActions
);
1124 const DolphinContextMenu::Command command
= contextMenu
.data()->open();
1127 case DolphinContextMenu::OpenParentFolder
:
1128 changeUrl(KIO::upUrl(item
.url()));
1129 m_activeViewContainer
->view()->markUrlsAsSelected({item
.url()});
1130 m_activeViewContainer
->view()->markUrlAsCurrent(item
.url());
1133 case DolphinContextMenu::OpenParentFolderInNewWindow
:
1134 Dolphin::openNewWindow({item
.url()}, this, Dolphin::OpenNewWindowFlag::Select
);
1137 case DolphinContextMenu::OpenParentFolderInNewTab
:
1138 openNewTabAfterLastTab(KIO::upUrl(item
.url()));
1141 case DolphinContextMenu::None
:
1146 // Delete the menu, unless it has been deleted in its own nested event loop already.
1148 contextMenu
->deleteLater();
1152 void DolphinMainWindow::updateControlMenu()
1154 QMenu
* menu
= qobject_cast
<QMenu
*>(sender());
1157 // All actions get cleared by QMenu::clear(). This includes the sub-menus
1158 // because 'menu' is their parent.
1161 KActionCollection
* ac
= actionCollection();
1163 menu
->addMenu(m_newFileMenu
->menu());
1164 addActionToMenu(ac
->action(QStringLiteral("file_new")), menu
);
1165 addActionToMenu(ac
->action(QStringLiteral("new_tab")), menu
);
1166 addActionToMenu(ac
->action(QStringLiteral("closed_tabs")), menu
);
1168 menu
->addSeparator();
1170 // Add "Edit" actions
1171 bool added
= addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Undo
)), menu
) |
1172 addActionToMenu(ac
->action(QString("copy_location")), menu
) |
1173 addActionToMenu(ac
->action(QStringLiteral("copy_to_inactive_split_view")), menu
) |
1174 addActionToMenu(ac
->action(QStringLiteral("move_to_inactive_split_view")), menu
) |
1175 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::SelectAll
)), menu
) |
1176 addActionToMenu(ac
->action(QStringLiteral("invert_selection")), menu
);
1179 menu
->addSeparator();
1182 // Add "View" actions
1183 if (!GeneralSettings::showZoomSlider()) {
1184 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomIn
)), menu
);
1185 addActionToMenu(ac
->action(QStringLiteral("view_zoom_reset")), menu
);
1186 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomOut
)), menu
);
1187 menu
->addSeparator();
1190 added
= addActionToMenu(ac
->action(QStringLiteral("show_preview")), menu
) |
1191 addActionToMenu(ac
->action(QStringLiteral("show_in_groups")), menu
) |
1192 addActionToMenu(ac
->action(QStringLiteral("show_hidden_files")), menu
) |
1193 addActionToMenu(ac
->action(QStringLiteral("additional_info")), menu
) |
1194 addActionToMenu(ac
->action(QStringLiteral("view_properties")), menu
);
1197 menu
->addSeparator();
1200 // Add a curated assortment of items from the "Tools" menu
1201 addActionToMenu(ac
->action(QStringLiteral("show_filter_bar")), menu
);
1202 addActionToMenu(ac
->action(QStringLiteral("open_preferred_search_tool")), menu
);
1203 addActionToMenu(ac
->action(QStringLiteral("open_terminal")), menu
);
1205 menu
->addSeparator();
1207 // Add "Show Panels" menu
1208 addActionToMenu(ac
->action(QStringLiteral("panels")), menu
);
1210 // Add "Settings" menu entries
1211 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)), menu
);
1212 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)), menu
);
1213 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Preferences
)), menu
);
1214 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)), menu
);
1217 auto helpMenu
= m_helpMenu
->menu();
1218 helpMenu
->setIcon(QIcon::fromTheme(QStringLiteral("system-help")));
1219 menu
->addMenu(helpMenu
);
1222 void DolphinMainWindow::updateToolBar()
1224 if (!menuBar()->isVisible()) {
1225 createControlButton();
1229 void DolphinMainWindow::slotControlButtonDeleted()
1231 m_controlButton
= nullptr;
1232 m_updateToolBarTimer
->start();
1235 void DolphinMainWindow::slotPlaceActivated(const QUrl
& url
)
1237 DolphinViewContainer
* view
= activeViewContainer();
1239 if (view
->url() == url
) {
1240 // We can end up here if the user clicked a device in the Places Panel
1241 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1248 void DolphinMainWindow::closedTabsCountChanged(unsigned int count
)
1250 actionCollection()->action(QStringLiteral("undo_close_tab"))->setEnabled(count
> 0);
1253 void DolphinMainWindow::activeViewChanged(DolphinViewContainer
* viewContainer
)
1255 DolphinViewContainer
* oldViewContainer
= m_activeViewContainer
;
1256 Q_ASSERT(viewContainer
);
1258 m_activeViewContainer
= viewContainer
;
1260 if (oldViewContainer
) {
1261 const QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
1262 toggleSearchAction
->disconnect(oldViewContainer
);
1264 // Disconnect all signals between the old view container (container,
1265 // view and url navigator) and main window.
1266 oldViewContainer
->disconnect(this);
1267 oldViewContainer
->view()->disconnect(this);
1268 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
1269 (actionCollection()->action(QStringLiteral("url_navigators")));
1270 navigators
->primaryUrlNavigator()->disconnect(this);
1271 if (auto secondaryUrlNavigator
= navigators
->secondaryUrlNavigator()) {
1272 secondaryUrlNavigator
->disconnect(this);
1275 // except the requestItemInfo so that on hover the information panel can still be updated
1276 connect(oldViewContainer
->view(), &DolphinView::requestItemInfo
,
1277 this, &DolphinMainWindow::requestItemInfo
);
1280 connectViewSignals(viewContainer
);
1282 m_actionHandler
->setCurrentView(viewContainer
->view());
1285 updateFileAndEditActions();
1286 updatePasteAction();
1287 updateViewActions();
1289 updateSearchAction();
1291 const QUrl url
= viewContainer
->url();
1292 Q_EMIT
urlChanged(url
);
1295 void DolphinMainWindow::tabCountChanged(int count
)
1297 const bool enableTabActions
= (count
> 1);
1298 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1299 actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i
))->setEnabled(enableTabActions
);
1301 actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions
);
1302 actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions
);
1303 actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions
);
1306 void DolphinMainWindow::updateWindowTitle()
1308 const QString newTitle
= m_activeViewContainer
->captionWindowTitle();
1309 if (windowTitle() != newTitle
) {
1310 setWindowTitle(newTitle
);
1314 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString
& mountPath
)
1316 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1317 setViewsToHomeIfMountPathOpen(mountPath
);
1320 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectory().startsWith(mountPath
)) {
1321 m_tearDownFromPlacesRequested
= true;
1322 m_terminalPanel
->goHome();
1323 // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
1325 m_placesPanel
->proceedWithTearDown();
1329 void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString
& mountPath
)
1331 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1332 setViewsToHomeIfMountPathOpen(mountPath
);
1335 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectory().startsWith(mountPath
)) {
1336 m_tearDownFromPlacesRequested
= false;
1337 m_terminalPanel
->goHome();
1341 void DolphinMainWindow::setViewsToHomeIfMountPathOpen(const QString
& mountPath
)
1343 const QVector
<DolphinViewContainer
*> theViewContainers
= viewContainers();
1344 for (DolphinViewContainer
*viewContainer
: theViewContainers
) {
1345 if (viewContainer
&& viewContainer
->url().toLocalFile().startsWith(mountPath
)) {
1346 viewContainer
->setUrl(QUrl::fromLocalFile(QDir::homePath()));
1349 disconnect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, nullptr, nullptr);
1352 void DolphinMainWindow::setupActions()
1354 // setup 'File' menu
1355 m_newFileMenu
= new DolphinNewFileMenu(actionCollection(), this);
1356 QMenu
* menu
= m_newFileMenu
->menu();
1357 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1358 menu
->setIcon(QIcon::fromTheme(QStringLiteral("document-new")));
1359 m_newFileMenu
->setDelayed(false);
1360 connect(menu
, &QMenu::aboutToShow
,
1361 this, &DolphinMainWindow::updateNewMenu
);
1363 QAction
* newWindow
= KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow
, actionCollection());
1364 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1365 newWindow
->setToolTip(i18nc("@info", "Open a new Dolphin window"));
1366 newWindow
->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1367 "window just like this one with the current location and view."
1368 "<nl/>You can drag and drop items between windows."));
1369 newWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1371 QAction
* newTab
= actionCollection()->addAction(QStringLiteral("new_tab"));
1372 newTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1373 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1374 newTab
->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1375 "<emphasis>Tab</emphasis> with the current location and view.<nl/>"
1376 "A tab is an additional view within this window. "
1377 "You can drag and drop items between tabs."));
1378 actionCollection()->setDefaultShortcuts(newTab
, {Qt::CTRL
+ Qt::Key_T
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_N
});
1379 connect(newTab
, &QAction::triggered
, this, &DolphinMainWindow::openNewActivatedTab
);
1381 QAction
* addToPlaces
= actionCollection()->addAction(QStringLiteral("add_to_places"));
1382 addToPlaces
->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new")));
1383 addToPlaces
->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places"));
1384 addToPlaces
->setWhatsThis(xi18nc("@info:whatsthis", "This adds the selected folder "
1385 "to the Places panel."));
1386 connect(addToPlaces
, &QAction::triggered
, this, &DolphinMainWindow::addToPlaces
);
1388 QAction
* closeTab
= KStandardAction::close(m_tabWidget
, QOverload
<>::of(&DolphinTabWidget::closeTab
), actionCollection());
1389 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1390 closeTab
->setWhatsThis(i18nc("@info:whatsthis", "This closes the "
1391 "currently viewed tab. If no more tabs are left this window "
1392 "will close instead."));
1394 QAction
* quitAction
= KStandardAction::quit(this, &DolphinMainWindow::quit
, actionCollection());
1395 quitAction
->setWhatsThis(i18nc("@info:whatsthis quit", "This closes this window."));
1397 // setup 'Edit' menu
1398 KStandardAction::undo(this,
1399 &DolphinMainWindow::undo
,
1400 actionCollection());
1402 // i18n: This will be the last paragraph for the whatsthis for all three:
1403 // Cut, Copy and Paste
1404 const QString cutCopyPastePara
= xi18nc("@info:whatsthis", "<para><emphasis>Cut, "
1405 "Copy</emphasis> and <emphasis>Paste</emphasis> work between many "
1406 "applications and are among the most used commands. That's why their "
1407 "<emphasis>keyboard shortcuts</emphasis> are prominently placed right "
1408 "next to each other on the keyboard: <shortcut>Ctrl+X</shortcut>, "
1409 "<shortcut>Ctrl+C</shortcut> and <shortcut>Ctrl+V</shortcut>.</para>");
1410 QAction
* cutAction
= KStandardAction::cut(this, &DolphinMainWindow::cut
, actionCollection());
1411 cutAction
->setWhatsThis(xi18nc("@info:whatsthis cut", "This copies the items "
1412 "in your current selection to the <emphasis>clipboard</emphasis>.<nl/>"
1413 "Use the <emphasis>Paste</emphasis> action afterwards to copy them from "
1414 "the clipboard to a new location. The items will be removed from their "
1415 "initial location.") + cutCopyPastePara
);
1416 QAction
* copyAction
= KStandardAction::copy(this, &DolphinMainWindow::copy
, actionCollection());
1417 copyAction
->setWhatsThis(xi18nc("@info:whatsthis copy", "This copies the "
1418 "items in your current selection to the <emphasis>clipboard</emphasis>."
1419 "<nl/>Use the <emphasis>Paste</emphasis> action afterwards to copy them "
1420 "from the clipboard to a new location.") + cutCopyPastePara
);
1421 QAction
* paste
= KStandardAction::paste(this, &DolphinMainWindow::paste
, actionCollection());
1422 // The text of the paste-action is modified dynamically by Dolphin
1423 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1424 // due to the long text, the text "Paste" is used:
1425 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1426 paste
->setWhatsThis(xi18nc("@info:whatsthis paste", "This copies the items from "
1427 "your <emphasis>clipboard</emphasis> to the currently viewed folder.<nl/>"
1428 "If the items were added to the clipboard by the <emphasis>Cut</emphasis> "
1429 "action they are removed from their old location.") + cutCopyPastePara
);
1431 QAction
* copyToOtherViewAction
= actionCollection()->addAction(QStringLiteral("copy_to_inactive_split_view"));
1432 copyToOtherViewAction
->setText(i18nc("@action:inmenu", "Copy to Inactive Split View"));
1433 copyToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Copy", "This copies the selected items from "
1434 "the <emphasis>active</emphasis> view to the inactive split view."));
1435 copyToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
1436 copyToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Copy to Inactive Split View"));
1437 actionCollection()->setDefaultShortcut(copyToOtherViewAction
, Qt::SHIFT
+ Qt::Key_F5
);
1438 connect(copyToOtherViewAction
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::copyToInactiveSplitView
);
1440 QAction
* moveToOtherViewAction
= actionCollection()->addAction(QStringLiteral("move_to_inactive_split_view"));
1441 moveToOtherViewAction
->setText(i18nc("@action:inmenu", "Move to Inactive Split View"));
1442 moveToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Move", "This moves the selected items from "
1443 "the <emphasis>active</emphasis> view to the inactive split view."));
1444 moveToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-cut")));
1445 moveToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Move to Inactive Split View"));
1446 actionCollection()->setDefaultShortcut(moveToOtherViewAction
, Qt::SHIFT
+ Qt::Key_F6
);
1447 connect(moveToOtherViewAction
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::moveToInactiveSplitView
);
1449 QAction
*searchAction
= KStandardAction::find(this, &DolphinMainWindow::find
, actionCollection());
1450 searchAction
->setText(i18n("Search..."));
1451 searchAction
->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
1452 searchAction
->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This helps you "
1453 "find files and folders by opening a <emphasis>find bar</emphasis>. "
1454 "There you can enter search terms and specify settings to find the "
1455 "objects you are looking for.</para><para>Use this help again on "
1456 "the find bar so we can have a look at it while the settings are "
1457 "explained.</para>"));
1459 // toggle_search acts as a copy of the main searchAction to be used mainly
1460 // in the toolbar, with no default shortcut attached, to avoid messing with
1461 // existing workflows (search bar always open and Ctrl-F to focus)
1462 QAction
*toggleSearchAction
= actionCollection()->addAction(QStringLiteral("toggle_search"));
1463 toggleSearchAction
->setText(i18nc("@action:inmenu", "Toggle Search Bar"));
1464 toggleSearchAction
->setIconText(i18nc("@action:intoolbar", "Search"));
1465 toggleSearchAction
->setIcon(searchAction
->icon());
1466 toggleSearchAction
->setToolTip(searchAction
->toolTip());
1467 toggleSearchAction
->setWhatsThis(searchAction
->whatsThis());
1468 toggleSearchAction
->setCheckable(true);
1470 QAction
* selectAllAction
= KStandardAction::selectAll(this, &DolphinMainWindow::selectAll
, actionCollection());
1471 selectAllAction
->setWhatsThis(xi18nc("@info:whatsthis", "This selects all "
1472 "files and folders in the current location."));
1474 QAction
* invertSelection
= actionCollection()->addAction(QStringLiteral("invert_selection"));
1475 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1476 invertSelection
->setWhatsThis(xi18nc("@info:whatsthis invert", "This selects all "
1477 "objects that you have currently <emphasis>not</emphasis> selected instead."));
1478 invertSelection
->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert")));
1479 actionCollection()->setDefaultShortcut(invertSelection
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_A
);
1480 connect(invertSelection
, &QAction::triggered
, this, &DolphinMainWindow::invertSelection
);
1482 // setup 'View' menu
1483 // (note that most of it is set up in DolphinViewActionHandler)
1485 QAction
* split
= actionCollection()->addAction(QStringLiteral("split_view"));
1486 split
->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This splits "
1487 "the folder view below into two autonomous views.</para><para>This "
1488 "way you can see two locations at once and move items between them "
1489 "quickly.</para>Click this again afterwards to recombine the views."));
1490 actionCollection()->setDefaultShortcut(split
, Qt::Key_F3
);
1491 connect(split
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitView
);
1493 QAction
* stashSplit
= actionCollection()->addAction(QStringLiteral("split_stash"));
1494 actionCollection()->setDefaultShortcut(stashSplit
, Qt::CTRL
+ Qt::Key_S
);
1495 stashSplit
->setText(i18nc("@action:intoolbar Stash", "Stash"));
1496 stashSplit
->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
1497 stashSplit
->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
1498 stashSplit
->setCheckable(false);
1499 stashSplit
->setVisible(KProtocolInfo::isKnownProtocol("stash"));
1500 connect(stashSplit
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitStash
);
1502 KStandardAction::redisplay(this, &DolphinMainWindow::reloadView
, actionCollection());
1504 QAction
* stop
= actionCollection()->addAction(QStringLiteral("stop"));
1505 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1506 stop
->setToolTip(i18nc("@info", "Stop loading"));
1507 stop
->setWhatsThis(i18nc("@info", "This stops the loading of the contents of the current folder."));
1508 stop
->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
1509 connect(stop
, &QAction::triggered
, this, &DolphinMainWindow::stopLoading
);
1511 KToggleAction
* editableLocation
= actionCollection()->add
<KToggleAction
>(QStringLiteral("editable_location"));
1512 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1513 editableLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1514 "This toggles the <emphasis>Location Bar</emphasis> to be "
1515 "editable so you can directly enter a location you want to go to.<nl/>"
1516 "You can also switch to editing by clicking to the right of the "
1517 "location and switch back by confirming the edited location."));
1518 actionCollection()->setDefaultShortcut(editableLocation
, Qt::Key_F6
);
1519 connect(editableLocation
, &KToggleAction::triggered
, this, &DolphinMainWindow::toggleEditLocation
);
1521 QAction
* replaceLocation
= actionCollection()->addAction(QStringLiteral("replace_location"));
1522 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1523 // i18n: "enter" is used both in the meaning of "writing" and "going to" a new location here.
1524 // Both meanings are useful but not necessary to understand the use of "Replace Location".
1525 // So you might want to be more verbose in your language to convey the meaning but it's up to you.
1526 replaceLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1527 "This switches to editing the location and selects it "
1528 "so you can quickly enter a different location."));
1529 actionCollection()->setDefaultShortcut(replaceLocation
, Qt::CTRL
+ Qt::Key_L
);
1530 connect(replaceLocation
, &QAction::triggered
, this, &DolphinMainWindow::replaceLocation
);
1534 QScopedPointer
<QAction
> backAction(KStandardAction::back(nullptr, nullptr, nullptr));
1535 m_backAction
= new KToolBarPopupAction(backAction
->icon(), backAction
->text(), actionCollection());
1536 m_backAction
->setObjectName(backAction
->objectName());
1537 m_backAction
->setShortcuts(backAction
->shortcuts());
1539 m_backAction
->setDelayed(true);
1540 m_backAction
->setStickyMenu(false);
1541 connect(m_backAction
, &QAction::triggered
, this, &DolphinMainWindow::goBack
);
1542 connect(m_backAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowBackPopupMenu
);
1543 connect(m_backAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoBack
);
1544 actionCollection()->addAction(m_backAction
->objectName(), m_backAction
);
1546 auto backShortcuts
= m_backAction
->shortcuts();
1547 backShortcuts
.append(QKeySequence(Qt::Key_Backspace
));
1548 actionCollection()->setDefaultShortcuts(m_backAction
, backShortcuts
);
1550 DolphinRecentTabsMenu
* recentTabsMenu
= new DolphinRecentTabsMenu(this);
1551 actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu
);
1552 connect(m_tabWidget
, &DolphinTabWidget::rememberClosedTab
,
1553 recentTabsMenu
, &DolphinRecentTabsMenu::rememberClosedTab
);
1554 connect(recentTabsMenu
, &DolphinRecentTabsMenu::restoreClosedTab
,
1555 m_tabWidget
, &DolphinTabWidget::restoreClosedTab
);
1556 connect(recentTabsMenu
, &DolphinRecentTabsMenu::closedTabsCountChanged
,
1557 this, &DolphinMainWindow::closedTabsCountChanged
);
1559 QAction
* undoCloseTab
= actionCollection()->addAction(QStringLiteral("undo_close_tab"));
1560 undoCloseTab
->setText(i18nc("@action:inmenu File", "Undo close tab"));
1561 undoCloseTab
->setWhatsThis(i18nc("@info:whatsthis undo close tab",
1562 "This returns you to the previously closed tab."));
1563 actionCollection()->setDefaultShortcut(undoCloseTab
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_T
);
1564 undoCloseTab
->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
1565 undoCloseTab
->setEnabled(false);
1566 connect(undoCloseTab
, &QAction::triggered
, recentTabsMenu
, &DolphinRecentTabsMenu::undoCloseTab
);
1568 auto undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
1569 undoAction
->setWhatsThis(xi18nc("@info:whatsthis", "This undoes "
1570 "the last change you made to files or folders.<nl/>"
1571 "Such changes include <interface>creating, renaming</interface> "
1572 "and <interface>moving</interface> them to a different location "
1573 "or to the <filename>Trash</filename>. <nl/>Changes that can't "
1574 "be undone will ask for your confirmation."));
1575 undoAction
->setEnabled(false); // undo should be disabled by default
1578 QScopedPointer
<QAction
> forwardAction(KStandardAction::forward(nullptr, nullptr, nullptr));
1579 m_forwardAction
= new KToolBarPopupAction(forwardAction
->icon(), forwardAction
->text(), actionCollection());
1580 m_forwardAction
->setObjectName(forwardAction
->objectName());
1581 m_forwardAction
->setShortcuts(forwardAction
->shortcuts());
1583 m_forwardAction
->setDelayed(true);
1584 m_forwardAction
->setStickyMenu(false);
1585 connect(m_forwardAction
, &QAction::triggered
, this, &DolphinMainWindow::goForward
);
1586 connect(m_forwardAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowForwardPopupMenu
);
1587 connect(m_forwardAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoForward
);
1588 actionCollection()->addAction(m_forwardAction
->objectName(), m_forwardAction
);
1589 actionCollection()->setDefaultShortcuts(m_forwardAction
, m_forwardAction
->shortcuts());
1591 // enable middle-click to open in a new tab
1592 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
1593 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotBackForwardActionMiddleClicked
);
1594 m_backAction
->menu()->installEventFilter(middleClickEventFilter
);
1595 m_forwardAction
->menu()->installEventFilter(middleClickEventFilter
);
1596 KStandardAction::up(this, &DolphinMainWindow::goUp
, actionCollection());
1597 QAction
* homeAction
= KStandardAction::home(this, &DolphinMainWindow::goHome
, actionCollection());
1598 homeAction
->setWhatsThis(xi18nc("@info:whatsthis", "Go to your "
1599 "<filename>Home</filename> folder.<nl/>Every user account "
1600 "has their own <filename>Home</filename> that contains their data "
1601 "including folders that contain personal application data."));
1603 // setup 'Tools' menu
1604 QAction
* showFilterBar
= actionCollection()->addAction(QStringLiteral("show_filter_bar"));
1605 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1606 showFilterBar
->setWhatsThis(xi18nc("@info:whatsthis", "This opens the "
1607 "<emphasis>Filter Bar</emphasis> at the bottom of the window.<nl/> "
1608 "There you can enter a text to filter the files and folders currently displayed. "
1609 "Only those that contain the text in their name will be kept in view."));
1610 showFilterBar
->setIcon(QIcon::fromTheme(QStringLiteral("view-filter")));
1611 actionCollection()->setDefaultShortcuts(showFilterBar
, {Qt::CTRL
+ Qt::Key_I
, Qt::Key_Slash
});
1612 connect(showFilterBar
, &QAction::triggered
, this, &DolphinMainWindow::showFilterBar
);
1614 QAction
* compareFiles
= actionCollection()->addAction(QStringLiteral("compare_files"));
1615 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1616 compareFiles
->setIcon(QIcon::fromTheme(QStringLiteral("kompare")));
1617 compareFiles
->setEnabled(false);
1618 connect(compareFiles
, &QAction::triggered
, this, &DolphinMainWindow::compareFiles
);
1620 QAction
* openPreferredSearchTool
= actionCollection()->addAction(QStringLiteral("open_preferred_search_tool"));
1621 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1622 openPreferredSearchTool
->setWhatsThis(xi18nc("@info:whatsthis",
1623 "<para>This opens a preferred search tool for the viewed location.</para>"
1624 "<para>Use <emphasis>More Search Tools</emphasis> menu to configure it.</para>"));
1625 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1626 actionCollection()->setDefaultShortcut(openPreferredSearchTool
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_F
);
1627 connect(openPreferredSearchTool
, &QAction::triggered
, this, &DolphinMainWindow::openPreferredSearchTool
);
1629 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1630 QAction
* openTerminal
= actionCollection()->addAction(QStringLiteral("open_terminal"));
1631 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1632 openTerminal
->setWhatsThis(xi18nc("@info:whatsthis",
1633 "<para>This opens a <emphasis>terminal</emphasis> application for the viewed location.</para>"
1634 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1635 openTerminal
->setIcon(QIcon::fromTheme(QStringLiteral("dialog-scripts")));
1636 actionCollection()->setDefaultShortcut(openTerminal
, Qt::SHIFT
+ Qt::Key_F4
);
1637 connect(openTerminal
, &QAction::triggered
, this, &DolphinMainWindow::openTerminal
);
1639 #ifdef HAVE_TERMINAL
1640 QAction
* focusTerminalPanel
= actionCollection()->addAction(QStringLiteral("focus_terminal_panel"));
1641 focusTerminalPanel
->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
1642 focusTerminalPanel
->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
1643 actionCollection()->setDefaultShortcut(focusTerminalPanel
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_F4
);
1644 connect(focusTerminalPanel
, &QAction::triggered
, this, &DolphinMainWindow::focusTerminalPanel
);
1648 // setup 'Bookmarks' menu
1649 KActionMenu
*bookmarkMenu
= new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this);
1650 bookmarkMenu
->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks")));
1651 // Make the toolbar button version work properly on click
1652 bookmarkMenu
->setDelayed(false);
1653 m_bookmarkHandler
= new DolphinBookmarkHandler(this, actionCollection(), bookmarkMenu
->menu(), this);
1654 actionCollection()->addAction(QStringLiteral("bookmarks"), bookmarkMenu
);
1656 // setup 'Settings' menu
1657 KToggleAction
* showMenuBar
= KStandardAction::showMenubar(nullptr, nullptr, actionCollection());
1658 showMenuBar
->setWhatsThis(xi18nc("@info:whatsthis",
1659 "This switches between having a <emphasis>Menubar</emphasis> "
1660 "and having a <interface>Control</interface> button. Both "
1661 "contain mostly the same commands and configuration options."));
1662 connect(showMenuBar
, &KToggleAction::triggered
, // Fixes #286822
1663 this, &DolphinMainWindow::toggleShowMenuBar
, Qt::QueuedConnection
);
1664 KStandardAction::preferences(this, &DolphinMainWindow::editSettings
, actionCollection());
1666 // setup 'Help' menu for the m_controlButton. The other one is set up in the base class.
1667 m_helpMenu
= new KHelpMenu(nullptr);
1668 m_helpMenu
->menu()->installEventFilter(this);
1669 // remove duplicate shortcuts
1670 m_helpMenu
->action(KHelpMenu::menuHelpContents
)->setShortcut(QKeySequence());
1671 m_helpMenu
->action(KHelpMenu::menuWhatsThis
)->setShortcut(QKeySequence());
1673 // not in menu actions
1674 QList
<QKeySequence
> nextTabKeys
= KStandardShortcut::tabNext();
1675 nextTabKeys
.append(QKeySequence(Qt::CTRL
+ Qt::Key_Tab
));
1677 QList
<QKeySequence
> prevTabKeys
= KStandardShortcut::tabPrev();
1678 prevTabKeys
.append(QKeySequence(Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_Tab
));
1680 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1681 QAction
* activateTab
= actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i
));
1682 activateTab
->setText(i18nc("@action:inmenu", "Activate Tab %1", i
+ 1));
1683 activateTab
->setEnabled(false);
1684 connect(activateTab
, &QAction::triggered
, this, [this, i
]() { m_tabWidget
->activateTab(i
); });
1686 // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts
1688 actionCollection()->setDefaultShortcut(activateTab
, QStringLiteral("Alt+%1").arg(i
+ 1));
1692 QAction
* activateLastTab
= actionCollection()->addAction(QStringLiteral("activate_last_tab"));
1693 activateLastTab
->setText(i18nc("@action:inmenu", "Activate Last Tab"));
1694 activateLastTab
->setEnabled(false);
1695 connect(activateLastTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateLastTab
);
1696 actionCollection()->setDefaultShortcut(activateLastTab
, Qt::ALT
+ Qt::Key_0
);
1698 QAction
* activateNextTab
= actionCollection()->addAction(QStringLiteral("activate_next_tab"));
1699 activateNextTab
->setIconText(i18nc("@action:inmenu", "Next Tab"));
1700 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1701 activateNextTab
->setEnabled(false);
1702 connect(activateNextTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateNextTab
);
1703 actionCollection()->setDefaultShortcuts(activateNextTab
, nextTabKeys
);
1705 QAction
* activatePrevTab
= actionCollection()->addAction(QStringLiteral("activate_prev_tab"));
1706 activatePrevTab
->setIconText(i18nc("@action:inmenu", "Previous Tab"));
1707 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1708 activatePrevTab
->setEnabled(false);
1709 connect(activatePrevTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activatePrevTab
);
1710 actionCollection()->setDefaultShortcuts(activatePrevTab
, prevTabKeys
);
1713 QAction
* showTarget
= actionCollection()->addAction(QStringLiteral("show_target"));
1714 showTarget
->setText(i18nc("@action:inmenu", "Show Target"));
1715 showTarget
->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
1716 showTarget
->setEnabled(false);
1717 connect(showTarget
, &QAction::triggered
, this, &DolphinMainWindow::showTarget
);
1719 QAction
* openInNewTab
= actionCollection()->addAction(QStringLiteral("open_in_new_tab"));
1720 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1721 openInNewTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1722 connect(openInNewTab
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
1724 QAction
* openInNewTabs
= actionCollection()->addAction(QStringLiteral("open_in_new_tabs"));
1725 openInNewTabs
->setText(i18nc("@action:inmenu", "Open in New Tabs"));
1726 openInNewTabs
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1727 connect(openInNewTabs
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
1729 QAction
* openInNewWindow
= actionCollection()->addAction(QStringLiteral("open_in_new_window"));
1730 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1731 openInNewWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1732 connect(openInNewWindow
, &QAction::triggered
, this, &DolphinMainWindow::openInNewWindow
);
1735 void DolphinMainWindow::setupDockWidgets()
1737 const bool lock
= GeneralSettings::lockPanels();
1739 KDualAction
* lockLayoutAction
= actionCollection()->add
<KDualAction
>(QStringLiteral("lock_panels"));
1740 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1741 lockLayoutAction
->setActiveIcon(QIcon::fromTheme(QStringLiteral("object-unlocked")));
1742 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1743 lockLayoutAction
->setInactiveIcon(QIcon::fromTheme(QStringLiteral("object-locked")));
1744 lockLayoutAction
->setWhatsThis(xi18nc("@info:whatsthis", "This "
1745 "switches between having panels <emphasis>locked</emphasis> or "
1746 "<emphasis>unlocked</emphasis>.<nl/>Unlocked panels can be "
1747 "dragged to the other side of the window and have a close "
1748 "button.<nl/>Locked panels are embedded more cleanly."));
1749 lockLayoutAction
->setActive(lock
);
1750 connect(lockLayoutAction
, &KDualAction::triggered
, this, &DolphinMainWindow::togglePanelLockState
);
1752 // Setup "Information"
1753 DolphinDockWidget
* infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
1754 infoDock
->setLocked(lock
);
1755 infoDock
->setObjectName(QStringLiteral("infoDock"));
1756 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1759 InformationPanel
* infoPanel
= new InformationPanel(infoDock
);
1760 infoPanel
->setCustomContextMenuActions({lockLayoutAction
});
1761 connect(infoPanel
, &InformationPanel::urlActivated
, this, &DolphinMainWindow::handleUrl
);
1762 infoDock
->setWidget(infoPanel
);
1764 QAction
* infoAction
= infoDock
->toggleViewAction();
1765 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-information")), Qt::Key_F11
, infoAction
, QStringLiteral("show_information_panel"));
1767 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1768 connect(this, &DolphinMainWindow::urlChanged
,
1769 infoPanel
, &InformationPanel::setUrl
);
1770 connect(this, &DolphinMainWindow::selectionChanged
,
1771 infoPanel
, &InformationPanel::setSelection
);
1772 connect(this, &DolphinMainWindow::requestItemInfo
,
1773 infoPanel
, &InformationPanel::requestDelayedItemInfo
);
1776 // i18n: This is the last paragraph for the "What's This"-texts of all four panels.
1777 const QString panelWhatsThis
= xi18nc("@info:whatsthis", "<para>To show or "
1778 "hide panels like this go to <interface>Control|Panels</interface> "
1779 "or <interface>View|Panels</interface>.</para>");
1781 actionCollection()->action(QStringLiteral("show_information_panel"))
1782 ->setWhatsThis(xi18nc("@info:whatsthis", "<para> This toggles the "
1783 "<emphasis>information</emphasis> panel at the right side of the "
1784 "window.</para><para>The panel provides in-depth information "
1785 "about the items your mouse is hovering over or about the selected "
1786 "items. Otherwise it informs you about the currently viewed folder.<nl/>"
1787 "For single items a preview of their contents is provided.</para>"));
1789 infoDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
1790 "provides in-depth information about the items your mouse is "
1791 "hovering over or about the selected items. Otherwise it informs "
1792 "you about the currently viewed folder.<nl/>For single items a "
1793 "preview of their contents is provided.</para><para>You can configure "
1794 "which and how details are given here by right-clicking.</para>") + panelWhatsThis
);
1797 DolphinDockWidget
* foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
1798 foldersDock
->setLocked(lock
);
1799 foldersDock
->setObjectName(QStringLiteral("foldersDock"));
1800 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1801 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1802 foldersPanel
->setCustomContextMenuActions({lockLayoutAction
});
1803 foldersDock
->setWidget(foldersPanel
);
1805 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1806 createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7
, foldersAction
, QStringLiteral("show_folders_panel"));
1808 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1809 connect(this, &DolphinMainWindow::urlChanged
,
1810 foldersPanel
, &FoldersPanel::setUrl
);
1811 connect(foldersPanel
, &FoldersPanel::folderActivated
,
1812 this, &DolphinMainWindow::changeUrl
);
1813 connect(foldersPanel
, &FoldersPanel::folderMiddleClicked
,
1814 this, &DolphinMainWindow::openNewTabAfterCurrentTab
);
1815 connect(foldersPanel
, &FoldersPanel::errorMessage
,
1816 this, &DolphinMainWindow::showErrorMessage
);
1818 actionCollection()->action(QStringLiteral("show_folders_panel"))
1819 ->setWhatsThis(xi18nc("@info:whatsthis", "This toggles the "
1820 "<emphasis>folders</emphasis> panel at the left side of the window."
1821 "<nl/><nl/>It shows the folders of the <emphasis>file system"
1822 "</emphasis> in a <emphasis>tree view</emphasis>."));
1823 foldersDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
1824 "shows the folders of the <emphasis>file system</emphasis> in a "
1825 "<emphasis>tree view</emphasis>.</para><para>Click a folder to go "
1826 "there. Click the arrow to the left of a folder to see its subfolders. "
1827 "This allows quick switching between any folders.</para>") + panelWhatsThis
);
1830 #ifdef HAVE_TERMINAL
1831 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1832 DolphinDockWidget
* terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1833 terminalDock
->setLocked(lock
);
1834 terminalDock
->setObjectName(QStringLiteral("terminalDock"));
1835 m_terminalPanel
= new TerminalPanel(terminalDock
);
1836 m_terminalPanel
->setCustomContextMenuActions({lockLayoutAction
});
1837 terminalDock
->setWidget(m_terminalPanel
);
1839 connect(m_terminalPanel
, &TerminalPanel::hideTerminalPanel
, terminalDock
, &DolphinDockWidget::hide
);
1840 connect(m_terminalPanel
, &TerminalPanel::changeUrl
, this, &DolphinMainWindow::slotTerminalDirectoryChanged
);
1841 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
,
1842 m_terminalPanel
, &TerminalPanel::dockVisibilityChanged
);
1843 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
,
1844 this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged
);
1846 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1847 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4
, terminalAction
, QStringLiteral("show_terminal_panel"));
1849 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1850 connect(this, &DolphinMainWindow::urlChanged
,
1851 m_terminalPanel
, &TerminalPanel::setUrl
);
1853 if (GeneralSettings::version() < 200) {
1854 terminalDock
->hide();
1857 actionCollection()->action(QStringLiteral("show_terminal_panel"))
1858 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
1859 "<emphasis>terminal</emphasis> panel at the bottom of the window."
1860 "<nl/>The location in the terminal will always match the folder "
1861 "view so you can navigate using either.</para><para>The terminal "
1862 "panel is not needed for basic computer usage but can be useful "
1863 "for advanced tasks. To learn more about terminals use the help "
1864 "in a standalone terminal application like Konsole.</para>"));
1865 terminalDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is "
1866 "the <emphasis>terminal</emphasis> panel. It behaves like a "
1867 "normal terminal but will match the location of the folder view "
1868 "so you can navigate using either.</para><para>The terminal panel "
1869 "is not needed for basic computer usage but can be useful for "
1870 "advanced tasks. To learn more about terminals use the help in a "
1871 "standalone terminal application like Konsole.</para>") + panelWhatsThis
);
1875 if (GeneralSettings::version() < 200) {
1877 foldersDock
->hide();
1881 DolphinDockWidget
* placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
1882 placesDock
->setLocked(lock
);
1883 placesDock
->setObjectName(QStringLiteral("placesDock"));
1884 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1886 m_placesPanel
= new PlacesPanel(placesDock
);
1887 m_placesPanel
->setCustomContextMenuActions({lockLayoutAction
});
1888 placesDock
->setWidget(m_placesPanel
);
1890 QAction
*placesAction
= placesDock
->toggleViewAction();
1891 createPanelAction(QIcon::fromTheme(QStringLiteral("bookmarks")), Qt::Key_F9
, placesAction
, QStringLiteral("show_places_panel"));
1893 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1894 connect(m_placesPanel
, &PlacesPanel::placeActivated
,
1895 this, &DolphinMainWindow::slotPlaceActivated
);
1896 connect(m_placesPanel
, &PlacesPanel::placeMiddleClicked
,
1897 this, &DolphinMainWindow::openNewTabAfterCurrentTab
);
1898 connect(m_placesPanel
, &PlacesPanel::errorMessage
,
1899 this, &DolphinMainWindow::showErrorMessage
);
1900 connect(this, &DolphinMainWindow::urlChanged
,
1901 m_placesPanel
, &PlacesPanel::setUrl
);
1902 connect(placesDock
, &DolphinDockWidget::visibilityChanged
,
1903 &DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged
);
1904 connect(this, &DolphinMainWindow::settingsChanged
,
1905 m_placesPanel
, &PlacesPanel::readSettings
);
1906 connect(m_placesPanel
, &PlacesPanel::storageTearDownRequested
,
1907 this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested
);
1908 connect(m_placesPanel
, &PlacesPanel::storageTearDownExternallyRequested
,
1909 this, &DolphinMainWindow::slotStorageTearDownExternallyRequested
);
1910 DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged(m_placesPanel
->isVisible());
1912 auto actionShowAllPlaces
= new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this);
1913 actionShowAllPlaces
->setCheckable(true);
1914 actionShowAllPlaces
->setDisabled(true);
1915 actionShowAllPlaces
->setWhatsThis(i18nc("@info:whatsthis", "This displays "
1916 "all places in the places panel that have been hidden. They will "
1917 "appear semi-transparent unless you uncheck their hide property."));
1919 connect(actionShowAllPlaces
, &QAction::triggered
, this, [actionShowAllPlaces
, this](bool checked
){
1920 actionShowAllPlaces
->setIcon(QIcon::fromTheme(checked
? QStringLiteral("view-visible") : QStringLiteral("view-hidden")));
1921 m_placesPanel
->showHiddenEntries(checked
);
1924 connect(m_placesPanel
, &PlacesPanel::showHiddenEntriesChanged
, this, [actionShowAllPlaces
] (bool checked
){
1925 actionShowAllPlaces
->setChecked(checked
);
1926 actionShowAllPlaces
->setIcon(QIcon::fromTheme(checked
? QStringLiteral("view-visible") : QStringLiteral("view-hidden")));
1929 actionCollection()->action(QStringLiteral("show_places_panel"))
1930 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
1931 "<emphasis>places</emphasis> panel at the left side of the window."
1932 "</para><para>It allows you to go to locations you have "
1933 "bookmarked and to access disk or media attached to the computer "
1934 "or to the network. It also contains sections to find recently "
1935 "saved files or files of a certain type.</para>"));
1936 placesDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
1937 "<emphasis>Places</emphasis> panel. It allows you to go to locations "
1938 "you have bookmarked and to access disk or media attached to the "
1939 "computer or to the network. It also contains sections to find "
1940 "recently saved files or files of a certain type.</para><para>"
1941 "Click on an entry to go there. Click with the right mouse button "
1942 "instead to open any entry in a new tab or new window.</para>"
1943 "<para>New entries can be added by dragging folders onto this panel. "
1944 "Right-click any section or entry to hide it. Right-click an empty "
1945 "space on this panel and select <interface>Show Hidden Places"
1946 "</interface> to display it again.</para>") + panelWhatsThis
);
1948 // Add actions into the "Panels" menu
1949 KActionMenu
* panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Show Panels"), this);
1950 actionCollection()->addAction(QStringLiteral("panels"), panelsMenu
);
1951 panelsMenu
->setIcon(QIcon::fromTheme(QStringLiteral("view-sidetree")));
1952 panelsMenu
->setDelayed(false);
1953 const KActionCollection
* ac
= actionCollection();
1954 panelsMenu
->addAction(ac
->action(QStringLiteral("show_places_panel")));
1956 panelsMenu
->addAction(ac
->action(QStringLiteral("show_information_panel")));
1958 panelsMenu
->addAction(ac
->action(QStringLiteral("show_folders_panel")));
1959 panelsMenu
->addAction(ac
->action(QStringLiteral("show_terminal_panel")));
1960 panelsMenu
->addSeparator();
1961 panelsMenu
->addAction(actionShowAllPlaces
);
1962 panelsMenu
->addAction(lockLayoutAction
);
1964 connect(panelsMenu
->menu(), &QMenu::aboutToShow
, this, [actionShowAllPlaces
, this]{
1965 actionShowAllPlaces
->setEnabled(m_placesPanel
->hiddenListCount());
1970 void DolphinMainWindow::updateFileAndEditActions()
1972 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1973 const KActionCollection
* col
= actionCollection();
1974 KFileItemListProperties
capabilitiesSource(list
);
1976 QAction
* addToPlacesAction
= col
->action(QStringLiteral("add_to_places"));
1977 QAction
* copyToOtherViewAction
= col
->action(QStringLiteral("copy_to_inactive_split_view"));
1978 QAction
* moveToOtherViewAction
= col
->action(QStringLiteral("move_to_inactive_split_view"));
1979 QAction
* copyLocation
= col
->action(QString("copy_location"));
1981 if (list
.isEmpty()) {
1982 stateChanged(QStringLiteral("has_no_selection"));
1984 addToPlacesAction
->setEnabled(true);
1985 copyToOtherViewAction
->setEnabled(false);
1986 moveToOtherViewAction
->setEnabled(false);
1987 copyLocation
->setEnabled(false);
1989 stateChanged(QStringLiteral("has_selection"));
1991 QAction
* renameAction
= col
->action(KStandardAction::name(KStandardAction::RenameFile
));
1992 QAction
* moveToTrashAction
= col
->action(KStandardAction::name(KStandardAction::MoveToTrash
));
1993 QAction
* deleteAction
= col
->action(KStandardAction::name(KStandardAction::DeleteFile
));
1994 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1995 QAction
* deleteWithTrashShortcut
= col
->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
1996 QAction
* showTarget
= col
->action(QStringLiteral("show_target"));
1997 QAction
* duplicateAction
= col
->action(QStringLiteral("duplicate")); // see DolphinViewActionHandler
1999 if (list
.length() == 1 && list
.first().isDir()) {
2000 addToPlacesAction
->setEnabled(true);
2002 addToPlacesAction
->setEnabled(false);
2005 if (m_tabWidget
->currentTabPage()->splitViewEnabled()) {
2006 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
2007 KFileItem capabilitiesDestination
;
2009 if (tabPage
->primaryViewActive()) {
2010 capabilitiesDestination
= tabPage
->secondaryViewContainer()->url();
2012 capabilitiesDestination
= tabPage
->primaryViewContainer()->url();
2015 copyToOtherViewAction
->setEnabled(capabilitiesDestination
.isWritable());
2016 moveToOtherViewAction
->setEnabled(capabilitiesSource
.supportsMoving() && capabilitiesDestination
.isWritable());
2018 copyToOtherViewAction
->setEnabled(false);
2019 moveToOtherViewAction
->setEnabled(false);
2022 const bool enableMoveToTrash
= capabilitiesSource
.isLocal() && capabilitiesSource
.supportsMoving();
2024 renameAction
->setEnabled(capabilitiesSource
.supportsMoving());
2025 moveToTrashAction
->setEnabled(enableMoveToTrash
);
2026 deleteAction
->setEnabled(capabilitiesSource
.supportsDeleting());
2027 deleteWithTrashShortcut
->setEnabled(capabilitiesSource
.supportsDeleting() && !enableMoveToTrash
);
2028 cutAction
->setEnabled(capabilitiesSource
.supportsMoving());
2029 copyLocation
->setEnabled(list
.length() == 1);
2030 showTarget
->setEnabled(list
.length() == 1 && list
.at(0).isLink());
2031 duplicateAction
->setEnabled(capabilitiesSource
.supportsWriting());
2035 void DolphinMainWindow::updateViewActions()
2037 m_actionHandler
->updateViewActions();
2039 QAction
* showFilterBarAction
= actionCollection()->action(QStringLiteral("show_filter_bar"));
2040 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
2042 updateSplitAction();
2045 void DolphinMainWindow::updateGoActions()
2047 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
2048 const QUrl currentUrl
= m_activeViewContainer
->url();
2049 // I think this is one of the best places to firstly be confronted
2050 // with a file system and its hierarchy. Talking about the root
2051 // directory might seem too much here but it is the question that
2052 // naturally arises in this context.
2053 goUpAction
->setWhatsThis(xi18nc("@info:whatsthis", "<para>Go to "
2054 "the folder that contains the currently viewed one.</para>"
2055 "<para>All files and folders are organized in a hierarchical "
2056 "<emphasis>file system</emphasis>. At the top of this hierarchy is "
2057 "a directory that contains all data connected to this computer"
2058 "—the <emphasis>root directory</emphasis>.</para>"));
2059 goUpAction
->setEnabled(KIO::upUrl(currentUrl
) != currentUrl
);
2062 void DolphinMainWindow::createControlButton()
2064 if (m_controlButton
) {
2067 Q_ASSERT(!m_controlButton
);
2069 m_controlButton
= new QToolButton(this);
2070 m_controlButton
->setAccessibleName(i18nc("@action:intoolbar", "Control"));
2071 m_controlButton
->setIcon(QIcon::fromTheme(QStringLiteral("application-menu")));
2072 m_controlButton
->setToolTip(i18nc("@action", "Show menu"));
2073 m_controlButton
->setAttribute(Qt::WidgetAttribute::WA_CustomWhatsThis
);
2074 m_controlButton
->setPopupMode(QToolButton::InstantPopup
);
2076 QMenu
* controlMenu
= new QMenu(m_controlButton
);
2077 connect(controlMenu
, &QMenu::aboutToShow
, this, &DolphinMainWindow::updateControlMenu
);
2078 controlMenu
->installEventFilter(this);
2080 m_controlButton
->setMenu(controlMenu
);
2082 toolBar()->addWidget(m_controlButton
);
2083 connect(toolBar(), &KToolBar::iconSizeChanged
,
2084 m_controlButton
, &QToolButton::setIconSize
);
2086 // The added widgets are owned by the toolbar and may get deleted when e.g. the toolbar
2087 // gets edited. In this case we must add them again. The adding is done asynchronously by
2088 // m_updateToolBarTimer.
2089 connect(m_controlButton
, &QToolButton::destroyed
, this, &DolphinMainWindow::slotControlButtonDeleted
);
2090 m_updateToolBarTimer
= new QTimer(this);
2091 m_updateToolBarTimer
->setInterval(500);
2092 connect(m_updateToolBarTimer
, &QTimer::timeout
, this, &DolphinMainWindow::updateToolBar
);
2095 void DolphinMainWindow::deleteControlButton()
2097 delete m_controlButton
;
2098 m_controlButton
= nullptr;
2100 delete m_updateToolBarTimer
;
2101 m_updateToolBarTimer
= nullptr;
2104 bool DolphinMainWindow::addActionToMenu(QAction
* action
, QMenu
* menu
)
2109 const KToolBar
* toolBarWidget
= toolBar();
2110 const auto associatedWidgets
= action
->associatedWidgets();
2111 for (const QWidget
* widget
: associatedWidgets
) {
2112 if (widget
== toolBarWidget
) {
2117 menu
->addAction(action
);
2121 void DolphinMainWindow::refreshViews()
2123 m_tabWidget
->refreshViews();
2125 if (GeneralSettings::modifiedStartupSettings()) {
2126 // The startup settings have been changed by the user (see bug #254947).
2127 // Synchronize the split-view setting with the active view:
2128 const bool splitView
= GeneralSettings::splitView();
2129 m_tabWidget
->currentTabPage()->setSplitViewEnabled(splitView
);
2130 updateSplitAction();
2131 updateWindowTitle();
2134 Q_EMIT
settingsChanged();
2137 void DolphinMainWindow::clearStatusBar()
2139 m_activeViewContainer
->statusBar()->resetToDefaultText();
2142 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
2144 connect(container
, &DolphinViewContainer::showFilterBarChanged
,
2145 this, &DolphinMainWindow::updateFilterBarAction
);
2146 connect(container
, &DolphinViewContainer::writeStateChanged
,
2147 this, &DolphinMainWindow::slotWriteStateChanged
);
2148 connect(container
, &DolphinViewContainer::searchModeEnabledChanged
,
2149 this, &DolphinMainWindow::updateSearchAction
);
2151 const QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
2152 connect(toggleSearchAction
, &QAction::triggered
, container
, &DolphinViewContainer::setSearchModeEnabled
);
2154 const DolphinView
* view
= container
->view();
2155 connect(view
, &DolphinView::selectionChanged
,
2156 this, &DolphinMainWindow::slotSelectionChanged
);
2157 connect(view
, &DolphinView::requestItemInfo
,
2158 this, &DolphinMainWindow::requestItemInfo
);
2159 connect(view
, &DolphinView::tabRequested
,
2160 this, &DolphinMainWindow::openNewTab
);
2161 connect(view
, &DolphinView::requestContextMenu
,
2162 this, &DolphinMainWindow::openContextMenu
);
2163 connect(view
, &DolphinView::directoryLoadingStarted
,
2164 this, &DolphinMainWindow::enableStopAction
);
2165 connect(view
, &DolphinView::directoryLoadingCompleted
,
2166 this, &DolphinMainWindow::disableStopAction
);
2167 connect(view
, &DolphinView::directoryLoadingCompleted
,
2168 this, &DolphinMainWindow::slotDirectoryLoadingCompleted
);
2169 connect(view
, &DolphinView::goBackRequested
,
2170 this, &DolphinMainWindow::goBack
);
2171 connect(view
, &DolphinView::goForwardRequested
,
2172 this, &DolphinMainWindow::goForward
);
2173 connect(view
, &DolphinView::urlActivated
,
2174 this, &DolphinMainWindow::handleUrl
);
2175 connect(view
, &DolphinView::goUpRequested
,
2176 this, &DolphinMainWindow::goUp
);
2178 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
2179 (actionCollection()->action(QStringLiteral("url_navigators")));
2181 const KUrlNavigator
*navigator
= m_tabWidget
->currentTabPage()->primaryViewActive() ?
2182 navigators
->primaryUrlNavigator() :
2183 navigators
->secondaryUrlNavigator();
2185 connect(navigator
, &KUrlNavigator::urlChanged
,
2186 this, &DolphinMainWindow::changeUrl
);
2187 QAction
*editableLocactionAction
= actionCollection()->action(QStringLiteral("editable_location"));
2188 editableLocactionAction
->setChecked(navigator
->isUrlEditable());
2189 connect(navigator
, &KUrlNavigator::editableStateChanged
,
2190 this, &DolphinMainWindow::slotEditableStateChanged
);
2191 connect(navigator
, &KUrlNavigator::tabRequested
,
2192 this, &DolphinMainWindow::openNewTabAfterLastTab
);
2194 disconnect(m_updateHistoryConnection
);
2195 m_updateHistoryConnection
= connect(
2196 container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::historyChanged
,
2197 this, &DolphinMainWindow::updateHistory
);
2200 void DolphinMainWindow::updateSplitAction()
2202 QAction
* splitAction
= actionCollection()->action(QStringLiteral("split_view"));
2203 const DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
2204 if (tabPage
->splitViewEnabled()) {
2205 if (GeneralSettings::closeActiveSplitView() ? tabPage
->primaryViewActive() : !tabPage
->primaryViewActive()) {
2206 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2207 splitAction
->setToolTip(i18nc("@info", "Close left view"));
2208 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close")));
2210 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2211 splitAction
->setToolTip(i18nc("@info", "Close right view"));
2212 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close")));
2215 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2216 splitAction
->setToolTip(i18nc("@info", "Split view"));
2217 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2221 void DolphinMainWindow::updateAllowedToolbarAreas()
2223 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
2224 (actionCollection()->action(QStringLiteral("url_navigators")));
2225 if (toolBar()->actions().contains(navigators
)) {
2226 toolBar()->setAllowedAreas(Qt::TopToolBarArea
| Qt::BottomToolBarArea
);
2227 if (toolBarArea(toolBar()) == Qt::LeftToolBarArea
||
2228 toolBarArea(toolBar()) == Qt::RightToolBarArea
) {
2229 addToolBar(Qt::TopToolBarArea
, toolBar());
2232 toolBar()->setAllowedAreas(Qt::AllToolBarAreas
);
2236 bool DolphinMainWindow::isKompareInstalled() const
2238 static bool initialized
= false;
2239 static bool installed
= false;
2241 // TODO: maybe replace this approach later by using a menu
2242 // plugin like kdiff3plugin.cpp
2243 installed
= !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty();
2249 void DolphinMainWindow::createPanelAction(const QIcon
& icon
,
2250 const QKeySequence
& shortcut
,
2251 QAction
* dockAction
,
2252 const QString
& actionName
)
2254 QAction
* panelAction
= actionCollection()->addAction(actionName
);
2255 panelAction
->setCheckable(true);
2256 panelAction
->setChecked(dockAction
->isChecked());
2257 panelAction
->setText(dockAction
->text());
2258 panelAction
->setIcon(icon
);
2259 actionCollection()->setDefaultShortcut(panelAction
, shortcut
);
2261 connect(panelAction
, &QAction::triggered
, dockAction
, &QAction::trigger
);
2262 connect(dockAction
, &QAction::toggled
, panelAction
, &QAction::setChecked
);
2265 void DolphinMainWindow::setupWhatsThis()
2268 menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2269 "<emphasis>Menubar</emphasis>. It provides access to commands and "
2270 "configuration options. Left-click on any of the menus on this "
2271 "bar to see its contents.</para><para>The Menubar can be hidden "
2272 "by unchecking <interface>Settings|Show Menubar</interface>. Then "
2273 "most of its contents become available through a <interface>Control"
2274 "</interface> button on the <emphasis>Toolbar</emphasis>.</para>"));
2275 toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2276 "<emphasis>Toolbar</emphasis>. It allows quick access to "
2277 "frequently used actions.</para><para>It is highly customizable. "
2278 "All items you see in the <interface>Control</interface> menu or "
2279 "in the <interface>Menubar</interface> can be placed on the "
2280 "Toolbar. Just right-click on it and select <interface>Configure "
2281 "Toolbars…</interface> or find this action in the <interface>"
2282 "Control</interface> or <interface>Settings</interface> menu."
2283 "</para><para>The location of the bar and the style of its "
2284 "buttons can also be changed in the right-click menu. Right-click "
2285 "a button if you want to show or hide its text.</para>"));
2286 m_tabWidget
->setWhatsThis(xi18nc("@info:whatsthis main view",
2287 "<para>Here you can see the <emphasis>folders</emphasis> and "
2288 "<emphasis>files</emphasis> that are at the location described in "
2289 "the <interface>Location Bar</interface> above. This area is the "
2290 "central part of this application where you navigate to the files "
2291 "you want to use.</para><para>For an elaborate and general "
2292 "introduction to this application <link "
2293 "url='https://userbase.kde.org/Dolphin/File_Management#Introduction_to_Dolphin'>"
2294 "click here</link>. This will open an introductory article from "
2295 "the <emphasis>KDE UserBase Wiki</emphasis>.</para><para>For brief "
2296 "explanations of all the features of this <emphasis>view</emphasis> "
2297 "<link url='help:/dolphin/dolphin-view.html'>click here</link> "
2298 "instead. This will open a page from the <emphasis>Handbook"
2299 "</emphasis> that covers the basics.</para>"));
2302 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings
))
2303 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window "
2304 "that lists the <emphasis>keyboard shortcuts</emphasis>.<nl/>"
2305 "There you can set up key combinations to trigger an action when "
2306 "they are pressed simultaneously. All commands in this application can "
2307 "be triggered this way.</para>"));
2308 actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars
))
2309 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window in which "
2310 "you can change which buttons appear on the <emphasis>Toolbar</emphasis>.</para>"
2311 "<para>All items you see in the <interface>Control</interface> menu "
2312 "or in the <interface>Menubar</interface> can also be placed on the Toolbar.</para>"));
2313 actionCollection()->action(KStandardAction::name(KStandardAction::Preferences
))
2314 ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can "
2315 "change a multitude of settings for this application. For an explanation "
2316 "of the various settings go to the chapter <emphasis>Configuring Dolphin"
2317 "</emphasis> in <interface>Help|Dolphin Handbook</interface>."));
2320 // The whatsthis has to be set for the m_helpMenu and for the
2321 // StandardAction separately because both are used in different locations.
2322 // m_helpMenu is only used for createControlButton() button.
2324 // Links do not work within the Menubar so texts without links are provided there.
2326 // i18n: If the external link isn't available in your language you should
2327 // probably state the external link language at least in brackets to not
2328 // frustrate the user. If there are multiple languages that the user might
2329 // know with a reasonable chance you might want to have 2 external links.
2330 // The same is in my opinion true for every external link you translate.
2331 const QString whatsThisHelpContents
= xi18nc("@info:whatsthis handbook",
2332 "<para>This opens the Handbook for this application. It provides "
2333 "explanations for every part of <emphasis>Dolphin</emphasis>.</para>");
2334 actionCollection()->action(KStandardAction::name(KStandardAction::HelpContents
))
2335 ->setWhatsThis(whatsThisHelpContents
2336 + xi18nc("@info:whatsthis second half of handbook hb text without link",
2337 "<para>If you want more elaborate introductions to the "
2338 "different features of <emphasis>Dolphin</emphasis> "
2339 "go to the KDE UserBase Wiki.</para>"));
2340 m_helpMenu
->action(KHelpMenu::menuHelpContents
)->setWhatsThis(whatsThisHelpContents
2341 + xi18nc("@info:whatsthis second half of handbook text with link",
2342 "<para>If you want more elaborate introductions to the "
2343 "different features of <emphasis>Dolphin</emphasis> "
2344 "<link url='https://userbase.kde.org/Dolphin/File_Management'>click here</link>. "
2345 "It will open the dedicated page in the KDE UserBase Wiki.</para>"));
2347 const QString whatsThisWhatsThis
= xi18nc("@info:whatsthis whatsthis button",
2348 "<para>This is the button that invokes the help feature you are "
2349 "using right now! Click it, then click any component of this "
2350 "application to ask \"What's this?\" about it. The mouse cursor "
2351 "will change appearance if no help is available for a spot.</para>");
2352 actionCollection()->action(KStandardAction::name(KStandardAction::WhatsThis
))
2353 ->setWhatsThis(whatsThisWhatsThis
2354 + xi18nc("@info:whatsthis second half of whatsthis button text without link",
2355 "<para>There are two other ways to get help for this application: The "
2356 "<interface>Dolphin Handbook</interface> in the <interface>Help"
2357 "</interface> menu and the <emphasis>KDE UserBase Wiki</emphasis> "
2358 "article about <emphasis>File Management</emphasis> online."
2359 "</para><para>The \"What's this?\" help is "
2360 "missing in most other windows so don't get too used to this.</para>"));
2361 m_helpMenu
->action(KHelpMenu::menuWhatsThis
)->setWhatsThis(whatsThisWhatsThis
2362 + xi18nc("@info:whatsthis second half of whatsthis button text with link",
2363 "<para>There are two other ways to get help: "
2364 "The <link url='help:/dolphin/index.html'>Dolphin Handbook</link> and "
2365 "the <link url='https://userbase.kde.org/Dolphin/File_Management'>KDE "
2366 "UserBase Wiki</link>.</para><para>The \"What's this?\" help is "
2367 "missing in most other windows so don't get too used to this.</para>"));
2369 const QString whatsThisReportBug
= xi18nc("@info:whatsthis","<para>This opens a "
2370 "window that will guide you through reporting errors or flaws "
2371 "in this application or in other KDE software.</para>");
2372 actionCollection()->action(KStandardAction::name(KStandardAction::ReportBug
))
2373 ->setWhatsThis(whatsThisReportBug
);
2374 m_helpMenu
->action(KHelpMenu::menuReportBug
)->setWhatsThis(whatsThisReportBug
2375 + xi18nc("@info:whatsthis second half of reportbug text with link",
2376 "<para>High-quality bug reports are much appreciated. To learn "
2377 "how to make your bug report as effective as possible "
2378 "<link url='https://community.kde.org/Get_Involved/Bug_Reporting'>"
2379 "click here</link>.</para>"));
2381 const QString whatsThisDonate
= xi18nc("@info:whatsthis","<para>This opens a "
2382 "<emphasis>web page</emphasis> where you can donate to "
2383 "support the continued work on this application and many "
2384 "other projects by the <emphasis>KDE</emphasis> community.</para>"
2385 "<para>Donating is the easiest and fastest way to efficiently "
2386 "support KDE and its projects. KDE projects are available for "
2387 "free therefore your donation is needed to cover things that "
2388 "require money like servers, contributor meetings, etc.</para>"
2389 "<para><emphasis>KDE e.V.</emphasis> is the non-profit "
2390 "organization behind the KDE community.</para>");
2391 actionCollection()->action(KStandardAction::name(KStandardAction::Donate
))
2392 ->setWhatsThis(whatsThisDonate
);
2393 m_helpMenu
->action(KHelpMenu::menuDonate
)->setWhatsThis(whatsThisDonate
);
2395 const QString whatsThisSwitchLanguage
= xi18nc("@info:whatsthis",
2396 "With this you can change the language this application uses."
2397 "<nl/>You can even set secondary languages which will be used "
2398 "if texts are not available in your preferred language.");
2399 actionCollection()->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
))
2400 ->setWhatsThis(whatsThisSwitchLanguage
);
2401 m_helpMenu
->action(KHelpMenu::menuSwitchLanguage
)->setWhatsThis(whatsThisSwitchLanguage
);
2403 const QString whatsThisAboutApp
= xi18nc("@info:whatsthis","This opens a "
2404 "window that informs you about the version, license, "
2405 "used libraries and maintainers of this application.");
2406 actionCollection()->action(KStandardAction::name(KStandardAction::AboutApp
))
2407 ->setWhatsThis(whatsThisAboutApp
);
2408 m_helpMenu
->action(KHelpMenu::menuAboutApp
)->setWhatsThis(whatsThisAboutApp
);
2410 const QString whatsThisAboutKDE
= xi18nc("@info:whatsthis","This opens a "
2411 "window with information about <emphasis>KDE</emphasis>. "
2412 "The KDE community are the people behind this free software."
2413 "<nl/>If you like using this application but don't know "
2414 "about KDE or want to see a cute dragon have a look!");
2415 actionCollection()->action(KStandardAction::name(KStandardAction::AboutKDE
))
2416 ->setWhatsThis(whatsThisAboutKDE
);
2417 m_helpMenu
->action(KHelpMenu::menuAboutKDE
)->setWhatsThis(whatsThisAboutKDE
);
2420 bool DolphinMainWindow::event(QEvent
*event
)
2422 if (event
->type() == QEvent::WhatsThisClicked
) {
2424 QWhatsThisClickedEvent
* whatsThisEvent
= dynamic_cast<QWhatsThisClickedEvent
*>(event
);
2425 QDesktopServices::openUrl(QUrl(whatsThisEvent
->href()));
2428 return KXmlGuiWindow::event(event
);
2431 bool DolphinMainWindow::eventFilter(QObject
* obj
, QEvent
* event
)
2434 if (event
->type() == QEvent::WhatsThisClicked
) {
2436 QWhatsThisClickedEvent
* whatsThisEvent
= dynamic_cast<QWhatsThisClickedEvent
*>(event
);
2437 QDesktopServices::openUrl(QUrl(whatsThisEvent
->href()));
2443 void DolphinMainWindow::saveNewToolbarConfig()
2445 KXmlGuiWindow::saveNewToolbarConfig(); // Applies the new config. This has to be called first
2446 // because the rest of this method decides things
2447 // based on the new config.
2448 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
2449 (actionCollection()->action(QStringLiteral("url_navigators")));
2450 if (!toolBar()->actions().contains(navigators
)) {
2451 m_tabWidget
->currentTabPage()->insertNavigatorsWidget(navigators
);
2453 updateAllowedToolbarAreas();
2456 void DolphinMainWindow::focusTerminalPanel()
2458 if (m_terminalPanel
->isVisible()) {
2459 if (m_terminalPanel
->terminalHasFocus()) {
2460 m_activeViewContainer
->view()->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2461 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2463 m_terminalPanel
->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2464 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2467 actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger();
2468 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2472 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
2473 KIO::FileUndoManager::UiInterface()
2477 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2481 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
2483 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2485 DolphinViewContainer
* container
= mainWin
->activeViewContainer();
2486 container
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
2488 KIO::FileUndoManager::UiInterface::jobError(job
);
2492 bool DolphinMainWindow::isUrlOpen(const QString
& url
)
2494 return m_tabWidget
->isUrlOpen(QUrl::fromUserInput((url
)));