#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"
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;
void ActivateWindow(int windowID, const std::vector<CStdString> ¶ms, 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.
if (m_idleTimer.IsRunning())
m_idleTimer.Restart();
}
+
+ virtual bool SetTextToKeyboard(const std::string &text, bool closeKeyboard = false) { return false; }
private:
CTimer m_idleTimer;
#include "osx/ios/IOSKeyboard.h"
#endif
+CGUIKeyboard *CGUIKeyboardFactory::g_activedKeyboard = NULL;
FILTERING CGUIKeyboardFactory::m_filtering = FILTERING_NONE;
CGUIKeyboardFactory::CGUIKeyboardFactory(void)
}
}
+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
if(kb)
{
+ g_activedKeyboard = kb;
kb->startAutoCloseTimer(autoCloseMs);
confirmed = kb->ShowAndGetInput(keyTypedCB, aTextString, aTextString, headingStr, hiddenInput);
+ g_activedKeyboard = NULL;
if(needsFreeing)
delete kb;
}
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);
};
JSONRPC_STATUS CInputOperations::SendText(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, 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;
}
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;
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)
{
- (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;
}
}
+- (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) {