]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.h
cb0be1431c0765f2a22a9958d72dfe320de7d67d
[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 #include <kmodifierkeyinfo.h>
35
36 #include "views/dolphinview.h"
37
38 #include "dolphincontextmenu.h"
39
40 #include <QList>
41
42 typedef KIO::FileUndoManager::CommandType CommandType;
43
44 class KAction;
45 class DolphinViewActionHandler;
46 class DolphinApplication;
47 class DolphinSettingsDialog;
48 class DolphinViewContainer;
49 class DolphinRemoteEncoding;
50 class KNewFileMenu;
51 class KTabBar;
52 class KUrl;
53 class QSplitter;
54 class KJob;
55
56 /**
57 * @short Main window for Dolphin.
58 *
59 * Handles the menus, toolbars and Dolphin views.
60 */
61 class DolphinMainWindow: public KXmlGuiWindow
62 {
63 Q_OBJECT
64 Q_CLASSINFO("D-Bus Interface", "org.kde.dolphin.MainWindow")
65 Q_PROPERTY(int id READ getId SCRIPTABLE true)
66 friend class DolphinApplication;
67
68 public:
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 \p 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 /**
100 * If the main window contains two instances of a view container
101 * (DolphinMainWindow::isSplit() returns true), then the
102 * two views get toggled (the right view is on the left, the left
103 * view on the right).
104 */
105 void toggleViews();
106
107 /** Renames the item represented by \a oldUrl to \a newUrl. */
108 void rename(const KUrl& oldUrl, const KUrl& newUrl);
109
110 /**
111 * Refreshes the views of the main window by recreating them dependent from
112 * the given Dolphin settings.
113 */
114 void refreshViews();
115
116 /**
117 * Returns the 'Create New...' sub menu which also can be shared
118 * with other menus (e. g. a context menu).
119 */
120 KNewFileMenu* newFileMenu() const;
121
122 /**
123 * Returns the 'Show Menubar' action which can be shared with
124 * other menus (e. g. a context menu).
125 */
126 KAction* showMenuBarAction() const;
127
128 public slots:
129 /**
130 * Pastes the clipboard data into the currently selected folder
131 * of the active view. If not exactly one folder is selected,
132 * no pasting is done at all.
133 */
134 void pasteIntoFolder();
135
136 /**
137 * Returns the main window ID used through DBus.
138 */
139 int getId() const;
140
141 /**
142 * Implementation of the MainWindowAdaptor/QDBusAbstractAdaptor interface.
143 * Inform all affected dolphin components (panels, views) of an URL
144 * change.
145 */
146 void changeUrl(const KUrl& url);
147
148 /** Stores all settings and quits Dolphin. */
149 void quit();
150
151 signals:
152 /**
153 * Is sent if the selection of the currently active view has
154 * been changed.
155 */
156 void selectionChanged(const KFileItemList& selection);
157
158 /**
159 * Is sent if the url of the currently active view has
160 * been changed.
161 */
162 void urlChanged(const KUrl& url);
163
164 /**
165 * Is emitted if information of an item is requested to be shown e. g. in the panel.
166 * If item is null, no item information request is pending.
167 */
168 void requestItemInfo(const KFileItem& item);
169
170 protected:
171 /** @see QWidget::showEvent() */
172 virtual void showEvent(QShowEvent* event);
173
174 /** @see QMainWindow::closeEvent() */
175 virtual void closeEvent(QCloseEvent* event);
176
177 /** @see KMainWindow::saveProperties() */
178 virtual void saveProperties(KConfigGroup& group);
179
180 /** @see KMainWindow::readProperties() */
181 virtual void readProperties(const KConfigGroup& group);
182
183 private slots:
184 void clearStatusBar();
185
186 /** Updates the 'Create New...' sub menu. */
187 void updateNewMenu();
188
189 void createDirectory();
190
191 /** Shows the error message in the status bar of the active view. */
192 void showErrorMessage(const QString& message);
193
194 /**
195 * Updates the state of the 'Undo' menu action dependent
196 * from the parameter \a available.
197 */
198 void slotUndoAvailable(bool available);
199
200 /** Invoked when an action in the recent tabs menu is clicked. */
201 void restoreClosedTab(QAction* action);
202
203 /** Sets the text of the 'Undo' menu action to \a text. */
204 void slotUndoTextChanged(const QString& text);
205
206 /** Performs the current undo operation. */
207 void undo();
208
209 /**
210 * Copies all selected items to the clipboard and marks
211 * the items as cut.
212 */
213 void cut();
214
215 /** Copies all selected items to the clipboard. */
216 void copy();
217
218 /** Pastes the clipboard data to the active view. */
219 void paste();
220
221 /** Replaces the URL navigator by a search box to find files. */
222 void find();
223
224 /**
225 * Updates the text of the paste action dependent from
226 * the number of items which are in the clipboard.
227 */
228 void updatePasteAction();
229
230 /** Selects all items from the active view. */
231 void selectAll();
232
233 /**
234 * Inverts the selection of all items of the active view:
235 * Selected items get nonselected and nonselected items get
236 * selected.
237 */
238 void invertSelection();
239
240 /**
241 * Switches between one and two views:
242 * If one view is visible, it will get split into two views.
243 * If already two views are visible, the nonactivated view gets closed.
244 */
245 void toggleSplitView();
246
247 /** Reloads the current active view. */
248 void reloadView();
249
250 /** Stops the loading process for the current active view. */
251 void stopLoading();
252
253 /**
254 * Toggles between showing and hiding of the filter bar
255 */
256 void toggleFilterBarVisibility(bool show);
257
258 /**
259 * Toggles between edit and browse mode of the navigation bar.
260 */
261 void toggleEditLocation();
262
263 /**
264 * Switches to the edit mode of the navigation bar and selects
265 * the whole URL, so that it can be replaced by the user. If the edit mode is
266 * already active, it is assured that the navigation bar get focused.
267 */
268 void replaceLocation();
269
270 /** Goes back on step of the URL history. */
271 void goBack();
272
273 /** Goes forward one step of the URL history. */
274 void goForward();
275
276 /** Goes up one hierarchy of the current URL. */
277 void goUp();
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 /** Goes to the home URL. */
298 void goHome();
299
300 /** Opens Kompare for 2 selected files. */
301 void compareFiles();
302
303 /**
304 * Hides the menu bar if it is visible, makes the menu bar
305 * visible if it is hidden.
306 */
307 void toggleShowMenuBar();
308
309 /** Opens a terminal window for the current location. */
310 void openTerminal();
311
312 /** Opens the settings dialog for Dolphin. */
313 void editSettings();
314
315 /** Updates the state of the 'Show Full Location' action. */
316 void slotEditableStateChanged(bool editable);
317
318 /**
319 * Updates the state of the 'Edit' menu actions and emits
320 * the signal selectionChanged().
321 */
322 void slotSelectionChanged(const KFileItemList& selection);
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 * Is connected to the KTabBar signal receivedDropEvent.
424 * Allows dragging and dropping files onto tabs.
425 */
426 void tabDropEvent(int tab, QDropEvent* event);
427
428 /**
429 * Is invoked when the write state of a folder has been changed and
430 * enables/disables the "Create New..." menu entry.
431 */
432 void slotWriteStateChanged(bool isFolderWritable);
433
434 /**
435 * Opens the context menu on the current mouse position.
436 * @item File item context. If item is null, the context menu
437 * should be applied to \a url.
438 * @url URL which contains \a item.
439 * @customActions Actions that should be added to the context menu,
440 * if the file item is null.
441 */
442 void openContextMenu(const KFileItem& item,
443 const KUrl& url,
444 const QList<QAction*>& customActions);
445
446 private:
447 DolphinMainWindow(int id);
448 void init();
449
450 /**
451 * Activates the given view, which means that
452 * all menu actions are applied to this view. When
453 * having a split view setup, the nonactive view
454 * is usually shown in darker colors.
455 */
456 void setActiveViewContainer(DolphinViewContainer* view);
457
458 void setupActions();
459 void setupDockWidgets();
460 void updateEditActions();
461 void updateViewActions();
462 void updateGoActions();
463
464 /**
465 * Adds the tab[\a index] to the closed tab menu's list of actions.
466 */
467 void rememberClosedTab(int index);
468
469 /**
470 * Connects the signals from the created DolphinView with
471 * the DolphinViewContainer \a container with the corresponding slots of
472 * the DolphinMainWindow. This method must be invoked each
473 * time a DolphinView has been created.
474 */
475 void connectViewSignals(DolphinViewContainer* container);
476
477 /**
478 * Updates the text of the split action:
479 * If two views are shown, the text is set to "Split",
480 * otherwise the text is set to "Join". The icon
481 * is updated to match with the text and the currently active view.
482 */
483 void updateSplitAction();
484
485 /** Returns the name of the tab for the URL \a url. */
486 QString tabName(const KUrl& url) const;
487
488 bool isKompareInstalled() const;
489
490 void createSecondaryView(int tabIndex);
491
492 /**
493 * Helper method for saveProperties() and readProperties(): Returns
494 * the property string for a tab with the index \a tabIndex and
495 * the property \a property.
496 */
497 QString tabProperty(const QString& property, int tabIndex) const;
498
499 /**
500 * Sets the window caption to url.fileName() if this is non-empty,
501 * "/" if the URL is "file:///", and url.protocol() otherwise.
502 */
503 void setUrlAsCaption(const KUrl& url);
504
505 QString squeezedText(const QString& text) const;
506
507 private:
508 /**
509 * Implements a custom error handling for the undo manager. This
510 * assures that all errors are shown in the status bar of Dolphin
511 * instead as modal error dialog with an OK button.
512 */
513 class UndoUiInterface : public KIO::FileUndoManager::UiInterface
514 {
515 public:
516 UndoUiInterface();
517 virtual ~UndoUiInterface();
518 virtual void jobError(KIO::Job* job);
519 };
520
521 KNewFileMenu* m_newFileMenu;
522 KActionMenu* m_recentTabsMenu;
523 KAction* m_showMenuBar;
524 KTabBar* m_tabBar;
525 DolphinViewContainer* m_activeViewContainer;
526 QVBoxLayout* m_centralWidgetLayout;
527 int m_id;
528
529 struct ViewTab
530 {
531 ViewTab() : isPrimaryViewActive(true), primaryView(0), secondaryView(0), splitter(0) {}
532 bool isPrimaryViewActive;
533 DolphinViewContainer* primaryView;
534 DolphinViewContainer* secondaryView;
535 QSplitter* splitter;
536 };
537
538 int m_tabIndex;
539 QList<ViewTab> m_viewTab;
540
541 DolphinViewActionHandler* m_actionHandler;
542 DolphinRemoteEncoding* m_remoteEncoding;
543 QPointer<DolphinSettingsDialog> m_settingsDialog;
544
545 KJob* m_lastHandleUrlStatJob;
546
547 KModifierKeyInfo m_keyInfo;
548 };
549
550 inline DolphinViewContainer* DolphinMainWindow::activeViewContainer() const
551 {
552 return m_activeViewContainer;
553 }
554
555 inline bool DolphinMainWindow::isSplit() const
556 {
557 return m_viewTab[m_tabIndex].secondaryView != 0;
558 }
559
560 inline KNewFileMenu* DolphinMainWindow::newFileMenu() const
561 {
562 return m_newFileMenu;
563 }
564
565 inline KAction* DolphinMainWindow::showMenuBarAction() const
566 {
567 return m_showMenuBar;
568 }
569
570 inline int DolphinMainWindow::getId() const
571 {
572 return m_id;
573 }
574
575 #endif // DOLPHIN_MAINWINDOW_H
576