30 #define _GL_UNISTD_H //Deflect poisonous define of close in Guile's GnuLib 38 #include <glib/gi18n.h> 39 #include <glib/gstdio.h> 40 #include <sys/types.h> 49 #include <webkit2/webkit2.h> 53 #include "gnc-gui-query.h" 56 #include "gnc-html-webkit.h" 57 #include "gnc-html-history.h" 61 G_DEFINE_TYPE(GncHtmlWebkit, gnc_html_webkit, GNC_TYPE_HTML )
63 static void gnc_html_webkit_dispose( GObject* obj );
64 static void gnc_html_webkit_finalize( GObject* obj );
66 #define GNC_HTML_WEBKIT_GET_PRIVATE(o) (GNC_HTML_WEBKIT(o)->priv) 68 #include "gnc-html-webkit-p.h" 71 static QofLogModule log_module = GNC_MOD_HTML;
78 extern GHashTable* gnc_html_object_handlers;
81 extern GHashTable* gnc_html_stream_handlers;
84 extern GHashTable* gnc_html_url_handlers;
86 static char error_404_format[] =
"<html><body><h3>%s</h3><p>%s</body></html>";
87 static char error_404_title[] = N_(
"Not found");
88 static char error_404_body[] = N_(
"The specified URL could not be loaded.");
90 #define BASE_URI_NAME "base-uri" 91 #define GNC_PREF_RPT_DFLT_ZOOM "default-zoom" 93 static gboolean webkit_decide_policy_cb (WebKitWebView* web_view,
94 WebKitPolicyDecision *decision,
95 WebKitPolicyDecisionType decision_type,
97 static void webkit_mouse_target_cb (WebKitWebView* web_view,
98 WebKitHitTestResult *hit,
99 guint modifiers, gpointer data);
100 static gboolean webkit_notification_cb (WebKitWebView *web_view,
101 WebKitNotification *note,
103 static gboolean webkit_load_failed_cb (WebKitWebView *web_view,
104 WebKitLoadEvent event,
105 gchar *uri, GError *error,
107 static void webkit_resource_load_started_cb (WebKitWebView *web_view,
108 WebKitWebResource *resource,
109 WebKitURIRequest *request,
111 static gchar* handle_embedded_object( GncHtmlWebkit*
self, gchar* html_str );
112 static void impl_webkit_show_url( GncHtml*
self, URLType type,
113 const gchar* location,
const gchar* label,
114 gboolean new_window_hint );
115 static void impl_webkit_show_data( GncHtml*
self,
const gchar* data,
int datalen );
116 static void impl_webkit_reload( GncHtml*
self, gboolean force_rebuild );
117 static void impl_webkit_copy_to_clipboard( GncHtml*
self );
118 static gboolean impl_webkit_export_to_file( GncHtml*
self,
const gchar* filepath );
119 static void impl_webkit_print (GncHtml*
self,
const gchar* jobname);
120 static void impl_webkit_cancel( GncHtml*
self );
121 static void impl_webkit_set_parent( GncHtml*
self, GtkWindow* parent );
122 static void impl_webkit_default_zoom_changed(gpointer prefs, gchar *pref, gpointer user_data);
125 gnc_html_webkit_webview_new (
void)
127 GtkWidget *view = webkit_web_view_new ();
128 WebKitSettings *webkit_settings = NULL;
129 const char *default_font_family = NULL;
130 GtkStyleContext *style = gtk_widget_get_style_context (view);
131 GValue val = G_VALUE_INIT;
132 GtkStateFlags state = gtk_style_context_get_state (style);
133 gtk_style_context_get_property (style, GTK_STYLE_PROPERTY_FONT,
136 if (G_VALUE_HOLDS_BOXED (&val))
138 const PangoFontDescription *font =
139 (
const PangoFontDescription*)g_value_get_boxed (&val);
140 default_font_family = pango_font_description_get_family (font);
143 webkit_settings = webkit_web_view_get_settings (WEBKIT_WEB_VIEW (view));
144 g_object_set (G_OBJECT(webkit_settings),
145 "default-charset",
"utf-8",
146 "allow-file-access-from-file-urls", TRUE,
147 "allow-universal-access-from-file-urls", TRUE,
148 "enable-java", FALSE,
149 "enable-page-cache", FALSE,
150 "enable-plugins", FALSE,
151 "enable-site-specific-quirks", FALSE,
152 "enable-xss-auditor", FALSE,
153 "enable-developer-extras", TRUE,
155 if (default_font_family != NULL)
157 g_object_set (G_OBJECT (webkit_settings),
158 "default-font-family", default_font_family, NULL);
160 g_value_unset (&val);
165 gnc_html_webkit_init( GncHtmlWebkit*
self )
167 GncHtmlWebkitPrivate* priv;
168 GncHtmlWebkitPrivate* new_priv;
171 new_priv = g_realloc (GNC_HTML(
self)->priv,
sizeof(GncHtmlWebkitPrivate));
172 priv =
self->priv = new_priv;
173 GNC_HTML(
self)->priv = (GncHtmlPrivate*)priv;
175 priv->html_string = NULL;
176 priv->web_view = WEBKIT_WEB_VIEW (gnc_html_webkit_webview_new ());
181 GNC_PREF_RPT_DFLT_ZOOM);
182 webkit_web_view_set_zoom_level (priv->web_view, zoom);
185 gtk_container_add( GTK_CONTAINER(priv->base.container),
186 GTK_WIDGET(priv->web_view) );
188 g_object_ref_sink( priv->base.container );
191 g_signal_connect (priv->web_view,
"decide-policy",
192 G_CALLBACK (webkit_decide_policy_cb),
195 g_signal_connect (priv->web_view,
"mouse-target-changed",
196 G_CALLBACK (webkit_mouse_target_cb),
199 g_signal_connect (priv->web_view,
"show-notification",
200 G_CALLBACK (webkit_notification_cb),
203 g_signal_connect (priv->web_view,
"load-failed",
204 G_CALLBACK (webkit_load_failed_cb),
206 g_signal_connect (priv->web_view,
"resource-load-started",
207 G_CALLBACK (webkit_resource_load_started_cb),
210 GNC_PREF_RPT_DFLT_ZOOM,
211 impl_webkit_default_zoom_changed,
214 LEAVE(
"retval %p",
self);
218 gnc_html_webkit_class_init( GncHtmlWebkitClass* klass )
220 GObjectClass* gobject_class = G_OBJECT_CLASS(klass);
221 GncHtmlClass* html_class = GNC_HTML_CLASS(klass);
223 gobject_class->dispose = gnc_html_webkit_dispose;
224 gobject_class->finalize = gnc_html_webkit_finalize;
226 html_class->show_url = impl_webkit_show_url;
227 html_class->show_data = impl_webkit_show_data;
228 html_class->reload = impl_webkit_reload;
229 html_class->copy_to_clipboard = impl_webkit_copy_to_clipboard;
230 html_class->export_to_file = impl_webkit_export_to_file;
231 html_class->print = impl_webkit_print;
232 html_class->cancel = impl_webkit_cancel;
233 html_class->set_parent = impl_webkit_set_parent;
237 gnc_html_webkit_dispose( GObject* obj )
239 GncHtmlWebkit*
self = GNC_HTML_WEBKIT(obj);
240 GncHtmlWebkitPrivate* priv = GNC_HTML_WEBKIT_GET_PRIVATE(
self);
242 if ( priv->web_view != NULL )
244 gtk_container_remove (GTK_CONTAINER(priv->base.container),
245 GTK_WIDGET(priv->web_view));
247 priv->web_view = NULL;
250 if ( priv->html_string != NULL )
252 g_free( priv->html_string );
253 priv->html_string = NULL;
257 GNC_PREF_RPT_DFLT_ZOOM,
258 impl_webkit_default_zoom_changed,
261 G_OBJECT_CLASS(gnc_html_webkit_parent_class)->dispose( obj );
265 gnc_html_webkit_finalize( GObject* obj )
267 GncHtmlWebkit*
self = GNC_HTML_WEBKIT(obj);
274 G_OBJECT_CLASS(gnc_html_webkit_parent_class)->finalize( obj );
280 extract_base_name(URLType type,
const gchar* path)
282 gchar machine_rexp[] =
"^(//[^/]*)/*(/.*)?$";
283 gchar path_rexp[] =
"^/*(.*)/+([^/]*)$";
284 regex_t compiled_m, compiled_p;
286 gchar * machine = NULL, * location = NULL, * base = NULL;
287 gchar * basename = NULL;
290 if (!path)
return NULL;
292 regcomp(&compiled_m, machine_rexp, REG_EXTENDED);
293 regcomp(&compiled_p, path_rexp, REG_EXTENDED);
295 if (!g_strcmp0 (type, URL_TYPE_HTTP) ||
296 !g_strcmp0 (type, URL_TYPE_SECURE) ||
297 !g_strcmp0 (type, URL_TYPE_FTP))
302 if (!regexec(&compiled_m, path, 4, match, 0))
305 if (match[1].rm_so != -1)
307 machine = g_strndup(path + match[1].rm_so,
308 match[1].rm_eo - match[1].rm_so);
311 if (match[2].rm_so != -1)
313 location = g_strndup(path + match[2].rm_so,
314 match[2].rm_eo - match[2].rm_so);
320 location = g_strdup(path);
325 if (!regexec(&compiled_p, location, 4, match, 0))
327 if (match[1].rm_so != -1)
329 base = g_strndup(location + match[1].rm_so,
330 match[1].rm_eo - match[1].rm_so);
339 regfree(&compiled_m);
340 regfree(&compiled_p);
344 if (base && (strlen(base) > 0))
346 basename = g_strconcat(machine,
"/", base,
"/", NULL);
350 basename = g_strconcat(machine,
"/", NULL);
355 if (base && (strlen(base) > 0))
357 basename = g_strdup(base);
384 handle_embedded_object( GncHtmlWebkit*
self, gchar* html_str )
389 gchar* remainder_str = html_str;
391 gchar* end_object_tag;
392 gchar* object_contents;
393 gchar* html_str_start = NULL;
394 gchar* html_str_middle;
395 gchar* html_str_result = NULL;
396 gchar* classid_start;
402 object_tag = g_strstr_len( remainder_str, -1,
"<object classid=" );
406 classid_start = object_tag + strlen(
"<object classid=" ) + 1;
407 classid_end = g_strstr_len( classid_start, -1,
"\"" );
408 classid_str = g_strndup( classid_start, (classid_end - classid_start) );
410 end_object_tag = g_strstr_len( object_tag, -1,
"</object>" );
411 if ( end_object_tag == NULL )
415 g_free (classid_str);
416 g_free (html_str_result);
417 return g_strdup (html_str);
419 end_object_tag += strlen(
"</object>" );
420 object_contents = g_strndup( object_tag, (end_object_tag - object_tag) );
422 h = g_hash_table_lookup( gnc_html_object_handlers, classid_str );
425 (void)h( GNC_HTML(
self), object_contents, &html_str_middle );
429 html_str_middle = g_strdup_printf(
"No handler found for classid \"%s\"", classid_str );
432 html_str_start = html_str_result;
433 new_chunk = g_strndup (remainder_str, (object_tag - remainder_str));
435 html_str_result = g_strconcat (new_chunk, html_str_middle, NULL);
437 html_str_result = g_strconcat (html_str_start, new_chunk, html_str_middle, NULL);
439 g_free( html_str_start );
441 g_free( html_str_middle );
443 remainder_str = end_object_tag;
444 object_tag = g_strstr_len( remainder_str, -1,
"<object classid=" );
449 html_str_start = html_str_result;
450 html_str_result = g_strconcat (html_str_start, remainder_str, NULL);
451 g_free (html_str_start);
454 html_str_result = g_strdup (remainder_str);
456 return html_str_result;
466 load_to_stream( GncHtmlWebkit*
self, URLType type,
467 const gchar* location,
const gchar* label )
471 GncHtmlWebkitPrivate* priv = GNC_HTML_WEBKIT_GET_PRIVATE(
self);
473 DEBUG(
"type %s, location %s, label %s", type ? type :
"(null)",
474 location ? location :
"(null)", label ? label :
"(null)");
476 g_return_val_if_fail(
self != NULL, FALSE );
478 if ( gnc_html_stream_handlers != NULL )
480 GncHTMLStreamCB stream_handler;
482 stream_handler = g_hash_table_lookup( gnc_html_stream_handlers, type );
483 if ( stream_handler )
485 GncHtml *weak_html = GNC_HTML(
self);
488 g_object_add_weak_pointer(G_OBJECT(
self),
489 (gpointer*)(&weak_html));
490 ok = stream_handler( location, &fdata, &fdata_len );
499 g_object_remove_weak_pointer(G_OBJECT(
self),
500 (gpointer*)(&weak_html));
505 fdata = fdata ? fdata : g_strdup(
"" );
511 if ( g_strstr_len( fdata, -1,
"<object classid=" ) != NULL )
514 new_fdata = handle_embedded_object(
self, fdata );
520 if ( priv->html_string != NULL )
522 g_free( priv->html_string );
524 priv->html_string = g_strdup( fdata );
525 impl_webkit_show_data( GNC_HTML(
self), fdata, strlen(fdata) );
531 fdata = fdata ? fdata :
532 g_strdup_printf( error_404_format,
533 _(error_404_title), _(error_404_body) );
534 webkit_web_view_load_html (priv->web_view, fdata,
542 while ( gtk_events_pending() )
544 gtk_main_iteration();
554 if ( !g_strcmp0( type, URL_TYPE_SECURE ) ||
555 !g_strcmp0( type, URL_TYPE_HTTP ) )
558 if ( !g_strcmp0( type, URL_TYPE_SECURE ) )
560 if ( !https_allowed() )
562 gnc_error_dialog (GTK_WINDOW (priv->base.parent),
"%s",
563 _(
"Secure HTTP access is disabled. " 564 "You can enable it in the Network section of " 565 "the Preferences dialog."));
570 if ( !http_allowed() )
572 gnc_error_dialog (GTK_WINDOW (priv->base.parent),
"%s",
573 _(
"Network HTTP access is disabled. " 574 "You can enable it in the Network section of " 575 "the Preferences dialog."));
579 gnc_build_url( type, location, label );
584 PWARN(
"load_to_stream for inappropriate type\n" 586 location ? location :
"(null)",
587 label ? label :
"(null)" );
588 fdata = g_strdup_printf( error_404_format,
589 _(error_404_title), _(error_404_body) );
590 webkit_web_view_load_html (priv->web_view, fdata, BASE_URI_NAME);
599 perform_navigation_policy (WebKitWebView *web_view,
600 WebKitNavigationPolicyDecision *decision,
603 WebKitURIRequest *req = NULL;
604 const gchar* uri, *scheme;
605 gchar *location = NULL, *label = NULL;
606 gboolean ignore = FALSE;
607 WebKitNavigationAction *action =
608 webkit_navigation_policy_decision_get_navigation_action (decision);
609 if (webkit_navigation_action_get_navigation_type (action) !=
610 WEBKIT_NAVIGATION_TYPE_LINK_CLICKED)
612 webkit_policy_decision_use ((WebKitPolicyDecision*)decision);
615 req = webkit_navigation_action_get_request (action);
616 uri = webkit_uri_request_get_uri (req);
617 scheme = gnc_html_parse_url (
self, uri, &location, &label);
618 if (strcmp (scheme, URL_TYPE_FILE) != 0)
620 impl_webkit_show_url (
self, scheme, location, label, FALSE);
626 webkit_policy_decision_ignore ((WebKitPolicyDecision*)decision);
628 webkit_policy_decision_use ((WebKitPolicyDecision*)decision);
633 webkit_decide_policy_cb (WebKitWebView *web_view,
634 WebKitPolicyDecision *decision,
635 WebKitPolicyDecisionType decision_type,
639 if (decision_type != WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION)
641 webkit_policy_decision_use (decision);
644 return perform_navigation_policy (
645 web_view, (WebKitNavigationPolicyDecision*) decision,
646 GNC_HTML (user_data));
650 webkit_mouse_target_cb (WebKitWebView *web_view, WebKitHitTestResult *hit,
651 guint modifiers, gpointer user_data)
653 GncHtmlWebkitPrivate* priv;
654 GncHtmlWebkit *
self = (GncHtmlWebkit*)user_data;
657 if (!webkit_hit_test_result_context_is_link (hit))
660 priv = GNC_HTML_WEBKIT_GET_PRIVATE (
self);
661 uri = g_strdup (webkit_hit_test_result_get_link_uri (hit));
662 g_free (priv->base.current_link);
663 priv->base.current_link = uri;
664 if (priv->base.flyover_cb)
666 (priv->base.flyover_cb) (GNC_HTML (
self), uri,
667 priv->base.flyover_cb_data);
671 webkit_notification_cb (WebKitWebView* web_view, WebKitNotification *note,
674 GtkWindow *top = NULL;
675 GtkWidget *dialog = NULL;
676 GncHtmlWebkit *
self = (GncHtmlWebkit*)user_data;
677 g_return_val_if_fail (
self != NULL, FALSE);
678 g_return_val_if_fail (note != NULL, FALSE);
680 top = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (web_view)));
681 dialog = gtk_message_dialog_new (top, GTK_DIALOG_MODAL,
682 GTK_MESSAGE_WARNING, GTK_BUTTONS_CLOSE,
684 webkit_notification_get_title (note),
685 webkit_notification_get_body (note));
686 gtk_dialog_run (GTK_DIALOG (dialog));
687 gtk_widget_destroy (dialog);
692 webkit_load_failed_cb (WebKitWebView *web_view, WebKitLoadEvent event,
693 gchar *uri, GError *error, gpointer user_data)
695 PERR (
"WebKit load of %s failed due to %s\n", uri, error->message);
699 webkit_resource_load_failed_cb (WebKitWebResource *resource,
703 WebKitURIResponse *response = webkit_web_resource_get_response (resource);
704 const gchar * uri = webkit_web_resource_get_uri (resource);
705 PERR (
"Load of resource at %s failed with error %s and status code %d.\n",
706 uri, error->message, webkit_uri_response_get_status_code (response));
710 webkit_resource_load_finished_cb (WebKitWebResource *resource, gpointer data)
712 DEBUG (
"Load of resource %s completed.\n", webkit_web_resource_get_uri(resource));
716 webkit_resource_load_started_cb (WebKitWebView *web_view,
717 WebKitWebResource *resource,
718 WebKitURIRequest *request,
721 DEBUG (
"Load of resource %s begun.\n", webkit_web_resource_get_uri(resource));
722 g_signal_connect (resource,
"failed",
723 G_CALLBACK (webkit_resource_load_failed_cb),
725 g_signal_connect (resource,
"finished",
726 G_CALLBACK (webkit_resource_load_finished_cb),
736 gnc_html_open_scm( GncHtmlWebkit*
self,
const gchar * location,
737 const gchar * label,
int newwin )
739 PINFO(
"location='%s'", location ? location :
"(null)");
750 impl_webkit_show_data( GncHtml*
self,
const gchar* data,
int datalen )
752 GncHtmlWebkitPrivate* priv;
753 #define TEMPLATE_REPORT_FILE_NAME "gnc-report-XXXXXX.html" 758 g_return_if_fail(
self != NULL );
759 g_return_if_fail( GNC_IS_HTML_WEBKIT(
self) );
761 ENTER(
"datalen %d, data %20.20s", datalen, data );
763 priv = GNC_HTML_WEBKIT_GET_PRIVATE(
self);
770 filename = g_build_filename(g_get_tmp_dir(), TEMPLATE_REPORT_FILE_NAME, (gchar *)NULL);
771 fd = g_mkstemp( filename );
772 impl_webkit_export_to_file(
self, filename );
774 uri = g_strdup_printf(
"file://%s", filename );
776 DEBUG(
"Loading uri '%s'", uri);
777 webkit_web_view_load_uri( priv->web_view, uri );
792 impl_webkit_show_url( GncHtml*
self, URLType type,
793 const gchar* location,
const gchar* label,
794 gboolean new_window_hint )
796 GncHTMLUrlCB url_handler;
798 GncHtmlWebkitPrivate* priv;
799 gboolean stream_loaded = FALSE;
801 g_return_if_fail(
self != NULL );
802 g_return_if_fail( GNC_IS_HTML_WEBKIT(
self) );
803 g_return_if_fail( location != NULL );
805 priv = GNC_HTML_WEBKIT_GET_PRIVATE(
self);
808 if ( new_window_hint == 0 )
810 if ( priv->base.urltype_cb )
812 new_window = !((priv->base.urltype_cb)( type ));
826 gnc_html_cancel( GNC_HTML(
self) );
829 if ( gnc_html_url_handlers )
831 url_handler = g_hash_table_lookup( gnc_html_url_handlers, type );
843 result.load_to_stream = FALSE;
844 result.url_type = type;
845 result.location = NULL;
847 result.base_type = URL_TYPE_FILE;
848 result.base_location = NULL;
849 result.error_message = NULL;
850 result.parent = GTK_WINDOW (priv->base.parent);
852 ok = url_handler( location, label, new_window, &result );
855 if ( result.error_message )
857 gnc_error_dialog (GTK_WINDOW (priv->base.parent),
"%s", result.error_message );
862 gnc_error_dialog (GTK_WINDOW (priv->base.parent), _(
"There was an error accessing %s."), location );
865 if ( priv->base.load_cb )
867 priv->base.load_cb( GNC_HTML(
self), result.url_type,
868 location, label, priv->base.load_cb_data );
871 else if ( result.load_to_stream )
873 gnc_html_history_node *hnode;
874 const char *new_location;
875 const char *new_label;
877 new_location = result.location ? result.location : location;
878 new_label = result.label ? result.label : label;
879 hnode = gnc_html_history_node_new( result.url_type, new_location, new_label );
881 gnc_html_history_append( priv->base.history, hnode );
883 g_free( priv->base.base_location );
884 priv->base.base_type = result.base_type;
885 priv->base.base_location =
886 g_strdup( extract_base_name( result.base_type, new_location ) );
887 DEBUG(
"resetting base location to %s",
888 priv->base.base_location ? priv->base.base_location :
"(null)" );
890 stream_loaded = load_to_stream( GNC_HTML_WEBKIT(
self),
892 new_location, new_label );
894 if ( stream_loaded && priv->base.load_cb != NULL )
896 priv->base.load_cb( GNC_HTML(
self), result.url_type,
897 new_location, new_label, priv->base.load_cb_data );
901 g_free( result.location );
902 g_free( result.label );
903 g_free( result.base_location );
904 g_free( result.error_message );
909 if ( g_strcmp0( type, URL_TYPE_SCHEME ) == 0 )
911 gnc_html_open_scm( GNC_HTML_WEBKIT(
self), location, label, new_window );
914 else if ( g_strcmp0( type, URL_TYPE_JUMP ) == 0 )
918 else if ( g_strcmp0( type, URL_TYPE_SECURE ) == 0 ||
919 g_strcmp0( type, URL_TYPE_HTTP ) == 0 ||
920 g_strcmp0( type, URL_TYPE_FILE ) == 0 )
925 if ( g_strcmp0( type, URL_TYPE_SECURE ) == 0 )
927 if ( !https_allowed() )
929 gnc_error_dialog (GTK_WINDOW (priv->base.parent),
"%s",
930 _(
"Secure HTTP access is disabled. " 931 "You can enable it in the Network section of " 932 "the Preferences dialog.") );
937 if ( g_strcmp0( type, URL_TYPE_HTTP ) == 0 )
939 if ( !http_allowed() )
941 gnc_error_dialog (GTK_WINDOW (priv->base.parent),
"%s",
942 _(
"Network HTTP access is disabled. " 943 "You can enable it in the Network section of " 944 "the Preferences dialog.") );
949 priv->base.base_type = type;
951 if ( priv->base.base_location != NULL ) g_free( priv->base.base_location );
952 priv->base.base_location = extract_base_name( type, location );
955 gnc_html_history_append( priv->base.history,
956 gnc_html_history_node_new( type, location, label ) );
957 stream_loaded = load_to_stream( GNC_HTML_WEBKIT(
self),
958 type, location, label );
965 PERR(
"URLType %s not supported.", type );
968 if ( stream_loaded && priv->base.load_cb != NULL )
970 (priv->base.load_cb)( GNC_HTML(
self), type, location, label, priv->base.load_cb_data );
983 impl_webkit_reload( GncHtml*
self, gboolean force_rebuild )
985 GncHtmlWebkitPrivate* priv;
987 g_return_if_fail(
self != NULL );
988 g_return_if_fail( GNC_IS_HTML_WEBKIT(
self) );
990 priv = GNC_HTML_WEBKIT_GET_PRIVATE(
self);
994 gnc_html_history_node *n = gnc_html_history_get_current( priv->base.history );
996 gnc_html_show_url(
self, n->type, n->location, n->label, 0 );
999 webkit_web_view_reload( priv->web_view );
1009 gnc_html_webkit_new(
void )
1011 GncHtmlWebkit*
self = g_object_new( GNC_TYPE_HTML_WEBKIT, NULL );
1012 return GNC_HTML(
self);
1021 webkit_cancel_helper(gpointer key, gpointer value, gpointer user_data)
1024 g_list_free((GList *)value);
1029 impl_webkit_cancel( GncHtml*
self )
1031 GncHtmlWebkitPrivate* priv;
1033 g_return_if_fail(
self != NULL );
1034 g_return_if_fail( GNC_IS_HTML_WEBKIT(
self) );
1036 priv = GNC_HTML_WEBKIT_GET_PRIVATE(
self);
1041 g_hash_table_foreach_remove( priv->base.request_info, webkit_cancel_helper, NULL );
1045 impl_webkit_copy_to_clipboard( GncHtml*
self )
1047 GncHtmlWebkitPrivate* priv;
1049 g_return_if_fail(
self != NULL );
1050 g_return_if_fail( GNC_IS_HTML_WEBKIT(
self) );
1052 priv = GNC_HTML_WEBKIT_GET_PRIVATE(
self);
1053 webkit_web_view_execute_editing_command (priv->web_view,
1054 WEBKIT_EDITING_COMMAND_COPY);
1065 impl_webkit_export_to_file( GncHtml*
self,
const char *filepath )
1068 GncHtmlWebkitPrivate* priv;
1070 g_return_val_if_fail(
self != NULL, FALSE );
1071 g_return_val_if_fail( GNC_IS_HTML_WEBKIT(
self), FALSE );
1072 g_return_val_if_fail( filepath != NULL, FALSE );
1074 priv = GNC_HTML_WEBKIT_GET_PRIVATE(
self);
1075 if ( priv->html_string == NULL )
1079 fh = g_fopen( filepath,
"w" );
1083 gint len = strlen( priv->html_string );
1085 written = fwrite( priv->html_string, 1, len, fh );
1088 if ( written != len )
1116 impl_webkit_print (GncHtml*
self,
const gchar* jobname)
1118 WebKitPrintOperation *op = NULL;
1119 GtkWindow *top = NULL;
1120 GncHtmlWebkitPrivate *priv;
1121 GtkPrintSettings *print_settings = NULL;
1122 WebKitPrintOperationResponse print_response;
1123 gchar *export_dirname = NULL;
1124 gchar *export_filename = NULL;
1125 gchar* basename = NULL;
1127 g_return_if_fail (
self != NULL);
1128 g_return_if_fail (GNC_IS_HTML_WEBKIT (
self));
1129 priv = GNC_HTML_WEBKIT_GET_PRIVATE (
self);
1130 op = webkit_print_operation_new (priv->web_view);
1131 basename = g_path_get_basename(jobname);
1132 print_settings = gtk_print_settings_new();
1133 webkit_print_operation_set_print_settings(op, print_settings);
1134 export_filename = g_strdup(jobname);
1136 gtk_print_settings_set(print_settings,
1137 GTK_PRINT_SETTINGS_OUTPUT_BASENAME,
1139 webkit_print_operation_set_print_settings(op, print_settings);
1141 top = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (priv->web_view)));
1142 print_response = webkit_print_operation_run_dialog (op, top);
1143 if (print_response == WEBKIT_PRINT_OPERATION_RESPONSE_PRINT)
1146 g_object_unref(print_settings);
1147 print_settings = g_object_ref(webkit_print_operation_get_print_settings(op));
1149 g_free(export_dirname);
1150 g_free(export_filename);
1151 g_object_unref (op);
1152 g_object_unref (print_settings);
1156 impl_webkit_set_parent( GncHtml*
self, GtkWindow* parent )
1158 GncHtmlWebkitPrivate* priv;
1160 g_return_if_fail(
self != NULL );
1161 g_return_if_fail( GNC_IS_HTML_WEBKIT(
self) );
1163 priv = GNC_HTML_WEBKIT_GET_PRIVATE(
self);
1164 priv->base.parent = GTK_WIDGET(parent);
1168 impl_webkit_default_zoom_changed(gpointer prefs, gchar *pref, gpointer user_data)
1171 GncHtmlWebkit*
self = GNC_HTML_WEBKIT(user_data);
1172 GncHtmlWebkitPrivate* priv = GNC_HTML_WEBKIT_GET_PRIVATE(
self);
1174 g_return_if_fail(user_data != NULL);
1177 webkit_web_view_set_zoom_level (priv->web_view, zoom);
gulong gnc_prefs_register_cb(const char *group, const gchar *pref_name, gpointer func, gpointer user_data)
Register a callback that gets triggered when the given preference changes.
#define PINFO(format, args...)
Print an informational note.
#define DEBUG(format, args...)
Print a debugging message.
#define PERR(format, args...)
Log a serious error.
#define ENTER(format, args...)
Print a function entry debugging message.
#define PWARN(format, args...)
Log a warning.
Account handling public routines.
All type declarations for the whole Gnucash engine.
Generic api to store and retrieve preferences.
#define LEAVE(format, args...)
Print a function exit debugging message.
void gnc_prefs_remove_cb_by_func(const gchar *group, const gchar *pref_name, gpointer func, gpointer user_data)
Remove a function that was registered for a callback when the given preference changed.
gdouble gnc_prefs_get_float(const gchar *group, const gchar *pref_name)
Get an float value from the preferences backend.