]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.h
Doesn't need a config.h
[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 <kmainwindow.h>
26 #include <ksortablelist.h>
27
28 #include <q3valuelist.h>
29
30 #include "dolphinview.h"
31 #include "undomanager.h" // for DolphinCommand::Type
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 * Updates the state of the 'Redo' menu action dependent
178 * from the parameter \a available.
179 */
180 void slotRedoAvailable(bool available);
181
182 /** Sets the text of the 'Redo' menu action to \a text. */
183 void slotRedoTextChanged(const QString& text);
184
185 /**
186 * Copies all selected items to the clipboard and marks
187 * the items as cutted.
188 */
189 void cut();
190
191 /** Copies all selected items to the clipboard. */
192 void copy();
193
194 /** Pastes the clipboard data to the active view. */
195 void paste();
196
197 /**
198 * Updates the text of the paste action dependent from
199 * the number of items which are in the clipboard.
200 */
201 void updatePasteAction();
202
203 /** Selects all items from the active view. */
204 void selectAll();
205
206 /**
207 * Inverts the selection of all items of the active view:
208 * Selected items get nonselected and nonselected items get
209 * selected.
210 */
211 void invertSelection();
212
213 /** The current active view is switched to the icons mode. */
214 void setIconsView();
215
216 /** The current active view is switched to the details mode. */
217 void setDetailsView();
218
219 /** The sorting of the current view should be done by the name. */
220 void sortByName();
221
222 /** The sorting of the current view should be done by the size. */
223 void sortBySize();
224
225 /** The sorting of the current view should be done by the date. */
226 void sortByDate();
227
228 /** Switches between an ascending and descending sorting order. */
229 void toggleSortOrder();
230
231 /**
232 * Switches between one and two views:
233 * If one view is visible, it will get split into two views.
234 * If already two views are visible, the nonactivated view gets closed.
235 */
236 void toggleSplitView();
237
238 /** Reloads the current active view. */
239 void reloadView();
240
241 /** Stops the loading process for the current active view. */
242 void stopLoading();
243
244 /** Switches between showing a preview of the file content and showing the icon. */
245 void togglePreview();
246
247 /**
248 * Switches between showing and hiding of hidden marked files dependent
249 * from the current state of the 'Show Hidden Files' menu toggle action.
250 */
251 void toggleShowHiddenFiles();
252
253 /**
254 * Switches between showing and hiding of the filter bar dependent
255 * from the current state of the 'Show Filter Bar' menu toggle action.
256 */
257 void showFilterBar();
258
259 /** Increases the size of the current set view mode. */
260 void zoomIn();
261
262 /** Decreases the size of the current set view mode. */
263 void zoomOut();
264
265 /**
266 * Toggles between edit and brose mode of the navigation bar.
267 */
268 void toggleEditLocation();
269
270 /**
271 * Switches to the edit mode of the navigation bar. If the edit mode is
272 * already active, it is assured that the navigation bar get focused.
273 */
274 void editLocation();
275
276 /**
277 * Opens the view properties dialog, which allows to modify the properties
278 * of the currently active view.
279 */
280 void adjustViewProperties();
281
282 /** Goes back on step of the Url history. */
283 void goBack();
284
285 /** Goes forward one step of the Url history. */
286 void goForward();
287
288 /** Goes up one hierarchy of the current Url. */
289 void goUp();
290
291 /** Goes to the home Url. */
292 void goHome();
293
294 /** Opens a terminal for the current shown directory. */
295 void openTerminal();
296
297 /** Opens KFind for the current shown directory. */
298 void findFile();
299
300 /** Opens Kompare for 2 selected files. */
301 void compareFiles();
302
303 /** Opens the settings dialog for Dolphin. */
304 void editSettings();
305
306 /**
307 * Adds the undo operation given by \a job
308 * to the UndoManager.
309 */
310 void addUndoOperation(KJob* job);
311
312 /** Updates the state of all 'View' menu actions. */
313 void slotViewModeChanged();
314
315 /** Updates the state of the 'Show hidden files' menu action. */
316 void slotShowHiddenFilesChanged();
317
318 /** Updates the state of the 'Sort by' actions. */
319 void slotSortingChanged(DolphinView::Sorting sorting);
320
321 /** Updates the state of the 'Sort Ascending/Descending' action. */
322 void slotSortOrderChanged(Qt::SortOrder order);
323
324 /** Updates the state of the 'Edit' menu actions. */
325 void slotSelectionChanged();
326
327 /**
328 * Updates the state of the 'Back' and 'Forward' menu
329 * actions corresponding the the current history.
330 */
331 void slotHistoryChanged();
332
333 /**
334 * Updates the caption of the main window and the state
335 * of all menu actions which depend from a changed Url.
336 */
337 void slotUrlChanged(const KUrl& url);
338
339 /** Updates the state of the 'Show filter bar' menu action. */
340 void updateFilterBarAction(bool show);
341
342 /** Executes the redo operation (see UndoManager::Redo ()). */
343 void redo();
344
345 /** Executes the undo operation (see UndoManager::Undo()). */
346 void undo();
347
348 /** Open a new main window. */
349 void openNewMainWindow();
350
351 /**
352 * Moves the items indicated by m_droppedUrls to the URL
353 * m_destination.
354 */
355 void moveDroppedItems();
356
357 /**
358 * Copies the items indicated by m_droppedUrls to the URL
359 * m_destination.
360 */
361 void copyDroppedItems();
362
363 /**
364 * Links the items indicated by m_droppedUrls to the URL
365 * m_destination.
366 */
367 void linkDroppedItems();
368
369 private:
370 DolphinMainWindow();
371 void init();
372 void loadSettings();
373
374 void setupAccel();
375 void setupActions();
376 void setupDockWidgets();
377 void setupCreateNewMenuActions();
378 void updateHistory();
379 void updateEditActions();
380 void updateViewActions();
381 void updateGoActions();
382 void copyUrls(const KUrl::List& source, const KUrl& dest);
383 void moveUrls(const KUrl::List& source, const KUrl& dest);
384 void addPendingUndoJob(KIO::Job* job,
385 DolphinCommand::Type commandType,
386 const KUrl::List& source,
387 const KUrl& dest);
388 void clearStatusBar();
389
390 /**
391 * Connects the signals from the created DolphinView with
392 * the index \a viewIndex with the corresponding slots of
393 * the DolphinMainWindow. This method must be invoked each
394 * time a DolphinView has been created.
395 */
396 void connectViewSignals(int viewIndex);
397
398 private:
399 QSplitter* m_splitter;
400 DolphinView* m_activeView;
401
402 KUrl m_dropDestination;
403 KUrl::List m_droppedUrls;
404
405 /**
406 * DolphinMainWindowsupports only one or two views, which
407 * are handled internally as primary and secondary view.
408 */
409 enum ViewIndex
410 {
411 PrimaryIdx = 0,
412 SecondaryIdx = 1
413 };
414 DolphinView* m_view[SecondaryIdx + 1];
415
416 /**
417 * Asynchronous operations like 'Move' and 'Copy' may only be added as undo
418 * operation after they have been finished successfully. When an asynchronous
419 * operation is started, it is added to a pending undo jobs list in the meantime.
420 * As soon as the job has been finished, the operation is added to the undo mangager.
421 * @see UndoManager
422 * @see DolphinMainWindow::addPendingUndoJob
423 * @see DolphinMainWindow::addUndoOperation
424 */
425 struct UndoInfo
426 {
427 int id;
428 DolphinCommand command;
429 };
430 Q3ValueList<UndoInfo> m_pendingUndoJobs;
431
432 /** Contains meta information for creating files. */
433 struct CreateFileEntry
434 {
435 QString name;
436 QString filePath;
437 QString templatePath;
438 QString icon;
439 QString comment;
440 };
441
442 QLinkedList<QAction*> m_fileGroupActions;
443 KSortableList<CreateFileEntry,QString> m_createFileTemplates;
444 };
445
446 #endif // _DOLPHIN_H_
447