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 DiskSpaceUsageMenu
;
36 class DolphinBookmarkHandler
;
37 class DolphinViewActionHandler
;
38 class DolphinSettingsDialog
;
39 class DolphinViewContainer
;
40 class DolphinRemoteEncoding
;
41 class DolphinTabWidget
;
46 class KRecentFilesAction
;
47 class KToolBarPopupAction
;
52 /** Used to identify that a custom command should be triggered on a view background double-click.*/
53 constexpr QLatin1String customCommand
{"CUSTOM_COMMAND"};
58 class CommandLauncherJob
;
60 namespace SelectionMode
62 class ActionTextHelper
;
66 * @short Main window for Dolphin.
68 * Handles the menus, toolbars and Dolphin views.
70 class DolphinMainWindow
: public KXmlGuiWindow
73 Q_CLASSINFO("D-Bus Interface", "org.kde.dolphin.MainWindow")
77 ~DolphinMainWindow() override
;
80 * Returns the currently active view.
81 * All menu actions are applied to this view. When
82 * having a split view setup, the nonactive view
83 * is usually shown in darker colors.
85 DolphinViewContainer
*activeViewContainer() const;
88 * Returns view container for all tabs
90 QVector
<DolphinViewContainer
*> viewContainers() const;
93 * Opens each directory in \p dirs in a separate tab. If \a splitView is set,
94 * 2 directories are collected within one tab.
95 * \pre \a dirs must contain at least one url.
97 void openDirectories(const QList
<QUrl
> &dirs
, bool splitView
);
100 * Opens the directories which contain the files \p files and selects all files.
101 * If \a splitView is set, 2 directories are collected within one tab.
102 * \pre \a files must contain at least one url.
104 void openFiles(const QList
<QUrl
> &files
, bool splitView
);
107 * Returns the 'Create New...' sub menu which also can be shared
108 * with other menus (e. g. a context menu).
110 KNewFileMenu
*newFileMenu() const;
113 * Augments Qt's build-in QMainWindow context menu to add
114 * Dolphin-specific actions, such as "unlock panels".
116 QMenu
*createPopupMenu() override
;
119 * Switch the window's view containers' locations to display the home path
120 * for any which are currently displaying a location corresponding to or
123 * This typically done after unmounting a disk at mountPath to ensure that
124 * the window is not displaying an invalid location.
126 void setViewsToHomeIfMountPathOpen(const QString
&mountPath
);
129 * Enables or disables the session autosaving feature.
131 * @param enable If true, saves the session automatically after a fixed
132 * time interval from the last state change.
134 void setSessionAutoSaveEnabled(bool enable
);
136 bool isFoldersPanelEnabled() const;
137 bool isInformationPanelEnabled() const;
138 bool isSplitViewEnabledInCurrentTab() const;
141 * Activates a user set action when double clicking the view's background.
143 void slotDoubleClickViewBackground(Qt::MouseButton button
);
147 * Opens each directory in \p dirs in a separate tab. If \a splitView is set,
148 * 2 directories are collected within one tab.
149 * \pre \a dirs must contain at least one url.
151 * @note this function is overloaded so that it is callable via DBus.
153 void openDirectories(const QStringList
&dirs
, bool splitView
);
156 * Opens the directories which contain the files \p files and selects all files.
157 * If \a splitView is set, 2 directories are collected within one tab.
158 * \pre \a files must contain at least one url.
160 * @note this is overloaded so that this function is callable via DBus.
162 void openFiles(const QStringList
&files
, bool splitView
);
165 * Tries to raise/activate the Dolphin window.
167 void activateWindow(const QString
&activationToken
);
169 bool isActiveWindow();
172 * Determines if a URL is open in any tab.
173 * @note Use of QString instead of QUrl is required to be callable via DBus.
175 * @param url URL to look for
176 * @returns true if url is currently open in a tab, false otherwise.
178 bool isUrlOpen(const QString
&url
);
181 * @return Whether the item with @p url can be found in any view only by switching
182 * between already open tabs and scrolling in their primary or secondary view.
183 * @note Use of QString instead of QUrl is required to be callable via DBus.
185 bool isItemVisibleInAnyView(const QString
&urlOfItem
);
188 * Pastes the clipboard data into the currently selected folder
189 * of the active view. If not exactly one folder is selected,
190 * no pasting is done at all.
192 void pasteIntoFolder();
195 * Implementation of the MainWindowAdaptor/QDBusAbstractAdaptor interface.
196 * Inform all affected dolphin components (panels, views) of an URL
199 void changeUrl(const QUrl
&url
);
202 * The current directory of the Terminal Panel has changed, probably because
203 * the user entered a 'cd' command. This slot calls changeUrl(url) and makes
204 * sure that the panel keeps the keyboard focus.
206 void slotTerminalDirectoryChanged(const QUrl
&url
);
208 /** Stores all settings and quits Dolphin. */
212 * Opens a new tab in the background showing the URL \a url.
213 * @return A pointer to the opened DolphinTabPage.
215 DolphinTabPage
*openNewTab(const QUrl
&url
);
218 * Opens a new tab showing the URL \a url and activate it.
220 void openNewTabAndActivate(const QUrl
&url
);
223 * Opens a new window showing the URL \a url.
225 void openNewWindow(const QUrl
&url
);
227 /** @see GeneralSettings::splitViewChanged() */
228 void slotSplitViewChanged();
232 * Is sent if the selection of the currently active view has
235 void selectionChanged(const KFileItemList
&selection
);
238 * Is sent if the url of the currently active view has
241 void urlChanged(const QUrl
&url
);
244 * Is emitted if information of an item is requested to be shown e. g. in the panel.
245 * If item is null, no item information request is pending.
247 void requestItemInfo(const KFileItem
&item
);
250 * It is emitted when in the current view, files are changed,
251 * or dirs have files/removed from them.
253 void fileItemsChanged(const KFileItemList
&changedFileItems
);
256 * Is emitted if the settings have been changed.
258 void settingsChanged();
261 /** @see QObject::event() */
262 bool event(QEvent
*event
) override
;
264 /** @see QWidget::showEvent() */
265 void showEvent(QShowEvent
*event
) override
;
267 /** @see QMainWindow::closeEvent() */
268 void closeEvent(QCloseEvent
*event
) override
;
270 /** @see KMainWindow::saveProperties() */
271 void saveProperties(KConfigGroup
&group
) override
;
273 /** @see KMainWindow::readProperties() */
274 void readProperties(const KConfigGroup
&group
) override
;
276 /** Sets a sane initial window size **/
277 QSize
sizeHint() const override
;
281 * Calls the base method KXmlGuiWindow::saveNewToolbarConfig().
282 * Is also used to set toolbar constraints and UrlNavigator position
283 * based on the newly changed toolbar configuration.
285 void saveNewToolbarConfig() override
;
289 * Refreshes the views of the main window by recreating them according to
290 * the given Dolphin settings.
294 void clearStatusBar();
296 /** Updates the 'Create New...' sub menu. */
297 void updateNewMenu();
299 void createDirectory();
302 /** Shows the error message in the status bar of the active view. */
303 void showErrorMessage(const QString
&message
);
306 * Updates the state of the 'Undo' menu action dependent
307 * on the parameter \a available.
309 void slotUndoAvailable(bool available
);
311 /** Sets the text of the 'Undo' menu action to \a text. */
312 void slotUndoTextChanged(const QString
&text
);
314 /** Performs the current undo operation. */
318 * Copies all selected items to the clipboard and marks
323 /** Copies all selected items to the clipboard. */
326 /** Pastes the clipboard data to the active view. */
329 /** Replaces the URL navigator by a search box to find files. */
332 /** Updates the state of the search action according to the view container. */
333 void updateSearchAction();
336 * Updates the text of the paste action dependent on
337 * the number of items which are in the clipboard.
339 void updatePasteAction();
341 /** Calls DolphinViewContainer::setSelectionMode() for m_activeViewContainer. */
342 void slotSetSelectionMode(bool enabled
, SelectionMode::BottomBar::Contents bottomBarContents
);
344 /** Selects all items from the active view. */
348 * Inverts the selection of all items of the active view:
349 * Selected items get nonselected and nonselected items get
352 void invertSelection();
355 * Switches between one and two views:
356 * If one view is visible, it will get split into two views.
357 * If already two views are visible, the active view gets closed.
359 void toggleSplitView();
362 * Pops out a split view.
363 * The active view will be popped out, unless the view is not split,
364 * in which case nothing will happen.
366 void popoutSplitView();
368 /** Dedicated action to open the stash:/ ioslave in split view. */
369 void toggleSplitStash();
371 /** Copies all selected items to the inactive view. */
372 void copyToInactiveSplitView();
374 /** Moves all selected items to the inactive view. */
375 void moveToInactiveSplitView();
377 /** Reloads the currently active view. */
380 /** Stops the loading process for the currently active view. */
383 void enableStopAction();
384 void disableStopAction();
386 void toggleSelectionMode();
388 void showFilterBar();
389 void toggleFilterBar();
392 * Toggles between edit and browse mode of the navigation bar.
394 void toggleEditLocation();
397 * Switches to the edit mode of the navigation bar and selects
398 * the whole URL, so that it can be replaced by the user. If the edit mode is
399 * already active, it is assured that the navigation bar get focused.
401 void replaceLocation();
404 * Toggles the state of the panels between a locked and unlocked layout.
406 void togglePanelLockState();
409 * Is invoked whenever the Terminal panel visibility is changed by the user and then moves the focus
410 * to the active view if the panel was hidden.
411 * @note The opposite action (putting focus to the Terminal) is not handled
412 * here but in TerminalPanel::showEvent().
413 * @param visible the new visibility state of the terminal panel
415 void slotTerminalPanelVisibilityChanged(bool visible
);
418 * Is invoked whenever the Places panel visibility is changed by the user and then either moves the focus
419 * - to the Places panel if it was made visible, or
420 * - to the active view if the panel was hidden.
421 * @param visible the new visibility state of the Places panel
423 void slotPlacesPanelVisibilityChanged(bool visible
);
425 /** Goes back one step of the URL history. */
428 /** Goes forward one step of the URL history. */
431 /** Goes up one hierarchy of the current URL. */
434 /** Changes the location to the home URL. */
437 /** Open the previous URL in the URL history in a new tab. */
438 void goBackInNewTab();
440 /** Open the next URL in the URL history in a new tab. */
441 void goForwardInNewTab();
443 /** Open the URL one hierarchy above the current URL in a new tab. */
446 /** * Open the home URL in a new tab. */
447 void goHomeInNewTab();
449 /** Opens Kompare for 2 selected files. */
453 * Hides the menu bar if it is visible, makes the menu bar
454 * visible if it is hidden.
456 void toggleShowMenuBar();
458 /** Updates "Open Preferred Search Tool" action. */
459 void updateOpenPreferredSearchToolAction();
461 /** Opens preferred search tool for the current location. */
462 void openPreferredSearchTool();
464 /** Opens a terminal window for the current location. */
467 /** Opens terminal windows for the selected items' locations. */
468 void openTerminalHere();
470 /** Opens a terminal window for the URL. */
471 void openTerminalJob(const QUrl
&url
);
473 /** Toggles focus to/from a Terminal Panel. */
474 void toggleTerminalPanelFocus();
476 /** Toggles focus to/from the Places Panel. */
477 void togglePlacesPanelFocus();
479 /** Opens the settings dialog for Dolphin. */
482 /** Updates the state of the 'Show Full Location' action. */
483 void slotEditableStateChanged(bool editable
);
486 * Updates the state of the 'Edit' menu actions and emits
487 * the signal selectionChanged().
489 void slotSelectionChanged(const KFileItemList
&selection
);
492 * Updates the state of the 'Back' and 'Forward' menu
493 * actions corresponding to the current history.
495 void updateHistory();
497 /** Updates the state of the 'Show filter bar' menu action. */
498 void updateFilterBarAction(bool show
);
500 /** Open a new main window. */
501 void openNewMainWindow();
504 * Opens a new view with the current URL that is part of a tab and
507 void openNewActivatedTab();
510 * Adds the current URL as an entry to the Places panel
515 * Opens the selected folder in a new tab.
520 * Opens the selected folder in a new window.
522 void openInNewWindow();
525 * Opens the selected folder in the other inactive split view, enables split view if necessary.
527 void openInSplitView(const QUrl
&url
);
530 * Show the target of the selected symlink
535 * Indicates in the statusbar that the execution of the command \a command
538 void showCommand(CommandType command
);
541 * If the URL can be listed, open it in the current view, otherwise
542 * run it through KRun.
544 void handleUrl(const QUrl
&url
);
547 * Is invoked when the write state of a folder has been changed and
548 * enables/disables the "Create New..." menu entry.
550 void slotWriteStateChanged(bool isFolderWritable
);
553 * Opens the context menu on the current mouse position.
554 * @pos Position in screen coordinates.
555 * @item File item context. If item is null, the context menu
556 * should be applied to \a url.
557 * @selectedItems The selected items for which the context menu
558 * is opened. This list generally includes \a item.
559 * @url URL which contains \a item.
561 void openContextMenu(const QPoint
&pos
, const KFileItem
&item
, const KFileItemList
&selectedItems
, const QUrl
&url
);
564 * Updates the menu that is by default at the right end of the toolbar.
566 * In true "simple by default" fashion, the menu only contains the most important
567 * and necessary actions to be able to use Dolphin. This is supposed to hold true even
568 * if the user does not know how to open a context menu. More advanced actions can be
569 * discovered through a sub-menu (@see KConfigWidgets::KHamburgerMenu::setMenuBarAdvertised()).
571 void updateHamburgerMenu();
574 * Is called if the user clicked an item in the Places Panel.
575 * Reloads the view if \a url is the current URL already, and changes the
576 * current URL otherwise.
578 void slotPlaceActivated(const QUrl
&url
);
581 * Is called if the another view has been activated by changing the current
582 * tab or activating another view in split-view mode.
584 * Activates the given view, which means that all menu actions are applied
585 * to this view. When having a split view setup, the nonactive view is
586 * usually shown in darker colors.
588 void activeViewChanged(DolphinViewContainer
*viewContainer
);
590 void closedTabsCountChanged(unsigned int count
);
593 * Is called if a new tab has been opened or a tab has been closed to
594 * enable/disable the tab actions.
596 void tabCountChanged(int count
);
599 * Updates the Window Title with the caption from the active view container
601 void updateWindowTitle();
604 * This slot is called when the user requested to unmount a removable media
605 * from the places menu
607 void slotStorageTearDownFromPlacesRequested(const QString
&mountPath
);
610 * This slot is called when the user requested to unmount a removable media
611 * _not_ from the dolphin's places menu (from the notification area for e.g.)
612 * This slot is basically connected to each removable device's
613 * Solid::StorageAccess::teardownRequested(const QString & udi)
614 * signal through the places panel.
616 void slotStorageTearDownExternallyRequested(const QString
&mountPath
);
619 * Is called when the view has finished loading the directory.
621 void slotDirectoryLoadingCompleted();
624 * Is called when the user middle clicks a toolbar button.
626 * Here middle clicking Back/Forward/Up/Home will open the resulting
627 * folder in a new tab.
629 void slotToolBarActionMiddleClicked(QAction
*action
);
632 * Is called before the Back popup menu is shown. This slot will populate
633 * the menu with history data
635 void slotAboutToShowBackPopupMenu();
638 * This slot is used by the Back Popup Menu to go back to a specific
639 * history index. The QAction::data will carry an int with the index
642 void slotGoBack(QAction
*action
);
645 * Middle clicking Back/Forward will open the resulting folder in a new tab.
647 void slotBackForwardActionMiddleClicked(QAction
*action
);
650 * Is called before the Forward popup menu is shown. This slot will populate
651 * the menu with history data
653 void slotAboutToShowForwardPopupMenu();
656 * This slot is used by the Forward Popup Menu to go forward to a specific
657 * history index. The QAction::data will carry an int with the index
660 void slotGoForward(QAction
*action
);
663 * Is called when configuring the keyboard shortcuts
665 void slotKeyBindings();
670 void slotSaveSession();
674 * Sets up the various menus and actions and connects them.
679 * Sets up the dock widgets and their panels.
681 void setupDockWidgets();
683 void updateFileAndEditActions();
684 void updateViewActions();
685 void updateGoActions();
688 * Connects the signals from the created DolphinView with
689 * the DolphinViewContainer \a container with the corresponding slots of
690 * the DolphinMainWindow. This method must be invoked each
691 * time a DolphinView has been created.
693 void connectViewSignals(DolphinViewContainer
*container
);
696 * Updates the text of the split action:
697 * If two views are shown, the text is set to "Split",
698 * otherwise the text is set to "Join". The icon
699 * is updated to match with the text and the currently active view.
701 void updateSplitActions();
704 * Sets the window sides the toolbar may be moved to based on toolbar contents.
706 void updateAllowedToolbarAreas();
709 * Sets the background of the location bar(s) on if they are inside the toolbar,
710 * or off if they are outside the toolbar.
712 void updateNavigatorsBackground();
714 bool isKompareInstalled() const;
717 * Creates an action for showing/hiding a panel, that is accessible
718 * in "Configure toolbars..." and "Configure shortcuts...".
720 void createPanelAction(const QIcon
&icon
, const QKeySequence
&shortcut
, QDockWidget
*dockAction
, const QString
&actionName
);
722 /** Adds "What's This?" texts to many widgets and StandardActions. */
723 void setupWhatsThis();
725 /** Returns preferred search tool as configured in "More Search Tools" menu. */
726 QPointer
<QAction
> preferredSearchTool();
729 * Adds this action to the mainWindow's toolbar and saves the change
730 * in the users ui configuration file.
731 * This method is only needed for migration and should be removed once we can expect
732 * that pretty much all users have been migrated. Remove in 2026 because that's when
733 * even the most risk-averse distros will already have been forced to upgrade.
734 * @return true if successful. Otherwise false.
736 bool addHamburgerMenuToToolbar();
738 /** Creates an action representing an item in the URL navigator history */
739 static QAction
*urlNavigatorHistoryAction(const KUrlNavigator
*urlNavigator
, int historyIndex
, QObject
*parent
= nullptr);
743 * Implements a custom error handling for the undo manager. This
744 * assures that all errors are shown in the status bar of Dolphin
745 * instead as modal error dialog with an OK button.
747 class UndoUiInterface
: public KIO::FileUndoManager::UiInterface
751 ~UndoUiInterface() override
;
752 void jobError(KIO::Job
*job
) override
;
755 KNewFileMenu
*m_newFileMenu
;
756 DolphinTabWidget
*m_tabWidget
;
757 DolphinViewContainer
*m_activeViewContainer
;
759 DolphinViewActionHandler
*m_actionHandler
;
760 DolphinRemoteEncoding
*m_remoteEncoding
;
761 QPointer
<DolphinSettingsDialog
> m_settingsDialog
;
762 DolphinBookmarkHandler
*m_bookmarkHandler
;
763 SelectionMode::ActionTextHelper
*m_actionTextHelper
;
764 DisabledActionNotifier
*m_disabledActionNotifier
;
766 KIO::OpenUrlJob
*m_lastHandleUrlOpenJob
;
768 TerminalPanel
*m_terminalPanel
;
769 PlacesPanel
*m_placesPanel
;
770 bool m_tearDownFromPlacesRequested
;
772 KToolBarPopupAction
*m_backAction
;
773 KToolBarPopupAction
*m_forwardAction
;
774 KActionMenu
*m_splitViewAction
;
775 QAction
*m_splitViewMenuAction
;
776 DiskSpaceUsageMenu
*m_diskSpaceUsageMenu
;
779 KFileItemActions m_fileItemActions
;
781 QTimer
*m_sessionSaveTimer
;
782 QFutureWatcher
<void> *m_sessionSaveWatcher
;
783 bool m_sessionSaveScheduled
;
785 KIO::CommandLauncherJob
*m_job
;
787 KRecentFilesAction
*m_recentFiles
= nullptr;
789 friend class DolphinMainWindowTest
;
792 inline DolphinViewContainer
*DolphinMainWindow::activeViewContainer() const
794 return m_activeViewContainer
;
797 inline KNewFileMenu
*DolphinMainWindow::newFileMenu() const
799 return m_newFileMenu
;
802 #endif // DOLPHIN_MAINWINDOW_H