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