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>
35 #include <QWeakPointer>
37 typedef KIO::FileUndoManager::CommandType CommandType
;
39 class DolphinViewActionHandler
;
40 class DolphinApplication
;
41 class DolphinSettingsDialog
;
42 class DolphinViewContainer
;
43 class DolphinRemoteEncoding
;
56 * @short Main window for Dolphin.
58 * Handles the menus, toolbars and Dolphin views.
60 class DolphinMainWindow
: public KXmlGuiWindow
63 Q_CLASSINFO("D-Bus Interface", "org.kde.dolphin.MainWindow")
64 Q_PROPERTY(int id READ getId SCRIPTABLE
true)
65 friend class DolphinApplication
;
69 virtual ~DolphinMainWindow();
72 * Returns the currently active view.
73 * All menu actions are applied to this view. When
74 * having a split view setup, the nonactive view
75 * is usually shown in darker colors.
77 DolphinViewContainer
* activeViewContainer() const;
80 * Opens each directory in \p dirs in a separate tab. If the "split view"
81 * option is enabled, 2 directories are collected within one tab.
83 void openDirectories(const QList
<KUrl
>& dirs
);
86 * Opens the directory which contains the files \p files
87 * and selects all files (implements the --select option
90 void openFiles(const QList
<KUrl
>& files
);
93 * Returns true, if the main window contains two instances
94 * of a view container. The active view constainer can be
95 * accessed by DolphinMainWindow::activeViewContainer().
99 /** Renames the item represented by \a oldUrl to \a newUrl. */
100 void rename(const KUrl
& oldUrl
, const KUrl
& newUrl
);
103 * Returns the 'Create New...' sub menu which also can be shared
104 * with other menus (e. g. a context menu).
106 KNewFileMenu
* newFileMenu() const;
110 * Pastes the clipboard data into the currently selected folder
111 * of the active view. If not exactly one folder is selected,
112 * no pasting is done at all.
114 void pasteIntoFolder();
117 * Returns the main window ID used through DBus.
122 * Implementation of the MainWindowAdaptor/QDBusAbstractAdaptor interface.
123 * Inform all affected dolphin components (panels, views) of an URL
126 void changeUrl(const KUrl
& url
);
128 /** Stores all settings and quits Dolphin. */
133 * Is sent if the selection of the currently active view has
136 void selectionChanged(const KFileItemList
& selection
);
139 * Is sent if the url of the currently active view has
142 void urlChanged(const KUrl
& url
);
145 * Is emitted if information of an item is requested to be shown e. g. in the panel.
146 * If item is null, no item information request is pending.
148 void requestItemInfo(const KFileItem
& item
);
151 /** @see QWidget::showEvent() */
152 virtual void showEvent(QShowEvent
* event
);
154 /** @see QMainWindow::closeEvent() */
155 virtual void closeEvent(QCloseEvent
* event
);
157 /** @see KMainWindow::saveProperties() */
158 virtual void saveProperties(KConfigGroup
& group
);
160 /** @see KMainWindow::readProperties() */
161 virtual void readProperties(const KConfigGroup
& group
);
165 * Refreshes the views of the main window by recreating them according to
166 * the given Dolphin settings.
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 * on 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. */
207 /** Replaces the URL navigator by a search box to find files. */
211 * Is invoked when the "Find" is active and the search location
212 * (From Here/Everywhere) has been changed. Updates the
213 * enabled state of the Search Panel.
215 void slotSearchLocationChanged();
218 * Updates the text of the paste action dependent on
219 * the number of items which are in the clipboard.
221 void updatePasteAction();
223 /** Selects all items from the active view. */
227 * Inverts the selection of all items of the active view:
228 * Selected items get nonselected and nonselected items get
231 void invertSelection();
234 * Switches between one and two views:
235 * If one view is visible, it will get split into two views.
236 * If already two views are visible, the active view gets closed.
238 void toggleSplitView();
240 /** Reloads the currently active view. */
243 /** Stops the loading process for the currently active view. */
246 void enableStopAction();
247 void disableStopAction();
249 void showFilterBar();
252 * Toggles between edit and browse mode of the navigation bar.
254 void toggleEditLocation();
257 * Switches to the edit mode of the navigation bar and selects
258 * the whole URL, so that it can be replaced by the user. If the edit mode is
259 * already active, it is assured that the navigation bar get focused.
261 void replaceLocation();
264 * Toggles the state of the panels between a locked and unlocked layout.
266 void togglePanelLockState();
269 * Is invoked if the Places panel got visible/invisible and takes care
270 * that the places-selector of all views is only shown if the Places panel
273 void slotPlacesPanelVisibilityChanged(bool visible
);
275 /** Goes back one step of the URL history. */
278 /** Goes forward one step of the URL history. */
281 /** Goes up one hierarchy of the current URL. */
284 /** Changes the location to the home URL. */
288 * Open the previous URL in the URL history in a new tab
289 * if the middle mouse button is clicked.
291 void goBack(Qt::MouseButtons buttons
);
294 * Open the next URL in the URL history in a new tab
295 * if the middle mouse button is clicked.
297 void goForward(Qt::MouseButtons buttons
);
300 * Open the URL one hierarchy above the current URL in a new tab
301 * if the middle mouse button is clicked.
303 void goUp(Qt::MouseButtons buttons
);
306 * Open the home URL in a new tab
308 void goHome(Qt::MouseButtons buttons
);
310 /** Opens Kompare for 2 selected files. */
314 * Hides the menu bar if it is visible, makes the menu bar
315 * visible if it is hidden.
317 void toggleShowMenuBar();
319 /** Opens a terminal window for the current location. */
322 /** Opens the settings dialog for Dolphin. */
325 /** Updates the state of the 'Show Full Location' action. */
326 void slotEditableStateChanged(bool editable
);
329 * Updates the state of the 'Edit' menu actions and emits
330 * the signal selectionChanged().
332 void slotSelectionChanged(const KFileItemList
& selection
);
334 /** Emits the signal requestItemInfo(). */
335 void slotRequestItemInfo(const KFileItem
&);
338 * Updates the state of the 'Back' and 'Forward' menu
339 * actions corresponding to the current history.
341 void updateHistory();
343 /** Updates the state of the 'Show filter bar' menu action. */
344 void updateFilterBarAction(bool show
);
346 /** Open a new main window. */
347 void openNewMainWindow();
349 /** Opens a new view with the current URL that is part of a tab. */
353 * Opens a new tab in the background showing the URL \a url.
355 void openNewTab(const KUrl
& url
);
358 * Opens a new tab showing the URL \a url and activates
361 void openNewActivatedTab(const KUrl
& url
);
363 void activateNextTab();
365 void activatePrevTab();
368 * Opens the selected folder in a new tab.
373 * Opens the selected folder in a new window.
375 void openInNewWindow();
377 /** Toggles the active view if two views are shown within the main window. */
378 void toggleActiveView();
381 * Indicates in the statusbar that the execution of the command \a command
384 void showCommand(CommandType command
);
387 * Activates the tab with the index \a index, which means that the current view
388 * is replaced by the view of the given tab.
390 void setActiveTab(int index
);
392 /** Closes the currently active tab. */
396 * Closes the tab with the index \a index and activates the tab with index - 1.
398 void closeTab(int index
);
401 * Opens a context menu for the tab with the index \a index
402 * on the position \a pos.
404 void openTabContextMenu(int index
, const QPoint
& pos
);
407 * Is connected to the QTabBar signal tabMoved(int from, int to).
408 * Reorders the list of tabs after a tab was moved in the tab bar
409 * and sets m_tabIndex to the new index of the current tab.
411 void slotTabMoved(int from
, int to
);
414 * Is connected to the KTabBar signal testCanDecode() and adjusts
415 * the output parameter \a accept.
417 void slotTestCanDecode(const QDragMoveEvent
* event
, bool& accept
);
420 * If the URL can be listed, open it in the current view, otherwise
421 * run it through KRun.
423 void handleUrl(const KUrl
& url
);
426 * handleUrl() can trigger a stat job to see if the url can actually
429 void slotHandleUrlStatFinished(KJob
* job
);
432 * Is connected to the KTabBar signal receivedDropEvent.
433 * Allows dragging and dropping files onto tabs.
435 void tabDropEvent(int tab
, QDropEvent
* event
);
438 * Is invoked when the write state of a folder has been changed and
439 * enables/disables the "Create New..." menu entry.
441 void slotWriteStateChanged(bool isFolderWritable
);
443 void slotSearchModeChanged(bool enabled
);
446 * Opens the context menu on the current mouse position.
447 * @pos Position in screen coordinates.
448 * @item File item context. If item is null, the context menu
449 * should be applied to \a url.
450 * @url URL which contains \a item.
451 * @customActions Actions that should be added to the context menu,
452 * if the file item is null.
454 void openContextMenu(const QPoint
& pos
,
455 const KFileItem
& item
,
457 const QList
<QAction
*>& customActions
);
459 void updateControlMenu();
460 void updateToolBar();
461 void slotControlButtonDeleted();
465 * Activates the given view, which means that
466 * all menu actions are applied to this view. When
467 * having a split view setup, the nonactive view
468 * is usually shown in darker colors.
470 void setActiveViewContainer(DolphinViewContainer
* view
);
473 * Creates a view container and does a default initialization.
475 DolphinViewContainer
* createViewContainer(const KUrl
& url
, QWidget
* parent
);
478 void setupDockWidgets();
479 void updateEditActions();
480 void updateViewActions();
481 void updateGoActions();
483 void createControlButton();
484 void deleteControlButton();
487 * Adds the action \p action to the menu \p menu in
488 * case if it has not added already to the toolbar.
489 * @return True if the action has been added to the menu.
491 bool addActionToMenu(QAction
* action
, KMenu
* menu
);
494 * Adds the tab[\a index] to the closed tab menu's list of actions.
496 void rememberClosedTab(int index
);
499 * Connects the signals from the created DolphinView with
500 * the DolphinViewContainer \a container with the corresponding slots of
501 * the DolphinMainWindow. This method must be invoked each
502 * time a DolphinView has been created.
504 void connectViewSignals(DolphinViewContainer
* container
);
507 * Updates the text of the split action:
508 * If two views are shown, the text is set to "Split",
509 * otherwise the text is set to "Join". The icon
510 * is updated to match with the text and the currently active view.
512 void updateSplitAction();
514 /** Returns the name of the tab for the URL \a url. */
515 QString
tabName(const KUrl
& url
) const;
517 bool isKompareInstalled() const;
519 void createSecondaryView(int tabIndex
);
522 * Helper method for saveProperties() and readProperties(): Returns
523 * the property string for a tab with the index \a tabIndex and
524 * the property \a property.
526 QString
tabProperty(const QString
& property
, int tabIndex
) const;
529 * Sets the window caption to url.fileName() if this is non-empty,
530 * "/" if the URL is "file:///", and url.protocol() otherwise.
532 void setUrlAsCaption(const KUrl
& url
);
534 QString
squeezedText(const QString
& text
) const;
537 * Creates an action for showing/hiding a panel, that is accessible
538 * in "Configure toolbars..." and "Configure shortcuts...". This is necessary
539 * as the action for toggling the dock visibility is done by Qt which
540 * is no KAction instance.
542 void createPanelAction(const KIcon
& icon
,
543 const QKeySequence
& shortcut
,
545 const QString
& actionName
);
549 * Implements a custom error handling for the undo manager. This
550 * assures that all errors are shown in the status bar of Dolphin
551 * instead as modal error dialog with an OK button.
553 class UndoUiInterface
: public KIO::FileUndoManager::UiInterface
557 virtual ~UndoUiInterface();
558 virtual void jobError(KIO::Job
* job
);
561 KNewFileMenu
* m_newFileMenu
;
562 KActionMenu
* m_recentTabsMenu
;
564 DolphinViewContainer
* m_activeViewContainer
;
565 QVBoxLayout
* m_centralWidgetLayout
;
568 // Members for the tab-handling:
571 ViewTab() : isPrimaryViewActive(true), wasActive(false), primaryView(0), secondaryView(0), splitter(0) {}
572 bool isPrimaryViewActive
;
574 DolphinViewContainer
* primaryView
;
575 DolphinViewContainer
* secondaryView
;
579 QList
<ViewTab
> m_viewTab
;
581 DolphinViewActionHandler
* m_actionHandler
;
582 DolphinRemoteEncoding
* m_remoteEncoding
;
583 QWeakPointer
<DolphinSettingsDialog
> m_settingsDialog
;
585 // Members for the toolbar menu that is shown when the menubar is hidden:
586 QToolButton
* m_controlButton
;
587 QTimer
* m_updateToolBarTimer
;
589 KIO::Job
* m_lastHandleUrlStatJob
;
592 * Set to true, if the filter dock visibility is only temporary set
593 * to true by enabling the search mode.
595 bool m_searchDockIsTemporaryVisible
;
598 inline DolphinViewContainer
* DolphinMainWindow::activeViewContainer() const
600 return m_activeViewContainer
;
603 inline bool DolphinMainWindow::isSplit() const
605 return m_viewTab
[m_tabIndex
].secondaryView
!= 0;
608 inline KNewFileMenu
* DolphinMainWindow::newFileMenu() const
610 return m_newFileMenu
;
613 inline int DolphinMainWindow::getId() const
618 #endif // DOLPHIN_MAINWINDOW_H