Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #2148 from Memphiz/keyboardfactoryautoclose

Add the missing autoclose feature to the keyboardfactory...
  • Loading branch information...
commit fbc641ff778b18b06d110740456483c1aed95424 2 parents 7484699 + 3e6df33
Memphiz Memphiz authored
6 xbmc/dialogs/GUIDialogKeyboardGeneric.cpp
View
@@ -641,6 +641,12 @@ int CGUIDialogKeyboardGeneric::GetWindowId() const
return GetID();
}
+void CGUIDialogKeyboardGeneric::Cancel()
+{
+ m_bIsConfirmed = false;
+ Close();
+}
+
bool CGUIDialogKeyboardGeneric::ShowAndGetInput(char_callback_t pCallback, const std::string &initialString, std::string &typedString, const std::string &heading, bool bHiddenInput)
{
CGUIDialogKeyboardGeneric *pKeyboard = (CGUIDialogKeyboardGeneric*)g_windowManager.GetWindow(WINDOW_DIALOG_KEYBOARD);
1  xbmc/dialogs/GUIDialogKeyboardGeneric.h
View
@@ -33,6 +33,7 @@ class CGUIDialogKeyboardGeneric : public CGUIDialog, public CGUIKeyboard
//CGUIKeyboard Interface
virtual bool ShowAndGetInput(char_callback_t pCallback, const std::string &initialString, std::string &typedString, const std::string &heading, bool bHiddenInput);
+ virtual void Cancel();
virtual int GetWindowId() const;
//CGUIDialog Interface
55 xbmc/guilib/GUIKeyboard.h
View
@@ -21,19 +21,64 @@
#pragma once
#include <string>
+#include "threads/Timer.h"
class CGUIKeyboard;
enum FILTERING { FILTERING_NONE = 0, FILTERING_CURRENT, FILTERING_SEARCH };
typedef void (*char_callback_t) (CGUIKeyboard *ref, const std::string &typedString);
-class CGUIKeyboard
+class CGUIKeyboard : public ITimerCallback
{
public:
+ CGUIKeyboard():m_idleTimer(this){};
+ virtual ~CGUIKeyboard(){ };
- CGUIKeyboard(){};
- virtual ~CGUIKeyboard(){};
+ // entrypoint
+ /*!
+ * \brief each native keyboard needs to implement this function with the following behaviour:
+ *
+ * \param pCallback implementation should call this on each keypress with the current whole string
+ * \param initialString implementation should show that initialstring
+ * \param typedstring returns the typed string after close if return is true
+ * \param heading implementation should show a heading (e.x. "search for a movie")
+ * \param bHiddenInput if true the implementation should obfuscate the user input (e.x. by printing "*" for each char)
+ *
+ * \return - true if typedstring is valid and user has confirmed input - false if typedstring is undefined and user canceled the input
+ *
+ */
+ virtual bool ShowAndGetInput(char_callback_t pCallback,
+ const std::string &initialString,
+ std::string &typedString,
+ const std::string &heading,
+ bool bHiddenInput = false) = 0;
+
+ /*!
+ *\brief This call should cancel a currently shown keyboard dialog. The implementation should
+ * return false from the modal ShowAndGetInput once anyone calls this metohod.
+ */
+ virtual void Cancel() = 0;
- //entrypoint
- virtual bool ShowAndGetInput(char_callback_t pCallback, const std::string &initialString, std::string &typedString, const std::string &heading, bool bHiddenInput = false) = 0;
virtual int GetWindowId() const {return 0;}
+
+ // CTimer Interface for autoclose
+ virtual void OnTimeout()
+ {
+ Cancel();
+ }
+
+ // helpers for autoclose function
+ void startAutoCloseTimer(unsigned int autoCloseMs)
+ {
+ if ( autoCloseMs > 0 )
+ m_idleTimer.Start(autoCloseMs, false);
+ }
+
+ void resetAutoCloseTimer()
+ {
+ if (m_idleTimer.IsRunning())
+ m_idleTimer.Restart();
+ }
+
+ private:
+ CTimer m_idleTimer;
};
34 xbmc/guilib/GUIKeyboardFactory.cpp
View
@@ -67,12 +67,13 @@ void CGUIKeyboardFactory::keyTypedCB(CGUIKeyboard *ref, const std::string &typed
break;
}
}
+ ref->resetAutoCloseTimer();
}
// 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 - unsucessful display of the keyboard or cancelled editing
-bool CGUIKeyboardFactory::ShowAndGetInput(CStdString& aTextString, const CVariant &heading, bool allowEmptyResult, bool hiddenInput /* = false */)
+bool CGUIKeyboardFactory::ShowAndGetInput(CStdString& aTextString, const CVariant &heading, bool allowEmptyResult, bool hiddenInput /* = false */, unsigned int autoCloseMs /* = 0 */)
{
bool confirmed = false;
CGUIKeyboard *kb = NULL;
@@ -96,6 +97,7 @@ bool CGUIKeyboardFactory::ShowAndGetInput(CStdString& aTextString, const CVarian
if(kb)
{
+ kb->startAutoCloseTimer(autoCloseMs);
confirmed = kb->ShowAndGetInput(keyTypedCB, aTextString, aTextString, headingStr, hiddenInput);
if(needsFreeing)
delete kb;
@@ -110,29 +112,29 @@ bool CGUIKeyboardFactory::ShowAndGetInput(CStdString& aTextString, const CVarian
return confirmed;
}
-bool CGUIKeyboardFactory::ShowAndGetInput(CStdString& aTextString, bool allowEmptyResult)
+bool CGUIKeyboardFactory::ShowAndGetInput(CStdString& aTextString, bool allowEmptyResult, unsigned int autoCloseMs /* = 0 */)
{
- return ShowAndGetInput(aTextString, "", allowEmptyResult) != 0;
+ return ShowAndGetInput(aTextString, "", allowEmptyResult, autoCloseMs) != 0;
}
// Shows keyboard and prompts for a password.
// Differs from ShowAndVerifyNewPassword() in that no second verification is necessary.
-bool CGUIKeyboardFactory::ShowAndGetNewPassword(CStdString& newPassword, const CVariant &heading, bool allowEmpty)
+bool CGUIKeyboardFactory::ShowAndGetNewPassword(CStdString& newPassword, const CVariant &heading, bool allowEmpty, unsigned int autoCloseMs /* = 0 */)
{
- return ShowAndGetInput(newPassword, heading, allowEmpty, true);
+ return ShowAndGetInput(newPassword, heading, allowEmpty, true, autoCloseMs);
}
// Shows keyboard and prompts for a password.
// Differs from ShowAndVerifyNewPassword() in that no second verification is necessary.
-bool CGUIKeyboardFactory::ShowAndGetNewPassword(CStdString& newPassword)
+bool CGUIKeyboardFactory::ShowAndGetNewPassword(CStdString& newPassword, unsigned int autoCloseMs /* = 0 */)
{
- return ShowAndGetNewPassword(newPassword, 12340, false);
+ return ShowAndGetNewPassword(newPassword, 12340, false, autoCloseMs);
}
-bool CGUIKeyboardFactory::ShowAndGetFilter(CStdString &filter, bool searching)
+bool CGUIKeyboardFactory::ShowAndGetFilter(CStdString &filter, bool searching, unsigned int autoCloseMs /* = 0 */)
{
m_filtering = searching ? FILTERING_SEARCH : FILTERING_CURRENT;
- bool ret = ShowAndGetInput(filter, searching ? 16017 : 16028, true);
+ bool ret = ShowAndGetInput(filter, searching ? 16017 : 16028, true, autoCloseMs);
m_filtering = FILTERING_NONE;
return ret;
}
@@ -143,17 +145,17 @@ bool CGUIKeyboardFactory::ShowAndGetFilter(CStdString &filter, bool searching)
// \param heading Heading to display
// \param allowEmpty Whether a blank password is valid or not.
// \return true if successful display and user input entry/re-entry. false if unsucessful display, no user input, or canceled editing.
-bool CGUIKeyboardFactory::ShowAndVerifyNewPassword(CStdString& newPassword, const CVariant &heading, bool allowEmpty)
+bool CGUIKeyboardFactory::ShowAndVerifyNewPassword(CStdString& newPassword, const CVariant &heading, bool allowEmpty, unsigned int autoCloseMs /* = 0 */)
{
// Prompt user for password input
CStdString userInput = "";
- if (!ShowAndGetInput(userInput, heading, allowEmpty, true))
+ if (!ShowAndGetInput(userInput, heading, allowEmpty, true, autoCloseMs))
{ // user cancelled, or invalid input
return false;
}
// success - verify the password
CStdString checkInput = "";
- if (!ShowAndGetInput(checkInput, 12341, allowEmpty, true))
+ if (!ShowAndGetInput(checkInput, 12341, allowEmpty, true, autoCloseMs))
{ // user cancelled, or invalid input
return false;
}
@@ -173,10 +175,10 @@ bool CGUIKeyboardFactory::ShowAndVerifyNewPassword(CStdString& newPassword, cons
// \brief Show keyboard twice to get and confirm a user-entered password string.
// \param strNewPassword Overwritten with user input if return=true.
// \return true if successful display and user input entry/re-entry. false if unsucessful display, no user input, or canceled editing.
-bool CGUIKeyboardFactory::ShowAndVerifyNewPassword(CStdString& newPassword)
+bool CGUIKeyboardFactory::ShowAndVerifyNewPassword(CStdString& newPassword, unsigned int autoCloseMs /* = 0 */)
{
CStdString heading = g_localizeStrings.Get(12340);
- return ShowAndVerifyNewPassword(newPassword, heading, false);
+ return ShowAndVerifyNewPassword(newPassword, heading, false, autoCloseMs);
}
// \brief Show keyboard and verify user input against strPassword.
@@ -184,7 +186,7 @@ bool CGUIKeyboardFactory::ShowAndVerifyNewPassword(CStdString& newPassword)
// \param dlgHeading String shown on dialog title. Converts to localized string if contains a positive integer.
// \param iRetries If greater than 0, shows "Incorrect password, %d retries left" on dialog line 2, else line 2 is blank.
// \return 0 if successful display and user input. 1 if unsucessful input. -1 if no user input or canceled editing.
-int CGUIKeyboardFactory::ShowAndVerifyPassword(CStdString& strPassword, const CStdString& strHeading, int iRetries)
+int CGUIKeyboardFactory::ShowAndVerifyPassword(CStdString& strPassword, const CStdString& strHeading, int iRetries, unsigned int autoCloseMs /* = 0 */)
{
CStdString strHeadingTemp;
if (1 > iRetries && strHeading.size())
@@ -193,7 +195,7 @@ int CGUIKeyboardFactory::ShowAndVerifyPassword(CStdString& strPassword, const CS
strHeadingTemp.Format("%s - %i %s", g_localizeStrings.Get(12326).c_str(), g_guiSettings.GetInt("masterlock.maxretries") - iRetries, g_localizeStrings.Get(12343).c_str());
CStdString strUserInput = "";
- if (!ShowAndGetInput(strUserInput, strHeadingTemp, false, true)) //bool hiddenInput = false/true ? TODO: GUI Setting to enable disable this feature y/n?
+ if (!ShowAndGetInput(strUserInput, strHeadingTemp, false, true, autoCloseMs)) //bool hiddenInput = false/true ? TODO: GUI Setting to enable disable this feature y/n?
return -1; // user canceled out
if (!strPassword.IsEmpty())
16 xbmc/guilib/GUIKeyboardFactory.h
View
@@ -31,14 +31,14 @@ class CGUIKeyboardFactory
CGUIKeyboardFactory(void);
virtual ~CGUIKeyboardFactory(void);
- static bool ShowAndGetInput(CStdString& aTextString, bool allowEmptyResult);
- static bool ShowAndGetInput(CStdString& aTextString, const CVariant &heading, bool allowEmptyResult, bool hiddenInput = false);
- static bool ShowAndGetNewPassword(CStdString& strNewPassword);
- static bool ShowAndGetNewPassword(CStdString& newPassword, const CVariant &heading, bool allowEmpty);
- static bool ShowAndVerifyNewPassword(CStdString& strNewPassword);
- static bool ShowAndVerifyNewPassword(CStdString& newPassword, const CVariant &heading, bool allowEmpty);
- static int ShowAndVerifyPassword(CStdString& strPassword, const CStdString& strHeading, int iRetries);
- static bool ShowAndGetFilter(CStdString& aTextString, bool searching);
+ static bool ShowAndGetInput(CStdString& aTextString, bool allowEmptyResult, unsigned int autoCloseMs = 0);
+ static bool ShowAndGetInput(CStdString& aTextString, const CVariant &heading, bool allowEmptyResult, bool hiddenInput = false, unsigned int autoCloseMs = 0);
+ static bool ShowAndGetNewPassword(CStdString& strNewPassword, unsigned int autoCloseMs = 0);
+ static bool ShowAndGetNewPassword(CStdString& newPassword, const CVariant &heading, bool allowEmpty, unsigned int autoCloseMs = 0);
+ static bool ShowAndVerifyNewPassword(CStdString& strNewPassword, unsigned int autoCloseMs = 0);
+ static bool ShowAndVerifyNewPassword(CStdString& newPassword, const CVariant &heading, bool allowEmpty, unsigned int autoCloseMs = 0);
+ 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);
private:
static FILTERING m_filtering;
3  xbmc/osx/ios/IOSKeyboard.h
View
@@ -24,10 +24,13 @@
class CIOSKeyboard : public CGUIKeyboard
{
public:
+ CIOSKeyboard():m_pCharCallback(NULL),m_pIosKeyboard(NULL){}
virtual bool ShowAndGetInput(char_callback_t pCallback, const std::string &initialString, std::string &typedString, const std::string &heading, bool bHiddenInput);
+ virtual void Cancel();
void fireCallback(const std::string &str);
void invalidateCallback(){m_pCharCallback = NULL;}
private:
char_callback_t m_pCharCallback;
+ void *m_pIosKeyboard;
};
30 xbmc/osx/ios/IOSKeyboard.mm
View
@@ -37,23 +37,33 @@
keyboardFrame.origin.x = frameHeight / 2;
keyboardFrame.origin.y = (pCurrentScreen.bounds.size.width/2) - frameHeight*scale + 10;
//create the keyboardview
- KeyboardView *iosKeyboard = [[KeyboardView alloc] initWithFrame:keyboardFrame];
-
+ m_pIosKeyboard = [[KeyboardView alloc] initWithFrame:keyboardFrame];
+ KeyboardView *keyboard = (KeyboardView*)m_pIosKeyboard;
m_pCharCallback = pCallback;
// init keyboard stuff
- [iosKeyboard setText:[NSString stringWithUTF8String:initialString.c_str()]];
- [iosKeyboard SetHiddenInput:bHiddenInput];
- [iosKeyboard SetHeading:[NSString stringWithUTF8String:heading.c_str()]];
- [iosKeyboard RegisterKeyboard:this]; // for calling back
- [iosKeyboard activate];//blocks and loops our application loop (like a modal dialog)
+ [keyboard setText:[NSString stringWithUTF8String:initialString.c_str()]];
+ [keyboard SetHiddenInput:bHiddenInput];
+ [keyboard SetHeading:[NSString stringWithUTF8String:heading.c_str()]];
+ [keyboard RegisterKeyboard:this]; // for calling back
+ [keyboard activate];//blocks and loops our application loop (like a modal dialog)
// user is done - get resulted text and confirmation
- typedString = [[iosKeyboard GetText] UTF8String];
- confirmed = [iosKeyboard GetResult];
- [iosKeyboard release]; // bye bye native keyboard
+ typedString = [[keyboard GetText] UTF8String];
+ confirmed = [keyboard GetResult];
+ [keyboard release]; // bye bye native keyboard
+ m_pIosKeyboard = NULL;
return confirmed;
}
+void CIOSKeyboard::Cancel()
+{
+ if (m_pIosKeyboard)
+ {
+ KeyboardView *keyboard = (KeyboardView*)m_pIosKeyboard;
+ [keyboard keyboardDidHide:nil];
+ }
+}
+
//wrap our callback between objc and c++
void CIOSKeyboard::fireCallback(const std::string &str)
{
1  xbmc/osx/ios/IOSKeyboardView.h
View
@@ -39,4 +39,5 @@
- (void) setText:(NSMutableString *)text;
- (void) activate;
- (void) deactivate;
+- (void)keyboardDidHide:(id)sender;
@end
Please sign in to comment.
Something went wrong with that request. Please try again.