QXmpp  Version: 1.15.1
QXmppFileShare.h
1 // SPDX-FileCopyrightText: 2022 Linus Jahn <lnj@kaidan.im>
2 //
3 // SPDX-License-Identifier: LGPL-2.1-or-later
4 
5 #ifndef QXMPPFILESHARE_H
6 #define QXMPPFILESHARE_H
7 
8 #include "QXmppConstants_p.h"
9 #include "QXmppGlobal.h"
10 
11 #include <any>
12 #include <functional>
13 #include <optional>
14 
15 #include <QSharedDataPointer>
16 
17 class QDomElement;
18 class QUrl;
19 class QXmlStreamWriter;
20 class QXmppFileSourcesAttachmentPrivate;
21 class QXmppFileSharePrivate;
22 class QXmppFileMetadata;
25 
26 namespace QXmpp::Private {
27 class XmlWriter;
28 }
29 
30 class QXMPP_EXPORT QXmppFileSourcesAttachment
31 {
32 public:
34  QXMPP_PRIVATE_DECLARE_RULE_OF_SIX(QXmppFileSourcesAttachment)
35 
36  const QString &id() const;
37  void setId(const QString &);
38 
39  const QVector<QXmppHttpFileSource> &httpSources() const;
40  void setHttpSources(const QVector<QXmppHttpFileSource> &newHttpSources);
41 
42  const QVector<QXmppEncryptedFileSource> &encryptedSources() const;
43  void setEncryptedSources(const QVector<QXmppEncryptedFileSource> &newEncryptedSources);
44 
45  void toXml(QXmpp::Private::XmlWriter &writer) const;
46 
47 private:
48  friend class QXmppMessage;
49 
50  static std::optional<QXmppFileSourcesAttachment> fromDom(const QDomElement &el);
51 
52  QSharedDataPointer<QXmppFileSourcesAttachmentPrivate> d;
53 };
54 
55 class QXMPP_EXPORT QXmppFileShare
56 {
57 public:
58  enum Disposition {
59  Inline,
60  Attachment,
61  };
62 
64  QXMPP_PRIVATE_DECLARE_RULE_OF_SIX(QXmppFileShare)
65 
66  Disposition disposition() const;
67  void setDisposition(Disposition);
68 
69  const QString &id() const;
70  void setId(const QString &);
71 
72  const QXmppFileMetadata &metadata() const;
73  void setMetadata(const QXmppFileMetadata &);
74 
75  const QVector<QXmppHttpFileSource> &httpSources() const;
76  void setHttpSources(const QVector<QXmppHttpFileSource> &newHttpSources);
77 
78  const QVector<QXmppEncryptedFileSource> &encryptedSources() const;
79  void setEncryptedSourecs(const QVector<QXmppEncryptedFileSource> &newEncryptedSources);
80 
82  static constexpr std::tuple XmlTag = { u"file-sharing", QXmpp::Private::ns_sfs };
83  bool parse(const QDomElement &el);
84  void toXml(QXmlStreamWriter *writer) const;
85 
86 protected:
87  friend class QXmppFileSharingManager;
88  friend class QXmppFileUpload;
89 
90  // Private, internally used API:
91  void visitSources(std::function<bool(const std::any &)> &&visitor) const;
92  void addSource(const std::any &source);
94 
95 private:
96  QSharedDataPointer<QXmppFileSharePrivate> d;
97 };
98 
99 #endif // QXMPPFILESHARE_H
Definition: QXmppFileSharingManager.h:118
Definition: QXmppFileMetadata.h:23
Definition: QXmppFileShare.h:55
Disposition
Decides whether to display the file contents (e.g. an image) inline in the chat or as a file...
Definition: QXmppFileShare.h:58
Definition: QXmppFileShare.h:30
Provides progress of stateless file sharing uploads.
Definition: QXmppFileSharingManager.h:31
Represents an encrypted file source for file sharing.
Definition: QXmppEncryptedFileSource.h:20
The QXmppMessage class represents an XMPP message.
Definition: QXmppMessage.h:63
Definition: Algorithms.h:14
Definition: QXmppHttpFileSource.h:16