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 <KSortableList>
16 #include <kxmlguiwindow.h>
25 typedef KIO::FileUndoManager::CommandType CommandType
;
27 class DolphinBookmarkHandler
;
28 class DolphinViewActionHandler
;
29 class DolphinSettingsDialog
;
30 class DolphinViewContainer
;
31 class DolphinRemoteEncoding
;
32 class DolphinTabWidget
;
38 class KToolBarPopupAction
;
49 * @short Main window for Dolphin.
51 * Handles the menus, toolbars and Dolphin views.
53 class DolphinMainWindow
: public KXmlGuiWindow
56 Q_CLASSINFO("D-Bus Interface", "org.kde.dolphin.MainWindow")
60 ~DolphinMainWindow() override
;
63 * Returns the currently active view.
64 * All menu actions are applied to this view. When
65 * having a split view setup, the nonactive view
66 * is usually shown in darker colors.
68 DolphinViewContainer
* activeViewContainer() const;
71 * Returns view containers for all tabs
72 * @param includeInactive When true all view containers available in
73 * this window are returned. When false the
74 * view containers of split views that are not
75 * currently active are ignored.
78 QVector
<DolphinViewContainer
*> viewContainers(bool includeInactive
= true) const;
81 * Opens each directory in \p dirs in a separate tab. If \a splitView is set,
82 * 2 directories are collected within one tab.
83 * \pre \a dirs must contain at least one url.
85 void openDirectories(const QList
<QUrl
> &dirs
, bool splitView
);
88 * Opens the directories which contain the files \p files and selects all files.
89 * If \a splitView is set, 2 directories are collected within one tab.
90 * \pre \a files must contain at least one url.
92 void openFiles(const QList
<QUrl
>& files
, bool splitView
);
95 * Returns the 'Create New...' sub menu which also can be shared
96 * with other menus (e. g. a context menu).
98 KNewFileMenu
* newFileMenu() const;
101 * Switch the window's view containers' locations to display the home path
102 * for any which are currently displaying a location corresponding to or
105 * This typically done after unmounting a disk at mountPath to ensure that
106 * the window is not displaying an invalid location.
108 void setViewsToHomeIfMountPathOpen(const QString
& mountPath
);
111 * Sets any of the window's view containers which are currently displaying
112 * invalid locations to the home path
114 void setViewsWithInvalidPathsToHome();
116 bool isFoldersPanelEnabled() const;
117 bool isInformationPanelEnabled() const;
121 * Opens each directory in \p dirs in a separate tab. If \a splitView is set,
122 * 2 directories are collected within one tab.
123 * \pre \a dirs must contain at least one url.
125 * @note this function is overloaded so that it is callable via DBus.
127 void openDirectories(const QStringList
&dirs
, bool splitView
);
130 * Opens the directories which contain the files \p files and selects all files.
131 * If \a splitView is set, 2 directories are collected within one tab.
132 * \pre \a files must contain at least one url.
134 * @note this is overloaded so that this function is callable via DBus.
136 void openFiles(const QStringList
&files
, bool splitView
);
139 * Tries to raise/activate the Dolphin window.
141 void activateWindow();
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
);
154 * Pastes the clipboard data into the currently selected folder
155 * of the active view. If not exactly one folder is selected,
156 * no pasting is done at all.
158 void pasteIntoFolder();
161 * Implementation of the MainWindowAdaptor/QDBusAbstractAdaptor interface.
162 * Inform all affected dolphin components (panels, views) of an URL
165 void changeUrl(const QUrl
& url
);
168 * The current directory of the Terminal Panel has changed, probably because
169 * the user entered a 'cd' command. This slot calls changeUrl(url) and makes
170 * sure that the panel keeps the keyboard focus.
172 void slotTerminalDirectoryChanged(const QUrl
& url
);
174 /** Stores all settings and quits Dolphin. */
178 * Opens a new tab and places it after the current tab
180 void openNewTabAfterCurrentTab(const QUrl
& url
);
183 * Opens a new tab and places it as the last tab
185 void openNewTabAfterLastTab(const QUrl
& url
);
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 * Is emitted if the settings have been changed.
209 void settingsChanged();
212 /** @see QWidget::showEvent() */
213 void showEvent(QShowEvent
* event
) override
;
215 /** @see QMainWindow::closeEvent() */
216 void closeEvent(QCloseEvent
* event
) override
;
218 /** @see KMainWindow::saveProperties() */
219 void saveProperties(KConfigGroup
& group
) override
;
221 /** @see KMainWindow::readProperties() */
222 void readProperties(const KConfigGroup
& group
) override
;
224 /** Handles QWhatsThisClickedEvent and passes all others on. */
225 bool event(QEvent
* event
) override
;
226 /** Handles QWhatsThisClickedEvent and passes all others on. */
227 bool eventFilter(QObject
*, QEvent
*) override
;
231 * Refreshes the views of the main window by recreating them according to
232 * the given Dolphin settings.
236 void clearStatusBar();
238 /** Updates the 'Create New...' sub menu. */
239 void updateNewMenu();
241 void createDirectory();
243 /** Shows the error message in the status bar of the active view. */
244 void showErrorMessage(const QString
& message
);
247 * Updates the state of the 'Undo' menu action dependent
248 * on the parameter \a available.
250 void slotUndoAvailable(bool available
);
252 /** Sets the text of the 'Undo' menu action to \a text. */
253 void slotUndoTextChanged(const QString
& text
);
255 /** Performs the current undo operation. */
259 * Copies all selected items to the clipboard and marks
264 /** Copies all selected items to the clipboard. */
267 /** Pastes the clipboard data to the active view. */
270 /** Replaces the URL navigator by a search box to find files. */
273 /** Updates the state of the search action according to the view container. */
274 void updateSearchAction();
277 * Updates the text of the paste action dependent on
278 * the number of items which are in the clipboard.
280 void updatePasteAction();
282 /** Selects all items from the active view. */
286 * Inverts the selection of all items of the active view:
287 * Selected items get nonselected and nonselected items get
290 void invertSelection();
293 * Switches between one and two views:
294 * If one view is visible, it will get split into two views.
295 * If already two views are visible, the active view gets closed.
297 void toggleSplitView();
299 /** Dedicated action to open the stash:/ ioslave in split view. */
300 void toggleSplitStash();
302 /** Reloads the currently active view. */
305 /** Stops the loading process for the currently active view. */
308 void enableStopAction();
309 void disableStopAction();
311 void showFilterBar();
314 * Toggle between either using an UrlNavigator in the toolbar or the
315 * ones in the location bar for navigating.
317 void toggleLocationInToolbar();
320 * Toggles between edit and browse mode of the navigation bar.
322 void toggleEditLocation();
325 * Switches to the edit mode of the navigation bar and selects
326 * the whole URL, so that it can be replaced by the user. If the edit mode is
327 * already active, it is assured that the navigation bar get focused.
329 void replaceLocation();
332 * Toggles the state of the panels between a locked and unlocked layout.
334 void togglePanelLockState();
337 * Is invoked if the Terminal panel got visible/invisible and takes care
338 * that the active view has the focus if the Terminal panel is invisible.
340 void slotTerminalPanelVisibilityChanged();
342 /** Goes back one step of the URL history. */
345 /** Goes forward one step of the URL history. */
348 /** Goes up one hierarchy of the current URL. */
351 /** Changes the location to the home URL. */
354 /** Open the previous URL in the URL history in a new tab. */
355 void goBackInNewTab();
357 /** Open the next URL in the URL history in a new tab. */
358 void goForwardInNewTab();
360 /** Open the URL one hierarchy above the current URL in a new tab. */
363 /** * Open the home URL in a new tab. */
364 void goHomeInNewTab();
366 /** Opens Kompare for 2 selected files. */
370 * Hides the menu bar if it is visible, makes the menu bar
371 * visible if it is hidden.
373 void toggleShowMenuBar();
375 /** Updates "Open Preferred Search Tool" action. */
376 void updateOpenPreferredSearchToolAction();
378 /** Opens preferred search tool for the current location. */
379 void openPreferredSearchTool();
381 /** Opens a terminal window for the current location. */
384 /** Focus a Terminal Panel. */
385 void focusTerminalPanel();
387 /** Opens the settings dialog for Dolphin. */
390 /** Updates the state of the 'Show Full Location' action. */
391 void slotEditableStateChanged(bool editable
);
394 * Updates the state of the 'Edit' menu actions and emits
395 * the signal selectionChanged().
397 void slotSelectionChanged(const KFileItemList
& selection
);
400 * Updates the state of the 'Back' and 'Forward' menu
401 * actions corresponding to the current history.
403 void updateHistory();
405 /** Updates the state of the 'Show filter bar' menu action. */
406 void updateFilterBarAction(bool show
);
408 /** Open a new main window. */
409 void openNewMainWindow();
412 * Opens a new view with the current URL that is part of a tab and
415 void openNewActivatedTab();
418 * Adds the current URL as an entry to the Places panel
423 * Opens a new tab in the background showing the URL \a url.
425 void openNewTab(const QUrl
& url
, DolphinTabWidget::TabPlacement tabPlacement
);
428 * Opens the selected folder in a new tab.
433 * Opens the selected folder in a new window.
435 void openInNewWindow();
438 * Show the target of the selected symlink
443 * Indicates in the statusbar that the execution of the command \a command
446 void showCommand(CommandType command
);
449 * If the URL can be listed, open it in the current view, otherwise
450 * run it through KRun.
452 void handleUrl(const QUrl
& url
);
455 * Is invoked when the write state of a folder has been changed and
456 * enables/disables the "Create New..." menu entry.
458 void slotWriteStateChanged(bool isFolderWritable
);
461 * Opens the context menu on the current mouse position.
462 * @pos Position in screen coordinates.
463 * @item File item context. If item is null, the context menu
464 * should be applied to \a url.
465 * @url URL which contains \a item.
466 * @customActions Actions that should be added to the context menu,
467 * if the file item is null.
469 void openContextMenu(const QPoint
& pos
,
470 const KFileItem
& item
,
472 const QList
<QAction
*>& customActions
);
474 void updateControlMenu();
475 void updateToolBar();
476 void slotControlButtonDeleted();
479 * Is called if the user clicked an item in the Places Panel.
480 * Reloads the view if \a url is the current URL already, and changes the
481 * current URL otherwise.
483 void slotPlaceActivated(const QUrl
& url
);
486 * Is called if the another view has been activated by changing the current
487 * tab or activating another view in split-view mode.
489 * Activates the given view, which means that all menu actions are applied
490 * to this view. When having a split view setup, the nonactive view is
491 * usually shown in darker colors.
493 void activeViewChanged(DolphinViewContainer
* viewContainer
);
495 void closedTabsCountChanged(unsigned int count
);
498 * Is called if a new tab has been opened or a tab has been closed to
499 * enable/disable the tab actions.
501 void tabCountChanged(int count
);
504 * Updates the Window Title with the caption from the active view container
506 void updateWindowTitle();
509 * This slot is called when the user requested to unmount a removable media
510 * from the places menu
512 void slotStorageTearDownFromPlacesRequested(const QString
& mountPath
);
515 * This slot is called when the user requested to unmount a removable media
516 * _not_ from the dolphin's places menu (from the notification area for e.g.)
517 * This slot is basically connected to each removable device's
518 * Solid::StorageAccess::teardownRequested(const QString & udi)
519 * signal through the places panel.
521 void slotStorageTearDownExternallyRequested(const QString
& mountPath
);
524 * Is called when the view has finished loading the directory.
526 void slotDirectoryLoadingCompleted();
529 * Is called when the user middle clicks a toolbar button.
531 * Here middle clicking Back/Forward/Up/Home will open the resulting
532 * folder in a new tab.
534 void slotToolBarActionMiddleClicked(QAction
*action
);
537 * Is called before the Back popup menu is shown. This slot will populate
538 * the menu with history data
540 void slotAboutToShowBackPopupMenu();
543 * This slot is used by the Back Popup Menu to go back to a specific
544 * history index. The QAction::data will carry an int with the index
547 void slotGoBack(QAction
* action
);
550 * Middle clicking Back/Forward will open the resulting folder in a new tab.
552 void slotBackForwardActionMiddleClicked(QAction
*action
);
555 * Is called before the Forward popup menu is shown. This slot will populate
556 * the menu with history data
558 void slotAboutToShowForwardPopupMenu();
561 * This slot is used by the Forward Popup Menu to go forward to a specific
562 * history index. The QAction::data will carry an int with the index
565 void slotGoForward(QAction
* action
);
568 * Sets up the various menus and actions and connects them.
573 * Sets up the dock widgets and their panels.
575 void setupDockWidgets();
577 void updateFileAndEditActions();
578 void updateViewActions();
579 void updateGoActions();
581 void createControlButton();
582 void deleteControlButton();
585 * Adds the action \p action to the menu \p menu in
586 * case if it has not added already to the toolbar.
587 * @return True if the action has been added to the menu.
589 bool addActionToMenu(QAction
* action
, QMenu
* menu
);
592 * Connects the signals from the created DolphinView with
593 * the DolphinViewContainer \a container with the corresponding slots of
594 * the DolphinMainWindow. This method must be invoked each
595 * time a DolphinView has been created.
597 void connectViewSignals(DolphinViewContainer
* container
);
600 * Updates the text of the split action:
601 * If two views are shown, the text is set to "Split",
602 * otherwise the text is set to "Join". The icon
603 * is updated to match with the text and the currently active view.
605 void updateSplitAction();
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();
628 * Implements a custom error handling for the undo manager. This
629 * assures that all errors are shown in the status bar of Dolphin
630 * instead as modal error dialog with an OK button.
632 class UndoUiInterface
: public KIO::FileUndoManager::UiInterface
636 ~UndoUiInterface() override
;
637 void jobError(KIO::Job
* job
) override
;
640 KNewFileMenu
* m_newFileMenu
;
641 KHelpMenu
* m_helpMenu
;
642 DolphinTabWidget
* m_tabWidget
;
643 DolphinViewContainer
* m_activeViewContainer
;
645 DolphinViewActionHandler
* m_actionHandler
;
646 DolphinRemoteEncoding
* m_remoteEncoding
;
647 QPointer
<DolphinSettingsDialog
> m_settingsDialog
;
648 DolphinBookmarkHandler
* m_bookmarkHandler
;
650 // Members for the toolbar menu that is shown when the menubar is hidden:
651 QToolButton
* m_controlButton
;
652 QTimer
* m_updateToolBarTimer
;
654 KIO::OpenUrlJob
*m_lastHandleUrlOpenJob
;
656 TerminalPanel
* m_terminalPanel
;
657 PlacesPanel
* m_placesPanel
;
658 bool m_tearDownFromPlacesRequested
;
660 KToolBarPopupAction
* m_backAction
;
661 KToolBarPopupAction
* m_forwardAction
;
667 inline DolphinViewContainer
* DolphinMainWindow::activeViewContainer() const
669 return m_activeViewContainer
;
672 inline KNewFileMenu
* DolphinMainWindow::newFileMenu() const
674 return m_newFileMenu
;
677 #endif // DOLPHIN_MAINWINDOW_H