]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.h
Use KonqMimeData for the cut- and copy-operation instead of using bool property insid...
[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 #ifdef HAVE_CONFIG_H
26 #include <config.h>
27 #endif
28
29 #include <kapplication.h>
30 #include <kmainwindow.h>
31 #include <ksortablelist.h>
32 #include <kvbox.h>
33
34 #include <q3valuelist.h>
35 #include <q3ptrlist.h>
36
37 #include <QCloseEvent>
38 #include <QString>
39
40 #include "dolphinview.h"
41 #include "undomanager.h"
42
43 class KPrinter;
44 class KUrl;
45 class QLineEdit;
46 class KFileIconView;
47 class KHBox;
48 class Q3IconViewItem;
49 class QSplitter;
50 class KAction;
51 class UrlNavigator;
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 the list of actions which are part of the file group
98 * of the 'Create New...' sub menu. Usually the list contains actions
99 * for creating folders, text files, HTML files etc.
100 */
101 QLinkedList<QAction*> fileGroupActions() const { return m_fileGroupActions; }
102
103 /**
104 * Refreshs the views of the main window by recreating them dependent from
105 * the given Dolphin settings.
106 */
107 void refreshViews();
108
109 signals:
110 /**
111 * Is send if the active view has been changed in
112 * the split view mode.
113 */
114 void activeViewChanged();
115
116 /**
117 * Is send if the selection of the currently active view has
118 * been changed.
119 */
120 void selectionChanged();
121
122 protected:
123 /** @see QMainWindow::closeEvent */
124 virtual void closeEvent(QCloseEvent* event);
125
126 /**
127 * This method is called when it is time for the app to save its
128 * properties for session management purposes.
129 */
130 void saveProperties(KConfig*);
131
132 /**
133 * This method is called when this app is restored. The KConfig
134 * object points to the session management config file that was saved
135 * with @ref saveProperties
136 */
137 void readProperties(KConfig*);
138
139 private slots:
140 /** Opens an input dialog for creating a new folder. */
141 void createFolder();
142
143 /** Creates a file with the MIME type given by the sender. */
144 void createFile();
145
146 /** Renames the selected item of the active view. */
147 void rename();
148
149 /** Moves the selected items of the active view to the trash. */
150 void moveToTrash();
151
152 /** Deletes the selected items of the active view. */
153 void deleteItems();
154
155 /**
156 * Opens the properties window for the selected items of the
157 * active view. The properties windows shows informations
158 * like name, size and permissions.
159 */
160 void properties();
161
162 /** Stores all settings and quits Dolphin. */
163 void quit();
164
165 /**
166 * Shows the error information of the job \a job
167 * in the status bar.
168 */
169 void slotHandleJobError(KJob* job);
170
171 /**
172 * Indicates in the status bar that the delete operation
173 * of the job \a job has been finished.
174 */
175 void slotDeleteFileFinished(KJob* job);
176
177 /**
178 * Updates the state of the 'Undo' menu action dependent
179 * from the parameter \a available.
180 */
181 void slotUndoAvailable(bool available);
182
183 /** Sets the text of the 'Undo' menu action to \a text. */
184 void slotUndoTextChanged(const QString& text);
185
186 /**
187 * Updates the state of the 'Redo' menu action dependent
188 * from the parameter \a available.
189 */
190 void slotRedoAvailable(bool available);
191
192 /** Sets the text of the 'Redo' menu action to \a text. */
193 void slotRedoTextChanged(const QString& text);
194
195 /**
196 * Copies all selected items to the clipboard and marks
197 * the items as cutted.
198 */
199 void cut();
200
201 /** Copies all selected items to the clipboard. */
202 void copy();
203
204 /** Pastes the clipboard data to the active view. */
205 void paste();
206
207 /**
208 * Updates the text of the paste action dependent from
209 * the number of items which are in the clipboard.
210 */
211 void updatePasteAction();
212
213 /** Selects all items from the active view. */
214 void selectAll();
215
216 /**
217 * Inverts the selection of all items of the active view:
218 * Selected items get nonselected and nonselected items get
219 * selected.
220 */
221 void invertSelection();
222
223 /** The current active view is switched to the icons mode. */
224 void setIconsView();
225
226 /** The current active view is switched to the details mode. */
227 void setDetailsView();
228
229 /** The sorting of the current view should be done by the name. */
230 void sortByName();
231
232 /** The sorting of the current view should be done by the size. */
233 void sortBySize();
234
235 /** The sorting of the current view should be done by the date. */
236 void sortByDate();
237
238 /** Switches between an ascending and descending sorting order. */
239 void toggleSortOrder();
240
241 /**
242 * Switches between one and two views:
243 * If one view is visible, it will get split into two views.
244 * If already two views are visible, the nonactivated view gets closed.
245 */
246 void toggleSplitView();
247
248 /** Reloads the current active view. */
249 void reloadView();
250
251 /** Stops the loading process for the current active view. */
252 void stopLoading();
253
254 /** Switches between showing a preview of the file content and showing the icon. */
255 void togglePreview();
256
257 /**
258 * Switches between showing and hiding of hidden marked files dependent
259 * from the current state of the 'Show Hidden Files' menu toggle action.
260 */
261 void toggleShowHiddenFiles();
262
263 /**
264 * Switches between showing and hiding of the filter bar dependent
265 * from the current state of the 'Show Filter Bar' menu toggle action.
266 */
267 void showFilterBar();
268
269 /** Increases the size of the current set view mode. */
270 void zoomIn();
271
272 /** Decreases the size of the current set view mode. */
273 void zoomOut();
274
275 /**
276 * Toggles between edit and brose mode of the navigation bar.
277 */
278 void toggleEditLocation();
279
280 /**
281 * Switches to the edit mode of the navigation bar. If the edit mode is
282 * already active, it is assured that the navigation bar get focused.
283 */
284 void editLocation();
285
286 /**
287 * Opens the view properties dialog, which allows to modify the properties
288 * of the currently active view.
289 */
290 void adjustViewProperties();
291
292 /** Goes back on step of the Url history. */
293 void goBack();
294
295 /** Goes forward one step of the Url history. */
296 void goForward();
297
298 /** Goes up one hierarchy of the current Url. */
299 void goUp();
300
301 /** Goes to the home Url. */
302 void goHome();
303
304 /** Opens a terminal for the current shown directory. */
305 void openTerminal();
306
307 /** Opens KFind for the current shown directory. */
308 void findFile();
309
310 /** Opens Kompare for 2 selected files. */
311 void compareFiles();
312
313 /** Opens the settings dialog for Dolphin. */
314 void editSettings();
315
316 /**
317 * Adds the undo operation given by \a job
318 * to the UndoManager.
319 */
320 void addUndoOperation(KJob* job);
321
322 /** Updates the state of all 'View' menu actions. */
323 void slotViewModeChanged();
324
325 /** Updates the state of the 'Show hidden files' menu action. */
326 void slotShowHiddenFilesChanged();
327
328 /** Updates the state of the 'Sort by' actions. */
329 void slotSortingChanged(DolphinView::Sorting sorting);
330
331 /** Updates the state of the 'Sort Ascending/Descending' action. */
332 void slotSortOrderChanged(Qt::SortOrder order);
333
334 /** Updates the state of the 'Edit' menu actions. */
335 void slotSelectionChanged();
336
337 /**
338 * Updates the state of the 'Back' and 'Forward' menu
339 * actions corresponding the the current history.
340 */
341 void slotHistoryChanged();
342
343 /**
344 * Updates the caption of the main window and the state
345 * of all menu actions which depend from a changed Url.
346 */
347 void slotUrlChanged(const KUrl& url);
348
349 /** Updates the state of the 'Show filter bar' menu action. */
350 void updateFilterBarAction(bool show);
351
352 /** Executes the redo operation (see UndoManager::Redo ()). */
353 void redo();
354
355 /** Executes the undo operation (see UndoManager::Undo()). */
356 void undo();
357
358 /** Open a new main window. */
359 void openNewMainWindow();
360
361 private:
362 DolphinMainWindow();
363 void init();
364 void loadSettings();
365
366 void setupAccel();
367 void setupActions();
368 void setupDockWidgets();
369 void setupCreateNewMenuActions();
370 void updateHistory();
371 void updateEditActions();
372 void updateViewActions();
373 void updateGoActions();
374 void updateViewProperties(const KUrl::List& urls);
375 void copyUrls(const KUrl::List& source, const KUrl& dest);
376 void moveUrls(const KUrl::List& source, const KUrl& dest);
377 void addPendingUndoJob(KIO::Job* job,
378 DolphinCommand::Type commandType,
379 const KUrl::List& source,
380 const KUrl& dest);
381 void clearStatusBar();
382
383 /**
384 * Connects the signals from the created DolphinView with
385 * the index \a viewIndex with the corresponding slots of
386 * the DolphinMainWindow. This method must be invoked each
387 * time a DolphinView has been created.
388 */
389 void connectViewSignals(int viewIndex);
390
391 private:
392 QSplitter* m_splitter;
393 DolphinView* m_activeView;
394
395 /**
396 * DolphinMainWindowsupports only one or two views, which
397 * are handled internally as primary and secondary view.
398 */
399 enum ViewIndex
400 {
401 PrimaryIdx = 0,
402 SecondaryIdx = 1
403 };
404 DolphinView* m_view[SecondaryIdx + 1];
405
406 /**
407 * Asynchronous operations like 'Move' and 'Copy' may only be added as undo
408 * operation after they have been finished successfully. When an asynchronous
409 * operation is started, it is added to a pending undo jobs list in the meantime.
410 * As soon as the job has been finished, the operation is added to the undo mangager.
411 * @see UndoManager
412 * @see DolphinMainWindow::addPendingUndoJob
413 * @see DolphinMainWindow::addUndoOperation
414 */
415 struct UndoInfo
416 {
417 int id;
418 DolphinCommand command;
419 };
420 Q3ValueList<UndoInfo> m_pendingUndoJobs;
421
422 /** Contains meta information for creating files. */
423 struct CreateFileEntry
424 {
425 QString name;
426 QString filePath;
427 QString templatePath;
428 QString icon;
429 QString comment;
430 };
431
432 QLinkedList<QAction*> m_fileGroupActions;
433 KSortableList<CreateFileEntry,QString> m_createFileTemplates;
434 };
435
436 #endif // _DOLPHIN_H_
437