First, note you can use GLib.Application in GLib, you don't have to use 
Gtk.Aplication(it's inherit from the first):
http://developer.gnome.org/gio/unstable/GApplication.html

There, you can see example 19A, where it shows you how to activate an Action, 
using Application class.
The action is performed in the primary instance, even if it was activated in 
other process.
You can pass a string parameter to the action.

Good luck
Tal

> From: db...@uci.cu
> To: vala-list@gnome.org
> Date: Fri, 1 Feb 2013 14:21:35 -0500
> Subject: [Vala] regarding Gtk.Application managing a single instance app
> 
> Hello,
> 
> a student of mine has been appointed to develop a copy manager. He
> decided to write the code in Vala and he's been consulting me since. The
> idea is to be able to manage several copy processes in a single window,
> so he's using Gtk.Application for that matter.
> 
> The logic behind the single instance is (as you may suppose) that the
> first time the application is invoked it launches a new window with the
> copy widgets on it. Any new attempt to invoke the application should add
> a new copy to the already existing window (a window exists solely while
> any of the copies it handles is alive, so: if the there is no copy in
> progress any invocation is considered as the first one).
> 
> All that being said what's happening is that the second time the app is
> invoked the "activate" method seems to be running on the first instance
> of the class, and since the new copy information is stored on the
> current instance, there is no new copy being created since the existing
> instance tries to create (again) it's own copy resulting on an logical
> error since the same copy cannot be run twice at the same time.
> 
> Issues related to good programming practices have been discussed with
> the student already, yet I fail to understand how could the new info be
> passed to the existing instance.
> 
> I'm hoping someone can shed some light on this.
> 
> Best regards,
> 
> D.H.Bahr.
> 
> PS: This is the code relevant to the problem:
> 
> /**********************************************************************/
> using GLib;
> using Gtk;
> 
> public class Main : Gtk.Application {
> 
>   private MainView main_view;
>   private string operation_type;
>   private List<string> sources;
>   private string destination;
>               
>   public Main (string operation_type, List<string> sources, string
> destination) {
>     Object (application_id: "nova.ncopier", flags:
> ApplicationFlags.FLAGS_NONE);
>               
>     this.operation_type = operation_type;
>               
>     this.sources = new List<string> ();               
>     foreach (unowned string source in sources) {
>       this.sources.append (source);
>     }
>               
>     this.destination = destination;
>   }
> 
>   public override void activate () {
>     if (this.get_windows ().length () == 0) {
>       main_view = new MainView (this.operation_type, this.sources,
> this.destination);                    
>       this.add_window(main_view);
>     } else {
>       for (int i = 0; i < (int) this.sources.length (); i++) {
>         stdout.printf ("%d:%s", i, this.sources.nth_data (i));
>       }
>       main_view.add_operation (new OperationView (this.operation_type,
> this.sources, this.destination));
>       main_view.present ();
>     }
>   }
> 
>   static int main (string[] args) {
>     Gtk.init (ref args);
>               
>     if (args.length < 4) {
>       stdout.printf ("incomplete parameters\n");
>       return 1;
>     } else {
>       string operation_type = "";
>       List<string> sources = new List<string> ();
>       string destination = "";
>                       
>       if (args[1] == "copy") {
>         operation_type = "COPYING";
>       }
>       sources.append ("file:" + args[2]);
>       destination = "file:" + args[3];
>                       
>       return new Main (operation_type, sources, destination).run ();
>     }
>   }
> }
> /***********************************************************************/
> 
> _______________________________________________
> vala-list mailing list
> vala-list@gnome.org
> https://mail.gnome.org/mailman/listinfo/vala-list
                                          
_______________________________________________
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to