diff -r 178207a9cd61 -r 9e589622f097 libgnomevfs2-mythtv/modules/mythtv-method.c --- a/libgnomevfs2-mythtv/modules/mythtv-method.c Thu Apr 05 15:26:47 2007 +0100 +++ b/libgnomevfs2-mythtv/modules/mythtv-method.c Thu Apr 19 23:03:58 2007 +0100 @@ -29,7 +29,9 @@ #include #include +#include #include +#include #include #include #include @@ -51,7 +53,7 @@ #define MYTHTV_MAX_REQUEST_SIZE 64*1024 typedef struct { - GMythFileTransfer *file_transfer; + GMythFile *file; GMythLiveTV *livetv; GMythBackendInfo *backend_info; GMythURI *gmyth_uri; @@ -128,9 +130,9 @@ method_handle->livetv = NULL; } - if (method_handle->file_transfer != NULL) { - g_object_unref (method_handle->file_transfer); - method_handle->file_transfer = NULL; + if (method_handle->file != NULL) { + g_object_unref (method_handle->file); + method_handle->file = NULL; } if (method_handle->gmyth_uri != NULL) { @@ -187,27 +189,37 @@ /* file size for remote files */ if (gmyth_uri_is_livetv (gmyth_uri) == FALSE) { - GMythFileTransfer *file_transfer = gmyth_file_transfer_new (backend_info); - + GMythFile *file = NULL; + gboolean ret = FALSE; + /* Verifies if the file exists */ if (!gmyth_util_file_exists (backend_info, gmyth_uri_get_path (gmyth_uri))) { - g_object_unref (file_transfer); + g_object_unref (file); g_object_unref (backend_info); g_debug ("NOT FOUND %s/%d", __FUNCTION__, __LINE__); return GNOME_VFS_ERROR_NOT_FOUND; } - if (!gmyth_file_transfer_open (file_transfer, gmyth_uri_get_path (gmyth_uri))) { - g_object_unref (file_transfer); + if ( gmyth_uri_is_local_file(gmyth_uri) ) + { + file = GMYTH_FILE( gmyth_file_local_new(backend_info) ); + ret = gmyth_file_local_open ( GMYTH_FILE_LOCAL( file ) ); + } else { + file = GMYTH_FILE( gmyth_file_transfer_new(backend_info) ); + ret = gmyth_file_transfer_open ( GMYTH_FILE_TRANSFER(file), gmyth_uri_get_path (gmyth_uri)); + } + + if (!ret) { + g_object_unref (file); g_object_unref (backend_info); g_debug ("NOT FOUND %s/%d", __FUNCTION__, __LINE__); return GNOME_VFS_ERROR_NOT_FOUND; } - info->size = gmyth_file_transfer_get_filesize (file_transfer); + info->size = gmyth_file_get_filesize (file); info->valid_fields |= GNOME_VFS_FILE_INFO_FIELDS_SIZE; - g_object_unref (file_transfer); + g_object_unref (file); } g_object_unref (backend_info); @@ -241,16 +253,16 @@ } - method_handle->file_transfer = - gmyth_livetv_create_file_transfer (method_handle->livetv); + method_handle->file = + GMYTH_FILE( gmyth_livetv_create_file_transfer (method_handle->livetv) ); - if (method_handle->file_transfer == NULL) { + if (method_handle->file == NULL) { result = GNOME_VFS_ERROR_INVALID_URI; g_debug ("MythTV FileTransfer is NULL!\n"); goto error; } - if (!gmyth_file_transfer_open (method_handle->file_transfer, + if (!gmyth_file_transfer_open ( GMYTH_FILE_TRANSFER(method_handle->file), method_handle->livetv->uri != NULL ? gmyth_uri_get_path (method_handle->livetv->uri) : method_handle->livetv->proginfo->pathname->str)) { @@ -261,9 +273,7 @@ } } else { - method_handle->file_transfer = - gmyth_file_transfer_new (method_handle->backend_info); - + gboolean ret = TRUE; /* Verifies if the file exists */ if (!gmyth_util_file_exists (method_handle->backend_info, gmyth_uri_get_path (method_handle->gmyth_uri))) { @@ -271,10 +281,19 @@ g_debug ("NOT FOUND %s/%d", __FUNCTION__, __LINE__); goto error; } + + if ( gmyth_uri_is_local_file(method_handle->gmyth_uri) ) + { + method_handle->file = GMYTH_FILE( gmyth_file_local_new(method_handle->backend_info) ); + ret = gmyth_file_local_open ( GMYTH_FILE_LOCAL( method_handle->file ) ); + } else { + method_handle->file = GMYTH_FILE( gmyth_file_transfer_new(method_handle->backend_info) ); + ret = gmyth_file_transfer_open ( GMYTH_FILE_TRANSFER(method_handle->file), + gmyth_uri_get_path (method_handle->gmyth_uri)); + } /* sets the Playback monitor connection */ - if (!gmyth_file_transfer_open (method_handle->file_transfer, - gmyth_uri_get_path (method_handle->gmyth_uri))) { + if (!ret) { g_debug ("NOT FOUND %s/%d", __FUNCTION__, __LINE__); result = GNOME_VFS_ERROR_NOT_FOUND; @@ -284,7 +303,7 @@ method_handle->configured = TRUE; - if (method_handle->file_transfer == NULL) { + if (method_handle->file == NULL) { result = GNOME_VFS_ERROR_NOT_OPEN; } @@ -360,22 +379,27 @@ { GnomeVFSResult retval = GNOME_VFS_OK; MythtvHandle *myth_handle; - GMythFileTransferReadResult result; + GMythFileReadResult result; GByteArray *myth_buffer = g_byte_array_new (); _GNOME_VFS_METHOD_PARAM_CHECK (method_handle != NULL); myth_handle = (MythtvHandle *) method_handle; - result = gmyth_file_transfer_read (myth_handle->file_transfer, + if ( gmyth_uri_is_local_file(myth_handle->gmyth_uri) ) + result = gmyth_file_local_read ( GMYTH_FILE_LOCAL(myth_handle->file), + myth_buffer, + num_bytes, gmyth_uri_is_livetv (myth_handle->gmyth_uri)); + else + result = gmyth_file_transfer_read ( GMYTH_FILE_TRANSFER(myth_handle->file), myth_buffer, num_bytes, gmyth_uri_is_livetv (myth_handle->gmyth_uri)); - if (result == GMYTH_FILE_TRANSFER_READ_ERROR) { + if (result == GMYTH_FILE_READ_ERROR) { retval = GNOME_VFS_ERROR_IO; } - if (result == GMYTH_FILE_TRANSFER_READ_EOF) { + if (result == GMYTH_FILE_READ_EOF) { retval = GNOME_VFS_ERROR_EOF; } @@ -433,7 +457,7 @@ return GNOME_VFS_ERROR_NOT_SUPPORTED; } - new_offset = gmyth_file_transfer_seek (myth_handle->file_transfer, offset, whence_p); + new_offset = gmyth_file_transfer_seek (myth_handle->file, offset, whence_p); if (new_offset != 0) { myth_handle->offset = new_offset; return GNOME_VFS_OK;