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