]>
cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.h
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-baloo.h>
27 #include <KFileItemDelegate>
28 #include <kio/fileundomanager.h>
29 #include <ksortablelist.h>
30 #include <kxmlguiwindow.h>
34 #include <QWeakPointer>
36 typedef KIO::FileUndoManager::CommandType CommandType
;
38 class DolphinViewActionHandler
;
39 class DolphinApplication
;
40 class DolphinSettingsDialog
;
41 class DolphinViewContainer
;
42 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
;
68 virtual ~DolphinMainWindow();
71 * Returns the currently active view.
72 * All menu actions are applied to this view. When
73 * having a split view setup, the nonactive view
74 * is usually shown in darker colors.
76 DolphinViewContainer
* activeViewContainer() const;
79 * Opens each directory in \p dirs in a separate tab. If the "split view"
80 * option is enabled, 2 directories are collected within one tab.
82 void openDirectories(const QList
<KUrl
>& dirs
);
85 * Opens the directory which contains the files \p files
86 * and selects all files (implements the --select option
89 void openFiles(const QList
<KUrl
>& files
);
92 * Returns true, if the main window contains two instances
93 * of a view container. The active view constainer can be
94 * accessed by DolphinMainWindow::activeViewContainer().
99 * Returns the 'Create New...' sub menu which also can be shared
100 * with other menus (e. g. a context menu).
102 KNewFileMenu
* newFileMenu() const;
106 * Pastes the clipboard data into the currently selected folder
107 * of the active view. If not exactly one folder is selected,
108 * no pasting is done at all.
110 void pasteIntoFolder();
113 * Returns the main window ID used through DBus.
118 * Implementation of the MainWindowAdaptor/QDBusAbstractAdaptor interface.
119 * Inform all affected dolphin components (panels, views) of an URL
122 void changeUrl(const KUrl
& url
);
125 * The current directory of the Terminal Panel has changed, probably because
126 * the user entered a 'cd' command. This slot calls changeUrl(url) and makes
127 * sure that the panel keeps the keyboard focus.
129 void slotTerminalDirectoryChanged(const KUrl
& url
);
131 /** Stores all settings and quits Dolphin. */
136 * Is sent if the selection of the currently active view has
139 void selectionChanged(const KFileItemList
& selection
);
142 * Is sent if the url of the currently active view has
145 void urlChanged(const KUrl
& url
);
148 * Is emitted if information of an item is requested to be shown e. g. in the panel.
149 * If item is null, no item information request is pending.
151 void requestItemInfo(const KFileItem
& item
);
154 * Is emitted if the settings have been changed.
156 void settingsChanged();
159 * Is emitted when a tab has been closed.
161 void rememberClosedTab(const KUrl
& primaryUrl
, const KUrl
& secondaryUrl
);
164 /** @see QWidget::showEvent() */
165 virtual void showEvent(QShowEvent
* event
);
167 /** @see QMainWindow::closeEvent() */
168 virtual void closeEvent(QCloseEvent
* event
);
170 /** @see KMainWindow::saveProperties() */
171 virtual void saveProperties(KConfigGroup
& group
);
173 /** @see KMainWindow::readProperties() */
174 virtual void readProperties(const KConfigGroup
& group
);
178 * Refreshes the views of the main window by recreating them according to
179 * the given Dolphin settings.
183 void clearStatusBar();
185 /** Updates the 'Create New...' sub menu. */
186 void updateNewMenu();
188 void createDirectory();
190 /** Shows the error message in the status bar of the active view. */
191 void showErrorMessage(const QString
& message
);
194 * Updates the state of the 'Undo' menu action dependent
195 * on the parameter \a available.
197 void slotUndoAvailable(bool available
);
199 /** Sets the text of the 'Undo' menu action to \a text. */
200 void slotUndoTextChanged(const QString
& text
);
202 /** Performs the current undo operation. */
206 * Copies all selected items to the clipboard and marks
211 /** Copies all selected items to the clipboard. */
214 /** Pastes the clipboard data to the active view. */
217 /** Replaces the URL navigator by a search box to find files. */
221 * Updates the text of the paste action dependent on
222 * the number of items which are in the clipboard.
224 void updatePasteAction();
226 /** Selects all items from the active view. */
230 * Inverts the selection of all items of the active view:
231 * Selected items get nonselected and nonselected items get
234 void invertSelection();
237 * Switches between one and two views:
238 * If one view is visible, it will get split into two views.
239 * If already two views are visible, the active view gets closed.
241 void toggleSplitView();
243 /** Reloads the currently active view. */
246 /** Stops the loading process for the currently active view. */
249 void enableStopAction();
250 void disableStopAction();
252 void showFilterBar();
255 * Toggles between edit and browse mode of the navigation bar.
257 void toggleEditLocation();
260 * Switches to the edit mode of the navigation bar and selects
261 * the whole URL, so that it can be replaced by the user. If the edit mode is
262 * already active, it is assured that the navigation bar get focused.
264 void replaceLocation();
267 * Toggles the state of the panels between a locked and unlocked layout.
269 void togglePanelLockState();
272 * Is invoked if the Places panel got visible/invisible and takes care
273 * that the places-selector of all views is only shown if the Places panel
276 void slotPlacesPanelVisibilityChanged(bool visible
);
278 /** Goes back one step of the URL history. */
281 /** Goes forward one step of the URL history. */
284 /** Goes up one hierarchy of the current URL. */
287 /** Changes the location to the home URL. */
291 * Open the previous URL in the URL history in a new tab
292 * if the middle mouse button is clicked.
294 void goBack(Qt::MouseButtons buttons
);
297 * Open the next URL in the URL history in a new tab
298 * if the middle mouse button is clicked.
300 void goForward(Qt::MouseButtons buttons
);
303 * Open the URL one hierarchy above the current URL in a new tab
304 * if the middle mouse button is clicked.
306 void goUp(Qt::MouseButtons buttons
);
309 * Open the home URL in a new tab
311 void goHome(Qt::MouseButtons buttons
);
313 /** Opens Kompare for 2 selected files. */
317 * Hides the menu bar if it is visible, makes the menu bar
318 * visible if it is hidden.
320 void toggleShowMenuBar();
322 /** Opens a terminal window for the current location. */
325 /** Opens the settings dialog for Dolphin. */
328 /** Updates the state of the 'Show Full Location' action. */
329 void slotEditableStateChanged(bool editable
);
332 * Updates the state of the 'Edit' menu actions and emits
333 * the signal selectionChanged().
335 void slotSelectionChanged(const KFileItemList
& selection
);
337 /** Emits the signal requestItemInfo(). */
338 void slotRequestItemInfo(const KFileItem
&);
341 * Updates the state of the 'Back' and 'Forward' menu
342 * actions corresponding to the current history.
344 void updateHistory();
346 /** Updates the state of the 'Show filter bar' menu action. */
347 void updateFilterBarAction(bool show
);
349 /** Open a new main window. */
350 void openNewMainWindow();
352 /** Opens a new view with the current URL that is part of a tab. */
356 * Opens a new tab in the background showing the URL \a url.
358 void openNewTab(const KUrl
& url
);
361 * Opens a new tab showing the URL \a url and activates
364 void openNewActivatedTab(const KUrl
& url
);
366 void activateNextTab();
368 void activatePrevTab();
371 * Opens the selected folder in a new tab.
376 * Opens the selected folder in a new window.
378 void openInNewWindow();
380 /** Toggles the active view if two views are shown within the main window. */
381 void toggleActiveView();
384 * Indicates in the statusbar that the execution of the command \a command
387 void showCommand(CommandType command
);
390 * Activates the tab with the index \a index, which means that the current view
391 * is replaced by the view of the given tab.
393 void setActiveTab(int index
);
395 /** Closes the currently active tab. */
399 * Closes the tab with the index \a index and activates the tab with index - 1.
401 void closeTab(int index
);
404 * Opens a context menu for the tab with the index \a index
405 * on the position \a pos.
407 void openTabContextMenu(int index
, const QPoint
& pos
);
410 * Is connected to the QTabBar signal tabMoved(int from, int to).
411 * Reorders the list of tabs after a tab was moved in the tab bar
412 * and sets m_tabIndex to the new index of the current tab.
414 void slotTabMoved(int from
, int to
);
417 * Is connected to the KTabBar signal testCanDecode() and adjusts
418 * the output parameter \a accept.
420 void slotTestCanDecode(const QDragMoveEvent
* event
, bool& accept
);
423 * If the URL can be listed, open it in the current view, otherwise
424 * run it through KRun.
426 void handleUrl(const KUrl
& url
);
429 * handleUrl() can trigger a stat job to see if the url can actually
432 void slotHandleUrlStatFinished(KJob
* job
);
435 * Is connected to the KTabBar signal receivedDropEvent.
436 * Allows dragging and dropping files onto tabs.
438 void tabDropEvent(int tab
, QDropEvent
* event
);
441 * Is invoked when the write state of a folder has been changed and
442 * enables/disables the "Create New..." menu entry.
444 void slotWriteStateChanged(bool isFolderWritable
);
447 * Opens the context menu on the current mouse position.
448 * @pos Position in screen coordinates.
449 * @item File item context. If item is null, the context menu
450 * should be applied to \a url.
451 * @url URL which contains \a item.
452 * @customActions Actions that should be added to the context menu,
453 * if the file item is null.
455 void openContextMenu(const QPoint
& pos
,
456 const KFileItem
& item
,
458 const QList
<QAction
*>& customActions
);
460 void updateControlMenu();
461 void updateToolBar();
462 void slotControlButtonDeleted();
465 * Is called if a panel emits an error-message and shows
466 * the error-message in the active view-container.
468 void slotPanelErrorMessage(const QString
& error
);
471 * Is called if the user clicked an item in the Places Panel.
472 * Reloads the view if \a url is the current URL already, and changes the
473 * current URL otherwise.
475 void slotPlaceActivated(const KUrl
& url
);
478 * Is called when the user wants to reopen a previously closed \a tab from
479 * the recent tabs menu.
481 void restoreClosedTab(const KUrl
& primaryUrl
, const KUrl
& secondaryUrl
);
485 * Activates the given view, which means that
486 * all menu actions are applied to this view. When
487 * having a split view setup, the nonactive view
488 * is usually shown in darker colors.
490 void setActiveViewContainer(DolphinViewContainer
* view
);
493 * Creates a view container and does a default initialization.
495 DolphinViewContainer
* createViewContainer(const KUrl
& url
, QWidget
* parent
);
498 void setupDockWidgets();
499 void updateEditActions();
500 void updateViewActions();
501 void updateGoActions();
503 void createControlButton();
504 void deleteControlButton();
507 * Adds the action \p action to the menu \p menu in
508 * case if it has not added already to the toolbar.
509 * @return True if the action has been added to the menu.
511 bool addActionToMenu(QAction
* action
, KMenu
* menu
);
514 * Connects the signals from the created DolphinView with
515 * the DolphinViewContainer \a container with the corresponding slots of
516 * the DolphinMainWindow. This method must be invoked each
517 * time a DolphinView has been created.
519 void connectViewSignals(DolphinViewContainer
* container
);
522 * Updates the text of the split action:
523 * If two views are shown, the text is set to "Split",
524 * otherwise the text is set to "Join". The icon
525 * is updated to match with the text and the currently active view.
527 void updateSplitAction();
529 /** Returns the name of the tab for the URL \a url. */
530 QString
tabName(const KUrl
& url
) const;
532 bool isKompareInstalled() const;
534 void createSecondaryView(int tabIndex
);
537 * Helper method for saveProperties() and readProperties(): Returns
538 * the property string for a tab with the index \a tabIndex and
539 * the property \a property.
541 QString
tabProperty(const QString
& property
, int tabIndex
) const;
544 * Sets the window caption to url.fileName() if this is non-empty,
545 * "/" if the URL is "file:///", and url.protocol() otherwise.
547 void setUrlAsCaption(const KUrl
& url
);
549 QString
squeezedText(const QString
& text
) const;
552 * Creates an action for showing/hiding a panel, that is accessible
553 * in "Configure toolbars..." and "Configure shortcuts...". This is necessary
554 * as the action for toggling the dock visibility is done by Qt which
555 * is no KAction instance.
557 void createPanelAction(const KIcon
& icon
,
558 const QKeySequence
& shortcut
,
560 const QString
& actionName
);
564 * Implements a custom error handling for the undo manager. This
565 * assures that all errors are shown in the status bar of Dolphin
566 * instead as modal error dialog with an OK button.
568 class UndoUiInterface
: public KIO::FileUndoManager::UiInterface
572 virtual ~UndoUiInterface();
573 virtual void jobError(KIO::Job
* job
);
576 KNewFileMenu
* m_newFileMenu
;
578 DolphinViewContainer
* m_activeViewContainer
;
579 QVBoxLayout
* m_centralWidgetLayout
;
582 // Members for the tab-handling:
585 ViewTab() : isPrimaryViewActive(true), wasActive(false), primaryView(0), secondaryView(0), splitter(0) {}
586 bool isPrimaryViewActive
;
588 DolphinViewContainer
* primaryView
;
589 DolphinViewContainer
* secondaryView
;
593 QList
<ViewTab
> m_viewTab
;
595 DolphinViewActionHandler
* m_actionHandler
;
596 DolphinRemoteEncoding
* m_remoteEncoding
;
597 QWeakPointer
<DolphinSettingsDialog
> m_settingsDialog
;
599 // Members for the toolbar menu that is shown when the menubar is hidden:
600 QToolButton
* m_controlButton
;
601 QTimer
* m_updateToolBarTimer
;
603 KIO::Job
* m_lastHandleUrlStatJob
;
606 inline DolphinViewContainer
* DolphinMainWindow::activeViewContainer() const
608 return m_activeViewContainer
;
611 inline bool DolphinMainWindow::isSplit() const
613 return m_viewTab
[m_tabIndex
].secondaryView
!= 0;
616 inline KNewFileMenu
* DolphinMainWindow::newFileMenu() const
618 return m_newFileMenu
;
621 inline int DolphinMainWindow::getId() const
626 #endif // DOLPHIN_MAINWINDOW_H