aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--executive-summary/ChangeLog22
-rw-r--r--executive-summary/component/e-summary-url.c117
-rw-r--r--executive-summary/component/e-summary.c103
-rw-r--r--executive-summary/component/e-summary.h4
-rw-r--r--executive-summary/summary.html6
-rw-r--r--executive-summary/test-service/main.c10
-rw-r--r--executive-summary/test-service/rdf-summary.c160
7 files changed, 286 insertions, 136 deletions
diff --git a/executive-summary/ChangeLog b/executive-summary/ChangeLog
index 24e69d56c0..696d21010a 100644
--- a/executive-summary/ChangeLog
+++ b/executive-summary/ChangeLog
@@ -1,3 +1,25 @@
+2000-12-26 Iain Holmes <iain@helixcode.com>
+
+ * component/e-summary.c (make_control_html): Neatened the code.
+ (e_summary_add_service): Get the event source that is shared
+ between everything.
+
+ * component/e-summary-url.c (e_summary_url_click): Use the shared
+ event source.
+
+ * test-service/rdf-summary.c (create_view): Use the EventSource when
+ creating the BonoboPropertyBag.
+
+ * test-service/main.c (create_view): Create a shared BonoboEventSource.
+
+2000-12-21 Iain Holmes <iain@helixcode.com>
+
+ * test-service/rdf-summary.c (download): Split this function into
+ many callbacks, for async action.
+
+ * component/e-summary-url.c (e_summary_url_request): Split this
+ into async callbacks too.
+
2000-12-13 Christopher James Lahey <clahey@helixcode.com>
* component/e-summary-callbacks.c (configure_summary): Added a
diff --git a/executive-summary/component/e-summary-url.c b/executive-summary/component/e-summary-url.c
index c3be19ab78..a997184e42 100644
--- a/executive-summary/component/e-summary-url.c
+++ b/executive-summary/component/e-summary-url.c
@@ -81,18 +81,97 @@ typedef struct _PropertyDialog {
} PropertyDialog;
#define COMPOSER_IID "OAFIID:GNOME_Evolution_Mail_Composer"
+#if HAVECACHE
+static ESummaryCache *image_cache = NULL;
+#endif
+
+#define USE_ASYNC
+
gboolean e_summary_url_mail_compose (ESummary *esummary,
const char *url);
gboolean e_summary_url_exec (const char *exec);
+struct _DownloadInfo {
+ GtkHTMLStream *stream;
+ char *uri;
+ char *buffer;
+
+ gboolean error;
+};
+typedef struct _DownloadInfo DownloadInfo;
+
+#ifdef USE_ASYNC
+
+static void
+close_callback (GnomeVFSAsyncHandle *handle,
+ GnomeVFSResult result,
+ DownloadInfo *info)
+{
+ if (info->error) {
+ gtk_html_stream_close (info->stream, GTK_HTML_STREAM_ERROR);
+ } else {
+ gtk_html_stream_close (info->stream, GTK_HTML_STREAM_OK);
+ }
+
+ g_free (info->uri);
+ g_free (info->buffer);
+ g_free (info);
+}
+
+static void
+read_callback (GnomeVFSAsyncHandle *handle,
+ GnomeVFSResult result,
+ gpointer buffer,
+ GnomeVFSFileSize bytes_requested,
+ GnomeVFSFileSize bytes_read,
+ DownloadInfo *info)
+{
+ if (result != GNOME_VFS_OK && result != GNOME_VFS_ERROR_EOF) {
+ g_warning ("Read error");
+ info->error = TRUE;
+ gnome_vfs_async_close (handle, close_callback, info);
+ }
+
+ if (bytes_read == 0) {
+ info->error = FALSE;
+ gnome_vfs_async_close (handle, close_callback, info);
+ } else {
+ gtk_html_stream_write (info->stream, buffer, bytes_read);
+ gnome_vfs_async_read (handle, buffer, 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->buffer = g_new (char, 4096);
+ gnome_vfs_async_read (handle, info->buffer, 4095, read_callback, info);
+}
+#endif
+
void
e_summary_url_request (GtkHTML *html,
const gchar *url,
GtkHTMLStream *stream)
{
char *filename;
+#ifndef USE_ASYNC
GnomeVFSHandle *handle = NULL;
GnomeVFSResult result;
+#else
+ GnomeVFSAsyncHandle *handle;
+ DownloadInfo *info;
+#endif
if (strncasecmp (url, "file:", 5) == 0) {
url += 5;
@@ -108,6 +187,7 @@ e_summary_url_request (GtkHTML *html,
}
g_print ("Filename: %s\n", filename);
+#ifndef USE_ASYNC
result = gnome_vfs_open (&handle, filename, GNOME_VFS_OPEN_READ);
if (result != GNOME_VFS_OK) {
@@ -142,6 +222,16 @@ e_summary_url_request (GtkHTML *html,
gtk_html_stream_close (stream, GTK_HTML_STREAM_OK);
gnome_vfs_close (handle);
+#else
+ info = g_new (DownloadInfo, 1);
+ info->stream = stream;
+ info->uri = filename;
+ info->error = FALSE;
+
+ gnome_vfs_async_open (&handle, filename, GNOME_VFS_OPEN_READ,
+ (GnomeVFSAsyncOpenCallback) open_callback, info);
+#endif
+
}
static char *
@@ -443,9 +533,7 @@ e_summary_url_click (GtkWidget *widget,
data->dialog = prefsbox;
CORBA_exception_init (&ev);
- data->eventsource = Bonobo_Unknown_queryInterface (window->propertycontrol,
- "IDL:Bonobo/EventSource:1.0",
- &ev);
+ data->eventsource = bonobo_object_dup_ref (window->event_source, &ev);
data->listener = bonobo_listener_new (property_event, data);
data->corba_listener = bonobo_object_corba_objref (BONOBO_OBJECT (data->listener));
Bonobo_EventSource_addListener (data->eventsource,
@@ -746,3 +834,26 @@ e_summary_url_over (GtkHTML *html,
e_summary_unset_message (esummary);
}
}
+
+/* Cache stuff */
+#if HAVECACHE
+void
+e_summary_url_init_cache (void)
+{
+ if (image_cache != NULL)
+ return;
+
+ image_cache = e_summary_cache_new ();
+}
+
+void
+e_summary_url_cache_destroy (void)
+{
+ if (image_cache == NULL)
+ return;
+
+ gtk_object_unref (GTK_OBJECT (image_cache));
+
+ image_cache = NULL;
+}
+#endif
diff --git a/executive-summary/component/e-summary.c b/executive-summary/component/e-summary.c
index ef95c7e8b1..12ed32376e 100644
--- a/executive-summary/component/e-summary.c
+++ b/executive-summary/component/e-summary.c
@@ -337,25 +337,13 @@ make_control_html (ESummaryWindow *window,
{
char *html, *tmp;
int id = GPOINTER_TO_INT (window);
- gboolean u, d, l, r, config;
+ gboolean config;
- u = d = l = r = config = TRUE;
+ config = TRUE;
if (window->propertycontrol == CORBA_OBJECT_NIL)
config = FALSE;
- if (row == 0) /* Top row */
- u = FALSE;
-
- if (row >= numwindows - 3) /* Bottom row */
- d = FALSE;
-
- if (col == 0) /* Leftmost column */
- l = FALSE;
-
- if (col == 2 || ((row * 3) + col) == numwindows - 1) /* Rightmost column */
- r = FALSE;
-
html = g_strdup_printf ("<table><tr><td><a href=\"close://%d\">"
"<img src=\"service-close.png\" border=\"0\">"
"</a></td></tr><tr><td>", id);
@@ -371,53 +359,6 @@ make_control_html (ESummaryWindow *window,
}
g_free (tmp);
-#if 0
- tmp = html;
- if (!l) {
- html = g_strdup_printf ("%s<img src=\"service-left-disabled.png\">"
- "</td><td>", tmp);
- } else {
- html = g_strdup_printf ("%s<a href=\"left://%d\">"
- "<img src=\"service-left.png\" border=\"0\">"
- "</a></td><td>", tmp, id);
- }
- g_free (tmp);
-
- tmp = html;
- if (!r) {
- html = g_strdup_printf ("%s<img src=\"service-right-disabled.png\">"
- "</td></tr></table>", tmp);
- } else {
- html = g_strdup_printf ("%s<a href=\"right://%d\">"
- "<img src=\"service-right.png\" border=\"0\">"
- "</a></td></tr></table>", tmp, id);
- }
- g_free (tmp);
-
-
- tmp = html;
- if (!d) {
- html = g_strdup_printf ("%s<img src=\"service-down-disabled.png\">"
- "</td><td>", tmp);
- } else {
- html = g_strdup_printf ("%s<a href=\"down://%d\">"
- "<img src=\"service-down.png\" border=\"0\">"
- "</a></td><td>", tmp, id);
- }
- g_free (tmp);
-
- tmp = html;
- if (!u) {
- html = g_strdup_printf ("%s<img src=\"service-up-disabled.png\">"
- "</td></tr></table>", tmp);
- } else {
- html = g_strdup_printf ("%s<a href=\"up://%d\">"
- "<img src=\"service-up.png\" border=\"0\">"
- "</a></td></tr></table>", tmp, id);
- }
- g_free (tmp);
-
-#endif
return html;
}
@@ -648,9 +589,10 @@ html_event (BonoboListener *listener,
}
static void
-prop_changed_cb (BonoboPropertyListener *listener,
+prop_changed_cb (BonoboListener *listener,
char *name,
BonoboArg *arg,
+ CORBA_Environment *ev,
ESummaryWindow *window)
{
if (strcmp (name, "window_title") == 0) {
@@ -678,7 +620,6 @@ e_summary_add_service (ESummary *esummary,
ESummaryWindow *window;
ESummaryPrivate *priv;
Bonobo_Unknown unknown = CORBA_OBJECT_NIL;
- Bonobo_PropertyListener corba_listener;
CORBA_Environment ev;
g_return_val_if_fail (esummary != NULL, NULL);
@@ -718,6 +659,16 @@ e_summary_add_service (ESummary *esummary,
return NULL;
}
+ window->event_source = Bonobo_Unknown_queryInterface(window->component,
+ "IDL:Bonobo/EventSource:1.0", &ev);
+ if (window->event_source == CORBA_OBJECT_NIL) {
+ g_warning ("There is no Bonobo::EventSource interface");
+
+ /* FIXME: Free whatever objects exist */
+ g_free (window);
+ return NULL;
+ }
+
if (window->html != CORBA_OBJECT_NIL) {
Bonobo_Listener listener;
CORBA_Environment ev2;
@@ -762,19 +713,21 @@ e_summary_add_service (ESummary *esummary,
window->propertybag,
"window_icon", NULL));
/* Listen to changes */
- window->listener = bonobo_property_listener_new ();
- gtk_signal_connect (GTK_OBJECT (window->listener), "prop_changed",
- GTK_SIGNAL_FUNC (prop_changed_cb), window);
- corba_listener = bonobo_object_corba_objref (BONOBO_OBJECT (window->listener));
- Bonobo_PropertyBag_addChangeListener (window->propertybag,
- "window_title",
- corba_listener, &ev);
-
- Bonobo_PropertyBag_addChangeListener (window->propertybag,
- "window_icon",
- corba_listener, &ev);
- CORBA_exception_free (&ev);
+ if (window->propertycontrol != CORBA_OBJECT_NIL) {
+ Bonobo_Listener listener;
+ CORBA_Environment ev2;
+
+ window->listener = bonobo_listener_new (NULL, NULL);
+ listener = bonobo_object_corba_objref (BONOBO_OBJECT (window->html_listener));
+ Bonobo_EventSource_addListener (window->event_source,
+ listener, &ev);
+
+ gtk_signal_connect (GTK_OBJECT (window->listener), "event_notify",
+ GTK_SIGNAL_FUNC (prop_changed_cb), window);
+ }
+
+ CORBA_exception_free (&ev);
priv->window_list = g_list_append (priv->window_list, window);
return window;
diff --git a/executive-summary/component/e-summary.h b/executive-summary/component/e-summary.h
index 8d80b70939..3ac6b1eaeb 100644
--- a/executive-summary/component/e-summary.h
+++ b/executive-summary/component/e-summary.h
@@ -54,9 +54,11 @@ struct _ESummaryWindow {
Bonobo_PersistStream persiststream;
Bonobo_PropertyBag propertybag;
Bonobo_PropertyControl propertycontrol;
+ Bonobo_EventSource property_event_source;
Bonobo_EventSource event_source;
+
- BonoboPropertyListener *listener;
+ BonoboListener *listener;
BonoboListener *html_listener;
Bonobo_Listener html_corba_listener;
diff --git a/executive-summary/summary.html b/executive-summary/summary.html
index ba23111e81..d7e68d7921 100644
--- a/executive-summary/summary.html
+++ b/executive-summary/summary.html
@@ -13,11 +13,11 @@ E V O L U T I O N
</td></tr>
<tr><td bgcolor="#9aadbf">&nbsp;</td>
<td><img src="executive-summary-curve.png"></td>
-<td align="left">
+<td width="100%" align="left">
<table>
<tr>
-<td align="middle">Search on Google: </td>
-<td align="middle"><form method="get" action="/search" name="f"><input type="text" size="15" name=q></form></td>
+<td valign="middle">Search on Google: </td>
+<td valign="middle"><form method="get" action="/search" name="f"><input type="text" size="15" name=q></form></td>
</tr>
</table>
</td>
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,