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