]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.h
Readd the "go home" action
[dolphin.git] / src / dolphinmainwindow.h
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz19@gmail.com> *
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>
30 #include <kio/fileundomanager.h>
31 #include <ksortablelist.h>
32 #include <kxmlguiwindow.h>
33 #include <KActionMenu>
34
35 #include "views/dolphinview.h"
36
37 #include <QList>
38
39 typedef KIO::FileUndoManager::CommandType CommandType;
40
41 class DolphinViewActionHandler;
42 class DolphinApplication;
43 class DolphinSettingsDialog;
44 class DolphinViewContainer;
45 class DolphinRemoteEncoding;
46 class KAction;
47 class KJob;
48 class KNewFileMenu;
49 class KTabBar;
50 class KUrl;
51 class QSplitter;
52 class QToolButton;
53
54 /**
55 * @short Main window for Dolphin.
56 *
57 * Handles the menus, toolbars and Dolphin views.
58 */
59 class DolphinMainWindow: public KXmlGuiWindow
60 {
61 Q_OBJECT
62 Q_CLASSINFO("D-Bus Interface", "org.kde.dolphin.MainWindow")
63 Q_PROPERTY(int id READ getId SCRIPTABLE true)
64 friend class DolphinApplication;
65
66 public:
67 virtual ~DolphinMainWindow();
68
69 /**
70 * Returns the currently active view.
71 * All menu actions are applied to this view. When
72 * having a split view setup, the nonactive view
73 * is usually shown in darker colors.
74 */
75 DolphinViewContainer* activeViewContainer() const;
76
77 /**
78 * Opens each directory in \p dirs in a separate tab. If the "split view"
79 * option is enabled, 2 directories are collected within one tab.
80 */
81 void openDirectories(const QList<KUrl>& dirs);
82
83 /**
84 * Opens the directory which contains the files \p files
85 * and selects all files (implements the --select option
86 * of Dolphin).
87 */
88 void openFiles(const QList<KUrl>& files);
89
90 /**
91 * Returns true, if the main window contains two instances
92 * of a view container. The active view constainer can be
93 * accessed by DolphinMainWindow::activeViewContainer().
94 */
95 bool isSplit() const;
96
97 /** Renames the item represented by \a oldUrl to \a newUrl. */
98 void rename(const KUrl& oldUrl, const KUrl& newUrl);
99
100 /**
101 * Refreshes the views of the main window by recreating them according to
102 * the given Dolphin settings.
103 */
104 void refreshViews();
105
106 /**
107 * Returns the 'Create New...' sub menu which also can be shared
108 * with other menus (e. g. a context menu).
109 */
110 KNewFileMenu* newFileMenu() 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 * Implementation of the MainWindowAdaptor/QDBusAbstractAdaptor interface.
127 * Inform all affected dolphin components (panels, views) of an URL
128 * change.
129 */
130 void changeUrl(const KUrl& url);
131
132 /** Stores all settings and quits Dolphin. */
133 void quit();
134
135 signals:
136 /**
137 * Is sent if the selection of the currently active view has
138 * been changed.
139 */
140 void selectionChanged(const KFileItemList& selection);
141
142 /**
143 * Is sent if the url of the currently active view has
144 * been changed.
145 */
146 void urlChanged(const KUrl& url);
147
148 /**
149 * Is emitted if information of an item is requested to be shown e. g. in the panel.
150 * If item is null, no item information request is pending.
151 */
152 void requestItemInfo(const KFileItem& item);
153
154 protected:
155 /** @see QWidget::showEvent() */
156 virtual void showEvent(QShowEvent* event);
157
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 void createDirectory();
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 * on 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 cut.
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 /** Replaces the URL navigator by a search box to find files. */
206 void find();
207
208 /**
209 * Updates the text of the paste action dependent on
210 * the number of items which are in the clipboard.
211 */
212 void updatePasteAction();
213
214 /** Selects all items from the active view. */
215 void selectAll();
216
217 /**
218 * Inverts the selection of all items of the active view:
219 * Selected items get nonselected and nonselected items get
220 * selected.
221 */
222 void invertSelection();
223
224 /**
225 * Switches between one and two views:
226 * If one view is visible, it will get split into two views.
227 * If already two views are visible, the active view gets closed.
228 */
229 void toggleSplitView();
230
231 /** Reloads the currently active view. */
232 void reloadView();
233
234 /** Stops the loading process for the currently active view. */
235 void stopLoading();
236
237 void enableStopAction();
238 void disableStopAction();
239
240 void showFilterBar();
241
242 /**
243 * Toggles between edit and browse mode of the navigation bar.
244 */
245 void toggleEditLocation();
246
247 /**
248 * Switches to the edit mode of the navigation bar and selects
249 * the whole URL, so that it can be replaced by the user. If the edit mode is
250 * already active, it is assured that the navigation bar get focused.
251 */
252 void replaceLocation();
253
254 /**
255 * Toggles the state of the panels between a locked and unlocked layout.
256 */
257 void togglePanelLockState();
258
259 /**
260 * Is invoked if the Places panel got visible/invisible and takes care
261 * that the places-selector of all views is only shown if the Places panel
262 * is invisible.
263 */
264 void slotPlacesPanelVisibilityChanged(bool visible);
265
266 /** Goes back one step of the URL history. */
267 void goBack();
268
269 /** Goes forward one step of the URL history. */
270 void goForward();
271
272 /** Goes up one hierarchy of the current URL. */
273 void goUp();
274
275 /** Changes the location to the home URL. */
276 void goHome();
277
278 /**
279 * Open the previous URL in the URL history in a new tab
280 * if the middle mouse button is clicked.
281 */
282 void goBack(Qt::MouseButtons buttons);
283
284 /**
285 * Open the next URL in the URL history in a new tab
286 * if the middle mouse button is clicked.
287 */
288 void goForward(Qt::MouseButtons buttons);
289
290 /**
291 * Open the URL one hierarchy above the current URL in a new tab
292 * if the middle mouse button is clicked.
293 */
294 void goUp(Qt::MouseButtons buttons);
295
296 /** Opens Kompare for 2 selected files. */
297 void compareFiles();
298
299 /**
300 * Hides the menu bar if it is visible, makes the menu bar
301 * visible if it is hidden.
302 */
303 void toggleShowMenuBar();
304
305 /** Opens a terminal window for the current location. */
306 void openTerminal();
307
308 /** Opens the settings dialog for Dolphin. */
309 void editSettings();
310
311 /** Updates the state of the 'Show Full Location' action. */
312 void slotEditableStateChanged(bool editable);
313
314 /**
315 * Updates the state of the 'Edit' menu actions and emits
316 * the signal selectionChanged().
317 */
318 void slotSelectionChanged(const KFileItemList& selection);
319
320 /** Emits the signal requestItemInfo(). */
321 void slotRequestItemInfo(const KFileItem&);
322
323 /**
324 * Updates the state of the 'Back' and 'Forward' menu
325 * actions corresponding to the current history.
326 */
327 void updateHistory();
328
329 /** Updates the state of the 'Show filter bar' menu action. */
330 void updateFilterBarAction(bool show);
331
332 /** Open a new main window. */
333 void openNewMainWindow();
334
335 /** Opens a new view with the current URL that is part of a tab. */
336 void openNewTab();
337
338 /**
339 * Opens a new tab showing the URL \a url.
340 */
341 void openNewTab(const KUrl& url);
342
343 void activateNextTab();
344
345 void activatePrevTab();
346
347 /**
348 * Opens the selected folder in a new tab.
349 */
350 void openInNewTab();
351
352 /**
353 * Opens the selected folder in a new window.
354 */
355 void openInNewWindow();
356
357 /** Toggles the active view if two views are shown within the main window. */
358 void toggleActiveView();
359
360 /**
361 * Indicates in the statusbar that the execution of the command \a command
362 * has been finished.
363 */
364 void showCommand(CommandType command);
365
366 /**
367 * Activates the tab with the index \a index, which means that the current view
368 * is replaced by the view of the given tab.
369 */
370 void setActiveTab(int index);
371
372 /** Closes the currently active tab. */
373 void closeTab();
374
375 /**
376 * Closes the tab with the index \a index and activates the tab with index - 1.
377 */
378 void closeTab(int index);
379
380 /**
381 * Opens a context menu for the tab with the index \a index
382 * on the position \a pos.
383 */
384 void openTabContextMenu(int index, const QPoint& pos);
385
386 /**
387 * Is connected to the QTabBar signal tabMoved(int from, int to).
388 * Reorders the list of tabs after a tab was moved in the tab bar
389 * and sets m_tabIndex to the new index of the current tab.
390 */
391 void slotTabMoved(int from, int to);
392
393 /**
394 * Handles a click on a places item: if the middle mouse button is
395 * clicked, a new tab is opened for \a url, otherwise the current
396 * view is replaced by \a url.
397 */
398 void handlePlacesClick(const KUrl& url, Qt::MouseButtons buttons);
399
400 /**
401 * Is connected to the KTabBar signal testCanDecode() and adjusts
402 * the output parameter \a accept.
403 */
404 void slotTestCanDecode(const QDragMoveEvent* event, bool& accept);
405
406 /**
407 * If the URL can be listed, open it in the current view, otherwise
408 * run it through KRun.
409 */
410 void handleUrl(const KUrl& url);
411
412 /**
413 * handleUrl() can trigger a stat job to see if the url can actually
414 * be listed.
415 */
416 void slotHandleUrlStatFinished(KJob* job);
417
418 /**
419 * Is connected to the KTabBar signal receivedDropEvent.
420 * Allows dragging and dropping files onto tabs.
421 */
422 void tabDropEvent(int tab, QDropEvent* event);
423
424 /**
425 * Is invoked when the write state of a folder has been changed and
426 * enables/disables the "Create New..." menu entry.
427 */
428 void slotWriteStateChanged(bool isFolderWritable);
429
430 void slotSearchModeChanged(bool enabled);
431
432 /**
433 * Opens the context menu on the current mouse position.
434 * @item File item context. If item is null, the context menu
435 * should be applied to \a url.
436 * @url URL which contains \a item.
437 * @customActions Actions that should be added to the context menu,
438 * if the file item is null.
439 */
440 void openContextMenu(const KFileItem& item,
441 const KUrl& url,
442 const QList<QAction*>& customActions);
443
444 void openToolBarMenu();
445 void updateToolBarMenu();
446 void updateToolBar();
447 void slotToolBarSpacerDeleted();
448 void slotToolBarMenuButtonDeleted();
449 void slotToolBarIconSizeChanged(const QSize& iconSize);
450
451 private:
452 DolphinMainWindow(int id);
453 void init();
454
455 /**
456 * Activates the given view, which means that
457 * all menu actions are applied to this view. When
458 * having a split view setup, the nonactive view
459 * is usually shown in darker colors.
460 */
461 void setActiveViewContainer(DolphinViewContainer* view);
462
463 /**
464 * Creates a view container and does a default initialization.
465 */
466 DolphinViewContainer* createViewContainer(const KUrl& url, QWidget* parent);
467
468 void setupActions();
469 void setupDockWidgets();
470 void updateEditActions();
471 void updateViewActions();
472 void updateGoActions();
473
474 void createToolBarMenuButton();
475 void deleteToolBarMenuButton();
476
477 /**
478 * Adds the action \p action to the menu \p menu in
479 * case if it has not added already to the toolbar.
480 * @return True if the action has been added to the menu.
481 */
482 bool addActionToMenu(QAction* action, KMenu* menu);
483
484 /**
485 * Adds the tab[\a index] to the closed tab menu's list of actions.
486 */
487 void rememberClosedTab(int index);
488
489 /**
490 * Connects the signals from the created DolphinView with
491 * the DolphinViewContainer \a container with the corresponding slots of
492 * the DolphinMainWindow. This method must be invoked each
493 * time a DolphinView has been created.
494 */
495 void connectViewSignals(DolphinViewContainer* container);
496
497 /**
498 * Updates the text of the split action:
499 * If two views are shown, the text is set to "Split",
500 * otherwise the text is set to "Join". The icon
501 * is updated to match with the text and the currently active view.
502 */
503 void updateSplitAction();
504
505 /** Returns the name of the tab for the URL \a url. */
506 QString tabName(const KUrl& url) const;
507
508 bool isKompareInstalled() const;
509
510 void createSecondaryView(int tabIndex);
511
512 /**
513 * Helper method for saveProperties() and readProperties(): Returns
514 * the property string for a tab with the index \a tabIndex and
515 * the property \a property.
516 */
517 QString tabProperty(const QString& property, int tabIndex) const;
518
519 /**
520 * Sets the window caption to url.fileName() if this is non-empty,
521 * "/" if the URL is "file:///", and url.protocol() otherwise.
522 */
523 void setUrlAsCaption(const KUrl& url);
524
525 QString squeezedText(const QString& text) const;
526
527 /**
528 * Adds a clone of the action \a action to the action-collection with
529 * the name \a actionName, so that the action \a action also can be
530 * added to the toolbar by the user. This is useful if the creation of
531 * \a action is e.g. done in Qt and hence cannot be added directly
532 * to the action-collection.
533 */
534 void addActionCloneToCollection(QAction* action, const QString& actionName);
535
536 private:
537 /**
538 * Implements a custom error handling for the undo manager. This
539 * assures that all errors are shown in the status bar of Dolphin
540 * instead as modal error dialog with an OK button.
541 */
542 class UndoUiInterface : public KIO::FileUndoManager::UiInterface
543 {
544 public:
545 UndoUiInterface();
546 virtual ~UndoUiInterface();
547 virtual void jobError(KIO::Job* job);
548 };
549
550 KNewFileMenu* m_newFileMenu;
551 KActionMenu* m_recentTabsMenu;
552 KTabBar* m_tabBar;
553 DolphinViewContainer* m_activeViewContainer;
554 QVBoxLayout* m_centralWidgetLayout;
555 int m_id;
556
557 // Members for the tab-handling:
558 struct ViewTab
559 {
560 ViewTab() : isPrimaryViewActive(true), primaryView(0), secondaryView(0), splitter(0) {}
561 bool isPrimaryViewActive;
562 DolphinViewContainer* primaryView;
563 DolphinViewContainer* secondaryView;
564 QSplitter* splitter;
565 };
566 int m_tabIndex;
567 QList<ViewTab> m_viewTab;
568
569 DolphinViewActionHandler* m_actionHandler;
570 DolphinRemoteEncoding* m_remoteEncoding;
571 QPointer<DolphinSettingsDialog> m_settingsDialog;
572
573 // Members for the toolbar menu that is shown when the menubar is hidden:
574 QWidget* m_toolBarSpacer;
575 QToolButton* m_openToolBarMenuButton;
576 QWeakPointer<KMenu> m_toolBarMenu;
577 QTimer* m_updateToolBarTimer;
578
579 KJob* m_lastHandleUrlStatJob;
580
581 /**
582 * Set to true, if the filter dock visibility is only temporary set
583 * to true by enabling the search mode.
584 */
585 bool m_searchDockIsTemporaryVisible;
586 };
587
588 inline DolphinViewContainer* DolphinMainWindow::activeViewContainer() const
589 {
590 return m_activeViewContainer;
591 }
592
593 inline bool DolphinMainWindow::isSplit() const
594 {
595 return m_viewTab[m_tabIndex].secondaryView != 0;
596 }
597
598 inline KNewFileMenu* DolphinMainWindow::newFileMenu() const
599 {
600 return m_newFileMenu;
601 }
602
603 inline int DolphinMainWindow::getId() const
604 {
605 return m_id;
606 }
607
608 #endif // DOLPHIN_MAINWINDOW_H
609