gmyth/gmyth/gmyth_programinfo.c
author ali@juiblex.co.uk
Wed Dec 16 10:06:21 2009 +0000 (2009-12-16)
branchtrunk
changeset 951 7b0d87ef5e63
parent 950 6308269b026e
permissions -rw-r--r--
Add rules and upcoming lists to gmyth_ls
     1 /**
     2  * GMyth Library
     3  *
     4  * @file gmyth/gmyth_programinfo.c
     5  * 
     6  * @brief <p> GMythProgramInfo representing the program info, with the
     7  * configuration data to the actual remote file in the TV chain.
     8  *
     9  * Copyright (C) 2006 INdT - Instituto Nokia de Tecnologia.
    10  * @author Rosfran Borges <rosfran.borges@indt.org.br>
    11  * @author Leonardo Sobral Cunha <leonardo.cunha@indt.org.br>
    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 *
    43                                               klass);
    44 static void     gmyth_program_info_init(GMythProgramInfo * object);
    45 
    46 static void     gmyth_program_info_dispose(GObject * object);
    47 static void     gmyth_program_info_finalize(GObject * object);
    48 
    49 G_DEFINE_TYPE(GMythProgramInfo, gmyth_program_info, G_TYPE_OBJECT)
    50     static const gchar *gmyth_program_info_non_null_value(const GString *
    51                                                           str);
    52 
    53     static void     gmyth_program_info_class_init(GMythProgramInfoClass *
    54                                                   klass)
    55 {
    56     GObjectClass   *gobject_class = G_OBJECT_CLASS(klass);
    57 
    58     gobject_class->dispose = gmyth_program_info_dispose;
    59     gobject_class->finalize = gmyth_program_info_finalize;
    60 }
    61 
    62 static void
    63 gmyth_program_info_init(GMythProgramInfo * gmyth_program_info)
    64 {
    65     gmyth_program_info->chancommfree = 0;
    66 
    67     /** A flag informing if the program has video or not. */
    68     gmyth_program_info->isVideo = FALSE;
    69     gmyth_program_info->lenMins = 0;
    70 
    71     gmyth_program_info->stars = 0.0f;
    72     gmyth_program_info->repeat = 0;
    73 
    74     gmyth_program_info->hasAirDate = FALSE;
    75 
    76     gmyth_program_info->spread = 0;
    77     gmyth_program_info->startCol = 0;
    78 
    79     gmyth_program_info->recpriority2 = 0;
    80     gmyth_program_info->reactivate = 0;
    81 
    82     gmyth_program_info->recordid = 0;
    83     gmyth_program_info->parentid = 0;
    84 
    85     /** The backend video source id associated to this program.*/
    86     gmyth_program_info->sourceid = 0;
    87     /** the backend input id associated to this program.*/
    88     gmyth_program_info->inputid = 0;
    89     /** The backend card id associated to this program.*/
    90     gmyth_program_info->cardid = 0;
    91     gmyth_program_info->shareable = FALSE;
    92     gmyth_program_info->duplicate = FALSE;
    93 
    94     gmyth_program_info->findid = 0;
    95 
    96     gmyth_program_info->programflags = 0;
    97     gmyth_program_info->transcoder = 0;
    98 
    99     gmyth_program_info->recpriority = 0;
   100 
   101     /** The file size of the recorded program.*/
   102     gmyth_program_info->filesize = -1;
   103 }
   104 
   105 static void
   106 gmyth_program_info_dispose(GObject * object)
   107 {
   108     GMythProgramInfo *gmyth_program_info = GMYTH_PROGRAM_INFO(object);
   109 
   110     /** The program start time. */
   111     g_free(gmyth_program_info->startts);
   112 
   113     /** The program end time. */
   114     g_free(gmyth_program_info->endts);
   115 
   116     /** The recording schedule start time. */
   117     g_free(gmyth_program_info->recstartts);
   118 
   119     /** The recording schedule end time */
   120     g_free(gmyth_program_info->recendts);
   121 
   122     /** The program title. */
   123     if (gmyth_program_info->title != NULL) {
   124         g_string_free(gmyth_program_info->title, TRUE);
   125         gmyth_program_info->title = NULL;
   126     }
   127 
   128     /** The program subtitle. */
   129     if (gmyth_program_info->subtitle != NULL) {
   130         g_string_free(gmyth_program_info->subtitle, TRUE);
   131         gmyth_program_info->subtitle = NULL;
   132     }
   133 
   134     /** The program description. */
   135     if (gmyth_program_info->description != NULL) {
   136         g_string_free(gmyth_program_info->description, TRUE);
   137         gmyth_program_info->description = NULL;
   138     }
   139 
   140     /** The program category. */
   141     if (gmyth_program_info->category != NULL) {
   142         g_string_free(gmyth_program_info->category, TRUE);
   143         gmyth_program_info->category = NULL;
   144     }
   145 
   146     if (gmyth_program_info->chanstr != NULL) {
   147         g_string_free(gmyth_program_info->chanstr, TRUE);
   148         gmyth_program_info->chanstr = NULL;
   149     }
   150 
   151     if (gmyth_program_info->chansign != NULL) {
   152         g_string_free(gmyth_program_info->chansign, TRUE);
   153         gmyth_program_info->chansign = NULL;
   154     }
   155 
   156     /** The associated channel name. */
   157     if (gmyth_program_info->channame != NULL) {
   158         g_string_free(gmyth_program_info->channame, TRUE);
   159         gmyth_program_info->channame = NULL;
   160     }
   161 
   162     if (gmyth_program_info->chanOutputFilters != NULL) {
   163         g_string_free(gmyth_program_info->chanOutputFilters, TRUE);
   164         gmyth_program_info->chanOutputFilters = NULL;
   165     }
   166 
   167     if (gmyth_program_info->seriesid != NULL) {
   168         g_string_free(gmyth_program_info->seriesid, TRUE);
   169         gmyth_program_info->chanOutputFilters = NULL;
   170     }
   171 
   172     /** The program unique id. */
   173     if (gmyth_program_info->program_id != NULL) {
   174         g_string_free (gmyth_program_info->program_id, TRUE);
   175         gmyth_program_info->program_id = NULL;
   176     }
   177 
   178     if (gmyth_program_info->catType != NULL) {
   179         g_string_free(gmyth_program_info->catType, TRUE);
   180         gmyth_program_info->catType = NULL;
   181     }
   182 
   183     if (gmyth_program_info->sortTitle != NULL) {
   184         g_string_free(gmyth_program_info->sortTitle, TRUE);
   185         gmyth_program_info->sortTitle = NULL;
   186     }
   187 
   188     if (gmyth_program_info->year != NULL) {
   189         g_string_free(gmyth_program_info->year, TRUE);
   190         gmyth_program_info->year = NULL;
   191     }
   192 
   193     g_free(gmyth_program_info->originalAirDate);
   194 
   195     g_free(gmyth_program_info->lastmodified);
   196 
   197     g_free(gmyth_program_info->lastInUseTime);
   198 
   199     if (gmyth_program_info->schedulerid != NULL) {
   200         g_string_free(gmyth_program_info->schedulerid, TRUE);
   201         gmyth_program_info->schedulerid = NULL;
   202     }
   203 
   204     if (gmyth_program_info->recgroup != NULL) {
   205         g_string_free(gmyth_program_info->recgroup, TRUE);
   206         gmyth_program_info->recgroup = NULL;
   207     }
   208 
   209     if (gmyth_program_info->playgroup != NULL) {
   210         g_string_free(gmyth_program_info->playgroup, TRUE);
   211         gmyth_program_info->playgroup = NULL;
   212     }
   213 
   214     /** The file name of the recorded program.*/
   215     if (gmyth_program_info->pathname != NULL) {
   216         g_string_free(gmyth_program_info->pathname, TRUE);
   217         gmyth_program_info->pathname = NULL;
   218     }
   219 
   220     if (gmyth_program_info->hostname != NULL) {
   221         g_string_free(gmyth_program_info->hostname, TRUE);
   222         gmyth_program_info->hostname = NULL;
   223     }
   224 
   225     G_OBJECT_CLASS(gmyth_program_info_parent_class)->dispose(object);
   226 }
   227 
   228 static void
   229 gmyth_program_info_finalize(GObject * object)
   230 {
   231     g_signal_handlers_destroy(object);
   232 
   233     G_OBJECT_CLASS(gmyth_program_info_parent_class)->finalize(object);
   234 }
   235 
   236 /**
   237  * Creates a new instance of GMythProgramInfo.
   238  * 
   239  * @return a new instance of GMythProgramInfo.
   240  */
   241 GMythProgramInfo *
   242 gmyth_program_info_new(void)
   243 {
   244     GMythProgramInfo *program_info =
   245         GMYTH_PROGRAM_INFO(g_object_new(GMYTH_PROGRAM_INFO_TYPE, NULL));
   246 
   247     return program_info;
   248 }
   249 
   250 /**
   251  * Converts an instance of a GMythProgramInfo, to a GMythStringList.
   252  * 
   253  * @param prog A GMythProgramInfo instance.
   254  * @param slist The GMythStringList to be passed to this function, in order to
   255  * 							give the responsibility of the string list creation to the
   256  * 						  API user.
   257  * 
   258  * @return a GMythStringList with the program info fields.
   259  */
   260 GMythStringList *
   261 gmyth_program_info_to_string_list(GMythProgramInfo * prog,
   262                                   GMythStringList * slist)
   263 {
   264     g_return_val_if_fail(prog != NULL, NULL);
   265     g_return_val_if_fail(slist != NULL, NULL);
   266 
   267     gmyth_string_list_append_string(slist, prog->title);    /* 0 */
   268     gmyth_string_list_append_string(slist, prog->subtitle); /* 1 */
   269     gmyth_string_list_append_string(slist, prog->description);  /* 2 */
   270     gmyth_string_list_append_string(slist, prog->category); /* 3 */
   271     gmyth_string_list_append_int (slist, prog->channel_id);   /* 4 */
   272     gmyth_string_list_append_string(slist, prog->chanstr);  /* 5 */
   273     gmyth_string_list_append_string(slist, prog->chansign); /* 6 */
   274     gmyth_string_list_append_string(slist, prog->channame); /* 7 */
   275     gmyth_string_list_append_string(slist, prog->pathname); /* 8 */
   276     gmyth_string_list_append_int64(slist, 0);   /* 9 */
   277 
   278     // fixme
   279     // gmyth_string_list_append_int64 (slist, 100/*prog->filesize*/); /* 9 
   280     // 
   281     // 
   282     // */
   283     // gmyth_string_list_append_int (slist, 0); /* 10 */
   284 
   285     if (prog->startts)
   286         gmyth_string_list_append_int(slist, prog->startts->tv_sec); /* 11 */// DATETIME_TO_LIST(startts)
   287     else
   288         gmyth_string_list_append_int(slist, 0);
   289 
   290     if (prog->endts)
   291         gmyth_string_list_append_int(slist, prog->endts->tv_sec);   /* 12 */// DATETIME_TO_LIST(endts)
   292     else
   293         gmyth_string_list_append_int(slist, 0);
   294 
   295     gmyth_string_list_append_int(slist, prog->duplicate);   /* 13 */
   296     gmyth_string_list_append_int(slist, prog->shareable);   /* 14 */
   297     gmyth_string_list_append_int(slist, prog->findid);  /* 15 */
   298     gmyth_string_list_append_string(slist, prog->hostname); /* 16 */
   299     gmyth_string_list_append_int(slist, prog->sourceid);    /* 17 */
   300     gmyth_string_list_append_int(slist, prog->cardid);  /* 18 */
   301     gmyth_string_list_append_int(slist, prog->inputid); /* 19 */
   302     gmyth_string_list_append_int(slist, prog->recpriority); /* 20 */
   303     gmyth_string_list_append_int(slist, prog->recstatus);  /* 21 */
   304     gmyth_string_list_append_int(slist, prog->recordid);    /* 22 */
   305     gmyth_string_list_append_int(slist, prog->rectype);    /* 23 */
   306     gmyth_string_list_append_int(slist, prog->dupin);  /* 24 */
   307     gmyth_string_list_append_int(slist, prog->dupmethod);  /* 25 */
   308     gmyth_string_list_append_int(slist, prog->recstartts != NULL ? prog->recstartts->tv_sec : 0);   /* 26 
   309      */// DATETIME_TO_LIST(recstartts)
   310     gmyth_string_list_append_int(slist, prog->recendts != NULL ? prog->recendts->tv_sec : 0);   /* 27 
   311      */// DATETIME_TO_LIST(recendts)
   312     gmyth_string_list_append_int(slist, prog->repeat);  /* 28 */
   313     gmyth_string_list_append_int(slist, prog->programflags);    /* 29 */
   314     gmyth_string_list_append_char_array(slist, "Default");  /* 30 */// prog->(recgroup 
   315                                                             // 
   316     // 
   317     // != "") ?
   318     // recgroup :
   319     // "Default")
   320     gmyth_string_list_append_int(slist, prog->chancommfree);    /* 31 */
   321     gmyth_string_list_append_string(slist, prog->chanOutputFilters);    /* 32 
   322                                                                          */
   323     gmyth_string_list_append_string(slist, prog->seriesid); /* 33 */
   324     gmyth_string_list_append_string(slist, prog->program_id);    /* 34 */
   325     gmyth_string_list_append_int(slist, prog->lastmodified != NULL ? prog->lastmodified->tv_sec : 0);   /* 35 */
   326     gmyth_string_list_append_int(slist, 0); /* 36: stars */
   327     gmyth_string_list_append_int(slist, prog->originalAirDate != NULL ? prog->originalAirDate->tv_sec : 0); /* 37 */
   328     gmyth_string_list_append_int(slist, prog->hasAirDate);  /* 38 */
   329     gmyth_string_list_append_char_array(slist, "Default");  /* 39: playgroup  */
   330     gmyth_string_list_append_int(slist, prog->recpriority2);    /* 40 */
   331     gmyth_string_list_append_int(slist, 0);    /* 41: parentid */
   332     gmyth_string_list_append_char_array(slist, "Default");    /* 42: storagegroup */
   333     gmyth_string_list_append_int(slist, 0);    /* 43: audioproperties */
   334     gmyth_string_list_append_int(slist, 0);    /* 44: videoproperties */
   335     gmyth_string_list_append_int(slist, 0);    /* 45: subtitleType */
   336     gmyth_string_list_append_char_array(slist, "");    /* 46: year */
   337 
   338     return slist;
   339 }
   340 
   341 /**
   342  * Converts an instance of a GMythStringList, to a GMythProgramInfo.
   343  * 
   344  * @param slist The GMythStringList got from the MythTV backend server.
   345  * @param pos   The position in the GMythStringList to start getting the fields.
   346  * 
   347  * @return a GMythProgramInfo representing the string list got from network.
   348  */
   349 GMythProgramInfo *
   350 gmyth_program_info_from_string_list_from_pos(GMythStringList * slist,
   351                                              guint pos)
   352 {
   353     GMythProgramInfo *prog = gmyth_program_info_new();
   354 
   355     g_return_val_if_fail(slist != NULL &&
   356                          gmyth_string_list_get_string(slist, pos) != NULL,
   357                          NULL);
   358 
   359     prog->title = gmyth_string_list_get_string(slist, pos);
   360     prog->subtitle = gmyth_string_list_get_string(slist, pos + 1);
   361     prog->description = gmyth_string_list_get_string(slist, pos + 2);
   362     prog->category = gmyth_string_list_get_string(slist, pos + 3);
   363     prog->channel_id = gmyth_string_list_get_int (slist, pos + 4);
   364     prog->channame = gmyth_string_list_get_string(slist, pos + 5);
   365     prog->chanstr = gmyth_string_list_get_string(slist, pos + 6);
   366     prog->chansign = gmyth_string_list_get_string(slist, pos + 7);
   367     prog->pathname = gmyth_string_list_get_string(slist, pos + 8);
   368 
   369     prog->filesize = gmyth_string_list_get_int64(slist, pos + 9);
   370 
   371     gmyth_debug("Prog info: [ %s, %s, %s, %s, %s, %s, %s, %s, %d ]\n",
   372                 gmyth_program_info_non_null_value(prog->title),
   373                 gmyth_program_info_non_null_value(prog->subtitle),
   374                 gmyth_program_info_non_null_value(prog->description),
   375                 gmyth_program_info_non_null_value(prog->category),
   376                 gmyth_program_info_non_null_value(prog->channame),
   377                 gmyth_program_info_non_null_value(prog->chanstr),
   378                 gmyth_program_info_non_null_value(prog->chansign),
   379                 gmyth_program_info_non_null_value(prog->pathname),
   380                 gmyth_string_list_get_int(slist, pos + 11));
   381 
   382     prog->startts = gmyth_util_string_to_time_val((gmyth_util_time_to_isoformat((time_t) gmyth_string_list_get_int(slist, pos + 11)))->str);    // DATETIME_TO_LIST(startts)
   383     prog->endts = gmyth_util_string_to_time_val((gmyth_util_time_to_isoformat((time_t) gmyth_string_list_get_int(slist, pos + 12)))->str);  // DATETIME_TO_LIST(endts)
   384     prog->duplicate = gmyth_string_list_get_int(slist, pos + 13);
   385     prog->shareable = gmyth_string_list_get_int(slist, pos + 14);
   386     prog->findid = gmyth_string_list_get_int(slist, pos + 15);
   387     prog->hostname = gmyth_string_list_get_string(slist, pos + 16);
   388     prog->sourceid = gmyth_string_list_get_int(slist, pos + 17);
   389     prog->cardid = gmyth_string_list_get_int(slist, pos + 18);
   390     prog->inputid = gmyth_string_list_get_int(slist, pos + 19);
   391     prog->recpriority = gmyth_string_list_get_int(slist, pos + 20);
   392     prog->recstatus = gmyth_string_list_get_int(slist, pos + 21);
   393     prog->reactivate = prog->recstatus;
   394     prog->recordid = gmyth_string_list_get_int(slist, pos + 22);
   395     prog->rectype = gmyth_string_list_get_int(slist, pos + 23);
   396     prog->dupin = gmyth_string_list_get_int(slist, pos + 24);
   397     prog->dupmethod = gmyth_string_list_get_int(slist, pos + 25);
   398     prog->recstartts = gmyth_util_string_to_time_val((gmyth_util_time_to_isoformat((time_t) gmyth_string_list_get_int(slist, pos + 26)))->str); // DATETIME_TO_LIST(recstartts)
   399     prog->recendts = gmyth_util_string_to_time_val((gmyth_util_time_to_isoformat((time_t) gmyth_string_list_get_int(slist, pos + 27)))->str);   // DATETIME_TO_LIST(recendts)
   400     prog->repeat = gmyth_string_list_get_int(slist, pos + 28);
   401     prog->programflags = gmyth_string_list_get_int(slist, pos + 29);
   402     prog->recgroup = gmyth_string_list_get_string(slist, pos + 30); // prog->(recgroup 
   403                                                                     // 
   404     // 
   405     // !=
   406     // "") 
   407     // ?
   408     // recgroup 
   409     // :
   410     // "Default")
   411     prog->chancommfree = gmyth_string_list_get_int(slist, pos + 31);
   412     prog->chanOutputFilters = gmyth_string_list_get_string(slist, pos + 32);
   413     prog->seriesid = gmyth_string_list_get_string(slist, pos + 33);
   414     prog->program_id = gmyth_string_list_get_string(slist, pos + 34);
   415     prog->lastmodified = gmyth_util_string_to_time_val((gmyth_util_time_to_isoformat((time_t) gmyth_string_list_get_int(slist, pos + 35)))->str);
   416     gmyth_string_list_get_int(slist, pos + 36); // FLOAT_TO_LIST(stars)
   417     prog->originalAirDate = gmyth_util_string_to_time_val((gmyth_util_time_to_isoformat((time_t) gmyth_string_list_get_int(slist, pos + 37)))->str);
   418     prog->hasAirDate = gmyth_string_list_get_int(slist, pos + 38);
   419     prog->playgroup = gmyth_string_list_get_string(slist, pos + 39);
   420     prog->recpriority2 = gmyth_string_list_get_int(slist, pos + 40);
   421     /* 41: parentid */
   422     /* 42: storagegroup */
   423     /* 43: audioproperties */
   424     /* 44: videoproperties */
   425     /* 45: subtitleType */
   426     /* 46: year */
   427 
   428     return prog;
   429 }
   430 
   431 /**
   432  * Converts an instance of a GMythStringList, to a GMythProgramInfo.
   433  * 
   434  * @param slist The GMythStringList got from the MythTV backend server.
   435  * 
   436  * @return a GMythProgramInfo representing the string list got from network.
   437  */
   438 GMythProgramInfo *
   439 gmyth_program_info_from_string_list(GMythStringList * slist)
   440 {
   441     GMythProgramInfo *prog = NULL;
   442 
   443     g_return_val_if_fail(slist != NULL, NULL);
   444 
   445     prog = gmyth_program_info_from_string_list_from_pos(slist, 0);
   446 
   447     return prog;
   448 }
   449 
   450 /**
   451  * Converts an instance of a GMythStringList, to a GMythProgramInfo ( NEXT_PROGRAM_INFO ).
   452  * 
   453  * @param slist The GMythStringList got from the MythTV backend server.
   454  * 
   455  * @return a GMythProgramInfo representing the string list got from network.
   456  */
   457 GMythProgramInfo *
   458 gmyth_program_info_from_string_list_next_prog(GMythStringList * slist)
   459 {
   460     GMythProgramInfo *prog = gmyth_program_info_new();
   461 
   462     g_return_val_if_fail(slist != NULL, NULL);
   463 
   464     /*
   465      * {Home Improvement[]:[]No, No, Godot[]:[] US sitcom about a
   466      * DIY-obsessed father of three. When Tim tries to sell off his extra 
   467      * ticket for an ice hockey game, he is arrested as a tout.[]:[]
   468      * Sitcom[]:[]2007-04-18T15:30:00[]:[]2007-04-18T16:00:00[]:[]ABC1[]:[]
   469      * /home/hmelo/.mythtv/channels/abc1.jpg[]:[]abc1[]:[]2000[]:[]25725844[]:[] 
   470      * } 
   471      */
   472 
   473     prog->title = gmyth_string_list_get_string(slist, 0);
   474     prog->subtitle = gmyth_string_list_get_string(slist, 1);
   475     prog->description = gmyth_string_list_get_string(slist, 2);
   476     prog->category = gmyth_string_list_get_string(slist, 3);
   477     prog->startts = gmyth_util_string_to_time_val(gmyth_string_list_get_char_array(slist, 4));  // DATETIME_TO_LIST(startts)
   478     prog->endts = gmyth_util_string_to_time_val(gmyth_string_list_get_char_array(slist, 5));    // DATETIME_TO_LIST(endts)
   479     prog->channame = gmyth_string_list_get_string(slist, 6);
   480     prog->chansign = gmyth_string_list_get_string(slist, 7);
   481     prog->chanstr = gmyth_string_list_get_string(slist, 8);
   482     prog->channel_id = gmyth_string_list_get_int (slist, 9);
   483     prog->filesize = gmyth_string_list_get_int64(slist, 10);
   484 
   485     gmyth_debug
   486         ("NEXT program info: [ %s, %s, %s, %s, %s, %s, %s, %s ]\n",
   487          gmyth_program_info_non_null_value(prog->title),
   488          gmyth_program_info_non_null_value(prog->subtitle),
   489          gmyth_program_info_non_null_value(prog->description),
   490          gmyth_program_info_non_null_value(prog->category),
   491          gmyth_program_info_non_null_value(prog->channame),
   492          gmyth_program_info_non_null_value(prog->chanstr),
   493          gmyth_program_info_non_null_value(prog->chansign),
   494          gmyth_program_info_non_null_value(prog->pathname));
   495 
   496     return prog;
   497 }
   498 
   499 static const gchar *
   500 gmyth_program_info_non_null_value(const GString * str)
   501 {
   502     return (str != NULL && str->str != NULL
   503             && strlen(str->str) > 0 ? str->str : " ");
   504 }
   505 
   506 /**
   507  * Prints out an instance of a GMythProgramInfo.
   508  * 
   509  * @param prog A GMythProgramInfo instance.
   510  * 
   511  * @return a string representing the program info.
   512  */
   513 const gchar    *
   514 gmyth_program_info_to_string(const GMythProgramInfo * prog)
   515 {
   516     return
   517         g_strdup_printf
   518         ("Title: %s, Subtitle: %s, Description: %s, Category: %s, Channel ID: %d, "
   519          "Channel Name: %s, Chan str: %s, Channel Sign: %s, Path Name: %s, File Size: %lld, \n"
   520          "Start TS: %s, End TS: %s, Duplicate: %d, Shareable: %d, Find ID: %d, Hostname: %s, "
   521          "Source ID: %d, Vard ID: %d, Input ID: %d, Rec Priority: %d, Reactivate: %d, \n"
   522          "Record ID: %d, Rec Start TS: %s, Rec End TS: %s, Repeat: %d, Program Flags: %d, "
   523          "Rec Group: %s, Channel Comm Free: %d, Channel Output Filters: %s, Series ID: %s, \n"
   524          "Program ID: %s, Last Modified Date: %s, Original Air Date: %s, Has Air Date: %d, "
   525          "Play Group: %s.\n",
   526          gmyth_program_info_non_null_value(prog->title),
   527          gmyth_program_info_non_null_value(prog->subtitle),
   528          gmyth_program_info_non_null_value(prog->description),
   529          gmyth_program_info_non_null_value(prog->category),
   530          prog->channel_id,
   531          gmyth_program_info_non_null_value(prog->channame),
   532          gmyth_program_info_non_null_value(prog->chanstr),
   533          gmyth_program_info_non_null_value(prog->chansign),
   534          gmyth_program_info_non_null_value(prog->pathname), prog->filesize,
   535          gmyth_util_time_to_string_from_time_val(prog->startts),
   536          gmyth_util_time_to_string_from_time_val(prog->endts),
   537          prog->duplicate, prog->shareable, prog->findid,
   538          gmyth_program_info_non_null_value(prog->hostname), prog->sourceid,
   539          prog->cardid, prog->inputid, prog->recpriority, prog->reactivate,
   540          prog->recordid,
   541          gmyth_util_time_to_string_from_time_val(prog->recstartts),
   542          gmyth_util_time_to_string_from_time_val(prog->recendts),
   543          prog->repeat, prog->programflags,
   544          gmyth_program_info_non_null_value(prog->recgroup),
   545          prog->chancommfree,
   546          gmyth_program_info_non_null_value(prog->chanOutputFilters),
   547          gmyth_program_info_non_null_value(prog->seriesid),
   548          gmyth_program_info_non_null_value(prog->program_id),
   549          gmyth_util_time_to_string_from_time_val(prog->lastmodified),
   550          gmyth_util_time_to_string_from_time_val(prog->originalAirDate),
   551          prog->hasAirDate,
   552          gmyth_program_info_non_null_value(prog->playgroup));
   553 }
   554 
   555 /**
   556  * Say if an instance of a GMythProgramInfo is equals to another one.
   557  * 
   558  * @param prog The first GMythProgramInfo instance.
   559  * @param prog The second GMythProgramInfo instance.
   560  * 
   561  * @return <code>true</code>, if the program infos are equals.
   562  */
   563 gboolean
   564 gmyth_program_info_is_equals(const GMythProgramInfo * prog1,
   565                              const GMythProgramInfo * prog2)
   566 {
   567     if ((strcmp(gmyth_program_info_non_null_value(prog1->title),
   568                 gmyth_program_info_non_null_value(prog2->title)) == 0)
   569         ||
   570         (strcmp
   571          (gmyth_program_info_non_null_value(prog1->pathname),
   572           gmyth_program_info_non_null_value(prog2->pathname)) == 0))
   573         return TRUE;
   574     else
   575         return FALSE;
   576 
   577 }