Permalink
Browse files

jsonrpc: add Input.SendText

  • Loading branch information...
1 parent 99e0bcf commit 15de54024b43a1340ac5605cda11e60d435b1677 @Montellese committed May 23, 2012
View
@@ -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);
@@ -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;
}
@@ -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;
}
@@ -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);
@@ -21,6 +21,7 @@
*/
#include "JSONRPC.h"
+#include "guilib/Key.h"
#include "threads/CriticalSection.h"
#include "utils/StdString.h"
@@ -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);
@@ -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;
};
}
@@ -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 },
@@ -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\","
@@ -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",

0 comments on commit 15de540

Please sign in to comment.