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