libroot/posix/stdio: Remove unused portions.
[haiku.git] / src / preferences / bluetooth / ExtendedLocalDeviceView.cpp
blob9cfad3c7ef2934e8d3a735716649bd8c646e15cc
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"
7 #include <bluetooth/bdaddrUtils.h>
9 #include "defs.h"
11 #include <Bitmap.h>
12 #include <Catalog.h>
13 #include <CheckBox.h>
14 #include <LayoutBuilder.h>
15 #include <SpaceLayoutItem.h>
16 #include <StringView.h>
19 #undef B_TRANSLATION_CONTEXT
20 #define B_TRANSLATION_CONTEXT "Extended local device view"
22 ExtendedLocalDeviceView::ExtendedLocalDeviceView(LocalDevice* bDevice,
23 uint32 flags)
25 BView("ExtendedLocalDeviceView", flags | B_WILL_DRAW),
26 fDevice(bDevice),
27 fScanMode(0)
29 fDeviceView = new BluetoothDeviceView(bDevice);
31 fDiscoverable = new BCheckBox("Discoverable",
32 B_TRANSLATE("Discoverable"), new BMessage(SET_DISCOVERABLE));
33 fVisible = new BCheckBox("Visible",
34 B_TRANSLATE("Show name"), new BMessage(SET_VISIBLE));
35 fAuthentication = new BCheckBox("Authenticate",
36 B_TRANSLATE("Authenticate"), new BMessage(SET_AUTHENTICATION));
38 SetEnabled(false);
40 BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
41 .SetInsets(5)
42 .Add(fDeviceView)
43 .AddGroup(B_HORIZONTAL, 0)
44 .SetInsets(5)
45 .AddGlue()
46 .Add(fDiscoverable)
47 .Add(fVisible)
48 .End()
49 .Add(fAuthentication)
50 .End();
54 ExtendedLocalDeviceView::~ExtendedLocalDeviceView()
59 void
60 ExtendedLocalDeviceView::SetLocalDevice(LocalDevice* lDevice)
62 if (lDevice != NULL) {
63 fDevice = lDevice;
64 SetName(lDevice->GetFriendlyName().String());
65 fDeviceView->SetBluetoothDevice(lDevice);
67 ClearDevice();
69 int value = fDevice->GetDiscoverable();
70 printf("ExtendedLocalDeviceView::SetLocalDevice value = %d\n", value);
71 if (value == 1)
72 fDiscoverable->SetValue(true);
73 else if (value == 2)
74 fVisible->SetValue(true);
75 else if (value == 3) {
76 fDiscoverable->SetValue(true);
77 fVisible->SetValue(true);
83 void
84 ExtendedLocalDeviceView::AttachedToWindow()
86 fDiscoverable->SetTarget(this);
87 fVisible->SetTarget(this);
88 fAuthentication->SetTarget(this);
92 void
93 ExtendedLocalDeviceView::SetTarget(BHandler* target)
95 printf("ExtendedLocalDeviceView::SetTarget\n");
99 void
100 ExtendedLocalDeviceView::MessageReceived(BMessage* message)
102 if (fDevice == NULL) {
103 printf("ExtendedLocalDeviceView::Device missing\n");
104 BView::MessageReceived(message);
105 return;
108 if (message->WasDropped()) {
112 switch (message->what)
114 case SET_DISCOVERABLE:
115 case SET_VISIBLE:
116 fScanMode = 0;
118 if (fDiscoverable->Value()) {
119 fScanMode = 1;
120 fVisible->SetEnabled(true);
121 } else {
122 fVisible->SetValue(false);
123 fVisible->SetEnabled(false);
126 if (fVisible->Value())
127 fScanMode |= 2;
129 if (fDevice != NULL)
130 fDevice->SetDiscoverable(fScanMode);
132 break;
133 case SET_AUTHENTICATION:
134 if (fDevice != NULL)
135 fDevice->SetAuthentication(fAuthentication->Value());
136 break;
138 default:
139 BView::MessageReceived(message);
140 break;
145 void
146 ExtendedLocalDeviceView::SetEnabled(bool value)
148 fVisible->SetEnabled(value);
149 fAuthentication->SetEnabled(value);
150 fDiscoverable->SetEnabled(value);
154 void
155 ExtendedLocalDeviceView::ClearDevice()
157 fVisible->SetValue(false);
158 fAuthentication->SetValue(false);
159 fDiscoverable->SetValue(false);