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