/soc/2012/michael/android: 66b28488a92d: Routed account added/de...
Michael Zangl
michael at soc.pidgin.im
Sat Jul 7 03:34:14 EDT 2012
Changeset: 66b28488a92d5c564b4f7abe219b932f818057d7
Author: Michael Zangl <michael at soc.pidgin.im>
Date: 2012-06-17 19:03 +0200
Branch: soc.2012.android
URL: http://hg.pidgin.im/soc/2012/michael/android/rev/66b28488a92d
Description:
Routed account added/deleted/disabled/enabled signals to account manager. Implemented addAccount and deleteAccount methods.
diffstat:
android/workspace/im.pidgin.libpurple/native/PurpleAccountManager.c | 111 +++++++++-
android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/account/PurpleAccountManager.java | 43 +++-
2 files changed, 150 insertions(+), 4 deletions(-)
diffs (206 lines):
diff --git a/android/workspace/im.pidgin.libpurple/native/PurpleAccountManager.c b/android/workspace/im.pidgin.libpurple/native/PurpleAccountManager.c
--- a/android/workspace/im.pidgin.libpurple/native/PurpleAccountManager.c
+++ b/android/workspace/im.pidgin.libpurple/native/PurpleAccountManager.c
@@ -19,12 +19,18 @@
gboolean on_list, PurpleAccountRequestAuthorizationCb authorize_cb,
PurpleAccountRequestAuthorizationCb deny_cb, void* user_data);
+static void
+account_added_callback(PurpleAccount *account);
+static void
+account_removed_callback(PurpleAccount *account);
+static void
+account_abled_callback(PurpleAccount *account);
+
void
close_account_request(void* ui_handle);
PurpleAccountUiOps uiOps = { notify_added, status_changed, request_add,
- request_authorize, close_account_request, NULL, NULL, NULL, NULL
-};
+ request_authorize, close_account_request, NULL, NULL, NULL, NULL };
JavaObjectReference accountList = JAVA_NULL_OBJECT_REF;
@@ -38,6 +44,58 @@
{
setJavaObject(&accountList, env, obj);
purple_accounts_set_ui_ops(&uiOps);
+
+ purple_signal_connect(purple_accounts_get_handle(), "account-added",
+ &accountList, PURPLE_CALLBACK(account_added_callback), NULL);
+ purple_signal_connect(purple_accounts_get_handle(), "account-removed",
+ &accountList, PURPLE_CALLBACK(account_removed_callback), NULL);
+ purple_signal_connect(purple_accounts_get_handle(), "account-disabled",
+ &accountList, PURPLE_CALLBACK(account_abled_callback), NULL);
+ purple_signal_connect(purple_accounts_get_handle(), "account-enabled",
+ &accountList, PURPLE_CALLBACK(account_abled_callback), NULL);
+
+}
+
+/*
+ * Class: im_pidgin_libpurple_account_PurpleAccountManager
+ * Method: getAllAccounts_native
+ * Signature: ()J
+ */JNIEXPORT jlong JNICALL
+Java_im_pidgin_libpurple_account_PurpleAccountManager_getAllAccounts_1native(
+ JNIEnv *env, jobject obj)
+{
+ return pToLong(purple_accounts_get_all());
+}
+/*
+ * Class: im_pidgin_libpurple_account_PurpleAccountManager
+ * Method: getActiveAccounts_native
+ * Signature: ()J
+ */JNIEXPORT jlong JNICALL
+Java_im_pidgin_libpurple_account_PurpleAccountManager_getActiveAccounts_1native(
+ JNIEnv *env, jobject obj)
+{
+ return pToLong(purple_accounts_get_all_active());
+}
+/*
+ * Class: im_pidgin_libpurple_account_PurpleAccountManager
+ * Method: addAccount_native
+ * Signature: (J)V
+ */JNIEXPORT void JNICALL
+Java_im_pidgin_libpurple_account_PurpleAccountManager_addAccount_1native(
+ JNIEnv *env, jobject obj, jlong account)
+{
+ purple_accounts_add((PurpleAccount*) longToP(account));
+}
+
+/*
+ * Class: im_pidgin_libpurple_account_PurpleAccountManager
+ * Method: deleteAccount_native
+ * Signature: (J)V
+ */JNIEXPORT void JNICALL
+Java_im_pidgin_libpurple_account_PurpleAccountManager_deleteAccount_1native(
+ JNIEnv *env, jobject obj, jlong account)
+{
+ purple_accounts_delete((PurpleAccount*) longToP(account));
}
static void
@@ -183,3 +241,52 @@
ui_handle_ptr);
}
}
+
+static void
+account_added_callback(PurpleAccount *account)
+{
+ static JavaMethodIDCache methodCache = METHOD_CACHE("accountAdded", "(J)V");
+
+ jmethodID mid;
+
+ CALLBACK_START_VOID(accountList);
+
+ mid = getMethodIDCachedReferenced(env, accountList.class, &methodCache);
+ if (mid != NULL) {
+ (*env)->CallVoidMethod(env, accountList.handlerObject, mid,
+ pToLong(account));
+ }
+}
+
+static void
+account_removed_callback(PurpleAccount *account)
+{
+ static JavaMethodIDCache methodCache =
+ METHOD_CACHE("accountRemoved", "(J)V");
+
+ jmethodID mid;
+
+ CALLBACK_START_VOID(accountList);
+
+ mid = getMethodIDCachedReferenced(env, accountList.class, &methodCache);
+ if (mid != NULL) {
+ (*env)->CallVoidMethod(env, accountList.handlerObject, mid,
+ pToLong(account));
+ }
+}
+
+static void
+account_abled_callback(PurpleAccount *account)
+{
+ static JavaMethodIDCache methodCache = METHOD_CACHE("accountAbled", "(J)V");
+
+ jmethodID mid;
+
+ CALLBACK_START_VOID(accountList);
+
+ mid = getMethodIDCachedReferenced(env, accountList.class, &methodCache);
+ if (mid != NULL) {
+ (*env)->CallVoidMethod(env, accountList.handlerObject, mid,
+ pToLong(account));
+ }
+}
diff --git a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/account/PurpleAccountManager.java b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/account/PurpleAccountManager.java
--- a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/account/PurpleAccountManager.java
+++ b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/account/PurpleAccountManager.java
@@ -128,17 +128,32 @@
accountListeners.notifyStatusChanged(purpleAccount);
}
+ protected void notifyAccountAdded(PurpleAccount purpleAccount) {
+ for (PurpleAccountListListener l : listeners) {
+ l.accountAdded(purpleAccount);
+ }
+ }
+
+ protected void notifyAccountRemoved(PurpleAccount purpleAccount) {
+ for (PurpleAccountListListener l : listeners) {
+ l.accountRemoved(purpleAccount);
+ }
+ }
+
@Override
public PurpleAccount addAccount(String username,
PurpleProtocolPlugin protocol) {
- PurpleAccount account = PurpleAccount.newAccount(getManager(), username, protocol);
+ PurpleAccount account = PurpleAccount.newAccount(getManager(),
+ username, protocol);
addAccount_native(account.getNativePointer());
return account;
}
/**
* Calls purple_accounts_add(account);
- * @param nativePointer account
+ *
+ * @param nativePointer
+ * account
*/
private native void addAccount_native(long nativePointer);
@@ -149,7 +164,31 @@
/**
* Calls purple_accounts_delete
+ *
* @param nativePointer
*/
private native void deleteAccount_native(long nativePointer);
+
+ protected void accountAdded(long nativeAccount) {
+ PurpleAccount account = getPeer(nativeAccount);
+ notifyAccountAdded(account);
+ }
+
+ protected void accountRemoved(long nativeAccount) {
+ PurpleAccount account = getPeer(nativeAccount);
+ notifyAccountRemoved(account);
+
+ /* remove it to free resources. */
+ knownAccounts.remove(nativeAccount);
+ }
+
+ /**
+ * Account enabled / disabled
+ *
+ * @param nativeAccount
+ */
+ protected void accountAbled(long nativeAccount) {
+ PurpleAccount account = getPeer(nativeAccount);
+ notifyPropertiesChanged(account);
+ }
}
More information about the Commits
mailing list