File indexing completed on 2024-10-06 04:34:01

0001 /*
0002    SPDX-FileCopyrightText: 2017-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "libruqolacore_export.h"
0010 #include "messageattachmentfield.h"
0011 #include <QDebug>
0012 class MessageAttachmentField;
0013 class LIBRUQOLACORE_EXPORT MessageAttachment
0014 {
0015     Q_GADGET
0016 public:
0017     MessageAttachment();
0018 
0019     enum AttachmentType {
0020         Unknown,
0021         NormalText,
0022         File,
0023         Video,
0024         Audio,
0025         Image,
0026     };
0027     Q_ENUM(AttachmentType)
0028     void parseAttachment(const QJsonObject &o);
0029 
0030     [[nodiscard]] bool isValid() const;
0031 
0032     [[nodiscard]] QString description() const;
0033     void setDescription(const QString &description);
0034 
0035     [[nodiscard]] QString title() const;
0036     void setTitle(const QString &title);
0037 
0038     [[nodiscard]] QString link() const;
0039     void setLink(const QString &link);
0040 
0041     [[nodiscard]] bool operator==(const MessageAttachment &other) const;
0042 
0043     static QJsonObject serialize(const MessageAttachment &message);
0044     static MessageAttachment deserialize(const QJsonObject &o);
0045     [[nodiscard]] int imageWidth() const;
0046     void setImageWidth(int imageWidth);
0047 
0048     [[nodiscard]] int imageHeight() const;
0049     void setImageHeight(int imageHeight);
0050 
0051     [[nodiscard]] QString color() const;
0052     void setColor(const QString &color);
0053 
0054     [[nodiscard]] QString authorName() const;
0055     void setAuthorName(const QString &authorName);
0056 
0057     [[nodiscard]] bool canDownloadAttachment() const;
0058     [[nodiscard]] QString displayTitle() const;
0059     [[nodiscard]] QString imageTitle() const;
0060 
0061     [[nodiscard]] QString mimeType() const;
0062     void setMimeType(const QString &type);
0063 
0064     [[nodiscard]] bool isAnimatedImage() const;
0065 
0066     [[nodiscard]] QString text() const;
0067     void setText(const QString &text);
0068 
0069     [[nodiscard]] AttachmentType attachmentType() const;
0070     void setAttachmentType(AttachmentType attachmentType);
0071 
0072     [[nodiscard]] QVector<MessageAttachmentField> attachmentFields() const;
0073     void setAttachmentFields(const QVector<MessageAttachmentField> &attachmentFields);
0074 
0075     [[nodiscard]] bool collapsed() const;
0076     void setCollapsed(bool collapsed);
0077 
0078     [[nodiscard]] QString attachmentId() const;
0079     void setAttachmentId(const QString &attachementId);
0080 
0081     [[nodiscard]] bool showAttachment() const;
0082     void setShowAttachment(bool showAttachment);
0083 
0084     [[nodiscard]] QString authorIcon() const;
0085     void setAuthorIcon(const QString &authorIcon);
0086 
0087     [[nodiscard]] QString attachmentFieldsText() const;
0088 
0089     void setImageUrlPreview(const QString &newImageUrlPreview);
0090 
0091     [[nodiscard]] const QString &imageUrlPreview() const;
0092 
0093     [[nodiscard]] bool hasDescription() const;
0094 
0095 private:
0096     LIBRUQOLACORE_NO_EXPORT void generateAttachmentFieldsText();
0097     QVector<MessageAttachmentField> mAttachmentFields;
0098     AttachmentType mAttachmentType = Unknown;
0099     QString mColor;
0100     QString mDescription;
0101     QString mTitle;
0102     QString mLink;
0103     QString mAuthorName;
0104     QString mMimeType;
0105     QString mText;
0106     QString mAttachmentId;
0107     QString mAuthorIcon;
0108     QString mAttachmentFieldsText;
0109     QString mImageUrlPreview;
0110     int mImageHeight = -1;
0111     int mImageWidth = -1;
0112     bool mIsAnimatedImage = false;
0113     bool mCollapsed = false;
0114     bool mShowAttachment = false;
0115 };
0116 Q_DECLARE_TYPEINFO(MessageAttachment, Q_RELOCATABLE_TYPE);
0117 LIBRUQOLACORE_EXPORT QDebug operator<<(QDebug d, const MessageAttachment &t);