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>
28 #include <kfileiconview.h>
31 #include <urlnavigator.h>
34 #include <QLinkedList>
36 #include <QMouseEvent>
37 #include <QVBoxLayout>
40 class DolphinController
;
42 class KFileItemDelegate
;
46 class DolphinDetailsView
;
47 class DolphinDirLister
;
48 class DolphinIconsView
;
49 class DolphinMainWindow
;
50 class DolphinSortFilterProxyModel
;
51 class DolphinStatusBar
;
58 * @short Represents a view for the directory content
59 * including the navigation bar, filter bar and status bar.
61 * View modes for icons and details are supported. Currently
62 * Dolphin allows to have up to two views inside the main window.
64 * @see DolphinIconsView
65 * @see DolphinDetailsView
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.
93 MaxModeEnum
= DetailsView
96 /** Defines the sort order for the items of a directory. */
105 MaxSortEnum
= SortByGroup
108 DolphinView(DolphinMainWindow
* mainwindow
,
111 Mode mode
= IconsView
,
112 bool showHiddenFiles
= false);
114 virtual ~DolphinView();
117 * Sets the current active URL.
118 * The signals UrlNavigator::urlChanged() and UrlNavigator::historyChanged()
121 void setUrl(const KUrl
& url
);
123 /** Returns the current active URL. */
124 const KUrl
& url() const;
127 * Returns true if the view is active and hence all actions are
128 * applied to this view.
130 bool isActive() const;
133 * Changes the view mode for the current directory to \a mode.
134 * If the view properties should be remembered for each directory
135 * (GeneralSettings::globalViewProps() returns false), then the
136 * changed view mode will be be stored automatically.
138 void setMode(Mode mode
);
142 * Turns on the file preview for the all files of the current directory,
143 * if \a show is true.
144 * If the view properties should be remembered for each directory
145 * (GeneralSettings::globalViewProps() returns false), then the
146 * preview setting will be be stored automatically.
148 void setShowPreview(bool show
);
149 bool showPreview() const;
152 * Shows all hidden files of the current directory,
153 * if \a show is true.
154 * If the view properties should be remembered for each directory
155 * (GeneralSettings::globalViewProps() returns false), then the
156 * show hidden file setting will be be stored automatically.
158 void setShowHiddenFiles(bool show
);
159 bool showHiddenFiles() const;
162 * Triggers the renaming of the currently selected items, where
163 * the user must input a new name for the items.
165 void renameSelectedItems();
169 * @see DolphinView::selectedItems()
174 * Inverts the current selection: selected items get unselected,
175 * unselected items get selected.
176 * @see DolphinView::selectedItems()
178 void invertSelection();
181 * Goes back one step in the URL history. The signals
182 * UrlNavigator::urlChanged() and UrlNavigator::historyChanged()
188 * Goes forward one step in the Url history. The signals
189 * UrlNavigator::urlChanged() and UrlNavigator::historyChanged()
195 * Goes up one step of the Url path. The signals
196 * UrlNavigator::urlChanged() and UrlNavigator::historyChanged()
202 * Goes to the home URL. The signals UrlNavigator::urlChanged()
203 * and UrlNavigator::historyChanged() are submitted.
208 * Sets the URL of the navigation bar to an editable state
209 * if \a editable is true. If \a editable is false, each part of
210 * the location is presented by a button for a fast navigation.
212 void setUrlEditable(bool editable
);
215 * Returns the complete URL history. The index 0 indicates the oldest
217 * @param index Output parameter which indicates the current
218 * index of the location.
220 const QLinkedList
<UrlNavigator::HistoryElem
> urlHistory(int& index
) const;
223 * Returns true, if at least one item is selected.
225 bool hasSelection() const;
228 * Returns the selected items. The list is empty if no item has been
230 * @see DolphinView::selectedUrls()
232 KFileItemList
selectedItems() const;
235 * Returns a list of URLs for all selected items. An empty list
236 * is returned, if no item is selected.
237 * @see DolphinView::selectedItems()
239 KUrl::List
selectedUrls() const;
242 * Returns the file item for the given model index \a index.
244 KFileItem
* fileItem(const QModelIndex index
) const;
247 * Renames the filename of the source URL by the new file name.
248 * If the new file name already exists, a dialog is opened which
249 * asks the user to enter a new name.
251 void rename(const KUrl
& source
, const QString
& newName
);
253 /** Returns the status bar of the view. */
254 DolphinStatusBar
* statusBar() const;
257 * Returns the x-position of the view content.
258 * The content of the view might be larger than the visible area
259 * and hence a scrolling must be done.
261 int contentsX() const;
264 * Returns the y-position of the view content.
265 * The content of the view might be larger than the visible area
266 * and hence a scrolling must be done.
268 int contentsY() const;
271 * Returns true, if the URL shown by the navigation bar is editable.
274 bool isUrlEditable() const;
276 /** Increases the size of the current set view mode. */
279 /** Decreases the size of the current set view mode. */
283 * Returns true, if zooming in is possible. If false is returned,
284 * the minimal zoom size is possible.
286 bool isZoomInPossible() const;
289 * Returns true, if zooming out is possible. If false is returned,
290 * the maximum zoom size is possible.
292 bool isZoomOutPossible() const;
294 /** Sets the sort order of the items inside a directory (see DolphinView::Sorting). */
295 void setSorting(Sorting sorting
);
297 /** Returns the sort order of the items inside a directory (see DolphinView::Sorting). */
298 Sorting
sorting() const;
300 /** Sets the sort order (Qt::Ascending or Qt::Descending) for the items. */
301 void setSortOrder(Qt::SortOrder order
);
303 /** Returns the current used sort order (Qt::Ascending or Qt::Descending). */
304 Qt::SortOrder
sortOrder() const;
306 /** Sets the additional information which should be shown for the items. */
307 void setAdditionalInfo(KFileItemDelegate::AdditionalInformation info
);
309 /** Returns the additional information which should be shown for the items. */
310 KFileItemDelegate::AdditionalInformation
additionalInfo() const;
312 /** Refreshs the view settings by reading out the stored settings. */
313 void refreshSettings();
315 /** Returns the UrlNavigator of the view for read access. */
316 const UrlNavigator
* urlNavigator() const { return m_urlNavigator
; }
319 * Triggers to request user information for the item given
320 * by the URL \a url. The signal requestItemInfo is emitted,
321 * which provides a way for widgets to get an indication to update
322 * the item information.
324 void emitRequestItemInfo(const KUrl
& url
);
326 /** Returns true, if the filter bar is visible. */
327 bool isFilterBarVisible() const;
330 * Return the DolphinMainWindow this View belongs to. It is guranteed
333 DolphinMainWindow
* mainWindow() const ;
335 /** Reloads the current directory. */
340 * Popups the filter bar above the status bar if \a show is true.
342 void showFilterBar(bool show
);
345 * Updates the number of items (= number of files + number of
346 * directories) in the statusbar. If files are selected, the number
347 * of selected files and the sum of the filesize is shown.
349 void updateStatusBar();
352 * Requests the main window to set this view as active view, which
353 * means that all actions are applied to this view.
355 void requestActivation();
357 /** Applies an item effect to all cut items of the clipboard. */
358 void updateCutItems();
361 /** Is emitted if URL of the view has been changed to \a url. */
362 void urlChanged(const KUrl
& url
);
365 * Is emitted if the view mode (IconsView, DetailsView,
366 * PreviewsView) has been changed.
370 /** Is emitted if the 'show preview' property has been changed. */
371 void showPreviewChanged();
373 /** Is emitted if the 'show hidden files' property has been changed. */
374 void showHiddenFilesChanged();
376 /** Is emitted if the sorting by name, size or date has been changed. */
377 void sortingChanged(DolphinView::Sorting sorting
);
379 /** Is emitted if the sort order (ascending or descending) has been changed. */
380 void sortOrderChanged(Qt::SortOrder order
);
382 /** Is emitted if the addtional information for an item has been changed. */
383 void additionalInfoChanged(KFileItemDelegate::AdditionalInformation info
);
386 * Is emitted if information of an item is requested to be shown e. g. in the sidebar.
387 * It the URL is empty, no item information request is pending.
389 void requestItemInfo(const KUrl
& url
);
391 /** Is emitted if the contents has been moved to \a x, \a y. */
392 void contentsMoved(int x
, int y
);
395 * Is emitted whenever the selection has been changed. The current selection can
396 * be retrieved by mainWindow()->activeView()->selectedItems() or by
397 * mainWindow()->activeView()->selectedUrls().
399 void selectionChanged();
402 * Is emitted whenever the filter bar has been turned show or hidden.
404 void showFilterBarChanged(bool shown
);
407 /** @see QWidget::mouseReleaseEvent */
408 virtual void mouseReleaseEvent(QMouseEvent
* event
);
411 void loadDirectory(const KUrl
& kurl
);
412 void triggerItem(const QModelIndex
& index
);
413 void updateProgress(int percent
);
416 * Updates the number of items (= number of directories + number of files)
417 * and shows this information in the statusbar.
419 void updateItemCount();
422 * Generates a preview image for each file item in \a items.
423 * The current preview settings (maximum size, 'Show Preview' menu)
426 void generatePreviews(const KFileItemList
& items
);
429 * Replaces the icon of the item \a item by the preview pixmap
432 void showPreview(const KFileItem
* item
, const QPixmap
& pixmap
);
435 * Restores the x- and y-position of the contents if the
436 * current view is part of the history.
438 void restoreContentsPos();
440 /** Shows the information \a msg inside the statusbar. */
441 void showInfoMessage(const QString
& msg
);
443 /** Shows the error message \a msg inside the statusbar. */
444 void showErrorMessage(const QString
& msg
);
446 void emitSelectionChangedSignal();
447 void closeFilterBar();
450 * Filters the currently shown items by \a nameFilter. All items
451 * which contain the given filter string will be shown.
453 void changeNameFilter(const QString
& nameFilter
);
456 * Opens the context menu on position \a pos. The position
457 * is used to check whether the context menu is related to an
458 * item or to the viewport.
460 void openContextMenu(const QPoint
& pos
);
463 * Drops the URLs \a urls to the index \a index. \a source
464 * indicates the widget where the dragging has been started from.
466 void dropUrls(const KUrl::List
& urls
,
467 const QModelIndex
& index
,
471 * Drops the URLs \a urls at the
472 * destination \a destination.
474 void dropUrls(const KUrl::List
& urls
,
475 const KUrl
& destination
);
477 * Updates the view properties of the current URL to the
478 * sorting given by \a sorting.
480 void updateSorting(DolphinView::Sorting sorting
);
483 * Updates the view properties of the current URL to the
484 * sort order given by \a order.
486 void updateSortOrder(Qt::SortOrder order
);
489 * Emits the signal contentsMoved with the current coordinates
490 * of the viewport as parameters.
492 void emitContentsMoved();
495 * Updates the activation state of the view by checking whether
496 * the currently active view is this view.
498 void updateActivationState();
501 void startDirLister(const KUrl
& url
, bool reload
= false);
504 * Returns the default text of the status bar, if no item is
507 QString
defaultStatusBarText() const;
510 * Returns the text for the status bar, if at least one item
513 QString
selectionStatusBarText() const;
516 * Creates a new view representing the given view mode (DolphinView::mode()).
517 * The current view will get deleted.
522 * Selects all items by using the selection flags \a flags. This is a helper
523 * method for the slots DolphinView::selectAll() and DolphinView::invertSelection().
525 void selectAll(QItemSelectionModel::SelectionFlags flags
);
528 * Returns a pointer to the currently used item view, which is either
529 * a ListView or a TreeView.
531 QAbstractItemView
* itemView() const;
534 * Returns true if the index is valid and represents
535 * the column KDirModel::Name.
537 bool isValidNameIndex(const QModelIndex
& index
) const;
540 * Returns true, if the item \a item has been cut into
543 bool isCutItem(const KFileItem
& item
) const;
553 DolphinMainWindow
* m_mainWindow
;
554 QVBoxLayout
* m_topLayout
;
555 UrlNavigator
* m_urlNavigator
;
557 DolphinController
* m_controller
;
558 DolphinIconsView
* m_iconsView
;
559 DolphinDetailsView
* m_detailsView
;
560 KFileItemDelegate
* m_fileItemDelegate
;
562 FilterBar
* m_filterBar
;
563 DolphinStatusBar
* m_statusBar
;
565 KDirModel
* m_dirModel
;
566 DolphinDirLister
* m_dirLister
;
567 DolphinSortFilterProxyModel
* m_proxyModel
;
570 #endif // _DOLPHINVIEW_H_