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