]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.h
split view on startup if it is defined by the settings
[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 from the places model
195 * in the status bar.
196 */
197 void slotHandlePlacesError(const QString &message);
198
199 /**
200 * Shows the error information of the job \a job
201 * in the status bar.
202 */
203 void slotHandleJobError(KJob* job);
204
205 /**
206 * Indicates in the status bar that the delete operation
207 * of the job \a job has been finished.
208 */
209 void slotDeleteFileFinished(KJob* job);
210
211 /**
212 * Updates the state of the 'Undo' menu action dependent
213 * from the parameter \a available.
214 */
215 void slotUndoAvailable(bool available);
216
217 /** Sets the text of the 'Undo' menu action to \a text. */
218 void slotUndoTextChanged(const QString& text);
219
220 /** Performs the current undo operation. */
221 void undo();
222
223 /**
224 * Copies all selected items to the clipboard and marks
225 * the items as cutted.
226 */
227 void cut();
228
229 /** Copies all selected items to the clipboard. */
230 void copy();
231
232 /** Pastes the clipboard data to the active view. */
233 void paste();
234
235 /**
236 * Updates the text of the paste action dependent from
237 * the number of items which are in the clipboard.
238 */
239 void updatePasteAction();
240
241 /** Selects all items from the active view. */
242 void selectAll();
243
244 /**
245 * Inverts the selection of all items of the active view:
246 * Selected items get nonselected and nonselected items get
247 * selected.
248 */
249 void invertSelection();
250
251 /** The current active view is switched to the icons mode. */
252 void setIconsView();
253
254 /** The current active view is switched to the details mode. */
255 void setDetailsView();
256
257 /** The current active view is switched to the column mode. */
258 void setColumnView();
259
260 /** The sorting of the current view should be done by the name. */
261 void sortByName();
262
263 /** The sorting of the current view should be done by the size. */
264 void sortBySize();
265
266 /** The sorting of the current view should be done by the date. */
267 void sortByDate();
268
269 /** The sorting of the current view should be done by the permissions. */
270 void sortByPermissions();
271
272 /** The sorting of the current view should be done by the owner. */
273 void sortByOwner();
274
275 /** The sorting of the current view should be done by the group. */
276 void sortByGroup();
277
278 /** The sorting of the current view should be done by the type. */
279 void sortByType();
280
281 /** Switches between an ascending and descending sorting order. */
282 void toggleSortOrder();
283
284 /** Switches between sorting by categories or not. */
285 void toggleSortCategorization();
286
287 /**
288 * Clears any additional information for an item except for the
289 * name and the icon.
290 */
291 void clearInfo();
292
293 /** Shows the MIME type as additional information for the item. */
294 void showMimeInfo();
295
296 /** Shows the size as additional information for the item. */
297 void showSizeInfo();
298
299 /** Shows the date as additional information for the item. */
300 void showDateInfo();
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 /** Opens the settings dialog for Dolphin. */
372 void editSettings();
373
374 /** Updates the state of all 'View' menu actions. */
375 void slotViewModeChanged();
376
377 /** Updates the state of the 'Show preview' menu action. */
378 void slotShowPreviewChanged();
379
380 /** Updates the state of the 'Show hidden files' menu action. */
381 void slotShowHiddenFilesChanged();
382
383 /** Updates the state of the 'Categorized sorting' menu action. */
384 void slotCategorizedSortingChanged();
385
386 /** Updates the state of the 'Sort by' actions. */
387 void slotSortingChanged(DolphinView::Sorting sorting);
388
389 /** Updates the state of the 'Sort Ascending/Descending' action. */
390 void slotSortOrderChanged(Qt::SortOrder order);
391
392 /** Updates the state of the 'Additional Information' actions. */
393 void slotAdditionalInfoChanged(KFileItemDelegate::AdditionalInformation info);
394
395 /**
396 * Updates the state of the 'Edit' menu actions and emits
397 * the signal selectionChanged().
398 */
399 void slotSelectionChanged(const KFileItemList& selection);
400
401 /** Emits the signal requestItemInfo(). */
402 void slotRequestItemInfo(const KUrl& url);
403
404 /**
405 * Updates the state of the 'Back' and 'Forward' menu
406 * actions corresponding the the current history.
407 */
408 void slotHistoryChanged();
409
410 /** Updates the state of the 'Show filter bar' menu action. */
411 void updateFilterBarAction(bool show);
412
413 /** Open a new main window. */
414 void openNewMainWindow();
415
416 /** Toggles the active view if two views are shown within the main window. */
417 void toggleActiveView();
418
419 private:
420 DolphinMainWindow(int id);
421 void init();
422
423 /**
424 * Activates the given view, which means that
425 * all menu actions are applied to this view. When
426 * having a split view setup, the nonactive view
427 * is usually shown in darker colors.
428 */
429 void setActiveViewContainer(DolphinViewContainer* view);
430
431 void setupActions();
432 void setupDockWidgets();
433 void updateHistory();
434 void updateEditActions();
435 void updateViewActions();
436 void updateGoActions();
437 void copyUrls(const KUrl::List& source, const KUrl& dest);
438 void moveUrls(const KUrl::List& source, const KUrl& dest);
439 void linkUrls(const KUrl::List& source, const KUrl& dest);
440 void clearStatusBar();
441
442 /**
443 * Connects the signals from the created DolphinView with
444 * the index \a viewIndex with the corresponding slots of
445 * the DolphinMainWindow. This method must be invoked each
446 * time a DolphinView has been created.
447 */
448 void connectViewSignals(int viewIndex);
449
450 /**
451 * Updates the text of the split action:
452 * If \a isSplit is true, the text is set to "Split",
453 * otherwise the text is set to "Join". The icon
454 * is updated to match with the text.
455 */
456 void updateSplitAction(bool isSplit);
457
458 private:
459 /**
460 * DolphinMainWindow supports up to two views beside each other.
461 */
462 enum ViewIndex
463 {
464 PrimaryView = 0, ///< View shown on the left side of the main window.
465 SecondaryView = 1 ///< View shown on the left side of the main window.
466 };
467
468 /**
469 * Implements a custom error handling for the undo manager. This
470 * assures that all errors are shown in the status bar of Dolphin
471 * instead as modal error dialog with an OK button.
472 */
473 class UndoUiInterface : public KonqUndoManager::UiInterface
474 {
475 public:
476 UndoUiInterface(DolphinMainWindow* mainWin);
477 virtual ~UndoUiInterface();
478 virtual void jobError(KIO::Job* job);
479
480 private:
481 DolphinMainWindow* m_mainWin;
482 };
483
484 KNewMenu* m_newMenu;
485 QSplitter* m_splitter;
486 DolphinViewContainer* m_activeViewContainer;
487 int m_id;
488
489 DolphinViewContainer* m_viewContainer[SecondaryView + 1];
490
491 /// remember pending undo operations until they are finished
492 QList<KonqUndoManager::CommandType> m_undoCommandTypes;
493 };
494
495 DolphinViewContainer* DolphinMainWindow::activeViewContainer() const
496 {
497 return m_activeViewContainer;
498 }
499
500 bool DolphinMainWindow::isSplit() const
501 {
502 return m_viewContainer[SecondaryView] != 0;
503 }
504
505 KNewMenu* DolphinMainWindow::newMenu() const
506 {
507 return m_newMenu;
508 }
509
510 int DolphinMainWindow::getId() const
511 {
512 return m_id;
513 }
514
515 #endif // DOLPHIN_MAINWINDOW_H
516