r18007 - gnucash/branches/webkit - 1) Add configuration option --enable-webkit. If specified, webkit will replace gtkhtml

Phil Longstaff plongstaff at code.gnucash.org
Mon Mar 30 19:02:28 EDT 2009


Author: plongstaff
Date: 2009-03-30 19:02:28 -0400 (Mon, 30 Mar 2009)
New Revision: 18007
Trac: http://svn.gnucash.org/trac/changeset/18007

Modified:
   gnucash/branches/webkit/configure.in
   gnucash/branches/webkit/src/html/Makefile.am
   gnucash/branches/webkit/src/html/gnc-html-factory.c
   gnucash/branches/webkit/src/html/gnc-html-graph-gog-webkit.c
   gnucash/branches/webkit/src/html/gnc-html-graph-gog.c
   gnucash/branches/webkit/src/html/gnc-html-gtkhtml.c
   gnucash/branches/webkit/src/html/gnc-html-gtkmozembed.c
   gnucash/branches/webkit/src/html/gnc-html-webkit.c
   gnucash/branches/webkit/src/html/gnc-html.c
   gnucash/branches/webkit/src/html/gnc-html.h
Log:
1) Add configuration option --enable-webkit.  If specified, webkit will replace gtkhtml
for report/chart rendering
2) Get webkit printing working.  NOTE: there is no public api function to print.  There is
a private to-be-released api.  Printing works by getting the function address from
/usr/include/libwebkit-1.0.so and using it.  This is not very portable or maintainable, but
it works for now.
3) Replace temporary chart image files with internal base64 string



Modified: gnucash/branches/webkit/configure.in
===================================================================
--- gnucash/branches/webkit/configure.in	2009-03-29 15:44:11 UTC (rev 18006)
+++ gnucash/branches/webkit/configure.in	2009-03-30 23:02:28 UTC (rev 18007)
@@ -515,7 +515,20 @@
 ### --------------------------------------------------------------------------
 ### look for webkit
 
-PKG_CHECK_MODULES(WEBKIT, webkit-1.0 >= "1.0")
+AC_ARG_ENABLE(webkit,
+  [AS_HELP_STRING([--enable-webkit],[build with the webkit HTML engine])],
+  [case "${enableval}" in
+     yes) want_webkit=true ;;
+     no)  want_webkit=false ;;
+     *) want_webkit=false ;;
+   esac],
+   [want_webkit=false])
+if test x${want_webkit} = xtrue
+then
+  PKG_CHECK_MODULES(WEBKIT, webkit-1.0 >= "1.0")
+  AC_DEFINE(WANT_WEBKIT,1,[Use webkit instead of gtkhtml])
+fi
+AM_CONDITIONAL(HTML_USING_WEBKIT, test x${want_webkit} = xtrue)
 AC_SUBST(WEBKIT_CFLAGS)
 AC_SUBST(WEBKIT_LIBS)
 

Modified: gnucash/branches/webkit/src/html/Makefile.am
===================================================================
--- gnucash/branches/webkit/src/html/Makefile.am	2009-03-29 15:44:11 UTC (rev 18006)
+++ gnucash/branches/webkit/src/html/Makefile.am	2009-03-30 23:02:28 UTC (rev 18007)
@@ -5,6 +5,7 @@
 
 # Note that src/gnome-utils CANNOT depend on src/gnome!
 
+if HTML_USING_WEBKIT
 AM_CPPFLAGS = \
   -I${top_srcdir}/src/core-utils \
   -I${top_srcdir}/src/gnc-module \
@@ -15,40 +16,61 @@
   -I${top_srcdir}/src \
   -I${top_builddir}/src \
   -I${top_srcdir}/lib/libc \
-  -I/usr/include/xulrunner/gtkembedmoz \
   ${QOF_CFLAGS} \
   ${GLIB_CFLAGS} \
   ${GTK_CFLAGS} \
   ${GNOME_CFLAGS} \
-  ${GTKHTML_CFLAGS} \
   ${GOFFICE_CFLAGS} \
   ${WEBKIT_CFLAGS}
+else
+AM_CPPFLAGS = \
+  -I${top_srcdir}/src/core-utils \
+  -I${top_srcdir}/src/gnc-module \
+  -I${top_srcdir}/src/engine \
+  -I${top_srcdir}/src/backend/file \
+  -I${top_srcdir}/src/app-utils \
+  -I${top_srcdir}/src/gnome-utils \
+  -I${top_srcdir}/src \
+  -I${top_builddir}/src \
+  -I${top_srcdir}/lib/libc \
+  ${QOF_CFLAGS} \
+  ${GLIB_CFLAGS} \
+  ${GTK_CFLAGS} \
+  ${GNOME_CFLAGS} \
+  ${GTKHTML_CFLAGS} \
+  ${GOFFICE_CFLAGS}
+endif
 
+if HTML_USING_WEBKIT
 libgncmod_html_la_SOURCES = \
   gnc-html.c \
   gnc-html-history.c \
-  gnc-html-gtkhtml.c \
   gnc-html-graph-gog.c \
-  gnc-html-graph-gog-gtkhtml.c \
   gnc-html-webkit.c \
   gnc-html-graph-gog-webkit.c \
-  gnc-html-gtkmozembed.c \
-  gnc-html-graph-gog-gtkmozembed.c \
   gnc-html-factory.c \
   swig-gnc-html.c
+else
+libgncmod_html_la_SOURCES = \
+  gnc-html.c \
+  gnc-html-history.c \
+  gnc-html-gtkhtml.c \
+  gnc-html-graph-gog.c \
+  gnc-html-graph-gog-gtkhtml.c \
+  gnc-html-factory.c \
+  swig-gnc-html.c
+endif
 
 gncincludedir = ${GNC_INCLUDE_DIR}
 gncinclude_HEADERS = \
   gnc-html-graph-gog.h \
-  gnc-html-graph-gog-gtkhtml.h \
-  gnc-html-graph-gog-webkit.h \
-  gnc-html-graph-gog-gtkmozembed.h \
   gnc-html-history.h \
   gnc-html.h \
   gnc-html-factory.h
 
 libgncmod_html_la_LDFLAGS = -avoid-version
 
+if HTML_USING_WEBKIT
 libgncmod_html_la_LIBADD = \
   ${top_builddir}/src/core-utils/libgnc-core-utils.la \
   ${top_builddir}/src/gnc-module/libgnc-module.la \
@@ -57,9 +79,7 @@
   ${top_builddir}/src/calculation/libgncmod-calculation.la \
   ${top_builddir}/src/app-utils/libgncmod-app-utils.la \
   $(top_builddir)/lib/libc/libc-missing.la \
-  -L/usr/lib/xulrunner -lgtkembedmoz \
   ${GNOME_LIBS} \
-  ${GTKHTML_LIBS} \
   ${GDK_PIXBUF_LIBS} \
   ${GLIB_LIBS} \
   ${DB_LIBS} \
@@ -67,6 +87,24 @@
   ${GOFFICE_LIBS} \
   ${REGEX_LIBS} \
   ${WEBKIT_LIBS}
+else
+libgncmod_html_la_LIBADD = \
+  ${top_builddir}/src/core-utils/libgnc-core-utils.la \
+  ${top_builddir}/src/gnc-module/libgnc-module.la \
+  ${top_builddir}/src/engine/libgncmod-engine.la \
+  ${top_builddir}/src/backend/file/libgnc-backend-xml-utils.la \
+  ${top_builddir}/src/calculation/libgncmod-calculation.la \
+  ${top_builddir}/src/app-utils/libgncmod-app-utils.la \
+  $(top_builddir)/lib/libc/libc-missing.la \
+  ${GNOME_LIBS} \
+  ${GTKHTML_LIBS} \
+  ${GDK_PIXBUF_LIBS} \
+  ${GLIB_LIBS} \
+  ${DB_LIBS} \
+  ${QOF_LIBS} \
+  ${GOFFICE_LIBS} \
+  ${REGEX_LIBS}
+endif
 
 if BUILDING_FROM_SVN
 swig-gnc-html.c: gnc-html.i gnc-html.h \

Modified: gnucash/branches/webkit/src/html/gnc-html-factory.c
===================================================================
--- gnucash/branches/webkit/src/html/gnc-html-factory.c	2009-03-29 15:44:11 UTC (rev 18006)
+++ gnucash/branches/webkit/src/html/gnc-html-factory.c	2009-03-30 23:02:28 UTC (rev 18007)
@@ -28,7 +28,7 @@
 #include "gnc-html.h"
 #include "gnc-html-gtkhtml.h"
 #include "gnc-html-webkit.h"
-#include "gnc-html-gtkmozembed.h"
+//#include "gnc-html-gtkmozembed.h"
 #include "qoflog.h"
 #include "gnc-engine.h"
 
@@ -39,6 +39,12 @@
 
 GncHtml* gnc_html_factory_create_html( void )
 {
+#ifdef WANT_WEBKIT
+	return gnc_html_webkit_new();
+#else
+	return gnc_html_gtkhtml_new();
+#endif
+#if 0
 	const gchar* html_type = g_getenv( "GNC_HTML" );
 
 	if( html_type == NULL ) {
@@ -52,4 +58,5 @@
 	} else {
 		return gnc_html_gtkhtml_new();
 	}
+#endif
 }

Modified: gnucash/branches/webkit/src/html/gnc-html-graph-gog-webkit.c
===================================================================
--- gnucash/branches/webkit/src/html/gnc-html-graph-gog-webkit.c	2009-03-29 15:44:11 UTC (rev 18006)
+++ gnucash/branches/webkit/src/html/gnc-html-graph-gog-webkit.c	2009-03-30 23:02:28 UTC (rev 18007)
@@ -67,8 +67,10 @@
  * - general graph cleanup
  **/
 
+/* indicates the debugging module that this .o belongs to.  */
 #undef G_LOG_DOMAIN
 #define G_LOG_DOMAIN "gnc.html.graph.gog.webkit"
+static QofLogModule log_module = GNC_MOD_HTML;
 
 static int handle_piechart( GncHtml* html, gpointer eb, gpointer d );
 static int handle_barchart( GncHtml* html, gpointer eb, gpointer d );
@@ -213,6 +215,24 @@
 	return val;
 }
 
+static gchar*
+convert_pixbuf_to_base64_string( GdkPixbuf* pixbuf )
+{
+	gchar* pixel_buffer;
+	gsize pixel_buffer_size;
+	GError* error = NULL;
+	gchar* base64_buf;
+
+    if( !gdk_pixbuf_save_to_buffer( pixbuf, &pixel_buffer, &pixel_buffer_size, "png",
+									&error, NULL ) ) {
+		PERR( "Unable to save pixbuf to buffer: %s\n", error->message );
+		return NULL;
+	}
+
+	base64_buf = g_base64_encode( pixel_buffer, pixel_buffer_size );
+	return base64_buf;
+}
+
 /*
  * Handle the following parameters:
  * title: text
@@ -234,7 +254,7 @@
 	gchar* p;
 	gchar* p_end;
 	gchar* temp_str;
-	gchar* filename;
+	gchar* base64_buf;
 
 	pieChartInfo.width = get_int_value( &object_info, "width" );
 	pieChartInfo.height = get_int_value( &object_info, "height" );
@@ -260,10 +280,14 @@
 	if( pieChartInfo.title != NULL ) g_free( (gchar*)pieChartInfo.title );
 	if( pieChartInfo.subtitle != NULL ) g_free( (gchar*)pieChartInfo.subtitle );
 
-	filename = "/tmp/piechart.png";
-	gdk_pixbuf_savev( pixbuf, filename, "png", NULL, NULL, NULL );
-	*pResult = g_strdup_printf( "<img src=\"%s\" alt=\"Cannot display piechart\"/>", filename );
+	base64_buf = convert_pixbuf_to_base64_string( pixbuf );
+	if( base64_buf == NULL ) {
+		return FALSE;
+	}
 
+	*pResult = g_strdup_printf( "<img src=\"data:image/png;base64,%s \" alt=\"Cannot display piechart\"/>", base64_buf );
+	g_free( base64_buf );
+
 	g_debug("piechart rendered.");
 	return TRUE;
 }
@@ -290,7 +314,7 @@
 	gchar* p;
 	gchar* p_end;
 	gchar* temp_str;
-	gchar* filename;
+	gchar* base64_buf;
 
 	barChartInfo.width = get_int_value( &object_info, "width" );
 	barChartInfo.height = get_int_value( &object_info, "height" );
@@ -328,10 +352,13 @@
 	if( barChartInfo.x_axis_label != NULL ) g_free( (gchar*)barChartInfo.x_axis_label );
 	if( barChartInfo.y_axis_label != NULL ) g_free( (gchar*)barChartInfo.y_axis_label );
 
-	filename = "/tmp/barchart.png";
-	gdk_pixbuf_savev( pixbuf, filename, "png", NULL, NULL, NULL );
-	*pResult = g_strdup_printf( "<img src=\"%s\" alt=\"Cannot display barchart\"/>", filename );
+	base64_buf = convert_pixbuf_to_base64_string( pixbuf );
+	if( base64_buf == NULL ) {
+		return FALSE;
+	}
 
+	*pResult = g_strdup_printf( "<img src=\"data:image/png;base64,%s \" alt=\"Cannot display barchart\"/>", base64_buf );
+
 	g_debug("barchart rendered.");
 	return TRUE;
 }
@@ -362,7 +389,7 @@
 	gchar* p;
 	gchar* p_end;
 	gchar* temp_str;
-	gchar* filename;
+	gchar* base64_buf;
 
 	lineChartInfo.width = get_int_value( &object_info, "width" );
 	lineChartInfo.height = get_int_value( &object_info, "height" );
@@ -403,10 +430,13 @@
 	if( lineChartInfo.x_axis_label != NULL ) g_free( (gchar*)lineChartInfo.x_axis_label );
 	if( lineChartInfo.y_axis_label != NULL ) g_free( (gchar*)lineChartInfo.y_axis_label );
 
-	filename = "/tmp/linechart.png";
-	gdk_pixbuf_savev( pixbuf, filename, "png", NULL, NULL, NULL );
-	*pResult = g_strdup_printf( "<img src=\"%s\" alt=\"Cannot display linechart\"/>", filename );
+	base64_buf = convert_pixbuf_to_base64_string( pixbuf );
+	if( base64_buf == NULL ) {
+		return FALSE;
+	}
 
+	*pResult = g_strdup_printf( "<img src=\"data:image/png;base64,%s \" alt=\"Cannot display linechart\"/>", base64_buf );
+
 	g_debug("linechart rendered.");
 	return TRUE;
 }
@@ -422,7 +452,7 @@
 	gchar* p;
 	gchar* p_end;
 	gchar* temp_str;
-	gchar* filename;
+	gchar* base64_buf;
 
 	scatterPlotInfo.width = get_int_value( &object_info, "width" );
 	scatterPlotInfo.height = get_int_value( &object_info, "height" );
@@ -446,10 +476,13 @@
 	if( scatterPlotInfo.title != NULL ) g_free( (gchar*)scatterPlotInfo.title );
 	if( scatterPlotInfo.subtitle != NULL ) g_free( (gchar*)scatterPlotInfo.subtitle );
 
-	filename = "/tmp/scatterplot.png";
-	gdk_pixbuf_savev( pixbuf, filename, "png", NULL, NULL, NULL );
-	*pResult = g_strdup_printf( "<img src=\"%s\" alt=\"Cannot display scatterplot\"/>", filename );
+	base64_buf = convert_pixbuf_to_base64_string( pixbuf );
+	if( base64_buf == NULL ) {
+		return FALSE;
+	}
 
+	*pResult = g_strdup_printf( "<img src=\"data:image/png;base64,%s \" alt=\"Cannot display scatterplot\"/>", base64_buf );
+
 	g_debug("scatterplot rendered.");
 	return TRUE;
 }

Modified: gnucash/branches/webkit/src/html/gnc-html-graph-gog.c
===================================================================
--- gnucash/branches/webkit/src/html/gnc-html-graph-gog.c	2009-03-29 15:44:11 UTC (rev 18006)
+++ gnucash/branches/webkit/src/html/gnc-html-graph-gog.c	2009-03-30 23:02:28 UTC (rev 18007)
@@ -212,6 +212,7 @@
 	GogPlot *plot;
 	GogSeries *series;
 	GOData *labelData, *sliceData;
+	GdkPixbuf* pixbuf;
 
 	if( !create_basic_plot_elements( "GogPiePlot", &graph, &chart, &plot ) ) {
 		return NULL;
@@ -233,7 +234,9 @@
 	// fixme: colors
 	set_chart_titles( chart, info->title, info->subtitle );
 
-	return create_graph_pixbuf( graph, info->width, info->height );
+	pixbuf = create_graph_pixbuf( graph, info->width, info->height );
+
+	return pixbuf;
 }
 
 /**

Modified: gnucash/branches/webkit/src/html/gnc-html-gtkhtml.c
===================================================================
--- gnucash/branches/webkit/src/html/gnc-html-gtkhtml.c	2009-03-29 15:44:11 UTC (rev 18006)
+++ gnucash/branches/webkit/src/html/gnc-html-gtkhtml.c	2009-03-30 23:02:28 UTC (rev 18007)
@@ -167,8 +167,6 @@
 
 	gtk_html_load_empty(GTK_HTML(priv->html));
 
-	show_type_signals( GTK_TYPE_HTML );
-
 	LEAVE("retval %p", self);
 }
 

Modified: gnucash/branches/webkit/src/html/gnc-html-gtkmozembed.c
===================================================================
--- gnucash/branches/webkit/src/html/gnc-html-gtkmozembed.c	2009-03-29 15:44:11 UTC (rev 18006)
+++ gnucash/branches/webkit/src/html/gnc-html-gtkmozembed.c	2009-03-30 23:02:28 UTC (rev 18007)
@@ -174,7 +174,6 @@
 #endif
 
 	printf( "GTK_TYPE_MOZ_EMBED:\n" );
-	show_type_signals( GTK_TYPE_MOZ_EMBED );
 
 	LEAVE("retval %p", self);
 }

Modified: gnucash/branches/webkit/src/html/gnc-html-webkit.c
===================================================================
--- gnucash/branches/webkit/src/html/gnc-html-webkit.c	2009-03-29 15:44:11 UTC (rev 18006)
+++ gnucash/branches/webkit/src/html/gnc-html-webkit.c	2009-03-30 23:02:28 UTC (rev 18007)
@@ -37,11 +37,11 @@
 #include <unistd.h>
 #include <regex.h>
 #include <libguile.h>
+#include <dlfcn.h>
 
 #include <webkit/webkit.h>
 
 #include "Account.h"
-#include "print-session.h"
 #include "gnc-engine.h"
 #include "gnc-gui-query.h"
 #include "gnc-html.h"
@@ -58,7 +58,6 @@
 static void gnc_html_webkit_class_init( GncHtmlWebkitClass* klass );
 static void gnc_html_webkit_init( GncHtmlWebkit* gs );
 
-//#define GNC_HTML_WEBKIT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), GNC_TYPE_HTML_WEBKIT, GncHtmlWebkitPrivate))
 #define GNC_HTML_WEBKIT_GET_PRIVATE(o) (GNC_HTML_WEBKIT(o)->priv)
 
 #include "gnc-html-webkit-p.h"
@@ -169,11 +168,6 @@
 		    self);
 #endif
 
-	printf( "WEBKIT_TYPE_WEB_VIEW:\n" );
-	show_type_signals( WEBKIT_TYPE_WEB_VIEW );
-	printf( "WEBKIT_TYPE_WEB_FRAME:\n" );
-	show_type_signals( WEBKIT_TYPE_WEB_FRAME );
-
 	LEAVE("retval %p", self);
 }
 
@@ -189,9 +183,9 @@
 	html_class->show_url = impl_webkit_show_url;
 	html_class->show_data = impl_webkit_show_data;
 	html_class->reload = impl_webkit_reload;
-	html_class->copy = impl_webkit_copy;
-	html_class->export = impl_webkit_export;
-//	html_class->print = impl_webkit_print;
+//	html_class->copy = impl_webkit_copy;
+//	html_class->export = impl_webkit_export;
+	html_class->print = impl_webkit_print;
 	html_class->cancel = impl_webkit_cancel;
 	html_class->set_parent = impl_webkit_set_parent;
 
@@ -650,9 +644,14 @@
 static void
 impl_webkit_show_data( GncHtml* self, const gchar* data, int datalen )
 {
-	GncHtmlWebkitPrivate* priv = GNC_HTML_WEBKIT_GET_PRIVATE(self);
+	GncHtmlWebkitPrivate* priv;
 
+	g_return_if_fail( self != NULL );
+	g_return_if_fail( GNC_IS_HTML_WEBKIT(self) );
+
 	DEBUG( "datalen %d, data %20.20s", datalen, data );
+
+	priv = GNC_HTML_WEBKIT_GET_PRIVATE(self);
 	webkit_web_view_load_html_string( priv->web_view, data, "base-uri" );
 }
 
@@ -671,12 +670,13 @@
 {
 	GncHTMLUrlCB url_handler;
 	gboolean new_window;
-	GncHtmlWebkitPrivate* priv = GNC_HTML_WEBKIT_GET_PRIVATE(self);
+	GncHtmlWebkitPrivate* priv;
 
-	DEBUG(" ");
+	g_return_if_fail( self != NULL );
+	g_return_if_fail( GNC_IS_HTML_WEBKIT(self) );
+	g_return_if_fail( location != NULL );
 
-	if( self == NULL ) return;
-	if( location == NULL ) return;
+	priv = GNC_HTML_WEBKIT_GET_PRIVATE(self);
 
 	/* make sure it's OK to show this URL type in this window */
 	if( new_window_hint == 0 ) {
@@ -821,10 +821,13 @@
 static void
 impl_webkit_reload( GncHtml* self )
 {
-	GncHtmlWebkitPrivate* priv = GNC_HTML_WEBKIT_GET_PRIVATE(self);
 	gnc_html_history_node * n;
+	GncHtmlWebkitPrivate* priv;
 
-	DEBUG(" ");
+	g_return_if_fail( self != NULL );
+	g_return_if_fail( GNC_IS_HTML_WEBKIT(self) );
+
+	priv = GNC_HTML_WEBKIT_GET_PRIVATE(self);
 	n = gnc_html_history_get_current( priv->base.history );
 	if( n != NULL ) {
 		gnc_html_show_url( self, n->type, n->location, n->label, 0 );
@@ -862,7 +865,13 @@
 static void
 impl_webkit_cancel( GncHtml* self )
 {
-	GncHtmlWebkitPrivate* priv = GNC_HTML_WEBKIT_GET_PRIVATE(self);
+	GncHtmlWebkitPrivate* priv;
+
+	g_return_if_fail( self != NULL );
+	g_return_if_fail( GNC_IS_HTML_WEBKIT(self) );
+
+	priv = GNC_HTML_WEBKIT_GET_PRIVATE(self);
+
 	/* remove our own references to requests */
 	//gnc_http_cancel_requests( priv->http );
 
@@ -875,9 +884,9 @@
 	GncHtmlWebkitPrivate* priv;
 
 	g_return_if_fail( self != NULL );
+	g_return_if_fail( GNC_IS_HTML_WEBKIT(self) );
 
 	priv = GNC_HTML_WEBKIT_GET_PRIVATE(self);
-//	gtk_html_copy( GTK_HTML(priv->html) );
 	g_assert( FALSE );
 }
 
@@ -908,6 +917,7 @@
 	GncHtmlWebkitPrivate* priv;
 
 	g_return_val_if_fail( self != NULL, FALSE );
+	g_return_val_if_fail( GNC_IS_HTML_WEBKIT(self), FALSE );
 	g_return_val_if_fail( filepath != NULL, FALSE );
 
 	priv = GNC_HTML_WEBKIT_GET_PRIVATE(self);
@@ -922,82 +932,36 @@
 	return TRUE;
 }
 
-#ifdef WEBKIT_USES_GTKPRINT
 static void
-draw_page_cb(GtkPrintOperation *operation, GtkPrintContext *context,
-             gint page_nr, gpointer user_data)
-{
-    GncHtmlWebkit* self = GNC_HTML_WEBKIT(user_data);
-	GncHtmlWebkitPrivate* priv;
-
-	priv = GNC_HTML_WEBKIT_GET_PRIVATE(self);
-//    gtk_html_print_page( GTK_HTML(priv->html), context );
-	g_assert( FALSE );
-}
-
-static void
 impl_webkit_print( GncHtml* self )
 {
-    GtkPrintOperation *print;
-    GtkPrintOperationResult res;
 	GncHtmlWebkitPrivate* priv;
+	static void (*webkit_web_frame_print)( WebKitWebFrame* frame ) = NULL;
+	WebKitWebFrame* frame;
 
-	priv = GNC_HTML_WEBKIT_GET_PRIVATE(self);
-    print = gtk_print_operation_new();
-
-    gnc_print_operation_init(print);
-    gtk_print_operation_set_use_full_page(print, FALSE);
-    gtk_print_operation_set_unit(print, GTK_UNIT_POINTS);
-    gtk_print_operation_set_n_pages(print, 1);
-    g_signal_connect(print, "draw_page", G_CALLBACK(draw_page_cb), self);
-
-    res = gtk_print_operation_run(print, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
-                                  GTK_WINDOW(priv->base.parent), NULL);
-
-    if( res == GTK_PRINT_OPERATION_RESULT_APPLY ) {
-        gnc_print_operation_save_print_settings( print );
+	/*  HACK ALERT
+	 *
+	 * The api to print isn't exported, but exists and works, so let's dig for it.
+	 */
+	if( webkit_web_frame_print == NULL ) {
+		void* handle = dlopen( "/usr/lib/libwebkit-1.0.so", RTLD_LAZY );
+		webkit_web_frame_print = dlsym( handle, "webkit_web_frame_print" );
+		dlclose( handle );
 	}
 
-    g_object_unref(print);
+	priv = GNC_HTML_WEBKIT_GET_PRIVATE(self);
+	frame = webkit_web_view_get_main_frame( priv->web_view );
+	webkit_web_frame_print( frame );
 }
 
-#else /* !WEBKIT_USES_GTKPRINT */
-#if 0
-void
-gnc_html_print( GncHtml* html )
-{
-	PrintSession *ps;
-
-	ps = gnc_print_session_create( FALSE );
-	if( ps == NULL ) {
-		/* user cancelled */
-		return;
-	}
-
-//	gtk_html_print( GTK_HTML(html->html), ps->context );
-	g_assert( FALSE );
-	gnc_print_session_done( ps );
-}
-#endif
-#endif /* WEBKIT_USES_GTKPRINT */
-
 static void
 impl_webkit_set_parent( GncHtml* self, GtkWindow* parent )
 {
 	GncHtmlWebkitPrivate* priv;
 
 	g_return_if_fail( self != NULL );
+	g_return_if_fail( GNC_IS_HTML_WEBKIT(self) );
 
 	priv = GNC_HTML_WEBKIT_GET_PRIVATE(self);
 	priv->base.parent = GTK_WIDGET(parent);
 }
-
-#if 0
-const gchar*
-gnc_html_get_embedded_param( gpointer eb, const gchar* param_name )
-{
-	GtkHTMLEmbedded* gtk_eb = (GtkHTMLEmbedded*)eb;
-
-	return (const gchar *)g_hash_table_lookup(gtk_eb->params, param_name);
-}
-#endif

Modified: gnucash/branches/webkit/src/html/gnc-html.c
===================================================================
--- gnucash/branches/webkit/src/html/gnc-html.c	2009-03-29 15:44:11 UTC (rev 18006)
+++ gnucash/branches/webkit/src/html/gnc-html.c	2009-03-30 23:02:28 UTC (rev 18007)
@@ -40,16 +40,12 @@
 #include <regex.h>
 #include <libguile.h>
 
-#include <gtkhtml/gtkhtml.h>
-#include <gtkhtml/gtkhtml-embedded.h>
-
 #include "Account.h"
 #include "print-session.h"
 #include "gnc-engine.h"
 #include "gnc-gui-query.h"
 #include "gnc-html.h"
 #include "gnc-html-history.h"
-//#include "gnc-html-graph-gog.h"
 #include "gnc-ui.h"
 #include "gnc-ui-util.h"
 
@@ -209,6 +205,7 @@
 	URLType retval;
 	GncHtmlPrivate* priv = GNC_HTML_GET_PRIVATE(self);
 
+	g_return_val_if_fail( self != NULL, NULL );
 	g_return_val_if_fail( GNC_IS_HTML(self), NULL );
 
 	DEBUG( "parsing %s, base_location %s",
@@ -307,9 +304,14 @@
 void
 gnc_html_show_data( GncHtml* self, const gchar* data, int datalen )
 {
+	g_return_if_fail( self != NULL );
 	g_return_if_fail( GNC_IS_HTML(self) );
 
-	GNC_HTML_GET_CLASS(self)->show_data( self, data, datalen );
+	if( GNC_HTML_GET_CLASS(self)->show_data != NULL ) {
+		GNC_HTML_GET_CLASS(self)->show_data( self, data, datalen );
+	} else {
+		DEBUG( "'show_data' not implemented" );
+	}
 }
 
 
@@ -326,9 +328,14 @@
                   const gchar* location, const gchar* label,
                   gboolean new_window_hint )
 {
+	g_return_if_fail( self != NULL );
 	g_return_if_fail( GNC_IS_HTML(self) );
 
-	GNC_HTML_GET_CLASS(self)->show_url( self, type, location, label, new_window_hint );
+	if( GNC_HTML_GET_CLASS(self)->show_url != NULL ) {
+		GNC_HTML_GET_CLASS(self)->show_url( self, type, location, label, new_window_hint );
+	} else {
+		DEBUG( "'show_url' not implemented" );
+	}
 }
 
 
@@ -340,9 +347,14 @@
 void
 gnc_html_reload( GncHtml* self )
 {
+	g_return_if_fail( self != NULL );
 	g_return_if_fail( GNC_IS_HTML(self) );
 
-	GNC_HTML_GET_CLASS(self)->reload( self );
+	if( GNC_HTML_GET_CLASS(self)->reload != NULL ) {
+		GNC_HTML_GET_CLASS(self)->reload( self );
+	} else {
+		DEBUG( "'reload' not implemented" );
+	}
 }
 
 /********************************************************************
@@ -353,9 +365,14 @@
 void
 gnc_html_cancel( GncHtml* self )
 {
+	g_return_if_fail( self != NULL );
 	g_return_if_fail( GNC_IS_HTML(self) );
 
-	GNC_HTML_GET_CLASS(self)->cancel( self );
+	if( GNC_HTML_GET_CLASS(self)->cancel != NULL ) {
+		GNC_HTML_GET_CLASS(self)->cancel( self );
+	} else {
+		DEBUG( "'cancel' not implemented" );
+	}
 }
 
 
@@ -367,6 +384,9 @@
 void
 gnc_html_destroy( GncHtml* self )
 {
+	g_return_if_fail( self != NULL );
+	g_return_if_fail( GNC_IS_HTML(self) );
+
 	g_object_unref( G_OBJECT(self) );
 }
 
@@ -374,6 +394,8 @@
 gnc_html_set_urltype_cb( GncHtml* self, GncHTMLUrltypeCB urltype_cb )
 {
 	GncHtmlPrivate* priv;
+
+	g_return_if_fail( self != NULL );
 	g_return_if_fail( GNC_IS_HTML(self) );
 
 	priv = GNC_HTML_GET_PRIVATE(self);
@@ -384,6 +406,8 @@
 gnc_html_set_load_cb( GncHtml* self, GncHTMLLoadCB load_cb, gpointer data )
 {
 	GncHtmlPrivate* priv;
+
+	g_return_if_fail( self != NULL );
 	g_return_if_fail( GNC_IS_HTML(self) );
 
 	priv = GNC_HTML_GET_PRIVATE(self);
@@ -395,6 +419,8 @@
 gnc_html_set_flyover_cb( GncHtml* self, GncHTMLFlyoverCB flyover_cb, gpointer data )
 {
 	GncHtmlPrivate* priv;
+
+	g_return_if_fail( self != NULL );
 	g_return_if_fail( GNC_IS_HTML(self) );
 
 	priv = GNC_HTML_GET_PRIVATE(self);
@@ -406,6 +432,8 @@
 gnc_html_set_button_cb( GncHtml* self, GncHTMLButtonCB button_cb, gpointer data )
 {
 	GncHtmlPrivate* priv;
+
+	g_return_if_fail( self != NULL );
 	g_return_if_fail( GNC_IS_HTML(self) );
 
 	priv = GNC_HTML_GET_PRIVATE(self);
@@ -416,9 +444,14 @@
 void
 gnc_html_copy( GncHtml* self )
 {
+	g_return_if_fail( self != NULL );
 	g_return_if_fail( GNC_IS_HTML(self) );
 
-	GNC_HTML_GET_CLASS(self)->copy( self );
+	if( GNC_HTML_GET_CLASS(self)->copy != NULL ) {
+		GNC_HTML_GET_CLASS(self)->copy( self );
+	} else {
+		DEBUG( "'copy' not implemented" );
+	}
 }
 
 /**************************************************************
@@ -428,23 +461,36 @@
 gboolean
 gnc_html_export( GncHtml* self, const gchar* filepath )
 {
+	g_return_val_if_fail( self != NULL, FALSE );
 	g_return_val_if_fail( GNC_IS_HTML(self), FALSE );
 
-	return GNC_HTML_GET_CLASS(self)->export( self, filepath );
+	if( GNC_HTML_GET_CLASS(self)->export != NULL ) {
+		return GNC_HTML_GET_CLASS(self)->export( self, filepath );
+	} else {
+		DEBUG( "'export' not implemented" );
+		return FALSE;
+	}
 }
 
 void
 gnc_html_print( GncHtml* self )
 {
+	g_return_if_fail( self != NULL );
 	g_return_if_fail( GNC_IS_HTML(self) );
 
-	GNC_HTML_GET_CLASS(self)->print( self );
+	if( GNC_HTML_GET_CLASS(self)->print != NULL ) {
+		GNC_HTML_GET_CLASS(self)->print( self );
+	} else {
+		DEBUG( "'print' not implemented" );
+	}
 }
 
 gnc_html_history *
 gnc_html_get_history( GncHtml* self )
 {
+	g_return_val_if_fail( self != NULL, NULL );
 	g_return_val_if_fail( GNC_IS_HTML(self), NULL );
+
 	return GNC_HTML_GET_PRIVATE(self)->history;
 }
 
@@ -452,15 +498,23 @@
 GtkWidget *
 gnc_html_get_widget( GncHtml* self )
 {
+	g_return_val_if_fail( self != NULL, NULL );
 	g_return_val_if_fail( GNC_IS_HTML(self), NULL );
+
 	return GNC_HTML_GET_PRIVATE(self)->container;
 }
 
 void
 gnc_html_set_parent( GncHtml* self, GtkWindow* parent )
 {
+	g_return_if_fail( self != NULL );
 	g_return_if_fail( GNC_IS_HTML(self) );
-	GNC_HTML_GET_CLASS(self)->set_parent( self, parent );
+
+	if( GNC_HTML_GET_CLASS(self)->set_parent != NULL ) {
+		GNC_HTML_GET_CLASS(self)->set_parent( self, parent );
+	} else {
+		DEBUG( "'set_parent' not implemented" );
+	}
 }
 
 /* Register the URLType if it doesn't already exist.
@@ -888,17 +942,3 @@
 {
 	g_hash_table_remove( gnc_html_url_handlers, url_type );
 }
-
-void show_type_signals( GType t )
-{
-	guint* signals;
-	guint n_ids;
-	guint i;
-	GSignalQuery sig;
-
-	signals = g_signal_list_ids( t, &n_ids );
-	for( i = 0; i < n_ids; i++ ) {
-		g_signal_query( signals[i], &sig );
-		printf( "Signal: %s\n", sig.signal_name );
-	}
-}

Modified: gnucash/branches/webkit/src/html/gnc-html.h
===================================================================
--- gnucash/branches/webkit/src/html/gnc-html.h	2009-03-29 15:44:11 UTC (rev 18006)
+++ gnucash/branches/webkit/src/html/gnc-html.h	2009-03-30 23:02:28 UTC (rev 18007)
@@ -73,15 +73,19 @@
 typedef gboolean (* GncHTMLUrlCB)(const gchar* location, const gchar* label,
                                   gboolean new_window, GNCURLResult* result);
 
-/* Register a new URLType.
+/**
+ * Registers a new URLType.
  * returns TRUE if succesful, FALSE if type already exists.
  *
- * protocol should be an empty string if there is no corresponding protocol.
- * if protocol is NULL, this function returns FALSE.
+ * @param type New URL type
+ * @param prococol Protocol - should be an empty string if there is no corresponding protocol.
+ * @return TRUE if successful, FALSE if type already exists or protocol is NULL.
  */
 gboolean gnc_html_register_urltype( URLType type, const gchar* protocol );
 
-/* Initialize the html subsystem */
+/**
+ * Initializes the html subsystem
+ */
 void gnc_html_initialize( void );
 
 gchar* gnc_html_encode_string( const gchar* in );
@@ -154,21 +158,82 @@
 	GncHtmlPrivate* priv;
 };
 
-GncHtml* gnc_html_new( GtkWindow* parent );
+/**
+ * Destroys a GncHtml object.
+ *
+ * @param html GncHtml object to destroy
+ */
 void gnc_html_destroy( GncHtml* html );
+
+/**
+ * Displays a URL in a GncHtml object.
+ *
+ * @param html GncHtml object
+ */
 void gnc_html_show_url( GncHtml* html, URLType type, const gchar* location, 
 						const gchar* label, gboolean new_window_hint );
+
+/**
+ * Displays an HTML string in a GncHtml object.
+ *
+ * @param html GncHtml object
+ */
 void gnc_html_show_data( GncHtml* html, const gchar* data, int datalen );
+
+/**
+ * Reloads the current GncHtml object.
+ *
+ * @param html GncHtml object
+ */
 void gnc_html_reload( GncHtml* html );
+
+/**
+ * 
+ * @param html GncHtml object
+ */
 void gnc_html_copy( GncHtml* html );
+
+/**
+ *
+ * @param html GncHtml object
+ */
 gboolean gnc_html_export( GncHtml* html, const gchar* file );
+
+/**
+ *
+ * @param html GncHtml object
+ */
 void gnc_html_print( GncHtml* html );
+
+/**
+ *
+ * @param html GncHtml object
+ */
 void gnc_html_cancel( GncHtml* html );
+
+/**
+ *
+ * @param html GncHtml object
+ */
 URLType gnc_html_parse_url( GncHtml* html, const gchar* url, 
 							gchar** url_location, gchar** url_label );
 
+/**
+ *
+ * @param html GncHtml object
+ */
 gnc_html_history* gnc_html_get_history( GncHtml* html );
+
+/**
+ *
+ * @param html GncHtml object
+ */
 GtkWidget* gnc_html_get_widget( GncHtml* html );
+
+/**
+ *
+ * @param html GncHtml object
+ */
 void gnc_html_set_parent( GncHtml* html, GtkWindow* parent );
 
 /* setting callbacks */
@@ -198,6 +263,4 @@
 
 const gchar* gnc_html_get_embedded_param( gpointer eb, const gchar* param_name );
 
-void show_type_signals( GType t );
-
 #endif



More information about the gnucash-changes mailing list