diff --git a/build.xml b/build.xml index 34677b354..7a9cdaf79 100644 --- a/build.xml +++ b/build.xml @@ -840,7 +840,7 @@ bundle-contactlist,meta-contactlist,meta-contactlist-slick, bundle-plugin-icqaccregwizz,bundle-plugin-jabberaccregwizz, bundle-plugin-msnaccregwizz,bundle-plugin-sipaccregwizz, - bundle-plugin-yahooaccregwizz, + bundle-plugin-yahooaccregwizz,bundle-plugin-aimaccregwizz, bundle-version,bundle-version-impl,bundle-shutdown, bundle-growlnotification,bundle-audionotifier,bundle-plugin-splashscreen, bundle-plugin-systray,bundle-browserlauncher,bundle-gibberish, @@ -1340,6 +1340,18 @@ javax.swing.event, javax.swing.border"/> prefix="resources/images/icq"/> + + + + + + + + + diff --git a/lib/felix.client.run.properties b/lib/felix.client.run.properties index 9900f3edd..ebebf28e3 100644 --- a/lib/felix.client.run.properties +++ b/lib/felix.client.run.properties @@ -82,6 +82,7 @@ felix.auto.start.60= \ felix.auto.start.67= \ reference:file:sc-bundles/icqaccregwizz.jar \ +reference:file:sc-bundles/aimaccregwizz.jar \ reference:file:sc-bundles/sipaccregwizz.jar \ reference:file:sc-bundles/jabberaccregwizz.jar \ reference:file:sc-bundles/msnaccregwizz.jar \ diff --git a/src/net/java/sip/communicator/impl/protocol/icq/IcqAccountID.java b/src/net/java/sip/communicator/impl/protocol/icq/IcqAccountID.java index ae9044750..df7f6a6fb 100644 --- a/src/net/java/sip/communicator/impl/protocol/icq/IcqAccountID.java +++ b/src/net/java/sip/communicator/impl/protocol/icq/IcqAccountID.java @@ -12,13 +12,38 @@ public class IcqAccountID extends AccountID { + /** + * Then name of a property which represenstots is this account icq or aim. + */ + public static final String IS_AIM = "IS_AIM"; + /** * Creates an icq account id from the specified uin and account properties. + * If property IS_AIM is set to true then this is an AIM account, else + * an Icq one. * @param uin the uin identifying this account * @param accountProperties any other properties necessary for the account. */ IcqAccountID(String uin, Map accountProperties ) { - super(uin, accountProperties, ProtocolNames.ICQ, "icq.com"); + super(uin, accountProperties, + isAIM(accountProperties) ? ProtocolNames.AIM : ProtocolNames.ICQ, + isAIM(accountProperties) ? "aim.com" : "icq.com"); + } + + /** + * Checks is the provided properties are for icq or aim account + * @param accountProperties account properties for the checked account. + */ + static boolean isAIM(Map accountProperties) + { + Object isAim = accountProperties.get(IS_AIM); + + if(isAim != null && + isAim instanceof String && + ((String)isAim).equalsIgnoreCase("true")) + return true; + else + return false; } } diff --git a/src/net/java/sip/communicator/impl/protocol/icq/IcqActivator.java b/src/net/java/sip/communicator/impl/protocol/icq/IcqActivator.java index 21585b70a..255ebeb0f 100644 --- a/src/net/java/sip/communicator/impl/protocol/icq/IcqActivator.java +++ b/src/net/java/sip/communicator/impl/protocol/icq/IcqActivator.java @@ -16,10 +16,12 @@ public class IcqActivator implements BundleActivator { private ServiceRegistration icqPpFactoryServReg = null; + private ServiceRegistration aimPpFactoryServReg = null; private static BundleContext bundleContext = null; private static ConfigurationService configurationService = null; private static ProtocolProviderFactoryIcqImpl icqProviderFactory = null; + private static ProtocolProviderFactoryIcqImpl aimProviderFactory = null; /** * Called when this bundle is started so the Framework can perform the @@ -34,19 +36,31 @@ public class IcqActivator public void start(BundleContext context) throws Exception { this.bundleContext = context; - Hashtable hashtable = new Hashtable(); - hashtable.put(ProtocolProviderFactory.PROTOCOL, ProtocolNames.ICQ); + Hashtable icqHashtable = new Hashtable(); + icqHashtable.put(ProtocolProviderFactory.PROTOCOL, ProtocolNames.ICQ); + + Hashtable aimHashtable = new Hashtable(); + aimHashtable.put(ProtocolProviderFactory.PROTOCOL, ProtocolNames.AIM); - icqProviderFactory = new ProtocolProviderFactoryIcqImpl(); + icqProviderFactory = new ProtocolProviderFactoryIcqImpl(false); + aimProviderFactory = new ProtocolProviderFactoryIcqImpl(true); //load all icq providers icqProviderFactory.loadStoredAccounts(); + //load all aim providers + aimProviderFactory.loadStoredAccounts(); + //reg the icq account man. icqPpFactoryServReg = context.registerService( ProtocolProviderFactory.class.getName(), icqProviderFactory, - hashtable); + icqHashtable); + + aimPpFactoryServReg = context.registerService( + ProtocolProviderFactory.class.getName(), + aimProviderFactory, + aimHashtable); } /** @@ -82,15 +96,26 @@ public static BundleContext getBundleContext() /** * Retrurns a reference to the protocol provider factory that we have - * registered. + * registered for icq accounts. * @return a reference to the ProtocolProviderFactoryIcqImpl * instance that we have registered from this package. */ - static ProtocolProviderFactoryIcqImpl getProtocolProviderFactory() + static ProtocolProviderFactoryIcqImpl getIcqProtocolProviderFactory() { return icqProviderFactory; } + /** + * Retrurns a reference to the protocol provider factory that we have + * registered for aim accounts. + * @return a reference to the ProtocolProviderFactoryIcqImpl + * instance that we have registered from this package. + */ + static ProtocolProviderFactoryIcqImpl getAimProtocolProviderFactory() + { + return aimProviderFactory; + } + /** * Called when this bundle is stopped so the Framework can perform the * bundle-specific activities necessary to stop the bundle. @@ -105,5 +130,7 @@ public void stop(BundleContext context) throws Exception { icqProviderFactory.stop(); icqPpFactoryServReg.unregister(); + + aimPpFactoryServReg.unregister(); } } diff --git a/src/net/java/sip/communicator/impl/protocol/icq/OperationSetPersistentPresenceIcqImpl.java b/src/net/java/sip/communicator/impl/protocol/icq/OperationSetPersistentPresenceIcqImpl.java index e0406bead..845adb7e0 100644 --- a/src/net/java/sip/communicator/impl/protocol/icq/OperationSetPersistentPresenceIcqImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/icq/OperationSetPersistentPresenceIcqImpl.java @@ -323,11 +323,7 @@ private IcqStatusEnum icqStatusLongToPresenceStatus(long icqStatus) // Fixed order of status checking // The order does matter, as the icqStatus consists of more than one // status for example DND = OCCUPIED | DND | AWAY - if (icqStatus == -1) - { - return IcqStatusEnum.OFFLINE; - } - else if ( (icqStatus & FullUserInfo.ICQSTATUS_INVISIBLE ) != 0) + if ( (icqStatus & FullUserInfo.ICQSTATUS_INVISIBLE ) != 0) { return IcqStatusEnum.INVISIBLE; } @@ -1358,13 +1354,19 @@ public void registrationStateChanged(RegistrationStateChangeEvent evt) if(presenceQueryTimer == null) presenceQueryTimer = new Timer(); else + { + // cancel any previous jobs and create new timer presenceQueryTimer.cancel(); + presenceQueryTimer = new Timer(); + } AwaitingAuthorizationContactsPresenceTimer queryTask = new AwaitingAuthorizationContactsPresenceTimer(); + // start after 15 seconds. wait for login to be completed and + // list and statuses to be gathered presenceQueryTimer.scheduleAtFixedRate( - queryTask, PRESENCE_QUERY_INTERVAL, PRESENCE_QUERY_INTERVAL); + queryTask, 15000, PRESENCE_QUERY_INTERVAL); } } else if(evt.getNewState() == RegistrationState.UNREGISTERED diff --git a/src/net/java/sip/communicator/impl/protocol/icq/ProtocolProviderFactoryIcqImpl.java b/src/net/java/sip/communicator/impl/protocol/icq/ProtocolProviderFactoryIcqImpl.java index 84b9f402e..2391b1b34 100644 --- a/src/net/java/sip/communicator/impl/protocol/icq/ProtocolProviderFactoryIcqImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/icq/ProtocolProviderFactoryIcqImpl.java @@ -27,12 +27,19 @@ public class ProtocolProviderFactoryIcqImpl * The table that we store our accounts in. */ private Hashtable registeredAccounts = new Hashtable(); + + /** + * Is this factory is created for aim or icq accounts + */ + private boolean isAimFactory = false; /** * Creates an instance of the ProtocolProviderFactoryIcqImpl. + * @param isAimFactory whether its an aim factory */ - protected ProtocolProviderFactoryIcqImpl() + protected ProtocolProviderFactoryIcqImpl(boolean isAimFactory) { + this.isAimFactory = isAimFactory; } /** @@ -93,6 +100,10 @@ public AccountID installAccount( String userIDStr, if (accountProperties == null) throw new NullPointerException("The specified property map was null"); + // we are installing new aim account from the wizzard, so mark it as aim + if(isAimFactory) + accountProperties.put(IcqAccountID.IS_AIM, "true"); + AccountID accountID = new IcqAccountID(userIDStr, accountProperties); //make sure we haven't seen this account id before. @@ -129,6 +140,13 @@ public AccountID loadAccount( Map accountProperties) if(context == null) throw new NullPointerException("The specified BundleContext was null"); + // there are two factories - one for icq accounts and one for aim ones. + // if we are trying to load an icq account in aim factory - skip it + // and the same for aim accounts in icq factory + if((IcqAccountID.isAIM(accountProperties) && !isAimFactory) || + (!IcqAccountID.isAIM(accountProperties) && isAimFactory)) + return null; + String userIDStr = (String)accountProperties.get(USER_ID); AccountID accountID = new IcqAccountID(userIDStr, accountProperties); @@ -136,15 +154,15 @@ public AccountID loadAccount( Map accountProperties) //get a reference to the configuration service and register whatever //properties we have in it. - Hashtable properties = new Hashtable(); - properties.put(PROTOCOL, ProtocolNames.ICQ); - properties.put(USER_ID, userIDStr); - ProtocolProviderServiceIcqImpl icqProtocolProvider = new ProtocolProviderServiceIcqImpl(); icqProtocolProvider.initialize(userIDStr, accountID); - + + Hashtable properties = new Hashtable(); + properties.put(PROTOCOL, icqProtocolProvider.getProtocolName()); + properties.put(USER_ID, userIDStr); + ServiceRegistration registration = context.registerService( ProtocolProviderService.class.getName(), icqProtocolProvider, diff --git a/src/net/java/sip/communicator/impl/protocol/icq/ProtocolProviderServiceIcqImpl.java b/src/net/java/sip/communicator/impl/protocol/icq/ProtocolProviderServiceIcqImpl.java index d140a9843..54122a3af 100644 --- a/src/net/java/sip/communicator/impl/protocol/icq/ProtocolProviderServiceIcqImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/icq/ProtocolProviderServiceIcqImpl.java @@ -202,9 +202,15 @@ public void register(SecurityAuthority authority) synchronized(initializationLock) { + ProtocolProviderFactoryIcqImpl protocolProviderFactory = null; + + if(USING_ICQ) + protocolProviderFactory = IcqActivator.getIcqProtocolProviderFactory(); + else + protocolProviderFactory = IcqActivator.getAimProtocolProviderFactory(); + //verify whether a password has already been stored for this account - String password = IcqActivator.getProtocolProviderFactory() - .loadPassword(getAccountID()); + String password = protocolProviderFactory.loadPassword(getAccountID()); //decode if( password == null ) @@ -214,7 +220,7 @@ public void register(SecurityAuthority authority) credentials.setUserName(this.getAccountID().getUserID()); //request a password from the user - credentials = authority.obtainCredentials(ProtocolNames.ICQ + credentials = authority.obtainCredentials(getProtocolName() , credentials); //extract the password the user passed us. char[] pass = credentials.getPassword(); @@ -233,7 +239,7 @@ public void register(SecurityAuthority authority) if (credentials.isPasswordPersistent()) { - IcqActivator.getProtocolProviderFactory() + protocolProviderFactory .storePassword(getAccountID(), password); } } @@ -337,7 +343,10 @@ public boolean isRegistered() */ public String getProtocolName() { - return ProtocolNames.ICQ; + if(USING_ICQ) + return ProtocolNames.ICQ; + else + return ProtocolNames.AIM; } /** @@ -387,14 +396,8 @@ protected void initialize(String screenname, { this.accountID = accountID; - try - { - Long.parseLong(accountID.getUserID()); - } catch (NumberFormatException ex) - { - // if its icq its number can be parsed - USING_ICQ = false; - } + if(IcqAccountID.isAIM(accountID.getAccountProperties())) + USING_ICQ = false; //initialize the presence operationset OperationSetPersistentPresence persistentPresence = @@ -726,8 +729,12 @@ else if (newState == State.DISCONNECTED) if(reasonCode == RegistrationStateChangeEvent .REASON_AUTHENTICATION_FAILED) { - IcqActivator.getProtocolProviderFactory().storePassword( - getAccountID(), null); + if(USING_ICQ) + IcqActivator.getIcqProtocolProviderFactory().storePassword( + getAccountID(), null); + else + IcqActivator.getAimProtocolProviderFactory().storePassword( + getAccountID(), null); } //now tell all interested parties about what happened. diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/ContactJabberImpl.java b/src/net/java/sip/communicator/impl/protocol/jabber/ContactJabberImpl.java index 00bcf1f01..beaf0562f 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/ContactJabberImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/ContactJabberImpl.java @@ -297,9 +297,15 @@ private byte[] getAvatar() { try { + XMPPConnection connection = + ssclCallback.getParentProvider().getConnection(); + + if(connection == null || !connection.isAuthenticated()) + return null; + VCard card = new VCard(); card.load( - ssclCallback.getParentProvider().getConnection(), + connection, getAddress()); return card.getAvatar(); @@ -313,5 +319,4 @@ private byte[] getAvatar() return null; } - -} +} \ No newline at end of file diff --git a/src/net/java/sip/communicator/plugin/aimaccregwizz/AimAccRegWizzActivator.java b/src/net/java/sip/communicator/plugin/aimaccregwizz/AimAccRegWizzActivator.java new file mode 100644 index 000000000..85786f0e0 --- /dev/null +++ b/src/net/java/sip/communicator/plugin/aimaccregwizz/AimAccRegWizzActivator.java @@ -0,0 +1,95 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.plugin.aimaccregwizz; + +import net.java.sip.communicator.service.browserlauncher.*; +import net.java.sip.communicator.service.gui.*; +import net.java.sip.communicator.service.protocol.*; +import net.java.sip.communicator.util.*; + +import org.osgi.framework.*; + +/** + * Registers the AimAccountRegistrationWizard in the UI Service. + * + * @author Yana Stamcheva + */ +public class AimAccRegWizzActivator implements BundleActivator { + + public static BundleContext bundleContext; + + private static Logger logger = Logger.getLogger( + AimAccRegWizzActivator.class); + + private static BrowserLauncherService browserLauncherService; + + /** + * Starts this bundle. + */ + public void start(BundleContext bc) throws Exception { + + bundleContext = bc; + + ServiceReference uiServiceRef = bundleContext + .getServiceReference(UIService.class.getName()); + + UIService uiService + = (UIService) bundleContext.getService(uiServiceRef); + + AccountRegistrationWizardContainer wizardContainer + = uiService.getAccountRegWizardContainer(); + + AimAccountRegistrationWizard aimWizard + = new AimAccountRegistrationWizard(wizardContainer); + + wizardContainer.addAccountRegistrationWizard(aimWizard); + } + + public void stop(BundleContext bundleContext) throws Exception { + } + + /** + * Returns the ProtocolProviderFactory for the AIM protocol. + * @return the ProtocolProviderFactory for the AIM protocol + */ + public static ProtocolProviderFactory getAimProtocolProviderFactory() { + + ServiceReference[] serRefs = null; + + String osgiFilter = "(" + + ProtocolProviderFactory.PROTOCOL + + "="+ProtocolNames.AIM+")"; + + try { + serRefs = bundleContext.getServiceReferences( + ProtocolProviderFactory.class.getName(), osgiFilter); + } + catch (InvalidSyntaxException ex){ + logger.error("AimAccRegWizzActivator : " + ex); + } + + return (ProtocolProviderFactory) bundleContext.getService(serRefs[0]); + } + + /** + * Returns the BrowserLauncherService obtained from the bundle + * context. + * @return the BrowserLauncherService obtained from the bundle + * context + */ + public static BrowserLauncherService getBrowserLauncher() { + if (browserLauncherService == null) { + ServiceReference serviceReference = bundleContext + .getServiceReference(BrowserLauncherService.class.getName()); + + browserLauncherService = (BrowserLauncherService) bundleContext + .getService(serviceReference); + } + + return browserLauncherService; + } +} diff --git a/src/net/java/sip/communicator/plugin/aimaccregwizz/AimAccountRegistration.java b/src/net/java/sip/communicator/plugin/aimaccregwizz/AimAccountRegistration.java new file mode 100644 index 000000000..54d14f376 --- /dev/null +++ b/src/net/java/sip/communicator/plugin/aimaccregwizz/AimAccountRegistration.java @@ -0,0 +1,161 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.plugin.aimaccregwizz; + +/** + * The AimAccountRegistration is used to store all user input data + * through the AimAccountRegistrationWizard. + * + * @author Yana Stamcheva + */ +public class AimAccountRegistration { + + private String uin; + + private String password; + + private boolean rememberPassword; + + private String proxyPort; + + private String proxy; + + private String proxyType; + + private String proxyUsername; + + private String proxyPassword; + + /** + * Returns the password of the aim registration account. + * @return the password of the aim registration account. + */ + public String getPassword() { + return password; + } + + /** + * Sets the password of the aim registration account. + * @param password the password of the aim registration account. + */ + public void setPassword(String password) { + this.password = password; + } + + /** + * Returns TRUE if password has to remembered, FALSE otherwise. + * @return TRUE if password has to remembered, FALSE otherwise + */ + public boolean isRememberPassword() { + return rememberPassword; + } + + /** + * Sets the rememberPassword value of this aim account registration. + * @param rememberPassword TRUE if password has to remembered, FALSE + * otherwise + */ + public void setRememberPassword(boolean rememberPassword) { + this.rememberPassword = rememberPassword; + } + + /** + * Returns the UIN of the aim registration account. + * @return the UIN of the aim registration account. + */ + public String getUin() { + return uin; + } + + /** + * Sets the UIN of the aim registration account. + * @param uin the UIN of the aim registration account. + */ + public void setUin(String uin) { + this.uin = uin; + } + + /** + * Returns the proxy that will be used for this aim account. + * @return the proxy that will be used for this aim account. + */ + public String getProxy() { + return proxy; + } + + /** + * Sets the proxy for this aim account. + * @param proxy the proxy for this aim account. + */ + public void setProxy(String proxy) { + this.proxy = proxy; + } + + /** + * Returns the proxy port that will be used for this aim account. + * @return the proxy port that will be used for this aim account. + */ + public String getProxyPort() { + return proxyPort; + } + + /** + * Sets the proxy port for this aim account. + * @param proxyPort the proxy port for this aim account. + */ + public void setProxyPort(String proxyPort) { + this.proxyPort = proxyPort; + } + + /** + * Returns the proxy type that will be used for this aim account. + * @return the proxy type that will be used for this aim account. + */ + public String getProxyType() { + return proxyType; + } + + /** + * Sets the proxy type for this aim account. + * @param proxyType the proxy type for this aim account + */ + public void setProxyType(String proxyType) { + this.proxyType = proxyType; + } + + /** + * Returns the proxy password of the aim registration account. + * @return the proxy password of the aim registration account. + */ + public String getProxyPassword() { + return proxyPassword; + } + + /** + * Sets the proxy password of the aim registration account. + * @param password the proxy password of the aim registration account. + */ + public void setProxyPassword(String password) { + this.proxyPassword = password; + } + + /** + * Returns the proxy username of the aim registration account. + * @return the proxy username of the aim registration account. + */ + public String getProxyUsername() { + return proxyUsername; + } + + /** + * Sets the proxy username of the aim registration account. + * @param username the proxy username of the aim registration account + */ + public void setProxyUsername(String username) { + this.proxyUsername = username; + } +} diff --git a/src/net/java/sip/communicator/plugin/aimaccregwizz/AimAccountRegistrationWizard.java b/src/net/java/sip/communicator/plugin/aimaccregwizz/AimAccountRegistrationWizard.java new file mode 100644 index 000000000..70d74b1d0 --- /dev/null +++ b/src/net/java/sip/communicator/plugin/aimaccregwizz/AimAccountRegistrationWizard.java @@ -0,0 +1,216 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.plugin.aimaccregwizz; + +import java.util.*; + +import net.java.sip.communicator.impl.gui.customcontrols.*; +import net.java.sip.communicator.plugin.gibberishaccregwizz.*; +import net.java.sip.communicator.service.gui.*; +import net.java.sip.communicator.service.protocol.*; + +import org.osgi.framework.*; + +/** + * The AimAccountRegistrationWizard is an implementation of the + * AccountRegistrationWizard for the AIM protocol. It should allow + * the user to create and configure a new AIM account. + * + * @author Yana Stamcheva + */ +public class AimAccountRegistrationWizard implements AccountRegistrationWizard +{ + private FirstWizardPage firstWizardPage; + + private AimAccountRegistration registration + = new AimAccountRegistration(); + + private WizardContainer wizardContainer; + + private ProtocolProviderService protocolProvider; + + private boolean isModification; + + /** + * Creates an instance of AimAccountRegistrationWizard. + * @param wizardContainer the wizard container, where this wizard + * is added + */ + public AimAccountRegistrationWizard(WizardContainer wizardContainer) { + this.wizardContainer = wizardContainer; + } + + /** + * Implements the AccountRegistrationWizard.getIcon method. + * Returns the icon to be used for this wizard. + */ + public byte[] getIcon() { + return Resources.getImage(Resources.AIM_LOGO); + } + + /** + * Implements the AccountRegistrationWizard.getPageImage method. + * Returns the image used to decorate the wizard page + * + * @return byte[] the image used to decorate the wizard page + */ + public byte[] getPageImage() + { + return Resources.getImage(Resources.PAGE_IMAGE); + } + + /** + * Implements the AccountRegistrationWizard.getProtocolName + * method. Returns the protocol name for this wizard. + */ + public String getProtocolName() { + return Resources.getString("protocolName"); + } + + /** + * Implements the AccountRegistrationWizard.getProtocolDescription + * method. Returns the description of the protocol for this wizard. + */ + public String getProtocolDescription() { + return Resources.getString("protocolDescription"); + } + + /** + * Returns the set of pages contained in this wizard. + */ + public Iterator getPages() { + ArrayList pages = new ArrayList(); + firstWizardPage = new FirstWizardPage(registration, wizardContainer); + + pages.add(firstWizardPage); + + return pages.iterator(); + } + + /** + * Returns the set of data that user has entered through this wizard. + */ + public Iterator getSummary() { + Hashtable summaryTable = new Hashtable(); + + summaryTable.put("UIN", registration.getUin()); + summaryTable.put("Remember password", + new Boolean(registration.isRememberPassword())); + + if(registration.getProxy() != null) + summaryTable.put(Resources.getString("proxy"), + registration.getProxy()); + + if(registration.getProxyPort() != null) + summaryTable.put(Resources.getString("proxyPort"), + registration.getProxyPort()); + + if(registration.getProxyType() != null) + summaryTable.put(Resources.getString("proxyType"), + registration.getProxyType()); + + if(registration.getProxyPort() != null) + summaryTable.put(Resources.getString("proxyUsername"), + registration.getProxyPort()); + + if(registration.getProxyType() != null) + summaryTable.put(Resources.getString("proxyPassword"), + registration.getProxyType()); + + return summaryTable.entrySet().iterator(); + } + + /** + * Installs the account created through this wizard. + */ + public ProtocolProviderService finish() { + firstWizardPage = null; + ProtocolProviderFactory factory + = AimAccRegWizzActivator.getAimProtocolProviderFactory(); + + return this.installAccount(factory, + registration.getUin(), registration.getPassword()); + } + + /** + * Creates an account for the given user and password. + * @param providerFactory the ProtocolProviderFactory which will create + * the account + * @param user the user identifier + * @param passwd the password + * @return the ProtocolProviderService for the new account. + */ + public ProtocolProviderService installAccount( + ProtocolProviderFactory providerFactory, + String user, + String passwd) { + + Hashtable accountProperties = new Hashtable(); + + if(registration.isRememberPassword()) { + accountProperties.put(ProtocolProviderFactory.PASSWORD, passwd); + } + + if(registration.getProxyType() != null) + { + accountProperties.put(ProtocolProviderFactory.PROXY_ADDRESS, + registration.getProxy()); + + accountProperties.put(ProtocolProviderFactory.PROXY_PORT, + registration.getProxyPort()); + + accountProperties.put(ProtocolProviderFactory.PROXY_TYPE, + registration.getProxyType()); + + accountProperties.put(ProtocolProviderFactory.PROXY_USERNAME, + registration.getProxyUsername()); + + accountProperties.put(ProtocolProviderFactory.PROXY_PASSWORD, + registration.getProxyPassword()); + } + + if(isModification) { + providerFactory.uninstallAccount(protocolProvider.getAccountID()); + this.protocolProvider = null; + } + + try { + AccountID accountID = providerFactory.installAccount( + user, accountProperties); + + ServiceReference serRef = providerFactory + .getProviderForAccount(accountID); + + protocolProvider + = (ProtocolProviderService) AimAccRegWizzActivator.bundleContext + .getService(serRef); + } + catch (IllegalArgumentException e) { + new ErrorDialog(null, e.getMessage(), e).showDialog(); + } + catch (IllegalStateException e) { + new ErrorDialog(null, e.getMessage(), e).showDialog(); + } + + return protocolProvider; + } + + /** + * Fills the UIN and Password fields in this panel with the data comming + * from the given protocolProvider. + * @param protocolProvider The ProtocolProviderService to load the + * data from. + */ + public void loadAccount(ProtocolProviderService protocolProvider) { + + this.protocolProvider = protocolProvider; + + this.firstWizardPage.loadAccount(protocolProvider); + + this.isModification = true; + } +} diff --git a/src/net/java/sip/communicator/plugin/aimaccregwizz/FirstWizardPage.java b/src/net/java/sip/communicator/plugin/aimaccregwizz/FirstWizardPage.java new file mode 100644 index 000000000..3533308a6 --- /dev/null +++ b/src/net/java/sip/communicator/plugin/aimaccregwizz/FirstWizardPage.java @@ -0,0 +1,405 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.plugin.aimaccregwizz; + +import java.awt.*; +import java.awt.event.*; +import java.util.*; + +import javax.swing.*; +import javax.swing.event.*; + +import net.java.sip.communicator.service.gui.*; +import net.java.sip.communicator.service.protocol.*; + +/** + * The FirstWizardPage is the page, where user could enter the uin + * and the password of the account. + * + * @author Yana Stamcheva + */ +public class FirstWizardPage extends JPanel + implements WizardPage, + DocumentListener, + ActionListener { + + public static final String FIRST_PAGE_IDENTIFIER = "FirstPageIdentifier"; + + private JPanel uinPassPanel = new JPanel(new BorderLayout(10, 10)); + + private JPanel labelsPanel = new JPanel(); + + private JPanel valuesPanel = new JPanel(); + + private JPanel advancedOpPanel = new JPanel(new BorderLayout(10, 10)); + + private JPanel labelsAdvOpPanel = new JPanel(new GridLayout(0, 1, 10, 10)); + + private JPanel valuesAdvOpPanel = new JPanel(new GridLayout(0, 1, 10, 10)); + + private JCheckBox enableAdvOpButton = new JCheckBox( + Resources.getString("ovverideServerOps"), false); + + private JLabel uinLabel = new JLabel(Resources.getString("uin")); + + private JPanel emptyPanel = new JPanel(); + + private JLabel uinExampleLabel = new JLabel("Ex: 83378997"); + + private JLabel passLabel = new JLabel(Resources.getString("password")); + + private JLabel existingAccountLabel + = new JLabel(Resources.getString("existingAccount")); + + private JTextField uinField = new JTextField(); + + private JPasswordField passField = new JPasswordField(); + + private JCheckBox rememberPassBox = new JCheckBox( + Resources.getString("rememberPassword")); + + private JPanel registerPanel = new JPanel(new GridLayout(0, 1)); + + private JPanel buttonPanel = new JPanel( + new FlowLayout(FlowLayout.CENTER)); + + private JTextArea registerArea = new JTextArea( + Resources.getString("registerNewAccountText")); + + private JButton registerButton = new JButton( + Resources.getString("registerNewAccount")); + + private JLabel proxyLabel = new JLabel(Resources.getString("proxy")); + + private JLabel proxyPortLabel = new JLabel(Resources.getString("proxyPort")); + + private JLabel proxyUsernameLabel = new JLabel(Resources.getString("proxyUsername")); + + private JLabel proxyPasswordLabel = new JLabel(Resources.getString("proxyPassword")); + + private JLabel proxyTypeLabel = new JLabel(Resources.getString("proxyType")); + + private JTextField proxyField = new JTextField(); + + private JTextField proxyPortField = new JTextField(); + + private JTextField proxyUsernameField = new JTextField(); + + private JPasswordField proxyPassField = new JPasswordField(); + + private JComboBox proxyTypeCombo = new JComboBox( + new Object[]{"http", "socks5", "socks4"}); + + private JPanel mainPanel = new JPanel(); + + private Object nextPageIdentifier = WizardPage.SUMMARY_PAGE_IDENTIFIER; + + private AimAccountRegistration registration; + + private WizardContainer wizardContainer; + + /** + * Creates an instance of FirstWizardPage. + * @param registration the AimAccountRegistration, where + * all data through the wizard are stored + * @param wizardContainer the wizardContainer, where this page will + * be added + */ + public FirstWizardPage(AimAccountRegistration registration, + WizardContainer wizardContainer) { + + super(new BorderLayout()); + + this.wizardContainer = wizardContainer; + + this.registration = registration; + + this.setPreferredSize(new Dimension(600, 500)); + + mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); + + this.init(); + + this.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); + + this.labelsPanel.setLayout(new BoxLayout(labelsPanel, BoxLayout.Y_AXIS)); + + this.valuesPanel.setLayout(new BoxLayout(valuesPanel, BoxLayout.Y_AXIS)); + } + + /** + * Initializes all panels, buttons, etc. + */ + private void init() { + this.registerButton.addActionListener(this); + this.uinField.getDocument().addDocumentListener(this); + this.rememberPassBox.setSelected(true); + + this.existingAccountLabel.setForeground(Color.RED); + + this.uinExampleLabel.setForeground(Color.GRAY); + this.uinExampleLabel.setFont(uinExampleLabel.getFont().deriveFont(8)); + this.emptyPanel.setMaximumSize(new Dimension(40, 35)); + this.uinExampleLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 8, 0)); + + labelsPanel.add(uinLabel); + labelsPanel.add(emptyPanel); + labelsPanel.add(passLabel); + + valuesPanel.add(uinField); + valuesPanel.add(uinExampleLabel); + valuesPanel.add(passField); + + uinPassPanel.add(labelsPanel, BorderLayout.WEST); + uinPassPanel.add(valuesPanel, BorderLayout.CENTER); + uinPassPanel.add(rememberPassBox, BorderLayout.SOUTH); + + uinPassPanel.setBorder(BorderFactory + .createTitledBorder(Resources.getString("uinAndPassword"))); + + mainPanel.add(uinPassPanel); + + proxyField.setEditable(false); + proxyPortField.setEditable(false); + proxyTypeCombo.setEnabled(false); + + enableAdvOpButton.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent evt) { + // Perform action + JCheckBox cb = (JCheckBox)evt.getSource(); + + proxyField.setEditable(cb.isSelected()); + proxyPortField.setEditable(cb.isSelected()); + proxyTypeCombo.setEnabled(cb.isSelected()); + }}); + + proxyTypeCombo.setSelectedItem("http"); + + labelsAdvOpPanel.add(proxyLabel); + labelsAdvOpPanel.add(proxyPortLabel); + labelsAdvOpPanel.add(proxyTypeLabel); + labelsAdvOpPanel.add(proxyUsernameLabel); + labelsAdvOpPanel.add(proxyPasswordLabel); + + valuesAdvOpPanel.add(proxyField); + valuesAdvOpPanel.add(proxyPortField); + valuesAdvOpPanel.add(proxyTypeCombo); + valuesAdvOpPanel.add(proxyUsernameField); + valuesAdvOpPanel.add(proxyPassField); + + advancedOpPanel.add(enableAdvOpButton, BorderLayout.NORTH); + advancedOpPanel.add(labelsAdvOpPanel, BorderLayout.WEST); + advancedOpPanel.add(valuesAdvOpPanel, BorderLayout.CENTER); + + advancedOpPanel.setBorder(BorderFactory + .createTitledBorder(Resources.getString( + "advancedOptions"))); + + mainPanel.add(advancedOpPanel); + + + this.buttonPanel.add(registerButton); + + this.registerArea.setEditable(false); + this.registerArea.setLineWrap(true); + this.registerArea.setWrapStyleWord(true); + + this.registerPanel.add(registerArea); + this.registerPanel.add(buttonPanel); + + this.registerPanel.setBorder(BorderFactory + .createTitledBorder(Resources.getString("registerNewAccount"))); + + mainPanel.add(registerPanel); + + this.add(mainPanel, BorderLayout.NORTH); + } + + /** + * Implements the WizardPage.getIdentifier to return + * this page identifier. + */ + public Object getIdentifier() { + return FIRST_PAGE_IDENTIFIER; + } + + /** + * Implements the WizardPage.getNextPageIdentifier to return + * the next page identifier - the summary page. + */ + public Object getNextPageIdentifier() { + return nextPageIdentifier; + } + + /** + * Implements the WizardPage.getBackPageIdentifier to return + * the next back identifier - the default page. + */ + public Object getBackPageIdentifier() { + return WizardPage.DEFAULT_PAGE_IDENTIFIER; + } + + /** + * Implements the WizardPage.getWizardForm to return + * this panel. + */ + public Object getWizardForm() { + return this; + } + + /** + * Before this page is displayed enables or disables the "Next" wizard + * button according to whether the UIN field is empty. + */ + public void pageShowing() { + this.setNextButtonAccordingToUIN(); + } + + /** + * Saves the user input when the "Next" wizard buttons is clicked. + */ + public void pageNext() { + String uin = uinField.getText(); + + if(isExistingAccount(uin)) { + nextPageIdentifier = FIRST_PAGE_IDENTIFIER; + uinPassPanel.add(existingAccountLabel, BorderLayout.NORTH); + this.revalidate(); + } + else { + nextPageIdentifier = SUMMARY_PAGE_IDENTIFIER; + uinPassPanel.remove(existingAccountLabel); + + registration.setUin(uin); + registration.setPassword(new String(passField.getPassword())); + registration.setRememberPassword(rememberPassBox.isSelected()); + + if(enableAdvOpButton.isSelected()) + { + registration.setProxy(proxyField.getText()); + registration.setProxyPort(proxyPortField.getText()); + registration.setProxyType( + proxyTypeCombo.getSelectedItem().toString()); + registration.setProxyUsername(proxyUsernameField.getText()); + registration.setProxyPassword(new String(proxyPassField.getPassword())); + } + } + } + + /** + * Enables or disables the "Next" wizard button according to whether the + * UIN field is empty. + */ + private void setNextButtonAccordingToUIN() { + if (uinField.getText() == null || uinField.getText().equals("")) { + wizardContainer.setNextFinishButtonEnabled(false); + } + else { + wizardContainer.setNextFinishButtonEnabled(true); + } + } + + /** + * Handles the DocumentEvent triggered when user types in the + * UIN field. Enables or disables the "Next" wizard button according to + * whether the UIN field is empty. + */ + public void insertUpdate(DocumentEvent e) { + this.setNextButtonAccordingToUIN(); + } + + /** + * Handles the DocumentEvent triggered when user deletes letters + * from the UIN field. Enables or disables the "Next" wizard button + * according to whether the UIN field is empty. + */ + public void removeUpdate(DocumentEvent e) { + this.setNextButtonAccordingToUIN(); + } + + public void changedUpdate(DocumentEvent e) { + } + + public void pageHiding() { + } + + public void pageShown() { + } + + public void pageBack() { + } + + /** + * Fills the UIN and Password fields in this panel with the data comming + * from the given protocolProvider. + * @param protocolProvider The ProtocolProviderService to load the + * data from. + */ + public void loadAccount(ProtocolProviderService protocolProvider) { + AccountID accountID = protocolProvider.getAccountID(); + String password = (String)accountID.getAccountProperties() + .get(ProtocolProviderFactory.PASSWORD); + + this.uinField.setText(accountID.getUserID()); + + if(password != null) { + this.passField.setText(password); + + this.rememberPassBox.setSelected(true); + } + + String proxyAddress = (String)accountID.getAccountProperties() + .get(ProtocolProviderFactory.PROXY_ADDRESS); + + String proxyPort = (String)accountID.getAccountProperties() + .get(ProtocolProviderFactory.PROXY_PORT); + + String proxyType = (String)accountID.getAccountProperties() + .get(ProtocolProviderFactory.PROXY_TYPE); + + String proxyUsername = (String)accountID.getAccountProperties() + .get(ProtocolProviderFactory.PROXY_USERNAME); + + String proxyPassword = (String)accountID.getAccountProperties() + .get(ProtocolProviderFactory.PROXY_PASSWORD); + + proxyField.setText(proxyAddress); + proxyPortField.setText(proxyPort); + proxyTypeCombo.setSelectedItem(proxyType); + proxyUsernameField.setText(proxyUsername); + proxyPassField.setText(proxyPassword); + } + + public void actionPerformed(ActionEvent e) + { + AimAccRegWizzActivator.getBrowserLauncher() + .openURL("http://my.screenname.aol.com/_cqr/login/login.psp?seamless=n&createSn=1"); + } + + /** + * Checks if an acount with the given account already exists. + * + * @param accountName the name of the account to check + * @return TRUE, if an account with the given name already exists, FALSE - + * otherwise + */ + private boolean isExistingAccount(String accountName) + { + ProtocolProviderFactory factory + = AimAccRegWizzActivator.getAimProtocolProviderFactory(); + + ArrayList registeredAccounts = factory.getRegisteredAccounts(); + + for(int i = 0; i < registeredAccounts.size(); i ++) { + AccountID accountID = (AccountID) registeredAccounts.get(i); + + if(accountName.equalsIgnoreCase(accountID.getUserID())) + return true; + } + return false; + } +} diff --git a/src/net/java/sip/communicator/plugin/aimaccregwizz/Resources.java b/src/net/java/sip/communicator/plugin/aimaccregwizz/Resources.java new file mode 100644 index 000000000..9f74eeda6 --- /dev/null +++ b/src/net/java/sip/communicator/plugin/aimaccregwizz/Resources.java @@ -0,0 +1,83 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ + +package net.java.sip.communicator.plugin.aimaccregwizz; + +import java.io.*; +import java.util.*; + +import net.java.sip.communicator.util.*; +/** + * The Messages class manages the access to the internationalization + * properties files. + * @author Yana Stamcheva + */ +public class Resources { + + private static Logger log = Logger.getLogger(Resources.class); + + private static final String BUNDLE_NAME + = "net.java.sip.communicator.plugin.aimaccregwizz.resources"; + + private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle + .getBundle(BUNDLE_NAME); + + public static ImageID AIM_LOGO = new ImageID("protocolIcon"); + + public static ImageID PAGE_IMAGE = new ImageID("pageImage"); + + /** + * Returns an internationalized string corresponding to the given key. + * @param key The key of the string. + * @return An internationalized string corresponding to the given key. + */ + public static String getString(String key) { + try { + return RESOURCE_BUNDLE.getString(key); + + } catch (MissingResourceException e) { + + return '!' + key + '!'; + } + } + + /** + * Loads an image from a given image identifier. + * @param imageID The identifier of the image. + * @return The image for the given identifier. + */ + public static byte[] getImage(ImageID imageID) { + byte[] image = new byte[100000]; + + String path = Resources.getString(imageID.getId()); + try { + Resources.class.getClassLoader() + .getResourceAsStream(path).read(image); + + } catch (IOException e) { + log.error("Failed to load image:" + path, e); + } + + return image; + } + + /** + * Represents the Image Identifier. + */ + public static class ImageID { + private String id; + + private ImageID(String id) { + this.id = id; + } + + public String getId() { + return id; + } + } + +} diff --git a/src/net/java/sip/communicator/plugin/aimaccregwizz/aimaccregwizz.manifest.mf b/src/net/java/sip/communicator/plugin/aimaccregwizz/aimaccregwizz.manifest.mf new file mode 100644 index 000000000..dd0809f16 --- /dev/null +++ b/src/net/java/sip/communicator/plugin/aimaccregwizz/aimaccregwizz.manifest.mf @@ -0,0 +1,31 @@ +Bundle-Activator: net.java.sip.communicator.plugin.aimaccregwizz.AimAccRegWizzActivator +Bundle-Name: AIM account registration wizard +Bundle-Description: AIM account registration wizard. +Bundle-Vendor: sip-communicator.org +Bundle-Version: 0.0.1 +Import-Package: org.osgi.framework, + net.java.sip.communicator.util, + net.java.sip.communicator.service.configuration, + net.java.sip.communicator.service.configuration.event, + net.java.sip.communicator.service.protocol, + net.java.sip.communicator.service.protocol.icqconstants, + net.java.sip.communicator.service.protocol.event, + net.java.sip.communicator.service.contactlist, + net.java.sip.communicator.service.contactlist.event, + net.java.sip.communicator.service.gui, + net.java.sip.communicator.service.gui.event, + net.java.sip.communicator.service.browserlauncher, + javax.swing, + javax.swing.event, + javax.swing.table, + javax.swing.text, + javax.swing.text.html, + javax.accessibility, + javax.swing.plaf, + javax.swing.plaf.metal, + javax.swing.plaf.basic, + javax.imageio, + javax.swing.filechooser, + javax.swing.tree, + javax.swing.undo, + javax.swing.border \ No newline at end of file diff --git a/src/net/java/sip/communicator/plugin/aimaccregwizz/resources.properties b/src/net/java/sip/communicator/plugin/aimaccregwizz/resources.properties new file mode 100644 index 000000000..f749fa237 --- /dev/null +++ b/src/net/java/sip/communicator/plugin/aimaccregwizz/resources.properties @@ -0,0 +1,19 @@ +protocolName=AIM +protocolDescription=The AIM service protocol +uin=AIM Screenname: +password=Password: +rememberPassword=Remember password +uinAndPassword=UIN and Password +registerNewAccount=Register new account +registerNewAccountText=In case you don't have an AIM account, click on this button to create a new one. +existingAccount=* The account you entered is already installed. +ovverideServerOps=Override server default options +advancedOptions=Advanced Options +proxy=Proxy +proxyPort=Proxy port +proxyType=Proxy type +proxyUsername=Proxy username +proxyPassword=Proxy password + +protocolIcon=resources/images/aim/aim16x16-online.png +pageImage=resources/images/aim/aim64x64.png