~ubuntu-branches/ubuntu/raring/libdmapsharing/raring

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*
 * Copyright (C) 2004,2005 Charles Schmidt <cschmidt2@emich.edu>
 * Copyright (C) 2006 INDT
 *  Andre Moreira Magalhaes <andre.magalhaes@indt.org.br>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include "config.h"

#include <libdmapsharing/dpap-connection.h>
#include <libdmapsharing/dmap-structure.h>

#define DPAP_CONNECTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), DPAP_TYPE_CONNECTION, DPAPConnectionPrivate))

/* FIXME:
struct DPAPConnectionPrivate {
};
*/

static DMAPContentCode
get_protocol_version_cc (DMAPConnection * connection)
{
	return DMAP_CC_PPRO;
}

static gchar *
get_query_metadata (DMAPConnection * connection)
{
	return g_strdup ("all");
}

static DMAPRecord *
handle_mlcl (DMAPConnection * connection, DMAPRecordFactory * factory,
	     GNode * n, int *item_id)
{
	GNode *n2;
	DMAPRecord *record = NULL;
	const gchar *filename = NULL;
	const gchar *aspect_ratio = NULL;
	const gchar *format = NULL;
	const gchar *comments = NULL;
	const gchar *thumbnail = NULL;
	GByteArray *ptr = NULL;
	gint creation_date = 0;
	gint filesize = 0;
	gint large_filesize = 0;
	gint height = 0;
	gint width = 0;
	gint rating = 0;

	for (n2 = n->children; n2; n2 = n2->next) {
		DMAPStructureItem *meta_item;

		meta_item = n2->data;

		switch (meta_item->content_code) {
		case DMAP_CC_MIID:
			*item_id = g_value_get_int (&(meta_item->content));
			break;
		case DMAP_CC_PIMF:
			filename = g_value_get_string (&(meta_item->content));
			break;
		case DMAP_CC_PASP:
			aspect_ratio =
				g_value_get_string (&(meta_item->content));
			break;
		case DMAP_CC_PICD:
			creation_date =
				g_value_get_int (&(meta_item->content));
			break;
		case DMAP_CC_PFMT:
			format = g_value_get_string (&(meta_item->content));
			break;
		case DMAP_CC_PIFS:
			filesize = g_value_get_int (&(meta_item->content));
			break;
		case DMAP_CC_PLSZ:
			large_filesize =
				g_value_get_int (&(meta_item->content));
			break;
		case DMAP_CC_PHGT:
			height = g_value_get_int (&(meta_item->content));
			break;
		case DMAP_CC_PWTH:
			width = g_value_get_int (&(meta_item->content));
			break;
		case DMAP_CC_PRAT:
			rating = g_value_get_int (&(meta_item->content));
			break;
		case DMAP_CC_PCMT:
			comments = g_value_get_string (&(meta_item->content));
			break;
		case DMAP_CC_PFDT:
			thumbnail =
				g_value_get_pointer (&(meta_item->content));
			break;
		default:
			break;
		}
	}

	record = dmap_record_factory_create (factory, NULL);
	if (record == NULL) {
		goto _return;
	}

	if (filesize) {
		ptr = g_byte_array_sized_new (filesize);
		g_byte_array_append (ptr, (guint8 *) thumbnail, filesize);
	} else {
		ptr = g_byte_array_sized_new (0);
	}

	g_object_set (record,
		      "filename", filename,
		      "aspect-ratio", aspect_ratio,
		      "creation-date", creation_date,
		      "format", format,
		      "large-filesize", large_filesize,
		      "pixel-height", height,
		      "pixel-width", width,
		      "rating", rating,
		      "comments", comments, "thumbnail", ptr, NULL);

	if (ptr) {
		g_byte_array_unref (ptr);
	}

      _return:
	return record;
}

static void
dpap_connection_class_init (DPAPConnectionClass * klass)
{
	GObjectClass *object_class = G_OBJECT_CLASS (klass);
	DMAPConnectionClass *parent_class =
		DMAP_CONNECTION_CLASS (object_class);

	parent_class->get_protocol_version_cc = get_protocol_version_cc;
	parent_class->get_query_metadata = get_query_metadata;
	parent_class->handle_mlcl = handle_mlcl;

	/* FIXME:
	 * g_type_class_add_private (klass, sizeof (DPAPConnectionPrivate));
	 */
}

DPAPConnection *
dpap_connection_new (const char *name,
		     const char *host,
		     guint port,
		     DMAPDb * db, DMAPRecordFactory * factory)
{
	DPAPConnection *connection;

	connection = g_object_new (DPAP_TYPE_CONNECTION,
				   "name", name,
				   "db", db,
				   "host", host,
				   "port", port, "factory", factory, NULL);

	return connection;
}

static void
dpap_connection_init (DPAPConnection * connection)
{
	/* FIXME: 
	 * connection->priv = DPAP_CONNECTION_GET_PRIVATE (connection);
	 */
}

G_DEFINE_TYPE (DPAPConnection, dpap_connection, DMAP_TYPE_CONNECTION);