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