📄 mailclientconfig.java
字号:
/*
* Copyright (C) 2006-2007 Funambol
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package com.funambol.mailclient.config;
import com.funambol.util.MailDateFormatter;
import java.io.DataOutputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.util.Date;
import com.funambol.mailclient.Account;
import com.funambol.mailclient.MailFilter;
import com.funambol.storage.Serializable;
import com.funambol.util.DateUtil;
import com.funambol.util.Log;
import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordStoreException;
import javax.microedition.rms.RecordStoreNotOpenException;
/**
* Configuration data for the Mail Client: account, polling time etc.
*
*/
public class MailClientConfig implements Serializable {
//---------------------------------------------------------------- Constants
/** This is the default polling interval*/
private static final int INTERVAL = 5;
/** The name of the config record */
public static final String NAME = "MailConfig" ;
/* This field contains a version string of the configuration data */
private static final int VERSION = 102 ;
/* This field contains the previous versions of the configuration data
* from which the backward compatibility is guaranteed
*/
private static final int VERSION_101 = 101;
private static final int VERSION_102 = 102;
//--------------------------------------------------------------- Attributes
/** The configuration version loaded from the store */
private long version ;
/** Mail params */
private Account mailAccount;
/** Mail Filter */
private MailFilter mailFilter;
/** Enable scheduled sync */
private boolean enableScheduler;
/** Polling interval, in minutes */
private int pollInterval;
/** Enable Sms listener */
private boolean enableSmsListener;
/** Enable Delete command propagation*/
private boolean enableDeletePropagation;
/** Log level*/
private int logLevel;
/** Time of daily polling */
private long nextTimeAlarm;
/** Client Server Communications Compress */
private boolean compress;
//--------------------------------- Fields added in version 101
/** Date of First installation */
private long startFilter;
// Number of days to remove for the date of starting for filter
private int DAYS_TO_REMOVE = 3;
private int rmsStoreSize;
//--------------------------------- Fields added in version 102
private String timeZone;
private static boolean timeZoneUpdated; // NOT Serialized
//------------------------------------------------------------- Constructors
/**
* Default constructor. Sets default configuration values.
*/
public MailClientConfig() {
version = VERSION;
// Mail parameters
mailAccount = new Account();
Date date = new DateUtil().toMidnight().removeDays(DAYS_TO_REMOVE).getTime();
// Default filter parameters
mailFilter = new MailFilter(2*1024, // size:2K
date, // from date
false, // headers only
false); // without attachments
// Push parameters
enableScheduler = false;
pollInterval = 240;
enableSmsListener = false;
enableDeletePropagation = false;
logLevel = Log.INFO ;
compress = true;
// Version 101
startFilter = date.getTime();
rmsStoreSize = 0; // XXX: use another default?
timeZoneUpdated = false;
}
//----------------------------------------------------------- Public methods
public long getStartFilter() {
return startFilter;
}
public void setStartFilter(long startFilter) {
this.startFilter = startFilter;
}
public Account getMailAccount() {
return this.mailAccount;
}
public void setMailAccount(Account account) {
this.mailAccount = account;
}
/** Return the currently configured mail filter. */
public MailFilter getMailFilter() {
return mailFilter;
}
/** Set a new mail filter. */
public void setMailFilter(MailFilter mailFilter) {
this.mailFilter = mailFilter;
}
/** Returns the current status of the scheduler. */
public boolean isSchedulerEnabled() {
return enableScheduler;
}
/** Enables or disables the scheduler */
public void enableScheduler(boolean enableScheduler) {
this.enableScheduler = enableScheduler;
}
/** This value is not used at the moment by the client. */
public boolean isSmsListenerEnabled() {
return enableSmsListener;
}
/** This value is not used at the moment by the client. */
public void enableSmsListener(boolean enableSmsListener) {
this.enableSmsListener = enableSmsListener;
}
/** Sets the log level. See com.funambol.util.Log for valid levels. */
public void setLogLevel(int logLevel) {
this.logLevel = logLevel;
}
/** Gets the log level. See com.funambol.util.Log for valid levels. */
public int getLogLevel() {
return logLevel;
}
/** Sets the polling interval, in seconds. */
public void setPollInterval(int pollInterval) {
this.pollInterval = pollInterval;
}
/** Returns the polling interval, in seconds. */
public int getPollInterval() {
return this.pollInterval;
}
/** Returns true if the communication with the server is compressed. */
public boolean isCompress() {
return compress;
}
/** Enables or disables compression in the communication with the server */
public void enableCompress(boolean enable) {
compress = enable;
}
/** Enables or disables the date filter */
public void enableDateFilter(boolean enable) {
if(enable) {
mailFilter.setDate(new Date(startFilter));
}
else {
mailFilter.setDate(null);
}
}
/** Returns the current status of the delete propagation on server */
public boolean isEnableDeletePropagation() {
return enableDeletePropagation;
}
/** Enables or disables the delete propagation on server */
public void enableDeletePropagation(boolean deletePropagation) {
this.enableDeletePropagation = deletePropagation;
}
/** Gets the time of the next wakeup for the daily scheduler */
public long getNextTimeAlarm() {
return nextTimeAlarm;
}
/** Sets the time of the next wakeup for the daily scheduler */
public void setNextTimeAlarm(long nextTimeAlarm) {
this.nextTimeAlarm = nextTimeAlarm;
}
/** Gets the RMS store size for the midlet. */
public int getRmsStoreSize() {
return rmsStoreSize;
}
/** Sets the RMS store size for the midlet. */
public void setRmsStoreSize(int rmsStoreSize) {
this.rmsStoreSize = rmsStoreSize;
}
public void setTimeZone (String timeZoneToSet){
this.timeZone = timeZoneToSet;
MailDateFormatter.setTimeZone(timeZone);
this.timeZoneUpdated = true;
}
public String getTimeZone (){
return timeZone;
}
public boolean getTimeZoneUpdated (){
return timeZoneUpdated;
}
public String toString() {
StringBuffer sb = new StringBuffer();
sb.append("Configuration version: \n").append(this.version);
sb.append("\nMailAccount: \n").append(this.mailAccount);
sb.append("\nMailFilter: ").append(this.mailFilter);
sb.append("\nEnableScheduler: ").append(this.enableScheduler);
sb.append("\nEnableSmsListener: ").append(this.enableSmsListener);
sb.append("\nLogLevel: ").append(this.logLevel);
sb.append("\nPollInterval: ").append(this.pollInterval);
sb.append("\nNextTimeAlarm: "
+
((nextTimeAlarm!=0L) ?
MailDateFormatter.dateToUTC(new Date(nextTimeAlarm)): "null")
);
sb.append("\nEnableDeletePropagation: ")
.append(this.enableDeletePropagation);
sb.append("\nCompress: ").append(this.compress);
// Ver.101
sb.append("\nStartFilter: ")
.append(MailDateFormatter.dateToUTC(new Date(startFilter)));
sb.append("\nRmsSize: ").append(rmsStoreSize);
return sb.toString();
}
//---------------------------------------------- Serializable implementation
/**
* Write object fields to the output stream.
* @param out Output stream
* @throws IOException
*/
public void serialize(DataOutputStream out) throws IOException {
out.writeInt(VERSION);
out.writeUTF(mailAccount.getUrl());
out.writeUTF(mailAccount.getUser());
out.writeUTF(mailAccount.getPassword());
out.writeUTF(mailAccount.getName());
out.writeUTF(mailAccount.getAddress());
out.writeUTF(mailAccount.getRemoteURI());
out.writeUTF(mailAccount.getPimRemoteURI());
out.writeBoolean(enableScheduler);
out.writeInt(pollInterval);
out.writeBoolean(enableSmsListener);
out.writeBoolean(enableDeletePropagation);
out.writeInt(logLevel);
out.writeLong(nextTimeAlarm);
out.writeInt(mailFilter.getSize());
// Handle the case of null date
Date d = mailFilter.getDate();
out.writeLong((d != null) ? d.getTime() : 0L);
out.writeBoolean(mailFilter.downloadAttachments());
out.writeBoolean(mailFilter.isHeadersOnly());
// Ver.101
out.writeLong(startFilter);
out.writeInt(rmsStoreSize);
}
/**
* Read object field from the input stream.
* @param in Input stream
* @throws IOException
*/
public void deserialize(DataInputStream in) throws IOException {
boolean enableFirstInstall = true;
int savedVer = in.readInt();
// If the config stored belongs to a newer version than the
// current one (the user went back to an older version, use
// the defaults.
if (savedVer > VERSION) {
Log.error("This app is older then the config stored.");
Log.error("Can't handle forward compatibility, using defaults.");
return;
}
version = savedVer;
mailAccount.setUrl(in.readUTF());
mailAccount.setUser(in.readUTF());
mailAccount.setPassword(in.readUTF());
mailAccount.setName(in.readUTF());
mailAccount.setAddress(in.readUTF());
mailAccount.setRemoteURI(in.readUTF());
mailAccount.setPimRemoteURI(in.readUTF());
enableScheduler = in.readBoolean();
pollInterval = in.readInt();
enableSmsListener = in.readBoolean();
enableDeletePropagation = in.readBoolean();
logLevel = in.readInt();
nextTimeAlarm = in.readLong();
mailFilter.setSize(in.readInt());
// Handle the case of null date
long d = in.readLong();
mailFilter.setDate((d != 0L) ? new Date(d) : null);
mailFilter.enableAttachmentsDownload(in.readBoolean());
mailFilter.enableHeadersOnly(in.readBoolean());
// Handle backward compatibilty
if (savedVer >= VERSION_101) {
startFilter = in.readLong();
rmsStoreSize = in.readInt();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -