diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2009-05-21 04:50:38 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@redhat.com> | 2009-05-21 04:50:38 +0800 |
commit | 23f58b3f17ce7ba08a8bd3f6066f62f0f454bacf (patch) | |
tree | 0db872538c32650de59a4a617582344d72b23d80 | |
parent | 292aea67a7f3f1d194ef60214d482881f54ab083 (diff) | |
parent | 43f43118634d29618cea74d8950346640142e883 (diff) | |
download | gsoc2013-evolution-23f58b3f17ce7ba08a8bd3f6066f62f0f454bacf.tar gsoc2013-evolution-23f58b3f17ce7ba08a8bd3f6066f62f0f454bacf.tar.gz gsoc2013-evolution-23f58b3f17ce7ba08a8bd3f6066f62f0f454bacf.tar.bz2 gsoc2013-evolution-23f58b3f17ce7ba08a8bd3f6066f62f0f454bacf.tar.lz gsoc2013-evolution-23f58b3f17ce7ba08a8bd3f6066f62f0f454bacf.tar.xz gsoc2013-evolution-23f58b3f17ce7ba08a8bd3f6066f62f0f454bacf.tar.zst gsoc2013-evolution-23f58b3f17ce7ba08a8bd3f6066f62f0f454bacf.zip |
Merge branch 'vcard-inline'
-rw-r--r-- | addressbook/gui/component/component-factory.c | 4 | ||||
-rw-r--r-- | addressbook/gui/widgets/Makefile.am | 2 | ||||
-rw-r--r-- | addressbook/gui/widgets/eab-vcard-control.c | 316 | ||||
-rw-r--r-- | addressbook/gui/widgets/eab-vcard-control.h | 28 | ||||
-rw-r--r-- | configure.in | 3 | ||||
-rw-r--r-- | mail/em-format-html-display.c | 208 | ||||
-rw-r--r-- | plugins/vcard-inline/Makefile.am | 20 | ||||
-rw-r--r-- | plugins/vcard-inline/org-gnome-vcard-inline.eplug.xml | 28 | ||||
-rw-r--r-- | plugins/vcard-inline/vcard-inline.c | 287 |
9 files changed, 343 insertions, 553 deletions
diff --git a/addressbook/gui/component/component-factory.c b/addressbook/gui/component/component-factory.c index feea79d88f..52bc377115 100644 --- a/addressbook/gui/component/component-factory.c +++ b/addressbook/gui/component/component-factory.c @@ -31,7 +31,6 @@ #include "addressbook-view.h" #include "autocompletion-config.h" #include "eab-popup-control.h" -#include "eab-vcard-control.h" #ifdef ENABLE_SMIME #include "smime/gui/certificate-manager.h" #endif @@ -40,7 +39,6 @@ #define FACTORY_ID "OAFIID:GNOME_Evolution_Addressbook_Factory:" BASE_VERSION -#define VCARD_CONTROL_ID "OAFIID:GNOME_Evolution_Addressbook_VCard_Control:" BASE_VERSION #define COMPONENT_ID "OAFIID:GNOME_Evolution_Addressbook_Component:" BASE_VERSION #define ADDRESS_POPUP_ID "OAFIID:GNOME_Evolution_Addressbook_AddressPopup:" BASE_VERSION #define COMPLETION_CONFIG_CONTROL_ID "OAFIID:GNOME_Evolution_Addressbook_Autocompletion_ConfigControl:" BASE_VERSION @@ -56,8 +54,6 @@ factory (BonoboGenericFactory *factory, { d(printf ("asked to activate component_id `%s'\n", component_id)); - if (strcmp (component_id, VCARD_CONTROL_ID) == 0) - return BONOBO_OBJECT (eab_vcard_control_new ()); if (strcmp (component_id, COMPONENT_ID) == 0) { BonoboObject *object = BONOBO_OBJECT (addressbook_component_peek ()); bonobo_object_ref (object); diff --git a/addressbook/gui/widgets/Makefile.am b/addressbook/gui/widgets/Makefile.am index c3a14d8aeb..ebdf49ef40 100644 --- a/addressbook/gui/widgets/Makefile.am +++ b/addressbook/gui/widgets/Makefile.am @@ -37,8 +37,6 @@ libeabwidgets_la_SOURCES = \ eab-popup.h \ eab-popup-control.c \ eab-popup-control.h \ - eab-vcard-control.c \ - eab-vcard-control.h \ e-minicard.c \ e-minicard.h \ e-minicard-label.c \ diff --git a/addressbook/gui/widgets/eab-vcard-control.c b/addressbook/gui/widgets/eab-vcard-control.c deleted file mode 100644 index 1e890167f6..0000000000 --- a/addressbook/gui/widgets/eab-vcard-control.c +++ /dev/null @@ -1,316 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * Chris Toshok <toshok@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#include <config.h> -#include <string.h> - -#include <gtk/gtk.h> -#include <bonobo/bonobo-generic-factory.h> -#include <bonobo/bonobo-persist.h> -#include <bonobo/bonobo-persist-stream.h> -#include <bonobo/bonobo-stream-client.h> -#include <e-util/e-util.h> - -#include <libebook/e-book.h> -#include <libebook/e-contact.h> -#include <addressbook/gui/component/addressbook.h> -#include <addressbook/gui/widgets/eab-contact-display.h> -#include <addressbook/util/eab-book-util.h> - -#include "eab-vcard-control.h" -#include "eab-contact-merging.h" - -typedef struct { - EABContactDisplay *display; - GList *card_list; - GtkWidget *label; - EABContactDisplayRenderMode render_mode; -} EABVCardControl; - -#define VCARD_CONTROL_ID "OAFIID:GNOME_Evolution_Addressbook_VCard_Control:" BASE_VERSION - -/* - * Bonobo::PersistStream - * - * These two functions implement the Bonobo::PersistStream load and - * save methods which allow data to be loaded into and out of the - * BonoboObject. - */ -static char * -stream_read (Bonobo_Stream stream) -{ - Bonobo_Stream_iobuf *buffer; - CORBA_Environment ev; - char *data = NULL; - gint length = 0; - - CORBA_exception_init (&ev); - do { -#define READ_CHUNK_SIZE 65536 - Bonobo_Stream_read (stream, READ_CHUNK_SIZE, - &buffer, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - CORBA_exception_free (&ev); - return NULL; - } - - if (buffer->_length <= 0) - break; - - data = g_realloc (data, length + buffer->_length + 1); - - memcpy (data + length, buffer->_buffer, buffer->_length); - - length += buffer->_length; - - CORBA_free (buffer); - } while (1); - - CORBA_free (buffer); - CORBA_exception_free (&ev); - - if (data) - data[length] = '\0'; - else - data = g_strdup(""); - - return data; -} /* stream_read */ - -/* - * This function implements the Bonobo::PersistStream:load method. - */ -static void -pstream_load (BonoboPersistStream *ps, const Bonobo_Stream stream, - Bonobo_Persist_ContentType type, void *data, - CORBA_Environment *ev) -{ - GList *list; - char *vcard; - EABVCardControl *vcard_control = data; - - 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; - } - - if ((vcard = stream_read (stream)) == NULL) { - CORBA_exception_set (ev, CORBA_USER_EXCEPTION, - ex_Bonobo_Persist_FileNotFound, NULL); - return; - } - - g_list_foreach ( - vcard_control->card_list, - (GFunc) g_object_unref, NULL); - g_list_free (vcard_control->card_list); - - list = eab_contact_list_from_string (vcard); - g_free(vcard); - vcard_control->card_list = list; - if (list) { - eab_contact_display_render (vcard_control->display, E_CONTACT (list->data), - vcard_control->render_mode); - } - if (list && list->next) { - char *message; - int length = g_list_length (list) - 1; - message = g_strdup_printf (ngettext("There is one other contact.", - "There are %d other contacts.", length), - length); - gtk_label_set_text (GTK_LABEL (vcard_control->label), message); - g_free (message); - gtk_widget_show (vcard_control->label); - } else { - gtk_widget_hide (vcard_control->label); - } -} /* pstream_load */ - -/* - * 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 Bonobo_Persist_ContentTypeList * -pstream_get_content_types (BonoboPersistStream *ps, void *closure, - CORBA_Environment *ev) -{ - return bonobo_persist_generate_content_types (2, "text/vCard", "text/x-vCard"); -} - -static void -book_open_cb (EBook *book, EBookStatus status, gpointer closure) -{ - GList *list = closure; - if (status == E_BOOK_ERROR_OK) { - GList *p; - for (p = list; p; p = p->next) { - /* XXX argh, more passing of NULL's for callbacks */ - eab_merging_book_add_contact (book, E_CONTACT (p->data), NULL, NULL); - } - } - if (book) - g_object_unref (book); - g_list_foreach (list, (GFunc) g_object_unref, NULL); - g_list_free (list); -} - -static void -save_in_addressbook(GtkWidget *button, gpointer data) -{ - EABVCardControl *vcard_control = data; - GList *list, *p; - - list = g_list_copy (vcard_control->card_list); - - for (p = list; p; p = p->next) - g_object_ref (p->data); - - addressbook_load_default_book (book_open_cb, list); -} - -static void -toggle_full_vcard(GtkWidget *button, gpointer data) -{ - EABVCardControl *vcard_control = data; - char *label; - - if (!vcard_control->card_list) - return; - - if (vcard_control->render_mode == EAB_CONTACT_DISPLAY_RENDER_NORMAL) { - vcard_control->render_mode = EAB_CONTACT_DISPLAY_RENDER_COMPACT; - label = _("Show Full vCard"); - } - else { - vcard_control->render_mode = EAB_CONTACT_DISPLAY_RENDER_NORMAL; - label = _("Show Compact vCard"); - } - - gtk_button_set_label (GTK_BUTTON (button), label); - eab_contact_display_render (vcard_control->display, E_CONTACT (vcard_control->card_list->data), - vcard_control->render_mode); -} - -static void -free_struct (gpointer data, GObject *where_object_was) -{ - EABVCardControl *vcard_control = data; - - g_list_foreach ( - vcard_control->card_list, - (GFunc) g_object_unref, NULL); - g_list_free (vcard_control->card_list); - g_free (vcard_control); -} - -BonoboControl * -eab_vcard_control_new (void) -{ - BonoboControl *control; - BonoboPersistStream *stream; - GtkWidget *display; - GtkWidget *button1, *button2; - GtkWidget *bbox; - GtkWidget *vbox; - - EABVCardControl *vcard_control = g_new (EABVCardControl, 1); - - vcard_control->card_list = NULL; - vcard_control->display = NULL; - vcard_control->label = NULL; - - vcard_control->render_mode = EAB_CONTACT_DISPLAY_RENDER_COMPACT; - - /* Create the control. */ - - display = eab_contact_display_new (); - vcard_control->display = EAB_CONTACT_DISPLAY (display); - - bbox = gtk_hbutton_box_new (); - gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_START); - gtk_box_set_spacing (GTK_BOX (bbox), 12); - - button1 = gtk_button_new_with_label(_("Show Full vCard")); - g_signal_connect (button1, "clicked", - G_CALLBACK (toggle_full_vcard), vcard_control); - gtk_box_pack_start (GTK_BOX (bbox), button1, FALSE, FALSE, 0); - - button2 = gtk_button_new_with_label(_("Save in address book")); - g_signal_connect (button2, "clicked", - G_CALLBACK (save_in_addressbook), vcard_control); - gtk_box_pack_start (GTK_BOX (bbox), button2, FALSE, FALSE, 0); - - /* This is intentionally not shown. */ - vcard_control->label = gtk_label_new (""); - - vbox = gtk_vbox_new (FALSE, 0); - gtk_box_pack_start (GTK_BOX (vbox), bbox, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (vbox), display, TRUE, TRUE, 0); - gtk_box_pack_start (GTK_BOX (vbox), vcard_control->label, TRUE, TRUE, 0); - gtk_widget_show_all (bbox); - gtk_widget_show (display); - gtk_widget_show (vbox); - - control = bonobo_control_new (vbox); - - g_object_weak_ref (G_OBJECT (control), free_struct, vcard_control); - - stream = bonobo_persist_stream_new (pstream_load, pstream_save, - pstream_get_content_types, - VCARD_CONTROL_ID, - vcard_control); - - if (stream == NULL) { - bonobo_object_unref (BONOBO_OBJECT (control)); - return NULL; - } - - bonobo_object_add_interface (BONOBO_OBJECT (control), - BONOBO_OBJECT (stream)); - - return control; -} diff --git a/addressbook/gui/widgets/eab-vcard-control.h b/addressbook/gui/widgets/eab-vcard-control.h deleted file mode 100644 index 06ca62727a..0000000000 --- a/addressbook/gui/widgets/eab-vcard-control.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef __EAB_VCARD_CONTROL_H__ -#define __EAB_VCARD_CONTROL_H__ - -#include <bonobo/bonobo-control.h> - -BonoboControl *eab_vcard_control_new (void); - -#endif /* __EAB_VCARD_CONTROL_H__ */ diff --git a/configure.in b/configure.in index 3793b086a6..45e54f854c 100644 --- a/configure.in +++ b/configure.in @@ -1785,7 +1785,7 @@ plugins_base_always="calendar-file calendar-http $CALENDAR_WEATHER itip-formatte plugins_base="$plugins_base_always $SA_JUNK_PLUGIN $BF_JUNK_PLUGIN $EXCHANGE_PLUGIN $MONO_PLUGIN " all_plugins_base="$plugins_base_always sa-junk-plugin bogo-junk-plugin exchange-operations mono" -plugins_standard_always="bbdb subject-thread save-calendar select-one-source copy-tool mail-to-task audio-inline mailing-list-actions default-mailer prefer-plain mail-notification attachment-reminder face backup-restore email-custom-header templates pst-import" +plugins_standard_always="bbdb subject-thread save-calendar select-one-source copy-tool mail-to-task audio-inline mailing-list-actions default-mailer prefer-plain mail-notification attachment-reminder face backup-restore email-custom-header templates pst-import vcard-inline" plugins_standard="$plugins_standard_always" all_plugins_standard="$plugins_standard" @@ -2120,6 +2120,7 @@ plugins/startup-wizard/Makefile plugins/subject-thread/Makefile plugins/templates/Makefile plugins/tnef-attachments/Makefile +plugins/vcard-inline/Makefile plugins/webdav-account-setup/Makefile smime/Makefile smime/lib/Makefile diff --git a/mail/em-format-html-display.c b/mail/em-format-html-display.c index 68a28ea7cd..aba9c64069 100644 --- a/mail/em-format-html-display.c +++ b/mail/em-format-html-display.c @@ -46,11 +46,6 @@ #include <glib/gi18n.h> -#include <bonobo/bonobo-control-frame.h> -#include <bonobo/bonobo-stream-memory.h> -#include <bonobo/bonobo-widget.h> -#include <bonobo-activation/bonobo-activation-mime.h> - #include <camel/camel-stream.h> #include <camel/camel-stream-filter.h> #include <camel/camel-stream-mem.h> @@ -174,8 +169,6 @@ static void efhd_format_optional(EMFormat *, CamelStream *, CamelMimePart *, Cam static void efhd_format_secure(EMFormat *emf, CamelStream *stream, CamelMimePart *part, CamelCipherValidity *valid); static void efhd_complete(EMFormat *); -static gboolean efhd_bonobo_object(EMFormatHTML *efh, GtkHTMLEmbedded *eb, EMFormatHTMLPObject *pobject); -static gboolean efhd_use_component(const char *mime_type); static void efhd_builtin_init(EMFormatHTMLDisplayClass *efhc); enum { @@ -187,8 +180,6 @@ enum { static guint efhd_signals[EFHD_LAST_SIGNAL] = { 0 }; -/* EMFormatHandler's for bonobo objects */ -static GHashTable *efhd_bonobo_handlers; static EMFormatHTMLClass *efhd_parent; static EMFormatClass *efhd_format_class; @@ -338,7 +329,7 @@ efhd_class_init(GObjectClass *klass) } GType -em_format_html_display_get_type(void) +em_format_html_display_get_type (void) { static GType type = 0; @@ -354,8 +345,6 @@ em_format_html_display_get_type(void) efhd_parent = g_type_class_ref(em_format_html_get_type()); efhd_format_class = g_type_class_ref(em_format_get_type()); type = g_type_register_static(em_format_html_get_type(), "EMFormatHTMLDisplay", &info, 0); - - efhd_bonobo_handlers = g_hash_table_new(g_str_hash, g_str_equal); } return type; @@ -1274,38 +1263,10 @@ efhd_builtin_init(EMFormatHTMLDisplayClass *efhc) em_format_class_add_handler((EMFormatClass *)efhc, &type_builtin_table[i]); } -/* ********************************************************************** */ -static void -efhd_bonobo_unknown(EMFormat *emf, CamelStream *stream, CamelMimePart *part, const EMFormatHandler *info) -{ - char *classid; - - classid = g_strdup_printf("bonobo-unknown:///em-format-html-display/%s", emf->part_id->str); - em_format_html_add_pobject((EMFormatHTML *)emf, sizeof(EMFormatHTMLPObject), classid, part, efhd_bonobo_object); - camel_stream_printf(stream, "<object classid=\"%s\" type=\"%s\"></object><br>\n", classid, info->mime_type); - g_free(classid); -} - - /* ********************************************************************** */ -static const EMFormatHandler *efhd_find_handler(EMFormat *emf, const char *mime_type) +static const EMFormatHandler * +efhd_find_handler(EMFormat *emf, const char *mime_type) { - const EMFormatHandler *handle; - - if ( (handle = ((EMFormatClass *)efhd_parent)->find_handler(emf, mime_type)) == NULL - && efhd_use_component(mime_type) - && (handle = g_hash_table_lookup(efhd_bonobo_handlers, mime_type)) == NULL) { - - EMFormatHandler *h = g_malloc0(sizeof(*h)); - - h->mime_type = g_strdup(mime_type); - h->handler = efhd_bonobo_unknown; - h->flags = EM_FORMAT_HANDLER_INLINE_DISPOSITION; - g_hash_table_insert(efhd_bonobo_handlers, h->mime_type, h); - - handle = h; - } - - return handle; + return ((EMFormatClass *) efhd_parent)->find_handler (emf, mime_type); } static void efhd_format_clone(EMFormat *emf, CamelFolder *folder, const char *uid, CamelMimeMessage *msg, EMFormat *src) @@ -1843,155 +1804,6 @@ efhd_attachment_frame(EMFormat *emf, CamelStream *stream, EMFormatPURI *puri) } } -static gboolean -efhd_bonobo_object(EMFormatHTML *efh, GtkHTMLEmbedded *eb, EMFormatHTMLPObject *pobject) -{ - CamelDataWrapper *wrapper; - Bonobo_ServerInfo *component; - GtkWidget *embedded; - Bonobo_PersistStream persist; - CORBA_Environment ev; - CamelStreamMem *cstream; - BonoboStream *bstream; - BonoboControlFrame *control_frame; - Bonobo_PropertyBag prop_bag; - - component = bonobo_activation_get_default_component_for_mime_type (eb->type); - if (component == NULL) - return FALSE; - - embedded = bonobo_widget_new_control(component->iid, NULL); - CORBA_free(component); - if (embedded == NULL) - return FALSE; - - CORBA_exception_init(&ev); - - control_frame = bonobo_widget_get_control_frame((BonoboWidget *)embedded); - prop_bag = bonobo_control_frame_get_control_property_bag(control_frame, NULL); - if (prop_bag != CORBA_OBJECT_NIL) { - /* - * Now we can take care of business. Currently, the only control - * that needs something passed to it through a property bag is - * the iTip control, and it needs only the From email address, - * but perhaps in the future we can generalize this section of code - * to pass a bunch of useful things to all embedded controls. - */ - const CamelInternetAddress *from; - char *from_address; - - from = camel_mime_message_get_from((CamelMimeMessage *)((EMFormat *)efh)->message); - from_address = camel_address_encode((CamelAddress *)from); - bonobo_property_bag_client_set_value_string(prop_bag, "from_address", from_address, &ev); - g_free(from_address); - - Bonobo_Unknown_unref(prop_bag, &ev); - } - - persist = (Bonobo_PersistStream)Bonobo_Unknown_queryInterface(bonobo_widget_get_objref((BonoboWidget *)embedded), - "IDL:Bonobo/PersistStream:1.0", &ev); - if (persist == CORBA_OBJECT_NIL) { - g_object_ref_sink(embedded); - CORBA_exception_free(&ev); - return FALSE; - } - - /* Write the data to a CamelStreamMem... */ - cstream = (CamelStreamMem *)camel_stream_mem_new(); - wrapper = camel_medium_get_content_object((CamelMedium *)pobject->part); - if (FALSE && !g_ascii_strncasecmp (eb->type, "text/", 5)) { - /* do charset conversion, etc */ - d(printf("performing charset conversion for %s component\n", eb->type)); - em_format_format_text((EMFormat *)efh, (CamelStream *)cstream, wrapper); - } else { - camel_data_wrapper_decode_to_stream (wrapper, (CamelStream *) cstream); - } - - /* ...convert the CamelStreamMem to a BonoboStreamMem... */ - bstream = bonobo_stream_mem_create((char *)cstream->buffer->data, cstream->buffer->len, TRUE, FALSE); - camel_object_unref(cstream); - - /* ...and hydrate the PersistStream from the BonoboStream. */ - Bonobo_PersistStream_load(persist, - bonobo_object_corba_objref(BONOBO_OBJECT (bstream)), - eb->type, &ev); - bonobo_object_unref(BONOBO_OBJECT (bstream)); - Bonobo_Unknown_unref(persist, &ev); - CORBA_Object_release(persist, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_object_ref_sink(embedded); - CORBA_exception_free(&ev); - return FALSE; - } - CORBA_exception_free(&ev); - - gtk_widget_show(embedded); - gtk_container_add(GTK_CONTAINER (eb), embedded); - - return TRUE; -} - -static gboolean -efhd_check_server_prop(Bonobo_ServerInfo *component, const char *propname, const char *value) -{ - CORBA_sequence_CORBA_string stringv; - Bonobo_ActivationProperty *prop; - int i; - - prop = bonobo_server_info_prop_find(component, propname); - if (!prop || prop->v._d != Bonobo_ACTIVATION_P_STRINGV) - return FALSE; - - stringv = prop->v._u.value_stringv; - for (i = 0; i < stringv._length; i++) { - if (!g_ascii_strcasecmp(value, stringv._buffer[i])) - return TRUE; - } - - return FALSE; -} - -static gboolean -efhd_use_component(const char *mime_type) -{ - GList *components, *iter; - Bonobo_ServerInfo *component = NULL; - - /* should this cache it? */ - - if (g_ascii_strcasecmp(mime_type, "text/x-vcard") != 0 - && g_ascii_strcasecmp(mime_type, "text/calendar") != 0) { - const char **mime_types; - int i; - - mime_types = mail_config_get_allowable_mime_types(); - for (i = 0; mime_types[i]; i++) { - if (!g_ascii_strcasecmp(mime_types[i], mime_type)) - goto type_ok; - } - return FALSE; - } -type_ok: - components = bonobo_activation_get_all_components_for_mime_type (mime_type); - for (iter = components; iter; iter = iter->next) { - Bonobo_ServerInfo *comp = iter->data; - - comp = iter->data; - if (efhd_check_server_prop(comp, "repo_ids", "IDL:Bonobo/PersistStream:1.0") - && efhd_check_server_prop(comp, "bonobo:supported_mime_types", mime_type)) { - component = comp; - break; - } - } - - /* FIXME: How should I free the Bonobo_ServerInfo's ? */ - g_list_foreach (components, (GFunc)CORBA_free, NULL); - g_list_free (components); - - return component != NULL; -} - static void efhd_bar_resize (EMFormatHTML *efh, GtkAllocation *event) @@ -2097,16 +1909,8 @@ efhd_format_attachment(EMFormat *emf, CamelStream *stream, CamelMimePart *part, stream, "</font></td></tr><tr></table>\n" EM_FORMAT_HTML_VPAD); - if (handle) { - if (info->shown) - handle->handler(emf, stream, part, handle); - } else if (efhd_use_component(mime_type)) { - g_free(classid); /* messy */ - - classid = g_strdup_printf("bonobo-unknown:///em-format-html-display/%s", emf->part_id->str); - em_format_html_add_pobject((EMFormatHTML *)emf, sizeof(EMFormatHTMLPObject), classid, part, efhd_bonobo_object); - camel_stream_printf(stream, "<object classid=\"%s\" type=\"%s\"></object><br>>\n", classid, mime_type); - } + if (handle && info->shown) + handle->handler(emf, stream, part, handle); g_free(classid); } diff --git a/plugins/vcard-inline/Makefile.am b/plugins/vcard-inline/Makefile.am new file mode 100644 index 0000000000..781eb53bd4 --- /dev/null +++ b/plugins/vcard-inline/Makefile.am @@ -0,0 +1,20 @@ +INCLUDES = \ + -I$(top_srcdir) \ + $(EVOLUTION_ADDRESSBOOK_CFLAGS) \ + $(EVOLUTION_MAIL_CFLAGS) + +@EVO_PLUGIN_RULE@ + +plugin_DATA = org-gnome-vcard-inline.eplug +plugin_LTLIBRARIES = liborg-gnome-vcard-inline.la + +liborg_gnome_vcard_inline_la_SOURCES = vcard-inline.c +liborg_gnome_vcard_inline_la_LDFLAGS = -module -avoid-version $(NO_UNDEFINED) +liborg_gnome_vcard_inline_la_LIBADD = \ + $(EVOLUTION_ADDRESSBOOK_LIBS) + $(EVOLUTION_MAIL_LIBS) + +EXTRA_DIST = org-gnome-vcard-inline.eplug.xml + +BUILT_SOURCES = $(plugin_DATA) +CLEANFILES = $(BUILT_SOURCES) diff --git a/plugins/vcard-inline/org-gnome-vcard-inline.eplug.xml b/plugins/vcard-inline/org-gnome-vcard-inline.eplug.xml new file mode 100644 index 0000000000..f9b2c1693e --- /dev/null +++ b/plugins/vcard-inline/org-gnome-vcard-inline.eplug.xml @@ -0,0 +1,28 @@ +<?xml version="1.0"?> +<e-plugin-list> + <e-plugin + type="shlib" + id="org.gnome.evolution.plugin.vcardInline" + location="@PLUGINDIR@/liborg-gnome-vcard-inline@SOEXT@" + _name="Inline vCards"> + + <author name="Matthew Barnes" email="mbarnes@redhat.com"/> + <_description> + Show vCards directly in mail messages. + </_description> + + <hook class="org.gnome.evolution.mail.format:1.0"> + <group id="EMFormatHTMLDisplay"> + <item + mime_type="text/vcard" + format="org_gnome_vcard_inline_format" + flags="inline_disposition"/> + <item + mime_type="text/x-vcard" + format="org_gnome_vcard_inline_format" + flags="inline_disposition"/> + </group> + </hook> + + </e-plugin> +</e-plugin-list> diff --git a/plugins/vcard-inline/vcard-inline.c b/plugins/vcard-inline/vcard-inline.c new file mode 100644 index 0000000000..e2b9e17272 --- /dev/null +++ b/plugins/vcard-inline/vcard-inline.c @@ -0,0 +1,287 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see <http://www.gnu.org/licenses/> + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <gtk/gtk.h> +#include <glib/gi18n-lib.h> +#include <libebook/e-book.h> +#include <libebook/e-contact.h> +#include <camel/camel-medium.h> +#include <camel/camel-mime-part.h> +#include <camel/camel-stream-mem.h> +#include <gtkhtml/gtkhtml-embedded.h> + +#include "addressbook/gui/component/addressbook.h" +#include "addressbook/gui/merging/eab-contact-merging.h" +#include "addressbook/gui/widgets/eab-contact-display.h" +#include "addressbook/util/eab-book-util.h" +#include "mail/em-format-hook.h" +#include "mail/em-format-html.h" + +#define d(x) + +typedef struct _VCardInlinePObject VCardInlinePObject; + +struct _VCardInlinePObject { + EMFormatHTMLPObject object; + + GList *contact_list; + GtkWidget *contact_display; + GtkWidget *message_label; + EABContactDisplayRenderMode mode; +}; + +static gint org_gnome_vcard_inline_classid; + +/* Forward Declarations */ +void org_gnome_vcard_inline_format (void *ep, EMFormatHookTarget *target); + +static void +org_gnome_vcard_inline_pobject_free (EMFormatHTMLPObject *object) +{ + VCardInlinePObject *vcard_object; + + vcard_object = (VCardInlinePObject *) object; + + g_list_foreach ( + vcard_object->contact_list, + (GFunc) g_object_unref, NULL); + g_list_free (vcard_object->contact_list); + vcard_object->contact_list = NULL; + + if (vcard_object->contact_display != NULL) { + g_object_unref (vcard_object->contact_display); + vcard_object->contact_display = NULL; + } + + if (vcard_object->message_label != NULL) { + g_object_unref (vcard_object->message_label); + vcard_object->message_label = NULL; + } +} + +static void +org_gnome_vcard_inline_decode (VCardInlinePObject *vcard_object, + CamelMimePart *mime_part) +{ + CamelDataWrapper *data_wrapper; + CamelMedium *medium; + CamelStream *stream; + GList *contact_list; + GByteArray *array; + const gchar *string; + + array = g_byte_array_new (); + medium = CAMEL_MEDIUM (mime_part); + + /* Stream takes ownership of the byte array. */ + stream = camel_stream_mem_new_with_byte_array (array); + data_wrapper = camel_medium_get_content_object (medium); + camel_data_wrapper_decode_to_stream (data_wrapper, stream); + + string = (gchar *) array->data; + contact_list = eab_contact_list_from_string (string); + vcard_object->contact_list = contact_list; + + camel_object_unref (data_wrapper); + camel_object_unref (stream); +} + +static void +org_gnome_vcard_inline_book_open_cb (EBook *book, + EBookStatus status, + gpointer user_data) +{ + GList *contact_list = user_data; + GList *iter; + + if (status != E_BOOK_ERROR_OK) + goto exit; + + for (iter = contact_list; iter != NULL; iter = iter->next) + eab_merging_book_add_contact ( + book, E_CONTACT (iter->data), NULL, NULL); + +exit: + if (book != NULL) + g_object_unref (book); + + g_list_foreach (contact_list, (GFunc) g_object_unref, NULL); + g_list_free (contact_list); +} + +static void +org_gnome_vcard_inline_save_cb (VCardInlinePObject *vcard_object) +{ + GList *contact_list; + + contact_list = g_list_copy (vcard_object->contact_list); + g_list_foreach (contact_list, (GFunc) g_object_ref, NULL); + + addressbook_load_default_book ( + org_gnome_vcard_inline_book_open_cb, contact_list); +} + +static void +org_gnome_vcard_inline_toggle_cb (VCardInlinePObject *vcard_object, + GtkButton *button) +{ + EABContactDisplay *contact_display; + const gchar *label; + + contact_display = EAB_CONTACT_DISPLAY (vcard_object->contact_display); + + /* Toggle between "full" and "compact" modes. */ + if (vcard_object->mode == EAB_CONTACT_DISPLAY_RENDER_NORMAL) { + vcard_object->mode = EAB_CONTACT_DISPLAY_RENDER_COMPACT; + label = _("Show Full vCard"); + } else { + vcard_object->mode = EAB_CONTACT_DISPLAY_RENDER_NORMAL; + label = _("Show Compact vCard"); + } + + gtk_button_set_label (button, label); + + eab_contact_display_render ( + EAB_CONTACT_DISPLAY (vcard_object->contact_display), + E_CONTACT (vcard_object->contact_list->data), + vcard_object->mode); +} + +static gboolean +org_gnome_vcard_inline_embed (EMFormatHTML *format, + GtkHTMLEmbedded *embedded, + EMFormatHTMLPObject *object) +{ + VCardInlinePObject *vcard_object; + GtkWidget *button_box; + GtkWidget *container; + GtkWidget *widget; + guint length; + + vcard_object = (VCardInlinePObject *) object; + length = g_list_length (vcard_object->contact_list); + g_return_val_if_fail (length > 0, FALSE); + + container = GTK_WIDGET (embedded); + + widget = gtk_vbox_new (FALSE, 0); + gtk_container_add (GTK_CONTAINER (container), widget); + gtk_widget_show (widget); + + container = widget; + + widget = gtk_hbutton_box_new (); + gtk_button_box_set_layout ( + GTK_BUTTON_BOX (widget), GTK_BUTTONBOX_START); + gtk_box_set_spacing (GTK_BOX (widget), 12); + gtk_box_pack_start (GTK_BOX (container), widget, FALSE, TRUE, 0); + gtk_widget_show (widget); + + button_box = widget; + + widget = eab_contact_display_new (); + gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0); + vcard_object->contact_display = g_object_ref (widget); + gtk_widget_show (widget); + + eab_contact_display_render ( + EAB_CONTACT_DISPLAY (vcard_object->contact_display), + E_CONTACT (vcard_object->contact_list->data), + vcard_object->mode); + + widget = gtk_label_new (NULL); + gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0); + vcard_object->message_label = g_object_ref (widget); + + if (length == 2) { + const gchar *text; + + text = _("There is one other contact."); + gtk_label_set_text (GTK_LABEL (widget), text); + gtk_widget_show (widget); + + } else if (length > 2) { + gchar *text; + + /* Translators: This will always be two or more. */ + text = g_strdup_printf (ngettext ( + "There is %d other contact.", + "There are %d other contacts.", + length - 1), length - 1); + gtk_label_set_text (GTK_LABEL (widget), text); + gtk_widget_show (widget); + g_free (text); + + } else + gtk_widget_hide (widget); + + container = button_box; + + widget = gtk_button_new_with_label (_("Show Full vCard")); + gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0); + gtk_widget_show (widget); + + g_signal_connect_swapped ( + widget, "clicked", + G_CALLBACK (org_gnome_vcard_inline_toggle_cb), + vcard_object); + + widget = gtk_button_new_with_label (_("Save in Address Book")); + gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0); + gtk_widget_show (widget); + + g_signal_connect_swapped ( + widget, "clicked", + G_CALLBACK (org_gnome_vcard_inline_save_cb), + vcard_object); + + return TRUE; +} + +void +org_gnome_vcard_inline_format (void *ep, EMFormatHookTarget *target) +{ + VCardInlinePObject *vcard_object; + gchar *classid; + + classid = g_strdup_printf ( + "org-gnome-vcard-inline-display-%d", + org_gnome_vcard_inline_classid++); + + vcard_object = (VCardInlinePObject *) + em_format_html_add_pobject ( + EM_FORMAT_HTML (target->format), + sizeof (VCardInlinePObject), + classid, target->part, + org_gnome_vcard_inline_embed); + + camel_object_ref (target->part); + + vcard_object->mode = EAB_CONTACT_DISPLAY_RENDER_COMPACT; + vcard_object->object.free = org_gnome_vcard_inline_pobject_free; + org_gnome_vcard_inline_decode (vcard_object, target->part); + + camel_stream_printf ( + target->stream, "<object classid=%s></object>", classid); + + g_free (classid); +} |