Changeset 561


Ignore:
Timestamp:
12/07/09 21:13:32 (2 years ago)
Author:
octorian
Message:

Improved local data location selection and path. Still need clean handling of use cases where this is disabled.

Location:
trunk/LogicMail
Files:
4 edited

Legend:

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

    r555 r561  
    3636CONFIG_GLOBAL_HOSTNAME#0="Hostname:"; 
    3737CONFIG_GLOBAL_LANGUAGE#0="Language:"; 
     38CONFIG_GLOBAL_LOCAL_DATA_DEVICE_MEMORY#0="Device Memory"; 
     39CONFIG_GLOBAL_LOCAL_DATA_DISABLED#0="Disabled"; 
    3840CONFIG_GLOBAL_LOCAL_DATA_LOCATION#0="Local data location:"; 
     41CONFIG_GLOBAL_LOCAL_DATA_MEDIA_CARD#0="Media Card"; 
    3942CONFIG_GLOBAL_MESSAGE_COUNT#0="Message count:"; 
    4043CONFIG_GLOBAL_MESSAGE_FORMAT#0="Preferred message format:"; 
  • trunk/LogicMail/res/org/logicprobe/LogicMail/LogicMail.rrh

    r555 r561  
    181181CONFIG_GLOBAL_SECTION_NETWORKING#0=182; 
    182182CONFIG_GLOBAL_SECTION_OTHER#0=183; 
     183CONFIG_GLOBAL_LOCAL_DATA_DISABLED#0=184; 
     184CONFIG_GLOBAL_LOCAL_DATA_MEDIA_CARD#0=185; 
     185CONFIG_GLOBAL_LOCAL_DATA_DEVICE_MEMORY#0=186; 
  • trunk/LogicMail/src/org/logicprobe/LogicMail/conf/GlobalConfig.java

    r518 r561  
    3131package org.logicprobe.LogicMail.conf; 
    3232 
     33import org.logicprobe.LogicMail.PlatformInfo; 
    3334import org.logicprobe.LogicMail.util.Serializable; 
    3435import org.logicprobe.LogicMail.util.SerializableHashtable; 
     
    3839import java.io.DataOutput; 
    3940import java.io.IOException; 
    40 import java.util.Enumeration; 
    41  
    42 import javax.microedition.io.file.FileSystemRegistry; 
    43  
     41 
     42import javax.microedition.io.Connector; 
     43import javax.microedition.io.file.FileConnection; 
    4444 
    4545/** 
     
    5757    /** Always use WiFi */ 
    5858    final public static int WIFI_ALWAYS = 2; 
    59      
     59 
    6060    /** Prefer plain text display for messages */ 
    6161    final public static int MESSAGE_DISPLAY_PLAIN_TEXT = 0; 
    62      
     62 
    6363    /** Prefer HTML display for messages */ 
    6464    final public static int MESSAGE_DISPLAY_HTML = 1; 
    65      
     65 
    6666    /** language code to use for the UI, or null for system default */ 
    6767    private String languageCode; 
    68      
     68 
    6969    /** true to enable Unicode normalization */ 
    7070    private boolean unicodeNormalization; 
     
    7272    /** Preferred message display format */ 
    7373    private int messageDisplayFormat; 
    74      
     74 
    7575    /** Number of message headers to retrieve */ 
    7676    private int retMsgCount; 
     
    8181    /** Root URL for local file storage */ 
    8282    private String localDataLocation; 
    83      
     83 
    8484    /** Mode for WiFi support */ 
    8585    private int wifiMode; 
     
    9494    private String localHostname; 
    9595 
     96    public static String FILE_URL_PREFIX = "file:///"; 
     97     
    9698    /** 
    9799     * Instantiates a new global configuration. 
     
    127129        this.hideDeletedMsg = true; 
    128130        this.localHostname = ""; 
    129          
    130         Enumeration e = FileSystemRegistry.listRoots(); 
    131         if(e.hasMoreElements()) { 
    132                 this.localDataLocation = "file:///" + (String)e.nextElement() + "LogicMail/"; 
    133         } 
    134         else { 
    135                 this.localDataLocation = "file:///LogicMail/"; 
    136         } 
    137     } 
    138      
     131        this.localDataLocation = null; 
     132    } 
     133 
    139134    /** 
    140135     * Sets the language code. 
     
    145140        this.languageCode = languageCode; 
    146141    } 
    147      
     142 
    148143    /** 
    149144     * Gets the language code. 
     
    154149        return languageCode; 
    155150    } 
    156      
     151 
    157152    /** 
    158153     * Sets whether unicode normalization is enabled. 
     
    163158        this.unicodeNormalization = unicodeNormalization; 
    164159    } 
    165      
     160 
    166161    /** 
    167162     * Gets whether unicode normalization is enabled. 
     
    179174     */ 
    180175    public void setMessageDisplayFormat(int messageDisplayFormat) { 
    181         this.messageDisplayFormat = messageDisplayFormat; 
    182     } 
    183      
     176        this.messageDisplayFormat = messageDisplayFormat; 
     177    } 
     178 
    184179    /** 
    185180     * Gets the preferred message display format. 
     
    188183     */ 
    189184    public int getMessageDisplayFormat() { 
    190         return messageDisplayFormat; 
    191     } 
    192      
     185        return messageDisplayFormat; 
     186    } 
     187 
    193188    /** 
    194189     * Set the number of message headers to retrieve. 
     
    233228     */ 
    234229    public void setLocalDataLocation(String localDataLocation) { 
    235         this.localDataLocation = localDataLocation; 
    236     } 
    237      
     230        this.localDataLocation = validateLocalDataLocation(localDataLocation); 
     231    } 
     232 
    238233    /** 
    239234     * Set the root URL for local file storage. 
     
    242237     */ 
    243238    public String getLocalDataLocation() { 
    244         return localDataLocation; 
     239        return localDataLocation; 
    245240    } 
    246241 
     
    324319 
    325320        SerializableHashtable table = new SerializableHashtable(); 
    326          
     321 
    327322        table.put("global_languageCode", languageCode); 
    328323        table.put("global_unicodeNormalization", new Boolean(unicodeNormalization)); 
     
    355350            languageCode = (String)value; 
    356351        } 
    357          
     352 
    358353        value = table.get("global_unicodeNormalization"); 
    359354        if(value != null && value instanceof Boolean) { 
    360355            unicodeNormalization = ((Boolean)value).booleanValue(); 
    361356        } 
    362          
     357 
    363358        value = table.get("global_messageDisplayFormat"); 
    364359        if ((value != null) && value instanceof Integer) { 
    365                 messageDisplayFormat = ((Integer) value).intValue(); 
    366         } 
    367          
     360            messageDisplayFormat = ((Integer) value).intValue(); 
     361        } 
     362 
    368363        value = table.get("global_retMsgCount"); 
    369364        if ((value != null) && value instanceof Integer) { 
     
    378373        value = table.get("global_localDataLocation"); 
    379374        if ((value != null) && value instanceof String) { 
    380                 localDataLocation = (String) value; 
    381         } 
    382          
     375            setLocalDataLocation((String)value); 
     376        } 
     377        else { 
     378            String[] fsRoots = PlatformInfo.getInstance().getFilesystemRoots(); 
     379            if(fsRoots.length > 0) { 
     380                setLocalDataLocation(fsRoots[0]); 
     381            } 
     382        } 
     383 
    383384        value = table.get("global_wifiMode"); 
    384385        if ((value != null) && value instanceof Integer) { 
     
    411412        return uniqueId; 
    412413    } 
     414     
     415    /** 
     416     * Checks provided filesystem root to make sure it exists, 
     417     * creating any intermediate directories as necessary, 
     418     * and returns a fully qualified file URL. 
     419     *  
     420     * @param fsRoot filesystem root to validate 
     421     * @return fully qualified and valid file URL, 
     422     * or null if one could not be created 
     423     */ 
     424    private static String validateLocalDataLocation(String fsRoot) { 
     425        String url; 
     426        if(fsRoot != null) { 
     427            // Clean up the string, removing everything but the base 
     428            int p = fsRoot.indexOf('/', FILE_URL_PREFIX.length() - 1); 
     429            int q = fsRoot.indexOf('/', p + 1); 
     430            if(p != -1 && q != -1 && p < q) { 
     431                fsRoot = fsRoot.substring(p + 1, q + 1); 
     432            } 
     433             
     434            // Add the prefix 
     435            url = FILE_URL_PREFIX + fsRoot; 
     436             
     437            // Append the necessary elements, creating directories as necessary 
     438            if(url.indexOf("Card/") != -1) { 
     439                try { 
     440                    FileConnection conn = (FileConnection)Connector.open(url + "BlackBerry/"); 
     441                    if(!conn.exists()) { conn.mkdir(); } 
     442                    url = conn.getURL(); conn.close(); 
     443                     
     444                    conn = (FileConnection)Connector.open(url + "logicmail/"); 
     445                    if(!conn.exists()) { conn.mkdir(); } 
     446                    url = conn.getURL(); conn.close(); 
     447                } catch (IOException e) { 
     448                    url = null; 
     449                } 
     450            } 
     451            else if(url.indexOf("store/") != -1) { 
     452                try { 
     453                    FileConnection conn = (FileConnection)Connector.open(url + "home/"); 
     454                    if(!conn.exists()) { conn.mkdir(); } 
     455                    url = conn.getURL(); conn.close(); 
     456                     
     457                    conn = (FileConnection)Connector.open(url + "user/"); 
     458                    if(!conn.exists()) { conn.mkdir(); } 
     459                    url = conn.getURL(); conn.close(); 
     460                     
     461                    conn = (FileConnection)Connector.open(url + "logicmail/"); 
     462                    if(!conn.exists()) { conn.mkdir(); } 
     463                    url = conn.getURL(); conn.close(); 
     464                } catch (IOException e) { 
     465                    url = null; 
     466                } 
     467            } 
     468            else { 
     469                try { 
     470                    FileConnection conn = (FileConnection)Connector.open(url + "logicmail/"); 
     471                    if(!conn.exists()) { conn.mkdir(); } 
     472                    url = conn.getURL(); conn.close(); 
     473                } catch (IOException e) { 
     474                    url = null; 
     475                } 
     476            } 
     477        } 
     478        else { 
     479            url = null; 
     480        } 
     481        return url; 
     482    } 
    413483} 
  • trunk/LogicMail/src/org/logicprobe/LogicMail/ui/GlobalConfigScreen.java

    r555 r561  
    3131package org.logicprobe.LogicMail.ui; 
    3232 
    33 import java.util.Enumeration; 
    34 import java.util.Vector; 
    35  
    36 import javax.microedition.io.file.FileSystemRegistry; 
    37  
    3833import net.rim.device.api.i18n.Locale; 
    3934import net.rim.device.api.ui.Field; 
     
    4540 
    4641import org.logicprobe.LogicMail.LogicMailResource; 
     42import org.logicprobe.LogicMail.PlatformInfo; 
    4743import org.logicprobe.LogicMail.conf.GlobalConfig; 
    4844import org.logicprobe.LogicMail.conf.MailSettings; 
     
    5854    private String[] languageCodes; 
    5955    private String[] fileSystemRoots; 
     56    private String[] fileSystemRootChoices; 
    6057    private int selectedFileSystemRootIndex; 
    61  
    62     private static String LOCAL_FILE_BASE = "LogicMail/"; 
    6358 
    6459    private ObjectChoiceField languageChoiceField; 
     
    8782                "Deutsch",      // German: de 
    8883                "English",      // English: en 
    89                 "Espa\u00f1ol",      // Spanish: es 
    90                 "Fran\u00e7ais",     // French: fr 
     84                "Espa\u00f1ol", // Spanish: es 
     85                "Fran\u00e7ais",// French: fr 
    9186                "Italiano",     // Italian: it 
    9287                "Nederlands",   // Dutch: nl 
     
    9590        }; 
    9691        languageCodes = new String[] { 
    97                 "", // System default 
     92                "",   // System default 
    9893                "da", // Danish 
    9994                "de", // German 
     
    108103 
    109104        // Populate fileSystemRoots with a list of all 
    110         // available storage devices 
    111         Vector resultsVector = new Vector(); 
     105        // available and writable storage devices 
    112106        String selectedFileSystemRoot = existingConfig.getLocalDataLocation(); 
    113         int i = 0; 
    114107        selectedFileSystemRootIndex = 0; 
    115         Enumeration e = FileSystemRegistry.listRoots(); 
    116         while(e.hasMoreElements()) { 
    117             String root = (String)e.nextElement(); 
    118             if(selectedFileSystemRoot.endsWith(root + LOCAL_FILE_BASE)) { 
     108         
     109        fileSystemRoots = PlatformInfo.getInstance().getFilesystemRoots(); 
     110        fileSystemRootChoices = new String[fileSystemRoots.length + 1]; 
     111        for(int i=0; i<fileSystemRoots.length; i++) { 
     112            String root = fileSystemRoots[i]; 
     113            if(selectedFileSystemRoot != null && selectedFileSystemRoot.indexOf(root) != -1) { 
    119114                selectedFileSystemRootIndex = i; 
    120115            } 
    121             resultsVector.addElement(root); 
    122             i++; 
    123         } 
    124         fileSystemRoots = new String[resultsVector.size()]; 
    125         resultsVector.copyInto(fileSystemRoots); 
    126  
     116            if(root.indexOf("Card/") != -1) { 
     117                fileSystemRootChoices[i] = 
     118                    resources.getString(LogicMailResource.CONFIG_GLOBAL_LOCAL_DATA_MEDIA_CARD); 
     119            } 
     120            else if(root.indexOf("store/") != -1) { 
     121                fileSystemRootChoices[i] = 
     122                    resources.getString(LogicMailResource.CONFIG_GLOBAL_LOCAL_DATA_DEVICE_MEMORY); 
     123            } 
     124            else { 
     125                int p = root.indexOf('/', GlobalConfig.FILE_URL_PREFIX.length() - 1); 
     126                int q = root.indexOf('/', p + 1); 
     127                if(p != -1 && q != -1 && p < q) { 
     128                    fileSystemRootChoices[i] = root.substring(p + 1, q); 
     129                } 
     130                else { 
     131                    fileSystemRootChoices[i] = root; 
     132                } 
     133            } 
     134        } 
     135        fileSystemRootChoices[fileSystemRootChoices.length - 1] = 
     136            resources.getString(LogicMailResource.CONFIG_GLOBAL_LOCAL_DATA_DISABLED); 
     137        if(selectedFileSystemRoot == null) { 
     138            selectedFileSystemRootIndex = fileSystemRootChoices.length - 1; 
     139        } 
     140         
    127141        initFields(); 
    128142    } 
     
    191205        localDataLocationChoiceLabel = new ObjectChoiceField( 
    192206                resources.getString(LogicMailResource.CONFIG_GLOBAL_LOCAL_DATA_LOCATION) + ' ', 
    193                 fileSystemRoots, 
     207                fileSystemRootChoices, 
    194208                selectedFileSystemRootIndex); 
    195209 
     
    288302        config.setWifiMode(wifiModeChoiceField.getSelectedIndex()); 
    289303 
    290         String url = "file:///" + fileSystemRoots[localDataLocationChoiceLabel.getSelectedIndex()] + LOCAL_FILE_BASE; 
     304        int fsRootIndex = localDataLocationChoiceLabel.getSelectedIndex(); 
     305        String url; 
     306        if(fsRootIndex > fileSystemRoots.length) { 
     307            url = null; 
     308        } 
     309        else { 
     310            url = fileSystemRoots[fsRootIndex]; 
     311        } 
    291312        config.setLocalDataLocation(url); 
    292313 
Note: See TracChangeset for help on using the changeset viewer.