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>
43 class DolphinController
;
45 class KFileItemDelegate
;
48 class DolphinColumnView
;
49 class DolphinDetailsView
;
50 class DolphinIconsView
;
51 class DolphinMainWindow
;
52 class DolphinSortFilterProxyModel
;
57 * @short Represents a view for the directory content.
59 * View modes for icons, details and columns are supported. It's
66 * @see DolphinIconsView
67 * @see DolphinDetailsView
68 * @see DolphinColumnView
70 class LIBDOLPHINPRIVATE_EXPORT DolphinView
: public QWidget
76 * Defines the view mode for a directory. The view mode
77 * can be defined when constructing a DolphinView. The
78 * view mode is automatically updated if the directory itself
79 * defines a view mode (see class ViewProperties for details).
84 * The directory items are shown as icons including an
89 * The icon, the name and at least the size of the directory
90 * items are shown in a table. It is possible to add columns
91 * for date, group and permissions.
96 * Each folder is shown in a separate column.
99 MaxModeEnum
= ColumnView
102 /** Defines the sort order for the items of a directory. */
114 MaxSortEnum
= SortByTags
118 * @param parent Parent widget of the view.
119 * @param url Specifies the content which should be shown.
120 * @param dirLister Used directory lister. The lister is not owned
121 * by the view and won't get deleted.
122 * @param dolphinModel Used directory model. The model is not owned
123 * by the view and won't get deleted.
124 * @param proxyModel Used proxy model which specifies the sorting. The
125 * model is not owned by the view and won't get
128 DolphinView(QWidget
* parent
,
130 KDirLister
* dirLister
,
131 DolphinModel
* dolphinModel
,
132 DolphinSortFilterProxyModel
* proxyModel
);
134 virtual ~DolphinView();
137 * Returns the current active URL, where all actions are applied.
138 * The URL navigator is synchronized with this URL.
140 const KUrl
& url() const;
143 * Returns the root URL of the view, which is defined as the first
144 * visible path of DolphinView::url(). Usually the root URL is
145 * equal to DolphinView::url(), but in the case of the column view
146 * when 2 columns are shown, the root URL might be:
147 * /home/peter/Documents
148 * and DolphinView::url() might return
149 * /home/peter/Documents/Music/
151 KUrl
rootUrl() const;
154 * If \a active is true, the view will marked as active. The active
155 * view is defined as view where all actions are applied to.
157 void setActive(bool active
);
158 bool isActive() const;
161 * Changes the view mode for the current directory to \a mode.
162 * If the view properties should be remembered for each directory
163 * (GeneralSettings::globalViewProps() returns false), then the
164 * changed view mode will be be stored automatically.
166 void setMode(Mode mode
);
170 * Turns on the file preview for the all files of the current directory,
171 * if \a show is true.
172 * If the view properties should be remembered for each directory
173 * (GeneralSettings::globalViewProps() returns false), then the
174 * preview setting will be be stored automatically.
176 void setShowPreview(bool show
);
177 bool showPreview() const;
180 * Shows all hidden files of the current directory,
181 * if \a show is true.
182 * If the view properties should be remembered for each directory
183 * (GeneralSettings::globalViewProps() returns false), then the
184 * show hidden file setting will be be stored automatically.
186 void setShowHiddenFiles(bool show
);
187 bool showHiddenFiles() const;
190 * Summarizes all sorted items by their category \a categorized
192 * If the view properties should be remembered for each directory
193 * (GeneralSettings::globalViewProps() returns false), then the
194 * categorized sorting setting will be be stored automatically.
196 void setCategorizedSorting(bool categorized
);
197 bool categorizedSorting() const;
200 * Returns true, if the categorized sorting is supported by the current
201 * used mode (see DolphinView::setMode()). Currently only DolphinView::IconsView
202 * supports categorizations. To check whether the categorized
203 * sorting is set, use DolphinView::categorizedSorting().
205 bool supportsCategorizedSorting() const;
209 * @see DolphinView::selectedItems()
214 * Inverts the current selection: selected items get unselected,
215 * unselected items get selected.
216 * @see DolphinView::selectedItems()
218 void invertSelection();
220 /** Returns true, if at least one item is selected. */
221 bool hasSelection() const;
223 void clearSelection();
226 * Returns the selected items. The list is empty if no item has been
228 * @see DolphinView::selectedUrls()
230 KFileItemList
selectedItems() const;
233 * Returns a list of URLs for all selected items. An empty list
234 * is returned, if no item is selected.
235 * @see DolphinView::selectedItems()
237 KUrl::List
selectedUrls() const;
240 * Returns the file item for the given model index \a index.
242 KFileItem
fileItem(const QModelIndex
& index
) const;
245 * Sets the upper left position of the view content
246 * to (x,y). The content of the view might be larger than the visible area
247 * and hence a scrolling must be done.
249 void setContentsPosition(int x
, int y
);
251 /** Returns the upper left position of the view content. */
252 QPoint
contentsPosition() const;
254 /** Increases the size of the current set view mode. */
257 /** Decreases the size of the current set view mode. */
261 * Returns true, if zooming in is possible. If false is returned,
262 * the minimal zoom size is possible.
264 bool isZoomInPossible() const;
267 * Returns true, if zooming out is possible. If false is returned,
268 * the maximum zoom size is possible.
270 bool isZoomOutPossible() const;
272 /** Sets the sort order of the items inside a directory (see DolphinView::Sorting). */
273 void setSorting(Sorting sorting
);
275 /** Returns the sort order of the items inside a directory (see DolphinView::Sorting). */
276 Sorting
sorting() const;
278 /** Sets the sort order (Qt::Ascending or Qt::Descending) for the items. */
279 void setSortOrder(Qt::SortOrder order
);
281 /** Returns the current used sort order (Qt::Ascending or Qt::Descending). */
282 Qt::SortOrder
sortOrder() const;
284 /** Sets the additional information which should be shown for the items. */
285 void setAdditionalInfo(KFileItemDelegate::InformationList info
);
287 /** Returns the additional information which should be shown for the items. */
288 KFileItemDelegate::InformationList
additionalInfo() const;
290 /** Reloads the current directory. */
294 * Refreshes the view to get synchronized with the (updated) Dolphin settings.
295 * This method only needs to get invoked if the view settings for the Icons View,
296 * Details View or Columns View have been changed.
301 * Changes the directory of the view to \a url. If \a rootUrl is empty, the view
302 * properties from \a url are used for adjusting the view mode and the other properties.
303 * If \a rootUrl is not empty, the view properties from the root URL are considered
304 * instead. Specifying a root URL is only required if a view having a different root URL
305 * (e. g. the column view) should be restored. Usually using DolphinView::setUrl()
306 * is enough for changing the current URL.
308 void updateView(const KUrl
& url
, const KUrl
& rootUrl
);
311 * Filters the currently shown items by \a nameFilter. All items
312 * which contain the given filter string will be shown.
314 void setNameFilter(const QString
& nameFilter
);
317 * Calculates the number of currently shown files into
318 * \a fileCount and the number of folders into \a folderCount.
319 * It is recommend using this method instead of asking the
320 * directory lister or the model directly, as it takes
321 * filtering and hierarchical previews into account.
323 void calculateItemCount(int& fileCount
, int& folderCount
);
326 * Returns the "switch to icons mode" action.
327 * This code is here to share it between the mainwindow and the part
329 static KToggleAction
* iconsModeAction(KActionCollection
* collection
);
332 * Returns the "switch to details mode" action.
333 * This code is here to share it between the mainwindow and the part
335 static KToggleAction
* detailsModeAction(KActionCollection
* collection
);
338 * Returns the "switch to columns mode" action.
339 * This code is here to share it between the mainwindow and the part
341 static KToggleAction
* columnsModeAction(KActionCollection
* collection
);
344 * Creates the rename action.
345 * This code is here to share it between the mainwindow and the part
347 static KAction
* createRenameAction(KActionCollection
* collection
);
350 * Creates the "move to trash" action.
351 * This code is here to share it between the mainwindow and the part
353 static KAction
* createMoveToTrashAction(KActionCollection
* collection
);
356 * Creates the delete action.
357 * This code is here to share it between the mainwindow and the part
359 static KAction
* createDeleteAction(KActionCollection
* collection
);
362 * Returns the action name corresponding to the current view mode
364 QString
currentViewModeActionName() const;
367 * Returns the state of the paste action:
368 * first is whether the action should be enabled
369 * second is the text for the action
371 QPair
<bool, QString
> pasteInfo() const;
375 * Changes the directory to \a url. If the current directory is equal to
376 * \a url, nothing will be done (use DolphinView::reload() instead).
378 void setUrl(const KUrl
& url
);
381 * Request of a selection change. The view will do its best to accommodate
382 * the request, but it is not guaranteed that all items in \a selection
383 * will actually get selected. The view will e.g. not select items which
384 * are not in the currently displayed folder.
386 void changeSelection(const KFileItemList
& selection
);
389 * Triggers the renaming of the currently selected items, where
390 * the user must input a new name for the items.
392 void renameSelectedItems();
395 * Moves all selected items to the trash.
397 void trashSelectedItems();
400 * Deletes all selected items.
402 void deleteSelectedItems();
405 * Copies all selected items to the clipboard and marks
406 * the items as cutted.
408 void cutSelectedItems();
410 /** Copies all selected items to the clipboard. */
411 void copySelectedItems();
413 /** Pastes the clipboard data to this view. */
418 * Is emitted if the view has been activated by e. g. a mouse click.
422 /** Is emitted if URL of the view has been changed to \a url. */
423 void urlChanged(const KUrl
& url
);
426 * Is emitted when clicking on an item
428 void itemTriggered(const KFileItem
& item
);
431 * Is emitted if the view mode (IconsView, DetailsView,
432 * PreviewsView) has been changed.
436 /** Is emitted if the 'show preview' property has been changed. */
437 void showPreviewChanged();
439 /** Is emitted if the 'show hidden files' property has been changed. */
440 void showHiddenFilesChanged();
442 /** Is emitted if the 'categorized sorting' property has been changed. */
443 void categorizedSortingChanged();
445 /** Is emitted if the sorting by name, size or date has been changed. */
446 void sortingChanged(DolphinView::Sorting sorting
);
448 /** Is emitted if the sort order (ascending or descending) has been changed. */
449 void sortOrderChanged(Qt::SortOrder order
);
451 /** Is emitted if the additional information for an item has been changed. */
452 void additionalInfoChanged(const KFileItemDelegate::InformationList
& info
);
455 * Is emitted if information of an item is requested to be shown e. g. in the sidebar.
456 * If item is null, no item information request is pending.
458 void requestItemInfo(const KFileItem
& item
);
460 /** Is emitted if the contents has been moved to \a x, \a y. */
461 void contentsMoved(int x
, int y
);
464 * Is emitted whenever the selection has been changed.
466 void selectionChanged(const KFileItemList
& selection
);
469 * Is emitted if a context menu is requested for the item \a item,
470 * which is part of \a url. If the item is 0, the context menu
471 * for the URL should be shown.
473 void requestContextMenu(const KFileItem
& item
, const KUrl
& url
);
476 * Is emitted if the URLs \a are dropped to the destination URL
477 * \a destination. No operation is done within the DolphinView, the
478 * receiver of the signal has to take care about the corresponding
481 void urlsDropped(const KUrl::List
& urls
, const KUrl
& destination
);
484 * Is emitted if an information message with the content \a msg
487 void infoMessage(const QString
& msg
);
490 * Is emitted if an error message with the content \a msg
493 void errorMessage(const QString
& msg
);
496 * Is emitted if an "operation completed" message with the content \a msg
499 void operationCompletedMessage(const QString
& msg
);
502 * Is emitted after DolphinView::setUrl() has been invoked and
503 * the path \a url is currently loaded. If this signal is emitted,
504 * it is assured that the view contains already the correct root
505 * URL and property settings.
507 void startedPathLoading(const KUrl
& url
);
510 * Is emitted when renaming, copying, moving, linking etc.
511 * Used for feedback in the mainwindow.
513 void doingOperation(KonqFileUndoManager::CommandType type
);
516 /** @see QWidget::mouseReleaseEvent */
517 virtual void mouseReleaseEvent(QMouseEvent
* event
);
521 * Marks the view as active (DolphinView:isActive() will return true)
522 * and emits the 'activated' signal if it is not already active.
527 * If the item \a item is a directory, then this
528 * directory will be loaded. If the item is a file, the corresponding
529 * application will get started.
531 void triggerItem(const KFileItem
& index
);
534 * Generates a preview image for each file item in \a items.
535 * The current preview settings (maximum size, 'Show Preview' menu)
538 void generatePreviews(const KFileItemList
& items
);
541 * Replaces the icon of the item \a item by the preview pixmap
544 void showPreview(const KFileItem
& item
, const QPixmap
& pixmap
);
546 void emitSelectionChangedSignal();
549 * Opens the context menu on position \a pos. The position
550 * is used to check whether the context menu is related to an
551 * item or to the viewport.
553 void openContextMenu(const QPoint
& pos
);
556 * Drops the URLs \a urls to the destination path \a destPath. If
557 * the URLs are dropped above an item inside the destination path,
558 * the item is indicated by \a destItem.
560 void dropUrls(const KUrl::List
& urls
,
561 const KUrl
& destPath
,
562 const KFileItem
& destItem
);
565 * Drops the URLs \a urls at the
566 * destination \a destination.
568 void dropUrls(const KUrl::List
& urls
,
569 const KUrl
& destination
);
571 * Updates the view properties of the current URL to the
572 * sorting given by \a sorting.
574 void updateSorting(DolphinView::Sorting sorting
);
577 * Updates the view properties of the current URL to the
578 * sort order given by \a order.
580 void updateSortOrder(Qt::SortOrder order
);
583 * Updates the view properties of the current URL to the
584 * additional informations given by \a info.
586 void updateAdditionalInfo(const KFileItemDelegate::InformationList
& info
);
589 * Emits the signal contentsMoved with the current coordinates
590 * of the viewport as parameters.
592 void emitContentsMoved();
594 /** Applies an item effect to all cut items of the clipboard. */
595 void updateCutItems();
598 * Updates the status bar to show hover information for the
599 * item \a item. If currently other items are selected,
600 * no hover information is shown.
601 * @see DolphinView::clearHoverInformation()
603 void showHoverInformation(const KFileItem
& item
);
606 * Clears the hover information shown in the status bar.
607 * @see DolphinView::showHoverInformation().
609 void clearHoverInformation();
612 * Indicates in the status bar that the delete operation
613 * of the job \a job has been finished.
615 void slotDeleteFileFinished(KJob
* job
);
618 void loadDirectory(const KUrl
& url
, bool reload
= false);
621 * Returns the URL where the view properties should be stored. Usually
622 * DolphinView::url() is returned, but in the case of a Column View the
623 * view properties are always stored in the directory represented by the
624 * first column. It is recommendend whenever using the ViewProperties class
625 * to use DolphinView::viewPropertiesUrl() as URL.
627 KUrl
viewPropertiesUrl() const;
630 * Applies the view properties which are defined by the current URL
631 * m_url to the DolphinView properties.
633 void applyViewProperties(const KUrl
& url
);
636 * Creates a new view representing the given view mode (DolphinView::mode()).
637 * The current view will get deleted.
644 * Returns a pointer to the currently used item view, which is either
645 * a ListView or a TreeView.
647 QAbstractItemView
* itemView() const;
650 * Returns true, if the item \a item has been cut into
653 bool isCutItem(const KFileItem
& item
) const;
655 /** Applies an item effect to all cut items. */
656 void applyCutItemEffect();
659 * Returns true, if the ColumnView is activated. As the column view
660 * requires some special handling for iterating through directories,
661 * this method has been introduced for convenience.
663 bool isColumnViewActive() const
665 return m_columnView
!= 0;
670 * Remembers the original pixmap for an item before
671 * the cut effect is applied.
681 bool m_loadingDirectory
;
682 bool m_storedCategorizedSorting
;
685 DolphinMainWindow
* m_mainWindow
;
686 QVBoxLayout
* m_topLayout
;
688 DolphinController
* m_controller
;
689 DolphinIconsView
* m_iconsView
;
690 DolphinDetailsView
* m_detailsView
;
691 DolphinColumnView
* m_columnView
;
692 KFileItemDelegate
* m_fileItemDelegate
;
694 DolphinModel
* m_dolphinModel
;
695 KDirLister
* m_dirLister
;
696 DolphinSortFilterProxyModel
* m_proxyModel
;
698 QList
<CutItem
> m_cutItemsCache
;
703 /// Allow using DolphinView::Mode in QVariant
704 Q_DECLARE_METATYPE(DolphinView::Mode
)
706 #endif // DOLPHINVIEW_H