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