Commit 99fe355c authored by Carlos Garnacho's avatar Carlos Garnacho
Browse files

tracker3: Change title-from-filename handling

Set it afterwards, instead of relying on a second for the same
metadata key. This is the only place where this is needed and
can be easily handled in other ways.
parent 7f85b6c7
......@@ -84,9 +84,13 @@ static void
set_title_from_filename (GrlMedia *media)
{
const gchar *url;
gchar *path, *display_name, *ext, *title;
gchar *path, *display_name, *ext, *title = NULL;
guint suffix_len;
/* Prefer the real title */
if (grl_media_get_title (media))
return;
url = grl_media_get_url (media);
if (url == NULL)
return;
......@@ -97,19 +101,21 @@ set_title_from_filename (GrlMedia *media)
display_name = g_filename_display_basename (path);
g_free (path);
ext = strrchr (display_name, '.');
if (!ext)
goto out;
if (ext) {
suffix_len = strlen (ext);
if (suffix_len != 4 && suffix_len != 5)
goto out;
suffix_len = strlen (ext);
if (suffix_len != 4 && suffix_len != 5)
goto out;
title = g_strndup (display_name, ext - display_name);
} else {
title = g_strdup (display_name);
}
title = g_strndup (display_name, ext - display_name);
if (g_strcmp0 (grl_media_get_title (media), title) == 0)
grl_data_set_boolean (GRL_DATA (media), GRL_METADATA_KEY_TITLE_FROM_FILENAME, TRUE);
g_free (title);
grl_data_set_string (GRL_DATA (media), GRL_METADATA_KEY_TITLE, title);
grl_data_set_boolean (GRL_DATA (media), GRL_METADATA_KEY_TITLE_FROM_FILENAME, TRUE);
out:
g_free (title);
g_free (display_name);
}
......
......@@ -107,19 +107,6 @@ set_favourite (TrackerSparqlCursor *cursor,
grl_data_set_boolean (GRL_DATA (media), key, is_favourite);
}
static void
set_title_from_filename (TrackerSparqlCursor *cursor,
gint column,
GrlMedia *media,
GrlKeyID key)
{
const gchar *str = tracker_sparql_cursor_get_string (cursor, column, NULL);
if (key == GRL_METADATA_KEY_TITLE) {
grl_data_set_boolean (GRL_DATA (media), GRL_METADATA_KEY_TITLE_FROM_FILENAME, TRUE);
grl_media_set_title (media, str);
}
}
static void
set_title (TrackerSparqlCursor *cursor,
gint column,
......@@ -428,14 +415,6 @@ grl_tracker_setup_key_mappings (void)
GRL_TYPE_FILTER_ALL,
set_title);
insert_key_mapping_with_setter (GRL_METADATA_KEY_TITLE,
"fileName",
"nfo:fileName",
"nfo:fileName(?urn)",
"file",
GRL_TYPE_FILTER_ALL,
set_title_from_filename);
insert_key_mapping (GRL_METADATA_KEY_URL,
"url",
"nie:isStoredAs",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment