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
|
|
|
*/
|
2021-05-23 14:39:07 -05:00
|
|
|
#include "Contact.h"
|
2010-05-07 04:47:10 -05:00
|
|
|
|
2012-05-15 11:48:53 -05:00
|
|
|
#include "CayaPreferences.h"
|
2010-05-07 04:47:10 -05:00
|
|
|
#include "ChatWindow.h"
|
|
|
|
#include "RosterItem.h"
|
|
|
|
#include "WindowsManager.h"
|
|
|
|
|
2010-05-28 12:20:02 -05:00
|
|
|
|
2021-05-23 14:39:07 -05:00
|
|
|
Contact::Contact(BString id, BMessenger msgn)
|
2010-05-19 17:28:26 -05:00
|
|
|
:
|
2021-05-23 15:10:14 -05:00
|
|
|
User::User(id, msgn),
|
2010-05-19 17:28:26 -05:00
|
|
|
fChatWindow(NULL),
|
2012-06-07 11:46:07 -05:00
|
|
|
fNewWindow(true)
|
2010-05-07 04:47:10 -05:00
|
|
|
{
|
|
|
|
fRosterItem = new RosterItem(id.String(), this);
|
|
|
|
RegisterObserver(fRosterItem);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-19 13:05:30 -05:00
|
|
|
ChatWindow*
|
2021-05-23 14:39:07 -05:00
|
|
|
Contact::GetChatWindow()
|
2010-05-07 04:47:10 -05:00
|
|
|
{
|
|
|
|
if (fChatWindow == NULL)
|
2021-05-23 15:10:14 -05:00
|
|
|
_CreateChatWindow();
|
2010-05-07 04:47:10 -05:00
|
|
|
return fChatWindow;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-19 13:05:30 -05:00
|
|
|
void
|
2021-05-23 14:39:07 -05:00
|
|
|
Contact::DeleteWindow()
|
2010-05-07 04:47:10 -05:00
|
|
|
{
|
|
|
|
if (fChatWindow != NULL) {
|
|
|
|
if (fChatWindow->Lock()) {
|
|
|
|
UnregisterObserver(fChatWindow);
|
|
|
|
fChatWindow->Quit();
|
|
|
|
fChatWindow = NULL;
|
2012-06-07 11:46:07 -05:00
|
|
|
fNewWindow = true;
|
2010-05-07 04:47:10 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2021-05-23 14:39:07 -05:00
|
|
|
Contact::ShowWindow(bool typing, bool userAction)
|
2010-05-07 04:47:10 -05:00
|
|
|
{
|
|
|
|
if (fChatWindow == NULL)
|
2021-05-23 15:10:14 -05:00
|
|
|
_CreateChatWindow();
|
2010-05-19 13:05:30 -05:00
|
|
|
|
2012-06-07 11:46:07 -05:00
|
|
|
fChatWindow->AvoidFocus(true);
|
|
|
|
|
2010-05-19 13:05:30 -05:00
|
|
|
if (CayaPreferences::Item()->MoveToCurrentWorkspace)
|
|
|
|
fChatWindow->SetWorkspaces(B_CURRENT_WORKSPACE);
|
|
|
|
|
2012-06-07 11:46:07 -05:00
|
|
|
if (fNewWindow || userAction) {
|
|
|
|
fChatWindow->AvoidFocus(false);
|
|
|
|
fChatWindow->ShowWindow();
|
|
|
|
fNewWindow = false;
|
|
|
|
} else {
|
|
|
|
if (typing) {
|
|
|
|
if (CayaPreferences::Item()->RaiseUserIsTyping)
|
|
|
|
fChatWindow->ShowWindow();
|
|
|
|
} else {
|
|
|
|
if (CayaPreferences::Item()->RaiseOnMessageReceived
|
|
|
|
|| fChatWindow->IsHidden())
|
|
|
|
fChatWindow->ShowWindow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fChatWindow->AvoidFocus(false);
|
2010-05-07 04:47:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2021-05-23 14:39:07 -05:00
|
|
|
Contact::HideWindow()
|
2010-05-07 04:47:10 -05:00
|
|
|
{
|
|
|
|
if ((fChatWindow != NULL) && !fChatWindow->IsHidden())
|
|
|
|
fChatWindow->Hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-07 13:22:09 -06:00
|
|
|
RosterItem*
|
2021-05-23 14:39:07 -05:00
|
|
|
Contact::GetRosterItem() const
|
2012-03-07 13:22:09 -06:00
|
|
|
{
|
|
|
|
return fRosterItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
void
|
2021-05-23 14:39:07 -05:00
|
|
|
Contact::SetNotifyAvatarBitmap(BBitmap* bitmap)
|
2010-05-07 04:47:10 -05:00
|
|
|
{
|
2021-05-23 15:10:14 -05:00
|
|
|
User::SetNotifyAvatarBitmap(bitmap);
|
|
|
|
if (fAvatarBitmap != NULL && fChatWindow != NULL)
|
|
|
|
fChatWindow->UpdateAvatar();
|
2010-05-07 04:47:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2021-05-23 15:10:14 -05:00
|
|
|
Contact::_CreateChatWindow()
|
2010-05-07 04:47:10 -05:00
|
|
|
{
|
|
|
|
fChatWindow = new ChatWindow(this);
|
|
|
|
WindowsManager::Get()->RelocateWindow(fChatWindow);
|
|
|
|
RegisterObserver(fChatWindow);
|
|
|
|
}
|