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 <Directory.h>
#include <FindDirectory.h> #include <FindDirectory.h>
#include <IconUtils.h> #include <IconUtils.h>
#include <Menu.h>
#include <MenuItem.h>
#include <Path.h> #include <Path.h>
#include <StringList.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* const char*
CayaAccountsPath() CayaAccountsPath()
{ {

View File

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

View File

@ -12,6 +12,7 @@
#include <StringView.h> #include <StringView.h>
#include "CayaProtocolMessages.h" #include "CayaProtocolMessages.h"
#include "CayaUtils.h"
const uint32 kJoinRoom = 'JWjr'; const uint32 kJoinRoom = 'JWjr';
@ -26,7 +27,6 @@ JoinWindow::JoinWindow(BMessenger* messenger, AccountInstances accounts)
fSelectedAcc(0) fSelectedAcc(0)
{ {
_InitInterface(); _InitInterface();
CenterOnScreen(); CenterOnScreen();
} }
@ -77,9 +77,10 @@ JoinWindow::MessageReceived(BMessage* msg)
void void
JoinWindow::_InitInterface() JoinWindow::_InitInterface()
{ {
fMenuField = new BMenuField("accountMenuField", NULL, _CreateAccountMenu());
BButton* join = new BButton("Join", new BMessage(kJoinRoom)); BButton* join = new BButton("Join", new BMessage(kJoinRoom));
fTextBox = new BTextControl("Room ID:", "", NULL); fTextBox = new BTextControl("Room ID:", "", NULL);
fMenuField = new BMenuField("accountMenuField", NULL,
CreateAccountMenu(fAccounts, BMessage(kAccSelected)));
BLayoutBuilder::Group<>(this, B_VERTICAL) BLayoutBuilder::Group<>(this, B_VERTICAL)
.SetInsets(B_USE_DEFAULT_SPACING) .SetInsets(B_USE_DEFAULT_SPACING)
@ -95,25 +96,3 @@ JoinWindow::_InitInterface()
fTextBox->MakeFocus(true); fTextBox->MakeFocus(true);
join->MakeDefault(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: private:
void _InitInterface(); void _InitInterface();
BMenu* _CreateAccountMenu();
BMessenger* fTarget; BMessenger* fTarget;
AccountInstances fAccounts; AccountInstances fAccounts;

View File

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

View File

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