1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz19@gmail.com> *
3 * Copyright (C) 2006 by Stefan Monov <logixoul@gmail.com> *
4 * Copyright (C) 2006 by Cvetoslav Ludmiloff <ludmiloff@gmail.com> *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20 ***************************************************************************/
22 #ifndef DOLPHIN_MAINWINDOW_H
23 #define DOLPHIN_MAINWINDOW_H
25 #include "dolphintabwidget.h"
26 #include <config-baloo.h>
27 #include <kio/fileundomanager.h>
28 #include <KSortableList>
29 #include <kxmlguiwindow.h>
38 typedef KIO::FileUndoManager::CommandType CommandType
;
40 class DolphinBookmarkHandler
;
41 class DolphinViewActionHandler
;
42 class DolphinSettingsDialog
;
43 class DolphinViewContainer
;
44 class DolphinRemoteEncoding
;
45 class DolphinTabWidget
;
51 class KToolBarPopupAction
;
62 * @short Main window for Dolphin.
64 * Handles the menus, toolbars and Dolphin views.
66 class DolphinMainWindow
: public KXmlGuiWindow
69 Q_CLASSINFO("D-Bus Interface", "org.kde.dolphin.MainWindow")
73 ~DolphinMainWindow() override
;
76 * Returns the currently active view.
77 * All menu actions are applied to this view. When
78 * having a split view setup, the nonactive view
79 * is usually shown in darker colors.
81 DolphinViewContainer
* activeViewContainer() const;
84 * Returns view container for all tabs
86 QVector
<DolphinViewContainer
*> viewContainers() const;
89 * Opens each directory in \p dirs in a separate tab. If \a splitView is set,
90 * 2 directories are collected within one tab.
91 * \pre \a dirs must contain at least one url.
93 void openDirectories(const QList
<QUrl
> &dirs
, bool splitView
);
96 * Opens the directories which contain the files \p files and selects all files.
97 * If \a splitView is set, 2 directories are collected within one tab.
98 * \pre \a files must contain at least one url.
100 void openFiles(const QList
<QUrl
>& files
, bool splitView
);
103 * Returns the 'Create New...' sub menu which also can be shared
104 * with other menus (e. g. a context menu).
106 KNewFileMenu
* newFileMenu() const;
108 void setTabsToHomeIfMountPathOpen(const QString
& mountPath
);
112 * Opens each directory in \p dirs in a separate tab. If \a splitView is set,
113 * 2 directories are collected within one tab.
114 * \pre \a dirs must contain at least one url.
116 * @note this function is overloaded so that it is callable via DBus.
118 void openDirectories(const QStringList
&dirs
, bool splitView
);
121 * Opens the directories which contain the files \p files and selects all files.
122 * If \a splitView is set, 2 directories are collected within one tab.
123 * \pre \a files must contain at least one url.
125 * @note this is overloaded so that this function is callable via DBus.
127 void openFiles(const QStringList
&files
, bool splitView
);
130 * Tries to raise/activate the Dolphin window.
132 void activateWindow();
135 * Determines if a URL is open in any tab.
136 * @note Use of QString instead of QUrl is required to be callable via DBus.
138 * @param url URL to look for
139 * @returns true if url is currently open in a tab, false otherwise.
141 bool isUrlOpen(const QString
&url
);
145 * Pastes the clipboard data into the currently selected folder
146 * of the active view. If not exactly one folder is selected,
147 * no pasting is done at all.
149 void pasteIntoFolder();
152 * Implementation of the MainWindowAdaptor/QDBusAbstractAdaptor interface.
153 * Inform all affected dolphin components (panels, views) of an URL
156 void changeUrl(const QUrl
& url
);
159 * The current directory of the Terminal Panel has changed, probably because
160 * the user entered a 'cd' command. This slot calls changeUrl(url) and makes
161 * sure that the panel keeps the keyboard focus.
163 void slotTerminalDirectoryChanged(const QUrl
& url
);
165 /** Stores all settings and quits Dolphin. */
169 * Opens a new tab and places it after the current tab
171 void openNewTabAfterCurrentTab(const QUrl
& url
);
174 * Opens a new tab and places it as the last tab
176 void openNewTabAfterLastTab(const QUrl
& url
);
180 * Is sent if the selection of the currently active view has
183 void selectionChanged(const KFileItemList
& selection
);
186 * Is sent if the url of the currently active view has
189 void urlChanged(const QUrl
& url
);
192 * Is emitted if information of an item is requested to be shown e. g. in the panel.
193 * If item is null, no item information request is pending.
195 void requestItemInfo(const KFileItem
& item
);
198 * Is emitted if the settings have been changed.
200 void settingsChanged();
203 /** @see QWidget::showEvent() */
204 void showEvent(QShowEvent
* event
) override
;
206 /** @see QMainWindow::closeEvent() */
207 void closeEvent(QCloseEvent
* event
) override
;
209 /** @see KMainWindow::saveProperties() */
210 void saveProperties(KConfigGroup
& group
) override
;
212 /** @see KMainWindow::readProperties() */
213 void readProperties(const KConfigGroup
& group
) override
;
215 /** Handles QWhatsThisClickedEvent and passes all others on. */
216 bool event(QEvent
* event
) override
;
217 /** Handles QWhatsThisClickedEvent and passes all others on. */
218 bool eventFilter(QObject
*, QEvent
*) override
;
222 * Refreshes the views of the main window by recreating them according to
223 * the given Dolphin settings.
227 void clearStatusBar();
229 /** Updates the 'Create New...' sub menu. */
230 void updateNewMenu();
232 void createDirectory();
234 /** Shows the error message in the status bar of the active view. */
235 void showErrorMessage(const QString
& message
);
238 * Updates the state of the 'Undo' menu action dependent
239 * on the parameter \a available.
241 void slotUndoAvailable(bool available
);
243 /** Sets the text of the 'Undo' menu action to \a text. */
244 void slotUndoTextChanged(const QString
& text
);
246 /** Performs the current undo operation. */
250 * Copies all selected items to the clipboard and marks
255 /** Copies all selected items to the clipboard. */
258 /** Pastes the clipboard data to the active view. */
261 /** Replaces the URL navigator by a search box to find files. */
264 /** Updates the state of the search action according to the view container. */
265 void updateSearchAction();
268 * Updates the text of the paste action dependent on
269 * the number of items which are in the clipboard.
271 void updatePasteAction();
273 /** Selects all items from the active view. */
277 * Inverts the selection of all items of the active view:
278 * Selected items get nonselected and nonselected items get
281 void invertSelection();
284 * Switches between one and two views:
285 * If one view is visible, it will get split into two views.
286 * If already two views are visible, the active view gets closed.
288 void toggleSplitView();
290 /** Dedicated action to open the stash:/ ioslave in split view. */
291 void toggleSplitStash();
293 /** Reloads the currently active view. */
296 /** Stops the loading process for the currently active view. */
299 void enableStopAction();
300 void disableStopAction();
302 void showFilterBar();
305 * Toggles between edit and browse mode of the navigation bar.
307 void toggleEditLocation();
310 * Switches to the edit mode of the navigation bar and selects
311 * the whole URL, so that it can be replaced by the user. If the edit mode is
312 * already active, it is assured that the navigation bar get focused.
314 void replaceLocation();
317 * Toggles the state of the panels between a locked and unlocked layout.
319 void togglePanelLockState();
322 * Is invoked if the Terminal panel got visible/invisible and takes care
323 * that the active view has the focus if the Terminal panel is invisible.
325 void slotTerminalPanelVisibilityChanged();
327 /** Goes back one step of the URL history. */
330 /** Goes forward one step of the URL history. */
333 /** Goes up one hierarchy of the current URL. */
336 /** Changes the location to the home URL. */
339 /** Open the previous URL in the URL history in a new tab. */
340 void goBackInNewTab();
342 /** Open the next URL in the URL history in a new tab. */
343 void goForwardInNewTab();
345 /** Open the URL one hierarchy above the current URL in a new tab. */
348 /** * Open the home URL in a new tab. */
349 void goHomeInNewTab();
351 /** Opens Kompare for 2 selected files. */
355 * Hides the menu bar if it is visible, makes the menu bar
356 * visible if it is hidden.
358 void toggleShowMenuBar();
360 /** Updates "Open Preferred Search Tool" action. */
361 void updateOpenPreferredSearchToolAction();
363 /** Opens preferred search tool for the current location. */
364 void openPreferredSearchTool();
366 /** Opens a terminal window for the current location. */
369 /** Focus a Terminal Panel. */
370 void focusTerminalPanel();
372 /** Opens the settings dialog for Dolphin. */
375 /** Updates the state of the 'Show Full Location' action. */
376 void slotEditableStateChanged(bool editable
);
379 * Updates the state of the 'Edit' menu actions and emits
380 * the signal selectionChanged().
382 void slotSelectionChanged(const KFileItemList
& selection
);
385 * Updates the state of the 'Back' and 'Forward' menu
386 * actions corresponding to the current history.
388 void updateHistory();
390 /** Updates the state of the 'Show filter bar' menu action. */
391 void updateFilterBarAction(bool show
);
393 /** Open a new main window. */
394 void openNewMainWindow();
397 * Opens a new view with the current URL that is part of a tab and
400 void openNewActivatedTab();
403 * Adds the current URL as an entry to the Places panel
408 * Opens a new tab in the background showing the URL \a url.
410 void openNewTab(const QUrl
& url
, DolphinTabWidget::TabPlacement tabPlacement
);
413 * Opens the selected folder in a new tab.
418 * Opens the selected folder in a new window.
420 void openInNewWindow();
423 * Show the target of the selected symlink
428 * Indicates in the statusbar that the execution of the command \a command
431 void showCommand(CommandType command
);
434 * If the URL can be listed, open it in the current view, otherwise
435 * run it through KRun.
437 void handleUrl(const QUrl
& url
);
440 * Is invoked when the write state of a folder has been changed and
441 * enables/disables the "Create New..." menu entry.
443 void slotWriteStateChanged(bool isFolderWritable
);
446 * Opens the context menu on the current mouse position.
447 * @pos Position in screen coordinates.
448 * @item File item context. If item is null, the context menu
449 * should be applied to \a url.
450 * @url URL which contains \a item.
451 * @customActions Actions that should be added to the context menu,
452 * if the file item is null.
454 void openContextMenu(const QPoint
& pos
,
455 const KFileItem
& item
,
457 const QList
<QAction
*>& customActions
);
459 void updateControlMenu();
460 void updateToolBar();
461 void slotControlButtonDeleted();
464 * Is called if the user clicked an item in the Places Panel.
465 * Reloads the view if \a url is the current URL already, and changes the
466 * current URL otherwise.
468 void slotPlaceActivated(const QUrl
& url
);
471 * Is called if the another view has been activated by changing the current
472 * tab or activating another view in split-view mode.
474 * Activates the given view, which means that all menu actions are applied
475 * to this view. When having a split view setup, the nonactive view is
476 * usually shown in darker colors.
478 void activeViewChanged(DolphinViewContainer
* viewContainer
);
480 void closedTabsCountChanged(unsigned int count
);
483 * Is called if a new tab has been opened or a tab has been closed to
484 * enable/disable the tab actions.
486 void tabCountChanged(int count
);
489 * Updates the Window Title with the caption from the active view container
491 void updateWindowTitle();
494 * This slot is called when the user requested to unmount a removable media
495 * from the places menu
497 void slotStorageTearDownFromPlacesRequested(const QString
& mountPath
);
500 * This slot is called when the user requested to unmount a removable media
501 * _not_ from the dolphin's places menu (from the notification area for e.g.)
502 * This slot is basically connected to each removable device's
503 * Solid::StorageAccess::teardownRequested(const QString & udi)
504 * signal through the places panel.
506 void slotStorageTearDownExternallyRequested(const QString
& mountPath
);
509 * Is called when the view has finished loading the directory.
511 void slotDirectoryLoadingCompleted();
514 * Is called when the user middle clicks a toolbar button.
516 * Here middle clicking Back/Forward/Up/Home will open the resulting
517 * folder in a new tab.
519 void slotToolBarActionMiddleClicked(QAction
*action
);
522 * Is called before the Back popup menu is shown. This slot will populate
523 * the menu with history data
525 void slotAboutToShowBackPopupMenu();
528 * This slot is used by the Back Popup Menu to go back to a specific
529 * history index. The QAction::data will carry an int with the index
532 void slotGoBack(QAction
* action
);
535 * Middle clicking Back/Forward will open the resulting folder in a new tab.
537 void slotBackForwardActionMiddleClicked(QAction
*action
);
540 * Is called before the Forward popup menu is shown. This slot will populate
541 * the menu with history data
543 void slotAboutToShowForwardPopupMenu();
546 * This slot is used by the Forward Popup Menu to go forward to a specific
547 * history index. The QAction::data will carry an int with the index
550 void slotGoForward(QAction
* action
);
553 * Sets up the various menus and actions and connects them.
558 * Sets up the dock widgets and their panels.
560 void setupDockWidgets();
562 void updateFileAndEditActions();
563 void updateViewActions();
564 void updateGoActions();
566 void createControlButton();
567 void deleteControlButton();
570 * Adds the action \p action to the menu \p menu in
571 * case if it has not added already to the toolbar.
572 * @return True if the action has been added to the menu.
574 bool addActionToMenu(QAction
* action
, QMenu
* menu
);
577 * Connects the signals from the created DolphinView with
578 * the DolphinViewContainer \a container with the corresponding slots of
579 * the DolphinMainWindow. This method must be invoked each
580 * time a DolphinView has been created.
582 void connectViewSignals(DolphinViewContainer
* container
);
585 * Updates the text of the split action:
586 * If two views are shown, the text is set to "Split",
587 * otherwise the text is set to "Join". The icon
588 * is updated to match with the text and the currently active view.
590 void updateSplitAction();
592 bool isKompareInstalled() const;
595 * Creates an action for showing/hiding a panel, that is accessible
596 * in "Configure toolbars..." and "Configure shortcuts...". This is necessary
597 * as the action for toggling the dock visibility is done by Qt which
598 * is no KAction instance.
600 void createPanelAction(const QIcon
&icon
,
601 const QKeySequence
& shortcut
,
603 const QString
& actionName
);
605 /** Adds "What's This?" texts to many widgets and StandardActions. */
606 void setupWhatsThis();
609 * Returns the KIO::StatJob::mostLocalUrl() for the active container URL
610 * if it's a local file. Otherwise returns the user's home path.
612 QString
activeContainerLocalPath();
614 /** Returns preferred search tool as configured in "More Search Tools" menu. */
615 QPointer
<QAction
> preferredSearchTool();
619 * Implements a custom error handling for the undo manager. This
620 * assures that all errors are shown in the status bar of Dolphin
621 * instead as modal error dialog with an OK button.
623 class UndoUiInterface
: public KIO::FileUndoManager::UiInterface
627 ~UndoUiInterface() override
;
628 void jobError(KIO::Job
* job
) override
;
631 KNewFileMenu
* m_newFileMenu
;
632 KHelpMenu
* m_helpMenu
;
633 DolphinTabWidget
* m_tabWidget
;
634 DolphinViewContainer
* m_activeViewContainer
;
636 DolphinViewActionHandler
* m_actionHandler
;
637 DolphinRemoteEncoding
* m_remoteEncoding
;
638 QPointer
<DolphinSettingsDialog
> m_settingsDialog
;
639 DolphinBookmarkHandler
* m_bookmarkHandler
;
641 // Members for the toolbar menu that is shown when the menubar is hidden:
642 QToolButton
* m_controlButton
;
643 QTimer
* m_updateToolBarTimer
;
645 KIO::OpenUrlJob
*m_lastHandleUrlOpenJob
;
647 TerminalPanel
* m_terminalPanel
;
648 PlacesPanel
* m_placesPanel
;
649 bool m_tearDownFromPlacesRequested
;
651 KToolBarPopupAction
* m_backAction
;
652 KToolBarPopupAction
* m_forwardAction
;
658 inline DolphinViewContainer
* DolphinMainWindow::activeViewContainer() const
660 return m_activeViewContainer
;
663 inline KNewFileMenu
* DolphinMainWindow::newFileMenu() const
665 return m_newFileMenu
;
668 #endif // DOLPHIN_MAINWINDOW_H