]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.h
SVN_SILENT unused (showed up in lxr)
[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 #include "dolphinview.h"
26
27 #include <kmainwindow.h>
28 #include <ksortablelist.h>
29 #include <konq_undo.h>
30
31 #include <QList>
32
33 class KNewMenu;
34 class KPrinter;
35 class KUrl;
36 class QLineEdit;
37 class KHBox;
38 class Q3IconViewItem;
39 class QSplitter;
40 class KAction;
41 class UrlNavigator;
42 class DolphinApplication;
43
44 /**
45 * @short Main window for Dolphin.
46 *
47 * Handles the menus, toolbars and Dolphin views.
48 */
49 class DolphinMainWindow: public KMainWindow
50 {
51 Q_OBJECT
52 Q_CLASSINFO("D-Bus Interface", "org.kde.dolphin.MainWindow")
53 Q_PROPERTY(int id READ getId SCRIPTABLE true)
54 friend class DolphinApplication;
55
56 public:
57 virtual ~DolphinMainWindow();
58
59 /**
60 * Activates the given view, which means that
61 * all menu actions are applied to this view. When
62 * having a split view setup the nonactive view
63 * is usually shown in darker colors.
64 */
65 void setActiveView(DolphinView* view);
66
67 /**
68 * Returns the currently active view. See
69 * DolphinMainWindow::setActiveView() for more details.
70 */
71 DolphinView* activeView() const { return m_activeView; }
72
73 /**
74 * Handles the dropping of URLs to the given
75 * destination. A context menu with the options
76 * 'Move Here', 'Copy Here', 'Link Here' and
77 * 'Cancel' is offered to the user.
78 * @param urls List of URLs which have been
79 * dropped.
80 * @param destination Destination URL, where the
81 * list or URLs should be moved,
82 * copied or linked to.
83 */
84 void dropUrls(const KUrl::List& urls,
85 const KUrl& destination);
86
87 /** Renames the item represented by \a oldUrl to \a newUrl. */
88 void rename(const KUrl& oldUrl, const KUrl& newUrl);
89
90 /**
91 * Refreshs the views of the main window by recreating them dependent from
92 * the given Dolphin settings.
93 */
94 void refreshViews();
95
96 /**
97 * Returns the 'Create New...' sub menu which also can be shared
98 * with other menus (e. g. a context menu).
99 */
100 KNewMenu* newMenu() const { return m_newMenu; }
101
102 public slots:
103 /**
104 * Returns the main windows ID, mainly used throught DBus.
105 */
106 int getId() const { return m_id; }
107
108 /**
109 * Changes the URL of the current active DolphinView to \a url.
110 */
111 void changeUrl(const QString& url);
112
113 /** Stores all settings and quits Dolphin. */
114 void quit();
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 protected:
130 /** @see QMainWindow::closeEvent */
131 virtual void closeEvent(QCloseEvent* event);
132
133 /**
134 * This method is called when it is time for the app to save its
135 * properties for session management purposes.
136 */
137 void saveProperties(KConfig*);
138
139 /**
140 * This method is called when this app is restored. The KConfig
141 * object points to the session management config file that was saved
142 * with @ref saveProperties
143 */
144 void readProperties(KConfig*);
145
146 private slots:
147 /** Updates the 'Create New...' sub menu. */
148 void updateNewMenu();
149
150 /**
151 * Let the user input a name for the selected item(s) and trigger
152 * a renaming afterwards.
153 */
154 void rename();
155
156 /** Moves the selected items of the active view to the trash. */
157 void moveToTrash();
158
159 /** Deletes the selected items of the active view. */
160 void deleteItems();
161
162 /**
163 * Opens the properties window for the selected items of the
164 * active view. The properties windows shows informations
165 * like name, size and permissions.
166 */
167 void properties();
168
169 /**
170 * Shows the error information of the job \a job
171 * in the status bar.
172 */
173 void slotHandleJobError(KJob* job);
174
175 /**
176 * Indicates in the status bar that the delete operation
177 * of the job \a job has been finished.
178 */
179 void slotDeleteFileFinished(KJob* job);
180
181 /**
182 * Updates the state of the 'Undo' menu action dependent
183 * from the parameter \a available.
184 */
185 void slotUndoAvailable(bool available);
186
187 /** Sets the text of the 'Undo' menu action to \a text. */
188 void slotUndoTextChanged(const QString& text);
189
190 /** Performs the current undo operation. */
191 void undo();
192
193 /**
194 * Copies all selected items to the clipboard and marks
195 * the items as cutted.
196 */
197 void cut();
198
199 /** Copies all selected items to the clipboard. */
200 void copy();
201
202 /** Pastes the clipboard data to the active view. */
203 void paste();
204
205 /**
206 * Updates the text of the paste action dependent from
207 * the number of items which are in the clipboard.
208 */
209 void updatePasteAction();
210
211 /** Selects all items from the active view. */
212 void selectAll();
213
214 /**
215 * Inverts the selection of all items of the active view:
216 * Selected items get nonselected and nonselected items get
217 * selected.
218 */
219 void invertSelection();
220
221 /** The current active view is switched to the icons mode. */
222 void setIconsView();
223
224 /** The current active view is switched to the details mode. */
225 void setDetailsView();
226
227 /** The sorting of the current view should be done by the name. */
228 void sortByName();
229
230 /** The sorting of the current view should be done by the size. */
231 void sortBySize();
232
233 /** The sorting of the current view should be done by the date. */
234 void sortByDate();
235
236 /** The sorting of the current view should be done by the permissions. */
237 void sortByPermissions();
238
239 /** The sorting of the current view should be done by the owner. */
240 void sortByOwner();
241
242 /** The sorting of the current view should be done by the group. */
243 void sortByGroup();
244
245 /** Switches between an ascending and descending sorting order. */
246 void toggleSortOrder();
247
248 /**
249 * Clears any additional information for an item except for the
250 * name and the icon.
251 */
252 void clearInfo();
253
254 /** Shows the MIME type as additional information for the item. */
255 void showMimeInfo();
256
257 /** Shows the size as additional information for the item. */
258 void showSizeInfo();
259
260 /** Shows the date as additional information for the item. */
261 void showDateInfo();
262
263 /**
264 * Switches between one and two views:
265 * If one view is visible, it will get split into two views.
266 * If already two views are visible, the nonactivated view gets closed.
267 */
268 void toggleSplitView();
269
270 /** Reloads the current active view. */
271 void reloadView();
272
273 /** Stops the loading process for the current active view. */
274 void stopLoading();
275
276 /** Switches between showing a preview of the file content and showing the icon. */
277 void togglePreview();
278
279 /**
280 * Switches between showing and hiding of hidden marked files dependent
281 * from the current state of the 'Show Hidden Files' menu toggle action.
282 */
283 void toggleShowHiddenFiles();
284
285 /**
286 * Switches between showing and hiding of the filter bar dependent
287 * from the current state of the 'Show Filter Bar' menu toggle action.
288 */
289 void showFilterBar();
290
291 /** Increases the size of the current set view mode. */
292 void zoomIn();
293
294 /** Decreases the size of the current set view mode. */
295 void zoomOut();
296
297 /**
298 * Toggles between edit and brose mode of the navigation bar.
299 */
300 void toggleEditLocation();
301
302 /**
303 * Switches to the edit mode of the navigation bar. If the edit mode is
304 * already active, it is assured that the navigation bar get focused.
305 */
306 void editLocation();
307
308 /**
309 * Opens the view properties dialog, which allows to modify the properties
310 * of the currently active view.
311 */
312 void adjustViewProperties();
313
314 /** Goes back on step of the URL history. */
315 void goBack();
316
317 /** Goes forward one step of the URL history. */
318 void goForward();
319
320 /** Goes up one hierarchy of the current URL. */
321 void goUp();
322
323 /** Goes to the home URL. */
324 void goHome();
325
326 /** Opens a terminal for the current shown directory. */
327 void openTerminal();
328
329 /** Opens KFind for the current shown directory. */
330 void findFile();
331
332 /** Opens Kompare for 2 selected files. */
333 void compareFiles();
334
335 /** Opens the settings dialog for Dolphin. */
336 void editSettings();
337
338 /** Updates the state of all 'View' menu actions. */
339 void slotViewModeChanged();
340
341 /** Updates the state of the 'Show preview' menu action. */
342 void slotShowPreviewChanged();
343
344 /** Updates the state of the 'Show hidden files' menu action. */
345 void slotShowHiddenFilesChanged();
346
347 /** Updates the state of the 'Sort by' actions. */
348 void slotSortingChanged(DolphinView::Sorting sorting);
349
350 /** Updates the state of the 'Sort Ascending/Descending' action. */
351 void slotSortOrderChanged(Qt::SortOrder order);
352
353 /** Updates the state of the 'Additional Information' actions. */
354 void slotAdditionalInfoChanged(KFileItemDelegate::AdditionalInformation info);
355
356 /** Updates the state of the 'Edit' menu actions. */
357 void slotSelectionChanged();
358
359 /**
360 * Updates the state of the 'Back' and 'Forward' menu
361 * actions corresponding the the current history.
362 */
363 void slotHistoryChanged();
364
365 /**
366 * Updates the caption of the main window and the state
367 * of all menu actions which depend from a changed URL.
368 */
369 void slotUrlChanged(const KUrl& url);
370
371 /** Updates the state of the 'Show filter bar' menu action. */
372 void updateFilterBarAction(bool show);
373
374 /** Open a new main window. */
375 void openNewMainWindow();
376
377 private:
378 DolphinMainWindow(int id);
379 void init();
380 void loadSettings();
381
382 void setupAccel();
383 void setupActions();
384 void setupDockWidgets();
385 void updateHistory();
386 void updateEditActions();
387 void updateViewActions();
388 void updateGoActions();
389 void copyUrls(const KUrl::List& source, const KUrl& dest);
390 void moveUrls(const KUrl::List& source, const KUrl& dest);
391 void linkUrls(const KUrl::List& source, const KUrl& dest);
392 void clearStatusBar();
393
394 /**
395 * Connects the signals from the created DolphinView with
396 * the index \a viewIndex with the corresponding slots of
397 * the DolphinMainWindow. This method must be invoked each
398 * time a DolphinView has been created.
399 */
400 void connectViewSignals(int viewIndex);
401
402 private:
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
413 /**
414 * Implements a custom error handling for the undo manager. This
415 * assures that all errors are shown in the status bar of Dolphin
416 * instead as modal error dialog with an OK button.
417 */
418 class UndoUiInterface : public KonqUndoManager::UiInterface
419 {
420 public:
421 UndoUiInterface(DolphinMainWindow* mainWin);
422 virtual ~UndoUiInterface();
423 virtual void jobError(KIO::Job* job);
424
425 private:
426 DolphinMainWindow* m_mainWin;
427 };
428
429 KNewMenu* m_newMenu;
430 QSplitter* m_splitter;
431 DolphinView* m_activeView;
432 int m_id;
433
434 DolphinView* m_view[SecondaryIdx + 1];
435
436 /// remember pending undo operations until they are finished
437 QList<KonqUndoManager::CommandType> m_undoCommandTypes;
438 };
439
440 #endif // _DOLPHIN_H_
441