xref: /haiku/src/apps/networkstatus/WirelessNetworkMenuItem.cpp (revision a629567a9001547736cfe892cdf992be16868fed)
1 /*
2  * Copyright 2010, Axel Dörfler, axeld@pinc-software.de.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 
7 #include "WirelessNetworkMenuItem.h"
8 
9 #include <Catalog.h>
10 #include <NetworkDevice.h>
11 #include <String.h>
12 
13 #include "RadioView.h"
14 
15 #undef B_TRANSLATION_CONTEXT
16 #define B_TRANSLATION_CONTEXT "WirelessNetworkMenuItem"
17 
18 
19 WirelessNetworkMenuItem::WirelessNetworkMenuItem(const char* name,
20 	int32 signalQuality, int32 authenticationMode, BMessage* message)
21 	:
22 	BMenuItem(name, message),
23 	fQuality(signalQuality)
24 {
25 	// Append authentication mode to label
26 	BString label = B_TRANSLATE("%name% (%authenticationMode%)");
27 	label.Replace("%name%", name, 1);
28 	label.Replace("%authenticationMode%",
29 		AuthenticationName(authenticationMode), 1);
30 
31 	SetLabel(label.String());
32 }
33 
34 
35 WirelessNetworkMenuItem::~WirelessNetworkMenuItem()
36 {
37 }
38 
39 
40 void
41 WirelessNetworkMenuItem::SetSignalQuality(int32 quality)
42 {
43 	fQuality = quality;
44 }
45 
46 
47 BString
48 WirelessNetworkMenuItem::AuthenticationName(int32 mode)
49 {
50 	switch (mode) {
51 		default:
52 		case B_NETWORK_AUTHENTICATION_NONE:
53 			return B_TRANSLATE_CONTEXT("open", "Open network");
54 			break;
55 		case B_NETWORK_AUTHENTICATION_WEP:
56 			return B_TRANSLATE_CONTEXT("WEP", "WEP protected network");
57 			break;
58 		case B_NETWORK_AUTHENTICATION_WPA:
59 			return B_TRANSLATE_CONTEXT("WPA", "WPA protected network");
60 			break;
61 		case B_NETWORK_AUTHENTICATION_WPA2:
62 			return B_TRANSLATE_CONTEXT("WPA2", "WPA2 protected network");
63 			break;
64 		case B_NETWORK_AUTHENTICATION_EAP:
65 			return B_TRANSLATE_CONTEXT("EAP", "EAP protected network");
66 			break;
67 	}
68 }
69 
70 
71 void
72 WirelessNetworkMenuItem::DrawContent()
73 {
74 	DrawRadioIcon();
75 	BMenuItem::DrawContent();
76 }
77 
78 
79 void
80 WirelessNetworkMenuItem::Highlight(bool isHighlighted)
81 {
82 	BMenuItem::Highlight(isHighlighted);
83 }
84 
85 
86 void
87 WirelessNetworkMenuItem::GetContentSize(float* width, float* height)
88 {
89 	BMenuItem::GetContentSize(width, height);
90 	*width += *height + 4;
91 }
92 
93 
94 void
95 WirelessNetworkMenuItem::DrawRadioIcon()
96 {
97 	BRect bounds = Frame();
98 	bounds.left = bounds.right - 4 - bounds.Height();
99 	bounds.right -= 4;
100 	bounds.bottom -= 2;
101 
102 	RadioView::Draw(Menu(), bounds, fQuality, RadioView::DefaultMax());
103 }
104