]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.h
Implement renaming in dolphinpart.
[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 public slots:
97 /**
98 * Handles the dropping of URLs to the given
99 * destination. A context menu with the options
100 * 'Move Here', 'Copy Here', 'Link Here' and
101 * 'Cancel' is offered to the user.
102 * @param urls List of URLs which have been
103 * dropped.
104 * @param destination Destination URL, where the
105 * list or URLs should be moved,
106 * copied or linked to.
107 */
108 void dropUrls(const KUrl::List& urls,
109 const KUrl& destination);
110
111 /**
112 * Returns the main window ID used through DBus.
113 */
114 int getId() const;
115
116 /**
117 * Inform all affected dolphin components (sidebars, views) of an URL
118 * change.
119 */
120 void changeUrl(const KUrl& url);
121
122 /**
123 * Inform all affected dolphin components that a selection change is
124 * requested.
125 */
126 void changeSelection(const KFileItemList& selection);
127
128 /** Stores all settings and quits Dolphin. */
129 void quit();
130
131 signals:
132 /**
133 * Is send if the active view has been changed in
134 * the split view mode.
135 */
136 void activeViewChanged();
137
138 /**
139 * Is sent if the selection of the currently active view has
140 * been changed.
141 */
142 void selectionChanged(const KFileItemList& selection);
143
144 /**
145 * Is sent if the url of the currently active view has
146 * been changed.
147 */
148 void urlChanged(const KUrl& url);
149
150 /**
151 * Is emitted if information of an item is requested to be shown e. g. in the sidebar.
152 * If item is null, no item information request is pending.
153 */
154 void requestItemInfo(const KFileItem& item);
155
156 protected:
157 /** @see QMainWindow::closeEvent */
158 virtual void closeEvent(QCloseEvent* event);
159
160 /**
161 * This method is called when it is time for the app to save its
162 * properties for session management purposes.
163 */
164 void saveProperties(KConfig*);
165
166 /**
167 * This method is called when this app is restored. The KConfig
168 * object points to the session management config file that was saved
169 * with @ref saveProperties
170 */
171 void readProperties(KConfig*);
172
173 private slots:
174 /** Updates the 'Create New...' sub menu. */
175 void updateNewMenu();
176
177 /**
178 * Let the user input a name for the selected item(s) and trigger
179 * a renaming afterwards.
180 */
181 void rename();
182
183 /** Moves the selected items of the active view to the trash. */
184 void moveToTrash();
185
186 /** Deletes the selected items of the active view. */
187 void deleteItems();
188
189 /**
190 * Opens the properties window for the selected items of the
191 * active view. The properties windows shows information
192 * like name, size and permissions.
193 */
194 void properties();
195
196 /**
197 * Shows the error information from the places model
198 * in the status bar.
199 */
200 void slotHandlePlacesError(const QString &message);
201
202 /**
203 * Shows the error information of the job \a job
204 * in the status bar.
205 */
206 void slotHandleJobError(KJob* job);
207
208 /**
209 * Indicates in the status bar that the delete operation
210 * of the job \a job has been finished.
211 */
212 void slotDeleteFileFinished(KJob* job);
213
214 /**
215 * Updates the state of the 'Undo' menu action dependent
216 * from the parameter \a available.
217 */
218 void slotUndoAvailable(bool available);
219
220 /** Sets the text of the 'Undo' menu action to \a text. */
221 void slotUndoTextChanged(const QString& text);
222
223 /** Performs the current undo operation. */
224 void undo();
225
226 /**
227 * Copies all selected items to the clipboard and marks
228 * the items as cutted.
229 */
230 void cut();
231
232 /** Copies all selected items to the clipboard. */
233 void copy();
234
235 /** Pastes the clipboard data to the active view. */
236 void paste();
237
238 /**
239 * Updates the text of the paste action dependent from
240 * the number of items which are in the clipboard.
241 */
242 void updatePasteAction();
243
244 /** Selects all items from the active view. */
245 void selectAll();
246
247 /**
248 * Inverts the selection of all items of the active view:
249 * Selected items get nonselected and nonselected items get
250 * selected.
251 */
252 void invertSelection();
253
254 /** The current active view is switched to a new view mode. */
255 void setViewMode(QAction *);
256
257 /** The sorting of the current view should be done by the name. */
258 void sortByName();
259
260 /** The sorting of the current view should be done by the size. */
261 void sortBySize();
262
263 /** The sorting of the current view should be done by the date. */
264 void sortByDate();
265
266 /** The sorting of the current view should be done by the permissions. */
267 void sortByPermissions();
268
269 /** The sorting of the current view should be done by the owner. */
270 void sortByOwner();
271
272 /** The sorting of the current view should be done by the group. */
273 void sortByGroup();
274
275 /** The sorting of the current view should be done by the type. */
276 void sortByType();
277
278 /** The sorting of the current view should be done by the rating. */
279 void sortByRating();
280
281 /** The sorting of the current view should be done by tags. */
282 void sortByTags();
283
284 /** Switches between an ascending and descending sorting order. */
285 void toggleSortOrder();
286
287 /** Switches between sorting by categories or not. */
288 void toggleSortCategorization();
289
290 /** Switches between showing the size as additional information for the item or not. */
291 void toggleSizeInfo();
292
293 /** Switchtes between showing the date as additional information for the item or not. */
294 void toggleDateInfo();
295
296 /** Switchtes between showing the permissions as additional information for the item or not. */
297 void togglePermissionsInfo();
298
299 /** Switchtes between showing the owner as additional information for the item or not. */
300 void toggleOwnerInfo();
301
302 /** Switchtes between showing the group as additional information for the item or not. */
303 void toggleGroupInfo();
304
305 /** Switches between showing the MIME type as additional information for the item or not. */
306 void toggleMimeInfo();
307
308 /**
309 * Switches between one and two views:
310 * If one view is visible, it will get split into two views.
311 * If already two views are visible, the nonactivated view gets closed.
312 */
313 void toggleSplitView();
314
315 /** Reloads the current active view. */
316 void reloadView();
317
318 /** Stops the loading process for the current active view. */
319 void stopLoading();
320
321 /** Switches between showing a preview of the file content and showing the icon. */
322 void togglePreview();
323
324 /**
325 * Switches between showing and hiding of hidden marked files dependent
326 * from the current state of the 'Show Hidden Files' menu toggle action.
327 */
328 void toggleShowHiddenFiles();
329
330 /**
331 * Toggles between showing and hiding of the filter bar dependent
332 * from the current state of the 'Show Filter Bar' menu toggle action.
333 */
334 void toggleFilterBarVisibility();
335
336 /** Increases the size of the current set view mode. */
337 void zoomIn();
338
339 /** Decreases the size of the current set view mode. */
340 void zoomOut();
341
342 /**
343 * Toggles between edit and brose mode of the navigation bar.
344 */
345 void toggleEditLocation();
346
347 /**
348 * Switches to the edit mode of the navigation bar. If the edit mode is
349 * already active, it is assured that the navigation bar get focused.
350 */
351 void editLocation();
352
353 /**
354 * Opens the view properties dialog, which allows to modify the properties
355 * of the currently active view.
356 */
357 void adjustViewProperties();
358
359 /** Goes back on step of the URL history. */
360 void goBack();
361
362 /** Goes forward one step of the URL history. */
363 void goForward();
364
365 /** Goes up one hierarchy of the current URL. */
366 void goUp();
367
368 /** Goes to the home URL. */
369 void goHome();
370
371 /** Opens KFind for the current shown directory. */
372 void findFile();
373
374 /** Opens Kompare for 2 selected files. */
375 void compareFiles();
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 renaming a file. */
426 void slotRenaming();
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 copyUrls(const KUrl::List& source, const KUrl& dest);
447 void moveUrls(const KUrl::List& source, const KUrl& dest);
448 void linkUrls(const KUrl::List& source, const KUrl& dest);
449 void clearStatusBar();
450
451 /**
452 * Connects the signals from the created DolphinView with
453 * the index \a viewIndex with the corresponding slots of
454 * the DolphinMainWindow. This method must be invoked each
455 * time a DolphinView has been created.
456 */
457 void connectViewSignals(int viewIndex);
458
459 /**
460 * Updates the text of the split action:
461 * If two views are shown, the text is set to "Split",
462 * otherwise the text is set to "Join". The icon
463 * is updated to match with the text and the currently active view.
464 */
465 void updateSplitAction();
466
467 /**
468 * Helper method for the slots toggleDateInfo(), toggleSizeInfo()
469 * and toggleMimeInfo(). Applies \a info dependent from the current
470 * checked state of the action \a actionName to the file item delegate.
471 */
472 void toggleAdditionalInfo(const char* actionName,
473 KFileItemDelegate::Information info);
474
475 private:
476 /**
477 * DolphinMainWindow supports up to two views beside each other.
478 */
479 enum ViewIndex
480 {
481 PrimaryView = 0, ///< View shown on the left side of the main window.
482 SecondaryView = 1 ///< View shown on the left side of the main window.
483 };
484
485 /**
486 * Implements a custom error handling for the undo manager. This
487 * assures that all errors are shown in the status bar of Dolphin
488 * instead as modal error dialog with an OK button.
489 */
490 class UndoUiInterface : public KonqFileUndoManager::UiInterface
491 {
492 public:
493 UndoUiInterface(DolphinMainWindow* mainWin);
494 virtual ~UndoUiInterface();
495 virtual void jobError(KIO::Job* job);
496
497 private:
498 DolphinMainWindow* m_mainWin;
499 };
500
501 KNewMenu* m_newMenu;
502 QSplitter* m_splitter;
503 DolphinViewContainer* m_activeViewContainer;
504 int m_id;
505
506 DolphinViewContainer* m_viewContainer[SecondaryView + 1];
507
508 /// remember pending undo operations until they are finished
509 QList<KonqFileUndoManager::CommandType> m_undoCommandTypes;
510 };
511
512 inline DolphinViewContainer* DolphinMainWindow::activeViewContainer() const
513 {
514 return m_activeViewContainer;
515 }
516
517 inline bool DolphinMainWindow::isSplit() const
518 {
519 return m_viewContainer[SecondaryView] != 0;
520 }
521
522 inline KNewMenu* DolphinMainWindow::newMenu() const
523 {
524 return m_newMenu;
525 }
526
527 inline int DolphinMainWindow::getId() const
528 {
529 return m_id;
530 }
531
532 #endif // DOLPHIN_MAINWINDOW_H
533