Editing of roster members
Roster members' can now be edited (through Roster->Edit Roster / CMD+R) TemplateWindows can now be populated through sending any IM_MESSAGE to it (it will assume the slots of the message correspond to the template's). IM_CONTACT_LIST_ADDED_CONTACT was removed (for redundancy), and IM_CONTACT_LIST_EDIT_CONTACT was added.
This commit is contained in:
parent
b1254494cb
commit
a21c8f7601
|
@ -41,14 +41,18 @@ enum im_what_code {
|
|||
// "roster" template (CayaProtocol::SettingsTemplate("roster"))
|
||||
IM_CONTACT_LIST_ADD_CONTACT = 3,
|
||||
|
||||
//! Someone has been added →Caya
|
||||
//! Remove a contact →Protocol
|
||||
// Requires: String "user_id"
|
||||
// Allows: String "user_name"
|
||||
IM_CONTACT_LIST_CONTACT_ADDED = 4,
|
||||
IM_CONTACT_LIST_REMOVE_CONTACT = 4,
|
||||
|
||||
//! Contact(s) removed from the server-side list →Caya
|
||||
// Requires: String "user_id"
|
||||
IM_CONTACT_LIST_REMOVED_CONTACT = 4,
|
||||
IM_CONTACT_LIST_REMOVED_CONTACT = 5,
|
||||
|
||||
//! Edit some data on contact →Protocol
|
||||
// The slots for this message are determined by the protocol's
|
||||
// "roster" template (CayaProtocol::SettingsTemplate("roster"))
|
||||
IM_CONTACT_LIST_EDIT_CONTACT = 6,
|
||||
|
||||
|
||||
/*
|
||||
|
|
|
@ -46,7 +46,6 @@ MainWindow::MainWindow()
|
|||
fWorkspaceChanged(false),
|
||||
fConversation(NULL),
|
||||
fRosterWindow(NULL),
|
||||
fRosterEditWindow(NULL),
|
||||
fServer(NULL)
|
||||
{
|
||||
_InitInterface();
|
||||
|
@ -173,8 +172,7 @@ MainWindow::MessageReceived(BMessage* message)
|
|||
}
|
||||
case CAYA_EDIT_ROSTER:
|
||||
{
|
||||
fRosterEditWindow = new RosterEditWindow(fServer);
|
||||
fRosterEditWindow->Show();
|
||||
RosterEditWindow::Get(fServer)->Show();
|
||||
break;
|
||||
}
|
||||
case CAYA_MOVE_UP:
|
||||
|
@ -292,8 +290,8 @@ MainWindow::ImMessage(BMessage* msg)
|
|||
case IM_STATUS_SET:
|
||||
if (fRosterWindow != NULL)
|
||||
fRosterWindow->PostMessage(msg);
|
||||
if (fRosterEditWindow != NULL)
|
||||
fRosterEditWindow->PostMessage(msg);
|
||||
if (RosterEditWindow::Check() == true)
|
||||
RosterEditWindow::Get(fServer)->PostMessage(msg);
|
||||
break;
|
||||
|
||||
case IM_PROTOCOL_READY:
|
||||
|
|
|
@ -36,12 +36,15 @@ const uint32 kEditMember = 'RWEM';
|
|||
const uint32 kSelAccount = 'RWSA';
|
||||
const uint32 kSelNoAccount = 'RWNA';
|
||||
|
||||
RosterEditWindow* RosterEditWindow::fInstance = NULL;
|
||||
|
||||
|
||||
RosterEditWindow::RosterEditWindow(Server* server)
|
||||
:
|
||||
BWindow(BRect(0, 0, 300, 400), "Roster", B_FLOATING_WINDOW, 0),
|
||||
fAccounts(server->GetAccounts()),
|
||||
fServer(server)
|
||||
fServer(server),
|
||||
fEditingWindow(NULL)
|
||||
{
|
||||
fRosterView = new RosterView("buddyView", server);
|
||||
fRosterView->SetInvocationMessage(new BMessage(kEditMember));
|
||||
|
@ -85,22 +88,69 @@ RosterEditWindow::RosterEditWindow(Server* server)
|
|||
}
|
||||
|
||||
|
||||
RosterEditWindow::~RosterEditWindow()
|
||||
{
|
||||
fInstance = NULL;
|
||||
}
|
||||
|
||||
|
||||
RosterEditWindow*
|
||||
RosterEditWindow::Get(Server* server)
|
||||
{
|
||||
if (fInstance == NULL) {
|
||||
fInstance = new RosterEditWindow(server);
|
||||
}
|
||||
return fInstance;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
RosterEditWindow::Check()
|
||||
{
|
||||
return (fInstance != NULL);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
RosterEditWindow::MessageReceived(BMessage* message)
|
||||
{
|
||||
switch (message->what) {
|
||||
case kEditMember:
|
||||
{
|
||||
if (fEditingWindow != NULL && fEditingWindow->Lock()) {
|
||||
fEditingWindow->Quit();
|
||||
fEditingUser.SetTo("");
|
||||
}
|
||||
|
||||
int index = message->FindInt32("index");
|
||||
RosterItem* ritem = fRosterView->ListView()->RosterItemAt(index);
|
||||
if (ritem == NULL)
|
||||
return;
|
||||
User* user = ritem->GetContact();
|
||||
|
||||
TemplateWindow* win =
|
||||
new TemplateWindow("Editing contact", "roster", new BMessage(),
|
||||
fServer, user->GetProtocolLooper()->GetInstance());
|
||||
win->Show();
|
||||
User* user = ritem->GetContact();
|
||||
fEditingUser.SetTo(user->GetId().String());
|
||||
|
||||
// The response IM_EXTENDED_CONTACT_INFO is used to populate the
|
||||
// TemplateWindow.
|
||||
BMessage* request = new BMessage(IM_MESSAGE);
|
||||
request->AddInt32("im_what", IM_GET_EXTENDED_CONTACT_INFO);
|
||||
request->AddString("user_id", user->GetId());
|
||||
user->GetProtocolLooper()->PostMessage(request);
|
||||
|
||||
BMessage* edit = new BMessage(IM_MESSAGE);
|
||||
edit->AddInt32("im_what", IM_CONTACT_LIST_EDIT_CONTACT);
|
||||
|
||||
fEditingWindow =
|
||||
new TemplateWindow("Editing contact", "roster", edit, fServer,
|
||||
user->GetProtocolLooper()->GetInstance());
|
||||
fEditingWindow->Show();
|
||||
break;
|
||||
}
|
||||
case IM_MESSAGE: {
|
||||
if (message->GetInt32("im_what", 0) == IM_EXTENDED_CONTACT_INFO)
|
||||
if (message->GetString("user_id", "") == fEditingUser)
|
||||
fEditingWindow->PostMessage(message);
|
||||
fRosterView->MessageReceived(message);
|
||||
break;
|
||||
}
|
||||
case kAddMember:
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
class BMenuField;
|
||||
class RosterItem;
|
||||
class RosterView;
|
||||
class TemplateWindow;
|
||||
|
||||
|
||||
/* A window with the a list of the user's contacts, will send a message to
|
||||
|
@ -26,16 +27,24 @@ class RosterView;
|
|||
class RosterEditWindow : public BWindow {
|
||||
public:
|
||||
RosterEditWindow(Server* server);
|
||||
void MessageReceived(BMessage* message);
|
||||
~RosterEditWindow();
|
||||
static RosterEditWindow* Get(Server* server);
|
||||
static bool Check();
|
||||
|
||||
void MessageReceived(BMessage* message);
|
||||
void UpdateListItem(RosterItem* item);
|
||||
|
||||
private:
|
||||
BMenuField* fAccountField;
|
||||
AccountInstances fAccounts;
|
||||
|
||||
BString fEditingUser;
|
||||
TemplateWindow* fEditingWindow;
|
||||
|
||||
Server* fServer;
|
||||
RosterView* fRosterView;
|
||||
|
||||
static RosterEditWindow* fInstance;
|
||||
};
|
||||
|
||||
#endif // _ROSTER_EDIT_WINDOW_H
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include <TextControl.h>
|
||||
#include <String.h>
|
||||
|
||||
#include "CayaProtocolMessages.h"
|
||||
#include "CayaUtils.h"
|
||||
#include "TemplateView.h"
|
||||
|
||||
|
@ -69,12 +70,13 @@ void
|
|||
TemplateWindow::MessageReceived(BMessage* msg)
|
||||
{
|
||||
switch (msg->what) {
|
||||
case kAccSelected:
|
||||
{
|
||||
int32 index;
|
||||
if (msg->FindInt32("index", &index) == B_OK)
|
||||
fSelectedAcc = index;
|
||||
_LoadTemplate();
|
||||
case IM_MESSAGE: {
|
||||
// If IM_MESSAGE, assume it should be treated as current settings
|
||||
if (fTemplate == NULL)
|
||||
break;
|
||||
for (int i = 0; fTemplateView->CountChildren(); i++)
|
||||
fTemplateView->RemoveChild(fTemplateView->ChildAt(i));
|
||||
fTemplate->Load(fTemplateView, msg);
|
||||
break;
|
||||
}
|
||||
case kOK: {
|
||||
|
@ -100,8 +102,14 @@ TemplateWindow::MessageReceived(BMessage* msg)
|
|||
Close();
|
||||
break;
|
||||
}
|
||||
case kChanged:
|
||||
case kAccSelected:
|
||||
{
|
||||
int32 index;
|
||||
if (msg->FindInt32("index", &index) == B_OK)
|
||||
fSelectedAcc = index;
|
||||
_LoadTemplate();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
BWindow::MessageReceived(msg);
|
||||
}
|
||||
|
|
|
@ -242,6 +242,13 @@ JabberHandler::Process(BMessage* msg)
|
|||
_MUCModeration(msg);
|
||||
break;
|
||||
|
||||
case IM_GET_EXTENDED_CONTACT_INFO: {
|
||||
BString user_id;
|
||||
if (msg->FindString("user_id", &user_id) == B_OK)
|
||||
fVCardManager->fetchVCard(gloox::JID(user_id.String()), this);
|
||||
break;
|
||||
}
|
||||
|
||||
case IM_CONTACT_LIST_ADD_CONTACT: {
|
||||
BString user_name = msg->FindString("user_name");
|
||||
BString user_id;
|
||||
|
@ -254,6 +261,24 @@ JabberHandler::Process(BMessage* msg)
|
|||
fClient->rosterManager()->synchronize();
|
||||
break;
|
||||
}
|
||||
|
||||
case IM_CONTACT_LIST_EDIT_CONTACT: {
|
||||
BString user_id;
|
||||
BString user_name = msg->FindString("user_name");
|
||||
if (msg->FindString("user_id", &user_id) != B_OK)
|
||||
break;
|
||||
|
||||
gloox::JID jid(user_id.String());
|
||||
gloox::RosterItem* item =
|
||||
fClient->rosterManager()->getRosterItem(jid);
|
||||
|
||||
if (item != NULL && user_name.IsEmpty() == false) {
|
||||
item->setName(user_name.String());
|
||||
fClient->rosterManager()->synchronize();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
return B_ERROR;
|
||||
}
|
||||
|
@ -1761,13 +1786,18 @@ JabberHandler::handleVCard(const gloox::JID& jid, const gloox::VCard* card)
|
|||
|
||||
gloox::VCard::Name name = card->name();
|
||||
gloox::VCard::Photo photo = card->photo();
|
||||
BString nick(card->nickname().c_str());
|
||||
|
||||
gloox::RosterItem* item = fClient->rosterManager()->getRosterItem(jid);
|
||||
if (item != NULL)
|
||||
nick = item->name().c_str();
|
||||
|
||||
std::string fullName = name.family + " " + name.given;
|
||||
|
||||
BMessage msg(IM_MESSAGE);
|
||||
msg.AddInt32("im_what", IM_EXTENDED_CONTACT_INFO);
|
||||
msg.AddString("user_id", jid.bare().c_str());
|
||||
msg.AddString("user_name", card->nickname().c_str());
|
||||
msg.AddString("user_name", nick);
|
||||
msg.AddString("family_name", name.family.c_str());
|
||||
msg.AddString("given_name", name.given.c_str());
|
||||
msg.AddString("middle_name", name.middle.c_str());
|
||||
|
|
Ŝarĝante…
Reference in New Issue