From 9581bd5691183bc9aca1f59fc80e656f1ff82239 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Thu, 30 Dec 2004 12:54:04 +0000 Subject: Fix for bug #1091801 (ALL: Possible to create corrupt config file) svn-id: r16379 --- gui/launcher.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'gui/launcher.cpp') diff --git a/gui/launcher.cpp b/gui/launcher.cpp index 5e9f9b3e08..e029dc4e8d 100644 --- a/gui/launcher.cpp +++ b/gui/launcher.cpp @@ -68,6 +68,27 @@ enum { kCmdSaveBrowser = 'PSAV' }; +/* + * TODO: Clean up this ugly design: we subclass EditTextWidget to perform + * input validation. It would be much more elegant to use a decorator pattern, + * or a validation callback, or something like that. + */ +class DomainEditTextWidget : public EditTextWidget { +public: + DomainEditTextWidget(GuiObject *boss, int x, int y, int w, int h, const String &text) + : EditTextWidget(boss, x, y, w, h, text) { + } + +protected: + bool tryInsertChar(char c, int pos) { + if (isalnum(c) || c == '-' || c == '_') { + _label.insertChar(c, pos); + return true; + } + return false; + } +}; + /* * A dialog that allows the user to edit a config game entry. * TODO: add widgets for some/all of the following @@ -96,7 +117,7 @@ public: protected: EditTextWidget *_descriptionWidget; - EditTextWidget *_domainWidget; + DomainEditTextWidget *_domainWidget; StaticTextWidget *_gamePathWidget; StaticTextWidget *_extraPathWidget; @@ -141,7 +162,7 @@ EditGameDialog::EditGameDialog(const String &domain, GameSettings target) // GUI: Label & edit widget for the game ID new StaticTextWidget(tab, x, yoffset + 2, labelWidth, kLineHeight, "ID: ", kTextAlignRight); - _domainWidget = new EditTextWidget(tab, x + labelWidth, yoffset, _w - labelWidth - 10, kLineHeight, _domain); + _domainWidget = new DomainEditTextWidget(tab, x + labelWidth, yoffset, _w - labelWidth - 10, kLineHeight, _domain); yoffset += 16; // GUI: Label & edit widget for the description -- cgit v1.2.3