Changeset 561
- Timestamp:
- 12/07/09 21:13:32 (2 years ago)
- Location:
- trunk/LogicMail
- Files:
-
- 4 edited
-
res/org/logicprobe/LogicMail/LogicMail.rrc (modified) (1 diff)
-
res/org/logicprobe/LogicMail/LogicMail.rrh (modified) (1 diff)
-
src/org/logicprobe/LogicMail/conf/GlobalConfig.java (modified) (18 diffs)
-
src/org/logicprobe/LogicMail/ui/GlobalConfigScreen.java (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/LogicMail/res/org/logicprobe/LogicMail/LogicMail.rrc
r555 r561 36 36 CONFIG_GLOBAL_HOSTNAME#0="Hostname:"; 37 37 CONFIG_GLOBAL_LANGUAGE#0="Language:"; 38 CONFIG_GLOBAL_LOCAL_DATA_DEVICE_MEMORY#0="Device Memory"; 39 CONFIG_GLOBAL_LOCAL_DATA_DISABLED#0="Disabled"; 38 40 CONFIG_GLOBAL_LOCAL_DATA_LOCATION#0="Local data location:"; 41 CONFIG_GLOBAL_LOCAL_DATA_MEDIA_CARD#0="Media Card"; 39 42 CONFIG_GLOBAL_MESSAGE_COUNT#0="Message count:"; 40 43 CONFIG_GLOBAL_MESSAGE_FORMAT#0="Preferred message format:"; -
trunk/LogicMail/res/org/logicprobe/LogicMail/LogicMail.rrh
r555 r561 181 181 CONFIG_GLOBAL_SECTION_NETWORKING#0=182; 182 182 CONFIG_GLOBAL_SECTION_OTHER#0=183; 183 CONFIG_GLOBAL_LOCAL_DATA_DISABLED#0=184; 184 CONFIG_GLOBAL_LOCAL_DATA_MEDIA_CARD#0=185; 185 CONFIG_GLOBAL_LOCAL_DATA_DEVICE_MEMORY#0=186; -
trunk/LogicMail/src/org/logicprobe/LogicMail/conf/GlobalConfig.java
r518 r561 31 31 package org.logicprobe.LogicMail.conf; 32 32 33 import org.logicprobe.LogicMail.PlatformInfo; 33 34 import org.logicprobe.LogicMail.util.Serializable; 34 35 import org.logicprobe.LogicMail.util.SerializableHashtable; … … 38 39 import java.io.DataOutput; 39 40 import java.io.IOException; 40 import java.util.Enumeration; 41 42 import javax.microedition.io.file.FileSystemRegistry; 43 41 42 import javax.microedition.io.Connector; 43 import javax.microedition.io.file.FileConnection; 44 44 45 45 /** … … 57 57 /** Always use WiFi */ 58 58 final public static int WIFI_ALWAYS = 2; 59 59 60 60 /** Prefer plain text display for messages */ 61 61 final public static int MESSAGE_DISPLAY_PLAIN_TEXT = 0; 62 62 63 63 /** Prefer HTML display for messages */ 64 64 final public static int MESSAGE_DISPLAY_HTML = 1; 65 65 66 66 /** language code to use for the UI, or null for system default */ 67 67 private String languageCode; 68 68 69 69 /** true to enable Unicode normalization */ 70 70 private boolean unicodeNormalization; … … 72 72 /** Preferred message display format */ 73 73 private int messageDisplayFormat; 74 74 75 75 /** Number of message headers to retrieve */ 76 76 private int retMsgCount; … … 81 81 /** Root URL for local file storage */ 82 82 private String localDataLocation; 83 83 84 84 /** Mode for WiFi support */ 85 85 private int wifiMode; … … 94 94 private String localHostname; 95 95 96 public static String FILE_URL_PREFIX = "file:///"; 97 96 98 /** 97 99 * Instantiates a new global configuration. … … 127 129 this.hideDeletedMsg = true; 128 130 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 139 134 /** 140 135 * Sets the language code. … … 145 140 this.languageCode = languageCode; 146 141 } 147 142 148 143 /** 149 144 * Gets the language code. … … 154 149 return languageCode; 155 150 } 156 151 157 152 /** 158 153 * Sets whether unicode normalization is enabled. … … 163 158 this.unicodeNormalization = unicodeNormalization; 164 159 } 165 160 166 161 /** 167 162 * Gets whether unicode normalization is enabled. … … 179 174 */ 180 175 public void setMessageDisplayFormat(int messageDisplayFormat) { 181 this.messageDisplayFormat = messageDisplayFormat;182 } 183 176 this.messageDisplayFormat = messageDisplayFormat; 177 } 178 184 179 /** 185 180 * Gets the preferred message display format. … … 188 183 */ 189 184 public int getMessageDisplayFormat() { 190 return messageDisplayFormat;191 } 192 185 return messageDisplayFormat; 186 } 187 193 188 /** 194 189 * Set the number of message headers to retrieve. … … 233 228 */ 234 229 public void setLocalDataLocation(String localDataLocation) { 235 this.localDataLocation = localDataLocation;236 } 237 230 this.localDataLocation = validateLocalDataLocation(localDataLocation); 231 } 232 238 233 /** 239 234 * Set the root URL for local file storage. … … 242 237 */ 243 238 public String getLocalDataLocation() { 244 return localDataLocation;239 return localDataLocation; 245 240 } 246 241 … … 324 319 325 320 SerializableHashtable table = new SerializableHashtable(); 326 321 327 322 table.put("global_languageCode", languageCode); 328 323 table.put("global_unicodeNormalization", new Boolean(unicodeNormalization)); … … 355 350 languageCode = (String)value; 356 351 } 357 352 358 353 value = table.get("global_unicodeNormalization"); 359 354 if(value != null && value instanceof Boolean) { 360 355 unicodeNormalization = ((Boolean)value).booleanValue(); 361 356 } 362 357 363 358 value = table.get("global_messageDisplayFormat"); 364 359 if ((value != null) && value instanceof Integer) { 365 messageDisplayFormat = ((Integer) value).intValue();366 } 367 360 messageDisplayFormat = ((Integer) value).intValue(); 361 } 362 368 363 value = table.get("global_retMsgCount"); 369 364 if ((value != null) && value instanceof Integer) { … … 378 373 value = table.get("global_localDataLocation"); 379 374 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 383 384 value = table.get("global_wifiMode"); 384 385 if ((value != null) && value instanceof Integer) { … … 411 412 return uniqueId; 412 413 } 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 } 413 483 } -
trunk/LogicMail/src/org/logicprobe/LogicMail/ui/GlobalConfigScreen.java
r555 r561 31 31 package org.logicprobe.LogicMail.ui; 32 32 33 import java.util.Enumeration;34 import java.util.Vector;35 36 import javax.microedition.io.file.FileSystemRegistry;37 38 33 import net.rim.device.api.i18n.Locale; 39 34 import net.rim.device.api.ui.Field; … … 45 40 46 41 import org.logicprobe.LogicMail.LogicMailResource; 42 import org.logicprobe.LogicMail.PlatformInfo; 47 43 import org.logicprobe.LogicMail.conf.GlobalConfig; 48 44 import org.logicprobe.LogicMail.conf.MailSettings; … … 58 54 private String[] languageCodes; 59 55 private String[] fileSystemRoots; 56 private String[] fileSystemRootChoices; 60 57 private int selectedFileSystemRootIndex; 61 62 private static String LOCAL_FILE_BASE = "LogicMail/";63 58 64 59 private ObjectChoiceField languageChoiceField; … … 87 82 "Deutsch", // German: de 88 83 "English", // English: en 89 "Espa\u00f1ol", // Spanish: es90 "Fran\u00e7ais", // French: fr84 "Espa\u00f1ol", // Spanish: es 85 "Fran\u00e7ais",// French: fr 91 86 "Italiano", // Italian: it 92 87 "Nederlands", // Dutch: nl … … 95 90 }; 96 91 languageCodes = new String[] { 97 "", // System default92 "", // System default 98 93 "da", // Danish 99 94 "de", // German … … 108 103 109 104 // Populate fileSystemRoots with a list of all 110 // available storage devices 111 Vector resultsVector = new Vector(); 105 // available and writable storage devices 112 106 String selectedFileSystemRoot = existingConfig.getLocalDataLocation(); 113 int i = 0;114 107 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) { 119 114 selectedFileSystemRootIndex = i; 120 115 } 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 127 141 initFields(); 128 142 } … … 191 205 localDataLocationChoiceLabel = new ObjectChoiceField( 192 206 resources.getString(LogicMailResource.CONFIG_GLOBAL_LOCAL_DATA_LOCATION) + ' ', 193 fileSystemRoot s,207 fileSystemRootChoices, 194 208 selectedFileSystemRootIndex); 195 209 … … 288 302 config.setWifiMode(wifiModeChoiceField.getSelectedIndex()); 289 303 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 } 291 312 config.setLocalDataLocation(url); 292 313
Note: See TracChangeset
for help on using the changeset viewer.
