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 KRecentFilesAction
;
46 class KToolBarPopupAction
;
51 /** Used to identify that a custom command should be triggered on a view background double-click.*/
52 constexpr QLatin1String customCommand
{"CUSTOM_COMMAND"};
57 class CommandLauncherJob
;
59 namespace SelectionMode
61 class ActionTextHelper
;
65 * @short Main window for Dolphin.
67 * Handles the menus, toolbars and Dolphin views.
69 class DolphinMainWindow
: public KXmlGuiWindow
72 Q_CLASSINFO("D-Bus Interface", "org.kde.dolphin.MainWindow")
76 ~DolphinMainWindow() override
;
79 * Returns the currently active view.
80 * All menu actions are applied to this view. When
81 * having a split view setup, the nonactive view
82 * is usually shown in darker colors.
84 DolphinViewContainer
*activeViewContainer() const;
87 * Returns view container for all tabs
89 QVector
<DolphinViewContainer
*> viewContainers() const;
92 * Opens each directory in \p dirs in a separate tab. If \a splitView is set,
93 * 2 directories are collected within one tab.
94 * \pre \a dirs must contain at least one url.
96 void openDirectories(const QList
<QUrl
> &dirs
, bool splitView
);
99 * Opens the directories which contain the files \p files and selects all files.
100 * If \a splitView is set, 2 directories are collected within one tab.
101 * \pre \a files must contain at least one url.
103 void openFiles(const QList
<QUrl
> &files
, bool splitView
);
106 * Returns the 'Create New...' sub menu which also can be shared
107 * with other menus (e. g. a context menu).
109 KNewFileMenu
*newFileMenu() const;
112 * Augments Qt's build-in QMainWindow context menu to add
113 * Dolphin-specific actions, such as "unlock panels".
115 QMenu
*createPopupMenu() override
;
118 * Switch the window's view containers' locations to display the home path
119 * for any which are currently displaying a location corresponding to or
122 * This typically done after unmounting a disk at mountPath to ensure that
123 * the window is not displaying an invalid location.
125 void setViewsToHomeIfMountPathOpen(const QString
&mountPath
);
128 * Enables or disables the session autosaving feature.
130 * @param enable If true, saves the session automatically after a fixed
131 * time interval from the last state change.
133 void setSessionAutoSaveEnabled(bool enable
);
135 bool isFoldersPanelEnabled() const;
136 bool isInformationPanelEnabled() const;
137 bool isSplitViewEnabledInCurrentTab() const;
140 * Activates a user set action when double clicking the view's background.
142 void slotDoubleClickViewBackground(Qt::MouseButton button
);
146 * Opens each directory in \p dirs in a separate tab. If \a splitView is set,
147 * 2 directories are collected within one tab.
148 * \pre \a dirs must contain at least one url.
150 * @note this function is overloaded so that it is callable via DBus.
152 void openDirectories(const QStringList
&dirs
, bool splitView
);
155 * Opens the directories which contain the files \p files and selects all files.
156 * If \a splitView is set, 2 directories are collected within one tab.
157 * \pre \a files must contain at least one url.
159 * @note this is overloaded so that this function is callable via DBus.
161 void openFiles(const QStringList
&files
, bool splitView
);
164 * Tries to raise/activate the Dolphin window.
166 void activateWindow(const QString
&activationToken
);
168 bool isActiveWindow();
171 * Determines if a URL is open in any tab.
172 * @note Use of QString instead of QUrl is required to be callable via DBus.
174 * @param url URL to look for
175 * @returns true if url is currently open in a tab, false otherwise.
177 bool isUrlOpen(const QString
&url
);
180 * @return Whether the item with @p url can be found in any view only by switching
181 * between already open tabs and scrolling in their primary or secondary view.
182 * @note Use of QString instead of QUrl is required to be callable via DBus.
184 bool isItemVisibleInAnyView(const QString
&urlOfItem
);
187 * Pastes the clipboard data into the currently selected folder
188 * of the active view. If not exactly one folder is selected,
189 * no pasting is done at all.
191 void pasteIntoFolder();
194 * Implementation of the MainWindowAdaptor/QDBusAbstractAdaptor interface.
195 * Inform all affected dolphin components (panels, views) of an URL
198 void changeUrl(const QUrl
&url
);
201 * The current directory of the Terminal Panel has changed, probably because
202 * the user entered a 'cd' command. This slot calls changeUrl(url) and makes
203 * sure that the panel keeps the keyboard focus.
205 void slotTerminalDirectoryChanged(const QUrl
&url
);
207 /** Stores all settings and quits Dolphin. */
211 * Opens a new tab in the background showing the URL \a url.
213 void openNewTab(const QUrl
&url
);
216 * Opens a new tab showing the URL \a url and activate it.
218 void openNewTabAndActivate(const QUrl
&url
);
221 * Opens a new window showing the URL \a url.
223 void openNewWindow(const QUrl
&url
);
225 /** @see GeneralSettings::splitViewChanged() */
226 void slotSplitViewChanged();
230 * Is sent if the selection of the currently active view has
233 void selectionChanged(const KFileItemList
&selection
);
236 * Is sent if the url of the currently active view has
239 void urlChanged(const QUrl
&url
);
242 * Is emitted if information of an item is requested to be shown e. g. in the panel.
243 * If item is null, no item information request is pending.
245 void requestItemInfo(const KFileItem
&item
);
248 * It is emitted when in the current view, files are changed,
249 * or dirs have files/removed from them.
251 void fileItemsChanged(const KFileItemList
&changedFileItems
);
254 * Is emitted if the settings have been changed.
256 void settingsChanged();
259 /** @see QObject::event() */
260 bool event(QEvent
*event
) override
;
262 /** @see QWidget::showEvent() */
263 void showEvent(QShowEvent
*event
) override
;
265 /** @see QMainWindow::closeEvent() */
266 void closeEvent(QCloseEvent
*event
) override
;
268 /** @see KMainWindow::saveProperties() */
269 void saveProperties(KConfigGroup
&group
) override
;
271 /** @see KMainWindow::readProperties() */
272 void readProperties(const KConfigGroup
&group
) override
;
274 /** Sets a sane initial window size **/
275 QSize
sizeHint() const override
;
279 * Calls the base method KXmlGuiWindow::saveNewToolbarConfig().
280 * Is also used to set toolbar constraints and UrlNavigator position
281 * based on the newly changed toolbar configuration.
283 void saveNewToolbarConfig() override
;
287 * Refreshes the views of the main window by recreating them according to
288 * the given Dolphin settings.
292 void clearStatusBar();
294 /** Updates the 'Create New...' sub menu. */
295 void updateNewMenu();
297 void createDirectory();
299 /** Shows the error message in the status bar of the active view. */
300 void showErrorMessage(const QString
&message
);
303 * Updates the state of the 'Undo' menu action dependent
304 * on the parameter \a available.
306 void slotUndoAvailable(bool available
);
308 /** Sets the text of the 'Undo' menu action to \a text. */
309 void slotUndoTextChanged(const QString
&text
);
311 /** Performs the current undo operation. */
315 * Copies all selected items to the clipboard and marks
320 /** Copies all selected items to the clipboard. */
323 /** Pastes the clipboard data to the active view. */
326 /** Replaces the URL navigator by a search box to find files. */
329 /** Updates the state of the search action according to the view container. */
330 void updateSearchAction();
333 * Updates the text of the paste action dependent on
334 * the number of items which are in the clipboard.
336 void updatePasteAction();
338 /** Calls DolphinViewContainer::setSelectionMode() for m_activeViewContainer. */
339 void slotSetSelectionMode(bool enabled
, SelectionMode::BottomBar::Contents bottomBarContents
);
341 /** Selects all items from the active view. */
345 * Inverts the selection of all items of the active view:
346 * Selected items get nonselected and nonselected items get
349 void invertSelection();
352 * Switches between one and two views:
353 * If one view is visible, it will get split into two views.
354 * If already two views are visible, the active view gets closed.
356 void toggleSplitView();
359 * Pops out a split view.
360 * The active view will be popped out, unless the view is not split,
361 * in which case nothing will happen.
363 void popoutSplitView();
365 /** Dedicated action to open the stash:/ ioslave in split view. */
366 void toggleSplitStash();
368 /** Copies all selected items to the inactive view. */
369 void copyToInactiveSplitView();
371 /** Moves all selected items to the inactive view. */
372 void moveToInactiveSplitView();
374 /** Reloads the currently active view. */
377 /** Stops the loading process for the currently active view. */
380 void enableStopAction();
381 void disableStopAction();
383 void toggleSelectionMode();
385 void showFilterBar();
386 void toggleFilterBar();
389 * Toggles between edit and browse mode of the navigation bar.
391 void toggleEditLocation();
394 * Switches to the edit mode of the navigation bar and selects
395 * the whole URL, so that it can be replaced by the user. If the edit mode is
396 * already active, it is assured that the navigation bar get focused.
398 void replaceLocation();
401 * Toggles the state of the panels between a locked and unlocked layout.
403 void togglePanelLockState();
406 * Is invoked if the Terminal panel got visible/invisible and takes care
407 * that the active view has the focus if the Terminal panel is invisible.
409 void slotTerminalPanelVisibilityChanged();
411 /** Goes back one step of the URL history. */
414 /** Goes forward one step of the URL history. */
417 /** Goes up one hierarchy of the current URL. */
420 /** Changes the location to the home URL. */
423 /** Open the previous URL in the URL history in a new tab. */
424 void goBackInNewTab();
426 /** Open the next URL in the URL history in a new tab. */
427 void goForwardInNewTab();
429 /** Open the URL one hierarchy above the current URL in a new tab. */
432 /** * Open the home URL in a new tab. */
433 void goHomeInNewTab();
435 /** Opens Kompare for 2 selected files. */
439 * Hides the menu bar if it is visible, makes the menu bar
440 * visible if it is hidden.
442 void toggleShowMenuBar();
444 /** Updates "Open Preferred Search Tool" action. */
445 void updateOpenPreferredSearchToolAction();
447 /** Opens preferred search tool for the current location. */
448 void openPreferredSearchTool();
450 /** Opens a terminal window for the current location. */
453 /** Opens terminal windows for the selected items' locations. */
454 void openTerminalHere();
456 /** Opens a terminal window for the URL. */
457 void openTerminalJob(const QUrl
&url
);
459 /** Focus a Terminal Panel. */
460 void focusTerminalPanel();
462 /** Opens the settings dialog for Dolphin. */
465 /** Updates the state of the 'Show Full Location' action. */
466 void slotEditableStateChanged(bool editable
);
469 * Updates the state of the 'Edit' menu actions and emits
470 * the signal selectionChanged().
472 void slotSelectionChanged(const KFileItemList
&selection
);
475 * Updates the state of the 'Back' and 'Forward' menu
476 * actions corresponding to the current history.
478 void updateHistory();
480 /** Updates the state of the 'Show filter bar' menu action. */
481 void updateFilterBarAction(bool show
);
483 /** Open a new main window. */
484 void openNewMainWindow();
487 * Opens a new view with the current URL that is part of a tab and
490 void openNewActivatedTab();
493 * Adds the current URL as an entry to the Places panel
498 * Opens the selected folder in a new tab.
503 * Opens the selected folder in a new window.
505 void openInNewWindow();
508 * Opens the selected folder in the other inactive split view, enables split view if necessary.
510 void openInSplitView(const QUrl
&url
);
513 * Show the target of the selected symlink
518 * Indicates in the statusbar that the execution of the command \a command
521 void showCommand(CommandType command
);
524 * If the URL can be listed, open it in the current view, otherwise
525 * run it through KRun.
527 void handleUrl(const QUrl
&url
);
530 * Is invoked when the write state of a folder has been changed and
531 * enables/disables the "Create New..." menu entry.
533 void slotWriteStateChanged(bool isFolderWritable
);
536 * Opens the context menu on the current mouse position.
537 * @pos Position in screen coordinates.
538 * @item File item context. If item is null, the context menu
539 * should be applied to \a url.
540 * @selectedItems The selected items for which the context menu
541 * is opened. This list generally includes \a item.
542 * @url URL which contains \a item.
544 void openContextMenu(const QPoint
&pos
, const KFileItem
&item
, const KFileItemList
&selectedItems
, const QUrl
&url
);
547 * Updates the menu that is by default at the right end of the toolbar.
549 * In true "simple by default" fashion, the menu only contains the most important
550 * and necessary actions to be able to use Dolphin. This is supposed to hold true even
551 * if the user does not know how to open a context menu. More advanced actions can be
552 * discovered through a sub-menu (@see KConfigWidgets::KHamburgerMenu::setMenuBarAdvertised()).
554 void updateHamburgerMenu();
557 * Is called if the user clicked an item in the Places Panel.
558 * Reloads the view if \a url is the current URL already, and changes the
559 * current URL otherwise.
561 void slotPlaceActivated(const QUrl
&url
);
564 * Is called if the another view has been activated by changing the current
565 * tab or activating another view in split-view mode.
567 * Activates the given view, which means that all menu actions are applied
568 * to this view. When having a split view setup, the nonactive view is
569 * usually shown in darker colors.
571 void activeViewChanged(DolphinViewContainer
*viewContainer
);
573 void closedTabsCountChanged(unsigned int count
);
576 * Is called if a new tab has been opened or a tab has been closed to
577 * enable/disable the tab actions.
579 void tabCountChanged(int count
);
582 * Updates the Window Title with the caption from the active view container
584 void updateWindowTitle();
587 * This slot is called when the user requested to unmount a removable media
588 * from the places menu
590 void slotStorageTearDownFromPlacesRequested(const QString
&mountPath
);
593 * This slot is called when the user requested to unmount a removable media
594 * _not_ from the dolphin's places menu (from the notification area for e.g.)
595 * This slot is basically connected to each removable device's
596 * Solid::StorageAccess::teardownRequested(const QString & udi)
597 * signal through the places panel.
599 void slotStorageTearDownExternallyRequested(const QString
&mountPath
);
602 * Is called when the view has finished loading the directory.
604 void slotDirectoryLoadingCompleted();
607 * Is called when the user middle clicks a toolbar button.
609 * Here middle clicking Back/Forward/Up/Home will open the resulting
610 * folder in a new tab.
612 void slotToolBarActionMiddleClicked(QAction
*action
);
615 * Is called before the Back popup menu is shown. This slot will populate
616 * the menu with history data
618 void slotAboutToShowBackPopupMenu();
621 * This slot is used by the Back Popup Menu to go back to a specific
622 * history index. The QAction::data will carry an int with the index
625 void slotGoBack(QAction
*action
);
628 * Middle clicking Back/Forward will open the resulting folder in a new tab.
630 void slotBackForwardActionMiddleClicked(QAction
*action
);
633 * Is called before the Forward popup menu is shown. This slot will populate
634 * the menu with history data
636 void slotAboutToShowForwardPopupMenu();
639 * This slot is used by the Forward Popup Menu to go forward to a specific
640 * history index. The QAction::data will carry an int with the index
643 void slotGoForward(QAction
*action
);
646 * Is called when configuring the keyboard shortcuts
648 void slotKeyBindings();
653 void slotSaveSession();
657 * Sets up the various menus and actions and connects them.
662 * Sets up the dock widgets and their panels.
664 void setupDockWidgets();
666 void updateFileAndEditActions();
667 void updateViewActions();
668 void updateGoActions();
671 * Connects the signals from the created DolphinView with
672 * the DolphinViewContainer \a container with the corresponding slots of
673 * the DolphinMainWindow. This method must be invoked each
674 * time a DolphinView has been created.
676 void connectViewSignals(DolphinViewContainer
*container
);
679 * Updates the text of the split action:
680 * If two views are shown, the text is set to "Split",
681 * otherwise the text is set to "Join". The icon
682 * is updated to match with the text and the currently active view.
684 void updateSplitActions();
687 * Sets the window sides the toolbar may be moved to based on toolbar contents.
689 void updateAllowedToolbarAreas();
691 bool isKompareInstalled() const;
694 * Creates an action for showing/hiding a panel, that is accessible
695 * in "Configure toolbars..." and "Configure shortcuts...".
697 void createPanelAction(const QIcon
&icon
, const QKeySequence
&shortcut
, QDockWidget
*dockAction
, const QString
&actionName
);
699 /** Adds "What's This?" texts to many widgets and StandardActions. */
700 void setupWhatsThis();
702 /** Returns preferred search tool as configured in "More Search Tools" menu. */
703 QPointer
<QAction
> preferredSearchTool();
706 * Adds this action to the mainWindow's toolbar and saves the change
707 * in the users ui configuration file.
708 * This method is only needed for migration and should be removed once we can expect
709 * that pretty much all users have been migrated. Remove in 2026 because that's when
710 * even the most risk-averse distros will already have been forced to upgrade.
711 * @return true if successful. Otherwise false.
713 bool addHamburgerMenuToToolbar();
715 /** Creates an action representing an item in the URL navigator history */
716 static QAction
*urlNavigatorHistoryAction(const KUrlNavigator
*urlNavigator
, int historyIndex
, QObject
*parent
= nullptr);
720 * Implements a custom error handling for the undo manager. This
721 * assures that all errors are shown in the status bar of Dolphin
722 * instead as modal error dialog with an OK button.
724 class UndoUiInterface
: public KIO::FileUndoManager::UiInterface
728 ~UndoUiInterface() override
;
729 void jobError(KIO::Job
*job
) override
;
732 KNewFileMenu
*m_newFileMenu
;
733 DolphinTabWidget
*m_tabWidget
;
734 DolphinViewContainer
*m_activeViewContainer
;
736 DolphinViewActionHandler
*m_actionHandler
;
737 DolphinRemoteEncoding
*m_remoteEncoding
;
738 QPointer
<DolphinSettingsDialog
> m_settingsDialog
;
739 DolphinBookmarkHandler
*m_bookmarkHandler
;
740 SelectionMode::ActionTextHelper
*m_actionTextHelper
;
741 DisabledActionNotifier
*m_disabledActionNotifier
;
743 KIO::OpenUrlJob
*m_lastHandleUrlOpenJob
;
745 TerminalPanel
*m_terminalPanel
;
746 PlacesPanel
*m_placesPanel
;
747 bool m_tearDownFromPlacesRequested
;
749 KToolBarPopupAction
*m_backAction
;
750 KToolBarPopupAction
*m_forwardAction
;
751 KActionMenu
*m_splitViewAction
;
752 QAction
*m_splitViewMenuAction
;
755 KFileItemActions m_fileItemActions
;
757 QTimer
*m_sessionSaveTimer
;
758 QFutureWatcher
<void> *m_sessionSaveWatcher
;
759 bool m_sessionSaveScheduled
;
761 KIO::CommandLauncherJob
*m_job
;
763 KRecentFilesAction
*m_recentFiles
= nullptr;
765 friend class DolphinMainWindowTest
;
768 inline DolphinViewContainer
*DolphinMainWindow::activeViewContainer() const
770 return m_activeViewContainer
;
773 inline KNewFileMenu
*DolphinMainWindow::newFileMenu() const
775 return m_newFileMenu
;
778 #endif // DOLPHIN_MAINWINDOW_H