diff options
-rw-r--r-- | src/web-view.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/web-view.c b/src/web-view.c index 37654a6..3f03a49 100644 --- a/src/web-view.c +++ b/src/web-view.c @@ -911,6 +911,55 @@ get_clean_title(MqWebView *web_view) } static void +save_type_changed_cb(GtkComboBox *combo_box, GtkFileChooser *chooser) +{ + gchar *name; + gchar *ext; + const gchar *active_id; + gchar *new_name; + + name = gtk_file_chooser_get_current_name(chooser); + ext = strrchr(name, '.') + 1; + + active_id = gtk_combo_box_get_active_id(combo_box); + if (g_strcmp0(active_id, "html") == 0) { + if (!( + ext[0] == 'h' && + ext[1] == 't' && + ext[2] == 'm' && + (ext[3] == '\0' || + (ext[3] == 'l' && + ext[4] == '\0' + )))) { + /* Extension is not "htm" or "html". */ + ext[0] = '\0'; /* Remove extension. */ + new_name = g_strconcat(name, "html", NULL); + gtk_file_chooser_set_current_name(chooser, new_name); + g_free(new_name); + } + } else if (g_strcmp0(active_id, "mhtml") == 0) { + if (!( + ext[0] == 'm' && + ext[1] == 'h' && + ext[2] == 't' && + (ext[3] == '\0' || + (ext[3] == 'm' && + (ext[4] == '\0' || + (ext[4] == 'l' && + ext[5] == '\0' + )))))) { + /* Extension is not "mht", "mhtm", or "mhtml". */ + ext[0] = '\0'; /* Remove extension. */ + new_name = g_strconcat(name, "mhtml", NULL); + gtk_file_chooser_set_current_name(chooser, new_name); + g_free(new_name); + } + } + + g_free(name); +} + +static void save_response_cb(GtkWidget *dialog, gint response_id, MqWebView *web_view) { gchar *dir; @@ -980,6 +1029,8 @@ mq_web_view_save(MqWebView *web_view) gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(type_combo_box), "mhtml", "MHTML"); gtk_combo_box_set_active(GTK_COMBO_BOX(type_combo_box), 0); + g_signal_connect(type_combo_box, "changed", + G_CALLBACK(save_type_changed_cb), chooser); type_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); gtk_box_pack_start(GTK_BOX(type_box), gtk_label_new("File type:"), |