]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.h
Provide toolbar-menu when the menubar is hidden
[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 KNewFileMenu;
48 class KPushButton;
49 class KTabBar;
50 class KUrl;
51 class QSplitter;
52 class KJob;
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 /**
276 * Open the previous URL in the URL history in a new tab
277 * if the middle mouse button is clicked.
278 */
279 void goBack(Qt::MouseButtons buttons);
280
281 /**
282 * Open the next URL in the URL history in a new tab
283 * if the middle mouse button is clicked.
284 */
285 void goForward(Qt::MouseButtons buttons);
286
287 /**
288 * Open the URL one hierarchy above the current URL in a new tab
289 * if the middle mouse button is clicked.
290 */
291 void goUp(Qt::MouseButtons buttons);
292
293 /** Opens Kompare for 2 selected files. */
294 void compareFiles();
295
296 /**
297 * Hides the menu bar if it is visible, makes the menu bar
298 * visible if it is hidden.
299 */
300 void toggleShowMenuBar();
301
302 /** Opens a terminal window for the current location. */
303 void openTerminal();
304
305 /** Opens the settings dialog for Dolphin. */
306 void editSettings();
307
308 /** Updates the state of the 'Show Full Location' action. */
309 void slotEditableStateChanged(bool editable);
310
311 /**
312 * Updates the state of the 'Edit' menu actions and emits
313 * the signal selectionChanged().
314 */
315 void slotSelectionChanged(const KFileItemList& selection);
316
317 /** Emits the signal requestItemInfo(). */
318 void slotRequestItemInfo(const KFileItem&);
319
320 /**
321 * Updates the state of the 'Back' and 'Forward' menu
322 * actions corresponding to the current history.
323 */
324 void updateHistory();
325
326 /** Updates the state of the 'Show filter bar' menu action. */
327 void updateFilterBarAction(bool show);
328
329 /** Open a new main window. */
330 void openNewMainWindow();
331
332 /** Opens a new view with the current URL that is part of a tab. */
333 void openNewTab();
334
335 /**
336 * Opens a new tab showing the URL \a url.
337 */
338 void openNewTab(const KUrl& url);
339
340 void activateNextTab();
341
342 void activatePrevTab();
343
344 /**
345 * Opens the selected folder in a new tab.
346 */
347 void openInNewTab();
348
349 /**
350 * Opens the selected folder in a new window.
351 */
352 void openInNewWindow();
353
354 /** Toggles the active view if two views are shown within the main window. */
355 void toggleActiveView();
356
357 /**
358 * Indicates in the statusbar that the execution of the command \a command
359 * has been finished.
360 */
361 void showCommand(CommandType command);
362
363 /**
364 * Activates the tab with the index \a index, which means that the current view
365 * is replaced by the view of the given tab.
366 */
367 void setActiveTab(int index);
368
369 /** Closes the currently active tab. */
370 void closeTab();
371
372 /**
373 * Closes the tab with the index \a index and activates the tab with index - 1.
374 */
375 void closeTab(int index);
376
377 /**
378 * Opens a context menu for the tab with the index \a index
379 * on the position \a pos.
380 */
381 void openTabContextMenu(int index, const QPoint& pos);
382
383 /**
384 * Is connected to the QTabBar signal tabMoved(int from, int to).
385 * Reorders the list of tabs after a tab was moved in the tab bar
386 * and sets m_tabIndex to the new index of the current tab.
387 */
388 void slotTabMoved(int from, int to);
389
390 /**
391 * Handles a click on a places item: if the middle mouse button is
392 * clicked, a new tab is opened for \a url, otherwise the current
393 * view is replaced by \a url.
394 */
395 void handlePlacesClick(const KUrl& url, Qt::MouseButtons buttons);
396
397 /**
398 * Is connected to the KTabBar signal testCanDecode() and adjusts
399 * the output parameter \a accept.
400 */
401 void slotTestCanDecode(const QDragMoveEvent* event, bool& accept);
402
403 /**
404 * If the URL can be listed, open it in the current view, otherwise
405 * run it through KRun.
406 */
407 void handleUrl(const KUrl& url);
408
409 /**
410 * handleUrl() can trigger a stat job to see if the url can actually
411 * be listed.
412 */
413 void slotHandleUrlStatFinished(KJob* job);
414
415 /**
416 * Is connected to the KTabBar signal receivedDropEvent.
417 * Allows dragging and dropping files onto tabs.
418 */
419 void tabDropEvent(int tab, QDropEvent* event);
420
421 /**
422 * Is invoked when the write state of a folder has been changed and
423 * enables/disables the "Create New..." menu entry.
424 */
425 void slotWriteStateChanged(bool isFolderWritable);
426
427 void slotSearchModeChanged(bool enabled);
428
429 /**
430 * Opens the context menu on the current mouse position.
431 * @item File item context. If item is null, the context menu
432 * should be applied to \a url.
433 * @url URL which contains \a item.
434 * @customActions Actions that should be added to the context menu,
435 * if the file item is null.
436 */
437 void openContextMenu(const KFileItem& item,
438 const KUrl& url,
439 const QList<QAction*>& customActions);
440
441 void openToolBarMenu();
442 void updateToolBarMenu();
443 void updateToolBar();
444 void slotToolBarSpacerDeleted();
445 void slotToolBarMenuButtonDeleted();
446
447 private:
448 DolphinMainWindow(int id);
449 void init();
450
451 /**
452 * Activates the given view, which means that
453 * all menu actions are applied to this view. When
454 * having a split view setup, the nonactive view
455 * is usually shown in darker colors.
456 */
457 void setActiveViewContainer(DolphinViewContainer* view);
458
459 /**
460 * Creates a view container and does a default initialization.
461 */
462 DolphinViewContainer* createViewContainer(const KUrl& url, QWidget* parent);
463
464 void setupActions();
465 void setupDockWidgets();
466 void updateEditActions();
467 void updateViewActions();
468 void updateGoActions();
469
470 void createToolBarMenuButton();
471 void deleteToolBarMenuButton();
472
473 /**
474 * Adds the action \p action to the menu \p menu in
475 * case if it has not added already to the toolbar.
476 * @return True if the action has been added to the menu.
477 */
478 bool addActionToMenu(QAction* action, KMenu* menu);
479
480 /**
481 * Adds the tab[\a index] to the closed tab menu's list of actions.
482 */
483 void rememberClosedTab(int index);
484
485 /**
486 * Connects the signals from the created DolphinView with
487 * the DolphinViewContainer \a container with the corresponding slots of
488 * the DolphinMainWindow. This method must be invoked each
489 * time a DolphinView has been created.
490 */
491 void connectViewSignals(DolphinViewContainer* container);
492
493 /**
494 * Updates the text of the split action:
495 * If two views are shown, the text is set to "Split",
496 * otherwise the text is set to "Join". The icon
497 * is updated to match with the text and the currently active view.
498 */
499 void updateSplitAction();
500
501 /** Returns the name of the tab for the URL \a url. */
502 QString tabName(const KUrl& url) const;
503
504 bool isKompareInstalled() const;
505
506 void createSecondaryView(int tabIndex);
507
508 /**
509 * Helper method for saveProperties() and readProperties(): Returns
510 * the property string for a tab with the index \a tabIndex and
511 * the property \a property.
512 */
513 QString tabProperty(const QString& property, int tabIndex) const;
514
515 /**
516 * Sets the window caption to url.fileName() if this is non-empty,
517 * "/" if the URL is "file:///", and url.protocol() otherwise.
518 */
519 void setUrlAsCaption(const KUrl& url);
520
521 QString squeezedText(const QString& text) const;
522
523 /**
524 * Adds a clone of the action \a action to the action-collection with
525 * the name \a actionName, so that the action \a action also can be
526 * added to the toolbar by the user. This is useful if the creation of
527 * \a action is e.g. done in Qt and hence cannot be added directly
528 * to the action-collection.
529 */
530 void addActionCloneToCollection(QAction* action, const QString& actionName);
531
532 private:
533 /**
534 * Implements a custom error handling for the undo manager. This
535 * assures that all errors are shown in the status bar of Dolphin
536 * instead as modal error dialog with an OK button.
537 */
538 class UndoUiInterface : public KIO::FileUndoManager::UiInterface
539 {
540 public:
541 UndoUiInterface();
542 virtual ~UndoUiInterface();
543 virtual void jobError(KIO::Job* job);
544 };
545
546 KNewFileMenu* m_newFileMenu;
547 KActionMenu* m_recentTabsMenu;
548 KTabBar* m_tabBar;
549 DolphinViewContainer* m_activeViewContainer;
550 QVBoxLayout* m_centralWidgetLayout;
551 int m_id;
552
553 // Members for the tab-handling:
554 struct ViewTab
555 {
556 ViewTab() : isPrimaryViewActive(true), primaryView(0), secondaryView(0), splitter(0) {}
557 bool isPrimaryViewActive;
558 DolphinViewContainer* primaryView;
559 DolphinViewContainer* secondaryView;
560 QSplitter* splitter;
561 };
562 int m_tabIndex;
563 QList<ViewTab> m_viewTab;
564
565 DolphinViewActionHandler* m_actionHandler;
566 DolphinRemoteEncoding* m_remoteEncoding;
567 QPointer<DolphinSettingsDialog> m_settingsDialog;
568
569 // Members for the toolbar menu that is shown when the menubar is hidden:
570 QWidget* m_toolBarSpacer;
571 KPushButton* m_openToolBarMenuButton;
572 QWeakPointer<KMenu> m_toolBarMenu;
573 QTimer* m_updateToolBarTimer;
574
575 KJob* m_lastHandleUrlStatJob;
576
577 /**
578 * Set to true, if the filter dock visibility is only temporary set
579 * to true by enabling the search mode.
580 */
581 bool m_searchDockIsTemporaryVisible;
582 };
583
584 inline DolphinViewContainer* DolphinMainWindow::activeViewContainer() const
585 {
586 return m_activeViewContainer;
587 }
588
589 inline bool DolphinMainWindow::isSplit() const
590 {
591 return m_viewTab[m_tabIndex].secondaryView != 0;
592 }
593
594 inline KNewFileMenu* DolphinMainWindow::newFileMenu() const
595 {
596 return m_newFileMenu;
597 }
598
599 inline int DolphinMainWindow::getId() const
600 {
601 return m_id;
602 }
603
604 #endif // DOLPHIN_MAINWINDOW_H
605