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