Changeset 628


Ignore:
Timestamp:
02/03/10 16:58:22 (2 years ago)
Author:
octorian
Message:

Integration of better configuration change notifications (#175)

Location:
trunk/LogicMail/src/org/logicprobe/LogicMail
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LogicMail/src/org/logicprobe/LogicMail/conf/GlobalConfig.java

    r627 r628  
    5252    /** Global network settings. */ 
    5353    public static final int CHANGE_TYPE_NETWORK = 0x01; 
     54    /** Global data storage settings. */ 
     55    public static final int CHANGE_TYPE_DATA = 0x02; 
    5456    /** Global other settings. */ 
    55     public static final int CHANGE_TYPE_OTHER = 0x02; 
     57    public static final int CHANGE_TYPE_OTHER = 0x04; 
    5658 
    5759    /** Prefer plain text display for messages */ 
     
    236238        if(!this.localDataLocation.equals(localDataLocation)) { 
    237239            this.localDataLocation = validateLocalDataLocation(localDataLocation); 
    238             changeType |= CHANGE_TYPE_OTHER; 
     240            changeType |= CHANGE_TYPE_DATA; 
    239241        } 
    240242    } 
  • trunk/LogicMail/src/org/logicprobe/LogicMail/conf/ImapConfig.java

    r627 r628  
    7070        this.maxMessageSize = 32768; 
    7171        this.maxFolderDepth = 4; 
    72         this.folderPrefix = null; 
     72        this.folderPrefix = ""; 
    7373        this.onlySubscribedFolders = true; 
    7474    } 
     
    192192        if(value instanceof String) { 
    193193            folderPrefix = (String)value; 
    194             if(folderPrefix.length() == 0) { 
    195                 folderPrefix = null; 
    196             } 
    197194        } 
    198195        value = table.get("account_imap_maxMessageSize"); 
  • trunk/LogicMail/src/org/logicprobe/LogicMail/mail/imap/ImapClient.java

    r608 r628  
    7272 */ 
    7373public class ImapClient implements IncomingMailClient { 
     74    private MailSettings mailSettings; 
    7475    private ImapConfig accountConfig; 
    7576    private Connection connection; 
     
    126127    public ImapClient(GlobalConfig globalConfig, ImapConfig accountConfig) { 
    127128        this.accountConfig = accountConfig; 
     129        this.mailSettings = MailSettings.getInstance(); 
    128130        connection = UtilFactory.getInstance().createConnection(accountConfig); 
    129131        imapProtocol = new ImapProtocol(connection); 
     
    132134        openStarted = false; 
    133135        configChanged = false; 
    134         MailSettings.getInstance().addMailSettingsListener(mailSettingsListener); 
     136        mailSettings.addMailSettingsListener(mailSettingsListener); 
    135137    } 
    136138 
     
    142144 
    143145    private void mailSettings_MailSettingsSaved(MailSettingsEvent e) { 
    144         if(MailSettings.getInstance().containsAccountConfig(accountConfig)) { 
     146        // Check for a list change, where we no longer exist afterwards 
     147        if((e.getListChange() & MailSettingsEvent.LIST_CHANGED_ACCOUNT) != 0 
     148                && !mailSettings.containsAccountConfig(accountConfig)) { 
     149            // We have been deleted, so unregister to make sure we 
     150            // no longer affect the system and can be garbage collected. 
     151            mailSettings.removeMailSettingsListener(mailSettingsListener); 
     152        } 
     153 
     154        // Check for a change to the global or account network settings 
     155        if((e.getGlobalChange() & GlobalConfig.CHANGE_TYPE_NETWORK) != 0 
     156                || (e.getConfigChange(accountConfig) & AccountConfig.CHANGE_TYPE_CONNECTION) != 0) { 
    145157            // Refresh authentication information from the configuration 
    146158            username = accountConfig.getServerUser(); 
     
    157169                configChanged = true; 
    158170            } 
    159         } 
    160         else { 
    161             // We have been deleted, so unregister to make sure we 
    162             // no longer affect the system and can be garbage collected. 
    163             MailSettings.getInstance().removeMailSettingsListener(mailSettingsListener); 
    164171        } 
    165172    } 
     
    694701 
    695702        if(!seenMailboxes.containsKey(activeMailbox)) { 
    696             int count = MailSettings.getInstance().getGlobalConfig().getRetMsgCount(); 
     703            int count = mailSettings.getGlobalConfig().getRetMsgCount(); 
    697704            int msgCount = activeMailbox.getMsgCount(); 
    698705            int firstIndex = Math.max(1, msgCount - count); 
  • trunk/LogicMail/src/org/logicprobe/LogicMail/mail/pop/PopClient.java

    r608 r628  
    6868 */ 
    6969public class PopClient implements IncomingMailClient { 
     70    private MailSettings mailSettings; 
    7071    private GlobalConfig globalConfig; 
    7172    private PopConfig accountConfig; 
     
    9394        this.globalConfig = globalConfig; 
    9495        this.accountConfig = accountConfig; 
     96        this.mailSettings = MailSettings.getInstance(); 
    9597        connection = UtilFactory.getInstance().createConnection(accountConfig); 
    9698        popProtocol = new PopProtocol(connection); 
     
    103105        openStarted = false; 
    104106        configChanged = false; 
    105         MailSettings.getInstance().addMailSettingsListener(mailSettingsListener); 
     107        mailSettings.addMailSettingsListener(mailSettingsListener); 
    106108    } 
    107109 
     
    113115     
    114116    private void mailSettings_MailSettingsSaved(MailSettingsEvent e) { 
    115                 if(MailSettings.getInstance().containsAccountConfig(accountConfig)) { 
    116                         // Refresh authentication information from the configuration 
    117                 username = accountConfig.getServerUser(); 
    118                 password = accountConfig.getServerPass(); 
    119                  
    120                 if(!isConnected()) { 
    121                         // Rebuild the connection to include new settings 
    122                     connection = UtilFactory.getInstance().createConnection(accountConfig); 
    123                     popProtocol = new PopProtocol(connection); 
    124                 } 
    125                 else { 
    126                         // Set a flag to make sure we rebuild the Connection object 
    127                         // the next time we close the connection. 
    128                         configChanged = true; 
    129                 } 
    130                 } 
    131                 else { 
    132                         // We have been deleted, so unregister to make sure we 
    133                         // no longer affect the system and can be garbage collected. 
    134                         MailSettings.getInstance().removeMailSettingsListener(mailSettingsListener); 
    135                 } 
     117        // Check for a list change, where we no longer exist afterwards 
     118        if((e.getListChange() & MailSettingsEvent.LIST_CHANGED_ACCOUNT) != 0 
     119                && !mailSettings.containsAccountConfig(accountConfig)) { 
     120            // We have been deleted, so unregister to make sure we 
     121            // no longer affect the system and can be garbage collected. 
     122            mailSettings.removeMailSettingsListener(mailSettingsListener); 
     123        } 
     124 
     125        // Check for a change to the global or account network settings 
     126        if((e.getGlobalChange() & GlobalConfig.CHANGE_TYPE_NETWORK) != 0 
     127                || (e.getConfigChange(accountConfig) & AccountConfig.CHANGE_TYPE_CONNECTION) != 0) { 
     128            // Refresh authentication information from the configuration 
     129            username = accountConfig.getServerUser(); 
     130            password = accountConfig.getServerPass(); 
     131 
     132            if(!isConnected()) { 
     133                // Rebuild the connection to include new settings 
     134                connection = UtilFactory.getInstance().createConnection(accountConfig); 
     135                popProtocol = new PopProtocol(connection); 
     136            } 
     137            else { 
     138                // Set a flag to make sure we rebuild the Connection object 
     139                // the next time we close the connection. 
     140                configChanged = true; 
     141            } 
     142        } 
    136143    } 
    137144 
     
    435442     */ 
    436443    public void getNewFolderMessages(boolean flagsOnly, FolderMessageCallback callback, MailProgressHandler progressHandler) throws IOException, MailException { 
    437         int count = MailSettings.getInstance().getGlobalConfig().getRetMsgCount(); 
     444        int count = globalConfig.getRetMsgCount(); 
    438445                int msgCount = activeMailbox.getMsgCount(); 
    439446        int firstIndex = Math.max(1, msgCount - count); 
  • trunk/LogicMail/src/org/logicprobe/LogicMail/mail/smtp/SmtpClient.java

    r608 r628  
    5555 */ 
    5656public class SmtpClient implements OutgoingMailClient { 
     57    private MailSettings mailSettings; 
    5758    private GlobalConfig globalConfig; 
    5859    private OutgoingConfig outgoingConfig; 
     
    8081        this.globalConfig = globalConfig; 
    8182        this.outgoingConfig = outgoingConfig; 
     83        this.mailSettings = MailSettings.getInstance(); 
    8284        connection = UtilFactory.getInstance().createConnection(outgoingConfig); 
    8385        smtpProtocol = new SmtpProtocol(connection); 
     
    9395        openStarted = false; 
    9496        configChanged = false; 
    95         MailSettings.getInstance().addMailSettingsListener(mailSettingsListener); 
     97        mailSettings.addMailSettingsListener(mailSettingsListener); 
    9698    } 
    9799 
    98100    private void mailSettings_MailSettingsSaved(MailSettingsEvent e) { 
    99         if (MailSettings.getInstance().containsOutgoingConfig(outgoingConfig)) { 
     101        // Check for a list change, where we no longer exist afterwards 
     102        if((e.getListChange() & MailSettingsEvent.LIST_CHANGED_OUTGOING) != 0 
     103                && !mailSettings.containsOutgoingConfig(outgoingConfig)) { 
     104            // We have been deleted, so unregister to make sure we 
     105            // no longer affect the system and can be garbage collected. 
     106            mailSettings.removeMailSettingsListener(mailSettingsListener); 
     107        } 
     108 
     109        // Check for a change to the global or account network settings 
     110        if((e.getGlobalChange() & GlobalConfig.CHANGE_TYPE_NETWORK) != 0 
     111                || (e.getConfigChange(outgoingConfig) & OutgoingConfig.CHANGE_TYPE_CONNECTION) != 0) { 
    100112            // Refresh authentication information from the configuration 
    101113            username = outgoingConfig.getServerUser(); 
    102114            password = outgoingConfig.getServerPass(); 
    103115 
    104             if (!isConnected()) { 
     116            if(!isConnected()) { 
    105117                // Rebuild the connection to include new settings 
    106118                connection = UtilFactory.getInstance().createConnection(outgoingConfig); 
    107119                smtpProtocol = new SmtpProtocol(connection); 
    108             } else { 
     120            } 
     121            else { 
    109122                // Set a flag to make sure we rebuild the Connection object 
    110123                // the next time we close the connection. 
    111124                configChanged = true; 
    112125            } 
    113         } else { 
    114             // We have been deleted, so unregister to make sure we 
    115             // no longer affect the system and can be garbage collected. 
    116             MailSettings.getInstance().removeMailSettingsListener(mailSettingsListener); 
    117126        } 
    118127    } 
  • trunk/LogicMail/src/org/logicprobe/LogicMail/model/MailFileManager.java

    r586 r628  
    4545 
    4646import org.logicprobe.LogicMail.AppInfo; 
     47import org.logicprobe.LogicMail.conf.GlobalConfig; 
    4748import org.logicprobe.LogicMail.conf.MailSettings; 
    4849import org.logicprobe.LogicMail.conf.MailSettingsEvent; 
     
    6970         * Instantiates a new mail file manager. 
    7071         */ 
    71         private MailFileManager() { 
    72                 mailSettings = MailSettings.getInstance(); 
    73                  
    74                 // Register a listener for configuration changes 
    75                 mailSettings.addMailSettingsListener(new MailSettingsListener() { 
    76                         public void mailSettingsSaved(MailSettingsEvent e) { 
    77                                 refreshConfiguration(); 
    78                         } 
    79                 }); 
    80                  
    81                 refreshConfiguration(); 
    82         } 
     72    private MailFileManager() { 
     73        mailSettings = MailSettings.getInstance(); 
     74 
     75        // Register a listener for configuration changes 
     76        mailSettings.addMailSettingsListener(new MailSettingsListener() { 
     77            public void mailSettingsSaved(MailSettingsEvent e) { 
     78                if((e.getGlobalChange() & GlobalConfig.CHANGE_TYPE_DATA) != 0) { 
     79                    refreshConfiguration(); 
     80                } 
     81            } 
     82        }); 
     83 
     84        refreshConfiguration(); 
     85    } 
    8386         
    8487        /** 
  • trunk/LogicMail/src/org/logicprobe/LogicMail/model/MailManager.java

    r627 r628  
    7373                MailSettings.getInstance().addMailSettingsListener(new MailSettingsListener() { 
    7474                        public void mailSettingsSaved(MailSettingsEvent e) { 
    75                                 mailSettings_MailSettingsSaved(e); 
    76                                 refreshMailboxTypes(); 
     75                            // This logic is rather crude, and will trigger a full refresh 
     76                            // under a wide variety of circumstances.  Its major intent is 
     77                            // to avoid a refresh in a few situations where a minor 
     78                            // configuration change affects future behavior and not 
     79                            // current state. 
     80                             
     81                            boolean refreshAccounts = false; 
     82                            // Trigger a refresh if either the account or outgoing list has changed 
     83                            int listChange = e.getListChange(); 
     84                            if((listChange & MailSettingsEvent.LIST_CHANGED_ACCOUNT) != 0 
     85                                    || (listChange & MailSettingsEvent.LIST_CHANGED_OUTGOING) != 0) { 
     86                                refreshAccounts = true; 
     87                            } 
     88                             
     89                            // Trigger a refresh if certain account settings have changed 
     90                            if(!refreshAccounts) { 
     91                                int num = mailSettings.getNumAccounts(); 
     92                                for(int i=0; i<num; i++) { 
     93                                    AccountConfig accountConfig = mailSettings.getAccountConfig(i); 
     94                                    int accountChange = e.getConfigChange(accountConfig); 
     95                                    if((accountChange & AccountConfig.CHANGE_TYPE_NAME) != 0 
     96                                            || (accountChange & AccountConfig.CHANGE_TYPE_MAILBOXES) != 0 
     97                                || (accountChange & AccountConfig.CHANGE_TYPE_OUTGOING) != 0) { 
     98                                        refreshAccounts = true; 
     99                                        break; 
     100                                    } 
     101                                    OutgoingConfig outgoingConfig = accountConfig.getOutgoingConfig(); 
     102                                    if(outgoingConfig != null 
     103                                            && (e.getConfigChange(outgoingConfig) & OutgoingConfig.CHANGE_TYPE_CONNECTION) != 0) { 
     104                            refreshAccounts = true; 
     105                            break; 
     106                                    } 
     107                                } 
     108                            } 
     109                             
     110                            // Trigger a refresh if appropriate 
     111                            if(refreshAccounts) { 
     112                            mailSettings_MailSettingsSaved(e); 
     113                                refreshMailboxTypes(); 
     114                            } 
    77115                        } 
    78116                }); 
  • trunk/LogicMail/src/org/logicprobe/LogicMail/ui/AccountConfigScreen.java

    r623 r628  
    628628            ImapConfig imapConfig = (ImapConfig)accountConfig; 
    629629 
    630             String folderPrefix = imapFolderPrefixField.getText().trim(); 
    631             if(folderPrefix.length() == 0) { 
    632                 imapConfig.setFolderPrefix(null); 
    633             } 
    634             else { 
    635                 imapConfig.setFolderPrefix(folderPrefix); 
    636             } 
     630            imapConfig.setFolderPrefix(imapFolderPrefixField.getText().trim()); 
    637631 
    638632            try { 
  • trunk/LogicMail/src/org/logicprobe/LogicMail/ui/ConfigScreen.java

    r626 r628  
    141141 
    142142        buildAccountsList(); 
    143  
    144         MailSettings.getInstance().addMailSettingsListener(new MailSettingsListener() { 
    145             public void mailSettingsSaved(MailSettingsEvent e) { 
    146                 buildAccountsList(); 
    147             } 
    148         }); 
    149     } 
    150  
     143    } 
     144 
     145    MailSettingsListener mailSettingsListener = new MailSettingsListener() { 
     146        public void mailSettingsSaved(MailSettingsEvent e) { 
     147            buildAccountsList(); 
     148        } 
     149    }; 
     150     
     151    protected void onDisplay() { 
     152        super.onDisplay(); 
     153        MailSettings.getInstance().addMailSettingsListener(mailSettingsListener); 
     154    } 
     155     
     156    protected void onUndisplay() { 
     157        MailSettings.getInstance().removeMailSettingsListener(mailSettingsListener); 
     158        super.onUndisplay(); 
     159    } 
     160     
    151161    private void initFileSystemChoices() { 
    152162        // Populate fileSystemRoots with a list of all 
Note: See TracChangeset for help on using the changeset viewer.