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 "dolphintabwidget.h"
13 #include "selectionmode/bottombar.h"
14 #include "config-dolphin.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
;
43 class KToolBarPopupAction
;
51 namespace SelectionMode
{
52 class ActionTextHelper
;
56 * @short Main window for Dolphin.
58 * Handles the menus, toolbars and Dolphin views.
60 class DolphinMainWindow
: public KXmlGuiWindow
63 Q_CLASSINFO("D-Bus Interface", "org.kde.dolphin.MainWindow")
67 ~DolphinMainWindow() override
;
70 * Returns the currently active view.
71 * All menu actions are applied to this view. When
72 * having a split view setup, the nonactive view
73 * is usually shown in darker colors.
75 DolphinViewContainer
* activeViewContainer() const;
78 * Returns view container for all tabs
80 QVector
<DolphinViewContainer
*> viewContainers() const;
83 * Opens each directory in \p dirs in a separate tab. If \a splitView is set,
84 * 2 directories are collected within one tab.
85 * \pre \a dirs must contain at least one url.
87 void openDirectories(const QList
<QUrl
> &dirs
, bool splitView
);
90 * Opens the directories which contain the files \p files and selects all files.
91 * If \a splitView is set, 2 directories are collected within one tab.
92 * \pre \a files must contain at least one url.
94 void openFiles(const QList
<QUrl
>& files
, bool splitView
);
97 * Returns the 'Create New...' sub menu which also can be shared
98 * with other menus (e. g. a context menu).
100 KNewFileMenu
* newFileMenu() const;
103 * Augments Qt's build-in QMainWindow context menu to add
104 * Dolphin-specific actions, such as "unlock panels".
106 QMenu
*createPopupMenu() override
;
109 * Switch the window's view containers' locations to display the home path
110 * for any which are currently displaying a location corresponding to or
113 * This typically done after unmounting a disk at mountPath to ensure that
114 * the window is not displaying an invalid location.
116 void setViewsToHomeIfMountPathOpen(const QString
& mountPath
);
118 bool isFoldersPanelEnabled() const;
119 bool isInformationPanelEnabled() const;
123 * Opens each directory in \p dirs in a separate tab. If \a splitView is set,
124 * 2 directories are collected within one tab.
125 * \pre \a dirs must contain at least one url.
127 * @note this function is overloaded so that it is callable via DBus.
129 void openDirectories(const QStringList
&dirs
, bool splitView
);
132 * Opens the directories which contain the files \p files and selects all files.
133 * If \a splitView is set, 2 directories are collected within one tab.
134 * \pre \a files must contain at least one url.
136 * @note this is overloaded so that this function is callable via DBus.
138 void openFiles(const QStringList
&files
, bool splitView
);
141 * Tries to raise/activate the Dolphin window.
143 void activateWindow();
145 bool isActiveWindow();
148 * Determines if a URL is open in any tab.
149 * @note Use of QString instead of QUrl is required to be callable via DBus.
151 * @param url URL to look for
152 * @returns true if url is currently open in a tab, false otherwise.
154 bool isUrlOpen(const QString
&url
);
157 * Determines if a URL or it's parent is open in any tab.
158 * @note Use of QString instead of QUrl is required to be callable via DBus.
160 * @param url URL to look for
161 * @returns true if url or it's parent is currently open in a tab, false otherwise.
163 bool isUrlOrParentOpen(const QString
&url
);
167 * Pastes the clipboard data into the currently selected folder
168 * of the active view. If not exactly one folder is selected,
169 * no pasting is done at all.
171 void pasteIntoFolder();
174 * Implementation of the MainWindowAdaptor/QDBusAbstractAdaptor interface.
175 * Inform all affected dolphin components (panels, views) of an URL
178 void changeUrl(const QUrl
& url
);
181 * The current directory of the Terminal Panel has changed, probably because
182 * the user entered a 'cd' command. This slot calls changeUrl(url) and makes
183 * sure that the panel keeps the keyboard focus.
185 void slotTerminalDirectoryChanged(const QUrl
& url
);
187 /** Stores all settings and quits Dolphin. */
191 * Opens a new tab in the background showing the URL \a url.
193 void openNewTab(const QUrl
& url
);
196 * Opens a new tab showing the URL \a url and activate it.
198 void openNewTabAndActivate(const QUrl
&url
);
201 * Opens a new window showing the URL \a url.
203 void openNewWindow(const QUrl
&url
);
205 /** @see GeneralSettings::splitViewChanged() */
206 void slotSplitViewChanged();
210 * Is sent if the selection of the currently active view has
213 void selectionChanged(const KFileItemList
& selection
);
216 * Is sent if the url of the currently active view has
219 void urlChanged(const QUrl
& url
);
222 * Is emitted if information of an item is requested to be shown e. g. in the panel.
223 * If item is null, no item information request is pending.
225 void requestItemInfo(const KFileItem
& item
);
228 * It is emitted when in the current view, files are changed,
229 * or dirs have files/removed from them.
231 void fileItemsChanged(const KFileItemList
&changedFileItems
);
234 * Is emitted if the settings have been changed.
236 void settingsChanged();
239 /** @see QWidget::showEvent() */
240 void showEvent(QShowEvent
* event
) override
;
242 /** @see QMainWindow::closeEvent() */
243 void closeEvent(QCloseEvent
* event
) override
;
245 /** @see KMainWindow::saveProperties() */
246 void saveProperties(KConfigGroup
& group
) override
;
248 /** @see KMainWindow::readProperties() */
249 void readProperties(const KConfigGroup
& group
) override
;
251 /** Handles QWhatsThisClickedEvent and passes all others on. */
252 bool event(QEvent
* event
) override
;
253 /** Handles QWhatsThisClickedEvent and passes all others on. */
254 bool eventFilter(QObject
*, QEvent
*) 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
,
665 const QKeySequence
& shortcut
,
667 const QString
& actionName
);
669 /** Adds "What's This?" texts to many widgets and StandardActions. */
670 void setupWhatsThis();
672 /** Returns preferred search tool as configured in "More Search Tools" menu. */
673 QPointer
<QAction
> preferredSearchTool();
676 * Adds this action to the mainWindow's toolbar and saves the change
677 * in the users ui configuration file.
678 * This method is only needed for migration and should be removed once we can expect
679 * that pretty much all users have been migrated. Remove in 2026 because that's when
680 * even the most risk-averse distros will already have been forced to upgrade.
681 * @return true if successful. Otherwise false.
683 bool addHamburgerMenuToToolbar();
685 /** Creates an action representing an item in the URL navigator history */
686 static QAction
*urlNavigatorHistoryAction(const KUrlNavigator
*urlNavigator
, int historyIndex
, QObject
*parent
= nullptr);
690 * Implements a custom error handling for the undo manager. This
691 * assures that all errors are shown in the status bar of Dolphin
692 * instead as modal error dialog with an OK button.
694 class UndoUiInterface
: public KIO::FileUndoManager::UiInterface
698 ~UndoUiInterface() override
;
699 void jobError(KIO::Job
* job
) override
;
702 KNewFileMenu
* m_newFileMenu
;
703 KHelpMenu
* m_helpMenu
;
704 DolphinTabWidget
* m_tabWidget
;
705 DolphinViewContainer
* m_activeViewContainer
;
707 DolphinViewActionHandler
* m_actionHandler
;
708 DolphinRemoteEncoding
* m_remoteEncoding
;
709 QPointer
<DolphinSettingsDialog
> m_settingsDialog
;
710 DolphinBookmarkHandler
* m_bookmarkHandler
;
711 SelectionMode::ActionTextHelper
* m_actionTextHelper
;
713 // Members for the toolbar menu that is shown when the menubar is hidden:
714 QToolButton
* m_controlButton
;
715 QTimer
* m_updateToolBarTimer
;
717 KIO::OpenUrlJob
*m_lastHandleUrlOpenJob
;
719 TerminalPanel
* m_terminalPanel
;
720 PlacesPanel
* m_placesPanel
;
721 bool m_tearDownFromPlacesRequested
;
723 KToolBarPopupAction
* m_backAction
;
724 KToolBarPopupAction
* m_forwardAction
;
727 KFileItemActions m_fileItemActions
;
729 friend class DolphinMainWindowTest
;
732 inline DolphinViewContainer
* DolphinMainWindow::activeViewContainer() const
734 return m_activeViewContainer
;
737 inline KNewFileMenu
* DolphinMainWindow::newFileMenu() const
739 return m_newFileMenu
;
742 #endif // DOLPHIN_MAINWINDOW_H