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