Make TemplateWindow use instance rather than index

This commit is contained in:
Jaidyn Ann 2021-08-06 11:10:05 -05:00
parent 39e4fc9ac7
commit a9022755ca
2 changed files with 16 additions and 17 deletions

View File

@ -38,7 +38,7 @@ TemplateWindow::TemplateWindow(const char* title, const char* templateType,
BWindow(BRect(0, 0, 400, 100), title, B_FLOATING_WINDOW, BWindow(BRect(0, 0, 400, 100), title, B_FLOATING_WINDOW,
B_NOT_RESIZABLE | B_AUTO_UPDATE_SIZE_LIMITS | B_CLOSE_ON_ESCAPE), B_NOT_RESIZABLE | B_AUTO_UPDATE_SIZE_LIMITS | B_CLOSE_ON_ESCAPE),
fServer(server), fServer(server),
fSelectedAcc(0), fSelectedAcc(-1),
fTemplate(NULL), fTemplate(NULL),
fTemplateType(templateType), fTemplateType(templateType),
fMessage(msg), fMessage(msg),
@ -56,7 +56,7 @@ TemplateWindow::TemplateWindow(const char* title, ProtocolTemplate* temp,
BWindow(BRect(0, 0, 400, 100), title, B_FLOATING_WINDOW, BWindow(BRect(0, 0, 400, 100), title, B_FLOATING_WINDOW,
B_NOT_RESIZABLE | B_AUTO_UPDATE_SIZE_LIMITS | B_CLOSE_ON_ESCAPE), B_NOT_RESIZABLE | B_AUTO_UPDATE_SIZE_LIMITS | B_CLOSE_ON_ESCAPE),
fServer(server), fServer(server),
fSelectedAcc(0), fSelectedAcc(-1),
fTemplate(temp), fTemplate(temp),
fMessage(msg) fMessage(msg)
{ {
@ -99,10 +99,7 @@ TemplateWindow::MessageReceived(BMessage* msg)
break; break;
} }
AccountInstances accounts = fServer->GetActiveAccounts(); ProtocolLooper* looper = fServer->GetProtocolLooper(fSelectedAcc);
ProtocolLooper* looper
= fServer->GetProtocolLooper(accounts.ValueAt(fSelectedAcc));
if (looper == NULL) if (looper == NULL)
break; break;
looper->PostMessage(settings); looper->PostMessage(settings);
@ -111,9 +108,9 @@ TemplateWindow::MessageReceived(BMessage* msg)
} }
case kAccSelected: case kAccSelected:
{ {
int32 index; int64 instance;
if (msg->FindInt32("index", &index) == B_OK) if (msg->FindInt64("instance", &instance) == B_OK)
fSelectedAcc = index; fSelectedAcc = instance;
_LoadTemplate(); _LoadTemplate();
break; break;
} }
@ -152,9 +149,13 @@ TemplateWindow::_InitInterface(bigtime_t instance)
fMenuField = new BMenuField("accountMenuField", NULL, accountMenu); fMenuField = new BMenuField("accountMenuField", NULL, accountMenu);
} }
else else {
fMenuField = new BMenuField("accountMenuField", NULL, AccountsMenu* accountMenu = new AccountsMenu("accountMenu",
new AccountsMenu("accountMenu", BMessage(kAccSelected))); BMessage(kAccSelected));
fMenuField = new BMenuField("accountMenuField", NULL, accountMenu);
fSelectedAcc = accountMenu->GetDefaultSelection();
}
BButton* fOkButton = new BButton(B_TRANSLATE("OK"), new BMessage(kOK)); BButton* fOkButton = new BButton(B_TRANSLATE("OK"), new BMessage(kOK));
if (accounts.CountItems() <= 0) if (accounts.CountItems() <= 0)
@ -181,12 +182,10 @@ TemplateWindow::_InitInterface(bigtime_t instance)
void void
TemplateWindow::_LoadTemplate() TemplateWindow::_LoadTemplate()
{ {
AccountInstances accounts = fServer->GetActiveAccounts(); if (fTemplateType.IsEmpty() == true)
if (accounts.CountItems() == 0 || fTemplateType.IsEmpty() == true)
return; return;
ProtocolLooper* looper ProtocolLooper* looper = fServer->GetProtocolLooper(fSelectedAcc);
= fServer->GetProtocolLooper(accounts.ValueAt(fSelectedAcc));
if (looper == NULL) if (looper == NULL)
return; return;

View File

@ -42,7 +42,7 @@ private:
void _LoadTemplate(); void _LoadTemplate();
Server* fServer; Server* fServer;
int32 fSelectedAcc; int64 fSelectedAcc;
BMenuField* fMenuField; BMenuField* fMenuField;
ProtocolTemplate* fTemplate; ProtocolTemplate* fTemplate;