diff options
author | Christian Persch <chpe@cvs.gnome.org> | 2004-08-30 03:42:36 +0800 |
---|---|---|
committer | Christian Persch <chpe@src.gnome.org> | 2004-08-30 03:42:36 +0800 |
commit | a941a1755f847bf100287e9c68537d5674d06e18 (patch) | |
tree | e8a92c432caff6b4b29834b24b2a376a275e885e /embed | |
parent | 19d8469ac62082ac4101026655ca957c3cd48041 (diff) | |
download | gsoc2013-epiphany-a941a1755f847bf100287e9c68537d5674d06e18.tar gsoc2013-epiphany-a941a1755f847bf100287e9c68537d5674d06e18.tar.gz gsoc2013-epiphany-a941a1755f847bf100287e9c68537d5674d06e18.tar.bz2 gsoc2013-epiphany-a941a1755f847bf100287e9c68537d5674d06e18.tar.lz gsoc2013-epiphany-a941a1755f847bf100287e9c68537d5674d06e18.tar.xz gsoc2013-epiphany-a941a1755f847bf100287e9c68537d5674d06e18.tar.zst gsoc2013-epiphany-a941a1755f847bf100287e9c68537d5674d06e18.zip |
Make sure the filename to print to doesn't contain slashes. Fixes bug
2004-08-29 Christian Persch <chpe@cvs.gnome.org>
* embed/print-dialog.c: (sanitize_filename),
(ephy_print_get_print_info):
Make sure the filename to print to doesn't contain slashes.
Fixes bug #148849.
Diffstat (limited to 'embed')
-rwxr-xr-x | embed/print-dialog.c | 76 |
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); |