]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.h
Merge branch 'Applications/19.08'
[dolphin.git] / src / dolphinmainwindow.h
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz19@gmail.com> *
3 * Copyright (C) 2006 by Stefan Monov <logixoul@gmail.com> *
4 * Copyright (C) 2006 by Cvetoslav Ludmiloff <ludmiloff@gmail.com> *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20 ***************************************************************************/
21
22 #ifndef DOLPHIN_MAINWINDOW_H
23 #define DOLPHIN_MAINWINDOW_H
24
25 #include "dolphintabwidget.h"
26 #include <config-baloo.h>
27 #include <kio/fileundomanager.h>
28 #include <ksortablelist.h>
29 #include <kxmlguiwindow.h>
30
31 #include <QIcon>
32 #include <QList>
33 #include <QPointer>
34 #include <QUrl>
35 #include <QVector>
36
37 typedef KIO::FileUndoManager::CommandType CommandType;
38
39 class DolphinBookmarkHandler;
40 class DolphinViewActionHandler;
41 class DolphinSettingsDialog;
42 class DolphinViewContainer;
43 class DolphinRemoteEncoding;
44 class DolphinTabWidget;
45 class KFileItem;
46 class KFileItemList;
47 class KJob;
48 class KNewFileMenu;
49 class KHelpMenu;
50 class KToolBarPopupAction;
51 class QToolButton;
52 class QIcon;
53 class PlacesPanel;
54 class TerminalPanel;
55
56 /**
57 * @short Main window for Dolphin.
58 *
59 * Handles the menus, toolbars and Dolphin views.
60 */
61 class DolphinMainWindow: public KXmlGuiWindow
62 {
63 Q_OBJECT
64 Q_CLASSINFO("D-Bus Interface", "org.kde.dolphin.MainWindow")
65
66 public:
67 DolphinMainWindow();
68 ~DolphinMainWindow() override;
69
70 /**
71 * Returns the currently active view.
72 * All menu actions are applied to this view. When
73 * having a split view setup, the nonactive view
74 * is usually shown in darker colors.
75 */
76 DolphinViewContainer* activeViewContainer() const;
77
78 /**
79 * Returns view container for all tabs
80 */
81 QVector<DolphinViewContainer*> viewContainers() const;
82
83 /**
84 * Opens each directory in \p dirs in a separate tab. If \a splitView is set,
85 * 2 directories are collected within one tab.
86 * \pre \a dirs must contain at least one url.
87 */
88 void openDirectories(const QList<QUrl> &dirs, bool splitView);
89
90 /**
91 * Opens the directories which contain the files \p files and selects all files.
92 * If \a splitView is set, 2 directories are collected within one tab.
93 * \pre \a files must contain at least one url.
94 */
95 void openFiles(const QList<QUrl>& files, bool splitView);
96
97 /**
98 * Returns the 'Create New...' sub menu which also can be shared
99 * with other menus (e. g. a context menu).
100 */
101 KNewFileMenu* newFileMenu() const;
102
103 void setTabsToHomeIfMountPathOpen(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 /** Opens a terminal window for the current location. */
356 void openTerminal();
357
358 /** Opens the settings dialog for Dolphin. */
359 void editSettings();
360
361 /** Updates the state of the 'Show Full Location' action. */
362 void slotEditableStateChanged(bool editable);
363
364 /**
365 * Updates the state of the 'Edit' menu actions and emits
366 * the signal selectionChanged().
367 */
368 void slotSelectionChanged(const KFileItemList& selection);
369
370 /**
371 * Updates the state of the 'Back' and 'Forward' menu
372 * actions corresponding to the current history.
373 */
374 void updateHistory();
375
376 /** Updates the state of the 'Show filter bar' menu action. */
377 void updateFilterBarAction(bool show);
378
379 /** Open a new main window. */
380 void openNewMainWindow();
381
382 /**
383 * Opens a new view with the current URL that is part of a tab and
384 * activates it.
385 */
386 void openNewActivatedTab();
387
388 /**
389 * Adds the current URL as an entry to the Places panel
390 */
391 void addToPlaces();
392
393 /**
394 * Opens a new tab in the background showing the URL \a url.
395 */
396 void openNewTab(const QUrl& url, DolphinTabWidget::TabPlacement tabPlacement);
397
398 /**
399 * Opens the selected folder in a new tab.
400 */
401 void openInNewTab();
402
403 /**
404 * Opens the selected folder in a new window.
405 */
406 void openInNewWindow();
407
408 /**
409 * Show the target of the selected symlink
410 */
411 void showTarget();
412
413 /**
414 * Indicates in the statusbar that the execution of the command \a command
415 * has been finished.
416 */
417 void showCommand(CommandType command);
418
419 /**
420 * If the URL can be listed, open it in the current view, otherwise
421 * run it through KRun.
422 */
423 void handleUrl(const QUrl& url);
424
425 /**
426 * handleUrl() can trigger a stat job to see if the url can actually
427 * be listed.
428 */
429 void slotHandleUrlStatFinished(KJob* job);
430
431 /**
432 * Is invoked when the write state of a folder has been changed and
433 * enables/disables the "Create New..." menu entry.
434 */
435 void slotWriteStateChanged(bool isFolderWritable);
436
437 /**
438 * Opens the context menu on the current mouse position.
439 * @pos Position in screen coordinates.
440 * @item File item context. If item is null, the context menu
441 * should be applied to \a url.
442 * @url URL which contains \a item.
443 * @customActions Actions that should be added to the context menu,
444 * if the file item is null.
445 */
446 void openContextMenu(const QPoint& pos,
447 const KFileItem& item,
448 const QUrl& url,
449 const QList<QAction*>& customActions);
450
451 void updateControlMenu();
452 void updateToolBar();
453 void slotControlButtonDeleted();
454
455 /**
456 * Is called if the user clicked an item in the Places Panel.
457 * Reloads the view if \a url is the current URL already, and changes the
458 * current URL otherwise.
459 */
460 void slotPlaceActivated(const QUrl& url);
461
462 /**
463 * Is called if the another view has been activated by changing the current
464 * tab or activating another view in split-view mode.
465 *
466 * Activates the given view, which means that all menu actions are applied
467 * to this view. When having a split view setup, the nonactive view is
468 * usually shown in darker colors.
469 */
470 void activeViewChanged(DolphinViewContainer* viewContainer);
471
472 void closedTabsCountChanged(unsigned int count);
473
474 /**
475 * Is called if a new tab has been opened or a tab has been closed to
476 * enable/disable the tab actions.
477 */
478 void tabCountChanged(int count);
479
480 /**
481 * Updates the Window Title with the caption from the active view container
482 */
483 void updateWindowTitle();
484
485 /**
486 * This slot is called when the user requested to unmount a removable media
487 * from the places menu
488 */
489 void slotStorageTearDownFromPlacesRequested(const QString& mountPath);
490
491 /**
492 * This slot is called when the user requested to unmount a removable media
493 * _not_ from the dolphin's places menu (from the notification area for e.g.)
494 * This slot is basically connected to each removable device's
495 * Solid::StorageAccess::teardownRequested(const QString & udi)
496 * signal through the places panel.
497 */
498 void slotStorageTearDownExternallyRequested(const QString& mountPath);
499
500 /**
501 * Is called when the view has finished loading the directory.
502 */
503 void slotDirectoryLoadingCompleted();
504
505 /**
506 * Is called when the user middle clicks a toolbar button.
507 *
508 * Here middle clicking Back/Forward/Up/Home will open the resulting
509 * folder in a new tab.
510 */
511 void slotToolBarActionMiddleClicked(QAction *action);
512
513 /**
514 * Is called before the Back popup menu is shown. This slot will populate
515 * the menu with history data
516 */
517 void slotAboutToShowBackPopupMenu();
518
519 /**
520 * This slot is used by the Back Popup Menu to go back to a specific
521 * history index. The QAction::data will carry an int with the index
522 * to go to.
523 */
524 void slotGoBack(QAction* action);
525
526 /**
527 * Middle clicking Back/Forward will open the resulting folder in a new tab.
528 */
529 void slotBackForwardActionMiddleClicked(QAction *action);
530
531 /**
532 * Is called before the Forward popup menu is shown. This slot will populate
533 * the menu with history data
534 */
535 void slotAboutToShowForwardPopupMenu();
536
537 /**
538 * This slot is used by the Forward Popup Menu to go forward to a specific
539 * history index. The QAction::data will carry an int with the index
540 * to go to.
541 */
542 void slotGoForward(QAction* action);
543 private:
544 /**
545 * Sets up the various menus and actions and connects them.
546 */
547 void setupActions();
548
549 /**
550 * Sets up the dock widgets and their panels.
551 */
552 void setupDockWidgets();
553
554 void updateFileAndEditActions();
555 void updateViewActions();
556 void updateGoActions();
557
558 void createControlButton();
559 void deleteControlButton();
560
561 /**
562 * Adds the action \p action to the menu \p menu in
563 * case if it has not added already to the toolbar.
564 * @return True if the action has been added to the menu.
565 */
566 bool addActionToMenu(QAction* action, QMenu* menu);
567
568 /**
569 * Connects the signals from the created DolphinView with
570 * the DolphinViewContainer \a container with the corresponding slots of
571 * the DolphinMainWindow. This method must be invoked each
572 * time a DolphinView has been created.
573 */
574 void connectViewSignals(DolphinViewContainer* container);
575
576 /**
577 * Updates the text of the split action:
578 * If two views are shown, the text is set to "Split",
579 * otherwise the text is set to "Join". The icon
580 * is updated to match with the text and the currently active view.
581 */
582 void updateSplitAction();
583
584 bool isKompareInstalled() const;
585
586 /**
587 * Creates an action for showing/hiding a panel, that is accessible
588 * in "Configure toolbars..." and "Configure shortcuts...". This is necessary
589 * as the action for toggling the dock visibility is done by Qt which
590 * is no KAction instance.
591 */
592 void createPanelAction(const QIcon &icon,
593 const QKeySequence& shortcut,
594 QAction* dockAction,
595 const QString& actionName);
596
597 /** Adds "What's This?" texts to many widgets and StandardActions. */
598 void setupWhatsThis();
599
600 private:
601 /**
602 * Implements a custom error handling for the undo manager. This
603 * assures that all errors are shown in the status bar of Dolphin
604 * instead as modal error dialog with an OK button.
605 */
606 class UndoUiInterface : public KIO::FileUndoManager::UiInterface
607 {
608 public:
609 UndoUiInterface();
610 ~UndoUiInterface() override;
611 void jobError(KIO::Job* job) override;
612 };
613
614 KNewFileMenu* m_newFileMenu;
615 KHelpMenu* m_helpMenu;
616 DolphinTabWidget* m_tabWidget;
617 DolphinViewContainer* m_activeViewContainer;
618
619 DolphinViewActionHandler* m_actionHandler;
620 DolphinRemoteEncoding* m_remoteEncoding;
621 QPointer<DolphinSettingsDialog> m_settingsDialog;
622 DolphinBookmarkHandler* m_bookmarkHandler;
623
624 // Members for the toolbar menu that is shown when the menubar is hidden:
625 QToolButton* m_controlButton;
626 QTimer* m_updateToolBarTimer;
627
628 KIO::Job* m_lastHandleUrlStatJob;
629
630 TerminalPanel* m_terminalPanel;
631 PlacesPanel* m_placesPanel;
632 bool m_tearDownFromPlacesRequested;
633
634 KToolBarPopupAction* m_backAction;
635 KToolBarPopupAction* m_forwardAction;
636 };
637
638 inline DolphinViewContainer* DolphinMainWindow::activeViewContainer() const
639 {
640 return m_activeViewContainer;
641 }
642
643 inline KNewFileMenu* DolphinMainWindow::newFileMenu() const
644 {
645 return m_newFileMenu;
646 }
647
648 #endif // DOLPHIN_MAINWINDOW_H
649