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