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