Example #1
0
static void
moko_contacts_init (MokoContacts *contacts)
{
  MokoContactsPrivate *priv;
  EBook *book;
  EBookView *view;
  EBookQuery *query;
  GList *contact, *c;

  priv = contacts->priv = MOKO_CONTACTS_GET_PRIVATE (contacts);

  priv->contacts = NULL;
  priv->entries = NULL;
  priv->start = NULL;
  priv->prefixes = g_hash_table_new ((GHashFunc)g_str_hash,
                                     (GEqualFunc)g_str_equal);
  priv->uids = g_hash_table_new ((GHashFunc)g_str_hash,
                                     (GEqualFunc)g_str_equal);
  query = e_book_query_any_field_contains ("");

  /* Open the system book and check that it is valid */
  book = priv->book = e_book_new_system_addressbook (NULL);
  if (!book)
  {
    g_warning ("Failed to create system book\n");
    return;
  }
  
  if (!e_book_open (book, FALSE, NULL))
  {
    g_warning ("Failed to open system book\n");
    return;
  }  
  
  if (!e_book_get_contacts (book, query, &contact, NULL)) 	 
  { 	 
     g_warning ("Failed to get contacts from system book\n"); 	 
     return; 	 
  } 	 
  	 
  /* Go through the contacts, creating the contact structs, and entry structs*/ 	 
  for (c = contact; c != NULL; c = c->next) 	 
  { 	 
     moko_contacts_add_contact (contacts, E_CONTACT (c->data)); 	 
  }

  /* Connect to the ebookviews signals */
  if (e_book_get_book_view (book, query, NULL, 0, &view, NULL))
  {
    g_signal_connect (G_OBJECT (view), "contacts-added",
                      G_CALLBACK (on_ebook_contacts_added), (gpointer)contacts);
    g_signal_connect (G_OBJECT (view), "contacts-changed",
                    G_CALLBACK (on_ebook_contacts_changed), (gpointer)contacts);
    g_signal_connect (G_OBJECT (view), "contacts-removed",
                    G_CALLBACK (on_ebook_contacts_removed), (gpointer)contacts);

    e_book_view_start (view);
  }
  e_book_query_unref(query);
}
static void
scan_objects (gpointer data, gpointer user_data)
{
    ScanContext *context;
    ScalixContact *contact;
    EBookBackendSExp *sexp;
    char *ostr;
    gboolean is_search;

    context = (ScanContext *) user_data;
    contact = SCALIX_CONTACT (data);
    sexp = context->sexp;
    is_search = context->search_needed;

    if (!is_search
        || e_book_backend_sexp_match_contact (sexp, E_CONTACT (contact))) {

        if (context->return_objects == TRUE) {
            context->obj_list =
                g_list_prepend (context->obj_list, g_object_ref (contact));
        } else {
            ostr = e_vcard_to_string (E_VCARD (contact), EVC_FORMAT_VCARD_30);
            context->obj_list = g_list_prepend (context->obj_list, ostr);
        }
    }
}
gint
main (gint argc,
      gchar **argv)
{
	EBookClient *book_client;
	const gchar *query_string;
	EBookQuery *query;
	gchar *sexp;
	GSList *c, *contacts;
	GError *error = NULL;

	main_initialize ();

	if (argc != 2) {
		query_string = "contains \"full_name\" \"a\"";
		printf ("usage: test-search <query>\n");
		printf ("   using default query \"%s\"\n", query_string);
	} else {
		query_string = argv[1];
	}

	query = e_book_query_from_string (query_string);
	if (!query) {
		fprintf (stderr, " * Failed to parse query string '%s'\n", query_string);
		return 1;
	}

	sexp = e_book_query_to_string (query);
	e_book_query_unref (query);

	book_client = open_system_book (FALSE);
	if (!book_client) {
		g_free (sexp);
		return 1;
	}

	if (!e_book_client_get_contacts_sync (book_client, sexp, &contacts, NULL, &error)) {
		report_error ("get contacts sync", &error);
		g_free (sexp);
		g_object_unref (book_client);
		return 1;
	}

	for (c = contacts; c; c = c->next) {
		EContact *contact = E_CONTACT (c->data);
		gchar *vcard = e_vcard_to_string (E_VCARD (contact), EVC_FORMAT_VCARD_30);

		printf ("%s\n\n", vcard);

		g_free (vcard);
	}

	g_slist_foreach (contacts, (GFunc) g_object_unref, NULL);
	g_slist_free (contacts);

	g_free (sexp);
	g_object_unref (book_client);

	return 0;
}
static void
print_all_emails (EBook *book)
{
	EBookQuery *query;
	gboolean status;
	GList *cards, *c;

	query = e_book_query_field_exists (E_CONTACT_FULL_NAME);

	status = e_book_get_contacts (book, query, &cards, NULL);

	e_book_query_unref (query);

	if (status == FALSE) {
		printf ("error %d getting card list\n", status);
		exit (0);
	}

	for (c = cards; c; c = c->next) {
		EContact *contact = E_CONTACT (c->data);

		print_email (contact);

		g_object_unref (contact);
	}
	g_list_free (cards);
}
Example #5
0
static void ebookpull_cb(EBook *book, EBookStatus estatus, GList *contacts,
							void *user_data)
{
	struct query_context *data = user_data;
	GString *string = g_string_new("");
	unsigned int count = 0, maxcount;
	GList *l;

	if (estatus == E_BOOK_ERROR_CANCELLED) {
		error("E-Book operation was cancelled: status %d", estatus);
		goto fail;
	}

	if (estatus != E_BOOK_ERROR_OK) {
		error("E-Book query failed: status %d", estatus);
		goto done;
	}

	/*
	 * When MaxListCount is zero, PCE wants to know the number of used
	 * indexes in the phonebook of interest. All other parameters that
	 * may be present in the request shall be ignored.
	 */
	maxcount = data->params->maxlistcount;
	if (maxcount == 0) {
		count = g_list_length(contacts);
		goto done;
	}

	l = g_list_nth(contacts, data->params->liststartoffset);

	/* FIXME: Missing 0.vcf */

	for (; l && count < maxcount; l = g_list_next(l), count++) {
		EContact *contact = E_CONTACT(l->data);
		EVCard *evcard = E_VCARD(contact);
		char *vcard;

		vcard = evcard_to_string(evcard, data->params->format,
						data->params->filter);

		string = g_string_append(string, vcard);
		string = g_string_append(string, "\r\n");
		g_free(vcard);
	}
	DBG("collected %d vcards", count);


done:
	data->completed = TRUE;
	data->contacts_cb(string->str, string->len, count, 0, TRUE,
							data->user_data);

fail:
	g_string_free(string, TRUE);

	if (data->completed)
		g_free(data);
}
gint
main (gint argc,
      gchar **argv)
{
#if 0  /* ACCOUNT_MGMT */
	EBook *book;
	gboolean status;
	EBookQuery *query;
	GList *c, *contacts;

	g_type_init ();

	if (argc < 3) {
		printf ("usage: test-search <addressbook uri> <query>\n");
		exit (0);
	}

	query = e_book_query_from_string (argv[2]);
	if (!query) {
		printf ("failed to parse query string '%s'\n", argv[2]);
		exit (0);
	}

	book = e_book_new_system_addressbook (NULL);
	if (!book) {
		printf ("failed to create ebook\n");
		exit (0);
	}

	status = e_book_open (book, TRUE, NULL);
	if (status == FALSE) {
		printf ("failed to open addressbook\n");
		exit (0);
	}

	status = e_book_get_contacts (book, query, &contacts, NULL);
	if (status == FALSE) {
		printf ("failed to get contacts\n");
		exit (0);
	}

	for (c = contacts; c; c = c->next) {
		EContact *contact = E_CONTACT (c->data);

		printf ("%s\n", e_vcard_to_string (E_VCARD (contact), EVC_FORMAT_VCARD_30));

		g_object_unref (contact);
	}

	g_list_free (contacts);

	g_object_unref (book);
#endif /* ACCOUNT_MGMT */

	return 0;
}
Example #7
0
static void cache_cb(EBook *book, EBookStatus estatus, GList *contacts,
							void *user_data)
{
	struct query_context *data = user_data;
	GList *l;

	if (estatus == E_BOOK_ERROR_CANCELLED) {
		error("E-Book operation was cancelled: status %d", estatus);
		goto fail;
	}

	data->completed = TRUE;

	if (estatus != E_BOOK_ERROR_OK) {
		error("E-Book query failed: status %d", estatus);
		goto done;
	}

	for (l = contacts; l; l = g_list_next(l)) {
		EContact *contact = E_CONTACT(l->data);
		EVCard *evcard = E_VCARD(contact);
		EVCardAttribute *attrib;
		char *uid, *tel, *name;

		name = evcard_name_attribute_to_string(evcard);
		if (!name)
			continue;

		attrib = e_vcard_get_attribute(evcard, EVC_UID);
		if (!attrib)
			continue;

		uid =  e_vcard_attribute_get_value(attrib);
		if (!uid)
			continue;

		attrib = e_vcard_get_attribute(evcard, EVC_TEL);
		if (!attrib)
			continue;

		tel =  e_vcard_attribute_get_value(attrib);

		data->entry_cb(uid, PHONEBOOK_INVALID_HANDLE, name, NULL,
							tel, data->user_data);
		g_free(name);
		g_free(uid);
		g_free(tel);
	}
done:
	data->ready_cb(data->user_data);

fail:
	if (data->completed)
		g_free(data);
}
Example #8
0
static void
search_changed_cb(GtkEntry *entry, GevoAddBuddyDialog *dialog)
{
	const char *text = gtk_entry_get_text(entry);
	GList *l;

	gtk_list_store_clear(dialog->model);

	for (l = dialog->contacts; l != NULL; l = l->next)
	{
		EContact *contact = E_CONTACT(l->data);
		const char *name;
		GList *aims, *jabbers, *yahoos, *msns, *icqs, *novells;

		name = e_contact_get_const(contact, E_CONTACT_FULL_NAME);

		if (text != NULL && *text != '\0' && name != NULL &&
			g_ascii_strncasecmp(name, text, strlen(text)))
		{
			continue;
		}

		aims    = e_contact_get(contact, E_CONTACT_IM_AIM);
		jabbers = e_contact_get(contact, E_CONTACT_IM_JABBER);
		yahoos  = e_contact_get(contact, E_CONTACT_IM_YAHOO);
		msns    = e_contact_get(contact, E_CONTACT_IM_MSN);
		icqs    = e_contact_get(contact, E_CONTACT_IM_ICQ);
		novells = e_contact_get(contact, E_CONTACT_IM_GROUPWISE);

		if (aims == NULL && jabbers == NULL && yahoos == NULL &&
			msns == NULL && icqs == NULL && novells == NULL)
		{
			GtkTreeIter iter;

			gtk_list_store_append(dialog->model, &iter);

			gtk_list_store_set(dialog->model, &iter,
							   COLUMN_NAME, name,
							   COLUMN_DATA, contact,
							   -1);
		}
		else
		{
			add_ims(dialog, contact, name, aims,    "prpl-aim");
			add_ims(dialog, contact, name, aims,    "prpl-oscar");
			add_ims(dialog, contact, name, jabbers, "prpl-jabber");
			add_ims(dialog, contact, name, yahoos,  "prpl-yahoo");
			add_ims(dialog, contact, name, msns,    "prpl-msn");
			add_ims(dialog, contact, name, icqs,    "prpl-icq");
			add_ims(dialog, contact, name, icqs,    "prpl-oscar");
			add_ims(dialog, contact, name, novells, "prpl-novell");
		}
	}
}
Example #9
0
static void
on_ebook_contacts_added (EBookView    *view, 
                        GList        *c_list, 
                        MokoContacts *contacts)
{
  MokoContactsPrivate *priv;
  GList *c;

  g_return_if_fail (MOKO_IS_CONTACTS (contacts));
  priv = contacts->priv;

  for (c = c_list; c != NULL; c = c->next)
    moko_contacts_add_contact (contacts, E_CONTACT (c->data));
}
static EBookBackendSyncStatus
e_book_backend_scalix_create_contact (EBookBackendSync * backend,
                                      EDataBook * book,
                                      guint32 opid,
                                      const char *vcard, EContact ** contact)
{
    EBookBackendScalix *bs;
    EBookBackendScalixPrivate *priv;
    ScalixObject *object;
    EContact *econtact;
    gboolean res;
    char *uid;

    bs = E_BOOK_BACKEND_SCALIX (backend);
    priv = E_BOOK_BACKEND_SCALIX_GET_PRIVATE (bs);

    econtact = e_contact_new_from_vcard (vcard);
    gboolean is_list =
        GPOINTER_TO_INT (e_contact_get (econtact, E_CONTACT_IS_LIST));

    if (is_list == TRUE) {
        object = SCALIX_OBJECT (scalix_contact_list_new (vcard));
    } else {
        object = SCALIX_OBJECT (scalix_contact_new (vcard));
    }

    if (object == NULL) {
        return GNOME_Evolution_Addressbook_OtherError;
    }

    res = scalix_container_add_object (priv->container, object);

    if (res == FALSE) {
        g_object_unref (object);
        return GNOME_Evolution_Addressbook_OtherError;
    }

    g_object_get (object, "uid", &uid, NULL);
    g_object_unref (object);

    object = scalix_container_refresh_object (priv->container, uid);

    if (object == NULL) {
        return GNOME_Evolution_Addressbook_OtherError;
    }

    *contact = E_CONTACT (object);

    return GNOME_Evolution_Addressbook_Success;
}
static void
container_object_added_cb (ScalixContainer * container,
                           ScalixObject * object, gpointer data)
{
    EBookBackend *backend;

    backend = E_BOOK_BACKEND (data);

    if (!E_IS_CONTACT (object)) {
        g_warning ("Invalid object\n");
        return;
    }

    e_book_backend_notify_update (backend, E_CONTACT (object));
    e_book_backend_notify_complete (backend);
}
Example #12
0
static void
book_open_cb (EBook *book, EBookStatus status, gpointer closure)
{
    GList *list = closure;
    if (status == E_BOOK_ERROR_OK) {
        GList *p;
        for (p = list; p; p = p->next) {
            /* XXX argh, more passing of NULL's for callbacks */
            eab_merging_book_add_contact (book, E_CONTACT (p->data), NULL, NULL);
        }
    }
    if (book)
        g_object_unref (book);
    g_list_foreach (list, (GFunc) g_object_unref, NULL);
    g_list_free (list);
}
Example #13
0
static EContact *
gevo_run_query_in_uri(const gchar *uri, EBookQuery *query)
{
	EBook *book;
	gboolean status;
	GList *cards;
	GError *err = NULL;

	if (!gevo_load_addressbook(uri, &book, &err))
	{
		purple_debug_error("evolution",
						 "Error retrieving addressbook: %s\n", err->message);
		g_error_free(err);
		return NULL;
	}

	status = e_book_get_contacts(book, query, &cards, NULL);
	if (!status)
	{
		purple_debug_error("evolution", "Error %d in getting card list\n",
						 status);
		g_object_unref(book);
		return NULL;
	}
	g_object_unref(book);

	if (cards != NULL)
	{
		EContact *contact = E_CONTACT(cards->data);
		GList *cards2 = cards->next;

		if (cards2 != NULL)
		{
			/* Break off the first contact and free the rest. */
			cards->next = NULL;
			cards2->prev = NULL;
			g_list_foreach(cards2, (GFunc)g_object_unref, NULL);
		}

		/* Free the whole list. */
		g_list_free(cards);

		return contact;
	}

	return NULL;
}
Example #14
0
/*
 * This function implements the Bonobo::PersistStream:load method.
 */
static void
pstream_load (BonoboPersistStream *ps, const Bonobo_Stream stream,
              Bonobo_Persist_ContentType type, void *data,
              CORBA_Environment *ev)
{
    GList *list;
    char *vcard;
    EABVCardControl *vcard_control = data;

    if (type && g_ascii_strcasecmp (type, "text/vCard") != 0 &&
            g_ascii_strcasecmp (type, "text/x-vCard") != 0) {
        CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
                             ex_Bonobo_Persist_WrongDataType, NULL);
        return;
    }

    if ((vcard = stream_read (stream)) == NULL) {
        CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
                             ex_Bonobo_Persist_FileNotFound, NULL);
        return;
    }

    g_list_foreach (
        vcard_control->card_list,
        (GFunc) g_object_unref, NULL);
    g_list_free (vcard_control->card_list);

    list = eab_contact_list_from_string (vcard);
    g_free(vcard);
    vcard_control->card_list = list;
    if (list) {
        eab_contact_display_render (vcard_control->display, E_CONTACT (list->data),
                                    vcard_control->render_mode);
    }
    if (list && list->next) {
        char *message;
        int length = g_list_length (list) - 1;
        message = g_strdup_printf (ngettext("There is one other contact.",
                                            "There are %d other contacts.", length),
                                   length);
        gtk_label_set_text (GTK_LABEL (vcard_control->label), message);
        g_free (message);
        gtk_widget_show (vcard_control->label);
    } else {
        gtk_widget_hide (vcard_control->label);
    }
} /* pstream_load */
Example #15
0
/**
 * eab_menu_target_new_select - create a menu target of the current selection.
 * @eabp: Address book menu.
 * @book: Book the cards belong to.  May be NULL in which case cards must be an empty GPtrArray.
 * @readonly: Book is read-only mode.  FIXME: Why can't we just get this off the book?
 * @cards: Cards selected.  This will be freed on completion and the array indices unreferenced.
 *
 * Create a new selection menu target.
 *
 * Return value:
 **/
EABMenuTargetSelect *
eab_menu_target_new_select(EABMenu *eabp, struct _EBook *book, int readonly, GPtrArray *cards)
{
	EABMenuTargetSelect *t = e_menu_target_new(&eabp->menu, EAB_MENU_TARGET_SELECT, sizeof(*t));
	guint32 mask = ~0;
	int has_email = FALSE, i;

	/* FIXME: duplicated in eab-popup.c */

	t->book = book;
	if (book)
		g_object_ref(book);
	t->cards = cards;

	for (i=0;i<cards->len && !has_email;i++) {
		EContact *contact = cards->pdata[i];
		GList *email;

		email = e_contact_get(E_CONTACT(contact), E_CONTACT_EMAIL);
		if (email) {
			has_email = TRUE;

			g_list_foreach(email, (GFunc)g_free, NULL);
			g_list_free(email);
		}
	}

	if (has_email)
		mask &= ~EAB_MENU_SELECT_EMAIL;

	if (!readonly)
		mask &= ~EAB_MENU_SELECT_EDITABLE;

	if (cards->len == 1)
		mask &= ~EAB_MENU_SELECT_ONE;

	if (cards->len > 1)
		mask &= ~EAB_MENU_SELECT_MANY;

	if (cards->len >= 1)
		mask &= ~EAB_MENU_SELECT_ANY;

	t->target.mask = mask;

	return t;
}
static EBookBackendSyncStatus
e_book_backend_scalix_modify_contact (EBookBackendSync * backend,
                                      EDataBook * book,
                                      guint32 opid,
                                      const char *vcard, EContact ** contact)
{
    EBookBackendScalix *bs;
    EBookBackendScalixPrivate *priv;
    ScalixObject *object;
    gboolean res;
    EContact *econtact;

    bs = E_BOOK_BACKEND_SCALIX (backend);
    priv = E_BOOK_BACKEND_SCALIX_GET_PRIVATE (bs);

    econtact = e_contact_new_from_vcard (vcard);
    gboolean is_list =
        GPOINTER_TO_INT (e_contact_get (econtact, E_CONTACT_IS_LIST));

    if (is_list == TRUE) {
        object = SCALIX_OBJECT (scalix_contact_list_new (vcard));
    } else {
        object = SCALIX_OBJECT (scalix_contact_new (vcard));
    }

    if (object == NULL) {
        return GNOME_Evolution_Addressbook_OtherError;
    }

    /* REVIEW: do we have to ask the cache for the object here first?
     * (to "save" the mapi stuff?) */

    res = scalix_container_update_object (priv->container, object, TRUE);

    if (res == FALSE) {
        g_object_unref (object);
        return GNOME_Evolution_Addressbook_OtherError;
    }

    *contact = E_CONTACT (object);

    return GNOME_Evolution_Addressbook_Success;

}
static void
print_all_emails_cb (EBook *book,
                     const GError *error,
                     GList *contacts,
                     gpointer closure)
{
	GList *c;

	if (!error) {
		for (c = contacts; c; c = c->next) {
			EContact *contact = E_CONTACT (c->data);

			print_email (contact);
		}
	} else {
		g_warning ("%s: Got error %d (%s)", G_STRFUNC, error->code, error->message);
	}

	g_main_loop_quit (loop);
}
Example #18
0
static void
toggle_full_vcard(GtkWidget *button, gpointer data)
{
    EABVCardControl *vcard_control = data;
    char *label;

    if (!vcard_control->card_list)
        return;

    if (vcard_control->render_mode == EAB_CONTACT_DISPLAY_RENDER_NORMAL) {
        vcard_control->render_mode = EAB_CONTACT_DISPLAY_RENDER_COMPACT;
        label = _("Show Full vCard");
    }
    else {
        vcard_control->render_mode = EAB_CONTACT_DISPLAY_RENDER_NORMAL;
        label = _("Show Compact vCard");
    }

    gtk_button_set_label (GTK_BUTTON (button), label);
    eab_contact_display_render (vcard_control->display, E_CONTACT (vcard_control->card_list->data),
                                vcard_control->render_mode);
}
static void
container_object_removed_cb (ScalixContainer * container,
                             ScalixObject * object, gpointer data)
{
    EBookBackend *backend;
    EContact *contact;
    const char *uid;

    backend = E_BOOK_BACKEND (data);

    if (!E_IS_CONTACT (object)) {
        g_warning ("Invalid object");
        return;
    }

    contact = E_CONTACT (object);
    uid = e_contact_get_const (contact, E_CONTACT_UID);

    g_assert (uid != NULL);

    e_book_backend_notify_remove (backend, uid);
    e_book_backend_notify_complete (backend);
}
static gboolean
test_bulk_modify (EBookClient *client,
                  const gchar *vcard_str,
                  gint batch_size)
{
	gint i;
	EContact *contact;
	GSList *contacts = NULL;
	GSList *added_uids = NULL;
	const GSList *l, *ll;
	const gchar *old_first_name = "xyz mix";
	const gchar *new_first_name = "abc mix";

	for (i = 0; i < batch_size; ++i) {
		EContact *contact = e_contact_new_from_vcard (vcard_str);
		contacts = g_slist_append (contacts, contact);
	}

	g_print ("  * Bulk addition of %d contacts...\n", batch_size);
	/* Bulk addition */
	g_return_val_if_fail (e_book_client_add_contacts_sync (client, contacts, &added_uids, NULL, NULL), FALSE);
	g_return_val_if_fail (added_uids != NULL, FALSE);
	g_return_val_if_fail (added_uids->data != NULL, FALSE);
	g_return_val_if_fail (g_slist_length (added_uids) == batch_size, FALSE);

	g_print ("  * Bulk modification of %d contacts...\n", batch_size);
	ll = added_uids;
	for (l = contacts; l != NULL; l = l->next) {
		const gchar * uid = ll->data;
		contact = E_CONTACT (l->data);

		/* Set contact UID */
		e_contact_set (contact, E_CONTACT_UID, uid);

		/* Change contact first name */
		e_contact_set (contact, E_CONTACT_GIVEN_NAME, new_first_name);

		ll = ll->next;
	}
	g_return_val_if_fail (e_book_client_modify_contacts_sync (client, contacts, NULL, NULL), FALSE);

	/* Validate */
	for (ll = added_uids; ll != NULL; ll = ll->next) {
		const gchar *first_name;
		const gchar *uid = ll->data;
		contact = NULL;

		g_return_val_if_fail (e_book_client_get_contact_sync (client, uid, &contact, NULL, NULL), FALSE);

		/* Check contact first name */
		first_name = e_contact_get_const (contact, E_CONTACT_GIVEN_NAME);
		g_return_val_if_fail (g_strcmp0 (first_name, new_first_name) == 0, FALSE);

		g_object_unref (contact);
	}

	/* Test failure case */
	g_print ("  * Bulk modification of %d contacts (expected failure)...\n", batch_size);
	contact = E_CONTACT (g_slist_nth_data (contacts, g_slist_length (contacts) - 2));
	g_return_val_if_fail (e_book_client_remove_contact_sync (client, contact, NULL, NULL), FALSE);
	for (l = contacts; l != NULL; l = l->next) {
		contact = E_CONTACT (l->data);
		/* Change contact first name */
		e_contact_set (contact, E_CONTACT_GIVEN_NAME, old_first_name);
	}
	g_return_val_if_fail (!e_book_client_modify_contacts_sync (client, contacts, NULL, NULL), FALSE);

	/* Remove the UID that no longer exists from the added_uid list */
	added_uids = g_slist_delete_link (added_uids, g_slist_nth (added_uids, g_slist_length (added_uids) - 2));

	/* Validate */
	for (ll = added_uids; ll != NULL; ll = ll->next) {
		const gchar *first_name;
		const gchar *uid = ll->data;
		contact = NULL;

		g_return_val_if_fail (e_book_client_get_contact_sync (client, uid, &contact, NULL, NULL), FALSE);

		/* Check contact first name */
		first_name = e_contact_get_const (contact, E_CONTACT_GIVEN_NAME);
		g_return_val_if_fail (g_strcmp0 (first_name, new_first_name) == 0, FALSE);

		g_object_unref (contact);
	}

	g_print ("  * Bulk removal of %d contacts...\n", batch_size);

	/* Bulk removal */
	g_return_val_if_fail (e_book_client_remove_contacts_sync (client, added_uids, NULL, NULL), FALSE);

	g_slist_free_full (added_uids, g_free);
	g_slist_free_full (contacts, g_object_unref);
	return TRUE;
}
Example #21
0
void
bbdb_sync_buddy_list (void)
{
	GList       *blist, *l;
	EBook       *book = NULL;

	/* Get the Gaim buddy list */
	blist = bbdb_get_gaim_buddy_list ();
	if (blist == NULL)
		return;

	/* Open the addressbook */
	book = bbdb_open_addressbook (GAIM_ADDRESSBOOK);
	if (book == NULL) {
		free_buddy_list (blist);
		return;
	}

	printf ("bbdb: Synchronizing buddy list to contacts...\n");
	/* Walk the buddy list */
	for (l = blist; l != NULL; l = l->next) {
		GaimBuddy *b = l->data;
		EBookQuery *query;
		GList *contacts;
		GError *error = NULL;
		EContact *c;

		if (b->alias == NULL || strlen (b->alias) == 0)
			b->alias = b->account_name;

		/* Look for an exact match full name == buddy alias */
		query = e_book_query_field_test (E_CONTACT_FULL_NAME, E_BOOK_QUERY_IS, b->alias);
		e_book_get_contacts (book, query, &contacts, NULL);
		e_book_query_unref (query);
		if (contacts != NULL) {

			/* FIXME: If there's more than one contact with this
			   name, just give up; we're not smart enough for
			   this. */
			if (contacts->next != NULL)
 				continue;

			c = E_CONTACT (contacts->data);

			if (! bbdb_merge_buddy_to_contact (book, b, c))
				continue;

			/* Write it out to the addressbook */
			if (! e_book_commit_contact (book, c, &error)) {
				g_warning ("bbdb: Could not modify contact: %s\n", error->message);
				g_error_free (error);
			}
			continue;
		}

		/* Otherwise, create a new contact. */
		c = e_contact_new ();
		e_contact_set (c, E_CONTACT_FULL_NAME, (gpointer) b->alias);
		if (! bbdb_merge_buddy_to_contact (book, b, c)) {
			g_object_unref (G_OBJECT (c));
			continue;
		}

		if (! e_book_add_contact (book, c, &error)) {
			g_warning ("bbdb: Failed to add new contact: %s\n", error->message);
			g_error_free (error);
			return;
		}
		g_object_unref (G_OBJECT (c));

	}


	/* Update the last-sync'd time */
	{
		GConfClient *gconf;
		time_t  last_sync;
		char   *last_sync_str;

		gconf = gconf_client_get_default ();

		time (&last_sync);
		last_sync_str = g_strdup_printf ("%ld", (glong) last_sync);
		gconf_client_set_string (gconf, GCONF_KEY_GAIM_LAST_SYNC, last_sync_str, NULL);
		g_free (last_sync_str);

		g_object_unref (G_OBJECT (gconf));
	}
	printf ("bbdb: Done syncing buddy list to contacts.\n");
}
Example #22
0
static void cache_cb(EBook *book, const GError *gerr, GList *contacts,
							void *user_data)
{
	struct query_context *data = user_data;
	GList *l;

	data->queued_calls--;

	if (data->canceled)
		goto canceled;

	if (gerr != NULL) {
		error("E-Book operation failed: %s", gerr->message);
		goto done;
	}

	DBG("");

	for (l = contacts; l; l = g_list_next(l)) {
		EContact *contact = E_CONTACT(l->data);
		EVCard *evcard = E_VCARD(contact);
		EVCardAttribute *attrib;
		char *uid, *tel, *name;

		name = evcard_name_attribute_to_string(evcard);
		if (!name)
			continue;

		attrib = e_vcard_get_attribute(evcard, EVC_UID);
		if (!attrib)
			continue;

		uid = e_vcard_attribute_get_value(attrib);
		if (!uid)
			continue;

		attrib = e_vcard_get_attribute(evcard, EVC_TEL);
		if (attrib)
			tel = e_vcard_attribute_get_value(attrib);
		else
			tel = g_strdup("");

		data->entry_cb(uid, PHONEBOOK_INVALID_HANDLE, name, NULL,
							tel, data->user_data);

		g_free(name);
		g_free(uid);
		g_free(tel);
	}

	g_list_free_full(contacts, g_object_unref);

done:
	if (data->queued_calls == 0)
		data->ready_cb(data->user_data);

	return;

canceled:
	if (data->queued_calls == 0)
		free_query_context(data);
}
Example #23
0
static void ebookpull_cb(EBook *book, const GError *gerr, GList *contacts,
							void *user_data)
{
	struct query_context *data = user_data;
	GList *l;
	unsigned int count, maxcount;

	data->queued_calls--;

	if (data->canceled)
		goto canceled;

	if (gerr != NULL) {
		error("E-Book query failed: %s", gerr->message);
		goto done;
	}

	DBG("");

	/*
	 * When MaxListCount is zero, PCE wants to know the number of used
	 * indexes in the phonebook of interest. All other parameters that
	 * may be present in the request shall be ignored.
	 */
	maxcount = data->params->maxlistcount;
	if (maxcount == 0) {
		data->count += g_list_length(contacts);
		goto done;
	}

	l = g_list_nth(contacts, data->params->liststartoffset);

	for (count = 0; l && count + data->count < maxcount; l = g_list_next(l),
								count++) {
		EContact *contact = E_CONTACT(l->data);
		EVCard *evcard = E_VCARD(contact);
		char *vcard;

		vcard = evcard_to_string(evcard, EVC_FORMAT_VCARD_30,
						data->params->filter);

		data->buf = g_string_append(data->buf, vcard);
		data->buf = g_string_append(data->buf, "\r\n");
		g_free(vcard);
	}

	DBG("collected %d vcards", count);

	data->count += count;

	g_list_free_full(contacts, g_object_unref);

done:
	if (data->queued_calls == 0) {
		GString *buf = data->buf;
		data->buf = NULL;

		data->contacts_cb(buf->str, buf->len, data->count,
						0, TRUE, data->user_data);

		g_string_free(buf, TRUE);

	}

	return;

canceled:
	if (data->queued_calls == 0)
		free_query_context(data);
}
Example #24
0
static void
populate_treeview(GevoAddBuddyDialog *dialog, const gchar *uri)
{
	EBookQuery *query;
	EBook *book;
	gboolean status;
	GList *cards, *c;
	GError *err = NULL;

	if (dialog->book != NULL)
	{
		g_object_unref(dialog->book);
		dialog->book = NULL;
	}

	if (dialog->contacts != NULL)
	{
		g_list_foreach(dialog->contacts, (GFunc)g_object_unref, NULL);
		g_list_free(dialog->contacts);
		dialog->contacts = NULL;
	}

	gtk_list_store_clear(dialog->model);

	if (!gevo_load_addressbook(uri, &book, &err))
	{
		purple_debug_error("evolution",
						 "Error retrieving default addressbook: %s\n", err->message);
		g_error_free(err);

		return;
	}

	query = e_book_query_field_exists(E_CONTACT_FULL_NAME);

	if (query == NULL)
	{
		purple_debug_error("evolution", "Error in creating query\n");

		g_object_unref(book);

		return;
	}

	status = e_book_get_contacts(book, query, &cards, NULL);

	e_book_query_unref(query);

	if (!status)
	{
		purple_debug_error("evolution", "Error %d in getting card list\n",
						 status);

		g_object_unref(book);

		return;
	}

	for (c = cards; c != NULL; c = c->next)
	{
		EContact *contact = E_CONTACT(c->data);
		const char *name;
		GList *aims, *jabbers, *yahoos, *msns, *icqs, *novells;

		name = e_contact_get_const(contact, E_CONTACT_FULL_NAME);

		aims    = e_contact_get(contact, E_CONTACT_IM_AIM);
		jabbers = e_contact_get(contact, E_CONTACT_IM_JABBER);
		yahoos  = e_contact_get(contact, E_CONTACT_IM_YAHOO);
		msns    = e_contact_get(contact, E_CONTACT_IM_MSN);
		icqs    = e_contact_get(contact, E_CONTACT_IM_ICQ);
		novells = e_contact_get(contact, E_CONTACT_IM_GROUPWISE);

		if (aims == NULL && jabbers == NULL && yahoos == NULL &&
			msns == NULL && icqs == NULL && novells == NULL)
		{
			GtkTreeIter iter;

			gtk_list_store_append(dialog->model, &iter);

			gtk_list_store_set(dialog->model, &iter,
							   COLUMN_NAME, name,
							   COLUMN_DATA, contact,
							   -1);
		}
		else
		{
			add_ims(dialog, contact, name, aims,    "prpl-aim");
			add_ims(dialog, contact, name, jabbers, "prpl-jabber");
			add_ims(dialog, contact, name, yahoos,  "prpl-yahoo");
			add_ims(dialog, contact, name, msns,    "prpl-msn");
			add_ims(dialog, contact, name, icqs,    "prpl-icq");
			add_ims(dialog, contact, name, novells, "prpl-novell");
		}
	}

	dialog->contacts = cards;
	dialog->book = book;
}
Example #25
0
static guint32
book_shell_content_check_state (EShellContent *shell_content)
{
    EBookShellContent *book_shell_content;
    ESelectionModel *selection_model;
    EAddressbookModel *model;
    EAddressbookView *view;
    gboolean has_email = TRUE;
    gboolean is_contact_list = TRUE;
    guint32 state = 0;
    gint n_selected;

    struct {
        EAddressbookModel *model;
        GList *list;
    } foreach_data;

    book_shell_content = E_BOOK_SHELL_CONTENT (shell_content);
    view = e_book_shell_content_get_current_view (book_shell_content);
    model = e_addressbook_view_get_model (view);

    selection_model = e_addressbook_view_get_selection_model (view);
    n_selected = (selection_model != NULL) ?
                 e_selection_model_selected_count (selection_model) : 0;

    foreach_data.model = model;
    foreach_data.list = NULL;

    if (selection_model != NULL)
        e_selection_model_foreach (
            selection_model, (EForeachFunc)
            book_shell_content_check_state_foreach,
            &foreach_data);

    while (foreach_data.list != NULL) {
        EContact *contact = E_CONTACT (foreach_data.list->data);
        GList *email_list;

        email_list = e_contact_get (contact, E_CONTACT_EMAIL);
        has_email &= (email_list != NULL);
        g_list_foreach (email_list, (GFunc) g_free, NULL);
        g_list_free (email_list);

        is_contact_list &=
            (e_contact_get (contact, E_CONTACT_IS_LIST) != NULL);

        g_object_unref (contact);

        foreach_data.list = g_list_delete_link (
                                foreach_data.list, foreach_data.list);
    }

    if (n_selected == 1)
        state |= E_BOOK_SHELL_CONTENT_SELECTION_SINGLE;
    if (n_selected > 1)
        state |= E_BOOK_SHELL_CONTENT_SELECTION_MULTIPLE;
    if (n_selected > 0 && has_email)
        state |= E_BOOK_SHELL_CONTENT_SELECTION_HAS_EMAIL;
    if (n_selected == 1 && is_contact_list)
        state |= E_BOOK_SHELL_CONTENT_SELECTION_IS_CONTACT_LIST;
    if (e_addressbook_model_can_stop (model))
        state |= E_BOOK_SHELL_CONTENT_SOURCE_IS_BUSY;
    if (e_addressbook_model_get_editable (model))
        state |= E_BOOK_SHELL_CONTENT_SOURCE_IS_EDITABLE;

    return state;
}
Example #26
0
static void
query_cb (GObject *source_object,
          GAsyncResult *result,
          gpointer user_data)
{
	MatchSearchInfo *info = (MatchSearchInfo *) user_data;
	EABContactMatchType best_match = EAB_CONTACT_MATCH_NONE;
	EContact *best_contact = NULL;
	EBookClient *book_client = E_BOOK_CLIENT (source_object);
	GSList *remaining_contacts = NULL;
	GSList *contacts = NULL;
	GError *error = NULL;
	const GSList *ii;

	if (result != NULL)
		e_book_client_get_contacts_finish (
			book_client, result, &contacts, &error);

	if (error != NULL) {
		g_warning (
			"%s: Failed to get contacts: %s\n",
			G_STRFUNC, error->message);
		g_error_free (error);

		info->cb (
			info->contact, NULL,
			EAB_CONTACT_MATCH_NONE,
			info->closure);

		match_search_info_free (info);
		g_object_unref (book_client);
		return;
	}

	/* remove the contacts we're to avoid from the list, if they're present */
	for (ii = contacts; ii != NULL; ii = g_slist_next (ii)) {
		EContact *this_contact = E_CONTACT (ii->data);
		const gchar *this_uid;
		GList *iterator;
		gboolean avoid = FALSE;

		this_uid = e_contact_get_const (this_contact, E_CONTACT_UID);
		if (!this_uid)
			continue;

		for (iterator = info->avoid; iterator; iterator = iterator->next) {
			const gchar *avoid_uid;

			avoid_uid = e_contact_get_const (iterator->data, E_CONTACT_UID);
			if (!avoid_uid)
				continue;

			if (!strcmp (avoid_uid, this_uid)) {
				avoid = TRUE;
				break;
			}
		}
		if (!avoid)
			remaining_contacts = g_slist_prepend (remaining_contacts, g_object_ref (this_contact));
	}

	remaining_contacts = g_slist_reverse (remaining_contacts);

	for (ii = remaining_contacts; ii != NULL; ii = g_slist_next (ii)) {
		EContact *this_contact = E_CONTACT (ii->data);
		EABContactMatchType this_match = eab_contact_compare (info->contact, this_contact);
		if ((gint) this_match > (gint) best_match) {
			best_match = this_match;
			best_contact = this_contact;
		}
	}

	if (best_contact)
		best_contact = g_object_ref (best_contact);

	g_slist_free_full (contacts, (GDestroyNotify) g_object_unref);
	g_slist_free_full (remaining_contacts, (GDestroyNotify) g_object_unref);

	info->cb (info->contact, best_contact, best_match, info->closure);
	match_search_info_free (info);
	g_object_unref (book_client);
	if (best_contact)
		g_object_unref (best_contact);
}