Use soup to transfer HTTP files and other bugs fixed
svn path=/trunk/; revision=15344
This commit is contained in:
@ -1,3 +1,49 @@
|
|||||||
|
2002-01-04 Iain Holmes <iain@ximian.com>
|
||||||
|
|
||||||
|
* e-summary-weather.c (message_finished): Made the Weather message
|
||||||
|
more verbose, and say which station data could not be retrieved for.
|
||||||
|
|
||||||
|
2002-01-03 Iain Holmes <iain@ximian.com>
|
||||||
|
|
||||||
|
* Makefile.am: Use SOUP_CFLAGS and SOUP_LIBS
|
||||||
|
|
||||||
|
* e-summary-rdf.c: Include soup.h
|
||||||
|
(close_callback): Remove.
|
||||||
|
(message_finished): Generate the cache and other stuff and redraw.
|
||||||
|
(read_callback): Remove.
|
||||||
|
(open_callback): Remove.
|
||||||
|
(e_summary_rdf_update): Replace gnome-vfs with Soup stuff.
|
||||||
|
(e_summary_rdf_count): Replace gnome-vfs with soup.
|
||||||
|
(rdf_free): ditto
|
||||||
|
(e_summary_rdf_set_online): Ditto
|
||||||
|
|
||||||
|
* e-summary-weather.c: Include soup.h
|
||||||
|
(close_callback): Remove.
|
||||||
|
(message_finished): Parse all the downloaded html.
|
||||||
|
(read_callback): Remove.
|
||||||
|
(open_callback): Remove.
|
||||||
|
(e_summary_weather_update): Use soup instead of gnome-vfs
|
||||||
|
(weather_free): Ditto.
|
||||||
|
(e_summary_weather_count): Ditto.
|
||||||
|
(e_summary_weather_add): ditto;
|
||||||
|
(e_summary_weather_set_online): Ditto.
|
||||||
|
|
||||||
|
* e-summary.c (close_callback): Remove.
|
||||||
|
(read_callback): Remove.
|
||||||
|
(open_callback): Remove.
|
||||||
|
(e_read_file_with_length): Read a file.
|
||||||
|
(e_summary_url_requested): Create the images cache. Load the image
|
||||||
|
with e_read_file_with_length instead of gnome-vfs.
|
||||||
|
|
||||||
|
* main.c (main): Remove gnome_vfs_init.
|
||||||
|
|
||||||
|
* weather.h: Replace gnome-vfs stuff.
|
||||||
|
|
||||||
|
2002-01-03 Iain Holmes <iain@ximian.com>
|
||||||
|
|
||||||
|
* e-summary-offline-handler.c (impl_prepareForOffline): Create an
|
||||||
|
empty list if the summary == NULL. Fixes bug 18025
|
||||||
|
|
||||||
2001-12-20 Ettore Perazzoli <ettore@ximian.com>
|
2001-12-20 Ettore Perazzoli <ettore@ximian.com>
|
||||||
|
|
||||||
[Fixes #17377, Evolution doesn't work on multi-depth displays.]
|
[Fixes #17377, Evolution doesn't work on multi-depth displays.]
|
||||||
|
@ -13,6 +13,7 @@ INCLUDES = \
|
|||||||
$(GTKHTML_CFLAGS) \
|
$(GTKHTML_CFLAGS) \
|
||||||
$(BONOBO_CONF_CFLAGS) \
|
$(BONOBO_CONF_CFLAGS) \
|
||||||
$(BONOBO_GNOME_CFLAGS) \
|
$(BONOBO_GNOME_CFLAGS) \
|
||||||
|
$(SOUP_CFLAGS) \
|
||||||
-DEVOLUTION_GLADEDIR=\""$(gladedir)"\" \
|
-DEVOLUTION_GLADEDIR=\""$(gladedir)"\" \
|
||||||
-DEVOLUTION_LOCALEDIR=\""$(localedir)"\" \
|
-DEVOLUTION_LOCALEDIR=\""$(localedir)"\" \
|
||||||
-DEVOLUTION_DATADIR=\""$(datadir)"\" \
|
-DEVOLUTION_DATADIR=\""$(datadir)"\" \
|
||||||
@ -69,9 +70,10 @@ evolution_executive_summary_LDADD = \
|
|||||||
$(top_builddir)/libversit/libversit.la \
|
$(top_builddir)/libversit/libversit.la \
|
||||||
$(top_builddir)/libical/src/libical/libical-evolution.la \
|
$(top_builddir)/libical/src/libical/libical-evolution.la \
|
||||||
$(top_builddir)/libwombat/libwombat.la \
|
$(top_builddir)/libwombat/libwombat.la \
|
||||||
$(BONOBO_VFS_GNOME_LIBS) \
|
$(BONOBO_GNOME_LIBS) \
|
||||||
$(BONOBO_CONF_LIBS) \
|
$(BONOBO_CONF_LIBS) \
|
||||||
$(EXTRA_GNOME_LIBS) \
|
$(EXTRA_GNOME_LIBS) \
|
||||||
|
$(SOUP_LIBS) \
|
||||||
-lgal \
|
-lgal \
|
||||||
$(GTKHTML_LIBS)
|
$(GTKHTML_LIBS)
|
||||||
|
|
||||||
|
@ -100,6 +100,11 @@ impl_prepareForOffline (PortableServer_Servant servant,
|
|||||||
|
|
||||||
if (priv->summary != NULL) {
|
if (priv->summary != NULL) {
|
||||||
*active_connection_list = e_summary_offline_handler_create_connection_list (priv->summary);
|
*active_connection_list = e_summary_offline_handler_create_connection_list (priv->summary);
|
||||||
|
} else {
|
||||||
|
*active_connection_list = GNOME_Evolution_ConnectionList__alloc ();
|
||||||
|
(*active_connection_list)->_length = 0;
|
||||||
|
(*active_connection_list)->_maximum = 0;
|
||||||
|
(*active_connection_list)->_buffer = CORBA_sequence_GNOME_Evolution_Connection_allocbuf (0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,8 +33,12 @@
|
|||||||
|
|
||||||
#include <libgnome/gnome-defs.h>
|
#include <libgnome/gnome-defs.h>
|
||||||
#include <libgnome/gnome-i18n.h>
|
#include <libgnome/gnome-i18n.h>
|
||||||
|
|
||||||
|
|
||||||
#include <gal/widgets/e-unicode.h>
|
#include <gal/widgets/e-unicode.h>
|
||||||
#include <libgnomevfs/gnome-vfs.h>
|
|
||||||
|
#include <libsoup/soup.h>
|
||||||
|
|
||||||
#include "e-summary.h"
|
#include "e-summary.h"
|
||||||
|
|
||||||
struct _ESummaryRDF {
|
struct _ESummaryRDF {
|
||||||
@ -49,14 +53,14 @@ struct _ESummaryRDF {
|
|||||||
typedef struct _RDF {
|
typedef struct _RDF {
|
||||||
char *uri;
|
char *uri;
|
||||||
char *html;
|
char *html;
|
||||||
GnomeVFSAsyncHandle *handle;
|
|
||||||
GString *string;
|
|
||||||
char *buffer;
|
|
||||||
|
|
||||||
xmlDocPtr cache;
|
xmlDocPtr cache;
|
||||||
ESummary *summary;
|
ESummary *summary;
|
||||||
|
|
||||||
gboolean shown;
|
gboolean shown;
|
||||||
|
|
||||||
|
/* Soup stuff */
|
||||||
|
SoupMessage *message;
|
||||||
} RDF;
|
} RDF;
|
||||||
|
|
||||||
int xmlSubstituteEntitiesDefaultValue = 1;
|
int xmlSubstituteEntitiesDefaultValue = 1;
|
||||||
@ -314,120 +318,35 @@ display_doc (RDF *r)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
close_callback (GnomeVFSAsyncHandle *handle,
|
message_finished (SoupMessage *msg,
|
||||||
GnomeVFSResult result,
|
gpointer userdata)
|
||||||
RDF *r)
|
|
||||||
{
|
{
|
||||||
ESummary *summary;
|
|
||||||
char *xml;
|
|
||||||
xmlDocPtr doc;
|
xmlDocPtr doc;
|
||||||
|
RDF *r = (RDF *) userdata;
|
||||||
|
|
||||||
summary = r->summary;
|
if (SOUP_MESSAGE_IS_ERROR (msg)) {
|
||||||
if (summary->rdf->connection->callback) {
|
g_warning ("Message failed: %d\n%s", msg->errorcode,
|
||||||
ESummaryConnection *connection = summary->rdf->connection;
|
msg->errorphrase);
|
||||||
connection->callback (summary, connection->callback_closure);
|
r->cache = NULL;
|
||||||
}
|
r->message = NULL;
|
||||||
|
|
||||||
if (r->handle == NULL) {
|
display_doc (r);
|
||||||
g_free (r->buffer);
|
|
||||||
r->buffer = NULL;
|
|
||||||
g_string_free (r->string, TRUE);
|
|
||||||
r->string = NULL;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
r->handle = NULL;
|
|
||||||
g_free (r->buffer);
|
|
||||||
r->buffer = NULL;
|
|
||||||
xml = r->string->str;
|
|
||||||
g_string_free (r->string, FALSE);
|
|
||||||
r->string = NULL;
|
|
||||||
|
|
||||||
if (r->cache != NULL) {
|
if (r->cache != NULL) {
|
||||||
xmlFreeDoc (r->cache);
|
xmlFreeDoc (r->cache);
|
||||||
r->cache = NULL;
|
r->cache = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
doc = xmlParseMemory (xml, strlen (xml));
|
doc = xmlParseMemory (msg->response.body, msg->response.length);
|
||||||
#if 0
|
|
||||||
if (doc == NULL) {
|
|
||||||
g_free (r->html);
|
|
||||||
r->html = g_strdup ("<b>Error parsing XML</b>");
|
|
||||||
|
|
||||||
e_summary_draw (r->summary);
|
|
||||||
g_free (xml);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
g_free (xml);
|
|
||||||
r->cache = doc;
|
r->cache = doc;
|
||||||
|
r->message = NULL;
|
||||||
|
|
||||||
/* Draw it */
|
/* Display it */
|
||||||
display_doc (r);
|
display_doc (r);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
read_callback (GnomeVFSAsyncHandle *handle,
|
|
||||||
GnomeVFSResult result,
|
|
||||||
gpointer buffer,
|
|
||||||
GnomeVFSFileSize bytes_requested,
|
|
||||||
GnomeVFSFileSize bytes_read,
|
|
||||||
RDF *r)
|
|
||||||
{
|
|
||||||
if (result != GNOME_VFS_OK && result != GNOME_VFS_ERROR_EOF) {
|
|
||||||
char *str;
|
|
||||||
|
|
||||||
g_free (r->html);
|
|
||||||
str = g_strdup_printf ("<b>%s:</b><br>%s", _("Error downloading RDF"),
|
|
||||||
r->uri);
|
|
||||||
r->html = e_utf8_from_locale_string (str);
|
|
||||||
|
|
||||||
g_free (str);
|
|
||||||
|
|
||||||
e_summary_draw (r->summary);
|
|
||||||
r->handle = NULL;
|
|
||||||
gnome_vfs_async_close (handle,
|
|
||||||
(GnomeVFSAsyncCloseCallback) close_callback, r);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bytes_read == 0) {
|
|
||||||
gnome_vfs_async_close (handle,
|
|
||||||
(GnomeVFSAsyncCloseCallback) close_callback, r);
|
|
||||||
} else {
|
|
||||||
*((char *) buffer + bytes_read) = 0;
|
|
||||||
g_string_append (r->string, (const char *) buffer);
|
|
||||||
gnome_vfs_async_read (handle, buffer, 4095,
|
|
||||||
(GnomeVFSAsyncReadCallback) read_callback, r);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
open_callback (GnomeVFSAsyncHandle *handle,
|
|
||||||
GnomeVFSResult result,
|
|
||||||
RDF *r)
|
|
||||||
{
|
|
||||||
if (result != GNOME_VFS_OK) {
|
|
||||||
char *str;
|
|
||||||
|
|
||||||
r->handle = NULL;
|
|
||||||
g_free (r->html);
|
|
||||||
str = g_strdup_printf ("<b>%s:</b><br>%s", _("Error downloading RDF"),
|
|
||||||
r->uri);
|
|
||||||
r->html = e_utf8_from_locale_string (str);
|
|
||||||
g_free (str);
|
|
||||||
|
|
||||||
display_doc (r);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
r->string = g_string_new ("");
|
|
||||||
r->buffer = g_new (char, 4096);
|
|
||||||
|
|
||||||
gnome_vfs_async_read (handle, r->buffer, 4095,
|
|
||||||
(GnomeVFSAsyncReadCallback) read_callback, r);
|
|
||||||
}
|
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
e_summary_rdf_update (ESummary *summary)
|
e_summary_rdf_update (ESummary *summary)
|
||||||
{
|
{
|
||||||
@ -439,27 +358,23 @@ e_summary_rdf_update (ESummary *summary)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (r = summary->rdf->rdfs; r; r = r->next) {
|
for (r = summary->rdf->rdfs; r; r = r->next) {
|
||||||
|
SoupContext *context;
|
||||||
RDF *rdf = r->data;
|
RDF *rdf = r->data;
|
||||||
|
|
||||||
if (rdf->handle) {
|
if (rdf->message) {
|
||||||
gnome_vfs_async_cancel (rdf->handle);
|
soup_message_cancel (rdf->message);
|
||||||
rdf->handle = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rdf->buffer) {
|
context = soup_context_get (rdf->uri);
|
||||||
g_free (rdf->buffer);
|
if (context == NULL) {
|
||||||
rdf->buffer = NULL;
|
g_warning ("Invalid URL: %s", rdf->uri);
|
||||||
}
|
soup_context_unref (context);
|
||||||
|
continue;
|
||||||
if (rdf->string) {
|
|
||||||
g_string_free (rdf->string, TRUE);
|
|
||||||
rdf->string = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
g_warning ("Opening %s", rdf->uri);
|
rdf->message = soup_message_new (context, SOUP_METHOD_GET);
|
||||||
gnome_vfs_async_open (&rdf->handle, rdf->uri,
|
soup_context_unref (context);
|
||||||
GNOME_VFS_OPEN_READ,
|
soup_message_queue (rdf->message, message_finished, rdf);
|
||||||
(GnomeVFSAsyncOpenCallback) open_callback, rdf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@ -510,7 +425,7 @@ e_summary_rdf_count (ESummary *summary,
|
|||||||
for (p = rdf->rdfs; p; p = p->next) {
|
for (p = rdf->rdfs; p; p = p->next) {
|
||||||
RDF *r = p->data;
|
RDF *r = p->data;
|
||||||
|
|
||||||
if (r->handle != NULL) {
|
if (r->message != NULL) {
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -541,7 +456,7 @@ e_summary_rdf_add (ESummary *summary,
|
|||||||
for (p = rdf->rdfs; p; p = p->next) {
|
for (p = rdf->rdfs; p; p = p->next) {
|
||||||
RDF *r = p->data;
|
RDF *r = p->data;
|
||||||
|
|
||||||
if (r->handle != NULL) {
|
if (r->message != NULL) {
|
||||||
ESummaryConnectionData *d;
|
ESummaryConnectionData *d;
|
||||||
|
|
||||||
d = make_connection (r);
|
d = make_connection (r);
|
||||||
@ -556,17 +471,12 @@ static void
|
|||||||
rdf_free (RDF *r)
|
rdf_free (RDF *r)
|
||||||
{
|
{
|
||||||
/* Stop the download */
|
/* Stop the download */
|
||||||
if (r->handle) {
|
if (r->message) {
|
||||||
gnome_vfs_async_cancel (r->handle);
|
soup_message_cancel (r->message);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free (r->uri);
|
g_free (r->uri);
|
||||||
g_free (r->html);
|
g_free (r->html);
|
||||||
g_free (r->buffer);
|
|
||||||
|
|
||||||
if (r->string) {
|
|
||||||
g_string_free (r->string, TRUE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (r->cache) {
|
if (r->cache) {
|
||||||
xmlFreeDoc (r->cache);
|
xmlFreeDoc (r->cache);
|
||||||
@ -599,9 +509,9 @@ e_summary_rdf_set_online (ESummary *summary,
|
|||||||
RDF *r;
|
RDF *r;
|
||||||
|
|
||||||
r = p->data;
|
r = p->data;
|
||||||
if (r->handle) {
|
if (r->message) {
|
||||||
gnome_vfs_async_cancel (r->handle);
|
soup_message_cancel (r->message);
|
||||||
r->handle = NULL;
|
r->message = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,8 +136,8 @@ sort_uids (gconstpointer a,
|
|||||||
CalComponent *comp_a, *comp_b;
|
CalComponent *comp_a, *comp_b;
|
||||||
CalClient *client = user_data;
|
CalClient *client = user_data;
|
||||||
CalClientGetStatus status;
|
CalClientGetStatus status;
|
||||||
CalComponentDateTime start_a, start_b;
|
int real_a = 0, real_b = 0;
|
||||||
int retval;
|
int *pri_a, *pri_b;
|
||||||
|
|
||||||
/* a after b then return > 0 */
|
/* a after b then return > 0 */
|
||||||
|
|
||||||
@ -149,20 +149,13 @@ sort_uids (gconstpointer a,
|
|||||||
if (status != CAL_CLIENT_GET_SUCCESS)
|
if (status != CAL_CLIENT_GET_SUCCESS)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
cal_component_get_dtstart (comp_a, &start_a);
|
pri_a = &real_a;
|
||||||
cal_component_get_dtstart (comp_b, &start_b);
|
pri_b = &real_b;
|
||||||
|
|
||||||
if (start_a.value == NULL || start_b.value == NULL) {
|
cal_component_get_priority (comp_a, &pri_a);
|
||||||
/* Try to do something reasonable if one or more of our .values is NULL */
|
cal_component_get_priority (comp_b, &pri_b);
|
||||||
retval = (start_a.value ? 1 : 0) - (start_b.value ? 1 : 0);
|
|
||||||
} else {
|
|
||||||
retval = icaltime_compare (*start_a.value, *start_b.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
cal_component_free_datetime (&start_a);
|
return *pri_a - *pri_b;
|
||||||
cal_component_free_datetime (&start_b);
|
|
||||||
|
|
||||||
return retval;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static GList *
|
static GList *
|
||||||
@ -258,6 +251,7 @@ generate_html (gpointer data)
|
|||||||
} else {
|
} else {
|
||||||
char *s;
|
char *s;
|
||||||
|
|
||||||
|
uids = cal_list_sort (uids, sort_uids, tasks->client);
|
||||||
string = g_string_new ("<dl><dt><img src=\"myevo-post-it.png\" align=\"middle\" "
|
string = g_string_new ("<dl><dt><img src=\"myevo-post-it.png\" align=\"middle\" "
|
||||||
"alt=\"\" width=\"48\" height=\"48\"> <b><a href=\"evolution:/local/Tasks\">");
|
"alt=\"\" width=\"48\" height=\"48\"> <b><a href=\"evolution:/local/Tasks\">");
|
||||||
s = e_utf8_from_locale_string (_("Tasks"));
|
s = e_utf8_from_locale_string (_("Tasks"));
|
||||||
|
@ -34,7 +34,6 @@
|
|||||||
|
|
||||||
#include <gal/widgets/e-unicode.h>
|
#include <gal/widgets/e-unicode.h>
|
||||||
|
|
||||||
#include <libgnomevfs/gnome-vfs.h>
|
|
||||||
#include "e-summary.h"
|
#include "e-summary.h"
|
||||||
#include "e-summary-weather.h"
|
#include "e-summary-weather.h"
|
||||||
#include "weather.h"
|
#include "weather.h"
|
||||||
@ -251,10 +250,10 @@ parse_metar (const char *metar,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
close_callback (GnomeVFSAsyncHandle *handle,
|
message_finished (SoupMessage *msg,
|
||||||
GnomeVFSResult result,
|
gpointer userdata)
|
||||||
Weather *w)
|
|
||||||
{
|
{
|
||||||
|
Weather *w = (Weather *) userdata;
|
||||||
ESummary *summary;
|
ESummary *summary;
|
||||||
char *html, *metar, *end;
|
char *html, *metar, *end;
|
||||||
char *search_str;
|
char *search_str;
|
||||||
@ -265,27 +264,39 @@ close_callback (GnomeVFSAsyncHandle *handle,
|
|||||||
connection->callback (summary, connection->callback_closure);
|
connection->callback (summary, connection->callback_closure);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (w->handle == NULL) {
|
if (SOUP_MESSAGE_IS_ERROR (msg)) {
|
||||||
g_free (w->buffer);
|
GString *string;
|
||||||
w->buffer = NULL;
|
ESummaryWeatherLocation *location;
|
||||||
g_string_free (w->string, TRUE);
|
|
||||||
w->string = NULL;
|
g_warning ("Message failed: %d\n%s", msg->errorcode,
|
||||||
|
msg->errorphrase);
|
||||||
|
w->message = NULL;
|
||||||
|
|
||||||
|
location = g_hash_table_lookup (locations_hash, w->location);
|
||||||
|
|
||||||
|
string = g_string_new ("<br><b>There was an error downloading data for ");
|
||||||
|
if (location == NULL) {
|
||||||
|
g_string_append (string, w->location);
|
||||||
|
} else {
|
||||||
|
g_string_append (string, location->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_string_append (string, "</b><br>");
|
||||||
|
w->html = e_utf8_from_locale_string (string->str);
|
||||||
|
g_string_free (string, TRUE);
|
||||||
|
|
||||||
|
e_summary_draw (w->summary);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
w->handle = NULL;
|
html = g_strdup (msg->response.body);
|
||||||
g_free (w->buffer);
|
w->message = NULL;
|
||||||
w->buffer = NULL;
|
|
||||||
html = w->string->str;
|
|
||||||
g_string_free (w->string, FALSE);
|
|
||||||
w->string = NULL;
|
|
||||||
|
|
||||||
/* Find the metar data */
|
/* Find the metar data */
|
||||||
search_str = g_strdup_printf ("\n%s", w->location);
|
search_str = g_strdup_printf ("\n%s", w->location);
|
||||||
metar = strstr (html, search_str);
|
metar = strstr (html, search_str);
|
||||||
if (metar == NULL) {
|
if (metar == NULL) {
|
||||||
g_free (search_str);
|
g_free (search_str);
|
||||||
g_free (html);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -293,77 +304,15 @@ close_callback (GnomeVFSAsyncHandle *handle,
|
|||||||
end = strchr (metar, '\n');
|
end = strchr (metar, '\n');
|
||||||
if (end == NULL) {
|
if (end == NULL) {
|
||||||
g_free (search_str);
|
g_free (search_str);
|
||||||
g_free (html);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
*end = '\0';
|
*end = '\0';
|
||||||
|
|
||||||
parse_metar (metar, w);
|
parse_metar (metar, w);
|
||||||
g_free (html);
|
|
||||||
g_free (search_str);
|
g_free (search_str);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
read_callback (GnomeVFSAsyncHandle *handle,
|
|
||||||
GnomeVFSResult result,
|
|
||||||
gpointer buffer,
|
|
||||||
GnomeVFSFileSize bytes_requested,
|
|
||||||
GnomeVFSFileSize bytes_read,
|
|
||||||
Weather *w)
|
|
||||||
{
|
|
||||||
if (result != GNOME_VFS_OK && result != GNOME_VFS_ERROR_EOF) {
|
|
||||||
if (w->summary->weather->errorshown == FALSE) {
|
|
||||||
w->html = g_strdup ("<dd><b>An error occurred while downloading weather data</b></dd>");
|
|
||||||
w->summary->weather->errorshown = TRUE;
|
|
||||||
} else {
|
|
||||||
w->html = g_strdup ("<dd> </dd>");
|
|
||||||
}
|
|
||||||
|
|
||||||
e_summary_draw (w->summary);
|
|
||||||
w->handle = NULL;
|
|
||||||
gnome_vfs_async_close (handle,
|
|
||||||
(GnomeVFSAsyncCloseCallback) close_callback, w);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bytes_read == 0) {
|
|
||||||
gnome_vfs_async_close (handle,
|
|
||||||
(GnomeVFSAsyncCloseCallback) close_callback, w);
|
|
||||||
} else {
|
|
||||||
*((char *) buffer + bytes_read) = 0;
|
|
||||||
g_string_append (w->string, (const char *) buffer);
|
|
||||||
gnome_vfs_async_read (handle, buffer, 4095,
|
|
||||||
(GnomeVFSAsyncReadCallback) read_callback, w);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
open_callback (GnomeVFSAsyncHandle *handle,
|
|
||||||
GnomeVFSResult result,
|
|
||||||
Weather *w)
|
|
||||||
{
|
|
||||||
if (result != GNOME_VFS_OK) {
|
|
||||||
if (w->summary->weather->errorshown == FALSE) {
|
|
||||||
w->html = e_utf8_from_locale_string (_("<dd><b>The weather server could not be contacted</b></dd>"));
|
|
||||||
|
|
||||||
w->summary->weather->errorshown = TRUE;
|
|
||||||
} else {
|
|
||||||
w->html = g_strdup ("<dd> </dd>");
|
|
||||||
}
|
|
||||||
|
|
||||||
w->handle = NULL;
|
|
||||||
e_summary_draw (w->summary);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
w->string = g_string_new ("");
|
|
||||||
w->buffer = g_new (char, 4096);
|
|
||||||
|
|
||||||
gnome_vfs_async_read (handle, w->buffer, 4095,
|
|
||||||
(GnomeVFSAsyncReadCallback) read_callback, w);
|
|
||||||
}
|
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
e_summary_weather_update (ESummary *summary)
|
e_summary_weather_update (ESummary *summary)
|
||||||
{
|
{
|
||||||
@ -376,26 +325,28 @@ e_summary_weather_update (ESummary *summary)
|
|||||||
|
|
||||||
summary->weather->errorshown = FALSE;
|
summary->weather->errorshown = FALSE;
|
||||||
for (w = summary->weather->weathers; w; w = w->next) {
|
for (w = summary->weather->weathers; w; w = w->next) {
|
||||||
|
SoupContext *context;
|
||||||
char *uri;
|
char *uri;
|
||||||
Weather *weather = w->data;
|
Weather *weather = w->data;
|
||||||
|
|
||||||
if (weather->handle != NULL) {
|
if (weather->message != NULL) {
|
||||||
gnome_vfs_async_cancel (weather->handle);
|
soup_message_cancel (weather->message);
|
||||||
weather->handle = NULL;
|
weather->message = NULL;
|
||||||
}
|
|
||||||
if (weather->string) {
|
|
||||||
g_string_free (weather->string, TRUE);
|
|
||||||
weather->string = NULL;
|
|
||||||
}
|
|
||||||
if (weather->buffer) {
|
|
||||||
g_free (weather->buffer);
|
|
||||||
weather->buffer = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uri = g_strdup_printf ("http://weather.noaa.gov/cgi-bin/mgetmetar.pl?cccc=%s", weather->location);
|
uri = g_strdup_printf ("http://weather.noaa.gov/cgi-bin/mgetmetar.pl?cccc=%s", weather->location);
|
||||||
|
context = soup_context_get (uri);
|
||||||
|
if (context == NULL) {
|
||||||
|
g_warning ("Invalid URL: %s", uri);
|
||||||
|
soup_context_unref (context);
|
||||||
|
g_free (uri);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
weather->message = soup_message_new (context, SOUP_METHOD_GET);
|
||||||
|
soup_context_unref (context);
|
||||||
|
soup_message_queue (weather->message, message_finished, weather);
|
||||||
|
|
||||||
gnome_vfs_async_open (&weather->handle, uri, GNOME_VFS_OPEN_READ,
|
|
||||||
(GnomeVFSAsyncOpenCallback) open_callback, weather);
|
|
||||||
g_free (uri);
|
g_free (uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -407,14 +358,8 @@ weather_free (Weather *w)
|
|||||||
{
|
{
|
||||||
g_return_if_fail (w != NULL);
|
g_return_if_fail (w != NULL);
|
||||||
|
|
||||||
if (w->handle != NULL) {
|
if (w->message != NULL) {
|
||||||
gnome_vfs_async_cancel (w->handle);
|
soup_message_cancel (w->message);
|
||||||
}
|
|
||||||
if (w->string) {
|
|
||||||
g_string_free (w->string, TRUE);
|
|
||||||
}
|
|
||||||
if (w->buffer) {
|
|
||||||
g_free (w->buffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free (w->location);
|
g_free (w->location);
|
||||||
@ -541,7 +486,7 @@ e_summary_weather_count (ESummary *summary,
|
|||||||
for (p = weather->weathers; p; p = p->next) {
|
for (p = weather->weathers; p; p = p->next) {
|
||||||
Weather *w = p->data;
|
Weather *w = p->data;
|
||||||
|
|
||||||
if (w->handle != NULL) {
|
if (w->message != NULL) {
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -572,7 +517,7 @@ e_summary_weather_add (ESummary *summary,
|
|||||||
for (p = weather->weathers; p; p = p->next) {
|
for (p = weather->weathers; p; p = p->next) {
|
||||||
Weather *w = p->data;
|
Weather *w = p->data;
|
||||||
|
|
||||||
if (w->handle != NULL) {
|
if (w->message != NULL) {
|
||||||
ESummaryConnectionData *d;
|
ESummaryConnectionData *d;
|
||||||
|
|
||||||
d = make_connection (w);
|
d = make_connection (w);
|
||||||
@ -607,9 +552,9 @@ e_summary_weather_set_online (ESummary *summary,
|
|||||||
Weather *w;
|
Weather *w;
|
||||||
|
|
||||||
w = p->data;
|
w = p->data;
|
||||||
if (w->handle) {
|
if (w->message) {
|
||||||
gnome_vfs_async_cancel (w->handle);
|
soup_message_cancel (w->message);
|
||||||
w->handle = NULL;
|
w->message = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +24,12 @@
|
|||||||
#include <config.h>
|
#include <config.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <libgnome/gnome-defs.h>
|
#include <libgnome/gnome-defs.h>
|
||||||
#include <libgnome/gnome-i18n.h>
|
#include <libgnome/gnome-i18n.h>
|
||||||
@ -34,8 +40,6 @@
|
|||||||
#include <gtkhtml/htmlengine.h>
|
#include <gtkhtml/htmlengine.h>
|
||||||
#include <gtkhtml/htmlselection.h>
|
#include <gtkhtml/htmlselection.h>
|
||||||
|
|
||||||
#include <libgnomevfs/gnome-vfs.h>
|
|
||||||
|
|
||||||
#include <gal/util/e-util.h>
|
#include <gal/util/e-util.h>
|
||||||
#include <gal/widgets/e-gui-utils.h>
|
#include <gal/widgets/e-gui-utils.h>
|
||||||
#include <gal/widgets/e-unicode.h>
|
#include <gal/widgets/e-unicode.h>
|
||||||
@ -77,13 +81,6 @@ struct _ESummaryMailFolderInfo {
|
|||||||
int unread;
|
int unread;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct _DownloadInfo {
|
|
||||||
GtkHTMLStream *stream;
|
|
||||||
char *uri;
|
|
||||||
char *buffer, *ptr;
|
|
||||||
guint32 bufsize;
|
|
||||||
} DownloadInfo;
|
|
||||||
|
|
||||||
struct _ESummaryPrivate {
|
struct _ESummaryPrivate {
|
||||||
GNOME_Evolution_Shell shell;
|
GNOME_Evolution_Shell shell;
|
||||||
GNOME_Evolution_ShellView shell_view_interface;
|
GNOME_Evolution_ShellView shell_view_interface;
|
||||||
@ -289,74 +286,6 @@ struct _imgcache {
|
|||||||
int bufsize;
|
int bufsize;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
|
||||||
close_callback (GnomeVFSAsyncHandle *handle,
|
|
||||||
GnomeVFSResult result,
|
|
||||||
gpointer data)
|
|
||||||
{
|
|
||||||
DownloadInfo *info = data;
|
|
||||||
struct _imgcache *img;
|
|
||||||
|
|
||||||
if (images_cache == NULL) {
|
|
||||||
images_cache = g_hash_table_new (g_str_hash, g_str_equal);
|
|
||||||
}
|
|
||||||
|
|
||||||
img = g_new (struct _imgcache, 1);
|
|
||||||
img->buffer = info->buffer;
|
|
||||||
img->bufsize = info->bufsize;
|
|
||||||
|
|
||||||
g_hash_table_insert (images_cache, info->uri, img);
|
|
||||||
g_free (info);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* The way this behaves is a workaround for ximian bug 10235: loading
|
|
||||||
* the image into gtkhtml progressively will result in garbage being
|
|
||||||
* drawn, so we wait until we've read the whole thing and then write
|
|
||||||
* it all at once.
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
read_callback (GnomeVFSAsyncHandle *handle,
|
|
||||||
GnomeVFSResult result,
|
|
||||||
gpointer buffer,
|
|
||||||
GnomeVFSFileSize bytes_requested,
|
|
||||||
GnomeVFSFileSize bytes_read,
|
|
||||||
gpointer data)
|
|
||||||
{
|
|
||||||
DownloadInfo *info = data;
|
|
||||||
|
|
||||||
if (result != GNOME_VFS_OK && result != GNOME_VFS_ERROR_EOF) {
|
|
||||||
gtk_html_stream_close (info->stream, GTK_HTML_STREAM_ERROR);
|
|
||||||
gnome_vfs_async_close (handle, close_callback, info);
|
|
||||||
} else if (bytes_read == 0) {
|
|
||||||
gtk_html_stream_write (info->stream, info->buffer, info->bufsize);
|
|
||||||
gtk_html_stream_close (info->stream, GTK_HTML_STREAM_OK);
|
|
||||||
gnome_vfs_async_close (handle, close_callback, info);
|
|
||||||
} else {
|
|
||||||
bytes_read += info->ptr - info->buffer;
|
|
||||||
info->bufsize += 4096;
|
|
||||||
info->buffer = g_realloc (info->buffer, info->bufsize);
|
|
||||||
info->ptr = info->buffer + bytes_read;
|
|
||||||
gnome_vfs_async_read (handle, info->ptr, 4095, read_callback, info);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
open_callback (GnomeVFSAsyncHandle *handle,
|
|
||||||
GnomeVFSResult result,
|
|
||||||
DownloadInfo *info)
|
|
||||||
{
|
|
||||||
if (result != GNOME_VFS_OK) {
|
|
||||||
gtk_html_stream_close (info->stream, GTK_HTML_STREAM_ERROR);
|
|
||||||
g_free (info->uri);
|
|
||||||
g_free (info);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
info->bufsize = 4096;
|
|
||||||
info->buffer = info->ptr = g_new (char, info->bufsize);
|
|
||||||
gnome_vfs_async_read (handle, info->buffer, 4095, read_callback, info);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
e_summary_url_clicked (GtkHTML *html,
|
e_summary_url_clicked (GtkHTML *html,
|
||||||
const char *url,
|
const char *url,
|
||||||
@ -387,6 +316,52 @@ e_summary_url_clicked (GtkHTML *html,
|
|||||||
protocol_listener->listener (summary, url, protocol_listener->closure);
|
protocol_listener->listener (summary, url, protocol_listener->closure);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char *
|
||||||
|
e_read_file_with_length (const char *filename,
|
||||||
|
size_t *length)
|
||||||
|
{
|
||||||
|
int fd, ret;
|
||||||
|
struct stat stat_buf;
|
||||||
|
char *buf;
|
||||||
|
size_t bytes_read, size;
|
||||||
|
|
||||||
|
g_return_val_if_fail (filename != NULL, NULL);
|
||||||
|
|
||||||
|
fd = open (filename, O_RDONLY);
|
||||||
|
g_return_val_if_fail (fd != -1, NULL);
|
||||||
|
|
||||||
|
fstat (fd, &stat_buf);
|
||||||
|
size = stat_buf.st_size;
|
||||||
|
buf = g_new (char, size + 1);
|
||||||
|
|
||||||
|
bytes_read = 0;
|
||||||
|
while (bytes_read < size) {
|
||||||
|
ssize_t rc;
|
||||||
|
|
||||||
|
rc = read (fd, buf + bytes_read, size - bytes_read);
|
||||||
|
if (rc < 0) {
|
||||||
|
if (errno != EINTR) {
|
||||||
|
close (fd);
|
||||||
|
g_free (buf);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
} else if (rc == 0) {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
bytes_read += rc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
buf[bytes_read] = '\0';
|
||||||
|
|
||||||
|
if (length) {
|
||||||
|
*length = bytes_read;
|
||||||
|
}
|
||||||
|
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
e_summary_url_requested (GtkHTML *html,
|
e_summary_url_requested (GtkHTML *html,
|
||||||
const char *url,
|
const char *url,
|
||||||
@ -394,8 +369,6 @@ e_summary_url_requested (GtkHTML *html,
|
|||||||
ESummary *summary)
|
ESummary *summary)
|
||||||
{
|
{
|
||||||
char *filename;
|
char *filename;
|
||||||
GnomeVFSAsyncHandle *handle;
|
|
||||||
DownloadInfo *info;
|
|
||||||
struct _imgcache *img = NULL;
|
struct _imgcache *img = NULL;
|
||||||
|
|
||||||
if (strncasecmp (url, "file:", 5) == 0) {
|
if (strncasecmp (url, "file:", 5) == 0) {
|
||||||
@ -414,19 +387,28 @@ e_summary_url_requested (GtkHTML *html,
|
|||||||
|
|
||||||
if (images_cache != NULL) {
|
if (images_cache != NULL) {
|
||||||
img = g_hash_table_lookup (images_cache, filename);
|
img = g_hash_table_lookup (images_cache, filename);
|
||||||
|
} else {
|
||||||
|
images_cache = g_hash_table_new (g_str_hash, g_str_equal);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (img == NULL) {
|
if (img == NULL) {
|
||||||
info = g_new (DownloadInfo, 1);
|
size_t length;
|
||||||
info->stream = stream;
|
char *contents;
|
||||||
info->uri = filename;
|
|
||||||
|
|
||||||
gnome_vfs_async_open (&handle, filename, GNOME_VFS_OPEN_READ,
|
contents = e_read_file_with_length (filename, &length);
|
||||||
(GnomeVFSAsyncOpenCallback) open_callback, info);
|
if (contents == NULL) {
|
||||||
} else {
|
return;
|
||||||
gtk_html_stream_write (stream, img->buffer, img->bufsize);
|
}
|
||||||
gtk_html_stream_close (stream, GTK_HTML_STREAM_OK);
|
|
||||||
|
img = g_new (struct _imgcache, 1);
|
||||||
|
img->buffer = contents;
|
||||||
|
img->bufsize = length;
|
||||||
|
|
||||||
|
g_hash_table_insert (images_cache, g_strdup (filename), img);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gtk_html_stream_write (stream, img->buffer, img->bufsize);
|
||||||
|
gtk_html_stream_close (stream, GTK_HTML_STREAM_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -43,7 +43,6 @@
|
|||||||
#include <gconf/gconf.h>
|
#include <gconf/gconf.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <libgnomevfs/gnome-vfs.h>
|
|
||||||
#include <glade/glade.h>
|
#include <glade/glade.h>
|
||||||
|
|
||||||
#include "component-factory.h"
|
#include "component-factory.h"
|
||||||
@ -72,7 +71,6 @@ main (int argc,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
glade_gnome_init ();
|
glade_gnome_init ();
|
||||||
gnome_vfs_init ();
|
|
||||||
|
|
||||||
gtk_widget_push_visual (gdk_rgb_get_visual ());
|
gtk_widget_push_visual (gdk_rgb_get_visual ());
|
||||||
gtk_widget_push_colormap (gdk_rgb_get_cmap ());
|
gtk_widget_push_colormap (gdk_rgb_get_cmap ());
|
||||||
|
@ -25,14 +25,13 @@
|
|||||||
|
|
||||||
#include "e-summary-weather.h"
|
#include "e-summary-weather.h"
|
||||||
|
|
||||||
#include <libgnomevfs/gnome-vfs.h>
|
#include <libsoup/soup.h>
|
||||||
|
|
||||||
typedef struct _Weather {
|
typedef struct _Weather {
|
||||||
char *location;
|
char *location;
|
||||||
char *html;
|
char *html;
|
||||||
GnomeVFSAsyncHandle *handle;
|
|
||||||
GString *string;
|
SoupMessage *message;
|
||||||
char *buffer;
|
|
||||||
|
|
||||||
ESummary *summary;
|
ESummary *summary;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user