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 "IPv6InterfaceAddOn" 22 23 24 class IPv6InterfaceAddOn : public BNetworkSettingsAddOn { 25 public: 26 IPv6InterfaceAddOn(image_id image, 27 BNetworkSettings& settings); 28 virtual ~IPv6InterfaceAddOn(); 29 30 virtual BNetworkSettingsInterfaceItem* 31 CreateNextInterfaceItem(uint32& cookie, 32 const char* interface); 33 }; 34 35 36 class IPv6InterfaceItem : public BNetworkSettingsInterfaceItem { 37 public: 38 IPv6InterfaceItem(const char* interface, 39 BNetworkSettings& settings); 40 virtual ~IPv6InterfaceItem(); 41 42 virtual BListItem* ListItem(); 43 virtual BView* View(); 44 45 virtual status_t Revert(); 46 virtual bool IsRevertable(); 47 48 virtual void ConfigurationUpdated(const BMessage& message); 49 50 private: 51 BNetworkSettings& fSettings; 52 BNetworkInterfaceListItem* 53 fItem; 54 InterfaceAddressView* 55 fView; 56 }; 57 58 59 // #pragma mark - 60 61 62 IPv6InterfaceItem::IPv6InterfaceItem(const char* interface, 63 BNetworkSettings& settings) 64 : 65 BNetworkSettingsInterfaceItem(interface), 66 fSettings(settings), 67 fItem(new BNetworkInterfaceListItem(AF_INET6, Interface(), 68 B_TRANSLATE("IPv6"), settings)), 69 fView(NULL) 70 { 71 } 72 73 74 IPv6InterfaceItem::~IPv6InterfaceItem() 75 { 76 if (fView->Parent() == NULL) 77 delete fView; 78 79 delete fItem; 80 } 81 82 83 BListItem* 84 IPv6InterfaceItem::ListItem() 85 { 86 return fItem; 87 } 88 89 90 BView* 91 IPv6InterfaceItem::View() 92 { 93 if (fView == NULL) 94 fView = new InterfaceAddressView(AF_INET6, Interface(), fSettings); 95 96 return fView; 97 } 98 99 100 status_t 101 IPv6InterfaceItem::Revert() 102 { 103 return fView != NULL ? fView->Revert() : B_OK; 104 } 105 106 107 bool 108 IPv6InterfaceItem::IsRevertable() 109 { 110 return fView != NULL ? fView->IsRevertable() : false; 111 } 112 113 114 void 115 IPv6InterfaceItem::ConfigurationUpdated(const BMessage& message) 116 { 117 if (fView != NULL) 118 fView->ConfigurationUpdated(message); 119 } 120 121 122 // #pragma mark - 123 124 125 IPv6InterfaceAddOn::IPv6InterfaceAddOn(image_id image, 126 BNetworkSettings& settings) 127 : 128 BNetworkSettingsAddOn(image, settings) 129 { 130 } 131 132 133 IPv6InterfaceAddOn::~IPv6InterfaceAddOn() 134 { 135 } 136 137 138 BNetworkSettingsInterfaceItem* 139 IPv6InterfaceAddOn::CreateNextInterfaceItem(uint32& cookie, 140 const char* interface) 141 { 142 if (cookie++ == 0) 143 return new IPv6InterfaceItem(interface, Settings()); 144 145 return NULL; 146 } 147 148 149 // #pragma mark - 150 151 152 extern "C" 153 BNetworkSettingsAddOn* 154 instantiate_network_settings_add_on(image_id image, BNetworkSettings& settings) 155 { 156 return new IPv6InterfaceAddOn(image, settings); 157 } 158