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

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 <QDebug>
0011 class LIBRUQOLACORE_EXPORT MessageUrl
0012 {
0013     Q_GADGET
0014 public:
0015     MessageUrl();
0016     [[nodiscard]] bool operator==(const MessageUrl &other) const;
0017     static QJsonObject serialize(const MessageUrl &url);
0018     static MessageUrl deserialize(const QJsonObject &o);
0019 
0020     [[nodiscard]] QString url() const;
0021     void setUrl(const QString &url);
0022 
0023     [[nodiscard]] QString pageTitle() const;
0024     void setPageTitle(const QString &pageTitle);
0025 
0026     [[nodiscard]] bool isEmpty() const;
0027 
0028     [[nodiscard]] QString description() const;
0029     void setDescription(const QString &description);
0030 
0031     void parseUrl(const QJsonObject &url);
0032 
0033     [[nodiscard]] QString imageUrl() const;
0034     void setImageUrl(const QString &newImageUrl);
0035 
0036     [[nodiscard]] QString authorName() const;
0037     void setAuthorName(const QString &newAuthorName);
0038 
0039     [[nodiscard]] QString authorUrl() const;
0040     void setAuthorUrl(const QString &newAuthorUrl);
0041 
0042     [[nodiscard]] QString siteUrl() const;
0043     void setSiteUrl(const QString &newSiteUrl);
0044 
0045     [[nodiscard]] QString siteName() const;
0046     void setSiteName(const QString &newSiteName);
0047 
0048     [[nodiscard]] int imageHeight() const;
0049     void setImageHeight(int newImageHeight);
0050 
0051     [[nodiscard]] int imageWidth() const;
0052     void setImageWidth(int newImageWidth);
0053 
0054     [[nodiscard]] QString urlId() const;
0055     void setUrlId(const QString &newUrlId);
0056 
0057     [[nodiscard]] bool showPreview() const;
0058     void setShowPreview(bool newShowPreview);
0059 
0060     [[nodiscard]] bool hasPreviewUrl() const;
0061 
0062     [[nodiscard]] QString htmlDescription() const;
0063 
0064     [[nodiscard]] bool hasHtmlDescription() const;
0065 
0066     void generateHtmlDescription();
0067 
0068 private:
0069     [[nodiscard]] LIBRUQOLACORE_NO_EXPORT static QStringList pageTitleElements();
0070     [[nodiscard]] LIBRUQOLACORE_NO_EXPORT static QStringList descriptionElements();
0071     [[nodiscard]] LIBRUQOLACORE_NO_EXPORT static QStringList imageUrlElements();
0072     [[nodiscard]] LIBRUQOLACORE_NO_EXPORT static QStringList siteUrlElements();
0073     [[nodiscard]] LIBRUQOLACORE_NO_EXPORT static QStringList siteNameElements();
0074     [[nodiscard]] LIBRUQOLACORE_NO_EXPORT static QStringList imageHeightElements();
0075     [[nodiscard]] LIBRUQOLACORE_NO_EXPORT static QStringList imageWidthElements();
0076     [[nodiscard]] LIBRUQOLACORE_NO_EXPORT static QString cleanText(const QString &str);
0077 
0078     QString mUrl;
0079     QString mPageTitle;
0080     QString mDescription;
0081     QString mImageUrl;
0082     QString mAuthorName;
0083     QString mAuthorUrl;
0084     QString mSiteUrl;
0085     QString mSiteName;
0086     QString mUrlId;
0087     QString mHtmlDescription;
0088     int mImageHeight = -1;
0089     int mImageWidth = -1;
0090     bool mShowPreview = true;
0091 };
0092 LIBRUQOLACORE_EXPORT QDebug operator<<(QDebug d, const MessageUrl &t);
0093 Q_DECLARE_TYPEINFO(MessageUrl, Q_RELOCATABLE_TYPE);