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