]>
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
;
43 class DolphinViewContainer
;
44 class DolphinRemoteEncoding
;
57 * @short Main window for Dolphin.
59 * Handles the menus, toolbars and Dolphin views.
61 class DolphinMainWindow
: public KXmlGuiWindow
64 Q_CLASSINFO("D-Bus Interface", "org.kde.dolphin.MainWindow")
65 Q_PROPERTY(int id READ getId SCRIPTABLE
true)
66 friend class DolphinApplication
;
70 virtual ~DolphinMainWindow();
73 * Returns the currently active view.
74 * All menu actions are applied to this view. When
75 * having a split view setup, the nonactive view
76 * is usually shown in darker colors.
78 DolphinViewContainer
* activeViewContainer() const;
81 * Opens each directory in \p dirs in a separate tab. If the "split view"
82 * option is enabled, 2 directories are collected within one tab.
84 void openDirectories(const QList
<KUrl
>& dirs
);
87 * Opens the directory which contains the files \p files
88 * and selects all files (implements the --select option
91 void openFiles(const QList
<KUrl
>& files
);
94 * Returns the 'Create New...' sub menu which also can be shared
95 * with other menus (e. g. a context menu).
97 KNewFileMenu
* newFileMenu() const;
101 * Pastes the clipboard data into the currently selected folder
102 * of the active view. If not exactly one folder is selected,
103 * no pasting is done at all.
105 void pasteIntoFolder();
108 * Returns the main window ID used through DBus.
113 * Implementation of the MainWindowAdaptor/QDBusAbstractAdaptor interface.
114 * Inform all affected dolphin components (panels, views) of an URL
117 void changeUrl(const KUrl
& url
);
120 * The current directory of the Terminal Panel has changed, probably because
121 * the user entered a 'cd' command. This slot calls changeUrl(url) and makes
122 * sure that the panel keeps the keyboard focus.
124 void slotTerminalDirectoryChanged(const KUrl
& url
);
126 /** Stores all settings and quits Dolphin. */
131 * Is sent if the selection of the currently active view has
134 void selectionChanged(const KFileItemList
& selection
);
137 * Is sent if the url of the currently active view has
140 void urlChanged(const KUrl
& url
);
143 * Is emitted if information of an item is requested to be shown e. g. in the panel.
144 * If item is null, no item information request is pending.
146 void requestItemInfo(const KFileItem
& item
);
149 * Is emitted if the settings have been changed.
151 void settingsChanged();
154 * Is emitted when a tab has been closed.
156 void rememberClosedTab(const KUrl
& primaryUrl
, const KUrl
& secondaryUrl
);
159 /** @see QWidget::showEvent() */
160 virtual void showEvent(QShowEvent
* event
);
162 /** @see QMainWindow::closeEvent() */
163 virtual void closeEvent(QCloseEvent
* event
);
165 /** @see KMainWindow::saveProperties() */
166 virtual void saveProperties(KConfigGroup
& group
);
168 /** @see KMainWindow::readProperties() */
169 virtual void readProperties(const KConfigGroup
& group
);
173 * Refreshes the views of the main window by recreating them according to
174 * the given Dolphin settings.
178 void clearStatusBar();
180 /** Updates the 'Create New...' sub menu. */
181 void updateNewMenu();
183 void createDirectory();
185 /** Shows the error message in the status bar of the active view. */
186 void showErrorMessage(const QString
& message
);
189 * Updates the state of the 'Undo' menu action dependent
190 * on the parameter \a available.
192 void slotUndoAvailable(bool available
);
194 /** Sets the text of the 'Undo' menu action to \a text. */
195 void slotUndoTextChanged(const QString
& text
);
197 /** Performs the current undo operation. */
201 * Copies all selected items to the clipboard and marks
206 /** Copies all selected items to the clipboard. */
209 /** Pastes the clipboard data to the active view. */
212 /** Replaces the URL navigator by a search box to find files. */
216 * Updates the text of the paste action dependent on
217 * the number of items which are in the clipboard.
219 void updatePasteAction();
221 /** Selects all items from the active view. */
225 * Inverts the selection of all items of the active view:
226 * Selected items get nonselected and nonselected items get
229 void invertSelection();
232 * Switches between one and two views:
233 * If one view is visible, it will get split into two views.
234 * If already two views are visible, the active view gets closed.
236 void toggleSplitView();
238 /** Reloads the currently active view. */
241 /** Stops the loading process for the currently active view. */
244 void enableStopAction();
245 void disableStopAction();
247 void showFilterBar();
250 * Toggles between edit and browse mode of the navigation bar.
252 void toggleEditLocation();
255 * Switches to the edit mode of the navigation bar and selects
256 * the whole URL, so that it can be replaced by the user. If the edit mode is
257 * already active, it is assured that the navigation bar get focused.
259 void replaceLocation();
262 * Toggles the state of the panels between a locked and unlocked layout.
264 void togglePanelLockState();
267 * Is invoked if the Places panel got visible/invisible and takes care
268 * that the places-selector of all views is only shown if the Places panel
271 void slotPlacesPanelVisibilityChanged(bool visible
);
273 /** Goes back one step of the URL history. */
276 /** Goes forward one step of the URL history. */
279 /** Goes up one hierarchy of the current URL. */
282 /** Changes the location to the home URL. */
286 * Open the previous URL in the URL history in a new tab
287 * if the middle mouse button is clicked.
289 void goBack(Qt::MouseButtons buttons
);
292 * Open the next URL in the URL history in a new tab
293 * if the middle mouse button is clicked.
295 void goForward(Qt::MouseButtons buttons
);
298 * Open the URL one hierarchy above the current URL in a new tab
299 * if the middle mouse button is clicked.
301 void goUp(Qt::MouseButtons buttons
);
304 * Open the home URL in a new tab
306 void goHome(Qt::MouseButtons buttons
);
308 /** Opens Kompare for 2 selected files. */
312 * Hides the menu bar if it is visible, makes the menu bar
313 * visible if it is hidden.
315 void toggleShowMenuBar();
317 /** Opens a terminal window for the current location. */
320 /** Opens the settings dialog for Dolphin. */
323 /** Updates the state of the 'Show Full Location' action. */
324 void slotEditableStateChanged(bool editable
);
327 * Updates the state of the 'Edit' menu actions and emits
328 * the signal selectionChanged().
330 void slotSelectionChanged(const KFileItemList
& selection
);
332 /** Emits the signal requestItemInfo(). */
333 void slotRequestItemInfo(const KFileItem
&);
336 * Updates the state of the 'Back' and 'Forward' menu
337 * actions corresponding to the current history.
339 void updateHistory();
341 /** Updates the state of the 'Show filter bar' menu action. */
342 void updateFilterBarAction(bool show
);
344 /** Open a new main window. */
345 void openNewMainWindow();
347 /** Opens a new view with the current URL that is part of a tab. */
351 * Opens a new tab in the background showing the URL \a primaryUrl and the
352 * optional URL \a secondaryUrl.
354 void openNewTab(const KUrl
& primaryUrl
, const KUrl
& secondaryUrl
= KUrl());
357 * Opens a new tab showing the URL \a primaryUrl and the optional URL
358 * \a secondaryUrl and activates the tab.
360 void openNewActivatedTab(const KUrl
& primaryUrl
, const KUrl
& secondaryUrl
= KUrl());
363 * Opens a new tab showing the url from tab at the given \a index and
366 void openNewActivatedTab(int index
);
368 void activateNextTab();
370 void activatePrevTab();
373 * Opens the selected folder in a new tab.
378 * Opens the selected folder in a new window.
380 void openInNewWindow();
383 * Indicates in the statusbar that the execution of the command \a command
386 void showCommand(CommandType command
);
389 * Activates the tab with the index \a index, which means that the current view
390 * is replaced by the view of the given tab.
392 void setActiveTab(int index
);
394 /** Closes the currently active tab. */
398 * Closes the tab with the index \a index and activates the tab with index - 1.
400 void closeTab(int index
);
403 * Opens the tab with the index \a index in a new Dolphin instance and closes
406 void detachTab(int index
);
409 * Is connected to the QTabBar signal tabMoved(int from, int to).
410 * Reorders the list of tabs after a tab was moved in the tab bar
411 * and sets m_tabIndex to the new index of the current tab.
413 void slotTabMoved(int from
, int to
);
416 * If the URL can be listed, open it in the current view, otherwise
417 * run it through KRun.
419 void handleUrl(const KUrl
& url
);
422 * handleUrl() can trigger a stat job to see if the url can actually
425 void slotHandleUrlStatFinished(KJob
* job
);
428 * Is connected to the KTabBar signal receivedDropEvent.
429 * Allows dragging and dropping files onto tabs.
431 void tabDropEvent(int tab
, QDropEvent
* event
);
434 * Is invoked when the write state of a folder has been changed and
435 * enables/disables the "Create New..." menu entry.
437 void slotWriteStateChanged(bool isFolderWritable
);
440 * Opens the context menu on the current mouse position.
441 * @pos Position in screen coordinates.
442 * @item File item context. If item is null, the context menu
443 * should be applied to \a url.
444 * @url URL which contains \a item.
445 * @customActions Actions that should be added to the context menu,
446 * if the file item is null.
448 void openContextMenu(const QPoint
& pos
,
449 const KFileItem
& item
,
451 const QList
<QAction
*>& customActions
);
453 void updateControlMenu();
454 void updateToolBar();
455 void slotControlButtonDeleted();
458 * Is called if a panel emits an error-message and shows
459 * the error-message in the active view-container.
461 void slotPanelErrorMessage(const QString
& error
);
464 * Is called if the user clicked an item in the Places Panel.
465 * Reloads the view if \a url is the current URL already, and changes the
466 * current URL otherwise.
468 void slotPlaceActivated(const KUrl
& url
);
470 void activeViewChanged();
474 * Activates the given view, which means that
475 * all menu actions are applied to this view. When
476 * having a split view setup, the nonactive view
477 * is usually shown in darker colors.
479 void setActiveViewContainer(DolphinViewContainer
* view
);
482 void setupDockWidgets();
483 void updateEditActions();
484 void updateViewActions();
485 void updateGoActions();
487 void createControlButton();
488 void deleteControlButton();
491 * Adds the action \p action to the menu \p menu in
492 * case if it has not added already to the toolbar.
493 * @return True if the action has been added to the menu.
495 bool addActionToMenu(QAction
* action
, KMenu
* menu
);
498 * Connects the signals from the created DolphinView with
499 * the DolphinViewContainer \a container with the corresponding slots of
500 * the DolphinMainWindow. This method must be invoked each
501 * time a DolphinView has been created.
503 void connectViewSignals(DolphinViewContainer
* container
);
506 * Updates the text of the split action:
507 * If two views are shown, the text is set to "Split",
508 * otherwise the text is set to "Join". The icon
509 * is updated to match with the text and the currently active view.
511 void updateSplitAction();
513 /** Returns the name of the tab for the URL \a url. */
514 QString
tabName(const KUrl
& url
) const;
517 bool isKompareInstalled() const;
520 * Sets the window caption to url.fileName() if this is non-empty,
521 * "/" if the URL is "file:///", and url.protocol() otherwise.
523 void setUrlAsCaption(const KUrl
& url
);
525 QString
squeezedText(const QString
& text
) const;
528 * Creates an action for showing/hiding a panel, that is accessible
529 * in "Configure toolbars..." and "Configure shortcuts...". This is necessary
530 * as the action for toggling the dock visibility is done by Qt which
531 * is no KAction instance.
533 void createPanelAction(const QIcon
&icon
,
534 const QKeySequence
& shortcut
,
536 const QString
& actionName
);
540 * Implements a custom error handling for the undo manager. This
541 * assures that all errors are shown in the status bar of Dolphin
542 * instead as modal error dialog with an OK button.
544 class UndoUiInterface
: public KIO::FileUndoManager::UiInterface
548 virtual ~UndoUiInterface();
549 virtual void jobError(KIO::Job
* job
);
552 KNewFileMenu
* m_newFileMenu
;
553 DolphinTabBar
* m_tabBar
;
554 DolphinViewContainer
* m_activeViewContainer
;
555 QVBoxLayout
* m_centralWidgetLayout
;
559 QList
<DolphinTabPage
*> m_viewTab
;
561 DolphinViewActionHandler
* m_actionHandler
;
562 DolphinRemoteEncoding
* m_remoteEncoding
;
563 QWeakPointer
<DolphinSettingsDialog
> m_settingsDialog
;
565 // Members for the toolbar menu that is shown when the menubar is hidden:
566 QToolButton
* m_controlButton
;
567 QTimer
* m_updateToolBarTimer
;
569 KIO::Job
* m_lastHandleUrlStatJob
;
572 inline DolphinViewContainer
* DolphinMainWindow::activeViewContainer() const
574 return m_activeViewContainer
;
577 inline KNewFileMenu
* DolphinMainWindow::newFileMenu() const
579 return m_newFileMenu
;
582 inline int DolphinMainWindow::getId() const
587 #endif // DOLPHIN_MAINWINDOW_H