Modified ContactLinker : moved some inline methods from class declaration, added Get* methods for contact status and status message. Added code in the ChatWindow to show the current avatar of the user. Modified the Server to allow a plugin set the status message when sending a IM_CONTACT_INFO notification to the server, as before it's already possible to do it using a IM_STATUS_SET message.

This commit is contained in:
barrett 2012-03-07 19:22:09 +00:00
parent 8d04f539c2
commit c22310f510
5 changed files with 83 additions and 6 deletions

View File

@ -22,6 +22,7 @@
#include <ScrollView.h> #include <ScrollView.h>
#include <String.h> #include <String.h>
#include "BitmapView.h"
#include "CayaMessages.h" #include "CayaMessages.h"
#include "CayaProtocolMessages.h" #include "CayaProtocolMessages.h"
#include "ChatWindow.h" #include "ChatWindow.h"
@ -36,7 +37,7 @@ ChatWindow::ChatWindow(ContactLinker* cl)
: :
BWindow(BRect(200, 200, 500, 500), BWindow(BRect(200, 200, 500, 500),
cl->GetName().String(), B_DOCUMENT_WINDOW, 0), cl->GetName().String(), B_DOCUMENT_WINDOW, 0),
fContactLinker(cl) fContactLinker(cl)
{ {
fReceiveView = new CayaRenderView("fReceiveView"); fReceiveView = new CayaRenderView("fReceiveView");
fReceiveView->SetOtherNick(cl->GetName()); fReceiveView->SetOtherNick(cl->GetName());
@ -50,15 +51,30 @@ ChatWindow::ChatWindow(ContactLinker* cl)
AddCommonFilter(new EditingFilter(fSendView)); AddCommonFilter(new EditingFilter(fSendView));
fSendView->MakeFocus(true); fSendView->MakeFocus(true);
/*
BStringView* personalMessage = new BStringView("personalMessage", "");
personalMessage->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, B_ALIGN_MIDDLE));
personalMessage->SetText(fContactLinker->GetNotifyPersonalStatus());
personalMessage->SetExplicitMaxSize(BSize(200, 200));
*/
fStatus = new BStringView("status", ""); fStatus = new BStringView("status", "");
fStatus->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, B_ALIGN_MIDDLE)); fStatus->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, B_ALIGN_MIDDLE));
SetLayout(new BGroupLayout(B_HORIZONTAL)); SetLayout(new BGroupLayout(B_HORIZONTAL));
fAvatar = new BitmapView("ContactIcon");
fAvatar->SetExplicitMaxSize(BSize(50, 50));
fAvatar->SetExplicitPreferredSize(BSize(50, 50));
fAvatar->SetExplicitAlignment(BAlignment(B_ALIGN_RIGHT, B_ALIGN_MIDDLE));
fAvatar->SetBitmap(fContactLinker->AvatarBitmap());
AddChild(BGroupLayoutBuilder(B_VERTICAL, 10) AddChild(BGroupLayoutBuilder(B_VERTICAL, 10)
// .Add(personalMessage)
.Add(fAvatar, 1)
.Add(scrollViewReceive, 2) .Add(scrollViewReceive, 2)
.Add(scrollViewSend) .Add(scrollViewSend)
.Add(fStatus) .Add(fStatus, 3)
.SetInsets(5, 5, 5, 5) .SetInsets(5, 5, 5, 5)
); );
@ -78,6 +94,13 @@ ChatWindow::QuitRequested()
} }
void
ChatWindow::UpdateAvatar()
{
fAvatar->SetBitmap(fContactLinker->AvatarBitmap());
}
void void
ChatWindow::MessageReceived(BMessage* message) ChatWindow::MessageReceived(BMessage* message)
{ {

View File

@ -12,6 +12,7 @@
#include "CayaConstants.h" #include "CayaConstants.h"
class BitmapView;
class ContactLinker; class ContactLinker;
class CayaRenderView; class CayaRenderView;
@ -22,6 +23,7 @@ public:
virtual void MessageReceived(BMessage* message); virtual void MessageReceived(BMessage* message);
virtual bool QuitRequested(); virtual bool QuitRequested();
void UpdateAvatar();
void ImMessage(BMessage* msg); void ImMessage(BMessage* msg);
void ObserveString(int32 what, BString str); void ObserveString(int32 what, BString str);
@ -34,6 +36,7 @@ private:
ContactLinker* fContactLinker; ContactLinker* fContactLinker;
CayaRenderView* fReceiveView; CayaRenderView* fReceiveView;
BStringView* fStatus; BStringView* fStatus;
BitmapView* fAvatar;
}; };

View File

@ -119,6 +119,20 @@ ContactLinker::DeletePopUp()
} }
RosterItem*
ContactLinker::GetRosterItem() const
{
return fRosterItem;
}
BString
ContactLinker::GetId() const
{
return fID;
}
BMessenger BMessenger
ContactLinker::Messenger() const ContactLinker::Messenger() const
{ {
@ -140,6 +154,34 @@ ContactLinker::GetProtocolLooper() const
} }
BString
ContactLinker::GetName() const
{
return fName;
}
BBitmap*
ContactLinker::AvatarBitmap() const
{
return fAvatarBitmap;
}
CayaStatus
ContactLinker::GetNotifyStatus() const
{
return fStatus;
}
BString
ContactLinker::GetNotifyPersonalStatus() const
{
return fPersonalStatus;
}
void void
ContactLinker::SetProtocolLooper(ProtocolLooper* looper) ContactLinker::SetProtocolLooper(ProtocolLooper* looper)
{ {
@ -171,6 +213,8 @@ ContactLinker::SetNotifyAvatarBitmap(BBitmap* bitmap)
if ((fAvatarBitmap != bitmap) && (bitmap != NULL)) { if ((fAvatarBitmap != bitmap) && (bitmap != NULL)) {
fAvatarBitmap = bitmap; fAvatarBitmap = bitmap;
NotifyPointer(PTR_AVATAR_BITMAP, (void*)bitmap); NotifyPointer(PTR_AVATAR_BITMAP, (void*)bitmap);
if (fChatWindow != NULL)
fChatWindow->UpdateAvatar();
} }
} }

View File

@ -33,9 +33,9 @@ public:
void DeletePopUp(); void DeletePopUp();
void HidePopUp(); void HidePopUp();
RosterItem* GetRosterItem() { return fRosterItem; } RosterItem* GetRosterItem() const;
BString GetId() { return fID; } BString GetId() const;
BMessenger Messenger() const; BMessenger Messenger() const;
void SetMessenger(BMessenger messenger); void SetMessenger(BMessenger messenger);
@ -43,8 +43,10 @@ public:
ProtocolLooper* GetProtocolLooper() const; ProtocolLooper* GetProtocolLooper() const;
void SetProtocolLooper(ProtocolLooper* looper); void SetProtocolLooper(ProtocolLooper* looper);
BString GetName() { return fName; } BString GetName() const;
BBitmap* AvatarBitmap() { return fAvatarBitmap; } BBitmap* AvatarBitmap() const;
CayaStatus GetNotifyStatus() const;
BString GetNotifyPersonalStatus() const;
void SetNotifyName(BString name); void SetNotifyName(BString name);
void SetNotifyAvatarBitmap(BBitmap* bitmap); void SetNotifyAvatarBitmap(BBitmap* bitmap);

View File

@ -262,6 +262,11 @@ Server::ImMessage(BMessage* msg)
if ((msg->FindString("name", &name) == B_OK) if ((msg->FindString("name", &name) == B_OK)
&& (strcmp(name, "") != 0)) && (strcmp(name, "") != 0))
linker->SetNotifyName(name); linker->SetNotifyName(name);
BString status;
if (msg->FindString("message", &status) == B_OK)
linker->SetNotifyPersonalStatus(status);
break; break;
} }
case IM_EXTENDED_CONTACT_INFO: case IM_EXTENDED_CONTACT_INFO: