From 2469b942dd85f1863fa732bc11c23c0bf3cccf11 Mon Sep 17 00:00:00 2001 From: Qball Cow Date: Thu, 9 Feb 2012 19:53:50 +0100 Subject: [PATCH] Do the loading inside the fetcher thread. --- src/MetaData/metadata.c | 53 ++++++++++++++++++++++++++++++++++++++++++++----- src/gmpc-metaimage.gob | 52 ++++++++++++------------------------------------ 2 files changed, 61 insertions(+), 44 deletions(-) diff --git a/src/MetaData/metadata.c b/src/MetaData/metadata.c index 3ba02caf..4baa6983 100644 --- a/src/MetaData/metadata.c +++ b/src/MetaData/metadata.c @@ -549,6 +549,38 @@ static GlyrQuery *glyr_exit_handle = NULL; static GMutex *exit_handle_lock = NULL; /** + * Load a file from an URI + * + * @param mtd A meta_thread_data. + * + * Loads a file from a hard-drive. + * + * @returns nothing. + */ +static void glyr_fetcher_thread_load_uri(meta_thread_data *mtd) +{ + const char *path = meta_data_get_uri(mtd->met); + gchar *scheme = g_uri_parse_scheme(path); + + if(scheme == NULL || strcmp(scheme, "file") == 0) + { + char *content = NULL; + gsize length =0; + g_file_get_contents(path, &content,&length, NULL); + // Clean old content. + g_free(mtd->met->content); + // set it to raw. + mtd->met->content_type = META_DATA_CONTENT_RAW; + mtd->met->cache = glyr_cache_new(); + glyr_cache_set_data(mtd->met->cache, content, length); + mtd->met->content = g_memdup(content, length); + mtd->met->size = length; + content = NULL; + } + g_free(scheme); +} + +/** * Thread that does the GLYR requests */ void glyr_fetcher_thread(void *user_data) @@ -797,8 +829,17 @@ void glyr_fetcher_thread(void *user_data) glyr_db_delete(db, &query); printf("do delete done\n"); - // Set dummy entry in cache, so we know - // we searched for this before. + + // load data + if(mtd->met->cache == NULL) + { + if(meta_data_is_uri(mtd->met)) + { + glyr_fetcher_thread_load_uri(mtd); + } + } + + if(mtd->met->cache) { mtd->met->cache->rating = 9; @@ -971,7 +1012,7 @@ gboolean meta_compare_func(meta_thread_data *mt1, meta_thread_data *mt2) static int test_id = 0; -void meta_data_set_entry ( mpd_Song *song, MetaData *met) +void meta_data_set_entry ( mpd_Song *song, MetaData *met ) { if(song == NULL || met == NULL) { @@ -979,8 +1020,7 @@ void meta_data_set_entry ( mpd_Song *song, MetaData *met) return; } -// meta_thread_data *mtd = g_malloc0(sizeof(*mtd)); - meta_thread_data *mtd = g_slice_new0(meta_thread_data);//g_malloc0(sizeof(*mtd)); + meta_thread_data *mtd = g_slice_new0(meta_thread_data); mtd->action = MTD_ACTION_SET_ENTRY; mtd->id = ++test_id; /* Create a copy of the original song */ @@ -989,6 +1029,9 @@ void meta_data_set_entry ( mpd_Song *song, MetaData *met) mtd->type = met->type; /* set result NULL */ mtd->met = meta_data_dup(met);; + /* signal we are fetching. */ + gmpc_meta_watcher_data_changed(gmw,mtd->song, (mtd->type)&META_QUERY_DATA_TYPES, META_DATA_FETCHING,NULL); + /* Set entry */ printf("Request setting entry\n"); g_async_queue_push(gaq, mtd); mtd = NULL; diff --git a/src/gmpc-metaimage.gob b/src/gmpc-metaimage.gob index e896b810..1ac83d2f 100644 --- a/src/gmpc-metaimage.gob +++ b/src/gmpc-metaimage.gob @@ -250,31 +250,18 @@ class Gmpc:MetaImage from Gtk:Event:Box{ /* try to open it */ if(path && gdk_pixbuf_get_file_info(path, NULL,NULL)) - { - mpd_Song *song = mpd_songDup(self->_priv->song); - /* Create MetaData object */ - MetaData* met = meta_data_new(); - met->type = self->image_type; - met->plugin_name = g_strdup("User set"); - met->content_type = META_DATA_CONTENT_RAW; - met->content = NULL; - met->size = 0; - - char *content = NULL; - gsize length =0; - g_file_get_contents(path, &content,&length, NULL); - met->cache = glyr_cache_new(); - glyr_cache_set_data(met->cache, content, length); - met->content = g_memdup(content, length); - met->size = length; - content = NULL; - - meta_data_set_entry(song, met); + { + /* Create MetaData object */ + MetaData* met = meta_data_new(); + met->type = self->image_type; + met->plugin_name = g_strdup("User set"); + met->content_type = META_DATA_CONTENT_URI; + meta_data_set_uri(met, path); + + meta_data_set_entry(self->_priv->song, met); /* free Metadata object */ - meta_data_free(met); - found = TRUE; - mpd_freeSong(song); - } + meta_data_free(met); + } g_free(path); } g_strfreev(uri); @@ -843,29 +830,16 @@ class Gmpc:MetaImage from Gtk:Event:Box{ { gchar *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(fcd)); { - char *content = NULL; - gsize length =0; - - //mpd_Song *song = mpd_songDup(self->_priv->song); /* Create MetaData object */ MetaData* met = meta_data_new(); met->type = self->image_type; met->plugin_name = g_strdup("User set"); - met->content_type = META_DATA_CONTENT_RAW; - - - // set content. - met->cache = glyr_cache_new(); - g_file_get_contents(filename, &content,&length, NULL); - glyr_cache_set_data(met->cache, content, length); - met->content = g_memdup(content, length); - met->size = length; - content = NULL; + met->content_type = META_DATA_CONTENT_URI; + meta_data_set_uri(met, filename); meta_data_set_entry(self->_priv->song, met); /* free Metadata object */ meta_data_free(met); - //mpd_freeSong(song); cfg_set_single_value_as_string(config, "MetaData", "image-file-chooser", filename); } -- 2.11.4.GIT