Description: Restore user level function gcal_contact_get_phone(),
gcal_contact_set_email() and gcal_contact_set_phone()
This should be enough to maintain ABI backward compatibility while
ensuring that support for multiple phones/emails work too.
Author: Adenilson Cavalcanti da Silva <adenilson.silva@openbossa.org>

--- a/inc/gcontact.h
+++ b/inc/gcontact.h
@@ -84,7 +84,7 @@ typedef enum {
 	P_WORK_PAGER,
 	P_ITEMS_COUNT			// must be the last one!
 } gcal_phone_type;
-	
+
 /** Email types allowed by Google API */
 typedef enum {
 	E_INVALID = -1,
@@ -382,6 +382,7 @@ char *gcal_contact_get_email_address(gca
 gcal_email_type gcal_contact_get_email_address_type(gcal_contact_t contact, int i);
 
 char *gcal_contact_get_email(gcal_contact_t contact);
+
 /** Access contact description.
  *
  * This the place where contacts notes can be retrieved.
@@ -466,6 +467,9 @@ int gcal_contact_get_phone_numbers_count
 char *gcal_contact_get_phone_number(gcal_contact_t contact, int i);
 gcal_phone_type gcal_contact_get_phone_number_type(gcal_contact_t contact, int i);
 
+
+char *gcal_contact_get_phone(gcal_contact_t contact);
+
 /** Access contact address (structuredPostalAddress.formattedAddress).
  *
  * @param contact A contact object, see \ref gcal_contact.
@@ -600,7 +604,7 @@ int gcal_contact_set_title(gcal_contact_
  *
  * @param contact A contact object, see \ref gcal_contact.
  *
- * @param field Email address..
+ * @param field Email address.
  *
  * @param type Email address type.
  *
@@ -612,6 +616,22 @@ int gcal_contact_set_title(gcal_contact_
 int gcal_contact_add_email_address(gcal_contact_t contact, const char *field,
 				   gcal_email_type type, int pref);
 
+/** Sets the prefered email.
+ *
+ * This is a convenience function, it is implemented internally using
+ * \ref gcal_contact_add_email_address.
+ *
+ * The email type defauls to HOME.
+ *
+ * @param contact A contact object, see \ref gcal_contact.
+ *
+ * @param pref_email Email address.
+ *
+ * @return 0 for success, -1 otherwise
+ */
+int gcal_contact_set_email(gcal_contact_t contact, const char *pref_email);
+
+
 /* TODO: document new functions */
 int gcal_contact_delete_email_addresses(gcal_contact_t contact);
 
@@ -674,6 +694,25 @@ int gcal_contact_set_etag(gcal_contact_t
 int gcal_contact_add_phone_number(gcal_contact_t contact, const char *field,
 				  gcal_phone_type type);
 
+
+/** Sets contact prefered phone.
+ *
+ * This is a convenience function, it is implemented internally using
+ * \ref gcal_contact_add_phone_number. Pay attention that when this
+ * function is called, it will destroy all the contact's phone list
+ * to ensure that the prefered email will be the first to be added.
+ *
+ * The phone type default to P_MOBILE.
+ *
+ * @param contact A contact object, see \ref gcal_contact.
+ *
+ * @param phone A phone number (e.g. "+551132314412")
+ *
+ * @return 0 for success, -1 otherwise
+ */
+int gcal_contact_set_phone(gcal_contact_t contact, const char *phone);
+
+
 /* TODO: document new functions */
 int gcal_contact_delete_phone_numbers(gcal_contact_t contact);
 
--- a/src/gcontact.c
+++ b/src/gcontact.c
@@ -469,6 +469,17 @@ char *gcal_contact_get_phone_number(gcal
 	return contact->phone_numbers_field[i];
 }
 
+char *gcal_contact_get_phone(gcal_contact_t contact)
+{
+	if ((!contact))
+		return NULL;
+
+	char *res;
+	/* The prefered phone is *always* the first */
+	res = gcal_contact_get_phone_number(contact, 0);
+	return res;
+}
+
 gcal_phone_type gcal_contact_get_phone_number_type(gcal_contact_t contact, int i)
 {
 	gcal_phone_type result = P_INVALID;
@@ -685,6 +696,13 @@ int gcal_contact_add_email_address(gcal_
 	return result;
 }
 
+int gcal_contact_set_email(gcal_contact_t contact, const char *pref_email)
+{
+	int res;
+	res = gcal_contact_add_email_address(contact, pref_email, E_HOME, 1);
+	return res;
+}
+
 int gcal_contact_set_url(gcal_contact_t contact, const char *field)
 {
 	int result = -1;
@@ -786,6 +804,17 @@ int gcal_contact_add_phone_number(gcal_c
 	return result;
 }
 
+int gcal_contact_set_phone(gcal_contact_t contact, const char *phone)
+{
+	int res;
+	res = gcal_contact_delete_phone_numbers(contact);
+	if (res)
+		return res;
+
+	res = gcal_contact_add_phone_number(contact, phone, P_MOBILE);
+	return res;
+}
+
 int gcal_contact_set_address(gcal_contact_t contact, const char *field)
 {
 	int result = -1;
--- a/utests/utest_userapi.c
+++ b/utests/utest_userapi.c
@@ -339,8 +339,10 @@ START_TEST (test_oper_contact)
 	contact = gcal_contact_new(NULL);
 	fail_if (!contact, "Cannot construct contact object!");
 	gcal_contact_set_title(contact, "John Doe");
-	gcal_contact_delete_email_addresses(contact);
-	gcal_contact_add_email_address(contact, "john.doe@foo.bar.com", E_OTHER, 1);
+	gcal_contact_set_email(contact, "john.doe@foo.bar.com");
+	gcal_contact_add_email_address(contact, "jonny@theman.com", E_OTHER, 0);
+	gcal_contact_set_phone(contact, "111-2222-3333-888");
+
 
 	/* Create a gcal object and authenticate */
 	gcal = gcal_new(GCONTACT);
@@ -351,11 +353,17 @@ START_TEST (test_oper_contact)
 	result = gcal_add_contact(gcal, contact);
 	fail_if(result == -1, "Failed adding a new contact!");
 
+
+	/* Tests integraty */
+	result = strcmp(gcal_contact_get_phone(contact), "111-2222-3333-888");
+	fail_if(result != 0, "Failed to extract phone from gcal_contact_t!");
+
+
 	/* Edit this contact */
 	gcal_contact_set_title(contact, "John 'The Generic' Doe");
 	fail_if(result == -1, "Failed editing contact!");
 	gcal_contact_delete_email_addresses(contact);
-	gcal_contact_add_email_address(contact, "john.super.doe@foo.bar.com", E_OTHER, 1);
+	gcal_contact_set_email(contact, "john.super.doe@foo.bar.com");
 	fail_if(result == -1, "Failed editing contact!");
 	result = gcal_update_contact(gcal, contact);
 	fail_if(result == -1, "Failed uploading edited contact!");
@@ -446,7 +454,6 @@ START_TEST (test_contact_photo)
 	contact = gcal_contact_new(NULL);
 	fail_if (!contact, "Cannot construct contact object!");
 	gcal_contact_set_title(contact, "Gromit");
-	gcal_contact_delete_email_addresses(contact);
 	gcal_contact_add_email_address(contact, "gromit@wallace.com", E_OTHER, 1);
 	fail_if(gcal_contact_set_photo(contact, photo_data, result),
 		"Failed copying photo data");
@@ -558,7 +565,6 @@ START_TEST (test_url_sanity_contact)
 	fail_if(result == -1, "Cannot authenticate!");
 
   	gcal_contact_set_title(contact, "Insanity in edit URL");
-	gcal_contact_delete_email_addresses(contact);
 	gcal_contact_add_email_address(contact, "prooftest@add.get.com", E_OTHER, 1);
 
 	fail_if((result = gcal_add_contact(gcal, contact)) != 0,
