diff --git a/application/CayaUtils.cpp b/application/CayaUtils.cpp index e32adb6..db59d5c 100644 --- a/application/CayaUtils.cpp +++ b/application/CayaUtils.cpp @@ -11,6 +11,8 @@ #include #include #include +#include +#include #include #include @@ -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() { diff --git a/application/CayaUtils.h b/application/CayaUtils.h index a93b854..2ba34fa 100644 --- a/application/CayaUtils.h +++ b/application/CayaUtils.h @@ -14,6 +14,10 @@ #include #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); diff --git a/application/windows/JoinWindow.cpp b/application/windows/JoinWindow.cpp index f738e11..5402518 100644 --- a/application/windows/JoinWindow.cpp +++ b/application/windows/JoinWindow.cpp @@ -12,6 +12,7 @@ #include #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; -} - - diff --git a/application/windows/JoinWindow.h b/application/windows/JoinWindow.h index c1724cc..181aa3b 100644 --- a/application/windows/JoinWindow.h +++ b/application/windows/JoinWindow.h @@ -24,7 +24,6 @@ public: private: void _InitInterface(); - BMenu* _CreateAccountMenu(); BMessenger* fTarget; AccountInstances fAccounts; diff --git a/application/windows/RosterWindow.cpp b/application/windows/RosterWindow.cpp index a1adae4..0b25646 100644 --- a/application/windows/RosterWindow.cpp +++ b/application/windows/RosterWindow.cpp @@ -10,43 +10,55 @@ * Jaidyn Levesque, jadedctrl@teknik.io */ - #include "RosterWindow.h" +#include #include +#include #include #include #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) - .Add(fRosterView) + .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; diff --git a/application/windows/RosterWindow.h b/application/windows/RosterWindow.h index 40b30fd..6e0a7c6 100644 --- a/application/windows/RosterWindow.h +++ b/application/windows/RosterWindow.h @@ -14,9 +14,11 @@ #include +#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;