branches/gmyth-0.1b/src/gmyth_programinfo.c
author morphbr
Sat Feb 10 20:01:54 2007 +0000 (2007-02-10)
branchtrunk
changeset 349 7005e696052c
permissions -rw-r--r--
[svn r351] - Bug fix in gmyth_util.c: included support for time without seconds in gmyth_util_string_to_time_val_fmt (XML format from backend)
- Bug fix in gmyth_http.c: fixed bug when there are no channels
- gmyth_vlc.c/h: included support to specify a port when connecting to VLC
- tests: fixed vlc test file regarding the fix above
created script to compile http test app
     1 /**
     2  * GMyth Library
     3  *
     4  * @file gmyth/gmyth_programinfo.c
     5  * 
     6  * @brief <p> GMythFileTransfer deals with the file streaming media remote/local
     7  * transfering to the MythTV frontend.
     8  *
     9  * Copyright (C) 2006 INdT - Instituto Nokia de Tecnologia.
    10  * @author Leonardo Sobral Cunha <leonardo.cunha@indt.org.br>
    11  *
    12  *//*
    13  * 
    14  * This program is free software; you can redistribute it and/or modify
    15  * it under the terms of the GNU Lesser General Public License as published by
    16  * the Free Software Foundation; either version 2 of the License, or
    17  * (at your option) any later version.
    18  *
    19  * This program is distributed in the hope that it will be useful,
    20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    22  * GNU General Public License for more details.
    23  *
    24  * You should have received a copy of the GNU Lesser General Public License
    25  * along with this program; if not, write to the Free Software
    26  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    27  *
    28  */
    29  
    30 #ifdef HAVE_CONFIG_H
    31 #include "config.h"
    32 #endif
    33 
    34 #include <stdlib.h>
    35 #include <string.h>
    36 #include <assert.h>
    37 
    38 #include "gmyth_programinfo.h"
    39 #include "gmyth_util.h"
    40 #include "gmyth_debug.h"
    41 
    42 static void gmyth_program_info_class_init          (GMythProgramInfoClass *klass);
    43 static void gmyth_program_info_init                (GMythProgramInfo *object);
    44 
    45 static void gmyth_program_info_dispose  (GObject *object);
    46 static void gmyth_program_info_finalize (GObject *object);
    47 
    48 G_DEFINE_TYPE(GMythProgramInfo, gmyth_program_info, G_TYPE_OBJECT)
    49     
    50 static void
    51 gmyth_program_info_class_init (GMythProgramInfoClass *klass)
    52 {
    53 	GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
    54 	
    55   gobject_class->dispose  = gmyth_program_info_dispose;
    56   gobject_class->finalize = gmyth_program_info_finalize;	
    57 }
    58 
    59 static void
    60 gmyth_program_info_init (GMythProgramInfo *gmyth_program_info)
    61 { 
    62   gmyth_program_info->chancommfree = 0;
    63 
    64 	/** A flag informing if the program has video or not. */    
    65   gmyth_program_info->isVideo = FALSE;
    66   gmyth_program_info->lenMins = 0;
    67   
    68   gmyth_program_info->stars = 0.0f;
    69   gmyth_program_info->repeat = 0;
    70   
    71   gmyth_program_info->hasAirDate = FALSE;
    72 
    73   gmyth_program_info->spread = 0;
    74   gmyth_program_info->startCol = 0;
    75 
    76   gmyth_program_info->recpriority2 = 0;
    77   gmyth_program_info->reactivate = 0;
    78 
    79   gmyth_program_info->recordid = 0;
    80   gmyth_program_info->parentid = 0;   
    81   
    82   /** The backend video source id associated to this program.*/
    83   gmyth_program_info->sourceid = 0;
    84   /** the backend input id associated to this program.*/
    85   gmyth_program_info->inputid = 0;
    86   /** The backend card id associated to this program.*/
    87   gmyth_program_info->cardid = 0;
    88   gmyth_program_info->shareable = FALSE;
    89   gmyth_program_info->duplicate = FALSE;
    90 
    91   gmyth_program_info->findid = 0;
    92 
    93   gmyth_program_info->programflags = 0;
    94   gmyth_program_info->transcoder = 0;
    95 
    96   gmyth_program_info->recpriority = 0;
    97 
    98 	/** The file size of the recorded program.*/
    99   gmyth_program_info->filesize = -1;
   100 
   101 
   102 }
   103 
   104 static void
   105 gmyth_program_info_dispose  (GObject *object)
   106 {
   107   GMythProgramInfo *gmyth_program_info = GMYTH_PROGRAM_INFO(object);
   108 
   109 	if ( gmyth_program_info->chanid != NULL )
   110 	{
   111 		g_string_free( gmyth_program_info->chanid, TRUE );
   112 		gmyth_program_info->chanid = NULL;
   113 	}
   114   
   115   /** The program start time. */
   116 	if ( gmyth_program_info->startts != NULL )
   117 	{
   118 		g_free( gmyth_program_info->startts);
   119 		gmyth_program_info->startts = NULL;
   120 	}
   121 
   122   /** The program end time. */
   123   if ( gmyth_program_info->endts != NULL )
   124   {
   125   	g_free( gmyth_program_info->endts );
   126   	gmyth_program_info->endts = NULL;
   127   }
   128   
   129   /** The recording schedule start time. */
   130   if ( gmyth_program_info->recstartts != NULL )
   131   {
   132   	g_free( gmyth_program_info->recstartts );
   133   	gmyth_program_info->recstartts = NULL;
   134   }
   135   
   136   /** The recording schedule end time */
   137   if ( gmyth_program_info->recendts != NULL )
   138   {
   139   	g_free(gmyth_program_info->recendts);
   140   	gmyth_program_info->recendts = NULL;
   141   }
   142   
   143   /** The program title. */
   144   if (gmyth_program_info->title != NULL )
   145   {
   146   	g_string_free(gmyth_program_info->title, TRUE);
   147   	gmyth_program_info->title = NULL;
   148   }
   149   
   150   /** The program subtitle. */
   151   if (gmyth_program_info->subtitle != NULL )
   152   {
   153   	g_string_free(gmyth_program_info->subtitle, TRUE );
   154   	gmyth_program_info->subtitle = NULL;
   155   }
   156   /** The program description. */
   157   if ( gmyth_program_info->description != NULL )
   158   {
   159   	g_string_free( gmyth_program_info->description, TRUE );
   160   	gmyth_program_info->description = NULL;
   161   }
   162   	
   163   /** The program category. */
   164   if ( gmyth_program_info->category != NULL )
   165   {
   166   	g_string_free( gmyth_program_info->category, TRUE );
   167   	gmyth_program_info->category = NULL;
   168   }
   169   
   170   if ( gmyth_program_info->chanstr != NULL )
   171   {
   172   	g_string_free( gmyth_program_info->chanstr, TRUE );
   173   	gmyth_program_info->chanstr = NULL;
   174   }
   175   if ( gmyth_program_info->chansign != NULL )
   176   {
   177   	g_string_free( gmyth_program_info->chansign, TRUE );
   178   	gmyth_program_info->chansign = NULL;
   179   }
   180   /** The associated channel name. */
   181   if ( gmyth_program_info->channame != NULL )
   182   {
   183   	g_string_free( gmyth_program_info->channame, TRUE );
   184   	gmyth_program_info->channame = NULL;
   185   }
   186   if ( gmyth_program_info->chanOutputFilters != NULL )
   187   {
   188   	g_string_free( gmyth_program_info->chanOutputFilters, TRUE );
   189   	gmyth_program_info->chanOutputFilters = NULL;
   190   }
   191   
   192   if ( gmyth_program_info->seriesid != NULL )
   193   {
   194   	g_string_free( gmyth_program_info->seriesid, TRUE );
   195   	gmyth_program_info->chanOutputFilters = NULL;
   196 
   197   }
   198   /** The program unique id. */
   199   if ( gmyth_program_info->programid != NULL )
   200   {
   201   	g_string_free( gmyth_program_info->programid, TRUE );
   202   	gmyth_program_info->programid = NULL;
   203 
   204   }
   205   if ( gmyth_program_info->catType != NULL )
   206   {
   207   	g_string_free( gmyth_program_info->catType, TRUE );
   208   	gmyth_program_info->catType = NULL;
   209 
   210   }
   211 
   212   if ( gmyth_program_info->sortTitle != NULL )
   213   {
   214   	g_string_free( gmyth_program_info->sortTitle, TRUE );
   215   	gmyth_program_info->sortTitle = NULL;
   216 
   217   }  
   218   
   219   if ( gmyth_program_info->year != NULL )
   220   {
   221   	g_string_free( gmyth_program_info->year, TRUE );
   222   	gmyth_program_info->year = NULL;
   223 
   224   }    
   225   
   226   if ( gmyth_program_info->originalAirDate != NULL )
   227   {
   228   	g_free( gmyth_program_info->originalAirDate);
   229   	gmyth_program_info->originalAirDate = NULL;
   230   }
   231   if ( gmyth_program_info->lastmodified != NULL )
   232   {
   233   	g_free( gmyth_program_info->lastmodified );
   234   	gmyth_program_info->lastmodified = NULL;
   235 
   236   }
   237   if (gmyth_program_info->lastInUseTime != NULL)
   238   {
   239   	g_free( gmyth_program_info->lastInUseTime );
   240   	gmyth_program_info->lastInUseTime = NULL;
   241   }
   242   
   243   if ( gmyth_program_info->schedulerid != NULL )
   244   {
   245   	g_string_free( gmyth_program_info->schedulerid, TRUE );
   246   	gmyth_program_info->schedulerid = NULL;
   247   }
   248 
   249   if ( gmyth_program_info->recgroup != NULL )
   250   {
   251   	g_string_free( gmyth_program_info->recgroup, TRUE );
   252   	gmyth_program_info->recgroup = NULL;
   253   }
   254   if ( gmyth_program_info->playgroup != NULL )
   255   {
   256   	g_string_free( gmyth_program_info->playgroup, TRUE );
   257   	gmyth_program_info->playgroup = NULL;
   258   }
   259   
   260   /** The file name of the recorded program.*/
   261   if ( gmyth_program_info->pathname != NULL)
   262   {
   263   	g_string_free( gmyth_program_info->pathname, TRUE );
   264   	gmyth_program_info->pathname = NULL;
   265   }
   266 
   267   if ( gmyth_program_info->hostname != NULL )
   268   {
   269   	g_string_free( gmyth_program_info->hostname, TRUE );
   270   	gmyth_program_info->hostname = NULL;
   271   }
   272    
   273 	G_OBJECT_CLASS (gmyth_program_info_parent_class)->dispose (object);
   274 }
   275 
   276 static void
   277 gmyth_program_info_finalize (GObject *object)
   278 {
   279     g_signal_handlers_destroy (object);
   280 
   281     G_OBJECT_CLASS (gmyth_program_info_parent_class)->finalize (object);
   282 }
   283 
   284 /**
   285  * Creates a new instance of GMythProgramInfo.
   286  * 
   287  * @return a new instance of GMythProgramInfo.
   288  */
   289 GMythProgramInfo*
   290 gmyth_program_info_new (void)
   291 {
   292     GMythProgramInfo *program_info = GMYTH_PROGRAM_INFO (g_object_new(GMYTH_PROGRAM_INFO_TYPE, NULL));
   293 
   294     return program_info;
   295 }
   296 
   297 GMythStringList*
   298 gmyth_program_info_to_string_list (GMythProgramInfo *prog, GMythStringList *slist)
   299 {
   300     g_return_val_if_fail (prog != NULL, NULL);
   301     g_return_val_if_fail (slist != NULL, NULL);
   302 
   303     gmyth_string_list_append_string (slist, prog->title); /* 0 */
   304     gmyth_string_list_append_string (slist, prog->subtitle); /* 1 */
   305     gmyth_string_list_append_string (slist, prog->description); /* 2 */
   306     gmyth_string_list_append_string (slist, prog->category); /* 3 */
   307     gmyth_string_list_append_string (slist, prog->chanid); /* 4 */
   308     gmyth_string_list_append_string (slist, prog->chanstr); /* 5 */
   309     gmyth_string_list_append_string (slist, prog->chansign); /* 6 */
   310     gmyth_string_list_append_string (slist, prog->channame); /* 7 */
   311     gmyth_string_list_append_string (slist, prog->pathname); /* 8 */
   312 
   313     // fixme
   314     gmyth_string_list_append_int64 (slist, 100/*prog->filesize*/); /* 9 */
   315     gmyth_string_list_append_int64 (slist, 10); /* 11 */
   316 
   317     if (prog->startts)
   318         gmyth_string_list_append_int (slist, prog->startts->tv_sec);  /* 11 */ //DATETIME_TO_LIST(startts)
   319     else
   320 	gmyth_string_list_append_int (slist, 0);
   321     
   322     if (prog->endts)
   323         gmyth_string_list_append_int (slist, prog->endts->tv_sec);  /* 12 */ //DATETIME_TO_LIST(endts)
   324     else
   325 	gmyth_string_list_append_int (slist, 0);
   326 
   327     gmyth_string_list_append_int (slist, prog->duplicate); /* 13 */
   328     gmyth_string_list_append_int (slist, prog->shareable); /* 14 */
   329     gmyth_string_list_append_int (slist, prog->findid); /* 15 */
   330     gmyth_string_list_append_string (slist, prog->hostname); /* 16 */
   331     gmyth_string_list_append_int (slist, prog->sourceid); /* 17 */
   332     gmyth_string_list_append_int (slist, prog->cardid); /* 18 */
   333     gmyth_string_list_append_int (slist, prog->inputid); /* 19 */
   334     gmyth_string_list_append_int (slist, prog->recpriority); /* 20 */
   335     gmyth_string_list_append_int (slist, 0 /*prog->recstatus*/); /* 21 */
   336     gmyth_string_list_append_int (slist, prog->recordid); /* 22 */
   337     gmyth_string_list_append_int (slist, 0 /*prog->rectype*/); /* 23 */
   338     gmyth_string_list_append_int (slist, 0 /*prog->dupin*/); /* 24 */
   339     gmyth_string_list_append_int (slist, 0 /*prog->dupmethod*/); /* 25 */
   340     gmyth_string_list_append_int (slist, prog->recstartts != NULL ? prog->recstartts->tv_sec : 0);  /* 26 */ //DATETIME_TO_LIST(recstartts)
   341     gmyth_string_list_append_int (slist, prog->recendts != NULL ? prog->recendts->tv_sec : 0);  /* 27 */ //DATETIME_TO_LIST(recendts)
   342     gmyth_string_list_append_int (slist, prog->repeat); /* 28 */
   343     gmyth_string_list_append_int (slist, prog->programflags); /* 29 */
   344     gmyth_string_list_append_char_array (slist, "Default"); /* 30 */ //prog->(recgroup != "") ? recgroup : "Default")
   345     gmyth_string_list_append_int (slist, prog->chancommfree); /* 31 */
   346     gmyth_string_list_append_string (slist, prog->chanOutputFilters); /* 32 */
   347     gmyth_string_list_append_string (slist, prog->seriesid); /* 33 */
   348     gmyth_string_list_append_string (slist, prog->programid); /* 34 */
   349     gmyth_string_list_append_string (slist, ""); /* 35 */
   350     gmyth_string_list_append_int (slist, prog->lastmodified != NULL ? prog->lastmodified->tv_sec : 0);  /* 36 */ //DATETIME_TO_LIST(lastmodified)
   351     gmyth_string_list_append_int (slist, 0);  /* 37 */ //FLOAT_TO_LIST(stars)
   352     gmyth_string_list_append_int (slist, prog->originalAirDate != NULL ? prog->originalAirDate->tv_sec : 0);  /* 38 */ //DATETIME_TO_LIST(QDateTime(originalAirDate))
   353     gmyth_string_list_append_int (slist, prog->hasAirDate); /* 39 */
   354     gmyth_string_list_append_char_array (slist, "Default");  /* 40 */ //prog->(playgroup != "") ? playgroup : "Default")
   355     gmyth_string_list_append_int (slist, prog->recpriority2); /* 41 */
   356    
   357     return slist;
   358 }
   359 
   360 GMythProgramInfo*
   361 gmyth_program_info_from_string_list ( GMythStringList *slist )
   362 {
   363 		GMythProgramInfo *prog = gmyth_program_info_new();
   364 
   365     g_return_val_if_fail (slist != NULL, NULL);
   366     /*
   367 		Unknown
   368 		
   369 		
   370 		
   371 		1000
   372 		9
   373 		1000
   374 		Band
   375 		/mnt/store//1000_20070125110059.nuv
   376 		0
   377 		0
   378 		1169733659
   379 		1169735400
   380 		0
   381 		0
   382 		0
   383 		hmelo-desktop
   384 		0
   385 		1
   386 		0
   387 		0
   388 		-2
   389 		0
   390 		0
   391 		15
   392 		6
   393 		1169733659
   394 		1169735400
   395 		0
   396 		0
   397 		LiveTV
   398 		0
   399 		
   400 		
   401 		
   402 		1169733659
   403 		0.000000
   404 		-1
   405 		0
   406 		Default
   407 		0
   408 		*/
   409     prog->title = gmyth_string_list_get_string (slist, 0);
   410     prog->subtitle = gmyth_string_list_get_string (slist, 1);
   411     prog->description = gmyth_string_list_get_string (slist, 2);
   412     prog->category = gmyth_string_list_get_string (slist, 3);
   413     prog->chanid = gmyth_string_list_get_string (slist, 4);
   414     prog->chanstr = gmyth_string_list_get_string (slist, 5);
   415     prog->chansign = gmyth_string_list_get_string (slist, 6);
   416     prog->channame = gmyth_string_list_get_string (slist, 7);
   417     prog->pathname = gmyth_string_list_get_string (slist, 8);
   418     prog->filesize = gmyth_string_list_get_int64 (slist, 9);
   419     gmyth_string_list_get_int64 (slist, 10);
   420 
   421     prog->startts = gmyth_util_string_to_time_val( (gmyth_util_time_to_isoformat( 
   422     					(time_t)gmyth_string_list_get_int (slist, 11) ))->str ); //DATETIME_TO_LIST(startts)
   423     prog->endts = gmyth_util_string_to_time_val( (gmyth_util_time_to_isoformat( 
   424     					(time_t)gmyth_string_list_get_int (slist, 12) ))->str ); //DATETIME_TO_LIST(endts)
   425     prog->duplicate = gmyth_string_list_get_int (slist, 13);
   426     prog->shareable = gmyth_string_list_get_int (slist, 14);
   427     prog->findid = gmyth_string_list_get_int (slist, 15);
   428     prog->hostname = gmyth_string_list_get_string (slist, 16);
   429     prog->sourceid = gmyth_string_list_get_int (slist, 17);
   430     prog->cardid = gmyth_string_list_get_int (slist, 18);
   431     prog->inputid = gmyth_string_list_get_int (slist, 19);
   432     prog->recpriority = gmyth_string_list_get_int (slist, 20);
   433     prog->reactivate = gmyth_string_list_get_int (slist, 21);
   434     prog->recordid = gmyth_string_list_get_int (slist, 22);
   435     gmyth_string_list_get_int (slist, 23);
   436     gmyth_string_list_get_int (slist, 24);
   437     gmyth_string_list_get_int (slist, 25);
   438     prog->recstartts = gmyth_util_string_to_time_val( (gmyth_util_time_to_isoformat( 
   439     					(time_t)gmyth_string_list_get_int (slist, 26) ))->str ); //DATETIME_TO_LIST(recstartts)
   440     prog->recendts = gmyth_util_string_to_time_val( (gmyth_util_time_to_isoformat( 
   441     					(time_t)gmyth_string_list_get_int (slist, 27) ))->str ); //DATETIME_TO_LIST(recendts)
   442     prog->repeat = gmyth_string_list_get_int (slist, 28);
   443     prog->programflags = gmyth_string_list_get_int (slist, 29);
   444     prog->recgroup = gmyth_string_list_get_string (slist, 30); //prog->(recgroup != "") ? recgroup : "Default")
   445     prog->chancommfree = gmyth_string_list_get_int (slist, 31);
   446     prog->chanOutputFilters = gmyth_string_list_get_string (slist, 32);
   447     prog->seriesid = gmyth_string_list_get_string (slist, 33);
   448     prog->programid = gmyth_string_list_get_string (slist, 34);
   449     gmyth_string_list_get_string (slist, 35);
   450     prog->lastmodified = gmyth_util_string_to_time_val( (gmyth_util_time_to_isoformat( 
   451     					(time_t)gmyth_string_list_get_int (slist, 36) ))->str ); //DATETIME_TO_LIST(lastmodified)
   452     gmyth_string_list_get_int (slist, 37); //FLOAT_TO_LIST(stars)
   453     prog->originalAirDate = gmyth_util_string_to_time_val( (gmyth_util_time_to_isoformat( 
   454     					(time_t)gmyth_string_list_get_int (slist, 38) ))->str ); //DATETIME_TO_LIST(QDateTime(originalAirDate))
   455     prog->hasAirDate = gmyth_string_list_get_int (slist, 39);
   456     prog->playgroup = gmyth_string_list_get_string (slist, 40); //prog->(playgroup != "") ? playgroup : "Default")
   457     prog->recpriority2 = gmyth_string_list_get_int (slist, 41);
   458    
   459     return prog;
   460 }