Account-toggling through Accounts menu
This commit is contained in:
parent
abb4d44684
commit
4bd821eee5
|
@ -65,4 +65,7 @@ const uint32 APP_EDIT_ROSTER = 'CYer';
|
||||||
//! Edit a specific account
|
//! Edit a specific account
|
||||||
const uint32 APP_EDIT_ACCOUNT = 'CYea';
|
const uint32 APP_EDIT_ACCOUNT = 'CYea';
|
||||||
|
|
||||||
|
//! Toggle a specific account
|
||||||
|
const uint32 APP_TOGGLE_ACCOUNT = 'CYta';
|
||||||
|
|
||||||
#endif // _APP_MESSAGES_H
|
#endif // _APP_MESSAGES_H
|
||||||
|
|
|
@ -512,7 +512,7 @@ ConversationView::_FakeChatNoAccounts()
|
||||||
welcome.AddString("body", B_TRANSLATE("Afterward, you can join a room or start a chat through the Chat menu. :-)"));
|
welcome.AddString("body", B_TRANSLATE("Afterward, you can join a room or start a chat through the Chat menu. :-)"));
|
||||||
|
|
||||||
welcome.AddString("user_id", B_TRANSLATE("Master Foo"));
|
welcome.AddString("user_id", B_TRANSLATE("Master Foo"));
|
||||||
welcome.AddString("body", B_TRANSLATE("Add an account through the [Program→Preferences] menu to get started."));
|
welcome.AddString("body", B_TRANSLATE("Add an account through the [Accounts] menu to get started."));
|
||||||
|
|
||||||
welcome.AddString("user_id", B_TRANSLATE("Master Foo"));
|
welcome.AddString("user_id", B_TRANSLATE("Master Foo"));
|
||||||
welcome.AddString("body", B_TRANSLATE("It looks like you don't have any accounts set up."));
|
welcome.AddString("body", B_TRANSLATE("It looks like you don't have any accounts set up."));
|
||||||
|
|
|
@ -110,6 +110,8 @@ AccountsWindow::AccountsWindow()
|
||||||
.Add(fEditButton)
|
.Add(fEditButton)
|
||||||
.End()
|
.End()
|
||||||
.End();
|
.End();
|
||||||
|
|
||||||
|
CenterOnScreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -123,16 +123,37 @@ MainWindow::MessageReceived(BMessage* message)
|
||||||
case APP_EDIT_ACCOUNT:
|
case APP_EDIT_ACCOUNT:
|
||||||
{
|
{
|
||||||
void* settings = NULL;
|
void* settings = NULL;
|
||||||
BString account = message->FindString("name");
|
BString account = message->FindString("account");
|
||||||
message->FindPointer("settings", &settings);
|
message->FindPointer("settings", &settings);
|
||||||
|
|
||||||
if (account.IsEmpty() != true || settings != NULL) {
|
if (account.IsEmpty() == false && settings != NULL) {
|
||||||
AccountDialog* win = new AccountDialog("Editing account",
|
AccountDialog* win = new AccountDialog("Editing account",
|
||||||
(ProtocolSettings*)settings, account.String());
|
(ProtocolSettings*)settings, account.String());
|
||||||
win->Show();
|
win->Show();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case APP_TOGGLE_ACCOUNT:
|
||||||
|
{
|
||||||
|
ProtocolSettings* settings = NULL;
|
||||||
|
BString account = message->FindString("account");
|
||||||
|
int64 instance = message->GetInt64("instance", -1);
|
||||||
|
message->FindPointer("settings", (void**)&settings);
|
||||||
|
|
||||||
|
if (account.IsEmpty() == false && settings != NULL) {
|
||||||
|
// Enable
|
||||||
|
if (instance == -1)
|
||||||
|
ProtocolManager::Get()->AddAccount(settings->AddOn(),
|
||||||
|
account, this);
|
||||||
|
else {
|
||||||
|
BMessage remove(IM_MESSAGE);
|
||||||
|
remove.AddInt32("im_what", IM_PROTOCOL_DISABLE);
|
||||||
|
remove.AddInt64("instance", instance);
|
||||||
|
PostMessage(&remove);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
case APP_NEW_CHAT:
|
case APP_NEW_CHAT:
|
||||||
{
|
{
|
||||||
BMessage* newMsg = new BMessage(IM_MESSAGE);
|
BMessage* newMsg = new BMessage(IM_MESSAGE);
|
||||||
|
@ -519,14 +540,17 @@ MainWindow::_CreateAccountsMenu()
|
||||||
BMenu* accountsMenu = new BMenu(B_TRANSLATE("Accounts"));
|
BMenu* accountsMenu = new BMenu(B_TRANSLATE("Accounts"));
|
||||||
ProtocolManager* pm = ProtocolManager::Get();
|
ProtocolManager* pm = ProtocolManager::Get();
|
||||||
|
|
||||||
|
bool hasAccounts = false;
|
||||||
for (uint32 i = 0; i < pm->CountProtocolAddOns(); i++) {
|
for (uint32 i = 0; i < pm->CountProtocolAddOns(); i++) {
|
||||||
ChatProtocolAddOn* addOn = pm->ProtocolAddOnAt(i);
|
ChatProtocolAddOn* addOn = pm->ProtocolAddOnAt(i);
|
||||||
ProtocolSettings* settings = new ProtocolSettings(addOn);
|
ProtocolSettings* settings = new ProtocolSettings(addOn);
|
||||||
|
|
||||||
_PopulateWithAccounts(accountsMenu, settings);
|
if (_PopulateWithAccounts(accountsMenu, settings) == true)
|
||||||
|
hasAccounts = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
accountsMenu->AddSeparatorItem();
|
if (hasAccounts == true)
|
||||||
|
accountsMenu->AddSeparatorItem();
|
||||||
accountsMenu->AddItem(
|
accountsMenu->AddItem(
|
||||||
new BMenuItem(B_TRANSLATE("Manage accounts" B_UTF8_ELLIPSIS),
|
new BMenuItem(B_TRANSLATE("Manage accounts" B_UTF8_ELLIPSIS),
|
||||||
new BMessage(APP_SHOW_ACCOUNTS), '.', B_COMMAND_KEY));
|
new BMessage(APP_SHOW_ACCOUNTS), '.', B_COMMAND_KEY));
|
||||||
|
@ -595,11 +619,11 @@ MainWindow::_EnsureConversationItem(BMessage* msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
bool
|
||||||
MainWindow::_PopulateWithAccounts(BMenu* menu, ProtocolSettings* settings)
|
MainWindow::_PopulateWithAccounts(BMenu* menu, ProtocolSettings* settings)
|
||||||
{
|
{
|
||||||
if (!settings)
|
if (!settings)
|
||||||
return;
|
return false;
|
||||||
BObjectList<BString> accounts = settings->Accounts();
|
BObjectList<BString> accounts = settings->Accounts();
|
||||||
|
|
||||||
// Add accounts to menu
|
// Add accounts to menu
|
||||||
|
@ -607,15 +631,31 @@ MainWindow::_PopulateWithAccounts(BMenu* menu, ProtocolSettings* settings)
|
||||||
BString* account = accounts.ItemAt(i);
|
BString* account = accounts.ItemAt(i);
|
||||||
BMenu* accMenu = new BMenu(account->String());
|
BMenu* accMenu = new BMenu(account->String());
|
||||||
|
|
||||||
|
BString toggleLabel = B_TRANSLATE("Enable");
|
||||||
|
bool isActive = false;
|
||||||
|
int64 instance = fServer->GetActiveAccounts().ValueFor(*account, &isActive);
|
||||||
|
if (isActive == true)
|
||||||
|
toggleLabel = B_TRANSLATE("Disable");
|
||||||
|
|
||||||
|
BMessage* toggleMsg = new BMessage(APP_TOGGLE_ACCOUNT);
|
||||||
|
toggleMsg->AddPointer("settings", settings);
|
||||||
|
toggleMsg->AddString("account", *account);
|
||||||
|
if (isActive == true)
|
||||||
|
toggleMsg->AddInt64("instance", instance);
|
||||||
|
|
||||||
BMessage* editMsg = new BMessage(APP_EDIT_ACCOUNT);
|
BMessage* editMsg = new BMessage(APP_EDIT_ACCOUNT);
|
||||||
editMsg->AddPointer("settings", settings);
|
editMsg->AddPointer("settings", settings);
|
||||||
editMsg->AddString("account", *account);
|
editMsg->AddString("account", *account);
|
||||||
|
|
||||||
|
accMenu->AddItem(new BMenuItem(toggleLabel.String(), toggleMsg));
|
||||||
|
|
||||||
accMenu->AddItem(
|
accMenu->AddItem(
|
||||||
new BMenuItem(B_TRANSLATE("Modify account" B_UTF8_ELLIPSIS),
|
new BMenuItem(B_TRANSLATE("Modify account" B_UTF8_ELLIPSIS),
|
||||||
editMsg));
|
editMsg));
|
||||||
|
|
||||||
menu->AddItem(accMenu);
|
menu->AddItem(accMenu);
|
||||||
}
|
}
|
||||||
|
return (accounts.CountItems() > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,7 @@ private:
|
||||||
ConversationItem*
|
ConversationItem*
|
||||||
_EnsureConversationItem(BMessage* msg);
|
_EnsureConversationItem(BMessage* msg);
|
||||||
|
|
||||||
void _PopulateWithAccounts(BMenu* menu,
|
bool _PopulateWithAccounts(BMenu* menu,
|
||||||
ProtocolSettings* settings);
|
ProtocolSettings* settings);
|
||||||
void _ReplaceMenu(const char* name, BMenu* newMenu);
|
void _ReplaceMenu(const char* name, BMenu* newMenu);
|
||||||
|
|
||||||
|
|
Ŝarĝante…
Reference in New Issue