Re: [Vala] Question about signal connection

2009-11-18 Thread Johan

Hi Frederik,
Thanks a lot, it works perfectly.
regards,
Johan

Frederik wrote:

public class HelloVala: GLib.Object {
static void handler2 (FileMonitor monitor, File file, File? 
other_file,

  FileMonitorEvent event_type) {
// ...
}

public static int main (string[] args) {
var file = File.new_for_path (test.png);
var monitor = file.monitor_file (FileMonitorFlags.NONE);
monitor.changed.connect (handler2);
return 0;
}
}



  

  


___
Vala-list mailing list
Vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


[Vala] Question about signal connection

2009-11-07 Thread Johan

Hi,
I wanna check if a file has been changed, and then take some action.
However I am not getting the trick with the signal connection.
the code below returns:
(process:18773): GLib-GObject-WARNING **: IA__g_object_connect: invalid 
signal spec changed


well I have checked the specs of GLIB and everything seems to be 
correct, maybe something with the Vala notation?


I appreciate any help!
johan

using GLib;
using Gtk;

public class HelloVala: GLib.Object {
int handler2 (FileMonitor monitor,
  File file, File other_file, FileMonitorEvent 
event_type) {

   return 0;
  }

public static int main (string[] args) {
   var file = File.new_for_path (test.png);
   var monitor = file.monitor_file(FileMonitorFlags.NONE);
   monitor.connect(changed,handler2);
   return 0;
   }
}

___
Vala-list mailing list
Vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Question about signal connection

2009-11-07 Thread Frederik
Johan wrote:
 Hi,
 I wanna check if a file has been changed, and then take some action.
 However I am not getting the trick with the signal connection.
 the code below returns:
 (process:18773): GLib-GObject-WARNING **: IA__g_object_connect: invalid
 signal spec changed
 
 well I have checked the specs of GLIB and everything seems to be
 correct, maybe something with the Vala notation?
 
 I appreciate any help!
 johan
 
 using GLib;
 using Gtk;
 
 public class HelloVala: GLib.Object {
 int handler2 (FileMonitor monitor,
   File file, File other_file, FileMonitorEvent
 event_type) {
return 0;
   }
 
 public static int main (string[] args) {
var file = File.new_for_path (test.png);
var monitor = file.monitor_file(FileMonitorFlags.NONE);
monitor.connect(changed,handler2);
return 0;
}
 }

public class HelloVala: GLib.Object {
static void handler2 (FileMonitor monitor, File file, File? other_file,
  FileMonitorEvent event_type) {
// ...
}

public static int main (string[] args) {
var file = File.new_for_path (test.png);
var monitor = file.monitor_file (FileMonitorFlags.NONE);
monitor.changed.connect (handler2);
return 0;
}
}


Best regards,

Frederik
___
Vala-list mailing list
Vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Question about signal connection

2009-11-07 Thread Johan

Hi Andrea,
Thanks for the fast reply.
I am still doing something wrong, I changed this:

public virtual signal void handler2 (...)

monitor.changed.connect((void) this.handler2);

and get the following:
macro g_signal_connect requires 4 arguments, but only 3 given

That is how the C-code looks like:  
//  g_signal_connect (monitor, changed, (GCallback) ((void) 
g_signal_emit_by_name (self, handler2)));

and that is how it should be:
//  g_signal_connect (instance, detailed_signal, c_handler, data)
  
any idea?


Andrea Bolognani wrote:

On Sat, Nov 07, 2009 at 12:33:58PM +0100, Johan wrote:

  

Hi,
I wanna check if a file has been changed, and then take some action.


[...]
  

public static int main (string[] args) {
   var file = File.new_for_path (test.png);
   var monitor = file.monitor_file(FileMonitorFlags.NONE);
   monitor.connect(changed,handler2);
   return 0;
   }
}



Try using

monitor.changed.connect(handler2);

that should do the trick.

  


___
Vala-list mailing list
Vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Question about signal connection

2009-11-07 Thread Nicolas

Hi Joan,

Try this:

Signal.connect(monitor, changed, (GLib.Callback)handler2, monitor);

Nicolas.


___
Vala-list mailing list
Vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Question about signal connection

2009-11-07 Thread Jan Hudec
On Sat, Nov 07, 2009 at 13:16:02 +0100, Johan wrote:
 Hi Andrea,
 Thanks for the fast reply.
 I am still doing something wrong, I changed this:
 
 public virtual signal void handler2 (...)

No 'signal' keyword here. A handler is just a function. It must have
a signature that matches the signal it will connect to and of course it must
have a body.

(The handler also does not need to be public, if the connect is in a method
of that class)

 monitor.changed.connect((void) this.handler2);

You should not have any cast here. A (void) cast in particular is complete
nonsense -- it would be (void *) if you meant just untyped reference.

Generally, you should need very few casts in correct vala code. Whenever you
seem to need a cast, it's quite likely something else is wrong, so
make sure you really understand what is going on before you write a cast.

 and get the following:
 macro g_signal_connect requires 4 arguments, but only 3 given
 
 That is how the C-code looks like:  //  g_signal_connect
 (monitor, changed, (GCallback) ((void) g_signal_emit_by_name
 (self, handler2)));

Vala should not have generated this. It should have probably errored out
saying the signal 'handler2' can't be used as value.

 and that is how it should be:
 //  g_signal_connect (instance, detailed_signal, c_handler, data)
 any idea?

-- 
 Jan 'Bulb' Hudec b...@ucw.cz
___
Vala-list mailing list
Vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Question about signal connection

2009-11-07 Thread Jan Hudec
On Sat, Nov 07, 2009 at 14:47:16 +0100, Nicolas wrote:
 Signal.connect(monitor, changed, (GLib.Callback)handler2, monitor);

No. That won't work without some magic applied to handler2, because the call
signature for signal handlers is different from regular methods. The normal
syntax:

object.signame.connect(invocant.handler)

is easier and better.

(I assume you didn't mean to pass the same object as emitter and handler
invocant above, as that makes no sense)

-- 
 Jan 'Bulb' Hudec b...@ucw.cz
___
Vala-list mailing list
Vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list