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 <KFileItemActions>
16 #include <kio/fileundomanager.h>
17 #include <kxmlguiwindow.h>
20 #include "panels/information/informationpanel.h"
23 #include <QFutureWatcher>
31 typedef KIO::FileUndoManager::CommandType CommandType
;
33 class DolphinBookmarkHandler
;
34 class DolphinViewActionHandler
;
35 class DolphinSettingsDialog
;
36 class DolphinViewContainer
;
37 class DolphinRemoteEncoding
;
38 class DolphinTabWidget
;
43 class KToolBarPopupAction
;
52 namespace SelectionMode
54 class ActionTextHelper
;
58 * @short Main window for Dolphin.
60 * Handles the menus, toolbars and Dolphin views.
62 class DolphinMainWindow
: public KXmlGuiWindow
65 Q_CLASSINFO("D-Bus Interface", "org.kde.dolphin.MainWindow")
69 ~DolphinMainWindow() override
;
72 * Returns the currently active view.
73 * All menu actions are applied to this view. When
74 * having a split view setup, the nonactive view
75 * is usually shown in darker colors.
77 DolphinViewContainer
*activeViewContainer() const;
80 * Returns view container for all tabs
82 QVector
<DolphinViewContainer
*> viewContainers() const;
85 * Opens each directory in \p dirs in a separate tab. If \a splitView is set,
86 * 2 directories are collected within one tab.
87 * \pre \a dirs must contain at least one url.
89 void openDirectories(const QList
<QUrl
> &dirs
, bool splitView
);
92 * Opens the directories which contain the files \p files and selects all files.
93 * If \a splitView is set, 2 directories are collected within one tab.
94 * \pre \a files must contain at least one url.
96 void openFiles(const QList
<QUrl
> &files
, bool splitView
);
99 * Returns the 'Create New...' sub menu which also can be shared
100 * with other menus (e. g. a context menu).
102 KNewFileMenu
*newFileMenu() const;
105 * Augments Qt's build-in QMainWindow context menu to add
106 * Dolphin-specific actions, such as "unlock panels".
108 QMenu
*createPopupMenu() override
;
111 * Switch the window's view containers' locations to display the home path
112 * for any which are currently displaying a location corresponding to or
115 * This typically done after unmounting a disk at mountPath to ensure that
116 * the window is not displaying an invalid location.
118 void setViewsToHomeIfMountPathOpen(const QString
&mountPath
);
121 * Enables or disables the session autosaving feature.
123 * @param enable If true, saves the session automatically after a fixed
124 * time interval from the last state change.
126 void setSessionAutoSaveEnabled(bool enable
);
128 bool isFoldersPanelEnabled() const;
129 bool isInformationPanelEnabled() const;
130 bool isSplitViewEnabledInCurrentTab() const;
134 * Opens each directory in \p dirs in a separate tab. If \a splitView is set,
135 * 2 directories are collected within one tab.
136 * \pre \a dirs must contain at least one url.
138 * @note this function is overloaded so that it is callable via DBus.
140 void openDirectories(const QStringList
&dirs
, bool splitView
);
143 * Opens the directories which contain the files \p files and selects all files.
144 * If \a splitView is set, 2 directories are collected within one tab.
145 * \pre \a files must contain at least one url.
147 * @note this is overloaded so that this function is callable via DBus.
149 void openFiles(const QStringList
&files
, bool splitView
);
152 * Tries to raise/activate the Dolphin window.
154 void activateWindow(const QString
&activationToken
);
156 bool isActiveWindow();
159 * Determines if a URL is open in any tab.
160 * @note Use of QString instead of QUrl is required to be callable via DBus.
162 * @param url URL to look for
163 * @returns true if url is currently open in a tab, false otherwise.
165 bool isUrlOpen(const QString
&url
);
168 * @return Whether the item with @p url can be found in any view only by switching
169 * between already open tabs and scrolling in their primary or secondary view.
170 * @note Use of QString instead of QUrl is required to be callable via DBus.
172 bool isItemVisibleInAnyView(const QString
&urlOfItem
);
175 * Pastes the clipboard data into the currently selected folder
176 * of the active view. If not exactly one folder is selected,
177 * no pasting is done at all.
179 void pasteIntoFolder();
182 * Implementation of the MainWindowAdaptor/QDBusAbstractAdaptor interface.
183 * Inform all affected dolphin components (panels, views) of an URL
186 void changeUrl(const QUrl
&url
);
189 * The current directory of the Terminal Panel has changed, probably because
190 * the user entered a 'cd' command. This slot calls changeUrl(url) and makes
191 * sure that the panel keeps the keyboard focus.
193 void slotTerminalDirectoryChanged(const QUrl
&url
);
195 /** Stores all settings and quits Dolphin. */
199 * Opens a new tab in the background showing the URL \a url.
201 void openNewTab(const QUrl
&url
);
204 * Opens a new tab showing the URL \a url and activate it.
206 void openNewTabAndActivate(const QUrl
&url
);
209 * Opens a new window showing the URL \a url.
211 void openNewWindow(const QUrl
&url
);
213 /** @see GeneralSettings::splitViewChanged() */
214 void slotSplitViewChanged();
218 * Is sent if the selection of the currently active view has
221 void selectionChanged(const KFileItemList
&selection
);
224 * Is sent if the url of the currently active view has
227 void urlChanged(const QUrl
&url
);
230 * Is emitted if information of an item is requested to be shown e. g. in the panel.
231 * If item is null, no item information request is pending.
233 void requestItemInfo(const KFileItem
&item
);
236 * It is emitted when in the current view, files are changed,
237 * or dirs have files/removed from them.
239 void fileItemsChanged(const KFileItemList
&changedFileItems
);
242 * Is emitted if the settings have been changed.
244 void settingsChanged();
247 /** @see QObject::event() */
248 bool event(QEvent
*event
) override
;
250 /** @see QWidget::showEvent() */
251 void showEvent(QShowEvent
*event
) override
;
253 /** @see QMainWindow::closeEvent() */
254 void closeEvent(QCloseEvent
*event
) override
;
256 /** @see KMainWindow::saveProperties() */
257 void saveProperties(KConfigGroup
&group
) override
;
259 /** @see KMainWindow::readProperties() */
260 void readProperties(const KConfigGroup
&group
) override
;
262 /** Sets a sane initial window size **/
263 QSize
sizeHint() const override
;
267 * Calls the base method KXmlGuiWindow::saveNewToolbarConfig().
268 * Is also used to set toolbar constraints and UrlNavigator position
269 * based on the newly changed toolbar configuration.
271 void saveNewToolbarConfig() override
;
275 * Refreshes the views of the main window by recreating them according to
276 * the given Dolphin settings.
280 void clearStatusBar();
282 /** Updates the 'Create New...' sub menu. */
283 void updateNewMenu();
285 void createDirectory();
287 /** Shows the error message in the status bar of the active view. */
288 void showErrorMessage(const QString
&message
);
291 * Updates the state of the 'Undo' menu action dependent
292 * on the parameter \a available.
294 void slotUndoAvailable(bool available
);
296 /** Sets the text of the 'Undo' menu action to \a text. */
297 void slotUndoTextChanged(const QString
&text
);
299 /** Performs the current undo operation. */
303 * Copies all selected items to the clipboard and marks
308 /** Copies all selected items to the clipboard. */
311 /** Pastes the clipboard data to the active view. */
314 /** Replaces the URL navigator by a search box to find files. */
317 /** Updates the state of the search action according to the view container. */
318 void updateSearchAction();
321 * Updates the text of the paste action dependent on
322 * the number of items which are in the clipboard.
324 void updatePasteAction();
326 /** Calls DolphinViewContainer::setSelectionMode() for m_activeViewContainer. */
327 void slotSetSelectionMode(bool enabled
, SelectionMode::BottomBar::Contents bottomBarContents
);
329 /** Selects all items from the active view. */
333 * Inverts the selection of all items of the active view:
334 * Selected items get nonselected and nonselected items get
337 void invertSelection();
340 * Switches between one and two views:
341 * If one view is visible, it will get split into two views.
342 * If already two views are visible, the active view gets closed.
344 void toggleSplitView();
346 /** Dedicated action to open the stash:/ ioslave in split view. */
347 void toggleSplitStash();
349 /** Copies all selected items to the inactive view. */
350 void copyToInactiveSplitView();
352 /** Moves all selected items to the inactive view. */
353 void moveToInactiveSplitView();
355 /** Reloads the currently active view. */
358 /** Stops the loading process for the currently active view. */
361 void enableStopAction();
362 void disableStopAction();
364 void toggleSelectionMode();
366 void showFilterBar();
367 void toggleFilterBar();
370 * Toggles between edit and browse mode of the navigation bar.
372 void toggleEditLocation();
375 * Switches to the edit mode of the navigation bar and selects
376 * the whole URL, so that it can be replaced by the user. If the edit mode is
377 * already active, it is assured that the navigation bar get focused.
379 void replaceLocation();
382 * Toggles the state of the panels between a locked and unlocked layout.
384 void togglePanelLockState();
387 * Is invoked if the Terminal panel got visible/invisible and takes care
388 * that the active view has the focus if the Terminal panel is invisible.
390 void slotTerminalPanelVisibilityChanged();
392 /** Goes back one step of the URL history. */
395 /** Goes forward one step of the URL history. */
398 /** Goes up one hierarchy of the current URL. */
401 /** Changes the location to the home URL. */
404 /** Open the previous URL in the URL history in a new tab. */
405 void goBackInNewTab();
407 /** Open the next URL in the URL history in a new tab. */
408 void goForwardInNewTab();
410 /** Open the URL one hierarchy above the current URL in a new tab. */
413 /** * Open the home URL in a new tab. */
414 void goHomeInNewTab();
416 /** Opens Kompare for 2 selected files. */
420 * Hides the menu bar if it is visible, makes the menu bar
421 * visible if it is hidden.
423 void toggleShowMenuBar();
425 /** Updates "Open Preferred Search Tool" action. */
426 void updateOpenPreferredSearchToolAction();
428 /** Opens preferred search tool for the current location. */
429 void openPreferredSearchTool();
431 /** Opens a terminal window for the current location. */
434 /** Opens terminal windows for the selected items' locations. */
435 void openTerminalHere();
437 /** Opens a terminal window for the URL. */
438 void openTerminalJob(const QUrl
&url
);
440 /** Focus a Terminal Panel. */
441 void focusTerminalPanel();
443 /** Opens the settings dialog for Dolphin. */
446 /** Updates the state of the 'Show Full Location' action. */
447 void slotEditableStateChanged(bool editable
);
450 * Updates the state of the 'Edit' menu actions and emits
451 * the signal selectionChanged().
453 void slotSelectionChanged(const KFileItemList
&selection
);
456 * Updates the state of the 'Back' and 'Forward' menu
457 * actions corresponding to the current history.
459 void updateHistory();
461 /** Updates the state of the 'Show filter bar' menu action. */
462 void updateFilterBarAction(bool show
);
464 /** Open a new main window. */
465 void openNewMainWindow();
468 * Opens a new view with the current URL that is part of a tab and
471 void openNewActivatedTab();
474 * Adds the current URL as an entry to the Places panel
479 * Opens the selected folder in a new tab.
484 * Opens the selected folder in a new window.
486 void openInNewWindow();
489 * Opens the selected folder in the other inactive split view, enables split view if necessary.
491 void openInSplitView(const QUrl
&url
);
494 * Show the target of the selected symlink
499 * Indicates in the statusbar that the execution of the command \a command
502 void showCommand(CommandType command
);
505 * If the URL can be listed, open it in the current view, otherwise
506 * run it through KRun.
508 void handleUrl(const QUrl
&url
);
511 * Is invoked when the write state of a folder has been changed and
512 * enables/disables the "Create New..." menu entry.
514 void slotWriteStateChanged(bool isFolderWritable
);
517 * Opens the context menu on the current mouse position.
518 * @pos Position in screen coordinates.
519 * @item File item context. If item is null, the context menu
520 * should be applied to \a url.
521 * @selectedItems The selected items for which the context menu
522 * is opened. This list generally includes \a item.
523 * @url URL which contains \a item.
525 void openContextMenu(const QPoint
&pos
, const KFileItem
&item
, const KFileItemList
&selectedItems
, const QUrl
&url
);
528 * Updates the menu that is by default at the right end of the toolbar.
530 * In true "simple by default" fashion, the menu only contains the most important
531 * and necessary actions to be able to use Dolphin. This is supposed to hold true even
532 * if the user does not know how to open a context menu. More advanced actions can be
533 * discovered through a sub-menu (@see KConfigWidgets::KHamburgerMenu::setMenuBarAdvertised()).
535 void updateHamburgerMenu();
538 * Is called if the user clicked an item in the Places Panel.
539 * Reloads the view if \a url is the current URL already, and changes the
540 * current URL otherwise.
542 void slotPlaceActivated(const QUrl
&url
);
545 * Is called if the another view has been activated by changing the current
546 * tab or activating another view in split-view mode.
548 * Activates the given view, which means that all menu actions are applied
549 * to this view. When having a split view setup, the nonactive view is
550 * usually shown in darker colors.
552 void activeViewChanged(DolphinViewContainer
*viewContainer
);
554 void closedTabsCountChanged(unsigned int count
);
557 * Is called if a new tab has been opened or a tab has been closed to
558 * enable/disable the tab actions.
560 void tabCountChanged(int count
);
563 * Updates the Window Title with the caption from the active view container
565 void updateWindowTitle();
568 * This slot is called when the user requested to unmount a removable media
569 * from the places menu
571 void slotStorageTearDownFromPlacesRequested(const QString
&mountPath
);
574 * This slot is called when the user requested to unmount a removable media
575 * _not_ from the dolphin's places menu (from the notification area for e.g.)
576 * This slot is basically connected to each removable device's
577 * Solid::StorageAccess::teardownRequested(const QString & udi)
578 * signal through the places panel.
580 void slotStorageTearDownExternallyRequested(const QString
&mountPath
);
583 * Is called when the view has finished loading the directory.
585 void slotDirectoryLoadingCompleted();
588 * Is called when the user middle clicks a toolbar button.
590 * Here middle clicking Back/Forward/Up/Home will open the resulting
591 * folder in a new tab.
593 void slotToolBarActionMiddleClicked(QAction
*action
);
596 * Is called before the Back popup menu is shown. This slot will populate
597 * the menu with history data
599 void slotAboutToShowBackPopupMenu();
602 * This slot is used by the Back Popup Menu to go back to a specific
603 * history index. The QAction::data will carry an int with the index
606 void slotGoBack(QAction
*action
);
609 * Middle clicking Back/Forward will open the resulting folder in a new tab.
611 void slotBackForwardActionMiddleClicked(QAction
*action
);
614 * Is called before the Forward popup menu is shown. This slot will populate
615 * the menu with history data
617 void slotAboutToShowForwardPopupMenu();
620 * This slot is used by the Forward Popup Menu to go forward to a specific
621 * history index. The QAction::data will carry an int with the index
624 void slotGoForward(QAction
*action
);
627 * Is called when configuring the keyboard shortcuts
629 void slotKeyBindings();
634 void slotSaveSession();
638 * Sets up the various menus and actions and connects them.
643 * Sets up the dock widgets and their panels.
645 void setupDockWidgets();
647 void updateFileAndEditActions();
648 void updateViewActions();
649 void updateGoActions();
652 * Connects the signals from the created DolphinView with
653 * the DolphinViewContainer \a container with the corresponding slots of
654 * the DolphinMainWindow. This method must be invoked each
655 * time a DolphinView has been created.
657 void connectViewSignals(DolphinViewContainer
*container
);
660 * Updates the text of the split action:
661 * If two views are shown, the text is set to "Split",
662 * otherwise the text is set to "Join". The icon
663 * is updated to match with the text and the currently active view.
665 void updateSplitAction();
668 * Sets the window sides the toolbar may be moved to based on toolbar contents.
670 void updateAllowedToolbarAreas();
672 bool isKompareInstalled() const;
675 * Creates an action for showing/hiding a panel, that is accessible
676 * in "Configure toolbars..." and "Configure shortcuts...".
678 void createPanelAction(const QIcon
&icon
, const QKeySequence
&shortcut
, QDockWidget
*dockAction
, const QString
&actionName
);
680 /** Adds "What's This?" texts to many widgets and StandardActions. */
681 void setupWhatsThis();
683 /** Returns preferred search tool as configured in "More Search Tools" menu. */
684 QPointer
<QAction
> preferredSearchTool();
687 * Adds this action to the mainWindow's toolbar and saves the change
688 * in the users ui configuration file.
689 * This method is only needed for migration and should be removed once we can expect
690 * that pretty much all users have been migrated. Remove in 2026 because that's when
691 * even the most risk-averse distros will already have been forced to upgrade.
692 * @return true if successful. Otherwise false.
694 bool addHamburgerMenuToToolbar();
696 /** Creates an action representing an item in the URL navigator history */
697 static QAction
*urlNavigatorHistoryAction(const KUrlNavigator
*urlNavigator
, int historyIndex
, QObject
*parent
= nullptr);
701 * Implements a custom error handling for the undo manager. This
702 * assures that all errors are shown in the status bar of Dolphin
703 * instead as modal error dialog with an OK button.
705 class UndoUiInterface
: public KIO::FileUndoManager::UiInterface
709 ~UndoUiInterface() override
;
710 void jobError(KIO::Job
*job
) override
;
713 KNewFileMenu
*m_newFileMenu
;
714 DolphinTabWidget
*m_tabWidget
;
715 DolphinViewContainer
*m_activeViewContainer
;
717 DolphinViewActionHandler
*m_actionHandler
;
718 DolphinRemoteEncoding
*m_remoteEncoding
;
719 QPointer
<DolphinSettingsDialog
> m_settingsDialog
;
720 DolphinBookmarkHandler
*m_bookmarkHandler
;
721 SelectionMode::ActionTextHelper
*m_actionTextHelper
;
723 KIO::OpenUrlJob
*m_lastHandleUrlOpenJob
;
725 TerminalPanel
*m_terminalPanel
;
726 PlacesPanel
*m_placesPanel
;
727 bool m_tearDownFromPlacesRequested
;
729 KToolBarPopupAction
*m_backAction
;
730 KToolBarPopupAction
*m_forwardAction
;
733 KFileItemActions m_fileItemActions
;
735 QTimer
*m_sessionSaveTimer
;
736 QFutureWatcher
<void> *m_sessionSaveWatcher
;
737 bool m_sessionSaveScheduled
;
739 friend class DolphinMainWindowTest
;
742 inline DolphinViewContainer
*DolphinMainWindow::activeViewContainer() const
744 return m_activeViewContainer
;
747 inline KNewFileMenu
*DolphinMainWindow::newFileMenu() const
749 return m_newFileMenu
;
752 #endif // DOLPHIN_MAINWINDOW_H