]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinview.h
don't trigger an item if the user does a selection by using the control- or shift...
[dolphin.git] / src / dolphinview.h
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
3 * Copyright (C) 2006 by Gregor Kališnik <gregor@podnapisi.net> *
4 * *
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. *
9 * *
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. *
14 * *
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 ***************************************************************************/
20
21
22 #ifndef _DOLPHINVIEW_H_
23 #define _DOLPHINVIEW_H_
24
25 #include <kparts/part.h>
26 #include <kfileitem.h>
27 #include <kfileiconview.h>
28 #include <kio/job.h>
29
30 #include <urlnavigator.h>
31
32 #include <QDropEvent>
33 #include <QLinkedList>
34 #include <QListView>
35 #include <QMouseEvent>
36 #include <QVBoxLayout>
37 #include <QWidget>
38
39 class FilterBar;
40 class KUrl;
41 class KDirModel;
42 class UrlNavigator;
43 class DolphinDetailsView;
44 class DolphinDirLister;
45 class DolphinIconsView;
46 class DolphinMainWindow;
47 class DolphinSortFilterProxyModel;
48 class DolphinStatusBar;
49 class QModelIndex;
50 class QPainter;
51 class QTimer;
52 class ViewProperties;
53
54 /**
55 * @short Represents a view for the directory content
56 * including the navigation bar and status bar.
57 *
58 * View modes for icons and details are supported. Currently
59 * Dolphin allows to have up to two views inside the main window.
60 *
61 * @see DolphinIconsView
62 * @see DolphinDetailsView
63 * @see UrlNavigator
64 * @see DolphinStatusBar
65 */
66 class DolphinView : public QWidget
67 {
68 Q_OBJECT
69
70 public:
71 /**
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).
76 */
77 enum Mode
78 {
79 /**
80 * The directory items are shown as icons including an
81 * icon name. */
82 IconsView = 0,
83
84 /**
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.
88 */
89 DetailsView = 1,
90 MaxModeEnum = DetailsView
91 };
92
93 /** Defines the sort order for the items of a directory. */
94 enum Sorting
95 {
96 SortByName = 0,
97 SortBySize,
98 SortByDate,
99 SortByPermissions,
100 SortByOwner,
101 SortByGroup,
102 MaxSortEnum = SortByGroup
103 };
104
105 DolphinView(DolphinMainWindow* mainwindow,
106 QWidget *parent,
107 const KUrl& url,
108 Mode mode = IconsView,
109 bool showHiddenFiles = false);
110
111 virtual ~DolphinView();
112
113 /**
114 * Sets the current active URL.
115 * The signals UrlNavigator::urlChanged() and UrlNavigator::historyChanged()
116 * are submitted.
117 */
118 void setUrl(const KUrl& url);
119
120 /** Returns the current active URL. */
121 const KUrl& url() const;
122
123 void requestActivation();
124 bool isActive() const;
125
126 /**
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.
131 */
132 void setMode(Mode mode);
133 Mode mode() const;
134
135 /**
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.
141 */
142 void setShowPreview(bool show);
143 bool showPreview() const;
144
145 /**
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.
151 */
152 void setShowHiddenFiles(bool show);
153 bool showHiddenFiles() const;
154
155 /**
156 * Triggers the renaming of the currently selected items, where
157 * the user must input a new name for the items.
158 */
159 void renameSelectedItems();
160
161 /**
162 * Selects all items.
163 * @see DolphinView::selectedItems()
164 */
165 void selectAll();
166
167 /**
168 * Inverts the current selection: selected items get unselected,
169 * unselected items get selected.
170 * @see DolphinView::selectedItems()
171 */
172 void invertSelection();
173
174 /**
175 * Goes back one step in the URL history. The signals
176 * UrlNavigator::urlChanged() and UrlNavigator::historyChanged()
177 * are submitted.
178 */
179 void goBack();
180
181 /**
182 * Goes forward one step in the Url history. The signals
183 * UrlNavigator::urlChanged() and UrlNavigator::historyChanged()
184 * are submitted.
185 */
186 void goForward();
187
188 /**
189 * Goes up one step of the Url path. The signals
190 * UrlNavigator::urlChanged() and UrlNavigator::historyChanged()
191 * are submitted.
192 */
193 void goUp();
194
195 /**
196 * Goes to the home URL. The signals UrlNavigator::urlChanged()
197 * and UrlNavigator::historyChanged() are submitted.
198 */
199 void goHome();
200
201 /**
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.
205 */
206 void setUrlEditable(bool editable);
207
208 /**
209 * Returns the complete URL history. The index 0 indicates the oldest
210 * history element.
211 * @param index Output parameter which indicates the current
212 * index of the location.
213 */
214 const QLinkedList<UrlNavigator::HistoryElem> urlHistory(int& index) const;
215
216 /**
217 * Returns true, if at least one item is selected.
218 */
219 bool hasSelection() const;
220
221 /**
222 * Returns the selected items. The list is empty if no item has been
223 * selected.
224 * @see DolphinView::selectedUrls()
225 */
226 KFileItemList selectedItems() const;
227
228 /**
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()
232 */
233 KUrl::List selectedUrls() const;
234
235 /**
236 * Returns the file item for the given model index \a index.
237 */
238 KFileItem* fileItem(const QModelIndex index) const;
239
240 /**
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.
244 */
245 void openContextMenu(KFileItem* fileInfo, const QPoint& pos);
246
247 /**
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.
251 */
252 void rename(const KUrl& source, const QString& newName);
253
254 /** Returns the status bar of the view. */
255 DolphinStatusBar* statusBar() const;
256
257 /**
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.
261 */
262 int contentsX() const;
263
264 /**
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.
268 */
269 int contentsY() const;
270
271 /**
272 * Returns true, if the URL shown by the navigation bar is editable.
273 * @see UrlNavigator
274 */
275 bool isUrlEditable() const;
276
277 /** Increases the size of the current set view mode. */
278 void zoomIn();
279
280 /** Decreases the size of the current set view mode. */
281 void zoomOut();
282
283 /**
284 * Returns true, if zooming in is possible. If false is returned,
285 * the minimal zoom size is possible.
286 */
287 bool isZoomInPossible() const;
288
289 /**
290 * Returns true, if zooming out is possible. If false is returned,
291 * the maximum zoom size is possible.
292 */
293 bool isZoomOutPossible() const;
294
295 /** Sets the sort order of the items inside a directory (see DolphinView::Sorting). */
296 void setSorting(Sorting sorting);
297
298 /** Returns the sort order of the items inside a directory (see DolphinView::Sorting). */
299 Sorting sorting() const;
300
301 /** Sets the sort order (Qt::Ascending or Qt::Descending) for the items. */
302 void setSortOrder(Qt::SortOrder order);
303
304 /** Returns the current used sort order (Qt::Ascending or Qt::Descending). */
305 Qt::SortOrder sortOrder() const;
306
307 /** Refreshs the view settings by reading out the stored settings. */
308 void refreshSettings();
309
310 /** Returns the UrlNavigator of the view for read access. */
311 const UrlNavigator* urlNavigator() const { return m_urlNavigator; }
312
313 /**
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.
318 */
319 void emitRequestItemInfo(const KUrl& url);
320
321 /** Returns true, if the filter bar is visible. */
322 bool isFilterBarVisible() const;
323
324 /**
325 * Return the DolphinMainWindow this View belongs to. It is guranteed
326 * that we have one.
327 */
328 DolphinMainWindow* mainWindow() const ;
329
330 /** Reloads the current directory. */
331 void reload();
332
333 /**
334 * Declare this View as the activeview of the mainWindow()
335 */
336 void declareViewActive();
337
338 public slots:
339 /**
340 * Popups the filter bar above the status bar if \a show is true.
341 */
342 void showFilterBar(bool show);
343
344 /**
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.
348 */
349 void updateStatusBar();
350
351 signals:
352 /** Is emitted if URL of the view has been changed to \a url. */
353 void urlChanged(const KUrl& url);
354
355 /**
356 * Is emitted if the view mode (IconsView, DetailsView,
357 * PreviewsView) has been changed.
358 */
359 void modeChanged();
360
361 /** Is emitted if the 'show preview' property has been changed. */
362 void showPreviewChanged();
363
364 /** Is emitted if the 'show hidden files' property has been changed. */
365 void showHiddenFilesChanged();
366
367 /** Is emitted if the sorting by name, size or date has been changed. */
368 void sortingChanged(DolphinView::Sorting sorting);
369
370 /** Is emitted if the sort order (ascending or descending) has been changed. */
371 void sortOrderChanged(Qt::SortOrder order);
372
373 /**
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.
376 */
377 void requestItemInfo(const KUrl& url);
378
379 /** Is emitted if the contents has been moved to \a x, \a y. */
380 void contentsMoved(int x, int y);
381
382 /**
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().
386 */
387 void selectionChanged();
388
389 /**
390 * Is emitted whenever the filter bar has been turned show or hidden.
391 */
392 void showFilterBarChanged(bool shown);
393
394 protected:
395 /** @see QWidget::mouseReleaseEvent */
396 virtual void mouseReleaseEvent(QMouseEvent* event);
397
398 private slots:
399 void loadDirectory(const KUrl& kurl);
400 void triggerItem(const QModelIndex& index);
401 void updateProgress(int percent);
402
403 /**
404 * Updates the number of items (= number of directories + number of files)
405 * and shows this information in the statusbar.
406 */
407 void updateItemCount();
408
409 /**
410 * Restores the x- and y-position of the contents if the
411 * current view is part of the history.
412 */
413 void restoreContentsPos();
414
415 /** Shows the information \a msg inside the statusbar. */
416 void showInfoMessage(const QString& msg);
417
418 /** Shows the error message \a msg inside the statusbar. */
419 void showErrorMessage(const QString& msg);
420
421 void emitSelectionChangedSignal();
422 void closeFilterBar();
423
424 /**
425 * Filters the currently shown items by \a nameFilter. All items
426 * which contain the given filter string will be shown.
427 */
428 void changeNameFilter(const QString& nameFilter);
429
430 private:
431 void startDirLister(const KUrl& url, bool reload = false);
432
433 /**
434 * Returns the default text of the status bar, if no item is
435 * selected.
436 */
437 QString defaultStatusBarText() const;
438
439 /**
440 * Returns the text for the status bar, if at least one item
441 * is selected.
442 */
443 QString selectionStatusBarText() const;
444
445 /**
446 * Creates a new view representing the given view mode (DolphinView::viewMode()).
447 * The current view will get deleted.
448 */
449 void createView();
450
451 /**
452 * Returns the column index used in the KDirModel depending on \a sorting.
453 */
454 int columnIndex(Sorting sorting) const;
455
456 /**
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().
459 */
460 void selectAll(QItemSelectionModel::SelectionFlags flags);
461
462 /**
463 * Returns a pointer to the currently used item view, which is either
464 * a ListView or a TreeView.
465 */
466 QAbstractItemView* itemView() const;
467
468 private:
469 bool m_showProgress;
470 Mode m_mode;
471
472 int m_iconSize;
473 int m_folderCount;
474 int m_fileCount;
475
476 DolphinMainWindow* m_mainWindow;
477 QVBoxLayout* m_topLayout;
478 UrlNavigator* m_urlNavigator;
479
480 DolphinIconsView* m_iconsView;
481 DolphinDetailsView* m_detailsView;
482
483 FilterBar* m_filterBar;
484 DolphinStatusBar* m_statusBar;
485
486 KDirModel* m_dirModel;
487 DolphinDirLister* m_dirLister;
488 DolphinSortFilterProxyModel* m_proxyModel;
489 };
490
491 #endif // _DOLPHINVIEW_H_