summaryrefslogtreecommitdiffstats
path: root/xbmc/guilib/guiinfo/WeatherGUIInfo.cpp
blob: 3aa20448d046d79fb3148b9e0279935554782c8b (plain)
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
/*
 *  Copyright (C) 2012-2018 Team Kodi
 *  This file is part of Kodi - https://kodi.tv
 *
 *  SPDX-License-Identifier: GPL-2.0-or-later
 *  See LICENSES/README.md for more information.
 */

#include "guilib/guiinfo/WeatherGUIInfo.h"

#include "FileItem.h"
#include "LangInfo.h"
#include "ServiceBroker.h"
#include "guilib/guiinfo/GUIInfo.h"
#include "guilib/guiinfo/GUIInfoLabels.h"
#include "settings/Settings.h"
#include "settings/SettingsComponent.h"
#include "utils/StringUtils.h"
#include "utils/URIUtils.h"
#include "weather/WeatherManager.h"

using namespace KODI::GUILIB::GUIINFO;

bool CWeatherGUIInfo::InitCurrentItem(CFileItem *item)
{
  return false;
}

bool CWeatherGUIInfo::GetLabel(std::string& value, const CFileItem *item, int contextWindow, const CGUIInfo &info, std::string *fallback) const
{
  switch (info.m_info)
  {
    ///////////////////////////////////////////////////////////////////////////////////////////////
    // WEATHER_*
    ///////////////////////////////////////////////////////////////////////////////////////////////
    case WEATHER_CONDITIONS_TEXT:
      value = CServiceBroker::GetWeatherManager().GetInfo(WEATHER_LABEL_CURRENT_COND);
      StringUtils::Trim(value);
      return true;
    case WEATHER_CONDITIONS_ICON:
      value = CServiceBroker::GetWeatherManager().GetInfo(WEATHER_IMAGE_CURRENT_ICON);
      return true;
    case WEATHER_TEMPERATURE:
      value = StringUtils::Format(
          "{}{}", CServiceBroker::GetWeatherManager().GetInfo(WEATHER_LABEL_CURRENT_TEMP),
          g_langInfo.GetTemperatureUnitString());
      return true;
    case WEATHER_LOCATION:
      value = CServiceBroker::GetWeatherManager().GetInfo(WEATHER_LABEL_LOCATION);
      return true;
    case WEATHER_FANART_CODE:
      value = URIUtils::GetFileName(CServiceBroker::GetWeatherManager().GetInfo(WEATHER_IMAGE_CURRENT_ICON));
      URIUtils::RemoveExtension(value);
      return true;
    case WEATHER_PLUGIN:
      value = CServiceBroker::GetSettingsComponent()->GetSettings()->GetString(CSettings::SETTING_WEATHER_ADDON);
      return true;
  }

  return false;
}

bool CWeatherGUIInfo::GetInt(int& value, const CGUIListItem *gitem, int contextWindow, const CGUIInfo &info) const
{
  return false;
}

bool CWeatherGUIInfo::GetBool(bool& value, const CGUIListItem *gitem, int contextWindow, const CGUIInfo &info) const
{
  switch (info.m_info)
  {
    ///////////////////////////////////////////////////////////////////////////////////////////////
    // WEATHER_*
    ///////////////////////////////////////////////////////////////////////////////////////////////
    case WEATHER_IS_FETCHED:
      value = CServiceBroker::GetWeatherManager().IsFetched();
      return true;;
  }

  return false;
}