]> git.sesse.net Git - vlc/blob - src/interface/interaction.c
* additional interaction enhancements
[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, both in a blocking and non-blocking way
240  *  \param p_this     Parent vlc_object
241  *  \param b_blocking Is this dialog blocking or not?
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                        vlc_bool_t b_blocking,
247                        const char *psz_title,
248                        const char *psz_format, ... )
249 {
250     va_list args;
251     interaction_dialog_t *p_new = NULL;
252     
253     INTERACT_INIT( p_new );
254     
255     p_new->psz_title = strdup( psz_title );
256
257     va_start( args, psz_format );
258     vasprintf( &p_new->psz_description, psz_format, args );
259     va_end( args );
260
261     if( b_blocking )
262         p_new->i_flags = DIALOG_BLOCKING_ERROR;
263     else
264         p_new->i_flags = DIALOG_NONBLOCKING_ERROR;
265
266     intf_Interact( p_this, p_new );
267 }
268
269 /** Helper function to send an warning, which is always shown non-blocking
270  *  \param p_this     Parent vlc_object
271  *  \param psz_title  Title for the dialog
272  *  \param psz_format The message to display
273  *  */
274 void __intf_UserWarn( vlc_object_t *p_this,
275                        const char *psz_title,
276                        const char *psz_format, ... )
277 {
278     va_list args;
279     interaction_dialog_t *p_new = NULL;
280     
281     INTERACT_INIT( p_new );
282     
283     p_new->psz_title = strdup( psz_title );
284
285     va_start( args, psz_format );
286     vasprintf( &p_new->psz_description, psz_format, args );
287     va_end( args );
288
289     p_new->i_flags = DIALOG_WARNING;
290
291     intf_Interact( p_this, p_new );
292 }
293
294 /** Helper function to ask a yes-no-cancel question
295  *  \param p_this           Parent vlc_object
296  *  \param psz_title        Title for the dialog
297  *  \param psz_description  A description
298  *  \param psz_default      caption for the default button
299  *  \param psz_alternate    caption for the alternate button
300  *  \param psz_other        caption for the optional 3rd button (== cancel)
301  *  \return                 Clicked button code
302  */
303 int __intf_UserYesNo( vlc_object_t *p_this,
304                       const char *psz_title,
305                       const char *psz_description,
306                       const char *psz_default,
307                       const char *psz_alternate,
308                       const char *psz_other )
309 {
310     int i_ret;
311     interaction_dialog_t *p_new = NULL;
312
313     INTERACT_INIT( p_new );
314
315     p_new->i_type = INTERACT_DIALOG_TWOWAY;
316     p_new->psz_title = strdup( psz_title );
317     p_new->psz_description = strdup( psz_description );
318     p_new->i_flags = DIALOG_YES_NO_CANCEL;
319     p_new->psz_defaultButton = strdup( psz_default );
320     p_new->psz_alternateButton = strdup( psz_alternate );
321     if( psz_other )
322         p_new->psz_otherButton = strdup( psz_other );
323     else
324         p_new->psz_otherButton = NULL;
325
326     i_ret = intf_Interact( p_this, p_new );
327
328     return i_ret;
329 }
330
331 /** Helper function to create a dialogue showing a progress-bar with some info
332  *  \param p_this           Parent vlc_object
333  *  \param psz_title        Title for the dialog
334  *  \param psz_status       Current status
335  *  \param f_position       Current position (0.0->100.0)
336  *  \param i_timeToGo       Time (in sec) to go until process is finished
337  *  \return                 Dialog id, to give to UserProgressUpdate
338  */
339 int __intf_UserProgress( vlc_object_t *p_this,
340                          const char *psz_title,
341                          const char *psz_status,
342                          float f_pos,
343                          int i_time )
344 {
345     int i_ret;
346     interaction_dialog_t *p_new = NULL;
347
348     INTERACT_INIT( p_new );
349
350     p_new->i_type = INTERACT_DIALOG_ONEWAY;
351     p_new->psz_title = strdup( psz_title );
352     p_new->psz_description = strdup( psz_status );
353     p_new->val.f_float = f_pos;
354     p_new->i_timeToGo = i_time;
355
356     p_new->i_flags = DIALOG_USER_PROGRESS;
357
358     i_ret = intf_Interact( p_this, p_new );
359
360     return p_new->i_id;
361 }
362
363 /** Update a progress bar in a dialogue
364  *  \param p_this           Parent vlc_object
365  *  \param i_id             Identifier of the dialog
366  *  \param psz_status       New status
367  *  \param f_position       New position (0.0->100.0)
368  *  \param i_timeToGo       Time (in sec) to go until process is finished
369  *  \return                 nothing
370  */
371 void __intf_UserProgressUpdate( vlc_object_t *p_this, int i_id,
372                                 const char *psz_status, float f_pos, 
373                                 int i_time )
374 {
375     interaction_t *p_interaction = intf_InteractionGet( p_this );
376     interaction_dialog_t *p_dialog;
377
378     if( !p_interaction ) return;
379
380     vlc_mutex_lock( &p_interaction->object_lock );
381     p_dialog  =  intf_InteractionGetById( p_this, i_id );
382
383     if( !p_dialog )
384     {
385         vlc_mutex_unlock( &p_interaction->object_lock ) ;
386         return;
387     }
388
389     if( p_dialog->psz_description )
390         free( p_dialog->psz_description );
391     p_dialog->psz_description = strdup( psz_status );
392
393     p_dialog->val.f_float = f_pos;
394     p_dialog->i_timeToGo = i_time;
395
396     p_dialog->i_status = UPDATED_DIALOG;
397     vlc_mutex_unlock( &p_interaction->object_lock) ;
398 }
399
400 /** Helper function to communicate dialogue cancellations between the intf-module and caller
401  *  \param p_this           Parent vlc_object
402  *  \param i_id             Identifier of the dialogue
403  *  \return                 Either true or false
404  */
405 vlc_bool_t __intf_UserProgressIsCancelled( vlc_object_t *p_this, int i_id )
406 {
407     interaction_t *p_interaction = intf_InteractionGet( p_this );
408     interaction_dialog_t *p_dialog;
409
410     if( !p_interaction ) return VLC_TRUE;
411
412     vlc_mutex_lock( &p_interaction->object_lock );
413     p_dialog  =  intf_InteractionGetById( p_this, i_id );
414
415     if( !p_dialog )
416     {
417         vlc_mutex_unlock( &p_interaction->object_lock ) ;
418         return VLC_TRUE;
419     }
420
421     vlc_mutex_unlock( &p_interaction->object_lock) ;
422     return p_dialog->b_cancelled;
423 }
424
425 /** Helper function to make a login/password dialogue
426  *  \param p_this           Parent vlc_object
427  *  \param psz_title        Title for the dialog
428  *  \param psz_description  A description
429  *  \param ppsz_login       Returned login
430  *  \param ppsz_password    Returned password
431  *  \return                 Clicked button code
432  */
433 int __intf_UserLoginPassword( vlc_object_t *p_this,
434                               const char *psz_title,
435                               const char *psz_description,
436                               char **ppsz_login,
437                               char **ppsz_password )
438 {
439
440     int i_ret;
441     interaction_dialog_t *p_new = NULL;
442
443     INTERACT_INIT( p_new );
444
445     p_new->i_type = INTERACT_DIALOG_TWOWAY;
446     p_new->psz_title = strdup( psz_title );
447     p_new->psz_description = strdup( psz_description );
448
449     p_new->i_flags = DIALOG_LOGIN_PW_OK_CANCEL;
450
451     i_ret = intf_Interact( p_this, p_new );
452
453     if( i_ret != DIALOG_CANCELLED )
454     {
455         *ppsz_login = strdup( p_new->psz_returned[0] );
456         *ppsz_password = strdup( p_new->psz_returned[1] );
457     }
458     return i_ret;
459 }
460
461 /** Helper function to make a dialogue asking the user for !password string
462  *  \param p_this           Parent vlc_object
463  *  \param psz_title        Title for the dialog
464  *  \param psz_description  A description
465  *  \param ppsz_usersString Returned login
466  *  \return                 Clicked button code
467  */
468 int __intf_UserStringInput( vlc_object_t *p_this,
469                               const char *psz_title,
470                               const char *psz_description,
471                               char **ppsz_usersString )
472 {
473
474     int i_ret;
475     interaction_dialog_t *p_new = NULL;
476
477     INTERACT_INIT( p_new );
478
479     p_new->i_type = INTERACT_DIALOG_TWOWAY;
480     p_new->psz_title = strdup( psz_title );
481     p_new->psz_description = strdup( psz_description );
482
483     p_new->i_flags = DIALOG_PSZ_INPUT_OK_CANCEL;
484
485     i_ret = intf_Interact( p_this, p_new );
486
487     if( i_ret != DIALOG_CANCELLED )
488     {
489         *ppsz_usersString = strdup( p_new->psz_returned[0] );
490     }
491     return i_ret;
492 }
493
494 /** Helper function to create a progress-bar in the main interface with a
495  *  single-line description
496  *  \param p_this           Parent vlc_object
497  *  \param psz_status       Current status
498  *  \param f_position       Current position (0.0->100.0)
499  *  \return                 Dialog id, to give to IntfProgressUpdate
500  */
501 int __intf_IntfProgress( vlc_object_t *p_this,
502                          const char *psz_status,
503                          float f_pos )
504 {
505     int i_ret;
506     interaction_dialog_t *p_new = NULL;
507
508     INTERACT_INIT( p_new );
509
510     p_new->i_type = INTERACT_DIALOG_ONEWAY;
511     p_new->psz_description = strdup( psz_status );
512     p_new->val.f_float = f_pos;
513
514     p_new->i_flags = DIALOG_INTF_PROGRESS;
515
516     i_ret = intf_Interact( p_this, p_new );
517
518     return p_new->i_id;
519 }
520
521 /** Update the progress bar in the main interface
522  *  \param p_this           Parent vlc_object
523  *  \param i_id             Identifier of the dialog
524  *  \param psz_status       New status
525  *  \param f_position       New position (0.0->100.0)
526  *  \return                 nothing
527  */
528 void __intf_IntfProgressUpdate( vlc_object_t *p_this, int i_id,
529                                 const char *psz_status, float f_pos )
530 {
531     interaction_t *p_interaction = intf_InteractionGet( p_this );
532     interaction_dialog_t *p_dialog;
533
534     if( !p_interaction ) return;
535
536     vlc_mutex_lock( &p_interaction->object_lock );
537     p_dialog  =  intf_InteractionGetById( p_this, i_id );
538
539     if( !p_dialog )
540     {
541         vlc_mutex_unlock( &p_interaction->object_lock ) ;
542         return;
543     }
544
545     if( p_dialog->psz_description )
546         free( p_dialog->psz_description );
547     p_dialog->psz_description = strdup( psz_status );
548
549     p_dialog->val.f_float = f_pos;
550
551     p_dialog->i_status = UPDATED_DIALOG;
552     vlc_mutex_unlock( &p_interaction->object_lock) ;
553 }
554
555 /** Hide an interaction dialog
556  * \param p_this the parent vlc object
557  * \param i_id the id of the item to hide
558  * \return nothing
559  */
560 void __intf_UserHide( vlc_object_t *p_this, int i_id )
561 {
562     interaction_t *p_interaction = intf_InteractionGet( p_this );
563     interaction_dialog_t *p_dialog;
564
565     if( !p_interaction ) return;
566
567     vlc_mutex_lock( &p_interaction->object_lock );
568     p_dialog  =  intf_InteractionGetById( p_this, i_id );
569
570     if( !p_dialog )
571     {
572        vlc_mutex_unlock( &p_interaction->object_lock );
573        return;
574     }
575
576     p_dialog->i_status = ANSWERED_DIALOG;
577     vlc_mutex_unlock( &p_interaction->object_lock );
578 }
579
580
581
582 /**********************************************************************
583  * The following functions are local
584  **********************************************************************/
585
586 /* Get the interaction object. Create it if needed */
587 static interaction_t * intf_InteractionGet( vlc_object_t *p_this )
588 {
589     playlist_t *p_playlist;
590     interaction_t *p_interaction;
591
592     p_playlist = (playlist_t*) vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,
593                                                 FIND_ANYWHERE );
594
595     if( !p_playlist )
596     {
597         return NULL;
598     }
599
600     if( p_playlist->p_interaction == NULL )
601     {
602         intf_InteractionInit( p_playlist );
603     }
604
605     p_interaction = p_playlist->p_interaction;
606
607     vlc_object_release( p_playlist );
608
609     return p_interaction;
610 }
611
612 /* Create the interaction object in the given playlist object */
613 static void intf_InteractionInit( playlist_t *p_playlist )
614 {
615     interaction_t *p_interaction;
616
617     p_interaction = vlc_object_create( VLC_OBJECT( p_playlist ),
618                                        sizeof( interaction_t ) );
619     if( !p_interaction )
620     {
621         msg_Err( p_playlist,"out of memory" );
622         return;
623     }
624
625     p_interaction->i_dialogs = 0;
626     p_interaction->pp_dialogs = NULL;
627     p_interaction->p_intf = NULL;
628     p_interaction->i_last_id = DIALOG_LAST_PREDEFINED + 1;
629
630     vlc_mutex_init( p_interaction , &p_interaction->object_lock );
631
632     p_playlist->p_interaction  = p_interaction;
633 }
634
635 /* Look for an interface suitable for interaction */
636 static void intf_InteractionSearchInterface( interaction_t *p_interaction )
637 {
638     vlc_list_t  *p_list;
639     int          i_index;
640
641     p_interaction->p_intf = NULL;
642
643     p_list = vlc_list_find( p_interaction, VLC_OBJECT_INTF, FIND_ANYWHERE );
644     if( !p_list )
645     {
646         msg_Err( p_interaction, "unable to create module list" );
647         return;
648     }
649
650     for( i_index = 0; i_index < p_list->i_count; i_index ++ )
651     {
652         intf_thread_t *p_intf = (intf_thread_t *)
653                                         p_list->p_values[i_index].p_object;
654         if( p_intf->b_interaction )
655         {
656             p_interaction->p_intf = p_intf;
657             break;
658         }
659     }
660     vlc_list_release ( p_list );
661 }
662
663 /* Add a dialog to the queue and wait for answer */
664 static int intf_WaitAnswer( interaction_t *p_interact,
665                             interaction_dialog_t *p_dialog )
666 {
667     int i;
668     vlc_bool_t b_found = VLC_FALSE;
669     vlc_mutex_lock( &p_interact->object_lock );
670     for( i = 0 ; i< p_interact->i_dialogs; i++ )
671     {
672         if( p_interact->pp_dialogs[i]->i_id == p_dialog->i_id )
673         {
674             b_found = VLC_TRUE;
675         }
676     }
677     if( ! b_found )
678     {
679         INSERT_ELEM( p_interact->pp_dialogs,
680                      p_interact->i_dialogs,
681                      p_interact->i_dialogs,
682                      p_dialog );
683     }
684     else
685         p_dialog->i_status = UPDATED_DIALOG;
686     vlc_mutex_unlock( &p_interact->object_lock );
687
688     /// \todo Check that the initiating object is not dying
689     while( p_dialog->i_status != ANSWERED_DIALOG &&
690            p_dialog->i_status != HIDING_DIALOG &&
691            p_dialog->i_status != HIDDEN_DIALOG &&
692            !p_dialog->p_parent->b_die )
693     {
694         msleep( 100000 );
695     }
696     /// \todo locking
697     if( p_dialog->p_parent->b_die )
698     {
699         p_dialog->i_return = DIALOG_CANCELLED;
700         p_dialog->i_status = ANSWERED_DIALOG;
701     }
702     p_dialog->i_flags |= DIALOG_GOT_ANSWER;
703     return p_dialog->i_return;
704 }
705
706 /* Add a dialog to the queue and return */
707 static int intf_Send( interaction_t *p_interact,
708                       interaction_dialog_t *p_dialog )
709 {
710     int i;
711     vlc_bool_t b_found = VLC_FALSE;
712     if( p_interact == NULL ) return VLC_ENOOBJ;
713     vlc_mutex_lock( &p_interact->object_lock );
714
715     for( i = 0 ; i< p_interact->i_dialogs; i++ )
716     {
717         if( p_interact->pp_dialogs[i]->i_id == p_dialog->i_id )
718         {
719             b_found = VLC_TRUE;
720         }
721     }
722     if( !b_found )
723     {
724         INSERT_ELEM( p_interact->pp_dialogs,
725                      p_interact->i_dialogs,
726                      p_interact->i_dialogs,
727                      p_dialog );
728     }
729     else
730         p_dialog->i_status = UPDATED_DIALOG;
731     // Pretend we already retrieved the "answer"
732     p_dialog->i_flags |= DIALOG_GOT_ANSWER;
733     vlc_mutex_unlock( &p_interact->object_lock );
734     return VLC_SUCCESS;
735 }
736
737 /* Find an interaction dialog by its id */
738 static interaction_dialog_t *intf_InteractionGetById( vlc_object_t* p_this,
739                                                        int i_id )
740 {
741     interaction_t *p_interaction = intf_InteractionGet( p_this );
742     int i;
743
744     if( !p_interaction ) return NULL;
745
746     for( i = 0 ; i< p_interaction->i_dialogs; i++ )
747     {
748         if( p_interaction->pp_dialogs[i]->i_id == i_id )
749         {
750             return p_interaction->pp_dialogs[i];
751         }
752     }
753     return NULL;
754 }
755
756 #define FREE( i ) { if( i ) free( i ); i = NULL; }
757
758 static void intf_InteractionDialogDestroy( interaction_dialog_t *p_dialog )
759 {
760     FREE( p_dialog->psz_title );
761     FREE( p_dialog->psz_description );
762     FREE( p_dialog->psz_defaultButton );
763     FREE( p_dialog->psz_alternateButton );
764     FREE( p_dialog->psz_otherButton );
765
766     free( p_dialog );
767 }