]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.h
* Adjust code to use the improved KUrlNavigator API.
[dolphin.git] / src / dolphinmainwindow.h
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
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 "dolphinview.h"
26 #include "panels/panel.h"
27
28 #include <config-nepomuk.h>
29
30 #include <kfileitemdelegate.h>
31 #include <kio/fileundomanager.h>
32 #include <ksortablelist.h>
33 #include <kxmlguiwindow.h>
34 #include <kactionmenu.h>
35
36 #include <QtCore/QList>
37
38 typedef KIO::FileUndoManager::CommandType CommandType;
39
40 class KAction;
41 class DolphinViewActionHandler;
42 class DolphinApplication;
43 class DolphinSearchBox;
44 class DolphinSearchOptionsConfigurator;
45 class DolphinSettingsDialog;
46 class DolphinViewContainer;
47 class DolphinRemoteEncoding;
48 class KNewMenu;
49 class KTabBar;
50 class KUrl;
51 class QSplitter;
52 class KJob;
53
54 /**
55 * @short Main window for Dolphin.
56 *
57 * Handles the menus, toolbars and Dolphin views.
58 */
59 class DolphinMainWindow: public KXmlGuiWindow
60 {
61 Q_OBJECT
62 Q_CLASSINFO("D-Bus Interface", "org.kde.dolphin.MainWindow")
63 Q_PROPERTY(int id READ getId SCRIPTABLE true)
64 friend class DolphinApplication;
65
66 public:
67 virtual ~DolphinMainWindow();
68
69 /**
70 * Returns the currently active view.
71 * All menu actions are applied to this view. When
72 * having a split view setup, the nonactive view
73 * is usually shown in darker colors.
74 */
75 DolphinViewContainer* activeViewContainer() const;
76
77 /**
78 * Opens each directory \p in a separate tab. If the "split view"
79 * option is enabled, 2 directories are collected within one tab.
80 */
81 void openDirectories(const QList<KUrl>& dirs);
82
83 /**
84 * Opens the directory which contains the files \p files
85 * and selects all files (implements the --select option
86 * of Dolphin).
87 */
88 void openFiles(const QList<KUrl>& files);
89
90 /**
91 * Returns true, if the main window contains two instances
92 * of a view container. The active view constainer can be
93 * accessed by DolphinMainWindow::activeViewContainer().
94 */
95 bool isSplit() const;
96
97 /**
98 * If the main window contains two instances of a view container
99 * (DolphinMainWindow::isSplit() returns true), then the
100 * two views get toggled (the right view is on the left, the left
101 * view on the right).
102 */
103 void toggleViews();
104
105 /** Renames the item represented by \a oldUrl to \a newUrl. */
106 void rename(const KUrl& oldUrl, const KUrl& newUrl);
107
108 /**
109 * Refreshes the views of the main window by recreating them dependent from
110 * the given Dolphin settings.
111 */
112 void refreshViews();
113
114 /**
115 * Returns the 'Create New...' sub menu which also can be shared
116 * with other menus (e. g. a context menu).
117 */
118 KNewMenu* newMenu() const;
119
120 /**
121 * Returns the 'Show Menubar' action which can be shared with
122 * other menus (e. g. a context menu).
123 */
124 KAction* showMenuBarAction() const;
125
126 public slots:
127 /**
128 * Pastes the clipboard data into the currently selected folder
129 * of the active view. If not exactly one folder is selected,
130 * no pasting is done at all.
131 */
132 void pasteIntoFolder();
133
134 /**
135 * Returns the main window ID used through DBus.
136 */
137 int getId() const;
138
139 /**
140 * Implementation of the MainWindowAdaptor/QDBusAbstractAdaptor interface.
141 * Inform all affected dolphin components (panels, views) of an URL
142 * change.
143 */
144 void changeUrl(const KUrl& url);
145
146 /** Stores all settings and quits Dolphin. */
147 void quit();
148
149 signals:
150 /**
151 * Is sent if the selection of the currently active view has
152 * been changed.
153 */
154 void selectionChanged(const KFileItemList& selection);
155
156 /**
157 * Is sent if the url of the currently active view has
158 * been changed.
159 */
160 void urlChanged(const KUrl& url);
161
162 /**
163 * Is emitted if information of an item is requested to be shown e. g. in the panel.
164 * If item is null, no item information request is pending.
165 */
166 void requestItemInfo(const KFileItem& item);
167
168 protected:
169 /** @see QWidget::showEvent() */
170 virtual void showEvent(QShowEvent* event);
171
172 /** @see QMainWindow::closeEvent() */
173 virtual void closeEvent(QCloseEvent* event);
174
175 /** @see KMainWindow::saveProperties() */
176 virtual void saveProperties(KConfigGroup& group);
177
178 /** @see KMainWindow::readProperties() */
179 virtual void readProperties(const KConfigGroup& group);
180
181 private slots:
182 void clearStatusBar();
183
184 /** Updates the 'Create New...' sub menu. */
185 void updateNewMenu();
186
187 void createDirectory();
188
189 /** Shows the error message in the status bar of the active view. */
190 void showErrorMessage(const QString& message);
191
192 /**
193 * Updates the state of the 'Undo' menu action dependent
194 * from the parameter \a available.
195 */
196 void slotUndoAvailable(bool available);
197
198 /** Invoked when an action in the recent tabs menu is clicked. */
199 void restoreClosedTab(QAction* action);
200
201 /** Sets the text of the 'Undo' menu action to \a text. */
202 void slotUndoTextChanged(const QString& text);
203
204 /** Performs the current undo operation. */
205 void undo();
206
207 /**
208 * Copies all selected items to the clipboard and marks
209 * the items as cut.
210 */
211 void cut();
212
213 /** Copies all selected items to the clipboard. */
214 void copy();
215
216 /** Pastes the clipboard data to the active view. */
217 void paste();
218
219 /**
220 * Updates the text of the paste action dependent from
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 nonactivated view gets closed.
239 */
240 void toggleSplitView();
241
242 /** Reloads the current active view. */
243 void reloadView();
244
245 /** Stops the loading process for the current active view. */
246 void stopLoading();
247
248 /**
249 * Toggles between showing and hiding of the filter bar
250 */
251 void toggleFilterBarVisibility(bool show);
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 /** Goes back on step of the URL history. */
266 void goBack();
267
268 /** Goes forward one step of the URL history. */
269 void goForward();
270
271 /** Goes up one hierarchy of the current URL. */
272 void goUp();
273
274 /**
275 * Open the previous URL in the URL history in a new tab
276 * if the middle mouse button is clicked.
277 */
278 void goBack(Qt::MouseButtons buttons);
279
280 /**
281 * Open the next URL in the URL history in a new tab
282 * if the middle mouse button is clicked.
283 */
284 void goForward(Qt::MouseButtons buttons);
285
286 /**
287 * Open the URL one hierarchy above the current URL in a new tab
288 * if the middle mouse button is clicked.
289 */
290 void goUp(Qt::MouseButtons buttons);
291
292 /** Goes to the home URL. */
293 void goHome();
294
295 /** Opens Kompare for 2 selected files. */
296 void compareFiles();
297
298 /**
299 * Hides the menu bar if it is visible, makes the menu bar
300 * visible if it is hidden.
301 */
302 void toggleShowMenuBar();
303
304 /** Opens a terminal window for the current location. */
305 void openTerminal();
306
307 /** Opens the settings dialog for Dolphin. */
308 void editSettings();
309
310 /** Updates the state of the 'Show Full Location' action. */
311 void slotEditableStateChanged(bool editable);
312
313 /**
314 * Updates the state of the 'Edit' menu actions and emits
315 * the signal selectionChanged().
316 */
317 void slotSelectionChanged(const KFileItemList& selection);
318
319 /** Enables changing of tabs via mouse wheel. */
320 void slotWheelMoved(int wheelDelta);
321
322 /** Emits the signal requestItemInfo(). */
323 void slotRequestItemInfo(const KFileItem&);
324
325 /**
326 * Updates the state of the 'Back' and 'Forward' menu
327 * actions corresponding to the current history.
328 */
329 void updateHistory();
330
331 /** Updates the state of the 'Show filter bar' menu action. */
332 void updateFilterBarAction(bool show);
333
334 /** Open a new main window. */
335 void openNewMainWindow();
336
337 /** Opens a new view with the current URL that is part of a tab. */
338 void openNewTab();
339
340 /**
341 * Opens a new tab showing the URL \a url.
342 */
343 void openNewTab(const KUrl& url);
344
345 void activateNextTab();
346
347 void activatePrevTab();
348
349 /**
350 * Opens the selected folder in a new tab.
351 */
352 void openInNewTab();
353
354 /**
355 * Opens the selected folder in a new window.
356 */
357 void openInNewWindow();
358
359 /** Toggles the active view if two views are shown within the main window. */
360 void toggleActiveView();
361
362 /**
363 * Indicates in the statusbar that the execution of the command \a command
364 * has been finished.
365 */
366 void showCommand(CommandType command);
367
368 /**
369 * Activates the tab with the index \a index, which means that the current view
370 * is replaced by the view of the given tab.
371 */
372 void setActiveTab(int index);
373
374 /** Closes the currently active tab. */
375 void closeTab();
376
377 /**
378 * Closes the tab with the index \index and activates the tab with index - 1.
379 */
380 void closeTab(int index);
381
382 /**
383 * Opens a context menu for the tab with the index \a index
384 * on the position \a pos.
385 */
386 void openTabContextMenu(int index, const QPoint& pos);
387
388 /**
389 * Is connected to the QTabBar signal tabMoved(int from, int to).
390 * Reorders the list of tabs after a tab was moved in the tab bar
391 * and sets m_tabIndex to the new index of the current tab.
392 */
393 void slotTabMoved(int from, int to);
394
395 /**
396 * Handles a click on a places item: if the middle mouse button is
397 * clicked, a new tab is opened for \a url, otherwise the current
398 * view is replaced by \a url.
399 */
400 void handlePlacesClick(const KUrl& url, Qt::MouseButtons buttons);
401
402 /**
403 * Is connected to the KTabBar signal testCanDecode() and adjusts
404 * the output parameter \a accept.
405 */
406 void slotTestCanDecode(const QDragMoveEvent* event, bool& accept);
407
408 /**
409 * Is connected with the Dolphin search box and the search configurator
410 * and triggers a Nepomuk search.
411 */
412 void searchItems();
413
414 /**
415 * Is connected to the searchbox signal 'requestSearchOptions' and
416 * takes care to show the search options.
417 */
418 void showSearchOptions();
419
420 /**
421 * If the URL can be listed open it in the current view, otherwise
422 * run it through KRun.
423 */
424 void handleUrl(const KUrl& url);
425
426 /**
427 * setUrlAsCaption() will trigger a stat job which reports its result in
428 * this slot.
429 */
430 void slotCaptionStatFinished(KJob* job);
431
432 /**
433 * Is invoked when the write state of a folder has been changed and
434 * enables/disables the "Create New..." menu entry.
435 */
436 void slotWriteStateChanged(bool isFolderWritable);
437
438 /**
439 * Opens the context menu on the current mouse position.
440 * @item File item context. If item is null, the context menu
441 * should be applied to \a url.
442 * @url URL which contains \a item.
443 * @customActions Actions that should be added to the context menu,
444 * if the file item is null.
445 */
446 void openContextMenu(const KFileItem& item,
447 const KUrl& url,
448 const QList<QAction*>& customActions);
449
450 private:
451 DolphinMainWindow(int id);
452 void init();
453
454 /**
455 * Activates the given view, which means that
456 * all menu actions are applied to this view. When
457 * having a split view setup, the nonactive view
458 * is usually shown in darker colors.
459 */
460 void setActiveViewContainer(DolphinViewContainer* view);
461
462 void setupActions();
463 void setupDockWidgets();
464 void updateEditActions();
465 void updateViewActions();
466 void updateGoActions();
467
468 /**
469 * Adds the tab[\a index] to the closed tab menu's list of actions.
470 */
471 void rememberClosedTab(int index);
472
473 /**
474 * Connects the signals from the created DolphinView with
475 * the DolphinViewContainer \a container with the corresponding slots of
476 * the DolphinMainWindow. This method must be invoked each
477 * time a DolphinView has been created.
478 */
479 void connectViewSignals(DolphinViewContainer* container);
480
481 /**
482 * Updates the text of the split action:
483 * If two views are shown, the text is set to "Split",
484 * otherwise the text is set to "Join". The icon
485 * is updated to match with the text and the currently active view.
486 */
487 void updateSplitAction();
488
489 /** Returns the name of the tab for the URL \a url. */
490 QString tabName(const KUrl& url) const;
491
492 bool isKompareInstalled() const;
493
494 void createSecondaryView(int tabIndex);
495
496 /**
497 * Helper method for saveProperties() and readProperties(): Returns
498 * the property string for a tab with the index \a tabIndex and
499 * the property \a property.
500 */
501 QString tabProperty(const QString& property, int tabIndex) const;
502
503 /**
504 * Sets the window caption to url.fileName() if this is non-empty,
505 * "/" if the URL is "file:///", and url.protocol() otherwise.
506 */
507 void setUrlAsCaption(const KUrl& url);
508
509 QString squeezedText(const QString& text) const;
510
511 private:
512 /**
513 * Implements a custom error handling for the undo manager. This
514 * assures that all errors are shown in the status bar of Dolphin
515 * instead as modal error dialog with an OK button.
516 */
517 class UndoUiInterface : public KIO::FileUndoManager::UiInterface
518 {
519 public:
520 UndoUiInterface();
521 virtual ~UndoUiInterface();
522 virtual void jobError(KIO::Job* job);
523 };
524
525 KNewMenu* m_newMenu;
526 KActionMenu* m_recentTabsMenu;
527 KAction* m_showMenuBar;
528 KTabBar* m_tabBar;
529 DolphinViewContainer* m_activeViewContainer;
530 QVBoxLayout* m_centralWidgetLayout;
531 DolphinSearchBox* m_searchBox;
532 DolphinSearchOptionsConfigurator* m_searchOptionsConfigurator;
533 int m_id;
534
535 struct ViewTab
536 {
537 ViewTab() : isPrimaryViewActive(true), primaryView(0), secondaryView(0), splitter(0) {}
538 bool isPrimaryViewActive;
539 DolphinViewContainer* primaryView;
540 DolphinViewContainer* secondaryView;
541 QSplitter* splitter;
542 };
543
544 int m_tabIndex;
545 QList<ViewTab> m_viewTab;
546
547 DolphinViewActionHandler* m_actionHandler;
548 DolphinRemoteEncoding* m_remoteEncoding;
549 QPointer<DolphinSettingsDialog> m_settingsDialog;
550
551 KJob* m_captionStatJob;
552 };
553
554 inline DolphinViewContainer* DolphinMainWindow::activeViewContainer() const
555 {
556 return m_activeViewContainer;
557 }
558
559 inline bool DolphinMainWindow::isSplit() const
560 {
561 return m_viewTab[m_tabIndex].secondaryView != 0;
562 }
563
564 inline KNewMenu* DolphinMainWindow::newMenu() const
565 {
566 return m_newMenu;
567 }
568
569 inline KAction* DolphinMainWindow::showMenuBarAction() const
570 {
571 return m_showMenuBar;
572 }
573
574 inline int DolphinMainWindow::getId() const
575 {
576 return m_id;
577 }
578
579 #endif // DOLPHIN_MAINWINDOW_H
580