2 * SPDX-FileCopyrightText: 2006 Peter Penz <peter.penz19@gmail.com>
3 * SPDX-FileCopyrightText: 2006 Stefan Monov <logixoul@gmail.com>
4 * SPDX-FileCopyrightText: 2006 Cvetoslav Ludmiloff <ludmiloff@gmail.com>
6 * SPDX-License-Identifier: GPL-2.0-or-later
9 #include "dolphinmainwindow.h"
11 #include "dolphinmainwindowadaptor.h"
12 #include "config-terminal.h"
14 #include "dolphinbookmarkhandler.h"
15 #include "dolphindockwidget.h"
16 #include "dolphincontextmenu.h"
17 #include "dolphinnavigatorswidgetaction.h"
18 #include "dolphinnewfilemenu.h"
19 #include "dolphinrecenttabsmenu.h"
20 #include "dolphinplacesmodelsingleton.h"
21 #include "dolphinurlnavigatorscontroller.h"
22 #include "dolphinviewcontainer.h"
23 #include "dolphintabpage.h"
24 #include "middleclickactioneventfilter.h"
25 #include "panels/folders/folderspanel.h"
26 #include "panels/places/placespanel.h"
27 #include "panels/terminal/terminalpanel.h"
28 #include "settings/dolphinsettingsdialog.h"
29 #include "statusbar/dolphinstatusbar.h"
30 #include "views/dolphinviewactionhandler.h"
31 #include "views/dolphinremoteencoding.h"
32 #include "views/draganddrophelper.h"
33 #include "views/viewproperties.h"
34 #include "views/dolphinnewfilemenuobserver.h"
35 #include "dolphin_generalsettings.h"
37 #include <KActionCollection>
38 #include <KActionMenu>
39 #include <KAuthorized>
42 #include <KDualAction>
43 #include <KFileItemListProperties>
45 #include <KIO/CommandLauncherJob>
46 #include <KIO/JobUiDelegate>
47 #include <KIO/OpenFileManagerWindowJob>
48 #include <KIO/OpenUrlJob>
49 #include <KJobWidgets>
50 #include <KLocalizedString>
51 #include <KMessageBox>
52 #include <KMoreToolsMenuFactory>
53 #include <KProtocolInfo>
54 #include <KProtocolManager>
56 #include <KShortcutsDialog>
57 #include <KStandardAction>
58 #include <KStartupInfo>
60 #include <KTerminalLauncherJob>
61 #include <KToggleAction>
63 #include <KToolBarPopupAction>
64 #include <KUrlComboBox>
65 #include <KUrlNavigator>
66 #include <KWindowSystem>
67 #include <KXMLGUIFactory>
69 #include <kio_version.h>
71 #include <QApplication>
73 #include <QCloseEvent>
74 #include <QDesktopServices>
76 #include <QDomDocument>
80 #include <QPushButton>
82 #include <QStandardPaths>
84 #include <QToolButton>
85 #include <QWhatsThisClickedEvent>
88 // Used for GeneralSettings::version() to determine whether
89 // an updated version of Dolphin is running.
90 const int CurrentDolphinVersion
= 201;
91 // The maximum number of entries in the back/forward popup menu
92 const int MaxNumberOfNavigationentries
= 12;
93 // The maximum number of "Activate Tab" shortcuts
94 const int MaxActivateTabShortcuts
= 9;
97 DolphinMainWindow::DolphinMainWindow() :
98 KXmlGuiWindow(nullptr),
99 m_newFileMenu(nullptr),
101 m_tabWidget(nullptr),
102 m_activeViewContainer(nullptr),
103 m_actionHandler(nullptr),
104 m_remoteEncoding(nullptr),
106 m_bookmarkHandler(nullptr),
107 m_controlButton(nullptr),
108 m_updateToolBarTimer(nullptr),
109 m_lastHandleUrlOpenJob(nullptr),
110 m_terminalPanel(nullptr),
111 m_placesPanel(nullptr),
112 m_tearDownFromPlacesRequested(false),
113 m_backAction(nullptr),
114 m_forwardAction(nullptr)
116 Q_INIT_RESOURCE(dolphin
);
118 new MainWindowAdaptor(this);
121 setWindowFlags(Qt::WindowContextHelpButtonHint
);
123 setComponentName(QStringLiteral("dolphin"), QGuiApplication::applicationDisplayName());
124 setObjectName(QStringLiteral("Dolphin#"));
126 setStateConfigGroup("State");
128 connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::errorMessage
,
129 this, &DolphinMainWindow::showErrorMessage
);
131 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
132 undoManager
->setUiInterface(new UndoUiInterface());
134 connect(undoManager
, &KIO::FileUndoManager::undoAvailable
,
135 this, &DolphinMainWindow::slotUndoAvailable
);
136 connect(undoManager
, &KIO::FileUndoManager::undoTextChanged
,
137 this, &DolphinMainWindow::slotUndoTextChanged
);
138 connect(undoManager
, &KIO::FileUndoManager::jobRecordingStarted
,
139 this, &DolphinMainWindow::clearStatusBar
);
140 connect(undoManager
, &KIO::FileUndoManager::jobRecordingFinished
,
141 this, &DolphinMainWindow::showCommand
);
143 const bool firstRun
= (GeneralSettings::version() < 200);
145 GeneralSettings::setViewPropsTimestamp(QDateTime::currentDateTime());
148 setAcceptDrops(true);
150 auto *navigatorsWidgetAction
= new DolphinNavigatorsWidgetAction(this);
151 actionCollection()->addAction(QStringLiteral("url_navigators"), navigatorsWidgetAction
);
152 m_tabWidget
= new DolphinTabWidget(navigatorsWidgetAction
, this);
153 m_tabWidget
->setObjectName("tabWidget");
154 connect(m_tabWidget
, &DolphinTabWidget::activeViewChanged
,
155 this, &DolphinMainWindow::activeViewChanged
);
156 connect(m_tabWidget
, &DolphinTabWidget::tabCountChanged
,
157 this, &DolphinMainWindow::tabCountChanged
);
158 connect(m_tabWidget
, &DolphinTabWidget::currentUrlChanged
,
159 this, &DolphinMainWindow::updateWindowTitle
);
160 setCentralWidget(m_tabWidget
);
164 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
165 connect(m_actionHandler
, &DolphinViewActionHandler::actionBeingHandled
, this, &DolphinMainWindow::clearStatusBar
);
166 connect(m_actionHandler
, &DolphinViewActionHandler::createDirectoryTriggered
, this, &DolphinMainWindow::createDirectory
);
168 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
169 connect(this, &DolphinMainWindow::urlChanged
,
170 m_remoteEncoding
, &DolphinRemoteEncoding::slotAboutToOpenUrl
);
174 setupGUI(Save
| Create
| ToolBar
);
175 stateChanged(QStringLiteral("new_file"));
177 QClipboard
* clipboard
= QApplication::clipboard();
178 connect(clipboard
, &QClipboard::dataChanged
,
179 this, &DolphinMainWindow::updatePasteAction
);
181 QAction
* toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
182 toggleFilterBarAction
->setChecked(GeneralSettings::filterBar());
185 menuBar()->setVisible(false);
188 const bool showMenu
= !menuBar()->isHidden();
189 QAction
* showMenuBarAction
= actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar
));
190 showMenuBarAction
->setChecked(showMenu
); // workaround for bug #171080
192 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(actionCollection()->action(
193 KStandardAction::name(KStandardAction::HamburgerMenu
)));
194 hamburgerMenu
->setMenuBar(menuBar());
195 hamburgerMenu
->setShowMenuBarAction(showMenuBarAction
);
196 connect(hamburgerMenu
, &KHamburgerMenu::aboutToShowMenu
,
197 this, &DolphinMainWindow::updateHamburgerMenu
);
198 hamburgerMenu
->hideActionsOf(toolBar());
199 if (GeneralSettings::version() < 201 && !toolBar()->actions().contains(hamburgerMenu
)) {
200 addHamburgerMenuToToolbar();
203 updateAllowedToolbarAreas();
205 // enable middle-click on back/forward/up to open in a new tab
206 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
207 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotToolBarActionMiddleClicked
);
208 toolBar()->installEventFilter(middleClickEventFilter
);
212 connect(KSycoca::self(), &KSycoca::databaseChanged
, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
214 QTimer::singleShot(0, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
216 m_fileItemActions
.setParentWidget(this);
217 connect(&m_fileItemActions
, &KFileItemActions::error
, this, [this](const QString
&errorMessage
) {
218 showErrorMessage(errorMessage
);
221 connect(GeneralSettings::self(), &GeneralSettings::splitViewChanged
,
222 this, &DolphinMainWindow::slotSplitViewChanged
);
225 DolphinMainWindow::~DolphinMainWindow()
227 // This fixes a crash on Wayland when closing the mainwindow while another dialog is open.
228 disconnect(QGuiApplication::clipboard(), &QClipboard::dataChanged
, this, &DolphinMainWindow::updatePasteAction
);
231 QVector
<DolphinViewContainer
*> DolphinMainWindow::viewContainers() const
233 QVector
<DolphinViewContainer
*> viewContainers
;
235 for (int i
= 0; i
< m_tabWidget
->count(); ++i
) {
236 DolphinTabPage
*tabPage
= m_tabWidget
->tabPageAt(i
);
238 viewContainers
<< tabPage
->primaryViewContainer();
239 if (tabPage
->splitViewEnabled()) {
240 viewContainers
<< tabPage
->secondaryViewContainer();
243 return viewContainers
;
246 void DolphinMainWindow::openDirectories(const QList
<QUrl
>& dirs
, bool splitView
)
248 m_tabWidget
->openDirectories(dirs
, splitView
);
251 void DolphinMainWindow::openDirectories(const QStringList
& dirs
, bool splitView
)
253 openDirectories(QUrl::fromStringList(dirs
), splitView
);
256 void DolphinMainWindow::openFiles(const QList
<QUrl
>& files
, bool splitView
)
258 m_tabWidget
->openFiles(files
, splitView
);
261 bool DolphinMainWindow::isFoldersPanelEnabled() const
263 return actionCollection()->action(QStringLiteral("show_folders_panel"))->isChecked();
266 bool DolphinMainWindow::isInformationPanelEnabled() const
269 return actionCollection()->action(QStringLiteral("show_information_panel"))->isChecked();
275 void DolphinMainWindow::openFiles(const QStringList
& files
, bool splitView
)
277 openFiles(QUrl::fromStringList(files
), splitView
);
280 void DolphinMainWindow::activateWindow()
282 window()->setAttribute(Qt::WA_NativeWindow
, true);
283 KStartupInfo::setNewStartupId(window()->windowHandle(), KStartupInfo::startupId());
284 KWindowSystem::activateWindow(window()->effectiveWinId());
287 void DolphinMainWindow::showCommand(CommandType command
)
289 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
291 case KIO::FileUndoManager::Copy
:
292 statusBar
->setText(i18nc("@info:status", "Successfully copied."));
294 case KIO::FileUndoManager::Move
:
295 statusBar
->setText(i18nc("@info:status", "Successfully moved."));
297 case KIO::FileUndoManager::Link
:
298 statusBar
->setText(i18nc("@info:status", "Successfully linked."));
300 case KIO::FileUndoManager::Trash
:
301 statusBar
->setText(i18nc("@info:status", "Successfully moved to trash."));
303 case KIO::FileUndoManager::Rename
:
304 statusBar
->setText(i18nc("@info:status", "Successfully renamed."));
307 case KIO::FileUndoManager::Mkdir
:
308 statusBar
->setText(i18nc("@info:status", "Created folder."));
316 void DolphinMainWindow::pasteIntoFolder()
318 m_activeViewContainer
->view()->pasteIntoFolder();
321 void DolphinMainWindow::changeUrl(const QUrl
&url
)
323 if (!KProtocolManager::supportsListing(url
)) {
324 // The URL navigator only checks for validity, not
325 // if the URL can be listed. An error message is
326 // shown due to DolphinViewContainer::restoreView().
330 m_activeViewContainer
->setUrl(url
);
331 updateFileAndEditActions();
336 Q_EMIT
urlChanged(url
);
339 void DolphinMainWindow::slotTerminalDirectoryChanged(const QUrl
& url
)
341 if (m_tearDownFromPlacesRequested
&& url
== QUrl::fromLocalFile(QDir::homePath())) {
342 m_placesPanel
->proceedWithTearDown();
343 m_tearDownFromPlacesRequested
= false;
346 m_activeViewContainer
->setAutoGrabFocus(false);
348 m_activeViewContainer
->setAutoGrabFocus(true);
351 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
353 KToggleAction
* editableLocationAction
=
354 static_cast<KToggleAction
*>(actionCollection()->action(QStringLiteral("editable_location")));
355 editableLocationAction
->setChecked(editable
);
358 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
360 updateFileAndEditActions();
362 const int selectedUrlsCount
= m_tabWidget
->currentTabPage()->selectedItemsCount();
364 QAction
* compareFilesAction
= actionCollection()->action(QStringLiteral("compare_files"));
365 if (selectedUrlsCount
== 2) {
366 compareFilesAction
->setEnabled(isKompareInstalled());
368 compareFilesAction
->setEnabled(false);
371 Q_EMIT
selectionChanged(selection
);
374 void DolphinMainWindow::updateHistory()
376 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
377 const int index
= urlNavigator
->historyIndex();
379 QAction
* backAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Back
));
381 backAction
->setToolTip(i18nc("@info", "Go back"));
382 backAction
->setWhatsThis(i18nc("@info:whatsthis go back", "Return to the previously viewed folder."));
383 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
386 QAction
* forwardAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Forward
));
388 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
389 forwardAction
->setWhatsThis(xi18nc("@info:whatsthis go forward",
390 "This undoes a <interface>Go|Back</interface> action."));
391 forwardAction
->setEnabled(index
> 0);
395 void DolphinMainWindow::updateFilterBarAction(bool show
)
397 QAction
* toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
398 toggleFilterBarAction
->setChecked(show
);
401 void DolphinMainWindow::openNewMainWindow()
403 Dolphin::openNewWindow({m_activeViewContainer
->url()}, this);
406 void DolphinMainWindow::openNewActivatedTab()
408 // keep browsers compatibility, new tab is always after last one
409 auto openNewTabAfterLastTabConfigured
= GeneralSettings::openNewTabAfterLastTab();
410 GeneralSettings::setOpenNewTabAfterLastTab(true);
411 m_tabWidget
->openNewActivatedTab();
412 GeneralSettings::setOpenNewTabAfterLastTab(openNewTabAfterLastTabConfigured
);
415 void DolphinMainWindow::addToPlaces()
420 // If nothing is selected, act on the current dir
421 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
422 url
= m_activeViewContainer
->url();
423 name
= m_activeViewContainer
->placesText();
425 const auto dirToAdd
= m_activeViewContainer
->view()->selectedItems().first();
426 url
= dirToAdd
.url();
427 name
= dirToAdd
.name();
431 if (m_activeViewContainer
->isSearchModeEnabled()) {
432 icon
= QStringLiteral("folder-saved-search-symbolic");
434 icon
= KIO::iconNameForUrl(url
);
436 DolphinPlacesModelSingleton::instance().placesModel()->addPlace(name
, url
, icon
);
440 void DolphinMainWindow::openNewTab(const QUrl
& url
)
442 m_tabWidget
->openNewTab(url
, QUrl());
445 void DolphinMainWindow::openNewTabAndActivate(const QUrl
&url
)
447 m_tabWidget
->openNewActivatedTab(url
, QUrl());
450 void DolphinMainWindow::openNewWindow(const QUrl
&url
)
452 Dolphin::openNewWindow({url
}, this);
455 void DolphinMainWindow::slotSplitViewChanged()
457 m_tabWidget
->currentTabPage()->setSplitViewEnabled(GeneralSettings::splitView(), WithAnimation
);
461 void DolphinMainWindow::openInNewTab()
463 const KFileItemList
& list
= m_activeViewContainer
->view()->selectedItems();
464 bool tabCreated
= false;
466 for (const KFileItem
& item
: list
) {
467 const QUrl
& url
= DolphinView::openItemAsFolderUrl(item
);
468 if (!url
.isEmpty()) {
474 // if no new tab has been created from the selection
475 // open the current directory in a new tab
477 openNewTab(m_activeViewContainer
->url());
481 void DolphinMainWindow::openInNewWindow()
485 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
486 if (list
.isEmpty()) {
487 newWindowUrl
= m_activeViewContainer
->url();
488 } else if (list
.count() == 1) {
489 const KFileItem
& item
= list
.first();
490 newWindowUrl
= DolphinView::openItemAsFolderUrl(item
);
493 if (!newWindowUrl
.isEmpty()) {
494 Dolphin::openNewWindow({newWindowUrl
}, this);
498 void DolphinMainWindow::showTarget()
500 const auto link
= m_activeViewContainer
->view()->selectedItems().at(0);
501 const auto linkLocationDir
= QFileInfo(link
.localPath()).absoluteDir();
502 auto linkDestination
= link
.linkDest();
503 if (QFileInfo(linkDestination
).isRelative()) {
504 linkDestination
= linkLocationDir
.filePath(linkDestination
);
506 if (QFileInfo::exists(linkDestination
)) {
507 KIO::highlightInFileManager({QUrl::fromLocalFile(linkDestination
).adjusted(QUrl::StripTrailingSlash
)});
509 m_activeViewContainer
->showMessage(xi18nc("@info", "Could not access <filename>%1</filename>.", linkDestination
),
510 DolphinViewContainer::Warning
);
514 void DolphinMainWindow::showEvent(QShowEvent
* event
)
516 KXmlGuiWindow::showEvent(event
);
518 if (!event
->spontaneous()) {
519 m_activeViewContainer
->view()->setFocus();
523 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
525 // Find out if Dolphin is closed directly by the user or
526 // by the session manager because the session is closed
527 bool closedByUser
= true;
528 if (qApp
->isSavingSession()) {
529 closedByUser
= false;
532 if (m_tabWidget
->count() > 1
533 && GeneralSettings::confirmClosingMultipleTabs()
534 && !GeneralSettings::rememberOpenedTabs()
536 // Ask the user if he really wants to quit and close all tabs.
537 // Open a confirmation dialog with 3 buttons:
538 // QDialogButtonBox::Yes -> Quit
539 // QDialogButtonBox::No -> Close only the current tab
540 // QDialogButtonBox::Cancel -> do nothing
541 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
542 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
543 dialog
->setModal(true);
544 QDialogButtonBox
* buttons
= new QDialogButtonBox(QDialogButtonBox::Yes
| QDialogButtonBox::No
| QDialogButtonBox::Cancel
);
545 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KGuiItem(i18nc("@action:button 'Quit Dolphin' button", "&Quit %1", QGuiApplication::applicationDisplayName()), QIcon::fromTheme(QStringLiteral("application-exit"))));
546 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("C&lose Current Tab"), QIcon::fromTheme(QStringLiteral("tab-close"))));
547 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
548 buttons
->button(QDialogButtonBox::Yes
)->setDefault(true);
550 bool doNotAskAgainCheckboxResult
= false;
552 const auto result
= KMessageBox::createKMessageBox(dialog
,
554 QMessageBox::Warning
,
555 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
557 i18n("Do not ask again"),
558 &doNotAskAgainCheckboxResult
,
559 KMessageBox::Notify
);
561 if (doNotAskAgainCheckboxResult
) {
562 GeneralSettings::setConfirmClosingMultipleTabs(false);
566 case QDialogButtonBox::Yes
:
569 case QDialogButtonBox::No
:
570 // Close only the current tab
571 m_tabWidget
->closeTab();
579 if (m_terminalPanel
&& m_terminalPanel
->hasProgramRunning() && GeneralSettings::confirmClosingTerminalRunningProgram() && closedByUser
) {
580 // Ask if the user really wants to quit Dolphin with a program that is still running in the Terminal panel
581 // Open a confirmation dialog with 3 buttons:
582 // QDialogButtonBox::Yes -> Quit
583 // QDialogButtonBox::No -> Show Terminal Panel
584 // QDialogButtonBox::Cancel -> do nothing
585 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
586 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
587 dialog
->setModal(true);
588 auto standardButtons
= QDialogButtonBox::Yes
| QDialogButtonBox::Cancel
;
589 if (!m_terminalPanel
->isVisible()) {
590 standardButtons
|= QDialogButtonBox::No
;
592 QDialogButtonBox
*buttons
= new QDialogButtonBox(standardButtons
);
593 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KStandardGuiItem::quit());
594 if (!m_terminalPanel
->isVisible()) {
596 buttons
->button(QDialogButtonBox::No
),
597 KGuiItem(i18n("Show &Terminal Panel"), QIcon::fromTheme(QStringLiteral("dialog-scripts"))));
599 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
601 bool doNotAskAgainCheckboxResult
= false;
603 const auto result
= KMessageBox::createKMessageBox(
606 QMessageBox::Warning
,
607 i18n("The program '%1' is still running in the Terminal panel. Are you sure you want to quit?", m_terminalPanel
->runningProgramName()),
609 i18n("Do not ask again"),
610 &doNotAskAgainCheckboxResult
,
611 KMessageBox::Dangerous
);
613 if (doNotAskAgainCheckboxResult
) {
614 GeneralSettings::setConfirmClosingTerminalRunningProgram(false);
618 case QDialogButtonBox::Yes
:
621 case QDialogButtonBox::No
:
622 actionCollection()->action("show_terminal_panel")->trigger();
623 // Do not quit, ignore quit event
631 if (GeneralSettings::rememberOpenedTabs()) {
632 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
633 KConfig
*config
= KConfigGui::sessionConfig();
634 saveGlobalProperties(config
);
635 savePropertiesInternal(config
, 1);
639 GeneralSettings::setVersion(CurrentDolphinVersion
);
640 GeneralSettings::self()->save();
642 KXmlGuiWindow::closeEvent(event
);
645 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
647 m_tabWidget
->saveProperties(group
);
650 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
652 m_tabWidget
->readProperties(group
);
655 void DolphinMainWindow::updateNewMenu()
657 m_newFileMenu
->checkUpToDate();
658 m_newFileMenu
->setPopupFiles(QList
<QUrl
>() << activeViewContainer()->url());
661 void DolphinMainWindow::createDirectory()
663 m_newFileMenu
->setPopupFiles(QList
<QUrl
>() << activeViewContainer()->url());
664 m_newFileMenu
->createDirectory();
667 void DolphinMainWindow::quit()
672 void DolphinMainWindow::showErrorMessage(const QString
& message
)
674 m_activeViewContainer
->showMessage(message
, DolphinViewContainer::Error
);
677 void DolphinMainWindow::slotUndoAvailable(bool available
)
679 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
681 undoAction
->setEnabled(available
);
685 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
687 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
689 undoAction
->setText(text
);
693 void DolphinMainWindow::undo()
696 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
697 KIO::FileUndoManager::self()->undo();
700 void DolphinMainWindow::cut()
702 m_activeViewContainer
->view()->cutSelectedItemsToClipboard();
705 void DolphinMainWindow::copy()
707 m_activeViewContainer
->view()->copySelectedItemsToClipboard();
710 void DolphinMainWindow::paste()
712 m_activeViewContainer
->view()->paste();
715 void DolphinMainWindow::find()
717 m_activeViewContainer
->setSearchModeEnabled(true);
720 void DolphinMainWindow::updateSearchAction()
722 QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
723 toggleSearchAction
->setChecked(m_activeViewContainer
->isSearchModeEnabled());
726 void DolphinMainWindow::updatePasteAction()
728 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
729 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
730 pasteAction
->setEnabled(pasteInfo
.first
);
731 pasteAction
->setText(pasteInfo
.second
);
734 void DolphinMainWindow::slotDirectoryLoadingCompleted()
739 void DolphinMainWindow::slotToolBarActionMiddleClicked(QAction
*action
)
741 if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Back
))) {
743 } else if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Forward
))) {
745 } else if (action
== actionCollection()->action(QStringLiteral("go_up"))) {
747 } else if (action
== actionCollection()->action(QStringLiteral("go_home"))) {
752 QAction
*DolphinMainWindow::urlNavigatorHistoryAction(const KUrlNavigator
*urlNavigator
, int historyIndex
, QObject
*parent
)
754 const QUrl url
= urlNavigator
->locationUrl(historyIndex
);
756 QString text
= url
.toDisplayString(QUrl::PreferLocalFile
);
758 if (!urlNavigator
->showFullPath()) {
759 const KFilePlacesModel
*placesModel
= DolphinPlacesModelSingleton::instance().placesModel();
761 const QModelIndex closestIdx
= placesModel
->closestItem(url
);
762 if (closestIdx
.isValid()) {
763 const QUrl placeUrl
= placesModel
->url(closestIdx
);
765 text
= placesModel
->text(closestIdx
);
767 QString pathInsidePlace
= url
.path().mid(placeUrl
.path().length());
769 if (!pathInsidePlace
.isEmpty() && !pathInsidePlace
.startsWith(QLatin1Char('/'))) {
770 pathInsidePlace
.prepend(QLatin1Char('/'));
773 if (pathInsidePlace
!= QLatin1Char('/')) {
774 text
.append(pathInsidePlace
);
779 QAction
*action
= new QAction(QIcon::fromTheme(KIO::iconNameForUrl(url
)), text
, parent
);
780 action
->setData(historyIndex
);
784 void DolphinMainWindow::slotAboutToShowBackPopupMenu()
786 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
788 m_backAction
->menu()->clear();
789 for (int i
= urlNavigator
->historyIndex() + 1; i
< urlNavigator
->historySize() && entries
< MaxNumberOfNavigationentries
; ++i
, ++entries
) {
790 QAction
*action
= urlNavigatorHistoryAction(urlNavigator
, i
, m_backAction
->menu());
792 m_backAction
->menu()->addAction(action
);
796 void DolphinMainWindow::slotGoBack(QAction
* action
)
798 int gotoIndex
= action
->data().value
<int>();
799 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
800 for (int i
= gotoIndex
- urlNavigator
->historyIndex(); i
> 0; --i
) {
805 void DolphinMainWindow::slotBackForwardActionMiddleClicked(QAction
* action
)
808 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
809 openNewTab(urlNavigator
->locationUrl(action
->data().value
<int>()));
813 void DolphinMainWindow::slotAboutToShowForwardPopupMenu()
815 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
817 m_forwardAction
->menu()->clear();
818 for (int i
= urlNavigator
->historyIndex() - 1; i
>= 0 && entries
< MaxNumberOfNavigationentries
; --i
, ++entries
) {
819 QAction
*action
= urlNavigatorHistoryAction(urlNavigator
, i
, m_forwardAction
->menu());
821 m_forwardAction
->menu()->addAction(action
);
825 void DolphinMainWindow::slotGoForward(QAction
* action
)
827 int gotoIndex
= action
->data().value
<int>();
828 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
829 for (int i
= urlNavigator
->historyIndex() - gotoIndex
; i
> 0; --i
) {
834 void DolphinMainWindow::selectAll()
838 // if the URL navigator is editable and focused, select the whole
839 // URL instead of all items of the view
841 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
842 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit();
843 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
844 lineEdit
->hasFocus();
846 lineEdit
->selectAll();
848 m_activeViewContainer
->view()->selectAll();
852 void DolphinMainWindow::invertSelection()
855 m_activeViewContainer
->view()->invertSelection();
858 void DolphinMainWindow::toggleSplitView()
860 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
861 tabPage
->setSplitViewEnabled(!tabPage
->splitViewEnabled(), WithAnimation
);
866 void DolphinMainWindow::toggleSplitStash()
868 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
869 tabPage
->setSplitViewEnabled(false, WithAnimation
);
870 tabPage
->setSplitViewEnabled(true, WithAnimation
, QUrl("stash:/"));
873 void DolphinMainWindow::reloadView()
876 m_activeViewContainer
->reload();
877 m_activeViewContainer
->statusBar()->updateSpaceInfo();
880 void DolphinMainWindow::stopLoading()
882 m_activeViewContainer
->view()->stopLoading();
885 void DolphinMainWindow::enableStopAction()
887 actionCollection()->action(QStringLiteral("stop"))->setEnabled(true);
890 void DolphinMainWindow::disableStopAction()
892 actionCollection()->action(QStringLiteral("stop"))->setEnabled(false);
895 void DolphinMainWindow::showFilterBar()
897 m_activeViewContainer
->setFilterBarVisible(true);
900 void DolphinMainWindow::toggleFilterBar()
902 const bool checked
= !m_activeViewContainer
->isFilterBarVisible();
903 m_activeViewContainer
->setFilterBarVisible(checked
);
905 QAction
* toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
906 toggleFilterBarAction
->setChecked(checked
);
909 void DolphinMainWindow::toggleEditLocation()
913 QAction
* action
= actionCollection()->action(QStringLiteral("editable_location"));
914 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
915 urlNavigator
->setUrlEditable(action
->isChecked());
918 void DolphinMainWindow::replaceLocation()
920 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
921 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit();
923 // If the text field currently has focus and everything is selected,
924 // pressing the keyboard shortcut returns the whole thing to breadcrumb mode
925 if (navigator
->isUrlEditable()
926 && lineEdit
->hasFocus()
927 && lineEdit
->selectedText() == lineEdit
->text() ) {
928 navigator
->setUrlEditable(false);
930 navigator
->setUrlEditable(true);
931 navigator
->setFocus();
932 lineEdit
->selectAll();
936 void DolphinMainWindow::togglePanelLockState()
938 const bool newLockState
= !GeneralSettings::lockPanels();
939 const auto childrenObjects
= children();
940 for (QObject
* child
: childrenObjects
) {
941 DolphinDockWidget
* dock
= qobject_cast
<DolphinDockWidget
*>(child
);
943 dock
->setLocked(newLockState
);
947 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(newLockState
);
949 GeneralSettings::setLockPanels(newLockState
);
952 void DolphinMainWindow::slotTerminalPanelVisibilityChanged()
954 if (m_terminalPanel
->isHiddenInVisibleWindow() && m_activeViewContainer
) {
955 m_activeViewContainer
->view()->setFocus();
959 void DolphinMainWindow::goBack()
961 DolphinUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
962 urlNavigator
->goBack();
964 if (urlNavigator
->locationState().isEmpty()) {
965 // An empty location state indicates a redirection URL,
966 // which must be skipped too
967 urlNavigator
->goBack();
971 void DolphinMainWindow::goForward()
973 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goForward();
976 void DolphinMainWindow::goUp()
978 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goUp();
981 void DolphinMainWindow::goHome()
983 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goHome();
986 void DolphinMainWindow::goBackInNewTab()
988 const KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
989 const int index
= urlNavigator
->historyIndex() + 1;
990 openNewTab(urlNavigator
->locationUrl(index
));
993 void DolphinMainWindow::goForwardInNewTab()
995 const KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
996 const int index
= urlNavigator
->historyIndex() - 1;
997 openNewTab(urlNavigator
->locationUrl(index
));
1000 void DolphinMainWindow::goUpInNewTab()
1002 const QUrl currentUrl
= activeViewContainer()->urlNavigator()->locationUrl();
1003 openNewTab(KIO::upUrl(currentUrl
));
1006 void DolphinMainWindow::goHomeInNewTab()
1008 openNewTab(Dolphin::homeUrl());
1011 void DolphinMainWindow::compareFiles()
1013 const KFileItemList items
= m_tabWidget
->currentTabPage()->selectedItems();
1014 if (items
.count() != 2) {
1015 // The action is disabled in this case, but it could have been triggered
1016 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
1020 QUrl urlA
= items
.at(0).url();
1021 QUrl urlB
= items
.at(1).url();
1023 QString
command(QStringLiteral("kompare -c \""));
1024 command
.append(urlA
.toDisplayString(QUrl::PreferLocalFile
));
1025 command
.append("\" \"");
1026 command
.append(urlB
.toDisplayString(QUrl::PreferLocalFile
));
1027 command
.append('\"');
1029 KIO::CommandLauncherJob
*job
= new KIO::CommandLauncherJob(command
, this);
1030 job
->setDesktopName(QStringLiteral("org.kde.kompare"));
1034 void DolphinMainWindow::toggleShowMenuBar()
1036 const bool visible
= menuBar()->isVisible();
1037 menuBar()->setVisible(!visible
);
1040 QPointer
<QAction
> DolphinMainWindow::preferredSearchTool()
1042 m_searchTools
.clear();
1043 KMoreToolsMenuFactory("dolphin/search-tools").fillMenuFromGroupingNames(
1044 &m_searchTools
, { "files-find" }, m_activeViewContainer
->url()
1046 QList
<QAction
*> actions
= m_searchTools
.actions();
1047 if (actions
.isEmpty()) {
1050 QAction
* action
= actions
.first();
1051 if (action
->isSeparator()) {
1057 void DolphinMainWindow::updateOpenPreferredSearchToolAction()
1059 QAction
* openPreferredSearchTool
= actionCollection()->action(QStringLiteral("open_preferred_search_tool"));
1060 if (!openPreferredSearchTool
) {
1063 QPointer
<QAction
> tool
= preferredSearchTool();
1065 openPreferredSearchTool
->setVisible(true);
1066 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open %1", tool
->text()));
1067 // Only override with the app icon if it is the default, i.e. the user hasn't configured one manually
1068 // https://bugs.kde.org/show_bug.cgi?id=442815
1069 if (openPreferredSearchTool
->icon().name() == QLatin1String("search")) {
1070 openPreferredSearchTool
->setIcon(tool
->icon());
1073 openPreferredSearchTool
->setVisible(false);
1074 // still visible in Shortcuts configuration window
1075 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1076 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1080 void DolphinMainWindow::openPreferredSearchTool()
1082 QPointer
<QAction
> tool
= preferredSearchTool();
1088 void DolphinMainWindow::openTerminal()
1090 openTerminalJob(m_activeViewContainer
->url());
1093 void DolphinMainWindow::openTerminalHere()
1095 QList
<QUrl
> urls
= {};
1097 for (const KFileItem
& item
: m_activeViewContainer
->view()->selectedItems()) {
1098 QUrl url
= item
.targetUrl();
1099 if (item
.isFile()) {
1100 url
.setPath(QFileInfo(url
.path()).absolutePath());
1102 if (!urls
.contains(url
)) {
1107 // No items are selected. Open a terminal window for the current location.
1108 if (urls
.count() == 0) {
1113 if (urls
.count() > 5) {
1114 QString question
= i18np("Are you sure you want to open 1 terminal window?",
1115 "Are you sure you want to open %1 terminal windows?", urls
.count());
1116 const int answer
= KMessageBox::warningYesNo(this, question
);
1117 if (answer
!= KMessageBox::Yes
) {
1122 for (const QUrl
& url
: urls
) {
1123 openTerminalJob(url
);
1127 void DolphinMainWindow::openTerminalJob(const QUrl
& url
)
1129 if (url
.isLocalFile()) {
1130 auto job
= new KTerminalLauncherJob(QString());
1131 job
->setWorkingDirectory(url
.toLocalFile());
1136 // Not a local file, with protocol Class ":local", try stat'ing
1137 if (KProtocolInfo::protocolClass(url
.scheme()) == QLatin1String(":local")) {
1138 KIO::StatJob
*job
= KIO::mostLocalUrl(url
);
1139 KJobWidgets::setWindow(job
, this);
1140 connect(job
, &KJob::result
, this, [job
]() {
1142 if (!job
->error()) {
1143 statUrl
= job
->mostLocalUrl();
1146 auto job
= new KTerminalLauncherJob(QString());
1147 job
->setWorkingDirectory(statUrl
.isLocalFile() ? statUrl
.toLocalFile() : QDir::homePath());
1154 // Nothing worked, just use $HOME
1155 auto job
= new KTerminalLauncherJob(QString());
1156 job
->setWorkingDirectory(QDir::homePath());
1160 void DolphinMainWindow::editSettings()
1162 if (!m_settingsDialog
) {
1163 DolphinViewContainer
* container
= activeViewContainer();
1164 container
->view()->writeSettings();
1166 const QUrl url
= container
->url();
1167 DolphinSettingsDialog
* settingsDialog
= new DolphinSettingsDialog(url
, this, actionCollection());
1168 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, this, &DolphinMainWindow::refreshViews
);
1169 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
,
1170 &DolphinUrlNavigatorsController::slotReadSettings
);
1171 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1172 settingsDialog
->show();
1173 m_settingsDialog
= settingsDialog
;
1175 m_settingsDialog
.data()->raise();
1179 void DolphinMainWindow::handleUrl(const QUrl
& url
)
1181 delete m_lastHandleUrlOpenJob
;
1182 m_lastHandleUrlOpenJob
= nullptr;
1184 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1185 activeViewContainer()->setUrl(url
);
1187 m_lastHandleUrlOpenJob
= new KIO::OpenUrlJob(url
);
1188 m_lastHandleUrlOpenJob
->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
1189 m_lastHandleUrlOpenJob
->setShowOpenOrExecuteDialog(true);
1191 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::mimeTypeFound
, this,
1192 [this, url
](const QString
&mimetype
) {
1193 if (mimetype
== QLatin1String("inode/directory")) {
1194 // If it's a dir, we'll take it from here
1195 m_lastHandleUrlOpenJob
->kill();
1196 m_lastHandleUrlOpenJob
= nullptr;
1197 activeViewContainer()->setUrl(url
);
1201 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::result
, this, [this]() {
1202 m_lastHandleUrlOpenJob
= nullptr;
1205 m_lastHandleUrlOpenJob
->start();
1209 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1211 // trash:/ is writable but we don't want to create new items in it.
1212 // TODO: remove the trash check once https://phabricator.kde.org/T8234 is implemented
1213 newFileMenu()->setEnabled(isFolderWritable
&& m_activeViewContainer
->url().scheme() != QLatin1String("trash"));
1216 void DolphinMainWindow::openContextMenu(const QPoint
& pos
,
1217 const KFileItem
& item
,
1218 const KFileItemList
&selectedItems
,
1221 QPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, item
, selectedItems
, url
, &m_fileItemActions
);
1222 contextMenu
.data()->exec(pos
);
1224 // Delete the menu, unless it has been deleted in its own nested event loop already.
1226 contextMenu
->deleteLater();
1230 QMenu
*DolphinMainWindow::createPopupMenu()
1232 QMenu
*menu
= KXmlGuiWindow::createPopupMenu();
1234 menu
->addSeparator();
1235 menu
->addAction(actionCollection()->action(QStringLiteral("lock_panels")));
1240 void DolphinMainWindow::updateHamburgerMenu()
1242 KActionCollection
* ac
= actionCollection();
1243 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(
1244 ac
->action(KStandardAction::name(KStandardAction::HamburgerMenu
)));
1245 auto menu
= hamburgerMenu
->menu();
1247 menu
= new QMenu(this);
1248 hamburgerMenu
->setMenu(menu
);
1249 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("basic_actions"))->menu());
1250 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("zoom"))->menu());
1254 const QList
<QAction
*> toolbarActions
= toolBar()->actions();
1256 if (!toolBar()->isVisible()) {
1257 // If neither the menu bar nor the toolbar are visible, these actions should be available.
1258 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)));
1259 menu
->addAction(toolBarMenuAction());
1260 menu
->addSeparator();
1263 // This group of actions (until the next separator) contains all the most basic actions
1264 // necessary to use Dolphin effectively.
1265 menu
->addAction(ac
->action(QStringLiteral("go_back")));
1266 menu
->addAction(ac
->action(QStringLiteral("go_forward")));
1268 menu
->addMenu(m_newFileMenu
->menu());
1269 menu
->addAction(ac
->action(QStringLiteral("basic_actions")));
1270 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Undo
)));
1271 if (!toolBar()->isVisible()
1272 || (!toolbarActions
.contains(ac
->action(QStringLiteral("toggle_search")))
1273 && !toolbarActions
.contains(ac
->action(QStringLiteral("open_preferred_search_tool"))))
1275 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Find
)));
1276 // This way a search action will only be added if none of the three available
1277 // search actions is present on the toolbar.
1279 if (!toolBar()->isVisible()
1280 || !toolbarActions
.contains(ac
->action(QStringLiteral("toggle_filter")))
1282 menu
->addAction(ac
->action(QStringLiteral("show_filter_bar")));
1283 // This way a filter action will only be added if none of the two available
1284 // filter actions is present on the toolbar.
1286 menu
->addSeparator();
1288 // The second group of actions (up until the next separator) contains actions for opening
1289 // additional views to interact with the file system.
1290 menu
->addAction(ac
->action(QStringLiteral("file_new")));
1291 menu
->addAction(ac
->action(QStringLiteral("new_tab")));
1292 if (ac
->action(QStringLiteral("undo_close_tab"))->isEnabled()) {
1293 menu
->addAction(ac
->action(QStringLiteral("closed_tabs")));
1295 menu
->addAction(ac
->action(QStringLiteral("open_terminal")));
1296 menu
->addSeparator();
1298 // The third group contains actions to change what one sees in the view
1299 // and to change the more general UI.
1300 if (!toolBar()->isVisible()
1301 || (!toolbarActions
.contains(ac
->action(QStringLiteral("icons")))
1302 && !toolbarActions
.contains(ac
->action(QStringLiteral("compact")))
1303 && !toolbarActions
.contains(ac
->action(QStringLiteral("details")))
1304 && !toolbarActions
.contains(ac
->action(QStringLiteral("view_mode"))))
1306 menu
->addAction(ac
->action(QStringLiteral("view_mode")));
1308 menu
->addAction(ac
->action(QStringLiteral("show_hidden_files")));
1309 menu
->addAction(ac
->action(QStringLiteral("sort")));
1310 menu
->addAction(ac
->action(QStringLiteral("additional_info")));
1311 if (!GeneralSettings::showStatusBar() || !GeneralSettings::showZoomSlider()) {
1312 menu
->addAction(ac
->action(QStringLiteral("zoom")));
1314 menu
->addAction(ac
->action(QStringLiteral("panels")));
1316 // The "Configure" menu is not added to the actionCollection() because there is hardly
1317 // a good reason for users to put it on their toolbar.
1318 auto configureMenu
= menu
->addMenu(QIcon::fromTheme(QStringLiteral("configure")),
1319 i18nc("@action:inmenu menu for configure actions", "Configure"));
1320 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
)));
1321 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)));
1322 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)));
1323 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Preferences
)));
1324 hamburgerMenu
->hideActionsOf(configureMenu
);
1327 void DolphinMainWindow::slotPlaceActivated(const QUrl
& url
)
1329 DolphinViewContainer
* view
= activeViewContainer();
1331 if (view
->url() == url
) {
1332 // We can end up here if the user clicked a device in the Places Panel
1333 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1336 view
->disableUrlNavigatorSelectionRequests();
1338 view
->enableUrlNavigatorSelectionRequests();
1342 void DolphinMainWindow::closedTabsCountChanged(unsigned int count
)
1344 actionCollection()->action(QStringLiteral("undo_close_tab"))->setEnabled(count
> 0);
1347 void DolphinMainWindow::activeViewChanged(DolphinViewContainer
* viewContainer
)
1349 DolphinViewContainer
* oldViewContainer
= m_activeViewContainer
;
1350 Q_ASSERT(viewContainer
);
1352 m_activeViewContainer
= viewContainer
;
1354 if (oldViewContainer
) {
1355 const QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
1356 toggleSearchAction
->disconnect(oldViewContainer
);
1358 // Disconnect all signals between the old view container (container,
1359 // view and url navigator) and main window.
1360 oldViewContainer
->disconnect(this);
1361 oldViewContainer
->view()->disconnect(this);
1362 oldViewContainer
->urlNavigatorInternalWithHistory()->disconnect(this);
1363 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
1364 (actionCollection()->action(QStringLiteral("url_navigators")));
1365 navigators
->primaryUrlNavigator()->disconnect(this);
1366 if (auto secondaryUrlNavigator
= navigators
->secondaryUrlNavigator()) {
1367 secondaryUrlNavigator
->disconnect(this);
1370 // except the requestItemInfo so that on hover the information panel can still be updated
1371 connect(oldViewContainer
->view(), &DolphinView::requestItemInfo
,
1372 this, &DolphinMainWindow::requestItemInfo
);
1375 connectViewSignals(viewContainer
);
1377 m_actionHandler
->setCurrentView(viewContainer
->view());
1380 updateFileAndEditActions();
1381 updatePasteAction();
1382 updateViewActions();
1384 updateSearchAction();
1386 const QUrl url
= viewContainer
->url();
1387 Q_EMIT
urlChanged(url
);
1390 void DolphinMainWindow::tabCountChanged(int count
)
1392 const bool enableTabActions
= (count
> 1);
1393 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1394 actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i
))->setEnabled(enableTabActions
);
1396 actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions
);
1397 actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions
);
1398 actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions
);
1401 void DolphinMainWindow::updateWindowTitle()
1403 const QString newTitle
= m_activeViewContainer
->captionWindowTitle();
1404 if (windowTitle() != newTitle
) {
1405 setWindowTitle(newTitle
);
1409 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString
& mountPath
)
1411 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1412 setViewsToHomeIfMountPathOpen(mountPath
);
1415 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectory().startsWith(mountPath
)) {
1416 m_tearDownFromPlacesRequested
= true;
1417 m_terminalPanel
->goHome();
1418 // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
1420 m_placesPanel
->proceedWithTearDown();
1424 void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString
& mountPath
)
1426 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1427 setViewsToHomeIfMountPathOpen(mountPath
);
1430 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectory().startsWith(mountPath
)) {
1431 m_tearDownFromPlacesRequested
= false;
1432 m_terminalPanel
->goHome();
1436 void DolphinMainWindow::slotKeyBindings()
1438 KShortcutsDialog
dialog(KShortcutsEditor::AllActions
, KShortcutsEditor::LetterShortcutsAllowed
, this);
1439 dialog
.addCollection(actionCollection());
1440 if (m_terminalPanel
) {
1441 KActionCollection
*konsolePartActionCollection
= m_terminalPanel
->actionCollection();
1442 if (konsolePartActionCollection
) {
1443 dialog
.addCollection(konsolePartActionCollection
, QStringLiteral("KonsolePart"));
1449 void DolphinMainWindow::setViewsToHomeIfMountPathOpen(const QString
& mountPath
)
1451 const QVector
<DolphinViewContainer
*> theViewContainers
= viewContainers();
1452 for (DolphinViewContainer
*viewContainer
: theViewContainers
) {
1453 if (viewContainer
&& viewContainer
->url().toLocalFile().startsWith(mountPath
)) {
1454 viewContainer
->setUrl(QUrl::fromLocalFile(QDir::homePath()));
1457 disconnect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, nullptr, nullptr);
1460 void DolphinMainWindow::setupActions()
1462 KStandardAction::hamburgerMenu(nullptr, nullptr, actionCollection());
1464 // setup 'File' menu
1465 m_newFileMenu
= new DolphinNewFileMenu(actionCollection(), this);
1466 QMenu
* menu
= m_newFileMenu
->menu();
1467 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1468 menu
->setIcon(QIcon::fromTheme(QStringLiteral("list-add")));
1469 m_newFileMenu
->setPopupMode(QToolButton::InstantPopup
);
1470 connect(menu
, &QMenu::aboutToShow
,
1471 this, &DolphinMainWindow::updateNewMenu
);
1473 QAction
* newWindow
= KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow
, actionCollection());
1474 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1475 newWindow
->setToolTip(i18nc("@info", "Open a new Dolphin window"));
1476 newWindow
->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1477 "window just like this one with the current location and view."
1478 "<nl/>You can drag and drop items between windows."));
1479 newWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1481 QAction
* newTab
= actionCollection()->addAction(QStringLiteral("new_tab"));
1482 newTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1483 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1484 newTab
->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1485 "<emphasis>Tab</emphasis> with the current location and view.<nl/>"
1486 "A tab is an additional view within this window. "
1487 "You can drag and drop items between tabs."));
1488 actionCollection()->setDefaultShortcuts(newTab
, {Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
});
1489 connect(newTab
, &QAction::triggered
, this, &DolphinMainWindow::openNewActivatedTab
);
1491 QAction
* addToPlaces
= actionCollection()->addAction(QStringLiteral("add_to_places"));
1492 addToPlaces
->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new")));
1493 addToPlaces
->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places"));
1494 addToPlaces
->setWhatsThis(xi18nc("@info:whatsthis", "This adds the selected folder "
1495 "to the Places panel."));
1496 connect(addToPlaces
, &QAction::triggered
, this, &DolphinMainWindow::addToPlaces
);
1498 QAction
* closeTab
= KStandardAction::close(m_tabWidget
, QOverload
<>::of(&DolphinTabWidget::closeTab
), actionCollection());
1499 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1500 closeTab
->setWhatsThis(i18nc("@info:whatsthis", "This closes the "
1501 "currently viewed tab. If no more tabs are left this window "
1502 "will close instead."));
1504 QAction
* quitAction
= KStandardAction::quit(this, &DolphinMainWindow::quit
, actionCollection());
1505 quitAction
->setWhatsThis(i18nc("@info:whatsthis quit", "This closes this window."));
1507 // setup 'Edit' menu
1508 KStandardAction::undo(this,
1509 &DolphinMainWindow::undo
,
1510 actionCollection());
1512 // i18n: This will be the last paragraph for the whatsthis for all three:
1513 // Cut, Copy and Paste
1514 const QString cutCopyPastePara
= xi18nc("@info:whatsthis", "<para><emphasis>Cut, "
1515 "Copy</emphasis> and <emphasis>Paste</emphasis> work between many "
1516 "applications and are among the most used commands. That's why their "
1517 "<emphasis>keyboard shortcuts</emphasis> are prominently placed right "
1518 "next to each other on the keyboard: <shortcut>Ctrl+X</shortcut>, "
1519 "<shortcut>Ctrl+C</shortcut> and <shortcut>Ctrl+V</shortcut>.</para>");
1520 QAction
* cutAction
= KStandardAction::cut(this, &DolphinMainWindow::cut
, actionCollection());
1521 cutAction
->setWhatsThis(xi18nc("@info:whatsthis cut", "This copies the items "
1522 "in your current selection to the <emphasis>clipboard</emphasis>.<nl/>"
1523 "Use the <emphasis>Paste</emphasis> action afterwards to copy them from "
1524 "the clipboard to a new location. The items will be removed from their "
1525 "initial location.") + cutCopyPastePara
);
1526 QAction
* copyAction
= KStandardAction::copy(this, &DolphinMainWindow::copy
, actionCollection());
1527 copyAction
->setWhatsThis(xi18nc("@info:whatsthis copy", "This copies the "
1528 "items in your current selection to the <emphasis>clipboard</emphasis>."
1529 "<nl/>Use the <emphasis>Paste</emphasis> action afterwards to copy them "
1530 "from the clipboard to a new location.") + cutCopyPastePara
);
1531 QAction
* paste
= KStandardAction::paste(this, &DolphinMainWindow::paste
, actionCollection());
1532 // The text of the paste-action is modified dynamically by Dolphin
1533 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1534 // due to the long text, the text "Paste" is used:
1535 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1536 paste
->setWhatsThis(xi18nc("@info:whatsthis paste", "This copies the items from "
1537 "your <emphasis>clipboard</emphasis> to the currently viewed folder.<nl/>"
1538 "If the items were added to the clipboard by the <emphasis>Cut</emphasis> "
1539 "action they are removed from their old location.") + cutCopyPastePara
);
1541 QAction
* copyToOtherViewAction
= actionCollection()->addAction(QStringLiteral("copy_to_inactive_split_view"));
1542 copyToOtherViewAction
->setText(i18nc("@action:inmenu", "Copy to Inactive Split View"));
1543 copyToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Copy", "This copies the selected items from "
1544 "the <emphasis>active</emphasis> view to the inactive split view."));
1545 copyToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
1546 copyToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Copy to Inactive Split View"));
1547 actionCollection()->setDefaultShortcut(copyToOtherViewAction
, Qt::SHIFT
| Qt::Key_F5
);
1548 connect(copyToOtherViewAction
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::copyToInactiveSplitView
);
1550 QAction
* moveToOtherViewAction
= actionCollection()->addAction(QStringLiteral("move_to_inactive_split_view"));
1551 moveToOtherViewAction
->setText(i18nc("@action:inmenu", "Move to Inactive Split View"));
1552 moveToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Move", "This moves the selected items from "
1553 "the <emphasis>active</emphasis> view to the inactive split view."));
1554 moveToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-cut")));
1555 moveToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Move to Inactive Split View"));
1556 actionCollection()->setDefaultShortcut(moveToOtherViewAction
, Qt::SHIFT
| Qt::Key_F6
);
1557 connect(moveToOtherViewAction
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::moveToInactiveSplitView
);
1559 QAction
* showFilterBar
= actionCollection()->addAction(QStringLiteral("show_filter_bar"));
1560 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Filter..."));
1561 showFilterBar
->setToolTip(i18nc("@info:tooltip", "Show Filter Bar"));
1562 showFilterBar
->setWhatsThis(xi18nc("@info:whatsthis", "This opens the "
1563 "<emphasis>Filter Bar</emphasis> at the bottom of the window.<nl/> "
1564 "There you can enter a text to filter the files and folders currently displayed. "
1565 "Only those that contain the text in their name will be kept in view."));
1566 showFilterBar
->setIcon(QIcon::fromTheme(QStringLiteral("view-filter")));
1567 actionCollection()->setDefaultShortcuts(showFilterBar
, {Qt::CTRL
| Qt::Key_I
, Qt::Key_Slash
});
1568 connect(showFilterBar
, &QAction::triggered
, this, &DolphinMainWindow::showFilterBar
);
1570 // toggle_filter acts as a copy of the main showFilterBar to be used mainly
1571 // in the toolbar, with no default shortcut attached, to avoid messing with
1572 // existing workflows (filter bar always open and Ctrl-I to focus)
1573 QAction
*toggleFilter
= actionCollection()->addAction(QStringLiteral("toggle_filter"));
1574 toggleFilter
->setText(i18nc("@action:inmenu", "Toggle Filter Bar"));
1575 toggleFilter
->setIconText(i18nc("@action:intoolbar", "Filter"));
1576 toggleFilter
->setIcon(showFilterBar
->icon());
1577 toggleFilter
->setToolTip(showFilterBar
->toolTip());
1578 toggleFilter
->setWhatsThis(showFilterBar
->whatsThis());
1579 toggleFilter
->setCheckable(true);
1580 connect(toggleFilter
, &QAction::triggered
, this, &DolphinMainWindow::toggleFilterBar
);
1582 QAction
*searchAction
= KStandardAction::find(this, &DolphinMainWindow::find
, actionCollection());
1583 searchAction
->setText(i18n("Search..."));
1584 searchAction
->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
1585 searchAction
->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This helps you "
1586 "find files and folders by opening a <emphasis>find bar</emphasis>. "
1587 "There you can enter search terms and specify settings to find the "
1588 "objects you are looking for.</para><para>Use this help again on "
1589 "the find bar so we can have a look at it while the settings are "
1590 "explained.</para>"));
1592 // toggle_search acts as a copy of the main searchAction to be used mainly
1593 // in the toolbar, with no default shortcut attached, to avoid messing with
1594 // existing workflows (search bar always open and Ctrl-F to focus)
1595 QAction
*toggleSearchAction
= actionCollection()->addAction(QStringLiteral("toggle_search"));
1596 toggleSearchAction
->setText(i18nc("@action:inmenu", "Toggle Search Bar"));
1597 toggleSearchAction
->setIconText(i18nc("@action:intoolbar", "Search"));
1598 toggleSearchAction
->setIcon(searchAction
->icon());
1599 toggleSearchAction
->setToolTip(searchAction
->toolTip());
1600 toggleSearchAction
->setWhatsThis(searchAction
->whatsThis());
1601 toggleSearchAction
->setCheckable(true);
1603 QAction
* selectAllAction
= KStandardAction::selectAll(this, &DolphinMainWindow::selectAll
, actionCollection());
1604 selectAllAction
->setWhatsThis(xi18nc("@info:whatsthis", "This selects all "
1605 "files and folders in the current location."));
1607 QAction
* invertSelection
= actionCollection()->addAction(QStringLiteral("invert_selection"));
1608 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1609 invertSelection
->setWhatsThis(xi18nc("@info:whatsthis invert", "This selects all "
1610 "objects that you have currently <emphasis>not</emphasis> selected instead."));
1611 invertSelection
->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert")));
1612 actionCollection()->setDefaultShortcut(invertSelection
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1613 connect(invertSelection
, &QAction::triggered
, this, &DolphinMainWindow::invertSelection
);
1615 // setup 'View' menu
1616 // (note that most of it is set up in DolphinViewActionHandler)
1618 QAction
* split
= actionCollection()->addAction(QStringLiteral("split_view"));
1619 split
->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This splits "
1620 "the folder view below into two autonomous views.</para><para>This "
1621 "way you can see two locations at once and move items between them "
1622 "quickly.</para>Click this again afterwards to recombine the views."));
1623 actionCollection()->setDefaultShortcut(split
, Qt::Key_F3
);
1624 connect(split
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitView
);
1626 QAction
* stashSplit
= actionCollection()->addAction(QStringLiteral("split_stash"));
1627 actionCollection()->setDefaultShortcut(stashSplit
, Qt::CTRL
| Qt::Key_S
);
1628 stashSplit
->setText(i18nc("@action:intoolbar Stash", "Stash"));
1629 stashSplit
->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
1630 stashSplit
->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
1631 stashSplit
->setCheckable(false);
1632 QDBusConnectionInterface
*sessionInterface
= QDBusConnection::sessionBus().interface();
1633 stashSplit
->setVisible(sessionInterface
&& sessionInterface
->isServiceRegistered(QStringLiteral("org.kde.kio.StashNotifier")));
1634 connect(stashSplit
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitStash
);
1636 KStandardAction::redisplay(this, &DolphinMainWindow::reloadView
, actionCollection());
1638 QAction
* stop
= actionCollection()->addAction(QStringLiteral("stop"));
1639 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1640 stop
->setToolTip(i18nc("@info", "Stop loading"));
1641 stop
->setWhatsThis(i18nc("@info", "This stops the loading of the contents of the current folder."));
1642 stop
->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
1643 connect(stop
, &QAction::triggered
, this, &DolphinMainWindow::stopLoading
);
1645 KToggleAction
* editableLocation
= actionCollection()->add
<KToggleAction
>(QStringLiteral("editable_location"));
1646 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1647 editableLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1648 "This toggles the <emphasis>Location Bar</emphasis> to be "
1649 "editable so you can directly enter a location you want to go to.<nl/>"
1650 "You can also switch to editing by clicking to the right of the "
1651 "location and switch back by confirming the edited location."));
1652 actionCollection()->setDefaultShortcut(editableLocation
, Qt::Key_F6
);
1653 connect(editableLocation
, &KToggleAction::triggered
, this, &DolphinMainWindow::toggleEditLocation
);
1655 QAction
* replaceLocation
= actionCollection()->addAction(QStringLiteral("replace_location"));
1656 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1657 // i18n: "enter" is used both in the meaning of "writing" and "going to" a new location here.
1658 // Both meanings are useful but not necessary to understand the use of "Replace Location".
1659 // So you might want to be more verbose in your language to convey the meaning but it's up to you.
1660 replaceLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1661 "This switches to editing the location and selects it "
1662 "so you can quickly enter a different location."));
1663 actionCollection()->setDefaultShortcut(replaceLocation
, Qt::CTRL
| Qt::Key_L
);
1664 connect(replaceLocation
, &QAction::triggered
, this, &DolphinMainWindow::replaceLocation
);
1668 QScopedPointer
<QAction
> backAction(KStandardAction::back(nullptr, nullptr, nullptr));
1669 m_backAction
= new KToolBarPopupAction(backAction
->icon(), backAction
->text(), actionCollection());
1670 m_backAction
->setObjectName(backAction
->objectName());
1671 m_backAction
->setShortcuts(backAction
->shortcuts());
1673 m_backAction
->setPopupMode(QToolButton::DelayedPopup
);
1674 connect(m_backAction
, &QAction::triggered
, this, &DolphinMainWindow::goBack
);
1675 connect(m_backAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowBackPopupMenu
);
1676 connect(m_backAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoBack
);
1677 actionCollection()->addAction(m_backAction
->objectName(), m_backAction
);
1679 auto backShortcuts
= m_backAction
->shortcuts();
1680 backShortcuts
.append(QKeySequence(Qt::Key_Backspace
));
1681 actionCollection()->setDefaultShortcuts(m_backAction
, backShortcuts
);
1683 DolphinRecentTabsMenu
* recentTabsMenu
= new DolphinRecentTabsMenu(this);
1684 actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu
);
1685 connect(m_tabWidget
, &DolphinTabWidget::rememberClosedTab
,
1686 recentTabsMenu
, &DolphinRecentTabsMenu::rememberClosedTab
);
1687 connect(recentTabsMenu
, &DolphinRecentTabsMenu::restoreClosedTab
,
1688 m_tabWidget
, &DolphinTabWidget::restoreClosedTab
);
1689 connect(recentTabsMenu
, &DolphinRecentTabsMenu::closedTabsCountChanged
,
1690 this, &DolphinMainWindow::closedTabsCountChanged
);
1692 QAction
* undoCloseTab
= actionCollection()->addAction(QStringLiteral("undo_close_tab"));
1693 undoCloseTab
->setText(i18nc("@action:inmenu File", "Undo close tab"));
1694 undoCloseTab
->setWhatsThis(i18nc("@info:whatsthis undo close tab",
1695 "This returns you to the previously closed tab."));
1696 actionCollection()->setDefaultShortcut(undoCloseTab
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_T
);
1697 undoCloseTab
->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
1698 undoCloseTab
->setEnabled(false);
1699 connect(undoCloseTab
, &QAction::triggered
, recentTabsMenu
, &DolphinRecentTabsMenu::undoCloseTab
);
1701 auto undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
1702 undoAction
->setWhatsThis(xi18nc("@info:whatsthis", "This undoes "
1703 "the last change you made to files or folders.<nl/>"
1704 "Such changes include <interface>creating, renaming</interface> "
1705 "and <interface>moving</interface> them to a different location "
1706 "or to the <filename>Trash</filename>. <nl/>Changes that can't "
1707 "be undone will ask for your confirmation."));
1708 undoAction
->setEnabled(false); // undo should be disabled by default
1711 QScopedPointer
<QAction
> forwardAction(KStandardAction::forward(nullptr, nullptr, nullptr));
1712 m_forwardAction
= new KToolBarPopupAction(forwardAction
->icon(), forwardAction
->text(), actionCollection());
1713 m_forwardAction
->setObjectName(forwardAction
->objectName());
1714 m_forwardAction
->setShortcuts(forwardAction
->shortcuts());
1716 m_forwardAction
->setPopupMode(QToolButton::DelayedPopup
);
1717 connect(m_forwardAction
, &QAction::triggered
, this, &DolphinMainWindow::goForward
);
1718 connect(m_forwardAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowForwardPopupMenu
);
1719 connect(m_forwardAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoForward
);
1720 actionCollection()->addAction(m_forwardAction
->objectName(), m_forwardAction
);
1721 actionCollection()->setDefaultShortcuts(m_forwardAction
, m_forwardAction
->shortcuts());
1723 // enable middle-click to open in a new tab
1724 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
1725 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotBackForwardActionMiddleClicked
);
1726 m_backAction
->menu()->installEventFilter(middleClickEventFilter
);
1727 m_forwardAction
->menu()->installEventFilter(middleClickEventFilter
);
1728 KStandardAction::up(this, &DolphinMainWindow::goUp
, actionCollection());
1729 QAction
* homeAction
= KStandardAction::home(this, &DolphinMainWindow::goHome
, actionCollection());
1730 homeAction
->setWhatsThis(xi18nc("@info:whatsthis", "Go to your "
1731 "<filename>Home</filename> folder.<nl/>Every user account "
1732 "has their own <filename>Home</filename> that contains their data "
1733 "including folders that contain personal application data."));
1735 // setup 'Tools' menu
1736 QAction
* compareFiles
= actionCollection()->addAction(QStringLiteral("compare_files"));
1737 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1738 compareFiles
->setIcon(QIcon::fromTheme(QStringLiteral("kompare")));
1739 compareFiles
->setEnabled(false);
1740 connect(compareFiles
, &QAction::triggered
, this, &DolphinMainWindow::compareFiles
);
1742 QAction
* openPreferredSearchTool
= actionCollection()->addAction(QStringLiteral("open_preferred_search_tool"));
1743 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1744 openPreferredSearchTool
->setWhatsThis(xi18nc("@info:whatsthis",
1745 "<para>This opens a preferred search tool for the viewed location.</para>"
1746 "<para>Use <emphasis>More Search Tools</emphasis> menu to configure it.</para>"));
1747 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1748 actionCollection()->setDefaultShortcut(openPreferredSearchTool
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F
);
1749 connect(openPreferredSearchTool
, &QAction::triggered
, this, &DolphinMainWindow::openPreferredSearchTool
);
1751 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1752 QAction
* openTerminal
= actionCollection()->addAction(QStringLiteral("open_terminal"));
1753 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1754 openTerminal
->setWhatsThis(xi18nc("@info:whatsthis",
1755 "<para>This opens a <emphasis>terminal</emphasis> application for the viewed location.</para>"
1756 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1757 openTerminal
->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
1758 actionCollection()->setDefaultShortcut(openTerminal
, Qt::SHIFT
| Qt::Key_F4
);
1759 connect(openTerminal
, &QAction::triggered
, this, &DolphinMainWindow::openTerminal
);
1761 QAction
* openTerminalHere
= actionCollection()->addAction(QStringLiteral("open_terminal_here"));
1762 // i18n: "Here" refers to the location(s) of the currently selected item(s) or the currently viewed location if nothing is selected.
1763 openTerminalHere
->setText(i18nc("@action:inmenu Tools", "Open Terminal Here"));
1764 openTerminalHere
->setWhatsThis(xi18nc("@info:whatsthis",
1765 "<para>This opens <emphasis>terminal</emphasis> applications for the selected items' locations.</para>"
1766 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1767 openTerminalHere
->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
1768 actionCollection()->setDefaultShortcut(openTerminalHere
, Qt::SHIFT
| Qt::ALT
| Qt::Key_F4
);
1769 connect(openTerminalHere
, &QAction::triggered
, this, &DolphinMainWindow::openTerminalHere
);
1771 #ifdef HAVE_TERMINAL
1772 QAction
* focusTerminalPanel
= actionCollection()->addAction(QStringLiteral("focus_terminal_panel"));
1773 focusTerminalPanel
->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
1774 focusTerminalPanel
->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
1775 actionCollection()->setDefaultShortcut(focusTerminalPanel
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F4
);
1776 connect(focusTerminalPanel
, &QAction::triggered
, this, &DolphinMainWindow::focusTerminalPanel
);
1780 // setup 'Bookmarks' menu
1781 KActionMenu
*bookmarkMenu
= new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this);
1782 bookmarkMenu
->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks")));
1783 // Make the toolbar button version work properly on click
1784 bookmarkMenu
->setPopupMode(QToolButton::InstantPopup
);
1785 m_bookmarkHandler
= new DolphinBookmarkHandler(this, actionCollection(), bookmarkMenu
->menu(), this);
1786 actionCollection()->addAction(QStringLiteral("bookmarks"), bookmarkMenu
);
1788 // setup 'Settings' menu
1789 KToggleAction
* showMenuBar
= KStandardAction::showMenubar(nullptr, nullptr, actionCollection());
1790 showMenuBar
->setWhatsThis(xi18nc("@info:whatsthis",
1791 "This switches between having a <emphasis>Menubar</emphasis> "
1792 "and having a <interface>Control</interface> button. Both "
1793 "contain mostly the same commands and configuration options."));
1794 connect(showMenuBar
, &KToggleAction::triggered
, // Fixes #286822
1795 this, &DolphinMainWindow::toggleShowMenuBar
, Qt::QueuedConnection
);
1796 KStandardAction::keyBindings(this, &DolphinMainWindow::slotKeyBindings
, actionCollection());
1797 KStandardAction::preferences(this, &DolphinMainWindow::editSettings
, actionCollection());
1799 // setup 'Help' menu for the m_controlButton. The other one is set up in the base class.
1800 m_helpMenu
= new KHelpMenu(nullptr);
1801 m_helpMenu
->menu()->installEventFilter(this);
1802 // remove duplicate shortcuts
1803 auto removeHelpActionShortcut
= [this](KHelpMenu::MenuId menuId
) {
1804 if (auto *action
= m_helpMenu
->action(menuId
)) {
1805 action
->setShortcut(QKeySequence());
1808 removeHelpActionShortcut(KHelpMenu::menuHelpContents
);
1809 removeHelpActionShortcut(KHelpMenu::menuWhatsThis
);
1811 // not in menu actions
1812 QList
<QKeySequence
> nextTabKeys
= KStandardShortcut::tabNext();
1813 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
1815 QList
<QKeySequence
> prevTabKeys
= KStandardShortcut::tabPrev();
1816 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
1818 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1819 QAction
* activateTab
= actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i
));
1820 activateTab
->setText(i18nc("@action:inmenu", "Activate Tab %1", i
+ 1));
1821 activateTab
->setEnabled(false);
1822 connect(activateTab
, &QAction::triggered
, this, [this, i
]() { m_tabWidget
->activateTab(i
); });
1824 // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts
1826 actionCollection()->setDefaultShortcut(activateTab
, QStringLiteral("Alt+%1").arg(i
+ 1));
1830 QAction
* activateLastTab
= actionCollection()->addAction(QStringLiteral("activate_last_tab"));
1831 activateLastTab
->setText(i18nc("@action:inmenu", "Activate Last Tab"));
1832 activateLastTab
->setEnabled(false);
1833 connect(activateLastTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateLastTab
);
1834 actionCollection()->setDefaultShortcut(activateLastTab
, Qt::ALT
| Qt::Key_0
);
1836 QAction
* activateNextTab
= actionCollection()->addAction(QStringLiteral("activate_next_tab"));
1837 activateNextTab
->setIconText(i18nc("@action:inmenu", "Next Tab"));
1838 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1839 activateNextTab
->setEnabled(false);
1840 connect(activateNextTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateNextTab
);
1841 actionCollection()->setDefaultShortcuts(activateNextTab
, nextTabKeys
);
1843 QAction
* activatePrevTab
= actionCollection()->addAction(QStringLiteral("activate_prev_tab"));
1844 activatePrevTab
->setIconText(i18nc("@action:inmenu", "Previous Tab"));
1845 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1846 activatePrevTab
->setEnabled(false);
1847 connect(activatePrevTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activatePrevTab
);
1848 actionCollection()->setDefaultShortcuts(activatePrevTab
, prevTabKeys
);
1851 QAction
* showTarget
= actionCollection()->addAction(QStringLiteral("show_target"));
1852 showTarget
->setText(i18nc("@action:inmenu", "Show Target"));
1853 showTarget
->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
1854 showTarget
->setEnabled(false);
1855 connect(showTarget
, &QAction::triggered
, this, &DolphinMainWindow::showTarget
);
1857 QAction
* openInNewTab
= actionCollection()->addAction(QStringLiteral("open_in_new_tab"));
1858 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1859 openInNewTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1860 connect(openInNewTab
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
1862 QAction
* openInNewTabs
= actionCollection()->addAction(QStringLiteral("open_in_new_tabs"));
1863 openInNewTabs
->setText(i18nc("@action:inmenu", "Open in New Tabs"));
1864 openInNewTabs
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1865 connect(openInNewTabs
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
1867 QAction
* openInNewWindow
= actionCollection()->addAction(QStringLiteral("open_in_new_window"));
1868 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1869 openInNewWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1870 connect(openInNewWindow
, &QAction::triggered
, this, &DolphinMainWindow::openInNewWindow
);
1873 void DolphinMainWindow::setupDockWidgets()
1875 const bool lock
= GeneralSettings::lockPanels();
1877 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(lock
);
1879 KDualAction
* lockLayoutAction
= actionCollection()->add
<KDualAction
>(QStringLiteral("lock_panels"));
1880 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1881 lockLayoutAction
->setActiveIcon(QIcon::fromTheme(QStringLiteral("object-unlocked")));
1882 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1883 lockLayoutAction
->setInactiveIcon(QIcon::fromTheme(QStringLiteral("object-locked")));
1884 lockLayoutAction
->setWhatsThis(xi18nc("@info:whatsthis", "This "
1885 "switches between having panels <emphasis>locked</emphasis> or "
1886 "<emphasis>unlocked</emphasis>.<nl/>Unlocked panels can be "
1887 "dragged to the other side of the window and have a close "
1888 "button.<nl/>Locked panels are embedded more cleanly."));
1889 lockLayoutAction
->setActive(lock
);
1890 connect(lockLayoutAction
, &KDualAction::triggered
, this, &DolphinMainWindow::togglePanelLockState
);
1892 // Setup "Information"
1893 DolphinDockWidget
* infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
1894 infoDock
->setLocked(lock
);
1895 infoDock
->setObjectName(QStringLiteral("infoDock"));
1896 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1899 InformationPanel
* infoPanel
= new InformationPanel(infoDock
);
1900 infoPanel
->setCustomContextMenuActions({lockLayoutAction
});
1901 connect(infoPanel
, &InformationPanel::urlActivated
, this, &DolphinMainWindow::handleUrl
);
1902 infoDock
->setWidget(infoPanel
);
1904 QAction
* infoAction
= infoDock
->toggleViewAction();
1905 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-information")), Qt::Key_F11
, infoAction
, QStringLiteral("show_information_panel"));
1907 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1908 connect(this, &DolphinMainWindow::urlChanged
,
1909 infoPanel
, &InformationPanel::setUrl
);
1910 connect(this, &DolphinMainWindow::selectionChanged
,
1911 infoPanel
, &InformationPanel::setSelection
);
1912 connect(this, &DolphinMainWindow::requestItemInfo
,
1913 infoPanel
, &InformationPanel::requestDelayedItemInfo
);
1914 connect(this, &DolphinMainWindow::fileItemsChanged
,
1915 infoPanel
, &InformationPanel::slotFilesItemChanged
);
1918 // i18n: This is the last paragraph for the "What's This"-texts of all four panels.
1919 const QString panelWhatsThis
= xi18nc("@info:whatsthis", "<para>To show or "
1920 "hide panels like this go to <interface>Control|Panels</interface> "
1921 "or <interface>View|Panels</interface>.</para>");
1923 actionCollection()->action(QStringLiteral("show_information_panel"))
1924 ->setWhatsThis(xi18nc("@info:whatsthis", "<para> This toggles the "
1925 "<emphasis>information</emphasis> panel at the right side of the "
1926 "window.</para><para>The panel provides in-depth information "
1927 "about the items your mouse is hovering over or about the selected "
1928 "items. Otherwise it informs you about the currently viewed folder.<nl/>"
1929 "For single items a preview of their contents is provided.</para>"));
1931 infoDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
1932 "provides in-depth information about the items your mouse is "
1933 "hovering over or about the selected items. Otherwise it informs "
1934 "you about the currently viewed folder.<nl/>For single items a "
1935 "preview of their contents is provided.</para><para>You can configure "
1936 "which and how details are given here by right-clicking.</para>") + panelWhatsThis
);
1939 DolphinDockWidget
* foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
1940 foldersDock
->setLocked(lock
);
1941 foldersDock
->setObjectName(QStringLiteral("foldersDock"));
1942 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1943 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1944 foldersPanel
->setCustomContextMenuActions({lockLayoutAction
});
1945 foldersDock
->setWidget(foldersPanel
);
1947 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1948 createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7
, foldersAction
, QStringLiteral("show_folders_panel"));
1950 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1951 connect(this, &DolphinMainWindow::urlChanged
,
1952 foldersPanel
, &FoldersPanel::setUrl
);
1953 connect(foldersPanel
, &FoldersPanel::folderActivated
,
1954 this, &DolphinMainWindow::changeUrl
);
1955 connect(foldersPanel
, &FoldersPanel::folderInNewTab
,
1956 this, &DolphinMainWindow::openNewTab
);
1957 connect(foldersPanel
, &FoldersPanel::folderInNewActiveTab
,
1958 this, &DolphinMainWindow::openNewTabAndActivate
);
1959 connect(foldersPanel
, &FoldersPanel::errorMessage
,
1960 this, &DolphinMainWindow::showErrorMessage
);
1962 actionCollection()->action(QStringLiteral("show_folders_panel"))
1963 ->setWhatsThis(xi18nc("@info:whatsthis", "This toggles the "
1964 "<emphasis>folders</emphasis> panel at the left side of the window."
1965 "<nl/><nl/>It shows the folders of the <emphasis>file system"
1966 "</emphasis> in a <emphasis>tree view</emphasis>."));
1967 foldersDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
1968 "shows the folders of the <emphasis>file system</emphasis> in a "
1969 "<emphasis>tree view</emphasis>.</para><para>Click a folder to go "
1970 "there. Click the arrow to the left of a folder to see its subfolders. "
1971 "This allows quick switching between any folders.</para>") + panelWhatsThis
);
1974 #ifdef HAVE_TERMINAL
1975 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1976 DolphinDockWidget
* terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1977 terminalDock
->setLocked(lock
);
1978 terminalDock
->setObjectName(QStringLiteral("terminalDock"));
1979 m_terminalPanel
= new TerminalPanel(terminalDock
);
1980 m_terminalPanel
->setCustomContextMenuActions({lockLayoutAction
});
1981 terminalDock
->setWidget(m_terminalPanel
);
1983 connect(m_terminalPanel
, &TerminalPanel::hideTerminalPanel
, terminalDock
, &DolphinDockWidget::hide
);
1984 connect(m_terminalPanel
, &TerminalPanel::changeUrl
, this, &DolphinMainWindow::slotTerminalDirectoryChanged
);
1985 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
,
1986 m_terminalPanel
, &TerminalPanel::dockVisibilityChanged
);
1987 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
,
1988 this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged
);
1990 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1991 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4
, terminalAction
, QStringLiteral("show_terminal_panel"));
1993 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1994 connect(this, &DolphinMainWindow::urlChanged
,
1995 m_terminalPanel
, &TerminalPanel::setUrl
);
1997 if (GeneralSettings::version() < 200) {
1998 terminalDock
->hide();
2001 actionCollection()->action(QStringLiteral("show_terminal_panel"))
2002 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
2003 "<emphasis>terminal</emphasis> panel at the bottom of the window."
2004 "<nl/>The location in the terminal will always match the folder "
2005 "view so you can navigate using either.</para><para>The terminal "
2006 "panel is not needed for basic computer usage but can be useful "
2007 "for advanced tasks. To learn more about terminals use the help "
2008 "in a standalone terminal application like Konsole.</para>"));
2009 terminalDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is "
2010 "the <emphasis>terminal</emphasis> panel. It behaves like a "
2011 "normal terminal but will match the location of the folder view "
2012 "so you can navigate using either.</para><para>The terminal panel "
2013 "is not needed for basic computer usage but can be useful for "
2014 "advanced tasks. To learn more about terminals use the help in a "
2015 "standalone terminal application like Konsole.</para>") + panelWhatsThis
);
2019 if (GeneralSettings::version() < 200) {
2021 foldersDock
->hide();
2025 DolphinDockWidget
* placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
2026 placesDock
->setLocked(lock
);
2027 placesDock
->setObjectName(QStringLiteral("placesDock"));
2028 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2030 m_placesPanel
= new PlacesPanel(placesDock
);
2031 m_placesPanel
->setCustomContextMenuActions({lockLayoutAction
});
2032 placesDock
->setWidget(m_placesPanel
);
2034 QAction
*placesAction
= placesDock
->toggleViewAction();
2035 createPanelAction(QIcon::fromTheme(QStringLiteral("compass")), Qt::Key_F9
, placesAction
, QStringLiteral("show_places_panel"));
2037 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
2038 connect(m_placesPanel
, &PlacesPanel::placeActivated
,
2039 this, &DolphinMainWindow::slotPlaceActivated
);
2040 connect(m_placesPanel
, &PlacesPanel::tabRequested
,
2041 this, &DolphinMainWindow::openNewTab
);
2042 connect(m_placesPanel
, &PlacesPanel::activeTabRequested
,
2043 this, &DolphinMainWindow::openNewTabAndActivate
);
2044 connect(m_placesPanel
, &PlacesPanel::newWindowRequested
, this, [this](const QUrl
&url
) {
2045 Dolphin::openNewWindow({url
}, this);
2047 connect(m_placesPanel
, &PlacesPanel::errorMessage
,
2048 this, &DolphinMainWindow::showErrorMessage
);
2049 connect(this, &DolphinMainWindow::urlChanged
,
2050 m_placesPanel
, &PlacesPanel::setUrl
);
2051 connect(placesDock
, &DolphinDockWidget::visibilityChanged
,
2052 &DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged
);
2053 connect(this, &DolphinMainWindow::settingsChanged
,
2054 m_placesPanel
, &PlacesPanel::readSettings
);
2055 connect(m_placesPanel
, &PlacesPanel::storageTearDownRequested
,
2056 this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested
);
2057 connect(m_placesPanel
, &PlacesPanel::storageTearDownExternallyRequested
,
2058 this, &DolphinMainWindow::slotStorageTearDownExternallyRequested
);
2059 DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged(m_placesPanel
->isVisible());
2061 auto actionShowAllPlaces
= new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this);
2062 actionShowAllPlaces
->setCheckable(true);
2063 actionShowAllPlaces
->setDisabled(true);
2064 actionShowAllPlaces
->setWhatsThis(i18nc("@info:whatsthis", "This displays "
2065 "all places in the places panel that have been hidden. They will "
2066 "appear semi-transparent unless you uncheck their hide property."));
2068 connect(actionShowAllPlaces
, &QAction::triggered
, this, [actionShowAllPlaces
, this](bool checked
){
2069 m_placesPanel
->setShowAll(checked
);
2071 connect(m_placesPanel
, &PlacesPanel::allPlacesShownChanged
, actionShowAllPlaces
, &QAction::setChecked
);
2073 actionCollection()->action(QStringLiteral("show_places_panel"))
2074 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
2075 "<emphasis>places</emphasis> panel at the left side of the window."
2076 "</para><para>It allows you to go to locations you have "
2077 "bookmarked and to access disk or media attached to the computer "
2078 "or to the network. It also contains sections to find recently "
2079 "saved files or files of a certain type.</para>"));
2080 placesDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2081 "<emphasis>Places</emphasis> panel. It allows you to go to locations "
2082 "you have bookmarked and to access disk or media attached to the "
2083 "computer or to the network. It also contains sections to find "
2084 "recently saved files or files of a certain type.</para><para>"
2085 "Click on an entry to go there. Click with the right mouse button "
2086 "instead to open any entry in a new tab or new window.</para>"
2087 "<para>New entries can be added by dragging folders onto this panel. "
2088 "Right-click any section or entry to hide it. Right-click an empty "
2089 "space on this panel and select <interface>Show Hidden Places"
2090 "</interface> to display it again.</para>") + panelWhatsThis
);
2092 // Add actions into the "Panels" menu
2093 KActionMenu
* panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Show Panels"), this);
2094 actionCollection()->addAction(QStringLiteral("panels"), panelsMenu
);
2095 panelsMenu
->setIcon(QIcon::fromTheme(QStringLiteral("view-sidetree")));
2096 panelsMenu
->setPopupMode(QToolButton::InstantPopup
);
2097 const KActionCollection
* ac
= actionCollection();
2098 panelsMenu
->addAction(ac
->action(QStringLiteral("show_places_panel")));
2100 panelsMenu
->addAction(ac
->action(QStringLiteral("show_information_panel")));
2102 panelsMenu
->addAction(ac
->action(QStringLiteral("show_folders_panel")));
2103 panelsMenu
->addAction(ac
->action(QStringLiteral("show_terminal_panel")));
2104 panelsMenu
->addSeparator();
2105 panelsMenu
->addAction(actionShowAllPlaces
);
2106 panelsMenu
->addAction(lockLayoutAction
);
2108 connect(panelsMenu
->menu(), &QMenu::aboutToShow
, this, [actionShowAllPlaces
, this]{
2109 actionShowAllPlaces
->setEnabled(DolphinPlacesModelSingleton::instance().placesModel()->hiddenCount());
2114 void DolphinMainWindow::updateFileAndEditActions()
2116 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
2117 const KActionCollection
* col
= actionCollection();
2118 KFileItemListProperties
capabilitiesSource(list
);
2120 QAction
* addToPlacesAction
= col
->action(QStringLiteral("add_to_places"));
2121 QAction
* copyToOtherViewAction
= col
->action(QStringLiteral("copy_to_inactive_split_view"));
2122 QAction
* moveToOtherViewAction
= col
->action(QStringLiteral("move_to_inactive_split_view"));
2123 QAction
* copyLocation
= col
->action(QString("copy_location"));
2125 if (list
.isEmpty()) {
2126 stateChanged(QStringLiteral("has_no_selection"));
2128 addToPlacesAction
->setEnabled(true);
2129 copyToOtherViewAction
->setEnabled(false);
2130 moveToOtherViewAction
->setEnabled(false);
2131 copyLocation
->setEnabled(false);
2133 stateChanged(QStringLiteral("has_selection"));
2135 QAction
* renameAction
= col
->action(KStandardAction::name(KStandardAction::RenameFile
));
2136 QAction
* moveToTrashAction
= col
->action(KStandardAction::name(KStandardAction::MoveToTrash
));
2137 QAction
* deleteAction
= col
->action(KStandardAction::name(KStandardAction::DeleteFile
));
2138 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
2139 QAction
* deleteWithTrashShortcut
= col
->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
2140 QAction
* showTarget
= col
->action(QStringLiteral("show_target"));
2141 QAction
* duplicateAction
= col
->action(QStringLiteral("duplicate")); // see DolphinViewActionHandler
2143 if (list
.length() == 1 && list
.first().isDir()) {
2144 addToPlacesAction
->setEnabled(true);
2146 addToPlacesAction
->setEnabled(false);
2149 if (m_tabWidget
->currentTabPage()->splitViewEnabled()) {
2150 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
2151 KFileItem capabilitiesDestination
;
2153 if (tabPage
->primaryViewActive()) {
2154 capabilitiesDestination
= tabPage
->secondaryViewContainer()->url();
2156 capabilitiesDestination
= tabPage
->primaryViewContainer()->url();
2159 copyToOtherViewAction
->setEnabled(capabilitiesDestination
.isWritable());
2160 moveToOtherViewAction
->setEnabled(capabilitiesSource
.supportsMoving() && capabilitiesDestination
.isWritable());
2162 copyToOtherViewAction
->setEnabled(false);
2163 moveToOtherViewAction
->setEnabled(false);
2166 const bool enableMoveToTrash
= capabilitiesSource
.isLocal() && capabilitiesSource
.supportsMoving();
2168 renameAction
->setEnabled(capabilitiesSource
.supportsMoving());
2169 moveToTrashAction
->setEnabled(enableMoveToTrash
);
2170 deleteAction
->setEnabled(capabilitiesSource
.supportsDeleting());
2171 deleteWithTrashShortcut
->setEnabled(capabilitiesSource
.supportsDeleting() && !enableMoveToTrash
);
2172 cutAction
->setEnabled(capabilitiesSource
.supportsMoving());
2173 copyLocation
->setEnabled(list
.length() == 1);
2174 showTarget
->setEnabled(list
.length() == 1 && list
.at(0).isLink());
2175 duplicateAction
->setEnabled(capabilitiesSource
.supportsWriting());
2179 void DolphinMainWindow::updateViewActions()
2181 m_actionHandler
->updateViewActions();
2183 QAction
* toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
2184 toggleFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
2186 updateSplitAction();
2189 void DolphinMainWindow::updateGoActions()
2191 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
2192 const QUrl currentUrl
= m_activeViewContainer
->url();
2193 // I think this is one of the best places to firstly be confronted
2194 // with a file system and its hierarchy. Talking about the root
2195 // directory might seem too much here but it is the question that
2196 // naturally arises in this context.
2197 goUpAction
->setWhatsThis(xi18nc("@info:whatsthis", "<para>Go to "
2198 "the folder that contains the currently viewed one.</para>"
2199 "<para>All files and folders are organized in a hierarchical "
2200 "<emphasis>file system</emphasis>. At the top of this hierarchy is "
2201 "a directory that contains all data connected to this computer"
2202 "—the <emphasis>root directory</emphasis>.</para>"));
2203 goUpAction
->setEnabled(KIO::upUrl(currentUrl
) != currentUrl
);
2206 void DolphinMainWindow::refreshViews()
2208 m_tabWidget
->refreshViews();
2210 if (GeneralSettings::modifiedStartupSettings()) {
2211 updateWindowTitle();
2214 Q_EMIT
settingsChanged();
2217 void DolphinMainWindow::clearStatusBar()
2219 m_activeViewContainer
->statusBar()->resetToDefaultText();
2222 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
2224 connect(container
, &DolphinViewContainer::showFilterBarChanged
,
2225 this, &DolphinMainWindow::updateFilterBarAction
);
2226 connect(container
, &DolphinViewContainer::writeStateChanged
,
2227 this, &DolphinMainWindow::slotWriteStateChanged
);
2228 connect(container
, &DolphinViewContainer::searchModeEnabledChanged
,
2229 this, &DolphinMainWindow::updateSearchAction
);
2230 connect(container
, &DolphinViewContainer::captionChanged
,
2231 this, &DolphinMainWindow::updateWindowTitle
);
2232 connect(container
, &DolphinViewContainer::tabRequested
,
2233 this, &DolphinMainWindow::openNewTab
);
2234 connect(container
, &DolphinViewContainer::activeTabRequested
,
2235 this, &DolphinMainWindow::openNewTabAndActivate
);
2237 const QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
2238 connect(toggleSearchAction
, &QAction::triggered
, container
, &DolphinViewContainer::setSearchModeEnabled
);
2240 const DolphinView
* view
= container
->view();
2241 connect(view
, &DolphinView::selectionChanged
,
2242 this, &DolphinMainWindow::slotSelectionChanged
);
2243 connect(view
, &DolphinView::requestItemInfo
,
2244 this, &DolphinMainWindow::requestItemInfo
);
2245 connect(view
, &DolphinView::fileItemsChanged
,
2246 this, &DolphinMainWindow::fileItemsChanged
);
2247 connect(view
, &DolphinView::tabRequested
,
2248 this, &DolphinMainWindow::openNewTab
);
2249 connect(view
, &DolphinView::activeTabRequested
,
2250 this, &DolphinMainWindow::openNewTabAndActivate
);
2251 connect(view
, &DolphinView::windowRequested
,
2252 this, &DolphinMainWindow::openNewWindow
);
2253 connect(view
, &DolphinView::requestContextMenu
,
2254 this, &DolphinMainWindow::openContextMenu
);
2255 connect(view
, &DolphinView::directoryLoadingStarted
,
2256 this, &DolphinMainWindow::enableStopAction
);
2257 connect(view
, &DolphinView::directoryLoadingCompleted
,
2258 this, &DolphinMainWindow::disableStopAction
);
2259 connect(view
, &DolphinView::directoryLoadingCompleted
,
2260 this, &DolphinMainWindow::slotDirectoryLoadingCompleted
);
2261 connect(view
, &DolphinView::goBackRequested
,
2262 this, &DolphinMainWindow::goBack
);
2263 connect(view
, &DolphinView::goForwardRequested
,
2264 this, &DolphinMainWindow::goForward
);
2265 connect(view
, &DolphinView::urlActivated
,
2266 this, &DolphinMainWindow::handleUrl
);
2267 connect(view
, &DolphinView::goUpRequested
,
2268 this, &DolphinMainWindow::goUp
);
2270 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::urlChanged
,
2271 this, &DolphinMainWindow::changeUrl
);
2272 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::historyChanged
,
2273 this, &DolphinMainWindow::updateHistory
);
2275 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
2276 (actionCollection()->action(QStringLiteral("url_navigators")));
2277 const KUrlNavigator
*navigator
= m_tabWidget
->currentTabPage()->primaryViewActive() ?
2278 navigators
->primaryUrlNavigator() :
2279 navigators
->secondaryUrlNavigator();
2281 QAction
*editableLocactionAction
= actionCollection()->action(QStringLiteral("editable_location"));
2282 editableLocactionAction
->setChecked(navigator
->isUrlEditable());
2283 connect(navigator
, &KUrlNavigator::editableStateChanged
,
2284 this, &DolphinMainWindow::slotEditableStateChanged
);
2285 connect(navigator
, &KUrlNavigator::tabRequested
,
2286 this, &DolphinMainWindow::openNewTab
);
2287 connect(navigator
, &KUrlNavigator::activeTabRequested
,
2288 this, &DolphinMainWindow::openNewTabAndActivate
);
2289 connect(navigator
, &KUrlNavigator::newWindowRequested
,
2290 this, &DolphinMainWindow::openNewWindow
);
2294 void DolphinMainWindow::updateSplitAction()
2296 QAction
* splitAction
= actionCollection()->action(QStringLiteral("split_view"));
2297 const DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
2298 if (tabPage
->splitViewEnabled()) {
2299 if (GeneralSettings::closeActiveSplitView() ? tabPage
->primaryViewActive() : !tabPage
->primaryViewActive()) {
2300 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2301 splitAction
->setToolTip(i18nc("@info", "Close left view"));
2302 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close")));
2304 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2305 splitAction
->setToolTip(i18nc("@info", "Close right view"));
2306 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close")));
2309 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2310 splitAction
->setToolTip(i18nc("@info", "Split view"));
2311 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2315 void DolphinMainWindow::updateAllowedToolbarAreas()
2317 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
2318 (actionCollection()->action(QStringLiteral("url_navigators")));
2319 if (toolBar()->actions().contains(navigators
)) {
2320 toolBar()->setAllowedAreas(Qt::TopToolBarArea
| Qt::BottomToolBarArea
);
2321 if (toolBarArea(toolBar()) == Qt::LeftToolBarArea
||
2322 toolBarArea(toolBar()) == Qt::RightToolBarArea
) {
2323 addToolBar(Qt::TopToolBarArea
, toolBar());
2326 toolBar()->setAllowedAreas(Qt::AllToolBarAreas
);
2330 bool DolphinMainWindow::isKompareInstalled() const
2332 static bool initialized
= false;
2333 static bool installed
= false;
2335 // TODO: maybe replace this approach later by using a menu
2336 // plugin like kdiff3plugin.cpp
2337 installed
= !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty();
2343 void DolphinMainWindow::createPanelAction(const QIcon
& icon
,
2344 const QKeySequence
& shortcut
,
2345 QAction
* dockAction
,
2346 const QString
& actionName
)
2348 QAction
* panelAction
= actionCollection()->addAction(actionName
);
2349 panelAction
->setCheckable(true);
2350 panelAction
->setChecked(dockAction
->isChecked());
2351 panelAction
->setText(dockAction
->text());
2352 panelAction
->setIcon(icon
);
2353 dockAction
->setIcon(icon
);
2354 actionCollection()->setDefaultShortcut(panelAction
, shortcut
);
2356 connect(panelAction
, &QAction::triggered
, dockAction
, &QAction::trigger
);
2357 connect(dockAction
, &QAction::toggled
, panelAction
, &QAction::setChecked
);
2360 void DolphinMainWindow::setupWhatsThis()
2363 menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2364 "<emphasis>Menubar</emphasis>. It provides access to commands and "
2365 "configuration options. Left-click on any of the menus on this "
2366 "bar to see its contents.</para><para>The Menubar can be hidden "
2367 "by unchecking <interface>Settings|Show Menubar</interface>. Then "
2368 "most of its contents become available through a <interface>Control"
2369 "</interface> button on the <emphasis>Toolbar</emphasis>.</para>"));
2370 toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2371 "<emphasis>Toolbar</emphasis>. It allows quick access to "
2372 "frequently used actions.</para><para>It is highly customizable. "
2373 "All items you see in the <interface>Control</interface> menu or "
2374 "in the <interface>Menubar</interface> can be placed on the "
2375 "Toolbar. Just right-click on it and select <interface>Configure "
2376 "Toolbars…</interface> or find this action in the <interface>"
2377 "Control</interface> or <interface>Settings</interface> menu."
2378 "</para><para>The location of the bar and the style of its "
2379 "buttons can also be changed in the right-click menu. Right-click "
2380 "a button if you want to show or hide its text.</para>"));
2381 m_tabWidget
->setWhatsThis(xi18nc("@info:whatsthis main view",
2382 "<para>Here you can see the <emphasis>folders</emphasis> and "
2383 "<emphasis>files</emphasis> that are at the location described in "
2384 "the <interface>Location Bar</interface> above. This area is the "
2385 "central part of this application where you navigate to the files "
2386 "you want to use.</para><para>For an elaborate and general "
2387 "introduction to this application <link "
2388 "url='https://userbase.kde.org/Dolphin/File_Management#Introduction_to_Dolphin'>"
2389 "click here</link>. This will open an introductory article from "
2390 "the <emphasis>KDE UserBase Wiki</emphasis>.</para><para>For brief "
2391 "explanations of all the features of this <emphasis>view</emphasis> "
2392 "<link url='help:/dolphin/dolphin-view.html'>click here</link> "
2393 "instead. This will open a page from the <emphasis>Handbook"
2394 "</emphasis> that covers the basics.</para>"));
2397 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings
))
2398 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window "
2399 "that lists the <emphasis>keyboard shortcuts</emphasis>.<nl/>"
2400 "There you can set up key combinations to trigger an action when "
2401 "they are pressed simultaneously. All commands in this application can "
2402 "be triggered this way.</para>"));
2403 actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars
))
2404 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window in which "
2405 "you can change which buttons appear on the <emphasis>Toolbar</emphasis>.</para>"
2406 "<para>All items you see in the <interface>Control</interface> menu "
2407 "or in the <interface>Menubar</interface> can also be placed on the Toolbar.</para>"));
2408 actionCollection()->action(KStandardAction::name(KStandardAction::Preferences
))
2409 ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can "
2410 "change a multitude of settings for this application. For an explanation "
2411 "of the various settings go to the chapter <emphasis>Configuring Dolphin"
2412 "</emphasis> in <interface>Help|Dolphin Handbook</interface>."));
2415 // The whatsthis has to be set for the m_helpMenu and for the
2416 // StandardAction separately because both are used in different locations.
2417 // m_helpMenu is only used for createControlButton() button.
2419 auto setStandardActionWhatsThis
= [this](KStandardAction::StandardAction actionId
,
2420 const QString
&whatsThis
) {
2421 if (auto *action
= actionCollection()->action(KStandardAction::name(actionId
))) {
2422 action
->setWhatsThis(whatsThis
);
2425 auto setHelpActionWhatsThis
= [this](KHelpMenu::MenuId menuId
, const QString
&whatsThis
) {
2426 if (auto *action
= m_helpMenu
->action(menuId
)) {
2427 action
->setWhatsThis(whatsThis
);
2431 // Links do not work within the Menubar so texts without links are provided there.
2433 // i18n: If the external link isn't available in your language you should
2434 // probably state the external link language at least in brackets to not
2435 // frustrate the user. If there are multiple languages that the user might
2436 // know with a reasonable chance you might want to have 2 external links.
2437 // The same is in my opinion true for every external link you translate.
2438 const QString whatsThisHelpContents
= xi18nc("@info:whatsthis handbook",
2439 "<para>This opens the Handbook for this application. It provides "
2440 "explanations for every part of <emphasis>Dolphin</emphasis>.</para>");
2441 setStandardActionWhatsThis(KStandardAction::HelpContents
, whatsThisHelpContents
2442 + xi18nc("@info:whatsthis second half of handbook hb text without link",
2443 "<para>If you want more elaborate introductions to the "
2444 "different features of <emphasis>Dolphin</emphasis> "
2445 "go to the KDE UserBase Wiki.</para>"));
2446 setHelpActionWhatsThis(KHelpMenu::menuHelpContents
, whatsThisHelpContents
2447 + xi18nc("@info:whatsthis second half of handbook text with link",
2448 "<para>If you want more elaborate introductions to the "
2449 "different features of <emphasis>Dolphin</emphasis> "
2450 "<link url='https://userbase.kde.org/Dolphin/File_Management'>click here</link>. "
2451 "It will open the dedicated page in the KDE UserBase Wiki.</para>"));
2453 const QString whatsThisWhatsThis
= xi18nc("@info:whatsthis whatsthis button",
2454 "<para>This is the button that invokes the help feature you are "
2455 "using right now! Click it, then click any component of this "
2456 "application to ask \"What's this?\" about it. The mouse cursor "
2457 "will change appearance if no help is available for a spot.</para>");
2458 setStandardActionWhatsThis(KStandardAction::WhatsThis
, whatsThisWhatsThis
2459 + xi18nc("@info:whatsthis second half of whatsthis button text without link",
2460 "<para>There are two other ways to get help for this application: The "
2461 "<interface>Dolphin Handbook</interface> in the <interface>Help"
2462 "</interface> menu and the <emphasis>KDE UserBase Wiki</emphasis> "
2463 "article about <emphasis>File Management</emphasis> online."
2464 "</para><para>The \"What's this?\" help is "
2465 "missing in most other windows so don't get too used to this.</para>"));
2466 setHelpActionWhatsThis(KHelpMenu::menuWhatsThis
, whatsThisWhatsThis
2467 + xi18nc("@info:whatsthis second half of whatsthis button text with link",
2468 "<para>There are two other ways to get help: "
2469 "The <link url='help:/dolphin/index.html'>Dolphin Handbook</link> and "
2470 "the <link url='https://userbase.kde.org/Dolphin/File_Management'>KDE "
2471 "UserBase Wiki</link>.</para><para>The \"What's this?\" help is "
2472 "missing in most other windows so don't get too used to this.</para>"));
2474 const QString whatsThisReportBug
= xi18nc("@info:whatsthis","<para>This opens a "
2475 "window that will guide you through reporting errors or flaws "
2476 "in this application or in other KDE software.</para>");
2477 setStandardActionWhatsThis(KStandardAction::ReportBug
, whatsThisReportBug
);
2478 setHelpActionWhatsThis(KHelpMenu::menuReportBug
, whatsThisReportBug
2479 + xi18nc("@info:whatsthis second half of reportbug text with link",
2480 "<para>High-quality bug reports are much appreciated. To learn "
2481 "how to make your bug report as effective as possible "
2482 "<link url='https://community.kde.org/Get_Involved/Bug_Reporting'>"
2483 "click here</link>.</para>"));
2485 const QString whatsThisDonate
= xi18nc("@info:whatsthis","<para>This opens a "
2486 "<emphasis>web page</emphasis> where you can donate to "
2487 "support the continued work on this application and many "
2488 "other projects by the <emphasis>KDE</emphasis> community.</para>"
2489 "<para>Donating is the easiest and fastest way to efficiently "
2490 "support KDE and its projects. KDE projects are available for "
2491 "free therefore your donation is needed to cover things that "
2492 "require money like servers, contributor meetings, etc.</para>"
2493 "<para><emphasis>KDE e.V.</emphasis> is the non-profit "
2494 "organization behind the KDE community.</para>");
2495 setStandardActionWhatsThis(KStandardAction::Donate
, whatsThisDonate
);
2496 setHelpActionWhatsThis(KHelpMenu::menuDonate
, whatsThisDonate
);
2498 const QString whatsThisSwitchLanguage
= xi18nc("@info:whatsthis",
2499 "With this you can change the language this application uses."
2500 "<nl/>You can even set secondary languages which will be used "
2501 "if texts are not available in your preferred language.");
2502 setStandardActionWhatsThis(KStandardAction::SwitchApplicationLanguage
,
2503 whatsThisSwitchLanguage
);
2504 setHelpActionWhatsThis(KHelpMenu::menuSwitchLanguage
, whatsThisSwitchLanguage
);
2506 const QString whatsThisAboutApp
= xi18nc("@info:whatsthis","This opens a "
2507 "window that informs you about the version, license, "
2508 "used libraries and maintainers of this application.");
2509 setStandardActionWhatsThis(KStandardAction::AboutApp
, whatsThisAboutApp
);
2510 setHelpActionWhatsThis(KHelpMenu::menuAboutApp
, whatsThisAboutApp
);
2512 const QString whatsThisAboutKDE
= xi18nc("@info:whatsthis","This opens a "
2513 "window with information about <emphasis>KDE</emphasis>. "
2514 "The KDE community are the people behind this free software."
2515 "<nl/>If you like using this application but don't know "
2516 "about KDE or want to see a cute dragon have a look!");
2517 setStandardActionWhatsThis(KStandardAction::AboutKDE
, whatsThisAboutKDE
);
2518 setHelpActionWhatsThis(KHelpMenu::menuAboutKDE
, whatsThisAboutKDE
);
2521 bool DolphinMainWindow::addHamburgerMenuToToolbar()
2523 QDomDocument domDocument
= KXMLGUIClient::domDocument();
2524 if (domDocument
.isNull()) {
2527 QDomNode toolbar
= domDocument
.elementsByTagName(QStringLiteral("ToolBar")).at(0);
2528 if (toolbar
.isNull()) {
2532 QDomElement hamburgerMenuElement
= domDocument
.createElement(QStringLiteral("Action"));
2533 hamburgerMenuElement
.setAttribute(QStringLiteral("name"), QStringLiteral("hamburger_menu"));
2534 toolbar
.appendChild(hamburgerMenuElement
);
2536 KXMLGUIFactory::saveConfigFile(domDocument
, xmlFile());
2540 // Make sure to also remove the <KXMLGUIFactory> and <QDomDocument> include
2541 // whenever this method is removed (maybe in the year ~2026).
2544 bool DolphinMainWindow::event(QEvent
*event
)
2546 if (event
->type() == QEvent::WhatsThisClicked
) {
2548 QWhatsThisClickedEvent
* whatsThisEvent
= dynamic_cast<QWhatsThisClickedEvent
*>(event
);
2549 QDesktopServices::openUrl(QUrl(whatsThisEvent
->href()));
2552 return KXmlGuiWindow::event(event
);
2555 bool DolphinMainWindow::eventFilter(QObject
* obj
, QEvent
* event
)
2558 if (event
->type() == QEvent::WhatsThisClicked
) {
2560 QWhatsThisClickedEvent
* whatsThisEvent
= dynamic_cast<QWhatsThisClickedEvent
*>(event
);
2561 QDesktopServices::openUrl(QUrl(whatsThisEvent
->href()));
2567 // Set a sane initial window size
2568 QSize
DolphinMainWindow::sizeHint() const
2570 return KXmlGuiWindow::sizeHint().expandedTo(QSize(760, 550));
2573 void DolphinMainWindow::saveNewToolbarConfig()
2575 KXmlGuiWindow::saveNewToolbarConfig(); // Applies the new config. This has to be called first
2576 // because the rest of this method decides things
2577 // based on the new config.
2578 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
2579 (actionCollection()->action(QStringLiteral("url_navigators")));
2580 if (!toolBar()->actions().contains(navigators
)) {
2581 m_tabWidget
->currentTabPage()->insertNavigatorsWidget(navigators
);
2583 updateAllowedToolbarAreas();
2584 (static_cast<KHamburgerMenu
*>(actionCollection()->action(KStandardAction::name(
2585 KStandardAction::HamburgerMenu
))))->hideActionsOf(toolBar());
2588 void DolphinMainWindow::focusTerminalPanel()
2590 if (m_terminalPanel
->isVisible()) {
2591 if (m_terminalPanel
->terminalHasFocus()) {
2592 m_activeViewContainer
->view()->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2593 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2595 m_terminalPanel
->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2596 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2599 actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger();
2600 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2604 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
2605 KIO::FileUndoManager::UiInterface()
2609 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2613 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
2615 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2617 DolphinViewContainer
* container
= mainWin
->activeViewContainer();
2618 container
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
2620 KIO::FileUndoManager::UiInterface::jobError(job
);
2624 bool DolphinMainWindow::isUrlOpen(const QString
& url
)
2626 return m_tabWidget
->isUrlOpen(QUrl::fromUserInput((url
)));