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")
61 Q_PROPERTY(int id READ getId SCRIPTABLE
true)
65 virtual ~DolphinMainWindow();
68 * Returns the currently active view.
69 * All menu actions are applied to this view. When
70 * having a split view setup, the nonactive view
71 * is usually shown in darker colors.
73 DolphinViewContainer
* activeViewContainer() const;
76 * Opens each directory in \p dirs in a separate tab. If \a splitView is set,
77 * 2 directories are collected within one tab.
78 * \pre \a dirs must contain at least one url.
80 void openDirectories(const QList
<QUrl
> &dirs
, bool splitView
);
83 * Opens the directories which contain the files \p files and selects all files.
84 * If \a splitView is set, 2 directories are collected within one tab.
85 * \pre \a files must contain at least one url.
87 void openFiles(const QList
<QUrl
>& files
, bool splitView
);
90 * Returns the 'Create New...' sub menu which also can be shared
91 * with other menus (e. g. a context menu).
93 KNewFileMenu
* newFileMenu() const;
95 void setTabsToHomeIfMountPathOpen(const QString
& mountPath
);
99 * Pastes the clipboard data into the currently selected folder
100 * of the active view. If not exactly one folder is selected,
101 * no pasting is done at all.
103 void pasteIntoFolder();
106 * Returns the main window ID used through DBus.
111 * Implementation of the MainWindowAdaptor/QDBusAbstractAdaptor interface.
112 * Inform all affected dolphin components (panels, views) of an URL
115 void changeUrl(const QUrl
& url
);
118 * The current directory of the Terminal Panel has changed, probably because
119 * the user entered a 'cd' command. This slot calls changeUrl(url) and makes
120 * sure that the panel keeps the keyboard focus.
122 void slotTerminalDirectoryChanged(const QUrl
& url
);
124 /** Stores all settings and quits Dolphin. */
129 * Is sent if the selection of the currently active view has
132 void selectionChanged(const KFileItemList
& selection
);
135 * Is sent if the url of the currently active view has
138 void urlChanged(const QUrl
& url
);
141 * Is emitted if information of an item is requested to be shown e. g. in the panel.
142 * If item is null, no item information request is pending.
144 void requestItemInfo(const KFileItem
& item
);
147 * Is emitted if the settings have been changed.
149 void settingsChanged();
152 /** @see QWidget::showEvent() */
153 virtual void showEvent(QShowEvent
* event
) Q_DECL_OVERRIDE
;
155 /** @see QMainWindow::closeEvent() */
156 virtual void closeEvent(QCloseEvent
* event
) Q_DECL_OVERRIDE
;
158 /** @see KMainWindow::saveProperties() */
159 virtual void saveProperties(KConfigGroup
& group
) Q_DECL_OVERRIDE
;
161 /** @see KMainWindow::readProperties() */
162 virtual void readProperties(const KConfigGroup
& group
) Q_DECL_OVERRIDE
;
166 * Refreshes the views of the main window by recreating them according to
167 * the given Dolphin settings.
171 void clearStatusBar();
173 /** Updates the 'Create New...' sub menu. */
174 void updateNewMenu();
176 void createDirectory();
178 /** Shows the error message in the status bar of the active view. */
179 void showErrorMessage(const QString
& message
);
182 * Updates the state of the 'Undo' menu action dependent
183 * on the parameter \a available.
185 void slotUndoAvailable(bool available
);
187 /** Sets the text of the 'Undo' menu action to \a text. */
188 void slotUndoTextChanged(const QString
& text
);
190 /** Performs the current undo operation. */
194 * Copies all selected items to the clipboard and marks
199 /** Copies all selected items to the clipboard. */
202 /** Pastes the clipboard data to the active view. */
205 /** Replaces the URL navigator by a search box to find files. */
209 * Updates the text of the paste action dependent on
210 * the number of items which are in the clipboard.
212 void updatePasteAction();
214 /** Selects all items from the active view. */
218 * Inverts the selection of all items of the active view:
219 * Selected items get nonselected and nonselected items get
222 void invertSelection();
225 * Switches between one and two views:
226 * If one view is visible, it will get split into two views.
227 * If already two views are visible, the active view gets closed.
229 void toggleSplitView();
231 /** Dedicated action to open the stash:/ ioslave in split view. */
232 void toggleSplitStash();
234 /** Reloads the currently active view. */
237 /** Stops the loading process for the currently active view. */
240 void enableStopAction();
241 void disableStopAction();
243 void showFilterBar();
246 * Toggles between edit and browse mode of the navigation bar.
248 void toggleEditLocation();
251 * Switches to the edit mode of the navigation bar and selects
252 * the whole URL, so that it can be replaced by the user. If the edit mode is
253 * already active, it is assured that the navigation bar get focused.
255 void replaceLocation();
258 * Toggles the state of the panels between a locked and unlocked layout.
260 void togglePanelLockState();
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 virtual ~UndoUiInterface();
501 virtual void jobError(KIO::Job
* job
) Q_DECL_OVERRIDE
;
504 KNewFileMenu
* m_newFileMenu
;
505 DolphinTabWidget
* m_tabWidget
;
506 DolphinViewContainer
* m_activeViewContainer
;
509 DolphinViewActionHandler
* m_actionHandler
;
510 DolphinRemoteEncoding
* m_remoteEncoding
;
511 QPointer
<DolphinSettingsDialog
> m_settingsDialog
;
513 // Members for the toolbar menu that is shown when the menubar is hidden:
514 QToolButton
* m_controlButton
;
515 QTimer
* m_updateToolBarTimer
;
517 KIO::Job
* m_lastHandleUrlStatJob
;
519 TerminalPanel
* m_terminalPanel
;
520 PlacesPanel
* m_placesPanel
;
521 bool m_tearDownFromPlacesRequested
;
524 inline DolphinViewContainer
* DolphinMainWindow::activeViewContainer() const
526 return m_activeViewContainer
;
529 inline KNewFileMenu
* DolphinMainWindow::newFileMenu() const
531 return m_newFileMenu
;
534 inline int DolphinMainWindow::getId() const
539 #endif // DOLPHIN_MAINWINDOW_H