From c69209a253c7ccbfe5d2c91e6972fa3dc1deb50c Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Mon, 7 Sep 2009 11:36:05 +0100 Subject: [PATCH] [animation] Move the check for the 'signal::' prefix into a separate function The old code checked whether the property began with 'signal-' and then checked for 'signal-swapped' and 'signal-after'. This prevented you from animating a property called for example 'signal-strength'. The check for the prefix is now in a separate function which also adds a 'signal-swapped-after' prefix for completeness. Fixes bug: http://bugzilla.openedhand.com/show_bug.cgi?id=1798 --- clutter/clutter-animation.c | 75 ++++++++++++++++++++----------------- 1 file changed, 41 insertions(+), 34 deletions(-) diff --git a/clutter/clutter-animation.c b/clutter/clutter-animation.c index fbbecb59c..b31445610 100644 --- a/clutter/clutter-animation.c +++ b/clutter/clutter-animation.c @@ -1616,6 +1616,39 @@ clutter_animation_setupv (ClutterAnimation *animation, } } +static const struct +{ + const gchar *name; + GConnectFlags flags; +} signal_prefixes[] = + { + { "::", 0 }, + { "-swapped::", G_CONNECT_SWAPPED }, + { "-after::", G_CONNECT_AFTER }, + { "-swapped-after::", G_CONNECT_SWAPPED | G_CONNECT_AFTER } + }; + +static gboolean +clutter_animation_has_signal_prefix (const gchar *property_name, + GConnectFlags *flags, + int *offset) +{ + int i; + + if (!g_str_has_prefix (property_name, "signal")) + return FALSE; + + for (i = 0; i < G_N_ELEMENTS (signal_prefixes); i++) + if (g_str_has_prefix (property_name + 6, signal_prefixes[i].name)) + { + *offset = strlen (signal_prefixes[i].name) + 6; + *flags = signal_prefixes[i].flags; + return TRUE; + } + + return FALSE; +} + static void clutter_animation_setup_valist (ClutterAnimation *animation, const gchar *first_property_name, @@ -1634,46 +1667,20 @@ clutter_animation_setup_valist (ClutterAnimation *animation, GValue final = { 0, }; gchar *error = NULL; gboolean is_fixed = FALSE; + GConnectFlags flags; + int offset; - if (g_str_has_prefix (property_name, "signal::")) + if (clutter_animation_has_signal_prefix (property_name, + &flags, + &offset)) { - const gchar *signal_name = property_name + 8; + const gchar *signal_name = property_name + offset; GCallback callback = va_arg (var_args, GCallback); gpointer userdata = va_arg (var_args, gpointer); - g_signal_connect (animation, signal_name, callback, userdata); - } - else if (g_str_has_prefix (property_name, "signal-")) - { - GCallback callback = va_arg (var_args, GCallback); - gpointer userdata = va_arg (var_args, gpointer); - const gchar *signal_name; - GConnectFlags flags; - - if (g_str_has_prefix (property_name, "signal-after::")) - { - signal_name = property_name + 14; - flags = G_CONNECT_AFTER; - } - else if (g_str_has_prefix (property_name, "signal-swapped::")) - { - signal_name = property_name + 16; - flags = G_CONNECT_SWAPPED; - } - else - { - g_warning ("Unable to connect to '%s': the valid signal " - "modifiers are 'signal-swapped::' and " - "'signal-swapped::'", - property_name); - break; - } - g_signal_connect_data (animation, signal_name, - callback, - userdata, - NULL, - flags); + callback, userdata, + NULL, flags); } else {