diff options
-rw-r--r-- | calendar/ChangeLog | 10 | ||||
-rw-r--r-- | calendar/gui/Makefile.am | 3 | ||||
-rw-r--r-- | calendar/gui/e-cal-component-preview.c | 448 | ||||
-rw-r--r-- | calendar/gui/e-cal-component-preview.h | 65 | ||||
-rw-r--r-- | calendar/gui/e-tasks.c | 330 |
5 files changed, 567 insertions, 289 deletions
diff --git a/calendar/ChangeLog b/calendar/ChangeLog index b810a3f356..585a27cd01 100644 --- a/calendar/ChangeLog +++ b/calendar/ChangeLog @@ -1,3 +1,13 @@ +2004-04-18 JP Rosevear <jpr@ximian.com> + + Fixes #53124 + + * gui/e-tasks.c: remove preview pieces, they are in their own + class now; use the new class for preview + + * gui/e-cal-component-preview.[hc]: implement a preview area for + tasks and events + 2004-04-17 Trent Lloyd <lathiat@sixlabs.org> * gui/e-calendar-view.c: include libecal/e-cal-component.h to kill diff --git a/calendar/gui/Makefile.am b/calendar/gui/Makefile.am index 18a66c7716..15245c6813 100644 --- a/calendar/gui/Makefile.am +++ b/calendar/gui/Makefile.am @@ -113,6 +113,9 @@ libevolution_calendar_la_SOURCES = \ control-factory.h \ e-alarm-list.c \ e-alarm-list.h \ + e-cal-component-preview.c \ + e-cal-component-preview.h \ + e-cal-model-calendar.h \ e-cal-model-calendar.c \ e-cal-model-calendar.h \ e-cal-model-tasks.c \ diff --git a/calendar/gui/e-cal-component-preview.c b/calendar/gui/e-cal-component-preview.c new file mode 100644 index 0000000000..91c48e1165 --- /dev/null +++ b/calendar/gui/e-cal-component-preview.c @@ -0,0 +1,448 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* e-tasks.c + * + * Copyright (C) 2001-2003 Ximian, Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * 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 + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + * Authors: Federico Mena Quintero <federico@ximian.com> + * Damon Chaplin <damon@ximian.com> + * Rodrigo Moya <rodrigo@ximian.com> + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <gnome.h> +#include <gtk/gtk.h> +#include <libgnomevfs/gnome-vfs-ops.h> +#include <libecal/e-cal-time-util.h> +#include <gal/util/e-util.h> +#include <gtkhtml/gtkhtml.h> +#include <gtkhtml/gtkhtml-stream.h> +#include <e-util/e-time-utils.h> +#include <e-util/e-categories-config.h> +#include "calendar-config.h" +#include "e-cal-component-preview.h" + +struct _ECalComponentPreviewPrivate { + GtkWidget *html; + + icaltimezone *zone; +}; + +static GtkTableClass *parent_class; + + +static void +on_link_clicked (GtkHTML *html, const char *url, gpointer data) +{ + GError *err = NULL; + + gnome_url_show (url, &err); + + if (err) { + g_warning ("gnome_url_show: %s", err->message); + g_error_free (err); + } +} + +static void +on_url_cb (GtkHTML *html, const char *url, gpointer data) +{ +#if 0 + char *msg; + ECalComponentPreview *preview = data; + + if (url && *url) { + msg = g_strdup_printf (_("Click to open %s"), url); + e_calendar_table_set_status_message (e_tasks_get_calendar_table (tasks), msg); + g_free (msg); + } else + e_calendar_table_set_status_message (e_tasks_get_calendar_table (tasks), NULL); +#endif +} + +/* Callback used when the user selects a URL in the HTML widget */ +static void +url_requested_cb (GtkHTML *html, const char *url, GtkHTMLStream *stream, gpointer data) +{ + if (!strncmp ("file:///", url, strlen ("file:///"))) { + GnomeVFSHandle *handle; + GnomeVFSResult result; + char buffer[4096]; + + if (gnome_vfs_open (&handle, url, GNOME_VFS_OPEN_READ) == GNOME_VFS_OK) { + do { + GnomeVFSFileSize bread; + + result = gnome_vfs_read (handle, buffer, sizeof (buffer), &bread); + if (result == GNOME_VFS_OK) + gtk_html_stream_write (stream, buffer, bread); + } while (result == GNOME_VFS_OK); + + gnome_vfs_close (handle); + } + } +} + +/* Converts a time_t to a string, relative to the specified timezone */ +static char * +timet_to_str_with_zone (ECalComponentDateTime *dt, ECal *ecal, icaltimezone *default_zone) +{ + struct icaltimetype itt; + icaltimezone *zone; + struct tm tm; + char buf[256]; + + if (dt->tzid) { + /* If we can't find the zone, we'll guess its "local" */ + if (!e_cal_get_timezone (ecal, dt->tzid, &zone, NULL)) + zone = NULL; + } else if (dt->value->is_utc) { + zone = icaltimezone_get_utc_timezone (); + } else { + zone = NULL; + } + + + itt = *dt->value; + if (zone) + icaltimezone_convert_time (&itt, zone, default_zone); + tm = icaltimetype_to_tm (&itt); + + e_time_format_date_and_time (&tm, calendar_config_get_24_hour_format (), + FALSE, FALSE, buf, sizeof (buf)); + + return g_locale_to_utf8 (buf, -1, NULL, NULL, NULL); +} + +static void +write_html (GtkHTMLStream *stream, ECal *ecal, ECalComponent *comp, icaltimezone *default_zone) +{ + ECalComponentText text; + ECalComponentDateTime dt; + gchar *str; + GSList *l; + icalproperty_status status; + const char *location; + int *priority_value; + + g_return_if_fail (E_IS_CAL_COMPONENT (comp)); + + /* write document header */ + e_cal_component_get_summary (comp, &text); + + if (text.value) + gtk_html_stream_printf (stream, + "<HTML><BODY><H1>%s</H1>", + text.value); + else + gtk_html_stream_printf (stream, + "<HTML><BODY><H1><I>%s</I></H1>", + _("Untitled")); + + + /* write icons for the categories */ + e_cal_component_get_categories_list (comp, &l); + if (l) { + GSList *node; + + for (node = l; node != NULL; node = node->next) { + const char *icon_file; + + icon_file = e_categories_config_get_icon_file_for ((const char *) node->data); + if (icon_file) { + gtk_html_stream_printf (stream, "<IMG ALT=\"%s\" SRC=\"file://%s\">", + (const char *) node->data, icon_file); + } + } + + e_cal_component_free_categories_list (l); + + gtk_html_stream_printf (stream, "<BR><BR><BR>"); + } + + /* Start table */ + gtk_html_stream_printf (stream, "<TABLE BORDER=\"0\" WIDTH=\"80%%\">" + "<TR><TD VALIGN=\"TOP\" ALIGN=\"RIGHT\" WIDTH=\"15%%\"></TD></TR>"); + + /* write location */ + e_cal_component_get_location (comp, &location); + if (location) + gtk_html_stream_printf (stream, "<TR><TD VALIGN=\"TOP\" ALIGN=\"RIGHT\" WIDTH=\"15%%\"><B>%s</B></TD><TD>%s</TD></TR>", + _("Summary:"), text.value); + + /* write start date */ + e_cal_component_get_dtstart (comp, &dt); + if (dt.value != NULL) { + str = timet_to_str_with_zone (&dt, ecal, default_zone); + gtk_html_stream_printf (stream, "<TR><TD VALIGN=\"TOP\" ALIGN=\"RIGHT\"><B>%s</B></TD><TD>%s</TD></TR>", + _("Start Date:"), str); + + e_cal_component_free_datetime (&dt); + g_free (str); + } + + /* write end date */ + e_cal_component_get_dtend (comp, &dt); + if (dt.value != NULL) { + str = timet_to_str_with_zone (&dt, ecal, default_zone); + gtk_html_stream_printf (stream, "<TR><TD VALIGN=\"TOP\" ALIGN=\"RIGHT\"><B>%s</B></TD><TD>%s</TD></TR>", + _("Start Date:"), str); + + e_cal_component_free_datetime (&dt); + g_free (str); + } + + /* write Due Date */ + e_cal_component_get_due (comp, &dt); + if (dt.value != NULL) { + str = timet_to_str_with_zone (&dt, ecal, default_zone); + gtk_html_stream_printf (stream, "<TR><TD VALIGN=\"TOP\" ALIGN=\"RIGHT\"><B>%s</B></TD><TD>%s</TD></TR>", + _("Due Date:"), str); + + e_cal_component_free_datetime (&dt); + g_free (str); + } + + /* write status */ + gtk_html_stream_printf (stream, "<TR><TD VALIGN=\"TOP\" ALIGN=\"RIGHT\"><B>%s</B></TD>", _("Status:")); + e_cal_component_get_status (comp, &status); + switch (status) { + case ICAL_STATUS_INPROCESS : + str = g_strdup (_("In Progress")); + break; + case ICAL_STATUS_COMPLETED : + str = g_strdup (_("Completed")); + break; + case ICAL_STATUS_CANCELLED : + str = g_strdup (_("Cancelled")); + break; + case ICAL_STATUS_NONE : + default : + str = g_strdup (_("Not Started")); + break; + } + + gtk_html_stream_printf (stream, "<TD>%s</TD></TR>", str); + g_free (str); + + /* write priority */ + e_cal_component_get_priority (comp, &priority_value); + if (priority_value && *priority_value != 0) { + gtk_html_stream_printf (stream, "<TR><TD VALIGN=\"TOP\" ALIGN=\"RIGHT\"><B>%s</B></TD>", _("Priority:")); + if (*priority_value <= 4) + str = g_strdup (_("High")); + else if (*priority_value == 5) + str = g_strdup (_("Normal")); + else + str = g_strdup (_("Low")); + + gtk_html_stream_printf (stream, "<TD>%s</TD></TR>", str); + + g_free (str); + e_cal_component_free_priority (priority_value); + } + + /* write description and URL */ + gtk_html_stream_printf (stream, "<TR><TD COLSPAN=\"2\"><HR></TD></TR>"); + + e_cal_component_get_description_list (comp, &l); + if (l) { + GSList *node; + + gtk_html_stream_printf (stream, "<TR><TD VALIGN=\"TOP\" ALIGN=\"RIGHT\"><B>%s</B></TD>", _("Description:")); + + gtk_html_stream_printf (stream, "<TD>"); + + for (node = l; node != NULL; node = node->next) { + gint i; + GString *str = g_string_new ("");; + + text = * (ECalComponentText *) node->data; + for (i = 0; i < strlen (text.value ? text.value : 0); i++) { + if (text.value[i] == '\n') + str = g_string_append (str, "<BR>"); + else if (text.value[i] == '<') + str = g_string_append (str, "<"); + else if (text.value[i] == '>') + str = g_string_append (str, ">"); + else + str = g_string_append_c (str, text.value[i]); + } + + gtk_html_stream_printf (stream, str->str); + g_string_free (str, TRUE); + } + + gtk_html_stream_printf (stream, "</TD></TR>"); + + e_cal_component_free_text_list (l); + } + + /* URL */ + e_cal_component_get_url (comp, (const char **) &str); + if (str) { + gtk_html_stream_printf (stream, "<TR><TD VALIGN=\"TOP\" ALIGN=\"RIGHT\"><B>%s</B></TD>", _("Web Page:")); + gtk_html_stream_printf (stream, "<TD><A HREF=\"%s\">%s</A></TD></TR>", str, str); + } + + gtk_html_stream_printf (stream, "</TABLE>"); + + /* close document */ + gtk_html_stream_printf (stream, "</BODY></HTML>"); +} + +static void +e_cal_component_preview_init (ECalComponentPreview *preview) +{ + ECalComponentPreviewPrivate *priv; + GtkWidget *scroll; + + priv = g_new0 (ECalComponentPreviewPrivate, 1); + preview->priv = priv; + + priv->html = gtk_html_new (); + gtk_html_set_default_content_type (GTK_HTML (priv->html), "charset=utf-8"); + gtk_html_load_empty (GTK_HTML (priv->html)); + + g_signal_connect (G_OBJECT (priv->html), "url_requested", + G_CALLBACK (url_requested_cb), NULL); + g_signal_connect (G_OBJECT (priv->html), "link_clicked", + G_CALLBACK (on_link_clicked), preview); + g_signal_connect (G_OBJECT (priv->html), "on_url", + G_CALLBACK (on_url_cb), preview); + + scroll = gtk_scrolled_window_new (NULL, NULL); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), + GTK_POLICY_AUTOMATIC, + GTK_POLICY_AUTOMATIC); + gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scroll), GTK_SHADOW_IN); + + gtk_container_add (GTK_CONTAINER (scroll), priv->html); + gtk_container_add (GTK_CONTAINER (preview), scroll); + gtk_widget_show_all (scroll); + + priv->zone = icaltimezone_get_utc_timezone (); +} + +static void +e_cal_component_preview_destroy (GtkObject *object) +{ + ECalComponentPreview *preview; + ECalComponentPreviewPrivate *priv; + + g_return_if_fail (object != NULL); + g_return_if_fail (E_IS_CAL_COMPONENT_PREVIEW (object)); + + preview = E_CAL_COMPONENT_PREVIEW (object); + priv = preview->priv; + + if (priv) { + + g_free (priv); + preview->priv = NULL; + } + + if (GTK_OBJECT_CLASS (parent_class)->destroy) + (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); +} + +static void +e_cal_component_preview_class_init (ECalComponentPreviewClass *klass) +{ + GtkObjectClass *object_class; + + object_class = (GtkObjectClass *) klass; + + parent_class = g_type_class_peek_parent (klass); + + object_class->destroy = e_cal_component_preview_destroy; +} + +E_MAKE_TYPE (e_cal_component_preview, "ECalComponentPreview", ECalComponentPreview, + e_cal_component_preview_class_init, e_cal_component_preview_init, + GTK_TYPE_TABLE) + +GtkWidget * +e_cal_component_preview_new (void) +{ + ECalComponentPreview *preview; + + preview = g_object_new (e_cal_component_preview_get_type (), NULL); + + return GTK_WIDGET (preview); +} + +icaltimezone * +e_cal_component_preview_get_default_timezone (ECalComponentPreview *preview) +{ + ECalComponentPreviewPrivate *priv; + + g_return_val_if_fail (preview != NULL, NULL); + g_return_val_if_fail (E_IS_CAL_COMPONENT_PREVIEW (preview), NULL); + + priv = preview->priv; + + return priv->zone; +} + +void +e_cal_component_preview_set_default_timezone (ECalComponentPreview *preview, icaltimezone *zone) +{ + ECalComponentPreviewPrivate *priv; + + g_return_if_fail (preview != NULL); + g_return_if_fail (E_IS_CAL_COMPONENT_PREVIEW (preview)); + g_return_if_fail (zone != NULL); + + priv = preview->priv; + + priv->zone = zone; +} + +void +e_cal_component_preview_display (ECalComponentPreview *preview, ECal *ecal, ECalComponent *comp) +{ + ECalComponentPreviewPrivate *priv; + GtkHTMLStream *stream; + + g_return_if_fail (preview != NULL); + g_return_if_fail (E_IS_CAL_COMPONENT_PREVIEW (preview)); + g_return_if_fail (comp != NULL); + g_return_if_fail (E_IS_CAL_COMPONENT (comp)); + + priv = preview->priv; + + stream = gtk_html_begin (GTK_HTML (priv->html)); + write_html (stream, ecal, comp, priv->zone); + gtk_html_stream_close (stream, GTK_HTML_STREAM_OK); +} + +void +e_cal_component_preview_clear (ECalComponentPreview *preview) +{ + ECalComponentPreviewPrivate *priv; + + g_return_if_fail (preview != NULL); + g_return_if_fail (E_IS_CAL_COMPONENT_PREVIEW (preview)); + + priv = preview->priv; + + gtk_html_load_empty (GTK_HTML (priv->html)); +} + diff --git a/calendar/gui/e-cal-component-preview.h b/calendar/gui/e-cal-component-preview.h new file mode 100644 index 0000000000..b2f02f813c --- /dev/null +++ b/calendar/gui/e-cal-component-preview.h @@ -0,0 +1,65 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* e-cal-component-preview.h + * + * Copyright (C) 2004 Novell, Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * 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 + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + * Authors: Federico Mena Quintero <federico@ximian.com> + * Damon Chaplin <damon@ximian.com> + */ + +#ifndef _E_CAL_COMPONENT_PREVIEW_H_ +#define _E_CAL_COMPONENT_PREVIEW_H_ + +#include <gtk/gtktable.h> +#include <libecal/e-cal.h> + +#define E_TYPE_CAL_COMPONENT_PREVIEW (e_cal_component_preview_get_type ()) +#define E_CAL_COMPONENT_PREVIEW(obj) (GTK_CHECK_CAST ((obj), E_TYPE_CAL_COMPONENT_PREVIEW, ECalComponentPreview)) +#define E_CAL_COMPONENT_PREVIEW_CLASS(klass) (GTK_CHECK_CAST_CLASS ((klass), E_TYPE_CAL_COMPONENT_PREVIEW, \ + ECalComponentPreviewClass)) +#define E_IS_CAL_COMPONENT_PREVIEW(obj) (GTK_CHECK_TYPE ((obj), E_TYPE_CAL_COMPONENT_PREVIEW)) +#define E_IS_CAL_COMPONENT_PREVIEW_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), E_TYPE_CAL_COMPONENT_PREVIEW)) + +typedef struct _ECalComponentPreview ECalComponentPreview; +typedef struct _ECalComponentPreviewClass ECalComponentPreviewClass; +typedef struct _ECalComponentPreviewPrivate ECalComponentPreviewPrivate; + +struct _ECalComponentPreview { + GtkTable table; + + /* Private data */ + ECalComponentPreviewPrivate *priv; +}; + +struct _ECalComponentPreviewClass { + GtkTableClass parent_class; + + /* Notification signals */ + void (* selection_changed) (ECalComponentPreview *preview, int n_selected); +}; + + +GtkType e_cal_component_preview_get_type (void); +GtkWidget *e_cal_component_preview_new (void); + +icaltimezone *e_cal_component_preview_get_default_timezone (ECalComponentPreview *preview); +void e_cal_component_preview_set_default_timezone (ECalComponentPreview *preview, icaltimezone *zone); + +void e_cal_component_preview_display (ECalComponentPreview *preview, ECal *ecal, ECalComponent *comp); +void e_cal_component_preview_clear (ECalComponentPreview *preview); + +#endif /* _E_CAL_COMPONENT_PREVIEW_H_ */ diff --git a/calendar/gui/e-tasks.c b/calendar/gui/e-tasks.c index 0072e26873..e1f65b5af0 100644 --- a/calendar/gui/e-tasks.c +++ b/calendar/gui/e-tasks.c @@ -22,7 +22,10 @@ * Rodrigo Moya <rodrigo@ximian.com> */ +#ifdef HAVE_CONFIG_H #include <config.h> +#endif + #include <gnome.h> #include <libgnomevfs/gnome-vfs-ops.h> #include <gal/util/e-util.h> @@ -30,8 +33,6 @@ #include <gal/menus/gal-view-instance.h> #include <gal/menus/gal-view-factory-etable.h> #include <gal/menus/gal-view-etable.h> -#include <gtkhtml/gtkhtml.h> -#include <gtkhtml/gtkhtml-stream.h> #include "e-util/e-categories-config.h" #include "e-util/e-time-utils.h" @@ -48,6 +49,7 @@ #include "e-calendar-table-config.h" #include "misc.h" #include "tasks-component.h" +#include "e-cal-component-preview.h" #include "e-tasks.h" #include "common/authentication.h" @@ -67,8 +69,9 @@ struct _ETasksPrivate { /* Calendar search bar for tasks */ GtkWidget *search_bar; - /* The HTML widget to display the task's details */ - GtkWidget *html; + /* The preview */ + GtkWidget *preview; + gchar *current_uid; /* View instance and the view menus handler */ @@ -102,261 +105,45 @@ E_MAKE_TYPE (e_tasks, "ETasks", ETasks, e_tasks_class_init, e_tasks_init, GTK_TYPE_TABLE) -/* Converts a time_t to a string, relative to the specified timezone */ -static char * -timet_to_str_with_zone (time_t t, icaltimezone *zone) -{ - struct icaltimetype itt; - struct tm tm; - char buf[256]; - - if (t == -1) - return g_strdup (_("invalid time")); - - itt = icaltime_from_timet_with_zone (t, FALSE, zone); - tm = icaltimetype_to_tm (&itt); - - e_time_format_date_and_time (&tm, calendar_config_get_24_hour_format (), - FALSE, FALSE, buf, sizeof (buf)); - return g_strdup (buf); -} - -static void -write_html (GtkHTMLStream *stream, ECalComponent *comp) -{ - ECalComponentText text; - ECalComponentDateTime dt; - gchar *buf, *str; - icaltimezone *current_zone; - GSList *l; - icalproperty_status status; - int *priority_value; - - g_return_if_fail (E_IS_CAL_COMPONENT (comp)); - - current_zone = calendar_config_get_icaltimezone (); - - /* write document header */ - e_cal_component_get_summary (comp, &text); - gtk_html_stream_printf (stream, - "<HTML><BODY><H1>%s</H1>", - text.value); - - /* write icons for the categories */ - e_cal_component_get_categories_list (comp, &l); - if (l) { - GSList *node; - - for (node = l; node != NULL; node = node->next) { - const char *icon_file; - - icon_file = e_categories_config_get_icon_file_for ((const char *) node->data); - if (icon_file) { - gtk_html_stream_printf (stream, "<IMG ALT=\"%s\" SRC=\"file://%s\">", - (const char *) node->data, icon_file); - } - } - - e_cal_component_free_categories_list (l); - } - - /* write summary */ - gtk_html_stream_printf (stream, - "<BR><BR><BR><TABLE BORDER=\"0\" WIDTH=\"80%%\">" - "<TR><TD VALIGN=\"TOP\" ALIGN=\"RIGHT\" WIDTH=\"15%%\"><B>%s</B></TD><TD>%s</TD></TR>", - _("Summary:"), text.value); - - /* write start date */ - e_cal_component_get_dtstart (comp, &dt); - if (dt.value != NULL) { - buf = timet_to_str_with_zone (icaltime_as_timet (*dt.value), current_zone); - str = g_locale_to_utf8 (buf, -1, NULL, NULL, NULL); - - g_free (buf); - } else - str = g_strdup (""); - - gtk_html_stream_printf (stream, "<TR><TD VALIGN=\"TOP\" ALIGN=\"RIGHT\"><B>%s</B></TD><TD>%s</TD></TR>", - _("Start Date:"), str); - - e_cal_component_free_datetime (&dt); - g_free (str); - - /* write Due Date */ - e_cal_component_get_due (comp, &dt); - if (dt.value != NULL) { - buf = timet_to_str_with_zone (icaltime_as_timet (*dt.value), current_zone); - str = g_locale_to_utf8 (buf, -1, NULL, NULL, NULL); - - g_free (buf); - } else - str = g_strdup (""); - - gtk_html_stream_printf (stream, "<TR><TD VALIGN=\"TOP\" ALIGN=\"RIGHT\"><B>%s</B></TD><TD>%s</TD></TR>", - _("Due Date:"), str); - - e_cal_component_free_datetime (&dt); - g_free (str); - - /* write status */ - gtk_html_stream_printf (stream, "<TR><TD VALIGN=\"TOP\" ALIGN=\"RIGHT\"><B>%s</B></TD>", _("Status:")); - e_cal_component_get_status (comp, &status); - switch (status) { - case ICAL_STATUS_INPROCESS : - str = g_strdup (_("In Progress")); - break; - case ICAL_STATUS_COMPLETED : - str = g_strdup (_("Completed")); - break; - case ICAL_STATUS_CANCELLED : - str = g_strdup (_("Cancelled")); - break; - case ICAL_STATUS_NONE : - default : - str = g_strdup (_("Not Started")); - break; - } - - gtk_html_stream_printf (stream, "<TD>%s</TD></TR>", str); - g_free (str); - - /* write priority */ - gtk_html_stream_printf (stream, "<TR><TD VALIGN=\"TOP\" ALIGN=\"RIGHT\"><B>%s</B></TD>", _("Priority:")); - e_cal_component_get_priority (comp, &priority_value); - if (priority_value) { - if (*priority_value == 0) - str = g_strdup (""); - else if (*priority_value <= 4) - str = g_strdup (_("High")); - else if (*priority_value == 5) - str = g_strdup (_("Normal")); - else - str = g_strdup (_("Low")); - - gtk_html_stream_printf (stream, "<TD>%s</TD></TR>", str); - - g_free (str); - e_cal_component_free_priority (priority_value); - } else - gtk_html_stream_printf (stream, "<TD></TD></TR>"); - - /* write description and URL */ - gtk_html_stream_printf (stream, "<TR><TD COLSPAN=\"2\"><HR></TD></TR>"); - - gtk_html_stream_printf (stream, "<TR><TD VALIGN=\"TOP\" ALIGN=\"RIGHT\"><B>%s</B></TD>", _("Description:")); - e_cal_component_get_description_list (comp, &l); - if (l) { - GSList *node; - - gtk_html_stream_printf (stream, "<TD>"); - - for (node = l; node != NULL; node = node->next) { - gint i; - GString *str = g_string_new ("");; - - text = * (ECalComponentText *) node->data; - for (i = 0; i < strlen (text.value ? text.value : 0); i++) { - if (text.value[i] == '\n') - str = g_string_append (str, "<BR>"); - else if (text.value[i] == '<') - str = g_string_append (str, "<"); - else if (text.value[i] == '>') - str = g_string_append (str, ">"); - else - str = g_string_append_c (str, text.value[i]); - } - - gtk_html_stream_printf (stream, str->str); - g_string_free (str, TRUE); - } - - gtk_html_stream_printf (stream, "</TD></TR>"); - - e_cal_component_free_text_list (l); - } else - gtk_html_stream_printf (stream, "<TD></TD></TR>"); - - /* URL */ - gtk_html_stream_printf (stream, "<TR><TD VALIGN=\"TOP\" ALIGN=\"RIGHT\"><B>%s</B></TD>", _("Web Page:")); - e_cal_component_get_url (comp, (const char **) &str); - if (str) - gtk_html_stream_printf (stream, "<TD><A HREF=\"%s\">%s</A></TD></TR>", str, str); - else - gtk_html_stream_printf (stream, "<TD></TD></TR>"); - - gtk_html_stream_printf (stream, "</TABLE>"); - - /* close document */ - gtk_html_stream_printf (stream, "</BODY></HTML>"); -} - -static void -on_link_clicked (GtkHTML *html, const char *url, gpointer data) -{ - GError *err = NULL; - - gnome_url_show (url, &err); - - if (err) { - g_warning ("gnome_url_show: %s", err->message); - g_error_free (err); - } -} - -static void -on_url_cb (GtkHTML *html, const char *url, gpointer data) -{ - char *msg; - ETasks *tasks = data; - - if (url && *url) { - msg = g_strdup_printf (_("Click to open %s"), url); - e_calendar_table_set_status_message (e_tasks_get_calendar_table (tasks), msg); - g_free (msg); - } else - e_calendar_table_set_status_message (e_tasks_get_calendar_table (tasks), NULL); -} - /* Callback used when the cursor changes in the table */ static void table_cursor_change_cb (ETable *etable, int row, gpointer data) { ETasks *tasks; ETasksPrivate *priv; + ECalModel *model; + ECalModelComponent *comp_data; + ECalComponent *comp; + const char *uid; + int n_selected; tasks = E_TASKS (data); priv = tasks->priv; n_selected = e_table_selected_count (etable); - + /* update the HTML widget */ - if (n_selected == 1) { - GtkHTMLStream *stream; - ECalModel *model; - ECalModelComponent *comp_data; - ECalComponent *comp; - const char *uid; + if (n_selected != 1) { + e_cal_component_preview_clear (E_CAL_COMPONENT_PREVIEW (priv->preview)); - model = e_calendar_table_get_model (E_CALENDAR_TABLE (priv->tasks_view)); - - stream = gtk_html_begin (GTK_HTML (priv->html)); - - comp_data = e_cal_model_get_component_at (model, e_table_get_cursor_row (etable)); - comp = e_cal_component_new (); - e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (comp_data->icalcomp)); - write_html (stream, comp); - - gtk_html_stream_close (stream, GTK_HTML_STREAM_OK); - - e_cal_component_get_uid (comp, &uid); - if (priv->current_uid) - g_free (priv->current_uid); - priv->current_uid = g_strdup (uid); + return; + } + + model = e_calendar_table_get_model (E_CALENDAR_TABLE (priv->tasks_view)); + + comp_data = e_cal_model_get_component_at (model, e_table_get_cursor_row (etable)); + comp = e_cal_component_new (); + e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (comp_data->icalcomp)); - g_object_unref (comp); - } else - gtk_html_load_empty (GTK_HTML (priv->html)); + e_cal_component_preview_display (E_CAL_COMPONENT_PREVIEW (priv->preview), comp_data->client, comp); + + e_cal_component_get_uid (comp, &uid); + if (priv->current_uid) + g_free (priv->current_uid); + priv->current_uid = g_strdup (uid); + + g_object_unref (comp); } /* Callback used when the selection changes in the table. */ @@ -403,29 +190,6 @@ search_bar_category_changed_cb (CalSearchBar *cal_search, const char *category, e_cal_model_set_default_category (model, category); } -/* Callback used when the user selects a URL in the HTML widget */ -static void -url_requested_cb (GtkHTML *html, const char *url, GtkHTMLStream *stream, gpointer data) -{ - if (!strncmp ("file:///", url, strlen ("file:///"))) { - GnomeVFSHandle *handle; - GnomeVFSResult result; - char buffer[4096]; - - if (gnome_vfs_open (&handle, url, GNOME_VFS_OPEN_READ) == GNOME_VFS_OK) { - do { - GnomeVFSFileSize bread; - - result = gnome_vfs_read (handle, buffer, sizeof (buffer), &bread); - if (result == GNOME_VFS_OK) - gtk_html_stream_write (stream, buffer, bread); - } while (result == GNOME_VFS_OK); - - gnome_vfs_close (handle); - } - } -} - static gboolean vpaned_resized_cb (GtkWidget *widget, GdkEventButton *event, ETasks *tasks) { @@ -451,6 +215,8 @@ set_timezone (ETasks *tasks) /* FIXME Error checking */ e_cal_set_default_timezone (client, zone, NULL); } + + e_cal_component_preview_set_default_timezone (E_CAL_COMPONENT_PREVIEW (priv->preview), zone); } static void @@ -550,7 +316,7 @@ setup_widgets (ETasks *tasks) ETasksPrivate *priv; ETable *etable; ECalModel *model; - GtkWidget *paned, *scroll; + GtkWidget *paned; priv = tasks->priv; @@ -587,26 +353,11 @@ setup_widgets (ETasks *tasks) g_signal_connect (etable, "selection_change", G_CALLBACK (table_selection_change_cb), tasks); /* create the task detail */ - priv->html = gtk_html_new (); - gtk_html_set_default_content_type (GTK_HTML (priv->html), "charset=utf-8"); - gtk_html_load_empty (GTK_HTML (priv->html)); - - g_signal_connect (G_OBJECT (priv->html), "url_requested", - G_CALLBACK (url_requested_cb), NULL); - g_signal_connect (G_OBJECT (priv->html), "link_clicked", - G_CALLBACK (on_link_clicked), tasks); - g_signal_connect (G_OBJECT (priv->html), "on_url", - G_CALLBACK (on_url_cb), tasks); - - gtk_widget_pop_colormap (); - scroll = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scroll), GTK_SHADOW_IN); - gtk_container_add (GTK_CONTAINER (scroll), priv->html); - gtk_paned_add2 (GTK_PANED (paned), scroll); - gtk_widget_show_all (scroll); +// gtk_widget_pop_colormap (); + + priv->preview = e_cal_component_preview_new (); + gtk_paned_add2 (GTK_PANED (paned), priv->preview); + gtk_widget_show (priv->preview); model = e_calendar_table_get_model (E_CALENDAR_TABLE (priv->tasks_view)); g_signal_connect (G_OBJECT (model), "model_row_changed", @@ -1053,7 +804,8 @@ e_tasks_delete_selected (ETasks *tasks) set_status_message (tasks, _("Deleting selected objects...")); e_calendar_table_delete_selected (cal_table); set_status_message (tasks, NULL); - gtk_html_load_empty (GTK_HTML (priv->html)); + + e_cal_component_preview_clear (E_CAL_COMPONENT_PREVIEW (priv->preview)); } /** |