]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.h
Use KFileItem by value rather than by pointer
[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 <kxmlguiwindow.h>
31 #include <ksortablelist.h>
32 #include <konq_undo.h>
33
34 #include <QtCore/QList>
35
36 class DolphinApplication;
37 class DolphinViewContainer;
38 class KNewMenu;
39 class KUrl;
40 class QSplitter;
41
42 /**
43 * @short Main window for Dolphin.
44 *
45 * Handles the menus, toolbars and Dolphin views.
46 */
47 class DolphinMainWindow: public KXmlGuiWindow
48 {
49 Q_OBJECT
50 Q_CLASSINFO("D-Bus Interface", "org.kde.dolphin.MainWindow")
51 Q_PROPERTY(int id READ getId SCRIPTABLE true)
52 friend class DolphinApplication;
53
54 public:
55 virtual ~DolphinMainWindow();
56
57 /**
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.
62 */
63 inline DolphinViewContainer* activeViewContainer() const;
64
65 /**
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().
69 */
70 inline bool isSplit() const;
71
72 /**
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
76 * view on the right).
77 */
78 void toggleViews();
79
80 /** Renames the item represented by \a oldUrl to \a newUrl. */
81 void rename(const KUrl& oldUrl, const KUrl& newUrl);
82
83 /**
84 * Refreshs the views of the main window by recreating them dependent from
85 * the given Dolphin settings.
86 */
87 void refreshViews();
88
89 /**
90 * Returns the 'Create New...' sub menu which also can be shared
91 * with other menus (e. g. a context menu).
92 */
93 inline KNewMenu* newMenu() const;
94
95 public slots:
96 /**
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
102 * dropped.
103 * @param destination Destination URL, where the
104 * list or URLs should be moved,
105 * copied or linked to.
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 inline 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 QList<KFileItem>& 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 QList<KFileItem>& 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 /**
160 * This method is called when it is time for the app to save its
161 * properties for session management purposes.
162 */
163 void saveProperties(KConfig*);
164
165 /**
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
169 */
170 void readProperties(KConfig*);
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 * Shows the error information of the job \a job
203 * in the status bar.
204 */
205 void slotHandleJobError(KJob* job);
206
207 /**
208 * Indicates in the status bar that the delete operation
209 * of the job \a job has been finished.
210 */
211 void slotDeleteFileFinished(KJob* job);
212
213 /**
214 * Updates the state of the 'Undo' menu action dependent
215 * from the parameter \a available.
216 */
217 void slotUndoAvailable(bool available);
218
219 /** Sets the text of the 'Undo' menu action to \a text. */
220 void slotUndoTextChanged(const QString& text);
221
222 /** Performs the current undo operation. */
223 void undo();
224
225 /**
226 * Copies all selected items to the clipboard and marks
227 * the items as cutted.
228 */
229 void cut();
230
231 /** Copies all selected items to the clipboard. */
232 void copy();
233
234 /** Pastes the clipboard data to the active view. */
235 void paste();
236
237 /**
238 * Updates the text of the paste action dependent from
239 * the number of items which are in the clipboard.
240 */
241 void updatePasteAction();
242
243 /** Selects all items from the active view. */
244 void selectAll();
245
246 /**
247 * Inverts the selection of all items of the active view:
248 * Selected items get nonselected and nonselected items get
249 * selected.
250 */
251 void invertSelection();
252
253 /** The current active view is switched to the icons mode. */
254 void setIconsView();
255
256 /** The current active view is switched to the details mode. */
257 void setDetailsView();
258
259 /** The current active view is switched to the column mode. */
260 void setColumnView();
261
262 /** The sorting of the current view should be done by the name. */
263 void sortByName();
264
265 /** The sorting of the current view should be done by the size. */
266 void sortBySize();
267
268 /** The sorting of the current view should be done by the date. */
269 void sortByDate();
270
271 /** The sorting of the current view should be done by the permissions. */
272 void sortByPermissions();
273
274 /** The sorting of the current view should be done by the owner. */
275 void sortByOwner();
276
277 /** The sorting of the current view should be done by the group. */
278 void sortByGroup();
279
280 /** The sorting of the current view should be done by the type. */
281 void sortByType();
282
283 /** The sorting of the current view should be done by the rating. */
284 void sortByRating();
285
286 /** The sorting of the current view should be done by tags. */
287 void sortByTags();
288
289 /** Switches between an ascending and descending sorting order. */
290 void toggleSortOrder();
291
292 /** Switches between sorting by categories or not. */
293 void toggleSortCategorization();
294
295 /**
296 * Clears any additional information for an item except for the
297 * name and the icon.
298 */
299 void clearInfo();
300
301 /** Shows the MIME type as additional information for the item. */
302 void showMimeInfo();
303
304 /** Shows the size as additional information for the item. */
305 void showSizeInfo();
306
307 /** Shows the date as additional information for the item. */
308 void showDateInfo();
309
310 /**
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.
314 */
315 void toggleSplitView();
316
317 /** Reloads the current active view. */
318 void reloadView();
319
320 /** Stops the loading process for the current active view. */
321 void stopLoading();
322
323 /** Switches between showing a preview of the file content and showing the icon. */
324 void togglePreview();
325
326 /**
327 * Switches between showing and hiding of hidden marked files dependent
328 * from the current state of the 'Show Hidden Files' menu toggle action.
329 */
330 void toggleShowHiddenFiles();
331
332 /**
333 * Toggles between showing and hiding of the filter bar dependent
334 * from the current state of the 'Show Filter Bar' menu toggle action.
335 */
336 void toggleFilterBarVisibility();
337
338 /** Increases the size of the current set view mode. */
339 void zoomIn();
340
341 /** Decreases the size of the current set view mode. */
342 void zoomOut();
343
344 /**
345 * Toggles between edit and brose mode of the navigation bar.
346 */
347 void toggleEditLocation();
348
349 /**
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.
352 */
353 void editLocation();
354
355 /**
356 * Opens the view properties dialog, which allows to modify the properties
357 * of the currently active view.
358 */
359 void adjustViewProperties();
360
361 /** Goes back on step of the URL history. */
362 void goBack();
363
364 /** Goes forward one step of the URL history. */
365 void goForward();
366
367 /** Goes up one hierarchy of the current URL. */
368 void goUp();
369
370 /** Goes to the home URL. */
371 void goHome();
372
373 /** Opens KFind for the current shown directory. */
374 void findFile();
375
376 /** Opens Kompare for 2 selected files. */
377 void compareFiles();
378
379 /** Opens the settings dialog for Dolphin. */
380 void editSettings();
381
382 /** Updates the state of all 'View' menu actions. */
383 void slotViewModeChanged();
384
385 /** Updates the state of the 'Show preview' menu action. */
386 void slotShowPreviewChanged();
387
388 /** Updates the state of the 'Show hidden files' menu action. */
389 void slotShowHiddenFilesChanged();
390
391 /** Updates the state of the 'Categorized sorting' menu action. */
392 void slotCategorizedSortingChanged();
393
394 /** Updates the state of the 'Sort by' actions. */
395 void slotSortingChanged(DolphinView::Sorting sorting);
396
397 /** Updates the state of the 'Sort Ascending/Descending' action. */
398 void slotSortOrderChanged(Qt::SortOrder order);
399
400 /** Updates the state of the 'Additional Information' actions. */
401 void slotAdditionalInfoChanged(KFileItemDelegate::AdditionalInformation info);
402
403 /**
404 * Updates the state of the 'Edit' menu actions and emits
405 * the signal selectionChanged().
406 */
407 void slotSelectionChanged(const QList<KFileItem>& selection);
408
409 /** Emits the signal requestItemInfo(). */
410 void slotRequestItemInfo(const KFileItem&);
411
412 /**
413 * Updates the state of the 'Back' and 'Forward' menu
414 * actions corresponding the the current history.
415 */
416 void slotHistoryChanged();
417
418 /** Updates the state of the 'Show filter bar' menu action. */
419 void updateFilterBarAction(bool show);
420
421 /** Open a new main window. */
422 void openNewMainWindow();
423
424 /** Toggles the active view if two views are shown within the main window. */
425 void toggleActiveView();
426
427 private:
428 DolphinMainWindow(int id);
429 void init();
430
431 /**
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.
436 */
437 void setActiveViewContainer(DolphinViewContainer* view);
438
439 void setupActions();
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();
449
450 /**
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.
455 */
456 void connectViewSignals(int viewIndex);
457
458 /**
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.
463 */
464 void updateSplitAction();
465
466 private:
467 /**
468 * DolphinMainWindow supports up to two views beside each other.
469 */
470 enum ViewIndex
471 {
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.
474 };
475
476 /**
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.
480 */
481 class UndoUiInterface : public KonqUndoManager::UiInterface
482 {
483 public:
484 UndoUiInterface(DolphinMainWindow* mainWin);
485 virtual ~UndoUiInterface();
486 virtual void jobError(KIO::Job* job);
487
488 private:
489 DolphinMainWindow* m_mainWin;
490 };
491
492 KNewMenu* m_newMenu;
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<KonqUndoManager::CommandType> m_undoCommandTypes;
501 };
502
503 DolphinViewContainer* DolphinMainWindow::activeViewContainer() const
504 {
505 return m_activeViewContainer;
506 }
507
508 bool DolphinMainWindow::isSplit() const
509 {
510 return m_viewContainer[SecondaryView] != 0;
511 }
512
513 KNewMenu* DolphinMainWindow::newMenu() const
514 {
515 return m_newMenu;
516 }
517
518 int DolphinMainWindow::getId() const
519 {
520 return m_id;
521 }
522
523 #endif // DOLPHIN_MAINWINDOW_H
524