2010-05-07 04:47:10 -05:00
|
|
|
/*
|
|
|
|
* Copyright 2009, Andrea Anzani. All rights reserved.
|
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Andrea Anzani, andrea.anzani@gmail.com
|
|
|
|
* Pier Luigi Fiorini, pierluigi.fiorini@gmail.com
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <ListView.h>
|
|
|
|
|
2010-05-12 13:59:17 -05:00
|
|
|
#include <libinterface/BitmapUtils.h>
|
|
|
|
|
2021-06-20 12:44:20 -05:00
|
|
|
#include "AppResources.h"
|
2021-05-23 14:39:07 -05:00
|
|
|
#include "Contact.h"
|
2010-05-07 04:47:10 -05:00
|
|
|
#include "NotifyMessage.h"
|
|
|
|
#include "RosterItem.h"
|
2021-06-20 12:44:20 -05:00
|
|
|
#include "Utils.h"
|
2010-05-07 04:47:10 -05:00
|
|
|
|
|
|
|
|
2021-05-23 14:39:07 -05:00
|
|
|
RosterItem::RosterItem(const char* name, Contact* contact)
|
2010-05-07 04:47:10 -05:00
|
|
|
: BStringItem(name),
|
|
|
|
fBitmap(NULL),
|
2021-06-20 12:44:20 -05:00
|
|
|
fStatus(STATUS_OFFLINE),
|
2010-05-07 04:47:10 -05:00
|
|
|
contactLinker(contact),
|
|
|
|
fVisible(true)
|
|
|
|
{
|
|
|
|
rgb_color highlightColor = ui_color(B_CONTROL_HIGHLIGHT_COLOR);
|
|
|
|
rgb_color darkenHighlightColor = tint_color(highlightColor, B_DARKEN_1_TINT);
|
|
|
|
|
|
|
|
fGradient.AddColor(highlightColor, 0);
|
|
|
|
fGradient.AddColor(darkenHighlightColor, 255);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
RosterItem::~RosterItem()
|
|
|
|
{
|
|
|
|
delete fBitmap;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
RosterItem::SetVisible(bool visible)
|
|
|
|
{
|
|
|
|
fVisible = visible;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
RosterItem::SetBitmap(BBitmap* bitmap)
|
|
|
|
{
|
|
|
|
if (fBitmap != NULL)
|
|
|
|
delete fBitmap;
|
|
|
|
fBitmap = bitmap;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
RosterItem::ObserveString(int32 what, BString str)
|
|
|
|
{
|
|
|
|
switch (what) {
|
|
|
|
case STR_CONTACT_NAME:
|
|
|
|
SetText(str);
|
|
|
|
break;
|
|
|
|
case STR_PERSONAL_STATUS:
|
|
|
|
SetPersonalStatus(str);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
RosterItem::ObservePointer(int32 what, void* ptr)
|
|
|
|
{
|
|
|
|
switch (what) {
|
|
|
|
case PTR_AVATAR_BITMAP:
|
|
|
|
SetBitmap((BBitmap*)ptr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
RosterItem::ObserveInteger(int32 what, int32 val)
|
|
|
|
{
|
|
|
|
switch (what) {
|
|
|
|
case INT_CONTACT_STATUS:
|
2021-06-20 12:44:20 -05:00
|
|
|
SetStatus((UserStatus)val);
|
2010-05-07 04:47:10 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RosterItem::DrawItem(BView* owner, BRect frame, bool complete)
|
|
|
|
{
|
|
|
|
if (Text() == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
rgb_color highlightColor = ui_color(B_CONTROL_HIGHLIGHT_COLOR);
|
2010-05-12 13:59:17 -05:00
|
|
|
rgb_color highColor = owner->HighColor();
|
|
|
|
rgb_color lowColor = owner->LowColor();
|
2012-05-15 11:48:53 -05:00
|
|
|
float h = frame.Height();
|
2010-05-07 04:47:10 -05:00
|
|
|
|
|
|
|
// Draw selection
|
|
|
|
if (IsSelected()) {
|
|
|
|
fGradient.SetStart(frame.LeftTop());
|
|
|
|
fGradient.SetEnd(frame.LeftBottom());
|
|
|
|
owner->SetLowColor(highlightColor);
|
|
|
|
owner->FillRect(frame, fGradient);
|
|
|
|
} else if (complete) {
|
|
|
|
owner->SetHighColor(lowColor);
|
|
|
|
owner->FillRect(frame);
|
|
|
|
}
|
|
|
|
|
2012-05-15 12:20:11 -05:00
|
|
|
// Draw contact status
|
|
|
|
switch (fStatus) {
|
2021-06-20 12:44:20 -05:00
|
|
|
case STATUS_ONLINE:
|
|
|
|
owner->SetHighColor(APP_GREEN_COLOR);
|
2012-05-15 11:48:53 -05:00
|
|
|
break;
|
2021-06-20 12:44:20 -05:00
|
|
|
case STATUS_CUSTOM_STATUS:
|
|
|
|
case STATUS_AWAY:
|
|
|
|
owner->SetHighColor(APP_ORANGE_COLOR);
|
2012-05-15 12:20:11 -05:00
|
|
|
break;
|
2021-06-20 12:44:20 -05:00
|
|
|
case STATUS_DO_NOT_DISTURB:
|
|
|
|
owner->SetHighColor(APP_RED_COLOR);
|
2012-05-15 12:20:11 -05:00
|
|
|
break;
|
2021-06-20 12:44:20 -05:00
|
|
|
case STATUS_INVISIBLE:
|
|
|
|
case STATUS_OFFLINE:
|
2012-05-15 12:20:11 -05:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2012-05-15 11:48:53 -05:00
|
|
|
}
|
2010-05-12 13:59:17 -05:00
|
|
|
|
2012-05-15 12:20:11 -05:00
|
|
|
owner->FillRect(BRect(frame.left,
|
|
|
|
frame.top,
|
|
|
|
frame.left + 5, frame.top + h - 1
|
|
|
|
));
|
2012-05-15 11:48:53 -05:00
|
|
|
|
|
|
|
// Draw avatar icon
|
|
|
|
if (fBitmap != NULL) {
|
|
|
|
BRect rect(frame.left + 6, frame.top,
|
|
|
|
frame.left + 42, frame.top + h);
|
|
|
|
owner->SetDrawingMode(B_OP_ALPHA);
|
|
|
|
owner->SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY);
|
|
|
|
owner->DrawBitmap(fBitmap, fBitmap->Bounds(),
|
|
|
|
rect, B_FILTER_BITMAP_BILINEAR);
|
2010-05-07 04:47:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Draw contact name
|
2012-05-15 11:48:53 -05:00
|
|
|
owner->MovePenTo(frame.left + 48, frame.top + fBaselineOffset);
|
2010-05-12 13:59:17 -05:00
|
|
|
owner->SetHighColor(ui_color(B_CONTROL_TEXT_COLOR));
|
2010-05-07 04:47:10 -05:00
|
|
|
owner->DrawString(Text());
|
|
|
|
|
|
|
|
// Draw contact status string
|
2012-05-15 11:48:53 -05:00
|
|
|
owner->MovePenTo(frame.left + 48, frame.top + fBaselineOffset +
|
|
|
|
fBaselineOffset + 3);
|
|
|
|
owner->SetHighColor(tint_color(lowColor, B_DARKEN_2_TINT));
|
2010-05-12 13:59:17 -05:00
|
|
|
if (fPersonalStatus.Length() == 0)
|
2021-06-20 12:44:20 -05:00
|
|
|
owner->DrawString(UserStatusToString(fStatus));
|
2010-05-07 04:47:10 -05:00
|
|
|
else
|
|
|
|
owner->DrawString(fPersonalStatus);
|
|
|
|
|
|
|
|
// Draw separator between items
|
2010-05-12 13:59:17 -05:00
|
|
|
owner->StrokeLine(BPoint(frame.left, frame.bottom),
|
|
|
|
BPoint(frame.right, frame.bottom));
|
2010-05-07 04:47:10 -05:00
|
|
|
|
2012-05-15 11:48:53 -05:00
|
|
|
// Draw protocol bitmpap
|
2012-05-01 14:48:15 -05:00
|
|
|
BBitmap* protocolBitmap = contactLinker->ProtocolBitmap();
|
2012-05-15 11:48:53 -05:00
|
|
|
|
|
|
|
BRect rect(frame.right - 19, frame.top + 2,
|
|
|
|
frame.right - 2, frame.top + 19 );;
|
2012-05-01 14:48:15 -05:00
|
|
|
owner->SetDrawingMode(B_OP_ALPHA);
|
|
|
|
owner->SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY);
|
|
|
|
owner->DrawBitmap(protocolBitmap, protocolBitmap->Bounds(),
|
|
|
|
rect, B_FILTER_BITMAP_BILINEAR);
|
|
|
|
|
2010-05-12 13:59:17 -05:00
|
|
|
owner->SetHighColor(highColor);
|
2010-05-07 04:47:10 -05:00
|
|
|
owner->SetLowColor(lowColor);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
RosterItem::Update(BView* owner, const BFont* font)
|
|
|
|
{
|
|
|
|
font_height fheight;
|
|
|
|
font->GetHeight(&fheight);
|
|
|
|
|
2010-05-12 13:59:17 -05:00
|
|
|
fBaselineOffset = 2 + ceilf(fheight.ascent + fheight.leading / 2);
|
2010-05-07 04:47:10 -05:00
|
|
|
|
|
|
|
SetHeight((ceilf(fheight.ascent) + ceilf(fheight.descent) +
|
|
|
|
ceilf(fheight.leading) + 4 ) * 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2021-06-20 12:44:20 -05:00
|
|
|
RosterItem::SetStatus(UserStatus status)
|
2010-05-07 04:47:10 -05:00
|
|
|
{
|
|
|
|
if (fStatus != status)
|
|
|
|
fStatus = status;
|
|
|
|
}
|