diff --git a/xbmc/Application.cpp b/xbmc/Application.cpp index 035e0de6e3e86..90a1bfd6dd4e1 100644 --- a/xbmc/Application.cpp +++ b/xbmc/Application.cpp @@ -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); diff --git a/xbmc/interfaces/json-rpc/InputOperations.cpp b/xbmc/interfaces/json-rpc/InputOperations.cpp index 541c67991a57e..be918643b4958 100644 --- a/xbmc/interfaces/json-rpc/InputOperations.cpp +++ b/xbmc/interfaces/json-rpc/InputOperations.cpp @@ -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 ¶meterObject, 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 ¶meterObject, CVariant &result) { return SendKey(XBMCVK_LEFT); diff --git a/xbmc/interfaces/json-rpc/InputOperations.h b/xbmc/interfaces/json-rpc/InputOperations.h index 2d82ed47f22da..69d19b9affc9f 100644 --- a/xbmc/interfaces/json-rpc/InputOperations.h +++ b/xbmc/interfaces/json-rpc/InputOperations.h @@ -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 ¶meterObject, CVariant &result); static JSONRPC_STATUS Left(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result); static JSONRPC_STATUS Right(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result); @@ -42,7 +45,7 @@ namespace JSONRPC static JSONRPC_STATUS Info(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result); static JSONRPC_STATUS Home(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, 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: @@ -50,6 +53,6 @@ namespace JSONRPC static bool handleScreenSaver(); static CCriticalSection m_critSection; - static uint32_t m_key; + static CKey m_key; }; } diff --git a/xbmc/interfaces/json-rpc/JSONServiceDescription.cpp b/xbmc/interfaces/json-rpc/JSONServiceDescription.cpp index faf133c7e3f6d..afda077dd76ac 100644 --- a/xbmc/interfaces/json-rpc/JSONServiceDescription.cpp +++ b/xbmc/interfaces/json-rpc/JSONServiceDescription.cpp @@ -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 }, diff --git a/xbmc/interfaces/json-rpc/ServiceDescription.h b/xbmc/interfaces/json-rpc/ServiceDescription.h index e9df4a90e7bcd..0f612d15e44c1 100644 --- a/xbmc/interfaces/json-rpc/ServiceDescription.h +++ b/xbmc/interfaces/json-rpc/ServiceDescription.h @@ -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\"," diff --git a/xbmc/interfaces/json-rpc/methods.json b/xbmc/interfaces/json-rpc/methods.json index 1340d84a7374b..ef5df2d18df44 100644 --- a/xbmc/interfaces/json-rpc/methods.json +++ b/xbmc/interfaces/json-rpc/methods.json @@ -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",