Re: [PATCH] Nautilus location bar

В Птн, 02/02/2007 в 14:28 +0100, Alexander Larsson пишет:
This part looks overly complex. Why not just use
gnome_vfs_uri_append_path(), possibly with a call to
gnome_vfs_make_path_name_canonical() afterward.
I looked at the patch again and found some problems with it:
this code will remove host info from uri if relative path has a lot of '..'

So i tried another way (it is only an example, so I hard-coded base & escaped vars):

    gchar *base = "";
    gchar *escaped = "../../../../../relative";

    const char *resolved_relative_uri_path;
    GnomeVFSURI *base_uri;
    GnomeVFSURI *resolved_relative_uri;

    base_uri = gnome_vfs_uri_new(base);
    if (base_uri == NULL)
        return 1;

    resolved_relative_uri = gnome_vfs_uri_append_string(base_uri, escaped);
    uri_path = gnome_vfs_uri_get_path (resolved_relative_uri);

    /* Complex part, I'll explain later
    if (resolved_relative_uri_path[0] != GNOME_VFS_URI_PATH_CHR) {
        gint offset = 0;
        if (resolved_relative_uri_path[0] == '.'
                && resolved_relative_uri_path[1] == '.')
            offset += 2;

        if (uri_path[offset] == GNOME_VFS_URI_PATH_CHR)
            offset += 1;

        gchar *tmp_path = resolved_relative_uri->text;
        resolved_relative_uri->text = g_strconcat(GNOME_VFS_URI_PATH_STR, tmp_path + offset, NULL);

    uri = gnome_vfs_uri_to_string(resolved_relative_uri, GNOME_VFS_URI_HIDE_NONE);


I think that some explanations needed:
Why do we need this complex part?
If we try to call gnome_vfs_uri_append_path(...) with supplied values uri will contain:

I don't think this is what we wanted...

This happens when the number of '..' is odd and it is greater then number of dirs
in /path/to/file. if the number of '..' is even, then we will get:

The problem with this code is that it uses uri->text, because I haven't found something like gnome_vfs_uri_set_path(...)
If it is OK for private function, I will create patch. If not, how can I do the same thing
(changing path without touching other parts of uri) with public or private functions?

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]