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