]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.h
Sourcecode hierarchy cleanup: Create folder "views" and move view related sources...
[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 "panels/panel.h"
26
27 #include <config-nepomuk.h>
28
29 #include <kfileitemdelegate.h>
30 #include <kio/fileundomanager.h>
31 #include <ksortablelist.h>
32 #include <kxmlguiwindow.h>
33 #include <kactionmenu.h>
34
35 #include "views/dolphinview.h"
36
37 #include <QList>
38
39 typedef KIO::FileUndoManager::CommandType CommandType;
40
41 class KAction;
42 class DolphinViewActionHandler;
43 class DolphinApplication;
44 class DolphinSettingsDialog;
45 class DolphinViewContainer;
46 class DolphinRemoteEncoding;
47 class KNewFileMenu;
48 class KTabBar;
49 class KUrl;
50 class QSplitter;
51 class KJob;
52
53 /**
54 * @short Main window for Dolphin.
55 *
56 * Handles the menus, toolbars and Dolphin views.
57 */
58 class DolphinMainWindow: public KXmlGuiWindow
59 {
60 Q_OBJECT
61 Q_CLASSINFO("D-Bus Interface", "org.kde.dolphin.MainWindow")
62 Q_PROPERTY(int id READ getId SCRIPTABLE true)
63 friend class DolphinApplication;
64
65 public:
66 virtual ~DolphinMainWindow();
67
68 /**
69 * Returns the currently active view.
70 * All menu actions are applied to this view. When
71 * having a split view setup, the nonactive view
72 * is usually shown in darker colors.
73 */
74 DolphinViewContainer* activeViewContainer() const;
75
76 /**
77 * Opens each directory \p in a separate tab. If the "split view"
78 * option is enabled, 2 directories are collected within one tab.
79 */
80 void openDirectories(const QList<KUrl>& dirs);
81
82 /**
83 * Opens the directory which contains the files \p files
84 * and selects all files (implements the --select option
85 * of Dolphin).
86 */
87 void openFiles(const QList<KUrl>& files);
88
89 /**
90 * Returns true, if the main window contains two instances
91 * of a view container. The active view constainer can be
92 * accessed by DolphinMainWindow::activeViewContainer().
93 */
94 bool isSplit() const;
95
96 /**
97 * If the main window contains two instances of a view container
98 * (DolphinMainWindow::isSplit() returns true), then the
99 * two views get toggled (the right view is on the left, the left
100 * view on the right).
101 */
102 void toggleViews();
103
104 /** Renames the item represented by \a oldUrl to \a newUrl. */
105 void rename(const KUrl& oldUrl, const KUrl& newUrl);
106
107 /**
108 * Refreshes the views of the main window by recreating them dependent from
109 * the given Dolphin settings.
110 */
111 void refreshViews();
112
113 /**
114 * Returns the 'Create New...' sub menu which also can be shared
115 * with other menus (e. g. a context menu).
116 */
117 KNewFileMenu* newMenu() const;
118
119 /**
120 * Returns the 'Show Menubar' action which can be shared with
121 * other menus (e. g. a context menu).
122 */
123 KAction* showMenuBarAction() const;
124
125 public slots:
126 /**
127 * Pastes the clipboard data into the currently selected folder
128 * of the active view. If not exactly one folder is selected,
129 * no pasting is done at all.
130 */
131 void pasteIntoFolder();
132
133 /**
134 * Returns the main window ID used through DBus.
135 */
136 int getId() const;
137
138 /**
139 * Implementation of the MainWindowAdaptor/QDBusAbstractAdaptor interface.
140 * Inform all affected dolphin components (panels, views) of an URL
141 * change.
142 */
143 void changeUrl(const KUrl& url);
144
145 /** Stores all settings and quits Dolphin. */
146 void quit();
147
148 signals:
149 /**
150 * Is sent if the selection of the currently active view has
151 * been changed.
152 */
153 void selectionChanged(const KFileItemList& selection);
154
155 /**
156 * Is sent if the url of the currently active view has
157 * been changed.
158 */
159 void urlChanged(const KUrl& url);
160
161 /**
162 * Is emitted if information of an item is requested to be shown e. g. in the panel.
163 * If item is null, no item information request is pending.
164 */
165 void requestItemInfo(const KFileItem& item);
166
167 protected:
168 /** @see QWidget::showEvent() */
169 virtual void showEvent(QShowEvent* event);
170
171 /** @see QMainWindow::closeEvent() */
172 virtual void closeEvent(QCloseEvent* event);
173
174 /** @see KMainWindow::saveProperties() */
175 virtual void saveProperties(KConfigGroup& group);
176
177 /** @see KMainWindow::readProperties() */
178 virtual void readProperties(const KConfigGroup& group);
179
180 private slots:
181 void clearStatusBar();
182
183 /** Updates the 'Create New...' sub menu. */
184 void updateNewMenu();
185
186 void createDirectory();
187
188 /** Shows the error message in the status bar of the active view. */
189 void showErrorMessage(const QString& message);
190
191 /**
192 * Updates the state of the 'Undo' menu action dependent
193 * from the parameter \a available.
194 */
195 void slotUndoAvailable(bool available);
196
197 /** Invoked when an action in the recent tabs menu is clicked. */
198 void restoreClosedTab(QAction* action);
199
200 /** Sets the text of the 'Undo' menu action to \a text. */
201 void slotUndoTextChanged(const QString& text);
202
203 /** Performs the current undo operation. */
204 void undo();
205
206 /**
207 * Copies all selected items to the clipboard and marks
208 * the items as cut.
209 */
210 void cut();
211
212 /** Copies all selected items to the clipboard. */
213 void copy();
214
215 /** Pastes the clipboard data to the active view. */
216 void paste();
217
218 /** Replaces the URL navigator by a search box to find files. */
219 void find();
220
221 /**
222 * Updates the text of the paste action dependent from
223 * the number of items which are in the clipboard.
224 */
225 void updatePasteAction();
226
227 /** Selects all items from the active view. */
228 void selectAll();
229
230 /**
231 * Inverts the selection of all items of the active view:
232 * Selected items get nonselected and nonselected items get
233 * selected.
234 */
235 void invertSelection();
236
237 /**
238 * Switches between one and two views:
239 * If one view is visible, it will get split into two views.
240 * If already two views are visible, the nonactivated view gets closed.
241 */
242 void toggleSplitView();
243
244 /** Reloads the current active view. */
245 void reloadView();
246
247 /** Stops the loading process for the current active view. */
248 void stopLoading();
249
250 /**
251 * Toggles between showing and hiding of the filter bar
252 */
253 void toggleFilterBarVisibility(bool show);
254
255 /**
256 * Toggles between edit and browse mode of the navigation bar.
257 */
258 void toggleEditLocation();
259
260 /**
261 * Switches to the edit mode of the navigation bar and selects
262 * the whole URL, so that it can be replaced by the user. If the edit mode is
263 * already active, it is assured that the navigation bar get focused.
264 */
265 void replaceLocation();
266
267 /** Goes back on 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 /**
277 * Open the previous URL in the URL history in a new tab
278 * if the middle mouse button is clicked.
279 */
280 void goBack(Qt::MouseButtons buttons);
281
282 /**
283 * Open the next URL in the URL history in a new tab
284 * if the middle mouse button is clicked.
285 */
286 void goForward(Qt::MouseButtons buttons);
287
288 /**
289 * Open the URL one hierarchy above the current URL in a new tab
290 * if the middle mouse button is clicked.
291 */
292 void goUp(Qt::MouseButtons buttons);
293
294 /** Goes to the home URL. */
295 void goHome();
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 /** Enables changing of tabs via mouse wheel. */
322 void slotWheelMoved(int wheelDelta);
323
324 /** Emits the signal requestItemInfo(). */
325 void slotRequestItemInfo(const KFileItem&);
326
327 /**
328 * Updates the state of the 'Back' and 'Forward' menu
329 * actions corresponding to the current history.
330 */
331 void updateHistory();
332
333 /** Updates the state of the 'Show filter bar' menu action. */
334 void updateFilterBarAction(bool show);
335
336 /** Open a new main window. */
337 void openNewMainWindow();
338
339 /** Opens a new view with the current URL that is part of a tab. */
340 void openNewTab();
341
342 /**
343 * Opens a new tab showing the URL \a url.
344 */
345 void openNewTab(const KUrl& url);
346
347 void activateNextTab();
348
349 void activatePrevTab();
350
351 /**
352 * Opens the selected folder in a new tab.
353 */
354 void openInNewTab();
355
356 /**
357 * Opens the selected folder in a new window.
358 */
359 void openInNewWindow();
360
361 /** Toggles the active view if two views are shown within the main window. */
362 void toggleActiveView();
363
364 /**
365 * Indicates in the statusbar that the execution of the command \a command
366 * has been finished.
367 */
368 void showCommand(CommandType command);
369
370 /**
371 * Activates the tab with the index \a index, which means that the current view
372 * is replaced by the view of the given tab.
373 */
374 void setActiveTab(int index);
375
376 /** Closes the currently active tab. */
377 void closeTab();
378
379 /**
380 * Closes the tab with the index \index and activates the tab with index - 1.
381 */
382 void closeTab(int index);
383
384 /**
385 * Opens a context menu for the tab with the index \a index
386 * on the position \a pos.
387 */
388 void openTabContextMenu(int index, const QPoint& pos);
389
390 /**
391 * Is connected to the QTabBar signal tabMoved(int from, int to).
392 * Reorders the list of tabs after a tab was moved in the tab bar
393 * and sets m_tabIndex to the new index of the current tab.
394 */
395 void slotTabMoved(int from, int to);
396
397 /**
398 * Handles a click on a places item: if the middle mouse button is
399 * clicked, a new tab is opened for \a url, otherwise the current
400 * view is replaced by \a url.
401 */
402 void handlePlacesClick(const KUrl& url, Qt::MouseButtons buttons);
403
404 /**
405 * Is connected to the KTabBar signal testCanDecode() and adjusts
406 * the output parameter \a accept.
407 */
408 void slotTestCanDecode(const QDragMoveEvent* event, bool& accept);
409
410 /**
411 * If the URL can be listed open it in the current view, otherwise
412 * run it through KRun.
413 */
414 void handleUrl(const KUrl& url);
415
416 /**
417 * handleUrl() can trigger a stat job to see if the url can actually
418 * be listed.
419 */
420 void slotHandleUrlStatFinished(KJob* job);
421
422 /**
423 * setUrlAsCaption() will trigger a stat job which reports its result in
424 * this slot.
425 */
426 void slotCaptionStatFinished(KJob* job);
427
428 /**
429 * Is connected to the KTabBar signal receivedDropEvent.
430 * Allows dragging and dropping files onto tabs.
431 */
432 void tabDropEvent(int tab, QDropEvent* event);
433
434 /**
435 * Is invoked when the write state of a folder has been changed and
436 * enables/disables the "Create New..." menu entry.
437 */
438 void slotWriteStateChanged(bool isFolderWritable);
439
440 /**
441 * Opens the context menu on the current mouse position.
442 * @item File item context. If item is null, the context menu
443 * should be applied to \a url.
444 * @url URL which contains \a item.
445 * @customActions Actions that should be added to the context menu,
446 * if the file item is null.
447 */
448 void openContextMenu(const KFileItem& item,
449 const KUrl& url,
450 const QList<QAction*>& customActions);
451
452 private:
453 DolphinMainWindow(int id);
454 void init();
455
456 /**
457 * Activates the given view, which means that
458 * all menu actions are applied to this view. When
459 * having a split view setup, the nonactive view
460 * is usually shown in darker colors.
461 */
462 void setActiveViewContainer(DolphinViewContainer* view);
463
464 void setupActions();
465 void setupDockWidgets();
466 void updateEditActions();
467 void updateViewActions();
468 void updateGoActions();
469
470 /**
471 * Adds the tab[\a index] to the closed tab menu's list of actions.
472 */
473 void rememberClosedTab(int index);
474
475 /**
476 * Connects the signals from the created DolphinView with
477 * the DolphinViewContainer \a container with the corresponding slots of
478 * the DolphinMainWindow. This method must be invoked each
479 * time a DolphinView has been created.
480 */
481 void connectViewSignals(DolphinViewContainer* container);
482
483 /**
484 * Updates the text of the split action:
485 * If two views are shown, the text is set to "Split",
486 * otherwise the text is set to "Join". The icon
487 * is updated to match with the text and the currently active view.
488 */
489 void updateSplitAction();
490
491 /** Returns the name of the tab for the URL \a url. */
492 QString tabName(const KUrl& url) const;
493
494 bool isKompareInstalled() const;
495
496 void createSecondaryView(int tabIndex);
497
498 /**
499 * Helper method for saveProperties() and readProperties(): Returns
500 * the property string for a tab with the index \a tabIndex and
501 * the property \a property.
502 */
503 QString tabProperty(const QString& property, int tabIndex) const;
504
505 /**
506 * Sets the window caption to url.fileName() if this is non-empty,
507 * "/" if the URL is "file:///", and url.protocol() otherwise.
508 */
509 void setUrlAsCaption(const KUrl& url);
510
511 QString squeezedText(const QString& text) const;
512
513 private:
514 /**
515 * Implements a custom error handling for the undo manager. This
516 * assures that all errors are shown in the status bar of Dolphin
517 * instead as modal error dialog with an OK button.
518 */
519 class UndoUiInterface : public KIO::FileUndoManager::UiInterface
520 {
521 public:
522 UndoUiInterface();
523 virtual ~UndoUiInterface();
524 virtual void jobError(KIO::Job* job);
525 };
526
527 KNewFileMenu* m_newMenu;
528 KActionMenu* m_recentTabsMenu;
529 KAction* m_showMenuBar;
530 KTabBar* m_tabBar;
531 DolphinViewContainer* m_activeViewContainer;
532 QVBoxLayout* m_centralWidgetLayout;
533 int m_id;
534
535 struct ViewTab
536 {
537 ViewTab() : isPrimaryViewActive(true), primaryView(0), secondaryView(0), splitter(0) {}
538 bool isPrimaryViewActive;
539 DolphinViewContainer* primaryView;
540 DolphinViewContainer* secondaryView;
541 QSplitter* splitter;
542 };
543
544 int m_tabIndex;
545 QList<ViewTab> m_viewTab;
546
547 DolphinViewActionHandler* m_actionHandler;
548 DolphinRemoteEncoding* m_remoteEncoding;
549 QPointer<DolphinSettingsDialog> m_settingsDialog;
550
551 KJob* m_captionStatJob;
552 KJob* m_lastHandleUrlStatJob;
553 };
554
555 inline DolphinViewContainer* DolphinMainWindow::activeViewContainer() const
556 {
557 return m_activeViewContainer;
558 }
559
560 inline bool DolphinMainWindow::isSplit() const
561 {
562 return m_viewTab[m_tabIndex].secondaryView != 0;
563 }
564
565 inline KNewFileMenu* DolphinMainWindow::newMenu() const
566 {
567 return m_newMenu;
568 }
569
570 inline KAction* DolphinMainWindow::showMenuBarAction() const
571 {
572 return m_showMenuBar;
573 }
574
575 inline int DolphinMainWindow::getId() const
576 {
577 return m_id;
578 }
579
580 #endif // DOLPHIN_MAINWINDOW_H
581