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. */
276 * Open the previous URL in the URL history in a new tab
277 * if the middle mouse button is clicked.
279 void goBack(Qt::MouseButtons buttons
);
282 * Open the next URL in the URL history in a new tab
283 * if the middle mouse button is clicked.
285 void goForward(Qt::MouseButtons buttons
);
288 * Open the URL one hierarchy above the current URL in a new tab
289 * if the middle mouse button is clicked.
291 void goUp(Qt::MouseButtons buttons
);
293 /** Opens Kompare for 2 selected files. */
297 * Hides the menu bar if it is visible, makes the menu bar
298 * visible if it is hidden.
300 void toggleShowMenuBar();
302 /** Opens a terminal window for the current location. */
305 /** Opens the settings dialog for Dolphin. */
308 /** Updates the state of the 'Show Full Location' action. */
309 void slotEditableStateChanged(bool editable
);
312 * Updates the state of the 'Edit' menu actions and emits
313 * the signal selectionChanged().
315 void slotSelectionChanged(const KFileItemList
& selection
);
317 /** Emits the signal requestItemInfo(). */
318 void slotRequestItemInfo(const KFileItem
&);
321 * Updates the state of the 'Back' and 'Forward' menu
322 * actions corresponding to the current history.
324 void updateHistory();
326 /** Updates the state of the 'Show filter bar' menu action. */
327 void updateFilterBarAction(bool show
);
329 /** Open a new main window. */
330 void openNewMainWindow();
332 /** Opens a new view with the current URL that is part of a tab. */
336 * Opens a new tab showing the URL \a url.
338 void openNewTab(const KUrl
& url
);
340 void activateNextTab();
342 void activatePrevTab();
345 * Opens the selected folder in a new tab.
350 * Opens the selected folder in a new window.
352 void openInNewWindow();
354 /** Toggles the active view if two views are shown within the main window. */
355 void toggleActiveView();
358 * Indicates in the statusbar that the execution of the command \a command
361 void showCommand(CommandType command
);
364 * Activates the tab with the index \a index, which means that the current view
365 * is replaced by the view of the given tab.
367 void setActiveTab(int index
);
369 /** Closes the currently active tab. */
373 * Closes the tab with the index \a index and activates the tab with index - 1.
375 void closeTab(int index
);
378 * Opens a context menu for the tab with the index \a index
379 * on the position \a pos.
381 void openTabContextMenu(int index
, const QPoint
& pos
);
384 * Is connected to the QTabBar signal tabMoved(int from, int to).
385 * Reorders the list of tabs after a tab was moved in the tab bar
386 * and sets m_tabIndex to the new index of the current tab.
388 void slotTabMoved(int from
, int to
);
391 * Handles a click on a places item: if the middle mouse button is
392 * clicked, a new tab is opened for \a url, otherwise the current
393 * view is replaced by \a url.
395 void handlePlacesClick(const KUrl
& url
, Qt::MouseButtons buttons
);
398 * Is connected to the KTabBar signal testCanDecode() and adjusts
399 * the output parameter \a accept.
401 void slotTestCanDecode(const QDragMoveEvent
* event
, bool& accept
);
404 * If the URL can be listed, open it in the current view, otherwise
405 * run it through KRun.
407 void handleUrl(const KUrl
& url
);
410 * handleUrl() can trigger a stat job to see if the url can actually
413 void slotHandleUrlStatFinished(KJob
* job
);
416 * Is connected to the KTabBar signal receivedDropEvent.
417 * Allows dragging and dropping files onto tabs.
419 void tabDropEvent(int tab
, QDropEvent
* event
);
422 * Is invoked when the write state of a folder has been changed and
423 * enables/disables the "Create New..." menu entry.
425 void slotWriteStateChanged(bool isFolderWritable
);
427 void slotSearchModeChanged(bool enabled
);
430 * Opens the context menu on the current mouse position.
431 * @item File item context. If item is null, the context menu
432 * should be applied to \a url.
433 * @url URL which contains \a item.
434 * @customActions Actions that should be added to the context menu,
435 * if the file item is null.
437 void openContextMenu(const KFileItem
& item
,
439 const QList
<QAction
*>& customActions
);
441 void openToolBarMenu();
442 void updateToolBarMenu();
443 void updateToolBar();
444 void slotToolBarSpacerDeleted();
445 void slotToolBarMenuButtonDeleted();
448 DolphinMainWindow(int id
);
452 * Activates the given view, which means that
453 * all menu actions are applied to this view. When
454 * having a split view setup, the nonactive view
455 * is usually shown in darker colors.
457 void setActiveViewContainer(DolphinViewContainer
* view
);
460 * Creates a view container and does a default initialization.
462 DolphinViewContainer
* createViewContainer(const KUrl
& url
, QWidget
* parent
);
465 void setupDockWidgets();
466 void updateEditActions();
467 void updateViewActions();
468 void updateGoActions();
470 void createToolBarMenuButton();
471 void deleteToolBarMenuButton();
474 * Adds the action \p action to the menu \p menu in
475 * case if it has not added already to the toolbar.
476 * @return True if the action has been added to the menu.
478 bool addActionToMenu(QAction
* action
, KMenu
* menu
);
481 * Adds the tab[\a index] to the closed tab menu's list of actions.
483 void rememberClosedTab(int index
);
486 * Connects the signals from the created DolphinView with
487 * the DolphinViewContainer \a container with the corresponding slots of
488 * the DolphinMainWindow. This method must be invoked each
489 * time a DolphinView has been created.
491 void connectViewSignals(DolphinViewContainer
* container
);
494 * Updates the text of the split action:
495 * If two views are shown, the text is set to "Split",
496 * otherwise the text is set to "Join". The icon
497 * is updated to match with the text and the currently active view.
499 void updateSplitAction();
501 /** Returns the name of the tab for the URL \a url. */
502 QString
tabName(const KUrl
& url
) const;
504 bool isKompareInstalled() const;
506 void createSecondaryView(int tabIndex
);
509 * Helper method for saveProperties() and readProperties(): Returns
510 * the property string for a tab with the index \a tabIndex and
511 * the property \a property.
513 QString
tabProperty(const QString
& property
, int tabIndex
) const;
516 * Sets the window caption to url.fileName() if this is non-empty,
517 * "/" if the URL is "file:///", and url.protocol() otherwise.
519 void setUrlAsCaption(const KUrl
& url
);
521 QString
squeezedText(const QString
& text
) const;
524 * Adds a clone of the action \a action to the action-collection with
525 * the name \a actionName, so that the action \a action also can be
526 * added to the toolbar by the user. This is useful if the creation of
527 * \a action is e.g. done in Qt and hence cannot be added directly
528 * to the action-collection.
530 void addActionCloneToCollection(QAction
* action
, const QString
& actionName
);
534 * Implements a custom error handling for the undo manager. This
535 * assures that all errors are shown in the status bar of Dolphin
536 * instead as modal error dialog with an OK button.
538 class UndoUiInterface
: public KIO::FileUndoManager::UiInterface
542 virtual ~UndoUiInterface();
543 virtual void jobError(KIO::Job
* job
);
546 KNewFileMenu
* m_newFileMenu
;
547 KActionMenu
* m_recentTabsMenu
;
549 DolphinViewContainer
* m_activeViewContainer
;
550 QVBoxLayout
* m_centralWidgetLayout
;
553 // Members for the tab-handling:
556 ViewTab() : isPrimaryViewActive(true), primaryView(0), secondaryView(0), splitter(0) {}
557 bool isPrimaryViewActive
;
558 DolphinViewContainer
* primaryView
;
559 DolphinViewContainer
* secondaryView
;
563 QList
<ViewTab
> m_viewTab
;
565 DolphinViewActionHandler
* m_actionHandler
;
566 DolphinRemoteEncoding
* m_remoteEncoding
;
567 QPointer
<DolphinSettingsDialog
> m_settingsDialog
;
569 // Members for the toolbar menu that is shown when the menubar is hidden:
570 QWidget
* m_toolBarSpacer
;
571 KPushButton
* m_openToolBarMenuButton
;
572 QWeakPointer
<KMenu
> m_toolBarMenu
;
573 QTimer
* m_updateToolBarTimer
;
575 KJob
* m_lastHandleUrlStatJob
;
578 * Set to true, if the filter dock visibility is only temporary set
579 * to true by enabling the search mode.
581 bool m_searchDockIsTemporaryVisible
;
584 inline DolphinViewContainer
* DolphinMainWindow::activeViewContainer() const
586 return m_activeViewContainer
;
589 inline bool DolphinMainWindow::isSplit() const
591 return m_viewTab
[m_tabIndex
].secondaryView
!= 0;
594 inline KNewFileMenu
* DolphinMainWindow::newFileMenu() const
596 return m_newFileMenu
;
599 inline int DolphinMainWindow::getId() const
604 #endif // DOLPHIN_MAINWINDOW_H