]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinview.h
- assure that when hovering the viewport that an empty request for item information...
[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 <kfileitemdelegate.h>
28 #include <kio/job.h>
29
30 #include <kurlnavigator.h>
31
32 #include <QtGui/QKeyEvent>
33 #include <QtCore/QLinkedList>
34 #include <QtGui/QListView>
35 #include <QtGui/QBoxLayout>
36 #include <QtGui/QWidget>
37
38 class DolphinController;
39 class FilterBar;
40 class KFileItemDelegate;
41 class KUrl;
42 class KDirModel;
43 class KUrlNavigator;
44 class DolphinColumnView;
45 class DolphinDetailsView;
46 class DolphinDirLister;
47 class DolphinIconsView;
48 class DolphinMainWindow;
49 class DolphinSortFilterProxyModel;
50 class DolphinStatusBar;
51 class QModelIndex;
52 class QPainter;
53 class QTimer;
54 class ViewProperties;
55
56 /**
57 * @short Represents a view for the directory content
58 * including the navigation bar, filter bar and status bar.
59 *
60 * View modes for icons, details and columns are supported. Currently
61 * Dolphin allows to have up to two views inside the main window.
62 *
63 * @see DolphinIconsView
64 * @see DolphinDetailsView
65 * @see DolphinColumnView
66 * @see KUrlNavigator
67 * @see DolphinStatusBar
68 */
69 class DolphinView : public QWidget
70 {
71 Q_OBJECT
72
73 public:
74 /**
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).
79 */
80 enum Mode
81 {
82 /**
83 * The directory items are shown as icons including an
84 * icon name. */
85 IconsView = 0,
86
87 /**
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.
91 */
92 DetailsView = 1,
93
94 /**
95 * Each folder is shown in a separate column.
96 */
97 ColumnView = 2,
98 MaxModeEnum = ColumnView
99 };
100
101 /** Defines the sort order for the items of a directory. */
102 enum Sorting
103 {
104 SortByName = 0,
105 SortBySize,
106 SortByDate,
107 SortByPermissions,
108 SortByOwner,
109 SortByGroup,
110 SortByType,
111 MaxSortEnum = SortByType
112 };
113
114 DolphinView(DolphinMainWindow* mainwindow,
115 QWidget *parent,
116 const KUrl& url,
117 Mode mode = IconsView,
118 bool showHiddenFiles = false);
119
120 virtual ~DolphinView();
121
122 /**
123 * Sets the current active URL, where all actions are applied. The
124 * URL navigator is synchronized with this URL. The signals
125 * KUrlNavigator::urlChanged() and KUrlNavigator::historyChanged()
126 * are emitted.
127 * @see DolphinView::urlNavigator()
128 */
129 void setUrl(const KUrl& url);
130
131 /**
132 * Returns the current active URL, where all actions are applied.
133 * The URL navigator is synchronized with this URL.
134 */
135 const KUrl& url() const;
136
137 /**
138 * Returns the root URL of the view, which is defined as the first
139 * visible path of DolphinView::url(). Usually the root URL is
140 * equal to DolphinView::url(), but in the case of the column view
141 * when 2 columns are shown, the root URL might be:
142 * /home/peter/Documents
143 * and DolphinView::url() might return
144 * /home/peter/Documents/Music/
145 */
146 KUrl rootUrl() const;
147
148 /**
149 * Returns true if the view is active and hence all actions are
150 * applied to this view.
151 */
152 bool isActive() const;
153
154 /**
155 * Changes the view mode for the current directory to \a mode.
156 * If the view properties should be remembered for each directory
157 * (GeneralSettings::globalViewProps() returns false), then the
158 * changed view mode will be be stored automatically.
159 */
160 void setMode(Mode mode);
161 Mode mode() const;
162
163 /**
164 * Turns on the file preview for the all files of the current directory,
165 * if \a show is true.
166 * If the view properties should be remembered for each directory
167 * (GeneralSettings::globalViewProps() returns false), then the
168 * preview setting will be be stored automatically.
169 */
170 void setShowPreview(bool show);
171 bool showPreview() const;
172
173 /**
174 * Shows all hidden files of the current directory,
175 * if \a show is true.
176 * If the view properties should be remembered for each directory
177 * (GeneralSettings::globalViewProps() returns false), then the
178 * show hidden file setting will be be stored automatically.
179 */
180 void setShowHiddenFiles(bool show);
181 bool showHiddenFiles() const;
182
183 /**
184 * Summarizes all sorted items by their category \a categorized
185 * is true.
186 * If the view properties should be remembered for each directory
187 * (GeneralSettings::globalViewProps() returns false), then the
188 * categorized sorting setting will be be stored automatically.
189 */
190 void setCategorizedSorting(bool categorized);
191 bool categorizedSorting() const;
192
193 /**
194 * Returns true, if the categorized sorting is supported by the current
195 * used mode (see DolphinView::setMode()). Currently only DolphinView::IconsView
196 * supports categorizations. To check whether the categorized
197 * sorting is set, use DolphinView::categorizedSorting().
198 */
199 bool supportsCategorizedSorting() const;
200
201 /**
202 * Triggers the renaming of the currently selected items, where
203 * the user must input a new name for the items.
204 */
205 void renameSelectedItems();
206
207 /**
208 * Selects all items.
209 * @see DolphinView::selectedItems()
210 */
211 void selectAll();
212
213 /**
214 * Inverts the current selection: selected items get unselected,
215 * unselected items get selected.
216 * @see DolphinView::selectedItems()
217 */
218 void invertSelection();
219
220 /**
221 * Goes back one step in the URL history. The signals
222 * KUrlNavigator::urlChanged() and KUrlNavigator::historyChanged()
223 * are submitted.
224 */
225 void goBack();
226
227 /**
228 * Goes forward one step in the Url history. The signals
229 * KUrlNavigator::urlChanged() and KUrlNavigator::historyChanged()
230 * are submitted.
231 */
232 void goForward();
233
234 /**
235 * Goes up one step of the Url path. The signals
236 * KUrlNavigator::urlChanged() and KUrlNavigator::historyChanged()
237 * are submitted.
238 */
239 void goUp();
240
241 /**
242 * Goes to the home URL. The signals KUrlNavigator::urlChanged()
243 * and KUrlNavigator::historyChanged() are submitted.
244 */
245 void goHome();
246
247 /**
248 * Sets the URL of the navigation bar to an editable state
249 * if \a editable is true. If \a editable is false, each part of
250 * the location is presented by a button for a fast navigation.
251 */
252 void setUrlEditable(bool editable);
253
254 /** Returns true, if at least one item is selected. */
255 bool hasSelection() const;
256
257 void clearSelection();
258
259 /**
260 * Returns the selected items. The list is empty if no item has been
261 * selected.
262 * @see DolphinView::selectedUrls()
263 */
264 KFileItemList selectedItems() const;
265
266 /**
267 * Returns a list of URLs for all selected items. An empty list
268 * is returned, if no item is selected.
269 * @see DolphinView::selectedItems()
270 */
271 KUrl::List selectedUrls() const;
272
273 /**
274 * Returns the file item for the given model index \a index.
275 */
276 KFileItem* fileItem(const QModelIndex index) const;
277
278 /**
279 * Renames the filename of the source URL by the new file name.
280 * If the new file name already exists, a dialog is opened which
281 * asks the user to enter a new name.
282 */
283 void rename(const KUrl& source, const QString& newName);
284
285 DolphinStatusBar* statusBar() const;
286
287 /**
288 * Returns the x-position of the view content.
289 * The content of the view might be larger than the visible area
290 * and hence a scrolling must be done.
291 */
292 int contentsX() const;
293
294 /**
295 * Returns the y-position of the view content.
296 * The content of the view might be larger than the visible area
297 * and hence a scrolling must be done.
298 */
299 int contentsY() const;
300
301 /**
302 * Returns true, if the URL shown by the navigation bar is editable.
303 * @see KUrlNavigator
304 */
305 bool isUrlEditable() const;
306
307 /** Increases the size of the current set view mode. */
308 void zoomIn();
309
310 /** Decreases the size of the current set view mode. */
311 void zoomOut();
312
313 /**
314 * Returns true, if zooming in is possible. If false is returned,
315 * the minimal zoom size is possible.
316 */
317 bool isZoomInPossible() const;
318
319 /**
320 * Returns true, if zooming out is possible. If false is returned,
321 * the maximum zoom size is possible.
322 */
323 bool isZoomOutPossible() const;
324
325 /** Sets the sort order of the items inside a directory (see DolphinView::Sorting). */
326 void setSorting(Sorting sorting);
327
328 /** Returns the sort order of the items inside a directory (see DolphinView::Sorting). */
329 Sorting sorting() const;
330
331 /** Sets the sort order (Qt::Ascending or Qt::Descending) for the items. */
332 void setSortOrder(Qt::SortOrder order);
333
334 /** Returns the current used sort order (Qt::Ascending or Qt::Descending). */
335 Qt::SortOrder sortOrder() const;
336
337 /** Sets the additional information which should be shown for the items. */
338 void setAdditionalInfo(KFileItemDelegate::AdditionalInformation info);
339
340 /** Returns the additional information which should be shown for the items. */
341 KFileItemDelegate::AdditionalInformation additionalInfo() const;
342
343 /** Returns the KUrlNavigator of the view for read access. */
344 const KUrlNavigator* urlNavigator() const
345 {
346 return m_urlNavigator;
347 }
348
349 /** Returns true, if the filter bar is visible. */
350 bool isFilterBarVisible() const;
351
352 /**
353 * Return the DolphinMainWindow this View belongs to. It is guranteed
354 * that we have one.
355 */
356 DolphinMainWindow* mainWindow() const ;
357
358 /** Reloads the current directory. */
359 void reload();
360
361 /**
362 * Refreshs the view to get synchronized with the (updated) Dolphin settings.
363 * This method only needs to get invoked if the view settings for the Icons View,
364 * Details View or Columns View have been changed.
365 */
366 void refresh();
367
368 public slots:
369 /**
370 * Popups the filter bar above the status bar if \a show is true.
371 */
372 void showFilterBar(bool show);
373
374 /**
375 * Updates the number of items (= number of files + number of
376 * directories) in the statusbar. If files are selected, the number
377 * of selected files and the sum of the filesize is shown.
378 */
379 void updateStatusBar();
380
381 /**
382 * Requests the main window to set this view as active view, which
383 * means that all actions are applied to this view.
384 */
385 void requestActivation();
386
387 /**
388 * Request of a selection change. The view will do its best to accommodate
389 * the request, but it is not guaranteed that all items in \a selection
390 * will actually get selected. The view will e.g. not select items which
391 * are not in the currently displayed folder.
392 */
393 void changeSelection(const KFileItemList& selection);
394
395 signals:
396 /** Is emitted if URL of the view has been changed to \a url. */
397 void urlChanged(const KUrl& url);
398
399 /**
400 * Is emitted if the view mode (IconsView, DetailsView,
401 * PreviewsView) has been changed.
402 */
403 void modeChanged();
404
405 /** Is emitted if the 'show preview' property has been changed. */
406 void showPreviewChanged();
407
408 /** Is emitted if the 'show hidden files' property has been changed. */
409 void showHiddenFilesChanged();
410
411 /** Is emitted if the 'categorized sorting' property has been changed. */
412 void categorizedSortingChanged();
413
414 /** Is emitted if the sorting by name, size or date has been changed. */
415 void sortingChanged(DolphinView::Sorting sorting);
416
417 /** Is emitted if the sort order (ascending or descending) has been changed. */
418 void sortOrderChanged(Qt::SortOrder order);
419
420 /** Is emitted if the addtional information for an item has been changed. */
421 void additionalInfoChanged(KFileItemDelegate::AdditionalInformation info);
422
423 /**
424 * Is emitted if information of an item is requested to be shown e. g. in the sidebar.
425 * It the URL is empty, no item information request is pending.
426 */
427 void requestItemInfo(const KUrl& url);
428
429 /** Is emitted if the contents has been moved to \a x, \a y. */
430 void contentsMoved(int x, int y);
431
432 /**
433 * Is emitted whenever the selection has been changed.
434 */
435 void selectionChanged(const KFileItemList& selection);
436
437 /**
438 * Is emitted whenever the filter bar has been turned show or hidden.
439 */
440 void showFilterBarChanged(bool shown);
441
442 protected:
443 /** @see QWidget::mouseReleaseEvent */
444 virtual void mouseReleaseEvent(QMouseEvent* event);
445
446 private slots:
447 void changeDirectory(const KUrl& url);
448 void triggerItem(const QModelIndex& index);
449 void updateProgress(int percent);
450
451 /**
452 * Updates the number of items (= number of directories + number of files)
453 * and shows this information in the statusbar.
454 */
455 void updateItemCount();
456
457 /**
458 * Generates a preview image for each file item in \a items.
459 * The current preview settings (maximum size, 'Show Preview' menu)
460 * are respected.
461 */
462 void generatePreviews(const KFileItemList& items);
463
464 /**
465 * Replaces the icon of the item \a item by the preview pixmap
466 * \a pixmap.
467 */
468 void showPreview(const KFileItem& item, const QPixmap& pixmap);
469
470 /**
471 * Restores the x- and y-position of the contents if the
472 * current view is part of the history.
473 */
474 void restoreContentsPos();
475
476 /** Shows the information \a msg inside the statusbar. */
477 void showInfoMessage(const QString& msg);
478
479 /** Shows the error message \a msg inside the statusbar. */
480 void showErrorMessage(const QString& msg);
481
482 void emitSelectionChangedSignal();
483 void closeFilterBar();
484
485 /**
486 * Filters the currently shown items by \a nameFilter. All items
487 * which contain the given filter string will be shown.
488 */
489 void changeNameFilter(const QString& nameFilter);
490
491 /**
492 * Opens the context menu on position \a pos. The position
493 * is used to check whether the context menu is related to an
494 * item or to the viewport.
495 */
496 void openContextMenu(const QPoint& pos);
497
498 /**
499 * Drops the URLs \a urls to the index \a index. \a source
500 * indicates the widget where the dragging has been started from.
501 */
502 void dropUrls(const KUrl::List& urls,
503 const QModelIndex& index,
504 QWidget* source);
505
506 /**
507 * Drops the URLs \a urls at the
508 * destination \a destination.
509 */
510 void dropUrls(const KUrl::List& urls,
511 const KUrl& destination);
512 /**
513 * Updates the view properties of the current URL to the
514 * sorting given by \a sorting.
515 */
516 void updateSorting(DolphinView::Sorting sorting);
517
518 /**
519 * Updates the view properties of the current URL to the
520 * sort order given by \a order.
521 */
522 void updateSortOrder(Qt::SortOrder order);
523
524 /**
525 * Emits the signal contentsMoved with the current coordinates
526 * of the viewport as parameters.
527 */
528 void emitContentsMoved();
529
530 /**
531 * Updates the activation state of the view by checking whether
532 * the currently active view is this view.
533 */
534 void updateActivationState();
535
536 /** Applies an item effect to all cut items of the clipboard. */
537 void updateCutItems();
538
539 /**
540 * Updates the status bar to show hover information for the
541 * item with the index \a index. If currently other items are selected,
542 * no hover information is shown.
543 * @see DolphinView::clearHoverInformation()
544 */
545 void showHoverInformation(const QModelIndex& index);
546
547 /**
548 * Clears the hover information shown in the status bar.
549 * @see DolphinView::showHoverInformation().
550 */
551 void clearHoverInformation();
552
553 private:
554 void startDirLister(const KUrl& url, bool reload = false);
555
556 /**
557 * Returns the default text of the status bar, if no item is
558 * selected.
559 */
560 QString defaultStatusBarText() const;
561
562 /**
563 * Returns the text for the status bar, if at least one item
564 * is selected.
565 */
566 QString selectionStatusBarText() const;
567
568 /**
569 * Creates a new view representing the given view mode (DolphinView::mode()).
570 * The current view will get deleted.
571 */
572 void createView();
573
574 /**
575 * Selects all items by using the selection flags \a flags. This is a helper
576 * method for the slots DolphinView::selectAll() and DolphinView::invertSelection().
577 */
578 void selectAll(QItemSelectionModel::SelectionFlags flags);
579
580 /**
581 * Returns a pointer to the currently used item view, which is either
582 * a ListView or a TreeView.
583 */
584 QAbstractItemView* itemView() const;
585
586 /**
587 * Returns true if the index is valid and represents
588 * the column KDirModel::Name.
589 */
590 bool isValidNameIndex(const QModelIndex& index) const;
591
592 /**
593 * Returns true, if the item \a item has been cut into
594 * the clipboard.
595 */
596 bool isCutItem(const KFileItem& item) const;
597
598 /** Applies an item effect to all cut items. */
599 void applyCutItemEffect();
600
601 /**
602 * Returns true, if the ColumnView is activated. As the column view
603 * requires some special handling for iterating through directories,
604 * this method has been introduced for convenience.
605 */
606 bool isColumnViewActive() const
607 {
608 return m_columnView != 0;
609 }
610
611 private:
612 /**
613 * Remembers the original pixmap for an item before
614 * the cut effect is applied.
615 */
616 struct CutItem
617 {
618 KUrl url;
619 QPixmap pixmap;
620 };
621
622 bool m_showProgress;
623 bool m_blockContentsMovedSignal;
624 bool m_initializeColumnView;
625 Mode m_mode;
626
627 int m_iconSize;
628 int m_folderCount;
629 int m_fileCount;
630
631 DolphinMainWindow* m_mainWindow;
632 QVBoxLayout* m_topLayout;
633 KUrlNavigator* m_urlNavigator;
634
635 DolphinController* m_controller;
636 DolphinIconsView* m_iconsView;
637 DolphinDetailsView* m_detailsView;
638 DolphinColumnView* m_columnView;
639 KFileItemDelegate* m_fileItemDelegate;
640
641 FilterBar* m_filterBar;
642 DolphinStatusBar* m_statusBar;
643
644 KDirModel* m_dirModel;
645 DolphinDirLister* m_dirLister;
646 DolphinSortFilterProxyModel* m_proxyModel;
647
648 QList<CutItem> m_cutItemsCache;
649 };
650
651 #endif // _DOLPHINVIEW_H_