Sign up

Problem with gio.File it doesn't have a method newForPath

I'm new to D and GtkD. Sorry my English. Sorry for the edition of the text.
I need to use a gio.File for many things but I can not create one for a directory path and to enumerate it's contents. I need to know how to get the gio.File and enumerate its children asyncronously. What I'm doing wrong.
My code is:

class HelloWorld : ApplicationWindow
{

private Button button;
private gio.File.File myfile;
private GFile * file;
this(Application application)
{
	super(application);
	setTitle("GtkD");
	setBorderWidth(10);

	Box vbox = new Box(Orientation.VERTICAL, 0);
	vbox.add (new Label("Presione para leer el File"));
	button = new Button("Leer Archivo");
	vbox.add(button);
	button.addOnClicked(delegate void(Button btn) {
        //GFile * file;
        size_t bytesRead;
        //string filenameFromUtf8(string utf8string, ptrdiff_t len, out size_t bytesRead)
        string dirPath = CharacterSet.filenameFromUtf8("D:\\Willy", "D:\\Willy".length, bytesRead);
        writeln(dirPath);
        file = g_file_new_for_path(dirPath.ptr);
        
        myfile = new gio.File.File(file);
        writeln("despues de new gio.File.File(file);");
        
        //myfile.enumerateChildrenAsync(string attributes, GFileQueryInfoFlags flags, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData);
        //"standard::*", FileQueryInfoFlags.NOFOLLOW_SYMLINKS, Priority.DEFAULT, null
        myfile.enumerateChildrenAsync("standard::*", 
        GFileQueryInfoFlags.NOFOLLOW_SYMLINKS, GPriority.DEFAULT, null,
        (&this.enumChildrenCallBack).funcptr, cast(void*)0);
        writeln("despues de myfile.enumerateChildrenAsync"); 
    });
    add (vbox);
	showAll();
}

extern (C) void enumChildrenCallBack(GObject* source, GAsyncResult* res, void* userData)
{ 
    writeln("enumChildrenCallBack");
    gio.File.File file = new gio.File.File(cast(GFile*)source);
    writeln("despues de new gio.File.File(cast(GFile*)source);");
    Task task = new Task(cast(GTask*)res);
    writeln("despues de new Task(cast(GTask*)res);");               
    try {
		FileEnumerator enumerator = file.enumerateChildrenFinish (task);
		FileInfo info;
		while ((info = enumerator.nextFile(null)) !is null) {
			writefln ("%s\n", info.getName ());
		}
	} catch (GException e) {
		writefln("Error: ");
	}         
}

}

Thanks.

Re: Problem with gio.File it doesn't have a method newForPath

On 07/16/2016 04:21 AM, WillyAguilera wrote:

I'm new to D and GtkD. Sorry my English. Sorry for the edition of the text.
I need to use a gio.File for many things but I can not create one for a directory path and to enumerate it's contents. I need to know how to get the gio.File and enumerate its children asyncronously. What I'm doing wrong.
My code is:

Your workaround for the missing newForPath looks correct. The generator
currently doesn't generate constructors for interfaces, i will have to
look for the best way to solve that.

What issues are you experiencing?
The of .funcptr might cause isses due to D bug 2672 to work around
that mark your function as static, and replace
(&this.enumChildrenCallBack).funcptr with
cast(GAsyncReadyCallback)(&this.enumChildrenCallBack)

Re: Problem with gio.File it doesn't have a method newForPath

On Sat, 16 Jul 2016 10:52:13 +0200, Mike Wey wrote:

What issues are you experiencing?
The of .funcptr might cause isses due to D bug [2672][1] to work around
that mark your function as static, and replace
(&this.enumChildrenCallBack).funcptr with
cast(GAsyncReadyCallback)(&this.enumChildrenCallBack)

[1]: https://issues.dlang.org/show_bug.cgi?id=2672

Thank you very much. The issue I was experiencing was that when I clicked the button the program hung indefinitly.The workaround solve the problem very well.