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 <GroupLayoutBuilder.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(BRect frame
,
23 LocalDevice
* bDevice
, uint32 resizingMode
, uint32 flags
)
25 BView(frame
,"ExtendedLocalDeviceView", resizingMode
, flags
| B_WILL_DRAW
),
29 SetViewColor(B_TRANSPARENT_COLOR
);
31 BRect
iDontCare(0, 0, 0, 0);
33 SetLayout(new BGroupLayout(B_HORIZONTAL
));
35 fDeviceView
= new BluetoothDeviceView(BRect(0, 0, 5, 5), bDevice
);
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
));
46 AddChild(BGroupLayoutBuilder(B_VERTICAL
, 0)
48 .Add(BGroupLayoutBuilder(B_HORIZONTAL
)
52 .SetInsets(5, 5, 5, 5)
55 .Add(BSpaceLayoutItem::CreateVerticalStrut(0))
56 .SetInsets(5, 5, 5, 5)
61 ExtendedLocalDeviceView::~ExtendedLocalDeviceView(void)
68 ExtendedLocalDeviceView::SetLocalDevice(LocalDevice
* lDevice
)
70 printf("ExtendedLocalDeviceView::SetLocalDevice\n");
71 if (lDevice
!= NULL
) {
73 SetName(lDevice
->GetFriendlyName().String());
74 fDeviceView
->SetBluetoothDevice(lDevice
);
78 int value
= fDevice
->GetDiscoverable();
79 printf("ExtendedLocalDeviceView::SetLocalDevice value = %d\n", value
);
81 fDiscoverable
->SetValue(true);
83 fVisible
->SetValue(true);
84 else if (value
== 3) {
85 fDiscoverable
->SetValue(true);
86 fVisible
->SetValue(true);
93 ExtendedLocalDeviceView::AttachedToWindow()
95 printf("ExtendedLocalDeviceView::AttachedToWindow\n");
96 fDiscoverable
->SetTarget(this);
97 fVisible
->SetTarget(this);
98 fAuthentication
->SetTarget(this);
103 ExtendedLocalDeviceView::SetTarget(BHandler
* target
)
105 printf("ExtendedLocalDeviceView::SetTarget\n");
110 ExtendedLocalDeviceView::MessageReceived(BMessage
* message
)
112 printf("ExtendedLocalDeviceView::MessageReceived\n");
114 if (fDevice
== NULL
) {
115 printf("ExtendedLocalDeviceView::Device missing\n");
119 if (message
->WasDropped()) {
123 switch (message
->what
)
125 case SET_DISCOVERABLE
:
129 if (fDiscoverable
->Value()) {
131 fVisible
->SetEnabled(true);
133 fVisible
->SetValue(false);
134 fVisible
->SetEnabled(false);
137 if (fVisible
->Value())
141 fDevice
->SetDiscoverable(fScanMode
);
144 case SET_AUTHENTICATION
:
146 fDevice
->SetAuthentication(fAuthentication
->Value());
150 BView::MessageReceived(message
);
157 ExtendedLocalDeviceView::SetEnabled(bool value
)
159 printf("ExtendedLocalDeviceView::SetEnabled\n");
161 fVisible
->SetEnabled(value
);
162 fAuthentication
->SetEnabled(value
);
163 fDiscoverable
->SetEnabled(value
);
168 ExtendedLocalDeviceView::ClearDevice()
170 printf("ExtendedLocalDeviceView::ClearDevice\n");
172 fVisible
->SetValue(false);
173 fAuthentication
->SetValue(false);
174 fDiscoverable
->SetValue(false);