]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.h
Forwardport 773570:
[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 <config-nepomuk.h>
29
30 #include <kfileitemdelegate.h>
31 #include <konq_fileundomanager.h>
32 #include <ksortablelist.h>
33 #include <kxmlguiwindow.h>
34
35 #include <QtCore/QList>
36
37 class DolphinViewActionHandler;
38 class DolphinApplication;
39 class DolphinViewContainer;
40 class KNewMenu;
41 class KUrl;
42 class QSplitter;
43
44 /**
45 * @short Main window for Dolphin.
46 *
47 * Handles the menus, toolbars and Dolphin views.
48 */
49 class DolphinMainWindow: public KXmlGuiWindow
50 {
51 Q_OBJECT
52 Q_CLASSINFO("D-Bus Interface", "org.kde.dolphin.MainWindow")
53 Q_PROPERTY(int id READ getId SCRIPTABLE true)
54 friend class DolphinApplication;
55
56 public:
57 virtual ~DolphinMainWindow();
58
59 /**
60 * Returns the currently active view.
61 * All menu actions are applied to this view. When
62 * having a split view setup, the nonactive view
63 * is usually shown in darker colors.
64 */
65 DolphinViewContainer* activeViewContainer() const;
66
67 /**
68 * Returns true, if the main window contains two instances
69 * of a view container. The active view constainer can be
70 * accessed by DolphinMainWindow::activeViewContainer().
71 */
72 bool isSplit() const;
73
74 /**
75 * If the main window contains two instances of a view container
76 * (DolphinMainWindow::isSplit() returns true), then the
77 * two views get toggled (the right view is on the left, the left
78 * view on the right).
79 */
80 void toggleViews();
81
82 /** Renames the item represented by \a oldUrl to \a newUrl. */
83 void rename(const KUrl& oldUrl, const KUrl& newUrl);
84
85 /**
86 * Refreshes the views of the main window by recreating them dependent from
87 * the given Dolphin settings.
88 */
89 void refreshViews();
90
91 /**
92 * Returns the 'Create New...' sub menu which also can be shared
93 * with other menus (e. g. a context menu).
94 */
95 KNewMenu* newMenu() const;
96
97 /**
98 * Returns the 'Show Menubar' action which can be shared with
99 * other menus (e. g. a context menu).
100 */
101 KAction* showMenuBarAction() const;
102
103 public slots:
104 /**
105 * Handles the dropping of URLs to the given
106 * destination. This is only called by the TreeViewSidebarPage.
107 */
108 void dropUrls(const KUrl::List& urls,
109 const KUrl& destination);
110
111 /**
112 * Returns the main window ID used through DBus.
113 */
114 int getId() const;
115
116 /**
117 * Inform all affected dolphin components (sidebars, views) of an URL
118 * change.
119 */
120 void changeUrl(const KUrl& url);
121
122 /**
123 * Inform all affected dolphin components that a selection change is
124 * requested.
125 */
126 void changeSelection(const KFileItemList& selection);
127
128 /** Stores all settings and quits Dolphin. */
129 void quit();
130
131 signals:
132 /**
133 * Is send if the active view has been changed in
134 * the split view mode.
135 */
136 void activeViewChanged();
137
138 /**
139 * Is sent if the selection of the currently active view has
140 * been changed.
141 */
142 void selectionChanged(const KFileItemList& selection);
143
144 /**
145 * Is sent if the url of the currently active view has
146 * been changed.
147 */
148 void urlChanged(const KUrl& url);
149
150 /**
151 * Is emitted if information of an item is requested to be shown e. g. in the sidebar.
152 * If item is null, no item information request is pending.
153 */
154 void requestItemInfo(const KFileItem& item);
155
156 protected:
157 /** @see QMainWindow::closeEvent() */
158 virtual void closeEvent(QCloseEvent* event);
159
160 /** @see KMainWindow::saveProperties() */
161 virtual void saveProperties(KConfigGroup& group);
162
163 /** @see KMainWindow::readProperties() */
164 virtual void readProperties(const KConfigGroup& group);
165
166 private slots:
167 void clearStatusBar();
168
169 /** Updates the 'Create New...' sub menu. */
170 void updateNewMenu();
171
172 /**
173 * Opens the properties window for the selected items of the
174 * active view. The properties windows shows information
175 * like name, size and permissions.
176 */
177 void properties();
178
179 /**
180 * Shows the error information from the places model
181 * in the status bar.
182 */
183 void slotHandlePlacesError(const QString &message);
184
185 /**
186 * Updates the state of the 'Undo' menu action dependent
187 * from the parameter \a available.
188 */
189 void slotUndoAvailable(bool available);
190
191 /** Sets the text of the 'Undo' menu action to \a text. */
192 void slotUndoTextChanged(const QString& text);
193
194 /** Performs the current undo operation. */
195 void undo();
196
197 /**
198 * Copies all selected items to the clipboard and marks
199 * the items as cutted.
200 */
201 void cut();
202
203 /** Copies all selected items to the clipboard. */
204 void copy();
205
206 /** Pastes the clipboard data to the active view. */
207 void paste();
208
209 /**
210 * Updates the text of the paste action dependent from
211 * the number of items which are in the clipboard.
212 */
213 void updatePasteAction();
214
215 /** Selects all items from the active view. */
216 void selectAll();
217
218 /**
219 * Inverts the selection of all items of the active view:
220 * Selected items get nonselected and nonselected items get
221 * selected.
222 */
223 void invertSelection();
224
225 /** The current active view is switched to a new view mode. */
226 void setViewMode(QAction *);
227
228 /** The sorting of the current view should be done by the name. */
229 void sortByName();
230
231 /** The sorting of the current view should be done by the size. */
232 void sortBySize();
233
234 /** The sorting of the current view should be done by the date. */
235 void sortByDate();
236
237 /** The sorting of the current view should be done by the permissions. */
238 void sortByPermissions();
239
240 /** The sorting of the current view should be done by the owner. */
241 void sortByOwner();
242
243 /** The sorting of the current view should be done by the group. */
244 void sortByGroup();
245
246 /** The sorting of the current view should be done by the type. */
247 void sortByType();
248
249 /** The sorting of the current view should be done by the rating. */
250 void sortByRating();
251
252 /** The sorting of the current view should be done by tags. */
253 void sortByTags();
254
255 /**
256 * Switches between one and two views:
257 * If one view is visible, it will get split into two views.
258 * If already two views are visible, the nonactivated view gets closed.
259 */
260 void toggleSplitView();
261
262 /** Reloads the current active view. */
263 void reloadView();
264
265 /** Stops the loading process for the current active view. */
266 void stopLoading();
267
268 /**
269 * Toggles between showing and hiding of the filter bar
270 */
271 void toggleFilterBarVisibility(bool show);
272
273 /**
274 * Toggles between edit and browse mode of the navigation bar.
275 */
276 void toggleEditLocation();
277
278 /**
279 * Switches to the edit mode of the navigation bar. If the edit mode is
280 * already active, it is assured that the navigation bar get focused.
281 */
282 void editLocation();
283
284 /**
285 * Opens the view properties dialog, which allows to modify the properties
286 * of the currently active view.
287 */
288 void adjustViewProperties();
289
290 /** Goes back on step of the URL history. */
291 void goBack();
292
293 /** Goes forward one step of the URL history. */
294 void goForward();
295
296 /** Goes up one hierarchy of the current URL. */
297 void goUp();
298
299 /** Goes to the home URL. */
300 void goHome();
301
302 /** Opens KFind for the current shown directory. */
303 void findFile();
304
305 /** Opens Kompare for 2 selected files. */
306 void compareFiles();
307
308 /**
309 * Hides the menu bar if it is visible, makes the menu bar
310 * visible if it is hidden.
311 */
312 void toggleShowMenuBar();
313
314 /** Opens the settings dialog for Dolphin. */
315 void editSettings();
316
317 /** Updates the state of all 'View' menu actions. */
318 void slotViewModeChanged();
319
320 /** Updates the state of the 'Sort by' actions. */
321 void slotSortingChanged(DolphinView::Sorting sorting);
322
323 /** Updates the state of the 'Show Full Location' action. */
324 void slotEditableStateChanged(bool editable);
325
326 /**
327 * Updates the state of the 'Edit' menu actions and emits
328 * the signal selectionChanged().
329 */
330 void slotSelectionChanged(const KFileItemList& selection);
331
332 /** Emits the signal requestItemInfo(). */
333 void slotRequestItemInfo(const KFileItem&);
334
335 /**
336 * Updates the state of the 'Back' and 'Forward' menu
337 * actions corresponding the the current history.
338 */
339 void slotHistoryChanged();
340
341 /** Updates the state of the 'Show filter bar' menu action. */
342 void updateFilterBarAction(bool show);
343
344 /** Open a new main window. */
345 void openNewMainWindow();
346
347 /** Toggles the active view if two views are shown within the main window. */
348 void toggleActiveView();
349
350 /** Called when the view is doing a file operation, like renaming, copying, moving etc. */
351 void slotDoingOperation(KonqFileUndoManager::CommandType type);
352
353 private:
354 DolphinMainWindow(int id);
355 void init();
356
357 /**
358 * Activates the given view, which means that
359 * all menu actions are applied to this view. When
360 * having a split view setup, the nonactive view
361 * is usually shown in darker colors.
362 */
363 void setActiveViewContainer(DolphinViewContainer* view);
364
365 void setupActions();
366 void setupDockWidgets();
367 void updateHistory();
368 void updateEditActions();
369 void updateViewActions();
370 void updateGoActions();
371
372 /**
373 * Connects the signals from the created DolphinView with
374 * the index \a viewIndex with the corresponding slots of
375 * the DolphinMainWindow. This method must be invoked each
376 * time a DolphinView has been created.
377 */
378 void connectViewSignals(int viewIndex);
379
380 /**
381 * Updates the text of the split action:
382 * If two views are shown, the text is set to "Split",
383 * otherwise the text is set to "Join". The icon
384 * is updated to match with the text and the currently active view.
385 */
386 void updateSplitAction();
387
388 private:
389 /**
390 * DolphinMainWindow supports up to two views beside each other.
391 */
392 enum ViewIndex
393 {
394 PrimaryView = 0, ///< View shown on the left side of the main window.
395 SecondaryView = 1 ///< View shown on the left side of the main window.
396 };
397
398 /**
399 * Implements a custom error handling for the undo manager. This
400 * assures that all errors are shown in the status bar of Dolphin
401 * instead as modal error dialog with an OK button.
402 */
403 class UndoUiInterface : public KonqFileUndoManager::UiInterface
404 {
405 public:
406 UndoUiInterface(DolphinMainWindow* mainWin);
407 virtual ~UndoUiInterface();
408 virtual void jobError(KIO::Job* job);
409
410 private:
411 DolphinMainWindow* m_mainWin;
412 };
413
414 KNewMenu* m_newMenu;
415 KAction* m_showMenuBar;
416 QSplitter* m_splitter;
417 DolphinViewContainer* m_activeViewContainer;
418 int m_id;
419
420 DolphinViewContainer* m_viewContainer[SecondaryView + 1];
421
422 DolphinViewActionHandler* m_actionHandler;
423
424 /// remember pending undo operations until they are finished
425 QList<KonqFileUndoManager::CommandType> m_undoCommandTypes;
426 };
427
428 inline DolphinViewContainer* DolphinMainWindow::activeViewContainer() const
429 {
430 return m_activeViewContainer;
431 }
432
433 inline bool DolphinMainWindow::isSplit() const
434 {
435 return m_viewContainer[SecondaryView] != 0;
436 }
437
438 inline KNewMenu* DolphinMainWindow::newMenu() const
439 {
440 return m_newMenu;
441 }
442
443 inline KAction* DolphinMainWindow::showMenuBarAction() const
444 {
445 return m_showMenuBar;
446 }
447
448 inline int DolphinMainWindow::getId() const
449 {
450 return m_id;
451 }
452
453 #endif // DOLPHIN_MAINWINDOW_H
454