File indexing completed on 2024-05-05 16:49:23
0001 /* 0002 * SPDX-FileCopyrightText: 2020-2021 Han Young <hanyoung@protonmail.com> 0003 * SPDX-FileCopyrightText: 2020 Devin Lin <espidev@gmail.com> 0004 * 0005 * SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 #pragma once 0008 #include "sunrise.h" 0009 #include <QDateTime> 0010 #include <QObject> 0011 #include <kweathercore/kweathercore_export.h> 0012 class QNetworkAccessManager; 0013 class QNetworkReply; 0014 namespace KWeatherCore 0015 { 0016 /** 0017 * @short The SunriseSource class can obtain the sunrise data of one location 0018 * for several days 0019 * 0020 * @see Sunrise 0021 * 0022 * @author Han Young <hanyoung@protonmail.com> 0023 */ 0024 class KWEATHERCORE_EXPORT SunriseSource : public QObject 0025 { 0026 Q_OBJECT 0027 public: 0028 /** 0029 * SunriseSource 0030 * @param timezone timezone ID 0031 * @param sunrise for caching purpose 0032 */ 0033 SunriseSource(double latitude, 0034 double longitude, 0035 const QString &timezone = QString(), 0036 const std::vector<Sunrise> &sunrise = std::vector<Sunrise>(), 0037 QObject *parent = nullptr); 0038 /** 0039 * start downloading data 0040 */ 0041 void requestData(); 0042 /** 0043 * change the timezone 0044 */ 0045 void setTimezone(const QString &timezone); 0046 /** 0047 * get the value 0048 * @return 0049 */ 0050 const std::vector<Sunrise> &value() const; 0051 Q_SIGNALS: 0052 /** 0053 * network error 0054 */ 0055 void networkError(); 0056 /** 0057 * query finished 0058 */ 0059 void finished(); 0060 private Q_SLOTS: 0061 void parseResults(QNetworkReply *reply); 0062 0063 private: 0064 double m_latitude, m_longitude; 0065 QString m_timezone; 0066 std::vector<Sunrise> m_sunriseVec; 0067 QNetworkAccessManager *m_manager = nullptr; 0068 0069 void popDay(); 0070 }; 0071 }