]>
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 <KFileItemDelegate>
28 #include <kio/fileundomanager.h>
29 #include <ksortablelist.h>
30 #include <kxmlguiwindow.h>
35 #include <QWeakPointer>
37 typedef KIO::FileUndoManager::CommandType CommandType
;
39 class DolphinViewActionHandler
;
40 class DolphinApplication
;
41 class DolphinSettingsDialog
;
42 class DolphinViewContainer
;
43 class DolphinRemoteEncoding
;
44 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)
62 friend class DolphinApplication
;
66 virtual ~DolphinMainWindow();
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 * Opens each directory in \p dirs in a separate tab. If the "split view"
78 * option is enabled, 2 directories are collected within one tab.
80 void openDirectories(const QList
<KUrl
>& dirs
);
83 * Opens the directory which contains the files \p files
84 * and selects all files (implements the --select option
87 void openFiles(const QList
<KUrl
>& files
);
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;
97 * Pastes the clipboard data into the currently selected folder
98 * of the active view. If not exactly one folder is selected,
99 * no pasting is done at all.
101 void pasteIntoFolder();
104 * Returns the main window ID used through DBus.
109 * Implementation of the MainWindowAdaptor/QDBusAbstractAdaptor interface.
110 * Inform all affected dolphin components (panels, views) of an URL
113 void changeUrl(const KUrl
& url
);
116 * The current directory of the Terminal Panel has changed, probably because
117 * the user entered a 'cd' command. This slot calls changeUrl(url) and makes
118 * sure that the panel keeps the keyboard focus.
120 void slotTerminalDirectoryChanged(const KUrl
& url
);
122 /** Stores all settings and quits Dolphin. */
127 * Is sent if the selection of the currently active view has
130 void selectionChanged(const KFileItemList
& selection
);
133 * Is sent if the url of the currently active view has
136 void urlChanged(const KUrl
& url
);
139 * Is emitted if information of an item is requested to be shown e. g. in the panel.
140 * If item is null, no item information request is pending.
142 void requestItemInfo(const KFileItem
& item
);
145 * Is emitted if the settings have been changed.
147 void settingsChanged();
150 /** @see QWidget::showEvent() */
151 virtual void showEvent(QShowEvent
* event
);
153 /** @see QMainWindow::closeEvent() */
154 virtual void closeEvent(QCloseEvent
* event
);
156 /** @see KMainWindow::saveProperties() */
157 virtual void saveProperties(KConfigGroup
& group
);
159 /** @see KMainWindow::readProperties() */
160 virtual void readProperties(const KConfigGroup
& group
);
164 * Refreshes the views of the main window by recreating them according to
165 * the given Dolphin settings.
169 void clearStatusBar();
171 /** Updates the 'Create New...' sub menu. */
172 void updateNewMenu();
174 void createDirectory();
176 /** Shows the error message in the status bar of the active view. */
177 void showErrorMessage(const QString
& message
);
180 * Updates the state of the 'Undo' menu action dependent
181 * on the parameter \a available.
183 void slotUndoAvailable(bool available
);
185 /** Sets the text of the 'Undo' menu action to \a text. */
186 void slotUndoTextChanged(const QString
& text
);
188 /** Performs the current undo operation. */
192 * Copies all selected items to the clipboard and marks
197 /** Copies all selected items to the clipboard. */
200 /** Pastes the clipboard data to the active view. */
203 /** Replaces the URL navigator by a search box to find files. */
207 * Updates the text of the paste action dependent on
208 * the number of items which are in the clipboard.
210 void updatePasteAction();
212 /** Selects all items from the active view. */
216 * Inverts the selection of all items of the active view:
217 * Selected items get nonselected and nonselected items get
220 void invertSelection();
223 * Switches between one and two views:
224 * If one view is visible, it will get split into two views.
225 * If already two views are visible, the active view gets closed.
227 void toggleSplitView();
229 /** Reloads the currently active view. */
232 /** Stops the loading process for the currently active view. */
235 void enableStopAction();
236 void disableStopAction();
238 void showFilterBar();
241 * Toggles between edit and browse mode of the navigation bar.
243 void toggleEditLocation();
246 * Switches to the edit mode of the navigation bar and selects
247 * the whole URL, so that it can be replaced by the user. If the edit mode is
248 * already active, it is assured that the navigation bar get focused.
250 void replaceLocation();
253 * Toggles the state of the panels between a locked and unlocked layout.
255 void togglePanelLockState();
257 /** Goes back one step of the URL history. */
260 /** Goes forward one step of the URL history. */
263 /** Goes up one hierarchy of the current URL. */
266 /** Changes the location to the home URL. */
270 * Open the previous URL in the URL history in a new tab
271 * if the middle mouse button is clicked.
273 void goBack(Qt::MouseButtons buttons
);
276 * Open the next URL in the URL history in a new tab
277 * if the middle mouse button is clicked.
279 void goForward(Qt::MouseButtons buttons
);
282 * Open the URL one hierarchy above the current URL in a new tab
283 * if the middle mouse button is clicked.
285 void goUp(Qt::MouseButtons buttons
);
288 * Open the home URL in a new tab
290 void goHome(Qt::MouseButtons buttons
);
292 /** Opens Kompare for 2 selected files. */
296 * Hides the menu bar if it is visible, makes the menu bar
297 * visible if it is hidden.
299 void toggleShowMenuBar();
301 /** Opens a terminal window for the current location. */
304 /** Opens the settings dialog for Dolphin. */
307 /** Updates the state of the 'Show Full Location' action. */
308 void slotEditableStateChanged(bool editable
);
311 * Updates the state of the 'Edit' menu actions and emits
312 * the signal selectionChanged().
314 void slotSelectionChanged(const KFileItemList
& selection
);
316 /** Emits the signal requestItemInfo(). */
317 void slotRequestItemInfo(const KFileItem
&);
320 * Updates the state of the 'Back' and 'Forward' menu
321 * actions corresponding to the current history.
323 void updateHistory();
325 /** Updates the state of the 'Show filter bar' menu action. */
326 void updateFilterBarAction(bool show
);
328 /** Open a new main window. */
329 void openNewMainWindow();
332 * Opens a new view with the current URL that is part of a tab and
335 void openNewActivatedTab();
338 * Opens a new tab in the background showing the URL \a url.
340 void openNewTab(const KUrl
& url
);
343 * Opens a new tab showing the URL \a url and activates the tab.
345 void openNewActivatedTab(const KUrl
& url
);
348 * Opens the selected folder in a new tab.
353 * Opens the selected folder in a new window.
355 void openInNewWindow();
358 * Indicates in the statusbar that the execution of the command \a command
361 void showCommand(CommandType command
);
364 * If the URL can be listed, open it in the current view, otherwise
365 * run it through KRun.
367 void handleUrl(const KUrl
& url
);
370 * handleUrl() can trigger a stat job to see if the url can actually
373 void slotHandleUrlStatFinished(KJob
* job
);
376 * Is invoked when the write state of a folder has been changed and
377 * enables/disables the "Create New..." menu entry.
379 void slotWriteStateChanged(bool isFolderWritable
);
382 * Opens the context menu on the current mouse position.
383 * @pos Position in screen coordinates.
384 * @item File item context. If item is null, the context menu
385 * should be applied to \a url.
386 * @url URL which contains \a item.
387 * @customActions Actions that should be added to the context menu,
388 * if the file item is null.
390 void openContextMenu(const QPoint
& pos
,
391 const KFileItem
& item
,
393 const QList
<QAction
*>& customActions
);
395 void updateControlMenu();
396 void updateToolBar();
397 void slotControlButtonDeleted();
400 * Is called if a panel emits an error-message and shows
401 * the error-message in the active view-container.
403 void slotPanelErrorMessage(const QString
& error
);
406 * Is called if the user clicked an item in the Places Panel.
407 * Reloads the view if \a url is the current URL already, and changes the
408 * current URL otherwise.
410 void slotPlaceActivated(const KUrl
& url
);
413 * Is called if the another view has been activated by changing the current
414 * tab or activating another view in split-view mode.
416 * Activates the given view, which means that all menu actions are applied
417 * to this view. When having a split view setup, the nonactive view is
418 * usually shown in darker colors.
420 void activeViewChanged(DolphinViewContainer
* viewContainer
);
422 void closedTabsCountChanged(unsigned int count
);
425 * Is called if a new tab has been opened or a tab has been closed to
426 * enable/disable the tab actions.
428 void tabCountChanged(int count
);
431 * Sets the window caption to url.fileName() if this is non-empty,
432 * "/" if the URL is "file:///", and url.protocol() otherwise.
434 void setUrlAsCaption(const KUrl
& url
);
438 void setupDockWidgets();
439 void updateEditActions();
440 void updateViewActions();
441 void updateGoActions();
443 void createControlButton();
444 void deleteControlButton();
447 * Adds the action \p action to the menu \p menu in
448 * case if it has not added already to the toolbar.
449 * @return True if the action has been added to the menu.
451 bool addActionToMenu(QAction
* action
, QMenu
* menu
);
454 * Connects the signals from the created DolphinView with
455 * the DolphinViewContainer \a container with the corresponding slots of
456 * the DolphinMainWindow. This method must be invoked each
457 * time a DolphinView has been created.
459 void connectViewSignals(DolphinViewContainer
* container
);
462 * Updates the text of the split action:
463 * If two views are shown, the text is set to "Split",
464 * otherwise the text is set to "Join". The icon
465 * is updated to match with the text and the currently active view.
467 void updateSplitAction();
469 bool isKompareInstalled() const;
472 * Creates an action for showing/hiding a panel, that is accessible
473 * in "Configure toolbars..." and "Configure shortcuts...". This is necessary
474 * as the action for toggling the dock visibility is done by Qt which
475 * is no KAction instance.
477 void createPanelAction(const QIcon
&icon
,
478 const QKeySequence
& shortcut
,
480 const QString
& actionName
);
484 * Implements a custom error handling for the undo manager. This
485 * assures that all errors are shown in the status bar of Dolphin
486 * instead as modal error dialog with an OK button.
488 class UndoUiInterface
: public KIO::FileUndoManager::UiInterface
492 virtual ~UndoUiInterface();
493 virtual void jobError(KIO::Job
* job
);
496 KNewFileMenu
* m_newFileMenu
;
497 DolphinTabWidget
* m_tabWidget
;
498 DolphinViewContainer
* m_activeViewContainer
;
501 DolphinViewActionHandler
* m_actionHandler
;
502 DolphinRemoteEncoding
* m_remoteEncoding
;
503 QWeakPointer
<DolphinSettingsDialog
> m_settingsDialog
;
505 // Members for the toolbar menu that is shown when the menubar is hidden:
506 QToolButton
* m_controlButton
;
507 QTimer
* m_updateToolBarTimer
;
509 KIO::Job
* m_lastHandleUrlStatJob
;
512 inline DolphinViewContainer
* DolphinMainWindow::activeViewContainer() const
514 return m_activeViewContainer
;
517 inline KNewFileMenu
* DolphinMainWindow::newFileMenu() const
519 return m_newFileMenu
;
522 inline int DolphinMainWindow::getId() const
527 #endif // DOLPHIN_MAINWINDOW_H