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>
36 #include <QLinkedList>
41 class DolphinController
;
43 class KFileItemDelegate
;
46 class DolphinColumnView
;
47 class DolphinDetailsView
;
48 class DolphinIconsView
;
49 class DolphinMainWindow
;
50 class DolphinSortFilterProxyModel
;
55 * @short Represents a view for the directory content.
57 * View modes for icons, details and columns are supported. It's
64 * @see DolphinIconsView
65 * @see DolphinDetailsView
66 * @see DolphinColumnView
68 class LIBDOLPHINPRIVATE_EXPORT DolphinView
: public QWidget
74 * Defines the view mode for a directory. The view mode
75 * can be defined when constructing a DolphinView. The
76 * view mode is automatically updated if the directory itself
77 * defines a view mode (see class ViewProperties for details).
82 * The directory items are shown as icons including an
87 * The icon, the name and at least the size of the directory
88 * items are shown in a table. It is possible to add columns
89 * for date, group and permissions.
94 * Each folder is shown in a separate column.
97 MaxModeEnum
= ColumnView
100 /** Defines the sort order for the items of a directory. */
112 MaxSortEnum
= SortByTags
116 * @param parent Parent widget of the view.
117 * @param url Specifies the content which should be shown.
118 * @param dirLister Used directory lister. The lister is not owned
119 * by the view and won't get deleted.
120 * @param dolphinModel Used directory model. The model is not owned
121 * by the view and won't get deleted.
122 * @param proxyModel Used proxy model which specifies the sorting. The
123 * model is not owned by the view and won't get
126 DolphinView(QWidget
* parent
,
128 KDirLister
* dirLister
,
129 DolphinModel
* dolphinModel
,
130 DolphinSortFilterProxyModel
* proxyModel
);
132 virtual ~DolphinView();
135 * Returns the current active URL, where all actions are applied.
136 * The URL navigator is synchronized with this URL.
138 const KUrl
& url() const;
141 * Returns the root URL of the view, which is defined as the first
142 * visible path of DolphinView::url(). Usually the root URL is
143 * equal to DolphinView::url(), but in the case of the column view
144 * when 2 columns are shown, the root URL might be:
145 * /home/peter/Documents
146 * and DolphinView::url() might return
147 * /home/peter/Documents/Music/
149 KUrl
rootUrl() const;
152 * If \a active is true, the view will marked as active. The active
153 * view is defined as view where all actions are applied to.
155 void setActive(bool active
);
156 bool isActive() const;
159 * Changes the view mode for the current directory to \a mode.
160 * If the view properties should be remembered for each directory
161 * (GeneralSettings::globalViewProps() returns false), then the
162 * changed view mode will be be stored automatically.
164 void setMode(Mode mode
);
168 * Turns on the file preview for the all files of the current directory,
169 * if \a show is true.
170 * If the view properties should be remembered for each directory
171 * (GeneralSettings::globalViewProps() returns false), then the
172 * preview setting will be be stored automatically.
174 void setShowPreview(bool show
);
175 bool showPreview() const;
178 * Shows all hidden files of the current directory,
179 * if \a show is true.
180 * If the view properties should be remembered for each directory
181 * (GeneralSettings::globalViewProps() returns false), then the
182 * show hidden file setting will be be stored automatically.
184 void setShowHiddenFiles(bool show
);
185 bool showHiddenFiles() const;
188 * Summarizes all sorted items by their category \a categorized
190 * If the view properties should be remembered for each directory
191 * (GeneralSettings::globalViewProps() returns false), then the
192 * categorized sorting setting will be be stored automatically.
194 void setCategorizedSorting(bool categorized
);
195 bool categorizedSorting() const;
198 * Returns true, if the categorized sorting is supported by the current
199 * used mode (see DolphinView::setMode()). Currently only DolphinView::IconsView
200 * supports categorizations. To check whether the categorized
201 * sorting is set, use DolphinView::categorizedSorting().
203 bool supportsCategorizedSorting() const;
207 * @see DolphinView::selectedItems()
212 * Inverts the current selection: selected items get unselected,
213 * unselected items get selected.
214 * @see DolphinView::selectedItems()
216 void invertSelection();
218 /** Returns true, if at least one item is selected. */
219 bool hasSelection() const;
221 void clearSelection();
224 * Returns the selected items. The list is empty if no item has been
226 * @see DolphinView::selectedUrls()
228 KFileItemList
selectedItems() const;
231 * Returns a list of URLs for all selected items. An empty list
232 * is returned, if no item is selected.
233 * @see DolphinView::selectedItems()
235 KUrl::List
selectedUrls() const;
238 * Returns the file item for the given model index \a index.
240 KFileItem
fileItem(const QModelIndex
& index
) const;
243 * Sets the upper left position of the view content
244 * to (x,y). The content of the view might be larger than the visible area
245 * and hence a scrolling must be done.
247 void setContentsPosition(int x
, int y
);
249 /** Returns the upper left position of the view content. */
250 QPoint
contentsPosition() const;
252 /** Increases the size of the current set view mode. */
255 /** Decreases the size of the current set view mode. */
259 * Returns true, if zooming in is possible. If false is returned,
260 * the minimal zoom size is possible.
262 bool isZoomInPossible() const;
265 * Returns true, if zooming out is possible. If false is returned,
266 * the maximum zoom size is possible.
268 bool isZoomOutPossible() const;
270 /** Sets the sort order of the items inside a directory (see DolphinView::Sorting). */
271 void setSorting(Sorting sorting
);
273 /** Returns the sort order of the items inside a directory (see DolphinView::Sorting). */
274 Sorting
sorting() const;
276 /** Sets the sort order (Qt::Ascending or Qt::Descending) for the items. */
277 void setSortOrder(Qt::SortOrder order
);
279 /** Returns the current used sort order (Qt::Ascending or Qt::Descending). */
280 Qt::SortOrder
sortOrder() const;
282 /** Sets the additional information which should be shown for the items. */
283 void setAdditionalInfo(KFileItemDelegate::InformationList info
);
285 /** Returns the additional information which should be shown for the items. */
286 KFileItemDelegate::InformationList
additionalInfo() const;
288 /** Reloads the current directory. */
292 * Refreshes the view to get synchronized with the (updated) Dolphin settings.
293 * This method only needs to get invoked if the view settings for the Icons View,
294 * Details View or Columns View have been changed.
299 * Changes the directory of the view to \a url. If \a rootUrl is empty, the view
300 * properties from \a url are used for adjusting the view mode and the other properties.
301 * If \a rootUrl is not empty, the view properties from the root URL are considered
302 * instead. Specifying a root URL is only required if a view having a different root URL
303 * (e. g. the column view) should be restored. Usually using DolphinView::setUrl()
304 * is enough for changing the current URL.
306 void updateView(const KUrl
& url
, const KUrl
& rootUrl
);
309 * Filters the currently shown items by \a nameFilter. All items
310 * which contain the given filter string will be shown.
312 void setNameFilter(const QString
& nameFilter
);
315 * Calculates the number of currently shown files into
316 * \a fileCount and the number of folders into \a folderCount.
317 * It is recommend using this method instead of asking the
318 * directory lister or the model directly, as it takes
319 * filtering and hierarchical previews into account.
321 void calculateItemCount(int& fileCount
, int& folderCount
);
324 * Returns the "switch to icons mode" action.
325 * This code is here to share it between the mainwindow and the part
327 static KToggleAction
* iconsModeAction(KActionCollection
* collection
);
330 * Returns the "switch to details mode" action.
331 * This code is here to share it between the mainwindow and the part
333 static KToggleAction
* detailsModeAction(KActionCollection
* collection
);
336 * Returns the "switch to columns mode" action.
337 * This code is here to share it between the mainwindow and the part
339 static KToggleAction
* columnsModeAction(KActionCollection
* collection
);
342 * Returns the action name corresponding to the current view mode
344 QString
currentViewModeActionName() const;
348 * Changes the directory to \a url. If the current directory is equal to
349 * \a url, nothing will be done (use DolphinView::reload() instead).
351 void setUrl(const KUrl
& url
);
354 * Request of a selection change. The view will do its best to accommodate
355 * the request, but it is not guaranteed that all items in \a selection
356 * will actually get selected. The view will e.g. not select items which
357 * are not in the currently displayed folder.
359 void changeSelection(const KFileItemList
& selection
);
364 * Is emitted if the view has been activated by e. g. a mouse click.
368 /** Is emitted if URL of the view has been changed to \a url. */
369 void urlChanged(const KUrl
& url
);
372 * Is emitted when clicking on an item
374 void itemTriggered(const KFileItem
& item
);
377 * Is emitted if the view mode (IconsView, DetailsView,
378 * PreviewsView) has been changed.
382 /** Is emitted if the 'show preview' property has been changed. */
383 void showPreviewChanged();
385 /** Is emitted if the 'show hidden files' property has been changed. */
386 void showHiddenFilesChanged();
388 /** Is emitted if the 'categorized sorting' property has been changed. */
389 void categorizedSortingChanged();
391 /** Is emitted if the sorting by name, size or date has been changed. */
392 void sortingChanged(DolphinView::Sorting sorting
);
394 /** Is emitted if the sort order (ascending or descending) has been changed. */
395 void sortOrderChanged(Qt::SortOrder order
);
397 /** Is emitted if the additional information for an item has been changed. */
398 void additionalInfoChanged(const KFileItemDelegate::InformationList
& info
);
401 * Is emitted if information of an item is requested to be shown e. g. in the sidebar.
402 * If item is null, no item information request is pending.
404 void requestItemInfo(const KFileItem
& item
);
406 /** Is emitted if the contents has been moved to \a x, \a y. */
407 void contentsMoved(int x
, int y
);
410 * Is emitted whenever the selection has been changed.
412 void selectionChanged(const KFileItemList
& selection
);
415 * Is emitted if a context menu is requested for the item \a item,
416 * which is part of \a url. If the item is 0, the context menu
417 * for the URL should be shown.
419 void requestContextMenu(const KFileItem
& item
, const KUrl
& url
);
422 * Is emitted if the URLs \a are dropped to the destination URL
423 * \a destination. No operation is done within the DolphinView, the
424 * receiver of the signal has to take care about the corresponding
427 void urlsDropped(const KUrl::List
& urls
, const KUrl
& destination
);
430 * Is emitted if an information message with the content \a msg
433 void infoMessage(const QString
& msg
);
436 * Is emitted if an error message with the content \a msg
439 void errorMessage(const QString
& msg
);
442 * Is emitted after DolphinView::setUrl() has been invoked and
443 * the path \a url is currently loaded. If this signal is emitted,
444 * it is assured that the view contains already the correct root
445 * URL and property settings.
447 void startedPathLoading(const KUrl
& url
);
450 /** @see QWidget::mouseReleaseEvent */
451 virtual void mouseReleaseEvent(QMouseEvent
* event
);
455 * Marks the view as active (DolphinView:isActive() will return true)
456 * and emits the 'activated' signal if it is not already active.
461 * If the item \a item is a directory, then this
462 * directory will be loaded. If the item is a file, the corresponding
463 * application will get started.
465 void triggerItem(const KFileItem
& index
);
468 * Generates a preview image for each file item in \a items.
469 * The current preview settings (maximum size, 'Show Preview' menu)
472 void generatePreviews(const KFileItemList
& items
);
475 * Replaces the icon of the item \a item by the preview pixmap
478 void showPreview(const KFileItem
& item
, const QPixmap
& pixmap
);
480 void emitSelectionChangedSignal();
483 * Opens the context menu on position \a pos. The position
484 * is used to check whether the context menu is related to an
485 * item or to the viewport.
487 void openContextMenu(const QPoint
& pos
);
490 * Drops the URLs \a urls to the destination path \a destPath. If
491 * the URLs are dropped above an item inside the destination path,
492 * the item is indicated by \a destItem.
494 void dropUrls(const KUrl::List
& urls
,
495 const KUrl
& destPath
,
496 const KFileItem
& destItem
);
499 * Drops the URLs \a urls at the
500 * destination \a destination.
502 void dropUrls(const KUrl::List
& urls
,
503 const KUrl
& destination
);
505 * Updates the view properties of the current URL to the
506 * sorting given by \a sorting.
508 void updateSorting(DolphinView::Sorting sorting
);
511 * Updates the view properties of the current URL to the
512 * sort order given by \a order.
514 void updateSortOrder(Qt::SortOrder order
);
517 * Updates the view properties of the current URL to the
518 * additional informations given by \a info.
520 void updateAdditionalInfo(const KFileItemDelegate::InformationList
& info
);
523 * Emits the signal contentsMoved with the current coordinates
524 * of the viewport as parameters.
526 void emitContentsMoved();
528 /** Applies an item effect to all cut items of the clipboard. */
529 void updateCutItems();
532 * Updates the status bar to show hover information for the
533 * item \a item. If currently other items are selected,
534 * no hover information is shown.
535 * @see DolphinView::clearHoverInformation()
537 void showHoverInformation(const KFileItem
& item
);
540 * Clears the hover information shown in the status bar.
541 * @see DolphinView::showHoverInformation().
543 void clearHoverInformation();
546 void loadDirectory(const KUrl
& url
, bool reload
= false);
549 * Returns the URL where the view properties should be stored. Usually
550 * DolphinView::url() is returned, but in the case of a Column View the
551 * view properties are always stored in the directory represented by the
552 * first column. It is recommendend whenever using the ViewProperties class
553 * to use DolphinView::viewPropertiesUrl() as URL.
555 KUrl
viewPropertiesUrl() const;
558 * Applies the view properties which are defined by the current URL
559 * m_url to the DolphinView properties.
561 void applyViewProperties(const KUrl
& url
);
564 * Creates a new view representing the given view mode (DolphinView::mode()).
565 * The current view will get deleted.
570 * Returns a pointer to the currently used item view, which is either
571 * a ListView or a TreeView.
573 QAbstractItemView
* itemView() const;
576 * Returns true, if the item \a item has been cut into
579 bool isCutItem(const KFileItem
& item
) const;
581 /** Applies an item effect to all cut items. */
582 void applyCutItemEffect();
585 * Returns true, if the ColumnView is activated. As the column view
586 * requires some special handling for iterating through directories,
587 * this method has been introduced for convenience.
589 bool isColumnViewActive() const
591 return m_columnView
!= 0;
596 * Remembers the original pixmap for an item before
597 * the cut effect is applied.
607 bool m_loadingDirectory
;
608 bool m_storedCategorizedSorting
;
611 DolphinMainWindow
* m_mainWindow
;
612 QVBoxLayout
* m_topLayout
;
614 DolphinController
* m_controller
;
615 DolphinIconsView
* m_iconsView
;
616 DolphinDetailsView
* m_detailsView
;
617 DolphinColumnView
* m_columnView
;
618 KFileItemDelegate
* m_fileItemDelegate
;
620 DolphinModel
* m_dolphinModel
;
621 KDirLister
* m_dirLister
;
622 DolphinSortFilterProxyModel
* m_proxyModel
;
624 QList
<CutItem
> m_cutItemsCache
;
629 /// Allow using DolphinView::Mode in QVariant
630 Q_DECLARE_METATYPE(DolphinView::Mode
)
632 #endif // DOLPHINVIEW_H