]> git.sesse.net Git - vlc/blob - src/interface/interaction.c
* minor core cleanup and WX compilation fix
[vlc] / src / interface / interaction.c
1 /*****************************************************************************
2  * interaction.c: User interaction functions
3  *****************************************************************************
4  * Copyright (C) 2005-2006 VideoLAN
5  * $Id$
6  *
7  * Authors: Clément Stenac <zorglub@videolan.org>
8  *          Felix Kühne <fkuehne@videolan.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 /**
26  *   \file
27  *   This file contains functions related to user interaction management
28  */
29
30 /*****************************************************************************
31  * Preamble
32  *****************************************************************************/
33 #include <stdlib.h>                                      /* free(), strtol() */
34 #include <stdio.h>                                                   /* FILE */
35 #include <string.h>                                            /* strerror() */
36
37 #include <vlc/vlc.h>
38 #include <vlc/input.h>
39
40 #include "vlc_interaction.h"
41 #include "vlc_interface.h"
42 #include "vlc_playlist.h"
43
44 /*****************************************************************************
45  * Local prototypes
46  *****************************************************************************/
47 static void                  intf_InteractionInit( playlist_t *p_playlist );
48 static interaction_t *       intf_InteractionGet( vlc_object_t *p_this );
49 static void                  intf_InteractionSearchInterface( interaction_t *
50                                                           p_interaction );
51 static int                   intf_WaitAnswer( interaction_t *p_interact,
52                              interaction_dialog_t *p_dialog );
53 static int                   intf_Send( interaction_t *p_interact,
54                              interaction_dialog_t *p_dialog );
55 static interaction_dialog_t *intf_InteractionGetById( vlc_object_t* , int );
56 static void                  intf_InteractionDialogDestroy(
57                                               interaction_dialog_t *p_dialog );
58
59 /**
60  * Send an interaction element to the user
61  *
62  * \param p_this the calling vlc_object_t
63  * \param p_interact the interaction element
64  * \return VLC_SUCCESS or an error code
65  */
66 int  __intf_Interact( vlc_object_t *p_this, interaction_dialog_t *p_dialog )
67 {
68     interaction_t *p_interaction = intf_InteractionGet( p_this );
69
70     /* Get an id, if we don't already have one */
71     if( p_dialog->i_id == 0 )
72     {
73         p_dialog->i_id = ++p_interaction->i_last_id;
74     }
75
76     if( p_this->i_flags & OBJECT_FLAGS_NOINTERACT ) return VLC_EGENERIC;
77
78     if( !config_GetInt(p_this, "interact") ) return VLC_EGENERIC;
79
80     p_dialog->p_interaction = p_interaction;
81     p_dialog->p_parent = p_this;
82
83     if( p_dialog->i_type == INTERACT_DIALOG_TWOWAY )
84     {
85         return intf_WaitAnswer( p_interaction, p_dialog );
86     }
87     else
88     {
89         p_dialog->i_flags |=  DIALOG_GOT_ANSWER;
90         return intf_Send( p_interaction, p_dialog );
91     }
92 }
93
94 /**
95  * Destroy the interaction system
96  * \param The interaction object to destroy
97  * \return nothing
98  */
99 void intf_InteractionDestroy( interaction_t *p_interaction )
100 {
101     int i;
102
103     // Remove all dialogs - Interfaces must be able to clean up their data
104
105     for( i = p_interaction->i_dialogs -1 ; i >= 0; i-- )
106     {
107         interaction_dialog_t * p_dialog = p_interaction->pp_dialogs[i];
108         intf_InteractionDialogDestroy( p_dialog );
109         REMOVE_ELEM( p_interaction->pp_dialogs, p_interaction->i_dialogs, i );
110     }
111
112     vlc_object_destroy( p_interaction );
113 }
114
115 /**
116  * The main interaction processing loop
117  * This function is called from the playlist loop
118  *
119  * \param p_playlist the parent playlist
120  * \return nothing
121  */
122 void intf_InteractionManage( playlist_t *p_playlist )
123 {
124     vlc_value_t val;
125     int i_index;
126     interaction_t *p_interaction;
127
128     p_interaction = p_playlist->p_interaction;
129
130     // Nothing to do
131     if( p_interaction->i_dialogs == 0 ) return;
132
133     vlc_mutex_lock( &p_interaction->object_lock );
134
135     intf_InteractionSearchInterface( p_interaction );
136
137     if( !p_interaction->p_intf )
138     {
139         // We mark all dialogs as answered with their "default" answer
140         for( i_index = 0 ; i_index < p_interaction->i_dialogs; i_index ++ )
141         {
142             interaction_dialog_t *p_dialog = p_interaction->pp_dialogs[i_index];
143
144             // Give default answer
145             p_dialog->i_return = DIALOG_DEFAULT;
146
147             // Pretend we have hidden and destroyed it
148             if( p_dialog->i_status == HIDDEN_DIALOG )
149             {
150                 p_dialog->i_status = DESTROYED_DIALOG;
151             }
152             else
153             {
154                 p_dialog->i_status = HIDING_DIALOG;
155             }
156         }
157     }
158     else
159     {
160         vlc_object_yield( p_interaction->p_intf );
161     }
162
163     for( i_index = 0 ; i_index < p_interaction->i_dialogs; i_index ++ )
164     {
165         interaction_dialog_t *p_dialog = p_interaction->pp_dialogs[i_index];
166         switch( p_dialog->i_status )
167         {
168         case ANSWERED_DIALOG:
169             // Ask interface to hide it
170             p_dialog->i_action = INTERACT_HIDE;
171             val.p_address = p_dialog;
172             if( p_interaction->p_intf )
173                 var_Set( p_interaction->p_intf, "interaction", val );
174             p_dialog->i_status = HIDING_DIALOG;
175             break;
176         case UPDATED_DIALOG:
177             p_dialog->i_action = INTERACT_UPDATE;
178             val.p_address = p_dialog;
179             if( p_interaction->p_intf )
180                 var_Set( p_interaction->p_intf, "interaction", val );
181             p_dialog->i_status = SENT_DIALOG;
182             break;
183         case HIDDEN_DIALOG:
184             if( !(p_dialog->i_flags & DIALOG_GOT_ANSWER) ) break;
185             if( !(p_dialog->i_flags & DIALOG_REUSABLE) )
186             {
187                 p_dialog->i_action = INTERACT_DESTROY;
188                 val.p_address = p_dialog;
189                 if( p_interaction->p_intf )
190                     var_Set( p_interaction->p_intf, "interaction", val );
191             }
192             break;
193         case DESTROYED_DIALOG:
194             // Interface has now destroyed it, remove it
195             REMOVE_ELEM( p_interaction->pp_dialogs, p_interaction->i_dialogs,
196                          i_index);
197             i_index--;
198             intf_InteractionDialogDestroy( p_dialog );
199             break;
200         case NEW_DIALOG:
201             // This is truly a new dialog, send it.
202             p_dialog->i_action = INTERACT_NEW;
203             val.p_address = p_dialog;
204             if( p_interaction->p_intf )
205                 var_Set( p_interaction->p_intf, "interaction", val );
206             p_dialog->i_status = SENT_DIALOG;
207             break;
208         }
209     }
210
211     if( p_interaction->p_intf )
212     {
213         vlc_object_release( p_interaction->p_intf );
214     }
215
216     vlc_mutex_unlock( &p_playlist->p_interaction->object_lock );
217 }
218
219
220 #define INTERACT_INIT( new )                                            \
221         new = (interaction_dialog_t*)malloc(                            \
222                         sizeof( interaction_dialog_t ) );               \
223         new->psz_title = NULL;                                          \
224         new->psz_description = NULL;                                    \
225         new->psz_defaultButton = NULL;                                  \
226         new->psz_alternateButton = NULL;                                \
227         new->psz_otherButton = NULL;                                    \
228         new->i_timeToGo = 0;                                            \
229         new->b_cancelled = VLC_FALSE;                                   \
230         new->p_private = NULL;                                          \
231         new->i_id = 0;                                                  \
232         new->i_flags = 0;                                               \
233         new->i_status = NEW_DIALOG;
234
235 #define INTERACT_FREE( new )                                            \
236         if( new->psz_title ) free( new->psz_title );                    \
237         if( new->psz_description ) free( new->psz_description );
238
239 /** Helper function to send an error message
240  *  \param p_this     Parent vlc_object
241  *  \param i_id       A predefined ID, 0 if not applicable
242  *  \param psz_title  Title for the dialog
243  *  \param psz_format The message to display
244  *  */
245 void __intf_UserFatal( vlc_object_t *p_this,
246                        const char *psz_title,
247                        const char *psz_format, ... )
248 {
249     va_list args;
250     interaction_dialog_t *p_new = NULL;
251     int i_id = DIALOG_ERRORS;
252
253     if( i_id > 0 )
254     {
255         p_new = intf_InteractionGetById( p_this, i_id );
256     }
257     if( !p_new )
258     {
259         INTERACT_INIT( p_new );
260         if( i_id > 0 ) p_new->i_id = i_id ;
261     }
262     else
263     {
264         p_new->i_status = UPDATED_DIALOG;
265     }
266
267     p_new->i_flags |= DIALOG_REUSABLE;
268
269     p_new->i_type = INTERACT_DIALOG_ONEWAY;
270     p_new->psz_title = strdup( psz_title );
271
272     va_start( args, psz_format );
273     vasprintf( &p_new->psz_description, psz_format, args );
274     va_end( args );
275
276     p_new->i_flags |= DIALOG_CLEAR_NOSHOW;
277
278     intf_Interact( p_this, p_new );
279 }
280
281 /** Helper function to ask a yes-no-cancel question
282  *  \param p_this           Parent vlc_object
283  *  \param psz_title        Title for the dialog
284  *  \param psz_description  A description
285  *  \param psz_default      caption for the default button
286  *  \param psz_alternate    caption for the alternate button
287  *  \param psz_other        caption for the optional 3rd button (== cancel)
288  *  \return                 Clicked button code
289  */
290 int __intf_UserYesNo( vlc_object_t *p_this,
291                       const char *psz_title,
292                       const char *psz_description,
293                       const char *psz_default,
294                       const char *psz_alternate,
295                       const char *psz_other )
296 {
297     int i_ret;
298     interaction_dialog_t *p_new = NULL;
299
300     INTERACT_INIT( p_new );
301
302     p_new->i_type = INTERACT_DIALOG_TWOWAY;
303     p_new->psz_title = strdup( psz_title );
304     p_new->psz_description = strdup( psz_description );
305     p_new->i_flags = DIALOG_YES_NO_CANCEL;
306     p_new->psz_defaultButton = strdup( psz_default );
307     p_new->psz_alternateButton = strdup( psz_alternate );
308     if( psz_other )
309         p_new->psz_otherButton = strdup( psz_other );
310     else
311         p_new->psz_otherButton = NULL;
312
313     i_ret = intf_Interact( p_this, p_new );
314
315     return i_ret;
316 }
317
318 /** Helper function to create a dialogue showing a progress-bar with some info
319  *  \param p_this           Parent vlc_object
320  *  \param psz_title        Title for the dialog
321  *  \param psz_status       Current status
322  *  \param f_position       Current position (0.0->100.0)
323  *  \param i_timeToGo       Time (in sec) to go until process is finished
324  *  \return                 Dialog id, to give to UserProgressUpdate
325  */
326 int __intf_UserProgress( vlc_object_t *p_this,
327                          const char *psz_title,
328                          const char *psz_status,
329                          float f_pos,
330                          int i_time )
331 {
332     int i_ret;
333     interaction_dialog_t *p_new = NULL;
334
335     INTERACT_INIT( p_new );
336
337     p_new->i_type = INTERACT_DIALOG_ONEWAY;
338     p_new->psz_title = strdup( psz_title );
339     p_new->psz_description = strdup( psz_status );
340     p_new->val.f_float = f_pos;
341     p_new->i_timeToGo = i_time;
342
343     p_new->i_flags = DIALOG_USER_PROGRESS;
344
345     i_ret = intf_Interact( p_this, p_new );
346
347     return p_new->i_id;
348 }
349
350 /** Update a progress bar in a dialogue
351  *  \param p_this           Parent vlc_object
352  *  \param i_id             Identifier of the dialog
353  *  \param psz_status       New status
354  *  \param f_position       New position (0.0->100.0)
355  *  \param i_timeToGo       Time (in sec) to go until process is finished
356  *  \return                 nothing
357  */
358 void __intf_UserProgressUpdate( vlc_object_t *p_this, int i_id,
359                                 const char *psz_status, float f_pos, 
360                                 int i_time )
361 {
362     interaction_t *p_interaction = intf_InteractionGet( p_this );
363     interaction_dialog_t *p_dialog;
364
365     if( !p_interaction ) return;
366
367     vlc_mutex_lock( &p_interaction->object_lock );
368     p_dialog  =  intf_InteractionGetById( p_this, i_id );
369
370     if( !p_dialog )
371     {
372         vlc_mutex_unlock( &p_interaction->object_lock ) ;
373         return;
374     }
375
376     if( p_dialog->psz_description )
377         free( p_dialog->psz_description );
378     p_dialog->psz_description = strdup( psz_status );
379
380     p_dialog->val.f_float = f_pos;
381     p_dialog->i_timeToGo = i_time;
382
383     p_dialog->i_status = UPDATED_DIALOG;
384     vlc_mutex_unlock( &p_interaction->object_lock) ;
385 }
386
387 /** Helper function to communicate dialogue cancellations between the intf-module and caller
388  *  \param p_this           Parent vlc_object
389  *  \param i_id             Identifier of the dialogue
390  *  \return                 Either true or false
391  */
392 vlc_bool_t __intf_UserProgressIsCancelled( vlc_object_t *p_this, int i_id )
393 {
394     interaction_t *p_interaction = intf_InteractionGet( p_this );
395     interaction_dialog_t *p_dialog;
396
397     if( !p_interaction ) return VLC_TRUE;
398
399     vlc_mutex_lock( &p_interaction->object_lock );
400     p_dialog  =  intf_InteractionGetById( p_this, i_id );
401
402     if( !p_dialog )
403     {
404         vlc_mutex_unlock( &p_interaction->object_lock ) ;
405         return VLC_TRUE;
406     }
407
408     vlc_mutex_unlock( &p_interaction->object_lock) ;
409     return p_dialog->b_cancelled;
410 }
411
412 /** Helper function to make a login/password dialogue
413  *  \param p_this           Parent vlc_object
414  *  \param psz_title        Title for the dialog
415  *  \param psz_description  A description
416  *  \param ppsz_login       Returned login
417  *  \param ppsz_password    Returned password
418  *  \return                 Clicked button code
419  */
420 int __intf_UserLoginPassword( vlc_object_t *p_this,
421                               const char *psz_title,
422                               const char *psz_description,
423                               char **ppsz_login,
424                               char **ppsz_password )
425 {
426
427     int i_ret;
428     interaction_dialog_t *p_new = NULL;
429
430     INTERACT_INIT( p_new );
431
432     p_new->i_type = INTERACT_DIALOG_TWOWAY;
433     p_new->psz_title = strdup( psz_title );
434     p_new->psz_description = strdup( psz_description );
435
436     p_new->i_flags = DIALOG_LOGIN_PW_OK_CANCEL;
437
438     i_ret = intf_Interact( p_this, p_new );
439
440     if( i_ret != DIALOG_CANCELLED )
441     {
442         *ppsz_login = strdup( p_new->psz_returned[0] );
443         *ppsz_password = strdup( p_new->psz_returned[1] );
444     }
445     return i_ret;
446 }
447
448 /** Helper function to make a dialogue asking the user for !password string
449  *  \param p_this           Parent vlc_object
450  *  \param psz_title        Title for the dialog
451  *  \param psz_description  A description
452  *  \param ppsz_usersString Returned login
453  *  \return                 Clicked button code
454  */
455 int __intf_UserStringInput( vlc_object_t *p_this,
456                               const char *psz_title,
457                               const char *psz_description,
458                               char **ppsz_usersString )
459 {
460
461     int i_ret;
462     interaction_dialog_t *p_new = NULL;
463
464     INTERACT_INIT( p_new );
465
466     p_new->i_type = INTERACT_DIALOG_TWOWAY;
467     p_new->psz_title = strdup( psz_title );
468     p_new->psz_description = strdup( psz_description );
469
470     p_new->i_flags = DIALOG_PSZ_INPUT_OK_CANCEL;
471
472     i_ret = intf_Interact( p_this, p_new );
473
474     if( i_ret != DIALOG_CANCELLED )
475     {
476         *ppsz_usersString = strdup( p_new->psz_returned[0] );
477     }
478     return i_ret;
479 }
480
481 /** Helper function to create a progress-bar in the main interface with a
482  *  single-line description
483  *  \param p_this           Parent vlc_object
484  *  \param psz_status       Current status
485  *  \param f_position       Current position (0.0->100.0)
486  *  \return                 Dialog id, to give to IntfProgressUpdate
487  */
488 int __intf_IntfProgress( vlc_object_t *p_this,
489                          const char *psz_status,
490                          float f_pos )
491 {
492     int i_ret;
493     interaction_dialog_t *p_new = NULL;
494
495     INTERACT_INIT( p_new );
496
497     p_new->i_type = INTERACT_DIALOG_ONEWAY;
498     p_new->psz_description = strdup( psz_status );
499     p_new->val.f_float = f_pos;
500
501     p_new->i_flags = DIALOG_INTF_PROGRESS;
502
503     i_ret = intf_Interact( p_this, p_new );
504
505     return p_new->i_id;
506 }
507
508 /** Update the progress bar in the main interface
509  *  \param p_this           Parent vlc_object
510  *  \param i_id             Identifier of the dialog
511  *  \param psz_status       New status
512  *  \param f_position       New position (0.0->100.0)
513  *  \return                 nothing
514  */
515 void __intf_IntfProgressUpdate( vlc_object_t *p_this, int i_id,
516                                 const char *psz_status, float f_pos )
517 {
518     interaction_t *p_interaction = intf_InteractionGet( p_this );
519     interaction_dialog_t *p_dialog;
520
521     if( !p_interaction ) return;
522
523     vlc_mutex_lock( &p_interaction->object_lock );
524     p_dialog  =  intf_InteractionGetById( p_this, i_id );
525
526     if( !p_dialog )
527     {
528         vlc_mutex_unlock( &p_interaction->object_lock ) ;
529         return;
530     }
531
532     if( p_dialog->psz_description )
533         free( p_dialog->psz_description );
534     p_dialog->psz_description = strdup( psz_status );
535
536     p_dialog->val.f_float = f_pos;
537
538     p_dialog->i_status = UPDATED_DIALOG;
539     vlc_mutex_unlock( &p_interaction->object_lock) ;
540 }
541
542 /** Hide an interaction dialog
543  * \param p_this the parent vlc object
544  * \param i_id the id of the item to hide
545  * \return nothing
546  */
547 void __intf_UserHide( vlc_object_t *p_this, int i_id )
548 {
549     interaction_t *p_interaction = intf_InteractionGet( p_this );
550     interaction_dialog_t *p_dialog;
551
552     if( !p_interaction ) return;
553
554     vlc_mutex_lock( &p_interaction->object_lock );
555     p_dialog  =  intf_InteractionGetById( p_this, i_id );
556
557     if( !p_dialog )
558     {
559        vlc_mutex_unlock( &p_interaction->object_lock );
560        return;
561     }
562
563     p_dialog->i_status = ANSWERED_DIALOG;
564     vlc_mutex_unlock( &p_interaction->object_lock );
565 }
566
567
568
569 /**********************************************************************
570  * The following functions are local
571  **********************************************************************/
572
573 /* Get the interaction object. Create it if needed */
574 static interaction_t * intf_InteractionGet( vlc_object_t *p_this )
575 {
576     playlist_t *p_playlist;
577     interaction_t *p_interaction;
578
579     p_playlist = (playlist_t*) vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,
580                                                 FIND_ANYWHERE );
581
582     if( !p_playlist )
583     {
584         return NULL;
585     }
586
587     if( p_playlist->p_interaction == NULL )
588     {
589         intf_InteractionInit( p_playlist );
590     }
591
592     p_interaction = p_playlist->p_interaction;
593
594     vlc_object_release( p_playlist );
595
596     return p_interaction;
597 }
598
599 /* Create the interaction object in the given playlist object */
600 static void intf_InteractionInit( playlist_t *p_playlist )
601 {
602     interaction_t *p_interaction;
603
604     p_interaction = vlc_object_create( VLC_OBJECT( p_playlist ),
605                                        sizeof( interaction_t ) );
606     if( !p_interaction )
607     {
608         msg_Err( p_playlist,"out of memory" );
609         return;
610     }
611
612     p_interaction->i_dialogs = 0;
613     p_interaction->pp_dialogs = NULL;
614     p_interaction->p_intf = NULL;
615     p_interaction->i_last_id = DIALOG_LAST_PREDEFINED + 1;
616
617     vlc_mutex_init( p_interaction , &p_interaction->object_lock );
618
619     p_playlist->p_interaction  = p_interaction;
620 }
621
622 /* Look for an interface suitable for interaction */
623 static void intf_InteractionSearchInterface( interaction_t *p_interaction )
624 {
625     vlc_list_t  *p_list;
626     int          i_index;
627
628     p_interaction->p_intf = NULL;
629
630     p_list = vlc_list_find( p_interaction, VLC_OBJECT_INTF, FIND_ANYWHERE );
631     if( !p_list )
632     {
633         msg_Err( p_interaction, "unable to create module list" );
634         return;
635     }
636
637     for( i_index = 0; i_index < p_list->i_count; i_index ++ )
638     {
639         intf_thread_t *p_intf = (intf_thread_t *)
640                                         p_list->p_values[i_index].p_object;
641         if( p_intf->b_interaction )
642         {
643             p_interaction->p_intf = p_intf;
644             break;
645         }
646     }
647     vlc_list_release ( p_list );
648 }
649
650 /* Add a dialog to the queue and wait for answer */
651 static int intf_WaitAnswer( interaction_t *p_interact,
652                             interaction_dialog_t *p_dialog )
653 {
654     int i;
655     vlc_bool_t b_found = VLC_FALSE;
656     vlc_mutex_lock( &p_interact->object_lock );
657     for( i = 0 ; i< p_interact->i_dialogs; i++ )
658     {
659         if( p_interact->pp_dialogs[i]->i_id == p_dialog->i_id )
660         {
661             b_found = VLC_TRUE;
662         }
663     }
664     if( ! b_found )
665     {
666         INSERT_ELEM( p_interact->pp_dialogs,
667                      p_interact->i_dialogs,
668                      p_interact->i_dialogs,
669                      p_dialog );
670     }
671     else
672         p_dialog->i_status = UPDATED_DIALOG;
673     vlc_mutex_unlock( &p_interact->object_lock );
674
675     /// \todo Check that the initiating object is not dying
676     while( p_dialog->i_status != ANSWERED_DIALOG &&
677            p_dialog->i_status != HIDING_DIALOG &&
678            p_dialog->i_status != HIDDEN_DIALOG &&
679            !p_dialog->p_parent->b_die )
680     {
681         msleep( 100000 );
682     }
683     /// \todo locking
684     if( p_dialog->p_parent->b_die )
685     {
686         p_dialog->i_return = DIALOG_CANCELLED;
687         p_dialog->i_status = ANSWERED_DIALOG;
688     }
689     p_dialog->i_flags |= DIALOG_GOT_ANSWER;
690     return p_dialog->i_return;
691 }
692
693 /* Add a dialog to the queue and return */
694 static int intf_Send( interaction_t *p_interact,
695                       interaction_dialog_t *p_dialog )
696 {
697     int i;
698     vlc_bool_t b_found = VLC_FALSE;
699     if( p_interact == NULL ) return VLC_ENOOBJ;
700     vlc_mutex_lock( &p_interact->object_lock );
701
702     for( i = 0 ; i< p_interact->i_dialogs; i++ )
703     {
704         if( p_interact->pp_dialogs[i]->i_id == p_dialog->i_id )
705         {
706             b_found = VLC_TRUE;
707         }
708     }
709     if( !b_found )
710     {
711         INSERT_ELEM( p_interact->pp_dialogs,
712                      p_interact->i_dialogs,
713                      p_interact->i_dialogs,
714                      p_dialog );
715     }
716     else
717         p_dialog->i_status = UPDATED_DIALOG;
718     // Pretend we already retrieved the "answer"
719     p_dialog->i_flags |= DIALOG_GOT_ANSWER;
720     vlc_mutex_unlock( &p_interact->object_lock );
721     return VLC_SUCCESS;
722 }
723
724 /* Find an interaction dialog by its id */
725 static interaction_dialog_t *intf_InteractionGetById( vlc_object_t* p_this,
726                                                        int i_id )
727 {
728     interaction_t *p_interaction = intf_InteractionGet( p_this );
729     int i;
730
731     if( !p_interaction ) return NULL;
732
733     for( i = 0 ; i< p_interaction->i_dialogs; i++ )
734     {
735         if( p_interaction->pp_dialogs[i]->i_id == i_id )
736         {
737             return p_interaction->pp_dialogs[i];
738         }
739     }
740     return NULL;
741 }
742
743 #define FREE( i ) { if( i ) free( i ); i = NULL; }
744
745 static void intf_InteractionDialogDestroy( interaction_dialog_t *p_dialog )
746 {
747     FREE( p_dialog->psz_title );
748     FREE( p_dialog->psz_description );
749     FREE( p_dialog->psz_defaultButton );
750     FREE( p_dialog->psz_alternateButton );
751     FREE( p_dialog->psz_otherButton );
752
753     free( p_dialog );
754 }