diff --git a/application/AppMessages.h b/application/AppMessages.h index 83d9196..4047c53 100644 --- a/application/AppMessages.h +++ b/application/AppMessages.h @@ -65,4 +65,7 @@ const uint32 APP_EDIT_ROSTER = 'CYer'; //! Edit a specific account const uint32 APP_EDIT_ACCOUNT = 'CYea'; +//! Toggle a specific account +const uint32 APP_TOGGLE_ACCOUNT = 'CYta'; + #endif // _APP_MESSAGES_H diff --git a/application/views/ConversationView.cpp b/application/views/ConversationView.cpp index 6f225a2..f650a61 100644 --- a/application/views/ConversationView.cpp +++ b/application/views/ConversationView.cpp @@ -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("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("body", B_TRANSLATE("It looks like you don't have any accounts set up.")); diff --git a/application/windows/AccountsWindow.cpp b/application/windows/AccountsWindow.cpp index 2067838..cfbf17d 100644 --- a/application/windows/AccountsWindow.cpp +++ b/application/windows/AccountsWindow.cpp @@ -110,6 +110,8 @@ AccountsWindow::AccountsWindow() .Add(fEditButton) .End() .End(); + + CenterOnScreen(); } diff --git a/application/windows/MainWindow.cpp b/application/windows/MainWindow.cpp index 9e3a5aa..78a4b43 100644 --- a/application/windows/MainWindow.cpp +++ b/application/windows/MainWindow.cpp @@ -123,16 +123,37 @@ MainWindow::MessageReceived(BMessage* message) case APP_EDIT_ACCOUNT: { void* settings = NULL; - BString account = message->FindString("name"); + BString account = message->FindString("account"); message->FindPointer("settings", &settings); - if (account.IsEmpty() != true || settings != NULL) { + if (account.IsEmpty() == false && settings != NULL) { AccountDialog* win = new AccountDialog("Editing account", (ProtocolSettings*)settings, account.String()); win->Show(); } 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: { BMessage* newMsg = new BMessage(IM_MESSAGE); @@ -519,14 +540,17 @@ MainWindow::_CreateAccountsMenu() BMenu* accountsMenu = new BMenu(B_TRANSLATE("Accounts")); ProtocolManager* pm = ProtocolManager::Get(); + bool hasAccounts = false; for (uint32 i = 0; i < pm->CountProtocolAddOns(); i++) { ChatProtocolAddOn* addOn = pm->ProtocolAddOnAt(i); ProtocolSettings* settings = new ProtocolSettings(addOn); - _PopulateWithAccounts(accountsMenu, settings); + if (_PopulateWithAccounts(accountsMenu, settings) == true) + hasAccounts = true; } - accountsMenu->AddSeparatorItem(); + if (hasAccounts == true) + accountsMenu->AddSeparatorItem(); accountsMenu->AddItem( new BMenuItem(B_TRANSLATE("Manage accounts" B_UTF8_ELLIPSIS), new BMessage(APP_SHOW_ACCOUNTS), '.', B_COMMAND_KEY)); @@ -595,11 +619,11 @@ MainWindow::_EnsureConversationItem(BMessage* msg) } -void +bool MainWindow::_PopulateWithAccounts(BMenu* menu, ProtocolSettings* settings) { if (!settings) - return; + return false; BObjectList accounts = settings->Accounts(); // Add accounts to menu @@ -607,15 +631,31 @@ MainWindow::_PopulateWithAccounts(BMenu* menu, ProtocolSettings* settings) BString* account = accounts.ItemAt(i); 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); editMsg->AddPointer("settings", settings); editMsg->AddString("account", *account); + accMenu->AddItem(new BMenuItem(toggleLabel.String(), toggleMsg)); + accMenu->AddItem( new BMenuItem(B_TRANSLATE("Modify account" B_UTF8_ELLIPSIS), editMsg)); + menu->AddItem(accMenu); } + return (accounts.CountItems() > 0); } diff --git a/application/windows/MainWindow.h b/application/windows/MainWindow.h index ca529b1..49c4b3a 100644 --- a/application/windows/MainWindow.h +++ b/application/windows/MainWindow.h @@ -58,7 +58,7 @@ private: ConversationItem* _EnsureConversationItem(BMessage* msg); - void _PopulateWithAccounts(BMenu* menu, + bool _PopulateWithAccounts(BMenu* menu, ProtocolSettings* settings); void _ReplaceMenu(const char* name, BMenu* newMenu);