/* * Copyright (C) by Roeland Jago Douma * * 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 #include #include #include #include #include #include #include #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, Email = 4, Federated = 6, Circle = 7, Room = 10 }; explicit Sharee(const QString shareWith, const QString displayName, const Type type); [[nodiscard]] QString format() const; [[nodiscard]] QString shareWith() const; [[nodiscard]] QString displayName() const; [[nodiscard]] Type type() const; private: QString _shareWith; QString _displayName; Type _type; }; class ShareeModel : public QAbstractListModel { Q_OBJECT public: enum LookupMode { LocalSearch = 0, GlobalSearch = 1 }; explicit ShareeModel(const AccountPtr &account, const QString &type, QObject *parent = nullptr); using ShareeSet = QVector>; // FIXME: make it a QSet when Sharee can be compared void fetch(const QString &search, const ShareeSet &blacklist, LookupMode lookupMode); [[nodiscard]] int rowCount(const QModelIndex &parent = QModelIndex()) const override; [[nodiscard]] QVariant data(const QModelIndex &index, int role) const override; QSharedPointer getSharee(int at); [[nodiscard]] QString currentSearch() const { return _search; } signals: void shareesReady(); void displayErrorMessage(int code, const QString &); private slots: void shareesFetched(const QJsonDocument &reply); private: QSharedPointer parseSharee(const QJsonObject &data); void setNewSharees(const QVector> &newSharees); AccountPtr _account; QString _search; QString _type; QVector> _sharees; QVector> _shareeBlacklist; }; } Q_DECLARE_METATYPE(QSharedPointer) #endif //SHAREE_H