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