1/*
2 * Copyright 2021, Haiku, Inc.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 * 		Tri-Edge AI <triedgeai@gmail.com>
7 */
8
9#include <ConnectionView.h>
10#include <BluetoothIconView.h>
11
12namespace Bluetooth
13{
14
15ConnectionView::ConnectionView(BRect frame, BString device, BString address)
16	:
17	BView(frame, "ConnectionView", 0, B_PULSE_NEEDED)
18{
19	SetLayout(new BGroupLayout(B_HORIZONTAL));
20	SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
21
22	fIcon = new BluetoothIconView();
23
24	strMessage = "A new connection is incoming..";
25
26	fMessage = new BStringView(frame, "", strMessage, B_FOLLOW_LEFT);
27	fMessage->SetAlignment(B_ALIGN_LEFT);
28
29	fDeviceLabel = new BStringView(frame, "", "Device Name:", B_FOLLOW_LEFT);
30	fDeviceLabel->SetFont(be_bold_font);
31
32	fDeviceText = new BStringView(frame, "", device, B_FOLLOW_RIGHT);
33	fDeviceText->SetAlignment(B_ALIGN_RIGHT);
34
35	fAddressLabel = new BStringView(frame, "", "MAC Address:", B_FOLLOW_LEFT);
36	fAddressLabel->SetFont(be_bold_font);
37
38	fAddressText = new BStringView(frame, "", address, B_FOLLOW_RIGHT);
39	fAddressText->SetAlignment(B_ALIGN_RIGHT);
40
41	AddChild(BGroupLayoutBuilder(B_HORIZONTAL, 0)
42			.Add(BGroupLayoutBuilder(B_VERTICAL, 8)
43				.Add(fIcon)
44			)
45			.Add(BGroupLayoutBuilder(B_VERTICAL, 0)
46				.Add(fMessage)
47				.AddGlue()
48				.Add(BGroupLayoutBuilder(B_HORIZONTAL, 10)
49					.Add(fDeviceLabel)
50					.AddGlue()
51					.Add(fDeviceText)
52				)
53				.Add(BGroupLayoutBuilder(B_HORIZONTAL, 10)
54					.Add(fAddressLabel)
55					.AddGlue()
56					.Add(fAddressText)
57				)
58				.AddGlue()
59			)
60			.AddGlue()
61			.SetInsets(8, 8, 8, 8)
62	);
63}
64
65
66void
67ConnectionView::Pulse()
68{
69	static int pulses = 0;
70
71	pulses++;
72
73	if (pulses >= 5) {
74		Window()->PostMessage(B_QUIT_REQUESTED);
75	} else {
76		strMessage += ".";
77		fMessage->SetText(strMessage);
78	}
79}
80
81}
82