]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.h
use KAction::setShortcut() instead of QAction::setShortcut()
[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 KNewMenu;
49 class KTabBar;
50 class KUrl;
51 class QSplitter;
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 KNewMenu* 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 /**
219 * Updates the text of the paste action dependent from
220 * the number of items which are in the clipboard.
221 */
222 void updatePasteAction();
223
224 /** Selects all items from the active view. */
225 void selectAll();
226
227 /**
228 * Inverts the selection of all items of the active view:
229 * Selected items get nonselected and nonselected items get
230 * selected.
231 */
232 void invertSelection();
233
234 /**
235 * Switches between one and two views:
236 * If one view is visible, it will get split into two views.
237 * If already two views are visible, the nonactivated view gets closed.
238 */
239 void toggleSplitView();
240
241 /** Reloads the current active view. */
242 void reloadView();
243
244 /** Stops the loading process for the current active view. */
245 void stopLoading();
246
247 /**
248 * Toggles between showing and hiding of the filter bar
249 */
250 void toggleFilterBarVisibility(bool show);
251
252 /**
253 * Toggles between edit and browse mode of the navigation bar.
254 */
255 void toggleEditLocation();
256
257 /**
258 * Switches to the edit mode of the navigation bar and selects
259 * the whole URL, so that it can be replaced by the user. If the edit mode is
260 * already active, it is assured that the navigation bar get focused.
261 */
262 void replaceLocation();
263
264 /** Goes back on step of the URL history. */
265 void goBack();
266
267 /** Goes forward one step of the URL history. */
268 void goForward();
269
270 /** Goes up one hierarchy of the current URL. */
271 void goUp();
272
273 /**
274 * Open the previous URL in the URL history in a new tab
275 * if the middle mouse button is clicked.
276 */
277 void goBack(Qt::MouseButtons buttons);
278
279 /**
280 * Open the next URL in the URL history in a new tab
281 * if the middle mouse button is clicked.
282 */
283 void goForward(Qt::MouseButtons buttons);
284
285 /**
286 * Open the URL one hierarchy above the current URL in a new tab
287 * if the middle mouse button is clicked.
288 */
289 void goUp(Qt::MouseButtons buttons);
290
291 /** Goes to the home URL. */
292 void goHome();
293
294 /** Opens Kompare for 2 selected files. */
295 void compareFiles();
296
297 /**
298 * Hides the menu bar if it is visible, makes the menu bar
299 * visible if it is hidden.
300 */
301 void toggleShowMenuBar();
302
303 /** Opens a terminal window for the current location. */
304 void openTerminal();
305
306 /** Opens the settings dialog for Dolphin. */
307 void editSettings();
308
309 /** Updates the state of the 'Show Full Location' action. */
310 void slotEditableStateChanged(bool editable);
311
312 /**
313 * Updates the state of the 'Edit' menu actions and emits
314 * the signal selectionChanged().
315 */
316 void slotSelectionChanged(const KFileItemList& selection);
317
318 /** Enables changing of tabs via mouse wheel. */
319 void slotWheelMoved(int wheelDelta);
320
321 /** Emits the signal requestItemInfo(). */
322 void slotRequestItemInfo(const KFileItem&);
323
324 /**
325 * Updates the state of the 'Back' and 'Forward' menu
326 * actions corresponding to the current history.
327 */
328 void updateHistory();
329
330 /** Updates the state of the 'Show filter bar' menu action. */
331 void updateFilterBarAction(bool show);
332
333 /** Open a new main window. */
334 void openNewMainWindow();
335
336 /** Opens a new view with the current URL that is part of a tab. */
337 void openNewTab();
338
339 /**
340 * Opens a new tab showing the URL \a url.
341 */
342 void openNewTab(const KUrl& url);
343
344 void activateNextTab();
345
346 void activatePrevTab();
347
348 /**
349 * Opens the selected folder in a new tab.
350 */
351 void openInNewTab();
352
353 /**
354 * Opens the selected folder in a new window.
355 */
356 void openInNewWindow();
357
358 /** Toggles the active view if two views are shown within the main window. */
359 void toggleActiveView();
360
361 /**
362 * Indicates in the statusbar that the execution of the command \a command
363 * has been finished.
364 */
365 void showCommand(CommandType command);
366
367 /**
368 * Activates the tab with the index \a index, which means that the current view
369 * is replaced by the view of the given tab.
370 */
371 void setActiveTab(int index);
372
373 /** Closes the currently active tab. */
374 void closeTab();
375
376 /**
377 * Closes the tab with the index \index and activates the tab with index - 1.
378 */
379 void closeTab(int index);
380
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 * Handles a click on a places item: if the middle mouse button is
390 * clicked, a new tab is opened for \a url, otherwise the current
391 * view is replaced by \a url.
392 */
393 void handlePlacesClick(const KUrl& url, Qt::MouseButtons buttons);
394
395 /**
396 * Is connected to the KTabBar signal testCanDecode() and adjusts
397 * the output parameter \a accept.
398 */
399 void slotTestCanDecode(const QDragMoveEvent* event, bool& accept);
400
401 /**
402 * Is connected with the Dolphin search box and the search configurator
403 * and triggers a Nepomuk search.
404 */
405 void searchItems();
406
407 /**
408 * Is connected to the QTabBar signal tabMoved(int from, int to).
409 * Reorders the list of tabs after a tab was moved in the tab bar
410 * and sets m_tabIndex to the new index of the current tab.
411 */
412 void slotTabMoved(int from, int to);
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 private:
427 DolphinMainWindow(int id);
428 void init();
429
430 /**
431 * Activates the given view, which means that
432 * all menu actions are applied to this view. When
433 * having a split view setup, the nonactive view
434 * is usually shown in darker colors.
435 */
436 void setActiveViewContainer(DolphinViewContainer* view);
437
438 void setupActions();
439 void setupDockWidgets();
440 void updateEditActions();
441 void updateViewActions();
442 void updateGoActions();
443
444 /**
445 * Adds the tab[\a index] to the closed tab menu's list of actions.
446 */
447 void rememberClosedTab(int index);
448
449 /**
450 * Connects the signals from the created DolphinView with
451 * the DolphinViewContainer \a container with the corresponding slots of
452 * the DolphinMainWindow. This method must be invoked each
453 * time a DolphinView has been created.
454 */
455 void connectViewSignals(DolphinViewContainer* container);
456
457 /**
458 * Updates the text of the split action:
459 * If two views are shown, the text is set to "Split",
460 * otherwise the text is set to "Join". The icon
461 * is updated to match with the text and the currently active view.
462 */
463 void updateSplitAction();
464
465 /** Returns the name of the tab for the URL \a url. */
466 QString tabName(const KUrl& url) const;
467
468 bool isKompareInstalled() const;
469
470 void createSecondaryView(int tabIndex);
471
472 /**
473 * Helper method for saveProperties() and readProperties(): Returns
474 * the property string for a tab with the index \a tabIndex and
475 * the property \a property.
476 */
477 QString tabProperty(const QString& property, int tabIndex) const;
478
479 /**
480 * Sets the window caption to url.fileName() if this is non-empty,
481 * "/" if the URL is "file:///", and url.protocol() otherwise.
482 */
483 void setUrlAsCaption(const KUrl& url);
484
485 QString squeezedText(const QString& text) const;
486
487 private:
488 /**
489 * Implements a custom error handling for the undo manager. This
490 * assures that all errors are shown in the status bar of Dolphin
491 * instead as modal error dialog with an OK button.
492 */
493 class UndoUiInterface : public KIO::FileUndoManager::UiInterface
494 {
495 public:
496 UndoUiInterface();
497 virtual ~UndoUiInterface();
498 virtual void jobError(KIO::Job* job);
499 };
500
501 KNewMenu* m_newMenu;
502 KActionMenu* m_recentTabsMenu;
503 KAction* m_showMenuBar;
504 KTabBar* m_tabBar;
505 DolphinViewContainer* m_activeViewContainer;
506 QVBoxLayout* m_centralWidgetLayout;
507 DolphinSearchBox* m_searchBox;
508 DolphinSearchOptionsConfigurator* m_searchOptionsConfigurator;
509 int m_id;
510
511 struct ViewTab
512 {
513 ViewTab() : isPrimaryViewActive(true), primaryView(0), secondaryView(0), splitter(0) {}
514 bool isPrimaryViewActive;
515 DolphinViewContainer* primaryView;
516 DolphinViewContainer* secondaryView;
517 QSplitter* splitter;
518 };
519
520 int m_tabIndex;
521 QList<ViewTab> m_viewTab;
522
523 DolphinViewActionHandler* m_actionHandler;
524 DolphinRemoteEncoding* m_remoteEncoding;
525 QPointer<DolphinSettingsDialog> m_settingsDialog;
526 };
527
528 inline DolphinViewContainer* DolphinMainWindow::activeViewContainer() const
529 {
530 return m_activeViewContainer;
531 }
532
533 inline bool DolphinMainWindow::isSplit() const
534 {
535 return m_viewTab[m_tabIndex].secondaryView != 0;
536 }
537
538 inline KNewMenu* DolphinMainWindow::newMenu() const
539 {
540 return m_newMenu;
541 }
542
543 inline KAction* DolphinMainWindow::showMenuBarAction() const
544 {
545 return m_showMenuBar;
546 }
547
548 inline int DolphinMainWindow::getId() const
549 {
550 return m_id;
551 }
552
553 #endif // DOLPHIN_MAINWINDOW_H
554