xref: /haiku/headers/os/add-ons/network_settings/NetworkSettingsAddOn.h (revision 02354704729d38c3b078c696adc1bbbd33cbcf72)
1 /*
2  * Copyright 2004-2015 Haiku Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  */
6 #ifndef _NETWORK_SETTINGS_ADD_ON_H
7 #define _NETWORK_SETTINGS_ADD_ON_H
8 
9 
10 #include <image.h>
11 #include <ListItem.h>
12 #include <Resources.h>
13 #include <String.h>
14 #include <View.h>
15 
16 
17 class BNetworkAddress;
18 
19 
20 namespace BNetworkKit {
21 
22 
23 enum BNetworkSettingsType {
24 	B_NETWORK_SETTINGS_TYPE_INTERFACE = 'intf',
25 	B_NETWORK_SETTINGS_TYPE_SERVICE = 'serv',
26 	B_NETWORK_SETTINGS_TYPE_DIAL_UP = 'dial',
27 	B_NETWORK_SETTINGS_TYPE_VPN = 'vpnc',
28 	B_NETWORK_SETTINGS_TYPE_OTHER = 'othr'
29 };
30 
31 class BNetworkProfile;
32 class BNetworkSettings;
33 
34 
35 class BNetworkConfigurationListener {
36 public:
37 	virtual void				ConfigurationUpdated(
38 									const BMessage& message) = 0;
39 };
40 
41 
42 class BNetworkSettingsListener {
43 public:
44 	virtual void				SettingsUpdated(uint32 type) = 0;
45 };
46 
47 
48 class BNetworkSettingsItem : public BNetworkConfigurationListener,
49 	BNetworkSettingsListener {
50 public:
51 								BNetworkSettingsItem();
52 	virtual						~BNetworkSettingsItem();
53 
54 	virtual	BNetworkSettingsType
55 								Type() const = 0;
56 	virtual BListItem*			ListItem() = 0;
57 	virtual BView*				View() = 0;
58 
59 	virtual status_t			ProfileChanged(
60 									const BNetworkProfile* newProfile);
61 			const BNetworkProfile*
62 								Profile() const;
63 
64 	virtual	status_t			Revert() = 0;
65 	virtual bool				IsRevertable() = 0;
66 
67 	virtual void				SettingsUpdated(uint32 type);
68 	virtual void				ConfigurationUpdated(const BMessage& message);
69 
70 	virtual	void				NotifySettingsUpdated();
71 
72 private:
73 			const BNetworkProfile*
74 								fProfile;
75 };
76 
77 
78 class BNetworkSettingsInterfaceItem : public BNetworkSettingsItem {
79 public:
80 								BNetworkSettingsInterfaceItem(
81 									const char* interface);
82 	virtual						~BNetworkSettingsInterfaceItem();
83 
84 	virtual	BNetworkSettingsType
85 								Type() const;
86 			const char*			Interface() const;
87 
88 private:
89 			const char*			fInterface;
90 };
91 
92 
93 class BNetworkInterfaceListItem : public BListItem,
94 	public BNetworkConfigurationListener {
95 public:
96 								BNetworkInterfaceListItem(int family,
97 									const char* interface, const char* label,
98 									BNetworkSettings& settings);
99 								~BNetworkInterfaceListItem();
100 
101 			const char*			Label() const;
102 
103 	virtual	void				DrawItem(BView* owner,
104 									BRect bounds, bool complete);
105 	virtual	void				Update(BView* owner, const BFont* font);
106 
107 	virtual void				ConfigurationUpdated(const BMessage& message);
108 
109 private:
110 			BFont				_AddressFont();
111 			void				_UpdateState();
112 
113 private:
114 			BNetworkSettings&	fSettings;
115 			int					fFamily;
116 			const char*			fInterface;
117 			const char*			fLabel;
118 			BString				fAddress;
119 			bool				fDisabled;
120 			float				fLineOffset;
121 			float				fSpacing;
122 };
123 
124 
125 class BNetworkSettingsAddOn {
126 public:
127 								BNetworkSettingsAddOn(image_id image,
128 									BNetworkSettings& settings);
129 	virtual						~BNetworkSettingsAddOn();
130 
131 	virtual	BNetworkSettingsInterfaceItem*
132 								CreateNextInterfaceItem(uint32& cookie,
133 									const char* interface);
134 	virtual	BNetworkSettingsItem*
135 								CreateNextItem(uint32& cookie);
136 
137 			image_id			Image();
138 			BResources*			Resources();
139 			BNetworkSettings&	Settings();
140 
141 private:
142 			image_id			fImage;
143 			BResources*			fResources;
144 			BNetworkSettings&	fSettings;
145 };
146 
147 
148 // Your add-on needs to export this hook in order to be picked up
149 extern "C" BNetworkSettingsAddOn* instantiate_network_settings_add_on(
150 	image_id image, BNetworkSettings& settings);
151 
152 
153 }	// namespace BNetworkKit
154 
155 
156 #endif // _NETWORK_SETTINGS_ADD_ON_H
157