]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinview.h
remove unused method (relict from times when KFilePreviewGenerator was not available)
[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 <config-nepomuk.h>
26
27 #include "libdolphin_export.h"
28
29 #include <kparts/part.h>
30 #include <kfileitem.h>
31 #include <kfileitemdelegate.h>
32 #include <kio/fileundomanager.h>
33 #include <kio/job.h>
34
35 #include <QBoxLayout>
36 #include <QKeyEvent>
37 #include <QLinkedList>
38 #include <QListView>
39 #include <QWidget>
40
41 class DolphinController;
42 class DolphinColumnView;
43 class DolphinDetailsView;
44 class DolphinFileItemDelegate;
45 class DolphinIconsView;
46 class DolphinMainWindow;
47 class DolphinModel;
48 class DolphinSortFilterProxyModel;
49 class KFilePreviewGenerator;
50 class KAction;
51 class KActionCollection;
52 class KDirLister;
53 class KUrl;
54 class KToggleAction;
55 class ToolTipManager;
56 class QModelIndex;
57 class ViewProperties;
58
59 /**
60 * @short Represents a view for the directory content.
61 *
62 * View modes for icons, details and columns are supported. It's
63 * possible to adjust:
64 * - sort order
65 * - sort type
66 * - show hidden files
67 * - show previews
68 *
69 * @see DolphinIconsView
70 * @see DolphinDetailsView
71 * @see DolphinColumnView
72 */
73 class LIBDOLPHINPRIVATE_EXPORT DolphinView : public QWidget
74 {
75 Q_OBJECT
76
77 public:
78 /**
79 * Defines the view mode for a directory. The view mode
80 * can be defined when constructing a DolphinView. The
81 * view mode is automatically updated if the directory itself
82 * defines a view mode (see class ViewProperties for details).
83 */
84 enum Mode
85 {
86 /**
87 * The directory items are shown as icons including an
88 * icon name.
89 */
90 IconsView = 0,
91
92 /**
93 * The icon, the name and at least the size of the directory
94 * items are shown in a table. It is possible to add columns
95 * for date, group and permissions.
96 */
97 DetailsView = 1,
98
99 /**
100 * Each folder is shown in a separate column.
101 */
102 ColumnView = 2,
103 MaxModeEnum = ColumnView
104 };
105
106 /** Defines the sort order for the items of a directory. */
107 enum Sorting
108 {
109 SortByName = 0,
110 SortBySize,
111 SortByDate,
112 SortByPermissions,
113 SortByOwner,
114 SortByGroup,
115 SortByType,
116 SortByRating,
117 SortByTags,
118 MaxSortEnum = SortByTags
119 };
120
121 /**
122 * @param parent Parent widget of the view.
123 * @param url Specifies the content which should be shown.
124 * @param dirLister Used directory lister. The lister is not owned
125 * by the view and won't get deleted.
126 * @param dolphinModel Used directory model. The model is not owned
127 * by the view and won't get deleted.
128 * @param proxyModel Used proxy model which specifies the sorting. The
129 * model is not owned by the view and won't get
130 * deleted.
131 */
132 DolphinView(QWidget* parent,
133 const KUrl& url,
134 KDirLister* dirLister,
135 DolphinModel* dolphinModel,
136 DolphinSortFilterProxyModel* proxyModel);
137
138 virtual ~DolphinView();
139
140 /**
141 * Returns the current active URL, where all actions are applied.
142 * The URL navigator is synchronized with this URL.
143 */
144 const KUrl& url() const;
145
146 /**
147 * Returns the root URL of the view, which is defined as the first
148 * visible path of DolphinView::url(). Usually the root URL is
149 * equal to DolphinView::url(), but in the case of the column view
150 * when 2 columns are shown, the root URL might be:
151 * /home/peter/Documents
152 * and DolphinView::url() might return
153 * /home/peter/Documents/Music/
154 */
155 KUrl rootUrl() const;
156
157 /**
158 * If \a active is true, the view will marked as active. The active
159 * view is defined as view where all actions are applied to.
160 */
161 void setActive(bool active);
162 bool isActive() const;
163
164 /**
165 * Changes the view mode for the current directory to \a mode.
166 * If the view properties should be remembered for each directory
167 * (GeneralSettings::globalViewProps() returns false), then the
168 * changed view mode will be stored automatically.
169 */
170 void setMode(Mode mode);
171 Mode mode() const;
172
173 /** See setShowPreview */
174 bool showPreview() const;
175
176 /** See setShowHiddenFiles */
177 bool showHiddenFiles() const;
178
179 /** See setCategorizedSorting */
180 bool categorizedSorting() const;
181
182 /**
183 * Returns true, if the categorized sorting is supported by the current
184 * used mode (see DolphinView::setMode()). Currently only DolphinView::IconsView
185 * supports categorizations. To check whether the categorized
186 * sorting is set, use DolphinView::categorizedSorting().
187 */
188 bool supportsCategorizedSorting() const;
189
190 /**
191 * Selects all items.
192 * @see DolphinView::selectedItems()
193 */
194 void selectAll();
195
196 /**
197 * Inverts the current selection: selected items get unselected,
198 * unselected items get selected.
199 * @see DolphinView::selectedItems()
200 */
201 void invertSelection();
202
203 /** Returns true, if at least one item is selected. */
204 bool hasSelection() const;
205
206 void clearSelection();
207
208 /**
209 * Returns the selected items. The list is empty if no item has been
210 * selected.
211 * @see DolphinView::selectedUrls()
212 */
213 KFileItemList selectedItems() const;
214
215 /**
216 * Returns a list of URLs for all selected items. An empty list
217 * is returned, if no item is selected.
218 * @see DolphinView::selectedItems()
219 */
220 KUrl::List selectedUrls() const;
221
222 /**
223 * Returns the number of selected items (this is faster than
224 * invoking selectedItems().count()).
225 */
226 int selectedItemsCount() const;
227
228 /**
229 * Sets the upper left position of the view content
230 * to (x,y). The content of the view might be larger than the visible area
231 * and hence a scrolling must be done.
232 */
233 void setContentsPosition(int x, int y);
234
235 /** Returns the upper left position of the view content. */
236 QPoint contentsPosition() const;
237
238 /**
239 * Sets the zoom level to \a level. It is assured that the used
240 * level is adjusted to be inside the range ZoomLevelInfo::minimumLevel() and
241 * ZoomLevelInfo::maximumLevel().
242 */
243 void setZoomLevel(int level);
244 int zoomLevel() const;
245
246 /**
247 * Returns true, if zooming in is possible. If false is returned,
248 * the maximum zooming level has been reached.
249 */
250 bool isZoomInPossible() const;
251
252 /**
253 * Returns true, if zooming out is possible. If false is returned,
254 * the minimum zooming level has been reached.
255 */
256 bool isZoomOutPossible() const;
257
258 /** Sets the sort order of the items inside a directory (see DolphinView::Sorting). */
259 void setSorting(Sorting sorting);
260
261 /** Returns the sort order of the items inside a directory (see DolphinView::Sorting). */
262 Sorting sorting() const;
263
264 /** Sets the sort order (Qt::Ascending or Qt::Descending) for the items. */
265 void setSortOrder(Qt::SortOrder order);
266
267 /** Returns the current used sort order (Qt::Ascending or Qt::Descending). */
268 Qt::SortOrder sortOrder() const;
269
270 /** Sets a separate sorting with folders first (true) or a mixed sorting of files and folders (false). */
271 void setSortFoldersFirst(bool foldersFirst);
272
273 /** Returns if files and folders are sorted separately or not. */
274 bool sortFoldersFirst() const;
275
276 /** Sets the additional information which should be shown for the items. */
277 void setAdditionalInfo(KFileItemDelegate::InformationList info);
278
279 /** Returns the additional information which should be shown for the items. */
280 KFileItemDelegate::InformationList additionalInfo() const;
281
282 /** Reloads the current directory. */
283 void reload();
284
285 /**
286 * Refreshes the view to get synchronized with the (updated) Dolphin settings.
287 * This method only needs to get invoked if the view settings for the Icons View,
288 * Details View or Columns View have been changed.
289 */
290 void refresh();
291
292 /**
293 * Changes the directory of the view to \a url. If \a rootUrl is empty, the view
294 * properties from \a url are used for adjusting the view mode and the other properties.
295 * If \a rootUrl is not empty, the view properties from the root URL are considered
296 * instead. Specifying a root URL is only required if a view having a different root URL
297 * (e. g. the column view) should be restored. Usually using DolphinView::setUrl()
298 * is enough for changing the current URL.
299 */
300 void updateView(const KUrl& url, const KUrl& rootUrl);
301
302 /**
303 * Filters the currently shown items by \a nameFilter. All items
304 * which contain the given filter string will be shown.
305 */
306 void setNameFilter(const QString& nameFilter);
307
308 /**
309 * Calculates the number of currently shown files into
310 * \a fileCount and the number of folders into \a folderCount.
311 * The size of all files is written into \a totalFileSize.
312 * It is recommend using this method instead of asking the
313 * directory lister or the model directly, as it takes
314 * filtering and hierarchical previews into account.
315 */
316 void calculateItemCount(int& fileCount, int& folderCount, KIO::filesize_t& totalFileSize) const;
317
318 /**
319 * Returns a textual representation of the state of the current
320 * folder or selected items, suitable for use in the status bar.
321 */
322 QString statusBarText() const;
323
324 /**
325 * Updates the state of the 'Additional Information' actions in \a collection.
326 */
327 void updateAdditionalInfoActions(KActionCollection* collection);
328
329 /**
330 * Returns the state of the paste action:
331 * first is whether the action should be enabled
332 * second is the text for the action
333 */
334 QPair<bool, QString> pasteInfo() const;
335
336 /**
337 * If \a tabsForFiles is true, the signal tabRequested() will also
338 * emitted also for files. Per default tabs for files is disabled
339 * and hence the signal tabRequested() will only be emitted for
340 * directories.
341 */
342 void setTabsForFilesEnabled(bool tabsForFiles);
343 bool isTabsForFilesEnabled() const;
344
345 /**
346 * Returns true if the current view allows folders to be expanded,
347 * i.e. presents a hierarchical view to the user.
348 */
349 bool itemsExpandable() const;
350
351 public slots:
352 /**
353 * Changes the directory to \a url. If the current directory is equal to
354 * \a url, nothing will be done (use DolphinView::reload() instead).
355 */
356 void setUrl(const KUrl& url);
357
358 /**
359 * Request of a selection change. The view will do its best to accommodate
360 * the request, but it is not guaranteed that all items in \a selection
361 * will actually get selected. The view will e.g. not select items which
362 * are not in the currently displayed folder.
363 */
364 void changeSelection(const KFileItemList& selection);
365
366 /**
367 * Triggers the renaming of the currently selected items, where
368 * the user must input a new name for the items.
369 */
370 void renameSelectedItems();
371
372 /**
373 * Moves all selected items to the trash.
374 */
375 void trashSelectedItems();
376
377 /**
378 * Deletes all selected items.
379 */
380 void deleteSelectedItems();
381
382 /**
383 * Copies all selected items to the clipboard and marks
384 * the items as cutted.
385 */
386 void cutSelectedItems();
387
388 /** Copies all selected items to the clipboard. */
389 void copySelectedItems();
390
391 /** Pastes the clipboard data to this view. */
392 void paste();
393
394 /**
395 * Pastes the clipboard data into the currently selected
396 * folder. If the current selection is not exactly one folder, no
397 * paste operation is done.
398 */
399 void pasteIntoFolder();
400
401 /**
402 * Turns on the file preview for the all files of the current directory,
403 * if \a show is true.
404 * If the view properties should be remembered for each directory
405 * (GeneralSettings::globalViewProps() returns false), then the
406 * preview setting will be stored automatically.
407 */
408 void setShowPreview(bool show);
409
410 /**
411 * Shows all hidden files of the current directory,
412 * if \a show is true.
413 * If the view properties should be remembered for each directory
414 * (GeneralSettings::globalViewProps() returns false), then the
415 * show hidden file setting will be stored automatically.
416 */
417 void setShowHiddenFiles(bool show);
418
419 /**
420 * Summarizes all sorted items by their category \a categorized
421 * is true.
422 * If the view properties should be remembered for each directory
423 * (GeneralSettings::globalViewProps() returns false), then the
424 * categorized sorting setting will be stored automatically.
425 */
426 void setCategorizedSorting(bool categorized);
427
428 /** Switches between an ascending and descending sorting order. */
429 void toggleSortOrder();
430
431 /** Switches between a separate sorting (with folders first) and a mixed sorting of files and folders. */
432 void toggleSortFoldersFirst();
433
434 /**
435 * Switches on or off the displaying of additional information
436 * as specified by \a action.
437 */
438 void toggleAdditionalInfo(QAction* action);
439
440 signals:
441 /**
442 * Is emitted if the view has been activated by e. g. a mouse click.
443 */
444 void activated();
445
446 /** Is emitted if URL of the view has been changed to \a url. */
447 void urlChanged(const KUrl& url);
448
449 /**
450 * Is emitted if the view requests a changing of the current
451 * URL to \a url (see DolphinController::triggerUrlChangeRequest()).
452 */
453 void requestUrlChange(const KUrl& url);
454
455 /**
456 * Is emitted when clicking on an item with the left mouse button.
457 */
458 void itemTriggered(const KFileItem& item);
459
460 /**
461 * Is emitted if a new tab should be opened for the URL \a url.
462 */
463 void tabRequested(const KUrl& url);
464
465 /**
466 * Is emitted if the view mode (IconsView, DetailsView,
467 * PreviewsView) has been changed.
468 */
469 void modeChanged();
470
471 /** Is emitted if the 'show preview' property has been changed. */
472 void showPreviewChanged();
473
474 /** Is emitted if the 'show hidden files' property has been changed. */
475 void showHiddenFilesChanged();
476
477 /** Is emitted if the 'categorized sorting' property has been changed. */
478 void categorizedSortingChanged();
479
480 /** Is emitted if the sorting by name, size or date has been changed. */
481 void sortingChanged(DolphinView::Sorting sorting);
482
483 /** Is emitted if the sort order (ascending or descending) has been changed. */
484 void sortOrderChanged(Qt::SortOrder order);
485
486 /** Is emitted if the sorting of files and folders (separate with folders first or mixed) has been changed. */
487 void sortFoldersFirstChanged(bool foldersFirst);
488
489 /** Is emitted if the additional information shown for this view has been changed. */
490 void additionalInfoChanged();
491
492 /** Is emitted if the zoom level has been changed by zooming in or out. */
493 void zoomLevelChanged(int level);
494
495 /**
496 * Is emitted if information of an item is requested to be shown e. g. in the panel.
497 * If item is null, no item information request is pending.
498 */
499 void requestItemInfo(const KFileItem& item);
500
501 /** Is emitted if the contents has been moved to \a x, \a y. */
502 void contentsMoved(int x, int y);
503
504 /**
505 * Is emitted whenever the selection has been changed.
506 */
507 void selectionChanged(const KFileItemList& selection);
508
509 /**
510 * Is emitted if a context menu is requested for the item \a item,
511 * which is part of \a url. If the item is null, the context menu
512 * for the URL should be shown and the custom actions \a customActions
513 * will be added.
514 */
515 void requestContextMenu(const KFileItem& item,
516 const KUrl& url,
517 const QList<QAction*>& customActions);
518
519 /**
520 * Is emitted if an information message with the content \a msg
521 * should be shown.
522 */
523 void infoMessage(const QString& msg);
524
525 /**
526 * Is emitted if an error message with the content \a msg
527 * should be shown.
528 */
529 void errorMessage(const QString& msg);
530
531 /**
532 * Is emitted if an "operation completed" message with the content \a msg
533 * should be shown.
534 */
535 void operationCompletedMessage(const QString& msg);
536
537 /**
538 * Is emitted after DolphinView::setUrl() has been invoked and
539 * the path \a url is currently loaded. If this signal is emitted,
540 * it is assured that the view contains already the correct root
541 * URL and property settings.
542 */
543 void startedPathLoading(const KUrl& url);
544
545 /**
546 * Emitted when KDirLister emits redirection.
547 * Testcase: fish://localhost
548 */
549 void redirection(const KUrl& oldUrl, const KUrl& newUrl);
550
551 protected:
552 /** @see QWidget::mouseReleaseEvent */
553 virtual void mouseReleaseEvent(QMouseEvent* event);
554 virtual void wheelEvent(QWheelEvent* event);
555 virtual bool eventFilter(QObject* watched, QEvent* event);
556
557 private slots:
558 /**
559 * Marks the view as active (DolphinView:isActive() will return true)
560 * and emits the 'activated' signal if it is not already active.
561 */
562 void activate();
563
564 /**
565 * If the item \a item is a directory, then this
566 * directory will be loaded. If the item is a file, the corresponding
567 * application will get started.
568 */
569 void triggerItem(const KFileItem& index);
570
571 void emitSelectionChangedSignal();
572
573 /**
574 * Opens the context menu on position \a pos. The position
575 * is used to check whether the context menu is related to an
576 * item or to the viewport.
577 */
578 void openContextMenu(const QPoint& pos, const QList<QAction*>& customActions);
579
580 /**
581 * Drops dragged URLs to the destination path \a destPath. If
582 * the URLs are dropped above an item inside the destination path,
583 * the item is indicated by \a destItem.
584 */
585 void dropUrls(const KFileItem& destItem,
586 const KUrl& destPath,
587 QDropEvent* event);
588
589 /**
590 * Updates the view properties of the current URL to the
591 * sorting given by \a sorting.
592 */
593 void updateSorting(DolphinView::Sorting sorting);
594
595 /**
596 * Updates the view properties of the current URL to the
597 * sort order given by \a order.
598 */
599 void updateSortOrder(Qt::SortOrder order);
600
601 /**
602 * Updates the view properties of the current URL to the
603 * sorting of files and folders (separate with folders first or mixed) given by \a foldersFirst.
604 */
605 void updateSortFoldersFirst(bool foldersFirst);
606
607 /**
608 * Updates the view properties of the current URL to the
609 * additional information given by \a info.
610 */
611 void updateAdditionalInfo(const KFileItemDelegate::InformationList& info);
612
613 /**
614 * Emits the signal contentsMoved with the current coordinates
615 * of the viewport as parameters.
616 */
617 void emitContentsMoved();
618
619 /**
620 * Updates the status bar to show hover information for the
621 * item \a item. If currently other items are selected,
622 * no hover information is shown.
623 * @see DolphinView::clearHoverInformation()
624 */
625 void showHoverInformation(const KFileItem& item);
626
627 /**
628 * Clears the hover information shown in the status bar.
629 * @see DolphinView::showHoverInformation().
630 */
631 void clearHoverInformation();
632
633 /**
634 * Indicates in the status bar that the delete operation
635 * of the job \a job has been finished.
636 */
637 void slotDeleteFileFinished(KJob* job);
638
639 /**
640 * Is emitted if the controller requests a changing of the current
641 * URL to \a url
642 */
643 void slotRequestUrlChange(const KUrl& url);
644
645 /**
646 * Restores the current item (= item that has the keyboard focus)
647 * to m_currentItemUrl.
648 */
649 void restoreCurrentItem();
650
651 /**
652 * Is invoked when the KDirLister indicates refreshed items.
653 */
654 void slotRefreshItems();
655
656 /**
657 * If \a view can be positively identified as not being the source for the
658 * current drag operation, deleteLater() it immediately. Else stores
659 * it for later deletion.
660 */
661 void deleteWhenNotDragSource(QAbstractItemView* view);
662
663 /**
664 * Observes the item with the URL \a url. As soon as the directory
665 * model indicates that the item is available, the item will
666 * get selected and it is assure that the item stays visible.
667 *
668 * @see selectAndScrollToCreatedItem()
669 */
670 void observeCreatedItem(const KUrl& url);
671
672 /**
673 * Selects and scrolls to the item that got observed
674 * by observeCreatedItem().
675 */
676 void selectAndScrollToCreatedItem();
677
678 /**
679 * Restore selection after view refresh.
680 */
681 void restoreSelection();
682
683 private:
684 void loadDirectory(const KUrl& url, bool reload = false);
685
686 /**
687 * Returns the URL where the view properties should be stored. Usually
688 * DolphinView::url() is returned, but in the case of a Column View the
689 * view properties are always stored in the directory represented by the
690 * first column. It is recommendend whenever using the ViewProperties class
691 * to use DolphinView::viewPropertiesUrl() as URL.
692 */
693 KUrl viewPropertiesUrl() const;
694
695 /**
696 * Applies the view properties which are defined by the current URL
697 * m_url to the DolphinView properties.
698 */
699 void applyViewProperties(const KUrl& url);
700
701 /**
702 * Creates a new view representing the given view mode (DolphinView::mode()).
703 * The current view will get deleted.
704 */
705 void createView();
706
707 void deleteView();
708
709 /**
710 * Returns a pointer to the currently used item view, which is either
711 * a ListView or a TreeView.
712 */
713 QAbstractItemView* itemView() const;
714
715 /**
716 * Helper method for DolphinView::paste() and DolphinView::pasteIntoFolder().
717 * Pastes the clipboard data into the URL \a url.
718 */
719 void pasteToUrl(const KUrl& url);
720
721 /**
722 * Checks whether the current item view has the same zoom level
723 * as \a oldZoomLevel. If this is not the case, the zoom level
724 * of the controller is updated and a zoomLevelChanged() signal
725 * is emitted.
726 */
727 void updateZoomLevel(int oldZoomLevel);
728
729 /**
730 * Returns a list of URLs for all selected items. The list is
731 * simplified, so that when the URLs are part of different tree
732 * levels, only the parent is returned.
733 */
734 KUrl::List simplifiedSelectedUrls() const;
735
736 /**
737 * Returns true, if the ColumnView is activated. As the column view
738 * requires some special handling for iterating through directories,
739 * this method has been introduced for convenience.
740 */
741 bool isColumnViewActive() const;
742
743 /**
744 * Returns the MIME data for all selected items.
745 */
746 QMimeData* selectionMimeData() const;
747
748 private:
749 bool m_active : 1;
750 bool m_showPreview : 1;
751 bool m_loadingDirectory : 1;
752 bool m_storedCategorizedSorting : 1;
753 bool m_tabsForFiles : 1;
754 bool m_isContextMenuOpen : 1; // TODO: workaround for Qt-issue 207192
755 bool m_ignoreViewProperties : 1;
756 bool m_assureVisibleCurrentIndex : 1;
757
758 Mode m_mode;
759
760 DolphinMainWindow* m_mainWindow;
761 QVBoxLayout* m_topLayout;
762
763 DolphinController* m_controller;
764 DolphinIconsView* m_iconsView;
765 DolphinDetailsView* m_detailsView;
766 DolphinColumnView* m_columnView;
767 DolphinFileItemDelegate* m_fileItemDelegate;
768 QItemSelectionModel* m_selectionModel;
769
770 DolphinModel* m_dolphinModel;
771 KDirLister* m_dirLister;
772 DolphinSortFilterProxyModel* m_proxyModel;
773
774 KFilePreviewGenerator* m_previewGenerator;
775 ToolTipManager* m_toolTipManager;
776
777 KUrl m_rootUrl;
778 KUrl m_currentItemUrl;
779 KUrl m_createdItemUrl; // URL for a new item that got created by the "Create New..." menu
780 KFileItemList m_selectedItems; //this is used for making the View to remember selections after F5
781
782 QAbstractItemView* m_expandedDragSource;
783 };
784
785 inline bool DolphinView::isColumnViewActive() const
786 {
787 return m_columnView != 0;
788 }
789
790 /// Allow using DolphinView::Mode in QVariant
791 Q_DECLARE_METATYPE(DolphinView::Mode)
792
793 #endif // DOLPHINVIEW_H