]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.h
The mouse wheel now works on Dolphin's tabs (to switch tabs), like just about every...
[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
35 #include <QtCore/QList>
36
37 typedef KIO::FileUndoManager::CommandType CommandType;
38
39 class KAction;
40 class DolphinViewActionHandler;
41 class DolphinApplication;
42 class DolphinSearchBox;
43 class DolphinSettingsDialog;
44 class DolphinViewContainer;
45 class KNewMenu;
46 class KTabBar;
47 class KUrl;
48 class QDropEvent;
49 class QSplitter;
50
51 /**
52 * @short Main window for Dolphin.
53 *
54 * Handles the menus, toolbars and Dolphin views.
55 */
56 class DolphinMainWindow: public KXmlGuiWindow
57 {
58 Q_OBJECT
59 Q_CLASSINFO("D-Bus Interface", "org.kde.dolphin.MainWindow")
60 Q_PROPERTY(int id READ getId SCRIPTABLE true)
61 friend class DolphinApplication;
62
63 public:
64 virtual ~DolphinMainWindow();
65
66 /**
67 * Returns the currently active view.
68 * All menu actions are applied to this view. When
69 * having a split view setup, the nonactive view
70 * is usually shown in darker colors.
71 */
72 DolphinViewContainer* activeViewContainer() const;
73
74 /**
75 * Returns true, if the main window contains two instances
76 * of a view container. The active view constainer can be
77 * accessed by DolphinMainWindow::activeViewContainer().
78 */
79 bool isSplit() const;
80
81 /**
82 * If the main window contains two instances of a view container
83 * (DolphinMainWindow::isSplit() returns true), then the
84 * two views get toggled (the right view is on the left, the left
85 * view on the right).
86 */
87 void toggleViews();
88
89 /** Renames the item represented by \a oldUrl to \a newUrl. */
90 void rename(const KUrl& oldUrl, const KUrl& newUrl);
91
92 /**
93 * Refreshes the views of the main window by recreating them dependent from
94 * the given Dolphin settings.
95 */
96 void refreshViews();
97
98 /**
99 * Returns the 'Create New...' sub menu which also can be shared
100 * with other menus (e. g. a context menu).
101 */
102 KNewMenu* newMenu() const;
103
104 /**
105 * Returns the 'Show Menubar' action which can be shared with
106 * other menus (e. g. a context menu).
107 */
108 KAction* showMenuBarAction() const;
109
110 public slots:
111 /**
112 * Pastes the clipboard data into the currently selected folder
113 * of the active view. If not exactly one folder is selected,
114 * no pasting is done at all.
115 */
116 void pasteIntoFolder();
117
118 /**
119 * Returns the main window ID used through DBus.
120 */
121 int getId() const;
122
123 /**
124 * Inform all affected dolphin components (panels, views) of an URL
125 * change.
126 */
127 void changeUrl(const KUrl& url);
128
129 /**
130 * Inform all affected dolphin components that a selection change is
131 * requested.
132 */
133 void changeSelection(const KFileItemList& selection);
134
135 /** Stores all settings and quits Dolphin. */
136 void quit();
137
138 signals:
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 panel.
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 /** Shows the error message in the status bar of the active view. */
174 void showErrorMessage(const QString& message);
175
176 /**
177 * Updates the state of the 'Undo' menu action dependent
178 * from the parameter \a available.
179 */
180 void slotUndoAvailable(bool available);
181
182 /** Sets the text of the 'Undo' menu action to \a text. */
183 void slotUndoTextChanged(const QString& text);
184
185 /** Performs the current undo operation. */
186 void undo();
187
188 /**
189 * Copies all selected items to the clipboard and marks
190 * the items as cutted.
191 */
192 void cut();
193
194 /** Copies all selected items to the clipboard. */
195 void copy();
196
197 /** Pastes the clipboard data to the active view. */
198 void paste();
199
200 /**
201 * Updates the text of the paste action dependent from
202 * the number of items which are in the clipboard.
203 */
204 void updatePasteAction();
205
206 /** Selects all items from the active view. */
207 void selectAll();
208
209 /**
210 * Inverts the selection of all items of the active view:
211 * Selected items get nonselected and nonselected items get
212 * selected.
213 */
214 void invertSelection();
215
216 /**
217 * Switches between one and two views:
218 * If one view is visible, it will get split into two views.
219 * If already two views are visible, the nonactivated view gets closed.
220 */
221 void toggleSplitView();
222
223 /** Reloads the current active view. */
224 void reloadView();
225
226 /** Stops the loading process for the current active view. */
227 void stopLoading();
228
229 /**
230 * Toggles between showing and hiding of the filter bar
231 */
232 void toggleFilterBarVisibility(bool show);
233
234 /**
235 * Toggles between edit and browse mode of the navigation bar.
236 */
237 void toggleEditLocation();
238
239 /**
240 * Switches to the edit mode of the navigation bar and selects
241 * the whole URL, so that it can be replaced by the user. If the edit mode is
242 * already active, it is assured that the navigation bar get focused.
243 */
244 void replaceLocation();
245
246 /** Goes back on step of the URL history. */
247 void goBack();
248
249 /** Goes forward one step of the URL history. */
250 void goForward();
251
252 /** Goes up one hierarchy of the current URL. */
253 void goUp();
254
255 /** Goes to the home URL. */
256 void goHome();
257
258 /** Opens Kompare for 2 selected files. */
259 void compareFiles();
260
261 /**
262 * Initiates a preview of the selected files
263 * on the desktop by the Previewer plasmoid.
264 */
265 void quickView();
266
267 /**
268 * Hides the menu bar if it is visible, makes the menu bar
269 * visible if it is hidden.
270 */
271 void toggleShowMenuBar();
272
273 /** Opens the settings dialog for Dolphin. */
274 void editSettings();
275
276 /** Updates the state of the 'Show Full Location' action. */
277 void slotEditableStateChanged(bool editable);
278
279 /**
280 * Updates the state of the 'Edit' menu actions and emits
281 * the signal selectionChanged().
282 */
283 void slotSelectionChanged(const KFileItemList& selection);
284
285 /**
286 * Wheel event, receives it's degree of movement (int).
287 * we look to see if it's negative (backwards) or positive (forwards).
288 * Enables changing of tabs via mouse wheel.
289 */
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 * Connects the signals from the created DolphinView with
398 * the DolphinViewContainer \a container with the corresponding slots of
399 * the DolphinMainWindow. This method must be invoked each
400 * time a DolphinView has been created.
401 */
402 void connectViewSignals(DolphinViewContainer* container);
403
404 /**
405 * Updates the text of the split action:
406 * If two views are shown, the text is set to "Split",
407 * otherwise the text is set to "Join". The icon
408 * is updated to match with the text and the currently active view.
409 */
410 void updateSplitAction();
411
412 /** Returns the name of the tab for the URL \a url. */
413 QString tabName(const KUrl& url) const;
414
415 bool isKompareInstalled() const;
416
417 void createSecondaryView(int tabIndex);
418
419 private:
420 /**
421 * Implements a custom error handling for the undo manager. This
422 * assures that all errors are shown in the status bar of Dolphin
423 * instead as modal error dialog with an OK button.
424 */
425 class UndoUiInterface : public KIO::FileUndoManager::UiInterface
426 {
427 public:
428 UndoUiInterface();
429 virtual ~UndoUiInterface();
430 virtual void jobError(KIO::Job* job);
431 };
432
433 KNewMenu* m_newMenu;
434 KAction* m_showMenuBar;
435 KTabBar* m_tabBar;
436 DolphinViewContainer* m_activeViewContainer;
437 QVBoxLayout* m_centralWidgetLayout;
438 DolphinSearchBox* m_searchBox;
439 int m_id;
440
441 struct ViewTab
442 {
443 ViewTab() : isPrimaryViewActive(true), primaryView(0), secondaryView(0), splitter(0) {}
444 bool isPrimaryViewActive;
445 DolphinViewContainer* primaryView;
446 DolphinViewContainer* secondaryView;
447 QSplitter* splitter;
448 };
449
450 int m_tabIndex;
451 QList<ViewTab> m_viewTab;
452
453 DolphinViewActionHandler* m_actionHandler;
454 QPointer<DolphinSettingsDialog> m_settingsDialog;
455 };
456
457 inline DolphinViewContainer* DolphinMainWindow::activeViewContainer() const
458 {
459 return m_activeViewContainer;
460 }
461
462 inline bool DolphinMainWindow::isSplit() const
463 {
464 return m_viewTab[m_tabIndex].secondaryView != 0;
465 }
466
467 inline KNewMenu* DolphinMainWindow::newMenu() const
468 {
469 return m_newMenu;
470 }
471
472 inline KAction* DolphinMainWindow::showMenuBarAction() const
473 {
474 return m_showMenuBar;
475 }
476
477 inline int DolphinMainWindow::getId() const
478 {
479 return m_id;
480 }
481
482 #endif // DOLPHIN_MAINWINDOW_H
483