/xbmc/utils/Weather.h

http://github.com/xbmc/xbmc · C Header · 173 lines · 122 code · 27 blank · 24 comment · 1 complexity · ad359203369a9114e8f1eb2d15a97b2f MD5 · raw file

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