xref: /haiku/src/add-ons/network_settings/dnsclient/DNSClientServiceAddOn.cpp (revision 4bd0c1066b227cec4b79883bdef697c7a27f2e90)
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 <NetworkSettings.h>
12 #include <NetworkSettingsAddOn.h>
13 #include <StringItem.h>
14 
15 #include "DNSSettingsView.h"
16 
17 
18 using namespace BNetworkKit;
19 
20 
21 #undef B_TRANSLATION_CONTEXT
22 #define B_TRANSLATION_CONTEXT "DNSClientServiceAddOn"
23 
24 
25 class DNSClientServiceAddOn : public BNetworkSettingsAddOn {
26 public:
27 								DNSClientServiceAddOn(image_id image,
28 									BNetworkSettings& settings);
29 	virtual						~DNSClientServiceAddOn();
30 
31 	virtual	BNetworkSettingsItem*
32 								CreateNextItem(uint32& cookie);
33 };
34 
35 
36 class DNSClientServiceItem : public BNetworkSettingsItem {
37 public:
38 								DNSClientServiceItem(
39 									BNetworkSettings& settings);
40 	virtual						~DNSClientServiceItem();
41 
42 	virtual	BNetworkSettingsType
43 								Type() const;
44 
45 	virtual BListItem*			ListItem();
46 	virtual BView*				View();
47 
48 	virtual	status_t			Revert();
49 	virtual bool				IsRevertable();
50 
51 private:
52 			BNetworkSettings&	fSettings;
53 			BStringItem*		fItem;
54 			DNSSettingsView*	fView;
55 };
56 
57 
58 // #pragma mark -
59 
60 
61 DNSClientServiceItem::DNSClientServiceItem(BNetworkSettings& settings)
62 	:
63 	fSettings(settings),
64 	fItem(new BStringItem(B_TRANSLATE("DNS settings"))),
65 	fView(NULL)
66 {
67 }
68 
69 
70 DNSClientServiceItem::~DNSClientServiceItem()
71 {
72 	if (fView->Parent() == NULL)
73 		delete fView;
74 
75 	delete fItem;
76 }
77 
78 
79 BNetworkSettingsType
80 DNSClientServiceItem::Type() const
81 {
82 	return B_NETWORK_SETTINGS_TYPE_SERVICE;
83 }
84 
85 
86 BListItem*
87 DNSClientServiceItem::ListItem()
88 {
89 	return fItem;
90 }
91 
92 
93 BView*
94 DNSClientServiceItem::View()
95 {
96 	if (fView == NULL)
97 		fView = new DNSSettingsView(this);
98 
99 	return fView;
100 }
101 
102 
103 status_t
104 DNSClientServiceItem::Revert()
105 {
106 	return B_OK;
107 }
108 
109 
110 bool
111 DNSClientServiceItem::IsRevertable()
112 {
113 	return false;
114 }
115 
116 
117 // #pragma mark -
118 
119 
120 DNSClientServiceAddOn::DNSClientServiceAddOn(image_id image,
121 	BNetworkSettings& settings)
122 	:
123 	BNetworkSettingsAddOn(image, settings)
124 {
125 }
126 
127 
128 DNSClientServiceAddOn::~DNSClientServiceAddOn()
129 {
130 }
131 
132 
133 BNetworkSettingsItem*
134 DNSClientServiceAddOn::CreateNextItem(uint32& cookie)
135 {
136 	if (cookie++ == 0)
137 		return new DNSClientServiceItem(Settings());
138 
139 	return NULL;
140 }
141 
142 
143 // #pragma mark -
144 
145 
146 extern "C"
147 BNetworkSettingsAddOn*
148 instantiate_network_settings_add_on(image_id image, BNetworkSettings& settings)
149 {
150 	return new DNSClientServiceAddOn(image, settings);
151 }
152