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