Generate a .gss_eap_id file in the home directory
authorJavier Jardón <javier.jardon@codethink.co.uk>
Wed, 4 May 2011 10:40:49 +0000 (11:40 +0100)
committerJavier Jardón <javier.jardon@codethink.co.uk>
Wed, 4 May 2011 11:19:37 +0000 (12:19 +0100)
This file will store only the username and password of the latest
ID card introduced

src/moonshot-identities-manager.vala
src/moonshot-window.vala

index 44efcb5..9b6f9c4 100644 (file)
@@ -80,4 +80,64 @@ class IdentitiesManager : Object {
 
         return path;
     }
+
+    public IdCard? load_gss_eap_id_file ()
+    {
+        IdCard id_card = new IdCard();
+        string text;
+        string id_card_data[2];
+
+        var filename = Path.build_filename (Environment.get_home_dir (),
+                                            ".gss_eap_id");
+        try {
+            FileUtils.get_contents (filename, out text, null);
+        }
+        catch (Error e)
+        {
+            return null;
+        }
+
+        if (text == "")
+            return null;
+
+        id_card_data = text.split ("\n", 2);
+        id_card.issuer = "Issuer";
+        id_card.username = id_card_data[0];
+        id_card.password = id_card_data[1];
+        id_card.services = {"email","jabber","irc"};
+
+        var icon_theme = Gtk.IconTheme.get_default ();
+        try
+        {
+            id_card.pixbuf = icon_theme.load_icon ("avatar-default",
+                                                   48,
+                                                   Gtk.IconLookupFlags.FORCE_SIZE);
+        }
+        catch (Error e)
+        {
+            id_card.pixbuf = null;
+            stdout.printf("Error: %s\n", e.message);
+        }
+
+        return id_card;
+    }
+
+    public void store_gss_eap_id_file (IdCard ?id_card)
+    {
+        string text = "";
+
+        if (id_card != null)
+            text = id_card.username + "\n" + id_card.password;
+
+        var filename = Path.build_filename (Environment.get_home_dir (),
+                                            ".gss_eap_id");
+        try
+        {
+            FileUtils.set_contents (filename, text, -1);
+        }
+        catch (Error e)
+        {
+            stdout.printf ("Error:  %s\n", e.message);
+        }
+    }
 }
index 0ee986b..77973dc 100644 (file)
@@ -35,7 +35,8 @@ class MainWindow : Window
 
         build_ui();
         setup_identities_list();
-        load_id_cards();
+        load_gss_eap_id_file();
+        //load_id_cards();
         connect_signals();
     }
 
@@ -109,6 +110,20 @@ class MainWindow : Window
         return false;
     }
 
+    private void load_gss_eap_id_file ()
+    {
+        IdCard id_card;
+
+        this.identities_manager = new IdentitiesManager ();
+
+        id_card = this.identities_manager.load_gss_eap_id_file ();
+        if (id_card != null)
+        {
+            add_id_card_data (id_card);
+            add_id_card_widget (id_card);
+        }
+    }
+
     private void load_id_cards ()
     {
         this.identities_manager = new IdentitiesManager ();
@@ -225,6 +240,7 @@ class MainWindow : Window
 
         this.identities_manager.id_card_list.prepend (id_card);
         this.identities_manager.store_id_cards ();
+        this.identities_manager.store_gss_eap_id_file (id_card);
 
         add_id_card_data (id_card);
         add_id_card_widget (id_card);
@@ -258,6 +274,7 @@ class MainWindow : Window
 
         this.identities_manager.id_card_list.remove (id_card);
         this.identities_manager.store_id_cards ();
+        this.identities_manager.store_gss_eap_id_file (null);
 
         remove_id_card_widget (id_card_widget);
     }