Preparing the input classes for Lua

- Add non locale variants for CExtendedInput, CStringInput,
 CStringInputSMS, CPINInput
 THX Martii


Origin commit data
------------------
Commit: 31842369cc
Author: Michael Liebmann <tuxcode.bbg@gmail.com>
Date: 2014-01-18 (Sat, 18 Jan 2014)

Origin message was:
------------------
Preparing the input classes for Lua

- Add non locale variants for CExtendedInput, CStringInput,
 CStringInputSMS, CPINInput
 THX Martii
This commit is contained in:
Michael Liebmann
2014-01-18 13:32:01 +01:00
parent c7fb87a9a3
commit 01de5acc30
21 changed files with 359 additions and 438 deletions

View File

@@ -1247,7 +1247,7 @@ int CMenuOptionNumberChooser::exec(CMenuTarget*)
if (b < upper_bound)
b = upper_bound;
for (; b; b /= 10, size++);
CIntInput cii(name, *optionValue, size, LOCALE_IPSETUP_HINT_1, LOCALE_IPSETUP_HINT_2);
CIntInput cii(name, optionValue, size, LOCALE_IPSETUP_HINT_1, LOCALE_IPSETUP_HINT_2);
cii.exec(NULL, "");
if (*optionValue > upper_bound)
*optionValue = upper_bound;
@@ -2037,38 +2037,38 @@ int CMenuSeparator::paint(bool selected)
bool CPINProtection::check()
{
char cPIN[5];
hint = NONEXISTANT_LOCALE;
std::string cPIN;
do
{
cPIN[0] = 0;
CPINInput* PINInput = new CPINInput(title, cPIN, 4, hint);
cPIN = "";
CPINInput* PINInput = new CPINInput(title, &cPIN, 4, hint);
PINInput->exec( getParent(), "");
delete PINInput;
hint = LOCALE_PINPROTECTION_WRONGCODE;
} while ((strncmp(cPIN,validPIN,4) != 0) && (cPIN[0] != 0));
return ( strncmp(cPIN,validPIN,4) == 0);
} while ((cPIN != *validPIN) && !cPIN.empty());
return (cPIN == *validPIN);
}
bool CZapProtection::check()
{
hint = NONEXISTANT_LOCALE;
int res;
char cPIN[5];
std::string cPIN;
do
{
cPIN[0] = 0;
cPIN = "";
CPLPINInput* PINInput = new CPLPINInput(title, cPIN, 4, hint, fsk);
CPLPINInput* PINInput = new CPLPINInput(title, &cPIN, 4, hint, fsk);
res = PINInput->exec(getParent(), "");
delete PINInput;
hint = LOCALE_PINPROTECTION_WRONGCODE;
} while ( (strncmp(cPIN,validPIN,4) != 0) &&
(cPIN[0] != 0) &&
} while ( (cPIN != *validPIN) && !cPIN.empty() &&
( res == menu_return::RETURN_REPAINT ) &&
( fsk >= g_settings.parentallock_lockage ) );
return ( ( strncmp(cPIN,validPIN,4) == 0 ) ||
return ( (cPIN == *validPIN) ||
( fsk < g_settings.parentallock_lockage ) );
}

View File

@@ -572,14 +572,14 @@ class CMenuWidget : public CMenuTarget
class CPINProtection
{
protected:
char* validPIN;
std::string *validPIN;
bool check();
virtual CMenuTarget* getParent() = 0;
neutrino_locale_t title, hint;
public:
CPINProtection( char* validpin)
CPINProtection(std::string &validpin)
{
validPIN = validpin;
validPIN = &validpin;
hint = NONEXISTANT_LOCALE;
title = LOCALE_PINPROTECTION_HEAD;
};
@@ -595,7 +595,7 @@ class CZapProtection : public CPINProtection
public:
int fsk;
CZapProtection( char* validpin, int FSK ) : CPINProtection(validpin)
CZapProtection(std::string &validpin, int FSK ) : CPINProtection(validpin)
{
fsk = FSK;
title = LOCALE_PARENTALLOCK_HEAD;
@@ -611,7 +611,7 @@ class CLockedMenuForwarder : public CMenuForwarder, public CPINProtection
protected:
virtual CMenuTarget* getParent(){ return Parent;};
public:
CLockedMenuForwarder(const neutrino_locale_t Text, char* _validPIN, bool ask=true, const bool Active=true, char *Option=NULL,
CLockedMenuForwarder(const neutrino_locale_t Text, std::string &_validPIN, bool ask=true, const bool Active=true, const char * const Option = NULL,
CMenuTarget* Target=NULL, const char * const ActionKey = NULL,
neutrino_msg_t DirectKey = CRCInput::RC_nokey, const char * const IconName = NULL, const char * const IconName_Info_right = NULL)
@@ -625,7 +625,7 @@ class CLockedMenuForwarder : public CMenuForwarder, public CPINProtection
iconName_Info_right = IconName_Info_right ? IconName_Info_right : NEUTRINO_ICON_LOCK;
else
iconName_Info_right = "";
};
};
virtual int exec(CMenuTarget* parent);
};

View File

@@ -4,6 +4,7 @@
Copyright (C) 2001 Steffen Hehn 'McClean'
Homepage: http://dbox.cyberphoria.org/
Copyright (C) 2009-2012 Stefan Seyfried
License: GPL
@@ -38,58 +39,15 @@
#include <gui/widget/icons.h>
#include <gui/widget/messagebox.h>
#include <system/helpers.h>
#include <global.h>
#include <neutrino.h>
CStringInput::CStringInput(const neutrino_locale_t Name, char* Value, const int min_value, const int max_value, int Size, const neutrino_locale_t Hint_1, const neutrino_locale_t Hint_2, const char * const Valid_Chars, CChangeObserver* Observ, const char * const Icon)
{
name = Name;
head = NULL;
value = Value;
valueString = NULL;
lower_bound = min_value - 1;
upper_bound = max_value + 1;
size = Size;
hint_1 = Hint_1;
hint_2 = Hint_2;
validchars = Valid_Chars;
iconfile = Icon ? Icon : "";
observ = Observ;
init();
}
CStringInput::CStringInput(const neutrino_locale_t Name, char* Value, int Size, const neutrino_locale_t Hint_1, const neutrino_locale_t Hint_2, const char * const Valid_Chars, CChangeObserver* Observ, const char * const Icon)
{
name = Name;
head = NULL;
value = Value;
valueString = NULL;
lower_bound = -1;
upper_bound = -1;
size = Size;
hint_1 = Hint_1;
hint_2 = Hint_2;
validchars = Valid_Chars;
iconfile = Icon ? Icon : "";
observ = Observ;
init();
}
CStringInput::CStringInput(const neutrino_locale_t Name, std::string* Value, int Size, const neutrino_locale_t Hint_1, const neutrino_locale_t Hint_2, const char * const Valid_Chars, CChangeObserver* Observ, const char * const Icon)
{
name = Name;
head = NULL;
value = NULL;
#if 0
value = new char[Size+1];
value[Size] = '\0';
strncpy(value,Value->c_str(),Size);
#endif
head = g_Locale->getText(Name);
valueString = Value;
lower_bound = -1;
upper_bound = -1;
@@ -104,11 +62,11 @@ CStringInput::CStringInput(const neutrino_locale_t Name, std::string* Value, int
init();
}
CStringInput::CStringInput(char * Head, char* Value, int Size, const neutrino_locale_t Hint_1, const neutrino_locale_t Hint_2, const char * const Valid_Chars, CChangeObserver* Observ, const char * const Icon)
CStringInput::CStringInput(const std::string &Name, std::string *Value, int Size, const neutrino_locale_t Hint_1, const neutrino_locale_t Hint_2, const char * const Valid_Chars, CChangeObserver* Observ, const char * const Icon)
{
head = strdup(Head);
value = Value;
valueString = NULL;
name = NONEXISTANT_LOCALE;
head = Name;
valueString = Value;
lower_bound = -1;
upper_bound = -1;
size = Size;
@@ -124,19 +82,15 @@ CStringInput::CStringInput(char * Head, char* Value, int Size, const neutrino_lo
CStringInput::~CStringInput()
{
#if 0
if (valueString != NULL)
{
delete[] value;
}
#endif
if(head) {
free(head);
}
g_RCInput->killTimer (smstimer);
}
void CStringInput::setMinMax(const int min_value, const int max_value)
{
lower_bound = min_value - 1;
upper_bound = max_value + 1;
}
#define CStringInputSMSButtonsCount 2
const struct button_label CStringInputSMSButtons[CStringInputSMSButtonsCount] =
{
@@ -160,11 +114,7 @@ void CStringInput::init()
width = std::max(size*input_w + 2*offset, (int) frameBuffer->getScreenWidth() / 100 * 45);
int tmp_w = 0;
if (head)
tmp_w = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]->getRenderWidth(head, true); // UTF-8
else
tmp_w = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]->getRenderWidth(g_Locale->getText(name), true); // UTF-8
int tmp_w = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]->getRenderWidth(head.c_str(), true); // UTF-8
if (!(iconfile.empty()))
{
@@ -205,18 +155,36 @@ void CStringInput::NormalKeyPressed(const neutrino_msg_t key)
{
if (CRCInput::isNumeric(key))
{
std::string tmp_value = value;
value[selected] = validchars[CRCInput::getNumericValue(key)];
int current_value = atoi(value);
std::string tmp_value = *valueString;
if (selected >= (int)valueString->length())
valueString->append(selected - valueString->length() + 1, ' ');
valueString->at(selected) = validchars[CRCInput::getNumericValue(key)];
int current_value = atoi((*valueString).c_str());
int tmp = current_value;
if (lower_bound != -1 || upper_bound != -1)
{
if (current_value <= lower_bound)
current_value = lower_bound + 1;
else if (current_value >= upper_bound)
current_value = upper_bound - 1;
if (tmp != current_value)
*valueString = to_string(current_value).substr(0, size);
}
if( (lower_bound == -1 || upper_bound == -1) || (current_value > 0 && current_value > lower_bound && current_value < upper_bound) ){
if (selected < (size - 1))
{
selected++;
paintChar(selected - 1);
}
paintChar(selected);
if (tmp != current_value)
{
for (tmp = 0; tmp < size; tmp++)
paintChar(tmp);
}
else
paintChar(selected);
}else{
snprintf(value, size,"%s",tmp_value.c_str());
*valueString = tmp_value;
}
}
}
@@ -228,10 +196,10 @@ void CStringInput::keyBackspacePressed(void)
selected--;
for (int i = selected; i < size - 1; i++)
{
value[i] = value[i + 1];
valueString->at(i) = valueString->at(i + 1);
paintChar(i);
}
value[size - 1] = ' ';
valueString->at(size - 1) = ' ';
paintChar(size - 1);
}
}
@@ -242,7 +210,7 @@ void CStringInput::keyRedPressed()
if(lower_bound == -1 || upper_bound == -1){
if (index(validchars, ' ') != NULL)
{
value[selected] = ' ';
valueString->at(selected) = ' ';
if (selected < (size - 1))
{
@@ -259,22 +227,20 @@ void CStringInput::keyYellowPressed()
{
if(lower_bound == -1 || upper_bound == -1){
selected=0;
valueString->assign(valueString->length(), ' ');
for(int i=0 ; i < size ; i++)
{
value[i]=' ';
paintChar(i);
}
}
}
void CStringInput::keyBluePressed()
{
if (((value[selected] | 32) >= 'a') && ((value[selected] | 32) <= 'z'))
if (((valueString->at(selected) | 32) >= 'a') && ((valueString->at(selected) | 32) <= 'z'))
{
char newValue = value[selected] ^ 32;
char newValue = valueString->at(selected) ^ 32;
if (index(validchars, newValue) != NULL)
{
value[selected] = newValue;
valueString->at(selected) = newValue;
paintChar(selected);
}
}
@@ -283,40 +249,72 @@ void CStringInput::keyBluePressed()
void CStringInput::keyUpPressed()
{
int npos = 0;
std::string tmp_value = value;
std::string tmp_value = *valueString;
for(int count=0;count<(int)strlen(validchars);count++)
if(value[selected]==validchars[count])
if(valueString->at(selected)==validchars[count])
npos = count;
npos++;
if(npos>=(int)strlen(validchars))
npos = 0;
value[selected]=validchars[npos];
valueString->at(selected)=validchars[npos];
int current_value = atoi(value);
int current_value = atoi((*valueString).c_str());
int tmp = current_value;
if (lower_bound != -1 || upper_bound != -1)
{
if (current_value <= lower_bound)
current_value = lower_bound + 1;
else if (current_value >= upper_bound)
current_value = upper_bound - 1;
if (tmp != current_value)
*valueString = to_string(current_value).substr(0, size);
}
if( (lower_bound == -1 || upper_bound == -1) || (current_value > 0 && current_value > lower_bound && current_value < upper_bound) ){
paintChar(selected);
if (tmp != current_value)
{
for (tmp = 0; tmp < size; tmp++)
paintChar(tmp);
}
else
paintChar(selected);
}else{
snprintf(value, size,"%s",tmp_value.c_str());
*valueString = tmp_value;
}
}
void CStringInput::keyDownPressed()
{
int npos = 0;
std::string tmp_value = value;
std::string tmp_value = *valueString;
for(int count=0;count<(int)strlen(validchars);count++)
if(value[selected]==validchars[count])
if(valueString->at(selected)==validchars[count])
npos = count;
npos--;
if(npos<0)
npos = strlen(validchars)-1;
value[selected]=validchars[npos];
valueString->at(selected)=validchars[npos];
int current_value = atoi(value);
int current_value = atoi((*valueString).c_str());
int tmp = current_value;
if (lower_bound != -1 || upper_bound != -1)
{
if (current_value <= lower_bound)
current_value = lower_bound + 1;
else if (current_value >= upper_bound)
current_value = upper_bound - 1;
if (tmp != current_value)
*valueString = to_string(current_value).substr(0, size);
}
if( (lower_bound == -1 || upper_bound == -1) || (current_value > 0 && current_value > lower_bound && current_value < upper_bound) ){
paintChar(selected);
if (tmp != current_value)
{
for (tmp = 0; tmp < size; tmp++)
paintChar(tmp);
}
else
paintChar(selected);
}else{
snprintf(value, size,"%s",tmp_value.c_str());
*valueString = tmp_value;
}
}
@@ -349,11 +347,11 @@ void CStringInput::keyMinusPressed()
int item = selected;
while (item < (size -1))
{
value[item] = value[item+1];
valueString->at(item) = valueString->at(item+1);
paintChar(item);
item++;
}
value[item] = ' ';
valueString->at(item) = ' ';
paintChar(item);
}
}
@@ -364,48 +362,41 @@ void CStringInput::keyPlusPressed()
int item = size -1;
while (item > selected)
{
value[item] = value[item-1];
valueString->at(item) = valueString->at(item-1);
paintChar(item);
item--;
}
value[item] = ' ';
valueString->at(item) = ' ';
paintChar(item);
}
}
std::string &CStringInput::getValue(void)
{
return *valueString;
}
int CStringInput::exec( CMenuTarget* parent, const std::string & )
{
neutrino_msg_t msg;
neutrino_msg_data_t data;
int res = menu_return::RETURN_REPAINT;
char *oldval = new char[size+1];
if(oldval == NULL)
return res;
char *dispval = new char[size+1];
if(dispval == NULL){
delete[] oldval;
return res;
}
if (valueString != NULL) {
value = new char[size+1];
value[size] = '\0';
strncpy(value,valueString->c_str(),size);
}
oldval[size] = 0;
dispval[size] = 0;
std::string oldval = *valueString;
std::string dispval = *valueString;
if (parent)
parent->hide();
for(int count=strlen(value)-1;count<size-1;count++)
strcat(value, " ");
strncpy(oldval, value, size);
if (size > (int) valueString->length())
valueString->append(size - valueString->length(), ' ');
fb_pixel_t * pixbuf = new fb_pixel_t[(width + SHADOW_OFFSET) * (height + SHADOW_OFFSET)];
if (pixbuf != NULL)
frameBuffer->SaveScreen(x, y, width + SHADOW_OFFSET, height + SHADOW_OFFSET, pixbuf);
fb_pixel_t * pixbuf = NULL;
if (!parent) {
pixbuf = new fb_pixel_t[(width + SHADOW_OFFSET) * (height + SHADOW_OFFSET)];
if (pixbuf)
frameBuffer->SaveScreen(x, y, width + SHADOW_OFFSET, height + SHADOW_OFFSET, pixbuf);
}
paint();
@@ -414,11 +405,10 @@ int CStringInput::exec( CMenuTarget* parent, const std::string & )
bool loop=true;
while (loop)
{
if ( strncmp(value, dispval, size) != 0)
if (*valueString != dispval)
{
std::string tmp = value;
CVFD::getInstance()->showMenuText(1,tmp.c_str() , selected+1);
strncpy(dispval, value, size);
CVFD::getInstance()->showMenuText(1,valueString->c_str() , selected+1);
dispval = *valueString;
}
g_RCInput->getMsgAbsoluteTimeout(&msg, &data, &timeoutEnd, true );
@@ -458,7 +448,7 @@ int CStringInput::exec( CMenuTarget* parent, const std::string & )
}
else if ( (msg==CRCInput::RC_green) && (index(validchars, '.') != NULL))
{
value[selected] = '.';
valueString->at(selected) = '.';
if (selected < (size - 1))
{
@@ -492,11 +482,11 @@ int CStringInput::exec( CMenuTarget* parent, const std::string & )
}
else if ( (msg==CRCInput::RC_home) || (msg==CRCInput::RC_timeout) )
{
if ( ( strcmp(value, oldval) != 0) &&
if ((*valueString != oldval) &&
(ShowLocalizedMessage(name, LOCALE_MESSAGEBOX_DISCARD, CMessageBox::mbrYes, CMessageBox::mbYes | CMessageBox::mbCancel) == CMessageBox::mbrCancel))
continue;
strncpy(value, oldval, size);
*valueString = oldval;
loop=false;
res = menu_return::RETURN_EXIT_REPAINT;
}
@@ -522,39 +512,19 @@ int CStringInput::exec( CMenuTarget* parent, const std::string & )
}
}
hide();
if (pixbuf != NULL)
if (pixbuf)
{
frameBuffer->RestoreScreen(x, y, width + SHADOW_OFFSET, height + SHADOW_OFFSET, pixbuf);
delete[] pixbuf;//Mismatching allocation and deallocation: pixbuf
}
} else
hide();
for(int count=size-1;count>=0;count--)
{
if((value[count]==' ') || (value[count]==0))
{
value[count]=0;
}
else
break;
}
value[size]=0;
if ( (valueString != NULL) && (msg == CRCInput::RC_ok) )
{
*valueString = value;
}
*valueString = trim (*valueString);
if ( (observ) && (msg==CRCInput::RC_ok) )
{
observ->changeNotify(name, value);
observ->changeNotify(name, (void *) valueString->c_str());
}
if (valueString != NULL)
delete[] value;
delete[] dispval;
delete[] oldval;
return res;
}
@@ -582,7 +552,7 @@ void CStringInput::paint(bool sms)
icol_o = icol_w + (offset/2);
}
g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]->RenderString(x+ (offset/2)+ icol_o, y+ hheight, width- offset- icol_o, head ? head : g_Locale->getText(name), COL_MENUHEAD_TEXT, 0, true); // UTF-8
g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]->RenderString(x+ (offset/2)+ icol_o, y+ hheight, width- offset- icol_o, head.c_str(), COL_MENUHEAD_TEXT, 0, true); // UTF-8
int tmp_y = y+ hheight+ offset+ input_h+ offset;
if ((hint_1 != NONEXISTANT_LOCALE) || (hint_2 != NONEXISTANT_LOCALE))
@@ -617,8 +587,8 @@ void CStringInput::paint(bool sms)
void CStringInput::paintChar(int pos)
{
if(pos<(int)strlen(value))
paintChar(pos, value[pos]);
if(pos<(int)valueString->length())
paintChar(pos, valueString->at(pos));
}
void CStringInput::paintChar(int pos, const char c)
@@ -650,13 +620,13 @@ void CStringInput::paintChar(int pos, const char c)
g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString(ch_x, ypos+ input_h, ch_w, ch, color);
}
CStringInputSMS::CStringInputSMS(const neutrino_locale_t Name, std::string* Value, int Size, const neutrino_locale_t Hint_1, const neutrino_locale_t Hint_2, const char * const Valid_Chars, CChangeObserver* Observ, const char * const Icon)
CStringInputSMS::CStringInputSMS(const neutrino_locale_t Name, std::string *Value, int Size, const neutrino_locale_t Hint_1, const neutrino_locale_t Hint_2, const char * const Valid_Chars, CChangeObserver* Observ, const char * const Icon)
: CStringInput(Name, Value, Size, Hint_1, Hint_2, Valid_Chars, Observ, Icon)
{
initSMS(Valid_Chars);
}
CStringInputSMS::CStringInputSMS(const neutrino_locale_t Name, char* Value, int Size, const neutrino_locale_t Hint_1, const neutrino_locale_t Hint_2, const char * const Valid_Chars, CChangeObserver* Observ, const char * const Icon)
CStringInputSMS::CStringInputSMS(const std::string &Name, std::string *Value, int Size, const neutrino_locale_t Hint_1, const neutrino_locale_t Hint_2, const char * const Valid_Chars, CChangeObserver* Observ, const char * const Icon)
: CStringInput(Name, Value, Size, Hint_1, Hint_2, Valid_Chars, Observ, Icon)
{
initSMS(Valid_Chars);
@@ -723,7 +693,7 @@ void CStringInputSMS::NormalKeyPressed(const neutrino_msg_t key)
}
else
keyCounter = (keyCounter + 1) % arraySizes[numericvalue];
value[selected] = Chars[numericvalue][keyCounter];
valueString->at(selected) = Chars[numericvalue][keyCounter];
last_digit = numericvalue;
paintChar(selected);
g_RCInput->killTimer (smstimer);
@@ -731,7 +701,7 @@ void CStringInputSMS::NormalKeyPressed(const neutrino_msg_t key)
}
else
{
value[selected] = (char)CRCInput::getUnicodeValue(key);
valueString->at(selected) = (char)CRCInput::getUnicodeValue(key);
keyRedPressed(); /* to lower, paintChar */
keyRightPressed(); /* last_digit = -1, move to next position */
}
@@ -745,8 +715,8 @@ void CStringInputSMS::keyBackspacePressed(void)
void CStringInputSMS::keyRedPressed() // switch between lower & uppercase
{
if (((value[selected] | 32) >= 'a') && ((value[selected] | 32) <= 'z'))
value[selected] ^= 32;
if (((valueString->at(selected) | 32) >= 'a') && ((valueString->at(selected) | 32) <= 'z'))
valueString->at(selected) ^= 32;
paintChar(selected);
}
@@ -778,7 +748,7 @@ void CStringInputSMS::keyDownPressed()
selected = size - 1;
while (value[selected] == ' ')
while (valueString->at(selected) == ' ')
{
selected--;
if (selected < 0)
@@ -811,7 +781,7 @@ void CStringInputSMS::paint(bool /*unused*/)
void CPINInput::paintChar(int pos)
{
CStringInput::paintChar(pos, (value[pos] == ' ') ? ' ' : '*');
CStringInput::paintChar(pos, (valueString->at(pos) == ' ') ? ' ' : '*');
}
int CPINInput::exec( CMenuTarget* parent, const std::string & )
@@ -824,8 +794,8 @@ int CPINInput::exec( CMenuTarget* parent, const std::string & )
if (parent)
parent->hide();
for(int count=strlen(value)-1;count<size-1;count++)
strcat(value, " ");
if (size > (int) valueString->length())
valueString->append(size - valueString->length(), ' ');
paint();
@@ -878,25 +848,15 @@ int CPINInput::exec( CMenuTarget* parent, const std::string & )
}
}
}
}
hide();
for(int count=size-1;count>=0;count--)
{
if((value[count]==' ') || (value[count]==0))
{
value[count]=0;
}
else
break;
}
value[size]=0;
*valueString = trim (*valueString);
if ( (observ) && (msg==CRCInput::RC_ok) )
{
observ->changeNotify(name, value);
observ->changeNotify(name, (void *) valueString->c_str());
}
return res;
@@ -905,9 +865,9 @@ int CPINInput::exec( CMenuTarget* parent, const std::string & )
void CEnquiryInput::paintChar(int pos)
{
if (blind)
CStringInput::paintChar(pos, (value[pos] == ' ') ? ' ' : '*');
CStringInput::paintChar(pos, (valueString->at(pos) == ' ') ? ' ' : '*');
else
CStringInput::paintChar(pos, value[pos]);
CStringInput::paintChar(pos, valueString->at(pos));
}
int CPLPINInput::handleOthers(neutrino_msg_t msg, neutrino_msg_data_t data)
@@ -946,7 +906,7 @@ int CPLPINInput::exec( CMenuTarget* parent, const std::string & )
{
fb_pixel_t * pixbuf = new fb_pixel_t[(width+ 2* borderwidth) * (height+ 2* borderwidth)];
if (pixbuf != NULL)
if (pixbuf)
frameBuffer->SaveScreen(x- borderwidth, y- borderwidth, width+ 2* borderwidth, height+ 2* borderwidth, pixbuf);
// clear border
@@ -957,9 +917,9 @@ int CPLPINInput::exec( CMenuTarget* parent, const std::string & )
int res = CPINInput::exec ( parent, "" );
if (pixbuf != NULL)
if (pixbuf)
{
frameBuffer->RestoreScreen(x- borderwidth, y- borderwidth, width+ 2* borderwidth, height+ 2* borderwidth, pixbuf);
frameBuffer->RestoreScreen(x - borderwidth, y- borderwidth, width+ 2* borderwidth, height+ 2* borderwidth, pixbuf);
delete[] pixbuf;//Mismatching allocation and deallocation: pixbuf
}

View File

@@ -53,13 +53,11 @@ class CStringInput : public CMenuTarget
uint32_t smstimer;
char * head;
std::string head;
neutrino_locale_t name;
neutrino_locale_t hint_1, hint_2;
std::string iconfile;
const char * validchars;
char * value;
std::string *valueString;
int size;
int selected;
CChangeObserver * observ;
@@ -85,18 +83,14 @@ class CStringInput : public CMenuTarget
virtual int handleOthers(const neutrino_msg_t msg, const neutrino_msg_data_t data);
public:
//CStringInput with max min value option
CStringInput(const neutrino_locale_t Name, char* Value , const int min_value, const int max_value
, int Size, const neutrino_locale_t Hint_1 = NONEXISTANT_LOCALE, const neutrino_locale_t Hint_2 = NONEXISTANT_LOCALE, const char * const Valid_Chars= (const char *) "0123456789. ", CChangeObserver* Observ = NULL, const char * const Icon = NULL);
CStringInput(const neutrino_locale_t Name, char* Value , int Size, const neutrino_locale_t Hint_1 = NONEXISTANT_LOCALE, const neutrino_locale_t Hint_2 = NONEXISTANT_LOCALE, const char * const Valid_Chars= (const char *) "0123456789. ", CChangeObserver* Observ = NULL, const char * const Icon = NULL);
CStringInput(char * Head, char* Value , int Size, const neutrino_locale_t Hint_1 = NONEXISTANT_LOCALE, const neutrino_locale_t Hint_2 = NONEXISTANT_LOCALE, const char * const Valid_Chars= (const char *) "0123456789. ", CChangeObserver* Observ = NULL, const char * const Icon = NULL);
CStringInput(const neutrino_locale_t Name, std::string* Value, int Size, const neutrino_locale_t Hint_1 = NONEXISTANT_LOCALE, const neutrino_locale_t Hint_2 = NONEXISTANT_LOCALE, const char * const Valid_Chars= (const char *) "0123456789. ", CChangeObserver* Observ = NULL, const char * const Icon = NULL);
CStringInput(const std::string &Name, std::string* Value, int Size, const neutrino_locale_t Hint_1 = NONEXISTANT_LOCALE, const neutrino_locale_t Hint_2 = NONEXISTANT_LOCALE, const char * const Valid_Chars= (const char *) "0123456789. ", CChangeObserver* Observ = NULL, const char * const Icon = NULL);
~CStringInput();
void hide();
int exec( CMenuTarget* parent, const std::string & actionKey );
void setMinMax(const int min_value, const int max_value);
virtual std::string &getValue(void);
};
class CStringInputSMS : public CStringInput
@@ -121,8 +115,8 @@ class CStringInputSMS : public CStringInput
void initSMS(const char * const Valid_Chars);
public:
CStringInputSMS(const neutrino_locale_t Name, char* Value, int Size, const neutrino_locale_t Hint_1, const neutrino_locale_t Hint_2, const char * const Valid_Chars, CChangeObserver* Observ = NULL, const char * const Icon = NULL);
CStringInputSMS(const neutrino_locale_t Name, std::string* Value, int Size, const neutrino_locale_t Hint_1, const neutrino_locale_t Hint_2, const char * const Valid_Chars, CChangeObserver* Observ = NULL, const char * const Icon = NULL);
CStringInputSMS(const std::string &Name, std::string* Value, int Size, const neutrino_locale_t Hint_1, const neutrino_locale_t Hint_2, const char * const Valid_Chars, CChangeObserver* Observ = NULL, const char * const Icon = NULL);
};
class CPINInput : public CStringInput
@@ -130,10 +124,10 @@ class CPINInput : public CStringInput
protected:
virtual void paintChar(int pos);
public:
CPINInput(const neutrino_locale_t Name, char* Value, int Size, const neutrino_locale_t Hint_1 = NONEXISTANT_LOCALE, const neutrino_locale_t Hint_2 = NONEXISTANT_LOCALE, const char * const Valid_Chars= (const char *)"0123456789", CChangeObserver* Observ = NULL)
: CStringInput(Name, (char *)Value, Size, Hint_1, Hint_2, Valid_Chars, Observ, (char *) NEUTRINO_ICON_LOCK) {};
CPINInput(char * Head, char* Value, int Size, const neutrino_locale_t Hint_1 = NONEXISTANT_LOCALE, const neutrino_locale_t Hint_2 = NONEXISTANT_LOCALE, const char * const Valid_Chars= (const char *)"0123456789", CChangeObserver* Observ = NULL)
: CStringInput(Head, (char *)Value, Size, Hint_1, Hint_2, Valid_Chars, Observ, (char *) NEUTRINO_ICON_LOCK) {};
CPINInput(const neutrino_locale_t Name, std::string *Value, int Size, const neutrino_locale_t Hint_1 = NONEXISTANT_LOCALE, const neutrino_locale_t Hint_2 = NONEXISTANT_LOCALE, const char * const Valid_Chars= (const char *)"0123456789", CChangeObserver* Observ = NULL)
: CStringInput(Name, Value, Size, Hint_1, Hint_2, Valid_Chars, Observ, (char *) NEUTRINO_ICON_LOCK) {};
CPINInput(const std::string &Name, std::string *Value, int Size, const neutrino_locale_t Hint_1 = NONEXISTANT_LOCALE, const neutrino_locale_t Hint_2 = NONEXISTANT_LOCALE, const char * const Valid_Chars= (const char *)"0123456789", CChangeObserver* Observ = NULL)
: CStringInput(Name, Value, Size, Hint_1, Hint_2, Valid_Chars, Observ, (char *) NEUTRINO_ICON_LOCK) {};
int exec( CMenuTarget* parent, const std::string & actionKey );
};
@@ -146,10 +140,10 @@ class CEnquiryInput : public CPINInput
protected:
virtual void paintChar(int pos);
public:
CEnquiryInput(const neutrino_locale_t Name, char* Value, int Size, bool Blind, const neutrino_locale_t Hint_1 = NONEXISTANT_LOCALE, const neutrino_locale_t Hint_2 = NONEXISTANT_LOCALE, const char * const Valid_Chars= (const char *)"0123456789", CChangeObserver* Observ = NULL)
: CPINInput(Name, (char *)Value, Size, Hint_1, Hint_2, Valid_Chars, Observ) { blind = Blind; }
CEnquiryInput(char * Head, char* Value, int Size, bool Blind, const neutrino_locale_t Hint_1 = NONEXISTANT_LOCALE, const neutrino_locale_t Hint_2 = NONEXISTANT_LOCALE, const char * const Valid_Chars= (const char *)"0123456789", CChangeObserver* Observ = NULL)
: CPINInput(Head, (char *)Value, Size, Hint_1, Hint_2, Valid_Chars, Observ) { blind = Blind; }
CEnquiryInput(const neutrino_locale_t Name, std::string *Value, int Size, bool Blind, const neutrino_locale_t Hint_1 = NONEXISTANT_LOCALE, const neutrino_locale_t Hint_2 = NONEXISTANT_LOCALE, const char * const Valid_Chars= (const char *)"0123456789", CChangeObserver* Observ = NULL)
: CPINInput(Name, Value, Size, Hint_1, Hint_2, Valid_Chars, Observ) { blind = Blind; }
CEnquiryInput(const std::string &Name, std::string *Value, int Size, bool Blind, const neutrino_locale_t Hint_1 = NONEXISTANT_LOCALE, const neutrino_locale_t Hint_2 = NONEXISTANT_LOCALE, const char * const Valid_Chars= (const char *)"0123456789", CChangeObserver* Observ = NULL)
: CPINInput(Name, Value, Size, Hint_1, Hint_2, Valid_Chars, Observ) { blind = Blind; }
};
@@ -164,8 +158,8 @@ class CPLPINInput : public CPINInput
virtual const char * getHint1(void);
public:
CPLPINInput(const neutrino_locale_t Name, char* Value, int Size, const neutrino_locale_t Hint_2, int FSK )
: CPINInput(Name, (char *)Value, Size, NONEXISTANT_LOCALE, Hint_2) { fsk = FSK; };
CPLPINInput(const neutrino_locale_t Name, std::string *Value, int Size, const neutrino_locale_t Hint_2, int FSK )
: CPINInput(Name, Value, Size, NONEXISTANT_LOCALE, Hint_2) { fsk = FSK; };
int exec( CMenuTarget* parent, const std::string & actionKey );
};
@@ -173,8 +167,8 @@ class CPLPINInput : public CPINInput
class CPINChangeWidget : public CStringInput
{
public:
CPINChangeWidget(const neutrino_locale_t Name, char* Value, int Size, const neutrino_locale_t Hint_1, const char * const Valid_Chars= (const char *) "0123456789", CChangeObserver* Observ = NULL)
: CStringInput(Name, (char *)Value, Size, Hint_1, NONEXISTANT_LOCALE, Valid_Chars, Observ){};
CPINChangeWidget(const neutrino_locale_t Name, std::string *Value, int Size, const neutrino_locale_t Hint_1, const char * const Valid_Chars= (const char *) "0123456789", CChangeObserver* Observ = NULL)
: CStringInput(Name, Value, Size, Hint_1, NONEXISTANT_LOCALE, Valid_Chars, Observ){};
};

View File

@@ -36,14 +36,15 @@
#include <gui/widget/messagebox.h>
#include <system/helpers.h>
#include <global.h>
#include <neutrino.h>
CExtendedInput::CExtendedInput(const neutrino_locale_t Name, char* Value, const neutrino_locale_t Hint_1, const neutrino_locale_t Hint_2, CChangeObserver* Observ, bool* Cancel)
CExtendedInput::CExtendedInput(const neutrino_locale_t Name, std::string *Value, const neutrino_locale_t Hint_1, const neutrino_locale_t Hint_2, CChangeObserver* Observ, bool* Cancel)
{
name = Name;
value = Value;
valueString = Value;
cancel = Cancel;
hint_1 = Hint_1;
@@ -111,11 +112,14 @@ void CExtendedInput::calculateDialog()
int maxX = 0;
int maxY = 0;
if (valueString->size() < inputFields.size())
valueString->append(inputFields.size() - valueString->size(), ' ');
selectedChar = -1;
for(unsigned int i=0; i<inputFields.size();i++)
{
inputFields[i]->init( ix, iy);
inputFields[i]->setDataPointer( &value[i] );
inputFields[i]->setDataPointer( &valueString->at(i) );
if ((selectedChar==-1) && (inputFields[i]->isSelectable()))
{
selectedChar = i;
@@ -138,24 +142,14 @@ int CExtendedInput::exec( CMenuTarget* parent, const std::string & )
neutrino_msg_data_t data;
onBeforeExec();
calculateDialog();
int res = menu_return::RETURN_REPAINT;
char *oldval = new char[inputFields.size()+10];
if(oldval == NULL)
return res;
char *dispval = new char[inputFields.size()+10];
if(dispval == NULL){
delete[] oldval;
return res;
}
if (parent)
{
parent->hide();
}
strcpy(oldval, value);
strcpy(dispval, value);
std::string oldval = *valueString;
std::string dispval = *valueString;
paint();
uint64_t timeoutEnd = CRCInput::calcTimeoutEnd(g_settings.timing[SNeutrinoSettings::TIMING_MENU] == 0 ? 0xFFFF : g_settings.timing[SNeutrinoSettings::TIMING_MENU]);
@@ -163,11 +157,10 @@ int CExtendedInput::exec( CMenuTarget* parent, const std::string & )
bool loop=true;
while (loop)
{
if ( strcmp(value, dispval) != 0)
if (*valueString != dispval)
{
std::string tmp = value;
CVFD::getInstance()->showMenuText(1, tmp.c_str(), selectedChar+1);
strcpy(dispval, value);
CVFD::getInstance()->showMenuText(1, valueString->c_str(), selectedChar+1);
dispval = *valueString;
}
g_RCInput->getMsgAbsoluteTimeout(&msg, &data, &timeoutEnd, true );
@@ -195,8 +188,7 @@ int CExtendedInput::exec( CMenuTarget* parent, const std::string & )
if(found) {
inputFields[oldSelectedChar]->paint(x+ offset, y+ hheight+ offset, false );
inputFields[selectedChar]->paint(x+ offset, y+ hheight+ offset, true );
std::string tmp = value;
CVFD::getInstance()->showMenuText(1, tmp.c_str(), selectedChar+1);
CVFD::getInstance()->showMenuText(1, valueString->c_str(), selectedChar+1);
}
} else if (msg==CRCInput::RC_right) {
bool found = false;
@@ -223,8 +215,7 @@ int CExtendedInput::exec( CMenuTarget* parent, const std::string & )
if(found) {
inputFields[oldSelectedChar]->paint(x+ offset, y+ hheight+ offset, false );
inputFields[selectedChar]->paint(x+ offset, y+ hheight+ offset, true );
std::string tmp = value;
CVFD::getInstance()->showMenuText(1, tmp.c_str(), selectedChar+1);
CVFD::getInstance()->showMenuText(1, valueString->c_str(), selectedChar+1);
}
}
else if ( (CRCInput::getUnicodeValue(msg) != -1) || (msg == CRCInput::RC_red) || (msg == CRCInput::RC_green) || (msg == CRCInput::RC_blue) || (msg == CRCInput::RC_yellow)
@@ -241,10 +232,10 @@ int CExtendedInput::exec( CMenuTarget* parent, const std::string & )
}
else if ( (msg==CRCInput::RC_home) || (msg==CRCInput::RC_timeout) )
{
if(strcmp(value, oldval)!= 0){
if(*valueString != oldval){
int erg = ShowLocalizedMessage(name, LOCALE_MESSAGEBOX_DISCARD, CMessageBox::mbrYes, CMessageBox::mbNo | CMessageBox::mbYes | CMessageBox::mbCancel);
if(erg==CMessageBox::mbrYes){
strcpy(value, oldval);
*valueString = oldval;
loop=false;
if(cancel != NULL)
*cancel = true;
@@ -268,7 +259,7 @@ int CExtendedInput::exec( CMenuTarget* parent, const std::string & )
}
else if ( CNeutrinoApp::getInstance()->handleMsg( msg, data ) & messages_return::cancel_all )
{
strcpy(value, oldval);
*valueString = oldval;
loop=false;
if(cancel != NULL)
*cancel = true;
@@ -278,15 +269,12 @@ int CExtendedInput::exec( CMenuTarget* parent, const std::string & )
hide();
*valueString = trim(*valueString);
onAfterExec();
if ((observ) && (msg == CRCInput::RC_ok))
{
observ->changeNotify(name, value);
}
delete[] dispval;
delete[] oldval;
observ->changeNotify(name, (void *)valueString->c_str());
return res;
}
@@ -428,11 +416,8 @@ void CExtendedInput_Item_Char::keyPressed(const int key)
//-----------------------------#################################-------------------------------------------------------
CIPInput::CIPInput(const neutrino_locale_t Name, std::string & Value, const neutrino_locale_t Hint_1, const neutrino_locale_t Hint_2, CChangeObserver* Observ)
: CExtendedInput(Name, IP, Hint_1, Hint_2, Observ)
CIPInput::CIPInput(const neutrino_locale_t Name, std::string *Value, const neutrino_locale_t Hint_1, const neutrino_locale_t Hint_2, CChangeObserver* Observ) : CExtendedInput(Name, Value, Hint_1, Hint_2, Observ)
{
ip = &Value;
frameBuffer = CFrameBuffer::getInstance();
addInputField( new CExtendedInput_Item_Char("012") );
addInputField( new CExtendedInput_Item_Char("0123456789") );
addInputField( new CExtendedInput_Item_Char("0123456789") );
@@ -449,47 +434,45 @@ CIPInput::CIPInput(const neutrino_locale_t Name, std::string & Value, const neut
addInputField( new CExtendedInput_Item_Char("0123456789") );
addInputField( new CExtendedInput_Item_Char("0123456789") );
addInputField( new CExtendedInput_Item_newLiner(30) );
calculateDialog();
}
void CIPInput::onBeforeExec()
{
if (ip->empty())
if (valueString->empty())
{
strcpy(value, "000.000.000.000");
//printf("[neutrino] value-before(2): %s\n", value);
*valueString = "000.000.000.000";
return;
}
unsigned char _ip[4];
sscanf(ip->c_str(), "%hhu.%hhu.%hhu.%hhu", &_ip[0], &_ip[1], &_ip[2], &_ip[3]);
sprintf( value, "%03hhu.%03hhu.%03hhu.%03hhu", _ip[0], _ip[1], _ip[2], _ip[3]);
unsigned char ip[4];
sscanf(valueString->c_str(), "%hhu.%hhu.%hhu.%hhu", &ip[0], &ip[1], &ip[2], &ip[3]);
char s[20];
snprintf(s, sizeof(s), "%03hhu.%03hhu.%03hhu.%03hhu", ip[0], ip[1], ip[2], ip[3]);
*valueString = std::string(s);
}
void CIPInput::onAfterExec()
{
int _ip[4];
sscanf( value, "%3d.%3d.%3d.%3d", &_ip[0], &_ip[1], &_ip[2], &_ip[3] );
sprintf( value, "%d.%d.%d.%d", _ip[0], _ip[1], _ip[2], _ip[3]);
if(strcmp(value,"0.0.0.0")==0)
{
(*ip) = "";
}
else
(*ip) = value;
int ip[4];
sscanf(valueString->c_str(), "%3d.%3d.%3d.%3d", &ip[0], &ip[1], &ip[2], &ip[3] );
char s[20];
snprintf(s, sizeof(s), "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
*valueString = std::string(s);
if(*valueString == "0.0.0.0")
*valueString = "";
}
//-----------------------------#################################-------------------------------------------------------
CDateInput::CDateInput(const neutrino_locale_t Name, time_t* Time, const neutrino_locale_t Hint_1, const neutrino_locale_t Hint_2, CChangeObserver* Observ)
: CExtendedInput(Name, (char *) "", Hint_1, Hint_2, Observ)
: CExtendedInput(Name, &valueStringTmp, Hint_1, Hint_2, Observ)
{
time=Time;
value= new char[20];
char value[40];
struct tm *tmTime = localtime(time);
sprintf( value, "%02d.%02d.%04d %02d:%02d", tmTime->tm_mday, tmTime->tm_mon+1,
snprintf(value, sizeof(value), "%02d.%02d.%04d %02d:%02d", tmTime->tm_mday, tmTime->tm_mon+1,
tmTime->tm_year+1900,
tmTime->tm_hour, tmTime->tm_min);
*valueString = std::string(value);
frameBuffer = CFrameBuffer::getInstance();
addInputField( new CExtendedInput_Item_Char("0123") );
addInputField( new CExtendedInput_Item_Char("0123456789") );
addInputField( new CExtendedInput_Item_Char(".",false) );
@@ -507,24 +490,22 @@ CDateInput::CDateInput(const neutrino_locale_t Name, time_t* Time, const neutrin
addInputField( new CExtendedInput_Item_Char("012345") );
addInputField( new CExtendedInput_Item_Char("0123456789") );
addInputField( new CExtendedInput_Item_newLiner(30) );
calculateDialog();
}
CDateInput::~CDateInput()
{
delete value;
}
void CDateInput::onBeforeExec()
{
char value[40];
struct tm *tmTime = localtime(time);
sprintf( value, "%02d.%02d.%04d %02d:%02d", tmTime->tm_mday, tmTime->tm_mon+1,
snprintf(value, sizeof(value), "%02d.%02d.%04d %02d:%02d", tmTime->tm_mday, tmTime->tm_mon+1,
tmTime->tm_year+1900,
tmTime->tm_hour, tmTime->tm_min);
*valueString = std::string(value);
}
void CDateInput::onAfterExec()
{
struct tm tmTime;
sscanf( value, "%02d.%02d.%04d %02d:%02d", &tmTime.tm_mday, &tmTime.tm_mon,
sscanf(valueString->c_str(), "%02d.%02d.%04d %02d:%02d", &tmTime.tm_mday, &tmTime.tm_mon,
&tmTime.tm_year,
&tmTime.tm_hour, &tmTime.tm_min);
tmTime.tm_mon -= 1;
@@ -559,18 +540,17 @@ void CDateInput::onAfterExec()
tmTime.tm_sec=0;
*time=mktime(&tmTime);
char value[40];
struct tm *tmTime2 = localtime(time);
sprintf( value, "%02d.%02d.%04d %02d:%02d", tmTime2->tm_mday, tmTime2->tm_mon+1,
tmTime2->tm_year+1900,
tmTime2->tm_hour, tmTime2->tm_min);
snprintf(value, sizeof(value), "%02d.%02d.%04d %02d:%02d", tmTime2->tm_mday, tmTime2->tm_mon+1,
tmTime2->tm_year+1900,
tmTime2->tm_hour, tmTime2->tm_min);
*valueString = std::string(value);
}
//-----------------------------#################################-------------------------------------------------------
CMACInput::CMACInput(const neutrino_locale_t Name, std::string &
Value, const neutrino_locale_t Hint_1, const neutrino_locale_t Hint_2, CChangeObserver* Observ)
: CExtendedInput(Name, MAC, Hint_1, Hint_2, Observ)
CMACInput::CMACInput(const neutrino_locale_t Name, std::string * Value, const neutrino_locale_t Hint_1, const neutrino_locale_t Hint_2, CChangeObserver* Observ) : CExtendedInput(Name, Value, Hint_1, Hint_2, Observ)
{
mac = &Value;
frameBuffer = CFrameBuffer::getInstance();
addInputField( new CExtendedInput_Item_Char("0123456789ABCDEF") );
addInputField( new CExtendedInput_Item_Char("0123456789ABCDEF") );
@@ -590,41 +570,65 @@ Value, const neutrino_locale_t Hint_1, const neutrino_locale_t Hint_2, CChangeOb
addInputField( new CExtendedInput_Item_Char("0123456789ABCDEF") );
addInputField( new CExtendedInput_Item_Char("0123456789ABCDEF") );
addInputField( new CExtendedInput_Item_newLiner(30) );
calculateDialog();
}
void CMACInput::onBeforeExec()
{
if (value[0] == 0) /* strcmp(value, "") == 0 */
if (valueString->empty())
{
strcpy(value, "00:00:00:00:00:00");
printf("[neutrino] value-before(2): %s\n", value);
*valueString = "00:00:00:00:00:00";
return;
}
int _mac[6];
sscanf( mac->c_str(), "%x:%x:%x:%x:%x:%x", &_mac[0], &_mac[1], &_mac[2], &_mac[3], &_mac[4], &_mac[5] );
sprintf( value, "%02x:%02x:%02x:%02x:%02x:%02x", _mac[0], _mac[1], _mac[2], _mac[3], _mac[4], _mac[5]);
int mac[6];
sscanf(valueString->c_str(), "%x:%x:%x:%x:%x:%x", &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5] );
char s[20];
snprintf(s, sizeof(s), "%02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
*valueString = std::string(s);
}
void CMACInput::onAfterExec()
{
int _mac[6];
sscanf( value, "%x:%x:%x:%x:%x:%x", &_mac[0], &_mac[1], &_mac[2], &_mac[3], &_mac[4], &_mac[5] );
sprintf( value, "%02x:%02x:%02x:%02x:%02x:%02x", _mac[0], _mac[1], _mac[2], _mac[3], _mac[4], _mac[5]);
if(strcmp(value,"00:00:00:00:00:00")==0)
{
(*mac) = "";
}
else
(*mac) = value;
int mac[6];
sscanf(valueString->c_str(), "%x:%x:%x:%x:%x:%x", &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5] );
char s[20];
snprintf(s, sizeof(s), "%02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
*valueString = std::string(s);
if(*valueString == "00:00:00:00:00:00")
*valueString = "";
}
//-----------------------------#################################-------------------------------------------------------
CTimeInput::CTimeInput(const neutrino_locale_t Name, char* Value, const neutrino_locale_t Hint_1, const neutrino_locale_t Hint_2, CChangeObserver* Observ, bool* Cancel)
: CExtendedInput(Name, Value, Hint_1, Hint_2, Observ, Cancel)
CTimeInput::CTimeInput(const neutrino_locale_t Name, std::string* Value, const neutrino_locale_t Hint_1, const neutrino_locale_t Hint_2, CChangeObserver* Observ, bool* Cancel)
: CExtendedInput(Name, &valueStringTmp, Hint_1, Hint_2, Observ, Cancel)
{
valueString = Value;
frameBuffer = CFrameBuffer::getInstance();
#if 0
// As nobody else seems to use this class I feel free to make some minor (and mostly backwards-compatible)
// adjustments to make it suitable for movieplayer playtime selection ... --martii
const char *v = valueString->c_str();
if (!isdigit(*v)) {
addInputField( new CExtendedInput_Item_Char("=+-") );
addInputField( new CExtendedInput_Item_Spacer(20) );
}
addInputField( new CExtendedInput_Item_Char("0123456789") );
addInputField( new CExtendedInput_Item_Char("0123456789") );
v = strstr(v, ":");
if (v) {
v++;
addInputField( new CExtendedInput_Item_Char(":",false) );
addInputField( new CExtendedInput_Item_Char("0123456789") );
addInputField( new CExtendedInput_Item_Char("0123456789") );
v = strstr(v, ":");
if (v) {
addInputField( new CExtendedInput_Item_Char(":",false) );
addInputField( new CExtendedInput_Item_Char("0123456789") );
addInputField( new CExtendedInput_Item_Char("0123456789") );
}
}
#else
addInputField( new CExtendedInput_Item_Char("=+-") );
addInputField( new CExtendedInput_Item_Spacer(20) );
addInputField( new CExtendedInput_Item_Char("0123456789") );
@@ -635,66 +639,56 @@ CTimeInput::CTimeInput(const neutrino_locale_t Name, char* Value, const neutrino
addInputField( new CExtendedInput_Item_Char(":",false) );
addInputField( new CExtendedInput_Item_Char("0123456789") );
addInputField( new CExtendedInput_Item_Char("0123456789") );
#endif
addInputField( new CExtendedInput_Item_newLiner(30) );
calculateDialog();
}
void CTimeInput::onBeforeExec()
{
#if 0 //--martii
strcpy(value, "= 00:00:00");
#endif
}
void CTimeInput::onAfterExec()
{
#if 0 //--martii
char tmp[10+1];
strcpy(tmp, value);
strcpy(value+1, tmp+2);
#endif
}
//-----------------------------#################################-------------------------------------------------------
CIntInput::CIntInput(const neutrino_locale_t Name, int& Value, const unsigned int Size, const neutrino_locale_t Hint_1, const neutrino_locale_t Hint_2, CChangeObserver* Observ)
: CExtendedInput(Name, myValueStringInput, Hint_1, Hint_2, Observ)
CIntInput::CIntInput(const neutrino_locale_t Name, int *Value, const unsigned int Size, const neutrino_locale_t Hint_1, const neutrino_locale_t Hint_2, CChangeObserver* Observ)
: CExtendedInput(Name, &valueStringTmp, Hint_1, Hint_2, Observ)
{
myValue = &Value;
myValue = Value;
if (Size<MAX_CINTINPUT_SIZE)
m_size = Size;
else
m_size = MAX_CINTINPUT_SIZE-1;
if (*myValue == 0)
{
sprintf(myValueStringInput,"%-7d",0);
sprintf(myValueStringOutput,"%7d",0);
} else {
sprintf(myValueStringInput,"%-*d",m_size,*myValue);
sprintf(myValueStringOutput,"%*d",m_size,*myValue);
}
onBeforeExec();
frameBuffer = CFrameBuffer::getInstance();
for (unsigned int i=0;i<Size;i++)
{
addInputField( new CExtendedInput_Item_Char("0123456789 ") );
}
addInputField( new CExtendedInput_Item_newLiner(30) );
calculateDialog();
}
void CIntInput::onBeforeExec()
{
if (*myValue == 0)
{
sprintf(myValueStringInput,"%-7d",0);
sprintf(myValueStringOutput,"%7d",0);
} else {
sprintf(myValueStringInput,"%-*d",m_size,*myValue);
sprintf(myValueStringOutput,"%*d",m_size,*myValue);
}
char tmp[MAX_CINTINPUT_SIZE];
snprintf(tmp, sizeof(tmp) - 1,"%*d", m_size, *myValue);
tmp[sizeof(tmp) - 1] = 0;
*valueString = std::string(tmp);
}
void CIntInput::onAfterExec()
{
sscanf(myValueStringInput, "%d", myValue);
sprintf(myValueStringOutput,"%d",*myValue);
*myValue = atoi((*valueString).c_str());
}
//-----------------------------#################################-------------------------------------------------------

View File

@@ -63,10 +63,10 @@ class CExtendedInput : public CMenuTarget
int selectedChar;
neutrino_locale_t name;
std::string nameString;
neutrino_locale_t hint_1;
neutrino_locale_t hint_2;
char* value;
CChangeObserver* observ;
bool* cancel;
@@ -76,7 +76,8 @@ class CExtendedInput : public CMenuTarget
public:
CExtendedInput(const neutrino_locale_t Name, char* Value, const neutrino_locale_t Hint_1, const neutrino_locale_t Hint_2, CChangeObserver* Observ = NULL, bool* cancel = NULL);
CExtendedInput(const neutrino_locale_t Name, std::string *Value, const neutrino_locale_t Hint_1 = NONEXISTANT_LOCALE, const neutrino_locale_t Hint_2 = NONEXISTANT_LOCALE, CChangeObserver* Observ = NULL, bool* cancel = NULL);
CExtendedInput(std::string &Name, std::string *Value, const neutrino_locale_t Hint_1 = NONEXISTANT_LOCALE, const neutrino_locale_t Hint_2 = NONEXISTANT_LOCALE, CChangeObserver* Observ = NULL, bool* cancel = NULL);
~CExtendedInput();
void hide();
@@ -155,22 +156,19 @@ class CExtendedInput_Item_Char : public CExtendedInput_Item
class CIPInput : public CExtendedInput
{
char IP[16];
std::string * ip;
protected:
virtual void onBeforeExec();
virtual void onAfterExec();
public:
CIPInput(const neutrino_locale_t Name, std::string & Value, const neutrino_locale_t Hint_1, const neutrino_locale_t Hint_2, CChangeObserver* Observ = NULL);
CIPInput(const neutrino_locale_t Name, std::string *Value, const neutrino_locale_t Hint_1 = NONEXISTANT_LOCALE, const neutrino_locale_t Hint_2 = NONEXISTANT_LOCALE, CChangeObserver* Observ = NULL);
};
//----------------------------------------------------------------------------------------------------
class CDateInput : public CExtendedInput
{
private:
private:
time_t* time;
protected:
@@ -178,23 +176,19 @@ class CDateInput : public CExtendedInput
virtual void onAfterExec();
public:
CDateInput(const neutrino_locale_t Name, time_t* Time, const neutrino_locale_t Hint_1, const neutrino_locale_t Hint_2, CChangeObserver* Observ = NULL);
~CDateInput();
CDateInput(const neutrino_locale_t Name, time_t* Time, const neutrino_locale_t Hint_1 = NONEXISTANT_LOCALE, const neutrino_locale_t Hint_2 = NONEXISTANT_LOCALE, CChangeObserver* Observ = NULL);
};
//----------------------------------------------------------------------------------------------------
class CMACInput : public CExtendedInput
{
char MAC[32];
std::string * mac;
protected:
virtual void onBeforeExec();
virtual void onAfterExec();
public:
CMACInput(const neutrino_locale_t Name, std::string & Value, const neutrino_locale_t Hint_1, const neutrino_locale_t Hint_2, CChangeObserver* Observ = NULL);
CMACInput(const neutrino_locale_t Name, std::string *Value, const neutrino_locale_t Hint_1 = NONEXISTANT_LOCALE, const neutrino_locale_t Hint_2 = NONEXISTANT_LOCALE, CChangeObserver* Observ = NULL);
};
//----------------------------------------------------------------------------------------------------
@@ -204,9 +198,8 @@ class CTimeInput : public CExtendedInput
protected:
virtual void onBeforeExec();
virtual void onAfterExec();
public:
CTimeInput(const neutrino_locale_t Name, char* Value, const neutrino_locale_t Hint_1, const neutrino_locale_t Hint_2, CChangeObserver* Observ = NULL, bool* cancel=NULL);
CTimeInput(const neutrino_locale_t Name, std::string *Value, const neutrino_locale_t Hint_1 = NONEXISTANT_LOCALE, const neutrino_locale_t Hint_2 = NONEXISTANT_LOCALE, CChangeObserver* Observ = NULL, bool* cancel=NULL);
};
//----------------------------------------------------------------------------------------------------
@@ -215,9 +208,6 @@ class CIntInput : public CExtendedInput
{
#define MAX_CINTINPUT_SIZE 16
char myValueStringInput[MAX_CINTINPUT_SIZE];
char myValueStringOutput[MAX_CINTINPUT_SIZE];
int* myValue;
unsigned int m_size;
protected:
@@ -228,7 +218,7 @@ class CIntInput : public CExtendedInput
/**
*@param Size how many digits can be entered
*/
CIntInput(const neutrino_locale_t Name, int& Value, const unsigned int Size, const neutrino_locale_t Hint_1, const neutrino_locale_t Hint_2, CChangeObserver* Observ = NULL);
CIntInput(const neutrino_locale_t Name, int *Value, const unsigned int Size, const neutrino_locale_t Hint_1 = NONEXISTANT_LOCALE, const neutrino_locale_t Hint_2 = NONEXISTANT_LOCALE, CChangeObserver* Observ = NULL);
void updateValue() { onBeforeExec(); }
};