e1459ddf8a76a7058034db5fb58da8a3c8df51a6
[tilda-gobject.git] / tilda.c
1 #include <glib.h>
2
3 #include "tilda.h"
4 #include "tilda-window.h"
5 #include "tilda-terminal.h"
6
7 DBusGConnection *dbus_connection;
8
9 static void
10 tilda_initialize_dbus ()
11 {
12         const gchar service_name[] = "net.sourceforge.Tilda";
13         GError *error = NULL;
14         DBusGProxy *driver_proxy;
15         int request_ret;
16
17         // Initialize the DBus connection
18         dbus_connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
19         if (dbus_connection == NULL)
20         {
21                 g_warning ("Unable to connect to dbus: %s", error->message);
22                 g_error_free (error);
23                 return;
24         }
25
26         // Register the service name
27         driver_proxy = dbus_g_proxy_new_for_name (dbus_connection,
28                                                                                           DBUS_SERVICE_DBUS,
29                                                                                           DBUS_PATH_DBUS,
30                                                                                           DBUS_INTERFACE_DBUS);
31
32         if (!org_freedesktop_DBus_request_name (driver_proxy, service_name, 0, &request_ret, &error))
33         {
34                 // FIXME: for whatever reason, this is wrong. The error message doesn't appear
35                 // FIXME: when we were unable to register the service. Perhaps there's a more
36                 // FIXME: GLib-y way of doing this?
37                 g_warning ("Unable to register service: %s", error->message);
38                 g_error_free (error);
39         }
40
41         g_object_unref (driver_proxy);
42 }
43
44 int main (int argc, char *argv[])
45 {
46         TildaWindow *tw;
47
48         /* Initialize GTK+ (and the GObject system) */
49         gtk_init (&argc, &argv);
50
51         /* Start our connection to DBus */
52         tilda_initialize_dbus ();
53
54         /* Create a TildaWindow, run it, and exit when it does, basically.
55          *
56          * This is nothing like what the real main() will be, but it's
57          * a good start for testing and integration of more of TildaWindow
58          * and TildaTerminal. */
59         tw = g_object_new (TILDA_TYPE_WINDOW, "number", 0, NULL);
60
61         gtk_main ();
62
63         g_object_unref (G_OBJECT (tw));
64
65         return 0;
66 }
67
68 /* vim: set ts=4 sts=4 sw=4 noet tw=112: */