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