Ejemplo n.º 1
0
static void
test_get_view_sync (ETestServerFixture *fixture,
                    gconstpointer user_data)
{
	EBookClient *book_client;
	EBookQuery *query;
	EBookClientView *view;
	gchar *sexp;
	GError *error = NULL;
	UIDOnlyClosure *closure = (UIDOnlyClosure *) user_data;

	uids_only = closure->uids_only;

	book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);

	setup_book (book_client);

	query = e_book_query_any_field_contains ("");
	sexp = e_book_query_to_string (query);
	e_book_query_unref (query);
	if (!e_book_client_get_view_sync (book_client, sexp, &view, NULL, &error)) {
		g_error ("get book view sync: %s", error->message);
		g_free (sexp);
		g_object_unref (book_client);
	}

	g_free (sexp);

	setup_and_start_view (view, fixture->loop);
	g_main_loop_run (fixture->loop);
}
Ejemplo n.º 2
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);
}
Ejemplo n.º 3
0
void *phonebook_create_cache(const char *name, phonebook_entry_cb entry_cb,
		phonebook_cache_ready_cb ready_cb, void *user_data, int *err)
{
	struct query_context *data;
	EBookQuery *query;
	gboolean ret;

	if (g_strcmp0("/telecom/pb", name) != 0) {
		if (err)
			*err = -ENOENT;
		return NULL;
	}

	query = e_book_query_any_field_contains("");

	data = g_new0(struct query_context, 1);
	data->entry_cb = entry_cb;
	data->ready_cb = ready_cb;
	data->user_data = user_data;

	ret = e_book_async_get_contacts(ebook, query, cache_cb, data);
	e_book_query_unref(query);
	if (ret != FALSE) {
		g_free(data);
		if (err)
			*err = -EFAULT;
		return NULL;
	}

	if (err)
		*err = 0;

	return data;
}
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;
}
Ejemplo n.º 5
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
test_photo_is_uri (ETestServerFixture *fixture,
                   gconstpointer user_data)
{
	EBookClient *book_client;
	EBookClientView *view;
	EBookQuery *query;
	GError     *error = NULL;
	gchar      *sexp;

	book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);

	add_contact_inline (book_client);
	add_contact_uri (book_client);

	query = e_book_query_any_field_contains ("");
	sexp = e_book_query_to_string (query);
	e_book_query_unref (query);
	if (!e_book_client_get_view_sync (book_client, sexp, &view, NULL, &error))
		g_error ("get book view sync: %s", error->message);

	g_free (sexp);

	setup_and_start_view (view);

	loop = fixture->loop;
	g_main_loop_run (loop);
}
gint
main (gint argc,
      gchar **argv)
{
#if 0  /* ACCOUNT_MGMT */
	EBook *book;
	gboolean status;
	EBookQuery *query;
	EBookView *view = NULL;
	EBookView *new_view;
	gint i;

	g_type_init ();

	/*
	** the actual ebook foo
	*/

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

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

	query = e_book_query_any_field_contains ("");

	for (i = 0; i < 500; i++) {
		status = e_book_get_book_view (book, query, NULL, -1, &new_view, NULL);

		g_signal_connect (new_view, "contacts_added", G_CALLBACK (contacts_added), NULL);
		g_signal_connect (new_view, "contacts_removed", G_CALLBACK (contacts_removed), NULL);
		g_signal_connect (new_view, "view_complete", G_CALLBACK (view_complete), NULL);

		e_book_view_start (new_view);

		if (view) {
			e_book_view_stop (view);
			g_object_unref (view);
		}

		view = new_view;
	}

	e_book_view_stop (view);
	g_object_unref (view);

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

	return 0;
}
Ejemplo n.º 8
0
static void
eds_receive_book_cb (EBook         *client,
		     EBookStatus    status,
		     gpointer       user_data)
{
	PlannerPlugin *plugin;
	EBookQuery    *query;
	AsyncQuery    *async_query;
	const gchar   *search;
	const gchar   *uid;
	const gchar   *book_uri;
	GtkListStore  *model;

	async_query = user_data;
	plugin = async_query->plugin;
	search = async_query->search;
	uid = async_query->uid;
	model = GTK_LIST_STORE (plugin->priv->resources_model);

	gtk_list_store_clear (model);
	g_free (async_query);

	book_uri = e_book_get_uri (client);

	if (eds_query_cancelled (plugin, uid)) {
		g_message ("Open book query cancelled: %s (%s)", book_uri, uid);
		gtk_widget_set_sensitive (glade_xml_get_widget (plugin->priv->glade,
								"search_box"), TRUE);
		eds_plugin_busy (plugin, FALSE);
		return;
	}

	if (status != E_BOOK_ERROR_OK) {
		g_warning ("Problems opening: %s", book_uri);
		gtk_widget_set_sensitive (glade_xml_get_widget (plugin->priv->glade,
								"search_box"), TRUE);
		eds_plugin_busy (plugin, FALSE);
		return;
	}

	g_message ("Looking the book: %s", book_uri);
	plugin->priv->books = g_list_append (plugin->priv->books, client);

	async_query = g_new0 (AsyncQuery, 1);
	g_free (plugin->priv->current_query_id);
	plugin->priv->current_query_id = e_uid_new ();
	async_query->uid = plugin->priv->current_query_id;
	async_query->plugin = plugin;

	query = e_book_query_any_field_contains (search);
	e_book_async_get_contacts (client, query,
				   eds_receive_contacts_cb,
				   (gpointer) async_query);

	eds_plugin_busy (plugin, TRUE);
	e_book_query_unref (query);
}
Ejemplo n.º 9
0
/* retrieve a list of contacts from the address book */
static int
addrbook_libebook_retrieve(ship_list_t *list)
{
	int ret = -1;
	contact_t *ct = 0;
	GError *error = 0;
	GList *contacts = 0, *loop;
	EBookQuery *query = 0;

	ship_lock(addrbook_lock);
	ASSERT_TRUE(query = e_book_query_any_field_contains(""), err);
	ASSERT_TRUE(e_book_get_contacts(book, query, &contacts, &error), err);
	ASSERT_ZERO(error, err);

	for (loop = contacts; loop; loop = g_list_next(loop)) {
		EContact *c = loop->data;
		char *name = 0;
		
		name = e_contact_get(c, E_CONTACT_OSSO_CONTACT_STATE);
		if (!name || strcmp(name, "DELETED")) {
			char **arrs = 0;

			ASSERT_TRUE(ct = ident_contact_new(), cerr);
			ASSERT_TRUE(ct->name = e_contact_get(c, E_CONTACT_FULL_NAME), cerr);
			
			ASSERT_TRUE(arrs = e_contact_get(c, E_CONTACT_SIP), cerr);
			ASSERT_TRUE(ct->sip_aor = addrbook_normalize_aor(arrs[0]), cerr);
			
			/* apparently arrs doesn't need to be free'd afterwards */
			g_list_foreach((GList*)arrs, (GFunc)g_free, NULL);
			ship_list_add(list, ct);
			ct = 0;
		cerr:
			ident_contact_free(ct);
		}
		if (name)
			g_free(name);
	}
	ret = 0;
 err:
	if (contacts) {
		g_list_free(contacts);
	}
	
	if (query) {
		e_book_query_unref(query);
	}

	if (error) {
		LOG_ERROR("Error getting contacts: %s\n", error->message);
		g_error_free(error);
	}
	ship_unlock(addrbook_lock);

	return ret;
}
gint
main (gint argc,
      gchar **argv)
{
	EBook *book;
	EBookQuery *query;
	EBookView *view;

	g_type_init ();

	/*
	 * Sync version
	 */
	setup_book (&book);
	query = e_book_query_any_field_contains ("");
	ebook_test_utils_book_get_book_view (book, query, &view);
	setup_and_start_view (view);

	test_print ("successfully set up the book view\n");

	loop = g_main_loop_new (NULL, TRUE);
	g_main_loop_run (loop);

	e_book_query_unref (query);
	ebook_test_utils_book_remove (book);

	/*
	 * Async version
	 */
	setup_book (&book);
	query = e_book_query_any_field_contains ("");

	loop = g_main_loop_new (NULL, TRUE);
	ebook_test_utils_book_async_get_book_view (book, query,
			(GSourceFunc) get_book_view_cb, loop);

	g_main_loop_run (loop);

	e_book_query_unref (query);
	ebook_test_utils_book_remove (book);

	return 0;
}
static void
print_all_emails (EBook *book)
{
	EBookQuery *query;

	query = e_book_query_field_exists (E_CONTACT_FULL_NAME);

	e_book_get_contacts_async (book, query, print_all_emails_cb, NULL);

	e_book_query_unref (query);
}
static gboolean
test_bulk_add_remove (EBookClient *client,
                      const gchar *vcard_str,
                      gint batch_size)
{
	gint i;
	GSList *contacts = NULL;
	GSList *added_uids = NULL;
	GSList *book_uids = NULL;
	EBookQuery *query = NULL;
	gchar *sexp = NULL;
	const GSList *l;

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

	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);

	/* Make sure the uids are in the address book */
	g_return_val_if_fail (e_book_client_get_contacts_uids_sync (client, sexp, &book_uids, NULL, NULL), FALSE);
	for (l = added_uids; l != NULL; l = l->next) {
		g_return_val_if_fail (check_string_in_slist (book_uids, (const gchar *) l->data), FALSE);
	}
	g_slist_free_full (book_uids, g_free);

	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);

	/* Make sure the uids are no longer in the address book */
	book_uids = NULL;
	g_return_val_if_fail (e_book_client_get_contacts_uids_sync (client, sexp, &book_uids, NULL, NULL), FALSE);
	for (l = added_uids; l != NULL; l = l->next) {
		g_return_val_if_fail (!check_string_in_slist (book_uids, (const gchar *) l->data), FALSE);
	}
	g_slist_free_full (book_uids, g_free);

	g_free (sexp);
	g_slist_free_full (added_uids, g_free);
	g_slist_free_full (contacts, g_object_unref);
	return TRUE;
}
Ejemplo n.º 13
0
static void free_query_context(struct query_context *data)
{
	g_free(data->id);

	if (data->buf != NULL)
		g_string_free(data->buf, TRUE);

	if (data->query != NULL)
		e_book_query_unref(data->query);

	close_ebooks(data->ebooks);

	g_free(data);
}
Ejemplo n.º 14
0
int phonebook_pull_read(void *request)
{
	struct query_context *data = request;
	EBookQuery *query;

	if (!data)
		return -ENOENT;

	query = e_book_query_any_field_contains("");
	e_book_async_get_contacts(ebook, query, ebookpull_cb, data);

	e_book_query_unref(query);

	return 0;
}
gint
main (gint argc,
      gchar **argv)
{
	EBookClient *book;
	EBookClientView *view;
	EBookQuery *query;
	GError     *error = NULL;
	gchar      *sexp;

	g_type_init ();

	setup_book (&book);

	query = e_book_query_any_field_contains ("");
	sexp = e_book_query_to_string (query);
	e_book_query_unref (query);
	if (!e_book_client_get_view_sync (book, sexp, &view, NULL, &error)) {
		report_error ("get book view sync", &error);
		g_free (sexp);
		g_object_unref (book);

		return 1;
	}

	g_free (sexp);

	setup_and_start_view (view);

	loop = g_main_loop_new (NULL, TRUE);
	g_main_loop_run (loop);

	if (!e_client_remove_sync (E_CLIENT (book), NULL, &error)) {
		report_error ("client remove sync", &error);
		g_object_unref (book);

		return 1;
	}

	g_object_unref (book);

	return 0;
}
static gpointer
call_get_view (gpointer user_data)
{
	EBookQuery *query;
	EBookClient *book_client = user_data;
	gchar *sexp;

	g_return_val_if_fail (book_client != NULL, NULL);
	g_return_val_if_fail (E_IS_BOOK_CLIENT (book_client), NULL);

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

	e_book_client_get_view (book_client, sexp, NULL, get_view_cb, NULL);

	g_free (sexp);

	return NULL;
}
static void
test_get_view_async (ETestServerFixture *fixture,
                     gconstpointer user_data)
{
	EBookClient *book_client;
	EBookQuery *query;
	gchar *sexp;

	book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);

	setup_book (book_client);
	query = e_book_query_any_field_contains ("");
	sexp = e_book_query_to_string (query);
	e_book_query_unref (query);

	e_book_client_get_view (book_client, sexp, NULL, get_view_cb, fixture->loop);

	g_free (sexp);
	g_main_loop_run (fixture->loop);
}
static void
test_get_book_view_async (ETestServerFixture *fixture,
                          gconstpointer user_data)
{
	EBook *book;
	EBookQuery *query;

	book = E_TEST_SERVER_UTILS_SERVICE (fixture, EBook);
	setup_book (book);

	query = e_book_query_any_field_contains ("");

	ebook_test_utils_book_async_get_book_view (
		book, query,
			(GSourceFunc) get_book_view_cb, fixture->loop);

	g_timeout_add_seconds (5, (GSourceFunc) main_loop_fail_timeout, NULL);
	g_main_loop_run (fixture->loop);
	e_book_query_unref (query);
}
static void
test_get_book_view_sync (ETestServerFixture *fixture,
                         gconstpointer user_data)
{
	EBook *book;
	EBookQuery *query;
	EBookView *view;

	book = E_TEST_SERVER_UTILS_SERVICE (fixture, EBook);
	setup_book (book);

	query = e_book_query_any_field_contains ("");
	ebook_test_utils_book_get_book_view (book, query, &view);
	setup_and_start_view (view, fixture->loop);

	test_print ("successfully set up the book view\n");

	g_main_loop_run (fixture->loop);

	e_book_query_unref (query);
}
Ejemplo n.º 20
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);
}
Ejemplo n.º 21
0
/* Pilot syncing callbacks */
static gint
pre_sync (GnomePilotConduit *conduit,
	  GnomePilotDBInfo *dbi,
	  EAddrConduitContext *ctxt)
{
	GnomePilotConduitSyncAbs *abs_conduit;
	EBookQuery *query;
    	GList *l;
	int len;
	char *filename;
	char *change_id;
	char *auth;
	gint num_records, add_records = 0, mod_records = 0, del_records = 0;
#ifdef PILOT_LINK_0_12
	pi_buffer_t *buffer;
#else
	unsigned char *buf;
#endif

	abs_conduit = GNOME_PILOT_CONDUIT_SYNC_ABS (conduit);

	LOG (g_message ( "---------------------------------------------------------\n" ));
	LOG (g_message ( "pre_sync: Addressbook Conduit v.%s", CONDUIT_VERSION ));
	/* g_message ("Addressbook Conduit v.%s", CONDUIT_VERSION); */

	ctxt->dbi = dbi;

	if (ctxt->cfg->source) {
		ctxt->ebook = e_book_new (ctxt->cfg->source, NULL);
	} else {
		ctxt->ebook = e_book_new_default_addressbook (NULL);
	}
	auth = (gchar *)e_source_get_property (ctxt->cfg->source, "auth");
	if (auth) {
		LOG (g_message ("contacts needs authentication\n"));
		g_signal_connect (ctxt->ebook, "auth_required",
				  G_CALLBACK (addressbook_authenticate), ctxt->cfg->source);
	}
	if (!ctxt->ebook || !e_book_open (ctxt->ebook, TRUE, NULL)) {
		WARN(_("Could not load addressbook"));
		gnome_pilot_conduit_error (conduit, _("Could not load addressbook"));

		return -1;
	}

	/* Load the uid <--> pilot id mappings */
	filename = map_name (ctxt);
	e_pilot_map_read (filename, &ctxt->map);
	g_free (filename);

	/* Get a list of all contacts */
	if (!(query = e_book_query_any_field_contains (""))) {
		LOG (g_warning ("Failed to get EBookQuery"));
		return -1;
	}

	if (!e_book_get_contacts (ctxt->ebook, query, &ctxt->cards, NULL)) {
		LOG (g_warning ("Failed to get Contacts"));
		e_book_query_unref (query);
		return -1;
	}

	e_book_query_unref (query);

	/* Count and hash the changes */
	change_id = g_strdup_printf ("pilot-sync-evolution-addressbook-%d", ctxt->cfg->pilot_id);
	if (!e_book_get_changes (ctxt->ebook, change_id, &ctxt->changed, NULL))
		return -1;
	ctxt->changed_hash = g_hash_table_new (g_str_hash, g_str_equal);
	g_free (change_id);

	for (l = ctxt->changed; l != NULL; l = l->next) {
		EBookChange *ebc = l->data;
		const char *uid;

		uid = e_contact_get_const (ebc->contact, E_CONTACT_UID);
		if (!e_pilot_map_uid_is_archived (ctxt->map, uid)) {

			g_hash_table_insert (ctxt->changed_hash, g_strdup (uid), ebc);

			switch (ebc->change_type) {
			case E_BOOK_CHANGE_CARD_ADDED:
				add_records++;
				break;
			case E_BOOK_CHANGE_CARD_MODIFIED:
				mod_records++;
				break;
			case E_BOOK_CHANGE_CARD_DELETED:
				del_records++;
				break;
			}
		} else if (ebc->change_type == E_BOOK_CHANGE_CARD_DELETED) {
			e_pilot_map_remove_by_uid (ctxt->map, uid);
		}
	}

	/* Set the count information */
  	num_records = g_list_length (ctxt->cards);
  	gnome_pilot_conduit_sync_abs_set_num_local_records(abs_conduit, num_records);
  	gnome_pilot_conduit_sync_abs_set_num_new_local_records (abs_conduit, add_records);
  	gnome_pilot_conduit_sync_abs_set_num_updated_local_records (abs_conduit, mod_records);
  	gnome_pilot_conduit_sync_abs_set_num_deleted_local_records(abs_conduit, del_records);

#ifdef PILOT_LINK_0_12
	buffer = pi_buffer_new(DLP_BUF_SIZE);
	if(buffer == NULL){
		return pi_set_error(dbi->pilot_socket, PI_ERR_GENERIC_MEMORY);
	}

	len = dlp_ReadAppBlock (dbi->pilot_socket, dbi->db_handle, 0,
			      DLP_BUF_SIZE, buffer);
#else
	buf = (unsigned char*)g_malloc (0xffff);
	len = dlp_ReadAppBlock (dbi->pilot_socket, dbi->db_handle, 0,
			      (unsigned char *)buf, 0xffff);
#endif
	if (len < 0) {
		WARN (_("Could not read pilot's Address application block"));
		WARN ("dlp_ReadAppBlock(...) = %d", len);
		gnome_pilot_conduit_error (conduit,
					   _("Could not read pilot's Address application block"));
		return -1;
	}
#ifdef PILOT_LINK_0_12
	unpack_AddressAppInfo (&(ctxt->ai), buffer->data, len);
	pi_buffer_free (buffer);
#else
	unpack_AddressAppInfo (&(ctxt->ai), buf, len);
	g_free (buf);
#endif
  	check_for_slow_setting (conduit, ctxt);
	if (ctxt->cfg->sync_type == GnomePilotConduitSyncTypeCopyToPilot
	    || ctxt->cfg->sync_type == GnomePilotConduitSyncTypeCopyFromPilot)
		ctxt->map->write_touched_only = TRUE;

	return 0;
}
Ejemplo n.º 22
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;
}
gint
main (gint argc,
      gchar **argv)
{
	EBookClient *book_client;
	EBookQuery *query;
	EBookClientView *view;
	gchar *sexp;
	GError *error = NULL;

	main_initialize ();

	/*
	 * Sync version
	 */
	if (!setup_book (&book_client))
		return 1;

	query = e_book_query_any_field_contains ("");
	sexp = e_book_query_to_string (query);
	e_book_query_unref (query);
	if (!e_book_client_get_view_sync (book_client, sexp, &view, NULL, &error)) {
		report_error ("get book view sync", &error);
		g_free (sexp);
		g_object_unref (book_client);

		return 1;
	}

	g_free (sexp);

	setup_and_start_view (view);
	start_main_loop (NULL, NULL);

	if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
		report_error ("client remove sync", &error);
		g_object_unref (book_client);

		return 1;
	}
	g_object_unref (book_client);

	/*
	 * Async version uids only
	 */
	if (!setup_book (&book_client))
		return 1;

	start_in_idle_with_main_loop (call_get_view, book_client);

	if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
		report_error ("client remove sync", &error);
		g_object_unref (book_client);

		return 1;
	}

	g_object_unref (book_client);

	return get_main_loop_stop_result ();
}
Ejemplo n.º 24
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);
}
Ejemplo n.º 25
0
static void
add_number_to_contact (gchar *number)
{
    EBook *book;
    EBookQuery *query;
    EBookView *view;
    GtkWidget *window, *contacts_treeview, *scroll, *groups_combo;
    GtkTreeModel *store, *group_store, *contact_filter;
    GError *err = NULL;

    window = gtk_dialog_new_with_buttons ("Add to Contact", NULL, 0,
					  "Cancel", GTK_RESPONSE_CANCEL,
					  "Add", GTK_RESPONSE_OK,
					  NULL);
    gtk_dialog_set_has_separator (GTK_DIALOG (window), FALSE);

    book = e_book_new_system_addressbook (&err);
    if (err)
      return;
    e_book_open (book, FALSE, &err);
    if (err)
     return;
    query = e_book_query_any_field_contains (NULL);
    e_book_get_book_view (book, query, NULL, 0, &view, &err);
    if (err)
      return;

    e_book_query_unref (query);
    e_book_view_start (view);


    store = hito_contact_store_new (view);

    group_store = hito_group_store_new ();
    hito_group_store_set_view (HITO_GROUP_STORE (group_store), view);
    hito_group_store_add_group (HITO_GROUP_STORE (group_store), hito_all_group_new ());
    hito_group_store_add_group (HITO_GROUP_STORE (group_store), hito_separator_group_new (-99));
    hito_group_store_add_group (HITO_GROUP_STORE (group_store), hito_separator_group_new (99));
    hito_group_store_add_group (HITO_GROUP_STORE (group_store), hito_no_category_group_new ());

    contact_filter = hito_contact_model_filter_new (HITO_CONTACT_STORE (store));

    groups_combo = hito_group_combo_new (HITO_GROUP_STORE (group_store));
    hito_group_combo_connect_filter (HITO_GROUP_COMBO (groups_combo),
                                   HITO_CONTACT_MODEL_FILTER (contact_filter));
    gtk_box_pack_start_defaults (GTK_BOX (GTK_DIALOG (window)->vbox), groups_combo);
    gtk_combo_box_set_active (GTK_COMBO_BOX (groups_combo), 0);



    contacts_treeview = hito_contact_view_new (HITO_CONTACT_STORE (store), HITO_CONTACT_MODEL_FILTER (contact_filter));

    scroll = moko_finger_scroll_new ();
    gtk_widget_set_size_request (scroll, -1, 300);
    gtk_box_pack_start_defaults (GTK_BOX (GTK_DIALOG (window)->vbox), scroll);

    gtk_container_add (GTK_CONTAINER (scroll), contacts_treeview);

    gtk_widget_show_all (scroll);
    gtk_widget_show_all (groups_combo);

    if (gtk_dialog_run (GTK_DIALOG (window)) == GTK_RESPONSE_OK)
    {
      GtkTreeIter iter;
      EContact *contact;
      EVCardAttribute *attr;
      GtkTreeModel *model;
      GtkTreeSelection *selection;

      selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (contacts_treeview));

      if (gtk_tree_selection_get_selected (selection, &model, &iter))
      {
        gtk_tree_model_get (model, &iter, COLUMN_CONTACT, &contact, -1);
        if (contact)
        {
          attr = e_vcard_attribute_new ("", EVC_TEL);
          e_vcard_add_attribute_with_value (E_VCARD (contact), attr, number);
          hito_vcard_attribute_set_type (attr, "Other");
          e_book_async_commit_contact (book, contact, NULL, NULL);
          g_object_unref (contact);
        }
      }
    }

    gtk_widget_destroy (window);
    g_object_unref (book);
}
Ejemplo n.º 26
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");
}
Ejemplo n.º 27
0
static void add_gnome_addressbook(GList **address_list)
{
  ESourceRegistry * registry = NULL;
  GError *error = NULL;
  GList *a;

  registry = e_source_registry_new_sync (NULL, &error);

  if (!registry || error) {
    debug_print("Error: Failed to get access to source registry: %s\n", error->message);
    g_error_free(error);
    return;
  }

  // create book accessor if necessary
  if(!eds_books) {
    GList *list_sources = e_source_registry_list_sources (registry, E_SOURCE_EXTENSION_ADDRESS_BOOK);
    for (a = list_sources; a; a = a->next) {
      ESource *source = E_SOURCE (a->data);
      if (e_source_get_enabled(source)) {
        EBook *eds_book = e_book_new(source, &error);

        if(!eds_book) {
          g_list_free_full(list_sources, g_object_unref);
          debug_print("Error: Could not get eds addressbook: %s\n", error->message);
          g_error_free(error);
          return;
        }
        eds_books = g_list_append (eds_books, eds_book);
      }
    }
    g_list_free_full(list_sources, g_object_unref);
  }

  for (a = eds_books; a; a = a->next) {
    EBook *eds_book = a->data;
    EBookQuery *query;
    EBookView *view;

    // open book if necessary
    if(!e_book_is_opened(eds_book) && !e_book_open(eds_book, TRUE, &error)) {
      debug_print("Error: Could not open eds addressbook: %s\n", error->message);
      g_error_free(error);
      return;
    }

    // query book
    query = e_book_query_field_exists(E_CONTACT_EMAIL);
    if(!e_book_get_book_view(eds_book, query, NULL, 0, &view, &error)) {
      debug_print("Error: Could not get eds addressbook view: %s\n", error->message);
      g_error_free(error);
    }
    e_book_query_unref(query);

    g_signal_connect(G_OBJECT(view), "contacts-added", G_CALLBACK(eds_contacts_added_cb), address_list);
    g_signal_connect(G_OBJECT(view), "sequence-complete", G_CALLBACK(eds_sequence_complete_cb), NULL);

    eds_waiting = TRUE;
    e_book_view_start(view);

    while(eds_waiting)
      gtk_main_iteration();

    e_book_view_stop(view);
    g_object_unref(view);
  }

}
static gboolean
start_tests (gpointer data)
{
	EwsBookBackendSqliteDB *ebsdb;
	gboolean populated = FALSE;
	gchar *vcard_str = NULL, *sexp;
	EBookQuery *q;
	GSList *uids = NULL;
	gboolean store_vcard = FALSE;

	g_print ("Creating the sqlitedb \n");
	op = "create sqlitedb";
	ebsdb = ews_book_backend_sqlitedb_new
					(cache_path, email, folderid, folder_name,
					 store_vcard, &error);
	if (error)
		goto exit;

	add_contacts (ebsdb);
	if (error)
		goto exit;

	g_print ("Getting is_populated \n");
	op = "set is_populated";
	ews_book_backend_sqlitedb_set_is_populated (ebsdb, folderid, TRUE, &error);
	if (error)
		goto exit;

	g_print ("Setting is_populated \n");
	op = "set is_populated";
	populated = ews_book_backend_sqlitedb_get_is_populated (ebsdb, folderid, &error);
	if (error)
		goto exit;
	g_print ("Populated: %d \n", populated);

	g_print ("Setting key value \n");
	op = "set key/value";
	ews_book_backend_sqlitedb_set_key_value (ebsdb, folderid, "customkey", "stored", &error);
	if (error)
		goto exit;

	g_print ("Get Vcard string \n");
	op = "get vcard string";
	vcard_str = ews_book_backend_sqlitedb_get_vcard_string (ebsdb, folderid, uid, NULL, NULL, &error);
	if (error)
		goto exit;
	g_print ("VCard: %s \n", vcard_str);
	g_free (vcard_str);

	q = e_book_query_field_test (E_CONTACT_FULL_NAME, E_BOOK_QUERY_CONTAINS, "test");
	sexp = e_book_query_to_string (q);
	search_db (ebsdb, "summary query", sexp);
	e_book_query_unref (q);
	g_free (sexp);
	if (error)
		goto exit;

	if (store_vcard) {
		q = e_book_query_any_field_contains ("word");
		sexp = e_book_query_to_string (q);
		search_db (ebsdb, "full_search query", sexp);
		e_book_query_unref (q);
		g_free (sexp);
		if (error)
			goto exit;
	}

	g_print ("Delete contact \n");
	op = "delete contact";
	uids = g_slist_append (uids, (gchar *) uid);
	ews_book_backend_sqlitedb_remove_contacts (ebsdb, folderid, uids, &error);
	g_slist_free (uids);
	if (error)
		goto exit;

	g_print ("Delete addressbook \n");
	op = "delete addressbook";
	ews_book_backend_sqlitedb_delete_addressbook (ebsdb, folderid, &error);

exit:
	g_object_unref (ebsdb);
	quit_tests ();
	return FALSE;
}
Ejemplo n.º 29
0
static void
action_address_book_save_as_cb (GtkAction *action,
                                EBookShellView *book_shell_view)
{
	EShell *shell;
	EShellView *shell_view;
	EShellWindow *shell_window;
	EShellBackend *shell_backend;
	EBookShellContent *book_shell_content;
	EAddressbookModel *model;
	EAddressbookView *view;
	EActivity *activity;
	EBookQuery *query;
	EBookClient *book;
	GSList *list = NULL;
	GFile *file;
	gchar *string;

	shell_view = E_SHELL_VIEW (book_shell_view);
	shell_window = e_shell_view_get_shell_window (shell_view);
	shell_backend = e_shell_view_get_shell_backend (shell_view);
	shell = e_shell_window_get_shell (shell_window);

	book_shell_content = book_shell_view->priv->book_shell_content;
	view = e_book_shell_content_get_current_view (book_shell_content);
	g_return_if_fail (view != NULL);

	model = e_addressbook_view_get_model (view);
	book = e_addressbook_model_get_client (model);

	query = e_book_query_any_field_contains ("");
	string = e_book_query_to_string (query);
	e_book_query_unref (query);

	e_book_client_get_contacts_sync (book, string, &list, NULL, NULL);
	g_free (string);

	if (list == NULL)
		goto exit;

	string = eab_suggest_filename (list);
	file = e_shell_run_save_dialog (
		/* Translators: This is a save dialog title */
		shell, _("Save as vCard"), string,
		"*.vcf:text/x-vcard,text/directory", NULL, NULL);
	g_free (string);

	if (file == NULL)
		goto exit;

	string = eab_contact_list_to_string (list);
	if (string == NULL) {
		g_warning ("Could not convert contact list to a string");
		g_object_unref (file);
		goto exit;
	}

	/* XXX No callback means errors are discarded.
	 *
	 *     There's an EAlert for this which I'm not using
	 *     until I figure out a better way to display errors:
	 *
	 *     "addressbook:save-error"
	 */
	activity = e_file_replace_contents_async (
		file, string, strlen (string), NULL, FALSE,
		G_FILE_CREATE_NONE, (GAsyncReadyCallback) NULL, NULL);
	e_shell_backend_add_activity (shell_backend, activity);

	/* Free the string when the activity is finalized. */
	g_object_set_data_full (
		G_OBJECT (activity),
		"file-content", string,
		(GDestroyNotify) g_free);

	g_object_unref (file);

exit:
	e_client_util_free_object_slist (list);
}
Ejemplo n.º 30
0
/*
 * Search for a buddy in the Evolution contacts.
 *
 * @param buddy The buddy to search for.
 * @param query An optional query. This function takes ownership of @a query,
 *              so callers must e_book_query_ref() it in advance (to obtain a
 *              second reference) if they want to reuse @a query.
 */
EContact *
gevo_search_buddy_in_contacts(PurpleBuddy *buddy, EBookQuery *query)
{
	ESourceList *addressbooks;
	GError *err = NULL;
	EBookQuery *full_query;
	GSList *groups, *g;
	EContact *result;
	EContactField protocol_field = gevo_prpl_get_field(buddy->account, buddy);

	if (protocol_field == 0)
		return NULL;

	if (query != NULL)
	{
		EBookQuery *queries[2];

		queries[0] = query;
		queries[1] = e_book_query_field_test(protocol_field, E_BOOK_QUERY_IS, buddy->name);
		if (queries[1] == NULL)
		{
			purple_debug_error("evolution", "Error in creating protocol query\n");
			e_book_query_unref(query);
			return NULL;
		}

		full_query = e_book_query_and(2, queries, TRUE);
	}
	else
	{
		full_query = e_book_query_field_test(protocol_field, E_BOOK_QUERY_IS, buddy->name);
		if (full_query == NULL)
		{
			purple_debug_error("evolution", "Error in creating protocol query\n");
			return NULL;
		}
	}

	if (!e_book_get_addressbooks(&addressbooks, &err))
	{
		purple_debug_error("evolution",
						 "Unable to fetch list of address books.\n");
		e_book_query_unref(full_query);
		if (err != NULL)
			g_error_free(err);
		return NULL;
	}

	groups = e_source_list_peek_groups(addressbooks);
	if (groups == NULL)
	{
		g_object_unref(addressbooks);
		e_book_query_unref(full_query);
		return NULL;
	}

	for (g = groups; g != NULL; g = g->next)
	{
		GSList *sources, *s;
		sources = e_source_group_peek_sources(g->data);
		for (s = sources; s != NULL; s = s->next)
		{
			result = gevo_run_query_in_uri(e_source_get_uri(E_SOURCE(s->data)), full_query);
			if (result != NULL) {
			    g_object_unref(addressbooks);
				e_book_query_unref(full_query);
			    return result;
			}
		}
	}

	g_object_unref(addressbooks);
	e_book_query_unref(full_query);
	return NULL;
}