[Python] Adds keyboard to dialog class, using all of Dialog().numeric() methods.
authornuka1195 <nuka1195@gmail.com>
Sat, 11 May 2013 21:09:53 +0000 (17:09 -0400)
committernuka1195 <nuka1195@gmail.com>
Mon, 10 Jun 2013 00:35:04 +0000 (20:35 -0400)
This does not eliminate xbmc.Keyboard() or Dialog().numeric. Those could be depreciated.

xbmc/interfaces/legacy/Dialog.cpp
xbmc/interfaces/legacy/Dialog.h
xbmc/interfaces/legacy/ModuleXbmcgui.h

index 52b563a..b8a1895 100644 (file)
@@ -1,5 +1,4 @@
 
-#include "Dialog.h"
 #include "LanguageHook.h"
 
 #include "dialogs/GUIDialogOK.h"
@@ -11,6 +10,7 @@
 #include "settings/MediaSourceSettings.h"
 #include "dialogs/GUIDialogKaiToast.h"
 #include "ModuleXbmcgui.h"
+#include "guilib/GUIKeyboardFactory.h"
 
 #define ACTIVE_WINDOW g_windowManager.GetActiveWindow()
 
@@ -258,6 +258,83 @@ namespace XBMCAddon
         CGUIDialogKaiToast::QueueNotification(strIcon, heading, message, iTime, sound);
     }
     
+    String Dialog::input(const String& heading, const String& defaultt, int type, int option, int autoclose) throw (WindowException)
+    {
+      DelayedCallGuard dcguard(languageHook);
+      CStdString value(defaultt);
+      SYSTEMTIME timedate;
+      GetLocalTime(&timedate);
+
+      switch (type)
+      {
+        case INPUT_ALPHANUM:
+          {
+            bool bHiddenInput = option & ALPHANUM_HIDE_INPUT;
+            if (!CGUIKeyboardFactory::ShowAndGetInput(value, heading, true, bHiddenInput, autoclose))
+              value = emptyString;
+          }
+          break;
+        case INPUT_NUMERIC:
+          {
+            if (!CGUIDialogNumeric::ShowAndGetNumber(value, heading, autoclose))
+              value = emptyString;
+          }
+          break;
+        case INPUT_DATE:
+          {
+            if (!defaultt.empty() && defaultt.size() == 10)
+            {
+              CStdString sDefault = defaultt;
+              timedate.wDay = atoi(sDefault.Left(2));
+              timedate.wMonth = atoi(sDefault.Mid(3,4));
+              timedate.wYear = atoi(sDefault.Right(4));
+            }
+            if (CGUIDialogNumeric::ShowAndGetDate(timedate, heading))
+              value.Format("%2d/%2d/%4d", timedate.wDay, timedate.wMonth, timedate.wYear);
+            else
+              value = emptyString;
+          }
+          break;
+        case INPUT_TIME:
+          {
+            if (!defaultt.empty() && defaultt.size() == 5)
+            {
+              CStdString sDefault = defaultt;
+              timedate.wHour = atoi(sDefault.Left(2));
+              timedate.wMinute = atoi(sDefault.Right(2));
+            }
+            if (CGUIDialogNumeric::ShowAndGetTime(timedate, heading))
+              value.Format("%2d:%02d", timedate.wHour, timedate.wMinute);
+            else
+              value = emptyString;
+          }
+          break;
+        case INPUT_IPADDRESS:
+          {
+            if (!CGUIDialogNumeric::ShowAndGetIPAddress(value, heading))
+              value = emptyString;
+          }
+          break;
+        case INPUT_PASSWORD:
+          {
+            bool bResult = false;
+
+            if (option & PASSWORD_VERIFY)
+              bResult = CGUIKeyboardFactory::ShowAndVerifyPassword(value, heading, 0, autoclose) == 0 ? true : false;
+            else
+              bResult = CGUIKeyboardFactory::ShowAndVerifyNewPassword(value, heading, true, autoclose);
+
+            if (!bResult)
+              value = emptyString;
+          }
+        default:
+          value = emptyString;
+          break;
+      }
+
+      return value;
+    }
+
     DialogProgress::~DialogProgress() { TRACE; deallocating(); }
 
     void DialogProgress::deallocating()
index b96d906..832f528 100644 (file)
 #include "dialogs/GUIDialogExtendedProgressBar.h"
 #include "Alternative.h"
 
+#define INPUT_ALPHANUM        0
+#define INPUT_NUMERIC         1
+#define INPUT_DATE            2
+#define INPUT_TIME            3
+#define INPUT_IPADDRESS       4
+#define INPUT_PASSWORD        5
+
+#define PASSWORD_VERIFY       1
+#define ALPHANUM_HIDE_INPUT   2
+
 namespace XBMCAddon
 {
   namespace xbmcgui
@@ -237,6 +247,42 @@ namespace XBMCAddon
        *   - dialog.notification('Movie Trailers', 'Finding Nemo download finished.', xbmcgui.NOTIFICATION_INFO, 5000)\n
        */
       void notification(const String& heading, const String& message, const String& icon = emptyString, int time = 0, bool sound = true);
+
+      /**
+       * input(heading[, default, type, option, autoclose]) -- Show an Input dialog.
+       *
+       * heading        : string - dialog heading.
+       * default        : [opt] string - default value. (default=empty string)
+       * type           : [opt] integer - the type of keyboard dialog. (default=xbmcgui.INPUT_ALPHANUM)
+       * option         : [opt] integer - option for the dialog. (see Options below)
+       * autoclose      : [opt] integer - milliseconds to autoclose dialog. (default=do not autoclose)
+       *
+       * Types:
+       *   xbmcgui.INPUT_ALPHANUM         (standard keyboard)
+       *   xbmcgui.INPUT_NUMERIC          (format: #)
+       *   xbmcgui.INPUT_DATE             (format: DD/MM/YYYY)
+       *   xbmcgui.INPUT_TIME             (format: HH:MM)
+       *   xbmcgui.INPUT_IPADDRESS        (format: #.#.#.#)
+       *   xbmcgui.INPUT_PASSWORD         (return md5 hash of input, input is masked)
+       *
+       * Options Password Dialog:
+       *   xbmcgui.PASSWORD_VERIFY (verifies an existing (default) md5 hashed password)
+       *
+       * Options Alphanum Dialog:
+       *   xbmcgui.ALPHANUM_HIDE_INPUT (masks input)
+       *
+       * *Note, Returns the entered data as a string.
+       *        Returns an empty string if dialog was canceled.
+       *
+       * example:
+       *   - dialog = xbmcgui.Dialog()
+       *   - d = dialog.input('Enter secret code', type=xbmcgui.INPUT_ALPHANUM, option=xbmcgui.ALPHANUM_HIDE_INPUT)\n
+       */
+      String input(const String& heading,
+                   const String& defaultt = emptyString,
+                   int type = INPUT_ALPHANUM,
+                   int option = 0,
+                   int autoclose = 0) throw (WindowException);
     };
 
     /**
index 04079db..c41d734 100644 (file)
@@ -20,6 +20,7 @@
  */
 
 #include "swighelper.h"
+#include "Dialog.h"
 
 namespace XBMCAddon
 {
@@ -74,5 +75,15 @@ namespace XBMCAddon
     SWIG_CONSTANT_FROM_GETTER(const char*,NOTIFICATION_WARNING);
     SWIG_CONSTANT_FROM_GETTER(const char*,NOTIFICATION_ERROR);
 
+    SWIG_CONSTANT(int,INPUT_ALPHANUM);
+    SWIG_CONSTANT(int,INPUT_NUMERIC);
+    SWIG_CONSTANT(int,INPUT_DATE);
+    SWIG_CONSTANT(int,INPUT_TIME);
+    SWIG_CONSTANT(int,INPUT_IPADDRESS);
+    SWIG_CONSTANT(int,INPUT_PASSWORD);
+
+    SWIG_CONSTANT(int,PASSWORD_VERIFY);
+    SWIG_CONSTANT(int,ALPHANUM_HIDE_INPUT);
+
   }
 }