4 * @file gmyth/gmyth_programinfo.c
6 * @brief <p> GMythProgramInfo representing the program info, with the
7 * configuration data to the actual remote file in the TV chain.
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>
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.
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.
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
38 #include "gmyth_programinfo.h"
39 #include "gmyth_util.h"
40 #include "gmyth_debug.h"
42 static void gmyth_program_info_class_init(GMythProgramInfoClass *
44 static void gmyth_program_info_init(GMythProgramInfo * object);
46 static void gmyth_program_info_dispose(GObject * object);
47 static void gmyth_program_info_finalize(GObject * object);
49 G_DEFINE_TYPE(GMythProgramInfo, gmyth_program_info, G_TYPE_OBJECT)
50 static const gchar *gmyth_program_info_non_null_value(const GString *
53 static void gmyth_program_info_class_init(GMythProgramInfoClass *
56 GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
58 gobject_class->dispose = gmyth_program_info_dispose;
59 gobject_class->finalize = gmyth_program_info_finalize;
63 gmyth_program_info_init(GMythProgramInfo * gmyth_program_info)
65 gmyth_program_info->chancommfree = 0;
67 /** A flag informing if the program has video or not. */
68 gmyth_program_info->isVideo = FALSE;
69 gmyth_program_info->lenMins = 0;
71 gmyth_program_info->stars = 0.0f;
72 gmyth_program_info->repeat = 0;
74 gmyth_program_info->hasAirDate = FALSE;
76 gmyth_program_info->spread = 0;
77 gmyth_program_info->startCol = 0;
79 gmyth_program_info->recpriority2 = 0;
80 gmyth_program_info->reactivate = 0;
82 gmyth_program_info->recordid = 0;
83 gmyth_program_info->parentid = 0;
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;
94 gmyth_program_info->findid = 0;
96 gmyth_program_info->programflags = 0;
97 gmyth_program_info->transcoder = 0;
99 gmyth_program_info->recpriority = 0;
101 /** The file size of the recorded program.*/
102 gmyth_program_info->filesize = -1;
106 gmyth_program_info_dispose(GObject * object)
108 GMythProgramInfo *gmyth_program_info = GMYTH_PROGRAM_INFO(object);
110 /** The program start time. */
111 g_free(gmyth_program_info->startts);
113 /** The program end time. */
114 g_free(gmyth_program_info->endts);
116 /** The recording schedule start time. */
117 g_free(gmyth_program_info->recstartts);
119 /** The recording schedule end time */
120 g_free(gmyth_program_info->recendts);
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;
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;
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;
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;
146 if (gmyth_program_info->chanstr != NULL) {
147 g_string_free(gmyth_program_info->chanstr, TRUE);
148 gmyth_program_info->chanstr = NULL;
151 if (gmyth_program_info->chansign != NULL) {
152 g_string_free(gmyth_program_info->chansign, TRUE);
153 gmyth_program_info->chansign = NULL;
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;
162 if (gmyth_program_info->chanOutputFilters != NULL) {
163 g_string_free(gmyth_program_info->chanOutputFilters, TRUE);
164 gmyth_program_info->chanOutputFilters = NULL;
167 if (gmyth_program_info->seriesid != NULL) {
168 g_string_free(gmyth_program_info->seriesid, TRUE);
169 gmyth_program_info->chanOutputFilters = NULL;
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;
178 if (gmyth_program_info->catType != NULL) {
179 g_string_free(gmyth_program_info->catType, TRUE);
180 gmyth_program_info->catType = NULL;
183 if (gmyth_program_info->sortTitle != NULL) {
184 g_string_free(gmyth_program_info->sortTitle, TRUE);
185 gmyth_program_info->sortTitle = NULL;
188 if (gmyth_program_info->year != NULL) {
189 g_string_free(gmyth_program_info->year, TRUE);
190 gmyth_program_info->year = NULL;
193 g_free(gmyth_program_info->originalAirDate);
195 g_free(gmyth_program_info->lastmodified);
197 g_free(gmyth_program_info->lastInUseTime);
199 if (gmyth_program_info->schedulerid != NULL) {
200 g_string_free(gmyth_program_info->schedulerid, TRUE);
201 gmyth_program_info->schedulerid = NULL;
204 if (gmyth_program_info->recgroup != NULL) {
205 g_string_free(gmyth_program_info->recgroup, TRUE);
206 gmyth_program_info->recgroup = NULL;
209 if (gmyth_program_info->playgroup != NULL) {
210 g_string_free(gmyth_program_info->playgroup, TRUE);
211 gmyth_program_info->playgroup = NULL;
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;
220 if (gmyth_program_info->hostname != NULL) {
221 g_string_free(gmyth_program_info->hostname, TRUE);
222 gmyth_program_info->hostname = NULL;
225 G_OBJECT_CLASS(gmyth_program_info_parent_class)->dispose(object);
229 gmyth_program_info_finalize(GObject * object)
231 g_signal_handlers_destroy(object);
233 G_OBJECT_CLASS(gmyth_program_info_parent_class)->finalize(object);
237 * Creates a new instance of GMythProgramInfo.
239 * @return a new instance of GMythProgramInfo.
242 gmyth_program_info_new(void)
244 GMythProgramInfo *program_info =
245 GMYTH_PROGRAM_INFO(g_object_new(GMYTH_PROGRAM_INFO_TYPE, NULL));
251 * Converts an instance of a GMythProgramInfo, to a GMythStringList.
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
258 * @return a GMythStringList with the program info fields.
261 gmyth_program_info_to_string_list(GMythProgramInfo * prog,
262 GMythStringList * slist)
264 g_return_val_if_fail(prog != NULL, NULL);
265 g_return_val_if_fail(slist != NULL, NULL);
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 */
279 // gmyth_string_list_append_int64 (slist, 100/*prog->filesize*/); /* 9
283 // gmyth_string_list_append_int (slist, 0); /* 10 */
286 gmyth_string_list_append_int(slist, prog->startts->tv_sec); /* 11 */// DATETIME_TO_LIST(startts)
288 gmyth_string_list_append_int(slist, 0);
291 gmyth_string_list_append_int(slist, prog->endts->tv_sec); /* 12 */// DATETIME_TO_LIST(endts)
293 gmyth_string_list_append_int(slist, 0);
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
320 gmyth_string_list_append_int(slist, prog->chancommfree); /* 31 */
321 gmyth_string_list_append_string(slist, prog->chanOutputFilters); /* 32
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 */
342 * Converts an instance of a GMythStringList, to a GMythProgramInfo.
344 * @param slist The GMythStringList got from the MythTV backend server.
345 * @param pos The position in the GMythStringList to start getting the fields.
347 * @return a GMythProgramInfo representing the string list got from network.
350 gmyth_program_info_from_string_list_from_pos(GMythStringList * slist,
353 GMythProgramInfo *prog = gmyth_program_info_new();
355 g_return_val_if_fail(slist != NULL &&
356 gmyth_string_list_get_string(slist, pos) != NULL,
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);
369 prog->filesize = gmyth_string_list_get_int64(slist, pos + 9);
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));
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
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);
422 /* 42: storagegroup */
423 /* 43: audioproperties */
424 /* 44: videoproperties */
425 /* 45: subtitleType */
432 * Converts an instance of a GMythStringList, to a GMythProgramInfo.
434 * @param slist The GMythStringList got from the MythTV backend server.
436 * @return a GMythProgramInfo representing the string list got from network.
439 gmyth_program_info_from_string_list(GMythStringList * slist)
441 GMythProgramInfo *prog = NULL;
443 g_return_val_if_fail(slist != NULL, NULL);
445 prog = gmyth_program_info_from_string_list_from_pos(slist, 0);
451 * Converts an instance of a GMythStringList, to a GMythProgramInfo ( NEXT_PROGRAM_INFO ).
453 * @param slist The GMythStringList got from the MythTV backend server.
455 * @return a GMythProgramInfo representing the string list got from network.
458 gmyth_program_info_from_string_list_next_prog(GMythStringList * slist)
460 GMythProgramInfo *prog = gmyth_program_info_new();
462 g_return_val_if_fail(slist != NULL, NULL);
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[]:[]
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);
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));
500 gmyth_program_info_non_null_value(const GString * str)
502 return (str != NULL && str->str != NULL
503 && strlen(str->str) > 0 ? str->str : " ");
507 * Prints out an instance of a GMythProgramInfo.
509 * @param prog A GMythProgramInfo instance.
511 * @return a string representing the program info.
514 gmyth_program_info_to_string(const GMythProgramInfo * prog)
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, "
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),
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,
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),
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),
552 gmyth_program_info_non_null_value(prog->playgroup));
556 * Say if an instance of a GMythProgramInfo is equals to another one.
558 * @param prog The first GMythProgramInfo instance.
559 * @param prog The second GMythProgramInfo instance.
561 * @return <code>true</code>, if the program infos are equals.
564 gmyth_program_info_is_equals(const GMythProgramInfo * prog1,
565 const GMythProgramInfo * prog2)
567 if ((strcmp(gmyth_program_info_non_null_value(prog1->title),
568 gmyth_program_info_non_null_value(prog2->title)) == 0)
571 (gmyth_program_info_non_null_value(prog1->pathname),
572 gmyth_program_info_non_null_value(prog2->pathname)) == 0))