1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
3 * Copyright (C) 2006 by Gregor Kališnik <gregor@podnapisi.net> *
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. *
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. *
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 ***************************************************************************/
25 #include <config-nepomuk.h>
27 #include "libdolphin_export.h"
29 #include <kparts/part.h>
30 #include <kfileitem.h>
31 #include <kfileitemdelegate.h>
32 #include <kio/fileundomanager.h>
37 #include <QLinkedList>
41 class DolphinController
;
42 class DolphinColumnView
;
43 class DolphinDetailsView
;
44 class DolphinFileItemDelegate
;
45 class DolphinIconsView
;
46 class DolphinMainWindow
;
48 class DolphinSortFilterProxyModel
;
49 class KFilePreviewGenerator
;
51 class KActionCollection
;
60 * @short Represents a view for the directory content.
62 * View modes for icons, details and columns are supported. It's
69 * @see DolphinIconsView
70 * @see DolphinDetailsView
71 * @see DolphinColumnView
73 class LIBDOLPHINPRIVATE_EXPORT DolphinView
: public QWidget
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).
87 * The directory items are shown as icons including an
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.
100 * Each folder is shown in a separate column.
103 MaxModeEnum
= ColumnView
106 /** Defines the sort order for the items of a directory. */
118 MaxSortEnum
= SortByTags
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
132 DolphinView(QWidget
* parent
,
134 KDirLister
* dirLister
,
135 DolphinModel
* dolphinModel
,
136 DolphinSortFilterProxyModel
* proxyModel
);
138 virtual ~DolphinView();
141 * Returns the current active URL, where all actions are applied.
142 * The URL navigator is synchronized with this URL.
144 const KUrl
& url() const;
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/
155 KUrl
rootUrl() const;
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.
161 void setActive(bool active
);
162 bool isActive() const;
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.
170 void setMode(Mode mode
);
173 /** See setShowPreview */
174 bool showPreview() const;
176 /** See setShowHiddenFiles */
177 bool showHiddenFiles() const;
179 /** See setCategorizedSorting */
180 bool categorizedSorting() const;
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().
188 bool supportsCategorizedSorting() const;
192 * @see DolphinView::selectedItems()
197 * Inverts the current selection: selected items get unselected,
198 * unselected items get selected.
199 * @see DolphinView::selectedItems()
201 void invertSelection();
203 /** Returns true, if at least one item is selected. */
204 bool hasSelection() const;
206 void clearSelection();
209 * Returns the selected items. The list is empty if no item has been
211 * @see DolphinView::selectedUrls()
213 KFileItemList
selectedItems() const;
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()
220 KUrl::List
selectedUrls() const;
223 * Returns the number of selected items (this is faster than
224 * invoking selectedItems().count()).
226 int selectedItemsCount() const;
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.
233 void setContentsPosition(int x
, int y
);
235 /** Returns the upper left position of the view content. */
236 QPoint
contentsPosition() const;
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().
243 void setZoomLevel(int level
);
244 int zoomLevel() const;
247 * Returns true, if zooming in is possible. If false is returned,
248 * the maximum zooming level has been reached.
250 bool isZoomInPossible() const;
253 * Returns true, if zooming out is possible. If false is returned,
254 * the minimum zooming level has been reached.
256 bool isZoomOutPossible() const;
258 /** Sets the sort order of the items inside a directory (see DolphinView::Sorting). */
259 void setSorting(Sorting sorting
);
261 /** Returns the sort order of the items inside a directory (see DolphinView::Sorting). */
262 Sorting
sorting() const;
264 /** Sets the sort order (Qt::Ascending or Qt::Descending) for the items. */
265 void setSortOrder(Qt::SortOrder order
);
267 /** Returns the current used sort order (Qt::Ascending or Qt::Descending). */
268 Qt::SortOrder
sortOrder() const;
270 /** Sets the additional information which should be shown for the items. */
271 void setAdditionalInfo(KFileItemDelegate::InformationList info
);
273 /** Returns the additional information which should be shown for the items. */
274 KFileItemDelegate::InformationList
additionalInfo() const;
276 /** Reloads the current directory. */
280 * Refreshes the view to get synchronized with the (updated) Dolphin settings.
281 * This method only needs to get invoked if the view settings for the Icons View,
282 * Details View or Columns View have been changed.
287 * Changes the directory of the view to \a url. If \a rootUrl is empty, the view
288 * properties from \a url are used for adjusting the view mode and the other properties.
289 * If \a rootUrl is not empty, the view properties from the root URL are considered
290 * instead. Specifying a root URL is only required if a view having a different root URL
291 * (e. g. the column view) should be restored. Usually using DolphinView::setUrl()
292 * is enough for changing the current URL.
294 void updateView(const KUrl
& url
, const KUrl
& rootUrl
);
297 * Filters the currently shown items by \a nameFilter. All items
298 * which contain the given filter string will be shown.
300 void setNameFilter(const QString
& nameFilter
);
303 * Calculates the number of currently shown files into
304 * \a fileCount and the number of folders into \a folderCount.
305 * The size of all files is written into \a totalFileSize.
306 * It is recommend using this method instead of asking the
307 * directory lister or the model directly, as it takes
308 * filtering and hierarchical previews into account.
310 void calculateItemCount(int& fileCount
, int& folderCount
, KIO::filesize_t
& totalFileSize
) const;
313 * Returns a textual representation of the state of the current
314 * folder or selected items, suitable for use in the status bar.
316 QString
statusBarText() const;
319 * Updates the state of the 'Additional Information' actions in \a collection.
321 void updateAdditionalInfoActions(KActionCollection
* collection
);
324 * Returns the state of the paste action:
325 * first is whether the action should be enabled
326 * second is the text for the action
328 QPair
<bool, QString
> pasteInfo() const;
331 * If \a tabsForFiles is true, the signal tabRequested() will also
332 * emitted also for files. Per default tabs for files is disabled
333 * and hence the signal tabRequested() will only be emitted for
336 void setTabsForFilesEnabled(bool tabsForFiles
);
337 bool isTabsForFilesEnabled() const;
340 * Returns true if the current view allows folders to be expanded,
341 * i.e. presents a hierarchical view to the user.
343 bool itemsExpandable() const;
347 * Changes the directory to \a url. If the current directory is equal to
348 * \a url, nothing will be done (use DolphinView::reload() instead).
350 void setUrl(const KUrl
& url
);
353 * Request of a selection change. The view will do its best to accommodate
354 * the request, but it is not guaranteed that all items in \a selection
355 * will actually get selected. The view will e.g. not select items which
356 * are not in the currently displayed folder.
358 void changeSelection(const KFileItemList
& selection
);
361 * Triggers the renaming of the currently selected items, where
362 * the user must input a new name for the items.
364 void renameSelectedItems();
367 * Moves all selected items to the trash.
369 void trashSelectedItems();
372 * Deletes all selected items.
374 void deleteSelectedItems();
377 * Copies all selected items to the clipboard and marks
378 * the items as cutted.
380 void cutSelectedItems();
382 /** Copies all selected items to the clipboard. */
383 void copySelectedItems();
385 /** Pastes the clipboard data to this view. */
389 * Pastes the clipboard data into the currently selected
390 * folder. If the current selection is not exactly one folder, no
391 * paste operation is done.
393 void pasteIntoFolder();
396 * Turns on the file preview for the all files of the current directory,
397 * if \a show is true.
398 * If the view properties should be remembered for each directory
399 * (GeneralSettings::globalViewProps() returns false), then the
400 * preview setting will be stored automatically.
402 void setShowPreview(bool show
);
405 * Shows all hidden files of the current directory,
406 * if \a show is true.
407 * If the view properties should be remembered for each directory
408 * (GeneralSettings::globalViewProps() returns false), then the
409 * show hidden file setting will be stored automatically.
411 void setShowHiddenFiles(bool show
);
414 * Summarizes all sorted items by their category \a categorized
416 * If the view properties should be remembered for each directory
417 * (GeneralSettings::globalViewProps() returns false), then the
418 * categorized sorting setting will be stored automatically.
420 void setCategorizedSorting(bool categorized
);
422 /** Switches between an ascending and descending sorting order. */
423 void toggleSortOrder();
426 * Switches on or off the displaying of additional information
427 * as specified by \a action.
429 void toggleAdditionalInfo(QAction
* action
);
433 * Is emitted if the view has been activated by e. g. a mouse click.
437 /** Is emitted if URL of the view has been changed to \a url. */
438 void urlChanged(const KUrl
& url
);
441 * Is emitted if the view requests a changing of the current
442 * URL to \a url (see DolphinController::triggerUrlChangeRequest()).
444 void requestUrlChange(const KUrl
& url
);
447 * Is emitted when clicking on an item with the left mouse button.
449 void itemTriggered(const KFileItem
& item
);
452 * Is emitted if a new tab should be opened for the URL \a url.
454 void tabRequested(const KUrl
& url
);
457 * Is emitted if the view mode (IconsView, DetailsView,
458 * PreviewsView) has been changed.
462 /** Is emitted if the 'show preview' property has been changed. */
463 void showPreviewChanged();
465 /** Is emitted if the 'show hidden files' property has been changed. */
466 void showHiddenFilesChanged();
468 /** Is emitted if the 'categorized sorting' property has been changed. */
469 void categorizedSortingChanged();
471 /** Is emitted if the sorting by name, size or date has been changed. */
472 void sortingChanged(DolphinView::Sorting sorting
);
474 /** Is emitted if the sort order (ascending or descending) has been changed. */
475 void sortOrderChanged(Qt::SortOrder order
);
477 /** Is emitted if the additional information shown for this view has been changed. */
478 void additionalInfoChanged();
480 /** Is emitted if the zoom level has been changed by zooming in or out. */
481 void zoomLevelChanged(int level
);
484 * Is emitted if information of an item is requested to be shown e. g. in the panel.
485 * If item is null, no item information request is pending.
487 void requestItemInfo(const KFileItem
& item
);
489 /** Is emitted if the contents has been moved to \a x, \a y. */
490 void contentsMoved(int x
, int y
);
493 * Is emitted whenever the selection has been changed.
495 void selectionChanged(const KFileItemList
& selection
);
498 * Is emitted if a context menu is requested for the item \a item,
499 * which is part of \a url. If the item is 0, the context menu
500 * for the URL should be shown.
502 void requestContextMenu(const KFileItem
& item
, const KUrl
& url
);
505 * Is emitted if an information message with the content \a msg
508 void infoMessage(const QString
& msg
);
511 * Is emitted if an error message with the content \a msg
514 void errorMessage(const QString
& msg
);
517 * Is emitted if an "operation completed" message with the content \a msg
520 void operationCompletedMessage(const QString
& msg
);
523 * Is emitted after DolphinView::setUrl() has been invoked and
524 * the path \a url is currently loaded. If this signal is emitted,
525 * it is assured that the view contains already the correct root
526 * URL and property settings.
528 void startedPathLoading(const KUrl
& url
);
531 * Emitted when KDirLister emits redirection.
532 * Testcase: fish://localhost
534 void redirection(const KUrl
& oldUrl
, const KUrl
& newUrl
);
537 /** @see QWidget::mouseReleaseEvent */
538 virtual void mouseReleaseEvent(QMouseEvent
* event
);
539 virtual void wheelEvent(QWheelEvent
* event
);
540 virtual bool eventFilter(QObject
* watched
, QEvent
* event
);
544 * Marks the view as active (DolphinView:isActive() will return true)
545 * and emits the 'activated' signal if it is not already active.
550 * If the item \a item is a directory, then this
551 * directory will be loaded. If the item is a file, the corresponding
552 * application will get started.
554 void triggerItem(const KFileItem
& index
);
556 void emitSelectionChangedSignal();
559 * Opens the context menu on position \a pos. The position
560 * is used to check whether the context menu is related to an
561 * item or to the viewport.
563 void openContextMenu(const QPoint
& pos
);
566 * Drops dragged URLs to the destination path \a destPath. If
567 * the URLs are dropped above an item inside the destination path,
568 * the item is indicated by \a destItem.
570 void dropUrls(const KFileItem
& destItem
,
571 const KUrl
& destPath
,
575 * Updates the view properties of the current URL to the
576 * sorting given by \a sorting.
578 void updateSorting(DolphinView::Sorting sorting
);
581 * Updates the view properties of the current URL to the
582 * sort order given by \a order.
584 void updateSortOrder(Qt::SortOrder order
);
587 * Updates the view properties of the current URL to the
588 * additional information given by \a info.
590 void updateAdditionalInfo(const KFileItemDelegate::InformationList
& info
);
593 * Emits the signal contentsMoved with the current coordinates
594 * of the viewport as parameters.
596 void emitContentsMoved();
599 * Updates the status bar to show hover information for the
600 * item \a item. If currently other items are selected,
601 * no hover information is shown.
602 * @see DolphinView::clearHoverInformation()
604 void showHoverInformation(const KFileItem
& item
);
607 * Clears the hover information shown in the status bar.
608 * @see DolphinView::showHoverInformation().
610 void clearHoverInformation();
613 * Indicates in the status bar that the delete operation
614 * of the job \a job has been finished.
616 void slotDeleteFileFinished(KJob
* job
);
619 * Is emitted if the controller requests a changing of the current
622 void slotRequestUrlChange(const KUrl
& url
);
625 * Restores the current item (= item that has the keyboard focus)
626 * to m_currentItemUrl.
628 void restoreCurrentItem();
631 * Is connected to the enterDir() signal from the FolderExpander
632 * and triggers the entering of the directory indicated by \a index.
634 void enterDir(const QModelIndex
& index
, QAbstractItemView
* view
);
637 void loadDirectory(const KUrl
& url
, bool reload
= false);
640 * Returns the URL where the view properties should be stored. Usually
641 * DolphinView::url() is returned, but in the case of a Column View the
642 * view properties are always stored in the directory represented by the
643 * first column. It is recommendend whenever using the ViewProperties class
644 * to use DolphinView::viewPropertiesUrl() as URL.
646 KUrl
viewPropertiesUrl() const;
649 * Applies the view properties which are defined by the current URL
650 * m_url to the DolphinView properties.
652 void applyViewProperties(const KUrl
& url
);
655 * Creates a new view representing the given view mode (DolphinView::mode()).
656 * The current view will get deleted.
663 * Returns a pointer to the currently used item view, which is either
664 * a ListView or a TreeView.
666 QAbstractItemView
* itemView() const;
669 * Returns true, if the item \a item has been cut into
672 bool isCutItem(const KFileItem
& item
) const;
675 * Helper method for DolphinView::paste() and DolphinView::pasteIntoFolder().
676 * Pastes the clipboard data into the URL \a url.
678 void pasteToUrl(const KUrl
& url
);
681 * Checks whether the current item view has the same zoom level
682 * as \a oldZoomLevel. If this is not the case, the zoom level
683 * of the controller is updated and a zoomLevelChanged() signal
686 void updateZoomLevel(int oldZoomLevel
);
689 * Returns a list of URLs for all selected items. The list is
690 * simplified, so that when the URLs are part of different tree
691 * levels, only the parent is returned.
693 KUrl::List
simplifiedSelectedUrls() const;
696 * Returns true, if the ColumnView is activated. As the column view
697 * requires some special handling for iterating through directories,
698 * this method has been introduced for convenience.
700 bool isColumnViewActive() const;
703 * Deletes all views from m_expandedViews except if the view
704 * is currently shown.
706 void deleteExpandedViews();
709 * Returns the MIME data for all selected items.
711 QMimeData
* selectionMimeData() const;
715 bool m_showPreview
: 1;
716 bool m_loadingDirectory
: 1;
717 bool m_storedCategorizedSorting
: 1;
718 bool m_tabsForFiles
: 1;
719 bool m_isContextMenuOpen
: 1; // TODO: workaround for Qt-issue 207192
720 bool m_ignoreViewProperties
: 1;
724 DolphinMainWindow
* m_mainWindow
;
725 QVBoxLayout
* m_topLayout
;
727 DolphinController
* m_controller
;
728 DolphinIconsView
* m_iconsView
;
729 DolphinDetailsView
* m_detailsView
;
730 DolphinColumnView
* m_columnView
;
731 DolphinFileItemDelegate
* m_fileItemDelegate
;
732 QItemSelectionModel
* m_selectionModel
;
734 DolphinModel
* m_dolphinModel
;
735 KDirLister
* m_dirLister
;
736 DolphinSortFilterProxyModel
* m_proxyModel
;
738 KFilePreviewGenerator
* m_previewGenerator
;
739 ToolTipManager
* m_toolTipManager
;
742 KUrl m_currentItemUrl
;
744 QList
<QAbstractItemView
*> m_expandedViews
;
747 inline bool DolphinView::isColumnViewActive() const
749 return m_columnView
!= 0;
752 /// Allow using DolphinView::Mode in QVariant
753 Q_DECLARE_METATYPE(DolphinView::Mode
)
755 #endif // DOLPHINVIEW_H