| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- /*
- * Copyright (C) 2022 by Claudio Cambra <claudio.cambra@nextcloud.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.
- */
- #pragma once
- #include <QAbstractListModel>
- #include "accountstate.h"
- #include "folder.h"
- #include "sharemanager.h"
- #include "sharepermissions.h"
- namespace OCC {
- class ShareModel : public QAbstractListModel
- {
- Q_OBJECT
- Q_PROPERTY(AccountState* accountState READ accountState WRITE setAccountState NOTIFY accountStateChanged)
- Q_PROPERTY(QString localPath READ localPath WRITE setLocalPath NOTIFY localPathChanged)
- Q_PROPERTY(bool accountConnected READ accountConnected NOTIFY accountConnectedChanged)
- Q_PROPERTY(bool sharingEnabled READ sharingEnabled NOTIFY sharingEnabledChanged)
- Q_PROPERTY(bool publicLinkSharesEnabled READ publicLinkSharesEnabled NOTIFY publicLinkSharesEnabledChanged)
- Q_PROPERTY(bool userGroupSharingEnabled READ userGroupSharingEnabled NOTIFY userGroupSharingEnabledChanged)
- Q_PROPERTY(bool canShare READ canShare NOTIFY sharePermissionsChanged)
- Q_PROPERTY(bool fetchOngoing READ fetchOngoing NOTIFY fetchOngoingChanged)
- Q_PROPERTY(bool hasInitialShareFetchCompleted READ hasInitialShareFetchCompleted NOTIFY hasInitialShareFetchCompletedChanged)
- Q_PROPERTY(QVariantList sharees READ sharees NOTIFY shareesChanged)
- public:
- enum Roles {
- ShareRole = Qt::UserRole + 1,
- ShareTypeRole,
- ShareIdRole,
- IconUrlRole,
- AvatarUrlRole,
- LinkRole,
- LinkShareNameRole,
- LinkShareLabelRole,
- NoteEnabledRole,
- NoteRole,
- ExpireDateEnabledRole,
- ExpireDateEnforcedRole,
- ExpireDateRole,
- EnforcedMaximumExpireDateRole,
- PasswordProtectEnabledRole,
- PasswordRole,
- PasswordEnforcedRole,
- EditingAllowedRole,
- IsSecureFileDropLinkRole,
- };
- Q_ENUM(Roles)
- /**
- * Possible share types
- * Need to be in sync with Share::ShareType.
- * We use this in QML.
- */
- enum ShareType {
- ShareTypeUser = Share::TypeUser,
- ShareTypeGroup = Share::TypeGroup,
- ShareTypeLink = Share::TypeLink,
- ShareTypeEmail = Share::TypeEmail,
- ShareTypeRemote = Share::TypeRemote,
- ShareTypeCircle = Share::TypeCircle,
- ShareTypeRoom = Share::TypeRoom,
- ShareTypePlaceholderLink = Share::TypePlaceholderLink,
- ShareTypeInternalLink = Share::TypeInternalLink,
- ShareTypeSecureFileDropPlaceholderLink = Share::TypeSecureFileDropPlaceholderLink,
- };
- Q_ENUM(ShareType);
- explicit ShareModel(QObject *parent = nullptr);
- [[nodiscard]] QVariant data(const QModelIndex &index, const int role) const override;
- [[nodiscard]] int rowCount(const QModelIndex &parent = QModelIndex()) const override;
- [[nodiscard]] QHash<int, QByteArray> roleNames() const override;
- [[nodiscard]] AccountState *accountState() const;
- [[nodiscard]] QString localPath() const;
- [[nodiscard]] bool accountConnected() const;
- [[nodiscard]] bool sharingEnabled() const;
- [[nodiscard]] bool publicLinkSharesEnabled() const;
- [[nodiscard]] bool userGroupSharingEnabled() const;
- [[nodiscard]] bool canShare() const;
- [[nodiscard]] bool fetchOngoing() const;
- [[nodiscard]] bool hasInitialShareFetchCompleted() const;
- [[nodiscard]] QVariantList sharees() const;
- signals:
- void localPathChanged();
- void accountStateChanged();
- void accountConnectedChanged();
- void sharingEnabledChanged();
- void publicLinkSharesEnabledChanged();
- void userGroupSharingEnabledChanged();
- void sharePermissionsChanged();
- void lockExpireStringChanged();
- void fetchOngoingChanged();
- void hasInitialShareFetchCompletedChanged();
- void shareesChanged();
- void internalLinkReady();
- void serverError(const int code, const QString &message);
- void passwordSetError(const QString &shareId, const int code, const QString &message);
- void requestPasswordForLinkShare();
- void requestPasswordForEmailSharee(const OCC::ShareePtr &sharee);
- void sharesChanged();
- public slots:
- void setAccountState(OCC::AccountState *accountState);
- void setLocalPath(const QString &localPath);
- void createNewLinkShare() const;
- void createNewLinkShareWithPassword(const QString &password) const;
- void createNewUserGroupShare(const OCC::ShareePtr &sharee);
- void createNewUserGroupShareFromQml(const QVariant &sharee);
- void createNewUserGroupShareWithPassword(const OCC::ShareePtr &sharee, const QString &password) const;
- void createNewUserGroupShareWithPasswordFromQml(const QVariant &sharee, const QString &password) const;
- void deleteShare(const OCC::SharePtr &share) const;
- void deleteShareFromQml(const QVariant &share) const;
- void toggleShareAllowEditing(const OCC::SharePtr &share, const bool enable) const;
- void toggleShareAllowEditingFromQml(const QVariant &share, const bool enable) const;
- void toggleShareAllowResharing(const OCC::SharePtr &share, const bool enable) const;
- void toggleShareAllowResharingFromQml(const QVariant &share, const bool enable) const;
- void toggleSharePasswordProtect(const OCC::SharePtr &share, const bool enable);
- void toggleSharePasswordProtectFromQml(const QVariant &share, const bool enable);
- void toggleShareExpirationDate(const OCC::SharePtr &share, const bool enable) const;
- void toggleShareExpirationDateFromQml(const QVariant &share, const bool enable) const;
- void toggleShareNoteToRecipient(const OCC::SharePtr &share, const bool enable) const;
- void toggleShareNoteToRecipientFromQml(const QVariant &share, const bool enable) const;
- void setLinkShareLabel(const QSharedPointer<OCC::LinkShare> &linkShare, const QString &label) const;
- void setLinkShareLabelFromQml(const QVariant &linkShare, const QString &label) const;
- void setShareExpireDate(const OCC::SharePtr &share, const qint64 milliseconds) const;
- // Needed as ints in QML are 32 bits so we need to use a QVariant
- void setShareExpireDateFromQml(const QVariant &share, const QVariant milliseconds) const;
- void setSharePassword(const OCC::SharePtr &share, const QString &password);
- void setSharePasswordFromQml(const QVariant &share, const QString &password);
- void setShareNote(const OCC::SharePtr &share, const QString ¬e) const;
- void setShareNoteFromQml(const QVariant &share, const QString ¬e) const;
- private slots:
- void resetData();
- void updateData();
- void initShareManager();
- void handlePlaceholderLinkShare();
- void handleSecureFileDropLinkShare();
- void handleLinkShare();
- void setupInternalLinkShare();
- void slotPropfindReceived(const QVariantMap &result);
- void slotServerError(const int code, const QString &message);
- void slotAddShare(const OCC::SharePtr &share);
- void slotRemoveShareWithId(const QString &shareId);
- void slotSharesFetched(const QList<OCC::SharePtr> &shares);
- void slotAddSharee(const OCC::ShareePtr &sharee);
- void slotRemoveSharee(const OCC::ShareePtr &sharee);
- void slotSharePermissionsSet(const QString &shareId);
- void slotSharePasswordSet(const QString &shareId);
- void slotShareNoteSet(const QString &shareId);
- void slotShareNameSet(const QString &shareId);
- void slotShareLabelSet(const QString &shareId);
- void slotShareExpireDateSet(const QString &shareId);
- private:
- [[nodiscard]] QString displayStringForShare(const SharePtr &share) const;
- [[nodiscard]] QString iconUrlForShare(const SharePtr &share) const;
- [[nodiscard]] QString avatarUrlForShare(const SharePtr &share) const;
- [[nodiscard]] long long enforcedMaxExpireDateForShare(const SharePtr &share) const;
- [[nodiscard]] bool expireDateEnforcedForShare(const SharePtr &share) const;
- [[nodiscard]] bool validCapabilities() const;
- bool _fetchOngoing = false;
- bool _hasInitialShareFetchCompleted = false;
- SharePtr _placeholderLinkShare;
- SharePtr _internalLinkShare;
- SharePtr _secureFileDropPlaceholderLinkShare;
- QPointer<AccountState> _accountState;
- QPointer<Folder> _folder;
- QString _localPath;
- QString _sharePath;
- SharePermissions _maxSharingPermissions;
- QByteArray _numericFileId;
- bool _isEncryptedItem = false;
- bool _isSecureFileDropSupportedFolder = false;
- SyncJournalFileLockInfo _filelockState;
- QString _privateLinkUrl;
- QSharedPointer<ShareManager> _manager;
- QVector<SharePtr> _shares;
- QHash<QString, QPersistentModelIndex> _shareIdIndexHash;
- QHash<QString, QString> _shareIdRecentlySetPasswords;
- QVector<ShareePtr> _sharees;
- };
- } // namespace OCC
|