This repository has been archived by the owner on Sep 30, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 75
/
Weather.h
169 lines (143 loc) · 4.41 KB
/
Weather.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#pragma once
/*
* Copyright (C) 2005-2008 Team XBMC
* http://www.xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
#include "InfoLoader.h"
#include "StdString.h"
#include "utils/GlobalsHandling.h"
#include <map>
class TiXmlElement;
#define WEATHER_LABEL_LOCATION 10
#define WEATHER_IMAGE_CURRENT_ICON 21
#define WEATHER_LABEL_CURRENT_COND 22
#define WEATHER_LABEL_CURRENT_TEMP 23
#define WEATHER_LABEL_CURRENT_FEEL 24
#define WEATHER_LABEL_CURRENT_UVID 25
#define WEATHER_LABEL_CURRENT_WIND 26
#define WEATHER_LABEL_CURRENT_DEWP 27
#define WEATHER_LABEL_CURRENT_HUMI 28
struct day_forecast
{
CStdString m_icon;
CStdString m_overview;
CStdString m_day;
CStdString m_high;
CStdString m_low;
};
#define NUM_DAYS 7
class CWeatherInfo
{
public:
day_forecast forecast[NUM_DAYS];
void Reset()
{
lastUpdateTime.clear();
currentIcon.clear();
currentConditions.clear();
currentTemperature.clear();
currentFeelsLike.clear();
currentWind.clear();
currentHumidity.clear();
currentUVIndex.clear();
currentDewPoint.clear();
for (int i = 0; i < NUM_DAYS; i++)
{
forecast[i].m_icon.clear();
forecast[i].m_overview.clear();
forecast[i].m_day.clear();
forecast[i].m_high.clear();
forecast[i].m_low.clear();
}
};
CStdString lastUpdateTime;
CStdString location;
CStdString currentIcon;
CStdString currentConditions;
CStdString currentTemperature;
CStdString currentFeelsLike;
CStdString currentUVIndex;
CStdString currentWind;
CStdString currentDewPoint;
CStdString currentHumidity;
CStdString busyString;
CStdString naIcon;
};
class CWeatherJob : public CJob
{
public:
CWeatherJob(int location);
virtual bool DoWork();
const CWeatherInfo &GetInfo() const;
private:
void LocalizeOverview(CStdString &str);
void LocalizeOverviewToken(CStdString &str);
void LoadLocalizedToken();
int ConvertSpeed(int speed);
void SetFromProperties();
/*! \brief Formats a celcius temperature into a string based on the users locale
\param text the string to format
\param temp the temperature (in degrees celcius).
*/
void FormatTemperature(CStdString &text, int temp);
struct ci_less : std::binary_function<std::string, std::string, bool>
{
// case-independent (ci) compare_less binary function
struct nocase_compare : public std::binary_function<unsigned char,unsigned char,bool>
{
bool operator() (const unsigned char& c1, const unsigned char& c2) const {
return tolower (c1) < tolower (c2);
}
};
bool operator() (const std::string & s1, const std::string & s2) const {
return std::lexicographical_compare
(s1.begin (), s1.end (),
s2.begin (), s2.end (),
nocase_compare ());
}
};
std::map<CStdString, int, ci_less> m_localizedTokens;
typedef std::map<CStdString, int, ci_less>::const_iterator ilocalizedTokens;
CWeatherInfo m_info;
int m_location;
static bool m_imagesOkay;
};
class CWeather : public CInfoLoader
{
public:
CWeather(void);
virtual ~CWeather(void);
static bool GetSearchResults(const CStdString &strSearch, CStdString &strResult);
CStdString GetLocation(int iLocation);
const CStdString &GetLastUpdateTime() const { return m_info.lastUpdateTime; };
const day_forecast &GetForecast(int day) const;
bool IsFetched();
void Reset();
void SetArea(int iLocation);
int GetArea() const;
protected:
virtual CJob *GetJob() const;
virtual CStdString TranslateInfo(int info) const;
virtual CStdString BusyInfo(int info) const;
virtual void OnJobComplete(unsigned int jobID, bool success, CJob *job);
private:
CWeatherInfo m_info;
};
XBMC_GLOBAL_REF(CWeather, g_weatherManager);
#define g_weatherManager XBMC_GLOBAL_USE(CWeather)