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