[vlc-commits] dialog: support format strings in dialog_Question()

Rémi Denis-Courmont git at videolan.org
Sun Sep 30 15:45:15 CEST 2012


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Sep 30 16:23:20 2012 +0300| [d40dc861c45da1c6e1acc384be695bfaef1b58f1] | committer: Rémi Denis-Courmont

dialog: support format strings in dialog_Question()

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

 include/vlc_dialog.h   |    8 +++++---
 src/interface/dialog.c |   22 ++++++++++++++++------
 2 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/include/vlc_dialog.h b/include/vlc_dialog.h
index 7c46d66..168bea4 100644
--- a/include/vlc_dialog.h
+++ b/include/vlc_dialog.h
@@ -91,9 +91,11 @@ typedef struct dialog_question_t
     int answer;
 } dialog_question_t;
 
-VLC_API 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_API int dialog_Question(vlc_object_t *, const char *, const char *,
+                            const char *, const char *, const char *, ...)
+VLC_FORMAT(3, 7);
+#define dialog_Question(o, t, m, y, n, ...) \
+        dialog_Question(VLC_OBJECT(o), t, m, y, n, __VA_ARGS__)
 
 typedef struct dialog_progress_bar_t
 {   /* Request-time parameters */
diff --git a/src/interface/dialog.c b/src/interface/dialog.c
index bbfb315..a1b8d3b 100644
--- a/src/interface/dialog.c
+++ b/src/interface/dialog.c
@@ -174,15 +174,15 @@ void dialog_Login (vlc_object_t *obj, char **username, char **password,
  * 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 fmt format string for the 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)
+int dialog_Question (vlc_object_t *obj, const char *title, const char *fmt,
+                     const char *yes, const char *no, const char *cancel, ...)
 {
     if (obj->i_flags & OBJECT_FLAGS_NOINTERACT)
         return 0;
@@ -191,10 +191,20 @@ int dialog_Question (vlc_object_t *obj, const char *title, const char *text,
     if (provider == NULL)
         return 0;
 
-    dialog_question_t dialog = { title, text, yes, no, cancel, 0, };
-    var_SetAddress (provider, "dialog-question", &dialog);
+    char *text;
+    va_list ap;
+    int answer = 0;
+
+    va_start (ap, cancel);
+    if (vasprintf (&text, fmt, ap) != -1)
+    {
+        dialog_question_t dialog = { title, text, yes, no, cancel, 0, };
+        var_SetAddress (provider, "dialog-question", &dialog);
+        answer = dialog.answer;
+    }
+    va_end (ap);
     vlc_object_release (provider);
-    return dialog.answer;
+    return answer;
 }
 
 #undef dialog_ProgressCreate



More information about the vlc-commits mailing list