GtkWidget *
empathy_contact_log_menu_item_new (EmpathyContact *contact)
{
	TplLogManager     *manager;
	TplEntity         *entity;
	gboolean           have_log;
	GtkWidget         *item;
	GtkWidget         *image;

	g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);

	manager = tpl_log_manager_dup_singleton ();
	entity = tpl_entity_new_from_tp_contact (empathy_contact_get_tp_contact (contact),
						 TPL_ENTITY_CONTACT);

	have_log = tpl_log_manager_exists (manager,
					   empathy_contact_get_account (contact),
					   entity,
					   TPL_EVENT_MASK_TEXT);

	g_object_unref (entity);
	g_object_unref (manager);

	item = gtk_image_menu_item_new_with_mnemonic (_("_Previous Conversations"));
	image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_LOG,
					      GTK_ICON_SIZE_MENU);
	gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
	gtk_widget_set_sensitive (item, have_log);
	gtk_widget_show (image);

	g_signal_connect_swapped (item, "activate",
				  G_CALLBACK (contact_log_menu_item_activate_cb),
				  contact);

	return item;
}
static void
chat_conversations_list_connection_prepare (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
  ChatConversationsList *self = CHAT_CONVERSATIONS_LIST (user_data);
  ChatConversationsListPrivate *priv = self->priv;
  GError *error;
  GList *contacts = NULL;
  GPtrArray *contact_list = NULL;
  TpAccount *account;
  TpConnection *conn = TP_CONNECTION (source_object);
  TpContactListState state;
  guint i;

  error = NULL;
  if (!tp_proxy_prepare_finish (source_object, res, &error))
    {
      g_warning ("Unable to prepare the connection: %s", error->message);
      g_error_free (error);
      goto out;
    }

  state = tp_connection_get_contact_list_state (conn);
  if (state != TP_CONTACT_LIST_STATE_SUCCESS)
    {
      g_warning ("Value of connection:contact-list-state %p was %d", conn, state);
      goto out;
    }

  account = tp_connection_get_account (conn);
  contact_list = tp_connection_dup_contact_list (conn);
  for (i = 0; i < contact_list->len; i++)
    {
      ChatConversationsListGetFilteredEventsData *data;
      TpContact *contact;
      TplEntity *entity;

      contact = TP_CONTACT (g_ptr_array_index (contact_list, i));
      entity = tpl_entity_new_from_tp_contact (contact, TPL_ENTITY_CONTACT);
      if (tpl_log_manager_exists (priv->lm, account, entity, TPL_EVENT_MASK_TEXT))
        {
          g_message ("%s", tp_contact_get_alias (contact));
          contacts = g_list_prepend (contacts, g_object_ref (contact));

          data = chat_conversations_list_get_filtered_events_data_new (self, contact);
          tpl_log_manager_get_filtered_events_async (priv->lm,
                                                     account,
                                                     entity,
                                                     TPL_EVENT_MASK_TEXT,
                                                     1,
                                                     NULL,
                                                     NULL,
                                                     chat_conversations_list_get_filtered_events,
                                                     data);
        }

      g_object_unref (entity);
    }

  g_hash_table_insert (priv->accounts, g_object_ref (account), contacts);

 out:
  if (contact_list != NULL)
    g_ptr_array_unref (contact_list);
  g_object_unref (self);
}