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();
347 * Pops out a split view.
348 * The active view will be popped out, unless the view is not split,
349 * in which case nothing will happen.
351 void popoutSplitView();
353 /** Dedicated action to open the stash:/ ioslave in split view. */
354 void toggleSplitStash();
356 /** Copies all selected items to the inactive view. */
357 void copyToInactiveSplitView();
359 /** Moves all selected items to the inactive view. */
360 void moveToInactiveSplitView();
362 /** Reloads the currently active view. */
365 /** Stops the loading process for the currently active view. */
368 void enableStopAction();
369 void disableStopAction();
371 void toggleSelectionMode();
373 void showFilterBar();
374 void toggleFilterBar();
377 * Toggles between edit and browse mode of the navigation bar.
379 void toggleEditLocation();
382 * Switches to the edit mode of the navigation bar and selects
383 * the whole URL, so that it can be replaced by the user. If the edit mode is
384 * already active, it is assured that the navigation bar get focused.
386 void replaceLocation();
389 * Toggles the state of the panels between a locked and unlocked layout.
391 void togglePanelLockState();
394 * Is invoked if the Terminal panel got visible/invisible and takes care
395 * that the active view has the focus if the Terminal panel is invisible.
397 void slotTerminalPanelVisibilityChanged();
399 /** Goes back one step of the URL history. */
402 /** Goes forward one step of the URL history. */
405 /** Goes up one hierarchy of the current URL. */
408 /** Changes the location to the home URL. */
411 /** Open the previous URL in the URL history in a new tab. */
412 void goBackInNewTab();
414 /** Open the next URL in the URL history in a new tab. */
415 void goForwardInNewTab();
417 /** Open the URL one hierarchy above the current URL in a new tab. */
420 /** * Open the home URL in a new tab. */
421 void goHomeInNewTab();
423 /** Opens Kompare for 2 selected files. */
427 * Hides the menu bar if it is visible, makes the menu bar
428 * visible if it is hidden.
430 void toggleShowMenuBar();
432 /** Updates "Open Preferred Search Tool" action. */
433 void updateOpenPreferredSearchToolAction();
435 /** Opens preferred search tool for the current location. */
436 void openPreferredSearchTool();
438 /** Opens a terminal window for the current location. */
441 /** Opens terminal windows for the selected items' locations. */
442 void openTerminalHere();
444 /** Opens a terminal window for the URL. */
445 void openTerminalJob(const QUrl
&url
);
447 /** Focus a Terminal Panel. */
448 void focusTerminalPanel();
450 /** Opens the settings dialog for Dolphin. */
453 /** Updates the state of the 'Show Full Location' action. */
454 void slotEditableStateChanged(bool editable
);
457 * Updates the state of the 'Edit' menu actions and emits
458 * the signal selectionChanged().
460 void slotSelectionChanged(const KFileItemList
&selection
);
463 * Updates the state of the 'Back' and 'Forward' menu
464 * actions corresponding to the current history.
466 void updateHistory();
468 /** Updates the state of the 'Show filter bar' menu action. */
469 void updateFilterBarAction(bool show
);
471 /** Open a new main window. */
472 void openNewMainWindow();
475 * Opens a new view with the current URL that is part of a tab and
478 void openNewActivatedTab();
481 * Adds the current URL as an entry to the Places panel
486 * Opens the selected folder in a new tab.
491 * Opens the selected folder in a new window.
493 void openInNewWindow();
496 * Opens the selected folder in the other inactive split view, enables split view if necessary.
498 void openInSplitView(const QUrl
&url
);
501 * Show the target of the selected symlink
506 * Indicates in the statusbar that the execution of the command \a command
509 void showCommand(CommandType command
);
512 * If the URL can be listed, open it in the current view, otherwise
513 * run it through KRun.
515 void handleUrl(const QUrl
&url
);
518 * Is invoked when the write state of a folder has been changed and
519 * enables/disables the "Create New..." menu entry.
521 void slotWriteStateChanged(bool isFolderWritable
);
524 * Opens the context menu on the current mouse position.
525 * @pos Position in screen coordinates.
526 * @item File item context. If item is null, the context menu
527 * should be applied to \a url.
528 * @selectedItems The selected items for which the context menu
529 * is opened. This list generally includes \a item.
530 * @url URL which contains \a item.
532 void openContextMenu(const QPoint
&pos
, const KFileItem
&item
, const KFileItemList
&selectedItems
, const QUrl
&url
);
535 * Updates the menu that is by default at the right end of the toolbar.
537 * In true "simple by default" fashion, the menu only contains the most important
538 * and necessary actions to be able to use Dolphin. This is supposed to hold true even
539 * if the user does not know how to open a context menu. More advanced actions can be
540 * discovered through a sub-menu (@see KConfigWidgets::KHamburgerMenu::setMenuBarAdvertised()).
542 void updateHamburgerMenu();
545 * Is called if the user clicked an item in the Places Panel.
546 * Reloads the view if \a url is the current URL already, and changes the
547 * current URL otherwise.
549 void slotPlaceActivated(const QUrl
&url
);
552 * Is called if the another view has been activated by changing the current
553 * tab or activating another view in split-view mode.
555 * Activates the given view, which means that all menu actions are applied
556 * to this view. When having a split view setup, the nonactive view is
557 * usually shown in darker colors.
559 void activeViewChanged(DolphinViewContainer
*viewContainer
);
561 void closedTabsCountChanged(unsigned int count
);
564 * Is called if a new tab has been opened or a tab has been closed to
565 * enable/disable the tab actions.
567 void tabCountChanged(int count
);
570 * Updates the Window Title with the caption from the active view container
572 void updateWindowTitle();
575 * This slot is called when the user requested to unmount a removable media
576 * from the places menu
578 void slotStorageTearDownFromPlacesRequested(const QString
&mountPath
);
581 * This slot is called when the user requested to unmount a removable media
582 * _not_ from the dolphin's places menu (from the notification area for e.g.)
583 * This slot is basically connected to each removable device's
584 * Solid::StorageAccess::teardownRequested(const QString & udi)
585 * signal through the places panel.
587 void slotStorageTearDownExternallyRequested(const QString
&mountPath
);
590 * Is called when the view has finished loading the directory.
592 void slotDirectoryLoadingCompleted();
595 * Is called when the user middle clicks a toolbar button.
597 * Here middle clicking Back/Forward/Up/Home will open the resulting
598 * folder in a new tab.
600 void slotToolBarActionMiddleClicked(QAction
*action
);
603 * Is called before the Back popup menu is shown. This slot will populate
604 * the menu with history data
606 void slotAboutToShowBackPopupMenu();
609 * This slot is used by the Back Popup Menu to go back to a specific
610 * history index. The QAction::data will carry an int with the index
613 void slotGoBack(QAction
*action
);
616 * Middle clicking Back/Forward will open the resulting folder in a new tab.
618 void slotBackForwardActionMiddleClicked(QAction
*action
);
621 * Is called before the Forward popup menu is shown. This slot will populate
622 * the menu with history data
624 void slotAboutToShowForwardPopupMenu();
627 * This slot is used by the Forward Popup Menu to go forward to a specific
628 * history index. The QAction::data will carry an int with the index
631 void slotGoForward(QAction
*action
);
634 * Is called when configuring the keyboard shortcuts
636 void slotKeyBindings();
641 void slotSaveSession();
645 * Sets up the various menus and actions and connects them.
650 * Sets up the dock widgets and their panels.
652 void setupDockWidgets();
654 void updateFileAndEditActions();
655 void updateViewActions();
656 void updateGoActions();
659 * Connects the signals from the created DolphinView with
660 * the DolphinViewContainer \a container with the corresponding slots of
661 * the DolphinMainWindow. This method must be invoked each
662 * time a DolphinView has been created.
664 void connectViewSignals(DolphinViewContainer
*container
);
667 * Updates the text of the split action:
668 * If two views are shown, the text is set to "Split",
669 * otherwise the text is set to "Join". The icon
670 * is updated to match with the text and the currently active view.
672 void updateSplitActions();
675 * Sets the window sides the toolbar may be moved to based on toolbar contents.
677 void updateAllowedToolbarAreas();
679 bool isKompareInstalled() const;
682 * Creates an action for showing/hiding a panel, that is accessible
683 * in "Configure toolbars..." and "Configure shortcuts...".
685 void createPanelAction(const QIcon
&icon
, const QKeySequence
&shortcut
, QDockWidget
*dockAction
, const QString
&actionName
);
687 /** Adds "What's This?" texts to many widgets and StandardActions. */
688 void setupWhatsThis();
690 /** Returns preferred search tool as configured in "More Search Tools" menu. */
691 QPointer
<QAction
> preferredSearchTool();
694 * Adds this action to the mainWindow's toolbar and saves the change
695 * in the users ui configuration file.
696 * This method is only needed for migration and should be removed once we can expect
697 * that pretty much all users have been migrated. Remove in 2026 because that's when
698 * even the most risk-averse distros will already have been forced to upgrade.
699 * @return true if successful. Otherwise false.
701 bool addHamburgerMenuToToolbar();
703 /** Creates an action representing an item in the URL navigator history */
704 static QAction
*urlNavigatorHistoryAction(const KUrlNavigator
*urlNavigator
, int historyIndex
, QObject
*parent
= nullptr);
708 * Implements a custom error handling for the undo manager. This
709 * assures that all errors are shown in the status bar of Dolphin
710 * instead as modal error dialog with an OK button.
712 class UndoUiInterface
: public KIO::FileUndoManager::UiInterface
716 ~UndoUiInterface() override
;
717 void jobError(KIO::Job
*job
) override
;
720 KNewFileMenu
*m_newFileMenu
;
721 DolphinTabWidget
*m_tabWidget
;
722 DolphinViewContainer
*m_activeViewContainer
;
724 DolphinViewActionHandler
*m_actionHandler
;
725 DolphinRemoteEncoding
*m_remoteEncoding
;
726 QPointer
<DolphinSettingsDialog
> m_settingsDialog
;
727 DolphinBookmarkHandler
*m_bookmarkHandler
;
728 SelectionMode::ActionTextHelper
*m_actionTextHelper
;
730 KIO::OpenUrlJob
*m_lastHandleUrlOpenJob
;
732 TerminalPanel
*m_terminalPanel
;
733 PlacesPanel
*m_placesPanel
;
734 bool m_tearDownFromPlacesRequested
;
736 KToolBarPopupAction
*m_backAction
;
737 KToolBarPopupAction
*m_forwardAction
;
740 KFileItemActions m_fileItemActions
;
742 QTimer
*m_sessionSaveTimer
;
743 QFutureWatcher
<void> *m_sessionSaveWatcher
;
744 bool m_sessionSaveScheduled
;
746 friend class DolphinMainWindowTest
;
749 inline DolphinViewContainer
*DolphinMainWindow::activeViewContainer() const
751 return m_activeViewContainer
;
754 inline KNewFileMenu
*DolphinMainWindow::newFileMenu() const
756 return m_newFileMenu
;
759 #endif // DOLPHIN_MAINWINDOW_H