/soc/2012/michael/android: a5b4ab2d9f15: Implemented buddy and c...

Michael Zangl michael at soc.pidgin.im
Sat Jul 7 03:34:27 EDT 2012


Changeset: a5b4ab2d9f15fe3f8641b39036680622b3f4ae62
Author:	 Michael Zangl <michael at soc.pidgin.im>
Date:	 2012-07-07 09:33 +0200
Branch:	 soc.2012.android
URL: http://hg.pidgin.im/soc/2012/michael/android/rev/a5b4ab2d9f15

Description:

Implemented buddy and contact setters and getters and added the ability to create conversations.

diffstat:

 android/workspace/im.pidgin.libpurple/native/PurpleBuddy.c                                           |  107 ++++++++++
 android/workspace/im.pidgin.libpurple/native/PurpleBuddy.h                                           |    5 +
 android/workspace/im.pidgin.libpurple/native/PurpleContact.c                                         |   47 ++++
 android/workspace/im.pidgin.libpurple/native/PurpleConversation.c                                    |   74 ++++++
 android/workspace/im.pidgin.libpurple/native/build.ant                                               |    4 +-
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/blist/PurpleBlistManager.java          |   57 ++++-
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/blist/PurpleBlistNode.java             |    6 +-
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/blist/PurpleContact.java               |   11 +
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/buddy/PurpleBuddy.java                 |   18 +
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/conversation/ConversationListener.java |    8 +
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/conversation/PurpleConversation.java   |   83 +++++++
 11 files changed, 409 insertions(+), 11 deletions(-)

diffs (truncated from 521 to 300 lines):

diff --git a/android/workspace/im.pidgin.libpurple/native/PurpleBuddy.c b/android/workspace/im.pidgin.libpurple/native/PurpleBuddy.c
new file mode 100644
--- /dev/null
+++ b/android/workspace/im.pidgin.libpurple/native/PurpleBuddy.c
@@ -0,0 +1,107 @@
+#include "PurpleBuddy.h"
+#include "helpers.h"
+#include <libpurple/blist.h>
+
+PurpleBuddy *
+getNativeBuddy(JNIEnv *env, jobject obj)
+{
+	return (PurpleBuddy*) getNativePointer(env, obj);
+}
+
+/*
+ * Class:     im_pidgin_libpurple_buddy_PurpleBuddy
+ * Method:    getName_native
+ * Signature: ()Ljava/lang/String;
+ */JNIEXPORT jstring JNICALL
+Java_im_pidgin_libpurple_buddy_PurpleBuddy_getName_1native(JNIEnv *env,
+		jobject obj)
+{
+	const char* name = purple_buddy_get_name(getNativeBuddy(env, obj));
+	return (*env)->NewStringUTF(env, name);
+}
+
+/*
+ * Class:     im_pidgin_libpurple_buddy_PurpleBuddy
+ * Method:    getAlias_native
+ * Signature: ()Ljava/lang/String;
+ */JNIEXPORT jstring JNICALL
+Java_im_pidgin_libpurple_buddy_PurpleBuddy_getAlias_1native(JNIEnv *env,
+		jobject obj)
+{
+	const char* alias = purple_buddy_get_alias(getNativeBuddy(env, obj));
+	return (*env)->NewStringUTF(env, alias);
+}
+
+/*
+ * Class:     im_pidgin_libpurple_buddy_PurpleBuddy
+ * Method:    setAlias_native
+ * Signature: (Ljava/lang/String;)V
+ */JNIEXPORT void JNICALL
+Java_im_pidgin_libpurple_buddy_PurpleBuddy_setAlias_1native(JNIEnv *env,
+		jobject obj, jstring alias)
+{
+	const char* alias_native;
+	alias_native = (*env)->GetStringUTFChars(env, alias, NULL);
+	g_return_if_fail(alias_native != NULL);
+	purple_blist_alias_buddy(getNativeBuddy(env, obj), alias_native);
+	(*env)->ReleaseStringUTFChars(env, alias, alias_native);
+}
+
+/*
+ * Class:     im_pidgin_libpurple_buddy_PurpleBuddy
+ * Method:    getServerAlias_native
+ * Signature: ()Ljava/lang/String;
+ */JNIEXPORT jstring JNICALL
+Java_im_pidgin_libpurple_buddy_PurpleBuddy_getServerAlias_1native(JNIEnv *env,
+		jobject obj)
+{
+	const char* server_alias = purple_buddy_get_server_alias(
+			getNativeBuddy(env, obj));
+	return (*env)->NewStringUTF(env, server_alias);
+}
+
+/*
+ * Class:     im_pidgin_libpurple_buddy_PurpleBuddy
+ * Method:    getDisplayName_native
+ * Signature: ()Ljava/lang/String;
+ */JNIEXPORT jstring JNICALL
+Java_im_pidgin_libpurple_buddy_PurpleBuddy_getDisplayName_1native(JNIEnv *env,
+		jobject obj)
+{
+	const char* contact_alias = purple_buddy_get_contact_alias(
+			getNativeBuddy(env, obj));
+	return (*env)->NewStringUTF(env, contact_alias);
+}
+
+/*
+ * Class:     im_pidgin_libpurple_buddy_PurpleBuddy
+ * Method:    getAccount_native
+ * Signature: ()J
+ */JNIEXPORT jlong JNICALL
+Java_im_pidgin_libpurple_buddy_PurpleBuddy_getAccount_1native(JNIEnv *env,
+		jobject obj)
+{
+	return pToLong(purple_buddy_get_account(getNativeBuddy(env, obj)));
+}
+
+/*
+ * Class:     im_pidgin_libpurple_buddy_PurpleBuddy
+ * Method:    isOnline_native
+ * Signature: ()Z
+ */JNIEXPORT jboolean JNICALL
+Java_im_pidgin_libpurple_buddy_PurpleBuddy_isOnline_1native(JNIEnv *env,
+		jobject obj)
+{
+	return PURPLE_BUDDY_IS_ONLINE(getNativeBuddy(env, obj));
+}
+
+/*
+ * Class:     im_pidgin_libpurple_buddy_PurpleBuddy
+ * Method:    getContact_native
+ * Signature: ()J
+ */JNIEXPORT jlong JNICALL
+Java_im_pidgin_libpurple_buddy_PurpleBuddy_getContact_1native(JNIEnv *env,
+		jobject obj)
+{
+	return pToLong(purple_buddy_get_contact(getNativeBuddy(env, obj)));
+}
diff --git a/android/workspace/im.pidgin.libpurple/native/PurpleBuddy.h b/android/workspace/im.pidgin.libpurple/native/PurpleBuddy.h
new file mode 100644
--- /dev/null
+++ b/android/workspace/im.pidgin.libpurple/native/PurpleBuddy.h
@@ -0,0 +1,5 @@
+#include "PurpleBuddy_jni.h"
+#include <libpurple/blist.h>
+
+PurpleBuddy *
+getNativeBuddy(JNIEnv *env, jobject obj);
diff --git a/android/workspace/im.pidgin.libpurple/native/PurpleContact.c b/android/workspace/im.pidgin.libpurple/native/PurpleContact.c
new file mode 100644
--- /dev/null
+++ b/android/workspace/im.pidgin.libpurple/native/PurpleContact.c
@@ -0,0 +1,47 @@
+#include "PurpleContact.h"
+#include "helpers.h"
+#include <libpurple/blist.h>
+
+PurpleContact *
+getNativeContact(JNIEnv *env, jobject obj)
+{
+	return (PurpleContact*) getNativePointer(env, obj);
+}
+/*
+ * Class:     im_pidgin_libpurple_blist_PurpleContact
+ * Method:    getAlias_native
+ * Signature: ()Ljava/lang/String;
+ */JNIEXPORT jstring JNICALL
+Java_im_pidgin_libpurple_blist_PurpleContact_getAlias_1native(JNIEnv *env,
+		jobject obj)
+{
+	const char* alias_native = purple_contact_get_alias(
+			getNativeContact(env, obj));
+	return (*env)->NewStringUTF(env, alias_native);
+}
+
+/*
+ * Class:     im_pidgin_libpurple_blist_PurpleContact
+ * Method:    setAlias_native
+ * Signature: (Ljava/lang/String;)V
+ */JNIEXPORT void JNICALL
+Java_im_pidgin_libpurple_blist_PurpleContact_setAlias_1native(JNIEnv *env,
+		jobject obj, jstring alias)
+{
+	const char* alias_native;
+	alias_native = (*env)->GetStringUTFChars(env, alias, NULL);
+	g_return_if_fail(alias_native != NULL);
+	purple_blist_alias_contact(getNativeContact(env, obj), alias_native);
+	(*env)->ReleaseStringUTFChars(env, alias, alias_native);
+}
+
+/*
+ * Class:     im_pidgin_libpurple_blist_PurpleContact
+ * Method:    getContactGroup_native
+ * Signature: ()J
+ */JNIEXPORT jlong JNICALL
+Java_im_pidgin_libpurple_blist_PurpleContact_getContactGroup_1native(
+		JNIEnv *env, jobject obj)
+{
+	return pToLong(purple_contact_get_group(getNativeContact(env, obj)));
+}
diff --git a/android/workspace/im.pidgin.libpurple/native/PurpleConversation.c b/android/workspace/im.pidgin.libpurple/native/PurpleConversation.c
new file mode 100644
--- /dev/null
+++ b/android/workspace/im.pidgin.libpurple/native/PurpleConversation.c
@@ -0,0 +1,74 @@
+#include "PurpleConversation.h"
+#include "PurpleBuddy.h"
+#include "helpers.h"
+#include <libpurple/conversation.h>
+
+PurpleConversation *
+getNativeConversation(JNIEnv *env, jobject obj)
+{
+	return (PurpleConversation*) getNativePointer(env, obj);
+}
+/*
+ * Class:     im_pidgin_libpurple_conversation_PurpleConversation
+ * Method:    newConversation_native
+ * Signature: (Lim/pidgin/libpurple/buddy/PurpleBuddy;)J
+ */JNIEXPORT jlong JNICALL
+Java_im_pidgin_libpurple_conversation_PurpleConversation_newConversation_1native(
+		JNIEnv *env, jclass cls, jobject buddy)
+{
+	PurpleBuddy *buddy_native = getNativeBuddy(env, buddy);
+	return pToLong(purple_conversation_new(PURPLE_CONV_TYPE_IM,
+					purple_buddy_get_account(buddy_native),
+					purple_buddy_get_name(buddy_native)));
+}
+
+/*
+ * Class:     im_pidgin_libpurple_conversation_PurpleConversation
+ * Method:    setLogging_native
+ * Signature: (Z)V
+ */JNIEXPORT void JNICALL
+Java_im_pidgin_libpurple_conversation_PurpleConversation_setLogging_1native(
+		JNIEnv *env, jobject obj, jboolean logging)
+{
+	purple_conversation_set_logging(getNativeConversation(env, obj), logging);
+}
+
+/*
+ * Class:     im_pidgin_libpurple_conversation_PurpleConversation
+ * Method:    isLogging_native
+ * Signature: ()Z
+ */JNIEXPORT jboolean JNICALL
+Java_im_pidgin_libpurple_conversation_PurpleConversation_isLogging_1native(
+		JNIEnv *env, jobject obj)
+{
+	return purple_conversation_is_logging(getNativeConversation(env, obj));
+}
+
+/*
+ * Class:     im_pidgin_libpurple_conversation_PurpleConversation
+ * Method:    send_native
+ * Signature: (Ljava/lang/String;)V
+ */JNIEXPORT void JNICALL
+Java_im_pidgin_libpurple_conversation_PurpleConversation_send_1native(
+		JNIEnv *env, jobject obj, jstring message)
+{
+	const char* message_native;
+	message_native = (*env)->GetStringUTFChars(env, message, NULL);
+	g_return_if_fail(message_native != NULL);
+	PurpleConvIm *im = purple_conversation_get_im_data(
+			getNativeConversation(env, obj));
+	purple_conv_im_send(im, message_native);
+	(*env)->ReleaseStringUTFChars(env, message, message_native);
+}
+
+ /*
+  * Class:     im_pidgin_libpurple_conversation_PurpleConversation
+  * Method:    getTypingState_native
+  * Signature: ()Z
+  */
+ JNIEXPORT jboolean JNICALL Java_im_pidgin_libpurple_conversation_PurpleConversation_getTypingState_1native
+   (JNIEnv *env, jobject obj) {
+		PurpleConvIm *im = purple_conversation_get_im_data(
+				getNativeConversation(env, obj));
+	 return purple_conv_im_get_typing_state(im) == PURPLE_TYPING;
+ }
diff --git a/android/workspace/im.pidgin.libpurple/native/build.ant b/android/workspace/im.pidgin.libpurple/native/build.ant
--- a/android/workspace/im.pidgin.libpurple/native/build.ant
+++ b/android/workspace/im.pidgin.libpurple/native/build.ant
@@ -41,8 +41,10 @@
 		<javah classdefinition="im.pidgin.libpurple.blist.PurpleBlistNode" to="${javah.out}" />
 		<javah classdefinition="im.pidgin.libpurple.blist.PurpleContact" to="${javah.out}" />
 
-		<javah classdefinition="im.pidgin.libpurple.buddy.PurpleBuddy" to="${javah.out}" />
+		<javah classdefinition="im.pidgin.libpurple.buddy.PurpleBuddy" to="${javah.out}" headerfilename="PurpleBuddy_jni.h" />
 
+		<javah classdefinition="im.pidgin.libpurple.conversation.PurpleConversation" to="${javah.out}" />
+		
 		<javah classdefinition="im.pidgin.libpurple.core.EventLoop" to="${javah.out}" headerfilename="EventLoop_jni.h"/>
 		<javah classdefinition="im.pidgin.libpurple.core.PurpleInstance" to="${javah.out}" />
 		<javah classdefinition="im.pidgin.libpurple.core.CoreManager" to="${javah.out}" />
diff --git a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/blist/PurpleBlistManager.java b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/blist/PurpleBlistManager.java
--- a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/blist/PurpleBlistManager.java
+++ b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/blist/PurpleBlistManager.java
@@ -1,25 +1,39 @@
 package im.pidgin.libpurple.blist;
 
+import im.pidgin.libpurple.buddy.PurpleBuddy;
+import im.pidgin.libpurple.core.AbstractPurpleManaged;
 import im.pidgin.libpurple.core.CoreManager;
 import im.pidgin.libpurple.peering.PeerGenerator;
 
-public class PurpleBlistManager implements PeerGenerator<PurpleBlistNode>{
-
-	private final CoreManager coreManager;
+/**
+ * This is the main manager class that manages all buddy list nodes. Each node
+ * uses the ui_data field to bind the native object to the node, so we do not
+ * need to have a node cache here.
+ * 
+ * @author michaelz
+ * 
+ */
+public class PurpleBlistManager extends AbstractPurpleManaged implements
+		PeerGenerator<PurpleBlistNode> {
 
 	public PurpleBlistManager(CoreManager coreManager) {
-		this.coreManager = coreManager;
+		super(coreManager);
 	}
-	
-	public PurpleBlistNode getRoot() {
+



More information about the Commits mailing list