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