2 * Copyright (C) 2005-2013 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, see
17 * <http://www.gnu.org/licenses/>.
21 #include "ApplicationOperations.h"
22 #include "InputOperations.h"
23 #include "Application.h"
24 #include "ApplicationMessenger.h"
27 #include "utils/log.h"
28 #include "GUIInfoManager.h"
30 #include "GitRevision.h"
32 using namespace JSONRPC;
34 JSONRPC_STATUS CApplicationOperations::GetProperties(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result)
36 CVariant properties = CVariant(CVariant::VariantTypeObject);
37 for (unsigned int index = 0; index < parameterObject["properties"].size(); index++)
39 CStdString propertyName = parameterObject["properties"][index].asString();
42 if ((ret = GetPropertyValue(propertyName, property)) != OK)
45 properties[propertyName] = property;
53 JSONRPC_STATUS CApplicationOperations::SetVolume(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result)
56 if (parameterObject["volume"].isInteger())
58 int oldVolume = (int)g_application.GetVolume();
59 int volume = (int)parameterObject["volume"].asInteger();
61 g_application.SetVolume((float)volume, true);
63 up = oldVolume < volume;
65 else if (parameterObject["volume"].isString())
68 std::string direction = parameterObject["volume"].asString();
69 if (direction.compare("increment") == 0)
71 ret = CInputOperations::SendAction(ACTION_VOLUME_UP, false, true);
74 else if (direction.compare("decrement") == 0)
76 ret = CInputOperations::SendAction(ACTION_VOLUME_DOWN, false, true);
82 if (ret != ACK && ret != OK)
88 CApplicationMessenger::Get().ShowVolumeBar(up);
90 return GetPropertyValue("volume", result);
93 JSONRPC_STATUS CApplicationOperations::SetMute(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result)
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())
101 return GetPropertyValue("muted", result);
104 JSONRPC_STATUS CApplicationOperations::Quit(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result)
106 CApplicationMessenger::Get().Quit();
110 JSONRPC_STATUS CApplicationOperations::GetPropertyValue(const CStdString &property, CVariant &result)
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"))
118 else if (property.Equals("version"))
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";
135 result["tag"] = "prealpha";
138 return InvalidParams;