]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.h
Adapt Dolphin Nepomuk support to namespace changes.
[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 * Activates the given view, which means that
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 void setActiveView(DolphinViewContainer* view);
62
63 /**
64 * Returns the currently active view. See
65 * DolphinMainWindow::setActiveView() for more details.
66 */
67 DolphinViewContainer* activeViewContainer() const
68 {
69 return m_activeViewContainer;
70 }
71
72 /** Renames the item represented by \a oldUrl to \a newUrl. */
73 void rename(const KUrl& oldUrl, const KUrl& newUrl);
74
75 /**
76 * Refreshs the views of the main window by recreating them dependent from
77 * the given Dolphin settings.
78 */
79 void refreshViews();
80
81 /**
82 * Returns the 'Create New...' sub menu which also can be shared
83 * with other menus (e. g. a context menu).
84 */
85 KNewMenu* newMenu() const
86 {
87 return m_newMenu;
88 }
89
90 public slots:
91 /**
92 * Handles the dropping of URLs to the given
93 * destination. A context menu with the options
94 * 'Move Here', 'Copy Here', 'Link Here' and
95 * 'Cancel' is offered to the user.
96 * @param urls List of URLs which have been
97 * dropped.
98 * @param destination Destination URL, where the
99 * list or URLs should be moved,
100 * copied or linked to.
101 */
102 void dropUrls(const KUrl::List& urls,
103 const KUrl& destination);
104
105 /**
106 * Returns the main window ID used through DBus.
107 */
108 int getId() const
109 {
110 return m_id;
111 }
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 of the job \a job
195 * in the status bar.
196 */
197 void slotHandleJobError(KJob* job);
198
199 /**
200 * Indicates in the status bar that the delete operation
201 * of the job \a job has been finished.
202 */
203 void slotDeleteFileFinished(KJob* job);
204
205 /**
206 * Updates the state of the 'Undo' menu action dependent
207 * from the parameter \a available.
208 */
209 void slotUndoAvailable(bool available);
210
211 /** Sets the text of the 'Undo' menu action to \a text. */
212 void slotUndoTextChanged(const QString& text);
213
214 /** Performs the current undo operation. */
215 void undo();
216
217 /**
218 * Copies all selected items to the clipboard and marks
219 * the items as cutted.
220 */
221 void cut();
222
223 /** Copies all selected items to the clipboard. */
224 void copy();
225
226 /** Pastes the clipboard data to the active view. */
227 void paste();
228
229 /**
230 * Updates the text of the paste action dependent from
231 * the number of items which are in the clipboard.
232 */
233 void updatePasteAction();
234
235 /** Selects all items from the active view. */
236 void selectAll();
237
238 /**
239 * Inverts the selection of all items of the active view:
240 * Selected items get nonselected and nonselected items get
241 * selected.
242 */
243 void invertSelection();
244
245 /** The current active view is switched to the icons mode. */
246 void setIconsView();
247
248 /** The current active view is switched to the details mode. */
249 void setDetailsView();
250
251 /** The current active view is switched to the column mode. */
252 void setColumnView();
253
254 /** The sorting of the current view should be done by the name. */
255 void sortByName();
256
257 /** The sorting of the current view should be done by the size. */
258 void sortBySize();
259
260 /** The sorting of the current view should be done by the date. */
261 void sortByDate();
262
263 /** The sorting of the current view should be done by the permissions. */
264 void sortByPermissions();
265
266 /** The sorting of the current view should be done by the owner. */
267 void sortByOwner();
268
269 /** The sorting of the current view should be done by the group. */
270 void sortByGroup();
271
272 /** The sorting of the current view should be done by the type. */
273 void sortByType();
274
275 /** Switches between an ascending and descending sorting order. */
276 void toggleSortOrder();
277
278 /** Switches between sorting by categories or not. */
279 void toggleSortCategorization();
280
281 /**
282 * Clears any additional information for an item except for the
283 * name and the icon.
284 */
285 void clearInfo();
286
287 /** Shows the MIME type as additional information for the item. */
288 void showMimeInfo();
289
290 /** Shows the size as additional information for the item. */
291 void showSizeInfo();
292
293 /** Shows the date as additional information for the item. */
294 void showDateInfo();
295
296 /**
297 * Switches between one and two views:
298 * If one view is visible, it will get split into two views.
299 * If already two views are visible, the nonactivated view gets closed.
300 */
301 void toggleSplitView();
302
303 /** Reloads the current active view. */
304 void reloadView();
305
306 /** Stops the loading process for the current active view. */
307 void stopLoading();
308
309 /** Switches between showing a preview of the file content and showing the icon. */
310 void togglePreview();
311
312 /**
313 * Switches between showing and hiding of hidden marked files dependent
314 * from the current state of the 'Show Hidden Files' menu toggle action.
315 */
316 void toggleShowHiddenFiles();
317
318 /**
319 * Toggles between showing and hiding of the filter bar dependent
320 * from the current state of the 'Show Filter Bar' menu toggle action.
321 */
322 void toggleFilterBarVisibility();
323
324 /** Increases the size of the current set view mode. */
325 void zoomIn();
326
327 /** Decreases the size of the current set view mode. */
328 void zoomOut();
329
330 /**
331 * Toggles between edit and brose mode of the navigation bar.
332 */
333 void toggleEditLocation();
334
335 /**
336 * Switches to the edit mode of the navigation bar. If the edit mode is
337 * already active, it is assured that the navigation bar get focused.
338 */
339 void editLocation();
340
341 /**
342 * Opens the view properties dialog, which allows to modify the properties
343 * of the currently active view.
344 */
345 void adjustViewProperties();
346
347 /** Goes back on step of the URL history. */
348 void goBack();
349
350 /** Goes forward one step of the URL history. */
351 void goForward();
352
353 /** Goes up one hierarchy of the current URL. */
354 void goUp();
355
356 /** Goes to the home URL. */
357 void goHome();
358
359 /** Opens KFind for the current shown directory. */
360 void findFile();
361
362 /** Opens Kompare for 2 selected files. */
363 void compareFiles();
364
365 /** Opens the settings dialog for Dolphin. */
366 void editSettings();
367
368 /** Updates the state of all 'View' menu actions. */
369 void slotViewModeChanged();
370
371 /** Updates the state of the 'Show preview' menu action. */
372 void slotShowPreviewChanged();
373
374 /** Updates the state of the 'Show hidden files' menu action. */
375 void slotShowHiddenFilesChanged();
376
377 /** Updates the state of the 'Categorized sorting' menu action. */
378 void slotCategorizedSortingChanged();
379
380 /** Updates the state of the 'Sort by' actions. */
381 void slotSortingChanged(DolphinView::Sorting sorting);
382
383 /** Updates the state of the 'Sort Ascending/Descending' action. */
384 void slotSortOrderChanged(Qt::SortOrder order);
385
386 /** Updates the state of the 'Additional Information' actions. */
387 void slotAdditionalInfoChanged(KFileItemDelegate::AdditionalInformation info);
388
389 /**
390 * Updates the state of the 'Edit' menu actions and emits
391 * the signal selectionChanged().
392 */
393 void slotSelectionChanged(const KFileItemList& selection);
394
395 /** Emits the signal requestItemInfo(). */
396 void slotRequestItemInfo(const KUrl& url);
397
398 /**
399 * Updates the state of the 'Back' and 'Forward' menu
400 * actions corresponding the the current history.
401 */
402 void slotHistoryChanged();
403
404 /** Updates the state of the 'Show filter bar' menu action. */
405 void updateFilterBarAction(bool show);
406
407 /** Open a new main window. */
408 void openNewMainWindow();
409
410 /** Toggles the active view if two views are shown within the main window. */
411 void toggleActiveView();
412
413 private:
414 DolphinMainWindow(int id);
415 void init();
416 void loadSettings();
417
418 void setupAccel();
419 void setupActions();
420 void setupDockWidgets();
421 void updateHistory();
422 void updateEditActions();
423 void updateViewActions();
424 void updateGoActions();
425 void copyUrls(const KUrl::List& source, const KUrl& dest);
426 void moveUrls(const KUrl::List& source, const KUrl& dest);
427 void linkUrls(const KUrl::List& source, const KUrl& dest);
428 void clearStatusBar();
429
430 /**
431 * Connects the signals from the created DolphinView with
432 * the index \a viewIndex with the corresponding slots of
433 * the DolphinMainWindow. This method must be invoked each
434 * time a DolphinView has been created.
435 */
436 void connectViewSignals(int viewIndex);
437
438 /**
439 * Updates the text of the split action:
440 * If \a isSplit is true, the text is set to "Split",
441 * otherwise the text is set to "Join". The icon
442 * is updated to match with the text.
443 */
444 void updateSplitAction(bool isSplit);
445
446 private:
447 /**
448 * DolphinMainWindowsupports only one or two views, which
449 * are handled internally as primary and secondary view.
450 */
451 enum ViewIndex
452 {
453 PrimaryIdx = 0,
454 SecondaryIdx = 1
455 };
456
457 /**
458 * Implements a custom error handling for the undo manager. This
459 * assures that all errors are shown in the status bar of Dolphin
460 * instead as modal error dialog with an OK button.
461 */
462 class UndoUiInterface : public KonqUndoManager::UiInterface
463 {
464 public:
465 UndoUiInterface(DolphinMainWindow* mainWin);
466 virtual ~UndoUiInterface();
467 virtual void jobError(KIO::Job* job);
468
469 private:
470 DolphinMainWindow* m_mainWin;
471 };
472
473 KNewMenu* m_newMenu;
474 QSplitter* m_splitter;
475 DolphinViewContainer* m_activeViewContainer;
476 int m_id;
477
478 DolphinViewContainer* m_viewContainer[SecondaryIdx + 1];
479
480 /// remember pending undo operations until they are finished
481 QList<KonqUndoManager::CommandType> m_undoCommandTypes;
482 };
483
484 #endif // DOLPHIN_MAINWINDOW_H
485