]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinview.h
don't lose the history of the URL navigator if the settings of the Icons View, Detail...
[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 <kparts/part.h>
26 #include <kfileitem.h>
27 #include <kfileitemdelegate.h>
28 #include <kio/job.h>
29
30 #include <kurlnavigator.h>
31
32 #include <QtGui/QKeyEvent>
33 #include <QtCore/QLinkedList>
34 #include <QtGui/QListView>
35 #include <QtGui/QBoxLayout>
36 #include <QtGui/QWidget>
37
38 class DolphinController;
39 class FilterBar;
40 class KFileItemDelegate;
41 class KUrl;
42 class KDirModel;
43 class KUrlNavigator;
44 class DolphinColumnView;
45 class DolphinDetailsView;
46 class DolphinDirLister;
47 class DolphinIconsView;
48 class DolphinMainWindow;
49 class DolphinSortFilterProxyModel;
50 class DolphinStatusBar;
51 class QModelIndex;
52 class QPainter;
53 class QTimer;
54 class ViewProperties;
55
56 /**
57 * @short Represents a view for the directory content
58 * including the navigation bar, filter bar and status bar.
59 *
60 * View modes for icons, details and columns are supported. Currently
61 * Dolphin allows to have up to two views inside the main window.
62 *
63 * @see DolphinIconsView
64 * @see DolphinDetailsView
65 * @see DolphinColumnView
66 * @see KUrlNavigator
67 * @see DolphinStatusBar
68 */
69 class DolphinView : public QWidget
70 {
71 Q_OBJECT
72
73 public:
74 /**
75 * Defines the view mode for a directory. The view mode
76 * can be defined when constructing a DolphinView. The
77 * view mode is automatically updated if the directory itself
78 * defines a view mode (see class ViewProperties for details).
79 */
80 enum Mode
81 {
82 /**
83 * The directory items are shown as icons including an
84 * icon name. */
85 IconsView = 0,
86
87 /**
88 * The icon, the name and at least the size of the directory
89 * items are shown in a table. It is possible to add columns
90 * for date, group and permissions.
91 */
92 DetailsView = 1,
93
94 /**
95 * Each folder is shown in a separate column.
96 */
97 ColumnView = 2,
98 MaxModeEnum = ColumnView
99 };
100
101 /** Defines the sort order for the items of a directory. */
102 enum Sorting
103 {
104 SortByName = 0,
105 SortBySize,
106 SortByDate,
107 SortByPermissions,
108 SortByOwner,
109 SortByGroup,
110 SortByType,
111 MaxSortEnum = SortByType
112 };
113
114 DolphinView(DolphinMainWindow* mainwindow,
115 QWidget *parent,
116 const KUrl& url,
117 Mode mode = IconsView,
118 bool showHiddenFiles = false);
119
120 virtual ~DolphinView();
121
122 /**
123 * Sets the current active URL.
124 * The signals KUrlNavigator::urlChanged() and KUrlNavigator::historyChanged()
125 * are emitted.
126 */
127 void setUrl(const KUrl& url);
128
129 /** Returns the current active URL. */
130 const KUrl& url() const;
131
132 /**
133 * Returns true if the view is active and hence all actions are
134 * applied to this view.
135 */
136 bool isActive() const;
137
138 /**
139 * Changes the view mode for the current directory to \a mode.
140 * If the view properties should be remembered for each directory
141 * (GeneralSettings::globalViewProps() returns false), then the
142 * changed view mode will be be stored automatically.
143 */
144 void setMode(Mode mode);
145 Mode mode() const;
146
147 /**
148 * Turns on the file preview for the all files of the current directory,
149 * if \a show is true.
150 * If the view properties should be remembered for each directory
151 * (GeneralSettings::globalViewProps() returns false), then the
152 * preview setting will be be stored automatically.
153 */
154 void setShowPreview(bool show);
155 bool showPreview() const;
156
157 /**
158 * Shows all hidden files of the current directory,
159 * if \a show is true.
160 * If the view properties should be remembered for each directory
161 * (GeneralSettings::globalViewProps() returns false), then the
162 * show hidden file setting will be be stored automatically.
163 */
164 void setShowHiddenFiles(bool show);
165 bool showHiddenFiles() const;
166
167 /**
168 * Summarizes all sorted items by their category \a categorized
169 * is true.
170 * If the view properties should be remembered for each directory
171 * (GeneralSettings::globalViewProps() returns false), then the
172 * categorized sorting setting will be be stored automatically.
173 */
174 void setCategorizedSorting(bool categorized);
175 bool categorizedSorting() const;
176
177 /**
178 * Returns true, if the categorized sorting is supported by the current
179 * used mode (see DolphinView::setMode()). Currently only DolphinView::IconsView
180 * supports categorizations. To check whether the categorized
181 * sorting is set, use DolphinView::categorizedSorting().
182 */
183 bool supportsCategorizedSorting() const;
184
185 /**
186 * Triggers the renaming of the currently selected items, where
187 * the user must input a new name for the items.
188 */
189 void renameSelectedItems();
190
191 /**
192 * Selects all items.
193 * @see DolphinView::selectedItems()
194 */
195 void selectAll();
196
197 /**
198 * Inverts the current selection: selected items get unselected,
199 * unselected items get selected.
200 * @see DolphinView::selectedItems()
201 */
202 void invertSelection();
203
204 /**
205 * Goes back one step in the URL history. The signals
206 * KUrlNavigator::urlChanged() and KUrlNavigator::historyChanged()
207 * are submitted.
208 */
209 void goBack();
210
211 /**
212 * Goes forward one step in the Url history. The signals
213 * KUrlNavigator::urlChanged() and KUrlNavigator::historyChanged()
214 * are submitted.
215 */
216 void goForward();
217
218 /**
219 * Goes up one step of the Url path. The signals
220 * KUrlNavigator::urlChanged() and KUrlNavigator::historyChanged()
221 * are submitted.
222 */
223 void goUp();
224
225 /**
226 * Goes to the home URL. The signals KUrlNavigator::urlChanged()
227 * and KUrlNavigator::historyChanged() are submitted.
228 */
229 void goHome();
230
231 /**
232 * Sets the URL of the navigation bar to an editable state
233 * if \a editable is true. If \a editable is false, each part of
234 * the location is presented by a button for a fast navigation.
235 */
236 void setUrlEditable(bool editable);
237
238 /** Returns true, if at least one item is selected. */
239 bool hasSelection() const;
240
241 void clearSelection();
242
243 /**
244 * Returns the selected items. The list is empty if no item has been
245 * selected.
246 * @see DolphinView::selectedUrls()
247 */
248 KFileItemList selectedItems() const;
249
250 /**
251 * Returns a list of URLs for all selected items. An empty list
252 * is returned, if no item is selected.
253 * @see DolphinView::selectedItems()
254 */
255 KUrl::List selectedUrls() const;
256
257 /**
258 * Returns the file item for the given model index \a index.
259 */
260 KFileItem* fileItem(const QModelIndex index) const;
261
262 /**
263 * Renames the filename of the source URL by the new file name.
264 * If the new file name already exists, a dialog is opened which
265 * asks the user to enter a new name.
266 */
267 void rename(const KUrl& source, const QString& newName);
268
269 DolphinStatusBar* statusBar() const;
270
271 /**
272 * Returns the x-position of the view content.
273 * The content of the view might be larger than the visible area
274 * and hence a scrolling must be done.
275 */
276 int contentsX() const;
277
278 /**
279 * Returns the y-position of the view content.
280 * The content of the view might be larger than the visible area
281 * and hence a scrolling must be done.
282 */
283 int contentsY() const;
284
285 /**
286 * Returns true, if the URL shown by the navigation bar is editable.
287 * @see KUrlNavigator
288 */
289 bool isUrlEditable() const;
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 * Returns true, if zooming in is possible. If false is returned,
299 * the minimal zoom size is possible.
300 */
301 bool isZoomInPossible() const;
302
303 /**
304 * Returns true, if zooming out is possible. If false is returned,
305 * the maximum zoom size is possible.
306 */
307 bool isZoomOutPossible() const;
308
309 /** Sets the sort order of the items inside a directory (see DolphinView::Sorting). */
310 void setSorting(Sorting sorting);
311
312 /** Returns the sort order of the items inside a directory (see DolphinView::Sorting). */
313 Sorting sorting() const;
314
315 /** Sets the sort order (Qt::Ascending or Qt::Descending) for the items. */
316 void setSortOrder(Qt::SortOrder order);
317
318 /** Returns the current used sort order (Qt::Ascending or Qt::Descending). */
319 Qt::SortOrder sortOrder() const;
320
321 /** Sets the additional information which should be shown for the items. */
322 void setAdditionalInfo(KFileItemDelegate::AdditionalInformation info);
323
324 /** Returns the additional information which should be shown for the items. */
325 KFileItemDelegate::AdditionalInformation additionalInfo() const;
326
327 /** Returns the KUrlNavigator of the view for read access. */
328 const KUrlNavigator* urlNavigator() const
329 {
330 return m_urlNavigator;
331 }
332
333 /**
334 * Triggers to request user information for the item given
335 * by the URL \a url. The signal requestItemInfo is emitted,
336 * which provides a way for widgets to get an indication to update
337 * the item information.
338 */
339 void emitRequestItemInfo(const KUrl& url);
340
341 /** Returns true, if the filter bar is visible. */
342 bool isFilterBarVisible() const;
343
344 /**
345 * Return the DolphinMainWindow this View belongs to. It is guranteed
346 * that we have one.
347 */
348 DolphinMainWindow* mainWindow() const ;
349
350 /** Reloads the current directory. */
351 void reload();
352
353 /**
354 * Refreshs the view to get synchronized with the (updated) Dolphin settings.
355 * This method only needs to get invoked if the view settings for the Icons View,
356 * Details View or Columns View have been changed.
357 */
358 void refresh();
359
360 public slots:
361 /**
362 * Popups the filter bar above the status bar if \a show is true.
363 */
364 void showFilterBar(bool show);
365
366 /**
367 * Updates the number of items (= number of files + number of
368 * directories) in the statusbar. If files are selected, the number
369 * of selected files and the sum of the filesize is shown.
370 */
371 void updateStatusBar();
372
373 /**
374 * Requests the main window to set this view as active view, which
375 * means that all actions are applied to this view.
376 */
377 void requestActivation();
378
379 /**
380 * Request of a selection change. The view will do its best to accommodate
381 * the request, but it is not guaranteed that all items in \a selection
382 * will actually get selected. The view will e.g. not select items which
383 * are not in the currently displayed folder.
384 */
385 void changeSelection(const KFileItemList& selection);
386
387 signals:
388 /** Is emitted if URL of the view has been changed to \a url. */
389 void urlChanged(const KUrl& url);
390
391 /**
392 * Is emitted if the view mode (IconsView, DetailsView,
393 * PreviewsView) has been changed.
394 */
395 void modeChanged();
396
397 /** Is emitted if the 'show preview' property has been changed. */
398 void showPreviewChanged();
399
400 /** Is emitted if the 'show hidden files' property has been changed. */
401 void showHiddenFilesChanged();
402
403 /** Is emitted if the 'categorized sorting' property has been changed. */
404 void categorizedSortingChanged();
405
406 /** Is emitted if the sorting by name, size or date has been changed. */
407 void sortingChanged(DolphinView::Sorting sorting);
408
409 /** Is emitted if the sort order (ascending or descending) has been changed. */
410 void sortOrderChanged(Qt::SortOrder order);
411
412 /** Is emitted if the addtional information for an item has been changed. */
413 void additionalInfoChanged(KFileItemDelegate::AdditionalInformation info);
414
415 /**
416 * Is emitted if information of an item is requested to be shown e. g. in the sidebar.
417 * It the URL is empty, no item information request is pending.
418 */
419 void requestItemInfo(const KUrl& url);
420
421 /** Is emitted if the contents has been moved to \a x, \a y. */
422 void contentsMoved(int x, int y);
423
424 /**
425 * Is emitted whenever the selection has been changed.
426 */
427 void selectionChanged(const KFileItemList& selection);
428
429 /**
430 * Is emitted whenever the filter bar has been turned show or hidden.
431 */
432 void showFilterBarChanged(bool shown);
433
434 protected:
435 /** @see QWidget::mouseReleaseEvent */
436 virtual void mouseReleaseEvent(QMouseEvent* event);
437
438 private slots:
439 void changeDirectory(const KUrl& url);
440 void triggerItem(const QModelIndex& index);
441 void updateProgress(int percent);
442
443 /**
444 * Updates the number of items (= number of directories + number of files)
445 * and shows this information in the statusbar.
446 */
447 void updateItemCount();
448
449 /**
450 * Generates a preview image for each file item in \a items.
451 * The current preview settings (maximum size, 'Show Preview' menu)
452 * are respected.
453 */
454 void generatePreviews(const KFileItemList& items);
455
456 /**
457 * Replaces the icon of the item \a item by the preview pixmap
458 * \a pixmap.
459 */
460 void showPreview(const KFileItem& item, const QPixmap& pixmap);
461
462 /**
463 * Restores the x- and y-position of the contents if the
464 * current view is part of the history.
465 */
466 void restoreContentsPos();
467
468 /** Shows the information \a msg inside the statusbar. */
469 void showInfoMessage(const QString& msg);
470
471 /** Shows the error message \a msg inside the statusbar. */
472 void showErrorMessage(const QString& msg);
473
474 void emitSelectionChangedSignal();
475 void closeFilterBar();
476
477 /**
478 * Filters the currently shown items by \a nameFilter. All items
479 * which contain the given filter string will be shown.
480 */
481 void changeNameFilter(const QString& nameFilter);
482
483 /**
484 * Opens the context menu on position \a pos. The position
485 * is used to check whether the context menu is related to an
486 * item or to the viewport.
487 */
488 void openContextMenu(const QPoint& pos);
489
490 /**
491 * Drops the URLs \a urls to the index \a index. \a source
492 * indicates the widget where the dragging has been started from.
493 */
494 void dropUrls(const KUrl::List& urls,
495 const QModelIndex& index,
496 QWidget* source);
497
498 /**
499 * Drops the URLs \a urls at the
500 * destination \a destination.
501 */
502 void dropUrls(const KUrl::List& urls,
503 const KUrl& destination);
504 /**
505 * Updates the view properties of the current URL to the
506 * sorting given by \a sorting.
507 */
508 void updateSorting(DolphinView::Sorting sorting);
509
510 /**
511 * Updates the view properties of the current URL to the
512 * sort order given by \a order.
513 */
514 void updateSortOrder(Qt::SortOrder order);
515
516 /**
517 * Emits the signal contentsMoved with the current coordinates
518 * of the viewport as parameters.
519 */
520 void emitContentsMoved();
521
522 /**
523 * Updates the activation state of the view by checking whether
524 * the currently active view is this view.
525 */
526 void updateActivationState();
527
528 /** Applies an item effect to all cut items of the clipboard. */
529 void updateCutItems();
530
531 private:
532 void startDirLister(const KUrl& url, bool reload = false);
533
534 /**
535 * Returns the default text of the status bar, if no item is
536 * selected.
537 */
538 QString defaultStatusBarText() const;
539
540 /**
541 * Returns the text for the status bar, if at least one item
542 * is selected.
543 */
544 QString selectionStatusBarText() const;
545
546 /**
547 * Creates a new view representing the given view mode (DolphinView::mode()).
548 * The current view will get deleted.
549 */
550 void createView();
551
552 /**
553 * Selects all items by using the selection flags \a flags. This is a helper
554 * method for the slots DolphinView::selectAll() and DolphinView::invertSelection().
555 */
556 void selectAll(QItemSelectionModel::SelectionFlags flags);
557
558 /**
559 * Returns a pointer to the currently used item view, which is either
560 * a ListView or a TreeView.
561 */
562 QAbstractItemView* itemView() const;
563
564 /**
565 * Returns true if the index is valid and represents
566 * the column KDirModel::Name.
567 */
568 bool isValidNameIndex(const QModelIndex& index) const;
569
570 /**
571 * Returns true, if the item \a item has been cut into
572 * the clipboard.
573 */
574 bool isCutItem(const KFileItem& item) const;
575
576 /** Applies an item effect to all cut items. */
577 void applyCutItemEffect();
578
579 /**
580 * Returns true, if the ColumnView is activated. As the column view
581 * requires some special handling for iterating through directories,
582 * this method has been introduced for convenience.
583 */
584 bool isColumnViewActive() const
585 {
586 return m_columnView != 0;
587 }
588
589 private:
590 /**
591 * Remembers the original pixmap for an item before
592 * the cut effect is applied.
593 */
594 struct CutItem
595 {
596 KUrl url;
597 QPixmap pixmap;
598 };
599
600 bool m_showProgress;
601 bool m_blockContentsMovedSignal;
602 bool m_initializeColumnView;
603 Mode m_mode;
604
605 int m_iconSize;
606 int m_folderCount;
607 int m_fileCount;
608
609 DolphinMainWindow* m_mainWindow;
610 QVBoxLayout* m_topLayout;
611 KUrlNavigator* m_urlNavigator;
612
613 DolphinController* m_controller;
614 DolphinIconsView* m_iconsView;
615 DolphinDetailsView* m_detailsView;
616 DolphinColumnView* m_columnView;
617 KFileItemDelegate* m_fileItemDelegate;
618
619 FilterBar* m_filterBar;
620 DolphinStatusBar* m_statusBar;
621
622 KDirModel* m_dirModel;
623 DolphinDirLister* m_dirLister;
624 DolphinSortFilterProxyModel* m_proxyModel;
625
626 QList<CutItem> m_cutItemsCache;
627 };
628
629 #endif // _DOLPHINVIEW_H_