summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPatrick McDermott <pj@pehjota.net>2017-10-28 16:43:07 (EDT)
committer Patrick McDermott <pj@pehjota.net>2017-10-28 16:43:07 (EDT)
commitb5884db66184cddf436f466a98f14d6aa4c3880b (patch)
tree314109996ba12364d20e12042778995e94da92d9 /src
parent3a1deda22290dbf0f495d1050aa710410c3c3570 (diff)
downloadmarquee-b5884db66184cddf436f466a98f14d6aa4c3880b.zip
marquee-b5884db66184cddf436f466a98f14d6aa4c3880b.tar.gz
marquee-b5884db66184cddf436f466a98f14d6aa4c3880b.tar.bz2
mq_web_view_open(), mq_web_view_save(): New functions
Diffstat (limited to 'src')
-rw-r--r--src/web-view.c87
-rw-r--r--src/web-view.h6
2 files changed, 93 insertions, 0 deletions
diff --git a/src/web-view.c b/src/web-view.c
index 2c07216..616ca40 100644
--- a/src/web-view.c
+++ b/src/web-view.c
@@ -797,3 +797,90 @@ mq_web_view_zoom_reset(MqWebView *web_view)
zoom_level = mq_config_get_double(web_view->config, "zoom.default");
webkit_web_view_set_zoom_level(WEBKIT_WEB_VIEW(web_view), zoom_level);
}
+
+static void
+open_response_cb(GtkWidget *dialog, gint response_id, MqWebView *web_view)
+{
+ gchar *filename;
+ gchar *uri;
+
+ if (response_id == GTK_RESPONSE_ACCEPT) {
+ filename = gtk_file_chooser_get_filename(
+ GTK_FILE_CHOOSER(dialog));
+ uri = g_strconcat("file://", filename, NULL);
+ g_free(filename);
+ webkit_web_view_load_uri(WEBKIT_WEB_VIEW(web_view), uri);
+ g_free(uri);
+ }
+
+ gtk_widget_destroy(dialog);
+}
+
+void
+mq_web_view_open(MqWebView *web_view)
+{
+ GtkWidget *dialog;
+
+ dialog = gtk_file_chooser_dialog_new("Open File",
+ GTK_WINDOW(mq_tab_page_get_window(web_view->tab_page)),
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ "_Cancel", GTK_RESPONSE_CANCEL,
+ "_Open", GTK_RESPONSE_ACCEPT,
+ NULL);
+ g_signal_connect(dialog, "response",
+ G_CALLBACK(open_response_cb), web_view);
+ gtk_widget_show_all(dialog);
+}
+
+static void
+save_async_cb(WebKitWebView *web_view, GAsyncResult *result)
+{
+ webkit_web_view_save_to_file_finish(web_view, result, NULL);
+}
+
+static void
+save_response_cb(GtkWidget *dialog, gint response_id, MqWebView *web_view)
+{
+ gchar *filename;
+ GFile *file;
+
+ if (response_id == GTK_RESPONSE_ACCEPT) {
+ filename = gtk_file_chooser_get_filename(
+ GTK_FILE_CHOOSER(dialog));
+ file = g_file_new_for_path(filename);
+ g_free(filename);
+ /* TODO: HTML-only file format? */
+ webkit_web_view_save_to_file(WEBKIT_WEB_VIEW(web_view), file,
+ WEBKIT_SAVE_MODE_MHTML, NULL,
+ (GAsyncReadyCallback) save_async_cb, NULL);
+ }
+
+ gtk_widget_destroy(dialog);
+}
+
+void
+mq_web_view_save(MqWebView *web_view)
+{
+ GtkWidget *dialog;
+ GtkFileChooser *chooser;
+ const gchar *title;
+ gchar *filename;
+
+ dialog = gtk_file_chooser_dialog_new("Save File",
+ GTK_WINDOW(mq_tab_page_get_window(web_view->tab_page)),
+ GTK_FILE_CHOOSER_ACTION_SAVE,
+ "_Cancel", GTK_RESPONSE_CANCEL,
+ "_Save", GTK_RESPONSE_ACCEPT,
+ NULL);
+ chooser = GTK_FILE_CHOOSER(dialog);
+ gtk_file_chooser_set_do_overwrite_confirmation(chooser, TRUE);
+ /* TODO: gtk_file_chooser_set_current_folder() */
+ /* TODO: Clean up title for file name. */
+ title = webkit_web_view_get_title(WEBKIT_WEB_VIEW(web_view));
+ filename = g_strconcat(title, ".mhtml", NULL);
+ gtk_file_chooser_set_current_name(chooser, filename);
+ g_free(filename);
+ g_signal_connect(dialog, "response",
+ G_CALLBACK(save_response_cb), web_view);
+ gtk_widget_show_all(dialog);
+}
diff --git a/src/web-view.h b/src/web-view.h
index fa209c1..913e1f9 100644
--- a/src/web-view.h
+++ b/src/web-view.h
@@ -66,6 +66,12 @@ mq_web_view_zoom_out(MqWebView *web_view);
void
mq_web_view_zoom_reset(MqWebView *web_view);
+void
+mq_web_view_open(MqWebView *web_view);
+
+void
+mq_web_view_save(MqWebView *web_view);
+
G_END_DECLS
#endif /* MQ_WEB_VIEW_H */