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