]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.h
Merge branch 'KDE/4.14'
[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 <KFileItemDelegate>
28 #include <kio/fileundomanager.h>
29 #include <ksortablelist.h>
30 #include <kxmlguiwindow.h>
31 #include <KIcon>
32
33 #include <QList>
34 #include <QWeakPointer>
35
36 typedef KIO::FileUndoManager::CommandType CommandType;
37
38 class DolphinViewActionHandler;
39 class DolphinApplication;
40 class DolphinSettingsDialog;
41 class DolphinViewContainer;
42 class DolphinRemoteEncoding;
43 class DolphinTabWidget;
44 class KAction;
45 class KFileItem;
46 class KFileItemList;
47 class KJob;
48 class KNewFileMenu;
49 class KUrl;
50 class QToolButton;
51
52 /**
53 * @short Main window for Dolphin.
54 *
55 * Handles the menus, toolbars and Dolphin views.
56 */
57 class DolphinMainWindow: public KXmlGuiWindow
58 {
59 Q_OBJECT
60 Q_CLASSINFO("D-Bus Interface", "org.kde.dolphin.MainWindow")
61 Q_PROPERTY(int id READ getId SCRIPTABLE true)
62 friend class DolphinApplication;
63
64 public:
65 DolphinMainWindow();
66 virtual ~DolphinMainWindow();
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 * Opens each directory in \p dirs in a separate tab. If the "split view"
78 * option is enabled, 2 directories are collected within one tab.
79 */
80 void openDirectories(const QList<KUrl>& dirs);
81
82 /**
83 * Opens the directory which contains the files \p files
84 * and selects all files (implements the --select option
85 * of Dolphin).
86 */
87 void openFiles(const QList<KUrl>& files);
88
89 /**
90 * Returns the 'Create New...' sub menu which also can be shared
91 * with other menus (e. g. a context menu).
92 */
93 KNewFileMenu* newFileMenu() const;
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 * Returns the main window ID used through DBus.
105 */
106 int getId() const;
107
108 /**
109 * Implementation of the MainWindowAdaptor/QDBusAbstractAdaptor interface.
110 * Inform all affected dolphin components (panels, views) of an URL
111 * change.
112 */
113 void changeUrl(const KUrl& url);
114
115 /**
116 * The current directory of the Terminal Panel has changed, probably because
117 * the user entered a 'cd' command. This slot calls changeUrl(url) and makes
118 * sure that the panel keeps the keyboard focus.
119 */
120 void slotTerminalDirectoryChanged(const KUrl& url);
121
122 /** Stores all settings and quits Dolphin. */
123 void quit();
124
125 signals:
126 /**
127 * Is sent if the selection of the currently active view has
128 * been changed.
129 */
130 void selectionChanged(const KFileItemList& selection);
131
132 /**
133 * Is sent if the url of the currently active view has
134 * been changed.
135 */
136 void urlChanged(const KUrl& url);
137
138 /**
139 * Is emitted if information of an item is requested to be shown e. g. in the panel.
140 * If item is null, no item information request is pending.
141 */
142 void requestItemInfo(const KFileItem& item);
143
144 /**
145 * Is emitted if the settings have been changed.
146 */
147 void settingsChanged();
148
149 protected:
150 /** @see QWidget::showEvent() */
151 virtual void showEvent(QShowEvent* event);
152
153 /** @see QMainWindow::closeEvent() */
154 virtual void closeEvent(QCloseEvent* event);
155
156 /** @see KMainWindow::saveProperties() */
157 virtual void saveProperties(KConfigGroup& group);
158
159 /** @see KMainWindow::readProperties() */
160 virtual void readProperties(const KConfigGroup& group);
161
162 private slots:
163 /**
164 * Refreshes the views of the main window by recreating them according to
165 * the given Dolphin settings.
166 */
167 void refreshViews();
168
169 void clearStatusBar();
170
171 /** Updates the 'Create New...' sub menu. */
172 void updateNewMenu();
173
174 void createDirectory();
175
176 /** Shows the error message in the status bar of the active view. */
177 void showErrorMessage(const QString& message);
178
179 /**
180 * Updates the state of the 'Undo' menu action dependent
181 * on the parameter \a available.
182 */
183 void slotUndoAvailable(bool available);
184
185 /** Sets the text of the 'Undo' menu action to \a text. */
186 void slotUndoTextChanged(const QString& text);
187
188 /** Performs the current undo operation. */
189 void undo();
190
191 /**
192 * Copies all selected items to the clipboard and marks
193 * the items as cut.
194 */
195 void cut();
196
197 /** Copies all selected items to the clipboard. */
198 void copy();
199
200 /** Pastes the clipboard data to the active view. */
201 void paste();
202
203 /** Replaces the URL navigator by a search box to find files. */
204 void find();
205
206 /**
207 * Updates the text of the paste action dependent on
208 * the number of items which are in the clipboard.
209 */
210 void updatePasteAction();
211
212 /** Selects all items from the active view. */
213 void selectAll();
214
215 /**
216 * Inverts the selection of all items of the active view:
217 * Selected items get nonselected and nonselected items get
218 * selected.
219 */
220 void invertSelection();
221
222 /**
223 * Switches between one and two views:
224 * If one view is visible, it will get split into two views.
225 * If already two views are visible, the active view gets closed.
226 */
227 void toggleSplitView();
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 /** Emits the signal requestItemInfo(). */
317 void slotRequestItemInfo(const KFileItem&);
318
319 /**
320 * Updates the state of the 'Back' and 'Forward' menu
321 * actions corresponding to the current history.
322 */
323 void updateHistory();
324
325 /** Updates the state of the 'Show filter bar' menu action. */
326 void updateFilterBarAction(bool show);
327
328 /** Open a new main window. */
329 void openNewMainWindow();
330
331 /**
332 * Opens a new view with the current URL that is part of a tab and
333 * activates it.
334 */
335 void openNewActivatedTab();
336
337 /**
338 * Opens a new tab in the background showing the URL \a primaryUrl and the
339 * optional URL \a secondaryUrl.
340 */
341 void openNewTab(const KUrl& primaryUrl, const KUrl& secondaryUrl = KUrl());
342
343 /**
344 * Opens a new tab showing the URL \a primaryUrl and the optional URL
345 * \a secondaryUrl and activates the tab.
346 */
347 void openNewActivatedTab(const KUrl& primaryUrl, const KUrl& secondaryUrl = KUrl());
348
349 /**
350 * Opens the selected folder in a new tab.
351 */
352 void openInNewTab();
353
354 /**
355 * Opens the selected folder in a new window.
356 */
357 void openInNewWindow();
358
359 /**
360 * Indicates in the statusbar that the execution of the command \a command
361 * has been finished.
362 */
363 void showCommand(CommandType command);
364
365 /**
366 * If the URL can be listed, open it in the current view, otherwise
367 * run it through KRun.
368 */
369 void handleUrl(const KUrl& url);
370
371 /**
372 * handleUrl() can trigger a stat job to see if the url can actually
373 * be listed.
374 */
375 void slotHandleUrlStatFinished(KJob* job);
376
377 /**
378 * Is invoked when the write state of a folder has been changed and
379 * enables/disables the "Create New..." menu entry.
380 */
381 void slotWriteStateChanged(bool isFolderWritable);
382
383 /**
384 * Opens the context menu on the current mouse position.
385 * @pos Position in screen coordinates.
386 * @item File item context. If item is null, the context menu
387 * should be applied to \a url.
388 * @url URL which contains \a item.
389 * @customActions Actions that should be added to the context menu,
390 * if the file item is null.
391 */
392 void openContextMenu(const QPoint& pos,
393 const KFileItem& item,
394 const KUrl& url,
395 const QList<QAction*>& customActions);
396
397 void updateControlMenu();
398 void updateToolBar();
399 void slotControlButtonDeleted();
400
401 /**
402 * Is called if a panel emits an error-message and shows
403 * the error-message in the active view-container.
404 */
405 void slotPanelErrorMessage(const QString& error);
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 KUrl& 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 * Sets the window caption to url.fileName() if this is non-empty,
434 * "/" if the URL is "file:///", and url.protocol() otherwise.
435 */
436 void setUrlAsCaption(const KUrl& url);
437
438 private:
439 void setupActions();
440 void setupDockWidgets();
441 void updateEditActions();
442 void updateViewActions();
443 void updateGoActions();
444
445 void createControlButton();
446 void deleteControlButton();
447
448 /**
449 * Adds the action \p action to the menu \p menu in
450 * case if it has not added already to the toolbar.
451 * @return True if the action has been added to the menu.
452 */
453 bool addActionToMenu(QAction* action, KMenu* menu);
454
455 /**
456 * Connects the signals from the created DolphinView with
457 * the DolphinViewContainer \a container with the corresponding slots of
458 * the DolphinMainWindow. This method must be invoked each
459 * time a DolphinView has been created.
460 */
461 void connectViewSignals(DolphinViewContainer* container);
462
463 /**
464 * Updates the text of the split action:
465 * If two views are shown, the text is set to "Split",
466 * otherwise the text is set to "Join". The icon
467 * is updated to match with the text and the currently active view.
468 */
469 void updateSplitAction();
470
471 bool isKompareInstalled() const;
472
473 /**
474 * Creates an action for showing/hiding a panel, that is accessible
475 * in "Configure toolbars..." and "Configure shortcuts...". This is necessary
476 * as the action for toggling the dock visibility is done by Qt which
477 * is no KAction instance.
478 */
479 void createPanelAction(const KIcon& icon,
480 const QKeySequence& shortcut,
481 QAction* dockAction,
482 const QString& actionName);
483
484 private:
485 /**
486 * Implements a custom error handling for the undo manager. This
487 * assures that all errors are shown in the status bar of Dolphin
488 * instead as modal error dialog with an OK button.
489 */
490 class UndoUiInterface : public KIO::FileUndoManager::UiInterface
491 {
492 public:
493 UndoUiInterface();
494 virtual ~UndoUiInterface();
495 virtual void jobError(KIO::Job* job);
496 };
497
498 KNewFileMenu* m_newFileMenu;
499 DolphinTabWidget* m_tabWidget;
500 DolphinViewContainer* m_activeViewContainer;
501 int m_id;
502
503 DolphinViewActionHandler* m_actionHandler;
504 DolphinRemoteEncoding* m_remoteEncoding;
505 QWeakPointer<DolphinSettingsDialog> m_settingsDialog;
506
507 // Members for the toolbar menu that is shown when the menubar is hidden:
508 QToolButton* m_controlButton;
509 QTimer* m_updateToolBarTimer;
510
511 KIO::Job* m_lastHandleUrlStatJob;
512 };
513
514 inline DolphinViewContainer* DolphinMainWindow::activeViewContainer() const
515 {
516 return m_activeViewContainer;
517 }
518
519 inline KNewFileMenu* DolphinMainWindow::newFileMenu() const
520 {
521 return m_newFileMenu;
522 }
523
524 inline int DolphinMainWindow::getId() const
525 {
526 return m_id;
527 }
528
529 #endif // DOLPHIN_MAINWINDOW_H
530