diff options
author | Lyubomir Marinov <lyubomir.marinov@jitsi.org> | 2011-01-07 19:01:32 +0000 |
---|---|---|
committer | Lyubomir Marinov <lyubomir.marinov@jitsi.org> | 2011-01-07 19:01:32 +0000 |
commit | 72bc56dbb32f2e311a9250ad561c9e3feef2e066 (patch) | |
tree | e10b816ef1a405e16caaba09ccc141cb073376e2 /src/native/addrbook/macosx | |
parent | 8b919ddfb1de75c72c256aa671203183c5bfc232 (diff) | |
download | jitsi-72bc56dbb32f2e311a9250ad561c9e3feef2e066.zip jitsi-72bc56dbb32f2e311a9250ad561c9e3feef2e066.tar.gz jitsi-72bc56dbb32f2e311a9250ad561c9e3feef2e066.tar.bz2 |
Activates an initial implementation of the support for the Address Book of Mac OS X. Neither it, nor the support for the Address Book of Microsoft Outlook implement the SourceContact image property.
Diffstat (limited to 'src/native/addrbook/macosx')
-rw-r--r-- | src/native/addrbook/macosx/Makefile | 16 | ||||
-rw-r--r-- | src/native/addrbook/macosx/net_java_sip_communicator_plugin_addrbook_macosx_MacOSXAddrBookContactQuery.m | 132 |
2 files changed, 145 insertions, 3 deletions
diff --git a/src/native/addrbook/macosx/Makefile b/src/native/addrbook/macosx/Makefile new file mode 100644 index 0000000..6b71ff5 --- /dev/null +++ b/src/native/addrbook/macosx/Makefile @@ -0,0 +1,16 @@ +CC = cc -O2 +TARGET_BASENAME = jmacosxaddrbook + +JAVA_HOME = /Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks/JavaVM.framework/Versions/1.5 + +CC := $(CC) -arch i386 -arch ppc -arch x86_64 -mmacosx-version-min=10.4 +CPPFLAGS = -Wall -Wreturn-type -DJNI_IMPLEMENTATION -I$(JAVA_HOME)/Headers -I.. +LDFLAGS = -dynamiclib +LIBS = -framework AddressBook -framework Foundation +TARGET = ../../../../lib/native/mac/lib$(TARGET_BASENAME).jnilib + +$(TARGET): \ + ../AddrBookContactQuery.c \ + net_java_sip_communicator_plugin_addrbook_macosx_MacOSXAddrBookContactQuery.m + $(CC) $(CPPFLAGS) $^ $(LDFLAGS) -o $@ $(LIBS) + -strip $(TARGET) 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 358e7a8..23a2e50 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 @@ -7,21 +7,98 @@ #include "net_java_sip_communicator_plugin_addrbook_macosx_MacOSXAddrBookContactQuery.h"
+#include "AddrBookContactQuery.h"
+
#import <AddressBook/AddressBook.h>
+#import <Foundation/NSArray.h>
+#import <Foundation/NSAutoreleasePool.h>
+
+static void MacOSXAddrBookContactQuery_idToJObject
+ (JNIEnv *jniEnv, id o, jobjectArray jos, jint i, jclass objectClass);
JNIEXPORT jobjectArray JNICALL
Java_net_java_sip_communicator_plugin_addrbook_macosx_MacOSXAddrBookContactQuery_ABRecord_1valuesForProperties
(JNIEnv *jniEnv, jclass clazz, jlong record, jlongArray properties)
{
- /* TODO Auto-generated method stub */
- return NULL;
+ jsize propertyCount;
+ jobjectArray values = NULL;
+
+ propertyCount = (*jniEnv)->GetArrayLength(jniEnv, properties);
+ if (propertyCount)
+ {
+ jclass objectClass;
+
+ objectClass = (*jniEnv)->FindClass(jniEnv, "java/lang/Object");
+ if (objectClass)
+ {
+ values
+ = (*jniEnv)->NewObjectArray(
+ jniEnv,
+ propertyCount, objectClass, NULL);
+ if (values)
+ {
+ jint i;
+ ABRecord *r = (ABRecord *) record;
+
+ for (i = 0; i < propertyCount; i++)
+ {
+ jlong property;
+
+ (*jniEnv)->GetLongArrayRegion(
+ jniEnv,
+ properties, i, 1, &property);
+ MacOSXAddrBookContactQuery_idToJObject(
+ jniEnv,
+ [r valueForProperty:(NSString *)property],
+ values, i,
+ objectClass);
+ if (JNI_TRUE == (*jniEnv)->ExceptionCheck(jniEnv))
+ break;
+ }
+ }
+ }
+ }
+ return values;
}
JNIEXPORT void JNICALL
Java_net_java_sip_communicator_plugin_addrbook_macosx_MacOSXAddrBookContactQuery_foreachPerson
(JNIEnv *jniEnv, jclass clazz, jstring query, jobject callback)
{
- /* TODO Auto-generated method stub */
+ jmethodID callbackMethodID;
+ NSAutoreleasePool *autoreleasePool;
+ ABAddressBook *addressBook;
+ NSArray *people;
+ NSUInteger peopleCount;
+ NSUInteger i;
+
+ callbackMethodID
+ = AddrBookContactQuery_getPtrCallbackMethodID(jniEnv, callback);
+ if (!callbackMethodID || (JNI_TRUE == (*jniEnv)->ExceptionCheck(jniEnv)))
+ return;
+
+ autoreleasePool = [[NSAutoreleasePool alloc] init];
+
+ addressBook = [ABAddressBook addressBook];
+ people = [addressBook people];
+ peopleCount = [people count];
+ for (i = 0; i < peopleCount; i++)
+ {
+ jboolean proceed;
+ ABPerson *person = [people objectAtIndex:i];
+
+ proceed
+ = (*jniEnv)->CallBooleanMethod(
+ jniEnv,
+ callback, callbackMethodID,
+ person);
+ if ((JNI_FALSE == proceed)
+ || (JNI_TRUE == (*jniEnv)->ExceptionCheck(jniEnv)))
+ break;
+ }
+ [addressBook release];
+
+ [autoreleasePool release];
}
#define DEFINE_ABPERSON_PROPERTY_GETTER(property) \
@@ -46,3 +123,52 @@ DEFINE_ABPERSON_PROPERTY_GETTER(kABMSNInstantProperty) DEFINE_ABPERSON_PROPERTY_GETTER(kABNicknameProperty)
DEFINE_ABPERSON_PROPERTY_GETTER(kABPhoneProperty)
DEFINE_ABPERSON_PROPERTY_GETTER(kABYahooInstantProperty)
+
+static void
+MacOSXAddrBookContactQuery_idToJObject
+ (JNIEnv *jniEnv,
+ id o,
+ jobjectArray jos, jint i,
+ jclass objectClass)
+{
+ if (o)
+ {
+ jobject jo;
+
+ if ([o isKindOfClass:[NSString class]])
+ {
+ jo = (*jniEnv)->NewStringUTF(jniEnv, [((NSString *) o) UTF8String]);
+ }
+ else if ([o isKindOfClass:[ABMultiValue class]])
+ {
+ ABMultiValue *mv = (ABMultiValue *) o;
+ NSUInteger mvCount = [mv count];
+ jobjectArray joArray
+ = (*jniEnv)->NewObjectArray(jniEnv, mvCount, objectClass, NULL);
+
+ jo = joArray;
+ if (joArray)
+ {
+ NSUInteger j;
+
+ for (j = 0; j < mvCount; j++)
+ {
+ MacOSXAddrBookContactQuery_idToJObject(
+ jniEnv,
+ [mv valueAtIndex:j],
+ joArray, j,
+ objectClass);
+ if (JNI_TRUE == (*jniEnv)->ExceptionCheck(jniEnv))
+ {
+ jo = NULL;
+ break;
+ }
+ }
+ }
+ }
+ else
+ jo = NULL;
+ if (jo)
+ (*jniEnv)->SetObjectArrayElement(jniEnv, jos, i, jo);
+ }
+}
|