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