summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/tab-page.c51
-rw-r--r--src/tab-page.h3
2 files changed, 54 insertions, 0 deletions
diff --git a/src/tab-page.c b/src/tab-page.c
index b1bdc77..9d32c31 100644
--- a/src/tab-page.c
+++ b/src/tab-page.c
@@ -305,6 +305,57 @@ mq_tab_page_open(MqTabPage *tab_page)
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, MqTabPage *tab_page)
+{
+ 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(tab_page->web_view, file,
+ WEBKIT_SAVE_MODE_MHTML, NULL,
+ (GAsyncReadyCallback) save_async_cb, NULL);
+ }
+
+ gtk_widget_destroy(dialog);
+}
+
+void
+mq_tab_page_save(MqTabPage *tab_page)
+{
+ GtkWidget *dialog;
+ GtkFileChooser *chooser;
+ gchar *filename;
+
+ dialog = gtk_file_chooser_dialog_new("Save File",
+ GTK_WINDOW(tab_page->window),
+ 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. */
+ filename = g_strconcat(tab_page->title, ".mhtml", NULL);
+ gtk_file_chooser_set_current_name(chooser, filename);
+ g_free(filename);
+ g_signal_connect(dialog, "response",
+ G_CALLBACK(save_response_cb), tab_page);
+ gtk_widget_show_all(dialog);
+}
+
void
mq_tab_page_scroll_tab_labels(MqTabPage *node)
{
diff --git a/src/tab-page.h b/src/tab-page.h
index 384eb34..e840ae1 100644
--- a/src/tab-page.h
+++ b/src/tab-page.h
@@ -83,6 +83,9 @@ void
mq_tab_page_open(MqTabPage *tab_page);
void
+mq_tab_page_save(MqTabPage *tab_page);
+
+void
mq_tab_page_scroll_tab_labels(MqTabPage *node);
void