Populate 'Accounts' menu with account submenus
This commit is contained in:
parent
2e746a975a
commit
abb4d44684
|
@ -62,4 +62,7 @@ const uint32 APP_ROOM_INFO = 'CYrw';
|
|||
//! Edit the contact roster
|
||||
const uint32 APP_EDIT_ROSTER = 'CYer';
|
||||
|
||||
//! Edit a specific account
|
||||
const uint32 APP_EDIT_ACCOUNT = 'CYea';
|
||||
|
||||
#endif // _APP_MESSAGES_H
|
||||
|
|
|
@ -17,11 +17,13 @@
|
|||
#include <MenuBar.h>
|
||||
#include <TranslationUtils.h>
|
||||
|
||||
#include "AccountDialog.h"
|
||||
#include "AccountManager.h"
|
||||
#include "AccountsWindow.h"
|
||||
#include "AppMessages.h"
|
||||
#include "AppPreferences.h"
|
||||
#include "Cardie.h"
|
||||
#include "ChatProtocolAddOn.h"
|
||||
#include "ChatProtocolMessages.h"
|
||||
#include "ConversationItem.h"
|
||||
#include "ConversationListView.h"
|
||||
|
@ -29,10 +31,11 @@
|
|||
#include "MainWindow.h"
|
||||
#include "NotifyMessage.h"
|
||||
#include "PreferencesWindow.h"
|
||||
#include "ProtocolManager.h"
|
||||
#include "ProtocolSettings.h"
|
||||
#include "ReplicantStatusView.h"
|
||||
#include "RosterEditWindow.h"
|
||||
#include "RosterWindow.h"
|
||||
#include "Server.h"
|
||||
#include "StatusView.h"
|
||||
#include "TemplateWindow.h"
|
||||
|
||||
|
@ -117,6 +120,19 @@ MainWindow::MessageReceived(BMessage* message)
|
|||
win->Show();
|
||||
break;
|
||||
}
|
||||
case APP_EDIT_ACCOUNT:
|
||||
{
|
||||
void* settings = NULL;
|
||||
BString account = message->FindString("name");
|
||||
message->FindPointer("settings", &settings);
|
||||
|
||||
if (account.IsEmpty() != true || settings != NULL) {
|
||||
AccountDialog* win = new AccountDialog("Editing account",
|
||||
(ProtocolSettings*)settings, account.String());
|
||||
win->Show();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case APP_NEW_CHAT:
|
||||
{
|
||||
BMessage* newMsg = new BMessage(IM_MESSAGE);
|
||||
|
@ -218,9 +234,11 @@ MainWindow::MessageReceived(BMessage* message)
|
|||
}
|
||||
break;
|
||||
}
|
||||
case APP_ACCOUNT_DISABLED:
|
||||
case APP_ACCOUNT_DISABLED: {
|
||||
_ToggleMenuItems();
|
||||
_RefreshAccountsMenu();
|
||||
break;
|
||||
}
|
||||
case IM_MESSAGE:
|
||||
ImMessage(message);
|
||||
break;
|
||||
|
@ -283,8 +301,9 @@ MainWindow::ImMessage(BMessage* msg)
|
|||
case IM_PROTOCOL_READY: {
|
||||
if (fConversation == NULL)
|
||||
fChatView->MessageReceived(msg);
|
||||
_ToggleMenuItems();
|
||||
fStatusView->MessageReceived(msg);
|
||||
_ToggleMenuItems();
|
||||
_RefreshAccountsMenu();
|
||||
break;
|
||||
}
|
||||
case IM_PROTOCOL_DISABLE:
|
||||
|
@ -456,13 +475,6 @@ MainWindow::_CreateMenuBar()
|
|||
new BMessage(B_QUIT_REQUESTED), 'Q', B_COMMAND_KEY));
|
||||
programMenu->SetTargetForItems(this);
|
||||
|
||||
// Accounts
|
||||
BMenu* accountsMenu = new BMenu(B_TRANSLATE("Accounts"));
|
||||
accountsMenu->AddItem(
|
||||
new BMenuItem(B_TRANSLATE("Manage accounts" B_UTF8_ELLIPSIS),
|
||||
new BMessage(APP_SHOW_ACCOUNTS), '.', B_COMMAND_KEY));
|
||||
accountsMenu->SetTargetForItems(this);
|
||||
|
||||
// Chat
|
||||
BMenu* chatMenu = new BMenu(B_TRANSLATE("Chat"));
|
||||
chatMenu->AddItem(new BMenuItem(B_TRANSLATE("Join room" B_UTF8_ELLIPSIS),
|
||||
|
@ -492,7 +504,7 @@ MainWindow::_CreateMenuBar()
|
|||
windowMenu->SetTargetForItems(this);
|
||||
|
||||
menuBar->AddItem(programMenu);
|
||||
menuBar->AddItem(accountsMenu);
|
||||
menuBar->AddItem(_CreateAccountsMenu());
|
||||
menuBar->AddItem(chatMenu);
|
||||
menuBar->AddItem(rosterMenu);
|
||||
menuBar->AddItem(windowMenu);
|
||||
|
@ -501,6 +513,35 @@ MainWindow::_CreateMenuBar()
|
|||
}
|
||||
|
||||
|
||||
BMenu*
|
||||
MainWindow::_CreateAccountsMenu()
|
||||
{
|
||||
BMenu* accountsMenu = new BMenu(B_TRANSLATE("Accounts"));
|
||||
ProtocolManager* pm = ProtocolManager::Get();
|
||||
|
||||
for (uint32 i = 0; i < pm->CountProtocolAddOns(); i++) {
|
||||
ChatProtocolAddOn* addOn = pm->ProtocolAddOnAt(i);
|
||||
ProtocolSettings* settings = new ProtocolSettings(addOn);
|
||||
|
||||
_PopulateWithAccounts(accountsMenu, settings);
|
||||
}
|
||||
|
||||
accountsMenu->AddSeparatorItem();
|
||||
accountsMenu->AddItem(
|
||||
new BMenuItem(B_TRANSLATE("Manage accounts" B_UTF8_ELLIPSIS),
|
||||
new BMessage(APP_SHOW_ACCOUNTS), '.', B_COMMAND_KEY));
|
||||
accountsMenu->SetTargetForItems(this);
|
||||
return accountsMenu;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MainWindow::_RefreshAccountsMenu()
|
||||
{
|
||||
_ReplaceMenu(B_TRANSLATE("Accounts"), _CreateAccountsMenu());
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MainWindow::_ToggleMenuItems()
|
||||
{
|
||||
|
@ -550,6 +591,41 @@ MainWindow::_EnsureConversationItem(BMessage* msg)
|
|||
fListView->SelectConversation(0);
|
||||
return item;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MainWindow::_PopulateWithAccounts(BMenu* menu, ProtocolSettings* settings)
|
||||
{
|
||||
if (!settings)
|
||||
return;
|
||||
BObjectList<BString> accounts = settings->Accounts();
|
||||
|
||||
// Add accounts to menu
|
||||
for (int32 i = 0; i < accounts.CountItems(); i++) {
|
||||
BString* account = accounts.ItemAt(i);
|
||||
BMenu* accMenu = new BMenu(account->String());
|
||||
|
||||
BMessage* editMsg = new BMessage(APP_EDIT_ACCOUNT);
|
||||
editMsg->AddPointer("settings", settings);
|
||||
editMsg->AddString("account", *account);
|
||||
|
||||
accMenu->AddItem(
|
||||
new BMenuItem(B_TRANSLATE("Modify account" B_UTF8_ELLIPSIS),
|
||||
editMsg));
|
||||
menu->AddItem(accMenu);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MainWindow::_ReplaceMenu(const char* name, BMenu* newMenu)
|
||||
{
|
||||
BMenuItem* old = fMenuBar->FindItem(name);
|
||||
if (old == NULL || newMenu == NULL)
|
||||
return;
|
||||
int32 index = fMenuBar->IndexOf(old);
|
||||
fMenuBar->RemoveItem(index);
|
||||
fMenuBar->AddItem(newMenu, index);
|
||||
}
|
||||
|
|
|
@ -9,6 +9,9 @@
|
|||
|
||||
#include <Window.h>
|
||||
|
||||
#include "Server.h"
|
||||
|
||||
class BMenu;
|
||||
class BSplitView;
|
||||
class BTextView;
|
||||
|
||||
|
@ -16,6 +19,7 @@ class Conversation;
|
|||
class ConversationItem;
|
||||
class ConversationListView;
|
||||
class ConversationView;
|
||||
class ProtocolSettings;
|
||||
class RosterItem;
|
||||
class RosterEditWindow;
|
||||
class RosterWindow;
|
||||
|
@ -44,11 +48,19 @@ public:
|
|||
|
||||
private:
|
||||
void _InitInterface();
|
||||
|
||||
BMenuBar* _CreateMenuBar();
|
||||
BMenu* _CreateAccountsMenu();
|
||||
void _RefreshAccountsMenu();
|
||||
|
||||
void _ToggleMenuItems();
|
||||
|
||||
ConversationItem*
|
||||
_EnsureConversationItem(BMessage* msg);
|
||||
|
||||
void _PopulateWithAccounts(BMenu* menu,
|
||||
ProtocolSettings* settings);
|
||||
void _ReplaceMenu(const char* name, BMenu* newMenu);
|
||||
|
||||
Server* fServer;
|
||||
RosterWindow* fRosterWindow;
|
||||
|
|
Ŝarĝante…
Reference in New Issue