gmyth/src/gmyth_programinfo.c
author renatofilho
Wed Jan 23 20:04:22 2008 +0000 (2008-01-23)
branchtrunk
changeset 890 6b565181036e
parent 754 cb885ee44618
child 895 4bdd0f922b68
permissions -rw-r--r--
[svn r896] fixed channel_id, program_id types
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@890
   173
    if (gmyth_program_info->xx_program_id != NULL) {
renatofilho@890
   174
        g_string_free (gmyth_program_info->xx_program_id, TRUE);
renatofilho@890
   175
        gmyth_program_info->xx_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@890
   271
    gmyth_string_list_append_int (slist, prog->xx_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 */
renatofilho@754
   303
    gmyth_string_list_append_int(slist, 0 /* prog->recstatus */ );  /* 21 */
renatofilho@754
   304
    gmyth_string_list_append_int(slist, prog->recordid);    /* 22 */
renatofilho@754
   305
    gmyth_string_list_append_int(slist, 0 /* prog->rectype */ );    /* 23 */
renatofilho@754
   306
    gmyth_string_list_append_int(slist, 0 /* prog->dupin */ );  /* 24 */
renatofilho@754
   307
    gmyth_string_list_append_int(slist, 0 /* 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@890
   324
    gmyth_string_list_append_string(slist, prog->xx_program_id);    /* 34 */
renatofilho@754
   325
    gmyth_string_list_append_char_array(slist, ""); /* 35 */
renatofilho@754
   326
    gmyth_string_list_append_int(slist, prog->lastmodified != NULL ? prog->lastmodified->tv_sec : 0);   /* 36 
renatofilho@754
   327
     */// DATETIME_TO_LIST(lastmodified)
renatofilho@754
   328
    gmyth_string_list_append_int(slist, 0); /* 37 */// FLOAT_TO_LIST(stars)
renatofilho@754
   329
    gmyth_string_list_append_int(slist, prog->originalAirDate != NULL ? prog->originalAirDate->tv_sec : 0); /* 38 
renatofilho@754
   330
     */// DATETIME_TO_LIST(QDateTime(originalAirDate))
renatofilho@754
   331
    gmyth_string_list_append_int(slist, prog->hasAirDate);  /* 39 */
renatofilho@754
   332
    gmyth_string_list_append_char_array(slist, "Default");  /* 40 */// prog->(playgroup 
renatofilho@754
   333
                                                            // 
renatofilho@754
   334
    // 
renatofilho@754
   335
    // != "") ?
renatofilho@754
   336
    // playgroup : 
renatofilho@754
   337
    // "Default")
renatofilho@754
   338
    gmyth_string_list_append_int(slist, prog->recpriority2);    /* 41 */
rosfran@698
   339
renatofilho@754
   340
    return slist;
melunko@128
   341
}
melunko@128
   342
rosfran@420
   343
/**
rosfran@420
   344
 * Converts an instance of a GMythStringList, to a GMythProgramInfo.
rosfran@420
   345
 * 
rosfran@420
   346
 * @param slist The GMythStringList got from the MythTV backend server.
rosfran@568
   347
 * @param pos   The position in the GMythStringList to start getting the fields.
rosfran@568
   348
 * 
rosfran@568
   349
 * @return a GMythProgramInfo representing the string list got from network.
rosfran@568
   350
 */
rosfran@698
   351
GMythProgramInfo *
renatofilho@750
   352
gmyth_program_info_from_string_list_from_pos(GMythStringList * slist,
renatofilho@754
   353
                                             guint pos)
rosfran@568
   354
{
renatofilho@754
   355
    GMythProgramInfo *prog = gmyth_program_info_new();
rosfran@568
   356
renatofilho@754
   357
    g_return_val_if_fail(slist != NULL &&
renatofilho@754
   358
                         gmyth_string_list_get_string(slist, pos) != NULL,
renatofilho@754
   359
                         NULL);
rosfran@568
   360
renatofilho@754
   361
    prog->title = gmyth_string_list_get_string(slist, pos);
renatofilho@754
   362
    prog->subtitle = gmyth_string_list_get_string(slist, pos + 1);
renatofilho@754
   363
    prog->description = gmyth_string_list_get_string(slist, pos + 2);
renatofilho@754
   364
    prog->category = gmyth_string_list_get_string(slist, pos + 3);
renatofilho@890
   365
    prog->xx_channel_id = gmyth_string_list_get_int (slist, pos + 4);
renatofilho@754
   366
    prog->channame = gmyth_string_list_get_string(slist, pos + 5);
renatofilho@754
   367
    prog->chanstr = gmyth_string_list_get_string(slist, pos + 6);
renatofilho@754
   368
    prog->chansign = gmyth_string_list_get_string(slist, pos + 7);
renatofilho@754
   369
    prog->pathname = gmyth_string_list_get_string(slist, pos + 8);
rosfran@698
   370
renatofilho@754
   371
    prog->filesize = gmyth_string_list_get_int64(slist, pos + 9);
rosfran@698
   372
renatofilho@890
   373
    gmyth_debug("Prog info: [ %s, %s, %s, %s, %s, %s, %s, %s, %d ]\n",
renatofilho@754
   374
                gmyth_program_info_non_null_value(prog->title),
renatofilho@754
   375
                gmyth_program_info_non_null_value(prog->subtitle),
renatofilho@754
   376
                gmyth_program_info_non_null_value(prog->description),
renatofilho@754
   377
                gmyth_program_info_non_null_value(prog->category),
renatofilho@754
   378
                gmyth_program_info_non_null_value(prog->channame),
renatofilho@754
   379
                gmyth_program_info_non_null_value(prog->chanstr),
renatofilho@754
   380
                gmyth_program_info_non_null_value(prog->chansign),
renatofilho@754
   381
                gmyth_program_info_non_null_value(prog->pathname),
renatofilho@754
   382
                gmyth_string_list_get_int(slist, pos + 11));
rosfran@698
   383
renatofilho@754
   384
    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
   385
    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
   386
    prog->duplicate = gmyth_string_list_get_int(slist, pos + 13);
renatofilho@754
   387
    prog->shareable = gmyth_string_list_get_int(slist, pos + 14);
renatofilho@754
   388
    prog->findid = gmyth_string_list_get_int(slist, pos + 15);
renatofilho@754
   389
    prog->hostname = gmyth_string_list_get_string(slist, pos + 16);
renatofilho@754
   390
    prog->sourceid = gmyth_string_list_get_int(slist, pos + 17);
renatofilho@754
   391
    prog->cardid = gmyth_string_list_get_int(slist, pos + 18);
renatofilho@754
   392
    prog->inputid = gmyth_string_list_get_int(slist, pos + 19);
renatofilho@754
   393
    prog->recpriority = gmyth_string_list_get_int(slist, pos + 20);
renatofilho@754
   394
    prog->reactivate = gmyth_string_list_get_int(slist, pos + 21);
renatofilho@754
   395
    prog->recordid = gmyth_string_list_get_int(slist, pos + 22);
renatofilho@754
   396
    gmyth_string_list_get_int(slist, pos + 23);
renatofilho@754
   397
    gmyth_string_list_get_int(slist, pos + 24);
renatofilho@754
   398
    gmyth_string_list_get_int(slist, pos + 25);
renatofilho@754
   399
    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
   400
    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
   401
    prog->repeat = gmyth_string_list_get_int(slist, pos + 28);
renatofilho@754
   402
    prog->programflags = gmyth_string_list_get_int(slist, pos + 29);
renatofilho@754
   403
    prog->recgroup = gmyth_string_list_get_string(slist, pos + 30); // prog->(recgroup 
renatofilho@754
   404
                                                                    // 
renatofilho@754
   405
    // 
renatofilho@754
   406
    // !=
renatofilho@754
   407
    // "") 
renatofilho@754
   408
    // ?
renatofilho@754
   409
    // recgroup 
renatofilho@754
   410
    // :
renatofilho@754
   411
    // "Default")
renatofilho@754
   412
    prog->chancommfree = gmyth_string_list_get_int(slist, pos + 31);
renatofilho@754
   413
    prog->chanOutputFilters =
renatofilho@754
   414
        gmyth_string_list_get_string(slist, pos + 32);
renatofilho@754
   415
    prog->seriesid = gmyth_string_list_get_string(slist, pos + 33);
renatofilho@890
   416
    prog->xx_program_id = gmyth_string_list_get_string(slist, pos + 34);
renatofilho@754
   417
    gmyth_string_list_get_string(slist, pos + 35);
renatofilho@754
   418
    prog->lastmodified = gmyth_util_string_to_time_val((gmyth_util_time_to_isoformat((time_t) gmyth_string_list_get_int(slist, pos + 36)))->str);   // DATETIME_TO_LIST(lastmodified)
renatofilho@754
   419
    gmyth_string_list_get_int(slist, pos + 37); // FLOAT_TO_LIST(stars)
renatofilho@754
   420
    prog->originalAirDate = gmyth_util_string_to_time_val((gmyth_util_time_to_isoformat((time_t) gmyth_string_list_get_int(slist, pos + 38)))->str);    // DATETIME_TO_LIST(QDateTime(originalAirDate))
renatofilho@754
   421
    prog->hasAirDate = gmyth_string_list_get_int(slist, pos + 39);
renatofilho@754
   422
    prog->playgroup = gmyth_string_list_get_string(slist, pos + 40);    // prog->(playgroup 
renatofilho@754
   423
                                                                        // 
renatofilho@754
   424
    // 
renatofilho@754
   425
    // != 
renatofilho@754
   426
    // "") 
renatofilho@754
   427
    // ? 
renatofilho@754
   428
    // playgroup 
renatofilho@754
   429
    // : 
renatofilho@754
   430
    // "Default")
renatofilho@754
   431
    prog->recpriority2 = gmyth_string_list_get_int(slist, pos + 41);
rosfran@698
   432
renatofilho@754
   433
    return prog;
rosfran@568
   434
}
rosfran@568
   435
rosfran@568
   436
/**
rosfran@568
   437
 * Converts an instance of a GMythStringList, to a GMythProgramInfo.
rosfran@568
   438
 * 
rosfran@568
   439
 * @param slist The GMythStringList got from the MythTV backend server.
rosfran@420
   440
 * 
rosfran@420
   441
 * @return a GMythProgramInfo representing the string list got from network.
rosfran@420
   442
 */
rosfran@698
   443
GMythProgramInfo *
renatofilho@750
   444
gmyth_program_info_from_string_list(GMythStringList * slist)
melunko@128
   445
{
renatofilho@754
   446
    GMythProgramInfo *prog = NULL;
rosfran@568
   447
renatofilho@754
   448
    g_return_val_if_fail(slist != NULL, NULL);
rosfran@698
   449
renatofilho@754
   450
    prog = gmyth_program_info_from_string_list_from_pos(slist, 0);
rosfran@698
   451
renatofilho@754
   452
    return prog;
rosfran@568
   453
}
rosfran@568
   454
rosfran@568
   455
/**
rosfran@568
   456
 * Converts an instance of a GMythStringList, to a GMythProgramInfo ( NEXT_PROGRAM_INFO ).
rosfran@568
   457
 * 
rosfran@568
   458
 * @param slist The GMythStringList got from the MythTV backend server.
rosfran@568
   459
 * 
rosfran@568
   460
 * @return a GMythProgramInfo representing the string list got from network.
rosfran@568
   461
 */
rosfran@698
   462
GMythProgramInfo *
renatofilho@750
   463
gmyth_program_info_from_string_list_next_prog(GMythStringList * slist)
rosfran@568
   464
{
renatofilho@754
   465
    GMythProgramInfo *prog = gmyth_program_info_new();
rosfran@291
   466
renatofilho@754
   467
    g_return_val_if_fail(slist != NULL, NULL);
rosfran@698
   468
renatofilho@754
   469
    /*
renatofilho@754
   470
     * {Home Improvement[]:[]No, No, Godot[]:[] US sitcom about a
renatofilho@754
   471
     * DIY-obsessed father of three. When Tim tries to sell off his extra 
renatofilho@754
   472
     * ticket for an ice hockey game, he is arrested as a tout.[]:[]
renatofilho@754
   473
     * Sitcom[]:[]2007-04-18T15:30:00[]:[]2007-04-18T16:00:00[]:[]ABC1[]:[]
renatofilho@754
   474
     * /home/hmelo/.mythtv/channels/abc1.jpg[]:[]abc1[]:[]2000[]:[]25725844[]:[] 
renatofilho@754
   475
     * } 
renatofilho@754
   476
     */
leo_sobral@387
   477
renatofilho@754
   478
    prog->title = gmyth_string_list_get_string(slist, 0);
renatofilho@754
   479
    prog->subtitle = gmyth_string_list_get_string(slist, 1);
renatofilho@754
   480
    prog->description = gmyth_string_list_get_string(slist, 2);
renatofilho@754
   481
    prog->category = gmyth_string_list_get_string(slist, 3);
renatofilho@754
   482
    prog->startts = gmyth_util_string_to_time_val(gmyth_string_list_get_char_array(slist, 4));  // DATETIME_TO_LIST(startts)
renatofilho@754
   483
    prog->endts = gmyth_util_string_to_time_val(gmyth_string_list_get_char_array(slist, 5));    // DATETIME_TO_LIST(endts)
renatofilho@754
   484
    prog->channame = gmyth_string_list_get_string(slist, 6);
renatofilho@754
   485
    prog->chansign = gmyth_string_list_get_string(slist, 7);
renatofilho@754
   486
    prog->chanstr = gmyth_string_list_get_string(slist, 8);
renatofilho@890
   487
    prog->xx_channel_id = gmyth_string_list_get_int (slist, 9);
renatofilho@754
   488
    prog->filesize = gmyth_string_list_get_int64(slist, 10);
rosfran@698
   489
renatofilho@754
   490
    gmyth_debug
renatofilho@890
   491
        ("NEXT program info: [ %s, %s, %s, %s, %s, %s, %s, %s ]\n",
renatofilho@754
   492
         gmyth_program_info_non_null_value(prog->title),
renatofilho@754
   493
         gmyth_program_info_non_null_value(prog->subtitle),
renatofilho@754
   494
         gmyth_program_info_non_null_value(prog->description),
renatofilho@754
   495
         gmyth_program_info_non_null_value(prog->category),
renatofilho@754
   496
         gmyth_program_info_non_null_value(prog->channame),
renatofilho@754
   497
         gmyth_program_info_non_null_value(prog->chanstr),
renatofilho@754
   498
         gmyth_program_info_non_null_value(prog->chansign),
renatofilho@754
   499
         gmyth_program_info_non_null_value(prog->pathname));
rosfran@698
   500
renatofilho@754
   501
    return prog;
melunko@128
   502
}
rosfran@356
   503
rosfran@698
   504
static const gchar *
renatofilho@750
   505
gmyth_program_info_non_null_value(const GString * str)
rosfran@356
   506
{
renatofilho@754
   507
    return (str != NULL && str->str != NULL
renatofilho@754
   508
            && strlen(str->str) > 0 ? str->str : " ");
rosfran@356
   509
}
rosfran@356
   510
rosfran@420
   511
/**
rosfran@420
   512
 * Prints out an instance of a GMythProgramInfo.
rosfran@420
   513
 * 
rosfran@420
   514
 * @param prog A GMythProgramInfo instance.
rosfran@420
   515
 * 
rosfran@420
   516
 * @return a string representing the program info.
rosfran@420
   517
 */
renatofilho@754
   518
const gchar    *
renatofilho@750
   519
gmyth_program_info_to_string(const GMythProgramInfo * prog)
rosfran@356
   520
{
renatofilho@754
   521
    return
renatofilho@754
   522
        g_strdup_printf
renatofilho@890
   523
        ("Title: %s, Subtitle: %s, Description: %s, Category: %s, Channel ID: %d, "
renatofilho@754
   524
         "Channel Name: %s, Chan str: %s, Channel Sign: %s, Path Name: %s, File Size: %lld, \n"
renatofilho@754
   525
         "Start TS: %s, End TS: %s, Duplicate: %d, Shareable: %d, Find ID: %d, Hostname: %s, "
renatofilho@754
   526
         "Source ID: %d, Vard ID: %d, Input ID: %d, Rec Priority: %d, Reactivate: %d, \n"
renatofilho@754
   527
         "Record ID: %d, Rec Start TS: %s, Rec End TS: %s, Repeat: %d, Program Flags: %d, "
renatofilho@754
   528
         "Rec Group: %s, Channel Comm Free: %d, Channel Output Filters: %s, Series ID: %s, \n"
renatofilho@754
   529
         "Program ID: %s, Last Modified Date: %s, Original Air Date: %s, Has Air Date: %d, "
renatofilho@754
   530
         "Play Group: %s.\n",
renatofilho@754
   531
         gmyth_program_info_non_null_value(prog->title),
renatofilho@754
   532
         gmyth_program_info_non_null_value(prog->subtitle),
renatofilho@754
   533
         gmyth_program_info_non_null_value(prog->description),
renatofilho@754
   534
         gmyth_program_info_non_null_value(prog->category),
renatofilho@890
   535
         prog->xx_channel_id,
renatofilho@754
   536
         gmyth_program_info_non_null_value(prog->channame),
renatofilho@754
   537
         gmyth_program_info_non_null_value(prog->chanstr),
renatofilho@754
   538
         gmyth_program_info_non_null_value(prog->chansign),
renatofilho@754
   539
         gmyth_program_info_non_null_value(prog->pathname), prog->filesize,
renatofilho@754
   540
         gmyth_util_time_to_string_from_time_val(prog->startts),
renatofilho@754
   541
         gmyth_util_time_to_string_from_time_val(prog->endts),
renatofilho@754
   542
         prog->duplicate, prog->shareable, prog->findid,
renatofilho@754
   543
         gmyth_program_info_non_null_value(prog->hostname), prog->sourceid,
renatofilho@754
   544
         prog->cardid, prog->inputid, prog->recpriority, prog->reactivate,
renatofilho@754
   545
         prog->recordid,
renatofilho@754
   546
         gmyth_util_time_to_string_from_time_val(prog->recstartts),
renatofilho@754
   547
         gmyth_util_time_to_string_from_time_val(prog->recendts),
renatofilho@754
   548
         prog->repeat, prog->programflags,
renatofilho@754
   549
         gmyth_program_info_non_null_value(prog->recgroup),
renatofilho@754
   550
         prog->chancommfree,
renatofilho@754
   551
         gmyth_program_info_non_null_value(prog->chanOutputFilters),
renatofilho@754
   552
         gmyth_program_info_non_null_value(prog->seriesid),
renatofilho@890
   553
         gmyth_program_info_non_null_value(prog->xx_program_id),
renatofilho@754
   554
         gmyth_util_time_to_string_from_time_val(prog->lastmodified),
renatofilho@754
   555
         gmyth_util_time_to_string_from_time_val(prog->originalAirDate),
renatofilho@754
   556
         prog->hasAirDate,
renatofilho@754
   557
         gmyth_program_info_non_null_value(prog->playgroup));
rosfran@356
   558
}
rosfran@443
   559
rosfran@443
   560
/**
rosfran@443
   561
 * Say if an instance of a GMythProgramInfo is equals to another one.
rosfran@443
   562
 * 
rosfran@443
   563
 * @param prog The first GMythProgramInfo instance.
rosfran@443
   564
 * @param prog The second GMythProgramInfo instance.
rosfran@443
   565
 * 
rosfran@443
   566
 * @return <code>true</code>, if the program infos are equals.
rosfran@443
   567
 */
rosfran@443
   568
gboolean
renatofilho@750
   569
gmyth_program_info_is_equals(const GMythProgramInfo * prog1,
renatofilho@754
   570
                             const GMythProgramInfo * prog2)
rosfran@443
   571
{
renatofilho@754
   572
    if ((strcmp(gmyth_program_info_non_null_value(prog1->title),
renatofilho@754
   573
                gmyth_program_info_non_null_value(prog2->title)) == 0)
renatofilho@754
   574
        ||
renatofilho@754
   575
        (strcmp
renatofilho@754
   576
         (gmyth_program_info_non_null_value(prog1->pathname),
renatofilho@754
   577
          gmyth_program_info_non_null_value(prog2->pathname)) == 0))
renatofilho@754
   578
        return TRUE;
renatofilho@754
   579
    else
renatofilho@754
   580
        return FALSE;
rosfran@443
   581
rosfran@698
   582
}