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