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 void DolphinMainWindow::showCommand(CommandType command
)
290 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
292 case KIO::FileUndoManager::Copy
:
293 statusBar
->setText(i18nc("@info:status", "Successfully copied."));
295 case KIO::FileUndoManager::Move
:
296 statusBar
->setText(i18nc("@info:status", "Successfully moved."));
298 case KIO::FileUndoManager::Link
:
299 statusBar
->setText(i18nc("@info:status", "Successfully linked."));
301 case KIO::FileUndoManager::Trash
:
302 statusBar
->setText(i18nc("@info:status", "Successfully moved to trash."));
304 case KIO::FileUndoManager::Rename
:
305 statusBar
->setText(i18nc("@info:status", "Successfully renamed."));
308 case KIO::FileUndoManager::Mkdir
:
309 statusBar
->setText(i18nc("@info:status", "Created folder."));
317 void DolphinMainWindow::pasteIntoFolder()
319 m_activeViewContainer
->view()->pasteIntoFolder();
322 void DolphinMainWindow::changeUrl(const QUrl
&url
)
324 if (!KProtocolManager::supportsListing(url
)) {
325 // The URL navigator only checks for validity, not
326 // if the URL can be listed. An error message is
327 // shown due to DolphinViewContainer::restoreView().
331 m_activeViewContainer
->setUrl(url
);
332 updateFileAndEditActions();
337 Q_EMIT
urlChanged(url
);
340 void DolphinMainWindow::slotTerminalDirectoryChanged(const QUrl
& url
)
342 if (m_tearDownFromPlacesRequested
&& url
== QUrl::fromLocalFile(QDir::homePath())) {
343 m_placesPanel
->proceedWithTearDown();
344 m_tearDownFromPlacesRequested
= false;
347 m_activeViewContainer
->setAutoGrabFocus(false);
349 m_activeViewContainer
->setAutoGrabFocus(true);
352 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
354 KToggleAction
* editableLocationAction
=
355 static_cast<KToggleAction
*>(actionCollection()->action(QStringLiteral("editable_location")));
356 editableLocationAction
->setChecked(editable
);
359 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
361 updateFileAndEditActions();
363 const int selectedUrlsCount
= m_tabWidget
->currentTabPage()->selectedItemsCount();
365 QAction
* compareFilesAction
= actionCollection()->action(QStringLiteral("compare_files"));
366 if (selectedUrlsCount
== 2) {
367 compareFilesAction
->setEnabled(isKompareInstalled());
369 compareFilesAction
->setEnabled(false);
372 Q_EMIT
selectionChanged(selection
);
375 void DolphinMainWindow::updateHistory()
377 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
378 const int index
= urlNavigator
->historyIndex();
380 QAction
* backAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Back
));
382 backAction
->setToolTip(i18nc("@info", "Go back"));
383 backAction
->setWhatsThis(i18nc("@info:whatsthis go back", "Return to the previously viewed folder."));
384 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
387 QAction
* forwardAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Forward
));
389 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
390 forwardAction
->setWhatsThis(xi18nc("@info:whatsthis go forward",
391 "This undoes a <interface>Go|Back</interface> action."));
392 forwardAction
->setEnabled(index
> 0);
396 void DolphinMainWindow::updateFilterBarAction(bool show
)
398 QAction
* toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
399 toggleFilterBarAction
->setChecked(show
);
402 void DolphinMainWindow::openNewMainWindow()
404 Dolphin::openNewWindow({m_activeViewContainer
->url()}, this);
407 void DolphinMainWindow::openNewActivatedTab()
409 // keep browsers compatibility, new tab is always after last one
410 auto openNewTabAfterLastTabConfigured
= GeneralSettings::openNewTabAfterLastTab();
411 GeneralSettings::setOpenNewTabAfterLastTab(true);
412 m_tabWidget
->openNewActivatedTab();
413 GeneralSettings::setOpenNewTabAfterLastTab(openNewTabAfterLastTabConfigured
);
416 void DolphinMainWindow::addToPlaces()
421 // If nothing is selected, act on the current dir
422 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
423 url
= m_activeViewContainer
->url();
424 name
= m_activeViewContainer
->placesText();
426 const auto dirToAdd
= m_activeViewContainer
->view()->selectedItems().first();
427 url
= dirToAdd
.url();
428 name
= dirToAdd
.name();
432 if (m_activeViewContainer
->isSearchModeEnabled()) {
433 icon
= QStringLiteral("folder-saved-search-symbolic");
435 icon
= KIO::iconNameForUrl(url
);
437 DolphinPlacesModelSingleton::instance().placesModel()->addPlace(name
, url
, icon
);
441 void DolphinMainWindow::openNewTab(const QUrl
& url
)
443 m_tabWidget
->openNewTab(url
, QUrl());
446 void DolphinMainWindow::openNewTabAndActivate(const QUrl
&url
)
448 m_tabWidget
->openNewActivatedTab(url
, QUrl());
451 void DolphinMainWindow::openNewWindow(const QUrl
&url
)
453 Dolphin::openNewWindow({url
}, this);
456 void DolphinMainWindow::slotSplitViewChanged()
458 m_tabWidget
->currentTabPage()->setSplitViewEnabled(GeneralSettings::splitView(), WithAnimation
);
462 void DolphinMainWindow::openInNewTab()
464 const KFileItemList
& list
= m_activeViewContainer
->view()->selectedItems();
465 bool tabCreated
= false;
467 for (const KFileItem
& item
: list
) {
468 const QUrl
& url
= DolphinView::openItemAsFolderUrl(item
);
469 if (!url
.isEmpty()) {
475 // if no new tab has been created from the selection
476 // open the current directory in a new tab
478 openNewTab(m_activeViewContainer
->url());
482 void DolphinMainWindow::openInNewWindow()
486 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
487 if (list
.isEmpty()) {
488 newWindowUrl
= m_activeViewContainer
->url();
489 } else if (list
.count() == 1) {
490 const KFileItem
& item
= list
.first();
491 newWindowUrl
= DolphinView::openItemAsFolderUrl(item
);
494 if (!newWindowUrl
.isEmpty()) {
495 Dolphin::openNewWindow({newWindowUrl
}, this);
499 void DolphinMainWindow::showTarget()
501 const auto link
= m_activeViewContainer
->view()->selectedItems().at(0);
502 const auto linkLocationDir
= QFileInfo(link
.localPath()).absoluteDir();
503 auto linkDestination
= link
.linkDest();
504 if (QFileInfo(linkDestination
).isRelative()) {
505 linkDestination
= linkLocationDir
.filePath(linkDestination
);
507 if (QFileInfo::exists(linkDestination
)) {
508 KIO::highlightInFileManager({QUrl::fromLocalFile(linkDestination
).adjusted(QUrl::StripTrailingSlash
)});
510 m_activeViewContainer
->showMessage(xi18nc("@info", "Could not access <filename>%1</filename>.", linkDestination
),
511 DolphinViewContainer::Warning
);
515 void DolphinMainWindow::showEvent(QShowEvent
* event
)
517 KXmlGuiWindow::showEvent(event
);
519 if (!event
->spontaneous()) {
520 m_activeViewContainer
->view()->setFocus();
524 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
526 // Find out if Dolphin is closed directly by the user or
527 // by the session manager because the session is closed
528 bool closedByUser
= true;
529 if (qApp
->isSavingSession()) {
530 closedByUser
= false;
533 if (m_tabWidget
->count() > 1
534 && GeneralSettings::confirmClosingMultipleTabs()
535 && !GeneralSettings::rememberOpenedTabs()
537 // Ask the user if he really wants to quit and close all tabs.
538 // Open a confirmation dialog with 3 buttons:
539 // QDialogButtonBox::Yes -> Quit
540 // QDialogButtonBox::No -> Close only the current tab
541 // QDialogButtonBox::Cancel -> do nothing
542 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
543 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
544 dialog
->setModal(true);
545 QDialogButtonBox
* buttons
= new QDialogButtonBox(QDialogButtonBox::Yes
| QDialogButtonBox::No
| QDialogButtonBox::Cancel
);
546 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KGuiItem(i18nc("@action:button 'Quit Dolphin' button", "&Quit %1", QGuiApplication::applicationDisplayName()), QIcon::fromTheme(QStringLiteral("application-exit"))));
547 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("C&lose Current Tab"), QIcon::fromTheme(QStringLiteral("tab-close"))));
548 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
549 buttons
->button(QDialogButtonBox::Yes
)->setDefault(true);
551 bool doNotAskAgainCheckboxResult
= false;
553 const auto result
= KMessageBox::createKMessageBox(dialog
,
555 QMessageBox::Warning
,
556 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
558 i18n("Do not ask again"),
559 &doNotAskAgainCheckboxResult
,
560 KMessageBox::Notify
);
562 if (doNotAskAgainCheckboxResult
) {
563 GeneralSettings::setConfirmClosingMultipleTabs(false);
567 case QDialogButtonBox::Yes
:
570 case QDialogButtonBox::No
:
571 // Close only the current tab
572 m_tabWidget
->closeTab();
580 if (m_terminalPanel
&& m_terminalPanel
->hasProgramRunning() && GeneralSettings::confirmClosingTerminalRunningProgram() && closedByUser
) {
581 // Ask if the user really wants to quit Dolphin with a program that is still running in the Terminal panel
582 // Open a confirmation dialog with 3 buttons:
583 // QDialogButtonBox::Yes -> Quit
584 // QDialogButtonBox::No -> Show Terminal Panel
585 // QDialogButtonBox::Cancel -> do nothing
586 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
587 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
588 dialog
->setModal(true);
589 auto standardButtons
= QDialogButtonBox::Yes
| QDialogButtonBox::Cancel
;
590 if (!m_terminalPanel
->isVisible()) {
591 standardButtons
|= QDialogButtonBox::No
;
593 QDialogButtonBox
*buttons
= new QDialogButtonBox(standardButtons
);
594 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KStandardGuiItem::quit());
595 if (!m_terminalPanel
->isVisible()) {
597 buttons
->button(QDialogButtonBox::No
),
598 KGuiItem(i18n("Show &Terminal Panel"), QIcon::fromTheme(QStringLiteral("dialog-scripts"))));
600 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
602 bool doNotAskAgainCheckboxResult
= false;
604 const auto result
= KMessageBox::createKMessageBox(
607 QMessageBox::Warning
,
608 i18n("The program '%1' is still running in the Terminal panel. Are you sure you want to quit?", m_terminalPanel
->runningProgramName()),
610 i18n("Do not ask again"),
611 &doNotAskAgainCheckboxResult
,
612 KMessageBox::Dangerous
);
614 if (doNotAskAgainCheckboxResult
) {
615 GeneralSettings::setConfirmClosingTerminalRunningProgram(false);
619 case QDialogButtonBox::Yes
:
622 case QDialogButtonBox::No
:
623 actionCollection()->action("show_terminal_panel")->trigger();
624 // Do not quit, ignore quit event
632 if (GeneralSettings::rememberOpenedTabs()) {
633 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
634 KConfig
*config
= KConfigGui::sessionConfig();
635 saveGlobalProperties(config
);
636 savePropertiesInternal(config
, 1);
640 GeneralSettings::setVersion(CurrentDolphinVersion
);
641 GeneralSettings::self()->save();
643 KXmlGuiWindow::closeEvent(event
);
646 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
648 m_tabWidget
->saveProperties(group
);
651 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
653 m_tabWidget
->readProperties(group
);
656 void DolphinMainWindow::updateNewMenu()
658 m_newFileMenu
->checkUpToDate();
659 m_newFileMenu
->setPopupFiles(QList
<QUrl
>() << activeViewContainer()->url());
662 void DolphinMainWindow::createDirectory()
664 m_newFileMenu
->setPopupFiles(QList
<QUrl
>() << activeViewContainer()->url());
665 m_newFileMenu
->createDirectory();
668 void DolphinMainWindow::quit()
673 void DolphinMainWindow::showErrorMessage(const QString
& message
)
675 m_activeViewContainer
->showMessage(message
, DolphinViewContainer::Error
);
678 void DolphinMainWindow::slotUndoAvailable(bool available
)
680 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
682 undoAction
->setEnabled(available
);
686 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
688 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
690 undoAction
->setText(text
);
694 void DolphinMainWindow::undo()
697 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
698 KIO::FileUndoManager::self()->undo();
701 void DolphinMainWindow::cut()
703 m_activeViewContainer
->view()->cutSelectedItemsToClipboard();
706 void DolphinMainWindow::copy()
708 m_activeViewContainer
->view()->copySelectedItemsToClipboard();
711 void DolphinMainWindow::paste()
713 m_activeViewContainer
->view()->paste();
716 void DolphinMainWindow::find()
718 m_activeViewContainer
->setSearchModeEnabled(true);
721 void DolphinMainWindow::updateSearchAction()
723 QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
724 toggleSearchAction
->setChecked(m_activeViewContainer
->isSearchModeEnabled());
727 void DolphinMainWindow::updatePasteAction()
729 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
730 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
731 pasteAction
->setEnabled(pasteInfo
.first
);
732 pasteAction
->setText(pasteInfo
.second
);
735 void DolphinMainWindow::slotDirectoryLoadingCompleted()
740 void DolphinMainWindow::slotToolBarActionMiddleClicked(QAction
*action
)
742 if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Back
))) {
744 } else if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Forward
))) {
746 } else if (action
== actionCollection()->action(QStringLiteral("go_up"))) {
748 } else if (action
== actionCollection()->action(QStringLiteral("go_home"))) {
753 QAction
*DolphinMainWindow::urlNavigatorHistoryAction(const KUrlNavigator
*urlNavigator
, int historyIndex
, QObject
*parent
)
755 const QUrl url
= urlNavigator
->locationUrl(historyIndex
);
757 QString text
= url
.toDisplayString(QUrl::PreferLocalFile
);
759 if (!urlNavigator
->showFullPath()) {
760 const KFilePlacesModel
*placesModel
= DolphinPlacesModelSingleton::instance().placesModel();
762 const QModelIndex closestIdx
= placesModel
->closestItem(url
);
763 if (closestIdx
.isValid()) {
764 const QUrl placeUrl
= placesModel
->url(closestIdx
);
766 text
= placesModel
->text(closestIdx
);
768 QString pathInsidePlace
= url
.path().mid(placeUrl
.path().length());
770 if (!pathInsidePlace
.isEmpty() && !pathInsidePlace
.startsWith(QLatin1Char('/'))) {
771 pathInsidePlace
.prepend(QLatin1Char('/'));
774 if (pathInsidePlace
!= QLatin1Char('/')) {
775 text
.append(pathInsidePlace
);
780 QAction
*action
= new QAction(QIcon::fromTheme(KIO::iconNameForUrl(url
)), text
, parent
);
781 action
->setData(historyIndex
);
785 void DolphinMainWindow::slotAboutToShowBackPopupMenu()
787 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
789 m_backAction
->menu()->clear();
790 for (int i
= urlNavigator
->historyIndex() + 1; i
< urlNavigator
->historySize() && entries
< MaxNumberOfNavigationentries
; ++i
, ++entries
) {
791 QAction
*action
= urlNavigatorHistoryAction(urlNavigator
, i
, m_backAction
->menu());
793 m_backAction
->menu()->addAction(action
);
797 void DolphinMainWindow::slotGoBack(QAction
* action
)
799 int gotoIndex
= action
->data().value
<int>();
800 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
801 for (int i
= gotoIndex
- urlNavigator
->historyIndex(); i
> 0; --i
) {
806 void DolphinMainWindow::slotBackForwardActionMiddleClicked(QAction
* action
)
809 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
810 openNewTab(urlNavigator
->locationUrl(action
->data().value
<int>()));
814 void DolphinMainWindow::slotAboutToShowForwardPopupMenu()
816 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
818 m_forwardAction
->menu()->clear();
819 for (int i
= urlNavigator
->historyIndex() - 1; i
>= 0 && entries
< MaxNumberOfNavigationentries
; --i
, ++entries
) {
820 QAction
*action
= urlNavigatorHistoryAction(urlNavigator
, i
, m_forwardAction
->menu());
822 m_forwardAction
->menu()->addAction(action
);
826 void DolphinMainWindow::slotGoForward(QAction
* action
)
828 int gotoIndex
= action
->data().value
<int>();
829 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
830 for (int i
= urlNavigator
->historyIndex() - gotoIndex
; i
> 0; --i
) {
835 void DolphinMainWindow::selectAll()
839 // if the URL navigator is editable and focused, select the whole
840 // URL instead of all items of the view
842 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
843 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit();
844 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
845 lineEdit
->hasFocus();
847 lineEdit
->selectAll();
849 m_activeViewContainer
->view()->selectAll();
853 void DolphinMainWindow::invertSelection()
856 m_activeViewContainer
->view()->invertSelection();
859 void DolphinMainWindow::toggleSplitView()
861 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
862 tabPage
->setSplitViewEnabled(!tabPage
->splitViewEnabled(), WithAnimation
);
867 void DolphinMainWindow::toggleSplitStash()
869 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
870 tabPage
->setSplitViewEnabled(false, WithAnimation
);
871 tabPage
->setSplitViewEnabled(true, WithAnimation
, QUrl("stash:/"));
874 void DolphinMainWindow::reloadView()
877 m_activeViewContainer
->reload();
878 m_activeViewContainer
->statusBar()->updateSpaceInfo();
881 void DolphinMainWindow::stopLoading()
883 m_activeViewContainer
->view()->stopLoading();
886 void DolphinMainWindow::enableStopAction()
888 actionCollection()->action(QStringLiteral("stop"))->setEnabled(true);
891 void DolphinMainWindow::disableStopAction()
893 actionCollection()->action(QStringLiteral("stop"))->setEnabled(false);
896 void DolphinMainWindow::showFilterBar()
898 m_activeViewContainer
->setFilterBarVisible(true);
901 void DolphinMainWindow::toggleFilterBar()
903 const bool checked
= !m_activeViewContainer
->isFilterBarVisible();
904 m_activeViewContainer
->setFilterBarVisible(checked
);
906 QAction
* toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
907 toggleFilterBarAction
->setChecked(checked
);
910 void DolphinMainWindow::toggleEditLocation()
914 QAction
* action
= actionCollection()->action(QStringLiteral("editable_location"));
915 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
916 urlNavigator
->setUrlEditable(action
->isChecked());
919 void DolphinMainWindow::replaceLocation()
921 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
922 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit();
924 // If the text field currently has focus and everything is selected,
925 // pressing the keyboard shortcut returns the whole thing to breadcrumb mode
926 if (navigator
->isUrlEditable()
927 && lineEdit
->hasFocus()
928 && lineEdit
->selectedText() == lineEdit
->text() ) {
929 navigator
->setUrlEditable(false);
931 navigator
->setUrlEditable(true);
932 navigator
->setFocus();
933 lineEdit
->selectAll();
937 void DolphinMainWindow::togglePanelLockState()
939 const bool newLockState
= !GeneralSettings::lockPanels();
940 const auto childrenObjects
= children();
941 for (QObject
* child
: childrenObjects
) {
942 DolphinDockWidget
* dock
= qobject_cast
<DolphinDockWidget
*>(child
);
944 dock
->setLocked(newLockState
);
948 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(newLockState
);
950 GeneralSettings::setLockPanels(newLockState
);
953 void DolphinMainWindow::slotTerminalPanelVisibilityChanged()
955 if (m_terminalPanel
->isHiddenInVisibleWindow() && m_activeViewContainer
) {
956 m_activeViewContainer
->view()->setFocus();
960 void DolphinMainWindow::goBack()
962 DolphinUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
963 urlNavigator
->goBack();
965 if (urlNavigator
->locationState().isEmpty()) {
966 // An empty location state indicates a redirection URL,
967 // which must be skipped too
968 urlNavigator
->goBack();
972 void DolphinMainWindow::goForward()
974 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goForward();
977 void DolphinMainWindow::goUp()
979 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goUp();
982 void DolphinMainWindow::goHome()
984 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goHome();
987 void DolphinMainWindow::goBackInNewTab()
989 const KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
990 const int index
= urlNavigator
->historyIndex() + 1;
991 openNewTab(urlNavigator
->locationUrl(index
));
994 void DolphinMainWindow::goForwardInNewTab()
996 const KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
997 const int index
= urlNavigator
->historyIndex() - 1;
998 openNewTab(urlNavigator
->locationUrl(index
));
1001 void DolphinMainWindow::goUpInNewTab()
1003 const QUrl currentUrl
= activeViewContainer()->urlNavigator()->locationUrl();
1004 openNewTab(KIO::upUrl(currentUrl
));
1007 void DolphinMainWindow::goHomeInNewTab()
1009 openNewTab(Dolphin::homeUrl());
1012 void DolphinMainWindow::compareFiles()
1014 const KFileItemList items
= m_tabWidget
->currentTabPage()->selectedItems();
1015 if (items
.count() != 2) {
1016 // The action is disabled in this case, but it could have been triggered
1017 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
1021 QUrl urlA
= items
.at(0).url();
1022 QUrl urlB
= items
.at(1).url();
1024 QString
command(QStringLiteral("kompare -c \""));
1025 command
.append(urlA
.toDisplayString(QUrl::PreferLocalFile
));
1026 command
.append("\" \"");
1027 command
.append(urlB
.toDisplayString(QUrl::PreferLocalFile
));
1028 command
.append('\"');
1030 KIO::CommandLauncherJob
*job
= new KIO::CommandLauncherJob(command
, this);
1031 job
->setDesktopName(QStringLiteral("org.kde.kompare"));
1035 void DolphinMainWindow::toggleShowMenuBar()
1037 const bool visible
= menuBar()->isVisible();
1038 menuBar()->setVisible(!visible
);
1041 QPointer
<QAction
> DolphinMainWindow::preferredSearchTool()
1043 m_searchTools
.clear();
1044 KMoreToolsMenuFactory("dolphin/search-tools").fillMenuFromGroupingNames(
1045 &m_searchTools
, { "files-find" }, m_activeViewContainer
->url()
1047 QList
<QAction
*> actions
= m_searchTools
.actions();
1048 if (actions
.isEmpty()) {
1051 QAction
* action
= actions
.first();
1052 if (action
->isSeparator()) {
1058 void DolphinMainWindow::updateOpenPreferredSearchToolAction()
1060 QAction
* openPreferredSearchTool
= actionCollection()->action(QStringLiteral("open_preferred_search_tool"));
1061 if (!openPreferredSearchTool
) {
1064 QPointer
<QAction
> tool
= preferredSearchTool();
1066 openPreferredSearchTool
->setVisible(true);
1067 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open %1", tool
->text()));
1068 // Only override with the app icon if it is the default, i.e. the user hasn't configured one manually
1069 // https://bugs.kde.org/show_bug.cgi?id=442815
1070 if (openPreferredSearchTool
->icon().name() == QLatin1String("search")) {
1071 openPreferredSearchTool
->setIcon(tool
->icon());
1074 openPreferredSearchTool
->setVisible(false);
1075 // still visible in Shortcuts configuration window
1076 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1077 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1081 void DolphinMainWindow::openPreferredSearchTool()
1083 QPointer
<QAction
> tool
= preferredSearchTool();
1089 void DolphinMainWindow::openTerminal()
1091 openTerminalJob(m_activeViewContainer
->url());
1094 void DolphinMainWindow::openTerminalHere()
1096 QList
<QUrl
> urls
= {};
1098 for (const KFileItem
& item
: m_activeViewContainer
->view()->selectedItems()) {
1099 QUrl url
= item
.targetUrl();
1100 if (item
.isFile()) {
1101 url
.setPath(QFileInfo(url
.path()).absolutePath());
1103 if (!urls
.contains(url
)) {
1108 // No items are selected. Open a terminal window for the current location.
1109 if (urls
.count() == 0) {
1114 if (urls
.count() > 5) {
1115 QString question
= i18np("Are you sure you want to open 1 terminal window?",
1116 "Are you sure you want to open %1 terminal windows?", urls
.count());
1117 const int answer
= KMessageBox::warningYesNo(this, question
);
1118 if (answer
!= KMessageBox::Yes
) {
1123 for (const QUrl
& url
: urls
) {
1124 openTerminalJob(url
);
1128 void DolphinMainWindow::openTerminalJob(const QUrl
& url
)
1130 if (url
.isLocalFile()) {
1131 auto job
= new KTerminalLauncherJob(QString());
1132 job
->setWorkingDirectory(url
.toLocalFile());
1137 // Not a local file, with protocol Class ":local", try stat'ing
1138 if (KProtocolInfo::protocolClass(url
.scheme()) == QLatin1String(":local")) {
1139 KIO::StatJob
*job
= KIO::mostLocalUrl(url
);
1140 KJobWidgets::setWindow(job
, this);
1141 connect(job
, &KJob::result
, this, [job
]() {
1143 if (!job
->error()) {
1144 statUrl
= job
->mostLocalUrl();
1147 auto job
= new KTerminalLauncherJob(QString());
1148 job
->setWorkingDirectory(statUrl
.isLocalFile() ? statUrl
.toLocalFile() : QDir::homePath());
1155 // Nothing worked, just use $HOME
1156 auto job
= new KTerminalLauncherJob(QString());
1157 job
->setWorkingDirectory(QDir::homePath());
1161 void DolphinMainWindow::editSettings()
1163 if (!m_settingsDialog
) {
1164 DolphinViewContainer
* container
= activeViewContainer();
1165 container
->view()->writeSettings();
1167 const QUrl url
= container
->url();
1168 DolphinSettingsDialog
* settingsDialog
= new DolphinSettingsDialog(url
, this, actionCollection());
1169 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, this, &DolphinMainWindow::refreshViews
);
1170 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
,
1171 &DolphinUrlNavigatorsController::slotReadSettings
);
1172 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1173 settingsDialog
->show();
1174 m_settingsDialog
= settingsDialog
;
1176 m_settingsDialog
.data()->raise();
1180 void DolphinMainWindow::handleUrl(const QUrl
& url
)
1182 delete m_lastHandleUrlOpenJob
;
1183 m_lastHandleUrlOpenJob
= nullptr;
1185 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1186 activeViewContainer()->setUrl(url
);
1188 m_lastHandleUrlOpenJob
= new KIO::OpenUrlJob(url
);
1189 m_lastHandleUrlOpenJob
->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
1190 m_lastHandleUrlOpenJob
->setShowOpenOrExecuteDialog(true);
1192 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::mimeTypeFound
, this,
1193 [this, url
](const QString
&mimetype
) {
1194 if (mimetype
== QLatin1String("inode/directory")) {
1195 // If it's a dir, we'll take it from here
1196 m_lastHandleUrlOpenJob
->kill();
1197 m_lastHandleUrlOpenJob
= nullptr;
1198 activeViewContainer()->setUrl(url
);
1202 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::result
, this, [this]() {
1203 m_lastHandleUrlOpenJob
= nullptr;
1206 m_lastHandleUrlOpenJob
->start();
1210 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1212 // trash:/ is writable but we don't want to create new items in it.
1213 // TODO: remove the trash check once https://phabricator.kde.org/T8234 is implemented
1214 newFileMenu()->setEnabled(isFolderWritable
&& m_activeViewContainer
->url().scheme() != QLatin1String("trash"));
1217 void DolphinMainWindow::openContextMenu(const QPoint
& pos
,
1218 const KFileItem
& item
,
1219 const KFileItemList
&selectedItems
,
1222 QPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, item
, selectedItems
, url
, &m_fileItemActions
);
1223 contextMenu
.data()->exec(pos
);
1225 // Delete the menu, unless it has been deleted in its own nested event loop already.
1227 contextMenu
->deleteLater();
1231 QMenu
*DolphinMainWindow::createPopupMenu()
1233 QMenu
*menu
= KXmlGuiWindow::createPopupMenu();
1235 menu
->addSeparator();
1236 menu
->addAction(actionCollection()->action(QStringLiteral("lock_panels")));
1241 void DolphinMainWindow::updateHamburgerMenu()
1243 KActionCollection
* ac
= actionCollection();
1244 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(
1245 ac
->action(KStandardAction::name(KStandardAction::HamburgerMenu
)));
1246 auto menu
= hamburgerMenu
->menu();
1248 menu
= new QMenu(this);
1249 hamburgerMenu
->setMenu(menu
);
1250 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("basic_actions"))->menu());
1251 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("zoom"))->menu());
1255 const QList
<QAction
*> toolbarActions
= toolBar()->actions();
1257 if (!toolBar()->isVisible()) {
1258 // If neither the menu bar nor the toolbar are visible, these actions should be available.
1259 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)));
1260 menu
->addAction(toolBarMenuAction());
1261 menu
->addSeparator();
1264 // This group of actions (until the next separator) contains all the most basic actions
1265 // necessary to use Dolphin effectively.
1266 menu
->addAction(ac
->action(QStringLiteral("go_back")));
1267 menu
->addAction(ac
->action(QStringLiteral("go_forward")));
1269 menu
->addMenu(m_newFileMenu
->menu());
1270 menu
->addAction(ac
->action(QStringLiteral("basic_actions")));
1271 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Undo
)));
1272 if (!toolBar()->isVisible()
1273 || (!toolbarActions
.contains(ac
->action(QStringLiteral("toggle_search")))
1274 && !toolbarActions
.contains(ac
->action(QStringLiteral("open_preferred_search_tool"))))
1276 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Find
)));
1277 // This way a search action will only be added if none of the three available
1278 // search actions is present on the toolbar.
1280 if (!toolBar()->isVisible()
1281 || !toolbarActions
.contains(ac
->action(QStringLiteral("toggle_filter")))
1283 menu
->addAction(ac
->action(QStringLiteral("show_filter_bar")));
1284 // This way a filter action will only be added if none of the two available
1285 // filter actions is present on the toolbar.
1287 menu
->addSeparator();
1289 // The second group of actions (up until the next separator) contains actions for opening
1290 // additional views to interact with the file system.
1291 menu
->addAction(ac
->action(QStringLiteral("file_new")));
1292 menu
->addAction(ac
->action(QStringLiteral("new_tab")));
1293 if (ac
->action(QStringLiteral("undo_close_tab"))->isEnabled()) {
1294 menu
->addAction(ac
->action(QStringLiteral("closed_tabs")));
1296 menu
->addAction(ac
->action(QStringLiteral("open_terminal")));
1297 menu
->addSeparator();
1299 // The third group contains actions to change what one sees in the view
1300 // and to change the more general UI.
1301 if (!toolBar()->isVisible()
1302 || (!toolbarActions
.contains(ac
->action(QStringLiteral("icons")))
1303 && !toolbarActions
.contains(ac
->action(QStringLiteral("compact")))
1304 && !toolbarActions
.contains(ac
->action(QStringLiteral("details")))
1305 && !toolbarActions
.contains(ac
->action(QStringLiteral("view_mode"))))
1307 menu
->addAction(ac
->action(QStringLiteral("view_mode")));
1309 menu
->addAction(ac
->action(QStringLiteral("show_hidden_files")));
1310 menu
->addAction(ac
->action(QStringLiteral("sort")));
1311 menu
->addAction(ac
->action(QStringLiteral("additional_info")));
1312 if (!GeneralSettings::showStatusBar() || !GeneralSettings::showZoomSlider()) {
1313 menu
->addAction(ac
->action(QStringLiteral("zoom")));
1315 menu
->addAction(ac
->action(QStringLiteral("panels")));
1317 // The "Configure" menu is not added to the actionCollection() because there is hardly
1318 // a good reason for users to put it on their toolbar.
1319 auto configureMenu
= menu
->addMenu(QIcon::fromTheme(QStringLiteral("configure")),
1320 i18nc("@action:inmenu menu for configure actions", "Configure"));
1321 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
)));
1322 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)));
1323 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)));
1324 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Preferences
)));
1325 hamburgerMenu
->hideActionsOf(configureMenu
);
1328 void DolphinMainWindow::slotPlaceActivated(const QUrl
& url
)
1330 DolphinViewContainer
* view
= activeViewContainer();
1332 if (view
->url() == url
) {
1333 // We can end up here if the user clicked a device in the Places Panel
1334 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1337 view
->disableUrlNavigatorSelectionRequests();
1339 view
->enableUrlNavigatorSelectionRequests();
1343 void DolphinMainWindow::closedTabsCountChanged(unsigned int count
)
1345 actionCollection()->action(QStringLiteral("undo_close_tab"))->setEnabled(count
> 0);
1348 void DolphinMainWindow::activeViewChanged(DolphinViewContainer
* viewContainer
)
1350 DolphinViewContainer
* oldViewContainer
= m_activeViewContainer
;
1351 Q_ASSERT(viewContainer
);
1353 m_activeViewContainer
= viewContainer
;
1355 if (oldViewContainer
) {
1356 const QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
1357 toggleSearchAction
->disconnect(oldViewContainer
);
1359 // Disconnect all signals between the old view container (container,
1360 // view and url navigator) and main window.
1361 oldViewContainer
->disconnect(this);
1362 oldViewContainer
->view()->disconnect(this);
1363 oldViewContainer
->urlNavigatorInternalWithHistory()->disconnect(this);
1364 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
1365 (actionCollection()->action(QStringLiteral("url_navigators")));
1366 navigators
->primaryUrlNavigator()->disconnect(this);
1367 if (auto secondaryUrlNavigator
= navigators
->secondaryUrlNavigator()) {
1368 secondaryUrlNavigator
->disconnect(this);
1371 // except the requestItemInfo so that on hover the information panel can still be updated
1372 connect(oldViewContainer
->view(), &DolphinView::requestItemInfo
,
1373 this, &DolphinMainWindow::requestItemInfo
);
1376 connectViewSignals(viewContainer
);
1378 m_actionHandler
->setCurrentView(viewContainer
->view());
1381 updateFileAndEditActions();
1382 updatePasteAction();
1383 updateViewActions();
1385 updateSearchAction();
1387 const QUrl url
= viewContainer
->url();
1388 Q_EMIT
urlChanged(url
);
1391 void DolphinMainWindow::tabCountChanged(int count
)
1393 const bool enableTabActions
= (count
> 1);
1394 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1395 actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i
))->setEnabled(enableTabActions
);
1397 actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions
);
1398 actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions
);
1399 actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions
);
1402 void DolphinMainWindow::updateWindowTitle()
1404 const QString newTitle
= m_activeViewContainer
->captionWindowTitle();
1405 if (windowTitle() != newTitle
) {
1406 setWindowTitle(newTitle
);
1410 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString
& mountPath
)
1412 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1413 setViewsToHomeIfMountPathOpen(mountPath
);
1416 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectory().startsWith(mountPath
)) {
1417 m_tearDownFromPlacesRequested
= true;
1418 m_terminalPanel
->goHome();
1419 // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
1421 m_placesPanel
->proceedWithTearDown();
1425 void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString
& mountPath
)
1427 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1428 setViewsToHomeIfMountPathOpen(mountPath
);
1431 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectory().startsWith(mountPath
)) {
1432 m_tearDownFromPlacesRequested
= false;
1433 m_terminalPanel
->goHome();
1437 void DolphinMainWindow::slotKeyBindings()
1439 KShortcutsDialog
dialog(KShortcutsEditor::AllActions
, KShortcutsEditor::LetterShortcutsAllowed
, this);
1440 dialog
.addCollection(actionCollection());
1441 if (m_terminalPanel
) {
1442 KActionCollection
*konsolePartActionCollection
= m_terminalPanel
->actionCollection();
1443 if (konsolePartActionCollection
) {
1444 dialog
.addCollection(konsolePartActionCollection
, QStringLiteral("KonsolePart"));
1450 void DolphinMainWindow::setViewsToHomeIfMountPathOpen(const QString
& mountPath
)
1452 const QVector
<DolphinViewContainer
*> theViewContainers
= viewContainers();
1453 for (DolphinViewContainer
*viewContainer
: theViewContainers
) {
1454 if (viewContainer
&& viewContainer
->url().toLocalFile().startsWith(mountPath
)) {
1455 viewContainer
->setUrl(QUrl::fromLocalFile(QDir::homePath()));
1458 disconnect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, nullptr, nullptr);
1461 void DolphinMainWindow::setupActions()
1463 KStandardAction::hamburgerMenu(nullptr, nullptr, actionCollection());
1465 // setup 'File' menu
1466 m_newFileMenu
= new DolphinNewFileMenu(actionCollection(), this);
1467 QMenu
* menu
= m_newFileMenu
->menu();
1468 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1469 menu
->setIcon(QIcon::fromTheme(QStringLiteral("list-add")));
1470 m_newFileMenu
->setPopupMode(QToolButton::InstantPopup
);
1471 connect(menu
, &QMenu::aboutToShow
,
1472 this, &DolphinMainWindow::updateNewMenu
);
1474 QAction
* newWindow
= KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow
, actionCollection());
1475 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1476 newWindow
->setToolTip(i18nc("@info", "Open a new Dolphin window"));
1477 newWindow
->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1478 "window just like this one with the current location and view."
1479 "<nl/>You can drag and drop items between windows."));
1480 newWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1482 QAction
* newTab
= actionCollection()->addAction(QStringLiteral("new_tab"));
1483 newTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1484 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1485 newTab
->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1486 "<emphasis>Tab</emphasis> with the current location and view.<nl/>"
1487 "A tab is an additional view within this window. "
1488 "You can drag and drop items between tabs."));
1489 actionCollection()->setDefaultShortcuts(newTab
, {Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
});
1490 connect(newTab
, &QAction::triggered
, this, &DolphinMainWindow::openNewActivatedTab
);
1492 QAction
* addToPlaces
= actionCollection()->addAction(QStringLiteral("add_to_places"));
1493 addToPlaces
->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new")));
1494 addToPlaces
->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places"));
1495 addToPlaces
->setWhatsThis(xi18nc("@info:whatsthis", "This adds the selected folder "
1496 "to the Places panel."));
1497 connect(addToPlaces
, &QAction::triggered
, this, &DolphinMainWindow::addToPlaces
);
1499 QAction
* closeTab
= KStandardAction::close(m_tabWidget
, QOverload
<>::of(&DolphinTabWidget::closeTab
), actionCollection());
1500 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1501 closeTab
->setWhatsThis(i18nc("@info:whatsthis", "This closes the "
1502 "currently viewed tab. If no more tabs are left this window "
1503 "will close instead."));
1505 QAction
* quitAction
= KStandardAction::quit(this, &DolphinMainWindow::quit
, actionCollection());
1506 quitAction
->setWhatsThis(i18nc("@info:whatsthis quit", "This closes this window."));
1508 // setup 'Edit' menu
1509 KStandardAction::undo(this,
1510 &DolphinMainWindow::undo
,
1511 actionCollection());
1513 // i18n: This will be the last paragraph for the whatsthis for all three:
1514 // Cut, Copy and Paste
1515 const QString cutCopyPastePara
= xi18nc("@info:whatsthis", "<para><emphasis>Cut, "
1516 "Copy</emphasis> and <emphasis>Paste</emphasis> work between many "
1517 "applications and are among the most used commands. That's why their "
1518 "<emphasis>keyboard shortcuts</emphasis> are prominently placed right "
1519 "next to each other on the keyboard: <shortcut>Ctrl+X</shortcut>, "
1520 "<shortcut>Ctrl+C</shortcut> and <shortcut>Ctrl+V</shortcut>.</para>");
1521 QAction
* cutAction
= KStandardAction::cut(this, &DolphinMainWindow::cut
, actionCollection());
1522 cutAction
->setWhatsThis(xi18nc("@info:whatsthis cut", "This copies the items "
1523 "in your current selection to the <emphasis>clipboard</emphasis>.<nl/>"
1524 "Use the <emphasis>Paste</emphasis> action afterwards to copy them from "
1525 "the clipboard to a new location. The items will be removed from their "
1526 "initial location.") + cutCopyPastePara
);
1527 QAction
* copyAction
= KStandardAction::copy(this, &DolphinMainWindow::copy
, actionCollection());
1528 copyAction
->setWhatsThis(xi18nc("@info:whatsthis copy", "This copies the "
1529 "items in your current selection to the <emphasis>clipboard</emphasis>."
1530 "<nl/>Use the <emphasis>Paste</emphasis> action afterwards to copy them "
1531 "from the clipboard to a new location.") + cutCopyPastePara
);
1532 QAction
* paste
= KStandardAction::paste(this, &DolphinMainWindow::paste
, actionCollection());
1533 // The text of the paste-action is modified dynamically by Dolphin
1534 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1535 // due to the long text, the text "Paste" is used:
1536 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1537 paste
->setWhatsThis(xi18nc("@info:whatsthis paste", "This copies the items from "
1538 "your <emphasis>clipboard</emphasis> to the currently viewed folder.<nl/>"
1539 "If the items were added to the clipboard by the <emphasis>Cut</emphasis> "
1540 "action they are removed from their old location.") + cutCopyPastePara
);
1542 QAction
* copyToOtherViewAction
= actionCollection()->addAction(QStringLiteral("copy_to_inactive_split_view"));
1543 copyToOtherViewAction
->setText(i18nc("@action:inmenu", "Copy to Inactive Split View"));
1544 copyToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Copy", "This copies the selected items from "
1545 "the <emphasis>active</emphasis> view to the inactive split view."));
1546 copyToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
1547 copyToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Copy to Inactive Split View"));
1548 actionCollection()->setDefaultShortcut(copyToOtherViewAction
, Qt::SHIFT
| Qt::Key_F5
);
1549 connect(copyToOtherViewAction
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::copyToInactiveSplitView
);
1551 QAction
* moveToOtherViewAction
= actionCollection()->addAction(QStringLiteral("move_to_inactive_split_view"));
1552 moveToOtherViewAction
->setText(i18nc("@action:inmenu", "Move to Inactive Split View"));
1553 moveToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Move", "This moves the selected items from "
1554 "the <emphasis>active</emphasis> view to the inactive split view."));
1555 moveToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-cut")));
1556 moveToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Move to Inactive Split View"));
1557 actionCollection()->setDefaultShortcut(moveToOtherViewAction
, Qt::SHIFT
| Qt::Key_F6
);
1558 connect(moveToOtherViewAction
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::moveToInactiveSplitView
);
1560 QAction
* showFilterBar
= actionCollection()->addAction(QStringLiteral("show_filter_bar"));
1561 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Filter..."));
1562 showFilterBar
->setToolTip(i18nc("@info:tooltip", "Show Filter Bar"));
1563 showFilterBar
->setWhatsThis(xi18nc("@info:whatsthis", "This opens the "
1564 "<emphasis>Filter Bar</emphasis> at the bottom of the window.<nl/> "
1565 "There you can enter a text to filter the files and folders currently displayed. "
1566 "Only those that contain the text in their name will be kept in view."));
1567 showFilterBar
->setIcon(QIcon::fromTheme(QStringLiteral("view-filter")));
1568 actionCollection()->setDefaultShortcuts(showFilterBar
, {Qt::CTRL
| Qt::Key_I
, Qt::Key_Slash
});
1569 connect(showFilterBar
, &QAction::triggered
, this, &DolphinMainWindow::showFilterBar
);
1571 // toggle_filter acts as a copy of the main showFilterBar to be used mainly
1572 // in the toolbar, with no default shortcut attached, to avoid messing with
1573 // existing workflows (filter bar always open and Ctrl-I to focus)
1574 QAction
*toggleFilter
= actionCollection()->addAction(QStringLiteral("toggle_filter"));
1575 toggleFilter
->setText(i18nc("@action:inmenu", "Toggle Filter Bar"));
1576 toggleFilter
->setIconText(i18nc("@action:intoolbar", "Filter"));
1577 toggleFilter
->setIcon(showFilterBar
->icon());
1578 toggleFilter
->setToolTip(showFilterBar
->toolTip());
1579 toggleFilter
->setWhatsThis(showFilterBar
->whatsThis());
1580 toggleFilter
->setCheckable(true);
1581 connect(toggleFilter
, &QAction::triggered
, this, &DolphinMainWindow::toggleFilterBar
);
1583 QAction
*searchAction
= KStandardAction::find(this, &DolphinMainWindow::find
, actionCollection());
1584 searchAction
->setText(i18n("Search..."));
1585 searchAction
->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
1586 searchAction
->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This helps you "
1587 "find files and folders by opening a <emphasis>find bar</emphasis>. "
1588 "There you can enter search terms and specify settings to find the "
1589 "objects you are looking for.</para><para>Use this help again on "
1590 "the find bar so we can have a look at it while the settings are "
1591 "explained.</para>"));
1593 // toggle_search acts as a copy of the main searchAction to be used mainly
1594 // in the toolbar, with no default shortcut attached, to avoid messing with
1595 // existing workflows (search bar always open and Ctrl-F to focus)
1596 QAction
*toggleSearchAction
= actionCollection()->addAction(QStringLiteral("toggle_search"));
1597 toggleSearchAction
->setText(i18nc("@action:inmenu", "Toggle Search Bar"));
1598 toggleSearchAction
->setIconText(i18nc("@action:intoolbar", "Search"));
1599 toggleSearchAction
->setIcon(searchAction
->icon());
1600 toggleSearchAction
->setToolTip(searchAction
->toolTip());
1601 toggleSearchAction
->setWhatsThis(searchAction
->whatsThis());
1602 toggleSearchAction
->setCheckable(true);
1604 QAction
* selectAllAction
= KStandardAction::selectAll(this, &DolphinMainWindow::selectAll
, actionCollection());
1605 selectAllAction
->setWhatsThis(xi18nc("@info:whatsthis", "This selects all "
1606 "files and folders in the current location."));
1608 QAction
* invertSelection
= actionCollection()->addAction(QStringLiteral("invert_selection"));
1609 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1610 invertSelection
->setWhatsThis(xi18nc("@info:whatsthis invert", "This selects all "
1611 "objects that you have currently <emphasis>not</emphasis> selected instead."));
1612 invertSelection
->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert")));
1613 actionCollection()->setDefaultShortcut(invertSelection
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1614 connect(invertSelection
, &QAction::triggered
, this, &DolphinMainWindow::invertSelection
);
1616 // setup 'View' menu
1617 // (note that most of it is set up in DolphinViewActionHandler)
1619 QAction
* split
= actionCollection()->addAction(QStringLiteral("split_view"));
1620 split
->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This splits "
1621 "the folder view below into two autonomous views.</para><para>This "
1622 "way you can see two locations at once and move items between them "
1623 "quickly.</para>Click this again afterwards to recombine the views."));
1624 actionCollection()->setDefaultShortcut(split
, Qt::Key_F3
);
1625 connect(split
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitView
);
1627 QAction
* stashSplit
= actionCollection()->addAction(QStringLiteral("split_stash"));
1628 actionCollection()->setDefaultShortcut(stashSplit
, Qt::CTRL
| Qt::Key_S
);
1629 stashSplit
->setText(i18nc("@action:intoolbar Stash", "Stash"));
1630 stashSplit
->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
1631 stashSplit
->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
1632 stashSplit
->setCheckable(false);
1633 QDBusConnectionInterface
*sessionInterface
= QDBusConnection::sessionBus().interface();
1634 stashSplit
->setVisible(sessionInterface
&& sessionInterface
->isServiceRegistered(QStringLiteral("org.kde.kio.StashNotifier")));
1635 connect(stashSplit
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitStash
);
1637 KStandardAction::redisplay(this, &DolphinMainWindow::reloadView
, actionCollection());
1639 QAction
* stop
= actionCollection()->addAction(QStringLiteral("stop"));
1640 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1641 stop
->setToolTip(i18nc("@info", "Stop loading"));
1642 stop
->setWhatsThis(i18nc("@info", "This stops the loading of the contents of the current folder."));
1643 stop
->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
1644 connect(stop
, &QAction::triggered
, this, &DolphinMainWindow::stopLoading
);
1646 KToggleAction
* editableLocation
= actionCollection()->add
<KToggleAction
>(QStringLiteral("editable_location"));
1647 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1648 editableLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1649 "This toggles the <emphasis>Location Bar</emphasis> to be "
1650 "editable so you can directly enter a location you want to go to.<nl/>"
1651 "You can also switch to editing by clicking to the right of the "
1652 "location and switch back by confirming the edited location."));
1653 actionCollection()->setDefaultShortcut(editableLocation
, Qt::Key_F6
);
1654 connect(editableLocation
, &KToggleAction::triggered
, this, &DolphinMainWindow::toggleEditLocation
);
1656 QAction
* replaceLocation
= actionCollection()->addAction(QStringLiteral("replace_location"));
1657 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1658 // i18n: "enter" is used both in the meaning of "writing" and "going to" a new location here.
1659 // Both meanings are useful but not necessary to understand the use of "Replace Location".
1660 // So you might want to be more verbose in your language to convey the meaning but it's up to you.
1661 replaceLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1662 "This switches to editing the location and selects it "
1663 "so you can quickly enter a different location."));
1664 actionCollection()->setDefaultShortcut(replaceLocation
, Qt::CTRL
| Qt::Key_L
);
1665 connect(replaceLocation
, &QAction::triggered
, this, &DolphinMainWindow::replaceLocation
);
1669 QScopedPointer
<QAction
> backAction(KStandardAction::back(nullptr, nullptr, nullptr));
1670 m_backAction
= new KToolBarPopupAction(backAction
->icon(), backAction
->text(), actionCollection());
1671 m_backAction
->setObjectName(backAction
->objectName());
1672 m_backAction
->setShortcuts(backAction
->shortcuts());
1674 m_backAction
->setPopupMode(QToolButton::DelayedPopup
);
1675 connect(m_backAction
, &QAction::triggered
, this, &DolphinMainWindow::goBack
);
1676 connect(m_backAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowBackPopupMenu
);
1677 connect(m_backAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoBack
);
1678 actionCollection()->addAction(m_backAction
->objectName(), m_backAction
);
1680 auto backShortcuts
= m_backAction
->shortcuts();
1681 backShortcuts
.append(QKeySequence(Qt::Key_Backspace
));
1682 actionCollection()->setDefaultShortcuts(m_backAction
, backShortcuts
);
1684 DolphinRecentTabsMenu
* recentTabsMenu
= new DolphinRecentTabsMenu(this);
1685 actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu
);
1686 connect(m_tabWidget
, &DolphinTabWidget::rememberClosedTab
,
1687 recentTabsMenu
, &DolphinRecentTabsMenu::rememberClosedTab
);
1688 connect(recentTabsMenu
, &DolphinRecentTabsMenu::restoreClosedTab
,
1689 m_tabWidget
, &DolphinTabWidget::restoreClosedTab
);
1690 connect(recentTabsMenu
, &DolphinRecentTabsMenu::closedTabsCountChanged
,
1691 this, &DolphinMainWindow::closedTabsCountChanged
);
1693 QAction
* undoCloseTab
= actionCollection()->addAction(QStringLiteral("undo_close_tab"));
1694 undoCloseTab
->setText(i18nc("@action:inmenu File", "Undo close tab"));
1695 undoCloseTab
->setWhatsThis(i18nc("@info:whatsthis undo close tab",
1696 "This returns you to the previously closed tab."));
1697 actionCollection()->setDefaultShortcut(undoCloseTab
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_T
);
1698 undoCloseTab
->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
1699 undoCloseTab
->setEnabled(false);
1700 connect(undoCloseTab
, &QAction::triggered
, recentTabsMenu
, &DolphinRecentTabsMenu::undoCloseTab
);
1702 auto undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
1703 undoAction
->setWhatsThis(xi18nc("@info:whatsthis", "This undoes "
1704 "the last change you made to files or folders.<nl/>"
1705 "Such changes include <interface>creating, renaming</interface> "
1706 "and <interface>moving</interface> them to a different location "
1707 "or to the <filename>Trash</filename>. <nl/>Changes that can't "
1708 "be undone will ask for your confirmation."));
1709 undoAction
->setEnabled(false); // undo should be disabled by default
1712 QScopedPointer
<QAction
> forwardAction(KStandardAction::forward(nullptr, nullptr, nullptr));
1713 m_forwardAction
= new KToolBarPopupAction(forwardAction
->icon(), forwardAction
->text(), actionCollection());
1714 m_forwardAction
->setObjectName(forwardAction
->objectName());
1715 m_forwardAction
->setShortcuts(forwardAction
->shortcuts());
1717 m_forwardAction
->setPopupMode(QToolButton::DelayedPopup
);
1718 connect(m_forwardAction
, &QAction::triggered
, this, &DolphinMainWindow::goForward
);
1719 connect(m_forwardAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowForwardPopupMenu
);
1720 connect(m_forwardAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoForward
);
1721 actionCollection()->addAction(m_forwardAction
->objectName(), m_forwardAction
);
1722 actionCollection()->setDefaultShortcuts(m_forwardAction
, m_forwardAction
->shortcuts());
1724 // enable middle-click to open in a new tab
1725 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
1726 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotBackForwardActionMiddleClicked
);
1727 m_backAction
->menu()->installEventFilter(middleClickEventFilter
);
1728 m_forwardAction
->menu()->installEventFilter(middleClickEventFilter
);
1729 KStandardAction::up(this, &DolphinMainWindow::goUp
, actionCollection());
1730 QAction
* homeAction
= KStandardAction::home(this, &DolphinMainWindow::goHome
, actionCollection());
1731 homeAction
->setWhatsThis(xi18nc("@info:whatsthis", "Go to your "
1732 "<filename>Home</filename> folder.<nl/>Every user account "
1733 "has their own <filename>Home</filename> that contains their data "
1734 "including folders that contain personal application data."));
1736 // setup 'Tools' menu
1737 QAction
* compareFiles
= actionCollection()->addAction(QStringLiteral("compare_files"));
1738 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1739 compareFiles
->setIcon(QIcon::fromTheme(QStringLiteral("kompare")));
1740 compareFiles
->setEnabled(false);
1741 connect(compareFiles
, &QAction::triggered
, this, &DolphinMainWindow::compareFiles
);
1743 QAction
* openPreferredSearchTool
= actionCollection()->addAction(QStringLiteral("open_preferred_search_tool"));
1744 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1745 openPreferredSearchTool
->setWhatsThis(xi18nc("@info:whatsthis",
1746 "<para>This opens a preferred search tool for the viewed location.</para>"
1747 "<para>Use <emphasis>More Search Tools</emphasis> menu to configure it.</para>"));
1748 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1749 actionCollection()->setDefaultShortcut(openPreferredSearchTool
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F
);
1750 connect(openPreferredSearchTool
, &QAction::triggered
, this, &DolphinMainWindow::openPreferredSearchTool
);
1752 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1753 QAction
* openTerminal
= actionCollection()->addAction(QStringLiteral("open_terminal"));
1754 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1755 openTerminal
->setWhatsThis(xi18nc("@info:whatsthis",
1756 "<para>This opens a <emphasis>terminal</emphasis> application for the viewed location.</para>"
1757 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1758 openTerminal
->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
1759 actionCollection()->setDefaultShortcut(openTerminal
, Qt::SHIFT
| Qt::Key_F4
);
1760 connect(openTerminal
, &QAction::triggered
, this, &DolphinMainWindow::openTerminal
);
1762 QAction
* openTerminalHere
= actionCollection()->addAction(QStringLiteral("open_terminal_here"));
1763 // i18n: "Here" refers to the location(s) of the currently selected item(s) or the currently viewed location if nothing is selected.
1764 openTerminalHere
->setText(i18nc("@action:inmenu Tools", "Open Terminal Here"));
1765 openTerminalHere
->setWhatsThis(xi18nc("@info:whatsthis",
1766 "<para>This opens <emphasis>terminal</emphasis> applications for the selected items' locations.</para>"
1767 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1768 openTerminalHere
->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
1769 actionCollection()->setDefaultShortcut(openTerminalHere
, Qt::SHIFT
| Qt::ALT
| Qt::Key_F4
);
1770 connect(openTerminalHere
, &QAction::triggered
, this, &DolphinMainWindow::openTerminalHere
);
1773 QAction
* focusTerminalPanel
= actionCollection()->addAction(QStringLiteral("focus_terminal_panel"));
1774 focusTerminalPanel
->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
1775 focusTerminalPanel
->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
1776 actionCollection()->setDefaultShortcut(focusTerminalPanel
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F4
);
1777 connect(focusTerminalPanel
, &QAction::triggered
, this, &DolphinMainWindow::focusTerminalPanel
);
1781 // setup 'Bookmarks' menu
1782 KActionMenu
*bookmarkMenu
= new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this);
1783 bookmarkMenu
->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks")));
1784 // Make the toolbar button version work properly on click
1785 bookmarkMenu
->setPopupMode(QToolButton::InstantPopup
);
1786 m_bookmarkHandler
= new DolphinBookmarkHandler(this, actionCollection(), bookmarkMenu
->menu(), this);
1787 actionCollection()->addAction(QStringLiteral("bookmarks"), bookmarkMenu
);
1789 // setup 'Settings' menu
1790 KToggleAction
* showMenuBar
= KStandardAction::showMenubar(nullptr, nullptr, actionCollection());
1791 showMenuBar
->setWhatsThis(xi18nc("@info:whatsthis",
1792 "This switches between having a <emphasis>Menubar</emphasis> "
1793 "and having a <interface>Control</interface> button. Both "
1794 "contain mostly the same commands and configuration options."));
1795 connect(showMenuBar
, &KToggleAction::triggered
, // Fixes #286822
1796 this, &DolphinMainWindow::toggleShowMenuBar
, Qt::QueuedConnection
);
1797 KStandardAction::keyBindings(this, &DolphinMainWindow::slotKeyBindings
, actionCollection());
1798 KStandardAction::preferences(this, &DolphinMainWindow::editSettings
, actionCollection());
1800 // setup 'Help' menu for the m_controlButton. The other one is set up in the base class.
1801 m_helpMenu
= new KHelpMenu(nullptr);
1802 m_helpMenu
->menu()->installEventFilter(this);
1803 // remove duplicate shortcuts
1804 auto removeHelpActionShortcut
= [this](KHelpMenu::MenuId menuId
) {
1805 if (auto *action
= m_helpMenu
->action(menuId
)) {
1806 action
->setShortcut(QKeySequence());
1809 removeHelpActionShortcut(KHelpMenu::menuHelpContents
);
1810 removeHelpActionShortcut(KHelpMenu::menuWhatsThis
);
1812 // not in menu actions
1813 QList
<QKeySequence
> nextTabKeys
= KStandardShortcut::tabNext();
1814 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
1816 QList
<QKeySequence
> prevTabKeys
= KStandardShortcut::tabPrev();
1817 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
1819 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1820 QAction
* activateTab
= actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i
));
1821 activateTab
->setText(i18nc("@action:inmenu", "Activate Tab %1", i
+ 1));
1822 activateTab
->setEnabled(false);
1823 connect(activateTab
, &QAction::triggered
, this, [this, i
]() { m_tabWidget
->activateTab(i
); });
1825 // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts
1827 actionCollection()->setDefaultShortcut(activateTab
, QStringLiteral("Alt+%1").arg(i
+ 1));
1831 QAction
* activateLastTab
= actionCollection()->addAction(QStringLiteral("activate_last_tab"));
1832 activateLastTab
->setText(i18nc("@action:inmenu", "Activate Last Tab"));
1833 activateLastTab
->setEnabled(false);
1834 connect(activateLastTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateLastTab
);
1835 actionCollection()->setDefaultShortcut(activateLastTab
, Qt::ALT
| Qt::Key_0
);
1837 QAction
* activateNextTab
= actionCollection()->addAction(QStringLiteral("activate_next_tab"));
1838 activateNextTab
->setIconText(i18nc("@action:inmenu", "Next Tab"));
1839 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1840 activateNextTab
->setEnabled(false);
1841 connect(activateNextTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateNextTab
);
1842 actionCollection()->setDefaultShortcuts(activateNextTab
, nextTabKeys
);
1844 QAction
* activatePrevTab
= actionCollection()->addAction(QStringLiteral("activate_prev_tab"));
1845 activatePrevTab
->setIconText(i18nc("@action:inmenu", "Previous Tab"));
1846 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1847 activatePrevTab
->setEnabled(false);
1848 connect(activatePrevTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activatePrevTab
);
1849 actionCollection()->setDefaultShortcuts(activatePrevTab
, prevTabKeys
);
1852 QAction
* showTarget
= actionCollection()->addAction(QStringLiteral("show_target"));
1853 showTarget
->setText(i18nc("@action:inmenu", "Show Target"));
1854 showTarget
->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
1855 showTarget
->setEnabled(false);
1856 connect(showTarget
, &QAction::triggered
, this, &DolphinMainWindow::showTarget
);
1858 QAction
* openInNewTab
= actionCollection()->addAction(QStringLiteral("open_in_new_tab"));
1859 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1860 openInNewTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1861 connect(openInNewTab
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
1863 QAction
* openInNewTabs
= actionCollection()->addAction(QStringLiteral("open_in_new_tabs"));
1864 openInNewTabs
->setText(i18nc("@action:inmenu", "Open in New Tabs"));
1865 openInNewTabs
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1866 connect(openInNewTabs
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
1868 QAction
* openInNewWindow
= actionCollection()->addAction(QStringLiteral("open_in_new_window"));
1869 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1870 openInNewWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1871 connect(openInNewWindow
, &QAction::triggered
, this, &DolphinMainWindow::openInNewWindow
);
1874 void DolphinMainWindow::setupDockWidgets()
1876 const bool lock
= GeneralSettings::lockPanels();
1878 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(lock
);
1880 KDualAction
* lockLayoutAction
= actionCollection()->add
<KDualAction
>(QStringLiteral("lock_panels"));
1881 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1882 lockLayoutAction
->setActiveIcon(QIcon::fromTheme(QStringLiteral("object-unlocked")));
1883 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1884 lockLayoutAction
->setInactiveIcon(QIcon::fromTheme(QStringLiteral("object-locked")));
1885 lockLayoutAction
->setWhatsThis(xi18nc("@info:whatsthis", "This "
1886 "switches between having panels <emphasis>locked</emphasis> or "
1887 "<emphasis>unlocked</emphasis>.<nl/>Unlocked panels can be "
1888 "dragged to the other side of the window and have a close "
1889 "button.<nl/>Locked panels are embedded more cleanly."));
1890 lockLayoutAction
->setActive(lock
);
1891 connect(lockLayoutAction
, &KDualAction::triggered
, this, &DolphinMainWindow::togglePanelLockState
);
1893 // Setup "Information"
1894 DolphinDockWidget
* infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
1895 infoDock
->setLocked(lock
);
1896 infoDock
->setObjectName(QStringLiteral("infoDock"));
1897 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1900 InformationPanel
* infoPanel
= new InformationPanel(infoDock
);
1901 infoPanel
->setCustomContextMenuActions({lockLayoutAction
});
1902 connect(infoPanel
, &InformationPanel::urlActivated
, this, &DolphinMainWindow::handleUrl
);
1903 infoDock
->setWidget(infoPanel
);
1905 QAction
* infoAction
= infoDock
->toggleViewAction();
1906 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-information")), Qt::Key_F11
, infoAction
, QStringLiteral("show_information_panel"));
1908 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1909 connect(this, &DolphinMainWindow::urlChanged
,
1910 infoPanel
, &InformationPanel::setUrl
);
1911 connect(this, &DolphinMainWindow::selectionChanged
,
1912 infoPanel
, &InformationPanel::setSelection
);
1913 connect(this, &DolphinMainWindow::requestItemInfo
,
1914 infoPanel
, &InformationPanel::requestDelayedItemInfo
);
1915 connect(this, &DolphinMainWindow::fileItemsChanged
,
1916 infoPanel
, &InformationPanel::slotFilesItemChanged
);
1919 // i18n: This is the last paragraph for the "What's This"-texts of all four panels.
1920 const QString panelWhatsThis
= xi18nc("@info:whatsthis", "<para>To show or "
1921 "hide panels like this go to <interface>Control|Panels</interface> "
1922 "or <interface>View|Panels</interface>.</para>");
1924 actionCollection()->action(QStringLiteral("show_information_panel"))
1925 ->setWhatsThis(xi18nc("@info:whatsthis", "<para> This toggles the "
1926 "<emphasis>information</emphasis> panel at the right side of the "
1927 "window.</para><para>The panel provides in-depth information "
1928 "about the items your mouse is hovering over or about the selected "
1929 "items. Otherwise it informs you about the currently viewed folder.<nl/>"
1930 "For single items a preview of their contents is provided.</para>"));
1932 infoDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
1933 "provides in-depth information about the items your mouse is "
1934 "hovering over or about the selected items. Otherwise it informs "
1935 "you about the currently viewed folder.<nl/>For single items a "
1936 "preview of their contents is provided.</para><para>You can configure "
1937 "which and how details are given here by right-clicking.</para>") + panelWhatsThis
);
1940 DolphinDockWidget
* foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
1941 foldersDock
->setLocked(lock
);
1942 foldersDock
->setObjectName(QStringLiteral("foldersDock"));
1943 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1944 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1945 foldersPanel
->setCustomContextMenuActions({lockLayoutAction
});
1946 foldersDock
->setWidget(foldersPanel
);
1948 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1949 createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7
, foldersAction
, QStringLiteral("show_folders_panel"));
1951 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1952 connect(this, &DolphinMainWindow::urlChanged
,
1953 foldersPanel
, &FoldersPanel::setUrl
);
1954 connect(foldersPanel
, &FoldersPanel::folderActivated
,
1955 this, &DolphinMainWindow::changeUrl
);
1956 connect(foldersPanel
, &FoldersPanel::folderInNewTab
,
1957 this, &DolphinMainWindow::openNewTab
);
1958 connect(foldersPanel
, &FoldersPanel::folderInNewActiveTab
,
1959 this, &DolphinMainWindow::openNewTabAndActivate
);
1960 connect(foldersPanel
, &FoldersPanel::errorMessage
,
1961 this, &DolphinMainWindow::showErrorMessage
);
1963 actionCollection()->action(QStringLiteral("show_folders_panel"))
1964 ->setWhatsThis(xi18nc("@info:whatsthis", "This toggles the "
1965 "<emphasis>folders</emphasis> panel at the left side of the window."
1966 "<nl/><nl/>It shows the folders of the <emphasis>file system"
1967 "</emphasis> in a <emphasis>tree view</emphasis>."));
1968 foldersDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
1969 "shows the folders of the <emphasis>file system</emphasis> in a "
1970 "<emphasis>tree view</emphasis>.</para><para>Click a folder to go "
1971 "there. Click the arrow to the left of a folder to see its subfolders. "
1972 "This allows quick switching between any folders.</para>") + panelWhatsThis
);
1976 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1977 DolphinDockWidget
* terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1978 terminalDock
->setLocked(lock
);
1979 terminalDock
->setObjectName(QStringLiteral("terminalDock"));
1980 m_terminalPanel
= new TerminalPanel(terminalDock
);
1981 m_terminalPanel
->setCustomContextMenuActions({lockLayoutAction
});
1982 terminalDock
->setWidget(m_terminalPanel
);
1984 connect(m_terminalPanel
, &TerminalPanel::hideTerminalPanel
, terminalDock
, &DolphinDockWidget::hide
);
1985 connect(m_terminalPanel
, &TerminalPanel::changeUrl
, this, &DolphinMainWindow::slotTerminalDirectoryChanged
);
1986 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
,
1987 m_terminalPanel
, &TerminalPanel::dockVisibilityChanged
);
1988 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
,
1989 this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged
);
1991 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1992 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4
, terminalAction
, QStringLiteral("show_terminal_panel"));
1994 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1995 connect(this, &DolphinMainWindow::urlChanged
,
1996 m_terminalPanel
, &TerminalPanel::setUrl
);
1998 if (GeneralSettings::version() < 200) {
1999 terminalDock
->hide();
2002 actionCollection()->action(QStringLiteral("show_terminal_panel"))
2003 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
2004 "<emphasis>terminal</emphasis> panel at the bottom of the window."
2005 "<nl/>The location in the terminal will always match the folder "
2006 "view so you can navigate using either.</para><para>The terminal "
2007 "panel is not needed for basic computer usage but can be useful "
2008 "for advanced tasks. To learn more about terminals use the help "
2009 "in a standalone terminal application like Konsole.</para>"));
2010 terminalDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is "
2011 "the <emphasis>terminal</emphasis> panel. It behaves like a "
2012 "normal terminal but will match the location of the folder view "
2013 "so you can navigate using either.</para><para>The terminal panel "
2014 "is not needed for basic computer usage but can be useful for "
2015 "advanced tasks. To learn more about terminals use the help in a "
2016 "standalone terminal application like Konsole.</para>") + panelWhatsThis
);
2020 if (GeneralSettings::version() < 200) {
2022 foldersDock
->hide();
2026 DolphinDockWidget
* placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
2027 placesDock
->setLocked(lock
);
2028 placesDock
->setObjectName(QStringLiteral("placesDock"));
2029 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2031 m_placesPanel
= new PlacesPanel(placesDock
);
2032 m_placesPanel
->setCustomContextMenuActions({lockLayoutAction
});
2033 placesDock
->setWidget(m_placesPanel
);
2035 QAction
*placesAction
= placesDock
->toggleViewAction();
2036 createPanelAction(QIcon::fromTheme(QStringLiteral("compass")), Qt::Key_F9
, placesAction
, QStringLiteral("show_places_panel"));
2038 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
2039 connect(m_placesPanel
, &PlacesPanel::placeActivated
,
2040 this, &DolphinMainWindow::slotPlaceActivated
);
2041 connect(m_placesPanel
, &PlacesPanel::tabRequested
,
2042 this, &DolphinMainWindow::openNewTab
);
2043 connect(m_placesPanel
, &PlacesPanel::activeTabRequested
,
2044 this, &DolphinMainWindow::openNewTabAndActivate
);
2045 connect(m_placesPanel
, &PlacesPanel::newWindowRequested
, this, [this](const QUrl
&url
) {
2046 Dolphin::openNewWindow({url
}, this);
2048 connect(m_placesPanel
, &PlacesPanel::errorMessage
,
2049 this, &DolphinMainWindow::showErrorMessage
);
2050 connect(this, &DolphinMainWindow::urlChanged
,
2051 m_placesPanel
, &PlacesPanel::setUrl
);
2052 connect(placesDock
, &DolphinDockWidget::visibilityChanged
,
2053 &DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged
);
2054 connect(this, &DolphinMainWindow::settingsChanged
,
2055 m_placesPanel
, &PlacesPanel::readSettings
);
2056 connect(m_placesPanel
, &PlacesPanel::storageTearDownRequested
,
2057 this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested
);
2058 connect(m_placesPanel
, &PlacesPanel::storageTearDownExternallyRequested
,
2059 this, &DolphinMainWindow::slotStorageTearDownExternallyRequested
);
2060 DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged(m_placesPanel
->isVisible());
2062 auto actionShowAllPlaces
= new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this);
2063 actionShowAllPlaces
->setCheckable(true);
2064 actionShowAllPlaces
->setDisabled(true);
2065 actionShowAllPlaces
->setWhatsThis(i18nc("@info:whatsthis", "This displays "
2066 "all places in the places panel that have been hidden. They will "
2067 "appear semi-transparent unless you uncheck their hide property."));
2069 connect(actionShowAllPlaces
, &QAction::triggered
, this, [actionShowAllPlaces
, this](bool checked
){
2070 m_placesPanel
->setShowAll(checked
);
2072 connect(m_placesPanel
, &PlacesPanel::allPlacesShownChanged
, actionShowAllPlaces
, &QAction::setChecked
);
2074 actionCollection()->action(QStringLiteral("show_places_panel"))
2075 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
2076 "<emphasis>places</emphasis> panel at the left side of the window."
2077 "</para><para>It allows you to go to locations you have "
2078 "bookmarked and to access disk or media attached to the computer "
2079 "or to the network. It also contains sections to find recently "
2080 "saved files or files of a certain type.</para>"));
2081 placesDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2082 "<emphasis>Places</emphasis> panel. It allows you to go to locations "
2083 "you have bookmarked and to access disk or media attached to the "
2084 "computer or to the network. It also contains sections to find "
2085 "recently saved files or files of a certain type.</para><para>"
2086 "Click on an entry to go there. Click with the right mouse button "
2087 "instead to open any entry in a new tab or new window.</para>"
2088 "<para>New entries can be added by dragging folders onto this panel. "
2089 "Right-click any section or entry to hide it. Right-click an empty "
2090 "space on this panel and select <interface>Show Hidden Places"
2091 "</interface> to display it again.</para>") + panelWhatsThis
);
2093 // Add actions into the "Panels" menu
2094 KActionMenu
* panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Show Panels"), this);
2095 actionCollection()->addAction(QStringLiteral("panels"), panelsMenu
);
2096 panelsMenu
->setIcon(QIcon::fromTheme(QStringLiteral("view-sidetree")));
2097 panelsMenu
->setPopupMode(QToolButton::InstantPopup
);
2098 const KActionCollection
* ac
= actionCollection();
2099 panelsMenu
->addAction(ac
->action(QStringLiteral("show_places_panel")));
2101 panelsMenu
->addAction(ac
->action(QStringLiteral("show_information_panel")));
2103 panelsMenu
->addAction(ac
->action(QStringLiteral("show_folders_panel")));
2104 panelsMenu
->addAction(ac
->action(QStringLiteral("show_terminal_panel")));
2105 panelsMenu
->addSeparator();
2106 panelsMenu
->addAction(actionShowAllPlaces
);
2107 panelsMenu
->addAction(lockLayoutAction
);
2109 connect(panelsMenu
->menu(), &QMenu::aboutToShow
, this, [actionShowAllPlaces
, this]{
2110 actionShowAllPlaces
->setEnabled(DolphinPlacesModelSingleton::instance().placesModel()->hiddenCount());
2115 void DolphinMainWindow::updateFileAndEditActions()
2117 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
2118 const KActionCollection
* col
= actionCollection();
2119 KFileItemListProperties
capabilitiesSource(list
);
2121 QAction
* addToPlacesAction
= col
->action(QStringLiteral("add_to_places"));
2122 QAction
* copyToOtherViewAction
= col
->action(QStringLiteral("copy_to_inactive_split_view"));
2123 QAction
* moveToOtherViewAction
= col
->action(QStringLiteral("move_to_inactive_split_view"));
2124 QAction
* copyLocation
= col
->action(QString("copy_location"));
2126 if (list
.isEmpty()) {
2127 stateChanged(QStringLiteral("has_no_selection"));
2129 addToPlacesAction
->setEnabled(true);
2130 copyToOtherViewAction
->setEnabled(false);
2131 moveToOtherViewAction
->setEnabled(false);
2132 copyLocation
->setEnabled(false);
2134 stateChanged(QStringLiteral("has_selection"));
2136 QAction
* renameAction
= col
->action(KStandardAction::name(KStandardAction::RenameFile
));
2137 QAction
* moveToTrashAction
= col
->action(KStandardAction::name(KStandardAction::MoveToTrash
));
2138 QAction
* deleteAction
= col
->action(KStandardAction::name(KStandardAction::DeleteFile
));
2139 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
2140 QAction
* deleteWithTrashShortcut
= col
->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
2141 QAction
* showTarget
= col
->action(QStringLiteral("show_target"));
2142 QAction
* duplicateAction
= col
->action(QStringLiteral("duplicate")); // see DolphinViewActionHandler
2144 if (list
.length() == 1 && list
.first().isDir()) {
2145 addToPlacesAction
->setEnabled(true);
2147 addToPlacesAction
->setEnabled(false);
2150 if (m_tabWidget
->currentTabPage()->splitViewEnabled()) {
2151 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
2152 KFileItem capabilitiesDestination
;
2154 if (tabPage
->primaryViewActive()) {
2155 capabilitiesDestination
= tabPage
->secondaryViewContainer()->url();
2157 capabilitiesDestination
= tabPage
->primaryViewContainer()->url();
2160 copyToOtherViewAction
->setEnabled(capabilitiesDestination
.isWritable());
2161 moveToOtherViewAction
->setEnabled(capabilitiesSource
.supportsMoving() && capabilitiesDestination
.isWritable());
2163 copyToOtherViewAction
->setEnabled(false);
2164 moveToOtherViewAction
->setEnabled(false);
2167 const bool enableMoveToTrash
= capabilitiesSource
.isLocal() && capabilitiesSource
.supportsMoving();
2169 renameAction
->setEnabled(capabilitiesSource
.supportsMoving());
2170 moveToTrashAction
->setEnabled(enableMoveToTrash
);
2171 deleteAction
->setEnabled(capabilitiesSource
.supportsDeleting());
2172 deleteWithTrashShortcut
->setEnabled(capabilitiesSource
.supportsDeleting() && !enableMoveToTrash
);
2173 cutAction
->setEnabled(capabilitiesSource
.supportsMoving());
2174 copyLocation
->setEnabled(list
.length() == 1);
2175 showTarget
->setEnabled(list
.length() == 1 && list
.at(0).isLink());
2176 duplicateAction
->setEnabled(capabilitiesSource
.supportsWriting());
2180 void DolphinMainWindow::updateViewActions()
2182 m_actionHandler
->updateViewActions();
2184 QAction
* toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
2185 toggleFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
2187 updateSplitAction();
2190 void DolphinMainWindow::updateGoActions()
2192 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
2193 const QUrl currentUrl
= m_activeViewContainer
->url();
2194 // I think this is one of the best places to firstly be confronted
2195 // with a file system and its hierarchy. Talking about the root
2196 // directory might seem too much here but it is the question that
2197 // naturally arises in this context.
2198 goUpAction
->setWhatsThis(xi18nc("@info:whatsthis", "<para>Go to "
2199 "the folder that contains the currently viewed one.</para>"
2200 "<para>All files and folders are organized in a hierarchical "
2201 "<emphasis>file system</emphasis>. At the top of this hierarchy is "
2202 "a directory that contains all data connected to this computer"
2203 "—the <emphasis>root directory</emphasis>.</para>"));
2204 goUpAction
->setEnabled(KIO::upUrl(currentUrl
) != currentUrl
);
2207 void DolphinMainWindow::refreshViews()
2209 m_tabWidget
->refreshViews();
2211 if (GeneralSettings::modifiedStartupSettings()) {
2212 updateWindowTitle();
2215 Q_EMIT
settingsChanged();
2218 void DolphinMainWindow::clearStatusBar()
2220 m_activeViewContainer
->statusBar()->resetToDefaultText();
2223 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
2225 connect(container
, &DolphinViewContainer::showFilterBarChanged
,
2226 this, &DolphinMainWindow::updateFilterBarAction
);
2227 connect(container
, &DolphinViewContainer::writeStateChanged
,
2228 this, &DolphinMainWindow::slotWriteStateChanged
);
2229 connect(container
, &DolphinViewContainer::searchModeEnabledChanged
,
2230 this, &DolphinMainWindow::updateSearchAction
);
2231 connect(container
, &DolphinViewContainer::captionChanged
,
2232 this, &DolphinMainWindow::updateWindowTitle
);
2233 connect(container
, &DolphinViewContainer::tabRequested
,
2234 this, &DolphinMainWindow::openNewTab
);
2235 connect(container
, &DolphinViewContainer::activeTabRequested
,
2236 this, &DolphinMainWindow::openNewTabAndActivate
);
2238 const QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
2239 connect(toggleSearchAction
, &QAction::triggered
, container
, &DolphinViewContainer::setSearchModeEnabled
);
2241 const DolphinView
* view
= container
->view();
2242 connect(view
, &DolphinView::selectionChanged
,
2243 this, &DolphinMainWindow::slotSelectionChanged
);
2244 connect(view
, &DolphinView::requestItemInfo
,
2245 this, &DolphinMainWindow::requestItemInfo
);
2246 connect(view
, &DolphinView::fileItemsChanged
,
2247 this, &DolphinMainWindow::fileItemsChanged
);
2248 connect(view
, &DolphinView::tabRequested
,
2249 this, &DolphinMainWindow::openNewTab
);
2250 connect(view
, &DolphinView::activeTabRequested
,
2251 this, &DolphinMainWindow::openNewTabAndActivate
);
2252 connect(view
, &DolphinView::windowRequested
,
2253 this, &DolphinMainWindow::openNewWindow
);
2254 connect(view
, &DolphinView::requestContextMenu
,
2255 this, &DolphinMainWindow::openContextMenu
);
2256 connect(view
, &DolphinView::directoryLoadingStarted
,
2257 this, &DolphinMainWindow::enableStopAction
);
2258 connect(view
, &DolphinView::directoryLoadingCompleted
,
2259 this, &DolphinMainWindow::disableStopAction
);
2260 connect(view
, &DolphinView::directoryLoadingCompleted
,
2261 this, &DolphinMainWindow::slotDirectoryLoadingCompleted
);
2262 connect(view
, &DolphinView::goBackRequested
,
2263 this, &DolphinMainWindow::goBack
);
2264 connect(view
, &DolphinView::goForwardRequested
,
2265 this, &DolphinMainWindow::goForward
);
2266 connect(view
, &DolphinView::urlActivated
,
2267 this, &DolphinMainWindow::handleUrl
);
2268 connect(view
, &DolphinView::goUpRequested
,
2269 this, &DolphinMainWindow::goUp
);
2271 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::urlChanged
,
2272 this, &DolphinMainWindow::changeUrl
);
2273 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::historyChanged
,
2274 this, &DolphinMainWindow::updateHistory
);
2276 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
2277 (actionCollection()->action(QStringLiteral("url_navigators")));
2278 const KUrlNavigator
*navigator
= m_tabWidget
->currentTabPage()->primaryViewActive() ?
2279 navigators
->primaryUrlNavigator() :
2280 navigators
->secondaryUrlNavigator();
2282 QAction
*editableLocactionAction
= actionCollection()->action(QStringLiteral("editable_location"));
2283 editableLocactionAction
->setChecked(navigator
->isUrlEditable());
2284 connect(navigator
, &KUrlNavigator::editableStateChanged
,
2285 this, &DolphinMainWindow::slotEditableStateChanged
);
2286 connect(navigator
, &KUrlNavigator::tabRequested
,
2287 this, &DolphinMainWindow::openNewTab
);
2288 connect(navigator
, &KUrlNavigator::activeTabRequested
,
2289 this, &DolphinMainWindow::openNewTabAndActivate
);
2290 connect(navigator
, &KUrlNavigator::newWindowRequested
,
2291 this, &DolphinMainWindow::openNewWindow
);
2295 void DolphinMainWindow::updateSplitAction()
2297 QAction
* splitAction
= actionCollection()->action(QStringLiteral("split_view"));
2298 const DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
2299 if (tabPage
->splitViewEnabled()) {
2300 if (GeneralSettings::closeActiveSplitView() ? tabPage
->primaryViewActive() : !tabPage
->primaryViewActive()) {
2301 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2302 splitAction
->setToolTip(i18nc("@info", "Close left view"));
2303 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close")));
2305 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2306 splitAction
->setToolTip(i18nc("@info", "Close right view"));
2307 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close")));
2310 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2311 splitAction
->setToolTip(i18nc("@info", "Split view"));
2312 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2316 void DolphinMainWindow::updateAllowedToolbarAreas()
2318 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
2319 (actionCollection()->action(QStringLiteral("url_navigators")));
2320 if (toolBar()->actions().contains(navigators
)) {
2321 toolBar()->setAllowedAreas(Qt::TopToolBarArea
| Qt::BottomToolBarArea
);
2322 if (toolBarArea(toolBar()) == Qt::LeftToolBarArea
||
2323 toolBarArea(toolBar()) == Qt::RightToolBarArea
) {
2324 addToolBar(Qt::TopToolBarArea
, toolBar());
2327 toolBar()->setAllowedAreas(Qt::AllToolBarAreas
);
2331 bool DolphinMainWindow::isKompareInstalled() const
2333 static bool initialized
= false;
2334 static bool installed
= false;
2336 // TODO: maybe replace this approach later by using a menu
2337 // plugin like kdiff3plugin.cpp
2338 installed
= !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty();
2344 void DolphinMainWindow::createPanelAction(const QIcon
& icon
,
2345 const QKeySequence
& shortcut
,
2346 QAction
* dockAction
,
2347 const QString
& actionName
)
2349 QAction
* panelAction
= actionCollection()->addAction(actionName
);
2350 panelAction
->setCheckable(true);
2351 panelAction
->setChecked(dockAction
->isChecked());
2352 panelAction
->setText(dockAction
->text());
2353 panelAction
->setIcon(icon
);
2354 dockAction
->setIcon(icon
);
2355 actionCollection()->setDefaultShortcut(panelAction
, shortcut
);
2357 connect(panelAction
, &QAction::triggered
, dockAction
, &QAction::trigger
);
2358 connect(dockAction
, &QAction::toggled
, panelAction
, &QAction::setChecked
);
2361 void DolphinMainWindow::setupWhatsThis()
2364 menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2365 "<emphasis>Menubar</emphasis>. It provides access to commands and "
2366 "configuration options. Left-click on any of the menus on this "
2367 "bar to see its contents.</para><para>The Menubar can be hidden "
2368 "by unchecking <interface>Settings|Show Menubar</interface>. Then "
2369 "most of its contents become available through a <interface>Control"
2370 "</interface> button on the <emphasis>Toolbar</emphasis>.</para>"));
2371 toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2372 "<emphasis>Toolbar</emphasis>. It allows quick access to "
2373 "frequently used actions.</para><para>It is highly customizable. "
2374 "All items you see in the <interface>Control</interface> menu or "
2375 "in the <interface>Menubar</interface> can be placed on the "
2376 "Toolbar. Just right-click on it and select <interface>Configure "
2377 "Toolbars…</interface> or find this action in the <interface>"
2378 "Control</interface> or <interface>Settings</interface> menu."
2379 "</para><para>The location of the bar and the style of its "
2380 "buttons can also be changed in the right-click menu. Right-click "
2381 "a button if you want to show or hide its text.</para>"));
2382 m_tabWidget
->setWhatsThis(xi18nc("@info:whatsthis main view",
2383 "<para>Here you can see the <emphasis>folders</emphasis> and "
2384 "<emphasis>files</emphasis> that are at the location described in "
2385 "the <interface>Location Bar</interface> above. This area is the "
2386 "central part of this application where you navigate to the files "
2387 "you want to use.</para><para>For an elaborate and general "
2388 "introduction to this application <link "
2389 "url='https://userbase.kde.org/Dolphin/File_Management#Introduction_to_Dolphin'>"
2390 "click here</link>. This will open an introductory article from "
2391 "the <emphasis>KDE UserBase Wiki</emphasis>.</para><para>For brief "
2392 "explanations of all the features of this <emphasis>view</emphasis> "
2393 "<link url='help:/dolphin/dolphin-view.html'>click here</link> "
2394 "instead. This will open a page from the <emphasis>Handbook"
2395 "</emphasis> that covers the basics.</para>"));
2398 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings
))
2399 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window "
2400 "that lists the <emphasis>keyboard shortcuts</emphasis>.<nl/>"
2401 "There you can set up key combinations to trigger an action when "
2402 "they are pressed simultaneously. All commands in this application can "
2403 "be triggered this way.</para>"));
2404 actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars
))
2405 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window in which "
2406 "you can change which buttons appear on the <emphasis>Toolbar</emphasis>.</para>"
2407 "<para>All items you see in the <interface>Control</interface> menu "
2408 "or in the <interface>Menubar</interface> can also be placed on the Toolbar.</para>"));
2409 actionCollection()->action(KStandardAction::name(KStandardAction::Preferences
))
2410 ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can "
2411 "change a multitude of settings for this application. For an explanation "
2412 "of the various settings go to the chapter <emphasis>Configuring Dolphin"
2413 "</emphasis> in <interface>Help|Dolphin Handbook</interface>."));
2416 // The whatsthis has to be set for the m_helpMenu and for the
2417 // StandardAction separately because both are used in different locations.
2418 // m_helpMenu is only used for createControlButton() button.
2420 auto setStandardActionWhatsThis
= [this](KStandardAction::StandardAction actionId
,
2421 const QString
&whatsThis
) {
2422 if (auto *action
= actionCollection()->action(KStandardAction::name(actionId
))) {
2423 action
->setWhatsThis(whatsThis
);
2426 auto setHelpActionWhatsThis
= [this](KHelpMenu::MenuId menuId
, const QString
&whatsThis
) {
2427 if (auto *action
= m_helpMenu
->action(menuId
)) {
2428 action
->setWhatsThis(whatsThis
);
2432 // Links do not work within the Menubar so texts without links are provided there.
2434 // i18n: If the external link isn't available in your language you should
2435 // probably state the external link language at least in brackets to not
2436 // frustrate the user. If there are multiple languages that the user might
2437 // know with a reasonable chance you might want to have 2 external links.
2438 // The same is in my opinion true for every external link you translate.
2439 const QString whatsThisHelpContents
= xi18nc("@info:whatsthis handbook",
2440 "<para>This opens the Handbook for this application. It provides "
2441 "explanations for every part of <emphasis>Dolphin</emphasis>.</para>");
2442 setStandardActionWhatsThis(KStandardAction::HelpContents
, whatsThisHelpContents
2443 + xi18nc("@info:whatsthis second half of handbook hb text without link",
2444 "<para>If you want more elaborate introductions to the "
2445 "different features of <emphasis>Dolphin</emphasis> "
2446 "go to the KDE UserBase Wiki.</para>"));
2447 setHelpActionWhatsThis(KHelpMenu::menuHelpContents
, whatsThisHelpContents
2448 + xi18nc("@info:whatsthis second half of handbook text with link",
2449 "<para>If you want more elaborate introductions to the "
2450 "different features of <emphasis>Dolphin</emphasis> "
2451 "<link url='https://userbase.kde.org/Dolphin/File_Management'>click here</link>. "
2452 "It will open the dedicated page in the KDE UserBase Wiki.</para>"));
2454 const QString whatsThisWhatsThis
= xi18nc("@info:whatsthis whatsthis button",
2455 "<para>This is the button that invokes the help feature you are "
2456 "using right now! Click it, then click any component of this "
2457 "application to ask \"What's this?\" about it. The mouse cursor "
2458 "will change appearance if no help is available for a spot.</para>");
2459 setStandardActionWhatsThis(KStandardAction::WhatsThis
, whatsThisWhatsThis
2460 + xi18nc("@info:whatsthis second half of whatsthis button text without link",
2461 "<para>There are two other ways to get help for this application: The "
2462 "<interface>Dolphin Handbook</interface> in the <interface>Help"
2463 "</interface> menu and the <emphasis>KDE UserBase Wiki</emphasis> "
2464 "article about <emphasis>File Management</emphasis> online."
2465 "</para><para>The \"What's this?\" help is "
2466 "missing in most other windows so don't get too used to this.</para>"));
2467 setHelpActionWhatsThis(KHelpMenu::menuWhatsThis
, whatsThisWhatsThis
2468 + xi18nc("@info:whatsthis second half of whatsthis button text with link",
2469 "<para>There are two other ways to get help: "
2470 "The <link url='help:/dolphin/index.html'>Dolphin Handbook</link> and "
2471 "the <link url='https://userbase.kde.org/Dolphin/File_Management'>KDE "
2472 "UserBase Wiki</link>.</para><para>The \"What's this?\" help is "
2473 "missing in most other windows so don't get too used to this.</para>"));
2475 const QString whatsThisReportBug
= xi18nc("@info:whatsthis","<para>This opens a "
2476 "window that will guide you through reporting errors or flaws "
2477 "in this application or in other KDE software.</para>");
2478 setStandardActionWhatsThis(KStandardAction::ReportBug
, whatsThisReportBug
);
2479 setHelpActionWhatsThis(KHelpMenu::menuReportBug
, whatsThisReportBug
2480 + xi18nc("@info:whatsthis second half of reportbug text with link",
2481 "<para>High-quality bug reports are much appreciated. To learn "
2482 "how to make your bug report as effective as possible "
2483 "<link url='https://community.kde.org/Get_Involved/Bug_Reporting'>"
2484 "click here</link>.</para>"));
2486 const QString whatsThisDonate
= xi18nc("@info:whatsthis","<para>This opens a "
2487 "<emphasis>web page</emphasis> where you can donate to "
2488 "support the continued work on this application and many "
2489 "other projects by the <emphasis>KDE</emphasis> community.</para>"
2490 "<para>Donating is the easiest and fastest way to efficiently "
2491 "support KDE and its projects. KDE projects are available for "
2492 "free therefore your donation is needed to cover things that "
2493 "require money like servers, contributor meetings, etc.</para>"
2494 "<para><emphasis>KDE e.V.</emphasis> is the non-profit "
2495 "organization behind the KDE community.</para>");
2496 setStandardActionWhatsThis(KStandardAction::Donate
, whatsThisDonate
);
2497 setHelpActionWhatsThis(KHelpMenu::menuDonate
, whatsThisDonate
);
2499 const QString whatsThisSwitchLanguage
= xi18nc("@info:whatsthis",
2500 "With this you can change the language this application uses."
2501 "<nl/>You can even set secondary languages which will be used "
2502 "if texts are not available in your preferred language.");
2503 setStandardActionWhatsThis(KStandardAction::SwitchApplicationLanguage
,
2504 whatsThisSwitchLanguage
);
2505 setHelpActionWhatsThis(KHelpMenu::menuSwitchLanguage
, whatsThisSwitchLanguage
);
2507 const QString whatsThisAboutApp
= xi18nc("@info:whatsthis","This opens a "
2508 "window that informs you about the version, license, "
2509 "used libraries and maintainers of this application.");
2510 setStandardActionWhatsThis(KStandardAction::AboutApp
, whatsThisAboutApp
);
2511 setHelpActionWhatsThis(KHelpMenu::menuAboutApp
, whatsThisAboutApp
);
2513 const QString whatsThisAboutKDE
= xi18nc("@info:whatsthis","This opens a "
2514 "window with information about <emphasis>KDE</emphasis>. "
2515 "The KDE community are the people behind this free software."
2516 "<nl/>If you like using this application but don't know "
2517 "about KDE or want to see a cute dragon have a look!");
2518 setStandardActionWhatsThis(KStandardAction::AboutKDE
, whatsThisAboutKDE
);
2519 setHelpActionWhatsThis(KHelpMenu::menuAboutKDE
, whatsThisAboutKDE
);
2522 bool DolphinMainWindow::addHamburgerMenuToToolbar()
2524 QDomDocument domDocument
= KXMLGUIClient::domDocument();
2525 if (domDocument
.isNull()) {
2528 QDomNode toolbar
= domDocument
.elementsByTagName(QStringLiteral("ToolBar")).at(0);
2529 if (toolbar
.isNull()) {
2533 QDomElement hamburgerMenuElement
= domDocument
.createElement(QStringLiteral("Action"));
2534 hamburgerMenuElement
.setAttribute(QStringLiteral("name"), QStringLiteral("hamburger_menu"));
2535 toolbar
.appendChild(hamburgerMenuElement
);
2537 KXMLGUIFactory::saveConfigFile(domDocument
, xmlFile());
2541 // Make sure to also remove the <KXMLGUIFactory> and <QDomDocument> include
2542 // whenever this method is removed (maybe in the year ~2026).
2545 bool DolphinMainWindow::event(QEvent
*event
)
2547 if (event
->type() == QEvent::WhatsThisClicked
) {
2549 QWhatsThisClickedEvent
* whatsThisEvent
= dynamic_cast<QWhatsThisClickedEvent
*>(event
);
2550 QDesktopServices::openUrl(QUrl(whatsThisEvent
->href()));
2553 return KXmlGuiWindow::event(event
);
2556 bool DolphinMainWindow::eventFilter(QObject
* obj
, QEvent
* event
)
2559 if (event
->type() == QEvent::WhatsThisClicked
) {
2561 QWhatsThisClickedEvent
* whatsThisEvent
= dynamic_cast<QWhatsThisClickedEvent
*>(event
);
2562 QDesktopServices::openUrl(QUrl(whatsThisEvent
->href()));
2568 // Set a sane initial window size
2569 QSize
DolphinMainWindow::sizeHint() const
2571 return KXmlGuiWindow::sizeHint().expandedTo(QSize(760, 550));
2574 void DolphinMainWindow::saveNewToolbarConfig()
2576 KXmlGuiWindow::saveNewToolbarConfig(); // Applies the new config. This has to be called first
2577 // because the rest of this method decides things
2578 // based on the new config.
2579 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
2580 (actionCollection()->action(QStringLiteral("url_navigators")));
2581 if (!toolBar()->actions().contains(navigators
)) {
2582 m_tabWidget
->currentTabPage()->insertNavigatorsWidget(navigators
);
2584 updateAllowedToolbarAreas();
2585 (static_cast<KHamburgerMenu
*>(actionCollection()->action(KStandardAction::name(
2586 KStandardAction::HamburgerMenu
))))->hideActionsOf(toolBar());
2589 void DolphinMainWindow::focusTerminalPanel()
2591 if (m_terminalPanel
->isVisible()) {
2592 if (m_terminalPanel
->terminalHasFocus()) {
2593 m_activeViewContainer
->view()->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2594 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2596 m_terminalPanel
->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2597 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2600 actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger();
2601 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2605 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
2606 KIO::FileUndoManager::UiInterface()
2610 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2614 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
2616 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2618 DolphinViewContainer
* container
= mainWin
->activeViewContainer();
2619 container
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
2621 KIO::FileUndoManager::UiInterface::jobError(job
);
2625 bool DolphinMainWindow::isUrlOpen(const QString
& url
)
2627 return m_tabWidget
->isUrlOpen(QUrl::fromUserInput((url
)));