]>
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>
34 #include <QWeakPointer>
36 typedef KIO::FileUndoManager::CommandType CommandType
;
38 class DolphinViewActionHandler
;
39 class DolphinApplication
;
40 class DolphinSettingsDialog
;
41 class DolphinViewContainer
;
42 class DolphinRemoteEncoding
;
43 class DolphinTabWidget
;
52 * @short Main window for Dolphin.
54 * Handles the menus, toolbars and Dolphin views.
56 class DolphinMainWindow
: public KXmlGuiWindow
59 Q_CLASSINFO("D-Bus Interface", "org.kde.dolphin.MainWindow")
60 Q_PROPERTY(int id READ getId SCRIPTABLE
true)
61 friend class DolphinApplication
;
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 the "split view"
77 * option is enabled, 2 directories are collected within one tab.
79 void openDirectories(const QList
<QUrl
> &dirs
);
82 * Opens the directory which contains the files \p files
83 * and selects all files (implements the --select option
86 void openFiles(const QList
<QUrl
>& files
);
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;
96 * Pastes the clipboard data into the currently selected folder
97 * of the active view. If not exactly one folder is selected,
98 * no pasting is done at all.
100 void pasteIntoFolder();
103 * Returns the main window ID used through DBus.
108 * Implementation of the MainWindowAdaptor/QDBusAbstractAdaptor interface.
109 * Inform all affected dolphin components (panels, views) of an URL
112 void changeUrl(const QUrl
& url
);
115 * The current directory of the Terminal Panel has changed, probably because
116 * the user entered a 'cd' command. This slot calls changeUrl(url) and makes
117 * sure that the panel keeps the keyboard focus.
119 void slotTerminalDirectoryChanged(const QUrl
& url
);
121 /** Stores all settings and quits Dolphin. */
126 * Is sent if the selection of the currently active view has
129 void selectionChanged(const KFileItemList
& selection
);
132 * Is sent if the url of the currently active view has
135 void urlChanged(const QUrl
& url
);
138 * Is emitted if information of an item is requested to be shown e. g. in the panel.
139 * If item is null, no item information request is pending.
141 void requestItemInfo(const KFileItem
& item
);
144 * Is emitted if the settings have been changed.
146 void settingsChanged();
149 /** @see QWidget::showEvent() */
150 virtual void showEvent(QShowEvent
* event
) Q_DECL_OVERRIDE
;
152 /** @see QMainWindow::closeEvent() */
153 virtual void closeEvent(QCloseEvent
* event
) Q_DECL_OVERRIDE
;
155 /** @see KMainWindow::saveProperties() */
156 virtual void saveProperties(KConfigGroup
& group
) Q_DECL_OVERRIDE
;
158 /** @see KMainWindow::readProperties() */
159 virtual void readProperties(const KConfigGroup
& group
) Q_DECL_OVERRIDE
;
163 * Refreshes the views of the main window by recreating them according to
164 * the given Dolphin settings.
168 void clearStatusBar();
170 /** Updates the 'Create New...' sub menu. */
171 void updateNewMenu();
173 void createDirectory();
175 /** Shows the error message in the status bar of the active view. */
176 void showErrorMessage(const QString
& message
);
179 * Updates the state of the 'Undo' menu action dependent
180 * on the parameter \a available.
182 void slotUndoAvailable(bool available
);
184 /** Sets the text of the 'Undo' menu action to \a text. */
185 void slotUndoTextChanged(const QString
& text
);
187 /** Performs the current undo operation. */
191 * Copies all selected items to the clipboard and marks
196 /** Copies all selected items to the clipboard. */
199 /** Pastes the clipboard data to the active view. */
202 /** Replaces the URL navigator by a search box to find files. */
206 * Updates the text of the paste action dependent on
207 * the number of items which are in the clipboard.
209 void updatePasteAction();
211 /** Selects all items from the active view. */
215 * Inverts the selection of all items of the active view:
216 * Selected items get nonselected and nonselected items get
219 void invertSelection();
222 * Switches between one and two views:
223 * If one view is visible, it will get split into two views.
224 * If already two views are visible, the active view gets closed.
226 void toggleSplitView();
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();
256 /** Goes back one step of the URL history. */
259 /** Goes forward one step of the URL history. */
262 /** Goes up one hierarchy of the current URL. */
265 /** Changes the location to the home URL. */
269 * Open the previous URL in the URL history in a new tab
270 * if the middle mouse button is clicked.
272 void goBack(Qt::MouseButtons buttons
);
275 * Open the next URL in the URL history in a new tab
276 * if the middle mouse button is clicked.
278 void goForward(Qt::MouseButtons buttons
);
281 * Open the URL one hierarchy above the current URL in a new tab
282 * if the middle mouse button is clicked.
284 void goUp(Qt::MouseButtons buttons
);
287 * Open the home URL in a new tab
289 void goHome(Qt::MouseButtons buttons
);
291 /** Opens Kompare for 2 selected files. */
295 * Hides the menu bar if it is visible, makes the menu bar
296 * visible if it is hidden.
298 void toggleShowMenuBar();
300 /** Opens a terminal window for the current location. */
303 /** Opens the settings dialog for Dolphin. */
306 /** Updates the state of the 'Show Full Location' action. */
307 void slotEditableStateChanged(bool editable
);
310 * Updates the state of the 'Edit' menu actions and emits
311 * the signal selectionChanged().
313 void slotSelectionChanged(const KFileItemList
& selection
);
316 * Updates the state of the 'Back' and 'Forward' menu
317 * actions corresponding to the current history.
319 void updateHistory();
321 /** Updates the state of the 'Show filter bar' menu action. */
322 void updateFilterBarAction(bool show
);
324 /** Open a new main window. */
325 void openNewMainWindow();
328 * Opens a new view with the current URL that is part of a tab and
331 void openNewActivatedTab();
334 * Opens a new tab in the background showing the URL \a url.
336 void openNewTab(const QUrl
& url
);
339 * Opens a new tab showing the URL \a url and activates the tab.
341 void openNewActivatedTab(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 * Indicates in the statusbar that the execution of the command \a command
357 void showCommand(CommandType command
);
360 * If the URL can be listed, open it in the current view, otherwise
361 * run it through KRun.
363 void handleUrl(const QUrl
& url
);
366 * handleUrl() can trigger a stat job to see if the url can actually
369 void slotHandleUrlStatFinished(KJob
* job
);
372 * Is invoked when the write state of a folder has been changed and
373 * enables/disables the "Create New..." menu entry.
375 void slotWriteStateChanged(bool isFolderWritable
);
378 * Opens the context menu on the current mouse position.
379 * @pos Position in screen coordinates.
380 * @item File item context. If item is null, the context menu
381 * should be applied to \a url.
382 * @url URL which contains \a item.
383 * @customActions Actions that should be added to the context menu,
384 * if the file item is null.
386 void openContextMenu(const QPoint
& pos
,
387 const KFileItem
& item
,
389 const QList
<QAction
*>& customActions
);
391 void updateControlMenu();
392 void updateToolBar();
393 void slotControlButtonDeleted();
396 * Is called if the user clicked an item in the Places Panel.
397 * Reloads the view if \a url is the current URL already, and changes the
398 * current URL otherwise.
400 void slotPlaceActivated(const QUrl
& url
);
403 * Is called if the another view has been activated by changing the current
404 * tab or activating another view in split-view mode.
406 * Activates the given view, which means that all menu actions are applied
407 * to this view. When having a split view setup, the nonactive view is
408 * usually shown in darker colors.
410 void activeViewChanged(DolphinViewContainer
* viewContainer
);
412 void closedTabsCountChanged(unsigned int count
);
415 * Is called if a new tab has been opened or a tab has been closed to
416 * enable/disable the tab actions.
418 void tabCountChanged(int count
);
421 * Sets the window caption to url.fileName() if this is non-empty,
422 * "/" if the URL is "file:///", and url.protocol() otherwise.
424 void setUrlAsCaption(const QUrl
& url
);
427 * Is called when the view has finished loading the directory.
429 void slotDirectoryLoadingCompleted();
433 void setupDockWidgets();
434 void updateEditActions();
435 void updateViewActions();
436 void updateGoActions();
438 void createControlButton();
439 void deleteControlButton();
442 * Adds the action \p action to the menu \p menu in
443 * case if it has not added already to the toolbar.
444 * @return True if the action has been added to the menu.
446 bool addActionToMenu(QAction
* action
, QMenu
* menu
);
449 * Connects the signals from the created DolphinView with
450 * the DolphinViewContainer \a container with the corresponding slots of
451 * the DolphinMainWindow. This method must be invoked each
452 * time a DolphinView has been created.
454 void connectViewSignals(DolphinViewContainer
* container
);
457 * Updates the text of the split action:
458 * If two views are shown, the text is set to "Split",
459 * otherwise the text is set to "Join". The icon
460 * is updated to match with the text and the currently active view.
462 void updateSplitAction();
464 bool isKompareInstalled() const;
467 * Creates an action for showing/hiding a panel, that is accessible
468 * in "Configure toolbars..." and "Configure shortcuts...". This is necessary
469 * as the action for toggling the dock visibility is done by Qt which
470 * is no KAction instance.
472 void createPanelAction(const QIcon
&icon
,
473 const QKeySequence
& shortcut
,
475 const QString
& actionName
);
479 * Implements a custom error handling for the undo manager. This
480 * assures that all errors are shown in the status bar of Dolphin
481 * instead as modal error dialog with an OK button.
483 class UndoUiInterface
: public KIO::FileUndoManager::UiInterface
487 virtual ~UndoUiInterface();
488 virtual void jobError(KIO::Job
* job
) Q_DECL_OVERRIDE
;
491 KNewFileMenu
* m_newFileMenu
;
492 DolphinTabWidget
* m_tabWidget
;
493 DolphinViewContainer
* m_activeViewContainer
;
496 DolphinViewActionHandler
* m_actionHandler
;
497 DolphinRemoteEncoding
* m_remoteEncoding
;
498 QWeakPointer
<DolphinSettingsDialog
> m_settingsDialog
;
500 // Members for the toolbar menu that is shown when the menubar is hidden:
501 QToolButton
* m_controlButton
;
502 QTimer
* m_updateToolBarTimer
;
504 KIO::Job
* m_lastHandleUrlStatJob
;
507 inline DolphinViewContainer
* DolphinMainWindow::activeViewContainer() const
509 return m_activeViewContainer
;
512 inline KNewFileMenu
* DolphinMainWindow::newFileMenu() const
514 return m_newFileMenu
;
517 inline int DolphinMainWindow::getId() const
522 #endif // DOLPHIN_MAINWINDOW_H