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