gmyth/src/gmyth_recprofile.c
author renatofilho
Fri Feb 01 19:21:52 2008 +0000 (2008-02-01)
branchtrunk
changeset 907 9fa6794e53fb
parent 750 312d6bc514f3
permissions -rw-r--r--
[svn r913] fixed gmyth version on control packages
     1 /**
     2  * GMyth Library
     3  * 
     4  * @file gmyth/gmyth_recprofile.c
     5  * 
     6  * @brief <p> This file contains the recprofile class.
     7  *
     8  * Copyright (C) 2007 INdT - Instituto Nokia de Tecnologia.
     9  * @author Artur Duque de Souza <artur.souza@indt.org.br>
    10  *
    11  * This program is free software; you can redistribute it and/or modify
    12  * it under the terms of the GNU Lesser General Public License as published by
    13  * the Free Software Foundation; either version 2 of the License, or
    14  * (at your option) any later version.
    15  *
    16  * This program is distributed in the hope that it will be useful,
    17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    19  * GNU General Public License for more details.
    20  *
    21  * You should have received a copy of the GNU Lesser General Public License
    22  * along with this program; if not, write to the Free Software
    23  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    24  */
    25 
    26 
    27 #ifdef HAVE_CONFIG_H
    28 #include "config.h"
    29 #endif
    30 
    31 #include <stdlib.h>
    32 #include <string.h>
    33 #include <assert.h>
    34 
    35 #include "gmyth_recprofile.h"
    36 #include "gmyth_util.h"
    37 #include "gmyth_debug.h"
    38 #include "gmyth_http.h"
    39 
    40 static void     gmyth_recprofile_class_init(GMythRecProfileClass * klass);
    41 static void     gmyth_recprofile_init(GMythRecProfile * object);
    42 
    43 static void     gmyth_recprofile_dispose(GObject * object);
    44 static void     gmyth_recprofile_finalize(GObject * object);
    45 
    46 G_DEFINE_TYPE(GMythRecProfile, gmyth_recprofile, G_TYPE_OBJECT)
    47     static void     gmyth_recprofile_class_init(GMythRecProfileClass *
    48                                                 klass)
    49 {
    50     GObjectClass   *gobject_class = G_OBJECT_CLASS(klass);
    51 
    52     gobject_class->dispose = gmyth_recprofile_dispose;
    53     gobject_class->finalize = gmyth_recprofile_finalize;
    54 }
    55 
    56 static void
    57 gmyth_recprofile_init(GMythRecProfile * recprofile)
    58 {
    59 }
    60 
    61 static void
    62 gmyth_recprofile_dispose(GObject * object)
    63 {
    64     GMythRecProfile *recprofile = GMYTH_RECPROFILE(object);
    65 
    66     if (recprofile->name)
    67         g_free(recprofile->name);
    68 
    69     if (recprofile->group)
    70         g_free(recprofile->group);
    71 
    72     if (recprofile->vcodec)
    73         g_free(recprofile->vcodec);
    74 
    75     if (recprofile->acodec)
    76         g_free(recprofile->acodec);
    77 
    78     if (recprofile->options)
    79         g_free(recprofile->options);
    80 
    81     G_OBJECT_CLASS(gmyth_recprofile_parent_class)->dispose(object);
    82 }
    83 
    84 static void
    85 gmyth_recprofile_finalize(GObject * object)
    86 {
    87     g_signal_handlers_destroy(object);
    88     G_OBJECT_CLASS(gmyth_recprofile_parent_class)->finalize(object);
    89 }
    90 
    91 /**
    92  * Creates a new instance of GMythRecProfile.
    93  * 
    94  * @return a new instance of GMythRecProfile.
    95  **/
    96 GMythRecProfile *
    97 gmyth_recprofile_new(void)
    98 {
    99     GMythRecProfile *recprofile = GMYTH_RECPROFILE
   100         (g_object_new(GMYTH_RECPROFILE_TYPE, NULL));
   101 
   102     recprofile->id = 0;
   103     recprofile->name = NULL;
   104     recprofile->group = NULL;
   105     recprofile->vcodec = NULL;
   106     recprofile->acodec = NULL;
   107     recprofile->options = NULL;
   108 
   109     return recprofile;
   110 }
   111 
   112 
   113 /**
   114  *
   115  * gmyth_recprofile_get_profile_list
   116  * @brief get profile list from the backend
   117  * @param backend_info GMythBackendInfo*
   118  * @return GSList
   119  *
   120  **/
   121 GSList         *
   122 gmyth_recprofile_get_profile_list(GMythBackendInfo * backend_info)
   123 {
   124     return gmyth_http_retrieve_rec_profiles(backend_info, "Transcoders");
   125 }
   126 
   127 /**
   128  *
   129  * gmyth_recprofile_create_profile
   130  * @brief get profile list from the backend
   131  * @param backend_info GMythBackendInfo*
   132  * @param profile GMythRecProfile*
   133  * @return gint representing the result
   134  *
   135  **/
   136 gint
   137 gmyth_recprofile_create_profile(GMythBackendInfo * backend_info,
   138                                 GMythRecProfile * profile)
   139 {
   140     return gmyth_http_create_rec_profile(backend_info, profile);
   141 }
   142 
   143 /**
   144  *
   145  * gmyth_recprofile_del_profile
   146  * @brief del profile from the backend
   147  * @param backend_info GMythBackendInfo*
   148  * @param id profile's id
   149  * @return gint representing the result
   150  *
   151  **/
   152 gint
   153 gmyth_recprofile_del_profile_list(GMythBackendInfo * backend_info, gint id)
   154 {
   155     return gmyth_http_del_rec_profile(backend_info, id);
   156 }
   157 
   158 /**
   159  *
   160  * gmyth_recprofile_set_id
   161  * @brief set recprofile's id
   162  * @param rec GMythRecProfile*
   163  * @param id profile's id
   164  * @return gint representing the result
   165  *
   166  **/
   167 gint
   168 gmyth_recprofile_set_id(GMythRecProfile * rec, gint id)
   169 {
   170     rec->id = id;
   171     return 0;
   172 }
   173 
   174 /**
   175  *
   176  * gmyth_recprofile_set
   177  * @brief set recprofile's property
   178  * @param rec GMythRecProfile*
   179  * @param member the member you want to modify
   180  * @param value the value
   181  * @return gint representing the result
   182  *
   183  **/
   184 gint
   185 gmyth_recprofile_set(GMythRecProfile * rec, gchar * member, gchar * value)
   186 {
   187     int             ret = 0;
   188 
   189     if (value != NULL) {
   190         if (g_ascii_strcasecmp(member, "name") == 0)
   191             rec->name = g_strndup(value, strlen(value));
   192         else if (g_ascii_strcasecmp(member, "group") == 0)
   193             rec->group = g_strndup(value, strlen(value));
   194         else if (g_ascii_strcasecmp(member, "vcodec") == 0)
   195             rec->vcodec = g_strndup(value, strlen(value));
   196         else if (g_ascii_strcasecmp(member, "acodec") == 0)
   197             rec->acodec = g_strndup(value, strlen(value));
   198         else
   199             ret = -1;
   200     } else
   201         ret = -1;
   202 
   203     return ret;
   204 }
   205 
   206 /**
   207  *
   208  * gmyth_recprofile_set_name
   209  * @brief set recprofile's name
   210  * @param rec GMythRecProfile*
   211  * @param name profile's name
   212  * @return gint representing the result
   213  *
   214  **/
   215 gint
   216 gmyth_recprofile_set_name(GMythRecProfile * rec, gchar * name)
   217 {
   218     return gmyth_recprofile_set(rec, "name", name);
   219 }
   220 
   221 /**
   222  *
   223  * gmyth_recprofile_set_group
   224  * @brief set recprofile's group
   225  * @param rec GMythRecProfile*
   226  * @param group profile's group
   227  * @return gint representing the result
   228  *
   229  **/
   230 gint
   231 gmyth_recprofile_set_group(GMythRecProfile * rec, gchar * group)
   232 {
   233     return gmyth_recprofile_set(rec, "group", group);
   234 }
   235 
   236 /**
   237  *
   238  * gmyth_recprofile_set_vcodec
   239  * @brief set recprofile's vcodec
   240  * @param rec GMythRecProfile*
   241  * @param vcodec profile's vcodec
   242  * @return gint representing the result
   243  *
   244  **/
   245 gint
   246 gmyth_recprofile_set_vcodec(GMythRecProfile * rec, gchar * vcodec)
   247 {
   248     return gmyth_recprofile_set(rec, "vcodec", vcodec);
   249 }
   250 
   251 /**
   252  *
   253  * gmyth_recprofile_set_acodec
   254  * @brief set recprofile's acodec
   255  * @param rec GMythRecProfile*
   256  * @param acodec profile's acodec
   257  * @return gint representing the result
   258  *
   259  **/
   260 gint
   261 gmyth_recprofile_set_acodec(GMythRecProfile * rec, gchar * acodec)
   262 {
   263     return gmyth_recprofile_set(rec, "acodec", acodec);
   264 }