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>
36 typedef KIO::FileUndoManager::CommandType CommandType
;
38 class DolphinViewActionHandler
;
39 class DolphinSettingsDialog
;
40 class DolphinViewContainer
;
41 class DolphinRemoteEncoding
;
42 class DolphinTabWidget
;
53 * @short Main window for Dolphin.
55 * Handles the menus, toolbars and Dolphin views.
57 class DolphinMainWindow
: public KXmlGuiWindow
60 Q_CLASSINFO("D-Bus Interface", "org.kde.dolphin.MainWindow")
64 ~DolphinMainWindow() override
;
67 * Returns the currently active view.
68 * All menu actions are applied to this view. When
69 * having a split view setup, the nonactive view
70 * is usually shown in darker colors.
72 DolphinViewContainer
* activeViewContainer() const;
75 * Opens each directory in \p dirs in a separate tab. If \a splitView is set,
76 * 2 directories are collected within one tab.
77 * \pre \a dirs must contain at least one url.
79 void openDirectories(const QList
<QUrl
> &dirs
, bool splitView
);
82 * Opens the directories which contain the files \p files and selects all files.
83 * If \a splitView is set, 2 directories are collected within one tab.
84 * \pre \a files must contain at least one url.
86 void openFiles(const QList
<QUrl
>& files
, bool splitView
);
89 * Returns the 'Create New...' sub menu which also can be shared
90 * with other menus (e. g. a context menu).
92 KNewFileMenu
* newFileMenu() const;
94 void setTabsToHomeIfMountPathOpen(const QString
& mountPath
);
98 * Pastes the clipboard data into the currently selected folder
99 * of the active view. If not exactly one folder is selected,
100 * no pasting is done at all.
102 void pasteIntoFolder();
105 * Implementation of the MainWindowAdaptor/QDBusAbstractAdaptor interface.
106 * Inform all affected dolphin components (panels, views) of an URL
109 void changeUrl(const QUrl
& url
);
112 * The current directory of the Terminal Panel has changed, probably because
113 * the user entered a 'cd' command. This slot calls changeUrl(url) and makes
114 * sure that the panel keeps the keyboard focus.
116 void slotTerminalDirectoryChanged(const QUrl
& url
);
118 /** Stores all settings and quits Dolphin. */
123 * Is sent if the selection of the currently active view has
126 void selectionChanged(const KFileItemList
& selection
);
129 * Is sent if the url of the currently active view has
132 void urlChanged(const QUrl
& url
);
135 * Is emitted if information of an item is requested to be shown e. g. in the panel.
136 * If item is null, no item information request is pending.
138 void requestItemInfo(const KFileItem
& item
);
141 * Is emitted if the settings have been changed.
143 void settingsChanged();
146 /** @see QWidget::showEvent() */
147 void showEvent(QShowEvent
* event
) override
;
149 /** @see QMainWindow::closeEvent() */
150 void closeEvent(QCloseEvent
* event
) override
;
152 /** @see KMainWindow::saveProperties() */
153 void saveProperties(KConfigGroup
& group
) override
;
155 /** @see KMainWindow::readProperties() */
156 void readProperties(const KConfigGroup
& group
) override
;
160 * Refreshes the views of the main window by recreating them according to
161 * the given Dolphin settings.
165 void clearStatusBar();
167 /** Updates the 'Create New...' sub menu. */
168 void updateNewMenu();
170 void createDirectory();
172 /** Shows the error message in the status bar of the active view. */
173 void showErrorMessage(const QString
& message
);
176 * Updates the state of the 'Undo' menu action dependent
177 * on the parameter \a available.
179 void slotUndoAvailable(bool available
);
181 /** Sets the text of the 'Undo' menu action to \a text. */
182 void slotUndoTextChanged(const QString
& text
);
184 /** Performs the current undo operation. */
188 * Copies all selected items to the clipboard and marks
193 /** Copies all selected items to the clipboard. */
196 /** Pastes the clipboard data to the active view. */
199 /** Replaces the URL navigator by a search box to find files. */
203 * Updates the text of the paste action dependent on
204 * the number of items which are in the clipboard.
206 void updatePasteAction();
208 /** Selects all items from the active view. */
212 * Inverts the selection of all items of the active view:
213 * Selected items get nonselected and nonselected items get
216 void invertSelection();
219 * Switches between one and two views:
220 * If one view is visible, it will get split into two views.
221 * If already two views are visible, the active view gets closed.
223 void toggleSplitView();
225 /** Dedicated action to open the stash:/ ioslave in split view. */
226 void toggleSplitStash();
228 /** Reloads the currently active view. */
231 /** Stops the loading process for the currently active view. */
234 void enableStopAction();
235 void disableStopAction();
237 void showFilterBar();
240 * Toggles between edit and browse mode of the navigation bar.
242 void toggleEditLocation();
245 * Switches to the edit mode of the navigation bar and selects
246 * the whole URL, so that it can be replaced by the user. If the edit mode is
247 * already active, it is assured that the navigation bar get focused.
249 void replaceLocation();
252 * Toggles the state of the panels between a locked and unlocked layout.
254 void togglePanelLockState();
257 * Is invoked if the Terminal panel got visible/invisible and takes care
258 * that the active view has the focus if the Terminal panel is invisible.
260 void slotTerminalPanelVisibilityChanged();
262 /** Goes back one step of the URL history. */
265 /** Goes forward one step of the URL history. */
268 /** Goes up one hierarchy of the current URL. */
271 /** Changes the location to the home URL. */
274 /** Open the previous URL in the URL history in a new tab. */
275 void goBackInNewTab();
277 /** Open the next URL in the URL history in a new tab. */
278 void goForwardInNewTab();
280 /** Open the URL one hierarchy above the current URL in a new tab. */
283 /** * Open the home URL in a new tab. */
284 void goHomeInNewTab();
286 /** Opens Kompare for 2 selected files. */
290 * Hides the menu bar if it is visible, makes the menu bar
291 * visible if it is hidden.
293 void toggleShowMenuBar();
295 /** Opens a terminal window for the current location. */
298 /** Opens the settings dialog for Dolphin. */
301 /** Updates the state of the 'Show Full Location' action. */
302 void slotEditableStateChanged(bool editable
);
305 * Updates the state of the 'Edit' menu actions and emits
306 * the signal selectionChanged().
308 void slotSelectionChanged(const KFileItemList
& selection
);
311 * Updates the state of the 'Back' and 'Forward' menu
312 * actions corresponding to the current history.
314 void updateHistory();
316 /** Updates the state of the 'Show filter bar' menu action. */
317 void updateFilterBarAction(bool show
);
319 /** Open a new main window. */
320 void openNewMainWindow();
323 * Opens a new view with the current URL that is part of a tab and
326 void openNewActivatedTab();
329 * Opens a new tab in the background showing the URL \a url.
331 void openNewTab(const QUrl
& url
, DolphinTabWidget::TabPlacement tabPlacement
);
334 * Opens a new tab and places it after the current tab
336 void openNewTabAfterCurrentTab(const QUrl
& url
);
339 * Opens a new tab and places it as the last tab
341 void openNewTabAfterLastTab(const QUrl
& url
);
344 * Opens the selected folder in a new tab.
349 * Opens the selected folder in a new window.
351 void openInNewWindow();
354 * Show the target of the selected symlink
359 * Indicates in the statusbar that the execution of the command \a command
362 void showCommand(CommandType command
);
365 * If the URL can be listed, open it in the current view, otherwise
366 * run it through KRun.
368 void handleUrl(const QUrl
& url
);
371 * handleUrl() can trigger a stat job to see if the url can actually
374 void slotHandleUrlStatFinished(KJob
* job
);
377 * Is invoked when the write state of a folder has been changed and
378 * enables/disables the "Create New..." menu entry.
380 void slotWriteStateChanged(bool isFolderWritable
);
383 * Opens the context menu on the current mouse position.
384 * @pos Position in screen coordinates.
385 * @item File item context. If item is null, the context menu
386 * should be applied to \a url.
387 * @url URL which contains \a item.
388 * @customActions Actions that should be added to the context menu,
389 * if the file item is null.
391 void openContextMenu(const QPoint
& pos
,
392 const KFileItem
& item
,
394 const QList
<QAction
*>& customActions
);
396 void updateControlMenu();
397 void updateToolBar();
398 void slotControlButtonDeleted();
401 * Is called if the user clicked an item in the Places Panel.
402 * Reloads the view if \a url is the current URL already, and changes the
403 * current URL otherwise.
405 void slotPlaceActivated(const QUrl
& url
);
408 * Is called if the another view has been activated by changing the current
409 * tab or activating another view in split-view mode.
411 * Activates the given view, which means that all menu actions are applied
412 * to this view. When having a split view setup, the nonactive view is
413 * usually shown in darker colors.
415 void activeViewChanged(DolphinViewContainer
* viewContainer
);
417 void closedTabsCountChanged(unsigned int count
);
420 * Is called if a new tab has been opened or a tab has been closed to
421 * enable/disable the tab actions.
423 void tabCountChanged(int count
);
426 * Updates the Window Title with the caption from the active view container
428 void updateWindowTitle();
431 * This slot is called when the user requested to unmount a removable media
432 * from the places menu
434 void slotStorageTearDownFromPlacesRequested(const QString
& mountPath
);
437 * This slot is called when the user requested to unmount a removable media
438 * _not_ from the dolphin's places menu (from the notification area for e.g.)
439 * This slot is basically connected to each removable device's
440 * Solid::StorageAccess::teardownRequested(const QString & udi)
441 * signal through the places panel.
443 void slotStorageTearDownExternallyRequested(const QString
& mountPath
);
446 * Is called when the view has finished loading the directory.
448 void slotDirectoryLoadingCompleted();
451 * Is called when the user middle clicks a toolbar button.
453 * Here middle clicking Back/Forward/Up/Home will open the resulting
454 * folder in a new tab.
456 void slotToolBarActionMiddleClicked(QAction
*action
);
460 void setupDockWidgets();
461 void updateEditActions();
462 void updateViewActions();
463 void updateGoActions();
465 void createControlButton();
466 void deleteControlButton();
469 * Adds the action \p action to the menu \p menu in
470 * case if it has not added already to the toolbar.
471 * @return True if the action has been added to the menu.
473 bool addActionToMenu(QAction
* action
, QMenu
* menu
);
476 * Connects the signals from the created DolphinView with
477 * the DolphinViewContainer \a container with the corresponding slots of
478 * the DolphinMainWindow. This method must be invoked each
479 * time a DolphinView has been created.
481 void connectViewSignals(DolphinViewContainer
* container
);
484 * Updates the text of the split action:
485 * If two views are shown, the text is set to "Split",
486 * otherwise the text is set to "Join". The icon
487 * is updated to match with the text and the currently active view.
489 void updateSplitAction();
491 bool isKompareInstalled() const;
494 * Creates an action for showing/hiding a panel, that is accessible
495 * in "Configure toolbars..." and "Configure shortcuts...". This is necessary
496 * as the action for toggling the dock visibility is done by Qt which
497 * is no KAction instance.
499 void createPanelAction(const QIcon
&icon
,
500 const QKeySequence
& shortcut
,
502 const QString
& actionName
);
506 * Implements a custom error handling for the undo manager. This
507 * assures that all errors are shown in the status bar of Dolphin
508 * instead as modal error dialog with an OK button.
510 class UndoUiInterface
: public KIO::FileUndoManager::UiInterface
514 ~UndoUiInterface() override
;
515 void jobError(KIO::Job
* job
) override
;
518 KNewFileMenu
* m_newFileMenu
;
519 DolphinTabWidget
* m_tabWidget
;
520 DolphinViewContainer
* m_activeViewContainer
;
522 DolphinViewActionHandler
* m_actionHandler
;
523 DolphinRemoteEncoding
* m_remoteEncoding
;
524 QPointer
<DolphinSettingsDialog
> m_settingsDialog
;
526 // Members for the toolbar menu that is shown when the menubar is hidden:
527 QToolButton
* m_controlButton
;
528 QTimer
* m_updateToolBarTimer
;
530 KIO::Job
* m_lastHandleUrlStatJob
;
532 TerminalPanel
* m_terminalPanel
;
533 PlacesPanel
* m_placesPanel
;
534 bool m_tearDownFromPlacesRequested
;
537 inline DolphinViewContainer
* DolphinMainWindow::activeViewContainer() const
539 return m_activeViewContainer
;
542 inline KNewFileMenu
* DolphinMainWindow::newFileMenu() const
544 return m_newFileMenu
;
547 #endif // DOLPHIN_MAINWINDOW_H