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-baloo.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();
142 * Determines if a URL is open in any tab.
143 * @note Use of QString instead of QUrl is required to be callable via DBus.
145 * @param url URL to look for
146 * @returns true if url is currently open in a tab, false otherwise.
148 bool isUrlOpen(const QString
&url
);
152 * Pastes the clipboard data into the currently selected folder
153 * of the active view. If not exactly one folder is selected,
154 * no pasting is done at all.
156 void pasteIntoFolder();
159 * Implementation of the MainWindowAdaptor/QDBusAbstractAdaptor interface.
160 * Inform all affected dolphin components (panels, views) of an URL
163 void changeUrl(const QUrl
& url
);
166 * The current directory of the Terminal Panel has changed, probably because
167 * the user entered a 'cd' command. This slot calls changeUrl(url) and makes
168 * sure that the panel keeps the keyboard focus.
170 void slotTerminalDirectoryChanged(const QUrl
& url
);
172 /** Stores all settings and quits Dolphin. */
176 * Opens a new tab in the background showing the URL \a url.
178 void openNewTab(const QUrl
& url
);
181 * Opens a new tab showing the URL \a url and activate it.
183 void openNewTabAndActivate(const QUrl
&url
);
186 * Opens a new window showing the URL \a url.
188 void openNewWindow(const QUrl
&url
);
190 /** @see GeneralSettings::splitViewChanged() */
191 void slotSplitViewChanged();
195 * Is sent if the selection of the currently active view has
198 void selectionChanged(const KFileItemList
& selection
);
201 * Is sent if the url of the currently active view has
204 void urlChanged(const QUrl
& url
);
207 * Is emitted if information of an item is requested to be shown e. g. in the panel.
208 * If item is null, no item information request is pending.
210 void requestItemInfo(const KFileItem
& item
);
213 * It is emitted when in the current view, files are changed,
214 * or dirs have files/removed from them.
216 void fileItemsChanged(const KFileItemList
&changedFileItems
);
219 * Is emitted if the settings have been changed.
221 void settingsChanged();
224 /** @see QWidget::showEvent() */
225 void showEvent(QShowEvent
* event
) override
;
227 /** @see QMainWindow::closeEvent() */
228 void closeEvent(QCloseEvent
* event
) override
;
230 /** @see KMainWindow::saveProperties() */
231 void saveProperties(KConfigGroup
& group
) override
;
233 /** @see KMainWindow::readProperties() */
234 void readProperties(const KConfigGroup
& group
) override
;
236 /** Handles QWhatsThisClickedEvent and passes all others on. */
237 bool event(QEvent
* event
) override
;
238 /** Handles QWhatsThisClickedEvent and passes all others on. */
239 bool eventFilter(QObject
*, QEvent
*) override
;
241 /** Sets a sane initial window size **/
242 QSize
sizeHint() const override
;
246 * Calls the base method KXmlGuiWindow::saveNewToolbarConfig().
247 * Is also used to set toolbar constraints and UrlNavigator position
248 * based on the newly changed toolbar configuration.
250 void saveNewToolbarConfig() override
;
254 * Refreshes the views of the main window by recreating them according to
255 * the given Dolphin settings.
259 void clearStatusBar();
261 /** Updates the 'Create New...' sub menu. */
262 void updateNewMenu();
264 void createDirectory();
266 /** Shows the error message in the status bar of the active view. */
267 void showErrorMessage(const QString
& message
);
270 * Updates the state of the 'Undo' menu action dependent
271 * on the parameter \a available.
273 void slotUndoAvailable(bool available
);
275 /** Sets the text of the 'Undo' menu action to \a text. */
276 void slotUndoTextChanged(const QString
& text
);
278 /** Performs the current undo operation. */
282 * Copies all selected items to the clipboard and marks
287 /** Copies all selected items to the clipboard. */
290 /** Pastes the clipboard data to the active view. */
293 /** Replaces the URL navigator by a search box to find files. */
296 /** Updates the state of the search action according to the view container. */
297 void updateSearchAction();
300 * Updates the text of the paste action dependent on
301 * the number of items which are in the clipboard.
303 void updatePasteAction();
305 /** Selects all items from the active view. */
309 * Inverts the selection of all items of the active view:
310 * Selected items get nonselected and nonselected items get
313 void invertSelection();
316 * Switches between one and two views:
317 * If one view is visible, it will get split into two views.
318 * If already two views are visible, the active view gets closed.
320 void toggleSplitView();
322 /** Dedicated action to open the stash:/ ioslave in split view. */
323 void toggleSplitStash();
325 /** Reloads the currently active view. */
328 /** Stops the loading process for the currently active view. */
331 void enableStopAction();
332 void disableStopAction();
334 void showFilterBar();
335 void toggleFilterBar();
338 * Toggles between edit and browse mode of the navigation bar.
340 void toggleEditLocation();
343 * Switches to the edit mode of the navigation bar and selects
344 * the whole URL, so that it can be replaced by the user. If the edit mode is
345 * already active, it is assured that the navigation bar get focused.
347 void replaceLocation();
350 * Toggles the state of the panels between a locked and unlocked layout.
352 void togglePanelLockState();
355 * Is invoked if the Terminal panel got visible/invisible and takes care
356 * that the active view has the focus if the Terminal panel is invisible.
358 void slotTerminalPanelVisibilityChanged();
360 /** Goes back one step of the URL history. */
363 /** Goes forward one step of the URL history. */
366 /** Goes up one hierarchy of the current URL. */
369 /** Changes the location to the home URL. */
372 /** Open the previous URL in the URL history in a new tab. */
373 void goBackInNewTab();
375 /** Open the next URL in the URL history in a new tab. */
376 void goForwardInNewTab();
378 /** Open the URL one hierarchy above the current URL in a new tab. */
381 /** * Open the home URL in a new tab. */
382 void goHomeInNewTab();
384 /** Opens Kompare for 2 selected files. */
388 * Hides the menu bar if it is visible, makes the menu bar
389 * visible if it is hidden.
391 void toggleShowMenuBar();
393 /** Updates "Open Preferred Search Tool" action. */
394 void updateOpenPreferredSearchToolAction();
396 /** Opens preferred search tool for the current location. */
397 void openPreferredSearchTool();
399 /** Opens a terminal window for the current location. */
402 /** Focus a Terminal Panel. */
403 void focusTerminalPanel();
405 /** Opens the settings dialog for Dolphin. */
408 /** Updates the state of the 'Show Full Location' action. */
409 void slotEditableStateChanged(bool editable
);
412 * Updates the state of the 'Edit' menu actions and emits
413 * the signal selectionChanged().
415 void slotSelectionChanged(const KFileItemList
& selection
);
418 * Updates the state of the 'Back' and 'Forward' menu
419 * actions corresponding to the current history.
421 void updateHistory();
423 /** Updates the state of the 'Show filter bar' menu action. */
424 void updateFilterBarAction(bool show
);
426 /** Open a new main window. */
427 void openNewMainWindow();
430 * Opens a new view with the current URL that is part of a tab and
433 void openNewActivatedTab();
436 * Adds the current URL as an entry to the Places panel
441 * Opens the selected folder in a new tab.
446 * Opens the selected folder in a new window.
448 void openInNewWindow();
451 * Show the target of the selected symlink
456 * Indicates in the statusbar that the execution of the command \a command
459 void showCommand(CommandType command
);
462 * If the URL can be listed, open it in the current view, otherwise
463 * run it through KRun.
465 void handleUrl(const QUrl
& url
);
468 * Is invoked when the write state of a folder has been changed and
469 * enables/disables the "Create New..." menu entry.
471 void slotWriteStateChanged(bool isFolderWritable
);
474 * Opens the context menu on the current mouse position.
475 * @pos Position in screen coordinates.
476 * @item File item context. If item is null, the context menu
477 * should be applied to \a url.
478 * @selectedItems The selected items for which the context menu
479 * is opened. This list generally includes \a item.
480 * @url URL which contains \a item.
482 void openContextMenu(const QPoint
& pos
, const KFileItem
& item
, const KFileItemList
&selectedItems
, const QUrl
& url
);
485 * Updates the menu that is by default at the right end of the toolbar.
487 * In true "simple by default" fashion, the menu only contains the most important
488 * and necessary actions to be able to use Dolphin. This is supposed to hold true even
489 * if the user does not know how to open a context menu. More advanced actions can be
490 * discovered through a sub-menu (@see KConfigWidgets::KHamburgerMenu::setMenuBarAdvertised()).
492 void updateHamburgerMenu();
495 * Is called if the user clicked an item in the Places Panel.
496 * Reloads the view if \a url is the current URL already, and changes the
497 * current URL otherwise.
499 void slotPlaceActivated(const QUrl
& url
);
502 * Is called if the another view has been activated by changing the current
503 * tab or activating another view in split-view mode.
505 * Activates the given view, which means that all menu actions are applied
506 * to this view. When having a split view setup, the nonactive view is
507 * usually shown in darker colors.
509 void activeViewChanged(DolphinViewContainer
* viewContainer
);
511 void closedTabsCountChanged(unsigned int count
);
514 * Is called if a new tab has been opened or a tab has been closed to
515 * enable/disable the tab actions.
517 void tabCountChanged(int count
);
520 * Updates the Window Title with the caption from the active view container
522 void updateWindowTitle();
525 * This slot is called when the user requested to unmount a removable media
526 * from the places menu
528 void slotStorageTearDownFromPlacesRequested(const QString
& mountPath
);
531 * This slot is called when the user requested to unmount a removable media
532 * _not_ from the dolphin's places menu (from the notification area for e.g.)
533 * This slot is basically connected to each removable device's
534 * Solid::StorageAccess::teardownRequested(const QString & udi)
535 * signal through the places panel.
537 void slotStorageTearDownExternallyRequested(const QString
& mountPath
);
540 * Is called when the view has finished loading the directory.
542 void slotDirectoryLoadingCompleted();
545 * Is called when the user middle clicks a toolbar button.
547 * Here middle clicking Back/Forward/Up/Home will open the resulting
548 * folder in a new tab.
550 void slotToolBarActionMiddleClicked(QAction
*action
);
553 * Is called before the Back popup menu is shown. This slot will populate
554 * the menu with history data
556 void slotAboutToShowBackPopupMenu();
559 * This slot is used by the Back Popup Menu to go back to a specific
560 * history index. The QAction::data will carry an int with the index
563 void slotGoBack(QAction
* action
);
566 * Middle clicking Back/Forward will open the resulting folder in a new tab.
568 void slotBackForwardActionMiddleClicked(QAction
*action
);
571 * Is called before the Forward popup menu is shown. This slot will populate
572 * the menu with history data
574 void slotAboutToShowForwardPopupMenu();
577 * This slot is used by the Forward Popup Menu to go forward to a specific
578 * history index. The QAction::data will carry an int with the index
581 void slotGoForward(QAction
* action
);
584 * Is called when configuring the keyboard shortcuts
586 void slotKeyBindings();
590 * Sets up the various menus and actions and connects them.
595 * Sets up the dock widgets and their panels.
597 void setupDockWidgets();
599 void updateFileAndEditActions();
600 void updateViewActions();
601 void updateGoActions();
604 * Connects the signals from the created DolphinView with
605 * the DolphinViewContainer \a container with the corresponding slots of
606 * the DolphinMainWindow. This method must be invoked each
607 * time a DolphinView has been created.
609 void connectViewSignals(DolphinViewContainer
* container
);
612 * Updates the text of the split action:
613 * If two views are shown, the text is set to "Split",
614 * otherwise the text is set to "Join". The icon
615 * is updated to match with the text and the currently active view.
617 void updateSplitAction();
620 * Sets the window sides the toolbar may be moved to based on toolbar contents.
622 void updateAllowedToolbarAreas();
624 bool isKompareInstalled() const;
627 * Creates an action for showing/hiding a panel, that is accessible
628 * in "Configure toolbars..." and "Configure shortcuts...". This is necessary
629 * as the action for toggling the dock visibility is done by Qt which
630 * is no KAction instance.
632 void createPanelAction(const QIcon
&icon
,
633 const QKeySequence
& shortcut
,
635 const QString
& actionName
);
637 /** Adds "What's This?" texts to many widgets and StandardActions. */
638 void setupWhatsThis();
640 /** Returns preferred search tool as configured in "More Search Tools" menu. */
641 QPointer
<QAction
> preferredSearchTool();
644 * Adds this action to the mainWindow's toolbar and saves the change
645 * in the users ui configuration file.
646 * This method is only needed for migration and should be removed once we can expect
647 * that pretty much all users have been migrated. Remove in 2026 because that's when
648 * even the most risk-averse distros will already have been forced to upgrade.
649 * @return true if successful. Otherwise false.
651 bool addHamburgerMenuToToolbar();
653 /** Creates an action representing an item in the URL navigator history */
654 static QAction
*urlNavigatorHistoryAction(const KUrlNavigator
*urlNavigator
, int historyIndex
, QObject
*parent
= nullptr);
658 * Implements a custom error handling for the undo manager. This
659 * assures that all errors are shown in the status bar of Dolphin
660 * instead as modal error dialog with an OK button.
662 class UndoUiInterface
: public KIO::FileUndoManager::UiInterface
666 ~UndoUiInterface() override
;
667 void jobError(KIO::Job
* job
) override
;
670 KNewFileMenu
* m_newFileMenu
;
671 KHelpMenu
* m_helpMenu
;
672 DolphinTabWidget
* m_tabWidget
;
673 DolphinViewContainer
* m_activeViewContainer
;
675 DolphinViewActionHandler
* m_actionHandler
;
676 DolphinRemoteEncoding
* m_remoteEncoding
;
677 QPointer
<DolphinSettingsDialog
> m_settingsDialog
;
678 DolphinBookmarkHandler
* m_bookmarkHandler
;
680 // Members for the toolbar menu that is shown when the menubar is hidden:
681 QToolButton
* m_controlButton
;
682 QTimer
* m_updateToolBarTimer
;
684 KIO::OpenUrlJob
*m_lastHandleUrlOpenJob
;
686 TerminalPanel
* m_terminalPanel
;
687 PlacesPanel
* m_placesPanel
;
688 bool m_tearDownFromPlacesRequested
;
690 KToolBarPopupAction
* m_backAction
;
691 KToolBarPopupAction
* m_forwardAction
;
694 KFileItemActions m_fileItemActions
;
698 inline DolphinViewContainer
* DolphinMainWindow::activeViewContainer() const
700 return m_activeViewContainer
;
703 inline KNewFileMenu
* DolphinMainWindow::newFileMenu() const
705 return m_newFileMenu
;
708 #endif // DOLPHIN_MAINWINDOW_H