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