From 9205983a6f1a75487abeb32e4fe6df3753980277 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 17 Jun 2013 10:41:25 -0500 Subject: when building location and appointment menuitems from a GMenu, grab all the parameters and then pass them to object_new() as a block to avoid them getting set twice -- once with the constructor's default values, and then once afterwards --- src/idolocationmenuitem.c | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) (limited to 'src/idolocationmenuitem.c') diff --git a/src/idolocationmenuitem.c b/src/idolocationmenuitem.c index 34e5de3..5993938 100644 --- a/src/idolocationmenuitem.c +++ b/src/idolocationmenuitem.c @@ -386,29 +386,49 @@ GtkMenuItem * ido_location_menu_item_new_from_model (GMenuItem * menu_item, GActionGroup * actions) { + guint i; + guint n; gchar * str; IdoLocationMenuItem * ido_location; + GParameter parameters[4]; - ido_location = IDO_LOCATION_MENU_ITEM (ido_location_menu_item_new ()); + /* create the ido_location */ + + n = 0; if (g_menu_item_get_attribute (menu_item, "label", "s", &str)) { - ido_location_menu_item_set_name (ido_location, str); - g_free (str); + GParameter p = { "name", G_VALUE_INIT }; + g_value_init (&p.value, G_TYPE_STRING); + g_value_take_string (&p.value, str); + parameters[n++] = p; } if (g_menu_item_get_attribute (menu_item, "x-canonical-timezone", "s", &str)) { - ido_location_menu_item_set_timezone (ido_location, str); - g_free (str); + GParameter p = { "timezone", G_VALUE_INIT }; + g_value_init (&p.value, G_TYPE_STRING); + g_value_take_string (&p.value, str); + parameters[n++] = p; } if (g_menu_item_get_attribute (menu_item, "x-canonical-time-format", "s", &str)) { - ido_location_menu_item_set_format (ido_location, str); - g_free (str); + GParameter p = { "format", G_VALUE_INIT }; + g_value_init (&p.value, G_TYPE_STRING); + g_value_take_string (&p.value, str); + parameters[n++] = p; } + g_assert (n <= G_N_ELEMENTS (parameters)); + ido_location = g_object_newv (IDO_LOCATION_MENU_ITEM_TYPE, n, parameters); + + for (i=0; i