diff options
author | Patrick McDermott <pj@pehjota.net> | 2017-10-29 00:22:53 (EDT) |
---|---|---|
committer | Patrick McDermott <pj@pehjota.net> | 2017-10-29 00:22:53 (EDT) |
commit | b61c56a7a3c3f1caeaff5a0c4954f46ea593fb85 (patch) | |
tree | 73b303ccc600d4b1a1e7ef852d8e2f175fc9d5db | |
parent | 760ae1c598f31d90db2374fdebdedd6609fecdb9 (diff) | |
download | marquee-b61c56a7a3c3f1caeaff5a0c4954f46ea593fb85.zip marquee-b61c56a7a3c3f1caeaff5a0c4954f46ea593fb85.tar.gz marquee-b61c56a7a3c3f1caeaff5a0c4954f46ea593fb85.tar.bz2 |
MqWebView: Implement HTML-only saving
-rw-r--r-- | src/web-view.c | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/src/web-view.c b/src/web-view.c index 320491f..7975813 100644 --- a/src/web-view.c +++ b/src/web-view.c @@ -40,6 +40,7 @@ struct _MqWebView { WebKitHitTestResult *hit_test_result; WebKitHitTestResult *mouse_target_hit_test_result; GtkComboBox *save_type_combo_box; + GFile *save_file; }; enum { @@ -971,6 +972,37 @@ save_type_changed_cb(GtkComboBox *combo_box, GtkFileChooser *chooser) } static void +save_html_replace_cb(GFile *file, GAsyncResult *result) +{ + g_file_replace_contents_finish(file, result, NULL, NULL); + /* TODO: Error handling? */ +} + +static void +save_html_get_data_cb(WebKitWebResource *resource, GAsyncResult *result, + MqWebView *web_view) +{ + guchar *data; + gsize length; + + data = webkit_web_resource_get_data_finish(resource, result, &length, + NULL); /* TODO: Error handling? */ + g_file_replace_contents_async(web_view->save_file, + (gchar *) data, length, + NULL, FALSE, G_FILE_CREATE_REPLACE_DESTINATION, NULL, + (GAsyncReadyCallback) save_html_replace_cb, NULL); +} + +static void +save_html(MqWebView *web_view, GFile *file) +{ + web_view->save_file = file; + webkit_web_resource_get_data( + webkit_web_view_get_main_resource(WEBKIT_WEB_VIEW(web_view)), + NULL, (GAsyncReadyCallback) save_html_get_data_cb, web_view); +} + +static void save_mhtml(MqWebView *web_view, GFile *file) { webkit_web_view_save_to_file(WEBKIT_WEB_VIEW(web_view), file, @@ -984,6 +1016,7 @@ save_response_cb(GtkWidget *dialog, gint response_id, MqWebView *web_view) gchar *dir; gchar *filename; GFile *file; + gchar *extension; const gchar *active_id; if (response_id == GTK_RESPONSE_ACCEPT) { @@ -1004,13 +1037,14 @@ save_response_cb(GtkWidget *dialog, gint response_id, MqWebView *web_view) active_id = gtk_combo_box_get_active_id( web_view->save_type_combo_box); if (g_strcmp0(active_id, "detect") == 0) { + extension = strrchr(filename, '.') + 1; if (extension_is_html(extension)) { - /* TODO */ + save_html(web_view, file); } else if (extension_is_mhtml(extension)) { save_mhtml(web_view, file); } } else if (g_strcmp0(active_id, "html") == 0) { - /* TODO */ + save_html(web_view, file); } else if (g_strcmp0(active_id, "mhtml") == 0) { save_mhtml(web_view, file); } |