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 container for all tabs
73 QVector
<DolphinViewContainer
*> viewContainers() const;
76 * Opens each directory in \p dirs in a separate tab. If \a splitView is set,
77 * 2 directories are collected within one tab.
78 * \pre \a dirs must contain at least one url.
80 void openDirectories(const QList
<QUrl
> &dirs
, bool splitView
);
83 * Opens the directories which contain the files \p files and selects all files.
84 * If \a splitView is set, 2 directories are collected within one tab.
85 * \pre \a files must contain at least one url.
87 void openFiles(const QList
<QUrl
>& files
, bool splitView
);
90 * Returns the 'Create New...' sub menu which also can be shared
91 * with other menus (e. g. a context menu).
93 KNewFileMenu
* newFileMenu() const;
96 * Switch the window's view containers' locations to display the home path
97 * for any which are currently displaying a location corresponding to or
100 * This typically done after unmounting a disk at mountPath to ensure that
101 * the window is not displaying an invalid location.
103 void setViewsToHomeIfMountPathOpen(const QString
& mountPath
);
107 * Opens each directory in \p dirs in a separate tab. If \a splitView is set,
108 * 2 directories are collected within one tab.
109 * \pre \a dirs must contain at least one url.
111 * @note this function is overloaded so that it is callable via DBus.
113 void openDirectories(const QStringList
&dirs
, bool splitView
);
116 * Opens the directories which contain the files \p files and selects all files.
117 * If \a splitView is set, 2 directories are collected within one tab.
118 * \pre \a files must contain at least one url.
120 * @note this is overloaded so that this function is callable via DBus.
122 void openFiles(const QStringList
&files
, bool splitView
);
125 * Tries to raise/activate the Dolphin window.
127 void activateWindow();
130 * Determines if a URL is open in any tab.
131 * @note Use of QString instead of QUrl is required to be callable via DBus.
133 * @param url URL to look for
134 * @returns true if url is currently open in a tab, false otherwise.
136 bool isUrlOpen(const QString
&url
);
140 * Pastes the clipboard data into the currently selected folder
141 * of the active view. If not exactly one folder is selected,
142 * no pasting is done at all.
144 void pasteIntoFolder();
147 * Implementation of the MainWindowAdaptor/QDBusAbstractAdaptor interface.
148 * Inform all affected dolphin components (panels, views) of an URL
151 void changeUrl(const QUrl
& url
);
154 * The current directory of the Terminal Panel has changed, probably because
155 * the user entered a 'cd' command. This slot calls changeUrl(url) and makes
156 * sure that the panel keeps the keyboard focus.
158 void slotTerminalDirectoryChanged(const QUrl
& url
);
160 /** Stores all settings and quits Dolphin. */
164 * Opens a new tab and places it after the current tab
166 void openNewTabAfterCurrentTab(const QUrl
& url
);
169 * Opens a new tab and places it as the last tab
171 void openNewTabAfterLastTab(const QUrl
& url
);
175 * Is sent if the selection of the currently active view has
178 void selectionChanged(const KFileItemList
& selection
);
181 * Is sent if the url of the currently active view has
184 void urlChanged(const QUrl
& url
);
187 * Is emitted if information of an item is requested to be shown e. g. in the panel.
188 * If item is null, no item information request is pending.
190 void requestItemInfo(const KFileItem
& item
);
193 * Is emitted if the settings have been changed.
195 void settingsChanged();
198 /** @see QWidget::showEvent() */
199 void showEvent(QShowEvent
* event
) override
;
201 /** @see QMainWindow::closeEvent() */
202 void closeEvent(QCloseEvent
* event
) override
;
204 /** @see KMainWindow::saveProperties() */
205 void saveProperties(KConfigGroup
& group
) override
;
207 /** @see KMainWindow::readProperties() */
208 void readProperties(const KConfigGroup
& group
) override
;
210 /** Handles QWhatsThisClickedEvent and passes all others on. */
211 bool event(QEvent
* event
) override
;
212 /** Handles QWhatsThisClickedEvent and passes all others on. */
213 bool eventFilter(QObject
*, QEvent
*) override
;
217 * Refreshes the views of the main window by recreating them according to
218 * the given Dolphin settings.
222 void clearStatusBar();
224 /** Updates the 'Create New...' sub menu. */
225 void updateNewMenu();
227 void createDirectory();
229 /** Shows the error message in the status bar of the active view. */
230 void showErrorMessage(const QString
& message
);
233 * Updates the state of the 'Undo' menu action dependent
234 * on the parameter \a available.
236 void slotUndoAvailable(bool available
);
238 /** Sets the text of the 'Undo' menu action to \a text. */
239 void slotUndoTextChanged(const QString
& text
);
241 /** Performs the current undo operation. */
245 * Copies all selected items to the clipboard and marks
250 /** Copies all selected items to the clipboard. */
253 /** Pastes the clipboard data to the active view. */
256 /** Replaces the URL navigator by a search box to find files. */
259 /** Updates the state of the search action according to the view container. */
260 void updateSearchAction();
263 * Updates the text of the paste action dependent on
264 * the number of items which are in the clipboard.
266 void updatePasteAction();
268 /** Selects all items from the active view. */
272 * Inverts the selection of all items of the active view:
273 * Selected items get nonselected and nonselected items get
276 void invertSelection();
279 * Switches between one and two views:
280 * If one view is visible, it will get split into two views.
281 * If already two views are visible, the active view gets closed.
283 void toggleSplitView();
285 /** Dedicated action to open the stash:/ ioslave in split view. */
286 void toggleSplitStash();
288 /** Reloads the currently active view. */
291 /** Stops the loading process for the currently active view. */
294 void enableStopAction();
295 void disableStopAction();
297 void showFilterBar();
300 * Toggles between edit and browse mode of the navigation bar.
302 void toggleEditLocation();
305 * Switches to the edit mode of the navigation bar and selects
306 * the whole URL, so that it can be replaced by the user. If the edit mode is
307 * already active, it is assured that the navigation bar get focused.
309 void replaceLocation();
312 * Toggles the state of the panels between a locked and unlocked layout.
314 void togglePanelLockState();
317 * Is invoked if the Terminal panel got visible/invisible and takes care
318 * that the active view has the focus if the Terminal panel is invisible.
320 void slotTerminalPanelVisibilityChanged();
322 /** Goes back one step of the URL history. */
325 /** Goes forward one step of the URL history. */
328 /** Goes up one hierarchy of the current URL. */
331 /** Changes the location to the home URL. */
334 /** Open the previous URL in the URL history in a new tab. */
335 void goBackInNewTab();
337 /** Open the next URL in the URL history in a new tab. */
338 void goForwardInNewTab();
340 /** Open the URL one hierarchy above the current URL in a new tab. */
343 /** * Open the home URL in a new tab. */
344 void goHomeInNewTab();
346 /** Opens Kompare for 2 selected files. */
350 * Hides the menu bar if it is visible, makes the menu bar
351 * visible if it is hidden.
353 void toggleShowMenuBar();
355 /** Updates "Open Preferred Search Tool" action. */
356 void updateOpenPreferredSearchToolAction();
358 /** Opens preferred search tool for the current location. */
359 void openPreferredSearchTool();
361 /** Opens a terminal window for the current location. */
364 /** Focus a Terminal Panel. */
365 void focusTerminalPanel();
367 /** Opens the settings dialog for Dolphin. */
370 /** Updates the state of the 'Show Full Location' action. */
371 void slotEditableStateChanged(bool editable
);
374 * Updates the state of the 'Edit' menu actions and emits
375 * the signal selectionChanged().
377 void slotSelectionChanged(const KFileItemList
& selection
);
380 * Updates the state of the 'Back' and 'Forward' menu
381 * actions corresponding to the current history.
383 void updateHistory();
385 /** Updates the state of the 'Show filter bar' menu action. */
386 void updateFilterBarAction(bool show
);
388 /** Open a new main window. */
389 void openNewMainWindow();
392 * Opens a new view with the current URL that is part of a tab and
395 void openNewActivatedTab();
398 * Adds the current URL as an entry to the Places panel
403 * Opens a new tab in the background showing the URL \a url.
405 void openNewTab(const QUrl
& url
, DolphinTabWidget::TabPlacement tabPlacement
);
408 * Opens the selected folder in a new tab.
413 * Opens the selected folder in a new window.
415 void openInNewWindow();
418 * Show the target of the selected symlink
423 * Indicates in the statusbar that the execution of the command \a command
426 void showCommand(CommandType command
);
429 * If the URL can be listed, open it in the current view, otherwise
430 * run it through KRun.
432 void handleUrl(const QUrl
& url
);
435 * Is invoked when the write state of a folder has been changed and
436 * enables/disables the "Create New..." menu entry.
438 void slotWriteStateChanged(bool isFolderWritable
);
441 * Opens the context menu on the current mouse position.
442 * @pos Position in screen coordinates.
443 * @item File item context. If item is null, the context menu
444 * should be applied to \a url.
445 * @url URL which contains \a item.
446 * @customActions Actions that should be added to the context menu,
447 * if the file item is null.
449 void openContextMenu(const QPoint
& pos
,
450 const KFileItem
& item
,
452 const QList
<QAction
*>& customActions
);
454 void updateControlMenu();
455 void updateToolBar();
456 void slotControlButtonDeleted();
459 * Is called if the user clicked an item in the Places Panel.
460 * Reloads the view if \a url is the current URL already, and changes the
461 * current URL otherwise.
463 void slotPlaceActivated(const QUrl
& url
);
466 * Is called if the another view has been activated by changing the current
467 * tab or activating another view in split-view mode.
469 * Activates the given view, which means that all menu actions are applied
470 * to this view. When having a split view setup, the nonactive view is
471 * usually shown in darker colors.
473 void activeViewChanged(DolphinViewContainer
* viewContainer
);
475 void closedTabsCountChanged(unsigned int count
);
478 * Is called if a new tab has been opened or a tab has been closed to
479 * enable/disable the tab actions.
481 void tabCountChanged(int count
);
484 * Updates the Window Title with the caption from the active view container
486 void updateWindowTitle();
489 * This slot is called when the user requested to unmount a removable media
490 * from the places menu
492 void slotStorageTearDownFromPlacesRequested(const QString
& mountPath
);
495 * This slot is called when the user requested to unmount a removable media
496 * _not_ from the dolphin's places menu (from the notification area for e.g.)
497 * This slot is basically connected to each removable device's
498 * Solid::StorageAccess::teardownRequested(const QString & udi)
499 * signal through the places panel.
501 void slotStorageTearDownExternallyRequested(const QString
& mountPath
);
504 * Is called when the view has finished loading the directory.
506 void slotDirectoryLoadingCompleted();
509 * Is called when the user middle clicks a toolbar button.
511 * Here middle clicking Back/Forward/Up/Home will open the resulting
512 * folder in a new tab.
514 void slotToolBarActionMiddleClicked(QAction
*action
);
517 * Is called before the Back popup menu is shown. This slot will populate
518 * the menu with history data
520 void slotAboutToShowBackPopupMenu();
523 * This slot is used by the Back Popup Menu to go back to a specific
524 * history index. The QAction::data will carry an int with the index
527 void slotGoBack(QAction
* action
);
530 * Middle clicking Back/Forward will open the resulting folder in a new tab.
532 void slotBackForwardActionMiddleClicked(QAction
*action
);
535 * Is called before the Forward popup menu is shown. This slot will populate
536 * the menu with history data
538 void slotAboutToShowForwardPopupMenu();
541 * This slot is used by the Forward Popup Menu to go forward to a specific
542 * history index. The QAction::data will carry an int with the index
545 void slotGoForward(QAction
* action
);
548 * Sets up the various menus and actions and connects them.
553 * Sets up the dock widgets and their panels.
555 void setupDockWidgets();
557 void updateFileAndEditActions();
558 void updateViewActions();
559 void updateGoActions();
561 void createControlButton();
562 void deleteControlButton();
565 * Adds the action \p action to the menu \p menu in
566 * case if it has not added already to the toolbar.
567 * @return True if the action has been added to the menu.
569 bool addActionToMenu(QAction
* action
, QMenu
* menu
);
572 * Connects the signals from the created DolphinView with
573 * the DolphinViewContainer \a container with the corresponding slots of
574 * the DolphinMainWindow. This method must be invoked each
575 * time a DolphinView has been created.
577 void connectViewSignals(DolphinViewContainer
* container
);
580 * Updates the text of the split action:
581 * If two views are shown, the text is set to "Split",
582 * otherwise the text is set to "Join". The icon
583 * is updated to match with the text and the currently active view.
585 void updateSplitAction();
587 bool isKompareInstalled() const;
590 * Creates an action for showing/hiding a panel, that is accessible
591 * in "Configure toolbars..." and "Configure shortcuts...". This is necessary
592 * as the action for toggling the dock visibility is done by Qt which
593 * is no KAction instance.
595 void createPanelAction(const QIcon
&icon
,
596 const QKeySequence
& shortcut
,
598 const QString
& actionName
);
600 /** Adds "What's This?" texts to many widgets and StandardActions. */
601 void setupWhatsThis();
603 /** Returns preferred search tool as configured in "More Search Tools" menu. */
604 QPointer
<QAction
> preferredSearchTool();
608 * Implements a custom error handling for the undo manager. This
609 * assures that all errors are shown in the status bar of Dolphin
610 * instead as modal error dialog with an OK button.
612 class UndoUiInterface
: public KIO::FileUndoManager::UiInterface
616 ~UndoUiInterface() override
;
617 void jobError(KIO::Job
* job
) override
;
620 KNewFileMenu
* m_newFileMenu
;
621 KHelpMenu
* m_helpMenu
;
622 DolphinTabWidget
* m_tabWidget
;
623 DolphinViewContainer
* m_activeViewContainer
;
625 DolphinViewActionHandler
* m_actionHandler
;
626 DolphinRemoteEncoding
* m_remoteEncoding
;
627 QPointer
<DolphinSettingsDialog
> m_settingsDialog
;
628 DolphinBookmarkHandler
* m_bookmarkHandler
;
630 // Members for the toolbar menu that is shown when the menubar is hidden:
631 QToolButton
* m_controlButton
;
632 QTimer
* m_updateToolBarTimer
;
634 KIO::OpenUrlJob
*m_lastHandleUrlOpenJob
;
636 TerminalPanel
* m_terminalPanel
;
637 PlacesPanel
* m_placesPanel
;
638 bool m_tearDownFromPlacesRequested
;
640 KToolBarPopupAction
* m_backAction
;
641 KToolBarPopupAction
* m_forwardAction
;
647 inline DolphinViewContainer
* DolphinMainWindow::activeViewContainer() const
649 return m_activeViewContainer
;
652 inline KNewFileMenu
* DolphinMainWindow::newFileMenu() const
654 return m_newFileMenu
;
657 #endif // DOLPHIN_MAINWINDOW_H