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

sharee.h « gui « src - github.com/owncloud/client.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b0ef316e2fd3275fcb8b549c8e54c3b4b1c78cc3 (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
/*
 * Copyright (C) by Roeland Jago Douma <roeland@owncloud.com>
 *
 * 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 SHAREE_H
#define SHAREE_H

#include <QObject>
#include <QFlags>
#include <QAbstractListModel>
#include <QLoggingCategory>
#include <QModelIndex>
#include <QVariant>
#include <QSharedPointer>
#include <QVector>

#include "accountfwd.h"

class QJsonDocument;
class QJsonObject;

namespace OCC {

Q_DECLARE_LOGGING_CATEGORY(lcSharing)

class Sharee
{
public:
    // Keep in sync with Share::ShareType
    enum Type {
        User = 0,
        Group = 1,
        Federated = 6
    };

    explicit Sharee(const QString shareWith,
        const QString displayName,
        const Type type);

    QString format() const;
    QString shareWith() const;
    QString displayName() const;
    Type type() const;

private:
    QString _shareWith;
    QString _displayName;
    Type _type;
};


class ShareeModel : public QAbstractListModel
{
    Q_OBJECT
public:
    explicit ShareeModel(const AccountPtr &account, const QString &type, QObject *parent = nullptr);

    typedef QVector<QSharedPointer<Sharee>> ShareeSet; // FIXME: make it a QSet<Sharee> when Sharee can be compared
    void fetch(const QString &search, const ShareeSet &blacklist);
    int rowCount(const QModelIndex &parent = QModelIndex()) const override;
    QVariant data(const QModelIndex &index, int role) const override;

    QSharedPointer<Sharee> getSharee(int at);

    QString currentSearch() const { return _search; }

signals:
    void shareesReady();
    void displayErrorMessage(int code, const QString &);

private:
    QSharedPointer<Sharee> parseSharee(const QJsonObject &data);
    void setNewSharees(const QVector<QSharedPointer<Sharee>> &newSharees);

    AccountPtr _account;
    QString _search;
    QString _type;

    QVector<QSharedPointer<Sharee>> _sharees;
    QVector<QSharedPointer<Sharee>> _shareeBlacklist;
};
}

Q_DECLARE_METATYPE(QSharedPointer<OCC::Sharee>)

#endif //SHAREE_H