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 KToolBarPopupAction
;
54 namespace SelectionMode
56 class ActionTextHelper
;
60 * @short Main window for Dolphin.
62 * Handles the menus, toolbars and Dolphin views.
64 class DolphinMainWindow
: public KXmlGuiWindow
67 Q_CLASSINFO("D-Bus Interface", "org.kde.dolphin.MainWindow")
71 ~DolphinMainWindow() override
;
74 * Returns the currently active view.
75 * All menu actions are applied to this view. When
76 * having a split view setup, the nonactive view
77 * is usually shown in darker colors.
79 DolphinViewContainer
*activeViewContainer() const;
82 * Returns view container for all tabs
84 QVector
<DolphinViewContainer
*> viewContainers() const;
87 * Opens each directory in \p dirs in a separate tab. If \a splitView is set,
88 * 2 directories are collected within one tab.
89 * \pre \a dirs must contain at least one url.
91 void openDirectories(const QList
<QUrl
> &dirs
, bool splitView
);
94 * Opens the directories which contain the files \p files and selects all files.
95 * If \a splitView is set, 2 directories are collected within one tab.
96 * \pre \a files must contain at least one url.
98 void openFiles(const QList
<QUrl
> &files
, bool splitView
);
101 * Returns the 'Create New...' sub menu which also can be shared
102 * with other menus (e. g. a context menu).
104 KNewFileMenu
*newFileMenu() const;
107 * Augments Qt's build-in QMainWindow context menu to add
108 * Dolphin-specific actions, such as "unlock panels".
110 QMenu
*createPopupMenu() override
;
113 * Switch the window's view containers' locations to display the home path
114 * for any which are currently displaying a location corresponding to or
117 * This typically done after unmounting a disk at mountPath to ensure that
118 * the window is not displaying an invalid location.
120 void setViewsToHomeIfMountPathOpen(const QString
&mountPath
);
123 * Enables or disables the session autosaving feature.
125 * @param enable If true, saves the session automatically after a fixed
126 * time interval from the last state change.
128 void setSessionAutoSaveEnabled(bool enable
);
130 bool isFoldersPanelEnabled() const;
131 bool isInformationPanelEnabled() const;
132 bool isSplitViewEnabledInCurrentTab() const;
136 * Opens each directory in \p dirs in a separate tab. If \a splitView is set,
137 * 2 directories are collected within one tab.
138 * \pre \a dirs must contain at least one url.
140 * @note this function is overloaded so that it is callable via DBus.
142 void openDirectories(const QStringList
&dirs
, bool splitView
);
145 * Opens the directories which contain the files \p files and selects all files.
146 * If \a splitView is set, 2 directories are collected within one tab.
147 * \pre \a files must contain at least one url.
149 * @note this is overloaded so that this function is callable via DBus.
151 void openFiles(const QStringList
&files
, bool splitView
);
154 * Tries to raise/activate the Dolphin window.
156 void activateWindow(const QString
&activationToken
);
158 bool isActiveWindow();
161 * Determines if a URL is open in any tab.
162 * @note Use of QString instead of QUrl is required to be callable via DBus.
164 * @param url URL to look for
165 * @returns true if url is currently open in a tab, false otherwise.
167 bool isUrlOpen(const QString
&url
);
170 * @return Whether the item with @p url can be found in any view only by switching
171 * between already open tabs and scrolling in their primary or secondary view.
172 * @note Use of QString instead of QUrl is required to be callable via DBus.
174 bool isItemVisibleInAnyView(const QString
&urlOfItem
);
177 * Pastes the clipboard data into the currently selected folder
178 * of the active view. If not exactly one folder is selected,
179 * no pasting is done at all.
181 void pasteIntoFolder();
184 * Implementation of the MainWindowAdaptor/QDBusAbstractAdaptor interface.
185 * Inform all affected dolphin components (panels, views) of an URL
188 void changeUrl(const QUrl
&url
);
191 * The current directory of the Terminal Panel has changed, probably because
192 * the user entered a 'cd' command. This slot calls changeUrl(url) and makes
193 * sure that the panel keeps the keyboard focus.
195 void slotTerminalDirectoryChanged(const QUrl
&url
);
197 /** Stores all settings and quits Dolphin. */
201 * Opens a new tab in the background showing the URL \a url.
203 void openNewTab(const QUrl
&url
);
206 * Opens a new tab showing the URL \a url and activate it.
208 void openNewTabAndActivate(const QUrl
&url
);
211 * Opens a new window showing the URL \a url.
213 void openNewWindow(const QUrl
&url
);
215 /** @see GeneralSettings::splitViewChanged() */
216 void slotSplitViewChanged();
220 * Is sent if the selection of the currently active view has
223 void selectionChanged(const KFileItemList
&selection
);
226 * Is sent if the url of the currently active view has
229 void urlChanged(const QUrl
&url
);
232 * Is emitted if information of an item is requested to be shown e. g. in the panel.
233 * If item is null, no item information request is pending.
235 void requestItemInfo(const KFileItem
&item
);
238 * It is emitted when in the current view, files are changed,
239 * or dirs have files/removed from them.
241 void fileItemsChanged(const KFileItemList
&changedFileItems
);
244 * Is emitted if the settings have been changed.
246 void settingsChanged();
249 /** @see QObject::event() */
250 bool event(QEvent
*event
) override
;
252 /** @see QWidget::showEvent() */
253 void showEvent(QShowEvent
*event
) override
;
255 /** @see QMainWindow::closeEvent() */
256 void closeEvent(QCloseEvent
*event
) override
;
258 /** @see KMainWindow::saveProperties() */
259 void saveProperties(KConfigGroup
&group
) override
;
261 /** @see KMainWindow::readProperties() */
262 void readProperties(const KConfigGroup
&group
) override
;
264 /** Sets a sane initial window size **/
265 QSize
sizeHint() const override
;
269 * Calls the base method KXmlGuiWindow::saveNewToolbarConfig().
270 * Is also used to set toolbar constraints and UrlNavigator position
271 * based on the newly changed toolbar configuration.
273 void saveNewToolbarConfig() override
;
277 * Refreshes the views of the main window by recreating them according to
278 * the given Dolphin settings.
282 void clearStatusBar();
284 /** Updates the 'Create New...' sub menu. */
285 void updateNewMenu();
287 void createDirectory();
289 /** Shows the error message in the status bar of the active view. */
290 void showErrorMessage(const QString
&message
);
293 * Updates the state of the 'Undo' menu action dependent
294 * on the parameter \a available.
296 void slotUndoAvailable(bool available
);
298 /** Sets the text of the 'Undo' menu action to \a text. */
299 void slotUndoTextChanged(const QString
&text
);
301 /** Performs the current undo operation. */
305 * Copies all selected items to the clipboard and marks
310 /** Copies all selected items to the clipboard. */
313 /** Pastes the clipboard data to the active view. */
316 /** Replaces the URL navigator by a search box to find files. */
319 /** Updates the state of the search action according to the view container. */
320 void updateSearchAction();
323 * Updates the text of the paste action dependent on
324 * the number of items which are in the clipboard.
326 void updatePasteAction();
328 /** Calls DolphinViewContainer::setSelectionMode() for m_activeViewContainer. */
329 void slotSetSelectionMode(bool enabled
, SelectionMode::BottomBar::Contents bottomBarContents
);
331 /** Selects all items from the active view. */
335 * Inverts the selection of all items of the active view:
336 * Selected items get nonselected and nonselected items get
339 void invertSelection();
342 * Switches between one and two views:
343 * If one view is visible, it will get split into two views.
344 * If already two views are visible, the active view gets closed.
346 void toggleSplitView();
349 * Pops out a split view.
350 * The active view will be popped out, unless the view is not split,
351 * in which case nothing will happen.
353 void popoutSplitView();
355 /** Dedicated action to open the stash:/ ioslave in split view. */
356 void toggleSplitStash();
358 /** Copies all selected items to the inactive view. */
359 void copyToInactiveSplitView();
361 /** Moves all selected items to the inactive view. */
362 void moveToInactiveSplitView();
364 /** Reloads the currently active view. */
367 /** Stops the loading process for the currently active view. */
370 void enableStopAction();
371 void disableStopAction();
373 void toggleSelectionMode();
375 void showFilterBar();
376 void toggleFilterBar();
379 * Toggles between edit and browse mode of the navigation bar.
381 void toggleEditLocation();
384 * Switches to the edit mode of the navigation bar and selects
385 * the whole URL, so that it can be replaced by the user. If the edit mode is
386 * already active, it is assured that the navigation bar get focused.
388 void replaceLocation();
391 * Toggles the state of the panels between a locked and unlocked layout.
393 void togglePanelLockState();
396 * Is invoked if the Terminal panel got visible/invisible and takes care
397 * that the active view has the focus if the Terminal panel is invisible.
399 void slotTerminalPanelVisibilityChanged();
401 /** Goes back one step of the URL history. */
404 /** Goes forward one step of the URL history. */
407 /** Goes up one hierarchy of the current URL. */
410 /** Changes the location to the home URL. */
413 /** Open the previous URL in the URL history in a new tab. */
414 void goBackInNewTab();
416 /** Open the next URL in the URL history in a new tab. */
417 void goForwardInNewTab();
419 /** Open the URL one hierarchy above the current URL in a new tab. */
422 /** * Open the home URL in a new tab. */
423 void goHomeInNewTab();
425 /** Opens Kompare for 2 selected files. */
429 * Hides the menu bar if it is visible, makes the menu bar
430 * visible if it is hidden.
432 void toggleShowMenuBar();
434 /** Updates "Open Preferred Search Tool" action. */
435 void updateOpenPreferredSearchToolAction();
437 /** Opens preferred search tool for the current location. */
438 void openPreferredSearchTool();
440 /** Opens a terminal window for the current location. */
443 /** Opens terminal windows for the selected items' locations. */
444 void openTerminalHere();
446 /** Opens a terminal window for the URL. */
447 void openTerminalJob(const QUrl
&url
);
449 /** Focus a Terminal Panel. */
450 void focusTerminalPanel();
452 /** Opens the settings dialog for Dolphin. */
455 /** Updates the state of the 'Show Full Location' action. */
456 void slotEditableStateChanged(bool editable
);
459 * Updates the state of the 'Edit' menu actions and emits
460 * the signal selectionChanged().
462 void slotSelectionChanged(const KFileItemList
&selection
);
465 * Updates the state of the 'Back' and 'Forward' menu
466 * actions corresponding to the current history.
468 void updateHistory();
470 /** Updates the state of the 'Show filter bar' menu action. */
471 void updateFilterBarAction(bool show
);
473 /** Open a new main window. */
474 void openNewMainWindow();
477 * Opens a new view with the current URL that is part of a tab and
480 void openNewActivatedTab();
483 * Adds the current URL as an entry to the Places panel
488 * Opens the selected folder in a new tab.
493 * Opens the selected folder in a new window.
495 void openInNewWindow();
498 * Opens the selected folder in the other inactive split view, enables split view if necessary.
500 void openInSplitView(const QUrl
&url
);
503 * Show the target of the selected symlink
508 * Indicates in the statusbar that the execution of the command \a command
511 void showCommand(CommandType command
);
514 * If the URL can be listed, open it in the current view, otherwise
515 * run it through KRun.
517 void handleUrl(const QUrl
&url
);
520 * Is invoked when the write state of a folder has been changed and
521 * enables/disables the "Create New..." menu entry.
523 void slotWriteStateChanged(bool isFolderWritable
);
526 * Opens the context menu on the current mouse position.
527 * @pos Position in screen coordinates.
528 * @item File item context. If item is null, the context menu
529 * should be applied to \a url.
530 * @selectedItems The selected items for which the context menu
531 * is opened. This list generally includes \a item.
532 * @url URL which contains \a item.
534 void openContextMenu(const QPoint
&pos
, const KFileItem
&item
, const KFileItemList
&selectedItems
, const QUrl
&url
);
537 * Updates the menu that is by default at the right end of the toolbar.
539 * In true "simple by default" fashion, the menu only contains the most important
540 * and necessary actions to be able to use Dolphin. This is supposed to hold true even
541 * if the user does not know how to open a context menu. More advanced actions can be
542 * discovered through a sub-menu (@see KConfigWidgets::KHamburgerMenu::setMenuBarAdvertised()).
544 void updateHamburgerMenu();
547 * Is called if the user clicked an item in the Places Panel.
548 * Reloads the view if \a url is the current URL already, and changes the
549 * current URL otherwise.
551 void slotPlaceActivated(const QUrl
&url
);
554 * Is called if the another view has been activated by changing the current
555 * tab or activating another view in split-view mode.
557 * Activates the given view, which means that all menu actions are applied
558 * to this view. When having a split view setup, the nonactive view is
559 * usually shown in darker colors.
561 void activeViewChanged(DolphinViewContainer
*viewContainer
);
563 void closedTabsCountChanged(unsigned int count
);
566 * Is called if a new tab has been opened or a tab has been closed to
567 * enable/disable the tab actions.
569 void tabCountChanged(int count
);
572 * Updates the Window Title with the caption from the active view container
574 void updateWindowTitle();
577 * This slot is called when the user requested to unmount a removable media
578 * from the places menu
580 void slotStorageTearDownFromPlacesRequested(const QString
&mountPath
);
583 * This slot is called when the user requested to unmount a removable media
584 * _not_ from the dolphin's places menu (from the notification area for e.g.)
585 * This slot is basically connected to each removable device's
586 * Solid::StorageAccess::teardownRequested(const QString & udi)
587 * signal through the places panel.
589 void slotStorageTearDownExternallyRequested(const QString
&mountPath
);
592 * Is called when the view has finished loading the directory.
594 void slotDirectoryLoadingCompleted();
597 * Is called when the user middle clicks a toolbar button.
599 * Here middle clicking Back/Forward/Up/Home will open the resulting
600 * folder in a new tab.
602 void slotToolBarActionMiddleClicked(QAction
*action
);
605 * Is called before the Back popup menu is shown. This slot will populate
606 * the menu with history data
608 void slotAboutToShowBackPopupMenu();
611 * This slot is used by the Back Popup Menu to go back to a specific
612 * history index. The QAction::data will carry an int with the index
615 void slotGoBack(QAction
*action
);
618 * Middle clicking Back/Forward will open the resulting folder in a new tab.
620 void slotBackForwardActionMiddleClicked(QAction
*action
);
623 * Is called before the Forward popup menu is shown. This slot will populate
624 * the menu with history data
626 void slotAboutToShowForwardPopupMenu();
629 * This slot is used by the Forward Popup Menu to go forward to a specific
630 * history index. The QAction::data will carry an int with the index
633 void slotGoForward(QAction
*action
);
636 * Is called when configuring the keyboard shortcuts
638 void slotKeyBindings();
643 void slotSaveSession();
647 * Sets up the various menus and actions and connects them.
652 * Sets up the dock widgets and their panels.
654 void setupDockWidgets();
656 void updateFileAndEditActions();
657 void updateViewActions();
658 void updateGoActions();
661 * Connects the signals from the created DolphinView with
662 * the DolphinViewContainer \a container with the corresponding slots of
663 * the DolphinMainWindow. This method must be invoked each
664 * time a DolphinView has been created.
666 void connectViewSignals(DolphinViewContainer
*container
);
669 * Updates the text of the split action:
670 * If two views are shown, the text is set to "Split",
671 * otherwise the text is set to "Join". The icon
672 * is updated to match with the text and the currently active view.
674 void updateSplitActions();
677 * Sets the window sides the toolbar may be moved to based on toolbar contents.
679 void updateAllowedToolbarAreas();
681 bool isKompareInstalled() const;
684 * Creates an action for showing/hiding a panel, that is accessible
685 * in "Configure toolbars..." and "Configure shortcuts...".
687 void createPanelAction(const QIcon
&icon
, const QKeySequence
&shortcut
, QDockWidget
*dockAction
, const QString
&actionName
);
689 /** Adds "What's This?" texts to many widgets and StandardActions. */
690 void setupWhatsThis();
692 /** Returns preferred search tool as configured in "More Search Tools" menu. */
693 QPointer
<QAction
> preferredSearchTool();
696 * Adds this action to the mainWindow's toolbar and saves the change
697 * in the users ui configuration file.
698 * This method is only needed for migration and should be removed once we can expect
699 * that pretty much all users have been migrated. Remove in 2026 because that's when
700 * even the most risk-averse distros will already have been forced to upgrade.
701 * @return true if successful. Otherwise false.
703 bool addHamburgerMenuToToolbar();
705 /** Creates an action representing an item in the URL navigator history */
706 static QAction
*urlNavigatorHistoryAction(const KUrlNavigator
*urlNavigator
, int historyIndex
, QObject
*parent
= nullptr);
710 * Implements a custom error handling for the undo manager. This
711 * assures that all errors are shown in the status bar of Dolphin
712 * instead as modal error dialog with an OK button.
714 class UndoUiInterface
: public KIO::FileUndoManager::UiInterface
718 ~UndoUiInterface() override
;
719 void jobError(KIO::Job
*job
) override
;
722 KNewFileMenu
*m_newFileMenu
;
723 DolphinTabWidget
*m_tabWidget
;
724 DolphinViewContainer
*m_activeViewContainer
;
726 DolphinViewActionHandler
*m_actionHandler
;
727 DolphinRemoteEncoding
*m_remoteEncoding
;
728 QPointer
<DolphinSettingsDialog
> m_settingsDialog
;
729 DolphinBookmarkHandler
*m_bookmarkHandler
;
730 SelectionMode::ActionTextHelper
*m_actionTextHelper
;
731 DisabledActionNotifier
*m_disabledActionNotifier
;
733 KIO::OpenUrlJob
*m_lastHandleUrlOpenJob
;
735 TerminalPanel
*m_terminalPanel
;
736 PlacesPanel
*m_placesPanel
;
737 bool m_tearDownFromPlacesRequested
;
739 KToolBarPopupAction
*m_backAction
;
740 KToolBarPopupAction
*m_forwardAction
;
741 KActionMenu
*m_splitViewAction
;
742 QAction
*m_splitViewMenuAction
;
745 KFileItemActions m_fileItemActions
;
747 QTimer
*m_sessionSaveTimer
;
748 QFutureWatcher
<void> *m_sessionSaveWatcher
;
749 bool m_sessionSaveScheduled
;
751 friend class DolphinMainWindowTest
;
754 inline DolphinViewContainer
*DolphinMainWindow::activeViewContainer() const
756 return m_activeViewContainer
;
759 inline KNewFileMenu
*DolphinMainWindow::newFileMenu() const
761 return m_newFileMenu
;
764 #endif // DOLPHIN_MAINWINDOW_H