2021-07-21 12:12:02 -05:00
|
|
|
/*
|
|
|
|
* Copyright 2021, Jaidyn Levesque <jadedctrl@teknik.io>
|
|
|
|
* All rights reserved. Distributed under the terms of the MIT license.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "AccountsMenu.h"
|
2021-07-24 21:11:34 -05:00
|
|
|
|
|
|
|
#include <Catalog.h>
|
|
|
|
#include <MenuItem.h>
|
|
|
|
|
2021-07-21 12:12:02 -05:00
|
|
|
#include "MainWindow.h"
|
|
|
|
#include "Server.h"
|
|
|
|
#include "TheApp.h"
|
|
|
|
|
2021-07-24 21:11:34 -05:00
|
|
|
|
|
|
|
#undef B_TRANSLATION_CONTEXT
|
|
|
|
#define B_TRANSLATION_CONTEXT "AccountsMenu"
|
2021-07-21 12:12:02 -05:00
|
|
|
|
|
|
|
|
|
|
|
AccountsMenu::AccountsMenu(const char* name, BMessage msg, BMessage* allMsg)
|
|
|
|
:
|
|
|
|
BMenu(name),
|
|
|
|
fAccountMessage(msg),
|
|
|
|
fAllMessage(allMsg)
|
|
|
|
{
|
|
|
|
_PopulateMenu();
|
|
|
|
|
|
|
|
SetRadioMode(true);
|
|
|
|
SetLabelFromMarked(true);
|
|
|
|
|
|
|
|
Server* server = ((TheApp*)be_app)->GetMainWindow()->GetServer();
|
|
|
|
server->RegisterObserver(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
AccountsMenu::~AccountsMenu()
|
|
|
|
{
|
|
|
|
delete fAllMessage;
|
|
|
|
Server* server = ((TheApp*)be_app)->GetMainWindow()->GetServer();
|
|
|
|
server->UnregisterObserver(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
AccountsMenu::ObserveInteger(int32 what, int32 value)
|
|
|
|
{
|
|
|
|
_PopulateMenu();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
AccountsMenu::_PopulateMenu()
|
|
|
|
{
|
|
|
|
if (CountItems() > 0)
|
|
|
|
RemoveItems(0, CountItems(), true);
|
|
|
|
|
|
|
|
if (fAllMessage != NULL)
|
2021-07-24 21:11:34 -05:00
|
|
|
AddItem(new BMenuItem(B_TRANSLATE("All"), new BMessage(*fAllMessage)));
|
2021-07-21 12:12:02 -05:00
|
|
|
|
|
|
|
Server* server = ((TheApp*)be_app)->GetMainWindow()->GetServer();
|
|
|
|
AccountInstances accounts = server->GetActiveAccounts();
|
|
|
|
|
2021-07-24 15:44:23 -05:00
|
|
|
for (int i = 0; i < accounts.CountItems(); i++) {
|
|
|
|
BString label = accounts.KeyAt(i).String();
|
|
|
|
if (label.CountChars() > 15) {
|
|
|
|
label.RemoveChars(16, label.CountChars() - 16);
|
|
|
|
label << B_UTF8_ELLIPSIS;
|
|
|
|
}
|
|
|
|
AddItem(new BMenuItem(label.String(), new BMessage(fAccountMessage)));
|
|
|
|
}
|
2021-07-21 12:12:02 -05:00
|
|
|
|
|
|
|
if (CountItems() > 0)
|
|
|
|
ItemAt(0)->SetMarked(true);
|
|
|
|
else
|
|
|
|
SetEnabled(false);
|
|
|
|
}
|