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 <kio/fileundomanager.h>
15 #include <kxmlguiwindow.h>
18 #include "panels/information/informationpanel.h"
28 typedef KIO::FileUndoManager::CommandType CommandType
;
30 class DolphinBookmarkHandler
;
31 class DolphinViewActionHandler
;
32 class DolphinSettingsDialog
;
33 class DolphinViewContainer
;
34 class DolphinRemoteEncoding
;
35 class DolphinTabWidget
;
41 class KToolBarPopupAction
;
51 * @short Main window for Dolphin.
53 * Handles the menus, toolbars and Dolphin views.
55 class DolphinMainWindow
: public KXmlGuiWindow
58 Q_CLASSINFO("D-Bus Interface", "org.kde.dolphin.MainWindow")
62 ~DolphinMainWindow() override
;
65 * Returns the currently active view.
66 * All menu actions are applied to this view. When
67 * having a split view setup, the nonactive view
68 * is usually shown in darker colors.
70 DolphinViewContainer
* activeViewContainer() const;
73 * Returns view container for all tabs
75 QVector
<DolphinViewContainer
*> viewContainers() const;
78 * Opens each directory in \p dirs in a separate tab. If \a splitView is set,
79 * 2 directories are collected within one tab.
80 * \pre \a dirs must contain at least one url.
82 void openDirectories(const QList
<QUrl
> &dirs
, bool splitView
);
85 * Opens the directories which contain the files \p files and selects all files.
86 * If \a splitView is set, 2 directories are collected within one tab.
87 * \pre \a files must contain at least one url.
89 void openFiles(const QList
<QUrl
>& files
, bool splitView
);
92 * Returns the 'Create New...' sub menu which also can be shared
93 * with other menus (e. g. a context menu).
95 KNewFileMenu
* newFileMenu() const;
98 * Switch the window's view containers' locations to display the home path
99 * for any which are currently displaying a location corresponding to or
102 * This typically done after unmounting a disk at mountPath to ensure that
103 * the window is not displaying an invalid location.
105 void setViewsToHomeIfMountPathOpen(const QString
& mountPath
);
108 * Sets any of the window's view containers which are currently displaying
109 * invalid locations to the home path
111 void setViewsWithInvalidPathsToHome();
113 bool isFoldersPanelEnabled() const;
114 bool isInformationPanelEnabled() const;
118 * Opens each directory in \p dirs in a separate tab. If \a splitView is set,
119 * 2 directories are collected within one tab.
120 * \pre \a dirs must contain at least one url.
122 * @note this function is overloaded so that it is callable via DBus.
124 void openDirectories(const QStringList
&dirs
, bool splitView
);
127 * Opens the directories which contain the files \p files and selects all files.
128 * If \a splitView is set, 2 directories are collected within one tab.
129 * \pre \a files must contain at least one url.
131 * @note this is overloaded so that this function is callable via DBus.
133 void openFiles(const QStringList
&files
, bool splitView
);
136 * Tries to raise/activate the Dolphin window.
138 void activateWindow();
141 * Determines if a URL is open in any tab.
142 * @note Use of QString instead of QUrl is required to be callable via DBus.
144 * @param url URL to look for
145 * @returns true if url is currently open in a tab, false otherwise.
147 bool isUrlOpen(const QString
&url
);
151 * Pastes the clipboard data into the currently selected folder
152 * of the active view. If not exactly one folder is selected,
153 * no pasting is done at all.
155 void pasteIntoFolder();
158 * Implementation of the MainWindowAdaptor/QDBusAbstractAdaptor interface.
159 * Inform all affected dolphin components (panels, views) of an URL
162 void changeUrl(const QUrl
& url
);
165 * The current directory of the Terminal Panel has changed, probably because
166 * the user entered a 'cd' command. This slot calls changeUrl(url) and makes
167 * sure that the panel keeps the keyboard focus.
169 void slotTerminalDirectoryChanged(const QUrl
& url
);
171 /** Stores all settings and quits Dolphin. */
175 * Opens a new tab in the background showing the URL \a url.
177 void openNewTab(const QUrl
& url
);
181 * Is sent if the selection of the currently active view has
184 void selectionChanged(const KFileItemList
& selection
);
187 * Is sent if the url of the currently active view has
190 void urlChanged(const QUrl
& url
);
193 * Is emitted if information of an item is requested to be shown e. g. in the panel.
194 * If item is null, no item information request is pending.
196 void requestItemInfo(const KFileItem
& item
);
199 * It is emitted when in the current view, files are changed,
200 * or dirs have files/removed from them.
202 void fileItemsChanged(const KFileItemList
&changedFileItems
);
205 * Is emitted if the settings have been changed.
207 void settingsChanged();
210 /** @see QWidget::showEvent() */
211 void showEvent(QShowEvent
* event
) override
;
213 /** @see QMainWindow::closeEvent() */
214 void closeEvent(QCloseEvent
* event
) override
;
216 /** @see KMainWindow::saveProperties() */
217 void saveProperties(KConfigGroup
& group
) override
;
219 /** @see KMainWindow::readProperties() */
220 void readProperties(const KConfigGroup
& group
) override
;
222 /** Handles QWhatsThisClickedEvent and passes all others on. */
223 bool event(QEvent
* event
) override
;
224 /** Handles QWhatsThisClickedEvent and passes all others on. */
225 bool eventFilter(QObject
*, QEvent
*) override
;
227 /** Sets a sane initial window size **/
228 QSize
sizeHint() const override
;
232 * Calls the base method KXmlGuiWindow::saveNewToolbarConfig().
233 * Is also used to set toolbar constraints and UrlNavigator position
234 * based on the newly changed toolbar configuration.
236 void saveNewToolbarConfig() override
;
240 * Refreshes the views of the main window by recreating them according to
241 * the given Dolphin settings.
245 void clearStatusBar();
247 /** Updates the 'Create New...' sub menu. */
248 void updateNewMenu();
250 void createDirectory();
252 /** Shows the error message in the status bar of the active view. */
253 void showErrorMessage(const QString
& message
);
256 * Updates the state of the 'Undo' menu action dependent
257 * on the parameter \a available.
259 void slotUndoAvailable(bool available
);
261 /** Sets the text of the 'Undo' menu action to \a text. */
262 void slotUndoTextChanged(const QString
& text
);
264 /** Performs the current undo operation. */
268 * Copies all selected items to the clipboard and marks
273 /** Copies all selected items to the clipboard. */
276 /** Pastes the clipboard data to the active view. */
279 /** Replaces the URL navigator by a search box to find files. */
282 /** Updates the state of the search action according to the view container. */
283 void updateSearchAction();
286 * Updates the text of the paste action dependent on
287 * the number of items which are in the clipboard.
289 void updatePasteAction();
291 /** Selects all items from the active view. */
295 * Inverts the selection of all items of the active view:
296 * Selected items get nonselected and nonselected items get
299 void invertSelection();
302 * Switches between one and two views:
303 * If one view is visible, it will get split into two views.
304 * If already two views are visible, the active view gets closed.
306 void toggleSplitView();
308 /** Dedicated action to open the stash:/ ioslave in split view. */
309 void toggleSplitStash();
311 /** Reloads the currently active view. */
314 /** Stops the loading process for the currently active view. */
317 void enableStopAction();
318 void disableStopAction();
320 void showFilterBar();
321 void toggleFilterBar();
324 * Toggles between edit and browse mode of the navigation bar.
326 void toggleEditLocation();
329 * Switches to the edit mode of the navigation bar and selects
330 * the whole URL, so that it can be replaced by the user. If the edit mode is
331 * already active, it is assured that the navigation bar get focused.
333 void replaceLocation();
336 * Toggles the state of the panels between a locked and unlocked layout.
338 void togglePanelLockState();
341 * Is invoked if the Terminal panel got visible/invisible and takes care
342 * that the active view has the focus if the Terminal panel is invisible.
344 void slotTerminalPanelVisibilityChanged();
346 /** Goes back one step of the URL history. */
349 /** Goes forward one step of the URL history. */
352 /** Goes up one hierarchy of the current URL. */
355 /** Changes the location to the home URL. */
358 /** Open the previous URL in the URL history in a new tab. */
359 void goBackInNewTab();
361 /** Open the next URL in the URL history in a new tab. */
362 void goForwardInNewTab();
364 /** Open the URL one hierarchy above the current URL in a new tab. */
367 /** * Open the home URL in a new tab. */
368 void goHomeInNewTab();
370 /** Opens Kompare for 2 selected files. */
374 * Hides the menu bar if it is visible, makes the menu bar
375 * visible if it is hidden.
377 void toggleShowMenuBar();
379 /** Updates "Open Preferred Search Tool" action. */
380 void updateOpenPreferredSearchToolAction();
382 /** Opens preferred search tool for the current location. */
383 void openPreferredSearchTool();
385 /** Opens a terminal window for the current location. */
388 /** Focus a Terminal Panel. */
389 void focusTerminalPanel();
391 /** Opens the settings dialog for Dolphin. */
394 /** Updates the state of the 'Show Full Location' action. */
395 void slotEditableStateChanged(bool editable
);
398 * Updates the state of the 'Edit' menu actions and emits
399 * the signal selectionChanged().
401 void slotSelectionChanged(const KFileItemList
& selection
);
404 * Updates the state of the 'Back' and 'Forward' menu
405 * actions corresponding to the current history.
407 void updateHistory();
409 /** Updates the state of the 'Show filter bar' menu action. */
410 void updateFilterBarAction(bool show
);
412 /** Open a new main window. */
413 void openNewMainWindow();
416 * Opens a new view with the current URL that is part of a tab and
419 void openNewActivatedTab();
422 * Adds the current URL as an entry to the Places panel
427 * Opens the selected folder in a new tab.
432 * Opens the selected folder in a new window.
434 void openInNewWindow();
437 * Show the target of the selected symlink
442 * Indicates in the statusbar that the execution of the command \a command
445 void showCommand(CommandType command
);
448 * If the URL can be listed, open it in the current view, otherwise
449 * run it through KRun.
451 void handleUrl(const QUrl
& url
);
454 * Is invoked when the write state of a folder has been changed and
455 * enables/disables the "Create New..." menu entry.
457 void slotWriteStateChanged(bool isFolderWritable
);
460 * Opens the context menu on the current mouse position.
461 * @pos Position in screen coordinates.
462 * @item File item context. If item is null, the context menu
463 * should be applied to \a url.
464 * @url URL which contains \a item.
465 * @customActions Actions that should be added to the context menu,
466 * if the file item is null.
468 void openContextMenu(const QPoint
& pos
,
469 const KFileItem
& item
,
471 const QList
<QAction
*>& customActions
);
474 * Updates the menu that is by default at the right end of the toolbar.
476 * In true "simple by default" fashion, the menu only contains the most important
477 * and necessary actions to be able to use Dolphin. This is supposed to hold true even
478 * if the user does not know how to open a context menu. More advanced actions can be
479 * discovered through a sub-menu (@see KConfigWidgets::KHamburgerMenu::setMenuBarAdvertised()).
481 void updateHamburgerMenu();
484 * Is called if the user clicked an item in the Places Panel.
485 * Reloads the view if \a url is the current URL already, and changes the
486 * current URL otherwise.
488 void slotPlaceActivated(const QUrl
& url
);
491 * Is called if the another view has been activated by changing the current
492 * tab or activating another view in split-view mode.
494 * Activates the given view, which means that all menu actions are applied
495 * to this view. When having a split view setup, the nonactive view is
496 * usually shown in darker colors.
498 void activeViewChanged(DolphinViewContainer
* viewContainer
);
500 void closedTabsCountChanged(unsigned int count
);
503 * Is called if a new tab has been opened or a tab has been closed to
504 * enable/disable the tab actions.
506 void tabCountChanged(int count
);
509 * Updates the Window Title with the caption from the active view container
511 void updateWindowTitle();
514 * This slot is called when the user requested to unmount a removable media
515 * from the places menu
517 void slotStorageTearDownFromPlacesRequested(const QString
& mountPath
);
520 * This slot is called when the user requested to unmount a removable media
521 * _not_ from the dolphin's places menu (from the notification area for e.g.)
522 * This slot is basically connected to each removable device's
523 * Solid::StorageAccess::teardownRequested(const QString & udi)
524 * signal through the places panel.
526 void slotStorageTearDownExternallyRequested(const QString
& mountPath
);
529 * Is called when the view has finished loading the directory.
531 void slotDirectoryLoadingCompleted();
534 * Is called when the user middle clicks a toolbar button.
536 * Here middle clicking Back/Forward/Up/Home will open the resulting
537 * folder in a new tab.
539 void slotToolBarActionMiddleClicked(QAction
*action
);
542 * Is called before the Back popup menu is shown. This slot will populate
543 * the menu with history data
545 void slotAboutToShowBackPopupMenu();
548 * This slot is used by the Back Popup Menu to go back to a specific
549 * history index. The QAction::data will carry an int with the index
552 void slotGoBack(QAction
* action
);
555 * Middle clicking Back/Forward will open the resulting folder in a new tab.
557 void slotBackForwardActionMiddleClicked(QAction
*action
);
560 * Is called before the Forward popup menu is shown. This slot will populate
561 * the menu with history data
563 void slotAboutToShowForwardPopupMenu();
566 * This slot is used by the Forward Popup Menu to go forward to a specific
567 * history index. The QAction::data will carry an int with the index
570 void slotGoForward(QAction
* action
);
573 * Sets up the various menus and actions and connects them.
578 * Sets up the dock widgets and their panels.
580 void setupDockWidgets();
582 void updateFileAndEditActions();
583 void updateViewActions();
584 void updateGoActions();
587 * Connects the signals from the created DolphinView with
588 * the DolphinViewContainer \a container with the corresponding slots of
589 * the DolphinMainWindow. This method must be invoked each
590 * time a DolphinView has been created.
592 void connectViewSignals(DolphinViewContainer
* container
);
595 * Updates the text of the split action:
596 * If two views are shown, the text is set to "Split",
597 * otherwise the text is set to "Join". The icon
598 * is updated to match with the text and the currently active view.
600 void updateSplitAction();
603 * Sets the window sides the toolbar may be moved to based on toolbar contents.
605 void updateAllowedToolbarAreas();
607 bool isKompareInstalled() const;
610 * Creates an action for showing/hiding a panel, that is accessible
611 * in "Configure toolbars..." and "Configure shortcuts...". This is necessary
612 * as the action for toggling the dock visibility is done by Qt which
613 * is no KAction instance.
615 void createPanelAction(const QIcon
&icon
,
616 const QKeySequence
& shortcut
,
618 const QString
& actionName
);
620 /** Adds "What's This?" texts to many widgets and StandardActions. */
621 void setupWhatsThis();
623 /** Returns preferred search tool as configured in "More Search Tools" menu. */
624 QPointer
<QAction
> preferredSearchTool();
627 * Adds this action to the mainWindow's toolbar and saves the change
628 * in the users ui configuration file.
629 * This method is only needed for migration and should be removed once we can expect
630 * that pretty much all users have been migrated. Remove in 2026 because that's when
631 * even the most risk-averse distros will already have been forced to upgrade.
632 * @return true if successful. Otherwise false.
634 bool addHamburgerMenuToToolbar();
638 * Implements a custom error handling for the undo manager. This
639 * assures that all errors are shown in the status bar of Dolphin
640 * instead as modal error dialog with an OK button.
642 class UndoUiInterface
: public KIO::FileUndoManager::UiInterface
646 ~UndoUiInterface() override
;
647 void jobError(KIO::Job
* job
) override
;
650 KNewFileMenu
* m_newFileMenu
;
651 KHelpMenu
* m_helpMenu
;
652 DolphinTabWidget
* m_tabWidget
;
653 DolphinViewContainer
* m_activeViewContainer
;
655 DolphinViewActionHandler
* m_actionHandler
;
656 DolphinRemoteEncoding
* m_remoteEncoding
;
657 QPointer
<DolphinSettingsDialog
> m_settingsDialog
;
658 DolphinBookmarkHandler
* m_bookmarkHandler
;
660 // Members for the toolbar menu that is shown when the menubar is hidden:
661 QToolButton
* m_controlButton
;
662 QTimer
* m_updateToolBarTimer
;
664 KIO::OpenUrlJob
*m_lastHandleUrlOpenJob
;
666 TerminalPanel
* m_terminalPanel
;
667 PlacesPanel
* m_placesPanel
;
668 bool m_tearDownFromPlacesRequested
;
670 KToolBarPopupAction
* m_backAction
;
671 KToolBarPopupAction
* m_forwardAction
;
676 inline DolphinViewContainer
* DolphinMainWindow::activeViewContainer() const
678 return m_activeViewContainer
;
681 inline KNewFileMenu
* DolphinMainWindow::newFileMenu() const
683 return m_newFileMenu
;
686 #endif // DOLPHIN_MAINWINDOW_H