]> 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 <KFileItemDelegate>
28 #include <kio/fileundomanager.h>
29 #include <ksortablelist.h>
30 #include <kxmlguiwindow.h>
31 #include <QIcon>
32 #include <KUrl>
33
34 #include <QList>
35 #include <QWeakPointer>
36
37 typedef KIO::FileUndoManager::CommandType CommandType;
38
39 class DolphinViewActionHandler;
40 class DolphinApplication;
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 QToolButton;
50 class QIcon;
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 url.
339 */
340 void openNewTab(const KUrl& url);
341
342 /**
343 * Opens a new tab showing the URL \a url and activates the tab.
344 */
345 void openNewActivatedTab(const KUrl& url);
346
347 /**
348 * Opens the selected folder in a new tab.
349 */
350 void openInNewTab();
351
352 /**
353 * Opens the selected folder in a new window.
354 */
355 void openInNewWindow();
356
357 /**
358 * Indicates in the statusbar that the execution of the command \a command
359 * has been finished.
360 */
361 void showCommand(CommandType command);
362
363 /**
364 * If the URL can be listed, open it in the current view, otherwise
365 * run it through KRun.
366 */
367 void handleUrl(const KUrl& url);
368
369 /**
370 * handleUrl() can trigger a stat job to see if the url can actually
371 * be listed.
372 */
373 void slotHandleUrlStatFinished(KJob* job);
374
375 /**
376 * Is invoked when the write state of a folder has been changed and
377 * enables/disables the "Create New..." menu entry.
378 */
379 void slotWriteStateChanged(bool isFolderWritable);
380
381 /**
382 * Opens the context menu on the current mouse position.
383 * @pos Position in screen coordinates.
384 * @item File item context. If item is null, the context menu
385 * should be applied to \a url.
386 * @url URL which contains \a item.
387 * @customActions Actions that should be added to the context menu,
388 * if the file item is null.
389 */
390 void openContextMenu(const QPoint& pos,
391 const KFileItem& item,
392 const KUrl& url,
393 const QList<QAction*>& customActions);
394
395 void updateControlMenu();
396 void updateToolBar();
397 void slotControlButtonDeleted();
398
399 /**
400 * Is called if a panel emits an error-message and shows
401 * the error-message in the active view-container.
402 */
403 void slotPanelErrorMessage(const QString& error);
404
405 /**
406 * Is called if the user clicked an item in the Places Panel.
407 * Reloads the view if \a url is the current URL already, and changes the
408 * current URL otherwise.
409 */
410 void slotPlaceActivated(const KUrl& url);
411
412 /**
413 * Is called if the another view has been activated by changing the current
414 * tab or activating another view in split-view mode.
415 *
416 * Activates the given view, which means that all menu actions are applied
417 * to this view. When having a split view setup, the nonactive view is
418 * usually shown in darker colors.
419 */
420 void activeViewChanged(DolphinViewContainer* viewContainer);
421
422 void closedTabsCountChanged(unsigned int count);
423
424 /**
425 * Is called if a new tab has been opened or a tab has been closed to
426 * enable/disable the tab actions.
427 */
428 void tabCountChanged(int count);
429
430 /**
431 * Sets the window caption to url.fileName() if this is non-empty,
432 * "/" if the URL is "file:///", and url.protocol() otherwise.
433 */
434 void setUrlAsCaption(const KUrl& url);
435
436 private:
437 void setupActions();
438 void setupDockWidgets();
439 void updateEditActions();
440 void updateViewActions();
441 void updateGoActions();
442
443 void createControlButton();
444 void deleteControlButton();
445
446 /**
447 * Adds the action \p action to the menu \p menu in
448 * case if it has not added already to the toolbar.
449 * @return True if the action has been added to the menu.
450 */
451 bool addActionToMenu(QAction* action, KMenu* menu);
452
453 /**
454 * Connects the signals from the created DolphinView with
455 * the DolphinViewContainer \a container with the corresponding slots of
456 * the DolphinMainWindow. This method must be invoked each
457 * time a DolphinView has been created.
458 */
459 void connectViewSignals(DolphinViewContainer* container);
460
461 /**
462 * Updates the text of the split action:
463 * If two views are shown, the text is set to "Split",
464 * otherwise the text is set to "Join". The icon
465 * is updated to match with the text and the currently active view.
466 */
467 void updateSplitAction();
468
469 bool isKompareInstalled() const;
470
471 /**
472 * Creates an action for showing/hiding a panel, that is accessible
473 * in "Configure toolbars..." and "Configure shortcuts...". This is necessary
474 * as the action for toggling the dock visibility is done by Qt which
475 * is no KAction instance.
476 */
477 void createPanelAction(const QIcon &icon,
478 const QKeySequence& shortcut,
479 QAction* dockAction,
480 const QString& actionName);
481
482 private:
483 /**
484 * Implements a custom error handling for the undo manager. This
485 * assures that all errors are shown in the status bar of Dolphin
486 * instead as modal error dialog with an OK button.
487 */
488 class UndoUiInterface : public KIO::FileUndoManager::UiInterface
489 {
490 public:
491 UndoUiInterface();
492 virtual ~UndoUiInterface();
493 virtual void jobError(KIO::Job* job);
494 };
495
496 KNewFileMenu* m_newFileMenu;
497 DolphinTabWidget* m_tabWidget;
498 DolphinViewContainer* m_activeViewContainer;
499 int m_id;
500
501 DolphinViewActionHandler* m_actionHandler;
502 DolphinRemoteEncoding* m_remoteEncoding;
503 QWeakPointer<DolphinSettingsDialog> m_settingsDialog;
504
505 // Members for the toolbar menu that is shown when the menubar is hidden:
506 QToolButton* m_controlButton;
507 QTimer* m_updateToolBarTimer;
508
509 KIO::Job* m_lastHandleUrlStatJob;
510 };
511
512 inline DolphinViewContainer* DolphinMainWindow::activeViewContainer() const
513 {
514 return m_activeViewContainer;
515 }
516
517 inline KNewFileMenu* DolphinMainWindow::newFileMenu() const
518 {
519 return m_newFileMenu;
520 }
521
522 inline int DolphinMainWindow::getId() const
523 {
524 return m_id;
525 }
526
527 #endif // DOLPHIN_MAINWINDOW_H
528