UserItem.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright 2021, Jaidyn Levesque <jadedctrl@teknik.io>
  3. * All rights reserved. Distributed under the terms of the MIT license.
  4. */
  5. #include "UserItem.h"
  6. #include <InterfaceDefs.h>
  7. #include <View.h>
  8. #include "AppConstants.h"
  9. #include "NotifyMessage.h"
  10. #include "User.h"
  11. #include "Utils.h"
  12. UserItem::UserItem(User* user)
  13. :
  14. BStringItem(user->GetName()),
  15. fUser(user),
  16. fStatus(user->GetNotifyStatus())
  17. {
  18. user->RegisterObserver(this);
  19. }
  20. UserItem::~UserItem()
  21. {
  22. fUser->UnregisterObserver(this);
  23. }
  24. void
  25. UserItem::DrawItem(BView* owner, BRect frame, bool complete)
  26. {
  27. rgb_color highColor = owner->HighColor();
  28. owner->SetHighColor(_GetTextColor(highColor));
  29. BStringItem::DrawItem(owner, frame, complete);
  30. owner->SetHighColor(highColor);
  31. }
  32. void
  33. UserItem::ObserveString(int32 what, BString str)
  34. {
  35. switch (what) {
  36. case STR_CONTACT_NAME:
  37. SetText(str);
  38. break;
  39. }
  40. }
  41. void
  42. UserItem::ObserveInteger(int32 what, int32 value)
  43. {
  44. switch (what) {
  45. case INT_CONTACT_STATUS:
  46. {
  47. fStatus = value;
  48. break;
  49. }
  50. }
  51. }
  52. User*
  53. UserItem::GetUser()
  54. {
  55. return fUser;
  56. }
  57. rgb_color
  58. UserItem::_GetTextColor(rgb_color highColor)
  59. {
  60. switch (fStatus)
  61. {
  62. case STATUS_AWAY:
  63. return TintColor(ui_color(B_LIST_ITEM_TEXT_COLOR), 1);
  64. case STATUS_INVISIBLE:
  65. case STATUS_DO_NOT_DISTURB:
  66. return TintColor(ui_color(B_LIST_ITEM_TEXT_COLOR), 2);
  67. case STATUS_OFFLINE:
  68. return TintColor(ui_color(B_LIST_ITEM_TEXT_COLOR), 3);
  69. }
  70. return highColor;
  71. }