diff --git a/application/Conversation.cpp b/application/Conversation.cpp index 10ed206..5f82c82 100644 --- a/application/Conversation.cpp +++ b/application/Conversation.cpp @@ -293,11 +293,12 @@ Conversation::SetNotifySubject(const char* subject) bool -Conversation::SetIconBitmap(BBitmap* icon) +Conversation::SetNotifyIconBitmap(BBitmap* icon) { if (icon != NULL) { fIcon = icon; GetView()->UpdateIcon(); + NotifyPointer(PTR_ROOM_BITMAP, (void*)icon); return true; } return false; @@ -434,7 +435,9 @@ Conversation::RemoveUser(User* user) user->UnregisterObserver(this); GetView()->UpdateUserList(fUsers); _SortConversationList(); + _UpdateIcon(); + NotifyInteger(INT_ROOM_MEMBERS, fUsers.CountItems()); } @@ -594,6 +597,7 @@ Conversation::_EnsureUser(BMessage* msg) user = serverUser; GetView()->UpdateUserList(fUsers); _UpdateIcon(user); + NotifyInteger(INT_ROOM_MEMBERS, fUsers.CountItems()); } // Not anywhere; create user else if (user == NULL) { @@ -604,6 +608,7 @@ Conversation::_EnsureUser(BMessage* msg) fUsers.AddItem(id, user); GetView()->UpdateUserList(fUsers); _UpdateIcon(user); + NotifyInteger(INT_ROOM_MEMBERS, fUsers.CountItems()); } if (name.IsEmpty() == false) { @@ -642,7 +647,7 @@ Conversation::_UpdateIcon(User* user) if (user != NULL && fUsers.CountItems() == 2 && user->GetId() != GetOwnContact()->GetId() && _IsDefaultIcon(user->AvatarBitmap()) == false) { - fUserIcon = SetIconBitmap(user->AvatarBitmap()); + fUserIcon = SetNotifyIconBitmap(user->AvatarBitmap()); return; } @@ -650,19 +655,19 @@ Conversation::_UpdateIcon(User* user) { case 0: case 1: - SetIconBitmap(ImageCache::Get()->GetImage("kOnePersonIcon")); + SetNotifyIconBitmap(ImageCache::Get()->GetImage("kOnePersonIcon")); break; case 2: - SetIconBitmap(ImageCache::Get()->GetImage("kTwoPeopleIcon")); + SetNotifyIconBitmap(ImageCache::Get()->GetImage("kTwoPeopleIcon")); break; case 3: - SetIconBitmap(ImageCache::Get()->GetImage("kThreePeopleIcon")); + SetNotifyIconBitmap(ImageCache::Get()->GetImage("kThreePeopleIcon")); break; case 4: - SetIconBitmap(ImageCache::Get()->GetImage("kFourPeopleIcon")); + SetNotifyIconBitmap(ImageCache::Get()->GetImage("kFourPeopleIcon")); break; default: - SetIconBitmap(ImageCache::Get()->GetImage("kMorePeopleIcon")); + SetNotifyIconBitmap(ImageCache::Get()->GetImage("kMorePeopleIcon")); break; } fUserIcon = false; diff --git a/application/Conversation.h b/application/Conversation.h index 7fee6d7..a0676d1 100644 --- a/application/Conversation.h +++ b/application/Conversation.h @@ -43,8 +43,7 @@ public: void SetNotifyName(const char* name); void SetNotifySubject(const char* subject); - - bool SetIconBitmap(BBitmap* icon); + bool SetNotifyIconBitmap(BBitmap* icon); BMessenger Messenger() const; void SetMessenger(BMessenger messenger); diff --git a/application/NotifyMessage.h b/application/NotifyMessage.h index 4a229b5..606218d 100644 --- a/application/NotifyMessage.h +++ b/application/NotifyMessage.h @@ -12,10 +12,12 @@ enum { STR_ROOM_SUBJECT, PTR_AVATAR_BITMAP, + PTR_ROOM_BITMAP, INT_ACCOUNT_STATUS, INT_CONTACT_STATUS, INT_USER_PERMS, + INT_ROOM_MEMBERS, INT_NEW_MESSAGE, INT_NEW_MENTION, diff --git a/application/windows/ConversationInfoWindow.cpp b/application/windows/ConversationInfoWindow.cpp index 6ea4eaf..93ff51e 100644 --- a/application/windows/ConversationInfoWindow.cpp +++ b/application/windows/ConversationInfoWindow.cpp @@ -15,6 +15,8 @@ #include #include +#include "NotifyMessage.h" + #undef B_TRANSLATION_CONTEXT #define B_TRANSLATION_CONTEXT "ConversationInfoWindow" @@ -23,8 +25,8 @@ ConversationInfoWindow::ConversationInfoWindow(Conversation* chat) : BWindow(BRect(200, 200, 300, 400), - B_TRANSLATE("Room information"), B_FLOATING_WINDOW, - B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS), + B_TRANSLATE("Room information"), B_FLOATING_WINDOW_LOOK, + B_NORMAL_WINDOW_FEEL, B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS), fChat(chat) { _InitInterface(); @@ -40,6 +42,45 @@ ConversationInfoWindow::~ConversationInfoWindow() } +void +ConversationInfoWindow::ObserveString(int32 what, BString string) +{ + Lock(); + switch (what) { + case STR_ROOM_NAME: + fNameLabel->SetText(string); + break; + } + Unlock(); +} + + +void +ConversationInfoWindow::ObserveInteger(int32 what, int32 num) +{ + Lock(); + switch (what) { + case INT_ROOM_MEMBERS: + _SetUserCountLabel(num); + break; + } + Unlock(); +} + + +void +ConversationInfoWindow::ObservePointer(int32 what, void* ptr) +{ + Lock(); + switch (what) { + case PTR_ROOM_BITMAP: + fIcon->SetBitmap((BBitmap*)ptr); + break; + } + Unlock(); +} + + void ConversationInfoWindow::_InitInterface() { diff --git a/application/windows/ConversationInfoWindow.h b/application/windows/ConversationInfoWindow.h index 2392f53..7cc59c4 100644 --- a/application/windows/ConversationInfoWindow.h +++ b/application/windows/ConversationInfoWindow.h @@ -22,7 +22,10 @@ public: ConversationInfoWindow(Conversation* chat); ~ConversationInfoWindow(); -// virtual void Observer + virtual void ObserveString(int32 what, BString string); + virtual void ObserveInteger(int32 what, int32 num); + virtual void ObservePointer(int32 what, void* ptr); + private: void _InitInterface(); diff --git a/application/windows/UserInfoWindow.cpp b/application/windows/UserInfoWindow.cpp index c7b0d76..f70f962 100644 --- a/application/windows/UserInfoWindow.cpp +++ b/application/windows/UserInfoWindow.cpp @@ -18,6 +18,7 @@ #include #include "ImageCache.h" +#include "NotifyMessage.h" #include "User.h" #include "Utils.h" @@ -29,12 +30,20 @@ UserInfoWindow::UserInfoWindow(User* user) : BWindow(BRect(200, 200, 300, 400), - B_TRANSLATE("User information"), B_FLOATING_WINDOW, - B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS), - fUser(user) + B_TRANSLATE("User information"), B_FLOATING_WINDOW_LOOK, + B_NORMAL_WINDOW_FEEL, B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS), + fUser(user) { _InitInterface(); MoveTo(BAlert::AlertPosition(Bounds().Width(), Bounds().Height() / 2)); + + fUser->RegisterObserver(this); +} + + +UserInfoWindow::~UserInfoWindow() +{ + fUser->UnregisterObserver(this); } @@ -49,25 +58,66 @@ UserInfoWindow::MessageReceived(BMessage* message) } +void +UserInfoWindow::ObserveString(int32 what, BString string) +{ + Lock(); + switch (what) { + case STR_CONTACT_NAME: + fNameLabel->SetText(string); + break; + case STR_PERSONAL_STATUS: + fTextStatusLabel->SetText(string); + break; + } + Unlock(); +} + + +void +UserInfoWindow::ObserveInteger(int32 what, int32 num) +{ + Lock(); + switch (what) { + case INT_CONTACT_STATUS: + _UpdateStatusViews((UserStatus)num); + break; + } + Unlock(); +} + + +void +UserInfoWindow::ObservePointer(int32 what, void* ptr) +{ + Lock(); + switch (what) { + case PTR_AVATAR_BITMAP: + fAvatar->SetBitmap((BBitmap*)ptr); + break; + } + Unlock(); +} + + + void UserInfoWindow::_InitInterface() { fNameLabel = new BStringView("nameLabel", fUser->GetName().String()); fNameLabel->SetFont(be_bold_font); - UserStatus status = fUser->GetNotifyStatus(); - fStatusLabel = new BStringView("statusLabel", UserStatusToString(status)); + fStatusLabel = new BStringView("statusLabel", ""); float iconSize = be_plain_font->Size() + 5; - BBitmap* statusBitmap = - ImageCache::Get()->GetImage(UserStatusToImageKey(status)); fStatusIcon = new BitmapView("statusIcon"); fStatusIcon->SetExplicitMaxSize(BSize(iconSize, iconSize)); - fStatusIcon->SetBitmap(statusBitmap); fTextStatusLabel = new BStringView("statusMessageLabel", fUser->GetNotifyPersonalStatus()); + _UpdateStatusViews(fUser->GetNotifyStatus()); + const char* userId = fUser->GetId().String(); fIdLabel = new BTextView("idLabel"); fIdLabel->SetText(userId); @@ -109,3 +159,14 @@ UserInfoWindow::_InitInterface() .End() .End(); } + + +void +UserInfoWindow::_UpdateStatusViews(UserStatus status) +{ + fStatusLabel->SetText(UserStatusToString(status)); + + BBitmap* statusBitmap = + ImageCache::Get()->GetImage(UserStatusToImageKey(status)); + fStatusIcon->SetBitmap(statusBitmap); +} diff --git a/application/windows/UserInfoWindow.h b/application/windows/UserInfoWindow.h index 829d6f1..0a708be 100644 --- a/application/windows/UserInfoWindow.h +++ b/application/windows/UserInfoWindow.h @@ -13,6 +13,8 @@ #include #include #include + +#include "AppConstants.h" #include "Observer.h" class BitmapView; @@ -22,12 +24,19 @@ class User; class UserInfoWindow: public BWindow, public Observer { public: UserInfoWindow(User* user); + ~UserInfoWindow(); virtual void MessageReceived(BMessage* message); + virtual void ObserveString(int32 what, BString string); + virtual void ObserveInteger(int32 what, int32 num); + virtual void ObservePointer(int32 what, void* ptr); + private: void _InitInterface(); + void _UpdateStatusViews(UserStatus status); + User* fUser; BitmapView* fAvatar;