aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/impl/googlecontacts
diff options
context:
space:
mode:
authorYana Stamcheva <yana@jitsi.org>2011-08-24 12:06:49 +0000
committerYana Stamcheva <yana@jitsi.org>2011-08-24 12:06:49 +0000
commitf4479d54a2dbb6c2a3510e13f0940672c573f63d (patch)
treea0755aa976a0c50a8b67a1e6cdf860fd340adce9 /src/net/java/sip/communicator/impl/googlecontacts
parentd72f188060f348a8710e48c004a200e4b832405a (diff)
downloadjitsi-f4479d54a2dbb6c2a3510e13f0940672c573f63d.zip
jitsi-f4479d54a2dbb6c2a3510e13f0940672c573f63d.tar.gz
jitsi-f4479d54a2dbb6c2a3510e13f0940672c573f63d.tar.bz2
Merges contact source configurations in a single configuration form.
Adds the possibility to disable/enable MacOSX AddressBook and MS Outlook. Adds a prefix configuration to all contact sources: AddressBook, Outlook, LDAP, Google Contacts.
Diffstat (limited to 'src/net/java/sip/communicator/impl/googlecontacts')
-rw-r--r--src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsActivator.java17
-rw-r--r--src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsConnectionImpl.java25
-rw-r--r--src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsServiceImpl.java11
-rw-r--r--src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsSourceService.java26
-rw-r--r--src/net/java/sip/communicator/impl/googlecontacts/configform/AccountSettingsForm.java41
-rw-r--r--src/net/java/sip/communicator/impl/googlecontacts/configform/GoogleContactsConfigForm.java5
-rw-r--r--src/net/java/sip/communicator/impl/googlecontacts/configform/GoogleContactsTableModel.java55
7 files changed, 149 insertions, 31 deletions
diff --git a/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsActivator.java b/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsActivator.java
index 0f1b681..a1eeb35 100644
--- a/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsActivator.java
+++ b/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsActivator.java
@@ -196,7 +196,7 @@ public class GoogleContactsActivator implements BundleActivator
Dictionary<String, String> properties =
new Hashtable<String, String>();
properties.put( ConfigurationForm.FORM_TYPE,
- ConfigurationForm.ADVANCED_TYPE);
+ ConfigurationForm.CONTACT_SOURCE_TYPE);
bundleContext.registerService(
ConfigurationForm.class.getName(),
@@ -205,7 +205,7 @@ public class GoogleContactsActivator implements BundleActivator
getClass().getClassLoader(),
"impl.googlecontacts.PLUGIN_ICON",
"impl.googlecontacts.CONFIG_FORM_TITLE",
- 2000, true),
+ 2000, false),
properties);
bundleContext.addServiceListener(new ServiceListener()
@@ -344,7 +344,8 @@ public class GoogleContactsActivator implements BundleActivator
* @param login login
* @param password password
*/
- public static void enableContactSource(String login, String password)
+ public static GoogleContactsSourceService enableContactSource(
+ String login, String password)
{
GoogleContactsSourceService css = new GoogleContactsSourceService(
login, password);
@@ -370,6 +371,8 @@ public class GoogleContactsActivator implements BundleActivator
cssList.put(css, cssServiceRegistration);
}
}
+
+ return css;
}
/**
@@ -378,10 +381,10 @@ public class GoogleContactsActivator implements BundleActivator
*
* @param cnx <tt>GoogleContactsConnection</tt>
*/
- public static void enableContactSource(GoogleContactsConnection cnx)
+ public static GoogleContactsSourceService enableContactSource(
+ GoogleContactsConnection cnx)
{
- GoogleContactsSourceService css = new GoogleContactsSourceService(
- cnx);
+ GoogleContactsSourceService css = new GoogleContactsSourceService(cnx);
ServiceRegistration cssServiceRegistration = null;
try
@@ -404,6 +407,8 @@ public class GoogleContactsActivator implements BundleActivator
cssList.put(css, cssServiceRegistration);
}
}
+
+ return css;
}
/**
diff --git a/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsConnectionImpl.java b/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsConnectionImpl.java
index 9be306e..a59bab8 100644
--- a/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsConnectionImpl.java
+++ b/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsConnectionImpl.java
@@ -43,6 +43,11 @@ public class GoogleContactsConnectionImpl
private boolean enabled = false;
/**
+ * The google contact prefix.
+ */
+ private String prefix = null;
+
+ /**
* Google Contacts service.
*/
private final ContactsService googleService =
@@ -157,4 +162,24 @@ public class GoogleContactsConnectionImpl
{
this.enabled = enabled;
}
+
+ /**
+ * Sets the google contacts prefix.
+ *
+ * @param prefix the prefix to set
+ */
+ public void setPrefix(String prefix)
+ {
+ this.prefix = prefix;
+ }
+
+ /**
+ * Returns the google contacts prefix.
+ *
+ * @return the google contacts prefix
+ */
+ public String getPrefix()
+ {
+ return prefix;
+ }
}
diff --git a/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsServiceImpl.java b/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsServiceImpl.java
index be783c8..c744ced 100644
--- a/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsServiceImpl.java
+++ b/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsServiceImpl.java
@@ -114,11 +114,14 @@ public class GoogleContactsServiceImpl
boolean enabled = Boolean.parseBoolean((String)oen);
String login =
(String)configService.getProperty(path + ".account");
+ String prefix =
+ (String)configService.getProperty(path + ".prefix");
String password = credentialsService.loadPassword(path);
GoogleContactsConnectionImpl cnx = (GoogleContactsConnectionImpl)
getConnection(login, password);
cnx.setEnabled(enabled);
+ cnx.setPrefix(prefix);
if(cnx != null)
{
@@ -138,6 +141,7 @@ public class GoogleContactsServiceImpl
settings.getConnection();
// set the enabled state as before
cnx.setEnabled(enabled);
+ cnx.setPrefix(prefix);
saveConfig(cnx);
}
}
@@ -175,8 +179,10 @@ public class GoogleContactsServiceImpl
{
ConfigurationService configService =
GoogleContactsActivator.getConfigService();
+
CredentialsStorageService credentialsService =
GoogleContactsActivator.getCredentialsService();
+
String login = cnx.getLogin();
String path = CONFIGURATION_PATH + ".acc" + Math.abs(login.hashCode());
@@ -189,6 +195,11 @@ public class GoogleContactsServiceImpl
configService.setProperty(
path + ".enabled",
((GoogleContactsConnectionImpl)cnx).isEnabled());
+
+ configService.setProperty(
+ path + ".prefix",
+ ((GoogleContactsConnectionImpl)cnx).getPrefix());
+
credentialsService.storePassword(path, cnx.getPassword());
}
diff --git a/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsSourceService.java b/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsSourceService.java
index 6d52148..28c3203 100644
--- a/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsSourceService.java
+++ b/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsSourceService.java
@@ -45,6 +45,11 @@ public class GoogleContactsSourceService
private final String password;
/**
+ * The prefix for all google contact phone numbers.
+ */
+ private String phoneNumberprefix;
+
+ /**
* Google Contacts connection.
*/
private GoogleContactsConnection cnx = null;
@@ -78,6 +83,7 @@ public class GoogleContactsSourceService
this.cnx = cnx;
this.login = cnx.getLogin();
this.password = cnx.getPassword();
+ this.phoneNumberprefix = cnx.getPrefix();
}
/**
@@ -351,4 +357,24 @@ public class GoogleContactsSourceService
queries.notify();
}
}
+
+ /**
+ * Returns the phoneNumber prefix for all phone numbers.
+ *
+ * @return the phoneNumber prefix for all phone numbers
+ */
+ public String getPhoneNumberPrefix()
+ {
+ return phoneNumberprefix;
+ }
+
+ /**
+ * Sets the phone number prefix.
+ *
+ * @param phoneNumberprefix the phone number prefix to set
+ */
+ public void setPhoneNumberPrefix(String phoneNumberprefix)
+ {
+ this.phoneNumberprefix = phoneNumberprefix;
+ }
}
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 f67b7c5..ad06c93 100644
--- a/src/net/java/sip/communicator/impl/googlecontacts/configform/AccountSettingsForm.java
+++ b/src/net/java/sip/communicator/impl/googlecontacts/configform/AccountSettingsForm.java
@@ -40,6 +40,11 @@ public class AccountSettingsForm
private JPasswordField passwordField;
/**
+ * The prefix field.
+ */
+ private JTextField prefixField;
+
+ /**
* Save button.
*/
private JButton saveBtn = new JButton(
@@ -59,7 +64,7 @@ public class AccountSettingsForm
/**
* The Google Contacts connection.
*/
- private GoogleContactsConnection cnx = null;
+ private GoogleContactsConnectionImpl cnx = null;
/**
* Constructor.
@@ -150,6 +155,29 @@ public class AccountSettingsForm
c.anchor = GridBagConstraints.LINE_END;
basePanel.add(passwordField, c);
+ JLabel prefixLabel = new JLabel(
+ Resources.getString("service.gui.PREFIX"));
+ this.prefixField = new JTextField();
+ prefixLabel.setLabelFor(prefixField);
+ c.gridx = 0;
+ c.gridy = 3;
+ c.weightx = 0;
+ c.weighty = 0;
+ c.gridwidth = 1;
+ c.insets = new Insets(2, 50, 0, 5);
+ c.fill = GridBagConstraints.HORIZONTAL;
+ c.anchor = GridBagConstraints.LINE_START;
+ basePanel.add(prefixLabel, c);
+ c.gridx = 1;
+ c.gridy = 3;
+ c.weightx = 1;
+ c.weighty = 0;
+ c.gridwidth = GridBagConstraints.REMAINDER;
+ c.insets = new Insets(2, 5, 0, 50);
+ c.fill = GridBagConstraints.HORIZONTAL;
+ c.anchor = GridBagConstraints.LINE_END;
+ basePanel.add(prefixField, c);
+
mainPanel.setLayout(boxLayout);
mainPanel.add(basePanel);
@@ -179,7 +207,8 @@ public class AccountSettingsForm
{
this.nameField.setText(cnx.getLogin());
this.passwordField.setText(cnx.getPassword());
- this.cnx = cnx;
+ this.prefixField.setText(cnx.getPrefix());
+ this.cnx = (GoogleContactsConnectionImpl) cnx;
}
else
{
@@ -202,11 +231,13 @@ public class AccountSettingsForm
{
String login = nameField.getText();
String password = new String(passwordField.getPassword());
+ String prefix = prefixField.getText();
if(cnx == null)
{
- cnx = GoogleContactsActivator.getGoogleContactsService().
- getConnection(login, password);
+ cnx = (GoogleContactsConnectionImpl) GoogleContactsActivator
+ .getGoogleContactsService()
+ .getConnection(login, password);
}
else
{
@@ -214,6 +245,8 @@ public class AccountSettingsForm
cnx.setPassword(password);
}
+ cnx.setPrefix(prefix);
+
if(cnx.connect() == GoogleContactsConnection.ConnectionStatus.
ERROR_INVALID_CREDENTIALS)
{
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 9d81006..a713b9e 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,9 @@ public class GoogleContactsConfigForm
if(ret == 1)
{
- GoogleContactsConnection cnx = settingsForm.getConnection();
- tableModel.addAccount(cnx, true);
+ GoogleContactsConnectionImpl cnx
+ = (GoogleContactsConnectionImpl) settingsForm.getConnection();
+ tableModel.addAccount(cnx, true, cnx.getPrefix());
new RefreshContactSourceThread(null, cnx).start();
GoogleContactsActivator.getGoogleContactsService().saveConfig(
cnx);
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 bc51bbc..c294f08 100644
--- a/src/net/java/sip/communicator/impl/googlecontacts/configform/GoogleContactsTableModel.java
+++ b/src/net/java/sip/communicator/impl/googlecontacts/configform/GoogleContactsTableModel.java
@@ -41,12 +41,18 @@ public class GoogleContactsTableModel
* @param cnx account
* @param enabled if the account should be enabled
*/
- public void addAccount(GoogleContactsConnection cnx, boolean enabled)
+ public void addAccount( GoogleContactsConnection cnx,
+ boolean enabled,
+ String prefix)
{
if(cnx != null)
{
- ((GoogleContactsConnectionImpl)cnx).setEnabled(enabled);
- googleService.getAccounts().add((GoogleContactsConnectionImpl)cnx);
+ GoogleContactsConnectionImpl cnxImpl
+ = (GoogleContactsConnectionImpl) cnx;
+ cnxImpl.setEnabled(enabled);
+ cnxImpl.setPrefix(prefix);
+
+ googleService.getAccounts().add(cnxImpl);
}
}
@@ -88,6 +94,8 @@ public class GoogleContactsTableModel
return Resources.getString("impl.googlecontacts.ENABLED");
case 1:
return Resources.getString("impl.googlecontacts.ACCOUNT_NAME");
+ case 2:
+ return Resources.getString("impl.googlecontacts.PREFIX");
default:
throw new IllegalArgumentException("column not found");
}
@@ -113,8 +121,8 @@ public class GoogleContactsTableModel
*/
public int getColumnCount()
{
- // 2 columns: "enable" and "account name"
- return 2;
+ // 3 columns: "enable", "account name", "prefix"
+ return 3;
}
/**
@@ -133,6 +141,8 @@ public class GoogleContactsTableModel
return new Boolean(getAccountAt(row).isEnabled());
case 1:
return getAccountAt(row).getLogin();
+ case 2:
+ return getAccountAt(row).getPrefix();
default:
throw new IllegalArgumentException("column not found");
}
@@ -168,10 +178,10 @@ public class GoogleContactsTableModel
*/
public boolean isCellEditable(int row, int col)
{
- if(col == 0)
- return true;
- else
+ if(col == 1)
return false;
+ else
+ return true;
}
/**
@@ -193,25 +203,32 @@ public class GoogleContactsTableModel
*/
public void setValueAt(Object aValue, int rowIndex, int columnIndex)
{
- if(columnIndex != 0)
+ if(columnIndex != 0 || columnIndex != 2)
throw new IllegalArgumentException("non editable column!");
GoogleContactsConfigForm.RefreshContactSourceThread th = null;
GoogleContactsConnectionImpl cnx = getAccountAt(rowIndex);
- if(cnx.isEnabled())
+ if (columnIndex == 0)
{
- th = new GoogleContactsConfigForm.RefreshContactSourceThread(cnx,
- null);
+ if(cnx.isEnabled())
+ {
+ th = new GoogleContactsConfigForm.RefreshContactSourceThread(cnx,
+ null);
+ }
+ else
+ {
+ th = new GoogleContactsConfigForm.RefreshContactSourceThread(null,
+ cnx);
+ }
+
+ cnx.setEnabled(!cnx.isEnabled());
+
+ th.start();
}
- else
+ else if (columnIndex == 2)
{
- th = new GoogleContactsConfigForm.RefreshContactSourceThread(null,
- cnx);
+ cnx.setPrefix(aValue.toString());
}
-
- cnx.setEnabled(!cnx.isEnabled());
-
- th.start();
}
}