1/* 2 * Copyright 2009, Oliver Ruiz Dorantes, <oliver.ruiz.dorantes_at_gmail.com> 3 * All rights reserved. Distributed under the terms of the MIT License. 4 */ 5 6#include <Bitmap.h> 7#include <View.h> 8 9#include <bluetooth/bdaddrUtils.h> 10#include <bluetooth/BluetoothDevice.h> 11 12#include "DeviceListItem.h" 13 14#define INSETS 5 15#define TEXT_ROWS 2 16 17namespace Bluetooth { 18 19DeviceListItem::DeviceListItem(BluetoothDevice* bDevice) 20 : 21 BListItem(), 22 fDevice(bDevice), 23 fName("unknown") 24{ 25 fAddress = bDevice->GetBluetoothAddress(); 26 fClass = bDevice->GetDeviceClass(); 27} 28 29 30void 31DeviceListItem::SetDevice(BluetoothDevice* bDevice) 32{ 33 fAddress = bDevice->GetBluetoothAddress(); 34 fClass = bDevice->GetDeviceClass(); 35 fName = bDevice->GetFriendlyName(); 36 // AKAIR rssi we can just have it @ inquiry time... 37} 38 39 40DeviceListItem::~DeviceListItem() 41{ 42 43} 44 45 46void 47DeviceListItem::DrawItem(BView* owner, BRect itemRect, bool complete) 48{ 49 rgb_color kBlack = { 0, 0, 0, 0 }; 50 rgb_color kHighlight = { 156, 154, 156, 0 }; 51 52 if (IsSelected() || complete) { 53 rgb_color color; 54 if (IsSelected()) 55 color = kHighlight; 56 else 57 color = owner->ViewColor(); 58 59 owner->SetHighColor(color); 60 owner->SetLowColor(color); 61 owner->FillRect(itemRect); 62 owner->SetHighColor(kBlack); 63 64 } else { 65 owner->SetLowColor(owner->ViewColor()); 66 } 67 68 font_height finfo; 69 be_plain_font->GetHeight(&finfo); 70 71 BPoint point = BPoint(itemRect.left + DeviceClass::PixelsForIcon 72 + 2 * INSETS, itemRect.bottom - finfo.descent + 1); 73 owner->SetFont(be_fixed_font); 74 owner->SetHighColor(kBlack); 75 owner->MovePenTo(point); 76 77 BString secondLine; 78 79 secondLine << bdaddrUtils::ToString(fAddress) << " "; 80 fClass.GetMajorDeviceClass(secondLine); 81 secondLine << " / "; 82 fClass.GetMinorDeviceClass(secondLine); 83 84 owner->DrawString(secondLine.String()); 85 86 point -= BPoint(0, (finfo.ascent + finfo.descent + finfo.leading) + INSETS); 87 88 owner->SetFont(be_plain_font); 89 owner->MovePenTo(point); 90 owner->DrawString(fName.String()); 91 92 fClass.Draw(owner, BPoint(itemRect.left, itemRect.top)); 93 94#if 0 95 switch (fClass.GetMajorDeviceClass()) { 96 case 1: 97 { 98 BRect iconRect(0, 0, 15, 15); 99 BBitmap* icon = new BBitmap(iconRect, B_CMAP8); 100 icon->SetBits(kTVBits, kTVWidth * kTVHeight, 0, kTVColorSpace); 101 owner->DrawBitmap(icon, iconRect, BRect(itemRect.left + INSETS, 102 itemRect.top + INSETS, itemRect.left + INSETS + PIXELS_FOR_ICON, 103 itemRect.top + INSETS + PIXELS_FOR_ICON)); 104 break; 105 } 106 case 4: 107 { 108 BRect iconRect(0, 0, 15, 15); 109 BBitmap* icon = new BBitmap(iconRect, B_CMAP8); 110 icon->SetBits(kMixerBits, kMixerWidth * kMixerHeight, 0, kMixerColorSpace); 111 owner->DrawBitmap(icon, iconRect, BRect(itemRect.left + INSETS, 112 itemRect.top + INSETS, itemRect.left + INSETS + PIXELS_FOR_ICON, 113 itemRect.top + INSETS + PIXELS_FOR_ICON)); 114 break; 115 } 116 } 117#endif 118 119 owner->SetHighColor(kBlack); 120 121} 122 123 124void 125DeviceListItem::Update(BView* owner, const BFont* font) 126{ 127 BListItem::Update(owner, font); 128 129 font_height height; 130 font->GetHeight(&height); 131 SetHeight(MAX((height.ascent + height.descent + height.leading) * TEXT_ROWS 132 + (TEXT_ROWS + 1)*INSETS, DeviceClass::PixelsForIcon + 2 * INSETS)); 133 134} 135 136 137int 138DeviceListItem::Compare(const void *firstArg, const void *secondArg) 139{ 140 const DeviceListItem* item1 = *static_cast<const DeviceListItem* const *> 141 (firstArg); 142 const DeviceListItem* item2 = *static_cast<const DeviceListItem* const *> 143 (secondArg); 144 145 return (int)bdaddrUtils::Compare(item1->fAddress, item2->fAddress); 146} 147 148 149BluetoothDevice* 150DeviceListItem::Device() const 151{ 152 return fDevice; 153} 154 155 156} 157