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 <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
);
334 * Opens the selected folder in a new tab.
339 * Opens the selected folder in a new window.
341 void openInNewWindow();
344 * Indicates in the statusbar that the execution of the command \a command
347 void showCommand(CommandType command
);
350 * If the URL can be listed, open it in the current view, otherwise
351 * run it through KRun.
353 void handleUrl(const QUrl
& url
);
356 * handleUrl() can trigger a stat job to see if the url can actually
359 void slotHandleUrlStatFinished(KJob
* job
);
362 * Is invoked when the write state of a folder has been changed and
363 * enables/disables the "Create New..." menu entry.
365 void slotWriteStateChanged(bool isFolderWritable
);
368 * Opens the context menu on the current mouse position.
369 * @pos Position in screen coordinates.
370 * @item File item context. If item is null, the context menu
371 * should be applied to \a url.
372 * @url URL which contains \a item.
373 * @customActions Actions that should be added to the context menu,
374 * if the file item is null.
376 void openContextMenu(const QPoint
& pos
,
377 const KFileItem
& item
,
379 const QList
<QAction
*>& customActions
);
381 void updateControlMenu();
382 void updateToolBar();
383 void slotControlButtonDeleted();
386 * Is called if the user clicked an item in the Places Panel.
387 * Reloads the view if \a url is the current URL already, and changes the
388 * current URL otherwise.
390 void slotPlaceActivated(const QUrl
& url
);
393 * Is called if the another view has been activated by changing the current
394 * tab or activating another view in split-view mode.
396 * Activates the given view, which means that all menu actions are applied
397 * to this view. When having a split view setup, the nonactive view is
398 * usually shown in darker colors.
400 void activeViewChanged(DolphinViewContainer
* viewContainer
);
402 void closedTabsCountChanged(unsigned int count
);
405 * Is called if a new tab has been opened or a tab has been closed to
406 * enable/disable the tab actions.
408 void tabCountChanged(int count
);
411 * Sets the window caption to url.fileName() if this is non-empty,
412 * "/" if the URL is "file:///", and url.protocol() otherwise.
414 void setUrlAsCaption(const QUrl
& url
);
417 * This slot is called when the user requested to unmount a removable media
418 * from the places menu
420 void slotStorageTearDownFromPlacesRequested(const QString
& mountPath
);
423 * This slot is called when the user requested to unmount a removable media
424 * _not_ from the dolphin's places menu (from the notification area for e.g.)
425 * This slot is basically connected to each removable device's
426 * Solid::StorageAccess::teardownRequested(const QString & udi)
427 * signal through the places panel.
429 void slotStorageTearDownExternallyRequested(const QString
& mountPath
);
432 * Is called when the view has finished loading the directory.
434 void slotDirectoryLoadingCompleted();
437 * Is called when the user middle clicks a toolbar button.
439 * Here middle clicking Back/Forward/Up/Home will open the resulting
440 * folder in a new tab.
442 void slotToolBarActionMiddleClicked(QAction
*action
);
446 void setupDockWidgets();
447 void updateEditActions();
448 void updateViewActions();
449 void updateGoActions();
451 void createControlButton();
452 void deleteControlButton();
455 * Adds the action \p action to the menu \p menu in
456 * case if it has not added already to the toolbar.
457 * @return True if the action has been added to the menu.
459 bool addActionToMenu(QAction
* action
, QMenu
* menu
);
462 * Connects the signals from the created DolphinView with
463 * the DolphinViewContainer \a container with the corresponding slots of
464 * the DolphinMainWindow. This method must be invoked each
465 * time a DolphinView has been created.
467 void connectViewSignals(DolphinViewContainer
* container
);
470 * Updates the text of the split action:
471 * If two views are shown, the text is set to "Split",
472 * otherwise the text is set to "Join". The icon
473 * is updated to match with the text and the currently active view.
475 void updateSplitAction();
477 bool isKompareInstalled() const;
480 * Creates an action for showing/hiding a panel, that is accessible
481 * in "Configure toolbars..." and "Configure shortcuts...". This is necessary
482 * as the action for toggling the dock visibility is done by Qt which
483 * is no KAction instance.
485 void createPanelAction(const QIcon
&icon
,
486 const QKeySequence
& shortcut
,
488 const QString
& actionName
);
492 * Implements a custom error handling for the undo manager. This
493 * assures that all errors are shown in the status bar of Dolphin
494 * instead as modal error dialog with an OK button.
496 class UndoUiInterface
: public KIO::FileUndoManager::UiInterface
500 ~UndoUiInterface() override
;
501 void jobError(KIO::Job
* job
) override
;
504 KNewFileMenu
* m_newFileMenu
;
505 DolphinTabWidget
* m_tabWidget
;
506 DolphinViewContainer
* m_activeViewContainer
;
508 DolphinViewActionHandler
* m_actionHandler
;
509 DolphinRemoteEncoding
* m_remoteEncoding
;
510 QPointer
<DolphinSettingsDialog
> m_settingsDialog
;
512 // Members for the toolbar menu that is shown when the menubar is hidden:
513 QToolButton
* m_controlButton
;
514 QTimer
* m_updateToolBarTimer
;
516 KIO::Job
* m_lastHandleUrlStatJob
;
518 TerminalPanel
* m_terminalPanel
;
519 PlacesPanel
* m_placesPanel
;
520 bool m_tearDownFromPlacesRequested
;
523 inline DolphinViewContainer
* DolphinMainWindow::activeViewContainer() const
525 return m_activeViewContainer
;
528 inline KNewFileMenu
* DolphinMainWindow::newFileMenu() const
530 return m_newFileMenu
;
533 #endif // DOLPHIN_MAINWINDOW_H