/soc/2012/michael/android: 450cb0cd7ba2: Added purple signal han...

Michael Zangl michael at soc.pidgin.im
Sat Jul 7 13:44:17 EDT 2012


Changeset: 450cb0cd7ba2697fa0c2d6a7b785405f0e0bd5d0
Author:	 Michael Zangl <michael at soc.pidgin.im>
Date:	 2012-07-07 19:44 +0200
Branch:	 soc.2012.android
URL: http://hg.pidgin.im/soc/2012/michael/android/rev/450cb0cd7ba2

Description:

Added purple signal handlers for PurpleBlistManager.

diffstat:

 android/workspace/im.pidgin.libpurple/native/PurpleBlistManager.c                           |  91 ++++++++++
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/blist/PurpleBlistManager.java |  16 +
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/CoreManager.java         |  37 ++-
 3 files changed, 130 insertions(+), 14 deletions(-)

diffs (224 lines):

diff --git a/android/workspace/im.pidgin.libpurple/native/PurpleBlistManager.c b/android/workspace/im.pidgin.libpurple/native/PurpleBlistManager.c
--- a/android/workspace/im.pidgin.libpurple/native/PurpleBlistManager.c
+++ b/android/workspace/im.pidgin.libpurple/native/PurpleBlistManager.c
@@ -2,6 +2,70 @@
 #include "helpers.h"
 #include <libpurple/blist.h>
 
+static void
+buddy_status_changed(PurpleBuddy* buddy, PurpleStatus* old, PurpleStatus* now,
+		JavaObjectReference *blist)
+{
+	static JavaMethodIDCache methodCache =
+			METHOD_CACHE("buddyStatusChanged", "(JJJ)V");
+
+	jmethodID mid;
+	jlong buddy_ptr;
+	jlong old_ptr;
+	jlong now_ptr;
+
+	CALLBACK_START_VOID(blist);
+
+	buddy_ptr = pToLong(buddy);
+	old_ptr = pToLong(old);
+	now_ptr = pToLong(now);
+
+	mid = getMethodIDCachedReferenced(env, blist.class, &methodCache);
+	if (mid != NULL) {
+		(*env)->CallVoidMethod(env, blist.handlerObject, mid, buddy_ptr,
+				old_ptr, now_ptr);
+	}
+}
+
+static void
+buddy_idle_changed(PurpleBuddy* buddy, int old, int new,
+		JavaObjectReference *blist)
+{
+	static JavaMethodIDCache methodCache =
+			METHOD_CACHE("buddyIdleChanged", "(JII)V");
+
+	jmethodID mid;
+	jlong buddy_ptr;
+
+	CALLBACK_START_VOID(blist);
+
+	buddy_ptr = pToLong(buddy);
+
+	mid = getMethodIDCachedReferenced(env, blist.class, &methodCache);
+	if (mid != NULL) {
+		(*env)->CallVoidMethod(env, blist.handlerObject, mid, buddy_ptr,
+				(jint) old, (jint) new);
+	}
+}
+
+static void
+buddy_signed_on_off(PurpleBuddy* buddy, JavaObjectReference *blist)
+{
+	static JavaMethodIDCache methodCache =
+			METHOD_CACHE("buddySignedOnOff", "(J)V");
+
+	jmethodID mid;
+	jlong buddy_ptr;
+
+	CALLBACK_START_VOID(blist);
+
+	buddy_ptr = pToLong(buddy);
+
+	mid = getMethodIDCachedReferenced(env, blist.class, &methodCache);
+	if (mid != NULL) {
+		(*env)->CallVoidMethod(env, blist.handlerObject, mid, buddy_ptr);
+	}
+}
 /*
  * Class:     im_pidgin_libpurple_blist_PurpleBlistManager
  * Method:    getRoot_native
@@ -12,3 +76,30 @@
 {
 	return pToLong(purple_blist_get_root());
 }
+
+/*
+ * Class:     im_pidgin_libpurple_blist_PurpleBlistManager
+ * Method:    register_native
+ * Signature: ()V
+ */JNIEXPORT void JNICALL
+Java_im_pidgin_libpurple_blist_PurpleBlistManager_register_1native(JNIEnv *env,
+		jobject obj)
+{
+	JavaObjectReference *blist = g_new(JavaObjectReference, 1);
+	g_return_if_fail(blist != NULL);
+	setJavaObject(blist, env, obj);
+
+	purple_signal_connect(purple_blist_get_handle(), "buddy-status-changed",
+			finch_blist_get_handle(), PURPLE_CALLBACK(buddy_status_changed),
+			blist);
+	purple_signal_connect(purple_blist_get_handle(), "buddy-idle-changed",
+			finch_blist_get_handle(), PURPLE_CALLBACK(buddy_idle_changed),
+			blist);
+	purple_signal_connect(purple_blist_get_handle(), "buddy-signed-on",
+			finch_blist_get_handle(), PURPLE_CALLBACK(buddy_signed_on_off),
+			blist);
+	purple_signal_connect(purple_blist_get_handle(), "buddy-signed-off",
+			finch_blist_get_handle(), PURPLE_CALLBACK(buddy_signed_on_off),
+			blist);
+
+}
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
@@ -26,6 +26,12 @@
 
 	private native long getRoot_native();
 
+	public void register() {
+		register_native();
+	}
+
+	private native void register_native();
+
 	@Override
 	public synchronized PurpleBlistNode getPeer(long pointer) {
 		PurpleBlistNode peer = PurpleBlistNode.getCachedPeer_native(pointer);
@@ -68,4 +74,14 @@
 					"Given pointer was not a contact.");
 		}
 	}
+
+	protected void buddyStatusChanged(long buddy, long old, long newStatus) {
+	}
+
+	protected void buddyIdleChanged(long buddy, int old, int newIdle) {
+	}
+
+	protected void buddySignedOnOff(long buddy) {
+	}
+
 }
diff --git a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/CoreManager.java b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/CoreManager.java
--- a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/CoreManager.java
+++ b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/CoreManager.java
@@ -2,6 +2,7 @@
 
 import im.pidgin.libpurple.account.PurpleAccountManager;
 import im.pidgin.libpurple.blist.PurpleBlistManager;
+import im.pidgin.libpurple.conversation.ConversationManager;
 import im.pidgin.libpurple.core.thread.PurpleThread;
 import im.pidgin.libpurple.plugin.PurplePluginList;
 import im.pidgin.libpurple.plugin.PurplePluginManager;
@@ -10,54 +11,62 @@
  * This is the core purple manager, that provides access to all functionality.
  * <p>
  * It also implements the core UI ops.
+ * 
  * @author michaelz
  * 
  */
-public class CoreManager{
-	private final PurpleAccountManager accountList = new PurpleAccountManager(this);
-	
+public class CoreManager {
+	private final PurpleAccountManager accountList = new PurpleAccountManager(
+			this);
+
 	private final EventLoop eventloop = new EventLoop(this);
-	
+
 	private final PurpleThread purpleThread = new PurpleThread();
-	
+
 	private final PurplePluginList pluginManager = new PurplePluginManager(this);
-	
+
 	private final PurpleBlistManager blist = new PurpleBlistManager(this);
-	
+
+	private final ConversationManager conversationManager = new ConversationManager(
+			this);
+
 	/**
 	 * Initializes libpurple by setting all the ui ops and calling
 	 * purple_core_init().
 	 * 
-	 * @param uiName The name of the UI.
+	 * @param uiName
+	 *            The name of the UI.
 	 */
 	public boolean startCore(String uiName) {
 		eventloop.register();
 		return startCore_native(uiName);
 	}
-	
+
 	private native boolean startCore_native(String uiName);
-	
+
 	public EventLoop getEventloop() {
 		return eventloop;
 	}
-	
+
 	/**
 	 * Register all the ui ops for the child objects and sets up jni.
 	 * <p>
 	 * Do not register the eventloop, since it is alredy registered.
 	 */
-	protected void coreInitUI() { 
+	protected void coreInitUI() {
 		accountList.register();
+		blist.register();
+		conversationManager.register();
 	}
 
 	public PurpleThread getThread() {
 		return purpleThread;
 	}
-	
+
 	public PurpleAccountManager getAccountList() {
 		return accountList;
 	}
-	
+
 	public PurplePluginList getPluginManager() {
 		return pluginManager;
 	}



More information about the Commits mailing list