]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.h
only set the title synchronously for the file-protocol, otherwise use KIO::stat()
[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 /**
384 * Opens a context menu for the tab with the index \a index
385 * on the position \a pos.
386 */
387 void openTabContextMenu(int index, const QPoint& pos);
388
389 /**
390 * Handles a click on a places item: if the middle mouse button is
391 * clicked, a new tab is opened for \a url, otherwise the current
392 * view is replaced by \a url.
393 */
394 void handlePlacesClick(const KUrl& url, Qt::MouseButtons buttons);
395
396 /**
397 * Is connected to the KTabBar signal testCanDecode() and adjusts
398 * the output parameter \a accept.
399 */
400 void slotTestCanDecode(const QDragMoveEvent* event, bool& accept);
401
402 /**
403 * Is connected with the Dolphin search box and the search configurator
404 * and triggers a Nepomuk search.
405 */
406 void searchItems();
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 searchbox signal 'requestSearchOptions' and
417 * takes care to show the search options.
418 */
419 void showSearchOptions();
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 * setUrlAsCaption() will trigger a stat job which reports its result in
429 * this slot.
430 */
431 void slotCaptionStatFinished(KJob* job);
432
433 private:
434 DolphinMainWindow(int id);
435 void init();
436
437 /**
438 * Activates the given view, which means that
439 * all menu actions are applied to this view. When
440 * having a split view setup, the nonactive view
441 * is usually shown in darker colors.
442 */
443 void setActiveViewContainer(DolphinViewContainer* view);
444
445 void setupActions();
446 void setupDockWidgets();
447 void updateEditActions();
448 void updateViewActions();
449 void updateGoActions();
450
451 /**
452 * Adds the tab[\a index] to the closed tab menu's list of actions.
453 */
454 void rememberClosedTab(int index);
455
456 /**
457 * Connects the signals from the created DolphinView with
458 * the DolphinViewContainer \a container with the corresponding slots of
459 * the DolphinMainWindow. This method must be invoked each
460 * time a DolphinView has been created.
461 */
462 void connectViewSignals(DolphinViewContainer* container);
463
464 /**
465 * Updates the text of the split action:
466 * If two views are shown, the text is set to "Split",
467 * otherwise the text is set to "Join". The icon
468 * is updated to match with the text and the currently active view.
469 */
470 void updateSplitAction();
471
472 /** Returns the name of the tab for the URL \a url. */
473 QString tabName(const KUrl& url) const;
474
475 bool isKompareInstalled() const;
476
477 void createSecondaryView(int tabIndex);
478
479 /**
480 * Helper method for saveProperties() and readProperties(): Returns
481 * the property string for a tab with the index \a tabIndex and
482 * the property \a property.
483 */
484 QString tabProperty(const QString& property, int tabIndex) const;
485
486 /**
487 * Sets the window caption to url.fileName() if this is non-empty,
488 * "/" if the URL is "file:///", and url.protocol() otherwise.
489 */
490 void setUrlAsCaption(const KUrl& url);
491
492 QString squeezedText(const QString& text) const;
493
494 private:
495 /**
496 * Implements a custom error handling for the undo manager. This
497 * assures that all errors are shown in the status bar of Dolphin
498 * instead as modal error dialog with an OK button.
499 */
500 class UndoUiInterface : public KIO::FileUndoManager::UiInterface
501 {
502 public:
503 UndoUiInterface();
504 virtual ~UndoUiInterface();
505 virtual void jobError(KIO::Job* job);
506 };
507
508 KNewMenu* m_newMenu;
509 KActionMenu* m_recentTabsMenu;
510 KAction* m_showMenuBar;
511 KTabBar* m_tabBar;
512 DolphinViewContainer* m_activeViewContainer;
513 QVBoxLayout* m_centralWidgetLayout;
514 DolphinSearchBox* m_searchBox;
515 DolphinSearchOptionsConfigurator* m_searchOptionsConfigurator;
516 int m_id;
517
518 struct ViewTab
519 {
520 ViewTab() : isPrimaryViewActive(true), primaryView(0), secondaryView(0), splitter(0) {}
521 bool isPrimaryViewActive;
522 DolphinViewContainer* primaryView;
523 DolphinViewContainer* secondaryView;
524 QSplitter* splitter;
525 };
526
527 int m_tabIndex;
528 QList<ViewTab> m_viewTab;
529
530 DolphinViewActionHandler* m_actionHandler;
531 DolphinRemoteEncoding* m_remoteEncoding;
532 QPointer<DolphinSettingsDialog> m_settingsDialog;
533
534 KJob* m_captionStatJob;
535 };
536
537 inline DolphinViewContainer* DolphinMainWindow::activeViewContainer() const
538 {
539 return m_activeViewContainer;
540 }
541
542 inline bool DolphinMainWindow::isSplit() const
543 {
544 return m_viewTab[m_tabIndex].secondaryView != 0;
545 }
546
547 inline KNewMenu* DolphinMainWindow::newMenu() const
548 {
549 return m_newMenu;
550 }
551
552 inline KAction* DolphinMainWindow::showMenuBarAction() const
553 {
554 return m_showMenuBar;
555 }
556
557 inline int DolphinMainWindow::getId() const
558 {
559 return m_id;
560 }
561
562 #endif // DOLPHIN_MAINWINDOW_H
563