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