gboolean folder_set = FALSE;
GtkWidget* dialog;
gchar* filename;
- gchar* dirname;
gchar* last_slash;
if (!gtk_widget_get_visible (GTK_WIDGET (browser)))
if (uri)
{
+ gchar* dirname;
+
/* Base the start folder on the current view's uri if it is local */
filename = g_filename_from_uri (uri, NULL, NULL);
if (filename)
g_free (dirname);
g_free (filename);
}
+ }
+
+ if (uri == NULL)
+ uri = midori_view_get_display_uri (view);
/* Try to provide a good default filename, UTF-8 encoded */
filename = soup_uri_decode (uri);
last_slash = g_strrstr (filename, "/") + 1;
- gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), last_slash);
+ /* Take the rest of the URI if needed */
+ if (*last_slash == '\0')
+ {
+ const gchar* extension = midori_view_fallback_extension (view, NULL);
+ gchar* guessed;
+ gchar* no_scheme;
+ last_slash = g_strdelimit (filename, "/\\<>:\"|?*", '-');
+ guessed = g_strconcat (filename, extension, NULL);
+ no_scheme = strstr (guessed, "---") + 3;
+ gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), no_scheme);
+ g_free (guessed);
+ }
+ else
+ gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), last_slash);
g_free (filename);
- }
if (!folder_set && last_dir && *last_dir)
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), last_dir);
return g_strdup (period);
}
-static const gchar*
+const gchar*
midori_view_fallback_extension (MidoriView* view,
const gchar* extension)
{
return ".js";
if (strstr (view->mime_type, "html"))
return ".htm";
+ if (strstr (view->mime_type, "plain"))
+ return ".txt";
return "";
}
midori_view_save_speed_dial_config (MidoriView* view,
GKeyFile* key_file);
+const gchar*
+midori_view_fallback_extension (MidoriView* view,
+ const gchar* extension);
+
G_END_DECLS
#endif /* __MIDORI_VIEW_H__ */