summaryrefslogtreecommitdiff
path: root/src/libtracker-extract/tracker-extract-info.c
blob: c534695dc6d8880799dc9423e691653f0ea165fc (plain)
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
/*
 * Copyright (C) 2011, Nokia <ivan.frade@nokia.com>
 *
 * 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 Street, Fifth Floor,
 * Boston, MA  02110-1301, USA.
 *
 * Author: Carlos Garnacho <carlos@lanedo.com>
 */

#include "config.h"

#include "tracker-extract-info.h"

/**
 * SECTION:tracker-extract-info
 * @title: TrackerExtractInfo
 * @short_description: struct used to pass information to and from
 *                     a Tracker extract module
 * @stability: Stable
 * @include: libtracker-extract/tracker-extract.h
 *
 * The #TrackerExtractInfo structure is used to pass information
 * on the file being extracted to an extractor module and contains
 * objects to hold the SPARQL updates generated by the extractor.
 **/


struct _TrackerExtractInfo
{
	TrackerSparqlBuilder *preupdate;
	TrackerSparqlBuilder *postupdate;
	TrackerSparqlBuilder *metadata;
	gchar *where_clause;

	GFile *file;
	gchar *mimetype;
	gchar *graph;
	gchar *urn;

#ifdef HAVE_LIBMEDIAART
	MediaArtProcess *media_art_process;
#endif

	gint ref_count;
};

G_DEFINE_BOXED_TYPE (TrackerExtractInfo, tracker_extract_info,
                     tracker_extract_info_ref, tracker_extract_info_unref)

/**
 * tracker_extract_info_new:
 * @file: a #GFile
 * @mimetype: mimetype for @file
 * @graph: SPARQL graph used for inserting data
 *
 * Returns a newly created #TrackerExtractInfo
 *
 * Returns: (transfer full): (boxed): A newly allocated #TrackerExtractInfo
 *
 * Since: 0.12
 **/
TrackerExtractInfo *
tracker_extract_info_new (GFile       *file,
                          const gchar *mimetype,
                          const gchar *graph,
                          const gchar *urn)
{
	TrackerExtractInfo *info;

	g_return_val_if_fail (G_IS_FILE (file), NULL);

	info = g_slice_new0 (TrackerExtractInfo);
	info->file = g_object_ref (file);
	info->mimetype = g_strdup (mimetype);
	info->graph = g_strdup (graph);
	info->urn = g_strdup (urn);

	info->preupdate = tracker_sparql_builder_new_update ();
	info->postupdate = tracker_sparql_builder_new_update ();
	info->metadata = tracker_sparql_builder_new_embedded_insert ();

        info->where_clause = NULL;

#ifdef HAVE_LIBMEDIAART
        info->media_art_process = NULL;
#endif

	info->ref_count = 1;

	return info;
}

/**
 * tracker_extract_info_ref:
 * @info: a #TrackerExtractInfo
 *
 * Increases the reference count of @info
 *
 * Returns: A new reference to @info
 *
 * Since: 0.12
 **/
TrackerExtractInfo *
tracker_extract_info_ref (TrackerExtractInfo *info)
{
	g_return_val_if_fail (info != NULL, NULL);

	g_atomic_int_inc (&info->ref_count);

	return info;
}

/**
 * tracker_extract_info_unref:
 * @info: a #TrackerExtractInfo
 *
 * Decreases the reference count of @info, freeing all its associated resources
 * if it reaches 0.
 *
 * Since: 0.12
 **/
void
tracker_extract_info_unref (TrackerExtractInfo *info)
{
	g_return_if_fail (info != NULL);

	if (g_atomic_int_dec_and_test (&info->ref_count)) {
		g_object_unref (info->file);
		g_free (info->mimetype);
		g_free (info->graph);
		g_free (info->urn);

		g_object_unref (info->preupdate);
		g_object_unref (info->postupdate);
		g_object_unref (info->metadata);
		g_free (info->where_clause);

#ifdef HAVE_LIBMEDIAART
		if (info->media_art_process)
			g_object_unref (info->media_art_process);
#endif

		g_slice_free (TrackerExtractInfo, info);
	}
}

/**
 * tracker_extract_info_get_file:
 * @info: a #TrackerExtractInfo
 *
 * Returns a #GFile pointing to the file being affected
 * by the metadata extraction represented by @info
 *
 * Returns: (transfer none): The file being inspected
 *
 * Since: 0.12
 **/
GFile *
tracker_extract_info_get_file (TrackerExtractInfo *info)
{
	g_return_val_if_fail (info != NULL, NULL);

	return info->file;
}

/**
 * tracker_extract_info_get_mimetype:
 * @info: a #TrackerExtractInfo
 *
 * Returns the mimetype being used for the file
 * metadata extraction.
 *
 * Returns: (transfer none): the mimetype being used
 *          for extraction.
 *
 * Since: 0.12
 **/
const gchar *
tracker_extract_info_get_mimetype (TrackerExtractInfo *info)
{
	g_return_val_if_fail (info != NULL, NULL);

	return info->mimetype;
}

/**
 * tracker_extract_info_get_graph:
 * @info: a #TrackerExtractInfo
 *
 * Returns the SPARQL graph that will be used when
 * inserting metadata.
 *
 * Returns: (transfer none): The SPARQL graph the extract
 *          operation belongs to.
 *
 * Since: 0.12
 **/
const gchar *
tracker_extract_info_get_graph (TrackerExtractInfo *info)
{
	g_return_val_if_fail (info != NULL, NULL);

	return info->graph;
}

/**
 * tracker_extract_info_get_preupdate_builder:
 * @info: a #TrackerExtractInfo
 *
 * Returns a #TrackerSparqlBuilder containing any
 * separate updates that could apply to the file,
 * such as author/band information in audio files,
 * and so on.
 *
 * Returns: (transfer none): miscellaneous metadata
 *
 * Since: 0.12
 **/
TrackerSparqlBuilder *
tracker_extract_info_get_preupdate_builder (TrackerExtractInfo *info)
{
	g_return_val_if_fail (info != NULL, NULL);

	return info->preupdate;
}

/**
 * tracker_extract_info_get_postupdate_builder:
 * @info: a #TrackerExtractInfo
 *
 * Returns a #TrackerSparqlBuilder containing separate
 * updates for resources that are contained within the file
 * and need to refer to it.
 *
 * Returns: (transfer none): #TrackerSparqlBuilder for
 * resources that need inserting after the file resource.
 *
 * Since: 0.12.4
 **/
TrackerSparqlBuilder *
tracker_extract_info_get_postupdate_builder (TrackerExtractInfo *info)
{
	g_return_val_if_fail (info != NULL, NULL);

	return info->postupdate;
}

/**
 * tracker_extract_info_get_metadata_builder:
 * @info: a #TrackerExtractInfo
 *
 * Returns a #TrackerSparqlBuilder containing the
 * file metadata.
 *
 * Returns: (transfer none): the file metadata
 *
 * Since: 0.12
 **/
TrackerSparqlBuilder *
tracker_extract_info_get_metadata_builder (TrackerExtractInfo *info)
{
	g_return_val_if_fail (info != NULL, NULL);

	return info->metadata;
}

/**
 * tracker_extract_info_get_where_clause:
 * @info: a #TrackerExtractInfo
 *
 * Returns the where clause that will apply to the
 * other metadata contained in @info.
 *
 * Returns: (transfer none): The where clause
 *
 * Since: 0.12
 **/
const gchar *
tracker_extract_info_get_where_clause (TrackerExtractInfo *info)
{
	g_return_val_if_fail (info != NULL, NULL);

	return info->where_clause;
}

/**
 * tracker_extract_info_set_where_clause:
 * @info: a #TrackerExtractInfo
 * @where: Where clause for the file update.
 *
 * Sets the where clause for the returned metadata.
 *
 * Since: 0.12
 **/
void
tracker_extract_info_set_where_clause (TrackerExtractInfo *info,
                                       const gchar        *where)
{
	g_return_if_fail (info != NULL);

	g_free (info->where_clause);
	info->where_clause = g_strdup (where);
}

const gchar *
tracker_extract_info_get_urn (TrackerExtractInfo *info)
{
	g_return_val_if_fail (info != NULL, NULL);

	return info->urn;
}

#ifdef HAVE_LIBMEDIAART

/**
 * tracker_extract_info_get_media_art_process:
 * @info: a #TrackerExtractInfo
 *
 * Returns the #MediaArtProcess object that can be used to retrieve
 * and store media art caches found in extracted content.
 *
 * Returns: (transfer none): The #MediaArtProcess. This object should
 * not be unreferenced.
 *
 * Since: 1.2
 **/
MediaArtProcess *
tracker_extract_info_get_media_art_process (TrackerExtractInfo *info)
{
	g_return_val_if_fail (info != NULL, NULL);
	return info->media_art_process;
}

/**
 * tracker_extract_info_set_media_art_process:
 * @info: a #TrackerExtractInfo
 * @media_art_process: a #MediaArtProcess.
 *
 * Use @media_art_process for caching and looking up media art.
 *
 * Since: 1.2
 **/
void
tracker_extract_info_set_media_art_process (TrackerExtractInfo *info,
                                            MediaArtProcess    *media_art_process)
{
	g_return_if_fail (info != NULL);
	g_return_if_fail (MEDIA_ART_IS_PROCESS (media_art_process));

	if (info->media_art_process) {
		g_object_unref (info->media_art_process);
	}

	info->media_art_process = g_object_ref (media_art_process);
}

#endif /* HAVE_LIBMEDIAART */