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