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 <kxmlguiwindow.h>
29 #include <ksortablelist.h>
30 #include <konq_undo.h>
32 #include <QtCore/QList>
34 class DolphinApplication
;
35 class DolphinViewContainer
;
41 * @short Main window for Dolphin.
43 * Handles the menus, toolbars and Dolphin views.
45 class DolphinMainWindow
: public KXmlGuiWindow
48 Q_CLASSINFO("D-Bus Interface", "org.kde.dolphin.MainWindow")
49 Q_PROPERTY(int id READ getId SCRIPTABLE
true)
50 friend class DolphinApplication
;
53 virtual ~DolphinMainWindow();
56 * Returns the currently active view.
57 * All menu actions are applied to this view. When
58 * having a split view setup, the nonactive view
59 * is usually shown in darker colors.
61 inline DolphinViewContainer
* activeViewContainer() const;
64 * Returns true, if the main window contains two instances
65 * of a view container. The active view constainer can be
66 * accessed by DolphinMainWindow::activeViewContainer().
68 inline bool isSplit() const;
71 * If the main window contains two instances of a view container
72 * (DolphinMainWindow::isSplit() returns true), then the
73 * two views get toggled (the right view is on the left, the left
78 /** Renames the item represented by \a oldUrl to \a newUrl. */
79 void rename(const KUrl
& oldUrl
, const KUrl
& newUrl
);
82 * Refreshs the views of the main window by recreating them dependent from
83 * the given Dolphin settings.
88 * Returns the 'Create New...' sub menu which also can be shared
89 * with other menus (e. g. a context menu).
91 inline KNewMenu
* newMenu() const;
95 * Handles the dropping of URLs to the given
96 * destination. A context menu with the options
97 * 'Move Here', 'Copy Here', 'Link Here' and
98 * 'Cancel' is offered to the user.
99 * @param urls List of URLs which have been
101 * @param destination Destination URL, where the
102 * list or URLs should be moved,
103 * copied or linked to.
105 void dropUrls(const KUrl::List
& urls
,
106 const KUrl
& destination
);
109 * Returns the main window ID used through DBus.
111 inline int getId() const;
114 * Inform all affected dolphin components (sidebars, views) of an URL
117 void changeUrl(const KUrl
& url
);
120 * Inform all affected dolphin components that a selection change is
123 void changeSelection(const KFileItemList
& selection
);
125 /** Stores all settings and quits Dolphin. */
130 * Is send if the active view has been changed in
131 * the split view mode.
133 void activeViewChanged();
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 sidebar.
149 * It the URL is empty, no item information request is pending.
151 void requestItemInfo(const KUrl
& url
);
154 /** @see QMainWindow::closeEvent */
155 virtual void closeEvent(QCloseEvent
* event
);
158 * This method is called when it is time for the app to save its
159 * properties for session management purposes.
161 void saveProperties(KConfig
*);
164 * This method is called when this app is restored. The KConfig
165 * object points to the session management config file that was saved
166 * with @ref saveProperties
168 void readProperties(KConfig
*);
171 /** Updates the 'Create New...' sub menu. */
172 void updateNewMenu();
175 * Let the user input a name for the selected item(s) and trigger
176 * a renaming afterwards.
180 /** Moves the selected items of the active view to the trash. */
183 /** Deletes the selected items of the active view. */
187 * Opens the properties window for the selected items of the
188 * active view. The properties windows shows information
189 * like name, size and permissions.
194 * Shows the error information of the job \a job
197 void slotHandleJobError(KJob
* job
);
200 * Indicates in the status bar that the delete operation
201 * of the job \a job has been finished.
203 void slotDeleteFileFinished(KJob
* job
);
206 * Updates the state of the 'Undo' menu action dependent
207 * from the parameter \a available.
209 void slotUndoAvailable(bool available
);
211 /** Sets the text of the 'Undo' menu action to \a text. */
212 void slotUndoTextChanged(const QString
& text
);
214 /** Performs the current undo operation. */
218 * Copies all selected items to the clipboard and marks
219 * the items as cutted.
223 /** Copies all selected items to the clipboard. */
226 /** Pastes the clipboard data to the active view. */
230 * Updates the text of the paste action dependent from
231 * the number of items which are in the clipboard.
233 void updatePasteAction();
235 /** Selects all items from the active view. */
239 * Inverts the selection of all items of the active view:
240 * Selected items get nonselected and nonselected items get
243 void invertSelection();
245 /** The current active view is switched to the icons mode. */
248 /** The current active view is switched to the details mode. */
249 void setDetailsView();
251 /** The current active view is switched to the column mode. */
252 void setColumnView();
254 /** The sorting of the current view should be done by the name. */
257 /** The sorting of the current view should be done by the size. */
260 /** The sorting of the current view should be done by the date. */
263 /** The sorting of the current view should be done by the permissions. */
264 void sortByPermissions();
266 /** The sorting of the current view should be done by the owner. */
269 /** The sorting of the current view should be done by the group. */
272 /** The sorting of the current view should be done by the type. */
275 /** Switches between an ascending and descending sorting order. */
276 void toggleSortOrder();
278 /** Switches between sorting by categories or not. */
279 void toggleSortCategorization();
282 * Clears any additional information for an item except for the
287 /** Shows the MIME type as additional information for the item. */
290 /** Shows the size as additional information for the item. */
293 /** Shows the date as additional information for the item. */
297 * Switches between one and two views:
298 * If one view is visible, it will get split into two views.
299 * If already two views are visible, the nonactivated view gets closed.
301 void toggleSplitView();
303 /** Reloads the current active view. */
306 /** Stops the loading process for the current active view. */
309 /** Switches between showing a preview of the file content and showing the icon. */
310 void togglePreview();
313 * Switches between showing and hiding of hidden marked files dependent
314 * from the current state of the 'Show Hidden Files' menu toggle action.
316 void toggleShowHiddenFiles();
319 * Toggles between showing and hiding of the filter bar dependent
320 * from the current state of the 'Show Filter Bar' menu toggle action.
322 void toggleFilterBarVisibility();
324 /** Increases the size of the current set view mode. */
327 /** Decreases the size of the current set view mode. */
331 * Toggles between edit and brose mode of the navigation bar.
333 void toggleEditLocation();
336 * Switches to the edit mode of the navigation bar. If the edit mode is
337 * already active, it is assured that the navigation bar get focused.
342 * Opens the view properties dialog, which allows to modify the properties
343 * of the currently active view.
345 void adjustViewProperties();
347 /** Goes back on step of the URL history. */
350 /** Goes forward one step of the URL history. */
353 /** Goes up one hierarchy of the current URL. */
356 /** Goes to the home URL. */
359 /** Opens KFind for the current shown directory. */
362 /** Opens Kompare for 2 selected files. */
365 /** Opens the settings dialog for Dolphin. */
368 /** Updates the state of all 'View' menu actions. */
369 void slotViewModeChanged();
371 /** Updates the state of the 'Show preview' menu action. */
372 void slotShowPreviewChanged();
374 /** Updates the state of the 'Show hidden files' menu action. */
375 void slotShowHiddenFilesChanged();
377 /** Updates the state of the 'Categorized sorting' menu action. */
378 void slotCategorizedSortingChanged();
380 /** Updates the state of the 'Sort by' actions. */
381 void slotSortingChanged(DolphinView::Sorting sorting
);
383 /** Updates the state of the 'Sort Ascending/Descending' action. */
384 void slotSortOrderChanged(Qt::SortOrder order
);
386 /** Updates the state of the 'Additional Information' actions. */
387 void slotAdditionalInfoChanged(KFileItemDelegate::AdditionalInformation info
);
390 * Updates the state of the 'Edit' menu actions and emits
391 * the signal selectionChanged().
393 void slotSelectionChanged(const KFileItemList
& selection
);
395 /** Emits the signal requestItemInfo(). */
396 void slotRequestItemInfo(const KUrl
& url
);
399 * Updates the state of the 'Back' and 'Forward' menu
400 * actions corresponding the the current history.
402 void slotHistoryChanged();
404 /** Updates the state of the 'Show filter bar' menu action. */
405 void updateFilterBarAction(bool show
);
407 /** Open a new main window. */
408 void openNewMainWindow();
410 /** Toggles the active view if two views are shown within the main window. */
411 void toggleActiveView();
414 DolphinMainWindow(int id
);
419 * Activates the given view, which means that
420 * all menu actions are applied to this view. When
421 * having a split view setup, the nonactive view
422 * is usually shown in darker colors.
424 void setActiveViewContainer(DolphinViewContainer
* view
);
427 void setupDockWidgets();
428 void updateHistory();
429 void updateEditActions();
430 void updateViewActions();
431 void updateGoActions();
432 void copyUrls(const KUrl::List
& source
, const KUrl
& dest
);
433 void moveUrls(const KUrl::List
& source
, const KUrl
& dest
);
434 void linkUrls(const KUrl::List
& source
, const KUrl
& dest
);
435 void clearStatusBar();
438 * Connects the signals from the created DolphinView with
439 * the index \a viewIndex with the corresponding slots of
440 * the DolphinMainWindow. This method must be invoked each
441 * time a DolphinView has been created.
443 void connectViewSignals(int viewIndex
);
446 * Updates the text of the split action:
447 * If \a isSplit is true, the text is set to "Split",
448 * otherwise the text is set to "Join". The icon
449 * is updated to match with the text.
451 void updateSplitAction(bool isSplit
);
455 * DolphinMainWindow supports up to two views beside each other.
459 PrimaryView
= 0, ///< View shown on the left side of the main window.
460 SecondaryView
= 1 ///< View shown on the left side of the main window.
464 * Implements a custom error handling for the undo manager. This
465 * assures that all errors are shown in the status bar of Dolphin
466 * instead as modal error dialog with an OK button.
468 class UndoUiInterface
: public KonqUndoManager::UiInterface
471 UndoUiInterface(DolphinMainWindow
* mainWin
);
472 virtual ~UndoUiInterface();
473 virtual void jobError(KIO::Job
* job
);
476 DolphinMainWindow
* m_mainWin
;
480 QSplitter
* m_splitter
;
481 DolphinViewContainer
* m_activeViewContainer
;
484 DolphinViewContainer
* m_viewContainer
[SecondaryView
+ 1];
486 /// remember pending undo operations until they are finished
487 QList
<KonqUndoManager::CommandType
> m_undoCommandTypes
;
490 DolphinViewContainer
* DolphinMainWindow::activeViewContainer() const
492 return m_activeViewContainer
;
495 bool DolphinMainWindow::isSplit() const
497 return m_viewContainer
[SecondaryView
] != 0;
500 KNewMenu
* DolphinMainWindow::newMenu() const
505 int DolphinMainWindow::getId() const
510 #endif // DOLPHIN_MAINWINDOW_H