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