1 package org.columba.mail.mailchecking; 17 18 import java.util.Iterator ; 19 import java.util.List ; 20 import java.util.Observable ; 21 import java.util.Vector ; 22 23 import javax.swing.event.EventListenerList ; 24 25 import org.columba.core.connectionstate.ConnectionStateImpl; 26 import org.columba.core.gui.action.AbstractColumbaAction; 27 import org.columba.mail.command.IMailFolderCommandReference; 28 import org.columba.mail.config.AccountItem; 29 import org.columba.mail.config.AccountList; 30 import org.columba.mail.config.MailConfig; 31 32 33 43 public class MailCheckingManager extends Observable { 44 private List list; 45 46 private static MailCheckingManager instance = new MailCheckingManager(); 47 48 49 protected EventListenerList listenerList = new EventListenerList (); 50 51 public MailCheckingManager() { 52 super(); 53 54 list = new Vector (); 55 56 AccountList accountList = MailConfig.getInstance().getAccountList(); 58 59 for (int i = 0; i < accountList.count(); i++) { 61 AccountItem accountItem = accountList.get(i); 62 63 add(accountItem); 64 } 65 66 addMailCheckingListener(new SystemPeepMailCheckingListener()); 68 } 69 70 public static MailCheckingManager getInstance() { 71 return instance; 72 } 73 74 83 public AbstractColumbaAction[] getActions() { 84 AbstractColumbaAction[] actions = new AbstractColumbaAction[list.size()]; 85 86 Iterator it = list.iterator(); 87 int i = 0; 88 89 while (it.hasNext()) { 90 actions[i++] = ((AbstractMailCheckingAction) it.next()); 91 } 92 93 return actions; 94 } 95 96 public AbstractMailCheckingAction get(int uid) { 97 Iterator it = list.iterator(); 98 99 while (it.hasNext()) { 101 AbstractMailCheckingAction action = (AbstractMailCheckingAction) it.next(); 102 103 AccountItem accountItem = action.getAccountItem(); 104 int i = accountItem.getUid(); 105 106 if (i == uid) { 107 return action; 109 } 110 } 111 112 return null; 113 } 114 115 public void remove(int uid) { 116 AbstractMailCheckingAction action = get(uid); 117 118 if (action != null) { 120 list.remove(action); 121 } 122 } 123 124 public void restartTimer(int uid) { 125 AbstractMailCheckingAction action = get(uid); 126 127 if (action != null) { 129 action.restartTimer(); 130 } 131 } 132 133 public void add(AccountItem accountItem) { 134 if (accountItem.isPopAccount()) { 135 list.add(new POP3MailCheckingAction(accountItem)); 136 } else { 137 list.add(new IMAPMailCheckingAction(accountItem)); 138 } 139 } 140 141 145 public void checkAll() { 146 if (ConnectionStateImpl.getInstance().isOnline() == false) { 148 ConnectionStateImpl.getInstance().setOnline(true); 150 } 151 Iterator it = list.iterator(); 152 153 while (it.hasNext()) { 155 AbstractMailCheckingAction action = (AbstractMailCheckingAction) it.next(); 156 if( action.isCheckAll() && action.isEnabled()) action.check(); 157 } 158 } 159 160 164 public void update() { 165 setChanged(); 166 167 notifyObservers(); 168 } 169 170 171 172 173 176 public void addMailCheckingListener(IMailCheckingListener l) { 177 listenerList.add(IMailCheckingListener.class, l); 178 } 179 180 183 public void removeMailCheckingListener(IMailCheckingListener l) { 184 listenerList.remove(IMailCheckingListener.class, l); 185 } 186 187 191 public void fireNewMessageArrived(IMailFolderCommandReference ref) { 192 193 MailCheckingEvent e = new MailCheckingEvent(this, ref); 194 Object [] listeners = listenerList.getListenerList(); 196 197 for (int i = listeners.length - 2; i >= 0; i -= 2) { 200 if (listeners[i] == IMailCheckingListener.class) { 201 ((IMailCheckingListener) listeners[i + 1]).newMessageArrived(e); 202 } 203 } 204 } 205 206 } 207 | Popular Tags |