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