]> git.sesse.net Git - vlc/blobdiff - src/interface/interaction.c
interface/interaction.c: Set the interaction object name.
[vlc] / src / interface / interaction.c
index a6b624c06a7755d4b869e5bd325612e9cdeb7296..bad5fa48edeca60beed6c02bac582352ac1ca389 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * interaction.c: User interaction functions
  *****************************************************************************
- * Copyright (C) 2005-2006 VideoLAN
+ * Copyright (C) 2005-2006 the VideoLAN team
  * $Id$
  *
  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
 /*****************************************************************************
  * 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 ++ )
     {
@@ -136,13 +133,10 @@ void intf_InteractionManage( playlist_t *p_playlist )
             break;
         case HIDDEN_DIALOG:
             if( !(p_dialog->i_flags & DIALOG_GOT_ANSWER) ) break;
-            if( !(p_dialog->i_flags & DIALOG_REUSABLE) )
-            {
-                p_dialog->i_action = INTERACT_DESTROY;
-                val.p_address = p_dialog;
-                if( p_interaction->p_intf )
-                    var_Set( p_interaction->p_intf, "interaction", val );
-            }
+            p_dialog->i_action = INTERACT_DESTROY;
+            val.p_address = p_dialog;
+            if( p_interaction->p_intf )
+                var_Set( p_interaction->p_intf, "interaction", val );
             break;
         case DESTROYED_DIALOG:
             // Interface has now destroyed it, remove it
@@ -175,6 +169,7 @@ void intf_InteractionManage( playlist_t *p_playlist )
         memset( p_new, 0, sizeof( interaction_dialog_t ) );               \
         p_new->b_cancelled = VLC_FALSE;                                   \
         p_new->i_status = NEW_DIALOG;                                     \
+        p_new->i_flags = 0; \
         p_new->i_type = INTERACT_DIALOG_##type;                           \
         p_new->psz_returned[0] = NULL;                                    \
         p_new->psz_returned[1] = NULL;
@@ -196,7 +191,7 @@ int __intf_UserFatal( vlc_object_t *p_this, vlc_bool_t b_blocking,
 {
     va_list args;
     DIALOG_INIT( ONEWAY );
-    
+
     p_new->psz_title = strdup( psz_title );
     FORMAT_DESC;
 
@@ -219,7 +214,7 @@ int __intf_UserWarn( vlc_object_t *p_this,
 {
     va_list args;
     DIALOG_INIT( ONEWAY );
-    
+
     p_new->psz_title = strdup( psz_title );
     FORMAT_DESC
 
@@ -272,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 )
     {
@@ -310,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;
@@ -318,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
@@ -366,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;
 }
@@ -394,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 );
 
@@ -403,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;
 }
@@ -441,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;
 }
 
@@ -469,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;
 }
 
@@ -523,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 );
 }
 
@@ -543,7 +542,7 @@ static int DialogSend( vlc_object_t *p_this, interaction_dialog_t *p_dialog )
 
     if( p_this->i_flags & OBJECT_FLAGS_NOINTERACT ) return VLC_EGENERIC;
 
-    if( config_GetInt(p_this, "interact") || 
+    if( config_GetInt(p_this, "interact") ||
         p_dialog->i_flags & DIALOG_BLOCKING_ERROR ||
         p_dialog->i_flags & DIALOG_NONBLOCKING_ERROR )
     {
@@ -570,24 +569,27 @@ static int DialogSend( vlc_object_t *p_this, interaction_dialog_t *p_dialog )
         }
         else
             p_dialog->i_status = UPDATED_DIALOG;
-        vlc_mutex_unlock( &p_interaction->object_lock );
 
         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 &&
                    !p_dialog->p_parent->b_die )
             {
+                vlc_mutex_unlock( &p_interaction->object_lock );
                 msleep( 100000 );
+                vlc_mutex_lock( &p_interaction->object_lock );
             }
-            /// \todo locking ?
             if( p_dialog->p_parent->b_die )
             {
                 p_dialog->i_return = DIALOG_CANCELLED;
                 p_dialog->i_status = ANSWERED_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
@@ -595,9 +597,10 @@ 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;
         }
     }
     else
         return VLC_EGENERIC;
-} 
+}