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"
13 #include "dolphinbookmarkhandler.h"
14 #include "dolphindockwidget.h"
15 #include "dolphincontextmenu.h"
16 #include "dolphinnavigatorswidgetaction.h"
17 #include "dolphinnewfilemenu.h"
18 #include "dolphinrecenttabsmenu.h"
19 #include "dolphinplacesmodelsingleton.h"
20 #include "dolphinurlnavigatorscontroller.h"
21 #include "dolphinviewcontainer.h"
22 #include "dolphintabpage.h"
23 #include "middleclickactioneventfilter.h"
24 #include "panels/folders/folderspanel.h"
25 #include "panels/places/placespanel.h"
26 #include "panels/terminal/terminalpanel.h"
27 #include "settings/dolphinsettingsdialog.h"
28 #include "statusbar/dolphinstatusbar.h"
29 #include "views/dolphinviewactionhandler.h"
30 #include "views/dolphinremoteencoding.h"
31 #include "views/draganddrophelper.h"
32 #include "views/viewproperties.h"
33 #include "views/dolphinnewfilemenuobserver.h"
34 #include "dolphin_generalsettings.h"
36 #include <KActionCollection>
37 #include <KActionMenu>
38 #include <KAuthorized>
41 #include <KDualAction>
42 #include <KFileItemListProperties>
44 #include <KIO/CommandLauncherJob>
45 #include <KIO/JobUiDelegate>
46 #include <KIO/OpenFileManagerWindowJob>
47 #include <KIO/OpenUrlJob>
48 #include <KJobWidgets>
49 #include <KLocalizedString>
50 #include <KMessageBox>
51 #include <KMoreToolsMenuFactory>
52 #include <KProtocolInfo>
53 #include <KProtocolManager>
55 #include <KShortcutsDialog>
56 #include <KStandardAction>
57 #include <KStartupInfo>
59 #include <KTerminalLauncherJob>
60 #include <KToggleAction>
62 #include <KToolBarPopupAction>
63 #include <KUrlComboBox>
64 #include <KUrlNavigator>
65 #include <KWindowSystem>
66 #include <KXMLGUIFactory>
68 #include <kio_version.h>
70 #include <QApplication>
72 #include <QCloseEvent>
73 #include <QDesktopServices>
75 #include <QDomDocument>
79 #include <QPushButton>
81 #include <QStandardPaths>
83 #include <QToolButton>
84 #include <QWhatsThisClickedEvent>
87 // Used for GeneralSettings::version() to determine whether
88 // an updated version of Dolphin is running, so as to migrate
89 // removed/renamed ...etc config entries; increment it in such
91 const int CurrentDolphinVersion
= 202;
92 // The maximum number of entries in the back/forward popup menu
93 const int MaxNumberOfNavigationentries
= 12;
94 // The maximum number of "Activate Tab" shortcuts
95 const int MaxActivateTabShortcuts
= 9;
98 DolphinMainWindow::DolphinMainWindow() :
99 KXmlGuiWindow(nullptr),
100 m_newFileMenu(nullptr),
102 m_tabWidget(nullptr),
103 m_activeViewContainer(nullptr),
104 m_actionHandler(nullptr),
105 m_remoteEncoding(nullptr),
107 m_bookmarkHandler(nullptr),
108 m_controlButton(nullptr),
109 m_updateToolBarTimer(nullptr),
110 m_lastHandleUrlOpenJob(nullptr),
111 m_terminalPanel(nullptr),
112 m_placesPanel(nullptr),
113 m_tearDownFromPlacesRequested(false),
114 m_backAction(nullptr),
115 m_forwardAction(nullptr)
117 Q_INIT_RESOURCE(dolphin
);
119 new MainWindowAdaptor(this);
122 setWindowFlags(Qt::WindowContextHelpButtonHint
);
124 setComponentName(QStringLiteral("dolphin"), QGuiApplication::applicationDisplayName());
125 setObjectName(QStringLiteral("Dolphin#"));
127 setStateConfigGroup("State");
129 connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::errorMessage
,
130 this, &DolphinMainWindow::showErrorMessage
);
132 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
133 undoManager
->setUiInterface(new UndoUiInterface());
135 connect(undoManager
, &KIO::FileUndoManager::undoAvailable
,
136 this, &DolphinMainWindow::slotUndoAvailable
);
137 connect(undoManager
, &KIO::FileUndoManager::undoTextChanged
,
138 this, &DolphinMainWindow::slotUndoTextChanged
);
139 connect(undoManager
, &KIO::FileUndoManager::jobRecordingStarted
,
140 this, &DolphinMainWindow::clearStatusBar
);
141 connect(undoManager
, &KIO::FileUndoManager::jobRecordingFinished
,
142 this, &DolphinMainWindow::showCommand
);
144 const bool firstRun
= (GeneralSettings::version() < 200);
146 GeneralSettings::setViewPropsTimestamp(QDateTime::currentDateTime());
149 setAcceptDrops(true);
151 auto *navigatorsWidgetAction
= new DolphinNavigatorsWidgetAction(this);
152 actionCollection()->addAction(QStringLiteral("url_navigators"), navigatorsWidgetAction
);
153 m_tabWidget
= new DolphinTabWidget(navigatorsWidgetAction
, this);
154 m_tabWidget
->setObjectName("tabWidget");
155 connect(m_tabWidget
, &DolphinTabWidget::activeViewChanged
,
156 this, &DolphinMainWindow::activeViewChanged
);
157 connect(m_tabWidget
, &DolphinTabWidget::tabCountChanged
,
158 this, &DolphinMainWindow::tabCountChanged
);
159 connect(m_tabWidget
, &DolphinTabWidget::currentUrlChanged
,
160 this, &DolphinMainWindow::updateWindowTitle
);
161 setCentralWidget(m_tabWidget
);
165 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
166 connect(m_actionHandler
, &DolphinViewActionHandler::actionBeingHandled
, this, &DolphinMainWindow::clearStatusBar
);
167 connect(m_actionHandler
, &DolphinViewActionHandler::createDirectoryTriggered
, this, &DolphinMainWindow::createDirectory
);
169 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
170 connect(this, &DolphinMainWindow::urlChanged
,
171 m_remoteEncoding
, &DolphinRemoteEncoding::slotAboutToOpenUrl
);
175 setupGUI(Save
| Create
| ToolBar
);
176 stateChanged(QStringLiteral("new_file"));
178 QClipboard
* clipboard
= QApplication::clipboard();
179 connect(clipboard
, &QClipboard::dataChanged
,
180 this, &DolphinMainWindow::updatePasteAction
);
182 QAction
* toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
183 toggleFilterBarAction
->setChecked(GeneralSettings::filterBar());
186 menuBar()->setVisible(false);
189 const bool showMenu
= !menuBar()->isHidden();
190 QAction
* showMenuBarAction
= actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar
));
191 showMenuBarAction
->setChecked(showMenu
); // workaround for bug #171080
193 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(actionCollection()->action(
194 KStandardAction::name(KStandardAction::HamburgerMenu
)));
195 hamburgerMenu
->setMenuBar(menuBar());
196 hamburgerMenu
->setShowMenuBarAction(showMenuBarAction
);
197 connect(hamburgerMenu
, &KHamburgerMenu::aboutToShowMenu
,
198 this, &DolphinMainWindow::updateHamburgerMenu
);
199 hamburgerMenu
->hideActionsOf(toolBar());
200 if (GeneralSettings::version() < 201 && !toolBar()->actions().contains(hamburgerMenu
)) {
201 addHamburgerMenuToToolbar();
204 updateAllowedToolbarAreas();
206 // enable middle-click on back/forward/up to open in a new tab
207 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
208 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotToolBarActionMiddleClicked
);
209 toolBar()->installEventFilter(middleClickEventFilter
);
213 connect(KSycoca::self(), &KSycoca::databaseChanged
, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
215 QTimer::singleShot(0, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
217 m_fileItemActions
.setParentWidget(this);
218 connect(&m_fileItemActions
, &KFileItemActions::error
, this, [this](const QString
&errorMessage
) {
219 showErrorMessage(errorMessage
);
222 connect(GeneralSettings::self(), &GeneralSettings::splitViewChanged
,
223 this, &DolphinMainWindow::slotSplitViewChanged
);
226 DolphinMainWindow::~DolphinMainWindow()
228 // This fixes a crash on Wayland when closing the mainwindow while another dialog is open.
229 disconnect(QGuiApplication::clipboard(), &QClipboard::dataChanged
, this, &DolphinMainWindow::updatePasteAction
);
232 QVector
<DolphinViewContainer
*> DolphinMainWindow::viewContainers() const
234 QVector
<DolphinViewContainer
*> viewContainers
;
236 for (int i
= 0; i
< m_tabWidget
->count(); ++i
) {
237 DolphinTabPage
*tabPage
= m_tabWidget
->tabPageAt(i
);
239 viewContainers
<< tabPage
->primaryViewContainer();
240 if (tabPage
->splitViewEnabled()) {
241 viewContainers
<< tabPage
->secondaryViewContainer();
244 return viewContainers
;
247 void DolphinMainWindow::openDirectories(const QList
<QUrl
>& dirs
, bool splitView
)
249 m_tabWidget
->openDirectories(dirs
, splitView
);
252 void DolphinMainWindow::openDirectories(const QStringList
& dirs
, bool splitView
)
254 openDirectories(QUrl::fromStringList(dirs
), splitView
);
257 void DolphinMainWindow::openFiles(const QList
<QUrl
>& files
, bool splitView
)
259 m_tabWidget
->openFiles(files
, splitView
);
262 bool DolphinMainWindow::isFoldersPanelEnabled() const
264 return actionCollection()->action(QStringLiteral("show_folders_panel"))->isChecked();
267 bool DolphinMainWindow::isInformationPanelEnabled() const
270 return actionCollection()->action(QStringLiteral("show_information_panel"))->isChecked();
276 void DolphinMainWindow::openFiles(const QStringList
& files
, bool splitView
)
278 openFiles(QUrl::fromStringList(files
), splitView
);
281 void DolphinMainWindow::activateWindow()
283 window()->setAttribute(Qt::WA_NativeWindow
, true);
284 KStartupInfo::setNewStartupId(window()->windowHandle(), KStartupInfo::startupId());
285 KWindowSystem::activateWindow(window()->effectiveWinId());
288 bool DolphinMainWindow::isActiveWindow()
290 return window()->isActiveWindow();
293 void DolphinMainWindow::showCommand(CommandType command
)
295 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
297 case KIO::FileUndoManager::Copy
:
298 statusBar
->setText(i18nc("@info:status", "Successfully copied."));
300 case KIO::FileUndoManager::Move
:
301 statusBar
->setText(i18nc("@info:status", "Successfully moved."));
303 case KIO::FileUndoManager::Link
:
304 statusBar
->setText(i18nc("@info:status", "Successfully linked."));
306 case KIO::FileUndoManager::Trash
:
307 statusBar
->setText(i18nc("@info:status", "Successfully moved to trash."));
309 case KIO::FileUndoManager::Rename
:
310 statusBar
->setText(i18nc("@info:status", "Successfully renamed."));
313 case KIO::FileUndoManager::Mkdir
:
314 statusBar
->setText(i18nc("@info:status", "Created folder."));
322 void DolphinMainWindow::pasteIntoFolder()
324 m_activeViewContainer
->view()->pasteIntoFolder();
327 void DolphinMainWindow::changeUrl(const QUrl
&url
)
329 if (!KProtocolManager::supportsListing(url
)) {
330 // The URL navigator only checks for validity, not
331 // if the URL can be listed. An error message is
332 // shown due to DolphinViewContainer::restoreView().
336 m_activeViewContainer
->setUrl(url
);
337 updateFileAndEditActions();
342 Q_EMIT
urlChanged(url
);
345 void DolphinMainWindow::slotTerminalDirectoryChanged(const QUrl
& url
)
347 if (m_tearDownFromPlacesRequested
&& url
== QUrl::fromLocalFile(QDir::homePath())) {
348 m_placesPanel
->proceedWithTearDown();
349 m_tearDownFromPlacesRequested
= false;
352 m_activeViewContainer
->setAutoGrabFocus(false);
354 m_activeViewContainer
->setAutoGrabFocus(true);
357 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
359 KToggleAction
* editableLocationAction
=
360 static_cast<KToggleAction
*>(actionCollection()->action(QStringLiteral("editable_location")));
361 editableLocationAction
->setChecked(editable
);
364 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
366 updateFileAndEditActions();
368 const int selectedUrlsCount
= m_tabWidget
->currentTabPage()->selectedItemsCount();
370 QAction
* compareFilesAction
= actionCollection()->action(QStringLiteral("compare_files"));
371 if (selectedUrlsCount
== 2) {
372 compareFilesAction
->setEnabled(isKompareInstalled());
374 compareFilesAction
->setEnabled(false);
377 Q_EMIT
selectionChanged(selection
);
380 void DolphinMainWindow::updateHistory()
382 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
383 const int index
= urlNavigator
->historyIndex();
385 QAction
* backAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Back
));
387 backAction
->setToolTip(i18nc("@info", "Go back"));
388 backAction
->setWhatsThis(i18nc("@info:whatsthis go back", "Return to the previously viewed folder."));
389 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
392 QAction
* forwardAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Forward
));
394 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
395 forwardAction
->setWhatsThis(xi18nc("@info:whatsthis go forward",
396 "This undoes a <interface>Go|Back</interface> action."));
397 forwardAction
->setEnabled(index
> 0);
401 void DolphinMainWindow::updateFilterBarAction(bool show
)
403 QAction
* toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
404 toggleFilterBarAction
->setChecked(show
);
407 void DolphinMainWindow::openNewMainWindow()
409 Dolphin::openNewWindow({m_activeViewContainer
->url()}, this);
412 void DolphinMainWindow::openNewActivatedTab()
414 // keep browsers compatibility, new tab is always after last one
415 auto openNewTabAfterLastTabConfigured
= GeneralSettings::openNewTabAfterLastTab();
416 GeneralSettings::setOpenNewTabAfterLastTab(true);
417 m_tabWidget
->openNewActivatedTab();
418 GeneralSettings::setOpenNewTabAfterLastTab(openNewTabAfterLastTabConfigured
);
421 void DolphinMainWindow::addToPlaces()
426 // If nothing is selected, act on the current dir
427 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
428 url
= m_activeViewContainer
->url();
429 name
= m_activeViewContainer
->placesText();
431 const auto dirToAdd
= m_activeViewContainer
->view()->selectedItems().first();
432 url
= dirToAdd
.url();
433 name
= dirToAdd
.name();
437 if (m_activeViewContainer
->isSearchModeEnabled()) {
438 icon
= QStringLiteral("folder-saved-search-symbolic");
440 icon
= KIO::iconNameForUrl(url
);
442 DolphinPlacesModelSingleton::instance().placesModel()->addPlace(name
, url
, icon
);
446 void DolphinMainWindow::openNewTab(const QUrl
& url
)
448 m_tabWidget
->openNewTab(url
, QUrl());
451 void DolphinMainWindow::openNewTabAndActivate(const QUrl
&url
)
453 m_tabWidget
->openNewActivatedTab(url
, QUrl());
456 void DolphinMainWindow::openNewWindow(const QUrl
&url
)
458 Dolphin::openNewWindow({url
}, this);
461 void DolphinMainWindow::slotSplitViewChanged()
463 m_tabWidget
->currentTabPage()->setSplitViewEnabled(GeneralSettings::splitView(), WithAnimation
);
467 void DolphinMainWindow::openInNewTab()
469 const KFileItemList
& list
= m_activeViewContainer
->view()->selectedItems();
470 bool tabCreated
= false;
472 for (const KFileItem
& item
: list
) {
473 const QUrl
& url
= DolphinView::openItemAsFolderUrl(item
);
474 if (!url
.isEmpty()) {
480 // if no new tab has been created from the selection
481 // open the current directory in a new tab
483 openNewTab(m_activeViewContainer
->url());
487 void DolphinMainWindow::openInNewWindow()
491 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
492 if (list
.isEmpty()) {
493 newWindowUrl
= m_activeViewContainer
->url();
494 } else if (list
.count() == 1) {
495 const KFileItem
& item
= list
.first();
496 newWindowUrl
= DolphinView::openItemAsFolderUrl(item
);
499 if (!newWindowUrl
.isEmpty()) {
500 Dolphin::openNewWindow({newWindowUrl
}, this);
504 void DolphinMainWindow::showTarget()
506 const auto link
= m_activeViewContainer
->view()->selectedItems().at(0);
507 const auto linkLocationDir
= QFileInfo(link
.localPath()).absoluteDir();
508 auto linkDestination
= link
.linkDest();
509 if (QFileInfo(linkDestination
).isRelative()) {
510 linkDestination
= linkLocationDir
.filePath(linkDestination
);
512 if (QFileInfo::exists(linkDestination
)) {
513 KIO::highlightInFileManager({QUrl::fromLocalFile(linkDestination
).adjusted(QUrl::StripTrailingSlash
)});
515 m_activeViewContainer
->showMessage(xi18nc("@info", "Could not access <filename>%1</filename>.", linkDestination
),
516 DolphinViewContainer::Warning
);
520 void DolphinMainWindow::showEvent(QShowEvent
* event
)
522 KXmlGuiWindow::showEvent(event
);
524 if (!event
->spontaneous()) {
525 m_activeViewContainer
->view()->setFocus();
529 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
531 // Find out if Dolphin is closed directly by the user or
532 // by the session manager because the session is closed
533 bool closedByUser
= true;
534 if (qApp
->isSavingSession()) {
535 closedByUser
= false;
538 if (m_tabWidget
->count() > 1
539 && GeneralSettings::confirmClosingMultipleTabs()
540 && !GeneralSettings::rememberOpenedTabs()
542 // Ask the user if he really wants to quit and close all tabs.
543 // Open a confirmation dialog with 3 buttons:
544 // QDialogButtonBox::Yes -> Quit
545 // QDialogButtonBox::No -> Close only the current tab
546 // QDialogButtonBox::Cancel -> do nothing
547 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
548 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
549 dialog
->setModal(true);
550 QDialogButtonBox
* buttons
= new QDialogButtonBox(QDialogButtonBox::Yes
| QDialogButtonBox::No
| QDialogButtonBox::Cancel
);
551 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KGuiItem(i18nc("@action:button 'Quit Dolphin' button", "&Quit %1", QGuiApplication::applicationDisplayName()), QIcon::fromTheme(QStringLiteral("application-exit"))));
552 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("C&lose Current Tab"), QIcon::fromTheme(QStringLiteral("tab-close"))));
553 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
554 buttons
->button(QDialogButtonBox::Yes
)->setDefault(true);
556 bool doNotAskAgainCheckboxResult
= false;
558 const auto result
= KMessageBox::createKMessageBox(dialog
,
560 QMessageBox::Warning
,
561 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
563 i18n("Do not ask again"),
564 &doNotAskAgainCheckboxResult
,
565 KMessageBox::Notify
);
567 if (doNotAskAgainCheckboxResult
) {
568 GeneralSettings::setConfirmClosingMultipleTabs(false);
572 case QDialogButtonBox::Yes
:
575 case QDialogButtonBox::No
:
576 // Close only the current tab
577 m_tabWidget
->closeTab();
585 if (m_terminalPanel
&& m_terminalPanel
->hasProgramRunning() && GeneralSettings::confirmClosingTerminalRunningProgram() && closedByUser
) {
586 // Ask if the user really wants to quit Dolphin with a program that is still running in the Terminal panel
587 // Open a confirmation dialog with 3 buttons:
588 // QDialogButtonBox::Yes -> Quit
589 // QDialogButtonBox::No -> Show Terminal Panel
590 // QDialogButtonBox::Cancel -> do nothing
591 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
592 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
593 dialog
->setModal(true);
594 auto standardButtons
= QDialogButtonBox::Yes
| QDialogButtonBox::Cancel
;
595 if (!m_terminalPanel
->isVisible()) {
596 standardButtons
|= QDialogButtonBox::No
;
598 QDialogButtonBox
*buttons
= new QDialogButtonBox(standardButtons
);
599 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KStandardGuiItem::quit());
600 if (!m_terminalPanel
->isVisible()) {
602 buttons
->button(QDialogButtonBox::No
),
603 KGuiItem(i18n("Show &Terminal Panel"), QIcon::fromTheme(QStringLiteral("dialog-scripts"))));
605 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
607 bool doNotAskAgainCheckboxResult
= false;
609 const auto result
= KMessageBox::createKMessageBox(
612 QMessageBox::Warning
,
613 i18n("The program '%1' is still running in the Terminal panel. Are you sure you want to quit?", m_terminalPanel
->runningProgramName()),
615 i18n("Do not ask again"),
616 &doNotAskAgainCheckboxResult
,
617 KMessageBox::Dangerous
);
619 if (doNotAskAgainCheckboxResult
) {
620 GeneralSettings::setConfirmClosingTerminalRunningProgram(false);
624 case QDialogButtonBox::Yes
:
627 case QDialogButtonBox::No
:
628 actionCollection()->action("show_terminal_panel")->trigger();
629 // Do not quit, ignore quit event
637 if (GeneralSettings::rememberOpenedTabs()) {
638 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
639 KConfig
*config
= KConfigGui::sessionConfig();
640 saveGlobalProperties(config
);
641 savePropertiesInternal(config
, 1);
645 GeneralSettings::setVersion(CurrentDolphinVersion
);
646 GeneralSettings::self()->save();
648 KXmlGuiWindow::closeEvent(event
);
651 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
653 m_tabWidget
->saveProperties(group
);
656 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
658 m_tabWidget
->readProperties(group
);
661 void DolphinMainWindow::updateNewMenu()
663 m_newFileMenu
->checkUpToDate();
664 m_newFileMenu
->setPopupFiles(QList
<QUrl
>() << activeViewContainer()->url());
667 void DolphinMainWindow::createDirectory()
669 m_newFileMenu
->setPopupFiles(QList
<QUrl
>() << activeViewContainer()->url());
670 m_newFileMenu
->createDirectory();
673 void DolphinMainWindow::quit()
678 void DolphinMainWindow::showErrorMessage(const QString
& message
)
680 m_activeViewContainer
->showMessage(message
, DolphinViewContainer::Error
);
683 void DolphinMainWindow::slotUndoAvailable(bool available
)
685 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
687 undoAction
->setEnabled(available
);
691 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
693 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
695 undoAction
->setText(text
);
699 void DolphinMainWindow::undo()
702 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
703 KIO::FileUndoManager::self()->undo();
706 void DolphinMainWindow::cut()
708 m_activeViewContainer
->view()->cutSelectedItemsToClipboard();
711 void DolphinMainWindow::copy()
713 m_activeViewContainer
->view()->copySelectedItemsToClipboard();
716 void DolphinMainWindow::paste()
718 m_activeViewContainer
->view()->paste();
721 void DolphinMainWindow::find()
723 m_activeViewContainer
->setSearchModeEnabled(true);
726 void DolphinMainWindow::updateSearchAction()
728 QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
729 toggleSearchAction
->setChecked(m_activeViewContainer
->isSearchModeEnabled());
732 void DolphinMainWindow::updatePasteAction()
734 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
735 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
736 pasteAction
->setEnabled(pasteInfo
.first
);
737 pasteAction
->setText(pasteInfo
.second
);
740 void DolphinMainWindow::slotDirectoryLoadingCompleted()
745 void DolphinMainWindow::slotToolBarActionMiddleClicked(QAction
*action
)
747 if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Back
))) {
749 } else if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Forward
))) {
751 } else if (action
== actionCollection()->action(QStringLiteral("go_up"))) {
753 } else if (action
== actionCollection()->action(QStringLiteral("go_home"))) {
758 QAction
*DolphinMainWindow::urlNavigatorHistoryAction(const KUrlNavigator
*urlNavigator
, int historyIndex
, QObject
*parent
)
760 const QUrl url
= urlNavigator
->locationUrl(historyIndex
);
762 QString text
= url
.toDisplayString(QUrl::PreferLocalFile
);
764 if (!urlNavigator
->showFullPath()) {
765 const KFilePlacesModel
*placesModel
= DolphinPlacesModelSingleton::instance().placesModel();
767 const QModelIndex closestIdx
= placesModel
->closestItem(url
);
768 if (closestIdx
.isValid()) {
769 const QUrl placeUrl
= placesModel
->url(closestIdx
);
771 text
= placesModel
->text(closestIdx
);
773 QString pathInsidePlace
= url
.path().mid(placeUrl
.path().length());
775 if (!pathInsidePlace
.isEmpty() && !pathInsidePlace
.startsWith(QLatin1Char('/'))) {
776 pathInsidePlace
.prepend(QLatin1Char('/'));
779 if (pathInsidePlace
!= QLatin1Char('/')) {
780 text
.append(pathInsidePlace
);
785 QAction
*action
= new QAction(QIcon::fromTheme(KIO::iconNameForUrl(url
)), text
, parent
);
786 action
->setData(historyIndex
);
790 void DolphinMainWindow::slotAboutToShowBackPopupMenu()
792 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
794 m_backAction
->menu()->clear();
795 for (int i
= urlNavigator
->historyIndex() + 1; i
< urlNavigator
->historySize() && entries
< MaxNumberOfNavigationentries
; ++i
, ++entries
) {
796 QAction
*action
= urlNavigatorHistoryAction(urlNavigator
, i
, m_backAction
->menu());
798 m_backAction
->menu()->addAction(action
);
802 void DolphinMainWindow::slotGoBack(QAction
* action
)
804 int gotoIndex
= action
->data().value
<int>();
805 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
806 for (int i
= gotoIndex
- urlNavigator
->historyIndex(); i
> 0; --i
) {
811 void DolphinMainWindow::slotBackForwardActionMiddleClicked(QAction
* action
)
814 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
815 openNewTab(urlNavigator
->locationUrl(action
->data().value
<int>()));
819 void DolphinMainWindow::slotAboutToShowForwardPopupMenu()
821 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
823 m_forwardAction
->menu()->clear();
824 for (int i
= urlNavigator
->historyIndex() - 1; i
>= 0 && entries
< MaxNumberOfNavigationentries
; --i
, ++entries
) {
825 QAction
*action
= urlNavigatorHistoryAction(urlNavigator
, i
, m_forwardAction
->menu());
827 m_forwardAction
->menu()->addAction(action
);
831 void DolphinMainWindow::slotGoForward(QAction
* action
)
833 int gotoIndex
= action
->data().value
<int>();
834 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
835 for (int i
= urlNavigator
->historyIndex() - gotoIndex
; i
> 0; --i
) {
840 void DolphinMainWindow::selectAll()
844 // if the URL navigator is editable and focused, select the whole
845 // URL instead of all items of the view
847 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
848 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit();
849 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
850 lineEdit
->hasFocus();
852 lineEdit
->selectAll();
854 m_activeViewContainer
->view()->selectAll();
858 void DolphinMainWindow::invertSelection()
861 m_activeViewContainer
->view()->invertSelection();
864 void DolphinMainWindow::toggleSplitView()
866 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
867 tabPage
->setSplitViewEnabled(!tabPage
->splitViewEnabled(), WithAnimation
);
872 void DolphinMainWindow::toggleSplitStash()
874 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
875 tabPage
->setSplitViewEnabled(false, WithAnimation
);
876 tabPage
->setSplitViewEnabled(true, WithAnimation
, QUrl("stash:/"));
879 void DolphinMainWindow::reloadView()
882 m_activeViewContainer
->reload();
883 m_activeViewContainer
->statusBar()->updateSpaceInfo();
886 void DolphinMainWindow::stopLoading()
888 m_activeViewContainer
->view()->stopLoading();
891 void DolphinMainWindow::enableStopAction()
893 actionCollection()->action(QStringLiteral("stop"))->setEnabled(true);
896 void DolphinMainWindow::disableStopAction()
898 actionCollection()->action(QStringLiteral("stop"))->setEnabled(false);
901 void DolphinMainWindow::showFilterBar()
903 m_activeViewContainer
->setFilterBarVisible(true);
906 void DolphinMainWindow::toggleFilterBar()
908 const bool checked
= !m_activeViewContainer
->isFilterBarVisible();
909 m_activeViewContainer
->setFilterBarVisible(checked
);
911 QAction
* toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
912 toggleFilterBarAction
->setChecked(checked
);
915 void DolphinMainWindow::toggleEditLocation()
919 QAction
* action
= actionCollection()->action(QStringLiteral("editable_location"));
920 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
921 urlNavigator
->setUrlEditable(action
->isChecked());
924 void DolphinMainWindow::replaceLocation()
926 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
927 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit();
929 // If the text field currently has focus and everything is selected,
930 // pressing the keyboard shortcut returns the whole thing to breadcrumb mode
931 if (navigator
->isUrlEditable()
932 && lineEdit
->hasFocus()
933 && lineEdit
->selectedText() == lineEdit
->text() ) {
934 navigator
->setUrlEditable(false);
936 navigator
->setUrlEditable(true);
937 navigator
->setFocus();
938 lineEdit
->selectAll();
942 void DolphinMainWindow::togglePanelLockState()
944 const bool newLockState
= !GeneralSettings::lockPanels();
945 const auto childrenObjects
= children();
946 for (QObject
* child
: childrenObjects
) {
947 DolphinDockWidget
* dock
= qobject_cast
<DolphinDockWidget
*>(child
);
949 dock
->setLocked(newLockState
);
953 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(newLockState
);
955 GeneralSettings::setLockPanels(newLockState
);
958 void DolphinMainWindow::slotTerminalPanelVisibilityChanged()
960 if (m_terminalPanel
->isHiddenInVisibleWindow() && m_activeViewContainer
) {
961 m_activeViewContainer
->view()->setFocus();
965 void DolphinMainWindow::goBack()
967 DolphinUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
968 urlNavigator
->goBack();
970 if (urlNavigator
->locationState().isEmpty()) {
971 // An empty location state indicates a redirection URL,
972 // which must be skipped too
973 urlNavigator
->goBack();
977 void DolphinMainWindow::goForward()
979 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goForward();
982 void DolphinMainWindow::goUp()
984 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goUp();
987 void DolphinMainWindow::goHome()
989 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goHome();
992 void DolphinMainWindow::goBackInNewTab()
994 const KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
995 const int index
= urlNavigator
->historyIndex() + 1;
996 openNewTab(urlNavigator
->locationUrl(index
));
999 void DolphinMainWindow::goForwardInNewTab()
1001 const KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
1002 const int index
= urlNavigator
->historyIndex() - 1;
1003 openNewTab(urlNavigator
->locationUrl(index
));
1006 void DolphinMainWindow::goUpInNewTab()
1008 const QUrl currentUrl
= activeViewContainer()->urlNavigator()->locationUrl();
1009 openNewTab(KIO::upUrl(currentUrl
));
1012 void DolphinMainWindow::goHomeInNewTab()
1014 openNewTab(Dolphin::homeUrl());
1017 void DolphinMainWindow::compareFiles()
1019 const KFileItemList items
= m_tabWidget
->currentTabPage()->selectedItems();
1020 if (items
.count() != 2) {
1021 // The action is disabled in this case, but it could have been triggered
1022 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
1026 QUrl urlA
= items
.at(0).url();
1027 QUrl urlB
= items
.at(1).url();
1029 QString
command(QStringLiteral("kompare -c \""));
1030 command
.append(urlA
.toDisplayString(QUrl::PreferLocalFile
));
1031 command
.append("\" \"");
1032 command
.append(urlB
.toDisplayString(QUrl::PreferLocalFile
));
1033 command
.append('\"');
1035 KIO::CommandLauncherJob
*job
= new KIO::CommandLauncherJob(command
, this);
1036 job
->setDesktopName(QStringLiteral("org.kde.kompare"));
1040 void DolphinMainWindow::toggleShowMenuBar()
1042 const bool visible
= menuBar()->isVisible();
1043 menuBar()->setVisible(!visible
);
1046 QPointer
<QAction
> DolphinMainWindow::preferredSearchTool()
1048 m_searchTools
.clear();
1049 KMoreToolsMenuFactory("dolphin/search-tools").fillMenuFromGroupingNames(
1050 &m_searchTools
, { "files-find" }, m_activeViewContainer
->url()
1052 QList
<QAction
*> actions
= m_searchTools
.actions();
1053 if (actions
.isEmpty()) {
1056 QAction
* action
= actions
.first();
1057 if (action
->isSeparator()) {
1063 void DolphinMainWindow::updateOpenPreferredSearchToolAction()
1065 QAction
* openPreferredSearchTool
= actionCollection()->action(QStringLiteral("open_preferred_search_tool"));
1066 if (!openPreferredSearchTool
) {
1069 QPointer
<QAction
> tool
= preferredSearchTool();
1071 openPreferredSearchTool
->setVisible(true);
1072 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open %1", tool
->text()));
1073 // Only override with the app icon if it is the default, i.e. the user hasn't configured one manually
1074 // https://bugs.kde.org/show_bug.cgi?id=442815
1075 if (openPreferredSearchTool
->icon().name() == QLatin1String("search")) {
1076 openPreferredSearchTool
->setIcon(tool
->icon());
1079 openPreferredSearchTool
->setVisible(false);
1080 // still visible in Shortcuts configuration window
1081 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1082 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1086 void DolphinMainWindow::openPreferredSearchTool()
1088 QPointer
<QAction
> tool
= preferredSearchTool();
1094 void DolphinMainWindow::openTerminal()
1096 openTerminalJob(m_activeViewContainer
->url());
1099 void DolphinMainWindow::openTerminalHere()
1101 QList
<QUrl
> urls
= {};
1103 for (const KFileItem
& item
: m_activeViewContainer
->view()->selectedItems()) {
1104 QUrl url
= item
.targetUrl();
1105 if (item
.isFile()) {
1106 url
.setPath(QFileInfo(url
.path()).absolutePath());
1108 if (!urls
.contains(url
)) {
1113 // No items are selected. Open a terminal window for the current location.
1114 if (urls
.count() == 0) {
1119 if (urls
.count() > 5) {
1120 QString question
= i18np("Are you sure you want to open 1 terminal window?",
1121 "Are you sure you want to open %1 terminal windows?", urls
.count());
1122 const int answer
= KMessageBox::warningYesNo(this, question
);
1123 if (answer
!= KMessageBox::Yes
) {
1128 for (const QUrl
& url
: urls
) {
1129 openTerminalJob(url
);
1133 void DolphinMainWindow::openTerminalJob(const QUrl
& url
)
1135 if (url
.isLocalFile()) {
1136 auto job
= new KTerminalLauncherJob(QString());
1137 job
->setWorkingDirectory(url
.toLocalFile());
1142 // Not a local file, with protocol Class ":local", try stat'ing
1143 if (KProtocolInfo::protocolClass(url
.scheme()) == QLatin1String(":local")) {
1144 KIO::StatJob
*job
= KIO::mostLocalUrl(url
);
1145 KJobWidgets::setWindow(job
, this);
1146 connect(job
, &KJob::result
, this, [job
]() {
1148 if (!job
->error()) {
1149 statUrl
= job
->mostLocalUrl();
1152 auto job
= new KTerminalLauncherJob(QString());
1153 job
->setWorkingDirectory(statUrl
.isLocalFile() ? statUrl
.toLocalFile() : QDir::homePath());
1160 // Nothing worked, just use $HOME
1161 auto job
= new KTerminalLauncherJob(QString());
1162 job
->setWorkingDirectory(QDir::homePath());
1166 void DolphinMainWindow::editSettings()
1168 if (!m_settingsDialog
) {
1169 DolphinViewContainer
* container
= activeViewContainer();
1170 container
->view()->writeSettings();
1172 const QUrl url
= container
->url();
1173 DolphinSettingsDialog
* settingsDialog
= new DolphinSettingsDialog(url
, this, actionCollection());
1174 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, this, &DolphinMainWindow::refreshViews
);
1175 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
,
1176 &DolphinUrlNavigatorsController::slotReadSettings
);
1177 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1178 settingsDialog
->show();
1179 m_settingsDialog
= settingsDialog
;
1181 m_settingsDialog
.data()->raise();
1185 void DolphinMainWindow::handleUrl(const QUrl
& url
)
1187 delete m_lastHandleUrlOpenJob
;
1188 m_lastHandleUrlOpenJob
= nullptr;
1190 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1191 activeViewContainer()->setUrl(url
);
1193 m_lastHandleUrlOpenJob
= new KIO::OpenUrlJob(url
);
1194 m_lastHandleUrlOpenJob
->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
1195 m_lastHandleUrlOpenJob
->setShowOpenOrExecuteDialog(true);
1197 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::mimeTypeFound
, this,
1198 [this, url
](const QString
&mimetype
) {
1199 if (mimetype
== QLatin1String("inode/directory")) {
1200 // If it's a dir, we'll take it from here
1201 m_lastHandleUrlOpenJob
->kill();
1202 m_lastHandleUrlOpenJob
= nullptr;
1203 activeViewContainer()->setUrl(url
);
1207 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::result
, this, [this]() {
1208 m_lastHandleUrlOpenJob
= nullptr;
1211 m_lastHandleUrlOpenJob
->start();
1215 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1217 // trash:/ is writable but we don't want to create new items in it.
1218 // TODO: remove the trash check once https://phabricator.kde.org/T8234 is implemented
1219 newFileMenu()->setEnabled(isFolderWritable
&& m_activeViewContainer
->url().scheme() != QLatin1String("trash"));
1222 void DolphinMainWindow::openContextMenu(const QPoint
& pos
,
1223 const KFileItem
& item
,
1224 const KFileItemList
&selectedItems
,
1227 QPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, item
, selectedItems
, url
, &m_fileItemActions
);
1228 contextMenu
.data()->exec(pos
);
1230 // Delete the menu, unless it has been deleted in its own nested event loop already.
1232 contextMenu
->deleteLater();
1236 QMenu
*DolphinMainWindow::createPopupMenu()
1238 QMenu
*menu
= KXmlGuiWindow::createPopupMenu();
1240 menu
->addSeparator();
1241 menu
->addAction(actionCollection()->action(QStringLiteral("lock_panels")));
1246 void DolphinMainWindow::updateHamburgerMenu()
1248 KActionCollection
* ac
= actionCollection();
1249 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(
1250 ac
->action(KStandardAction::name(KStandardAction::HamburgerMenu
)));
1251 auto menu
= hamburgerMenu
->menu();
1253 menu
= new QMenu(this);
1254 hamburgerMenu
->setMenu(menu
);
1255 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("basic_actions"))->menu());
1256 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("zoom"))->menu());
1260 const QList
<QAction
*> toolbarActions
= toolBar()->actions();
1262 if (!toolBar()->isVisible()) {
1263 // If neither the menu bar nor the toolbar are visible, these actions should be available.
1264 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)));
1265 menu
->addAction(toolBarMenuAction());
1266 menu
->addSeparator();
1269 // This group of actions (until the next separator) contains all the most basic actions
1270 // necessary to use Dolphin effectively.
1271 menu
->addAction(ac
->action(QStringLiteral("go_back")));
1272 menu
->addAction(ac
->action(QStringLiteral("go_forward")));
1274 menu
->addMenu(m_newFileMenu
->menu());
1275 menu
->addAction(ac
->action(QStringLiteral("basic_actions")));
1276 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Undo
)));
1277 if (!toolBar()->isVisible()
1278 || (!toolbarActions
.contains(ac
->action(QStringLiteral("toggle_search")))
1279 && !toolbarActions
.contains(ac
->action(QStringLiteral("open_preferred_search_tool"))))
1281 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Find
)));
1282 // This way a search action will only be added if none of the three available
1283 // search actions is present on the toolbar.
1285 if (!toolBar()->isVisible()
1286 || !toolbarActions
.contains(ac
->action(QStringLiteral("toggle_filter")))
1288 menu
->addAction(ac
->action(QStringLiteral("show_filter_bar")));
1289 // This way a filter action will only be added if none of the two available
1290 // filter actions is present on the toolbar.
1292 menu
->addSeparator();
1294 // The second group of actions (up until the next separator) contains actions for opening
1295 // additional views to interact with the file system.
1296 menu
->addAction(ac
->action(QStringLiteral("file_new")));
1297 menu
->addAction(ac
->action(QStringLiteral("new_tab")));
1298 if (ac
->action(QStringLiteral("undo_close_tab"))->isEnabled()) {
1299 menu
->addAction(ac
->action(QStringLiteral("closed_tabs")));
1301 menu
->addAction(ac
->action(QStringLiteral("open_terminal")));
1302 menu
->addSeparator();
1304 // The third group contains actions to change what one sees in the view
1305 // and to change the more general UI.
1306 if (!toolBar()->isVisible()
1307 || (!toolbarActions
.contains(ac
->action(QStringLiteral("icons")))
1308 && !toolbarActions
.contains(ac
->action(QStringLiteral("compact")))
1309 && !toolbarActions
.contains(ac
->action(QStringLiteral("details")))
1310 && !toolbarActions
.contains(ac
->action(QStringLiteral("view_mode"))))
1312 menu
->addAction(ac
->action(QStringLiteral("view_mode")));
1314 menu
->addAction(ac
->action(QStringLiteral("show_hidden_files")));
1315 menu
->addAction(ac
->action(QStringLiteral("sort")));
1316 menu
->addAction(ac
->action(QStringLiteral("additional_info")));
1317 if (!GeneralSettings::showStatusBar() || !GeneralSettings::showZoomSlider()) {
1318 menu
->addAction(ac
->action(QStringLiteral("zoom")));
1320 menu
->addAction(ac
->action(QStringLiteral("panels")));
1322 // The "Configure" menu is not added to the actionCollection() because there is hardly
1323 // a good reason for users to put it on their toolbar.
1324 auto configureMenu
= menu
->addMenu(QIcon::fromTheme(QStringLiteral("configure")),
1325 i18nc("@action:inmenu menu for configure actions", "Configure"));
1326 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
)));
1327 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)));
1328 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)));
1329 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Preferences
)));
1330 hamburgerMenu
->hideActionsOf(configureMenu
);
1333 void DolphinMainWindow::slotPlaceActivated(const QUrl
& url
)
1335 DolphinViewContainer
* view
= activeViewContainer();
1337 if (view
->url() == url
) {
1338 // We can end up here if the user clicked a device in the Places Panel
1339 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1342 view
->disableUrlNavigatorSelectionRequests();
1344 view
->enableUrlNavigatorSelectionRequests();
1348 void DolphinMainWindow::closedTabsCountChanged(unsigned int count
)
1350 actionCollection()->action(QStringLiteral("undo_close_tab"))->setEnabled(count
> 0);
1353 void DolphinMainWindow::activeViewChanged(DolphinViewContainer
* viewContainer
)
1355 DolphinViewContainer
* oldViewContainer
= m_activeViewContainer
;
1356 Q_ASSERT(viewContainer
);
1358 m_activeViewContainer
= viewContainer
;
1360 if (oldViewContainer
) {
1361 const QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
1362 toggleSearchAction
->disconnect(oldViewContainer
);
1364 // Disconnect all signals between the old view container (container,
1365 // view and url navigator) and main window.
1366 oldViewContainer
->disconnect(this);
1367 oldViewContainer
->view()->disconnect(this);
1368 oldViewContainer
->urlNavigatorInternalWithHistory()->disconnect(this);
1369 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
1370 (actionCollection()->action(QStringLiteral("url_navigators")));
1371 navigators
->primaryUrlNavigator()->disconnect(this);
1372 if (auto secondaryUrlNavigator
= navigators
->secondaryUrlNavigator()) {
1373 secondaryUrlNavigator
->disconnect(this);
1376 // except the requestItemInfo so that on hover the information panel can still be updated
1377 connect(oldViewContainer
->view(), &DolphinView::requestItemInfo
,
1378 this, &DolphinMainWindow::requestItemInfo
);
1381 connectViewSignals(viewContainer
);
1383 m_actionHandler
->setCurrentView(viewContainer
->view());
1386 updateFileAndEditActions();
1387 updatePasteAction();
1388 updateViewActions();
1390 updateSearchAction();
1392 const QUrl url
= viewContainer
->url();
1393 Q_EMIT
urlChanged(url
);
1396 void DolphinMainWindow::tabCountChanged(int count
)
1398 const bool enableTabActions
= (count
> 1);
1399 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1400 actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i
))->setEnabled(enableTabActions
);
1402 actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions
);
1403 actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions
);
1404 actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions
);
1407 void DolphinMainWindow::updateWindowTitle()
1409 const QString newTitle
= m_activeViewContainer
->captionWindowTitle();
1410 if (windowTitle() != newTitle
) {
1411 setWindowTitle(newTitle
);
1415 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString
& mountPath
)
1417 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1418 setViewsToHomeIfMountPathOpen(mountPath
);
1421 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectory().startsWith(mountPath
)) {
1422 m_tearDownFromPlacesRequested
= true;
1423 m_terminalPanel
->goHome();
1424 // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
1426 m_placesPanel
->proceedWithTearDown();
1430 void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString
& mountPath
)
1432 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1433 setViewsToHomeIfMountPathOpen(mountPath
);
1436 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectory().startsWith(mountPath
)) {
1437 m_tearDownFromPlacesRequested
= false;
1438 m_terminalPanel
->goHome();
1442 void DolphinMainWindow::slotKeyBindings()
1444 KShortcutsDialog
dialog(KShortcutsEditor::AllActions
, KShortcutsEditor::LetterShortcutsAllowed
, this);
1445 dialog
.addCollection(actionCollection());
1446 if (m_terminalPanel
) {
1447 KActionCollection
*konsolePartActionCollection
= m_terminalPanel
->actionCollection();
1448 if (konsolePartActionCollection
) {
1449 dialog
.addCollection(konsolePartActionCollection
, QStringLiteral("KonsolePart"));
1455 void DolphinMainWindow::setViewsToHomeIfMountPathOpen(const QString
& mountPath
)
1457 const QVector
<DolphinViewContainer
*> theViewContainers
= viewContainers();
1458 for (DolphinViewContainer
*viewContainer
: theViewContainers
) {
1459 if (viewContainer
&& viewContainer
->url().toLocalFile().startsWith(mountPath
)) {
1460 viewContainer
->setUrl(QUrl::fromLocalFile(QDir::homePath()));
1463 disconnect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, nullptr, nullptr);
1466 void DolphinMainWindow::setupActions()
1468 KStandardAction::hamburgerMenu(nullptr, nullptr, actionCollection());
1470 // setup 'File' menu
1471 m_newFileMenu
= new DolphinNewFileMenu(actionCollection(), this);
1472 QMenu
* menu
= m_newFileMenu
->menu();
1473 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1474 menu
->setIcon(QIcon::fromTheme(QStringLiteral("list-add")));
1475 m_newFileMenu
->setPopupMode(QToolButton::InstantPopup
);
1476 connect(menu
, &QMenu::aboutToShow
,
1477 this, &DolphinMainWindow::updateNewMenu
);
1479 QAction
* newWindow
= KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow
, actionCollection());
1480 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1481 newWindow
->setToolTip(i18nc("@info", "Open a new Dolphin window"));
1482 newWindow
->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1483 "window just like this one with the current location and view."
1484 "<nl/>You can drag and drop items between windows."));
1485 newWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1487 QAction
* newTab
= actionCollection()->addAction(QStringLiteral("new_tab"));
1488 newTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1489 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1490 newTab
->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1491 "<emphasis>Tab</emphasis> with the current location and view.<nl/>"
1492 "A tab is an additional view within this window. "
1493 "You can drag and drop items between tabs."));
1494 actionCollection()->setDefaultShortcuts(newTab
, {Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
});
1495 connect(newTab
, &QAction::triggered
, this, &DolphinMainWindow::openNewActivatedTab
);
1497 QAction
* addToPlaces
= actionCollection()->addAction(QStringLiteral("add_to_places"));
1498 addToPlaces
->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new")));
1499 addToPlaces
->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places"));
1500 addToPlaces
->setWhatsThis(xi18nc("@info:whatsthis", "This adds the selected folder "
1501 "to the Places panel."));
1502 connect(addToPlaces
, &QAction::triggered
, this, &DolphinMainWindow::addToPlaces
);
1504 QAction
* closeTab
= KStandardAction::close(m_tabWidget
, QOverload
<>::of(&DolphinTabWidget::closeTab
), actionCollection());
1505 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1506 closeTab
->setWhatsThis(i18nc("@info:whatsthis", "This closes the "
1507 "currently viewed tab. If no more tabs are left this window "
1508 "will close instead."));
1510 QAction
* quitAction
= KStandardAction::quit(this, &DolphinMainWindow::quit
, actionCollection());
1511 quitAction
->setWhatsThis(i18nc("@info:whatsthis quit", "This closes this window."));
1513 // setup 'Edit' menu
1514 KStandardAction::undo(this,
1515 &DolphinMainWindow::undo
,
1516 actionCollection());
1518 // i18n: This will be the last paragraph for the whatsthis for all three:
1519 // Cut, Copy and Paste
1520 const QString cutCopyPastePara
= xi18nc("@info:whatsthis", "<para><emphasis>Cut, "
1521 "Copy</emphasis> and <emphasis>Paste</emphasis> work between many "
1522 "applications and are among the most used commands. That's why their "
1523 "<emphasis>keyboard shortcuts</emphasis> are prominently placed right "
1524 "next to each other on the keyboard: <shortcut>Ctrl+X</shortcut>, "
1525 "<shortcut>Ctrl+C</shortcut> and <shortcut>Ctrl+V</shortcut>.</para>");
1526 QAction
* cutAction
= KStandardAction::cut(this, &DolphinMainWindow::cut
, actionCollection());
1527 cutAction
->setWhatsThis(xi18nc("@info:whatsthis cut", "This copies the items "
1528 "in your current selection to the <emphasis>clipboard</emphasis>.<nl/>"
1529 "Use the <emphasis>Paste</emphasis> action afterwards to copy them from "
1530 "the clipboard to a new location. The items will be removed from their "
1531 "initial location.") + cutCopyPastePara
);
1532 QAction
* copyAction
= KStandardAction::copy(this, &DolphinMainWindow::copy
, actionCollection());
1533 copyAction
->setWhatsThis(xi18nc("@info:whatsthis copy", "This copies the "
1534 "items in your current selection to the <emphasis>clipboard</emphasis>."
1535 "<nl/>Use the <emphasis>Paste</emphasis> action afterwards to copy them "
1536 "from the clipboard to a new location.") + cutCopyPastePara
);
1537 QAction
* paste
= KStandardAction::paste(this, &DolphinMainWindow::paste
, actionCollection());
1538 // The text of the paste-action is modified dynamically by Dolphin
1539 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1540 // due to the long text, the text "Paste" is used:
1541 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1542 paste
->setWhatsThis(xi18nc("@info:whatsthis paste", "This copies the items from "
1543 "your <emphasis>clipboard</emphasis> to the currently viewed folder.<nl/>"
1544 "If the items were added to the clipboard by the <emphasis>Cut</emphasis> "
1545 "action they are removed from their old location.") + cutCopyPastePara
);
1547 QAction
* copyToOtherViewAction
= actionCollection()->addAction(QStringLiteral("copy_to_inactive_split_view"));
1548 copyToOtherViewAction
->setText(i18nc("@action:inmenu", "Copy to Inactive Split View"));
1549 copyToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Copy", "This copies the selected items from "
1550 "the <emphasis>active</emphasis> view to the inactive split view."));
1551 copyToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
1552 copyToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Copy to Inactive Split View"));
1553 actionCollection()->setDefaultShortcut(copyToOtherViewAction
, Qt::SHIFT
| Qt::Key_F5
);
1554 connect(copyToOtherViewAction
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::copyToInactiveSplitView
);
1556 QAction
* moveToOtherViewAction
= actionCollection()->addAction(QStringLiteral("move_to_inactive_split_view"));
1557 moveToOtherViewAction
->setText(i18nc("@action:inmenu", "Move to Inactive Split View"));
1558 moveToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Move", "This moves the selected items from "
1559 "the <emphasis>active</emphasis> view to the inactive split view."));
1560 moveToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-cut")));
1561 moveToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Move to Inactive Split View"));
1562 actionCollection()->setDefaultShortcut(moveToOtherViewAction
, Qt::SHIFT
| Qt::Key_F6
);
1563 connect(moveToOtherViewAction
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::moveToInactiveSplitView
);
1565 QAction
* showFilterBar
= actionCollection()->addAction(QStringLiteral("show_filter_bar"));
1566 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Filter..."));
1567 showFilterBar
->setToolTip(i18nc("@info:tooltip", "Show Filter Bar"));
1568 showFilterBar
->setWhatsThis(xi18nc("@info:whatsthis", "This opens the "
1569 "<emphasis>Filter Bar</emphasis> at the bottom of the window.<nl/> "
1570 "There you can enter a text to filter the files and folders currently displayed. "
1571 "Only those that contain the text in their name will be kept in view."));
1572 showFilterBar
->setIcon(QIcon::fromTheme(QStringLiteral("view-filter")));
1573 actionCollection()->setDefaultShortcuts(showFilterBar
, {Qt::CTRL
| Qt::Key_I
, Qt::Key_Slash
});
1574 connect(showFilterBar
, &QAction::triggered
, this, &DolphinMainWindow::showFilterBar
);
1576 // toggle_filter acts as a copy of the main showFilterBar to be used mainly
1577 // in the toolbar, with no default shortcut attached, to avoid messing with
1578 // existing workflows (filter bar always open and Ctrl-I to focus)
1579 QAction
*toggleFilter
= actionCollection()->addAction(QStringLiteral("toggle_filter"));
1580 toggleFilter
->setText(i18nc("@action:inmenu", "Toggle Filter Bar"));
1581 toggleFilter
->setIconText(i18nc("@action:intoolbar", "Filter"));
1582 toggleFilter
->setIcon(showFilterBar
->icon());
1583 toggleFilter
->setToolTip(showFilterBar
->toolTip());
1584 toggleFilter
->setWhatsThis(showFilterBar
->whatsThis());
1585 toggleFilter
->setCheckable(true);
1586 connect(toggleFilter
, &QAction::triggered
, this, &DolphinMainWindow::toggleFilterBar
);
1588 QAction
*searchAction
= KStandardAction::find(this, &DolphinMainWindow::find
, actionCollection());
1589 searchAction
->setText(i18n("Search..."));
1590 searchAction
->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
1591 searchAction
->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This helps you "
1592 "find files and folders by opening a <emphasis>find bar</emphasis>. "
1593 "There you can enter search terms and specify settings to find the "
1594 "objects you are looking for.</para><para>Use this help again on "
1595 "the find bar so we can have a look at it while the settings are "
1596 "explained.</para>"));
1598 // toggle_search acts as a copy of the main searchAction to be used mainly
1599 // in the toolbar, with no default shortcut attached, to avoid messing with
1600 // existing workflows (search bar always open and Ctrl-F to focus)
1601 QAction
*toggleSearchAction
= actionCollection()->addAction(QStringLiteral("toggle_search"));
1602 toggleSearchAction
->setText(i18nc("@action:inmenu", "Toggle Search Bar"));
1603 toggleSearchAction
->setIconText(i18nc("@action:intoolbar", "Search"));
1604 toggleSearchAction
->setIcon(searchAction
->icon());
1605 toggleSearchAction
->setToolTip(searchAction
->toolTip());
1606 toggleSearchAction
->setWhatsThis(searchAction
->whatsThis());
1607 toggleSearchAction
->setCheckable(true);
1609 QAction
* selectAllAction
= KStandardAction::selectAll(this, &DolphinMainWindow::selectAll
, actionCollection());
1610 selectAllAction
->setWhatsThis(xi18nc("@info:whatsthis", "This selects all "
1611 "files and folders in the current location."));
1613 QAction
* invertSelection
= actionCollection()->addAction(QStringLiteral("invert_selection"));
1614 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1615 invertSelection
->setWhatsThis(xi18nc("@info:whatsthis invert", "This selects all "
1616 "objects that you have currently <emphasis>not</emphasis> selected instead."));
1617 invertSelection
->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert")));
1618 actionCollection()->setDefaultShortcut(invertSelection
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1619 connect(invertSelection
, &QAction::triggered
, this, &DolphinMainWindow::invertSelection
);
1621 // setup 'View' menu
1622 // (note that most of it is set up in DolphinViewActionHandler)
1624 QAction
* split
= actionCollection()->addAction(QStringLiteral("split_view"));
1625 split
->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This splits "
1626 "the folder view below into two autonomous views.</para><para>This "
1627 "way you can see two locations at once and move items between them "
1628 "quickly.</para>Click this again afterwards to recombine the views."));
1629 actionCollection()->setDefaultShortcut(split
, Qt::Key_F3
);
1630 connect(split
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitView
);
1632 QAction
* stashSplit
= actionCollection()->addAction(QStringLiteral("split_stash"));
1633 actionCollection()->setDefaultShortcut(stashSplit
, Qt::CTRL
| Qt::Key_S
);
1634 stashSplit
->setText(i18nc("@action:intoolbar Stash", "Stash"));
1635 stashSplit
->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
1636 stashSplit
->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
1637 stashSplit
->setCheckable(false);
1638 QDBusConnectionInterface
*sessionInterface
= QDBusConnection::sessionBus().interface();
1639 stashSplit
->setVisible(sessionInterface
&& sessionInterface
->isServiceRegistered(QStringLiteral("org.kde.kio.StashNotifier")));
1640 connect(stashSplit
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitStash
);
1642 KStandardAction::redisplay(this, &DolphinMainWindow::reloadView
, actionCollection());
1644 QAction
* stop
= actionCollection()->addAction(QStringLiteral("stop"));
1645 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1646 stop
->setToolTip(i18nc("@info", "Stop loading"));
1647 stop
->setWhatsThis(i18nc("@info", "This stops the loading of the contents of the current folder."));
1648 stop
->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
1649 connect(stop
, &QAction::triggered
, this, &DolphinMainWindow::stopLoading
);
1651 KToggleAction
* editableLocation
= actionCollection()->add
<KToggleAction
>(QStringLiteral("editable_location"));
1652 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1653 editableLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1654 "This toggles the <emphasis>Location Bar</emphasis> to be "
1655 "editable so you can directly enter a location you want to go to.<nl/>"
1656 "You can also switch to editing by clicking to the right of the "
1657 "location and switch back by confirming the edited location."));
1658 actionCollection()->setDefaultShortcut(editableLocation
, Qt::Key_F6
);
1659 connect(editableLocation
, &KToggleAction::triggered
, this, &DolphinMainWindow::toggleEditLocation
);
1661 QAction
* replaceLocation
= actionCollection()->addAction(QStringLiteral("replace_location"));
1662 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1663 // i18n: "enter" is used both in the meaning of "writing" and "going to" a new location here.
1664 // Both meanings are useful but not necessary to understand the use of "Replace Location".
1665 // So you might want to be more verbose in your language to convey the meaning but it's up to you.
1666 replaceLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1667 "This switches to editing the location and selects it "
1668 "so you can quickly enter a different location."));
1669 actionCollection()->setDefaultShortcut(replaceLocation
, Qt::CTRL
| Qt::Key_L
);
1670 connect(replaceLocation
, &QAction::triggered
, this, &DolphinMainWindow::replaceLocation
);
1674 QScopedPointer
<QAction
> backAction(KStandardAction::back(nullptr, nullptr, nullptr));
1675 m_backAction
= new KToolBarPopupAction(backAction
->icon(), backAction
->text(), actionCollection());
1676 m_backAction
->setObjectName(backAction
->objectName());
1677 m_backAction
->setShortcuts(backAction
->shortcuts());
1679 m_backAction
->setPopupMode(QToolButton::DelayedPopup
);
1680 connect(m_backAction
, &QAction::triggered
, this, &DolphinMainWindow::goBack
);
1681 connect(m_backAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowBackPopupMenu
);
1682 connect(m_backAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoBack
);
1683 actionCollection()->addAction(m_backAction
->objectName(), m_backAction
);
1685 auto backShortcuts
= m_backAction
->shortcuts();
1686 backShortcuts
.append(QKeySequence(Qt::Key_Backspace
));
1687 actionCollection()->setDefaultShortcuts(m_backAction
, backShortcuts
);
1689 DolphinRecentTabsMenu
* recentTabsMenu
= new DolphinRecentTabsMenu(this);
1690 actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu
);
1691 connect(m_tabWidget
, &DolphinTabWidget::rememberClosedTab
,
1692 recentTabsMenu
, &DolphinRecentTabsMenu::rememberClosedTab
);
1693 connect(recentTabsMenu
, &DolphinRecentTabsMenu::restoreClosedTab
,
1694 m_tabWidget
, &DolphinTabWidget::restoreClosedTab
);
1695 connect(recentTabsMenu
, &DolphinRecentTabsMenu::closedTabsCountChanged
,
1696 this, &DolphinMainWindow::closedTabsCountChanged
);
1698 QAction
* undoCloseTab
= actionCollection()->addAction(QStringLiteral("undo_close_tab"));
1699 undoCloseTab
->setText(i18nc("@action:inmenu File", "Undo close tab"));
1700 undoCloseTab
->setWhatsThis(i18nc("@info:whatsthis undo close tab",
1701 "This returns you to the previously closed tab."));
1702 actionCollection()->setDefaultShortcut(undoCloseTab
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_T
);
1703 undoCloseTab
->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
1704 undoCloseTab
->setEnabled(false);
1705 connect(undoCloseTab
, &QAction::triggered
, recentTabsMenu
, &DolphinRecentTabsMenu::undoCloseTab
);
1707 auto undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
1708 undoAction
->setWhatsThis(xi18nc("@info:whatsthis", "This undoes "
1709 "the last change you made to files or folders.<nl/>"
1710 "Such changes include <interface>creating, renaming</interface> "
1711 "and <interface>moving</interface> them to a different location "
1712 "or to the <filename>Trash</filename>. <nl/>Changes that can't "
1713 "be undone will ask for your confirmation."));
1714 undoAction
->setEnabled(false); // undo should be disabled by default
1717 QScopedPointer
<QAction
> forwardAction(KStandardAction::forward(nullptr, nullptr, nullptr));
1718 m_forwardAction
= new KToolBarPopupAction(forwardAction
->icon(), forwardAction
->text(), actionCollection());
1719 m_forwardAction
->setObjectName(forwardAction
->objectName());
1720 m_forwardAction
->setShortcuts(forwardAction
->shortcuts());
1722 m_forwardAction
->setPopupMode(QToolButton::DelayedPopup
);
1723 connect(m_forwardAction
, &QAction::triggered
, this, &DolphinMainWindow::goForward
);
1724 connect(m_forwardAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowForwardPopupMenu
);
1725 connect(m_forwardAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoForward
);
1726 actionCollection()->addAction(m_forwardAction
->objectName(), m_forwardAction
);
1727 actionCollection()->setDefaultShortcuts(m_forwardAction
, m_forwardAction
->shortcuts());
1729 // enable middle-click to open in a new tab
1730 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
1731 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotBackForwardActionMiddleClicked
);
1732 m_backAction
->menu()->installEventFilter(middleClickEventFilter
);
1733 m_forwardAction
->menu()->installEventFilter(middleClickEventFilter
);
1734 KStandardAction::up(this, &DolphinMainWindow::goUp
, actionCollection());
1735 QAction
* homeAction
= KStandardAction::home(this, &DolphinMainWindow::goHome
, actionCollection());
1736 homeAction
->setWhatsThis(xi18nc("@info:whatsthis", "Go to your "
1737 "<filename>Home</filename> folder.<nl/>Every user account "
1738 "has their own <filename>Home</filename> that contains their data "
1739 "including folders that contain personal application data."));
1741 // setup 'Tools' menu
1742 QAction
* compareFiles
= actionCollection()->addAction(QStringLiteral("compare_files"));
1743 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1744 compareFiles
->setIcon(QIcon::fromTheme(QStringLiteral("kompare")));
1745 compareFiles
->setEnabled(false);
1746 connect(compareFiles
, &QAction::triggered
, this, &DolphinMainWindow::compareFiles
);
1748 QAction
* openPreferredSearchTool
= actionCollection()->addAction(QStringLiteral("open_preferred_search_tool"));
1749 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1750 openPreferredSearchTool
->setWhatsThis(xi18nc("@info:whatsthis",
1751 "<para>This opens a preferred search tool for the viewed location.</para>"
1752 "<para>Use <emphasis>More Search Tools</emphasis> menu to configure it.</para>"));
1753 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1754 actionCollection()->setDefaultShortcut(openPreferredSearchTool
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F
);
1755 connect(openPreferredSearchTool
, &QAction::triggered
, this, &DolphinMainWindow::openPreferredSearchTool
);
1757 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1758 QAction
* openTerminal
= actionCollection()->addAction(QStringLiteral("open_terminal"));
1759 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1760 openTerminal
->setWhatsThis(xi18nc("@info:whatsthis",
1761 "<para>This opens a <emphasis>terminal</emphasis> application for the viewed location.</para>"
1762 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1763 openTerminal
->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
1764 actionCollection()->setDefaultShortcut(openTerminal
, Qt::SHIFT
| Qt::Key_F4
);
1765 connect(openTerminal
, &QAction::triggered
, this, &DolphinMainWindow::openTerminal
);
1767 QAction
* openTerminalHere
= actionCollection()->addAction(QStringLiteral("open_terminal_here"));
1768 // i18n: "Here" refers to the location(s) of the currently selected item(s) or the currently viewed location if nothing is selected.
1769 openTerminalHere
->setText(i18nc("@action:inmenu Tools", "Open Terminal Here"));
1770 openTerminalHere
->setWhatsThis(xi18nc("@info:whatsthis",
1771 "<para>This opens <emphasis>terminal</emphasis> applications for the selected items' locations.</para>"
1772 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1773 openTerminalHere
->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
1774 actionCollection()->setDefaultShortcut(openTerminalHere
, Qt::SHIFT
| Qt::ALT
| Qt::Key_F4
);
1775 connect(openTerminalHere
, &QAction::triggered
, this, &DolphinMainWindow::openTerminalHere
);
1778 QAction
* focusTerminalPanel
= actionCollection()->addAction(QStringLiteral("focus_terminal_panel"));
1779 focusTerminalPanel
->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
1780 focusTerminalPanel
->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
1781 actionCollection()->setDefaultShortcut(focusTerminalPanel
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F4
);
1782 connect(focusTerminalPanel
, &QAction::triggered
, this, &DolphinMainWindow::focusTerminalPanel
);
1786 // setup 'Bookmarks' menu
1787 KActionMenu
*bookmarkMenu
= new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this);
1788 bookmarkMenu
->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks")));
1789 // Make the toolbar button version work properly on click
1790 bookmarkMenu
->setPopupMode(QToolButton::InstantPopup
);
1791 m_bookmarkHandler
= new DolphinBookmarkHandler(this, actionCollection(), bookmarkMenu
->menu(), this);
1792 actionCollection()->addAction(QStringLiteral("bookmarks"), bookmarkMenu
);
1794 // setup 'Settings' menu
1795 KToggleAction
* showMenuBar
= KStandardAction::showMenubar(nullptr, nullptr, actionCollection());
1796 showMenuBar
->setWhatsThis(xi18nc("@info:whatsthis",
1797 "This switches between having a <emphasis>Menubar</emphasis> "
1798 "and having a <interface>Control</interface> button. Both "
1799 "contain mostly the same commands and configuration options."));
1800 connect(showMenuBar
, &KToggleAction::triggered
, // Fixes #286822
1801 this, &DolphinMainWindow::toggleShowMenuBar
, Qt::QueuedConnection
);
1802 KStandardAction::keyBindings(this, &DolphinMainWindow::slotKeyBindings
, actionCollection());
1803 KStandardAction::preferences(this, &DolphinMainWindow::editSettings
, actionCollection());
1805 // setup 'Help' menu for the m_controlButton. The other one is set up in the base class.
1806 m_helpMenu
= new KHelpMenu(nullptr);
1807 m_helpMenu
->menu()->installEventFilter(this);
1808 // remove duplicate shortcuts
1809 auto removeHelpActionShortcut
= [this](KHelpMenu::MenuId menuId
) {
1810 if (auto *action
= m_helpMenu
->action(menuId
)) {
1811 action
->setShortcut(QKeySequence());
1814 removeHelpActionShortcut(KHelpMenu::menuHelpContents
);
1815 removeHelpActionShortcut(KHelpMenu::menuWhatsThis
);
1817 // not in menu actions
1818 QList
<QKeySequence
> nextTabKeys
= KStandardShortcut::tabNext();
1819 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
1821 QList
<QKeySequence
> prevTabKeys
= KStandardShortcut::tabPrev();
1822 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
1824 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1825 QAction
* activateTab
= actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i
));
1826 activateTab
->setText(i18nc("@action:inmenu", "Activate Tab %1", i
+ 1));
1827 activateTab
->setEnabled(false);
1828 connect(activateTab
, &QAction::triggered
, this, [this, i
]() { m_tabWidget
->activateTab(i
); });
1830 // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts
1832 actionCollection()->setDefaultShortcut(activateTab
, QStringLiteral("Alt+%1").arg(i
+ 1));
1836 QAction
* activateLastTab
= actionCollection()->addAction(QStringLiteral("activate_last_tab"));
1837 activateLastTab
->setText(i18nc("@action:inmenu", "Activate Last Tab"));
1838 activateLastTab
->setEnabled(false);
1839 connect(activateLastTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateLastTab
);
1840 actionCollection()->setDefaultShortcut(activateLastTab
, Qt::ALT
| Qt::Key_0
);
1842 QAction
* activateNextTab
= actionCollection()->addAction(QStringLiteral("activate_next_tab"));
1843 activateNextTab
->setIconText(i18nc("@action:inmenu", "Next Tab"));
1844 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1845 activateNextTab
->setEnabled(false);
1846 connect(activateNextTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateNextTab
);
1847 actionCollection()->setDefaultShortcuts(activateNextTab
, nextTabKeys
);
1849 QAction
* activatePrevTab
= actionCollection()->addAction(QStringLiteral("activate_prev_tab"));
1850 activatePrevTab
->setIconText(i18nc("@action:inmenu", "Previous Tab"));
1851 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1852 activatePrevTab
->setEnabled(false);
1853 connect(activatePrevTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activatePrevTab
);
1854 actionCollection()->setDefaultShortcuts(activatePrevTab
, prevTabKeys
);
1857 QAction
* showTarget
= actionCollection()->addAction(QStringLiteral("show_target"));
1858 showTarget
->setText(i18nc("@action:inmenu", "Show Target"));
1859 showTarget
->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
1860 showTarget
->setEnabled(false);
1861 connect(showTarget
, &QAction::triggered
, this, &DolphinMainWindow::showTarget
);
1863 QAction
* openInNewTab
= actionCollection()->addAction(QStringLiteral("open_in_new_tab"));
1864 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1865 openInNewTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1866 connect(openInNewTab
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
1868 QAction
* openInNewTabs
= actionCollection()->addAction(QStringLiteral("open_in_new_tabs"));
1869 openInNewTabs
->setText(i18nc("@action:inmenu", "Open in New Tabs"));
1870 openInNewTabs
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1871 connect(openInNewTabs
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
1873 QAction
* openInNewWindow
= actionCollection()->addAction(QStringLiteral("open_in_new_window"));
1874 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1875 openInNewWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1876 connect(openInNewWindow
, &QAction::triggered
, this, &DolphinMainWindow::openInNewWindow
);
1879 void DolphinMainWindow::setupDockWidgets()
1881 const bool lock
= GeneralSettings::lockPanels();
1883 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(lock
);
1885 KDualAction
* lockLayoutAction
= actionCollection()->add
<KDualAction
>(QStringLiteral("lock_panels"));
1886 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1887 lockLayoutAction
->setActiveIcon(QIcon::fromTheme(QStringLiteral("object-unlocked")));
1888 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1889 lockLayoutAction
->setInactiveIcon(QIcon::fromTheme(QStringLiteral("object-locked")));
1890 lockLayoutAction
->setWhatsThis(xi18nc("@info:whatsthis", "This "
1891 "switches between having panels <emphasis>locked</emphasis> or "
1892 "<emphasis>unlocked</emphasis>.<nl/>Unlocked panels can be "
1893 "dragged to the other side of the window and have a close "
1894 "button.<nl/>Locked panels are embedded more cleanly."));
1895 lockLayoutAction
->setActive(lock
);
1896 connect(lockLayoutAction
, &KDualAction::triggered
, this, &DolphinMainWindow::togglePanelLockState
);
1898 // Setup "Information"
1899 DolphinDockWidget
* infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
1900 infoDock
->setLocked(lock
);
1901 infoDock
->setObjectName(QStringLiteral("infoDock"));
1902 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1905 InformationPanel
* infoPanel
= new InformationPanel(infoDock
);
1906 infoPanel
->setCustomContextMenuActions({lockLayoutAction
});
1907 connect(infoPanel
, &InformationPanel::urlActivated
, this, &DolphinMainWindow::handleUrl
);
1908 infoDock
->setWidget(infoPanel
);
1910 QAction
* infoAction
= infoDock
->toggleViewAction();
1911 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-information")), Qt::Key_F11
, infoAction
, QStringLiteral("show_information_panel"));
1913 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1914 connect(this, &DolphinMainWindow::urlChanged
,
1915 infoPanel
, &InformationPanel::setUrl
);
1916 connect(this, &DolphinMainWindow::selectionChanged
,
1917 infoPanel
, &InformationPanel::setSelection
);
1918 connect(this, &DolphinMainWindow::requestItemInfo
,
1919 infoPanel
, &InformationPanel::requestDelayedItemInfo
);
1920 connect(this, &DolphinMainWindow::fileItemsChanged
,
1921 infoPanel
, &InformationPanel::slotFilesItemChanged
);
1924 // i18n: This is the last paragraph for the "What's This"-texts of all four panels.
1925 const QString panelWhatsThis
= xi18nc("@info:whatsthis", "<para>To show or "
1926 "hide panels like this go to <interface>Control|Panels</interface> "
1927 "or <interface>View|Panels</interface>.</para>");
1929 actionCollection()->action(QStringLiteral("show_information_panel"))
1930 ->setWhatsThis(xi18nc("@info:whatsthis", "<para> This toggles the "
1931 "<emphasis>information</emphasis> panel at the right side of the "
1932 "window.</para><para>The panel provides in-depth information "
1933 "about the items your mouse is hovering over or about the selected "
1934 "items. Otherwise it informs you about the currently viewed folder.<nl/>"
1935 "For single items a preview of their contents is provided.</para>"));
1937 infoDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
1938 "provides in-depth information about the items your mouse is "
1939 "hovering over or about the selected items. Otherwise it informs "
1940 "you about the currently viewed folder.<nl/>For single items a "
1941 "preview of their contents is provided.</para><para>You can configure "
1942 "which and how details are given here by right-clicking.</para>") + panelWhatsThis
);
1945 DolphinDockWidget
* foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
1946 foldersDock
->setLocked(lock
);
1947 foldersDock
->setObjectName(QStringLiteral("foldersDock"));
1948 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1949 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1950 foldersPanel
->setCustomContextMenuActions({lockLayoutAction
});
1951 foldersDock
->setWidget(foldersPanel
);
1953 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1954 createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7
, foldersAction
, QStringLiteral("show_folders_panel"));
1956 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1957 connect(this, &DolphinMainWindow::urlChanged
,
1958 foldersPanel
, &FoldersPanel::setUrl
);
1959 connect(foldersPanel
, &FoldersPanel::folderActivated
,
1960 this, &DolphinMainWindow::changeUrl
);
1961 connect(foldersPanel
, &FoldersPanel::folderInNewTab
,
1962 this, &DolphinMainWindow::openNewTab
);
1963 connect(foldersPanel
, &FoldersPanel::folderInNewActiveTab
,
1964 this, &DolphinMainWindow::openNewTabAndActivate
);
1965 connect(foldersPanel
, &FoldersPanel::errorMessage
,
1966 this, &DolphinMainWindow::showErrorMessage
);
1968 actionCollection()->action(QStringLiteral("show_folders_panel"))
1969 ->setWhatsThis(xi18nc("@info:whatsthis", "This toggles the "
1970 "<emphasis>folders</emphasis> panel at the left side of the window."
1971 "<nl/><nl/>It shows the folders of the <emphasis>file system"
1972 "</emphasis> in a <emphasis>tree view</emphasis>."));
1973 foldersDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
1974 "shows the folders of the <emphasis>file system</emphasis> in a "
1975 "<emphasis>tree view</emphasis>.</para><para>Click a folder to go "
1976 "there. Click the arrow to the left of a folder to see its subfolders. "
1977 "This allows quick switching between any folders.</para>") + panelWhatsThis
);
1981 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1982 DolphinDockWidget
* terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1983 terminalDock
->setLocked(lock
);
1984 terminalDock
->setObjectName(QStringLiteral("terminalDock"));
1985 m_terminalPanel
= new TerminalPanel(terminalDock
);
1986 m_terminalPanel
->setCustomContextMenuActions({lockLayoutAction
});
1987 terminalDock
->setWidget(m_terminalPanel
);
1989 connect(m_terminalPanel
, &TerminalPanel::hideTerminalPanel
, terminalDock
, &DolphinDockWidget::hide
);
1990 connect(m_terminalPanel
, &TerminalPanel::changeUrl
, this, &DolphinMainWindow::slotTerminalDirectoryChanged
);
1991 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
,
1992 m_terminalPanel
, &TerminalPanel::dockVisibilityChanged
);
1993 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
,
1994 this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged
);
1996 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1997 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4
, terminalAction
, QStringLiteral("show_terminal_panel"));
1999 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
2000 connect(this, &DolphinMainWindow::urlChanged
,
2001 m_terminalPanel
, &TerminalPanel::setUrl
);
2003 if (GeneralSettings::version() < 200) {
2004 terminalDock
->hide();
2007 actionCollection()->action(QStringLiteral("show_terminal_panel"))
2008 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
2009 "<emphasis>terminal</emphasis> panel at the bottom of the window."
2010 "<nl/>The location in the terminal will always match the folder "
2011 "view so you can navigate using either.</para><para>The terminal "
2012 "panel is not needed for basic computer usage but can be useful "
2013 "for advanced tasks. To learn more about terminals use the help "
2014 "in a standalone terminal application like Konsole.</para>"));
2015 terminalDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is "
2016 "the <emphasis>terminal</emphasis> panel. It behaves like a "
2017 "normal terminal but will match the location of the folder view "
2018 "so you can navigate using either.</para><para>The terminal panel "
2019 "is not needed for basic computer usage but can be useful for "
2020 "advanced tasks. To learn more about terminals use the help in a "
2021 "standalone terminal application like Konsole.</para>") + panelWhatsThis
);
2025 if (GeneralSettings::version() < 200) {
2027 foldersDock
->hide();
2031 DolphinDockWidget
* placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
2032 placesDock
->setLocked(lock
);
2033 placesDock
->setObjectName(QStringLiteral("placesDock"));
2034 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2036 m_placesPanel
= new PlacesPanel(placesDock
);
2037 m_placesPanel
->setCustomContextMenuActions({lockLayoutAction
});
2038 placesDock
->setWidget(m_placesPanel
);
2040 QAction
*placesAction
= placesDock
->toggleViewAction();
2041 createPanelAction(QIcon::fromTheme(QStringLiteral("compass")), Qt::Key_F9
, placesAction
, QStringLiteral("show_places_panel"));
2043 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
2044 connect(m_placesPanel
, &PlacesPanel::placeActivated
,
2045 this, &DolphinMainWindow::slotPlaceActivated
);
2046 connect(m_placesPanel
, &PlacesPanel::tabRequested
,
2047 this, &DolphinMainWindow::openNewTab
);
2048 connect(m_placesPanel
, &PlacesPanel::activeTabRequested
,
2049 this, &DolphinMainWindow::openNewTabAndActivate
);
2050 connect(m_placesPanel
, &PlacesPanel::newWindowRequested
, this, [this](const QUrl
&url
) {
2051 Dolphin::openNewWindow({url
}, this);
2053 connect(m_placesPanel
, &PlacesPanel::errorMessage
,
2054 this, &DolphinMainWindow::showErrorMessage
);
2055 connect(this, &DolphinMainWindow::urlChanged
,
2056 m_placesPanel
, &PlacesPanel::setUrl
);
2057 connect(placesDock
, &DolphinDockWidget::visibilityChanged
,
2058 &DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged
);
2059 connect(this, &DolphinMainWindow::settingsChanged
,
2060 m_placesPanel
, &PlacesPanel::readSettings
);
2061 connect(m_placesPanel
, &PlacesPanel::storageTearDownRequested
,
2062 this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested
);
2063 connect(m_placesPanel
, &PlacesPanel::storageTearDownExternallyRequested
,
2064 this, &DolphinMainWindow::slotStorageTearDownExternallyRequested
);
2065 DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged(m_placesPanel
->isVisible());
2067 auto actionShowAllPlaces
= new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this);
2068 actionShowAllPlaces
->setCheckable(true);
2069 actionShowAllPlaces
->setDisabled(true);
2070 actionShowAllPlaces
->setWhatsThis(i18nc("@info:whatsthis", "This displays "
2071 "all places in the places panel that have been hidden. They will "
2072 "appear semi-transparent unless you uncheck their hide property."));
2074 connect(actionShowAllPlaces
, &QAction::triggered
, this, [actionShowAllPlaces
, this](bool checked
){
2075 m_placesPanel
->setShowAll(checked
);
2077 connect(m_placesPanel
, &PlacesPanel::allPlacesShownChanged
, actionShowAllPlaces
, &QAction::setChecked
);
2079 actionCollection()->action(QStringLiteral("show_places_panel"))
2080 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
2081 "<emphasis>places</emphasis> panel at the left side of the window."
2082 "</para><para>It allows you to go to locations you have "
2083 "bookmarked and to access disk or media attached to the computer "
2084 "or to the network. It also contains sections to find recently "
2085 "saved files or files of a certain type.</para>"));
2086 placesDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2087 "<emphasis>Places</emphasis> panel. It allows you to go to locations "
2088 "you have bookmarked and to access disk or media attached to the "
2089 "computer or to the network. It also contains sections to find "
2090 "recently saved files or files of a certain type.</para><para>"
2091 "Click on an entry to go there. Click with the right mouse button "
2092 "instead to open any entry in a new tab or new window.</para>"
2093 "<para>New entries can be added by dragging folders onto this panel. "
2094 "Right-click any section or entry to hide it. Right-click an empty "
2095 "space on this panel and select <interface>Show Hidden Places"
2096 "</interface> to display it again.</para>") + panelWhatsThis
);
2098 // Add actions into the "Panels" menu
2099 KActionMenu
* panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Show Panels"), this);
2100 actionCollection()->addAction(QStringLiteral("panels"), panelsMenu
);
2101 panelsMenu
->setIcon(QIcon::fromTheme(QStringLiteral("view-sidetree")));
2102 panelsMenu
->setPopupMode(QToolButton::InstantPopup
);
2103 const KActionCollection
* ac
= actionCollection();
2104 panelsMenu
->addAction(ac
->action(QStringLiteral("show_places_panel")));
2106 panelsMenu
->addAction(ac
->action(QStringLiteral("show_information_panel")));
2108 panelsMenu
->addAction(ac
->action(QStringLiteral("show_folders_panel")));
2109 panelsMenu
->addAction(ac
->action(QStringLiteral("show_terminal_panel")));
2110 panelsMenu
->addSeparator();
2111 panelsMenu
->addAction(actionShowAllPlaces
);
2112 panelsMenu
->addAction(lockLayoutAction
);
2114 connect(panelsMenu
->menu(), &QMenu::aboutToShow
, this, [actionShowAllPlaces
, this]{
2115 actionShowAllPlaces
->setEnabled(DolphinPlacesModelSingleton::instance().placesModel()->hiddenCount());
2120 void DolphinMainWindow::updateFileAndEditActions()
2122 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
2123 const KActionCollection
* col
= actionCollection();
2124 KFileItemListProperties
capabilitiesSource(list
);
2126 QAction
* addToPlacesAction
= col
->action(QStringLiteral("add_to_places"));
2127 QAction
* copyToOtherViewAction
= col
->action(QStringLiteral("copy_to_inactive_split_view"));
2128 QAction
* moveToOtherViewAction
= col
->action(QStringLiteral("move_to_inactive_split_view"));
2129 QAction
* copyLocation
= col
->action(QString("copy_location"));
2131 if (list
.isEmpty()) {
2132 stateChanged(QStringLiteral("has_no_selection"));
2134 addToPlacesAction
->setEnabled(true);
2135 copyToOtherViewAction
->setEnabled(false);
2136 moveToOtherViewAction
->setEnabled(false);
2137 copyLocation
->setEnabled(false);
2139 stateChanged(QStringLiteral("has_selection"));
2141 QAction
* renameAction
= col
->action(KStandardAction::name(KStandardAction::RenameFile
));
2142 QAction
* moveToTrashAction
= col
->action(KStandardAction::name(KStandardAction::MoveToTrash
));
2143 QAction
* deleteAction
= col
->action(KStandardAction::name(KStandardAction::DeleteFile
));
2144 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
2145 QAction
* deleteWithTrashShortcut
= col
->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
2146 QAction
* showTarget
= col
->action(QStringLiteral("show_target"));
2147 QAction
* duplicateAction
= col
->action(QStringLiteral("duplicate")); // see DolphinViewActionHandler
2149 if (list
.length() == 1 && list
.first().isDir()) {
2150 addToPlacesAction
->setEnabled(true);
2152 addToPlacesAction
->setEnabled(false);
2155 if (m_tabWidget
->currentTabPage()->splitViewEnabled()) {
2156 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
2157 KFileItem capabilitiesDestination
;
2159 if (tabPage
->primaryViewActive()) {
2160 capabilitiesDestination
= tabPage
->secondaryViewContainer()->url();
2162 capabilitiesDestination
= tabPage
->primaryViewContainer()->url();
2165 copyToOtherViewAction
->setEnabled(capabilitiesDestination
.isWritable());
2166 moveToOtherViewAction
->setEnabled(capabilitiesSource
.supportsMoving() && capabilitiesDestination
.isWritable());
2168 copyToOtherViewAction
->setEnabled(false);
2169 moveToOtherViewAction
->setEnabled(false);
2172 const bool enableMoveToTrash
= capabilitiesSource
.isLocal() && capabilitiesSource
.supportsMoving();
2174 renameAction
->setEnabled(capabilitiesSource
.supportsMoving());
2175 moveToTrashAction
->setEnabled(enableMoveToTrash
);
2176 deleteAction
->setEnabled(capabilitiesSource
.supportsDeleting());
2177 deleteWithTrashShortcut
->setEnabled(capabilitiesSource
.supportsDeleting() && !enableMoveToTrash
);
2178 cutAction
->setEnabled(capabilitiesSource
.supportsMoving());
2179 copyLocation
->setEnabled(list
.length() == 1);
2180 showTarget
->setEnabled(list
.length() == 1 && list
.at(0).isLink());
2181 duplicateAction
->setEnabled(capabilitiesSource
.supportsWriting());
2185 void DolphinMainWindow::updateViewActions()
2187 m_actionHandler
->updateViewActions();
2189 QAction
* toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
2190 toggleFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
2192 updateSplitAction();
2195 void DolphinMainWindow::updateGoActions()
2197 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
2198 const QUrl currentUrl
= m_activeViewContainer
->url();
2199 // I think this is one of the best places to firstly be confronted
2200 // with a file system and its hierarchy. Talking about the root
2201 // directory might seem too much here but it is the question that
2202 // naturally arises in this context.
2203 goUpAction
->setWhatsThis(xi18nc("@info:whatsthis", "<para>Go to "
2204 "the folder that contains the currently viewed one.</para>"
2205 "<para>All files and folders are organized in a hierarchical "
2206 "<emphasis>file system</emphasis>. At the top of this hierarchy is "
2207 "a directory that contains all data connected to this computer"
2208 "—the <emphasis>root directory</emphasis>.</para>"));
2209 goUpAction
->setEnabled(KIO::upUrl(currentUrl
) != currentUrl
);
2212 void DolphinMainWindow::refreshViews()
2214 m_tabWidget
->refreshViews();
2216 if (GeneralSettings::modifiedStartupSettings()) {
2217 updateWindowTitle();
2220 Q_EMIT
settingsChanged();
2223 void DolphinMainWindow::clearStatusBar()
2225 m_activeViewContainer
->statusBar()->resetToDefaultText();
2228 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
2230 connect(container
, &DolphinViewContainer::showFilterBarChanged
,
2231 this, &DolphinMainWindow::updateFilterBarAction
);
2232 connect(container
, &DolphinViewContainer::writeStateChanged
,
2233 this, &DolphinMainWindow::slotWriteStateChanged
);
2234 connect(container
, &DolphinViewContainer::searchModeEnabledChanged
,
2235 this, &DolphinMainWindow::updateSearchAction
);
2236 connect(container
, &DolphinViewContainer::captionChanged
,
2237 this, &DolphinMainWindow::updateWindowTitle
);
2238 connect(container
, &DolphinViewContainer::tabRequested
,
2239 this, &DolphinMainWindow::openNewTab
);
2240 connect(container
, &DolphinViewContainer::activeTabRequested
,
2241 this, &DolphinMainWindow::openNewTabAndActivate
);
2243 const QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
2244 connect(toggleSearchAction
, &QAction::triggered
, container
, &DolphinViewContainer::setSearchModeEnabled
);
2246 const DolphinView
* view
= container
->view();
2247 connect(view
, &DolphinView::selectionChanged
,
2248 this, &DolphinMainWindow::slotSelectionChanged
);
2249 connect(view
, &DolphinView::requestItemInfo
,
2250 this, &DolphinMainWindow::requestItemInfo
);
2251 connect(view
, &DolphinView::fileItemsChanged
,
2252 this, &DolphinMainWindow::fileItemsChanged
);
2253 connect(view
, &DolphinView::tabRequested
,
2254 this, &DolphinMainWindow::openNewTab
);
2255 connect(view
, &DolphinView::activeTabRequested
,
2256 this, &DolphinMainWindow::openNewTabAndActivate
);
2257 connect(view
, &DolphinView::windowRequested
,
2258 this, &DolphinMainWindow::openNewWindow
);
2259 connect(view
, &DolphinView::requestContextMenu
,
2260 this, &DolphinMainWindow::openContextMenu
);
2261 connect(view
, &DolphinView::directoryLoadingStarted
,
2262 this, &DolphinMainWindow::enableStopAction
);
2263 connect(view
, &DolphinView::directoryLoadingCompleted
,
2264 this, &DolphinMainWindow::disableStopAction
);
2265 connect(view
, &DolphinView::directoryLoadingCompleted
,
2266 this, &DolphinMainWindow::slotDirectoryLoadingCompleted
);
2267 connect(view
, &DolphinView::goBackRequested
,
2268 this, &DolphinMainWindow::goBack
);
2269 connect(view
, &DolphinView::goForwardRequested
,
2270 this, &DolphinMainWindow::goForward
);
2271 connect(view
, &DolphinView::urlActivated
,
2272 this, &DolphinMainWindow::handleUrl
);
2273 connect(view
, &DolphinView::goUpRequested
,
2274 this, &DolphinMainWindow::goUp
);
2276 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::urlChanged
,
2277 this, &DolphinMainWindow::changeUrl
);
2278 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::historyChanged
,
2279 this, &DolphinMainWindow::updateHistory
);
2281 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
2282 (actionCollection()->action(QStringLiteral("url_navigators")));
2283 const KUrlNavigator
*navigator
= m_tabWidget
->currentTabPage()->primaryViewActive() ?
2284 navigators
->primaryUrlNavigator() :
2285 navigators
->secondaryUrlNavigator();
2287 QAction
*editableLocactionAction
= actionCollection()->action(QStringLiteral("editable_location"));
2288 editableLocactionAction
->setChecked(navigator
->isUrlEditable());
2289 connect(navigator
, &KUrlNavigator::editableStateChanged
,
2290 this, &DolphinMainWindow::slotEditableStateChanged
);
2291 connect(navigator
, &KUrlNavigator::tabRequested
,
2292 this, &DolphinMainWindow::openNewTab
);
2293 connect(navigator
, &KUrlNavigator::activeTabRequested
,
2294 this, &DolphinMainWindow::openNewTabAndActivate
);
2295 connect(navigator
, &KUrlNavigator::newWindowRequested
,
2296 this, &DolphinMainWindow::openNewWindow
);
2300 void DolphinMainWindow::updateSplitAction()
2302 QAction
* splitAction
= actionCollection()->action(QStringLiteral("split_view"));
2303 const DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
2304 if (tabPage
->splitViewEnabled()) {
2305 if (GeneralSettings::closeActiveSplitView() ? tabPage
->primaryViewActive() : !tabPage
->primaryViewActive()) {
2306 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2307 splitAction
->setToolTip(i18nc("@info", "Close left view"));
2308 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close")));
2310 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2311 splitAction
->setToolTip(i18nc("@info", "Close right view"));
2312 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close")));
2315 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2316 splitAction
->setToolTip(i18nc("@info", "Split view"));
2317 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2321 void DolphinMainWindow::updateAllowedToolbarAreas()
2323 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
2324 (actionCollection()->action(QStringLiteral("url_navigators")));
2325 if (toolBar()->actions().contains(navigators
)) {
2326 toolBar()->setAllowedAreas(Qt::TopToolBarArea
| Qt::BottomToolBarArea
);
2327 if (toolBarArea(toolBar()) == Qt::LeftToolBarArea
||
2328 toolBarArea(toolBar()) == Qt::RightToolBarArea
) {
2329 addToolBar(Qt::TopToolBarArea
, toolBar());
2332 toolBar()->setAllowedAreas(Qt::AllToolBarAreas
);
2336 bool DolphinMainWindow::isKompareInstalled() const
2338 static bool initialized
= false;
2339 static bool installed
= false;
2341 // TODO: maybe replace this approach later by using a menu
2342 // plugin like kdiff3plugin.cpp
2343 installed
= !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty();
2349 void DolphinMainWindow::createPanelAction(const QIcon
& icon
,
2350 const QKeySequence
& shortcut
,
2351 QAction
* dockAction
,
2352 const QString
& actionName
)
2354 QAction
* panelAction
= actionCollection()->addAction(actionName
);
2355 panelAction
->setCheckable(true);
2356 panelAction
->setChecked(dockAction
->isChecked());
2357 panelAction
->setText(dockAction
->text());
2358 panelAction
->setIcon(icon
);
2359 dockAction
->setIcon(icon
);
2360 actionCollection()->setDefaultShortcut(panelAction
, shortcut
);
2362 connect(panelAction
, &QAction::triggered
, dockAction
, &QAction::trigger
);
2363 connect(dockAction
, &QAction::toggled
, panelAction
, &QAction::setChecked
);
2366 void DolphinMainWindow::setupWhatsThis()
2369 menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2370 "<emphasis>Menubar</emphasis>. It provides access to commands and "
2371 "configuration options. Left-click on any of the menus on this "
2372 "bar to see its contents.</para><para>The Menubar can be hidden "
2373 "by unchecking <interface>Settings|Show Menubar</interface>. Then "
2374 "most of its contents become available through a <interface>Control"
2375 "</interface> button on the <emphasis>Toolbar</emphasis>.</para>"));
2376 toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2377 "<emphasis>Toolbar</emphasis>. It allows quick access to "
2378 "frequently used actions.</para><para>It is highly customizable. "
2379 "All items you see in the <interface>Control</interface> menu or "
2380 "in the <interface>Menubar</interface> can be placed on the "
2381 "Toolbar. Just right-click on it and select <interface>Configure "
2382 "Toolbars…</interface> or find this action in the <interface>"
2383 "Control</interface> or <interface>Settings</interface> menu."
2384 "</para><para>The location of the bar and the style of its "
2385 "buttons can also be changed in the right-click menu. Right-click "
2386 "a button if you want to show or hide its text.</para>"));
2387 m_tabWidget
->setWhatsThis(xi18nc("@info:whatsthis main view",
2388 "<para>Here you can see the <emphasis>folders</emphasis> and "
2389 "<emphasis>files</emphasis> that are at the location described in "
2390 "the <interface>Location Bar</interface> above. This area is the "
2391 "central part of this application where you navigate to the files "
2392 "you want to use.</para><para>For an elaborate and general "
2393 "introduction to this application <link "
2394 "url='https://userbase.kde.org/Dolphin/File_Management#Introduction_to_Dolphin'>"
2395 "click here</link>. This will open an introductory article from "
2396 "the <emphasis>KDE UserBase Wiki</emphasis>.</para><para>For brief "
2397 "explanations of all the features of this <emphasis>view</emphasis> "
2398 "<link url='help:/dolphin/dolphin-view.html'>click here</link> "
2399 "instead. This will open a page from the <emphasis>Handbook"
2400 "</emphasis> that covers the basics.</para>"));
2403 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings
))
2404 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window "
2405 "that lists the <emphasis>keyboard shortcuts</emphasis>.<nl/>"
2406 "There you can set up key combinations to trigger an action when "
2407 "they are pressed simultaneously. All commands in this application can "
2408 "be triggered this way.</para>"));
2409 actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars
))
2410 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window in which "
2411 "you can change which buttons appear on the <emphasis>Toolbar</emphasis>.</para>"
2412 "<para>All items you see in the <interface>Control</interface> menu "
2413 "or in the <interface>Menubar</interface> can also be placed on the Toolbar.</para>"));
2414 actionCollection()->action(KStandardAction::name(KStandardAction::Preferences
))
2415 ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can "
2416 "change a multitude of settings for this application. For an explanation "
2417 "of the various settings go to the chapter <emphasis>Configuring Dolphin"
2418 "</emphasis> in <interface>Help|Dolphin Handbook</interface>."));
2421 // The whatsthis has to be set for the m_helpMenu and for the
2422 // StandardAction separately because both are used in different locations.
2423 // m_helpMenu is only used for createControlButton() button.
2425 auto setStandardActionWhatsThis
= [this](KStandardAction::StandardAction actionId
,
2426 const QString
&whatsThis
) {
2427 if (auto *action
= actionCollection()->action(KStandardAction::name(actionId
))) {
2428 action
->setWhatsThis(whatsThis
);
2431 auto setHelpActionWhatsThis
= [this](KHelpMenu::MenuId menuId
, const QString
&whatsThis
) {
2432 if (auto *action
= m_helpMenu
->action(menuId
)) {
2433 action
->setWhatsThis(whatsThis
);
2437 // Links do not work within the Menubar so texts without links are provided there.
2439 // i18n: If the external link isn't available in your language you should
2440 // probably state the external link language at least in brackets to not
2441 // frustrate the user. If there are multiple languages that the user might
2442 // know with a reasonable chance you might want to have 2 external links.
2443 // The same is in my opinion true for every external link you translate.
2444 const QString whatsThisHelpContents
= xi18nc("@info:whatsthis handbook",
2445 "<para>This opens the Handbook for this application. It provides "
2446 "explanations for every part of <emphasis>Dolphin</emphasis>.</para>");
2447 setStandardActionWhatsThis(KStandardAction::HelpContents
, whatsThisHelpContents
2448 + xi18nc("@info:whatsthis second half of handbook hb text without link",
2449 "<para>If you want more elaborate introductions to the "
2450 "different features of <emphasis>Dolphin</emphasis> "
2451 "go to the KDE UserBase Wiki.</para>"));
2452 setHelpActionWhatsThis(KHelpMenu::menuHelpContents
, whatsThisHelpContents
2453 + xi18nc("@info:whatsthis second half of handbook text with link",
2454 "<para>If you want more elaborate introductions to the "
2455 "different features of <emphasis>Dolphin</emphasis> "
2456 "<link url='https://userbase.kde.org/Dolphin/File_Management'>click here</link>. "
2457 "It will open the dedicated page in the KDE UserBase Wiki.</para>"));
2459 const QString whatsThisWhatsThis
= xi18nc("@info:whatsthis whatsthis button",
2460 "<para>This is the button that invokes the help feature you are "
2461 "using right now! Click it, then click any component of this "
2462 "application to ask \"What's this?\" about it. The mouse cursor "
2463 "will change appearance if no help is available for a spot.</para>");
2464 setStandardActionWhatsThis(KStandardAction::WhatsThis
, whatsThisWhatsThis
2465 + xi18nc("@info:whatsthis second half of whatsthis button text without link",
2466 "<para>There are two other ways to get help for this application: The "
2467 "<interface>Dolphin Handbook</interface> in the <interface>Help"
2468 "</interface> menu and the <emphasis>KDE UserBase Wiki</emphasis> "
2469 "article about <emphasis>File Management</emphasis> online."
2470 "</para><para>The \"What's this?\" help is "
2471 "missing in most other windows so don't get too used to this.</para>"));
2472 setHelpActionWhatsThis(KHelpMenu::menuWhatsThis
, whatsThisWhatsThis
2473 + xi18nc("@info:whatsthis second half of whatsthis button text with link",
2474 "<para>There are two other ways to get help: "
2475 "The <link url='help:/dolphin/index.html'>Dolphin Handbook</link> and "
2476 "the <link url='https://userbase.kde.org/Dolphin/File_Management'>KDE "
2477 "UserBase Wiki</link>.</para><para>The \"What's this?\" help is "
2478 "missing in most other windows so don't get too used to this.</para>"));
2480 const QString whatsThisReportBug
= xi18nc("@info:whatsthis","<para>This opens a "
2481 "window that will guide you through reporting errors or flaws "
2482 "in this application or in other KDE software.</para>");
2483 setStandardActionWhatsThis(KStandardAction::ReportBug
, whatsThisReportBug
);
2484 setHelpActionWhatsThis(KHelpMenu::menuReportBug
, whatsThisReportBug
2485 + xi18nc("@info:whatsthis second half of reportbug text with link",
2486 "<para>High-quality bug reports are much appreciated. To learn "
2487 "how to make your bug report as effective as possible "
2488 "<link url='https://community.kde.org/Get_Involved/Bug_Reporting'>"
2489 "click here</link>.</para>"));
2491 const QString whatsThisDonate
= xi18nc("@info:whatsthis","<para>This opens a "
2492 "<emphasis>web page</emphasis> where you can donate to "
2493 "support the continued work on this application and many "
2494 "other projects by the <emphasis>KDE</emphasis> community.</para>"
2495 "<para>Donating is the easiest and fastest way to efficiently "
2496 "support KDE and its projects. KDE projects are available for "
2497 "free therefore your donation is needed to cover things that "
2498 "require money like servers, contributor meetings, etc.</para>"
2499 "<para><emphasis>KDE e.V.</emphasis> is the non-profit "
2500 "organization behind the KDE community.</para>");
2501 setStandardActionWhatsThis(KStandardAction::Donate
, whatsThisDonate
);
2502 setHelpActionWhatsThis(KHelpMenu::menuDonate
, whatsThisDonate
);
2504 const QString whatsThisSwitchLanguage
= xi18nc("@info:whatsthis",
2505 "With this you can change the language this application uses."
2506 "<nl/>You can even set secondary languages which will be used "
2507 "if texts are not available in your preferred language.");
2508 setStandardActionWhatsThis(KStandardAction::SwitchApplicationLanguage
,
2509 whatsThisSwitchLanguage
);
2510 setHelpActionWhatsThis(KHelpMenu::menuSwitchLanguage
, whatsThisSwitchLanguage
);
2512 const QString whatsThisAboutApp
= xi18nc("@info:whatsthis","This opens a "
2513 "window that informs you about the version, license, "
2514 "used libraries and maintainers of this application.");
2515 setStandardActionWhatsThis(KStandardAction::AboutApp
, whatsThisAboutApp
);
2516 setHelpActionWhatsThis(KHelpMenu::menuAboutApp
, whatsThisAboutApp
);
2518 const QString whatsThisAboutKDE
= xi18nc("@info:whatsthis","This opens a "
2519 "window with information about <emphasis>KDE</emphasis>. "
2520 "The KDE community are the people behind this free software."
2521 "<nl/>If you like using this application but don't know "
2522 "about KDE or want to see a cute dragon have a look!");
2523 setStandardActionWhatsThis(KStandardAction::AboutKDE
, whatsThisAboutKDE
);
2524 setHelpActionWhatsThis(KHelpMenu::menuAboutKDE
, whatsThisAboutKDE
);
2527 bool DolphinMainWindow::addHamburgerMenuToToolbar()
2529 QDomDocument domDocument
= KXMLGUIClient::domDocument();
2530 if (domDocument
.isNull()) {
2533 QDomNode toolbar
= domDocument
.elementsByTagName(QStringLiteral("ToolBar")).at(0);
2534 if (toolbar
.isNull()) {
2538 QDomElement hamburgerMenuElement
= domDocument
.createElement(QStringLiteral("Action"));
2539 hamburgerMenuElement
.setAttribute(QStringLiteral("name"), QStringLiteral("hamburger_menu"));
2540 toolbar
.appendChild(hamburgerMenuElement
);
2542 KXMLGUIFactory::saveConfigFile(domDocument
, xmlFile());
2546 // Make sure to also remove the <KXMLGUIFactory> and <QDomDocument> include
2547 // whenever this method is removed (maybe in the year ~2026).
2550 bool DolphinMainWindow::event(QEvent
*event
)
2552 if (event
->type() == QEvent::WhatsThisClicked
) {
2554 QWhatsThisClickedEvent
* whatsThisEvent
= dynamic_cast<QWhatsThisClickedEvent
*>(event
);
2555 QDesktopServices::openUrl(QUrl(whatsThisEvent
->href()));
2558 return KXmlGuiWindow::event(event
);
2561 bool DolphinMainWindow::eventFilter(QObject
* obj
, QEvent
* event
)
2564 if (event
->type() == QEvent::WhatsThisClicked
) {
2566 QWhatsThisClickedEvent
* whatsThisEvent
= dynamic_cast<QWhatsThisClickedEvent
*>(event
);
2567 QDesktopServices::openUrl(QUrl(whatsThisEvent
->href()));
2573 // Set a sane initial window size
2574 QSize
DolphinMainWindow::sizeHint() const
2576 return KXmlGuiWindow::sizeHint().expandedTo(QSize(760, 550));
2579 void DolphinMainWindow::saveNewToolbarConfig()
2581 KXmlGuiWindow::saveNewToolbarConfig(); // Applies the new config. This has to be called first
2582 // because the rest of this method decides things
2583 // based on the new config.
2584 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
2585 (actionCollection()->action(QStringLiteral("url_navigators")));
2586 if (!toolBar()->actions().contains(navigators
)) {
2587 m_tabWidget
->currentTabPage()->insertNavigatorsWidget(navigators
);
2589 updateAllowedToolbarAreas();
2590 (static_cast<KHamburgerMenu
*>(actionCollection()->action(KStandardAction::name(
2591 KStandardAction::HamburgerMenu
))))->hideActionsOf(toolBar());
2594 void DolphinMainWindow::focusTerminalPanel()
2596 if (m_terminalPanel
->isVisible()) {
2597 if (m_terminalPanel
->terminalHasFocus()) {
2598 m_activeViewContainer
->view()->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2599 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2601 m_terminalPanel
->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2602 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2605 actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger();
2606 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2610 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
2611 KIO::FileUndoManager::UiInterface()
2615 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2619 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
2621 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2623 DolphinViewContainer
* container
= mainWin
->activeViewContainer();
2624 container
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
2626 KIO::FileUndoManager::UiInterface::jobError(job
);
2630 bool DolphinMainWindow::isUrlOpen(const QString
&url
)
2632 return m_tabWidget
->isUrlOpen(QUrl::fromUserInput(url
));
2635 bool DolphinMainWindow::isUrlOrParentOpen(const QString
&url
)
2637 return m_tabWidget
->isUrlOrParentOpen(QUrl::fromUserInput(url
));