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 "sidebarpage.h"
28 #include <config-nepomuk.h>
30 #include <kxmlguiwindow.h>
31 #include <ksortablelist.h>
32 #include <konq_undo.h>
34 #include <QtCore/QList>
36 class DolphinApplication
;
37 class DolphinViewContainer
;
43 * @short Main window for Dolphin.
45 * Handles the menus, toolbars and Dolphin views.
47 class DolphinMainWindow
: public KXmlGuiWindow
50 Q_CLASSINFO("D-Bus Interface", "org.kde.dolphin.MainWindow")
51 Q_PROPERTY(int id READ getId SCRIPTABLE
true)
52 friend class DolphinApplication
;
55 virtual ~DolphinMainWindow();
58 * Returns the currently active view.
59 * All menu actions are applied to this view. When
60 * having a split view setup, the nonactive view
61 * is usually shown in darker colors.
63 inline DolphinViewContainer
* activeViewContainer() const;
66 * Returns true, if the main window contains two instances
67 * of a view container. The active view constainer can be
68 * accessed by DolphinMainWindow::activeViewContainer().
70 inline bool isSplit() const;
73 * If the main window contains two instances of a view container
74 * (DolphinMainWindow::isSplit() returns true), then the
75 * two views get toggled (the right view is on the left, the left
80 /** Renames the item represented by \a oldUrl to \a newUrl. */
81 void rename(const KUrl
& oldUrl
, const KUrl
& newUrl
);
84 * Refreshs the views of the main window by recreating them dependent from
85 * the given Dolphin settings.
90 * Returns the 'Create New...' sub menu which also can be shared
91 * with other menus (e. g. a context menu).
93 inline KNewMenu
* newMenu() const;
97 * Handles the dropping of URLs to the given
98 * destination. A context menu with the options
99 * 'Move Here', 'Copy Here', 'Link Here' and
100 * 'Cancel' is offered to the user.
101 * @param urls List of URLs which have been
103 * @param destination Destination URL, where the
104 * list or URLs should be moved,
105 * copied or linked to.
107 void dropUrls(const KUrl::List
& urls
,
108 const KUrl
& destination
);
111 * Returns the main window ID used through DBus.
113 inline int getId() const;
116 * Inform all affected dolphin components (sidebars, views) of an URL
119 void changeUrl(const KUrl
& url
);
122 * Inform all affected dolphin components that a selection change is
125 void changeSelection(const QList
<KFileItem
>& selection
);
127 /** Stores all settings and quits Dolphin. */
132 * Is send if the active view has been changed in
133 * the split view mode.
135 void activeViewChanged();
138 * Is sent if the selection of the currently active view has
141 void selectionChanged(const QList
<KFileItem
>& selection
);
144 * Is sent if the url of the currently active view has
147 void urlChanged(const KUrl
& url
);
150 * Is emitted if information of an item is requested to be shown e. g. in the sidebar.
151 * If item is null, no item information request is pending.
153 void requestItemInfo(const KFileItem
& item
);
156 /** @see QMainWindow::closeEvent */
157 virtual void closeEvent(QCloseEvent
* event
);
160 * This method is called when it is time for the app to save its
161 * properties for session management purposes.
163 void saveProperties(KConfig
*);
166 * This method is called when this app is restored. The KConfig
167 * object points to the session management config file that was saved
168 * with @ref saveProperties
170 void readProperties(KConfig
*);
173 /** Updates the 'Create New...' sub menu. */
174 void updateNewMenu();
177 * Let the user input a name for the selected item(s) and trigger
178 * a renaming afterwards.
182 /** Moves the selected items of the active view to the trash. */
185 /** Deletes the selected items of the active view. */
189 * Opens the properties window for the selected items of the
190 * active view. The properties windows shows information
191 * like name, size and permissions.
196 * Shows the error information from the places model
199 void slotHandlePlacesError(const QString
&message
);
202 * Shows the error information of the job \a job
205 void slotHandleJobError(KJob
* job
);
208 * Indicates in the status bar that the delete operation
209 * of the job \a job has been finished.
211 void slotDeleteFileFinished(KJob
* job
);
214 * Updates the state of the 'Undo' menu action dependent
215 * from the parameter \a available.
217 void slotUndoAvailable(bool available
);
219 /** Sets the text of the 'Undo' menu action to \a text. */
220 void slotUndoTextChanged(const QString
& text
);
222 /** Performs the current undo operation. */
226 * Copies all selected items to the clipboard and marks
227 * the items as cutted.
231 /** Copies all selected items to the clipboard. */
234 /** Pastes the clipboard data to the active view. */
238 * Updates the text of the paste action dependent from
239 * the number of items which are in the clipboard.
241 void updatePasteAction();
243 /** Selects all items from the active view. */
247 * Inverts the selection of all items of the active view:
248 * Selected items get nonselected and nonselected items get
251 void invertSelection();
253 /** The current active view is switched to the icons mode. */
256 /** The current active view is switched to the details mode. */
257 void setDetailsView();
259 /** The current active view is switched to the column mode. */
260 void setColumnView();
262 /** The sorting of the current view should be done by the name. */
265 /** The sorting of the current view should be done by the size. */
268 /** The sorting of the current view should be done by the date. */
271 /** The sorting of the current view should be done by the permissions. */
272 void sortByPermissions();
274 /** The sorting of the current view should be done by the owner. */
277 /** The sorting of the current view should be done by the group. */
280 /** The sorting of the current view should be done by the type. */
283 /** The sorting of the current view should be done by the rating. */
286 /** The sorting of the current view should be done by tags. */
289 /** Switches between an ascending and descending sorting order. */
290 void toggleSortOrder();
292 /** Switches between sorting by categories or not. */
293 void toggleSortCategorization();
296 * Clears any additional information for an item except for the
301 /** Shows the MIME type as additional information for the item. */
304 /** Shows the size as additional information for the item. */
307 /** Shows the date as additional information for the item. */
311 * Switches between one and two views:
312 * If one view is visible, it will get split into two views.
313 * If already two views are visible, the nonactivated view gets closed.
315 void toggleSplitView();
317 /** Reloads the current active view. */
320 /** Stops the loading process for the current active view. */
323 /** Switches between showing a preview of the file content and showing the icon. */
324 void togglePreview();
327 * Switches between showing and hiding of hidden marked files dependent
328 * from the current state of the 'Show Hidden Files' menu toggle action.
330 void toggleShowHiddenFiles();
333 * Toggles between showing and hiding of the filter bar dependent
334 * from the current state of the 'Show Filter Bar' menu toggle action.
336 void toggleFilterBarVisibility();
338 /** Increases the size of the current set view mode. */
341 /** Decreases the size of the current set view mode. */
345 * Toggles between edit and brose mode of the navigation bar.
347 void toggleEditLocation();
350 * Switches to the edit mode of the navigation bar. If the edit mode is
351 * already active, it is assured that the navigation bar get focused.
356 * Opens the view properties dialog, which allows to modify the properties
357 * of the currently active view.
359 void adjustViewProperties();
361 /** Goes back on step of the URL history. */
364 /** Goes forward one step of the URL history. */
367 /** Goes up one hierarchy of the current URL. */
370 /** Goes to the home URL. */
373 /** Opens KFind for the current shown directory. */
376 /** Opens Kompare for 2 selected files. */
379 /** Opens the settings dialog for Dolphin. */
382 /** Updates the state of all 'View' menu actions. */
383 void slotViewModeChanged();
385 /** Updates the state of the 'Show preview' menu action. */
386 void slotShowPreviewChanged();
388 /** Updates the state of the 'Show hidden files' menu action. */
389 void slotShowHiddenFilesChanged();
391 /** Updates the state of the 'Categorized sorting' menu action. */
392 void slotCategorizedSortingChanged();
394 /** Updates the state of the 'Sort by' actions. */
395 void slotSortingChanged(DolphinView::Sorting sorting
);
397 /** Updates the state of the 'Sort Ascending/Descending' action. */
398 void slotSortOrderChanged(Qt::SortOrder order
);
400 /** Updates the state of the 'Additional Information' actions. */
401 void slotAdditionalInfoChanged(KFileItemDelegate::AdditionalInformation info
);
404 * Updates the state of the 'Edit' menu actions and emits
405 * the signal selectionChanged().
407 void slotSelectionChanged(const QList
<KFileItem
>& selection
);
409 /** Emits the signal requestItemInfo(). */
410 void slotRequestItemInfo(const KFileItem
&);
413 * Updates the state of the 'Back' and 'Forward' menu
414 * actions corresponding the the current history.
416 void slotHistoryChanged();
418 /** Updates the state of the 'Show filter bar' menu action. */
419 void updateFilterBarAction(bool show
);
421 /** Open a new main window. */
422 void openNewMainWindow();
424 /** Toggles the active view if two views are shown within the main window. */
425 void toggleActiveView();
428 DolphinMainWindow(int id
);
432 * Activates the given view, which means that
433 * all menu actions are applied to this view. When
434 * having a split view setup, the nonactive view
435 * is usually shown in darker colors.
437 void setActiveViewContainer(DolphinViewContainer
* view
);
440 void setupDockWidgets();
441 void updateHistory();
442 void updateEditActions();
443 void updateViewActions();
444 void updateGoActions();
445 void copyUrls(const KUrl::List
& source
, const KUrl
& dest
);
446 void moveUrls(const KUrl::List
& source
, const KUrl
& dest
);
447 void linkUrls(const KUrl::List
& source
, const KUrl
& dest
);
448 void clearStatusBar();
451 * Connects the signals from the created DolphinView with
452 * the index \a viewIndex with the corresponding slots of
453 * the DolphinMainWindow. This method must be invoked each
454 * time a DolphinView has been created.
456 void connectViewSignals(int viewIndex
);
459 * Updates the text of the split action:
460 * If two views are shown, the text is set to "Split",
461 * otherwise the text is set to "Join". The icon
462 * is updated to match with the text and the currently active view.
464 void updateSplitAction();
468 * DolphinMainWindow supports up to two views beside each other.
472 PrimaryView
= 0, ///< View shown on the left side of the main window.
473 SecondaryView
= 1 ///< View shown on the left side of the main window.
477 * Implements a custom error handling for the undo manager. This
478 * assures that all errors are shown in the status bar of Dolphin
479 * instead as modal error dialog with an OK button.
481 class UndoUiInterface
: public KonqUndoManager::UiInterface
484 UndoUiInterface(DolphinMainWindow
* mainWin
);
485 virtual ~UndoUiInterface();
486 virtual void jobError(KIO::Job
* job
);
489 DolphinMainWindow
* m_mainWin
;
493 QSplitter
* m_splitter
;
494 DolphinViewContainer
* m_activeViewContainer
;
497 DolphinViewContainer
* m_viewContainer
[SecondaryView
+ 1];
499 /// remember pending undo operations until they are finished
500 QList
<KonqUndoManager::CommandType
> m_undoCommandTypes
;
503 DolphinViewContainer
* DolphinMainWindow::activeViewContainer() const
505 return m_activeViewContainer
;
508 bool DolphinMainWindow::isSplit() const
510 return m_viewContainer
[SecondaryView
] != 0;
513 KNewMenu
* DolphinMainWindow::newMenu() const
518 int DolphinMainWindow::getId() const
523 #endif // DOLPHIN_MAINWINDOW_H