12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- /*
- * Copyright 2021, Jaidyn Levesque <jadedctrl@teknik.io>
- * All rights reserved. Distributed under the terms of the MIT license.
- */
- #include "UserItem.h"
- #include <InterfaceDefs.h>
- #include <View.h>
- #include "AppConstants.h"
- #include "NotifyMessage.h"
- #include "User.h"
- #include "Utils.h"
- UserItem::UserItem(User* user)
- :
- BStringItem(user->GetName()),
- fUser(user),
- fStatus(user->GetNotifyStatus())
- {
- user->RegisterObserver(this);
- }
- UserItem::~UserItem()
- {
- fUser->UnregisterObserver(this);
- }
- void
- UserItem::DrawItem(BView* owner, BRect frame, bool complete)
- {
- rgb_color highColor = owner->HighColor();
- owner->SetHighColor(_GetTextColor(highColor));
- BStringItem::DrawItem(owner, frame, complete);
- owner->SetHighColor(highColor);
- }
- void
- UserItem::ObserveString(int32 what, BString str)
- {
- switch (what) {
- case STR_CONTACT_NAME:
- SetText(str);
- break;
- }
- }
- void
- UserItem::ObserveInteger(int32 what, int32 value)
- {
- switch (what) {
- case INT_CONTACT_STATUS:
- {
- fStatus = value;
- break;
- }
- }
- }
- User*
- UserItem::GetUser()
- {
- return fUser;
- }
- rgb_color
- UserItem::_GetTextColor(rgb_color highColor)
- {
- switch (fStatus)
- {
- case STATUS_AWAY:
- return TintColor(ui_color(B_LIST_ITEM_TEXT_COLOR), 1);
- case STATUS_INVISIBLE:
- case STATUS_DO_NOT_DISTURB:
- return TintColor(ui_color(B_LIST_ITEM_TEXT_COLOR), 2);
- case STATUS_OFFLINE:
- return TintColor(ui_color(B_LIST_ITEM_TEXT_COLOR), 3);
- }
- return highColor;
- }
|