# HG changeset patch
# User melunko
# Date 1164683755 0
# Node ID 420f3b9432db16dd85adda62fb582810d11c7111
# Parent  d2d5fe1c3997a0a8dd2030035709ebb27e05cc18
[svn r126] Added gmyth_util_file_exists() predicate function

diff -r d2d5fe1c3997 -r 420f3b9432db gmyth/src/Makefile.am
--- a/gmyth/src/Makefile.am	Tue Nov 28 00:54:53 2006 +0000
+++ b/gmyth/src/Makefile.am	Tue Nov 28 03:15:55 2006 +0000
@@ -16,6 +16,7 @@
 	gmyth_file_transfer.c			\
 	gmyth_livetv.c				\
 	gmyth_backendinfo.c			\
+	gmyth_programinfo.c			\
 	gmyth_uri.c
 
 libgmyth_la_CFLAGS = 			\
@@ -55,6 +56,7 @@
 	gmyth_file_transfer.h			\
 	gmyth_livetv.h				\
 	gmyth_backendinfo.h			\
+	gmyth_programinfo.h			\
 	gmyth_uri.h
 
 CLEANFILES = $(BUILT_SOURCES)
diff -r d2d5fe1c3997 -r 420f3b9432db gmyth/src/gmyth_file_transfer.c
--- a/gmyth/src/gmyth_file_transfer.c	Tue Nov 28 00:54:53 2006 +0000
+++ b/gmyth/src/gmyth_file_transfer.c	Tue Nov 28 03:15:55 2006 +0000
@@ -288,7 +288,7 @@
   g_print( "[%s] Got Monitor response from %s: %s\n", __FUNCTION__, base_str->str, resp->str );
   //g_thread_create( (GThreadFunc)myth_control_sock_listener, transfer->event_sock->sd_io_ch, TRUE, NULL );
   io_watcher_context = g_main_context_default();
-  GMainLoop *loop = g_main_loop_new( NULL, TRUE );
+  //GMainLoop *loop = g_main_loop_new( NULL, TRUE );
 
   //GSource *source;
 
diff -r d2d5fe1c3997 -r 420f3b9432db gmyth/src/gmyth_socket.c
--- a/gmyth/src/gmyth_socket.c	Tue Nov 28 00:54:53 2006 +0000
+++ b/gmyth/src/gmyth_socket.c	Tue Nov 28 03:15:55 2006 +0000
@@ -942,8 +942,11 @@
     // FIXME: change this implementation!
     tmp_list = str_list->glist;
     for(; tmp_list; tmp_list = tmp_list->next) {
-	if ( tmp_list->data != NULL )
+	if ( tmp_list->data != NULL ) {
 	    g_ptr_array_add(ptr_array, ((GString*)tmp_list->data)->str);
+	} else {
+	    g_ptr_array_add (ptr_array, g_strdup (""));
+	}
     }
     g_ptr_array_add(ptr_array, NULL); // g_str_joinv() needs a NULL terminated string
 
diff -r d2d5fe1c3997 -r 420f3b9432db gmyth/src/gmyth_util.c
--- a/gmyth/src/gmyth_util.c	Tue Nov 28 00:54:53 2006 +0000
+++ b/gmyth/src/gmyth_util.c	Tue Nov 28 03:15:55 2006 +0000
@@ -25,10 +25,16 @@
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 
+#include <glib.h>
+#include <glib/gprintf.h>
+
 #include "gmyth_util.h"
 
-#include <glib.h>
-#include <glib/gprintf.h>
+#include "gmyth_backendinfo.h"
+#include "gmyth_socket.h"
+#include "gmyth_programinfo.h"
+#include "gmyth_common.h"
+
 
 /** Converts a time_t struct in a GString at ISO standard format 
  * (e.g. 2006-07-20T09:56:41).
@@ -138,4 +144,37 @@
 
 }
 
+gboolean
+gmyth_util_file_exists (GMythBackendInfo *backend_info, const char* filename)
+{
+    GMythSocket *socket;
+    GMythProgramInfo *program;
+    GMythStringList *slist;
+    gboolean res;
+    
+    socket = gmyth_socket_new ();
+    gmyth_socket_connect_to_backend (socket, backend_info->hostname,
+		    backend_info->port, TRUE);
 
+    program = g_new0 (GMythProgramInfo, 1);
+    program->pathname = g_string_new (filename);
+
+    slist = gmyth_string_list_new ();
+    gmyth_string_list_append_char_array (slist, "QUERY_CHECKFILE");
+
+    gmyth_program_info_to_string_list (program, slist);
+    g_debug ("XXXXXXXX List size: %d\n", gmyth_string_list_length (slist));
+
+    gmyth_socket_sendreceive_stringlist (socket, slist);
+
+    res = (gmyth_string_list_get_int (slist, 0) == 1);
+    
+    // fixme: we should do this in a program_info_free() function
+    g_string_free (program->pathname, FALSE);
+    g_free (program);
+
+    g_object_unref (slist);
+
+    return res;    
+}
+
diff -r d2d5fe1c3997 -r 420f3b9432db gmyth/src/gmyth_util.h
--- a/gmyth/src/gmyth_util.h	Tue Nov 28 00:54:53 2006 +0000
+++ b/gmyth/src/gmyth_util.h	Tue Nov 28 03:15:55 2006 +0000
@@ -32,6 +32,7 @@
 #include <glib.h>
 
 #include "gmyth_stringlist.h"
+#include "gmyth_backendinfo.h"
 
 G_BEGIN_DECLS
 
@@ -40,6 +41,9 @@
 time_t      gmyth_util_string_to_time   (GString* time_str);
 gint64     gmyth_util_decode_long_long (GMythStringList *strlist, 
                                          guint offset);
+
+gboolean gmyth_util_file_exists (GMythBackendInfo *backend_info, const char* filename);
+
 G_END_DECLS
 	
 #endif /*GMYTH_UTIL_H_*/