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