Merge pull request #473 from Montellese/onplaybackspeedchanged
[vuplus_xbmc] / xbmc / interfaces / json-rpc / ApplicationOperations.cpp
1 /*
2  *      Copyright (C) 2005-2010 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, write to
17  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18  *  http://www.gnu.org/copyleft/gpl.html
19  *
20  */
21
22 #include "ApplicationOperations.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
31 using namespace JSONRPC;
32
33 JSON_STATUS CApplicationOperations::GetProperties(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
34 {
35   CVariant properties = CVariant(CVariant::VariantTypeObject);
36   for (unsigned int index = 0; index < parameterObject["properties"].size(); index++)
37   {
38     CStdString propertyName = parameterObject["properties"][index].asString();
39     CVariant property;
40     JSON_STATUS ret;
41     if ((ret = GetPropertyValue(propertyName, property)) != OK)
42       return ret;
43
44     properties[propertyName] = property;
45   }
46
47   result = properties;
48
49   return OK;
50 }
51
52 JSON_STATUS CApplicationOperations::SetVolume(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
53 {
54   int oldVolume = g_application.GetVolume();
55   int volume = (int)parameterObject["volume"].asInteger();
56   
57   g_application.SetVolume(volume);
58
59   g_application.getApplicationMessenger().ShowVolumeBar(oldVolume < volume);
60
61   return GetPropertyValue("volume", result);
62 }
63
64 JSON_STATUS CApplicationOperations::SetMute(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
65 {
66   if ((parameterObject["mute"].isString() && parameterObject["mute"].asString().compare("toggle") == 0) ||
67       (parameterObject["mute"].isBoolean() && parameterObject["mute"].asBoolean() != g_application.IsMuted()))
68     g_application.getApplicationMessenger().SendAction(CAction(ACTION_MUTE));
69   else if (!parameterObject["mute"].isBoolean() && !parameterObject["mute"].isString())
70     return InvalidParams;
71
72   return GetPropertyValue("muted", result);
73 }
74
75 JSON_STATUS CApplicationOperations::Quit(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
76 {
77   g_application.getApplicationMessenger().Quit();
78   return ACK;
79 }
80
81 JSON_STATUS CApplicationOperations::GetPropertyValue(const CStdString &property, CVariant &result)
82 {
83   if (property.Equals("volume"))
84     result = g_application.GetVolume();
85   else if (property.Equals("muted"))
86     result = g_application.IsMuted();
87   else if (property.Equals("name"))
88     result = "XBMC";
89   else if (property.Equals("version"))
90   {
91     result = CVariant(CVariant::VariantTypeObject);
92     result["major"] = VERSION_MAJOR;
93     result["minor"] = VERSION_MINOR;
94 #ifdef GIT_REV
95     result["revision"] = GIT_REV;
96 #endif
97     CStdString tag(VERSION_TAG);
98     if (tag.Equals("PRE-"))
99       result["tag"] = "alpha";
100     else if (tag.Equals("BETA-"))
101       result["tag"] = "beta";
102     else if (tag.Left(2).Equals("RC"))
103       result["tag"] = "releasecandidate";
104     else if (tag.empty())
105       result["tag"] = "stable";
106     else
107       result["tag"] = "prealpha";
108   }
109   else
110     return InvalidParams;
111
112   return OK;
113 }