1 package net.suberic.pooka.gui.propedit; 2 import net.suberic.pooka.Pooka; 3 import net.suberic.pooka.gui.FolderNode; 4 import net.suberic.pooka.gui.FolderPanel; 5 import net.suberic.pooka.gui.MailTreeNode; 6 import net.suberic.util.VariableBundle; 7 import net.suberic.util.gui.propedit.*; 8 import net.suberic.util.thread.ActionThread; 9 10 import java.io.File ; 11 import java.util.*; 12 import javax.mail.MessagingException ; 13 import javax.swing.Action ; 14 import javax.swing.JLabel ; 15 import javax.swing.JOptionPane ; 16 17 20 public class FirstRunWizardController extends NewStoreWizardController { 21 22 25 public FirstRunWizardController(String sourceTemplate, WizardEditorPane wep) { 26 super(sourceTemplate, wep); 27 } 28 29 32 public void finishWizard() throws PropertyValueVetoException { 33 saveProperties(); 34 getEditorPane().addDisableMask(this); 35 getManager().commit(); 36 setupFolders(); 37 Pooka.getUIFactory().showStatusMessage(Pooka.getProperty("Pooka._firstRunWizard.status.loadingFolders", "Loading folders...")); 38 Pooka.getStoreManager().loadAllSentFolders(); 39 Pooka.getOutgoingMailManager().loadOutboxFolders(); 40 Pooka.getPookaManager().getResources().saveProperties(); 41 42 Pooka.getUIFactory().showStatusMessage(Pooka.getProperty("Pooka._firstRunWizard.status.openingInbox", "Opening Inbox...")); 43 openInbox(); 44 45 } 46 47 50 public void setupFolders() { 51 boolean useLocalFiles = Pooka.getProperty("Pooka.useLocalFiles", "true").equalsIgnoreCase("true"); 52 String storeName = Pooka.getProperty("Store"); 53 String protocol = Pooka.getProperty("Store." + storeName + ".protocol"); 54 String localStoreName = storeName; 55 56 if (protocol.equalsIgnoreCase("imap") && useLocalFiles) { 57 localStoreName = "local"; 60 Pooka.setProperty("Store.local.useInbox", "false"); 61 Pooka.setProperty("Store.local.folderList", "sent:outbox"); 62 Pooka.setProperty("Store.local.protocol", "maildir"); 63 Pooka.setProperty("Store", storeName + ":local"); 64 } else { 65 Pooka.setProperty("Store." + localStoreName + ".folderList", "INBOX:sent:outbox"); 67 } 68 String pookaDirName = Pooka.getProperty("FirstRunWizard.pookaDirectory", System.getProperty("user.home") + File.separator + ".pooka"); 69 String mailDirName = pookaDirName + File.separator + localStoreName; 70 String subFolderDirName = mailDirName + File.separator + Pooka.getProperty("Pooka.subFolderName", "folders"); 71 72 if (useLocalFiles) { 73 File mailDir = new File (mailDirName); 74 if (! mailDir.exists()) 75 mailDir.mkdirs(); 76 77 File subFolderDir = new File (subFolderDirName); 78 if (! subFolderDir.exists()) 79 subFolderDir.mkdirs(); 80 81 File sentFile = new File (subFolderDirName + File.separator + ".sent"); 82 if (! sentFile.exists()) { 83 sentFile.mkdir(); 84 85 new File (sentFile, "cur").mkdir(); 87 new File (sentFile, "new").mkdir(); 88 new File (sentFile, "tmp").mkdir(); 89 } 90 } 91 92 if (useLocalFiles) { 93 File outboxFile = new File (subFolderDirName + File.separator + ".outbox"); 94 if (! outboxFile.exists()) { 95 outboxFile.mkdir(); 96 97 new File (outboxFile, "cur").mkdir(); 98 new File (outboxFile, "new").mkdir(); 99 new File (outboxFile, "tmp").mkdir(); 100 } 101 102 Pooka.setProperty("Store.local.mailDir", mailDirName); 103 104 } 105 106 107 109 String outgoingServer = Pooka.getProperty("OutgoingServer"); 110 Pooka.setProperty("OutgoingServer." + outgoingServer + ".outbox", localStoreName + "/outbox"); 111 112 String userName = Pooka.getProperty("UserProfile"); 113 Pooka.setProperty("UserProfile." + userName + ".sentFolder", localStoreName + "/sent"); 114 } 115 116 117 Exception mOpenInboxException = null; 118 boolean mOpenInboxSuccessful = false; 119 122 public void openInbox() { 123 java.util.Vector allStores = Pooka.getStoreManager().getStoreList(); 124 net.suberic.pooka.StoreInfo si = null; 125 if (allStores.size() > 0) { 126 si = (net.suberic.pooka.StoreInfo) allStores.get(0); 127 } 128 129 if (si != null) { 130 ActionThread thread = si.getStoreThread(); 131 final net.suberic.pooka.StoreInfo storeInfo = si; 132 133 mOpenInboxException = null; 135 mOpenInboxSuccessful = false; 136 137 javax.swing.Action connectionAction = new javax.swing.AbstractAction () { 138 public void actionPerformed(java.awt.event.ActionEvent ae) { 139 try { 140 storeInfo.connectStore(); 141 javax.swing.SwingUtilities.invokeLater( new Runnable () { 142 143 public void run() { 144 MailTreeNode mtn = null; 145 net.suberic.pooka.FolderInfo fi = storeInfo.getChild("INBOX"); 146 if (fi != null) { 147 FolderNode fn = fi.getFolderNode(); 148 Action openAction = fn.getAction("file-open"); 149 openAction.actionPerformed(new java.awt.event.ActionEvent (this, 0, "file-open")); 150 mtn = fn; 151 } else { 152 mtn = storeInfo.getStoreNode(); 153 } 154 if (mtn != null) { 155 javax.swing.JTree folderTree = ((FolderPanel)mtn.getParentContainer()).getFolderTree(); 156 folderTree.scrollPathToVisible(new javax.swing.tree.TreePath (mtn.getPath())); 157 } 158 159 openInboxSuccess(); 160 } 161 }); 162 } catch (MessagingException me) { 163 Pooka.getUIFactory().clearStatus(); 164 me.printStackTrace(); 165 int continueValue = handleInvalidEntry(me.getMessage()); 166 if (continueValue == JOptionPane.YES_OPTION) { 167 getEditorPane().removeDisableMask(FirstRunWizardController.this); 168 clearProperties(); 170 mState = "storeConfig"; 171 getEditorPane().loadState("storeConfig"); 172 } else { 173 getEditorPane().getWizardContainer().closeWizard(); 174 } 175 } 176 } 177 }; 178 179 thread.addToQueue(connectionAction, new java.awt.event.ActionEvent (this, 0, "connectStore")); 180 } 181 182 } 183 184 private void openInboxSuccess() { 185 Pooka.getUIFactory().clearStatus(); 186 getEditorPane().getWizardContainer().closeWizard(); 187 } 188 189 public int handleInvalidEntry(String message) { 190 StringBuffer errorMessage = new StringBuffer (Pooka.getProperty("error.NewAccountPooka.invalidEntry", "invalid first entry.")); 191 if (message != null && message.length() > 0) { 192 errorMessage.append("\n"); 193 errorMessage.append(message); 194 } 195 errorMessage.append("\n\n"); 196 errorMessage.append(Pooka.getProperty("error.NewAccountPooka.continueMessage", "Would you like to re-enter your information?")); 197 198 JLabel jta = new JLabel (errorMessage.toString()); 199 int continueResponse = JOptionPane.showOptionDialog(Pooka.getMainPanel(), errorMessage.toString(), "Failed to connect to Store.", javax.swing.JOptionPane.YES_NO_OPTION, javax.swing.JOptionPane.WARNING_MESSAGE, null, new Object [] { "Re-enter", "Continue" }, "Re-enter"); 200 if (continueResponse == 0) { 201 return JOptionPane.YES_OPTION; 202 } else { 203 return JOptionPane.NO_OPTION; 204 } 205 206 } 207 208 209 212 private void clearProperties() { 213 getManager().removeProperty("Store"); 217 getManager().removeProperty("User"); 218 getManager().removeProperty("OutgoingServer"); 219 220 getManager().commit(); 221 222 Set<String > removeProperties = getManager().getPropertyNamesStartingWith("Store"); 223 for (String prop: removeProperties) { 224 getManager().removeProperty(prop); 226 } 227 removeProperties = getManager().getPropertyNamesStartingWith("User"); 228 for (String prop: removeProperties) { 229 getManager().removeProperty(prop); 231 } 232 removeProperties = getManager().getPropertyNamesStartingWith("OutgoingServer"); 233 for (String prop: removeProperties) { 234 getManager().removeProperty(prop); 236 } 237 getManager().commit(); 238 239 } 240 } 241 | Popular Tags |