]>
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>
31 #include <KActionMenu>
34 #include <QWeakPointer>
36 typedef KIO::FileUndoManager::CommandType CommandType
;
38 class DolphinViewActionHandler
;
39 class DolphinApplication
;
40 class DolphinSettingsDialog
;
41 class DolphinViewContainer
;
42 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 * Is emitted if the settings have been changed.
157 void settingsChanged();
160 /** @see QWidget::showEvent() */
161 virtual void showEvent(QShowEvent
* event
);
163 /** @see QMainWindow::closeEvent() */
164 virtual void closeEvent(QCloseEvent
* event
);
166 /** @see KMainWindow::saveProperties() */
167 virtual void saveProperties(KConfigGroup
& group
);
169 /** @see KMainWindow::readProperties() */
170 virtual void readProperties(const KConfigGroup
& group
);
174 * Refreshes the views of the main window by recreating them according to
175 * the given Dolphin settings.
179 void clearStatusBar();
181 /** Updates the 'Create New...' sub menu. */
182 void updateNewMenu();
184 void createDirectory();
186 /** Shows the error message in the status bar of the active view. */
187 void showErrorMessage(const QString
& message
);
190 * Updates the state of the 'Undo' menu action dependent
191 * on the parameter \a available.
193 void slotUndoAvailable(bool available
);
195 /** Invoked when an action in the recent tabs menu is clicked. */
196 void restoreClosedTab(QAction
* action
);
198 /** Sets the text of the 'Undo' menu action to \a text. */
199 void slotUndoTextChanged(const QString
& text
);
201 /** Performs the current undo operation. */
205 * Copies all selected items to the clipboard and marks
210 /** Copies all selected items to the clipboard. */
213 /** Pastes the clipboard data to the active view. */
216 /** Replaces the URL navigator by a search box to find files. */
220 * Updates the text of the paste action dependent on
221 * the number of items which are in the clipboard.
223 void updatePasteAction();
225 /** Selects all items from the active view. */
229 * Inverts the selection of all items of the active view:
230 * Selected items get nonselected and nonselected items get
233 void invertSelection();
236 * Switches between one and two views:
237 * If one view is visible, it will get split into two views.
238 * If already two views are visible, the active view gets closed.
240 void toggleSplitView();
242 /** Reloads the currently active view. */
245 /** Stops the loading process for the currently active view. */
248 void enableStopAction();
249 void disableStopAction();
251 void showFilterBar();
254 * Toggles between edit and browse mode of the navigation bar.
256 void toggleEditLocation();
259 * Switches to the edit mode of the navigation bar and selects
260 * the whole URL, so that it can be replaced by the user. If the edit mode is
261 * already active, it is assured that the navigation bar get focused.
263 void replaceLocation();
266 * Toggles the state of the panels between a locked and unlocked layout.
268 void togglePanelLockState();
271 * Is invoked if the Places panel got visible/invisible and takes care
272 * that the places-selector of all views is only shown if the Places panel
275 void slotPlacesPanelVisibilityChanged(bool visible
);
277 /** Goes back one step of the URL history. */
280 /** Goes forward one step of the URL history. */
283 /** Goes up one hierarchy of the current URL. */
286 /** Changes the location to the home URL. */
290 * Open the previous URL in the URL history in a new tab
291 * if the middle mouse button is clicked.
293 void goBack(Qt::MouseButtons buttons
);
296 * Open the next URL in the URL history in a new tab
297 * if the middle mouse button is clicked.
299 void goForward(Qt::MouseButtons buttons
);
302 * Open the URL one hierarchy above the current URL in a new tab
303 * if the middle mouse button is clicked.
305 void goUp(Qt::MouseButtons buttons
);
308 * Open the home URL in a new tab
310 void goHome(Qt::MouseButtons buttons
);
312 /** Opens Kompare for 2 selected files. */
316 * Hides the menu bar if it is visible, makes the menu bar
317 * visible if it is hidden.
319 void toggleShowMenuBar();
321 /** Opens a terminal window for the current location. */
324 /** Opens the settings dialog for Dolphin. */
327 /** Updates the state of the 'Show Full Location' action. */
328 void slotEditableStateChanged(bool editable
);
331 * Updates the state of the 'Edit' menu actions and emits
332 * the signal selectionChanged().
334 void slotSelectionChanged(const KFileItemList
& selection
);
336 /** Emits the signal requestItemInfo(). */
337 void slotRequestItemInfo(const KFileItem
&);
340 * Updates the state of the 'Back' and 'Forward' menu
341 * actions corresponding to the current history.
343 void updateHistory();
345 /** Updates the state of the 'Show filter bar' menu action. */
346 void updateFilterBarAction(bool show
);
348 /** Open a new main window. */
349 void openNewMainWindow();
351 /** Opens a new view with the current URL that is part of a tab. */
355 * Opens a new tab in the background showing the URL \a url.
357 void openNewTab(const KUrl
& url
);
360 * Opens a new tab showing the URL \a url and activates
363 void openNewActivatedTab(const KUrl
& url
);
365 void activateNextTab();
367 void activatePrevTab();
370 * Opens the selected folder in a new tab.
375 * Opens the selected folder in a new window.
377 void openInNewWindow();
379 /** Toggles the active view if two views are shown within the main window. */
380 void toggleActiveView();
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 a context menu for the tab with the index \a index
404 * on the position \a pos.
406 void openTabContextMenu(int index
, const QPoint
& pos
);
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 * Is connected to the KTabBar signal testCanDecode() and adjusts
417 * the output parameter \a accept.
419 void slotTestCanDecode(const QDragMoveEvent
* event
, bool& accept
);
422 * If the URL can be listed, open it in the current view, otherwise
423 * run it through KRun.
425 void handleUrl(const KUrl
& url
);
428 * handleUrl() can trigger a stat job to see if the url can actually
431 void slotHandleUrlStatFinished(KJob
* job
);
434 * Is connected to the KTabBar signal receivedDropEvent.
435 * Allows dragging and dropping files onto tabs.
437 void tabDropEvent(int tab
, QDropEvent
* event
);
440 * Is invoked when the write state of a folder has been changed and
441 * enables/disables the "Create New..." menu entry.
443 void slotWriteStateChanged(bool isFolderWritable
);
446 * Opens the context menu on the current mouse position.
447 * @pos Position in screen coordinates.
448 * @item File item context. If item is null, the context menu
449 * should be applied to \a url.
450 * @url URL which contains \a item.
451 * @customActions Actions that should be added to the context menu,
452 * if the file item is null.
454 void openContextMenu(const QPoint
& pos
,
455 const KFileItem
& item
,
457 const QList
<QAction
*>& customActions
);
459 void updateControlMenu();
460 void updateToolBar();
461 void slotControlButtonDeleted();
464 * Is called if a panel emits an error-message and shows
465 * the error-message in the active view-container.
467 void slotPanelErrorMessage(const QString
& error
);
470 * Is called if the user clicked an item in the Places Panel.
471 * Reloads the view if \a url is the current URL already, and changes the
472 * current URL otherwise.
474 void slotPlaceActivated(const KUrl
& url
);
478 * Activates the given view, which means that
479 * all menu actions are applied to this view. When
480 * having a split view setup, the nonactive view
481 * is usually shown in darker colors.
483 void setActiveViewContainer(DolphinViewContainer
* view
);
486 * Creates a view container and does a default initialization.
488 DolphinViewContainer
* createViewContainer(const KUrl
& url
, QWidget
* parent
);
491 void setupDockWidgets();
492 void updateEditActions();
493 void updateViewActions();
494 void updateGoActions();
496 void createControlButton();
497 void deleteControlButton();
500 * Adds the action \p action to the menu \p menu in
501 * case if it has not added already to the toolbar.
502 * @return True if the action has been added to the menu.
504 bool addActionToMenu(QAction
* action
, KMenu
* menu
);
507 * Adds the tab[\a index] to the closed tab menu's list of actions.
509 void rememberClosedTab(int index
);
512 * Connects the signals from the created DolphinView with
513 * the DolphinViewContainer \a container with the corresponding slots of
514 * the DolphinMainWindow. This method must be invoked each
515 * time a DolphinView has been created.
517 void connectViewSignals(DolphinViewContainer
* container
);
520 * Updates the text of the split action:
521 * If two views are shown, the text is set to "Split",
522 * otherwise the text is set to "Join". The icon
523 * is updated to match with the text and the currently active view.
525 void updateSplitAction();
527 /** Returns the name of the tab for the URL \a url. */
528 QString
tabName(const KUrl
& url
) const;
530 bool isKompareInstalled() const;
532 void createSecondaryView(int tabIndex
);
535 * Helper method for saveProperties() and readProperties(): Returns
536 * the property string for a tab with the index \a tabIndex and
537 * the property \a property.
539 QString
tabProperty(const QString
& property
, int tabIndex
) const;
542 * Sets the window caption to url.fileName() if this is non-empty,
543 * "/" if the URL is "file:///", and url.protocol() otherwise.
545 void setUrlAsCaption(const KUrl
& url
);
547 QString
squeezedText(const QString
& text
) const;
550 * Creates an action for showing/hiding a panel, that is accessible
551 * in "Configure toolbars..." and "Configure shortcuts...". This is necessary
552 * as the action for toggling the dock visibility is done by Qt which
553 * is no KAction instance.
555 void createPanelAction(const QIcon
&icon
,
556 const QKeySequence
& shortcut
,
558 const QString
& actionName
);
562 * Implements a custom error handling for the undo manager. This
563 * assures that all errors are shown in the status bar of Dolphin
564 * instead as modal error dialog with an OK button.
566 class UndoUiInterface
: public KIO::FileUndoManager::UiInterface
570 virtual ~UndoUiInterface();
571 virtual void jobError(KIO::Job
* job
);
574 KNewFileMenu
* m_newFileMenu
;
575 KActionMenu
* m_recentTabsMenu
;
577 DolphinViewContainer
* m_activeViewContainer
;
578 QVBoxLayout
* m_centralWidgetLayout
;
581 // Members for the tab-handling:
584 ViewTab() : isPrimaryViewActive(true), wasActive(false), primaryView(0), secondaryView(0), splitter(0) {}
585 bool isPrimaryViewActive
;
587 DolphinViewContainer
* primaryView
;
588 DolphinViewContainer
* secondaryView
;
592 QList
<ViewTab
> m_viewTab
;
594 DolphinViewActionHandler
* m_actionHandler
;
595 DolphinRemoteEncoding
* m_remoteEncoding
;
596 QWeakPointer
<DolphinSettingsDialog
> m_settingsDialog
;
598 // Members for the toolbar menu that is shown when the menubar is hidden:
599 QToolButton
* m_controlButton
;
600 QTimer
* m_updateToolBarTimer
;
602 KIO::Job
* m_lastHandleUrlStatJob
;
605 inline DolphinViewContainer
* DolphinMainWindow::activeViewContainer() const
607 return m_activeViewContainer
;
610 inline bool DolphinMainWindow::isSplit() const
612 return m_viewTab
[m_tabIndex
].secondaryView
!= 0;
615 inline KNewFileMenu
* DolphinMainWindow::newFileMenu() const
617 return m_newFileMenu
;
620 inline int DolphinMainWindow::getId() const
625 #endif // DOLPHIN_MAINWINDOW_H