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 14 #include "ServiceListItem.h" 15 #include "ServiceView.h" 16 17 18 using namespace BNetworkKit; 19 20 21 #undef B_TRANSLATION_CONTEXT 22 #define B_TRANSLATION_CONTEXT "FTPServiceAddOn" 23 24 25 class FTPServiceAddOn : public BNetworkSettingsAddOn { 26 public: 27 FTPServiceAddOn(image_id image, 28 BNetworkSettings& settings); 29 virtual ~FTPServiceAddOn(); 30 31 virtual BNetworkSettingsItem* 32 CreateNextItem(uint32& cookie); 33 }; 34 35 36 class FTPServiceItem : public BNetworkSettingsItem { 37 public: 38 FTPServiceItem(BNetworkSettings& settings); 39 virtual ~FTPServiceItem(); 40 41 virtual BNetworkSettingsType 42 Type() const; 43 44 virtual BListItem* ListItem(); 45 virtual BView* View(); 46 47 virtual status_t Revert(); 48 virtual bool IsRevertable(); 49 50 virtual void SettingsUpdated(uint32 which); 51 52 private: 53 BNetworkSettings& fSettings; 54 BListItem* fItem; 55 ServiceView* fView; 56 }; 57 58 59 // #pragma mark - 60 61 62 FTPServiceItem::FTPServiceItem(BNetworkSettings& settings) 63 : 64 fSettings(settings), 65 fItem(new ServiceListItem("ftp", B_TRANSLATE("FTP server"), settings)), 66 fView(NULL) 67 { 68 } 69 70 71 FTPServiceItem::~FTPServiceItem() 72 { 73 if (fView->Parent() == NULL) 74 delete fView; 75 76 delete fItem; 77 } 78 79 80 BNetworkSettingsType 81 FTPServiceItem::Type() const 82 { 83 return B_NETWORK_SETTINGS_TYPE_SERVICE; 84 } 85 86 87 BListItem* 88 FTPServiceItem::ListItem() 89 { 90 return fItem; 91 } 92 93 94 BView* 95 FTPServiceItem::View() 96 { 97 if (fView == NULL) { 98 fView = new ServiceView("ftp", "ftpd", B_TRANSLATE("FTP server"), 99 B_TRANSLATE("The FTP server allows you to remotely access the " 100 "files on your machine using the FTP protocol.\n\nPlease note " 101 "that it is an insecure and unencrypted connection."), 102 fSettings); 103 } 104 105 return fView; 106 } 107 108 109 status_t 110 FTPServiceItem::Revert() 111 { 112 return fView != NULL ? fView->Revert() : B_OK; 113 } 114 115 116 bool 117 FTPServiceItem::IsRevertable() 118 { 119 return fView != NULL ? fView->IsRevertable() : false; 120 } 121 122 123 void 124 FTPServiceItem::SettingsUpdated(uint32 which) 125 { 126 if (fView != NULL) 127 fView->SettingsUpdated(which); 128 } 129 130 131 // #pragma mark - 132 133 134 FTPServiceAddOn::FTPServiceAddOn(image_id image, 135 BNetworkSettings& settings) 136 : 137 BNetworkSettingsAddOn(image, settings) 138 { 139 } 140 141 142 FTPServiceAddOn::~FTPServiceAddOn() 143 { 144 } 145 146 147 BNetworkSettingsItem* 148 FTPServiceAddOn::CreateNextItem(uint32& cookie) 149 { 150 if (cookie++ == 0) 151 return new FTPServiceItem(Settings()); 152 153 return NULL; 154 } 155 156 157 // #pragma mark - 158 159 160 extern "C" 161 BNetworkSettingsAddOn* 162 instantiate_network_settings_add_on(image_id image, BNetworkSettings& settings) 163 { 164 return new FTPServiceAddOn(image, settings); 165 } 166