[vlc-devel] commit: dialog_Question: simple thread-safe replacement for intf_UserYesNo ( Rémi Denis-Courmont )

git version control git at videolan.org
Sun Mar 8 11:38:10 CET 2009


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Mar  8 12:04:32 2009 +0200| [3c62d02f23d51f30d0fa1c2c9d314932e8df3ab5] | committer: Rémi Denis-Courmont 

dialog_Question: simple thread-safe replacement for intf_UserYesNo

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=3c62d02f23d51f30d0fa1c2c9d314932e8df3ab5
---

 include/vlc_dialog.h   |   17 +++++++++++++++++
 src/interface/dialog.c |   29 +++++++++++++++++++++++++++++
 src/libvlccore.sym     |    1 +
 3 files changed, 47 insertions(+), 0 deletions(-)

diff --git a/include/vlc_dialog.h b/include/vlc_dialog.h
index f9db0ad..fb34492 100644
--- a/include/vlc_dialog.h
+++ b/include/vlc_dialog.h
@@ -79,6 +79,23 @@ VLC_EXPORT( void, dialog_Login, (vlc_object_t *, char **, char **, const char *,
 #define dialog_Login(o, u, p, t, ...) \
         dialog_Login(VLC_OBJECT(o), u, p, t, __VA_ARGS__)
 
+/**
+ * A question dialog.
+ */
+typedef struct dialog_question_t
+{
+    const char *title;
+    const char *message;
+    const char *yes;
+    const char *no;
+    const char *cancel;
+    int answer;
+} dialog_question_t;
+
+VLC_EXPORT( int, dialog_Question, (vlc_object_t *, const char *, const char *, const char *, const char *, const char *) );
+#define dialog_Question(o, t, m, y, n, c) \
+        dialog_Question(VLC_OBJECT(o), t, m, y, n, c)
+
 VLC_EXPORT( int, dialog_Register, (vlc_object_t *) );
 VLC_EXPORT( int, dialog_Unregister, (vlc_object_t *) );
 #define dialog_Register(o) dialog_Register(VLC_OBJECT(o))
diff --git a/src/interface/dialog.c b/src/interface/dialog.c
index d0ba589..bfd8c91 100644
--- a/src/interface/dialog.c
+++ b/src/interface/dialog.c
@@ -165,3 +165,32 @@ void dialog_Login (vlc_object_t *obj, char **username, char **password,
     va_end (ap);
     vlc_object_release (provider);
 }
+
+
+#undef dialog_Question
+/**
+ * Asks a total (Yes/No/Cancel) question through the user interface.
+ * @param obj VLC object emitting the question
+ * @param title dialog box title
+ * @param text dialog box text
+ * @param yes first choice/button text
+ * @param no second choice/button text
+ * @param cancel third answer/button text, or NULL if no third option
+ * @return 0 if the user could not answer the question (e.g. there is no UI),
+ * 1, 2 resp. 3 if the user pressed the first, second resp. third button.
+ */
+int dialog_Question (vlc_object_t *obj, const char *title, const char *text,
+                     const char *yes, const char *no, const char *cancel)
+{
+    if (obj->i_flags & OBJECT_FLAGS_NOINTERACT)
+        return 0;
+
+    vlc_object_t *provider = dialog_GetProvider (obj);
+    if (provider == NULL)
+        return 0;
+
+    dialog_question_t dialog = { title, text, yes, no, cancel, 0, };
+    var_SetAddress (provider, "dialog-question", &dialog);
+    vlc_object_release (provider);
+    return dialog.answer;
+}
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 4cfca8a..e59faea 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -103,6 +103,7 @@ demux_PacketizerDestroy
 demux_PacketizerNew
 demux_vaControlHelper
 dialog_Login
+dialog_Question
 dialog_Register
 dialog_Unregister
 dialog_VFatal




More information about the vlc-devel mailing list