]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.h
when clicking with the middle mouse button on a directory, a new tab should be opened
[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 <konq_fileundomanager.h>
32 #include <ksortablelist.h>
33 #include <kxmlguiwindow.h>
34
35 #include <QtCore/QList>
36
37 class KAction;
38 class DolphinViewActionHandler;
39 class DolphinApplication;
40 class DolphinViewContainer;
41 class KNewMenu;
42 class KTabBar;
43 class KUrl;
44 class QSplitter;
45
46 /**
47 * @short Main window for Dolphin.
48 *
49 * Handles the menus, toolbars and Dolphin views.
50 */
51 class DolphinMainWindow: public KXmlGuiWindow
52 {
53 Q_OBJECT
54 Q_CLASSINFO("D-Bus Interface", "org.kde.dolphin.MainWindow")
55 Q_PROPERTY(int id READ getId SCRIPTABLE true)
56 friend class DolphinApplication;
57
58 public:
59 virtual ~DolphinMainWindow();
60
61 /**
62 * Returns the currently active view.
63 * All menu actions are applied to this view. When
64 * having a split view setup, the nonactive view
65 * is usually shown in darker colors.
66 */
67 DolphinViewContainer* activeViewContainer() const;
68
69 /**
70 * Returns true, if the main window contains two instances
71 * of a view container. The active view constainer can be
72 * accessed by DolphinMainWindow::activeViewContainer().
73 */
74 bool isSplit() const;
75
76 /**
77 * If the main window contains two instances of a view container
78 * (DolphinMainWindow::isSplit() returns true), then the
79 * two views get toggled (the right view is on the left, the left
80 * view on the right).
81 */
82 void toggleViews();
83
84 /** Renames the item represented by \a oldUrl to \a newUrl. */
85 void rename(const KUrl& oldUrl, const KUrl& newUrl);
86
87 /**
88 * Refreshes the views of the main window by recreating them dependent from
89 * the given Dolphin settings.
90 */
91 void refreshViews();
92
93 /**
94 * Returns the 'Create New...' sub menu which also can be shared
95 * with other menus (e. g. a context menu).
96 */
97 KNewMenu* newMenu() const;
98
99 /**
100 * Returns the 'Show Menubar' action which can be shared with
101 * other menus (e. g. a context menu).
102 */
103 KAction* showMenuBarAction() const;
104
105 public slots:
106 /**
107 * Handles the dropping of URLs to the given
108 * destination. This is only called by the TreeViewSidebarPage.
109 */
110 void dropUrls(const KUrl::List& urls,
111 const KUrl& destination);
112
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 (sidebars, 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 sidebar.
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 /**
176 * Opens the properties window for the selected items of the
177 * active view. The properties windows shows information
178 * like name, size and permissions.
179 */
180 void properties();
181
182 /**
183 * Shows the error information from the places model
184 * in the status bar.
185 */
186 void slotHandlePlacesError(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 /** Sets the text of the 'Undo' menu action to \a text. */
195 void slotUndoTextChanged(const QString& text);
196
197 /** Performs the current undo operation. */
198 void undo();
199
200 /**
201 * Copies all selected items to the clipboard and marks
202 * the items as cutted.
203 */
204 void cut();
205
206 /** Copies all selected items to the clipboard. */
207 void copy();
208
209 /** Pastes the clipboard data to the active view. */
210 void paste();
211
212 /**
213 * Updates the text of the paste action dependent from
214 * the number of items which are in the clipboard.
215 */
216 void updatePasteAction();
217
218 /** Selects all items from the active view. */
219 void selectAll();
220
221 /**
222 * Inverts the selection of all items of the active view:
223 * Selected items get nonselected and nonselected items get
224 * selected.
225 */
226 void invertSelection();
227
228 /**
229 * Switches between one and two views:
230 * If one view is visible, it will get split into two views.
231 * If already two views are visible, the nonactivated view gets closed.
232 */
233 void toggleSplitView();
234
235 /** Reloads the current active view. */
236 void reloadView();
237
238 /** Stops the loading process for the current active view. */
239 void stopLoading();
240
241 /**
242 * Toggles between showing and hiding of the filter bar
243 */
244 void toggleFilterBarVisibility(bool show);
245
246 /**
247 * Toggles between edit and browse mode of the navigation bar.
248 */
249 void toggleEditLocation();
250
251 /**
252 * Switches to the edit mode of the navigation bar. If the edit mode is
253 * already active, it is assured that the navigation bar get focused.
254 */
255 void editLocation();
256
257 /**
258 * Opens the view properties dialog, which allows to modify the properties
259 * of the currently active view.
260 */
261 void adjustViewProperties();
262
263 /** Goes back on step of the URL history. */
264 void goBack();
265
266 /** Goes forward one step of the URL history. */
267 void goForward();
268
269 /** Goes up one hierarchy of the current URL. */
270 void goUp();
271
272 /** Goes to the home URL. */
273 void goHome();
274
275 /** Opens KFind for the current shown directory. */
276 void findFile();
277
278 /** Opens Kompare for 2 selected files. */
279 void compareFiles();
280
281 /**
282 * Hides the menu bar if it is visible, makes the menu bar
283 * visible if it is hidden.
284 */
285 void toggleShowMenuBar();
286
287 /** Opens the settings dialog for Dolphin. */
288 void editSettings();
289
290 /** Updates the state of the 'Show Full Location' action. */
291 void slotEditableStateChanged(bool editable);
292
293 /**
294 * Updates the state of the 'Edit' menu actions and emits
295 * the signal selectionChanged().
296 */
297 void slotSelectionChanged(const KFileItemList& selection);
298
299 /** Emits the signal requestItemInfo(). */
300 void slotRequestItemInfo(const KFileItem&);
301
302 /**
303 * Updates the state of the 'Back' and 'Forward' menu
304 * actions corresponding the the current history.
305 */
306 void updateHistory();
307
308 /** Updates the state of the 'Show filter bar' menu action. */
309 void updateFilterBarAction(bool show);
310
311 /** Open a new main window. */
312 void openNewMainWindow();
313
314 /** Opens a new view with the current URL that is part of a tab. */
315 void openNewTab();
316
317 /**
318 * Opens a new tab showing the URL \a url.
319 */
320 void openNewTab(const KUrl& url);
321
322 /** Toggles the active view if two views are shown within the main window. */
323 void toggleActiveView();
324
325 /** Called when the view is doing a file operation, like renaming, copying, moving etc. */
326 void slotDoingOperation(KonqFileUndoManager::CommandType type);
327
328 /**
329 * Activates the tab with the index \a index, which means that the current view
330 * is replaced by the view of the given tab.
331 */
332 void setActiveTab(int index);
333
334 private:
335 DolphinMainWindow(int id);
336 void init();
337
338 /**
339 * Activates the given view, which means that
340 * all menu actions are applied to this view. When
341 * having a split view setup, the nonactive view
342 * is usually shown in darker colors.
343 */
344 void setActiveViewContainer(DolphinViewContainer* view);
345
346 void setupActions();
347 void setupDockWidgets();
348 void updateEditActions();
349 void updateViewActions();
350 void updateGoActions();
351
352 /**
353 * Connects the signals from the created DolphinView with
354 * the DolphinViewContainer \a container with the corresponding slots of
355 * the DolphinMainWindow. This method must be invoked each
356 * time a DolphinView has been created.
357 */
358 void connectViewSignals(DolphinViewContainer* container);
359
360 /**
361 * Updates the text of the split action:
362 * If two views are shown, the text is set to "Split",
363 * otherwise the text is set to "Join". The icon
364 * is updated to match with the text and the currently active view.
365 */
366 void updateSplitAction();
367
368 private:
369 /**
370 * Implements a custom error handling for the undo manager. This
371 * assures that all errors are shown in the status bar of Dolphin
372 * instead as modal error dialog with an OK button.
373 */
374 class UndoUiInterface : public KonqFileUndoManager::UiInterface
375 {
376 public:
377 UndoUiInterface(DolphinMainWindow* mainWin);
378 virtual ~UndoUiInterface();
379 virtual void jobError(KIO::Job* job);
380
381 private:
382 DolphinMainWindow* m_mainWin;
383 };
384
385 KNewMenu* m_newMenu;
386 KAction* m_showMenuBar;
387 KTabBar* m_tabBar;
388 DolphinViewContainer* m_activeViewContainer;
389 QVBoxLayout* m_centralWidgetLayout;
390 int m_id;
391
392 struct ViewTab
393 {
394 ViewTab() : primaryView(0), secondaryView(0), splitter(0) {}
395 DolphinViewContainer* primaryView;
396 DolphinViewContainer* secondaryView;
397 QSplitter* splitter;
398 };
399
400 int m_tabIndex;
401 QList<ViewTab> m_viewTab;
402
403 DolphinViewActionHandler* m_actionHandler;
404
405 /// remember pending undo operations until they are finished
406 QList<KonqFileUndoManager::CommandType> m_undoCommandTypes;
407 };
408
409 inline DolphinViewContainer* DolphinMainWindow::activeViewContainer() const
410 {
411 return m_activeViewContainer;
412 }
413
414 inline bool DolphinMainWindow::isSplit() const
415 {
416 return m_viewTab[m_tabIndex].secondaryView != 0;
417 }
418
419 inline KNewMenu* DolphinMainWindow::newMenu() const
420 {
421 return m_newMenu;
422 }
423
424 inline KAction* DolphinMainWindow::showMenuBarAction() const
425 {
426 return m_showMenuBar;
427 }
428
429 inline int DolphinMainWindow::getId() const
430 {
431 return m_id;
432 }
433
434 #endif // DOLPHIN_MAINWINDOW_H
435