VLC 4.0.0-dev
vlc_dialog.h
Go to the documentation of this file.
1/*****************************************************************************
2 * vlc_dialog.h: user interaction dialogs
3 *****************************************************************************
4 * Copyright (C) 2009 RĂ©mi Denis-Courmont
5 * Copyright (C) 2016 VLC authors and VideoLAN
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation; either version 2.1 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this program; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
20 *****************************************************************************/
21
22#ifndef VLC_DIALOG_H_
23#define VLC_DIALOG_H_
24# include <stdarg.h>
25
30/* Called from src/libvlc.c */
31int
33
34/* Called from src/libvlc.c */
35void
37
38/**
39 * @defgroup vlc_dialog VLC dialog
40 * @ingroup interface
41 * @{
42 * @file
43 * This file declares VLC dialog functions
44 * @defgroup vlc_dialog_api VLC dialog functions
45 * In order to interact with the user
46 * @{
47 */
48
49/**
50 * Dialog question type, see vlc_dialog_wait_question()
51 */
52typedef enum vlc_dialog_question_type
59/**
60 * Sends an error message
61 *
62 * This function returns immediately
63 *
64 * @param p_obj the VLC object emitting the error
65 * @param psz_title title of the error dialog
66 * @param psz_fmt format string for the error message
67 * @return VLC_SUCCESS on success, or a VLC error code on error
68 */
69VLC_API int
71 const char *psz_fmt, ...) VLC_FORMAT(3,4);
72#define vlc_dialog_display_error(a, b, c, ...) \
73 vlc_dialog_display_error(VLC_OBJECT(a), b, c, ##__VA_ARGS__)
74
75/**
76 * Sends an error message
77 *
78 * Equivalent to vlc_dialog_display_error() expect that it's called with a
79 * va_list.
80 */
81VLC_API int
83 const char *psz_fmt, va_list ap);
84
85/**
86 * Requests an user name and a password
87 *
88 * This function waits until the user dismisses the dialog or responds. It's
89 * interruptible via vlc_interrupt. In that case, vlc_dialog_cbs.pf_cancel()
90 * will be invoked. If p_store is not NULL, the user will be asked to store the
91 * password or not.
92 *
93 * @param p_obj the VLC object emitting the dialog
94 * @param ppsz_username a pointer to the user name provided by the user, it
95 * must be freed with free() on success
96 * @param ppsz_password a pointer to the password provided by the user, it must
97 * be freed with free() on success
98 * @param p_store a pointer to the store answer provided by the user (optional)
99 * @param psz_default_username default user name proposed
100 * @param psz_title title of the login dialog
101 * @param psz_fmt format string for the login message
102 * @return < 0 on error, 0 if the user cancelled it, and 1 if ppsz_username and
103 * ppsz_password are valid.
104 */
105VLC_API int
106vlc_dialog_wait_login(vlc_object_t *p_obj, char **ppsz_username,
107 char **ppsz_password, bool *p_store,
108 const char *psz_default_username,
109 const char *psz_title, const char *psz_fmt, ...)
110 VLC_FORMAT(7,8);
111#define vlc_dialog_wait_login(a, b, c, d, e, f, g, ...) \
112 vlc_dialog_wait_login(VLC_OBJECT(a), b, c, d, e, f, g, ##__VA_ARGS__)
113
114/**
115 * Requests an user name and a password
116 *
117 * Equivalent to vlc_dialog_wait_login() expect that it's called with a
118 * va_list.
119 */
120VLC_API int
121vlc_dialog_wait_login_va(vlc_object_t *p_obj, char **ppsz_username,
122 char **ppsz_password, bool *p_store,
123 const char *psz_default_username,
124 const char *psz_title, const char *psz_fmt, va_list ap);
125
126/**
127 * Asks a total (Yes/No/Cancel) question
128 *
129 * This function waits until the user dismisses the dialog or responds. It's
130 * interruptible via vlc_interrupt. In that case, vlc_dialog_cbs.pf_cancel()
131 * will be invoked. The psz_cancel is mandatory since this dialog is always
132 * cancellable by the user.
133 *
134 * @param p_obj the VLC object emitting the dialog
135 * @param i_type question type (severity of the question)
136 * @param psz_cancel text of the cancel button
137 * @param psz_action1 first choice/button text (optional)
138 * @param psz_action2 second choice/button text (optional)
139 * @param psz_title title of the question dialog
140 * @param psz_fmt format string for the question message
141 * @return < 0 on error, 0 if the user cancelled it, 1 on action1, 2 on action2
142 */
143VLC_API int
146 const char *psz_cancel, const char *psz_action1,
147 const char *psz_action2, const char *psz_title,
148 const char *psz_fmt, ...) VLC_FORMAT(7,8);
149#define vlc_dialog_wait_question(a, b, c, d, e, f, g, ...) \
150 vlc_dialog_wait_question(VLC_OBJECT(a), b, c, d, e, f, g, ##__VA_ARGS__)
151
152/**
153 * Asks a total (Yes/No/Cancel) question
154 *
155 * Equivalent to vlc_dialog_wait_question() expect that it's called with a
156 * va_list.
157 */
158VLC_API int
161 const char *psz_cancel, const char *psz_action1,
162 const char *psz_action2, const char *psz_title,
163 const char *psz_fmt, va_list ap);
164
165/**
166 * Display a progress dialog
167 *
168 * This function returns immediately
169 *
170 * @param p_obj the VLC object emitting the dialog
171 * @param b_indeterminate true if the progress dialog is indeterminate
172 * @param f_position initial position of the progress bar (between 0.0 and 1.0)
173 * @param psz_cancel text of the cancel button, if NULL the dialog is not
174 * cancellable (optional)
175 * @param psz_title title of the progress dialog
176 * @param psz_fmt format string for the progress message
177 * @return a valid vlc_dialog_id on success, must be released with
178 * vlc_dialog_id_release()
179 */
181vlc_dialog_display_progress(vlc_object_t *p_obj, bool b_indeterminate,
182 float f_position, const char *psz_cancel,
183 const char *psz_title, const char *psz_fmt, ...)
184 VLC_FORMAT(6,7);
185#define vlc_dialog_display_progress(a, b, c, d, e, f, ...) \
186 vlc_dialog_display_progress(VLC_OBJECT(a), b, c, d, e, f, ##__VA_ARGS__)
187
188/**
189 * Display a progress dialog
190 *
191 * Equivalent to vlc_dialog_display_progress() expect that it's called with a
192 * va_list.
193 */
195vlc_dialog_display_progress_va(vlc_object_t *p_obj, bool b_indeterminate,
196 float f_position, const char *psz_cancel,
197 const char *psz_title, const char *psz_fmt,
198 va_list ap);
199
200/**
201 * Update the position of the progress dialog
202 *
203 * @param p_obj the VLC object emitting the dialog
204 * @param p_id id of the dialog to update
205 * @param f_position position of the progress bar (between 0.0 and 1.0)
206 * @return VLC_SUCCESS on success, or a VLC error code on error
207 */
208VLC_API int
210 float f_position);
211#define vlc_dialog_update_progress(a, b, c) \
212 vlc_dialog_update_progress(VLC_OBJECT(a), b, c)
213
214/**
215 * Update the position and the message of the progress dialog
216 *
217 * @param p_obj the VLC object emitting the dialog
218 * @param p_id id of the dialog to update
219 * @param f_position position of the progress bar (between 0.0 and 1.0)
220 * @param psz_fmt format string for the progress message
221 * @return VLC_SUCCESS on success, or a VLC error code on error
222 */
223VLC_API int
225 float f_position, const char *psz_fmt, ...)
226 VLC_FORMAT(4, 5);
227#define vlc_dialog_update_progress_text(a, b, c, d, ...) \
228 vlc_dialog_update_progress_text(VLC_OBJECT(a), b, c, d, ##__VA_ARGS__)
229
230/**
231 * Update the position and the message of the progress dialog
232 *
233 * Equivalent to vlc_dialog_update_progress_text() expect that it's called
234 * with a va_list.
235 */
236VLC_API int
238 float f_position, const char *psz_fmt,
239 va_list ap);
240
241/**
242 * Release the dialog id returned by vlc_dialog_display_progress()
243 *
244 * It causes the vlc_dialog_cbs.pf_cancel() callback to be invoked.
245 *
246 * @param p_obj the VLC object emitting the dialog
247 * @param p_id id of the dialog to release
248 */
249VLC_API void
251#define vlc_dialog_release(a, b) \
252 vlc_dialog_release(VLC_OBJECT(a), b)
253
254/**
255 * Return true if the dialog id is cancelled
256 *
257 * @param p_obj the VLC object emitting the dialog
258 * @param p_id id of the dialog
259 */
260VLC_API bool
262#define vlc_dialog_is_cancelled(a, b) \
263 vlc_dialog_is_cancelled(VLC_OBJECT(a), b)
264
265/**
266 * @}
267 * @defgroup vlc_dialog_impl VLC dialog callbacks
268 * Need to be implemented by GUI modules or libvlc
269 * @{
270 */
271
272/**
273 * Dialog callbacks to be implemented
274 */
275typedef struct vlc_dialog_cbs
277 /**
278 * Called when a login dialog needs to be displayed
279 *
280 * You can interact with this dialog by calling vlc_dialog_id_post_login()
281 * to post an answer or vlc_dialog_id_dismiss() to cancel this dialog.
282 *
283 * @note to receive this callback, vlc_dialog_cbs.pf_cancel should not be
284 * NULL.
285 *
286 * @param p_data opaque pointer for the callback
287 * @param p_id id used to interact with the dialog
288 * @param psz_title title of the dialog
289 * @param psz_text text of the dialog
290 * @param psz_default_username user name that should be set on the user form
291 * @param b_ask_store if true, ask the user if he wants to save the
292 * credentials
293 */
294 void (*pf_display_login)(void *p_data, vlc_dialog_id *p_id,
295 const char *psz_title, const char *psz_text,
296 const char *psz_default_username,
297 bool b_ask_store);
298
299 /**
300 * Called when a question dialog needs to be displayed
301 *
302 * You can interact with this dialog by calling vlc_dialog_id_post_action()
303 * to post an answer or vlc_dialog_id_dismiss() to cancel this dialog.
304 *
305 * @note to receive this callback, vlc_dialog_cbs.pf_cancel should not be
306 * NULL.
307 *
308 * @param p_data opaque pointer for the callback
309 * @param p_id id used to interact with the dialog
310 * @param psz_title title of the dialog
311 * @param psz_text text of the dialog
312 * @param i_type question type (or severity) of the dialog
313 * @param psz_cancel text of the cancel button
314 * @param psz_action1 text of the first button, if NULL, don't display this
315 * button
316 * @param psz_action2 text of the second button, if NULL, don't display
317 * this button
318 */
319 void (*pf_display_question)(void *p_data, vlc_dialog_id *p_id,
320 const char *psz_title, const char *psz_text,
322 const char *psz_cancel, const char *psz_action1,
323 const char *psz_action2);
324
325 /**
326 * Called when a progress dialog needs to be displayed
327 *
328 * If cancellable (psz_cancel != NULL), you can cancel this dialog by
329 * calling vlc_dialog_id_dismiss()
330 *
331 * @note to receive this callback, vlc_dialog_cbs.pf_cancel and
332 * vlc_dialog_cbs.pf_update_progress should not be NULL.
333 *
334 * @param p_data opaque pointer for the callback
335 * @param p_id id used to interact with the dialog
336 * @param psz_title title of the dialog
337 * @param psz_text text of the dialog
338 * @param b_indeterminate true if the progress dialog is indeterminate
339 * @param f_position initial position of the progress bar (between 0.0 and
340 * 1.0)
341 * @param psz_cancel text of the cancel button, if NULL the dialog is not
342 * cancellable
343 */
344 void (*pf_display_progress)(void *p_data, vlc_dialog_id *p_id,
345 const char *psz_title, const char *psz_text,
346 bool b_indeterminate, float f_position,
347 const char *psz_cancel);
348
349 /**
350 * Called when a displayed dialog needs to be cancelled
351 *
352 * The implementation must call vlc_dialog_id_dismiss() to really release
353 * the dialog.
354 *
355 * @param p_data opaque pointer for the callback
356 * @param p_id id of the dialog
357 */
358 void (*pf_cancel)(void *p_data, vlc_dialog_id *p_id);
360 /**
361 * Called when a progress dialog needs to be updated
362 *
363 * @param p_data opaque pointer for the callback
364 * @param p_id id of the dialog
365 * @param f_position osition of the progress bar (between 0.0 and 1.0)
366 * @param psz_text new text of the progress dialog
367 */
368 void (*pf_update_progress)(void *p_data, vlc_dialog_id *p_id,
369 float f_position, const char *psz_text);
372/**
373 * Called when an error message needs to be displayed
374 *
375 * @param p_data opaque pointer for the callback
376 * @param psz_title title of the dialog
377 * @param psz_text text of the dialog
378 */
379typedef void (*vlc_dialog_error_cbs)(void *p_data, const char *psz_title, const char *psz_text);
381/**
382 * Register callbacks to handle VLC dialogs
383 *
384 * @param p_cbs a pointer to callbacks, or NULL to unregister callbacks.
385 * @param p_data opaque pointer for the callback
386 */
387VLC_API void
389 const vlc_dialog_cbs *p_cbs, void *p_data);
390#define vlc_dialog_provider_set_callbacks(a, b, c) \
391 vlc_dialog_provider_set_callbacks(VLC_OBJECT(a), b, c)
392
393/**
394 * Register callbacks to handle VLC error messages
395 *
396 * @version LibVLC 4.0.0 and later.
397 *
398 * @param p_cbs a pointer to the callback, or NULL to unregister the callback.
399 * @param p_data opaque pointer for the callback
400 */
401VLC_API void
403 vlc_dialog_error_cbs p_cbs, void *p_data);
404#define vlc_dialog_provider_set_error_callback(a, b, c) \
405 vlc_dialog_provider_set_error_callback(VLC_OBJECT(a), b, c)
406
407/**
408 * Associate an opaque pointer with the dialog id
409 */
410VLC_API void
411vlc_dialog_id_set_context(vlc_dialog_id *p_id, void *p_context);
412
413/**
414 * Return the opaque pointer associated with the dialog id
415 */
416VLC_API void *
418
419/**
420 * Post a login answer
421 *
422 * After this call, p_id won't be valid anymore
423 *
424 * @see vlc_dialog_cbs.pf_display_login
425 *
426 * @param p_id id of the dialog
427 * @param psz_username valid and non empty string
428 * @param psz_password valid string (can be empty)
429 * @param b_store if true, store the credentials
430 * @return VLC_SUCCESS on success, or a VLC error code on error
431 */
432VLC_API int
433vlc_dialog_id_post_login(vlc_dialog_id *p_id, const char *psz_username,
434 const char *psz_password, bool b_store);
435
436/**
437 * Post a question answer
438 *
439 * After this call, p_id won't be valid anymore
440 *
441 * @see vlc_dialog_cbs.pf_display_question
442 *
443 * @param p_id id of the dialog
444 * @param i_action 1 for action1, 2 for action2
445 * @return VLC_SUCCESS on success, or a VLC error code on error
446 */
447VLC_API int
448vlc_dialog_id_post_action(vlc_dialog_id *p_id, int i_action);
449
450/**
451 * Dismiss a dialog
452 *
453 * After this call, p_id won't be valid anymore
454 *
455 * @see vlc_dialog_cbs.pf_cancel
456 *
457 * @param p_id id of the dialog
458 * @return VLC_SUCCESS on success, or a VLC error code on error
459 */
460VLC_API int
462
463/**
464 * @}
465 * @defgroup vlc_dialog_ext VLC extension dialog functions
466 * @{
467 */
468
469VLC_API int
471#define vlc_ext_dialog_update(a, b) \
472 vlc_ext_dialog_update(VLC_OBJECT(a), b)
473
474/**
475 * Dialog extension callback to be implemented
476 */
477typedef void (*vlc_dialog_ext_update_cb)(extension_dialog_t *p_ext_dialog,
478 void *p_data);
479
480/**
481 * Register a callback for VLC extension dialog
482 *
483 * @param pf_update a pointer to the update callback, or NULL to unregister
484 * callback
485 * @param p_data opaque pointer for the callback
486 */
487VLC_API void
489 vlc_dialog_ext_update_cb pf_update,
490 void *p_data);
491#define vlc_dialog_provider_set_ext_callback(a, b, c) \
492 vlc_dialog_provider_set_ext_callback(VLC_OBJECT(a), b, c)
493
494/** @} */
495/** @} */
496
497#endif
#define VLC_API
Definition: fourcc_gen.c:31
#define VLC_FORMAT(x, y)
String format function annotation.
Definition: vlc_common.h:204
#define vlc_dialog_wait_question(a, b, c, d, e, f, g,...)
Definition: vlc_dialog.h:150
int vlc_dialog_wait_question_va(vlc_object_t *p_obj, vlc_dialog_question_type i_type, const char *psz_cancel, const char *psz_action1, const char *psz_action2, const char *psz_title, const char *psz_fmt, va_list ap)
Asks a total (Yes/No/Cancel) question.
Definition: dialog.c:541
#define vlc_dialog_release(a, b)
Definition: vlc_dialog.h:252
int vlc_dialog_update_progress_text_va(vlc_object_t *p_obj, vlc_dialog_id *p_id, float f_position, const char *psz_fmt, va_list ap)
Update the position and the message of the progress dialog.
Definition: dialog.c:704
#define vlc_dialog_is_cancelled(a, b)
Definition: vlc_dialog.h:263
vlc_dialog_id * vlc_dialog_display_progress_va(vlc_object_t *p_obj, bool b_indeterminate, float f_position, const char *psz_cancel, const char *psz_title, const char *psz_fmt, va_list ap)
Display a progress dialog.
Definition: dialog.c:631
#define vlc_dialog_display_progress(a, b, c, d, e, f,...)
Definition: vlc_dialog.h:186
#define vlc_dialog_update_progress_text(a, b, c, d,...)
Definition: vlc_dialog.h:228
vlc_dialog_question_type
Dialog question type, see vlc_dialog_wait_question()
Definition: vlc_dialog.h:54
#define vlc_dialog_display_error(a, b, c,...)
Definition: vlc_dialog.h:73
int vlc_dialog_display_error_va(vlc_object_t *p_obj, const char *psz_title, const char *psz_fmt, va_list ap)
Sends an error message.
Definition: dialog.c:382
#define vlc_dialog_update_progress(a, b, c)
Definition: vlc_dialog.h:212
int vlc_dialog_wait_login_va(vlc_object_t *p_obj, char **ppsz_username, char **ppsz_password, bool *p_store, const char *psz_default_username, const char *psz_title, const char *psz_fmt, va_list ap)
Requests an user name and a password.
Definition: dialog.c:453
#define vlc_dialog_wait_login(a, b, c, d, e, f, g,...)
Definition: vlc_dialog.h:112
@ VLC_DIALOG_QUESTION_CRITICAL
Definition: vlc_dialog.h:57
@ VLC_DIALOG_QUESTION_NORMAL
Definition: vlc_dialog.h:55
@ VLC_DIALOG_QUESTION_WARNING
Definition: vlc_dialog.h:56
#define vlc_ext_dialog_update(a, b)
Definition: vlc_dialog.h:472
#define vlc_dialog_provider_set_ext_callback(a, b, c)
Definition: vlc_dialog.h:492
void(* vlc_dialog_ext_update_cb)(extension_dialog_t *p_ext_dialog, void *p_data)
Dialog extension callback to be implemented.
Definition: vlc_dialog.h:478
void(* vlc_dialog_error_cbs)(void *p_data, const char *psz_title, const char *psz_text)
Called when an error message needs to be displayed.
Definition: vlc_dialog.h:380
void vlc_dialog_id_set_context(vlc_dialog_id *p_id, void *p_context)
Associate an opaque pointer with the dialog id.
Definition: dialog.c:757
void * vlc_dialog_id_get_context(vlc_dialog_id *p_id)
Return the opaque pointer associated with the dialog id.
Definition: dialog.c:765
int vlc_dialog_id_dismiss(vlc_dialog_id *p_id)
Dismiss a dialog.
Definition: dialog.c:841
int vlc_dialog_id_post_login(vlc_dialog_id *p_id, const char *psz_username, const char *psz_password, bool b_store)
Post a login answer.
Definition: dialog.c:802
int vlc_dialog_id_post_action(vlc_dialog_id *p_id, int i_action)
Post a question answer.
Definition: dialog.c:828
#define vlc_dialog_provider_set_callbacks(a, b, c)
Definition: vlc_dialog.h:391
#define vlc_dialog_provider_set_error_callback(a, b, c)
Definition: vlc_dialog.h:405
struct vlc_dialog_cbs vlc_dialog_cbs
Dialog callbacks to be implemented.
int i_type
Definition: httpd.c:1282
Definition: dialog.c:78
Dialog descriptor for extensions.
Definition: vlc_extensions.h:214
char * psz_title
Title for the Dialog (in TitleBar)
Definition: vlc_extensions.h:217
Definition: vlc_objects.h:91
Dialog callbacks to be implemented.
Definition: vlc_dialog.h:277
void(* pf_cancel)(void *p_data, vlc_dialog_id *p_id)
Called when a displayed dialog needs to be cancelled.
Definition: vlc_dialog.h:359
void(* pf_display_question)(void *p_data, vlc_dialog_id *p_id, const char *psz_title, const char *psz_text, vlc_dialog_question_type i_type, const char *psz_cancel, const char *psz_action1, const char *psz_action2)
Called when a question dialog needs to be displayed.
Definition: vlc_dialog.h:320
void(* pf_display_progress)(void *p_data, vlc_dialog_id *p_id, const char *psz_title, const char *psz_text, bool b_indeterminate, float f_position, const char *psz_cancel)
Called when a progress dialog needs to be displayed.
Definition: vlc_dialog.h:345
void(* pf_update_progress)(void *p_data, vlc_dialog_id *p_id, float f_position, const char *psz_text)
Called when a progress dialog needs to be updated.
Definition: vlc_dialog.h:369
void(* pf_display_login)(void *p_data, vlc_dialog_id *p_id, const char *psz_title, const char *psz_text, const char *psz_default_username, bool b_ask_store)
Called when a login dialog needs to be displayed.
Definition: vlc_dialog.h:295
Definition: dialog.c:107
Definition: dialog.c:38
VLC object common members.
Definition: vlc_objects.h:45
This file is a collection of common definitions and types.
void libvlc_InternalDialogClean(libvlc_int_t *p_libvlc)
Definition: dialog.c:242
int libvlc_InternalDialogInit(libvlc_int_t *p_libvlc)
Definition: dialog.c:151