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