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>
35 #include <QtCore/QList>
37 typedef KIO::FileUndoManager::CommandType CommandType
;
40 class DolphinViewActionHandler
;
41 class DolphinApplication
;
42 class DolphinSettingsDialog
;
43 class DolphinViewContainer
;
51 * @short Main window for Dolphin.
53 * Handles the menus, toolbars and Dolphin views.
55 class DolphinMainWindow
: public KXmlGuiWindow
58 Q_CLASSINFO("D-Bus Interface", "org.kde.dolphin.MainWindow")
59 Q_PROPERTY(int id READ getId SCRIPTABLE
true)
60 friend class DolphinApplication
;
63 virtual ~DolphinMainWindow();
66 * Returns the currently active view.
67 * All menu actions are applied to this view. When
68 * having a split view setup, the nonactive view
69 * is usually shown in darker colors.
71 DolphinViewContainer
* activeViewContainer() const;
74 * Returns true, if the main window contains two instances
75 * of a view container. The active view constainer can be
76 * accessed by DolphinMainWindow::activeViewContainer().
81 * If the main window contains two instances of a view container
82 * (DolphinMainWindow::isSplit() returns true), then the
83 * two views get toggled (the right view is on the left, the left
88 /** Renames the item represented by \a oldUrl to \a newUrl. */
89 void rename(const KUrl
& oldUrl
, const KUrl
& newUrl
);
92 * Refreshes the views of the main window by recreating them dependent from
93 * the given Dolphin settings.
98 * Returns the 'Create New...' sub menu which also can be shared
99 * with other menus (e. g. a context menu).
101 KNewMenu
* newMenu() const;
104 * Returns the 'Show Menubar' action which can be shared with
105 * other menus (e. g. a context menu).
107 KAction
* showMenuBarAction() const;
111 * Pastes the clipboard data into the currently selected folder
112 * of the active view. If not exactly one folder is selected,
113 * no pasting is done at all.
115 void pasteIntoFolder();
118 * Returns the main window ID used through DBus.
123 * Inform all affected dolphin components (panels, views) of an URL
126 void changeUrl(const KUrl
& url
);
129 * Inform all affected dolphin components that a selection change is
132 void changeSelection(const KFileItemList
& selection
);
134 /** Stores all settings and quits Dolphin. */
139 * Is sent if the selection of the currently active view has
142 void selectionChanged(const KFileItemList
& selection
);
145 * Is sent if the url of the currently active view has
148 void urlChanged(const KUrl
& url
);
151 * Is emitted if information of an item is requested to be shown e. g. in the panel.
152 * If item is null, no item information request is pending.
154 void requestItemInfo(const KFileItem
& item
);
157 /** @see QMainWindow::closeEvent() */
158 virtual void closeEvent(QCloseEvent
* event
);
160 /** @see KMainWindow::saveProperties() */
161 virtual void saveProperties(KConfigGroup
& group
);
163 /** @see KMainWindow::readProperties() */
164 virtual void readProperties(const KConfigGroup
& group
);
167 void clearStatusBar();
169 /** Updates the 'Create New...' sub menu. */
170 void updateNewMenu();
172 /** Shows the error message in the status bar of the active view. */
173 void showErrorMessage(const QString
& message
);
176 * Updates the state of the 'Undo' menu action dependent
177 * from the parameter \a available.
179 void slotUndoAvailable(bool available
);
181 /** Sets the text of the 'Undo' menu action to \a text. */
182 void slotUndoTextChanged(const QString
& text
);
184 /** Performs the current undo operation. */
188 * Copies all selected items to the clipboard and marks
189 * the items as cutted.
193 /** Copies all selected items to the clipboard. */
196 /** Pastes the clipboard data to the active view. */
200 * Updates the text of the paste action dependent from
201 * the number of items which are in the clipboard.
203 void updatePasteAction();
205 /** Selects all items from the active view. */
209 * Inverts the selection of all items of the active view:
210 * Selected items get nonselected and nonselected items get
213 void invertSelection();
216 * Switches between one and two views:
217 * If one view is visible, it will get split into two views.
218 * If already two views are visible, the nonactivated view gets closed.
220 void toggleSplitView();
222 /** Reloads the current active view. */
225 /** Stops the loading process for the current active view. */
229 * Toggles between showing and hiding of the filter bar
231 void toggleFilterBarVisibility(bool show
);
234 * Toggles between edit and browse mode of the navigation bar.
236 void toggleEditLocation();
239 * Switches to the edit mode of the navigation bar and selects
240 * the whole URL, so that it can be replaced by the user. If the edit mode is
241 * already active, it is assured that the navigation bar get focused.
243 void replaceLocation();
245 /** Goes back on step of the URL history. */
248 /** Goes forward one step of the URL history. */
251 /** Goes up one hierarchy of the current URL. */
254 /** Goes to the home URL. */
257 /** Opens Kompare for 2 selected files. */
261 * Initiates a preview of the selected files
262 * on the desktop by the Previewer plasmoid.
267 * Hides the menu bar if it is visible, makes the menu bar
268 * visible if it is hidden.
270 void toggleShowMenuBar();
272 /** Opens the settings dialog for Dolphin. */
275 /** Updates the state of the 'Show Full Location' action. */
276 void slotEditableStateChanged(bool editable
);
279 * Updates the state of the 'Edit' menu actions and emits
280 * the signal selectionChanged().
282 void slotSelectionChanged(const KFileItemList
& selection
);
284 /** Emits the signal requestItemInfo(). */
285 void slotRequestItemInfo(const KFileItem
&);
288 * Updates the state of the 'Back' and 'Forward' menu
289 * actions corresponding to the current history.
291 void updateHistory();
293 /** Updates the state of the 'Show filter bar' menu action. */
294 void updateFilterBarAction(bool show
);
296 /** Open a new main window. */
297 void openNewMainWindow();
299 /** Opens a new view with the current URL that is part of a tab. */
303 * Opens a new tab showing the URL \a url.
305 void openNewTab(const KUrl
& url
);
307 void activateNextTab();
309 void activatePrevTab();
312 * Opens the selected folder in a new tab.
317 * Opens the selected folder in a new window.
319 void openInNewWindow();
321 /** Toggles the active view if two views are shown within the main window. */
322 void toggleActiveView();
325 * Indicates in the statusbar that the execution of the command \a command
328 void showCommand(CommandType command
);
331 * Activates the tab with the index \a index, which means that the current view
332 * is replaced by the view of the given tab.
334 void setActiveTab(int index
);
336 /** Closes the currently active tab. */
340 * Closes the tab with the index \index and activates the tab with index - 1.
342 void closeTab(int index
);
345 * Opens a context menu for the tab with the index \a index
346 * on the position \a pos.
348 void openTabContextMenu(int index
, const QPoint
& pos
);
351 * Handles a click on a places item: if the middle mouse button is
352 * clicked, a new tab is opened for \a url, otherwise the current
353 * view is replaced by \a url.
355 void handlePlacesClick(const KUrl
& url
, Qt::MouseButtons buttons
);
358 * Is connected to the KTabBar signal testCanDecode() and adjusts
359 * the output parameter \a accept.
361 void slotTestCanDecode(const QDragMoveEvent
* event
, bool& accept
);
364 DolphinMainWindow(int id
);
368 * Activates the given view, which means that
369 * all menu actions are applied to this view. When
370 * having a split view setup, the nonactive view
371 * is usually shown in darker colors.
373 void setActiveViewContainer(DolphinViewContainer
* view
);
376 void setupDockWidgets();
377 void updateEditActions();
378 void updateViewActions();
379 void updateGoActions();
382 * Connects the signals from the created DolphinView with
383 * the DolphinViewContainer \a container with the corresponding slots of
384 * the DolphinMainWindow. This method must be invoked each
385 * time a DolphinView has been created.
387 void connectViewSignals(DolphinViewContainer
* container
);
390 * Updates the text of the split action:
391 * If two views are shown, the text is set to "Split",
392 * otherwise the text is set to "Join". The icon
393 * is updated to match with the text and the currently active view.
395 void updateSplitAction();
397 /** Returns the name of the tab for the URL \a url. */
398 QString
tabName(const KUrl
& url
) const;
400 bool isKompareInstalled() const;
402 void createSecondaryView(int tabIndex
);
406 * Implements a custom error handling for the undo manager. This
407 * assures that all errors are shown in the status bar of Dolphin
408 * instead as modal error dialog with an OK button.
410 class UndoUiInterface
: public KIO::FileUndoManager::UiInterface
414 virtual ~UndoUiInterface();
415 virtual void jobError(KIO::Job
* job
);
419 KAction
* m_showMenuBar
;
421 DolphinViewContainer
* m_activeViewContainer
;
422 QVBoxLayout
* m_centralWidgetLayout
;
427 ViewTab() : isPrimaryViewActive(true), primaryView(0), secondaryView(0), splitter(0) {}
428 bool isPrimaryViewActive
;
429 DolphinViewContainer
* primaryView
;
430 DolphinViewContainer
* secondaryView
;
435 QList
<ViewTab
> m_viewTab
;
437 DolphinViewActionHandler
* m_actionHandler
;
438 QPointer
<DolphinSettingsDialog
> m_settingsDialog
;
441 inline DolphinViewContainer
* DolphinMainWindow::activeViewContainer() const
443 return m_activeViewContainer
;
446 inline bool DolphinMainWindow::isSplit() const
448 return m_viewTab
[m_tabIndex
].secondaryView
!= 0;
451 inline KNewMenu
* DolphinMainWindow::newMenu() const
456 inline KAction
* DolphinMainWindow::showMenuBarAction() const
458 return m_showMenuBar
;
461 inline int DolphinMainWindow::getId() const
466 #endif // DOLPHIN_MAINWINDOW_H