xref: /haiku/src/preferences/bluetooth/RemoteDevicesView.cpp (revision 96455f01e8645027964cb1fc2bb00f8e18ed18e8)
1*96455f01SOliver Ruiz Dorantes /*
2*96455f01SOliver Ruiz Dorantes  * Copyright 2008-09, Oliver Ruiz Dorantes, <oliver.ruiz.dorantes_at_gmail.com>
3*96455f01SOliver Ruiz Dorantes  * All rights reserved. Distributed under the terms of the MIT License.
4*96455f01SOliver Ruiz Dorantes  */
5*96455f01SOliver Ruiz Dorantes #include "RemoteDevicesView.h"
6*96455f01SOliver Ruiz Dorantes 
7*96455f01SOliver Ruiz Dorantes #include <Alert.h>
8*96455f01SOliver Ruiz Dorantes #include <Directory.h>
9*96455f01SOliver Ruiz Dorantes #include <Entry.h>
10*96455f01SOliver Ruiz Dorantes #include <File.h>
11*96455f01SOliver Ruiz Dorantes #include <GroupLayoutBuilder.h>
12*96455f01SOliver Ruiz Dorantes #include <Messenger.h>
13*96455f01SOliver Ruiz Dorantes #include <Path.h>
14*96455f01SOliver Ruiz Dorantes #include <SpaceLayoutItem.h>
15*96455f01SOliver Ruiz Dorantes 
16*96455f01SOliver Ruiz Dorantes #include <stdio.h>
17*96455f01SOliver Ruiz Dorantes 
18*96455f01SOliver Ruiz Dorantes #include "BluetoothWindow.h"
19*96455f01SOliver Ruiz Dorantes #include "defs.h"
20*96455f01SOliver Ruiz Dorantes 
21*96455f01SOliver Ruiz Dorantes static const uint32 kMsgAddDevices = 'ddDv';
22*96455f01SOliver Ruiz Dorantes 
23*96455f01SOliver Ruiz Dorantes 
24*96455f01SOliver Ruiz Dorantes 
25*96455f01SOliver Ruiz Dorantes 
26*96455f01SOliver Ruiz Dorantes RemoteDevicesView::RemoteDevicesView(const char *name, uint32 flags)
27*96455f01SOliver Ruiz Dorantes  :	BView(name, flags)
28*96455f01SOliver Ruiz Dorantes {
29*96455f01SOliver Ruiz Dorantes 	SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
30*96455f01SOliver Ruiz Dorantes 
31*96455f01SOliver Ruiz Dorantes 	BButton* addButton = new BButton(BRect(5,5,5,5), "add", "Add" B_UTF8_ELLIPSIS,
32*96455f01SOliver Ruiz Dorantes 										new BMessage(kMsgAddDevices), B_FOLLOW_RIGHT);
33*96455f01SOliver Ruiz Dorantes 
34*96455f01SOliver Ruiz Dorantes 	BButton* removeButton = new BButton(BRect(5,5,5,5), "remove", "Remove",
35*96455f01SOliver Ruiz Dorantes 										new BMessage(kMsgAddDevices), B_FOLLOW_RIGHT);
36*96455f01SOliver Ruiz Dorantes 
37*96455f01SOliver Ruiz Dorantes 	BButton* trustButton = new BButton(BRect(5,5,5,5), "trust", "As Trusted",
38*96455f01SOliver Ruiz Dorantes 										new BMessage(kMsgAddDevices), B_FOLLOW_RIGHT);
39*96455f01SOliver Ruiz Dorantes 
40*96455f01SOliver Ruiz Dorantes 
41*96455f01SOliver Ruiz Dorantes 	BButton* blockButton = new BButton(BRect(5,5,5,5), "trust", "As Blocked",
42*96455f01SOliver Ruiz Dorantes 										new BMessage(kMsgAddDevices), B_FOLLOW_RIGHT);
43*96455f01SOliver Ruiz Dorantes 
44*96455f01SOliver Ruiz Dorantes 
45*96455f01SOliver Ruiz Dorantes 	BButton* availButton = new BButton(BRect(5,5,5,5), "check", "Refresh" B_UTF8_ELLIPSIS,
46*96455f01SOliver Ruiz Dorantes 										new BMessage(kMsgAddDevices), B_FOLLOW_RIGHT);
47*96455f01SOliver Ruiz Dorantes 
48*96455f01SOliver Ruiz Dorantes 
49*96455f01SOliver Ruiz Dorantes 
50*96455f01SOliver Ruiz Dorantes 	// Set up list of color attributes
51*96455f01SOliver Ruiz Dorantes 	fAttrList = new BListView("AttributeList", B_SINGLE_SELECTION_LIST);
52*96455f01SOliver Ruiz Dorantes 
53*96455f01SOliver Ruiz Dorantes 	fScrollView = new BScrollView("ScrollView", fAttrList, 0, false, true);
54*96455f01SOliver Ruiz Dorantes 	fScrollView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
55*96455f01SOliver Ruiz Dorantes 
56*96455f01SOliver Ruiz Dorantes 	SetLayout(new BGroupLayout(B_VERTICAL));
57*96455f01SOliver Ruiz Dorantes 
58*96455f01SOliver Ruiz Dorantes 	// TODO: Make list view and scroller use all the additional height
59*96455f01SOliver Ruiz Dorantes 	// available!
60*96455f01SOliver Ruiz Dorantes 	AddChild(BGroupLayoutBuilder(B_HORIZONTAL, 10)
61*96455f01SOliver Ruiz Dorantes 		.Add(fScrollView)
62*96455f01SOliver Ruiz Dorantes 		//.Add(BSpaceLayoutItem::CreateHorizontalStrut(5))
63*96455f01SOliver Ruiz Dorantes 		.Add(BGroupLayoutBuilder(B_VERTICAL)
64*96455f01SOliver Ruiz Dorantes 						.Add(addButton)
65*96455f01SOliver Ruiz Dorantes 						.Add(removeButton)
66*96455f01SOliver Ruiz Dorantes 						.AddGlue()
67*96455f01SOliver Ruiz Dorantes 						.Add(availButton)
68*96455f01SOliver Ruiz Dorantes 						.AddGlue()
69*96455f01SOliver Ruiz Dorantes 						.Add(trustButton)
70*96455f01SOliver Ruiz Dorantes 						.Add(blockButton)
71*96455f01SOliver Ruiz Dorantes 						.AddGlue()
72*96455f01SOliver Ruiz Dorantes 						.SetInsets(0, 15, 0, 15)
73*96455f01SOliver Ruiz Dorantes 			)
74*96455f01SOliver Ruiz Dorantes 		.SetInsets(5, 5, 5, 100)
75*96455f01SOliver Ruiz Dorantes 	);
76*96455f01SOliver Ruiz Dorantes 
77*96455f01SOliver Ruiz Dorantes 	fAttrList->SetSelectionMessage(new BMessage(ATTRIBUTE_CHOSEN));
78*96455f01SOliver Ruiz Dorantes }
79*96455f01SOliver Ruiz Dorantes 
80*96455f01SOliver Ruiz Dorantes RemoteDevicesView::~RemoteDevicesView(void)
81*96455f01SOliver Ruiz Dorantes {
82*96455f01SOliver Ruiz Dorantes 
83*96455f01SOliver Ruiz Dorantes }
84*96455f01SOliver Ruiz Dorantes 
85*96455f01SOliver Ruiz Dorantes void
86*96455f01SOliver Ruiz Dorantes RemoteDevicesView::AttachedToWindow(void)
87*96455f01SOliver Ruiz Dorantes {
88*96455f01SOliver Ruiz Dorantes 	fAttrList->SetTarget(this);
89*96455f01SOliver Ruiz Dorantes 
90*96455f01SOliver Ruiz Dorantes 	LoadSettings();
91*96455f01SOliver Ruiz Dorantes 	fAttrList->Select(0);
92*96455f01SOliver Ruiz Dorantes }
93*96455f01SOliver Ruiz Dorantes 
94*96455f01SOliver Ruiz Dorantes void
95*96455f01SOliver Ruiz Dorantes RemoteDevicesView::MessageReceived(BMessage *msg)
96*96455f01SOliver Ruiz Dorantes {
97*96455f01SOliver Ruiz Dorantes 	if (msg->WasDropped()) {
98*96455f01SOliver Ruiz Dorantes 		rgb_color *color;
99*96455f01SOliver Ruiz Dorantes 		ssize_t size;
100*96455f01SOliver Ruiz Dorantes 
101*96455f01SOliver Ruiz Dorantes 		if (msg->FindData("RGBColor", (type_code)'RGBC', (const void**)&color, &size) == B_OK) {
102*96455f01SOliver Ruiz Dorantes 
103*96455f01SOliver Ruiz Dorantes 		}
104*96455f01SOliver Ruiz Dorantes 	}
105*96455f01SOliver Ruiz Dorantes 
106*96455f01SOliver Ruiz Dorantes 	switch(msg->what) {
107*96455f01SOliver Ruiz Dorantes 
108*96455f01SOliver Ruiz Dorantes 		default:
109*96455f01SOliver Ruiz Dorantes 			BView::MessageReceived(msg);
110*96455f01SOliver Ruiz Dorantes 			break;
111*96455f01SOliver Ruiz Dorantes 	}
112*96455f01SOliver Ruiz Dorantes }
113*96455f01SOliver Ruiz Dorantes 
114*96455f01SOliver Ruiz Dorantes void RemoteDevicesView::LoadSettings(void)
115*96455f01SOliver Ruiz Dorantes {
116*96455f01SOliver Ruiz Dorantes 
117*96455f01SOliver Ruiz Dorantes }
118*96455f01SOliver Ruiz Dorantes 
119*96455f01SOliver Ruiz Dorantes bool RemoteDevicesView::IsDefaultable(void)
120*96455f01SOliver Ruiz Dorantes {
121*96455f01SOliver Ruiz Dorantes 	return true;
122*96455f01SOliver Ruiz Dorantes }
123*96455f01SOliver Ruiz Dorantes 
124