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 KNewMenu
* 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
);
384 * Opens a context menu for the tab with the index \a index
385 * on the position \a pos.
387 void openTabContextMenu(int index
, const QPoint
& pos
);
390 * Handles a click on a places item: if the middle mouse button is
391 * clicked, a new tab is opened for \a url, otherwise the current
392 * view is replaced by \a url.
394 void handlePlacesClick(const KUrl
& url
, Qt::MouseButtons buttons
);
397 * Is connected to the KTabBar signal testCanDecode() and adjusts
398 * the output parameter \a accept.
400 void slotTestCanDecode(const QDragMoveEvent
* event
, bool& accept
);
403 * Is connected with the Dolphin search box and the search configurator
404 * and triggers a Nepomuk search.
409 * Is connected to the QTabBar signal tabMoved(int from, int to).
410 * Reorders the list of tabs after a tab was moved in the tab bar
411 * and sets m_tabIndex to the new index of the current tab.
413 void slotTabMoved(int from
, int to
);
416 * Is connected to the searchbox signal 'requestSearchOptions' and
417 * takes care to show the search options.
419 void showSearchOptions();
422 * If the URL can be listed open it in the current view, otherwise
423 * run it through KRun.
425 void handleUrl(const KUrl
& url
);
428 * setUrlAsCaption() will trigger a stat job which reports its result in
431 void slotCaptionStatFinished(KJob
* job
);
434 DolphinMainWindow(int id
);
438 * Activates the given view, which means that
439 * all menu actions are applied to this view. When
440 * having a split view setup, the nonactive view
441 * is usually shown in darker colors.
443 void setActiveViewContainer(DolphinViewContainer
* view
);
446 void setupDockWidgets();
447 void updateEditActions();
448 void updateViewActions();
449 void updateGoActions();
452 * Adds the tab[\a index] to the closed tab menu's list of actions.
454 void rememberClosedTab(int index
);
457 * Connects the signals from the created DolphinView with
458 * the DolphinViewContainer \a container with the corresponding slots of
459 * the DolphinMainWindow. This method must be invoked each
460 * time a DolphinView has been created.
462 void connectViewSignals(DolphinViewContainer
* container
);
465 * Updates the text of the split action:
466 * If two views are shown, the text is set to "Split",
467 * otherwise the text is set to "Join". The icon
468 * is updated to match with the text and the currently active view.
470 void updateSplitAction();
472 /** Returns the name of the tab for the URL \a url. */
473 QString
tabName(const KUrl
& url
) const;
475 bool isKompareInstalled() const;
477 void createSecondaryView(int tabIndex
);
480 * Helper method for saveProperties() and readProperties(): Returns
481 * the property string for a tab with the index \a tabIndex and
482 * the property \a property.
484 QString
tabProperty(const QString
& property
, int tabIndex
) const;
487 * Sets the window caption to url.fileName() if this is non-empty,
488 * "/" if the URL is "file:///", and url.protocol() otherwise.
490 void setUrlAsCaption(const KUrl
& url
);
492 QString
squeezedText(const QString
& text
) const;
496 * Implements a custom error handling for the undo manager. This
497 * assures that all errors are shown in the status bar of Dolphin
498 * instead as modal error dialog with an OK button.
500 class UndoUiInterface
: public KIO::FileUndoManager::UiInterface
504 virtual ~UndoUiInterface();
505 virtual void jobError(KIO::Job
* job
);
509 KActionMenu
* m_recentTabsMenu
;
510 KAction
* m_showMenuBar
;
512 DolphinViewContainer
* m_activeViewContainer
;
513 QVBoxLayout
* m_centralWidgetLayout
;
514 DolphinSearchBox
* m_searchBox
;
515 DolphinSearchOptionsConfigurator
* m_searchOptionsConfigurator
;
520 ViewTab() : isPrimaryViewActive(true), primaryView(0), secondaryView(0), splitter(0) {}
521 bool isPrimaryViewActive
;
522 DolphinViewContainer
* primaryView
;
523 DolphinViewContainer
* secondaryView
;
528 QList
<ViewTab
> m_viewTab
;
530 DolphinViewActionHandler
* m_actionHandler
;
531 DolphinRemoteEncoding
* m_remoteEncoding
;
532 QPointer
<DolphinSettingsDialog
> m_settingsDialog
;
534 KJob
* m_captionStatJob
;
537 inline DolphinViewContainer
* DolphinMainWindow::activeViewContainer() const
539 return m_activeViewContainer
;
542 inline bool DolphinMainWindow::isSplit() const
544 return m_viewTab
[m_tabIndex
].secondaryView
!= 0;
547 inline KNewMenu
* DolphinMainWindow::newMenu() const
552 inline KAction
* DolphinMainWindow::showMenuBarAction() const
554 return m_showMenuBar
;
557 inline int DolphinMainWindow::getId() const
562 #endif // DOLPHIN_MAINWINDOW_H