]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.h
adapt Dolphin to kdelibs coding style (http://techbase.kde.org/Policies/Kdelibs_Codin...
[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
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 protected:
147 /** @see QMainWindow::closeEvent */
148 virtual void closeEvent(QCloseEvent* event);
149
150 /**
151 * This method is called when it is time for the app to save its
152 * properties for session management purposes.
153 */
154 void saveProperties(KConfig*);
155
156 /**
157 * This method is called when this app is restored. The KConfig
158 * object points to the session management config file that was saved
159 * with @ref saveProperties
160 */
161 void readProperties(KConfig*);
162
163 private slots:
164 /** Updates the 'Create New...' sub menu. */
165 void updateNewMenu();
166
167 /**
168 * Let the user input a name for the selected item(s) and trigger
169 * a renaming afterwards.
170 */
171 void rename();
172
173 /** Moves the selected items of the active view to the trash. */
174 void moveToTrash();
175
176 /** Deletes the selected items of the active view. */
177 void deleteItems();
178
179 /**
180 * Opens the properties window for the selected items of the
181 * active view. The properties windows shows informations
182 * like name, size and permissions.
183 */
184 void properties();
185
186 /**
187 * Shows the error information of the job \a job
188 * in the status bar.
189 */
190 void slotHandleJobError(KJob* job);
191
192 /**
193 * Indicates in the status bar that the delete operation
194 * of the job \a job has been finished.
195 */
196 void slotDeleteFileFinished(KJob* job);
197
198 /**
199 * Updates the state of the 'Undo' menu action dependent
200 * from the parameter \a available.
201 */
202 void slotUndoAvailable(bool available);
203
204 /** Sets the text of the 'Undo' menu action to \a text. */
205 void slotUndoTextChanged(const QString& text);
206
207 /** Performs the current undo operation. */
208 void undo();
209
210 /**
211 * Copies all selected items to the clipboard and marks
212 * the items as cutted.
213 */
214 void cut();
215
216 /** Copies all selected items to the clipboard. */
217 void copy();
218
219 /** Pastes the clipboard data to the active view. */
220 void paste();
221
222 /**
223 * Updates the text of the paste action dependent from
224 * the number of items which are in the clipboard.
225 */
226 void updatePasteAction();
227
228 /** Selects all items from the active view. */
229 void selectAll();
230
231 /**
232 * Inverts the selection of all items of the active view:
233 * Selected items get nonselected and nonselected items get
234 * selected.
235 */
236 void invertSelection();
237
238 /** The current active view is switched to the icons mode. */
239 void setIconsView();
240
241 /** The current active view is switched to the details mode. */
242 void setDetailsView();
243
244 /** The current active view is switched to the column mode. */
245 void setColumnView();
246
247 /** The sorting of the current view should be done by the name. */
248 void sortByName();
249
250 /** The sorting of the current view should be done by the size. */
251 void sortBySize();
252
253 /** The sorting of the current view should be done by the date. */
254 void sortByDate();
255
256 /** The sorting of the current view should be done by the permissions. */
257 void sortByPermissions();
258
259 /** The sorting of the current view should be done by the owner. */
260 void sortByOwner();
261
262 /** The sorting of the current view should be done by the group. */
263 void sortByGroup();
264
265 /** Switches between an ascending and descending sorting order. */
266 void toggleSortOrder();
267
268 /**
269 * Clears any additional information for an item except for the
270 * name and the icon.
271 */
272 void clearInfo();
273
274 /** Shows the MIME type as additional information for the item. */
275 void showMimeInfo();
276
277 /** Shows the size as additional information for the item. */
278 void showSizeInfo();
279
280 /** Shows the date as additional information for the item. */
281 void showDateInfo();
282
283 /**
284 * Switches between one and two views:
285 * If one view is visible, it will get split into two views.
286 * If already two views are visible, the nonactivated view gets closed.
287 */
288 void toggleSplitView();
289
290 /** Reloads the current active view. */
291 void reloadView();
292
293 /** Stops the loading process for the current active view. */
294 void stopLoading();
295
296 /** Switches between showing a preview of the file content and showing the icon. */
297 void togglePreview();
298
299 /**
300 * Switches between showing and hiding of hidden marked files dependent
301 * from the current state of the 'Show Hidden Files' menu toggle action.
302 */
303 void toggleShowHiddenFiles();
304
305 /**
306 * Switches between showing and hiding of the filter bar dependent
307 * from the current state of the 'Show Filter Bar' menu toggle action.
308 */
309 void showFilterBar();
310
311 /** Increases the size of the current set view mode. */
312 void zoomIn();
313
314 /** Decreases the size of the current set view mode. */
315 void zoomOut();
316
317 /**
318 * Toggles between edit and brose mode of the navigation bar.
319 */
320 void toggleEditLocation();
321
322 /**
323 * Switches to the edit mode of the navigation bar. If the edit mode is
324 * already active, it is assured that the navigation bar get focused.
325 */
326 void editLocation();
327
328 /**
329 * Opens the view properties dialog, which allows to modify the properties
330 * of the currently active view.
331 */
332 void adjustViewProperties();
333
334 /** Goes back on step of the URL history. */
335 void goBack();
336
337 /** Goes forward one step of the URL history. */
338 void goForward();
339
340 /** Goes up one hierarchy of the current URL. */
341 void goUp();
342
343 /** Goes to the home URL. */
344 void goHome();
345
346 /** Opens a terminal for the current shown directory. */
347 void openTerminal();
348
349 /** Opens KFind for the current shown directory. */
350 void findFile();
351
352 /** Opens Kompare for 2 selected files. */
353 void compareFiles();
354
355 /** Opens the settings dialog for Dolphin. */
356 void editSettings();
357
358 /** Updates the state of all 'View' menu actions. */
359 void slotViewModeChanged();
360
361 /** Updates the state of the 'Show preview' menu action. */
362 void slotShowPreviewChanged();
363
364 /** Updates the state of the 'Show hidden files' menu action. */
365 void slotShowHiddenFilesChanged();
366
367 /** Updates the state of the 'Sort by' actions. */
368 void slotSortingChanged(DolphinView::Sorting sorting);
369
370 /** Updates the state of the 'Sort Ascending/Descending' action. */
371 void slotSortOrderChanged(Qt::SortOrder order);
372
373 /** Updates the state of the 'Additional Information' actions. */
374 void slotAdditionalInfoChanged(KFileItemDelegate::AdditionalInformation info);
375
376 /** Updates the state of the 'Edit' menu actions. */
377 void slotSelectionChanged(const KFileItemList& selection);
378
379 /**
380 * Updates the state of the 'Back' and 'Forward' menu
381 * actions corresponding the the current history.
382 */
383 void slotHistoryChanged();
384
385 /** Updates the state of the 'Show filter bar' menu action. */
386 void updateFilterBarAction(bool show);
387
388 /** Open a new main window. */
389 void openNewMainWindow();
390
391 private:
392 DolphinMainWindow(int id);
393 void init();
394 void loadSettings();
395
396 void setupAccel();
397 void setupActions();
398 void setupDockWidgets();
399 void updateHistory();
400 void updateEditActions();
401 void updateViewActions();
402 void updateGoActions();
403 void copyUrls(const KUrl::List& source, const KUrl& dest);
404 void moveUrls(const KUrl::List& source, const KUrl& dest);
405 void linkUrls(const KUrl::List& source, const KUrl& dest);
406 void clearStatusBar();
407
408 /**
409 * Connects the signals from the created DolphinView with
410 * the index \a viewIndex with the corresponding slots of
411 * the DolphinMainWindow. This method must be invoked each
412 * time a DolphinView has been created.
413 */
414 void connectViewSignals(int viewIndex);
415
416 /**
417 * Helper function to connect all signal/slots of the given \sidebar.
418 */
419 void connectSidebarPage(SidebarPage* sidebar);
420
421 private:
422 /**
423 * DolphinMainWindowsupports only one or two views, which
424 * are handled internally as primary and secondary view.
425 */
426 enum ViewIndex
427 {
428 PrimaryIdx = 0,
429 SecondaryIdx = 1
430 };
431
432 /**
433 * Implements a custom error handling for the undo manager. This
434 * assures that all errors are shown in the status bar of Dolphin
435 * instead as modal error dialog with an OK button.
436 */
437 class UndoUiInterface : public KonqUndoManager::UiInterface
438 {
439 public:
440 UndoUiInterface(DolphinMainWindow* mainWin);
441 virtual ~UndoUiInterface();
442 virtual void jobError(KIO::Job* job);
443
444 private:
445 DolphinMainWindow* m_mainWin;
446 };
447
448 KNewMenu* m_newMenu;
449 QSplitter* m_splitter;
450 DolphinView* m_activeView;
451 int m_id;
452
453 DolphinView* m_view[SecondaryIdx + 1];
454
455 /// remember pending undo operations until they are finished
456 QList<KonqUndoManager::CommandType> m_undoCommandTypes;
457 };
458
459 #endif // DOLPHIN_MAINWINDOW_H
460