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