📄 uicontroller.java
字号:
/*
* this is to avoid that a message in the Drafts once edited and
* saved to be sent later (i.e. stored in the Outbox) remains in the
* Drafts while it is in the Outbox
*/
if (message.getParent() != null)
if ("/Outbox".equals(message.getParent().getFullName()))
getFolderInfo(messageManager.OUTBOX).getFolder().deleteMessage(message);
getFolderInfo(messageManager.DRAFTS).getFolder().appendMessage(message);
messageManager.updateMessageFlag(message, MessageFlags.DRAFT, true);
//message.getFlags().setFlag(MessageFlags.DRAFT, true);
//updateDraftMessageList(message);
//updateInboxMessageList(null);
showAlert(
Localization.getMessages().COMPOSE_MESSAGE_FORM_SAVED_TO_DRAFT,
getInboxMessageList());
//destroyAddressList();
//Log.debug("message saved to draft");
} catch (Exception ex) {
Log.error("UIC.savemessage: " + ex.toString() );
showErrorAlert(
Localization.getMessages().UNABLE_TO_SAVE_MESSAGE_TO_DRAFT,
getInboxMessageList());
// destroyAddressList();
}
}
private static String getMyAddress() {
mailClientConfig = getConfig();
return (mailClientConfig.getMailAccount().getAddress());
}
/**
* build the reply message of a given message.
*
*/
//TODO: check the cc field, it seems not to work.
public static void replyAll(Message message) {
Message m=new Message();
try {
m.setCc(message.getCc());
m.setTo(message.getReplyTo());
Address[] to=message.getTo();
for (int i=0; i<to.length; i++) {
if (!StringUtil.equalsIgnoreCase(to[i].getEmail(),getMyAddress())) {
to[i].setType(Address.CC);
m.addRecipient(to[i]);
}
}
m.setSubject(RE+ message.getSubject());
//setRepliedFlag(message);
delayedFlag(message, MessageFlags.ANSWERED);
updateComposeMessageScreen(m,getReplyText(message));
getContactList().emptySearchString();
showComposeMessageScreen(display.getCurrent(),getComposeMessageScreen().body);
} catch (MailException ex) {
Log.error("Error in reply all message function: " + ex.getMessage());
ex.printStackTrace();
}
}
/**
* Get the complete message (up to the maxObjSize).
*/
public static Message getFullMessage(Message message) {
Message msg = message;
Log.info("Get Full Message");
try {
msg=messageManager.getFullMessage(
message.getParent().getName(),
message.getMessageId());
} catch (ConfigException e) {
Log.error("getFullMessage: " + e.toString());
e.printStackTrace();
} catch (MailException e) {
Log.error("getFullMessage: " + e.toString());
e.printStackTrace();
}
return msg;
}
private static String getReplyText(Message message) {
StringBuffer sb = new StringBuffer();
sb.append("\n\n");
try {
//TODO: use right timiezone offset here
Date dateObj = message.getSentDate();
Calendar calendar = Calendar.getInstance();
calendar.setTime(dateObj);
calendar.setTimeZone(TimeZone.getDefault());
// this is only for visualization purposes
//TODO: check if the variables in formatLocalTime are really used
String date = MailDateFormatter.formatLocalTime(calendar.getTime());
sb.append(Localization.getMessages().STRING_ON).
append(" ").append(date).append(" ").
append((message.getFrom()==null)?"":message.getFrom().getVisibleName()).
append(" ").append(Localization.getMessages().REPLY_WROTE).
append("\n").append(message.getTextContent());
} catch (MailException ex) {
ex.printStackTrace();
Log.error("getReplyText() mailexception ");
}
//Log.debug("replty text: \n----------------------\n" + sb.toString() + "\n-------------------------");
return sb.toString();
}
private static FunambolAlert getFunambolAlert(String message,
AlertType alertType, boolean autoDismiss) {
/*FunambolAlert messageAlert =new FunambolAlert(
Localization.getMessages("FunambolAlertTitle"),
message,
alertType);*/
FunambolAlert messageAlert =new FunambolAlert(
"Funambol",
message,
alertType);
if (autoDismiss)
messageAlert.setTimeout(FunambolAlert.DEFAULT_TIMEOUT);
else
messageAlert.setTimeout(Alert.FOREVER);
return messageAlert;
}
public static Address getMyFrom() {
try {
if (StringUtil.isNullOrEmpty(getMyAddress())) {
return null;
} else {
return new Address(
Address.FROM,
mailClientConfig.getMailAccount().getName(),
getMyAddress());
}
} catch (MailException ex) {
ex.printStackTrace();
UIController.showAccountSettings(display.getCurrent());
UIController.showErrorAlert(
Localization.getMessages().UNABLE_TO_FIND_PERSONAL_ADDRESS
);
Log.error("uicontroller getMyFrom() error " +
"getting from field, returning null");
return null;
}
}
/**
* Returns the current MailClientConfig, or the default one
* in case of errors.
*/
public static MailClientConfig getConfig() {
try {
return ConfigManager.getConfig();
} catch (ConfigException e) {
// TODO shall we alert the user?
Log.error("Error retrieving configuration: " + e.getMessage());
MailClientConfig mcc = new MailClientConfig();
try {
ConfigManager.saveConfig(mcc);
} catch (Exception ex) {
Log.error("!!!Can't save default config!!! " + ex.toString());
}
return mailClientConfig;
}
}
/**
* Save the current configuration to the persistent storage.
*/
public static void saveConfig() {
try {
ConfigManager.saveConfig();
} catch (Exception e) {
// TODO: shall we alert the user?
Log.error("Error saving configuration: " + e.getMessage());
}
}
/**
* Save new configuration to persistent memory.
* If username field is changed a new account is initialized and
* slow sync are performed both for contact list and Emails
* @param mailClientConfig is the new configuration to be saved
*/
public static void saveNewConfig(MailClientConfig mailClientConfig) {
try {
ConfigManager.saveConfig(mailClientConfig);
} catch (Exception e) {
Log.error("Unable to save new configuration: " + e.getMessage());
e.printStackTrace();
}
}
/**
* Loads the source config from the store, if present.
*
* @param name the name of the source to load.
* @return the config, or null in case of error.
*/
public static SourceConfig getSourceConfig(String name) {
SourceConfig ret = new SourceConfig();
try {
ConfigManager.load("source." + name, ret);
return ret;
} catch (Exception e) {
Log.error("getSourceConfig: "+ e.toString());
return null;
}
}
/**
* Save the given source config.
*
* @param sc the SourceConfig to save.
*
* @throws ConfigException if the config is not present
* @throws IOException if an error occurred during the deserialization
*/
public static void saveSourceConfig(SourceConfig sc) {
try {
// The source config is stored in a record named "source.<sourcename>"
ConfigManager.save("source." + sc.getName(), sc);
Log.info("[UIController] config for source "+sc.getName()+" saved.");
} catch (Exception e) {
Log.error("saveSourceConfig: "+ e.toString());
// TODO: shall we put an alert here?
}
}
/** Enable or disable contact synchronization. */
public static void enableContactSync(boolean enable) {
SourceConfig sc = getSourceConfig(SourceConfig.CONTACT);
if(sc != null) {
if (enable) {
sc.setSyncMode(SyncML.ALERT_CODE_FAST);
} else {
sc.setSyncMode(SyncML.ALERT_CODE_NONE);
}
saveSourceConfig(sc);
}
}
public static void playSound() {
UIController.display.vibrate(1000);
InputStream is =
midlet.getClass().getResourceAsStream("/res/newmessage.midi");
MessageMediaManager mm = new MessageMediaManager(is);
mm.playSound();
}
public static void deleteMessage(Message toDelete) {
try {
messageManager.deleteMessage(toDelete);
if (UiUtils.isIncoming(toDelete)) {
getInboxMessageList().deleteMessage(toDelete.getMessageId());
} else {
updateMessageList(toDelete);
}
} catch (Exception ex) {
ex.printStackTrace();
Log.error("uicontroller deleteMessage() error deleting" +
" message " + toDelete.getSubject());
showErrorAlert(
Localization.getMessages().
getGENERIC_UNABLE_TO_DELETE_MESSAGE(toDelete.getSubject()));
}
}
public static void deleteMessage(MessageInfo msgInfo) {
deleteMessage(msgInfo.getMessage());
}
public static String getVersion() {
return ConfigManager.getClientVersion();
}
public static void emptyFolder(int folderId) {
try {
messageManager.emptyFolder(folderId);
} catch (MailException ex) {
ex.printStackTrace();
Log.error("unable to recreate folder " + folderId );
//TODO: add alert
}
}
public static void showAdvancedContactScreen(Contact contact) {
backStack.push(display.getCurrent());
UIController.display.setCurrent(new AdvancedContactForm(contact));
}
/**
* delete a contact
**/
public static void deleteContact(Contact contact) {
try {
UIController.contactManager.removeContact(contact.getContactId());
UIController.showAlert(Localization.getMessages().DELETING_CONTACT);
} catch (ContactManagerException ex) {
UIController.showErrorAlert(
Localization.getMessages().UNABLE_TO_DELETE_CONTACT);
}
}
public static void synchContacts() throws SyncException {
if (contactManager.getContactCount()>=contactManager.getDefaultContactNumber()) {
Log.info("[UIController] Addressbook is full. Remove some contact from server and try again.");
UIController.showAlert(Localization.getMessages().AB_LIMIT_ERROR_MSG);
return;
}
SourceConfig sc = getSourceConfig(SourceConfig.CONTACT);
// Check if the contacty sync is not enabled.
if(sc != null && sc.getSyncMode() == SyncML.ALERT_CODE_NONE) {
Log.info("Contact sync disabled.");
} else {
try {
enableSyncCommands(false);
contactManager.sync();
} catch (ConfigException e) {
Log.error("ConfigException: " + e.getMessage());
e.printStackTrace();
} catch (ContactManagerException e) {
Log.error("ContactManagerException: " + e.getMessage());
e.printStackTrace();
} finally {
enableSyncCommands(true);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -