diff --git a/application/ProtocolLooper.cpp b/application/ProtocolLooper.cpp index cafa399..007a41d 100644 --- a/application/ProtocolLooper.cpp +++ b/application/ProtocolLooper.cpp @@ -193,8 +193,10 @@ ProtocolLooper::GetOwnContact() void ProtocolLooper::SetOwnContact(Contact* contact) { - if (contact != NULL) + if (contact != NULL) { fMySelf = contact; + AddUser(contact); + } } diff --git a/application/Server.cpp b/application/Server.cpp index 543b94a..85abcbe 100644 --- a/application/Server.cpp +++ b/application/Server.cpp @@ -279,6 +279,17 @@ Server::ImMessage(BMessage* msg) } break; } + case IM_OWN_NICKNAME_SET: + { + BString nick = msg->FindString("user_name"); + ProtocolLooper* looper = _LooperFromMessage(msg); + if (looper == NULL) + break; + Contact* contact = looper->GetOwnContact(); + if (contact != NULL) + contact->SetNotifyName(nick.String()); + break; + } case IM_STATUS_SET: { int32 status; diff --git a/application/User.cpp b/application/User.cpp index cefcf1f..4fbd8b4 100644 --- a/application/User.cpp +++ b/application/User.cpp @@ -22,7 +22,6 @@ #include "NotifyMessage.h" #include "ProtocolLooper.h" #include "ProtocolManager.h" -#include "UserItem.h" #include "UserPopUp.h" #include "Utils.h" @@ -33,7 +32,6 @@ User::User(BString id, BMessenger msgn) fName(id), fMessenger(msgn), fLooper(NULL), - fListItem(NULL), fItemColor(ForegroundColor(ui_color(B_LIST_BACKGROUND_COLOR))), fStatus(STATUS_ONLINE), fAvatarBitmap(NULL), @@ -148,17 +146,6 @@ User::ProtocolBitmap() const } -UserItem* -User::GetListItem() -{ - if (fListItem == NULL) { - fListItem = new UserItem(fName, this, (int32)fStatus); - RegisterObserver(fListItem); - } - return fListItem; -} - - UserStatus User::GetNotifyStatus() const { diff --git a/application/User.h b/application/User.h index 129b49d..967afd8 100644 --- a/application/User.h +++ b/application/User.h @@ -22,7 +22,6 @@ class BBitmap; class Conversation; class ProtocolLooper; -class UserItem; class UserPopUp; @@ -51,8 +50,6 @@ public: void SetProtocolLooper(ProtocolLooper* looper); BBitmap* ProtocolBitmap() const; - UserItem* GetListItem(); - BString GetName() const; BBitmap* AvatarBitmap() const; UserStatus GetNotifyStatus() const; @@ -76,8 +73,6 @@ protected: BMessenger fMessenger; ProtocolLooper* fLooper; - UserItem* fListItem; - BString fID; BString fName; BString fPersonalStatus; diff --git a/application/views/ConversationView.cpp b/application/views/ConversationView.cpp index b8ae76a..cda259f 100644 --- a/application/views/ConversationView.cpp +++ b/application/views/ConversationView.cpp @@ -30,7 +30,6 @@ #include "RenderView.h" #include "SendTextView.h" #include "User.h" -#include "UserItem.h" #include "UserListView.h" #include "Utils.h" @@ -273,8 +272,8 @@ ConversationView::UpdateUserList(UserMap users) fUserList->MakeEmpty(); for (int i = 0; i < users.CountItems(); i++) { User* user = users.ValueAt(i); - if (fUserList->HasItem(user->GetListItem()) == false) { - fUserList->AddItem(user->GetListItem()); + if (fUserList->HasUser(user) == false) { + fUserList->AddUser(user); fUserList->Sort(); } } diff --git a/application/views/UserItem.cpp b/application/views/UserItem.cpp index 7f61e26..5c80430 100644 --- a/application/views/UserItem.cpp +++ b/application/views/UserItem.cpp @@ -14,12 +14,19 @@ #include "Utils.h" -UserItem::UserItem(const char* name, User* user, int32 status) +UserItem::UserItem(User* user) : - BStringItem(name), + BStringItem(user->GetName()), fUser(user), - fStatus(status) + fStatus(user->GetNotifyStatus()) { + user->RegisterObserver(this); +} + + +UserItem::~UserItem() +{ + fUser->UnregisterObserver(this); } @@ -81,5 +88,3 @@ UserItem::_GetTextColor(rgb_color highColor) } return highColor; } - - diff --git a/application/views/UserItem.h b/application/views/UserItem.h index c9d5b9c..9cd59e3 100644 --- a/application/views/UserItem.h +++ b/application/views/UserItem.h @@ -15,23 +15,22 @@ class User; class UserItem : public BStringItem, public Observer { public: - UserItem(const char* name, User* user, int32 status); + UserItem(User* user); + ~UserItem(); - void DrawItem(BView* owner, BRect frame, bool complete); + virtual void DrawItem(BView* owner, BRect frame, bool complete); - void ObserveString(int32 what, BString str); - void ObserveInteger(int32 what, int32 value); + virtual void ObserveString(int32 what, BString str); + virtual void ObserveInteger(int32 what, int32 value); - User* GetUser(); + User* GetUser(); protected: - rgb_color _GetTextColor(rgb_color highColor); + rgb_color _GetTextColor(rgb_color highColor); private: User* fUser; int fStatus; }; - #endif // USERITEM_H - diff --git a/application/views/UserListView.cpp b/application/views/UserListView.cpp index 72ebe8a..2733b1c 100644 --- a/application/views/UserListView.cpp +++ b/application/views/UserListView.cpp @@ -69,6 +69,32 @@ UserListView::Sort() } +bool +UserListView::HasUser(User* user) +{ + for (int i = 0; i < CountItems(); i++) + if (user == ((UserItem*)ItemAt(i))->GetUser()) + return true; + return false; +} + + +void +UserListView::AddUser(User* user) +{ + AddItem(new UserItem(user)); +} + + +void +UserListView::RemoveUser(User* user) +{ + for (int i = 0; i < CountItems(); i++) + if (user == ((UserItem*)ItemAt(i))->GetUser()) + RemoveItem(i); +} + + BPopUpMenu* UserListView::_UserPopUp() { diff --git a/application/views/UserListView.h b/application/views/UserListView.h index f3810a3..a79872d 100644 --- a/application/views/UserListView.h +++ b/application/views/UserListView.h @@ -10,7 +10,9 @@ #include "Role.h" class BPopUpMenu; + class Conversation; +class User; enum @@ -33,6 +35,10 @@ public: void Sort(); + bool HasUser(User* user); + void AddUser(User* user); + void RemoveUser(User* user); + void SetConversation(Conversation* chat) { fChat = chat; } private: