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