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 | |
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')
10 files changed, 160 insertions, 73 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(); } } diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/ProtocolProviderServiceJabberImpl.java b/src/net/java/sip/communicator/impl/protocol/jabber/ProtocolProviderServiceJabberImpl.java index 0945813..8b239c8 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/ProtocolProviderServiceJabberImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/ProtocolProviderServiceJabberImpl.java @@ -22,7 +22,6 @@ import net.java.sip.communicator.impl.protocol.jabber.extensions.jingle.*; import net.java.sip.communicator.impl.protocol.jabber.extensions.inputevt.*; import net.java.sip.communicator.impl.protocol.jabber.sasl.*; import net.java.sip.communicator.service.certificate.*; -import net.java.sip.communicator.service.googlecontacts.*; import org.jivesoftware.smack.*; import org.jivesoftware.smack.packet.*; @@ -1258,9 +1257,6 @@ public class ProtocolProviderServiceJabberImpl OperationSetGenericNotifications.class, new OperationSetGenericNotificationsJabberImpl(this)); - /* add Google Contacts as contact source if enabled */ - registerGoogleContactsSource(); - isInitialized = true; } } @@ -1277,8 +1273,6 @@ public class ProtocolProviderServiceJabberImpl if (logger.isTraceEnabled()) logger.trace("Killing the Jabber Protocol Provider."); - unregisterGoogleContactsSource(); - //kill all active calls OperationSetBasicTelephonyJabberImpl telephony = (OperationSetBasicTelephonyJabberImpl)getOperationSet( @@ -1847,7 +1841,8 @@ public class ProtocolProviderServiceJabberImpl { // Jingle Nodes Service Initialization JabberAccountID accID = (JabberAccountID)getAccountID(); - final SmackServiceNode service = new SmackServiceNode(connection, 60000); + final SmackServiceNode service = new SmackServiceNode(connection, + 60000); for(JingleNodeDescriptor desc : accID.getJingleNodes()) { @@ -1903,56 +1898,6 @@ public class ProtocolProviderServiceJabberImpl } /** - * Register Google Contacts as contact source if user has enable it. - */ - private void registerGoogleContactsSource() - { - if(accountID.getAccountPropertyBoolean( - "GOOGLE_CONTACTS_ENABLED", - true)) - { - logger.info("Register Google Contacts service as contact source"); - GoogleContactsService googleService = - JabberActivator.getGoogleService(); - - if(googleService != null) - { - googleService.addContactSource( - org.jivesoftware.smack.util.StringUtils.parseName( - getOurJID()) + "@" + - StringUtils.parseServer(getAccountID().getUserID()), - JabberActivator. - getProtocolProviderFactory().loadPassword( - getAccountID())); - } - } - } - - /** - * Unregister Google Contacts as contact source. - */ - private void unregisterGoogleContactsSource() - { - if(accountID.getAccountPropertyBoolean( - "GOOGLE_CONTACTS_ENABLED", - true)) - { - logger.info("Unregister Google Contacts service as contact source"); - - GoogleContactsService googleService = - JabberActivator.getGoogleService(); - - if(googleService != null) - { - googleService.removeContactSource( - org.jivesoftware.smack.util.StringUtils.parseName( - getOurJID()) + "@" + - StringUtils.parseServer(getAccountID().getUserID())); - } - } - } - - /** * Logs a specific message and associated <tt>Throwable</tt> cause as an * error using the current <tt>Logger</tt> and then throws a new * <tt>OperationFailedException</tt> with the message, a specific error code diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/jabber.provider.manifest.mf b/src/net/java/sip/communicator/impl/protocol/jabber/jabber.provider.manifest.mf index 730b671..47839ae 100755 --- a/src/net/java/sip/communicator/impl/protocol/jabber/jabber.provider.manifest.mf +++ b/src/net/java/sip/communicator/impl/protocol/jabber/jabber.provider.manifest.mf @@ -48,7 +48,6 @@ Import-Package: org.osgi.framework, net.java.sip.communicator.service.argdelegation, net.java.sip.communicator.service.certificate, net.java.sip.communicator.service.gui, - net.java.sip.communicator.service.googlecontacts, org.xmlpull.v1, org.xmlpull.mxp1, javax.xml.parsers, diff --git a/src/net/java/sip/communicator/service/googlecontacts/GoogleContactsConnection.java b/src/net/java/sip/communicator/service/googlecontacts/GoogleContactsConnection.java index 557c8c4..6e3879f 100644 --- a/src/net/java/sip/communicator/service/googlecontacts/GoogleContactsConnection.java +++ b/src/net/java/sip/communicator/service/googlecontacts/GoogleContactsConnection.java @@ -21,13 +21,27 @@ public interface GoogleContactsConnection public String getLogin(); /** - * get password. + * Get password. * * @return password to connect to the service */ public String getPassword(); /** + * Set login. + * + * @param login login to connect to the service + */ + public void setLogin(String login); + + /** + * Set password. + * + * @param password password to connect to the service + */ + public void setPassword(String password); + + /** * Initialize connection. * * @return true if connection succeed, false if credentials is wrong diff --git a/src/net/java/sip/communicator/service/protocol/AccountManager.java b/src/net/java/sip/communicator/service/protocol/AccountManager.java index 0a93b7f..08ef08f 100644 --- a/src/net/java/sip/communicator/service/protocol/AccountManager.java +++ b/src/net/java/sip/communicator/service/protocol/AccountManager.java @@ -18,7 +18,7 @@ import org.osgi.framework.*; /**
* Represents an implementation of <tt>AccountManager</tt> which loads the
* accounts in a separate thread.
- *
+ *
* @author Lubomir Marinov
* @author Yana Stamcheva
*/
@@ -484,7 +484,7 @@ public class AccountManager * implementation tracks the registrations of
* <tt>ProtocolProviderFactory</tt> services in order to queue them for
* loading their stored accounts.
- *
+ *
* @param serviceEvent the <tt>ServiceEvent</tt> containing the event
* data
*/
diff --git a/src/net/java/sip/communicator/service/protocol/event/ProviderStatusChangeEvent.java b/src/net/java/sip/communicator/service/protocol/event/ProviderStatusChangeEvent.java index 304cf24..35fa9f8 100644 --- a/src/net/java/sip/communicator/service/protocol/event/ProviderStatusChangeEvent.java +++ b/src/net/java/sip/communicator/service/protocol/event/ProviderStatusChangeEvent.java @@ -28,18 +28,18 @@ public class ProviderStatusChangeEvent extends PropertyChangeEvent * <tt>newValue</tt>. * @param source the provider that generated the event * @param eventType the type of the newly created event. - * @param oldValue the status the source provider was int before enetering + * @param oldValue the status the source provider was int before entering * the new state. * @param newValue the status the source provider is currently in. */ - public ProviderStatusChangeEvent(ProtocolProviderService source, String eventType, - PresenceStatus oldValue, PresenceStatus newValue) + public ProviderStatusChangeEvent(ProtocolProviderService source, + String eventType, PresenceStatus oldValue, PresenceStatus newValue) { super(source, eventType, oldValue, newValue); } /** - * Returns the provider that has genereted this event + * Returns the provider that has generated this event * @return the provider that generated the event. */ public ProtocolProviderService getProvider() |