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_
28 #include <Q3ValueList>
29 #include <QMouseEvent>
30 #include <QVBoxLayout>
31 #include <kparts/part.h>
32 #include <kfileitem.h>
33 #include <kfileiconview.h>
35 #include <urlnavigator.h>
48 class DolphinMainWindow
;
49 class DolphinDirLister
;
50 class DolphinStatusBar
;
51 class DolphinIconsView
;
52 class DolphinDetailsView
;
53 class DolphinSortFilterProxyModel
;
62 * @short Represents a view for the directory content
63 * including the navigation bar and status bar.
65 * View modes for icons, details and previews are supported. Currently
66 * Dolphin allows to have up to two views inside the main window.
68 * @see DolphinIconsView
69 * @see DolphinDetailsView
71 * @see DolphinStatusBar
73 * @author Peter Penz <peter.penz@gmx.at>
75 class DolphinView
: public QWidget
81 * Defines the view mode for a directory. The view mode
82 * can be defined when constructing a DolphinView. The
83 * view mode is automatically updated if the directory itself
84 * defines a view mode (see class ViewProperties for details).
89 * The directory items are shown as icons including an
94 * The icon, the name and at least the size of the directory
95 * items are shown in a table. It is possible to add columns
96 * for date, group and permissions.
99 MaxModeEnum
= DetailsView
102 /** Defines the sort order for the items of a directory. */
108 MaxSortEnum
= SortByDate
111 DolphinView(DolphinMainWindow
* mainwindow
,
114 Mode mode
= IconsView
,
115 bool showHiddenFiles
= false);
117 virtual ~DolphinView();
120 * Sets the current active Url.
121 * The signals UrlNavigator::urlChanged and UrlNavigator::historyChanged
124 void setUrl(const KUrl
& url
);
126 /** Returns the current active Url. */
127 const KUrl
& url() const;
129 void requestActivation();
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 Q3ValueList
<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 current item, where the cursor is. 0 is returned, if there is no
243 * current item (e. g. if the view is empty). Note that the current item must
244 * not be a selected item.
245 * @see DolphinView::selectedItems()
247 const KFileItem
* currentFileItem() const;
250 * Opens the context menu for the item indicated by \a fileInfo
251 * on the position \a pos. If 0 is passed for the file info, a context
252 * menu for the viewport is opened.
254 void openContextMenu(KFileItem
* fileInfo
, const QPoint
& pos
);
257 * Renames the filename of the source Url by the new file name.
258 * If the new file name already exists, a dialog is opened which
259 * asks the user to enter a new name.
261 void rename(const KUrl
& source
, const QString
& newName
);
263 /** Returns the status bar of the view. */
264 DolphinStatusBar
* statusBar() const;
267 * Returns the x-position of the view content.
268 * The content of the view might be larger than the visible area
269 * and hence a scrolling must be done.
271 int contentsX() const;
274 * Returns the y-position of the view content.
275 * The content of the view might be larger than the visible area
276 * and hence a scrolling must be done.
278 int contentsY() const;
281 * Returns true, if the Url shown by the navigation bar is editable.
284 bool isUrlEditable() const;
286 /** Increases the size of the current set view mode. */
289 /** Decreases the size of the current set view mode. */
293 * Returns true, if zooming in is possible. If false is returned,
294 * the minimal zoom size is possible.
296 bool isZoomInPossible() const;
299 * Returns true, if zooming out is possible. If false is returned,
300 * the maximum zoom size is possible.
302 bool isZoomOutPossible() const;
304 /** Sets the sort order of the items inside a directory (see DolphinView::Sorting). */
305 void setSorting(Sorting sorting
);
307 /** Returns the sort order of the items inside a directory (see DolphinView::Sorting). */
308 Sorting
sorting() const;
310 /** Sets the sort order (Qt::Ascending or Qt::Descending) for the items. */
311 void setSortOrder(Qt::SortOrder order
);
313 /** Returns the current used sort order (Qt::Ascending or Qt::Descending). */
314 Qt::SortOrder
sortOrder() const;
316 /** Refreshs the view settings by reading out the stored settings. */
317 void refreshSettings();
320 * Updates the number of items (= number of files + number of
321 * directories) in the statusbar. If files are selected, the number
322 * of selected files and the sum of the filesize is shown.
324 void updateStatusBar();
326 /** Returns the UrlNavigator of the view for read access. */
327 const UrlNavigator
* urlNavigator() const { return m_urlNavigator
; }
330 * Triggers to request user information for the item given
331 * by the Url \a url. The signal requestItemInfo is emitted,
332 * which provides a way for widgets to get an indication to update
333 * the item information.
335 void emitRequestItemInfo(const KUrl
& url
);
337 /** Returns true, if the filter bar is visible. */
338 bool isFilterBarVisible() const;
341 * Return the DolphinMainWindow this View belongs to. It is guranteed
344 DolphinMainWindow
* mainWindow() const ;
348 void slotUrlListDropped(QDropEvent
* event
,
349 const KUrl::List
& urls
,
353 * Slot that popups the filter bar like FireFox popups his Search bar.
355 void slotShowFilterBar(bool show
);
358 * Declare this View as the activeview of the mainWindow()
360 void declareViewActive();
363 /** Is emitted if Url of the view has been changed to \a url. */
364 void urlChanged(const KUrl
& url
);
367 * Is emitted if the view mode (IconsView, DetailsView,
368 * PreviewsView) has been changed.
372 /** Is emitted if the 'show preview' property has been changed. */
373 void showPreviewChanged();
375 /** Is emitted if the 'show hidden files' property has been changed. */
376 void showHiddenFilesChanged();
378 /** Is emitted if the sorting by name, size or date has been changed. */
379 void sortingChanged(DolphinView::Sorting sorting
);
381 /** Is emitted if the sort order (ascending or descending) has been changed. */
382 void sortOrderChanged(Qt::SortOrder order
);
385 * Is emitted if information of an item is requested to be shown e. g. in the sidebar.
386 * It the Url is empty, no item information request is pending.
388 void requestItemInfo(const KUrl
& url
);
390 /** Is emitted if the contents has been moved to \a x, \a y. */
391 void contentsMoved(int x
, int y
);
394 * Is emitted whenever the selection has been changed. The current selection can
395 * be retrieved by mainWindow()->activeView()->selectedItems() or by
396 * mainWindow()->activeView()->selectedUrls().
398 void selectionChanged();
401 * Is emitted whenever the filter bar has been turned show or hidden.
403 void showFilterBarChanged(bool shown
);
406 /** @see QWidget::mouseReleaseEvent */
407 virtual void mouseReleaseEvent(QMouseEvent
* event
);
410 void loadDirectory(const KUrl
& kurl
);
411 void triggerItem(const QModelIndex
& index
);
413 void slotPercent(int percent
);
415 void slotDeleteItem(KFileItem
* item
);
416 void slotCompleted();
417 void slotInfoMessage(const QString
& msg
);
418 void slotErrorMessage(const QString
& msg
);
419 void slotGrabActivation();
420 void emitSelectionChangedSignal();
421 void closeFilterBar();
424 * Is invoked shortly before the contents of a view implementation
425 * has been moved and emits the signal contentsMoved. Note that no
426 * signal is emitted when the contents moving is only temporary by
427 * e. g. reloading a directory.
429 void slotContentsMoving(int x
, int y
);
432 * Filters the currently shown items by \a nameFilter. All items
433 * which contain the given filter string will be shown.
435 void slotChangeNameFilter(const QString
& nameFilter
);
438 void startDirLister(const KUrl
& url
, bool reload
= false);
441 * Returns the default text of the status bar, if no item is
444 QString
defaultStatusBarText() const;
447 * Returns the text for the status bar, if at least one item
450 QString
selectionStatusBarText() const;
453 * Returns the string representation for the index \a index
454 * for renaming \itemCount items.
456 QString
renameIndexPresentation(int index
, int itemCount
) const;
459 * Applies the current view mode m_mode to the
460 * view implementation.
462 void applyModeToView();
465 * Returns the column index used in the KDirModel depending on \a sorting.
467 int columnIndex(Sorting sorting
) const;
470 * Selects all items by using the selection flags \a flags. This is a helper
471 * method for the slots DolphinView::selectAll() and DolphinView::invertSelection().
473 void selectAll(QItemSelectionModel::SelectionFlags flags
);
484 DolphinMainWindow
* m_mainWindow
;
485 QVBoxLayout
* m_topLayout
;
486 UrlNavigator
* m_urlNavigator
;
487 DolphinIconsView
* m_iconsView
;
488 FilterBar
*m_filterBar
;
489 DolphinStatusBar
* m_statusBar
;
491 KDirModel
* m_dirModel
;
492 DolphinDirLister
* m_dirLister
;
493 DolphinSortFilterProxyModel
* m_proxyModel
;
497 #endif // _DOLPHINVIEW_H_