# HG changeset patch
# User rosfran
# Date 1171053748 0
# Node ID 4ba9626303753c150ccdae3df44c19b82a0da2ca
# Parent  8c26cc7dc51b055d5ed7557d030cc5aed0987b2e
[svn r348] Fixes.

diff -r 8c26cc7dc51b -r 4ba962630375 libgnomevfs2-mythtv/modules/mythtv-method.c
--- a/libgnomevfs2-mythtv/modules/mythtv-method.c	Fri Feb 09 20:42:11 2007 +0000
+++ b/libgnomevfs2-mythtv/modules/mythtv-method.c	Fri Feb 09 20:42:28 2007 +0000
@@ -305,11 +305,13 @@
 {
     GMythFileTransfer *file_transfer = NULL;
     GMythRecorder			*recorder 		 = NULL;
+    GMythTVChain			*tvchain	 		 = NULL;
     GMythBackendInfo  *backend_info  = NULL;
     GMythURI					*gmyth_uri		 = NULL;
 		GMythSocket 			*socket 			 = NULL;		 
     gboolean 					is_livetv 		 = FALSE;
     gboolean					ret						 = TRUE;
+    gboolean 					res 					 = TRUE;
     
     /* Creates and fills out the backend info structure */    
 	  backend_info = gmyth_backend_info_new_with_uri ( 
@@ -339,7 +341,6 @@
 
 	  /* Connect to the backend */
 	  if ( gmyth_uri != NULL && is_livetv == TRUE ) {
-	  	gboolean res = TRUE;
 	  	
 	  	/* start to get file info from LiveTV remote encoder */	  	
 			socket = gmyth_socket_new ();
@@ -362,8 +363,8 @@
 			/* Gets the recorder num */
 			recorder = remote_request_next_free_recorder (socket, -1);
 			
-			if ( socket != NULL )
-				g_object_unref (socket);
+			//if ( socket != NULL )
+			//	g_object_unref (socket);
 		
 			if ( recorder == NULL ) {
 				g_print ("[%s] None remote encoder available", __FUNCTION__);
@@ -377,7 +378,25 @@
 				g_print ("[%s] Fail while setting remote encoder\n", __FUNCTION__);
 				res = FALSE;
 				goto error;
-			}			
+			}
+			
+			/* Creates livetv chain handler */
+			tvchain = gmyth_tvchain_new();
+			gmyth_tvchain_initialize ( tvchain, backend_info );
+		
+			if ( tvchain == NULL || tvchain->tvchain_id == NULL ) {
+				res = FALSE;
+				goto error;
+			}
+			
+			// Spawn live tv. Uses the socket to send mythprotocol data to start livetv in the backend (remotelly)
+			res = gmyth_recorder_spawntv ( recorder,
+					gmyth_tvchain_get_id(tvchain) );
+			if (!res) {
+				g_warning ("[%s] Fail while spawn tv\n", __FUNCTION__);
+				res = FALSE;
+				goto error;
+			}		
 			
 		  //gchar* channel_name = gmyth_uri_get_channel_name( gmyth_uri );
 	
@@ -402,6 +421,9 @@
 	    
 	    if ( prog_info != NULL )
 	    	g_object_unref( prog_info );
+
+	    if ( tvchain != NULL )
+	    	g_object_unref (tvchain);
 	    
 	    file_info->size = (GnomeVFSFileSize) - 1;
 
@@ -440,6 +462,9 @@
 error:
     if (backend_info)
    		g_object_unref (backend_info);
+   		
+   	if (!res)
+   		return GNOME_VFS_ERROR_IO;
 
     return GNOME_VFS_OK;
 }