Commit 2f79c80a authored by Thomas Guillem's avatar Thomas Guillem

dialog: remove old API

parent 9f47a3a5
......@@ -23,117 +23,6 @@
#define VLC_DIALOG_H_
# include <stdarg.h>
/**
* \ingroup interaction
* @{
* \file vlc_dialog.h
* User interaction dialog APIs
*/
/**
* A fatal error dialog.
* No response expected from the user.
*/
typedef struct dialog_fatal_t
{
const char *title;
const char *message;
} dialog_fatal_t;
VLC_API void dialog_VFatal(vlc_object_t *, bool, const char *, const char *, va_list);
static inline VLC_FORMAT(3, 4)
void dialog_Fatal (vlc_object_t *obj, const char *title, const char *fmt, ...)
{
va_list ap;
va_start (ap, fmt);
dialog_VFatal(obj, false, title, fmt, ap);
va_end (ap);
}
#define dialog_Fatal(o, t, ...) \
dialog_Fatal(VLC_OBJECT(o), t, __VA_ARGS__)
static inline VLC_FORMAT(3, 4)
void dialog_FatalWait (vlc_object_t *obj, const char *title,
const char *fmt, ...){
va_list ap;
va_start (ap, fmt);
dialog_VFatal(obj, true, title, fmt, ap);
va_end (ap);
}
#define dialog_FatalWait(o, t, ...) \
dialog_FatalWait(VLC_OBJECT(o), t, __VA_ARGS__)
/**
* A login dialog.
*/
typedef struct dialog_login_t
{
const char *title;
const char *message;
const char *default_username;
char **username;
char **password;
/* if store is NULL, password can't be stored (there is no keystore) */
bool *store;
} dialog_login_t;
VLC_API void dialog_Login(vlc_object_t *, const char *, char **, char **, bool *, const char *, const char *, ...) VLC_FORMAT (7, 8);
#define dialog_Login(o, u, p, s, t, v, w, ...) \
dialog_Login(VLC_OBJECT(o), u, p, s, t, v, w, __VA_ARGS__)
VLC_API void dialog_vaLogin(vlc_object_t *, const char *, char **, char **, bool *, const char *, const char *, va_list args);
#define dialog_vaLogin(o, u, p, s, t, v, w, x) \
dialog_vaLogin(VLC_OBJECT(o), u, p, s, t, v, w, x)
/**
* 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_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 */
const char *title;
const char *message;
const char *cancel;
/* Permanent parameters */
void (*pf_update) (void *, const char *, float);
bool (*pf_check) (void *);
void (*pf_destroy) (void *);
void *p_sys;
} dialog_progress_bar_t;
VLC_API dialog_progress_bar_t * dialog_ProgressCreate(vlc_object_t *, const char *, const char *, const char *) VLC_USED;
#define dialog_ProgressCreate(o, t, m, c) \
dialog_ProgressCreate(VLC_OBJECT(o), t, m, c)
VLC_API void dialog_ProgressDestroy(dialog_progress_bar_t *);
VLC_API void dialog_ProgressSet(dialog_progress_bar_t *, const char *, float);
VLC_API bool dialog_ProgressCancelled(dialog_progress_bar_t *);
VLC_API int dialog_Register(vlc_object_t *);
VLC_API int dialog_Unregister(vlc_object_t *);
#define dialog_Register(o) dialog_Register(VLC_OBJECT(o))
#define dialog_Unregister(o) dialog_Unregister(VLC_OBJECT(o))
/** @} */
typedef struct vlc_dialog_provider vlc_dialog_provider;
typedef struct vlc_dialog_id vlc_dialog_id;
typedef struct extension_dialog_t extension_dialog_t;
......
......@@ -311,8 +311,4 @@ struct extension_widget_t
extension_dialog_t *p_dialog; ///< Parent dialog
};
VLC_API int dialog_ExtensionUpdate(vlc_object_t*, extension_dialog_t *);
#define dialog_ExtensionUpdate(o, d) dialog_ExtensionUpdate(VLC_OBJECT(o), d)
#endif /* VLC_EXTENSIONS_H */
......@@ -33,273 +33,6 @@
#include <assert.h>
#include "libvlc.h"
static vlc_mutex_t provider_lock = VLC_STATIC_MUTEX;
#undef dialog_Register
/**
* Registers an object as the dialog provider.
* It is assumed that the appropriate variable callbacks are already
* registered.
*/
int dialog_Register (vlc_object_t *obj)
{
libvlc_priv_t *priv = libvlc_priv (obj->p_libvlc);
int ret = VLC_EGENERIC;
vlc_mutex_lock (&provider_lock);
if (priv->p_legacy_dialog_provider == NULL)
{ /* Since the object is responsible for unregistering itself before
* it terminates, at reference is not needed. */
priv->p_legacy_dialog_provider = obj;
ret = VLC_SUCCESS;
}
vlc_mutex_unlock (&provider_lock);
return ret;
}
#undef dialog_Unregister
/**
* Unregisters the dialog provider.
* Note that unless you have unregistered the callbacks already, the provider
* might still be in use by other threads. Also, you need to cancel all
* pending dialogs yourself.
*/
int dialog_Unregister (vlc_object_t *obj)
{
libvlc_priv_t *priv = libvlc_priv (obj->p_libvlc);
int ret = VLC_EGENERIC;
vlc_mutex_lock (&provider_lock);
if (priv->p_legacy_dialog_provider == obj)
{
priv->p_legacy_dialog_provider = NULL;
ret = VLC_SUCCESS;
}
vlc_mutex_unlock (&provider_lock);
return ret;
}
static vlc_object_t *dialog_GetProvider (vlc_object_t *obj)
{
libvlc_priv_t *priv = libvlc_priv (obj->p_libvlc);
vlc_object_t *provider;
vlc_mutex_lock (&provider_lock);
if ((provider = priv->p_legacy_dialog_provider) != NULL)
vlc_object_hold (provider);
vlc_mutex_unlock (&provider_lock);
return provider;
}
/**
* Sends an error message through the user interface (if any).
* @param obj the VLC object emitting the error
* @param modal whether to wait for user to acknowledge the error
* before returning control to the caller
* @param title title of the error dialog
* @param fmt format string for the error message
* @param ap parameters list for the formatted error message
*/
void dialog_VFatal (vlc_object_t *obj, bool modal, const char *title,
const char *fmt, va_list ap)
{
char *text;
if (obj->i_flags & OBJECT_FLAGS_NOINTERACT)
return;
vlc_object_t *provider = dialog_GetProvider (obj);
if (provider == NULL)
{
msg_Err (obj, "%s", title);
msg_GenericVa (obj, VLC_MSG_ERR, fmt, ap);
return;
}
if (vasprintf (&text, fmt, ap) != -1)
{
dialog_fatal_t dialog = { title, text, };
var_SetAddress (provider,
modal ? "dialog-critical" : "dialog-error", &dialog);
free (text);
}
vlc_object_release (provider);
}
#undef dialog_vaLogin
void dialog_vaLogin (vlc_object_t *obj, const char *default_username,
char **username, char **password, bool *store,
const char *title, const char *fmt, va_list ap)
{
assert ((username != NULL) && (password != NULL));
*username = *password = NULL;
if (obj->i_flags & OBJECT_FLAGS_NOINTERACT)
return;
vlc_object_t *provider = dialog_GetProvider (obj);
if (provider == NULL)
return;
char *text;
if (vasprintf (&text, fmt, ap) != -1)
{
dialog_login_t dialog = { title, text, default_username, username,
password, store };
var_SetAddress (provider, "dialog-login", &dialog);
free (text);
}
vlc_object_release (provider);
}
#undef dialog_Login
/**
* Requests a username and password through the user interface.
* @param obj the VLC object requesting credential information
* @param username a pointer to the specified username [OUT]
* @param password a pointer to the specified password [OUT]
* @param title title for the dialog
* @param fmt format string for the message in the dialog
* @return Nothing. If a user name resp. a password was specified,
* it will be returned as a heap-allocated character array
* into the username resp password pointer. Those must be freed with free().
* Otherwise *username resp *password will be NULL.
*/
void dialog_Login (vlc_object_t *obj, const char *default_username,
char **username, char **password,
bool *store, const char *title, const char *fmt, ...)
{
va_list ap;
va_start (ap, fmt);
dialog_vaLogin (obj, default_username, username, password, store,
title, fmt, ap);
va_end (ap);
}
#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 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 *fmt,
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;
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;
free (text);
}
va_end (ap);
vlc_object_release (provider);
return 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);
}
#undef dialog_ExtensionUpdate
int dialog_ExtensionUpdate (vlc_object_t *obj, extension_dialog_t *dialog)
{
assert (obj);
assert (dialog);
vlc_object_t *dp = dialog_GetProvider(obj);
if (!dp)
{
msg_Warn (obj, "Dialog provider is not set, can't update dialog '%s'",
dialog->psz_title);
return VLC_EGENERIC;
}
// Signaling the dialog provider
int ret = var_SetAddress (dp, "dialog-extension", dialog);
vlc_object_release (dp);
return ret;
}
struct vlc_dialog_provider
{
vlc_mutex_t lock;
......
......@@ -101,7 +101,6 @@ libvlc_int_t * libvlc_InternalCreate( void )
priv = libvlc_priv (p_libvlc);
priv->playlist = NULL;
priv->p_legacy_dialog_provider = NULL;
priv->p_vlm = NULL;
vlc_ExitInit( &priv->exit );
......
......@@ -150,7 +150,6 @@ typedef struct libvlc_priv_t
/* Singleton objects */
vlc_logger_t *logger;
vlm_t *p_vlm; ///< the VLM singleton (or NULL)
vlc_object_t *p_legacy_dialog_provider; ///< dialog provider
vlc_dialog_provider *p_dialog_provider; ///< dialog provider
struct playlist_t *playlist; ///< Playlist for interfaces
struct playlist_preparser_t *parser; ///< Input item meta data handler
......
......@@ -94,17 +94,6 @@ demux_PacketizerNew
demux_New
demux_vaControl
demux_vaControlHelper
dialog_ExtensionUpdate
dialog_Login
dialog_vaLogin
dialog_ProgressCancelled
dialog_ProgressCreate
dialog_ProgressDestroy
dialog_ProgressSet
dialog_Question
dialog_Register
dialog_Unregister
dialog_VFatal
EndMD5
es_format_Clean
es_format_Copy
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment