[glib/wip/menus: 2/18] Drop 'by_name' variants



commit 1979da0cf4f5aeb5e319bb2bb2a92cb5d9b82900
Author: Ryan Lortie <desrt desrt ca>
Date:   Mon Jul 11 01:14:54 2011 +0200

    Drop 'by_name' variants

 gio/gmenu.c       |   77 ------------------------
 gio/gmenu.h       |   19 ------
 gio/gmenumarkup.c |   17 ++---
 gio/gmenumodel.c  |  172 -----------------------------------------------------
 gio/gmenumodel.h  |   28 ---------
 5 files changed, 7 insertions(+), 306 deletions(-)
---
diff --git a/gio/gmenu.c b/gio/gmenu.c
index c7e5df7..54dac68 100644
--- a/gio/gmenu.c
+++ b/gio/gmenu.c
@@ -383,38 +383,6 @@ g_menu_item_get_attribute (GMenuItem   *menu_item,
   return TRUE;
 }
 
-GVariant *
-g_menu_item_get_attribute_value_by_name (GMenuItem          *menu_item,
-                                         const gchar        *attribute_name,
-                                         const GVariantType *expected_type)
-{
-  return g_menu_item_get_attribute_value (menu_item, g_quark_try_string (attribute_name), expected_type);
-}
-
-gboolean
-g_menu_item_get_attribute_by_name (GMenuItem   *menu_item,
-                                   const gchar *attribute_name,
-                                   const gchar *format_string,
-                                   ...)
-{
-  const GVariantType *expected_type;
-  GVariant *value;
-  va_list ap;
-
-  expected_type = NULL; /* XXX devine the type, ensure no '&' */
-
-  value = g_menu_item_get_attribute_value_by_name (menu_item, attribute_name, expected_type);
-  if (value == NULL)
-    return FALSE;
-
-  va_start (ap, format_string);
-  g_variant_get_va (value, format_string, NULL, &ap);
-  g_variant_unref (value);
-  va_end (ap);
-
-  return TRUE;
-}
-
 void
 g_menu_item_set_attribute_value (GMenuItem *menu_item,
                                  GQuark     attribute_quark,
@@ -452,37 +420,6 @@ g_menu_item_unset_attribute (GMenuItem *menu_item,
   g_hash_table_remove (menu_item->attributes, GINT_TO_POINTER (attribute_quark));
 }
 
-void
-g_menu_item_set_attribute_value_by_name (GMenuItem   *menu_item,
-                                         const gchar *attribute_name,
-                                         GVariant    *value)
-{
-  g_menu_item_set_attribute_value (menu_item, g_quark_from_string (attribute_name), value);
-}
-
-void
-g_menu_item_set_attribute_by_name (GMenuItem   *menu_item,
-                                   const gchar *attribute_name,
-                                   const gchar *format_string,
-                                   ...)
-{
-  GVariant *value;
-  va_list ap;
-
-  va_start (ap, format_string);
-  value = g_variant_new_va (format_string, NULL, &ap);
-  va_end (ap);
-
-  g_menu_item_set_attribute_value (menu_item, g_quark_from_string (attribute_name), value);
-}
-
-void
-g_menu_item_unset_attribute_by_name (GMenuItem   *menu_item,
-                                     const gchar *attribute_name)
-{
-  g_hash_table_remove (menu_item->attributes, GINT_TO_POINTER (g_quark_try_string (attribute_name)));
-}
-
 
 GMenuModel *
 g_menu_item_get_link (GMenuItem *menu_item,
@@ -498,12 +435,6 @@ g_menu_item_get_link (GMenuItem *menu_item,
   return link ? g_object_ref (link) : NULL;
 }
 
-GMenuModel *
-g_menu_item_get_link_by_name (GMenuItem   *menu_item,
-                              const gchar *link_name)
-{
-  return g_menu_item_get_link (menu_item, g_quark_try_string (link_name));
-}
 
 void
 g_menu_item_set_link (GMenuItem  *menu_item,
@@ -520,14 +451,6 @@ g_menu_item_set_link (GMenuItem  *menu_item,
 }
 
 void
-g_menu_item_set_link_by_name (GMenuItem   *menu_item,
-                              const gchar *link_name,
-                              GMenuModel  *link)
-{
-  g_menu_item_set_link (menu_item, g_quark_from_string (link_name), link);
-}
-
-void
 g_menu_item_set_label (GMenuItem   *menu_item,
                        const gchar *label)
 {
diff --git a/gio/gmenu.h b/gio/gmenu.h
index 1f54d79..69253ea 100644
--- a/gio/gmenu.h
+++ b/gio/gmenu.h
@@ -119,13 +119,6 @@ gboolean                g_menu_item_get_attribute                       (GMenuIt
                                                                          GQuark              attribute_quark,
                                                                          const gchar        *format_string,
                                                                          ...);
-GVariant *              g_menu_item_get_attribute_value_by_name         (GMenuItem          *menu_item,
-                                                                         const gchar        *attribute_name,
-                                                                         const GVariantType *expected_type);
-gboolean                g_menu_item_get_attribute_by_name               (GMenuItem          *menu_item,
-                                                                         const gchar        *attribute_name,
-                                                                         const gchar        *format_string,
-                                                                         ...);
 void                    g_menu_item_set_attribute_value                 (GMenuItem          *menu_item,
                                                                          GQuark              attribute_quark,
                                                                          GVariant           *value);
@@ -133,23 +126,11 @@ void                    g_menu_item_set_attribute                       (GMenuIt
                                                                          GQuark              attribute_quark,
                                                                          const gchar        *format_string,
                                                                          ...);
-void                    g_menu_item_set_attribute_value_by_name         (GMenuItem          *menu_item,
-                                                                         const gchar        *attribute_name,
-                                                                         GVariant           *value);
-void                    g_menu_item_set_attribute_by_name               (GMenuItem          *menu_item,
-                                                                         const gchar        *attribute_name,
-                                                                         const gchar        *format_string,
-                                                                         ...);
 GMenuModel *            g_menu_item_get_link                            (GMenuItem          *menu_item,
                                                                          GQuark              link_quark);
-GMenuModel *            g_menu_item_get_link_by_name                    (GMenuItem          *menu_item,
-                                                                         const gchar        *link_name);
 void                    g_menu_item_set_link                            (GMenuItem          *menu_item,
                                                                          GQuark              link_quark,
                                                                          GMenuModel         *link);
-void                    g_menu_item_set_link_by_name                    (GMenuItem          *menu_item,
-                                                                         const gchar        *link_name,
-                                                                         GMenuModel         *link);
 void                    g_menu_item_set_label                           (GMenuItem          *menu_item,
                                                                          const gchar        *label);
 void                    g_menu_item_set_submenu                         (GMenuItem          *menu_item,
diff --git a/gio/gmenumarkup.c b/gio/gmenumarkup.c
index 38cca8e..c84bf34 100644
--- a/gio/gmenumarkup.c
+++ b/gio/gmenumarkup.c
@@ -22,9 +22,9 @@ typedef struct
   struct frame frame;
 
   /* attributes */
+  GQuark        attribute;
   GVariantType *type;
   GString      *string;
-  gchar        *name;
 } GMenuMarkupState;
 
 static void
@@ -170,7 +170,7 @@ g_menu_markup_start_element (GMarkupParseContext  *context,
 
               state->type = typestr ? g_variant_type_new (typestr) : NULL;
               state->string = g_string_new (NULL);
-              state->name = g_strdup (name);
+              state->attribute = g_quark_from_string (name);
               g_menu_markup_push_frame (state, NULL, NULL);
             }
 
@@ -185,10 +185,13 @@ g_menu_markup_start_element (GMarkupParseContext  *context,
           if (COLLECT (STRING,            "name", &name,
                        STRING | OPTIONAL, "id",   &id))
             {
+              GQuark link;
               GMenu *menu;
 
+              link = g_quark_from_string (name);
+
               menu = g_menu_new ();
-              g_menu_item_set_link_by_name (state->frame.item, name, G_MENU_MODEL (menu));
+              g_menu_item_set_link (state->frame.item, link, G_MENU_MODEL (menu));
               g_menu_markup_push_frame (state, menu, NULL);
 
               if (id != NULL)
@@ -238,13 +241,10 @@ g_menu_markup_end_element (GMarkupParseContext  *context,
        */
       if ((value = g_variant_parse (state->type, text, NULL, NULL, error)))
         {
-          g_menu_item_set_attribute_value_by_name (state->frame.item, state->name, value);
+          g_menu_item_set_attribute_value (state->frame.item, state->attribute, value);
           g_variant_unref (value);
         }
 
-      g_free (state->name);
-      state->name = NULL;
-
       if (state->type)
         {
           g_variant_type_free (state->type);
@@ -301,9 +301,6 @@ g_menu_markup_error (GMarkupParseContext *context,
   if (state->type)
     g_variant_type_free (state->type);
 
-  if (state->name)
-    g_free (state->name);
-
   if (state->objects)
     g_hash_table_unref (state->objects);
 
diff --git a/gio/gmenumodel.c b/gio/gmenumodel.c
index a34ff3a..7fb33a7 100644
--- a/gio/gmenumodel.c
+++ b/gio/gmenumodel.c
@@ -251,62 +251,6 @@ g_menu_model_real_iterate_item_attributes (GMenuModel *model,
 }
 
 static GVariant *
-g_menu_model_real_get_item_attribute_value_by_name (GMenuModel         *model,
-                                                    gint                item_index,
-                                                    const gchar        *attribute_name,
-                                                    const GVariantType *expected_type)
-{
-  GHashTable *string_table = NULL;
-  GHashTable *quark_table = NULL;
-  GVariant *dictionary = NULL;
-  GVariant *value = NULL;
-
-  G_MENU_MODEL_GET_CLASS (model)
-    ->get_item_attributes (model, item_index, &quark_table, &string_table, &dictionary);
-
-  if (string_table != NULL)
-    {
-      value = g_hash_table_lookup (string_table, attribute_name);
-
-      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 (quark_table != NULL)
-    {
-      GQuark quark = g_quark_try_string (attribute_name);
-
-      if (quark != 0)
-        value = g_hash_table_lookup (quark_table, GINT_TO_POINTER (quark));
-
-      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 (dictionary != NULL)
-    value = g_variant_lookup_value (dictionary, attribute_name, expected_type);
-
-  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);
-
-  return value;
-}
-
-static GVariant *
 g_menu_model_real_get_item_attribute_value (GMenuModel         *model,
                                             gint                item_index,
                                             GQuark              attribute_quark,
@@ -406,37 +350,6 @@ g_menu_model_real_iterate_item_links (GMenuModel *model,
 }
 
 static GMenuModel *
-g_menu_model_real_get_item_link_by_name (GMenuModel  *model,
-                                         gint         item_index,
-                                         const gchar *link_name)
-{
-  GHashTable *string_table = NULL;
-  GHashTable *quark_table = NULL;
-  GMenuModel *link = NULL;
-
-  G_MENU_MODEL_GET_CLASS (model)
-    ->get_item_links (model, item_index, &quark_table, &string_table);
-
-  if (string_table != NULL)
-    link = g_hash_table_lookup (string_table, link_name);
-
-  else if (quark_table != NULL)
-    {
-      GQuark quark = g_quark_try_string (link_name);
-
-      if (quark != 0)
-        link = g_hash_table_lookup (quark_table, GINT_TO_POINTER (quark));
-    }
-
-  if (string_table != NULL)
-    g_hash_table_unref (string_table);
-  if (quark_table != NULL)
-    g_hash_table_unref (quark_table);
-
-  return link ? g_object_ref (link) : NULL;
-}
-
-static GMenuModel *
 g_menu_model_real_get_item_link (GMenuModel *model,
                                  gint        item_index,
                                  GQuark      link_quark)
@@ -471,10 +384,8 @@ static void
 g_menu_model_class_init (GMenuModelClass *class)
 {
   class->iterate_item_attributes = g_menu_model_real_iterate_item_attributes;
-  class->get_item_attribute_value_by_name = g_menu_model_real_get_item_attribute_value_by_name;
   class->get_item_attribute_value = g_menu_model_real_get_item_attribute_value;
   class->iterate_item_links = g_menu_model_real_iterate_item_links;
-  class->get_item_link_by_name = g_menu_model_real_get_item_link_by_name;
   class->get_item_link = g_menu_model_real_get_item_link;
 
   g_menu_model_items_changed_signal =
@@ -520,41 +431,6 @@ g_menu_model_iterate_item_attributes (GMenuModel *model,
 }
 
 GVariant *
-g_menu_model_get_item_attribute_value_by_name (GMenuModel         *model,
-                                               gint                item_index,
-                                               const gchar        *attribute_name,
-                                               const GVariantType *expected_type)
-{
-  return G_MENU_MODEL_GET_CLASS (model)
-    ->get_item_attribute_value_by_name (model, item_index, attribute_name, expected_type);
-}
-
-gboolean
-g_menu_model_get_item_attribute_by_name (GMenuModel  *model,
-                                         gint         item_index,
-                                         const gchar *attribute_name,
-                                         const gchar *format_string,
-                                         ...)
-{
-  const GVariantType *expected_type;
-  GVariant *value;
-  va_list ap;
-
-  expected_type = NULL; /* XXX devine the type, ensure no '&' */
-
-  value = g_menu_model_get_item_attribute_value_by_name (model, item_index, attribute_name, expected_type);
-  if (value == NULL)
-    return FALSE;
-
-  va_start (ap, format_string);
-  g_variant_get_va (value, format_string, NULL, &ap);
-  g_variant_unref (value);
-  va_end (ap);
-
-  return TRUE;
-}
-
-GVariant *
 g_menu_model_get_item_attribute_value (GMenuModel         *model,
                                        gint                item_index,
                                        GQuark              attribute_quark,
@@ -598,15 +474,6 @@ g_menu_model_iterate_item_links (GMenuModel *model,
 }
 
 GMenuModel *
-g_menu_model_get_item_link_by_name (GMenuModel  *model,
-                                    gint         item_index,
-                                    const gchar *link_name)
-{
-  return G_MENU_MODEL_GET_CLASS (model)
-    ->get_item_link_by_name (model, item_index, link_name);
-}
-
-GMenuModel *
 g_menu_model_get_item_link (GMenuModel *model,
                             gint        item_index,
                             GQuark      link_quark)
@@ -789,38 +656,6 @@ g_menu_model_item_iterate_attributes (GMenuModelItem *item)
 }
 
 GVariant *
-g_menu_model_item_get_attribute_value_by_name (GMenuModelItem     *item,
-                                               const gchar        *attribute_name,
-                                               const GVariantType *expected_type)
-{
-  return g_menu_model_get_item_attribute_value_by_name (item->model, item->index_, attribute_name, expected_type);
-}
-
-gboolean
-g_menu_model_item_get_attribute_by_name (GMenuModelItem *item,
-                                         const gchar    *attribute_name,
-                                         const gchar    *format_string,
-                                         ...)
-{
-  const GVariantType *expected_type;
-  GVariant *value;
-  va_list ap;
-
-  expected_type = NULL; /* XXX devine the type, ensure no '&' */
-
-  value = g_menu_model_get_item_attribute_value_by_name (item->model, item->index_, attribute_name, expected_type);
-  if (value == NULL)
-    return FALSE;
-
-  va_start (ap, format_string);
-  g_variant_get_va (value, format_string, NULL, &ap);
-  g_variant_unref (value);
-  va_end (ap);
-
-  return TRUE;
-}
-
-GVariant *
 g_menu_model_item_get_attribute_value (GMenuModelItem     *item,
                                        GQuark              attribute_quark,
                                        const GVariantType *expected_type)
@@ -859,13 +694,6 @@ g_menu_model_item_iterate_links (GMenuModelItem *item)
 }
 
 GMenuModel *
-g_menu_model_item_get_link_by_name (GMenuModelItem *item,
-                                    const gchar    *link_name)
-{
-  return g_menu_model_get_item_link_by_name (item->model, item->index_, link_name);
-}
-
-GMenuModel *
 g_menu_model_item_get_link (GMenuModelItem *item,
                             GQuark          link_quark)
 {
diff --git a/gio/gmenumodel.h b/gio/gmenumodel.h
index 053e83b..e74f7de 100644
--- a/gio/gmenumodel.h
+++ b/gio/gmenumodel.h
@@ -71,10 +71,6 @@ struct _GMenuModelClass
                                                               GVariant          **dictionary);
   GMenuAttributeIter *  (*iterate_item_attributes)           (GMenuModel         *model,
                                                               gint                item_index);
-  GVariant *            (*get_item_attribute_value_by_name) (GMenuModel          *model,
-                                                             gint                 item_index,
-                                                             const gchar         *attribute_name,
-                                                             const GVariantType  *expected_type);
   GVariant *            (*get_item_attribute_value)         (GMenuModel          *model,
                                                              gint                 item_index,
                                                              GQuark               attribute_quark,
@@ -86,9 +82,6 @@ struct _GMenuModelClass
                                                              GHashTable         **string_table);
   GMenuLinkIter *       (*iterate_item_links)               (GMenuModel          *model,
                                                              gint                 item_index);
-  GMenuModel *          (*get_item_link_by_name)            (GMenuModel          *model,
-                                                             gint                 item_index,
-                                                             const gchar         *link_name);
   GMenuModel *          (*get_item_link)                    (GMenuModel          *model,
                                                              gint                 item_index,
                                                              GQuark               link_quark);
@@ -104,15 +97,6 @@ void                    g_menu_model_get_item                           (GMenuMo
 
 GMenuAttributeIter *    g_menu_model_iterate_item_attributes            (GMenuModel         *model,
                                                                          gint                item_index);
-GVariant *              g_menu_model_get_item_attribute_value_by_name   (GMenuModel         *model,
-                                                                         gint                item_index,
-                                                                         const gchar        *attribute_name,
-                                                                         const GVariantType *expected_type);
-gboolean                g_menu_model_get_item_attribute_by_name         (GMenuModel         *model,
-                                                                         gint                item_index,
-                                                                         const gchar        *attribute_name,
-                                                                         const gchar        *format_string,
-                                                                         ...);
 GVariant *              g_menu_model_get_item_attribute_value           (GMenuModel         *model,
                                                                          gint                item_index,
                                                                          GQuark              attribute_quark,
@@ -124,9 +108,6 @@ gboolean                g_menu_model_get_item_attribute                 (GMenuMo
                                                                          ...);
 GMenuLinkIter *         g_menu_model_iterate_item_links                 (GMenuModel         *model,
                                                                          gint                item_index);
-GMenuModel *            g_menu_model_get_item_link_by_name              (GMenuModel         *model,
-                                                                         gint                item_index,
-                                                                         const gchar        *link_name);
 GMenuModel *            g_menu_model_get_item_link                      (GMenuModel         *model,
                                                                          gint                item_index,
                                                                          GQuark              link_quark);
@@ -218,13 +199,6 @@ struct _GMenuModelItem
 };
 
 GMenuAttributeIter *    g_menu_model_item_iterate_attributes            (GMenuModelItem     *item);
-GVariant *              g_menu_model_item_get_attribute_value_by_name   (GMenuModelItem     *item,
-                                                                         const gchar        *attribute_name,
-                                                                         const GVariantType *expected_type);
-gboolean                g_menu_model_item_get_attribute_by_name         (GMenuModelItem     *item,
-                                                                         const gchar        *attribute_name,
-                                                                         const gchar        *format_string,
-                                                                         ...);
 GVariant *              g_menu_model_item_get_attribute_value           (GMenuModelItem     *item,
                                                                          GQuark              attribute_quark,
                                                                          const GVariantType *expected_type);
@@ -233,8 +207,6 @@ gboolean                g_menu_model_item_get_attribute                 (GMenuMo
                                                                          const gchar        *format_string,
                                                                          ...);
 GMenuLinkIter *         g_menu_model_item_iterate_links                 (GMenuModelItem     *item);
-GMenuModel *            g_menu_model_item_get_link_by_name              (GMenuModelItem     *item,
-                                                                         const gchar        *link_name);
 GMenuModel *            g_menu_model_item_get_link                      (GMenuModelItem     *item,
                                                                          GQuark              link_quark);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]