[svn r260] Fixes references over libraries, such as the gmyth-0.1.
5 * @file gmyth/gmyth_backend_info.c
7 * Copyright (C) 2006 INdT - Instituto Nokia de Tecnologia.
8 * @author Hallyson Melo <hallyson.melo@indt.org.br>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #include "gmyth_backendinfo.h"
32 #include "gmyth_uri.h"
33 #include "gmyth_debug.h"
35 static void gmyth_backend_info_class_init (GMythBackendInfoClass *klass);
36 static void gmyth_backend_info_init (GMythBackendInfo *object);
38 static void gmyth_backend_info_dispose (GObject *object);
39 static void gmyth_backend_info_finalize (GObject *object);
41 G_DEFINE_TYPE(GMythBackendInfo, gmyth_backend_info, G_TYPE_OBJECT)
44 gmyth_backend_info_class_init (GMythBackendInfoClass *klass)
46 GObjectClass *gobject_class;
48 gobject_class = (GObjectClass *) klass;
50 gobject_class->dispose = gmyth_backend_info_dispose;
51 gobject_class->finalize = gmyth_backend_info_finalize;
55 gmyth_backend_info_init (GMythBackendInfo *backend_info)
57 backend_info->hostname = NULL;
58 backend_info->username = NULL;
59 backend_info->password = NULL;
60 backend_info->db_name = NULL;
61 backend_info->port = -1;
65 gmyth_backend_info_dispose (GObject *object)
67 GMythBackendInfo *backend_info = GMYTH_BACKEND_INFO (object);
69 g_free (backend_info->hostname);
70 g_free (backend_info->username);
71 g_free (backend_info->password);
72 g_free (backend_info->db_name);
74 backend_info->hostname = NULL;
75 backend_info->username = NULL;
76 backend_info->password = NULL;
77 backend_info->db_name = NULL;
78 backend_info->port = -1;
80 G_OBJECT_CLASS (gmyth_backend_info_parent_class)->dispose (object);
84 gmyth_backend_info_finalize (GObject *object)
86 g_signal_handlers_destroy (object);
88 G_OBJECT_CLASS (gmyth_backend_info_parent_class)->finalize (object);
91 /** Creates a new instance of GMythBackendInfo.
93 * @return a new instance of GMythBackendInfo.
96 gmyth_backend_info_new ()
98 GMythBackendInfo *backend_info =
99 GMYTH_BACKEND_INFO (g_object_new(GMYTH_BACKEND_INFO_TYPE, NULL));
105 gmyth_backend_info_new_full (const gchar *hostname, const gchar *username,
106 const gchar *password, const gchar *db_name, gint port)
108 GMythBackendInfo *backend_info =
109 GMYTH_BACKEND_INFO (g_object_new(GMYTH_BACKEND_INFO_TYPE, NULL));
111 gmyth_backend_info_set_hostname (backend_info, hostname);
112 gmyth_backend_info_set_username (backend_info, username);
113 gmyth_backend_info_set_password (backend_info, password);
114 gmyth_backend_info_set_db_name (backend_info, db_name);
115 gmyth_backend_info_set_port (backend_info, port);
121 gmyth_backend_info_new_with_uri ( const gchar *uri_str )
123 GMythBackendInfo *backend_info =
124 GMYTH_BACKEND_INFO (g_object_new(GMYTH_BACKEND_INFO_TYPE, NULL));
126 GMythURI* uri = gmyth_uri_new_with_value( uri_str );
128 gmyth_backend_info_set_hostname (backend_info, gmyth_uri_get_host (uri ) );
129 gmyth_backend_info_set_username (backend_info, gmyth_uri_get_user( uri ) );
130 gmyth_backend_info_set_password (backend_info, gmyth_uri_get_password( uri ) );
131 gmyth_backend_info_set_db_name (backend_info, strlen( gmyth_uri_get_fragment( uri ) ) > 0
132 ? gmyth_uri_get_fragment( uri ) : gmyth_uri_get_query( uri ) );
133 gmyth_backend_info_set_port (backend_info, gmyth_uri_get_port( uri ) );
139 gmyth_backend_info_set_hostname (GMythBackendInfo *backend_info, const gchar *hostname)
141 g_return_if_fail (backend_info != NULL);
143 if ( NULL == hostname || strlen(hostname) <= 0 )
145 gmyth_debug ( "Error trying to set a hostname equals to NULL (it doesn't using UPnP)." );
147 backend_info->hostname = g_strdup (hostname);
152 gmyth_backend_info_set_username (GMythBackendInfo *backend_info, const gchar *username)
154 g_return_if_fail (backend_info != NULL);
156 backend_info->username = g_strdup (username);
160 gmyth_backend_info_set_password (GMythBackendInfo *backend_info, const gchar *password)
162 g_return_if_fail (backend_info != NULL);
164 backend_info->password = g_strdup (password);
168 gmyth_backend_info_set_db_name (GMythBackendInfo *backend_info, const gchar *db_name)
170 g_return_if_fail (backend_info != NULL);
172 backend_info->db_name = g_strdup (db_name);
176 gmyth_backend_info_set_port (GMythBackendInfo *backend_info, const gint port )
178 g_return_if_fail (backend_info != NULL);
182 gmyth_debug ( "Error trying to set a hostname equals to NULL (it doesn't using UPnP)." );
184 backend_info->port = port;
189 gmyth_backend_info_get_hostname (GMythBackendInfo *backend_info)
191 g_return_val_if_fail (backend_info != NULL, NULL);
193 return backend_info->hostname;
197 gmyth_backend_info_get_username (GMythBackendInfo *backend_info)
199 g_return_val_if_fail (backend_info != NULL, NULL);
201 return backend_info->username;
205 gmyth_backend_info_get_password (GMythBackendInfo *backend_info)
207 g_return_val_if_fail (backend_info != NULL, NULL);
209 return backend_info->password;
213 gmyth_backend_info_get_db_name (GMythBackendInfo *backend_info)
215 g_return_val_if_fail (backend_info != NULL, NULL);
217 return backend_info->db_name;
221 gmyth_backend_info_get_port (GMythBackendInfo *backend_info)
223 g_return_val_if_fail (backend_info != NULL, -1);
225 return backend_info->port;