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 KGuiItem(i18ncp("@action:button", "Open %1 Terminal", "Open %1 Terminals", urls
.count()),
1124 QStringLiteral("utilities-terminal")),
1125 KStandardGuiItem::cancel());
1126 if (answer
!= KMessageBox::Yes
) {
1131 for (const QUrl
& url
: urls
) {
1132 openTerminalJob(url
);
1136 void DolphinMainWindow::openTerminalJob(const QUrl
& url
)
1138 if (url
.isLocalFile()) {
1139 auto job
= new KTerminalLauncherJob(QString());
1140 job
->setWorkingDirectory(url
.toLocalFile());
1145 // Not a local file, with protocol Class ":local", try stat'ing
1146 if (KProtocolInfo::protocolClass(url
.scheme()) == QLatin1String(":local")) {
1147 KIO::StatJob
*job
= KIO::mostLocalUrl(url
);
1148 KJobWidgets::setWindow(job
, this);
1149 connect(job
, &KJob::result
, this, [job
]() {
1151 if (!job
->error()) {
1152 statUrl
= job
->mostLocalUrl();
1155 auto job
= new KTerminalLauncherJob(QString());
1156 job
->setWorkingDirectory(statUrl
.isLocalFile() ? statUrl
.toLocalFile() : QDir::homePath());
1163 // Nothing worked, just use $HOME
1164 auto job
= new KTerminalLauncherJob(QString());
1165 job
->setWorkingDirectory(QDir::homePath());
1169 void DolphinMainWindow::editSettings()
1171 if (!m_settingsDialog
) {
1172 DolphinViewContainer
* container
= activeViewContainer();
1173 container
->view()->writeSettings();
1175 const QUrl url
= container
->url();
1176 DolphinSettingsDialog
* settingsDialog
= new DolphinSettingsDialog(url
, this, actionCollection());
1177 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, this, &DolphinMainWindow::refreshViews
);
1178 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
,
1179 &DolphinUrlNavigatorsController::slotReadSettings
);
1180 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1181 settingsDialog
->show();
1182 m_settingsDialog
= settingsDialog
;
1184 m_settingsDialog
.data()->raise();
1188 void DolphinMainWindow::handleUrl(const QUrl
& url
)
1190 delete m_lastHandleUrlOpenJob
;
1191 m_lastHandleUrlOpenJob
= nullptr;
1193 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1194 activeViewContainer()->setUrl(url
);
1196 m_lastHandleUrlOpenJob
= new KIO::OpenUrlJob(url
);
1197 m_lastHandleUrlOpenJob
->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
1198 m_lastHandleUrlOpenJob
->setShowOpenOrExecuteDialog(true);
1200 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::mimeTypeFound
, this,
1201 [this, url
](const QString
&mimetype
) {
1202 if (mimetype
== QLatin1String("inode/directory")) {
1203 // If it's a dir, we'll take it from here
1204 m_lastHandleUrlOpenJob
->kill();
1205 m_lastHandleUrlOpenJob
= nullptr;
1206 activeViewContainer()->setUrl(url
);
1210 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::result
, this, [this]() {
1211 m_lastHandleUrlOpenJob
= nullptr;
1214 m_lastHandleUrlOpenJob
->start();
1218 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1220 // trash:/ is writable but we don't want to create new items in it.
1221 // TODO: remove the trash check once https://phabricator.kde.org/T8234 is implemented
1222 newFileMenu()->setEnabled(isFolderWritable
&& m_activeViewContainer
->url().scheme() != QLatin1String("trash"));
1225 void DolphinMainWindow::openContextMenu(const QPoint
& pos
,
1226 const KFileItem
& item
,
1227 const KFileItemList
&selectedItems
,
1230 QPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, item
, selectedItems
, url
, &m_fileItemActions
);
1231 contextMenu
.data()->exec(pos
);
1233 // Delete the menu, unless it has been deleted in its own nested event loop already.
1235 contextMenu
->deleteLater();
1239 QMenu
*DolphinMainWindow::createPopupMenu()
1241 QMenu
*menu
= KXmlGuiWindow::createPopupMenu();
1243 menu
->addSeparator();
1244 menu
->addAction(actionCollection()->action(QStringLiteral("lock_panels")));
1249 void DolphinMainWindow::updateHamburgerMenu()
1251 KActionCollection
* ac
= actionCollection();
1252 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(
1253 ac
->action(KStandardAction::name(KStandardAction::HamburgerMenu
)));
1254 auto menu
= hamburgerMenu
->menu();
1256 menu
= new QMenu(this);
1257 hamburgerMenu
->setMenu(menu
);
1258 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("basic_actions"))->menu());
1259 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("zoom"))->menu());
1263 const QList
<QAction
*> toolbarActions
= toolBar()->actions();
1265 if (!toolBar()->isVisible()) {
1266 // If neither the menu bar nor the toolbar are visible, these actions should be available.
1267 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)));
1268 menu
->addAction(toolBarMenuAction());
1269 menu
->addSeparator();
1272 // This group of actions (until the next separator) contains all the most basic actions
1273 // necessary to use Dolphin effectively.
1274 menu
->addAction(ac
->action(QStringLiteral("go_back")));
1275 menu
->addAction(ac
->action(QStringLiteral("go_forward")));
1277 menu
->addMenu(m_newFileMenu
->menu());
1278 menu
->addAction(ac
->action(QStringLiteral("basic_actions")));
1279 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Undo
)));
1280 if (!toolBar()->isVisible()
1281 || (!toolbarActions
.contains(ac
->action(QStringLiteral("toggle_search")))
1282 && !toolbarActions
.contains(ac
->action(QStringLiteral("open_preferred_search_tool"))))
1284 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Find
)));
1285 // This way a search action will only be added if none of the three available
1286 // search actions is present on the toolbar.
1288 if (!toolBar()->isVisible()
1289 || !toolbarActions
.contains(ac
->action(QStringLiteral("toggle_filter")))
1291 menu
->addAction(ac
->action(QStringLiteral("show_filter_bar")));
1292 // This way a filter action will only be added if none of the two available
1293 // filter actions is present on the toolbar.
1295 menu
->addSeparator();
1297 // The second group of actions (up until the next separator) contains actions for opening
1298 // additional views to interact with the file system.
1299 menu
->addAction(ac
->action(QStringLiteral("file_new")));
1300 menu
->addAction(ac
->action(QStringLiteral("new_tab")));
1301 if (ac
->action(QStringLiteral("undo_close_tab"))->isEnabled()) {
1302 menu
->addAction(ac
->action(QStringLiteral("closed_tabs")));
1304 menu
->addAction(ac
->action(QStringLiteral("open_terminal")));
1305 menu
->addSeparator();
1307 // The third group contains actions to change what one sees in the view
1308 // and to change the more general UI.
1309 if (!toolBar()->isVisible()
1310 || (!toolbarActions
.contains(ac
->action(QStringLiteral("icons")))
1311 && !toolbarActions
.contains(ac
->action(QStringLiteral("compact")))
1312 && !toolbarActions
.contains(ac
->action(QStringLiteral("details")))
1313 && !toolbarActions
.contains(ac
->action(QStringLiteral("view_mode"))))
1315 menu
->addAction(ac
->action(QStringLiteral("view_mode")));
1317 menu
->addAction(ac
->action(QStringLiteral("show_hidden_files")));
1318 menu
->addAction(ac
->action(QStringLiteral("sort")));
1319 menu
->addAction(ac
->action(QStringLiteral("additional_info")));
1320 if (!GeneralSettings::showStatusBar() || !GeneralSettings::showZoomSlider()) {
1321 menu
->addAction(ac
->action(QStringLiteral("zoom")));
1323 menu
->addAction(ac
->action(QStringLiteral("panels")));
1325 // The "Configure" menu is not added to the actionCollection() because there is hardly
1326 // a good reason for users to put it on their toolbar.
1327 auto configureMenu
= menu
->addMenu(QIcon::fromTheme(QStringLiteral("configure")),
1328 i18nc("@action:inmenu menu for configure actions", "Configure"));
1329 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
)));
1330 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)));
1331 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)));
1332 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Preferences
)));
1333 hamburgerMenu
->hideActionsOf(configureMenu
);
1336 void DolphinMainWindow::slotPlaceActivated(const QUrl
& url
)
1338 DolphinViewContainer
* view
= activeViewContainer();
1340 if (view
->url() == url
) {
1341 // We can end up here if the user clicked a device in the Places Panel
1342 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1345 view
->disableUrlNavigatorSelectionRequests();
1347 view
->enableUrlNavigatorSelectionRequests();
1351 void DolphinMainWindow::closedTabsCountChanged(unsigned int count
)
1353 actionCollection()->action(QStringLiteral("undo_close_tab"))->setEnabled(count
> 0);
1356 void DolphinMainWindow::activeViewChanged(DolphinViewContainer
* viewContainer
)
1358 DolphinViewContainer
* oldViewContainer
= m_activeViewContainer
;
1359 Q_ASSERT(viewContainer
);
1361 m_activeViewContainer
= viewContainer
;
1363 if (oldViewContainer
) {
1364 const QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
1365 toggleSearchAction
->disconnect(oldViewContainer
);
1367 // Disconnect all signals between the old view container (container,
1368 // view and url navigator) and main window.
1369 oldViewContainer
->disconnect(this);
1370 oldViewContainer
->view()->disconnect(this);
1371 oldViewContainer
->urlNavigatorInternalWithHistory()->disconnect(this);
1372 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
1373 (actionCollection()->action(QStringLiteral("url_navigators")));
1374 navigators
->primaryUrlNavigator()->disconnect(this);
1375 if (auto secondaryUrlNavigator
= navigators
->secondaryUrlNavigator()) {
1376 secondaryUrlNavigator
->disconnect(this);
1379 // except the requestItemInfo so that on hover the information panel can still be updated
1380 connect(oldViewContainer
->view(), &DolphinView::requestItemInfo
,
1381 this, &DolphinMainWindow::requestItemInfo
);
1384 connectViewSignals(viewContainer
);
1386 m_actionHandler
->setCurrentView(viewContainer
->view());
1389 updateFileAndEditActions();
1390 updatePasteAction();
1391 updateViewActions();
1393 updateSearchAction();
1395 const QUrl url
= viewContainer
->url();
1396 Q_EMIT
urlChanged(url
);
1399 void DolphinMainWindow::tabCountChanged(int count
)
1401 const bool enableTabActions
= (count
> 1);
1402 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1403 actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i
))->setEnabled(enableTabActions
);
1405 actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions
);
1406 actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions
);
1407 actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions
);
1410 void DolphinMainWindow::updateWindowTitle()
1412 const QString newTitle
= m_activeViewContainer
->captionWindowTitle();
1413 if (windowTitle() != newTitle
) {
1414 setWindowTitle(newTitle
);
1418 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString
& mountPath
)
1420 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1421 setViewsToHomeIfMountPathOpen(mountPath
);
1424 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectory().startsWith(mountPath
)) {
1425 m_tearDownFromPlacesRequested
= true;
1426 m_terminalPanel
->goHome();
1427 // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
1429 m_placesPanel
->proceedWithTearDown();
1433 void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString
& mountPath
)
1435 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1436 setViewsToHomeIfMountPathOpen(mountPath
);
1439 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectory().startsWith(mountPath
)) {
1440 m_tearDownFromPlacesRequested
= false;
1441 m_terminalPanel
->goHome();
1445 void DolphinMainWindow::slotKeyBindings()
1447 KShortcutsDialog
dialog(KShortcutsEditor::AllActions
, KShortcutsEditor::LetterShortcutsAllowed
, this);
1448 dialog
.addCollection(actionCollection());
1449 if (m_terminalPanel
) {
1450 KActionCollection
*konsolePartActionCollection
= m_terminalPanel
->actionCollection();
1451 if (konsolePartActionCollection
) {
1452 dialog
.addCollection(konsolePartActionCollection
, QStringLiteral("KonsolePart"));
1458 void DolphinMainWindow::setViewsToHomeIfMountPathOpen(const QString
& mountPath
)
1460 const QVector
<DolphinViewContainer
*> theViewContainers
= viewContainers();
1461 for (DolphinViewContainer
*viewContainer
: theViewContainers
) {
1462 if (viewContainer
&& viewContainer
->url().toLocalFile().startsWith(mountPath
)) {
1463 viewContainer
->setUrl(QUrl::fromLocalFile(QDir::homePath()));
1466 disconnect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, nullptr, nullptr);
1469 void DolphinMainWindow::setupActions()
1471 KStandardAction::hamburgerMenu(nullptr, nullptr, actionCollection());
1473 // setup 'File' menu
1474 m_newFileMenu
= new DolphinNewFileMenu(actionCollection(), this);
1475 QMenu
* menu
= m_newFileMenu
->menu();
1476 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1477 menu
->setIcon(QIcon::fromTheme(QStringLiteral("list-add")));
1478 m_newFileMenu
->setPopupMode(QToolButton::InstantPopup
);
1479 connect(menu
, &QMenu::aboutToShow
,
1480 this, &DolphinMainWindow::updateNewMenu
);
1482 QAction
* newWindow
= KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow
, actionCollection());
1483 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1484 newWindow
->setToolTip(i18nc("@info", "Open a new Dolphin window"));
1485 newWindow
->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1486 "window just like this one with the current location and view."
1487 "<nl/>You can drag and drop items between windows."));
1488 newWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1490 QAction
* newTab
= actionCollection()->addAction(QStringLiteral("new_tab"));
1491 newTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1492 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1493 newTab
->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1494 "<emphasis>Tab</emphasis> with the current location and view.<nl/>"
1495 "A tab is an additional view within this window. "
1496 "You can drag and drop items between tabs."));
1497 actionCollection()->setDefaultShortcuts(newTab
, {Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
});
1498 connect(newTab
, &QAction::triggered
, this, &DolphinMainWindow::openNewActivatedTab
);
1500 QAction
* addToPlaces
= actionCollection()->addAction(QStringLiteral("add_to_places"));
1501 addToPlaces
->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new")));
1502 addToPlaces
->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places"));
1503 addToPlaces
->setWhatsThis(xi18nc("@info:whatsthis", "This adds the selected folder "
1504 "to the Places panel."));
1505 connect(addToPlaces
, &QAction::triggered
, this, &DolphinMainWindow::addToPlaces
);
1507 QAction
* closeTab
= KStandardAction::close(m_tabWidget
, QOverload
<>::of(&DolphinTabWidget::closeTab
), actionCollection());
1508 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1509 closeTab
->setWhatsThis(i18nc("@info:whatsthis", "This closes the "
1510 "currently viewed tab. If no more tabs are left this window "
1511 "will close instead."));
1513 QAction
* quitAction
= KStandardAction::quit(this, &DolphinMainWindow::quit
, actionCollection());
1514 quitAction
->setWhatsThis(i18nc("@info:whatsthis quit", "This closes this window."));
1516 // setup 'Edit' menu
1517 KStandardAction::undo(this,
1518 &DolphinMainWindow::undo
,
1519 actionCollection());
1521 // i18n: This will be the last paragraph for the whatsthis for all three:
1522 // Cut, Copy and Paste
1523 const QString cutCopyPastePara
= xi18nc("@info:whatsthis", "<para><emphasis>Cut, "
1524 "Copy</emphasis> and <emphasis>Paste</emphasis> work between many "
1525 "applications and are among the most used commands. That's why their "
1526 "<emphasis>keyboard shortcuts</emphasis> are prominently placed right "
1527 "next to each other on the keyboard: <shortcut>Ctrl+X</shortcut>, "
1528 "<shortcut>Ctrl+C</shortcut> and <shortcut>Ctrl+V</shortcut>.</para>");
1529 QAction
* cutAction
= KStandardAction::cut(this, &DolphinMainWindow::cut
, actionCollection());
1530 cutAction
->setWhatsThis(xi18nc("@info:whatsthis cut", "This copies the items "
1531 "in your current selection to the <emphasis>clipboard</emphasis>.<nl/>"
1532 "Use the <emphasis>Paste</emphasis> action afterwards to copy them from "
1533 "the clipboard to a new location. The items will be removed from their "
1534 "initial location.") + cutCopyPastePara
);
1535 QAction
* copyAction
= KStandardAction::copy(this, &DolphinMainWindow::copy
, actionCollection());
1536 copyAction
->setWhatsThis(xi18nc("@info:whatsthis copy", "This copies the "
1537 "items in your current selection to the <emphasis>clipboard</emphasis>."
1538 "<nl/>Use the <emphasis>Paste</emphasis> action afterwards to copy them "
1539 "from the clipboard to a new location.") + cutCopyPastePara
);
1540 QAction
* paste
= KStandardAction::paste(this, &DolphinMainWindow::paste
, actionCollection());
1541 // The text of the paste-action is modified dynamically by Dolphin
1542 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1543 // due to the long text, the text "Paste" is used:
1544 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1545 paste
->setWhatsThis(xi18nc("@info:whatsthis paste", "This copies the items from "
1546 "your <emphasis>clipboard</emphasis> to the currently viewed folder.<nl/>"
1547 "If the items were added to the clipboard by the <emphasis>Cut</emphasis> "
1548 "action they are removed from their old location.") + cutCopyPastePara
);
1550 QAction
* copyToOtherViewAction
= actionCollection()->addAction(QStringLiteral("copy_to_inactive_split_view"));
1551 copyToOtherViewAction
->setText(i18nc("@action:inmenu", "Copy to Inactive Split View"));
1552 copyToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Copy", "This copies the selected items from "
1553 "the <emphasis>active</emphasis> view to the inactive split view."));
1554 copyToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
1555 copyToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Copy to Inactive Split View"));
1556 actionCollection()->setDefaultShortcut(copyToOtherViewAction
, Qt::SHIFT
| Qt::Key_F5
);
1557 connect(copyToOtherViewAction
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::copyToInactiveSplitView
);
1559 QAction
* moveToOtherViewAction
= actionCollection()->addAction(QStringLiteral("move_to_inactive_split_view"));
1560 moveToOtherViewAction
->setText(i18nc("@action:inmenu", "Move to Inactive Split View"));
1561 moveToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Move", "This moves the selected items from "
1562 "the <emphasis>active</emphasis> view to the inactive split view."));
1563 moveToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-cut")));
1564 moveToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Move to Inactive Split View"));
1565 actionCollection()->setDefaultShortcut(moveToOtherViewAction
, Qt::SHIFT
| Qt::Key_F6
);
1566 connect(moveToOtherViewAction
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::moveToInactiveSplitView
);
1568 QAction
* showFilterBar
= actionCollection()->addAction(QStringLiteral("show_filter_bar"));
1569 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Filter..."));
1570 showFilterBar
->setToolTip(i18nc("@info:tooltip", "Show Filter Bar"));
1571 showFilterBar
->setWhatsThis(xi18nc("@info:whatsthis", "This opens the "
1572 "<emphasis>Filter Bar</emphasis> at the bottom of the window.<nl/> "
1573 "There you can enter a text to filter the files and folders currently displayed. "
1574 "Only those that contain the text in their name will be kept in view."));
1575 showFilterBar
->setIcon(QIcon::fromTheme(QStringLiteral("view-filter")));
1576 actionCollection()->setDefaultShortcuts(showFilterBar
, {Qt::CTRL
| Qt::Key_I
, Qt::Key_Slash
});
1577 connect(showFilterBar
, &QAction::triggered
, this, &DolphinMainWindow::showFilterBar
);
1579 // toggle_filter acts as a copy of the main showFilterBar to be used mainly
1580 // in the toolbar, with no default shortcut attached, to avoid messing with
1581 // existing workflows (filter bar always open and Ctrl-I to focus)
1582 QAction
*toggleFilter
= actionCollection()->addAction(QStringLiteral("toggle_filter"));
1583 toggleFilter
->setText(i18nc("@action:inmenu", "Toggle Filter Bar"));
1584 toggleFilter
->setIconText(i18nc("@action:intoolbar", "Filter"));
1585 toggleFilter
->setIcon(showFilterBar
->icon());
1586 toggleFilter
->setToolTip(showFilterBar
->toolTip());
1587 toggleFilter
->setWhatsThis(showFilterBar
->whatsThis());
1588 toggleFilter
->setCheckable(true);
1589 connect(toggleFilter
, &QAction::triggered
, this, &DolphinMainWindow::toggleFilterBar
);
1591 QAction
*searchAction
= KStandardAction::find(this, &DolphinMainWindow::find
, actionCollection());
1592 searchAction
->setText(i18n("Search..."));
1593 searchAction
->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
1594 searchAction
->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This helps you "
1595 "find files and folders by opening a <emphasis>find bar</emphasis>. "
1596 "There you can enter search terms and specify settings to find the "
1597 "objects you are looking for.</para><para>Use this help again on "
1598 "the find bar so we can have a look at it while the settings are "
1599 "explained.</para>"));
1601 // toggle_search acts as a copy of the main searchAction to be used mainly
1602 // in the toolbar, with no default shortcut attached, to avoid messing with
1603 // existing workflows (search bar always open and Ctrl-F to focus)
1604 QAction
*toggleSearchAction
= actionCollection()->addAction(QStringLiteral("toggle_search"));
1605 toggleSearchAction
->setText(i18nc("@action:inmenu", "Toggle Search Bar"));
1606 toggleSearchAction
->setIconText(i18nc("@action:intoolbar", "Search"));
1607 toggleSearchAction
->setIcon(searchAction
->icon());
1608 toggleSearchAction
->setToolTip(searchAction
->toolTip());
1609 toggleSearchAction
->setWhatsThis(searchAction
->whatsThis());
1610 toggleSearchAction
->setCheckable(true);
1612 QAction
* selectAllAction
= KStandardAction::selectAll(this, &DolphinMainWindow::selectAll
, actionCollection());
1613 selectAllAction
->setWhatsThis(xi18nc("@info:whatsthis", "This selects all "
1614 "files and folders in the current location."));
1616 QAction
* invertSelection
= actionCollection()->addAction(QStringLiteral("invert_selection"));
1617 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1618 invertSelection
->setWhatsThis(xi18nc("@info:whatsthis invert", "This selects all "
1619 "objects that you have currently <emphasis>not</emphasis> selected instead."));
1620 invertSelection
->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert")));
1621 actionCollection()->setDefaultShortcut(invertSelection
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1622 connect(invertSelection
, &QAction::triggered
, this, &DolphinMainWindow::invertSelection
);
1624 // setup 'View' menu
1625 // (note that most of it is set up in DolphinViewActionHandler)
1627 QAction
* split
= actionCollection()->addAction(QStringLiteral("split_view"));
1628 split
->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This splits "
1629 "the folder view below into two autonomous views.</para><para>This "
1630 "way you can see two locations at once and move items between them "
1631 "quickly.</para>Click this again afterwards to recombine the views."));
1632 actionCollection()->setDefaultShortcut(split
, Qt::Key_F3
);
1633 connect(split
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitView
);
1635 QAction
* stashSplit
= actionCollection()->addAction(QStringLiteral("split_stash"));
1636 actionCollection()->setDefaultShortcut(stashSplit
, Qt::CTRL
| Qt::Key_S
);
1637 stashSplit
->setText(i18nc("@action:intoolbar Stash", "Stash"));
1638 stashSplit
->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
1639 stashSplit
->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
1640 stashSplit
->setCheckable(false);
1641 QDBusConnectionInterface
*sessionInterface
= QDBusConnection::sessionBus().interface();
1642 stashSplit
->setVisible(sessionInterface
&& sessionInterface
->isServiceRegistered(QStringLiteral("org.kde.kio.StashNotifier")));
1643 connect(stashSplit
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitStash
);
1645 KStandardAction::redisplay(this, &DolphinMainWindow::reloadView
, actionCollection());
1647 QAction
* stop
= actionCollection()->addAction(QStringLiteral("stop"));
1648 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1649 stop
->setToolTip(i18nc("@info", "Stop loading"));
1650 stop
->setWhatsThis(i18nc("@info", "This stops the loading of the contents of the current folder."));
1651 stop
->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
1652 connect(stop
, &QAction::triggered
, this, &DolphinMainWindow::stopLoading
);
1654 KToggleAction
* editableLocation
= actionCollection()->add
<KToggleAction
>(QStringLiteral("editable_location"));
1655 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1656 editableLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1657 "This toggles the <emphasis>Location Bar</emphasis> to be "
1658 "editable so you can directly enter a location you want to go to.<nl/>"
1659 "You can also switch to editing by clicking to the right of the "
1660 "location and switch back by confirming the edited location."));
1661 actionCollection()->setDefaultShortcut(editableLocation
, Qt::Key_F6
);
1662 connect(editableLocation
, &KToggleAction::triggered
, this, &DolphinMainWindow::toggleEditLocation
);
1664 QAction
* replaceLocation
= actionCollection()->addAction(QStringLiteral("replace_location"));
1665 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1666 // i18n: "enter" is used both in the meaning of "writing" and "going to" a new location here.
1667 // Both meanings are useful but not necessary to understand the use of "Replace Location".
1668 // So you might want to be more verbose in your language to convey the meaning but it's up to you.
1669 replaceLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1670 "This switches to editing the location and selects it "
1671 "so you can quickly enter a different location."));
1672 actionCollection()->setDefaultShortcut(replaceLocation
, Qt::CTRL
| Qt::Key_L
);
1673 connect(replaceLocation
, &QAction::triggered
, this, &DolphinMainWindow::replaceLocation
);
1677 QScopedPointer
<QAction
> backAction(KStandardAction::back(nullptr, nullptr, nullptr));
1678 m_backAction
= new KToolBarPopupAction(backAction
->icon(), backAction
->text(), actionCollection());
1679 m_backAction
->setObjectName(backAction
->objectName());
1680 m_backAction
->setShortcuts(backAction
->shortcuts());
1682 m_backAction
->setPopupMode(QToolButton::DelayedPopup
);
1683 connect(m_backAction
, &QAction::triggered
, this, &DolphinMainWindow::goBack
);
1684 connect(m_backAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowBackPopupMenu
);
1685 connect(m_backAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoBack
);
1686 actionCollection()->addAction(m_backAction
->objectName(), m_backAction
);
1688 auto backShortcuts
= m_backAction
->shortcuts();
1689 backShortcuts
.append(QKeySequence(Qt::Key_Backspace
));
1690 actionCollection()->setDefaultShortcuts(m_backAction
, backShortcuts
);
1692 DolphinRecentTabsMenu
* recentTabsMenu
= new DolphinRecentTabsMenu(this);
1693 actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu
);
1694 connect(m_tabWidget
, &DolphinTabWidget::rememberClosedTab
,
1695 recentTabsMenu
, &DolphinRecentTabsMenu::rememberClosedTab
);
1696 connect(recentTabsMenu
, &DolphinRecentTabsMenu::restoreClosedTab
,
1697 m_tabWidget
, &DolphinTabWidget::restoreClosedTab
);
1698 connect(recentTabsMenu
, &DolphinRecentTabsMenu::closedTabsCountChanged
,
1699 this, &DolphinMainWindow::closedTabsCountChanged
);
1701 QAction
* undoCloseTab
= actionCollection()->addAction(QStringLiteral("undo_close_tab"));
1702 undoCloseTab
->setText(i18nc("@action:inmenu File", "Undo close tab"));
1703 undoCloseTab
->setWhatsThis(i18nc("@info:whatsthis undo close tab",
1704 "This returns you to the previously closed tab."));
1705 actionCollection()->setDefaultShortcut(undoCloseTab
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_T
);
1706 undoCloseTab
->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
1707 undoCloseTab
->setEnabled(false);
1708 connect(undoCloseTab
, &QAction::triggered
, recentTabsMenu
, &DolphinRecentTabsMenu::undoCloseTab
);
1710 auto undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
1711 undoAction
->setWhatsThis(xi18nc("@info:whatsthis", "This undoes "
1712 "the last change you made to files or folders.<nl/>"
1713 "Such changes include <interface>creating, renaming</interface> "
1714 "and <interface>moving</interface> them to a different location "
1715 "or to the <filename>Trash</filename>. <nl/>Changes that can't "
1716 "be undone will ask for your confirmation."));
1717 undoAction
->setEnabled(false); // undo should be disabled by default
1720 QScopedPointer
<QAction
> forwardAction(KStandardAction::forward(nullptr, nullptr, nullptr));
1721 m_forwardAction
= new KToolBarPopupAction(forwardAction
->icon(), forwardAction
->text(), actionCollection());
1722 m_forwardAction
->setObjectName(forwardAction
->objectName());
1723 m_forwardAction
->setShortcuts(forwardAction
->shortcuts());
1725 m_forwardAction
->setPopupMode(QToolButton::DelayedPopup
);
1726 connect(m_forwardAction
, &QAction::triggered
, this, &DolphinMainWindow::goForward
);
1727 connect(m_forwardAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowForwardPopupMenu
);
1728 connect(m_forwardAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoForward
);
1729 actionCollection()->addAction(m_forwardAction
->objectName(), m_forwardAction
);
1730 actionCollection()->setDefaultShortcuts(m_forwardAction
, m_forwardAction
->shortcuts());
1732 // enable middle-click to open in a new tab
1733 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
1734 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotBackForwardActionMiddleClicked
);
1735 m_backAction
->menu()->installEventFilter(middleClickEventFilter
);
1736 m_forwardAction
->menu()->installEventFilter(middleClickEventFilter
);
1737 KStandardAction::up(this, &DolphinMainWindow::goUp
, actionCollection());
1738 QAction
* homeAction
= KStandardAction::home(this, &DolphinMainWindow::goHome
, actionCollection());
1739 homeAction
->setWhatsThis(xi18nc("@info:whatsthis", "Go to your "
1740 "<filename>Home</filename> folder.<nl/>Every user account "
1741 "has their own <filename>Home</filename> that contains their data "
1742 "including folders that contain personal application data."));
1744 // setup 'Tools' menu
1745 QAction
* compareFiles
= actionCollection()->addAction(QStringLiteral("compare_files"));
1746 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1747 compareFiles
->setIcon(QIcon::fromTheme(QStringLiteral("kompare")));
1748 compareFiles
->setEnabled(false);
1749 connect(compareFiles
, &QAction::triggered
, this, &DolphinMainWindow::compareFiles
);
1751 QAction
* openPreferredSearchTool
= actionCollection()->addAction(QStringLiteral("open_preferred_search_tool"));
1752 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1753 openPreferredSearchTool
->setWhatsThis(xi18nc("@info:whatsthis",
1754 "<para>This opens a preferred search tool for the viewed location.</para>"
1755 "<para>Use <emphasis>More Search Tools</emphasis> menu to configure it.</para>"));
1756 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1757 actionCollection()->setDefaultShortcut(openPreferredSearchTool
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F
);
1758 connect(openPreferredSearchTool
, &QAction::triggered
, this, &DolphinMainWindow::openPreferredSearchTool
);
1760 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1761 QAction
* openTerminal
= actionCollection()->addAction(QStringLiteral("open_terminal"));
1762 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1763 openTerminal
->setWhatsThis(xi18nc("@info:whatsthis",
1764 "<para>This opens a <emphasis>terminal</emphasis> application for the viewed location.</para>"
1765 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1766 openTerminal
->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
1767 actionCollection()->setDefaultShortcut(openTerminal
, Qt::SHIFT
| Qt::Key_F4
);
1768 connect(openTerminal
, &QAction::triggered
, this, &DolphinMainWindow::openTerminal
);
1770 QAction
* openTerminalHere
= actionCollection()->addAction(QStringLiteral("open_terminal_here"));
1771 // i18n: "Here" refers to the location(s) of the currently selected item(s) or the currently viewed location if nothing is selected.
1772 openTerminalHere
->setText(i18nc("@action:inmenu Tools", "Open Terminal Here"));
1773 openTerminalHere
->setWhatsThis(xi18nc("@info:whatsthis",
1774 "<para>This opens <emphasis>terminal</emphasis> applications for the selected items' locations.</para>"
1775 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1776 openTerminalHere
->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
1777 actionCollection()->setDefaultShortcut(openTerminalHere
, Qt::SHIFT
| Qt::ALT
| Qt::Key_F4
);
1778 connect(openTerminalHere
, &QAction::triggered
, this, &DolphinMainWindow::openTerminalHere
);
1781 QAction
* focusTerminalPanel
= actionCollection()->addAction(QStringLiteral("focus_terminal_panel"));
1782 focusTerminalPanel
->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
1783 focusTerminalPanel
->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
1784 actionCollection()->setDefaultShortcut(focusTerminalPanel
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F4
);
1785 connect(focusTerminalPanel
, &QAction::triggered
, this, &DolphinMainWindow::focusTerminalPanel
);
1789 // setup 'Bookmarks' menu
1790 KActionMenu
*bookmarkMenu
= new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this);
1791 bookmarkMenu
->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks")));
1792 // Make the toolbar button version work properly on click
1793 bookmarkMenu
->setPopupMode(QToolButton::InstantPopup
);
1794 m_bookmarkHandler
= new DolphinBookmarkHandler(this, actionCollection(), bookmarkMenu
->menu(), this);
1795 actionCollection()->addAction(QStringLiteral("bookmarks"), bookmarkMenu
);
1797 // setup 'Settings' menu
1798 KToggleAction
* showMenuBar
= KStandardAction::showMenubar(nullptr, nullptr, actionCollection());
1799 showMenuBar
->setWhatsThis(xi18nc("@info:whatsthis",
1800 "This switches between having a <emphasis>Menubar</emphasis> "
1801 "and having a <interface>Control</interface> button. Both "
1802 "contain mostly the same commands and configuration options."));
1803 connect(showMenuBar
, &KToggleAction::triggered
, // Fixes #286822
1804 this, &DolphinMainWindow::toggleShowMenuBar
, Qt::QueuedConnection
);
1806 KToggleAction
* showStatusBar
= KStandardAction::showStatusbar(nullptr, nullptr, actionCollection());
1807 showStatusBar
->setChecked(GeneralSettings::showStatusBar());
1808 connect(GeneralSettings::self(), &GeneralSettings::showStatusBarChanged
, showStatusBar
, &KToggleAction::setChecked
);
1809 connect(showStatusBar
, &KToggleAction::triggered
, this, [this](bool checked
) {
1810 GeneralSettings::setShowStatusBar(checked
);
1814 KStandardAction::keyBindings(this, &DolphinMainWindow::slotKeyBindings
, actionCollection());
1815 KStandardAction::preferences(this, &DolphinMainWindow::editSettings
, actionCollection());
1817 // setup 'Help' menu for the m_controlButton. The other one is set up in the base class.
1818 m_helpMenu
= new KHelpMenu(nullptr);
1819 m_helpMenu
->menu()->installEventFilter(this);
1820 // remove duplicate shortcuts
1821 auto removeHelpActionShortcut
= [this](KHelpMenu::MenuId menuId
) {
1822 if (auto *action
= m_helpMenu
->action(menuId
)) {
1823 action
->setShortcut(QKeySequence());
1826 removeHelpActionShortcut(KHelpMenu::menuHelpContents
);
1827 removeHelpActionShortcut(KHelpMenu::menuWhatsThis
);
1829 // not in menu actions
1830 QList
<QKeySequence
> nextTabKeys
= KStandardShortcut::tabNext();
1831 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
1833 QList
<QKeySequence
> prevTabKeys
= KStandardShortcut::tabPrev();
1834 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
1836 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1837 QAction
* activateTab
= actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i
));
1838 activateTab
->setText(i18nc("@action:inmenu", "Activate Tab %1", i
+ 1));
1839 activateTab
->setEnabled(false);
1840 connect(activateTab
, &QAction::triggered
, this, [this, i
]() { m_tabWidget
->activateTab(i
); });
1842 // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts
1844 actionCollection()->setDefaultShortcut(activateTab
, QStringLiteral("Alt+%1").arg(i
+ 1));
1848 QAction
* activateLastTab
= actionCollection()->addAction(QStringLiteral("activate_last_tab"));
1849 activateLastTab
->setText(i18nc("@action:inmenu", "Activate Last Tab"));
1850 activateLastTab
->setEnabled(false);
1851 connect(activateLastTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateLastTab
);
1852 actionCollection()->setDefaultShortcut(activateLastTab
, Qt::ALT
| Qt::Key_0
);
1854 QAction
* activateNextTab
= actionCollection()->addAction(QStringLiteral("activate_next_tab"));
1855 activateNextTab
->setIconText(i18nc("@action:inmenu", "Next Tab"));
1856 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1857 activateNextTab
->setEnabled(false);
1858 connect(activateNextTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateNextTab
);
1859 actionCollection()->setDefaultShortcuts(activateNextTab
, nextTabKeys
);
1861 QAction
* activatePrevTab
= actionCollection()->addAction(QStringLiteral("activate_prev_tab"));
1862 activatePrevTab
->setIconText(i18nc("@action:inmenu", "Previous Tab"));
1863 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1864 activatePrevTab
->setEnabled(false);
1865 connect(activatePrevTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activatePrevTab
);
1866 actionCollection()->setDefaultShortcuts(activatePrevTab
, prevTabKeys
);
1869 QAction
* showTarget
= actionCollection()->addAction(QStringLiteral("show_target"));
1870 showTarget
->setText(i18nc("@action:inmenu", "Show Target"));
1871 showTarget
->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
1872 showTarget
->setEnabled(false);
1873 connect(showTarget
, &QAction::triggered
, this, &DolphinMainWindow::showTarget
);
1875 QAction
* openInNewTab
= actionCollection()->addAction(QStringLiteral("open_in_new_tab"));
1876 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1877 openInNewTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1878 connect(openInNewTab
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
1880 QAction
* openInNewTabs
= actionCollection()->addAction(QStringLiteral("open_in_new_tabs"));
1881 openInNewTabs
->setText(i18nc("@action:inmenu", "Open in New Tabs"));
1882 openInNewTabs
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1883 connect(openInNewTabs
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
1885 QAction
* openInNewWindow
= actionCollection()->addAction(QStringLiteral("open_in_new_window"));
1886 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1887 openInNewWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1888 connect(openInNewWindow
, &QAction::triggered
, this, &DolphinMainWindow::openInNewWindow
);
1891 void DolphinMainWindow::setupDockWidgets()
1893 const bool lock
= GeneralSettings::lockPanels();
1895 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(lock
);
1897 KDualAction
* lockLayoutAction
= actionCollection()->add
<KDualAction
>(QStringLiteral("lock_panels"));
1898 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1899 lockLayoutAction
->setActiveIcon(QIcon::fromTheme(QStringLiteral("object-unlocked")));
1900 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1901 lockLayoutAction
->setInactiveIcon(QIcon::fromTheme(QStringLiteral("object-locked")));
1902 lockLayoutAction
->setWhatsThis(xi18nc("@info:whatsthis", "This "
1903 "switches between having panels <emphasis>locked</emphasis> or "
1904 "<emphasis>unlocked</emphasis>.<nl/>Unlocked panels can be "
1905 "dragged to the other side of the window and have a close "
1906 "button.<nl/>Locked panels are embedded more cleanly."));
1907 lockLayoutAction
->setActive(lock
);
1908 connect(lockLayoutAction
, &KDualAction::triggered
, this, &DolphinMainWindow::togglePanelLockState
);
1910 // Setup "Information"
1911 DolphinDockWidget
* infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
1912 infoDock
->setLocked(lock
);
1913 infoDock
->setObjectName(QStringLiteral("infoDock"));
1914 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1917 InformationPanel
* infoPanel
= new InformationPanel(infoDock
);
1918 infoPanel
->setCustomContextMenuActions({lockLayoutAction
});
1919 connect(infoPanel
, &InformationPanel::urlActivated
, this, &DolphinMainWindow::handleUrl
);
1920 infoDock
->setWidget(infoPanel
);
1922 QAction
* infoAction
= infoDock
->toggleViewAction();
1923 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-information")), Qt::Key_F11
, infoAction
, QStringLiteral("show_information_panel"));
1925 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1926 connect(this, &DolphinMainWindow::urlChanged
,
1927 infoPanel
, &InformationPanel::setUrl
);
1928 connect(this, &DolphinMainWindow::selectionChanged
,
1929 infoPanel
, &InformationPanel::setSelection
);
1930 connect(this, &DolphinMainWindow::requestItemInfo
,
1931 infoPanel
, &InformationPanel::requestDelayedItemInfo
);
1932 connect(this, &DolphinMainWindow::fileItemsChanged
,
1933 infoPanel
, &InformationPanel::slotFilesItemChanged
);
1936 // i18n: This is the last paragraph for the "What's This"-texts of all four panels.
1937 const QString panelWhatsThis
= xi18nc("@info:whatsthis", "<para>To show or "
1938 "hide panels like this go to <interface>Control|Panels</interface> "
1939 "or <interface>View|Panels</interface>.</para>");
1941 actionCollection()->action(QStringLiteral("show_information_panel"))
1942 ->setWhatsThis(xi18nc("@info:whatsthis", "<para> This toggles the "
1943 "<emphasis>information</emphasis> panel at the right side of the "
1944 "window.</para><para>The panel provides in-depth information "
1945 "about the items your mouse is hovering over or about the selected "
1946 "items. Otherwise it informs you about the currently viewed folder.<nl/>"
1947 "For single items a preview of their contents is provided.</para>"));
1949 infoDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
1950 "provides in-depth information about the items your mouse is "
1951 "hovering over or about the selected items. Otherwise it informs "
1952 "you about the currently viewed folder.<nl/>For single items a "
1953 "preview of their contents is provided.</para><para>You can configure "
1954 "which and how details are given here by right-clicking.</para>") + panelWhatsThis
);
1957 DolphinDockWidget
* foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
1958 foldersDock
->setLocked(lock
);
1959 foldersDock
->setObjectName(QStringLiteral("foldersDock"));
1960 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1961 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1962 foldersPanel
->setCustomContextMenuActions({lockLayoutAction
});
1963 foldersDock
->setWidget(foldersPanel
);
1965 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1966 createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7
, foldersAction
, QStringLiteral("show_folders_panel"));
1968 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1969 connect(this, &DolphinMainWindow::urlChanged
,
1970 foldersPanel
, &FoldersPanel::setUrl
);
1971 connect(foldersPanel
, &FoldersPanel::folderActivated
,
1972 this, &DolphinMainWindow::changeUrl
);
1973 connect(foldersPanel
, &FoldersPanel::folderInNewTab
,
1974 this, &DolphinMainWindow::openNewTab
);
1975 connect(foldersPanel
, &FoldersPanel::folderInNewActiveTab
,
1976 this, &DolphinMainWindow::openNewTabAndActivate
);
1977 connect(foldersPanel
, &FoldersPanel::errorMessage
,
1978 this, &DolphinMainWindow::showErrorMessage
);
1980 actionCollection()->action(QStringLiteral("show_folders_panel"))
1981 ->setWhatsThis(xi18nc("@info:whatsthis", "This toggles the "
1982 "<emphasis>folders</emphasis> panel at the left side of the window."
1983 "<nl/><nl/>It shows the folders of the <emphasis>file system"
1984 "</emphasis> in a <emphasis>tree view</emphasis>."));
1985 foldersDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
1986 "shows the folders of the <emphasis>file system</emphasis> in a "
1987 "<emphasis>tree view</emphasis>.</para><para>Click a folder to go "
1988 "there. Click the arrow to the left of a folder to see its subfolders. "
1989 "This allows quick switching between any folders.</para>") + panelWhatsThis
);
1993 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1994 DolphinDockWidget
* terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1995 terminalDock
->setLocked(lock
);
1996 terminalDock
->setObjectName(QStringLiteral("terminalDock"));
1997 m_terminalPanel
= new TerminalPanel(terminalDock
);
1998 m_terminalPanel
->setCustomContextMenuActions({lockLayoutAction
});
1999 terminalDock
->setWidget(m_terminalPanel
);
2001 connect(m_terminalPanel
, &TerminalPanel::hideTerminalPanel
, terminalDock
, &DolphinDockWidget::hide
);
2002 connect(m_terminalPanel
, &TerminalPanel::changeUrl
, this, &DolphinMainWindow::slotTerminalDirectoryChanged
);
2003 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
,
2004 m_terminalPanel
, &TerminalPanel::dockVisibilityChanged
);
2005 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
,
2006 this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged
);
2008 QAction
* terminalAction
= terminalDock
->toggleViewAction();
2009 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4
, terminalAction
, QStringLiteral("show_terminal_panel"));
2011 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
2012 connect(this, &DolphinMainWindow::urlChanged
,
2013 m_terminalPanel
, &TerminalPanel::setUrl
);
2015 if (GeneralSettings::version() < 200) {
2016 terminalDock
->hide();
2019 actionCollection()->action(QStringLiteral("show_terminal_panel"))
2020 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
2021 "<emphasis>terminal</emphasis> panel at the bottom of the window."
2022 "<nl/>The location in the terminal will always match the folder "
2023 "view so you can navigate using either.</para><para>The terminal "
2024 "panel is not needed for basic computer usage but can be useful "
2025 "for advanced tasks. To learn more about terminals use the help "
2026 "in a standalone terminal application like Konsole.</para>"));
2027 terminalDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is "
2028 "the <emphasis>terminal</emphasis> panel. It behaves like a "
2029 "normal terminal but will match the location of the folder view "
2030 "so you can navigate using either.</para><para>The terminal panel "
2031 "is not needed for basic computer usage but can be useful for "
2032 "advanced tasks. To learn more about terminals use the help in a "
2033 "standalone terminal application like Konsole.</para>") + panelWhatsThis
);
2037 if (GeneralSettings::version() < 200) {
2039 foldersDock
->hide();
2043 DolphinDockWidget
* placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
2044 placesDock
->setLocked(lock
);
2045 placesDock
->setObjectName(QStringLiteral("placesDock"));
2046 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2048 m_placesPanel
= new PlacesPanel(placesDock
);
2049 m_placesPanel
->setCustomContextMenuActions({lockLayoutAction
});
2050 placesDock
->setWidget(m_placesPanel
);
2052 QAction
*placesAction
= placesDock
->toggleViewAction();
2053 createPanelAction(QIcon::fromTheme(QStringLiteral("compass")), Qt::Key_F9
, placesAction
, QStringLiteral("show_places_panel"));
2055 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
2056 connect(m_placesPanel
, &PlacesPanel::placeActivated
,
2057 this, &DolphinMainWindow::slotPlaceActivated
);
2058 connect(m_placesPanel
, &PlacesPanel::tabRequested
,
2059 this, &DolphinMainWindow::openNewTab
);
2060 connect(m_placesPanel
, &PlacesPanel::activeTabRequested
,
2061 this, &DolphinMainWindow::openNewTabAndActivate
);
2062 connect(m_placesPanel
, &PlacesPanel::newWindowRequested
, this, [this](const QUrl
&url
) {
2063 Dolphin::openNewWindow({url
}, this);
2065 connect(m_placesPanel
, &PlacesPanel::errorMessage
,
2066 this, &DolphinMainWindow::showErrorMessage
);
2067 connect(this, &DolphinMainWindow::urlChanged
,
2068 m_placesPanel
, &PlacesPanel::setUrl
);
2069 connect(placesDock
, &DolphinDockWidget::visibilityChanged
,
2070 &DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged
);
2071 connect(this, &DolphinMainWindow::settingsChanged
,
2072 m_placesPanel
, &PlacesPanel::readSettings
);
2073 connect(m_placesPanel
, &PlacesPanel::storageTearDownRequested
,
2074 this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested
);
2075 connect(m_placesPanel
, &PlacesPanel::storageTearDownExternallyRequested
,
2076 this, &DolphinMainWindow::slotStorageTearDownExternallyRequested
);
2077 DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged(m_placesPanel
->isVisible());
2079 auto actionShowAllPlaces
= new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this);
2080 actionShowAllPlaces
->setCheckable(true);
2081 actionShowAllPlaces
->setDisabled(true);
2082 actionShowAllPlaces
->setWhatsThis(i18nc("@info:whatsthis", "This displays "
2083 "all places in the places panel that have been hidden. They will "
2084 "appear semi-transparent unless you uncheck their hide property."));
2086 connect(actionShowAllPlaces
, &QAction::triggered
, this, [actionShowAllPlaces
, this](bool checked
){
2087 m_placesPanel
->setShowAll(checked
);
2089 connect(m_placesPanel
, &PlacesPanel::allPlacesShownChanged
, actionShowAllPlaces
, &QAction::setChecked
);
2091 actionCollection()->action(QStringLiteral("show_places_panel"))
2092 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
2093 "<emphasis>places</emphasis> panel at the left side of the window."
2094 "</para><para>It allows you to go to locations you have "
2095 "bookmarked and to access disk or media attached to the computer "
2096 "or to the network. It also contains sections to find recently "
2097 "saved files or files of a certain type.</para>"));
2098 placesDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2099 "<emphasis>Places</emphasis> panel. It allows you to go to locations "
2100 "you have bookmarked and to access disk or media attached to the "
2101 "computer or to the network. It also contains sections to find "
2102 "recently saved files or files of a certain type.</para><para>"
2103 "Click on an entry to go there. Click with the right mouse button "
2104 "instead to open any entry in a new tab or new window.</para>"
2105 "<para>New entries can be added by dragging folders onto this panel. "
2106 "Right-click any section or entry to hide it. Right-click an empty "
2107 "space on this panel and select <interface>Show Hidden Places"
2108 "</interface> to display it again.</para>") + panelWhatsThis
);
2110 // Add actions into the "Panels" menu
2111 KActionMenu
* panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Show Panels"), this);
2112 actionCollection()->addAction(QStringLiteral("panels"), panelsMenu
);
2113 panelsMenu
->setIcon(QIcon::fromTheme(QStringLiteral("view-sidetree")));
2114 panelsMenu
->setPopupMode(QToolButton::InstantPopup
);
2115 const KActionCollection
* ac
= actionCollection();
2116 panelsMenu
->addAction(ac
->action(QStringLiteral("show_places_panel")));
2118 panelsMenu
->addAction(ac
->action(QStringLiteral("show_information_panel")));
2120 panelsMenu
->addAction(ac
->action(QStringLiteral("show_folders_panel")));
2121 panelsMenu
->addAction(ac
->action(QStringLiteral("show_terminal_panel")));
2122 panelsMenu
->addSeparator();
2123 panelsMenu
->addAction(actionShowAllPlaces
);
2124 panelsMenu
->addAction(lockLayoutAction
);
2126 connect(panelsMenu
->menu(), &QMenu::aboutToShow
, this, [actionShowAllPlaces
, this]{
2127 actionShowAllPlaces
->setEnabled(DolphinPlacesModelSingleton::instance().placesModel()->hiddenCount());
2132 void DolphinMainWindow::updateFileAndEditActions()
2134 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
2135 const KActionCollection
* col
= actionCollection();
2136 KFileItemListProperties
capabilitiesSource(list
);
2138 QAction
* addToPlacesAction
= col
->action(QStringLiteral("add_to_places"));
2139 QAction
* copyToOtherViewAction
= col
->action(QStringLiteral("copy_to_inactive_split_view"));
2140 QAction
* moveToOtherViewAction
= col
->action(QStringLiteral("move_to_inactive_split_view"));
2141 QAction
* copyLocation
= col
->action(QString("copy_location"));
2143 if (list
.isEmpty()) {
2144 stateChanged(QStringLiteral("has_no_selection"));
2146 addToPlacesAction
->setEnabled(true);
2147 copyToOtherViewAction
->setEnabled(false);
2148 moveToOtherViewAction
->setEnabled(false);
2149 copyLocation
->setEnabled(false);
2151 stateChanged(QStringLiteral("has_selection"));
2153 QAction
* renameAction
= col
->action(KStandardAction::name(KStandardAction::RenameFile
));
2154 QAction
* moveToTrashAction
= col
->action(KStandardAction::name(KStandardAction::MoveToTrash
));
2155 QAction
* deleteAction
= col
->action(KStandardAction::name(KStandardAction::DeleteFile
));
2156 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
2157 QAction
* deleteWithTrashShortcut
= col
->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
2158 QAction
* showTarget
= col
->action(QStringLiteral("show_target"));
2159 QAction
* duplicateAction
= col
->action(QStringLiteral("duplicate")); // see DolphinViewActionHandler
2161 if (list
.length() == 1 && list
.first().isDir()) {
2162 addToPlacesAction
->setEnabled(true);
2164 addToPlacesAction
->setEnabled(false);
2167 if (m_tabWidget
->currentTabPage()->splitViewEnabled()) {
2168 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
2169 KFileItem capabilitiesDestination
;
2171 if (tabPage
->primaryViewActive()) {
2172 capabilitiesDestination
= tabPage
->secondaryViewContainer()->url();
2174 capabilitiesDestination
= tabPage
->primaryViewContainer()->url();
2177 copyToOtherViewAction
->setEnabled(capabilitiesDestination
.isWritable());
2178 moveToOtherViewAction
->setEnabled(capabilitiesSource
.supportsMoving() && capabilitiesDestination
.isWritable());
2180 copyToOtherViewAction
->setEnabled(false);
2181 moveToOtherViewAction
->setEnabled(false);
2184 const bool enableMoveToTrash
= capabilitiesSource
.isLocal() && capabilitiesSource
.supportsMoving();
2186 renameAction
->setEnabled(capabilitiesSource
.supportsMoving());
2187 moveToTrashAction
->setEnabled(enableMoveToTrash
);
2188 deleteAction
->setEnabled(capabilitiesSource
.supportsDeleting());
2189 deleteWithTrashShortcut
->setEnabled(capabilitiesSource
.supportsDeleting() && !enableMoveToTrash
);
2190 cutAction
->setEnabled(capabilitiesSource
.supportsMoving());
2191 copyLocation
->setEnabled(list
.length() == 1);
2192 showTarget
->setEnabled(list
.length() == 1 && list
.at(0).isLink());
2193 duplicateAction
->setEnabled(capabilitiesSource
.supportsWriting());
2197 void DolphinMainWindow::updateViewActions()
2199 m_actionHandler
->updateViewActions();
2201 QAction
* toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
2202 toggleFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
2204 updateSplitAction();
2207 void DolphinMainWindow::updateGoActions()
2209 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
2210 const QUrl currentUrl
= m_activeViewContainer
->url();
2211 // I think this is one of the best places to firstly be confronted
2212 // with a file system and its hierarchy. Talking about the root
2213 // directory might seem too much here but it is the question that
2214 // naturally arises in this context.
2215 goUpAction
->setWhatsThis(xi18nc("@info:whatsthis", "<para>Go to "
2216 "the folder that contains the currently viewed one.</para>"
2217 "<para>All files and folders are organized in a hierarchical "
2218 "<emphasis>file system</emphasis>. At the top of this hierarchy is "
2219 "a directory that contains all data connected to this computer"
2220 "—the <emphasis>root directory</emphasis>.</para>"));
2221 goUpAction
->setEnabled(KIO::upUrl(currentUrl
) != currentUrl
);
2224 void DolphinMainWindow::refreshViews()
2226 m_tabWidget
->refreshViews();
2228 if (GeneralSettings::modifiedStartupSettings()) {
2229 updateWindowTitle();
2232 Q_EMIT
settingsChanged();
2235 void DolphinMainWindow::clearStatusBar()
2237 m_activeViewContainer
->statusBar()->resetToDefaultText();
2240 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
2242 connect(container
, &DolphinViewContainer::showFilterBarChanged
,
2243 this, &DolphinMainWindow::updateFilterBarAction
);
2244 connect(container
, &DolphinViewContainer::writeStateChanged
,
2245 this, &DolphinMainWindow::slotWriteStateChanged
);
2246 connect(container
, &DolphinViewContainer::searchModeEnabledChanged
,
2247 this, &DolphinMainWindow::updateSearchAction
);
2248 connect(container
, &DolphinViewContainer::captionChanged
,
2249 this, &DolphinMainWindow::updateWindowTitle
);
2250 connect(container
, &DolphinViewContainer::tabRequested
,
2251 this, &DolphinMainWindow::openNewTab
);
2252 connect(container
, &DolphinViewContainer::activeTabRequested
,
2253 this, &DolphinMainWindow::openNewTabAndActivate
);
2255 const QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
2256 connect(toggleSearchAction
, &QAction::triggered
, container
, &DolphinViewContainer::setSearchModeEnabled
);
2258 const DolphinView
* view
= container
->view();
2259 connect(view
, &DolphinView::selectionChanged
,
2260 this, &DolphinMainWindow::slotSelectionChanged
);
2261 connect(view
, &DolphinView::requestItemInfo
,
2262 this, &DolphinMainWindow::requestItemInfo
);
2263 connect(view
, &DolphinView::fileItemsChanged
,
2264 this, &DolphinMainWindow::fileItemsChanged
);
2265 connect(view
, &DolphinView::tabRequested
,
2266 this, &DolphinMainWindow::openNewTab
);
2267 connect(view
, &DolphinView::activeTabRequested
,
2268 this, &DolphinMainWindow::openNewTabAndActivate
);
2269 connect(view
, &DolphinView::windowRequested
,
2270 this, &DolphinMainWindow::openNewWindow
);
2271 connect(view
, &DolphinView::requestContextMenu
,
2272 this, &DolphinMainWindow::openContextMenu
);
2273 connect(view
, &DolphinView::directoryLoadingStarted
,
2274 this, &DolphinMainWindow::enableStopAction
);
2275 connect(view
, &DolphinView::directoryLoadingCompleted
,
2276 this, &DolphinMainWindow::disableStopAction
);
2277 connect(view
, &DolphinView::directoryLoadingCompleted
,
2278 this, &DolphinMainWindow::slotDirectoryLoadingCompleted
);
2279 connect(view
, &DolphinView::goBackRequested
,
2280 this, &DolphinMainWindow::goBack
);
2281 connect(view
, &DolphinView::goForwardRequested
,
2282 this, &DolphinMainWindow::goForward
);
2283 connect(view
, &DolphinView::urlActivated
,
2284 this, &DolphinMainWindow::handleUrl
);
2285 connect(view
, &DolphinView::goUpRequested
,
2286 this, &DolphinMainWindow::goUp
);
2288 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::urlChanged
,
2289 this, &DolphinMainWindow::changeUrl
);
2290 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::historyChanged
,
2291 this, &DolphinMainWindow::updateHistory
);
2293 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
2294 (actionCollection()->action(QStringLiteral("url_navigators")));
2295 const KUrlNavigator
*navigator
= m_tabWidget
->currentTabPage()->primaryViewActive() ?
2296 navigators
->primaryUrlNavigator() :
2297 navigators
->secondaryUrlNavigator();
2299 QAction
*editableLocactionAction
= actionCollection()->action(QStringLiteral("editable_location"));
2300 editableLocactionAction
->setChecked(navigator
->isUrlEditable());
2301 connect(navigator
, &KUrlNavigator::editableStateChanged
,
2302 this, &DolphinMainWindow::slotEditableStateChanged
);
2303 connect(navigator
, &KUrlNavigator::tabRequested
,
2304 this, &DolphinMainWindow::openNewTab
);
2305 connect(navigator
, &KUrlNavigator::activeTabRequested
,
2306 this, &DolphinMainWindow::openNewTabAndActivate
);
2307 connect(navigator
, &KUrlNavigator::newWindowRequested
,
2308 this, &DolphinMainWindow::openNewWindow
);
2312 void DolphinMainWindow::updateSplitAction()
2314 QAction
* splitAction
= actionCollection()->action(QStringLiteral("split_view"));
2315 const DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
2316 if (tabPage
->splitViewEnabled()) {
2317 if (GeneralSettings::closeActiveSplitView() ? tabPage
->primaryViewActive() : !tabPage
->primaryViewActive()) {
2318 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2319 splitAction
->setToolTip(i18nc("@info", "Close left view"));
2320 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close")));
2322 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2323 splitAction
->setToolTip(i18nc("@info", "Close right view"));
2324 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close")));
2327 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2328 splitAction
->setToolTip(i18nc("@info", "Split view"));
2329 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2333 void DolphinMainWindow::updateAllowedToolbarAreas()
2335 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
2336 (actionCollection()->action(QStringLiteral("url_navigators")));
2337 if (toolBar()->actions().contains(navigators
)) {
2338 toolBar()->setAllowedAreas(Qt::TopToolBarArea
| Qt::BottomToolBarArea
);
2339 if (toolBarArea(toolBar()) == Qt::LeftToolBarArea
||
2340 toolBarArea(toolBar()) == Qt::RightToolBarArea
) {
2341 addToolBar(Qt::TopToolBarArea
, toolBar());
2344 toolBar()->setAllowedAreas(Qt::AllToolBarAreas
);
2348 bool DolphinMainWindow::isKompareInstalled() const
2350 static bool initialized
= false;
2351 static bool installed
= false;
2353 // TODO: maybe replace this approach later by using a menu
2354 // plugin like kdiff3plugin.cpp
2355 installed
= !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty();
2361 void DolphinMainWindow::createPanelAction(const QIcon
& icon
,
2362 const QKeySequence
& shortcut
,
2363 QAction
* dockAction
,
2364 const QString
& actionName
)
2366 QAction
* panelAction
= actionCollection()->addAction(actionName
);
2367 panelAction
->setCheckable(true);
2368 panelAction
->setChecked(dockAction
->isChecked());
2369 panelAction
->setText(dockAction
->text());
2370 panelAction
->setIcon(icon
);
2371 dockAction
->setIcon(icon
);
2372 actionCollection()->setDefaultShortcut(panelAction
, shortcut
);
2374 connect(panelAction
, &QAction::triggered
, dockAction
, &QAction::trigger
);
2375 connect(dockAction
, &QAction::toggled
, panelAction
, &QAction::setChecked
);
2378 void DolphinMainWindow::setupWhatsThis()
2381 menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2382 "<emphasis>Menubar</emphasis>. It provides access to commands and "
2383 "configuration options. Left-click on any of the menus on this "
2384 "bar to see its contents.</para><para>The Menubar can be hidden "
2385 "by unchecking <interface>Settings|Show Menubar</interface>. Then "
2386 "most of its contents become available through a <interface>Control"
2387 "</interface> button on the <emphasis>Toolbar</emphasis>.</para>"));
2388 toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2389 "<emphasis>Toolbar</emphasis>. It allows quick access to "
2390 "frequently used actions.</para><para>It is highly customizable. "
2391 "All items you see in the <interface>Control</interface> menu or "
2392 "in the <interface>Menubar</interface> can be placed on the "
2393 "Toolbar. Just right-click on it and select <interface>Configure "
2394 "Toolbars…</interface> or find this action in the <interface>"
2395 "Control</interface> or <interface>Settings</interface> menu."
2396 "</para><para>The location of the bar and the style of its "
2397 "buttons can also be changed in the right-click menu. Right-click "
2398 "a button if you want to show or hide its text.</para>"));
2399 m_tabWidget
->setWhatsThis(xi18nc("@info:whatsthis main view",
2400 "<para>Here you can see the <emphasis>folders</emphasis> and "
2401 "<emphasis>files</emphasis> that are at the location described in "
2402 "the <interface>Location Bar</interface> above. This area is the "
2403 "central part of this application where you navigate to the files "
2404 "you want to use.</para><para>For an elaborate and general "
2405 "introduction to this application <link "
2406 "url='https://userbase.kde.org/Dolphin/File_Management#Introduction_to_Dolphin'>"
2407 "click here</link>. This will open an introductory article from "
2408 "the <emphasis>KDE UserBase Wiki</emphasis>.</para><para>For brief "
2409 "explanations of all the features of this <emphasis>view</emphasis> "
2410 "<link url='help:/dolphin/dolphin-view.html'>click here</link> "
2411 "instead. This will open a page from the <emphasis>Handbook"
2412 "</emphasis> that covers the basics.</para>"));
2415 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings
))
2416 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window "
2417 "that lists the <emphasis>keyboard shortcuts</emphasis>.<nl/>"
2418 "There you can set up key combinations to trigger an action when "
2419 "they are pressed simultaneously. All commands in this application can "
2420 "be triggered this way.</para>"));
2421 actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars
))
2422 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window in which "
2423 "you can change which buttons appear on the <emphasis>Toolbar</emphasis>.</para>"
2424 "<para>All items you see in the <interface>Control</interface> menu "
2425 "or in the <interface>Menubar</interface> can also be placed on the Toolbar.</para>"));
2426 actionCollection()->action(KStandardAction::name(KStandardAction::Preferences
))
2427 ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can "
2428 "change a multitude of settings for this application. For an explanation "
2429 "of the various settings go to the chapter <emphasis>Configuring Dolphin"
2430 "</emphasis> in <interface>Help|Dolphin Handbook</interface>."));
2433 // The whatsthis has to be set for the m_helpMenu and for the
2434 // StandardAction separately because both are used in different locations.
2435 // m_helpMenu is only used for createControlButton() button.
2437 auto setStandardActionWhatsThis
= [this](KStandardAction::StandardAction actionId
,
2438 const QString
&whatsThis
) {
2439 if (auto *action
= actionCollection()->action(KStandardAction::name(actionId
))) {
2440 action
->setWhatsThis(whatsThis
);
2443 auto setHelpActionWhatsThis
= [this](KHelpMenu::MenuId menuId
, const QString
&whatsThis
) {
2444 if (auto *action
= m_helpMenu
->action(menuId
)) {
2445 action
->setWhatsThis(whatsThis
);
2449 // Links do not work within the Menubar so texts without links are provided there.
2451 // i18n: If the external link isn't available in your language you should
2452 // probably state the external link language at least in brackets to not
2453 // frustrate the user. If there are multiple languages that the user might
2454 // know with a reasonable chance you might want to have 2 external links.
2455 // The same is in my opinion true for every external link you translate.
2456 const QString whatsThisHelpContents
= xi18nc("@info:whatsthis handbook",
2457 "<para>This opens the Handbook for this application. It provides "
2458 "explanations for every part of <emphasis>Dolphin</emphasis>.</para>");
2459 setStandardActionWhatsThis(KStandardAction::HelpContents
, whatsThisHelpContents
2460 + xi18nc("@info:whatsthis second half of handbook hb text without link",
2461 "<para>If you want more elaborate introductions to the "
2462 "different features of <emphasis>Dolphin</emphasis> "
2463 "go to the KDE UserBase Wiki.</para>"));
2464 setHelpActionWhatsThis(KHelpMenu::menuHelpContents
, whatsThisHelpContents
2465 + xi18nc("@info:whatsthis second half of handbook text with link",
2466 "<para>If you want more elaborate introductions to the "
2467 "different features of <emphasis>Dolphin</emphasis> "
2468 "<link url='https://userbase.kde.org/Dolphin/File_Management'>click here</link>. "
2469 "It will open the dedicated page in the KDE UserBase Wiki.</para>"));
2471 const QString whatsThisWhatsThis
= xi18nc("@info:whatsthis whatsthis button",
2472 "<para>This is the button that invokes the help feature you are "
2473 "using right now! Click it, then click any component of this "
2474 "application to ask \"What's this?\" about it. The mouse cursor "
2475 "will change appearance if no help is available for a spot.</para>");
2476 setStandardActionWhatsThis(KStandardAction::WhatsThis
, whatsThisWhatsThis
2477 + xi18nc("@info:whatsthis second half of whatsthis button text without link",
2478 "<para>There are two other ways to get help for this application: The "
2479 "<interface>Dolphin Handbook</interface> in the <interface>Help"
2480 "</interface> menu and the <emphasis>KDE UserBase Wiki</emphasis> "
2481 "article about <emphasis>File Management</emphasis> online."
2482 "</para><para>The \"What's this?\" help is "
2483 "missing in most other windows so don't get too used to this.</para>"));
2484 setHelpActionWhatsThis(KHelpMenu::menuWhatsThis
, whatsThisWhatsThis
2485 + xi18nc("@info:whatsthis second half of whatsthis button text with link",
2486 "<para>There are two other ways to get help: "
2487 "The <link url='help:/dolphin/index.html'>Dolphin Handbook</link> and "
2488 "the <link url='https://userbase.kde.org/Dolphin/File_Management'>KDE "
2489 "UserBase Wiki</link>.</para><para>The \"What's this?\" help is "
2490 "missing in most other windows so don't get too used to this.</para>"));
2492 const QString whatsThisReportBug
= xi18nc("@info:whatsthis","<para>This opens a "
2493 "window that will guide you through reporting errors or flaws "
2494 "in this application or in other KDE software.</para>");
2495 setStandardActionWhatsThis(KStandardAction::ReportBug
, whatsThisReportBug
);
2496 setHelpActionWhatsThis(KHelpMenu::menuReportBug
, whatsThisReportBug
2497 + xi18nc("@info:whatsthis second half of reportbug text with link",
2498 "<para>High-quality bug reports are much appreciated. To learn "
2499 "how to make your bug report as effective as possible "
2500 "<link url='https://community.kde.org/Get_Involved/Bug_Reporting'>"
2501 "click here</link>.</para>"));
2503 const QString whatsThisDonate
= xi18nc("@info:whatsthis","<para>This opens a "
2504 "<emphasis>web page</emphasis> where you can donate to "
2505 "support the continued work on this application and many "
2506 "other projects by the <emphasis>KDE</emphasis> community.</para>"
2507 "<para>Donating is the easiest and fastest way to efficiently "
2508 "support KDE and its projects. KDE projects are available for "
2509 "free therefore your donation is needed to cover things that "
2510 "require money like servers, contributor meetings, etc.</para>"
2511 "<para><emphasis>KDE e.V.</emphasis> is the non-profit "
2512 "organization behind the KDE community.</para>");
2513 setStandardActionWhatsThis(KStandardAction::Donate
, whatsThisDonate
);
2514 setHelpActionWhatsThis(KHelpMenu::menuDonate
, whatsThisDonate
);
2516 const QString whatsThisSwitchLanguage
= xi18nc("@info:whatsthis",
2517 "With this you can change the language this application uses."
2518 "<nl/>You can even set secondary languages which will be used "
2519 "if texts are not available in your preferred language.");
2520 setStandardActionWhatsThis(KStandardAction::SwitchApplicationLanguage
,
2521 whatsThisSwitchLanguage
);
2522 setHelpActionWhatsThis(KHelpMenu::menuSwitchLanguage
, whatsThisSwitchLanguage
);
2524 const QString whatsThisAboutApp
= xi18nc("@info:whatsthis","This opens a "
2525 "window that informs you about the version, license, "
2526 "used libraries and maintainers of this application.");
2527 setStandardActionWhatsThis(KStandardAction::AboutApp
, whatsThisAboutApp
);
2528 setHelpActionWhatsThis(KHelpMenu::menuAboutApp
, whatsThisAboutApp
);
2530 const QString whatsThisAboutKDE
= xi18nc("@info:whatsthis","This opens a "
2531 "window with information about <emphasis>KDE</emphasis>. "
2532 "The KDE community are the people behind this free software."
2533 "<nl/>If you like using this application but don't know "
2534 "about KDE or want to see a cute dragon have a look!");
2535 setStandardActionWhatsThis(KStandardAction::AboutKDE
, whatsThisAboutKDE
);
2536 setHelpActionWhatsThis(KHelpMenu::menuAboutKDE
, whatsThisAboutKDE
);
2539 bool DolphinMainWindow::addHamburgerMenuToToolbar()
2541 QDomDocument domDocument
= KXMLGUIClient::domDocument();
2542 if (domDocument
.isNull()) {
2545 QDomNode toolbar
= domDocument
.elementsByTagName(QStringLiteral("ToolBar")).at(0);
2546 if (toolbar
.isNull()) {
2550 QDomElement hamburgerMenuElement
= domDocument
.createElement(QStringLiteral("Action"));
2551 hamburgerMenuElement
.setAttribute(QStringLiteral("name"), QStringLiteral("hamburger_menu"));
2552 toolbar
.appendChild(hamburgerMenuElement
);
2554 KXMLGUIFactory::saveConfigFile(domDocument
, xmlFile());
2558 // Make sure to also remove the <KXMLGUIFactory> and <QDomDocument> include
2559 // whenever this method is removed (maybe in the year ~2026).
2562 bool DolphinMainWindow::event(QEvent
*event
)
2564 if (event
->type() == QEvent::WhatsThisClicked
) {
2566 QWhatsThisClickedEvent
* whatsThisEvent
= dynamic_cast<QWhatsThisClickedEvent
*>(event
);
2567 QDesktopServices::openUrl(QUrl(whatsThisEvent
->href()));
2570 return KXmlGuiWindow::event(event
);
2573 bool DolphinMainWindow::eventFilter(QObject
* obj
, QEvent
* event
)
2576 if (event
->type() == QEvent::WhatsThisClicked
) {
2578 QWhatsThisClickedEvent
* whatsThisEvent
= dynamic_cast<QWhatsThisClickedEvent
*>(event
);
2579 QDesktopServices::openUrl(QUrl(whatsThisEvent
->href()));
2585 // Set a sane initial window size
2586 QSize
DolphinMainWindow::sizeHint() const
2588 return KXmlGuiWindow::sizeHint().expandedTo(QSize(760, 550));
2591 void DolphinMainWindow::saveNewToolbarConfig()
2593 KXmlGuiWindow::saveNewToolbarConfig(); // Applies the new config. This has to be called first
2594 // because the rest of this method decides things
2595 // based on the new config.
2596 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
2597 (actionCollection()->action(QStringLiteral("url_navigators")));
2598 if (!toolBar()->actions().contains(navigators
)) {
2599 m_tabWidget
->currentTabPage()->insertNavigatorsWidget(navigators
);
2601 updateAllowedToolbarAreas();
2602 (static_cast<KHamburgerMenu
*>(actionCollection()->action(KStandardAction::name(
2603 KStandardAction::HamburgerMenu
))))->hideActionsOf(toolBar());
2606 void DolphinMainWindow::focusTerminalPanel()
2608 if (m_terminalPanel
->isVisible()) {
2609 if (m_terminalPanel
->terminalHasFocus()) {
2610 m_activeViewContainer
->view()->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2611 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2613 m_terminalPanel
->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2614 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2617 actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger();
2618 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2622 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
2623 KIO::FileUndoManager::UiInterface()
2627 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2631 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
2633 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2635 DolphinViewContainer
* container
= mainWin
->activeViewContainer();
2636 container
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
2638 KIO::FileUndoManager::UiInterface::jobError(job
);
2642 bool DolphinMainWindow::isUrlOpen(const QString
&url
)
2644 return m_tabWidget
->isUrlOpen(QUrl::fromUserInput(url
));
2647 bool DolphinMainWindow::isUrlOrParentOpen(const QString
&url
)
2649 return m_tabWidget
->isUrlOrParentOpen(QUrl::fromUserInput(url
));