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
;
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 \p 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().
98 * If the main window contains two instances of a view container
99 * (DolphinMainWindow::isSplit() returns true), then the
100 * two views get toggled (the right view is on the left, the left
101 * view on the right).
105 /** Renames the item represented by \a oldUrl to \a newUrl. */
106 void rename(const KUrl
& oldUrl
, const KUrl
& newUrl
);
109 * Refreshes the views of the main window by recreating them dependent from
110 * the given Dolphin settings.
115 * Returns the 'Create New...' sub menu which also can be shared
116 * with other menus (e. g. a context menu).
118 KNewFileMenu
* newMenu() const;
121 * Returns the 'Show Menubar' action which can be shared with
122 * other menus (e. g. a context menu).
124 KAction
* showMenuBarAction() const;
128 * Pastes the clipboard data into the currently selected folder
129 * of the active view. If not exactly one folder is selected,
130 * no pasting is done at all.
132 void pasteIntoFolder();
135 * Returns the main window ID used through DBus.
140 * Implementation of the MainWindowAdaptor/QDBusAbstractAdaptor interface.
141 * Inform all affected dolphin components (panels, views) of an URL
144 void changeUrl(const KUrl
& url
);
146 /** Stores all settings and quits Dolphin. */
151 * Is sent if the selection of the currently active view has
154 void selectionChanged(const KFileItemList
& selection
);
157 * Is sent if the url of the currently active view has
160 void urlChanged(const KUrl
& url
);
163 * Is emitted if information of an item is requested to be shown e. g. in the panel.
164 * If item is null, no item information request is pending.
166 void requestItemInfo(const KFileItem
& item
);
169 /** @see QWidget::showEvent() */
170 virtual void showEvent(QShowEvent
* event
);
172 /** @see QMainWindow::closeEvent() */
173 virtual void closeEvent(QCloseEvent
* event
);
175 /** @see KMainWindow::saveProperties() */
176 virtual void saveProperties(KConfigGroup
& group
);
178 /** @see KMainWindow::readProperties() */
179 virtual void readProperties(const KConfigGroup
& group
);
182 void clearStatusBar();
184 /** Updates the 'Create New...' sub menu. */
185 void updateNewMenu();
187 void createDirectory();
189 /** Shows the error message in the status bar of the active view. */
190 void showErrorMessage(const QString
& message
);
193 * Updates the state of the 'Undo' menu action dependent
194 * from the parameter \a available.
196 void slotUndoAvailable(bool available
);
198 /** Invoked when an action in the recent tabs menu is clicked. */
199 void restoreClosedTab(QAction
* action
);
201 /** Sets the text of the 'Undo' menu action to \a text. */
202 void slotUndoTextChanged(const QString
& text
);
204 /** Performs the current undo operation. */
208 * Copies all selected items to the clipboard and marks
213 /** Copies all selected items to the clipboard. */
216 /** Pastes the clipboard data to the active view. */
220 * Updates the text of the paste action dependent from
221 * the number of items which are in the clipboard.
223 void updatePasteAction();
225 /** Selects all items from the active view. */
229 * Inverts the selection of all items of the active view:
230 * Selected items get nonselected and nonselected items get
233 void invertSelection();
236 * Switches between one and two views:
237 * If one view is visible, it will get split into two views.
238 * If already two views are visible, the nonactivated view gets closed.
240 void toggleSplitView();
242 /** Reloads the current active view. */
245 /** Stops the loading process for the current active view. */
249 * Toggles between showing and hiding of the filter bar
251 void toggleFilterBarVisibility(bool show
);
254 * Toggles between edit and browse mode of the navigation bar.
256 void toggleEditLocation();
259 * Switches to the edit mode of the navigation bar and selects
260 * the whole URL, so that it can be replaced by the user. If the edit mode is
261 * already active, it is assured that the navigation bar get focused.
263 void replaceLocation();
265 /** Goes back on step of the URL history. */
268 /** Goes forward one step of the URL history. */
271 /** Goes up one hierarchy of the current URL. */
275 * Open the previous URL in the URL history in a new tab
276 * if the middle mouse button is clicked.
278 void goBack(Qt::MouseButtons buttons
);
281 * Open the next URL in the URL history in a new tab
282 * if the middle mouse button is clicked.
284 void goForward(Qt::MouseButtons buttons
);
287 * Open the URL one hierarchy above the current URL in a new tab
288 * if the middle mouse button is clicked.
290 void goUp(Qt::MouseButtons buttons
);
292 /** Goes to the home URL. */
295 /** Opens Kompare for 2 selected files. */
299 * Hides the menu bar if it is visible, makes the menu bar
300 * visible if it is hidden.
302 void toggleShowMenuBar();
304 /** Opens a terminal window for the current location. */
307 /** Opens the settings dialog for Dolphin. */
310 /** Updates the state of the 'Show Full Location' action. */
311 void slotEditableStateChanged(bool editable
);
314 * Updates the state of the 'Edit' menu actions and emits
315 * the signal selectionChanged().
317 void slotSelectionChanged(const KFileItemList
& selection
);
319 /** Enables changing of tabs via mouse wheel. */
320 void slotWheelMoved(int wheelDelta
);
322 /** Emits the signal requestItemInfo(). */
323 void slotRequestItemInfo(const KFileItem
&);
326 * Updates the state of the 'Back' and 'Forward' menu
327 * actions corresponding to the current history.
329 void updateHistory();
331 /** Updates the state of the 'Show filter bar' menu action. */
332 void updateFilterBarAction(bool show
);
334 /** Open a new main window. */
335 void openNewMainWindow();
337 /** Opens a new view with the current URL that is part of a tab. */
341 * Opens a new tab showing the URL \a url.
343 void openNewTab(const KUrl
& url
);
345 void activateNextTab();
347 void activatePrevTab();
350 * Opens the selected folder in a new tab.
355 * Opens the selected folder in a new window.
357 void openInNewWindow();
359 /** Toggles the active view if two views are shown within the main window. */
360 void toggleActiveView();
363 * Indicates in the statusbar that the execution of the command \a command
366 void showCommand(CommandType command
);
369 * Activates the tab with the index \a index, which means that the current view
370 * is replaced by the view of the given tab.
372 void setActiveTab(int index
);
374 /** Closes the currently active tab. */
378 * Closes the tab with the index \index and activates the tab with index - 1.
380 void closeTab(int index
);
383 * Opens a context menu for the tab with the index \a index
384 * on the position \a pos.
386 void openTabContextMenu(int index
, const QPoint
& pos
);
389 * Is connected to the QTabBar signal tabMoved(int from, int to).
390 * Reorders the list of tabs after a tab was moved in the tab bar
391 * and sets m_tabIndex to the new index of the current tab.
393 void slotTabMoved(int from
, int to
);
396 * Handles a click on a places item: if the middle mouse button is
397 * clicked, a new tab is opened for \a url, otherwise the current
398 * view is replaced by \a url.
400 void handlePlacesClick(const KUrl
& url
, Qt::MouseButtons buttons
);
403 * Is connected to the KTabBar signal testCanDecode() and adjusts
404 * the output parameter \a accept.
406 void slotTestCanDecode(const QDragMoveEvent
* event
, bool& accept
);
409 * Is connected with the Dolphin search box and the search configurator
410 * and triggers a Nepomuk search.
415 * Is connected to the searchbox signal 'requestSearchOptions' and
416 * takes care to show the search options.
418 void showSearchOptions();
421 * If the URL can be listed open it in the current view, otherwise
422 * run it through KRun.
424 void handleUrl(const KUrl
& url
);
427 * setUrlAsCaption() will trigger a stat job which reports its result in
430 void slotCaptionStatFinished(KJob
* job
);
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
);
439 * Opens the context menu on the current mouse position.
440 * @item File item context. If item is null, the context menu
441 * should be applied to \a url.
442 * @url URL which contains \a item.
443 * @customActions Actions that should be added to the context menu,
444 * if the file item is null.
446 void openContextMenu(const KFileItem
& item
,
448 const QList
<QAction
*>& customActions
);
451 DolphinMainWindow(int id
);
455 * Activates the given view, which means that
456 * all menu actions are applied to this view. When
457 * having a split view setup, the nonactive view
458 * is usually shown in darker colors.
460 void setActiveViewContainer(DolphinViewContainer
* view
);
463 void setupDockWidgets();
464 void updateEditActions();
465 void updateViewActions();
466 void updateGoActions();
469 * Adds the tab[\a index] to the closed tab menu's list of actions.
471 void rememberClosedTab(int index
);
474 * Connects the signals from the created DolphinView with
475 * the DolphinViewContainer \a container with the corresponding slots of
476 * the DolphinMainWindow. This method must be invoked each
477 * time a DolphinView has been created.
479 void connectViewSignals(DolphinViewContainer
* container
);
482 * Updates the text of the split action:
483 * If two views are shown, the text is set to "Split",
484 * otherwise the text is set to "Join". The icon
485 * is updated to match with the text and the currently active view.
487 void updateSplitAction();
489 /** Returns the name of the tab for the URL \a url. */
490 QString
tabName(const KUrl
& url
) const;
492 bool isKompareInstalled() const;
494 void createSecondaryView(int tabIndex
);
497 * Helper method for saveProperties() and readProperties(): Returns
498 * the property string for a tab with the index \a tabIndex and
499 * the property \a property.
501 QString
tabProperty(const QString
& property
, int tabIndex
) const;
504 * Sets the window caption to url.fileName() if this is non-empty,
505 * "/" if the URL is "file:///", and url.protocol() otherwise.
507 void setUrlAsCaption(const KUrl
& url
);
509 QString
squeezedText(const QString
& text
) const;
513 * Implements a custom error handling for the undo manager. This
514 * assures that all errors are shown in the status bar of Dolphin
515 * instead as modal error dialog with an OK button.
517 class UndoUiInterface
: public KIO::FileUndoManager::UiInterface
521 virtual ~UndoUiInterface();
522 virtual void jobError(KIO::Job
* job
);
525 KNewFileMenu
* m_newMenu
;
526 KActionMenu
* m_recentTabsMenu
;
527 KAction
* m_showMenuBar
;
529 DolphinViewContainer
* m_activeViewContainer
;
530 QVBoxLayout
* m_centralWidgetLayout
;
531 DolphinSearchBox
* m_searchBox
;
532 DolphinSearchOptionsConfigurator
* m_searchOptionsConfigurator
;
537 ViewTab() : isPrimaryViewActive(true), primaryView(0), secondaryView(0), splitter(0) {}
538 bool isPrimaryViewActive
;
539 DolphinViewContainer
* primaryView
;
540 DolphinViewContainer
* secondaryView
;
545 QList
<ViewTab
> m_viewTab
;
547 DolphinViewActionHandler
* m_actionHandler
;
548 DolphinRemoteEncoding
* m_remoteEncoding
;
549 QPointer
<DolphinSettingsDialog
> m_settingsDialog
;
551 KJob
* m_captionStatJob
;
554 inline DolphinViewContainer
* DolphinMainWindow::activeViewContainer() const
556 return m_activeViewContainer
;
559 inline bool DolphinMainWindow::isSplit() const
561 return m_viewTab
[m_tabIndex
].secondaryView
!= 0;
564 inline KNewFileMenu
* DolphinMainWindow::newMenu() const
569 inline KAction
* DolphinMainWindow::showMenuBarAction() const
571 return m_showMenuBar
;
574 inline int DolphinMainWindow::getId() const
579 #endif // DOLPHIN_MAINWINDOW_H