static void
remove_contact_by_uid_cb (GObject *source_object,
                          GAsyncResult *result,
                          gpointer uid)
{
	GError *error = NULL;
	EContact *contact = NULL;

	if (!e_book_client_remove_contact_by_uid_finish (E_BOOK_CLIENT (source_object), result, &error)) {
		report_error ("remove contact by uid finish", &error);
		stop_main_loop (1);
		return;
	}

	if (!e_book_client_get_contact_sync (E_BOOK_CLIENT (source_object), uid, &contact, NULL, &error) &&
	    g_error_matches (error, E_BOOK_CLIENT_ERROR, E_BOOK_CLIENT_ERROR_CONTACT_NOT_FOUND)) {
		g_clear_error (&error);
		stop_main_loop (0);
	} else {
		report_error ("fail with get contact on removed contact", &error);
		if (contact)
			g_object_unref (contact);
		stop_main_loop (1);
	}
}
static void
remove_contacts_cb (GObject *source_object,
                    GAsyncResult *result,
                    gpointer user_data)
{
	GError *error = NULL;
	RemoveData *data = (RemoveData *) user_data;

	if (!e_book_client_remove_contacts_finish (E_BOOK_CLIENT (source_object), result, &error))
		g_error ("remove contacts finish: %s", error->message);

	check_removed (E_BOOK_CLIENT (source_object), data->uids);
	g_main_loop_quit (data->loop);
}
Example #3
0
static void
remove_contact_ready_cb (GObject *source_object,
                         GAsyncResult *result,
                         gpointer user_data)
{
	EBookClient *book_client = E_BOOK_CLIENT (source_object);
	EContactMergingLookup *lookup = user_data;
	GError *error = NULL;

	g_return_if_fail (book_client != NULL);
	g_return_if_fail (lookup != NULL);

	e_book_client_remove_contact_finish (book_client, result, &error);

	if (error != NULL) {
		g_warning (
			"%s: Failed to remove contact: %s",
			G_STRFUNC, error->message);
		g_error_free (error);
	}

	e_book_client_add_contact (
		book_client, lookup->contact, NULL,
		add_contact_ready_cb, lookup);
}
static void
contact_modified_cb (GObject *source_object,
                     GAsyncResult *result,
                     gpointer user_data)
{
	ModifyData *data = (ModifyData *) user_data;
	GError *error = NULL;

	if (!e_book_client_modify_contact_finish (E_BOOK_CLIENT (source_object), result, &error))
		g_error ("modify contact finish: %s", error->message);

	e_book_client_get_contact (
		E_BOOK_CLIENT (source_object),
		e_contact_get_const (data->contact, E_CONTACT_UID),
		NULL, contact_ready_cb, data->loop);
}
Example #5
0
static void
client_view_ready_cb (GObject *source_object,
                      GAsyncResult *result,
                      gpointer user_data)
{
	EBookClient *book_client = E_BOOK_CLIENT (source_object);
	EBookClientView *client_view = NULL;
	EAddressbookModel *model = user_data;
	GError *error = NULL;

	if (!e_book_client_get_view_finish (book_client, result, &client_view, &error))
		client_view = NULL;

	if (error) {
		eab_error_dialog (NULL, _("Error getting book view"), error);
		g_error_free (error);
		return;
	}

	remove_book_view (model);
	free_data (model);

	model->priv->client_view = client_view;
	if (model->priv->client_view) {
		model->priv->create_contact_id = g_signal_connect (
			model->priv->client_view, "objects-added",
			G_CALLBACK (view_create_contact_cb), model);
		model->priv->remove_contact_id = g_signal_connect (
			model->priv->client_view, "objects-removed",
			G_CALLBACK (view_remove_contact_cb), model);
		model->priv->modify_contact_id = g_signal_connect (
			model->priv->client_view, "objects-modified",
			G_CALLBACK (view_modify_contact_cb), model);
		model->priv->status_message_id = g_signal_connect (
			model->priv->client_view, "progress",
			G_CALLBACK (view_progress_cb), model);
		model->priv->view_complete_id = g_signal_connect (
			model->priv->client_view, "complete",
			G_CALLBACK (view_complete_cb), model);

		model->priv->search_in_progress = TRUE;
	}

	g_signal_emit (model, signals[MODEL_CHANGED], 0);
	g_signal_emit (model, signals[SEARCH_STARTED], 0);
	g_signal_emit (model, signals[STOP_STATE_CHANGED], 0);

	if (model->priv->client_view) {
		e_book_client_view_start (model->priv->client_view, &error);

		if (error != NULL) {
			g_warning (
				"%s: Failed to start client view: %s",
				G_STRFUNC, error->message);
			g_error_free (error);
		}
	}
}
Example #6
0
static void
addressbook_model_client_notify_readonly_cb (EClientCache *client_cache,
                                             EClient *client,
                                             GParamSpec *pspec,
                                             EAddressbookModel *model)
{
	if (!E_IS_BOOK_CLIENT (client))
		return;

	if (E_BOOK_CLIENT (client) == model->priv->book_client) {
		gboolean editable = !e_client_is_readonly (client);
		e_addressbook_model_set_editable (model, editable);
	}
}
static void
get_view_cb (GObject *source_object,
             GAsyncResult *result,
             gpointer user_data)
{
	EBookClientView *view;
	GError *error = NULL;
	GMainLoop *loop = (GMainLoop *) user_data;

	if (!e_book_client_get_view_finish (E_BOOK_CLIENT (source_object), result, &view, &error))
		g_error ("get view finish: %s", error->message);

	setup_and_start_view (view, loop);
}
static void
get_view_cb (GObject *source_object,
             GAsyncResult *result,
             gpointer user_data)
{
	EBookClientView *view;
	GError *error = NULL;

	if (!e_book_client_get_view_finish (E_BOOK_CLIENT (source_object), result, &view, &error)) {
		report_error ("get view finish", &error);
		stop_main_loop (1);

		return;
	}

	setup_and_start_view (view);
}
static void
contact_ready_cb (GObject *source_object,
                  GAsyncResult *result,
                  gpointer user_data)
{
	EContact *contact;
	GError *error = NULL;
	GMainLoop *loop = (GMainLoop *) user_data;

	if (!e_book_client_get_contact_finish (E_BOOK_CLIENT (source_object), result, &contact, &error))
		g_error ("get contact finish: %s", error->message);

	verify_modify (contact);

	g_object_unref (contact);
	g_main_loop_quit (loop);
}
Example #10
0
static void
get_view_ready_cb (GObject *source_object,
                   GAsyncResult *result,
                   gpointer user_data)
{
	GtkPrintOperation *operation = user_data;
	EBookClient *book_client = E_BOOK_CLIENT (source_object);
	EBookClientView *client_view = NULL;
	EContactPrintContext *ctxt;
	GError *error = NULL;

	e_book_client_get_view_finish (book_client, result, &client_view, &error);

	ctxt = g_object_get_data (G_OBJECT (operation), "contact-print-ctx");
	g_return_if_fail (ctxt != NULL);

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

		gtk_print_operation_run (operation, ctxt->action, NULL, NULL);
		g_object_unref (operation);
	} else {
		g_signal_connect (
			client_view, "objects-added",
			G_CALLBACK (contacts_added), ctxt);
		g_signal_connect (
			client_view, "complete",
			G_CALLBACK (view_complete), operation);

		e_book_client_view_start (client_view, &error);

		if (error != NULL) {
			g_warning (
				"%s: Failed to start view: %s",
				G_STRFUNC, error->message);
			g_error_free (error);

			gtk_print_operation_run (operation, ctxt->action, NULL, NULL);
			g_object_unref (operation);
		}
	}
}
static void
add_contact_cb (GObject *source_object,
                GAsyncResult *result,
                gpointer user_data)
{
	GError *error = NULL;
	gchar *uid;

	if (!e_book_client_add_contact_finish (E_BOOK_CLIENT (source_object), result, &uid, &error)) {
		report_error ("add contact finish", &error);
		stop_main_loop (1);
		return;
	}

	printf ("Contact added as '%s'\n", uid);
	g_free (uid);
	stop_main_loop (0);
}
Example #12
0
static void
book_client_connect_cb (GObject *source_object,
                        GAsyncResult *result,
                        gpointer user_data)
{
	CSVImporter *gci = user_data;
	EClient *client;

	client = e_book_client_connect_finish (result, NULL);

	if (client == NULL) {
		csv_import_done (gci);
		return;
	}

	gci->book_client = E_BOOK_CLIENT (client);
	gci->idle_id = g_idle_add (csv_import_contacts, gci);
}
static void
book_loaded_cb (GObject *source_object,
                GAsyncResult *result,
                gpointer user_data)
{
	ESource *source = E_SOURCE (source_object);
	VCardImporter *gci = user_data;
	EClient *client = NULL;

	e_client_utils_open_new_finish (source, result, &client, NULL);

	if (client == NULL) {
		vcard_import_done (gci);
		return;
	}

	gci->book_client = E_BOOK_CLIENT (client);

	if (gci->encoding == VCARD_ENCODING_UTF16) {
		gchar *tmp;

		gunichar2 *contents_utf16 = (gunichar2 *) gci->contents;
		tmp = utf16_to_utf8 (contents_utf16);
		g_free (gci->contents);
		gci->contents = tmp;

	} else if (gci->encoding == VCARD_ENCODING_LOCALE) {
		gchar *tmp;
		tmp = g_locale_to_utf8 (gci->contents, -1, NULL, NULL, NULL);
		g_free (gci->contents);
		gci->contents = tmp;
	}

	gci->contactlist = eab_contact_list_from_string (gci->contents);
	g_free (gci->contents);
	gci->contents = NULL;
	gci->iterator = gci->contactlist;
	gci->total = g_slist_length (gci->contactlist);

	if (gci->iterator)
		gci->idle_id = g_idle_add (vcard_import_contacts, gci);
	else
		vcard_import_done (gci);
}
static void
book_loaded_cb (GObject *source_object,
                GAsyncResult *result,
                gpointer user_data)
{
	ESource *source = E_SOURCE (source_object);
	LDIFImporter *gci = user_data;
	EClient *client = NULL;

	e_client_utils_open_new_finish (source, result, &client, NULL);

	if (client == NULL) {
		ldif_import_done (gci);
		return;
	}

	gci->book_client = E_BOOK_CLIENT (client);
	gci->idle_id = g_idle_add (ldif_import_contacts, gci);
}
Example #15
0
static void
add_contact_ready_cb (GObject *source_object,
                      GAsyncResult *result,
                      gpointer user_data)
{
	EBookClient *book_client = E_BOOK_CLIENT (source_object);
	EContactMergingLookup *lookup = user_data;
	gchar *uid = NULL;
	GError *error = NULL;

	g_return_if_fail (book_client != NULL);
	g_return_if_fail (lookup != NULL);

	e_book_client_add_contact_finish (book_client, result, &uid, &error);

	final_id_cb (book_client, error, uid, lookup);

	if (error != NULL)
		g_error_free (error);
}
Example #16
0
static void
modify_contact_ready_cb (GObject *source_object,
                         GAsyncResult *result,
                         gpointer user_data)
{
	EBookClient *book_client = E_BOOK_CLIENT (source_object);
	EContactMergingLookup *lookup = user_data;
	GError *error = NULL;

	g_return_if_fail (book_client != NULL);
	g_return_if_fail (lookup != NULL);

	e_book_client_modify_contact_finish (book_client, result, &error);

	if (lookup->op == E_CONTACT_MERGING_ADD)
		final_cb_as_id (book_client, error, lookup);
	else
		final_cb (book_client, error, lookup);

	if (error != NULL)
		g_error_free (error);
}
Example #17
0
static void
import_contacts (void)
{
	EShell *shell;
	ESourceRegistry *registry;
	EClient *client = NULL;
	GList *list;
	gchar *name;
	GString *line;
	FILE *fp;
	gsize offset;
	const gchar *extension_name;
	GError *error = NULL;

	printf ("importing pine addressbook\n");

	shell = e_shell_get_default ();
	registry = e_shell_get_registry (shell);
	extension_name = E_SOURCE_EXTENSION_ADDRESS_BOOK;

	name = g_build_filename (g_get_home_dir (), ".addressbook", NULL);
	fp = fopen (name, "r");
	g_free (name);
	if (fp == NULL)
		return;

	list = e_source_registry_list_sources (registry, extension_name);

	if (list != NULL) {
		ESource *source;

		source = E_SOURCE (list->data);
		client = e_book_client_connect_sync (source, 30, NULL, &error);
	} else {
		/* No address books exist. */
		g_warning ("%s: No address books exist.", G_STRFUNC);
		fclose (fp);
		return;
	}

	g_list_free_full (list, (GDestroyNotify) g_object_unref);

	if (error != NULL) {
		g_warning (
			"%s: Failed to open book client: %s",
			G_STRFUNC, error ? error->message : "Unknown error");
		g_clear_error (&error);
		fclose (fp);
		return;
	}

	line = g_string_new ("");
	g_string_set_size (line, 256);
	offset = 0;
	while (fgets (line->str + offset, 256, fp)) {
		gsize len;

		len = strlen (line->str + offset) + offset;
		if (line->str[len - 1] == '\n')
			g_string_truncate (line, len - 1);
		else if (!feof (fp)) {
			offset = len;
			g_string_set_size (line, len + 256);
			continue;
		} else {
			g_string_truncate (line, len);
		}

		import_contact (E_BOOK_CLIENT (client), line->str);
		offset = 0;
	}

	g_string_free (line, TRUE);
	fclose (fp);
	g_object_unref (client);
}
/* We need this function to he defined all the time. */
static void
action_address_book_map_cb (GtkAction *action,
                            EBookShellView *book_shell_view)
{
#ifdef WITH_CONTACT_MAPS
	EShell *shell;
	EShellView *shell_view;
	EShellBackend *shell_backend;
	EContactMapWindow *map_window;
	EBookShellSidebar *book_shell_sidebar;
	ESource *source;
	ESourceSelector *selector;
	EClient *client;
	EClientCache *client_cache;
	GError *error = NULL;

	book_shell_sidebar = book_shell_view->priv->book_shell_sidebar;
	selector = e_book_shell_sidebar_get_selector (book_shell_sidebar);
	source = e_source_selector_ref_primary_selection (selector);
	g_return_if_fail (source != NULL);

	shell_view = E_SHELL_VIEW (book_shell_view);
	shell_backend = e_shell_view_get_shell_backend (shell_view);
	shell = e_shell_backend_get_shell (shell_backend);
	client_cache = e_shell_get_client_cache (shell);

	/* FIXME This blocks.  Needs to be asynchronous. */
	client = e_client_cache_get_client_sync (
		client_cache, source,
		E_SOURCE_EXTENSION_ADDRESS_BOOK, (guint32) -1,
		NULL, &error);

	g_object_unref (source);

	/* Sanity check. */
	g_return_if_fail (
		((client != NULL) && (error == NULL)) ||
		((client == NULL) && (error != NULL)));

	if (error != NULL) {
		g_warning ("Error loading addressbook: %s", error->message);
		g_error_free (error);
		return;
	}

	map_window = e_contact_map_window_new ();
	e_contact_map_window_load_addressbook (
		map_window, E_BOOK_CLIENT (client));

	/* Free the map_window automatically when it is closed */
	g_signal_connect_swapped (
		map_window, "hide",
		G_CALLBACK (gtk_widget_destroy), GTK_WIDGET (map_window));
	g_signal_connect (
		map_window, "show-contact-editor",
		G_CALLBACK (map_window_show_contact_editor_cb), book_shell_view);

	gtk_widget_show_all (GTK_WIDGET (map_window));

	g_object_unref (client);
#endif
}
static void
map_window_show_contact_editor_cb (EContactMapWindow *window,
                                   const gchar *contact_uid,
                                   gpointer user_data)
{
	EBookShellView *book_shell_view = user_data;
	EBookShellSidebar *book_shell_sidebar;
	EShell *shell;
	EShellView *shell_view;
	EShellBackend *shell_backend;
	ESource *source;
	ESourceSelector *selector;
	EClient *client;
	EClientCache *client_cache;
	EContact *contact;
	EABEditor *editor;
	GError *error = NULL;

	book_shell_sidebar = book_shell_view->priv->book_shell_sidebar;
	selector = e_book_shell_sidebar_get_selector (book_shell_sidebar);
	source = e_source_selector_ref_primary_selection (selector);
	g_return_if_fail (source != NULL);

	shell_view = E_SHELL_VIEW (book_shell_view);
	shell_backend = e_shell_view_get_shell_backend (shell_view);
	shell = e_shell_backend_get_shell (shell_backend);
	client_cache = e_shell_get_client_cache (shell);

	/* FIXME This blocks.  Needs to be asynchronous. */
	client = e_client_cache_get_client_sync (
		client_cache, source,
		E_SOURCE_EXTENSION_ADDRESS_BOOK, (guint32) -1,
		NULL, &error);

	g_object_unref (source);

	/* Sanity check. */
	g_return_if_fail (
		((client != NULL) && (error == NULL)) ||
		((client == NULL) && (error != NULL)));

	if (error != NULL) {
		g_warning ("Error loading addressbook: %s", error->message);
		g_error_free (error);
		return;
	}

	e_book_client_get_contact_sync (
		E_BOOK_CLIENT (client), contact_uid, &contact, NULL, &error);
	if (error != NULL) {
		g_warning ("Error getting contact from addressbook: %s", error->message);
		g_error_free (error);
		g_object_unref (client);
		return;
	}

	editor = e_contact_editor_new (
		shell, E_BOOK_CLIENT (client), contact, FALSE, TRUE);

	g_signal_connect (
		editor, "contact-modified",
		G_CALLBACK (contact_editor_contact_modified_cb), window);

	eab_editor_show (editor);
	g_object_unref (client);
}
Example #20
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);
}