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