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