]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.h
Add a "New Window" option to Dolphin
[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 /** Open a new mainwindow */
173 void slotNewMainWindow();
174
175 protected:
176 /** @see QMainWindow::closeEvent */
177 virtual void closeEvent(QCloseEvent* event);
178
179 /**
180 * This method is called when it is time for the app to save its
181 * properties for session management purposes.
182 */
183 void saveProperties(KConfig*);
184
185 /**
186 * This method is called when this app is restored. The KConfig
187 * object points to the session management config file that was saved
188 * with @ref saveProperties
189 */
190 void readProperties(KConfig*);
191
192 private slots:
193 /** Opens an input dialog for creating a new folder. */
194 void createFolder();
195
196 /** Creates a file with the MIME type given by the sender. */
197 void createFile();
198
199 /** Renames the selected item of the active view. */
200 void rename();
201
202 /** Moves the selected items of the active view to the trash. */
203 void moveToTrash();
204
205 /** Deletes the selected items of the active view. */
206 void deleteItems();
207
208 /**
209 * Opens the properties window for the selected items of the
210 * active view. The properties windows shows informations
211 * like name, size and permissions.
212 */
213 void properties();
214
215 /** Stores all settings and quits Dolphin. */
216 void quit();
217
218 /**
219 * Shows the error information of the job \a job
220 * in the status bar.
221 */
222 void slotHandleJobError(KJob* job);
223
224 /**
225 * Indicates in the status bar that the delete operation
226 * of the job \a job has been finished.
227 */
228 void slotDeleteFileFinished(KJob* job);
229
230 /**
231 * Updates the state of the 'Undo' menu action dependent
232 * from the parameter \a available.
233 */
234 void slotUndoAvailable(bool available);
235
236 /** Sets the text of the 'Undo' menu action to \a text. */
237 void slotUndoTextChanged(const QString& text);
238
239 /**
240 * Updates the state of the 'Redo' menu action dependent
241 * from the parameter \a available.
242 */
243 void slotRedoAvailable(bool available);
244
245 /** Sets the text of the 'Redo' menu action to \a text. */
246 void slotRedoTextChanged(const QString& text);
247
248 /**
249 * Copies all selected items to the clipboard and marks
250 * the items as cutted.
251 */
252 void cut();
253
254 /** Copies all selected items to the clipboard. */
255 void copy();
256
257 /** Pastes the clipboard data to the active view. */
258 void paste();
259
260 /**
261 * Updates the text of the paste action dependent from
262 * the number of items which are in the clipboard.
263 */
264 void updatePasteAction();
265
266 /** Selects all items from the active view. */
267 void selectAll();
268
269 /**
270 * Inverts the selection of all items of the active view:
271 * Selected items get nonselected and nonselected items get
272 * selected.
273 */
274 void invertSelection();
275
276 /** The current active view is switched to the icons mode. */
277 void setIconsView();
278
279 /** The current active view is switched to the details mode. */
280 void setDetailsView();
281
282 /** The current active view is switched to the previews mode. */
283 void setPreviewsView();
284
285 /** The sorting of the current view should be done by the name. */
286 void sortByName();
287
288 /** The sorting of the current view should be done by the size. */
289 void sortBySize();
290
291 /** The sorting of the current view should be done by the date. */
292 void sortByDate();
293
294 /** Switches between an ascending and descending sorting order. */
295 void toggleSortOrder();
296
297 /**
298 * Switches between one and two views:
299 * If one view is visible, it will get split into two views.
300 * If already two views are visible, the nonactivated view gets closed.
301 */
302 void toggleSplitView();
303
304 /** Reloads the current active view. */
305 void reloadView();
306
307 /** Stops the loading process for the current active view. */
308 void stopLoading();
309
310 /**
311 * Switches between showing and hiding of hidden marked files dependent
312 * from the current state of the 'Show Hidden Files' menu toggle action.
313 */
314 void showHiddenFiles();
315
316 /**
317 * Switches between showing and hiding of the filter bar dependent
318 * from the current state of the 'Show Filter Bar' menu toggle action.
319 */
320 void showFilterBar();
321
322 /** Increases the size of the current set view mode. */
323 void zoomIn();
324
325 /** Decreases the size of the current set view mode. */
326 void zoomOut();
327
328 /**
329 * Toggles between edit and brose mode of the navigation bar.
330 */
331 void toggleEditLocation();
332
333 /**
334 * Switches to the edit mode of the navigation bar. If the edit mode is
335 * already active, it is assured that the navigation bar get focused.
336 */
337 void editLocation();
338
339 /**
340 * Opens the view properties dialog, which allows to modify the properties
341 * of the currently active view.
342 */
343 void adjustViewProperties();
344
345 /** Goes back on step of the Url history. */
346 void goBack();
347
348 /** Goes forward one step of the Url history. */
349 void goForward();
350
351 /** Goes up one hierarchy of the current Url. */
352 void goUp();
353
354 /** Goes to the home Url. */
355 void goHome();
356
357 /** Opens a terminal for the current shown directory. */
358 void openTerminal();
359
360 /** Opens KFind for the current shown directory. */
361 void findFile();
362
363 /** Opens Kompare for 2 selected files. */
364 void compareFiles();
365
366 /** Opens the settings dialog for Dolphin. */
367 void editSettings();
368
369 /**
370 * Adds the undo operation given by \a job
371 * to the UndoManager.
372 */
373 void addUndoOperation(KJob* job);
374
375
376 void toggleSidebar();
377
378 /**
379 * Stores the current sidebar width and closes
380 * the sidebar.
381 */
382 void closeSidebar();
383
384 private:
385 DolphinMainWindow();
386 void init();
387 void loadSettings();
388
389 void setupAccel();
390 void setupActions();
391 void setupCreateNewMenuActions();
392 void updateHistory();
393 void updateEditActions();
394 void updateViewActions();
395 void updateGoActions();
396 void updateViewProperties(const KUrl::List& urls);
397 void copyUrls(const KUrl::List& source, const KUrl& dest);
398 void moveUrls(const KUrl::List& source, const KUrl& dest);
399 void addPendingUndoJob(KIO::Job* job,
400 DolphinCommand::Type commandType,
401 const KUrl::List& source,
402 const KUrl& dest);
403 void clearStatusBar();
404 void openSidebar();
405
406 QSplitter* m_splitter;
407 Sidebar* m_sidebar;
408 DolphinView* m_activeView;
409
410 /**
411 * DolphinMainWindowsupports only one or two views, which
412 * are handled internally as primary and secondary view.
413 */
414 enum ViewIndex
415 {
416 PrimaryIdx = 0,
417 SecondaryIdx = 1
418 };
419 DolphinView* m_view[SecondaryIdx + 1];
420
421 /// If set to true, the clipboard contains data which should be cutted after pasting.
422 bool m_clipboardContainsCutData;
423
424 /**
425 * Asynchronous operations like 'Move' and 'Copy' may only be added as undo
426 * operation after they have been finished successfully. When an asynchronous
427 * operation is started, it is added to a pending undo jobs list in the meantime.
428 * As soon as the job has been finished, the operation is added to the undo mangager.
429 * @see UndoManager
430 * @see DolphinMainWindow::addPendingUndoJob
431 * @see DolphinMainWindow::addUndoOperation
432 */
433 struct UndoInfo
434 {
435 int id;
436 DolphinCommand command;
437 };
438 Q3ValueList<UndoInfo> m_pendingUndoJobs;
439
440 /** Contains meta information for creating files. */
441 struct CreateFileEntry
442 {
443 QString name;
444 QString filePath;
445 QString templatePath;
446 QString icon;
447 QString comment;
448 };
449
450 Q3PtrList<KAction> m_fileGroupActions;
451 KSortableList<CreateFileEntry,QString> m_createFileTemplates;
452
453 // TODO: not used yet. See documentation of DolphinMainWindow::linkGroupActions()
454 // and DolphinMainWindow::linkToDeviceActions() in for details.
455 //QPtrList<KAction> m_linkGroupActions;
456 //QPtrList<KAction> m_linkToDeviceActions;
457 };
458
459 #endif // _DOLPHIN_H_
460