aboutsummaryrefslogtreecommitdiffstats
path: root/executive-summary/test-service/rdf-summary.c
diff options
context:
space:
mode:
Diffstat (limited to 'executive-summary/test-service/rdf-summary.c')
-rw-r--r--executive-summary/test-service/rdf-summary.c160
1 files changed, 108 insertions, 52 deletions
diff --git a/executive-summary/test-service/rdf-summary.c b/executive-summary/test-service/rdf-summary.c
index a2a01aa541..a1aca7d88b 100644
--- a/executive-summary/test-service/rdf-summary.c
+++ b/executive-summary/test-service/rdf-summary.c
@@ -50,6 +50,9 @@ struct _RdfSummary {
char *icon;
char *location;
int limit;
+
+ GString *str;
+ char *buffer;
};
typedef struct _RdfSummary RdfSummary;
@@ -283,79 +286,131 @@ view_destroyed (GtkObject *object,
}
}
-static int
-download (RdfSummary *summary)
+static void
+close_callback (GnomeVFSAsyncHandle *handle,
+ GnomeVFSResult result,
+ RdfSummary *summary)
{
- ExecutiveSummaryHtmlView *view;
- GString *rdf;
GString *html;
- char *xml;
- GnomeVFSHandle *handle = NULL;
- GnomeVFSResult result;
xmlDocPtr doc;
- char *location;
- int len = 0;
+ char *xml;
+
+ if (summary == NULL)
+ return;
- /* Download the RDF file here */
- /* Then parse it */
- /* The update it */
+ g_free (summary->buffer);
+ xml = summary->str->str;
+ g_string_free (summary->str, FALSE);
- g_print ("Starting download\n");
- view = EXECUTIVE_SUMMARY_HTML_VIEW (summary->view);
- result = gnome_vfs_open (&handle, summary->location,
- GNOME_VFS_OPEN_READ);
- if (result != GNOME_VFS_OK) {
+ doc = xmlParseMemory (xml, strlen (xml));
+ if (doc == NULL) {
char *emsg;
+ BonoboArg *arg;
+ arg = bonobo_arg_new (BONOBO_ARG_STRING);
+ BONOBO_ARG_SET_STRING (arg, _("Error"));
+ bonobo_property_bag_set_value (summary->bag,
+ "window_title",
+ (const BonoboArg *) arg,
+ NULL);
+ bonobo_arg_release (arg);
+
emsg = g_strdup_printf ("<b>Cannot open location:<br>%s</b>",
summary->location);
- executive_summary_html_view_set_html (view, emsg);
+ executive_summary_html_view_set_html (EXECUTIVE_SUMMARY_HTML_VIEW (summary->view), emsg);
g_free (emsg);
- return FALSE;
+ g_free (xml);
+ return;
}
+
+ g_free (xml);
+ html = g_string_new ("");
- rdf = g_string_new ("");
+ tree_walk (doc->root, summary, html);
+ executive_summary_html_view_set_html (EXECUTIVE_SUMMARY_HTML_VIEW (summary->view), html->str);
+ g_string_free (html, TRUE);
+}
- while (1) {
- char buffer[4096];
- GnomeVFSFileSize size;
+static void
+read_callback (GnomeVFSAsyncHandle *handle,
+ GnomeVFSResult result,
+ gpointer buffer,
+ GnomeVFSFileSize bytes_requested,
+ GnomeVFSFileSize bytes_read,
+ RdfSummary *summary)
+{
+ if (result != GNOME_VFS_OK && result != GNOME_VFS_ERROR_EOF) {
+ char *emsg;
+ BonoboArg *arg;
+
+ arg = bonobo_arg_new (BONOBO_ARG_STRING);
+ BONOBO_ARG_SET_STRING (arg, _("Error"));
+ bonobo_property_bag_set_value (summary->bag,
+ "window_title",
+ (const BonoboArg *) arg,
+ NULL);
+ bonobo_arg_release (arg);
+
+ emsg = g_strdup_printf ("<b>Cannot open location:<br>%s</b>",
+ summary->location);
+ executive_summary_html_view_set_html (EXECUTIVE_SUMMARY_HTML_VIEW (summary->view), emsg);
+ g_free (emsg);
+ gnome_vfs_async_close (handle, close_callback, NULL);
+ }
- memset (buffer, 0x00, 4096);
+ if (bytes_read == 0) {
+ /* EOF */
+ gnome_vfs_async_close (handle, close_callback, summary);
+ } else {
+ *((char *) buffer + bytes_read) = 0;
+ g_string_append (summary->str, (const char *) buffer);
+ gnome_vfs_async_read (handle, buffer, 4095, read_callback,
+ summary);
+ }
+}
- result = gnome_vfs_read (handle, buffer, 4096, &size);
- if (result != GNOME_VFS_OK && result != GNOME_VFS_ERROR_EOF) {
- executive_summary_html_view_set_html (view,
- "<b>Error reading data.</b>");
- g_string_free (rdf, TRUE);
- return FALSE;
- }
+static void
+open_callback (GnomeVFSAsyncHandle *handle,
+ GnomeVFSResult result,
+ RdfSummary *summary)
+{
+ GList *uri;
+ char *buffer;
- if (size == 0) {
- break;
- }
+ if (result != GNOME_VFS_OK) {
+ char *emsg;
+ BonoboArg *arg;
- rdf = g_string_append (rdf, buffer);
- len += size;
+ arg = bonobo_arg_new (BONOBO_ARG_STRING);
+ BONOBO_ARG_SET_STRING (arg, _("Error"));
+ bonobo_property_bag_set_value (summary->bag,
+ "window_title",
+ (const BonoboArg *) arg,
+ NULL);
+ bonobo_arg_release (arg);
+
+ emsg = g_strdup_printf ("<b>Cannot open location:<br>%s</b>",
+ summary->location);
+ executive_summary_html_view_set_html (EXECUTIVE_SUMMARY_HTML_VIEW (summary->view), emsg);
+ g_free (emsg);
+ return;
}
- gnome_vfs_close (handle);
- xml = rdf->str;
- g_string_free (rdf, FALSE);
+ summary->str = g_string_new ("");
+ summary->buffer = g_new (char, 4096);
- doc = xmlParseMemory (xml, len);
- if (doc == NULL) {
- g_warning ("Unable to parse document.");
- return FALSE;
- }
-
- g_free (xml);
- html = g_string_new ("");
+ gnome_vfs_async_read (handle, summary->buffer, 4095, read_callback, summary);
+}
- tree_walk (doc->root, summary, html);
- executive_summary_html_view_set_html (view, html->str);
- g_string_free (html, TRUE);
+static int
+download (RdfSummary *summary)
+{
+ GnomeVFSAsyncHandle *handle;
+
+ gnome_vfs_async_open (&handle, summary->location, GNOME_VFS_OPEN_READ,
+ (GnomeVFSAsyncOpenCallback) open_callback,
+ summary);
- g_print ("Finished Download\n");
return FALSE;
}
@@ -527,7 +582,8 @@ create_view (ExecutiveSummaryComponentFactory *_factory,
html);
bonobo_object_add_interface (component, view);
- bag = bonobo_property_bag_new (get_prop, set_prop, summary);
+ bag = bonobo_property_bag_new_full (get_prop, set_prop,
+ event_source, summary);
summary->bag = bag;
bonobo_property_bag_add (bag,
"window_title", PROPERTY_TITLE,