X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Finterface%2Fdialog.c;h=22ac7859e77f28269b1e8f5002e941bd27f0dbe9;hb=f645d20b9fe57805ec3d217a2aeaaee9dfbb9b1f;hp=bfd8c91a6d52f06e3609445d3cd0a213cc62f125;hpb=3c62d02f23d51f30d0fa1c2c9d314932e8df3ab5;p=vlc diff --git a/src/interface/dialog.c b/src/interface/dialog.c index bfd8c91a6d..22ac7859e7 100644 --- a/src/interface/dialog.c +++ b/src/interface/dialog.c @@ -194,3 +194,67 @@ int dialog_Question (vlc_object_t *obj, const char *title, const char *text, vlc_object_release (provider); return dialog.answer; } + +#undef dialog_ProgressCreate +/** + * Creates a progress bar dialog. + */ +dialog_progress_bar_t * +dialog_ProgressCreate (vlc_object_t *obj, const char *title, + const char *message, const char *cancel) +{ + if (obj->i_flags & OBJECT_FLAGS_NOINTERACT) + return NULL; + + vlc_object_t *provider = dialog_GetProvider (obj); + if (provider == NULL) + return NULL; + + dialog_progress_bar_t *dialog = malloc (sizeof (*dialog)); + if (dialog != NULL) + { + dialog->title = title; + dialog->message = message; + dialog->cancel = cancel; + var_SetAddress (provider, "dialog-progress-bar", dialog); +#ifndef NDEBUG + dialog->title = dialog->message = dialog->cancel = NULL; +#endif + assert (dialog->pf_update); + assert (dialog->pf_check); + assert (dialog->pf_destroy); + } + + /* FIXME: This could conceivably crash if the dialog provider is destroyed + * before the dialog user. Holding the provider does not help, as it only + * protects object variable operations. For instance, it does not prevent + * unloading of the interface plugin. In the short term, the only solution + * is to not use progress dialog after deinitialization of the interfaces. + */ + vlc_object_release (provider); + return dialog; +} + +void dialog_ProgressDestroy (dialog_progress_bar_t *dialog) +{ + assert (dialog); + + dialog->pf_destroy (dialog->p_sys); + free (dialog); +} + +void dialog_ProgressSet (dialog_progress_bar_t *dialog, const char *text, + float value) +{ + assert (dialog); + + dialog->pf_update (dialog->p_sys, text, value); +} + +bool dialog_ProgressCancelled (dialog_progress_bar_t *dialog) +{ + assert (dialog); + + return dialog->pf_check (dialog->p_sys); +} +