File indexing completed on 2024-04-28 15:11:24
0001 /* 0002 SPDX-FileCopyrightText: 2013 Vijay Dhameliya <vijay.atwork13@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <QObject> 0010 #include <QByteArray> 0011 #include <QString> 0012 #include <QNetworkAccessManager> 0013 #include <QNetworkRequest> 0014 #include <QNetworkReply> 0015 0016 /** 0017 * @class SkyObjDescription 0018 * 0019 * Fetches short description for various sky object from wikipedia. 0020 * 0021 * @author Vijay Dhameliya 0022 */ 0023 class SkyObjDescription : public QObject 0024 { 0025 Q_OBJECT 0026 0027 public: 0028 /** 0029 * @brief Constructor sends request to network for data from wikipedia API and starts 0030 * downloading data from QUrl 0031 * @param soName SkyObject name 0032 * @param soType SkyObject type 0033 */ 0034 explicit SkyObjDescription(const QString soName, const QString soType); 0035 0036 virtual ~SkyObjDescription() override = default; 0037 0038 /** @return returns description if it was available on wikipedia else returns empty string */ 0039 QString downloadedData() const { return m_description; } 0040 0041 /** @return returns wikipedia link for skyobject */ 0042 QString url() const { return m_url; } 0043 0044 signals: 0045 void downloaded(); 0046 0047 private slots: 0048 /** 0049 * @brief parse downloaded data to extract description of SkyObject when downloading is finished 0050 * 0051 * @param reply 0052 */ 0053 void fileDownloaded(QNetworkReply *reply); 0054 0055 private: 0056 QString soName, soType, m_description, m_url; 0057 QNetworkAccessManager *manager { nullptr }; 0058 QByteArray m_DownloadedData; 0059 };