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;
132 void setMode(Mode mode
);
134 void setShowHiddenFiles(bool show
);
135 bool showHiddenFiles() const;
137 void setViewProperties(const ViewProperties
& props
);
140 * Triggers the renaming of the currently selected items, where
141 * the user must input a new name for the items.
143 void renameSelectedItems();
147 * @see DolphinView::selectedItems()
152 * Inverts the current selection: selected items get unselected,
153 * unselected items get selected.
154 * @see DolphinView::selectedItems()
156 void invertSelection();
159 * Goes back one step in the Url history. The signals
160 * UrlNavigator::urlChanged and UrlNavigator::historyChanged
166 * Goes forward one step in the Url history. The signals
167 * UrlNavigator::urlChanged and UrlNavigator::historyChanged
173 * Goes up one step of the Url path. The signals
174 * UrlNavigator::urlChanged and UrlNavigator::historyChanged
180 * Goes to the home Url. The signals UrlNavigator::urlChanged
181 * and UrlNavigator::historyChanged are submitted.
186 * Sets the Url of the navigation bar to an editable state
187 * if \a editable is true. If \a editable is false, each part of
188 * the location is presented by a button for a fast navigation.
190 void setUrlEditable(bool editable
);
193 * Returns the complete Url history. The index 0 indicates the oldest
195 * @param index Output parameter which indicates the current
196 * index of the location.
198 const Q3ValueList
<UrlNavigator::HistoryElem
> urlHistory(int& index
) const;
201 * Returns true, if at least one item is selected.
203 bool hasSelection() const;
206 * Returns the selected items. The list is empty if no item has been
208 * @see DolphinView::selectedUrls()
210 KFileItemList
selectedItems() const;
213 * Returns a list of Urls for all selected items. An empty list
214 * is returned, if no item is selected.
215 * @see DolphinView::selectedItems()
217 KUrl::List
selectedUrls() const;
220 * Returns the current item, where the cursor is. 0 is returned, if there is no
221 * current item (e. g. if the view is empty). Note that the current item must
222 * not be a selected item.
223 * @see DolphinView::selectedItems()
225 const KFileItem
* currentFileItem() const;
228 * Opens the context menu for the item indicated by \a fileInfo
229 * on the position \a pos. If 0 is passed for the file info, a context
230 * menu for the viewport is opened.
232 void openContextMenu(KFileItem
* fileInfo
, const QPoint
& pos
);
235 * Renames the filename of the source Url by the new file name.
236 * If the new file name already exists, a dialog is opened which
237 * asks the user to enter a new name.
239 void rename(const KUrl
& source
, const QString
& newName
);
241 /** Returns the status bar of the view. */
242 DolphinStatusBar
* statusBar() const;
245 * Returns the x-position of the view content.
246 * The content of the view might be larger than the visible area
247 * and hence a scrolling must be done.
249 int contentsX() const;
252 * Returns the y-position of the view content.
253 * The content of the view might be larger than the visible area
254 * and hence a scrolling must be done.
256 int contentsY() const;
259 * Returns true, if the Url shown by the navigation bar is editable.
262 bool isUrlEditable() const;
264 /** Increases the size of the current set view mode. */
267 /** Decreases the size of the current set view mode. */
271 * Returns true, if zooming in is possible. If false is returned,
272 * the minimal zoom size is possible.
274 bool isZoomInPossible() const;
277 * Returns true, if zooming out is possible. If false is returned,
278 * the maximum zoom size is possible.
280 bool isZoomOutPossible() const;
282 /** Sets the sort order of the items inside a directory (see DolphinView::Sorting). */
283 void setSorting(Sorting sorting
);
285 /** Returns the sort order of the items inside a directory (see DolphinView::Sorting). */
286 Sorting
sorting() const;
288 /** Sets the sort order (Qt::Ascending or Qt::Descending) for the items. */
289 void setSortOrder(Qt::SortOrder order
);
291 /** Returns the current used sort order (Qt::Ascending or Qt::Descending). */
292 Qt::SortOrder
sortOrder() const;
294 /** Refreshs the view settings by reading out the stored settings. */
295 void refreshSettings();
298 * Updates the number of items (= number of files + number of
299 * directories) in the statusbar. If files are selected, the number
300 * of selected files and the sum of the filesize is shown.
302 void updateStatusBar();
304 /** Returns the UrlNavigator of the view for read access. */
305 const UrlNavigator
* urlNavigator() const { return m_urlNavigator
; }
308 * Triggers to request user information for the item given
309 * by the Url \a url. The signal requestItemInfo is emitted,
310 * which provides a way for widgets to get an indication to update
311 * the item information.
313 void emitRequestItemInfo(const KUrl
& url
);
315 /** Returns true, if the filter bar is visible. */
316 bool isFilterBarVisible() const;
319 * Return the DolphinMainWindow this View belongs to. It is guranteed
322 DolphinMainWindow
* mainWindow() const ;
326 void slotUrlListDropped(QDropEvent
* event
,
327 const KUrl::List
& urls
,
331 * Slot that popups the filter bar like FireFox popups his Search bar.
333 void slotShowFilterBar(bool show
);
336 * Declare this View as the activeview of the mainWindow()
338 void declareViewActive();
341 /** Is emitted if Url of the view has been changed to \a url. */
342 void urlChanged(const KUrl
& url
);
345 * Is emitted if the view mode (IconsView, DetailsView,
346 * PreviewsView) has been changed.
350 /** Is emitted if the 'show hidden files' property has been changed. */
351 void showHiddenFilesChanged();
353 /** Is emitted if the sorting by name, size or date has been changed. */
354 void sortingChanged(DolphinView::Sorting sorting
);
356 /** Is emitted if the sort order (ascending or descending) has been changed. */
357 void sortOrderChanged(Qt::SortOrder order
);
360 * Is emitted if information of an item is requested to be shown e. g. in the sidebar.
361 * It the Url is empty, no item information request is pending.
363 void requestItemInfo(const KUrl
& url
);
365 /** Is emitted if the contents has been moved to \a x, \a y. */
366 void contentsMoved(int x
, int y
);
369 * Is emitted whenever the selection has been changed. The current selection can
370 * be retrieved by mainWindow()->activeView()->selectedItems() or by
371 * mainWindow()->activeView()->selectedUrls().
373 void selectionChanged();
376 * Is emitted whenever the filter bar has been turned show or hidden.
378 void showFilterBarChanged(bool shown
);
381 /** @see QWidget::mouseReleaseEvent */
382 virtual void mouseReleaseEvent(QMouseEvent
* event
);
385 void loadDirectory(const KUrl
& kurl
);
386 void triggerIconsViewItem(Q3IconViewItem
*item
);
387 void triggerItem(const QModelIndex
& index
);
390 void slotPercent(int percent
);
392 void slotDeleteItem(KFileItem
* item
);
393 void slotCompleted();
394 void slotInfoMessage(const QString
& msg
);
395 void slotErrorMessage(const QString
& msg
);
396 void slotGrabActivation();
397 void emitSelectionChangedSignal();
398 void closeFilterBar();
401 * Is invoked shortly before the contents of a view implementation
402 * has been moved and emits the signal contentsMoved. Note that no
403 * signal is emitted when the contents moving is only temporary by
404 * e. g. reloading a directory.
406 void slotContentsMoving(int x
, int y
);
409 * Filters the currently shown items by \a nameFilter. All items
410 * which contain the given filter string will be shown.
412 void slotChangeNameFilter(const QString
& nameFilter
);
415 void startDirLister(const KUrl
& url
, bool reload
= false);
418 * Returns the default text of the status bar, if no item is
421 QString
defaultStatusBarText() const;
424 * Returns the text for the status bar, if at least one item
427 QString
selectionStatusBarText() const;
430 * Returns the string representation for the index \a index
431 * for renaming \itemCount items.
433 QString
renameIndexPresentation(int index
, int itemCount
) const;
436 * Applies the current view mode m_mode to the
437 * view implementation.
439 void applyModeToView();
442 * Returns the column index used in the KDirModel depending on \a sorting.
444 int columnIndex(Sorting sorting
) const;
447 * Selects all items by using the selection flags \a flags. This is a helper
448 * method for the slots DolphinView::selectAll() and DolphinView::invertSelection().
450 void selectAll(QItemSelectionModel::SelectionFlags flags
);
461 DolphinMainWindow
* m_mainWindow
;
462 QVBoxLayout
* m_topLayout
;
463 UrlNavigator
* m_urlNavigator
;
464 DolphinIconsView
* m_iconsView
;
465 FilterBar
*m_filterBar
;
466 DolphinStatusBar
* m_statusBar
;
468 KDirModel
* m_dirModel
;
469 DolphinDirLister
* m_dirLister
;
470 DolphinSortFilterProxyModel
* m_proxyModel
;
474 #endif // _DOLPHINVIEW_H_