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 "config-dolphin.h"
14 #include <KFileItemActions>
15 #include <kio/fileundomanager.h>
16 #include <kxmlguiwindow.h>
19 #include "panels/information/informationpanel.h"
29 typedef KIO::FileUndoManager::CommandType CommandType
;
31 class DolphinBookmarkHandler
;
32 class DolphinViewActionHandler
;
33 class DolphinSettingsDialog
;
34 class DolphinViewContainer
;
35 class DolphinRemoteEncoding
;
36 class DolphinTabWidget
;
42 class KToolBarPopupAction
;
52 * @short Main window for Dolphin.
54 * Handles the menus, toolbars and Dolphin views.
56 class DolphinMainWindow
: public KXmlGuiWindow
59 Q_CLASSINFO("D-Bus Interface", "org.kde.dolphin.MainWindow")
63 ~DolphinMainWindow() override
;
66 * Returns the currently active view.
67 * All menu actions are applied to this view. When
68 * having a split view setup, the nonactive view
69 * is usually shown in darker colors.
71 DolphinViewContainer
* activeViewContainer() const;
74 * Returns view container for all tabs
76 QVector
<DolphinViewContainer
*> viewContainers() const;
79 * Opens each directory in \p dirs in a separate tab. If \a splitView is set,
80 * 2 directories are collected within one tab.
81 * \pre \a dirs must contain at least one url.
83 void openDirectories(const QList
<QUrl
> &dirs
, bool splitView
);
86 * Opens the directories which contain the files \p files and selects all files.
87 * If \a splitView is set, 2 directories are collected within one tab.
88 * \pre \a files must contain at least one url.
90 void openFiles(const QList
<QUrl
>& files
, bool splitView
);
93 * Returns the 'Create New...' sub menu which also can be shared
94 * with other menus (e. g. a context menu).
96 KNewFileMenu
* newFileMenu() const;
99 * Augments Qt's build-in QMainWindow context menu to add
100 * Dolphin-specific actions, such as "unlock panels".
102 QMenu
*createPopupMenu() override
;
105 * Switch the window's view containers' locations to display the home path
106 * for any which are currently displaying a location corresponding to or
109 * This typically done after unmounting a disk at mountPath to ensure that
110 * the window is not displaying an invalid location.
112 void setViewsToHomeIfMountPathOpen(const QString
& mountPath
);
114 bool isFoldersPanelEnabled() const;
115 bool isInformationPanelEnabled() const;
119 * Opens each directory in \p dirs in a separate tab. If \a splitView is set,
120 * 2 directories are collected within one tab.
121 * \pre \a dirs must contain at least one url.
123 * @note this function is overloaded so that it is callable via DBus.
125 void openDirectories(const QStringList
&dirs
, bool splitView
);
128 * Opens the directories which contain the files \p files and selects all files.
129 * If \a splitView is set, 2 directories are collected within one tab.
130 * \pre \a files must contain at least one url.
132 * @note this is overloaded so that this function is callable via DBus.
134 void openFiles(const QStringList
&files
, bool splitView
);
137 * Tries to raise/activate the Dolphin window.
139 void activateWindow();
141 bool isActiveWindow();
144 * Determines if a URL is open in any tab.
145 * @note Use of QString instead of QUrl is required to be callable via DBus.
147 * @param url URL to look for
148 * @returns true if url is currently open in a tab, false otherwise.
150 bool isUrlOpen(const QString
&url
);
153 * Determines if a URL or it's parent is open in any tab.
154 * @note Use of QString instead of QUrl is required to be callable via DBus.
156 * @param url URL to look for
157 * @returns true if url or it's parent is currently open in a tab, false otherwise.
159 bool isUrlOrParentOpen(const QString
&url
);
163 * Pastes the clipboard data into the currently selected folder
164 * of the active view. If not exactly one folder is selected,
165 * no pasting is done at all.
167 void pasteIntoFolder();
170 * Implementation of the MainWindowAdaptor/QDBusAbstractAdaptor interface.
171 * Inform all affected dolphin components (panels, views) of an URL
174 void changeUrl(const QUrl
& url
);
177 * The current directory of the Terminal Panel has changed, probably because
178 * the user entered a 'cd' command. This slot calls changeUrl(url) and makes
179 * sure that the panel keeps the keyboard focus.
181 void slotTerminalDirectoryChanged(const QUrl
& url
);
183 /** Stores all settings and quits Dolphin. */
187 * Opens a new tab in the background showing the URL \a url.
189 void openNewTab(const QUrl
& url
);
192 * Opens a new tab showing the URL \a url and activate it.
194 void openNewTabAndActivate(const QUrl
&url
);
197 * Opens a new window showing the URL \a url.
199 void openNewWindow(const QUrl
&url
);
201 /** @see GeneralSettings::splitViewChanged() */
202 void slotSplitViewChanged();
206 * Is sent if the selection of the currently active view has
209 void selectionChanged(const KFileItemList
& selection
);
212 * Is sent if the url of the currently active view has
215 void urlChanged(const QUrl
& url
);
218 * Is emitted if information of an item is requested to be shown e. g. in the panel.
219 * If item is null, no item information request is pending.
221 void requestItemInfo(const KFileItem
& item
);
224 * It is emitted when in the current view, files are changed,
225 * or dirs have files/removed from them.
227 void fileItemsChanged(const KFileItemList
&changedFileItems
);
230 * Is emitted if the settings have been changed.
232 void settingsChanged();
235 /** @see QWidget::showEvent() */
236 void showEvent(QShowEvent
* event
) override
;
238 /** @see QMainWindow::closeEvent() */
239 void closeEvent(QCloseEvent
* event
) override
;
241 /** @see KMainWindow::saveProperties() */
242 void saveProperties(KConfigGroup
& group
) override
;
244 /** @see KMainWindow::readProperties() */
245 void readProperties(const KConfigGroup
& group
) override
;
247 /** Handles QWhatsThisClickedEvent and passes all others on. */
248 bool event(QEvent
* event
) override
;
249 /** Handles QWhatsThisClickedEvent and passes all others on. */
250 bool eventFilter(QObject
*, QEvent
*) override
;
252 /** Sets a sane initial window size **/
253 QSize
sizeHint() const override
;
257 * Calls the base method KXmlGuiWindow::saveNewToolbarConfig().
258 * Is also used to set toolbar constraints and UrlNavigator position
259 * based on the newly changed toolbar configuration.
261 void saveNewToolbarConfig() override
;
265 * Refreshes the views of the main window by recreating them according to
266 * the given Dolphin settings.
270 void clearStatusBar();
272 /** Updates the 'Create New...' sub menu. */
273 void updateNewMenu();
275 void createDirectory();
277 /** Shows the error message in the status bar of the active view. */
278 void showErrorMessage(const QString
& message
);
281 * Updates the state of the 'Undo' menu action dependent
282 * on the parameter \a available.
284 void slotUndoAvailable(bool available
);
286 /** Sets the text of the 'Undo' menu action to \a text. */
287 void slotUndoTextChanged(const QString
& text
);
289 /** Performs the current undo operation. */
293 * Copies all selected items to the clipboard and marks
298 /** Copies all selected items to the clipboard. */
301 /** Pastes the clipboard data to the active view. */
304 /** Replaces the URL navigator by a search box to find files. */
307 /** Updates the state of the search action according to the view container. */
308 void updateSearchAction();
311 * Updates the text of the paste action dependent on
312 * the number of items which are in the clipboard.
314 void updatePasteAction();
316 /** Selects all items from the active view. */
320 * Inverts the selection of all items of the active view:
321 * Selected items get nonselected and nonselected items get
324 void invertSelection();
327 * Switches between one and two views:
328 * If one view is visible, it will get split into two views.
329 * If already two views are visible, the active view gets closed.
331 void toggleSplitView();
333 /** Dedicated action to open the stash:/ ioslave in split view. */
334 void toggleSplitStash();
336 /** Reloads the currently active view. */
339 /** Stops the loading process for the currently active view. */
342 void enableStopAction();
343 void disableStopAction();
345 void showFilterBar();
346 void toggleFilterBar();
349 * Toggles between edit and browse mode of the navigation bar.
351 void toggleEditLocation();
354 * Switches to the edit mode of the navigation bar and selects
355 * the whole URL, so that it can be replaced by the user. If the edit mode is
356 * already active, it is assured that the navigation bar get focused.
358 void replaceLocation();
361 * Toggles the state of the panels between a locked and unlocked layout.
363 void togglePanelLockState();
366 * Is invoked if the Terminal panel got visible/invisible and takes care
367 * that the active view has the focus if the Terminal panel is invisible.
369 void slotTerminalPanelVisibilityChanged();
371 /** Goes back one step of the URL history. */
374 /** Goes forward one step of the URL history. */
377 /** Goes up one hierarchy of the current URL. */
380 /** Changes the location to the home URL. */
383 /** Open the previous URL in the URL history in a new tab. */
384 void goBackInNewTab();
386 /** Open the next URL in the URL history in a new tab. */
387 void goForwardInNewTab();
389 /** Open the URL one hierarchy above the current URL in a new tab. */
392 /** * Open the home URL in a new tab. */
393 void goHomeInNewTab();
395 /** Opens Kompare for 2 selected files. */
399 * Hides the menu bar if it is visible, makes the menu bar
400 * visible if it is hidden.
402 void toggleShowMenuBar();
404 /** Updates "Open Preferred Search Tool" action. */
405 void updateOpenPreferredSearchToolAction();
407 /** Opens preferred search tool for the current location. */
408 void openPreferredSearchTool();
410 /** Opens a terminal window for the current location. */
413 /** Opens terminal windows for the selected items' locations. */
414 void openTerminalHere();
416 /** Opens a terminal window for the URL. */
417 void openTerminalJob(const QUrl
& url
);
419 /** Focus a Terminal Panel. */
420 void focusTerminalPanel();
422 /** Opens the settings dialog for Dolphin. */
425 /** Updates the state of the 'Show Full Location' action. */
426 void slotEditableStateChanged(bool editable
);
429 * Updates the state of the 'Edit' menu actions and emits
430 * the signal selectionChanged().
432 void slotSelectionChanged(const KFileItemList
& selection
);
435 * Updates the state of the 'Back' and 'Forward' menu
436 * actions corresponding to the current history.
438 void updateHistory();
440 /** Updates the state of the 'Show filter bar' menu action. */
441 void updateFilterBarAction(bool show
);
443 /** Open a new main window. */
444 void openNewMainWindow();
447 * Opens a new view with the current URL that is part of a tab and
450 void openNewActivatedTab();
453 * Adds the current URL as an entry to the Places panel
458 * Opens the selected folder in a new tab.
463 * Opens the selected folder in a new window.
465 void openInNewWindow();
468 * Show the target of the selected symlink
473 * Indicates in the statusbar that the execution of the command \a command
476 void showCommand(CommandType command
);
479 * If the URL can be listed, open it in the current view, otherwise
480 * run it through KRun.
482 void handleUrl(const QUrl
& url
);
485 * Is invoked when the write state of a folder has been changed and
486 * enables/disables the "Create New..." menu entry.
488 void slotWriteStateChanged(bool isFolderWritable
);
491 * Opens the context menu on the current mouse position.
492 * @pos Position in screen coordinates.
493 * @item File item context. If item is null, the context menu
494 * should be applied to \a url.
495 * @selectedItems The selected items for which the context menu
496 * is opened. This list generally includes \a item.
497 * @url URL which contains \a item.
499 void openContextMenu(const QPoint
& pos
, const KFileItem
& item
, const KFileItemList
&selectedItems
, const QUrl
& url
);
502 * Updates the menu that is by default at the right end of the toolbar.
504 * In true "simple by default" fashion, the menu only contains the most important
505 * and necessary actions to be able to use Dolphin. This is supposed to hold true even
506 * if the user does not know how to open a context menu. More advanced actions can be
507 * discovered through a sub-menu (@see KConfigWidgets::KHamburgerMenu::setMenuBarAdvertised()).
509 void updateHamburgerMenu();
512 * Is called if the user clicked an item in the Places Panel.
513 * Reloads the view if \a url is the current URL already, and changes the
514 * current URL otherwise.
516 void slotPlaceActivated(const QUrl
& url
);
519 * Is called if the another view has been activated by changing the current
520 * tab or activating another view in split-view mode.
522 * Activates the given view, which means that all menu actions are applied
523 * to this view. When having a split view setup, the nonactive view is
524 * usually shown in darker colors.
526 void activeViewChanged(DolphinViewContainer
* viewContainer
);
528 void closedTabsCountChanged(unsigned int count
);
531 * Is called if a new tab has been opened or a tab has been closed to
532 * enable/disable the tab actions.
534 void tabCountChanged(int count
);
537 * Updates the Window Title with the caption from the active view container
539 void updateWindowTitle();
542 * This slot is called when the user requested to unmount a removable media
543 * from the places menu
545 void slotStorageTearDownFromPlacesRequested(const QString
& mountPath
);
548 * This slot is called when the user requested to unmount a removable media
549 * _not_ from the dolphin's places menu (from the notification area for e.g.)
550 * This slot is basically connected to each removable device's
551 * Solid::StorageAccess::teardownRequested(const QString & udi)
552 * signal through the places panel.
554 void slotStorageTearDownExternallyRequested(const QString
& mountPath
);
557 * Is called when the view has finished loading the directory.
559 void slotDirectoryLoadingCompleted();
562 * Is called when the user middle clicks a toolbar button.
564 * Here middle clicking Back/Forward/Up/Home will open the resulting
565 * folder in a new tab.
567 void slotToolBarActionMiddleClicked(QAction
*action
);
570 * Is called before the Back popup menu is shown. This slot will populate
571 * the menu with history data
573 void slotAboutToShowBackPopupMenu();
576 * This slot is used by the Back Popup Menu to go back to a specific
577 * history index. The QAction::data will carry an int with the index
580 void slotGoBack(QAction
* action
);
583 * Middle clicking Back/Forward will open the resulting folder in a new tab.
585 void slotBackForwardActionMiddleClicked(QAction
*action
);
588 * Is called before the Forward popup menu is shown. This slot will populate
589 * the menu with history data
591 void slotAboutToShowForwardPopupMenu();
594 * This slot is used by the Forward Popup Menu to go forward to a specific
595 * history index. The QAction::data will carry an int with the index
598 void slotGoForward(QAction
* action
);
601 * Is called when configuring the keyboard shortcuts
603 void slotKeyBindings();
607 * Sets up the various menus and actions and connects them.
612 * Sets up the dock widgets and their panels.
614 void setupDockWidgets();
616 void updateFileAndEditActions();
617 void updateViewActions();
618 void updateGoActions();
621 * Connects the signals from the created DolphinView with
622 * the DolphinViewContainer \a container with the corresponding slots of
623 * the DolphinMainWindow. This method must be invoked each
624 * time a DolphinView has been created.
626 void connectViewSignals(DolphinViewContainer
* container
);
629 * Updates the text of the split action:
630 * If two views are shown, the text is set to "Split",
631 * otherwise the text is set to "Join". The icon
632 * is updated to match with the text and the currently active view.
634 void updateSplitAction();
637 * Sets the window sides the toolbar may be moved to based on toolbar contents.
639 void updateAllowedToolbarAreas();
641 bool isKompareInstalled() const;
644 * Creates an action for showing/hiding a panel, that is accessible
645 * in "Configure toolbars..." and "Configure shortcuts...". This is necessary
646 * as the action for toggling the dock visibility is done by Qt which
647 * is no KAction instance.
649 void createPanelAction(const QIcon
&icon
,
650 const QKeySequence
& shortcut
,
652 const QString
& actionName
);
654 /** Adds "What's This?" texts to many widgets and StandardActions. */
655 void setupWhatsThis();
657 /** Returns preferred search tool as configured in "More Search Tools" menu. */
658 QPointer
<QAction
> preferredSearchTool();
661 * Adds this action to the mainWindow's toolbar and saves the change
662 * in the users ui configuration file.
663 * This method is only needed for migration and should be removed once we can expect
664 * that pretty much all users have been migrated. Remove in 2026 because that's when
665 * even the most risk-averse distros will already have been forced to upgrade.
666 * @return true if successful. Otherwise false.
668 bool addHamburgerMenuToToolbar();
670 /** Creates an action representing an item in the URL navigator history */
671 static QAction
*urlNavigatorHistoryAction(const KUrlNavigator
*urlNavigator
, int historyIndex
, QObject
*parent
= nullptr);
675 * Implements a custom error handling for the undo manager. This
676 * assures that all errors are shown in the status bar of Dolphin
677 * instead as modal error dialog with an OK button.
679 class UndoUiInterface
: public KIO::FileUndoManager::UiInterface
683 ~UndoUiInterface() override
;
684 void jobError(KIO::Job
* job
) override
;
687 KNewFileMenu
* m_newFileMenu
;
688 KHelpMenu
* m_helpMenu
;
689 DolphinTabWidget
* m_tabWidget
;
690 DolphinViewContainer
* m_activeViewContainer
;
692 DolphinViewActionHandler
* m_actionHandler
;
693 DolphinRemoteEncoding
* m_remoteEncoding
;
694 QPointer
<DolphinSettingsDialog
> m_settingsDialog
;
695 DolphinBookmarkHandler
* m_bookmarkHandler
;
697 // Members for the toolbar menu that is shown when the menubar is hidden:
698 QToolButton
* m_controlButton
;
699 QTimer
* m_updateToolBarTimer
;
701 KIO::OpenUrlJob
*m_lastHandleUrlOpenJob
;
703 TerminalPanel
* m_terminalPanel
;
704 PlacesPanel
* m_placesPanel
;
705 bool m_tearDownFromPlacesRequested
;
707 KToolBarPopupAction
* m_backAction
;
708 KToolBarPopupAction
* m_forwardAction
;
711 KFileItemActions m_fileItemActions
;
713 friend class DolphinMainWindowTest
;
716 inline DolphinViewContainer
* DolphinMainWindow::activeViewContainer() const
718 return m_activeViewContainer
;
721 inline KNewFileMenu
* DolphinMainWindow::newFileMenu() const
723 return m_newFileMenu
;
726 #endif // DOLPHIN_MAINWINDOW_H