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