[glib/wip/menus-rebase2] Stop using quarks in GMenu
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/menus-rebase2] Stop using quarks in GMenu
- Date: Sat, 19 Nov 2011 04:44:41 +0000 (UTC)
commit ee3b002a87844303f4b141f03577e5946365e9d6
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Nov 18 21:03:58 2011 -0500
Stop using quarks in GMenu
This allows us to drop the parallel string_table/quark_table/dictionary
madness. The dictionary variant was unused, except for one test.
gio/gio.symbols | 1 -
gio/gmenu.c | 49 +++++--------
gio/gmenumodel.c | 180 ++++++++---------------------------------------
gio/gmenumodel.h | 11 +--
gio/gmenuproxy.c | 18 ++---
gio/tests/gmenumodel.c | 55 +++++++--------
6 files changed, 85 insertions(+), 229 deletions(-)
---
diff --git a/gio/gio.symbols b/gio/gio.symbols
index b2b557c..6e6b7db 100644
--- a/gio/gio.symbols
+++ b/gio/gio.symbols
@@ -1605,7 +1605,6 @@ g_menu_append
g_menu_append_item
g_menu_append_section
g_menu_append_submenu
-g_menu_attribute_dict_iter_get_type
g_menu_attribute_hash_iter_get_type
g_menu_attribute_iter_get_name
g_menu_attribute_iter_get_next
diff --git a/gio/gmenu.c b/gio/gmenu.c
index 03df5bb..dd11bc6 100644
--- a/gio/gmenu.c
+++ b/gio/gmenu.c
@@ -104,24 +104,21 @@ g_menu_get_n_items (GMenuModel *model)
static void
g_menu_get_item_attributes (GMenuModel *model,
gint position,
- GHashTable **attr_table,
- GHashTable **string_table,
- GVariant **dictionary)
+ GHashTable **table)
{
GMenu *menu = G_MENU (model);
- *attr_table = g_hash_table_ref (g_array_index (menu->items, struct item, position).attributes);
+ *table = g_hash_table_ref (g_array_index (menu->items, struct item, position).attributes);
}
static void
g_menu_get_item_links (GMenuModel *model,
gint position,
- GHashTable **attr_table,
- GHashTable **string_table)
+ GHashTable **table)
{
GMenu *menu = G_MENU (model);
- *attr_table = g_hash_table_ref (g_array_index (menu->items, struct item, position).links);
+ *table = g_hash_table_ref (g_array_index (menu->items, struct item, position).links);
}
/**
@@ -507,17 +504,17 @@ g_menu_item_clear_cow (GMenuItem *menu_item)
gpointer key;
gpointer val;
- new = g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify) g_variant_unref);
+ new = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_variant_unref);
g_hash_table_iter_init (&iter, menu_item->attributes);
while (g_hash_table_iter_next (&iter, &key, &val))
- g_hash_table_insert (new, key, g_variant_ref (val));
+ g_hash_table_insert (new, g_strdup (key), g_variant_ref (val));
g_hash_table_unref (menu_item->attributes);
menu_item->attributes = new;
- new = g_hash_table_new_full (NULL, NULL, NULL, g_object_unref);
+ new = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_object_unref);
g_hash_table_iter_init (&iter, menu_item->links);
while (g_hash_table_iter_next (&iter, &key, &val))
- g_hash_table_insert (new, key, g_object_ref (val));
+ g_hash_table_insert (new, g_strdup (key), g_object_ref (val));
g_hash_table_unref (menu_item->links);
menu_item->links = new;
@@ -540,8 +537,8 @@ g_menu_item_finalize (GObject *object)
static void
g_menu_item_init (GMenuItem *menu_item)
{
- menu_item->attributes = g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify) g_variant_unref);
- menu_item->links = g_hash_table_new_full (NULL, NULL, NULL, g_object_unref);
+ menu_item->attributes = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_variant_unref);
+ menu_item->links = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
menu_item->cow = FALSE;
}
@@ -568,23 +565,19 @@ g_menu_item_class_init (GMenuItemClass *class)
* the same.
**/
void
-g_menu_item_set_attribute_value (GMenuItem *menu_item,
+g_menu_item_set_attribute_value (GMenuItem *menu_item,
const gchar *attribute,
- GVariant *value)
+ GVariant *value)
{
- GQuark attribute_q;
-
g_return_if_fail (G_IS_MENU_ITEM (menu_item));
g_return_if_fail (attribute != NULL);
- attribute_q = g_quark_from_string (attribute);
-
g_menu_item_clear_cow (menu_item);
if (value != NULL)
- g_hash_table_insert (menu_item->attributes, GINT_TO_POINTER (attribute_q), g_variant_ref_sink (value));
+ g_hash_table_insert (menu_item->attributes, g_strdup (attribute), g_variant_ref_sink (value));
else
- g_hash_table_remove (menu_item->attributes, GINT_TO_POINTER (attribute_q));
+ g_hash_table_remove (menu_item->attributes, attribute);
}
/**
@@ -639,25 +632,21 @@ g_menu_item_set_attribute (GMenuItem *menu_item,
* Links are used to establish a relationship between a particular menu
* item and another menu. For example, %G_MENU_LINK_SUBMENU is used to
* associate a submenu with a particular menu item.
- **/
+ */
void
-g_menu_item_set_link (GMenuItem *menu_item,
+g_menu_item_set_link (GMenuItem *menu_item,
const gchar *link,
- GMenuModel *model)
+ GMenuModel *model)
{
- GQuark link_q;
-
g_return_if_fail (G_IS_MENU_ITEM (menu_item));
g_return_if_fail (link != NULL);
- link_q = g_quark_from_string (link);
-
g_menu_item_clear_cow (menu_item);
if (model != NULL)
- g_hash_table_insert (menu_item->links, GINT_TO_POINTER (link_q), g_object_ref (model));
+ g_hash_table_insert (menu_item->links, g_strdup (link), g_object_ref (model));
else
- g_hash_table_remove (menu_item->links, GINT_TO_POINTER (link_q));
+ g_hash_table_remove (menu_item->links, link);
}
/**
diff --git a/gio/gmenumodel.c b/gio/gmenumodel.c
index 9079448..4a9fd59 100644
--- a/gio/gmenumodel.c
+++ b/gio/gmenumodel.c
@@ -103,7 +103,6 @@ typedef struct
GMenuLinkIter parent_instance;
GHashTableIter iter;
GHashTable *table;
- gboolean is_quarks;
} GMenuLinkHashIter;
typedef GMenuLinkIterClass GMenuLinkHashIterClass;
@@ -121,10 +120,7 @@ g_menu_link_hash_iter_get_next (GMenuLinkIter *link_iter,
if (!g_hash_table_iter_next (&iter->iter, &keyptr, &valueptr))
return FALSE;
- if (iter->is_quarks)
- *out_name = g_quark_to_string (GPOINTER_TO_INT (keyptr));
- else
- *out_name = keyptr;
+ *out_name = keyptr;
*value = g_object_ref (valueptr);
return TRUE;
@@ -161,7 +157,6 @@ typedef struct
GMenuAttributeIter parent_instance;
GHashTableIter iter;
GHashTable *table;
- gboolean is_quarks;
} GMenuAttributeHashIter;
typedef GMenuAttributeIterClass GMenuAttributeHashIterClass;
@@ -179,10 +174,7 @@ g_menu_attribute_hash_iter_get_next (GMenuAttributeIter *attr_iter,
if (!g_hash_table_iter_next (&iter->iter, &keyptr, &valueptr))
return FALSE;
- if (iter->is_quarks)
- *name = g_quark_to_string (GPOINTER_TO_INT (keyptr));
- else
- *name = keyptr;
+ *name = keyptr;
*value = g_variant_ref (valueptr);
@@ -214,54 +206,6 @@ g_menu_attribute_hash_iter_class_init (GMenuAttributeHashIterClass *class)
class->get_next = g_menu_attribute_hash_iter_get_next;
}
-
-typedef struct
-{
- GMenuAttributeIter parent_instance;
- GVariantIter iter;
- GVariant *dict;
-} GMenuAttributeDictIter;
-
-typedef GMenuAttributeIterClass GMenuAttributeDictIterClass;
-
-G_DEFINE_TYPE (GMenuAttributeDictIter, g_menu_attribute_dict_iter, G_TYPE_MENU_ATTRIBUTE_ITER)
-
-static gboolean
-g_menu_attribute_dict_iter_get_next (GMenuAttributeIter *attr_iter,
- const gchar **name,
- GVariant **value)
-{
- GMenuAttributeDictIter *iter = (GMenuAttributeDictIter *) attr_iter;
-
- return g_variant_iter_next (&iter->iter, "{&sv}", name, value);
-}
-
-static void
-g_menu_attribute_dict_iter_finalize (GObject *object)
-{
- GMenuAttributeDictIter *iter = (GMenuAttributeDictIter *) object;
-
- g_variant_unref (iter->dict);
-
- G_OBJECT_CLASS (g_menu_attribute_dict_iter_parent_class)
- ->finalize (object);
-}
-
-static void
-g_menu_attribute_dict_iter_init (GMenuAttributeDictIter *iter)
-{
-}
-
-static void
-g_menu_attribute_dict_iter_class_init (GMenuAttributeDictIterClass *class)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (class);
-
- object_class->finalize = g_menu_attribute_dict_iter_finalize;
- class->get_next = g_menu_attribute_dict_iter_get_next;
-}
-
-
G_DEFINE_ABSTRACT_TYPE (GMenuModel, g_menu_model, G_TYPE_OBJECT)
@@ -271,35 +215,16 @@ static GMenuAttributeIter *
g_menu_model_real_iterate_item_attributes (GMenuModel *model,
gint item_index)
{
- GHashTable *string_table = NULL;
- GHashTable *quark_table = NULL;
- GVariant *dictionary = NULL;
+ GHashTable *table = NULL;
GMenuAttributeIter *result;
- G_MENU_MODEL_GET_CLASS (model)
- ->get_item_attributes (model, item_index, &quark_table, &string_table, &dictionary);
+ G_MENU_MODEL_GET_CLASS (model)->get_item_attributes (model, item_index, &table);
- if (quark_table)
- {
- GMenuAttributeHashIter *iter = g_object_new (g_menu_attribute_hash_iter_get_type (), NULL);
- g_hash_table_iter_init (&iter->iter, quark_table);
- iter->table = g_hash_table_ref (quark_table);
- iter->is_quarks = TRUE;
- result = G_MENU_ATTRIBUTE_ITER (iter);
- }
- else if (string_table)
+ if (table)
{
GMenuAttributeHashIter *iter = g_object_new (g_menu_attribute_hash_iter_get_type (), NULL);
- g_hash_table_iter_init (&iter->iter, string_table);
- iter->table = g_hash_table_ref (string_table);
- iter->is_quarks = FALSE;
- result = G_MENU_ATTRIBUTE_ITER (iter);
- }
- else if (dictionary)
- {
- GMenuAttributeDictIter *iter = g_object_new (g_menu_attribute_dict_iter_get_type (), NULL);
- g_variant_iter_init (&iter->iter, dictionary);
- iter->dict = g_variant_ref (dictionary);
+ g_hash_table_iter_init (&iter->iter, table);
+ iter->table = g_hash_table_ref (table);
result = G_MENU_ATTRIBUTE_ITER (iter);
}
else
@@ -310,12 +235,8 @@ g_menu_model_real_iterate_item_attributes (GMenuModel *model,
result = NULL;
}
- if (string_table != NULL)
- g_hash_table_unref (string_table);
- if (quark_table != NULL)
- g_hash_table_unref (quark_table);
- if (dictionary != NULL)
- g_variant_unref (dictionary);
+ if (table != NULL)
+ g_hash_table_unref (table);
return result;
}
@@ -326,30 +247,15 @@ g_menu_model_real_get_item_attribute_value (GMenuModel *model,
const gchar *attribute,
const GVariantType *expected_type)
{
- GQuark attribute_q = g_quark_from_string (attribute);
- GHashTable *string_table = NULL;
- GHashTable *quark_table = NULL;
- GVariant *dictionary = NULL;
+ GHashTable *table = NULL;
GVariant *value = NULL;
G_MENU_MODEL_GET_CLASS (model)
- ->get_item_attributes (model, item_index, &quark_table, &string_table, &dictionary);
-
- if (quark_table != NULL)
- {
- value = g_hash_table_lookup (quark_table, GINT_TO_POINTER (attribute_q));
+ ->get_item_attributes (model, item_index, &table);
- if (value != NULL)
- {
- if (expected_type == NULL || g_variant_is_of_type (value, expected_type))
- value = g_variant_ref (value);
- else
- value = NULL;
- }
- }
- else if (string_table != NULL)
+ if (table != NULL)
{
- value = g_hash_table_lookup (string_table, attribute);
+ value = g_hash_table_lookup (table, attribute);
if (value != NULL)
{
@@ -359,17 +265,11 @@ g_menu_model_real_get_item_attribute_value (GMenuModel *model,
value = NULL;
}
}
- else if (dictionary != NULL)
- value = g_variant_lookup_value (dictionary, attribute, expected_type);
else
g_assert_not_reached ();
- if (string_table != NULL)
- g_hash_table_unref (string_table);
- if (quark_table != NULL)
- g_hash_table_unref (quark_table);
- if (dictionary != NULL)
- g_variant_unref (dictionary);
+ if (table != NULL)
+ g_hash_table_unref (table);
return value;
}
@@ -378,27 +278,17 @@ static GMenuLinkIter *
g_menu_model_real_iterate_item_links (GMenuModel *model,
gint item_index)
{
- GHashTable *string_table = NULL;
- GHashTable *quark_table = NULL;
+ GHashTable *table = NULL;
GMenuLinkIter *result;
G_MENU_MODEL_GET_CLASS (model)
- ->get_item_links (model, item_index, &quark_table, &string_table);
+ ->get_item_links (model, item_index, &table);
- if (quark_table)
+ if (table)
{
GMenuLinkHashIter *iter = g_object_new (g_menu_link_hash_iter_get_type (), NULL);
- g_hash_table_iter_init (&iter->iter, quark_table);
- iter->table = g_hash_table_ref (quark_table);
- iter->is_quarks = TRUE;
- result = G_MENU_LINK_ITER (iter);
- }
- else if (string_table)
- {
- GMenuLinkHashIter *iter = g_object_new (g_menu_link_hash_iter_get_type (), NULL);
- g_hash_table_iter_init (&iter->iter, string_table);
- iter->table = g_hash_table_ref (string_table);
- iter->is_quarks = FALSE;
+ g_hash_table_iter_init (&iter->iter, table);
+ iter->table = g_hash_table_ref (table);
result = G_MENU_LINK_ITER (iter);
}
else
@@ -409,38 +299,30 @@ g_menu_model_real_iterate_item_links (GMenuModel *model,
result = NULL;
}
- if (string_table != NULL)
- g_hash_table_unref (string_table);
- if (quark_table != NULL)
- g_hash_table_unref (quark_table);
+ if (table != NULL)
+ g_hash_table_unref (table);
return result;
}
static GMenuModel *
-g_menu_model_real_get_item_link (GMenuModel *model,
- gint item_index,
+g_menu_model_real_get_item_link (GMenuModel *model,
+ gint item_index,
const gchar *link)
{
- GQuark link_q = g_quark_from_string (link);
- GHashTable *string_table = NULL;
- GHashTable *quark_table = NULL;
+ GHashTable *table = NULL;
GMenuModel *value = NULL;
G_MENU_MODEL_GET_CLASS (model)
- ->get_item_links (model, item_index, &quark_table, &string_table);
+ ->get_item_links (model, item_index, &table);
- if (quark_table != NULL)
- value = g_hash_table_lookup (quark_table, GINT_TO_POINTER (link_q));
- else if (string_table != NULL)
- value = g_hash_table_lookup (string_table, link);
+ if (table != NULL)
+ value = g_hash_table_lookup (table, link);
else
g_assert_not_reached ();
- if (string_table != NULL)
- g_hash_table_unref (string_table);
- if (quark_table != NULL)
- g_hash_table_unref (quark_table);
+ if (table != NULL)
+ g_hash_table_unref (table);
return value ? g_object_ref (value) : NULL;
}
@@ -767,7 +649,7 @@ struct _GMenuAttributeIterPrivate
**/
gboolean
g_menu_attribute_iter_get_next (GMenuAttributeIter *iter,
- const gchar **out_name,
+ const gchar **out_name,
GVariant **value)
{
const gchar *name;
diff --git a/gio/gmenumodel.h b/gio/gmenumodel.h
index 03ead5d..8ae8ae9 100644
--- a/gio/gmenumodel.h
+++ b/gio/gmenumodel.h
@@ -73,28 +73,23 @@ struct _GMenuModelClass
gboolean (*is_mutable) (GMenuModel *model);
gint (*get_n_items) (GMenuModel *model);
-
void (*get_item_attributes) (GMenuModel *model,
gint item_index,
- GHashTable **quark_table,
- GHashTable **string_table,
- GVariant **dictionary);
+ GHashTable **attributes);
GMenuAttributeIter * (*iterate_item_attributes) (GMenuModel *model,
gint item_index);
GVariant * (*get_item_attribute_value) (GMenuModel *model,
gint item_index,
const gchar *attribute,
const GVariantType *expected_type);
-
void (*get_item_links) (GMenuModel *model,
gint item_index,
- GHashTable **quark_table,
- GHashTable **string_table);
+ GHashTable **links);
GMenuLinkIter * (*iterate_item_links) (GMenuModel *model,
gint item_index);
GMenuModel * (*get_item_link) (GMenuModel *model,
gint item_index,
- const gchar *link);
+ const gchar *link);
};
GType g_menu_model_get_type (void) G_GNUC_CONST;
diff --git a/gio/gmenuproxy.c b/gio/gmenuproxy.c
index 34928bd..3e4f1a4 100644
--- a/gio/gmenuproxy.c
+++ b/gio/gmenuproxy.c
@@ -127,9 +127,8 @@
* GMenuProxy, the change signal is passed along to that proxy. If the
* proxy is inactive, the change signal is ignored.
*
- * GMenuProxyItem is just a pair of (GVariant, GHashTable) where the
- * GVariant is a dictionary containing the attributes of the item and
- * the hashtable contains the links of the item (mapping strings to
+ * GMenuProxyItem is just a pair of hashtables, one for the attributes
+ * and one for the links of the item (mapping strings to
* other GMenuProxy instances). XXX reconsider this since it means the
* submenu proxies stay around forever.....
*
@@ -404,7 +403,7 @@ g_menu_proxy_group_create_item (GMenuProxyGroup *context,
item = g_slice_new (GMenuProxyItem);
item->attributes = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_variant_unref);
- item->links = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
+ item->links = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_object_unref);
g_variant_iter_init (&iter, description);
while (g_variant_iter_loop (&iter, "{&sv}", &key, &value))
@@ -722,9 +721,7 @@ g_menu_proxy_get_n_items (GMenuModel *model)
static void
g_menu_proxy_get_item_attributes (GMenuModel *model,
gint item_index,
- GHashTable **attr_table,
- GHashTable **string_table,
- GVariant **dictionary)
+ GHashTable **table)
{
GMenuProxy *proxy = G_MENU_PROXY (model);
GMenuProxyItem *item;
@@ -739,14 +736,13 @@ g_menu_proxy_get_item_attributes (GMenuModel *model,
item = g_sequence_get (iter);
g_return_if_fail (item);
- *string_table = g_hash_table_ref (item->attributes);
+ *table = g_hash_table_ref (item->attributes);
}
static void
g_menu_proxy_get_item_links (GMenuModel *model,
gint item_index,
- GHashTable **attr_table,
- GHashTable **string_table)
+ GHashTable **table)
{
GMenuProxy *proxy = G_MENU_PROXY (model);
GMenuProxyItem *item;
@@ -761,7 +757,7 @@ g_menu_proxy_get_item_links (GMenuModel *model,
item = g_sequence_get (iter);
g_return_if_fail (item);
- *string_table = g_hash_table_ref (item->links);
+ *table = g_hash_table_ref (item->links);
}
static void
diff --git a/gio/tests/gmenumodel.c b/gio/tests/gmenumodel.c
index 3c63570..b5825f2 100644
--- a/gio/tests/gmenumodel.c
+++ b/gio/tests/gmenumodel.c
@@ -6,18 +6,18 @@
* class implementations below.
*/
typedef struct {
- GVariant *attributes;
+ GHashTable *attributes;
GHashTable *links;
} TestItem;
static TestItem *
-test_item_new (GVariant *attributes,
+test_item_new (GHashTable *attributes,
GHashTable *links)
{
TestItem *item;
item = g_slice_new (TestItem);
- item->attributes = g_variant_ref_sink (attributes);
+ item->attributes = g_hash_table_ref (attributes);
item->links = g_hash_table_ref (links);
return item;
@@ -28,7 +28,7 @@ test_item_free (gpointer data)
{
TestItem *item = data;
- g_variant_unref (item->attributes);
+ g_hash_table_unref (item->attributes);
g_hash_table_unref (item->links);
g_slice_free (TestItem, item);
@@ -67,28 +67,25 @@ random_menu_get_n_items (GMenuModel *model)
static void
random_menu_get_item_attributes (GMenuModel *model,
gint position,
- GHashTable **quarks_table,
- GHashTable **string_table,
- GVariant **dictionary)
+ GHashTable **table)
{
RandomMenu *menu = (RandomMenu *) model;
TestItem *item;
item = g_sequence_get (g_sequence_get_iter_at_pos (menu->items, position));
- *dictionary = g_variant_ref (item->attributes);
+ *table = g_hash_table_ref (item->attributes);
}
static void
random_menu_get_item_links (GMenuModel *model,
gint position,
- GHashTable **quarks_table,
- GHashTable **string_table)
+ GHashTable **table)
{
RandomMenu *menu = (RandomMenu *) model;
TestItem *item;
item = g_sequence_get (g_sequence_get_iter_at_pos (menu->items, position));
- *quarks_table = g_hash_table_ref (item->links);
+ *table = g_hash_table_ref (item->links);
}
static void
@@ -153,12 +150,12 @@ random_menu_change (RandomMenu *menu,
for (i = 0; i < adds; i++)
{
- GVariantBuilder builder;
const gchar *label;
GHashTable *links;
+ GHashTable *attributes;
- g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT);
- links = g_hash_table_new_full (NULL, NULL, NULL, g_object_unref);
+ attributes = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_variant_unref);
+ links = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_object_unref);
if (menu->order > 0 && g_rand_boolean (rand))
{
@@ -183,17 +180,18 @@ random_menu_change (RandomMenu *menu,
label = "Submenu";
}
- g_hash_table_insert (links, GINT_TO_POINTER (g_quark_from_string (subtype)), child);
+ g_hash_table_insert (links, g_strdup (subtype), child);
}
else
/* label all terminals */
label = "Menu Item";
if (label)
- g_variant_builder_add (&builder, "{sv}", "label", g_variant_new_string (label));
+ g_hash_table_insert (attributes, g_strdup ("label"), g_variant_ref_sink (g_variant_new_string (label)));
- g_sequence_insert_before (point, test_item_new (g_variant_builder_end (&builder), links));
+ g_sequence_insert_before (point, test_item_new (attributes, links));
g_hash_table_unref (links);
+ g_hash_table_unref (attributes);
}
g_menu_model_items_changed (G_MENU_MODEL (menu), position, removes, adds);
@@ -247,28 +245,25 @@ mirror_menu_get_n_items (GMenuModel *model)
static void
mirror_menu_get_item_attributes (GMenuModel *model,
gint position,
- GHashTable **quarks_table,
- GHashTable **string_table,
- GVariant **dictionary)
+ GHashTable **table)
{
MirrorMenu *menu = (MirrorMenu *) model;
TestItem *item;
item = g_sequence_get (g_sequence_get_iter_at_pos (menu->items, position));
- *dictionary = g_variant_ref (item->attributes);
+ *table = g_hash_table_ref (item->attributes);
}
static void
mirror_menu_get_item_links (GMenuModel *model,
gint position,
- GHashTable **quarks_table,
- GHashTable **string_table)
+ GHashTable **table)
{
MirrorMenu *menu = (MirrorMenu *) model;
TestItem *item;
item = g_sequence_get (g_sequence_get_iter_at_pos (menu->items, position));
- *string_table = g_hash_table_ref (item->links);
+ *table = g_hash_table_ref (item->links);
}
static void
@@ -333,20 +328,19 @@ mirror_menu_changed (GMenuModel *model,
{
GMenuAttributeIter *attr_iter;
GMenuLinkIter *link_iter;
- GVariantBuilder builder;
GHashTable *links;
+ GHashTable *attributes;
const gchar *name;
GMenuModel *child;
GVariant *value;
- g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT);
- links = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
+ attributes = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_variant_unref);
+ links = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_object_unref);
attr_iter = g_menu_model_iterate_item_attributes (model, i);
while (g_menu_attribute_iter_get_next (attr_iter, &name, &value))
{
- g_variant_builder_add (&builder, "{sv}", name, value);
- g_variant_unref (value);
+ g_hash_table_insert (attributes, g_strdup (name), value);
}
g_object_unref (attr_iter);
@@ -358,7 +352,8 @@ mirror_menu_changed (GMenuModel *model,
}
g_object_unref (link_iter);
- g_sequence_insert_before (point, test_item_new (g_variant_builder_end (&builder), links));
+ g_sequence_insert_before (point, test_item_new (attributes, links));
+ g_hash_table_unref (attributes);
g_hash_table_unref (links);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]