static void
contact_constructed (GObject *object)
{
  EmpathyContact *contact = (EmpathyContact *) object;
  EmpathyContactPriv *priv = GET_PRIV (contact);
  GHashTable *location;
  TpHandle self_handle;
  TpHandle handle;

  if (priv->tp_contact == NULL)
    return;

  priv->presence = empathy_contact_get_presence (contact);

  location = tp_contact_get_location (priv->tp_contact);
  if (location != NULL)
    empathy_contact_set_location (contact, location);

  set_capabilities_from_tp_caps (contact,
      tp_contact_get_capabilities (priv->tp_contact));

  contact_set_avatar_from_tp_contact (contact);

  /* Set is-user property. Note that it could still be the handle is
   * different from the connection's self handle, in the case the handle
   * comes from a group interface. */
  self_handle = tp_connection_get_self_handle (
      tp_contact_get_connection (priv->tp_contact));
  handle = tp_contact_get_handle (priv->tp_contact);
  empathy_contact_set_is_user (contact, self_handle == handle);

  g_signal_connect (priv->tp_contact, "notify",
    G_CALLBACK (tp_contact_notify_cb), contact);
}
Beispiel #2
0
static void
tp_chat_got_self_contact_cb (EmpathyTpContactFactory *factory,
			     EmpathyContact          *contact,
			     const GError            *error,
			     gpointer                 user_data,
			     GObject                 *chat)
{
	EmpathyTpChatPriv *priv = GET_PRIV (chat);

	if (error) {
		DEBUG ("Error: %s", error->message);
		empathy_tp_chat_close (EMPATHY_TP_CHAT (chat));
		return;
	}

	priv->user = g_object_ref (contact);
	empathy_contact_set_is_user (priv->user, TRUE);
	tp_chat_check_if_ready (EMPATHY_TP_CHAT (chat));
}
static void
tp_contact_factory_add_contact (EmpathyTpContactFactory *tp_factory,
				EmpathyContact          *contact)
{
	EmpathyTpContactFactoryPriv *priv = GET_PRIV (tp_factory);
	TpHandle self_handle;
	TpHandle handle;
	GArray handles = {(gchar *) &handle, 1};
	EmpathyCapabilities caps;

	/* Keep a weak ref to that contact */
	g_object_weak_ref (G_OBJECT (contact),
			   tp_contact_factory_weak_notify,
			   tp_factory);
	priv->contacts = g_list_prepend (priv->contacts, contact);

	/* The contact keeps a ref to its factory */
	g_object_set_data_full (G_OBJECT (contact), "empathy-factory",
				g_object_ref (tp_factory),
				g_object_unref);

	caps = empathy_contact_get_capabilities (contact);

	/* Set the FT capability */
	if (!priv->contact_caps_supported) {
		/* ContactCapabilities is not supported; assume all contacts can do file
		 * transfer if it's implemented in the CM */
		if (priv->can_request_ft) {
			caps |= EMPATHY_CAPABILITIES_FT;
		}

		/* Set the Stream Tube capability */
		if (priv->can_request_st) {
			caps |= EMPATHY_CAPABILITIES_STREAM_TUBE;
		}
	}

	empathy_contact_set_capabilities (contact, caps);

	/* Set is-user property. Note that it could still be the handle is
	 * different from the connection's self handle, in the case the handle
	 * comes from a group interface. */
	self_handle = tp_connection_get_self_handle (priv->connection);
	handle = empathy_contact_get_handle (contact);
	empathy_contact_set_is_user (contact, self_handle == handle);

	/* FIXME: This should be done by TpContact */
	if (tp_proxy_has_interface_by_id (priv->connection,
			TP_IFACE_QUARK_CONNECTION_INTERFACE_AVATARS)) {
		tp_cli_connection_interface_avatars_call_get_known_avatar_tokens (
			priv->connection, -1, &handles,
			tp_contact_factory_got_known_avatar_tokens, NULL, NULL,
			G_OBJECT (tp_factory));
	}

	if (priv->contact_caps_supported) {
		tp_cli_connection_interface_contact_capabilities_call_get_contact_capabilities (
			priv->connection, -1, &handles,
			tp_contact_factory_got_contact_capabilities, NULL, NULL,
			G_OBJECT (tp_factory));
	}
	else if (tp_proxy_has_interface_by_id (priv->connection,
			TP_IFACE_QUARK_CONNECTION_INTERFACE_CAPABILITIES)) {
		tp_cli_connection_interface_capabilities_call_get_capabilities (
			priv->connection, -1, &handles,
			tp_contact_factory_got_capabilities, NULL, NULL,
			G_OBJECT (tp_factory));
	}

	DEBUG ("Contact added: %s (%d)",
		empathy_contact_get_id (contact),
		empathy_contact_get_handle (contact));
}
Beispiel #4
0
GList *
empathy_log_manager_get_messages_for_file (EmpathyLogManager *manager,
					   const gchar       *filename)
{
	GList               *messages = NULL;
	xmlParserCtxtPtr     ctxt;
	xmlDocPtr            doc;
	xmlNodePtr           log_node;
	xmlNodePtr           node;
	EmpathyLogSearchHit *hit;
	McAccount           *account;

	g_return_val_if_fail (EMPATHY_IS_LOG_MANAGER (manager), NULL);
	g_return_val_if_fail (filename != NULL, NULL);

	DEBUG ("Attempting to parse filename:'%s'...", filename);

	if (!g_file_test (filename, G_FILE_TEST_EXISTS)) {
		DEBUG ("Filename:'%s' does not exist", filename);
		return NULL;
	}

	/* Get the account from the filename */
	hit = log_manager_search_hit_new (manager, filename);
	account = g_object_ref (hit->account);
	log_manager_search_hit_free (hit);

	/* Create parser. */
	ctxt = xmlNewParserCtxt ();

	/* Parse and validate the file. */
	doc = xmlCtxtReadFile (ctxt, filename, NULL, 0);
	if (!doc) {
		g_warning ("Failed to parse file:'%s'", filename);
		xmlFreeParserCtxt (ctxt);
		return NULL;
	}

	/* The root node, presets. */
	log_node = xmlDocGetRootElement (doc);
	if (!log_node) {
		xmlFreeDoc (doc);
		xmlFreeParserCtxt (ctxt);
		return NULL;
	}

	/* Now get the messages. */
	for (node = log_node->children; node; node = node->next) {
		EmpathyMessage     *message;
		EmpathyContact     *sender;
		gchar              *time;
		time_t              t;
		gchar              *sender_id;
		gchar              *sender_name;
		gchar              *sender_avatar_token;
		gchar              *body;
		gchar              *is_user_str;
		gboolean            is_user = FALSE;
		gchar              *msg_type_str;
		TpChannelTextMessageType msg_type = TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL;

		if (strcmp (node->name, "message") != 0) {
			continue;
		}

		body = xmlNodeGetContent (node);
		time = xmlGetProp (node, "time");
		sender_id = xmlGetProp (node, "id");
		sender_name = xmlGetProp (node, "name");
		sender_avatar_token = xmlGetProp (node, "token");
		is_user_str = xmlGetProp (node, "isuser");
		msg_type_str = xmlGetProp (node, "type");

		if (is_user_str) {
			is_user = strcmp (is_user_str, "true") == 0;
		}
		if (msg_type_str) {
			msg_type = empathy_message_type_from_str (msg_type_str);
		}

		t = empathy_time_parse (time);

		sender = empathy_contact_new_full (account, sender_id, sender_name);
		empathy_contact_set_is_user (sender, is_user);
		if (!EMP_STR_EMPTY (sender_avatar_token)) {
			empathy_contact_load_avatar_cache (sender,
							   sender_avatar_token);
		}

		message = empathy_message_new (body);
		empathy_message_set_sender (message, sender);
		empathy_message_set_timestamp (message, t);
		empathy_message_set_tptype (message, msg_type);

		messages = g_list_append (messages, message);

		g_object_unref (sender);
		xmlFree (time);
		xmlFree (sender_id);
		xmlFree (sender_name);
		xmlFree (body);
		xmlFree (is_user_str);
		xmlFree (msg_type_str);
	}

	DEBUG ("Parsed %d messages", g_list_length (messages));

	xmlFreeDoc (doc);
	xmlFreeParserCtxt (ctxt);

	return messages;
}