Try to support xbmc remote works with ios native keyboard as control target
authorulion <ulion2002@gmail.com>
Mon, 3 Feb 2014 14:30:10 +0000 (22:30 +0800)
committerulion <ulion2002@gmail.com>
Wed, 5 Feb 2014 23:34:06 +0000 (07:34 +0800)
xbmc/ApplicationMessenger.cpp
xbmc/ApplicationMessenger.h
xbmc/guilib/GUIKeyboard.h
xbmc/guilib/GUIKeyboardFactory.cpp
xbmc/guilib/GUIKeyboardFactory.h
xbmc/interfaces/json-rpc/InputOperations.cpp
xbmc/osx/ios/IOSKeyboard.h
xbmc/osx/ios/IOSKeyboard.mm
xbmc/osx/ios/IOSKeyboardView.h
xbmc/osx/ios/IOSKeyboardView.mm

index 34dbc18..3524e89 100644 (file)
@@ -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"
@@ -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;
index 6457087..e62c772 100644 (file)
@@ -235,6 +235,9 @@ public:
   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.
index ac4b238..f65d361 100644 (file)
@@ -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;
index 822f079..1f6d158 100644 (file)
@@ -34,6 +34,7 @@
 #include "osx/ios/IOSKeyboard.h"
 #endif
 
+CGUIKeyboard *CGUIKeyboardFactory::g_activedKeyboard = NULL;
 FILTERING CGUIKeyboardFactory::m_filtering = FILTERING_NONE;
 
 CGUIKeyboardFactory::CGUIKeyboardFactory(void)
@@ -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
@@ -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;
   }
index 274f8c7..0b143cd 100644 (file)
@@ -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);
 };
index 196d4a3..69a6b0d 100644 (file)
@@ -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;
 }
 
index cd21b9a..c870a75 100644 (file)
@@ -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;
index c98ebcc..74c4c7a 100644 (file)
@@ -80,6 +80,14 @@ void CIOSKeyboard::Cancel()
   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)
 {
index 8392d2a..834276a 100644 (file)
@@ -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;
index 8fb6f55..e56cd0a 100644 (file)
@@ -261,6 +261,24 @@ static CEvent keyboardFinishedEvent;
   }
 }
 
+- (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) {