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