5 #include "tilda-window.h"
6 #include "tilda-terminal.h"
7 #include "tomboykeybinder.h"
9 DBusGConnection *dbus_connection;
13 tilda_initialize_dbus ()
17 static const gchar service_name[] = "net.sourceforge.Tilda";
19 DBusGProxy *driver_proxy;
22 // Initialize the DBus connection
23 dbus_connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
24 if (dbus_connection == NULL)
26 g_warning ("Unable to connect to dbus: %s", error->message);
31 // Register the service name
32 driver_proxy = dbus_g_proxy_new_for_name (dbus_connection,
37 if (!org_freedesktop_DBus_request_name (driver_proxy, service_name, 0, &request_ret, &error))
39 // FIXME: for whatever reason, this is wrong. The error message doesn't appear
40 // FIXME: when we were unable to register the service. Perhaps there's a more
41 // FIXME: GLib-y way of doing this?
42 g_warning ("Unable to register service: %s", error->message);
46 g_object_unref (driver_proxy);
50 tilda_find_next_free_window_number ()
57 for (i=0; i<INT_MAX; ++i)
61 for (j=0; j<windows->len; ++j)
63 TildaWindow *tw = g_ptr_array_index (windows, j);
87 number = tilda_find_next_free_window_number ();
88 ret = g_object_new (TILDA_TYPE_WINDOW, "number", number, NULL);
90 g_ptr_array_add (windows, ret);
92 debug_printf ("Adding window: 0x%x (number %d of %d)\n", ret, ret->number, windows->len-1);
97 tilda_del_window (gint number)
104 for (i=0; i<windows->len; ++i)
106 win = g_ptr_array_index (windows, i);
108 if (win->number == number)
110 debug_printf ("Deleting window 0x%x (number %d of %d)\n", win, win->number, windows->len-1);
111 g_ptr_array_remove_index (windows, i);
112 g_object_unref (G_OBJECT(win));
119 tilda_parse_command_line (gint argc, gchar *argv[])
123 gboolean version = FALSE;
125 /* All of the various command-line options */
126 const GOptionEntry cl_opts[] = {
127 { "version", 'V', 0, G_OPTION_ARG_NONE, &version, N_("Show version information"), NULL },
131 /* Set up the command-line parser */
132 GError *error = NULL;
133 GOptionContext *context = g_option_context_new (NULL);
134 g_option_context_add_main_entries (context, cl_opts, NULL);
135 g_option_context_add_group (context, gtk_get_option_group (TRUE));
136 g_option_context_parse (context, &argc, &argv, &error);
137 g_option_context_free (context);
139 /* Check for unknown options, and give a nice message if there are some */
142 g_printerr (_("Error parsing command-line options: %s\n"), error->message);
143 g_printerr (_("The command \"tilda --help\" will show all possible options\n"));
144 g_error_free (error);
148 /* If we need to show the version, show it then exit normally */
151 g_print ("%s\n\n", TILDA_VERSION);
153 g_print ("Copyright (c) 2005-2008 Tristan Sloughter (sloutri@iit.edu)\n");
154 g_print ("Copyright (c) 2005-2008 Ira W. Snyder (tilda@irasnyder.com)\n\n");
156 g_print ("This program comes with ABSOLUTELY NO WARRANTY.\n");
157 g_print ("This is free software, and you are welcome to redistribute it\n");
158 g_print ("under certain conditions. See the file COPYING for details.\n");
164 int main (int argc, char *argv[])
171 /* Gettext Initialization */
172 setlocale (LC_ALL, "");
173 bindtextdomain (PACKAGE, LOCALEDIR);
174 textdomain (PACKAGE);
177 /* Parse the command-line options */
178 tilda_parse_command_line (argc, argv);
180 /* Initialize GTK+ (and the GObject system) */
181 gtk_init (&argc, &argv);
183 /* Initialize the keybinder */
184 tomboy_keybinder_init ();
186 /* Start our connection to DBus */
187 tilda_initialize_dbus ();
189 /* Initialize the array of windows */
190 windows = g_ptr_array_new ();
192 /* Create a TildaWindow, run it, and exit when it does, basically.
194 * This is nothing like what the real main() will be, but it's
195 * a good start for testing and integration of more of TildaWindow
196 * and TildaTerminal. */
197 tw = tilda_add_window ();
199 debug_printf ("Starting gtk_main()!\n");
201 debug_printf ("Out of gtk_main(), going down\n");
206 /* vim: set ts=4 sts=4 sw=4 noet tw=112: */