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 18using namespace BNetworkKit; 19 20 21#undef B_TRANSLATION_CONTEXT 22#define B_TRANSLATION_CONTEXT "FTPServiceAddOn" 23 24 25class FTPServiceAddOn : public BNetworkSettingsAddOn { 26public: 27 FTPServiceAddOn(image_id image, 28 BNetworkSettings& settings); 29 virtual ~FTPServiceAddOn(); 30 31 virtual BNetworkSettingsItem* 32 CreateNextItem(uint32& cookie); 33}; 34 35 36class FTPServiceItem : public BNetworkSettingsItem { 37public: 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 52private: 53 BNetworkSettings& fSettings; 54 BListItem* fItem; 55 ServiceView* fView; 56}; 57 58 59// #pragma mark - 60 61 62FTPServiceItem::FTPServiceItem(BNetworkSettings& settings) 63 : 64 fSettings(settings), 65 fItem(new ServiceListItem("ftp", B_TRANSLATE("FTP server"), settings)), 66 fView(NULL) 67{ 68} 69 70 71FTPServiceItem::~FTPServiceItem() 72{ 73 if (fView->Parent() == NULL) 74 delete fView; 75 76 delete fItem; 77} 78 79 80BNetworkSettingsType 81FTPServiceItem::Type() const 82{ 83 return B_NETWORK_SETTINGS_TYPE_SERVICE; 84} 85 86 87BListItem* 88FTPServiceItem::ListItem() 89{ 90 return fItem; 91} 92 93 94BView* 95FTPServiceItem::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 109status_t 110FTPServiceItem::Revert() 111{ 112 return fView != NULL ? fView->Revert() : B_OK; 113} 114 115 116bool 117FTPServiceItem::IsRevertable() 118{ 119 return fView != NULL ? fView->IsRevertable() : false; 120} 121 122 123void 124FTPServiceItem::SettingsUpdated(uint32 which) 125{ 126 if (fView != NULL) 127 fView->SettingsUpdated(which); 128} 129 130 131// #pragma mark - 132 133 134FTPServiceAddOn::FTPServiceAddOn(image_id image, 135 BNetworkSettings& settings) 136 : 137 BNetworkSettingsAddOn(image, settings) 138{ 139} 140 141 142FTPServiceAddOn::~FTPServiceAddOn() 143{ 144} 145 146 147BNetworkSettingsItem* 148FTPServiceAddOn::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 160extern "C" 161BNetworkSettingsAddOn* 162instantiate_network_settings_add_on(image_id image, BNetworkSettings& settings) 163{ 164 return new FTPServiceAddOn(image, settings); 165} 166