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