Welcome to mirror list, hosted at ThFree Co, Russian Federation.

folderstatusmodel.h « gui « src - github.com/owncloud/client.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c19f0fe08b298c9189d7a22199a09f41ff98b2aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
 * Copyright (C) by Klaas Freitag <freitag@kde.org>
 *
 * 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.
 */

#ifndef FOLDERSTATUSMODEL_H
#define FOLDERSTATUSMODEL_H

#include <accountfwd.h>
#include <QAbstractItemModel>
#include <QVector>


class QNetworkReply;
namespace OCC {

class Folder;
class ProgressInfo;

/**
 * @brief The FolderStatusModel class
 * @ingroup gui
 */
class FolderStatusModel : public QAbstractItemModel
{
    Q_OBJECT
public:
    FolderStatusModel(QObject * parent = 0);
    ~FolderStatusModel();
    void setAccountState(const AccountState* accountState);

    Qt::ItemFlags flags( const QModelIndex& ) const Q_DECL_OVERRIDE;
    QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE;
    bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) Q_DECL_OVERRIDE;
    int columnCount(const QModelIndex& parent = QModelIndex()) const Q_DECL_OVERRIDE;
    int rowCount(const QModelIndex& parent = QModelIndex()) const Q_DECL_OVERRIDE;
    QModelIndex index(int row, int column = 0, const QModelIndex& parent = QModelIndex()) const Q_DECL_OVERRIDE;
    QModelIndex parent(const QModelIndex& child) const Q_DECL_OVERRIDE;
    bool canFetchMore(const QModelIndex& parent) const Q_DECL_OVERRIDE;
    void fetchMore(const QModelIndex& parent) Q_DECL_OVERRIDE;
    bool hasChildren(const QModelIndex& parent = QModelIndex()) const Q_DECL_OVERRIDE;

    struct SubFolderInfo {
        SubFolderInfo()
            : _folder(0), _size(0), _fetched(false), _fetching(false), _isUndecided(false),
            _hasError(false), _checked(Qt::Checked) {}
        Folder *_folder;
        QString _name;
        QString _path;
        QVector<int> _pathIdx;
        QVector<SubFolderInfo> _subs;
        qint64 _size;
        bool _fetched; // If we did the LSCOL for this folder already
        bool _fetching;
        bool _isUndecided; // undecided folder are the big folder that the user has not accepted yet
        bool _hasError; // If the last fetching job ended in an error
        Qt::CheckState _checked;

        struct Progress {
            Progress() : _warningCount(0), _overallPercent(0) {}
            bool isNull() const
            { return _progressString.isEmpty() && _warningCount == 0 && _overallSyncString.isEmpty(); }
            QString _progressString;
            QString _overallSyncString;
            int _warningCount;
            int _overallPercent;
        };
        Progress _progress;
    };

    QVector<SubFolderInfo> _folders;

    enum ItemType { RootFolder, SubFolder, AddButton, ErrorLabel };
    ItemType classify(const QModelIndex &index) const;
    SubFolderInfo *infoForIndex(const QModelIndex &index) const;

    // If the selective sync check boxes were changed
    bool isDirty() { return _dirty; }

    /**
     * return a QModelIndex for the given path within the given folder.
     * Note: this method returns an invalid index if the path was not fetch from the server before
     */
    QModelIndex indexForPath(Folder *f, const QString &path) const;

public slots:
    void slotUpdateFolderState(Folder *);
    void slotApplySelectiveSync();
    void resetFolders();
    void slotSetProgress(const ProgressInfo &progress);

private slots:
    void slotUpdateDirectories(const QStringList &);
    void slotLscolFinishedWithError(QNetworkReply *r);
    void slotFolderSyncStateChange();
    void slotNewBigFolder();

private:
    QStringList createBlackList(OCC::FolderStatusModel::SubFolderInfo* root,
                                const QStringList& oldBlackList) const;
    const AccountState* _accountState;
    bool _dirty;  // If the selective sync checkboxes were changed

#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
    //the roles argument was added in Qt5
    void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int>())
    { emit QAbstractItemModel::dataChanged(topLeft,bottomRight); }
#endif

signals:
    void dirtyChanged();
    void suggestExpand(const QModelIndex &); // Tell the view that this item should be expanded because it has a undecided item
};

} // namespace OCC

#endif // FOLDERSTATUSMODEL_H