summaryrefslogtreecommitdiff
path: root/src/libtracker-extract/tracker-extract-info.c
blob: 90c2836f8f150e80986614118b57c639049dc074 (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
/*
 * 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
{
	TrackerResource *resource;

	GFile *file;
	gchar *mimetype;

#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)
{
	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->resource = 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);

		if (info->resource)
			g_object_unref (info->resource);

#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_resource:
 * @info: a #TrackerExtractInfo
 *
 * Returns the #TrackerResource representing metadata about the file
 * associated with this #TrackerExtractInfo, or %NULL if
 * tracker_extract_info_set_metadata() was not yet called.
 *
 * Returns: (transfer none): a #TrackerResource instance
 *
 * Since: 1.10
 */
TrackerResource *
tracker_extract_info_get_resource (TrackerExtractInfo *info)
{
	return info->resource;
}

/**
 * tracker_extract_info_set_resource:
 * @info: a #TrackerExtractInfo
 * @resource: a #TrackerResource
 *
 * Adds the #TrackerResource with results from the extraction to this
 * #TrackerExtractInfo.
 *
 * Information about the file itself should be represented by properties of
 * @resource itself. It's expected this resource will have nfo:FileDataObject
 * as one of its types. This @resource can have related resources attached to
 * it.
 *
 * In most cases, a file contains a single logical resource. Most MP3 files
 * contain one song, for example. In this case you set all properties on the
 * one @resource.
 *
 * In more complex cases, a single physical resource (i.e. a file) contains multiple
 * logical resources: for example, an MBOX file holding multiple emails, or
 * an audio file containing an entire CD. In this case you should treat each
 * logical resource as its own #TrackerResource. Only properties of the file
 * itself should be set on @resource. You then relate each logical
 * #TrackerResource to the main @resource using the nie:isStoredAs property.
 *
 * FIXME: you need a way to delete the logical resources when re-extracting a
 * file -- still need to decide on API for that.
 *
 * Since: 1.10
 **/
void
tracker_extract_info_set_resource (TrackerExtractInfo *info,
                                   TrackerResource    *resource)
{
	g_object_ref (resource);
	info->resource = resource;
}

#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 */