[grilo-plugins] lua-factory: Add string member to OperationSpec struct



commit 2418b1e3919eb8b3fd14ae6694dff52a809b4325
Author: Bastien Nocera <hadess hadess net>
Date:   Sat Apr 19 13:43:04 2014 +0200

    lua-factory: Add string member to OperationSpec struct
    
    To be used to cache operation parameters.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=728882

 src/lua-factory/grl-lua-common.h  |    4 ++++
 src/lua-factory/grl-lua-factory.c |   12 +++++++++---
 src/lua-factory/grl-lua-library.c |    1 +
 3 files changed, 14 insertions(+), 3 deletions(-)
---
diff --git a/src/lua-factory/grl-lua-common.h b/src/lua-factory/grl-lua-common.h
index 42a947b..6042991 100644
--- a/src/lua-factory/grl-lua-common.h
+++ b/src/lua-factory/grl-lua-common.h
@@ -46,6 +46,9 @@ typedef enum {
 * @cb: union to user callback. The function parameters depends on operation.
 *      resolve is used for LUA_RESOLVE operations
 *      result is used for LUA_SEARCH, LUA_BROWSE and LUA_QUERY operations.
+* @string: The text to search for for LUA_SEARCH operations,
+*      the query for LUA_QUERY operations and the media ID for
+*      LUA_BROWSE operations.
 * @content: Save the current user media if already have one.
 * @user_data: User data passed in user defined callback.
 * @error_code: To set GRL_CORE_ERROR of the operation.
@@ -65,6 +68,7 @@ typedef struct _OperationSpec {
     GrlSourceResultCb result;
     GrlSourceResolveCb resolve;
   } cb;
+  char *string;
   GrlMedia *media;
   gpointer user_data;
   guint error_code;
diff --git a/src/lua-factory/grl-lua-factory.c b/src/lua-factory/grl-lua-factory.c
index e360ba1..8a5f7ef 100644
--- a/src/lua-factory/grl-lua-factory.c
+++ b/src/lua-factory/grl-lua-factory.c
@@ -983,11 +983,14 @@ grl_lua_factory_source_search (GrlSource *source,
 
   GRL_DEBUG ("grl_lua_factory_source_search");
 
+  text = (ss->text == NULL) ? "" : ss->text;
+
   os = g_slice_new0 (OperationSpec);
   os->source = ss->source;
   os->operation_id = ss->operation_id;
   os->cb.result = ss->callback;
   os->user_data = ss->user_data;
+  os->string = g_strdup (text);
   os->error_code = GRL_CORE_ERROR_SEARCH_FAILED;
   os->keys = g_list_copy (ss->keys);
   os->options = grl_operation_options_copy (ss->options);
@@ -997,7 +1000,6 @@ grl_lua_factory_source_search (GrlSource *source,
   grl_lua_library_set_current_operation (L, os->operation_id);
   lua_getglobal (L, LUA_SOURCE_OPERATION[LUA_SEARCH]);
 
-  text = (ss->text == NULL) ? "" : ss->text;
   lua_pushstring (L, text);
   if (lua_pcall (L, 1, 0, 0)) {
     GRL_WARNING ("%s '%s'", "calling search function fail:",
@@ -1019,12 +1021,15 @@ grl_lua_factory_source_browse (GrlSource *source,
 
   GRL_DEBUG ("grl_lua_factory_source_browse");
 
+  media_id = bs->container ? grl_media_get_id (bs->container) : NULL;
+
   os = g_slice_new0 (OperationSpec);
   os->source = bs->source;
   os->operation_id = bs->operation_id;
   os->media = bs->container;
   os->cb.result = bs->callback;
   os->user_data = bs->user_data;
+  os->string = g_strdup (media_id);
   os->error_code = GRL_CORE_ERROR_BROWSE_FAILED;
   os->keys = g_list_copy (bs->keys);
   os->options = grl_operation_options_copy (bs->options);
@@ -1034,7 +1039,6 @@ grl_lua_factory_source_browse (GrlSource *source,
   grl_lua_library_set_current_operation (L, os->operation_id);
   lua_getglobal (L, LUA_SOURCE_OPERATION[LUA_BROWSE]);
 
-  media_id = grl_media_get_id (os->media);
   lua_pushstring (L, media_id);
   if (lua_pcall (L, 1, 0, 0)) {
     GRL_WARNING ("%s '%s'", "calling browse function fail:",
@@ -1056,11 +1060,14 @@ grl_lua_factory_source_query (GrlSource *source,
 
   GRL_DEBUG ("grl_lua_factory_source_query");
 
+  query = (qs->query == NULL) ? "" : qs->query;
+
   os = g_slice_new0 (OperationSpec);
   os->source = qs->source;
   os->operation_id = qs->operation_id;
   os->cb.result = qs->callback;
   os->user_data = qs->user_data;
+  os->string = g_strdup (query);
   os->error_code = GRL_CORE_ERROR_QUERY_FAILED;
   os->keys = g_list_copy (qs->keys);
   os->options = grl_operation_options_copy (qs->options);
@@ -1070,7 +1077,6 @@ grl_lua_factory_source_query (GrlSource *source,
   grl_lua_library_set_current_operation (L, os->operation_id);
   lua_getglobal (L, LUA_SOURCE_OPERATION[LUA_QUERY]);
 
-  query = (qs->query == NULL) ? "" : qs->query;
   lua_pushstring (L, query);
   if (lua_pcall (L, 1, 0, 0)) {
     GRL_WARNING ("%s '%s'", "calling query function fail:",
diff --git a/src/lua-factory/grl-lua-library.c b/src/lua-factory/grl-lua-library.c
index 86337c4..2e19050 100644
--- a/src/lua-factory/grl-lua-library.c
+++ b/src/lua-factory/grl-lua-library.c
@@ -900,6 +900,7 @@ grl_l_callback (lua_State *L)
     g_object_unref (os->options);
     os->callback_done = TRUE;
     grl_lua_library_remove_operation_data (L, os->operation_id);
+    g_free (os->string);
     g_slice_free (OperationSpec, os);
   }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]