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 "dolphintabwidget.h"
14 #include "selectionmode/bottombar.h"
15 #include <KActionMenu>
16 #include <KFileItemActions>
17 #include <kio/fileundomanager.h>
18 #include <kxmlguiwindow.h>
21 #include "panels/information/informationpanel.h"
24 #include <QFutureWatcher>
32 typedef KIO::FileUndoManager::CommandType CommandType
;
34 class DolphinBookmarkHandler
;
35 class DolphinViewActionHandler
;
36 class DolphinSettingsDialog
;
37 class DolphinViewContainer
;
38 class DolphinRemoteEncoding
;
39 class DolphinTabWidget
;
44 class KToolBarPopupAction
;
53 namespace SelectionMode
55 class ActionTextHelper
;
59 * @short Main window for Dolphin.
61 * Handles the menus, toolbars and Dolphin views.
63 class DolphinMainWindow
: public KXmlGuiWindow
66 Q_CLASSINFO("D-Bus Interface", "org.kde.dolphin.MainWindow")
70 ~DolphinMainWindow() override
;
73 * Returns the currently active view.
74 * All menu actions are applied to this view. When
75 * having a split view setup, the nonactive view
76 * is usually shown in darker colors.
78 DolphinViewContainer
*activeViewContainer() const;
81 * Returns view container for all tabs
83 QVector
<DolphinViewContainer
*> viewContainers() const;
86 * Opens each directory in \p dirs in a separate tab. If \a splitView is set,
87 * 2 directories are collected within one tab.
88 * \pre \a dirs must contain at least one url.
90 void openDirectories(const QList
<QUrl
> &dirs
, bool splitView
);
93 * Opens the directories which contain the files \p files and selects all files.
94 * If \a splitView is set, 2 directories are collected within one tab.
95 * \pre \a files must contain at least one url.
97 void openFiles(const QList
<QUrl
> &files
, bool splitView
);
100 * Returns the 'Create New...' sub menu which also can be shared
101 * with other menus (e. g. a context menu).
103 KNewFileMenu
*newFileMenu() const;
106 * Augments Qt's build-in QMainWindow context menu to add
107 * Dolphin-specific actions, such as "unlock panels".
109 QMenu
*createPopupMenu() override
;
112 * Switch the window's view containers' locations to display the home path
113 * for any which are currently displaying a location corresponding to or
116 * This typically done after unmounting a disk at mountPath to ensure that
117 * the window is not displaying an invalid location.
119 void setViewsToHomeIfMountPathOpen(const QString
&mountPath
);
122 * Enables or disables the session autosaving feature.
124 * @param enable If true, saves the session automatically after a fixed
125 * time interval from the last state change.
127 void setSessionAutoSaveEnabled(bool enable
);
129 bool isFoldersPanelEnabled() const;
130 bool isInformationPanelEnabled() const;
131 bool isSplitViewEnabledInCurrentTab() const;
135 * Opens each directory in \p dirs in a separate tab. If \a splitView is set,
136 * 2 directories are collected within one tab.
137 * \pre \a dirs must contain at least one url.
139 * @note this function is overloaded so that it is callable via DBus.
141 void openDirectories(const QStringList
&dirs
, bool splitView
);
144 * Opens the directories which contain the files \p files and selects all files.
145 * If \a splitView is set, 2 directories are collected within one tab.
146 * \pre \a files must contain at least one url.
148 * @note this is overloaded so that this function is callable via DBus.
150 void openFiles(const QStringList
&files
, bool splitView
);
153 * Tries to raise/activate the Dolphin window.
155 void activateWindow(const QString
&activationToken
);
157 bool isActiveWindow();
160 * Determines if a URL is open in any tab.
161 * @note Use of QString instead of QUrl is required to be callable via DBus.
163 * @param url URL to look for
164 * @returns true if url is currently open in a tab, false otherwise.
166 bool isUrlOpen(const QString
&url
);
169 * @return Whether the item with @p url can be found in any view only by switching
170 * between already open tabs and scrolling in their primary or secondary view.
171 * @note Use of QString instead of QUrl is required to be callable via DBus.
173 bool isItemVisibleInAnyView(const QString
&urlOfItem
);
176 * Pastes the clipboard data into the currently selected folder
177 * of the active view. If not exactly one folder is selected,
178 * no pasting is done at all.
180 void pasteIntoFolder();
183 * Implementation of the MainWindowAdaptor/QDBusAbstractAdaptor interface.
184 * Inform all affected dolphin components (panels, views) of an URL
187 void changeUrl(const QUrl
&url
);
190 * The current directory of the Terminal Panel has changed, probably because
191 * the user entered a 'cd' command. This slot calls changeUrl(url) and makes
192 * sure that the panel keeps the keyboard focus.
194 void slotTerminalDirectoryChanged(const QUrl
&url
);
196 /** Stores all settings and quits Dolphin. */
200 * Opens a new tab in the background showing the URL \a url.
202 void openNewTab(const QUrl
&url
);
205 * Opens a new tab showing the URL \a url and activate it.
207 void openNewTabAndActivate(const QUrl
&url
);
210 * Opens a new window showing the URL \a url.
212 void openNewWindow(const QUrl
&url
);
214 /** @see GeneralSettings::splitViewChanged() */
215 void slotSplitViewChanged();
219 * Is sent if the selection of the currently active view has
222 void selectionChanged(const KFileItemList
&selection
);
225 * Is sent if the url of the currently active view has
228 void urlChanged(const QUrl
&url
);
231 * Is emitted if information of an item is requested to be shown e. g. in the panel.
232 * If item is null, no item information request is pending.
234 void requestItemInfo(const KFileItem
&item
);
237 * It is emitted when in the current view, files are changed,
238 * or dirs have files/removed from them.
240 void fileItemsChanged(const KFileItemList
&changedFileItems
);
243 * Is emitted if the settings have been changed.
245 void settingsChanged();
248 /** @see QObject::event() */
249 bool event(QEvent
*event
) override
;
251 /** @see QWidget::showEvent() */
252 void showEvent(QShowEvent
*event
) override
;
254 /** @see QMainWindow::closeEvent() */
255 void closeEvent(QCloseEvent
*event
) override
;
257 /** @see KMainWindow::saveProperties() */
258 void saveProperties(KConfigGroup
&group
) override
;
260 /** @see KMainWindow::readProperties() */
261 void readProperties(const KConfigGroup
&group
) override
;
263 /** Sets a sane initial window size **/
264 QSize
sizeHint() const override
;
268 * Calls the base method KXmlGuiWindow::saveNewToolbarConfig().
269 * Is also used to set toolbar constraints and UrlNavigator position
270 * based on the newly changed toolbar configuration.
272 void saveNewToolbarConfig() override
;
276 * Refreshes the views of the main window by recreating them according to
277 * the given Dolphin settings.
281 void clearStatusBar();
283 /** Updates the 'Create New...' sub menu. */
284 void updateNewMenu();
286 void createDirectory();
288 /** Shows the error message in the status bar of the active view. */
289 void showErrorMessage(const QString
&message
);
292 * Updates the state of the 'Undo' menu action dependent
293 * on the parameter \a available.
295 void slotUndoAvailable(bool available
);
297 /** Sets the text of the 'Undo' menu action to \a text. */
298 void slotUndoTextChanged(const QString
&text
);
300 /** Performs the current undo operation. */
304 * Copies all selected items to the clipboard and marks
309 /** Copies all selected items to the clipboard. */
312 /** Pastes the clipboard data to the active view. */
315 /** Replaces the URL navigator by a search box to find files. */
318 /** Updates the state of the search action according to the view container. */
319 void updateSearchAction();
322 * Updates the text of the paste action dependent on
323 * the number of items which are in the clipboard.
325 void updatePasteAction();
327 /** Calls DolphinViewContainer::setSelectionMode() for m_activeViewContainer. */
328 void slotSetSelectionMode(bool enabled
, SelectionMode::BottomBar::Contents bottomBarContents
);
330 /** Selects all items from the active view. */
334 * Inverts the selection of all items of the active view:
335 * Selected items get nonselected and nonselected items get
338 void invertSelection();
341 * Switches between one and two views:
342 * If one view is visible, it will get split into two views.
343 * If already two views are visible, the active view gets closed.
345 void toggleSplitView();
348 * Pops out a split view.
349 * The active view will be popped out, unless the view is not split,
350 * in which case nothing will happen.
352 void popoutSplitView();
354 /** Dedicated action to open the stash:/ ioslave in split view. */
355 void toggleSplitStash();
357 /** Copies all selected items to the inactive view. */
358 void copyToInactiveSplitView();
360 /** Moves all selected items to the inactive view. */
361 void moveToInactiveSplitView();
363 /** Reloads the currently active view. */
366 /** Stops the loading process for the currently active view. */
369 void enableStopAction();
370 void disableStopAction();
372 void toggleSelectionMode();
374 void showFilterBar();
375 void toggleFilterBar();
378 * Toggles between edit and browse mode of the navigation bar.
380 void toggleEditLocation();
383 * Switches to the edit mode of the navigation bar and selects
384 * the whole URL, so that it can be replaced by the user. If the edit mode is
385 * already active, it is assured that the navigation bar get focused.
387 void replaceLocation();
390 * Toggles the state of the panels between a locked and unlocked layout.
392 void togglePanelLockState();
395 * Is invoked if the Terminal panel got visible/invisible and takes care
396 * that the active view has the focus if the Terminal panel is invisible.
398 void slotTerminalPanelVisibilityChanged();
400 /** Goes back one step of the URL history. */
403 /** Goes forward one step of the URL history. */
406 /** Goes up one hierarchy of the current URL. */
409 /** Changes the location to the home URL. */
412 /** Open the previous URL in the URL history in a new tab. */
413 void goBackInNewTab();
415 /** Open the next URL in the URL history in a new tab. */
416 void goForwardInNewTab();
418 /** Open the URL one hierarchy above the current URL in a new tab. */
421 /** * Open the home URL in a new tab. */
422 void goHomeInNewTab();
424 /** Opens Kompare for 2 selected files. */
428 * Hides the menu bar if it is visible, makes the menu bar
429 * visible if it is hidden.
431 void toggleShowMenuBar();
433 /** Updates "Open Preferred Search Tool" action. */
434 void updateOpenPreferredSearchToolAction();
436 /** Opens preferred search tool for the current location. */
437 void openPreferredSearchTool();
439 /** Opens a terminal window for the current location. */
442 /** Opens terminal windows for the selected items' locations. */
443 void openTerminalHere();
445 /** Opens a terminal window for the URL. */
446 void openTerminalJob(const QUrl
&url
);
448 /** Focus a Terminal Panel. */
449 void focusTerminalPanel();
451 /** Opens the settings dialog for Dolphin. */
454 /** Updates the state of the 'Show Full Location' action. */
455 void slotEditableStateChanged(bool editable
);
458 * Updates the state of the 'Edit' menu actions and emits
459 * the signal selectionChanged().
461 void slotSelectionChanged(const KFileItemList
&selection
);
464 * Updates the state of the 'Back' and 'Forward' menu
465 * actions corresponding to the current history.
467 void updateHistory();
469 /** Updates the state of the 'Show filter bar' menu action. */
470 void updateFilterBarAction(bool show
);
472 /** Open a new main window. */
473 void openNewMainWindow();
476 * Opens a new view with the current URL that is part of a tab and
479 void openNewActivatedTab();
482 * Adds the current URL as an entry to the Places panel
487 * Opens the selected folder in a new tab.
492 * Opens the selected folder in a new window.
494 void openInNewWindow();
497 * Opens the selected folder in the other inactive split view, enables split view if necessary.
499 void openInSplitView(const QUrl
&url
);
502 * Show the target of the selected symlink
507 * Indicates in the statusbar that the execution of the command \a command
510 void showCommand(CommandType command
);
513 * If the URL can be listed, open it in the current view, otherwise
514 * run it through KRun.
516 void handleUrl(const QUrl
&url
);
519 * Is invoked when the write state of a folder has been changed and
520 * enables/disables the "Create New..." menu entry.
522 void slotWriteStateChanged(bool isFolderWritable
);
525 * Opens the context menu on the current mouse position.
526 * @pos Position in screen coordinates.
527 * @item File item context. If item is null, the context menu
528 * should be applied to \a url.
529 * @selectedItems The selected items for which the context menu
530 * is opened. This list generally includes \a item.
531 * @url URL which contains \a item.
533 void openContextMenu(const QPoint
&pos
, const KFileItem
&item
, const KFileItemList
&selectedItems
, const QUrl
&url
);
536 * Updates the menu that is by default at the right end of the toolbar.
538 * In true "simple by default" fashion, the menu only contains the most important
539 * and necessary actions to be able to use Dolphin. This is supposed to hold true even
540 * if the user does not know how to open a context menu. More advanced actions can be
541 * discovered through a sub-menu (@see KConfigWidgets::KHamburgerMenu::setMenuBarAdvertised()).
543 void updateHamburgerMenu();
546 * Is called if the user clicked an item in the Places Panel.
547 * Reloads the view if \a url is the current URL already, and changes the
548 * current URL otherwise.
550 void slotPlaceActivated(const QUrl
&url
);
553 * Is called if the another view has been activated by changing the current
554 * tab or activating another view in split-view mode.
556 * Activates the given view, which means that all menu actions are applied
557 * to this view. When having a split view setup, the nonactive view is
558 * usually shown in darker colors.
560 void activeViewChanged(DolphinViewContainer
*viewContainer
);
562 void closedTabsCountChanged(unsigned int count
);
565 * Is called if a new tab has been opened or a tab has been closed to
566 * enable/disable the tab actions.
568 void tabCountChanged(int count
);
571 * Updates the Window Title with the caption from the active view container
573 void updateWindowTitle();
576 * This slot is called when the user requested to unmount a removable media
577 * from the places menu
579 void slotStorageTearDownFromPlacesRequested(const QString
&mountPath
);
582 * This slot is called when the user requested to unmount a removable media
583 * _not_ from the dolphin's places menu (from the notification area for e.g.)
584 * This slot is basically connected to each removable device's
585 * Solid::StorageAccess::teardownRequested(const QString & udi)
586 * signal through the places panel.
588 void slotStorageTearDownExternallyRequested(const QString
&mountPath
);
591 * Is called when the view has finished loading the directory.
593 void slotDirectoryLoadingCompleted();
596 * Is called when the user middle clicks a toolbar button.
598 * Here middle clicking Back/Forward/Up/Home will open the resulting
599 * folder in a new tab.
601 void slotToolBarActionMiddleClicked(QAction
*action
);
604 * Is called before the Back popup menu is shown. This slot will populate
605 * the menu with history data
607 void slotAboutToShowBackPopupMenu();
610 * This slot is used by the Back Popup Menu to go back to a specific
611 * history index. The QAction::data will carry an int with the index
614 void slotGoBack(QAction
*action
);
617 * Middle clicking Back/Forward will open the resulting folder in a new tab.
619 void slotBackForwardActionMiddleClicked(QAction
*action
);
622 * Is called before the Forward popup menu is shown. This slot will populate
623 * the menu with history data
625 void slotAboutToShowForwardPopupMenu();
628 * This slot is used by the Forward Popup Menu to go forward to a specific
629 * history index. The QAction::data will carry an int with the index
632 void slotGoForward(QAction
*action
);
635 * Is called when configuring the keyboard shortcuts
637 void slotKeyBindings();
642 void slotSaveSession();
646 * Sets up the various menus and actions and connects them.
651 * Sets up the dock widgets and their panels.
653 void setupDockWidgets();
655 void updateFileAndEditActions();
656 void updateViewActions();
657 void updateGoActions();
660 * Connects the signals from the created DolphinView with
661 * the DolphinViewContainer \a container with the corresponding slots of
662 * the DolphinMainWindow. This method must be invoked each
663 * time a DolphinView has been created.
665 void connectViewSignals(DolphinViewContainer
*container
);
668 * Updates the text of the split action:
669 * If two views are shown, the text is set to "Split",
670 * otherwise the text is set to "Join". The icon
671 * is updated to match with the text and the currently active view.
673 void updateSplitActions();
676 * Sets the window sides the toolbar may be moved to based on toolbar contents.
678 void updateAllowedToolbarAreas();
680 bool isKompareInstalled() const;
683 * Creates an action for showing/hiding a panel, that is accessible
684 * in "Configure toolbars..." and "Configure shortcuts...".
686 void createPanelAction(const QIcon
&icon
, const QKeySequence
&shortcut
, QDockWidget
*dockAction
, const QString
&actionName
);
688 /** Adds "What's This?" texts to many widgets and StandardActions. */
689 void setupWhatsThis();
691 /** Returns preferred search tool as configured in "More Search Tools" menu. */
692 QPointer
<QAction
> preferredSearchTool();
695 * Adds this action to the mainWindow's toolbar and saves the change
696 * in the users ui configuration file.
697 * This method is only needed for migration and should be removed once we can expect
698 * that pretty much all users have been migrated. Remove in 2026 because that's when
699 * even the most risk-averse distros will already have been forced to upgrade.
700 * @return true if successful. Otherwise false.
702 bool addHamburgerMenuToToolbar();
704 /** Creates an action representing an item in the URL navigator history */
705 static QAction
*urlNavigatorHistoryAction(const KUrlNavigator
*urlNavigator
, int historyIndex
, QObject
*parent
= nullptr);
709 * Implements a custom error handling for the undo manager. This
710 * assures that all errors are shown in the status bar of Dolphin
711 * instead as modal error dialog with an OK button.
713 class UndoUiInterface
: public KIO::FileUndoManager::UiInterface
717 ~UndoUiInterface() override
;
718 void jobError(KIO::Job
*job
) override
;
721 KNewFileMenu
*m_newFileMenu
;
722 DolphinTabWidget
*m_tabWidget
;
723 DolphinViewContainer
*m_activeViewContainer
;
725 DolphinViewActionHandler
*m_actionHandler
;
726 DolphinRemoteEncoding
*m_remoteEncoding
;
727 QPointer
<DolphinSettingsDialog
> m_settingsDialog
;
728 DolphinBookmarkHandler
*m_bookmarkHandler
;
729 SelectionMode::ActionTextHelper
*m_actionTextHelper
;
731 KIO::OpenUrlJob
*m_lastHandleUrlOpenJob
;
733 TerminalPanel
*m_terminalPanel
;
734 PlacesPanel
*m_placesPanel
;
735 bool m_tearDownFromPlacesRequested
;
737 KToolBarPopupAction
*m_backAction
;
738 KToolBarPopupAction
*m_forwardAction
;
739 KActionMenu
*m_splitViewAction
;
742 KFileItemActions m_fileItemActions
;
744 QTimer
*m_sessionSaveTimer
;
745 QFutureWatcher
<void> *m_sessionSaveWatcher
;
746 bool m_sessionSaveScheduled
;
748 friend class DolphinMainWindowTest
;
751 inline DolphinViewContainer
*DolphinMainWindow::activeViewContainer() const
753 return m_activeViewContainer
;
756 inline KNewFileMenu
*DolphinMainWindow::newFileMenu() const
758 return m_newFileMenu
;
761 #endif // DOLPHIN_MAINWINDOW_H