2015-11-02 00:23:22 +03:00
|
|
|
/*
|
|
|
|
* 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
|
2016-10-25 12:00:07 +03:00
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
2015-11-02 00:23:22 +03:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2015-11-05 00:00:35 +03:00
|
|
|
#ifndef SHAREE_H
|
|
|
|
#define SHAREE_H
|
|
|
|
|
2015-11-02 00:23:22 +03:00
|
|
|
#include <QObject>
|
|
|
|
#include <QFlags>
|
2015-11-05 00:00:35 +03:00
|
|
|
#include <QAbstractListModel>
|
2017-05-09 15:24:11 +03:00
|
|
|
#include <QLoggingCategory>
|
2015-11-02 00:23:22 +03:00
|
|
|
#include <QModelIndex>
|
|
|
|
#include <QVariant>
|
|
|
|
#include <QSharedPointer>
|
|
|
|
#include <QVector>
|
|
|
|
|
|
|
|
#include "accountfwd.h"
|
|
|
|
|
2017-04-26 12:38:10 +03:00
|
|
|
class QJsonDocument;
|
|
|
|
class QJsonObject;
|
|
|
|
|
2015-11-02 00:23:22 +03:00
|
|
|
namespace OCC {
|
|
|
|
|
2017-05-09 15:24:11 +03:00
|
|
|
Q_DECLARE_LOGGING_CATEGORY(lcSharing)
|
|
|
|
|
2015-11-05 00:00:35 +03:00
|
|
|
class Sharee
|
|
|
|
{
|
2015-11-02 00:23:22 +03:00
|
|
|
public:
|
2015-11-19 12:50:21 +03:00
|
|
|
// Keep in sync with Share::ShareType
|
2015-11-02 00:23:22 +03:00
|
|
|
enum Type {
|
|
|
|
User = 0,
|
|
|
|
Group = 1,
|
|
|
|
Federated = 6
|
|
|
|
};
|
|
|
|
|
|
|
|
explicit Sharee(const QString shareWith,
|
|
|
|
const QString displayName,
|
|
|
|
const Type type);
|
2015-11-19 12:50:21 +03:00
|
|
|
|
2015-11-05 00:00:35 +03:00
|
|
|
QString format() const;
|
2015-11-02 00:23:22 +03:00
|
|
|
QString shareWith() const;
|
|
|
|
QString displayName() const;
|
|
|
|
Type type() const;
|
2015-11-16 16:18:01 +03:00
|
|
|
|
2015-11-02 00:23:22 +03:00
|
|
|
private:
|
|
|
|
QString _shareWith;
|
|
|
|
QString _displayName;
|
|
|
|
Type _type;
|
|
|
|
};
|
|
|
|
|
2015-11-16 16:18:01 +03:00
|
|
|
|
2015-11-05 00:00:35 +03:00
|
|
|
class ShareeModel : public QAbstractListModel
|
|
|
|
{
|
2015-11-02 00:23:22 +03:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2018-11-11 12:56:22 +03:00
|
|
|
explicit ShareeModel(const AccountPtr &account, const QString &type, QObject *parent = nullptr);
|
2015-11-02 00:23:22 +03:00
|
|
|
|
2015-11-16 16:18:01 +03:00
|
|
|
typedef QVector<QSharedPointer<Sharee>> ShareeSet; // FIXME: make it a QSet<Sharee> when Sharee can be compared
|
|
|
|
void fetch(const QString &search, const ShareeSet &blacklist);
|
2018-11-11 13:08:03 +03:00
|
|
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
|
|
|
QVariant data(const QModelIndex &index, int role) const override;
|
2015-11-02 00:23:22 +03:00
|
|
|
|
2015-11-05 00:00:35 +03:00
|
|
|
QSharedPointer<Sharee> getSharee(int at);
|
|
|
|
|
2016-01-12 16:35:35 +03:00
|
|
|
QString currentSearch() const { return _search; }
|
|
|
|
|
2015-11-05 00:00:35 +03:00
|
|
|
signals:
|
|
|
|
void shareesReady();
|
2016-01-12 16:35:35 +03:00
|
|
|
void displayErrorMessage(int code, const QString &);
|
2015-11-02 00:23:22 +03:00
|
|
|
|
|
|
|
private slots:
|
2017-04-26 12:38:10 +03:00
|
|
|
void shareesFetched(const QJsonDocument &reply);
|
2015-11-02 00:23:22 +03:00
|
|
|
|
|
|
|
private:
|
2017-04-26 12:38:10 +03:00
|
|
|
QSharedPointer<Sharee> parseSharee(const QJsonObject &data);
|
2015-11-16 16:18:01 +03:00
|
|
|
void setNewSharees(const QVector<QSharedPointer<Sharee>> &newSharees);
|
2015-11-05 00:00:35 +03:00
|
|
|
|
2015-11-02 00:23:22 +03:00
|
|
|
AccountPtr _account;
|
|
|
|
QString _search;
|
|
|
|
QString _type;
|
|
|
|
|
|
|
|
QVector<QSharedPointer<Sharee>> _sharees;
|
2015-11-05 14:30:34 +03:00
|
|
|
QVector<QSharedPointer<Sharee>> _shareeBlacklist;
|
2015-11-02 00:23:22 +03:00
|
|
|
};
|
|
|
|
}
|
2015-11-05 00:00:35 +03:00
|
|
|
|
2015-11-10 12:06:14 +03:00
|
|
|
Q_DECLARE_METATYPE(QSharedPointer<OCC::Sharee>)
|
2015-11-09 19:21:42 +03:00
|
|
|
|
2015-11-05 00:00:35 +03:00
|
|
|
#endif //SHAREE_H
|