1 /* 2 * Copyright 2007-2011, Haiku, Inc. All rights reserved. 3 * Copyright 2001-2002 Dr. Zoidberg Enterprises. All rights reserved. 4 * Copyright 2011, Clemens Zeidler <haiku@clemens-zeidler.de> 5 * 6 * Distributed under the terms of the MIT License. 7 */ 8 9 10 #include <TextControl.h> 11 12 #include <FileConfigView.h> 13 #include <MDRLanguage.h> 14 #include <MailAddon.h> 15 #include <MenuField.h> 16 #include <ProtocolConfigView.h> 17 18 19 class SMTPConfigView : public BMailProtocolConfigView { 20 public: 21 SMTPConfigView(MailAddonSettings& settings, 22 BMailAccountSettings& accountSettings); 23 status_t Archive(BMessage *into, bool deep = true) const; 24 void GetPreferredSize(float *width, float *height); 25 private: 26 BMailFileConfigView* fFileView; 27 }; 28 29 30 SMTPConfigView::SMTPConfigView(MailAddonSettings& settings, 31 BMailAccountSettings& accountSettings) 32 : 33 #ifdef USE_SSL 34 BMailProtocolConfigView( B_MAIL_PROTOCOL_HAS_AUTH_METHODS 35 | B_MAIL_PROTOCOL_HAS_USERNAME | B_MAIL_PROTOCOL_HAS_PASSWORD 36 | B_MAIL_PROTOCOL_HAS_HOSTNAME | B_MAIL_PROTOCOL_HAS_FLAVORS) 37 #else 38 BMailProtocolConfigView(B_MAIL_PROTOCOL_HAS_AUTH_METHODS 39 | B_MAIL_PROTOCOL_HAS_USERNAME | B_MAIL_PROTOCOL_HAS_PASSWORD 40 | B_MAIL_PROTOCOL_HAS_HOSTNAME) 41 #endif 42 { 43 #ifdef USE_SSL 44 AddFlavor("Unencrypted"); 45 AddFlavor("SSL"); 46 AddFlavor("STARTTLS"); 47 #endif 48 49 AddAuthMethod(MDR_DIALECT_CHOICE("None","無し"), false); 50 AddAuthMethod(MDR_DIALECT_CHOICE("ESMTP","ESMTP")); 51 AddAuthMethod(MDR_DIALECT_CHOICE("POP3 before SMTP","送信前に受信する"), 52 false); 53 54 BTextControl *control = (BTextControl *)(FindView("host")); 55 control->SetLabel(MDR_DIALECT_CHOICE("SMTP server: ","SMTPサーバ: ")); 56 57 // Reset the dividers after changing one 58 float widestLabel=0; 59 for (int32 i = CountChildren(); i-- > 0;) { 60 if(BTextControl *text = dynamic_cast<BTextControl *>(ChildAt(i))) 61 widestLabel = MAX(widestLabel,text->StringWidth(text->Label()) + 5); 62 } 63 for (int32 i = CountChildren(); i-- > 0;) { 64 if(BTextControl *text = dynamic_cast<BTextControl *>(ChildAt(i))) 65 text->SetDivider(widestLabel); 66 } 67 68 BMenuField *field = (BMenuField *)(FindView("auth_method")); 69 field->SetDivider(widestLabel); 70 71 SetTo(settings); 72 73 fFileView = new BMailFileConfigView("Destination:", "destination", 74 false, default_sent_directory()); 75 fFileView->SetTo(&settings.Settings(), NULL); 76 AddChild(fFileView); 77 float w, h; 78 BMailProtocolConfigView::GetPreferredSize(&w, &h); 79 fFileView->MoveBy(0, h - 10); 80 GetPreferredSize(&w, &h); 81 ResizeTo(w, h); 82 } 83 84 85 status_t 86 SMTPConfigView::Archive(BMessage *into, bool deep) const 87 { 88 fFileView->Archive(into, deep); 89 return BMailProtocolConfigView::Archive(into, deep); 90 } 91 92 93 void 94 SMTPConfigView::GetPreferredSize(float* width, float* height) 95 { 96 BMailProtocolConfigView::GetPreferredSize(width, height); 97 *width += 20; 98 *height += 20; 99 } 100 101 102 BView* 103 instantiate_config_panel(MailAddonSettings& settings, 104 BMailAccountSettings& accountSettings) 105 { 106 return new SMTPConfigView(settings, accountSettings); 107 } 108 109