Commit 5e7f10e9 authored by Martyn James Russell's avatar Martyn James Russell

Added preprocessor checks for __LIBTRACKER_COMMON_INSIDE__ which were

	* src/libtracker-common/tracker-thumbnailer.h:
	* src/libtracker-common/tracker-albumart.h: Added preprocessor
	checks for __LIBTRACKER_COMMON_INSIDE__ which were missing.

	* src/libtracker-common/tracker-albumart.[ch]: 
	* src/tracker-extract/tracker-extract-mp3.c: Fixed coding style
	issues.

	* src/libtracker-common/tracker-albumart.[ch]: 
	* src/tracker-extract/tracker-extract-albumart.c:
	* src/tracker-extract/tracker-main.[ch]: Only create one
	TrackerHal object during the life time of tracker-extract instead
	of for EVERY file which has album art (which is quite a lot). This
	seems to be showing an increase of 2x the speed now for
	tracker-extract. 

	* src/tracker-indexer/tracker-main.c: (main): Added print
	statement like we have in the daemon so we know when the process
	is finished and returning to the cmd line.

	* tests/tracker-extract/tracker-extract-test-utils.c:
	(tracker_test_extract_file_access): Added tracker_main_get_hal()
	fixes to ensure the tests build.

svn path=/trunk/; revision=3185
parent ae7ee350
2009-04-07 Martyn Russell <martyn@imendio.com>
* src/libtracker-common/tracker-thumbnailer.h:
* src/libtracker-common/tracker-albumart.h: Added preprocessor
checks for __LIBTRACKER_COMMON_INSIDE__ which were missing.
* src/libtracker-common/tracker-albumart.[ch]:
* src/tracker-extract/tracker-extract-mp3.c: Fixed coding style
issues.
* src/libtracker-common/tracker-albumart.[ch]:
* src/tracker-extract/tracker-extract-albumart.c:
* src/tracker-extract/tracker-main.[ch]: Only create one
TrackerHal object during the life time of tracker-extract instead
of for EVERY file which has album art (which is quite a lot). This
seems to be showing an increase of 2x the speed now for
tracker-extract.
* src/tracker-indexer/tracker-main.c: (main): Added print
statement like we have in the daemon so we know when the process
is finished and returning to the cmd line.
* tests/tracker-extract/tracker-extract-test-utils.c:
(tracker_test_extract_file_access): Added tracker_main_get_hal()
fixes to ensure the tests build.
2009-04-07 Carlos Garnacho <carlos@imendio.com>
Propagate index errors up to the GUI, so the user has the opportunity
......
......@@ -55,8 +55,9 @@
#define THUMBNAILER_INTERFACE "org.freedesktop.thumbnailer.Generic"
typedef struct {
gchar *art_path;
gchar *local_uri;
TrackerHal *hal;
gchar *art_path;
gchar *local_uri;
} GetFileInfo;
static gboolean no_more_requesting = FALSE;
......@@ -66,18 +67,18 @@ my_compute_checksum_for_data (GChecksumType checksum_type,
const guchar *data,
gsize length)
{
GChecksum *checksum;
gchar *retval;
checksum = g_checksum_new (checksum_type);
if (!checksum)
return NULL;
g_checksum_update (checksum, data, length);
retval = g_strdup (g_checksum_get_string (checksum));
g_checksum_free (checksum);
return retval;
GChecksum *checksum;
gchar *retval;
checksum = g_checksum_new (checksum_type);
if (!checksum)
return NULL;
g_checksum_update (checksum, data, length);
retval = g_strdup (g_checksum_get_string (checksum));
g_checksum_free (checksum);
return retval;
}
#ifndef HAVE_STRCASESTR
......@@ -174,8 +175,6 @@ make_directory_with_parents (GFile *file,
return g_file_make_directory (file, cancellable, error);
}
static gchar*
strip_characters (const gchar *original)
{
......@@ -185,9 +184,7 @@ strip_characters (const gchar *original)
guint i = 0, y = 0;
while (i < osize) {
/* Remove (anything) */
if (original[i] == '(') {
gchar *loc = strchr (original+i, ')');
if (loc) {
......@@ -197,7 +194,6 @@ strip_characters (const gchar *original)
}
/* Remove [anything] */
if (original[i] == '[') {
gchar *loc = strchr (original+i, ']');
if (loc) {
......@@ -207,7 +203,6 @@ strip_characters (const gchar *original)
}
/* Remove {anything} */
if (original[i] == '{') {
gchar *loc = strchr (original+i, '}');
if (loc) {
......@@ -217,7 +212,6 @@ strip_characters (const gchar *original)
}
/* Remove <anything> */
if (original[i] == '<') {
gchar *loc = strchr (original+i, '>');
if (loc) {
......@@ -227,7 +221,6 @@ strip_characters (const gchar *original)
}
/* Remove double whitespaces */
if ((y > 0) &&
(original[i] == ' ' || original[i] == '\t') &&
(retval[y-1] == ' ' || retval[y-1] == '\t')) {
......@@ -236,7 +229,6 @@ strip_characters (const gchar *original)
}
/* Remove strange characters */
if (!strchr (foo, original[i])) {
retval[y] = original[i]!='\t'?original[i]:' ';
y++;
......@@ -250,31 +242,25 @@ strip_characters (const gchar *original)
return retval;
}
void
tracker_albumart_copy_to_local (const gchar *filename, const gchar *local_uri)
tracker_albumart_copy_to_local (TrackerHal *hal,
const gchar *filename,
const gchar *local_uri)
{
#ifdef HAVE_HAL
TrackerHal *hal;
#endif
GList *removable_roots, *l;
gboolean on_removable_device = FALSE;
guint flen;
if (!filename)
return;
if (!local_uri)
return;
g_return_if_fail (filename != NULL);
g_return_if_fail (local_uri != NULL);
flen = strlen (filename);
/* Determining if we are on a removable device */
#ifdef HAVE_HAL
hal = tracker_hal_new ();
g_return_if_fail (hal != NULL);
removable_roots = tracker_hal_get_removable_device_roots (hal);
g_object_unref (hal);
#else
removable_roots = g_list_append (removable_roots, "/media");
removable_roots = g_list_append (removable_roots, "/mnt");
......@@ -344,32 +330,31 @@ tracker_albumart_heuristic (const gchar *artist_,
gchar *album = NULL;
/* Copy from local album art (.mediaartlocal) to spec */
if (local_uri) {
GFile *local_file;
local_file = g_file_new_for_uri (local_uri);
if (g_file_query_exists (local_file, NULL)) {
tracker_albumart_get_path (artist, album,
"album", NULL,
&target, NULL);
file = g_file_new_for_path (target);
g_file_copy_async (local_file, file, 0, 0,
NULL, NULL, NULL, NULL, NULL);
g_object_unref (file);
GFile *local_file;
local_file = g_file_new_for_uri (local_uri);
if (g_file_query_exists (local_file, NULL)) {
tracker_albumart_get_path (artist, album,
"album", NULL,
&target, NULL);
file = g_file_new_for_path (target);
g_file_copy_async (local_file, file, 0, 0,
NULL, NULL, NULL, NULL, NULL);
g_object_unref (file);
g_object_unref (local_file);
*copied = TRUE;
g_free (target);
return TRUE;
}
g_object_unref (local_file);
*copied = TRUE;
g_free (target);
return TRUE;
}
g_object_unref (local_file);
}
*copied = FALSE;
......@@ -401,10 +386,13 @@ tracker_albumart_heuristic (const gchar *artist_,
tracks = -1;
}
if (artist_)
if (artist_) {
artist = strip_characters (artist_);
if (album_)
}
if (album_) {
album = strip_characters (album_);
}
/* If amount of files and amount of tracks in the album somewhat match */
......@@ -413,7 +401,6 @@ tracker_albumart_heuristic (const gchar *artist_,
gchar *found = NULL;
/* Try to find cover art in the directory */
for (name = g_dir_read_name (dir); name; name = g_dir_read_name (dir)) {
if ((artist && strcasestr (name, artist)) ||
(album && strcasestr (name, album)) ||
......@@ -484,8 +471,9 @@ tracker_albumart_heuristic (const gchar *artist_,
#endif /* HAVE_GDKPIXBUF */
}
if (retval)
if (retval) {
break;
}
}
}
......@@ -529,7 +517,6 @@ get_albumart_requester (void)
return albart_proxy;
}
static void
tracker_albumart_queue_cb (DBusGProxy *proxy,
DBusGProxyCall *call,
......@@ -561,12 +548,18 @@ tracker_albumart_queue_cb (DBusGProxy *proxy,
tracker_thumbnailer_queue_file (uri, "image/jpeg");
g_free (uri);
tracker_albumart_copy_to_local (info->art_path, info->local_uri);
tracker_albumart_copy_to_local (info->hal,
info->art_path,
info->local_uri);
}
g_free (info->art_path);
g_free (info->local_uri);
if (info->hal) {
g_object_unref (info->hal);
}
g_slice_free (GetFileInfo, info);
}
......@@ -598,15 +591,17 @@ tracker_albumart_get_path (const gchar *a,
return;
}
if (!a)
if (!a) {
f_a = g_strdup (" ");
else
} else {
f_a = strip_characters (a);
}
if (!b)
if (!b) {
f_b = g_strdup (" ");
else
f_b = strip_characters (b);
} else {
f_b = strip_characters (b);
}
down1 = g_utf8_strdown (f_a, -1);
down2 = g_utf8_strdown (f_b, -1);
......@@ -626,7 +621,10 @@ tracker_albumart_get_path (const gchar *a,
g_free (down1);
g_free (down2);
art_filename = g_strdup_printf ("%s-%s-%s.jpeg", prefix?prefix:"album", str1, str2);
art_filename = g_strdup_printf ("%s-%s-%s.jpeg",
prefix ? prefix : "album",
str1,
str2);
*path = g_build_filename (dir, art_filename, NULL);
......@@ -634,10 +632,11 @@ tracker_albumart_get_path (const gchar *a,
gchar *local_dir;
GFile *file, *parent;
if (strchr (uri, ':'))
if (strchr (uri, ':')) {
file = g_file_new_for_uri (uri);
else
file = g_file_new_for_path (uri);
} else {
file = g_file_new_for_path (uri);
}
parent = g_file_get_parent (file);
local_dir = g_file_get_uri (parent);
......@@ -657,18 +656,28 @@ tracker_albumart_get_path (const gchar *a,
}
void
tracker_albumart_request_download (const gchar *album,
tracker_albumart_request_download (TrackerHal *hal,
const gchar *album,
const gchar *artist,
const gchar *local_uri,
const gchar *art_path)
{
GetFileInfo *info;
if (no_more_requesting)
g_return_if_fail (hal != NULL);
if (no_more_requesting) {
return;
}
info = g_slice_new (GetFileInfo);
#ifdef HAVE_HAL
info->hal = g_object_ref (hal);
#else
info->hal = NULL;
#endif
info->local_uri = g_strdup (local_uri);
info->art_path = g_strdup (art_path);
......
......@@ -26,13 +26,20 @@
G_BEGIN_DECLS
#if !defined (__LIBTRACKER_COMMON_INSIDE__) && !defined (TRACKER_COMPILATION)
#error "only <libtracker-common/tracker-common.h> must be included directly."
#endif
#include "tracker-hal.h"
gboolean tracker_albumart_heuristic (const gchar *artist_,
const gchar *album_,
const gchar *tracks_str,
const gchar *filename,
const gchar *local_uri,
gboolean *copied);
void tracker_albumart_copy_to_local (const gchar *filename,
void tracker_albumart_copy_to_local (TrackerHal *hal,
const gchar *filename,
const gchar *local_uri);
void tracker_albumart_get_path (const gchar *a,
const gchar *b,
......@@ -40,7 +47,8 @@ void tracker_albumart_get_path (const gchar *a,
const gchar *uri,
gchar **path,
gchar **local);
void tracker_albumart_request_download (const gchar *album,
void tracker_albumart_request_download (TrackerHal *hal,
const gchar *album,
const gchar *artist,
const gchar *local_uri,
const gchar *art_path);
......
......@@ -26,6 +26,10 @@
G_BEGIN_DECLS
#if !defined (__LIBTRACKER_COMMON_INSIDE__) && !defined (TRACKER_COMPILATION)
#error "only <libtracker-common/tracker-common.h> must be included directly."
#endif
void tracker_thumbnailer_init (TrackerConfig *config);
void tracker_thumbnailer_shutdown (void);
void tracker_thumbnailer_queue_file (const gchar *path,
......
......@@ -40,6 +40,7 @@
#include <libtracker-common/tracker-common.h>
#include <libtracker-common/tracker-thumbnailer.h>
#include "tracker-main.h"
#include "tracker-extract-albumart.h"
#ifdef HAVE_GDKPIXBUF
......@@ -163,7 +164,8 @@ tracker_process_albumart (const unsigned char *buffer,
/* If the heuristic failed, we request the download
* of the media-art to the media-art downloaders */
lcopied = TRUE;
tracker_albumart_request_download (artist,
tracker_albumart_request_download (tracker_main_get_hal (),
artist,
album,
local_uri,
art_path);
......@@ -189,7 +191,9 @@ tracker_process_albumart (const unsigned char *buffer,
if (local_uri && !g_file_test (local_uri, G_FILE_TEST_EXISTS)) {
if (g_file_test (art_path, G_FILE_TEST_EXISTS))
tracker_albumart_copy_to_local (art_path, local_uri);
tracker_albumart_copy_to_local (tracker_main_get_hal (),
art_path,
local_uri);
}
g_free (art_path);
......
......@@ -286,13 +286,14 @@ static TrackerExtractData extract_data[] = {
/* Convert from UCS-2 to UTF-8 checking the BOM.*/
static gchar *
ucs2_to_utf8(const gchar *data, guint len) {
gchar *encoding = NULL;
guint16 c;
gboolean be;
gchar *utf8 = NULL;
ucs2_to_utf8 (const gchar *data, guint len)
{
gchar *encoding = NULL;
guint16 c;
gboolean be;
gchar *utf8 = NULL;
memcpy(&c, data, 2);
memcpy (&c, data, 2);
switch (c) {
case 0xfeff:
......@@ -308,7 +309,7 @@ ucs2_to_utf8(const gchar *data, guint len) {
break;
}
utf8 = g_convert(data, len, "UTF-8", encoding, NULL, NULL, NULL);
utf8 = g_convert (data, len, "UTF-8", encoding, NULL, NULL, NULL);
return utf8;
}
......@@ -323,15 +324,15 @@ get_genre_number (const char *str, guint *genre)
gchar *result = NULL;
if (!regex1)
regex1 = g_regex_new("\\(([0-9]+)\\)", 0, 0, NULL);
regex1 = g_regex_new ("\\(([0-9]+)\\)", 0, 0, NULL);
if (!regex2)
regex2 = g_regex_new("([0-9]+)\\z", 0, 0, NULL);
regex2 = g_regex_new ("([0-9]+)\\z", 0, 0, NULL);
if (g_regex_match(regex1, str, 0, &info)) {
result = g_match_info_fetch(info, 1);
if (g_regex_match (regex1, str, 0, &info)) {
result = g_match_info_fetch (info, 1);
if (result) {
*genre = atoi(result);
*genre = atoi (result);
g_free (result);
g_match_info_free (info);
return TRUE;
......@@ -340,10 +341,10 @@ get_genre_number (const char *str, guint *genre)
g_match_info_free (info);
if (g_regex_match(regex2, str, 0, &info)) {
result = g_match_info_fetch(info, 1);
if (g_regex_match (regex2, str, 0, &info)) {
result = g_match_info_fetch (info, 1);
if (result) {
*genre = atoi(result);
*genre = atoi (result);
g_free (result);
g_match_info_free (info);
return TRUE;
......@@ -367,13 +368,13 @@ un_unsync (const unsigned char *source,
*destination = g_malloc0 (size);
dest = *destination;
new_size = size;
new_size = size;
while (offset < size) {
*dest = source[offset];
if ( (source[offset] == 0xFF) &&
(source[offset+1] == 0x00) ) {
if ((source[offset] == 0xFF) &&
(source[offset+1] == 0x00)) {
offset++;
new_size--;
}
......@@ -518,7 +519,7 @@ mp3_parse_header (const gchar *data,
break;
}
switch (header&mpeg_layer_mask) {
switch (header & mpeg_layer_mask) {
case 0x400:
layer_ver = LAYER_2;
padsize = 1;
......@@ -555,7 +556,7 @@ mp3_parse_header (const gchar *data,
g_strdup ("Audio:Channels"),
g_strdup ("1"));
} else {
ch=2; /*stereo non stereo select*/
ch = 2; /* stereo non stereo select */
g_hash_table_insert (metadata,
g_strdup ("Audio:Channels"),
g_strdup ("2"));
......@@ -604,7 +605,7 @@ mp3_parse_header (const gchar *data,
memcpy(&header, &data[pos], sizeof (header));
} while ((header & sync_mask) == sync_mask);
if (frames<2) { /* At least 2 frames to check the right position */
if (frames < 2) { /* At least 2 frames to check the right position */
/* No valid frames */
return FALSE;
}
......@@ -643,15 +644,15 @@ mp3_parse (const gchar *data,
do {
/* Seek for frame start */
if (pos + sizeof(header) > size) {
if (pos + sizeof (header) > size) {
return;
}
memcpy (&header, &data[pos], sizeof (header));
if ((header&sync_mask) == sync_mask) {
if ((header & sync_mask) == sync_mask) {
/* Found header sync */
if (mp3_parse_header (data,size,pos,metadata)) {
if (mp3_parse_header (data, size, pos, metadata)) {
return;
}
}
......@@ -661,7 +662,6 @@ mp3_parse (const gchar *data,
} while (counter < MAX_MP3_SCAN_DEEP);
}
static void
get_id3v24_tags (const gchar *data,
size_t size,
......@@ -712,8 +712,8 @@ get_id3v24_tags (const gchar *data,
break;
}
flags = ( ((unsigned char)(data[pos + 8]) << 8) +
((unsigned char)(data[pos + 9]) ) );
flags = (((unsigned char) (data[pos + 8]) << 8) +
((unsigned char) (data[pos + 9])));
if (((flags & 0x80) > 0) ||
((flags & 0x40) > 0)) {
pos += 10 + csize;
......@@ -738,25 +738,25 @@ get_id3v24_tags (const gchar *data,
switch (data[pos + 10]) {
case 0x00:
word = g_convert(&data[pos+11],
csize-1,
"UTF-8",
"ISO-8859-1",
NULL, NULL, NULL);
word = g_convert (&data[pos+11],
csize-1,
"UTF-8",
"ISO-8859-1",
NULL, NULL, NULL);
break;
case 0x01 :
word = g_convert(&data[pos+11],
csize-1,
"UTF-8",
"UTF-16",
NULL, NULL, NULL);
word = g_convert (&data[pos+11],
csize-1,
"UTF-8",
"UTF-16",
NULL, NULL, NULL);
break;
case 0x02 :
word = g_convert(&data[pos+11],
csize-1,
"UTF-8",
"UTF-16BE",
NULL, NULL, NULL);
word = g_convert (&data[pos+11],
csize-1,
"UTF-8",
"UTF-16BE",
NULL, NULL, NULL);
break;
case 0x03 :
word = strndup (&data[pos+11], csize-1);
......@@ -767,11 +767,11 @@ get_id3v24_tags (const gchar *data,
* try to convert from
* iso-8859-1
*/
word = g_convert(&data[pos+11],
csize-1,
"UTF-8",
"ISO-8859-1",
NULL, NULL, NULL);
word = g_convert (&data[pos+11],
csize-1,
"UTF-8",
"ISO-8859-1",
NULL, NULL, NULL);
break;
}
......@@ -831,25 +831,25 @@ get_id3v24_tags (const gchar *data,
switch (text_encode) {
case 0x00:
word = g_convert(text,
csize-offset,
"UTF-8",
"ISO-8859-1",
NULL, NULL, NULL);
word = g_convert (text,
csize-offset,
"UTF-8",
"ISO-8859-1",
NULL, NULL, NULL);
break;
case 0x01 :
word = g_convert(text,
csize-offset,
"UTF-8",
"UTF-16",
NULL, NULL, NULL);
word = g_convert (text,
csize-offset,
"UTF-8",
"UTF-16",
NULL, NULL, NULL);
break;
case 0x02 :
word = g_convert(text,
csize-offset,
"UTF-8",
"UTF-16BE",
NULL, NULL, NULL);
word = g_convert (text,
csize-offset,
"UTF-8",
"UTF-16BE",
NULL, NULL, NULL);
break;
case 0x03 :
word = strndup (text, csize-offset);
......@@ -860,11 +860,11 @@ get_id3v24_tags (const gchar *data,
* try to convert from
* iso-8859-1
*/
word = g_convert(text,
csize-offset,
"UTF-8",
"ISO-8859-1",
NULL, NULL, NULL);
word = g_convert (text,
csize-offset,
"UTF-8",
"ISO-8859-1",
NULL, NULL, NULL);
break;
}
......@@ -892,9 +892,9 @@ get_id3v24_tags (const gchar *data,
pic_type = data[pos+11+strlen(mime)+1];
desc = &data[pos+11+strlen(mime)+1+1];
if ((pic_type == 3)||((pic_type == 0)&&(filedata->albumartsize == 0))) {
if ((pic_type == 3) || ((pic_type == 0) && (filedata->albumartsize == 0))) {
offset = pos+11+strlen(mime)+2+strlen(desc)+1;
offset = pos + 11 + strlen(mime) + 2 + strlen(desc) + 1;
filedata->albumartdata = g_malloc0 (csize);
memcpy (filedata->albumartdata, &data[offset], csize);
......@@ -955,8 +955,8 @@ get_id3v23_tags (const gchar *data,
break;
}
flags = ( ((unsigned char)(data[pos + 8]) << 8) +
((unsigned char)(data[pos + 9])) );
flags = (((unsigned char)(data[pos + 8]) << 8) +
((unsigned char)(data[pos + 9])));
if (((flags & 0x80) > 0) || ((flags & 0x40) > 0)) {
pos += 10 + csize;
......@@ -981,18 +981,18 @@ get_id3v23_tags (const gchar *data,
switch (data[pos + 10]) {
case 0x00:
word = g_convert(&data[pos+11],
csize-1,
"UTF-8",
"ISO-8859-1",
NULL, NULL, NULL);
word = g_convert (&data[pos+11],
csize-1,
"UTF-8",
"ISO-8859-1",
NULL, NULL, NULL);
break;
case 0x01 :
/* word = g_convert(&data[pos+11], */
/* csize-1, */