xref: /haiku/src/add-ons/network_settings/ipv4/IPv4InterfaceAddOn.cpp (revision 85fb1470bffd85ca09709a8eb78c65457dc28a27)
1 /*
2  * Copyright 2015 Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Axel Dörfler, <axeld@pinc-software.de>
7  */
8 
9 
10 #include <Catalog.h>
11 #include <NetworkSettingsAddOn.h>
12 #include <StringItem.h>
13 
14 #include "InterfaceAddressView.h"
15 
16 
17 using namespace BNetworkKit;
18 
19 
20 #undef B_TRANSLATION_CONTEXT
21 #define B_TRANSLATION_CONTEXT "IPv4InterfaceAddOn"
22 
23 
24 class IPv4InterfaceAddOn : public BNetworkSettingsAddOn {
25 public:
26 								IPv4InterfaceAddOn(image_id image);
27 	virtual						~IPv4InterfaceAddOn();
28 
29 	virtual	BNetworkSettingsInterfaceItem*
30 								CreateNextInterfaceItem(uint32& cookie,
31 									const char* interface);
32 };
33 
34 
35 class IPv4InterfaceItem : public BNetworkSettingsInterfaceItem {
36 public:
37 								IPv4InterfaceItem(const char* interface);
38 	virtual						~IPv4InterfaceItem();
39 
40 	virtual BListItem*			ListItem();
41 	virtual BView*				View();
42 
43 	virtual	status_t			Apply();
44 	virtual	status_t			Revert();
45 	virtual bool				IsRevertable();
46 
47 private:
48 			BStringItem*		fItem;
49 			InterfaceAddressView*
50 								fView;
51 };
52 
53 
54 // #pragma mark -
55 
56 
57 IPv4InterfaceItem::IPv4InterfaceItem(const char* interface)
58 	:
59 	BNetworkSettingsInterfaceItem(interface),
60 	fItem(new BStringItem(B_TRANSLATE("IPv4"))),
61 	fView(NULL)
62 {
63 }
64 
65 
66 IPv4InterfaceItem::~IPv4InterfaceItem()
67 {
68 	if (fView->Parent() == NULL)
69 		delete fView;
70 
71 	delete fItem;
72 }
73 
74 
75 BListItem*
76 IPv4InterfaceItem::ListItem()
77 {
78 	return fItem;
79 }
80 
81 
82 BView*
83 IPv4InterfaceItem::View()
84 {
85 	if (fView == NULL) {
86 		// TODO!
87 		fView = new InterfaceAddressView(AF_INET, Interface());
88 	}
89 	return fView;
90 }
91 
92 
93 status_t
94 IPv4InterfaceItem::Apply()
95 {
96 	return B_OK;
97 }
98 
99 
100 status_t
101 IPv4InterfaceItem::Revert()
102 {
103 	return B_OK;
104 }
105 
106 
107 bool
108 IPv4InterfaceItem::IsRevertable()
109 {
110 	return false;
111 }
112 
113 
114 // #pragma mark -
115 
116 
117 IPv4InterfaceAddOn::IPv4InterfaceAddOn(image_id image)
118 	:
119 	BNetworkSettingsAddOn(image)
120 {
121 }
122 
123 
124 IPv4InterfaceAddOn::~IPv4InterfaceAddOn()
125 {
126 }
127 
128 
129 BNetworkSettingsInterfaceItem*
130 IPv4InterfaceAddOn::CreateNextInterfaceItem(uint32& cookie,
131 	const char* interface)
132 {
133 	if (cookie++ == 0)
134 		return new IPv4InterfaceItem(interface);
135 
136 	return NULL;
137 }
138 
139 
140 // #pragma mark -
141 
142 
143 extern "C"
144 BNetworkSettingsAddOn*
145 instantiate_network_settings_add_on(image_id image)
146 {
147 	return new IPv4InterfaceAddOn(image);
148 }
149