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 ***************************************************************************/
22 #ifndef _DOLPHINVIEW_H_
23 #define _DOLPHINVIEW_H_
25 #include <kparts/part.h>
26 #include <kfileitem.h>
27 #include <kfileitemdelegate.h>
30 #include <kurlnavigator.h>
32 #include <QtGui/QKeyEvent>
33 #include <QtCore/QLinkedList>
34 #include <QtGui/QListView>
35 #include <QtGui/QBoxLayout>
36 #include <QtGui/QWidget>
38 class DolphinController
;
40 class KFileItemDelegate
;
44 class DolphinColumnView
;
45 class DolphinDetailsView
;
46 class DolphinDirLister
;
47 class DolphinIconsView
;
48 class DolphinMainWindow
;
49 class DolphinSortFilterProxyModel
;
50 class DolphinStatusBar
;
57 * @short Represents a view for the directory content
58 * including the navigation bar, filter bar and status bar.
60 * View modes for icons, details and columns are supported. Currently
61 * Dolphin allows to have up to two views inside the main window.
63 * @see DolphinIconsView
64 * @see DolphinDetailsView
65 * @see DolphinColumnView
67 * @see DolphinStatusBar
69 class 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. */
111 MaxSortEnum
= SortByType
114 DolphinView(DolphinMainWindow
* mainwindow
,
117 Mode mode
= IconsView
,
118 bool showHiddenFiles
= false);
120 virtual ~DolphinView();
123 * Sets the current active URL, where all actions are applied. The
124 * URL navigator is synchronized with this URL. The signals
125 * KUrlNavigator::urlChanged() and KUrlNavigator::historyChanged()
127 * @see DolphinView::urlNavigator()
129 void setUrl(const KUrl
& url
);
132 * Returns the current active URL, where all actions are applied.
133 * The URL navigator is synchronized with this URL.
135 const KUrl
& url() const;
138 * Returns the root URL of the view, which is defined as the first
139 * visible path of DolphinView::url(). Usually the root URL is
140 * equal to DolphinView::url(), but in the case of the column view
141 * when 2 columns are shown, the root URL might be:
142 * /home/peter/Documents
143 * and DolphinView::url() might return
144 * /home/peter/Documents/Music/
146 KUrl
rootUrl() const;
149 * Returns true if the view is active and hence all actions are
150 * applied to this view.
152 bool isActive() const;
155 * Changes the view mode for the current directory to \a mode.
156 * If the view properties should be remembered for each directory
157 * (GeneralSettings::globalViewProps() returns false), then the
158 * changed view mode will be be stored automatically.
160 void setMode(Mode mode
);
164 * Turns on the file preview for the all files of the current directory,
165 * if \a show is true.
166 * If the view properties should be remembered for each directory
167 * (GeneralSettings::globalViewProps() returns false), then the
168 * preview setting will be be stored automatically.
170 void setShowPreview(bool show
);
171 bool showPreview() const;
174 * Shows all hidden 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 * show hidden file setting will be be stored automatically.
180 void setShowHiddenFiles(bool show
);
181 bool showHiddenFiles() const;
184 * Summarizes all sorted items by their category \a categorized
186 * If the view properties should be remembered for each directory
187 * (GeneralSettings::globalViewProps() returns false), then the
188 * categorized sorting setting will be be stored automatically.
190 void setCategorizedSorting(bool categorized
);
191 bool categorizedSorting() const;
194 * Returns true, if the categorized sorting is supported by the current
195 * used mode (see DolphinView::setMode()). Currently only DolphinView::IconsView
196 * supports categorizations. To check whether the categorized
197 * sorting is set, use DolphinView::categorizedSorting().
199 bool supportsCategorizedSorting() const;
202 * Triggers the renaming of the currently selected items, where
203 * the user must input a new name for the items.
205 void renameSelectedItems();
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();
221 * Goes back one step in the URL history. The signals
222 * KUrlNavigator::urlChanged() and KUrlNavigator::historyChanged()
228 * Goes forward one step in the Url history. The signals
229 * KUrlNavigator::urlChanged() and KUrlNavigator::historyChanged()
235 * Goes up one step of the Url path. The signals
236 * KUrlNavigator::urlChanged() and KUrlNavigator::historyChanged()
242 * Goes to the home URL. The signals KUrlNavigator::urlChanged()
243 * and KUrlNavigator::historyChanged() are submitted.
248 * Sets the URL of the navigation bar to an editable state
249 * if \a editable is true. If \a editable is false, each part of
250 * the location is presented by a button for a fast navigation.
252 void setUrlEditable(bool editable
);
254 /** Returns true, if at least one item is selected. */
255 bool hasSelection() const;
257 void clearSelection();
260 * Returns the selected items. The list is empty if no item has been
262 * @see DolphinView::selectedUrls()
264 KFileItemList
selectedItems() const;
267 * Returns a list of URLs for all selected items. An empty list
268 * is returned, if no item is selected.
269 * @see DolphinView::selectedItems()
271 KUrl::List
selectedUrls() const;
274 * Returns the file item for the given model index \a index.
276 KFileItem
* fileItem(const QModelIndex index
) const;
279 * Renames the filename of the source URL by the new file name.
280 * If the new file name already exists, a dialog is opened which
281 * asks the user to enter a new name.
283 void rename(const KUrl
& source
, const QString
& newName
);
285 DolphinStatusBar
* statusBar() const;
288 * Returns the x-position of the view content.
289 * The content of the view might be larger than the visible area
290 * and hence a scrolling must be done.
292 int contentsX() const;
295 * Returns the y-position of the view content.
296 * The content of the view might be larger than the visible area
297 * and hence a scrolling must be done.
299 int contentsY() const;
302 * Returns true, if the URL shown by the navigation bar is editable.
305 bool isUrlEditable() const;
307 /** Increases the size of the current set view mode. */
310 /** Decreases the size of the current set view mode. */
314 * Returns true, if zooming in is possible. If false is returned,
315 * the minimal zoom size is possible.
317 bool isZoomInPossible() const;
320 * Returns true, if zooming out is possible. If false is returned,
321 * the maximum zoom size is possible.
323 bool isZoomOutPossible() const;
325 /** Sets the sort order of the items inside a directory (see DolphinView::Sorting). */
326 void setSorting(Sorting sorting
);
328 /** Returns the sort order of the items inside a directory (see DolphinView::Sorting). */
329 Sorting
sorting() const;
331 /** Sets the sort order (Qt::Ascending or Qt::Descending) for the items. */
332 void setSortOrder(Qt::SortOrder order
);
334 /** Returns the current used sort order (Qt::Ascending or Qt::Descending). */
335 Qt::SortOrder
sortOrder() const;
337 /** Sets the additional information which should be shown for the items. */
338 void setAdditionalInfo(KFileItemDelegate::AdditionalInformation info
);
340 /** Returns the additional information which should be shown for the items. */
341 KFileItemDelegate::AdditionalInformation
additionalInfo() const;
343 /** Returns the KUrlNavigator of the view for read access. */
344 const KUrlNavigator
* urlNavigator() const
346 return m_urlNavigator
;
350 * Triggers to request user information for the item given
351 * by the URL \a url. The signal requestItemInfo is emitted,
352 * which provides a way for widgets to get an indication to update
353 * the item information.
355 void emitRequestItemInfo(const KUrl
& url
);
357 /** Returns true, if the filter bar is visible. */
358 bool isFilterBarVisible() const;
361 * Return the DolphinMainWindow this View belongs to. It is guranteed
364 DolphinMainWindow
* mainWindow() const ;
366 /** Reloads the current directory. */
370 * Refreshs the view to get synchronized with the (updated) Dolphin settings.
371 * This method only needs to get invoked if the view settings for the Icons View,
372 * Details View or Columns View have been changed.
378 * Popups the filter bar above the status bar if \a show is true.
380 void showFilterBar(bool show
);
383 * Updates the number of items (= number of files + number of
384 * directories) in the statusbar. If files are selected, the number
385 * of selected files and the sum of the filesize is shown.
387 void updateStatusBar();
390 * Requests the main window to set this view as active view, which
391 * means that all actions are applied to this view.
393 void requestActivation();
396 * Request of a selection change. The view will do its best to accommodate
397 * the request, but it is not guaranteed that all items in \a selection
398 * will actually get selected. The view will e.g. not select items which
399 * are not in the currently displayed folder.
401 void changeSelection(const KFileItemList
& selection
);
404 /** Is emitted if URL of the view has been changed to \a url. */
405 void urlChanged(const KUrl
& url
);
408 * Is emitted if the view mode (IconsView, DetailsView,
409 * PreviewsView) has been changed.
413 /** Is emitted if the 'show preview' property has been changed. */
414 void showPreviewChanged();
416 /** Is emitted if the 'show hidden files' property has been changed. */
417 void showHiddenFilesChanged();
419 /** Is emitted if the 'categorized sorting' property has been changed. */
420 void categorizedSortingChanged();
422 /** Is emitted if the sorting by name, size or date has been changed. */
423 void sortingChanged(DolphinView::Sorting sorting
);
425 /** Is emitted if the sort order (ascending or descending) has been changed. */
426 void sortOrderChanged(Qt::SortOrder order
);
428 /** Is emitted if the addtional information for an item has been changed. */
429 void additionalInfoChanged(KFileItemDelegate::AdditionalInformation info
);
432 * Is emitted if information of an item is requested to be shown e. g. in the sidebar.
433 * It the URL is empty, no item information request is pending.
435 void requestItemInfo(const KUrl
& url
);
437 /** Is emitted if the contents has been moved to \a x, \a y. */
438 void contentsMoved(int x
, int y
);
441 * Is emitted whenever the selection has been changed.
443 void selectionChanged(const KFileItemList
& selection
);
446 * Is emitted whenever the filter bar has been turned show or hidden.
448 void showFilterBarChanged(bool shown
);
451 /** @see QWidget::mouseReleaseEvent */
452 virtual void mouseReleaseEvent(QMouseEvent
* event
);
455 void changeDirectory(const KUrl
& url
);
456 void triggerItem(const QModelIndex
& index
);
457 void updateProgress(int percent
);
460 * Updates the number of items (= number of directories + number of files)
461 * and shows this information in the statusbar.
463 void updateItemCount();
466 * Generates a preview image for each file item in \a items.
467 * The current preview settings (maximum size, 'Show Preview' menu)
470 void generatePreviews(const KFileItemList
& items
);
473 * Replaces the icon of the item \a item by the preview pixmap
476 void showPreview(const KFileItem
& item
, const QPixmap
& pixmap
);
479 * Restores the x- and y-position of the contents if the
480 * current view is part of the history.
482 void restoreContentsPos();
484 /** Shows the information \a msg inside the statusbar. */
485 void showInfoMessage(const QString
& msg
);
487 /** Shows the error message \a msg inside the statusbar. */
488 void showErrorMessage(const QString
& msg
);
490 void emitSelectionChangedSignal();
491 void closeFilterBar();
494 * Filters the currently shown items by \a nameFilter. All items
495 * which contain the given filter string will be shown.
497 void changeNameFilter(const QString
& nameFilter
);
500 * Opens the context menu on position \a pos. The position
501 * is used to check whether the context menu is related to an
502 * item or to the viewport.
504 void openContextMenu(const QPoint
& pos
);
507 * Drops the URLs \a urls to the index \a index. \a source
508 * indicates the widget where the dragging has been started from.
510 void dropUrls(const KUrl::List
& urls
,
511 const QModelIndex
& index
,
515 * Drops the URLs \a urls at the
516 * destination \a destination.
518 void dropUrls(const KUrl::List
& urls
,
519 const KUrl
& destination
);
521 * Updates the view properties of the current URL to the
522 * sorting given by \a sorting.
524 void updateSorting(DolphinView::Sorting sorting
);
527 * Updates the view properties of the current URL to the
528 * sort order given by \a order.
530 void updateSortOrder(Qt::SortOrder order
);
533 * Emits the signal contentsMoved with the current coordinates
534 * of the viewport as parameters.
536 void emitContentsMoved();
539 * Updates the activation state of the view by checking whether
540 * the currently active view is this view.
542 void updateActivationState();
544 /** Applies an item effect to all cut items of the clipboard. */
545 void updateCutItems();
548 * Updates the status bar to show hover information for the
549 * item with the index \a index. If currently other items are selected,
550 * no hover information is shown.
551 * @see DolphinView::clearHoverInformation()
553 void showHoverInformation(const QModelIndex
& index
);
556 * Clears the hover information shown in the status bar.
557 * @see DolphinView::showHoverInformation().
559 void clearHoverInformation();
562 void startDirLister(const KUrl
& url
, bool reload
= false);
565 * Returns the default text of the status bar, if no item is
568 QString
defaultStatusBarText() const;
571 * Returns the text for the status bar, if at least one item
574 QString
selectionStatusBarText() const;
577 * Creates a new view representing the given view mode (DolphinView::mode()).
578 * The current view will get deleted.
583 * Selects all items by using the selection flags \a flags. This is a helper
584 * method for the slots DolphinView::selectAll() and DolphinView::invertSelection().
586 void selectAll(QItemSelectionModel::SelectionFlags flags
);
589 * Returns a pointer to the currently used item view, which is either
590 * a ListView or a TreeView.
592 QAbstractItemView
* itemView() const;
595 * Returns true if the index is valid and represents
596 * the column KDirModel::Name.
598 bool isValidNameIndex(const QModelIndex
& index
) const;
601 * Returns true, if the item \a item has been cut into
604 bool isCutItem(const KFileItem
& item
) const;
606 /** Applies an item effect to all cut items. */
607 void applyCutItemEffect();
610 * Returns true, if the ColumnView is activated. As the column view
611 * requires some special handling for iterating through directories,
612 * this method has been introduced for convenience.
614 bool isColumnViewActive() const
616 return m_columnView
!= 0;
621 * Remembers the original pixmap for an item before
622 * the cut effect is applied.
631 bool m_blockContentsMovedSignal
;
632 bool m_initializeColumnView
;
639 DolphinMainWindow
* m_mainWindow
;
640 QVBoxLayout
* m_topLayout
;
641 KUrlNavigator
* m_urlNavigator
;
643 DolphinController
* m_controller
;
644 DolphinIconsView
* m_iconsView
;
645 DolphinDetailsView
* m_detailsView
;
646 DolphinColumnView
* m_columnView
;
647 KFileItemDelegate
* m_fileItemDelegate
;
649 FilterBar
* m_filterBar
;
650 DolphinStatusBar
* m_statusBar
;
652 KDirModel
* m_dirModel
;
653 DolphinDirLister
* m_dirLister
;
654 DolphinSortFilterProxyModel
* m_proxyModel
;
656 QList
<CutItem
> m_cutItemsCache
;
659 #endif // _DOLPHINVIEW_H_