# HG changeset patch # User Daniel Atallah # Date 1175723825 0 # Node ID bd49e48ba3377c32ea6f878f85c94d4b9be90532 # Parent 5db7909331fa0238085978d6d29688376570e823# Parent f77f1d5870b6ed1565ee6f46bb3c3037c3b588a0 merge of '4b0f41a73b406685da6c053dbdd7dc909b4e4183' and '5e1e1599fddeeecfcd8b76796b71073f780cadfd' diff -r 5db7909331fa -r bd49e48ba337 finch/libgnt/gntfilesel.c --- a/finch/libgnt/gntfilesel.c Wed Apr 04 21:41:41 2007 +0000 +++ b/finch/libgnt/gntfilesel.c Wed Apr 04 21:57:05 2007 +0000 @@ -37,6 +37,106 @@ } } +#if !GLIB_CHECK_VERSION(2,8,0) +/* ripped from glib/gfileutils.c */ +static gchar * +g_build_path_va (const gchar *separator, + gchar **str_array) +{ + GString *result; + gint separator_len = strlen (separator); + gboolean is_first = TRUE; + gboolean have_leading = FALSE; + const gchar *single_element = NULL; + const gchar *next_element; + const gchar *last_trailing = NULL; + gint i = 0; + + result = g_string_new (NULL); + + next_element = str_array[i++]; + + while (TRUE) { + const gchar *element; + const gchar *start; + const gchar *end; + + if (next_element) { + element = next_element; + next_element = str_array[i++]; + } else + break; + + /* Ignore empty elements */ + if (!*element) + continue; + + start = element; + + if (separator_len) { + while (start && + strncmp (start, separator, separator_len) == 0) + start += separator_len; + } + + end = start + strlen (start); + + if (separator_len) { + while (end >= start + separator_len && + strncmp (end - separator_len, separator, separator_len) == 0) + end -= separator_len; + + last_trailing = end; + while (last_trailing >= element + separator_len && + strncmp (last_trailing - separator_len, separator, separator_len) == 0) + last_trailing -= separator_len; + + if (!have_leading) { + /* If the leading and trailing separator strings are in the + * same element and overlap, the result is exactly that element + */ + if (last_trailing <= start) + single_element = element; + + g_string_append_len (result, element, start - element); + have_leading = TRUE; + } else + single_element = NULL; + } + + if (end == start) + continue; + + if (!is_first) + g_string_append (result, separator); + + g_string_append_len (result, start, end - start); + is_first = FALSE; + } + + if (single_element) { + g_string_free (result, TRUE); + return g_strdup (single_element); + } else { + if (last_trailing) + g_string_append (result, last_trailing); + + return g_string_free (result, FALSE); + } +} + +static gchar * +g_build_pathv (const gchar *separator, + gchar **args) +{ + if (!args) + return NULL; + + return g_build_path_va (separator, args); +} + +#endif + static char * process_path(const char *path) { @@ -259,6 +359,11 @@ path = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", sel->current, str); str = process_path(path); g_free(path); + path = str; + + if (gnt_file_sel_set_current_location(sel, path)) + goto success; + path = g_path_get_dirname(str); g_free(str); @@ -298,8 +403,8 @@ gnt_widget_draw(sel->files); } globfree(&gl); +#endif success: -#endif g_free(path); return TRUE; }