1 /* 2 * Copyright 2003-2004 Waldemar Kornewald. All rights reserved. 3 * Copyright 2017 Haiku, Inc. All rights reserved. 4 * Distributed under the terms of the MIT License. 5 */ 6 7 8 #include <stdio.h> 9 #include <stdlib.h> 10 #include <string.h> 11 12 #include <dirent.h> 13 #include <sys/stat.h> 14 15 #include <String.h> 16 #include <ListView.h> 17 #include <ListItem.h> 18 #include <ScrollView.h> 19 #include <Box.h> 20 #include <Button.h> 21 #include <Bitmap.h> 22 #include <Alert.h> 23 24 #include <NetworkSettings.h> 25 #include <NetworkSettingsAddOn.h> 26 #include "InterfaceListItem.h" 27 28 #include "DialUpView.h" 29 30 31 using namespace BNetworkKit; 32 33 34 class AddOn : public BNetworkSettingsAddOn { 35 public: 36 AddOn(image_id addon_image, BNetworkSettings& settings); 37 virtual ~AddOn(); 38 39 virtual BNetworkSettingsItem* 40 CreateNextItem(uint32& cookie); 41 }; 42 43 44 class DialUpInterfaceItem : public BNetworkSettingsItem { 45 public: 46 DialUpInterfaceItem(BNetworkSettings& settings); 47 virtual ~DialUpInterfaceItem(); 48 49 virtual BNetworkSettingsType 50 Type() const; 51 52 virtual BListItem* ListItem(); 53 virtual BView* View(); 54 55 virtual status_t Revert(); 56 virtual bool IsRevertable(); 57 58 private: 59 BNetworkSettings& fSettings; 60 BListItem* fItem; 61 BView* fView; 62 }; 63 64 65 // #pragma mark - 66 67 68 DialUpInterfaceItem::DialUpInterfaceItem(BNetworkSettings& settings) 69 : 70 fSettings(settings), 71 fItem(new InterfaceListItem("Dialup", 72 B_NETWORK_INTERFACE_TYPE_DIAL_UP)), 73 fView(NULL) 74 { 75 } 76 77 78 DialUpInterfaceItem::~DialUpInterfaceItem() 79 { 80 if (fView->Parent() == NULL) 81 delete fView; 82 83 delete fItem; 84 } 85 86 87 BNetworkSettingsType 88 DialUpInterfaceItem::Type() const 89 { 90 return B_NETWORK_SETTINGS_TYPE_DIAL_UP; 91 } 92 93 94 BListItem* 95 DialUpInterfaceItem::ListItem() 96 { 97 return fItem; 98 } 99 100 101 BView* 102 DialUpInterfaceItem::View() 103 { 104 if (fView == NULL) 105 fView = new DialUpView(/*fSettings*/); 106 107 return fView; 108 } 109 110 111 status_t 112 DialUpInterfaceItem::Revert() 113 { 114 return B_OK; 115 } 116 117 bool 118 DialUpInterfaceItem::IsRevertable() 119 { 120 // TODO 121 return false; 122 } 123 124 125 // #pragma mark - 126 127 128 AddOn::AddOn(image_id image, BNetworkSettings& settings) 129 : BNetworkSettingsAddOn(image, settings) 130 { 131 } 132 133 134 AddOn::~AddOn() 135 { 136 } 137 138 139 BNetworkSettingsItem* 140 AddOn::CreateNextItem(uint32& cookie) 141 { 142 if (cookie++ == 0) 143 return new DialUpInterfaceItem(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 AddOn(image, settings); 157 } 158