HaikuDepot: Limit language selection for account creation
For the time being, there is a limited amount of supported languages when creating accounts, reflect this in the UI and use a BMenuField. Creating accounts with other languages fails, the error reporting was not ideal and could be improved. The server responded with "object not found", which was reported in the alert, but the response actually contains the object which was not found (NaturalLanguageCode).
This commit is contained in:
@@ -15,6 +15,8 @@
|
|||||||
#include <Catalog.h>
|
#include <Catalog.h>
|
||||||
#include <Button.h>
|
#include <Button.h>
|
||||||
#include <LayoutBuilder.h>
|
#include <LayoutBuilder.h>
|
||||||
|
#include <MenuField.h>
|
||||||
|
#include <PopUpMenu.h>
|
||||||
#include <TabView.h>
|
#include <TabView.h>
|
||||||
#include <TextControl.h>
|
#include <TextControl.h>
|
||||||
|
|
||||||
@@ -31,6 +33,7 @@ enum {
|
|||||||
MSG_SEND = 'send',
|
MSG_SEND = 'send',
|
||||||
MSG_TAB_SELECTED = 'tbsl',
|
MSG_TAB_SELECTED = 'tbsl',
|
||||||
MSG_CAPTCHA_OBTAINED = 'cpob',
|
MSG_CAPTCHA_OBTAINED = 'cpob',
|
||||||
|
MSG_LANGUAGE_SELECTED = 'lngs',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -59,12 +62,26 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
add_languages_to_menu(const StringList& languages, BMenu* menu)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < languages.CountItems(); i++) {
|
||||||
|
const BString& language = languages.ItemAtFast(i);
|
||||||
|
BMessage* message = new BMessage(MSG_LANGUAGE_SELECTED);
|
||||||
|
message->AddString("code", language);
|
||||||
|
BMenuItem* item = new BMenuItem(language, message);
|
||||||
|
menu->AddItem(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
UserLoginWindow::UserLoginWindow(BWindow* parent, BRect frame, Model& model)
|
UserLoginWindow::UserLoginWindow(BWindow* parent, BRect frame, Model& model)
|
||||||
:
|
:
|
||||||
BWindow(frame, B_TRANSLATE_SYSTEM_NAME("Log in"),
|
BWindow(frame, B_TRANSLATE_SYSTEM_NAME("Log in"),
|
||||||
B_FLOATING_WINDOW_LOOK, B_FLOATING_SUBSET_WINDOW_FEEL,
|
B_FLOATING_WINDOW_LOOK, B_FLOATING_SUBSET_WINDOW_FEEL,
|
||||||
B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS
|
B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS
|
||||||
| B_NOT_RESIZABLE | B_NOT_ZOOMABLE),
|
| B_NOT_RESIZABLE | B_NOT_ZOOMABLE),
|
||||||
|
fPreferredLanguage(model.PreferredLanguage()),
|
||||||
fModel(model),
|
fModel(model),
|
||||||
fMode(NONE),
|
fMode(NONE),
|
||||||
fWorkerThread(-1)
|
fWorkerThread(-1)
|
||||||
@@ -73,14 +90,30 @@ UserLoginWindow::UserLoginWindow(BWindow* parent, BRect frame, Model& model)
|
|||||||
|
|
||||||
fUsernameField = new BTextControl(B_TRANSLATE("User name:"), "", NULL);
|
fUsernameField = new BTextControl(B_TRANSLATE("User name:"), "", NULL);
|
||||||
fPasswordField = new BTextControl(B_TRANSLATE("Pass phrase:"), "", NULL);
|
fPasswordField = new BTextControl(B_TRANSLATE("Pass phrase:"), "", NULL);
|
||||||
|
fPasswordField->TextView()->HideTyping(true);
|
||||||
|
|
||||||
fNewUsernameField = new BTextControl(B_TRANSLATE("User name:"), "", NULL);
|
fNewUsernameField = new BTextControl(B_TRANSLATE("User name:"), "", NULL);
|
||||||
fNewPasswordField = new BTextControl(B_TRANSLATE("Pass phrase:"), "",
|
fNewPasswordField = new BTextControl(B_TRANSLATE("Pass phrase:"), "",
|
||||||
NULL);
|
NULL);
|
||||||
|
fNewPasswordField->TextView()->HideTyping(true);
|
||||||
fRepeatPasswordField = new BTextControl(B_TRANSLATE("Repeat pass phrase:"),
|
fRepeatPasswordField = new BTextControl(B_TRANSLATE("Repeat pass phrase:"),
|
||||||
"", NULL);
|
"", NULL);
|
||||||
fLanguageCodeField = new BTextControl(B_TRANSLATE("Language code:"),
|
fRepeatPasswordField->TextView()->HideTyping(true);
|
||||||
model.PreferredLanguage(), NULL);
|
|
||||||
|
// Construct languages popup
|
||||||
|
BPopUpMenu* languagesMenu = new BPopUpMenu(B_TRANSLATE("Language"));
|
||||||
|
fLanguageCodeField = new BMenuField("language",
|
||||||
|
B_TRANSLATE("Preferred language:"), languagesMenu);
|
||||||
|
|
||||||
|
add_languages_to_menu(fModel.SupportedLanguages(), languagesMenu);
|
||||||
|
languagesMenu->SetTargetForItems(this);
|
||||||
|
|
||||||
|
BMenuItem* defaultItem = languagesMenu->ItemAt(
|
||||||
|
fModel.SupportedLanguages().IndexOf(fPreferredLanguage));
|
||||||
|
if (defaultItem != NULL)
|
||||||
|
defaultItem->SetMarked(true);
|
||||||
|
|
||||||
|
|
||||||
fEmailField = new BTextControl(B_TRANSLATE("Email address:"), "", NULL);
|
fEmailField = new BTextControl(B_TRANSLATE("Email address:"), "", NULL);
|
||||||
fCaptchaView = new BitmapView("captcha view");
|
fCaptchaView = new BitmapView("captcha view");
|
||||||
fCaptchaResultField = new BTextControl("", "", NULL);
|
fCaptchaResultField = new BTextControl("", "", NULL);
|
||||||
@@ -104,7 +137,7 @@ UserLoginWindow::UserLoginWindow(BWindow* parent, BRect frame, Model& model)
|
|||||||
.AddTextControl(fNewPasswordField, 0, 1)
|
.AddTextControl(fNewPasswordField, 0, 1)
|
||||||
.AddTextControl(fRepeatPasswordField, 0, 2)
|
.AddTextControl(fRepeatPasswordField, 0, 2)
|
||||||
.AddTextControl(fEmailField, 0, 3)
|
.AddTextControl(fEmailField, 0, 3)
|
||||||
.AddTextControl(fLanguageCodeField, 0, 4)
|
.AddMenuField(fLanguageCodeField, 0, 4)
|
||||||
.Add(fCaptchaView, 0, 5)
|
.Add(fCaptchaView, 0, 5)
|
||||||
.Add(fCaptchaResultField, 1, 5)
|
.Add(fCaptchaResultField, 1, 5)
|
||||||
|
|
||||||
@@ -190,6 +223,10 @@ UserLoginWindow::MessageReceived(BMessage* message)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case MSG_LANGUAGE_SELECTED:
|
||||||
|
message->FindString("code", &fPreferredLanguage);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
BWindow::MessageReceived(message);
|
BWindow::MessageReceived(message);
|
||||||
break;
|
break;
|
||||||
@@ -448,7 +485,7 @@ UserLoginWindow::_CreateAccountThread()
|
|||||||
BString email(fEmailField->Text());
|
BString email(fEmailField->Text());
|
||||||
BString captchaToken(fCaptchaToken);
|
BString captchaToken(fCaptchaToken);
|
||||||
BString captchaResponse(fCaptchaResultField->Text());
|
BString captchaResponse(fCaptchaResultField->Text());
|
||||||
BString languageCode(fLanguageCodeField->Text());
|
BString languageCode(fPreferredLanguage);
|
||||||
|
|
||||||
Unlock();
|
Unlock();
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
|
|
||||||
class BButton;
|
class BButton;
|
||||||
|
class BMenuField;
|
||||||
class BTabView;
|
class BTabView;
|
||||||
class BTextControl;
|
class BTextControl;
|
||||||
class BitmapView;
|
class BitmapView;
|
||||||
@@ -63,7 +64,7 @@ private:
|
|||||||
BTextControl* fNewPasswordField;
|
BTextControl* fNewPasswordField;
|
||||||
BTextControl* fRepeatPasswordField;
|
BTextControl* fRepeatPasswordField;
|
||||||
BTextControl* fEmailField;
|
BTextControl* fEmailField;
|
||||||
BTextControl* fLanguageCodeField;
|
BMenuField* fLanguageCodeField;
|
||||||
BitmapView* fCaptchaView;
|
BitmapView* fCaptchaView;
|
||||||
BTextControl* fCaptchaResultField;
|
BTextControl* fCaptchaResultField;
|
||||||
|
|
||||||
@@ -72,6 +73,7 @@ private:
|
|||||||
|
|
||||||
BString fCaptchaToken;
|
BString fCaptchaToken;
|
||||||
BitmapRef fCaptchaImage;
|
BitmapRef fCaptchaImage;
|
||||||
|
BString fPreferredLanguage;
|
||||||
|
|
||||||
Model& fModel;
|
Model& fModel;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user