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