gchar * eab_book_and_contact_list_to_string (EBookClient *book_client, const GSList *contacts) { gchar *s0, *s1; s0 = eab_contact_list_to_string (contacts); if (!s0) s0 = g_strdup (""); if (book_client != NULL) { EClient *client; ESource *source; const gchar *uid; client = E_CLIENT (book_client); source = e_client_get_source (client); uid = e_source_get_uid (source); s1 = g_strconcat ("Book: ", uid, "\r\n", s0, NULL); } else s1 = g_strdup (s0); g_free (s0); return s1; }
static void e_minicard_view_drag_data_get (GtkWidget *widget, GdkDragContext *context, GtkSelectionData *selection_data, guint info, guint time, EMinicardView *view) { GdkAtom target; if (!E_IS_MINICARD_VIEW (view)) return; target = gtk_selection_data_get_target (selection_data); switch (info) { case DND_TARGET_TYPE_VCARD_LIST: { gchar *value; value = eab_contact_list_to_string (view->drag_list); gtk_selection_data_set ( selection_data, target, 8, (guchar *) value, strlen (value)); g_free (value); break; } case DND_TARGET_TYPE_SOURCE_VCARD_LIST: { EBookClient *book_client = NULL; gchar *value; g_object_get (view->adapter, "client", &book_client, NULL); value = eab_book_and_contact_list_to_string (book_client, view->drag_list); gtk_selection_data_set ( selection_data, target, 8, (guchar *) value, strlen (value)); g_object_unref (book_client); g_free (value); break; } } }
/* * This function implements the Bonobo::PersistStream:save method. */ static void pstream_save (BonoboPersistStream *ps, const Bonobo_Stream stream, Bonobo_Persist_ContentType type, void *data, CORBA_Environment *ev) { EABVCardControl *vcard_control = data; char *vcard; int length; if (type && g_ascii_strcasecmp (type, "text/vCard") != 0 && g_ascii_strcasecmp (type, "text/x-vCard") != 0) { CORBA_exception_set (ev, CORBA_USER_EXCEPTION, ex_Bonobo_Persist_WrongDataType, NULL); return; } vcard = eab_contact_list_to_string (vcard_control->card_list); length = strlen (vcard); bonobo_stream_client_write (stream, vcard, length, ev); g_free (vcard); } /* pstream_save */
static void eab_composer_created_cb (GObject *source_object, GAsyncResult *result, gpointer user_data) { CreateComposerData *ccd = user_data; EComposerHeaderTable *table; EMsgComposer *composer; GError *error = NULL; g_return_if_fail (ccd != NULL); composer = e_msg_composer_new_finish (result, &error); if (error) { g_warning ("%s: Failed to create msg composer: %s", G_STRFUNC, error->message); g_clear_error (&error); } else { table = e_msg_composer_get_header_table (composer); if (ccd->to_destinations) e_composer_header_table_set_destinations_to (table, ccd->to_destinations); if (ccd->bcc_destinations) e_composer_header_table_set_destinations_bcc (table, ccd->bcc_destinations); if (ccd->attachment_destinations) { CamelMimePart *attachment; GSList *contacts, *iter; gchar *data; attachment = camel_mime_part_new (); contacts = g_slist_copy (ccd->attachment_destinations); for (iter = contacts; iter != NULL; iter = iter->next) iter->data = e_destination_get_contact (iter->data); data = eab_contact_list_to_string (contacts); g_slist_free (contacts); camel_mime_part_set_content (attachment, data, strlen (data), "text/x-vcard"); if (ccd->attachment_destinations->next != NULL) { camel_mime_part_set_description (attachment, _("Multiple vCards")); } else { EContact *contact; const gchar *file_as; gchar *description; contact = e_destination_get_contact (ccd->attachment_destinations->data); file_as = e_contact_get_const (contact, E_CONTACT_FILE_AS); description = g_strdup_printf (_("vCard for %s"), file_as); camel_mime_part_set_description (attachment, description); g_free (description); } camel_mime_part_set_disposition (attachment, "attachment"); e_msg_composer_attach (composer, attachment); g_object_unref (attachment); if (ccd->attachment_destinations->next != NULL) { e_composer_header_table_set_subject (table, _("Contact information")); } else { EContact *contact; gchar *tempstr; const gchar *tempstr2; gchar *tempfree = NULL; contact = e_destination_get_contact (ccd->attachment_destinations->data); tempstr2 = e_contact_get_const (contact, E_CONTACT_FILE_AS); if (!tempstr2 || !*tempstr2) tempstr2 = e_contact_get_const (contact, E_CONTACT_FULL_NAME); if (!tempstr2 || !*tempstr2) tempstr2 = e_contact_get_const (contact, E_CONTACT_ORG); if (!tempstr2 || !*tempstr2) { g_free (tempfree); tempstr2 = get_email (contact, E_CONTACT_EMAIL_1, &tempfree); } if (!tempstr2 || !*tempstr2) { g_free (tempfree); tempstr2 = get_email (contact, E_CONTACT_EMAIL_2, &tempfree); } if (!tempstr2 || !*tempstr2) { g_free (tempfree); tempstr2 = get_email (contact, E_CONTACT_EMAIL_3, &tempfree); } if (!tempstr2 || !*tempstr2) tempstr = g_strdup_printf (_("Contact information")); else tempstr = g_strdup_printf (_("Contact information for %s"), tempstr2); e_composer_header_table_set_subject (table, tempstr); g_free (tempstr); g_free (tempfree); } } gtk_widget_show (GTK_WIDGET (composer)); } if (ccd->to_destinations) e_destination_freev (ccd->to_destinations); if (ccd->bcc_destinations) e_destination_freev (ccd->bcc_destinations); g_slist_free_full (ccd->attachment_destinations, g_object_unref); g_free (ccd); }
static void action_contact_save_as_cb (GtkAction *action, EBookShellView *book_shell_view) { EShell *shell; EShellView *shell_view; EShellWindow *shell_window; EShellBackend *shell_backend; EBookShellContent *book_shell_content; EAddressbookView *view; EActivity *activity; GSList *list; 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); list = e_addressbook_view_get_selected (view); 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); }
void eab_send_as_attachment (EShell *shell, GSList *destinations) { EMsgComposer *composer; EComposerHeaderTable *table; CamelMimePart *attachment; GSList *contacts, *iter; gchar *data; g_return_if_fail (E_IS_SHELL (shell)); if (destinations == NULL) return; composer = e_msg_composer_new (shell); table = e_msg_composer_get_header_table (composer); attachment = camel_mime_part_new (); contacts = g_slist_copy (destinations); for (iter = contacts; iter != NULL; iter = iter->next) iter->data = e_destination_get_contact (iter->data); data = eab_contact_list_to_string (contacts); g_slist_free (contacts); camel_mime_part_set_content ( attachment, data, strlen (data), "text/x-vcard"); if (destinations->next != NULL) camel_mime_part_set_description ( attachment, _("Multiple vCards")); else { EContact *contact; const gchar *file_as; gchar *description; contact = e_destination_get_contact (destinations->data); file_as = e_contact_get_const (contact, E_CONTACT_FILE_AS); description = g_strdup_printf (_("vCard for %s"), file_as); camel_mime_part_set_description (attachment, description); g_free (description); } camel_mime_part_set_disposition (attachment, "attachment"); e_msg_composer_attach (composer, attachment); g_object_unref (attachment); if (destinations->next != NULL) e_composer_header_table_set_subject ( table, _("Contact information")); else { EContact *contact; gchar *tempstr; const gchar *tempstr2; gchar *tempfree = NULL; contact = e_destination_get_contact (destinations->data); tempstr2 = e_contact_get_const (contact, E_CONTACT_FILE_AS); if (!tempstr2 || !*tempstr2) tempstr2 = e_contact_get_const (contact, E_CONTACT_FULL_NAME); if (!tempstr2 || !*tempstr2) tempstr2 = e_contact_get_const (contact, E_CONTACT_ORG); if (!tempstr2 || !*tempstr2) { g_free (tempfree); tempstr2 = get_email (contact, E_CONTACT_EMAIL_1, &tempfree); } if (!tempstr2 || !*tempstr2) { g_free (tempfree); tempstr2 = get_email (contact, E_CONTACT_EMAIL_2, &tempfree); } if (!tempstr2 || !*tempstr2) { g_free (tempfree); tempstr2 = get_email (contact, E_CONTACT_EMAIL_3, &tempfree); } if (!tempstr2 || !*tempstr2) tempstr = g_strdup_printf (_("Contact information")); else tempstr = g_strdup_printf (_("Contact information for %s"), tempstr2); e_composer_header_table_set_subject (table, tempstr); g_free (tempstr); g_free (tempfree); } gtk_widget_show (GTK_WIDGET (composer)); }