From 2a22b3d668b277ff354d767635a7c6067360645a Mon Sep 17 00:00:00 2001 From: Larry Ewing Date: Thu, 18 Oct 2001 19:59:05 +0000 Subject: add html widget (url_requested_cb): add function to load images from file 2001-10-18 Larry Ewing * gui/alarm-notify/alarm-notify-dialog.c: add html widget (url_requested_cb): add function to load images from file as they are requested. (write_html_heading): convert to using html. (alarm_notify_dialog): convert to use html display. (make_html_display): this is the function the custom widget in the galde file uses to create the html widget. * gui/alarm-notify/alarm-notify.glade: add placeholder for the custom html widget. * gui/alarm-notify/Makefile.am: add flags for gtkhtml and gal. svn path=/trunk/; revision=13766 --- calendar/gui/alarm-notify/alarm-notify-dialog.c | 189 +++++++++++++++++------- 1 file changed, 132 insertions(+), 57 deletions(-) (limited to 'calendar/gui/alarm-notify/alarm-notify-dialog.c') diff --git a/calendar/gui/alarm-notify/alarm-notify-dialog.c b/calendar/gui/alarm-notify/alarm-notify-dialog.c index 665419241f..c6644264c6 100644 --- a/calendar/gui/alarm-notify/alarm-notify-dialog.c +++ b/calendar/gui/alarm-notify/alarm-notify-dialog.c @@ -1,7 +1,7 @@ /* Evolution calendar - alarm notification dialog * * Copyright (C) 2000 Ximian, Inc. - * Copyright (C) 2000 Ximian, Inc. + * Copyright (C) 2001 Ximian, Inc. * * Author: Federico Mena-Quintero * @@ -21,6 +21,8 @@ */ #include +#include +#include #include #include #include @@ -28,11 +30,18 @@ #include #include #include +#include #include +#include +#include #include +#include +#include +#include #include "alarm-notify-dialog.h" +GtkWidget *make_html_display (gchar *widget_name, char *s1, char *s2, int scroll, int shadow); /* The useful contents of the alarm notify dialog */ typedef struct { @@ -45,6 +54,7 @@ typedef struct { GtkWidget *heading; GtkWidget *message; GtkWidget *snooze_time; + GtkWidget *html; AlarmNotifyFunc func; gpointer func_data; @@ -122,18 +132,108 @@ edit_clicked_cb (GtkWidget *widget, gpointer data) gtk_widget_destroy (an->dialog); } +static void +url_requested_cb (GtkHTML *html, const char *url, GtkHTMLStream *stream, gpointer data) +{ + + if (!strncmp ("file:///", url, strlen ("file:///"))) { + FILE *fp; + const char *filename = url + strlen ("file://"); + char buf[4096]; + size_t len; + + fp = fopen (filename, "r"); + + if (fp == NULL) { + g_warning ("Error opening image: %s\n", url); + gtk_html_stream_close (stream, GTK_HTML_STREAM_ERROR); + return; + } + + while ((len = fread (buf, 1, sizeof(buf), fp)) > 0) + gtk_html_stream_write (stream, buf, len); + + if (feof (fp)) { + fclose (fp); + gtk_html_stream_close (stream, GTK_HTML_STREAM_OK); + return; + } + + fclose (fp); + } + + g_warning ("Error loading image"); + gtk_html_stream_close (stream, GTK_HTML_STREAM_ERROR); + return; +} + +GtkWidget * +make_html_display (gchar *widget_name, char *s1, char *s2, int scroll, int shadow) +{ + GtkWidget *html, *frame; + + gtk_widget_push_visual(gdk_rgb_get_visual()); + gtk_widget_push_colormap(gdk_rgb_get_cmap()); + + html = gtk_html_new(); + + gtk_html_set_default_content_type (GTK_HTML (html), + "charset=utf-8"); + gtk_html_load_empty (GTK_HTML (html)); + + gtk_signal_connect (GTK_OBJECT (html), "url_requested", + GTK_SIGNAL_FUNC (url_requested_cb), + NULL); + + gtk_widget_pop_colormap(); + gtk_widget_pop_visual(); + + frame = e_scroll_frame_new(NULL, NULL); + + e_scroll_frame_set_policy(E_SCROLL_FRAME(frame), + GTK_POLICY_AUTOMATIC, + GTK_POLICY_AUTOMATIC); + + + e_scroll_frame_set_shadow_type (E_SCROLL_FRAME (frame), + GTK_SHADOW_IN); + + gtk_widget_set_usize (frame, 300, 200); + + gtk_container_add(GTK_CONTAINER (frame), html); + + gtk_widget_show_all(frame); + + gtk_object_set_user_data(GTK_OBJECT (frame), html); + return frame; +} + +static void +write_times (GtkHTMLStream *stream, char *start, char *end) +{ + if (start) + gtk_html_stream_printf (stream, "%s %s
", U_("Starting:"), start); + if (end) + gtk_html_stream_printf (stream, "%s %s
", U_("Ending:"), end); + +} + /* Creates a heading for the alarm notification dialog */ -static char * -make_heading (CalComponentVType vtype, time_t occur_start, time_t occur_end) +static void +write_html_heading (GtkHTMLStream *stream, const char *message, CalComponentVType vtype, time_t occur_start, time_t occur_end) { char *buf; char s[128], e[128]; + char *start = NULL, *end = NULL; + char *bg_path = "file://" EVOLUTION_ICONSDIR "/bcg.png"; + char *image_path = "file://" EVOLUTION_ICONSDIR "/alarm.png"; if (occur_start != -1) { struct tm tm; tm = *localtime (&occur_start); strftime (s, sizeof (s), "%A %b %d %Y %H:%M", &tm); + start = e_utf8_from_locale_string (s); } if (occur_end != -1) { @@ -141,51 +241,33 @@ make_heading (CalComponentVType vtype, time_t occur_start, time_t occur_end) tm = *localtime (&occur_end); strftime (e, sizeof (e), "%A %b %d %Y %H:%M", &tm); + end = e_utf8_from_locale_string (e); } /* I love combinatorial explosion */ + gtk_html_stream_printf (stream, + "" + "" + "" + "" + "" + "" + "

%s

", + bg_path, + image_path, + U_("Evolution Alarm")); + + gtk_html_stream_printf (stream, "

%s

", message); switch (vtype) { case CAL_COMPONENT_EVENT: - if (occur_start != -1) { - if (occur_end != -1) - buf = g_strdup_printf (_("Notification about your appointment " - "starting on %s and ending on %s"), - s, e); - else - buf = g_strdup_printf (_("Notification about your appointment " - "starting on %s"), - s); - } else { - if (occur_end != -1) - buf = g_strdup_printf (_("Notification about your appointment " - "ending on %s"), - e); - else - buf = g_strdup_printf (_("Notification about your appointment")); - } + /* gtk_html_stream_printf (stream, "%s
", U_("Notification about your appointment")); */ + write_times (stream, start, end); break; - case CAL_COMPONENT_TODO: - if (occur_start != -1) { - if (occur_end != -1) - buf = g_strdup_printf (_("Notification about your task " - "starting on %s and ending on %s"), - s, e); - else - buf = g_strdup_printf (_("Notification about your task " - "starting on %s"), - s); - } else { - if (occur_end != -1) - buf = g_strdup_printf (_("Notification about your task " - "ending on %s"), - e); - else - buf = g_strdup_printf (_("Notification about your task")); - } + /* gtk_html_stream_printf (stream, "%s
", U_("Notification about your task")); */ + write_times (stream, start, end); break; - default: /* Only VEVENTs and VTODOs can have alarms */ g_assert_not_reached (); @@ -193,7 +275,9 @@ make_heading (CalComponentVType vtype, time_t occur_start, time_t occur_end) break; } - return buf; + g_free (start); + g_free (end); + return; } /** @@ -218,9 +302,8 @@ alarm_notify_dialog (time_t trigger, time_t occur_start, time_t occur_end, { AlarmNotify *an; char buf[256]; - char *heading; - char *msg; struct tm tm_trigger; + GtkHTMLStream *stream; g_return_val_if_fail (trigger != -1, FALSE); @@ -248,6 +331,7 @@ alarm_notify_dialog (time_t trigger, time_t occur_start, time_t occur_end, an->heading = glade_xml_get_widget (an->xml, "heading"); an->message = glade_xml_get_widget (an->xml, "message"); an->snooze_time = glade_xml_get_widget (an->xml, "snooze-time"); + an->html = gtk_object_get_user_data (GTK_OBJECT (glade_xml_get_widget (an->xml, "frame"))); if (!(an->dialog && an->close && an->snooze && an->edit && an->heading && an->message && an->snooze_time)) { @@ -262,25 +346,14 @@ alarm_notify_dialog (time_t trigger, time_t occur_start, time_t occur_end, GTK_SIGNAL_FUNC (dialog_destroy_cb), an); /* Title */ - tm_trigger = *localtime (&trigger); strftime (buf, sizeof (buf), _("Alarm on %A %b %d %Y %H:%M"), &tm_trigger); gtk_window_set_title (GTK_WINDOW (an->dialog), buf); - /* Heading */ - - heading = make_heading (vtype, occur_start, occur_end); - gtk_label_set_text (GTK_LABEL (an->heading), heading); - g_free (heading); - - /* Message */ - - msg = e_utf8_to_gtk_string (an->message, message); - if (msg) { - gtk_label_set_text (GTK_LABEL (an->message), msg); - g_free (msg); - } else - g_message ("Could not convert the alarm message from UTF8"); + /* html heading */ + stream = gtk_html_begin (GTK_HTML (an->html)); + write_html_heading (stream, message, vtype, occur_start, occur_end); + gtk_html_stream_close (stream, GTK_HTML_STREAM_OK); /* Connect actions */ @@ -306,7 +379,9 @@ alarm_notify_dialog (time_t trigger, time_t occur_start, time_t occur_end, gtk_widget_realize (an->dialog); gnome_win_hints_set_state (an->dialog, WIN_STATE_STICKY); + gnome_window_icon_set_from_file (GTK_WINDOW (an->dialog), EVOLUTION_ICONSDIR "/alarm.png"); gtk_widget_show (an->dialog); return TRUE; } + -- cgit v1.2.3