1/* 2 * Copyright 2001-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 <Button.h> 11#include <Catalog.h> 12#include <TextControl.h> 13 14#include <MailAddon.h> 15#include <Path.h> 16 17#include <FileConfigView.h> 18#include <ProtocolConfigView.h> 19#include <MailPrivate.h> 20 21#include "IMAPFolderConfig.h" 22 23 24#undef B_TRANSLATION_CONTEXT 25#define B_TRANSLATION_CONTEXT "imap_config" 26 27 28const uint32 kMsgOpenIMAPFolder = '&OIF'; 29 30 31class IMAPConfig : public BMailProtocolConfigView { 32public: 33 IMAPConfig(MailAddonSettings& settings, 34 BMailAccountSettings& accountSettings); 35 virtual ~IMAPConfig(); 36 virtual status_t Archive(BMessage *into, bool deep = true) const; 37 virtual void GetPreferredSize(float *width, float *height); 38 39 virtual void MessageReceived(BMessage* message); 40 virtual void AttachedToWindow(); 41 42private: 43 BMailFileConfigView* fFileView; 44 BButton* fIMAPFolderButton; 45 MailAddonSettings& fAddonSettings; 46}; 47 48 49IMAPConfig::IMAPConfig(MailAddonSettings& settings, 50 BMailAccountSettings& accountSettings) 51 : 52 BMailProtocolConfigView(B_MAIL_PROTOCOL_HAS_USERNAME 53 | B_MAIL_PROTOCOL_HAS_PASSWORD | B_MAIL_PROTOCOL_HAS_HOSTNAME 54 | B_MAIL_PROTOCOL_CAN_LEAVE_MAIL_ON_SERVER 55 | B_MAIL_PROTOCOL_PARTIAL_DOWNLOAD 56#ifdef USE_SSL 57 | B_MAIL_PROTOCOL_HAS_FLAVORS 58#endif 59 ), 60 fAddonSettings(settings) 61{ 62#ifdef USE_SSL 63 AddFlavor(B_TRANSLATE("No encryption")); 64 AddFlavor(B_TRANSLATE("SSL")); 65#endif 66 67 SetTo(settings); 68 69 ((BControl*)(FindView("leave_mail_on_server")))->SetValue(B_CONTROL_ON); 70 ((BControl*)(FindView("leave_mail_on_server")))->Hide(); 71 72 BRect frame = FindView("delete_remote_when_local")->Frame(); 73 74 ((BControl*)(FindView("delete_remote_when_local")))->SetEnabled(true); 75 ((BControl*)(FindView("delete_remote_when_local")))->MoveBy(0, -25); 76 77 fIMAPFolderButton = new BButton(frame, "IMAP Folders", B_TRANSLATE( 78 "IMAP Folders"), new BMessage(kMsgOpenIMAPFolder)); 79 AddChild(fIMAPFolderButton); 80 81 frame.right -= 10; 82 83 BPath defaultFolder = BPrivate::default_mail_directory(); 84 defaultFolder.Append(accountSettings.Name()); 85 86 fFileView = new BMailFileConfigView(B_TRANSLATE("Destination:"), 87 "destination", false, defaultFolder.Path()); 88 fFileView->SetTo(&settings.Settings(), NULL); 89 AddChild(fFileView); 90 fFileView->MoveBy(0, frame.bottom + 5); 91 92 ResizeToPreferred(); 93} 94 95 96IMAPConfig::~IMAPConfig() 97{ 98} 99 100 101status_t 102IMAPConfig::Archive(BMessage *into, bool deep) const 103{ 104 fFileView->Archive(into, deep); 105 return BMailProtocolConfigView::Archive(into, deep); 106} 107 108 109void 110IMAPConfig::GetPreferredSize(float *width, float *height) 111{ 112 BMailProtocolConfigView::GetPreferredSize(width,height); 113 *height -= 20; 114} 115 116 117void 118IMAPConfig::MessageReceived(BMessage* message) 119{ 120 switch (message->what) { 121 case kMsgOpenIMAPFolder: 122 { 123 BMessage settings; 124 Archive(&settings); 125 BWindow* window = new FolderConfigWindow(Window()->Frame(), 126 settings); 127 window->Show(); 128 break; 129 } 130 131 default: 132 BMailProtocolConfigView::MessageReceived(message); 133 } 134} 135 136 137void 138IMAPConfig::AttachedToWindow() 139{ 140 fIMAPFolderButton->SetTarget(this); 141} 142 143 144// #pragma mark - 145 146 147BView* 148instantiate_config_panel(MailAddonSettings& settings, 149 BMailAccountSettings& accountSettings) 150{ 151 return new IMAPConfig(settings, accountSettings); 152} 153