]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.h
Fix some compile warnings
[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 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);
332
333 /**
334 * Opens the selected folder in a new tab.
335 */
336 void openInNewTab();
337
338 /**
339 * Opens the selected folder in a new window.
340 */
341 void openInNewWindow();
342
343 /**
344 * Indicates in the statusbar that the execution of the command \a command
345 * has been finished.
346 */
347 void showCommand(CommandType command);
348
349 /**
350 * If the URL can be listed, open it in the current view, otherwise
351 * run it through KRun.
352 */
353 void handleUrl(const QUrl& url);
354
355 /**
356 * handleUrl() can trigger a stat job to see if the url can actually
357 * be listed.
358 */
359 void slotHandleUrlStatFinished(KJob* job);
360
361 /**
362 * Is invoked when the write state of a folder has been changed and
363 * enables/disables the "Create New..." menu entry.
364 */
365 void slotWriteStateChanged(bool isFolderWritable);
366
367 /**
368 * Opens the context menu on the current mouse position.
369 * @pos Position in screen coordinates.
370 * @item File item context. If item is null, the context menu
371 * should be applied to \a url.
372 * @url URL which contains \a item.
373 * @customActions Actions that should be added to the context menu,
374 * if the file item is null.
375 */
376 void openContextMenu(const QPoint& pos,
377 const KFileItem& item,
378 const QUrl& url,
379 const QList<QAction*>& customActions);
380
381 void updateControlMenu();
382 void updateToolBar();
383 void slotControlButtonDeleted();
384
385 /**
386 * Is called if the user clicked an item in the Places Panel.
387 * Reloads the view if \a url is the current URL already, and changes the
388 * current URL otherwise.
389 */
390 void slotPlaceActivated(const QUrl& url);
391
392 /**
393 * Is called if the another view has been activated by changing the current
394 * tab or activating another view in split-view mode.
395 *
396 * Activates the given view, which means that all menu actions are applied
397 * to this view. When having a split view setup, the nonactive view is
398 * usually shown in darker colors.
399 */
400 void activeViewChanged(DolphinViewContainer* viewContainer);
401
402 void closedTabsCountChanged(unsigned int count);
403
404 /**
405 * Is called if a new tab has been opened or a tab has been closed to
406 * enable/disable the tab actions.
407 */
408 void tabCountChanged(int count);
409
410 /**
411 * Sets the window caption to url.fileName() if this is non-empty,
412 * "/" if the URL is "file:///", and url.protocol() otherwise.
413 */
414 void setUrlAsCaption(const QUrl& url);
415
416 /**
417 * This slot is called when the user requested to unmount a removable media
418 * from the places menu
419 */
420 void slotStorageTearDownFromPlacesRequested(const QString& mountPath);
421
422 /**
423 * This slot is called when the user requested to unmount a removable media
424 * _not_ from the dolphin's places menu (from the notification area for e.g.)
425 * This slot is basically connected to each removable device's
426 * Solid::StorageAccess::teardownRequested(const QString & udi)
427 * signal through the places panel.
428 */
429 void slotStorageTearDownExternallyRequested(const QString& mountPath);
430
431 /**
432 * Is called when the view has finished loading the directory.
433 */
434 void slotDirectoryLoadingCompleted();
435
436 /**
437 * Is called when the user middle clicks a toolbar button.
438 *
439 * Here middle clicking Back/Forward/Up/Home will open the resulting
440 * folder in a new tab.
441 */
442 void slotToolBarActionMiddleClicked(QAction *action);
443
444 private:
445 void setupActions();
446 void setupDockWidgets();
447 void updateEditActions();
448 void updateViewActions();
449 void updateGoActions();
450
451 void createControlButton();
452 void deleteControlButton();
453
454 /**
455 * Adds the action \p action to the menu \p menu in
456 * case if it has not added already to the toolbar.
457 * @return True if the action has been added to the menu.
458 */
459 bool addActionToMenu(QAction* action, QMenu* menu);
460
461 /**
462 * Connects the signals from the created DolphinView with
463 * the DolphinViewContainer \a container with the corresponding slots of
464 * the DolphinMainWindow. This method must be invoked each
465 * time a DolphinView has been created.
466 */
467 void connectViewSignals(DolphinViewContainer* container);
468
469 /**
470 * Updates the text of the split action:
471 * If two views are shown, the text is set to "Split",
472 * otherwise the text is set to "Join". The icon
473 * is updated to match with the text and the currently active view.
474 */
475 void updateSplitAction();
476
477 bool isKompareInstalled() const;
478
479 /**
480 * Creates an action for showing/hiding a panel, that is accessible
481 * in "Configure toolbars..." and "Configure shortcuts...". This is necessary
482 * as the action for toggling the dock visibility is done by Qt which
483 * is no KAction instance.
484 */
485 void createPanelAction(const QIcon &icon,
486 const QKeySequence& shortcut,
487 QAction* dockAction,
488 const QString& actionName);
489
490 private:
491 /**
492 * Implements a custom error handling for the undo manager. This
493 * assures that all errors are shown in the status bar of Dolphin
494 * instead as modal error dialog with an OK button.
495 */
496 class UndoUiInterface : public KIO::FileUndoManager::UiInterface
497 {
498 public:
499 UndoUiInterface();
500 ~UndoUiInterface() override;
501 void jobError(KIO::Job* job) override;
502 };
503
504 KNewFileMenu* m_newFileMenu;
505 DolphinTabWidget* m_tabWidget;
506 DolphinViewContainer* m_activeViewContainer;
507
508 DolphinViewActionHandler* m_actionHandler;
509 DolphinRemoteEncoding* m_remoteEncoding;
510 QPointer<DolphinSettingsDialog> m_settingsDialog;
511
512 // Members for the toolbar menu that is shown when the menubar is hidden:
513 QToolButton* m_controlButton;
514 QTimer* m_updateToolBarTimer;
515
516 KIO::Job* m_lastHandleUrlStatJob;
517
518 TerminalPanel* m_terminalPanel;
519 PlacesPanel* m_placesPanel;
520 bool m_tearDownFromPlacesRequested;
521 };
522
523 inline DolphinViewContainer* DolphinMainWindow::activeViewContainer() const
524 {
525 return m_activeViewContainer;
526 }
527
528 inline KNewFileMenu* DolphinMainWindow::newFileMenu() const
529 {
530 return m_newFileMenu;
531 }
532
533 #endif // DOLPHIN_MAINWINDOW_H
534