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;
}
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;
}
int
main (int argc, char **argv)
{
	int i;
	gboolean failure = FALSE;

	for (i = 0; i < G_N_ELEMENTS (queries); i ++) {
		EBookQuery *query = e_book_query_from_string (queries[i]);
		char *str;

		str = e_book_query_to_string (query);

		if (strcmp (str, queries[i])) {
			g_warning ("failed on query: %s", queries[i]);

			failure = TRUE;
		}
	}

	if (!failure)
	  g_message ("all tests passed");

	return 0;
}
Exemple #4
0
static void
on_query_button_clicked (GtkButton *button, GtkEntry *entry)
{
    const char *s;
    EBookQuery *query;

    g_return_if_fail (GTK_ENTRY (entry));

    s = gtk_entry_get_text (entry);

    if (s[0] == '\0') {
        query = e_book_query_any_field_contains ("");
    } else {
        query = e_book_query_from_string (s);
    }

    if (!query) {
        /* TODO: display error dialog */
        return;
    }

    eds_contact_view_show_query (EDS_CONTACT_VIEW (query_view), query);
    e_book_query_unref (query);
}
Exemple #5
0
static void
use_common_book_client (EBookClient *book_client,
                        MatchSearchInfo *info)
{
	EContact *contact = info->contact;
	EContactName *contact_name;
	GList *contact_email;
	gchar *query_parts[MAX_QUERY_PARTS + 1];
	gint p = 0;
	gchar *contact_file_as, *qj;
	EBookQuery *query = NULL;
	gint i;

	if (book_client == NULL) {
		info->cb (info->contact, NULL, EAB_CONTACT_MATCH_NONE, info->closure);
		match_search_info_free (info);
		return;
	}

	contact_file_as = e_contact_get (contact, E_CONTACT_FILE_AS);
	if (contact_file_as) {
		query_parts[p++] = g_strdup_printf ("(contains \"file_as\" \"%s\")", contact_file_as);
		g_free (contact_file_as);
	}

	if (!e_contact_get (contact, E_CONTACT_IS_LIST)) {
		contact_name = e_contact_get (contact, E_CONTACT_NAME);
		if (contact_name) {
			if (contact_name->given && *contact_name->given)
				query_parts[p++] = g_strdup_printf ("(contains \"full_name\" \"%s\")", contact_name->given);

			if (contact_name->additional && *contact_name->additional)
				query_parts[p++] = g_strdup_printf ("(contains \"full_name\" \"%s\")", contact_name->additional);

			if (contact_name->family && *contact_name->family)
				query_parts[p++] = g_strdup_printf ("(contains \"full_name\" \"%s\")", contact_name->family);

			e_contact_name_free (contact_name);
		}

		contact_email = e_contact_get (contact, E_CONTACT_EMAIL);
		if (contact_email) {
			GList *iter;
			for (iter = contact_email; iter && p < MAX_QUERY_PARTS; iter = iter->next) {
				gchar *addr = g_strdup (iter->data);
				if (addr && *addr) {
					gchar *s = addr;
					while (*s) {
						if (*s == '@') {
							*s = '\0';
							break;
						}
						++s;
					}
					query_parts[p++] = g_strdup_printf ("(beginswith \"email\" \"%s\")", addr);
					g_free (addr);
				}
			}
		}
		g_list_foreach (contact_email, (GFunc) g_free, NULL);
		g_list_free (contact_email);
	}

	/* Build up our full query from the parts. */
	query_parts[p] = NULL;
	qj = g_strjoinv (" ", query_parts);
	for (i = 0; query_parts[i] != NULL; i++)
		g_free (query_parts[i]);
	if (p > 1) {
		gchar *s;
		s = g_strdup_printf ("(or %s)", qj);
		query = e_book_query_from_string (s);
		g_free (s);
	}
	else if (p == 1) {
		query = e_book_query_from_string (qj);
	}
	else {
		query = NULL;
	}

	if (query) {
		gchar *query_str = e_book_query_to_string (query);

		e_book_client_get_contacts (book_client, query_str, NULL, query_cb, info);

		g_free (query_str);
	} else
		query_cb (G_OBJECT (book_client), NULL, info);

	g_free (qj);
	if (query)
		e_book_query_unref (query);
}