| 1 |
/* |
| 2 |
* Copyright (C) 2005-2018 Team Kodi |
| 3 |
* This file is part of Kodi - https://kodi.tv |
| 4 |
* |
| 5 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 6 |
* See LICENSES/README.md for more information. |
| 7 |
*/ |
| 8 |
|
| 9 |
#pragma once |
| 10 |
|
| 11 |
#include "settings/lib/ISettingCallback.h" |
| 12 |
#include "utils/InfoLoader.h" |
| 13 |
|
| 14 |
#include <string> |
| 15 |
|
| 16 |
#define WEATHER_LABEL_LOCATION 10 |
| 17 |
#define WEATHER_IMAGE_CURRENT_ICON 21 |
| 18 |
#define WEATHER_LABEL_CURRENT_COND 22 |
| 19 |
#define WEATHER_LABEL_CURRENT_TEMP 23 |
| 20 |
#define WEATHER_LABEL_CURRENT_FEEL 24 |
| 21 |
#define WEATHER_LABEL_CURRENT_UVID 25 |
| 22 |
#define WEATHER_LABEL_CURRENT_WIND 26 |
| 23 |
#define WEATHER_LABEL_CURRENT_DEWP 27 |
| 24 |
#define WEATHER_LABEL_CURRENT_HUMI 28 |
| 25 |
|
| 26 |
static const std::string ICON_ADDON_PATH = "resource://resource.images.weathericons.default"; |
| 27 |
|
| 28 |
struct ForecastDay |
| 29 |
{ |
| 30 |
std::string m_icon; |
| 31 |
std::string m_overview; |
| 32 |
std::string m_day; |
| 33 |
std::string m_high; |
| 34 |
std::string m_low; |
| 35 |
}; |
| 36 |
|
| 37 |
#define NUM_DAYS 7 |
| 38 |
|
| 39 |
class CWeatherInfo |
| 40 |
{ |
| 41 |
public: |
| 42 |
ForecastDay forecast[NUM_DAYS]; |
| 43 |
|
| 44 |
void Reset() |
| 45 |
{ |
| 46 |
lastUpdateTime.clear(); |
| 47 |
currentIcon.clear(); |
| 48 |
currentConditions.clear(); |
| 49 |
currentTemperature.clear(); |
| 50 |
currentFeelsLike.clear(); |
| 51 |
currentWind.clear(); |
| 52 |
currentHumidity.clear(); |
| 53 |
currentUVIndex.clear(); |
| 54 |
currentDewPoint.clear(); |
| 55 |
|
| 56 |
for (ForecastDay& f : forecast) |
| 57 |
{ |
| 58 |
f.m_icon.clear(); |
| 59 |
f.m_overview.clear(); |
| 60 |
f.m_day.clear(); |
| 61 |
f.m_high.clear(); |
| 62 |
f.m_low.clear(); |
| 63 |
} |
| 64 |
}; |
| 65 |
|
| 66 |
std::string lastUpdateTime; |
| 67 |
std::string location; |
| 68 |
std::string currentIcon; |
| 69 |
std::string currentConditions; |
| 70 |
std::string currentTemperature; |
| 71 |
std::string currentFeelsLike; |
| 72 |
std::string currentUVIndex; |
| 73 |
std::string currentWind; |
| 74 |
std::string currentDewPoint; |
| 75 |
std::string currentHumidity; |
| 76 |
std::string busyString; |
| 77 |
std::string naIcon; |
| 78 |
}; |
| 79 |
|
| 80 |
class CWeatherManager |
| 81 |
: public CInfoLoader, public ISettingCallback |
| 82 |
{ |
| 83 |
public: |
| 84 |
CWeatherManager(void); |
| 85 |
~CWeatherManager(void) override; |
| 86 |
static bool GetSearchResults(const std::string &strSearch, std::string &strResult); |
| 87 |
|
| 88 |
std::string GetLocation(int iLocation); |
| 89 |
const std::string& GetLastUpdateTime() const { return m_info.lastUpdateTime; } |
| 90 |
const ForecastDay &GetForecast(int day) const; |
| 91 |
bool IsFetched(); |
| 92 |
void Reset(); |
| 93 |
|
| 94 |
void SetArea(int iLocation); |
| 95 |
int GetArea() const; |
| 96 |
protected: |
| 97 |
CJob *GetJob() const override; |
| 98 |
std::string TranslateInfo(int info) const override; |
| 99 |
std::string BusyInfo(int info) const override; |
| 100 |
void OnJobComplete(unsigned int jobID, bool success, CJob *job) override; |
| 101 |
|
| 102 |
void OnSettingChanged(const std::shared_ptr<const CSetting>& setting) override; |
| 103 |
void OnSettingAction(const std::shared_ptr<const CSetting>& setting) override; |
| 104 |
|
| 105 |
private: |
| 106 |
|
| 107 |
CWeatherInfo m_info; |
| 108 |
}; |