[Android] LibVLC Dialog: update API (squash)

Thomas Guillem git at videolan.org
Thu Feb 4 12:30:55 CET 2016


vlc-android | branch: dialog | Thomas Guillem <thomas at gllm.fr> | Thu Feb  4 11:24:44 2016 +0100| [500d92d306d1877ac71067fec89b506f62f4639b] | committer: Thomas Guillem

LibVLC Dialog: update API (squash)

> https://code.videolan.org/videolan/vlc-android/commit/500d92d306d1877ac71067fec89b506f62f4639b
---

 libvlc/jni/libvlcjni-dialog.c | 136 ++++++++++++++++++++++++------------------
 1 file changed, 78 insertions(+), 58 deletions(-)

diff --git a/libvlc/jni/libvlcjni-dialog.c b/libvlc/jni/libvlcjni-dialog.c
index 1ace73b..526f29f 100644
--- a/libvlc/jni/libvlcjni-dialog.c
+++ b/libvlc/jni/libvlcjni-dialog.c
@@ -31,71 +31,88 @@
 
 JNIEnv *jni_get_env(const char *name);
 
-static bool
-display_cb(libvlc_dialog_id *p_id, libvlc_dialog *p_dialog, void *p_data)
+
+static void
+dialog_set_context(JNIEnv *env, libvlc_dialog_id *p_id, jobject *jdialog)
+{
+    if (jdialog != NULL
+     && (jdialog = (*env)->NewGlobalRef(env, jdialog)) != NULL)
+        libvlc_dialog_set_context(p_id, jdialog);
+    else
+        libvlc_dialog_dismiss(p_id);
+}
+
+static void
+display_error_cb(const char *psz_title, const char *psz_text, void *p_data)
 {
-    jobject jdialog = NULL;
     JNIEnv *env = NULL;
+    if (!(env = jni_get_env(THREAD_NAME)))
+        return;
 
+    (*env)->CallStaticVoidMethod(env, fields.Dialog.clazz,
+        fields.Dialog.displayErrorFromNativeID,
+        (*env)->NewStringUTF(env, psz_title),
+        (*env)->NewStringUTF(env, psz_text));
+}
+
+static void
+display_login_cb(libvlc_dialog_id *p_id, const char *psz_title,
+                 const char *psz_text, const char *psz_default_username,
+                 bool b_ask_store, void *p_data)
+{
+    jobject jdialog = NULL;
+    JNIEnv *env = NULL;
     if (!(env = jni_get_env(THREAD_NAME)))
-        return false;
+        return;
 
-    switch (p_dialog->i_type)
-    {
-    case LIBVLC_DIALOG_ERROR:
-        (*env)->CallStaticVoidMethod(env, fields.Dialog.clazz,
-            fields.Dialog.displayErrorFromNativeID,
-            (*env)->NewStringUTF(env, p_dialog->psz_title),
-            (*env)->NewStringUTF(env, p_dialog->psz_text));
-        return true;
-    case LIBVLC_DIALOG_LOGIN:
-        jdialog = (*env)->CallStaticObjectMethod(env, fields.Dialog.clazz,
-            fields.Dialog.displayLoginFromNativeID,
-            (jlong)(intptr_t) p_id,
-            (*env)->NewStringUTF(env, p_dialog->psz_title),
-            (*env)->NewStringUTF(env, p_dialog->psz_text),
-            (*env)->NewStringUTF(env, p_dialog->u.login.psz_default_username),
-            p_dialog->u.login.b_ask_store);
-        break;
-    case LIBVLC_DIALOG_QUESTION:
-    {
-        const char *psz_a1 = p_dialog->u.question.psz_action1;
-        const char *psz_a2 = p_dialog->u.question.psz_action2;
-        jdialog = (*env)->CallStaticObjectMethod(env, fields.Dialog.clazz,
-            fields.Dialog.displayQuestionFromNativeID,
-            (jlong)(intptr_t) p_id,
-            (*env)->NewStringUTF(env, p_dialog->psz_title),
-            (*env)->NewStringUTF(env, p_dialog->psz_text),
-            p_dialog->u.question.i_type,
-            (*env)->NewStringUTF(env, p_dialog->u.question.psz_cancel),
-            psz_a1 ? (*env)->NewStringUTF(env, psz_a1) : NULL,
-            psz_a2 ? (*env)->NewStringUTF(env, psz_a2) : NULL);
-        break;
-    }
-    case LIBVLC_DIALOG_PROGRESS:
-        jdialog = (*env)->CallStaticObjectMethod(env, fields.Dialog.clazz,
-            fields.Dialog.displayProgressFromNativeID,
-            (jlong)(intptr_t) p_id,
-            (*env)->NewStringUTF(env, p_dialog->psz_title),
-            (*env)->NewStringUTF(env, p_dialog->psz_text),
-            p_dialog->u.progress.b_indeterminate,
-            p_dialog->u.progress.f_position,
-            (*env)->NewStringUTF(env, p_dialog->u.progress.psz_cancel));
-        break;
-    default:
-        return false;
-    }
+    jdialog = (*env)->CallStaticObjectMethod(env, fields.Dialog.clazz,
+        fields.Dialog.displayLoginFromNativeID,
+        (jlong)(intptr_t) p_id,
+        (*env)->NewStringUTF(env, psz_title),
+        (*env)->NewStringUTF(env, psz_text),
+        (*env)->NewStringUTF(env, psz_default_username), b_ask_store);
+    dialog_set_context(env, p_id, jdialog);
+}
 
-    if (jdialog == NULL)
-        return false;
+static void
+display_question_cb(libvlc_dialog_id *p_id, const char *psz_title,
+                    const char *psz_text, libvlc_dialog_question_type i_type,
+                    const char *psz_cancel, const char *psz_action1,
+                    const char *psz_action2, void *p_data)
+{
+    jobject jdialog = NULL;
+    JNIEnv *env = NULL;
+    if (!(env = jni_get_env(THREAD_NAME)))
+        return;
 
-    assert(p_id != NULL);
-    jdialog = (*env)->NewGlobalRef(env, jdialog);
-    if (jdialog == NULL)
-        return false;
+    jdialog = (*env)->CallStaticObjectMethod(env, fields.Dialog.clazz,
+        fields.Dialog.displayQuestionFromNativeID,
+        (jlong)(intptr_t) p_id,
+        (*env)->NewStringUTF(env, psz_title),
+        (*env)->NewStringUTF(env, psz_text), i_type,
+        (*env)->NewStringUTF(env, psz_cancel),
+        psz_action1 ? (*env)->NewStringUTF(env, psz_action1) : NULL,
+        psz_action2 ? (*env)->NewStringUTF(env, psz_action2) : NULL);
+    dialog_set_context(env, p_id, jdialog);
+}
+
+static void
+display_progress_cb(libvlc_dialog_id *p_id, const char *psz_title,
+                    const char *psz_text, bool b_indeterminate,
+                    float f_position, const char *psz_cancel, void *p_data)
+{
+    jobject jdialog = NULL;
+    JNIEnv *env = NULL;
+    if (!(env = jni_get_env(THREAD_NAME)))
+        return;
 
-    libvlc_dialog_set_context(p_id, jdialog);
-    return true;
+    jdialog = (*env)->CallStaticObjectMethod(env, fields.Dialog.clazz,
+        fields.Dialog.displayProgressFromNativeID,
+        (jlong)(intptr_t) p_id,
+        (*env)->NewStringUTF(env, psz_title),
+        (*env)->NewStringUTF(env, psz_text),
+        b_indeterminate, f_position, (*env)->NewStringUTF(env, psz_cancel));
+    dialog_set_context(env, p_id, jdialog);
 }
 
 static void
@@ -133,7 +150,10 @@ update_progress_cb(libvlc_dialog_id *p_id, float f_position,
 }
 
 static const libvlc_dialog_cbs dialog_cbs = {
-    .pf_display = display_cb,
+    .pf_display_error = display_error_cb,
+    .pf_display_login = display_login_cb,
+    .pf_display_question = display_question_cb,
+    .pf_display_progress = display_progress_cb,
     .pf_cancel = cancel_cb,
     .pf_update_progress = update_progress_cb,
 };



More information about the Android mailing list