[gnome-control-center/gsoc2011/location] Solve a week of headbanging with g_variant_ref_sink ()



commit fd4d344466567a2e7177c2b983722fac23956ded
Author: StÃphane Maniaci <stephane maniaci gmail com>
Date:   Fri Jul 22 20:21:08 2011 +0200

    Solve a week of headbanging with g_variant_ref_sink ()

 panels/location/cc-location-panel.c |   11 +++++----
 panels/location/location-utils.c    |   41 +++-------------------------------
 2 files changed, 10 insertions(+), 42 deletions(-)
---
diff --git a/panels/location/cc-location-panel.c b/panels/location/cc-location-panel.c
index 01f1102..63bc822 100644
--- a/panels/location/cc-location-panel.c
+++ b/panels/location/cc-location-panel.c
@@ -61,7 +61,6 @@ static void
 populate_locations (GtkListStore *store,
                     GVariant     *locations)
 {
-  g_debug ("Updating liststore with new locations");
   GtkTreeIter iter;
   GVariantIter viter;
   GVariant *dict;
@@ -94,15 +93,16 @@ populate_locations (GtkListStore *store,
 
     gtk_list_store_set (store, &iter, 3, "20:00", -1);
 
-    value = g_variant_lookup_value (dict,
+    /*value = g_variant_lookup_value (dict,
                                     "longitude",
                                     G_VARIANT_TYPE_DOUBLE);
-    //    gtk_list_store_set (store, &iter, 1, g_variant_get_double (value), -1);
+    gtk_list_store_set (store, &iter, 1, g_variant_get_double (value), -1);
 
     value = g_variant_lookup_value (dict,
                                     "latitude",
                                     G_VARIANT_TYPE_DOUBLE);
-    // gtk_list_store_set (store, &iter, 1, g_variant_get_double (value), -1);
+    gtk_list_store_set (store, &iter, 1, g_variant_get_double (value), -1);
+    */
   }
 }
 
@@ -121,7 +121,7 @@ _on_add_location (GtkToolButton   *bt,
 
   switch (res) {
     case GTK_RESPONSE_OK:
-      printf ("s");
+      printf ("Dialog response OK\n");
       // FIXME: column ids
       const char *city = gtk_entry_get_text (GTK_ENTRY (WID ("city-entry")));
       const char *ctry = gtk_entry_get_text (GTK_ENTRY (WID ("country-entry")));
@@ -134,6 +134,7 @@ _on_add_location (GtkToolButton   *bt,
       g_assert (g_settings_set_value (priv->location_settings,
                                       "locations",
                                       priv->locations));
+
       gtk_list_store_clear (priv->location_store);
       populate_locations (priv->location_store,
                           priv->locations);
diff --git a/panels/location/location-utils.c b/panels/location/location-utils.c
index 0a93c01..e48aaf7 100644
--- a/panels/location/location-utils.c
+++ b/panels/location/location-utils.c
@@ -40,7 +40,6 @@ g_variant_location_new (const char  *city,
   g_variant_builder_add_parsed (builder, "{'latitude', <%d>}", latitude);
 
   GVariant *val = g_variant_builder_end (builder);
-  g_variant_location_print (val);
   return val;
 }
 
@@ -48,51 +47,19 @@ GVariant *
 g_variant_array_add_value (GVariant *container,
                            GVariant *value)
 {
-  g_debug ("Adding value to the locations array");
-
   GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE_ARRAY);
   GVariantIter iter;
   GVariant *val;
 
   g_variant_iter_init (&iter, container);
-  g_debug ("About to loop in the previous locations");
   while ((val = g_variant_iter_next_value (&iter))) {
-    g_debug ("In the loop\n");
-    g_variant_location_print (val);
     g_variant_builder_add_value (builder, val);
   }
-  g_debug ("Added the previous locations");
   g_variant_builder_add_value (builder, value);
 
-  return g_variant_builder_end (builder);
-}
-
-void
-g_variant_location_print (GVariant *location)
-{
-  g_print("Location:\n");
-  g_print ("\tcity:%s\n"
-           "\tcountry: %s\n"
-           "\ttimezone: %i\n"
-           "\tlong: %f\n"
-           "\tlat: %f\n",
-           g_variant_get_string (g_variant_lookup_value (location,
-                                                         "city",
-                                                         G_VARIANT_TYPE_STRING),
-                                 NULL),
-           g_variant_get_string (g_variant_lookup_value (location,
-                                                         "country",
-                                                         G_VARIANT_TYPE_STRING),
-                                 NULL),
-           g_variant_get_int16 (g_variant_lookup_value (location,
-                                                        "timezone",
-                                                        G_VARIANT_TYPE_INT16)),
-           g_variant_get_double (g_variant_lookup_value (location,
-                                                         "latitude",
-                                                         G_VARIANT_TYPE_DOUBLE)),
-           g_variant_get_double (g_variant_lookup_value (location,
-                                                         "longitude",
-                                                         G_VARIANT_TYPE_DOUBLE))
-           );
+  GVariant *res = g_variant_builder_end (builder);
+  g_variant_builder_unref (builder);
 
+  g_variant_ref_sink (res);
+  return res;
 }



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