📄 accountsettings.java
字号:
/*MujMail - Simple mail client for J2MECopyright (C) 2006 Nguyen Son Tung <n.sontung@gmail.com>Copyright (C) 2006 Martin Stefan <martin.stefan@centrum.cz>This program is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2 of the License, or(at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */package mujmail.account;import java.io.ByteArrayInputStream;import java.io.ByteArrayOutputStream;import java.io.DataInputStream;import java.io.DataOutputStream;import javax.microedition.lcdui.AlertType;import javax.microedition.lcdui.Choice;import javax.microedition.lcdui.ChoiceGroup;import javax.microedition.lcdui.Command;import javax.microedition.lcdui.Form;import javax.microedition.lcdui.Item;import javax.microedition.lcdui.ItemStateListener;import javax.microedition.lcdui.TextField;import javax.microedition.rms.RecordEnumeration;import javax.microedition.rms.RecordStore;import javax.microedition.rms.RecordStoreException;import mujmail.Lang;import mujmail.MujMail;import mujmail.MyAlert;import mujmail.Properties;import mujmail.Settings;import mujmail.protocols.IMAP4;import mujmail.protocols.POP3;import mujmail.protocols.SMTP;//#ifdef MUJMAIL_SSLimport mujmail.ui.SSLTypeChooser;//#endif/** * Cares about administration of the account. * Offers the form for creating new account, * the settings reads and stores into * the database. */public class AccountSettings extends Form implements Runnable, ItemStateListener { /** Flag signals if we want to print debug prints */ private static final boolean DEBUG = false; /// Debugging output for this file /** Standard TCP port for POP communication */ public static final int CONST_PORT_POP = 110; /** Standard TCP port for POP communication secured by SSL */ public static final int CONST_PORT_POPS = 995; /** Standard TCP port for IMAP communication */ public static final int CONST_PORT_IMAP = 143; /** Standard TCP port for IMAP communication secured by SSL */ public static final int CONST_PORT_IMAPS = 993; private ChoiceGroup active; private TextField email; private ChoiceGroup protocolType; private TextField inboxServer; private TextField inboxPort; private TextField inboxAuthName; private TextField inboxAuthPass; private TextField IMAP_boxes; private ChoiceGroup SSL; //#ifdef MUJMAIL_SSL private SSLTypeChooser sslTypeChooser; //#endif private ChoiceGroup copyToServer; private TextField copyToSrvSentFolderName; private TextField copyToSrvTrashFolderName; private boolean copyToSrvSentFolderNameVisible = false; private boolean copyToSrvTrashFolderNameVisible = false; public Command back, ok; private MujMail mujMail; private boolean editting = false; /** Marks if loading databases */ private boolean busy; /** Marks if loading of accounts had been finnished */ private boolean accountsLoaded = false; /** Object on which wait fo beeing notify */ private Object notifier = new Object(); /** * Constructor of the class * @param mujMail - main application */ public AccountSettings(MujMail mujMail) { super("Account form"); this.mujMail = mujMail; active = new ChoiceGroup(Lang.get(Lang.AS_ACTIVATION), Choice.MULTIPLE); active.append( Lang.get(Lang.ACTIVE), null); if ( Properties.textFieldMailIncorrect ) { email = new TextField(Lang.get(Lang.AS_EMAIL), "", 50, TextField.ANY); } else { email = new TextField(Lang.get(Lang.AS_EMAIL), "", 50, TextField.EMAILADDR); } protocolType = new ChoiceGroup(Lang.get(Lang.AS_PROTOCOL), Choice.EXCLUSIVE); protocolType.append("POP3", null); protocolType.append("IMAP4", null); protocolType.setSelectedIndex(0, true); inboxServer = new TextField(Lang.get(Lang.AS_SERVER), "", 50, TextField.ANY); inboxPort = new TextField(Lang.get(Lang.AS_PORT), "", 50, TextField.NUMERIC); inboxAuthName = new TextField(Lang.get(Lang.AS_USR_NAME), "", 50, TextField.ANY); inboxAuthPass = new TextField(Lang.get(Lang.AS_PASS), "", 50, TextField.PASSWORD); IMAP_boxes = new TextField(Lang.get(Lang.AS_IMAP_MAILBOXES), "", 50, TextField.ANY); SSL = new ChoiceGroup("SSL", Choice.MULTIPLE); SSL.append(Lang.get(Lang.AS_SSL), null); //#ifdef MUJMAIL_SSL sslTypeChooser = new SSLTypeChooser(this, 4); //#endif copyToServer = new ChoiceGroup(Lang.get(Lang.AS_COPY_TO_SERVER), Choice.MULTIPLE); copyToServer.append( Lang.get(Lang.AS_COPY_TO_SRV_SENT), null); copyToServer.append( Lang.get(Lang.AS_COPY_TO_SRV_TRASH), null); copyToServer.setLabel(Lang.get(Lang.AS_COPY_TO_SERVER)); copyToSrvSentFolderName = new TextField(Lang.get(Lang.AS_COPY_TO_SRV_SENT_MAILBOX), "" ,1000, TextField.ANY); copyToSrvSentFolderName.setLabel(Lang.get(Lang.AS_COPY_TO_SRV_SENT_MAILBOX)); copyToSrvTrashFolderName = new TextField(Lang.get(Lang.AS_COPY_TO_SRV_TRASH_MAILBOX), "", 1000, TextField.ANY); copyToSrvTrashFolderName.setLabel(Lang.get(Lang.AS_COPY_TO_SRV_TRASH_MAILBOX)); back = new Command(Lang.get(Lang.BTN_BACK), Command.BACK, 0); ok = new Command(Lang.get(Lang.BTN_OK), Command.OK, 1); addCommand(ok); addCommand(back); setItemStateListener(this); setCommandListener(mujMail); } /** * Updates current view according settings changes made by user. * <p>Actualize protocol ports, SSL settings, IMAP specific setting (folders, ...) * * @param item Item that was changed */ public void itemStateChanged(Item item) { int portOld = 0; try { portOld = Integer.parseInt(inboxPort.getString()); } catch (Exception e) { System.out.println( "WARN AccountSettings.itemStateChanged(Item) - unable to parse integer from string '" + inboxPort.getString() + "'" ); e.printStackTrace(); } if (item == protocolType) { if (protocolType.getSelectedIndex() == 0) { //pop3 selected // Protocol ports customization if (SSL.isSelected(0) == false) { // imap->pop3 if (portOld == CONST_PORT_IMAP) inboxPort.setString( Integer.toString(CONST_PORT_POP) ); } else { // imaps->pop3s if (portOld == CONST_PORT_IMAPS) inboxPort.setString( Integer.toString(CONST_PORT_POPS) ); } int index = -1; for ( int i = 0; i < size(); i++) if (this.get(i).getLabel().equals(Lang.get(Lang.AS_IMAP_MAILBOXES))) index = i; if (index != -1) delete(index); //delete IMAP_boxes // MailBoxes setting int ctsIndex = -1; // CopyToServer ChoiceGroup index for ( int i = 0; i < size(); i++) if (this.get(i).getLabel().equals(Lang.get(Lang.AS_COPY_TO_SERVER))) ctsIndex = i; if (ctsIndex != -1) delete( ctsIndex); // remove all visible, then adds visible one ... its necessary not to change order of if (copyToSrvSentFolderNameVisible == true) { int index1 = -1; // CopyToServer ChoiceGroup index for ( int i = 0; i < size(); i++) if (this.get(i).getLabel().equals(Lang.get(Lang.AS_COPY_TO_SRV_SENT_MAILBOX))) index1 = i; delete(index1); copyToSrvSentFolderNameVisible = false; } if (copyToSrvTrashFolderNameVisible == true) { int index1 = -1; // CopyToServer ChoiceGroup index for ( int i = 0; i < size(); i++) if (this.get(i).getLabel().equals(Lang.get(Lang.AS_COPY_TO_SRV_TRASH_MAILBOX))) index1 = i; delete(index1); copyToSrvTrashFolderNameVisible = false; } } else { // imap selected // Protocol ports customization if (SSL.isSelected(0) == false) { // pop3->imap if (portOld == CONST_PORT_POP) inboxPort.setString( Integer.toString(CONST_PORT_IMAP) ); } else { // pop3s->imaps if (portOld == CONST_PORT_POPS) inboxPort.setString( Integer.toString(CONST_PORT_IMAPS) ); } int index = -1; for ( int i = 0; i < size(); i++) { if ( this.get(i).getLabel().equals(Lang.get(Lang.AS_PASS)) ) { index = i; } } index +=1; insert(index, IMAP_boxes); index +=1; insert(index, copyToServer); if (copyToServer.isSelected(0)) { index +=1; insert(index, copyToSrvSentFolderName); copyToSrvSentFolderNameVisible = true; } if (copyToServer.isSelected(1)) { index +=1; insert(index, copyToSrvTrashFolderName); copyToSrvTrashFolderNameVisible = true; } } } if (item == SSL) { if (SSL.isSelected(0)) { //#ifdef MUJMAIL_SSL sslTypeChooser.insertToForm(); //#endif // Protocol ports customization if (protocolType.isSelected(0)) { // pop3->pop3s if (portOld == CONST_PORT_POP) inboxPort.setString( Integer.toString(CONST_PORT_POPS) ); } else { // imap->imaps if (portOld == CONST_PORT_IMAP) inboxPort.setString( Integer.toString(CONST_PORT_IMAPS) );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -