xref: /haiku/src/preferences/bluetooth/ExtendedLocalDeviceView.cpp (revision 85fb3e7df81f8d5b6e47a9a64a53873ea906ea6e)
1 /*
2  * Copyright 2008-09, Oliver Ruiz Dorantes, <oliver.ruiz.dorantes_at_gmail.com>
3  * All rights reserved. Distributed under the terms of the MIT License.
4  */
5 #include "ExtendedLocalDeviceView.h"
6 
7 #include <bluetooth/bdaddrUtils.h>
8 
9 #include "defs.h"
10 
11 #include <Bitmap.h>
12 #include <Catalog.h>
13 #include <CheckBox.h>
14 #include <GroupLayoutBuilder.h>
15 #include <SpaceLayoutItem.h>
16 #include <StringView.h>
17 
18 
19 #undef B_TRANSLATION_CONTEXT
20 #define B_TRANSLATION_CONTEXT "Extended local device view"
21 
22 ExtendedLocalDeviceView::ExtendedLocalDeviceView(BRect frame,
23 	LocalDevice* bDevice, uint32 resizingMode, uint32 flags)
24 	:
25 	BView(frame,"ExtendedLocalDeviceView", resizingMode, flags | B_WILL_DRAW),
26 	fDevice(bDevice),
27 	fScanMode(0)
28 {
29 	SetViewColor(B_TRANSPARENT_COLOR);
30 	SetLowColor(0, 0, 0);
31 	BRect iDontCare(0, 0, 0, 0);
32 
33 	SetLayout(new BGroupLayout(B_HORIZONTAL));
34 
35 	fDeviceView = new BluetoothDeviceView(BRect(0, 0, 5, 5), bDevice);
36 
37 	fDiscoverable = new BCheckBox(iDontCare, "Discoverable",
38 		B_TRANSLATE("Discoverable"), new BMessage(SET_DISCOVERABLE));
39 	fVisible = new BCheckBox(iDontCare, "Visible",
40 		B_TRANSLATE("Show name"), new BMessage(SET_VISIBLE));
41 	fAuthentication = new BCheckBox(iDontCare, "Authenticate",
42 		B_TRANSLATE("Authenticate"), new BMessage(SET_AUTHENTICATION));
43 
44 	fDiscoverable->SetEnabled(false);
45 	fVisible->SetEnabled(false);
46 
47 	AddChild(BGroupLayoutBuilder(B_VERTICAL, 0)
48 				.Add(fDeviceView)
49 				.Add(BGroupLayoutBuilder(B_HORIZONTAL)
50 						.AddGlue()
51 						.Add(fDiscoverable)
52 						.Add(fVisible)
53 						.SetInsets(5, 5, 5, 5)
54 					)
55 				.Add(fAuthentication)
56 				.Add(BSpaceLayoutItem::CreateVerticalStrut(0))
57 			.SetInsets(5, 5, 5, 5)
58 	);
59 
60 }
61 
62 
63 ExtendedLocalDeviceView::~ExtendedLocalDeviceView(void)
64 {
65 
66 }
67 
68 
69 void
70 ExtendedLocalDeviceView::SetLocalDevice(LocalDevice* lDevice)
71 {
72 	if (lDevice != NULL) {
73 		fDevice = lDevice;
74 		SetName(lDevice->GetFriendlyName().String());
75 		fDeviceView->SetBluetoothDevice(lDevice);
76 	}
77 }
78 
79 
80 void
81 ExtendedLocalDeviceView::AttachedToWindow()
82 {
83 	fDiscoverable->SetTarget(this);
84 	fVisible->SetTarget(this);
85 	fAuthentication->SetTarget(this);
86 }
87 
88 
89 void
90 ExtendedLocalDeviceView::SetTarget(BHandler* target)
91 {
92 
93 }
94 
95 
96 void
97 ExtendedLocalDeviceView::MessageReceived(BMessage* message)
98 {
99 	if (message->WasDropped()) {
100 
101 	}
102 
103 	switch (message->what)
104 	{
105 		case SET_DISCOVERABLE:
106 		case SET_VISIBLE:
107 			fScanMode = 0;
108 
109 			if (fDiscoverable->Value()) {
110 				fScanMode = 1;
111 				fVisible->SetEnabled(true);
112 			} else {
113 				fVisible->SetValue(false);
114 				fVisible->SetEnabled(false);
115 			}
116 
117 			if (fVisible->Value())
118 				fScanMode |= 2;
119 			if (fDevice != NULL)
120 				fDevice->SetDiscoverable(fScanMode);
121 
122 			break;
123 		case SET_AUTHENTICATION:
124 			fDevice->SetAuthentication(fAuthentication->Value());
125 			break;
126 
127 		default:
128 			BView::MessageReceived(message);
129 		break;
130 	}
131 }
132 
133 
134 void
135 ExtendedLocalDeviceView::SetEnabled(bool value)
136 {
137 	fDiscoverable->SetEnabled(value);
138 }
139