Skip to content

Commit

Permalink
[Python] Adds keyboard to dialog class, using all of Dialog().numeric…
Browse files Browse the repository at this point in the history
…() methods.

This does not eliminate xbmc.Keyboard() or Dialog().numeric. Those could be depreciated.
  • Loading branch information
nuka1195 committed Jun 10, 2013
1 parent a2bc716 commit 3957810
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 1 deletion.
79 changes: 78 additions & 1 deletion xbmc/interfaces/legacy/Dialog.cpp
@@ -1,5 +1,4 @@

#include "Dialog.h"
#include "LanguageHook.h"

#include "dialogs/GUIDialogOK.h"
Expand All @@ -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()

Expand Down Expand Up @@ -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()
Expand Down
46 changes: 46 additions & 0 deletions xbmc/interfaces/legacy/Dialog.h
Expand Up @@ -31,6 +31,16 @@
#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
Expand Down Expand Up @@ -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);
};

/**
Expand Down
11 changes: 11 additions & 0 deletions xbmc/interfaces/legacy/ModuleXbmcgui.h
Expand Up @@ -20,6 +20,7 @@
*/

#include "swighelper.h"
#include "Dialog.h"

namespace XBMCAddon
{
Expand Down Expand Up @@ -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);

}
}

0 comments on commit 3957810

Please sign in to comment.