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