Merge pull request #2948 from ace20022/blu_lang_fix
[vuplus_xbmc] / xbmc / interfaces / json-rpc / ApplicationOperations.cpp
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://www.xbmc.org
4  *
5  *  This Program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2, or (at your option)
8  *  any later version.
9  *
10  *  This Program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with XBMC; see the file COPYING.  If not, see
17  *  <http://www.gnu.org/licenses/>.
18  *
19  */
20
21 #include "ApplicationOperations.h"
22 #include "InputOperations.h"
23 #include "Application.h"
24 #include "ApplicationMessenger.h"
25 #include "FileItem.h"
26 #include "Util.h"
27 #include "utils/log.h"
28 #include "GUIInfoManager.h"
29 #include "system.h"
30 #include "GitRevision.h"
31
32 using namespace JSONRPC;
33
34 JSONRPC_STATUS CApplicationOperations::GetProperties(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
35 {
36   CVariant properties = CVariant(CVariant::VariantTypeObject);
37   for (unsigned int index = 0; index < parameterObject["properties"].size(); index++)
38   {
39     CStdString propertyName = parameterObject["properties"][index].asString();
40     CVariant property;
41     JSONRPC_STATUS ret;
42     if ((ret = GetPropertyValue(propertyName, property)) != OK)
43       return ret;
44
45     properties[propertyName] = property;
46   }
47
48   result = properties;
49
50   return OK;
51 }
52
53 JSONRPC_STATUS CApplicationOperations::SetVolume(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
54 {
55   bool up = false;
56   if (parameterObject["volume"].isInteger())
57   {
58     int oldVolume = (int)g_application.GetVolume();
59     int volume = (int)parameterObject["volume"].asInteger();
60   
61     g_application.SetVolume((float)volume, true);
62
63     up = oldVolume < volume;
64   }
65   else if (parameterObject["volume"].isString())
66   {
67     JSONRPC_STATUS ret;
68     std::string direction = parameterObject["volume"].asString();
69     if (direction.compare("increment") == 0)
70     {
71       ret = CInputOperations::SendAction(ACTION_VOLUME_UP, false, true);
72       up = true;
73     }
74     else if (direction.compare("decrement") == 0)
75     {
76       ret = CInputOperations::SendAction(ACTION_VOLUME_DOWN, false, true);
77       up = false;
78     }
79     else
80       return InvalidParams;
81
82     if (ret != ACK && ret != OK)
83       return ret;
84   }
85   else
86     return InvalidParams;
87
88   CApplicationMessenger::Get().ShowVolumeBar(up);
89
90   return GetPropertyValue("volume", result);
91 }
92
93 JSONRPC_STATUS CApplicationOperations::SetMute(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
94 {
95   if ((parameterObject["mute"].isString() && parameterObject["mute"].asString().compare("toggle") == 0) ||
96       (parameterObject["mute"].isBoolean() && parameterObject["mute"].asBoolean() != g_application.IsMuted()))
97     CApplicationMessenger::Get().SendAction(CAction(ACTION_MUTE));
98   else if (!parameterObject["mute"].isBoolean() && !parameterObject["mute"].isString())
99     return InvalidParams;
100
101   return GetPropertyValue("muted", result);
102 }
103
104 JSONRPC_STATUS CApplicationOperations::Quit(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
105 {
106   CApplicationMessenger::Get().Quit();
107   return ACK;
108 }
109
110 JSONRPC_STATUS CApplicationOperations::GetPropertyValue(const CStdString &property, CVariant &result)
111 {
112   if (property.Equals("volume"))
113     result = (int)g_application.GetVolume();
114   else if (property.Equals("muted"))
115     result = g_application.IsMuted();
116   else if (property.Equals("name"))
117     result = "XBMC";
118   else if (property.Equals("version"))
119   {
120     result = CVariant(CVariant::VariantTypeObject);
121     result["major"] = VERSION_MAJOR;
122     result["minor"] = VERSION_MINOR;
123     if (GetXbmcGitRevision())
124       result["revision"] = GetXbmcGitRevision();
125     CStdString tag(VERSION_TAG);
126     if (tag.ToLower().Equals("-pre"))
127       result["tag"] = "alpha";
128     else if (tag.ToLower().Left(5).Equals("-beta"))
129       result["tag"] = "beta";
130     else if (tag.ToLower().Left(3).Equals("-rc"))
131       result["tag"] = "releasecandidate";
132     else if (tag.empty())
133       result["tag"] = "stable";
134     else
135       result["tag"] = "prealpha";
136   }
137   else
138     return InvalidParams;
139
140   return OK;
141 }