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 <konq_fileundomanager.h>
37 #include <QLinkedList>
42 class DolphinController
;
44 class KFileItemDelegate
;
47 class DolphinColumnView
;
48 class DolphinDetailsView
;
49 class DolphinIconsView
;
50 class DolphinMainWindow
;
51 class DolphinSortFilterProxyModel
;
56 * @short Represents a view for the directory content.
58 * View modes for icons, details and columns are supported. It's
65 * @see DolphinIconsView
66 * @see DolphinDetailsView
67 * @see DolphinColumnView
69 class LIBDOLPHINPRIVATE_EXPORT DolphinView
: public QWidget
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).
83 * The directory items are shown as icons including an
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.
95 * Each folder is shown in a separate column.
98 MaxModeEnum
= ColumnView
101 /** Defines the sort order for the items of a directory. */
113 MaxSortEnum
= SortByTags
117 * @param parent Parent widget of the view.
118 * @param url Specifies the content which should be shown.
119 * @param dirLister Used directory lister. The lister is not owned
120 * by the view and won't get deleted.
121 * @param dolphinModel Used directory model. The model is not owned
122 * by the view and won't get deleted.
123 * @param proxyModel Used proxy model which specifies the sorting. The
124 * model is not owned by the view and won't get
127 DolphinView(QWidget
* parent
,
129 KDirLister
* dirLister
,
130 DolphinModel
* dolphinModel
,
131 DolphinSortFilterProxyModel
* proxyModel
);
133 virtual ~DolphinView();
136 * Returns the current active URL, where all actions are applied.
137 * The URL navigator is synchronized with this URL.
139 const KUrl
& url() const;
142 * Returns the root URL of the view, which is defined as the first
143 * visible path of DolphinView::url(). Usually the root URL is
144 * equal to DolphinView::url(), but in the case of the column view
145 * when 2 columns are shown, the root URL might be:
146 * /home/peter/Documents
147 * and DolphinView::url() might return
148 * /home/peter/Documents/Music/
150 KUrl
rootUrl() const;
153 * If \a active is true, the view will marked as active. The active
154 * view is defined as view where all actions are applied to.
156 void setActive(bool active
);
157 bool isActive() const;
160 * Changes the view mode for the current directory to \a mode.
161 * If the view properties should be remembered for each directory
162 * (GeneralSettings::globalViewProps() returns false), then the
163 * changed view mode will be be stored automatically.
165 void setMode(Mode mode
);
169 * Turns on the file preview for the all files of the current directory,
170 * if \a show is true.
171 * If the view properties should be remembered for each directory
172 * (GeneralSettings::globalViewProps() returns false), then the
173 * preview setting will be be stored automatically.
175 void setShowPreview(bool show
);
176 bool showPreview() const;
179 * Shows all hidden files of the current directory,
180 * if \a show is true.
181 * If the view properties should be remembered for each directory
182 * (GeneralSettings::globalViewProps() returns false), then the
183 * show hidden file setting will be be stored automatically.
185 void setShowHiddenFiles(bool show
);
186 bool showHiddenFiles() const;
189 * Summarizes all sorted items by their category \a categorized
191 * If the view properties should be remembered for each directory
192 * (GeneralSettings::globalViewProps() returns false), then the
193 * categorized sorting setting will be be stored automatically.
195 void setCategorizedSorting(bool categorized
);
196 bool categorizedSorting() const;
199 * Returns true, if the categorized sorting is supported by the current
200 * used mode (see DolphinView::setMode()). Currently only DolphinView::IconsView
201 * supports categorizations. To check whether the categorized
202 * sorting is set, use DolphinView::categorizedSorting().
204 bool supportsCategorizedSorting() const;
208 * @see DolphinView::selectedItems()
213 * Inverts the current selection: selected items get unselected,
214 * unselected items get selected.
215 * @see DolphinView::selectedItems()
217 void invertSelection();
219 /** Returns true, if at least one item is selected. */
220 bool hasSelection() const;
222 void clearSelection();
225 * Returns the selected items. The list is empty if no item has been
227 * @see DolphinView::selectedUrls()
229 KFileItemList
selectedItems() const;
232 * Returns a list of URLs for all selected items. An empty list
233 * is returned, if no item is selected.
234 * @see DolphinView::selectedItems()
236 KUrl::List
selectedUrls() const;
239 * Returns the file item for the given model index \a index.
241 KFileItem
fileItem(const QModelIndex
& index
) const;
244 * Sets the upper left position of the view content
245 * to (x,y). The content of the view might be larger than the visible area
246 * and hence a scrolling must be done.
248 void setContentsPosition(int x
, int y
);
250 /** Returns the upper left position of the view content. */
251 QPoint
contentsPosition() const;
253 /** Increases the size of the current set view mode. */
256 /** Decreases the size of the current set view mode. */
260 * Returns true, if zooming in is possible. If false is returned,
261 * the minimal zoom size is possible.
263 bool isZoomInPossible() const;
266 * Returns true, if zooming out is possible. If false is returned,
267 * the maximum zoom size is possible.
269 bool isZoomOutPossible() const;
271 /** Sets the sort order of the items inside a directory (see DolphinView::Sorting). */
272 void setSorting(Sorting sorting
);
274 /** Returns the sort order of the items inside a directory (see DolphinView::Sorting). */
275 Sorting
sorting() const;
277 /** Sets the sort order (Qt::Ascending or Qt::Descending) for the items. */
278 void setSortOrder(Qt::SortOrder order
);
280 /** Returns the current used sort order (Qt::Ascending or Qt::Descending). */
281 Qt::SortOrder
sortOrder() const;
283 /** Sets the additional information which should be shown for the items. */
284 void setAdditionalInfo(KFileItemDelegate::InformationList info
);
286 /** Returns the additional information which should be shown for the items. */
287 KFileItemDelegate::InformationList
additionalInfo() const;
289 /** Reloads the current directory. */
293 * Refreshes the view to get synchronized with the (updated) Dolphin settings.
294 * This method only needs to get invoked if the view settings for the Icons View,
295 * Details View or Columns View have been changed.
300 * Changes the directory of the view to \a url. If \a rootUrl is empty, the view
301 * properties from \a url are used for adjusting the view mode and the other properties.
302 * If \a rootUrl is not empty, the view properties from the root URL are considered
303 * instead. Specifying a root URL is only required if a view having a different root URL
304 * (e. g. the column view) should be restored. Usually using DolphinView::setUrl()
305 * is enough for changing the current URL.
307 void updateView(const KUrl
& url
, const KUrl
& rootUrl
);
310 * Filters the currently shown items by \a nameFilter. All items
311 * which contain the given filter string will be shown.
313 void setNameFilter(const QString
& nameFilter
);
316 * Calculates the number of currently shown files into
317 * \a fileCount and the number of folders into \a folderCount.
318 * It is recommend using this method instead of asking the
319 * directory lister or the model directly, as it takes
320 * filtering and hierarchical previews into account.
322 void calculateItemCount(int& fileCount
, int& folderCount
);
325 * Returns the "switch to icons mode" action.
326 * This code is here to share it between the mainwindow and the part
328 static KToggleAction
* iconsModeAction(KActionCollection
* collection
);
331 * Returns the "switch to details mode" action.
332 * This code is here to share it between the mainwindow and the part
334 static KToggleAction
* detailsModeAction(KActionCollection
* collection
);
337 * Returns the "switch to columns mode" action.
338 * This code is here to share it between the mainwindow and the part
340 static KToggleAction
* columnsModeAction(KActionCollection
* collection
);
343 * Returns the action name corresponding to the current view mode
345 QString
currentViewModeActionName() const;
348 * Returns the state of the paste action:
349 * first is whether the action should be enabled
350 * second is the text for the action
352 QPair
<bool, QString
> pasteInfo() const;
356 * Changes the directory to \a url. If the current directory is equal to
357 * \a url, nothing will be done (use DolphinView::reload() instead).
359 void setUrl(const KUrl
& url
);
362 * Request of a selection change. The view will do its best to accommodate
363 * the request, but it is not guaranteed that all items in \a selection
364 * will actually get selected. The view will e.g. not select items which
365 * are not in the currently displayed folder.
367 void changeSelection(const KFileItemList
& selection
);
370 * Triggers the renaming of the currently selected items, where
371 * the user must input a new name for the items.
373 void renameSelectedItems();
376 * Copies all selected items to the clipboard and marks
377 * the items as cutted.
379 void cutSelectedItems();
381 /** Copies all selected items to the clipboard. */
382 void copySelectedItems();
384 /** Pastes the clipboard data to this view. */
389 * Is emitted if the view has been activated by e. g. a mouse click.
393 /** Is emitted if URL of the view has been changed to \a url. */
394 void urlChanged(const KUrl
& url
);
397 * Is emitted when clicking on an item
399 void itemTriggered(const KFileItem
& item
);
402 * Is emitted if the view mode (IconsView, DetailsView,
403 * PreviewsView) has been changed.
407 /** Is emitted if the 'show preview' property has been changed. */
408 void showPreviewChanged();
410 /** Is emitted if the 'show hidden files' property has been changed. */
411 void showHiddenFilesChanged();
413 /** Is emitted if the 'categorized sorting' property has been changed. */
414 void categorizedSortingChanged();
416 /** Is emitted if the sorting by name, size or date has been changed. */
417 void sortingChanged(DolphinView::Sorting sorting
);
419 /** Is emitted if the sort order (ascending or descending) has been changed. */
420 void sortOrderChanged(Qt::SortOrder order
);
422 /** Is emitted if the additional information for an item has been changed. */
423 void additionalInfoChanged(const KFileItemDelegate::InformationList
& info
);
426 * Is emitted if information of an item is requested to be shown e. g. in the sidebar.
427 * If item is null, no item information request is pending.
429 void requestItemInfo(const KFileItem
& item
);
431 /** Is emitted if the contents has been moved to \a x, \a y. */
432 void contentsMoved(int x
, int y
);
435 * Is emitted whenever the selection has been changed.
437 void selectionChanged(const KFileItemList
& selection
);
440 * Is emitted if a context menu is requested for the item \a item,
441 * which is part of \a url. If the item is 0, the context menu
442 * for the URL should be shown.
444 void requestContextMenu(const KFileItem
& item
, const KUrl
& url
);
447 * Is emitted if the URLs \a are dropped to the destination URL
448 * \a destination. No operation is done within the DolphinView, the
449 * receiver of the signal has to take care about the corresponding
452 void urlsDropped(const KUrl::List
& urls
, const KUrl
& destination
);
455 * Is emitted if an information message with the content \a msg
458 void infoMessage(const QString
& msg
);
461 * Is emitted if an error message with the content \a msg
464 void errorMessage(const QString
& msg
);
467 * Is emitted after DolphinView::setUrl() has been invoked and
468 * the path \a url is currently loaded. If this signal is emitted,
469 * it is assured that the view contains already the correct root
470 * URL and property settings.
472 void startedPathLoading(const KUrl
& url
);
475 * Is emitted when renaming, copying, moving, linking etc.
476 * Used for feedback in the mainwindow.
478 void doingOperation(KonqFileUndoManager::CommandType type
);
481 /** @see QWidget::mouseReleaseEvent */
482 virtual void mouseReleaseEvent(QMouseEvent
* event
);
486 * Marks the view as active (DolphinView:isActive() will return true)
487 * and emits the 'activated' signal if it is not already active.
492 * If the item \a item is a directory, then this
493 * directory will be loaded. If the item is a file, the corresponding
494 * application will get started.
496 void triggerItem(const KFileItem
& index
);
499 * Generates a preview image for each file item in \a items.
500 * The current preview settings (maximum size, 'Show Preview' menu)
503 void generatePreviews(const KFileItemList
& items
);
506 * Replaces the icon of the item \a item by the preview pixmap
509 void showPreview(const KFileItem
& item
, const QPixmap
& pixmap
);
511 void emitSelectionChangedSignal();
514 * Opens the context menu on position \a pos. The position
515 * is used to check whether the context menu is related to an
516 * item or to the viewport.
518 void openContextMenu(const QPoint
& pos
);
521 * Drops the URLs \a urls to the destination path \a destPath. If
522 * the URLs are dropped above an item inside the destination path,
523 * the item is indicated by \a destItem.
525 void dropUrls(const KUrl::List
& urls
,
526 const KUrl
& destPath
,
527 const KFileItem
& destItem
);
530 * Drops the URLs \a urls at the
531 * destination \a destination.
533 void dropUrls(const KUrl::List
& urls
,
534 const KUrl
& destination
);
536 * Updates the view properties of the current URL to the
537 * sorting given by \a sorting.
539 void updateSorting(DolphinView::Sorting sorting
);
542 * Updates the view properties of the current URL to the
543 * sort order given by \a order.
545 void updateSortOrder(Qt::SortOrder order
);
548 * Updates the view properties of the current URL to the
549 * additional informations given by \a info.
551 void updateAdditionalInfo(const KFileItemDelegate::InformationList
& info
);
554 * Emits the signal contentsMoved with the current coordinates
555 * of the viewport as parameters.
557 void emitContentsMoved();
559 /** Applies an item effect to all cut items of the clipboard. */
560 void updateCutItems();
563 * Updates the status bar to show hover information for the
564 * item \a item. If currently other items are selected,
565 * no hover information is shown.
566 * @see DolphinView::clearHoverInformation()
568 void showHoverInformation(const KFileItem
& item
);
571 * Clears the hover information shown in the status bar.
572 * @see DolphinView::showHoverInformation().
574 void clearHoverInformation();
577 void loadDirectory(const KUrl
& url
, bool reload
= false);
580 * Returns the URL where the view properties should be stored. Usually
581 * DolphinView::url() is returned, but in the case of a Column View the
582 * view properties are always stored in the directory represented by the
583 * first column. It is recommendend whenever using the ViewProperties class
584 * to use DolphinView::viewPropertiesUrl() as URL.
586 KUrl
viewPropertiesUrl() const;
589 * Applies the view properties which are defined by the current URL
590 * m_url to the DolphinView properties.
592 void applyViewProperties(const KUrl
& url
);
595 * Creates a new view representing the given view mode (DolphinView::mode()).
596 * The current view will get deleted.
603 * Returns a pointer to the currently used item view, which is either
604 * a ListView or a TreeView.
606 QAbstractItemView
* itemView() const;
609 * Returns true, if the item \a item has been cut into
612 bool isCutItem(const KFileItem
& item
) const;
614 /** Applies an item effect to all cut items. */
615 void applyCutItemEffect();
618 * Returns true, if the ColumnView is activated. As the column view
619 * requires some special handling for iterating through directories,
620 * this method has been introduced for convenience.
622 bool isColumnViewActive() const
624 return m_columnView
!= 0;
629 * Remembers the original pixmap for an item before
630 * the cut effect is applied.
640 bool m_loadingDirectory
;
641 bool m_storedCategorizedSorting
;
644 DolphinMainWindow
* m_mainWindow
;
645 QVBoxLayout
* m_topLayout
;
647 DolphinController
* m_controller
;
648 DolphinIconsView
* m_iconsView
;
649 DolphinDetailsView
* m_detailsView
;
650 DolphinColumnView
* m_columnView
;
651 KFileItemDelegate
* m_fileItemDelegate
;
653 DolphinModel
* m_dolphinModel
;
654 KDirLister
* m_dirLister
;
655 DolphinSortFilterProxyModel
* m_proxyModel
;
657 QList
<CutItem
> m_cutItemsCache
;
662 /// Allow using DolphinView::Mode in QVariant
663 Q_DECLARE_METATYPE(DolphinView::Mode
)
665 #endif // DOLPHINVIEW_H