]>
cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.h
d76cf0d5c04b3b8f5ed8b8c562dba660d67e8ef4
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 "panels/panel.h"
27 #include <config-nepomuk.h>
29 #include <kfileitemdelegate.h>
30 #include <kio/fileundomanager.h>
31 #include <ksortablelist.h>
32 #include <kxmlguiwindow.h>
33 #include <kactionmenu.h>
35 #include "views/dolphinview.h"
39 typedef KIO::FileUndoManager::CommandType CommandType
;
42 class DolphinViewActionHandler
;
43 class DolphinApplication
;
44 class DolphinSettingsDialog
;
45 class DolphinViewContainer
;
46 class DolphinRemoteEncoding
;
54 * @short Main window for Dolphin.
56 * Handles the menus, toolbars and Dolphin views.
58 class DolphinMainWindow
: public KXmlGuiWindow
61 Q_CLASSINFO("D-Bus Interface", "org.kde.dolphin.MainWindow")
62 Q_PROPERTY(int id READ getId SCRIPTABLE
true)
63 friend class DolphinApplication
;
66 virtual ~DolphinMainWindow();
69 * Returns the currently active view.
70 * All menu actions are applied to this view. When
71 * having a split view setup, the nonactive view
72 * is usually shown in darker colors.
74 DolphinViewContainer
* activeViewContainer() const;
77 * Opens each directory \p in a separate tab. If the "split view"
78 * option is enabled, 2 directories are collected within one tab.
80 void openDirectories(const QList
<KUrl
>& dirs
);
83 * Opens the directory which contains the files \p files
84 * and selects all files (implements the --select option
87 void openFiles(const QList
<KUrl
>& files
);
90 * Returns true, if the main window contains two instances
91 * of a view container. The active view constainer can be
92 * accessed by DolphinMainWindow::activeViewContainer().
97 * If the main window contains two instances of a view container
98 * (DolphinMainWindow::isSplit() returns true), then the
99 * two views get toggled (the right view is on the left, the left
100 * view on the right).
104 /** Renames the item represented by \a oldUrl to \a newUrl. */
105 void rename(const KUrl
& oldUrl
, const KUrl
& newUrl
);
108 * Refreshes the views of the main window by recreating them dependent from
109 * the given Dolphin settings.
114 * Returns the 'Create New...' sub menu which also can be shared
115 * with other menus (e. g. a context menu).
117 KNewFileMenu
* newFileMenu() const;
120 * Returns the 'Show Menubar' action which can be shared with
121 * other menus (e. g. a context menu).
123 KAction
* showMenuBarAction() const;
127 * Pastes the clipboard data into the currently selected folder
128 * of the active view. If not exactly one folder is selected,
129 * no pasting is done at all.
131 void pasteIntoFolder();
134 * Returns the main window ID used through DBus.
139 * Implementation of the MainWindowAdaptor/QDBusAbstractAdaptor interface.
140 * Inform all affected dolphin components (panels, views) of an URL
143 void changeUrl(const KUrl
& url
);
145 /** Stores all settings and quits Dolphin. */
150 * Is sent if the selection of the currently active view has
153 void selectionChanged(const KFileItemList
& selection
);
156 * Is sent if the url of the currently active view has
159 void urlChanged(const KUrl
& url
);
162 * Is emitted if information of an item is requested to be shown e. g. in the panel.
163 * If item is null, no item information request is pending.
165 void requestItemInfo(const KFileItem
& item
);
168 /** @see QWidget::showEvent() */
169 virtual void showEvent(QShowEvent
* event
);
171 /** @see QMainWindow::closeEvent() */
172 virtual void closeEvent(QCloseEvent
* event
);
174 /** @see KMainWindow::saveProperties() */
175 virtual void saveProperties(KConfigGroup
& group
);
177 /** @see KMainWindow::readProperties() */
178 virtual void readProperties(const KConfigGroup
& group
);
181 void clearStatusBar();
183 /** Updates the 'Create New...' sub menu. */
184 void updateNewMenu();
186 void createDirectory();
188 /** Shows the error message in the status bar of the active view. */
189 void showErrorMessage(const QString
& message
);
192 * Updates the state of the 'Undo' menu action dependent
193 * from the parameter \a available.
195 void slotUndoAvailable(bool available
);
197 /** Invoked when an action in the recent tabs menu is clicked. */
198 void restoreClosedTab(QAction
* action
);
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 from
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 nonactivated view gets closed.
242 void toggleSplitView();
244 /** Reloads the current active view. */
247 /** Stops the loading process for the current active view. */
251 * Toggles between showing and hiding of the filter bar
253 void toggleFilterBarVisibility(bool show
);
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();
267 /** Goes back on step of the URL history. */
270 /** Goes forward one step of the URL history. */
273 /** Goes up one hierarchy of the current URL. */
277 * Open the previous URL in the URL history in a new tab
278 * if the middle mouse button is clicked.
280 void goBack(Qt::MouseButtons buttons
);
283 * Open the next URL in the URL history in a new tab
284 * if the middle mouse button is clicked.
286 void goForward(Qt::MouseButtons buttons
);
289 * Open the URL one hierarchy above the current URL in a new tab
290 * if the middle mouse button is clicked.
292 void goUp(Qt::MouseButtons buttons
);
294 /** Goes to the home URL. */
297 /** Opens Kompare for 2 selected files. */
301 * Hides the menu bar if it is visible, makes the menu bar
302 * visible if it is hidden.
304 void toggleShowMenuBar();
306 /** Opens a terminal window for the current location. */
309 /** Opens the settings dialog for Dolphin. */
312 /** Updates the state of the 'Show Full Location' action. */
313 void slotEditableStateChanged(bool editable
);
316 * Updates the state of the 'Edit' menu actions and emits
317 * the signal selectionChanged().
319 void slotSelectionChanged(const KFileItemList
& selection
);
321 /** Emits the signal requestItemInfo(). */
322 void slotRequestItemInfo(const KFileItem
&);
325 * Updates the state of the 'Back' and 'Forward' menu
326 * actions corresponding to the current history.
328 void updateHistory();
330 /** Updates the state of the 'Show filter bar' menu action. */
331 void updateFilterBarAction(bool show
);
333 /** Open a new main window. */
334 void openNewMainWindow();
336 /** Opens a new view with the current URL that is part of a tab. */
340 * Opens a new tab showing the URL \a url.
342 void openNewTab(const KUrl
& url
);
344 void activateNextTab();
346 void activatePrevTab();
349 * Opens the selected folder in a new tab.
354 * Opens the selected folder in a new window.
356 void openInNewWindow();
358 /** Toggles the active view if two views are shown within the main window. */
359 void toggleActiveView();
362 * Indicates in the statusbar that the execution of the command \a command
365 void showCommand(CommandType command
);
368 * Activates the tab with the index \a index, which means that the current view
369 * is replaced by the view of the given tab.
371 void setActiveTab(int index
);
373 /** Closes the currently active tab. */
377 * Closes the tab with the index \index and activates the tab with index - 1.
379 void closeTab(int index
);
382 * Opens a context menu for the tab with the index \a index
383 * on the position \a pos.
385 void openTabContextMenu(int index
, const QPoint
& pos
);
388 * Is connected to the QTabBar signal tabMoved(int from, int to).
389 * Reorders the list of tabs after a tab was moved in the tab bar
390 * and sets m_tabIndex to the new index of the current tab.
392 void slotTabMoved(int from
, int to
);
395 * Handles a click on a places item: if the middle mouse button is
396 * clicked, a new tab is opened for \a url, otherwise the current
397 * view is replaced by \a url.
399 void handlePlacesClick(const KUrl
& url
, Qt::MouseButtons buttons
);
402 * Is connected to the KTabBar signal testCanDecode() and adjusts
403 * the output parameter \a accept.
405 void slotTestCanDecode(const QDragMoveEvent
* event
, bool& accept
);
408 * If the URL can be listed open it in the current view, otherwise
409 * run it through KRun.
411 void handleUrl(const KUrl
& url
);
414 * handleUrl() can trigger a stat job to see if the url can actually
417 void slotHandleUrlStatFinished(KJob
* job
);
420 * Is connected to the KTabBar signal receivedDropEvent.
421 * Allows dragging and dropping files onto tabs.
423 void tabDropEvent(int tab
, QDropEvent
* event
);
426 * Is invoked when the write state of a folder has been changed and
427 * enables/disables the "Create New..." menu entry.
429 void slotWriteStateChanged(bool isFolderWritable
);
432 * Opens the context menu on the current mouse position.
433 * @item File item context. If item is null, the context menu
434 * should be applied to \a url.
435 * @url URL which contains \a item.
436 * @customActions Actions that should be added to the context menu,
437 * if the file item is null.
439 void openContextMenu(const KFileItem
& item
,
441 const QList
<QAction
*>& customActions
);
444 DolphinMainWindow(int id
);
448 * Activates the given view, which means that
449 * all menu actions are applied to this view. When
450 * having a split view setup, the nonactive view
451 * is usually shown in darker colors.
453 void setActiveViewContainer(DolphinViewContainer
* view
);
456 void setupDockWidgets();
457 void updateEditActions();
458 void updateViewActions();
459 void updateGoActions();
462 * Adds the tab[\a index] to the closed tab menu's list of actions.
464 void rememberClosedTab(int index
);
467 * Connects the signals from the created DolphinView with
468 * the DolphinViewContainer \a container with the corresponding slots of
469 * the DolphinMainWindow. This method must be invoked each
470 * time a DolphinView has been created.
472 void connectViewSignals(DolphinViewContainer
* container
);
475 * Updates the text of the split action:
476 * If two views are shown, the text is set to "Split",
477 * otherwise the text is set to "Join". The icon
478 * is updated to match with the text and the currently active view.
480 void updateSplitAction();
482 /** Returns the name of the tab for the URL \a url. */
483 QString
tabName(const KUrl
& url
) const;
485 bool isKompareInstalled() const;
487 void createSecondaryView(int tabIndex
);
490 * Helper method for saveProperties() and readProperties(): Returns
491 * the property string for a tab with the index \a tabIndex and
492 * the property \a property.
494 QString
tabProperty(const QString
& property
, int tabIndex
) const;
497 * Sets the window caption to url.fileName() if this is non-empty,
498 * "/" if the URL is "file:///", and url.protocol() otherwise.
500 void setUrlAsCaption(const KUrl
& url
);
502 QString
squeezedText(const QString
& text
) const;
506 * Implements a custom error handling for the undo manager. This
507 * assures that all errors are shown in the status bar of Dolphin
508 * instead as modal error dialog with an OK button.
510 class UndoUiInterface
: public KIO::FileUndoManager::UiInterface
514 virtual ~UndoUiInterface();
515 virtual void jobError(KIO::Job
* job
);
518 KNewFileMenu
* m_newFileMenu
;
519 KActionMenu
* m_recentTabsMenu
;
520 KAction
* m_showMenuBar
;
522 DolphinViewContainer
* m_activeViewContainer
;
523 QVBoxLayout
* m_centralWidgetLayout
;
528 ViewTab() : isPrimaryViewActive(true), primaryView(0), secondaryView(0), splitter(0) {}
529 bool isPrimaryViewActive
;
530 DolphinViewContainer
* primaryView
;
531 DolphinViewContainer
* secondaryView
;
536 QList
<ViewTab
> m_viewTab
;
538 DolphinViewActionHandler
* m_actionHandler
;
539 DolphinRemoteEncoding
* m_remoteEncoding
;
540 QPointer
<DolphinSettingsDialog
> m_settingsDialog
;
542 KJob
* m_lastHandleUrlStatJob
;
545 inline DolphinViewContainer
* DolphinMainWindow::activeViewContainer() const
547 return m_activeViewContainer
;
550 inline bool DolphinMainWindow::isSplit() const
552 return m_viewTab
[m_tabIndex
].secondaryView
!= 0;
555 inline KNewFileMenu
* DolphinMainWindow::newFileMenu() const
557 return m_newFileMenu
;
560 inline KAction
* DolphinMainWindow::showMenuBarAction() const
562 return m_showMenuBar
;
565 inline int DolphinMainWindow::getId() const
570 #endif // DOLPHIN_MAINWINDOW_H