[vlc-commits] Lua: add support for the new spin icon

Jean-Philippe André git at videolan.org
Sat Jan 22 00:56:46 CET 2011


vlc | branch: master | Jean-Philippe André <jpeg at videolan.org> | Tue Jan 18 22:08:32 2011 +0100| [30b3704a1a56ff25211563be360eddb14178f8c8] | committer: Jean-Philippe André

Lua: add support for the new spin icon

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=30b3704a1a56ff25211563be360eddb14178f8c8
---

 include/vlc_extensions.h       |    5 ++
 modules/misc/lua/libs/dialog.c |   82 +++++++++++++++++++++++++++++++++++++++-
 2 files changed, 85 insertions(+), 2 deletions(-)

diff --git a/include/vlc_extensions.h b/include/vlc_extensions.h
index 07c6221..89fb714 100644
--- a/include/vlc_extensions.h
+++ b/include/vlc_extensions.h
@@ -255,6 +255,7 @@ typedef enum
     EXTENSION_WIDGET_DROPDOWN,   ///< Drop-down box
     EXTENSION_WIDGET_LIST,       ///< Vertical list box (of strings)
     EXTENSION_WIDGET_CHECK_BOX,  ///< Checkable box with label
+    EXTENSION_WIDGET_SPIN_ICON,  ///< A "loading..." spinning icon
 } extension_widget_type_e;
 
 /// Widget descriptor for extensions
@@ -285,6 +286,10 @@ struct extension_widget_t
     int i_height;                 ///< Height hint
     bool b_hide;                  ///< Hide this widget (make it invisible)
 
+    /* Spinning icon */
+    int i_spin_loops;             ///< Number of loops to play (-1 = infinite,
+                                  // 0 = stop animation)
+
     /* Orders */
     bool b_kill;                  ///< Destroy this widget
     bool b_update;                ///< Update this widget
diff --git a/modules/misc/lua/libs/dialog.c b/modules/misc/lua/libs/dialog.c
index a2e0d14..3ca67b2 100644
--- a/modules/misc/lua/libs/dialog.c
+++ b/modules/misc/lua/libs/dialog.c
@@ -78,6 +78,7 @@ static int vlclua_dialog_add_check_box( lua_State *L );
 static int vlclua_dialog_add_list( lua_State *L );
 static int vlclua_dialog_add_dropdown( lua_State *L );
 static int vlclua_dialog_add_image( lua_State *L );
+static int vlclua_dialog_add_spin_icon( lua_State *L );
 static int vlclua_create_widget_inner( lua_State *L, int i_args,
                                        extension_widget_t *p_widget);
 
@@ -92,6 +93,8 @@ static int vlclua_widget_add_value( lua_State *L );
 static int vlclua_widget_get_value( lua_State *L );
 static int vlclua_widget_clear( lua_State *L );
 static int vlclua_widget_get_selection( lua_State *L );
+static int vlclua_widget_animate( lua_State *L );
+static int vlclua_widget_stop( lua_State *L );
 
 /* Helpers */
 static void AddWidget( extension_dialog_t *p_dialog,
@@ -115,6 +118,7 @@ static const luaL_Reg vlclua_dialog_reg[] = {
     { "add_dropdown", vlclua_dialog_add_dropdown },
     { "add_list", vlclua_dialog_add_list },
     { "add_image", vlclua_dialog_add_image },
+    { "add_spin_icon", vlclua_dialog_add_spin_icon },
 
     { "del_widget", vlclua_dialog_delete_widget },
     { NULL, NULL }
@@ -129,6 +133,8 @@ static const luaL_Reg vlclua_widget_reg[] = {
     { "get_value", vlclua_widget_get_value },
     { "clear", vlclua_widget_clear },
     { "get_selection", vlclua_widget_get_selection },
+    { "animate", vlclua_widget_animate },
+    { "stop", vlclua_widget_stop },
     { NULL, NULL }
 };
 
@@ -511,7 +517,7 @@ static int vlclua_dialog_add_list( lua_State *L )
 
 /**
  * Create an image label
- * Arguments: url
+ * Arguments: (string) url
  * Qt: QLabel with setPixmap( QPixmap& )
  **/
 static int vlclua_dialog_add_image( lua_State *L )
@@ -528,6 +534,23 @@ static int vlclua_dialog_add_image( lua_State *L )
 }
 
 /**
+ * Create a spinning icon
+ * Arguments: (int) loop count to play: 0 means stopped, -1 means infinite.
+ * Qt: SpinningIcon (custom widget)
+ **/
+static int vlclua_dialog_add_spin_icon( lua_State *L )
+{
+    /* Verify arguments */
+    if( !lua_isstring( L, 2 ) )
+        return luaL_error( L, "dialog:add_image usage: (filename)" );
+
+    extension_widget_t *p_widget = calloc( 1, sizeof( extension_widget_t ) );
+    p_widget->type = EXTENSION_WIDGET_SPIN_ICON;
+
+    return vlclua_create_widget_inner( L, 0, p_widget );
+}
+
+/**
  * Internal helper to finalize the creation of a widget
  * @param L Lua State
  * @param i_args Number of arguments before "row" (0 or more)
@@ -847,7 +870,6 @@ static int vlclua_widget_get_selection( lua_State *L )
     return 1;
 }
 
-
 static int vlclua_widget_set_checked( lua_State *L )
 {
     /* Get dialog */
@@ -881,6 +903,62 @@ static int vlclua_widget_set_checked( lua_State *L )
     return 1;
 }
 
+static int vlclua_widget_animate( lua_State *L )
+{
+    /* Get dialog */
+    extension_widget_t **pp_widget =
+            (extension_widget_t **) luaL_checkudata( L, 1, "widget" );
+    if( !pp_widget || !*pp_widget )
+        return luaL_error( L, "Can't get pointer to widget" );
+    extension_widget_t *p_widget = *pp_widget;
+
+    if( p_widget->type != EXTENSION_WIDGET_SPIN_ICON )
+        return luaL_error( L, "method animate not valid for this widget" );
+
+    /* Verify arguments */
+    vlc_mutex_lock( &p_widget->p_dialog->lock );
+    if( !lua_isnumber( L, 2 ) )
+        p_widget->i_spin_loops = -1;
+    else
+        p_widget->i_spin_loops = lua_tointeger( L, 2 );
+    vlc_mutex_unlock( &p_widget->p_dialog->lock );
+
+    /* Signal interface of the change */
+    p_widget->b_update = true;
+    lua_SetDialogUpdate( L, 1 );
+
+    return 1;
+}
+
+static int vlclua_widget_stop( lua_State *L )
+{
+    /* Get dialog */
+    extension_widget_t **pp_widget =
+            (extension_widget_t **) luaL_checkudata( L, 1, "widget" );
+    if( !pp_widget || !*pp_widget )
+        return luaL_error( L, "Can't get pointer to widget" );
+    extension_widget_t *p_widget = *pp_widget;
+
+    if( p_widget->type != EXTENSION_WIDGET_SPIN_ICON )
+        return luaL_error( L, "method stop not valid for this widget" );
+
+    vlc_mutex_lock( &p_widget->p_dialog->lock );
+
+    bool b_needs_update = p_widget->i_spin_loops != 0;
+    p_widget->i_spin_loops = 0;
+
+    vlc_mutex_unlock( &p_widget->p_dialog->lock );
+
+    if( b_needs_update )
+    {
+        /* Signal interface of the change */
+        p_widget->b_update = true;
+        lua_SetDialogUpdate( L, 1 );
+    }
+
+    return 1;
+}
+
 /**
  * Delete a widget from a dialog
  * Remove it from the list once it has been safely destroyed by the interface



More information about the vlc-commits mailing list