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>
44 class DolphinController
;
46 class KFileItemDelegate
;
49 class DolphinColumnView
;
50 class DolphinDetailsView
;
51 class DolphinIconsView
;
52 class DolphinMainWindow
;
53 class DolphinSortFilterProxyModel
;
62 * @short Represents a view for the directory content.
64 * View modes for icons, details and columns are supported. It's
71 * @see DolphinIconsView
72 * @see DolphinDetailsView
73 * @see DolphinColumnView
75 class LIBDOLPHINPRIVATE_EXPORT DolphinView
: public QWidget
81 * Defines the view mode for a directory. The view mode
82 * can be defined when constructing a DolphinView. The
83 * view mode is automatically updated if the directory itself
84 * defines a view mode (see class ViewProperties for details).
89 * The directory items are shown as icons including an
94 * The icon, the name and at least the size of the directory
95 * items are shown in a table. It is possible to add columns
96 * for date, group and permissions.
101 * Each folder is shown in a separate column.
104 MaxModeEnum
= ColumnView
107 /** Defines the sort order for the items of a directory. */
119 MaxSortEnum
= SortByTags
123 * @param parent Parent widget of the view.
124 * @param url Specifies the content which should be shown.
125 * @param dirLister Used directory lister. The lister is not owned
126 * by the view and won't get deleted.
127 * @param dolphinModel Used directory model. The model is not owned
128 * by the view and won't get deleted.
129 * @param proxyModel Used proxy model which specifies the sorting. The
130 * model is not owned by the view and won't get
133 DolphinView(QWidget
* parent
,
135 KDirLister
* dirLister
,
136 DolphinModel
* dolphinModel
,
137 DolphinSortFilterProxyModel
* proxyModel
);
139 virtual ~DolphinView();
142 * Returns the current active URL, where all actions are applied.
143 * The URL navigator is synchronized with this URL.
145 const KUrl
& url() const;
148 * Returns the root URL of the view, which is defined as the first
149 * visible path of DolphinView::url(). Usually the root URL is
150 * equal to DolphinView::url(), but in the case of the column view
151 * when 2 columns are shown, the root URL might be:
152 * /home/peter/Documents
153 * and DolphinView::url() might return
154 * /home/peter/Documents/Music/
156 KUrl
rootUrl() const;
159 * If \a active is true, the view will marked as active. The active
160 * view is defined as view where all actions are applied to.
162 void setActive(bool active
);
163 bool isActive() const;
166 * Changes the view mode for the current directory to \a mode.
167 * If the view properties should be remembered for each directory
168 * (GeneralSettings::globalViewProps() returns false), then the
169 * changed view mode will be stored automatically.
171 void setMode(Mode mode
);
174 /** See setShowPreview */
175 bool showPreview() const;
177 /** See setShowHiddenFiles */
178 bool showHiddenFiles() const;
180 /** See setCategorizedSorting */
181 bool categorizedSorting() const;
184 * Returns true, if the categorized sorting is supported by the current
185 * used mode (see DolphinView::setMode()). Currently only DolphinView::IconsView
186 * supports categorizations. To check whether the categorized
187 * sorting is set, use DolphinView::categorizedSorting().
189 bool supportsCategorizedSorting() const;
193 * @see DolphinView::selectedItems()
198 * Inverts the current selection: selected items get unselected,
199 * unselected items get selected.
200 * @see DolphinView::selectedItems()
202 void invertSelection();
204 /** Returns true, if at least one item is selected. */
205 bool hasSelection() const;
207 void clearSelection();
210 * Returns the selected items. The list is empty if no item has been
212 * @see DolphinView::selectedUrls()
214 KFileItemList
selectedItems() const;
217 * Returns a list of URLs for all selected items. An empty list
218 * is returned, if no item is selected.
219 * @see DolphinView::selectedItems()
221 KUrl::List
selectedUrls() const;
224 * Returns the file item for the given model index \a index.
226 KFileItem
fileItem(const QModelIndex
& index
) 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;
238 /** Increases the size of the current set view mode. */
241 /** Decreases the size of the current set view mode. */
245 * Returns true, if zooming in is possible. If false is returned,
246 * the minimal zoom size is possible.
248 bool isZoomInPossible() const;
251 * Returns true, if zooming out is possible. If false is returned,
252 * the maximum zoom size is possible.
254 bool isZoomOutPossible() const;
256 /** Sets the sort order of the items inside a directory (see DolphinView::Sorting). */
257 void setSorting(Sorting sorting
);
259 /** Returns the sort order of the items inside a directory (see DolphinView::Sorting). */
260 Sorting
sorting() const;
262 /** Sets the sort order (Qt::Ascending or Qt::Descending) for the items. */
263 void setSortOrder(Qt::SortOrder order
);
265 /** Returns the current used sort order (Qt::Ascending or Qt::Descending). */
266 Qt::SortOrder
sortOrder() const;
268 /** Sets the additional information which should be shown for the items. */
269 void setAdditionalInfo(KFileItemDelegate::InformationList info
);
271 /** Returns the additional information which should be shown for the items. */
272 KFileItemDelegate::InformationList
additionalInfo() const;
274 /** Reloads the current directory. */
278 * Refreshes the view to get synchronized with the (updated) Dolphin settings.
279 * This method only needs to get invoked if the view settings for the Icons View,
280 * Details View or Columns View have been changed.
285 * Changes the directory of the view to \a url. If \a rootUrl is empty, the view
286 * properties from \a url are used for adjusting the view mode and the other properties.
287 * If \a rootUrl is not empty, the view properties from the root URL are considered
288 * instead. Specifying a root URL is only required if a view having a different root URL
289 * (e. g. the column view) should be restored. Usually using DolphinView::setUrl()
290 * is enough for changing the current URL.
292 void updateView(const KUrl
& url
, const KUrl
& rootUrl
);
295 * Filters the currently shown items by \a nameFilter. All items
296 * which contain the given filter string will be shown.
298 void setNameFilter(const QString
& nameFilter
);
301 * Calculates the number of currently shown files into
302 * \a fileCount and the number of folders into \a folderCount.
303 * It is recommend using this method instead of asking the
304 * directory lister or the model directly, as it takes
305 * filtering and hierarchical previews into account.
307 void calculateItemCount(int& fileCount
, int& folderCount
);
310 * Returns the "switch to icons mode" action.
311 * This code is here to share it between the mainwindow and the part
313 static KToggleAction
* iconsModeAction(KActionCollection
* collection
);
316 * Returns the "switch to details mode" action.
317 * This code is here to share it between the mainwindow and the part
319 static KToggleAction
* detailsModeAction(KActionCollection
* collection
);
322 * Returns the "switch to columns mode" action.
323 * This code is here to share it between the mainwindow and the part
325 static KToggleAction
* columnsModeAction(KActionCollection
* collection
);
328 * Updates the state of the 'Additional Information' actions in \a collection.
330 void updateAdditionalInfoActions(KActionCollection
* collection
);
333 * Returns the action name corresponding to the current view mode
335 QString
currentViewModeActionName() const;
338 * Returns the state of the paste action:
339 * first is whether the action should be enabled
340 * second is the text for the action
342 QPair
<bool, QString
> pasteInfo() const;
346 * Changes the directory to \a url. If the current directory is equal to
347 * \a url, nothing will be done (use DolphinView::reload() instead).
349 void setUrl(const KUrl
& url
);
352 * Request of a selection change. The view will do its best to accommodate
353 * the request, but it is not guaranteed that all items in \a selection
354 * will actually get selected. The view will e.g. not select items which
355 * are not in the currently displayed folder.
357 void changeSelection(const KFileItemList
& selection
);
360 * Triggers the renaming of the currently selected items, where
361 * the user must input a new name for the items.
363 void renameSelectedItems();
366 * Moves all selected items to the trash.
368 void trashSelectedItems();
371 * Deletes all selected items.
373 void deleteSelectedItems();
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. */
388 * Turns on the file preview for the all files of the current directory,
389 * if \a show is true.
390 * If the view properties should be remembered for each directory
391 * (GeneralSettings::globalViewProps() returns false), then the
392 * preview setting will be stored automatically.
394 void setShowPreview(bool show
);
397 * Shows all hidden files of the current directory,
398 * if \a show is true.
399 * If the view properties should be remembered for each directory
400 * (GeneralSettings::globalViewProps() returns false), then the
401 * show hidden file setting will be stored automatically.
403 void setShowHiddenFiles(bool show
);
406 * Summarizes all sorted items by their category \a categorized
408 * If the view properties should be remembered for each directory
409 * (GeneralSettings::globalViewProps() returns false), then the
410 * categorized sorting setting will be stored automatically.
412 void setCategorizedSorting(bool categorized
);
414 /** Switches between an ascending and descending sorting order. */
415 void toggleSortOrder();
418 * Switches on or off the displaying of additional information
419 * as specified by \a action.
421 void toggleAdditionalInfo(QAction
* action
);
425 * Is emitted if the view has been activated by e. g. a mouse click.
429 /** Is emitted if URL of the view has been changed to \a url. */
430 void urlChanged(const KUrl
& url
);
433 * Is emitted when clicking on an item
435 void itemTriggered(const KFileItem
& item
);
438 * Is emitted if the view mode (IconsView, DetailsView,
439 * PreviewsView) has been changed.
443 /** Is emitted if the 'show preview' property has been changed. */
444 void showPreviewChanged();
446 /** Is emitted if the 'show hidden files' property has been changed. */
447 void showHiddenFilesChanged();
449 /** Is emitted if the 'categorized sorting' property has been changed. */
450 void categorizedSortingChanged();
452 /** Is emitted if the sorting by name, size or date has been changed. */
453 void sortingChanged(DolphinView::Sorting sorting
);
455 /** Is emitted if the sort order (ascending or descending) has been changed. */
456 void sortOrderChanged(Qt::SortOrder order
);
458 /** Is emitted if the additional information shown for this view has been changed. */
459 void additionalInfoChanged();
462 * Is emitted if information of an item is requested to be shown e. g. in the sidebar.
463 * If item is null, no item information request is pending.
465 void requestItemInfo(const KFileItem
& item
);
467 /** Is emitted if the contents has been moved to \a x, \a y. */
468 void contentsMoved(int x
, int y
);
471 * Is emitted whenever the selection has been changed.
473 void selectionChanged(const KFileItemList
& selection
);
476 * Is emitted if a context menu is requested for the item \a item,
477 * which is part of \a url. If the item is 0, the context menu
478 * for the URL should be shown.
480 void requestContextMenu(const KFileItem
& item
, const KUrl
& url
);
483 * Is emitted if an information message with the content \a msg
486 void infoMessage(const QString
& msg
);
489 * Is emitted if an error message with the content \a msg
492 void errorMessage(const QString
& msg
);
495 * Is emitted if an "operation completed" message with the content \a msg
498 void operationCompletedMessage(const QString
& msg
);
501 * Is emitted after DolphinView::setUrl() has been invoked and
502 * the path \a url is currently loaded. If this signal is emitted,
503 * it is assured that the view contains already the correct root
504 * URL and property settings.
506 void startedPathLoading(const KUrl
& url
);
509 * Is emitted when renaming, copying, moving, linking etc.
510 * Used for feedback in the mainwindow.
512 void doingOperation(KonqFileUndoManager::CommandType type
);
515 /** @see QWidget::mouseReleaseEvent */
516 virtual void mouseReleaseEvent(QMouseEvent
* event
);
520 * Marks the view as active (DolphinView:isActive() will return true)
521 * and emits the 'activated' signal if it is not already active.
526 * If the item \a item is a directory, then this
527 * directory will be loaded. If the item is a file, the corresponding
528 * application will get started.
530 void triggerItem(const KFileItem
& index
);
533 * Generates a preview image for each file item in \a items.
534 * The current preview settings (maximum size, 'Show Preview' menu)
537 void generatePreviews(const KFileItemList
& items
);
540 * Replaces the icon of the item \a item by the preview pixmap
543 void replaceIcon(const KFileItem
& item
, const QPixmap
& pixmap
);
545 void emitSelectionChangedSignal();
548 * Opens the context menu on position \a pos. The position
549 * is used to check whether the context menu is related to an
550 * item or to the viewport.
552 void openContextMenu(const QPoint
& pos
);
555 * Drops the URLs \a urls to the destination path \a destPath. If
556 * the URLs are dropped above an item inside the destination path,
557 * the item is indicated by \a destItem.
559 void dropUrls(const KUrl::List
& urls
,
560 const KUrl
& destPath
,
561 const KFileItem
& destItem
);
564 * Handles the dropping of URLs to the given destination.
565 * @see DolphinDropController
567 void dropUrls(const KUrl::List
& urls
,
568 const KUrl
& destination
);
570 * Updates the view properties of the current URL to the
571 * sorting given by \a sorting.
573 void updateSorting(DolphinView::Sorting sorting
);
576 * Updates the view properties of the current URL to the
577 * sort order given by \a order.
579 void updateSortOrder(Qt::SortOrder order
);
582 * Updates the view properties of the current URL to the
583 * additional information given by \a info.
585 void updateAdditionalInfo(const KFileItemDelegate::InformationList
& info
);
588 * Emits the signal contentsMoved with the current coordinates
589 * of the viewport as parameters.
591 void emitContentsMoved();
593 /** Applies an item effect to all cut items of the clipboard. */
594 void updateCutItems();
597 * Updates the status bar to show hover information for the
598 * item \a item. If currently other items are selected,
599 * no hover information is shown.
600 * @see DolphinView::clearHoverInformation()
602 void showHoverInformation(const KFileItem
& item
);
605 * Clears the hover information shown in the status bar.
606 * @see DolphinView::showHoverInformation().
608 void clearHoverInformation();
611 * Indicates in the status bar that the delete operation
612 * of the job \a job has been finished.
614 void slotDeleteFileFinished(KJob
* job
);
617 * Is invoked when the preview job has been finished and
618 * set m_previewJob to 0.
620 void slotPreviewJobFinished(KJob
* job
);
623 void loadDirectory(const KUrl
& url
, bool reload
= false);
626 * Returns the URL where the view properties should be stored. Usually
627 * DolphinView::url() is returned, but in the case of a Column View the
628 * view properties are always stored in the directory represented by the
629 * first column. It is recommendend whenever using the ViewProperties class
630 * to use DolphinView::viewPropertiesUrl() as URL.
632 KUrl
viewPropertiesUrl() const;
635 * Applies the view properties which are defined by the current URL
636 * m_url to the DolphinView properties.
638 void applyViewProperties(const KUrl
& url
);
641 * Creates a new view representing the given view mode (DolphinView::mode()).
642 * The current view will get deleted.
649 * Returns a pointer to the currently used item view, which is either
650 * a ListView or a TreeView.
652 QAbstractItemView
* itemView() const;
655 * Returns true, if the item \a item has been cut into
658 bool isCutItem(const KFileItem
& item
) const;
660 /** Applies an item effect to all cut items. */
661 void applyCutItemEffect();
664 * Returns true, if the ColumnView is activated. As the column view
665 * requires some special handling for iterating through directories,
666 * this method has been introduced for convenience.
668 bool isColumnViewActive() const
670 return m_columnView
!= 0;
675 * Remembers the original pixmap for an item before
676 * the cut effect is applied.
686 bool m_loadingDirectory
;
687 bool m_storedCategorizedSorting
;
690 DolphinMainWindow
* m_mainWindow
;
691 QVBoxLayout
* m_topLayout
;
693 DolphinController
* m_controller
;
694 DolphinIconsView
* m_iconsView
;
695 DolphinDetailsView
* m_detailsView
;
696 DolphinColumnView
* m_columnView
;
697 KFileItemDelegate
* m_fileItemDelegate
;
698 QItemSelectionModel
* m_selectionModel
;
700 DolphinModel
* m_dolphinModel
;
701 KDirLister
* m_dirLister
;
702 DolphinSortFilterProxyModel
* m_proxyModel
;
704 KIO::PreviewJob
* m_previewJob
;
706 QList
<CutItem
> m_cutItemsCache
;
711 /// Allow using DolphinView::Mode in QVariant
712 Q_DECLARE_METATYPE(DolphinView::Mode
)
714 #endif // DOLPHINVIEW_H