diff --git a/application/Contact.cpp b/application/Contact.cpp index 55c3775..8311d51 100644 --- a/application/Contact.cpp +++ b/application/Contact.cpp @@ -9,35 +9,18 @@ */ #include "Contact.h" -#include - -#include "CayaUtils.h" #include "CayaPreferences.h" -#include "CayaProtocolAddOn.h" -#include "CayaResources.h" #include "ChatWindow.h" -#include "ContactPopUp.h" -#include "NotifyMessage.h" -#include "ProtocolLooper.h" -#include "ProtocolManager.h" #include "RosterItem.h" #include "WindowsManager.h" -#include - Contact::Contact(BString id, BMessenger msgn) : + User::User(id, msgn), fChatWindow(NULL), - fID(id), - fName(id), - fMessenger(msgn), - fLooper(NULL), - fStatus(CAYA_OFFLINE), - fPopUp(NULL), fNewWindow(true) { - // Create the roster item and register it as observer fRosterItem = new RosterItem(id.String(), this); RegisterObserver(fRosterItem); } @@ -47,7 +30,7 @@ ChatWindow* Contact::GetChatWindow() { if (fChatWindow == NULL) - CreateChatWindow(); + _CreateChatWindow(); return fChatWindow; } @@ -70,7 +53,7 @@ void Contact::ShowWindow(bool typing, bool userAction) { if (fChatWindow == NULL) - CreateChatWindow(); + _CreateChatWindow(); fChatWindow->AvoidFocus(true); @@ -103,41 +86,6 @@ Contact::HideWindow() } -void -Contact::ShowPopUp(BPoint where) -{ - if (fPopUp == NULL) { - fPopUp = new ContactPopUp(this); - RegisterObserver(fPopUp); - } - - fPopUp->Show(); - fPopUp->MoveTo(where); -} - - -void -Contact::HidePopUp() -{ - if ((fPopUp != NULL) && !fPopUp->IsHidden()) - fPopUp->Hide(); -} - - -void -Contact::DeletePopUp() -{ - if (fPopUp == NULL) - return; - - if (fPopUp->Lock()) { - UnregisterObserver(fPopUp); - fPopUp->Quit(); - fPopUp = NULL; - } -} - - RosterItem* Contact::GetRosterItem() const { @@ -145,133 +93,17 @@ Contact::GetRosterItem() const } -BString -Contact::GetId() const -{ - return fID; -} - - -BMessenger -Contact::Messenger() const -{ - return fMessenger; -} - - -void -Contact::SetMessenger(BMessenger messenger) -{ - fMessenger = messenger; -} - - -ProtocolLooper* -Contact::GetProtocolLooper() const -{ - return fLooper; -} - - -BString -Contact::GetName() const -{ - return fName; -} - - -BBitmap* -Contact::AvatarBitmap() const -{ - return fAvatarBitmap; -} - - -BBitmap* -Contact::ProtocolBitmap() const -{ - CayaProtocol* protocol = fLooper->Protocol(); - CayaProtocolAddOn* addOn - = ProtocolManager::Get()->ProtocolAddOn(protocol->Signature()); - - return addOn->ProtoIcon(); -} - - -CayaStatus -Contact::GetNotifyStatus() const -{ - return fStatus; -} - - -BString -Contact::GetNotifyPersonalStatus() const -{ - return fPersonalStatus; -} - - -void -Contact::SetProtocolLooper(ProtocolLooper* looper) -{ - if (looper) { - fLooper = looper; - - // By default we use the Person icon as avatar icon - BResources* res = CayaResources(); - BBitmap* bitmap = IconFromResources(res, - kPersonIcon, B_LARGE_ICON); - - SetNotifyAvatarBitmap(bitmap); - } -} - - -void -Contact::SetNotifyName(BString name) -{ - if (fName.Compare(name) != 0) { - fName = name; - NotifyString(STR_CONTACT_NAME, name); - } -} - - void Contact::SetNotifyAvatarBitmap(BBitmap* bitmap) { - if ((fAvatarBitmap != bitmap) && (bitmap != NULL)) { - fAvatarBitmap = bitmap; - NotifyPointer(PTR_AVATAR_BITMAP, (void*)bitmap); - if (fChatWindow != NULL) - fChatWindow->UpdateAvatar(); - } + User::SetNotifyAvatarBitmap(bitmap); + if (fAvatarBitmap != NULL && fChatWindow != NULL) + fChatWindow->UpdateAvatar(); } void -Contact::SetNotifyStatus(CayaStatus status) -{ - if (fStatus != status) { - fStatus = status; - NotifyInteger(INT_CONTACT_STATUS, (int32)fStatus); - } -} - - -void -Contact::SetNotifyPersonalStatus(BString personalStatus) -{ - if (fPersonalStatus.Compare(personalStatus) != 0) { - fPersonalStatus = personalStatus; - NotifyString(STR_PERSONAL_STATUS, personalStatus); - } -} - - -void -Contact::CreateChatWindow() +Contact::_CreateChatWindow() { fChatWindow = new ChatWindow(this); WindowsManager::Get()->RelocateWindow(fChatWindow); diff --git a/application/Contact.h b/application/Contact.h index ea1481c..ec9cbb8 100644 --- a/application/Contact.h +++ b/application/Contact.h @@ -10,17 +10,17 @@ #include #include -#include "Notifier.h" #include "CayaConstants.h" +#include "User.h" class BBitmap; class ChatWindow; -class ContactPopUp; class ProtocolLooper; class RosterItem; -class Contact : public Notifier { + +class Contact : public User { public: Contact(BString id, BMessenger msgn); @@ -30,46 +30,15 @@ public: void ShowWindow(bool typing = false, bool userAction = false); void HideWindow(); - void ShowPopUp(BPoint where); - void DeletePopUp(); - void HidePopUp(); - RosterItem* GetRosterItem() const; - BString GetId() const; - - BMessenger Messenger() const; - void SetMessenger(BMessenger messenger); - - ProtocolLooper* GetProtocolLooper() const; - void SetProtocolLooper(ProtocolLooper* looper); - BBitmap* ProtocolBitmap() const; - - BString GetName() const; - BBitmap* AvatarBitmap() const; - CayaStatus GetNotifyStatus() const; - BString GetNotifyPersonalStatus() const; - - void SetNotifyName(BString name); void SetNotifyAvatarBitmap(BBitmap* bitmap); - void SetNotifyStatus(CayaStatus status); - void SetNotifyPersonalStatus(BString personalStatus); private: - void CreateChatWindow(); + void _CreateChatWindow(); RosterItem* fRosterItem; ChatWindow* fChatWindow; - BMessenger fMessenger; - ProtocolLooper* fLooper; - - BString fID; - bigtime_t fInstance; - BString fName; - BString fPersonalStatus; - BBitmap* fAvatarBitmap; - CayaStatus fStatus; - ContactPopUp* fPopUp; bool fNewWindow; }; diff --git a/application/Makefile b/application/Makefile index 3e39758..852d9f3 100644 --- a/application/Makefile +++ b/application/Makefile @@ -49,6 +49,7 @@ SRCS = \ application/ProtocolSettings.cpp \ application/Server.cpp \ application/TheApp.cpp \ + application/User.cpp \ application/WindowsManager.cpp \ application/preferences/AccountDialog.cpp \ application/preferences/AccountListItem.cpp \ @@ -59,17 +60,17 @@ SRCS = \ application/preferences/PreferencesBehavior.cpp \ application/preferences/PreferencesReplicant.cpp \ application/preferences/PreferencesChatWindow.cpp \ - application/views/ContactPopUp.cpp \ application/views/SearchBarTextControl.cpp \ application/views/NicknameTextControl.cpp \ application/views/RosterItem.cpp \ application/views/RosterListView.cpp \ - application/views/ContactInfoWindow.cpp \ application/views/StatusMenuItem.cpp \ application/views/StatusView.cpp \ application/views/CayaRenderView.cpp \ application/views/ReplicantStatusView.cpp \ - application/views/ReplicantMenuItem.cpp + application/views/ReplicantMenuItem.cpp \ + application/views/UserInfoWindow.cpp \ + application/views/UserPopUp.cpp # Specify the resource definition files to use. Full or relative paths can be diff --git a/application/User.cpp b/application/User.cpp new file mode 100644 index 0000000..92e6de8 --- /dev/null +++ b/application/User.cpp @@ -0,0 +1,192 @@ +/* + * Copyright 2009-2011, Andrea Anzani. All rights reserved. + * Copyright 2012, Dario Casalinuovo. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Andrea Anzani, andrea.anzani@gmail.com + * Dario Casalinuovo + */ +#include "User.h" + +#include + +#include "CayaProtocolAddOn.h" +#include "CayaResources.h" +#include "CayaUtils.h" +#include "NotifyMessage.h" +#include "ProtocolLooper.h" +#include "ProtocolManager.h" +#include "UserPopUp.h" + + +User::User(BString id, BMessenger msgn) + : + fID(id), + fName(id), + fMessenger(msgn), + fLooper(NULL), + fStatus(CAYA_OFFLINE), + fPopUp(NULL) +{ +} + + +void +User::ShowPopUp(BPoint where) +{ + if (fPopUp == NULL) { + fPopUp = new UserPopUp(this); + RegisterObserver(fPopUp); + } + + fPopUp->Show(); + fPopUp->MoveTo(where); +} + + +void +User::HidePopUp() +{ + if ((fPopUp != NULL) && !fPopUp->IsHidden()) + fPopUp->Hide(); +} + + +void +User::DeletePopUp() +{ + if (fPopUp == NULL) + return; + + if (fPopUp->Lock()) { + UnregisterObserver(fPopUp); + fPopUp->Quit(); + fPopUp = NULL; + } +} + + +BString +User::GetId() const +{ + return fID; +} + + +BMessenger +User::Messenger() const +{ + return fMessenger; +} + + +void +User::SetMessenger(BMessenger messenger) +{ + fMessenger = messenger; +} + + +ProtocolLooper* +User::GetProtocolLooper() const +{ + return fLooper; +} + + +BString +User::GetName() const +{ + return fName; +} + + +BBitmap* +User::AvatarBitmap() const +{ + return fAvatarBitmap; +} + + +BBitmap* +User::ProtocolBitmap() const +{ + CayaProtocol* protocol = fLooper->Protocol(); + CayaProtocolAddOn* addOn + = ProtocolManager::Get()->ProtocolAddOn(protocol->Signature()); + + return addOn->ProtoIcon(); +} + + +CayaStatus +User::GetNotifyStatus() const +{ + return fStatus; +} + + +BString +User::GetNotifyPersonalStatus() const +{ + return fPersonalStatus; +} + + +void +User::SetProtocolLooper(ProtocolLooper* looper) +{ + if (looper) { + fLooper = looper; + + // By default we use the Person icon as avatar icon + BResources* res = CayaResources(); + BBitmap* bitmap = IconFromResources(res, + kPersonIcon, B_LARGE_ICON); + + SetNotifyAvatarBitmap(bitmap); + } +} + + +void +User::SetNotifyName(BString name) +{ + if (fName.Compare(name) != 0) { + fName = name; + NotifyString(STR_CONTACT_NAME, name); + } +} + + +void +User::SetNotifyAvatarBitmap(BBitmap* bitmap) +{ + if ((fAvatarBitmap != bitmap) && (bitmap != NULL)) { + fAvatarBitmap = bitmap; + NotifyPointer(PTR_AVATAR_BITMAP, (void*)bitmap); + } +} + + +void +User::SetNotifyStatus(CayaStatus status) +{ + if (fStatus != status) { + fStatus = status; + NotifyInteger(INT_CONTACT_STATUS, (int32)fStatus); + } +} + + +void +User::SetNotifyPersonalStatus(BString personalStatus) +{ + if (fPersonalStatus.Compare(personalStatus) != 0) { + fPersonalStatus = personalStatus; + NotifyString(STR_PERSONAL_STATUS, personalStatus); + } +} + + diff --git a/application/User.h b/application/User.h new file mode 100644 index 0000000..ca434af --- /dev/null +++ b/application/User.h @@ -0,0 +1,63 @@ +/* + * Copyright 2009-2011, Andrea Anzani. All rights reserved. + * Copyright 2012, Dario Casalinuovo. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _USER_H_ +#define _USER_H_ + +#include +#include +#include + +#include "Notifier.h" +#include "CayaConstants.h" + +class BBitmap; + +class ChatWindow; +class UserPopUp; +class ProtocolLooper; +class RosterItem; + +class User : public Notifier { +public: + User(BString id, BMessenger msgn); + + void ShowPopUp(BPoint where); + void DeletePopUp(); + void HidePopUp(); + + BString GetId() const; + + BMessenger Messenger() const; + void SetMessenger(BMessenger messenger); + + ProtocolLooper* GetProtocolLooper() const; + void SetProtocolLooper(ProtocolLooper* looper); + BBitmap* ProtocolBitmap() const; + + BString GetName() const; + BBitmap* AvatarBitmap() const; + CayaStatus GetNotifyStatus() const; + BString GetNotifyPersonalStatus() const; + + void SetNotifyName(BString name); + void SetNotifyAvatarBitmap(BBitmap* bitmap); + void SetNotifyStatus(CayaStatus status); + void SetNotifyPersonalStatus(BString personalStatus); + +protected: + BMessenger fMessenger; + ProtocolLooper* fLooper; + + BString fID; + bigtime_t fInstance; + BString fName; + BString fPersonalStatus; + BBitmap* fAvatarBitmap; + CayaStatus fStatus; + UserPopUp* fPopUp; +}; + +#endif // _USER_H_ diff --git a/application/views/RosterListView.cpp b/application/views/RosterListView.cpp index 4e87c5f..576fe65 100644 --- a/application/views/RosterListView.cpp +++ b/application/views/RosterListView.cpp @@ -16,7 +16,7 @@ #include #include -#include "ContactInfoWindow.h" +#include "UserInfoWindow.h" #include "Contact.h" #include "RosterItem.h" @@ -223,6 +223,6 @@ RosterListView::Sort() void RosterListView::_InfoWindow(Contact* linker) { - ContactInfoWindow* win = new ContactInfoWindow(linker); + UserInfoWindow* win = new UserInfoWindow(linker); win->Show(); } diff --git a/application/views/ContactInfoWindow.cpp b/application/views/UserInfoWindow.cpp similarity index 78% rename from application/views/ContactInfoWindow.cpp rename to application/views/UserInfoWindow.cpp index b3a9def..eb0e2c4 100644 --- a/application/views/ContactInfoWindow.cpp +++ b/application/views/UserInfoWindow.cpp @@ -6,7 +6,7 @@ * Casalinuovo Dario */ -#include "ContactInfoWindow.h" +#include "UserInfoWindow.h" #include #include @@ -24,34 +24,34 @@ #include "CayaMessages.h" #include "CayaProtocolMessages.h" -#include "Contact.h" #include "CayaConstants.h" #include "CayaRenderView.h" #include "CayaUtils.h" #include "NotifyMessage.h" +#include "User.h" -ContactInfoWindow::ContactInfoWindow(Contact* linker) +UserInfoWindow::UserInfoWindow(User* user) : BWindow(BRect(200, 200, 500, 400), - "Contact Informations", B_FLOATING_WINDOW, + "User information", B_FLOATING_WINDOW, B_NOT_ZOOMABLE | B_NOT_RESIZABLE), - fContact(linker) + fUser(user) { fPersonalMessage = new BTextView("personalMessage", B_WILL_DRAW); fPersonalMessage->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, B_ALIGN_MIDDLE)); - fPersonalMessage->SetText(fContact->GetNotifyPersonalStatus()); + fPersonalMessage->SetText(fUser->GetNotifyPersonalStatus()); fPersonalMessage->SetExplicitMaxSize(BSize(200, 200)); fPersonalMessage->MakeEditable(false); fPersonalMessage->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - BString status(fContact->GetName()); - status << CayaStatusToString(fContact->GetNotifyStatus()); + BString status(fUser->GetName()); + status << CayaStatusToString(fUser->GetNotifyStatus()); status << "\n\n ID : "; - status << fContact->GetId(); + status << fUser->GetId(); fStatus = new BTextView("status", B_WILL_DRAW); fStatus->SetText(status); @@ -60,12 +60,12 @@ ContactInfoWindow::ContactInfoWindow(Contact* linker) SetLayout(new BGroupLayout(B_HORIZONTAL)); - fAvatar = new BitmapView("ContactIcon"); + fAvatar = new BitmapView("UserIcon"); fAvatar->SetExplicitMaxSize(BSize(70, 70)); fAvatar->SetExplicitMinSize(BSize(50, 50)); fAvatar->SetExplicitPreferredSize(BSize(50, 50)); fAvatar->SetExplicitAlignment(BAlignment(B_ALIGN_RIGHT, B_ALIGN_MIDDLE)); - fAvatar->SetBitmap(fContact->AvatarBitmap()); + fAvatar->SetBitmap(fUser->AvatarBitmap()); AddChild(BGroupLayoutBuilder(B_VERTICAL, 10) .AddGroup(B_HORIZONTAL) @@ -83,7 +83,7 @@ ContactInfoWindow::ContactInfoWindow(Contact* linker) void -ContactInfoWindow::MessageReceived(BMessage* message) +UserInfoWindow::MessageReceived(BMessage* message) { switch (message->what) { default: diff --git a/application/views/ContactInfoWindow.h b/application/views/UserInfoWindow.h similarity index 64% rename from application/views/ContactInfoWindow.h rename to application/views/UserInfoWindow.h index eaa1152..a009989 100644 --- a/application/views/ContactInfoWindow.h +++ b/application/views/UserInfoWindow.h @@ -5,8 +5,8 @@ * Authors: * Casalinuovo Dario */ -#ifndef _CONTACT_INFO_WINDOW_H -#define _CONTACT_INFO_WINDOW_H +#ifndef _USER_INFO_WINDOW_H +#define _USER_INFO_WINDOW_H #include #include @@ -16,19 +16,22 @@ #include "CayaConstants.h" class BitmapView; -class Contact; +class User; -class ContactInfoWindow: public BWindow, public Observer { + +class UserInfoWindow: public BWindow, public Observer { public: - ContactInfoWindow(Contact* linker); + UserInfoWindow(User* user); virtual void MessageReceived(BMessage* message); + private: - BTextView* fStatus; - Contact* fContact; + BTextView* fStatus; + User* fUser; BTextView* fPersonalMessage; BitmapView* fAvatar; - }; -#endif + +#endif // _USER_INFO_WINDOW_H + diff --git a/application/views/ContactPopUp.cpp b/application/views/UserPopUp.cpp similarity index 74% rename from application/views/ContactPopUp.cpp rename to application/views/UserPopUp.cpp index 6989264..5d5bec2 100644 --- a/application/views/ContactPopUp.cpp +++ b/application/views/UserPopUp.cpp @@ -6,7 +6,7 @@ * Pier Luigi Fiorini, pierluigi.fiorini@gmail.com */ -#include "ContactPopUp.h" +#include "UserPopUp.h" #include #include @@ -15,7 +15,7 @@ #include -#include "Contact.h" +#include "User.h" #include "NotifyMessage.h" @@ -24,23 +24,23 @@ const window_feel kMenuWindowFeel = window_feel(B_NORMAL_WINDOW_FEEL); const int32 kNickChanged = 'NICH'; -ContactPopUp::ContactPopUp(Contact* contact) - : BWindow(BRect(0, 0, 1, 1), "ContactPopUp", B_BORDERED_WINDOW_LOOK, +UserPopUp::UserPopUp(User* user) + : BWindow(BRect(0, 0, 1, 1), "UserPopUp", B_BORDERED_WINDOW_LOOK, kMenuWindowFeel, B_NOT_MOVABLE | B_NOT_CLOSABLE | B_NOT_MINIMIZABLE | B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS | B_AVOID_FOCUS | B_AUTO_UPDATE_SIZE_LIMITS), fCoords(B_ORIGIN) { // Box to change nick name - fNickBox = new BTextControl("nickBox", NULL, contact->GetName(), + fNickBox = new BTextControl("nickBox", NULL, user->GetName(), new BMessage(kNickChanged)); // Real nick name - fLabel = new BStringView("label", contact->GetId()); + fLabel = new BStringView("label", user->GetId()); // Avatar bitmap fAvatarView = new BitmapView("avatarView"); - fAvatarView->SetBitmap(contact->AvatarBitmap()); + fAvatarView->SetBitmap(user->AvatarBitmap()); // Layout SetLayout(new BGroupLayout(B_VERTICAL)); @@ -58,7 +58,7 @@ ContactPopUp::ContactPopUp(Contact* contact) void -ContactPopUp::MessageReceived(BMessage* msg) +UserPopUp::MessageReceived(BMessage* msg) { switch (msg->what) { case kNickChanged: @@ -70,7 +70,7 @@ ContactPopUp::MessageReceived(BMessage* msg) void -ContactPopUp::MoveTo(BPoint where) +UserPopUp::MoveTo(BPoint where) { if (fCoords != where) { if (Lock()) { @@ -83,7 +83,7 @@ ContactPopUp::MoveTo(BPoint where) void -ContactPopUp::ObserveString(int32 what, BString str) +UserPopUp::ObserveString(int32 what, BString str) { switch (what) { case STR_CONTACT_NAME: @@ -97,7 +97,7 @@ ContactPopUp::ObserveString(int32 what, BString str) void -ContactPopUp::ObservePointer(int32 what, void* ptr) +UserPopUp::ObservePointer(int32 what, void* ptr) { switch (what) { case PTR_AVATAR_BITMAP: @@ -111,7 +111,7 @@ ContactPopUp::ObservePointer(int32 what, void* ptr) void -ContactPopUp::ObserveInteger(int32 what, int32 val) +UserPopUp::ObserveInteger(int32 what, int32 val) { switch (what) { case INT_CONTACT_STATUS: diff --git a/application/views/ContactPopUp.h b/application/views/UserPopUp.h similarity index 75% rename from application/views/ContactPopUp.h rename to application/views/UserPopUp.h index ea10d42..90831f4 100644 --- a/application/views/ContactPopUp.h +++ b/application/views/UserPopUp.h @@ -2,8 +2,8 @@ * Copyright 2009, Pier Luigi Fiorini. All rights reserved. * Distributed under the terms of the MIT License. */ -#ifndef _CONTACT_POPUP_H -#define _CONTACT_POPUP_H +#ifndef _USER_POPUP_H +#define _USER_POPUP_H #include @@ -13,11 +13,11 @@ class BTextControl; class BStringView; class BitmapView; -class Contact; +class User; -class ContactPopUp : public BWindow, public Observer { +class UserPopUp : public BWindow, public Observer { public: - ContactPopUp(Contact* contact); + UserPopUp(User* user); virtual void MessageReceived(BMessage* msg); @@ -35,4 +35,6 @@ private: BitmapView* fAvatarView; }; -#endif // _CONTACT_POPUP_H + +#endif // _USER_POPUP_H +