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