From 3d8942af60734372283dd69f6181132c4f503611 Mon Sep 17 00:00:00 2001 From: Jaidyn Ann Date: Sat, 19 Jun 2021 00:11:02 -0500 Subject: [PATCH] When sending invites, filter the roster window --- application/windows/MainWindow.cpp | 6 ++++-- application/windows/RosterWindow.cpp | 25 ++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/application/windows/MainWindow.cpp b/application/windows/MainWindow.cpp index 7f63a63..8eab286 100644 --- a/application/windows/MainWindow.cpp +++ b/application/windows/MainWindow.cpp @@ -149,9 +149,11 @@ MainWindow::MessageReceived(BMessage* message) invite->AddInt32("im_what", IM_ROOM_SEND_INVITE); invite->AddString("chat_id", chat_id); - BLooper* looper = (BLooper*)fConversation->GetProtocolLooper(); + ProtocolLooper* plooper = fConversation->GetProtocolLooper(); + BLooper* looper = (BLooper*)plooper; fRosterWindow = new RosterWindow("Invite contact to chat" - B_UTF8_ELLIPSIS, invite, new BMessenger(looper), fServer); + B_UTF8_ELLIPSIS, invite, new BMessenger(looper), fServer, + plooper->GetInstance()); fRosterWindow->Show(); break; diff --git a/application/windows/RosterWindow.cpp b/application/windows/RosterWindow.cpp index 0b25646..39dd8f1 100644 --- a/application/windows/RosterWindow.cpp +++ b/application/windows/RosterWindow.cpp @@ -45,9 +45,28 @@ RosterWindow::RosterWindow(const char* title, BMessage* selectMsg, fRosterView->SetInvocationMessage(new BMessage(kSendMessage)); fOkButton = new BButton("OK", new BMessage(kSendMessage)); - fAccountField = new BMenuField("accountMenuField", NULL, - CreateAccountMenu(fAccounts, BMessage(kSelAccount), - new BMessage(kSelNoAccount))); + + BMenu* accountMenu; + + // If a specific instance is given, disallow selecting other accounts + if (instance > -1) { + accountMenu = new BMenu("accountMenu"); + BString name = "N/A"; + for (int i = 0; i < fAccounts.CountItems(); i++) + if (fAccounts.ValueAt(i) == instance) { + name = fAccounts.KeyAt(i); + break; + } + accountMenu->AddItem(new BMenuItem(name.String(), NULL)); + accountMenu->SetLabelFromMarked(true); + accountMenu->ItemAt(0)->SetMarked(true); + accountMenu->SetEnabled(false); + } + else + accountMenu = CreateAccountMenu(fAccounts, BMessage(kSelAccount), + new BMessage(kSelNoAccount)); + + fAccountField = new BMenuField("accountMenuField", NULL, accountMenu); BLayoutBuilder::Group<>(this, B_VERTICAL, 0.0f) .SetInsets(B_USE_DEFAULT_SPACING)