only call IPlayerCallback::OnPlayBackSpeedChanged if the speed has actually changed
[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["value"].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::ToggleMute(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
65 {
66   g_application.getApplicationMessenger().SendAction(CAction(ACTION_MUTE));
67   return GetPropertyValue("volume", result);
68 }
69
70 JSON_STATUS CApplicationOperations::Quit(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
71 {
72   g_application.getApplicationMessenger().Quit();
73   return ACK;
74 }
75
76 JSON_STATUS CApplicationOperations::GetPropertyValue(const CStdString &property, CVariant &result)
77 {
78   if (property.Equals("volume"))
79     result = g_application.GetVolume();
80   else if (property.Equals("muted"))
81     result = g_application.IsMuted();
82   else if (property.Equals("name"))
83     result = "XBMC";
84   else if (property.Equals("version"))
85   {
86     result = CVariant(CVariant::VariantTypeObject);
87     result["major"] = VERSION_MAJOR;
88     result["minor"] = VERSION_MINOR;
89 #ifdef GIT_REV
90     result["revision"] = GIT_REV;
91 #endif
92     CStdString tag(VERSION_TAG);
93     if (tag.Equals("PRE-"))
94       result["tag"] = "alpha";
95     else if (tag.Equals("BETA-"))
96       result["tag"] = "beta";
97     else if (tag.Left(2).Equals("RC"))
98       result["tag"] = "releasecandidate";
99     else if (tag.empty())
100       result["tag"] = "stable";
101     else
102       result["tag"] = "prealpha";
103   }
104   else
105     return InvalidParams;
106
107   return OK;
108 }