File indexing completed on 2024-10-06 12:54:05
0001 // SPDX-FileCopyrightText: 2022 Bharadwaj Raju <bharadwaj.raju777@protonmail.com> 0002 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-or-later OR LicenseRef-KDE-Accepted-GPL 0003 0004 #pragma once 0005 0006 #include <QObject> 0007 #include <QUrl> 0008 0009 class NeoChatRoom; 0010 0011 /** 0012 * @class LinkPreviewer 0013 * 0014 * A class to download the link preview info for a URL and provide a QML interface for it. 0015 * 0016 * To use set the URL property and then access the other parameters which will be 0017 * populated once loaded is true. 0018 */ 0019 class LinkPreviewer : public QObject 0020 { 0021 Q_OBJECT 0022 /** 0023 * @brief The URL to get the preview for. 0024 */ 0025 Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged) 0026 0027 /** 0028 * @brief Whether the preview information has been loaded. 0029 */ 0030 Q_PROPERTY(bool loaded READ loaded NOTIFY loadedChanged) 0031 0032 /** 0033 * @brief The title of the preview. 0034 */ 0035 Q_PROPERTY(QString title READ title NOTIFY titleChanged) 0036 0037 /** 0038 * @brief The description of the preview. 0039 */ 0040 Q_PROPERTY(QString description READ description NOTIFY descriptionChanged) 0041 0042 /** 0043 * @brief The image source for the preview. 0044 */ 0045 Q_PROPERTY(QUrl imageSource READ imageSource NOTIFY imageSourceChanged) 0046 0047 public: 0048 explicit LinkPreviewer(QObject *parent = nullptr, NeoChatRoom *room = nullptr, const QUrl &url = {}); 0049 0050 [[nodiscard]] QUrl url() const; 0051 void setUrl(QUrl); 0052 [[nodiscard]] bool loaded() const; 0053 [[nodiscard]] QString title() const; 0054 [[nodiscard]] QString description() const; 0055 [[nodiscard]] QUrl imageSource() const; 0056 0057 private: 0058 NeoChatRoom *m_currentRoom = nullptr; 0059 0060 bool m_loaded; 0061 QString m_title = QString(); 0062 QString m_description = QString(); 0063 QUrl m_imageSource = QUrl(); 0064 QUrl m_url; 0065 0066 void loadUrlPreview(); 0067 0068 Q_SIGNALS: 0069 void loadedChanged(); 0070 void titleChanged(); 0071 void descriptionChanged(); 0072 void imageSourceChanged(); 0073 void urlChanged(); 0074 }; 0075 Q_DECLARE_METATYPE(LinkPreviewer *)