File open association works, but crashes if you choose not to import the card
[moonshot-ui.git] / src / moonshot-identity-manager-app.vala
1 using Gtk;
2
3
4 class IdentityManagerApp : Window {
5     public IdentityManagerModel model;
6     private IdentityManagerView view;
7     private MoonshotServer ipc_server;
8 #if OS_MACOS
9         public OSXApplication osxApp;
10 #endif
11     private const int WINDOW_WIDTH = 400;
12     private const int WINDOW_HEIGHT = 500;
13     public void show() {
14         view.show();    
15     }
16     public IdentityManagerApp () {
17         model = new IdentityManagerModel(this);
18         view = new IdentityManagerView(this);
19         init_ipc_server ();
20 #if OS_MACOS
21                 osxApp = OSXApplication.get_instance();
22                 osxApp.ns_application_open_file.connect(ipc_server.install_from_file);
23 #endif
24         view.show();
25     }   
26     
27 #if IPC_MSRPC
28     private void init_ipc_server ()
29     {
30         // Errors will currently be sent via g_log - ie. to an
31         // obtrusive message box, on Windows
32         //
33         this.ipc_server = MoonshotServer.get_instance ();
34         MoonshotServer.start (this.view);
35     }
36 #elif IPC_DBUS_GLIB
37     private void init_ipc_server ()
38     {
39  
40         try {
41             var conn = DBus.Bus.get (DBus.BusType.SESSION);
42             dynamic DBus.Object bus = conn.get_object ("org.freedesktop.DBus",
43                                                        "/org/freedesktop/DBus",
44                                                        "org.freedesktop.DBus");
45
46             // try to register service in session bus
47             uint reply = bus.request_name ("org.janet.Moonshot", (uint) 0);
48             assert (reply == DBus.RequestNameReply.PRIMARY_OWNER);
49
50             this.ipc_server = new MoonshotServer (this.view);
51             conn.register_object ("/org/janet/moonshot", ipc_server);
52         }
53         catch (DBus.Error e)
54         {
55             stderr.printf ("%s\n", e.message);
56         }
57     }
58 #else
59     private void bus_acquired_cb (DBusConnection conn)
60     {
61         try {
62             conn.register_object ("/org/janet/moonshot", ipc_server);
63         }
64         catch (Error e)
65         {
66             stderr.printf ("%s\n", e.message);
67         }
68     }
69
70     private void init_ipc_server ()
71     {
72         this.ipc_server = new MoonshotServer (this.view);
73         GLib.Bus.own_name (GLib.BusType.SESSION,
74                            "org.janet.Moonshot",
75                            GLib.BusNameOwnerFlags.NONE,
76                            bus_acquired_cb,
77                            (conn, name) => {},
78                            (conn, name) => {
79                                error ("Couldn't own name %s on DBus.", name);
80                            });
81     }
82 #endif
83 }
84
85
86 public static int main(string[] args){
87         Gtk.init(ref args);
88                 stdout.printf("Hello\n");
89         foreach (string arg in args)
90                         stdout.printf("arg %s\n", arg);
91
92 #if OS_WIN32
93         // Force specific theme settings on Windows without requiring a gtkrc file
94         Gtk.Settings settings = Gtk.Settings.get_default ();
95         settings.set_string_property ("gtk-theme-name", "ms-windows", "moonshot");
96         settings.set_long_property ("gtk-menu-images", 0, "moonshot");
97 #endif
98
99         Intl.bindtextdomain (Config.GETTEXT_PACKAGE, Config.LOCALEDIR);
100         Intl.bind_textdomain_codeset (Config.GETTEXT_PACKAGE, "UTF-8");
101         Intl.textdomain (Config.GETTEXT_PACKAGE);
102        
103            
104         var app = new IdentityManagerApp();
105         
106         app.show();
107
108         Gtk.main();
109
110         return 0;
111     }
112