diff options
author | Sebastien Vincent <seb@jitsi.org> | 2011-03-25 12:12:59 +0000 |
---|---|---|
committer | Sebastien Vincent <seb@jitsi.org> | 2011-03-25 12:12:59 +0000 |
commit | f66ae33f62343a2782d3f417939847b4b99a97f0 (patch) | |
tree | c3ef06b4852f9eaa64d349641b74a95daa934ebe /src/net/java/sip/communicator/impl/googlecontacts | |
parent | 3c582f11022c051bcbada5d6a4dd0550bc276323 (diff) | |
download | jitsi-f66ae33f62343a2782d3f417939847b4b99a97f0.zip jitsi-f66ae33f62343a2782d3f417939847b4b99a97f0.tar.gz jitsi-f66ae33f62343a2782d3f417939847b4b99a97f0.tar.bz2 |
Fix NPE in Google Contacts service. Redesign Jabber account contact source activation: do all in Google Contacts service. Fix name in Mac OS X Dock when Jitsi is run from the sources.
Diffstat (limited to 'src/net/java/sip/communicator/impl/googlecontacts')
5 files changed, 137 insertions, 8 deletions
diff --git a/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsActivator.java b/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsActivator.java index f07a20e..a65396c 100644 --- a/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsActivator.java +++ b/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsActivator.java @@ -208,11 +208,93 @@ public class GoogleContactsActivator implements BundleActivator 2000, true), properties); + bundleContext.addServiceListener(new ServiceListener() + { + public void serviceChanged(ServiceEvent serviceEvent) + { + GoogleContactsActivator.this.serviceChanged(serviceEvent); + } + }); if (logger.isDebugEnabled()) logger.debug("Google Contacts Service ... [REGISTERED]"); } /** + * Implements the <tt>ServiceListener</tt> method. Verifies whether the + * passed event concerns a <tt>ProtocolProviderService</tt> and adds the + * corresponding UI controls. + * + * @param event The <tt>ServiceEvent</tt> object. + */ + private void serviceChanged(ServiceEvent event) + { + ServiceReference serviceRef = event.getServiceReference(); + + // if the event is caused by a bundle being stopped, we don't want to + // know + if (serviceRef.getBundle().getState() == Bundle.STOPPING) + { + return; + } + + Object service = bundleContext.getService(serviceRef); + + // we don't care if the source service is not a protocol provider + if (!(service instanceof ProtocolProviderService)) + { + return; + } + + // we don't care if the protocol provider is not a Jabber ones + if(((ProtocolProviderService)service).getProtocolName() != + ProtocolNames.JABBER) + { + return; + } + + switch (event.getType()) + { + case ServiceEvent.REGISTERED: + this.handleProviderAdded((ProtocolProviderService) service); + break; + case ServiceEvent.UNREGISTERING: + this.handleProviderRemoved((ProtocolProviderService) service); + break; + } + } + + /** + * Notifies this manager that a specific + * <tt>ProtocolProviderService</tt> has been registered as a service. + * + * @param provider the <tt>ProtocolProviderService</tt> which has been + * registered as a service. + */ + private void handleProviderAdded(ProtocolProviderService provider) + { + String className = provider.getClass().getName(); + className = className.substring(0, className.lastIndexOf('.')); + String acc = ProtocolProviderFactory.findAccountPrefix( + bundleContext, provider.getAccountID(), className); + String password = getCredentialsService().loadPassword(acc); + + enableContactSource(provider.getAccountID().getAccountAddress(), + password); + } + + /** + * Notifies this manager that a specific + * <tt>ProtocolProviderService</tt> has been unregistered as a service. + * + * @param provider the <tt>ProtocolProviderService</tt> which has been + * unregistered as a service. + */ + private void handleProviderRemoved(ProtocolProviderService provider) + { + disableContactSource(provider.getAccountID().getAccountAddress()); + } + + /** * Stops the Google Contacts service. * * @param bundleContext BundleContext @@ -373,9 +455,17 @@ public class GoogleContactsActivator implements BundleActivator for(Map.Entry<GoogleContactsSourceService, ServiceRegistration> entry : cssList.entrySet()) { - String cssName = - entry.getKey().getConnection().getLogin(); + GoogleContactsConnection cnxEntry = entry.getKey().getConnection(); + + if(cnx == null) + { + found = entry.getKey(); + break; + } + + String cssName = cnxEntry.getLogin(); String name = cnx.getLogin(); + if(cssName.equals(name)) { try diff --git a/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsConnectionImpl.java b/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsConnectionImpl.java index 03d0705..6f82505 100644 --- a/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsConnectionImpl.java +++ b/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsConnectionImpl.java @@ -22,12 +22,12 @@ public class GoogleContactsConnectionImpl /** * Login. */ - private final String login; + private String login = null; /** * Password. */ - private final String password; + private String password = null; /** * If the connection is enabled. @@ -84,6 +84,26 @@ public class GoogleContactsConnectionImpl } /** + * Set login. + * + * @param login login to connect to the service + */ + public void setLogin(String login) + { + this.login = login; + } + + /** + * Set password. + * + * @param password password to connect to the service + */ + public void setPassword(String password) + { + this.password = password; + } + + /** * Initialize connection. * * @return true if connection succeed, false if credentials is wrong diff --git a/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsEntryImpl.java b/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsEntryImpl.java index 1b4f739..e594639 100644 --- a/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsEntryImpl.java +++ b/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsEntryImpl.java @@ -382,6 +382,10 @@ public class GoogleContactsEntryImpl for(PhoneNumber phone : contact.getPhoneNumbers()) { + if(phone.getRel() == null) + { + homePhones.add(phone.getPhoneNumber()); + } if(phone.getRel().contains("#work")) { workPhones.add(phone.getPhoneNumber()); diff --git a/src/net/java/sip/communicator/impl/googlecontacts/configform/AccountSettingsForm.java b/src/net/java/sip/communicator/impl/googlecontacts/configform/AccountSettingsForm.java index e4c47d0..6db4845 100644 --- a/src/net/java/sip/communicator/impl/googlecontacts/configform/AccountSettingsForm.java +++ b/src/net/java/sip/communicator/impl/googlecontacts/configform/AccountSettingsForm.java @@ -179,11 +179,13 @@ public class AccountSettingsForm { this.nameField.setText(cnx.getLogin()); this.passwordField.setText(cnx.getPassword()); + this.cnx = cnx; } else { this.nameField.setText(""); this.passwordField.setText(""); + this.cnx = null; } } @@ -201,8 +203,16 @@ public class AccountSettingsForm String login = nameField.getText(); String password = new String(passwordField.getPassword()); - cnx = GoogleContactsActivator.getGoogleContactsService(). - getConnection(login, password); + if(cnx == null) + { + cnx = GoogleContactsActivator.getGoogleContactsService(). + getConnection(login, password); + } + else + { + cnx.setLogin(login); + cnx.setPassword(password); + } if(!cnx.connect()) { @@ -261,7 +271,6 @@ public class AccountSettingsForm { retCode = 0; - cnx = null; setVisible(true); // this will block until user click on save/cancel/press escape/close diff --git a/src/net/java/sip/communicator/impl/googlecontacts/configform/GoogleContactsConfigForm.java b/src/net/java/sip/communicator/impl/googlecontacts/configform/GoogleContactsConfigForm.java index a6dce89..9d81006 100644 --- a/src/net/java/sip/communicator/impl/googlecontacts/configform/GoogleContactsConfigForm.java +++ b/src/net/java/sip/communicator/impl/googlecontacts/configform/GoogleContactsConfigForm.java @@ -237,13 +237,19 @@ public class GoogleContactsConfigForm if (e.getActionCommand().equals("modify") && row != -1) { settingsForm.setNameFieldEnabled(false); - GoogleContactsConnection cnx = tableModel.getAccountAt(row); + GoogleContactsConnectionImpl cnx = tableModel.getAccountAt(row); settingsForm.loadData(cnx); int ret = settingsForm.showDialog(); if(ret == 1) { + GoogleContactsActivator.getGoogleContactsService().saveConfig( + cnx); + if(cnx.isEnabled()) + { + new RefreshContactSourceThread(cnx, cnx).start(); + } refresh(); } } |