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 "panels/panel.h"
27 #include <config-nepomuk.h>
29 #include <KFileItemDelegate>
30 #include <kio/fileundomanager.h>
31 #include <ksortablelist.h>
32 #include <kxmlguiwindow.h>
33 #include <KActionMenu>
35 #include "views/dolphinview.h"
39 typedef KIO::FileUndoManager::CommandType CommandType
;
41 class DolphinViewActionHandler
;
42 class DolphinApplication
;
43 class DolphinSettingsDialog
;
44 class DolphinViewContainer
;
45 class DolphinRemoteEncoding
;
55 * @short Main window for Dolphin.
57 * Handles the menus, toolbars and Dolphin views.
59 class DolphinMainWindow
: public KXmlGuiWindow
62 Q_CLASSINFO("D-Bus Interface", "org.kde.dolphin.MainWindow")
63 Q_PROPERTY(int id READ getId SCRIPTABLE
true)
64 friend class DolphinApplication
;
67 virtual ~DolphinMainWindow();
70 * Returns the currently active view.
71 * All menu actions are applied to this view. When
72 * having a split view setup, the nonactive view
73 * is usually shown in darker colors.
75 DolphinViewContainer
* activeViewContainer() const;
78 * Opens each directory in \p dirs in a separate tab. If the "split view"
79 * option is enabled, 2 directories are collected within one tab.
81 void openDirectories(const QList
<KUrl
>& dirs
);
84 * Opens the directory which contains the files \p files
85 * and selects all files (implements the --select option
88 void openFiles(const QList
<KUrl
>& files
);
91 * Returns true, if the main window contains two instances
92 * of a view container. The active view constainer can be
93 * accessed by DolphinMainWindow::activeViewContainer().
97 /** Renames the item represented by \a oldUrl to \a newUrl. */
98 void rename(const KUrl
& oldUrl
, const KUrl
& newUrl
);
101 * Refreshes the views of the main window by recreating them according to
102 * the given Dolphin settings.
107 * Returns the 'Create New...' sub menu which also can be shared
108 * with other menus (e. g. a context menu).
110 KNewFileMenu
* newFileMenu() const;
114 * Pastes the clipboard data into the currently selected folder
115 * of the active view. If not exactly one folder is selected,
116 * no pasting is done at all.
118 void pasteIntoFolder();
121 * Returns the main window ID used through DBus.
126 * Implementation of the MainWindowAdaptor/QDBusAbstractAdaptor interface.
127 * Inform all affected dolphin components (panels, views) of an URL
130 void changeUrl(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
);
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 /** Invoked when an action in the recent tabs menu is clicked. */
185 void restoreClosedTab(QAction
* action
);
187 /** Sets the text of the 'Undo' menu action to \a text. */
188 void slotUndoTextChanged(const QString
& text
);
190 /** Performs the current undo operation. */
194 * Copies all selected items to the clipboard and marks
199 /** Copies all selected items to the clipboard. */
202 /** Pastes the clipboard data to the active view. */
205 /** Replaces the URL navigator by a search box to find files. */
209 * Updates the text of the paste action dependent on
210 * the number of items which are in the clipboard.
212 void updatePasteAction();
214 /** Selects all items from the active view. */
218 * Inverts the selection of all items of the active view:
219 * Selected items get nonselected and nonselected items get
222 void invertSelection();
225 * Switches between one and two views:
226 * If one view is visible, it will get split into two views.
227 * If already two views are visible, the active view gets closed.
229 void toggleSplitView();
231 /** Reloads the currently active view. */
234 /** Stops the loading process for the currently active view. */
237 void enableStopAction();
238 void disableStopAction();
240 void showFilterBar();
243 * Toggles between edit and browse mode of the navigation bar.
245 void toggleEditLocation();
248 * Switches to the edit mode of the navigation bar and selects
249 * the whole URL, so that it can be replaced by the user. If the edit mode is
250 * already active, it is assured that the navigation bar get focused.
252 void replaceLocation();
255 * Toggles the state of the panels between a locked and unlocked layout.
257 void togglePanelLockState();
260 * Is invoked if the Places panel got visible/invisible and takes care
261 * that the places-selector of all views is only shown if the Places panel
264 void slotPlacesPanelVisibilityChanged(bool visible
);
266 /** Goes back one step of the URL history. */
269 /** Goes forward one step of the URL history. */
272 /** Goes up one hierarchy of the current URL. */
275 /** Changes the location to the home URL. */
279 * Open the previous URL in the URL history in a new tab
280 * if the middle mouse button is clicked.
282 void goBack(Qt::MouseButtons buttons
);
285 * Open the next URL in the URL history in a new tab
286 * if the middle mouse button is clicked.
288 void goForward(Qt::MouseButtons buttons
);
291 * Open the URL one hierarchy above the current URL in a new tab
292 * if the middle mouse button is clicked.
294 void goUp(Qt::MouseButtons buttons
);
296 /** Opens Kompare for 2 selected files. */
300 * Hides the menu bar if it is visible, makes the menu bar
301 * visible if it is hidden.
303 void toggleShowMenuBar();
305 /** Opens a terminal window for the current location. */
308 /** Opens the settings dialog for Dolphin. */
311 /** Updates the state of the 'Show Full Location' action. */
312 void slotEditableStateChanged(bool editable
);
315 * Updates the state of the 'Edit' menu actions and emits
316 * the signal selectionChanged().
318 void slotSelectionChanged(const KFileItemList
& selection
);
320 /** Emits the signal requestItemInfo(). */
321 void slotRequestItemInfo(const KFileItem
&);
324 * Updates the state of the 'Back' and 'Forward' menu
325 * actions corresponding to the current history.
327 void updateHistory();
329 /** Updates the state of the 'Show filter bar' menu action. */
330 void updateFilterBarAction(bool show
);
332 /** Open a new main window. */
333 void openNewMainWindow();
335 /** Opens a new view with the current URL that is part of a tab. */
339 * Opens a new tab showing the URL \a url.
341 void openNewTab(const KUrl
& url
);
343 void activateNextTab();
345 void activatePrevTab();
348 * Opens the selected folder in a new tab.
353 * Opens the selected folder in a new window.
355 void openInNewWindow();
357 /** Toggles the active view if two views are shown within the main window. */
358 void toggleActiveView();
361 * Indicates in the statusbar that the execution of the command \a command
364 void showCommand(CommandType command
);
367 * Activates the tab with the index \a index, which means that the current view
368 * is replaced by the view of the given tab.
370 void setActiveTab(int index
);
372 /** Closes the currently active tab. */
376 * Closes the tab with the index \a index and activates the tab with index - 1.
378 void closeTab(int index
);
381 * Opens a context menu for the tab with the index \a index
382 * on the position \a pos.
384 void openTabContextMenu(int index
, const QPoint
& pos
);
387 * Is connected to the QTabBar signal tabMoved(int from, int to).
388 * Reorders the list of tabs after a tab was moved in the tab bar
389 * and sets m_tabIndex to the new index of the current tab.
391 void slotTabMoved(int from
, int to
);
394 * Handles a click on a places item: if the middle mouse button is
395 * clicked, a new tab is opened for \a url, otherwise the current
396 * view is replaced by \a url.
398 void handlePlacesClick(const KUrl
& url
, Qt::MouseButtons buttons
);
401 * Is connected to the KTabBar signal testCanDecode() and adjusts
402 * the output parameter \a accept.
404 void slotTestCanDecode(const QDragMoveEvent
* event
, bool& accept
);
407 * If the URL can be listed, open it in the current view, otherwise
408 * run it through KRun.
410 void handleUrl(const KUrl
& url
);
413 * handleUrl() can trigger a stat job to see if the url can actually
416 void slotHandleUrlStatFinished(KJob
* job
);
419 * Is connected to the KTabBar signal receivedDropEvent.
420 * Allows dragging and dropping files onto tabs.
422 void tabDropEvent(int tab
, QDropEvent
* event
);
425 * Is invoked when the write state of a folder has been changed and
426 * enables/disables the "Create New..." menu entry.
428 void slotWriteStateChanged(bool isFolderWritable
);
430 void slotSearchModeChanged(bool enabled
);
433 * Opens the context menu on the current mouse position.
434 * @item File item context. If item is null, the context menu
435 * should be applied to \a url.
436 * @url URL which contains \a item.
437 * @customActions Actions that should be added to the context menu,
438 * if the file item is null.
440 void openContextMenu(const KFileItem
& item
,
442 const QList
<QAction
*>& customActions
);
444 void openToolBarMenu();
445 void updateToolBarMenu();
446 void updateToolBar();
447 void slotToolBarSpacerDeleted();
448 void slotToolBarMenuButtonDeleted();
449 void slotToolBarIconSizeChanged(const QSize
& iconSize
);
452 DolphinMainWindow(int id
);
456 * Activates the given view, which means that
457 * all menu actions are applied to this view. When
458 * having a split view setup, the nonactive view
459 * is usually shown in darker colors.
461 void setActiveViewContainer(DolphinViewContainer
* view
);
464 * Creates a view container and does a default initialization.
466 DolphinViewContainer
* createViewContainer(const KUrl
& url
, QWidget
* parent
);
469 void setupDockWidgets();
470 void updateEditActions();
471 void updateViewActions();
472 void updateGoActions();
474 void createToolBarMenuButton();
475 void deleteToolBarMenuButton();
478 * Adds the action \p action to the menu \p menu in
479 * case if it has not added already to the toolbar.
480 * @return True if the action has been added to the menu.
482 bool addActionToMenu(QAction
* action
, KMenu
* menu
);
485 * Adds the tab[\a index] to the closed tab menu's list of actions.
487 void rememberClosedTab(int index
);
490 * Connects the signals from the created DolphinView with
491 * the DolphinViewContainer \a container with the corresponding slots of
492 * the DolphinMainWindow. This method must be invoked each
493 * time a DolphinView has been created.
495 void connectViewSignals(DolphinViewContainer
* container
);
498 * Updates the text of the split action:
499 * If two views are shown, the text is set to "Split",
500 * otherwise the text is set to "Join". The icon
501 * is updated to match with the text and the currently active view.
503 void updateSplitAction();
505 /** Returns the name of the tab for the URL \a url. */
506 QString
tabName(const KUrl
& url
) const;
508 bool isKompareInstalled() const;
510 void createSecondaryView(int tabIndex
);
513 * Helper method for saveProperties() and readProperties(): Returns
514 * the property string for a tab with the index \a tabIndex and
515 * the property \a property.
517 QString
tabProperty(const QString
& property
, int tabIndex
) 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 * Adds a clone of the action \a action to the action-collection with
529 * the name \a actionName, so that the action \a action also can be
530 * added to the toolbar by the user. This is useful if the creation of
531 * \a action is e.g. done in Qt and hence cannot be added directly
532 * to the action-collection.
534 void addActionCloneToCollection(QAction
* action
, const QString
& actionName
);
538 * Implements a custom error handling for the undo manager. This
539 * assures that all errors are shown in the status bar of Dolphin
540 * instead as modal error dialog with an OK button.
542 class UndoUiInterface
: public KIO::FileUndoManager::UiInterface
546 virtual ~UndoUiInterface();
547 virtual void jobError(KIO::Job
* job
);
550 KNewFileMenu
* m_newFileMenu
;
551 KActionMenu
* m_recentTabsMenu
;
553 DolphinViewContainer
* m_activeViewContainer
;
554 QVBoxLayout
* m_centralWidgetLayout
;
557 // Members for the tab-handling:
560 ViewTab() : isPrimaryViewActive(true), primaryView(0), secondaryView(0), splitter(0) {}
561 bool isPrimaryViewActive
;
562 DolphinViewContainer
* primaryView
;
563 DolphinViewContainer
* secondaryView
;
567 QList
<ViewTab
> m_viewTab
;
569 DolphinViewActionHandler
* m_actionHandler
;
570 DolphinRemoteEncoding
* m_remoteEncoding
;
571 QPointer
<DolphinSettingsDialog
> m_settingsDialog
;
573 // Members for the toolbar menu that is shown when the menubar is hidden:
574 QWidget
* m_toolBarSpacer
;
575 QToolButton
* m_openToolBarMenuButton
;
576 QWeakPointer
<KMenu
> m_toolBarMenu
;
577 QTimer
* m_updateToolBarTimer
;
579 KJob
* m_lastHandleUrlStatJob
;
582 * Set to true, if the filter dock visibility is only temporary set
583 * to true by enabling the search mode.
585 bool m_searchDockIsTemporaryVisible
;
588 inline DolphinViewContainer
* DolphinMainWindow::activeViewContainer() const
590 return m_activeViewContainer
;
593 inline bool DolphinMainWindow::isSplit() const
595 return m_viewTab
[m_tabIndex
].secondaryView
!= 0;
598 inline KNewFileMenu
* DolphinMainWindow::newFileMenu() const
600 return m_newFileMenu
;
603 inline int DolphinMainWindow::getId() const
608 #endif // DOLPHIN_MAINWINDOW_H