aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Persch <chpe@cvs.gnome.org>2004-08-31 21:13:46 +0800
committerChristian Persch <chpe@src.gnome.org>2004-08-31 21:13:46 +0800
commitd2dab3d0437e1430276a480b2bb8ec6f1e34966d (patch)
treee8ef3d9bf5881669c52d9e79ede2adf926a07b62
parenta0665f48e913456778cf7ed84403491907f8b0e1 (diff)
downloadgsoc2013-epiphany-d2dab3d0437e1430276a480b2bb8ec6f1e34966d.tar.gz
gsoc2013-epiphany-d2dab3d0437e1430276a480b2bb8ec6f1e34966d.tar.zst
gsoc2013-epiphany-d2dab3d0437e1430276a480b2bb8ec6f1e34966d.zip
Fix printing to file with a non-absolute path. Fixes bug #148849.
2004-08-31 Christian Persch <chpe@cvs.gnome.org> * embed/print-dialog.c: (sanitize_filename), (ephy_print_get_print_info): Fix printing to file with a non-absolute path. Fixes bug #148849.
-rw-r--r--ChangeLog7
-rwxr-xr-xembed/print-dialog.c76
2 files changed, 73 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index 43ac35501..b4d0fb1a4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
2004-08-31 Christian Persch <chpe@cvs.gnome.org>
+ * embed/print-dialog.c: (sanitize_filename),
+ (ephy_print_get_print_info):
+
+ Fix printing to file with a non-absolute path. Fixes bug #148849.
+
+2004-08-31 Christian Persch <chpe@cvs.gnome.org>
+
* embed/mozilla/ContentHandler.h:
Forgot to re-number MOZILLA_SNAPSHOT here.
diff --git a/embed/print-dialog.c b/embed/print-dialog.c
index c2c6699d3..84b431634 100755
--- a/embed/print-dialog.c
+++ b/embed/print-dialog.c
@@ -151,26 +151,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);
+ }
+
info->printer = eel_gconf_get_string (print_props[PRINTER_PROP].pref);
info->pages = eel_gconf_get_integer (print_props[ALL_PAGES_PROP].pref);