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"
30 typedef KIO::FileUndoManager::CommandType CommandType
;
32 class DolphinBookmarkHandler
;
33 class DolphinViewActionHandler
;
34 class DolphinSettingsDialog
;
35 class DolphinViewContainer
;
36 class DolphinRemoteEncoding
;
37 class DolphinTabWidget
;
42 class KToolBarPopupAction
;
51 namespace SelectionMode
53 class ActionTextHelper
;
57 * @short Main window for Dolphin.
59 * Handles the menus, toolbars and Dolphin views.
61 class DolphinMainWindow
: public KXmlGuiWindow
64 Q_CLASSINFO("D-Bus Interface", "org.kde.dolphin.MainWindow")
68 ~DolphinMainWindow() override
;
71 * Returns the currently active view.
72 * All menu actions are applied to this view. When
73 * having a split view setup, the nonactive view
74 * is usually shown in darker colors.
76 DolphinViewContainer
*activeViewContainer() const;
79 * Returns view container for all tabs
81 QVector
<DolphinViewContainer
*> viewContainers() const;
84 * Opens each directory in \p dirs in a separate tab. If \a splitView is set,
85 * 2 directories are collected within one tab.
86 * \pre \a dirs must contain at least one url.
88 void openDirectories(const QList
<QUrl
> &dirs
, bool splitView
);
91 * Opens the directories which contain the files \p files and selects all files.
92 * If \a splitView is set, 2 directories are collected within one tab.
93 * \pre \a files must contain at least one url.
95 void openFiles(const QList
<QUrl
> &files
, bool splitView
);
98 * Returns the 'Create New...' sub menu which also can be shared
99 * with other menus (e. g. a context menu).
101 KNewFileMenu
*newFileMenu() const;
104 * Augments Qt's build-in QMainWindow context menu to add
105 * Dolphin-specific actions, such as "unlock panels".
107 QMenu
*createPopupMenu() override
;
110 * Switch the window's view containers' locations to display the home path
111 * for any which are currently displaying a location corresponding to or
114 * This typically done after unmounting a disk at mountPath to ensure that
115 * the window is not displaying an invalid location.
117 void setViewsToHomeIfMountPathOpen(const QString
&mountPath
);
119 bool isFoldersPanelEnabled() const;
120 bool isInformationPanelEnabled() const;
121 bool isSplitViewEnabledInCurrentTab() const;
125 * Opens each directory in \p dirs in a separate tab. If \a splitView is set,
126 * 2 directories are collected within one tab.
127 * \pre \a dirs must contain at least one url.
129 * @note this function is overloaded so that it is callable via DBus.
131 void openDirectories(const QStringList
&dirs
, bool splitView
);
134 * Opens the directories which contain the files \p files and selects all files.
135 * If \a splitView is set, 2 directories are collected within one tab.
136 * \pre \a files must contain at least one url.
138 * @note this is overloaded so that this function is callable via DBus.
140 void openFiles(const QStringList
&files
, bool splitView
);
143 * Tries to raise/activate the Dolphin window.
145 void activateWindow(const QString
&activationToken
);
147 bool isActiveWindow();
150 * Determines if a URL is open in any tab.
151 * @note Use of QString instead of QUrl is required to be callable via DBus.
153 * @param url URL to look for
154 * @returns true if url is currently open in a tab, false otherwise.
156 bool isUrlOpen(const QString
&url
);
159 * @return Whether the item with @p url can be found in any view only by switching
160 * between already open tabs and scrolling in their primary or secondary view.
161 * @note Use of QString instead of QUrl is required to be callable via DBus.
163 bool isItemVisibleInAnyView(const QString
&urlOfItem
);
166 * Pastes the clipboard data into the currently selected folder
167 * of the active view. If not exactly one folder is selected,
168 * no pasting is done at all.
170 void pasteIntoFolder();
173 * Implementation of the MainWindowAdaptor/QDBusAbstractAdaptor interface.
174 * Inform all affected dolphin components (panels, views) of an URL
177 void changeUrl(const QUrl
&url
);
180 * The current directory of the Terminal Panel has changed, probably because
181 * the user entered a 'cd' command. This slot calls changeUrl(url) and makes
182 * sure that the panel keeps the keyboard focus.
184 void slotTerminalDirectoryChanged(const QUrl
&url
);
186 /** Stores all settings and quits Dolphin. */
190 * Opens a new tab in the background showing the URL \a url.
192 void openNewTab(const QUrl
&url
);
195 * Opens a new tab showing the URL \a url and activate it.
197 void openNewTabAndActivate(const QUrl
&url
);
200 * Opens a new window showing the URL \a url.
202 void openNewWindow(const QUrl
&url
);
204 /** @see GeneralSettings::splitViewChanged() */
205 void slotSplitViewChanged();
207 bool isOnActivity(const QString
&activityId
) const;
208 bool isOnCurrentDesktop() const;
212 * Is sent if the selection of the currently active view has
215 void selectionChanged(const KFileItemList
&selection
);
218 * Is sent if the url of the currently active view has
221 void urlChanged(const QUrl
&url
);
224 * Is emitted if information of an item is requested to be shown e. g. in the panel.
225 * If item is null, no item information request is pending.
227 void requestItemInfo(const KFileItem
&item
);
230 * It is emitted when in the current view, files are changed,
231 * or dirs have files/removed from them.
233 void fileItemsChanged(const KFileItemList
&changedFileItems
);
236 * Is emitted if the settings have been changed.
238 void settingsChanged();
241 /** @see QObject::event() */
242 bool event(QEvent
*event
) override
;
244 /** @see QWidget::showEvent() */
245 void showEvent(QShowEvent
*event
) override
;
247 /** @see QMainWindow::closeEvent() */
248 void closeEvent(QCloseEvent
*event
) override
;
250 /** @see KMainWindow::saveProperties() */
251 void saveProperties(KConfigGroup
&group
) override
;
253 /** @see KMainWindow::readProperties() */
254 void readProperties(const KConfigGroup
&group
) override
;
256 /** Sets a sane initial window size **/
257 QSize
sizeHint() const override
;
261 * Calls the base method KXmlGuiWindow::saveNewToolbarConfig().
262 * Is also used to set toolbar constraints and UrlNavigator position
263 * based on the newly changed toolbar configuration.
265 void saveNewToolbarConfig() override
;
269 * Refreshes the views of the main window by recreating them according to
270 * the given Dolphin settings.
274 void clearStatusBar();
276 /** Updates the 'Create New...' sub menu. */
277 void updateNewMenu();
279 void createDirectory();
281 /** Shows the error message in the status bar of the active view. */
282 void showErrorMessage(const QString
&message
);
285 * Updates the state of the 'Undo' menu action dependent
286 * on the parameter \a available.
288 void slotUndoAvailable(bool available
);
290 /** Sets the text of the 'Undo' menu action to \a text. */
291 void slotUndoTextChanged(const QString
&text
);
293 /** Performs the current undo operation. */
297 * Copies all selected items to the clipboard and marks
302 /** Copies all selected items to the clipboard. */
305 /** Pastes the clipboard data to the active view. */
308 /** Replaces the URL navigator by a search box to find files. */
311 /** Updates the state of the search action according to the view container. */
312 void updateSearchAction();
315 * Updates the text of the paste action dependent on
316 * the number of items which are in the clipboard.
318 void updatePasteAction();
320 /** Calls DolphinViewContainer::setSelectionMode() for m_activeViewContainer. */
321 void slotSetSelectionMode(bool enabled
, SelectionMode::BottomBar::Contents bottomBarContents
);
323 /** Selects all items from the active view. */
327 * Inverts the selection of all items of the active view:
328 * Selected items get nonselected and nonselected items get
331 void invertSelection();
334 * Switches between one and two views:
335 * If one view is visible, it will get split into two views.
336 * If already two views are visible, the active view gets closed.
338 void toggleSplitView();
340 /** Dedicated action to open the stash:/ ioslave in split view. */
341 void toggleSplitStash();
343 /** Copies all selected items to the inactive view. */
344 void copyToInactiveSplitView();
346 /** Moves all selected items to the inactive view. */
347 void moveToInactiveSplitView();
349 /** Reloads the currently active view. */
352 /** Stops the loading process for the currently active view. */
355 void enableStopAction();
356 void disableStopAction();
358 void toggleSelectionMode();
360 void showFilterBar();
361 void toggleFilterBar();
364 * Toggles between edit and browse mode of the navigation bar.
366 void toggleEditLocation();
369 * Switches to the edit mode of the navigation bar and selects
370 * the whole URL, so that it can be replaced by the user. If the edit mode is
371 * already active, it is assured that the navigation bar get focused.
373 void replaceLocation();
376 * Toggles the state of the panels between a locked and unlocked layout.
378 void togglePanelLockState();
381 * Is invoked if the Terminal panel got visible/invisible and takes care
382 * that the active view has the focus if the Terminal panel is invisible.
384 void slotTerminalPanelVisibilityChanged();
386 /** Goes back one step of the URL history. */
389 /** Goes forward one step of the URL history. */
392 /** Goes up one hierarchy of the current URL. */
395 /** Changes the location to the home URL. */
398 /** Open the previous URL in the URL history in a new tab. */
399 void goBackInNewTab();
401 /** Open the next URL in the URL history in a new tab. */
402 void goForwardInNewTab();
404 /** Open the URL one hierarchy above the current URL in a new tab. */
407 /** * Open the home URL in a new tab. */
408 void goHomeInNewTab();
410 /** Opens Kompare for 2 selected files. */
414 * Hides the menu bar if it is visible, makes the menu bar
415 * visible if it is hidden.
417 void toggleShowMenuBar();
419 /** Updates "Open Preferred Search Tool" action. */
420 void updateOpenPreferredSearchToolAction();
422 /** Opens preferred search tool for the current location. */
423 void openPreferredSearchTool();
425 /** Opens a terminal window for the current location. */
428 /** Opens terminal windows for the selected items' locations. */
429 void openTerminalHere();
431 /** Opens a terminal window for the URL. */
432 void openTerminalJob(const QUrl
&url
);
434 /** Focus a Terminal Panel. */
435 void focusTerminalPanel();
437 /** Opens the settings dialog for Dolphin. */
440 /** Updates the state of the 'Show Full Location' action. */
441 void slotEditableStateChanged(bool editable
);
444 * Updates the state of the 'Edit' menu actions and emits
445 * the signal selectionChanged().
447 void slotSelectionChanged(const KFileItemList
&selection
);
450 * Updates the state of the 'Back' and 'Forward' menu
451 * actions corresponding to the current history.
453 void updateHistory();
455 /** Updates the state of the 'Show filter bar' menu action. */
456 void updateFilterBarAction(bool show
);
458 /** Open a new main window. */
459 void openNewMainWindow();
462 * Opens a new view with the current URL that is part of a tab and
465 void openNewActivatedTab();
468 * Adds the current URL as an entry to the Places panel
473 * Opens the selected folder in a new tab.
478 * Opens the selected folder in a new window.
480 void openInNewWindow();
483 * Show the target of the selected symlink
488 * Indicates in the statusbar that the execution of the command \a command
491 void showCommand(CommandType command
);
494 * If the URL can be listed, open it in the current view, otherwise
495 * run it through KRun.
497 void handleUrl(const QUrl
&url
);
500 * Is invoked when the write state of a folder has been changed and
501 * enables/disables the "Create New..." menu entry.
503 void slotWriteStateChanged(bool isFolderWritable
);
506 * Opens the context menu on the current mouse position.
507 * @pos Position in screen coordinates.
508 * @item File item context. If item is null, the context menu
509 * should be applied to \a url.
510 * @selectedItems The selected items for which the context menu
511 * is opened. This list generally includes \a item.
512 * @url URL which contains \a item.
514 void openContextMenu(const QPoint
&pos
, const KFileItem
&item
, const KFileItemList
&selectedItems
, const QUrl
&url
);
517 * Updates the menu that is by default at the right end of the toolbar.
519 * In true "simple by default" fashion, the menu only contains the most important
520 * and necessary actions to be able to use Dolphin. This is supposed to hold true even
521 * if the user does not know how to open a context menu. More advanced actions can be
522 * discovered through a sub-menu (@see KConfigWidgets::KHamburgerMenu::setMenuBarAdvertised()).
524 void updateHamburgerMenu();
527 * Is called if the user clicked an item in the Places Panel.
528 * Reloads the view if \a url is the current URL already, and changes the
529 * current URL otherwise.
531 void slotPlaceActivated(const QUrl
&url
);
534 * Is called if the another view has been activated by changing the current
535 * tab or activating another view in split-view mode.
537 * Activates the given view, which means that all menu actions are applied
538 * to this view. When having a split view setup, the nonactive view is
539 * usually shown in darker colors.
541 void activeViewChanged(DolphinViewContainer
*viewContainer
);
543 void closedTabsCountChanged(unsigned int count
);
546 * Is called if a new tab has been opened or a tab has been closed to
547 * enable/disable the tab actions.
549 void tabCountChanged(int count
);
552 * Updates the Window Title with the caption from the active view container
554 void updateWindowTitle();
557 * This slot is called when the user requested to unmount a removable media
558 * from the places menu
560 void slotStorageTearDownFromPlacesRequested(const QString
&mountPath
);
563 * This slot is called when the user requested to unmount a removable media
564 * _not_ from the dolphin's places menu (from the notification area for e.g.)
565 * This slot is basically connected to each removable device's
566 * Solid::StorageAccess::teardownRequested(const QString & udi)
567 * signal through the places panel.
569 void slotStorageTearDownExternallyRequested(const QString
&mountPath
);
572 * Is called when the view has finished loading the directory.
574 void slotDirectoryLoadingCompleted();
577 * Is called when the user middle clicks a toolbar button.
579 * Here middle clicking Back/Forward/Up/Home will open the resulting
580 * folder in a new tab.
582 void slotToolBarActionMiddleClicked(QAction
*action
);
585 * Is called before the Back popup menu is shown. This slot will populate
586 * the menu with history data
588 void slotAboutToShowBackPopupMenu();
591 * This slot is used by the Back Popup Menu to go back to a specific
592 * history index. The QAction::data will carry an int with the index
595 void slotGoBack(QAction
*action
);
598 * Middle clicking Back/Forward will open the resulting folder in a new tab.
600 void slotBackForwardActionMiddleClicked(QAction
*action
);
603 * Is called before the Forward popup menu is shown. This slot will populate
604 * the menu with history data
606 void slotAboutToShowForwardPopupMenu();
609 * This slot is used by the Forward Popup Menu to go forward to a specific
610 * history index. The QAction::data will carry an int with the index
613 void slotGoForward(QAction
*action
);
616 * Is called when configuring the keyboard shortcuts
618 void slotKeyBindings();
622 * Sets up the various menus and actions and connects them.
627 * Sets up the dock widgets and their panels.
629 void setupDockWidgets();
631 void updateFileAndEditActions();
632 void updateViewActions();
633 void updateGoActions();
636 * Connects the signals from the created DolphinView with
637 * the DolphinViewContainer \a container with the corresponding slots of
638 * the DolphinMainWindow. This method must be invoked each
639 * time a DolphinView has been created.
641 void connectViewSignals(DolphinViewContainer
*container
);
644 * Updates the text of the split action:
645 * If two views are shown, the text is set to "Split",
646 * otherwise the text is set to "Join". The icon
647 * is updated to match with the text and the currently active view.
649 void updateSplitAction();
652 * Sets the window sides the toolbar may be moved to based on toolbar contents.
654 void updateAllowedToolbarAreas();
656 bool isKompareInstalled() const;
659 * Creates an action for showing/hiding a panel, that is accessible
660 * in "Configure toolbars..." and "Configure shortcuts...". This is necessary
661 * as the action for toggling the dock visibility is done by Qt which
662 * is no KAction instance.
664 void createPanelAction(const QIcon
&icon
, const QKeySequence
&shortcut
, QAction
*dockAction
, const QString
&actionName
);
666 /** Adds "What's This?" texts to many widgets and StandardActions. */
667 void setupWhatsThis();
669 /** Returns preferred search tool as configured in "More Search Tools" menu. */
670 QPointer
<QAction
> preferredSearchTool();
673 * Adds this action to the mainWindow's toolbar and saves the change
674 * in the users ui configuration file.
675 * This method is only needed for migration and should be removed once we can expect
676 * that pretty much all users have been migrated. Remove in 2026 because that's when
677 * even the most risk-averse distros will already have been forced to upgrade.
678 * @return true if successful. Otherwise false.
680 bool addHamburgerMenuToToolbar();
682 /** Creates an action representing an item in the URL navigator history */
683 static QAction
*urlNavigatorHistoryAction(const KUrlNavigator
*urlNavigator
, int historyIndex
, QObject
*parent
= nullptr);
687 * Implements a custom error handling for the undo manager. This
688 * assures that all errors are shown in the status bar of Dolphin
689 * instead as modal error dialog with an OK button.
691 class UndoUiInterface
: public KIO::FileUndoManager::UiInterface
695 ~UndoUiInterface() override
;
696 void jobError(KIO::Job
*job
) override
;
699 KNewFileMenu
*m_newFileMenu
;
700 DolphinTabWidget
*m_tabWidget
;
701 DolphinViewContainer
*m_activeViewContainer
;
703 DolphinViewActionHandler
*m_actionHandler
;
704 DolphinRemoteEncoding
*m_remoteEncoding
;
705 QPointer
<DolphinSettingsDialog
> m_settingsDialog
;
706 DolphinBookmarkHandler
*m_bookmarkHandler
;
707 SelectionMode::ActionTextHelper
*m_actionTextHelper
;
709 KIO::OpenUrlJob
*m_lastHandleUrlOpenJob
;
711 TerminalPanel
*m_terminalPanel
;
712 PlacesPanel
*m_placesPanel
;
713 bool m_tearDownFromPlacesRequested
;
715 KToolBarPopupAction
*m_backAction
;
716 KToolBarPopupAction
*m_forwardAction
;
719 KFileItemActions m_fileItemActions
;
721 friend class DolphinMainWindowTest
;
724 inline DolphinViewContainer
*DolphinMainWindow::activeViewContainer() const
726 return m_activeViewContainer
;
729 inline KNewFileMenu
*DolphinMainWindow::newFileMenu() const
731 return m_newFileMenu
;
734 #endif // DOLPHIN_MAINWINDOW_H