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