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.h>
29 #include <kxmlguiwindow.h>
37 typedef KIO::FileUndoManager::CommandType CommandType
;
39 class DolphinBookmarkHandler
;
40 class DolphinViewActionHandler
;
41 class DolphinSettingsDialog
;
42 class DolphinViewContainer
;
43 class DolphinRemoteEncoding
;
44 class DolphinTabWidget
;
50 class KToolBarPopupAction
;
57 * @short Main window for Dolphin.
59 * Handles the menus, toolbars and Dolphin views.
61 class DolphinMainWindow
: public KXmlGuiWindow
64 Q_CLASSINFO("D-Bus Interface", "org.kde.dolphin.MainWindow")
68 ~DolphinMainWindow() override
;
71 * Returns the currently active view.
72 * All menu actions are applied to this view. When
73 * having a split view setup, the nonactive view
74 * is usually shown in darker colors.
76 DolphinViewContainer
* activeViewContainer() const;
79 * Returns view container for all tabs
81 QVector
<DolphinViewContainer
*> viewContainers() const;
84 * Opens each directory in \p dirs in a separate tab. If \a splitView is set,
85 * 2 directories are collected within one tab.
86 * \pre \a dirs must contain at least one url.
88 void openDirectories(const QList
<QUrl
> &dirs
, bool splitView
);
91 * Opens the directories which contain the files \p files and selects all files.
92 * If \a splitView is set, 2 directories are collected within one tab.
93 * \pre \a files must contain at least one url.
95 void openFiles(const QList
<QUrl
>& files
, bool splitView
);
98 * Returns the 'Create New...' sub menu which also can be shared
99 * with other menus (e. g. a context menu).
101 KNewFileMenu
* newFileMenu() const;
103 void setTabsToHomeIfMountPathOpen(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 /** Opens a terminal window for the current location. */
358 /** Opens the settings dialog for Dolphin. */
361 /** Updates the state of the 'Show Full Location' action. */
362 void slotEditableStateChanged(bool editable
);
365 * Updates the state of the 'Edit' menu actions and emits
366 * the signal selectionChanged().
368 void slotSelectionChanged(const KFileItemList
& selection
);
371 * Updates the state of the 'Back' and 'Forward' menu
372 * actions corresponding to the current history.
374 void updateHistory();
376 /** Updates the state of the 'Show filter bar' menu action. */
377 void updateFilterBarAction(bool show
);
379 /** Open a new main window. */
380 void openNewMainWindow();
383 * Opens a new view with the current URL that is part of a tab and
386 void openNewActivatedTab();
389 * Adds the current URL as an entry to the Places panel
394 * Opens a new tab in the background showing the URL \a url.
396 void openNewTab(const QUrl
& url
, DolphinTabWidget::TabPlacement tabPlacement
);
399 * Opens the selected folder in a new tab.
404 * Opens the selected folder in a new window.
406 void openInNewWindow();
409 * Show the target of the selected symlink
414 * Indicates in the statusbar that the execution of the command \a command
417 void showCommand(CommandType command
);
420 * If the URL can be listed, open it in the current view, otherwise
421 * run it through KRun.
423 void handleUrl(const QUrl
& url
);
426 * handleUrl() can trigger a stat job to see if the url can actually
429 void slotHandleUrlStatFinished(KJob
* job
);
432 * Is invoked when the write state of a folder has been changed and
433 * enables/disables the "Create New..." menu entry.
435 void slotWriteStateChanged(bool isFolderWritable
);
438 * Opens the context menu on the current mouse position.
439 * @pos Position in screen coordinates.
440 * @item File item context. If item is null, the context menu
441 * should be applied to \a url.
442 * @url URL which contains \a item.
443 * @customActions Actions that should be added to the context menu,
444 * if the file item is null.
446 void openContextMenu(const QPoint
& pos
,
447 const KFileItem
& item
,
449 const QList
<QAction
*>& customActions
);
451 void updateControlMenu();
452 void updateToolBar();
453 void slotControlButtonDeleted();
456 * Is called if the user clicked an item in the Places Panel.
457 * Reloads the view if \a url is the current URL already, and changes the
458 * current URL otherwise.
460 void slotPlaceActivated(const QUrl
& url
);
463 * Is called if the another view has been activated by changing the current
464 * tab or activating another view in split-view mode.
466 * Activates the given view, which means that all menu actions are applied
467 * to this view. When having a split view setup, the nonactive view is
468 * usually shown in darker colors.
470 void activeViewChanged(DolphinViewContainer
* viewContainer
);
472 void closedTabsCountChanged(unsigned int count
);
475 * Is called if a new tab has been opened or a tab has been closed to
476 * enable/disable the tab actions.
478 void tabCountChanged(int count
);
481 * Updates the Window Title with the caption from the active view container
483 void updateWindowTitle();
486 * This slot is called when the user requested to unmount a removable media
487 * from the places menu
489 void slotStorageTearDownFromPlacesRequested(const QString
& mountPath
);
492 * This slot is called when the user requested to unmount a removable media
493 * _not_ from the dolphin's places menu (from the notification area for e.g.)
494 * This slot is basically connected to each removable device's
495 * Solid::StorageAccess::teardownRequested(const QString & udi)
496 * signal through the places panel.
498 void slotStorageTearDownExternallyRequested(const QString
& mountPath
);
501 * Is called when the view has finished loading the directory.
503 void slotDirectoryLoadingCompleted();
506 * Is called when the user middle clicks a toolbar button.
508 * Here middle clicking Back/Forward/Up/Home will open the resulting
509 * folder in a new tab.
511 void slotToolBarActionMiddleClicked(QAction
*action
);
514 * Is called before the Back popup menu is shown. This slot will populate
515 * the menu with history data
517 void slotAboutToShowBackPopupMenu();
520 * This slot is used by the Back Popup Menu to go back to a specific
521 * history index. The QAction::data will carry an int with the index
524 void slotGoBack(QAction
* action
);
527 * Middle clicking Back/Forward will open the resulting folder in a new tab.
529 void slotBackForwardActionMiddleClicked(QAction
*action
);
532 * Is called before the Forward popup menu is shown. This slot will populate
533 * the menu with history data
535 void slotAboutToShowForwardPopupMenu();
538 * This slot is used by the Forward Popup Menu to go forward to a specific
539 * history index. The QAction::data will carry an int with the index
542 void slotGoForward(QAction
* action
);
545 * Sets up the various menus and actions and connects them.
550 * Sets up the dock widgets and their panels.
552 void setupDockWidgets();
554 void updateFileAndEditActions();
555 void updateViewActions();
556 void updateGoActions();
558 void createControlButton();
559 void deleteControlButton();
562 * Adds the action \p action to the menu \p menu in
563 * case if it has not added already to the toolbar.
564 * @return True if the action has been added to the menu.
566 bool addActionToMenu(QAction
* action
, QMenu
* menu
);
569 * Connects the signals from the created DolphinView with
570 * the DolphinViewContainer \a container with the corresponding slots of
571 * the DolphinMainWindow. This method must be invoked each
572 * time a DolphinView has been created.
574 void connectViewSignals(DolphinViewContainer
* container
);
577 * Updates the text of the split action:
578 * If two views are shown, the text is set to "Split",
579 * otherwise the text is set to "Join". The icon
580 * is updated to match with the text and the currently active view.
582 void updateSplitAction();
584 bool isKompareInstalled() const;
587 * Creates an action for showing/hiding a panel, that is accessible
588 * in "Configure toolbars..." and "Configure shortcuts...". This is necessary
589 * as the action for toggling the dock visibility is done by Qt which
590 * is no KAction instance.
592 void createPanelAction(const QIcon
&icon
,
593 const QKeySequence
& shortcut
,
595 const QString
& actionName
);
597 /** Adds "What's This?" texts to many widgets and StandardActions. */
598 void setupWhatsThis();
602 * Implements a custom error handling for the undo manager. This
603 * assures that all errors are shown in the status bar of Dolphin
604 * instead as modal error dialog with an OK button.
606 class UndoUiInterface
: public KIO::FileUndoManager::UiInterface
610 ~UndoUiInterface() override
;
611 void jobError(KIO::Job
* job
) override
;
614 KNewFileMenu
* m_newFileMenu
;
615 KHelpMenu
* m_helpMenu
;
616 DolphinTabWidget
* m_tabWidget
;
617 DolphinViewContainer
* m_activeViewContainer
;
619 DolphinViewActionHandler
* m_actionHandler
;
620 DolphinRemoteEncoding
* m_remoteEncoding
;
621 QPointer
<DolphinSettingsDialog
> m_settingsDialog
;
622 DolphinBookmarkHandler
* m_bookmarkHandler
;
624 // Members for the toolbar menu that is shown when the menubar is hidden:
625 QToolButton
* m_controlButton
;
626 QTimer
* m_updateToolBarTimer
;
628 KIO::Job
* m_lastHandleUrlStatJob
;
630 TerminalPanel
* m_terminalPanel
;
631 PlacesPanel
* m_placesPanel
;
632 bool m_tearDownFromPlacesRequested
;
634 KToolBarPopupAction
* m_backAction
;
635 KToolBarPopupAction
* m_forwardAction
;
638 inline DolphinViewContainer
* DolphinMainWindow::activeViewContainer() const
640 return m_activeViewContainer
;
643 inline KNewFileMenu
* DolphinMainWindow::newFileMenu() const
645 return m_newFileMenu
;
648 #endif // DOLPHIN_MAINWINDOW_H