Skip to content

Commit

Permalink
jsonrpc: add Input.SendText
Browse files Browse the repository at this point in the history
  • Loading branch information
Montellese committed Jul 10, 2012
1 parent 99e0bcf commit 15de540
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 9 deletions.
10 changes: 10 additions & 0 deletions xbmc/Application.cpp
Expand Up @@ -3061,6 +3061,16 @@ bool CApplication::ProcessJsonRpcButtons()
{
#ifdef HAS_JSONRPC
CKey tempKey(JSONRPC::CInputOperations::GetKey());
if (tempKey.GetButtonCode() == KEY_UNICODE && tempKey.GetUnicode() != 0)
{
XBMC_Event event = { 0 };
event.type = XBMC_KEYDOWN;
event.key.type = XBMC_KEYDOWN;
event.key.keysym.unicode = (uint16_t)tempKey.GetUnicode();
event.key.keysym.sym = (XBMCKey)tempKey.GetUnicode();

return OnEvent(event);
}
if (tempKey.GetButtonCode() != KEY_INVALID)
{
tempKey.SetFromService(true);
Expand Down
37 changes: 31 additions & 6 deletions xbmc/interfaces/json-rpc/InputOperations.cpp
Expand Up @@ -22,19 +22,23 @@
#include "InputOperations.h"
#include "Application.h"
#include "guilib/GUIAudioManager.h"
#include "guilib/GUIWindow.h"
#include "guilib/GUIWindowManager.h"
#include "input/XBMC_keyboard.h"
#include "input/XBMC_vkeys.h"
#include "threads/SingleLock.h"
#include "utils/CharsetConverter.h"

using namespace JSONRPC;

CCriticalSection CInputOperations::m_critSection;
uint32_t CInputOperations::m_key = KEY_INVALID;
CKey CInputOperations::m_key(KEY_INVALID);

uint32_t CInputOperations::GetKey()
CKey CInputOperations::GetKey()
{
CSingleLock lock(m_critSection);
uint32_t currentKey = m_key;
m_key = KEY_INVALID;
CKey currentKey = m_key;
m_key = CKey(KEY_INVALID);
return currentKey;
}

Expand All @@ -55,13 +59,16 @@ bool CInputOperations::handleScreenSaver()
return screenSaverBroken;
}

JSONRPC_STATUS CInputOperations::SendKey(uint32_t keyCode)
JSONRPC_STATUS CInputOperations::SendKey(uint32_t keyCode, bool unicode /* = false */)
{
if (keyCode == KEY_INVALID)
return InternalError;

CSingleLock lock(m_critSection);
m_key = keyCode | KEY_VKEY;
if (unicode)
m_key = CKey(0, (wchar_t)keyCode, 0, 0, 0);
else
m_key = CKey(keyCode | KEY_VKEY);
return ACK;
}

Expand All @@ -84,6 +91,24 @@ JSONRPC_STATUS CInputOperations::activateWindow(int windowID)
return ACK;
}

JSONRPC_STATUS CInputOperations::SendText(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
{
std::string text = parameterObject["text"].asString();
if (text.empty())
return InvalidParams;

int controlID = 0;
CGUIWindow *window = g_windowManager.GetWindow(g_windowManager.GetFocusedWindow());
if (!window)
return InternalError;

CGUIMessage msg(GUI_MSG_SET_TEXT, 0, 0);
msg.SetLabel(text);
msg.SetParam1(parameterObject["done"].asBoolean() ? 1 : 0);
g_application.getApplicationMessenger().SendGUIMessage(msg, window->GetID());
return ACK;
}

JSONRPC_STATUS CInputOperations::Left(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
{
return SendKey(XBMCVK_LEFT);
Expand Down
9 changes: 6 additions & 3 deletions xbmc/interfaces/json-rpc/InputOperations.h
Expand Up @@ -21,6 +21,7 @@
*/

#include "JSONRPC.h"
#include "guilib/Key.h"
#include "threads/CriticalSection.h"
#include "utils/StdString.h"

Expand All @@ -29,7 +30,9 @@ namespace JSONRPC
class CInputOperations
{
public:
static uint32_t GetKey();
static CKey GetKey();

static JSONRPC_STATUS SendText(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);

static JSONRPC_STATUS Left(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
static JSONRPC_STATUS Right(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
Expand All @@ -42,14 +45,14 @@ namespace JSONRPC
static JSONRPC_STATUS Info(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
static JSONRPC_STATUS Home(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);

static JSONRPC_STATUS SendKey(uint32_t keyCode);
static JSONRPC_STATUS SendKey(uint32_t keyCode, bool unicode = false);
static JSONRPC_STATUS SendAction(int actionID, bool wakeScreensaver = true, bool waitResult = false);

private:
static JSONRPC_STATUS activateWindow(int windowID);
static bool handleScreenSaver();

static CCriticalSection m_critSection;
static uint32_t m_key;
static CKey m_key;
};
}
1 change: 1 addition & 0 deletions xbmc/interfaces/json-rpc/JSONServiceDescription.cpp
Expand Up @@ -162,6 +162,7 @@ JsonRpcMethodMap CJSONServiceDescription::m_methodMaps[] = {
{ "System.Reboot", CSystemOperations::Reboot },

// Input operations
{ "Input.SendText", CInputOperations::SendText },
{ "Input.Left", CInputOperations::Left },
{ "Input.Right", CInputOperations::Right },
{ "Input.Down", CInputOperations::Down },
Expand Down
11 changes: 11 additions & 0 deletions xbmc/interfaces/json-rpc/ServiceDescription.h
Expand Up @@ -2328,6 +2328,17 @@ namespace JSONRPC
"\"params\": [],"
"\"returns\": \"string\""
"}",
"\"Input.SendText\": {"
"\"type\": \"method\","
"\"description\": \"Send a generic (unicode) text\","
"\"transport\": \"Response\","
"\"permission\": \"Navigate\","
"\"params\": ["
"{ \"name\": \"text\", \"type\": \"string\", \"minLength\": 1, \"required\": true, \"description\": \"Unicode text\" },"
"{ \"name\": \"done\", \"type\": \"boolean\", \"default\": true, \"description\": \"Whether this is the whole input or not (closes an open input dialog if true).\" }"
"],"
"\"returns\": \"string\""
"}",
"\"Input.Left\": {"
"\"type\": \"method\","
"\"description\": \"Navigate left in GUI\","
Expand Down
11 changes: 11 additions & 0 deletions xbmc/interfaces/json-rpc/methods.json
Expand Up @@ -1463,6 +1463,17 @@
"params": [],
"returns": "string"
},
"Input.SendText": {
"type": "method",
"description": "Send a generic (unicode) text",
"transport": "Response",
"permission": "Navigate",
"params": [
{ "name": "text", "type": "string", "minLength": 1, "required": true, "description": "Unicode text" },
{ "name": "done", "type": "boolean", "default": true, "description": "Whether this is the whole input or not (closes an open input dialog if true)." }
],
"returns": "string"
},
"Input.Left": {
"type": "method",
"description": "Navigate left in GUI",
Expand Down

0 comments on commit 15de540

Please sign in to comment.