]>
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
;
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().
100 * Returns the 'Create New...' sub menu which also can be shared
101 * with other menus (e. g. a context menu).
103 KNewFileMenu
* newFileMenu() const;
107 * Pastes the clipboard data into the currently selected folder
108 * of the active view. If not exactly one folder is selected,
109 * no pasting is done at all.
111 void pasteIntoFolder();
114 * Returns the main window ID used through DBus.
119 * Implementation of the MainWindowAdaptor/QDBusAbstractAdaptor interface.
120 * Inform all affected dolphin components (panels, views) of an URL
123 void changeUrl(const KUrl
& url
);
126 * The current directory of the Terminal Panel has changed, probably because
127 * the user entered a 'cd' command. This slot calls changeUrl(url) and makes
128 * sure that the panel keeps the keyboard focus.
130 void slotTerminalDirectoryChanged(const KUrl
& url
);
132 /** Stores all settings and quits Dolphin. */
137 * Is sent if the selection of the currently active view has
140 void selectionChanged(const KFileItemList
& selection
);
143 * Is sent if the url of the currently active view has
146 void urlChanged(const KUrl
& url
);
149 * Is emitted if information of an item is requested to be shown e. g. in the panel.
150 * If item is null, no item information request is pending.
152 void requestItemInfo(const KFileItem
& item
);
155 * Is emitted if the settings have been changed.
157 void settingsChanged();
160 * Is emitted when a tab has been closed.
162 void rememberClosedTab(const KUrl
& primaryUrl
, const KUrl
& secondaryUrl
);
165 /** @see QWidget::showEvent() */
166 virtual void showEvent(QShowEvent
* event
);
168 /** @see QMainWindow::closeEvent() */
169 virtual void closeEvent(QCloseEvent
* event
);
171 /** @see KMainWindow::saveProperties() */
172 virtual void saveProperties(KConfigGroup
& group
);
174 /** @see KMainWindow::readProperties() */
175 virtual void readProperties(const KConfigGroup
& group
);
179 * Refreshes the views of the main window by recreating them according to
180 * the given Dolphin settings.
184 void clearStatusBar();
186 /** Updates the 'Create New...' sub menu. */
187 void updateNewMenu();
189 void createDirectory();
191 /** Shows the error message in the status bar of the active view. */
192 void showErrorMessage(const QString
& message
);
195 * Updates the state of the 'Undo' menu action dependent
196 * on the parameter \a available.
198 void slotUndoAvailable(bool available
);
200 /** Sets the text of the 'Undo' menu action to \a text. */
201 void slotUndoTextChanged(const QString
& text
);
203 /** Performs the current undo operation. */
207 * Copies all selected items to the clipboard and marks
212 /** Copies all selected items to the clipboard. */
215 /** Pastes the clipboard data to the active view. */
218 /** Replaces the URL navigator by a search box to find files. */
222 * Updates the text of the paste action dependent on
223 * the number of items which are in the clipboard.
225 void updatePasteAction();
227 /** Selects all items from the active view. */
231 * Inverts the selection of all items of the active view:
232 * Selected items get nonselected and nonselected items get
235 void invertSelection();
238 * Switches between one and two views:
239 * If one view is visible, it will get split into two views.
240 * If already two views are visible, the active view gets closed.
242 void toggleSplitView();
244 /** Reloads the currently active view. */
247 /** Stops the loading process for the currently active view. */
250 void enableStopAction();
251 void disableStopAction();
253 void showFilterBar();
256 * Toggles between edit and browse mode of the navigation bar.
258 void toggleEditLocation();
261 * Switches to the edit mode of the navigation bar and selects
262 * the whole URL, so that it can be replaced by the user. If the edit mode is
263 * already active, it is assured that the navigation bar get focused.
265 void replaceLocation();
268 * Toggles the state of the panels between a locked and unlocked layout.
270 void togglePanelLockState();
273 * Is invoked if the Places panel got visible/invisible and takes care
274 * that the places-selector of all views is only shown if the Places panel
277 void slotPlacesPanelVisibilityChanged(bool visible
);
279 /** Goes back one step of the URL history. */
282 /** Goes forward one step of the URL history. */
285 /** Goes up one hierarchy of the current URL. */
288 /** Changes the location to the home URL. */
292 * Open the previous URL in the URL history in a new tab
293 * if the middle mouse button is clicked.
295 void goBack(Qt::MouseButtons buttons
);
298 * Open the next URL in the URL history in a new tab
299 * if the middle mouse button is clicked.
301 void goForward(Qt::MouseButtons buttons
);
304 * Open the URL one hierarchy above the current URL in a new tab
305 * if the middle mouse button is clicked.
307 void goUp(Qt::MouseButtons buttons
);
310 * Open the home URL in a new tab
312 void goHome(Qt::MouseButtons buttons
);
314 /** Opens Kompare for 2 selected files. */
318 * Hides the menu bar if it is visible, makes the menu bar
319 * visible if it is hidden.
321 void toggleShowMenuBar();
323 /** Opens a terminal window for the current location. */
326 /** Opens the settings dialog for Dolphin. */
329 /** Updates the state of the 'Show Full Location' action. */
330 void slotEditableStateChanged(bool editable
);
333 * Updates the state of the 'Edit' menu actions and emits
334 * the signal selectionChanged().
336 void slotSelectionChanged(const KFileItemList
& selection
);
338 /** Emits the signal requestItemInfo(). */
339 void slotRequestItemInfo(const KFileItem
&);
342 * Updates the state of the 'Back' and 'Forward' menu
343 * actions corresponding to the current history.
345 void updateHistory();
347 /** Updates the state of the 'Show filter bar' menu action. */
348 void updateFilterBarAction(bool show
);
350 /** Open a new main window. */
351 void openNewMainWindow();
353 /** Opens a new view with the current URL that is part of a tab. */
357 * Opens a new tab in the background showing the URL \a url.
359 void openNewTab(const KUrl
& url
);
362 * Opens a new tab showing the URL \a url and activates
365 void openNewActivatedTab(const KUrl
& url
);
367 void activateNextTab();
369 void activatePrevTab();
372 * Opens the selected folder in a new tab.
377 * Opens the selected folder in a new window.
379 void openInNewWindow();
381 /** Toggles the active view if two views are shown within the main window. */
382 void toggleActiveView();
385 * Indicates in the statusbar that the execution of the command \a command
388 void showCommand(CommandType command
);
391 * Activates the tab with the index \a index, which means that the current view
392 * is replaced by the view of the given tab.
394 void setActiveTab(int index
);
396 /** Closes the currently active tab. */
400 * Closes the tab with the index \a index and activates the tab with index - 1.
402 void closeTab(int index
);
405 * Opens a context menu for the tab with the index \a index
406 * on the position \a pos.
408 void openTabContextMenu(int index
, const QPoint
& pos
);
411 * Is connected to the QTabBar signal tabMoved(int from, int to).
412 * Reorders the list of tabs after a tab was moved in the tab bar
413 * and sets m_tabIndex to the new index of the current tab.
415 void slotTabMoved(int from
, int to
);
418 * Is connected to the KTabBar signal testCanDecode() and adjusts
419 * the output parameter \a accept.
421 void slotTestCanDecode(const QDragMoveEvent
* event
, bool& accept
);
424 * If the URL can be listed, open it in the current view, otherwise
425 * run it through KRun.
427 void handleUrl(const KUrl
& url
);
430 * handleUrl() can trigger a stat job to see if the url can actually
433 void slotHandleUrlStatFinished(KJob
* job
);
436 * Is connected to the KTabBar signal receivedDropEvent.
437 * Allows dragging and dropping files onto tabs.
439 void tabDropEvent(int tab
, QDropEvent
* event
);
442 * Is invoked when the write state of a folder has been changed and
443 * enables/disables the "Create New..." menu entry.
445 void slotWriteStateChanged(bool isFolderWritable
);
448 * Opens the context menu on the current mouse position.
449 * @pos Position in screen coordinates.
450 * @item File item context. If item is null, the context menu
451 * should be applied to \a url.
452 * @url URL which contains \a item.
453 * @customActions Actions that should be added to the context menu,
454 * if the file item is null.
456 void openContextMenu(const QPoint
& pos
,
457 const KFileItem
& item
,
459 const QList
<QAction
*>& customActions
);
461 void updateControlMenu();
462 void updateToolBar();
463 void slotControlButtonDeleted();
466 * Is called if a panel emits an error-message and shows
467 * the error-message in the active view-container.
469 void slotPanelErrorMessage(const QString
& error
);
472 * Is called if the user clicked an item in the Places Panel.
473 * Reloads the view if \a url is the current URL already, and changes the
474 * current URL otherwise.
476 void slotPlaceActivated(const KUrl
& url
);
479 * Is called when the user wants to reopen a previously closed \a tab from
480 * the recent tabs menu.
482 void restoreClosedTab(const KUrl
& primaryUrl
, const KUrl
& secondaryUrl
);
486 * Activates the given view, which means that
487 * all menu actions are applied to this view. When
488 * having a split view setup, the nonactive view
489 * is usually shown in darker colors.
491 void setActiveViewContainer(DolphinViewContainer
* view
);
494 * Creates a view container and does a default initialization.
496 DolphinViewContainer
* createViewContainer(const KUrl
& url
, QWidget
* parent
);
499 void setupDockWidgets();
500 void updateEditActions();
501 void updateViewActions();
502 void updateGoActions();
504 void createControlButton();
505 void deleteControlButton();
508 * Adds the action \p action to the menu \p menu in
509 * case if it has not added already to the toolbar.
510 * @return True if the action has been added to the menu.
512 bool addActionToMenu(QAction
* action
, KMenu
* menu
);
515 * Connects the signals from the created DolphinView with
516 * the DolphinViewContainer \a container with the corresponding slots of
517 * the DolphinMainWindow. This method must be invoked each
518 * time a DolphinView has been created.
520 void connectViewSignals(DolphinViewContainer
* container
);
523 * Updates the text of the split action:
524 * If two views are shown, the text is set to "Split",
525 * otherwise the text is set to "Join". The icon
526 * is updated to match with the text and the currently active view.
528 void updateSplitAction();
530 /** Returns the name of the tab for the URL \a url. */
531 QString
tabName(const KUrl
& url
) const;
533 bool isKompareInstalled() const;
535 void createSecondaryView(int tabIndex
);
538 * Helper method for saveProperties() and readProperties(): Returns
539 * the property string for a tab with the index \a tabIndex and
540 * the property \a property.
542 QString
tabProperty(const QString
& property
, int tabIndex
) const;
545 * Sets the window caption to url.fileName() if this is non-empty,
546 * "/" if the URL is "file:///", and url.protocol() otherwise.
548 void setUrlAsCaption(const KUrl
& url
);
550 QString
squeezedText(const QString
& text
) const;
553 * Creates an action for showing/hiding a panel, that is accessible
554 * in "Configure toolbars..." and "Configure shortcuts...". This is necessary
555 * as the action for toggling the dock visibility is done by Qt which
556 * is no KAction instance.
558 void createPanelAction(const QIcon
&icon
,
559 const QKeySequence
& shortcut
,
561 const QString
& actionName
);
565 * Implements a custom error handling for the undo manager. This
566 * assures that all errors are shown in the status bar of Dolphin
567 * instead as modal error dialog with an OK button.
569 class UndoUiInterface
: public KIO::FileUndoManager::UiInterface
573 virtual ~UndoUiInterface();
574 virtual void jobError(KIO::Job
* job
);
577 KNewFileMenu
* m_newFileMenu
;
579 DolphinViewContainer
* m_activeViewContainer
;
580 QVBoxLayout
* m_centralWidgetLayout
;
583 // Members for the tab-handling:
586 ViewTab() : isPrimaryViewActive(true), wasActive(false), primaryView(0), secondaryView(0), splitter(0) {}
587 bool isPrimaryViewActive
;
589 DolphinViewContainer
* primaryView
;
590 DolphinViewContainer
* secondaryView
;
594 QList
<ViewTab
> m_viewTab
;
596 DolphinViewActionHandler
* m_actionHandler
;
597 DolphinRemoteEncoding
* m_remoteEncoding
;
598 QWeakPointer
<DolphinSettingsDialog
> m_settingsDialog
;
600 // Members for the toolbar menu that is shown when the menubar is hidden:
601 QToolButton
* m_controlButton
;
602 QTimer
* m_updateToolBarTimer
;
604 KIO::Job
* m_lastHandleUrlStatJob
;
607 inline DolphinViewContainer
* DolphinMainWindow::activeViewContainer() const
609 return m_activeViewContainer
;
612 inline bool DolphinMainWindow::isSplit() const
614 return m_viewTab
[m_tabIndex
].secondaryView
!= 0;
617 inline KNewFileMenu
* DolphinMainWindow::newFileMenu() const
619 return m_newFileMenu
;
622 inline int DolphinMainWindow::getId() const
627 #endif // DOLPHIN_MAINWINDOW_H