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 #ifndef DOLPHIN_MAINWINDOW_H
10 #define DOLPHIN_MAINWINDOW_H
12 #include "config-dolphin.h"
13 #include "disabledactionnotifier.h"
14 #include "dolphintabwidget.h"
15 #include "selectionmode/bottombar.h"
16 #include <KActionMenu>
17 #include <KFileItemActions>
18 #include <kio/fileundomanager.h>
19 #include <kxmlguiwindow.h>
22 #include "panels/information/informationpanel.h"
25 #include <QFutureWatcher>
33 typedef KIO::FileUndoManager::CommandType CommandType
;
35 class DolphinBookmarkHandler
;
36 class DolphinViewActionHandler
;
37 class DolphinSettingsDialog
;
38 class DolphinViewContainer
;
39 class DolphinRemoteEncoding
;
40 class DolphinTabWidget
;
45 class KToolBarPopupAction
;
50 /** Used to identify that a custom command should be triggered on a view background double-click.*/
51 constexpr QLatin1String customCommand
{"CUSTOM_COMMAND"};
56 class CommandLauncherJob
;
58 namespace SelectionMode
60 class ActionTextHelper
;
64 * @short Main window for Dolphin.
66 * Handles the menus, toolbars and Dolphin views.
68 class DolphinMainWindow
: public KXmlGuiWindow
71 Q_CLASSINFO("D-Bus Interface", "org.kde.dolphin.MainWindow")
75 ~DolphinMainWindow() override
;
78 * Returns the currently active view.
79 * All menu actions are applied to this view. When
80 * having a split view setup, the nonactive view
81 * is usually shown in darker colors.
83 DolphinViewContainer
*activeViewContainer() const;
86 * Returns view container for all tabs
88 QVector
<DolphinViewContainer
*> viewContainers() const;
91 * Opens each directory in \p dirs in a separate tab. If \a splitView is set,
92 * 2 directories are collected within one tab.
93 * \pre \a dirs must contain at least one url.
95 void openDirectories(const QList
<QUrl
> &dirs
, bool splitView
);
98 * Opens the directories which contain the files \p files and selects all files.
99 * If \a splitView is set, 2 directories are collected within one tab.
100 * \pre \a files must contain at least one url.
102 void openFiles(const QList
<QUrl
> &files
, bool splitView
);
105 * Returns the 'Create New...' sub menu which also can be shared
106 * with other menus (e. g. a context menu).
108 KNewFileMenu
*newFileMenu() const;
111 * Augments Qt's build-in QMainWindow context menu to add
112 * Dolphin-specific actions, such as "unlock panels".
114 QMenu
*createPopupMenu() override
;
117 * Switch the window's view containers' locations to display the home path
118 * for any which are currently displaying a location corresponding to or
121 * This typically done after unmounting a disk at mountPath to ensure that
122 * the window is not displaying an invalid location.
124 void setViewsToHomeIfMountPathOpen(const QString
&mountPath
);
127 * Enables or disables the session autosaving feature.
129 * @param enable If true, saves the session automatically after a fixed
130 * time interval from the last state change.
132 void setSessionAutoSaveEnabled(bool enable
);
134 bool isFoldersPanelEnabled() const;
135 bool isInformationPanelEnabled() const;
136 bool isSplitViewEnabledInCurrentTab() const;
139 * Activates a user set action when double clicking the view's background.
141 void slotDoubleClickViewBackground(Qt::MouseButton button
);
145 * Opens each directory in \p dirs in a separate tab. If \a splitView is set,
146 * 2 directories are collected within one tab.
147 * \pre \a dirs must contain at least one url.
149 * @note this function is overloaded so that it is callable via DBus.
151 void openDirectories(const QStringList
&dirs
, bool splitView
);
154 * Opens the directories which contain the files \p files and selects all files.
155 * If \a splitView is set, 2 directories are collected within one tab.
156 * \pre \a files must contain at least one url.
158 * @note this is overloaded so that this function is callable via DBus.
160 void openFiles(const QStringList
&files
, bool splitView
);
163 * Tries to raise/activate the Dolphin window.
165 void activateWindow(const QString
&activationToken
);
167 bool isActiveWindow();
170 * Determines if a URL is open in any tab.
171 * @note Use of QString instead of QUrl is required to be callable via DBus.
173 * @param url URL to look for
174 * @returns true if url is currently open in a tab, false otherwise.
176 bool isUrlOpen(const QString
&url
);
179 * @return Whether the item with @p url can be found in any view only by switching
180 * between already open tabs and scrolling in their primary or secondary view.
181 * @note Use of QString instead of QUrl is required to be callable via DBus.
183 bool isItemVisibleInAnyView(const QString
&urlOfItem
);
186 * Pastes the clipboard data into the currently selected folder
187 * of the active view. If not exactly one folder is selected,
188 * no pasting is done at all.
190 void pasteIntoFolder();
193 * Implementation of the MainWindowAdaptor/QDBusAbstractAdaptor interface.
194 * Inform all affected dolphin components (panels, views) of an URL
197 void changeUrl(const QUrl
&url
);
200 * The current directory of the Terminal Panel has changed, probably because
201 * the user entered a 'cd' command. This slot calls changeUrl(url) and makes
202 * sure that the panel keeps the keyboard focus.
204 void slotTerminalDirectoryChanged(const QUrl
&url
);
206 /** Stores all settings and quits Dolphin. */
210 * Opens a new tab in the background showing the URL \a url.
212 void openNewTab(const QUrl
&url
);
215 * Opens a new tab showing the URL \a url and activate it.
217 void openNewTabAndActivate(const QUrl
&url
);
220 * Opens a new window showing the URL \a url.
222 void openNewWindow(const QUrl
&url
);
224 /** @see GeneralSettings::splitViewChanged() */
225 void slotSplitViewChanged();
229 * Is sent if the selection of the currently active view has
232 void selectionChanged(const KFileItemList
&selection
);
235 * Is sent if the url of the currently active view has
238 void urlChanged(const QUrl
&url
);
241 * Is emitted if information of an item is requested to be shown e. g. in the panel.
242 * If item is null, no item information request is pending.
244 void requestItemInfo(const KFileItem
&item
);
247 * It is emitted when in the current view, files are changed,
248 * or dirs have files/removed from them.
250 void fileItemsChanged(const KFileItemList
&changedFileItems
);
253 * Is emitted if the settings have been changed.
255 void settingsChanged();
258 /** @see QObject::event() */
259 bool event(QEvent
*event
) override
;
261 /** @see QWidget::showEvent() */
262 void showEvent(QShowEvent
*event
) override
;
264 /** @see QMainWindow::closeEvent() */
265 void closeEvent(QCloseEvent
*event
) override
;
267 /** @see KMainWindow::saveProperties() */
268 void saveProperties(KConfigGroup
&group
) override
;
270 /** @see KMainWindow::readProperties() */
271 void readProperties(const KConfigGroup
&group
) override
;
273 /** Sets a sane initial window size **/
274 QSize
sizeHint() const override
;
278 * Calls the base method KXmlGuiWindow::saveNewToolbarConfig().
279 * Is also used to set toolbar constraints and UrlNavigator position
280 * based on the newly changed toolbar configuration.
282 void saveNewToolbarConfig() override
;
286 * Refreshes the views of the main window by recreating them according to
287 * the given Dolphin settings.
291 void clearStatusBar();
293 /** Updates the 'Create New...' sub menu. */
294 void updateNewMenu();
296 void createDirectory();
298 /** Shows the error message in the status bar of the active view. */
299 void showErrorMessage(const QString
&message
);
302 * Updates the state of the 'Undo' menu action dependent
303 * on the parameter \a available.
305 void slotUndoAvailable(bool available
);
307 /** Sets the text of the 'Undo' menu action to \a text. */
308 void slotUndoTextChanged(const QString
&text
);
310 /** Performs the current undo operation. */
314 * Copies all selected items to the clipboard and marks
319 /** Copies all selected items to the clipboard. */
322 /** Pastes the clipboard data to the active view. */
325 /** Replaces the URL navigator by a search box to find files. */
328 /** Updates the state of the search action according to the view container. */
329 void updateSearchAction();
332 * Updates the text of the paste action dependent on
333 * the number of items which are in the clipboard.
335 void updatePasteAction();
337 /** Calls DolphinViewContainer::setSelectionMode() for m_activeViewContainer. */
338 void slotSetSelectionMode(bool enabled
, SelectionMode::BottomBar::Contents bottomBarContents
);
340 /** Selects all items from the active view. */
344 * Inverts the selection of all items of the active view:
345 * Selected items get nonselected and nonselected items get
348 void invertSelection();
351 * Switches between one and two views:
352 * If one view is visible, it will get split into two views.
353 * If already two views are visible, the active view gets closed.
355 void toggleSplitView();
358 * Pops out a split view.
359 * The active view will be popped out, unless the view is not split,
360 * in which case nothing will happen.
362 void popoutSplitView();
364 /** Dedicated action to open the stash:/ ioslave in split view. */
365 void toggleSplitStash();
367 /** Copies all selected items to the inactive view. */
368 void copyToInactiveSplitView();
370 /** Moves all selected items to the inactive view. */
371 void moveToInactiveSplitView();
373 /** Reloads the currently active view. */
376 /** Stops the loading process for the currently active view. */
379 void enableStopAction();
380 void disableStopAction();
382 void toggleSelectionMode();
384 void showFilterBar();
385 void toggleFilterBar();
388 * Toggles between edit and browse mode of the navigation bar.
390 void toggleEditLocation();
393 * Switches to the edit mode of the navigation bar and selects
394 * the whole URL, so that it can be replaced by the user. If the edit mode is
395 * already active, it is assured that the navigation bar get focused.
397 void replaceLocation();
400 * Toggles the state of the panels between a locked and unlocked layout.
402 void togglePanelLockState();
405 * Is invoked if the Terminal panel got visible/invisible and takes care
406 * that the active view has the focus if the Terminal panel is invisible.
408 void slotTerminalPanelVisibilityChanged();
410 /** Goes back one step of the URL history. */
413 /** Goes forward one step of the URL history. */
416 /** Goes up one hierarchy of the current URL. */
419 /** Changes the location to the home URL. */
422 /** Open the previous URL in the URL history in a new tab. */
423 void goBackInNewTab();
425 /** Open the next URL in the URL history in a new tab. */
426 void goForwardInNewTab();
428 /** Open the URL one hierarchy above the current URL in a new tab. */
431 /** * Open the home URL in a new tab. */
432 void goHomeInNewTab();
434 /** Opens Kompare for 2 selected files. */
438 * Hides the menu bar if it is visible, makes the menu bar
439 * visible if it is hidden.
441 void toggleShowMenuBar();
443 /** Updates "Open Preferred Search Tool" action. */
444 void updateOpenPreferredSearchToolAction();
446 /** Opens preferred search tool for the current location. */
447 void openPreferredSearchTool();
449 /** Opens a terminal window for the current location. */
452 /** Opens terminal windows for the selected items' locations. */
453 void openTerminalHere();
455 /** Opens a terminal window for the URL. */
456 void openTerminalJob(const QUrl
&url
);
458 /** Focus a Terminal Panel. */
459 void focusTerminalPanel();
461 /** Opens the settings dialog for Dolphin. */
464 /** Updates the state of the 'Show Full Location' action. */
465 void slotEditableStateChanged(bool editable
);
468 * Updates the state of the 'Edit' menu actions and emits
469 * the signal selectionChanged().
471 void slotSelectionChanged(const KFileItemList
&selection
);
474 * Updates the state of the 'Back' and 'Forward' menu
475 * actions corresponding to the current history.
477 void updateHistory();
479 /** Updates the state of the 'Show filter bar' menu action. */
480 void updateFilterBarAction(bool show
);
482 /** Open a new main window. */
483 void openNewMainWindow();
486 * Opens a new view with the current URL that is part of a tab and
489 void openNewActivatedTab();
492 * Adds the current URL as an entry to the Places panel
497 * Opens the selected folder in a new tab.
502 * Opens the selected folder in a new window.
504 void openInNewWindow();
507 * Opens the selected folder in the other inactive split view, enables split view if necessary.
509 void openInSplitView(const QUrl
&url
);
512 * Show the target of the selected symlink
517 * Indicates in the statusbar that the execution of the command \a command
520 void showCommand(CommandType command
);
523 * If the URL can be listed, open it in the current view, otherwise
524 * run it through KRun.
526 void handleUrl(const QUrl
&url
);
529 * Is invoked when the write state of a folder has been changed and
530 * enables/disables the "Create New..." menu entry.
532 void slotWriteStateChanged(bool isFolderWritable
);
535 * Opens the context menu on the current mouse position.
536 * @pos Position in screen coordinates.
537 * @item File item context. If item is null, the context menu
538 * should be applied to \a url.
539 * @selectedItems The selected items for which the context menu
540 * is opened. This list generally includes \a item.
541 * @url URL which contains \a item.
543 void openContextMenu(const QPoint
&pos
, const KFileItem
&item
, const KFileItemList
&selectedItems
, const QUrl
&url
);
546 * Updates the menu that is by default at the right end of the toolbar.
548 * In true "simple by default" fashion, the menu only contains the most important
549 * and necessary actions to be able to use Dolphin. This is supposed to hold true even
550 * if the user does not know how to open a context menu. More advanced actions can be
551 * discovered through a sub-menu (@see KConfigWidgets::KHamburgerMenu::setMenuBarAdvertised()).
553 void updateHamburgerMenu();
556 * Is called if the user clicked an item in the Places Panel.
557 * Reloads the view if \a url is the current URL already, and changes the
558 * current URL otherwise.
560 void slotPlaceActivated(const QUrl
&url
);
563 * Is called if the another view has been activated by changing the current
564 * tab or activating another view in split-view mode.
566 * Activates the given view, which means that all menu actions are applied
567 * to this view. When having a split view setup, the nonactive view is
568 * usually shown in darker colors.
570 void activeViewChanged(DolphinViewContainer
*viewContainer
);
572 void closedTabsCountChanged(unsigned int count
);
575 * Is called if a new tab has been opened or a tab has been closed to
576 * enable/disable the tab actions.
578 void tabCountChanged(int count
);
581 * Updates the Window Title with the caption from the active view container
583 void updateWindowTitle();
586 * This slot is called when the user requested to unmount a removable media
587 * from the places menu
589 void slotStorageTearDownFromPlacesRequested(const QString
&mountPath
);
592 * This slot is called when the user requested to unmount a removable media
593 * _not_ from the dolphin's places menu (from the notification area for e.g.)
594 * This slot is basically connected to each removable device's
595 * Solid::StorageAccess::teardownRequested(const QString & udi)
596 * signal through the places panel.
598 void slotStorageTearDownExternallyRequested(const QString
&mountPath
);
601 * Is called when the view has finished loading the directory.
603 void slotDirectoryLoadingCompleted();
606 * Is called when the user middle clicks a toolbar button.
608 * Here middle clicking Back/Forward/Up/Home will open the resulting
609 * folder in a new tab.
611 void slotToolBarActionMiddleClicked(QAction
*action
);
614 * Is called before the Back popup menu is shown. This slot will populate
615 * the menu with history data
617 void slotAboutToShowBackPopupMenu();
620 * This slot is used by the Back Popup Menu to go back to a specific
621 * history index. The QAction::data will carry an int with the index
624 void slotGoBack(QAction
*action
);
627 * Middle clicking Back/Forward will open the resulting folder in a new tab.
629 void slotBackForwardActionMiddleClicked(QAction
*action
);
632 * Is called before the Forward popup menu is shown. This slot will populate
633 * the menu with history data
635 void slotAboutToShowForwardPopupMenu();
638 * This slot is used by the Forward Popup Menu to go forward to a specific
639 * history index. The QAction::data will carry an int with the index
642 void slotGoForward(QAction
*action
);
645 * Is called when configuring the keyboard shortcuts
647 void slotKeyBindings();
652 void slotSaveSession();
656 * Sets up the various menus and actions and connects them.
661 * Sets up the dock widgets and their panels.
663 void setupDockWidgets();
665 void updateFileAndEditActions();
666 void updateViewActions();
667 void updateGoActions();
670 * Connects the signals from the created DolphinView with
671 * the DolphinViewContainer \a container with the corresponding slots of
672 * the DolphinMainWindow. This method must be invoked each
673 * time a DolphinView has been created.
675 void connectViewSignals(DolphinViewContainer
*container
);
678 * Updates the text of the split action:
679 * If two views are shown, the text is set to "Split",
680 * otherwise the text is set to "Join". The icon
681 * is updated to match with the text and the currently active view.
683 void updateSplitActions();
686 * Sets the window sides the toolbar may be moved to based on toolbar contents.
688 void updateAllowedToolbarAreas();
690 bool isKompareInstalled() const;
693 * Creates an action for showing/hiding a panel, that is accessible
694 * in "Configure toolbars..." and "Configure shortcuts...".
696 void createPanelAction(const QIcon
&icon
, const QKeySequence
&shortcut
, QDockWidget
*dockAction
, const QString
&actionName
);
698 /** Adds "What's This?" texts to many widgets and StandardActions. */
699 void setupWhatsThis();
701 /** Returns preferred search tool as configured in "More Search Tools" menu. */
702 QPointer
<QAction
> preferredSearchTool();
705 * Adds this action to the mainWindow's toolbar and saves the change
706 * in the users ui configuration file.
707 * This method is only needed for migration and should be removed once we can expect
708 * that pretty much all users have been migrated. Remove in 2026 because that's when
709 * even the most risk-averse distros will already have been forced to upgrade.
710 * @return true if successful. Otherwise false.
712 bool addHamburgerMenuToToolbar();
714 /** Creates an action representing an item in the URL navigator history */
715 static QAction
*urlNavigatorHistoryAction(const KUrlNavigator
*urlNavigator
, int historyIndex
, QObject
*parent
= nullptr);
719 * Implements a custom error handling for the undo manager. This
720 * assures that all errors are shown in the status bar of Dolphin
721 * instead as modal error dialog with an OK button.
723 class UndoUiInterface
: public KIO::FileUndoManager::UiInterface
727 ~UndoUiInterface() override
;
728 void jobError(KIO::Job
*job
) override
;
731 KNewFileMenu
*m_newFileMenu
;
732 DolphinTabWidget
*m_tabWidget
;
733 DolphinViewContainer
*m_activeViewContainer
;
735 DolphinViewActionHandler
*m_actionHandler
;
736 DolphinRemoteEncoding
*m_remoteEncoding
;
737 QPointer
<DolphinSettingsDialog
> m_settingsDialog
;
738 DolphinBookmarkHandler
*m_bookmarkHandler
;
739 SelectionMode::ActionTextHelper
*m_actionTextHelper
;
740 DisabledActionNotifier
*m_disabledActionNotifier
;
742 KIO::OpenUrlJob
*m_lastHandleUrlOpenJob
;
744 TerminalPanel
*m_terminalPanel
;
745 PlacesPanel
*m_placesPanel
;
746 bool m_tearDownFromPlacesRequested
;
748 KToolBarPopupAction
*m_backAction
;
749 KToolBarPopupAction
*m_forwardAction
;
750 KActionMenu
*m_splitViewAction
;
751 QAction
*m_splitViewMenuAction
;
754 KFileItemActions m_fileItemActions
;
756 QTimer
*m_sessionSaveTimer
;
757 QFutureWatcher
<void> *m_sessionSaveWatcher
;
758 bool m_sessionSaveScheduled
;
760 KIO::CommandLauncherJob
*m_job
;
762 friend class DolphinMainWindowTest
;
765 inline DolphinViewContainer
*DolphinMainWindow::activeViewContainer() const
767 return m_activeViewContainer
;
770 inline KNewFileMenu
*DolphinMainWindow::newFileMenu() const
772 return m_newFileMenu
;
775 #endif // DOLPHIN_MAINWINDOW_H