Re-architecting changes
[moonshot-ui.git] / src / moonshot-identity-request.vala
1 delegate void ReturnIdentityCallback (IdentityRequest request);
2
3 class IdentityRequest : Object {
4     public IdCard? id_card = null;
5     public bool complete = false;
6     public bool select_default = false;
7
8     private IdentityManagerView main_window;
9     public string nai;
10     public string password;
11     public string service;
12
13     ReturnIdentityCallback callback = null;
14
15     public IdentityRequest (IdentityManagerView                   main_window,
16                             string                       nai,
17                             string                       password,
18                             string                       service)
19     {
20         this.main_window = main_window;
21         this.nai = nai;
22         this.password = password;
23         this.service = service;
24     }
25
26     public IdentityRequest.default (IdentityManagerView main_window)
27     {
28         this.main_window = main_window;
29         this.select_default = true;
30     }
31
32     public void set_callback (owned ReturnIdentityCallback cb)
33     {
34 #if VALA_0_12
35         this.callback = ((owned) cb);
36 #else
37         this.callback = ((IdCard) => cb (IdCard));
38 #endif
39     }
40
41     public bool execute () {
42         main_window.select_identity (this);
43
44         /* This function works as a GSourceFunc, so it can be passed to
45          * the main loop from other threads
46          */
47         return false;
48     }
49
50     public void return_identity (IdCard? id_card) {
51         return_if_fail (callback != null);
52
53         this.id_card = id_card;
54         this.complete = true;
55
56         callback (this);
57     }
58
59 #if OS_WIN32
60     /* For synchronisation between RPC thread and main loop. Because
61      * these objects are not refcounted, it's best to tie them to the
62      * lifecycle of the IdentityRequest object.
63      */
64     public Mutex mutex;
65     public Cond cond;
66 #endif
67 }