]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinview.h
Port to new KAction, KActionCollection API.
[dolphin.git] / src / dolphinview.h
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
3 * Copyright (C) 2006 by Gregor Kališnik <gregor@podnapisi.net> *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
20
21
22 #ifndef _DOLPHINVIEW_H_
23 #define _DOLPHINVIEW_H_
24
25 #include <qwidget.h>
26 //Added by qt3to4:
27 #include <QDropEvent>
28 #include <Q3ValueList>
29 #include <QMouseEvent>
30 #include <QVBoxLayout>
31 #include <kparts/part.h>
32 #include <kfileitem.h>
33 #include <kfileiconview.h>
34 #include <kio/job.h>
35 #include <urlnavigator.h>
36
37 #include <QListView>
38
39 class QPainter;
40 class KUrl;
41 class KDirModel;
42 class QLineEdit;
43 class UrlNavigator;
44 class QTimer;
45 class Q3IconViewItem;
46 class Q3ListViewItem;
47 class Q3VBoxLayout;
48 class DolphinMainWindow;
49 class DolphinDirLister;
50 class DolphinStatusBar;
51 class DolphinIconsView;
52 class DolphinDetailsView;
53 class DolphinSortFilterProxyModel;
54 class ViewProperties;
55 class KProgress;
56 class KDirModel;
57 class FilterBar;
58
59 class QModelIndex;
60
61 /**
62 * @short Represents a view for the directory content
63 * including the navigation bar and status bar.
64 *
65 * View modes for icons, details and previews are supported. Currently
66 * Dolphin allows to have up to two views inside the main window.
67 *
68 * @see DolphinIconsView
69 * @see DolphinDetailsView
70 * @see UrlNavigator
71 * @see DolphinStatusBar
72 *
73 * @author Peter Penz <peter.penz@gmx.at>
74 */
75 class DolphinView : public QWidget
76 {
77 Q_OBJECT
78
79 public:
80 /**
81 * Defines the view mode for a directory. The view mode
82 * can be defined when constructing a DolphinView. The
83 * view mode is automatically updated if the directory itself
84 * defines a view mode (see class ViewProperties for details).
85 */
86 enum Mode
87 {
88 /**
89 * The directory items are shown as icons including an
90 * icon name. */
91 IconsView = 0,
92
93 /**
94 * The icon, the name and at least the size of the directory
95 * items are shown in a table. It is possible to add columns
96 * for date, group and permissions.
97 */
98 DetailsView = 1,
99 MaxModeEnum = DetailsView
100 };
101
102 /** Defines the sort order for the items of a directory. */
103 enum Sorting
104 {
105 SortByName = 0,
106 SortBySize = 1,
107 SortByDate = 2,
108 MaxSortEnum = SortByDate
109 };
110
111 DolphinView(DolphinMainWindow* mainwindow,
112 QWidget *parent,
113 const KUrl& url,
114 Mode mode = IconsView,
115 bool showHiddenFiles = false);
116
117 virtual ~DolphinView();
118
119 /**
120 * Sets the current active Url.
121 * The signals UrlNavigator::urlChanged and UrlNavigator::historyChanged
122 * are submitted.
123 */
124 void setUrl(const KUrl& url);
125
126 /** Returns the current active Url. */
127 const KUrl& url() const;
128
129 void requestActivation();
130 bool isActive() const;
131
132 /**
133 * Changes the view mode for the current directory to \a mode.
134 * If the view properties should be remembered for each directory
135 * (GeneralSettings::globalViewProps() returns false), then the
136 * changed view mode will be be stored automatically.
137 */
138 void setMode(Mode mode);
139 Mode mode() const;
140
141 /**
142 * Turns on the file preview for the all files of the current directory,
143 * if \a show is true.
144 * If the view properties should be remembered for each directory
145 * (GeneralSettings::globalViewProps() returns false), then the
146 * preview setting will be be stored automatically.
147 */
148 void setShowPreview(bool show);
149 bool showPreview() const;
150
151 /**
152 * Shows all hidden files of the current directory,
153 * if \a show is true.
154 * If the view properties should be remembered for each directory
155 * (GeneralSettings::globalViewProps() returns false), then the
156 * show hidden file setting will be be stored automatically.
157 */
158 void setShowHiddenFiles(bool show);
159 bool showHiddenFiles() const;
160
161 /**
162 * Triggers the renaming of the currently selected items, where
163 * the user must input a new name for the items.
164 */
165 void renameSelectedItems();
166
167 /**
168 * Selects all items.
169 * @see DolphinView::selectedItems()
170 */
171 void selectAll();
172
173 /**
174 * Inverts the current selection: selected items get unselected,
175 * unselected items get selected.
176 * @see DolphinView::selectedItems()
177 */
178 void invertSelection();
179
180 /**
181 * Goes back one step in the Url history. The signals
182 * UrlNavigator::urlChanged and UrlNavigator::historyChanged
183 * are submitted.
184 */
185 void goBack();
186
187 /**
188 * Goes forward one step in the Url history. The signals
189 * UrlNavigator::urlChanged and UrlNavigator::historyChanged
190 * are submitted.
191 */
192 void goForward();
193
194 /**
195 * Goes up one step of the Url path. The signals
196 * UrlNavigator::urlChanged and UrlNavigator::historyChanged
197 * are submitted.
198 */
199 void goUp();
200
201 /**
202 * Goes to the home Url. The signals UrlNavigator::urlChanged
203 * and UrlNavigator::historyChanged are submitted.
204 */
205 void goHome();
206
207 /**
208 * Sets the Url of the navigation bar to an editable state
209 * if \a editable is true. If \a editable is false, each part of
210 * the location is presented by a button for a fast navigation.
211 */
212 void setUrlEditable(bool editable);
213
214 /**
215 * Returns the complete Url history. The index 0 indicates the oldest
216 * history element.
217 * @param index Output parameter which indicates the current
218 * index of the location.
219 */
220 const Q3ValueList<UrlNavigator::HistoryElem> urlHistory(int& index) const;
221
222 /**
223 * Returns true, if at least one item is selected.
224 */
225 bool hasSelection() const;
226
227 /**
228 * Returns the selected items. The list is empty if no item has been
229 * selected.
230 * @see DolphinView::selectedUrls()
231 */
232 KFileItemList selectedItems() const;
233
234 /**
235 * Returns a list of Urls for all selected items. An empty list
236 * is returned, if no item is selected.
237 * @see DolphinView::selectedItems()
238 */
239 KUrl::List selectedUrls() const;
240
241 /**
242 * Returns the current item, where the cursor is. 0 is returned, if there is no
243 * current item (e. g. if the view is empty). Note that the current item must
244 * not be a selected item.
245 * @see DolphinView::selectedItems()
246 */
247 const KFileItem* currentFileItem() const;
248
249 /**
250 * Opens the context menu for the item indicated by \a fileInfo
251 * on the position \a pos. If 0 is passed for the file info, a context
252 * menu for the viewport is opened.
253 */
254 void openContextMenu(KFileItem* fileInfo, const QPoint& pos);
255
256 /**
257 * Renames the filename of the source Url by the new file name.
258 * If the new file name already exists, a dialog is opened which
259 * asks the user to enter a new name.
260 */
261 void rename(const KUrl& source, const QString& newName);
262
263 /** Returns the status bar of the view. */
264 DolphinStatusBar* statusBar() const;
265
266 /**
267 * Returns the x-position of the view content.
268 * The content of the view might be larger than the visible area
269 * and hence a scrolling must be done.
270 */
271 int contentsX() const;
272
273 /**
274 * Returns the y-position of the view content.
275 * The content of the view might be larger than the visible area
276 * and hence a scrolling must be done.
277 */
278 int contentsY() const;
279
280 /**
281 * Returns true, if the Url shown by the navigation bar is editable.
282 * @see UrlNavigator
283 */
284 bool isUrlEditable() const;
285
286 /** Increases the size of the current set view mode. */
287 void zoomIn();
288
289 /** Decreases the size of the current set view mode. */
290 void zoomOut();
291
292 /**
293 * Returns true, if zooming in is possible. If false is returned,
294 * the minimal zoom size is possible.
295 */
296 bool isZoomInPossible() const;
297
298 /**
299 * Returns true, if zooming out is possible. If false is returned,
300 * the maximum zoom size is possible.
301 */
302 bool isZoomOutPossible() const;
303
304 /** Sets the sort order of the items inside a directory (see DolphinView::Sorting). */
305 void setSorting(Sorting sorting);
306
307 /** Returns the sort order of the items inside a directory (see DolphinView::Sorting). */
308 Sorting sorting() const;
309
310 /** Sets the sort order (Qt::Ascending or Qt::Descending) for the items. */
311 void setSortOrder(Qt::SortOrder order);
312
313 /** Returns the current used sort order (Qt::Ascending or Qt::Descending). */
314 Qt::SortOrder sortOrder() const;
315
316 /** Refreshs the view settings by reading out the stored settings. */
317 void refreshSettings();
318
319 /**
320 * Updates the number of items (= number of files + number of
321 * directories) in the statusbar. If files are selected, the number
322 * of selected files and the sum of the filesize is shown.
323 */
324 void updateStatusBar();
325
326 /** Returns the UrlNavigator of the view for read access. */
327 const UrlNavigator* urlNavigator() const { return m_urlNavigator; }
328
329 /**
330 * Triggers to request user information for the item given
331 * by the Url \a url. The signal requestItemInfo is emitted,
332 * which provides a way for widgets to get an indication to update
333 * the item information.
334 */
335 void emitRequestItemInfo(const KUrl& url);
336
337 /** Returns true, if the filter bar is visible. */
338 bool isFilterBarVisible() const;
339
340 /**
341 * Return the DolphinMainWindow this View belongs to. It is guranteed
342 * that we have one.
343 */
344 DolphinMainWindow* mainWindow() const ;
345
346 public slots:
347 void reload();
348 void slotUrlListDropped(QDropEvent* event,
349 const KUrl::List& urls,
350 const KUrl& url);
351
352 /**
353 * Slot that popups the filter bar like FireFox popups his Search bar.
354 */
355 void slotShowFilterBar(bool show);
356
357 /**
358 * Declare this View as the activeview of the mainWindow()
359 */
360 void declareViewActive();
361
362 signals:
363 /** Is emitted if Url of the view has been changed to \a url. */
364 void urlChanged(const KUrl& url);
365
366 /**
367 * Is emitted if the view mode (IconsView, DetailsView,
368 * PreviewsView) has been changed.
369 */
370 void modeChanged();
371
372 /** Is emitted if the 'show preview' property has been changed. */
373 void showPreviewChanged();
374
375 /** Is emitted if the 'show hidden files' property has been changed. */
376 void showHiddenFilesChanged();
377
378 /** Is emitted if the sorting by name, size or date has been changed. */
379 void sortingChanged(DolphinView::Sorting sorting);
380
381 /** Is emitted if the sort order (ascending or descending) has been changed. */
382 void sortOrderChanged(Qt::SortOrder order);
383
384 /**
385 * Is emitted if information of an item is requested to be shown e. g. in the sidebar.
386 * It the Url is empty, no item information request is pending.
387 */
388 void requestItemInfo(const KUrl& url);
389
390 /** Is emitted if the contents has been moved to \a x, \a y. */
391 void contentsMoved(int x, int y);
392
393 /**
394 * Is emitted whenever the selection has been changed. The current selection can
395 * be retrieved by mainWindow()->activeView()->selectedItems() or by
396 * mainWindow()->activeView()->selectedUrls().
397 */
398 void selectionChanged();
399
400 /**
401 * Is emitted whenever the filter bar has been turned show or hidden.
402 */
403 void showFilterBarChanged(bool shown);
404
405 protected:
406 /** @see QWidget::mouseReleaseEvent */
407 virtual void mouseReleaseEvent(QMouseEvent* event);
408
409 private slots:
410 void loadDirectory(const KUrl& kurl);
411 void triggerItem(const QModelIndex& index);
412
413 void slotPercent(int percent);
414 void slotClear();
415 void slotDeleteItem(KFileItem* item);
416 void slotCompleted();
417 void slotInfoMessage(const QString& msg);
418 void slotErrorMessage(const QString& msg);
419 void slotGrabActivation();
420 void emitSelectionChangedSignal();
421 void closeFilterBar();
422
423 /**
424 * Is invoked shortly before the contents of a view implementation
425 * has been moved and emits the signal contentsMoved. Note that no
426 * signal is emitted when the contents moving is only temporary by
427 * e. g. reloading a directory.
428 */
429 void slotContentsMoving(int x, int y);
430
431 /**
432 * Filters the currently shown items by \a nameFilter. All items
433 * which contain the given filter string will be shown.
434 */
435 void slotChangeNameFilter(const QString& nameFilter);
436
437 private:
438 void startDirLister(const KUrl& url, bool reload = false);
439
440 /**
441 * Returns the default text of the status bar, if no item is
442 * selected.
443 */
444 QString defaultStatusBarText() const;
445
446 /**
447 * Returns the text for the status bar, if at least one item
448 * is selected.
449 */
450 QString selectionStatusBarText() const;
451
452 /**
453 * Returns the string representation for the index \a index
454 * for renaming \itemCount items.
455 */
456 QString renameIndexPresentation(int index, int itemCount) const;
457
458 /**
459 * Applies the current view mode m_mode to the
460 * view implementation.
461 */
462 void applyModeToView();
463
464 /**
465 * Returns the column index used in the KDirModel depending on \a sorting.
466 */
467 int columnIndex(Sorting sorting) const;
468
469 /**
470 * Selects all items by using the selection flags \a flags. This is a helper
471 * method for the slots DolphinView::selectAll() and DolphinView::invertSelection().
472 */
473 void selectAll(QItemSelectionModel::SelectionFlags flags);
474
475 private:
476 bool m_refreshing;
477 bool m_showProgress;
478 Mode m_mode;
479
480 int m_iconSize;
481 int m_folderCount;
482 int m_fileCount;
483
484 DolphinMainWindow* m_mainWindow;
485 QVBoxLayout* m_topLayout;
486 UrlNavigator* m_urlNavigator;
487 DolphinIconsView* m_iconsView;
488 FilterBar *m_filterBar;
489 DolphinStatusBar* m_statusBar;
490
491 KDirModel* m_dirModel;
492 DolphinDirLister* m_dirLister;
493 DolphinSortFilterProxyModel* m_proxyModel;
494
495 };
496
497 #endif // _DOLPHINVIEW_H_