2010-05-07 04:47:10 -05:00
|
|
|
/*
|
2011-12-03 16:38:03 -06:00
|
|
|
* Copyright 2009-2011, Andrea Anzani. All rights reserved.
|
2012-05-01 16:09:56 -05:00
|
|
|
* Copyright 2012, Dario Casalinuovo. All rights reserved.
|
2010-05-07 04:47:10 -05:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Andrea Anzani, andrea.anzani@gmail.com
|
2012-05-01 16:09:56 -05:00
|
|
|
* Dario Casalinuovo
|
2010-05-07 04:47:10 -05:00
|
|
|
*/
|
2012-05-15 11:48:53 -05:00
|
|
|
#include "ContactLinker.h"
|
2010-05-07 04:47:10 -05:00
|
|
|
|
2012-05-01 16:09:56 -05:00
|
|
|
#include <libinterface/BitmapUtils.h>
|
2010-05-07 04:47:10 -05:00
|
|
|
|
2012-05-15 11:48:53 -05:00
|
|
|
#include "CayaUtils.h"
|
|
|
|
#include "CayaPreferences.h"
|
2010-05-16 16:02:50 -05:00
|
|
|
#include "CayaProtocolAddOn.h"
|
2012-05-15 11:48:53 -05:00
|
|
|
#include "CayaResources.h"
|
2010-05-07 04:47:10 -05:00
|
|
|
#include "ChatWindow.h"
|
|
|
|
#include "ContactPopUp.h"
|
|
|
|
#include "NotifyMessage.h"
|
2010-05-28 12:20:02 -05:00
|
|
|
#include "ProtocolLooper.h"
|
2010-05-07 04:47:10 -05:00
|
|
|
#include "ProtocolManager.h"
|
|
|
|
#include "RosterItem.h"
|
|
|
|
#include "WindowsManager.h"
|
|
|
|
|
2012-05-01 16:09:56 -05:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2010-05-28 12:20:02 -05:00
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
ContactLinker::ContactLinker(BString id, BMessenger msgn)
|
2010-05-19 17:28:26 -05:00
|
|
|
:
|
|
|
|
fChatWindow(NULL),
|
2010-05-07 04:47:10 -05:00
|
|
|
fID(id),
|
|
|
|
fName(id),
|
|
|
|
fMessenger(msgn),
|
2010-05-16 16:02:50 -05:00
|
|
|
fLooper(NULL),
|
2010-05-07 04:47:10 -05:00
|
|
|
fStatus(CAYA_OFFLINE),
|
|
|
|
fPopUp(NULL)
|
|
|
|
{
|
|
|
|
// Create the roster item and register it as observer
|
|
|
|
fRosterItem = new RosterItem(id.String(), this);
|
|
|
|
RegisterObserver(fRosterItem);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-19 13:05:30 -05:00
|
|
|
ChatWindow*
|
2010-05-07 04:47:10 -05:00
|
|
|
ContactLinker::GetChatWindow()
|
|
|
|
{
|
|
|
|
if (fChatWindow == NULL)
|
|
|
|
CreateChatWindow();
|
|
|
|
return fChatWindow;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-19 13:05:30 -05:00
|
|
|
void
|
2010-05-07 04:47:10 -05:00
|
|
|
ContactLinker::DeleteWindow()
|
|
|
|
{
|
|
|
|
if (fChatWindow != NULL) {
|
|
|
|
if (fChatWindow->Lock()) {
|
|
|
|
UnregisterObserver(fChatWindow);
|
|
|
|
fChatWindow->Quit();
|
|
|
|
fChatWindow = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
ContactLinker::ShowWindow()
|
|
|
|
{
|
|
|
|
if (fChatWindow == NULL)
|
|
|
|
CreateChatWindow();
|
2010-05-19 13:05:30 -05:00
|
|
|
|
|
|
|
if (CayaPreferences::Item()->MoveToCurrentWorkspace)
|
|
|
|
fChatWindow->SetWorkspaces(B_CURRENT_WORKSPACE);
|
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
if (fChatWindow->IsHidden())
|
|
|
|
fChatWindow->Show();
|
2010-05-19 13:05:30 -05:00
|
|
|
|
2012-03-19 15:43:18 -05:00
|
|
|
if (fChatWindow->IsMinimized())
|
|
|
|
fChatWindow->Minimize(false);
|
|
|
|
|
2012-03-08 18:35:02 -06:00
|
|
|
if (CayaPreferences::Item()->FocusOnMessageReceived == true
|
|
|
|
|| CayaPreferences::Item()->FocusUserIsTyping == true)
|
2010-05-19 13:05:30 -05:00
|
|
|
fChatWindow->Activate(true);
|
2010-05-07 04:47:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
ContactLinker::HideWindow()
|
|
|
|
{
|
|
|
|
if ((fChatWindow != NULL) && !fChatWindow->IsHidden())
|
|
|
|
fChatWindow->Hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
ContactLinker::ShowPopUp(BPoint where)
|
|
|
|
{
|
|
|
|
if (fPopUp == NULL) {
|
|
|
|
fPopUp = new ContactPopUp(this);
|
|
|
|
RegisterObserver(fPopUp);
|
|
|
|
}
|
|
|
|
|
|
|
|
fPopUp->Show();
|
|
|
|
fPopUp->MoveTo(where);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
ContactLinker::HidePopUp()
|
|
|
|
{
|
|
|
|
if ((fPopUp != NULL) && !fPopUp->IsHidden())
|
|
|
|
fPopUp->Hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
ContactLinker::DeletePopUp()
|
|
|
|
{
|
|
|
|
if (fPopUp == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (fPopUp->Lock()) {
|
|
|
|
UnregisterObserver(fPopUp);
|
|
|
|
fPopUp->Quit();
|
|
|
|
fPopUp = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-07 13:22:09 -06:00
|
|
|
RosterItem*
|
|
|
|
ContactLinker::GetRosterItem() const
|
|
|
|
{
|
|
|
|
return fRosterItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BString
|
|
|
|
ContactLinker::GetId() const
|
|
|
|
{
|
|
|
|
return fID;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-16 16:02:50 -05:00
|
|
|
BMessenger
|
|
|
|
ContactLinker::Messenger() const
|
|
|
|
{
|
|
|
|
return fMessenger;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
ContactLinker::SetMessenger(BMessenger messenger)
|
|
|
|
{
|
|
|
|
fMessenger = messenger;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ProtocolLooper*
|
|
|
|
ContactLinker::GetProtocolLooper() const
|
|
|
|
{
|
|
|
|
return fLooper;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-07 13:22:09 -06:00
|
|
|
BString
|
|
|
|
ContactLinker::GetName() const
|
|
|
|
{
|
|
|
|
return fName;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BBitmap*
|
|
|
|
ContactLinker::AvatarBitmap() const
|
|
|
|
{
|
|
|
|
return fAvatarBitmap;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-01 14:48:15 -05:00
|
|
|
BBitmap*
|
|
|
|
ContactLinker::ProtocolBitmap() const
|
|
|
|
{
|
|
|
|
CayaProtocol* protocol = fLooper->Protocol();
|
|
|
|
CayaProtocolAddOn* addOn
|
|
|
|
= ProtocolManager::Get()->ProtocolAddOn(protocol->Signature());
|
|
|
|
|
|
|
|
return addOn->Icon();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-07 13:22:09 -06:00
|
|
|
CayaStatus
|
|
|
|
ContactLinker::GetNotifyStatus() const
|
|
|
|
{
|
|
|
|
return fStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BString
|
|
|
|
ContactLinker::GetNotifyPersonalStatus() const
|
|
|
|
{
|
|
|
|
return fPersonalStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-16 16:02:50 -05:00
|
|
|
void
|
|
|
|
ContactLinker::SetProtocolLooper(ProtocolLooper* looper)
|
|
|
|
{
|
2010-05-28 12:20:02 -05:00
|
|
|
if (looper) {
|
2010-05-16 16:02:50 -05:00
|
|
|
fLooper = looper;
|
2010-05-28 12:20:02 -05:00
|
|
|
|
2012-05-01 16:09:56 -05:00
|
|
|
// By default we use the Person icon as avatar icon
|
|
|
|
BResources* res = CayaResources();
|
|
|
|
BBitmap* bitmap = IconFromResources(res,
|
|
|
|
kPersonIcon, B_LARGE_ICON);
|
|
|
|
|
|
|
|
SetNotifyAvatarBitmap(bitmap);
|
2010-05-28 12:20:02 -05:00
|
|
|
}
|
2010-05-16 16:02:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
void
|
|
|
|
ContactLinker::SetNotifyName(BString name)
|
2010-05-19 13:05:30 -05:00
|
|
|
{
|
|
|
|
if (fName.Compare(name) != 0) {
|
2010-05-07 04:47:10 -05:00
|
|
|
fName = name;
|
|
|
|
NotifyString(STR_CONTACT_NAME, name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
ContactLinker::SetNotifyAvatarBitmap(BBitmap* bitmap)
|
|
|
|
{
|
|
|
|
if ((fAvatarBitmap != bitmap) && (bitmap != NULL)) {
|
|
|
|
fAvatarBitmap = bitmap;
|
|
|
|
NotifyPointer(PTR_AVATAR_BITMAP, (void*)bitmap);
|
2012-03-07 13:22:09 -06:00
|
|
|
if (fChatWindow != NULL)
|
|
|
|
fChatWindow->UpdateAvatar();
|
2010-05-07 04:47:10 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
ContactLinker::SetNotifyStatus(CayaStatus status)
|
|
|
|
{
|
|
|
|
if (fStatus != status) {
|
|
|
|
fStatus = status;
|
|
|
|
NotifyInteger(INT_CONTACT_STATUS, (int32)fStatus);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
ContactLinker::SetNotifyPersonalStatus(BString personalStatus)
|
|
|
|
{
|
|
|
|
if (fPersonalStatus.Compare(personalStatus) != 0) {
|
|
|
|
fPersonalStatus = personalStatus;
|
|
|
|
NotifyString(STR_PERSONAL_STATUS, personalStatus);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
ContactLinker::CreateChatWindow()
|
|
|
|
{
|
|
|
|
fChatWindow = new ChatWindow(this);
|
|
|
|
WindowsManager::Get()->RelocateWindow(fChatWindow);
|
|
|
|
RegisterObserver(fChatWindow);
|
|
|
|
}
|