Skip to content

Commit

Permalink
Merge pull request xbmc#17661 from ronie/numericpass
Browse files Browse the repository at this point in the history
[python] masking support for numeric input
  • Loading branch information
MilhouseVH authored and Maven85 committed Aug 7, 2020
1 parent c42333c commit b8080f6
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 24 deletions.
7 changes: 5 additions & 2 deletions xbmc/dialogs/GUIDialogNumeric.cpp
Expand Up @@ -533,13 +533,16 @@ bool CGUIDialogNumeric::ShowAndGetIPAddress(std::string &IPAddress, const std::s
return true;
}

bool CGUIDialogNumeric::ShowAndGetNumber(std::string& strInput, const std::string &strHeading, unsigned int iAutoCloseTimeoutMs /* = 0 */)
bool CGUIDialogNumeric::ShowAndGetNumber(std::string& strInput, const std::string &strHeading, unsigned int iAutoCloseTimeoutMs /* = 0 */, bool bSetHidden /* = false */)
{
// Prompt user for password input
CGUIDialogNumeric *pDialog = CServiceBroker::GetGUI()->GetWindowManager().GetWindow<CGUIDialogNumeric>(WINDOW_DIALOG_NUMERIC);
pDialog->SetHeading( strHeading );

pDialog->SetMode(INPUT_NUMBER, strInput);
if (bSetHidden)
pDialog->SetMode(INPUT_PASSWORD, strInput);
else
pDialog->SetMode(INPUT_NUMBER, strInput);
if (iAutoCloseTimeoutMs)
pDialog->SetAutoClose(iAutoCloseTimeoutMs);

Expand Down
2 changes: 1 addition & 1 deletion xbmc/dialogs/GUIDialogNumeric.h
Expand Up @@ -49,7 +49,7 @@ class CGUIDialogNumeric :
static bool ShowAndGetTime(KODI::TIME::SystemTime& time, const std::string& heading);
static bool ShowAndGetDate(KODI::TIME::SystemTime& date, const std::string& heading);
static bool ShowAndGetIPAddress(std::string &IPAddress, const std::string &heading);
static bool ShowAndGetNumber(std::string& strInput, const std::string &strHeading, unsigned int iAutoCloseTimeoutMs = 0);
static bool ShowAndGetNumber(std::string& strInput, const std::string &strHeading, unsigned int iAutoCloseTimeoutMs = 0, bool bSetHidden = false);
static bool ShowAndGetSeconds(std::string& timeString, const std::string &heading);

protected:
Expand Down
22 changes: 12 additions & 10 deletions xbmc/interfaces/legacy/Control.h
Expand Up @@ -1069,22 +1069,24 @@ namespace XBMCAddon
/// Sets the type of this edit control.
///
/// @param type integer - type of the edit control.
/// | Param | Definition |
/// |----------------------------------|:--------------------------------------------|
/// | xbmcgui.INPUT_TYPE_TEXT | (standard keyboard)
/// | xbmcgui.INPUT_TYPE_NUMBER | (format: #)
/// | xbmcgui.INPUT_TYPE_DATE | (format: DD/MM/YYYY)
/// | xbmcgui.INPUT_TYPE_TIME | (format: HH:MM)
/// | xbmcgui.INPUT_TYPE_IPADDRESS | (format: #.#.#.#)
/// | xbmcgui.INPUT_TYPE_PASSWORD | (input is masked)
/// | xbmcgui.INPUT_TYPE_PASSWORD_MD5 | (input is masked, return md5 hash of input)
/// | xbmcgui.INPUT_TYPE_SECONDS | (format: SS or MM:SS or HH:MM:SS or MM min)
/// | Param | Definition |
/// |-----------------------------------------------|:--------------------------------------------|
/// | xbmcgui.INPUT_TYPE_TEXT | (standard keyboard)
/// | xbmcgui.INPUT_TYPE_NUMBER | (format: #)
/// | xbmcgui.INPUT_TYPE_DATE | (format: DD/MM/YYYY)
/// | xbmcgui.INPUT_TYPE_TIME | (format: HH:MM)
/// | xbmcgui.INPUT_TYPE_IPADDRESS | (format: #.#.#.#)
/// | xbmcgui.INPUT_TYPE_PASSWORD | (input is masked)
/// | xbmcgui.INPUT_TYPE_PASSWORD_MD5 | (input is masked, return md5 hash of input)
/// | xbmcgui.INPUT_TYPE_SECONDS | (format: SS or MM:SS or HH:MM:SS or MM min)
/// | xbmcgui.INPUT_TYPE_PASSWORD_NUMBER_VERIFY_NEW | (numeric input is masked)
/// @param heading string or unicode - heading that will be used for to numeric or
/// keyboard dialog when the edit control is clicked.
///
///
///-----------------------------------------------------------------------
/// @python_v18 New function added.
/// @python_v19 New option added to mask numeric input.
///
/// **Example:**
/// ~~~~~~~~~~~~~{.py}
Expand Down
10 changes: 8 additions & 2 deletions xbmc/interfaces/legacy/Dialog.cpp
Expand Up @@ -277,7 +277,7 @@ namespace XBMCAddon
return valuelist;
}

String Dialog::numeric(int inputtype, const String& heading, const String& defaultt)
String Dialog::numeric(int inputtype, const String& heading, const String& defaultt, bool bHiddenInput)
{
DelayedCallGuard dcguard(languageHook);
std::string value;
Expand Down Expand Up @@ -319,10 +319,16 @@ namespace XBMCAddon
if (!CGUIDialogNumeric::ShowAndGetIPAddress(value, heading))
return emptyString;
}
else if (inputtype == 4)
{
value = defaultt;
if (!CGUIDialogNumeric::ShowAndVerifyNewPassword(value))
return emptyString;
}
else
{
value = defaultt;
if (!CGUIDialogNumeric::ShowAndGetNumber(value, heading))
if (!CGUIDialogNumeric::ShowAndGetNumber(value, heading, 0, bHiddenInput))
return emptyString;
}
}
Expand Down
22 changes: 13 additions & 9 deletions xbmc/interfaces/legacy/Dialog.h
Expand Up @@ -485,7 +485,7 @@ constexpr int ALPHANUM_HIDE_INPUT{2};
#ifdef DOXYGEN_SHOULD_USE_THIS
///
/// \ingroup python_Dialog
/// \python_func{ xbmcgui.Dialog().numeric(type, heading[, defaultt]) }
/// \python_func{ xbmcgui.Dialog().numeric(type, heading[, defaultt, bHiddenInput]) }
///------------------------------------------------------------------------
///
/// **Numeric dialog**
Expand All @@ -494,19 +494,23 @@ constexpr int ALPHANUM_HIDE_INPUT{2};
/// of a numeric keyboard around an input.
///
/// @param type integer - the type of numeric dialog.
/// | Param | Name | Format |
/// |:-----:|:--------------------|:-----------------------------|
/// | 0 | ShowAndGetNumber | (default format: #)
/// | 1 | ShowAndGetDate | (default format: DD/MM/YYYY)
/// | 2 | ShowAndGetTime | (default format: HH:MM)
/// | 3 | ShowAndGetIPAddress | (default format: #.#.#.#)
/// @param heading string or unicode - dialog heading.
/// | Param | Name | Format |
/// |:-----:|:-------------------------|:-----------------------------|
/// | 0 | ShowAndGetNumber | (default format: #)
/// | 1 | ShowAndGetDate | (default format: DD/MM/YYYY)
/// | 2 | ShowAndGetTime | (default format: HH:MM)
/// | 3 | ShowAndGetIPAddress | (default format: #.#.#.#)
/// | 4 | ShowAndVerifyNewPassword | (default format: *)
/// @param heading string or unicode - dialog heading (will be ignored for type 4).
/// @param defaultt [opt] string - default value.
/// @param bHiddenInput [opt] bool - mask input (available for type 0).
/// @return Returns the entered data as a string.
/// Returns the default value if dialog was canceled.
///
///
///------------------------------------------------------------------------
/// @python_v19 New option added ShowAndVerifyNewPassword.
/// @python_v19 Added new option **bHiddenInput**.
///
/// **Example:**
/// ~~~~~~~~~~~~~{.py}
Expand All @@ -518,7 +522,7 @@ constexpr int ALPHANUM_HIDE_INPUT{2};
///
numeric(...);
#else
String numeric(int type, const String& heading, const String& defaultt = emptyString);
String numeric(int type, const String& heading, const String& defaultt = emptyString, bool bHiddenInput = false);
#endif

#ifdef DOXYGEN_SHOULD_USE_THIS
Expand Down
1 change: 1 addition & 0 deletions xbmc/interfaces/legacy/ModuleXbmcgui.h
Expand Up @@ -127,6 +127,7 @@ namespace XBMCAddon
SWIG_CONSTANT2(int, INPUT_TYPE_PASSWORD, CGUIEditControl::INPUT_TYPE_PASSWORD);
SWIG_CONSTANT2(int, INPUT_TYPE_PASSWORD_MD5, CGUIEditControl::INPUT_TYPE_PASSWORD_MD5);
SWIG_CONSTANT2(int, INPUT_TYPE_SECONDS, CGUIEditControl::INPUT_TYPE_SECONDS);
SWIG_CONSTANT2(int, INPUT_TYPE_PASSWORD_NUMBER_VERIFY_NEW, CGUIEditControl::INPUT_TYPE_PASSWORD_NUMBER_VERIFY_NEW);

SWIG_CONSTANT_FROM_GETTER(const char*, NOTIFICATION_INFO);
SWIG_CONSTANT_FROM_GETTER(const char*, NOTIFICATION_WARNING);
Expand Down

0 comments on commit b8080f6

Please sign in to comment.