diff options
author | Lyubomir Marinov <lyubomir.marinov@jitsi.org> | 2011-02-16 10:12:58 +0000 |
---|---|---|
committer | Lyubomir Marinov <lyubomir.marinov@jitsi.org> | 2011-02-16 10:12:58 +0000 |
commit | 2ec8f1b300b23af5f48255b88f421a257d75fa61 (patch) | |
tree | 94f86d4b52ca411bfffe1b62cd122188b56492c3 /src | |
parent | 02e2cf6808ec86313aeb00e515ffbbe4a36e057c (diff) | |
download | jitsi-2ec8f1b300b23af5f48255b88f421a257d75fa61.zip jitsi-2ec8f1b300b23af5f48255b88f421a257d75fa61.tar.gz jitsi-2ec8f1b300b23af5f48255b88f421a257d75fa61.tar.bz2 |
Reports contact specifiers such as Home, Work, Mobile for the SourceContact ContactDetails returned by the Mac OS X Address Book ContactSourceService.
Diffstat (limited to 'src')
3 files changed, 113 insertions, 13 deletions
diff --git a/src/native/addrbook/macosx/net_java_sip_communicator_plugin_addrbook_macosx_MacOSXAddrBookContactQuery.m b/src/native/addrbook/macosx/net_java_sip_communicator_plugin_addrbook_macosx_MacOSXAddrBookContactQuery.m index 2572adf..be3ddd3 100644 --- a/src/native/addrbook/macosx/net_java_sip_communicator_plugin_addrbook_macosx_MacOSXAddrBookContactQuery.m +++ b/src/native/addrbook/macosx/net_java_sip_communicator_plugin_addrbook_macosx_MacOSXAddrBookContactQuery.m @@ -173,15 +173,24 @@ MacOSXAddrBookContactQuery_idToJObject }
else if ([o isKindOfClass:[ABMultiValue class]])
{
+ /*
+ * We changed our minds after the initial implementation and decided
+ * that we want to display not only the values but the labels as
+ * well. In order to minimize the scope of the modifications, we'll
+ * be returning each label in the same array right after its
+ * corresponding value.
+ */
ABMultiValue *mv = (ABMultiValue *) o;
NSUInteger mvCount = [mv count];
jobjectArray joArray
- = (*jniEnv)->NewObjectArray(jniEnv, mvCount, objectClass, NULL);
+ = (*jniEnv)->NewObjectArray(
+ jniEnv,
+ mvCount * 2 /* value, label */, objectClass, NULL);
jo = joArray;
if (joArray)
{
- NSUInteger j;
+ NSUInteger j, j1;
for (j = 0; j < mvCount; j++)
{
@@ -195,6 +204,19 @@ MacOSXAddrBookContactQuery_idToJObject jo = NULL;
break;
}
+ /* Because the compiler says ++j may be undefined for j. */
+ j1 = j + 1;
+ MacOSXAddrBookContactQuery_idToJObject(
+ jniEnv,
+ [mv labelAtIndex:j],
+ joArray, j1,
+ objectClass);
+ if (JNI_TRUE == (*jniEnv)->ExceptionCheck(jniEnv))
+ {
+ jo = NULL;
+ break;
+ }
+ j = j1;
}
}
}
diff --git a/src/net/java/sip/communicator/plugin/addrbook/macosx/MacOSXAddrBookContactQuery.java b/src/net/java/sip/communicator/plugin/addrbook/macosx/MacOSXAddrBookContactQuery.java index 2b9467b..22e33a9 100644 --- a/src/net/java/sip/communicator/plugin/addrbook/macosx/MacOSXAddrBookContactQuery.java +++ b/src/net/java/sip/communicator/plugin/addrbook/macosx/MacOSXAddrBookContactQuery.java @@ -173,6 +173,15 @@ public class MacOSXAddrBookContactQuery kABYahooInstantProperty
};
+ /**
+ * The regex which matches the superfluous parts of an <tt>ABMultiValue</tt>
+ * label.
+ */
+ private static final Pattern LABEL_PATTERN
+ = Pattern.compile(
+ "kAB|Email|Phone|Label|(\\p{Punct}*)",
+ Pattern.CASE_INSENSITIVE);
+
static
{
System.loadLibrary("jmacosxaddrbook");
@@ -202,6 +211,52 @@ public class MacOSXAddrBookContactQuery long[] properties);
/**
+ * Initializes a new <tt>ContactDetail</tt> instance which is to reperesent
+ * a specific contact address that is the value of a specific
+ * <tt>ABPerson</tt> property and, optionally, has a specific label.
+ *
+ * @param property the index in {@link #ABPERSON_PROPERTIES} of the
+ * <tt>ABPerson</tt> property to be represented by <tt>ContactDetail</tt>
+ * @param contactAddress the contact address to be represented by the new
+ * <tt>ContactDetail</tt> instance
+ * @param label an optional label to be added to the set of labels, if any,
+ * determined by <tt>property</tt>
+ * @return a new <tt>ContactDetail</tt> instance which represents the
+ * specified <tt>contactAddress</tt>
+ */
+ private ContactDetail createContactDetail(
+ int property,
+ String contactAddress,
+ Object label)
+ {
+ String p, l;
+
+ switch (property)
+ {
+ case kABEmailProperty:
+ p = ContactDetail.LABEL_EMAIL;
+ break;
+ case kABPhoneProperty:
+ p = ContactDetail.LABEL_PHONE;
+ break;
+ default:
+ p = null;
+ break;
+ }
+
+ if (label == null)
+ l = null;
+ else
+ {
+ l = LABEL_PATTERN.matcher((String) label).replaceAll("").trim();
+ if (l.length() < 1)
+ l = null;
+ }
+
+ return new ContactDetail(contactAddress, new String[] { p, l });
+ }
+
+ /**
* Calls back to a specific <tt>PtrCallback</tt> for each <tt>ABPerson</tt>
* found in the Address Book of Mac OS X which matches a specific
* <tt>String</tt> query.
@@ -245,14 +300,23 @@ public class MacOSXAddrBookContactQuery contactDetails.add(
setCapabilities(
- new ContactDetail(stringValue),
+ createContactDetail(
+ property,
+ stringValue,
+ null),
property));
}
}
else if (value instanceof Object[])
{
- for (Object subValue : (Object[]) value)
+ Object[] multiValue = (Object[]) value;
+
+ for (int multiValueIndex = 0;
+ multiValueIndex < multiValue.length;
+ multiValueIndex += 2)
{
+ Object subValue = multiValue[multiValueIndex];
+
if (subValue instanceof String)
{
String stringSubValue = (String) subValue;
@@ -267,7 +331,10 @@ public class MacOSXAddrBookContactQuery contactDetails.add(
setCapabilities(
- new ContactDetail(stringSubValue),
+ createContactDetail(
+ property,
+ stringSubValue,
+ multiValue[multiValueIndex + 1]),
property));
}
}
@@ -366,8 +433,14 @@ public class MacOSXAddrBookContactQuery }
else if (value instanceof Object[])
{
- for (Object subValue : (Object[]) value)
+ Object[] multiValue = (Object[]) value;
+
+ for (int multiValueIndex = 0;
+ multiValueIndex < multiValue.length;
+ multiValueIndex += 2)
{
+ Object subValue = multiValue[multiValueIndex];
+
if (subValue instanceof String)
{
String stringSubValue = (String) subValue;
@@ -538,8 +611,13 @@ public class MacOSXAddrBookContactQuery }
else if (value instanceof Object[])
{
- for (Object subValue : (Object[]) value)
+ Object[] multiValue = (Object[]) value;
+
+ for (int multiValueIndex = 0;
+ multiValueIndex < multiValue.length;
+ multiValueIndex += 2)
{
+ Object subValue = multiValue[multiValueIndex];
if ((subValue instanceof String)
&& matches(property, (String) subValue))
return true;
diff --git a/src/net/java/sip/communicator/service/contactsource/ContactDetail.java b/src/net/java/sip/communicator/service/contactsource/ContactDetail.java index 1dcaa38..92b47a7 100644 --- a/src/net/java/sip/communicator/service/contactsource/ContactDetail.java +++ b/src/net/java/sip/communicator/service/contactsource/ContactDetail.java @@ -117,7 +117,11 @@ public class ContactDetail * @param labels the set of labels with which the new <tt>ContactDetail</tt> * instance is to be labeled. The labels may be arbitrary and may include * any of the standard/well-known labels defined by the <tt>LABEL_XXX</tt> - * constants of the <tt>ContactDetail</tt> class. + * constants of the <tt>ContactDetail</tt> class. For the sake of + * convenience, <tt>null</tt> and duplicate values in the specified + * <tt>String[]</tt> <tt>labels</tt> will be ignored i.e. will not appear in + * the set of labels reported by the new <tt>ContactDetail</tt> instance + * later on. */ public ContactDetail(String contactAddress, String[] labels) { @@ -126,14 +130,10 @@ public class ContactDetail // labels if (labels != null) { - System.err.println(this.contactAddress); for (String label : labels) { - if (!this.labels.contains(label)) - { + if ((label != null) && !this.labels.contains(label)) this.labels.add(label); - System.err.println("\t" + label); - } } } } |