Interim commit - compiles and runs
authorPete Fotheringham <pete.fotheringham@codethink.co.uk>
Fri, 9 Dec 2011 14:18:49 +0000 (14:18 +0000)
committerPete Fotheringham <pete.fotheringham@codethink.co.uk>
Fri, 9 Dec 2011 14:18:49 +0000 (14:18 +0000)
Makefile.am
src/moonshot-custom-vbox.vala
src/moonshot-idcard-store.vala
src/moonshot-identities-manager.vala
src/moonshot-identity-manager-app.vala
src/moonshot-identity-request.vala
src/moonshot-local-flat-file-store.vala
src/moonshot-server.vala
src/moonshot-window.vala

index 4750fa8..c80c0e5 100644 (file)
@@ -35,6 +35,7 @@ noinst_HEADERS = libmoonshot/libmoonshot-common.h
 
 src_moonshot_SOURCES = \
         src/moonshot-identity-manager-app.vala \
+        src/moonshot-identity-management-view.vala \
         src/moonshot-local-flat-file-store.vala \
         src/moonshot-idcard-store.vala \
         src/moonshot-id.vala \
@@ -44,7 +45,6 @@ src_moonshot_SOURCES = \
         src/moonshot-identities-manager.vala \
         src/moonshot-identity-request.vala \
         src/moonshot-server.vala \
-        src/moonshot-window.vala \
         src/moonshot-password-dialog.vala \
         src/moonshot-utils.vala
 
index 31b2a20..3fb96ff 100644 (file)
@@ -3,9 +3,9 @@ using Gtk;
 class CustomVBox : VBox
 {
     public IdCardWidget current_idcard { get; set; default = null; }
-    private MainWindow main_window; 
+    private IdentityManagerView main_window; 
 
-    public CustomVBox (MainWindow window, bool homogeneous, int spacing)
+    public CustomVBox (IdentityManagerView window, bool homogeneous, int spacing)
     {
         main_window = window;
         set_homogeneous (homogeneous);
index 0bfe40c..84a285f 100644 (file)
@@ -1,8 +1,9 @@
 public interface IIdentityCardStore : Object {
-     // Methods
-     public abstract void add_card(IdCard card);
-     public abstract void remove_card(IdCard card);
-     public abstract SList<IdCard> get_card_list(); 
-     public signal void CardListChanged();
+    // Methods
+    public abstract void add_card(IdCard card);
+    public abstract void remove_card(IdCard card);
+    public abstract void update_card(IdCard card);
+    public abstract SList<IdCard> get_card_list(); 
+    public signal void card_list_changed();
 }
 
index 90bbec9..4d02493 100644 (file)
@@ -1,17 +1,23 @@
-class IdentitiesManager : Object {
+class IdentityManagerModel : Object {
 
     public SList<IdCard> id_card_list;
+    public SList<IdCard> get_card_list() {
+         return id_card_list.copy(); 
+    }
+    public signal void card_list_changed();
+
 
     private const string FILE_NAME = "identities.txt";
+    private IdentityManagerApp parent;
 
-    public IdentitiesManager ()
+    public IdentityManagerModel(IdentityManagerApp parent_app)
     {
+     print("IdentityManagerModel()\n");
+        parent = parent_app;
         id_card_list = new SList<IdCard>();
         var key_file = new KeyFile ();
-
         var path = get_data_dir ();
         var filename = Path.build_filename (path, FILE_NAME);
-
         try
         {
             key_file.load_from_file (filename, KeyFileFlags.NONE);
index d366e97..a65dd60 100644 (file)
@@ -1,18 +1,79 @@
 using Gtk;
 
 class IdentityManagerApp : Window {
-    private MainWindow main_window;
-    
+    public IdentityManagerModel model;
+    private IdentityManagerView view;
+    private MoonshotServer ipc_server;
+    private const int WINDOW_WIDTH = 400;
+    private const int WINDOW_HEIGHT = 500;
+
     public IdentityManagerApp () {
-        main_window = new MainWindow();
-        main_window.show();
-    }
+        model = new IdentityManagerModel(this);
+        view = new IdentityManagerView(this);
+        init_ipc_server ();
+        view.show();
+    }   
     
-/*    public int run(string[] args){
-        GLib.Application.run(args);
-     }*/
-    public static int main(string[] args)
+
+#if IPC_MSRPC
+    private void init_ipc_server ()
+    {
+        // Errors will currently be sent via g_log - ie. to an
+        // obtrusive message box, on Windows
+        //
+        this.ipc_server = MoonshotServer.get_instance ();
+        MoonshotServer.start (this.view);
+    }
+#elif IPC_DBUS_GLIB
+    private void init_ipc_server ()
     {
+        try {
+            var conn = DBus.Bus.get (DBus.BusType.SESSION);
+            dynamic DBus.Object bus = conn.get_object ("org.freedesktop.DBus",
+                                                       "/org/freedesktop/DBus",
+                                                       "org.freedesktop.DBus");
+
+            // try to register service in session bus
+            uint reply = bus.request_name ("org.janet.Moonshot", (uint) 0);
+            assert (reply == DBus.RequestNameReply.PRIMARY_OWNER);
+
+            this.ipc_server = new MoonshotServer (this.view);
+            conn.register_object ("/org/janet/moonshot", ipc_server);
+        }
+        catch (DBus.Error e)
+        {
+            stderr.printf ("%s\n", e.message);
+        }
+    }
+#else
+    private void bus_acquired_cb (DBusConnection conn)
+    {
+        try {
+            conn.register_object ("/org/janet/moonshot", ipc_server);
+        }
+        catch (Error e)
+        {
+            stderr.printf ("%s\n", e.message);
+        }
+    }
+
+    private void init_ipc_server ()
+    {
+        this.ipc_server = new MoonshotServer (this.view);
+        GLib.Bus.own_name (GLib.BusType.SESSION,
+                           "org.janet.Moonshot",
+                           GLib.BusNameOwnerFlags.NONE,
+                           bus_acquired_cb,
+                           (conn, name) => {},
+                           (conn, name) => {
+                               error ("Couldn't own name %s on DBus.", name);
+                           });
+    }
+#endif
+}
+
+
+public static int main(string[] args){
         Gtk.init(ref args);
 
 #if OS_WIN32
@@ -25,14 +86,13 @@ class IdentityManagerApp : Window {
         Intl.bindtextdomain (Config.GETTEXT_PACKAGE, Config.LOCALEDIR);
         Intl.bind_textdomain_codeset (Config.GETTEXT_PACKAGE, "UTF-8");
         Intl.textdomain (Config.GETTEXT_PACKAGE);
-        
+       
         var app = new IdentityManagerApp();
         
-//        app.show();
+        app.show();
+
         Gtk.main();
 
         return 0;
     }
-}
 
index 8415048..bb67997 100644 (file)
@@ -5,14 +5,14 @@ class IdentityRequest : Object {
     public bool complete = false;
     public bool select_default = false;
 
-    private MainWindow main_window;
+    private IdentityManagerView main_window;
     public string nai;
     public string password;
     public string service;
 
     ReturnIdentityCallback callback = null;
 
-    public IdentityRequest (MainWindow                   main_window,
+    public IdentityRequest (IdentityManagerView                   main_window,
                             string                       nai,
                             string                       password,
                             string                       service)
@@ -23,7 +23,7 @@ class IdentityRequest : Object {
         this.service = service;
     }
 
-    public IdentityRequest.default (MainWindow main_window)
+    public IdentityRequest.default (IdentityManagerView main_window)
     {
         this.main_window = main_window;
         this.select_default = true;
index 1d2caa7..df16f95 100644 (file)
@@ -5,6 +5,9 @@ public class LocalFlatFileStore : Object, IIdentityCardStore {
      public void add_card(IdCard card) {
      }
 
+     public void update_card(IdCard card) {
+     }
+
      public void remove_card(IdCard card) {
      }
 
index c5cae18..abae433 100644 (file)
@@ -3,11 +3,11 @@
 [DBus (name = "org.janet.Moonshot")]
 public class MoonshotServer : Object {
 
-    private MainWindow main_window;
+    private IdentityManagerView main_window;
 
     public MoonshotServer (Gtk.Window window)
     {
-        this.main_window = (MainWindow) window;
+        this.main_window = (IdentityManagerView) window;
     }
 
     public async bool get_identity (string nai,
@@ -166,13 +166,13 @@ using MoonshotRpcInterface;
  * process ends
  */
 public class MoonshotServer : Object {
-    private static MainWindow main_window;
+    private static IdentityManagerView main_window;
 
     private static MoonshotServer instance = null;
 
     public static void start (Gtk.Window window)
     {
-        main_window = (MainWindow) window;
+        main_window = (IdentityManagerView) window;
         Rpc.server_start (MoonshotRpcInterface.spec, "/org/janet/Moonshot", Rpc.Flags.PER_USER);
     }
 
index 63beb49..d7c6194 100644 (file)
@@ -17,10 +17,10 @@ class MainWindow : Window
     private ListStore listmodel;
     private TreeModelFilter filter;
 
-    public IdentitiesManager identities_manager;
+    public IdentityManagerModel identities_manager;
     private SList<IdCard>    candidates;
 
-    private MoonshotServer ipc_server;
+//    private MoonshotServer ipc_server;
 
     private IdCard default_id_card;
     public Queue<IdentityRequest> request_queue;
@@ -64,7 +64,7 @@ class MainWindow : Window
         setup_identities_list();
         load_id_cards();
         connect_signals();
-        init_ipc_server();
+  //      init_ipc_server();
     }
     
     public void add_candidate (IdCard idcard)
@@ -186,7 +186,7 @@ class MainWindow : Window
 
     private void load_id_cards ()
     {
       identities_manager = new IdentitiesManager ();
//       identities_manager = new IdentityManagerModel();
         
         if (identities_manager.id_card_list == null)
           return;
@@ -948,13 +948,13 @@ SUCH DAMAGE.
     {
         this.destroy.connect (Gtk.main_quit);
     }
-
+/*
 #if IPC_MSRPC
     private void init_ipc_server ()
     {
-        /* Errors will currently be sent via g_log - ie. to an
-         * obtrusive message box, on Windows
-         */
+        // Errors will currently be sent via g_log - ie. to an
+        // obtrusive message box, on Windows
+        //
         this.ipc_server = MoonshotServer.get_instance ();
         MoonshotServer.start (this);
     }
@@ -1004,5 +1004,5 @@ SUCH DAMAGE.
                            });
     }
 #endif
-
+*/
 }