]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.h
Port KRun to OpenUrlJob
[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 "dolphintabwidget.h"
26 #include <config-baloo.h>
27 #include <kio/fileundomanager.h>
28 #include <KSortableList>
29 #include <kxmlguiwindow.h>
30
31 #include <QIcon>
32 #include <QList>
33 #include <QMenu>
34 #include <QPointer>
35 #include <QUrl>
36 #include <QVector>
37
38 typedef KIO::FileUndoManager::CommandType CommandType;
39
40 class DolphinBookmarkHandler;
41 class DolphinViewActionHandler;
42 class DolphinSettingsDialog;
43 class DolphinViewContainer;
44 class DolphinRemoteEncoding;
45 class DolphinTabWidget;
46 class KFileItem;
47 class KFileItemList;
48 class KJob;
49 class KNewFileMenu;
50 class KHelpMenu;
51 class KToolBarPopupAction;
52 class QToolButton;
53 class QIcon;
54 class PlacesPanel;
55 class TerminalPanel;
56
57 namespace KIO {
58 class OpenUrlJob;
59 }
60
61 /**
62 * @short Main window for Dolphin.
63 *
64 * Handles the menus, toolbars and Dolphin views.
65 */
66 class DolphinMainWindow: public KXmlGuiWindow
67 {
68 Q_OBJECT
69 Q_CLASSINFO("D-Bus Interface", "org.kde.dolphin.MainWindow")
70
71 public:
72 DolphinMainWindow();
73 ~DolphinMainWindow() override;
74
75 /**
76 * Returns the currently active view.
77 * All menu actions are applied to this view. When
78 * having a split view setup, the nonactive view
79 * is usually shown in darker colors.
80 */
81 DolphinViewContainer* activeViewContainer() const;
82
83 /**
84 * Returns view container for all tabs
85 */
86 QVector<DolphinViewContainer*> viewContainers() const;
87
88 /**
89 * Opens each directory in \p dirs in a separate tab. If \a splitView is set,
90 * 2 directories are collected within one tab.
91 * \pre \a dirs must contain at least one url.
92 */
93 void openDirectories(const QList<QUrl> &dirs, bool splitView);
94
95 /**
96 * Opens the directories which contain the files \p files and selects all files.
97 * If \a splitView is set, 2 directories are collected within one tab.
98 * \pre \a files must contain at least one url.
99 */
100 void openFiles(const QList<QUrl>& files, bool splitView);
101
102 /**
103 * Returns the 'Create New...' sub menu which also can be shared
104 * with other menus (e. g. a context menu).
105 */
106 KNewFileMenu* newFileMenu() const;
107
108 void setTabsToHomeIfMountPathOpen(const QString& mountPath);
109
110 public slots:
111 /**
112 * Opens each directory in \p dirs in a separate tab. If \a splitView is set,
113 * 2 directories are collected within one tab.
114 * \pre \a dirs must contain at least one url.
115 *
116 * @note this function is overloaded so that it is callable via DBus.
117 */
118 void openDirectories(const QStringList &dirs, bool splitView);
119
120 /**
121 * Opens the directories which contain the files \p files and selects all files.
122 * If \a splitView is set, 2 directories are collected within one tab.
123 * \pre \a files must contain at least one url.
124 *
125 * @note this is overloaded so that this function is callable via DBus.
126 */
127 void openFiles(const QStringList &files, bool splitView);
128
129 /**
130 * Tries to raise/activate the Dolphin window.
131 */
132 void activateWindow();
133
134 /**
135 * Determines if a URL is open in any tab.
136 * @note Use of QString instead of QUrl is required to be callable via DBus.
137 *
138 * @param url URL to look for
139 * @returns true if url is currently open in a tab, false otherwise.
140 */
141 bool isUrlOpen(const QString &url);
142
143
144 /**
145 * Pastes the clipboard data into the currently selected folder
146 * of the active view. If not exactly one folder is selected,
147 * no pasting is done at all.
148 */
149 void pasteIntoFolder();
150
151 /**
152 * Implementation of the MainWindowAdaptor/QDBusAbstractAdaptor interface.
153 * Inform all affected dolphin components (panels, views) of an URL
154 * change.
155 */
156 void changeUrl(const QUrl& url);
157
158 /**
159 * The current directory of the Terminal Panel has changed, probably because
160 * the user entered a 'cd' command. This slot calls changeUrl(url) and makes
161 * sure that the panel keeps the keyboard focus.
162 */
163 void slotTerminalDirectoryChanged(const QUrl& url);
164
165 /** Stores all settings and quits Dolphin. */
166 void quit();
167
168 /**
169 * Opens a new tab and places it after the current tab
170 */
171 void openNewTabAfterCurrentTab(const QUrl& url);
172
173 /**
174 * Opens a new tab and places it as the last tab
175 */
176 void openNewTabAfterLastTab(const QUrl& url);
177
178 signals:
179 /**
180 * Is sent if the selection of the currently active view has
181 * been changed.
182 */
183 void selectionChanged(const KFileItemList& selection);
184
185 /**
186 * Is sent if the url of the currently active view has
187 * been changed.
188 */
189 void urlChanged(const QUrl& url);
190
191 /**
192 * Is emitted if information of an item is requested to be shown e. g. in the panel.
193 * If item is null, no item information request is pending.
194 */
195 void requestItemInfo(const KFileItem& item);
196
197 /**
198 * Is emitted if the settings have been changed.
199 */
200 void settingsChanged();
201
202 protected:
203 /** @see QWidget::showEvent() */
204 void showEvent(QShowEvent* event) override;
205
206 /** @see QMainWindow::closeEvent() */
207 void closeEvent(QCloseEvent* event) override;
208
209 /** @see KMainWindow::saveProperties() */
210 void saveProperties(KConfigGroup& group) override;
211
212 /** @see KMainWindow::readProperties() */
213 void readProperties(const KConfigGroup& group) override;
214
215 /** Handles QWhatsThisClickedEvent and passes all others on. */
216 bool event(QEvent* event) override;
217 /** Handles QWhatsThisClickedEvent and passes all others on. */
218 bool eventFilter(QObject*, QEvent*) override;
219
220 private slots:
221 /**
222 * Refreshes the views of the main window by recreating them according to
223 * the given Dolphin settings.
224 */
225 void refreshViews();
226
227 void clearStatusBar();
228
229 /** Updates the 'Create New...' sub menu. */
230 void updateNewMenu();
231
232 void createDirectory();
233
234 /** Shows the error message in the status bar of the active view. */
235 void showErrorMessage(const QString& message);
236
237 /**
238 * Updates the state of the 'Undo' menu action dependent
239 * on the parameter \a available.
240 */
241 void slotUndoAvailable(bool available);
242
243 /** Sets the text of the 'Undo' menu action to \a text. */
244 void slotUndoTextChanged(const QString& text);
245
246 /** Performs the current undo operation. */
247 void undo();
248
249 /**
250 * Copies all selected items to the clipboard and marks
251 * the items as cut.
252 */
253 void cut();
254
255 /** Copies all selected items to the clipboard. */
256 void copy();
257
258 /** Pastes the clipboard data to the active view. */
259 void paste();
260
261 /** Replaces the URL navigator by a search box to find files. */
262 void find();
263
264 /** Updates the state of the search action according to the view container. */
265 void updateSearchAction();
266
267 /**
268 * Updates the text of the paste action dependent on
269 * the number of items which are in the clipboard.
270 */
271 void updatePasteAction();
272
273 /** Selects all items from the active view. */
274 void selectAll();
275
276 /**
277 * Inverts the selection of all items of the active view:
278 * Selected items get nonselected and nonselected items get
279 * selected.
280 */
281 void invertSelection();
282
283 /**
284 * Switches between one and two views:
285 * If one view is visible, it will get split into two views.
286 * If already two views are visible, the active view gets closed.
287 */
288 void toggleSplitView();
289
290 /** Dedicated action to open the stash:/ ioslave in split view. */
291 void toggleSplitStash();
292
293 /** Reloads the currently active view. */
294 void reloadView();
295
296 /** Stops the loading process for the currently active view. */
297 void stopLoading();
298
299 void enableStopAction();
300 void disableStopAction();
301
302 void showFilterBar();
303
304 /**
305 * Toggles between edit and browse mode of the navigation bar.
306 */
307 void toggleEditLocation();
308
309 /**
310 * Switches to the edit mode of the navigation bar and selects
311 * the whole URL, so that it can be replaced by the user. If the edit mode is
312 * already active, it is assured that the navigation bar get focused.
313 */
314 void replaceLocation();
315
316 /**
317 * Toggles the state of the panels between a locked and unlocked layout.
318 */
319 void togglePanelLockState();
320
321 /**
322 * Is invoked if the Terminal panel got visible/invisible and takes care
323 * that the active view has the focus if the Terminal panel is invisible.
324 */
325 void slotTerminalPanelVisibilityChanged();
326
327 /** Goes back one step of the URL history. */
328 void goBack();
329
330 /** Goes forward one step of the URL history. */
331 void goForward();
332
333 /** Goes up one hierarchy of the current URL. */
334 void goUp();
335
336 /** Changes the location to the home URL. */
337 void goHome();
338
339 /** Open the previous URL in the URL history in a new tab. */
340 void goBackInNewTab();
341
342 /** Open the next URL in the URL history in a new tab. */
343 void goForwardInNewTab();
344
345 /** Open the URL one hierarchy above the current URL in a new tab. */
346 void goUpInNewTab();
347
348 /** * Open the home URL in a new tab. */
349 void goHomeInNewTab();
350
351 /** Opens Kompare for 2 selected files. */
352 void compareFiles();
353
354 /**
355 * Hides the menu bar if it is visible, makes the menu bar
356 * visible if it is hidden.
357 */
358 void toggleShowMenuBar();
359
360 /** Updates "Open Preferred Search Tool" action. */
361 void updateOpenPreferredSearchToolAction();
362
363 /** Opens preferred search tool for the current location. */
364 void openPreferredSearchTool();
365
366 /** Opens a terminal window for the current location. */
367 void openTerminal();
368
369 /** Focus a Terminal Panel. */
370 void focusTerminalPanel();
371
372 /** Opens the settings dialog for Dolphin. */
373 void editSettings();
374
375 /** Updates the state of the 'Show Full Location' action. */
376 void slotEditableStateChanged(bool editable);
377
378 /**
379 * Updates the state of the 'Edit' menu actions and emits
380 * the signal selectionChanged().
381 */
382 void slotSelectionChanged(const KFileItemList& selection);
383
384 /**
385 * Updates the state of the 'Back' and 'Forward' menu
386 * actions corresponding to the current history.
387 */
388 void updateHistory();
389
390 /** Updates the state of the 'Show filter bar' menu action. */
391 void updateFilterBarAction(bool show);
392
393 /** Open a new main window. */
394 void openNewMainWindow();
395
396 /**
397 * Opens a new view with the current URL that is part of a tab and
398 * activates it.
399 */
400 void openNewActivatedTab();
401
402 /**
403 * Adds the current URL as an entry to the Places panel
404 */
405 void addToPlaces();
406
407 /**
408 * Opens a new tab in the background showing the URL \a url.
409 */
410 void openNewTab(const QUrl& url, DolphinTabWidget::TabPlacement tabPlacement);
411
412 /**
413 * Opens the selected folder in a new tab.
414 */
415 void openInNewTab();
416
417 /**
418 * Opens the selected folder in a new window.
419 */
420 void openInNewWindow();
421
422 /**
423 * Show the target of the selected symlink
424 */
425 void showTarget();
426
427 /**
428 * Indicates in the statusbar that the execution of the command \a command
429 * has been finished.
430 */
431 void showCommand(CommandType command);
432
433 /**
434 * If the URL can be listed, open it in the current view, otherwise
435 * run it through KRun.
436 */
437 void handleUrl(const QUrl& url);
438
439 /**
440 * Is invoked when the write state of a folder has been changed and
441 * enables/disables the "Create New..." menu entry.
442 */
443 void slotWriteStateChanged(bool isFolderWritable);
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 QUrl& url,
457 const QList<QAction*>& customActions);
458
459 void updateControlMenu();
460 void updateToolBar();
461 void slotControlButtonDeleted();
462
463 /**
464 * Is called if the user clicked an item in the Places Panel.
465 * Reloads the view if \a url is the current URL already, and changes the
466 * current URL otherwise.
467 */
468 void slotPlaceActivated(const QUrl& url);
469
470 /**
471 * Is called if the another view has been activated by changing the current
472 * tab or activating another view in split-view mode.
473 *
474 * Activates the given view, which means that all menu actions are applied
475 * to this view. When having a split view setup, the nonactive view is
476 * usually shown in darker colors.
477 */
478 void activeViewChanged(DolphinViewContainer* viewContainer);
479
480 void closedTabsCountChanged(unsigned int count);
481
482 /**
483 * Is called if a new tab has been opened or a tab has been closed to
484 * enable/disable the tab actions.
485 */
486 void tabCountChanged(int count);
487
488 /**
489 * Updates the Window Title with the caption from the active view container
490 */
491 void updateWindowTitle();
492
493 /**
494 * This slot is called when the user requested to unmount a removable media
495 * from the places menu
496 */
497 void slotStorageTearDownFromPlacesRequested(const QString& mountPath);
498
499 /**
500 * This slot is called when the user requested to unmount a removable media
501 * _not_ from the dolphin's places menu (from the notification area for e.g.)
502 * This slot is basically connected to each removable device's
503 * Solid::StorageAccess::teardownRequested(const QString & udi)
504 * signal through the places panel.
505 */
506 void slotStorageTearDownExternallyRequested(const QString& mountPath);
507
508 /**
509 * Is called when the view has finished loading the directory.
510 */
511 void slotDirectoryLoadingCompleted();
512
513 /**
514 * Is called when the user middle clicks a toolbar button.
515 *
516 * Here middle clicking Back/Forward/Up/Home will open the resulting
517 * folder in a new tab.
518 */
519 void slotToolBarActionMiddleClicked(QAction *action);
520
521 /**
522 * Is called before the Back popup menu is shown. This slot will populate
523 * the menu with history data
524 */
525 void slotAboutToShowBackPopupMenu();
526
527 /**
528 * This slot is used by the Back Popup Menu to go back to a specific
529 * history index. The QAction::data will carry an int with the index
530 * to go to.
531 */
532 void slotGoBack(QAction* action);
533
534 /**
535 * Middle clicking Back/Forward will open the resulting folder in a new tab.
536 */
537 void slotBackForwardActionMiddleClicked(QAction *action);
538
539 /**
540 * Is called before the Forward popup menu is shown. This slot will populate
541 * the menu with history data
542 */
543 void slotAboutToShowForwardPopupMenu();
544
545 /**
546 * This slot is used by the Forward Popup Menu to go forward to a specific
547 * history index. The QAction::data will carry an int with the index
548 * to go to.
549 */
550 void slotGoForward(QAction* action);
551 private:
552 /**
553 * Sets up the various menus and actions and connects them.
554 */
555 void setupActions();
556
557 /**
558 * Sets up the dock widgets and their panels.
559 */
560 void setupDockWidgets();
561
562 void updateFileAndEditActions();
563 void updateViewActions();
564 void updateGoActions();
565
566 void createControlButton();
567 void deleteControlButton();
568
569 /**
570 * Adds the action \p action to the menu \p menu in
571 * case if it has not added already to the toolbar.
572 * @return True if the action has been added to the menu.
573 */
574 bool addActionToMenu(QAction* action, QMenu* menu);
575
576 /**
577 * Connects the signals from the created DolphinView with
578 * the DolphinViewContainer \a container with the corresponding slots of
579 * the DolphinMainWindow. This method must be invoked each
580 * time a DolphinView has been created.
581 */
582 void connectViewSignals(DolphinViewContainer* container);
583
584 /**
585 * Updates the text of the split action:
586 * If two views are shown, the text is set to "Split",
587 * otherwise the text is set to "Join". The icon
588 * is updated to match with the text and the currently active view.
589 */
590 void updateSplitAction();
591
592 bool isKompareInstalled() const;
593
594 /**
595 * Creates an action for showing/hiding a panel, that is accessible
596 * in "Configure toolbars..." and "Configure shortcuts...". This is necessary
597 * as the action for toggling the dock visibility is done by Qt which
598 * is no KAction instance.
599 */
600 void createPanelAction(const QIcon &icon,
601 const QKeySequence& shortcut,
602 QAction* dockAction,
603 const QString& actionName);
604
605 /** Adds "What's This?" texts to many widgets and StandardActions. */
606 void setupWhatsThis();
607
608 /**
609 * Returns the KIO::StatJob::mostLocalUrl() for the active container URL
610 * if it's a local file. Otherwise returns the user's home path.
611 */
612 QString activeContainerLocalPath();
613
614 /** Returns preferred search tool as configured in "More Search Tools" menu. */
615 QPointer<QAction> preferredSearchTool();
616
617 private:
618 /**
619 * Implements a custom error handling for the undo manager. This
620 * assures that all errors are shown in the status bar of Dolphin
621 * instead as modal error dialog with an OK button.
622 */
623 class UndoUiInterface : public KIO::FileUndoManager::UiInterface
624 {
625 public:
626 UndoUiInterface();
627 ~UndoUiInterface() override;
628 void jobError(KIO::Job* job) override;
629 };
630
631 KNewFileMenu* m_newFileMenu;
632 KHelpMenu* m_helpMenu;
633 DolphinTabWidget* m_tabWidget;
634 DolphinViewContainer* m_activeViewContainer;
635
636 DolphinViewActionHandler* m_actionHandler;
637 DolphinRemoteEncoding* m_remoteEncoding;
638 QPointer<DolphinSettingsDialog> m_settingsDialog;
639 DolphinBookmarkHandler* m_bookmarkHandler;
640
641 // Members for the toolbar menu that is shown when the menubar is hidden:
642 QToolButton* m_controlButton;
643 QTimer* m_updateToolBarTimer;
644
645 KIO::OpenUrlJob *m_lastHandleUrlOpenJob;
646
647 TerminalPanel* m_terminalPanel;
648 PlacesPanel* m_placesPanel;
649 bool m_tearDownFromPlacesRequested;
650
651 KToolBarPopupAction* m_backAction;
652 KToolBarPopupAction* m_forwardAction;
653
654 QMenu m_searchTools;
655
656 };
657
658 inline DolphinViewContainer* DolphinMainWindow::activeViewContainer() const
659 {
660 return m_activeViewContainer;
661 }
662
663 inline KNewFileMenu* DolphinMainWindow::newFileMenu() const
664 {
665 return m_newFileMenu;
666 }
667
668 #endif // DOLPHIN_MAINWINDOW_H
669