Changeset 445


Ignore:
Timestamp:
05/30/09 14:33:31 (3 years ago)
Author:
octorian
Message:

Manual language selection, initial Vietnamese translation (very rough), QP decoding fix, and Unicode normalizer integration with mappings for Vietnamese

Location:
branches/LogicMail-1.1/LogicMail
Files:
2 added
12 edited

Legend:

Unmodified
Added
Removed
  • branches/LogicMail-1.1/LogicMail/LogicMail.jdp

    r419 r445  
    5252src\org\logicprobe\LogicMail\LogicMail_fr.rrc 
    5353src\org\logicprobe\LogicMail\LogicMail_nl.rrc 
     54src\org\logicprobe\LogicMail\LogicMail_vi.rrc 
    5455src\org\logicprobe\LogicMail\LogicMail_zh.rrc 
    5556src\org\logicprobe\LogicMail\LogicMail_zh_CN.rrc 
     
    116117src\org\logicprobe\LogicMail\util\StringFactory.java 
    117118src\org\logicprobe\LogicMail\util\StringParser.java 
     119src\org\logicprobe\LogicMail\util\UnicodeNormalizer.java 
    118120src\org\logicprobe\LogicMail\util\UniqueIdGenerator.java 
    119121src\org\logicprobe\LogicMail\util\UtilProxy.java 
  • branches/LogicMail-1.1/LogicMail/src/org/logicprobe/LogicMail/LogicMail.java

    r423 r445  
    3333 
    3434import java.util.Calendar; 
     35 
     36import net.rim.device.api.i18n.Locale; 
    3537import net.rim.device.api.system.EventLogger; 
    3638import net.rim.device.api.ui.UiApplication; 
     
    5860        MailSettings.getInstance().loadSettings(); 
    5961 
     62        // Set the language, if configured 
     63        String languageCode = 
     64            MailSettings.getInstance().getGlobalConfig().getLanguageCode(); 
     65        if(languageCode != null) { 
     66            try { 
     67                Locale.setDefault(Locale.get(languageCode)); 
     68            } catch (Exception e) { } 
     69        } 
     70         
    6071        // Log application startup information 
    6172        if(EventLogger.getMinimumLevel() >= EventLogger.INFORMATION) { 
  • branches/LogicMail-1.1/LogicMail/src/org/logicprobe/LogicMail/LogicMail.rrc

    r444 r445  
    3737CONFIG_GLOBAL_HOSTNAME#0="Hostname:"; 
    3838CONFIG_GLOBAL_IMAP_SETTINGS#0="IMAP settings:"; 
     39CONFIG_GLOBAL_LANGUAGE#0="Language:"; 
    3940CONFIG_GLOBAL_LOCAL_DATA_LOCATION#0="Local data location:"; 
    4041CONFIG_GLOBAL_MESSAGE_COUNT#0="Message count:"; 
     
    4445CONFIG_GLOBAL_SETTINGS#0="Global settings"; 
    4546CONFIG_GLOBAL_TITLE#0="Global"; 
     47CONFIG_GLOBAL_UNICODE_NORMALIZATION#0="Unicode normalization"; 
    4648CONFIG_GLOBAL_WIFI_MODE#0="WiFi mode:"; 
    4749CONFIG_IDENTITIES#0="Identities"; 
  • branches/LogicMail-1.1/LogicMail/src/org/logicprobe/LogicMail/LogicMail.rrh

    r444 r445  
    141141MAILCLIENT_STATUS_AUTHENTICATION_FAILURE#0=166; 
    142142MAILCLIENT_STATUS_UNABLE_TO_CONNECT_TO_SERVER#0=168; 
     143CONFIG_GLOBAL_LANGUAGE#0=169; 
     144CONFIG_GLOBAL_UNICODE_NORMALIZATION#0=170; 
  • branches/LogicMail-1.1/LogicMail/src/org/logicprobe/LogicMail/conf/GlobalConfig.java

    r287 r445  
    4444public class GlobalConfig implements Serializable { 
    4545    private long uniqueId; 
     46    /** language code to use for the UI, or null for system default */ 
     47    private String languageCode; 
     48    /** true to enable Unicode normalization */ 
     49    private boolean unicodeNormalization; 
    4650    /** number of message headers to retrieve */ 
    4751    private int retMsgCount; 
    48     /** true for ascending, false for decending */ 
     52    /** true for ascending, false for descending */ 
    4953    private boolean dispOrder; 
    5054    /** IMAP: maximum message size */ 
     
    8589    private void setDefaults() { 
    8690        uniqueId = UniqueIdGenerator.getInstance().getUniqueId(); 
     91        this.languageCode = ""; 
     92        this.unicodeNormalization = false; 
    8793        this.retMsgCount = 30; 
    8894        this.dispOrder = false; 
     
    95101    } 
    96102     
     103    public void setLanguageCode(String languageCode) { 
     104        this.languageCode = languageCode; 
     105    } 
     106     
     107    public String getLanguageCode() { 
     108        return languageCode; 
     109    } 
     110     
     111    public void setUnicodeNormalization(boolean unicodeNormalization) { 
     112        this.unicodeNormalization = unicodeNormalization; 
     113    } 
     114     
     115    public boolean getUnicodeNormalization() { 
     116        return unicodeNormalization; 
     117    } 
     118     
    97119    public void setRetMsgCount(int retMsgCount) { 
    98120        this.retMsgCount = retMsgCount; 
     
    172194        SerializableHashtable table = new SerializableHashtable(); 
    173195         
     196        table.put("global_languageCode", languageCode); 
     197        table.put("global_unicodeNormalization", new Boolean(unicodeNormalization)); 
    174198        table.put("global_retMsgCount", new Integer(retMsgCount)); 
    175199        table.put("global_dispOrder", new Boolean(dispOrder)); 
     
    193217        Object value; 
    194218 
     219        value = table.get("global_languageCode"); 
     220        if(value != null && value instanceof String) { 
     221            languageCode = (String)value; 
     222        } 
     223        value = table.get("global_unicodeNormalization"); 
     224        if(value != null && value instanceof Boolean) { 
     225            unicodeNormalization = ((Boolean)value).booleanValue(); 
     226        } 
    195227        value = table.get("global_retMsgCount"); 
    196228        if(value != null && value instanceof Integer) { 
  • branches/LogicMail-1.1/LogicMail/src/org/logicprobe/LogicMail/message/MessagePartFactory.java

    r397 r445  
    3333import net.rim.device.api.system.EncodedImage; 
    3434 
     35import org.logicprobe.LogicMail.conf.MailSettings; 
    3536import org.logicprobe.LogicMail.util.StringParser; 
    3637import org.logicprobe.LogicMail.util.StringFactory; 
     38import org.logicprobe.LogicMail.util.UnicodeNormalizer; 
    3739import org.logicprobe.LogicMail.util.UtilProxy; 
    3840 
     
    98100    private static MessagePart createTextPart(String mimeSubtype, 
    99101        String encoding, String charset, String data) { 
     102 
     103        UnicodeNormalizer unicodeNormalizer; 
     104        if(MailSettings.getInstance().getGlobalConfig().getUnicodeNormalization()) { 
     105            unicodeNormalizer = UnicodeNormalizer.getInstance(); 
     106        } 
     107        else { 
     108            unicodeNormalizer = null; 
     109        } 
     110         
    100111        // Check for any encodings that need to be handled 
    101112        if (encoding.equalsIgnoreCase("quoted-printable")) { 
     
    141152        } 
    142153 
     154        // The last step is to run the Unicode normalizer, if enabled 
     155        if(unicodeNormalizer != null) { 
     156            // If the encoding type is QP, then we need to do another 
     157            // charset juggle to make sure that the data is using the, 
     158            // right characters instead of ISO-8859-1 characters 
     159            if(encoding.equalsIgnoreCase("quoted-printable")) { 
     160                try{ 
     161                    byte[] encodedBytes = data.getBytes(); 
     162                    data = new String(encodedBytes, charset); 
     163                } catch(Exception e){} 
     164            } 
     165            data = unicodeNormalizer.normalize(data); 
     166        } 
     167         
    143168        // Check for a supported text sub-type and decode if necessary 
    144169        if (mimeSubtype.equalsIgnoreCase("plain")) { 
  • branches/LogicMail-1.1/LogicMail/src/org/logicprobe/LogicMail/ui/BaseScreen.java

    r423 r445  
    4040import org.logicprobe.LogicMail.AppInfo; 
    4141import org.logicprobe.LogicMail.LogicMailResource; 
     42import org.logicprobe.LogicMail.conf.MailSettings; 
    4243import org.logicprobe.LogicMail.util.Connection; 
     44import org.logicprobe.LogicMail.util.UnicodeNormalizer; 
    4345 
    4446 
     
    5052public abstract class BaseScreen extends MainScreen { 
    5153        protected static ResourceBundle resources = ResourceBundle.getBundle(LogicMailResource.BUNDLE_ID, LogicMailResource.BUNDLE_NAME); 
     54    private UnicodeNormalizer unicodeNormalizer; 
    5255    private HeaderField headerField; 
    5356     
     
    9699    public BaseScreen() { 
    97100        super(); 
     101         
     102        if(MailSettings.getInstance().getGlobalConfig().getUnicodeNormalization()) { 
     103            unicodeNormalizer = UnicodeNormalizer.getInstance(); 
     104        } 
    98105    } 
    99106 
     
    104111        headerField = new HeaderField("LogicMail - " + title); 
    105112        setTitle(headerField); 
     113 
     114        if(MailSettings.getInstance().getGlobalConfig().getUnicodeNormalization()) { 
     115            unicodeNormalizer = UnicodeNormalizer.getInstance(); 
     116        } 
    106117    } 
    107118 
     
    132143        return true; 
    133144    } 
     145     
     146    /** 
     147     * Run the Unicode normalizer on the provide string, 
     148     * only if normalization is enabled in the configuration. 
     149     * If normalization is disabled, this method returns 
     150     * the input unmodified. 
     151     *  
     152     * @param input Input string 
     153     * @return Normalized string 
     154     */ 
     155    protected String normalize(String input) { 
     156        if(unicodeNormalizer == null) { 
     157            return input; 
     158        } 
     159        else { 
     160            return unicodeNormalizer.normalize(input); 
     161        } 
     162    } 
    134163} 
  • branches/LogicMail-1.1/LogicMail/src/org/logicprobe/LogicMail/ui/CompositionScreen.java

    r444 r445  
    124124 
    125125        // Set the subject 
    126         fldSubject.setText(env.subject); 
     126        fldSubject.setText(normalize(env.subject)); 
    127127         
    128128        // Set the recipients 
     
    130130            for(i=0; i<env.to.length; i++) { 
    131131                if(env.to[i].indexOf('@') != -1) { 
    132                     insertRecipientField(EmailAddressBookEditField.ADDRESS_TO).setAddress(env.to[i]); 
     132                    insertRecipientField(EmailAddressBookEditField.ADDRESS_TO).setAddress(normalize(env.to[i])); 
    133133                } 
    134134            } 
     
    137137            for(i=0; i<env.cc.length; i++) { 
    138138                if(env.cc[i].indexOf('@') != -1) { 
    139                     insertRecipientField(EmailAddressBookEditField.ADDRESS_CC).setAddress(env.cc[i]); 
     139                    insertRecipientField(EmailAddressBookEditField.ADDRESS_CC).setAddress(normalize(env.cc[i])); 
    140140                } 
    141141            } 
     
    144144            for(i=0; i<env.bcc.length; i++) { 
    145145                if(env.bcc[i].indexOf('@') != -1) { 
    146                     insertRecipientField(EmailAddressBookEditField.ADDRESS_BCC).setAddress(env.bcc[i]); 
     146                    insertRecipientField(EmailAddressBookEditField.ADDRESS_BCC).setAddress(normalize(env.bcc[i])); 
    147147                } 
    148148            } 
  • branches/LogicMail-1.1/LogicMail/src/org/logicprobe/LogicMail/ui/GlobalConfigScreen.java

    r444 r445  
    3232package org.logicprobe.LogicMail.ui; 
    3333 
     34import net.rim.device.api.i18n.Locale; 
    3435import net.rim.device.api.ui.Field; 
    3536import net.rim.device.api.ui.FieldChangeListener; 
     
    5051public class GlobalConfigScreen extends BaseCfgScreen implements FieldChangeListener { 
    5152    private MailSettings mailSettings; 
     53    private ObjectChoiceField fldLanguage; 
     54    private CheckboxField fldUnicodeNormalization; 
    5255    private BasicEditField fldRetMsgCount; 
    5356    private ObjectChoiceField fldDispOrder; 
     
    6366    private String localHostname; 
    6467 
     68    private String[] languageChoices; 
     69    private String[] languageCodes; 
     70     
    6571    public GlobalConfigScreen() { 
    6672        super("LogicMail - " + 
     
    7278         
    7379        add(new RichTextField(resources.getString(LogicMailResource.CONFIG_GLOBAL_GLOBAL_SETTINGS), Field.NON_FOCUSABLE)); 
     80 
     81        languageChoices = new String[] { 
     82                "BlackBerry", // System default 
     83                "Dansk",        // Danish: da 
     84                "Deutsch",      // German: de 
     85                "English",      // English: en 
     86                "Español",      // Spanish: es 
     87                "Français",     // French: fr 
     88                "Nederlands",   // Dutch: nl 
     89                "Ti\u00ea\u0301ng Vi\u00ea\u0323t", // Vietnamese: vi 
     90                "\u4E2D\u6587", // Chinese: zh 
     91        }; 
     92        languageCodes = new String[] { 
     93                "", // System default 
     94                "da", // Danish 
     95                "de", // German 
     96                "en", // English 
     97                "es", // Spanish 
     98                "fr", // French 
     99                "nl", // Dutch 
     100                "vi", // Vietnamese 
     101                "zh", // Chinese 
     102        }; 
     103         
     104        String languageCode = config.getLanguageCode(); 
     105        int languageIndex = 0; 
     106        if(languageCode != null && languageCode.length() != 0) { 
     107            for(int i=0; i<languageCodes.length; i++) { 
     108                if(languageCodes[i].equals(languageCode)) { 
     109                    languageIndex = i; 
     110                    break; 
     111                } 
     112            } 
     113        } 
     114         
     115        fldLanguage = new ObjectChoiceField("  " + resources.getString(LogicMailResource.CONFIG_GLOBAL_LANGUAGE), languageChoices, languageIndex); 
     116        add(fldLanguage); 
     117         
     118        fldUnicodeNormalization = new CheckboxField(resources.getString(LogicMailResource.CONFIG_GLOBAL_UNICODE_NORMALIZATION), config.getUnicodeNormalization()); 
     119        add(fldUnicodeNormalization); 
    74120         
    75121        fldRetMsgCount = new BasicEditField("  " + resources.getString(LogicMailResource.CONFIG_GLOBAL_MESSAGE_COUNT) + ' ', 
     
    158204        GlobalConfig config = mailSettings.getGlobalConfig(); 
    159205 
     206        String languageCode = languageCodes[fldLanguage.getSelectedIndex()]; 
     207        if(languageCode != null && languageCode.length() != 0) { 
     208            try { 
     209                Locale.setDefault(Locale.get(languageCode)); 
     210                config.setLanguageCode(languageCode); 
     211            } catch (Exception e) { } 
     212        } 
     213        else { 
     214            Locale.setDefault(Locale.getDefault()); 
     215            config.setLanguageCode(""); 
     216        } 
     217         
     218        config.setUnicodeNormalization(fldUnicodeNormalization.getChecked()); 
     219         
    160220        try { 
    161221            config.setRetMsgCount(Integer.parseInt(fldRetMsgCount.getText())); 
  • branches/LogicMail-1.1/LogicMail/src/org/logicprobe/LogicMail/ui/MailboxScreen.java

    r444 r445  
    302302        else { 
    303303            if(env.from != null && env.from.length > 0) { 
    304                 graphics.drawText((String)env.from[0], 20, y, 
     304                graphics.drawText(normalize(env.from[0]), 20, y, 
    305305                                  (int)(getStyle() | DrawStyle.ELLIPSIS), 
    306306                                   senderWidth); 
     
    309309        graphics.setFont(origFont.derive(Font.PLAIN)); 
    310310        if(env.subject != null) { 
    311             graphics.drawText((String)env.subject, 20, y+lineHeight, 
     311            graphics.drawText(normalize(env.subject), 20, y+lineHeight, 
    312312                              (int)(getStyle() | DrawStyle.ELLIPSIS), 
    313313                               maxWidth-20); 
  • branches/LogicMail-1.1/LogicMail/src/org/logicprobe/LogicMail/ui/MessageScreen.java

    r428 r445  
    9292        if(isSentFolder) { 
    9393            if(envelope.to != null && envelope.to.length > 0) { 
    94                 add(new RichTextField(resources.getString(LogicMailResource.MESSAGEPROPERTIES_TO) + ' ' + envelope.to[0])); 
     94                add(new RichTextField(resources.getString(LogicMailResource.MESSAGEPROPERTIES_TO) + ' ' + normalize(envelope.to[0]))); 
    9595                if(envelope.to.length > 1) { 
    9696                    for(int i=1;i<envelope.to.length;i++) { 
     
    104104        else { 
    105105            if(envelope.from != null && envelope.from.length > 0) { 
    106                 add(new RichTextField(resources.getString(LogicMailResource.MESSAGEPROPERTIES_FROM) + ' ' + envelope.from[0])); 
     106                add(new RichTextField(resources.getString(LogicMailResource.MESSAGEPROPERTIES_FROM) + ' ' + normalize(envelope.from[0]))); 
    107107                if(envelope.from.length > 1) { 
    108108                    for(int i=1;i<envelope.from.length;i++) { 
    109109                        if(envelope.from[i] != null) { 
    110                             add(new RichTextField("      " + envelope.from[i])); 
     110                            add(new RichTextField("      " + normalize(envelope.from[i]))); 
    111111                        } 
    112112                    } 
     
    115115        } 
    116116        if(envelope.subject != null) { 
    117             add(new RichTextField(resources.getString(LogicMailResource.MESSAGEPROPERTIES_SUBJECT) + ' ' + envelope.subject)); 
     117            add(new RichTextField(resources.getString(LogicMailResource.MESSAGEPROPERTIES_SUBJECT) + ' ' + normalize(envelope.subject))); 
    118118        } 
    119119        add(new SeparatorField()); 
  • branches/LogicMail-1.1/LogicMail/src/org/logicprobe/LogicMail/util/StringParser.java

    r384 r445  
    769769                } 
    770770            } 
     771            else if(text.charAt(index) == '_') { 
     772                buffer.append(' '); 
     773                index++; 
     774            } 
    771775            else { 
    772776                buffer.append(text.charAt(index)); 
Note: See TracChangeset for help on using the changeset viewer.