]> git.sesse.net Git - vlc/blobdiff - src/interface/interaction.c
interface/interaction.c: Set the interaction object name.
[vlc] / src / interface / interaction.c
index 4fa46d9b28ae2ef67331885733abfc0b8ae4e9f8..bad5fa48edeca60beed6c02bac582352ac1ca389 100644 (file)
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <stdlib.h>                                      /* free(), strtol() */
-#include <stdio.h>                                                   /* FILE */
-#include <string.h>                                            /* strerror() */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
 
 #include <vlc/vlc.h>
-#include <vlc/input.h>
-#include <assert.h>
 
-#include "vlc_interaction.h"
-#include "vlc_interface.h"
-#include "vlc_playlist.h"
+#include <stdlib.h>                                      /* free(), strtol() */
+#include <stdio.h>                                                   /* FILE */
+#include <string.h>
+
+#include <vlc_interface.h>
+#include <vlc_playlist.h>
+#include "interface.h"
 
 /*****************************************************************************
  * Local prototypes
@@ -68,7 +71,7 @@ void intf_InteractionDestroy( interaction_t *p_interaction )
         DialogDestroy( p_dialog );
         REMOVE_ELEM( p_interaction->pp_dialogs, p_interaction->i_dialogs, i );
     }
-    vlc_object_destroy( p_interaction );
+    vlc_object_release( p_interaction );
 }
 
 /**
@@ -100,19 +103,13 @@ void intf_InteractionManage( playlist_t *p_playlist )
 
             // 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
-    {
         vlc_object_yield( p_interaction->p_intf );
-    }
 
     for( i_index = 0 ; i_index < p_interaction->i_dialogs; i_index ++ )
     {
@@ -270,6 +267,7 @@ int __intf_Progress( vlc_object_t *p_this, const char *psz_title,
     p_new->psz_description = strdup( psz_status );
     p_new->val.f_float = f_pos;
     p_new->i_timeToGo = i_time;
+    p_new->psz_alternate_button = strdup( _( "Cancel" ) );
 
     if( psz_title )
     {
@@ -308,7 +306,7 @@ void __intf_ProgressUpdate( vlc_object_t *p_this, int i_id,
         return;
     }
 
-    FREE( p_dialog->psz_description );
+    free( p_dialog->psz_description );
     p_dialog->psz_description = strdup( psz_status );
 
     p_dialog->val.f_float = f_pos;
@@ -316,6 +314,8 @@ void __intf_ProgressUpdate( vlc_object_t *p_this, int i_id,
 
     p_dialog->i_status = UPDATED_DIALOG;
     vlc_mutex_unlock( &p_interaction->object_lock) ;
+
+    playlist_Signal( pl_Get( p_this ) );
 }
 
 /** Helper function to communicate dialogue cancellations between the
@@ -364,16 +364,19 @@ int __intf_UserLoginPassword( vlc_object_t *p_this,
     p_new->i_type = INTERACT_DIALOG_TWOWAY;
     p_new->psz_title = strdup( psz_title );
     p_new->psz_description = strdup( psz_description );
+    p_new->psz_default_button = strdup( _("Ok" ) );
+    p_new->psz_alternate_button = strdup( _("Cancel" ) );
 
     p_new->i_flags = DIALOG_LOGIN_PW_OK_CANCEL;
 
     i_ret = DialogSend( p_this, p_new );
 
-    if( i_ret != DIALOG_CANCELLED )
+    if( i_ret != DIALOG_CANCELLED && i_ret != VLC_EGENERIC )
     {
-        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] );
+        *ppsz_login = p_new->psz_returned[0]?
+                                strdup( p_new->psz_returned[0] ) : NULL;
+        *ppsz_password = p_new->psz_returned[1]?
+                                strdup( p_new->psz_returned[1] ) : NULL;
     }
     return i_ret;
 }
@@ -392,6 +395,7 @@ int __intf_UserStringInput( vlc_object_t *p_this,
 {
     int i_ret;
     DIALOG_INIT( TWOWAY );
+    p_new->i_type = INTERACT_DIALOG_TWOWAY;
     p_new->psz_title = strdup( psz_title );
     p_new->psz_description = strdup( psz_description );
 
@@ -401,8 +405,8 @@ int __intf_UserStringInput( vlc_object_t *p_this,
 
     if( i_ret != DIALOG_CANCELLED )
     {
-        assert( p_new->psz_returned[0] );
-        *ppsz_usersString = strdup( p_new->psz_returned[0] );
+        *ppsz_usersString = p_new->psz_returned[0]?
+                                    strdup( p_new->psz_returned[0] ) : NULL;
     }
     return i_ret;
 }
@@ -439,20 +443,17 @@ void __intf_UserHide( vlc_object_t *p_this, int i_id )
 /* Get the interaction object. Create it if needed */
 static interaction_t * InteractionGet( vlc_object_t *p_this )
 {
-    playlist_t *p_playlist;
     interaction_t *p_interaction;
+    playlist_t *p_playlist = pl_Yield( p_this );
 
-    p_playlist = (playlist_t*) vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,
-                                                FIND_ANYWHERE );
-    if( !p_playlist )
-        return NULL;
-
+    PL_LOCK;
     if( p_playlist->p_interaction == NULL )
        InteractionInit( p_playlist );
 
     p_interaction = p_playlist->p_interaction;
+    PL_UNLOCK;
 
-    vlc_object_release( p_playlist );
+    pl_Release( p_this );
     return p_interaction;
 }
 
@@ -467,13 +468,13 @@ static void InteractionInit( playlist_t *p_playlist )
         return;
     }
 
+    p_interaction->psz_object_name = "interaction";
     p_interaction->i_dialogs = 0;
     p_interaction->pp_dialogs = NULL;
     p_interaction->p_intf = NULL;
-    p_interaction->i_last_id = DIALOG_LAST_PREDEFINED + 1;
+    p_interaction->i_last_id = 0;
 
     vlc_mutex_init( p_interaction , &p_interaction->object_lock );
-
     p_playlist->p_interaction  = p_interaction;
 }
 
@@ -521,11 +522,11 @@ static interaction_dialog_t *DialogGetById( interaction_t *p_interaction,
 /* 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->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 );
 }
 
@@ -571,6 +572,7 @@ static int DialogSend( vlc_object_t *p_this, interaction_dialog_t *p_dialog )
 
         if( p_dialog->i_type == INTERACT_DIALOG_TWOWAY ) // Wait for answer
         {
+            playlist_Signal( pl_Get( p_this ) );
             while( p_dialog->i_status != ANSWERED_DIALOG &&
                    p_dialog->i_status != HIDING_DIALOG &&
                    p_dialog->i_status != HIDDEN_DIALOG &&
@@ -587,6 +589,7 @@ static int DialogSend( vlc_object_t *p_this, interaction_dialog_t *p_dialog )
             }
             p_dialog->i_flags |= DIALOG_GOT_ANSWER;
             vlc_mutex_unlock( &p_interaction->object_lock );
+            playlist_Signal( pl_Get( p_this ) );
             return p_dialog->i_return;
         }
         else
@@ -594,6 +597,7 @@ static int DialogSend( vlc_object_t *p_this, interaction_dialog_t *p_dialog )
             // Pretend we already retrieved the "answer"
             p_dialog->i_flags |=  DIALOG_GOT_ANSWER;
             vlc_mutex_unlock( &p_interaction->object_lock );
+            playlist_Signal( pl_Get( p_this ) );
             return VLC_SUCCESS;
         }
     }