Skip to content

Commit

Permalink
Merge pull request #1056 from Montellese/jsonrpc_sendkey
Browse files Browse the repository at this point in the history
JSON-RPC SendKey, ExecuteAction, ShowCodec and ShowOSD in Input namespace
  • Loading branch information
Montellese committed Jul 11, 2012
2 parents 3d7ed17 + 4c5310b commit c924204
Show file tree
Hide file tree
Showing 16 changed files with 349 additions and 20 deletions.
10 changes: 10 additions & 0 deletions xbmc/Application.cpp
Original file line number Diff line number Diff line change
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
16 changes: 16 additions & 0 deletions xbmc/dialogs/GUIDialogKeyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "Application.h"
#include "settings/AdvancedSettings.h"
#include "guilib/LocalizeStrings.h"
#include "interfaces/AnnouncementManager.h"

// Symbol mapping (based on MS virtual keyboard - may need improving)
static char symbol_map[37] = ")!@#$%^&*([]{}-_=+;:\'\",.<>/?\\|`~ ";
Expand Down Expand Up @@ -98,6 +99,11 @@ void CGUIDialogKeyboard::OnInitWindow()
{
SET_CONTROL_HIDDEN(CTL_LABEL_HEADING);
}

CVariant data;
data["title"] = m_strHeading;
data["type"] = "keyboard";
ANNOUNCEMENT::CAnnouncementManager::Announce(ANNOUNCEMENT::Input, "xbmc", "OnInputRequested", data);
}

bool CGUIDialogKeyboard::OnAction(const CAction &action)
Expand Down Expand Up @@ -255,6 +261,14 @@ bool CGUIDialogKeyboard::OnMessage(CGUIMessage& message)
}
}
break;

case GUI_MSG_SET_TEXT:
SetText(message.GetLabel());

// close the dialog if requested
if (message.GetParam1() > 0)
OnOK();
break;
}

return true;
Expand Down Expand Up @@ -664,6 +678,8 @@ void CGUIDialogKeyboard::OnDeinitWindow(int nextWindowID)
CGUIDialog::OnDeinitWindow(nextWindowID);
// reset the heading (we don't always have this)
m_strHeading = "";

ANNOUNCEMENT::CAnnouncementManager::Announce(ANNOUNCEMENT::Input, "xbmc", "OnInputFinished");
}

void CGUIDialogKeyboard::MoveCursor(int iAmount)
Expand Down
101 changes: 98 additions & 3 deletions xbmc/dialogs/GUIDialogNumeric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "input/XBMC_vkeys.h"
#include "utils/StringUtils.h"
#include "guilib/LocalizeStrings.h"
#include "interfaces/AnnouncementManager.h"

#define CONTROL_HEADING_LABEL 1
#define CONTROL_INPUT_LABEL 4
Expand Down Expand Up @@ -54,6 +55,51 @@ CGUIDialogNumeric::~CGUIDialogNumeric(void)
{
}

void CGUIDialogNumeric::OnInitWindow()
{
CGUIDialog::OnInitWindow();

CVariant data;
switch (m_mode)
{
case INPUT_TIME:
data["type"] = "time";
break;
case INPUT_DATE:
data["type"] = "date";
break;
case INPUT_IP_ADDRESS:
data["type"] = "ip";
break;
case INPUT_PASSWORD:
data["type"] = "password";
break;
case INPUT_NUMBER:
data["type"] = "number";
break;
case INPUT_TIME_SECONDS:
data["type"] = "seconds";
break;
default:
data["type"] = "keyboard";
break;
}

const CGUILabelControl *control = (const CGUILabelControl *)GetControl(CONTROL_HEADING_LABEL);
if (control != NULL)
data["title"] = control->GetDescription();

ANNOUNCEMENT::CAnnouncementManager::Announce(ANNOUNCEMENT::Input, "xbmc", "OnInputRequested", data);
}

void CGUIDialogNumeric::OnDeinitWindow(int nextWindowID)
{
// call base class
CGUIDialog::OnDeinitWindow(nextWindowID);

ANNOUNCEMENT::CAnnouncementManager::Announce(ANNOUNCEMENT::Input, "xbmc", "OnInputFinished");
}

bool CGUIDialogNumeric::OnAction(const CAction &action)
{
if (action.GetID() == ACTION_NEXT_ITEM)
Expand Down Expand Up @@ -139,6 +185,14 @@ bool CGUIDialogNumeric::OnMessage(CGUIMessage& message)
}
}
break;

case GUI_MSG_SET_TEXT:
SetMode(m_mode, message.GetLabel());

// close the dialog if requested
if (message.GetParam1() > 0)
OnOK();
break;
}
return CGUIDialog::OnMessage(message);
}
Expand Down Expand Up @@ -462,7 +516,7 @@ void CGUIDialogNumeric::SetMode(INPUT_MODE mode, void *initial)
m_datetime = *(SYSTEMTIME *)initial;
m_lastblock = (m_mode == INPUT_DATE) ? 2 : 1;
}
if (m_mode == INPUT_IP_ADDRESS)
else if (m_mode == INPUT_IP_ADDRESS)
{
m_lastblock = 3;
m_ip[0] = m_ip[1] = m_ip[2] = m_ip[3] = 0;
Expand All @@ -484,10 +538,51 @@ void CGUIDialogNumeric::SetMode(INPUT_MODE mode, void *initial)
}
}
}
if (m_mode == INPUT_NUMBER || m_mode == INPUT_PASSWORD)
{
else if (m_mode == INPUT_NUMBER || m_mode == INPUT_PASSWORD)
m_number = *(CStdString *)initial;
}

void CGUIDialogNumeric::SetMode(INPUT_MODE mode, const CStdString &initial)
{
m_mode = mode;
m_block = 0;
m_lastblock = 0;
if (m_mode == INPUT_TIME || m_mode == INPUT_TIME_SECONDS || m_mode == INPUT_DATE)
{
CDateTime dateTime;
if (m_mode == INPUT_TIME || m_mode == INPUT_TIME_SECONDS)
{
// check if we have a pure number
if (initial.find_first_not_of("0123456789") == std::string::npos)
{
long seconds = strtol(initial.c_str(), NULL, 10);
dateTime = seconds;
}
else
{
CStdString tmp = initial;
// if we are handling seconds and if the string only contains
// "mm:ss" we need to add dummy "hh:" to get "hh:mm:ss"
if (m_mode == INPUT_TIME_SECONDS && tmp.size() <= 5)
tmp = "00:" + tmp;
dateTime.SetFromDBTime(tmp);
}
}
else if (m_mode == INPUT_DATE)
{
CStdString tmp = initial;
tmp.Replace("/", ".");
dateTime.SetFromDBDate(tmp);
}

if (!dateTime.IsValid())
return;

dateTime.GetAsSystemTime(m_datetime);
m_lastblock = (m_mode == INPUT_DATE) ? 2 : 1;
}
else
SetMode(mode, (void*)&initial);
}

void CGUIDialogNumeric::GetOutput(void *output)
Expand Down
4 changes: 4 additions & 0 deletions xbmc/dialogs/GUIDialogNumeric.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class CGUIDialogNumeric :

void SetHeading(const CStdString &strHeading);
void SetMode(INPUT_MODE mode, void *initial);
void SetMode(INPUT_MODE mode, const CStdString &initial);
void GetOutput(void *output);

static bool ShowAndGetTime(SYSTEMTIME &time, const CStdString &heading);
Expand All @@ -53,6 +54,9 @@ class CGUIDialogNumeric :
static bool ShowAndGetSeconds(CStdString& timeString, const CStdString &heading);

protected:
virtual void OnInitWindow();
virtual void OnDeinitWindow(int nextWindowID);

void OnNumber(unsigned int num);
void VerifyDate(bool checkYear);
void OnNext();
Expand Down
5 changes: 5 additions & 0 deletions xbmc/guilib/GUIEditControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ bool CGUIEditControl::OnMessage(CGUIMessage &message)
{
m_smsTimer.Stop();
}
else if (message.GetMessage() == GUI_MSG_SET_TEXT)
{
SetLabel2(message.GetLabel());
UpdateText();
}
return CGUIButtonControl::OnMessage(message);
}

Expand Down
2 changes: 2 additions & 0 deletions xbmc/guilib/GUIMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@
*/
#define GUI_MSG_UNFOCUS_ALL 41

#define GUI_MSG_SET_TEXT 42

#define GUI_MSG_USER 1000

/*!
Expand Down
9 changes: 9 additions & 0 deletions xbmc/input/ButtonTranslator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,15 @@ bool CButtonTranslator::TranslateJoystickString(int window, const char* szDevice
}
#endif

void CButtonTranslator::GetActions(std::vector<std::string> &actionList)
{
unsigned int size = sizeof(actions) / sizeof(ActionMapping);
actionList.clear();
actionList.reserve(size);
for (unsigned int index = 0; index < size; index++)
actionList.push_back(actions[index].name);
}

CAction CButtonTranslator::GetAction(int window, const CKey &key, bool fallback)
{
CStdString strAction;
Expand Down
3 changes: 3 additions & 0 deletions xbmc/input/ButtonTranslator.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#pragma once

#include <map>
#include <vector>
#include "system.h" // for HAS_EVENT_SERVER, HAS_SDL_JOYSTICK, HAS_LIRC

#ifdef HAS_EVENT_SERVER
Expand Down Expand Up @@ -69,6 +70,8 @@ class CButtonTranslator
/// clears the maps
void Clear();

static void GetActions(std::vector<std::string> &actionList);

CAction GetAction(int window, const CKey &key, bool fallback = true);

/*! \brief Translate between a window name and it's id
Expand Down
19 changes: 11 additions & 8 deletions xbmc/interfaces/IAnnouncer.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@ namespace ANNOUNCEMENT
{
enum AnnouncementFlag
{
Player = 0x1,
GUI = 0x2,
System = 0x4,
VideoLibrary = 0x8,
AudioLibrary = 0x10,
Application = 0x20,
Other = 0x40
Player = 0x01,
GUI = 0x02,
System = 0x04,
VideoLibrary = 0x08,
AudioLibrary = 0x10,
Application = 0x20,
Input = 0x40,
Other = 0x80
};

#define ANNOUNCE_ALL (Player | GUI | System | VideoLibrary | AudioLibrary | Application | Other)
#define ANNOUNCE_ALL (Player | GUI | System | VideoLibrary | AudioLibrary | Application | Input | Other)

/*!
\brief Returns a string representation for the
Expand All @@ -58,6 +59,8 @@ namespace ANNOUNCEMENT
return "AudioLibrary";
case Application:
return "Application";
case Input:
return "Input";
case Other:
return "Other";
default:
Expand Down
Loading

0 comments on commit c924204

Please sign in to comment.