tags:

views:

178

answers:

3

Can GTK#'s FileChooserDialog be used as a unified file/URI dialog? I'd like it to accept http/https/ftp URIs without "rewriting" them (prepending local directory).

Even if I set LocalOnly=false and paste a http://.... uri into the text box inside the filechooser, I cannot get the original entry. Local directory is always prepended to the text.

A: 

I've done some research, and I don't think it's possible. At least not with the direct native C GTK+ API, which is what I tested.

In my testing, I always either got the local directory's path prepended to the http:// URI I had entered in the dialog, or I got back (null). I did call the get_uri() method, not just get_filename().

I also took a quick look, as a reference, at the GIMP application's File menu. As you probably know, GIMP provides the G in GTK+, so it can sometimes be used as a reference for ideas on how to use the toolkit. GIMP does not try to support URIs entered in the file chooser dialog, instead it has a dedicated Open Location command, that opens a simple dialog with just a GtkEntry.

unwind
A: 

I think you need to set local-only to FALSE and then use the GIO get_file ()/get_files () calls which return a GFile* accessible through the GIO File API and therefore through gvfs.

Vlagged
A: 

I found a solution / hack after all (in C#):

private string _extractUri(Widget wi) {
    if (wi is Entry)
        return ((wi as Entry).Text);
    else if (wi is Container) {
        foreach (Widget w in (wi as Container).Children) {
            string x = _extractUri(w);
            if (x!=null)
                return x;
        }
    }
    return null;
}

I'm not sure if that's always safe, but it worked for the standard FileChooserDialog. It will return the original string from the input field - even if standard Uri / File results are mangled.

viraptor