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