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>
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
;
58 * @short Main window for Dolphin.
60 * Handles the menus, toolbars and Dolphin views.
62 class DolphinMainWindow
: public KXmlGuiWindow
65 Q_CLASSINFO("D-Bus Interface", "org.kde.dolphin.MainWindow")
69 ~DolphinMainWindow() override
;
72 * Returns the currently active view.
73 * All menu actions are applied to this view. When
74 * having a split view setup, the nonactive view
75 * is usually shown in darker colors.
77 DolphinViewContainer
* activeViewContainer() const;
80 * Returns view container for all tabs
82 QVector
<DolphinViewContainer
*> viewContainers() const;
85 * Opens each directory in \p dirs in a separate tab. If \a splitView is set,
86 * 2 directories are collected within one tab.
87 * \pre \a dirs must contain at least one url.
89 void openDirectories(const QList
<QUrl
> &dirs
, bool splitView
);
92 * Opens the directories which contain the files \p files and selects all files.
93 * If \a splitView is set, 2 directories are collected within one tab.
94 * \pre \a files must contain at least one url.
96 void openFiles(const QList
<QUrl
>& files
, bool splitView
);
99 * Returns the 'Create New...' sub menu which also can be shared
100 * with other menus (e. g. a context menu).
102 KNewFileMenu
* newFileMenu() const;
104 void setTabsToHomeIfMountPathOpen(const QString
& mountPath
);
108 * Opens each directory in \p dirs in a separate tab. If \a splitView is set,
109 * 2 directories are collected within one tab.
110 * \pre \a dirs must contain at least one url.
112 * @note this function is overloaded so that it is callable via DBus.
114 void openDirectories(const QStringList
&dirs
, bool splitView
);
117 * Opens the directories which contain the files \p files and selects all files.
118 * If \a splitView is set, 2 directories are collected within one tab.
119 * \pre \a files must contain at least one url.
121 * @note this is overloaded so that this function is callable via DBus.
123 void openFiles(const QStringList
&files
, bool splitView
);
126 * Tries to raise/activate the Dolphin window.
128 void activateWindow();
131 * Determines if a URL is open in any tab.
132 * @note Use of QString instead of QUrl is required to be callable via DBus.
134 * @param url URL to look for
135 * @returns true if url is currently open in a tab, false otherwise.
137 bool isUrlOpen(const QString
&url
);
141 * Pastes the clipboard data into the currently selected folder
142 * of the active view. If not exactly one folder is selected,
143 * no pasting is done at all.
145 void pasteIntoFolder();
148 * Implementation of the MainWindowAdaptor/QDBusAbstractAdaptor interface.
149 * Inform all affected dolphin components (panels, views) of an URL
152 void changeUrl(const QUrl
& url
);
155 * The current directory of the Terminal Panel has changed, probably because
156 * the user entered a 'cd' command. This slot calls changeUrl(url) and makes
157 * sure that the panel keeps the keyboard focus.
159 void slotTerminalDirectoryChanged(const QUrl
& url
);
161 /** Stores all settings and quits Dolphin. */
165 * Opens a new tab and places it after the current tab
167 void openNewTabAfterCurrentTab(const QUrl
& url
);
170 * Opens a new tab and places it as the last tab
172 void openNewTabAfterLastTab(const QUrl
& url
);
176 * Is sent if the selection of the currently active view has
179 void selectionChanged(const KFileItemList
& selection
);
182 * Is sent if the url of the currently active view has
185 void urlChanged(const QUrl
& url
);
188 * Is emitted if information of an item is requested to be shown e. g. in the panel.
189 * If item is null, no item information request is pending.
191 void requestItemInfo(const KFileItem
& item
);
194 * Is emitted if the settings have been changed.
196 void settingsChanged();
199 /** @see QWidget::showEvent() */
200 void showEvent(QShowEvent
* event
) override
;
202 /** @see QMainWindow::closeEvent() */
203 void closeEvent(QCloseEvent
* event
) override
;
205 /** @see KMainWindow::saveProperties() */
206 void saveProperties(KConfigGroup
& group
) override
;
208 /** @see KMainWindow::readProperties() */
209 void readProperties(const KConfigGroup
& group
) override
;
211 /** Handles QWhatsThisClickedEvent and passes all others on. */
212 bool event(QEvent
* event
) override
;
213 /** Handles QWhatsThisClickedEvent and passes all others on. */
214 bool eventFilter(QObject
*, QEvent
*) override
;
218 * Refreshes the views of the main window by recreating them according to
219 * the given Dolphin settings.
223 void clearStatusBar();
225 /** Updates the 'Create New...' sub menu. */
226 void updateNewMenu();
228 void createDirectory();
230 /** Shows the error message in the status bar of the active view. */
231 void showErrorMessage(const QString
& message
);
234 * Updates the state of the 'Undo' menu action dependent
235 * on the parameter \a available.
237 void slotUndoAvailable(bool available
);
239 /** Sets the text of the 'Undo' menu action to \a text. */
240 void slotUndoTextChanged(const QString
& text
);
242 /** Performs the current undo operation. */
246 * Copies all selected items to the clipboard and marks
251 /** Copies all selected items to the clipboard. */
254 /** Pastes the clipboard data to the active view. */
257 /** Replaces the URL navigator by a search box to find files. */
260 /** Updates the state of the search action according to the view container. */
261 void updateSearchAction();
264 * Updates the text of the paste action dependent on
265 * the number of items which are in the clipboard.
267 void updatePasteAction();
269 /** Selects all items from the active view. */
273 * Inverts the selection of all items of the active view:
274 * Selected items get nonselected and nonselected items get
277 void invertSelection();
280 * Switches between one and two views:
281 * If one view is visible, it will get split into two views.
282 * If already two views are visible, the active view gets closed.
284 void toggleSplitView();
286 /** Dedicated action to open the stash:/ ioslave in split view. */
287 void toggleSplitStash();
289 /** Reloads the currently active view. */
292 /** Stops the loading process for the currently active view. */
295 void enableStopAction();
296 void disableStopAction();
298 void showFilterBar();
301 * Toggles between edit and browse mode of the navigation bar.
303 void toggleEditLocation();
306 * Switches to the edit mode of the navigation bar and selects
307 * the whole URL, so that it can be replaced by the user. If the edit mode is
308 * already active, it is assured that the navigation bar get focused.
310 void replaceLocation();
313 * Toggles the state of the panels between a locked and unlocked layout.
315 void togglePanelLockState();
318 * Is invoked if the Terminal panel got visible/invisible and takes care
319 * that the active view has the focus if the Terminal panel is invisible.
321 void slotTerminalPanelVisibilityChanged();
323 /** Goes back one step of the URL history. */
326 /** Goes forward one step of the URL history. */
329 /** Goes up one hierarchy of the current URL. */
332 /** Changes the location to the home URL. */
335 /** Open the previous URL in the URL history in a new tab. */
336 void goBackInNewTab();
338 /** Open the next URL in the URL history in a new tab. */
339 void goForwardInNewTab();
341 /** Open the URL one hierarchy above the current URL in a new tab. */
344 /** * Open the home URL in a new tab. */
345 void goHomeInNewTab();
347 /** Opens Kompare for 2 selected files. */
351 * Hides the menu bar if it is visible, makes the menu bar
352 * visible if it is hidden.
354 void toggleShowMenuBar();
356 /** Updates "Open Preferred Search Tool" action. */
357 void updateOpenPreferredSearchToolAction();
359 /** Opens preferred search tool for the current location. */
360 void openPreferredSearchTool();
362 /** Opens a terminal window for the current location. */
365 /** Focus a Terminal Panel. */
366 void focusTerminalPanel();
368 /** Opens the settings dialog for Dolphin. */
371 /** Updates the state of the 'Show Full Location' action. */
372 void slotEditableStateChanged(bool editable
);
375 * Updates the state of the 'Edit' menu actions and emits
376 * the signal selectionChanged().
378 void slotSelectionChanged(const KFileItemList
& selection
);
381 * Updates the state of the 'Back' and 'Forward' menu
382 * actions corresponding to the current history.
384 void updateHistory();
386 /** Updates the state of the 'Show filter bar' menu action. */
387 void updateFilterBarAction(bool show
);
389 /** Open a new main window. */
390 void openNewMainWindow();
393 * Opens a new view with the current URL that is part of a tab and
396 void openNewActivatedTab();
399 * Adds the current URL as an entry to the Places panel
404 * Opens a new tab in the background showing the URL \a url.
406 void openNewTab(const QUrl
& url
, DolphinTabWidget::TabPlacement tabPlacement
);
409 * Opens the selected folder in a new tab.
414 * Opens the selected folder in a new window.
416 void openInNewWindow();
419 * Show the target of the selected symlink
424 * Indicates in the statusbar that the execution of the command \a command
427 void showCommand(CommandType command
);
430 * If the URL can be listed, open it in the current view, otherwise
431 * run it through KRun.
433 void handleUrl(const QUrl
& url
);
436 * handleUrl() can trigger a stat job to see if the url can actually
439 void slotHandleUrlStatFinished(KJob
* job
);
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();
594 bool isKompareInstalled() const;
597 * Creates an action for showing/hiding a panel, that is accessible
598 * in "Configure toolbars..." and "Configure shortcuts...". This is necessary
599 * as the action for toggling the dock visibility is done by Qt which
600 * is no KAction instance.
602 void createPanelAction(const QIcon
&icon
,
603 const QKeySequence
& shortcut
,
605 const QString
& actionName
);
607 /** Adds "What's This?" texts to many widgets and StandardActions. */
608 void setupWhatsThis();
611 * Returns the KIO::StatJob::mostLocalUrl() for the active container URL
612 * if it's a local file. Otherwise returns the user's home path.
614 QString
activeContainerLocalPath();
616 /** Returns preferred search tool as configured in "More Search Tools" menu. */
617 QPointer
<QAction
> preferredSearchTool();
621 * Implements a custom error handling for the undo manager. This
622 * assures that all errors are shown in the status bar of Dolphin
623 * instead as modal error dialog with an OK button.
625 class UndoUiInterface
: public KIO::FileUndoManager::UiInterface
629 ~UndoUiInterface() override
;
630 void jobError(KIO::Job
* job
) override
;
633 KNewFileMenu
* m_newFileMenu
;
634 KHelpMenu
* m_helpMenu
;
635 DolphinTabWidget
* m_tabWidget
;
636 DolphinViewContainer
* m_activeViewContainer
;
638 DolphinViewActionHandler
* m_actionHandler
;
639 DolphinRemoteEncoding
* m_remoteEncoding
;
640 QPointer
<DolphinSettingsDialog
> m_settingsDialog
;
641 DolphinBookmarkHandler
* m_bookmarkHandler
;
643 // Members for the toolbar menu that is shown when the menubar is hidden:
644 QToolButton
* m_controlButton
;
645 QTimer
* m_updateToolBarTimer
;
647 KIO::Job
* m_lastHandleUrlStatJob
;
649 TerminalPanel
* m_terminalPanel
;
650 PlacesPanel
* m_placesPanel
;
651 bool m_tearDownFromPlacesRequested
;
653 KToolBarPopupAction
* m_backAction
;
654 KToolBarPopupAction
* m_forwardAction
;
660 inline DolphinViewContainer
* DolphinMainWindow::activeViewContainer() const
662 return m_activeViewContainer
;
665 inline KNewFileMenu
* DolphinMainWindow::newFileMenu() const
667 return m_newFileMenu
;
670 #endif // DOLPHIN_MAINWINDOW_H