Commit 093de856 authored by Clément Stenac's avatar Clément Stenac

Interaction cleanup, remove some unused functions, factorize some code, ...

parent 7eee710f
......@@ -618,10 +618,13 @@ static int64_t GCD( int64_t a, int64_t b )
if( !var ) goto error; }
#define DECMALLOC_VOID( var, type ) type* var = (type*)malloc( sizeof(type) );\
if( !var ) return;
#define DECMALLOC_ERR( var, type ) type* var = (type*)malloc( sizeof(type) );\
if( !var ) return VLC_ENOMEM;
#define DECMALLOC_NULL( var, type ) type* var = (type*)malloc( sizeof(type) );\
if( !var ) return NULL;
#define FREENULL(a) if( a ) { free( a ); a = NULL; }
#define FREE(a) if( a ) { free( a ); }
/* Dynamic array handling: realloc array, move data, increment position */
#if defined( _MSC_VER ) && _MSC_VER < 1300 && !defined( UNDER_CE )
......
......@@ -169,32 +169,24 @@ enum
* Exported symbols
***************************************************************************/
#define intf_Interact( a,b ) __intf_Interact( VLC_OBJECT(a), b )
VLC_EXPORT( int,__intf_Interact,( vlc_object_t *,interaction_dialog_t * ) );
#define intf_UserFatal( a, b, c, d, e... ) __intf_UserFatal( VLC_OBJECT(a),b,c,d, ## e )
VLC_EXPORT( void, __intf_UserFatal,( vlc_object_t*, vlc_bool_t, const char*, const char*, ...) );
VLC_EXPORT( int, __intf_UserFatal,( vlc_object_t*, vlc_bool_t, const char*, const char*, ...) );
#define intf_UserWarn( a, c, d, e... ) __intf_UserWarn( VLC_OBJECT(a),c,d, ## e )
VLC_EXPORT( void, __intf_UserWarn,( vlc_object_t*, const char*, const char*, ...) );
VLC_EXPORT( int, __intf_UserWarn,( vlc_object_t*, const char*, const char*, ...) );
#define intf_UserLoginPassword( a, b, c, d, e... ) __intf_UserLoginPassword( VLC_OBJECT(a),b,c,d,e)
VLC_EXPORT( int, __intf_UserLoginPassword,( vlc_object_t*, const char*, const char*, char **, char **) );
#define intf_UserYesNo( a, b, c, d, e, f ) __intf_UserYesNo( VLC_OBJECT(a),b,c, d, e, f )
VLC_EXPORT( int, __intf_UserYesNo,( vlc_object_t*, const char*, const char*, const char*, const char*, const char*) );
#define intf_UserProgress( a, b, c, d, e ) __intf_UserProgress( VLC_OBJECT(a),b,c,d,e )
VLC_EXPORT( int, __intf_UserProgress,( vlc_object_t*, const char*, const char*, float, int) );
#define intf_UserProgressUpdate( a, b, c, d, e ) __intf_UserProgressUpdate( VLC_OBJECT(a),b,c,d,e )
VLC_EXPORT( void, __intf_UserProgressUpdate,( vlc_object_t*, int, const char*, float, int) );
#define intf_UserProgressIsCancelled( a, b ) __intf_UserProgressIsCancelled( VLC_OBJECT(a),b )
VLC_EXPORT( vlc_bool_t, __intf_UserProgressIsCancelled,( vlc_object_t*, int ) );
#define intf_UserStringInput( a, b, c, d ) __intf_UserStringInput( VLC_OBJECT(a),b,c,d )
VLC_EXPORT( int, __intf_UserStringInput,(vlc_object_t*, const char*, const char*, char **) );
#define intf_IntfProgress( a, b, c ) __intf_IntfProgress( VLC_OBJECT(a),b,c )
VLC_EXPORT( int, __intf_IntfProgress,( vlc_object_t*, const char*, float) );
#define intf_IntfProgressUpdate( a, b, c, d ) __intf_IntfProgressUpdate( VLC_OBJECT(a),b,c,d )
VLC_EXPORT( void, __intf_IntfProgressUpdate,( vlc_object_t*, int, const char*, float) );
#define intf_IntfProgress( a, b, c ) __intf_Progress( VLC_OBJECT(a), NULL, b,c, -1 )
#define intf_UserProgress( a, b, c, d, e ) __intf_Progress( VLC_OBJECT(a),b,c,d,e )
VLC_EXPORT( int, __intf_Progress,( vlc_object_t*, const char*, const char*, float, int) );
#define intf_ProgressUpdate( a, b, c, d, e ) __intf_ProgressUpdate( VLC_OBJECT(a),b,c,d,e )
VLC_EXPORT( void, __intf_ProgressUpdate,( vlc_object_t*, int, const char*, float, int) );
#define intf_ProgressIsCancelled( a, b ) __intf_UserProgressIsCancelled( VLC_OBJECT(a),b )
VLC_EXPORT( vlc_bool_t, __intf_UserProgressIsCancelled,( vlc_object_t*, int ) );
#define intf_UserHide( a, b ) __intf_UserHide( VLC_OBJECT(a), b )
VLC_EXPORT( void, __intf_UserHide,( vlc_object_t *, int ));
......
......@@ -429,14 +429,14 @@ struct module_symbols_t
char * (*FromUTF32_inner) (const uint32_t *);
int (*__input_Read_inner) (vlc_object_t *, input_item_t *, vlc_bool_t);
int (*__net_ConnectUDP_inner) (vlc_object_t *p_this, const char *psz_host, int i_port, int hlim);
int (*__intf_Interact_inner) (vlc_object_t *,interaction_dialog_t *);
void *__intf_Interact_deprecated;
void (*intf_InteractionManage_inner) (playlist_t *);
void (*intf_InteractionDestroy_inner) (interaction_t *);
void (*__intf_UserFatal_inner) (vlc_object_t*, vlc_bool_t, const char*, const char*, ...);
int (*__intf_UserFatal_inner) (vlc_object_t*, vlc_bool_t, const char*, const char*, ...);
int (*__intf_UserLoginPassword_inner) (vlc_object_t*, const char*, const char*, char **, char **);
int (*__intf_UserYesNo_inner) (vlc_object_t*, const char*, const char*, const char*, const char*, const char*);
int (*__intf_UserProgress_inner) (vlc_object_t*, const char*, const char*, float, int);
void (*__intf_UserProgressUpdate_inner) (vlc_object_t*, int, const char*, float, int);
void *__intf_UserProgress_deprecated;
void *__intf_UserProgressUpdate_deprecated;
void (*__intf_UserHide_inner) (vlc_object_t *, int);
void *__stats_Create_deprecated;
int (*__stats_Update_inner) (vlc_object_t*, counter_t *, vlc_value_t, vlc_value_t *);
......@@ -517,11 +517,13 @@ struct module_symbols_t
void *stats_TimerClean_deprecated;
void *stats_TimersClean_deprecated;
void (*__stats_TimersClean_inner) (vlc_object_t *);
void (*__intf_IntfProgressUpdate_inner) (vlc_object_t*, int, const char*, float);
int (*__intf_IntfProgress_inner) (vlc_object_t*, const char*, float);
void *__intf_IntfProgressUpdate_deprecated;
void *__intf_IntfProgress_deprecated;
void *streaming_ChainToPsz_deprecated;
void (*__intf_UserWarn_inner) (vlc_object_t*, const char*, const char*, ...);
int (*__intf_UserWarn_inner) (vlc_object_t*, const char*, const char*, ...);
vlc_bool_t (*__intf_UserProgressIsCancelled_inner) (vlc_object_t*, int);
int (*__intf_Progress_inner) (vlc_object_t*, const char*, const char*, float, int);
void (*__intf_ProgressUpdate_inner) (vlc_object_t*, int, const char*, float, int);
};
# if defined (__PLUGIN__)
# define aout_FiltersCreatePipeline (p_symbols)->aout_FiltersCreatePipeline_inner
......@@ -908,14 +910,11 @@ struct module_symbols_t
# define FromUTF32 (p_symbols)->FromUTF32_inner
# define __input_Read (p_symbols)->__input_Read_inner
# define __net_ConnectUDP (p_symbols)->__net_ConnectUDP_inner
# define __intf_Interact (p_symbols)->__intf_Interact_inner
# define intf_InteractionManage (p_symbols)->intf_InteractionManage_inner
# define intf_InteractionDestroy (p_symbols)->intf_InteractionDestroy_inner
# define __intf_UserFatal (p_symbols)->__intf_UserFatal_inner
# define __intf_UserLoginPassword (p_symbols)->__intf_UserLoginPassword_inner
# define __intf_UserYesNo (p_symbols)->__intf_UserYesNo_inner
# define __intf_UserProgress (p_symbols)->__intf_UserProgress_inner
# define __intf_UserProgressUpdate (p_symbols)->__intf_UserProgressUpdate_inner
# define __intf_UserHide (p_symbols)->__intf_UserHide_inner
# define __stats_Update (p_symbols)->__stats_Update_inner
# define __stats_Get (p_symbols)->__stats_Get_inner
......@@ -988,10 +987,10 @@ struct module_symbols_t
# define input_AddSubtitles (p_symbols)->input_AddSubtitles_inner
# define __stats_CounterCreate (p_symbols)->__stats_CounterCreate_inner
# define __stats_TimersClean (p_symbols)->__stats_TimersClean_inner
# define __intf_IntfProgressUpdate (p_symbols)->__intf_IntfProgressUpdate_inner
# define __intf_IntfProgress (p_symbols)->__intf_IntfProgress_inner
# define __intf_UserWarn (p_symbols)->__intf_UserWarn_inner
# define __intf_UserProgressIsCancelled (p_symbols)->__intf_UserProgressIsCancelled_inner
# define __intf_Progress (p_symbols)->__intf_Progress_inner
# define __intf_ProgressUpdate (p_symbols)->__intf_ProgressUpdate_inner
# elif defined (HAVE_DYNAMIC_PLUGINS) && !defined (__BUILTIN__)
/******************************************************************
* STORE_SYMBOLS: store VLC APIs into p_symbols for plugin access.
......@@ -1381,14 +1380,11 @@ struct module_symbols_t
((p_symbols)->FromUTF32_inner) = FromUTF32; \
((p_symbols)->__input_Read_inner) = __input_Read; \
((p_symbols)->__net_ConnectUDP_inner) = __net_ConnectUDP; \
((p_symbols)->__intf_Interact_inner) = __intf_Interact; \
((p_symbols)->intf_InteractionManage_inner) = intf_InteractionManage; \
((p_symbols)->intf_InteractionDestroy_inner) = intf_InteractionDestroy; \
((p_symbols)->__intf_UserFatal_inner) = __intf_UserFatal; \
((p_symbols)->__intf_UserLoginPassword_inner) = __intf_UserLoginPassword; \
((p_symbols)->__intf_UserYesNo_inner) = __intf_UserYesNo; \
((p_symbols)->__intf_UserProgress_inner) = __intf_UserProgress; \
((p_symbols)->__intf_UserProgressUpdate_inner) = __intf_UserProgressUpdate; \
((p_symbols)->__intf_UserHide_inner) = __intf_UserHide; \
((p_symbols)->__stats_Update_inner) = __stats_Update; \
((p_symbols)->__stats_Get_inner) = __stats_Get; \
......@@ -1461,10 +1457,10 @@ struct module_symbols_t
((p_symbols)->input_AddSubtitles_inner) = input_AddSubtitles; \
((p_symbols)->__stats_CounterCreate_inner) = __stats_CounterCreate; \
((p_symbols)->__stats_TimersClean_inner) = __stats_TimersClean; \
((p_symbols)->__intf_IntfProgressUpdate_inner) = __intf_IntfProgressUpdate; \
((p_symbols)->__intf_IntfProgress_inner) = __intf_IntfProgress; \
((p_symbols)->__intf_UserWarn_inner) = __intf_UserWarn; \
((p_symbols)->__intf_UserProgressIsCancelled_inner) = __intf_UserProgressIsCancelled; \
((p_symbols)->__intf_Progress_inner) = __intf_Progress; \
((p_symbols)->__intf_ProgressUpdate_inner) = __intf_ProgressUpdate; \
(p_symbols)->net_ConvertIPv4_deprecated = NULL; \
(p_symbols)->__playlist_ItemCopy_deprecated = NULL; \
(p_symbols)->playlist_ItemAddParent_deprecated = NULL; \
......@@ -1491,6 +1487,9 @@ struct module_symbols_t
(p_symbols)->playlist_Sort_deprecated = NULL; \
(p_symbols)->playlist_Move_deprecated = NULL; \
(p_symbols)->playlist_NodeRemoveParent_deprecated = NULL; \
(p_symbols)->__intf_Interact_deprecated = NULL; \
(p_symbols)->__intf_UserProgress_deprecated = NULL; \
(p_symbols)->__intf_UserProgressUpdate_deprecated = NULL; \
(p_symbols)->__stats_Create_deprecated = NULL; \
(p_symbols)->__stats_CounterGet_deprecated = NULL; \
(p_symbols)->stats_HandlerDestroy_deprecated = NULL; \
......@@ -1499,6 +1498,8 @@ struct module_symbols_t
(p_symbols)->__intf_UserOkayCancel_deprecated = NULL; \
(p_symbols)->stats_TimerClean_deprecated = NULL; \
(p_symbols)->stats_TimersClean_deprecated = NULL; \
(p_symbols)->__intf_IntfProgressUpdate_deprecated = NULL; \
(p_symbols)->__intf_IntfProgress_deprecated = NULL; \
(p_symbols)->streaming_ChainToPsz_deprecated = NULL; \
# endif /* __PLUGIN__ */
......
......@@ -2298,8 +2298,8 @@ static void AVI_IndexCreate( demux_t *p_demux )
stream_Size( p_demux->s );
float f_pos = (float)i_pos;
p_demux->p_sys->last_update = mdate();
intf_IntfProgressUpdate( p_demux, p_demux->p_sys->i_dialog_id,
_( "Fixing AVI Index..." ), f_pos );
intf_ProgressUpdate( p_demux, p_demux->p_sys->i_dialog_id,
_( "Fixing AVI Index..." ), f_pos, -1 );
}
if( AVI_PacketGetHeader( p_demux, &pk ) )
......
......@@ -196,7 +196,8 @@ static void Run( services_discovery_t *p_sd )
int i_id = input_Read( p_sd, p_sys->p_input, VLC_FALSE );
int i_dialog_id;
i_dialog_id = intf_UserProgress( p_sd, "Shoutcast" , "Connecting...", 0.0, 0 );
i_dialog_id = intf_UserProgress( p_sd, "Shoutcast" ,
_("Connecting...") , 0.0, 0 );
p_sys->b_dialog = VLC_TRUE;
while( !p_sd->b_die )
......@@ -214,7 +215,7 @@ static void Run( services_discovery_t *p_sd )
{
float f_pos = (float)(p_sys->p_node_cat->i_children)* 2 *100.0 /
260 /* gruiiik FIXME */;
intf_UserProgressUpdate( p_sd, i_dialog_id, "Downloading",
intf_ProgressUpdate( p_sd, i_dialog_id, "Downloading",
f_pos, 0 );
}
vlc_object_release( p_input );
......
......@@ -36,6 +36,7 @@
#include <vlc/vlc.h>
#include <vlc/input.h>
#include <assert.h>
#include "vlc_interaction.h"
#include "vlc_interface.h"
......@@ -44,57 +45,13 @@
/*****************************************************************************
* Local prototypes
*****************************************************************************/
static void intf_InteractionInit( playlist_t *p_playlist );
static interaction_t * intf_InteractionGet( vlc_object_t *p_this );
static void intf_InteractionSearchInterface( interaction_t *
static void InteractionInit( playlist_t *p_playlist );
static interaction_t * InteractionGet( vlc_object_t *p_this );
static void InteractionSearchInterface( interaction_t *
p_interaction );
static int intf_WaitAnswer( interaction_t *p_interact,
interaction_dialog_t *p_dialog );
static int intf_Send( interaction_t *p_interact,
interaction_dialog_t *p_dialog );
static interaction_dialog_t *intf_InteractionGetById( vlc_object_t* , int );
static void intf_InteractionDialogDestroy(
interaction_dialog_t *p_dialog );
/**
* Send an interaction element to the user
*
* \param p_this the calling vlc_object_t
* \param p_interact the interaction element
* \return VLC_SUCCESS or an error code
*/
int __intf_Interact( vlc_object_t *p_this, interaction_dialog_t *p_dialog )
{
interaction_t *p_interaction = intf_InteractionGet( p_this );
/* Get an id, if we don't already have one */
if( p_dialog->i_id == 0 )
{
p_dialog->i_id = ++p_interaction->i_last_id;
}
if( p_this->i_flags & OBJECT_FLAGS_NOINTERACT ) return VLC_EGENERIC;
if( config_GetInt(p_this, "interact") ||
p_dialog->i_flags & DIALOG_BLOCKING_ERROR ||
p_dialog->i_flags & DIALOG_NONBLOCKING_ERROR )
{
p_dialog->p_interaction = p_interaction;
p_dialog->p_parent = p_this;
if( p_dialog->i_type == INTERACT_DIALOG_TWOWAY )
{
return intf_WaitAnswer( p_interaction, p_dialog );
}
else
{
p_dialog->i_flags |= DIALOG_GOT_ANSWER;
return intf_Send( p_interaction, p_dialog );
}
}
else
return VLC_EGENERIC;
}
static interaction_dialog_t *DialogGetById( interaction_t* , int );
static void DialogDestroy( interaction_dialog_t *p_dialog );
static int DialogSend( vlc_object_t *p_this, interaction_dialog_t *p_dialog );
/**
* Destroy the interaction system
......@@ -104,16 +61,13 @@ int __intf_Interact( vlc_object_t *p_this, interaction_dialog_t *p_dialog )
void intf_InteractionDestroy( interaction_t *p_interaction )
{
int i;
// Remove all dialogs - Interfaces must be able to clean up their data
for( i = p_interaction->i_dialogs -1 ; i >= 0; i-- )
{
interaction_dialog_t * p_dialog = p_interaction->pp_dialogs[i];
intf_InteractionDialogDestroy( p_dialog );
DialogDestroy( p_dialog );
REMOVE_ELEM( p_interaction->pp_dialogs, p_interaction->i_dialogs, i );
}
vlc_object_destroy( p_interaction );
}
......@@ -128,26 +82,21 @@ void intf_InteractionManage( playlist_t *p_playlist )
{
vlc_value_t val;
int i_index;
interaction_t *p_interaction;
p_interaction = p_playlist->p_interaction;
interaction_t *p_interaction = p_playlist->p_interaction;
// Nothing to do
if( p_interaction->i_dialogs == 0 ) return;
vlc_mutex_lock( &p_interaction->object_lock );
intf_InteractionSearchInterface( p_interaction );
InteractionSearchInterface( p_interaction );
if( !p_interaction->p_intf )
{
// We mark all dialogs as answered with their "default" answer
for( i_index = 0 ; i_index < p_interaction->i_dialogs; i_index ++ )
{
interaction_dialog_t *p_dialog = p_interaction->pp_dialogs[i_index];
// Give default answer
p_dialog->i_return = DIALOG_DEFAULT;
p_dialog->i_return = DIALOG_DEFAULT; // Give default answer
// Pretend we have hidden and destroyed it
if( p_dialog->i_status == HIDDEN_DIALOG )
......@@ -200,7 +149,7 @@ void intf_InteractionManage( playlist_t *p_playlist )
REMOVE_ELEM( p_interaction->pp_dialogs, p_interaction->i_dialogs,
i_index);
i_index--;
intf_InteractionDialogDestroy( p_dialog );
DialogDestroy( p_dialog );
break;
case NEW_DIALOG:
// This is truly a new dialog, send it.
......@@ -221,55 +170,42 @@ void intf_InteractionManage( playlist_t *p_playlist )
vlc_mutex_unlock( &p_playlist->p_interaction->object_lock );
}
#define DIALOG_INIT( type ) \
DECMALLOC_ERR( p_new, interaction_dialog_t ); \
memset( p_new, 0, sizeof( interaction_dialog_t ) ); \
p_new->b_cancelled = VLC_FALSE; \
p_new->i_status = NEW_DIALOG; \
p_new->i_type = INTERACT_DIALOG_##type; \
p_new->psz_returned[0] = NULL; \
p_new->psz_returned[1] = NULL;
#define FORMAT_DESC \
va_start( args, psz_format ); \
vasprintf( &p_new->psz_description, psz_format, args ); \
va_end( args );
#define INTERACT_INIT( new ) \
new = (interaction_dialog_t*)malloc( \
sizeof( interaction_dialog_t ) ); \
new->psz_title = NULL; \
new->psz_description = NULL; \
new->psz_default_button = NULL; \
new->psz_alternate_button = NULL; \
new->psz_other_button = NULL; \
new->i_timeToGo = 0; \
new->b_cancelled = VLC_FALSE; \
new->p_private = NULL; \
new->i_id = 0; \
new->i_flags = 0; \
new->i_status = NEW_DIALOG;
#define INTERACT_FREE( new ) \
if( new->psz_title ) free( new->psz_title ); \
if( new->psz_description ) free( new->psz_description );
/** Helper function to send an error message, both in a blocking and non-blocking way
/** Send an error message, both in a blocking and non-blocking way
* \param p_this Parent vlc_object
* \param b_blocking Is this dialog blocking or not?
* \param psz_title Title for the dialog
* \param psz_format The message to display
* */
void __intf_UserFatal( vlc_object_t *p_this,
vlc_bool_t b_blocking,
int __intf_UserFatal( vlc_object_t *p_this, vlc_bool_t b_blocking,
const char *psz_title,
const char *psz_format, ... )
{
va_list args;
interaction_dialog_t *p_new = NULL;
INTERACT_INIT( p_new );
DIALOG_INIT( ONEWAY );
p_new->psz_title = strdup( psz_title );
p_new->i_type = INTERACT_DIALOG_ONEWAY;
va_start( args, psz_format );
vasprintf( &p_new->psz_description, psz_format, args );
va_end( args );
FORMAT_DESC;
if( b_blocking )
p_new->i_flags = DIALOG_BLOCKING_ERROR;
else
p_new->i_flags = DIALOG_NONBLOCKING_ERROR;
intf_Interact( p_this, p_new );
return DialogSend( p_this, p_new );
}
/** Helper function to send an warning, which is always shown non-blocking
......@@ -277,25 +213,19 @@ void __intf_UserFatal( vlc_object_t *p_this,
* \param psz_title Title for the dialog
* \param psz_format The message to display
* */
void __intf_UserWarn( vlc_object_t *p_this,
int __intf_UserWarn( vlc_object_t *p_this,
const char *psz_title,
const char *psz_format, ... )
{
va_list args;
interaction_dialog_t *p_new = NULL;
INTERACT_INIT( p_new );
DIALOG_INIT( ONEWAY );
p_new->psz_title = strdup( psz_title );
p_new->i_type = INTERACT_DIALOG_ONEWAY;
va_start( args, psz_format );
vasprintf( &p_new->psz_description, psz_format, args );
va_end( args );
FORMAT_DESC
p_new->i_flags = DIALOG_WARNING;
intf_Interact( p_this, p_new );
return DialogSend( p_this, p_new );
}
/** Helper function to ask a yes-no-cancel question
......@@ -314,12 +244,8 @@ int __intf_UserYesNo( vlc_object_t *p_this,
const char *psz_alternate,
const char *psz_other )
{
int i_ret;
interaction_dialog_t *p_new = NULL;
INTERACT_INIT( p_new );
DIALOG_INIT( TWOWAY );
p_new->i_type = INTERACT_DIALOG_TWOWAY;
p_new->psz_title = strdup( psz_title );
p_new->psz_description = strdup( psz_description );
p_new->i_flags = DIALOG_YES_NO_CANCEL;
......@@ -327,43 +253,35 @@ int __intf_UserYesNo( vlc_object_t *p_this,
p_new->psz_alternate_button = strdup( psz_alternate );
if( psz_other )
p_new->psz_other_button = strdup( psz_other );
else
p_new->psz_other_button = NULL;
i_ret = intf_Interact( p_this, p_new );
return i_ret;
return DialogSend( p_this, p_new );
}
/** Helper function to create a dialogue showing a progress-bar with some info
* \param p_this Parent vlc_object
* \param psz_title Title for the dialog
* \param psz_title Title for the dialog (NULL implies main intf )
* \param psz_status Current status
* \param f_position Current position (0.0->100.0)
* \param i_timeToGo Time (in sec) to go until process is finished
* \return Dialog id, to give to UserProgressUpdate
*/
int __intf_UserProgress( vlc_object_t *p_this,
const char *psz_title,
const char *psz_status,
float f_pos,
int i_time )
int __intf_Progress( vlc_object_t *p_this, const char *psz_title,
const char *psz_status, float f_pos, int i_time )
{
int i_ret;
interaction_dialog_t *p_new = NULL;
INTERACT_INIT( p_new );
p_new->i_type = INTERACT_DIALOG_ONEWAY;
p_new->psz_title = strdup( psz_title );
DIALOG_INIT( ONEWAY );
p_new->psz_description = strdup( psz_status );
p_new->val.f_float = f_pos;
p_new->i_timeToGo = i_time;
if( psz_title )
{
p_new->psz_title = strdup( psz_title );
p_new->i_flags = DIALOG_USER_PROGRESS;
}
else
p_new->i_flags = DIALOG_INTF_PROGRESS;
i_ret = intf_Interact( p_this, p_new );
DialogSend( p_this, p_new );
return p_new->i_id;
}
......@@ -375,17 +293,16 @@ int __intf_UserProgress( vlc_object_t *p_this,
* \param i_timeToGo Time (in sec) to go until process is finished
* \return nothing
*/
void __intf_UserProgressUpdate( vlc_object_t *p_this, int i_id,
const char *psz_status, float f_pos,
int i_time )
void __intf_ProgressUpdate( vlc_object_t *p_this, int i_id,
const char *psz_status, float f_pos, int i_time )
{
interaction_t *p_interaction = intf_InteractionGet( p_this );
interaction_t *p_interaction = InteractionGet( p_this );
interaction_dialog_t *p_dialog;
if( !p_interaction ) return;
vlc_mutex_lock( &p_interaction->object_lock );
p_dialog = intf_InteractionGetById( p_this, i_id );
p_dialog = DialogGetById( p_interaction, i_id );
if( !p_dialog )
{
......@@ -393,8 +310,7 @@ void __intf_UserProgressUpdate( vlc_object_t *p_this, int i_id,
return;
}
if( p_dialog->psz_description )
free( p_dialog->psz_description );
FREE( p_dialog->psz_description );
p_dialog->psz_description = strdup( psz_status );
p_dialog->val.f_float = f_pos;
......@@ -404,29 +320,31 @@ void __intf_UserProgressUpdate( vlc_object_t *p_this, int i_id,
vlc_mutex_unlock( &p_interaction->object_lock) ;
}
/** Helper function to communicate dialogue cancellations between the intf-module and caller
/** Helper function to communicate dialogue cancellations between the
* interface module and the caller
* \param p_this Parent vlc_object
* \param i_id Identifier of the dialogue
* \return Either true or false
*/
vlc_bool_t __intf_UserProgressIsCancelled( vlc_object_t *p_this, int i_id )
{
interaction_t *p_interaction = intf_InteractionGet( p_this );
interaction_t *p_interaction = InteractionGet( p_this );
interaction_dialog_t *p_dialog;
vlc_bool_t b_cancel;
if( !p_interaction ) return VLC_TRUE;
vlc_mutex_lock( &p_interaction->object_lock );
p_dialog = intf_InteractionGetById( p_this, i_id );
p_dialog = DialogGetById( p_interaction, i_id );
if( !p_dialog )
{
vlc_mutex_unlock( &p_interaction->object_lock ) ;
return VLC_TRUE;
}
vlc_mutex_unlock( &p_interaction->object_lock) ;
return p_dialog->b_cancelled;
b_cancel = p_dialog->b_cancelled;
vlc_mutex_unlock( &p_interaction->object_lock );
return b_cancel;
}
/** Helper function to make a login/password dialogue
......@@ -443,22 +361,19 @@ int __intf_UserLoginPassword( vlc_object_t *p_this,
char **ppsz_login,
char **ppsz_password )
{
int i_ret;
interaction_dialog_t *p_new = NULL;
INTERACT_INIT( p_new );
DIALOG_INIT( TWOWAY );
p_new->i_type = INTERACT_DIALOG_TWOWAY;
p_new->psz_title = strdup( psz_title );
p_new->psz_description = strdup( psz_description );
p_new->i_flags = DIALOG_LOGIN_PW_OK_CANCEL;
i_ret = intf_Interact( p_this, p_new );
i_ret = DialogSend( p_this, p_new );
if( i_ret != DIALOG_CANCELLED )
{
assert( p_new->psz_returned[0] && p_new->psz_returned[1] );
*ppsz_login = strdup( p_new->psz_returned[0] );
*ppsz_password = strdup( p_new->psz_returned[1] );
}
......@@ -477,88 +392,23 @@ int __intf_UserStringInput( vlc_object_t *p_this,
const char *psz_description,
char **ppsz_usersString )
{
int i_ret;
interaction_dialog_t *p_new = NULL;
INTERACT_INIT( p_new );
p_new->i_type = INTERACT_DIALOG_TWOWAY;
DIALOG_INIT( TWOWAY );
p_new->psz_title = strdup( psz_title );
p_new->psz_description = strdup( psz_description );
p_new->i_flags = DIALOG_PSZ_INPUT_OK_CANCEL;
i_ret = intf_Interact( p_this, p_new );
i_ret = DialogSend( p_this, p_new );
if( i_ret != DIALOG_CANCELLED )
{
assert( p_new->psz_returned[0] );
*ppsz_usersString = strdup( p_new->psz_returned[0] );
}
return i_ret;
}
/** Helper function to create a progress-bar in the main interface with a
* single-line description
* \param p_this Parent vlc_object
* \param psz_status Current status
* \param f_position Current position (0.0->100.0)
* \return Dialog id, to give to IntfProgressUpdate
*/
int __intf_IntfProgress( vlc_object_t *p_this,
const char *psz_status,
float f_pos )
{
int i_ret;
interaction_dialog_t *p_new = NULL;
INTERACT_INIT( p_new );
p_new->i_type = INTERACT_DIALOG_ONEWAY;
p_new->psz_description = strdup( psz_status );
p_new->val.f_float = f_pos;
p_new->i_flags = DIALOG_INTF_PROGRESS;
i_ret = intf_Interact( p_this, p_new );
return p_new->i_id;
}
/** Update the progress bar in the main interface
* \param p_this Parent vlc_object
* \param i_id Identifier of the dialog
* \param psz_status New status
* \param f_position New position (0.0->100.0)
* \return nothing
*/
void __intf_IntfProgressUpdate( vlc_object_t *p_this, int i_id,
const char *psz_status, float f_pos )
{
interaction_t *p_interaction = intf_InteractionGet( p_this );
interaction_dialog_t *p_dialog;
if( !p_interaction ) return;
vlc_mutex_lock( &p_interaction->object_lock );
p_dialog = intf_InteractionGetById( p_this, i_id );
if( !p_dialog )
{
vlc_mutex_unlock( &p_interaction->object_lock ) ;
return;
}
if( p_dialog->psz_description )
free( p_dialog->psz_description );
p_dialog->psz_description = strdup( psz_status );
p_dialog->val.f_float = f_pos;
p_dialog->i_status = UPDATED_DIALOG;
vlc_mutex_unlock( &p_interaction->object_lock) ;
}
/** Hide an interaction dialog
* \param p_this the parent vlc object
* \param i_id the id of the item to hide
......@@ -566,13 +416,13 @@ void __intf_IntfProgressUpdate( vlc_object_t *p_this, int i_id,
*/
void __intf_UserHide( vlc_object_t *p_this, int i_id )
{
interaction_t *p_interaction = intf_InteractionGet( p_this );
interaction_t *p_interaction = InteractionGet( p_this );
interaction_dialog_t *p_dialog;
if( !p_interaction ) return;
vlc_mutex_lock( &p_interaction->object_lock );
p_dialog = intf_InteractionGetById( p_this, i_id );
p_dialog = DialogGetById( p_interaction, i_id );
if( !p_dialog )
{
......@@ -584,44 +434,34 @@ void __intf_UserHide( vlc_object_t *p_this, int i_id )
vlc_mutex_unlock( &p_interaction->object_lock );
}
/**********************************************************************
* The following functions are local
**********************************************************************/
/* Get the interaction object. Create it if needed */
static interaction_t * intf_InteractionGet( vlc_object_t *p_this )
static interaction_t * InteractionGet( vlc_object_t *p_this )
{
playlist_t *p_playlist;
interaction_t *p_interaction;
p_playlist = (playlist_t*) vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,
FIND_ANYWHERE );
if( !p_playlist )
{
return NULL;
}
if( p_playlist->p_interaction == NULL )
{
intf_InteractionInit( p_playlist );
}
InteractionInit( p_playlist );
p_interaction = p_playlist->p_interaction;
vlc_object_release( p_playlist );
return p_interaction;
}
/* Create the interaction object in the given playlist object */
static void intf_InteractionInit( playlist_t *p_playlist )
static void InteractionInit( playlist_t *p_playlist )
{
interaction_t *p_interaction;
p_interaction = vlc_object_create( VLC_OBJECT( p_playlist ),
interaction_t *p_interaction = vlc_object_create( VLC_OBJECT( p_playlist ),
sizeof( interaction_t ) );
if( !p_interaction )
{
......@@ -640,7 +480,7 @@ static void intf_InteractionInit( playlist_t *p_playlist )
}
/* Look for an interface suitable for interaction */
static void intf_InteractionSearchInterface( interaction_t *p_interaction )
static void InteractionSearchInterface( interaction_t *p_interaction )
{
vlc_list_t *p_list;
int i_index;
......@@ -667,32 +507,73 @@ static void intf_InteractionSearchInterface( interaction_t *p_interaction )
vlc_list_release ( p_list );
}
/* Add a dialog to the queue and wait for answer */
static int intf_WaitAnswer( interaction_t *p_interact,
interaction_dialog_t *p_dialog )
/* Find an interaction dialog by its id */
static interaction_dialog_t *DialogGetById( interaction_t *p_interaction,
int i_id )
{
int i;
vlc_bool_t b_found = VLC_FALSE;
vlc_mutex_lock( &p_interact->object_lock );
for( i = 0 ; i< p_interact->i_dialogs; i++ )
for( i = 0 ; i< p_interaction->i_dialogs; i++ )
{
if( p_interaction->pp_dialogs[i]->i_id == i_id )
return p_interaction->pp_dialogs[i];
}
return NULL;
}
/* Destroy a dialog */
static void DialogDestroy( interaction_dialog_t *p_dialog )
{
FREENULL( p_dialog->psz_title );
FREENULL( p_dialog->psz_description );
FREENULL( p_dialog->psz_default_button );
FREENULL( p_dialog->psz_alternate_button );
FREENULL( p_dialog->psz_other_button );
free( p_dialog );
}
/* Ask for the dialog to be sent to the user. Wait for answer
* if required */
static int DialogSend( vlc_object_t *p_this, interaction_dialog_t *p_dialog )
{
interaction_t *p_interaction = InteractionGet( p_this );
/* Get an id, if we don't already have one */
if( p_dialog->i_id == 0 )
p_dialog->i_id = ++p_interaction->i_last_id;
if( p_this->i_flags & OBJECT_FLAGS_NOINTERACT ) return VLC_EGENERIC;
if( config_GetInt(p_this, "interact") ||
p_dialog->i_flags & DIALOG_BLOCKING_ERROR ||
p_dialog->i_flags & DIALOG_NONBLOCKING_ERROR )
{
if( p_interact->pp_dialogs[i]->i_id == p_dialog->i_id )
vlc_bool_t b_found = VLC_FALSE;
int i;
p_dialog->p_interaction = p_interaction;
p_dialog->p_parent = p_this;
/* Check if we have already added this dialog */
vlc_mutex_lock( &p_interaction->object_lock );
for( i = 0 ; i< p_interaction->i_dialogs; i++ )
{
if( p_interaction->pp_dialogs[i]->i_id == p_dialog->i_id )
b_found = VLC_TRUE;
}
}
/* Add it to the queue, the main loop will send the orders to the
* interface */
if( ! b_found )
{
INSERT_ELEM( p_interact->pp_dialogs,
p_interact->i_dialogs,
p_interact->i_dialogs,
INSERT_ELEM( p_interaction->pp_dialogs,
p_interaction->i_dialogs,
p_interaction->i_dialogs,
p_dialog );
}
else
p_dialog->i_status = UPDATED_DIALOG;
vlc_mutex_unlock( &p_interact->object_lock );
vlc_mutex_unlock( &p_interaction->object_lock );
/// \todo Check that the initiating object is not dying
if( p_dialog->i_type == INTERACT_DIALOG_TWOWAY ) // Wait for answer
{
while( p_dialog->i_status != ANSWERED_DIALOG &&
p_dialog->i_status != HIDING_DIALOG &&
p_dialog->i_status != HIDDEN_DIALOG &&
......@@ -700,7 +581,7 @@ static int intf_WaitAnswer( interaction_t *p_interact,
{
msleep( 100000 );
}
/// \todo locking
/// \todo locking ?
if( p_dialog->p_parent->b_die )
{
p_dialog->i_return = DIALOG_CANCELLED;
......@@ -708,67 +589,15 @@ static int intf_WaitAnswer( interaction_t *p_interact,
}
p_dialog->i_flags |= DIALOG_GOT_ANSWER;
return p_dialog->i_return;
}
/* Add a dialog to the queue and return */
static int intf_Send( interaction_t *p_interact,
interaction_dialog_t *p_dialog )
{
int i;
vlc_bool_t b_found = VLC_FALSE;
if( p_interact == NULL ) return VLC_ENOOBJ;
vlc_mutex_lock( &p_interact->object_lock );
for( i = 0 ; i< p_interact->i_dialogs; i++ )
{
if( p_interact->pp_dialogs[i]->i_id == p_dialog->i_id )
{
b_found = VLC_TRUE;
}
}
if( !b_found )
{
INSERT_ELEM( p_interact->pp_dialogs,
p_interact->i_dialogs,
p_interact->i_dialogs,
p_dialog );
}
else
p_dialog->i_status = UPDATED_DIALOG;
{
// Pretend we already retrieved the "answer"
p_dialog->i_flags |= DIALOG_GOT_ANSWER;
vlc_mutex_unlock( &p_interact->object_lock );
vlc_mutex_unlock( &p_interaction->object_lock );
return VLC_SUCCESS;
}
/* Find an interaction dialog by its id */
static interaction_dialog_t *intf_InteractionGetById( vlc_object_t* p_this,
int i_id )
{
interaction_t *p_interaction = intf_InteractionGet( p_this );
int i;
if( !p_interaction ) return NULL;
for( i = 0 ; i< p_interaction->i_dialogs; i++ )
{
if( p_interaction->pp_dialogs[i]->i_id == i_id )
{
return p_interaction->pp_dialogs[i];
}
}
return NULL;
}
#define FREE( i ) { if( i ) free( i ); i = NULL; }
static void intf_InteractionDialogDestroy( interaction_dialog_t *p_dialog )
{
FREE( p_dialog->psz_title );
FREE( p_dialog->psz_description );
FREE( p_dialog->psz_default_button );
FREE( p_dialog->psz_alternate_button );
FREE( p_dialog->psz_other_button );
free( p_dialog );
else
return VLC_EGENERIC;
}
......@@ -78,7 +78,6 @@
#define UPDATE_VLC_STATUS_URL "http://update.videolan.org/vlc/status.xml"
#define UPDATE_VLC_MIRRORS_URL "http://update.videolan.org/mirrors.xml"
#define FREE( a ) free(a);a=NULL;
#define STRDUP( a ) ( a ? strdup( a ) : NULL )
/*****************************************************************************
......@@ -167,7 +166,7 @@ void FreeMirrorsList( update_t *p_update )
free( p_update->p_mirrors[i].psz_type );
free( p_update->p_mirrors[i].psz_base_url );
}
FREE( p_update->p_mirrors );
FREENULL( p_update->p_mirrors );
p_update->i_mirrors = 0;
p_update->b_mirrors = VLC_FALSE;
}
......@@ -200,7 +199,7 @@ void FreeReleasesList( update_t *p_update )
free( p_release->psz_svn_revision );
free( p_release->p_files );
}
FREE( p_update->p_releases );
FREENULL( p_update->p_releases );
p_update->i_releases = 0;
p_update->b_releases = VLC_FALSE;
}
......@@ -308,8 +307,8 @@ void GetMirrorsList( update_t *p_update, vlc_bool_t b_force )
else if( !strcmp( psz_name, "base" ) )
tmp_mirror.psz_base_url = STRDUP( psz_value );
}
FREE( psz_name );
FREE( psz_value );
FREENULL( psz_name );
FREENULL( psz_value );
}
if( !strcmp( psz_eltname, "url" ) )
{
......@@ -325,7 +324,7 @@ void GetMirrorsList( update_t *p_update, vlc_bool_t b_force )
tmp_mirror.psz_type = NULL;
tmp_mirror.psz_base_url = NULL;
}
FREE( psz_eltname );
FREENULL( psz_eltname );
break;
case XML_READER_ENDELEM:
......@@ -339,16 +338,16 @@ void GetMirrorsList( update_t *p_update, vlc_bool_t b_force )
if( !strcmp( psz_eltname, "mirror" ) )
{
FREE( tmp_mirror.psz_name );
FREE( tmp_mirror.psz_location );
FREENULL( tmp_mirror.psz_name );
FREENULL( tmp_mirror.psz_location );
}
FREE( psz_eltname );
FREENULL( psz_eltname );
break;
/*case XML_READER_TEXT:
psz_eltvalue = xml_ReaderValue( p_xml_reader );
FREE( psz_eltvalue );
FREENULL( psz_eltvalue );
break;*/
}
}
......@@ -536,8 +535,8 @@ void GetFilesList( update_t *p_update, vlc_bool_t b_force )
{
b_arch = VLC_TRUE;
}
FREE( psz_name );
FREE( psz_value );
FREENULL( psz_name );
FREENULL( psz_value );
}
if( ( b_os && b_arch && strcmp( psz_eltname, "arch" ) ) )
{
......@@ -579,13 +578,13 @@ void GetFilesList( update_t *p_update, vlc_bool_t b_force )
}
else
{
FREE( tmp_release.psz_major );
FREE( tmp_release.psz_minor );
FREE( tmp_release.psz_revision );
FREE( tmp_release.psz_extra );
FREE( tmp_release.psz_svn_revision );
FREENULL( tmp_release.psz_major );
FREENULL( tmp_release.psz_minor );
FREENULL( tmp_release.psz_revision );
FREENULL( tmp_release.psz_extra );
FREENULL( tmp_release.psz_svn_revision );
tmp_release.i_type = UPDATE_RELEASE_TYPE_STABLE;
FREE( tmp_release.p_files );
FREENULL( tmp_release.p_files );
tmp_release.i_files = 0;
}
}
......@@ -607,7 +606,7 @@ void GetFilesList( update_t *p_update, vlc_bool_t b_force )
tmp_file.psz_description = NULL;
}
}
FREE( psz_eltname );
FREENULL( psz_eltname );
break;
case XML_READER_ENDELEM:
......@@ -623,7 +622,7 @@ void GetFilesList( update_t *p_update, vlc_bool_t b_force )
b_os = VLC_FALSE;
else if( !strcmp( psz_eltname, "arch" ) )
b_arch = VLC_FALSE;
FREE( psz_eltname );
FREENULL( psz_eltname );
break;
case XML_READER_TEXT:
......@@ -631,7 +630,7 @@ void GetFilesList( update_t *p_update, vlc_bool_t b_force )
if( p_release && p_release->i_files )
p_release->p_files[ p_release->i_files - 1 ]
.psz_description = STRDUP( psz_eltvalue );
FREE( psz_eltvalue );
FREENULL( psz_eltvalue );
break;
}
}
......@@ -1115,17 +1114,17 @@ void update_iterator_GetData( update_iterator_t *p_uit )
void update_iterator_ClearData( update_iterator_t *p_uit )
{
p_uit->file.i_type = UPDATE_FILE_TYPE_NONE;
FREE( p_uit->file.psz_md5 );
FREENULL( p_uit->file.psz_md5 );
p_uit->file.l_size = 0;
FREE( p_uit->file.psz_description );
FREE( p_uit->file.psz_url );
FREE( p_uit->release.psz_version );
FREE( p_uit->release.psz_svn_revision );
FREENULL( p_uit->file.psz_description );
FREENULL( p_uit->file.psz_url );
FREENULL( p_uit->release.psz_version );
FREENULL( p_uit->release.psz_svn_revision );
p_uit->release.i_type = UPDATE_RELEASE_TYPE_UNSTABLE;
p_uit->release.i_status = UPDATE_RELEASE_STATUS_NONE;
FREE( p_uit->mirror.psz_name );
FREE( p_uit->mirror.psz_location );
FREE( p_uit->mirror.psz_type );
FREENULL( p_uit->mirror.psz_name );
FREENULL( p_uit->mirror.psz_location );
FREENULL( p_uit->mirror.psz_type );
}
/**
......@@ -1308,7 +1307,7 @@ void update_download_for_real( download_thread_t *p_this )
p_this->psz_status, psz_s1, psz_s2, f_progress );
free( psz_s1 ); free( psz_s2 );
intf_UserProgressUpdate( p_vlc, i_progress,
intf_ProgressUpdate( p_vlc, i_progress,
psz_status, f_progress, 0 );
}
......@@ -1321,7 +1320,7 @@ void update_download_for_real( download_thread_t *p_this )
asprintf( &psz_status, "%s\nDone %s (100.00%%)",
p_this->psz_status, psz_s2 );
free( psz_s2 );
intf_UserProgressUpdate( p_vlc, i_progress, psz_status, 100.0, 0 );
intf_ProgressUpdate( p_vlc, i_progress, psz_status, 100.0, 0 );
free( psz_status );
}
}
......
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