From dd0b02c40b5d202794d03299f2d190833b63bb22 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Mon, 19 Jan 2004 14:06:41 +0000 Subject: Add a way to store paths. 2004-01-19 Marco Pesenti Gritti * lib/eel-gconf-extensions.c: (tilde_compress), (eel_gconf_set_path): * lib/eel-gconf-extensions.h: Add a way to store paths. * embed/mozilla/ContentHandler.cpp: * embed/mozilla/ContentHandler.h: * embed/mozilla/MozDownload.cpp: * embed/mozilla/MozDownload.h: Actually save the file in downloads dir and then open it. It doesnt seem to open it but it's prolly a gnome-vfs bug. * src/prefs-dialog.c: (get_download_button_label), (download_path_response_cb): Simplify the label logic using ~. --- lib/eel-gconf-extensions.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++ lib/eel-gconf-extensions.h | 2 ++ 2 files changed, 64 insertions(+) (limited to 'lib') diff --git a/lib/eel-gconf-extensions.c b/lib/eel-gconf-extensions.c index 7ec18f492..a60372d45 100644 --- a/lib/eel-gconf-extensions.c +++ b/lib/eel-gconf-extensions.c @@ -687,3 +687,65 @@ eel_gconf_get_float (const char *key) return result; } + +static char * +tilde_compress (const char *path) +{ + const char *home_dir = g_get_home_dir(); + int home_dir_l = strlen (home_dir); + int ntilde = 0; + const char *scan; + int path_l, result_l; + char *result, *scan2; + + if (path == NULL) + return NULL; + + path_l = strlen (path); + for (scan = path; scan != NULL; scan++) { + if (path_l - (scan - path) < home_dir_l) + break; + if (strncmp (scan, home_dir, home_dir_l) == 0) + ntilde++; + } + + if (ntilde == 0) + return g_strdup (path); + + result_l = strlen (path) + ntilde - (ntilde * home_dir_l); + result = g_new (char, result_l + 1); + + for (scan = path, scan2 = result; scan != NULL; scan2++) { + if (path_l - (scan - path) < home_dir_l) { + strcpy (scan2, scan); + scan2 += strlen (scan); + break; + } + if (strncmp (scan, home_dir, home_dir_l) == 0) { + *scan2 = '~'; + scan += home_dir_l; + } else { + *scan2 = *scan; + scan++; + } + } + *scan2 = 0; + + return result; +} + +void +eel_gconf_set_path (const char *key, + const char *value) +{ + char *tilde_path; + char *converted; + + converted = g_filename_to_utf8 (value, -1, NULL, NULL, NULL); + + tilde_path = tilde_compress (converted); + eel_gconf_set_string (key, tilde_path); + + g_free (tilde_path); + g_free (converted); +} diff --git a/lib/eel-gconf-extensions.h b/lib/eel-gconf-extensions.h index 13196d7ee..4bc6167ef 100644 --- a/lib/eel-gconf-extensions.h +++ b/lib/eel-gconf-extensions.h @@ -72,6 +72,8 @@ void eel_gconf_value_set_string_list (GConfValue *value, void eel_gconf_set_float (const char *key, gfloat float_value); gfloat eel_gconf_get_float (const char *key); +void eel_gconf_set_path (const char *key, + const char *value); G_END_DECLS -- cgit v1.2.3