]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinview.h
when the column view is used, then 'Split view' should take the root URL of the colum...
[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 /**
350 * Triggers to request user information for the item given
351 * by the URL \a url. The signal requestItemInfo is emitted,
352 * which provides a way for widgets to get an indication to update
353 * the item information.
354 */
355 void emitRequestItemInfo(const KUrl& url);
356
357 /** Returns true, if the filter bar is visible. */
358 bool isFilterBarVisible() const;
359
360 /**
361 * Return the DolphinMainWindow this View belongs to. It is guranteed
362 * that we have one.
363 */
364 DolphinMainWindow* mainWindow() const ;
365
366 /** Reloads the current directory. */
367 void reload();
368
369 /**
370 * Refreshs the view to get synchronized with the (updated) Dolphin settings.
371 * This method only needs to get invoked if the view settings for the Icons View,
372 * Details View or Columns View have been changed.
373 */
374 void refresh();
375
376 public slots:
377 /**
378 * Popups the filter bar above the status bar if \a show is true.
379 */
380 void showFilterBar(bool show);
381
382 /**
383 * Updates the number of items (= number of files + number of
384 * directories) in the statusbar. If files are selected, the number
385 * of selected files and the sum of the filesize is shown.
386 */
387 void updateStatusBar();
388
389 /**
390 * Requests the main window to set this view as active view, which
391 * means that all actions are applied to this view.
392 */
393 void requestActivation();
394
395 /**
396 * Request of a selection change. The view will do its best to accommodate
397 * the request, but it is not guaranteed that all items in \a selection
398 * will actually get selected. The view will e.g. not select items which
399 * are not in the currently displayed folder.
400 */
401 void changeSelection(const KFileItemList& selection);
402
403 signals:
404 /** Is emitted if URL of the view has been changed to \a url. */
405 void urlChanged(const KUrl& url);
406
407 /**
408 * Is emitted if the view mode (IconsView, DetailsView,
409 * PreviewsView) has been changed.
410 */
411 void modeChanged();
412
413 /** Is emitted if the 'show preview' property has been changed. */
414 void showPreviewChanged();
415
416 /** Is emitted if the 'show hidden files' property has been changed. */
417 void showHiddenFilesChanged();
418
419 /** Is emitted if the 'categorized sorting' property has been changed. */
420 void categorizedSortingChanged();
421
422 /** Is emitted if the sorting by name, size or date has been changed. */
423 void sortingChanged(DolphinView::Sorting sorting);
424
425 /** Is emitted if the sort order (ascending or descending) has been changed. */
426 void sortOrderChanged(Qt::SortOrder order);
427
428 /** Is emitted if the addtional information for an item has been changed. */
429 void additionalInfoChanged(KFileItemDelegate::AdditionalInformation info);
430
431 /**
432 * Is emitted if information of an item is requested to be shown e. g. in the sidebar.
433 * It the URL is empty, no item information request is pending.
434 */
435 void requestItemInfo(const KUrl& url);
436
437 /** Is emitted if the contents has been moved to \a x, \a y. */
438 void contentsMoved(int x, int y);
439
440 /**
441 * Is emitted whenever the selection has been changed.
442 */
443 void selectionChanged(const KFileItemList& selection);
444
445 /**
446 * Is emitted whenever the filter bar has been turned show or hidden.
447 */
448 void showFilterBarChanged(bool shown);
449
450 protected:
451 /** @see QWidget::mouseReleaseEvent */
452 virtual void mouseReleaseEvent(QMouseEvent* event);
453
454 private slots:
455 void changeDirectory(const KUrl& url);
456 void triggerItem(const QModelIndex& index);
457 void updateProgress(int percent);
458
459 /**
460 * Updates the number of items (= number of directories + number of files)
461 * and shows this information in the statusbar.
462 */
463 void updateItemCount();
464
465 /**
466 * Generates a preview image for each file item in \a items.
467 * The current preview settings (maximum size, 'Show Preview' menu)
468 * are respected.
469 */
470 void generatePreviews(const KFileItemList& items);
471
472 /**
473 * Replaces the icon of the item \a item by the preview pixmap
474 * \a pixmap.
475 */
476 void showPreview(const KFileItem& item, const QPixmap& pixmap);
477
478 /**
479 * Restores the x- and y-position of the contents if the
480 * current view is part of the history.
481 */
482 void restoreContentsPos();
483
484 /** Shows the information \a msg inside the statusbar. */
485 void showInfoMessage(const QString& msg);
486
487 /** Shows the error message \a msg inside the statusbar. */
488 void showErrorMessage(const QString& msg);
489
490 void emitSelectionChangedSignal();
491 void closeFilterBar();
492
493 /**
494 * Filters the currently shown items by \a nameFilter. All items
495 * which contain the given filter string will be shown.
496 */
497 void changeNameFilter(const QString& nameFilter);
498
499 /**
500 * Opens the context menu on position \a pos. The position
501 * is used to check whether the context menu is related to an
502 * item or to the viewport.
503 */
504 void openContextMenu(const QPoint& pos);
505
506 /**
507 * Drops the URLs \a urls to the index \a index. \a source
508 * indicates the widget where the dragging has been started from.
509 */
510 void dropUrls(const KUrl::List& urls,
511 const QModelIndex& index,
512 QWidget* source);
513
514 /**
515 * Drops the URLs \a urls at the
516 * destination \a destination.
517 */
518 void dropUrls(const KUrl::List& urls,
519 const KUrl& destination);
520 /**
521 * Updates the view properties of the current URL to the
522 * sorting given by \a sorting.
523 */
524 void updateSorting(DolphinView::Sorting sorting);
525
526 /**
527 * Updates the view properties of the current URL to the
528 * sort order given by \a order.
529 */
530 void updateSortOrder(Qt::SortOrder order);
531
532 /**
533 * Emits the signal contentsMoved with the current coordinates
534 * of the viewport as parameters.
535 */
536 void emitContentsMoved();
537
538 /**
539 * Updates the activation state of the view by checking whether
540 * the currently active view is this view.
541 */
542 void updateActivationState();
543
544 /** Applies an item effect to all cut items of the clipboard. */
545 void updateCutItems();
546
547 /**
548 * Updates the status bar to show hover information for the
549 * item with the index \a index. If currently other items are selected,
550 * no hover information is shown.
551 * @see DolphinView::clearHoverInformation()
552 */
553 void showHoverInformation(const QModelIndex& index);
554
555 /**
556 * Clears the hover information shown in the status bar.
557 * @see DolphinView::showHoverInformation().
558 */
559 void clearHoverInformation();
560
561 private:
562 void startDirLister(const KUrl& url, bool reload = false);
563
564 /**
565 * Returns the default text of the status bar, if no item is
566 * selected.
567 */
568 QString defaultStatusBarText() const;
569
570 /**
571 * Returns the text for the status bar, if at least one item
572 * is selected.
573 */
574 QString selectionStatusBarText() const;
575
576 /**
577 * Creates a new view representing the given view mode (DolphinView::mode()).
578 * The current view will get deleted.
579 */
580 void createView();
581
582 /**
583 * Selects all items by using the selection flags \a flags. This is a helper
584 * method for the slots DolphinView::selectAll() and DolphinView::invertSelection().
585 */
586 void selectAll(QItemSelectionModel::SelectionFlags flags);
587
588 /**
589 * Returns a pointer to the currently used item view, which is either
590 * a ListView or a TreeView.
591 */
592 QAbstractItemView* itemView() const;
593
594 /**
595 * Returns true if the index is valid and represents
596 * the column KDirModel::Name.
597 */
598 bool isValidNameIndex(const QModelIndex& index) const;
599
600 /**
601 * Returns true, if the item \a item has been cut into
602 * the clipboard.
603 */
604 bool isCutItem(const KFileItem& item) const;
605
606 /** Applies an item effect to all cut items. */
607 void applyCutItemEffect();
608
609 /**
610 * Returns true, if the ColumnView is activated. As the column view
611 * requires some special handling for iterating through directories,
612 * this method has been introduced for convenience.
613 */
614 bool isColumnViewActive() const
615 {
616 return m_columnView != 0;
617 }
618
619 private:
620 /**
621 * Remembers the original pixmap for an item before
622 * the cut effect is applied.
623 */
624 struct CutItem
625 {
626 KUrl url;
627 QPixmap pixmap;
628 };
629
630 bool m_showProgress;
631 bool m_blockContentsMovedSignal;
632 bool m_initializeColumnView;
633 Mode m_mode;
634
635 int m_iconSize;
636 int m_folderCount;
637 int m_fileCount;
638
639 DolphinMainWindow* m_mainWindow;
640 QVBoxLayout* m_topLayout;
641 KUrlNavigator* m_urlNavigator;
642
643 DolphinController* m_controller;
644 DolphinIconsView* m_iconsView;
645 DolphinDetailsView* m_detailsView;
646 DolphinColumnView* m_columnView;
647 KFileItemDelegate* m_fileItemDelegate;
648
649 FilterBar* m_filterBar;
650 DolphinStatusBar* m_statusBar;
651
652 KDirModel* m_dirModel;
653 DolphinDirLister* m_dirLister;
654 DolphinSortFilterProxyModel* m_proxyModel;
655
656 QList<CutItem> m_cutItemsCache;
657 };
658
659 #endif // _DOLPHINVIEW_H_