balsa r8069 - in trunk: . libbalsa src



Author: pawels
Date: Sun Feb  8 14:06:16 2009
New Revision: 8069
URL: http://svn.gnome.org/viewvc/balsa?rev=8069&view=rev

Log:
* libbalsa/rfc2445.[hc]: Implement VCALENDAR and VEVENT objects.
* src/balsa-mime-widget-vcalendar.[hc]:
  display vevent's, and the stuff for sending a text/calendar reply;
* src/balsa-mime-widget.c: call functions to display text/calendar
* src/balsa-print-object-text.[hc]:  support print these parts
* src/balsa-print-object.c:: call functions to print text/calendar
* src/balsa-message.c: make text/calendar the preferred part.
* src/balsa-print-object-default.c: catch missing pixbuf
* src/Makefile.am, libbalsa/Makefile.am: add new source files


Modified:
   trunk/ChangeLog
   trunk/libbalsa/Makefile.am
   trunk/src/Makefile.am
   trunk/src/balsa-message.c
   trunk/src/balsa-mime-widget.c
   trunk/src/balsa-print-object-default.c
   trunk/src/balsa-print-object-text.c
   trunk/src/balsa-print-object-text.h
   trunk/src/balsa-print-object.c

Modified: trunk/libbalsa/Makefile.am
==============================================================================
--- trunk/libbalsa/Makefile.am	(original)
+++ trunk/libbalsa/Makefile.am	Sun Feb  8 14:06:16 2009
@@ -124,6 +124,8 @@
 	mime-stream-shared.h    \
 	misc.c			\
 	misc.h			\
+	rfc2445.c		\
+	rfc2445.h		\
 	rfc3156.c		\
 	rfc3156.h		\
 	send.c			\

Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am	(original)
+++ trunk/src/Makefile.am	Sun Feb  8 14:06:16 2009
@@ -31,6 +31,8 @@
 	balsa-mime-widget-multipart.h	\
 	balsa-mime-widget-text.c	\
 	balsa-mime-widget-text.h	\
+	balsa-mime-widget-vcalendar.c	\
+	balsa-mime-widget-vcalendar.h	\
 	balsa-cite-bar.c	\
 	balsa-cite-bar.h	\
 	filter-edit-callbacks.c	\

Modified: trunk/src/balsa-message.c
==============================================================================
--- trunk/src/balsa-message.c	(original)
+++ trunk/src/balsa-message.c	Sun Feb  8 14:06:16 2009
@@ -1974,7 +1974,8 @@
 
         content_type = libbalsa_message_body_get_mime_type(body);
 
-        if (g_ascii_strcasecmp(content_type, "text/plain") == 0)
+        if (g_ascii_strcasecmp(content_type, "text/plain") == 0 ||
+            g_ascii_strcasecmp(content_type, "text/calendar") == 0)
             preferred = body;
 #ifdef HAVE_GTKHTML
         else if (libbalsa_can_display(body))

Modified: trunk/src/balsa-mime-widget.c
==============================================================================
--- trunk/src/balsa-mime-widget.c	(original)
+++ trunk/src/balsa-mime-widget.c	Sun Feb  8 14:06:16 2009
@@ -30,6 +30,7 @@
 #include "balsa-mime-widget-message.h"
 #include "balsa-mime-widget-multipart.h"
 #include "balsa-mime-widget-text.h"
+#include "balsa-mime-widget-vcalendar.h"
 #include "balsa-mime-widget-callbacks.h"
 #include "balsa-mime-widget-crypto.h"
 #include "balsa-mime-widget.h"
@@ -111,8 +112,9 @@
 } mime_delegate_t;
 
 static mime_delegate_t mime_delegate[] =
-    { {FALSE,  "message/delivery-status",      balsa_mime_widget_new_text},
+    { {FALSE, "message/delivery-status",       balsa_mime_widget_new_text},
       {TRUE,  "message/",                      balsa_mime_widget_new_message},
+      {FALSE, "text/calendar",                 balsa_mime_widget_new_vcalendar},
       {TRUE,  "text/",                         balsa_mime_widget_new_text},
       {TRUE,  "multipart/",                    balsa_mime_widget_new_multipart},
       {TRUE,  "image/",                        balsa_mime_widget_new_image},

Modified: trunk/src/balsa-print-object-default.c
==============================================================================
--- trunk/src/balsa-print-object-default.c	(original)
+++ trunk/src/balsa-print-object-default.c	Sun Feb  8 14:06:16 2009
@@ -223,9 +223,10 @@
     c_offset = pod->c_image_width + 4 * C_LABEL_SEP;
 
     /* print the icon */
-    cairo_print_pixbuf(cairo_ctx, pod->pixbuf, self->c_at_x,
-		       self->c_at_y + (c_max_height -
-				       pod->c_image_height) * 0.5, 1.0);
+    if (pod->pixbuf)
+        cairo_print_pixbuf(cairo_ctx, pod->pixbuf, self->c_at_x,
+                           self->c_at_y + (c_max_height -
+                                           pod->c_image_height) * 0.5, 1.0);
 
     /* print the description */
     font = pango_font_description_from_string(balsa_app.print_header_font);

Modified: trunk/src/balsa-print-object-text.c
==============================================================================
--- trunk/src/balsa-print-object-text.c	(original)
+++ trunk/src/balsa-print-object-text.c	Sun Feb  8 14:06:16 2009
@@ -23,6 +23,8 @@
 #include <string.h>
 #include "config.h"
 #include <glib/gi18n.h>
+#include "libbalsa.h"
+#include "rfc2445.h"
 #include "balsa-icons.h"
 #include "balsa-print-object.h"
 #include "balsa-print-object-decor.h"
@@ -553,6 +555,179 @@
 }
 
 
+/* add a text/calendar object */
+
+#define ADD_VCAL_FIELD(buf, labwidth, layout, field, descr)		\
+    do {								\
+	if (field) {							\
+	    gint label_width = p_string_width_from_layout(layout, descr); \
+	    if (label_width > labwidth)					\
+		labwidth = label_width;					\
+	    if ((buf)->len > 0)						\
+		g_string_append_c(buf, '\n');				\
+	    g_string_append_printf(buf, "%s\t%s", descr, field);	\
+	}								\
+    } while(0)
+
+#define ADD_VCAL_DATE(buf, labwidth, layout, date, descr)               \
+    do {                                                                \
+        if (date != (time_t) -1) {                                      \
+            gchar * _dstr =                                             \
+                libbalsa_date_to_utf8(&date, balsa_app.date_string);    \
+            ADD_VCAL_FIELD(buf, labwidth, layout, _dstr, descr);        \
+            g_free(_dstr);                                              \
+        }                                                               \
+    } while (0)
+
+#define ADD_VCAL_ADDRESS(buf, labwidth, layout, addr, descr)            \
+    do {                                                                \
+        if (addr) {                                                     \
+            gchar * _astr = libbalsa_vcal_attendee_to_str(addr);        \
+            ADD_VCAL_FIELD(buf, labwidth, layout, _astr, descr);        \
+            g_free(_astr);                                              \
+        }                                                               \
+    } while (0)
+
+
+GList *
+balsa_print_object_text_calendar(GList * list,
+                                 GtkPrintContext * context,
+                                 LibBalsaMessageBody * body,
+                                 BalsaPrintSetup * psetup)
+{
+    BalsaPrintObjectDefault *pod;
+    BalsaPrintObject *po;
+    PangoFontDescription *header_font;
+    PangoLayout *test_layout;
+    PangoTabArray *tabs;
+    GString *desc_buf;
+    gdouble c_max_height;
+    LibBalsaVCal * vcal_obj = NULL;
+    GList * this_ev;
+
+    /* check if we can evaluate the body a calendar object and fall back
+     * to text if not */
+    if (!(vcal_obj = libbalsa_vcal_new_from_body(body)))
+	return balsa_print_object_text(list, context, body, psetup);
+
+    /* proceed with the address information */
+    pod = g_object_new(BALSA_TYPE_PRINT_OBJECT_DEFAULT, NULL);
+    g_assert(pod != NULL);
+    po = BALSA_PRINT_OBJECT(pod);
+
+    /* create the part */
+    po->depth = psetup->curr_depth;
+    po->c_width =
+	psetup->c_width - 2 * psetup->curr_depth * C_LABEL_SEP;
+
+    /* get the stock calendar icon or the mime type icon on fail */
+    pod->pixbuf =
+	gtk_icon_theme_load_icon(gtk_icon_theme_get_default(),
+				 "stock_calendar", 48,
+				 GTK_ICON_LOOKUP_USE_BUILTIN, NULL);
+    if (!pod->pixbuf) {
+	gchar *conttype = libbalsa_message_body_get_mime_type(body);
+	
+	pod->pixbuf = libbalsa_icon_finder(conttype, NULL, NULL, GTK_ICON_SIZE_DND);
+    }
+    pod->c_image_width = gdk_pixbuf_get_width(pod->pixbuf);
+    pod->c_image_height = gdk_pixbuf_get_height(pod->pixbuf);
+
+
+    /* create a layout for calculating the maximum label width */
+    header_font =
+	pango_font_description_from_string(balsa_app.print_header_font);
+    test_layout = gtk_print_context_create_pango_layout(context);
+    pango_layout_set_font_description(test_layout, header_font);
+    pango_font_description_free(header_font);
+
+    /* add fields from the events*/
+    desc_buf = g_string_new("");
+    pod->p_label_width = 0;
+    for (this_ev = vcal_obj->vevent; this_ev; this_ev = g_list_next(this_ev)) {
+        LibBalsaVEvent * event = (LibBalsaVEvent *) this_ev->data;
+
+        if (desc_buf->len > 0)
+            g_string_append_c(desc_buf, '\n');
+        ADD_VCAL_FIELD(desc_buf, pod->p_label_width, test_layout,
+                       event->summary, _("Summary"));
+        ADD_VCAL_ADDRESS(desc_buf, pod->p_label_width, test_layout,
+                         event->organizer, _("Organizer"));
+        ADD_VCAL_DATE(desc_buf, pod->p_label_width, test_layout,
+                      event->start, _("Start"));
+        ADD_VCAL_DATE(desc_buf, pod->p_label_width, test_layout,
+                      event->end, _("End"));
+        ADD_VCAL_FIELD(desc_buf, pod->p_label_width, test_layout,
+                       event->location, _("Location"));
+        if (event->attendee) {
+            GList * att = event->attendee;
+            gchar * this_att;
+
+            this_att =
+                libbalsa_vcal_attendee_to_str(LIBBALSA_ADDRESS(att->data));
+            att = g_list_next(att);
+            ADD_VCAL_FIELD(desc_buf, pod->p_label_width, test_layout,
+                           this_att, att ? _("Attendees") : _("Attendee"));
+            g_free(this_att);
+            for (; att; att = g_list_next(att)) {
+                this_att =
+                    libbalsa_vcal_attendee_to_str(LIBBALSA_ADDRESS(att->data));
+                g_string_append_printf(desc_buf, "\n\t%s", this_att);
+                g_free(this_att);
+            }
+        }
+        if (event->description) {
+            gchar ** desc_lines = g_strsplit(event->description, "\n", -1);
+            gint i;
+
+            ADD_VCAL_FIELD(desc_buf, pod->p_label_width, test_layout,
+                           desc_lines[0], _("Description"));
+            for (i = 1; desc_lines[i]; i++)
+                g_string_append_printf(desc_buf, "\n\t%s", desc_lines[i]);
+            g_strfreev(desc_lines);
+        }
+    }
+    g_object_unref(vcal_obj);
+
+    /* add a small space between label and value */
+    pod->p_label_width += C_TO_P(C_LABEL_SEP);
+
+    /* configure the layout so we can calculate the text height */
+    pango_layout_set_indent(test_layout, -pod->p_label_width);
+    tabs =
+	pango_tab_array_new_with_positions(1, FALSE, PANGO_TAB_LEFT,
+					   pod->p_label_width);
+    pango_layout_set_tabs(test_layout, tabs);
+    pango_tab_array_free(tabs);
+    pango_layout_set_width(test_layout,
+			   C_TO_P(po->c_width -
+				  4 * C_LABEL_SEP - pod->c_image_width));
+    pango_layout_set_alignment(test_layout, PANGO_ALIGN_LEFT);
+    pod->c_text_height =
+	P_TO_C(p_string_height_from_layout(test_layout, desc_buf->str));
+    pod->description = g_string_free(desc_buf, FALSE);
+
+    /* check if we should move to the next page */
+    c_max_height = MAX(pod->c_text_height, pod->c_image_height);
+    if (psetup->c_y_pos + c_max_height > psetup->c_height) {
+	psetup->c_y_pos = 0;
+	psetup->page_count++;
+    }
+
+    /* remember the extent */
+    po->on_page = psetup->page_count - 1;
+    po->c_at_x = psetup->c_x0 + po->depth * C_LABEL_SEP;
+    po->c_at_y = psetup->c_y0 + psetup->c_y_pos;
+    po->c_width = psetup->c_width - 2 * po->depth * C_LABEL_SEP;
+    po->c_height = c_max_height;
+
+    /* adjust the y position */
+    psetup->c_y_pos += c_max_height;
+
+    return g_list_append(list, po);
+}
+
+
 static void
 balsa_print_object_text_draw(BalsaPrintObject * self,
 			     GtkPrintContext * context,

Modified: trunk/src/balsa-print-object-text.h
==============================================================================
--- trunk/src/balsa-print-object-text.h	(original)
+++ trunk/src/balsa-print-object-text.h	Sun Feb  8 14:06:16 2009
@@ -68,6 +68,10 @@
 				     GtkPrintContext * context,
 				     LibBalsaMessageBody * body,
 				     BalsaPrintSetup * psetup);
+GList *balsa_print_object_text_calendar(GList *list,
+                                        GtkPrintContext * context,
+                                        LibBalsaMessageBody * body,
+                                        BalsaPrintSetup * psetup);
 
 
 G_END_DECLS

Modified: trunk/src/balsa-print-object.c
==============================================================================
--- trunk/src/balsa-print-object.c	(original)
+++ trunk/src/balsa-print-object.c	Sun Feb  8 14:06:16 2009
@@ -117,6 +117,9 @@
         !g_ascii_strcasecmp("text/directory", conttype))
 	return balsa_print_object_text_vcard(list, context, mime_body, psetup);
 
+    if (!g_ascii_strcasecmp("text/calendar", conttype))
+	return balsa_print_object_text_calendar(list, context, mime_body, psetup);
+
     if (!g_ascii_strcasecmp("text/plain", conttype))
 	return balsa_print_object_text_plain(list, context, mime_body, psetup);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]