]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.h
Request the activation of the view, even if the column is marked as active already...
[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 KNewFileMenu;
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 KNewFileMenu* 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 connected to the KTabBar signal receivedDropEvent.
434 * Allows dragging and dropping files onto tabs.
435 */
436 void tabDropEvent(int tab, QDropEvent* event);
437
438 /**
439 * Is invoked when the write state of a folder has been changed and
440 * enables/disables the "Create New..." menu entry.
441 */
442 void slotWriteStateChanged(bool isFolderWritable);
443
444 /**
445 * Opens the context menu on the current mouse position.
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 KFileItem& item,
453 const KUrl& url,
454 const QList<QAction*>& customActions);
455
456 private:
457 DolphinMainWindow(int id);
458 void init();
459
460 /**
461 * Activates the given view, which means that
462 * all menu actions are applied to this view. When
463 * having a split view setup, the nonactive view
464 * is usually shown in darker colors.
465 */
466 void setActiveViewContainer(DolphinViewContainer* view);
467
468 void setupActions();
469 void setupDockWidgets();
470 void updateEditActions();
471 void updateViewActions();
472 void updateGoActions();
473
474 /**
475 * Adds the tab[\a index] to the closed tab menu's list of actions.
476 */
477 void rememberClosedTab(int index);
478
479 /**
480 * Connects the signals from the created DolphinView with
481 * the DolphinViewContainer \a container with the corresponding slots of
482 * the DolphinMainWindow. This method must be invoked each
483 * time a DolphinView has been created.
484 */
485 void connectViewSignals(DolphinViewContainer* container);
486
487 /**
488 * Updates the text of the split action:
489 * If two views are shown, the text is set to "Split",
490 * otherwise the text is set to "Join". The icon
491 * is updated to match with the text and the currently active view.
492 */
493 void updateSplitAction();
494
495 /** Returns the name of the tab for the URL \a url. */
496 QString tabName(const KUrl& url) const;
497
498 bool isKompareInstalled() const;
499
500 void createSecondaryView(int tabIndex);
501
502 /**
503 * Helper method for saveProperties() and readProperties(): Returns
504 * the property string for a tab with the index \a tabIndex and
505 * the property \a property.
506 */
507 QString tabProperty(const QString& property, int tabIndex) const;
508
509 /**
510 * Sets the window caption to url.fileName() if this is non-empty,
511 * "/" if the URL is "file:///", and url.protocol() otherwise.
512 */
513 void setUrlAsCaption(const KUrl& url);
514
515 QString squeezedText(const QString& text) const;
516
517 private:
518 /**
519 * Implements a custom error handling for the undo manager. This
520 * assures that all errors are shown in the status bar of Dolphin
521 * instead as modal error dialog with an OK button.
522 */
523 class UndoUiInterface : public KIO::FileUndoManager::UiInterface
524 {
525 public:
526 UndoUiInterface();
527 virtual ~UndoUiInterface();
528 virtual void jobError(KIO::Job* job);
529 };
530
531 KNewFileMenu* m_newMenu;
532 KActionMenu* m_recentTabsMenu;
533 KAction* m_showMenuBar;
534 KTabBar* m_tabBar;
535 DolphinViewContainer* m_activeViewContainer;
536 QVBoxLayout* m_centralWidgetLayout;
537 DolphinSearchBox* m_searchBox;
538 DolphinSearchOptionsConfigurator* m_searchOptionsConfigurator;
539 int m_id;
540
541 struct ViewTab
542 {
543 ViewTab() : isPrimaryViewActive(true), primaryView(0), secondaryView(0), splitter(0) {}
544 bool isPrimaryViewActive;
545 DolphinViewContainer* primaryView;
546 DolphinViewContainer* secondaryView;
547 QSplitter* splitter;
548 };
549
550 int m_tabIndex;
551 QList<ViewTab> m_viewTab;
552
553 DolphinViewActionHandler* m_actionHandler;
554 DolphinRemoteEncoding* m_remoteEncoding;
555 QPointer<DolphinSettingsDialog> m_settingsDialog;
556
557 KJob* m_captionStatJob;
558 };
559
560 inline DolphinViewContainer* DolphinMainWindow::activeViewContainer() const
561 {
562 return m_activeViewContainer;
563 }
564
565 inline bool DolphinMainWindow::isSplit() const
566 {
567 return m_viewTab[m_tabIndex].secondaryView != 0;
568 }
569
570 inline KNewFileMenu* DolphinMainWindow::newMenu() const
571 {
572 return m_newMenu;
573 }
574
575 inline KAction* DolphinMainWindow::showMenuBarAction() const
576 {
577 return m_showMenuBar;
578 }
579
580 inline int DolphinMainWindow::getId() const
581 {
582 return m_id;
583 }
584
585 #endif // DOLPHIN_MAINWINDOW_H
586