File indexing completed on 2024-12-22 05:30:44

0001 /*
0002     SPDX-FileCopyrightText: 2020 HanY <hanyoung@protonmail.com>
0003     SPDX-License-Identifier: LGPL-2.1-or-later
0004 */
0005 
0006 #ifndef KWEATHER_1X4_H
0007 #define KWEATHER_1X4_H
0008 
0009 #include <Plasma/Applet>
0010 
0011 #include <KWeatherCore/WeatherForecastSource>
0012 
0013 class HourlyModel;
0014 class QTimer;
0015 class KWeather_1x4 : public Plasma::Applet
0016 {
0017     Q_OBJECT
0018     Q_PROPERTY(bool needLocation READ needLocation NOTIFY needLocationChanged)
0019     Q_PROPERTY(QString location READ location NOTIFY locationChanged)
0020     Q_PROPERTY(qreal temp READ temp NOTIFY updated)
0021     Q_PROPERTY(QString desc READ desc NOTIFY updated)
0022     Q_PROPERTY(QString weatherIcon READ weatherIcon NOTIFY updated)
0023     Q_PROPERTY(qreal humidity READ humidity NOTIFY updated)
0024     Q_PROPERTY(qreal precipitation READ precipitation NOTIFY updated)
0025     Q_PROPERTY(HourlyModel *hourlyModel READ hourlyModel NOTIFY hourlyModelChanged)
0026 public:
0027     KWeather_1x4(QObject *parent, const KPluginMetaData &md, const QVariantList &args);
0028     QString location() const;
0029     QString desc() const;
0030     qreal temp() const;
0031     QString weatherIcon() const;
0032     qreal humidity() const;
0033     qreal precipitation() const;
0034     bool needLocation() const
0035     {
0036         return m_needLocation;
0037     }
0038     HourlyModel *hourlyModel() const
0039     {
0040         return m_hourlyModel;
0041     }
0042 
0043     Q_INVOKABLE QStringList locationsInSystem();
0044     Q_INVOKABLE void setLocation(const QString &location);
0045 Q_SIGNALS:
0046     void locationChanged();
0047     void updated();
0048     void needLocationChanged();
0049     void hourlyModelChanged();
0050 
0051 private:
0052     void update();
0053     bool hasForecast() const;
0054     const KWeatherCore::HourlyWeatherForecast &getFirst() const;
0055 
0056     bool m_needLocation = true;
0057     QString m_location;
0058     double m_latitude, m_longitude;
0059     KWeatherCore::WeatherForecast m_forecast;
0060     KWeatherCore::WeatherForecastSource m_source;
0061 
0062     HourlyModel *m_hourlyModel = nullptr;
0063     QTimer *m_timer = nullptr;
0064 };
0065 
0066 #endif