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