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