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