Add 'error' slot for templates
This commit is contained in:
parent
077a01e8bf
commit
4f8aaf7957
|
@ -85,16 +85,16 @@ ProtocolSettings::Load(const char* account, BView* parent)
|
|||
|
||||
|
||||
status_t
|
||||
ProtocolSettings::Save(const char* account, BView* parent)
|
||||
ProtocolSettings::Save(const char* account, BView* parent, BString* errorText)
|
||||
{
|
||||
if (!parent)
|
||||
debugger("Couldn't save protocol's settings GUI on a NULL parent!");
|
||||
|
||||
BMessage settings;
|
||||
status_t status = fTemplate.Save(parent, &settings);
|
||||
status_t status = fTemplate.Save(parent, &settings, errorText);
|
||||
|
||||
if (!account || status != B_OK)
|
||||
return B_BAD_VALUE;
|
||||
if (status != B_OK)
|
||||
return status;
|
||||
|
||||
status_t ret = B_ERROR;
|
||||
|
||||
|
|
|
@ -25,7 +25,8 @@ public:
|
|||
BObjectList<BString> Accounts() const;
|
||||
|
||||
status_t Load(const char* account, BView* parent);
|
||||
status_t Save(const char* account, BView* parent);
|
||||
status_t Save(const char* account, BView* parent,
|
||||
BString* errorText = NULL);
|
||||
|
||||
status_t Rename(const char* from, const char* to);
|
||||
status_t Delete(const char* account);
|
||||
|
|
|
@ -228,7 +228,7 @@ ProtocolTemplate::Load(BView* parent, BMessage* settings)
|
|||
|
||||
|
||||
status_t
|
||||
ProtocolTemplate::Save(BView* parent, BMessage* settings)
|
||||
ProtocolTemplate::Save(BView* parent, BMessage* settings, BString* errorText)
|
||||
{
|
||||
if (!parent)
|
||||
debugger("Couldn't save protocol's settings GUI on a NULL parent!");
|
||||
|
@ -236,6 +236,7 @@ ProtocolTemplate::Save(BView* parent, BMessage* settings)
|
|||
BMessage cur;
|
||||
for (int32 i = 0; fTemplate->FindMessage("setting", i, &cur) == B_OK; i++) {
|
||||
const char* name = cur.FindString("name");
|
||||
BString error = cur.FindString("error");
|
||||
|
||||
// Skip NULL names
|
||||
if (!name)
|
||||
|
@ -251,7 +252,13 @@ ProtocolTemplate::Save(BView* parent, BMessage* settings)
|
|||
|
||||
BTextControl* textControl
|
||||
= dynamic_cast<BTextControl*>(view);
|
||||
if (textControl) {
|
||||
|
||||
if (textControl && BString(textControl->Text()).IsEmpty() == true) {
|
||||
if (error.IsEmpty() == false && errorText != NULL)
|
||||
errorText->SetTo(error);
|
||||
return B_BAD_VALUE;
|
||||
}
|
||||
else if (textControl)
|
||||
switch (type) {
|
||||
case B_STRING_TYPE:
|
||||
settings->AddString(name, textControl->Text());
|
||||
|
@ -260,8 +267,7 @@ ProtocolTemplate::Save(BView* parent, BMessage* settings)
|
|||
settings->AddInt32(name, atoi(textControl->Text()));
|
||||
break;
|
||||
default:
|
||||
return B_ERROR;
|
||||
}
|
||||
return B_BAD_TYPE;
|
||||
}
|
||||
|
||||
BMenuField* menuField
|
||||
|
@ -279,7 +285,7 @@ ProtocolTemplate::Save(BView* parent, BMessage* settings)
|
|||
settings->AddInt32(name, atoi(item->Label()));
|
||||
break;
|
||||
default:
|
||||
return B_ERROR;
|
||||
return B_BAD_TYPE;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <SupportDefs.h>
|
||||
|
||||
class BMessage;
|
||||
class BString;
|
||||
class BView;
|
||||
class CayaProtocol;
|
||||
|
||||
|
@ -24,7 +25,8 @@ public:
|
|||
CayaProtocol* Protocol() const;
|
||||
|
||||
status_t Load(BView* parent, BMessage* settings = NULL);
|
||||
status_t Save(BView* parent, BMessage* settings);
|
||||
status_t Save(BView* parent, BMessage* settings,
|
||||
BString* errorText = NULL);
|
||||
|
||||
private:
|
||||
CayaProtocol* fProtocol;
|
||||
|
|
|
@ -98,7 +98,10 @@ AccountDialog::MessageReceived(BMessage* msg)
|
|||
}
|
||||
|
||||
// Save account settings
|
||||
if (fSettings->Save(fAccountName->Text(), fTop) == B_OK) {
|
||||
BString error = "An error has occured saving the settings.\n"
|
||||
"Check if your disk has enough space.";
|
||||
|
||||
if (fSettings->Save(fAccountName->Text(), fTop, &error) == B_OK) {
|
||||
if (fTarget && (adding || renaming)) {
|
||||
BMessage* saveMsg = new BMessage(renaming
|
||||
? kAccountRenamed : kAccountAdded);
|
||||
|
@ -113,12 +116,9 @@ AccountDialog::MessageReceived(BMessage* msg)
|
|||
|
||||
Close();
|
||||
} else {
|
||||
BAlert* alert = new BAlert("", "An error is occurred saving the settings.\n"
|
||||
"Check if your disk has enough space.", "OK", NULL, NULL, B_WIDTH_AS_USUAL,
|
||||
B_STOP_ALERT);
|
||||
BAlert* alert = new BAlert("", error.String(), "OK", NULL, NULL,
|
||||
B_WIDTH_AS_USUAL, B_STOP_ALERT);
|
||||
alert->Go();
|
||||
|
||||
Close();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -62,12 +62,14 @@ TemplateWindow::MessageReceived(BMessage* msg)
|
|||
if (fTemplate == NULL || fTemplateView == NULL)
|
||||
break;
|
||||
|
||||
BString error = "Some items are empty. Please make sure to fill "
|
||||
"out every item.";
|
||||
BMessage* settings = new BMessage(*fMessage);
|
||||
status_t result = fTemplate->Save(fTemplateView, settings);
|
||||
status_t result = fTemplate->Save(fTemplateView, settings, &error);
|
||||
|
||||
if (result != B_OK) {
|
||||
BAlert* alert = new BAlert("", "Invalid settings― make sure "
|
||||
"each item is filled out.\n", "OK", NULL, NULL);
|
||||
BAlert* alert = new BAlert("", error.String(), "OK", NULL, NULL,
|
||||
B_WIDTH_AS_USUAL, B_WARNING_ALERT);
|
||||
alert->Go();
|
||||
break;
|
||||
}
|
||||
|
@ -75,7 +77,6 @@ TemplateWindow::MessageReceived(BMessage* msg)
|
|||
= fServer->GetProtocolLooper(fAccounts.ValueAt(fSelectedAcc));
|
||||
if (looper == NULL)
|
||||
break;
|
||||
|
||||
looper->PostMessage(settings);
|
||||
Close();
|
||||
break;
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include "ProtocolTemplate.h"
|
||||
#include "Server.h"
|
||||
|
||||
class BAlert;
|
||||
class BMenu;
|
||||
class BMenuField;
|
||||
class BTextControl;
|
||||
|
|
|
@ -1142,12 +1142,16 @@ JabberHandler::_SettingsTemplate(const char* username, bool serverOption)
|
|||
BMessage usernameText;
|
||||
usernameText.AddString("name", "username");
|
||||
usernameText.AddString("description", username);
|
||||
usernameText.AddString("error", "You can't log into an account without a "
|
||||
"username.\nPlease fill in your username for the given server.");
|
||||
usernameText.AddInt32("type", 'CSTR');
|
||||
stemplate.AddMessage("setting", &usernameText);
|
||||
|
||||
BMessage passwordText;
|
||||
passwordText.AddString("name", "password");
|
||||
passwordText.AddString("description", "Password");
|
||||
passwordText.AddString("error", "You can't log into an account without a "
|
||||
"password.\nPlease fill in your password for the given account.");
|
||||
passwordText.AddInt32("type", 'CSTR');
|
||||
passwordText.AddBool("is_secret", true);
|
||||
stemplate.AddMessage("setting", &passwordText);
|
||||
|
@ -1155,6 +1159,8 @@ JabberHandler::_SettingsTemplate(const char* username, bool serverOption)
|
|||
BMessage serverText;
|
||||
serverText.AddString("name", "server");
|
||||
serverText.AddString("description", "Server");
|
||||
serverText.AddString("error", "You can't add an account without a server.\n"
|
||||
"Please add a valid XMPP server.");
|
||||
serverText.AddInt32("type", 'CSTR');
|
||||
if (serverOption == true)
|
||||
stemplate.AddMessage("setting", &serverText);
|
||||
|
@ -1164,6 +1170,8 @@ JabberHandler::_SettingsTemplate(const char* username, bool serverOption)
|
|||
resourceText.AddString("description", "Resource");
|
||||
resourceText.AddInt32("type", 'CSTR');
|
||||
resourceText.AddString("default", "Caya");
|
||||
resourceText.AddString("error", "You can't add an account without a "
|
||||
"resource.\nDon't worry― it can be whatever string you want.");
|
||||
stemplate.AddMessage("setting", &resourceText);
|
||||
|
||||
return stemplate;
|
||||
|
@ -1176,7 +1184,9 @@ JabberHandler::_RoomTemplate()
|
|||
BMessage stemplate('IMst');
|
||||
BMessage roomIdentifier;
|
||||
roomIdentifier.AddString("name", "chat_id");
|
||||
roomIdentifier.AddString("description", "JID");
|
||||
roomIdentifier.AddString("description", "Room identifier");
|
||||
roomIdentifier.AddString("error", "You can't create a room without a JID!\n"
|
||||
"Use the \"name@server\" format.");
|
||||
roomIdentifier.AddInt32("type", 'CSTR');
|
||||
stemplate.AddMessage("setting", &roomIdentifier);
|
||||
|
||||
|
|
Ŝarĝante…
Reference in New Issue