2 * Copyright 2009, Oliver Ruiz Dorantes, <oliver.ruiz.dorantes_at_gmail.com>
3 * All rights reserved. Distributed under the terms of the MIT License.
9 #include <bluetooth/bdaddrUtils.h>
10 #include <bluetooth/BluetoothDevice.h>
11 /*#include "../media/iconfile.h"*/
13 #include "DeviceListItem.h"
20 DeviceListItem::DeviceListItem(BluetoothDevice
* bDevice
)
26 fAddress
= bDevice
->GetBluetoothAddress();
27 fClass
= bDevice
->GetDeviceClass();
32 DeviceListItem::SetDevice(BluetoothDevice
* bDevice
)
34 fAddress
= bDevice
->GetBluetoothAddress();
35 fClass
= bDevice
->GetDeviceClass();
36 fName
= bDevice
->GetFriendlyName();
37 // AKAIR rssi we can just have it @ inquiry time...
41 DeviceListItem::~DeviceListItem()
48 DeviceListItem::DrawItem(BView
* owner
, BRect itemRect
, bool complete
)
50 rgb_color kBlack
= { 0, 0, 0, 0 };
51 rgb_color kHighlight
= { 156, 154, 156, 0 };
53 if (IsSelected() || complete
) {
58 color
= owner
->ViewColor();
60 owner
->SetHighColor(color
);
61 owner
->SetLowColor(color
);
62 owner
->FillRect(itemRect
);
63 owner
->SetHighColor(kBlack
);
66 owner
->SetLowColor(owner
->ViewColor());
70 be_plain_font
->GetHeight(&finfo
);
72 BPoint point
= BPoint(itemRect
.left
+ DeviceClass::PixelsForIcon
73 + 2 * INSETS
, itemRect
.bottom
- finfo
.descent
+ 1);
74 owner
->SetFont(be_fixed_font
);
75 owner
->SetHighColor(kBlack
);
76 owner
->MovePenTo(point
);
80 secondLine
<< bdaddrUtils::ToString(fAddress
) << " ";
81 fClass
.GetMajorDeviceClass(secondLine
);
83 fClass
.GetMinorDeviceClass(secondLine
);
85 owner
->DrawString(secondLine
.String());
87 point
-= BPoint(0, (finfo
.ascent
+ finfo
.descent
+ finfo
.leading
) + INSETS
);
89 owner
->SetFont(be_plain_font
);
90 owner
->MovePenTo(point
);
91 owner
->DrawString(fName
.String());
93 fClass
.Draw(owner
, BPoint(itemRect
.left
, itemRect
.top
));
96 switch (fClass
.GetMajorDeviceClass()) {
99 BRect
iconRect(0, 0, 15, 15);
100 BBitmap
* icon
= new BBitmap(iconRect
, B_CMAP8
);
101 icon
->SetBits(kTVBits
, kTVWidth
* kTVHeight
, 0, kTVColorSpace
);
102 owner
->DrawBitmap(icon
, iconRect
, BRect(itemRect
.left
+ INSETS
,
103 itemRect
.top
+ INSETS
, itemRect
.left
+ INSETS
+ PIXELS_FOR_ICON
,
104 itemRect
.top
+ INSETS
+ PIXELS_FOR_ICON
));
109 BRect
iconRect(0, 0, 15, 15);
110 BBitmap
* icon
= new BBitmap(iconRect
, B_CMAP8
);
111 icon
->SetBits(kMixerBits
, kMixerWidth
* kMixerHeight
, 0, kMixerColorSpace
);
112 owner
->DrawBitmap(icon
, iconRect
, BRect(itemRect
.left
+ INSETS
,
113 itemRect
.top
+ INSETS
, itemRect
.left
+ INSETS
+ PIXELS_FOR_ICON
,
114 itemRect
.top
+ INSETS
+ PIXELS_FOR_ICON
));
120 owner
->SetHighColor(kBlack
);
126 DeviceListItem::Update(BView
* owner
, const BFont
* font
)
128 BListItem::Update(owner
, font
);
131 font
->GetHeight(&height
);
132 SetHeight(MAX((height
.ascent
+ height
.descent
+ height
.leading
) * TEXT_ROWS
133 + (TEXT_ROWS
+ 1)*INSETS
, DeviceClass::PixelsForIcon
+ 2 * INSETS
));
139 DeviceListItem::Compare(const void *firstArg
, const void *secondArg
)
141 const DeviceListItem
* item1
= *static_cast<const DeviceListItem
* const *>
143 const DeviceListItem
* item2
= *static_cast<const DeviceListItem
* const *>
146 return (int)bdaddrUtils::Compare(item1
->fAddress
, item2
->fAddress
);
151 DeviceListItem::Device() const