summaryrefslogtreecommitdiffstats
path: root/xbmc/interfaces/builtins/WeatherBuiltins.cpp
blob: 8769a8887aa4227ef302bc8a03b0d6e89d92e07d (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
82
83
84
85
86
87
88
/*
 *  Copyright (C) 2005-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 "WeatherBuiltins.h"

#include "ServiceBroker.h"
#include "guilib/GUIComponent.h"
#include "guilib/GUIWindowManager.h"

#include <stdlib.h>

/*! \brief Switch to a given weather location.
 *  \param params The parameters.
 *  \details params[0] = 1, 2 or 3.
 */
static int SetLocation(const std::vector<std::string>& params)
{
  int loc = atoi(params[0].c_str());
  CGUIMessage msg(GUI_MSG_ITEM_SELECT, 0, 0, loc);
  CServiceBroker::GetGUI()->GetWindowManager().SendMessage(msg, WINDOW_WEATHER);

  return 0;
}

/*! \brief Switch weather location or refresh current.
 *  \param params (ignored)
 *
 *  The Direction template parameter can be -1 for previous location,
 *  1 for next location or 0 to refresh current location.
 */
  template<int Direction>
static int SwitchLocation(const std::vector<std::string>& params)
{
  CGUIMessage msg(GUI_MSG_MOVE_OFFSET, 0, 0, Direction);
  CServiceBroker::GetGUI()->GetWindowManager().SendMessage(msg, WINDOW_WEATHER);

  return 0;
}

// Note: For new Texts with comma add a "\" before!!! Is used for table text.
//
/// \page page_List_of_built_in_functions
/// \section built_in_functions_16 Weather built-in's
///
/// -----------------------------------------------------------------------------
///
/// \table_start
///   \table_h2_l{
///     Function,
///     Description }
///   \table_row2_l{
///     <b>`Weather.Refresh`</b>
///     ,
///     Force weather data refresh.
///   }
///   \table_row2_l{
///     <b>`Weather.LocationNext`</b>
///     ,
///     Switch to next weather location
///   }
///   \table_row2_l{
///     <b>`Weather.LocationPrevious`</b>
///     ,
///     Switch to previous weather location
///   }
///   \table_row2_l{
///     <b>`Weather.LocationSet`</b>
///     ,
///     Switch to given weather location (parameter can be 1-3).
///     @param[in] parameter             1-3
///   }
/// \table_end
///

CBuiltins::CommandMap CWeatherBuiltins::GetOperations() const
{
  return {
           {"weather.refresh",          {"Force weather data refresh", 0, SwitchLocation<0>}},
           {"weather.locationnext",     {"Switch to next weather location", 0, SwitchLocation<1>}},
           {"weather.locationprevious", {"Switch to previous weather location", 0, SwitchLocation<-1>}},
           {"weather.locationset",      {"Switch to given weather location (parameter can be 1-3)", 1, SetLocation}}
         };
}