4 * @file gmyth/gmyth_common.c
6 * @brief <p> This file contains basic common functions for the gmyth library.
8 * Copyright (C) 2006 INdT - Instituto Nokia de Tecnologia.
9 * @author Leonardo Sobral Cunha <leonardo.cunha@indt.org.br>
10 * @author Rosfran Borges <rosfran.borges@indt.org.br>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU Lesser General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU Lesser General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 #include "gmyth_common.h"
33 #include "gmyth_debug.h"
34 #include "gmyth_util.h"
36 static void free_channel_data(gpointer data, gpointer user_data);
37 static void free_program_data(gpointer data, gpointer user_data);
40 * Frees the memory allocated to the GMythChannelInfo objects inside list.
41 * The list memory is also released by g_list_free(). If LIST is NULL it
44 * @param list the GList containing a list of GMythChannelInfo to free.
47 gmyth_free_channel_list(GList * list)
49 g_return_if_fail(list != NULL);
51 g_list_foreach(list, free_channel_data, NULL);
56 * Frees the memory allocated to the GMythProgramInfo objects inside list.
57 * The list memory is also released by g_list_free(). If list is NULL it
60 * @param list the GList containing a list of GMythProgramInfo to free.
63 gmyth_free_program_list(GList * list)
65 g_return_if_fail(list != NULL);
67 g_list_foreach(list, free_program_data, NULL);
72 gmyth_channel_info_free(GMythChannelInfo * channel)
74 g_return_if_fail(channel != NULL);
76 if (channel->channel_num)
77 g_string_free(channel->channel_num, TRUE);
79 if (channel->channel_name)
80 g_string_free(channel->channel_name, TRUE);
82 if (channel->channel_icon)
83 g_string_free(channel->channel_icon, TRUE);
89 * Prints the channel info to the standard output. The gmyth debug must be enabled.
90 * @param channel_info the GMythChannelInfo instance
93 gmyth_channel_info_print(GMythChannelInfo * channel_info)
95 #ifdef GMYTH_USE_DEBUG
96 if (channel_info != NULL) {
97 g_return_if_fail(channel_info->channel_name != NULL);
98 g_return_if_fail(channel_info->channel_num != NULL);
100 gmyth_debug("ChannelInfo (Name, Num, ID) = (%s, %s, %d)",
101 channel_info->channel_name->str,
102 channel_info->channel_num->str,
103 channel_info->channel_ID);
110 * Prints the program info to the standard output. The gmyth debug must be enabled.
111 * @param channel_info the GMythProgramInfo instance
114 gmyth_program_info_print(GMythProgramInfo * program_info)
116 #ifdef GMYTH_USE_DEBUG
117 g_return_if_fail(program_info);
119 gmyth_debug("ProgramInfo\n\tTitle = %s\n\t"
120 "Description = %s\n\t"
124 "File size = %lld\n",
125 program_info->title ? program_info->title->str : "NULL",
126 program_info->description ? program_info->description->
128 gmyth_util_time_to_string_from_time_val(program_info->
130 gmyth_util_time_to_string_from_time_val(program_info->
132 program_info->pathname ? program_info->pathname->
133 str : "NULL", program_info->filesize);
138 free_channel_data(gpointer data, gpointer user_data)
141 * Frees the GMythChannelInfo structure
143 GMythChannelInfo *channel = (GMythChannelInfo *) data;
145 gmyth_channel_info_free(channel);
149 free_program_data(gpointer data, gpointer user_data)
151 g_return_if_fail(data != NULL);
153 g_object_unref((GMythProgramInfo *) data);