fat: Greatly simplify and clean up dosfs_get_file_map().
[haiku.git] / src / preferences / bluetooth / ExtendedLocalDeviceView.cpp
blob31ddfaff284df9e1f266fa194b18892ddb96eb8b
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 <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),
26 fDevice(bDevice),
27 fScanMode(0)
29 SetViewColor(B_TRANSPARENT_COLOR);
30 SetLowColor(0, 0, 0);
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));
44 SetEnabled(false);
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)
54 .Add(fAuthentication)
55 .Add(BSpaceLayoutItem::CreateVerticalStrut(0))
56 .SetInsets(5, 5, 5, 5)
61 ExtendedLocalDeviceView::~ExtendedLocalDeviceView(void)
67 void
68 ExtendedLocalDeviceView::SetLocalDevice(LocalDevice* lDevice)
70 printf("ExtendedLocalDeviceView::SetLocalDevice\n");
71 if (lDevice != NULL) {
72 fDevice = lDevice;
73 SetName(lDevice->GetFriendlyName().String());
74 fDeviceView->SetBluetoothDevice(lDevice);
76 ClearDevice();
78 int value = fDevice->GetDiscoverable();
79 printf("ExtendedLocalDeviceView::SetLocalDevice value = %d\n", value);
80 if (value == 1)
81 fDiscoverable->SetValue(true);
82 else if (value == 2)
83 fVisible->SetValue(true);
84 else if (value == 3) {
85 fDiscoverable->SetValue(true);
86 fVisible->SetValue(true);
92 void
93 ExtendedLocalDeviceView::AttachedToWindow()
95 printf("ExtendedLocalDeviceView::AttachedToWindow\n");
96 fDiscoverable->SetTarget(this);
97 fVisible->SetTarget(this);
98 fAuthentication->SetTarget(this);
102 void
103 ExtendedLocalDeviceView::SetTarget(BHandler* target)
105 printf("ExtendedLocalDeviceView::SetTarget\n");
109 void
110 ExtendedLocalDeviceView::MessageReceived(BMessage* message)
112 printf("ExtendedLocalDeviceView::MessageReceived\n");
114 if (fDevice == NULL) {
115 printf("ExtendedLocalDeviceView::Device missing\n");
116 return;
119 if (message->WasDropped()) {
123 switch (message->what)
125 case SET_DISCOVERABLE:
126 case SET_VISIBLE:
127 fScanMode = 0;
129 if (fDiscoverable->Value()) {
130 fScanMode = 1;
131 fVisible->SetEnabled(true);
132 } else {
133 fVisible->SetValue(false);
134 fVisible->SetEnabled(false);
137 if (fVisible->Value())
138 fScanMode |= 2;
140 if (fDevice != NULL)
141 fDevice->SetDiscoverable(fScanMode);
143 break;
144 case SET_AUTHENTICATION:
145 if (fDevice != NULL)
146 fDevice->SetAuthentication(fAuthentication->Value());
147 break;
149 default:
150 BView::MessageReceived(message);
151 break;
156 void
157 ExtendedLocalDeviceView::SetEnabled(bool value)
159 printf("ExtendedLocalDeviceView::SetEnabled\n");
161 fVisible->SetEnabled(value);
162 fAuthentication->SetEnabled(value);
163 fDiscoverable->SetEnabled(value);
167 void
168 ExtendedLocalDeviceView::ClearDevice()
170 printf("ExtendedLocalDeviceView::ClearDevice\n");
172 fVisible->SetValue(false);
173 fAuthentication->SetValue(false);
174 fDiscoverable->SetValue(false);