]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.h
enable session management
[dolphin.git] / src / dolphinmainwindow.h
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> *
5 * *
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. *
10 * *
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. *
15 * *
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 ***************************************************************************/
21
22 #ifndef DOLPHIN_MAINWINDOW_H
23 #define DOLPHIN_MAINWINDOW_H
24
25 #include "dolphinview.h"
26 #include "sidebarpage.h"
27
28 #include <config-nepomuk.h>
29
30 #include <kfileitemdelegate.h>
31 #include <konq_fileundomanager.h>
32 #include <ksortablelist.h>
33 #include <kxmlguiwindow.h>
34
35 #include <QtCore/QList>
36
37 class DolphinApplication;
38 class DolphinViewContainer;
39 class KNewMenu;
40 class KUrl;
41 class QSplitter;
42
43 /**
44 * @short Main window for Dolphin.
45 *
46 * Handles the menus, toolbars and Dolphin views.
47 */
48 class DolphinMainWindow: public KXmlGuiWindow
49 {
50 Q_OBJECT
51 Q_CLASSINFO("D-Bus Interface", "org.kde.dolphin.MainWindow")
52 Q_PROPERTY(int id READ getId SCRIPTABLE true)
53 friend class DolphinApplication;
54
55 public:
56 virtual ~DolphinMainWindow();
57
58 /**
59 * Returns the currently active view.
60 * All menu actions are applied to this view. When
61 * having a split view setup, the nonactive view
62 * is usually shown in darker colors.
63 */
64 DolphinViewContainer* activeViewContainer() const;
65
66 /**
67 * Returns true, if the main window contains two instances
68 * of a view container. The active view constainer can be
69 * accessed by DolphinMainWindow::activeViewContainer().
70 */
71 bool isSplit() const;
72
73 /**
74 * If the main window contains two instances of a view container
75 * (DolphinMainWindow::isSplit() returns true), then the
76 * two views get toggled (the right view is on the left, the left
77 * view on the right).
78 */
79 void toggleViews();
80
81 /** Renames the item represented by \a oldUrl to \a newUrl. */
82 void rename(const KUrl& oldUrl, const KUrl& newUrl);
83
84 /**
85 * Refreshes the views of the main window by recreating them dependent from
86 * the given Dolphin settings.
87 */
88 void refreshViews();
89
90 /**
91 * Returns the 'Create New...' sub menu which also can be shared
92 * with other menus (e. g. a context menu).
93 */
94 KNewMenu* newMenu() const;
95
96 /**
97 * Returns the 'Show Menubar' action which can be shared with
98 * other menus (e. g. a context menu).
99 */
100 KAction* showMenuBarAction() const;
101
102 public slots:
103 /**
104 * Handles the dropping of URLs to the given
105 * destination. A context menu with the options
106 * 'Move Here', 'Copy Here', 'Link Here' and
107 * 'Cancel' is offered to the user.
108 * @param urls List of URLs which have been
109 * dropped.
110 * @param destination Destination URL, where the
111 * list or URLs should be moved,
112 * copied or linked to.
113 */
114 void dropUrls(const KUrl::List& urls,
115 const KUrl& destination);
116
117 /**
118 * Returns the main window ID used through DBus.
119 */
120 int getId() const;
121
122 /**
123 * Inform all affected dolphin components (sidebars, views) of an URL
124 * change.
125 */
126 void changeUrl(const KUrl& url);
127
128 /**
129 * Inform all affected dolphin components that a selection change is
130 * requested.
131 */
132 void changeSelection(const KFileItemList& selection);
133
134 /** Stores all settings and quits Dolphin. */
135 void quit();
136
137 signals:
138 /**
139 * Is send if the active view has been changed in
140 * the split view mode.
141 */
142 void activeViewChanged();
143
144 /**
145 * Is sent if the selection of the currently active view has
146 * been changed.
147 */
148 void selectionChanged(const KFileItemList& selection);
149
150 /**
151 * Is sent if the url of the currently active view has
152 * been changed.
153 */
154 void urlChanged(const KUrl& url);
155
156 /**
157 * Is emitted if information of an item is requested to be shown e. g. in the sidebar.
158 * If item is null, no item information request is pending.
159 */
160 void requestItemInfo(const KFileItem& item);
161
162 protected:
163 /** @see QMainWindow::closeEvent() */
164 virtual void closeEvent(QCloseEvent* event);
165
166 /** @see KMainWindow::saveProperties() */
167 virtual void saveProperties(KConfigGroup& group);
168
169 /** @see KMainWindow::readProperties() */
170 virtual void readProperties(const KConfigGroup& group);
171
172 private slots:
173 /** Updates the 'Create New...' sub menu. */
174 void updateNewMenu();
175
176 /**
177 * Let the user input a name for the selected item(s) and trigger
178 * a renaming afterwards.
179 */
180 void rename();
181
182 /** Moves the selected items of the active view to the trash. */
183 void moveToTrash();
184
185 /** Deletes the selected items of the active view. */
186 void deleteItems();
187
188 /**
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.
192 */
193 void properties();
194
195 /**
196 * Shows the error information from the places model
197 * in the status bar.
198 */
199 void slotHandlePlacesError(const QString &message);
200
201 /**
202 * Updates the state of the 'Undo' menu action dependent
203 * from the parameter \a available.
204 */
205 void slotUndoAvailable(bool available);
206
207 /** Sets the text of the 'Undo' menu action to \a text. */
208 void slotUndoTextChanged(const QString& text);
209
210 /** Performs the current undo operation. */
211 void undo();
212
213 /**
214 * Copies all selected items to the clipboard and marks
215 * the items as cutted.
216 */
217 void cut();
218
219 /** Copies all selected items to the clipboard. */
220 void copy();
221
222 /** Pastes the clipboard data to the active view. */
223 void paste();
224
225 /**
226 * Updates the text of the paste action dependent from
227 * the number of items which are in the clipboard.
228 */
229 void updatePasteAction();
230
231 /** Selects all items from the active view. */
232 void selectAll();
233
234 /**
235 * Inverts the selection of all items of the active view:
236 * Selected items get nonselected and nonselected items get
237 * selected.
238 */
239 void invertSelection();
240
241 /** The current active view is switched to a new view mode. */
242 void setViewMode(QAction *);
243
244 /** The sorting of the current view should be done by the name. */
245 void sortByName();
246
247 /** The sorting of the current view should be done by the size. */
248 void sortBySize();
249
250 /** The sorting of the current view should be done by the date. */
251 void sortByDate();
252
253 /** The sorting of the current view should be done by the permissions. */
254 void sortByPermissions();
255
256 /** The sorting of the current view should be done by the owner. */
257 void sortByOwner();
258
259 /** The sorting of the current view should be done by the group. */
260 void sortByGroup();
261
262 /** The sorting of the current view should be done by the type. */
263 void sortByType();
264
265 /** The sorting of the current view should be done by the rating. */
266 void sortByRating();
267
268 /** The sorting of the current view should be done by tags. */
269 void sortByTags();
270
271 /** Switches between an ascending and descending sorting order. */
272 void toggleSortOrder();
273
274 /** Switches between sorting by categories or not. */
275 void toggleSortCategorization();
276
277 /** Switches between showing the size as additional information for the item or not. */
278 void toggleSizeInfo();
279
280 /** Switchtes between showing the date as additional information for the item or not. */
281 void toggleDateInfo();
282
283 /** Switchtes between showing the permissions as additional information for the item or not. */
284 void togglePermissionsInfo();
285
286 /** Switchtes between showing the owner as additional information for the item or not. */
287 void toggleOwnerInfo();
288
289 /** Switchtes between showing the group as additional information for the item or not. */
290 void toggleGroupInfo();
291
292 /** Switches between showing the MIME type as additional information for the item or not. */
293 void toggleMimeInfo();
294
295 /**
296 * Switches between one and two views:
297 * If one view is visible, it will get split into two views.
298 * If already two views are visible, the nonactivated view gets closed.
299 */
300 void toggleSplitView();
301
302 /** Reloads the current active view. */
303 void reloadView();
304
305 /** Stops the loading process for the current active view. */
306 void stopLoading();
307
308 /** Switches between showing a preview of the file content and showing the icon. */
309 void togglePreview();
310
311 /**
312 * Switches between showing and hiding of hidden marked files dependent
313 * from the current state of the 'Show Hidden Files' menu toggle action.
314 */
315 void toggleShowHiddenFiles();
316
317 /**
318 * Toggles between showing and hiding of the filter bar dependent
319 * from the current state of the 'Show Filter Bar' menu toggle action.
320 */
321 void toggleFilterBarVisibility();
322
323 /** Increases the size of the current set view mode. */
324 void zoomIn();
325
326 /** Decreases the size of the current set view mode. */
327 void zoomOut();
328
329 /**
330 * Toggles between edit and brose mode of the navigation bar.
331 */
332 void toggleEditLocation();
333
334 /**
335 * Switches to the edit mode of the navigation bar. If the edit mode is
336 * already active, it is assured that the navigation bar get focused.
337 */
338 void editLocation();
339
340 /**
341 * Opens the view properties dialog, which allows to modify the properties
342 * of the currently active view.
343 */
344 void adjustViewProperties();
345
346 /** Goes back on step of the URL history. */
347 void goBack();
348
349 /** Goes forward one step of the URL history. */
350 void goForward();
351
352 /** Goes up one hierarchy of the current URL. */
353 void goUp();
354
355 /** Goes to the home URL. */
356 void goHome();
357
358 /** Opens KFind for the current shown directory. */
359 void findFile();
360
361 /** Opens Kompare for 2 selected files. */
362 void compareFiles();
363
364 /**
365 * Hides the menu bar if it is visible, makes the menu bar
366 * visible if it is hidden.
367 */
368 void toggleShowMenuBar();
369
370 /** Opens the settings dialog for Dolphin. */
371 void editSettings();
372
373 /** Updates the state of all 'View' menu actions. */
374 void slotViewModeChanged();
375
376 /** Updates the state of the 'Show preview' menu action. */
377 void slotShowPreviewChanged();
378
379 /** Updates the state of the 'Show hidden files' menu action. */
380 void slotShowHiddenFilesChanged();
381
382 /** Updates the state of the 'Categorized sorting' menu action. */
383 void slotCategorizedSortingChanged();
384
385 /** Updates the state of the 'Sort by' actions. */
386 void slotSortingChanged(DolphinView::Sorting sorting);
387
388 /** Updates the state of the 'Sort Ascending/Descending' action. */
389 void slotSortOrderChanged(Qt::SortOrder order);
390
391 /** Updates the state of the 'Additional Information' actions. */
392 void slotAdditionalInfoChanged(KFileItemDelegate::InformationList info);
393
394 /**
395 * Updates the state of the 'Edit' menu actions and emits
396 * the signal selectionChanged().
397 */
398 void slotSelectionChanged(const KFileItemList& selection);
399
400 /** Emits the signal requestItemInfo(). */
401 void slotRequestItemInfo(const KFileItem&);
402
403 /**
404 * Updates the state of the 'Back' and 'Forward' menu
405 * actions corresponding the the current history.
406 */
407 void slotHistoryChanged();
408
409 /** Updates the state of the 'Show filter bar' menu action. */
410 void updateFilterBarAction(bool show);
411
412 /** Open a new main window. */
413 void openNewMainWindow();
414
415 /** Toggles the active view if two views are shown within the main window. */
416 void toggleActiveView();
417
418 /** Called when the view is doing a file operation, like renaming, copying, moving etc. */
419 void slotDoingOperation(KonqFileUndoManager::CommandType type);
420
421 private:
422 DolphinMainWindow(int id);
423 void init();
424
425 /**
426 * Activates the given view, which means that
427 * all menu actions are applied to this view. When
428 * having a split view setup, the nonactive view
429 * is usually shown in darker colors.
430 */
431 void setActiveViewContainer(DolphinViewContainer* view);
432
433 void setupActions();
434 void setupDockWidgets();
435 void updateHistory();
436 void updateEditActions();
437 void updateViewActions();
438 void updateGoActions();
439 void clearStatusBar();
440
441 /**
442 * Connects the signals from the created DolphinView with
443 * the index \a viewIndex with the corresponding slots of
444 * the DolphinMainWindow. This method must be invoked each
445 * time a DolphinView has been created.
446 */
447 void connectViewSignals(int viewIndex);
448
449 /**
450 * Updates the text of the split action:
451 * If two views are shown, the text is set to "Split",
452 * otherwise the text is set to "Join". The icon
453 * is updated to match with the text and the currently active view.
454 */
455 void updateSplitAction();
456
457 /**
458 * Helper method for the slots toggleDateInfo(), toggleSizeInfo()
459 * and toggleMimeInfo(). Applies \a info dependent from the current
460 * checked state of the action \a actionName to the file item delegate.
461 */
462 void toggleAdditionalInfo(const char* actionName,
463 KFileItemDelegate::Information info);
464
465 private:
466 /**
467 * DolphinMainWindow supports up to two views beside each other.
468 */
469 enum ViewIndex
470 {
471 PrimaryView = 0, ///< View shown on the left side of the main window.
472 SecondaryView = 1 ///< View shown on the left side of the main window.
473 };
474
475 /**
476 * Implements a custom error handling for the undo manager. This
477 * assures that all errors are shown in the status bar of Dolphin
478 * instead as modal error dialog with an OK button.
479 */
480 class UndoUiInterface : public KonqFileUndoManager::UiInterface
481 {
482 public:
483 UndoUiInterface(DolphinMainWindow* mainWin);
484 virtual ~UndoUiInterface();
485 virtual void jobError(KIO::Job* job);
486
487 private:
488 DolphinMainWindow* m_mainWin;
489 };
490
491 KNewMenu* m_newMenu;
492 KAction* m_showMenuBar;
493 QSplitter* m_splitter;
494 DolphinViewContainer* m_activeViewContainer;
495 int m_id;
496
497 DolphinViewContainer* m_viewContainer[SecondaryView + 1];
498
499 /// remember pending undo operations until they are finished
500 QList<KonqFileUndoManager::CommandType> m_undoCommandTypes;
501 };
502
503 inline DolphinViewContainer* DolphinMainWindow::activeViewContainer() const
504 {
505 return m_activeViewContainer;
506 }
507
508 inline bool DolphinMainWindow::isSplit() const
509 {
510 return m_viewContainer[SecondaryView] != 0;
511 }
512
513 inline KNewMenu* DolphinMainWindow::newMenu() const
514 {
515 return m_newMenu;
516 }
517
518 inline KAction* DolphinMainWindow::showMenuBarAction() const
519 {
520 return m_showMenuBar;
521 }
522
523 inline int DolphinMainWindow::getId() const
524 {
525 return m_id;
526 }
527
528 #endif // DOLPHIN_MAINWINDOW_H
529