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