int main (int argc, char **argv) { EBook *book; EContact *contact; GError *error = NULL; char *vcard; g_type_init (); printf ("getting the self contact\n"); if (!e_book_get_self (&contact, &book, &error)) { printf ("error %d getting self: %s\n", error->code, error->message); g_clear_error (&error); return -1; } vcard = e_vcard_to_string (E_VCARD (contact), EVC_FORMAT_VCARD_30); printf ("self contact = \n%s\n", vcard); g_free (vcard); g_object_unref (contact); g_object_unref (book); return 0; }
static void create_salut_account (void) { McProfile *profile; McProtocol *protocol; gboolean salut_created = FALSE; McAccount *account; GList *accounts; EBook *book; EContact *contact; gchar *nickname = NULL; gchar *first_name = NULL; gchar *last_name = NULL; gchar *email = NULL; gchar *jid = NULL; GError *error = NULL; /* Check if we already created a salut account */ empathy_conf_get_bool (empathy_conf_get(), EMPATHY_PREFS_SALUT_ACCOUNT_CREATED, &salut_created); if (salut_created) { return; } DEBUG ("Try to add a salut account..."); /* Check if the salut CM is installed */ profile = mc_profile_lookup ("salut"); if (!profile) { DEBUG ("No salut profile"); return; } protocol = mc_profile_get_protocol (profile); if (!protocol) { DEBUG ("Salut not installed"); g_object_unref (profile); return; } g_object_unref (protocol); /* Get self EContact from EDS */ if (!e_book_get_self (&contact, &book, &error)) { DEBUG ("Failed to get self econtact: %s", error ? error->message : "No error given"); g_clear_error (&error); g_object_unref (profile); return; } empathy_conf_set_bool (empathy_conf_get (), EMPATHY_PREFS_SALUT_ACCOUNT_CREATED, TRUE); /* Check if there is already a salut account */ accounts = mc_accounts_list_by_profile (profile); if (accounts) { DEBUG ("There is already a salut account"); mc_accounts_list_free (accounts); g_object_unref (profile); return; } account = mc_account_create (profile); mc_account_set_display_name (account, _("People nearby")); nickname = e_contact_get (contact, E_CONTACT_NICKNAME); first_name = e_contact_get (contact, E_CONTACT_GIVEN_NAME); last_name = e_contact_get (contact, E_CONTACT_FAMILY_NAME); email = e_contact_get (contact, E_CONTACT_EMAIL_1); jid = e_contact_get (contact, E_CONTACT_IM_JABBER_HOME_1); if (!tp_strdiff (nickname, "nickname")) { g_free (nickname); nickname = NULL; } DEBUG ("Salut account created:\nnickname=%s\nfirst-name=%s\n" "last-name=%s\nemail=%s\njid=%s\n", nickname, first_name, last_name, email, jid); mc_account_set_param_string (account, "nickname", nickname ? nickname : ""); mc_account_set_param_string (account, "first-name", first_name ? first_name : ""); mc_account_set_param_string (account, "last-name", last_name ? last_name : ""); mc_account_set_param_string (account, "email", email ? email : ""); mc_account_set_param_string (account, "jid", jid ? jid : ""); g_free (nickname); g_free (first_name); g_free (last_name); g_free (email); g_free (jid); g_object_unref (account); g_object_unref (profile); g_object_unref (contact); g_object_unref (book); }
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; GSList *l; EContact *me; EVCard *evcard; GError *gerr = NULL; EBook *eb; EVCardAttribute *attrib; char *uid, *tel, *cname; if (g_strcmp0(PB_CONTACTS_FOLDER, name) != 0) { if (err) *err = -ENOENT; return NULL; } DBG(""); 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; data->query = query; data->ebooks = open_ebooks(); /* Add 0.vcf */ if (e_book_get_self(&me, &eb, &gerr) == FALSE) { g_error_free(gerr); goto next; } evcard = E_VCARD(me); cname = evcard_name_attribute_to_string(evcard); if (!cname) cname = g_strdup(""); attrib = e_vcard_get_attribute(evcard, EVC_UID); uid = e_vcard_attribute_get_value(attrib); if (!uid) uid = g_strdup(""); 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, 0, cname, NULL, tel, data->user_data); data->count++; g_free(cname); g_free(uid); g_free(tel); g_object_unref(eb); next: for (l = data->ebooks; l != NULL; l = g_slist_next(l)) { EBook *ebook = l->data; if (e_book_is_opened(ebook) == FALSE) continue; if (e_book_get_contacts_async(ebook, query, cache_cb, data) == TRUE) data->queued_calls++; } if (err) *err = (data->queued_calls == 0 ? -ENOENT : 0); return data; }
static void create_salut_account_am_ready_cb (GObject *source_object, GAsyncResult *result, gpointer user_data) { TpAccountManager *account_manager = TP_ACCOUNT_MANAGER (source_object); EmpathyConnectionManagers *managers = user_data; EmpathyAccountSettings *settings; TpConnectionManager *manager; const TpConnectionManagerProtocol *protocol; EBook *book; EContact *contact; gchar *nickname = NULL; gchar *first_name = NULL; gchar *last_name = NULL; gchar *email = NULL; gchar *jid = NULL; GError *error = NULL; if (!tp_account_manager_prepare_finish (account_manager, result, &error)) { DEBUG ("Failed to prepare account manager: %s", error->message); g_error_free (error); goto out; } if (!should_create_salut_account (account_manager)) goto out; manager = empathy_connection_managers_get_cm (managers, "salut"); if (manager == NULL) { DEBUG ("Salut not installed, not making a salut account"); goto out; } protocol = tp_connection_manager_get_protocol (manager, "local-xmpp"); if (protocol == NULL) { DEBUG ("Salut doesn't support local-xmpp!!"); goto out; } DEBUG ("Trying to add a salut account..."); /* Get self EContact from EDS */ if (!e_book_get_self (&contact, &book, &error)) { DEBUG ("Failed to get self econtact: %s", error ? error->message : "No error given"); g_clear_error (&error); goto out; } settings = empathy_account_settings_new ("salut", "local-xmpp", _("People nearby")); nickname = e_contact_get (contact, E_CONTACT_NICKNAME); first_name = e_contact_get (contact, E_CONTACT_GIVEN_NAME); last_name = e_contact_get (contact, E_CONTACT_FAMILY_NAME); email = e_contact_get (contact, E_CONTACT_EMAIL_1); jid = e_contact_get (contact, E_CONTACT_IM_JABBER_HOME_1); if (!tp_strdiff (nickname, "nickname")) { g_free (nickname); nickname = NULL; } DEBUG ("Salut account created:\nnickname=%s\nfirst-name=%s\n" "last-name=%s\nemail=%s\njid=%s\n", nickname, first_name, last_name, email, jid); empathy_account_settings_set_string (settings, "nickname", nickname ? nickname : ""); empathy_account_settings_set_string (settings, "first-name", first_name ? first_name : ""); empathy_account_settings_set_string (settings, "last-name", last_name ? last_name : ""); empathy_account_settings_set_string (settings, "email", email ? email : ""); empathy_account_settings_set_string (settings, "jid", jid ? jid : ""); empathy_account_settings_apply_async (settings, salut_account_created, NULL); g_free (nickname); g_free (first_name); g_free (last_name); g_free (email); g_free (jid); g_object_unref (settings); g_object_unref (contact); g_object_unref (book); out: g_object_unref (managers); }