2 * Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
3 * All rights reserved. Distributed under the terms of the MIT License.
6 #include <bluetooth/DeviceClass.h>
7 #include <bluetooth/debug.h>
13 #undef B_TRANSLATION_CONTEXT
14 #define B_TRANSLATION_CONTEXT "DeviceClass"
20 DeviceClass::GetServiceClass(BString
& serviceClass
)
23 static const char *services
[] = { B_TRANSLATE_MARK("Positioning"),
24 B_TRANSLATE_MARK("Networking"), B_TRANSLATE_MARK("Rendering"),
25 B_TRANSLATE_MARK("Capturing"), B_TRANSLATE_MARK("Object transfer"),
26 B_TRANSLATE_MARK("Audio"), B_TRANSLATE_MARK("Telephony"),
27 B_TRANSLATE_MARK("Information") };
29 if (ServiceClass() != 0) {
32 for (uint s
= 0; s
< (sizeof(services
) / sizeof(*services
)); s
++) {
33 if (ServiceClass() & (1 << s
)) {
36 serviceClass
<< services
[s
];
38 serviceClass
<< ", " << services
[s
];
45 serviceClass
<< B_TRANSLATE("Unspecified");
50 DeviceClass::GetMajorDeviceClass(BString
& majorClass
)
53 static const char *major_devices
[] = { B_TRANSLATE_MARK("Miscellaneous"),
54 B_TRANSLATE_MARK("Computer"), B_TRANSLATE_MARK("Phone"),
55 B_TRANSLATE_MARK("LAN access"), B_TRANSLATE_MARK("Audio/Video"),
56 B_TRANSLATE_MARK("Peripheral"), B_TRANSLATE_MARK("Imaging"),
57 B_TRANSLATE_MARK("Uncategorized") };
59 if (MajorDeviceClass() >= sizeof(major_devices
) / sizeof(*major_devices
))
60 majorClass
<< B_TRANSLATE("Invalid device class!\n");
62 majorClass
<< major_devices
[MajorDeviceClass()];
68 DeviceClass::GetMinorDeviceClass(BString
& minorClass
)
71 uint major
= MajorDeviceClass();
72 uint minor
= MinorDeviceClass();
78 case 1: /* computer */
81 minorClass
<< B_TRANSLATE("Uncategorized");
84 minorClass
<< B_TRANSLATE("Desktop workstation");
87 minorClass
<< B_TRANSLATE("Server");
90 minorClass
<< B_TRANSLATE("Laptop");
93 minorClass
<< B_TRANSLATE("Handheld");
96 minorClass
<< B_TRANSLATE_COMMENT("Palm",
97 "A palm-held device");
100 minorClass
<< B_TRANSLATE_COMMENT("Wearable",
101 "A wearable computer");
108 minorClass
<< B_TRANSLATE("Uncategorized");
111 minorClass
<< B_TRANSLATE("Cellular");
114 minorClass
<< B_TRANSLATE("Cordless");
117 minorClass
<< B_TRANSLATE("Smart phone");
120 minorClass
<< B_TRANSLATE("Wired modem or voice gateway");
123 minorClass
<< B_TRANSLATE("Common ISDN access");
126 minorClass
<< B_TRANSLATE("SIM card reader");
130 case 3: /* lan access */
132 minorClass
<< B_TRANSLATE("Uncategorized");
137 minorClass
<< B_TRANSLATE("Fully available");
140 minorClass
<< B_TRANSLATE("1-17% utilized");
143 minorClass
<< B_TRANSLATE("17-33% utilized");
146 minorClass
<< B_TRANSLATE("33-50% utilized");
149 minorClass
<< B_TRANSLATE("50-67% utilized");
152 minorClass
<< B_TRANSLATE("67-83% utilized");
155 minorClass
<< B_TRANSLATE("83-99% utilized");
158 minorClass
<< B_TRANSLATE("No service available");
162 case 4: /* audio/video */
165 minorClass
<< B_TRANSLATE("Uncategorized");
168 minorClass
<< B_TRANSLATE("Device conforms to the headset profile");
171 minorClass
<< B_TRANSLATE("Hands-free");
175 minorClass
<< B_TRANSLATE("Microphone");
178 minorClass
<< B_TRANSLATE("Loudspeaker");
181 minorClass
<< B_TRANSLATE("Headphones");
184 minorClass
<< B_TRANSLATE("Portable audio");
187 minorClass
<< B_TRANSLATE("Car audio");
190 minorClass
<< B_TRANSLATE("Set-top box");
193 minorClass
<< B_TRANSLATE("HiFi audio device");
196 minorClass
<< B_TRANSLATE("VCR");
199 minorClass
<< B_TRANSLATE("Video camera");
202 minorClass
<< B_TRANSLATE("Camcorder");
205 minorClass
<< B_TRANSLATE("Video monitor");
208 minorClass
<< B_TRANSLATE("Video display and loudspeaker");
211 minorClass
<< B_TRANSLATE("Video conferencing");
215 minorClass
<< B_TRANSLATE("Gaming/Toy");
219 case 5: /* peripheral */
223 minorClass
<< B_TRANSLATE("Keyboard");
228 minorClass
<< B_TRANSLATE("Pointing device");
233 minorClass
<< B_TRANSLATE("Combo keyboard/pointing device");
243 minorClass
<< B_TRANSLATE("Joystick");
246 minorClass
<< B_TRANSLATE("Gamepad");
249 minorClass
<< B_TRANSLATE("Remote control");
252 minorClass
<< B_TRANSLATE("Sensing device");
255 minorClass
<< B_TRANSLATE("Digitizer tablet");
258 minorClass
<< B_TRANSLATE("Card reader");
261 minorClass
<< B_TRANSLATE("(reserved)");
266 case 6: /* imaging */
268 minorClass
<< B_TRANSLATE("Display");
270 minorClass
<< B_TRANSLATE("Camera");
272 minorClass
<< B_TRANSLATE("Scanner");
274 minorClass
<< B_TRANSLATE("Printer");
276 case 7: /* wearable */
279 minorClass
<< B_TRANSLATE("Wrist watch");
282 minorClass
<< B_TRANSLATE_COMMENT("Pager",
283 "A small radio device to receive short text messages");
286 minorClass
<< B_TRANSLATE("Jacket");
289 minorClass
<< B_TRANSLATE("Helmet");
292 minorClass
<< B_TRANSLATE("Glasses");
299 minorClass
<< B_TRANSLATE("Robot");
302 minorClass
<< B_TRANSLATE("Vehicle");
305 minorClass
<< B_TRANSLATE("Doll/Action figure");
308 minorClass
<< B_TRANSLATE("Controller");
311 minorClass
<< B_TRANSLATE("Game");
315 case 63: /* uncategorised */
319 minorClass
<< B_TRANSLATE("Unknown (reserved) minor device class");
326 DeviceClass::DumpDeviceClass(BString
& string
)
329 string
<< B_TRANSLATE("Service classes: ");
330 GetServiceClass(string
);
332 string
<< B_TRANSLATE("Major class: ");
333 GetMajorDeviceClass(string
);
335 string
<< B_TRANSLATE("Minor class: ");
336 GetMinorDeviceClass(string
);
342 DeviceClass::Draw(BView
* view
, const BPoint
& point
)
345 rgb_color kBlack
= { 0,0,0,0 };
346 rgb_color kBlue
= { 28,110,157,0 };
347 rgb_color kWhite
= { 255,255,255,0 };
350 view
->SetHighColor(kBlue
);
351 view
->FillRoundRect(BRect(point
.x
+ IconInsets
, point
.y
+ IconInsets
,
352 point
.x
+ IconInsets
+ PixelsForIcon
, point
.y
+ IconInsets
+ PixelsForIcon
), 5, 5);
354 view
->SetHighColor(kWhite
);
356 switch (MajorDeviceClass()) {
359 view
->StrokeRoundRect(BRect(point
.x
+ IconInsets
+ uint(PixelsForIcon
/4),
360 point
.y
+ IconInsets
+ 6,
361 point
.x
+ IconInsets
+ uint(PixelsForIcon
*3/4),
362 point
.y
+ IconInsets
+ PixelsForIcon
- 2), 2, 2);
363 view
->StrokeRect(BRect(point
.x
+ IconInsets
+ uint(PixelsForIcon
/4) + 4,
364 point
.y
+ IconInsets
+ 10,
365 point
.x
+ IconInsets
+ uint(PixelsForIcon
*3/4) - 4,
366 point
.y
+ IconInsets
+ uint(PixelsForIcon
*3/4)));
367 view
->StrokeLine(BPoint(point
.x
+ IconInsets
+ uint(PixelsForIcon
/4) + 4,
368 point
.y
+ IconInsets
+ PixelsForIcon
- 6),
369 BPoint(point
.x
+ IconInsets
+ uint(PixelsForIcon
*3/4) - 4,
370 point
.y
+ IconInsets
+ PixelsForIcon
- 6));
371 view
->StrokeLine(BPoint(point
.x
+ IconInsets
+ uint(PixelsForIcon
/4) + 4,
372 point
.y
+ IconInsets
+ PixelsForIcon
- 4),
373 BPoint(point
.x
+ IconInsets
+ uint(PixelsForIcon
*3/4) - 4,
374 point
.y
+ IconInsets
+ PixelsForIcon
- 4));
375 view
->StrokeLine(BPoint(point
.x
+ IconInsets
+ uint(PixelsForIcon
/4) + 4,
376 point
.y
+ IconInsets
+ 2),
377 BPoint(point
.x
+ IconInsets
+ uint(PixelsForIcon
/4) + 4,
378 point
.y
+ IconInsets
+ 6));
381 view
->StrokeLine(BPoint(point
.x
+ IconInsets
+ uint(PixelsForIcon
/4),
382 point
.y
+ IconInsets
+ uint(PixelsForIcon
*3/8)),
383 BPoint(point
.x
+ IconInsets
+ uint(PixelsForIcon
*3/4),
384 point
.y
+ IconInsets
+ uint(PixelsForIcon
*3/8)));
385 view
->StrokeLine(BPoint(point
.x
+ IconInsets
+ uint(PixelsForIcon
*5/8),
386 point
.y
+ IconInsets
+ uint(PixelsForIcon
/8)));
387 view
->StrokeLine(BPoint(point
.x
+ IconInsets
+ uint(PixelsForIcon
*3/4),
388 point
.y
+ IconInsets
+ uint(PixelsForIcon
*5/8)),
389 BPoint(point
.x
+ IconInsets
+ uint(PixelsForIcon
/4),
390 point
.y
+ IconInsets
+ uint(PixelsForIcon
*5/8)));
391 view
->StrokeLine(BPoint(point
.x
+ IconInsets
+ uint(PixelsForIcon
*3/8),
392 point
.y
+ IconInsets
+ uint(PixelsForIcon
*7/8)));
394 case 4: // audio/video
395 view
->StrokeRect(BRect(point
.x
+ IconInsets
+ uint(PixelsForIcon
/4),
396 point
.y
+ IconInsets
+ uint(PixelsForIcon
*3/8),
397 point
.x
+ IconInsets
+ uint(PixelsForIcon
*3/8),
398 point
.y
+ IconInsets
+ uint(PixelsForIcon
*5/8)));
399 view
->StrokeLine(BPoint(point
.x
+ IconInsets
+ uint(PixelsForIcon
*3/8),
400 point
.y
+ IconInsets
+ uint(PixelsForIcon
*3/8)),
401 BPoint(point
.x
+ IconInsets
+ uint(PixelsForIcon
*3/4),
402 point
.y
+ IconInsets
+ uint(PixelsForIcon
/8)));
403 view
->StrokeLine(BPoint(point
.x
+ IconInsets
+ uint(PixelsForIcon
*3/4),
404 point
.y
+ IconInsets
+ uint(PixelsForIcon
*7/8)));
405 view
->StrokeLine(BPoint(point
.x
+ IconInsets
+ uint(PixelsForIcon
*3/8),
406 point
.y
+ IconInsets
+ uint(PixelsForIcon
*5/8)));
408 default: // Bluetooth Logo
409 view
->StrokeLine(BPoint(point
.x
+ IconInsets
+ uint(PixelsForIcon
/4),
410 point
.y
+ IconInsets
+ uint(PixelsForIcon
*3/4)),
411 BPoint(point
.x
+ IconInsets
+ uint(PixelsForIcon
*3/4),
412 point
.y
+ IconInsets
+ uint(PixelsForIcon
/4)));
413 view
->StrokeLine(BPoint(point
.x
+ IconInsets
+ uint(PixelsForIcon
/2),
414 point
.y
+ IconInsets
+2));
415 view
->StrokeLine(BPoint(point
.x
+ IconInsets
+ uint(PixelsForIcon
/2),
416 point
.y
+ IconInsets
+ PixelsForIcon
- 2));
417 view
->StrokeLine(BPoint(point
.x
+ IconInsets
+ uint(PixelsForIcon
*3/4),
418 point
.y
+ IconInsets
+ uint(PixelsForIcon
*3/4)));
419 view
->StrokeLine(BPoint(point
.x
+ IconInsets
+ uint(PixelsForIcon
/4),
420 point
.y
+ IconInsets
+ uint(PixelsForIcon
/4)));
423 view
->SetHighColor(kBlack
);