Remove gtkhtml-related sources completely.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@20483 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Christian Stimming 2011-03-26 09:23:45 +00:00
parent 51e95d1840
commit 8298177be7
13 changed files with 8 additions and 1562 deletions

View File

@ -964,7 +964,6 @@ then
webkit)
PKG_CHECK_MODULES(WEBKIT, webkit-1.0 >= "1.0")
AC_DEFINE(WANT_WEBKIT,1,[Use webkit])
case "$platform" in
win32)
# 1.1.90 has both functions
@ -998,7 +997,6 @@ then
*) AC_MSG_ERROR([Invalid HTML engine: must be webkit]) ;;
esac
AM_CONDITIONAL(HTML_USING_WEBKIT, [test x${with_html_engine} = xwebkit])
AC_SUBST(WEBKIT_CFLAGS)
AC_SUBST(WEBKIT_LIBS)
@ -1442,7 +1440,6 @@ AC_MSG_RESULT([
gnucash version ...... : $VERSION
Build for host ....... : $host
Optional components... : $components
HTML engine .......... : $with_html_engine
Extra Warnings ....... : $warnFLAGS
CPPFLAGS ............. : $CPPFLAGS
CFLAGS ............... : $CFLAGS

View File

@ -355,9 +355,7 @@ src/gnome/window-reconcile.c
src/html/gnc-html.c
src/html/gnc-html-factory.c
src/html/gnc-html-graph-gog.c
src/html/gnc-html-graph-gog-gtkhtml.c
src/html/gnc-html-graph-gog-webkit.c
src/html/gnc-html-gtkhtml.c
src/html/gnc-html-history.c
src/html/gnc-html-webkit.c
src/html/gncmod-html.c

View File

@ -280,7 +280,7 @@ gnc_gnome_init (int argc, char **argv, const char * version)
xmlCleanupInputCallbacks();
#endif
/* initialization required for gtkhtml */
/* initialization required for gtkhtml (is it also needed for webkit?) */
gtk_widget_set_default_colormap (gdk_rgb_get_colormap ());
/* use custom icon */

View File

@ -18,6 +18,7 @@ AM_CPPFLAGS = \
${GTK_CFLAGS} \
${GLADE_CFLAGS} \
${GNOME_CFLAGS} \
${WEBKIT_CFLAGS} \
${GOFFICE_CFLAGS}
libgncmod_html_la_SOURCES = \
@ -26,6 +27,8 @@ libgncmod_html_la_SOURCES = \
gnc-html-history.c \
gnc-html-graph-gog.c \
gnc-html-factory.c \
gnc-html-webkit.c \
gnc-html-graph-gog-webkit.c \
swig-gnc-html.c
gncincludedir = ${GNC_INCLUDE_DIR}
@ -35,12 +38,9 @@ gncinclude_HEADERS = \
gnc-html.h \
gnc-html-p.h \
gnc-html-factory.h \
gnc-html-gtkhtml.h \
gnc-html-webkit.h \
gnc-html-extras.h \
gnc-html-gtkhtml-p.h \
gnc-html-webkit-p.h \
gnc-html-graph-gog-gtkhtml.h \
gnc-html-graph-gog-webkit.h \
gnc-html-graph-gog-extras.h
@ -54,6 +54,7 @@ libgncmod_html_la_LIBADD = \
${top_builddir}/src/gnome-utils/libgncmod-gnome-utils.la \
${top_builddir}/src/app-utils/libgncmod-app-utils.la \
$(top_builddir)/lib/libc/libc-missing.la \
${WEBKIT_LIBS} \
${GNOME_LIBS} \
${GDK_PIXBUF_LIBS} \
${GLIB_LIBS} \
@ -64,23 +65,6 @@ libgncmod_html_la_LIBADD = \
${GUILE_LIBS} \
${REGEX_LIBS}
if HTML_USING_WEBKIT
AM_CPPFLAGS += ${WEBKIT_CFLAGS}
libgncmod_html_la_SOURCES += \
gnc-html-webkit.c \
gnc-html-graph-gog-webkit.c
libgncmod_html_la_LIBADD += \
${WEBKIT_LIBS}
else
AM_CPPFLAGS += ${GTKHTML_CFLAGS}
libgncmod_html_la_SOURCES += \
gnc-html-gtkhtml.c \
gnc-html-graph-gog-gtkhtml.c
libgncmod_html_la_LIBADD += \
${GTKHTML_LIBS}
endif
if BUILDING_FROM_SVN
swig-gnc-html.c: gnc-html.i gnc-html.h \
${top_srcdir}/src/base-typemaps.i

View File

@ -26,7 +26,6 @@
#include <gtk/gtk.h>
#include "gnc-html.h"
#include "gnc-html-gtkhtml.h"
#include "gnc-html-webkit.h"
#include "qoflog.h"
#include "gnc-engine.h"
@ -38,19 +37,11 @@ static QofLogModule log_module = GNC_MOD_HTML;
GncHtml* gnc_html_factory_create_html( void )
{
#ifdef WANT_WEBKIT
return gnc_html_webkit_new();
#else
return gnc_html_gtkhtml_new();
#endif
}
gboolean
gnc_html_engine_supports_css( void )
{
#ifdef WANT_WEBKIT
return TRUE;
#else
return FALSE;
#endif
}

View File

@ -1,403 +0,0 @@
/********************************************************************
* gnc-html-graph-gog.c -- GNC/HTML Graphing support via GOG *
* *
* Copyright (C) 2005 Joshua Sled <jsled@asynchronous.org> *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 2 of *
* the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License*
* along with this program; if not, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
* Boston, MA 02110-1301, USA gnu@gnu.org *
********************************************************************/
#include "config.h"
#include <gtk/gtk.h>
#include <gtkhtml/gtkhtml.h>
#include <gtkhtml/gtkhtml-embedded.h>
#include <string.h>
#include "gnc-locale-utils.h"
#include "gnc-html-graph-gog.h"
#include "gnc-html-graph-gog-gtkhtml.h"
#include "gnc-html-graph-gog-extras.h"
#include "gnc-html.h"
#include "gnc-engine.h"
#include <goffice/goffice.h>
#include <goffice/graph/gog-chart.h>
#include <goffice/graph/gog-graph.h>
#include <goffice/graph/gog-object.h>
#include <goffice/graph/gog-renderer.h>
/* everything inside the following #ifndef can be safely removed when gnucash
requires libgoffice >= 0.7.5. */
#ifndef GOG_TYPE_GRAPH
# define GOG_TYPE_GRAPH GOG_GRAPH_TYPE
# define GOG_TYPE_RENDERER GOG_RENDERER_TYPE
#endif
#include <goffice/graph/gog-styled-object.h>
#include <goffice/graph/gog-plot.h>
#include <goffice/graph/gog-series.h>
#include <goffice/utils/go-color.h>
#include <goffice/utils/go-marker.h>
#include <goffice/graph/gog-data-set.h>
#include <goffice/data/go-data-simple.h>
#include <goffice/app/go-plugin.h>
#include <goffice/app/go-plugin-loader-module.h>
/**
* TODO:
* - scatter-plot marker selection
* - series-color, piecharts (hard, not really supported by GOG)
* and scatters (or drop feature)
* - title-string freeing (fixmes)
* - general graph cleanup
**/
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "gnc.html.graph.gog.gtkhtml"
static int handle_piechart( GncHtml* html, gpointer eb, gpointer d );
static int handle_barchart( GncHtml* html, gpointer eb, gpointer d );
static int handle_linechart( GncHtml* html, gpointer eb, gpointer d );
static int handle_scatter( GncHtml* html, gpointer eb, gpointer d );
static void draw_print_cb(GtkHTMLEmbedded *eb, cairo_t *cr, gpointer graph);
static double * read_doubles(const char * string, int nvalues);
void
gnc_html_graph_gog_gtkhtml_init( void )
{
gnc_html_graph_gog_init();
gnc_html_register_object_handler( GNC_CHART_PIE, handle_piechart );
gnc_html_register_object_handler( GNC_CHART_BAR, handle_barchart );
gnc_html_register_object_handler( GNC_CHART_SCATTER, handle_scatter );
gnc_html_register_object_handler( GNC_CHART_LINE, handle_linechart );
}
static double *
read_doubles(const char * string, int nvalues)
{
int n;
gchar *next;
double * retval = g_new0(double, nvalues);
// guile is going to (puts ...) the elements of the double array
// together. In non-POSIX locales, that will be in a format that
// the locale-specific sscanf will not be able to parse.
gnc_push_locale(LC_NUMERIC, "C");
{
for (n = 0; n < nvalues; n++)
{
retval[n] = strtod(string, &next);
string = next;
}
}
gnc_pop_locale(LC_NUMERIC);
return retval;
}
static char **
read_strings(const char * string, int nvalues)
{
int n;
int choffset = 0;
int accum = 0;
char ** retval = g_new0(char *, nvalues);
char thischar;
const char * inptr = string;
int escaped = FALSE;
for (n = 0; n < nvalues; n++)
{
retval[n] = g_new0(char, strlen(string + accum) + 1);
retval[n][0] = 0;
choffset = 0;
while ((thischar = *inptr) != 0)
{
if (thischar == '\\')
{
escaped = TRUE;
inptr++;
}
else if ((thischar != ' ') || escaped)
{
retval[n][choffset] = thischar;
retval[n][choffset+1] = 0;
choffset++;
escaped = FALSE;
inptr++;
}
else
{
/* an unescaped space */
escaped = FALSE;
inptr++;
break;
}
}
accum += choffset;
/* printf("retval[%d] = '%s'\n", n, retval[n]); */
}
return retval;
}
static void
add_pixbuf_graph_widget( GtkHTMLEmbedded *eb, GdkPixbuf* buf )
{
GtkWidget *widget;
gboolean update_status;
GogGraph *graph = GOG_GRAPH(g_object_get_data( G_OBJECT(buf), "graph" ));
widget = gtk_image_new_from_pixbuf (buf);
gtk_widget_set_size_request (widget, eb->width, eb->height);
gtk_widget_show_all (widget);
gtk_container_add (GTK_CONTAINER (eb), widget);
// blindly copied from gnc-html-guppi.c..
gtk_widget_set_size_request (GTK_WIDGET (eb), eb->width, eb->height);
g_object_set_data_full (G_OBJECT (eb), "graph", graph, g_object_unref);
g_signal_connect (G_OBJECT (eb), "draw_print",
G_CALLBACK (draw_print_cb), NULL);
}
/*
* Handle the following parameters:
* title: text
* subtitle: text
* datasize: (length data), sscanf( .., %d, (int)&datasize )
* data: (foreach (lambda (datum) (push datum) (push " ")) data)
* colors: string; space-seperated?
* labels: string; space-seperated?
* slice_urls_[123]: ?
* legend_urls_[123]: ?
*/
static gboolean
handle_piechart( GncHtml* html, gpointer eb, gpointer unused )
{
GncHtmlPieChartInfo pieChartInfo;
// parse data from the text-ized params.
{
const char *datasizeStr, *dataStr, *labelsStr, *colorStr;
datasizeStr = gnc_html_get_embedded_param(eb, "datasize");
dataStr = gnc_html_get_embedded_param(eb, "data" );
labelsStr = gnc_html_get_embedded_param(eb, "labels");
colorStr = gnc_html_get_embedded_param(eb, "colors");
g_return_val_if_fail( datasizeStr != NULL
&& dataStr != NULL
&& labelsStr != NULL
&& colorStr != NULL, FALSE );
pieChartInfo.datasize = atoi( datasizeStr );
pieChartInfo.data = read_doubles( dataStr, pieChartInfo.datasize );
pieChartInfo.labels = read_strings( labelsStr, pieChartInfo.datasize );
pieChartInfo.colors = read_strings( colorStr, pieChartInfo.datasize );
}
pieChartInfo.title = (const char *)gnc_html_get_embedded_param(eb, "title");
pieChartInfo.subtitle = (const char *)gnc_html_get_embedded_param(eb, "subtitle");
pieChartInfo.width = ((GtkHTMLEmbedded*)eb)->width;
pieChartInfo.height = ((GtkHTMLEmbedded*)eb)->height;
add_pixbuf_graph_widget( eb, gnc_html_graph_gog_create_piechart( &pieChartInfo ) );
return TRUE;
}
/**
* data_rows:int
* data_cols:int
* data:doubles[], data_rows*data_cols
* x_axis_label:string
* y_axis_label:string
* row_labels:string[]
* col_labels:string[]
* col_colors:string[]
* rotate_row_labels:boolean
* stacked:boolean
**/
static gboolean
handle_barchart( GncHtml* html, gpointer eb, gpointer unused )
{
GncHtmlBarChartInfo barChartInfo;
// parse data from the text-ized params
// series => bars [gnc:cols]
// series-elements => segments [gnc:rows]
{
const char *data_rows_str, *data_cols_str, *data_str, *col_labels_str, *row_labels_str;
const char *col_colors_str, *rotate_row_labels_str = NULL, *stacked_str = NULL;
data_rows_str = gnc_html_get_embedded_param (eb, "data_rows");
data_cols_str = gnc_html_get_embedded_param (eb, "data_cols");
data_str = gnc_html_get_embedded_param (eb, "data" );
row_labels_str = gnc_html_get_embedded_param (eb, "row_labels");
col_labels_str = gnc_html_get_embedded_param (eb, "col_labels");
col_colors_str = gnc_html_get_embedded_param (eb, "col_colors");
rotate_row_labels_str = gnc_html_get_embedded_param (eb, "rotate_row_labels");
stacked_str = gnc_html_get_embedded_param (eb, "stacked");
barChartInfo.rotate_row_labels = (gboolean) atoi (rotate_row_labels_str);
barChartInfo.stacked = (gboolean) atoi (stacked_str);
#if 0 // too strong at the moment.
g_return_val_if_fail (data_rows_str != NULL
&& data_cols_str != NULL
&& data_str != NULL
&& col_labels_str != NULL
&& row_labels_str != NULL
&& col_colors_str != NULL, FALSE );
#endif // 0
barChartInfo.data_rows = atoi (data_rows_str);
barChartInfo.data_cols = atoi (data_cols_str);
barChartInfo.data = read_doubles (data_str, barChartInfo.data_rows * barChartInfo.data_cols);
barChartInfo.row_labels = read_strings (row_labels_str, barChartInfo.data_rows);
barChartInfo.col_labels = read_strings (col_labels_str, barChartInfo.data_cols);
barChartInfo.col_colors = read_strings (col_colors_str, barChartInfo.data_cols);
}
barChartInfo.title = (const char *)gnc_html_get_embedded_param(eb, "title");
barChartInfo.subtitle = (const char *)gnc_html_get_embedded_param(eb, "subtitle");
barChartInfo.width = ((GtkHTMLEmbedded*)eb)->width;
barChartInfo.height = ((GtkHTMLEmbedded*)eb)->height;
barChartInfo.x_axis_label = gnc_html_get_embedded_param(eb, "x_axis_label"),
barChartInfo.y_axis_label = gnc_html_get_embedded_param(eb, "y_axis_label");
add_pixbuf_graph_widget( eb, gnc_html_graph_gog_create_barchart( &barChartInfo ) );
g_debug("barchart rendered.");
return TRUE;
}
/**
* data_rows:int
* data_cols:int
* data:doubles[], data_rows*data_cols
* x_axis_label:string
* y_axis_label:string
* row_labels:string[]
* col_labels:string[]
* col_colors:string[]
* rotate_row_labels:boolean
* stacked:boolean
* markers:boolean
* major_grid:boolean
* minor_grid:boolean
**/
static gboolean
handle_linechart( GncHtml* html, gpointer eb, gpointer unused )
{
GncHtmlLineChartInfo lineChartInfo;
// parse data from the text-ized params
// series => lines [gnc:cols]
// series-elements => segments [gnc:rows]
{
const char *data_rows_str, *data_cols_str, *data_str, *col_labels_str, *row_labels_str;
const char *col_colors_str, *rotate_row_labels_str = NULL, *stacked_str = NULL, *markers_str = NULL;
const char *major_grid_str = NULL, *minor_grid_str = NULL;
data_rows_str = gnc_html_get_embedded_param (eb, "data_rows");
data_cols_str = gnc_html_get_embedded_param (eb, "data_cols");
data_str = gnc_html_get_embedded_param (eb, "data" );
row_labels_str = gnc_html_get_embedded_param (eb, "row_labels");
col_labels_str = gnc_html_get_embedded_param (eb, "col_labels");
col_colors_str = gnc_html_get_embedded_param (eb, "col_colors");
rotate_row_labels_str = gnc_html_get_embedded_param (eb, "rotate_row_labels");
stacked_str = gnc_html_get_embedded_param (eb, "stacked");
markers_str = gnc_html_get_embedded_param (eb, "markers");
major_grid_str = gnc_html_get_embedded_param (eb, "major_grid");
minor_grid_str = gnc_html_get_embedded_param (eb, "minor_grid");
lineChartInfo.rotate_row_labels = (gboolean) atoi (rotate_row_labels_str);
lineChartInfo.stacked = (gboolean) atoi (stacked_str);
lineChartInfo.markers = (gboolean) atoi (markers_str);
lineChartInfo.major_grid = (gboolean) atoi (major_grid_str);
lineChartInfo.minor_grid = (gboolean) atoi (minor_grid_str);
lineChartInfo.data_rows = atoi (data_rows_str);
lineChartInfo.data_cols = atoi (data_cols_str);
lineChartInfo.data = read_doubles (data_str, lineChartInfo.data_rows * lineChartInfo.data_cols);
lineChartInfo.row_labels = read_strings (row_labels_str, lineChartInfo.data_rows);
lineChartInfo.col_labels = read_strings (col_labels_str, lineChartInfo.data_cols);
lineChartInfo.col_colors = read_strings (col_colors_str, lineChartInfo.data_cols);
}
lineChartInfo.title = (const char *)gnc_html_get_embedded_param(eb, "title");
lineChartInfo.subtitle = (const char *)gnc_html_get_embedded_param(eb, "subtitle");
lineChartInfo.width = ((GtkHTMLEmbedded*)eb)->width;
lineChartInfo.height = ((GtkHTMLEmbedded*)eb)->height;
lineChartInfo.x_axis_label = gnc_html_get_embedded_param(eb, "x_axis_label"),
lineChartInfo.y_axis_label = gnc_html_get_embedded_param(eb, "y_axis_label");
add_pixbuf_graph_widget( eb, gnc_html_graph_gog_create_linechart( &lineChartInfo ) );
g_debug("linechart rendered.");
return TRUE;
}
static gboolean
handle_scatter( GncHtml* html, gpointer eb, gpointer unused )
{
GncHtmlScatterPlotInfo scatterPlotInfo;
{
const char *datasizeStr, *xDataStr, *yDataStr;
datasizeStr = gnc_html_get_embedded_param( eb, "datasize" );
scatterPlotInfo.datasize = atoi( datasizeStr );
xDataStr = gnc_html_get_embedded_param( eb, "x_data" );
scatterPlotInfo.xData = read_doubles( xDataStr, scatterPlotInfo.datasize );
yDataStr = gnc_html_get_embedded_param( eb, "y_data" );
scatterPlotInfo.yData = read_doubles( yDataStr, scatterPlotInfo.datasize );
scatterPlotInfo.marker_str = gnc_html_get_embedded_param(eb, "marker");
scatterPlotInfo.color_str = gnc_html_get_embedded_param(eb, "color");
}
scatterPlotInfo.title = (const char *)gnc_html_get_embedded_param(eb, "title");
scatterPlotInfo.subtitle = (const char *)gnc_html_get_embedded_param(eb, "subtitle");
scatterPlotInfo.width = ((GtkHTMLEmbedded*)eb)->width;
scatterPlotInfo.height = ((GtkHTMLEmbedded*)eb)->height;
scatterPlotInfo.x_axis_label = gnc_html_get_embedded_param(eb, "x_axis_label"),
scatterPlotInfo.y_axis_label = gnc_html_get_embedded_param(eb, "y_axis_label");
add_pixbuf_graph_widget( eb, gnc_html_graph_gog_create_scatterplot( &scatterPlotInfo ) );
return TRUE;
}
static void
draw_print_cb(GtkHTMLEmbedded *eb, cairo_t *cr, gpointer unused)
{
GogGraph *graph = GOG_GRAPH(g_object_get_data(G_OBJECT(eb), "graph"));
GogRenderer *rend = g_object_new(GOG_TYPE_RENDERER, "model", graph, NULL);
/* assuming pixel size is 0.5, cf. gtkhtml/src/htmlprinter.c */
cairo_scale(cr, 0.5, 0.5);
cairo_translate(cr, 0, -eb->height);
gog_renderer_render_to_cairo(rend, cr, eb->width, eb->height);
g_object_unref(rend);
}

View File

@ -1,30 +0,0 @@
/********************************************************************
* gnc-html_graph_gog_gtkhtml.h -- display html with gnc special *
* tags *
* Copyright (C) 2000 Bill Gribble <grib@billgribble.com> *
* Copyright (C) 2009 Phil Longstaff <plongstaff@rogers.com> *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 2 of *
* the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License*
* along with this program; if not, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
* Boston, MA 02110-1301, USA gnu@gnu.org *
\********************************************************************/
#ifndef GNC_HTML_GRAPH_GOG_GTKHTML_H
#define GNC_HTML_GRAPH_GOG_GTKHTML_H 1
void gnc_html_graph_gog_gtkhtml_init( void );
#endif /* GNC_HTML_GRAPH_GOG_GTKHTML_H */

View File

@ -1,35 +0,0 @@
/********************************************************************
* gnc-html-gtkhtml-p.h -- display html with gnc special tags *
* Copyright (C) 2009 Phil Longstaff <plongstaff@rogers.com> *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 2 of *
* the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License*
* along with this program; if not, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
* Boston, MA 02110-1301, USA gnu@gnu.org *
\********************************************************************/
#ifndef GNC_HTML_GTKHTML_P_H
#define GNC_HTML_GTKHTML_P_H
#include "gnc-html-p.h"
struct _GncHtmlGtkhtmlPrivate
{
struct _GncHtmlPrivate base;
GtkWidget* html; /* gtkhtml widget itself */
};
#endif

View File

@ -1,995 +0,0 @@
/********************************************************************
* gnc-html-gtkhtml.c -- display HTML with some special gnucash *
* tags. *
* *
* Copyright (C) 2000 Bill Gribble <grib@billgribble.com> *
* Copyright (C) 2001 Linas Vepstas <linas@linas.org> *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 2 of *
* the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License*
* along with this program; if not, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
* Boston, MA 02110-1301, USA gnu@gnu.org *
********************************************************************/
// libgtkhtml docs:
// http://www.fifi.org/doc/libgtkhtml-dev/html/
#include "config.h"
#include <gtk/gtk.h>
#include <glib/gi18n.h>
#include <glib/gstdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#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-gtkhtml.h"
#include "gnc-html-history.h"
#include "gnc-html-graph-gog-gtkhtml.h"
#include "gnc-ui.h"
#include "gnc-ui-util.h"
G_DEFINE_TYPE(GncHtmlGtkhtml, gnc_html_gtkhtml, GNC_TYPE_HTML )
static void gnc_html_gtkhtml_dispose( GObject* obj );
static void gnc_html_gtkhtml_finalize( GObject* obj );
static void gnc_html_gtkhtml_class_init( GncHtmlGtkhtmlClass* klass );
static void gnc_html_gtkhtml_init( GncHtmlGtkhtml* gs );
//#define GNC_HTML_GTKHTML_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), GNC_TYPE_HTML_GTKHTML, GncHtmlGtkhtmlPrivate))
#define GNC_HTML_GTKHTML_GET_PRIVATE(o) (GNC_HTML_GTKHTML(o)->priv)
#include "gnc-html-gtkhtml-p.h"
/* indicates the debugging module that this .o belongs to. */
static QofLogModule log_module = GNC_MOD_HTML;
/* hashes for URLType -> protocol and protocol -> URLType */
//extern GHashTable* gnc_html_type_to_proto_hash;
extern GHashTable* gnc_html_proto_to_type_hash;
/* hashes an HTML <object classid="ID"> classid to a handler function */
extern GHashTable* gnc_html_object_handlers;
/* hashes handlers for loading different URLType data */
extern GHashTable* gnc_html_stream_handlers;
/* hashes handlers for handling different URLType data */
extern GHashTable* gnc_html_url_handlers;
static char error_404_format[] = "<html><body><h3>%s</h3><p>%s</body></html>";
static char error_404_title[] = N_("Not found");
static char error_404_body[] = N_("The specified URL could not be loaded.");
static void gtkhtml_pre_3_10_1_bug_workaround( GtkHTMLEmbedded* eb );
static void gnc_html_url_requested_cb( GtkHTML* html, gchar* url,
GtkHTMLStream* handle, gpointer data );
static void gnc_html_on_url_cb( GtkHTML* html, const gchar* url, gpointer data );
static void gnc_html_set_base_cb( GtkHTML* gtkhtml, const gchar* base, gpointer data );
static void gnc_html_link_clicked_cb( GtkHTML* html, const gchar* url, gpointer data );
static gboolean gnc_html_object_requested_cb( GtkHTML* html, GtkHTMLEmbedded* eb,
gpointer data );
static int gnc_html_button_press_cb( GtkWidget* widg, GdkEventButton* event,
gpointer user_data );
static void impl_gtkhtml_show_url( GncHtml* self, URLType type,
const gchar* location, const gchar* label,
gboolean new_window_hint );
static void impl_gtkhtml_show_data( GncHtml* self, const gchar* data, int datalen );
static void impl_gtkhtml_reload( GncHtml* self );
static void impl_gtkhtml_copy_to_clipboard( GncHtml* self );
static gboolean impl_gtkhtml_export_to_file( GncHtml* self, const gchar* filepath );
static void impl_gtkhtml_print( GncHtml* self, const gchar* jobname );
static void impl_gtkhtml_cancel( GncHtml* self );
static void impl_gtkhtml_set_parent( GncHtml* self, GtkWindow* parent );
static void
gnc_html_gtkhtml_init( GncHtmlGtkhtml* self )
{
GncHtmlGtkhtmlPrivate* priv;
GncHtmlGtkhtmlPrivate* new_priv;
new_priv = g_realloc( GNC_HTML(self)->priv, sizeof(GncHtmlGtkhtmlPrivate) );
priv = self->priv = new_priv;
GNC_HTML(self)->priv = (GncHtmlPrivate*)priv;
priv->html = gtk_html_new();
gtk_container_add( GTK_CONTAINER(priv->base.container),
GTK_WIDGET(priv->html) );
g_object_ref_sink( priv->base.container );
/* signals */
g_signal_connect( priv->html, "url_requested",
G_CALLBACK(gnc_html_url_requested_cb),
self);
g_signal_connect( priv->html, "on_url",
G_CALLBACK(gnc_html_on_url_cb),
self );
g_signal_connect( priv->html, "set_base",
G_CALLBACK(gnc_html_set_base_cb),
self);
g_signal_connect(priv->html, "link_clicked",
G_CALLBACK(gnc_html_link_clicked_cb),
self);
g_signal_connect (priv->html, "object_requested",
G_CALLBACK (gnc_html_object_requested_cb),
self);
g_signal_connect (priv->html, "button_press_event",
G_CALLBACK (gnc_html_button_press_cb),
self);
gtk_html_load_empty(GTK_HTML(priv->html));
LEAVE("retval %p", self);
}
static void
gnc_html_gtkhtml_class_init( GncHtmlGtkhtmlClass* klass )
{
GObjectClass* gobject_class = G_OBJECT_CLASS(klass);
GncHtmlClass* html_class = GNC_HTML_CLASS(klass);
gobject_class->dispose = gnc_html_gtkhtml_dispose;
gobject_class->finalize = gnc_html_gtkhtml_finalize;
html_class->show_url = impl_gtkhtml_show_url;
html_class->show_data = impl_gtkhtml_show_data;
html_class->reload = impl_gtkhtml_reload;
html_class->copy_to_clipboard = impl_gtkhtml_copy_to_clipboard;
html_class->export_to_file = impl_gtkhtml_export_to_file;
html_class->print = impl_gtkhtml_print;
html_class->cancel = impl_gtkhtml_cancel;
html_class->set_parent = impl_gtkhtml_set_parent;
// Initialize graphing support
gnc_html_graph_gog_gtkhtml_init();
}
static void
gnc_html_gtkhtml_dispose( GObject* obj )
{
GncHtmlGtkhtml* self = GNC_HTML_GTKHTML(obj);
GncHtmlGtkhtmlPrivate* priv = GNC_HTML_GTKHTML_GET_PRIVATE(self);
if ( priv->html != NULL )
{
g_object_unref( G_OBJECT(priv->html) );
priv->html = NULL;
}
G_OBJECT_CLASS(gnc_html_gtkhtml_parent_class)->dispose( obj );
}
static void
gnc_html_gtkhtml_finalize( GObject* obj )
{
GncHtmlGtkhtml* self = GNC_HTML_GTKHTML(obj);
// if( self->priv != NULL ) {
// g_free( self->priv );
self->priv = NULL;
// }
G_OBJECT_CLASS(gnc_html_gtkhtml_parent_class)->finalize( obj );
}
/*****************************************************************************/
static char*
extract_base_name(URLType type, const gchar* path)
{
gchar machine_rexp[] = "^(//[^/]*)/*(/.*)?$";
gchar path_rexp[] = "^/*(.*)/+([^/]*)$";
regex_t compiled_m, compiled_p;
regmatch_t match[4];
gchar * machine = NULL, * location = NULL, * base = NULL;
gchar * basename = NULL;
DEBUG(" ");
if (!path) return NULL;
regcomp(&compiled_m, machine_rexp, REG_EXTENDED);
regcomp(&compiled_p, path_rexp, REG_EXTENDED);
if (!safe_strcmp (type, URL_TYPE_HTTP) ||
!safe_strcmp (type, URL_TYPE_SECURE) ||
!safe_strcmp (type, URL_TYPE_FTP))
{
/* step 1: split the machine name away from the path
* components */
if (!regexec(&compiled_m, path, 4, match, 0))
{
/* $1 is the machine name */
if (match[1].rm_so != -1)
{
machine = g_strndup(path + match[1].rm_so,
match[1].rm_eo - match[1].rm_so);
}
/* $2 is the path */
if (match[2].rm_so != -1)
{
location = g_strndup(path + match[2].rm_so,
match[2].rm_eo - match[2].rm_so);
}
}
}
else
{
location = g_strdup(path);
}
/* step 2: split up the path into prefix and file components */
if (location)
{
if (!regexec(&compiled_p, location, 4, match, 0))
{
if (match[1].rm_so != -1)
{
base = g_strndup(location + match[1].rm_so,
match[1].rm_eo - match[1].rm_so);
}
else
{
base = NULL;
}
}
}
regfree(&compiled_m);
regfree(&compiled_p);
if (machine)
{
if (base && (strlen(base) > 0))
{
basename = g_strconcat(machine, "/", base, "/", NULL);
}
else
{
basename = g_strconcat(machine, "/", NULL);
}
}
else
{
if (base && (strlen(base) > 0))
{
basename = g_strdup(base);
}
else
{
basename = NULL;
}
}
g_free(machine);
g_free(base);
g_free(location);
return basename;
}
static gboolean
http_allowed()
{
return TRUE;
}
static gboolean
https_allowed()
{
return TRUE;
}
/************************************************************
* gnc_html_start_request: starts the gnc-http object working on an
* http/https request.
************************************************************/
static void
gnc_html_start_request( GncHtmlGtkhtml* self, gchar * uri, GtkHTMLStream * handle )
{
GList * handles = NULL;
gint need_request = FALSE;
GncHtmlGtkhtmlPrivate* priv = GNC_HTML_GTKHTML_GET_PRIVATE(self);
/* we want to make a list of handles to fill with this URI.
* multiple handles with the same URI will all get filled when the
* request comes in. */
DEBUG("requesting %s", uri);
handles = g_hash_table_lookup( priv->base.request_info, uri );
if ( handles == NULL )
{
need_request = TRUE;
}
handles = g_list_append( handles, handle );
g_hash_table_insert( priv->base.request_info, uri, handles );
if ( need_request )
{
g_critical("we've not supported network requests for years");
}
}
/********************************************************************
* gnc_html_load_to_stream : actually do the work of loading the HTML
* or binary data referenced by a URL and feeding it into the GtkHTML
* widget.
********************************************************************/
static void
gnc_html_load_to_stream( GncHtmlGtkhtml* self, GtkHTMLStream* handle,
URLType type, const gchar* location,
const gchar* label )
{
gchar* fdata = NULL;
int fdata_len = 0;
GncHtmlGtkhtmlPrivate* priv = GNC_HTML_GTKHTML_GET_PRIVATE(self);
DEBUG( "type %s, location %s, label %s", type ? type : "(null)",
location ? location : "(null)", label ? label : "(null)");
g_return_if_fail( self != NULL );
if ( gnc_html_stream_handlers != NULL )
{
GncHTMLStreamCB stream_handler;
stream_handler = g_hash_table_lookup( gnc_html_stream_handlers, type );
if ( stream_handler )
{
gboolean ok = stream_handler( location, &fdata, &fdata_len );
if ( ok )
{
fdata = fdata ? fdata : g_strdup( "" );
gtk_html_write( GTK_HTML(priv->html), handle, fdata, fdata_len );
gtk_html_end( GTK_HTML(priv->html), handle, GTK_HTML_STREAM_OK );
}
else
{
fdata = fdata ? fdata :
g_strdup_printf( error_404_format,
_(error_404_title), _(error_404_body) );
gtk_html_write( GTK_HTML(priv->html), handle, fdata, strlen(fdata) );
gtk_html_end( GTK_HTML(priv->html), handle, GTK_HTML_STREAM_ERROR );
}
g_free( fdata );
if ( label )
{
while ( gtk_events_pending() )
{
gtk_main_iteration();
}
gtk_html_jump_to_anchor( GTK_HTML(priv->html), label );
}
return;
}
}
do
{
if ( !safe_strcmp( type, URL_TYPE_SECURE ) ||
!safe_strcmp( type, URL_TYPE_HTTP ) )
{
if ( !safe_strcmp( type, URL_TYPE_SECURE ) )
{
if ( !https_allowed() )
{
gnc_error_dialog( priv->base.parent, "%s",
_("Secure HTTP access is disabled. "
"You can enable it in the Network section of "
"the Preferences dialog."));
break;
}
}
if ( !http_allowed() )
{
gnc_error_dialog( priv->base.parent, "%s",
_("Network HTTP access is disabled. "
"You can enable it in the Network section of "
"the Preferences dialog."));
}
else
{
char *fullurl;
fullurl = gnc_build_url( type, location, label );
gnc_html_start_request( self, fullurl, handle );
}
}
else
{
PWARN( "load_to_stream for inappropriate type\n"
"\turl = '%s#%s'\n",
location ? location : "(null)",
label ? label : "(null)" );
fdata = g_strdup_printf( error_404_format,
_(error_404_title), _(error_404_body) );
gtk_html_write( GTK_HTML(priv->html), handle, fdata, strlen (fdata) );
gtk_html_end( GTK_HTML(priv->html), handle, GTK_HTML_STREAM_ERROR );
g_free( fdata );
}
}
while ( FALSE );
}
/********************************************************************
* gnc_html_link_clicked_cb - called when user left-clicks on html
* anchor.
********************************************************************/
static void
gnc_html_link_clicked_cb( GtkHTML* html, const gchar* url, gpointer data )
{
URLType type;
gchar* location = NULL;
gchar* label = NULL;
GncHtmlGtkhtml* self = GNC_HTML_GTKHTML(data);
DEBUG("Clicked %s", url);
type = gnc_html_parse_url( GNC_HTML(self), url, &location, &label );
gnc_html_show_url( GNC_HTML(self), type, location, label, 0 );
g_free( location );
g_free( label );
}
/********************************************************************
* gnc_html_url_requested_cb - called when a URL needs to be
* loaded within the loading of a page (embedded image).
********************************************************************/
static void
gnc_html_url_requested_cb( GtkHTML* html, gchar* url,
GtkHTMLStream* handle, gpointer data )
{
URLType type;
gchar* location = NULL;
gchar* label = NULL;
GncHtmlGtkhtml* self = GNC_HTML_GTKHTML(data);
DEBUG( "requesting %s", url );
type = gnc_html_parse_url( GNC_HTML(self), url, &location, &label );
gnc_html_load_to_stream( self, handle, type, location, label );
g_free( location );
g_free( label );
}
/********************************************************************
* gnc_html_object_requested_cb - called when an applet needs to be
* loaded.
********************************************************************/
static gboolean
gnc_html_object_requested_cb( GtkHTML* html, GtkHTMLEmbedded* eb,
gpointer data )
{
GncHtmlGtkhtml* self = GNC_HTML_GTKHTML(data);
GncHTMLObjectCB h;
DEBUG( " " );
if ( !eb || !(eb->classid) || !gnc_html_object_handlers ) return FALSE;
gtkhtml_pre_3_10_1_bug_workaround( eb );
h = g_hash_table_lookup( gnc_html_object_handlers, eb->classid );
if ( h )
{
return h( GNC_HTML(self), eb, data );
}
else
{
return FALSE;
}
}
/********************************************************************
* gnc_html_on_url_cb - called when user rolls over html anchor
********************************************************************/
static void
gnc_html_on_url_cb( GtkHTML* html, const gchar* url, gpointer data )
{
GncHtmlGtkhtml* self = GNC_HTML_GTKHTML(data);
GncHtmlGtkhtmlPrivate* priv = GNC_HTML_GTKHTML_GET_PRIVATE(self);
DEBUG( "Rollover %s", url ? url : "(null)" );
g_free( priv->base.current_link );
priv->base.current_link = g_strdup( url );
if ( priv->base.flyover_cb )
{
(priv->base.flyover_cb)( GNC_HTML(self), url, priv->base.flyover_cb_data );
}
}
/********************************************************************
* gnc_html_set_base_cb
********************************************************************/
static void
gnc_html_set_base_cb( GtkHTML* gtkhtml, const gchar* base,
gpointer data )
{
GncHtmlGtkhtml* self = GNC_HTML_GTKHTML(data);
GncHtmlGtkhtmlPrivate* priv = GNC_HTML_GTKHTML_GET_PRIVATE(self);
URLType type;
gchar* location = NULL;
gchar* label = NULL;
DEBUG( "Setting base location to %s", base );
type = gnc_html_parse_url( GNC_HTML(self), base, &location, &label );
g_free( priv->base.base_location );
g_free( label );
priv->base.base_type = type;
priv->base.base_location = location;
}
/********************************************************************
* gnc_html_button_press_cb
* mouse button callback (if any)
********************************************************************/
static int
gnc_html_button_press_cb( GtkWidget* widg, GdkEventButton* event,
gpointer user_data )
{
GncHtmlGtkhtml* self = GNC_HTML_GTKHTML(user_data);
GncHtmlGtkhtmlPrivate* priv = GNC_HTML_GTKHTML_GET_PRIVATE(self);
DEBUG( "Button Press" );
if ( priv->base.button_cb != NULL )
{
(priv->base.button_cb)( GNC_HTML(self), event, priv->base.button_cb_data );
return TRUE;
}
else
{
return FALSE;
}
}
/********************************************************************
* gnc_html_open_scm
* insert some scheme-generated HTML
********************************************************************/
static void
gnc_html_open_scm( GncHtmlGtkhtml* self, const gchar * location,
const gchar * label, int newwin )
{
PINFO("location='%s'", location ? location : "(null)");
}
/********************************************************************
* gnc_html_show_data
* display some HTML that the creator of the gnc-html got from
* somewhere.
********************************************************************/
static void
impl_gtkhtml_show_data( GncHtml* self, const char * data, int datalen )
{
GtkHTMLStream * handle;
GncHtmlGtkhtmlPrivate* priv = GNC_HTML_GTKHTML_GET_PRIVATE(self);
DEBUG( "datalen %d, data %20.20s", datalen, data );
handle = gtk_html_begin( GTK_HTML(priv->html) );
gtk_html_write( GTK_HTML(priv->html), handle, data, datalen );
gtk_html_end( GTK_HTML(priv->html), handle, GTK_HTML_STREAM_OK );
}
/********************************************************************
* gnc_html_show_url
*
* open a URL. This is called when the user clicks a link or
* for the creator of the gnc_html window to explicitly request
* a URL.
********************************************************************/
static void
impl_gtkhtml_show_url( GncHtml* self, URLType type,
const gchar* location, const gchar* label,
gboolean new_window_hint )
{
GncHTMLUrlCB url_handler;
GtkHTMLStream * handle;
gboolean new_window;
GncHtmlGtkhtmlPrivate* priv = GNC_HTML_GTKHTML_GET_PRIVATE(self);
DEBUG(" ");
if ( self == NULL ) return;
if ( location == NULL ) return;
/* make sure it's OK to show this URL type in this window */
if ( new_window_hint == 0 )
{
if ( priv->base.urltype_cb )
{
new_window = !((priv->base.urltype_cb)( type ));
}
else
{
new_window = FALSE;
}
}
else
{
new_window = TRUE;
}
if ( !new_window )
{
gnc_html_cancel( GNC_HTML(self) );
}
if ( gnc_html_url_handlers )
{
url_handler = g_hash_table_lookup( gnc_html_url_handlers, type );
}
else
{
url_handler = NULL;
}
if ( url_handler )
{
GNCURLResult result;
gboolean ok;
result.load_to_stream = FALSE;
result.url_type = type;
result.location = NULL;
result.label = NULL;
result.base_type = URL_TYPE_FILE;
result.base_location = NULL;
result.error_message = NULL;
ok = url_handler( location, label, new_window, &result );
if ( !ok )
{
if ( result.error_message )
{
gnc_error_dialog( priv->base.parent, "%s", result.error_message );
}
else
{
/* %s is a URL (some location somewhere). */
gnc_error_dialog( priv->base.parent, _("There was an error accessing %s."), location );
}
if ( priv->base.load_cb )
{
priv->base.load_cb( GNC_HTML(self), result.url_type,
location, label, priv->base.load_cb_data );
}
}
else if ( result.load_to_stream )
{
gnc_html_history_node *hnode;
const char *new_location;
const char *new_label;
GtkHTMLStream * stream;
new_location = result.location ? result.location : location;
new_label = result.label ? result.label : label;
hnode = gnc_html_history_node_new( result.url_type, new_location, new_label );
gnc_html_history_append( priv->base.history, hnode );
g_free( priv->base.base_location );
priv->base.base_type = result.base_type;
priv->base.base_location =
g_strdup( extract_base_name( result.base_type, new_location ) );
DEBUG( "resetting base location to %s",
priv->base.base_location ? priv->base.base_location : "(null)" );
stream = gtk_html_begin( GTK_HTML(priv->html) );
gnc_html_load_to_stream( GNC_HTML_GTKHTML(self), stream, result.url_type,
new_location, new_label );
if ( priv->base.load_cb != NULL )
{
priv->base.load_cb( GNC_HTML(self), result.url_type,
new_location, new_label, priv->base.load_cb_data );
}
}
g_free( result.location );
g_free( result.label );
g_free( result.base_location );
g_free( result.error_message );
return;
}
if ( safe_strcmp( type, URL_TYPE_SCHEME ) == 0 )
{
gnc_html_open_scm( GNC_HTML_GTKHTML(self), location, label, new_window );
}
else if ( safe_strcmp( type, URL_TYPE_JUMP ) == 0 )
{
gtk_html_jump_to_anchor( GTK_HTML(priv->html), label );
}
else if ( safe_strcmp( type, URL_TYPE_SECURE ) == 0 ||
safe_strcmp( type, URL_TYPE_HTTP ) == 0 ||
safe_strcmp( type, URL_TYPE_FILE ) == 0 )
{
do
{
if ( safe_strcmp( type, URL_TYPE_SECURE ) == 0 )
{
if ( !https_allowed() )
{
gnc_error_dialog( priv->base.parent, "%s",
_("Secure HTTP access is disabled. "
"You can enable it in the Network section of "
"the Preferences dialog.") );
break;
}
}
if ( safe_strcmp( type, URL_TYPE_HTTP ) == 0 )
{
if ( !http_allowed() )
{
gnc_error_dialog( priv->base.parent, "%s",
_("Network HTTP access is disabled. "
"You can enable it in the Network section of "
"the Preferences dialog.") );
break;
}
}
priv->base.base_type = type;
if ( priv->base.base_location != NULL ) g_free( priv->base.base_location );
priv->base.base_location = extract_base_name( type, location );
/* FIXME : handle new_window = 1 */
gnc_html_history_append( priv->base.history,
gnc_html_history_node_new( type, location, label ) );
handle = gtk_html_begin( GTK_HTML(priv->html) );
gnc_html_load_to_stream( GNC_HTML_GTKHTML(self), handle, type, location, label );
}
while ( FALSE );
}
else
{
PERR( "URLType %s not supported.", type );
}
if ( priv->base.load_cb != NULL )
{
(priv->base.load_cb)( GNC_HTML(self), type, location, label, priv->base.load_cb_data );
}
}
/********************************************************************
* gnc_html_reload
* reload the current page
********************************************************************/
static void
impl_gtkhtml_reload( GncHtml* self )
{
GncHtmlGtkhtmlPrivate* priv = GNC_HTML_GTKHTML_GET_PRIVATE(self);
gnc_html_history_node * n;
DEBUG(" ");
n = gnc_html_history_get_current( priv->base.history );
if ( n != NULL )
{
gnc_html_show_url( self, n->type, n->location, n->label, 0 );
}
}
/********************************************************************
* gnc_html_gtkhtml_new
* create and set up a new gtkhtml widget.
********************************************************************/
GncHtml*
gnc_html_gtkhtml_new( void )
{
GncHtmlGtkhtml* self = g_object_new( GNC_TYPE_HTML_GTKHTML, NULL );
GncHtmlGtkhtmlPrivate* priv = GNC_HTML_GTKHTML_GET_PRIVATE(self);
return GNC_HTML(self);
}
/********************************************************************
* gnc_html_cancel
* cancel any outstanding HTML fetch requests.
********************************************************************/
static gboolean
gtkhtml_cancel_helper(gpointer key, gpointer value, gpointer user_data)
{
g_free(key);
g_list_free((GList *)value);
return TRUE;
}
static void
impl_gtkhtml_cancel( GncHtml* self )
{
GncHtmlGtkhtmlPrivate* priv = GNC_HTML_GTKHTML_GET_PRIVATE(self);
/* remove our own references to requests */
//gnc_http_cancel_requests( priv->http );
g_hash_table_foreach_remove( priv->base.request_info, gtkhtml_cancel_helper, NULL );
}
static void
impl_gtkhtml_copy_to_clipboard( GncHtml* self )
{
GncHtmlGtkhtmlPrivate* priv;
g_return_if_fail( self != NULL );
priv = GNC_HTML_GTKHTML_GET_PRIVATE(self);
gtk_html_copy( GTK_HTML(priv->html) );
}
/**************************************************************
* gnc_html_export_to_file : wrapper around the builtin function in gtkhtml
**************************************************************/
static gboolean
raw_html_receiver( gpointer engine,
const gchar* data,
size_t len,
gpointer user_data )
{
FILE *fh = (FILE *) user_data;
size_t written;
do
{
written = fwrite (data, 1, len, fh);
len -= written;
}
while (len > 0);
return TRUE;
}
static gboolean
impl_gtkhtml_export_to_file( GncHtml* self, const char *filepath )
{
FILE *fh;
GncHtmlGtkhtmlPrivate* priv;
g_return_val_if_fail( self != NULL, FALSE );
g_return_val_if_fail( filepath != NULL, FALSE );
priv = GNC_HTML_GTKHTML_GET_PRIVATE(self);
fh = g_fopen( filepath, "w" );
if ( fh == 0 )
return FALSE;
gtk_html_save( GTK_HTML(priv->html), GINT_TO_POINTER(raw_html_receiver), fh );
fclose (fh);
return TRUE;
}
static void
draw_page_cb(GtkPrintOperation *operation, GtkPrintContext *context,
gint page_nr, gpointer user_data)
{
GncHtmlGtkhtml* self = GNC_HTML_GTKHTML(user_data);
GncHtmlGtkhtmlPrivate* priv;
priv = GNC_HTML_GTKHTML_GET_PRIVATE(self);
gtk_html_print_page( GTK_HTML(priv->html), context );
}
static void
impl_gtkhtml_print( GncHtml* self, const gchar* jobname )
{
GtkPrintOperation *print;
GtkPrintOperationResult res;
GncHtmlGtkhtmlPrivate* priv;
priv = GNC_HTML_GTKHTML_GET_PRIVATE(self);
print = gtk_print_operation_new();
gnc_print_operation_init(print, jobname);
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 );
}
g_object_unref(print);
}
static void
impl_gtkhtml_set_parent( GncHtml* self, GtkWindow* parent )
{
GncHtmlGtkhtmlPrivate* priv;
g_return_if_fail( self != NULL );
priv = GNC_HTML_GTKHTML_GET_PRIVATE(self);
priv->base.parent = GTK_WIDGET(parent);
}
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);
}
static void
gtkhtml_pre_3_10_1_bug_workaround(GtkHTMLEmbedded *eb)
{
/* HACK ALERT! Compensate for bug in gtkhtml < 3.10.1
Gtkhtml set the width parameter twice (=width, =height), so both,
width (==height) and height (<1) were incorrect. */
if ( eb->height < 1 )
{
eb->height = eb->width; /* only squares here :( */
}
}

View File

@ -1,61 +0,0 @@
/********************************************************************
* gnc-html-gtkhtml.h -- display html with gnc special tags *
* Copyright (C) 2000 Bill Gribble <grib@billgribble.com> *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 2 of *
* the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License*
* along with this program; if not, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
* Boston, MA 02110-1301, USA gnu@gnu.org *
\********************************************************************/
#ifndef GNC_HTML_GTKHTML_H
#define GNC_HTML_GTKHTML_H
#include <glib-object.h>
#include "gnc-html.h"
G_BEGIN_DECLS
#define GNC_TYPE_HTML_GTKHTML (gnc_html_gtkhtml_get_type())
#define GNC_HTML_GTKHTML(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_HTML_GTKHTML, GncHtmlGtkhtml))
#define GNC_HTML_GTKHTML_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_HTML_GTKHTML, GncHtmlGtkhtmlClass))
#define GNC_IS_HTML_GTKHTML(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), GNC_TYPE_HTML_GTKHTML))
#define GNC_IS_HTML_GTKHTML_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE((k), GNC_TYPE_HTML_GTKHTML))
#define GNC_HTML_GTKHTML_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS((o), GNC_TYPE_HTML_GTKHTML, GncHtmlGtkhtmlClass))
typedef struct _GncHtmlGtkhtml GncHtmlGtkhtml;
typedef struct _GncHtmlGtkhtmlClass GncHtmlGtkhtmlClass;
typedef struct _GncHtmlGtkhtmlPrivate GncHtmlGtkhtmlPrivate;
struct _GncHtmlGtkhtml
{
GncHtml parent_instance;
/*< private >*/
GncHtmlGtkhtmlPrivate* priv;
};
struct _GncHtmlGtkhtmlClass
{
GncHtmlClass parent_class;
};
GType gnc_html_gtkhtml_get_type( void );
GncHtml* gnc_html_gtkhtml_new( void );
G_END_DECLS
#endif

View File

@ -26,7 +26,7 @@
struct _GncHtmlPrivate
{
GtkWidget* parent; /* window this html goes into */
GtkWidget* container; /* parent of the gtkhtml widget */
GtkWidget* container; /* parent of the webkit widget */
gchar* current_link; /* link under mouse pointer */
URLType base_type; /* base of URL (path - filename) */

View File

@ -396,7 +396,7 @@ handle_embedded_object( GncHtmlWebkit* self, gchar* html_str )
/********************************************************************
* load_to_stream : actually do the work of loading the HTML
* or binary data referenced by a URL and feeding it into the GtkHTML
* or binary data referenced by a URL and feeding it into the webkit
* widget.
********************************************************************/

View File

@ -26,7 +26,7 @@
/**
* A GncHtml object is an abstract base for an html engine used to display reports and
* charts in gnucash. It must be overridden to create specific objects using specific
* html engines (e.g. gtkhtml, webkit).
* html engines (e.g. webkit).
*/
#include <glib-object.h>