]>
cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.h
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
;
51 * @short Main window for Dolphin.
53 * Handles the menus, toolbars and Dolphin views.
55 class DolphinMainWindow
: public KXmlGuiWindow
58 Q_CLASSINFO("D-Bus Interface", "org.kde.dolphin.MainWindow")
59 Q_PROPERTY(int id READ getId SCRIPTABLE
true)
63 virtual ~DolphinMainWindow();
66 * Returns the currently active view.
67 * All menu actions are applied to this view. When
68 * having a split view setup, the nonactive view
69 * is usually shown in darker colors.
71 DolphinViewContainer
* activeViewContainer() const;
74 * Opens each directory in \p dirs in a separate tab. If \a splitView is set,
75 * 2 directories are collected within one tab.
76 * \pre \a dirs must contain at least one url.
78 void openDirectories(const QList
<QUrl
> &dirs
, bool splitView
);
81 * Opens the directories which contain the files \p files and selects all files.
82 * If \a splitView is set, 2 directories are collected within one tab.
83 * \pre \a files must contain at least one url.
85 void openFiles(const QList
<QUrl
>& files
, bool splitView
);
88 * Returns the 'Create New...' sub menu which also can be shared
89 * with other menus (e. g. a context menu).
91 KNewFileMenu
* newFileMenu() const;
95 * Pastes the clipboard data into the currently selected folder
96 * of the active view. If not exactly one folder is selected,
97 * no pasting is done at all.
99 void pasteIntoFolder();
102 * Returns the main window ID used through DBus.
107 * Implementation of the MainWindowAdaptor/QDBusAbstractAdaptor interface.
108 * Inform all affected dolphin components (panels, views) of an URL
111 void changeUrl(const QUrl
& url
);
114 * The current directory of the Terminal Panel has changed, probably because
115 * the user entered a 'cd' command. This slot calls changeUrl(url) and makes
116 * sure that the panel keeps the keyboard focus.
118 void slotTerminalDirectoryChanged(const QUrl
& url
);
120 /** Stores all settings and quits Dolphin. */
125 * Is sent if the selection of the currently active view has
128 void selectionChanged(const KFileItemList
& selection
);
131 * Is sent if the url of the currently active view has
134 void urlChanged(const QUrl
& url
);
137 * Is emitted if information of an item is requested to be shown e. g. in the panel.
138 * If item is null, no item information request is pending.
140 void requestItemInfo(const KFileItem
& item
);
143 * Is emitted if the settings have been changed.
145 void settingsChanged();
148 /** @see QWidget::showEvent() */
149 virtual void showEvent(QShowEvent
* event
) Q_DECL_OVERRIDE
;
151 /** @see QMainWindow::closeEvent() */
152 virtual void closeEvent(QCloseEvent
* event
) Q_DECL_OVERRIDE
;
154 /** @see KMainWindow::saveProperties() */
155 virtual void saveProperties(KConfigGroup
& group
) Q_DECL_OVERRIDE
;
157 /** @see KMainWindow::readProperties() */
158 virtual void readProperties(const KConfigGroup
& group
) Q_DECL_OVERRIDE
;
162 * Refreshes the views of the main window by recreating them according to
163 * the given Dolphin settings.
167 void clearStatusBar();
169 /** Updates the 'Create New...' sub menu. */
170 void updateNewMenu();
172 void createDirectory();
174 /** Shows the error message in the status bar of the active view. */
175 void showErrorMessage(const QString
& message
);
178 * Updates the state of the 'Undo' menu action dependent
179 * on the parameter \a available.
181 void slotUndoAvailable(bool available
);
183 /** Sets the text of the 'Undo' menu action to \a text. */
184 void slotUndoTextChanged(const QString
& text
);
186 /** Performs the current undo operation. */
190 * Copies all selected items to the clipboard and marks
195 /** Copies all selected items to the clipboard. */
198 /** Pastes the clipboard data to the active view. */
201 /** Replaces the URL navigator by a search box to find files. */
205 * Updates the text of the paste action dependent on
206 * the number of items which are in the clipboard.
208 void updatePasteAction();
210 /** Selects all items from the active view. */
214 * Inverts the selection of all items of the active view:
215 * Selected items get nonselected and nonselected items get
218 void invertSelection();
221 * Switches between one and two views:
222 * If one view is visible, it will get split into two views.
223 * If already two views are visible, the active view gets closed.
225 void toggleSplitView();
227 /** Reloads the currently active view. */
230 /** Stops the loading process for the currently active view. */
233 void enableStopAction();
234 void disableStopAction();
236 void showFilterBar();
239 * Toggles between edit and browse mode of the navigation bar.
241 void toggleEditLocation();
244 * Switches to the edit mode of the navigation bar and selects
245 * the whole URL, so that it can be replaced by the user. If the edit mode is
246 * already active, it is assured that the navigation bar get focused.
248 void replaceLocation();
251 * Toggles the state of the panels between a locked and unlocked layout.
253 void togglePanelLockState();
255 /** Goes back one step of the URL history. */
258 /** Goes forward one step of the URL history. */
261 /** Goes up one hierarchy of the current URL. */
264 /** Changes the location to the home URL. */
268 * Open the previous URL in the URL history in a new tab
269 * if the middle mouse button is clicked.
271 void goBack(Qt::MouseButtons buttons
);
274 * Open the next URL in the URL history in a new tab
275 * if the middle mouse button is clicked.
277 void goForward(Qt::MouseButtons buttons
);
280 * Open the URL one hierarchy above the current URL in a new tab
281 * if the middle mouse button is clicked.
283 void goUp(Qt::MouseButtons buttons
);
286 * Open the home URL in a new tab
288 void goHome(Qt::MouseButtons buttons
);
290 /** Opens Kompare for 2 selected files. */
294 * Hides the menu bar if it is visible, makes the menu bar
295 * visible if it is hidden.
297 void toggleShowMenuBar();
299 /** Opens a terminal window for the current location. */
302 /** Opens the settings dialog for Dolphin. */
305 /** Updates the state of the 'Show Full Location' action. */
306 void slotEditableStateChanged(bool editable
);
309 * Updates the state of the 'Edit' menu actions and emits
310 * the signal selectionChanged().
312 void slotSelectionChanged(const KFileItemList
& selection
);
315 * Updates the state of the 'Back' and 'Forward' menu
316 * actions corresponding to the current history.
318 void updateHistory();
320 /** Updates the state of the 'Show filter bar' menu action. */
321 void updateFilterBarAction(bool show
);
323 /** Open a new main window. */
324 void openNewMainWindow();
327 * Opens a new view with the current URL that is part of a tab and
330 void openNewActivatedTab();
333 * Opens a new tab in the background showing the URL \a url.
335 void openNewTab(const QUrl
& url
);
338 * Opens the selected folder in a new tab.
343 * Opens the selected folder in a new window.
345 void openInNewWindow();
348 * Indicates in the statusbar that the execution of the command \a command
351 void showCommand(CommandType command
);
354 * If the URL can be listed, open it in the current view, otherwise
355 * run it through KRun.
357 void handleUrl(const QUrl
& url
);
360 * handleUrl() can trigger a stat job to see if the url can actually
363 void slotHandleUrlStatFinished(KJob
* job
);
366 * Is invoked when the write state of a folder has been changed and
367 * enables/disables the "Create New..." menu entry.
369 void slotWriteStateChanged(bool isFolderWritable
);
372 * Opens the context menu on the current mouse position.
373 * @pos Position in screen coordinates.
374 * @item File item context. If item is null, the context menu
375 * should be applied to \a url.
376 * @url URL which contains \a item.
377 * @customActions Actions that should be added to the context menu,
378 * if the file item is null.
380 void openContextMenu(const QPoint
& pos
,
381 const KFileItem
& item
,
383 const QList
<QAction
*>& customActions
);
385 void updateControlMenu();
386 void updateToolBar();
387 void slotControlButtonDeleted();
390 * Is called if the user clicked an item in the Places Panel.
391 * Reloads the view if \a url is the current URL already, and changes the
392 * current URL otherwise.
394 void slotPlaceActivated(const QUrl
& url
);
397 * Is called if the another view has been activated by changing the current
398 * tab or activating another view in split-view mode.
400 * Activates the given view, which means that all menu actions are applied
401 * to this view. When having a split view setup, the nonactive view is
402 * usually shown in darker colors.
404 void activeViewChanged(DolphinViewContainer
* viewContainer
);
406 void closedTabsCountChanged(unsigned int count
);
409 * Is called if a new tab has been opened or a tab has been closed to
410 * enable/disable the tab actions.
412 void tabCountChanged(int count
);
415 * Sets the window caption to url.fileName() if this is non-empty,
416 * "/" if the URL is "file:///", and url.protocol() otherwise.
418 void setUrlAsCaption(const QUrl
& url
);
421 * Is called when the view has finished loading the directory.
423 void slotDirectoryLoadingCompleted();
427 void setupDockWidgets();
428 void updateEditActions();
429 void updateViewActions();
430 void updateGoActions();
432 void createControlButton();
433 void deleteControlButton();
436 * Adds the action \p action to the menu \p menu in
437 * case if it has not added already to the toolbar.
438 * @return True if the action has been added to the menu.
440 bool addActionToMenu(QAction
* action
, QMenu
* menu
);
443 * Connects the signals from the created DolphinView with
444 * the DolphinViewContainer \a container with the corresponding slots of
445 * the DolphinMainWindow. This method must be invoked each
446 * time a DolphinView has been created.
448 void connectViewSignals(DolphinViewContainer
* container
);
451 * Updates the text of the split action:
452 * If two views are shown, the text is set to "Split",
453 * otherwise the text is set to "Join". The icon
454 * is updated to match with the text and the currently active view.
456 void updateSplitAction();
458 bool isKompareInstalled() const;
461 * Creates an action for showing/hiding a panel, that is accessible
462 * in "Configure toolbars..." and "Configure shortcuts...". This is necessary
463 * as the action for toggling the dock visibility is done by Qt which
464 * is no KAction instance.
466 void createPanelAction(const QIcon
&icon
,
467 const QKeySequence
& shortcut
,
469 const QString
& actionName
);
473 * Implements a custom error handling for the undo manager. This
474 * assures that all errors are shown in the status bar of Dolphin
475 * instead as modal error dialog with an OK button.
477 class UndoUiInterface
: public KIO::FileUndoManager::UiInterface
481 virtual ~UndoUiInterface();
482 virtual void jobError(KIO::Job
* job
) Q_DECL_OVERRIDE
;
485 KNewFileMenu
* m_newFileMenu
;
486 DolphinTabWidget
* m_tabWidget
;
487 DolphinViewContainer
* m_activeViewContainer
;
490 DolphinViewActionHandler
* m_actionHandler
;
491 DolphinRemoteEncoding
* m_remoteEncoding
;
492 QPointer
<DolphinSettingsDialog
> m_settingsDialog
;
494 // Members for the toolbar menu that is shown when the menubar is hidden:
495 QToolButton
* m_controlButton
;
496 QTimer
* m_updateToolBarTimer
;
498 KIO::Job
* m_lastHandleUrlStatJob
;
501 inline DolphinViewContainer
* DolphinMainWindow::activeViewContainer() const
503 return m_activeViewContainer
;
506 inline KNewFileMenu
* DolphinMainWindow::newFileMenu() const
508 return m_newFileMenu
;
511 inline int DolphinMainWindow::getId() const
516 #endif // DOLPHIN_MAINWINDOW_H