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