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/GoogleContactsActivator.java | |
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/GoogleContactsActivator.java')
-rw-r--r-- | src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsActivator.java | 94 |
1 files changed, 92 insertions, 2 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 |