diff options
author | Iain Holmes <iain@src.gnome.org> | 2000-12-27 08:03:11 +0800 |
---|---|---|
committer | Iain Holmes <iain@src.gnome.org> | 2000-12-27 08:03:11 +0800 |
commit | 3e5f3687c7460009c93e876ae0ab7eb0e2a71648 (patch) | |
tree | b5c0e1743e85852038f5ad023616a7f89637e31e /executive-summary/test-service | |
parent | 138e45cc665e70e637652eca1cae64ddf7e3b979 (diff) | |
download | gsoc2013-evolution-3e5f3687c7460009c93e876ae0ab7eb0e2a71648.tar.gz gsoc2013-evolution-3e5f3687c7460009c93e876ae0ab7eb0e2a71648.tar.zst gsoc2013-evolution-3e5f3687c7460009c93e876ae0ab7eb0e2a71648.zip |
More fixes for new bonobo
pt 2
svn path=/trunk/; revision=7178
Diffstat (limited to 'executive-summary/test-service')
-rw-r--r-- | executive-summary/test-service/main.c | 10 | ||||
-rw-r--r-- | executive-summary/test-service/rdf-summary.c | 160 |
2 files changed, 116 insertions, 54 deletions
diff --git a/executive-summary/test-service/main.c b/executive-summary/test-service/main.c index 2a3b25975c..d2d35e9c96 100644 --- a/executive-summary/test-service/main.c +++ b/executive-summary/test-service/main.c @@ -176,6 +176,7 @@ create_view (ExecutiveSummaryComponentFactory *_factory, BonoboObject *component, *view; BonoboPersistStream *stream; BonoboPropertyBag *bag; + BonoboEventSource *event_source; UserData *ud; /* Create the component object */ @@ -201,8 +202,12 @@ create_view (ExecutiveSummaryComponentFactory *_factory, ii) Use bonobo_object_add_interface (). */ + /* Create an event source to share with all the interfaces, + as we can only aggregate one onto the ExecutiveSummaryComponent */ + event_source = bonobo_event_source_new (); + /* The Summary::HTMLView interface */ - view = executive_summary_html_view_new (); + view = executive_summary_html_view_new_full (event_source); /* Set the default HTML */ executive_summary_html_view_set_html (EXECUTIVE_SUMMARY_HTML_VIEW (view), "<B>Hello World</b>"); @@ -210,7 +215,8 @@ create_view (ExecutiveSummaryComponentFactory *_factory, bonobo_object_add_interface (component, view); /* Add the Bonobo::PropertyBag interface */ - bag = bonobo_property_bag_new (get_property, set_property, ud); + bag = bonobo_property_bag_new_full (get_property, set_property, + event_source, ud); /* Add the properties. There should be 2: window_title: For the window title. window_icon: For the window icon. 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, |