From 8dc96ec83060a8a21d5178183165fb47aee402d3 Mon Sep 17 00:00:00 2001 From: Thilo Graf Date: Tue, 27 Dec 2016 18:25:43 +0100 Subject: [PATCH] CStringInput: unify init handler inside constructors, fix message title Alternative solution for: remove possible display of NONEXISTANT_LOCALE 4e853d98c2b2b289f0dce1c7dc9fed53eb317ce1 Locales are used for setting keys and passed with notifies for observer objects. It seems this is not really a good idea in some constellations. --- src/gui/widget/stringinput.cpp | 48 ++++++++++++++-------------------- src/gui/widget/stringinput.h | 2 +- 2 files changed, 20 insertions(+), 30 deletions(-) diff --git a/src/gui/widget/stringinput.cpp b/src/gui/widget/stringinput.cpp index 8d6d5e5ff..f325cedb1 100644 --- a/src/gui/widget/stringinput.cpp +++ b/src/gui/widget/stringinput.cpp @@ -47,38 +47,14 @@ 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 = g_Locale->getText(Name); - valueString = Value; - 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(); + name = Name; + init(g_Locale->getText(name), Value, Size, Hint_1, Hint_2, Valid_Chars, Observ, 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) { name = NONEXISTANT_LOCALE; - head = Name; - valueString = Value; - 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(); + init(Name, Value, Size, Hint_1, Hint_2, Valid_Chars, Observ, Icon); } CStringInput::~CStringInput() @@ -99,10 +75,23 @@ const struct button_label CStringInputSMSButtons[CStringInputSMSButtonsCount] = { NEUTRINO_ICON_BUTTON_YELLOW, LOCALE_STRINGINPUT_CLEAR } }; -void CStringInput::init() +void CStringInput::init(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) { frameBuffer = CFrameBuffer::getInstance(); + head = Name; + valueString = Value; + lower_bound = -1; + upper_bound = -1; + size = Size; + + hint_1 = Hint_1; + hint_2 = Hint_2; + validchars = Valid_Chars; + iconfile = Icon ? Icon : ""; + + observ = Observ; + #ifdef DEBUG_STRINGINPUT printf("HEAD: %s (len: %d)\n", head, strlen(head)); #endif @@ -496,8 +485,9 @@ int CStringInput::exec( CMenuTarget* parent, const std::string & ) } else if ( (msg==CRCInput::RC_home) || (msg==CRCInput::RC_timeout) ) { + string tmp_name = name == NONEXISTANT_LOCALE ? head : g_Locale->getText(name); if ((trim (*valueString) != trim(oldval)) && - (ShowMsg(name, LOCALE_MESSAGEBOX_DISCARD, CMsgBox::mbrYes, CMsgBox::mbYes | CMsgBox::mbCancel) == CMsgBox::mbrCancel)) { + (ShowMsg(tmp_name, LOCALE_MESSAGEBOX_DISCARD, CMsgBox::mbrYes, CMsgBox::mbYes | CMsgBox::mbCancel) == CMsgBox::mbrCancel)) { timeoutEnd = CRCInput::calcTimeoutEnd(g_settings.timing[SNeutrinoSettings::TIMING_MENU] == 0 ? 0xFFFF : g_settings.timing[SNeutrinoSettings::TIMING_MENU]); continue; } diff --git a/src/gui/widget/stringinput.h b/src/gui/widget/stringinput.h index d435a7f84..b01d65c09 100644 --- a/src/gui/widget/stringinput.h +++ b/src/gui/widget/stringinput.h @@ -64,7 +64,7 @@ class CStringInput : public CMenuTarget bool force_saveScreen; fb_pixel_t *pixBuf; - virtual void init(); + virtual void init(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); virtual void paint(bool sms = false); virtual void paintChar(int pos, char c);