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