]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.h
there's no need having 2-liners inside their own method when this method is only...
[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 /**
167 * This method is called when it is time for the app to save its
168 * properties for session management purposes.
169 */
170 void saveProperties(KConfig*);
171
172 /**
173 * This method is called when this app is restored. The KConfig
174 * object points to the session management config file that was saved
175 * with @ref saveProperties
176 */
177 void readProperties(KConfig*);
178
179 private slots:
180 /** Updates the 'Create New...' sub menu. */
181 void updateNewMenu();
182
183 /**
184 * Let the user input a name for the selected item(s) and trigger
185 * a renaming afterwards.
186 */
187 void rename();
188
189 /** Moves the selected items of the active view to the trash. */
190 void moveToTrash();
191
192 /** Deletes the selected items of the active view. */
193 void deleteItems();
194
195 /**
196 * Opens the properties window for the selected items of the
197 * active view. The properties windows shows information
198 * like name, size and permissions.
199 */
200 void properties();
201
202 /**
203 * Shows the error information from the places model
204 * in the status bar.
205 */
206 void slotHandlePlacesError(const QString &message);
207
208 /**
209 * Updates the state of the 'Undo' menu action dependent
210 * from the parameter \a available.
211 */
212 void slotUndoAvailable(bool available);
213
214 /** Sets the text of the 'Undo' menu action to \a text. */
215 void slotUndoTextChanged(const QString& text);
216
217 /** Performs the current undo operation. */
218 void undo();
219
220 /**
221 * Copies all selected items to the clipboard and marks
222 * the items as cutted.
223 */
224 void cut();
225
226 /** Copies all selected items to the clipboard. */
227 void copy();
228
229 /** Pastes the clipboard data to the active view. */
230 void paste();
231
232 /**
233 * Updates the text of the paste action dependent from
234 * the number of items which are in the clipboard.
235 */
236 void updatePasteAction();
237
238 /** Selects all items from the active view. */
239 void selectAll();
240
241 /**
242 * Inverts the selection of all items of the active view:
243 * Selected items get nonselected and nonselected items get
244 * selected.
245 */
246 void invertSelection();
247
248 /** The current active view is switched to a new view mode. */
249 void setViewMode(QAction *);
250
251 /** The sorting of the current view should be done by the name. */
252 void sortByName();
253
254 /** The sorting of the current view should be done by the size. */
255 void sortBySize();
256
257 /** The sorting of the current view should be done by the date. */
258 void sortByDate();
259
260 /** The sorting of the current view should be done by the permissions. */
261 void sortByPermissions();
262
263 /** The sorting of the current view should be done by the owner. */
264 void sortByOwner();
265
266 /** The sorting of the current view should be done by the group. */
267 void sortByGroup();
268
269 /** The sorting of the current view should be done by the type. */
270 void sortByType();
271
272 /** The sorting of the current view should be done by the rating. */
273 void sortByRating();
274
275 /** The sorting of the current view should be done by tags. */
276 void sortByTags();
277
278 /** Switches between an ascending and descending sorting order. */
279 void toggleSortOrder();
280
281 /** Switches between sorting by categories or not. */
282 void toggleSortCategorization();
283
284 /** Switches between showing the size as additional information for the item or not. */
285 void toggleSizeInfo();
286
287 /** Switchtes between showing the date as additional information for the item or not. */
288 void toggleDateInfo();
289
290 /** Switchtes between showing the permissions as additional information for the item or not. */
291 void togglePermissionsInfo();
292
293 /** Switchtes between showing the owner as additional information for the item or not. */
294 void toggleOwnerInfo();
295
296 /** Switchtes between showing the group as additional information for the item or not. */
297 void toggleGroupInfo();
298
299 /** Switches between showing the MIME type as additional information for the item or not. */
300 void toggleMimeInfo();
301
302 /**
303 * Switches between one and two views:
304 * If one view is visible, it will get split into two views.
305 * If already two views are visible, the nonactivated view gets closed.
306 */
307 void toggleSplitView();
308
309 /** Reloads the current active view. */
310 void reloadView();
311
312 /** Stops the loading process for the current active view. */
313 void stopLoading();
314
315 /** Switches between showing a preview of the file content and showing the icon. */
316 void togglePreview();
317
318 /**
319 * Switches between showing and hiding of hidden marked files dependent
320 * from the current state of the 'Show Hidden Files' menu toggle action.
321 */
322 void toggleShowHiddenFiles();
323
324 /**
325 * Toggles between showing and hiding of the filter bar dependent
326 * from the current state of the 'Show Filter Bar' menu toggle action.
327 */
328 void toggleFilterBarVisibility();
329
330 /** Increases the size of the current set view mode. */
331 void zoomIn();
332
333 /** Decreases the size of the current set view mode. */
334 void zoomOut();
335
336 /**
337 * Toggles between edit and brose mode of the navigation bar.
338 */
339 void toggleEditLocation();
340
341 /**
342 * Switches to the edit mode of the navigation bar. If the edit mode is
343 * already active, it is assured that the navigation bar get focused.
344 */
345 void editLocation();
346
347 /**
348 * Opens the view properties dialog, which allows to modify the properties
349 * of the currently active view.
350 */
351 void adjustViewProperties();
352
353 /** Goes back on step of the URL history. */
354 void goBack();
355
356 /** Goes forward one step of the URL history. */
357 void goForward();
358
359 /** Goes up one hierarchy of the current URL. */
360 void goUp();
361
362 /** Goes to the home URL. */
363 void goHome();
364
365 /** Opens KFind for the current shown directory. */
366 void findFile();
367
368 /** Opens Kompare for 2 selected files. */
369 void compareFiles();
370
371 /**
372 * Hides the menu bar if it is visible, makes the menu bar
373 * visible if it is hidden.
374 */
375 void toggleShowMenuBar();
376
377 /** Opens the settings dialog for Dolphin. */
378 void editSettings();
379
380 /** Updates the state of all 'View' menu actions. */
381 void slotViewModeChanged();
382
383 /** Updates the state of the 'Show preview' menu action. */
384 void slotShowPreviewChanged();
385
386 /** Updates the state of the 'Show hidden files' menu action. */
387 void slotShowHiddenFilesChanged();
388
389 /** Updates the state of the 'Categorized sorting' menu action. */
390 void slotCategorizedSortingChanged();
391
392 /** Updates the state of the 'Sort by' actions. */
393 void slotSortingChanged(DolphinView::Sorting sorting);
394
395 /** Updates the state of the 'Sort Ascending/Descending' action. */
396 void slotSortOrderChanged(Qt::SortOrder order);
397
398 /** Updates the state of the 'Additional Information' actions. */
399 void slotAdditionalInfoChanged(KFileItemDelegate::InformationList info);
400
401 /**
402 * Updates the state of the 'Edit' menu actions and emits
403 * the signal selectionChanged().
404 */
405 void slotSelectionChanged(const KFileItemList& selection);
406
407 /** Emits the signal requestItemInfo(). */
408 void slotRequestItemInfo(const KFileItem&);
409
410 /**
411 * Updates the state of the 'Back' and 'Forward' menu
412 * actions corresponding the the current history.
413 */
414 void slotHistoryChanged();
415
416 /** Updates the state of the 'Show filter bar' menu action. */
417 void updateFilterBarAction(bool show);
418
419 /** Open a new main window. */
420 void openNewMainWindow();
421
422 /** Toggles the active view if two views are shown within the main window. */
423 void toggleActiveView();
424
425 /** Called when the view is doing a file operation, like renaming, copying, moving etc. */
426 void slotDoingOperation(KonqFileUndoManager::CommandType type);
427
428 private:
429 DolphinMainWindow(int id);
430 void init();
431
432 /**
433 * Activates the given view, which means that
434 * all menu actions are applied to this view. When
435 * having a split view setup, the nonactive view
436 * is usually shown in darker colors.
437 */
438 void setActiveViewContainer(DolphinViewContainer* view);
439
440 void setupActions();
441 void setupDockWidgets();
442 void updateHistory();
443 void updateEditActions();
444 void updateViewActions();
445 void updateGoActions();
446 void clearStatusBar();
447
448 /**
449 * Connects the signals from the created DolphinView with
450 * the index \a viewIndex with the corresponding slots of
451 * the DolphinMainWindow. This method must be invoked each
452 * time a DolphinView has been created.
453 */
454 void connectViewSignals(int viewIndex);
455
456 /**
457 * Updates the text of the split action:
458 * If two views are shown, the text is set to "Split",
459 * otherwise the text is set to "Join". The icon
460 * is updated to match with the text and the currently active view.
461 */
462 void updateSplitAction();
463
464 /**
465 * Helper method for the slots toggleDateInfo(), toggleSizeInfo()
466 * and toggleMimeInfo(). Applies \a info dependent from the current
467 * checked state of the action \a actionName to the file item delegate.
468 */
469 void toggleAdditionalInfo(const char* actionName,
470 KFileItemDelegate::Information info);
471
472 private:
473 /**
474 * DolphinMainWindow supports up to two views beside each other.
475 */
476 enum ViewIndex
477 {
478 PrimaryView = 0, ///< View shown on the left side of the main window.
479 SecondaryView = 1 ///< View shown on the left side of the main window.
480 };
481
482 /**
483 * Implements a custom error handling for the undo manager. This
484 * assures that all errors are shown in the status bar of Dolphin
485 * instead as modal error dialog with an OK button.
486 */
487 class UndoUiInterface : public KonqFileUndoManager::UiInterface
488 {
489 public:
490 UndoUiInterface(DolphinMainWindow* mainWin);
491 virtual ~UndoUiInterface();
492 virtual void jobError(KIO::Job* job);
493
494 private:
495 DolphinMainWindow* m_mainWin;
496 };
497
498 KNewMenu* m_newMenu;
499 KAction* m_showMenuBar;
500 QSplitter* m_splitter;
501 DolphinViewContainer* m_activeViewContainer;
502 int m_id;
503
504 DolphinViewContainer* m_viewContainer[SecondaryView + 1];
505
506 /// remember pending undo operations until they are finished
507 QList<KonqFileUndoManager::CommandType> m_undoCommandTypes;
508 };
509
510 inline DolphinViewContainer* DolphinMainWindow::activeViewContainer() const
511 {
512 return m_activeViewContainer;
513 }
514
515 inline bool DolphinMainWindow::isSplit() const
516 {
517 return m_viewContainer[SecondaryView] != 0;
518 }
519
520 inline KNewMenu* DolphinMainWindow::newMenu() const
521 {
522 return m_newMenu;
523 }
524
525 inline KAction* DolphinMainWindow::showMenuBarAction() const
526 {
527 return m_showMenuBar;
528 }
529
530 inline int DolphinMainWindow::getId() const
531 {
532 return m_id;
533 }
534
535 #endif // DOLPHIN_MAINWINDOW_H
536