[grilo-plugins] Revert "lua-factory: change grl.get_media_keys() into the static table"



commit 500935d069fb622946d2e67f7a2882757e2e4456
Author: Victor Toso <me victortoso com>
Date:   Tue Mar 8 22:56:35 2016 +0100

    Revert "lua-factory: change grl.get_media_keys() into the static table"
    
    In order to keep the previous API between Lua sources and Lua-Factory.
    
    This reverts commit 3e409b7727f803e2be4427c7544c679373a7d926.
    
    This breaks the current plugins by changing the static table passed as
    argument back grl.get_media_keys()
    
    After applying this patch, it will break the lua sources due the API
    change.  We are not passing an static table as GrlMedia anymore. Lua
    sources should use grl.get_media_keys().
    
    This is not 100% revert. We are keeping some fixes that was introduced
    together with the api change for grilo-0.3 on grl.get_media_keys such as
    using GrlMedia instead of specific types for audio, video, image and box
    (which is now container)
    
    https://bugzilla.gnome.org/show_bug.cgi?id=763046

 src/lua-factory/grl-lua-common.h  |    1 -
 src/lua-factory/grl-lua-factory.c |    9 ++++++---
 src/lua-factory/grl-lua-library.c |   22 ++++++++++++----------
 3 files changed, 18 insertions(+), 14 deletions(-)
---
diff --git a/src/lua-factory/grl-lua-common.h b/src/lua-factory/grl-lua-common.h
index 9137461..15564b0 100644
--- a/src/lua-factory/grl-lua-common.h
+++ b/src/lua-factory/grl-lua-common.h
@@ -89,7 +89,6 @@ typedef struct _OperationSpec {
 void grl_lua_library_save_goa_data (lua_State *L, gpointer goa_object);
 gpointer grl_lua_library_load_goa_data (lua_State *L);
 
-void grl_lua_library_push_grl_media (lua_State *L, GrlMedia *media);
 void grl_lua_library_push_grl_options (lua_State *L, guint operation_id, GrlOperationOptions *options, GList 
*keys);
 
 /* grl-lua-library-operations */
diff --git a/src/lua-factory/grl-lua-factory.c b/src/lua-factory/grl-lua-factory.c
index 61a2d65..b078c3c 100644
--- a/src/lua-factory/grl-lua-factory.c
+++ b/src/lua-factory/grl-lua-factory.c
@@ -1543,12 +1543,16 @@ grl_lua_factory_source_browse (GrlSource *source,
   lua_State *L = lua_source->priv->l_st;
   OperationSpec *os = NULL;
   GError *err = NULL;
+  const gchar *media_id = NULL;
 
   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->error_code = GRL_CORE_ERROR_BROWSE_FAILED;
@@ -1556,7 +1560,7 @@ grl_lua_factory_source_browse (GrlSource *source,
 
   lua_getglobal (L, LUA_SOURCE_OPERATION[LUA_BROWSE]);
 
-  grl_lua_library_push_grl_media (L, bs->container);
+  lua_pushstring (L, media_id);
   grl_lua_library_push_grl_options (L, bs->operation_id, bs->options, bs->keys);
   if (!grl_lua_operations_pcall (L, 2, os, &err)) {
     if (err != NULL) {
@@ -1622,9 +1626,8 @@ grl_lua_factory_source_resolve (GrlSource *source,
 
   lua_getglobal (L, LUA_SOURCE_OPERATION[LUA_RESOLVE]);
 
-  grl_lua_library_push_grl_media (L, rs->media);
   grl_lua_library_push_grl_options (L, rs->operation_id, rs->options, rs->keys);
-  if (!grl_lua_operations_pcall (L, 2, os, &err)) {
+  if (!grl_lua_operations_pcall (L, 1, os, &err)) {
     if (err != NULL) {
       GRL_WARNING ("calling resolve function failed: %s", err->message);
       g_error_free (err);
diff --git a/src/lua-factory/grl-lua-library.c b/src/lua-factory/grl-lua-library.c
index 8dc8172..ee748c9 100644
--- a/src/lua-factory/grl-lua-library.c
+++ b/src/lua-factory/grl-lua-library.c
@@ -815,26 +815,26 @@ fail:
 }
 
 /**
-* grl_lua_library_push_grl_media.
+* grl.get_media_keys
 *
-* Pushes the GrlMedia on top of the lua stack as a key-value table
-*
-* @L: LuaState where the data is stored.
-* @media: GrlMedia to be put.
-* @return: Nothing.
+* @return: table with all keys/values of media (may be empty);
 */
-void
-grl_lua_library_push_grl_media (lua_State *L,
-                                GrlMedia *media)
+static gint
+grl_l_media_get_keys (lua_State *L)
 {
+  OperationSpec *os;
   GrlRegistry *registry;
   GList *it;
   GList *list_keys;
   const gchar *media_type = NULL;
+  GrlMedia *media;
+
+  os = grl_lua_operations_get_current_op (L);
+  media = os->media;
 
   if (media == NULL) {
     lua_pushnil (L);
-    return;
+    return 1;
   }
 
   registry = grl_registry_get_default ();
@@ -882,6 +882,7 @@ grl_lua_library_push_grl_media (lua_State *L,
     g_free (key_name);
   }
   g_list_free (list_keys);
+  return 1;
 }
 
 /**
@@ -1399,6 +1400,7 @@ gint
 luaopen_grilo (lua_State *L)
 {
   static const luaL_Reg library_fn[] = {
+    {"get_media_keys", &grl_l_media_get_keys},
     {"callback", &grl_l_callback},
     {"fetch", &grl_l_fetch},
     {"debug", &grl_l_debug},


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