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