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 * Switch the window's view containers' locations to display the home path
100 * for any which are currently displaying a location corresponding to or
103 * This typically done after unmounting a disk at mountPath to ensure that
104 * the window is not displaying an invalid location.
106 void setViewsToHomeIfMountPathOpen(const QString
& mountPath
);
108 bool isFoldersPanelEnabled() const;
109 bool isInformationPanelEnabled() const;
113 * Opens each directory in \p dirs in a separate tab. If \a splitView is set,
114 * 2 directories are collected within one tab.
115 * \pre \a dirs must contain at least one url.
117 * @note this function is overloaded so that it is callable via DBus.
119 void openDirectories(const QStringList
&dirs
, bool splitView
);
122 * Opens the directories which contain the files \p files and selects all files.
123 * If \a splitView is set, 2 directories are collected within one tab.
124 * \pre \a files must contain at least one url.
126 * @note this is overloaded so that this function is callable via DBus.
128 void openFiles(const QStringList
&files
, bool splitView
);
131 * Tries to raise/activate the Dolphin window.
133 void activateWindow();
136 * Determines if a URL is open in any tab.
137 * @note Use of QString instead of QUrl is required to be callable via DBus.
139 * @param url URL to look for
140 * @returns true if url is currently open in a tab, false otherwise.
142 bool isUrlOpen(const QString
&url
);
146 * Pastes the clipboard data into the currently selected folder
147 * of the active view. If not exactly one folder is selected,
148 * no pasting is done at all.
150 void pasteIntoFolder();
153 * Implementation of the MainWindowAdaptor/QDBusAbstractAdaptor interface.
154 * Inform all affected dolphin components (panels, views) of an URL
157 void changeUrl(const QUrl
& url
);
160 * The current directory of the Terminal Panel has changed, probably because
161 * the user entered a 'cd' command. This slot calls changeUrl(url) and makes
162 * sure that the panel keeps the keyboard focus.
164 void slotTerminalDirectoryChanged(const QUrl
& url
);
166 /** Stores all settings and quits Dolphin. */
170 * Opens a new tab in the background showing the URL \a url.
172 void openNewTab(const QUrl
& url
);
175 * Opens a new tab showing the URL \a url and activate it.
177 void openNewTabAndActivate(const QUrl
&url
);
180 * Opens a new window showing the URL \a url.
182 void openNewWindow(const QUrl
&url
);
184 /** @see GeneralSettings::splitViewChanged() */
185 void slotSplitViewChanged();
189 * Is sent if the selection of the currently active view has
192 void selectionChanged(const KFileItemList
& selection
);
195 * Is sent if the url of the currently active view has
198 void urlChanged(const QUrl
& url
);
201 * Is emitted if information of an item is requested to be shown e. g. in the panel.
202 * If item is null, no item information request is pending.
204 void requestItemInfo(const KFileItem
& item
);
207 * It is emitted when in the current view, files are changed,
208 * or dirs have files/removed from them.
210 void fileItemsChanged(const KFileItemList
&changedFileItems
);
213 * Is emitted if the settings have been changed.
215 void settingsChanged();
218 /** @see QWidget::showEvent() */
219 void showEvent(QShowEvent
* event
) override
;
221 /** @see QMainWindow::closeEvent() */
222 void closeEvent(QCloseEvent
* event
) override
;
224 /** @see KMainWindow::saveProperties() */
225 void saveProperties(KConfigGroup
& group
) override
;
227 /** @see KMainWindow::readProperties() */
228 void readProperties(const KConfigGroup
& group
) override
;
230 /** Handles QWhatsThisClickedEvent and passes all others on. */
231 bool event(QEvent
* event
) override
;
232 /** Handles QWhatsThisClickedEvent and passes all others on. */
233 bool eventFilter(QObject
*, QEvent
*) override
;
235 /** Sets a sane initial window size **/
236 QSize
sizeHint() const override
;
240 * Calls the base method KXmlGuiWindow::saveNewToolbarConfig().
241 * Is also used to set toolbar constraints and UrlNavigator position
242 * based on the newly changed toolbar configuration.
244 void saveNewToolbarConfig() override
;
248 * Refreshes the views of the main window by recreating them according to
249 * the given Dolphin settings.
253 void clearStatusBar();
255 /** Updates the 'Create New...' sub menu. */
256 void updateNewMenu();
258 void createDirectory();
260 /** Shows the error message in the status bar of the active view. */
261 void showErrorMessage(const QString
& message
);
264 * Updates the state of the 'Undo' menu action dependent
265 * on the parameter \a available.
267 void slotUndoAvailable(bool available
);
269 /** Sets the text of the 'Undo' menu action to \a text. */
270 void slotUndoTextChanged(const QString
& text
);
272 /** Performs the current undo operation. */
276 * Copies all selected items to the clipboard and marks
281 /** Copies all selected items to the clipboard. */
284 /** Pastes the clipboard data to the active view. */
287 /** Replaces the URL navigator by a search box to find files. */
290 /** Updates the state of the search action according to the view container. */
291 void updateSearchAction();
294 * Updates the text of the paste action dependent on
295 * the number of items which are in the clipboard.
297 void updatePasteAction();
299 /** Selects all items from the active view. */
303 * Inverts the selection of all items of the active view:
304 * Selected items get nonselected and nonselected items get
307 void invertSelection();
310 * Switches between one and two views:
311 * If one view is visible, it will get split into two views.
312 * If already two views are visible, the active view gets closed.
314 void toggleSplitView();
316 /** Dedicated action to open the stash:/ ioslave in split view. */
317 void toggleSplitStash();
319 /** Reloads the currently active view. */
322 /** Stops the loading process for the currently active view. */
325 void enableStopAction();
326 void disableStopAction();
328 void showFilterBar();
329 void toggleFilterBar();
332 * Toggles between edit and browse mode of the navigation bar.
334 void toggleEditLocation();
337 * Switches to the edit mode of the navigation bar and selects
338 * the whole URL, so that it can be replaced by the user. If the edit mode is
339 * already active, it is assured that the navigation bar get focused.
341 void replaceLocation();
344 * Toggles the state of the panels between a locked and unlocked layout.
346 void togglePanelLockState();
349 * Is invoked if the Terminal panel got visible/invisible and takes care
350 * that the active view has the focus if the Terminal panel is invisible.
352 void slotTerminalPanelVisibilityChanged();
354 /** Goes back one step of the URL history. */
357 /** Goes forward one step of the URL history. */
360 /** Goes up one hierarchy of the current URL. */
363 /** Changes the location to the home URL. */
366 /** Open the previous URL in the URL history in a new tab. */
367 void goBackInNewTab();
369 /** Open the next URL in the URL history in a new tab. */
370 void goForwardInNewTab();
372 /** Open the URL one hierarchy above the current URL in a new tab. */
375 /** * Open the home URL in a new tab. */
376 void goHomeInNewTab();
378 /** Opens Kompare for 2 selected files. */
382 * Hides the menu bar if it is visible, makes the menu bar
383 * visible if it is hidden.
385 void toggleShowMenuBar();
387 /** Updates "Open Preferred Search Tool" action. */
388 void updateOpenPreferredSearchToolAction();
390 /** Opens preferred search tool for the current location. */
391 void openPreferredSearchTool();
393 /** Opens a terminal window for the current location. */
396 /** Focus a Terminal Panel. */
397 void focusTerminalPanel();
399 /** Opens the settings dialog for Dolphin. */
402 /** Updates the state of the 'Show Full Location' action. */
403 void slotEditableStateChanged(bool editable
);
406 * Updates the state of the 'Edit' menu actions and emits
407 * the signal selectionChanged().
409 void slotSelectionChanged(const KFileItemList
& selection
);
412 * Updates the state of the 'Back' and 'Forward' menu
413 * actions corresponding to the current history.
415 void updateHistory();
417 /** Updates the state of the 'Show filter bar' menu action. */
418 void updateFilterBarAction(bool show
);
420 /** Open a new main window. */
421 void openNewMainWindow();
424 * Opens a new view with the current URL that is part of a tab and
427 void openNewActivatedTab();
430 * Adds the current URL as an entry to the Places panel
435 * Opens the selected folder in a new tab.
440 * Opens the selected folder in a new window.
442 void openInNewWindow();
445 * Show the target of the selected symlink
450 * Indicates in the statusbar that the execution of the command \a command
453 void showCommand(CommandType command
);
456 * If the URL can be listed, open it in the current view, otherwise
457 * run it through KRun.
459 void handleUrl(const QUrl
& url
);
462 * Is invoked when the write state of a folder has been changed and
463 * enables/disables the "Create New..." menu entry.
465 void slotWriteStateChanged(bool isFolderWritable
);
468 * Opens the context menu on the current mouse position.
469 * @pos Position in screen coordinates.
470 * @item File item context. If item is null, the context menu
471 * should be applied to \a url.
472 * @url URL which contains \a item.
473 * @customActions Actions that should be added to the context menu,
474 * if the file item is null.
476 void openContextMenu(const QPoint
& pos
,
477 const KFileItem
& item
,
479 const QList
<QAction
*>& customActions
);
482 * Updates the menu that is by default at the right end of the toolbar.
484 * In true "simple by default" fashion, the menu only contains the most important
485 * and necessary actions to be able to use Dolphin. This is supposed to hold true even
486 * if the user does not know how to open a context menu. More advanced actions can be
487 * discovered through a sub-menu (@see KConfigWidgets::KHamburgerMenu::setMenuBarAdvertised()).
489 void updateHamburgerMenu();
492 * Is called if the user clicked an item in the Places Panel.
493 * Reloads the view if \a url is the current URL already, and changes the
494 * current URL otherwise.
496 void slotPlaceActivated(const QUrl
& url
);
499 * Is called if the another view has been activated by changing the current
500 * tab or activating another view in split-view mode.
502 * Activates the given view, which means that all menu actions are applied
503 * to this view. When having a split view setup, the nonactive view is
504 * usually shown in darker colors.
506 void activeViewChanged(DolphinViewContainer
* viewContainer
);
508 void closedTabsCountChanged(unsigned int count
);
511 * Is called if a new tab has been opened or a tab has been closed to
512 * enable/disable the tab actions.
514 void tabCountChanged(int count
);
517 * Updates the Window Title with the caption from the active view container
519 void updateWindowTitle();
522 * This slot is called when the user requested to unmount a removable media
523 * from the places menu
525 void slotStorageTearDownFromPlacesRequested(const QString
& mountPath
);
528 * This slot is called when the user requested to unmount a removable media
529 * _not_ from the dolphin's places menu (from the notification area for e.g.)
530 * This slot is basically connected to each removable device's
531 * Solid::StorageAccess::teardownRequested(const QString & udi)
532 * signal through the places panel.
534 void slotStorageTearDownExternallyRequested(const QString
& mountPath
);
537 * Is called when the view has finished loading the directory.
539 void slotDirectoryLoadingCompleted();
542 * Is called when the user middle clicks a toolbar button.
544 * Here middle clicking Back/Forward/Up/Home will open the resulting
545 * folder in a new tab.
547 void slotToolBarActionMiddleClicked(QAction
*action
);
550 * Is called before the Back popup menu is shown. This slot will populate
551 * the menu with history data
553 void slotAboutToShowBackPopupMenu();
556 * This slot is used by the Back Popup Menu to go back to a specific
557 * history index. The QAction::data will carry an int with the index
560 void slotGoBack(QAction
* action
);
563 * Middle clicking Back/Forward will open the resulting folder in a new tab.
565 void slotBackForwardActionMiddleClicked(QAction
*action
);
568 * Is called before the Forward popup menu is shown. This slot will populate
569 * the menu with history data
571 void slotAboutToShowForwardPopupMenu();
574 * This slot is used by the Forward Popup Menu to go forward to a specific
575 * history index. The QAction::data will carry an int with the index
578 void slotGoForward(QAction
* action
);
581 * Sets up the various menus and actions and connects them.
586 * Sets up the dock widgets and their panels.
588 void setupDockWidgets();
590 void updateFileAndEditActions();
591 void updateViewActions();
592 void updateGoActions();
595 * Connects the signals from the created DolphinView with
596 * the DolphinViewContainer \a container with the corresponding slots of
597 * the DolphinMainWindow. This method must be invoked each
598 * time a DolphinView has been created.
600 void connectViewSignals(DolphinViewContainer
* container
);
603 * Updates the text of the split action:
604 * If two views are shown, the text is set to "Split",
605 * otherwise the text is set to "Join". The icon
606 * is updated to match with the text and the currently active view.
608 void updateSplitAction();
611 * Sets the window sides the toolbar may be moved to based on toolbar contents.
613 void updateAllowedToolbarAreas();
615 bool isKompareInstalled() const;
618 * Creates an action for showing/hiding a panel, that is accessible
619 * in "Configure toolbars..." and "Configure shortcuts...". This is necessary
620 * as the action for toggling the dock visibility is done by Qt which
621 * is no KAction instance.
623 void createPanelAction(const QIcon
&icon
,
624 const QKeySequence
& shortcut
,
626 const QString
& actionName
);
628 /** Adds "What's This?" texts to many widgets and StandardActions. */
629 void setupWhatsThis();
631 /** Returns preferred search tool as configured in "More Search Tools" menu. */
632 QPointer
<QAction
> preferredSearchTool();
635 * Adds this action to the mainWindow's toolbar and saves the change
636 * in the users ui configuration file.
637 * This method is only needed for migration and should be removed once we can expect
638 * that pretty much all users have been migrated. Remove in 2026 because that's when
639 * even the most risk-averse distros will already have been forced to upgrade.
640 * @return true if successful. Otherwise false.
642 bool addHamburgerMenuToToolbar();
646 * Implements a custom error handling for the undo manager. This
647 * assures that all errors are shown in the status bar of Dolphin
648 * instead as modal error dialog with an OK button.
650 class UndoUiInterface
: public KIO::FileUndoManager::UiInterface
654 ~UndoUiInterface() override
;
655 void jobError(KIO::Job
* job
) override
;
658 KNewFileMenu
* m_newFileMenu
;
659 KHelpMenu
* m_helpMenu
;
660 DolphinTabWidget
* m_tabWidget
;
661 DolphinViewContainer
* m_activeViewContainer
;
663 DolphinViewActionHandler
* m_actionHandler
;
664 DolphinRemoteEncoding
* m_remoteEncoding
;
665 QPointer
<DolphinSettingsDialog
> m_settingsDialog
;
666 DolphinBookmarkHandler
* m_bookmarkHandler
;
668 // Members for the toolbar menu that is shown when the menubar is hidden:
669 QToolButton
* m_controlButton
;
670 QTimer
* m_updateToolBarTimer
;
672 KIO::OpenUrlJob
*m_lastHandleUrlOpenJob
;
674 TerminalPanel
* m_terminalPanel
;
675 PlacesPanel
* m_placesPanel
;
676 bool m_tearDownFromPlacesRequested
;
678 KToolBarPopupAction
* m_backAction
;
679 KToolBarPopupAction
* m_forwardAction
;
682 KFileItemActions m_fileItemActions
;
686 inline DolphinViewContainer
* DolphinMainWindow::activeViewContainer() const
688 return m_activeViewContainer
;
691 inline KNewFileMenu
* DolphinMainWindow::newFileMenu() const
693 return m_newFileMenu
;
696 #endif // DOLPHIN_MAINWINDOW_H