Skip to content
This repository
Browse code

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 authored January 31, 2013
6  xbmc/dialogs/GUIDialogKeyboardGeneric.cpp
@@ -641,6 +641,12 @@ int CGUIDialogKeyboardGeneric::GetWindowId() const
641 641
   return GetID();
642 642
 }
643 643
 
  644
+void CGUIDialogKeyboardGeneric::Cancel()
  645
+{
  646
+  m_bIsConfirmed = false;
  647
+  Close();
  648
+}
  649
+
644 650
 bool CGUIDialogKeyboardGeneric::ShowAndGetInput(char_callback_t pCallback, const std::string &initialString, std::string &typedString, const std::string &heading, bool bHiddenInput)
645 651
 {
646 652
   CGUIDialogKeyboardGeneric *pKeyboard = (CGUIDialogKeyboardGeneric*)g_windowManager.GetWindow(WINDOW_DIALOG_KEYBOARD);
1  xbmc/dialogs/GUIDialogKeyboardGeneric.h
@@ -33,6 +33,7 @@ class CGUIDialogKeyboardGeneric : public CGUIDialog, public CGUIKeyboard
33 33
 
34 34
     //CGUIKeyboard Interface
35 35
     virtual bool ShowAndGetInput(char_callback_t pCallback, const std::string &initialString, std::string &typedString, const std::string &heading, bool bHiddenInput);
  36
+    virtual void Cancel();
36 37
     virtual int GetWindowId() const;
37 38
 
38 39
     //CGUIDialog Interface
55  xbmc/guilib/GUIKeyboard.h
@@ -21,19 +21,64 @@
21 21
 #pragma once
22 22
 
23 23
 #include <string>
  24
+#include "threads/Timer.h"
24 25
 
25 26
 class CGUIKeyboard;
26 27
 enum FILTERING { FILTERING_NONE = 0, FILTERING_CURRENT, FILTERING_SEARCH };
27 28
 typedef void (*char_callback_t) (CGUIKeyboard *ref, const std::string &typedString);
28 29
 
29  
-class CGUIKeyboard
  30
+class CGUIKeyboard : public ITimerCallback
30 31
 {
31 32
   public:
  33
+    CGUIKeyboard():m_idleTimer(this){};
  34
+    virtual ~CGUIKeyboard(){ };
32 35
 
33  
-    CGUIKeyboard(){};
34  
-    virtual ~CGUIKeyboard(){};
  36
+    // entrypoint
  37
+    /*!
  38
+     * \brief each native keyboard needs to implement this function with the following behaviour:
  39
+     *
  40
+     * \param pCallback implementation should call this on each keypress with the current whole string
  41
+     * \param initialString implementation should show that initialstring
  42
+     * \param typedstring returns the typed string after close if return is true
  43
+     * \param heading implementation should show a heading (e.x. "search for a movie")
  44
+     * \param bHiddenInput if true the implementation should obfuscate the user input (e.x. by printing "*" for each char)
  45
+     *
  46
+     * \return - true if typedstring is valid and user has confirmed input - false if typedstring is undefined and user canceled the input
  47
+     *
  48
+     */
  49
+    virtual bool ShowAndGetInput(char_callback_t pCallback, 
  50
+                                 const std::string &initialString, 
  51
+                                 std::string &typedString, 
  52
+                                 const std::string &heading, 
  53
+                                 bool bHiddenInput = false) = 0;
  54
+    
  55
+    /*!
  56
+    *\brief This call should cancel a currently shown keyboard dialog. The implementation should 
  57
+    * return false from the modal ShowAndGetInput once anyone calls this metohod.
  58
+    */
  59
+    virtual void Cancel() = 0;
35 60
 
36  
-    //entrypoint
37  
-    virtual bool ShowAndGetInput(char_callback_t pCallback, const std::string &initialString, std::string &typedString, const std::string &heading, bool bHiddenInput = false) = 0;
38 61
     virtual int GetWindowId() const {return 0;}
  62
+
  63
+    // CTimer Interface for autoclose
  64
+    virtual void OnTimeout()
  65
+    {
  66
+      Cancel();
  67
+    }
  68
+
  69
+    // helpers for autoclose function
  70
+    void startAutoCloseTimer(unsigned int autoCloseMs)
  71
+    {
  72
+      if ( autoCloseMs > 0 ) 
  73
+        m_idleTimer.Start(autoCloseMs, false);
  74
+    }
  75
+
  76
+    void resetAutoCloseTimer()
  77
+    {
  78
+      if (m_idleTimer.IsRunning()) 
  79
+        m_idleTimer.Restart();
  80
+    }
  81
+    
  82
+  private:
  83
+    CTimer m_idleTimer;
39 84
 };
34  xbmc/guilib/GUIKeyboardFactory.cpp
@@ -67,12 +67,13 @@ void CGUIKeyboardFactory::keyTypedCB(CGUIKeyboard *ref, const std::string &typed
67 67
         break;
68 68
     }
69 69
   }
  70
+  ref->resetAutoCloseTimer();
70 71
 }
71 72
 
72 73
 // Show keyboard with initial value (aTextString) and replace with result string.
73 74
 // Returns: true  - successful display and input (empty result may return true or false depending on parameter)
74 75
 //          false - unsucessful display of the keyboard or cancelled editing
75  
-bool CGUIKeyboardFactory::ShowAndGetInput(CStdString& aTextString, const CVariant &heading, bool allowEmptyResult, bool hiddenInput /* = false */)
  76
+bool CGUIKeyboardFactory::ShowAndGetInput(CStdString& aTextString, const CVariant &heading, bool allowEmptyResult, bool hiddenInput /* = false */, unsigned int autoCloseMs /* = 0 */)
76 77
 {
77 78
   bool confirmed = false;
78 79
   CGUIKeyboard *kb = NULL;
@@ -96,6 +97,7 @@ bool CGUIKeyboardFactory::ShowAndGetInput(CStdString& aTextString, const CVarian
96 97
 
97 98
   if(kb)
98 99
   {
  100
+    kb->startAutoCloseTimer(autoCloseMs);
99 101
     confirmed = kb->ShowAndGetInput(keyTypedCB, aTextString, aTextString, headingStr, hiddenInput);
100 102
     if(needsFreeing)
101 103
       delete kb;
@@ -110,29 +112,29 @@ bool CGUIKeyboardFactory::ShowAndGetInput(CStdString& aTextString, const CVarian
110 112
   return confirmed;
111 113
 }
112 114
 
113  
-bool CGUIKeyboardFactory::ShowAndGetInput(CStdString& aTextString, bool allowEmptyResult)
  115
+bool CGUIKeyboardFactory::ShowAndGetInput(CStdString& aTextString, bool allowEmptyResult, unsigned int autoCloseMs /* = 0 */)
114 116
 {
115  
-  return ShowAndGetInput(aTextString, "", allowEmptyResult) != 0;
  117
+  return ShowAndGetInput(aTextString, "", allowEmptyResult, autoCloseMs) != 0;
116 118
 }
117 119
 
118 120
 // Shows keyboard and prompts for a password.
119 121
 // Differs from ShowAndVerifyNewPassword() in that no second verification is necessary.
120  
-bool CGUIKeyboardFactory::ShowAndGetNewPassword(CStdString& newPassword, const CVariant &heading, bool allowEmpty)
  122
+bool CGUIKeyboardFactory::ShowAndGetNewPassword(CStdString& newPassword, const CVariant &heading, bool allowEmpty, unsigned int autoCloseMs /* = 0 */)
121 123
 {
122  
-  return ShowAndGetInput(newPassword, heading, allowEmpty, true);
  124
+  return ShowAndGetInput(newPassword, heading, allowEmpty, true, autoCloseMs);
123 125
 }
124 126
 
125 127
 // Shows keyboard and prompts for a password.
126 128
 // Differs from ShowAndVerifyNewPassword() in that no second verification is necessary.
127  
-bool CGUIKeyboardFactory::ShowAndGetNewPassword(CStdString& newPassword)
  129
+bool CGUIKeyboardFactory::ShowAndGetNewPassword(CStdString& newPassword, unsigned int autoCloseMs /* = 0 */)
128 130
 {
129  
-  return ShowAndGetNewPassword(newPassword, 12340, false);
  131
+  return ShowAndGetNewPassword(newPassword, 12340, false, autoCloseMs);
130 132
 }
131 133
 
132  
-bool CGUIKeyboardFactory::ShowAndGetFilter(CStdString &filter, bool searching)
  134
+bool CGUIKeyboardFactory::ShowAndGetFilter(CStdString &filter, bool searching, unsigned int autoCloseMs /* = 0 */)
133 135
 {
134 136
   m_filtering = searching ? FILTERING_SEARCH : FILTERING_CURRENT;
135  
-  bool ret = ShowAndGetInput(filter, searching ? 16017 : 16028, true);
  137
+  bool ret = ShowAndGetInput(filter, searching ? 16017 : 16028, true, autoCloseMs);
136 138
   m_filtering = FILTERING_NONE;
137 139
   return ret;
138 140
 }
@@ -143,17 +145,17 @@ bool CGUIKeyboardFactory::ShowAndGetFilter(CStdString &filter, bool searching)
143 145
 // \param heading Heading to display
144 146
 // \param allowEmpty Whether a blank password is valid or not.
145 147
 // \return true if successful display and user input entry/re-entry. false if unsucessful display, no user input, or canceled editing.
146  
-bool CGUIKeyboardFactory::ShowAndVerifyNewPassword(CStdString& newPassword, const CVariant &heading, bool allowEmpty)
  148
+bool CGUIKeyboardFactory::ShowAndVerifyNewPassword(CStdString& newPassword, const CVariant &heading, bool allowEmpty, unsigned int autoCloseMs /* = 0 */)
147 149
 {
148 150
   // Prompt user for password input
149 151
   CStdString userInput = "";
150  
-  if (!ShowAndGetInput(userInput, heading, allowEmpty, true))
  152
+  if (!ShowAndGetInput(userInput, heading, allowEmpty, true, autoCloseMs))
151 153
   { // user cancelled, or invalid input
152 154
     return false;
153 155
   }
154 156
   // success - verify the password
155 157
   CStdString checkInput = "";
156  
-  if (!ShowAndGetInput(checkInput, 12341, allowEmpty, true))
  158
+  if (!ShowAndGetInput(checkInput, 12341, allowEmpty, true, autoCloseMs))
157 159
   { // user cancelled, or invalid input
158 160
     return false;
159 161
   }
@@ -173,10 +175,10 @@ bool CGUIKeyboardFactory::ShowAndVerifyNewPassword(CStdString& newPassword, cons
173 175
 // \brief Show keyboard twice to get and confirm a user-entered password string.
174 176
 // \param strNewPassword Overwritten with user input if return=true.
175 177
 // \return true if successful display and user input entry/re-entry. false if unsucessful display, no user input, or canceled editing.
176  
-bool CGUIKeyboardFactory::ShowAndVerifyNewPassword(CStdString& newPassword)
  178
+bool CGUIKeyboardFactory::ShowAndVerifyNewPassword(CStdString& newPassword, unsigned int autoCloseMs /* = 0 */)
177 179
 {
178 180
   CStdString heading = g_localizeStrings.Get(12340);
179  
-  return ShowAndVerifyNewPassword(newPassword, heading, false);
  181
+  return ShowAndVerifyNewPassword(newPassword, heading, false, autoCloseMs);
180 182
 }
181 183
 
182 184
 // \brief Show keyboard and verify user input against strPassword.
@@ -184,7 +186,7 @@ bool CGUIKeyboardFactory::ShowAndVerifyNewPassword(CStdString& newPassword)
184 186
 // \param dlgHeading String shown on dialog title. Converts to localized string if contains a positive integer.
185 187
 // \param iRetries If greater than 0, shows "Incorrect password, %d retries left" on dialog line 2, else line 2 is blank.
186 188
 // \return 0 if successful display and user input. 1 if unsucessful input. -1 if no user input or canceled editing.
187  
-int CGUIKeyboardFactory::ShowAndVerifyPassword(CStdString& strPassword, const CStdString& strHeading, int iRetries)
  189
+int CGUIKeyboardFactory::ShowAndVerifyPassword(CStdString& strPassword, const CStdString& strHeading, int iRetries, unsigned int autoCloseMs /* = 0 */)
188 190
 {
189 191
   CStdString strHeadingTemp;
190 192
   if (1 > iRetries && strHeading.size())
@@ -193,7 +195,7 @@ int CGUIKeyboardFactory::ShowAndVerifyPassword(CStdString& strPassword, const CS
193 195
     strHeadingTemp.Format("%s - %i %s", g_localizeStrings.Get(12326).c_str(), g_guiSettings.GetInt("masterlock.maxretries") - iRetries, g_localizeStrings.Get(12343).c_str());
194 196
 
195 197
   CStdString strUserInput = "";
196  
-  if (!ShowAndGetInput(strUserInput, strHeadingTemp, false, true))  //bool hiddenInput = false/true ? TODO: GUI Setting to enable disable this feature y/n?
  198
+  if (!ShowAndGetInput(strUserInput, strHeadingTemp, false, true, autoCloseMs))  //bool hiddenInput = false/true ? TODO: GUI Setting to enable disable this feature y/n?
197 199
     return -1; // user canceled out
198 200
 
199 201
   if (!strPassword.IsEmpty())
16  xbmc/guilib/GUIKeyboardFactory.h
@@ -31,14 +31,14 @@ class CGUIKeyboardFactory
31 31
     CGUIKeyboardFactory(void);
32 32
     virtual ~CGUIKeyboardFactory(void);
33 33
 
34  
-    static bool ShowAndGetInput(CStdString& aTextString, bool allowEmptyResult);
35  
-    static bool ShowAndGetInput(CStdString& aTextString, const CVariant &heading, bool allowEmptyResult, bool hiddenInput = false);
36  
-    static bool ShowAndGetNewPassword(CStdString& strNewPassword);
37  
-    static bool ShowAndGetNewPassword(CStdString& newPassword, const CVariant &heading, bool allowEmpty);
38  
-    static bool ShowAndVerifyNewPassword(CStdString& strNewPassword);
39  
-    static bool ShowAndVerifyNewPassword(CStdString& newPassword, const CVariant &heading, bool allowEmpty);
40  
-    static int  ShowAndVerifyPassword(CStdString& strPassword, const CStdString& strHeading, int iRetries);
41  
-    static bool ShowAndGetFilter(CStdString& aTextString, bool searching);
  34
+    static bool ShowAndGetInput(CStdString& aTextString, bool allowEmptyResult, unsigned int autoCloseMs = 0);
  35
+    static bool ShowAndGetInput(CStdString& aTextString, const CVariant &heading, bool allowEmptyResult, bool hiddenInput = false, unsigned int autoCloseMs = 0);
  36
+    static bool ShowAndGetNewPassword(CStdString& strNewPassword, unsigned int autoCloseMs = 0);
  37
+    static bool ShowAndGetNewPassword(CStdString& newPassword, const CVariant &heading, bool allowEmpty, unsigned int autoCloseMs = 0);
  38
+    static bool ShowAndVerifyNewPassword(CStdString& strNewPassword, unsigned int autoCloseMs = 0);
  39
+    static bool ShowAndVerifyNewPassword(CStdString& newPassword, const CVariant &heading, bool allowEmpty, unsigned int autoCloseMs = 0);
  40
+    static int  ShowAndVerifyPassword(CStdString& strPassword, const CStdString& strHeading, int iRetries, unsigned int autoCloseMs = 0);
  41
+    static bool ShowAndGetFilter(CStdString& aTextString, bool searching, unsigned int autoCloseMs = 0);
42 42
 
43 43
   private:
44 44
     static FILTERING m_filtering;
3  xbmc/osx/ios/IOSKeyboard.h
@@ -24,10 +24,13 @@
24 24
 class CIOSKeyboard : public CGUIKeyboard
25 25
 {
26 26
   public:
  27
+    CIOSKeyboard():m_pCharCallback(NULL),m_pIosKeyboard(NULL){}
27 28
     virtual bool ShowAndGetInput(char_callback_t pCallback, const std::string &initialString, std::string &typedString, const std::string &heading, bool bHiddenInput);
  29
+    virtual void Cancel();
28 30
     void fireCallback(const std::string &str);
29 31
     void invalidateCallback(){m_pCharCallback = NULL;}
30 32
 
31 33
   private:
32 34
     char_callback_t m_pCharCallback;
  35
+    void *m_pIosKeyboard;
33 36
 };
30  xbmc/osx/ios/IOSKeyboard.mm
@@ -37,23 +37,33 @@
37 37
   keyboardFrame.origin.x = frameHeight / 2;
38 38
   keyboardFrame.origin.y = (pCurrentScreen.bounds.size.width/2) - frameHeight*scale + 10;
39 39
   //create the keyboardview
40  
-  KeyboardView *iosKeyboard = [[KeyboardView alloc] initWithFrame:keyboardFrame];
41  
-
  40
+  m_pIosKeyboard = [[KeyboardView alloc] initWithFrame:keyboardFrame];
  41
+  KeyboardView *keyboard = (KeyboardView*)m_pIosKeyboard;
42 42
   m_pCharCallback = pCallback;
43 43
 
44 44
   // init keyboard stuff
45  
-  [iosKeyboard setText:[NSString stringWithUTF8String:initialString.c_str()]];
46  
-  [iosKeyboard SetHiddenInput:bHiddenInput];
47  
-  [iosKeyboard SetHeading:[NSString stringWithUTF8String:heading.c_str()]];
48  
-  [iosKeyboard RegisterKeyboard:this]; // for calling back
49  
-  [iosKeyboard activate];//blocks and loops our application loop (like a modal dialog)
  45
+  [keyboard setText:[NSString stringWithUTF8String:initialString.c_str()]];
  46
+  [keyboard SetHiddenInput:bHiddenInput];
  47
+  [keyboard SetHeading:[NSString stringWithUTF8String:heading.c_str()]];
  48
+  [keyboard RegisterKeyboard:this]; // for calling back
  49
+  [keyboard activate];//blocks and loops our application loop (like a modal dialog)
50 50
   // user is done - get resulted text and confirmation
51  
-  typedString = [[iosKeyboard GetText] UTF8String];
52  
-  confirmed = [iosKeyboard GetResult];
53  
-  [iosKeyboard release]; // bye bye native keyboard
  51
+  typedString = [[keyboard GetText] UTF8String];
  52
+  confirmed = [keyboard GetResult];
  53
+  [keyboard release]; // bye bye native keyboard
  54
+  m_pIosKeyboard = NULL;
54 55
   return confirmed;
55 56
 }
56 57
 
  58
+void CIOSKeyboard::Cancel()
  59
+{
  60
+  if (m_pIosKeyboard)
  61
+  {
  62
+    KeyboardView *keyboard = (KeyboardView*)m_pIosKeyboard;
  63
+    [keyboard keyboardDidHide:nil];
  64
+  }
  65
+}
  66
+
57 67
 //wrap our callback between objc and c++
58 68
 void CIOSKeyboard::fireCallback(const std::string &str)
59 69
 {
1  xbmc/osx/ios/IOSKeyboardView.h
@@ -39,4 +39,5 @@
39 39
 - (void) setText:(NSMutableString *)text;
40 40
 - (void) activate;
41 41
 - (void) deactivate;
  42
+- (void)keyboardDidHide:(id)sender;
42 43
 @end

0 notes on commit fbc641f

Please sign in to comment.
Something went wrong with that request. Please try again.