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