/* This callback is called by geoclue when it found a position
 * for the given address.  A position is necessary for a contact
 * to show up on the map
 */
static void
geocode_cb (GeoclueGeocode *geocode,
	    GeocluePositionFields fields,
	    double latitude,
	    double longitude,
	    double altitude,
	    GeoclueAccuracy *accuracy,
	    GError *error,
	    gpointer contact)
{
	GValue *new_value;
	GHashTable *location;

	location = empathy_contact_get_location (EMPATHY_CONTACT (contact));

	if (error != NULL) {
		DEBUG ("Error geocoding location : %s", error->message);
		g_object_unref (geocode);
		g_object_unref (contact);
		return;
	}

	if (fields & GEOCLUE_POSITION_FIELDS_LATITUDE) {
		new_value = tp_g_value_slice_new_double (latitude);
		g_hash_table_replace (location, g_strdup (EMPATHY_LOCATION_LAT),
			new_value);
		DEBUG ("\t - Latitude: %f", latitude);
	}
	if (fields & GEOCLUE_POSITION_FIELDS_LONGITUDE) {
		new_value = tp_g_value_slice_new_double (longitude);
		g_hash_table_replace (location, g_strdup (EMPATHY_LOCATION_LON),
			new_value);
		DEBUG ("\t - Longitude: %f", longitude);
	}
	if (fields & GEOCLUE_POSITION_FIELDS_ALTITUDE) {
		new_value = tp_g_value_slice_new_double (altitude);
		g_hash_table_replace (location, g_strdup (EMPATHY_LOCATION_ALT),
			new_value);
		DEBUG ("\t - Altitude: %f", altitude);
	}

	/* Don't change the accuracy as we used an address to get this position */
	g_object_notify (contact, "location");
	g_object_unref (geocode);
	g_object_unref (contact);
}
Esempio n. 2
0
static GValue *
empathy_plist_parse_real (xmlNode *a_node)
{
	char *str_val;
	char *end_ptr;
	gdouble double_val;

	str_val = (char *) xmlNodeGetContent (a_node);
	double_val = g_ascii_strtod (str_val, &end_ptr);
	if (*end_ptr != '\0') {
		xmlFree (str_val);
		return NULL;
	}
	xmlFree (str_val);

	return tp_g_value_slice_new_double (double_val);
}
Esempio n. 3
0
static gboolean
update_location_from_msg (GabbleConnection *conn,
                          TpHandle contact,
                          LmMessage *msg)
{
  LmMessageNode *node;
  GHashTable *location = g_hash_table_new_full (g_direct_hash, g_direct_equal,
      g_free, (GDestroyNotify) tp_g_value_slice_free);
  TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (
      (TpBaseConnection *) conn, TP_HANDLE_TYPE_CONTACT);
  const gchar *from = tp_handle_inspect (contact_repo, contact);
  NodeIter i;
  const gchar *lang;

  node = lm_message_node_find_child (wocky_stanza_get_top_node (msg),
      "geoloc");
  if (node == NULL)
    return FALSE;

  DEBUG ("LocationsUpdate for %s:", from);

  lang = lm_message_node_get_attribute (node, "xml:lang");
  if (lang != NULL)
    {
      g_hash_table_insert (location, g_strdup ("language"),
          tp_g_value_slice_new_string (lang));
    }

  build_mapping_tables ();

  for (i = node_iter (node); i; i = node_iter_next (i))
    {
      LmMessageNode *subloc_node = node_iter_data (i);
      GValue *value = NULL;
      gchar *xmpp_name;
      const gchar *str;
      LocationMapping *mapping;

      xmpp_name = subloc_node->name;
      str = lm_message_node_get_value (subloc_node);
      if (str == NULL)
        continue;

      mapping = g_hash_table_lookup (xmpp_to_tp, xmpp_name);
      if (mapping == NULL)
        {
          DEBUG ("Unknown location attribute: %s\n", xmpp_name);
          continue;
        }

      if (mapping->type == G_TYPE_DOUBLE)
        {
          gdouble double_value;
          gchar *end;

          double_value = g_ascii_strtod (str, &end);

          if (end == str)
            continue;

          value = tp_g_value_slice_new_double (double_value);
          DEBUG ("\t - %s: %f", xmpp_name, double_value);
        }
      else if (strcmp (xmpp_name, "timestamp") == 0)
        {
          GTimeVal timeval;
          if (g_time_val_from_iso8601 (str, &timeval))
            {
              value = tp_g_value_slice_new_int64 (timeval.tv_sec);
              DEBUG ("\t - %s: %s", xmpp_name, str);
            }
          else
            {
              DEBUG ("\t - %s: %s: unknown date format", xmpp_name, str);
              continue;
            }
        }
      else if (mapping->type == G_TYPE_STRING)
        {
          value = tp_g_value_slice_new_string (str);
          DEBUG ("\t - %s: %s", xmpp_name, str);
        }
      else
        {
          g_assert_not_reached ();
        }

      g_hash_table_insert (location, g_strdup (mapping->tp_name), value);
    }

  tp_svc_connection_interface_location_emit_location_updated (conn,
      contact, location);
  gabble_presence_cache_update_location (conn->presence_cache, contact,
      location);

  return TRUE;
}