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