1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
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 "dolphinview.h"
26 #include "panels/panel.h"
28 #include <config-nepomuk.h>
30 #include <kfileitemdelegate.h>
31 #include <kio/fileundomanager.h>
32 #include <ksortablelist.h>
33 #include <kxmlguiwindow.h>
34 #include <kactionmenu.h>
36 #include <QtCore/QList>
38 typedef KIO::FileUndoManager::CommandType CommandType
;
41 class DolphinViewActionHandler
;
42 class DolphinApplication
;
43 class DolphinSearchBox
;
44 class DolphinSearchOptionsConfigurator
;
45 class DolphinSettingsDialog
;
46 class DolphinViewContainer
;
47 class DolphinRemoteEncoding
;
54 * @short Main window for Dolphin.
56 * Handles the menus, toolbars and Dolphin views.
58 class DolphinMainWindow
: public KXmlGuiWindow
61 Q_CLASSINFO("D-Bus Interface", "org.kde.dolphin.MainWindow")
62 Q_PROPERTY(int id READ getId SCRIPTABLE
true)
63 friend class DolphinApplication
;
66 virtual ~DolphinMainWindow();
69 * Returns the currently active view.
70 * All menu actions are applied to this view. When
71 * having a split view setup, the nonactive view
72 * is usually shown in darker colors.
74 DolphinViewContainer
* activeViewContainer() const;
77 * Returns true, if the main window contains two instances
78 * of a view container. The active view constainer can be
79 * accessed by DolphinMainWindow::activeViewContainer().
84 * If the main window contains two instances of a view container
85 * (DolphinMainWindow::isSplit() returns true), then the
86 * two views get toggled (the right view is on the left, the left
91 /** Renames the item represented by \a oldUrl to \a newUrl. */
92 void rename(const KUrl
& oldUrl
, const KUrl
& newUrl
);
95 * Refreshes the views of the main window by recreating them dependent from
96 * the given Dolphin settings.
101 * Returns the 'Create New...' sub menu which also can be shared
102 * with other menus (e. g. a context menu).
104 KNewMenu
* newMenu() const;
107 * Returns the 'Show Menubar' action which can be shared with
108 * other menus (e. g. a context menu).
110 KAction
* showMenuBarAction() 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 * Inform all affected dolphin components (panels, views) of an URL
129 void changeUrl(const KUrl
& url
);
132 * Inform all affected dolphin components that a selection change is
135 void changeSelection(const KFileItemList
& selection
);
137 /** Stores all settings and quits Dolphin. */
142 * Is sent if the selection of the currently active view has
145 void selectionChanged(const KFileItemList
& selection
);
148 * Is sent if the url of the currently active view has
151 void urlChanged(const KUrl
& url
);
154 * Is emitted if information of an item is requested to be shown e. g. in the panel.
155 * If item is null, no item information request is pending.
157 void requestItemInfo(const KFileItem
& item
);
160 /** @see QMainWindow::closeEvent() */
161 virtual void closeEvent(QCloseEvent
* event
);
163 /** @see KMainWindow::saveProperties() */
164 virtual void saveProperties(KConfigGroup
& group
);
166 /** @see KMainWindow::readProperties() */
167 virtual void readProperties(const KConfigGroup
& group
);
170 void clearStatusBar();
172 /** Updates the 'Create New...' sub menu. */
173 void updateNewMenu();
175 void createDirectory();
177 /** Shows the error message in the status bar of the active view. */
178 void showErrorMessage(const QString
& message
);
181 * Updates the state of the 'Undo' menu action dependent
182 * from the parameter \a available.
184 void slotUndoAvailable(bool available
);
186 /** Invoked when an action in the recent tabs menu is clicked. */
187 void restoreClosedTab(QAction
* action
);
189 /** Sets the text of the 'Undo' menu action to \a text. */
190 void slotUndoTextChanged(const QString
& text
);
192 /** Performs the current undo operation. */
196 * Copies all selected items to the clipboard and marks
201 /** Copies all selected items to the clipboard. */
204 /** Pastes the clipboard data to the active view. */
208 * Updates the text of the paste action dependent from
209 * the number of items which are in the clipboard.
211 void updatePasteAction();
213 /** Selects all items from the active view. */
217 * Inverts the selection of all items of the active view:
218 * Selected items get nonselected and nonselected items get
221 void invertSelection();
224 * Switches between one and two views:
225 * If one view is visible, it will get split into two views.
226 * If already two views are visible, the nonactivated view gets closed.
228 void toggleSplitView();
230 /** Reloads the current active view. */
233 /** Stops the loading process for the current active view. */
237 * Toggles between showing and hiding of the filter bar
239 void toggleFilterBarVisibility(bool show
);
242 * Toggles between edit and browse mode of the navigation bar.
244 void toggleEditLocation();
247 * Switches to the edit mode of the navigation bar and selects
248 * the whole URL, so that it can be replaced by the user. If the edit mode is
249 * already active, it is assured that the navigation bar get focused.
251 void replaceLocation();
253 /** Goes back on step of the URL history. */
256 /** Goes forward one step of the URL history. */
259 /** Goes up one hierarchy of the current URL. */
262 /** Goes to the home URL. */
265 /** Opens Kompare for 2 selected files. */
269 * Hides the menu bar if it is visible, makes the menu bar
270 * visible if it is hidden.
272 void toggleShowMenuBar();
274 /** Opens a terminal window for the current location. */
277 /** Opens the settings dialog for Dolphin. */
280 /** Updates the state of the 'Show Full Location' action. */
281 void slotEditableStateChanged(bool editable
);
284 * Updates the state of the 'Edit' menu actions and emits
285 * the signal selectionChanged().
287 void slotSelectionChanged(const KFileItemList
& selection
);
289 /** Enables changing of tabs via mouse wheel. */
290 void slotWheelMoved(int wheelDelta
);
292 /** Emits the signal requestItemInfo(). */
293 void slotRequestItemInfo(const KFileItem
&);
296 * Updates the state of the 'Back' and 'Forward' menu
297 * actions corresponding to the current history.
299 void updateHistory();
301 /** Updates the state of the 'Show filter bar' menu action. */
302 void updateFilterBarAction(bool show
);
304 /** Open a new main window. */
305 void openNewMainWindow();
307 /** Opens a new view with the current URL that is part of a tab. */
311 * Opens a new tab showing the URL \a url.
313 void openNewTab(const KUrl
& url
);
315 void activateNextTab();
317 void activatePrevTab();
320 * Opens the selected folder in a new tab.
325 * Opens the selected folder in a new window.
327 void openInNewWindow();
329 /** Toggles the active view if two views are shown within the main window. */
330 void toggleActiveView();
333 * Indicates in the statusbar that the execution of the command \a command
336 void showCommand(CommandType command
);
339 * Activates the tab with the index \a index, which means that the current view
340 * is replaced by the view of the given tab.
342 void setActiveTab(int index
);
344 /** Closes the currently active tab. */
348 * Closes the tab with the index \index and activates the tab with index - 1.
350 void closeTab(int index
);
354 * Opens a context menu for the tab with the index \a index
355 * on the position \a pos.
357 void openTabContextMenu(int index
, const QPoint
& pos
);
360 * Handles a click on a places item: if the middle mouse button is
361 * clicked, a new tab is opened for \a url, otherwise the current
362 * view is replaced by \a url.
364 void handlePlacesClick(const KUrl
& url
, Qt::MouseButtons buttons
);
367 * Is connected to the KTabBar signal testCanDecode() and adjusts
368 * the output parameter \a accept.
370 void slotTestCanDecode(const QDragMoveEvent
* event
, bool& accept
);
373 * Is connected with the Dolphin search box and searchs items that
374 * match to the text entered in the search bar.
376 void searchItems(const KUrl
& url
);
379 * Is connected to the QTabBar signal tabMoved(int from, int to).
380 * Reorders the list of tabs after a tab was moved in the tab bar
381 * and sets m_tabIndex to the new index of the current tab.
383 void slotTabMoved(int from
, int to
);
386 * Is connected to the searchbox signal 'textChanged' and
387 * takes care to make the search options configurator visible
388 * if a search text has been entered.
390 void slotSearchBoxTextChanged(const QString
& text
);
393 DolphinMainWindow(int id
);
397 * Activates the given view, which means that
398 * all menu actions are applied to this view. When
399 * having a split view setup, the nonactive view
400 * is usually shown in darker colors.
402 void setActiveViewContainer(DolphinViewContainer
* view
);
405 void setupDockWidgets();
406 void updateEditActions();
407 void updateViewActions();
408 void updateGoActions();
411 * Adds the tab[\a index] to the closed tab menu's list of actions.
413 void rememberClosedTab(int index
);
416 * Connects the signals from the created DolphinView with
417 * the DolphinViewContainer \a container with the corresponding slots of
418 * the DolphinMainWindow. This method must be invoked each
419 * time a DolphinView has been created.
421 void connectViewSignals(DolphinViewContainer
* container
);
424 * Updates the text of the split action:
425 * If two views are shown, the text is set to "Split",
426 * otherwise the text is set to "Join". The icon
427 * is updated to match with the text and the currently active view.
429 void updateSplitAction();
431 /** Returns the name of the tab for the URL \a url. */
432 QString
tabName(const KUrl
& url
) const;
434 bool isKompareInstalled() const;
436 void createSecondaryView(int tabIndex
);
439 * Helper method for saveProperties() and readProperties(): Returns
440 * the property string for a tab with the index \a tabIndex and
441 * the property \a property.
443 QString
tabProperty(const QString
& property
, int tabIndex
) const;
446 * Sets the window caption to url.fileName() if this is non-empty,
447 * "/" if the URL is "file:///", and url.protocol() otherwise.
449 void setUrlAsCaption(const KUrl
& url
);
451 QString
squeezedText(const QString
& text
) const;
455 * Implements a custom error handling for the undo manager. This
456 * assures that all errors are shown in the status bar of Dolphin
457 * instead as modal error dialog with an OK button.
459 class UndoUiInterface
: public KIO::FileUndoManager::UiInterface
463 virtual ~UndoUiInterface();
464 virtual void jobError(KIO::Job
* job
);
468 KActionMenu
* m_recentTabsMenu
;
469 KAction
* m_showMenuBar
;
471 DolphinViewContainer
* m_activeViewContainer
;
472 QVBoxLayout
* m_centralWidgetLayout
;
473 DolphinSearchBox
* m_searchBox
;
474 DolphinSearchOptionsConfigurator
* m_searchOptionsConfigurator
;
479 ViewTab() : isPrimaryViewActive(true), primaryView(0), secondaryView(0), splitter(0) {}
480 bool isPrimaryViewActive
;
481 DolphinViewContainer
* primaryView
;
482 DolphinViewContainer
* secondaryView
;
487 QList
<ViewTab
> m_viewTab
;
489 DolphinViewActionHandler
* m_actionHandler
;
490 DolphinRemoteEncoding
* m_remoteEncoding
;
491 QPointer
<DolphinSettingsDialog
> m_settingsDialog
;
494 inline DolphinViewContainer
* DolphinMainWindow::activeViewContainer() const
496 return m_activeViewContainer
;
499 inline bool DolphinMainWindow::isSplit() const
501 return m_viewTab
[m_tabIndex
].secondaryView
!= 0;
504 inline KNewMenu
* DolphinMainWindow::newMenu() const
509 inline KAction
* DolphinMainWindow::showMenuBarAction() const
511 return m_showMenuBar
;
514 inline int DolphinMainWindow::getId() const
519 #endif // DOLPHIN_MAINWINDOW_H