]> git.sesse.net Git - vlc/commitdiff
dialog: support format strings in dialog_Question()
authorRémi Denis-Courmont <remi@remlab.net>
Sun, 30 Sep 2012 13:23:20 +0000 (16:23 +0300)
committerRémi Denis-Courmont <remi@remlab.net>
Sun, 30 Sep 2012 13:45:11 +0000 (16:45 +0300)
include/vlc_dialog.h
src/interface/dialog.c

index 7c46d66a60b820cf5751c663c5740e1b1d4cd29c..168bea4b091aca59eba46291e94b79f016162462 100644 (file)
@@ -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 */
index bbfb3156bb62fbe19e9364b83a404afdad9ac09a..a1b8d3b2a675cb35fcfb3fc3cb9ce9e3478983a2 100644 (file)
@@ -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