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
;
48 * @short Main window for Dolphin.
50 * Handles the menus, toolbars and Dolphin views.
52 class DolphinMainWindow
: public KXmlGuiWindow
55 Q_CLASSINFO("D-Bus Interface", "org.kde.dolphin.MainWindow")
59 ~DolphinMainWindow() override
;
62 * Returns the currently active view.
63 * All menu actions are applied to this view. When
64 * having a split view setup, the nonactive view
65 * is usually shown in darker colors.
67 DolphinViewContainer
* activeViewContainer() const;
70 * Returns view container for all tabs
72 QVector
<DolphinViewContainer
*> viewContainers() const;
75 * Opens each directory in \p dirs in a separate tab. If \a splitView is set,
76 * 2 directories are collected within one tab.
77 * \pre \a dirs must contain at least one url.
79 void openDirectories(const QList
<QUrl
> &dirs
, bool splitView
);
82 * Opens the directories which contain the files \p files and selects all files.
83 * If \a splitView is set, 2 directories are collected within one tab.
84 * \pre \a files must contain at least one url.
86 void openFiles(const QList
<QUrl
>& files
, bool splitView
);
89 * Returns the 'Create New...' sub menu which also can be shared
90 * with other menus (e. g. a context menu).
92 KNewFileMenu
* newFileMenu() const;
95 * Switch the window's view containers' locations to display the home path
96 * for any which are currently displaying a location corresponding to or
99 * This typically done after unmounting a disk at mountPath to ensure that
100 * the window is not displaying an invalid location.
102 void setViewsToHomeIfMountPathOpen(const QString
& mountPath
);
105 * Sets any of the window's view containers which are currently displaying
106 * invalid locations to the home path
108 void setViewsWithInvalidPathsToHome();
110 bool isFoldersPanelEnabled() const;
111 bool isInformationPanelEnabled() const;
115 * Opens each directory in \p dirs in a separate tab. If \a splitView is set,
116 * 2 directories are collected within one tab.
117 * \pre \a dirs must contain at least one url.
119 * @note this function is overloaded so that it is callable via DBus.
121 void openDirectories(const QStringList
&dirs
, bool splitView
);
124 * Opens the directories which contain the files \p files and selects all files.
125 * If \a splitView is set, 2 directories are collected within one tab.
126 * \pre \a files must contain at least one url.
128 * @note this is overloaded so that this function is callable via DBus.
130 void openFiles(const QStringList
&files
, bool splitView
);
133 * Tries to raise/activate the Dolphin window.
135 void activateWindow();
138 * Determines if a URL is open in any tab.
139 * @note Use of QString instead of QUrl is required to be callable via DBus.
141 * @param url URL to look for
142 * @returns true if url is currently open in a tab, false otherwise.
144 bool isUrlOpen(const QString
&url
);
148 * Pastes the clipboard data into the currently selected folder
149 * of the active view. If not exactly one folder is selected,
150 * no pasting is done at all.
152 void pasteIntoFolder();
155 * Implementation of the MainWindowAdaptor/QDBusAbstractAdaptor interface.
156 * Inform all affected dolphin components (panels, views) of an URL
159 void changeUrl(const QUrl
& url
);
162 * The current directory of the Terminal Panel has changed, probably because
163 * the user entered a 'cd' command. This slot calls changeUrl(url) and makes
164 * sure that the panel keeps the keyboard focus.
166 void slotTerminalDirectoryChanged(const QUrl
& url
);
168 /** Stores all settings and quits Dolphin. */
172 * Opens a new tab in the background showing the URL \a url.
174 void openNewTab(const QUrl
& url
);
178 * Is sent if the selection of the currently active view has
181 void selectionChanged(const KFileItemList
& selection
);
184 * Is sent if the url of the currently active view has
187 void urlChanged(const QUrl
& url
);
190 * Is emitted if information of an item is requested to be shown e. g. in the panel.
191 * If item is null, no item information request is pending.
193 void requestItemInfo(const KFileItem
& item
);
196 * Is emitted if the settings have been changed.
198 void settingsChanged();
201 /** @see QWidget::showEvent() */
202 void showEvent(QShowEvent
* event
) override
;
204 /** @see QMainWindow::closeEvent() */
205 void closeEvent(QCloseEvent
* event
) override
;
207 /** @see KMainWindow::saveProperties() */
208 void saveProperties(KConfigGroup
& group
) override
;
210 /** @see KMainWindow::readProperties() */
211 void readProperties(const KConfigGroup
& group
) override
;
213 /** Handles QWhatsThisClickedEvent and passes all others on. */
214 bool event(QEvent
* event
) override
;
215 /** Handles QWhatsThisClickedEvent and passes all others on. */
216 bool eventFilter(QObject
*, QEvent
*) override
;
220 * Calls the base method KXmlGuiWindow::saveNewToolbarConfig().
221 * Is also used to set toolbar constraints and UrlNavigator position
222 * based on the newly changed toolbar configuration.
224 void saveNewToolbarConfig() override
;
228 * Refreshes the views of the main window by recreating them according to
229 * the given Dolphin settings.
233 void clearStatusBar();
235 /** Updates the 'Create New...' sub menu. */
236 void updateNewMenu();
238 void createDirectory();
240 /** Shows the error message in the status bar of the active view. */
241 void showErrorMessage(const QString
& message
);
244 * Updates the state of the 'Undo' menu action dependent
245 * on the parameter \a available.
247 void slotUndoAvailable(bool available
);
249 /** Sets the text of the 'Undo' menu action to \a text. */
250 void slotUndoTextChanged(const QString
& text
);
252 /** Performs the current undo operation. */
256 * Copies all selected items to the clipboard and marks
261 /** Copies all selected items to the clipboard. */
264 /** Pastes the clipboard data to the active view. */
267 /** Replaces the URL navigator by a search box to find files. */
270 /** Updates the state of the search action according to the view container. */
271 void updateSearchAction();
274 * Updates the text of the paste action dependent on
275 * the number of items which are in the clipboard.
277 void updatePasteAction();
279 /** Selects all items from the active view. */
283 * Inverts the selection of all items of the active view:
284 * Selected items get nonselected and nonselected items get
287 void invertSelection();
290 * Switches between one and two views:
291 * If one view is visible, it will get split into two views.
292 * If already two views are visible, the active view gets closed.
294 void toggleSplitView();
296 /** Dedicated action to open the stash:/ ioslave in split view. */
297 void toggleSplitStash();
299 /** Reloads the currently active view. */
302 /** Stops the loading process for the currently active view. */
305 void enableStopAction();
306 void disableStopAction();
308 void showFilterBar();
309 void toggleFilterBar();
312 * Toggles between edit and browse mode of the navigation bar.
314 void toggleEditLocation();
317 * Switches to the edit mode of the navigation bar and selects
318 * the whole URL, so that it can be replaced by the user. If the edit mode is
319 * already active, it is assured that the navigation bar get focused.
321 void replaceLocation();
324 * Toggles the state of the panels between a locked and unlocked layout.
326 void togglePanelLockState();
329 * Is invoked if the Terminal panel got visible/invisible and takes care
330 * that the active view has the focus if the Terminal panel is invisible.
332 void slotTerminalPanelVisibilityChanged();
334 /** Goes back one step of the URL history. */
337 /** Goes forward one step of the URL history. */
340 /** Goes up one hierarchy of the current URL. */
343 /** Changes the location to the home URL. */
346 /** Open the previous URL in the URL history in a new tab. */
347 void goBackInNewTab();
349 /** Open the next URL in the URL history in a new tab. */
350 void goForwardInNewTab();
352 /** Open the URL one hierarchy above the current URL in a new tab. */
355 /** * Open the home URL in a new tab. */
356 void goHomeInNewTab();
358 /** Opens Kompare for 2 selected files. */
362 * Hides the menu bar if it is visible, makes the menu bar
363 * visible if it is hidden.
365 void toggleShowMenuBar();
367 /** Updates "Open Preferred Search Tool" action. */
368 void updateOpenPreferredSearchToolAction();
370 /** Opens preferred search tool for the current location. */
371 void openPreferredSearchTool();
373 /** Opens a terminal window for the current location. */
376 /** Focus a Terminal Panel. */
377 void focusTerminalPanel();
379 /** Opens the settings dialog for Dolphin. */
382 /** Updates the state of the 'Show Full Location' action. */
383 void slotEditableStateChanged(bool editable
);
386 * Updates the state of the 'Edit' menu actions and emits
387 * the signal selectionChanged().
389 void slotSelectionChanged(const KFileItemList
& selection
);
392 * Updates the state of the 'Back' and 'Forward' menu
393 * actions corresponding to the current history.
395 void updateHistory();
397 /** Updates the state of the 'Show filter bar' menu action. */
398 void updateFilterBarAction(bool show
);
400 /** Open a new main window. */
401 void openNewMainWindow();
404 * Opens a new view with the current URL that is part of a tab and
407 void openNewActivatedTab();
410 * Adds the current URL as an entry to the Places panel
415 * Opens the selected folder in a new tab.
420 * Opens the selected folder in a new window.
422 void openInNewWindow();
425 * Show the target of the selected symlink
430 * Indicates in the statusbar that the execution of the command \a command
433 void showCommand(CommandType command
);
436 * If the URL can be listed, open it in the current view, otherwise
437 * run it through KRun.
439 void handleUrl(const QUrl
& url
);
442 * Is invoked when the write state of a folder has been changed and
443 * enables/disables the "Create New..." menu entry.
445 void slotWriteStateChanged(bool isFolderWritable
);
448 * Opens the context menu on the current mouse position.
449 * @pos Position in screen coordinates.
450 * @item File item context. If item is null, the context menu
451 * should be applied to \a url.
452 * @url URL which contains \a item.
453 * @customActions Actions that should be added to the context menu,
454 * if the file item is null.
456 void openContextMenu(const QPoint
& pos
,
457 const KFileItem
& item
,
459 const QList
<QAction
*>& customActions
);
461 void updateControlMenu();
462 void updateToolBar();
463 void slotControlButtonDeleted();
466 * Is called if the user clicked an item in the Places Panel.
467 * Reloads the view if \a url is the current URL already, and changes the
468 * current URL otherwise.
470 void slotPlaceActivated(const QUrl
& url
);
473 * Is called if the another view has been activated by changing the current
474 * tab or activating another view in split-view mode.
476 * Activates the given view, which means that all menu actions are applied
477 * to this view. When having a split view setup, the nonactive view is
478 * usually shown in darker colors.
480 void activeViewChanged(DolphinViewContainer
* viewContainer
);
482 void closedTabsCountChanged(unsigned int count
);
485 * Is called if a new tab has been opened or a tab has been closed to
486 * enable/disable the tab actions.
488 void tabCountChanged(int count
);
491 * Updates the Window Title with the caption from the active view container
493 void updateWindowTitle();
496 * This slot is called when the user requested to unmount a removable media
497 * from the places menu
499 void slotStorageTearDownFromPlacesRequested(const QString
& mountPath
);
502 * This slot is called when the user requested to unmount a removable media
503 * _not_ from the dolphin's places menu (from the notification area for e.g.)
504 * This slot is basically connected to each removable device's
505 * Solid::StorageAccess::teardownRequested(const QString & udi)
506 * signal through the places panel.
508 void slotStorageTearDownExternallyRequested(const QString
& mountPath
);
511 * Is called when the view has finished loading the directory.
513 void slotDirectoryLoadingCompleted();
516 * Is called when the user middle clicks a toolbar button.
518 * Here middle clicking Back/Forward/Up/Home will open the resulting
519 * folder in a new tab.
521 void slotToolBarActionMiddleClicked(QAction
*action
);
524 * Is called before the Back popup menu is shown. This slot will populate
525 * the menu with history data
527 void slotAboutToShowBackPopupMenu();
530 * This slot is used by the Back Popup Menu to go back to a specific
531 * history index. The QAction::data will carry an int with the index
534 void slotGoBack(QAction
* action
);
537 * Middle clicking Back/Forward will open the resulting folder in a new tab.
539 void slotBackForwardActionMiddleClicked(QAction
*action
);
542 * Is called before the Forward popup menu is shown. This slot will populate
543 * the menu with history data
545 void slotAboutToShowForwardPopupMenu();
548 * This slot is used by the Forward Popup Menu to go forward to a specific
549 * history index. The QAction::data will carry an int with the index
552 void slotGoForward(QAction
* action
);
555 * Sets up the various menus and actions and connects them.
560 * Sets up the dock widgets and their panels.
562 void setupDockWidgets();
564 void updateFileAndEditActions();
565 void updateViewActions();
566 void updateGoActions();
568 void createControlButton();
569 void deleteControlButton();
572 * Adds the action \p action to the menu \p menu in
573 * case if it has not added already to the toolbar.
574 * @return True if the action has been added to the menu.
576 bool addActionToMenu(QAction
* action
, QMenu
* menu
);
579 * Connects the signals from the created DolphinView with
580 * the DolphinViewContainer \a container with the corresponding slots of
581 * the DolphinMainWindow. This method must be invoked each
582 * time a DolphinView has been created.
584 void connectViewSignals(DolphinViewContainer
* container
);
587 * Updates the text of the split action:
588 * If two views are shown, the text is set to "Split",
589 * otherwise the text is set to "Join". The icon
590 * is updated to match with the text and the currently active view.
592 void updateSplitAction();
595 * Sets the window sides the toolbar may be moved to based on toolbar contents.
597 void updateAllowedToolbarAreas();
599 bool isKompareInstalled() const;
602 * Creates an action for showing/hiding a panel, that is accessible
603 * in "Configure toolbars..." and "Configure shortcuts...". This is necessary
604 * as the action for toggling the dock visibility is done by Qt which
605 * is no KAction instance.
607 void createPanelAction(const QIcon
&icon
,
608 const QKeySequence
& shortcut
,
610 const QString
& actionName
);
612 /** Adds "What's This?" texts to many widgets and StandardActions. */
613 void setupWhatsThis();
615 /** Returns preferred search tool as configured in "More Search Tools" menu. */
616 QPointer
<QAction
> preferredSearchTool();
620 * Implements a custom error handling for the undo manager. This
621 * assures that all errors are shown in the status bar of Dolphin
622 * instead as modal error dialog with an OK button.
624 class UndoUiInterface
: public KIO::FileUndoManager::UiInterface
628 ~UndoUiInterface() override
;
629 void jobError(KIO::Job
* job
) override
;
632 KNewFileMenu
* m_newFileMenu
;
633 KHelpMenu
* m_helpMenu
;
634 DolphinTabWidget
* m_tabWidget
;
635 DolphinViewContainer
* m_activeViewContainer
;
637 DolphinViewActionHandler
* m_actionHandler
;
638 DolphinRemoteEncoding
* m_remoteEncoding
;
639 QPointer
<DolphinSettingsDialog
> m_settingsDialog
;
640 DolphinBookmarkHandler
* m_bookmarkHandler
;
642 // Members for the toolbar menu that is shown when the menubar is hidden:
643 QToolButton
* m_controlButton
;
644 QTimer
* m_updateToolBarTimer
;
646 KIO::OpenUrlJob
*m_lastHandleUrlOpenJob
;
648 TerminalPanel
* m_terminalPanel
;
649 PlacesPanel
* m_placesPanel
;
650 bool m_tearDownFromPlacesRequested
;
652 KToolBarPopupAction
* m_backAction
;
653 KToolBarPopupAction
* m_forwardAction
;
655 /** Makes sure that only one object is ever connected to the history. */
656 QMetaObject::Connection m_updateHistoryConnection
;
662 inline DolphinViewContainer
* DolphinMainWindow::activeViewContainer() const
664 return m_activeViewContainer
;
667 inline KNewFileMenu
* DolphinMainWindow::newFileMenu() const
669 return m_newFileMenu
;
672 #endif // DOLPHIN_MAINWINDOW_H