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>
34 #include <QWeakPointer>
36 typedef KIO::FileUndoManager::CommandType CommandType
;
38 class DolphinViewActionHandler
;
39 class DolphinApplication
;
40 class DolphinSettingsDialog
;
41 class DolphinViewContainer
;
42 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
;
68 virtual ~DolphinMainWindow();
71 * Returns the currently active view.
72 * All menu actions are applied to this view. When
73 * having a split view setup, the nonactive view
74 * is usually shown in darker colors.
76 DolphinViewContainer
* activeViewContainer() const;
79 * Opens each directory in \p dirs in a separate tab. If the "split view"
80 * option is enabled, 2 directories are collected within one tab.
82 void openDirectories(const QList
<KUrl
>& dirs
);
85 * Opens the directory which contains the files \p files
86 * and selects all files (implements the --select option
89 void openFiles(const QList
<KUrl
>& files
);
92 * Returns true, if the main window contains two instances
93 * of a view container. The active view constainer can be
94 * accessed by DolphinMainWindow::activeViewContainer().
98 /** Renames the item represented by \a oldUrl to \a newUrl. */
99 void rename(const KUrl
& oldUrl
, const KUrl
& newUrl
);
102 * Returns the 'Create New...' sub menu which also can be shared
103 * with other menus (e. g. a context menu).
105 KNewFileMenu
* newFileMenu() const;
109 * Pastes the clipboard data into the currently selected folder
110 * of the active view. If not exactly one folder is selected,
111 * no pasting is done at all.
113 void pasteIntoFolder();
116 * Returns the main window ID used through DBus.
121 * Implementation of the MainWindowAdaptor/QDBusAbstractAdaptor interface.
122 * Inform all affected dolphin components (panels, views) of an URL
125 void changeUrl(const KUrl
& url
);
127 /** Stores all settings and quits Dolphin. */
132 * Is sent if the selection of the currently active view has
135 void selectionChanged(const KFileItemList
& selection
);
138 * Is sent if the url of the currently active view has
141 void urlChanged(const KUrl
& url
);
144 * Is emitted if information of an item is requested to be shown e. g. in the panel.
145 * If item is null, no item information request is pending.
147 void requestItemInfo(const KFileItem
& item
);
150 /** @see QWidget::showEvent() */
151 virtual void showEvent(QShowEvent
* event
);
153 /** @see QMainWindow::closeEvent() */
154 virtual void closeEvent(QCloseEvent
* event
);
156 /** @see KMainWindow::saveProperties() */
157 virtual void saveProperties(KConfigGroup
& group
);
159 /** @see KMainWindow::readProperties() */
160 virtual void readProperties(const KConfigGroup
& group
);
164 * Refreshes the views of the main window by recreating them according to
165 * the given Dolphin settings.
169 void clearStatusBar();
171 /** Updates the 'Create New...' sub menu. */
172 void updateNewMenu();
174 void createDirectory();
176 /** Shows the error message in the status bar of the active view. */
177 void showErrorMessage(const QString
& message
);
180 * Updates the state of the 'Undo' menu action dependent
181 * on the parameter \a available.
183 void slotUndoAvailable(bool available
);
185 /** Invoked when an action in the recent tabs menu is clicked. */
186 void restoreClosedTab(QAction
* action
);
188 /** Sets the text of the 'Undo' menu action to \a text. */
189 void slotUndoTextChanged(const QString
& text
);
191 /** Performs the current undo operation. */
195 * Copies all selected items to the clipboard and marks
200 /** Copies all selected items to the clipboard. */
203 /** Pastes the clipboard data to the active view. */
206 /** Replaces the URL navigator by a search box to find files. */
210 * Is invoked when the "Find" is active and the search location
211 * (From Here/Everywhere) has been changed. Updates the
212 * enabled state of the Search Panel.
214 void slotSearchLocationChanged();
217 * Updates the text of the paste action dependent on
218 * the number of items which are in the clipboard.
220 void updatePasteAction();
222 /** Selects all items from the active view. */
226 * Inverts the selection of all items of the active view:
227 * Selected items get nonselected and nonselected items get
230 void invertSelection();
233 * Switches between one and two views:
234 * If one view is visible, it will get split into two views.
235 * If already two views are visible, the active view gets closed.
237 void toggleSplitView();
239 /** Reloads the currently active view. */
242 /** Stops the loading process for the currently active view. */
245 void enableStopAction();
246 void disableStopAction();
248 void showFilterBar();
251 * Toggles between edit and browse mode of the navigation bar.
253 void toggleEditLocation();
256 * Switches to the edit mode of the navigation bar and selects
257 * the whole URL, so that it can be replaced by the user. If the edit mode is
258 * already active, it is assured that the navigation bar get focused.
260 void replaceLocation();
263 * Toggles the state of the panels between a locked and unlocked layout.
265 void togglePanelLockState();
268 * Is invoked if the Places panel got visible/invisible and takes care
269 * that the places-selector of all views is only shown if the Places panel
272 void slotPlacesPanelVisibilityChanged(bool visible
);
274 /** Goes back one step of the URL history. */
277 /** Goes forward one step of the URL history. */
280 /** Goes up one hierarchy of the current URL. */
283 /** Changes the location to the home URL. */
287 * Open the previous URL in the URL history in a new tab
288 * if the middle mouse button is clicked.
290 void goBack(Qt::MouseButtons buttons
);
293 * Open the next URL in the URL history in a new tab
294 * if the middle mouse button is clicked.
296 void goForward(Qt::MouseButtons buttons
);
299 * Open the URL one hierarchy above the current URL in a new tab
300 * if the middle mouse button is clicked.
302 void goUp(Qt::MouseButtons buttons
);
304 /** Opens Kompare for 2 selected files. */
308 * Hides the menu bar if it is visible, makes the menu bar
309 * visible if it is hidden.
311 void toggleShowMenuBar();
313 /** Opens a terminal window for the current location. */
316 /** Opens the settings dialog for Dolphin. */
319 /** Updates the state of the 'Show Full Location' action. */
320 void slotEditableStateChanged(bool editable
);
323 * Updates the state of the 'Edit' menu actions and emits
324 * the signal selectionChanged().
326 void slotSelectionChanged(const KFileItemList
& selection
);
328 /** Emits the signal requestItemInfo(). */
329 void slotRequestItemInfo(const KFileItem
&);
332 * Updates the state of the 'Back' and 'Forward' menu
333 * actions corresponding to the current history.
335 void updateHistory();
337 /** Updates the state of the 'Show filter bar' menu action. */
338 void updateFilterBarAction(bool show
);
340 /** Open a new main window. */
341 void openNewMainWindow();
343 /** Opens a new view with the current URL that is part of a tab. */
347 * Opens a new tab showing the URL \a url.
349 void openNewTab(const KUrl
& url
);
351 void activateNextTab();
353 void activatePrevTab();
356 * Opens the selected folder in a new tab.
361 * Opens the selected folder in a new window.
363 void openInNewWindow();
365 /** Toggles the active view if two views are shown within the main window. */
366 void toggleActiveView();
369 * Indicates in the statusbar that the execution of the command \a command
372 void showCommand(CommandType command
);
375 * Activates the tab with the index \a index, which means that the current view
376 * is replaced by the view of the given tab.
378 void setActiveTab(int index
);
380 /** Closes the currently active tab. */
384 * Closes the tab with the index \a index and activates the tab with index - 1.
386 void closeTab(int index
);
389 * Opens a context menu for the tab with the index \a index
390 * on the position \a pos.
392 void openTabContextMenu(int index
, const QPoint
& pos
);
395 * Is connected to the QTabBar signal tabMoved(int from, int to).
396 * Reorders the list of tabs after a tab was moved in the tab bar
397 * and sets m_tabIndex to the new index of the current tab.
399 void slotTabMoved(int from
, int to
);
402 * Handles a click on a places item: if the middle mouse button is
403 * clicked, a new tab is opened for \a url, otherwise the current
404 * view is replaced by \a url.
406 void handlePlacesClick(const KUrl
& url
, Qt::MouseButtons buttons
);
409 * Is connected to the KTabBar signal testCanDecode() and adjusts
410 * the output parameter \a accept.
412 void slotTestCanDecode(const QDragMoveEvent
* event
, bool& accept
);
415 * If the URL can be listed, open it in the current view, otherwise
416 * run it through KRun.
418 void handleUrl(const KUrl
& url
);
421 * handleUrl() can trigger a stat job to see if the url can actually
424 void slotHandleUrlStatFinished(KJob
* job
);
427 * Is connected to the KTabBar signal receivedDropEvent.
428 * Allows dragging and dropping files onto tabs.
430 void tabDropEvent(int tab
, QDropEvent
* event
);
433 * Is invoked when the write state of a folder has been changed and
434 * enables/disables the "Create New..." menu entry.
436 void slotWriteStateChanged(bool isFolderWritable
);
438 void slotSearchModeChanged(bool enabled
);
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 updateToolBarMenu();
455 void updateToolBar();
456 void slotToolBarSpacerDeleted();
457 void slotToolBarMenuButtonDeleted();
458 void slotToolBarIconSizeChanged(const QSize
& iconSize
);
462 * Activates the given view, which means that
463 * all menu actions are applied to this view. When
464 * having a split view setup, the nonactive view
465 * is usually shown in darker colors.
467 void setActiveViewContainer(DolphinViewContainer
* view
);
470 * Creates a view container and does a default initialization.
472 DolphinViewContainer
* createViewContainer(const KUrl
& url
, QWidget
* parent
);
475 void setupDockWidgets();
476 void updateEditActions();
477 void updateViewActions();
478 void updateGoActions();
480 void createToolBarMenuButton();
481 void deleteToolBarMenuButton();
484 * Adds the action \p action to the menu \p menu in
485 * case if it has not added already to the toolbar.
486 * @return True if the action has been added to the menu.
488 bool addActionToMenu(QAction
* action
, KMenu
* menu
);
491 * Adds the tab[\a index] to the closed tab menu's list of actions.
493 void rememberClosedTab(int index
);
496 * Connects the signals from the created DolphinView with
497 * the DolphinViewContainer \a container with the corresponding slots of
498 * the DolphinMainWindow. This method must be invoked each
499 * time a DolphinView has been created.
501 void connectViewSignals(DolphinViewContainer
* container
);
504 * Updates the text of the split action:
505 * If two views are shown, the text is set to "Split",
506 * otherwise the text is set to "Join". The icon
507 * is updated to match with the text and the currently active view.
509 void updateSplitAction();
511 /** Returns the name of the tab for the URL \a url. */
512 QString
tabName(const KUrl
& url
) const;
514 bool isKompareInstalled() const;
516 void createSecondaryView(int tabIndex
);
519 * Helper method for saveProperties() and readProperties(): Returns
520 * the property string for a tab with the index \a tabIndex and
521 * the property \a property.
523 QString
tabProperty(const QString
& property
, int tabIndex
) const;
526 * Sets the window caption to url.fileName() if this is non-empty,
527 * "/" if the URL is "file:///", and url.protocol() otherwise.
529 void setUrlAsCaption(const KUrl
& url
);
531 QString
squeezedText(const QString
& text
) const;
534 * Creates an action for showing/hiding a panel, that is accessible
535 * in "Configure toolbars..." and "Configure shortcuts...". This is necessary
536 * as the action for toggling the dock visibility is done by Qt which
537 * is no KAction instance.
539 void createPanelAction(const KIcon
& icon
,
540 const QKeySequence
& shortcut
,
542 const QString
& actionName
);
546 * Implements a custom error handling for the undo manager. This
547 * assures that all errors are shown in the status bar of Dolphin
548 * instead as modal error dialog with an OK button.
550 class UndoUiInterface
: public KIO::FileUndoManager::UiInterface
554 virtual ~UndoUiInterface();
555 virtual void jobError(KIO::Job
* job
);
558 KNewFileMenu
* m_newFileMenu
;
559 KActionMenu
* m_recentTabsMenu
;
561 DolphinViewContainer
* m_activeViewContainer
;
562 QVBoxLayout
* m_centralWidgetLayout
;
565 // Members for the tab-handling:
568 ViewTab() : isPrimaryViewActive(true), primaryView(0), secondaryView(0), splitter(0) {}
569 bool isPrimaryViewActive
;
570 DolphinViewContainer
* primaryView
;
571 DolphinViewContainer
* secondaryView
;
575 QList
<ViewTab
> m_viewTab
;
577 DolphinViewActionHandler
* m_actionHandler
;
578 DolphinRemoteEncoding
* m_remoteEncoding
;
579 QWeakPointer
<DolphinSettingsDialog
> m_settingsDialog
;
581 // Members for the toolbar menu that is shown when the menubar is hidden:
582 QWidget
* m_toolBarSpacer
;
583 QToolButton
* m_openToolBarMenuButton
;
584 QTimer
* m_updateToolBarTimer
;
586 KJob
* m_lastHandleUrlStatJob
;
589 * Set to true, if the filter dock visibility is only temporary set
590 * to true by enabling the search mode.
592 bool m_searchDockIsTemporaryVisible
;
595 inline DolphinViewContainer
* DolphinMainWindow::activeViewContainer() const
597 return m_activeViewContainer
;
600 inline bool DolphinMainWindow::isSplit() const
602 return m_viewTab
[m_tabIndex
].secondaryView
!= 0;
605 inline KNewFileMenu
* DolphinMainWindow::newFileMenu() const
607 return m_newFileMenu
;
610 inline int DolphinMainWindow::getId() const
615 #endif // DOLPHIN_MAINWINDOW_H