Commit 3fbfb3d4 authored by Clément Stenac's avatar Clément Stenac

Handle removal

Improve non-handling by interfaces without interaction
parent 59a8d434
...@@ -549,7 +549,6 @@ void DialogsProvider::OnInteraction( wxCommandEvent& event ) ...@@ -549,7 +549,6 @@ void DialogsProvider::OnInteraction( wxCommandEvent& event )
} }
p_dialog = p_arg->p_dialog; p_dialog = p_arg->p_dialog;
/** \bug We store the interface object for the dialog in the p_private /** \bug We store the interface object for the dialog in the p_private
* field of the core dialog object. This is not safe if we change * field of the core dialog object. This is not safe if we change
* interface while a dialog is loaded */ * interface while a dialog is loaded */
...@@ -568,6 +567,12 @@ void DialogsProvider::OnInteraction( wxCommandEvent& event ) ...@@ -568,6 +567,12 @@ void DialogsProvider::OnInteraction( wxCommandEvent& event )
case INTERACT_HIDE: case INTERACT_HIDE:
p_wxdialog = (InteractionDialog*)(p_dialog->p_private); p_wxdialog = (InteractionDialog*)(p_dialog->p_private);
p_wxdialog->Hide(); p_wxdialog->Hide();
p_dialog->i_status = HIDDEN_DIALOG;
break;
case INTERACT_DESTROY:
p_wxdialog = (InteractionDialog*)(p_dialog->p_private);
/// \todo
p_dialog->i_status = DESTROYED_DIALOG;
break; break;
} }
} }
...@@ -118,6 +118,7 @@ void InteractionDialog::Render() ...@@ -118,6 +118,7 @@ void InteractionDialog::Render()
InputWidget widget; InputWidget widget;
widget.control = input; widget.control = input;
widget.val = &p_widget->val; widget.val = &p_widget->val;
widget.i_type = WIDGET_INPUT_TEXT;
input_widgets.push_back( widget ); input_widgets.push_back( widget );
} }
} }
...@@ -167,6 +168,7 @@ void InteractionDialog::Finish( int i_ret ) ...@@ -167,6 +168,7 @@ void InteractionDialog::Finish( int i_ret )
vector<InputWidget>::iterator it = input_widgets.begin(); vector<InputWidget>::iterator it = input_widgets.begin();
while ( it < input_widgets.end() ) while ( it < input_widgets.end() )
{ {
if( (*it).i_type == WIDGET_INPUT_TEXT )
(*it).val->psz_string = strdup( (*it).control->GetValue().mb_str() ); (*it).val->psz_string = strdup( (*it).control->GetValue().mb_str() );
it++; it++;
} }
......
...@@ -38,6 +38,7 @@ namespace wxvlc ...@@ -38,6 +38,7 @@ namespace wxvlc
/// \todo Clean up /// \todo Clean up
wxTextCtrl *control; wxTextCtrl *control;
vlc_value_t *val; vlc_value_t *val;
int i_type;
}; };
class InteractionDialog: public wxFrame class InteractionDialog: public wxFrame
......
...@@ -1217,13 +1217,6 @@ static int InteractCallback( vlc_object_t *p_this, ...@@ -1217,13 +1217,6 @@ static int InteractCallback( vlc_object_t *p_this,
Interface *p_interface = (Interface*)param; Interface *p_interface = (Interface*)param;
interaction_dialog_t *p_dialog = (interaction_dialog_t*)(new_val.p_address); interaction_dialog_t *p_dialog = (interaction_dialog_t*)(new_val.p_address);
/// Not handled
if( p_dialog->i_action == INTERACT_HIDE )
{
p_dialog->i_status = HIDDEN_DIALOG;
return 0;
}
wxCommandEvent event( wxEVT_INTERACTION, -1 ); wxCommandEvent event( wxEVT_INTERACTION, -1 );
event.SetClientData( new_val.p_address ); event.SetClientData( new_val.p_address );
p_interface->AddPendingEvent( event ); p_interface->AddPendingEvent( event );
......
...@@ -52,6 +52,8 @@ static int intf_WaitAnswer( interaction_t *p_interact, ...@@ -52,6 +52,8 @@ static int intf_WaitAnswer( interaction_t *p_interact,
static int intf_Send( interaction_t *p_interact, static int intf_Send( interaction_t *p_interact,
interaction_dialog_t *p_dialog ); interaction_dialog_t *p_dialog );
static interaction_dialog_t *intf_InteractionGetById( vlc_object_t* , int ); 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 * Send an interaction element to the user
...@@ -90,7 +92,18 @@ int __intf_Interact( vlc_object_t *p_this, interaction_dialog_t * ...@@ -90,7 +92,18 @@ int __intf_Interact( vlc_object_t *p_this, interaction_dialog_t *
*/ */
void intf_InteractionDestroy( interaction_t *p_interaction ) void intf_InteractionDestroy( interaction_t *p_interaction )
{ {
/// \todo Code this, and call it 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 );
REMOVE_ELEM( p_interaction->pp_dialogs, p_interaction->i_dialogs, i );
}
vlc_object_destroy( p_interaction );
} }
/** /**
...@@ -121,12 +134,23 @@ void intf_InteractionManage( playlist_t *p_playlist ) ...@@ -121,12 +134,23 @@ void intf_InteractionManage( playlist_t *p_playlist )
for( i_index = 0 ; i_index < p_interaction->i_dialogs; i_index ++ ) for( i_index = 0 ; i_index < p_interaction->i_dialogs; i_index ++ )
{ {
interaction_dialog_t *p_dialog = p_interaction->pp_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;
if( p_dialog->i_flags & DIALOG_OK_CANCEL ) if( p_dialog->i_flags & DIALOG_OK_CANCEL )
p_dialog->i_return = DIALOG_CANCELLED; p_dialog->i_return = DIALOG_CANCELLED;
if( p_dialog->i_flags & DIALOG_YES_NO_CANCEL ) if( p_dialog->i_flags & DIALOG_YES_NO_CANCEL )
p_dialog->i_return = DIALOG_CANCELLED; p_dialog->i_return = DIALOG_CANCELLED;
p_dialog->i_status = ANSWERED_DIALOG;
// Pretend we have hidden and destroyed it
if( p_dialog->i_status == HIDDEN_DIALOG )
{
p_dialog->i_status = DESTROYED_DIALOG;
}
else
{
p_dialog->i_status = HIDING_DIALOG;
}
} }
} }
else else
...@@ -170,10 +194,14 @@ void intf_InteractionManage( playlist_t *p_playlist ) ...@@ -170,10 +194,14 @@ void intf_InteractionManage( playlist_t *p_playlist )
} }
break; break;
case DESTROYED_DIALOG: case DESTROYED_DIALOG:
msg_Dbg( p_interaction, "Removing dialog %i",
p_dialog->i_id );
// Interface has now destroyed it, remove it // Interface has now destroyed it, remove it
/// \todo Remove it from the list REMOVE_ELEM( p_interaction->pp_dialogs, p_interaction->i_dialogs,
/// \todo Free data fields i_index);
free( p_dialog ); i_index--;
intf_InteractionDialogDestroy( p_dialog );
break;
case NEW_DIALOG: case NEW_DIALOG:
// This is truly a new dialog, send it. // This is truly a new dialog, send it.
p_dialog->i_action = INTERACT_NEW; p_dialog->i_action = INTERACT_NEW;
...@@ -203,6 +231,7 @@ void intf_InteractionManage( playlist_t *p_playlist ) ...@@ -203,6 +231,7 @@ void intf_InteractionManage( playlist_t *p_playlist )
new->psz_title = NULL; \ new->psz_title = NULL; \
new->psz_description = NULL; \ new->psz_description = NULL; \
new->i_id = 0; \ new->i_id = 0; \
new->i_flags = 0; \
new->i_status = NEW_DIALOG; new->i_status = NEW_DIALOG;
#define INTERACT_FREE( new ) \ #define INTERACT_FREE( new ) \
...@@ -246,6 +275,7 @@ void __intf_UserFatal( vlc_object_t *p_this, ...@@ -246,6 +275,7 @@ void __intf_UserFatal( vlc_object_t *p_this,
p_widget = (user_widget_t* )malloc( sizeof( user_widget_t ) ); p_widget = (user_widget_t* )malloc( sizeof( user_widget_t ) );
p_widget->i_type = WIDGET_TEXT; p_widget->i_type = WIDGET_TEXT;
p_widget->val.psz_string = NULL;
va_start( args, psz_format ); va_start( args, psz_format );
vasprintf( &p_widget->psz_text, psz_format, args ); vasprintf( &p_widget->psz_text, psz_format, args );
...@@ -286,6 +316,7 @@ int __intf_UserLoginPassword( vlc_object_t *p_this, ...@@ -286,6 +316,7 @@ int __intf_UserLoginPassword( vlc_object_t *p_this,
p_widget = (user_widget_t* )malloc( sizeof( user_widget_t ) ); p_widget = (user_widget_t* )malloc( sizeof( user_widget_t ) );
p_widget->i_type = WIDGET_TEXT; p_widget->i_type = WIDGET_TEXT;
p_widget->psz_text = strdup( psz_description ); p_widget->psz_text = strdup( psz_description );
p_widget->val.psz_string = NULL;
INSERT_ELEM ( p_new->pp_widgets, p_new->i_widgets, INSERT_ELEM ( p_new->pp_widgets, p_new->i_widgets,
p_new->i_widgets, p_widget ); p_new->i_widgets, p_widget );
...@@ -309,7 +340,7 @@ int __intf_UserLoginPassword( vlc_object_t *p_this, ...@@ -309,7 +340,7 @@ int __intf_UserLoginPassword( vlc_object_t *p_this,
i_ret = intf_Interact( p_this, p_new ); i_ret = intf_Interact( p_this, p_new );
if( i_ret == DIALOG_OK_YES ) if( i_ret != DIALOG_CANCELLED )
{ {
*ppsz_login = strdup( p_new->pp_widgets[1]->val.psz_string ); *ppsz_login = strdup( p_new->pp_widgets[1]->val.psz_string );
*ppsz_password = strdup( p_new->pp_widgets[2]->val.psz_string ); *ppsz_password = strdup( p_new->pp_widgets[2]->val.psz_string );
...@@ -427,6 +458,7 @@ static int intf_WaitAnswer( interaction_t *p_interact, interaction_dialog_t *p_d ...@@ -427,6 +458,7 @@ static int intf_WaitAnswer( interaction_t *p_interact, interaction_dialog_t *p_d
/// \todo Check that the initiating object is not dying /// \todo Check that the initiating object is not dying
while( p_dialog->i_status != ANSWERED_DIALOG && while( p_dialog->i_status != ANSWERED_DIALOG &&
p_dialog->i_status != HIDING_DIALOG && p_dialog->i_status != HIDING_DIALOG &&
p_dialog->i_status != HIDDEN_DIALOG &&
!p_dialog->p_parent->b_die ) !p_dialog->p_parent->b_die )
{ {
msleep( 100000 ); msleep( 100000 );
...@@ -464,6 +496,8 @@ static int intf_Send( interaction_t *p_interact, interaction_dialog_t *p_dialog ...@@ -464,6 +496,8 @@ static int intf_Send( interaction_t *p_interact, interaction_dialog_t *p_dialog
} }
else else
p_dialog->i_status = UPDATED_DIALOG; 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_interact->object_lock );
return VLC_SUCCESS; return VLC_SUCCESS;
} }
...@@ -486,3 +520,23 @@ static interaction_dialog_t *intf_InteractionGetById( vlc_object_t* p_this, ...@@ -486,3 +520,23 @@ static interaction_dialog_t *intf_InteractionGetById( vlc_object_t* p_this,
} }
return NULL; return NULL;
} }
#define FREE( i ) { if( i ) free( i ); i = NULL; }
static void intf_InteractionDialogDestroy( interaction_dialog_t *p_dialog )
{
int i;
for( i = p_dialog->i_widgets - 1 ; i >= 0 ; i-- )
{
user_widget_t *p_widget = p_dialog->pp_widgets[i];
FREE( p_widget->psz_text );
FREE( p_widget->val.psz_string );
REMOVE_ELEM( p_dialog->pp_widgets, p_dialog->i_widgets, i );
free( p_widget );
}
FREE( p_dialog->psz_title );
FREE( p_dialog->psz_description );
free( p_dialog );
}
...@@ -237,6 +237,11 @@ int playlist_Destroy( playlist_t * p_playlist ) ...@@ -237,6 +237,11 @@ int playlist_Destroy( playlist_t * p_playlist )
p_playlist->pp_sds[0]->psz_module ); p_playlist->pp_sds[0]->psz_module );
} }
if( p_playlist->p_interaction )
{
intf_InteractionDestroy( p_playlist->p_interaction );
}
vlc_thread_join( p_playlist->p_preparse ); vlc_thread_join( p_playlist->p_preparse );
vlc_thread_join( p_playlist ); vlc_thread_join( p_playlist );
......
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