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 <kfileiconview.h>
30 #include <urlnavigator.h>
33 #include <QLinkedList>
35 #include <QMouseEvent>
36 #include <QVBoxLayout>
43 class DolphinDetailsView
;
44 class DolphinDirLister
;
45 class DolphinIconsView
;
46 class DolphinMainWindow
;
47 class DolphinSortFilterProxyModel
;
48 class DolphinStatusBar
;
55 * @short Represents a view for the directory content
56 * including the navigation bar and status bar.
58 * View modes for icons and details are supported. Currently
59 * Dolphin allows to have up to two views inside the main window.
61 * @see DolphinIconsView
62 * @see DolphinDetailsView
64 * @see DolphinStatusBar
66 class DolphinView
: public QWidget
72 * Defines the view mode for a directory. The view mode
73 * can be defined when constructing a DolphinView. The
74 * view mode is automatically updated if the directory itself
75 * defines a view mode (see class ViewProperties for details).
80 * The directory items are shown as icons including an
85 * The icon, the name and at least the size of the directory
86 * items are shown in a table. It is possible to add columns
87 * for date, group and permissions.
90 MaxModeEnum
= DetailsView
93 /** Defines the sort order for the items of a directory. */
102 MaxSortEnum
= SortByGroup
105 DolphinView(DolphinMainWindow
* mainwindow
,
108 Mode mode
= IconsView
,
109 bool showHiddenFiles
= false);
111 virtual ~DolphinView();
114 * Sets the current active URL.
115 * The signals UrlNavigator::urlChanged() and UrlNavigator::historyChanged()
118 void setUrl(const KUrl
& url
);
120 /** Returns the current active URL. */
121 const KUrl
& url() const;
123 void requestActivation();
124 bool isActive() const;
127 * Changes the view mode for the current directory to \a mode.
128 * If the view properties should be remembered for each directory
129 * (GeneralSettings::globalViewProps() returns false), then the
130 * changed view mode will be be stored automatically.
132 void setMode(Mode mode
);
136 * Turns on the file preview for the all files of the current directory,
137 * if \a show is true.
138 * If the view properties should be remembered for each directory
139 * (GeneralSettings::globalViewProps() returns false), then the
140 * preview setting will be be stored automatically.
142 void setShowPreview(bool show
);
143 bool showPreview() const;
146 * Shows all hidden files of the current directory,
147 * if \a show is true.
148 * If the view properties should be remembered for each directory
149 * (GeneralSettings::globalViewProps() returns false), then the
150 * show hidden file setting will be be stored automatically.
152 void setShowHiddenFiles(bool show
);
153 bool showHiddenFiles() const;
156 * Triggers the renaming of the currently selected items, where
157 * the user must input a new name for the items.
159 void renameSelectedItems();
163 * @see DolphinView::selectedItems()
168 * Inverts the current selection: selected items get unselected,
169 * unselected items get selected.
170 * @see DolphinView::selectedItems()
172 void invertSelection();
175 * Goes back one step in the URL history. The signals
176 * UrlNavigator::urlChanged() and UrlNavigator::historyChanged()
182 * Goes forward one step in the Url history. The signals
183 * UrlNavigator::urlChanged() and UrlNavigator::historyChanged()
189 * Goes up one step of the Url path. The signals
190 * UrlNavigator::urlChanged() and UrlNavigator::historyChanged()
196 * Goes to the home URL. The signals UrlNavigator::urlChanged()
197 * and UrlNavigator::historyChanged() are submitted.
202 * Sets the URL of the navigation bar to an editable state
203 * if \a editable is true. If \a editable is false, each part of
204 * the location is presented by a button for a fast navigation.
206 void setUrlEditable(bool editable
);
209 * Returns the complete URL history. The index 0 indicates the oldest
211 * @param index Output parameter which indicates the current
212 * index of the location.
214 const QLinkedList
<UrlNavigator::HistoryElem
> urlHistory(int& index
) const;
217 * Returns true, if at least one item is selected.
219 bool hasSelection() const;
222 * Returns the selected items. The list is empty if no item has been
224 * @see DolphinView::selectedUrls()
226 KFileItemList
selectedItems() const;
229 * Returns a list of URLs for all selected items. An empty list
230 * is returned, if no item is selected.
231 * @see DolphinView::selectedItems()
233 KUrl::List
selectedUrls() const;
236 * Returns the file item for the given model index \a index.
238 KFileItem
* fileItem(const QModelIndex index
) const;
241 * Opens the context menu for the item indicated by \a fileInfo
242 * on the position \a pos. If 0 is passed for the file info, a context
243 * menu for the viewport is opened.
245 void openContextMenu(KFileItem
* fileInfo
, const QPoint
& pos
);
248 * Renames the filename of the source URL by the new file name.
249 * If the new file name already exists, a dialog is opened which
250 * asks the user to enter a new name.
252 void rename(const KUrl
& source
, const QString
& newName
);
254 /** Returns the status bar of the view. */
255 DolphinStatusBar
* statusBar() const;
258 * Returns the x-position of the view content.
259 * The content of the view might be larger than the visible area
260 * and hence a scrolling must be done.
262 int contentsX() const;
265 * Returns the y-position of the view content.
266 * The content of the view might be larger than the visible area
267 * and hence a scrolling must be done.
269 int contentsY() const;
272 * Returns true, if the URL shown by the navigation bar is editable.
275 bool isUrlEditable() const;
277 /** Increases the size of the current set view mode. */
280 /** Decreases the size of the current set view mode. */
284 * Returns true, if zooming in is possible. If false is returned,
285 * the minimal zoom size is possible.
287 bool isZoomInPossible() const;
290 * Returns true, if zooming out is possible. If false is returned,
291 * the maximum zoom size is possible.
293 bool isZoomOutPossible() const;
295 /** Sets the sort order of the items inside a directory (see DolphinView::Sorting). */
296 void setSorting(Sorting sorting
);
298 /** Returns the sort order of the items inside a directory (see DolphinView::Sorting). */
299 Sorting
sorting() const;
301 /** Sets the sort order (Qt::Ascending or Qt::Descending) for the items. */
302 void setSortOrder(Qt::SortOrder order
);
304 /** Returns the current used sort order (Qt::Ascending or Qt::Descending). */
305 Qt::SortOrder
sortOrder() const;
307 /** Refreshs the view settings by reading out the stored settings. */
308 void refreshSettings();
310 /** Returns the UrlNavigator of the view for read access. */
311 const UrlNavigator
* urlNavigator() const { return m_urlNavigator
; }
314 * Triggers to request user information for the item given
315 * by the URL \a url. The signal requestItemInfo is emitted,
316 * which provides a way for widgets to get an indication to update
317 * the item information.
319 void emitRequestItemInfo(const KUrl
& url
);
321 /** Returns true, if the filter bar is visible. */
322 bool isFilterBarVisible() const;
325 * Return the DolphinMainWindow this View belongs to. It is guranteed
328 DolphinMainWindow
* mainWindow() const ;
330 /** Reloads the current directory. */
334 * Declare this View as the activeview of the mainWindow()
336 void declareViewActive();
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 /** Is emitted if URL of the view has been changed to \a url. */
353 void urlChanged(const KUrl
& url
);
356 * Is emitted if the view mode (IconsView, DetailsView,
357 * PreviewsView) has been changed.
361 /** Is emitted if the 'show preview' property has been changed. */
362 void showPreviewChanged();
364 /** Is emitted if the 'show hidden files' property has been changed. */
365 void showHiddenFilesChanged();
367 /** Is emitted if the sorting by name, size or date has been changed. */
368 void sortingChanged(DolphinView::Sorting sorting
);
370 /** Is emitted if the sort order (ascending or descending) has been changed. */
371 void sortOrderChanged(Qt::SortOrder order
);
374 * Is emitted if information of an item is requested to be shown e. g. in the sidebar.
375 * It the U is empty, no item information request is pending.
377 void requestItemInfo(const KUrl
& url
);
379 /** Is emitted if the contents has been moved to \a x, \a y. */
380 void contentsMoved(int x
, int y
);
383 * Is emitted whenever the selection has been changed. The current selection can
384 * be retrieved by mainWindow()->activeView()->selectedItems() or by
385 * mainWindow()->activeView()->selectedUrls().
387 void selectionChanged();
390 * Is emitted whenever the filter bar has been turned show or hidden.
392 void showFilterBarChanged(bool shown
);
395 /** @see QWidget::mouseReleaseEvent */
396 virtual void mouseReleaseEvent(QMouseEvent
* event
);
399 void loadDirectory(const KUrl
& kurl
);
400 void triggerItem(const QModelIndex
& index
);
401 void updateProgress(int percent
);
404 * Updates the number of items (= number of directories + number of files)
405 * and shows this information in the statusbar.
407 void updateItemCount();
410 * Restores the x- and y-position of the contents if the
411 * current view is part of the history.
413 void restoreContentsPos();
415 /** Shows the information \a msg inside the statusbar. */
416 void showInfoMessage(const QString
& msg
);
418 /** Shows the error message \a msg inside the statusbar. */
419 void showErrorMessage(const QString
& msg
);
421 void emitSelectionChangedSignal();
422 void closeFilterBar();
425 * Filters the currently shown items by \a nameFilter. All items
426 * which contain the given filter string will be shown.
428 void changeNameFilter(const QString
& nameFilter
);
431 void startDirLister(const KUrl
& url
, bool reload
= false);
434 * Returns the default text of the status bar, if no item is
437 QString
defaultStatusBarText() const;
440 * Returns the text for the status bar, if at least one item
443 QString
selectionStatusBarText() const;
446 * Creates a new view representing the given view mode (DolphinView::viewMode()).
447 * The current view will get deleted.
452 * Returns the column index used in the KDirModel depending on \a sorting.
454 int columnIndex(Sorting sorting
) const;
457 * Selects all items by using the selection flags \a flags. This is a helper
458 * method for the slots DolphinView::selectAll() and DolphinView::invertSelection().
460 void selectAll(QItemSelectionModel::SelectionFlags flags
);
463 * Returns a pointer to the currently used item view, which is either
464 * a ListView or a TreeView.
466 QAbstractItemView
* itemView() const;
476 DolphinMainWindow
* m_mainWindow
;
477 QVBoxLayout
* m_topLayout
;
478 UrlNavigator
* m_urlNavigator
;
480 DolphinIconsView
* m_iconsView
;
481 DolphinDetailsView
* m_detailsView
;
483 FilterBar
* m_filterBar
;
484 DolphinStatusBar
* m_statusBar
;
486 KDirModel
* m_dirModel
;
487 DolphinDirLister
* m_dirLister
;
488 DolphinSortFilterProxyModel
* m_proxyModel
;
491 #endif // _DOLPHINVIEW_H_