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