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