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;
95 void setTabsToHomeIfMountPathOpen(const QString
& mountPath
);
99 * Opens each directory in \p dirs in a separate tab. If \a splitView is set,
100 * 2 directories are collected within one tab.
101 * \pre \a dirs must contain at least one url.
103 * @note this function is overloaded so that it is callable via DBus.
105 void openDirectories(const QStringList
&dirs
, bool splitView
);
108 * Opens the directories which contain the files \p files and selects all files.
109 * If \a splitView is set, 2 directories are collected within one tab.
110 * \pre \a files must contain at least one url.
112 * @note this is overloaded so that this function is callable via DBus.
114 void openFiles(const QStringList
&files
, bool splitView
);
117 * Tries to raise/activate the Dolphin window.
119 void activateWindow();
122 * Determines if a URL is open in any tab.
123 * @note Use of QString instead of QUrl is required to be callable via DBus.
125 * @param url URL to look for
126 * @returns true if url is currently open in a tab, false otherwise.
128 bool isUrlOpen(const QString
&url
);
132 * Pastes the clipboard data into the currently selected folder
133 * of the active view. If not exactly one folder is selected,
134 * no pasting is done at all.
136 void pasteIntoFolder();
139 * Implementation of the MainWindowAdaptor/QDBusAbstractAdaptor interface.
140 * Inform all affected dolphin components (panels, views) of an URL
143 void changeUrl(const QUrl
& url
);
146 * The current directory of the Terminal Panel has changed, probably because
147 * the user entered a 'cd' command. This slot calls changeUrl(url) and makes
148 * sure that the panel keeps the keyboard focus.
150 void slotTerminalDirectoryChanged(const QUrl
& url
);
152 /** Stores all settings and quits Dolphin. */
156 * Opens a new tab and places it after the current tab
158 void openNewTabAfterCurrentTab(const QUrl
& url
);
161 * Opens a new tab and places it as the last tab
163 void openNewTabAfterLastTab(const QUrl
& url
);
167 * Is sent if the selection of the currently active view has
170 void selectionChanged(const KFileItemList
& selection
);
173 * Is sent if the url of the currently active view has
176 void urlChanged(const QUrl
& url
);
179 * Is emitted if information of an item is requested to be shown e. g. in the panel.
180 * If item is null, no item information request is pending.
182 void requestItemInfo(const KFileItem
& item
);
185 * Is emitted if the settings have been changed.
187 void settingsChanged();
190 /** @see QWidget::showEvent() */
191 void showEvent(QShowEvent
* event
) override
;
193 /** @see QMainWindow::closeEvent() */
194 void closeEvent(QCloseEvent
* event
) override
;
196 /** @see KMainWindow::saveProperties() */
197 void saveProperties(KConfigGroup
& group
) override
;
199 /** @see KMainWindow::readProperties() */
200 void readProperties(const KConfigGroup
& group
) override
;
202 /** Handles QWhatsThisClickedEvent and passes all others on. */
203 bool event(QEvent
* event
) override
;
204 /** Handles QWhatsThisClickedEvent and passes all others on. */
205 bool eventFilter(QObject
*, QEvent
*) override
;
209 * Refreshes the views of the main window by recreating them according to
210 * the given Dolphin settings.
214 void clearStatusBar();
216 /** Updates the 'Create New...' sub menu. */
217 void updateNewMenu();
219 void createDirectory();
221 /** Shows the error message in the status bar of the active view. */
222 void showErrorMessage(const QString
& message
);
225 * Updates the state of the 'Undo' menu action dependent
226 * on the parameter \a available.
228 void slotUndoAvailable(bool available
);
230 /** Sets the text of the 'Undo' menu action to \a text. */
231 void slotUndoTextChanged(const QString
& text
);
233 /** Performs the current undo operation. */
237 * Copies all selected items to the clipboard and marks
242 /** Copies all selected items to the clipboard. */
245 /** Pastes the clipboard data to the active view. */
248 /** Replaces the URL navigator by a search box to find files. */
251 /** Updates the state of the search action according to the view container. */
252 void updateSearchAction();
255 * Updates the text of the paste action dependent on
256 * the number of items which are in the clipboard.
258 void updatePasteAction();
260 /** Selects all items from the active view. */
264 * Inverts the selection of all items of the active view:
265 * Selected items get nonselected and nonselected items get
268 void invertSelection();
271 * Switches between one and two views:
272 * If one view is visible, it will get split into two views.
273 * If already two views are visible, the active view gets closed.
275 void toggleSplitView();
277 /** Dedicated action to open the stash:/ ioslave in split view. */
278 void toggleSplitStash();
280 /** Reloads the currently active view. */
283 /** Stops the loading process for the currently active view. */
286 void enableStopAction();
287 void disableStopAction();
289 void showFilterBar();
292 * Toggles between edit and browse mode of the navigation bar.
294 void toggleEditLocation();
297 * Switches to the edit mode of the navigation bar and selects
298 * the whole URL, so that it can be replaced by the user. If the edit mode is
299 * already active, it is assured that the navigation bar get focused.
301 void replaceLocation();
304 * Toggles the state of the panels between a locked and unlocked layout.
306 void togglePanelLockState();
309 * Is invoked if the Terminal panel got visible/invisible and takes care
310 * that the active view has the focus if the Terminal panel is invisible.
312 void slotTerminalPanelVisibilityChanged();
314 /** Goes back one step of the URL history. */
317 /** Goes forward one step of the URL history. */
320 /** Goes up one hierarchy of the current URL. */
323 /** Changes the location to the home URL. */
326 /** Open the previous URL in the URL history in a new tab. */
327 void goBackInNewTab();
329 /** Open the next URL in the URL history in a new tab. */
330 void goForwardInNewTab();
332 /** Open the URL one hierarchy above the current URL in a new tab. */
335 /** * Open the home URL in a new tab. */
336 void goHomeInNewTab();
338 /** Opens Kompare for 2 selected files. */
342 * Hides the menu bar if it is visible, makes the menu bar
343 * visible if it is hidden.
345 void toggleShowMenuBar();
347 /** Updates "Open Preferred Search Tool" action. */
348 void updateOpenPreferredSearchToolAction();
350 /** Opens preferred search tool for the current location. */
351 void openPreferredSearchTool();
353 /** Opens a terminal window for the current location. */
356 /** Focus a Terminal Panel. */
357 void focusTerminalPanel();
359 /** Opens the settings dialog for Dolphin. */
362 /** Updates the state of the 'Show Full Location' action. */
363 void slotEditableStateChanged(bool editable
);
366 * Updates the state of the 'Edit' menu actions and emits
367 * the signal selectionChanged().
369 void slotSelectionChanged(const KFileItemList
& selection
);
372 * Updates the state of the 'Back' and 'Forward' menu
373 * actions corresponding to the current history.
375 void updateHistory();
377 /** Updates the state of the 'Show filter bar' menu action. */
378 void updateFilterBarAction(bool show
);
380 /** Open a new main window. */
381 void openNewMainWindow();
384 * Opens a new view with the current URL that is part of a tab and
387 void openNewActivatedTab();
390 * Adds the current URL as an entry to the Places panel
395 * Opens a new tab in the background showing the URL \a url.
397 void openNewTab(const QUrl
& url
, DolphinTabWidget::TabPlacement tabPlacement
);
400 * Opens the selected folder in a new tab.
405 * Opens the selected folder in a new window.
407 void openInNewWindow();
410 * Show the target of the selected symlink
415 * Indicates in the statusbar that the execution of the command \a command
418 void showCommand(CommandType command
);
421 * If the URL can be listed, open it in the current view, otherwise
422 * run it through KRun.
424 void handleUrl(const QUrl
& url
);
427 * Is invoked when the write state of a folder has been changed and
428 * enables/disables the "Create New..." menu entry.
430 void slotWriteStateChanged(bool isFolderWritable
);
433 * Opens the context menu on the current mouse position.
434 * @pos Position in screen coordinates.
435 * @item File item context. If item is null, the context menu
436 * should be applied to \a url.
437 * @url URL which contains \a item.
438 * @customActions Actions that should be added to the context menu,
439 * if the file item is null.
441 void openContextMenu(const QPoint
& pos
,
442 const KFileItem
& item
,
444 const QList
<QAction
*>& customActions
);
446 void updateControlMenu();
447 void updateToolBar();
448 void slotControlButtonDeleted();
451 * Is called if the user clicked an item in the Places Panel.
452 * Reloads the view if \a url is the current URL already, and changes the
453 * current URL otherwise.
455 void slotPlaceActivated(const QUrl
& url
);
458 * Is called if the another view has been activated by changing the current
459 * tab or activating another view in split-view mode.
461 * Activates the given view, which means that all menu actions are applied
462 * to this view. When having a split view setup, the nonactive view is
463 * usually shown in darker colors.
465 void activeViewChanged(DolphinViewContainer
* viewContainer
);
467 void closedTabsCountChanged(unsigned int count
);
470 * Is called if a new tab has been opened or a tab has been closed to
471 * enable/disable the tab actions.
473 void tabCountChanged(int count
);
476 * Updates the Window Title with the caption from the active view container
478 void updateWindowTitle();
481 * This slot is called when the user requested to unmount a removable media
482 * from the places menu
484 void slotStorageTearDownFromPlacesRequested(const QString
& mountPath
);
487 * This slot is called when the user requested to unmount a removable media
488 * _not_ from the dolphin's places menu (from the notification area for e.g.)
489 * This slot is basically connected to each removable device's
490 * Solid::StorageAccess::teardownRequested(const QString & udi)
491 * signal through the places panel.
493 void slotStorageTearDownExternallyRequested(const QString
& mountPath
);
496 * Is called when the view has finished loading the directory.
498 void slotDirectoryLoadingCompleted();
501 * Is called when the user middle clicks a toolbar button.
503 * Here middle clicking Back/Forward/Up/Home will open the resulting
504 * folder in a new tab.
506 void slotToolBarActionMiddleClicked(QAction
*action
);
509 * Is called before the Back popup menu is shown. This slot will populate
510 * the menu with history data
512 void slotAboutToShowBackPopupMenu();
515 * This slot is used by the Back Popup Menu to go back to a specific
516 * history index. The QAction::data will carry an int with the index
519 void slotGoBack(QAction
* action
);
522 * Middle clicking Back/Forward will open the resulting folder in a new tab.
524 void slotBackForwardActionMiddleClicked(QAction
*action
);
527 * Is called before the Forward popup menu is shown. This slot will populate
528 * the menu with history data
530 void slotAboutToShowForwardPopupMenu();
533 * This slot is used by the Forward Popup Menu to go forward to a specific
534 * history index. The QAction::data will carry an int with the index
537 void slotGoForward(QAction
* action
);
540 * Sets up the various menus and actions and connects them.
545 * Sets up the dock widgets and their panels.
547 void setupDockWidgets();
549 void updateFileAndEditActions();
550 void updateViewActions();
551 void updateGoActions();
553 void createControlButton();
554 void deleteControlButton();
557 * Adds the action \p action to the menu \p menu in
558 * case if it has not added already to the toolbar.
559 * @return True if the action has been added to the menu.
561 bool addActionToMenu(QAction
* action
, QMenu
* menu
);
564 * Connects the signals from the created DolphinView with
565 * the DolphinViewContainer \a container with the corresponding slots of
566 * the DolphinMainWindow. This method must be invoked each
567 * time a DolphinView has been created.
569 void connectViewSignals(DolphinViewContainer
* container
);
572 * Updates the text of the split action:
573 * If two views are shown, the text is set to "Split",
574 * otherwise the text is set to "Join". The icon
575 * is updated to match with the text and the currently active view.
577 void updateSplitAction();
579 bool isKompareInstalled() const;
582 * Creates an action for showing/hiding a panel, that is accessible
583 * in "Configure toolbars..." and "Configure shortcuts...". This is necessary
584 * as the action for toggling the dock visibility is done by Qt which
585 * is no KAction instance.
587 void createPanelAction(const QIcon
&icon
,
588 const QKeySequence
& shortcut
,
590 const QString
& actionName
);
592 /** Adds "What's This?" texts to many widgets and StandardActions. */
593 void setupWhatsThis();
596 * Returns the KIO::StatJob::mostLocalUrl() for the active container URL
597 * if it's a local file. Otherwise returns the user's home path.
599 QString
activeContainerLocalPath();
601 /** Returns preferred search tool as configured in "More Search Tools" menu. */
602 QPointer
<QAction
> preferredSearchTool();
606 * Implements a custom error handling for the undo manager. This
607 * assures that all errors are shown in the status bar of Dolphin
608 * instead as modal error dialog with an OK button.
610 class UndoUiInterface
: public KIO::FileUndoManager::UiInterface
614 ~UndoUiInterface() override
;
615 void jobError(KIO::Job
* job
) override
;
618 KNewFileMenu
* m_newFileMenu
;
619 KHelpMenu
* m_helpMenu
;
620 DolphinTabWidget
* m_tabWidget
;
621 DolphinViewContainer
* m_activeViewContainer
;
623 DolphinViewActionHandler
* m_actionHandler
;
624 DolphinRemoteEncoding
* m_remoteEncoding
;
625 QPointer
<DolphinSettingsDialog
> m_settingsDialog
;
626 DolphinBookmarkHandler
* m_bookmarkHandler
;
628 // Members for the toolbar menu that is shown when the menubar is hidden:
629 QToolButton
* m_controlButton
;
630 QTimer
* m_updateToolBarTimer
;
632 KIO::OpenUrlJob
*m_lastHandleUrlOpenJob
;
634 TerminalPanel
* m_terminalPanel
;
635 PlacesPanel
* m_placesPanel
;
636 bool m_tearDownFromPlacesRequested
;
638 KToolBarPopupAction
* m_backAction
;
639 KToolBarPopupAction
* m_forwardAction
;
645 inline DolphinViewContainer
* DolphinMainWindow::activeViewContainer() const
647 return m_activeViewContainer
;
650 inline KNewFileMenu
* DolphinMainWindow::newFileMenu() const
652 return m_newFileMenu
;
655 #endif // DOLPHIN_MAINWINDOW_H