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