diff options
author | Charles Kerr <charles.kerr@canonical.com> | 2013-06-17 10:41:25 -0500 |
---|---|---|
committer | Charles Kerr <charles.kerr@canonical.com> | 2013-06-17 10:41:25 -0500 |
commit | 9205983a6f1a75487abeb32e4fe6df3753980277 (patch) | |
tree | ceb874d79d9337b6c67e5aeb52d6155e54100950 /src | |
parent | 6de8e0386beb02beafc321aaef82176acaae5424 (diff) | |
download | ayatana-ido-9205983a6f1a75487abeb32e4fe6df3753980277.tar.gz ayatana-ido-9205983a6f1a75487abeb32e4fe6df3753980277.tar.bz2 ayatana-ido-9205983a6f1a75487abeb32e4fe6df3753980277.zip |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/idoappointmentmenuitem.c | 43 | ||||
-rw-r--r-- | src/idolocationmenuitem.c | 34 |
2 files changed, 60 insertions, 17 deletions
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<n; i++) + g_value_unset (¶meters[i].value); + + + /* add an ActionHelper */ + if (g_menu_item_get_attribute (menu_item, "action", "s", &str)) { GVariant * target; 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<n; i++) + g_value_unset (¶meters[i].value); + + + /* give it an ActionHelper */ + if (g_menu_item_get_attribute (menu_item, "action", "s", &str)) { GVariant * target; |