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