Skip to content

Commit

Permalink
Merge pull request #4142 from ulion/ios_native_keyboard_with_xbmc_rem…
Browse files Browse the repository at this point in the history
…ote_app

[IOS] Try to support xbmc remote works with ios native keyboard as control target, fix #14911
  • Loading branch information
jmarshallnz committed Feb 7, 2014
2 parents ad81556 + f429754 commit cf5266d
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 8 deletions.
16 changes: 16 additions & 0 deletions xbmc/ApplicationMessenger.cpp
Expand Up @@ -38,6 +38,7 @@
#include "FileItem.h"
#include "guilib/GUIDialog.h"
#include "guilib/Key.h"
#include "guilib/GUIKeyboardFactory.h"
#include "GUIInfoManager.h"
#include "utils/Splash.h"
#include "cores/IPlayer.h"
Expand Down Expand Up @@ -1261,6 +1262,21 @@ void CApplicationMessenger::SendGUIMessage(const CGUIMessage &message, int windo
SendMessage(tMsg, waitResult);
}

void CApplicationMessenger::SendText(const std::string &aTextString, bool closeKeyboard /* = false */)
{
if (CGUIKeyboardFactory::SendTextToActiveKeyboard(aTextString, closeKeyboard))
return;

CGUIWindow *window = g_windowManager.GetWindow(g_windowManager.GetFocusedWindow());
if (!window)
return;

CGUIMessage msg(GUI_MSG_SET_TEXT, 0, 0);
msg.SetLabel(aTextString);
msg.SetParam1(closeKeyboard ? 1 : 0);
SendGUIMessage(msg, window->GetID());
}

vector<CStdString> CApplicationMessenger::GetInfoLabels(const vector<CStdString> &properties)
{
vector<CStdString> infoLabels;
Expand Down
3 changes: 3 additions & 0 deletions xbmc/ApplicationMessenger.h
Expand Up @@ -235,6 +235,9 @@ class CApplicationMessenger
void ActivateWindow(int windowID, const std::vector<CStdString> &params, bool swappingWindows);
void SendAction(const CAction &action, int windowID = WINDOW_INVALID, bool waitResult=true);

//! \brief Send text to currently focused window / keyboard.
void SendText(const std::string &aTextString, bool closeKeyboard = false);

/*! \brief Send a GUIMessage, optionally waiting before it's processed to return.
Should be used to send messages to the GUI from other threads.
\param msg the GUIMessage to send.
Expand Down
2 changes: 2 additions & 0 deletions xbmc/guilib/GUIKeyboard.h
Expand Up @@ -83,6 +83,8 @@ class CGUIKeyboard : public ITimerCallback
if (m_idleTimer.IsRunning())
m_idleTimer.Restart();
}

virtual bool SetTextToKeyboard(const std::string &text, bool closeKeyboard = false) { return false; }

private:
CTimer m_idleTimer;
Expand Down
11 changes: 11 additions & 0 deletions xbmc/guilib/GUIKeyboardFactory.cpp
Expand Up @@ -34,6 +34,7 @@
#include "osx/ios/IOSKeyboard.h"
#endif

CGUIKeyboard *CGUIKeyboardFactory::g_activedKeyboard = NULL;
FILTERING CGUIKeyboardFactory::m_filtering = FILTERING_NONE;

CGUIKeyboardFactory::CGUIKeyboardFactory(void)
Expand Down Expand Up @@ -68,6 +69,14 @@ void CGUIKeyboardFactory::keyTypedCB(CGUIKeyboard *ref, const std::string &typed
}
}

bool CGUIKeyboardFactory::SendTextToActiveKeyboard(const std::string &aTextString, bool closeKeyboard /* = false */)
{
if (!g_activedKeyboard)
return false;
return g_activedKeyboard->SetTextToKeyboard(aTextString, closeKeyboard);
}


// Show keyboard with initial value (aTextString) and replace with result string.
// Returns: true - successful display and input (empty result may return true or false depending on parameter)
// false - unsuccessful display of the keyboard or cancelled editing
Expand Down Expand Up @@ -95,8 +104,10 @@ bool CGUIKeyboardFactory::ShowAndGetInput(CStdString& aTextString, const CVarian

if(kb)
{
g_activedKeyboard = kb;
kb->startAutoCloseTimer(autoCloseMs);
confirmed = kb->ShowAndGetInput(keyTypedCB, aTextString, aTextString, headingStr, hiddenInput);
g_activedKeyboard = NULL;
if(needsFreeing)
delete kb;
}
Expand Down
4 changes: 4 additions & 0 deletions xbmc/guilib/GUIKeyboardFactory.h
Expand Up @@ -40,7 +40,11 @@ class CGUIKeyboardFactory
static int ShowAndVerifyPassword(CStdString& strPassword, const CStdString& strHeading, int iRetries, unsigned int autoCloseMs = 0);
static bool ShowAndGetFilter(CStdString& aTextString, bool searching, unsigned int autoCloseMs = 0);

static bool SendTextToActiveKeyboard(const std::string &aTextString, bool closeKeyboard = false);

static bool isKeyboardActivated() { return g_activedKeyboard != NULL; }
private:
static CGUIKeyboard *g_activedKeyboard;
static FILTERING m_filtering;
static void keyTypedCB(CGUIKeyboard *ref, const std::string &typedString);
};
9 changes: 1 addition & 8 deletions xbmc/interfaces/json-rpc/InputOperations.cpp
Expand Up @@ -64,14 +64,7 @@ JSONRPC_STATUS CInputOperations::activateWindow(int windowID)

JSONRPC_STATUS CInputOperations::SendText(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
{
CGUIWindow *window = g_windowManager.GetWindow(g_windowManager.GetFocusedWindow());
if (!window)
return InternalError;

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

Expand Down
1 change: 1 addition & 0 deletions xbmc/osx/ios/IOSKeyboard.h
Expand Up @@ -29,6 +29,7 @@ class CIOSKeyboard : public CGUIKeyboard
virtual void Cancel();
void fireCallback(const std::string &str);
void invalidateCallback(){m_pCharCallback = NULL;}
virtual bool SetTextToKeyboard(const std::string &text, bool closeKeyboard = false);

private:
char_callback_t m_pCharCallback;
Expand Down
8 changes: 8 additions & 0 deletions xbmc/osx/ios/IOSKeyboard.mm
Expand Up @@ -80,6 +80,14 @@
m_bCanceled = true;
}

bool CIOSKeyboard::SetTextToKeyboard(const std::string &text, bool closeKeyboard /* = false */)
{
if (!g_pIosKeyboard)
return false;
[g_pIosKeyboard setKeyboardText:[NSString stringWithUTF8String:text.c_str()] closeKeyboard:closeKeyboard?YES:NO];
return true;
}

//wrap our callback between objc and c++
void CIOSKeyboard::fireCallback(const std::string &str)
{
Expand Down
1 change: 1 addition & 0 deletions xbmc/osx/ios/IOSKeyboardView.h
Expand Up @@ -43,6 +43,7 @@
- (void) setHidden:(BOOL)hidden;
- (void) activate;
- (void) deactivate;
- (void) setKeyboardText:(NSString*)aText closeKeyboard:(BOOL)closeKeyboard;
- (void) textChanged:(NSNotification*)aNotification;
- (void) setCancelFlag:(bool *)cancelFlag;
- (void) doDeactivate:(NSDictionary *)dict;
Expand Down
18 changes: 18 additions & 0 deletions xbmc/osx/ios/IOSKeyboardView.mm
Expand Up @@ -261,6 +261,24 @@ - (void) deactivate
}
}

- (void) setKeyboardText:(NSString*)aText closeKeyboard:(BOOL)closeKeyboard
{
LOG(@"%s: %@, %d", __PRETTY_FUNCTION__, aText, closeKeyboard);
if([NSThread currentThread] != [NSThread mainThread])
{
[self performSelectorOnMainThread:@selector(setDefault:) withObject:aText waitUntilDone:YES];
}
else
{
[self setDefault:aText];
}
if (closeKeyboard)
{
_confirmed = YES;
[self deactivate];
}
}

- (void) setHeading:(NSString *)heading
{
if (heading && heading.length > 0) {
Expand Down

0 comments on commit cf5266d

Please sign in to comment.