diff options
author | Ted Gould <ted@gould.cx> | 2010-06-23 10:17:44 -0500 |
---|---|---|
committer | Ted Gould <ted@gould.cx> | 2010-06-23 10:17:44 -0500 |
commit | 4c05e67b833cdd4467eab0a740367536ebfb2c33 (patch) | |
tree | 584756fa2be78e8e0f20fb03e0f1e54763348b26 /libdbusmenu-gtk | |
parent | 51815a2cd05dd18d649113f2fc76247d7fdf00d1 (diff) | |
download | libdbusmenu-4c05e67b833cdd4467eab0a740367536ebfb2c33.tar.gz libdbusmenu-4c05e67b833cdd4467eab0a740367536ebfb2c33.tar.bz2 libdbusmenu-4c05e67b833cdd4467eab0a740367536ebfb2c33.zip |
Reworking to use collection iterators.
Diffstat (limited to 'libdbusmenu-gtk')
-rw-r--r-- | libdbusmenu-gtk/menuitem.c | 117 |
1 files changed, 69 insertions, 48 deletions
diff --git a/libdbusmenu-gtk/menuitem.c b/libdbusmenu-gtk/menuitem.c index 8874ebe..fa94c1e 100644 --- a/libdbusmenu-gtk/menuitem.c +++ b/libdbusmenu-gtk/menuitem.c @@ -275,6 +275,69 @@ dbusmenu_menuitem_property_set_shortcut_menuitem (DbusmenuMenuitem * menuitem, c return dbusmenu_menuitem_property_set_shortcut(menuitem, key->accel_key, key->accel_mods); } +typedef struct _iter_data_t iter_data_t; +struct _iter_data_t { + guint * key; + GdkModifierType * modifier; + const gchar * last_string; +}; + +static void +_string_iterator (const GValue * value, gpointer user_data) +{ + iter_data_t * iter_data = (iter_data_t *)user_data; + + if (!G_VALUE_HOLDS_STRING(value)) { + return; + } + + const gchar * string = g_value_get_string(value); + iter_data->last_string = string; + + if (g_strcmp0(string, DBUSMENU_MENUITEM_SHORTCUT_CONTROL) == 0) { + *iter_data->modifier |= GDK_CONTROL_MASK; + return; + } + if (g_strcmp0(string, DBUSMENU_MENUITEM_SHORTCUT_ALT) == 0) { + *iter_data->modifier |= GDK_MOD1_MASK; + return; + } + if (g_strcmp0(string, DBUSMENU_MENUITEM_SHORTCUT_SHIFT) == 0) { + *iter_data->modifier |= GDK_SHIFT_MASK; + return; + } + if (g_strcmp0(string, DBUSMENU_MENUITEM_SHORTCUT_SUPER) == 0) { + *iter_data->modifier |= GDK_SUPER_MASK; + return; + } + + return; +} + +static void +_wrapper_iterator (const GValue * value, gpointer user_data) +{ + iter_data_t * iter_data = (iter_data_t *)user_data; + + if (*iter_data->key != 0) { + g_warning("Shortcut is more than one entry. Which we don't currently support. Taking the first."); + return; + } + + if (!dbus_g_type_is_collection(G_VALUE_TYPE(value))) { + g_warning("Unexpected shortcut structure. Value array is: %s", G_VALUE_TYPE_NAME(value)); + } + + dbus_g_type_collection_value_iterate(value, _string_iterator, iter_data); + + if (iter_data->last_string != NULL) { + GdkModifierType tempmod; + gtk_accelerator_parse(iter_data->last_string, iter_data->key, &tempmod); + } + + return; +} + /** dbusmenu_menuitem_property_get_shortcut: @menuitem: The #DbusmenuMenuitem to get the shortcut off @@ -296,59 +359,17 @@ dbusmenu_menuitem_property_get_shortcut (DbusmenuMenuitem * menuitem, guint * ke if (wrapper == NULL) { return; } - if (!G_VALUE_HOLDS(wrapper, G_TYPE_BOXED)) { + if (!dbus_g_type_is_collection(G_VALUE_TYPE(wrapper))) { g_warning("Unexpected shortcut structure. Wrapper is: %s", G_VALUE_TYPE_NAME(wrapper)); return; } - GPtrArray * wrapperarray = (GPtrArray *)g_value_get_boxed(wrapper); - if (wrapperarray->len == 0) { - return; - } - - if (wrapperarray->len != 1) { - g_warning("Shortcut is more than one entry. Which we don't currently support. Taking the first."); - } - - GValue * ventryarray = g_ptr_array_index(wrapperarray, 0); - if (!G_VALUE_HOLDS(ventryarray, G_TYPE_BOXED)) { - g_warning("Unexpected shortcut structure. Value array is: %s", G_VALUE_TYPE_NAME(ventryarray)); - return; - } - - gchar ** entryarray = (gchar **)g_value_get_boxed(ventryarray); - if (entryarray == NULL || entryarray[0] == NULL) { - /* Seems a little odd, but really, we're saying that it isn't a - shortcut, so I'm comfortable with exiting silently. */ - return; - } - - /* Parse through modifiers */ - int i; - for (i = 0; entryarray[i + 1] != NULL; i++) { - gchar * value = entryarray[i]; - - if (g_strcmp0(value, DBUSMENU_MENUITEM_SHORTCUT_CONTROL) == 0) { - *modifier |= GDK_CONTROL_MASK; - continue; - } - if (g_strcmp0(value, DBUSMENU_MENUITEM_SHORTCUT_ALT) == 0) { - *modifier |= GDK_MOD1_MASK; - continue; - } - if (g_strcmp0(value, DBUSMENU_MENUITEM_SHORTCUT_SHIFT) == 0) { - *modifier |= GDK_SHIFT_MASK; - continue; - } - if (g_strcmp0(value, DBUSMENU_MENUITEM_SHORTCUT_SUPER) == 0) { - *modifier |= GDK_SUPER_MASK; - continue; - } - } + iter_data_t iter_data; + iter_data.key = key; + iter_data.modifier = modifier; + iter_data.last_string = NULL; - GdkModifierType tempmod; - gchar * accelval = entryarray[i]; - gtk_accelerator_parse(accelval, key, &tempmod); + dbus_g_type_collection_value_iterate(wrapper, _wrapper_iterator, &iter_data); return; } |