Aim wizard and some improvments on the loading of accounts for the aim/icq protocol.

cusax-fix
Damian Minkov 19 years ago
parent 75b88bb5a6
commit 214e73f509

@ -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"/>
</jar>
</target>
<!-- BUNDLE-PLUGIN-AIMACCREGWIZZ -->
<target name="bundle-plugin-aimaccregwizz">
<!-- Creates a bundle for the plugin Aim Account Registration Wizard.-->
<jar compress="false" destfile="${bundles.dest}/aimaccregwizz.jar"
manifest="src/net/java/sip/communicator/plugin/aimaccregwizz/aimaccregwizz.manifest.mf">
<zipfileset dir="${dest}/net/java/sip/communicator/plugin/aimaccregwizz"
prefix="net/java/sip/communicator/plugin/aimaccregwizz"/>
<zipfileset dir="resources/images/aim"
prefix="resources/images/aim"/>
</jar>
</target>
<!-- BUNDLE-PLUGIN-JABBERACCREGWIZZ -->
<target name="bundle-plugin-jabberaccregwizz">

@ -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 \

@ -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;
}
}

@ -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 <tt>ProtocolProviderFactoryIcqImpl</tt>
* 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 <tt>ProtocolProviderFactoryIcqImpl</tt>
* 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();
}
}

@ -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

@ -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,

@ -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.

@ -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;
}
}
}

@ -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 <tt>AimAccountRegistrationWizard</tt> 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 <tt>ProtocolProviderFactory</tt> for the AIM protocol.
* @return the <tt>ProtocolProviderFactory</tt> 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 <tt>BrowserLauncherService</tt> obtained from the bundle
* context.
* @return the <tt>BrowserLauncherService</tt> 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;
}
}

@ -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 <tt>AimAccountRegistration</tt> is used to store all user input data
* through the <tt>AimAccountRegistrationWizard</tt>.
*
* @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;
}
}

@ -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 <tt>AimAccountRegistrationWizard</tt> is an implementation of the
* <tt>AccountRegistrationWizard</tt> 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 <tt>AimAccountRegistrationWizard</tt>.
* @param wizardContainer the wizard container, where this wizard
* is added
*/
public AimAccountRegistrationWizard(WizardContainer wizardContainer) {
this.wizardContainer = wizardContainer;
}
/**
* Implements the <code>AccountRegistrationWizard.getIcon</code> method.
* Returns the icon to be used for this wizard.
*/
public byte[] getIcon() {
return Resources.getImage(Resources.AIM_LOGO);
}
/**
* Implements the <code>AccountRegistrationWizard.getPageImage</code> 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 <code>AccountRegistrationWizard.getProtocolName</code>
* method. Returns the protocol name for this wizard.
*/
public String getProtocolName() {
return Resources.getString("protocolName");
}
/**
* Implements the <code>AccountRegistrationWizard.getProtocolDescription
* </code> 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 <tt>ProtocolProviderService</tt> 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 <tt>ProtocolProviderService</tt> to load the
* data from.
*/
public void loadAccount(ProtocolProviderService protocolProvider) {
this.protocolProvider = protocolProvider;
this.firstWizardPage.loadAccount(protocolProvider);
this.isModification = true;
}
}

@ -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 <tt>FirstWizardPage</tt> 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 <tt>FirstWizardPage</tt>.
* @param registration the <tt>AimAccountRegistration</tt>, 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 <code>WizardPage.getIdentifier</code> to return
* this page identifier.
*/
public Object getIdentifier() {
return FIRST_PAGE_IDENTIFIER;
}
/**
* Implements the <code>WizardPage.getNextPageIdentifier</code> to return
* the next page identifier - the summary page.
*/
public Object getNextPageIdentifier() {
return nextPageIdentifier;
}
/**
* Implements the <code>WizardPage.getBackPageIdentifier</code> to return
* the next back identifier - the default page.
*/
public Object getBackPageIdentifier() {
return WizardPage.DEFAULT_PAGE_IDENTIFIER;
}
/**
* Implements the <code>WizardPage.getWizardForm</code> 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 <tt>DocumentEvent</tt> 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 <tt>DocumentEvent</tt> 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 <tt>ProtocolProviderService</tt> 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;
}
}

@ -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;
}
}
}

@ -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

@ -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
Loading…
Cancel
Save