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