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
);
106 * Sets any of the window's view containers which are currently displaying
107 * invalid locations to the home path
109 void setViewsWithInvalidPathsToHome();
111 bool isFoldersPanelEnabled() const;
112 bool isInformationPanelEnabled() const;
116 * Opens each directory in \p dirs in a separate tab. If \a splitView is set,
117 * 2 directories are collected within one tab.
118 * \pre \a dirs must contain at least one url.
120 * @note this function is overloaded so that it is callable via DBus.
122 void openDirectories(const QStringList
&dirs
, bool splitView
);
125 * Opens the directories which contain the files \p files and selects all files.
126 * If \a splitView is set, 2 directories are collected within one tab.
127 * \pre \a files must contain at least one url.
129 * @note this is overloaded so that this function is callable via DBus.
131 void openFiles(const QStringList
&files
, bool splitView
);
134 * Tries to raise/activate the Dolphin window.
136 void activateWindow();
139 * Determines if a URL is open in any tab.
140 * @note Use of QString instead of QUrl is required to be callable via DBus.
142 * @param url URL to look for
143 * @returns true if url is currently open in a tab, false otherwise.
145 bool isUrlOpen(const QString
&url
);
149 * Pastes the clipboard data into the currently selected folder
150 * of the active view. If not exactly one folder is selected,
151 * no pasting is done at all.
153 void pasteIntoFolder();
156 * Implementation of the MainWindowAdaptor/QDBusAbstractAdaptor interface.
157 * Inform all affected dolphin components (panels, views) of an URL
160 void changeUrl(const QUrl
& url
);
163 * The current directory of the Terminal Panel has changed, probably because
164 * the user entered a 'cd' command. This slot calls changeUrl(url) and makes
165 * sure that the panel keeps the keyboard focus.
167 void slotTerminalDirectoryChanged(const QUrl
& url
);
169 /** Stores all settings and quits Dolphin. */
173 * Opens a new tab and places it after the current tab
175 void openNewTabAfterCurrentTab(const QUrl
& url
);
178 * Opens a new tab and places it as the last tab
180 void openNewTabAfterLastTab(const QUrl
& url
);
184 * Is sent if the selection of the currently active view has
187 void selectionChanged(const KFileItemList
& selection
);
190 * Is sent if the url of the currently active view has
193 void urlChanged(const QUrl
& url
);
196 * Is emitted if information of an item is requested to be shown e. g. in the panel.
197 * If item is null, no item information request is pending.
199 void requestItemInfo(const KFileItem
& item
);
202 * Is emitted if the settings have been changed.
204 void settingsChanged();
207 /** @see QWidget::showEvent() */
208 void showEvent(QShowEvent
* event
) override
;
210 /** @see QMainWindow::closeEvent() */
211 void closeEvent(QCloseEvent
* event
) override
;
213 /** @see KMainWindow::saveProperties() */
214 void saveProperties(KConfigGroup
& group
) override
;
216 /** @see KMainWindow::readProperties() */
217 void readProperties(const KConfigGroup
& group
) override
;
219 /** Handles QWhatsThisClickedEvent and passes all others on. */
220 bool event(QEvent
* event
) override
;
221 /** Handles QWhatsThisClickedEvent and passes all others on. */
222 bool eventFilter(QObject
*, QEvent
*) override
;
226 * Calls the base method KXmlGuiWindow::saveNewToolbarConfig().
227 * Is also used to set toolbar constraints and UrlNavigator position
228 * based on the newly changed toolbar configuration.
230 void saveNewToolbarConfig() override
;
234 * Refreshes the views of the main window by recreating them according to
235 * the given Dolphin settings.
239 void clearStatusBar();
241 /** Updates the 'Create New...' sub menu. */
242 void updateNewMenu();
244 void createDirectory();
246 /** Shows the error message in the status bar of the active view. */
247 void showErrorMessage(const QString
& message
);
250 * Updates the state of the 'Undo' menu action dependent
251 * on the parameter \a available.
253 void slotUndoAvailable(bool available
);
255 /** Sets the text of the 'Undo' menu action to \a text. */
256 void slotUndoTextChanged(const QString
& text
);
258 /** Performs the current undo operation. */
262 * Copies all selected items to the clipboard and marks
267 /** Copies all selected items to the clipboard. */
270 /** Pastes the clipboard data to the active view. */
273 /** Replaces the URL navigator by a search box to find files. */
276 /** Updates the state of the search action according to the view container. */
277 void updateSearchAction();
280 * Updates the text of the paste action dependent on
281 * the number of items which are in the clipboard.
283 void updatePasteAction();
285 /** Selects all items from the active view. */
289 * Inverts the selection of all items of the active view:
290 * Selected items get nonselected and nonselected items get
293 void invertSelection();
296 * Switches between one and two views:
297 * If one view is visible, it will get split into two views.
298 * If already two views are visible, the active view gets closed.
300 void toggleSplitView();
302 /** Dedicated action to open the stash:/ ioslave in split view. */
303 void toggleSplitStash();
305 /** Reloads the currently active view. */
308 /** Stops the loading process for the currently active view. */
311 void enableStopAction();
312 void disableStopAction();
314 void showFilterBar();
315 void toggleFilterBar();
318 * Toggles between edit and browse mode of the navigation bar.
320 void toggleEditLocation();
323 * Switches to the edit mode of the navigation bar and selects
324 * the whole URL, so that it can be replaced by the user. If the edit mode is
325 * already active, it is assured that the navigation bar get focused.
327 void replaceLocation();
330 * Toggles the state of the panels between a locked and unlocked layout.
332 void togglePanelLockState();
335 * Is invoked if the Terminal panel got visible/invisible and takes care
336 * that the active view has the focus if the Terminal panel is invisible.
338 void slotTerminalPanelVisibilityChanged();
340 /** Goes back one step of the URL history. */
343 /** Goes forward one step of the URL history. */
346 /** Goes up one hierarchy of the current URL. */
349 /** Changes the location to the home URL. */
352 /** Open the previous URL in the URL history in a new tab. */
353 void goBackInNewTab();
355 /** Open the next URL in the URL history in a new tab. */
356 void goForwardInNewTab();
358 /** Open the URL one hierarchy above the current URL in a new tab. */
361 /** * Open the home URL in a new tab. */
362 void goHomeInNewTab();
364 /** Opens Kompare for 2 selected files. */
368 * Hides the menu bar if it is visible, makes the menu bar
369 * visible if it is hidden.
371 void toggleShowMenuBar();
373 /** Updates "Open Preferred Search Tool" action. */
374 void updateOpenPreferredSearchToolAction();
376 /** Opens preferred search tool for the current location. */
377 void openPreferredSearchTool();
379 /** Opens a terminal window for the current location. */
382 /** Focus a Terminal Panel. */
383 void focusTerminalPanel();
385 /** Opens the settings dialog for Dolphin. */
388 /** Updates the state of the 'Show Full Location' action. */
389 void slotEditableStateChanged(bool editable
);
392 * Updates the state of the 'Edit' menu actions and emits
393 * the signal selectionChanged().
395 void slotSelectionChanged(const KFileItemList
& selection
);
398 * Updates the state of the 'Back' and 'Forward' menu
399 * actions corresponding to the current history.
401 void updateHistory();
403 /** Updates the state of the 'Show filter bar' menu action. */
404 void updateFilterBarAction(bool show
);
406 /** Open a new main window. */
407 void openNewMainWindow();
410 * Opens a new view with the current URL that is part of a tab and
413 void openNewActivatedTab();
416 * Adds the current URL as an entry to the Places panel
421 * Opens a new tab in the background showing the URL \a url.
423 void openNewTab(const QUrl
& url
, DolphinTabWidget::TabPlacement tabPlacement
);
426 * Opens the selected folder in a new tab.
431 * Opens the selected folder in a new window.
433 void openInNewWindow();
436 * Show the target of the selected symlink
441 * Indicates in the statusbar that the execution of the command \a command
444 void showCommand(CommandType command
);
447 * If the URL can be listed, open it in the current view, otherwise
448 * run it through KRun.
450 void handleUrl(const QUrl
& url
);
453 * Is invoked when the write state of a folder has been changed and
454 * enables/disables the "Create New..." menu entry.
456 void slotWriteStateChanged(bool isFolderWritable
);
459 * Opens the context menu on the current mouse position.
460 * @pos Position in screen coordinates.
461 * @item File item context. If item is null, the context menu
462 * should be applied to \a url.
463 * @url URL which contains \a item.
464 * @customActions Actions that should be added to the context menu,
465 * if the file item is null.
467 void openContextMenu(const QPoint
& pos
,
468 const KFileItem
& item
,
470 const QList
<QAction
*>& customActions
);
472 void updateControlMenu();
473 void updateToolBar();
474 void slotControlButtonDeleted();
477 * Is called if the user clicked an item in the Places Panel.
478 * Reloads the view if \a url is the current URL already, and changes the
479 * current URL otherwise.
481 void slotPlaceActivated(const QUrl
& url
);
484 * Is called if the another view has been activated by changing the current
485 * tab or activating another view in split-view mode.
487 * Activates the given view, which means that all menu actions are applied
488 * to this view. When having a split view setup, the nonactive view is
489 * usually shown in darker colors.
491 void activeViewChanged(DolphinViewContainer
* viewContainer
);
493 void closedTabsCountChanged(unsigned int count
);
496 * Is called if a new tab has been opened or a tab has been closed to
497 * enable/disable the tab actions.
499 void tabCountChanged(int count
);
502 * Updates the Window Title with the caption from the active view container
504 void updateWindowTitle();
507 * This slot is called when the user requested to unmount a removable media
508 * from the places menu
510 void slotStorageTearDownFromPlacesRequested(const QString
& mountPath
);
513 * This slot is called when the user requested to unmount a removable media
514 * _not_ from the dolphin's places menu (from the notification area for e.g.)
515 * This slot is basically connected to each removable device's
516 * Solid::StorageAccess::teardownRequested(const QString & udi)
517 * signal through the places panel.
519 void slotStorageTearDownExternallyRequested(const QString
& mountPath
);
522 * Is called when the view has finished loading the directory.
524 void slotDirectoryLoadingCompleted();
527 * Is called when the user middle clicks a toolbar button.
529 * Here middle clicking Back/Forward/Up/Home will open the resulting
530 * folder in a new tab.
532 void slotToolBarActionMiddleClicked(QAction
*action
);
535 * Is called before the Back popup menu is shown. This slot will populate
536 * the menu with history data
538 void slotAboutToShowBackPopupMenu();
541 * This slot is used by the Back Popup Menu to go back to a specific
542 * history index. The QAction::data will carry an int with the index
545 void slotGoBack(QAction
* action
);
548 * Middle clicking Back/Forward will open the resulting folder in a new tab.
550 void slotBackForwardActionMiddleClicked(QAction
*action
);
553 * Is called before the Forward popup menu is shown. This slot will populate
554 * the menu with history data
556 void slotAboutToShowForwardPopupMenu();
559 * This slot is used by the Forward Popup Menu to go forward to a specific
560 * history index. The QAction::data will carry an int with the index
563 void slotGoForward(QAction
* action
);
566 * Sets up the various menus and actions and connects them.
571 * Sets up the dock widgets and their panels.
573 void setupDockWidgets();
575 void updateFileAndEditActions();
576 void updateViewActions();
577 void updateGoActions();
579 void createControlButton();
580 void deleteControlButton();
583 * Adds the action \p action to the menu \p menu in
584 * case if it has not added already to the toolbar.
585 * @return True if the action has been added to the menu.
587 bool addActionToMenu(QAction
* action
, QMenu
* menu
);
590 * Connects the signals from the created DolphinView with
591 * the DolphinViewContainer \a container with the corresponding slots of
592 * the DolphinMainWindow. This method must be invoked each
593 * time a DolphinView has been created.
595 void connectViewSignals(DolphinViewContainer
* container
);
598 * Updates the text of the split action:
599 * If two views are shown, the text is set to "Split",
600 * otherwise the text is set to "Join". The icon
601 * is updated to match with the text and the currently active view.
603 void updateSplitAction();
606 * Sets the window sides the toolbar may be moved to based on toolbar contents.
608 void updateAllowedToolbarAreas();
610 bool isKompareInstalled() const;
613 * Creates an action for showing/hiding a panel, that is accessible
614 * in "Configure toolbars..." and "Configure shortcuts...". This is necessary
615 * as the action for toggling the dock visibility is done by Qt which
616 * is no KAction instance.
618 void createPanelAction(const QIcon
&icon
,
619 const QKeySequence
& shortcut
,
621 const QString
& actionName
);
623 /** Adds "What's This?" texts to many widgets and StandardActions. */
624 void setupWhatsThis();
626 /** Returns preferred search tool as configured in "More Search Tools" menu. */
627 QPointer
<QAction
> preferredSearchTool();
631 * Implements a custom error handling for the undo manager. This
632 * assures that all errors are shown in the status bar of Dolphin
633 * instead as modal error dialog with an OK button.
635 class UndoUiInterface
: public KIO::FileUndoManager::UiInterface
639 ~UndoUiInterface() override
;
640 void jobError(KIO::Job
* job
) override
;
643 KNewFileMenu
* m_newFileMenu
;
644 KHelpMenu
* m_helpMenu
;
645 DolphinTabWidget
* m_tabWidget
;
646 DolphinViewContainer
* m_activeViewContainer
;
648 DolphinViewActionHandler
* m_actionHandler
;
649 DolphinRemoteEncoding
* m_remoteEncoding
;
650 QPointer
<DolphinSettingsDialog
> m_settingsDialog
;
651 DolphinBookmarkHandler
* m_bookmarkHandler
;
653 // Members for the toolbar menu that is shown when the menubar is hidden:
654 QToolButton
* m_controlButton
;
655 QTimer
* m_updateToolBarTimer
;
657 KIO::OpenUrlJob
*m_lastHandleUrlOpenJob
;
659 TerminalPanel
* m_terminalPanel
;
660 PlacesPanel
* m_placesPanel
;
661 bool m_tearDownFromPlacesRequested
;
663 KToolBarPopupAction
* m_backAction
;
664 KToolBarPopupAction
* m_forwardAction
;
666 /** Makes sure that only one object is ever connected to the history. */
667 QMetaObject::Connection m_updateHistoryConnection
;
673 inline DolphinViewContainer
* DolphinMainWindow::activeViewContainer() const
675 return m_activeViewContainer
;
678 inline KNewFileMenu
* DolphinMainWindow::newFileMenu() const
680 return m_newFileMenu
;
683 #endif // DOLPHIN_MAINWINDOW_H