From 2fa5a83fdd52e1384c77a51cefca633813751bca Mon Sep 17 00:00:00 2001 From: Yana Stamcheva Date: Fri, 17 Nov 2006 12:02:52 +0000 Subject: [PATCH] in all account registration wizards, check if the account entered by user is not already installed and if so, show a message to the user. --- .../plugin/icqaccregwizz/FirstWizardPage.java | 49 ++++++++++++--- .../plugin/icqaccregwizz/resources.properties | 1 + .../jabberaccregwizz/FirstWizardPage.java | 63 +++++++++++++++---- .../jabberaccregwizz/resources.properties | 1 + .../plugin/msnaccregwizz/FirstWizardPage.java | 46 ++++++++++++-- .../plugin/msnaccregwizz/resources.properties | 1 + .../plugin/sipaccregwizz/FirstWizardPage.java | 58 +++++++++++++---- .../plugin/sipaccregwizz/resources.properties | 1 + 8 files changed, 184 insertions(+), 36 deletions(-) diff --git a/src/net/java/sip/communicator/plugin/icqaccregwizz/FirstWizardPage.java b/src/net/java/sip/communicator/plugin/icqaccregwizz/FirstWizardPage.java index bf129b3e4..158af3e4e 100644 --- a/src/net/java/sip/communicator/plugin/icqaccregwizz/FirstWizardPage.java +++ b/src/net/java/sip/communicator/plugin/icqaccregwizz/FirstWizardPage.java @@ -8,11 +8,11 @@ import java.awt.*; import java.awt.event.*; +import java.util.*; import javax.swing.*; import javax.swing.event.*; -import net.java.sip.communicator.impl.gui.utils.*; import net.java.sip.communicator.service.gui.*; import net.java.sip.communicator.service.protocol.*; @@ -39,6 +39,9 @@ public class FirstWizardPage extends JPanel 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(); @@ -59,6 +62,8 @@ public class FirstWizardPage extends JPanel private JPanel mainPanel = new JPanel(); + private Object nextPageIdentifier = WizardPage.SUMMARY_PAGE_IDENTIFIER; + private IcqAccountRegistration registration; private WizardContainer wizardContainer; @@ -95,6 +100,8 @@ private void init() { this.registerButton.addActionListener(this); this.uinField.getDocument().addDocumentListener(this); this.rememberPassBox.setSelected(true); + + this.existingAccountLabel.setForeground(Color.RED); labelsPanel.add(uinLabel); labelsPanel.add(passLabel); @@ -140,8 +147,8 @@ public Object getIdentifier() { * Implements the WizardPage.getNextPageIdentifier to return * the next page identifier - the summary page. */ - public Object getNextPageIdentifier() { - return WizardPage.SUMMARY_PAGE_IDENTIFIER; + public Object getNextPageIdentifier() { + return nextPageIdentifier; } /** @@ -172,9 +179,21 @@ public void pageShowing() { * Saves the user input when the "Next" wizard buttons is clicked. */ public void pageNext() { - registration.setUin(uinField.getText()); - registration.setPassword(new String(passField.getPassword())); - registration.setRememberPassword(rememberPassBox.isSelected()); + 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()); + } } /** @@ -242,6 +261,22 @@ public void loadAccount(ProtocolProviderService protocolProvider) { public void actionPerformed(ActionEvent e) { - CrossPlatformBrowserLauncher.openURL("https://www.icq.com/register/"); + CrossPlatformBrowserLauncher.openURL("https://www.icq.com/register/"); + } + + private boolean isExistingAccount(String accountName) + { + ProtocolProviderFactory factory + = IcqAccRegWizzActivator.getIcqProtocolProviderFactory(); + + 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/icqaccregwizz/resources.properties b/src/net/java/sip/communicator/plugin/icqaccregwizz/resources.properties index 675a15b32..762db6f64 100644 --- a/src/net/java/sip/communicator/plugin/icqaccregwizz/resources.properties +++ b/src/net/java/sip/communicator/plugin/icqaccregwizz/resources.properties @@ -6,5 +6,6 @@ rememberPassword=Remember password uinAndPassword=UIN and Password registerNewAccount=Register new account registerNewAccountText=In case you don't have an ICQ account, click on this button to create a new one. +existingAccount=* The account you entered is already installed. protocolIcon=net/java/sip/communicator/plugin/icqaccregwizz/resources/Icq.png \ No newline at end of file diff --git a/src/net/java/sip/communicator/plugin/jabberaccregwizz/FirstWizardPage.java b/src/net/java/sip/communicator/plugin/jabberaccregwizz/FirstWizardPage.java index 44bc4b5cc..7c78a70f4 100644 --- a/src/net/java/sip/communicator/plugin/jabberaccregwizz/FirstWizardPage.java +++ b/src/net/java/sip/communicator/plugin/jabberaccregwizz/FirstWizardPage.java @@ -8,6 +8,8 @@ import java.awt.*; import java.awt.event.*; +import java.util.*; + import javax.swing.*; import javax.swing.event.*; @@ -36,9 +38,12 @@ public class FirstWizardPage extends JPanel private JPanel valuesPanel = new JPanel(new GridLayout(0, 1, 10, 10)); private JLabel uinLabel = new JLabel(Resources.getString("uin")); - + 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(); @@ -66,6 +71,8 @@ public class FirstWizardPage extends JPanel private JPanel mainPanel = new JPanel(); + private Object nextPageIdentifier = WizardPage.SUMMARY_PAGE_IDENTIFIER; + private JabberAccountRegistration registration; private WizardContainer wizardContainer; @@ -102,6 +109,8 @@ private void init() { this.uinField.getDocument().addDocumentListener(this); this.rememberPassBox.setSelected(true); + this.existingAccountLabel.setForeground(Color.RED); + labelsPanel.add(uinLabel); labelsPanel.add(passLabel); @@ -177,7 +186,7 @@ public Object getIdentifier() { * the next page identifier - the summary page. */ public Object getNextPageIdentifier() { - return WizardPage.SUMMARY_PAGE_IDENTIFIER; + return nextPageIdentifier; } /** @@ -208,18 +217,30 @@ public void pageShowing() { * Saves the user input when the "Next" wizard buttons is clicked. */ public void pageNext() { - registration.setUin(uinField.getText()); - registration.setPassword(new String(passField.getPassword())); - registration.setRememberPassword(rememberPassBox.isSelected()); - - registration.setServerAddress(serverField.getText()); - registration.setSendKeepAlive(sendKeepAliveBox.isSelected()); - try - { - registration.setPort(Integer.parseInt(portField.getText())); + 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(uinField.getText()); + registration.setPassword(new String(passField.getPassword())); + registration.setRememberPassword(rememberPassBox.isSelected()); + + registration.setServerAddress(serverField.getText()); + registration.setSendKeepAlive(sendKeepAliveBox.isSelected()); + try + { + registration.setPort(Integer.parseInt(portField.getText())); + } + catch (NumberFormatException ex) + {} } - catch (NumberFormatException ex) - {} } /** @@ -323,4 +344,20 @@ private void setNextButtonAccordingToPort() wizardContainer.setNextFinishButtonEnabled(false); } } + + private boolean isExistingAccount(String accountName) + { + ProtocolProviderFactory factory + = JabberAccRegWizzActivator.getJabberProtocolProviderFactory(); + + 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/jabberaccregwizz/resources.properties b/src/net/java/sip/communicator/plugin/jabberaccregwizz/resources.properties index 7511daf8b..1dfa21626 100755 --- a/src/net/java/sip/communicator/plugin/jabberaccregwizz/resources.properties +++ b/src/net/java/sip/communicator/plugin/jabberaccregwizz/resources.properties @@ -9,5 +9,6 @@ ovverideServerOps=Override server default options server=Connect Server port=Port sendKeepAlive=Send keep alive packets +existingAccount=* The account you entered is already installed. protocolIcon=net/java/sip/communicator/plugin/jabberaccregwizz/resources/jabber.gif diff --git a/src/net/java/sip/communicator/plugin/msnaccregwizz/FirstWizardPage.java b/src/net/java/sip/communicator/plugin/msnaccregwizz/FirstWizardPage.java index 19ff585c3..285aaff69 100644 --- a/src/net/java/sip/communicator/plugin/msnaccregwizz/FirstWizardPage.java +++ b/src/net/java/sip/communicator/plugin/msnaccregwizz/FirstWizardPage.java @@ -7,7 +7,8 @@ package net.java.sip.communicator.plugin.msnaccregwizz; import java.awt.*; -import java.awt.event.*; +import java.util.*; + import javax.swing.*; import javax.swing.event.*; @@ -36,6 +37,9 @@ public class FirstWizardPage extends JPanel 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(); @@ -44,6 +48,8 @@ public class FirstWizardPage extends JPanel Resources.getString("rememberPassword")); private JPanel mainPanel = new JPanel(); + + private Object nextPageIdentifier = WizardPage.SUMMARY_PAGE_IDENTIFIER; private MsnAccountRegistration registration; @@ -81,6 +87,8 @@ private void init() { this.uinField.getDocument().addDocumentListener(this); this.rememberPassBox.setSelected(true); + this.existingAccountLabel.setForeground(Color.RED); + labelsPanel.add(uinLabel); labelsPanel.add(passLabel); @@ -111,7 +119,7 @@ public Object getIdentifier() { * the next page identifier - the summary page. */ public Object getNextPageIdentifier() { - return WizardPage.SUMMARY_PAGE_IDENTIFIER; + return nextPageIdentifier; } /** @@ -142,9 +150,21 @@ public void pageShowing() { * Saves the user input when the "Next" wizard buttons is clicked. */ public void pageNext() { - registration.setUin(uinField.getText()); - registration.setPassword(new String(passField.getPassword())); - registration.setRememberPassword(rememberPassBox.isSelected()); + 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(uinField.getText()); + registration.setPassword(new String(passField.getPassword())); + registration.setRememberPassword(rememberPassBox.isSelected()); + } } /** @@ -208,4 +228,20 @@ public void loadAccount(ProtocolProviderService protocolProvider) { this.rememberPassBox.setSelected(true); } } + + private boolean isExistingAccount(String accountName) + { + ProtocolProviderFactory factory + = MsnAccRegWizzActivator.getMsnProtocolProviderFactory(); + + 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/msnaccregwizz/resources.properties b/src/net/java/sip/communicator/plugin/msnaccregwizz/resources.properties index 6d9ee8a99..704f92512 100755 --- a/src/net/java/sip/communicator/plugin/msnaccregwizz/resources.properties +++ b/src/net/java/sip/communicator/plugin/msnaccregwizz/resources.properties @@ -4,5 +4,6 @@ uin=Email: password=Password: rememberPassword=Remember password uinAndPassword=ID and Password +existingAccount=* The account you entered is already installed. protocolIcon=net/java/sip/communicator/plugin/msnaccregwizz/resources/msn.gif diff --git a/src/net/java/sip/communicator/plugin/sipaccregwizz/FirstWizardPage.java b/src/net/java/sip/communicator/plugin/sipaccregwizz/FirstWizardPage.java index 15df6accf..726121214 100644 --- a/src/net/java/sip/communicator/plugin/sipaccregwizz/FirstWizardPage.java +++ b/src/net/java/sip/communicator/plugin/sipaccregwizz/FirstWizardPage.java @@ -8,6 +8,7 @@ import java.awt.*; import java.awt.event.*; +import java.util.*; import javax.swing.*; import javax.swing.event.*; @@ -42,6 +43,9 @@ public class FirstWizardPage extends JPanel 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(); @@ -81,6 +85,8 @@ public class FirstWizardPage extends JPanel new Object[]{"UDP", "TLS", "TCP"}); private JPanel mainPanel = new JPanel(); + + private Object nextPageIdentifier = WizardPage.SUMMARY_PAGE_IDENTIFIER; private SIPAccountRegistration registration; @@ -118,6 +124,8 @@ private void init() { this.uinField.getDocument().addDocumentListener(this); this.transportCombo.addItemListener(this); this.rememberPassBox.setSelected(true); + + existingAccountLabel.setForeground(Color.RED); labelsPanel.add(uinLabel); labelsPanel.add(passLabel); @@ -191,7 +199,7 @@ public Object getIdentifier() { * the next page identifier - the summary page. */ public Object getNextPageIdentifier() { - return WizardPage.SUMMARY_PAGE_IDENTIFIER; + return nextPageIdentifier; } /** @@ -222,16 +230,28 @@ public void pageShowing() { * Saves the user input when the "Next" wizard buttons is clicked. */ public void pageNext() { - registration.setUin(uinField.getText()); - registration.setPassword(new String(passField.getPassword())); - registration.setRememberPassword(rememberPassBox.isSelected()); - - registration.setServerAddress(serverField.getText()); - registration.setServerPort(serverPortField.getText()); - registration.setProxy(proxyField.getText()); - registration.setProxyPort(proxyPortField.getText()); - registration.setPreferredTransport( - transportCombo.getSelectedItem().toString()); + 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(uinField.getText()); + registration.setPassword(new String(passField.getPassword())); + registration.setRememberPassword(rememberPassBox.isSelected()); + + registration.setServerAddress(serverField.getText()); + registration.setServerPort(serverPortField.getText()); + registration.setProxy(proxyField.getText()); + registration.setProxyPort(proxyPortField.getText()); + registration.setPreferredTransport( + transportCombo.getSelectedItem().toString()); + } } /** @@ -367,4 +387,20 @@ public void itemStateChanged(ItemEvent e) proxyPortField.setText("5060"); } } + + private boolean isExistingAccount(String accountName) + { + ProtocolProviderFactory factory + = SIPAccRegWizzActivator.getSIPProtocolProviderFactory(); + + 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/sipaccregwizz/resources.properties b/src/net/java/sip/communicator/plugin/sipaccregwizz/resources.properties index 2952b513d..c3221d6f2 100755 --- a/src/net/java/sip/communicator/plugin/sipaccregwizz/resources.properties +++ b/src/net/java/sip/communicator/plugin/sipaccregwizz/resources.properties @@ -13,5 +13,6 @@ proxyPort=Proxy port preferredTransport=Preferred transport yes=Yes no=No +existingAccount=* The account you entered is already installed. protocolIcon=net/java/sip/communicator/plugin/sipaccregwizz/resources/sip.png