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

sharemanager.h « gui « src - github.com/nextcloud/desktop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a69ec449d985e8231963cedba781ea28ccff0c4a (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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
/*
 * Copyright (C) by Roeland Jago Douma <rullzer@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 SHAREMANAGER_H
#define SHAREMANAGER_H

#include "accountfwd.h"
#include "sharee.h"
#include "sharepermissions.h"

#include <QObject>
#include <QDate>
#include <QString>
#include <QList>
#include <QSharedPointer>
#include <QUrl>

class QJsonDocument;
class QJsonObject;

namespace OCC {

class OcsShareJob;

class Share : public QObject
{
    Q_OBJECT

public:
    /**
     * Possible share types
     * Need to be in sync with Sharee::Type
     */
    enum ShareType {
        TypeUser = Sharee::User,
        TypeGroup = Sharee::Group,
        TypeLink = 3,
        TypeEmail = Sharee::Email,
        TypeRemote = Sharee::Federated,
        TypeCircle = Sharee::Circle,
        TypeRoom = Sharee::Room
    };

    using Permissions = SharePermissions;

    /*
     * Constructor for shares
     */
    explicit Share(AccountPtr account,
        const QString &id,
        const QString &owner,
        const QString &ownerDisplayName,
        const QString &path,
        const ShareType shareType,
        bool isPasswordSet = false,
        const Permissions permissions = SharePermissionDefault,
        const QSharedPointer<Sharee> shareWith = QSharedPointer<Sharee>(nullptr));

    /**
     * The account the share is defined on.
     */
    AccountPtr account() const;

    QString path() const;

    /*
     * Get the id
     */
    QString getId() const;

    /*
     * Get the uid_owner
     */
    QString getUidOwner() const;

    /*
     * Get the owner display name
     */
    QString getOwnerDisplayName() const;

    /*
     * Get the shareType
     */
    ShareType getShareType() const;

    /*
     * Get the shareWith
     */
    QSharedPointer<Sharee> getShareWith() const;

    /*
     * Get permissions
     */
    Permissions getPermissions() const;

    /*
     * Set the permissions of a share
     *
     * On success the permissionsSet signal is emitted
     * In case of a server error the serverError signal is emitted.
     */
    void setPermissions(Permissions permissions);

    /*
     * Set the password for remote share
     *
     * On success the passwordSet signal is emitted
     * In case of a server error the passwordSetError signal is emitted.
     */
    void setPassword(const QString &password);

    bool isPasswordSet() const;

    /*
     * Deletes a share
     *
     * On success the shareDeleted signal is emitted
     * In case of a server error the serverError signal is emitted.
     */
    void deleteShare();

     /*
     * Is it a share with a user or group (local or remote)
     */
    static bool isShareTypeUserGroupEmailRoomOrRemote(const ShareType type);

signals:
    void permissionsSet();
    void shareDeleted();
    void serverError(int code, const QString &message);
    void passwordSet();
    void passwordSetError(int statusCode, const QString &message);

protected:
    AccountPtr _account;
    QString _id;
    QString _uidowner;
    QString _ownerDisplayName;
    QString _path;
    ShareType _shareType;
    bool _isPasswordSet;
    Permissions _permissions;
    QSharedPointer<Sharee> _shareWith;

protected slots:
    void slotOcsError(int statusCode, const QString &message);
    void slotPasswordSet(const QJsonDocument &, const QVariant &value);
    void slotSetPasswordError(int statusCode, const QString &message);

private slots:
    void slotDeleted();
    void slotPermissionsSet(const QJsonDocument &, const QVariant &value);
};

/**
 * A Link share is just like a regular share but then slightly different.
 * There are several methods in the API that either work differently for
 * link shares or are only available to link shares.
 */
class LinkShare : public Share
{
    Q_OBJECT
public:
    explicit LinkShare(AccountPtr account,
        const QString &id,
        const QString &uidowner,
        const QString &ownerDisplayName,
        const QString &path,
        const QString &name,
        const QString &token,
        const Permissions permissions,
        bool isPasswordSet,
        const QUrl &url,
        const QDate &expireDate,
        const QString &note,
        const QString &label);

    /*
     * Get the share link
     */
    QUrl getLink() const;

    /*
     * The share's link for direct downloading.
     */
    QUrl getDirectDownloadLink() const;

    /*
     * Get the publicUpload status of this share
     */
    bool getPublicUpload() const;

    /*
     * Whether directory listings are available (READ permission)
     */
    bool getShowFileListing() const;

    /*
     * Returns the name of the link share. Can be empty.
     */
    QString getName() const;

    /*
     * Returns the note of the link share.
     */
    QString getNote() const;
    
    /*
     * Returns the label of the link share.
     */
    QString getLabel() const;

    /*
     * Set the name of the link share.
     *
     * Emits either nameSet() or serverError().
     */
    void setName(const QString &name);

    /*
     * Set the note of the link share.
     */
    void setNote(const QString &note);

    /*
     * Returns the token of the link share.
     */
    QString getToken() const;

    /*
     * Get the expiration date
     */
    QDate getExpireDate() const;

    /*
     * Set the expiration date
     *
     * On success the expireDateSet signal is emitted
     * In case of a server error the serverError signal is emitted.
     */
    void setExpireDate(const QDate &expireDate);
    
    /*
     * Set the label of the share link.
     */
    void setLabel(const QString &label);
    
    /*
     * Create OcsShareJob and connect to signal/slots
     */
    template <typename LinkShareSlot>
    OcsShareJob *createShareJob(const LinkShareSlot slotFunction);
    
    
signals:
    void expireDateSet();
    void noteSet();
    void nameSet();
    void labelSet();

private slots:
    void slotNoteSet(const QJsonDocument &, const QVariant &value);
    void slotExpireDateSet(const QJsonDocument &reply, const QVariant &value);
    void slotNameSet(const QJsonDocument &, const QVariant &value);
    void slotLabelSet(const QJsonDocument &, const QVariant &value);

private:
    QString _name;
    QString _token;
    QString _note;
    QDate _expireDate;
    QUrl _url;
    QString _label;
};

class UserGroupShare : public Share
{
    Q_OBJECT
public:
    UserGroupShare(AccountPtr account,
        const QString &id,
        const QString &owner,
        const QString &ownerDisplayName,
        const QString &path,
        const ShareType shareType,
        bool isPasswordSet,
        const Permissions permissions,
        const QSharedPointer<Sharee> shareWith,
        const QDate &expireDate,
        const QString &note);

    void setNote(const QString &note);

    QString getNote() const;

    void slotNoteSet(const QJsonDocument &, const QVariant &note);

    void setExpireDate(const QDate &date);

    QDate getExpireDate() const;

    void slotExpireDateSet(const QJsonDocument &reply, const QVariant &value);

signals:
    void noteSet();
    void noteSetError();
    void expireDateSet();

private:
    QString _note;
    QDate _expireDate;
};

/**
 * The share manager allows for creating, retrieving and deletion
 * of shares. It abstracts away from the OCS Share API, all the usages
 * shares should talk to this manager and not use OCS Share Job directly
 */
class ShareManager : public QObject
{
    Q_OBJECT
public:
    explicit ShareManager(AccountPtr _account, QObject *parent = nullptr);

    /**
     * Tell the manager to create a link share
     *
     * @param path The path of the linkshare relative to the user folder on the server
     * @param name The name of the created share, may be empty
     * @param password The password of the share, may be empty
     *
     * On success the signal linkShareCreated is emitted
     * For older server the linkShareRequiresPassword signal is emitted when it seems appropiate
     * In case of a server error the serverError signal is emitted
     */
    void createLinkShare(const QString &path,
        const QString &name,
        const QString &password);

    /**
     * Tell the manager to create a new share
     *
     * @param path The path of the share relative to the user folder on the server
     * @param shareType The type of share (TypeUser, TypeGroup, TypeRemote)
     * @param Permissions The share permissions
     *
     * On success the signal shareCreated is emitted
     * In case of a server error the serverError signal is emitted
     */
    void createShare(const QString &path,
        const Share::ShareType shareType,
        const QString shareWith,
        const Share::Permissions permissions,
        const QString &password = "");

    /**
     * Fetch all the shares for path
     *
     * @param path The path to get the shares for relative to the users folder on the server
     *
     * On success the sharesFetched signal is emitted
     * In case of a server error the serverError signal is emitted
     */
    void fetchShares(const QString &path);

signals:
    void shareCreated(const QSharedPointer<Share> &share);
    void linkShareCreated(const QSharedPointer<LinkShare> &share);
    void sharesFetched(const QList<QSharedPointer<Share>> &shares);
    void serverError(int code, const QString &message);

    /** Emitted when creating a link share with password fails.
     *
     * @param message the error message reported by the server
     *
     * See createLinkShare().
     */
    void linkShareRequiresPassword(const QString &message);

private slots:
    void slotSharesFetched(const QJsonDocument &reply);
    void slotLinkShareCreated(const QJsonDocument &reply);
    void slotShareCreated(const QJsonDocument &reply);
    void slotOcsError(int statusCode, const QString &message);
private:
    QSharedPointer<LinkShare> parseLinkShare(const QJsonObject &data);
    QSharedPointer<UserGroupShare> parseUserGroupShare(const QJsonObject &data);
    QSharedPointer<Share> parseShare(const QJsonObject &data);

    AccountPtr _account;
};
}

#endif // SHAREMANAGER_H