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