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/idoappointmentmenuitem.c | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) (limited to 'src/idoappointmentmenuitem.c') diff --git a/src/idoappointmentmenuitem.c b/src/idoappointmentmenuitem.c index 929e011..45daeed 100644 --- a/src/idoappointmentmenuitem.c +++ b/src/idoappointmentmenuitem.c @@ -366,35 +366,58 @@ GtkMenuItem * ido_appointment_menu_item_new_from_model (GMenuItem * menu_item, GActionGroup * actions) { + guint i; + guint n; gint64 i64; gchar * str; IdoAppointmentMenuItem * ido_appointment; + GParameter parameters[8]; - ido_appointment = IDO_APPOINTMENT_MENU_ITEM (ido_appointment_menu_item_new()); + /* create the ido_appointment */ + + n = 0; if (g_menu_item_get_attribute (menu_item, "label", "s", &str)) { - ido_appointment_menu_item_set_summary (ido_appointment, str); - g_free (str); + GParameter p = { "summary", 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-color", "s", &str)) { - ido_appointment_menu_item_set_color (ido_appointment, str); - g_free (str); + GParameter p = { "color", 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", "x", &i64)) + if (g_menu_item_get_attribute (menu_item, "x-canonical-time-format", "s", &str)) { - ido_appointment_menu_item_set_time (ido_appointment, (time_t)i64); + GParameter p = { "format", 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)) + if (g_menu_item_get_attribute (menu_item, "x-canonical-time", "x", &i64)) { - ido_appointment_menu_item_set_format (ido_appointment, str); - g_free (str); + GParameter p = { "time", G_VALUE_INIT }; + g_value_init (&p.value, G_TYPE_INT64); + g_value_set_int64 (&p.value, i64); + parameters[n++] = p; } + g_assert (n <= G_N_ELEMENTS (parameters)); + ido_appointment = g_object_newv (IDO_APPOINTMENT_MENU_ITEM_TYPE, n, parameters); + + for (i=0; i