Sign up

Implementing application.addOnOpen

I am trying to implement application.addOnOpen and I am getting stuck trying to work with the "void* files".

Here is the main function for my test app:

int main(string[] args)
{
    auto application = new Application(null, GApplicationFlags.HANDLES_OPEN);
    application.addOnActivate(delegate void(GioApplication app) { new HelloWorld(application); });
	application.addOnOpen(delegate void(void* files, int cnt, string hint, GioApplication app) { new HelloWorld(files, cnt, hint, application); });
    return application.run(args);
}

The constructor for the HelloWorld class looks like this:

this(void* files, int cnt, string hint, Application application)
{
	writeln(cnt);
	GFile* p = cast(GFile*)files;
	gio.File.File f = new gio.File.File(p);
	this(application);
}

When I run it and pass in one file name on the command line, I can see that cnt is one. So far I have tried casting the void pointer to a GFile pointer and then passing that into a File constructor (as shown above) but that didn't work and received the following errors:

GLib-GObject-CRITICAL **: gobjectsetdatafull: assertion 'GISOBJECT (object)' failed

GLib-GObject-CRITICAL **: gobjectaddtoggleref: assertion 'GISOBJECT (object)' failed

GLib-GObject-CRITICAL **: gobjectisfloating: assertion 'GIS_OBJECT (object)' failed

I am assuming that I am doing something fundamentally wrong here, does anybody see my mistake?

Re: Implementing application.addOnOpen

On 01/05/2017 09:49 PM, dlang user wrote:

I am trying to implement application.addOnOpen and I am getting stuck trying to work with the "void* files".

Here is the main function for my test app:

...

I am assuming that I am doing something fundamentally wrong here, does anybody see my mistake?

The Gio documentation and the gir files contain the wrong type for
files. I'ts actual type is: GFile**

It should probably be wrapped as an gio.File.File array.

For now you can do:

new gio.File.File((cast(GFile**)files)[0]);

For the first file.

Re: Implementing application.addOnOpen

On Thu, 5 Jan 2017 22:46:09 +0100, Mike Wey wrote:

On 01/05/2017 09:49 PM, dlang user wrote:

I am trying to implement application.addOnOpen and I am getting stuck trying to work with the "void* files".

Here is the main function for my test app:

...

I am assuming that I am doing something fundamentally wrong here, does anybody see my mistake?

The Gio documentation and the gir files contain the wrong type for
files. I'ts actual type is: GFile**

It should probably be wrapped as an gio.File.File array.

For now you can do:

new gio.File.File((cast(GFile**)files)[0]);

For the first file.

Great, thanks for the fast work around, it worked perfectly.