dolphinview.h 26.6 KB
Newer Older
1
/***************************************************************************
2
 *   Copyright (C) 2006-2009 by Peter Penz <peter.penz19@gmail.com>        *
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 *   Copyright (C) 2006 by Gregor Kališnik <gregor@podnapisi.net>          *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
18
 *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
19
20
 ***************************************************************************/

21
22
#ifndef DOLPHINVIEW_H
#define DOLPHINVIEW_H
23

24
#include "dolphintabwidget.h"
25
#include "dolphin_export.h"
26
#include "tooltips/tooltipmanager.h"
27

Peter Penz's avatar
Peter Penz committed
28
29
#include <KFileItem>
#include <KIO/Job>
Roman Inflianskas's avatar
Roman Inflianskas committed
30
31
32
33
#include <config-baloo.h>
#include <kio/fileundomanager.h>
#include <kparts/part.h>

Lukáš Tinkl's avatar
Lukáš Tinkl committed
34
#include <QMimeData>
Roman Inflianskas's avatar
Roman Inflianskas committed
35
#include <QUrl>
36
#include <QWidget>
37

38
typedef KIO::FileUndoManager::CommandType CommandType;
Laurent Montel's avatar
Laurent Montel committed
39
class QVBoxLayout;
40
class DolphinItemListView;
41
class KFileItemModel;
42
class KItemListContainer;
43
class KItemModelBase;
44
class KItemSet;
45
class ToolTipManager;
46
class VersionControlObserver;
Peter Penz's avatar
Peter Penz committed
47
class ViewProperties;
Peter Penz's avatar
Peter Penz committed
48
class QGraphicsSceneDragDropEvent;
49
class QRegExp;
50

51
/**
52
 * @short Represents a view for the directory content.
53
 *
54
 * View modes for icons, compact and details are supported. It's
55
56
57
58
59
 * possible to adjust:
 * - sort order
 * - sort type
 * - show hidden files
 * - show previews
60
 * - enable grouping
61
 */
62
class DOLPHIN_EXPORT DolphinView : public QWidget
63
64
65
66
{
    Q_OBJECT

public:
67
    /**
68
     * Defines the view mode for a directory. The
69
70
71
     * view mode is automatically updated if the directory itself
     * defines a view mode (see class ViewProperties for details).
     */
72
73
74
    enum Mode
    {
        /**
75
         * The items are shown as icons with a name-label below.
76
         */
77
78
79
        IconsView = 0,

        /**
80
81
         * The icon, the name and the size of the items are
         * shown per default as a table.
82
         */
Peter Penz's avatar
Peter Penz committed
83
        DetailsView,
84
85

        /**
86
87
         * The items are shown as icons with the name-label aligned
         * to the right side.
88
         */
Peter Penz's avatar
Peter Penz committed
89
        CompactView
90
91
    };

92
    /**
93
     * @param url              Specifies the content which should be shown.
94
     * @param parent           Parent widget of the view.
95
     */
96
    DolphinView(const QUrl& url, QWidget* parent);
97

98
    ~DolphinView() override;
99

100
101
102
103
    /**
     * Returns the current active URL, where all actions are applied.
     * The URL navigator is synchronized with this URL.
     */
104
    QUrl url() const;
105

106
    /**
107
108
     * If \a active is true, the view will marked as active. The active
     * view is defined as view where all actions are applied to.
109
     */
110
    void setActive(bool active);
111
112
    bool isActive() const;

113
114
115
116
    /**
     * Changes the view mode for the current directory to \a mode.
     * If the view properties should be remembered for each directory
     * (GeneralSettings::globalViewProps() returns false), then the
117
     * changed view mode will be stored automatically.
118
     */
119
120
    void setMode(Mode mode);
    Mode mode() const;
121

122
123
124
125
126
127
128
129
    /**
     * Turns on the file preview for the all files of the current directory,
     * if \a show is true.
     * If the view properties should be remembered for each directory
     * (GeneralSettings::globalViewProps() returns false), then the
     * preview setting will be stored automatically.
     */
    void setPreviewsShown(bool show);
130
    bool previewsShown() const;
131

132
133
134
135
136
137
138
139
    /**
     * Shows all hidden files of the current directory,
     * if \a show is true.
     * If the view properties should be remembered for each directory
     * (GeneralSettings::globalViewProps() returns false), then the
     * show hidden file setting will be stored automatically.
     */
    void setHiddenFilesShown(bool show);
140
    bool hiddenFilesShown() const;
141

142
143
144
145
146
    /**
     * Turns on sorting by groups if \a enable is true.
     */
    void setGroupedSorting(bool grouped);
    bool groupedSorting() const;
147

148
    /**
149
     * Returns the items of the view.
150
     */
151
    KFileItemList items() const;
152

153
154
155
156
157
158
    /**
     * @return The number of items. itemsCount() is faster in comparison
     *         to items().count().
     */
    int itemsCount() const;

159
    /**
Peter Penz's avatar
Peter Penz committed
160
161
     * Returns the selected items. The list is empty if no item has been
     * selected.
162
     */
163
    KFileItemList selectedItems() const;
164

165
166
167
168
169
170
    /**
     * Returns the number of selected items (this is faster than
     * invoking selectedItems().count()).
     */
    int selectedItemsCount() const;

171
172
173
174
175
176
    /**
     * Marks the items indicated by \p urls to get selected after the
     * directory DolphinView::url() has been loaded. Note that nothing
     * gets selected if no loading of a directory has been triggered
     * by DolphinView::setUrl() or DolphinView::reload().
     */
177
    void markUrlsAsSelected(const QList<QUrl> &urls);
178

179
    /**
180
181
     * Marks the item indicated by \p url to be scrolled to and as the
     * current item after directory DolphinView::url() has been loaded.
182
     */
183
    void markUrlAsCurrent(const QUrl& url);
184

185
186
187
188
    /**
     * All items that match to the pattern \a pattern will get selected
     * if \a enabled is true and deselected if  \a enabled is false.
     */
189
    void selectItems(const QRegExp& pattern, bool enabled);
190

191
192
    /**
     * Sets the zoom level to \a level. It is assured that the used
193
194
     * level is adjusted to be inside the range ZoomLevelInfo::minimumLevel() and
     * ZoomLevelInfo::maximumLevel().
195
196
197
     */
    void setZoomLevel(int level);
    int zoomLevel() const;
198

199
200
201
202
203
    /**
     * Resets the view's icon size to the default value
     */
    void resetZoomLevel();

204
205
    void setSortRole(const QByteArray& role);
    QByteArray sortRole() const;
206
207
208
209

    void setSortOrder(Qt::SortOrder order);
    Qt::SortOrder sortOrder() const;

210
211
212
213
    /** Sets a separate sorting with folders first (true) or a mixed sorting of files and folders (false). */
    void setSortFoldersFirst(bool foldersFirst);
    bool sortFoldersFirst() const;

214
    /** Sets the additional information which should be shown for the items. */
215
    void setVisibleRoles(const QList<QByteArray>& roles);
216

217
    /** Returns the additional information which should be shown for the items. */
218
    QList<QByteArray> visibleRoles() const;
219

220
    void reload();
221

222
    /**
223
224
     * Refreshes the view to get synchronized with the settings (e.g. icons size,
     * font, ...).
225
     */
226
    void readSettings();
227

228
229
230
231
    /**
     * Saves the current settings (e.g. icons size, font, ..).
     */
    void writeSettings();
232

233
234
235
236
237
    /**
     * Filters the currently shown items by \a nameFilter. All items
     * which contain the given filter string will be shown.
     */
    void setNameFilter(const QString& nameFilter);
238
    QString nameFilter() const;
239

240
241
242
243
244
245
246
247
    /**
     * Filters the currently shown items by \a filters. All items
     * whose content-type matches those given by the list of filters
     * will be shown.
     */
    void setMimeTypeFilters(const QStringList& filters);
    QStringList mimeTypeFilters() const;

248
249
250
251
252
    /**
     * Returns a textual representation of the state of the current
     * folder or selected items, suitable for use in the status bar.
     */
    QString statusBarText() const;
253

254
    /**
255
     * Returns the version control actions that are provided for the items \p items.
256
257
     * Usually the actions are presented in the context menu.
     */
258
    QList<QAction*> versionControlActions(const KFileItemList& items) const;
259

260
261
262
263
264
265
266
    /**
     * Returns the state of the paste action:
     * first is whether the action should be enabled
     * second is the text for the action
     */
    QPair<bool, QString> pasteInfo() const;

267
268
269
270
271
272
273
274
275
    /**
     * If \a tabsForFiles is true, the signal tabRequested() will also
     * emitted also for files. Per default tabs for files is disabled
     * and hence the signal tabRequested() will only be emitted for
     * directories.
     */
    void setTabsForFilesEnabled(bool tabsForFiles);
    bool isTabsForFilesEnabled() const;

276
277
278
279
280
281
    /**
     * Returns true if the current view allows folders to be expanded,
     * i.e. presents a hierarchical view to the user.
     */
    bool itemsExpandable() const;

282
283
284
    /**
     * Restores the view state (current item, contents position, details view expansion state)
     */
285
    void restoreState(QDataStream& stream);
286
287
288
289

    /**
     * Saves the view state (current item, contents position, details view expansion state)
     */
290
    void saveState(QDataStream& stream);
291

292
    /**
293
     * Returns the root item which represents the current URL.
294
295
296
     */
    KFileItem rootItem() const;

297
298
299
300
301
302
303
304
305
306
    /**
     * Sets a context that is used for remembering the view-properties.
     * Per default the context is empty and the path of the currently set URL
     * is used for remembering the view-properties. Setting a custom context
     * makes sense if specific types of URLs (e.g. search-URLs) should
     * share common view-properties.
     */
    void setViewPropertiesContext(const QString& context);
    QString viewPropertiesContext() const;

307
308
309
310
311
312
    /**
     * Checks if the given \a item can be opened as folder (e.g. archives).
     * This function will also adjust the \a url (e.g. change the protocol).
     * @return a valid and adjusted url if the item can be opened as folder,
     * otherwise return an empty url.
     */
Lukáš Tinkl's avatar
Lukáš Tinkl committed
313
    static QUrl openItemAsFolderUrl(const KFileItem& item, const bool browseThroughArchives = true);
314

315
316
317
318
319
    /**
     * Hides tooltip displayed over element.
     */
    void hideToolTip(const ToolTipManager::HideBehavior behavior = ToolTipManager::HideBehavior::Later);

320
public slots:
321
    /**
322
323
     * Changes the directory to \a url. If the current directory is equal to
     * \a url, nothing will be done (use DolphinView::reload() instead).
Peter Penz's avatar
Peter Penz committed
324
     */
Lukáš Tinkl's avatar
Lukáš Tinkl committed
325
    void setUrl(const QUrl& url);
326

327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
    /**
     * Selects all items.
     * @see DolphinView::selectedItems()
     */
    void selectAll();

    /**
     * Inverts the current selection: selected items get unselected,
     * unselected items get selected.
     * @see DolphinView::selectedItems()
     */
    void invertSelection();

    void clearSelection();

342
343
344
345
346
    /**
     * Triggers the renaming of the currently selected items, where
     * the user must input a new name for the items.
     */
    void renameSelectedItems();
347

348
349
350
351
352
353
354
355
356
357
    /**
     * Moves all selected items to the trash.
     */
    void trashSelectedItems();

    /**
     * Deletes all selected items.
     */
    void deleteSelectedItems();

358
359
    /**
     * Copies all selected items to the clipboard and marks
360
     * the items as cut.
361
362
363
364
365
366
367
368
369
     */
    void cutSelectedItems();

    /** Copies all selected items to the clipboard. */
    void copySelectedItems();

    /** Pastes the clipboard data to this view. */
    void paste();

370
371
372
373
374
375
376
    /**
     * Pastes the clipboard data into the currently selected
     * folder. If the current selection is not exactly one folder, no
     * paste operation is done.
     */
    void pasteIntoFolder();

377
    /**
378
     * Handles a drop of @p dropEvent onto widget @p dropWidget and destination @p destUrl
379
     */
380
    void dropUrls(const QUrl &destUrl, QDropEvent *dropEvent, QWidget *dropWidget);
381

382
383
    void stopLoading();

384
385
386
387
388
389
    /**
     * Applies the state that has been restored by restoreViewState()
     * to the view.
     */
    void updateViewState();

390
    /** Activates the view if the item list container gets focus. */
391
    bool eventFilter(QObject* watched, QEvent* event) override;
392

393
signals:
394
395
396
397
398
    /**
     * Is emitted if the view has been activated by e. g. a mouse click.
     */
    void activated();

399
    /** Is emitted if the URL of the view has been changed to \a url. */
Lukáš Tinkl's avatar
Lukáš Tinkl committed
400
    void urlChanged(const QUrl& url);
401

402
    /**
403
     * Is emitted when clicking on an item with the left mouse button.
404
     */
405
    void itemActivated(const KFileItem& item);
406

407
408
409
410
411
412
    /**
     * Is emitted when multiple items have been activated by e. g.
     * context menu open with.
     */
    void itemsActivated(const KFileItemList& items);

413
414
415
416
417
    /**
     * Is emitted if items have been added or deleted.
     */
    void itemCountChanged();

418
419
420
    /**
     * Is emitted if a new tab should be opened for the URL \a url.
     */
421
    void tabRequested(const QUrl& url, DolphinTabWidget::TabPlacement tabPlacement);
422

423
424
425
426
    /**
     * Is emitted if the view mode (IconsView, DetailsView,
     * PreviewsView) has been changed.
     */
427
    void modeChanged(DolphinView::Mode current, DolphinView::Mode previous);
428

429
    /** Is emitted if the 'show preview' property has been changed. */
430
    void previewsShownChanged(bool shown);
431

432
    /** Is emitted if the 'show hidden files' property has been changed. */
433
    void hiddenFilesShownChanged(bool shown);
434

435
436
    /** Is emitted if the 'grouped sorting' property has been changed. */
    void groupedSortingChanged(bool groupedSorting);
437

438
    /** Is emitted if the sorting by name, size or date has been changed. */
439
    void sortRoleChanged(const QByteArray& role);
440
441

    /** Is emitted if the sort order (ascending or descending) has been changed. */
442
    void sortOrderChanged(Qt::SortOrder order);
443

444
445
446
447
    /**
     * Is emitted if the sorting of files and folders (separate with folders
     * first or mixed) has been changed.
     */
448
449
    void sortFoldersFirstChanged(bool foldersFirst);

450
    /** Is emitted if the additional information shown for this view has been changed. */
451
452
    void visibleRolesChanged(const QList<QByteArray>& current,
                             const QList<QByteArray>& previous);
453

454
    /** Is emitted if the zoom level has been changed by zooming in or out. */
455
    void zoomLevelChanged(int current, int previous);
456

457
    /**
458
     * Is emitted if information of an item is requested to be shown e. g. in the panel.
459
     * If item is null, no item information request is pending.
460
     */
461
    void requestItemInfo(const KFileItem& item);
462
463

    /**
464
     * Is emitted whenever the selection has been changed.
465
     */
466
    void selectionChanged(const KFileItemList& selection);
467

468
469
    /**
     * Is emitted if a context menu is requested for the item \a item,
470
471
472
     * which is part of \a url. If the item is null, the context menu
     * for the URL should be shown and the custom actions \a customActions
     * will be added.
473
     */
Peter Penz's avatar
Peter Penz committed
474
475
    void requestContextMenu(const QPoint& pos,
                            const KFileItem& item,
Lukáš Tinkl's avatar
Lukáš Tinkl committed
476
                            const QUrl& url,
477
                            const QList<QAction*>& customActions);
478

479
480
481
482
483
484
485
486
487
488
489
490
    /**
     * Is emitted if an information message with the content \a msg
     * should be shown.
     */
    void infoMessage(const QString& msg);

    /**
     * Is emitted if an error message with the content \a msg
     * should be shown.
     */
    void errorMessage(const QString& msg);

491
492
493
494
495
496
    /**
     * Is emitted if an "operation completed" message with the content \a msg
     * should be shown.
     */
    void operationCompletedMessage(const QString& msg);

497
    /**
498
     * Is emitted after DolphinView::setUrl() has been invoked and
499
     * the current directory is loaded. If this signal is emitted,
500
501
     * it is assured that the view contains already the correct root
     * URL and property settings.
502
     */
503
    void directoryLoadingStarted();
504

505
    /**
506
     * Is emitted after the directory triggered by DolphinView::setUrl()
507
508
     * has been loaded.
     */
509
    void directoryLoadingCompleted();
510

511
512
513
514
515
516
    /**
     * Is emitted after the directory loading triggered by DolphinView::setUrl()
     * has been canceled.
     */
    void directoryLoadingCanceled();

517
518
    /**
     * Is emitted after DolphinView::setUrl() has been invoked and provides
519
     * the information how much percent of the current directory have been loaded.
520
     */
521
    void directoryLoadingProgress(int percent);
522

523
524
525
526
    /**
     * Is emitted if the sorting is done asynchronously and provides the
     * progress information of the sorting.
     */
527
    void directorySortingProgress(int percent);
528

529
    /**
530
     * Emitted when the file-item-model emits redirection.
531
532
     * Testcase: fish://localhost
     */
Lukáš Tinkl's avatar
Lukáš Tinkl committed
533
    void redirection(const QUrl& oldUrl, const QUrl& newUrl);
534

535
536
537
538
    /**
     * Is emitted when the URL set by DolphinView::setUrl() represents a file.
     * In this case no signal errorMessage() will be emitted.
     */
Lukáš Tinkl's avatar
Lukáš Tinkl committed
539
    void urlIsFileError(const QUrl& url);
540

541
542
543
544
545
546
547
    /**
     * Is emitted when the write state of the folder has been changed. The application
     * should disable all actions like "Create New..." that depend on the write
     * state.
     */
    void writeStateChanged(bool isFolderWritable);

548
549
550
551
552
553
554
555
556
557
558
559
    /**
     * Is emitted if the URL should be changed to the previous URL of the
     * history (e.g. because the "back"-mousebutton has been pressed).
     */
    void goBackRequested();

    /**
     * Is emitted if the URL should be changed to the next URL of the
     * history (e.g. because the "next"-mousebutton has been pressed).
     */
    void goForwardRequested();

560
561
562
563
564
    /**
     * Is emitted when the user wants to move the focus to another view.
     */
    void toggleActiveViewRequested();

565
566
567
568
569
570
    /**
     * Is emitted when the user clicks a tag or a link
     * in the metadata widget of a tooltip.
     */
    void urlActivated(const QUrl& url);

571
572
protected:
    /** Changes the zoom level if Control is pressed during a wheel event. */
573
    void wheelEvent(QWheelEvent* event) override;
574

575
576
    void hideEvent(QHideEvent* event) override;
    bool event(QEvent* event) override;
577

578
private slots:
579
580
581
582
583
    /**
     * Marks the view as active (DolphinView:isActive() will return true)
     * and emits the 'activated' signal if it is not already active.
     */
    void activate();
584

585
    void slotItemActivated(int index);
586
    void slotItemsActivated(const KItemSet& indexes);
587
    void slotItemMiddleClicked(int index);
Peter Penz's avatar
Peter Penz committed
588
589
590
    void slotItemContextMenuRequested(int index, const QPointF& pos);
    void slotViewContextMenuRequested(const QPointF& pos);
    void slotHeaderContextMenuRequested(const QPointF& pos);
591
    void slotHeaderColumnWidthChangeFinished(const QByteArray& role, qreal current);
592
593
    void slotItemHovered(int index);
    void slotItemUnhovered(int index);
Peter Penz's avatar
Peter Penz committed
594
    void slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* event);
595
    void slotModelChanged(KItemModelBase* current, KItemModelBase* previous);
596
    void slotMouseButtonPressed(int itemIndex, Qt::MouseButtons buttons);
Emirald Mateli's avatar
Emirald Mateli committed
597
    void slotRenameDialogRenamingFinished(const QList<QUrl>& urls);
598
    void slotSelectedItemTextPressed(int index);
Peter Penz's avatar
Peter Penz committed
599

600
601
602
    /*
     * Is called when new items get pasted or dropped.
     */
603
604
605
606
607
    void slotItemCreated(const QUrl &url);
    /*
     * Is called after all pasted or dropped items have been copied to destination.
     */
    void slotPasteJobResult(KJob *job);
608

609
610
    /**
     * Emits the signal \a selectionChanged() with a small delay. This is
611
     * because getting all file items for the selection can be an expensive
612
613
614
615
     * operation. Fast selection changes are collected in this case and
     * the signal is emitted only after no selection change has been done
     * within a small delay.
     */
616
    void slotSelectionChanged(const KItemSet& current, const KItemSet& previous);
617
618
619
620
621

    /**
     * Is called by emitDelayedSelectionChangedSignal() and emits the
     * signal \a selectionChanged() with all selected file items as parameter.
     */
Peter Penz's avatar
Peter Penz committed
622
    void emitSelectionChangedSignal();
623

624
625
    /**
     * Updates the view properties of the current URL to the
626
     * sorting given by \a role.
627
     */
628
    void updateSortRole(const QByteArray& role);
629
630
631
632
633
634
635

    /**
     * Updates the view properties of the current URL to the
     * sort order given by \a order.
     */
    void updateSortOrder(Qt::SortOrder order);

636
637
638
639
640
641
    /**
     * Updates the view properties of the current URL to the
     * sorting of files and folders (separate with folders first or mixed) given by \a foldersFirst.
     */
    void updateSortFoldersFirst(bool foldersFirst);

642
643
644
645
646
647
    /**
     * Indicates in the status bar that the delete operation
     * of the job \a job has been finished.
     */
    void slotDeleteFileFinished(KJob* job);

648
649
650
651
652
653
    /**
     * Indicates in the status bar that the trash operation
     * of the job \a job has been finished.
     */
    void slotTrashFileFinished(KJob* job);

654
655
656
657
    /**
     * Invoked when the rename job is done, for error handling.
     */
    void slotRenamingResult(KJob* job);
658

659
    /**
660
661
     * Invoked when the file item model has started the loading
     * of the directory specified by DolphinView::url().
662
     */
663
    void slotDirectoryLoadingStarted();
664

665
    /**
666
     * Invoked when the file item model indicates that the loading of a directory has
Yuri Chornoivan's avatar
Yuri Chornoivan committed
667
     * been completed. Assures that pasted items and renamed items get selected.
668
     */
669
    void slotDirectoryLoadingCompleted();
670

671
    /**
672
     * Is invoked when items of KFileItemModel have been changed.
673
     */
674
    void slotItemsChanged();
675

Peter Penz's avatar
Peter Penz committed
676
677
678
679
680
681
682
683
684
685
686
687
    /**
     * Is invoked when the sort order has been changed by the user by clicking
     * on a header item. The view properties of the directory will get updated.
     */
    void slotSortOrderChangedByHeader(Qt::SortOrder current, Qt::SortOrder previous);

    /**
     * Is invoked when the sort role has been changed by the user by clicking
     * on a header item. The view properties of the directory will get updated.
     */
    void slotSortRoleChangedByHeader(const QByteArray& current, const QByteArray& previous);

688
689
690
691
692
693
694
    /**
     * Is invoked when the visible roles have been changed by the user by dragging
     * a header item. The view properties of the directory will get updated.
     */
    void slotVisibleRolesChangedByHeader(const QList<QByteArray>& current,
                                         const QList<QByteArray>& previous);

695
    void slotRoleEditingCanceled();
696
697
    void slotRoleEditingFinished(int index, const QByteArray& role, const QVariant& value);

698
699
700
    /**
     * Observes the item with the URL \a url. As soon as the directory
     * model indicates that the item is available, the item will
701
     * get selected and it is assured that the item stays visible.
702
     */
703
    void observeCreatedItem(const QUrl &url);
704

705
706
707
708
    /**
     * Called when a redirection happens.
     * Testcase: fish://localhost
     */
709
    void slotDirectoryRedirection(const QUrl& oldUrl, const QUrl& newUrl);
710

711
712
713
714
715
716
717
718
719
720
    /**
     * Calculates the number of currently shown files into
     * \a fileCount and the number of folders into \a folderCount.
     * The size of all files is written into \a totalFileSize.
     * It is recommend using this method instead of asking the
     * directory lister or the model directly, as it takes
     * filtering and hierarchical previews into account.
     */
    void calculateItemCount(int& fileCount, int& folderCount, KIO::filesize_t& totalFileSize) const;

721
722
    void slotTwoClicksRenamingTimerTimeout();

723
private:
Lukáš Tinkl's avatar
Lukáš Tinkl committed
724
    void loadDirectory(const QUrl& url, bool reload = false);
725

726
727
    /**
     * Applies the view properties which are defined by the current URL
728
729
730
     * to the DolphinView properties. The view properties are read from a
     * .directory file either in the current directory, or in the
     * share/apps/dolphin/view_properties/ subfolder of the user's .kde folder.
731
     */
732
    void applyViewProperties();
733

734
735
736
737
738
    /**
     * Applies the given view properties to the DolphinView.
     */
    void applyViewProperties(const ViewProperties& props);

739
740
741
742
743
744
    /**
     * Applies the m_mode property to the corresponding
     * itemlayout-property of the KItemListView.
     */
    void applyModeToView();

745
746
747
748
    /**
     * Helper method for DolphinView::paste() and DolphinView::pasteIntoFolder().
     * Pastes the clipboard data into the URL \a url.
     */
Lukáš Tinkl's avatar
Lukáš Tinkl committed
749
    void pasteToUrl(const QUrl& url);
750

751
752
753
754
755
    /**
     * Returns a list of URLs for all selected items. The list is
     * simplified, so that when the URLs are part of different tree
     * levels, only the parent is returned.
     */
Lukáš Tinkl's avatar
Lukáš Tinkl committed
756
    QList<QUrl> simplifiedSelectedUrls() const;
757

758
759
760
761
    /**
     * Returns the MIME data for all selected items.
     */
    QMimeData* selectionMimeData() const;
762

763
764
765
766
767
768
769
    /**
     * Updates m_isFolderWritable dependent on whether the folder represented by
     * the current URL is writable. If the state has changed, the signal
     * writeableStateChanged() will be emitted.
     */
    void updateWritableState();

770
771
772
773
774
    /**
     * @return The current URL if no viewproperties-context is given (see
     *         DolphinView::viewPropertiesContext(), otherwise the context
     *         is returned.
     */
Lukáš Tinkl's avatar
Lukáš Tinkl committed
775
    QUrl viewPropertiesUrl() const;
776

Emirald Mateli's avatar
Emirald Mateli committed
777
778
779
780
781
782
783
784
    /**
     * Clears the selection and updates current item and selection according to the parameters
     *
     * @param current URL to be set as current
     * @param selected list of selected items
     */
    void forceUrlsSelection(const QUrl& current, const QList<QUrl>& selected);

785
786
    void abortTwoClicksRenaming();

787
private:
788
789
    void updatePalette();

790
791
792
793
794
795
    bool m_active;
    bool m_tabsForFiles;
    bool m_assureVisibleCurrentIndex;
    bool m_isFolderWritable;
    bool m_dragging; // True if a dragging is done. Required to be able to decide whether a
                     // tooltip may be shown when hovering an item.
796

Lukáš Tinkl's avatar
Lukáš Tinkl committed
797
    QUrl m_url;
798
    QString m_viewPropertiesContext;
799
    Mode m_mode;
800
    QList<QByteArray> m_visibleRoles;
801

802
    QVBoxLayout* m_topLayout;
803

804
805
806
    KFileItemModel* m_model;
    DolphinItemListView* m_view;
    KItemListContainer* m_container;
807

808
809
    ToolTipManager* m_toolTipManager;

810
    QTimer* m_selectionChangedTimer;
811

812
    QUrl m_currentItemUrl; // Used for making the view to remember the current URL after F5
813
    bool m_scrollToCurrentItem; // Used for marking we need to scroll to current item or not
814
    QPoint m_restoredContentsPosition;
Peter Penz's avatar
Peter Penz committed
815

816
    QList<QUrl> m_selectedUrls; // Used for making the view to remember selections after F5
817
    bool m_clearSelectionBeforeSelectingNewItems;
818
    bool m_markFirstNewlySelectedItemAsCurrent;
819

820
    VersionControlObserver* m_versionControlObserver;
821

822
823
824
    QTimer* m_twoClicksRenamingTimer;
    QUrl m_twoClicksRenamingItemUrl;

825
    // For unit tests
826
    friend class TestBase;
827
    friend class DolphinDetailsViewTest;
828
    friend class DolphinPart;                   // Accesses m_model
829
830
};

831
832
833
/// Allow using DolphinView::Mode in QVariant
Q_DECLARE_METATYPE(DolphinView::Mode)

834
#endif // DOLPHINVIEW_H