]>
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-nepomuk.h>
27 #include <KFileItemDelegate>
28 #include <kio/fileundomanager.h>
29 #include <ksortablelist.h>
30 #include <kxmlguiwindow.h>
31 #include <KActionMenu>
35 #include <QWeakPointer>
37 typedef KIO::FileUndoManager::CommandType CommandType
;
39 class DolphinViewActionHandler
;
40 class DolphinApplication
;
41 class DolphinSettingsDialog
;
42 class DolphinViewContainer
;
43 class DolphinRemoteEncoding
;
56 * @short Main window for Dolphin.
58 * Handles the menus, toolbars and Dolphin views.
60 class DolphinMainWindow
: public KXmlGuiWindow
63 Q_CLASSINFO("D-Bus Interface", "org.kde.dolphin.MainWindow")
64 Q_PROPERTY(int id READ getId SCRIPTABLE
true)
65 friend class DolphinApplication
;
69 virtual ~DolphinMainWindow();
72 * Returns the currently active view.
73 * All menu actions are applied to this view. When
74 * having a split view setup, the nonactive view
75 * is usually shown in darker colors.
77 DolphinViewContainer
* activeViewContainer() const;
80 * Opens each directory in \p dirs in a separate tab. If the "split view"
81 * option is enabled, 2 directories are collected within one tab.
83 void openDirectories(const QList
<KUrl
>& dirs
);
86 * Opens the directory which contains the files \p files
87 * and selects all files (implements the --select option
90 void openFiles(const QList
<KUrl
>& files
);
93 * Returns true, if the main window contains two instances
94 * of a view container. The active view constainer can be
95 * accessed by DolphinMainWindow::activeViewContainer().
100 * Returns the 'Create New...' sub menu which also can be shared
101 * with other menus (e. g. a context menu).
103 KNewFileMenu
* newFileMenu() const;
107 * Pastes the clipboard data into the currently selected folder
108 * of the active view. If not exactly one folder is selected,
109 * no pasting is done at all.
111 void pasteIntoFolder();
114 * Returns the main window ID used through DBus.
119 * Implementation of the MainWindowAdaptor/QDBusAbstractAdaptor interface.
120 * Inform all affected dolphin components (panels, views) of an URL
123 void changeUrl(const KUrl
& url
);
126 * The current directory of the Terminal Panel has changed, probably because
127 * the user entered a 'cd' command. This slot calls changeUrl(url) and makes
128 * sure that the panel keeps the keyboard focus.
130 void slotTerminalDirectoryChanged(const KUrl
& url
);
132 /** Stores all settings and quits Dolphin. */
137 * Is sent if the selection of the currently active view has
140 void selectionChanged(const KFileItemList
& selection
);
143 * Is sent if the url of the currently active view has
146 void urlChanged(const KUrl
& url
);
149 * Is emitted if information of an item is requested to be shown e. g. in the panel.
150 * If item is null, no item information request is pending.
152 void requestItemInfo(const KFileItem
& item
);
155 /** @see QWidget::showEvent() */
156 virtual void showEvent(QShowEvent
* event
);
158 /** @see QMainWindow::closeEvent() */
159 virtual void closeEvent(QCloseEvent
* event
);
161 /** @see KMainWindow::saveProperties() */
162 virtual void saveProperties(KConfigGroup
& group
);
164 /** @see KMainWindow::readProperties() */
165 virtual void readProperties(const KConfigGroup
& group
);
169 * Refreshes the views of the main window by recreating them according to
170 * the given Dolphin settings.
174 void clearStatusBar();
176 /** Updates the 'Create New...' sub menu. */
177 void updateNewMenu();
179 void createDirectory();
181 /** Shows the error message in the status bar of the active view. */
182 void showErrorMessage(const QString
& message
);
185 * Updates the state of the 'Undo' menu action dependent
186 * on the parameter \a available.
188 void slotUndoAvailable(bool available
);
190 /** Invoked when an action in the recent tabs menu is clicked. */
191 void restoreClosedTab(QAction
* action
);
193 /** Sets the text of the 'Undo' menu action to \a text. */
194 void slotUndoTextChanged(const QString
& text
);
196 /** Performs the current undo operation. */
200 * Copies all selected items to the clipboard and marks
205 /** Copies all selected items to the clipboard. */
208 /** Pastes the clipboard data to the active view. */
211 /** Replaces the URL navigator by a search box to find files. */
215 * Updates the text of the paste action dependent on
216 * the number of items which are in the clipboard.
218 void updatePasteAction();
220 /** Selects all items from the active view. */
224 * Inverts the selection of all items of the active view:
225 * Selected items get nonselected and nonselected items get
228 void invertSelection();
231 * Switches between one and two views:
232 * If one view is visible, it will get split into two views.
233 * If already two views are visible, the active view gets closed.
235 void toggleSplitView();
237 /** Reloads the currently active view. */
240 /** Stops the loading process for the currently active view. */
243 void enableStopAction();
244 void disableStopAction();
246 void showFilterBar();
249 * Toggles between edit and browse mode of the navigation bar.
251 void toggleEditLocation();
254 * Switches to the edit mode of the navigation bar and selects
255 * the whole URL, so that it can be replaced by the user. If the edit mode is
256 * already active, it is assured that the navigation bar get focused.
258 void replaceLocation();
261 * Toggles the state of the panels between a locked and unlocked layout.
263 void togglePanelLockState();
266 * Is invoked if the Places panel got visible/invisible and takes care
267 * that the places-selector of all views is only shown if the Places panel
270 void slotPlacesPanelVisibilityChanged(bool visible
);
272 /** Goes back one step of the URL history. */
275 /** Goes forward one step of the URL history. */
278 /** Goes up one hierarchy of the current URL. */
281 /** Changes the location to the home URL. */
285 * Open the previous URL in the URL history in a new tab
286 * if the middle mouse button is clicked.
288 void goBack(Qt::MouseButtons buttons
);
291 * Open the next URL in the URL history in a new tab
292 * if the middle mouse button is clicked.
294 void goForward(Qt::MouseButtons buttons
);
297 * Open the URL one hierarchy above the current URL in a new tab
298 * if the middle mouse button is clicked.
300 void goUp(Qt::MouseButtons buttons
);
303 * Open the home URL in a new tab
305 void goHome(Qt::MouseButtons buttons
);
307 /** Opens Kompare for 2 selected files. */
311 * Hides the menu bar if it is visible, makes the menu bar
312 * visible if it is hidden.
314 void toggleShowMenuBar();
316 /** Opens a terminal window for the current location. */
319 /** Opens the settings dialog for Dolphin. */
322 /** Updates the state of the 'Show Full Location' action. */
323 void slotEditableStateChanged(bool editable
);
326 * Updates the state of the 'Edit' menu actions and emits
327 * the signal selectionChanged().
329 void slotSelectionChanged(const KFileItemList
& selection
);
331 /** Emits the signal requestItemInfo(). */
332 void slotRequestItemInfo(const KFileItem
&);
335 * Updates the state of the 'Back' and 'Forward' menu
336 * actions corresponding to the current history.
338 void updateHistory();
340 /** Updates the state of the 'Show filter bar' menu action. */
341 void updateFilterBarAction(bool show
);
343 /** Open a new main window. */
344 void openNewMainWindow();
346 /** Opens a new view with the current URL that is part of a tab. */
350 * Opens a new tab in the background showing the URL \a url.
352 void openNewTab(const KUrl
& url
);
355 * Opens a new tab showing the URL \a url and activates
358 void openNewActivatedTab(const KUrl
& url
);
360 void activateNextTab();
362 void activatePrevTab();
365 * Opens the selected folder in a new tab.
370 * Opens the selected folder in a new window.
372 void openInNewWindow();
374 /** Toggles the active view if two views are shown within the main window. */
375 void toggleActiveView();
378 * Indicates in the statusbar that the execution of the command \a command
381 void showCommand(CommandType command
);
384 * Activates the tab with the index \a index, which means that the current view
385 * is replaced by the view of the given tab.
387 void setActiveTab(int index
);
389 /** Closes the currently active tab. */
393 * Closes the tab with the index \a index and activates the tab with index - 1.
395 void closeTab(int index
);
398 * Opens a context menu for the tab with the index \a index
399 * on the position \a pos.
401 void openTabContextMenu(int index
, const QPoint
& pos
);
404 * Is connected to the QTabBar signal tabMoved(int from, int to).
405 * Reorders the list of tabs after a tab was moved in the tab bar
406 * and sets m_tabIndex to the new index of the current tab.
408 void slotTabMoved(int from
, int to
);
411 * Is connected to the KTabBar signal testCanDecode() and adjusts
412 * the output parameter \a accept.
414 void slotTestCanDecode(const QDragMoveEvent
* event
, bool& accept
);
417 * If the URL can be listed, open it in the current view, otherwise
418 * run it through KRun.
420 void handleUrl(const KUrl
& url
);
423 * handleUrl() can trigger a stat job to see if the url can actually
426 void slotHandleUrlStatFinished(KJob
* job
);
429 * Is connected to the KTabBar signal receivedDropEvent.
430 * Allows dragging and dropping files onto tabs.
432 void tabDropEvent(int tab
, QDropEvent
* event
);
435 * Is invoked when the write state of a folder has been changed and
436 * enables/disables the "Create New..." menu entry.
438 void slotWriteStateChanged(bool isFolderWritable
);
441 * Opens the context menu on the current mouse position.
442 * @pos Position in screen coordinates.
443 * @item File item context. If item is null, the context menu
444 * should be applied to \a url.
445 * @url URL which contains \a item.
446 * @customActions Actions that should be added to the context menu,
447 * if the file item is null.
449 void openContextMenu(const QPoint
& pos
,
450 const KFileItem
& item
,
452 const QList
<QAction
*>& customActions
);
454 void updateControlMenu();
455 void updateToolBar();
456 void slotControlButtonDeleted();
459 * Is called if a panel emits an error-message and shows
460 * the error-message in the active view-container.
462 void slotPanelErrorMessage(const QString
& error
);
466 * Activates the given view, which means that
467 * all menu actions are applied to this view. When
468 * having a split view setup, the nonactive view
469 * is usually shown in darker colors.
471 void setActiveViewContainer(DolphinViewContainer
* view
);
474 * Creates a view container and does a default initialization.
476 DolphinViewContainer
* createViewContainer(const KUrl
& url
, QWidget
* parent
);
479 void setupDockWidgets();
480 void updateEditActions();
481 void updateViewActions();
482 void updateGoActions();
484 void createControlButton();
485 void deleteControlButton();
488 * Adds the action \p action to the menu \p menu in
489 * case if it has not added already to the toolbar.
490 * @return True if the action has been added to the menu.
492 bool addActionToMenu(QAction
* action
, KMenu
* menu
);
495 * Adds the tab[\a index] to the closed tab menu's list of actions.
497 void rememberClosedTab(int index
);
500 * Connects the signals from the created DolphinView with
501 * the DolphinViewContainer \a container with the corresponding slots of
502 * the DolphinMainWindow. This method must be invoked each
503 * time a DolphinView has been created.
505 void connectViewSignals(DolphinViewContainer
* container
);
508 * Updates the text of the split action:
509 * If two views are shown, the text is set to "Split",
510 * otherwise the text is set to "Join". The icon
511 * is updated to match with the text and the currently active view.
513 void updateSplitAction();
515 /** Returns the name of the tab for the URL \a url. */
516 QString
tabName(const KUrl
& url
) const;
518 bool isKompareInstalled() const;
520 void createSecondaryView(int tabIndex
);
523 * Helper method for saveProperties() and readProperties(): Returns
524 * the property string for a tab with the index \a tabIndex and
525 * the property \a property.
527 QString
tabProperty(const QString
& property
, int tabIndex
) const;
530 * Sets the window caption to url.fileName() if this is non-empty,
531 * "/" if the URL is "file:///", and url.protocol() otherwise.
533 void setUrlAsCaption(const KUrl
& url
);
535 QString
squeezedText(const QString
& text
) const;
538 * Creates an action for showing/hiding a panel, that is accessible
539 * in "Configure toolbars..." and "Configure shortcuts...". This is necessary
540 * as the action for toggling the dock visibility is done by Qt which
541 * is no KAction instance.
543 void createPanelAction(const KIcon
& icon
,
544 const QKeySequence
& shortcut
,
546 const QString
& actionName
);
550 * Implements a custom error handling for the undo manager. This
551 * assures that all errors are shown in the status bar of Dolphin
552 * instead as modal error dialog with an OK button.
554 class UndoUiInterface
: public KIO::FileUndoManager::UiInterface
558 virtual ~UndoUiInterface();
559 virtual void jobError(KIO::Job
* job
);
562 KNewFileMenu
* m_newFileMenu
;
563 KActionMenu
* m_recentTabsMenu
;
565 DolphinViewContainer
* m_activeViewContainer
;
566 QVBoxLayout
* m_centralWidgetLayout
;
569 // Members for the tab-handling:
572 ViewTab() : isPrimaryViewActive(true), wasActive(false), primaryView(0), secondaryView(0), splitter(0) {}
573 bool isPrimaryViewActive
;
575 DolphinViewContainer
* primaryView
;
576 DolphinViewContainer
* secondaryView
;
580 QList
<ViewTab
> m_viewTab
;
582 DolphinViewActionHandler
* m_actionHandler
;
583 DolphinRemoteEncoding
* m_remoteEncoding
;
584 QWeakPointer
<DolphinSettingsDialog
> m_settingsDialog
;
586 // Members for the toolbar menu that is shown when the menubar is hidden:
587 QToolButton
* m_controlButton
;
588 QTimer
* m_updateToolBarTimer
;
590 KIO::Job
* m_lastHandleUrlStatJob
;
593 inline DolphinViewContainer
* DolphinMainWindow::activeViewContainer() const
595 return m_activeViewContainer
;
598 inline bool DolphinMainWindow::isSplit() const
600 return m_viewTab
[m_tabIndex
].secondaryView
!= 0;
603 inline KNewFileMenu
* DolphinMainWindow::newFileMenu() const
605 return m_newFileMenu
;
608 inline int DolphinMainWindow::getId() const
613 #endif // DOLPHIN_MAINWINDOW_H