[libchamplain] Return back using state for local rendering data download notification



commit 258280403b31598c093c72b786bb104f7916bd96
Author: JiÅ?í Techet <techet gmail com>
Date:   Mon Aug 2 23:41:12 2010 +0200

    Return back using state for local rendering data download notification
    
    It is probably cleaner solution than the signal I have introduced.
    
    Signed-off-by: JiÅ?í Techet <techet gmail com>

 champlain/champlain-network-bbox-tile-source.c |   51 ++++++++++++++++--------
 demos/local-rendering.c                        |   27 ++++++++----
 2 files changed, 52 insertions(+), 26 deletions(-)
---
diff --git a/champlain/champlain-network-bbox-tile-source.c b/champlain/champlain-network-bbox-tile-source.c
index 7371de4..4b0746c 100644
--- a/champlain/champlain-network-bbox-tile-source.c
+++ b/champlain/champlain-network-bbox-tile-source.c
@@ -51,16 +51,10 @@ G_DEFINE_TYPE (ChamplainNetworkBboxTileSource, champlain_network_bbox_tile_sourc
 
 enum
 {
-  /* normal signals */
-  DATA_LOADED,
-  LAST_SIGNAL
-};
-
-enum
-{
   PROP_0,
   PROP_API_URI,
-  PROP_PROXY_URI
+  PROP_PROXY_URI,
+  PROP_STATE
 };
 
 struct _ChamplainNetworkBboxTileSourcePrivate
@@ -68,10 +62,9 @@ struct _ChamplainNetworkBboxTileSourcePrivate
   gchar *api_uri;
   gchar *proxy_uri;
   SoupSession *soup_session;
+  ChamplainState state;
 };
 
-static guint champlain_network_bbox_tile_source_signals[LAST_SIGNAL] = { 0, };
-
 static void fill_tile (ChamplainMapSource *map_source,
     ChamplainTile *tile);
 
@@ -97,6 +90,10 @@ champlain_network_bbox_tile_source_get_property (GObject *object,
       g_value_set_string (value, priv->proxy_uri);
       break;
 
+    case PROP_STATE:
+      g_value_set_enum (value, priv->state);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
     }
@@ -129,6 +126,11 @@ champlain_network_bbox_tile_source_set_property (GObject *object,
             soup_uri_new (priv->proxy_uri), NULL);
       break;
 
+    case PROP_STATE:
+      priv->state = g_value_get_enum (value);
+      g_object_notify (G_OBJECT (self), "state");
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
     }
@@ -210,12 +212,23 @@ champlain_network_bbox_tile_source_class_init (ChamplainNetworkBboxTileSourceCla
           "The proxy URI to use to access network",
           "",
           G_PARAM_READWRITE));
-
-  champlain_network_bbox_tile_source_signals[DATA_LOADED] =
-    g_signal_new ("data-loaded", G_OBJECT_CLASS_TYPE (object_class),
-        G_SIGNAL_RUN_LAST, 0, NULL, NULL,
-        g_cclosure_marshal_VOID__VOID, G_TYPE_NONE,
-        0, NULL);
+          
+  /*
+  * ChamplainMapDataSource:state:
+  *
+  * The map data source's state. Useful to know if the data source is loading
+  * or not.
+  *
+  * Since: 0.6
+  */
+  g_object_class_install_property (object_class,
+       PROP_STATE,
+       g_param_spec_enum ("state",
+           "map data source's state",
+           "The state of the map data source",
+           CHAMPLAIN_TYPE_STATE,
+           CHAMPLAIN_STATE_NONE,
+           G_PARAM_READWRITE));
 }
 
 
@@ -238,6 +251,8 @@ champlain_network_bbox_tile_source_init (ChamplainNetworkBboxTileSource *self)
   g_object_set (G_OBJECT (priv->soup_session),
       "user-agent", "libchamplain/" CHAMPLAIN_VERSION_S,
       "max-conns-per-host", 2, NULL);
+      
+  priv->state = CHAMPLAIN_STATE_NONE;
 }
 
 
@@ -294,7 +309,7 @@ load_map_data_cb (G_GNUC_UNUSED SoupSession *session, SoupMessage *msg,
       return;
     }
 
-  g_signal_emit_by_name (self, "data-loaded", NULL);
+  g_object_set (G_OBJECT (self), "state", CHAMPLAIN_STATE_DONE, NULL);
 
   renderer = champlain_map_source_get_renderer (CHAMPLAIN_MAP_SOURCE (self));
   champlain_renderer_set_data (renderer, msg->response_body->data, msg->response_body->length);
@@ -344,6 +359,8 @@ champlain_network_bbox_tile_source_load_map_data (
   DEBUG ("Request BBox data: '%s'", url);
 
   g_free (url);
+  
+  g_object_set (G_OBJECT (self), "state", CHAMPLAIN_STATE_LOADING, NULL);
 
   soup_session_queue_message (priv->soup_session, msg, load_map_data_cb, self);
 }
diff --git a/demos/local-rendering.c b/demos/local-rendering.c
index 2284f21..2602496 100644
--- a/demos/local-rendering.c
+++ b/demos/local-rendering.c
@@ -86,21 +86,32 @@ color_clutter_to_gdk (const ClutterColor *clutter_color,
 static void
 reload_tiles ()
 {
-  champlain_memory_cache_clean (memory_cache);
+  if (memory_cache)
+    champlain_memory_cache_clean (memory_cache);
   champlain_view_reload_tiles (champlain_view);
 }
 
 
 static void
 data_source_state_changed (ChamplainNetworkBboxTileSource *source,
+    GParamSpec *gobject,
     GtkImage *image)
 {
-  gtk_image_clear (image);
+  ChamplainState state;
+
+  g_object_get (G_OBJECT (source), "state", &state, NULL);
+  if (state == CHAMPLAIN_STATE_LOADING)
+    {
+      gtk_image_set_from_stock (image, GTK_STOCK_NETWORK, GTK_ICON_SIZE_BUTTON);
+      g_print ("NET DATA SOURCE STATE: loading\n");
+    }
+  else
+    {
+      gtk_image_clear (image);
+      g_print ("NET DATA SOURCE STATE: done\n");
+    }
+  
   reload_tiles ();
-  g_print ("NET DATA SOURCE STATE: done\n");
-  g_signal_handlers_disconnect_by_func (source,
-      data_source_state_changed,
-      image);
 }
 
 
@@ -109,11 +120,9 @@ load_network_map_data (ChamplainNetworkBboxTileSource *source, ChamplainView *vi
 {
   gdouble lat, lon;
 
-  g_signal_connect (source, "data-loaded", G_CALLBACK (data_source_state_changed),
+  g_signal_connect (source, "notify::state", G_CALLBACK (data_source_state_changed),
       map_data_state_img);
 
-  gtk_image_set_from_stock (GTK_IMAGE (map_data_state_img), GTK_STOCK_NETWORK, GTK_ICON_SIZE_BUTTON);
-  g_print ("NET DATA SOURCE STATE: loading\n");
   g_object_get (G_OBJECT (view), "latitude", &lat, "longitude", &lon, NULL);
 
   champlain_network_bbox_tile_source_load_map_data (source,



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