]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.h
Additionally to sorting by name, size and date it is now possible to sort by permissi...
[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
27 #include <kmainwindow.h>
28 #include <ksortablelist.h>
29 #include <konq_operations.h>
30 #include <konq_undo.h>
31
32 #include <QList>
33
34 class KNewMenu;
35 class KPrinter;
36 class KUrl;
37 class QLineEdit;
38 class KFileIconView;
39 class KHBox;
40 class Q3IconViewItem;
41 class QSplitter;
42 class KAction;
43 class UrlNavigator;
44 class DolphinApplication;
45
46 /**
47 * @short Main window for Dolphin.
48 *
49 * Handles the menus, toolbars and Dolphin views.
50 *
51 * @author Peter Penz <peter.penz@gmx.at>
52 */
53 class DolphinMainWindow: public KMainWindow
54 {
55 Q_OBJECT
56 friend class DolphinApplication;
57 public:
58 virtual ~DolphinMainWindow();
59
60 /**
61 * Activates the given view, which means that
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 void setActiveView(DolphinView* view);
67
68 /**
69 * Returns the currently active view. See
70 * DolphinMainWindow::setActiveView() for more details.
71 */
72 DolphinView* activeView() const { return m_activeView; }
73
74 /**
75 * Handles the dropping of Urls to the given
76 * destination. A context menu with the options
77 * 'Move Here', 'Copy Here', 'Link Here' and
78 * 'Cancel' is offered to the user.
79 * @param urls List of Urls which have been
80 * dropped.
81 * @param destination Destination Url, where the
82 * list or Urls should be moved,
83 * copied or linked to.
84 */
85 void dropUrls(const KUrl::List& urls,
86 const KUrl& destination);
87
88 /**
89 * Refreshs the views of the main window by recreating them dependent from
90 * the given Dolphin settings.
91 */
92 void refreshViews();
93
94 /**
95 * Returns the 'Create New...' sub menu which also can be shared
96 * with other menus (e. g. a context menu).
97 */
98 KNewMenu* newMenu() const { return m_newMenu; }
99
100 signals:
101 /**
102 * Is send if the active view has been changed in
103 * the split view mode.
104 */
105 void activeViewChanged();
106
107 /**
108 * Is send if the selection of the currently active view has
109 * been changed.
110 */
111 void selectionChanged();
112
113 protected:
114 /** @see QMainWindow::closeEvent */
115 virtual void closeEvent(QCloseEvent* event);
116
117 /**
118 * This method is called when it is time for the app to save its
119 * properties for session management purposes.
120 */
121 void saveProperties(KConfig*);
122
123 /**
124 * This method is called when this app is restored. The KConfig
125 * object points to the session management config file that was saved
126 * with @ref saveProperties
127 */
128 void readProperties(KConfig*);
129
130 private slots:
131 /** Updates the 'Create New...' sub menu. */
132 void updateNewMenu();
133
134 /** Renames the selected item of the active view. */
135 void rename();
136
137 /** Moves the selected items of the active view to the trash. */
138 void moveToTrash();
139
140 /** Deletes the selected items of the active view. */
141 void deleteItems();
142
143 /**
144 * Opens the properties window for the selected items of the
145 * active view. The properties windows shows informations
146 * like name, size and permissions.
147 */
148 void properties();
149
150 /** Stores all settings and quits Dolphin. */
151 void quit();
152
153 /**
154 * Shows the error information of the job \a job
155 * in the status bar.
156 */
157 void slotHandleJobError(KJob* job);
158
159 /**
160 * Indicates in the status bar that the delete operation
161 * of the job \a job has been finished.
162 */
163 void slotDeleteFileFinished(KJob* job);
164
165 /**
166 * Updates the state of the 'Undo' menu action dependent
167 * from the parameter \a available.
168 */
169 void slotUndoAvailable(bool available);
170
171 /** Sets the text of the 'Undo' menu action to \a text. */
172 void slotUndoTextChanged(const QString& text);
173
174 /** Performs the current undo operation. */
175 void undo();
176
177 /**
178 * Copies all selected items to the clipboard and marks
179 * the items as cutted.
180 */
181 void cut();
182
183 /** Copies all selected items to the clipboard. */
184 void copy();
185
186 /** Pastes the clipboard data to the active view. */
187 void paste();
188
189 /**
190 * Updates the text of the paste action dependent from
191 * the number of items which are in the clipboard.
192 */
193 void updatePasteAction();
194
195 /** Selects all items from the active view. */
196 void selectAll();
197
198 /**
199 * Inverts the selection of all items of the active view:
200 * Selected items get nonselected and nonselected items get
201 * selected.
202 */
203 void invertSelection();
204
205 /** The current active view is switched to the icons mode. */
206 void setIconsView();
207
208 /** The current active view is switched to the details mode. */
209 void setDetailsView();
210
211 /** The sorting of the current view should be done by the name. */
212 void sortByName();
213
214 /** The sorting of the current view should be done by the size. */
215 void sortBySize();
216
217 /** The sorting of the current view should be done by the date. */
218 void sortByDate();
219
220 /** The sorting of the current view should be done by the permissions. */
221 void sortByPermissions();
222
223 /** The sorting of the current view should be done by the owner. */
224 void sortByOwner();
225
226 /** The sorting of the current view should be done by the group. */
227 void sortByGroup();
228
229 /** Switches between an ascending and descending sorting order. */
230 void toggleSortOrder();
231
232 /**
233 * Switches between one and two views:
234 * If one view is visible, it will get split into two views.
235 * If already two views are visible, the nonactivated view gets closed.
236 */
237 void toggleSplitView();
238
239 /** Reloads the current active view. */
240 void reloadView();
241
242 /** Stops the loading process for the current active view. */
243 void stopLoading();
244
245 /** Switches between showing a preview of the file content and showing the icon. */
246 void togglePreview();
247
248 /**
249 * Switches between showing and hiding of hidden marked files dependent
250 * from the current state of the 'Show Hidden Files' menu toggle action.
251 */
252 void toggleShowHiddenFiles();
253
254 /**
255 * Switches between showing and hiding of the filter bar dependent
256 * from the current state of the 'Show Filter Bar' menu toggle action.
257 */
258 void showFilterBar();
259
260 /** Increases the size of the current set view mode. */
261 void zoomIn();
262
263 /** Decreases the size of the current set view mode. */
264 void zoomOut();
265
266 /**
267 * Toggles between edit and brose mode of the navigation bar.
268 */
269 void toggleEditLocation();
270
271 /**
272 * Switches to the edit mode of the navigation bar. If the edit mode is
273 * already active, it is assured that the navigation bar get focused.
274 */
275 void editLocation();
276
277 /**
278 * Opens the view properties dialog, which allows to modify the properties
279 * of the currently active view.
280 */
281 void adjustViewProperties();
282
283 /** Goes back on step of the Url history. */
284 void goBack();
285
286 /** Goes forward one step of the Url history. */
287 void goForward();
288
289 /** Goes up one hierarchy of the current Url. */
290 void goUp();
291
292 /** Goes to the home Url. */
293 void goHome();
294
295 /** Opens a terminal for the current shown directory. */
296 void openTerminal();
297
298 /** Opens KFind for the current shown directory. */
299 void findFile();
300
301 /** Opens Kompare for 2 selected files. */
302 void compareFiles();
303
304 /** Opens the settings dialog for Dolphin. */
305 void editSettings();
306
307 /** Updates the state of all 'View' menu actions. */
308 void slotViewModeChanged();
309
310 /** Updates the state of the 'Show hidden files' menu action. */
311 void slotShowHiddenFilesChanged();
312
313 /** Updates the state of the 'Sort by' actions. */
314 void slotSortingChanged(DolphinView::Sorting sorting);
315
316 /** Updates the state of the 'Sort Ascending/Descending' action. */
317 void slotSortOrderChanged(Qt::SortOrder order);
318
319 /** Updates the state of the 'Edit' menu actions. */
320 void slotSelectionChanged();
321
322 /**
323 * Updates the state of the 'Back' and 'Forward' menu
324 * actions corresponding the the current history.
325 */
326 void slotHistoryChanged();
327
328 /**
329 * Updates the caption of the main window and the state
330 * of all menu actions which depend from a changed Url.
331 */
332 void slotUrlChanged(const KUrl& url);
333
334 /** Updates the state of the 'Show filter bar' menu action. */
335 void updateFilterBarAction(bool show);
336
337 /** Open a new main window. */
338 void openNewMainWindow();
339
340 private:
341 DolphinMainWindow();
342 void init();
343 void loadSettings();
344
345 void setupAccel();
346 void setupActions();
347 void setupDockWidgets();
348 void updateHistory();
349 void updateEditActions();
350 void updateViewActions();
351 void updateGoActions();
352 void copyUrls(const KUrl::List& source, const KUrl& dest);
353 void moveUrls(const KUrl::List& source, const KUrl& dest);
354 void linkUrls(const KUrl::List& source, const KUrl& dest);
355 void clearStatusBar();
356
357 /**
358 * Connects the signals from the created DolphinView with
359 * the index \a viewIndex with the corresponding slots of
360 * the DolphinMainWindow. This method must be invoked each
361 * time a DolphinView has been created.
362 */
363 void connectViewSignals(int viewIndex);
364
365 private:
366 /**
367 * DolphinMainWindowsupports only one or two views, which
368 * are handled internally as primary and secondary view.
369 */
370 enum ViewIndex
371 {
372 PrimaryIdx = 0,
373 SecondaryIdx = 1
374 };
375
376 /**
377 * Implements a custom error handling for the undo manager. This
378 * assures that all errors are shown in the status bar of Dolphin
379 * instead as modal error dialog with an OK button.
380 */
381 class UndoUiInterface : public KonqUndoManager::UiInterface
382 {
383 public:
384 UndoUiInterface(DolphinMainWindow* mainWin);
385 virtual ~UndoUiInterface();
386 virtual void jobError(KIO::Job* job);
387
388 private:
389 DolphinMainWindow* m_mainWin;
390 };
391
392 KNewMenu* m_newMenu;
393 QSplitter* m_splitter;
394 DolphinView* m_activeView;
395
396 DolphinView* m_view[SecondaryIdx + 1];
397
398 /// remember pending undo operations until they are finished
399 QList<KonqOperations::Operation> m_undoOperations;
400 };
401
402 #endif // _DOLPHIN_H_
403