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