]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.h
Make toggleSplitView()'s documentation consistent with its behavior
[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 "panels/panel.h"
26
27 #include <config-nepomuk.h>
28
29 #include <kfileitemdelegate.h>
30 #include <kio/fileundomanager.h>
31 #include <ksortablelist.h>
32 #include <kxmlguiwindow.h>
33 #include <kactionmenu.h>
34
35 #include "views/dolphinview.h"
36
37 #include <QList>
38
39 typedef KIO::FileUndoManager::CommandType CommandType;
40
41 class KAction;
42 class DolphinViewActionHandler;
43 class DolphinApplication;
44 class DolphinSettingsDialog;
45 class DolphinViewContainer;
46 class DolphinRemoteEncoding;
47 class KNewFileMenu;
48 class KTabBar;
49 class KUrl;
50 class QSplitter;
51 class KJob;
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 * Opens each directory in \p dirs in a separate tab. If the "split view"
78 * option is enabled, 2 directories are collected within one tab.
79 */
80 void openDirectories(const QList<KUrl>& dirs);
81
82 /**
83 * Opens the directory which contains the files \p files
84 * and selects all files (implements the --select option
85 * of Dolphin).
86 */
87 void openFiles(const QList<KUrl>& files);
88
89 /**
90 * Returns true, if the main window contains two instances
91 * of a view container. The active view constainer can be
92 * accessed by DolphinMainWindow::activeViewContainer().
93 */
94 bool isSplit() const;
95
96 /** Renames the item represented by \a oldUrl to \a newUrl. */
97 void rename(const KUrl& oldUrl, const KUrl& newUrl);
98
99 /**
100 * Refreshes the views of the main window by recreating them according to
101 * the given Dolphin settings.
102 */
103 void refreshViews();
104
105 /**
106 * Returns the 'Create New...' sub menu which also can be shared
107 * with other menus (e. g. a context menu).
108 */
109 KNewFileMenu* newFileMenu() const;
110
111 /**
112 * Returns the 'Show Menubar' action which can be shared with
113 * other menus (e. g. a context menu).
114 */
115 KAction* showMenuBarAction() const;
116
117 public slots:
118 /**
119 * Pastes the clipboard data into the currently selected folder
120 * of the active view. If not exactly one folder is selected,
121 * no pasting is done at all.
122 */
123 void pasteIntoFolder();
124
125 /**
126 * Returns the main window ID used through DBus.
127 */
128 int getId() const;
129
130 /**
131 * Implementation of the MainWindowAdaptor/QDBusAbstractAdaptor interface.
132 * Inform all affected dolphin components (panels, views) of an URL
133 * change.
134 */
135 void changeUrl(const KUrl& url);
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 QWidget::showEvent() */
161 virtual void showEvent(QShowEvent* event);
162
163 /** @see QMainWindow::closeEvent() */
164 virtual void closeEvent(QCloseEvent* event);
165
166 /** @see KMainWindow::saveProperties() */
167 virtual void saveProperties(KConfigGroup& group);
168
169 /** @see KMainWindow::readProperties() */
170 virtual void readProperties(const KConfigGroup& group);
171
172 private slots:
173 void clearStatusBar();
174
175 /** Updates the 'Create New...' sub menu. */
176 void updateNewMenu();
177
178 void createDirectory();
179
180 /** Shows the error message in the status bar of the active view. */
181 void showErrorMessage(const QString& message);
182
183 /**
184 * Updates the state of the 'Undo' menu action dependent
185 * on the parameter \a available.
186 */
187 void slotUndoAvailable(bool available);
188
189 /** Invoked when an action in the recent tabs menu is clicked. */
190 void restoreClosedTab(QAction* action);
191
192 /** Sets the text of the 'Undo' menu action to \a text. */
193 void slotUndoTextChanged(const QString& text);
194
195 /** Performs the current undo operation. */
196 void undo();
197
198 /**
199 * Copies all selected items to the clipboard and marks
200 * the items as cut.
201 */
202 void cut();
203
204 /** Copies all selected items to the clipboard. */
205 void copy();
206
207 /** Pastes the clipboard data to the active view. */
208 void paste();
209
210 /** Replaces the URL navigator by a search box to find files. */
211 void find();
212
213 /**
214 * Updates the text of the paste action dependent on
215 * the number of items which are in the clipboard.
216 */
217 void updatePasteAction();
218
219 /** Selects all items from the active view. */
220 void selectAll();
221
222 /**
223 * Inverts the selection of all items of the active view:
224 * Selected items get nonselected and nonselected items get
225 * selected.
226 */
227 void invertSelection();
228
229 /**
230 * Switches between one and two views:
231 * If one view is visible, it will get split into two views.
232 * If already two views are visible, the active view gets closed.
233 */
234 void toggleSplitView();
235
236 /** Reloads the currently active view. */
237 void reloadView();
238
239 /** Stops the loading process for the currently active view. */
240 void stopLoading();
241
242 void enableStopAction();
243 void disableStopAction();
244
245 void showFilterBar();
246
247 /**
248 * Toggles between edit and browse mode of the navigation bar.
249 */
250 void toggleEditLocation();
251
252 /**
253 * Switches to the edit mode of the navigation bar and selects
254 * the whole URL, so that it can be replaced by the user. If the edit mode is
255 * already active, it is assured that the navigation bar get focused.
256 */
257 void replaceLocation();
258
259 /**
260 * Toggles the state of the panels between a locked and unlocked layout.
261 */
262 void togglePanelLockState();
263
264 /** Goes back one step of the URL history. */
265 void goBack();
266
267 /** Goes forward one step of the URL history. */
268 void goForward();
269
270 /** Goes up one hierarchy of the current URL. */
271 void goUp();
272
273 /**
274 * Open the previous URL in the URL history in a new tab
275 * if the middle mouse button is clicked.
276 */
277 void goBack(Qt::MouseButtons buttons);
278
279 /**
280 * Open the next URL in the URL history in a new tab
281 * if the middle mouse button is clicked.
282 */
283 void goForward(Qt::MouseButtons buttons);
284
285 /**
286 * Open the URL one hierarchy above the current URL in a new tab
287 * if the middle mouse button is clicked.
288 */
289 void goUp(Qt::MouseButtons buttons);
290
291 /** Goes to the home URL. */
292 void goHome();
293
294 /** Opens Kompare for 2 selected files. */
295 void compareFiles();
296
297 /**
298 * Hides the menu bar if it is visible, makes the menu bar
299 * visible if it is hidden.
300 */
301 void toggleShowMenuBar();
302
303 /** Opens a terminal window for the current location. */
304 void openTerminal();
305
306 /** Opens the settings dialog for Dolphin. */
307 void editSettings();
308
309 /** Updates the state of the 'Show Full Location' action. */
310 void slotEditableStateChanged(bool editable);
311
312 /**
313 * Updates the state of the 'Edit' menu actions and emits
314 * the signal selectionChanged().
315 */
316 void slotSelectionChanged(const KFileItemList& selection);
317
318 /** Emits the signal requestItemInfo(). */
319 void slotRequestItemInfo(const KFileItem&);
320
321 /**
322 * Updates the state of the 'Back' and 'Forward' menu
323 * actions corresponding to the current history.
324 */
325 void updateHistory();
326
327 /** Updates the state of the 'Show filter bar' menu action. */
328 void updateFilterBarAction(bool show);
329
330 /** Open a new main window. */
331 void openNewMainWindow();
332
333 /** Opens a new view with the current URL that is part of a tab. */
334 void openNewTab();
335
336 /**
337 * Opens a new tab showing the URL \a url.
338 */
339 void openNewTab(const KUrl& url);
340
341 void activateNextTab();
342
343 void activatePrevTab();
344
345 /**
346 * Opens the selected folder in a new tab.
347 */
348 void openInNewTab();
349
350 /**
351 * Opens the selected folder in a new window.
352 */
353 void openInNewWindow();
354
355 /** Toggles the active view if two views are shown within the main window. */
356 void toggleActiveView();
357
358 /**
359 * Indicates in the statusbar that the execution of the command \a command
360 * has been finished.
361 */
362 void showCommand(CommandType command);
363
364 /**
365 * Activates the tab with the index \a index, which means that the current view
366 * is replaced by the view of the given tab.
367 */
368 void setActiveTab(int index);
369
370 /** Closes the currently active tab. */
371 void closeTab();
372
373 /**
374 * Closes the tab with the index \a index and activates the tab with index - 1.
375 */
376 void closeTab(int index);
377
378 /**
379 * Opens a context menu for the tab with the index \a index
380 * on the position \a pos.
381 */
382 void openTabContextMenu(int index, const QPoint& pos);
383
384 /**
385 * Is connected to the QTabBar signal tabMoved(int from, int to).
386 * Reorders the list of tabs after a tab was moved in the tab bar
387 * and sets m_tabIndex to the new index of the current tab.
388 */
389 void slotTabMoved(int from, int to);
390
391 /**
392 * Handles a click on a places item: if the middle mouse button is
393 * clicked, a new tab is opened for \a url, otherwise the current
394 * view is replaced by \a url.
395 */
396 void handlePlacesClick(const KUrl& url, Qt::MouseButtons buttons);
397
398 /**
399 * Is connected to the KTabBar signal testCanDecode() and adjusts
400 * the output parameter \a accept.
401 */
402 void slotTestCanDecode(const QDragMoveEvent* event, bool& accept);
403
404 /**
405 * If the URL can be listed, open it in the current view, otherwise
406 * run it through KRun.
407 */
408 void handleUrl(const KUrl& url);
409
410 /**
411 * handleUrl() can trigger a stat job to see if the url can actually
412 * be listed.
413 */
414 void slotHandleUrlStatFinished(KJob* job);
415
416 /**
417 * Is connected to the KTabBar signal receivedDropEvent.
418 * Allows dragging and dropping files onto tabs.
419 */
420 void tabDropEvent(int tab, QDropEvent* event);
421
422 /**
423 * Is invoked when the write state of a folder has been changed and
424 * enables/disables the "Create New..." menu entry.
425 */
426 void slotWriteStateChanged(bool isFolderWritable);
427
428 void slotSearchModeChanged(bool enabled);
429
430 /**
431 * Opens the context menu on the current mouse position.
432 * @item File item context. If item is null, the context menu
433 * should be applied to \a url.
434 * @url URL which contains \a item.
435 * @customActions Actions that should be added to the context menu,
436 * if the file item is null.
437 */
438 void openContextMenu(const KFileItem& item,
439 const KUrl& url,
440 const QList<QAction*>& customActions);
441
442 private:
443 DolphinMainWindow(int id);
444 void init();
445
446 /**
447 * Activates the given view, which means that
448 * all menu actions are applied to this view. When
449 * having a split view setup, the nonactive view
450 * is usually shown in darker colors.
451 */
452 void setActiveViewContainer(DolphinViewContainer* view);
453
454 void setupActions();
455 void setupDockWidgets();
456 void updateEditActions();
457 void updateViewActions();
458 void updateGoActions();
459
460 /**
461 * Adds the tab[\a index] to the closed tab menu's list of actions.
462 */
463 void rememberClosedTab(int index);
464
465 /**
466 * Connects the signals from the created DolphinView with
467 * the DolphinViewContainer \a container with the corresponding slots of
468 * the DolphinMainWindow. This method must be invoked each
469 * time a DolphinView has been created.
470 */
471 void connectViewSignals(DolphinViewContainer* container);
472
473 /**
474 * Updates the text of the split action:
475 * If two views are shown, the text is set to "Split",
476 * otherwise the text is set to "Join". The icon
477 * is updated to match with the text and the currently active view.
478 */
479 void updateSplitAction();
480
481 /** Returns the name of the tab for the URL \a url. */
482 QString tabName(const KUrl& url) const;
483
484 bool isKompareInstalled() const;
485
486 void createSecondaryView(int tabIndex);
487
488 /**
489 * Helper method for saveProperties() and readProperties(): Returns
490 * the property string for a tab with the index \a tabIndex and
491 * the property \a property.
492 */
493 QString tabProperty(const QString& property, int tabIndex) const;
494
495 /**
496 * Sets the window caption to url.fileName() if this is non-empty,
497 * "/" if the URL is "file:///", and url.protocol() otherwise.
498 */
499 void setUrlAsCaption(const KUrl& url);
500
501 QString squeezedText(const QString& text) const;
502
503 /**
504 * Adds a clone of the action \a action to the action-collection with
505 * the name \a actionName, so that the action \a action also can be
506 * added to the toolbar by the user. This is useful if the creation of
507 * \a action is e.g. done in Qt and hence cannot be added directly
508 * to the action-collection.
509 */
510 void addActionCloneToCollection(QAction* action, const QString& actionName);
511
512 private:
513 /**
514 * Implements a custom error handling for the undo manager. This
515 * assures that all errors are shown in the status bar of Dolphin
516 * instead as modal error dialog with an OK button.
517 */
518 class UndoUiInterface : public KIO::FileUndoManager::UiInterface
519 {
520 public:
521 UndoUiInterface();
522 virtual ~UndoUiInterface();
523 virtual void jobError(KIO::Job* job);
524 };
525
526 KNewFileMenu* m_newFileMenu;
527 KActionMenu* m_recentTabsMenu;
528 KAction* m_showMenuBar;
529 KTabBar* m_tabBar;
530 DolphinViewContainer* m_activeViewContainer;
531 QVBoxLayout* m_centralWidgetLayout;
532 int m_id;
533
534 struct ViewTab
535 {
536 ViewTab() : isPrimaryViewActive(true), primaryView(0), secondaryView(0), splitter(0) {}
537 bool isPrimaryViewActive;
538 DolphinViewContainer* primaryView;
539 DolphinViewContainer* secondaryView;
540 QSplitter* splitter;
541 };
542
543 int m_tabIndex;
544 QList<ViewTab> m_viewTab;
545
546 DolphinViewActionHandler* m_actionHandler;
547 DolphinRemoteEncoding* m_remoteEncoding;
548 QPointer<DolphinSettingsDialog> m_settingsDialog;
549
550 KJob* m_lastHandleUrlStatJob;
551
552 /**
553 * Set to true, if the filter dock visibility is only temporary set
554 * to true by enabling the search mode.
555 */
556 bool m_filterDockIsTemporaryVisible;
557 };
558
559 inline DolphinViewContainer* DolphinMainWindow::activeViewContainer() const
560 {
561 return m_activeViewContainer;
562 }
563
564 inline bool DolphinMainWindow::isSplit() const
565 {
566 return m_viewTab[m_tabIndex].secondaryView != 0;
567 }
568
569 inline KNewFileMenu* DolphinMainWindow::newFileMenu() const
570 {
571 return m_newFileMenu;
572 }
573
574 inline KAction* DolphinMainWindow::showMenuBarAction() const
575 {
576 return m_showMenuBar;
577 }
578
579 inline int DolphinMainWindow::getId() const
580 {
581 return m_id;
582 }
583
584 #endif // DOLPHIN_MAINWINDOW_H
585