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