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
;
56 * @short Main window for Dolphin.
58 * Handles the menus, toolbars and Dolphin views.
60 class DolphinMainWindow
: public KXmlGuiWindow
63 Q_CLASSINFO("D-Bus Interface", "org.kde.dolphin.MainWindow")
67 ~DolphinMainWindow() override
;
70 * Returns the currently active view.
71 * All menu actions are applied to this view. When
72 * having a split view setup, the nonactive view
73 * is usually shown in darker colors.
75 DolphinViewContainer
* activeViewContainer() const;
78 * Returns view container for all tabs
80 QVector
<DolphinViewContainer
*> viewContainers() const;
83 * Opens each directory in \p dirs in a separate tab. If \a splitView is set,
84 * 2 directories are collected within one tab.
85 * \pre \a dirs must contain at least one url.
87 void openDirectories(const QList
<QUrl
> &dirs
, bool splitView
);
90 * Opens the directories which contain the files \p files and selects all files.
91 * If \a splitView is set, 2 directories are collected within one tab.
92 * \pre \a files must contain at least one url.
94 void openFiles(const QList
<QUrl
>& files
, bool splitView
);
97 * Returns the 'Create New...' sub menu which also can be shared
98 * with other menus (e. g. a context menu).
100 KNewFileMenu
* newFileMenu() const;
102 void setTabsToHomeIfMountPathOpen(const QString
& mountPath
);
106 * Opens each directory in \p dirs in a separate tab. If \a splitView is set,
107 * 2 directories are collected within one tab.
108 * \pre \a dirs must contain at least one url.
110 * @note this function is overloaded so that it is callable via DBus.
112 void openDirectories(const QStringList
&dirs
, bool splitView
);
115 * Opens the directories which contain the files \p files and selects all files.
116 * If \a splitView is set, 2 directories are collected within one tab.
117 * \pre \a files must contain at least one url.
119 * @note this is overloaded so that this function is callable via DBus.
121 void openFiles(const QStringList
&files
, bool splitView
);
124 * Tries to raise/activate the Dolphin window.
126 void activateWindow();
129 * Determines if a URL is open in any tab.
130 * @note Use of QString instead of QUrl is required to be callable via DBus.
132 * @param url URL to look for
133 * @returns true if url is currently open in a tab, false otherwise.
135 bool isUrlOpen(const QString
&url
);
139 * Pastes the clipboard data into the currently selected folder
140 * of the active view. If not exactly one folder is selected,
141 * no pasting is done at all.
143 void pasteIntoFolder();
146 * Implementation of the MainWindowAdaptor/QDBusAbstractAdaptor interface.
147 * Inform all affected dolphin components (panels, views) of an URL
150 void changeUrl(const QUrl
& url
);
153 * The current directory of the Terminal Panel has changed, probably because
154 * the user entered a 'cd' command. This slot calls changeUrl(url) and makes
155 * sure that the panel keeps the keyboard focus.
157 void slotTerminalDirectoryChanged(const QUrl
& url
);
159 /** Stores all settings and quits Dolphin. */
163 * Opens a new tab and places it after the current tab
165 void openNewTabAfterCurrentTab(const QUrl
& url
);
168 * Opens a new tab and places it as the last tab
170 void openNewTabAfterLastTab(const QUrl
& url
);
174 * Is sent if the selection of the currently active view has
177 void selectionChanged(const KFileItemList
& selection
);
180 * Is sent if the url of the currently active view has
183 void urlChanged(const QUrl
& url
);
186 * Is emitted if information of an item is requested to be shown e. g. in the panel.
187 * If item is null, no item information request is pending.
189 void requestItemInfo(const KFileItem
& item
);
192 * Is emitted if the settings have been changed.
194 void settingsChanged();
197 /** @see QWidget::showEvent() */
198 void showEvent(QShowEvent
* event
) override
;
200 /** @see QMainWindow::closeEvent() */
201 void closeEvent(QCloseEvent
* event
) override
;
203 /** @see KMainWindow::saveProperties() */
204 void saveProperties(KConfigGroup
& group
) override
;
206 /** @see KMainWindow::readProperties() */
207 void readProperties(const KConfigGroup
& group
) override
;
209 /** Handles QWhatsThisClickedEvent and passes all others on. */
210 bool event(QEvent
* event
) override
;
211 /** Handles QWhatsThisClickedEvent and passes all others on. */
212 bool eventFilter(QObject
*, QEvent
*) override
;
216 * Refreshes the views of the main window by recreating them according to
217 * the given Dolphin settings.
221 void clearStatusBar();
223 /** Updates the 'Create New...' sub menu. */
224 void updateNewMenu();
226 void createDirectory();
228 /** Shows the error message in the status bar of the active view. */
229 void showErrorMessage(const QString
& message
);
232 * Updates the state of the 'Undo' menu action dependent
233 * on the parameter \a available.
235 void slotUndoAvailable(bool available
);
237 /** Sets the text of the 'Undo' menu action to \a text. */
238 void slotUndoTextChanged(const QString
& text
);
240 /** Performs the current undo operation. */
244 * Copies all selected items to the clipboard and marks
249 /** Copies all selected items to the clipboard. */
252 /** Pastes the clipboard data to the active view. */
255 /** Replaces the URL navigator by a search box to find files. */
258 /** Updates the state of the search action according to the view container. */
259 void updateSearchAction();
262 * Updates the text of the paste action dependent on
263 * the number of items which are in the clipboard.
265 void updatePasteAction();
267 /** Selects all items from the active view. */
271 * Inverts the selection of all items of the active view:
272 * Selected items get nonselected and nonselected items get
275 void invertSelection();
278 * Switches between one and two views:
279 * If one view is visible, it will get split into two views.
280 * If already two views are visible, the active view gets closed.
282 void toggleSplitView();
284 /** Dedicated action to open the stash:/ ioslave in split view. */
285 void toggleSplitStash();
287 /** Reloads the currently active view. */
290 /** Stops the loading process for the currently active view. */
293 void enableStopAction();
294 void disableStopAction();
296 void showFilterBar();
299 * Toggles between edit and browse mode of the navigation bar.
301 void toggleEditLocation();
304 * Switches to the edit mode of the navigation bar and selects
305 * the whole URL, so that it can be replaced by the user. If the edit mode is
306 * already active, it is assured that the navigation bar get focused.
308 void replaceLocation();
311 * Toggles the state of the panels between a locked and unlocked layout.
313 void togglePanelLockState();
316 * Is invoked if the Terminal panel got visible/invisible and takes care
317 * that the active view has the focus if the Terminal panel is invisible.
319 void slotTerminalPanelVisibilityChanged();
321 /** Goes back one step of the URL history. */
324 /** Goes forward one step of the URL history. */
327 /** Goes up one hierarchy of the current URL. */
330 /** Changes the location to the home URL. */
333 /** Open the previous URL in the URL history in a new tab. */
334 void goBackInNewTab();
336 /** Open the next URL in the URL history in a new tab. */
337 void goForwardInNewTab();
339 /** Open the URL one hierarchy above the current URL in a new tab. */
342 /** * Open the home URL in a new tab. */
343 void goHomeInNewTab();
345 /** Opens Kompare for 2 selected files. */
349 * Hides the menu bar if it is visible, makes the menu bar
350 * visible if it is hidden.
352 void toggleShowMenuBar();
354 /** Opens a terminal window for the current location. */
357 /** Opens the settings dialog for Dolphin. */
360 /** Updates the state of the 'Show Full Location' action. */
361 void slotEditableStateChanged(bool editable
);
364 * Updates the state of the 'Edit' menu actions and emits
365 * the signal selectionChanged().
367 void slotSelectionChanged(const KFileItemList
& selection
);
370 * Updates the state of the 'Back' and 'Forward' menu
371 * actions corresponding to the current history.
373 void updateHistory();
375 /** Updates the state of the 'Show filter bar' menu action. */
376 void updateFilterBarAction(bool show
);
378 /** Open a new main window. */
379 void openNewMainWindow();
382 * Opens a new view with the current URL that is part of a tab and
385 void openNewActivatedTab();
388 * Adds the current URL as an entry to the Places panel
393 * Opens a new tab in the background showing the URL \a url.
395 void openNewTab(const QUrl
& url
, DolphinTabWidget::TabPlacement tabPlacement
);
398 * Opens the selected folder in a new tab.
403 * Opens the selected folder in a new window.
405 void openInNewWindow();
408 * Show the target of the selected symlink
413 * Indicates in the statusbar that the execution of the command \a command
416 void showCommand(CommandType command
);
419 * If the URL can be listed, open it in the current view, otherwise
420 * run it through KRun.
422 void handleUrl(const QUrl
& url
);
425 * handleUrl() can trigger a stat job to see if the url can actually
428 void slotHandleUrlStatFinished(KJob
* job
);
431 * Is invoked when the write state of a folder has been changed and
432 * enables/disables the "Create New..." menu entry.
434 void slotWriteStateChanged(bool isFolderWritable
);
437 * Opens the context menu on the current mouse position.
438 * @pos Position in screen coordinates.
439 * @item File item context. If item is null, the context menu
440 * should be applied to \a url.
441 * @url URL which contains \a item.
442 * @customActions Actions that should be added to the context menu,
443 * if the file item is null.
445 void openContextMenu(const QPoint
& pos
,
446 const KFileItem
& item
,
448 const QList
<QAction
*>& customActions
);
450 void updateControlMenu();
451 void updateToolBar();
452 void slotControlButtonDeleted();
455 * Is called if the user clicked an item in the Places Panel.
456 * Reloads the view if \a url is the current URL already, and changes the
457 * current URL otherwise.
459 void slotPlaceActivated(const QUrl
& url
);
462 * Is called if the another view has been activated by changing the current
463 * tab or activating another view in split-view mode.
465 * Activates the given view, which means that all menu actions are applied
466 * to this view. When having a split view setup, the nonactive view is
467 * usually shown in darker colors.
469 void activeViewChanged(DolphinViewContainer
* viewContainer
);
471 void closedTabsCountChanged(unsigned int count
);
474 * Is called if a new tab has been opened or a tab has been closed to
475 * enable/disable the tab actions.
477 void tabCountChanged(int count
);
480 * Updates the Window Title with the caption from the active view container
482 void updateWindowTitle();
485 * This slot is called when the user requested to unmount a removable media
486 * from the places menu
488 void slotStorageTearDownFromPlacesRequested(const QString
& mountPath
);
491 * This slot is called when the user requested to unmount a removable media
492 * _not_ from the dolphin's places menu (from the notification area for e.g.)
493 * This slot is basically connected to each removable device's
494 * Solid::StorageAccess::teardownRequested(const QString & udi)
495 * signal through the places panel.
497 void slotStorageTearDownExternallyRequested(const QString
& mountPath
);
500 * Is called when the view has finished loading the directory.
502 void slotDirectoryLoadingCompleted();
505 * Is called when the user middle clicks a toolbar button.
507 * Here middle clicking Back/Forward/Up/Home will open the resulting
508 * folder in a new tab.
510 void slotToolBarActionMiddleClicked(QAction
*action
);
514 * Sets up the various menus and actions and connects them.
519 * Sets up the dock widgets and their panels.
521 void setupDockWidgets();
523 void updateFileAndEditActions();
524 void updateViewActions();
525 void updateGoActions();
527 void createControlButton();
528 void deleteControlButton();
531 * Adds the action \p action to the menu \p menu in
532 * case if it has not added already to the toolbar.
533 * @return True if the action has been added to the menu.
535 bool addActionToMenu(QAction
* action
, QMenu
* menu
);
538 * Connects the signals from the created DolphinView with
539 * the DolphinViewContainer \a container with the corresponding slots of
540 * the DolphinMainWindow. This method must be invoked each
541 * time a DolphinView has been created.
543 void connectViewSignals(DolphinViewContainer
* container
);
546 * Updates the text of the split action:
547 * If two views are shown, the text is set to "Split",
548 * otherwise the text is set to "Join". The icon
549 * is updated to match with the text and the currently active view.
551 void updateSplitAction();
553 bool isKompareInstalled() const;
556 * Creates an action for showing/hiding a panel, that is accessible
557 * in "Configure toolbars..." and "Configure shortcuts...". This is necessary
558 * as the action for toggling the dock visibility is done by Qt which
559 * is no KAction instance.
561 void createPanelAction(const QIcon
&icon
,
562 const QKeySequence
& shortcut
,
564 const QString
& actionName
);
566 /** Adds "What's This?" texts to many widgets and StandardActions. */
567 void setupWhatsThis();
571 * Implements a custom error handling for the undo manager. This
572 * assures that all errors are shown in the status bar of Dolphin
573 * instead as modal error dialog with an OK button.
575 class UndoUiInterface
: public KIO::FileUndoManager::UiInterface
579 ~UndoUiInterface() override
;
580 void jobError(KIO::Job
* job
) override
;
583 KNewFileMenu
* m_newFileMenu
;
584 KHelpMenu
* m_helpMenu
;
585 DolphinTabWidget
* m_tabWidget
;
586 DolphinViewContainer
* m_activeViewContainer
;
588 DolphinViewActionHandler
* m_actionHandler
;
589 DolphinRemoteEncoding
* m_remoteEncoding
;
590 QPointer
<DolphinSettingsDialog
> m_settingsDialog
;
591 DolphinBookmarkHandler
* m_bookmarkHandler
;
593 // Members for the toolbar menu that is shown when the menubar is hidden:
594 QToolButton
* m_controlButton
;
595 QTimer
* m_updateToolBarTimer
;
597 KIO::Job
* m_lastHandleUrlStatJob
;
599 TerminalPanel
* m_terminalPanel
;
600 PlacesPanel
* m_placesPanel
;
601 bool m_tearDownFromPlacesRequested
;
604 inline DolphinViewContainer
* DolphinMainWindow::activeViewContainer() const
606 return m_activeViewContainer
;
609 inline KNewFileMenu
* DolphinMainWindow::newFileMenu() const
611 return m_newFileMenu
;
614 #endif // DOLPHIN_MAINWINDOW_H