]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinview.h
Forgot to modify the code for category selection. Fixed.
[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 <config-nepomuk.h>
26
27 #include "libdolphin_export.h"
28
29 #include <kparts/part.h>
30 #include <kfileitem.h>
31 #include <kfileitemdelegate.h>
32 #include <konq_fileundomanager.h>
33 #include <kio/job.h>
34
35 #include <QBoxLayout>
36 #include <QKeyEvent>
37 #include <QLinkedList>
38 #include <QListView>
39 #include <QWidget>
40
41 class KAction;
42 class KToggleAction;
43 class DolphinController;
44 class KDirLister;
45 class KFileItemDelegate;
46 class KUrl;
47 class DolphinModel;
48 class DolphinColumnView;
49 class DolphinDetailsView;
50 class DolphinIconsView;
51 class DolphinMainWindow;
52 class DolphinSortFilterProxyModel;
53 class QModelIndex;
54 class ViewProperties;
55 namespace KIO
56 {
57 class PreviewJob;
58 }
59
60 /**
61 * @short Represents a view for the directory content.
62 *
63 * View modes for icons, details and columns are supported. It's
64 * possible to adjust:
65 * - sort order
66 * - sort type
67 * - show hidden files
68 * - show previews
69 *
70 * @see DolphinIconsView
71 * @see DolphinDetailsView
72 * @see DolphinColumnView
73 */
74 class LIBDOLPHINPRIVATE_EXPORT DolphinView : public QWidget
75 {
76 Q_OBJECT
77
78 public:
79 /**
80 * Defines the view mode for a directory. The view mode
81 * can be defined when constructing a DolphinView. The
82 * view mode is automatically updated if the directory itself
83 * defines a view mode (see class ViewProperties for details).
84 */
85 enum Mode
86 {
87 /**
88 * The directory items are shown as icons including an
89 * icon name. */
90 IconsView = 0,
91
92 /**
93 * The icon, the name and at least the size of the directory
94 * items are shown in a table. It is possible to add columns
95 * for date, group and permissions.
96 */
97 DetailsView = 1,
98
99 /**
100 * Each folder is shown in a separate column.
101 */
102 ColumnView = 2,
103 MaxModeEnum = ColumnView
104 };
105
106 /** Defines the sort order for the items of a directory. */
107 enum Sorting
108 {
109 SortByName = 0,
110 SortBySize,
111 SortByDate,
112 SortByPermissions,
113 SortByOwner,
114 SortByGroup,
115 SortByType,
116 SortByRating,
117 SortByTags,
118 MaxSortEnum = SortByTags
119 };
120
121 /**
122 * @param parent Parent widget of the view.
123 * @param url Specifies the content which should be shown.
124 * @param dirLister Used directory lister. The lister is not owned
125 * by the view and won't get deleted.
126 * @param dolphinModel Used directory model. The model is not owned
127 * by the view and won't get deleted.
128 * @param proxyModel Used proxy model which specifies the sorting. The
129 * model is not owned by the view and won't get
130 * deleted.
131 */
132 DolphinView(QWidget* parent,
133 const KUrl& url,
134 KDirLister* dirLister,
135 DolphinModel* dolphinModel,
136 DolphinSortFilterProxyModel* proxyModel);
137
138 virtual ~DolphinView();
139
140 /**
141 * Returns the current active URL, where all actions are applied.
142 * The URL navigator is synchronized with this URL.
143 */
144 const KUrl& url() const;
145
146 /**
147 * Returns the root URL of the view, which is defined as the first
148 * visible path of DolphinView::url(). Usually the root URL is
149 * equal to DolphinView::url(), but in the case of the column view
150 * when 2 columns are shown, the root URL might be:
151 * /home/peter/Documents
152 * and DolphinView::url() might return
153 * /home/peter/Documents/Music/
154 */
155 KUrl rootUrl() const;
156
157 /**
158 * If \a active is true, the view will marked as active. The active
159 * view is defined as view where all actions are applied to.
160 */
161 void setActive(bool active);
162 bool isActive() const;
163
164 /**
165 * Changes the view mode for the current directory to \a mode.
166 * If the view properties should be remembered for each directory
167 * (GeneralSettings::globalViewProps() returns false), then the
168 * changed view mode will be be stored automatically.
169 */
170 void setMode(Mode mode);
171 Mode mode() const;
172
173 /**
174 * Turns on the file preview for the all 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 * preview setting will be be stored automatically.
179 */
180 void setShowPreview(bool show);
181 bool showPreview() const;
182
183 /**
184 * Shows all hidden files of the current directory,
185 * if \a show is true.
186 * If the view properties should be remembered for each directory
187 * (GeneralSettings::globalViewProps() returns false), then the
188 * show hidden file setting will be be stored automatically.
189 */
190 void setShowHiddenFiles(bool show);
191 bool showHiddenFiles() const;
192
193 /**
194 * Summarizes all sorted items by their category \a categorized
195 * is true.
196 * If the view properties should be remembered for each directory
197 * (GeneralSettings::globalViewProps() returns false), then the
198 * categorized sorting setting will be be stored automatically.
199 */
200 void setCategorizedSorting(bool categorized);
201 bool categorizedSorting() const;
202
203 /**
204 * Returns true, if the categorized sorting is supported by the current
205 * used mode (see DolphinView::setMode()). Currently only DolphinView::IconsView
206 * supports categorizations. To check whether the categorized
207 * sorting is set, use DolphinView::categorizedSorting().
208 */
209 bool supportsCategorizedSorting() const;
210
211 /**
212 * Selects all items.
213 * @see DolphinView::selectedItems()
214 */
215 void selectAll();
216
217 /**
218 * Inverts the current selection: selected items get unselected,
219 * unselected items get selected.
220 * @see DolphinView::selectedItems()
221 */
222 void invertSelection();
223
224 /** Returns true, if at least one item is selected. */
225 bool hasSelection() const;
226
227 void clearSelection();
228
229 /**
230 * Returns the selected items. The list is empty if no item has been
231 * selected.
232 * @see DolphinView::selectedUrls()
233 */
234 KFileItemList selectedItems() const;
235
236 /**
237 * Returns a list of URLs for all selected items. An empty list
238 * is returned, if no item is selected.
239 * @see DolphinView::selectedItems()
240 */
241 KUrl::List selectedUrls() const;
242
243 /**
244 * Returns the file item for the given model index \a index.
245 */
246 KFileItem fileItem(const QModelIndex& index) const;
247
248 /**
249 * Sets the upper left position of the view content
250 * to (x,y). The content of the view might be larger than the visible area
251 * and hence a scrolling must be done.
252 */
253 void setContentsPosition(int x, int y);
254
255 /** Returns the upper left position of the view content. */
256 QPoint contentsPosition() const;
257
258 /** Increases the size of the current set view mode. */
259 void zoomIn();
260
261 /** Decreases the size of the current set view mode. */
262 void zoomOut();
263
264 /**
265 * Returns true, if zooming in is possible. If false is returned,
266 * the minimal zoom size is possible.
267 */
268 bool isZoomInPossible() const;
269
270 /**
271 * Returns true, if zooming out is possible. If false is returned,
272 * the maximum zoom size is possible.
273 */
274 bool isZoomOutPossible() const;
275
276 /** Sets the sort order of the items inside a directory (see DolphinView::Sorting). */
277 void setSorting(Sorting sorting);
278
279 /** Returns the sort order of the items inside a directory (see DolphinView::Sorting). */
280 Sorting sorting() const;
281
282 /** Sets the sort order (Qt::Ascending or Qt::Descending) for the items. */
283 void setSortOrder(Qt::SortOrder order);
284
285 /** Returns the current used sort order (Qt::Ascending or Qt::Descending). */
286 Qt::SortOrder sortOrder() const;
287
288 /** Sets the additional information which should be shown for the items. */
289 void setAdditionalInfo(KFileItemDelegate::InformationList info);
290
291 /** Returns the additional information which should be shown for the items. */
292 KFileItemDelegate::InformationList additionalInfo() const;
293
294 /** Reloads the current directory. */
295 void reload();
296
297 /**
298 * Refreshes the view to get synchronized with the (updated) Dolphin settings.
299 * This method only needs to get invoked if the view settings for the Icons View,
300 * Details View or Columns View have been changed.
301 */
302 void refresh();
303
304 /**
305 * Changes the directory of the view to \a url. If \a rootUrl is empty, the view
306 * properties from \a url are used for adjusting the view mode and the other properties.
307 * If \a rootUrl is not empty, the view properties from the root URL are considered
308 * instead. Specifying a root URL is only required if a view having a different root URL
309 * (e. g. the column view) should be restored. Usually using DolphinView::setUrl()
310 * is enough for changing the current URL.
311 */
312 void updateView(const KUrl& url, const KUrl& rootUrl);
313
314 /**
315 * Filters the currently shown items by \a nameFilter. All items
316 * which contain the given filter string will be shown.
317 */
318 void setNameFilter(const QString& nameFilter);
319
320 /**
321 * Calculates the number of currently shown files into
322 * \a fileCount and the number of folders into \a folderCount.
323 * It is recommend using this method instead of asking the
324 * directory lister or the model directly, as it takes
325 * filtering and hierarchical previews into account.
326 */
327 void calculateItemCount(int& fileCount, int& folderCount);
328
329 /**
330 * Returns the "switch to icons mode" action.
331 * This code is here to share it between the mainwindow and the part
332 */
333 static KToggleAction* iconsModeAction(KActionCollection* collection);
334
335 /**
336 * Returns the "switch to details mode" action.
337 * This code is here to share it between the mainwindow and the part
338 */
339 static KToggleAction* detailsModeAction(KActionCollection* collection);
340
341 /**
342 * Returns the "switch to columns mode" action.
343 * This code is here to share it between the mainwindow and the part
344 */
345 static KToggleAction* columnsModeAction(KActionCollection* collection);
346
347 /**
348 * Creates the rename action.
349 * This code is here to share it between the mainwindow and the part
350 */
351 static KAction* createRenameAction(KActionCollection* collection);
352
353 /**
354 * Creates the "move to trash" action.
355 * This code is here to share it between the mainwindow and the part
356 */
357 static KAction* createMoveToTrashAction(KActionCollection* collection);
358
359 /**
360 * Creates the delete action.
361 * This code is here to share it between the mainwindow and the part
362 */
363 static KAction* createDeleteAction(KActionCollection* collection);
364
365 /**
366 * Returns the action name corresponding to the current view mode
367 */
368 QString currentViewModeActionName() const;
369
370 /**
371 * Returns the state of the paste action:
372 * first is whether the action should be enabled
373 * second is the text for the action
374 */
375 QPair<bool, QString> pasteInfo() const;
376
377 public slots:
378 /**
379 * Changes the directory to \a url. If the current directory is equal to
380 * \a url, nothing will be done (use DolphinView::reload() instead).
381 */
382 void setUrl(const KUrl& url);
383
384 /**
385 * Request of a selection change. The view will do its best to accommodate
386 * the request, but it is not guaranteed that all items in \a selection
387 * will actually get selected. The view will e.g. not select items which
388 * are not in the currently displayed folder.
389 */
390 void changeSelection(const KFileItemList& selection);
391
392 /**
393 * Triggers the renaming of the currently selected items, where
394 * the user must input a new name for the items.
395 */
396 void renameSelectedItems();
397
398 /**
399 * Moves all selected items to the trash.
400 */
401 void trashSelectedItems();
402
403 /**
404 * Deletes all selected items.
405 */
406 void deleteSelectedItems();
407
408 /**
409 * Copies all selected items to the clipboard and marks
410 * the items as cutted.
411 */
412 void cutSelectedItems();
413
414 /** Copies all selected items to the clipboard. */
415 void copySelectedItems();
416
417 /** Pastes the clipboard data to this view. */
418 void paste();
419
420 signals:
421 /**
422 * Is emitted if the view has been activated by e. g. a mouse click.
423 */
424 void activated();
425
426 /** Is emitted if URL of the view has been changed to \a url. */
427 void urlChanged(const KUrl& url);
428
429 /**
430 * Is emitted when clicking on an item
431 */
432 void itemTriggered(const KFileItem& item);
433
434 /**
435 * Is emitted if the view mode (IconsView, DetailsView,
436 * PreviewsView) has been changed.
437 */
438 void modeChanged();
439
440 /** Is emitted if the 'show preview' property has been changed. */
441 void showPreviewChanged();
442
443 /** Is emitted if the 'show hidden files' property has been changed. */
444 void showHiddenFilesChanged();
445
446 /** Is emitted if the 'categorized sorting' property has been changed. */
447 void categorizedSortingChanged();
448
449 /** Is emitted if the sorting by name, size or date has been changed. */
450 void sortingChanged(DolphinView::Sorting sorting);
451
452 /** Is emitted if the sort order (ascending or descending) has been changed. */
453 void sortOrderChanged(Qt::SortOrder order);
454
455 /** Is emitted if the additional information for an item has been changed. */
456 void additionalInfoChanged(const KFileItemDelegate::InformationList& info);
457
458 /**
459 * Is emitted if information of an item is requested to be shown e. g. in the sidebar.
460 * If item is null, no item information request is pending.
461 */
462 void requestItemInfo(const KFileItem& item);
463
464 /** Is emitted if the contents has been moved to \a x, \a y. */
465 void contentsMoved(int x, int y);
466
467 /**
468 * Is emitted whenever the selection has been changed.
469 */
470 void selectionChanged(const KFileItemList& selection);
471
472 /**
473 * Is emitted if a context menu is requested for the item \a item,
474 * which is part of \a url. If the item is 0, the context menu
475 * for the URL should be shown.
476 */
477 void requestContextMenu(const KFileItem& item, const KUrl& url);
478
479 /**
480 * Is emitted if the URLs \a are dropped to the destination URL
481 * \a destination. No operation is done within the DolphinView, the
482 * receiver of the signal has to take care about the corresponding
483 * operation.
484 */
485 void urlsDropped(const KUrl::List& urls, const KUrl& destination);
486
487 /**
488 * Is emitted if an information message with the content \a msg
489 * should be shown.
490 */
491 void infoMessage(const QString& msg);
492
493 /**
494 * Is emitted if an error message with the content \a msg
495 * should be shown.
496 */
497 void errorMessage(const QString& msg);
498
499 /**
500 * Is emitted if an "operation completed" message with the content \a msg
501 * should be shown.
502 */
503 void operationCompletedMessage(const QString& msg);
504
505 /**
506 * Is emitted after DolphinView::setUrl() has been invoked and
507 * the path \a url is currently loaded. If this signal is emitted,
508 * it is assured that the view contains already the correct root
509 * URL and property settings.
510 */
511 void startedPathLoading(const KUrl& url);
512
513 /**
514 * Is emitted when renaming, copying, moving, linking etc.
515 * Used for feedback in the mainwindow.
516 */
517 void doingOperation(KonqFileUndoManager::CommandType type);
518
519 protected:
520 /** @see QWidget::mouseReleaseEvent */
521 virtual void mouseReleaseEvent(QMouseEvent* event);
522
523 private slots:
524 /**
525 * Marks the view as active (DolphinView:isActive() will return true)
526 * and emits the 'activated' signal if it is not already active.
527 */
528 void activate();
529
530 /**
531 * If the item \a item is a directory, then this
532 * directory will be loaded. If the item is a file, the corresponding
533 * application will get started.
534 */
535 void triggerItem(const KFileItem& index);
536
537 /**
538 * Generates a preview image for each file item in \a items.
539 * The current preview settings (maximum size, 'Show Preview' menu)
540 * are respected.
541 */
542 void generatePreviews(const KFileItemList& items);
543
544 /**
545 * Replaces the icon of the item \a item by the preview pixmap
546 * \a pixmap.
547 */
548 void replaceIcon(const KFileItem& item, const QPixmap& pixmap);
549
550 void emitSelectionChangedSignal();
551
552 /**
553 * Opens the context menu on position \a pos. The position
554 * is used to check whether the context menu is related to an
555 * item or to the viewport.
556 */
557 void openContextMenu(const QPoint& pos);
558
559 /**
560 * Drops the URLs \a urls to the destination path \a destPath. If
561 * the URLs are dropped above an item inside the destination path,
562 * the item is indicated by \a destItem.
563 */
564 void dropUrls(const KUrl::List& urls,
565 const KUrl& destPath,
566 const KFileItem& destItem);
567
568 /**
569 * Drops the URLs \a urls at the
570 * destination \a destination.
571 */
572 void dropUrls(const KUrl::List& urls,
573 const KUrl& destination);
574 /**
575 * Updates the view properties of the current URL to the
576 * sorting given by \a sorting.
577 */
578 void updateSorting(DolphinView::Sorting sorting);
579
580 /**
581 * Updates the view properties of the current URL to the
582 * sort order given by \a order.
583 */
584 void updateSortOrder(Qt::SortOrder order);
585
586 /**
587 * Updates the view properties of the current URL to the
588 * additional informations given by \a info.
589 */
590 void updateAdditionalInfo(const KFileItemDelegate::InformationList& info);
591
592 /**
593 * Emits the signal contentsMoved with the current coordinates
594 * of the viewport as parameters.
595 */
596 void emitContentsMoved();
597
598 /** Applies an item effect to all cut items of the clipboard. */
599 void updateCutItems();
600
601 /**
602 * Updates the status bar to show hover information for the
603 * item \a item. If currently other items are selected,
604 * no hover information is shown.
605 * @see DolphinView::clearHoverInformation()
606 */
607 void showHoverInformation(const KFileItem& item);
608
609 /**
610 * Clears the hover information shown in the status bar.
611 * @see DolphinView::showHoverInformation().
612 */
613 void clearHoverInformation();
614
615 /**
616 * Indicates in the status bar that the delete operation
617 * of the job \a job has been finished.
618 */
619 void slotDeleteFileFinished(KJob* job);
620
621 /**
622 * Is invoked when the preview job has been finished and
623 * set m_previewJob to 0.
624 */
625 void slotPreviewJobFinished(KJob* job);
626
627 private:
628 void loadDirectory(const KUrl& url, bool reload = false);
629
630 /**
631 * Returns the URL where the view properties should be stored. Usually
632 * DolphinView::url() is returned, but in the case of a Column View the
633 * view properties are always stored in the directory represented by the
634 * first column. It is recommendend whenever using the ViewProperties class
635 * to use DolphinView::viewPropertiesUrl() as URL.
636 */
637 KUrl viewPropertiesUrl() const;
638
639 /**
640 * Applies the view properties which are defined by the current URL
641 * m_url to the DolphinView properties.
642 */
643 void applyViewProperties(const KUrl& url);
644
645 /**
646 * Creates a new view representing the given view mode (DolphinView::mode()).
647 * The current view will get deleted.
648 */
649 void createView();
650
651 void deleteView();
652
653 /**
654 * Returns a pointer to the currently used item view, which is either
655 * a ListView or a TreeView.
656 */
657 QAbstractItemView* itemView() const;
658
659 /**
660 * Returns true, if the item \a item has been cut into
661 * the clipboard.
662 */
663 bool isCutItem(const KFileItem& item) const;
664
665 /** Applies an item effect to all cut items. */
666 void applyCutItemEffect();
667
668 /**
669 * Returns true, if the ColumnView is activated. As the column view
670 * requires some special handling for iterating through directories,
671 * this method has been introduced for convenience.
672 */
673 bool isColumnViewActive() const
674 {
675 return m_columnView != 0;
676 }
677
678 private:
679 /**
680 * Remembers the original pixmap for an item before
681 * the cut effect is applied.
682 */
683 struct CutItem
684 {
685 KUrl url;
686 QPixmap pixmap;
687 };
688
689 bool m_active;
690 bool m_showPreview;
691 bool m_loadingDirectory;
692 bool m_storedCategorizedSorting;
693 Mode m_mode;
694
695 DolphinMainWindow* m_mainWindow;
696 QVBoxLayout* m_topLayout;
697
698 DolphinController* m_controller;
699 DolphinIconsView* m_iconsView;
700 DolphinDetailsView* m_detailsView;
701 DolphinColumnView* m_columnView;
702 KFileItemDelegate* m_fileItemDelegate;
703 QItemSelectionModel* m_selectionModel;
704
705 DolphinModel* m_dolphinModel;
706 KDirLister* m_dirLister;
707 DolphinSortFilterProxyModel* m_proxyModel;
708
709 KIO::PreviewJob* m_previewJob;
710
711 QList<CutItem> m_cutItemsCache;
712
713 KUrl m_rootUrl;
714 };
715
716 /// Allow using DolphinView::Mode in QVariant
717 Q_DECLARE_METATYPE(DolphinView::Mode)
718
719 #endif // DOLPHINVIEW_H