/soc/2012/michael/android: 16076ffa8aed: Added basic ui ops for ...

Michael Zangl michael at soc.pidgin.im
Sun Jul 29 08:20:08 EDT 2012


Changeset: 16076ffa8aed86af31d6649d17c69513c25c3d06
Author:	 Michael Zangl <michael at soc.pidgin.im>
Date:	 2012-07-29 13:28 +0200
Branch:	 soc.2012.android
URL: http://hg.pidgin.im/soc/2012/michael/android/rev/16076ffa8aed

Description:

Added basic ui ops for user input requests.

diffstat:

 android/workspace/im.pidgin.libpurple/native/RequestUiOps.c                                          |  391 ++++++++++
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/CoreManager.java                  |    2 +
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/request/PurpleRequestAction.java  |   11 +
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/request/PurpleRequestChoice.java  |   12 +
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/request/PurpleRequestHandler.java |   10 +
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/core/request/RequestUiOps.java         |   41 +
 6 files changed, 467 insertions(+), 0 deletions(-)

diffs (truncated from 509 to 300 lines):

diff --git a/android/workspace/im.pidgin.libpurple/native/RequestUiOps.c b/android/workspace/im.pidgin.libpurple/native/RequestUiOps.c
new file mode 100644
--- /dev/null
+++ b/android/workspace/im.pidgin.libpurple/native/RequestUiOps.c
@@ -0,0 +1,391 @@
+#include "RequestUiOps.h"
+#include "helpers.h"
+#include <libpurple/request.h>
+
+static JavaObjectReference request = JAVA_NULL_OBJECT_REF;
+
+static void
+addToList(JNIEnv *env, jobject list, jobject add)
+{
+	static JavaMethodIDCache addMethod =
+			METHOD_CACHE("add", "(Ljava/lang/Object;)V");
+
+	jclass listClass;
+	jmethodID addMethodMid;
+
+	listClass = (*env)->FindClass(env, "java/util/ArrayList");
+	addMethodMid = getMethodIDCachedReferenced(env, listClass, &addMethod);
+	(*env)->CallVoidMethod(env, list, addMethodMid, add);
+
+}
+
+static jobject
+newList(JNIEnv *env)
+{
+	static JavaMethodIDCache listConstructor = METHOD_CACHE("<init>", "");
+
+	jobject list;
+	jclass listClass;
+	jmethodID listConstructorMid;
+
+	listClass = (*env)->FindClass(env, "java/util/ArrayList");
+	listConstructorMid = getMethodIDCachedReferenced(env, listClass,
+			&listConstructor);
+	g_return_val_if_fail(listConstructorMid != NULL, NULL);
+	list = (*env)->NewObject(env, listClass, listConstructorMid);
+
+	return list;
+}
+
+static jobject
+actionsToList(JNIEnv *env, size_t action_count, va_list args)
+{
+	static JavaMethodIDCache actionConstructor =
+			METHOD_CACHE("<init>", "(Ljava/lang/String;J)V");
+
+	const char * label_native;
+	PurpleRequestActionCb cb;
+	jobject list = newList(env);
+	jobject action;
+	jclass actionClass;
+	jstring label;
+	jmethodID actionConstructorMid;
+	size_t actions_remaining = action_count;
+
+	actionClass = (*env)->FindClass(env,
+			"im/pidgin/libpurple/core/request/PurpleRequestAction");
+	actionConstructorMid = getMethodIDCachedReferenced(env, actionClass,
+			&actionConstructor);
+	g_return_val_if_fail(actionConstructorMid != NULL, NULL);
+
+	label_native = va_arg(args, const char *);
+	while (label_native != NULL && actions_remaining > 0) {
+		cb = va_arg(args, PurpleRequestActionCb);
+		g_return_val_if_fail(cb != NULL, NULL);
+
+		label = (*env)->NewStringUTF(env, label_native);
+		g_return_val_if_fail(label != NULL, NULL);
+
+		action = (*env)->NewObject(env, actionClass, actionConstructorMid,
+				label, pToLong(cb));
+		g_return_val_if_fail(action != NULL, NULL);
+
+		addToList(env, list, action);
+		(*env)->DeleteLocalRef(env, action);
+		actions_remaining--;
+	}
+	return list;
+}
+
+static jobject
+choicesToList(JNIEnv *env, va_list args)
+{
+	static JavaMethodIDCache choiceConstructor =
+			METHOD_CACHE("<init>", "(Ljava/lang/String;I)V");
+
+	const char * label_native;
+	int index;
+	jobject list = newList(env);
+	jobject choice;
+	jclass choiceClass;
+	jstring label;
+	jmethodID choiceConstructorMid;
+
+	choiceClass = (*env)->FindClass(env,
+			"im/pidgin/libpurple/core/request/PurpleRequestChoice");
+	choiceConstructorMid = getMethodIDCachedReferenced(env, choiceClass,
+			&choiceConstructor);
+	g_return_val_if_fail(choiceConstructorMid != NULL, NULL);
+
+	label_native = va_arg(args, const char *);
+	while (label_native != NULL) {
+		index = va_arg(args, int);
+		g_return_val_if_fail(index != 0, NULL);
+
+		label = (*env)->NewStringUTF(env, label_native);
+		g_return_val_if_fail(label != NULL, NULL);
+
+		choice = (*env)->NewObject(env, choiceClass, choiceConstructorMid,
+				label, (jint) index);
+		g_return_val_if_fail(choice != NULL, NULL);
+
+		addToList(env, list, choice);
+		(*env)->DeleteLocalRef(env, choice);
+	}
+	return list;
+}
+
+static void*
+request_input(const char* title, const char* primary, const char* secondary,
+		const char* default_value, gboolean multiline, gboolean masked,
+		gchar* hint, const char* ok_text, GCallback ok_cb,
+		const char* cancel_text, GCallback cancel_cb, PurpleAccount* account,
+		const char* who, PurpleConversation* conv, void* user_data)
+{
+	static JavaMethodIDCache methodCache =
+					METHOD_CACHE("requestInput", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZZLjava/lang/String;Ljava/lang/String;JLjava/lang/String;JJLjava/lang/String;JJ)J");
+
+	jmethodID mid;
+	jstring title_obj;
+	jstring primary_obj;
+	jstring secondary_obj;
+	jstring default_value_obj;
+	jstring hint_obj;
+	jstring ok_text_obj;
+	jlong ok_cb_ptr;
+	jstring cancel_text_obj;
+	jlong cancel_cb_ptr;
+	jlong account_ptr;
+	jstring who_obj;
+	jlong conv_ptr;
+	jlong user_data_ptr;
+	jlong result = 0;
+
+	CALLBACK_START(&request, NULL);
+
+	title_obj = (*env)->NewStringUTF(env, title);
+	primary_obj = (*env)->NewStringUTF(env, primary);
+	secondary_obj = (*env)->NewStringUTF(env, secondary);
+	default_value_obj = (*env)->NewStringUTF(env, default_value);
+	hint_obj = (*env)->NewStringUTF(env, hint);
+	ok_text_obj = (*env)->NewStringUTF(env, ok_text);
+	ok_cb_ptr = pToLong(ok_cb);
+	cancel_text_obj = (*env)->NewStringUTF(env, cancel_text);
+	cancel_cb_ptr = pToLong(cancel_cb);
+	account_ptr = pToLong(account);
+	who_obj = (*env)->NewStringUTF(env, who);
+	conv_ptr = pToLong(conv);
+	user_data_ptr = pToLong(user_data);
+
+	mid = getMethodIDCachedReferenced(env, request.java_class, &methodCache);
+	if (mid != NULL && title_obj != NULL && primary_obj != NULL
+			&& secondary_obj != NULL && default_value_obj != NULL
+			&& hint_obj != NULL && ok_text_obj != NULL
+			&& cancel_text_obj != NULL && who_obj != NULL) {
+		result = (*env)->CallLongMethod(env, request.handlerObject, mid,
+				title_obj, primary_obj, secondary_obj, default_value_obj,
+				(jboolean) multiline, (jboolean) masked, hint_obj, ok_text_obj,
+				ok_cb_ptr, cancel_text_obj, cancel_cb_ptr, account_ptr, who_obj,
+				conv_ptr, user_data_ptr);
+	}
+	return (void*) longToP(result);
+}
+static
+void*
+request_choice(const char* title, const char* primary, const char* secondary,
+		int default_value, const char* ok_text, GCallback ok_cb,
+		const char* cancel_text, GCallback cancel_cb, PurpleAccount* account,
+		const char* who, PurpleConversation* conv, void* user_data,
+		va_list choices)
+{
+	static JavaMethodIDCache methodCache =
+					METHOD_CACHE("requestChoice",
+							"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;JLjava/lang/String;JJLjava/lang/String;JJLjava/util/ArrayList;)J");
+
+	jmethodID mid;
+	jstring title_obj;
+	jstring primary_obj;
+	jstring secondary_obj;
+	jstring ok_text_obj;
+	jlong ok_cb_ptr;
+	jstring cancel_text_obj;
+	jlong cancel_cb_ptr;
+	jlong account_ptr;
+	jstring who_obj;
+	jlong conv_ptr;
+	jlong user_data_ptr;
+	jobject choices_obj;
+	jlong result = 0;
+
+	CALLBACK_START(&request, NULL);
+
+	title_obj = (*env)->NewStringUTF(env, title);
+	primary_obj = (*env)->NewStringUTF(env, primary);
+	secondary_obj = (*env)->NewStringUTF(env, secondary);
+	ok_text_obj = (*env)->NewStringUTF(env, ok_text);
+	ok_cb_ptr = pToLong(ok_cb);
+	cancel_text_obj = (*env)->NewStringUTF(env, cancel_text);
+	cancel_cb_ptr = pToLong(cancel_cb);
+	account_ptr = pToLong(account);
+	who_obj = (*env)->NewStringUTF(env, who);
+	conv_ptr = pToLong(conv);
+	user_data_ptr = pToLong(user_data);
+	choices_obj = choicesToList(env, choices);
+
+	mid = getMethodIDCachedReferenced(env, request.java_class, &methodCache);
+	if (mid != NULL && title_obj != NULL && primary_obj != NULL
+			&& secondary_obj != NULL && ok_text_obj != NULL
+			&& cancel_text_obj != NULL && who_obj != NULL && choices_obj != NULL) {
+		result = (*env)->CallLongMethod(env, request.handlerObject, mid,
+				title_obj, primary_obj, secondary_obj, (jint) default_value,
+				ok_text_obj, ok_cb_ptr, cancel_text_obj, cancel_cb_ptr,
+				account_ptr, who_obj, conv_ptr, user_data_ptr, choices_obj);
+	}
+	return (void*) longToP(result);
+}
+
+static void*
+request_action(const char* title, const char* primary, const char* secondary,
+		int default_action, PurpleAccount* account, const char* who,
+		PurpleConversation* conv, void* user_data, size_t action_count,
+		va_list actions)
+{
+	static JavaMethodIDCache methodCache =
+					METHOD_CACHE("requestAction", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IJLjava/lang/String;JJILjava/util/ArrayList;)J");
+
+	jmethodID mid;
+	jstring title_obj;
+	jstring primary_obj;
+	jstring secondary_obj;
+	jlong account_ptr;
+	jstring who_obj;
+	jlong conv_ptr;
+	jlong user_data_ptr;
+	jobject actions_obj;
+	jlong result = 0;
+
+	CALLBACK_START(&request, NULL);
+
+	title_obj = (*env)->NewStringUTF(env, title);
+	primary_obj = (*env)->NewStringUTF(env, primary);
+	secondary_obj = (*env)->NewStringUTF(env, secondary);
+	account_ptr = pToLong(account);
+	who_obj = (*env)->NewStringUTF(env, who);
+	conv_ptr = pToLong(conv);
+	user_data_ptr = pToLong(user_data);
+	actions_obj = actionsToList(env, action_count, actions);
+
+	mid = getMethodIDCachedReferenced(env, request.java_class, &methodCache);
+	if (mid != NULL && title_obj != NULL && primary_obj != NULL
+			&& secondary_obj != NULL && who_obj != NULL) {
+		result = (*env)->CallLongMethod(env, request.handlerObject, mid,
+				title_obj, primary_obj, secondary_obj, (jint) default_action,
+				account_ptr, who_obj, conv_ptr, user_data_ptr, actions_obj);
+	}
+	return (void*) longToP(result);
+}
+static void*
+request_fields(const char* title, const char* primary, const char* secondary,
+		PurpleRequestFields* fields, const char* ok_text, GCallback ok_cb,
+		const char* cancel_text, GCallback cancel_cb, PurpleAccount* account,
+		const char* who, PurpleConversation* conv, void* user_data)
+{
+	static JavaMethodIDCache methodCache =
+					METHOD_CACHE("requestFields", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;JLjava/lang/String;JLjava/lang/String;JJLjava/lang/String;JJ)J");
+
+	jmethodID mid;
+	jstring title_obj;
+	jstring primary_obj;
+	jstring secondary_obj;
+	jlong fields_ptr;
+	jstring ok_text_obj;
+	jlong ok_cb_ptr;
+	jstring cancel_text_obj;
+	jlong cancel_cb_ptr;
+	jlong account_ptr;
+	jstring who_obj;
+	jlong conv_ptr;
+	jlong user_data_ptr;
+	jlong result = 0;
+
+	CALLBACK_START(&request, NULL);
+
+	title_obj = (*env)->NewStringUTF(env, title);
+	primary_obj = (*env)->NewStringUTF(env, primary);
+	secondary_obj = (*env)->NewStringUTF(env, secondary);



More information about the Commits mailing list