From 2b96e2ee910b8a6c0f573efeb7c73bb827a8d020 Mon Sep 17 00:00:00 2001 From: Sebastien Vincent Date: Fri, 2 Dec 2011 10:26:25 +0000 Subject: [PATCH] Detects Google Contacts support in contact source via the protocol provider of the account ('Google Talk') or the Google contacts source is extern (created via the Google Contacts configuration form), in addition to the SRV method. --- .../GoogleContactsActivator.java | 17 ++++++-- .../GoogleContactsServiceImpl.java | 15 ++++--- .../GoogleContactsSourceService.java | 41 +++++++++++++++++++ .../configform/GoogleContactsConfigForm.java | 6 +-- .../configform/GoogleContactsTableModel.java | 2 +- .../googlecontacts/GoogleContactsService.java | 7 +++- 6 files changed, 73 insertions(+), 15 deletions(-) diff --git a/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsActivator.java b/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsActivator.java index 6e2a0e0a9..243b9f095 100644 --- a/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsActivator.java +++ b/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsActivator.java @@ -288,7 +288,9 @@ public void run() { enableContactSource( provider.getAccountID().getAccountAddress(), - password); + password, + provider.getProtocolDisplayName().equals( + "Google Talk")); } } }).start(); @@ -348,15 +350,19 @@ public void stop(BundleContext bundleContext) * * @param login login * @param password password + * @param googleTalk if the provider service is GoogleTalk * @return a GoogleContactsSourceService instance */ public static GoogleContactsSourceService enableContactSource( - String login, String password) + String login, String password, + boolean googleTalk) { GoogleContactsSourceService css = new GoogleContactsSourceService( login, password); ServiceRegistration cssServiceRegistration = null; + css.setGoogleTalk(googleTalk); + try { cssServiceRegistration @@ -386,14 +392,19 @@ public static GoogleContactsSourceService enableContactSource( * GoogleContactsConnection. * * @param cnx GoogleContactsConnection + * @param googleTalk if the contact source has been created as GoogleTalk + * account or via external Google Contacts * @return a GoogleContactsSourceService instance */ public static GoogleContactsSourceService enableContactSource( - GoogleContactsConnection cnx) + GoogleContactsConnection cnx, + boolean googleTalk) { GoogleContactsSourceService css = new GoogleContactsSourceService(cnx); ServiceRegistration cssServiceRegistration = null; + css.setGoogleTalk(googleTalk); + try { cssServiceRegistration diff --git a/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsServiceImpl.java b/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsServiceImpl.java index 6861fbfee..0b1c98d49 100644 --- a/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsServiceImpl.java +++ b/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsServiceImpl.java @@ -157,7 +157,7 @@ private void loadConfig() /* register contact source */ if(cnx.isEnabled()) { - addContactSource(cnx); + addContactSource(cnx, true); } } } @@ -430,14 +430,17 @@ public GoogleContactsConnection getConnection(String login, } /** - * Add a contact source service with the specified. - * + * Add a contact source service with the specified * GoogleContactsConnection. + * * @param cnx GoogleContactsConnection. + * @param googleTalk if the contact source has been created as GoogleTalk + * account or via external Google Contacts */ - public void addContactSource(GoogleContactsConnection cnx) + public void addContactSource(GoogleContactsConnection cnx, + boolean googleTalk) { - GoogleContactsActivator.enableContactSource(cnx); + GoogleContactsActivator.enableContactSource(cnx, googleTalk); } /** @@ -449,7 +452,7 @@ public void addContactSource(GoogleContactsConnection cnx) */ public void addContactSource(String login, String password) { - GoogleContactsActivator.enableContactSource(login, password); + GoogleContactsActivator.enableContactSource(login, password, false); } /** diff --git a/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsSourceService.java b/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsSourceService.java index 1a71e822f..518d5e20e 100644 --- a/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsSourceService.java +++ b/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsSourceService.java @@ -59,6 +59,12 @@ public class GoogleContactsSourceService */ private AccountSettingsForm settings = null; + /** + * If the account has been created using GoogleTalk wizard or via + * external Google Contacts. + */ + private boolean googleTalk = false; + /** * Constructor. * @@ -96,6 +102,29 @@ public String getLogin() return login; } + /** + * Set whether or not the account has been created via GoogleTalk wizard or + * external Google contacts. + * + * @param googleTalk value to set + */ + public void setGoogleTalk(boolean googleTalk) + { + this.googleTalk = googleTalk; + } + + /** + * Returns whether or not the account has been created via GoogleTalk + * wizard or via external Google Contacts. + * + * @return true if account has been created via GoogleTalk wizard or via + * external Google Contacts. + */ + public boolean isGoogleTalk() + { + return googleTalk; + } + /** * Queries this search source for the given searchPattern. * @@ -174,6 +203,12 @@ public GoogleContactsConnectionImpl getConnection() return null; } + // To detect that account is a google ones, we try the following: + // - lookup in SRV and see if it is google.com; + // - if the account has been created with GoogleTalk form; + // - if it is an "external" google contact. + + // SRV checks for(SRVRecord srv : srvRecords) { if(srv.getTarget().endsWith("google.com") || @@ -184,6 +219,12 @@ public GoogleContactsConnectionImpl getConnection() } } + // GoogleTalk based account or external Google Contacts ? + if(!isGoogleAppsOrGmail) + { + isGoogleAppsOrGmail = googleTalk; + } + if(isGoogleAppsOrGmail) { if(cnx == null) 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 033456b92..d170fafd1 100644 --- a/src/net/java/sip/communicator/impl/googlecontacts/configform/GoogleContactsConfigForm.java +++ b/src/net/java/sip/communicator/impl/googlecontacts/configform/GoogleContactsConfigForm.java @@ -225,8 +225,8 @@ public void actionPerformed(ActionEvent e) if(ret == 1) { - GoogleContactsConnectionImpl cnx - = (GoogleContactsConnectionImpl) settingsForm.getConnection(); + GoogleContactsConnectionImpl cnx = + (GoogleContactsConnectionImpl) settingsForm.getConnection(); tableModel.addAccount(cnx, true, cnx.getPrefix()); new RefreshContactSourceThread(null, cnx).start(); GoogleContactsActivator.getGoogleContactsService().saveConfig( @@ -351,7 +351,7 @@ public void run() if(newCnx != null) { GoogleContactsActivator.getGoogleContactsService(). - addContactSource(newCnx); + addContactSource(newCnx, true); } } } diff --git a/src/net/java/sip/communicator/impl/googlecontacts/configform/GoogleContactsTableModel.java b/src/net/java/sip/communicator/impl/googlecontacts/configform/GoogleContactsTableModel.java index 3347f4d8e..5f1bdb1ea 100644 --- a/src/net/java/sip/communicator/impl/googlecontacts/configform/GoogleContactsTableModel.java +++ b/src/net/java/sip/communicator/impl/googlecontacts/configform/GoogleContactsTableModel.java @@ -204,7 +204,7 @@ public Class getColumnClass(int columnIndex) */ public void setValueAt(Object aValue, int rowIndex, int columnIndex) { - if(columnIndex != 0 || columnIndex != 2) + if(columnIndex != 0 && columnIndex != 2) throw new IllegalArgumentException("non editable column!"); GoogleContactsConfigForm.RefreshContactSourceThread th = null; diff --git a/src/net/java/sip/communicator/service/googlecontacts/GoogleContactsService.java b/src/net/java/sip/communicator/service/googlecontacts/GoogleContactsService.java index c61351eb4..cee058866 100644 --- a/src/net/java/sip/communicator/service/googlecontacts/GoogleContactsService.java +++ b/src/net/java/sip/communicator/service/googlecontacts/GoogleContactsService.java @@ -58,9 +58,12 @@ public GoogleContactsConnection getConnection(String login, * Add a contact source service with the specified * GoogleContactsConnection. * - * @param cnx GoogleContactsConnection. + * @param cnx GoogleContactsConnection + * @param googleTalk if the contact source has been created as GoogleTalk + * account or via external Google Contacts */ - public void addContactSource(GoogleContactsConnection cnx); + public void addContactSource(GoogleContactsConnection cnx, + boolean googleTalk); /** * Remove a contact source service with the specified