]> 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 <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 KAction;
44 class KFileItem;
45 class KFileItemList;
46 class KJob;
47 class KNewFileMenu;
48 class KTabBar;
49 class KUrl;
50 class QSplitter;
51 class QToolButton;
52 class QVBoxLayout;
53 class QIcon;
54
55 /**
56 * @short Main window for Dolphin.
57 *
58 * Handles the menus, toolbars and Dolphin views.
59 */
60 class DolphinMainWindow: public KXmlGuiWindow
61 {
62 Q_OBJECT
63 Q_CLASSINFO("D-Bus Interface", "org.kde.dolphin.MainWindow")
64 Q_PROPERTY(int id READ getId SCRIPTABLE true)
65 friend class DolphinApplication;
66
67 public:
68 DolphinMainWindow();
69 virtual ~DolphinMainWindow();
70
71 /**
72 * Returns the currently active view.
73 * All menu actions are applied to this view. When
74 * having a split view setup, the nonactive view
75 * is usually shown in darker colors.
76 */
77 DolphinViewContainer* activeViewContainer() const;
78
79 /**
80 * Opens each directory in \p dirs in a separate tab. If the "split view"
81 * option is enabled, 2 directories are collected within one tab.
82 */
83 void openDirectories(const QList<KUrl>& dirs);
84
85 /**
86 * Opens the directory which contains the files \p files
87 * and selects all files (implements the --select option
88 * of Dolphin).
89 */
90 void openFiles(const QList<KUrl>& files);
91
92 /**
93 * Returns true, if the main window contains two instances
94 * of a view container. The active view constainer can be
95 * accessed by DolphinMainWindow::activeViewContainer().
96 */
97 bool isSplit() const;
98
99 /**
100 * Returns the 'Create New...' sub menu which also can be shared
101 * with other menus (e. g. a context menu).
102 */
103 KNewFileMenu* newFileMenu() const;
104
105 public slots:
106 /**
107 * Pastes the clipboard data into the currently selected folder
108 * of the active view. If not exactly one folder is selected,
109 * no pasting is done at all.
110 */
111 void pasteIntoFolder();
112
113 /**
114 * Returns the main window ID used through DBus.
115 */
116 int getId() const;
117
118 /**
119 * Implementation of the MainWindowAdaptor/QDBusAbstractAdaptor interface.
120 * Inform all affected dolphin components (panels, views) of an URL
121 * change.
122 */
123 void changeUrl(const KUrl& url);
124
125 /**
126 * The current directory of the Terminal Panel has changed, probably because
127 * the user entered a 'cd' command. This slot calls changeUrl(url) and makes
128 * sure that the panel keeps the keyboard focus.
129 */
130 void slotTerminalDirectoryChanged(const KUrl& url);
131
132 /** Stores all settings and quits Dolphin. */
133 void quit();
134
135 signals:
136 /**
137 * Is sent if the selection of the currently active view has
138 * been changed.
139 */
140 void selectionChanged(const KFileItemList& selection);
141
142 /**
143 * Is sent if the url of the currently active view has
144 * been changed.
145 */
146 void urlChanged(const KUrl& url);
147
148 /**
149 * Is emitted if information of an item is requested to be shown e. g. in the panel.
150 * If item is null, no item information request is pending.
151 */
152 void requestItemInfo(const KFileItem& item);
153
154 /**
155 * Is emitted if the settings have been changed.
156 */
157 void settingsChanged();
158
159 /**
160 * Is emitted when a tab has been closed.
161 */
162 void rememberClosedTab(const KUrl& primaryUrl, const KUrl& secondaryUrl);
163
164 protected:
165 /** @see QWidget::showEvent() */
166 virtual void showEvent(QShowEvent* event);
167
168 /** @see QMainWindow::closeEvent() */
169 virtual void closeEvent(QCloseEvent* event);
170
171 /** @see KMainWindow::saveProperties() */
172 virtual void saveProperties(KConfigGroup& group);
173
174 /** @see KMainWindow::readProperties() */
175 virtual void readProperties(const KConfigGroup& group);
176
177 private slots:
178 /**
179 * Refreshes the views of the main window by recreating them according to
180 * the given Dolphin settings.
181 */
182 void refreshViews();
183
184 void clearStatusBar();
185
186 /** Updates the 'Create New...' sub menu. */
187 void updateNewMenu();
188
189 void createDirectory();
190
191 /** Shows the error message in the status bar of the active view. */
192 void showErrorMessage(const QString& message);
193
194 /**
195 * Updates the state of the 'Undo' menu action dependent
196 * on the parameter \a available.
197 */
198 void slotUndoAvailable(bool available);
199
200 /** Sets the text of the 'Undo' menu action to \a text. */
201 void slotUndoTextChanged(const QString& text);
202
203 /** Performs the current undo operation. */
204 void undo();
205
206 /**
207 * Copies all selected items to the clipboard and marks
208 * the items as cut.
209 */
210 void cut();
211
212 /** Copies all selected items to the clipboard. */
213 void copy();
214
215 /** Pastes the clipboard data to the active view. */
216 void paste();
217
218 /** Replaces the URL navigator by a search box to find files. */
219 void find();
220
221 /**
222 * Updates the text of the paste action dependent on
223 * the number of items which are in the clipboard.
224 */
225 void updatePasteAction();
226
227 /** Selects all items from the active view. */
228 void selectAll();
229
230 /**
231 * Inverts the selection of all items of the active view:
232 * Selected items get nonselected and nonselected items get
233 * selected.
234 */
235 void invertSelection();
236
237 /**
238 * Switches between one and two views:
239 * If one view is visible, it will get split into two views.
240 * If already two views are visible, the active view gets closed.
241 */
242 void toggleSplitView();
243
244 /** Reloads the currently active view. */
245 void reloadView();
246
247 /** Stops the loading process for the currently active view. */
248 void stopLoading();
249
250 void enableStopAction();
251 void disableStopAction();
252
253 void showFilterBar();
254
255 /**
256 * Toggles between edit and browse mode of the navigation bar.
257 */
258 void toggleEditLocation();
259
260 /**
261 * Switches to the edit mode of the navigation bar and selects
262 * the whole URL, so that it can be replaced by the user. If the edit mode is
263 * already active, it is assured that the navigation bar get focused.
264 */
265 void replaceLocation();
266
267 /**
268 * Toggles the state of the panels between a locked and unlocked layout.
269 */
270 void togglePanelLockState();
271
272 /**
273 * Is invoked if the Places panel got visible/invisible and takes care
274 * that the places-selector of all views is only shown if the Places panel
275 * is invisible.
276 */
277 void slotPlacesPanelVisibilityChanged(bool visible);
278
279 /** Goes back one step of the URL history. */
280 void goBack();
281
282 /** Goes forward one step of the URL history. */
283 void goForward();
284
285 /** Goes up one hierarchy of the current URL. */
286 void goUp();
287
288 /** Changes the location to the home URL. */
289 void goHome();
290
291 /**
292 * Open the previous URL in the URL history in a new tab
293 * if the middle mouse button is clicked.
294 */
295 void goBack(Qt::MouseButtons buttons);
296
297 /**
298 * Open the next URL in the URL history in a new tab
299 * if the middle mouse button is clicked.
300 */
301 void goForward(Qt::MouseButtons buttons);
302
303 /**
304 * Open the URL one hierarchy above the current URL in a new tab
305 * if the middle mouse button is clicked.
306 */
307 void goUp(Qt::MouseButtons buttons);
308
309 /**
310 * Open the home URL in a new tab
311 */
312 void goHome(Qt::MouseButtons buttons);
313
314 /** Opens Kompare for 2 selected files. */
315 void compareFiles();
316
317 /**
318 * Hides the menu bar if it is visible, makes the menu bar
319 * visible if it is hidden.
320 */
321 void toggleShowMenuBar();
322
323 /** Opens a terminal window for the current location. */
324 void openTerminal();
325
326 /** Opens the settings dialog for Dolphin. */
327 void editSettings();
328
329 /** Updates the state of the 'Show Full Location' action. */
330 void slotEditableStateChanged(bool editable);
331
332 /**
333 * Updates the state of the 'Edit' menu actions and emits
334 * the signal selectionChanged().
335 */
336 void slotSelectionChanged(const KFileItemList& selection);
337
338 /** Emits the signal requestItemInfo(). */
339 void slotRequestItemInfo(const KFileItem&);
340
341 /**
342 * Updates the state of the 'Back' and 'Forward' menu
343 * actions corresponding to the current history.
344 */
345 void updateHistory();
346
347 /** Updates the state of the 'Show filter bar' menu action. */
348 void updateFilterBarAction(bool show);
349
350 /** Open a new main window. */
351 void openNewMainWindow();
352
353 /** Opens a new view with the current URL that is part of a tab. */
354 void openNewTab();
355
356 /**
357 * Opens a new tab in the background showing the URL \a url.
358 */
359 void openNewTab(const KUrl& url);
360
361 /**
362 * Opens a new tab showing the URL \a url and activates
363 * the tab.
364 */
365 void openNewActivatedTab(const KUrl& url);
366
367 void activateNextTab();
368
369 void activatePrevTab();
370
371 /**
372 * Opens the selected folder in a new tab.
373 */
374 void openInNewTab();
375
376 /**
377 * Opens the selected folder in a new window.
378 */
379 void openInNewWindow();
380
381 /** Toggles the active view if two views are shown within the main window. */
382 void toggleActiveView();
383
384 /**
385 * Indicates in the statusbar that the execution of the command \a command
386 * has been finished.
387 */
388 void showCommand(CommandType command);
389
390 /**
391 * Activates the tab with the index \a index, which means that the current view
392 * is replaced by the view of the given tab.
393 */
394 void setActiveTab(int index);
395
396 /** Closes the currently active tab. */
397 void closeTab();
398
399 /**
400 * Closes the tab with the index \a index and activates the tab with index - 1.
401 */
402 void closeTab(int index);
403
404 /**
405 * Opens a context menu for the tab with the index \a index
406 * on the position \a pos.
407 */
408 void openTabContextMenu(int index, const QPoint& pos);
409
410 /**
411 * Is connected to the QTabBar signal tabMoved(int from, int to).
412 * Reorders the list of tabs after a tab was moved in the tab bar
413 * and sets m_tabIndex to the new index of the current tab.
414 */
415 void slotTabMoved(int from, int to);
416
417 /**
418 * Is connected to the KTabBar signal testCanDecode() and adjusts
419 * the output parameter \a accept.
420 */
421 void slotTestCanDecode(const QDragMoveEvent* event, bool& accept);
422
423 /**
424 * If the URL can be listed, open it in the current view, otherwise
425 * run it through KRun.
426 */
427 void handleUrl(const KUrl& url);
428
429 /**
430 * handleUrl() can trigger a stat job to see if the url can actually
431 * be listed.
432 */
433 void slotHandleUrlStatFinished(KJob* job);
434
435 /**
436 * Is connected to the KTabBar signal receivedDropEvent.
437 * Allows dragging and dropping files onto tabs.
438 */
439 void tabDropEvent(int tab, QDropEvent* event);
440
441 /**
442 * Is invoked when the write state of a folder has been changed and
443 * enables/disables the "Create New..." menu entry.
444 */
445 void slotWriteStateChanged(bool isFolderWritable);
446
447 /**
448 * Opens the context menu on the current mouse position.
449 * @pos Position in screen coordinates.
450 * @item File item context. If item is null, the context menu
451 * should be applied to \a url.
452 * @url URL which contains \a item.
453 * @customActions Actions that should be added to the context menu,
454 * if the file item is null.
455 */
456 void openContextMenu(const QPoint& pos,
457 const KFileItem& item,
458 const KUrl& url,
459 const QList<QAction*>& customActions);
460
461 void updateControlMenu();
462 void updateToolBar();
463 void slotControlButtonDeleted();
464
465 /**
466 * Is called if a panel emits an error-message and shows
467 * the error-message in the active view-container.
468 */
469 void slotPanelErrorMessage(const QString& error);
470
471 /**
472 * Is called if the user clicked an item in the Places Panel.
473 * Reloads the view if \a url is the current URL already, and changes the
474 * current URL otherwise.
475 */
476 void slotPlaceActivated(const KUrl& url);
477
478 /**
479 * Is called when the user wants to reopen a previously closed \a tab from
480 * the recent tabs menu.
481 */
482 void restoreClosedTab(const KUrl& primaryUrl, const KUrl& secondaryUrl);
483
484 private:
485 /**
486 * Activates the given view, which means that
487 * all menu actions are applied to this view. When
488 * having a split view setup, the nonactive view
489 * is usually shown in darker colors.
490 */
491 void setActiveViewContainer(DolphinViewContainer* view);
492
493 /**
494 * Creates a view container and does a default initialization.
495 */
496 DolphinViewContainer* createViewContainer(const KUrl& url, QWidget* parent);
497
498 void setupActions();
499 void setupDockWidgets();
500 void updateEditActions();
501 void updateViewActions();
502 void updateGoActions();
503
504 void createControlButton();
505 void deleteControlButton();
506
507 /**
508 * Adds the action \p action to the menu \p menu in
509 * case if it has not added already to the toolbar.
510 * @return True if the action has been added to the menu.
511 */
512 bool addActionToMenu(QAction* action, KMenu* menu);
513
514 /**
515 * Connects the signals from the created DolphinView with
516 * the DolphinViewContainer \a container with the corresponding slots of
517 * the DolphinMainWindow. This method must be invoked each
518 * time a DolphinView has been created.
519 */
520 void connectViewSignals(DolphinViewContainer* container);
521
522 /**
523 * Updates the text of the split action:
524 * If two views are shown, the text is set to "Split",
525 * otherwise the text is set to "Join". The icon
526 * is updated to match with the text and the currently active view.
527 */
528 void updateSplitAction();
529
530 /** Returns the name of the tab for the URL \a url. */
531 QString tabName(const KUrl& url) const;
532
533 bool isKompareInstalled() const;
534
535 void createSecondaryView(int tabIndex);
536
537 /**
538 * Helper method for saveProperties() and readProperties(): Returns
539 * the property string for a tab with the index \a tabIndex and
540 * the property \a property.
541 */
542 QString tabProperty(const QString& property, int tabIndex) const;
543
544 /**
545 * Sets the window caption to url.fileName() if this is non-empty,
546 * "/" if the URL is "file:///", and url.protocol() otherwise.
547 */
548 void setUrlAsCaption(const KUrl& url);
549
550 QString squeezedText(const QString& text) const;
551
552 /**
553 * Creates an action for showing/hiding a panel, that is accessible
554 * in "Configure toolbars..." and "Configure shortcuts...". This is necessary
555 * as the action for toggling the dock visibility is done by Qt which
556 * is no KAction instance.
557 */
558 void createPanelAction(const QIcon &icon,
559 const QKeySequence& shortcut,
560 QAction* dockAction,
561 const QString& actionName);
562
563 private:
564 /**
565 * Implements a custom error handling for the undo manager. This
566 * assures that all errors are shown in the status bar of Dolphin
567 * instead as modal error dialog with an OK button.
568 */
569 class UndoUiInterface : public KIO::FileUndoManager::UiInterface
570 {
571 public:
572 UndoUiInterface();
573 virtual ~UndoUiInterface();
574 virtual void jobError(KIO::Job* job);
575 };
576
577 KNewFileMenu* m_newFileMenu;
578 KTabBar* m_tabBar;
579 DolphinViewContainer* m_activeViewContainer;
580 QVBoxLayout* m_centralWidgetLayout;
581 int m_id;
582
583 // Members for the tab-handling:
584 struct ViewTab
585 {
586 ViewTab() : isPrimaryViewActive(true), wasActive(false), primaryView(0), secondaryView(0), splitter(0) {}
587 bool isPrimaryViewActive;
588 bool wasActive;
589 DolphinViewContainer* primaryView;
590 DolphinViewContainer* secondaryView;
591 QSplitter* splitter;
592 };
593 int m_tabIndex;
594 QList<ViewTab> m_viewTab;
595
596 DolphinViewActionHandler* m_actionHandler;
597 DolphinRemoteEncoding* m_remoteEncoding;
598 QWeakPointer<DolphinSettingsDialog> m_settingsDialog;
599
600 // Members for the toolbar menu that is shown when the menubar is hidden:
601 QToolButton* m_controlButton;
602 QTimer* m_updateToolBarTimer;
603
604 KIO::Job* m_lastHandleUrlStatJob;
605 };
606
607 inline DolphinViewContainer* DolphinMainWindow::activeViewContainer() const
608 {
609 return m_activeViewContainer;
610 }
611
612 inline bool DolphinMainWindow::isSplit() const
613 {
614 return m_viewTab[m_tabIndex].secondaryView != 0;
615 }
616
617 inline KNewFileMenu* DolphinMainWindow::newFileMenu() const
618 {
619 return m_newFileMenu;
620 }
621
622 inline int DolphinMainWindow::getId() const
623 {
624 return m_id;
625 }
626
627 #endif // DOLPHIN_MAINWINDOW_H
628