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