Handle concurrent identity requests correctly
[moonshot-ui.git] / src / moonshot-window.vala
index 24f3070..0b8bd83 100644 (file)
@@ -23,7 +23,7 @@ class MainWindow : Window
 
     public IdCardWidget selected_id_card_widget;
 
-    private SourceFunc callback;
+    private Queue<IdentityRequest> request_queue;
 
     private enum Columns
     {
@@ -52,6 +52,8 @@ class MainWindow : Window
 
     public MainWindow()
     {
+        request_queue = new Queue<IdentityRequest>();
+
         this.title = "Moonshoot";
         this.set_position (WindowPosition.CENTER);
         set_default_size (WINDOW_WIDTH, WINDOW_HEIGHT);
@@ -338,36 +340,42 @@ class MainWindow : Window
         dialog.destroy ();
     }
 
-    public void set_callback (owned SourceFunc callback)
+    public void select_identity (IdentityRequest request)
     {
-        this.callback = (owned) callback;
+        /* Automatic service matching rules can go here */
+
+        /* Resort to manual selection */
+        this.request_queue.push_tail (request);
+        this.show ();
     }
 
     public void send_identity_cb (IdCardWidget id_card_widget)
     {
+        var request = this.request_queue.pop_head ();
+        var identity = id_card_widget.id_card;
         this.selected_id_card_widget = id_card_widget;
 
-        if (id_card_widget.id_card.password == null)
+        if (identity.password == null)
         {
             var dialog = new AddPasswordDialog ();
             var result = dialog.run ();
 
             switch (result) {
             case ResponseType.OK:
-                this.hide ();
-                this.callback ();
+                identity.password = dialog.password;
                 break;
             default:
-                this.hide ();
+                identity = null;
                 break;
             }
+
             dialog.destroy ();
         }
-        else
-        {
-          this.hide ();
-          this.callback ();
-        }
+
+        if (this.request_queue.is_empty())
+            this.hide ();
+
+        request.return_identity (identity);
     }
 
     private void label_make_bold (Label label)
@@ -418,23 +426,40 @@ class MainWindow : Window
             null
         };
 
-        const string copyright = "Copyright 2011 JANET";
-
-        const string license =
-"
-    This program is free software: you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation, either version 3 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program.  If not, see <http://www.gnu.org/licenses/>.
-";
+        string copyright = "Copyright 2011 JANET";
+
+        string license =
+"""
+Copyright (c) 2011, JANET(UK)
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+
+1. Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+
+3. Neither the name of JANET(UK) nor the names of its contributors
+   may be used to endorse or promote products derived from this software
+   without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGE.
+""";
 
         Gtk.show_about_dialog (this,
             "comments", _("Moonshot project UI"),
@@ -460,7 +485,7 @@ class MainWindow : Window
 #if VALA_0_12
                                 Stock.ADD,
 #else
-                                STOCK.ADD,
+                                STOCK_ADD,
 #endif
                                 N_("Add ID Card"),
                                 null,
@@ -471,7 +496,7 @@ class MainWindow : Window
 #if VALA_0_12
                                  Stock.QUIT,
 #else
-                                 STOCK.QUIT,
+                                 STOCK_QUIT,
 #endif
                                  N_("Quit"),
                                  "<control>Q",
@@ -488,7 +513,7 @@ class MainWindow : Window
 #if VALA_0_12
                                   Stock.ABOUT,
 #else
-                                  STOCK.ABOUT,
+                                  STOCK_ABOUT,
 #endif
                                   N_("About"),
                                   null,