fat: Greatly simplify and clean up dosfs_get_file_map().
[haiku.git] / src / preferences / bluetooth / DeviceListItem.cpp
blob0b64d0abd5eb4f5f52bd9165b525ba16877e2009
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 */
6 #include <Bitmap.h>
7 #include <View.h>
9 #include <bluetooth/bdaddrUtils.h>
10 #include <bluetooth/BluetoothDevice.h>
11 /*#include "../media/iconfile.h"*/
13 #include "DeviceListItem.h"
15 #define INSETS 5
16 #define TEXT_ROWS 2
18 namespace Bluetooth {
20 DeviceListItem::DeviceListItem(BluetoothDevice* bDevice)
22 BListItem(),
23 fDevice(bDevice),
24 fName("unknown")
26 fAddress = bDevice->GetBluetoothAddress();
27 fClass = bDevice->GetDeviceClass();
31 void
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()
47 void
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) {
54 rgb_color color;
55 if (IsSelected())
56 color = kHighlight;
57 else
58 color = owner->ViewColor();
60 owner->SetHighColor(color);
61 owner->SetLowColor(color);
62 owner->FillRect(itemRect);
63 owner->SetHighColor(kBlack);
65 } else {
66 owner->SetLowColor(owner->ViewColor());
69 font_height finfo;
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);
78 BString secondLine;
80 secondLine << bdaddrUtils::ToString(fAddress) << " ";
81 fClass.GetMajorDeviceClass(secondLine);
82 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));
95 #if 0
96 switch (fClass.GetMajorDeviceClass()) {
97 case 1:
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));
105 break;
107 case 4:
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));
115 break;
118 #endif
120 owner->SetHighColor(kBlack);
125 void
126 DeviceListItem::Update(BView* owner, const BFont* font)
128 BListItem::Update(owner, font);
130 font_height height;
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 *>
142 (firstArg);
143 const DeviceListItem* item2 = *static_cast<const DeviceListItem* const *>
144 (secondArg);
146 return (int)bdaddrUtils::Compare(item1->fAddress, item2->fAddress);
150 BluetoothDevice*
151 DeviceListItem::Device() const
153 return fDevice;