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