Sort room directory by account, 'Category' column
The room directory window now has an accounts menu, to allow the user to filter rooms by account― and a "category" column has been added, which can optionally be filled by the protocol for more semantic sorting of rooms (Through "category" slot of IM_ROOM_DIRECTORY).
This commit is contained in:
parent
8cb98ccf4b
commit
6a160ced88
|
@ -423,7 +423,8 @@ enum im_what_code {
|
||||||
copied and sent back verbatim (with im_what changed to IM_JOIN_ROOM)
|
copied and sent back verbatim (with im_what changed to IM_JOIN_ROOM)
|
||||||
to join.
|
to join.
|
||||||
Requires: Strings "chat_id"
|
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,
|
IM_ROOM_DIRECTORY = 231,
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,11 +18,18 @@ RoomListRow::RoomListRow(BMessage* msg)
|
||||||
BString id = msg->FindString("chat_id");
|
BString id = msg->FindString("chat_id");
|
||||||
BString name = msg->GetString("chat_name", id);
|
BString name = msg->GetString("chat_name", id);
|
||||||
BString desc = msg->FindString("subject");
|
BString desc = msg->FindString("subject");
|
||||||
|
BString category = msg->FindString("category");
|
||||||
int32 user_n = msg->GetInt32("user_count", -1);
|
int32 user_n = msg->GetInt32("user_count", -1);
|
||||||
|
|
||||||
SetField(new BStringField(name), kNameColumn);
|
SetField(new BStringField(name), kNameColumn);
|
||||||
SetField(new BStringField(desc), kDescColumn);
|
SetField(new BStringField(desc), kDescColumn);
|
||||||
SetField(new BStringField(id), kIdColumn);
|
SetField(new BStringField(category), kCatColumn);
|
||||||
if (user_n > -1)
|
if (user_n > -1)
|
||||||
SetField(new BIntegerField(user_n), kUserColumn);
|
SetField(new BIntegerField(user_n), kUserColumn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
RoomListRow::~RoomListRow()
|
||||||
|
{
|
||||||
|
delete fMessage;
|
||||||
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
enum {
|
enum {
|
||||||
kNameColumn,
|
kNameColumn,
|
||||||
kDescColumn,
|
kDescColumn,
|
||||||
kIdColumn,
|
kCatColumn,
|
||||||
kUserColumn
|
kUserColumn
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@ enum {
|
||||||
class RoomListRow : public BRow {
|
class RoomListRow : public BRow {
|
||||||
public:
|
public:
|
||||||
RoomListRow(BMessage* msg);
|
RoomListRow(BMessage* msg);
|
||||||
|
~RoomListRow();
|
||||||
|
|
||||||
BMessage* Message() { return fMessage; }
|
BMessage* Message() { return fMessage; }
|
||||||
int64 Instance() { return fInstance; }
|
int64 Instance() { return fInstance; }
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include <LayoutBuilder.h>
|
#include <LayoutBuilder.h>
|
||||||
#include <StringList.h>
|
#include <StringList.h>
|
||||||
|
|
||||||
|
#include "AccountsMenu.h"
|
||||||
#include "AppPreferences.h"
|
#include "AppPreferences.h"
|
||||||
#include "ChatProtocolMessages.h"
|
#include "ChatProtocolMessages.h"
|
||||||
#include "RoomListRow.h"
|
#include "RoomListRow.h"
|
||||||
|
@ -22,6 +23,8 @@
|
||||||
#define B_TRANSLATION_CONTEXT "Room directory"
|
#define B_TRANSLATION_CONTEXT "Room directory"
|
||||||
|
|
||||||
|
|
||||||
|
const uint32 kSelectAcc = 'rlse';
|
||||||
|
const uint32 kSelectAll = 'rlsa';
|
||||||
const uint32 kJoinRoom = 'join';
|
const uint32 kJoinRoom = 'join';
|
||||||
RoomListWindow* RoomListWindow::fInstance = NULL;
|
RoomListWindow* RoomListWindow::fInstance = NULL;
|
||||||
|
|
||||||
|
@ -31,7 +34,8 @@ RoomListWindow::RoomListWindow(Server* server)
|
||||||
BWindow(AppPreferences::Get()->RoomDirectoryRect,
|
BWindow(AppPreferences::Get()->RoomDirectoryRect,
|
||||||
B_TRANSLATE("Room directory"), B_FLOATING_WINDOW,
|
B_TRANSLATE("Room directory"), B_FLOATING_WINDOW,
|
||||||
B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS),
|
B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS),
|
||||||
fServer(server)
|
fServer(server),
|
||||||
|
fAccount(-1)
|
||||||
{
|
{
|
||||||
_InitInterface();
|
_InitInterface();
|
||||||
CenterOnScreen();
|
CenterOnScreen();
|
||||||
|
@ -46,15 +50,21 @@ RoomListWindow::~RoomListWindow()
|
||||||
{
|
{
|
||||||
fInstance = NULL;
|
fInstance = NULL;
|
||||||
AppPreferences::Get()->RoomDirectoryRect = Bounds();
|
AppPreferences::Get()->RoomDirectoryRect = Bounds();
|
||||||
|
_EmptyList();
|
||||||
|
|
||||||
|
for (int i = 0; i < fRows.CountItems(); i++) {
|
||||||
|
BObjectList<RoomListRow>* list = fRows.ValueAt(i);
|
||||||
|
if (list != NULL)
|
||||||
|
delete list;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
RoomListWindow*
|
RoomListWindow*
|
||||||
RoomListWindow::Get(Server* server)
|
RoomListWindow::Get(Server* server)
|
||||||
{
|
{
|
||||||
if (fInstance == NULL) {
|
if (fInstance == NULL)
|
||||||
fInstance = new RoomListWindow(server);
|
fInstance = new RoomListWindow(server);
|
||||||
}
|
|
||||||
return fInstance;
|
return fInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,8 +88,55 @@ RoomListWindow::MessageReceived(BMessage* msg)
|
||||||
int64 instance;
|
int64 instance;
|
||||||
BString id;
|
BString id;
|
||||||
if (msg->FindInt64("instance", &instance) == B_OK
|
if (msg->FindInt64("instance", &instance) == B_OK
|
||||||
&& msg->FindString("chat_id", &id) == B_OK)
|
&& msg->FindString("chat_id", &id) == B_OK) {
|
||||||
fListView->AddRow(new RoomListRow(msg));
|
RoomListRow* row = new RoomListRow(msg);
|
||||||
|
|
||||||
|
bool fnd = false;
|
||||||
|
BObjectList<RoomListRow>* list = fRows.ValueFor(instance, &fnd);
|
||||||
|
if (fnd == false || list == NULL) {
|
||||||
|
list = new BObjectList<RoomListRow>(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<RoomListRow>* 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<RoomListRow>* 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;
|
break;
|
||||||
}
|
}
|
||||||
case kJoinRoom:
|
case kJoinRoom:
|
||||||
|
@ -109,7 +166,8 @@ RoomListWindow::_InitInterface()
|
||||||
B_TRUNCATE_END);
|
B_TRUNCATE_END);
|
||||||
BStringColumn* desc = new BStringColumn(B_TRANSLATE("Description"), 270,
|
BStringColumn* desc = new BStringColumn(B_TRANSLATE("Description"), 270,
|
||||||
50, 5000, B_TRUNCATE_END);
|
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);
|
BIntegerColumn* users = new BIntegerColumn("Users", 70, 10, 300);
|
||||||
|
|
||||||
fListView = new BColumnListView("roomList", B_NAVIGABLE, B_PLAIN_BORDER);
|
fListView = new BColumnListView("roomList", B_NAVIGABLE, B_PLAIN_BORDER);
|
||||||
|
@ -117,9 +175,13 @@ RoomListWindow::_InitInterface()
|
||||||
fListView->SetSelectionMode(B_SINGLE_SELECTION_LIST);
|
fListView->SetSelectionMode(B_SINGLE_SELECTION_LIST);
|
||||||
fListView->AddColumn(name, kNameColumn);
|
fListView->AddColumn(name, kNameColumn);
|
||||||
fListView->AddColumn(desc, kDescColumn);
|
fListView->AddColumn(desc, kDescColumn);
|
||||||
fListView->AddColumn(id, kIdColumn);
|
fListView->AddColumn(category, kCatColumn);
|
||||||
fListView->AddColumn(users, kUserColumn);
|
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"),
|
fJoinButton = new BButton("joinRoom", B_TRANSLATE("Join"),
|
||||||
new BMessage(kJoinRoom));
|
new BMessage(kJoinRoom));
|
||||||
|
|
||||||
|
@ -127,8 +189,20 @@ RoomListWindow::_InitInterface()
|
||||||
.SetInsets(B_USE_DEFAULT_SPACING)
|
.SetInsets(B_USE_DEFAULT_SPACING)
|
||||||
.Add(fListView)
|
.Add(fListView)
|
||||||
.AddGroup(B_HORIZONTAL)
|
.AddGroup(B_HORIZONTAL)
|
||||||
|
.Add(accsField)
|
||||||
.AddGlue()
|
.AddGlue()
|
||||||
.Add(fJoinButton)
|
.Add(fJoinButton)
|
||||||
.End()
|
.End()
|
||||||
.End();
|
.End();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
RoomListWindow::_EmptyList()
|
||||||
|
{
|
||||||
|
BRow* row = fListView->RowAt((int32)0, NULL);
|
||||||
|
while (row != NULL) {
|
||||||
|
fListView->RemoveRow(row);
|
||||||
|
row = fListView->RowAt((int32)0, NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -5,13 +5,20 @@
|
||||||
#ifndef _ROOM_LIST_WINDOW_H
|
#ifndef _ROOM_LIST_WINDOW_H
|
||||||
#define _ROOM_LIST_WINDOW_H
|
#define _ROOM_LIST_WINDOW_H
|
||||||
|
|
||||||
|
#include <ObjectList.h>
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
|
|
||||||
|
#include <libsupport/KeyMap.h>
|
||||||
|
|
||||||
class BButton;
|
class BButton;
|
||||||
class BColumnListView;
|
class BColumnListView;
|
||||||
|
class RoomListRow;
|
||||||
class Server;
|
class Server;
|
||||||
|
|
||||||
|
|
||||||
|
typedef KeyMap<int64, BObjectList<RoomListRow>*> RowMap;
|
||||||
|
|
||||||
|
|
||||||
class RoomListWindow : public BWindow {
|
class RoomListWindow : public BWindow {
|
||||||
public:
|
public:
|
||||||
RoomListWindow(Server* server);
|
RoomListWindow(Server* server);
|
||||||
|
@ -25,9 +32,14 @@ public:
|
||||||
private:
|
private:
|
||||||
void _InitInterface();
|
void _InitInterface();
|
||||||
|
|
||||||
|
void _EmptyList();
|
||||||
|
|
||||||
BButton* fJoinButton;
|
BButton* fJoinButton;
|
||||||
BColumnListView* fListView;
|
BColumnListView* fListView;
|
||||||
|
|
||||||
|
RowMap fRows;
|
||||||
|
int64 fAccount;
|
||||||
|
|
||||||
Server* fServer;
|
Server* fServer;
|
||||||
static RoomListWindow* fInstance;
|
static RoomListWindow* fInstance;
|
||||||
};
|
};
|
||||||
|
|
Ŝarĝante…
Reference in New Issue