diff --git a/application/ChatProtocolMessages.h b/application/ChatProtocolMessages.h index 14b0d23..151ff48 100644 --- a/application/ChatProtocolMessages.h +++ b/application/ChatProtocolMessages.h @@ -423,7 +423,8 @@ enum im_what_code { copied and sent back verbatim (with im_what changed to IM_JOIN_ROOM) to join. Requires: Strings "chat_id" - Allows: String "chat_name", String "subject", int32 "user_count"*/ + Allows: String "chat_name", String "subject", String "category", + int32 "user_count" */ IM_ROOM_DIRECTORY = 231, diff --git a/application/views/RoomListRow.cpp b/application/views/RoomListRow.cpp index 617da7a..cd38c48 100644 --- a/application/views/RoomListRow.cpp +++ b/application/views/RoomListRow.cpp @@ -18,11 +18,18 @@ RoomListRow::RoomListRow(BMessage* msg) BString id = msg->FindString("chat_id"); BString name = msg->GetString("chat_name", id); BString desc = msg->FindString("subject"); + BString category = msg->FindString("category"); int32 user_n = msg->GetInt32("user_count", -1); SetField(new BStringField(name), kNameColumn); SetField(new BStringField(desc), kDescColumn); - SetField(new BStringField(id), kIdColumn); + SetField(new BStringField(category), kCatColumn); if (user_n > -1) SetField(new BIntegerField(user_n), kUserColumn); } + + +RoomListRow::~RoomListRow() +{ + delete fMessage; +} diff --git a/application/views/RoomListRow.h b/application/views/RoomListRow.h index aedb378..e2348da 100644 --- a/application/views/RoomListRow.h +++ b/application/views/RoomListRow.h @@ -11,7 +11,7 @@ enum { kNameColumn, kDescColumn, - kIdColumn, + kCatColumn, kUserColumn }; @@ -19,6 +19,7 @@ enum { class RoomListRow : public BRow { public: RoomListRow(BMessage* msg); + ~RoomListRow(); BMessage* Message() { return fMessage; } int64 Instance() { return fInstance; } diff --git a/application/windows/RoomListWindow.cpp b/application/windows/RoomListWindow.cpp index 1789200..3fe8286 100644 --- a/application/windows/RoomListWindow.cpp +++ b/application/windows/RoomListWindow.cpp @@ -12,6 +12,7 @@ #include #include +#include "AccountsMenu.h" #include "AppPreferences.h" #include "ChatProtocolMessages.h" #include "RoomListRow.h" @@ -22,6 +23,8 @@ #define B_TRANSLATION_CONTEXT "Room directory" +const uint32 kSelectAcc = 'rlse'; +const uint32 kSelectAll = 'rlsa'; const uint32 kJoinRoom = 'join'; RoomListWindow* RoomListWindow::fInstance = NULL; @@ -31,7 +34,8 @@ RoomListWindow::RoomListWindow(Server* server) BWindow(AppPreferences::Get()->RoomDirectoryRect, B_TRANSLATE("Room directory"), B_FLOATING_WINDOW, B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS), - fServer(server) + fServer(server), + fAccount(-1) { _InitInterface(); CenterOnScreen(); @@ -46,15 +50,21 @@ RoomListWindow::~RoomListWindow() { fInstance = NULL; AppPreferences::Get()->RoomDirectoryRect = Bounds(); + _EmptyList(); + + for (int i = 0; i < fRows.CountItems(); i++) { + BObjectList* list = fRows.ValueAt(i); + if (list != NULL) + delete list; + } } RoomListWindow* RoomListWindow::Get(Server* server) { - if (fInstance == NULL) { + if (fInstance == NULL) fInstance = new RoomListWindow(server); - } return fInstance; } @@ -78,8 +88,55 @@ RoomListWindow::MessageReceived(BMessage* msg) int64 instance; BString id; if (msg->FindInt64("instance", &instance) == B_OK - && msg->FindString("chat_id", &id) == B_OK) - fListView->AddRow(new RoomListRow(msg)); + && msg->FindString("chat_id", &id) == B_OK) { + RoomListRow* row = new RoomListRow(msg); + + bool fnd = false; + BObjectList* list = fRows.ValueFor(instance, &fnd); + if (fnd == false || list == NULL) { + list = new BObjectList(20, true); + fRows.AddItem(instance, list); + } + list->AddItem(row); + + if (fAccount == -1 || instance == fAccount) + fListView->AddRow(row); + } + break; + } + case kSelectAll: + { + _EmptyList(); + for (int i = 0; i < fRows.CountItems(); i++) { + BObjectList* list = fRows.ValueAt(i); + if (list != NULL) + for (int j = 0; j < list->CountItems(); j++) { + RoomListRow* row = list->ItemAt(j); + if (row != NULL) + fListView->AddRow(row); + } + } + fAccount = -1; + break; + } + case kSelectAcc: + { + msg->PrintToStream(); + int64 instance; + if (msg->FindInt64("instance", &instance) == B_OK) { + bool fnd = false; + BObjectList* list = fRows.ValueFor(instance, &fnd); + if (fnd == false || list == NULL) + break; + + _EmptyList(); + for (int i = 0; i < list->CountItems(); i++) { + RoomListRow* row = list->ItemAt(i); + if (row != NULL) + fListView->AddRow(row); + } + fAccount = instance; + } break; } case kJoinRoom: @@ -109,7 +166,8 @@ RoomListWindow::_InitInterface() B_TRUNCATE_END); BStringColumn* desc = new BStringColumn(B_TRANSLATE("Description"), 270, 50, 5000, B_TRUNCATE_END); - BStringColumn* id = new BStringColumn("ID", 90, 50, 300, B_TRUNCATE_END); + BStringColumn* category = new BStringColumn("Category", 90, 50, 300, + B_TRUNCATE_END); BIntegerColumn* users = new BIntegerColumn("Users", 70, 10, 300); fListView = new BColumnListView("roomList", B_NAVIGABLE, B_PLAIN_BORDER); @@ -117,9 +175,13 @@ RoomListWindow::_InitInterface() fListView->SetSelectionMode(B_SINGLE_SELECTION_LIST); fListView->AddColumn(name, kNameColumn); fListView->AddColumn(desc, kDescColumn); - fListView->AddColumn(id, kIdColumn); + fListView->AddColumn(category, kCatColumn); fListView->AddColumn(users, kUserColumn); + AccountsMenu* accsMenu = new AccountsMenu("accounts", BMessage(kSelectAcc), + new BMessage(kSelectAll), fServer); + BMenuField* accsField = new BMenuField(NULL, accsMenu); + fJoinButton = new BButton("joinRoom", B_TRANSLATE("Join"), new BMessage(kJoinRoom)); @@ -127,8 +189,20 @@ RoomListWindow::_InitInterface() .SetInsets(B_USE_DEFAULT_SPACING) .Add(fListView) .AddGroup(B_HORIZONTAL) + .Add(accsField) .AddGlue() .Add(fJoinButton) .End() .End(); } + + +void +RoomListWindow::_EmptyList() +{ + BRow* row = fListView->RowAt((int32)0, NULL); + while (row != NULL) { + fListView->RemoveRow(row); + row = fListView->RowAt((int32)0, NULL); + } +} diff --git a/application/windows/RoomListWindow.h b/application/windows/RoomListWindow.h index eb440fb..716b048 100644 --- a/application/windows/RoomListWindow.h +++ b/application/windows/RoomListWindow.h @@ -5,13 +5,20 @@ #ifndef _ROOM_LIST_WINDOW_H #define _ROOM_LIST_WINDOW_H +#include #include +#include + class BButton; class BColumnListView; +class RoomListRow; class Server; +typedef KeyMap*> RowMap; + + class RoomListWindow : public BWindow { public: RoomListWindow(Server* server); @@ -25,9 +32,14 @@ public: private: void _InitInterface(); + void _EmptyList(); + BButton* fJoinButton; BColumnListView* fListView; + RowMap fRows; + int64 fAccount; + Server* fServer; static RoomListWindow* fInstance; };