Changeset 608


Ignore:
Timestamp:
01/15/10 22:13:25 (2 years ago)
Author:
octorian
Message:

Initial implementation of improved network-interface selection (#146). Contains all the new configuration options and necessary refactoring, but only an initial attempt at actual pre-5.0 connection logic.

Location:
trunk
Files:
3 added
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/LogicMail/res/org/logicprobe/LogicMail/LogicMail.rrc

    r599 r608  
    3131CONFIG_ACCOUNT_SERVER#0="Server:"; 
    3232CONFIG_ACCOUNT_TITLE#0="Account"; 
     33CONFIG_ACCOUNT_TRANSPORT_USE_GLOBAL#0="Use global"; 
    3334CONFIG_ACCOUNT_USEMDSPROXY#0="Use MDS proxy"; 
    3435CONFIG_ACCOUNT_USERNAME#0="Username:"; 
    3536CONFIG_GLOBAL_CONNECTION_DEBUGGING#0="Connection debugging"; 
     37CONFIG_GLOBAL_ENABLE_WIFI#0="Use WiFi if available"; 
    3638CONFIG_GLOBAL_HIDE_DELETED_MESSAGES#0="Hide deleted messages"; 
    3739CONFIG_GLOBAL_HOSTNAME#0="Hostname:"; 
     
    4547CONFIG_GLOBAL_MESSAGE_FORMAT_PLAIN_TEXT#0="Plain Text"; 
    4648CONFIG_GLOBAL_MESSAGE_ORDER#0="Message order:"; 
     49CONFIG_GLOBAL_NETWORK_TRANSPORT#0="Connection method:"; 
    4750CONFIG_GLOBAL_OVERRIDE_HOSTNAME#0="Override hostname"; 
    4851CONFIG_GLOBAL_SECTION_MESSAGE_DISPLAY#0="Message display"; 
     
    5154CONFIG_GLOBAL_SETTINGS#0="Global settings"; 
    5255CONFIG_GLOBAL_TITLE#0="Global"; 
     56CONFIG_GLOBAL_TRANSPORT_AUTO#0="Auto"; 
     57CONFIG_GLOBAL_TRANSPORT_DIRECT_TCP#0="Direct TCP"; 
     58CONFIG_GLOBAL_TRANSPORT_MDS#0="MDS"; 
     59CONFIG_GLOBAL_TRANSPORT_WAP2#0="WAP 2.0"; 
    5360CONFIG_GLOBAL_UNICODE_NORMALIZATION#0="Unicode normalization"; 
    5461CONFIG_GLOBAL_WIFI_MODE#0="WiFi mode:"; 
     
    6976EMAILADDRESSBOOKEDIT_ALERT_NO_ADDRESS#0="The selected contact has no email address!"; 
    7077EMAILADDRESSBOOKEDIT_WHICH_ADDRESS#0="Which address?"; 
     78ERROR_UNABLE_TO_OPEN_CONNECTION#0="Unable to open connection"; 
    7179ERROR_UNKNOWN#0="Unknown error"; 
    7280FILESAVEDIALOG_NAME#0="Name:"; 
  • trunk/LogicMail/res/org/logicprobe/LogicMail/LogicMail.rrh

    r599 r608  
    194194MESSAGE_NO_ACCOUNTS_HAVE_SENDERS#0=195; 
    195195CONFIG_ACCOUNT_IMAP_ONLY_SUBSCRIBED_FOLDERS#0=196; 
     196CONFIG_GLOBAL_NETWORK_TRANSPORT#0=197; 
     197CONFIG_GLOBAL_ENABLE_WIFI#0=198; 
     198CONFIG_GLOBAL_TRANSPORT_AUTO#0=199; 
     199CONFIG_GLOBAL_TRANSPORT_DIRECT_TCP#0=200; 
     200CONFIG_GLOBAL_TRANSPORT_MDS#0=201; 
     201CONFIG_GLOBAL_TRANSPORT_WAP2#0=202; 
     202CONFIG_ACCOUNT_TRANSPORT_USE_GLOBAL#0=203; 
     203ERROR_UNABLE_TO_OPEN_CONNECTION#0=204; 
  • trunk/LogicMail/src/org/logicprobe/LogicMail/conf/ConnectionConfig.java

    r518 r608  
    3535import java.io.DataOutput; 
    3636import java.io.IOException; 
     37 
    3738import org.logicprobe.LogicMail.util.Serializable; 
    3839import org.logicprobe.LogicMail.util.SerializableHashtable; 
     
    5051    private int serverSecurity; 
    5152    private int serverPort; 
    52     private boolean deviceSide; 
     53    private int transportType; 
     54    private boolean enableWiFi; 
     55 
     56    /** Use the transport specified in the global configuration */ 
     57    public static final int TRANSPORT_GLOBAL = 0; 
     58    /** Use the Direct TCP transport */ 
     59    public static final int TRANSPORT_DIRECT_TCP = 10; 
     60    /** Use the MDS transport */ 
     61    public static final int TRANSPORT_MDS = 20; 
     62    /** Use the WAP 2.0 transport */ 
     63    public static final int TRANSPORT_WAP2 = 30; 
     64    /** Automatically select the transport type */ 
     65    public static final int TRANSPORT_AUTO = 9999; 
    5366 
    5467    /** Connection is not encrypted */ 
     
    92105        serverSecurity = SECURITY_NONE; 
    93106        serverPort = 110; 
    94         deviceSide = false; 
     107        transportType = TRANSPORT_GLOBAL; 
     108        enableWiFi = false; 
    95109    } 
    96110 
     
    168182 
    169183    /** 
    170      * Gets whether the connection is device side. 
    171      *  
    172      * @return The device side mode 
    173      */ 
    174     public boolean getDeviceSide() { 
    175         return deviceSide; 
    176     } 
    177      
    178     /** 
    179      * Sets whether the connection is device side. 
    180      *  
    181      * @param deviceSide The new device side mode 
    182      */ 
    183     public void setDeviceSide(boolean deviceSide) { 
    184         this.deviceSide = deviceSide; 
    185     } 
    186  
     184     * Gets the preferred network transport type. 
     185     *  
     186     * @return the preferred network transport type 
     187     */ 
     188    public int getTransportType() { 
     189        return transportType; 
     190    } 
     191     
     192    /** 
     193     * Sets the preferred network transport type. 
     194     *  
     195     * @param transportType the new preferred network transport type 
     196     */ 
     197    public void setTransportType(int transportType) { 
     198        this.transportType = transportType; 
     199    } 
     200     
     201    /** 
     202     * Gets whether to use WiFi if available. 
     203     *  
     204     * @return whether to use WiFi if available 
     205     */ 
     206    public boolean getEnableWiFi() { 
     207        return enableWiFi; 
     208    } 
     209     
     210    /** 
     211     * Sets whether to use WiFi if available. 
     212     *  
     213     * @param enableWiFi whether to use WiFi if available 
     214     */ 
     215    public void setEnableWiFi(boolean enableWiFi) { 
     216        this.enableWiFi = enableWiFi; 
     217    } 
     218     
    187219    /* (non-Javadoc) 
    188220     * @see org.logicprobe.LogicMail.util.Serializable#serialize(java.io.DataOutput) 
    189221     */ 
    190     final public void serialize(DataOutput output) throws IOException { 
     222    public final void serialize(DataOutput output) throws IOException { 
    191223        output.writeLong(uniqueId); 
    192224        SerializableHashtable table = new SerializableHashtable(); 
     
    198230     * @see org.logicprobe.LogicMail.util.Serializable#deserialize(java.io.DataInput) 
    199231     */ 
    200     final public void deserialize(DataInput input) throws IOException { 
     232    public final void deserialize(DataInput input) throws IOException { 
    201233        setDefaults(); 
    202234        uniqueId = input.readLong(); 
     
    218250        table.put("account_serverSecurity", new Integer(serverSecurity)); 
    219251        table.put("account_serverPort", new Integer(serverPort)); 
    220         table.put("account_deviceSide", new Boolean(deviceSide)); 
     252        table.put("account_transportType", new Integer(transportType)); 
     253        table.put("account_enableWiFi", new Boolean(enableWiFi)); 
    221254    } 
    222255     
     
    247280            serverPort = ((Integer)value).intValue(); 
    248281        } 
    249         value = table.get("account_deviceSide"); 
     282        value = table.get("account_transportType"); 
     283        if(value instanceof Integer) { 
     284            transportType = ((Integer)value).intValue(); 
     285        } 
     286        value = table.get("account_enableWiFi"); 
    250287        if(value instanceof Boolean) { 
    251             deviceSide = ((Boolean)value).booleanValue(); 
     288            enableWiFi = ((Boolean)value).booleanValue(); 
    252289        } 
    253290    } 
  • trunk/LogicMail/src/org/logicprobe/LogicMail/conf/GlobalConfig.java

    r597 r608  
    4949    private long uniqueId; 
    5050 
    51     /** WiFi support is disabled, best for non-WiFi devices */ 
    52     final public static int WIFI_DISABLED = 0; 
    53  
    54     /** Prompt for WiFi use whenever establishing a connection */ 
    55     final public static int WIFI_PROMPT = 1; 
    56  
    57     /** Always use WiFi */ 
    58     final public static int WIFI_ALWAYS = 2; 
    59  
    6051    /** Prefer plain text display for messages */ 
    61     final public static int MESSAGE_DISPLAY_PLAIN_TEXT = 0; 
    62  
     52    public static final int MESSAGE_DISPLAY_PLAIN_TEXT = 0; 
    6353    /** Prefer HTML display for messages */ 
    64     final public static int MESSAGE_DISPLAY_HTML = 1; 
     54    public static final int MESSAGE_DISPLAY_HTML = 1; 
    6555 
    6656    /** language code to use for the UI, or null for system default */ 
    6757    private String languageCode; 
    68  
    6958    /** true to enable Unicode normalization */ 
    7059    private boolean unicodeNormalization; 
    71  
    7260    /** Preferred message display format */ 
    7361    private int messageDisplayFormat; 
    74  
    7562    /** Number of message headers to retrieve */ 
    7663    private int retMsgCount; 
    77  
    7864    /** True for ascending, false for descending */ 
    7965    private boolean dispOrder; 
    80  
    8166    /** Root URL for local file storage */ 
    8267    private String localDataLocation = ""; 
    83  
    84     /** Mode for WiFi support */ 
    85     private int wifiMode; 
    86  
     68    /** Preferred network transport type */ 
     69    private int transportType; 
     70    /** Whether WiFi should be used if available */ 
     71    private boolean enableWiFi; 
    8772    /** Connection debugging */ 
    8873    private boolean connDebug; 
    89  
    9074    /** Hide deleted messages */ 
    9175    private boolean hideDeletedMsg; 
    92  
    9376    /** Local host name override */ 
    9477    private String localHostname; 
    9578 
    9679    public static String FILE_URL_PREFIX = "file:///"; 
    97      
     80 
    9881    /** 
    9982     * Instantiates a new global configuration. 
     
    126109        this.retMsgCount = 30; 
    127110        this.dispOrder = false; 
    128         this.wifiMode = GlobalConfig.WIFI_DISABLED; 
     111        this.transportType = ConnectionConfig.TRANSPORT_AUTO; 
     112        this.enableWiFi = true; 
    129113        this.hideDeletedMsg = true; 
    130114        this.localHostname = ""; 
     
    245229        return localDataLocation; 
    246230    } 
    247  
    248     /** 
    249      * Gets the WiFi connection mode. 
    250      *  
    251      * @return The WiFi connection mode 
    252      */ 
    253     public int getWifiMode() { 
    254         return wifiMode; 
    255     } 
    256  
    257     /** 
    258      * Sets the WiFi connection mode. 
    259      *  
    260      * @param wifiMode The WiFi connection mode 
    261      */ 
    262     public void setWifiMode(int wifiMode) { 
    263         this.wifiMode = wifiMode; 
     231     
     232    /** 
     233     * Gets the preferred network transport type. 
     234     *  
     235     * @return the preferred network transport type 
     236     */ 
     237    public int getTransportType() { 
     238        return transportType; 
     239    } 
     240     
     241    /** 
     242     * Sets the preferred network transport type. 
     243     *  
     244     * @param transportType the new preferred network transport type 
     245     */ 
     246    public void setTransportType(int transportType) { 
     247        this.transportType = transportType; 
     248    } 
     249     
     250    /** 
     251     * Gets whether to use WiFi if available. 
     252     *  
     253     * @return whether to use WiFi if available 
     254     */ 
     255    public boolean getEnableWiFi() { 
     256        return enableWiFi; 
     257    } 
     258     
     259    /** 
     260     * Sets whether to use WiFi if available. 
     261     *  
     262     * @param enableWiFi whether to use WiFi if available 
     263     */ 
     264    public void setEnableWiFi(boolean enableWiFi) { 
     265        this.enableWiFi = enableWiFi; 
    264266    } 
    265267 
     
    332334        table.put("global_dispOrder", new Boolean(dispOrder)); 
    333335        table.put("global_localDataLocation", localDataLocation); 
    334         table.put("global_wifiMode", new Integer(wifiMode)); 
     336        table.put("global_transportType", new Integer(transportType)); 
     337        table.put("global_enableWiFi", new Boolean(enableWiFi)); 
    335338        table.put("global_connDebug", new Boolean(connDebug)); 
    336339        table.put("global_hideDeletedMsg", new Boolean(hideDeletedMsg)); 
     
    353356 
    354357        value = table.get("global_languageCode"); 
    355         if(value != null && value instanceof String) { 
     358        if(value instanceof String) { 
    356359            languageCode = (String)value; 
    357360        } 
    358  
    359361        value = table.get("global_unicodeNormalization"); 
    360         if(value != null && value instanceof Boolean) { 
     362        if(value instanceof Boolean) { 
    361363            unicodeNormalization = ((Boolean)value).booleanValue(); 
    362364        } 
    363  
    364365        value = table.get("global_messageDisplayFormat"); 
    365         if ((value != null) && value instanceof Integer) { 
     366        if (value instanceof Integer) { 
    366367            messageDisplayFormat = ((Integer) value).intValue(); 
    367368        } 
    368  
    369369        value = table.get("global_retMsgCount"); 
    370         if ((value != null) && value instanceof Integer) { 
     370        if (value instanceof Integer) { 
    371371            retMsgCount = ((Integer) value).intValue(); 
    372372        } 
    373  
    374373        value = table.get("global_dispOrder"); 
    375         if ((value != null) && value instanceof Boolean) { 
     374        if (value instanceof Boolean) { 
    376375            dispOrder = ((Boolean) value).booleanValue(); 
    377376        } 
    378  
    379377        value = table.get("global_localDataLocation"); 
    380         if ((value != null) && value instanceof String) { 
     378        if (value instanceof String) { 
    381379            setLocalDataLocation((String)value); 
    382380        } 
     
    387385            } 
    388386        } 
    389  
    390         value = table.get("global_wifiMode"); 
    391         if ((value != null) && value instanceof Integer) { 
    392             wifiMode = ((Integer) value).intValue(); 
    393             if ((wifiMode < 0) || (wifiMode > 2)) { 
    394                 wifiMode = GlobalConfig.WIFI_DISABLED; 
    395             } 
    396         } 
    397  
     387        value = table.get("account_transportType"); 
     388        if(value instanceof Integer) { 
     389            transportType = ((Integer)value).intValue(); 
     390        } 
     391        value = table.get("account_enableWiFi"); 
     392        if(value instanceof Boolean) { 
     393            enableWiFi = ((Boolean)value).booleanValue(); 
     394        } 
    398395        value = table.get("global_connDebug"); 
    399         if ((value != null) && value instanceof Boolean) { 
     396        if (value instanceof Boolean) { 
    400397            connDebug = ((Boolean) value).booleanValue(); 
    401398        } 
    402  
    403399        value = table.get("global_hideDeletedMsg"); 
    404         if ((value != null) && value instanceof Boolean) { 
     400        if (value instanceof Boolean) { 
    405401            hideDeletedMsg = ((Boolean) value).booleanValue(); 
    406402        } 
    407  
    408403        value = table.get("global_localHostname"); 
    409         if ((value != null) && value instanceof String) { 
     404        if (value instanceof String) { 
    410405            localHostname = (String) value; 
    411406        } 
     
    418413        return uniqueId; 
    419414    } 
    420      
     415 
    421416    /** 
    422417     * Checks provided filesystem root to make sure it exists, 
     
    437432                fsRoot = fsRoot.substring(p + 1, q + 1); 
    438433            } 
    439              
     434 
    440435            // Add the prefix 
    441436            url = FILE_URL_PREFIX + fsRoot; 
    442              
     437 
    443438            // Append the necessary elements, creating directories as necessary 
    444439            if(url.indexOf("Card/") != -1) { 
     
    447442                    if(!conn.exists()) { conn.mkdir(); } 
    448443                    url = conn.getURL(); conn.close(); 
    449                      
     444 
    450445                    conn = (FileConnection)Connector.open(url + "logicmail/"); 
    451446                    if(!conn.exists()) { conn.mkdir(); } 
     
    460455                    if(!conn.exists()) { conn.mkdir(); } 
    461456                    url = conn.getURL(); conn.close(); 
    462                      
     457 
    463458                    conn = (FileConnection)Connector.open(url + "user/"); 
    464459                    if(!conn.exists()) { conn.mkdir(); } 
    465460                    url = conn.getURL(); conn.close(); 
    466                      
     461 
    467462                    conn = (FileConnection)Connector.open(url + "logicmail/"); 
    468463                    if(!conn.exists()) { conn.mkdir(); } 
  • trunk/LogicMail/src/org/logicprobe/LogicMail/mail/imap/ImapClient.java

    r599 r608  
    6262import org.logicprobe.LogicMail.message.UnsupportedPart; 
    6363import org.logicprobe.LogicMail.util.Connection; 
     64import org.logicprobe.LogicMail.util.UtilFactory; 
    6465import org.logicprobe.LogicMail.util.DataStore; 
    6566import org.logicprobe.LogicMail.util.DataStoreFactory; 
     
    125126    public ImapClient(GlobalConfig globalConfig, ImapConfig accountConfig) { 
    126127        this.accountConfig = accountConfig; 
    127         connection = new Connection( 
    128                 accountConfig.getServerName(), 
    129                 accountConfig.getServerPort(), 
    130                 accountConfig.getServerSecurity() == ConnectionConfig.SECURITY_SSL, 
    131                 accountConfig.getDeviceSide()); 
     128        connection = UtilFactory.getInstance().createConnection(accountConfig); 
    132129        imapProtocol = new ImapProtocol(connection); 
    133130        username = accountConfig.getServerUser(); 
     
    152149            if(!isConnected()) { 
    153150                // Rebuild the connection to include new settings 
    154                 connection = new Connection( 
    155                         accountConfig.getServerName(), 
    156                         accountConfig.getServerPort(), 
    157                         accountConfig.getServerSecurity() == ConnectionConfig.SECURITY_SSL, 
    158                         accountConfig.getDeviceSide()); 
     151                connection = UtilFactory.getInstance().createConnection(accountConfig); 
    159152                imapProtocol = new ImapProtocol(connection); 
    160153            } 
     
    257250        if(configChanged) { 
    258251            // Rebuild the connection to include new settings 
    259             connection = new Connection( 
    260                     accountConfig.getServerName(), 
    261                     accountConfig.getServerPort(), 
    262                     accountConfig.getServerSecurity() == ConnectionConfig.SECURITY_SSL, 
    263                     accountConfig.getDeviceSide()); 
     252            connection = UtilFactory.getInstance().createConnection(accountConfig); 
    264253            imapProtocol = new ImapProtocol(connection); 
    265254            configChanged = false; 
  • trunk/LogicMail/src/org/logicprobe/LogicMail/mail/pop/PopClient.java

    r582 r608  
    5858import org.logicprobe.LogicMail.message.MimeMessagePart; 
    5959import org.logicprobe.LogicMail.util.Connection; 
     60import org.logicprobe.LogicMail.util.UtilFactory; 
    6061import org.logicprobe.LogicMail.util.MailMessageParser; 
    6162import org.logicprobe.LogicMail.util.StringParser; 
     
    9293        this.globalConfig = globalConfig; 
    9394        this.accountConfig = accountConfig; 
    94         connection = new Connection( 
    95                 accountConfig.getServerName(), 
    96                 accountConfig.getServerPort(), 
    97                 accountConfig.getServerSecurity() == ConnectionConfig.SECURITY_SSL, 
    98                 accountConfig.getDeviceSide()); 
     95        connection = UtilFactory.getInstance().createConnection(accountConfig); 
    9996        popProtocol = new PopProtocol(connection); 
    10097        username = accountConfig.getServerUser(); 
     
    123120                if(!isConnected()) { 
    124121                        // Rebuild the connection to include new settings 
    125                     connection = new Connection( 
    126                             accountConfig.getServerName(), 
    127                             accountConfig.getServerPort(), 
    128                             accountConfig.getServerSecurity() == ConnectionConfig.SECURITY_SSL, 
    129                             accountConfig.getDeviceSide()); 
     122                    connection = UtilFactory.getInstance().createConnection(accountConfig); 
    130123                    popProtocol = new PopProtocol(connection); 
    131124                } 
     
    206199        if(configChanged) { 
    207200                // Rebuild the connection to include new settings 
    208             connection = new Connection( 
    209                     accountConfig.getServerName(), 
    210                     accountConfig.getServerPort(), 
    211                     accountConfig.getServerSecurity() == ConnectionConfig.SECURITY_SSL, 
    212                     accountConfig.getDeviceSide()); 
     201            connection = UtilFactory.getInstance().createConnection(accountConfig); 
    213202            popProtocol = new PopProtocol(connection); 
    214203            configChanged = false; 
  • trunk/LogicMail/src/org/logicprobe/LogicMail/mail/smtp/SmtpClient.java

    r481 r608  
    4343import org.logicprobe.LogicMail.message.MessageMimeConverter; 
    4444import org.logicprobe.LogicMail.util.Connection; 
     45import org.logicprobe.LogicMail.util.UtilFactory; 
    4546import org.logicprobe.LogicMail.util.MailMessageParser; 
    4647 
     
    7980        this.globalConfig = globalConfig; 
    8081        this.outgoingConfig = outgoingConfig; 
    81         connection = new Connection( 
    82                         outgoingConfig.getServerName(), 
    83                 outgoingConfig.getServerPort(), 
    84                 outgoingConfig.getServerSecurity() == ConnectionConfig.SECURITY_SSL, 
    85                 outgoingConfig.getDeviceSide()); 
     82        connection = UtilFactory.getInstance().createConnection(outgoingConfig); 
    8683        smtpProtocol = new SmtpProtocol(connection); 
    8784 
     
    107104            if (!isConnected()) { 
    108105                // Rebuild the connection to include new settings 
    109                 connection = new Connection( 
    110                                 outgoingConfig.getServerName(), 
    111                         outgoingConfig.getServerPort(), 
    112                         outgoingConfig.getServerSecurity() == ConnectionConfig.SECURITY_SSL, 
    113                         outgoingConfig.getDeviceSide()); 
     106                connection = UtilFactory.getInstance().createConnection(outgoingConfig); 
    114107                smtpProtocol = new SmtpProtocol(connection); 
    115108            } else { 
     
    179172        if (configChanged) { 
    180173            // Rebuild the connection to include new settings 
    181             connection = new Connection( 
    182                         outgoingConfig.getServerName(), 
    183                     outgoingConfig.getServerPort(), 
    184                     outgoingConfig.getServerSecurity() == ConnectionConfig.SECURITY_SSL, 
    185                     outgoingConfig.getDeviceSide()); 
     174            connection = UtilFactory.getInstance().createConnection(outgoingConfig); 
    186175            smtpProtocol = new SmtpProtocol(connection); 
    187176            configChanged = false; 
  • trunk/LogicMail/src/org/logicprobe/LogicMail/ui/AccountConfigScreen.java

    r601 r608  
    7777    private BasicEditField serverUserField; 
    7878    private PasswordEditField serverPassField; 
    79     private CheckboxField useMdsField; 
    8079    private ObjectChoiceField identityField; 
    8180    private ObjectChoiceField outgoingServerField; 
     
    8685    private LabelField draftFolderChoiceLabel; 
    8786    private LabelField draftFolderChoiceButtonLabel; 
     87 
     88    // Advanced settings fields (both) 
     89    private ObjectChoiceField networkTransportChoiceField; 
     90    private CheckboxField enableWiFiCheckboxField; 
    8891 
    8992    // Advanced settings fields (IMAP) 
     
    155158            }}; 
    156159 
    157             initFields(); 
    158  
    159             IdentityConfig selectedIdentityConfig = this.accountConfig.getIdentityConfig(); 
    160             if(selectedIdentityConfig != null) { 
    161                 identityField.setSelectedIndex(selectedIdentityConfig); 
    162             } 
    163  
    164             OutgoingConfig selectedOutgoingConfig = this.accountConfig.getOutgoingConfig(); 
    165             if(selectedOutgoingConfig != null) { 
    166                 outgoingServerField.setSelectedIndex(selectedOutgoingConfig); 
    167             } 
     160        initFields(); 
     161 
     162        IdentityConfig selectedIdentityConfig = this.accountConfig.getIdentityConfig(); 
     163        if(selectedIdentityConfig != null) { 
     164            identityField.setSelectedIndex(selectedIdentityConfig); 
     165        } 
     166 
     167        OutgoingConfig selectedOutgoingConfig = this.accountConfig.getOutgoingConfig(); 
     168        if(selectedOutgoingConfig != null) { 
     169            outgoingServerField.setSelectedIndex(selectedOutgoingConfig); 
     170        } 
    168171    } 
    169172 
     
    254257                accountConfig.getServerPass(), 
    255258                256, TextField.NO_NEWLINE); 
    256         useMdsField = new CheckboxField( 
    257                 resources.getString(LogicMailResource.CONFIG_ACCOUNT_USEMDSPROXY), 
    258                 !accountConfig.getDeviceSide()); 
    259259        identityField = new ObjectChoiceField( 
    260260                resources.getString(LogicMailResource.CONFIG_ACCOUNT_IDENTITY) + ' ', 
     
    270270        manager.add(serverUserField); 
    271271        manager.add(serverPassField); 
    272         manager.add(useMdsField); 
    273272        manager.add(new LabelField()); 
    274273        manager.add(identityField); 
    275274        manager.add(outgoingServerField); 
    276  
     275        manager.add(new LabelField()); 
     276         
    277277        return manager; 
    278278    } 
     
    303303    private Manager initFieldsAdvanced() { 
    304304        Manager manager = new VerticalFieldManager(); 
     305         
     306        String[] transportChoices = { 
     307                resources.getString(LogicMailResource.CONFIG_ACCOUNT_TRANSPORT_USE_GLOBAL), 
     308                resources.getString(LogicMailResource.CONFIG_GLOBAL_TRANSPORT_AUTO), 
     309                resources.getString(LogicMailResource.CONFIG_GLOBAL_TRANSPORT_DIRECT_TCP), 
     310                resources.getString(LogicMailResource.CONFIG_GLOBAL_TRANSPORT_MDS), 
     311                resources.getString(LogicMailResource.CONFIG_GLOBAL_TRANSPORT_WAP2) 
     312        }; 
     313        networkTransportChoiceField = new ObjectChoiceField( 
     314                resources.getString(LogicMailResource.CONFIG_GLOBAL_NETWORK_TRANSPORT), 
     315                transportChoices, 
     316                getTransportChoice(accountConfig.getTransportType())); 
     317        networkTransportChoiceField.setChangeListener(fieldChangeListener); 
     318         
     319        enableWiFiCheckboxField = new CheckboxField( 
     320                resources.getString(LogicMailResource.CONFIG_GLOBAL_ENABLE_WIFI), 
     321                accountConfig.getEnableWiFi()); 
     322        if(networkTransportChoiceField.getSelectedIndex() == 0) { 
     323            enableWiFiCheckboxField.setChecked(false); 
     324            enableWiFiCheckboxField.setEditable(false); 
     325        } 
     326         
     327        manager.add(networkTransportChoiceField); 
     328        manager.add(enableWiFiCheckboxField); 
     329         
    305330        if(accountConfig instanceof ImapConfig) { 
    306331            ImapConfig imapConfig = (ImapConfig)accountConfig; 
     
    368393            } 
    369394        } 
     395        else if(field == networkTransportChoiceField) { 
     396            if(networkTransportChoiceField.getSelectedIndex() == 0) { 
     397                enableWiFiCheckboxField.setChecked(false); 
     398                enableWiFiCheckboxField.setEditable(false); 
     399            } 
     400            else { 
     401                enableWiFiCheckboxField.setChecked(true); 
     402                enableWiFiCheckboxField.setEditable(true); 
     403            } 
     404        } 
    370405    } 
    371406 
     
    457492    } 
    458493 
     494    private static int getTransportChoice(int transportSetting) { 
     495        int result; 
     496        switch(transportSetting) { 
     497        case ConnectionConfig.TRANSPORT_GLOBAL: 
     498            result = 0; 
     499            break; 
     500        case ConnectionConfig.TRANSPORT_AUTO: 
     501            result = 1; 
     502            break; 
     503        case ConnectionConfig.TRANSPORT_DIRECT_TCP: 
     504            result = 2; 
     505            break; 
     506        case ConnectionConfig.TRANSPORT_MDS: 
     507            result = 3; 
     508            break; 
     509        case ConnectionConfig.TRANSPORT_WAP2: 
     510            result = 4; 
     511            break; 
     512        default: 
     513            result = 0; 
     514            break; 
     515        } 
     516        return result; 
     517    } 
     518     
     519    private static int getTransportSetting(int transportChoice) { 
     520        int result; 
     521        switch(transportChoice) { 
     522        case 0: 
     523            result = ConnectionConfig.TRANSPORT_GLOBAL; 
     524            break; 
     525        case 1: 
     526            result = ConnectionConfig.TRANSPORT_AUTO; 
     527            break; 
     528        case 2: 
     529            result = ConnectionConfig.TRANSPORT_DIRECT_TCP; 
     530            break; 
     531        case 3: 
     532            result = ConnectionConfig.TRANSPORT_MDS; 
     533            break; 
     534        case 4: 
     535            result = ConnectionConfig.TRANSPORT_WAP2; 
     536            break; 
     537        default: 
     538            result = ConnectionConfig.TRANSPORT_GLOBAL; 
     539            break; 
     540        } 
     541        return result; 
     542    } 
     543     
    459544    /** 
    460545     * Determines if this screen is dirty. 
     
    510595        this.accountConfig.setServerUser(serverUserField.getText()); 
    511596        this.accountConfig.setServerPass(serverPassField.getText()); 
    512         this.accountConfig.setDeviceSide(!useMdsField.getChecked()); 
    513597 
    514598        IdentityConfig selectedIdentityConfig = (IdentityConfig)identityField.getChoice(identityField.getSelectedIndex()); 
     
    535619        this.accountConfig.setDraftMailbox(selectedDraftFolder); 
    536620 
     621        this.accountConfig.setTransportType(getTransportSetting(networkTransportChoiceField.getSelectedIndex())); 
     622        this.accountConfig.setEnableWiFi(enableWiFiCheckboxField.getChecked()); 
     623         
    537624        if(accountConfig instanceof ImapConfig) { 
    538625            ImapConfig imapConfig = (ImapConfig)accountConfig; 
  • trunk/LogicMail/src/org/logicprobe/LogicMail/ui/AccountConfigWizard.java

    r606 r608  
    1717import net.rim.device.api.ui.component.BasicEditField; 
    1818import net.rim.device.api.ui.component.PasswordEditField; 
    19 import net.rim.device.api.ui.component.CheckboxField; 
    2019import net.rim.device.api.ui.component.ObjectChoiceField; 
    2120import net.rim.device.api.ui.component.LabelField; 
     
    7675                }}; 
    7776 
    78                 identityChoiceField = new ObjectChoiceField( 
    79                         resources.getString(LogicMailResource.WIZARD_SCREEN_NEW_ACCOUNT_SELECT_IDENTITY), 
    80                         identityChoices, 0); 
    81                 identityChoiceField.setChangeListener(fieldChangeListener); 
    82  
    83                 identityNameEditField = new EditField(resources.getString(LogicMailResource.WIZARD_SCREEN_NEW_ACCOUNT_IDENTITY) + ' ', ""); 
    84                 identityNameEditField.setChangeListener(fieldChangeListener); 
    85  
    86                 nameEditField = new EditField(resources.getString(LogicMailResource.WIZARD_SCREEN_NEW_ACCOUNT_YOUR_NAME) + ' ', ""); 
    87                 nameEditField.setChangeListener(fieldChangeListener); 
    88  
    89                 emailAddressEditField = new EmailAddressEditField(resources.getString(LogicMailResource.WIZARD_SCREEN_NEW_ACCOUNT_EMAIL_ADDRESS) + ' ', ""); 
    90                 emailAddressEditField.setChangeListener(fieldChangeListener); 
    91  
    92                 commentsField = new RichTextField(resources.getString(LogicMailResource.WIZARD_SCREEN_NEW_ACCOUNT_COMMENTS)); 
    93                 commentsField.setFont(this.getFont().derive(Font.ITALIC)); 
    94  
    95                 add(identityChoiceField); 
    96                 add(identityNameEditField); 
    97                 add(nameEditField); 
    98                 add(emailAddressEditField); 
    99                 add(new LabelField()); 
    100                 add(commentsField); 
    101  
    102                 populateIdentityItems(); 
    103                 validateData(); 
     77            identityChoiceField = new ObjectChoiceField( 
     78                    resources.getString(LogicMailResource.WIZARD_SCREEN_NEW_ACCOUNT_SELECT_IDENTITY), 
     79                    identityChoices, 0); 
     80            identityChoiceField.setChangeListener(fieldChangeListener); 
     81 
     82            identityNameEditField = new EditField(resources.getString(LogicMailResource.WIZARD_SCREEN_NEW_ACCOUNT_IDENTITY) + ' ', ""); 
     83            identityNameEditField.setChangeListener(fieldChangeListener); 
     84 
     85            nameEditField = new EditField(resources.getString(LogicMailResource.WIZARD_SCREEN_NEW_ACCOUNT_YOUR_NAME) + ' ', ""); 
     86            nameEditField.setChangeListener(fieldChangeListener); 
     87 
     88            emailAddressEditField = new EmailAddressEditField(resources.getString(LogicMailResource.WIZARD_SCREEN_NEW_ACCOUNT_EMAIL_ADDRESS) + ' ', ""); 
     89            emailAddressEditField.setChangeListener(fieldChangeListener); 
     90 
     91            commentsField = new RichTextField(resources.getString(LogicMailResource.WIZARD_SCREEN_NEW_ACCOUNT_COMMENTS)); 
     92            commentsField.setFont(this.getFont().derive(Font.ITALIC)); 
     93 
     94            add(identityChoiceField); 
     95            add(identityNameEditField); 
     96            add(nameEditField); 
     97            add(emailAddressEditField); 
     98            add(new LabelField()); 
     99            add(commentsField); 
     100 
     101            populateIdentityItems(); 
     102            validateData(); 
    104103        } 
    105104 
     
    235234        private ObjectChoiceField securityChoiceField; 
    236235        private BasicEditField portEditField; 
    237         private CheckboxField useMdsCheckboxField; 
    238236 
    239237        protected void initFields() { 
     
    243241                }}; 
    244242 
    245                 descriptionLabelField = new LabelField(resources.getString(LogicMailResource.WIZARD_SCREEN_MAIL_SERVER_QUESTION)); 
    246  
    247                 nameEditField = new HostnameEditField(resources.getString(LogicMailResource.CONFIG_ACCOUNT_SERVER) + ' ', ""); 
    248                 nameEditField.setChangeListener(fieldChangeListener); 
    249  
    250                 securityChoiceField = new ObjectChoiceField( 
    251                         resources.getString(LogicMailResource.CONFIG_ACCOUNT_SECURITY), 
    252                         new Object[] { 
    253                             resources.getString(LogicMailResource.CONFIG_ACCOUNT_SECURITY_NEVER), 
    254                             resources.getString(LogicMailResource.CONFIG_ACCOUNT_SECURITY_TLS_IF_AVAILABLE), 
    255                             resources.getString(LogicMailResource.CONFIG_ACCOUNT_SECURITY_TLS), 
    256                             resources.getString(LogicMailResource.CONFIG_ACCOUNT_SECURITY_SSL)}, 
    257                             ConnectionConfig.SECURITY_NONE); 
    258                 securityChoiceField.setChangeListener(fieldChangeListener); 
    259  
    260                 portEditField = new BasicEditField(resources.getString(LogicMailResource.CONFIG_ACCOUNT_PORT) + ' ', Integer.toString(143)); 
    261                 portEditField.setFilter(TextFilter.get(TextFilter.NUMERIC)); 
    262                 portEditField.setChangeListener(fieldChangeListener); 
    263  
    264                 useMdsCheckboxField = new CheckboxField(resources.getString(LogicMailResource.CONFIG_ACCOUNT_USEMDSPROXY), true); 
    265  
    266                 add(descriptionLabelField); 
    267                 add(nameEditField); 
    268                 add(securityChoiceField); 
    269                 add(portEditField); 
    270                 add(useMdsCheckboxField); 
     243            descriptionLabelField = new LabelField(resources.getString(LogicMailResource.WIZARD_SCREEN_MAIL_SERVER_QUESTION)); 
     244 
     245            nameEditField = new HostnameEditField(resources.getString(LogicMailResource.CONFIG_ACCOUNT_SERVER) + ' ', ""); 
     246            nameEditField.setChangeListener(fieldChangeListener); 
     247 
     248            securityChoiceField = new ObjectChoiceField( 
     249                    resources.getString(LogicMailResource.CONFIG_ACCOUNT_SECURITY), 
     250                    new Object[] { 
     251                        resources.getString(LogicMailResource.CONFIG_ACCOUNT_SECURITY_NEVER), 
     252                        resources.getString(LogicMailResource.CONFIG_ACCOUNT_SECURITY_TLS_IF_AVAILABLE), 
     253                        resources.getString(LogicMailResource.CONFIG_ACCOUNT_SECURITY_TLS), 
     254                        resources.getString(LogicMailResource.CONFIG_ACCOUNT_SECURITY_SSL)}, 
     255                        ConnectionConfig.SECURITY_NONE); 
     256            securityChoiceField.setChangeListener(fieldChangeListener); 
     257 
     258            portEditField = new BasicEditField(resources.getString(LogicMailResource.CONFIG_ACCOUNT_PORT) + ' ', Integer.toString(143)); 
     259            portEditField.setFilter(TextFilter.get(TextFilter.NUMERIC)); 
     260            portEditField.setChangeListener(fieldChangeListener); 
     261 
     262            add(descriptionLabelField); 
     263            add(nameEditField); 
     264            add(securityChoiceField); 
     265            add(portEditField); 
    271266        } 
    272267 
     
    302297            accountConfig.setServerSecurity(securityChoiceField.getSelectedIndex()); 
    303298            accountConfig.setServerPort(Integer.parseInt(portEditField.getText())); 
    304             accountConfig.setDeviceSide(!useMdsCheckboxField.getChecked()); 
     299            accountConfig.setTransportType(ConnectionConfig.TRANSPORT_GLOBAL); 
    305300        } 
    306301    }; 
     
    342337        private ObjectChoiceField securityChoiceField; 
    343338        private BasicEditField portEditField; 
    344         private CheckboxField useMdsCheckboxField; 
    345339 
    346340        protected void initFields() { 
     
    359353                }}; 
    360354 
    361                 outgoingChoiceField = new ObjectChoiceField( 
    362                         resources.getString(LogicMailResource.WIZARD_SCREEN_OUTGOING_QUESTION), 
    363                         outgoingChoices, 0); 
    364                 outgoingChoiceField.setChangeListener(fieldChangeListener); 
    365  
    366                 nameEditField = new HostnameEditField(resources.getString(LogicMailResource.CONFIG_ACCOUNT_SERVER) + ' ', ""); 
    367                 nameEditField.setChangeListener(fieldChangeListener); 
    368  
    369                 securityChoiceField = new ObjectChoiceField( 
    370                         resources.getString(LogicMailResource.CONFIG_ACCOUNT_SECURITY), 
    371                         new Object[] { 
    372                             resources.getString(LogicMailResource.CONFIG_ACCOUNT_SECURITY_NEVER), 
    373                             resources.getString(LogicMailResource.CONFIG_ACCOUNT_SECURITY_TLS_IF_AVAILABLE), 
    374                             resources.getString(LogicMailResource.CONFIG_ACCOUNT_SECURITY_TLS), 
    375                             resources.getString(LogicMailResource.CONFIG_ACCOUNT_SECURITY_SSL)}, 
    376                             ConnectionConfig.SECURITY_NONE); 
    377                 securityChoiceField.setChangeListener(fieldChangeListener); 
    378  
    379                 portEditField = new BasicEditField(resources.getString(LogicMailResource.CONFIG_ACCOUNT_PORT) + ' ', Integer.toString(25)); 
    380                 portEditField.setFilter(TextFilter.get(TextFilter.NUMERIC)); 
    381                 portEditField.setChangeListener(fieldChangeListener); 
    382  
    383                 useMdsCheckboxField = new CheckboxField(resources.getString(LogicMailResource.CONFIG_ACCOUNT_USEMDSPROXY), true); 
    384  
    385                 add(outgoingChoiceField); 
    386                 add(nameEditField); 
    387                 add(securityChoiceField); 
    388                 add(portEditField); 
    389                 add(useMdsCheckboxField); 
    390  
    391                 populateOutgoingItems(); 
    392                 validateData(); 
     355            outgoingChoiceField = new ObjectChoiceField( 
     356                    resources.getString(LogicMailResource.WIZARD_SCREEN_OUTGOING_QUESTION), 
     357                    outgoingChoices, 0); 
     358            outgoingChoiceField.setChangeListener(fieldChangeListener); 
     359 
     360            nameEditField = new HostnameEditField(resources.getString(LogicMailResource.CONFIG_ACCOUNT_SERVER) + ' ', ""); 
     361            nameEditField.setChangeListener(fieldChangeListener); 
     362 
     363            securityChoiceField = new ObjectChoiceField( 
     364                    resources.getString(LogicMailResource.CONFIG_ACCOUNT_SECURITY), 
     365                    new Object[] { 
     366                        resources.getString(LogicMailResource.CONFIG_ACCOUNT_SECURITY_NEVER), 
     367                        resources.getString(LogicMailResource.CONFIG_ACCOUNT_SECURITY_TLS_IF_AVAILABLE), 
     368                        resources.getString(LogicMailResource.CONFIG_ACCOUNT_SECURITY_TLS), 
     369                        resources.getString(LogicMailResource.CONFIG_ACCOUNT_SECURITY_SSL)}, 
     370                        ConnectionConfig.SECURITY_NONE); 
     371            securityChoiceField.setChangeListener(fieldChangeListener); 
     372 
     373            portEditField = new BasicEditField(resources.getString(LogicMailResource.CONFIG_ACCOUNT_PORT) + ' ', Integer.toString(25)); 
     374            portEditField.setFilter(TextFilter.get(TextFilter.NUMERIC)); 
     375            portEditField.setChangeListener(fieldChangeListener); 
     376 
     377            add(outgoingChoiceField); 
     378            add(nameEditField); 
     379            add(securityChoiceField); 
     380            add(portEditField); 
     381 
     382            populateOutgoingItems(); 
     383            validateData(); 
    393384        } 
    394385 
     
    424415                securityChoiceField.setSelectedIndex(outgoingConfig.getServerSecurity()); 
    425416                portEditField.setText(Integer.toString(outgoingConfig.getServerPort())); 
    426                 useMdsCheckboxField.setChecked(!outgoingConfig.getDeviceSide()); 
    427417 
    428418                nameEditField.setEditable(false); 
    429419                securityChoiceField.setEditable(false); 
    430420                portEditField.setEditable(false); 
    431                 useMdsCheckboxField.setEditable(false); 
    432421            } 
    433422            else { 
     
    435424                securityChoiceField.setSelectedIndex(ConnectionConfig.SECURITY_NONE); 
    436425                portEditField.setText("25"); 
    437                 useMdsCheckboxField.setChecked(true); 
    438426 
    439427                nameEditField.setEditable(true); 
    440428                securityChoiceField.setEditable(true); 
    441429                portEditField.setEditable(true); 
    442                 useMdsCheckboxField.setEditable(true); 
    443430            } 
    444431        } 
     
    465452                outgoingConfig.setServerSecurity(securityChoiceField.getSelectedIndex()); 
    466453                outgoingConfig.setServerPort(Integer.parseInt(portEditField.getText())); 
    467                 outgoingConfig.setDeviceSide(!useMdsCheckboxField.getChecked()); 
     454                outgoingConfig.setTransportType(ConnectionConfig.TRANSPORT_GLOBAL); 
    468455                outgoingCreated = true; 
    469456            } 
     
    488475                }}; 
    489476 
    490                 descriptionLabelField = new LabelField(resources.getString(LogicMailResource.WIZARD_SCREEN_OUTGOING_AUTHENTICATION_QUESTION)); 
    491  
    492                 String authTypes[] = { 
    493                         resources.getString(LogicMailResource.MENUITEM_NONE), 
    494                         "PLAIN", "LOGIN", "CRAM-MD5" }; 
    495                 authChoiceField = 
    496                     new ObjectChoiceField(resources.getString(LogicMailResource.CONFIG_OUTGOING_AUTHENTICATION) + ' ', authTypes, 0); 
    497                 authChoiceField.setChangeListener(fieldChangeListener); 
    498  
    499                 userEditField = new BasicEditField(resources.getString(LogicMailResource.CONFIG_ACCOUNT_USERNAME) + ' ', ""); 
    500  
    501                 passEditField = new PasswordEditField(resources.getString(LogicMailResource.CONFIG_ACCOUNT_PASSWORD) + ' ', ""); 
    502  
    503                 commentsSpacerLabel = new LabelField(); 
    504                 commentsField = new RichTextField(resources.getString(LogicMailResource.WIZARD_SCREEN_OUTGOING_AUTHENTICATION_COMMENTS)); 
    505                 commentsField.setFont(this.getFont().derive(Font.ITALIC)); 
    506  
    507                 add(descriptionLabelField); 
    508                 add(authChoiceField); 
    509                 setInputValid(true); 
     477            descriptionLabelField = new LabelField(resources.getString(LogicMailResource.WIZARD_SCREEN_OUTGOING_AUTHENTICATION_QUESTION)); 
     478 
     479            String authTypes[] = { 
     480                    resources.getString(LogicMailResource.MENUITEM_NONE), 
     481                    "PLAIN", "LOGIN", "CRAM-MD5" }; 
     482            authChoiceField = 
     483                new ObjectChoiceField(resources.getString(LogicMailResource.CONFIG_OUTGOING_AUTHENTICATION) + ' ', authTypes, 0); 
     484            authChoiceField.setChangeListener(fieldChangeListener); 
     485 
     486            userEditField = new BasicEditField(resources.getString(LogicMailResource.CONFIG_ACCOUNT_USERNAME) + ' ', ""); 
     487 
     488            passEditField = new PasswordEditField(resources.getString(LogicMailResource.CONFIG_ACCOUNT_PASSWORD) + ' ', ""); 
     489 
     490            commentsSpacerLabel = new LabelField(); 
     491            commentsField = new RichTextField(resources.getString(LogicMailResource.WIZARD_SCREEN_OUTGOING_AUTHENTICATION_COMMENTS)); 
     492            commentsField.setFont(this.getFont().derive(Font.ITALIC)); 
     493 
     494            add(descriptionLabelField); 
     495            add(authChoiceField); 
     496            setInputValid(true); 
    510497        } 
    511498 
  • trunk/LogicMail/src/org/logicprobe/LogicMail/ui/GlobalConfigScreen.java

    r570 r608  
    4242import org.logicprobe.LogicMail.LogicMailResource; 
    4343import org.logicprobe.LogicMail.PlatformInfo; 
     44import org.logicprobe.LogicMail.conf.ConnectionConfig; 
    4445import org.logicprobe.LogicMail.conf.GlobalConfig; 
    4546import org.logicprobe.LogicMail.conf.MailSettings; 
     
    6566    private ObjectChoiceField displayOrderChoiceField; 
    6667    private CheckboxField hideDeletedMessagesCheckboxField; 
    67     private ObjectChoiceField wifiModeChoiceField; 
     68    private ObjectChoiceField networkTransportChoiceField; 
     69    private CheckboxField enableWiFiCheckboxField; 
    6870    private ObjectChoiceField localDataLocationChoiceLabel; 
    6971    private CheckboxField connectionDebuggingCheckboxField; 
     
    7274 
    7375    public GlobalConfigScreen() { 
    74         super("LogicMail - " + 
     76        super(resources.getString(LogicMailResource.APPNAME) + " - " + 
    7577                resources.getString(LogicMailResource.CONFIG_GLOBAL_TITLE)); 
    7678 
     
    194196                existingConfig.getHideDeletedMsg()); 
    195197 
    196         String[] wifiModes = { 
    197                 resources.getString(LogicMailResource.MENUITEM_DISABLED), 
    198                 resources.getString(LogicMailResource.MENUITEM_PROMPT), 
    199                 resources.getString(LogicMailResource.MENUITEM_ALWAYS) 
     198 
     199        String[] transportChoices = { 
     200                resources.getString(LogicMailResource.CONFIG_GLOBAL_TRANSPORT_AUTO), 
     201                resources.getString(LogicMailResource.CONFIG_GLOBAL_TRANSPORT_DIRECT_TCP), 
     202                resources.getString(LogicMailResource.CONFIG_GLOBAL_TRANSPORT_MDS), 
     203                resources.getString(LogicMailResource.CONFIG_GLOBAL_TRANSPORT_WAP2) 
    200204        }; 
    201         wifiModeChoiceField = new ObjectChoiceField( 
    202                 resources.getString(LogicMailResource.CONFIG_GLOBAL_WIFI_MODE) + ' ', 
    203                 wifiModes, 
    204                 existingConfig.getWifiMode()); 
    205  
     205        networkTransportChoiceField = new ObjectChoiceField( 
     206                resources.getString(LogicMailResource.CONFIG_GLOBAL_NETWORK_TRANSPORT), 
     207                transportChoices, 
     208                getTransportChoice(existingConfig.getTransportType())); 
     209         
     210        enableWiFiCheckboxField = new CheckboxField( 
     211                resources.getString(LogicMailResource.CONFIG_GLOBAL_ENABLE_WIFI), 
     212                existingConfig.getEnableWiFi()); 
     213         
    206214        localDataLocationChoiceLabel = new ObjectChoiceField( 
    207215                resources.getString(LogicMailResource.CONFIG_GLOBAL_LOCAL_DATA_LOCATION) + ' ', 
     
    231239                existingConfig.getConnDebug()); 
    232240 
    233  
    234241        add(new LabeledSeparatorField( 
    235242                resources.getString(LogicMailResource.CONFIG_GLOBAL_SECTION_MESSAGE_DISPLAY), 
     
    243250                resources.getString(LogicMailResource.CONFIG_GLOBAL_SECTION_NETWORKING), 
    244251                Field.NON_FOCUSABLE | LabeledSeparatorField.TOP_BORDER | LabeledSeparatorField.BOTTOM_BORDER)); 
    245         add(wifiModeChoiceField); 
     252        add(networkTransportChoiceField); 
     253        add(enableWiFiCheckboxField); 
    246254        add(overrideHostnameCheckboxField); 
    247255        add(localHostnameEditField); 
     
    256264    } 
    257265 
     266    private static int getTransportChoice(int transportSetting) { 
     267        int result; 
     268        switch(transportSetting) { 
     269        case ConnectionConfig.TRANSPORT_AUTO: 
     270            result = 0; 
     271            break; 
     272        case ConnectionConfig.TRANSPORT_DIRECT_TCP: 
     273            result = 1; 
     274            break; 
     275        case ConnectionConfig.TRANSPORT_MDS: 
     276            result = 2; 
     277            break; 
     278        case ConnectionConfig.TRANSPORT_WAP2: 
     279            result = 3; 
     280            break; 
     281        default: 
     282            result = 0; 
     283            break; 
     284        } 
     285        return result; 
     286    } 
     287     
     288    private static int getTransportSetting(int transportChoice) { 
     289        int result; 
     290        switch(transportChoice) { 
     291        case 0: 
     292            result = ConnectionConfig.TRANSPORT_AUTO; 
     293            break; 
     294        case 1: 
     295            result = ConnectionConfig.TRANSPORT_DIRECT_TCP; 
     296            break; 
     297        case 2: 
     298            result = ConnectionConfig.TRANSPORT_MDS; 
     299            break; 
     300        case 3: 
     301            result = ConnectionConfig.TRANSPORT_WAP2; 
     302            break; 
     303        default: 
     304            result = ConnectionConfig.TRANSPORT_AUTO; 
     305            break; 
     306        } 
     307        return result; 
     308    } 
     309     
    258310    public void fieldChanged(Field field, int context) { 
    259311        if (field == overrideHostnameCheckboxField) { 
     
    301353        config.setHideDeletedMsg(hideDeletedMessagesCheckboxField.getChecked()); 
    302354 
    303         config.setWifiMode(wifiModeChoiceField.getSelectedIndex()); 
     355        config.setTransportType(getTransportSetting(networkTransportChoiceField.getSelectedIndex())); 
     356         
     357        config.setEnableWiFi(enableWiFiCheckboxField.getChecked()); 
    304358 
    305359        int fsRootIndex = localDataLocationChoiceLabel.getSelectedIndex(); 
  • trunk/LogicMail/src/org/logicprobe/LogicMail/ui/OutgoingConfigScreen.java

    r595 r608  
    3838import net.rim.device.api.ui.component.CheckboxField; 
    3939import net.rim.device.api.ui.component.Dialog; 
     40import net.rim.device.api.ui.component.LabelField; 
    4041import net.rim.device.api.ui.component.ObjectChoiceField; 
    4142import net.rim.device.api.ui.component.PasswordEditField; 
     
    6061    private BasicEditField serverUserField; 
    6162    private PasswordEditField serverPassField; 
    62     private CheckboxField useMdsField; 
     63    private ObjectChoiceField networkTransportChoiceField; 
     64    private CheckboxField enableWiFiCheckboxField; 
    6365     
    6466    private boolean acctSaved; 
     
    134136                outgoingConfig.getServerPass()); 
    135137         
    136         useMdsField = new CheckboxField( 
    137                 resources.getString(LogicMailResource.CONFIG_ACCOUNT_USEMDSPROXY), 
    138                 !outgoingConfig.getDeviceSide()); 
     138        String[] transportChoices = { 
     139                resources.getString(LogicMailResource.CONFIG_ACCOUNT_TRANSPORT_USE_GLOBAL), 
     140                resources.getString(LogicMailResource.CONFIG_GLOBAL_TRANSPORT_AUTO), 
     141                resources.getString(LogicMailResource.CONFIG_GLOBAL_TRANSPORT_DIRECT_TCP), 
     142                resources.getString(LogicMailResource.CONFIG_GLOBAL_TRANSPORT_MDS), 
     143                resources.getString(LogicMailResource.CONFIG_GLOBAL_TRANSPORT_WAP2) 
     144        }; 
     145        networkTransportChoiceField = new ObjectChoiceField( 
     146                resources.getString(LogicMailResource.CONFIG_GLOBAL_NETWORK_TRANSPORT), 
     147                transportChoices, 
     148                getTransportChoice(outgoingConfig.getTransportType())); 
     149        networkTransportChoiceField.setChangeListener(new FieldChangeListener() { 
     150            public void fieldChanged(Field field, int context) { 
     151                networkTransportChoiceField_FieldChanged(field, context); 
     152            } 
     153        }); 
     154        enableWiFiCheckboxField = new CheckboxField( 
     155                resources.getString(LogicMailResource.CONFIG_GLOBAL_ENABLE_WIFI), 
     156                outgoingConfig.getEnableWiFi()); 
     157        if(networkTransportChoiceField.getSelectedIndex() == 0) { 
     158            enableWiFiCheckboxField.setChecked(false); 
     159            enableWiFiCheckboxField.setEditable(false); 
     160        } 
    139161         
    140162        headerFieldManager = new BorderedFieldManager(BorderedFieldManager.BOTTOM_BORDER_NONE); 
     
    148170        contentFieldManager.add(serverUserField); 
    149171        contentFieldManager.add(serverPassField); 
    150         contentFieldManager.add(useMdsField); 
     172        contentFieldManager.add(new LabelField()); 
     173        contentFieldManager.add(networkTransportChoiceField); 
     174        contentFieldManager.add(enableWiFiCheckboxField); 
    151175         
    152176        add(headerFieldManager); 
    153177        add(contentFieldManager); 
    154178    } 
    155      
     179 
    156180    private void serverSecurityField_FieldChanged(Field field, int context) { 
    157181        if(serverSecurityField.getSelectedIndex() == ConnectionConfig.SECURITY_SSL) { 
     
    176200            serverPassField.setText(""); 
    177201        } 
     202    } 
     203     
     204    private void networkTransportChoiceField_FieldChanged(Field field, int context) { 
     205        if(networkTransportChoiceField.getSelectedIndex() == 0) { 
     206            enableWiFiCheckboxField.setChecked(false); 
     207            enableWiFiCheckboxField.setEditable(false); 
     208        } 
     209        else { 
     210            enableWiFiCheckboxField.setChecked(true); 
     211            enableWiFiCheckboxField.setEditable(true); 
     212        } 
     213    } 
     214 
     215    private static int getTransportChoice(int transportSetting) { 
     216        int result; 
     217        switch(transportSetting) { 
     218        case ConnectionConfig.TRANSPORT_GLOBAL: 
     219            result = 0; 
     220            break; 
     221        case ConnectionConfig.TRANSPORT_AUTO: 
     222            result = 1; 
     223            break; 
     224        case ConnectionConfig.TRANSPORT_DIRECT_TCP: 
     225            result = 2; 
     226            break; 
     227        case ConnectionConfig.TRANSPORT_MDS: 
     228            result = 3; 
     229            break; 
     230        case ConnectionConfig.TRANSPORT_WAP2: 
     231            result = 4; 
     232            break; 
     233        default: 
     234            result = 0; 
     235            break; 
     236        } 
     237        return result; 
     238    } 
     239     
     240    private static int getTransportSetting(int transportChoice) { 
     241        int result; 
     242        switch(transportChoice) { 
     243        case 0: 
     244            result = ConnectionConfig.TRANSPORT_GLOBAL; 
     245            break; 
     246        case 1: 
     247            result = ConnectionConfig.TRANSPORT_AUTO; 
     248            break; 
     249        case 2: 
     250            result = ConnectionConfig.TRANSPORT_DIRECT_TCP; 
     251            break; 
     252        case 3: 
     253            result = ConnectionConfig.TRANSPORT_MDS; 
     254            break; 
     255        case 4: 
     256            result = ConnectionConfig.TRANSPORT_WAP2; 
     257            break; 
     258        default: 
     259            result = ConnectionConfig.TRANSPORT_GLOBAL; 
     260            break; 
     261        } 
     262        return result; 
    178263    } 
    179264 
     
    206291        this.outgoingConfig.setServerUser(serverUserField.getText()); 
    207292        this.outgoingConfig.setServerPass(serverPassField.getText()); 
    208         this.outgoingConfig.setDeviceSide(!useMdsField.getChecked()); 
     293        this.outgoingConfig.setTransportType(getTransportSetting(networkTransportChoiceField.getSelectedIndex())); 
     294        this.outgoingConfig.setEnableWiFi(enableWiFiCheckboxField.getChecked()); 
    209295        this.outgoingConfig.setUseAuth(useAuthField.getSelectedIndex()); 
    210296        if(useAuthField.getSelectedIndex() > 0) { 
  • trunk/LogicMail/src/org/logicprobe/LogicMail/util/Connection.java

    r477 r608  
    6161 
    6262import net.rim.device.api.crypto.tls.tls10.TLS10Connection; 
     63import net.rim.device.api.i18n.ResourceBundle; 
    6364import net.rim.device.api.system.EventLogger; 
    64 import net.rim.device.api.ui.UiApplication; 
    65 import net.rim.device.api.ui.component.Dialog; 
    6665import net.rim.device.api.util.DataBuffer; 
    6766import net.rim.device.cldc.io.ssl.TLSException; 
    6867 
    6968import org.logicprobe.LogicMail.AppInfo; 
     69import org.logicprobe.LogicMail.LogicMailResource; 
     70import org.logicprobe.LogicMail.conf.ConnectionConfig; 
    7071import org.logicprobe.LogicMail.conf.GlobalConfig; 
    7172import org.logicprobe.LogicMail.conf.MailSettings; 
     
    7778import java.io.OutputStream; 
    7879 
    79 import java.util.Vector; 
    80  
    81 import javax.microedition.io.Connector; 
    8280import javax.microedition.io.SocketConnection; 
    8381import javax.microedition.io.StreamConnection; 
     
    102100 * is the only way to get rid of compile-time dependencies on these classes. 
    103101 */ 
    104 public class Connection { 
     102public abstract class Connection { 
     103    protected static ResourceBundle resources = ResourceBundle.getBundle(LogicMailResource.BUNDLE_ID, LogicMailResource.BUNDLE_NAME); 
     104     
     105    /** Select everything except WiFi */ 
     106    protected static final int TRANSPORT_AUTO = 0xFE; 
     107    /** Select WiFi */ 
     108    protected static final int TRANSPORT_WIFI = 0x01; 
     109    /** Select Direct TCP */ 
     110    protected static final int TRANSPORT_DIRECT_TCP = 0x02; 
     111    /** Select MDS */ 
     112    protected static final int TRANSPORT_MDS = 0x04; 
     113    /** Select WAP 2.0 */ 
     114    protected static final int TRANSPORT_WAP2 = 0x08; 
     115 
    105116    /** 
    106117     * Byte array holding carriage return and line feed 
     
    108119    private static final byte[] CRLF = new byte[] { 13, 10 }; 
    109120 
    110     /** 
    111      * Holds a list of open connections 
    112      */ 
    113     private static Vector openConnections = new Vector(); 
    114     private String serverName; 
    115     private int serverPort; 
    116     private boolean useSSL; 
    117     private boolean deviceSide; 
     121    private static UtilFactory connectionFactory; 
     122    protected String serverName; 
     123    protected int serverPort; 
     124    protected boolean useSSL; 
     125    protected int transports; 
    118126    private StreamConnection socket; 
    119127    private String localAddress; 
    120     private GlobalConfig globalConfig; 
     128    protected GlobalConfig globalConfig; 
    121129    protected InputStream input; 
    122130    protected OutputStream output; 
    123     private boolean useWiFi; 
     131    protected boolean useWiFi; 
    124132    private int fakeAvailable = -1; 
    125133    private int bytesSent = 0; 
    126134    private int bytesReceived = 0; 
    127      
     135 
    128136    /** 
    129137     * Provides a buffer used for incoming data. 
     
    136144    DataBuffer resultBuffer = new DataBuffer(); 
    137145 
    138     public Connection(String serverName, int serverPort, boolean useSSL, 
    139         boolean deviceSide) { 
    140         this.serverName = serverName; 
    141         this.serverPort = serverPort; 
    142         this.useSSL = useSSL; 
    143         this.deviceSide = deviceSide; 
     146    /** 
     147     * Initializes a new connection object. 
     148     *  
     149     * @param connectionConfig Configuration data for the connection 
     150     */ 
     151    protected Connection(ConnectionConfig connectionConfig) { 
     152        this.globalConfig = MailSettings.getInstance().getGlobalConfig(); 
     153         
     154        this.serverName = connectionConfig.getServerName(); 
     155        this.serverPort = connectionConfig.getServerPort(); 
     156        this.useSSL = (connectionConfig.getServerSecurity() == ConnectionConfig.SECURITY_SSL); 
     157         
     158        int transportType; 
     159        boolean enableWiFi; 
     160        if(connectionConfig.getTransportType() == ConnectionConfig.TRANSPORT_GLOBAL) { 
     161            transportType = globalConfig.getTransportType(); 
     162            enableWiFi = globalConfig.getEnableWiFi(); 
     163        } 
     164        else { 
     165            transportType = connectionConfig.getTransportType(); 
     166            enableWiFi = connectionConfig.getEnableWiFi(); 
     167        } 
     168 
     169        // Populate the bit-flags for the selected transport types 
     170        // based on the configuration parameters. 
     171        switch(transportType) { 
     172        case ConnectionConfig.TRANSPORT_AUTO: 
     173            transports = Connection.TRANSPORT_AUTO; 
     174            break; 
     175        case ConnectionConfig.TRANSPORT_DIRECT_TCP: 
     176            transports = Connection.TRANSPORT_DIRECT_TCP; 
     177            break; 
     178        case ConnectionConfig.TRANSPORT_MDS: 
     179            transports = Connection.TRANSPORT_MDS; 
     180            break; 
     181        case ConnectionConfig.TRANSPORT_WAP2: 
     182            transports = Connection.TRANSPORT_WAP2; 
     183            break; 
     184        default: 
     185            // Should only get here in rare cases of invalid configuration 
     186            // data, so we select full automatic with WiFi. 
     187            transports = Connection.TRANSPORT_AUTO; 
     188            enableWiFi = true; 
     189            break; 
     190        } 
     191        if(enableWiFi) { transports |= Connection.TRANSPORT_WIFI; } 
     192         
    144193        this.input = null; 
    145194        this.output = null; 
    146195        this.socket = null; 
    147         this.globalConfig = MailSettings.getInstance().getGlobalConfig(); 
    148     } 
    149  
     196    } 
     197 
     198    /** 
     199     * Sets the connection factory reference. 
     200     *  
     201     * @param connectionFactory connection factory reference 
     202     */ 
     203    static void setConnectionFactory(UtilFactory connectionFactory) { 
     204        Connection.connectionFactory = connectionFactory; 
     205    } 
     206     
    150207    /** 
    151208     * Opens a connection. 
     
    155212            close(); 
    156213        } 
    157  
    158         synchronized (openConnections) { 
    159             if (!openConnections.contains(this)) { 
    160                 openConnections.addElement(this); 
    161             } 
    162         } 
    163  
    164         String protocolStr = (useSSL ? "ssl" : "socket"); 
    165  
    166         // This parameter, which allows bypassing the MDS proxy, should probably 
    167         // be a global user configurable option 
    168         String paramStr = (deviceSide ? ";deviceside=true" : ""); 
    169  
    170         useWiFi = false; 
    171  
    172         if (globalConfig.getWifiMode() == GlobalConfig.WIFI_PROMPT) { 
    173             UiApplication.getUiApplication().invokeAndWait(new Runnable() { 
    174                     public void run() { 
    175                         useWiFi = (Dialog.ask(Dialog.D_YES_NO, 
    176                                 "Connect through WiFi?") == Dialog.YES); 
    177                     } 
    178                 }); 
    179         } else if (globalConfig.getWifiMode() == GlobalConfig.WIFI_ALWAYS) { 
    180             useWiFi = true; 
    181         } 
    182  
    183         if (useWiFi) { 
    184             paramStr = paramStr + ";interface=wifi"; 
    185         } 
    186  
    187         String connectStr = protocolStr + "://" + serverName + ":" + 
    188             serverPort + paramStr; 
    189  
    190         if (EventLogger.getMinimumLevel() >= EventLogger.INFORMATION) { 
    191             String msg = "Opening connection:\r\n" + connectStr + "\r\n"; 
    192             EventLogger.logEvent(AppInfo.GUID, msg.getBytes(), 
    193                 EventLogger.INFORMATION); 
    194         } 
    195  
    196         socket = (StreamConnection) Connector.open(connectStr, 
    197                 Connector.READ_WRITE, true); 
     214         
     215        connectionFactory.addOpenConnection(this); 
     216 
     217        socket = openStreamConnection(); 
     218        if(socket == null) { 
     219            throw new IOException(resources.getString(LogicMailResource.ERROR_UNABLE_TO_OPEN_CONNECTION)); 
     220        } 
     221         
    198222        input = socket.openDataInputStream(); 
    199223        output = socket.openDataOutputStream(); 
     
    201225        bytesSent = 0; 
    202226        bytesReceived = 0; 
    203          
     227 
    204228        if (EventLogger.getMinimumLevel() >= EventLogger.INFORMATION) { 
    205229            String msg = "Connection established:\r\n" + "Socket: " + 
    206                 socket.getClass().toString() + "\r\n" + "Local address: " + 
    207                 localAddress + "\r\n"; 
     230            socket.getClass().toString() + "\r\n" + "Local address: " + 
     231            localAddress + "\r\n"; 
    208232            EventLogger.logEvent(AppInfo.GUID, msg.getBytes(), 
    209                 EventLogger.INFORMATION); 
    210         } 
    211     } 
     233                    EventLogger.INFORMATION); 
     234        } 
     235    } 
     236     
     237    /** 
     238     * Open a stream connection. 
     239     * This method should encapsulate all platform-specific logic for opening 
     240     * network connections. 
     241     *  
     242     * @return the stream connection 
     243     *  
     244     * @throws IOException Signals that an I/O exception has occurred. 
     245     */ 
     246    protected abstract StreamConnection openStreamConnection() throws IOException; 
    212247 
    213248    /** 
     
    242277        } 
    243278 
    244         synchronized (openConnections) { 
    245             if (openConnections.contains(this)) { 
    246                 openConnections.removeElement(this); 
    247             } 
    248         } 
     279        connectionFactory.removeOpenConnection(this); 
    249280 
    250281        EventLogger.logEvent(AppInfo.GUID, "Connection closed".getBytes(), 
    251             EventLogger.INFORMATION); 
    252     } 
    253  
    254     /** 
    255      * Determine whether open connections exist 
    256      * 
    257      * @return True if there are open connections 
    258      */ 
    259     public static boolean hasOpenConnections() { 
    260         boolean result; 
    261  
    262         synchronized (openConnections) { 
    263             result = !openConnections.isEmpty(); 
    264         } 
    265  
    266         return result; 
    267     } 
    268  
    269     /** 
    270      * Close all open connections 
    271      */ 
    272     public static void closeAllConnections() { 
    273         synchronized (openConnections) { 
    274             int size = openConnections.size(); 
    275  
    276             for (int i = 0; i < size; i++) { 
    277                 try { 
    278                     ((Connection) openConnections.elementAt(i)).close(); 
    279                 } catch (IOException e) { 
    280                 } 
    281             } 
    282  
    283             openConnections.removeAllElements(); 
    284         } 
     282                EventLogger.INFORMATION); 
    285283    } 
    286284 
     
    324322     */ 
    325323    public int getBytesSent() { 
    326         return bytesSent; 
    327     } 
    328      
     324        return bytesSent; 
     325    } 
     326 
    329327    /** 
    330328     * Gets the number of bytes that have been received since the 
     
    338336     */ 
    339337    public int getBytesReceived() { 
    340         return bytesReceived; 
    341     } 
    342      
     338        return bytesReceived; 
     339    } 
     340 
    343341    /** 
    344342     * Sends a string to the server. This method is used internally for 
     
    360358            if (globalConfig.getConnDebug()) { 
    361359                EventLogger.logEvent(AppInfo.GUID, "[SEND]".getBytes(), 
    362                     EventLogger.DEBUG_INFO); 
     360                        EventLogger.DEBUG_INFO); 
    363361            } 
    364362 
     
    386384                if (globalConfig.getConnDebug()) { 
    387385                    EventLogger.logEvent(AppInfo.GUID, 
    388                         ("[SEND] " + s.substring(i, j)).getBytes(), 
    389                         EventLogger.DEBUG_INFO); 
     386                            ("[SEND] " + s.substring(i, j)).getBytes(), 
     387                            EventLogger.DEBUG_INFO); 
    390388                } 
    391389 
     
    420418        if (globalConfig.getConnDebug()) { 
    421419            EventLogger.logEvent(AppInfo.GUID, ("[SEND CMD] " + s).getBytes(), 
    422                 EventLogger.DEBUG_INFO); 
     420                    EventLogger.DEBUG_INFO); 
    423421        } 
    424422 
     
    427425            bytesSent += 2; 
    428426        } else { 
    429                 byte[] buf = (s + "\r\n").getBytes(); 
     427            byte[] buf = (s + "\r\n").getBytes(); 
    430428            output.write(buf); 
    431429            bytesSent += buf.length; 
     
    448446        if (globalConfig.getConnDebug()) { 
    449447            EventLogger.logEvent(AppInfo.GUID, 
    450                 ("[SEND RAW]\r\n" + s).getBytes(), EventLogger.DEBUG_INFO); 
     448                    ("[SEND RAW]\r\n" + s).getBytes(), EventLogger.DEBUG_INFO); 
    451449        } 
    452450 
    453451        output.write(buf, 0, buf.length); 
    454452        bytesSent += buf.length; 
    455          
     453 
    456454        output.flush(); 
    457455    } 
     
    530528            while (true) { 
    531529                int actual = input.read(buffer, count, 1); 
    532                  
     530 
    533531                /** 
    534532                 * If -1 is returned, the InputStream is already closed, 
     
    539537                if (actual == -1) { 
    540538                    EventLogger.logEvent(AppInfo.GUID, 
    541                         "Unable to read from socket, closing connection".getBytes(), 
    542                         EventLogger.INFORMATION); 
     539                            "Unable to read from socket, closing connection".getBytes(), 
     540                            EventLogger.INFORMATION); 
    543541 
    544542                    try { 
     
    567565                // approach which screws up on mid-line LFs. (DK) 
    568566                else { 
    569                         bytesReceived += actual; 
    570                          
     567                    bytesReceived += actual; 
     568 
    571569                    byte b = buffer[count]; 
    572570                    readBytes++; 
     
    606604        if (globalConfig.getConnDebug()) { 
    607605            EventLogger.logEvent(AppInfo.GUID, 
    608                 ("[RECV] " + result).getBytes(), 
    609                 EventLogger.DEBUG_INFO); 
     606                    ("[RECV] " + result).getBytes(), 
     607                    EventLogger.DEBUG_INFO); 
    610608        } 
    611609 
     
    619617    } 
    620618 
    621         /** 
    622         * Switches the underlying connection to SSL mode, as commonly done after 
    623         * sending a <tt>STARTTLS</tt> command to the server. 
    624         *  
    625         * @throws IOException Signals that an I/O exception has occurred. 
    626         */ 
    627         public void startTLS() throws IOException { 
    628                 // Shortcut the method if we're already in SSL mode 
    629                 if(socket instanceof TLS10Connection) { return; } 
    630                  
    631                 try { 
    632                         TLS10Connection tlsSocket = new TLS10Connection( 
    633                                         new StreamConnectionWrapper( 
    634                                                 socket, 
    635                                                 (DataInputStream)input, 
    636                                                 (DataOutputStream)output), 
    637                                         serverName + ':' + serverPort, 
    638                                         true); 
    639                          
    640                         socket = tlsSocket; 
    641                         input = socket.openDataInputStream(); 
    642                         output = socket.openDataOutputStream(); 
    643                 } catch (IOException e) { 
     619    /** 
     620    * Switches the underlying connection to SSL mode, as commonly done after 
     621    * sending a <tt>STARTTLS</tt> command to the server. 
     622    *  
     623    * @throws IOException Signals that an I/O exception has occurred. 
     624    */ 
     625    public void startTLS() throws IOException { 
     626        // Shortcut the method if we're already in SSL mode 
     627        if(socket instanceof TLS10Connection) { return; } 
     628 
     629        try { 
     630            TLS10Connection tlsSocket = new TLS10Connection( 
     631                    new StreamConnectionWrapper( 
     632                            socket, 
     633                            (DataInputStream)input, 
     634                            (DataOutputStream)output), 
     635                            serverName + ':' + serverPort, 
     636                            true); 
     637 
     638            socket = tlsSocket; 
     639            input = socket.openDataInputStream(); 
     640            output = socket.openDataOutputStream(); 
     641        } catch (IOException e) { 
    644642            EventLogger.logEvent(AppInfo.GUID, 
    645643                    ("Unable to switch to TLS mode: " + e.getMessage()).getBytes(), EventLogger.ERROR); 
    646644            throw new IOException("Unable to switch to TLS mode"); 
    647                 } catch (TLSException e) { 
     645        } catch (TLSException e) { 
    648646            EventLogger.logEvent(AppInfo.GUID, 
    649647                    ("Unable to switch to TLS mode: " + e.getMessage()).getBytes(), EventLogger.ERROR); 
    650648            throw new IOException("Unable to switch to TLS mode"); 
    651                 } 
    652         } 
    653          
    654         /** 
    655         * Decorator to wrap an existing stream connection so its I/O streams 
    656         * can be reopened without throwing exceptions. 
    657         */ 
    658         private static class StreamConnectionWrapper implements StreamConnection { 
    659                 private StreamConnection stream; 
    660                 private DataInputStream dataInputStream; 
    661                 private DataOutputStream dataOutputStream; 
    662                  
    663                 public StreamConnectionWrapper(StreamConnection stream, DataInputStream dataInputStream, DataOutputStream dataOutputStream) { 
    664                         this.stream = stream; 
    665                         this.dataInputStream = dataInputStream; 
    666                         this.dataOutputStream = dataOutputStream; 
    667                 } 
    668                  
    669                 public DataInputStream openDataInputStream() throws IOException { 
    670                         return dataInputStream; 
    671                 } 
    672                 public InputStream openInputStream() throws IOException { 
    673                         return dataInputStream; 
    674                 } 
    675                 public void close() throws IOException { 
    676                         stream.close(); 
    677                 } 
    678                 public DataOutputStream openDataOutputStream() throws IOException { 
    679                         return dataOutputStream; 
    680                 } 
    681                 public OutputStream openOutputStream() throws IOException { 
    682                         return dataOutputStream; 
    683                 } 
    684         } 
     649        } 
     650    } 
     651 
     652    /** 
     653    * Decorator to wrap an existing stream connection so its I/O streams 
     654    * can be reopened without throwing exceptions. 
     655    */ 
     656    private static class StreamConnectionWrapper implements StreamConnection { 
     657        private StreamConnection stream; 
     658        private DataInputStream dataInputStream; 
     659        private DataOutputStream dataOutputStream; 
     660 
     661        public StreamConnectionWrapper(StreamConnection stream, DataInputStream dataInputStream, DataOutputStream dataOutputStream) { 
     662            this.stream = stream; 
     663            this.dataInputStream = dataInputStream; 
     664            this.dataOutputStream = dataOutputStream; 
     665        } 
     666 
     667        public DataInputStream openDataInputStream() throws IOException { 
     668            return dataInputStream; 
     669        } 
     670        public InputStream openInputStream() throws IOException { 
     671            return dataInputStream; 
     672        } 
     673        public void close() throws IOException { 
     674            stream.close(); 
     675        } 
     676        public DataOutputStream openDataOutputStream() throws IOException { 
     677            return dataOutputStream; 
     678        } 
     679        public OutputStream openOutputStream() throws IOException { 
     680            return dataOutputStream; 
     681        } 
     682    } 
    685683} 
  • trunk/LogicMailTests/src/org/logicprobe/LogicMail/conf/AccountConfigTest.java

    r482 r608  
    9696        assertEquals("", instance.getServerPass()); 
    9797        assertEquals(143, instance.getServerPort()); 
    98         assertTrue(!instance.getDeviceSide()); 
     98        assertEquals(ConnectionConfig.TRANSPORT_GLOBAL, instance.getTransportType()); 
     99        assertTrue(!instance.getEnableWiFi()); 
    99100    } 
    100101 
     
    109110            instance.setServerPass("12345"); 
    110111            instance.setServerPort(995); 
    111             instance.setDeviceSide(true); 
     112            instance.setTransportType(ConnectionConfig.TRANSPORT_DIRECT_TCP); 
     113            instance.setEnableWiFi(true); 
    112114             
    113115            // Serialize 
     
    127129            assertEquals("12345", instance.getServerPass()); 
    128130            assertEquals(995, instance.getServerPort()); 
    129             assertTrue(instance.getDeviceSide()); 
     131            assertEquals(ConnectionConfig.TRANSPORT_DIRECT_TCP, instance.getTransportType()); 
     132            assertTrue(instance.getEnableWiFi()); 
    130133        } catch (Throwable t) { 
    131134            fail("Exception thrown during test: "+t.toString()); 
  • trunk/LogicMailTests/src/org/logicprobe/LogicMail/conf/GlobalConfigTest.java

    r350 r608  
    9393        assertEquals(30, instance.getRetMsgCount()); 
    9494        assertTrue(!instance.getDispOrder()); 
    95         assertEquals(0, instance.getWifiMode()); 
     95        assertEquals(ConnectionConfig.TRANSPORT_AUTO, instance.getTransportType()); 
     96        assertTrue(instance.getEnableWiFi()); 
    9697        assertTrue(instance.getHideDeletedMsg()); 
    9798    } 
     
    103104            instance.setRetMsgCount(20); 
    104105            instance.setDispOrder(true); 
    105             instance.setWifiMode(1); 
     106            instance.setTransportType(ConnectionConfig.TRANSPORT_DIRECT_TCP); 
     107            instance.setEnableWiFi(false); 
    106108            instance.setHideDeletedMsg(false); 
    107109             
     
    118120            assertEquals(20, instance.getRetMsgCount()); 
    119121            assertTrue(instance.getDispOrder()); 
    120             assertEquals(1, instance.getWifiMode()); 
     122            assertEquals(ConnectionConfig.TRANSPORT_DIRECT_TCP, instance.getTransportType()); 
     123            assertTrue(!instance.getEnableWiFi()); 
    121124            assertTrue(!instance.getHideDeletedMsg()); 
    122125        } catch (Throwable t) { 
Note: See TracChangeset for help on using the changeset viewer.