Add vapi for gtk-mac-integration. App now uses the Mac system menu :-)
[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 #endif
23         view.show();
24     }   
25     
26 #if IPC_MSRPC
27     private void init_ipc_server ()
28     {
29         // Errors will currently be sent via g_log - ie. to an
30         // obtrusive message box, on Windows
31         //
32         this.ipc_server = MoonshotServer.get_instance ();
33         MoonshotServer.start (this.view);
34     }
35 #elif IPC_DBUS_GLIB
36     private void init_ipc_server ()
37     {
38  
39         try {
40             var conn = DBus.Bus.get (DBus.BusType.SESSION);
41             dynamic DBus.Object bus = conn.get_object ("org.freedesktop.DBus",
42                                                        "/org/freedesktop/DBus",
43                                                        "org.freedesktop.DBus");
44
45             // try to register service in session bus
46             uint reply = bus.request_name ("org.janet.Moonshot", (uint) 0);
47             assert (reply == DBus.RequestNameReply.PRIMARY_OWNER);
48
49             this.ipc_server = new MoonshotServer (this.view);
50             conn.register_object ("/org/janet/moonshot", ipc_server);
51         }
52         catch (DBus.Error e)
53         {
54             stderr.printf ("%s\n", e.message);
55         }
56     }
57 #else
58     private void bus_acquired_cb (DBusConnection conn)
59     {
60         try {
61             conn.register_object ("/org/janet/moonshot", ipc_server);
62         }
63         catch (Error e)
64         {
65             stderr.printf ("%s\n", e.message);
66         }
67     }
68
69     private void init_ipc_server ()
70     {
71         this.ipc_server = new MoonshotServer (this.view);
72         GLib.Bus.own_name (GLib.BusType.SESSION,
73                            "org.janet.Moonshot",
74                            GLib.BusNameOwnerFlags.NONE,
75                            bus_acquired_cb,
76                            (conn, name) => {},
77                            (conn, name) => {
78                                error ("Couldn't own name %s on DBus.", name);
79                            });
80     }
81 #endif
82 }
83
84
85 public static int main(string[] args){
86         Gtk.init(ref args);
87                 stdout.printf("Hello\n");
88         foreach (string arg in args)
89                         stdout.printf("arg %s\n", arg);
90
91 #if OS_WIN32
92         // Force specific theme settings on Windows without requiring a gtkrc file
93         Gtk.Settings settings = Gtk.Settings.get_default ();
94         settings.set_string_property ("gtk-theme-name", "ms-windows", "moonshot");
95         settings.set_long_property ("gtk-menu-images", 0, "moonshot");
96 #endif
97
98         Intl.bindtextdomain (Config.GETTEXT_PACKAGE, Config.LOCALEDIR);
99         Intl.bind_textdomain_codeset (Config.GETTEXT_PACKAGE, "UTF-8");
100         Intl.textdomain (Config.GETTEXT_PACKAGE);
101        
102            
103         var app = new IdentityManagerApp();
104         
105         app.show();
106
107         Gtk.main();
108
109         return 0;
110     }
111