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
;
55 * @short Main window for Dolphin.
57 * Handles the menus, toolbars and Dolphin views.
59 class DolphinMainWindow
: public KXmlGuiWindow
62 Q_CLASSINFO("D-Bus Interface", "org.kde.dolphin.MainWindow")
66 ~DolphinMainWindow() override
;
69 * Returns the currently active view.
70 * All menu actions are applied to this view. When
71 * having a split view setup, the nonactive view
72 * is usually shown in darker colors.
74 DolphinViewContainer
* activeViewContainer() const;
77 * Returns view container for all tabs
79 QVector
<DolphinViewContainer
*> viewContainers() const;
82 * Opens each directory in \p dirs in a separate tab. If \a splitView is set,
83 * 2 directories are collected within one tab.
84 * \pre \a dirs must contain at least one url.
86 void openDirectories(const QList
<QUrl
> &dirs
, bool splitView
);
89 * Opens the directories which contain the files \p files and selects all files.
90 * If \a splitView is set, 2 directories are collected within one tab.
91 * \pre \a files must contain at least one url.
93 void openFiles(const QList
<QUrl
>& files
, bool splitView
);
96 * Returns the 'Create New...' sub menu which also can be shared
97 * with other menus (e. g. a context menu).
99 KNewFileMenu
* newFileMenu() const;
101 void setTabsToHomeIfMountPathOpen(const QString
& mountPath
);
105 * Pastes the clipboard data into the currently selected folder
106 * of the active view. If not exactly one folder is selected,
107 * no pasting is done at all.
109 void pasteIntoFolder();
112 * Implementation of the MainWindowAdaptor/QDBusAbstractAdaptor interface.
113 * Inform all affected dolphin components (panels, views) of an URL
116 void changeUrl(const QUrl
& url
);
119 * The current directory of the Terminal Panel has changed, probably because
120 * the user entered a 'cd' command. This slot calls changeUrl(url) and makes
121 * sure that the panel keeps the keyboard focus.
123 void slotTerminalDirectoryChanged(const QUrl
& url
);
125 /** Stores all settings and quits Dolphin. */
129 * Opens a new tab and places it after the current tab
131 void openNewTabAfterCurrentTab(const QUrl
& url
);
134 * Opens a new tab and places it as the last tab
136 void openNewTabAfterLastTab(const QUrl
& url
);
140 * Is sent if the selection of the currently active view has
143 void selectionChanged(const KFileItemList
& selection
);
146 * Is sent if the url of the currently active view has
149 void urlChanged(const QUrl
& url
);
152 * Is emitted if information of an item is requested to be shown e. g. in the panel.
153 * If item is null, no item information request is pending.
155 void requestItemInfo(const KFileItem
& item
);
158 * Is emitted if the settings have been changed.
160 void settingsChanged();
163 /** @see QWidget::showEvent() */
164 void showEvent(QShowEvent
* event
) override
;
166 /** @see QMainWindow::closeEvent() */
167 void closeEvent(QCloseEvent
* event
) override
;
169 /** @see KMainWindow::saveProperties() */
170 void saveProperties(KConfigGroup
& group
) override
;
172 /** @see KMainWindow::readProperties() */
173 void readProperties(const KConfigGroup
& group
) override
;
177 * Refreshes the views of the main window by recreating them according to
178 * the given Dolphin settings.
182 void clearStatusBar();
184 /** Updates the 'Create New...' sub menu. */
185 void updateNewMenu();
187 void createDirectory();
189 /** Shows the error message in the status bar of the active view. */
190 void showErrorMessage(const QString
& message
);
193 * Updates the state of the 'Undo' menu action dependent
194 * on the parameter \a available.
196 void slotUndoAvailable(bool available
);
198 /** Sets the text of the 'Undo' menu action to \a text. */
199 void slotUndoTextChanged(const QString
& text
);
201 /** Performs the current undo operation. */
205 * Copies all selected items to the clipboard and marks
210 /** Copies all selected items to the clipboard. */
213 /** Pastes the clipboard data to the active view. */
216 /** Replaces the URL navigator by a search box to find files. */
220 * Updates the text of the paste action dependent on
221 * the number of items which are in the clipboard.
223 void updatePasteAction();
225 /** Selects all items from the active view. */
229 * Inverts the selection of all items of the active view:
230 * Selected items get nonselected and nonselected items get
233 void invertSelection();
236 * Switches between one and two views:
237 * If one view is visible, it will get split into two views.
238 * If already two views are visible, the active view gets closed.
240 void toggleSplitView();
242 /** Dedicated action to open the stash:/ ioslave in split view. */
243 void toggleSplitStash();
245 /** Reloads the currently active view. */
248 /** Stops the loading process for the currently active view. */
251 void enableStopAction();
252 void disableStopAction();
254 void showFilterBar();
257 * Toggles between edit and browse mode of the navigation bar.
259 void toggleEditLocation();
262 * Switches to the edit mode of the navigation bar and selects
263 * the whole URL, so that it can be replaced by the user. If the edit mode is
264 * already active, it is assured that the navigation bar get focused.
266 void replaceLocation();
269 * Toggles the state of the panels between a locked and unlocked layout.
271 void togglePanelLockState();
274 * Is invoked if the Terminal panel got visible/invisible and takes care
275 * that the active view has the focus if the Terminal panel is invisible.
277 void slotTerminalPanelVisibilityChanged();
279 /** Goes back one step of the URL history. */
282 /** Goes forward one step of the URL history. */
285 /** Goes up one hierarchy of the current URL. */
288 /** Changes the location to the home URL. */
291 /** Open the previous URL in the URL history in a new tab. */
292 void goBackInNewTab();
294 /** Open the next URL in the URL history in a new tab. */
295 void goForwardInNewTab();
297 /** Open the URL one hierarchy above the current URL in a new tab. */
300 /** * Open the home URL in a new tab. */
301 void goHomeInNewTab();
303 /** Opens Kompare for 2 selected files. */
307 * Hides the menu bar if it is visible, makes the menu bar
308 * visible if it is hidden.
310 void toggleShowMenuBar();
312 /** Opens a terminal window for the current location. */
315 /** Opens the settings dialog for Dolphin. */
318 /** Updates the state of the 'Show Full Location' action. */
319 void slotEditableStateChanged(bool editable
);
322 * Updates the state of the 'Edit' menu actions and emits
323 * the signal selectionChanged().
325 void slotSelectionChanged(const KFileItemList
& selection
);
328 * Updates the state of the 'Back' and 'Forward' menu
329 * actions corresponding to the current history.
331 void updateHistory();
333 /** Updates the state of the 'Show filter bar' menu action. */
334 void updateFilterBarAction(bool show
);
336 /** Open a new main window. */
337 void openNewMainWindow();
340 * Opens a new view with the current URL that is part of a tab and
343 void openNewActivatedTab();
346 * Opens a new tab in the background showing the URL \a url.
348 void openNewTab(const QUrl
& url
, DolphinTabWidget::TabPlacement tabPlacement
);
351 * Opens the selected folder in a new tab.
356 * Opens the selected folder in a new window.
358 void openInNewWindow();
361 * Show the target of the selected symlink
366 * Indicates in the statusbar that the execution of the command \a command
369 void showCommand(CommandType command
);
372 * If the URL can be listed, open it in the current view, otherwise
373 * run it through KRun.
375 void handleUrl(const QUrl
& url
);
378 * handleUrl() can trigger a stat job to see if the url can actually
381 void slotHandleUrlStatFinished(KJob
* job
);
384 * Is invoked when the write state of a folder has been changed and
385 * enables/disables the "Create New..." menu entry.
387 void slotWriteStateChanged(bool isFolderWritable
);
390 * Opens the context menu on the current mouse position.
391 * @pos Position in screen coordinates.
392 * @item File item context. If item is null, the context menu
393 * should be applied to \a url.
394 * @url URL which contains \a item.
395 * @customActions Actions that should be added to the context menu,
396 * if the file item is null.
398 void openContextMenu(const QPoint
& pos
,
399 const KFileItem
& item
,
401 const QList
<QAction
*>& customActions
);
403 void updateControlMenu();
404 void updateToolBar();
405 void slotControlButtonDeleted();
408 * Is called if the user clicked an item in the Places Panel.
409 * Reloads the view if \a url is the current URL already, and changes the
410 * current URL otherwise.
412 void slotPlaceActivated(const QUrl
& url
);
415 * Is called if the another view has been activated by changing the current
416 * tab or activating another view in split-view mode.
418 * Activates the given view, which means that all menu actions are applied
419 * to this view. When having a split view setup, the nonactive view is
420 * usually shown in darker colors.
422 void activeViewChanged(DolphinViewContainer
* viewContainer
);
424 void closedTabsCountChanged(unsigned int count
);
427 * Is called if a new tab has been opened or a tab has been closed to
428 * enable/disable the tab actions.
430 void tabCountChanged(int count
);
433 * Updates the Window Title with the caption from the active view container
435 void updateWindowTitle();
438 * This slot is called when the user requested to unmount a removable media
439 * from the places menu
441 void slotStorageTearDownFromPlacesRequested(const QString
& mountPath
);
444 * This slot is called when the user requested to unmount a removable media
445 * _not_ from the dolphin's places menu (from the notification area for e.g.)
446 * This slot is basically connected to each removable device's
447 * Solid::StorageAccess::teardownRequested(const QString & udi)
448 * signal through the places panel.
450 void slotStorageTearDownExternallyRequested(const QString
& mountPath
);
453 * Is called when the view has finished loading the directory.
455 void slotDirectoryLoadingCompleted();
458 * Is called when the user middle clicks a toolbar button.
460 * Here middle clicking Back/Forward/Up/Home will open the resulting
461 * folder in a new tab.
463 void slotToolBarActionMiddleClicked(QAction
*action
);
467 void setupDockWidgets();
468 void updateEditActions();
469 void updateViewActions();
470 void updateGoActions();
472 void createControlButton();
473 void deleteControlButton();
476 * Adds the action \p action to the menu \p menu in
477 * case if it has not added already to the toolbar.
478 * @return True if the action has been added to the menu.
480 bool addActionToMenu(QAction
* action
, QMenu
* menu
);
483 * Connects the signals from the created DolphinView with
484 * the DolphinViewContainer \a container with the corresponding slots of
485 * the DolphinMainWindow. This method must be invoked each
486 * time a DolphinView has been created.
488 void connectViewSignals(DolphinViewContainer
* container
);
491 * Updates the text of the split action:
492 * If two views are shown, the text is set to "Split",
493 * otherwise the text is set to "Join". The icon
494 * is updated to match with the text and the currently active view.
496 void updateSplitAction();
498 bool isKompareInstalled() const;
501 * Creates an action for showing/hiding a panel, that is accessible
502 * in "Configure toolbars..." and "Configure shortcuts...". This is necessary
503 * as the action for toggling the dock visibility is done by Qt which
504 * is no KAction instance.
506 void createPanelAction(const QIcon
&icon
,
507 const QKeySequence
& shortcut
,
509 const QString
& actionName
);
513 * Implements a custom error handling for the undo manager. This
514 * assures that all errors are shown in the status bar of Dolphin
515 * instead as modal error dialog with an OK button.
517 class UndoUiInterface
: public KIO::FileUndoManager::UiInterface
521 ~UndoUiInterface() override
;
522 void jobError(KIO::Job
* job
) override
;
525 KNewFileMenu
* m_newFileMenu
;
526 DolphinTabWidget
* m_tabWidget
;
527 DolphinViewContainer
* m_activeViewContainer
;
529 DolphinViewActionHandler
* m_actionHandler
;
530 DolphinRemoteEncoding
* m_remoteEncoding
;
531 QPointer
<DolphinSettingsDialog
> m_settingsDialog
;
532 DolphinBookmarkHandler
* m_bookmarkHandler
;
534 // Members for the toolbar menu that is shown when the menubar is hidden:
535 QToolButton
* m_controlButton
;
536 QTimer
* m_updateToolBarTimer
;
538 KIO::Job
* m_lastHandleUrlStatJob
;
540 TerminalPanel
* m_terminalPanel
;
541 PlacesPanel
* m_placesPanel
;
542 bool m_tearDownFromPlacesRequested
;
545 inline DolphinViewContainer
* DolphinMainWindow::activeViewContainer() const
547 return m_activeViewContainer
;
550 inline KNewFileMenu
* DolphinMainWindow::newFileMenu() const
552 return m_newFileMenu
;
555 #endif // DOLPHIN_MAINWINDOW_H