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.
5 #include "ExtendedLocalDeviceView.h"
7 #include <bluetooth/bdaddrUtils.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
,
25 BView("ExtendedLocalDeviceView", flags
| B_WILL_DRAW
),
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
));
40 BLayoutBuilder::Group
<>(this, B_VERTICAL
, 0)
43 .AddGroup(B_HORIZONTAL
, 0)
54 ExtendedLocalDeviceView::~ExtendedLocalDeviceView()
60 ExtendedLocalDeviceView::SetLocalDevice(LocalDevice
* lDevice
)
62 if (lDevice
!= NULL
) {
64 SetName(lDevice
->GetFriendlyName().String());
65 fDeviceView
->SetBluetoothDevice(lDevice
);
69 int value
= fDevice
->GetDiscoverable();
70 printf("ExtendedLocalDeviceView::SetLocalDevice value = %d\n", value
);
72 fDiscoverable
->SetValue(true);
74 fVisible
->SetValue(true);
75 else if (value
== 3) {
76 fDiscoverable
->SetValue(true);
77 fVisible
->SetValue(true);
84 ExtendedLocalDeviceView::AttachedToWindow()
86 fDiscoverable
->SetTarget(this);
87 fVisible
->SetTarget(this);
88 fAuthentication
->SetTarget(this);
93 ExtendedLocalDeviceView::SetTarget(BHandler
* target
)
95 printf("ExtendedLocalDeviceView::SetTarget\n");
100 ExtendedLocalDeviceView::MessageReceived(BMessage
* message
)
102 if (fDevice
== NULL
) {
103 printf("ExtendedLocalDeviceView::Device missing\n");
104 BView::MessageReceived(message
);
108 if (message
->WasDropped()) {
112 switch (message
->what
)
114 case SET_DISCOVERABLE
:
118 if (fDiscoverable
->Value()) {
120 fVisible
->SetEnabled(true);
122 fVisible
->SetValue(false);
123 fVisible
->SetEnabled(false);
126 if (fVisible
->Value())
130 fDevice
->SetDiscoverable(fScanMode
);
133 case SET_AUTHENTICATION
:
135 fDevice
->SetAuthentication(fAuthentication
->Value());
139 BView::MessageReceived(message
);
146 ExtendedLocalDeviceView::SetEnabled(bool value
)
148 fVisible
->SetEnabled(value
);
149 fAuthentication
->SetEnabled(value
);
150 fDiscoverable
->SetEnabled(value
);
155 ExtendedLocalDeviceView::ClearDevice()
157 fVisible
->SetValue(false);
158 fAuthentication
->SetValue(false);
159 fDiscoverable
->SetValue(false);