aboutsummaryrefslogtreecommitdiffstats
path: root/embed/print-dialog.c
diff options
context:
space:
mode:
Diffstat (limited to 'embed/print-dialog.c')
-rwxr-xr-xembed/print-dialog.c76
1 files changed, 66 insertions, 10 deletions
diff --git a/embed/print-dialog.c b/embed/print-dialog.c
index 0aa921a05..baf92744c 100755
--- a/embed/print-dialog.c
+++ b/embed/print-dialog.c
@@ -157,26 +157,82 @@ ephy_print_info_free (EmbedPrintInfo *info)
g_free (info);
}
-EmbedPrintInfo *
-ephy_print_get_print_info (void)
+static char *
+sanitize_filename (const char *input)
{
- EmbedPrintInfo *info;
- char *filename;
+ char *dir, *filename;
- info = g_new0 (EmbedPrintInfo, 1);
+ if (input == NULL) return NULL;
- filename = eel_gconf_get_string (print_props[FILE_PROP].pref);
- if (filename != NULL)
+ if (g_path_is_absolute (input) == FALSE)
{
- info->file = gnome_vfs_expand_initial_tilde (filename);
+ dir = eel_gconf_get_string (CONF_PRINT_DIR);
+ /* Fallback */
+ if (dir == NULL || g_path_is_absolute (dir) == FALSE)
+ {
+ g_free (dir);
+ dir = g_get_current_dir ();
+ }
+ /* Fallback */
+ if (dir == NULL)
+ {
+ dir = g_strdup (g_get_home_dir ());
+ }
+
+ filename = g_build_filename (dir, input, NULL);
+ g_free (dir);
}
else
{
- info->file = NULL;
+ filename = g_strdup (input);
+ }
+
+ dir = g_path_get_dirname (filename);
+ if (dir == NULL || g_file_test (dir, G_FILE_TEST_IS_DIR) == FALSE)
+ {
+ g_free (filename);
+ filename = NULL;
}
- g_free (filename);
+ g_free (dir);
+
+ return filename;
+}
+
+EmbedPrintInfo *
+ephy_print_get_print_info (void)
+{
+ EmbedPrintInfo *info;
+ char *filename, *converted, *expanded, *fname = NULL;
+
+ info = g_new0 (EmbedPrintInfo, 1);
info->print_to_file = eel_gconf_get_integer (print_props[PRINTON_PROP].pref) == 1;
+
+ if (info->print_to_file)
+ {
+ filename = eel_gconf_get_string (print_props[FILE_PROP].pref);
+ if (filename != NULL)
+ {
+ converted = g_filename_from_utf8 (filename, -1, NULL, NULL, NULL);
+ if (converted != NULL)
+ {
+ expanded = gnome_vfs_expand_initial_tilde (filename);
+ fname = sanitize_filename (expanded);
+ g_free (expanded);
+ g_free (converted);
+ }
+ }
+
+ /* fallback */
+ if (fname == NULL)
+ {
+ fname = sanitize_filename ("output.ps");
+ }
+
+ info->file = g_filename_to_utf8 (fname, -1, NULL, NULL, NULL);
+ g_free (fname);
+ }
+g_print (info->file);
info->printer = eel_gconf_get_string (print_props[PRINTER_PROP].pref);
info->pages = eel_gconf_get_integer (print_props[ALL_PAGES_PROP].pref);