diff --git a/application/Contact.cpp b/application/Contact.cpp index c352913..0ad3d9b 100644 --- a/application/Contact.cpp +++ b/application/Contact.cpp @@ -30,15 +30,6 @@ Contact::GetRosterItem() const } -void -Contact::SetNotifyAvatarBitmap(BBitmap* bitmap) -{ - User::SetNotifyAvatarBitmap(bitmap); -// if (fAvatarBitmap != NULL && fChatWindow != NULL) -// fChatWindow->UpdateAvatar(); -} - - void Contact::_EnsureCachePath() { diff --git a/application/Contact.h b/application/Contact.h index 123180e..127ee01 100644 --- a/application/Contact.h +++ b/application/Contact.h @@ -26,8 +26,6 @@ public: RosterItem* GetRosterItem() const; - void SetNotifyAvatarBitmap(BBitmap* bitmap); - private: virtual void _EnsureCachePath(); diff --git a/application/Server.cpp b/application/Server.cpp index 783927e..0d42b8f 100644 --- a/application/Server.cpp +++ b/application/Server.cpp @@ -322,6 +322,19 @@ Server::ImMessage(BMessage* msg) contact->SetNotifyName(name); break; } + case IM_OWN_AVATAR_SET: + { + ProtocolLooper* looper = _LooperFromMessage(msg); + Contact* contact = looper->GetOwnContact(); + entry_ref ref; + + if (msg->FindRef("ref", &ref) == B_OK) { + BBitmap* bitmap = BTranslationUtils::GetBitmap(&ref); + if (bitmap != NULL) + contact->SetNotifyAvatarBitmap(bitmap); + } + break; + } case IM_AVATAR_SET: { User* user = _EnsureUser(msg); diff --git a/application/Server.h b/application/Server.h index ae5ef46..3e92449 100644 --- a/application/Server.h +++ b/application/Server.h @@ -70,6 +70,7 @@ private: Contact* _EnsureContact(BMessage* message); User* _EnsureUser(BMessage* message); User* _EnsureUser(BString id, ProtocolLooper* protoLooper); + Contact* _GetOwnContact(BMessage* message); Conversation* _EnsureConversation(BMessage* message); Role* _GetRole(BMessage* msg); diff --git a/application/views/StatusView.cpp b/application/views/StatusView.cpp index 5c2ed41..1b63127 100644 --- a/application/views/StatusView.cpp +++ b/application/views/StatusView.cpp @@ -21,6 +21,7 @@ #include #include "AccountManager.h" +#include "ImageCache.h" #include "NicknameTextControl.h" #include "StatusMenuItem.h" #include "Utils.h" @@ -69,6 +70,7 @@ StatusView::StatusView(const char* name) fAvatar = new BitmapView("AvatarIcon"); fAvatar->SetExplicitMaxSize(BSize(50, 50)); fAvatar->SetExplicitPreferredSize(BSize(50, 50)); + fAvatar->SetBitmap(ImageCache::Get()->GetImage("kPersonIcon")); // Set layout BLayoutBuilder::Group<>(this, B_HORIZONTAL) @@ -140,5 +142,7 @@ StatusView::SetStatus(UserStatus status) void StatusView::SetAvatarIcon(const BBitmap* bitmap) { - fAvatar->SetBitmap(bitmap); + // We don't want the default avatar to override a real one + if (bitmap != ImageCache::Get()->GetImage("kPersonIcon")) + fAvatar->SetBitmap(bitmap); } diff --git a/application/windows/MainWindow.cpp b/application/windows/MainWindow.cpp index 96d23dc..0877fa6 100644 --- a/application/windows/MainWindow.cpp +++ b/application/windows/MainWindow.cpp @@ -229,15 +229,19 @@ MainWindow::ImMessage(BMessage* msg) int32 im_what = msg->FindInt32("im_what"); switch (im_what) { case IM_OWN_CONTACT_INFO: - fStatusView->SetName(msg->FindString("name")); - break; - case IM_OWN_AVATAR_SET: { - entry_ref ref; + BString name; + if (msg->FindString("name", &name) == B_OK) + fStatusView->SetName(msg->FindString("name")); - if (msg->FindRef("ref", &ref) == B_OK) { - BBitmap* bitmap = BTranslationUtils::GetBitmap(&ref); - fStatusView->SetAvatarIcon(bitmap); + int64 instance; + if (msg->FindInt64("instance", &instance) == B_OK) { + ProtocolLooper* looper = fServer->GetProtocolLooper(instance); + if (looper != NULL) { + Contact* contact = looper->GetOwnContact(); + contact->RegisterObserver(this); + fStatusView->SetAvatarIcon(contact->AvatarBitmap()); + } } break; } @@ -309,6 +313,17 @@ MainWindow::ObserveInteger(int32 what, int32 val) } +void +MainWindow::ObservePointer(int32 what, void* ptr) +{ + if (what == PTR_AVATAR_BITMAP) { + BBitmap* bmp = (BBitmap*)ptr; + if (bmp != NULL) + fStatusView->SetAvatarIcon(bmp); + } +} + + void MainWindow::WorkspaceActivated(int32 workspace, bool active) { diff --git a/application/windows/MainWindow.h b/application/windows/MainWindow.h index c7025ea..cff3a11 100644 --- a/application/windows/MainWindow.h +++ b/application/windows/MainWindow.h @@ -39,6 +39,7 @@ public: // Observer inheritance void ObserveInteger(int32 what, int32 val); + void ObservePointer(int32 what, void* ptr); virtual void WorkspaceActivated(int32 workspace, bool active);