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
;
61 * @short Represents a view for the directory content.
63 * View modes for icons, details and columns are supported. It's
70 * @see DolphinIconsView
71 * @see DolphinDetailsView
72 * @see DolphinColumnView
74 class LIBDOLPHINPRIVATE_EXPORT DolphinView
: public QWidget
80 * Defines the view mode for a directory. The view mode
81 * can be defined when constructing a DolphinView. The
82 * view mode is automatically updated if the directory itself
83 * defines a view mode (see class ViewProperties for details).
88 * The directory items are shown as icons including an
93 * The icon, the name and at least the size of the directory
94 * items are shown in a table. It is possible to add columns
95 * for date, group and permissions.
100 * Each folder is shown in a separate column.
103 MaxModeEnum
= ColumnView
106 /** Defines the sort order for the items of a directory. */
118 MaxSortEnum
= SortByTags
122 * @param parent Parent widget of the view.
123 * @param url Specifies the content which should be shown.
124 * @param dirLister Used directory lister. The lister is not owned
125 * by the view and won't get deleted.
126 * @param dolphinModel Used directory model. The model is not owned
127 * by the view and won't get deleted.
128 * @param proxyModel Used proxy model which specifies the sorting. The
129 * model is not owned by the view and won't get
132 DolphinView(QWidget
* parent
,
134 KDirLister
* dirLister
,
135 DolphinModel
* dolphinModel
,
136 DolphinSortFilterProxyModel
* proxyModel
);
138 virtual ~DolphinView();
141 * Returns the current active URL, where all actions are applied.
142 * The URL navigator is synchronized with this URL.
144 const KUrl
& url() const;
147 * Returns the root URL of the view, which is defined as the first
148 * visible path of DolphinView::url(). Usually the root URL is
149 * equal to DolphinView::url(), but in the case of the column view
150 * when 2 columns are shown, the root URL might be:
151 * /home/peter/Documents
152 * and DolphinView::url() might return
153 * /home/peter/Documents/Music/
155 KUrl
rootUrl() const;
158 * If \a active is true, the view will marked as active. The active
159 * view is defined as view where all actions are applied to.
161 void setActive(bool active
);
162 bool isActive() const;
165 * Changes the view mode for the current directory to \a mode.
166 * If the view properties should be remembered for each directory
167 * (GeneralSettings::globalViewProps() returns false), then the
168 * changed view mode will be be stored automatically.
170 void setMode(Mode mode
);
174 * Turns on the file preview for the all files of the current directory,
175 * if \a show is true.
176 * If the view properties should be remembered for each directory
177 * (GeneralSettings::globalViewProps() returns false), then the
178 * preview setting will be be stored automatically.
180 void setShowPreview(bool show
);
181 bool showPreview() const;
184 * Shows all hidden files of the current directory,
185 * if \a show is true.
186 * If the view properties should be remembered for each directory
187 * (GeneralSettings::globalViewProps() returns false), then the
188 * show hidden file setting will be be stored automatically.
190 void setShowHiddenFiles(bool show
);
191 bool showHiddenFiles() const;
194 * Summarizes all sorted items by their category \a categorized
196 * If the view properties should be remembered for each directory
197 * (GeneralSettings::globalViewProps() returns false), then the
198 * categorized sorting setting will be be stored automatically.
200 void setCategorizedSorting(bool categorized
);
201 bool categorizedSorting() const;
204 * Returns true, if the categorized sorting is supported by the current
205 * used mode (see DolphinView::setMode()). Currently only DolphinView::IconsView
206 * supports categorizations. To check whether the categorized
207 * sorting is set, use DolphinView::categorizedSorting().
209 bool supportsCategorizedSorting() const;
213 * @see DolphinView::selectedItems()
218 * Inverts the current selection: selected items get unselected,
219 * unselected items get selected.
220 * @see DolphinView::selectedItems()
222 void invertSelection();
224 /** Returns true, if at least one item is selected. */
225 bool hasSelection() const;
227 void clearSelection();
230 * Returns the selected items. The list is empty if no item has been
232 * @see DolphinView::selectedUrls()
234 KFileItemList
selectedItems() const;
237 * Returns a list of URLs for all selected items. An empty list
238 * is returned, if no item is selected.
239 * @see DolphinView::selectedItems()
241 KUrl::List
selectedUrls() const;
244 * Returns the file item for the given model index \a index.
246 KFileItem
fileItem(const QModelIndex
& index
) const;
249 * Sets the upper left position of the view content
250 * to (x,y). The content of the view might be larger than the visible area
251 * and hence a scrolling must be done.
253 void setContentsPosition(int x
, int y
);
255 /** Returns the upper left position of the view content. */
256 QPoint
contentsPosition() const;
258 /** Increases the size of the current set view mode. */
261 /** Decreases the size of the current set view mode. */
265 * Returns true, if zooming in is possible. If false is returned,
266 * the minimal zoom size is possible.
268 bool isZoomInPossible() const;
271 * Returns true, if zooming out is possible. If false is returned,
272 * the maximum zoom size is possible.
274 bool isZoomOutPossible() const;
276 /** Sets the sort order of the items inside a directory (see DolphinView::Sorting). */
277 void setSorting(Sorting sorting
);
279 /** Returns the sort order of the items inside a directory (see DolphinView::Sorting). */
280 Sorting
sorting() const;
282 /** Sets the sort order (Qt::Ascending or Qt::Descending) for the items. */
283 void setSortOrder(Qt::SortOrder order
);
285 /** Returns the current used sort order (Qt::Ascending or Qt::Descending). */
286 Qt::SortOrder
sortOrder() const;
288 /** Sets the additional information which should be shown for the items. */
289 void setAdditionalInfo(KFileItemDelegate::InformationList info
);
291 /** Returns the additional information which should be shown for the items. */
292 KFileItemDelegate::InformationList
additionalInfo() const;
294 /** Reloads the current directory. */
298 * Refreshes the view to get synchronized with the (updated) Dolphin settings.
299 * This method only needs to get invoked if the view settings for the Icons View,
300 * Details View or Columns View have been changed.
305 * Changes the directory of the view to \a url. If \a rootUrl is empty, the view
306 * properties from \a url are used for adjusting the view mode and the other properties.
307 * If \a rootUrl is not empty, the view properties from the root URL are considered
308 * instead. Specifying a root URL is only required if a view having a different root URL
309 * (e. g. the column view) should be restored. Usually using DolphinView::setUrl()
310 * is enough for changing the current URL.
312 void updateView(const KUrl
& url
, const KUrl
& rootUrl
);
315 * Filters the currently shown items by \a nameFilter. All items
316 * which contain the given filter string will be shown.
318 void setNameFilter(const QString
& nameFilter
);
321 * Calculates the number of currently shown files into
322 * \a fileCount and the number of folders into \a folderCount.
323 * It is recommend using this method instead of asking the
324 * directory lister or the model directly, as it takes
325 * filtering and hierarchical previews into account.
327 void calculateItemCount(int& fileCount
, int& folderCount
);
330 * Returns the "switch to icons mode" action.
331 * This code is here to share it between the mainwindow and the part
333 static KToggleAction
* iconsModeAction(KActionCollection
* collection
);
336 * Returns the "switch to details mode" action.
337 * This code is here to share it between the mainwindow and the part
339 static KToggleAction
* detailsModeAction(KActionCollection
* collection
);
342 * Returns the "switch to columns mode" action.
343 * This code is here to share it between the mainwindow and the part
345 static KToggleAction
* columnsModeAction(KActionCollection
* collection
);
348 * Creates the rename action.
349 * This code is here to share it between the mainwindow and the part
351 static KAction
* createRenameAction(KActionCollection
* collection
);
354 * Creates the "move to trash" action.
355 * This code is here to share it between the mainwindow and the part
357 static KAction
* createMoveToTrashAction(KActionCollection
* collection
);
360 * Creates the delete action.
361 * This code is here to share it between the mainwindow and the part
363 static KAction
* createDeleteAction(KActionCollection
* collection
);
366 * Creates the "new directory" action.
367 * This code is here to share it between the mainwindow and the part
369 static KAction
* createNewDirAction(KActionCollection
* collection
);
372 * Creates the "sort descending" action.
373 * This code is here to share it between the mainwindow and the part
375 static KAction
* createSortDescendingAction(KActionCollection
* collection
);
378 * Returns the action name corresponding to the current view mode
380 QString
currentViewModeActionName() const;
383 * Returns the state of the paste action:
384 * first is whether the action should be enabled
385 * second is the text for the action
387 QPair
<bool, QString
> pasteInfo() const;
391 * Changes the directory to \a url. If the current directory is equal to
392 * \a url, nothing will be done (use DolphinView::reload() instead).
394 void setUrl(const KUrl
& url
);
397 * Request of a selection change. The view will do its best to accommodate
398 * the request, but it is not guaranteed that all items in \a selection
399 * will actually get selected. The view will e.g. not select items which
400 * are not in the currently displayed folder.
402 void changeSelection(const KFileItemList
& selection
);
405 * Triggers the renaming of the currently selected items, where
406 * the user must input a new name for the items.
408 void renameSelectedItems();
411 * Moves all selected items to the trash.
413 void trashSelectedItems();
416 * Deletes all selected items.
418 void deleteSelectedItems();
421 * Copies all selected items to the clipboard and marks
422 * the items as cutted.
424 void cutSelectedItems();
426 /** Copies all selected items to the clipboard. */
427 void copySelectedItems();
429 /** Pastes the clipboard data to this view. */
432 /** Switches between an ascending and descending sorting order. */
433 void toggleSortOrder();
437 * Is emitted if the view has been activated by e. g. a mouse click.
441 /** Is emitted if URL of the view has been changed to \a url. */
442 void urlChanged(const KUrl
& url
);
445 * Is emitted when clicking on an item
447 void itemTriggered(const KFileItem
& item
);
450 * Is emitted if the view mode (IconsView, DetailsView,
451 * PreviewsView) has been changed.
455 /** Is emitted if the 'show preview' property has been changed. */
456 void showPreviewChanged();
458 /** Is emitted if the 'show hidden files' property has been changed. */
459 void showHiddenFilesChanged();
461 /** Is emitted if the 'categorized sorting' property has been changed. */
462 void categorizedSortingChanged();
464 /** Is emitted if the sorting by name, size or date has been changed. */
465 void sortingChanged(DolphinView::Sorting sorting
);
467 /** Is emitted if the sort order (ascending or descending) has been changed. */
468 void sortOrderChanged(Qt::SortOrder order
);
470 /** Is emitted if the additional information for an item has been changed. */
471 void additionalInfoChanged(const KFileItemDelegate::InformationList
& info
);
474 * Is emitted if information of an item is requested to be shown e. g. in the sidebar.
475 * If item is null, no item information request is pending.
477 void requestItemInfo(const KFileItem
& item
);
479 /** Is emitted if the contents has been moved to \a x, \a y. */
480 void contentsMoved(int x
, int y
);
483 * Is emitted whenever the selection has been changed.
485 void selectionChanged(const KFileItemList
& selection
);
488 * Is emitted if a context menu is requested for the item \a item,
489 * which is part of \a url. If the item is 0, the context menu
490 * for the URL should be shown.
492 void requestContextMenu(const KFileItem
& item
, const KUrl
& url
);
495 * Is emitted if an information message with the content \a msg
498 void infoMessage(const QString
& msg
);
501 * Is emitted if an error message with the content \a msg
504 void errorMessage(const QString
& msg
);
507 * Is emitted if an "operation completed" message with the content \a msg
510 void operationCompletedMessage(const QString
& msg
);
513 * Is emitted after DolphinView::setUrl() has been invoked and
514 * the path \a url is currently loaded. If this signal is emitted,
515 * it is assured that the view contains already the correct root
516 * URL and property settings.
518 void startedPathLoading(const KUrl
& url
);
521 * Is emitted when renaming, copying, moving, linking etc.
522 * Used for feedback in the mainwindow.
524 void doingOperation(KonqFileUndoManager::CommandType type
);
527 /** @see QWidget::mouseReleaseEvent */
528 virtual void mouseReleaseEvent(QMouseEvent
* event
);
532 * Marks the view as active (DolphinView:isActive() will return true)
533 * and emits the 'activated' signal if it is not already active.
538 * If the item \a item is a directory, then this
539 * directory will be loaded. If the item is a file, the corresponding
540 * application will get started.
542 void triggerItem(const KFileItem
& index
);
545 * Generates a preview image for each file item in \a items.
546 * The current preview settings (maximum size, 'Show Preview' menu)
549 void generatePreviews(const KFileItemList
& items
);
552 * Replaces the icon of the item \a item by the preview pixmap
555 void replaceIcon(const KFileItem
& item
, const QPixmap
& pixmap
);
557 void emitSelectionChangedSignal();
560 * Opens the context menu on position \a pos. The position
561 * is used to check whether the context menu is related to an
562 * item or to the viewport.
564 void openContextMenu(const QPoint
& pos
);
567 * Drops the URLs \a urls to the destination path \a destPath. If
568 * the URLs are dropped above an item inside the destination path,
569 * the item is indicated by \a destItem.
571 void dropUrls(const KUrl::List
& urls
,
572 const KUrl
& destPath
,
573 const KFileItem
& destItem
);
576 * Handles the dropping of URLs to the given destination.
577 * @see DolphinDropController
579 void dropUrls(const KUrl::List
& urls
,
580 const KUrl
& destination
);
582 * Updates the view properties of the current URL to the
583 * sorting given by \a sorting.
585 void updateSorting(DolphinView::Sorting sorting
);
588 * Updates the view properties of the current URL to the
589 * sort order given by \a order.
591 void updateSortOrder(Qt::SortOrder order
);
594 * Updates the view properties of the current URL to the
595 * additional information given by \a info.
597 void updateAdditionalInfo(const KFileItemDelegate::InformationList
& info
);
600 * Emits the signal contentsMoved with the current coordinates
601 * of the viewport as parameters.
603 void emitContentsMoved();
605 /** Applies an item effect to all cut items of the clipboard. */
606 void updateCutItems();
609 * Updates the status bar to show hover information for the
610 * item \a item. If currently other items are selected,
611 * no hover information is shown.
612 * @see DolphinView::clearHoverInformation()
614 void showHoverInformation(const KFileItem
& item
);
617 * Clears the hover information shown in the status bar.
618 * @see DolphinView::showHoverInformation().
620 void clearHoverInformation();
623 * Indicates in the status bar that the delete operation
624 * of the job \a job has been finished.
626 void slotDeleteFileFinished(KJob
* job
);
629 * Is invoked when the preview job has been finished and
630 * set m_previewJob to 0.
632 void slotPreviewJobFinished(KJob
* job
);
635 void loadDirectory(const KUrl
& url
, bool reload
= false);
638 * Returns the URL where the view properties should be stored. Usually
639 * DolphinView::url() is returned, but in the case of a Column View the
640 * view properties are always stored in the directory represented by the
641 * first column. It is recommendend whenever using the ViewProperties class
642 * to use DolphinView::viewPropertiesUrl() as URL.
644 KUrl
viewPropertiesUrl() const;
647 * Applies the view properties which are defined by the current URL
648 * m_url to the DolphinView properties.
650 void applyViewProperties(const KUrl
& url
);
653 * Creates a new view representing the given view mode (DolphinView::mode()).
654 * The current view will get deleted.
661 * Returns a pointer to the currently used item view, which is either
662 * a ListView or a TreeView.
664 QAbstractItemView
* itemView() const;
667 * Returns true, if the item \a item has been cut into
670 bool isCutItem(const KFileItem
& item
) const;
672 /** Applies an item effect to all cut items. */
673 void applyCutItemEffect();
676 * Returns true, if the ColumnView is activated. As the column view
677 * requires some special handling for iterating through directories,
678 * this method has been introduced for convenience.
680 bool isColumnViewActive() const
682 return m_columnView
!= 0;
687 * Remembers the original pixmap for an item before
688 * the cut effect is applied.
698 bool m_loadingDirectory
;
699 bool m_storedCategorizedSorting
;
702 DolphinMainWindow
* m_mainWindow
;
703 QVBoxLayout
* m_topLayout
;
705 DolphinController
* m_controller
;
706 DolphinIconsView
* m_iconsView
;
707 DolphinDetailsView
* m_detailsView
;
708 DolphinColumnView
* m_columnView
;
709 KFileItemDelegate
* m_fileItemDelegate
;
710 QItemSelectionModel
* m_selectionModel
;
712 DolphinModel
* m_dolphinModel
;
713 KDirLister
* m_dirLister
;
714 DolphinSortFilterProxyModel
* m_proxyModel
;
716 KIO::PreviewJob
* m_previewJob
;
718 QList
<CutItem
> m_cutItemsCache
;
723 /// Allow using DolphinView::Mode in QVariant
724 Q_DECLARE_METATYPE(DolphinView::Mode
)
726 #endif // DOLPHINVIEW_H