Sorting of RosterWindow by accounts

This commit is contained in:
Jaidyn Ann 2021-06-18 18:42:10 -05:00
parent 9d72c53dd9
commit fdeb533d6e
6 changed files with 72 additions and 36 deletions

View File

@ -11,6 +11,8 @@
#include <Directory.h>
#include <FindDirectory.h>
#include <IconUtils.h>
#include <Menu.h>
#include <MenuItem.h>
#include <Path.h>
#include <StringList.h>
@ -88,6 +90,26 @@ CayaResources()
}
BMenu*
CreateAccountMenu(AccountInstances accounts, BMessage msg, BMessage* allMsg)
{
BMenu* menu = new BMenu("accountMenu");
if (allMsg != NULL)
menu->AddItem(new BMenuItem("All", new BMessage(*allMsg)));
for (int i = 0; i < accounts.CountItems(); i++)
menu->AddItem(new BMenuItem(accounts.KeyAt(i).String(), new BMessage(msg)));
menu->SetRadioMode(true);
menu->SetLabelFromMarked(true);
menu->ItemAt(0)->SetMarked(true);
if (accounts.CountItems() == 0)
menu->SetEnabled(false);
return menu;
}
const char*
CayaAccountsPath()
{

View File

@ -14,6 +14,10 @@
#include <Resources.h>
#include "CayaConstants.h"
#include "Server.h"
class BMenu;
const char* CayaStatusToString(CayaStatus status);
@ -23,6 +27,9 @@ BString CommandArgs(BString line);
BResources* CayaResources();
BMenu* CreateAccountMenu(AccountInstances accounts, BMessage msg,
BMessage* allMsg = NULL);
const char* CayaAccountsPath();
const char* CayaAccountPath(const char* signature);
const char* CayaAccountPath(const char* signature, const char* subsignature);

View File

@ -12,6 +12,7 @@
#include <StringView.h>
#include "CayaProtocolMessages.h"
#include "CayaUtils.h"
const uint32 kJoinRoom = 'JWjr';
@ -26,7 +27,6 @@ JoinWindow::JoinWindow(BMessenger* messenger, AccountInstances accounts)
fSelectedAcc(0)
{
_InitInterface();
CenterOnScreen();
}
@ -77,9 +77,10 @@ JoinWindow::MessageReceived(BMessage* msg)
void
JoinWindow::_InitInterface()
{
fMenuField = new BMenuField("accountMenuField", NULL, _CreateAccountMenu());
BButton* join = new BButton("Join", new BMessage(kJoinRoom));
fTextBox = new BTextControl("Room ID:", "", NULL);
fMenuField = new BMenuField("accountMenuField", NULL,
CreateAccountMenu(fAccounts, BMessage(kAccSelected)));
BLayoutBuilder::Group<>(this, B_VERTICAL)
.SetInsets(B_USE_DEFAULT_SPACING)
@ -95,25 +96,3 @@ JoinWindow::_InitInterface()
fTextBox->MakeFocus(true);
join->MakeDefault(true);
}
BMenu*
JoinWindow::_CreateAccountMenu()
{
BMenu* menu = new BMenu("accountMenu");
for (int i = 0; i < fAccounts.CountItems(); i++)
menu->AddItem(new BMenuItem(fAccounts.KeyAt(i).String(),
new BMessage(kAccSelected)));
menu->SetRadioMode(true);
menu->SetLabelFromMarked(true);
menu->ItemAt(fSelectedAcc)->SetMarked(true);
if (fAccounts.CountItems() == 0)
menu->SetEnabled(false);
return menu;
}

View File

@ -24,7 +24,6 @@ public:
private:
void _InitInterface();
BMenu* _CreateAccountMenu();
BMessenger* fTarget;
AccountInstances fAccounts;

View File

@ -10,43 +10,55 @@
* Jaidyn Levesque, jadedctrl@teknik.io
*/
#include "RosterWindow.h"
#include <Button.h>
#include <LayoutBuilder.h>
#include <MenuField.h>
#include <Notification.h>
#include <ScrollView.h>
#include "CayaMessages.h"
#include "CayaPreferences.h"
#include "CayaProtocolMessages.h"
#include "CayaUtils.h"
#include "RosterItem.h"
#include "RosterListView.h"
#include "RosterView.h"
#include "Server.h"
const uint32 kSendMessage = 'RWSM';
const uint32 kSelAccount = 'RWSA';
const uint32 kSelNoAccount = 'RWNA';
RosterWindow::RosterWindow(const char* title, BMessage* selectMsg,
BMessenger* messenger, Server* server)
BMessenger* messenger, Server* server, bigtime_t instance)
:
BWindow(BRect(0, 0, 300, 400), title, B_FLOATING_WINDOW, 0),
fTarget(messenger),
fMessage(selectMsg),
fAccounts(server->GetAccounts()),
fServer(server)
{
fRosterView = new RosterView("buddyView", server);
fRosterView = new RosterView("buddyView", server, instance),
fRosterView->SetInvocationMessage(new BMessage(kSendMessage));
fOkButton = new BButton("OK", new BMessage(kSendMessage));
fAccountField = new BMenuField("accountMenuField", NULL,
CreateAccountMenu(fAccounts, BMessage(kSelAccount),
new BMessage(kSelNoAccount)));
BLayoutBuilder::Group<>(this, B_VERTICAL, 0.0f)
.AddGroup(B_VERTICAL)
.SetInsets(5, 5, 5, 10)
.SetInsets(B_USE_DEFAULT_SPACING)
.Add(fRosterView)
.AddGroup(B_HORIZONTAL)
.Add(fAccountField)
.AddGlue()
.Add(new BButton("Cancel", new BMessage(B_QUIT_REQUESTED)))
.Add(fOkButton)
.End()
.End();
CenterOnScreen();
}
@ -68,9 +80,19 @@ RosterWindow::MessageReceived(BMessage* message)
fMessage->AddInt64("instance", user->GetProtocolLooper()->GetInstance());
fTarget->SendMessage(fMessage);
PostMessage(B_QUIT_REQUESTED);
break;
}
case kSelAccount:
{
int index = message->FindInt32("index") - 1;
if (index < 0 || index > (fAccounts.CountItems() - 1))
return;
fRosterView->SetAccount(fAccounts.ValueAt(index));
break;
}
case kSelNoAccount:
fRosterView->SetAccount(-1);
break;
case IM_MESSAGE:
fRosterView->MessageReceived(message);
break;

View File

@ -14,9 +14,11 @@
#include <Window.h>
#include "Server.h"
class BMenuField;
class RosterItem;
class RosterView;
class Server;
/* A window with the a list of the user's contacts, will send a message to
@ -24,14 +26,19 @@ class Server;
class RosterWindow : public BWindow {
public:
RosterWindow(const char* title, BMessage* selectMsg, BMessenger* messenger,
Server* server);
Server* server, bigtime_t instance = -1);
void MessageReceived(BMessage* message);
void UpdateListItem(RosterItem* item);
private:
BButton* fOkButton;
BMenuField* fAccountField;
AccountInstances fAccounts;
Server* fServer;
RosterView* fRosterView;
BMessenger* fTarget;
BMessage* fMessage;