2 * Copyright (C) 2005-2010 Team XBMC
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)
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.
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
22 #include "ApplicationOperations.h"
23 #include "Application.h"
24 #include "ApplicationMessenger.h"
27 #include "utils/log.h"
28 #include "GUIInfoManager.h"
31 using namespace JSONRPC;
33 JSON_STATUS CApplicationOperations::GetProperties(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result)
35 CVariant properties = CVariant(CVariant::VariantTypeObject);
36 for (unsigned int index = 0; index < parameterObject["properties"].size(); index++)
38 CStdString propertyName = parameterObject["properties"][index].asString();
41 if ((ret = GetPropertyValue(propertyName, property)) != OK)
44 properties[propertyName] = property;
52 JSON_STATUS CApplicationOperations::SetVolume(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result)
54 int oldVolume = g_application.GetVolume();
55 int volume = (int)parameterObject["volume"].asInteger();
57 g_application.SetVolume(volume);
59 g_application.getApplicationMessenger().ShowVolumeBar(oldVolume < volume);
61 return GetPropertyValue("volume", result);
64 JSON_STATUS CApplicationOperations::SetMute(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result)
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())
72 return GetPropertyValue("muted", result);
75 JSON_STATUS CApplicationOperations::Quit(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result)
77 g_application.getApplicationMessenger().Quit();
81 JSON_STATUS CApplicationOperations::GetPropertyValue(const CStdString &property, CVariant &result)
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"))
89 else if (property.Equals("version"))
91 result = CVariant(CVariant::VariantTypeObject);
92 result["major"] = VERSION_MAJOR;
93 result["minor"] = VERSION_MINOR;
95 result["revision"] = GIT_REV;
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";
107 result["tag"] = "prealpha";
110 return InvalidParams;