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>
41 class DolphinController
;
42 class DolphinColumnView
;
43 class DolphinDetailsView
;
44 class DolphinIconsView
;
45 class DolphinMainWindow
;
47 class DolphinSortFilterProxyModel
;
51 class KFileItemDelegate
;
58 * @short Represents a view for the directory content.
60 * View modes for icons, details and columns are supported. It's
67 * @see DolphinIconsView
68 * @see DolphinDetailsView
69 * @see DolphinColumnView
71 class LIBDOLPHINPRIVATE_EXPORT DolphinView
: public QWidget
77 * Defines the view mode for a directory. The view mode
78 * can be defined when constructing a DolphinView. The
79 * view mode is automatically updated if the directory itself
80 * defines a view mode (see class ViewProperties for details).
85 * The directory items are shown as icons including an
90 * The icon, the name and at least the size of the directory
91 * items are shown in a table. It is possible to add columns
92 * for date, group and permissions.
97 * Each folder is shown in a separate column.
100 MaxModeEnum
= ColumnView
103 /** Defines the sort order for the items of a directory. */
115 MaxSortEnum
= SortByTags
119 * @param parent Parent widget of the view.
120 * @param url Specifies the content which should be shown.
121 * @param dirLister Used directory lister. The lister is not owned
122 * by the view and won't get deleted.
123 * @param dolphinModel Used directory model. The model is not owned
124 * by the view and won't get deleted.
125 * @param proxyModel Used proxy model which specifies the sorting. The
126 * model is not owned by the view and won't get
129 DolphinView(QWidget
* parent
,
131 KDirLister
* dirLister
,
132 DolphinModel
* dolphinModel
,
133 DolphinSortFilterProxyModel
* proxyModel
);
135 virtual ~DolphinView();
138 * Returns the current active URL, where all actions are applied.
139 * The URL navigator is synchronized with this URL.
141 const KUrl
& url() const;
144 * Returns the root URL of the view, which is defined as the first
145 * visible path of DolphinView::url(). Usually the root URL is
146 * equal to DolphinView::url(), but in the case of the column view
147 * when 2 columns are shown, the root URL might be:
148 * /home/peter/Documents
149 * and DolphinView::url() might return
150 * /home/peter/Documents/Music/
152 KUrl
rootUrl() const;
155 * If \a active is true, the view will marked as active. The active
156 * view is defined as view where all actions are applied to.
158 void setActive(bool active
);
159 bool isActive() const;
162 * Changes the view mode for the current directory to \a mode.
163 * If the view properties should be remembered for each directory
164 * (GeneralSettings::globalViewProps() returns false), then the
165 * changed view mode will be be stored automatically.
167 void setMode(Mode mode
);
171 * Turns on the file preview for the all files of the current directory,
172 * if \a show is true.
173 * If the view properties should be remembered for each directory
174 * (GeneralSettings::globalViewProps() returns false), then the
175 * preview setting will be be stored automatically.
177 void setShowPreview(bool show
);
178 bool showPreview() const;
181 * Shows all hidden files of the current directory,
182 * if \a show is true.
183 * If the view properties should be remembered for each directory
184 * (GeneralSettings::globalViewProps() returns false), then the
185 * show hidden file setting will be be stored automatically.
187 void setShowHiddenFiles(bool show
);
188 bool showHiddenFiles() const;
191 * Summarizes all sorted items by their category \a categorized
193 * If the view properties should be remembered for each directory
194 * (GeneralSettings::globalViewProps() returns false), then the
195 * categorized sorting setting will be be stored automatically.
197 void setCategorizedSorting(bool categorized
);
198 bool categorizedSorting() const;
201 * Returns true, if the categorized sorting is supported by the current
202 * used mode (see DolphinView::setMode()). Currently only DolphinView::IconsView
203 * supports categorizations. To check whether the categorized
204 * sorting is set, use DolphinView::categorizedSorting().
206 bool supportsCategorizedSorting() const;
210 * @see DolphinView::selectedItems()
215 * Inverts the current selection: selected items get unselected,
216 * unselected items get selected.
217 * @see DolphinView::selectedItems()
219 void invertSelection();
221 /** Returns true, if at least one item is selected. */
222 bool hasSelection() const;
224 void clearSelection();
227 * Returns the selected items. The list is empty if no item has been
229 * @see DolphinView::selectedUrls()
231 KFileItemList
selectedItems() const;
234 * Returns a list of URLs for all selected items. An empty list
235 * is returned, if no item is selected.
236 * @see DolphinView::selectedItems()
238 KUrl::List
selectedUrls() const;
241 * Returns the file item for the given model index \a index.
243 KFileItem
fileItem(const QModelIndex
& index
) const;
246 * Sets the upper left position of the view content
247 * to (x,y). The content of the view might be larger than the visible area
248 * and hence a scrolling must be done.
250 void setContentsPosition(int x
, int y
);
252 /** Returns the upper left position of the view content. */
253 QPoint
contentsPosition() const;
255 /** Increases the size of the current set view mode. */
258 /** Decreases the size of the current set view mode. */
262 * Returns true, if zooming in is possible. If false is returned,
263 * the minimal zoom size is possible.
265 bool isZoomInPossible() const;
268 * Returns true, if zooming out is possible. If false is returned,
269 * the maximum zoom size is possible.
271 bool isZoomOutPossible() const;
273 /** Sets the sort order of the items inside a directory (see DolphinView::Sorting). */
274 void setSorting(Sorting sorting
);
276 /** Returns the sort order of the items inside a directory (see DolphinView::Sorting). */
277 Sorting
sorting() const;
279 /** Sets the sort order (Qt::Ascending or Qt::Descending) for the items. */
280 void setSortOrder(Qt::SortOrder order
);
282 /** Returns the current used sort order (Qt::Ascending or Qt::Descending). */
283 Qt::SortOrder
sortOrder() const;
285 /** Sets the additional information which should be shown for the items. */
286 void setAdditionalInfo(KFileItemDelegate::InformationList info
);
288 /** Returns the additional information which should be shown for the items. */
289 KFileItemDelegate::InformationList
additionalInfo() const;
291 /** Reloads the current directory. */
295 * Refreshes the view to get synchronized with the (updated) Dolphin settings.
296 * This method only needs to get invoked if the view settings for the Icons View,
297 * Details View or Columns View have been changed.
302 * Changes the directory of the view to \a url. If \a rootUrl is empty, the view
303 * properties from \a url are used for adjusting the view mode and the other properties.
304 * If \a rootUrl is not empty, the view properties from the root URL are considered
305 * instead. Specifying a root URL is only required if a view having a different root URL
306 * (e. g. the column view) should be restored. Usually using DolphinView::setUrl()
307 * is enough for changing the current URL.
309 void updateView(const KUrl
& url
, const KUrl
& rootUrl
);
312 * Filters the currently shown items by \a nameFilter. All items
313 * which contain the given filter string will be shown.
315 void setNameFilter(const QString
& nameFilter
);
318 * Calculates the number of currently shown files into
319 * \a fileCount and the number of folders into \a folderCount.
320 * It is recommend using this method instead of asking the
321 * directory lister or the model directly, as it takes
322 * filtering and hierarchical previews into account.
324 void calculateItemCount(int& fileCount
, int& folderCount
);
327 * Returns the "switch to icons mode" action.
328 * This code is here to share it between the mainwindow and the part
330 static KToggleAction
* iconsModeAction(KActionCollection
* collection
);
333 * Returns the "switch to details mode" action.
334 * This code is here to share it between the mainwindow and the part
336 static KToggleAction
* detailsModeAction(KActionCollection
* collection
);
339 * Returns the "switch to columns mode" action.
340 * This code is here to share it between the mainwindow and the part
342 static KToggleAction
* columnsModeAction(KActionCollection
* collection
);
345 * Creates the rename action.
346 * This code is here to share it between the mainwindow and the part
348 static KAction
* createRenameAction(KActionCollection
* collection
);
351 * Creates the "move to trash" action.
352 * This code is here to share it between the mainwindow and the part
354 static KAction
* createMoveToTrashAction(KActionCollection
* collection
);
357 * Creates the delete action.
358 * This code is here to share it between the mainwindow and the part
360 static KAction
* createDeleteAction(KActionCollection
* collection
);
363 * Returns the action name corresponding to the current view mode
365 QString
currentViewModeActionName() const;
368 * Returns the state of the paste action:
369 * first is whether the action should be enabled
370 * second is the text for the action
372 QPair
<bool, QString
> pasteInfo() const;
376 * Changes the directory to \a url. If the current directory is equal to
377 * \a url, nothing will be done (use DolphinView::reload() instead).
379 void setUrl(const KUrl
& url
);
382 * Request of a selection change. The view will do its best to accommodate
383 * the request, but it is not guaranteed that all items in \a selection
384 * will actually get selected. The view will e.g. not select items which
385 * are not in the currently displayed folder.
387 void changeSelection(const KFileItemList
& selection
);
390 * Triggers the renaming of the currently selected items, where
391 * the user must input a new name for the items.
393 void renameSelectedItems();
396 * Moves all selected items to the trash.
398 void trashSelectedItems();
401 * Deletes all selected items.
403 void deleteSelectedItems();
406 * Copies all selected items to the clipboard and marks
407 * the items as cutted.
409 void cutSelectedItems();
411 /** Copies all selected items to the clipboard. */
412 void copySelectedItems();
414 /** Pastes the clipboard data to this view. */
419 * Is emitted if the view has been activated by e. g. a mouse click.
423 /** Is emitted if URL of the view has been changed to \a url. */
424 void urlChanged(const KUrl
& url
);
427 * Is emitted when clicking on an item
429 void itemTriggered(const KFileItem
& item
);
432 * Is emitted if the view mode (IconsView, DetailsView,
433 * PreviewsView) has been changed.
437 /** Is emitted if the 'show preview' property has been changed. */
438 void showPreviewChanged();
440 /** Is emitted if the 'show hidden files' property has been changed. */
441 void showHiddenFilesChanged();
443 /** Is emitted if the 'categorized sorting' property has been changed. */
444 void categorizedSortingChanged();
446 /** Is emitted if the sorting by name, size or date has been changed. */
447 void sortingChanged(DolphinView::Sorting sorting
);
449 /** Is emitted if the sort order (ascending or descending) has been changed. */
450 void sortOrderChanged(Qt::SortOrder order
);
452 /** Is emitted if the additional information for an item has been changed. */
453 void additionalInfoChanged(const KFileItemDelegate::InformationList
& info
);
456 * Is emitted if information of an item is requested to be shown e. g. in the sidebar.
457 * If item is null, no item information request is pending.
459 void requestItemInfo(const KFileItem
& item
);
461 /** Is emitted if the contents has been moved to \a x, \a y. */
462 void contentsMoved(int x
, int y
);
465 * Is emitted whenever the selection has been changed.
467 void selectionChanged(const KFileItemList
& selection
);
470 * Is emitted if a context menu is requested for the item \a item,
471 * which is part of \a url. If the item is 0, the context menu
472 * for the URL should be shown.
474 void requestContextMenu(const KFileItem
& item
, const KUrl
& url
);
477 * Is emitted if an information message with the content \a msg
480 void infoMessage(const QString
& msg
);
483 * Is emitted if an error message with the content \a msg
486 void errorMessage(const QString
& msg
);
489 * Is emitted if an "operation completed" message with the content \a msg
492 void operationCompletedMessage(const QString
& msg
);
495 * Is emitted after DolphinView::setUrl() has been invoked and
496 * the path \a url is currently loaded. If this signal is emitted,
497 * it is assured that the view contains already the correct root
498 * URL and property settings.
500 void startedPathLoading(const KUrl
& url
);
503 * Is emitted when renaming, copying, moving, linking etc.
504 * Used for feedback in the mainwindow.
506 void doingOperation(KonqFileUndoManager::CommandType type
);
509 /** @see QWidget::mouseReleaseEvent */
510 virtual void mouseReleaseEvent(QMouseEvent
* event
);
514 * Marks the view as active (DolphinView:isActive() will return true)
515 * and emits the 'activated' signal if it is not already active.
520 * If the item \a item is a directory, then this
521 * directory will be loaded. If the item is a file, the corresponding
522 * application will get started.
524 void triggerItem(const KFileItem
& index
);
526 void emitSelectionChangedSignal();
529 * Opens the context menu on position \a pos. The position
530 * is used to check whether the context menu is related to an
531 * item or to the viewport.
533 void openContextMenu(const QPoint
& pos
);
536 * Drops the URLs \a urls to the destination path \a destPath. If
537 * the URLs are dropped above an item inside the destination path,
538 * the item is indicated by \a destItem.
540 void dropUrls(const KUrl::List
& urls
,
541 const KUrl
& destPath
,
542 const KFileItem
& destItem
);
545 * Handles the dropping of URLs to the given destination.
546 * @see DolphinDropController
548 void dropUrls(const KUrl::List
& urls
,
549 const KUrl
& destination
);
551 * Updates the view properties of the current URL to the
552 * sorting given by \a sorting.
554 void updateSorting(DolphinView::Sorting sorting
);
557 * Updates the view properties of the current URL to the
558 * sort order given by \a order.
560 void updateSortOrder(Qt::SortOrder order
);
563 * Updates the view properties of the current URL to the
564 * additional information given by \a info.
566 void updateAdditionalInfo(const KFileItemDelegate::InformationList
& info
);
569 * Emits the signal contentsMoved with the current coordinates
570 * of the viewport as parameters.
572 void emitContentsMoved();
575 * Updates the status bar to show hover information for the
576 * item \a item. If currently other items are selected,
577 * no hover information is shown.
578 * @see DolphinView::clearHoverInformation()
580 void showHoverInformation(const KFileItem
& item
);
583 * Clears the hover information shown in the status bar.
584 * @see DolphinView::showHoverInformation().
586 void clearHoverInformation();
589 * Indicates in the status bar that the delete operation
590 * of the job \a job has been finished.
592 void slotDeleteFileFinished(KJob
* job
);
595 void loadDirectory(const KUrl
& url
, bool reload
= false);
598 * Returns the URL where the view properties should be stored. Usually
599 * DolphinView::url() is returned, but in the case of a Column View the
600 * view properties are always stored in the directory represented by the
601 * first column. It is recommendend whenever using the ViewProperties class
602 * to use DolphinView::viewPropertiesUrl() as URL.
604 KUrl
viewPropertiesUrl() const;
607 * Applies the view properties which are defined by the current URL
608 * m_url to the DolphinView properties.
610 void applyViewProperties(const KUrl
& url
);
613 * Creates a new view representing the given view mode (DolphinView::mode()).
614 * The current view will get deleted.
621 * Returns a pointer to the currently used item view, which is either
622 * a ListView or a TreeView.
624 QAbstractItemView
* itemView() const;
627 * Returns true, if the item \a item has been cut into
630 bool isCutItem(const KFileItem
& item
) const;
633 * Returns true, if the ColumnView is activated. As the column view
634 * requires some special handling for iterating through directories,
635 * this method has been introduced for convenience.
637 bool isColumnViewActive() const
639 return m_columnView
!= 0;
645 bool m_loadingDirectory
;
646 bool m_storedCategorizedSorting
;
649 DolphinMainWindow
* m_mainWindow
;
650 QVBoxLayout
* m_topLayout
;
652 DolphinController
* m_controller
;
653 DolphinIconsView
* m_iconsView
;
654 DolphinDetailsView
* m_detailsView
;
655 DolphinColumnView
* m_columnView
;
656 KFileItemDelegate
* m_fileItemDelegate
;
657 QItemSelectionModel
* m_selectionModel
;
659 DolphinModel
* m_dolphinModel
;
660 KDirLister
* m_dirLister
;
661 DolphinSortFilterProxyModel
* m_proxyModel
;
663 IconManager
* m_iconManager
;
668 /// Allow using DolphinView::Mode in QVariant
669 Q_DECLARE_METATYPE(DolphinView::Mode
)
671 #endif // DOLPHINVIEW_H