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