gmyth/tests/gmyth_test_epg.c
author renatofilho
Wed May 16 23:55:23 2007 +0100 (2007-05-16)
branchtrunk
changeset 681 1d488185037f
parent 594 f36075170a4e
child 750 312d6bc514f3
permissions -rw-r--r--
[svn r687] removed some debug messages
     1 
     2 #include <gmyth/gmyth_backendinfo.h>
     3 #include <gmyth/gmyth_epg.h>
     4 
     5 #include "common.h"
     6 
     7 static gboolean
     8 test_epg_connection (GMythBackendInfo *backend_info)
     9 {
    10     GMythEPG *epg = gmyth_epg_new ();
    11     gboolean res = FALSE;
    12 
    13     res = gmyth_epg_connect (epg, backend_info);
    14 
    15     gmyth_epg_disconnect (epg);
    16     if ( epg != NULL )
    17     	g_object_unref (epg);
    18 
    19     return res; 
    20 }
    21 
    22 
    23 static gboolean
    24 test_epg_get_channels (GMythBackendInfo *backend_info)
    25 {
    26     GMythEPG *epg = gmyth_epg_new ();
    27     GList *clist;
    28     gint i, length;
    29 
    30     if (!gmyth_epg_connect (epg, backend_info)) {
    31         return FALSE;
    32     }
    33 
    34     length = gmyth_epg_get_channel_list (epg, &clist);
    35     g_debug ("==== %d channels found in the EPG ====\n", length);
    36     for (i=0; i<length; i++) {
    37         GMythChannelInfo *channel_info = (GMythChannelInfo*) g_list_nth_data (clist, i);
    38 
    39         gmyth_channel_info_print(channel_info);
    40     }
    41 
    42     g_list_free (clist);
    43     gmyth_epg_disconnect (epg);
    44     if ( epg != NULL )
    45     	g_object_unref (epg);
    46 }
    47 
    48 static gboolean
    49 test_epg_get_channel_icon (GMythBackendInfo *backend_info)
    50 {
    51     GMythEPG *epg = gmyth_epg_new ();
    52     GList *clist;
    53     gint i, length;
    54 
    55     if (!gmyth_epg_connect (epg, backend_info)) {
    56         return FALSE;
    57     }
    58 
    59     length = gmyth_epg_get_channel_list (epg, &clist);
    60     g_debug ("==== %d channels found in the EPG ====\n", length);
    61     for (i=0; i<length; i++) {
    62         GMythChannelInfo *channel_info = (GMythChannelInfo*) g_list_nth_data (clist, i);
    63         
    64         if (gmyth_epg_channel_has_icon (epg, channel_info)) {
    65             gchar *icon_name = g_strdup_printf ("%s.jpg", channel_info->channel_name->str);
    66             guint8 *icon_data = NULL;
    67             guint icon_length;
    68 
    69             g_debug ("Channel %s has icon %s\n", channel_info->channel_name->str, channel_info->channel_icon->str);
    70 
    71             if (gmyth_epg_channel_get_icon (epg, channel_info, &icon_data, &icon_length)) {
    72                 FILE *outfile = fopen (icon_name, "w+");
    73                 if (fwrite (icon_data, icon_length, 1, outfile) == icon_length)
    74                     g_debug ("\tIcon saved as %s", icon_name);
    75                 else
    76                     g_debug ("\tError while downloading the file or writing it");
    77 
    78                 g_free (icon_data);
    79             }
    80             g_free (icon_name);
    81             
    82         } else {
    83             g_debug ("Channel %s does not have icon\n", channel_info->channel_name->str);
    84         }
    85         gmyth_channel_info_print(channel_info);
    86     }
    87 
    88     g_list_free (clist);
    89     gmyth_epg_disconnect (epg);
    90     g_object_unref (epg);
    91 
    92     return TRUE;
    93 }
    94 
    95 int
    96 main (int args, const char **argv)
    97 {
    98 
    99     GMythBackendInfo *backend_info;
   100     g_type_init ();
   101     g_thread_init (NULL);
   102 
   103     if (args < 2) {
   104         g_debug ("Type %s myth://hostname:port/?mythconverg\n", argv[0]);
   105         return -1;
   106     }
   107 
   108     backend_info = gmyth_backend_info_new_with_uri (argv[1]);
   109 
   110     fprintf(stdout, SYNC_STRING);
   111     fflush(NULL);
   112     getchar();
   113 
   114     test_epg_connection (backend_info);
   115     test_epg_get_channels (backend_info);
   116     test_epg_get_channel_icon (backend_info);
   117 
   118     if ( backend_info != NULL )
   119     	g_object_unref( backend_info );
   120 
   121     return(0);
   122 }
   123