5 #include "tilda-window.h"
6 #include "tilda-terminal.h"
8 DBusGConnection *dbus_connection;
12 tilda_initialize_dbus ()
16 static const gchar service_name[] = "net.sourceforge.Tilda";
18 DBusGProxy *driver_proxy;
21 // Initialize the DBus connection
22 dbus_connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
23 if (dbus_connection == NULL)
25 g_warning ("Unable to connect to dbus: %s", error->message);
30 // Register the service name
31 driver_proxy = dbus_g_proxy_new_for_name (dbus_connection,
36 if (!org_freedesktop_DBus_request_name (driver_proxy, service_name, 0, &request_ret, &error))
38 // FIXME: for whatever reason, this is wrong. The error message doesn't appear
39 // FIXME: when we were unable to register the service. Perhaps there's a more
40 // FIXME: GLib-y way of doing this?
41 g_warning ("Unable to register service: %s", error->message);
45 g_object_unref (driver_proxy);
49 tilda_find_next_free_window_number ()
56 for (i=0; i<INT_MAX; ++i)
60 for (j=0; j<windows->len; ++j)
62 TildaWindow *tw = g_ptr_array_index (windows, j);
86 number = tilda_find_next_free_window_number ();
87 ret = g_object_new (TILDA_TYPE_WINDOW, "number", number, NULL);
89 g_ptr_array_add (windows, ret);
91 debug_printf ("Adding window: 0x%x (number %d of %d)\n", ret, ret->number, windows->len-1);
96 tilda_del_window (gint number)
103 for (i=0; i<windows->len; ++i)
105 win = g_ptr_array_index (windows, i);
107 if (win->number == number)
109 debug_printf ("Deleting window 0x%x (number %d of %d)\n", win, win->number, windows->len-1);
110 g_ptr_array_remove_index (windows, i);
111 g_object_unref (G_OBJECT(win));
118 tilda_parse_command_line (gint argc, gchar *argv[])
122 gboolean version = FALSE;
124 /* All of the various command-line options */
125 const GOptionEntry cl_opts[] = {
126 { "version", 'V', 0, G_OPTION_ARG_NONE, &version, N_("Show version information"), NULL },
130 /* Set up the command-line parser */
131 GError *error = NULL;
132 GOptionContext *context = g_option_context_new (NULL);
133 g_option_context_add_main_entries (context, cl_opts, NULL);
134 g_option_context_add_group (context, gtk_get_option_group (TRUE));
135 g_option_context_parse (context, &argc, &argv, &error);
136 g_option_context_free (context);
138 /* Check for unknown options, and give a nice message if there are some */
141 g_printerr (_("Error parsing command-line options: %s\n"), error->message);
142 g_printerr (_("The command \"tilda --help\" will show all possible options\n"));
143 g_error_free (error);
147 /* If we need to show the version, show it then exit normally */
150 g_print ("%s\n\n", TILDA_VERSION);
152 g_print ("Copyright (c) 2005-2008 Tristan Sloughter (sloutri@iit.edu)\n");
153 g_print ("Copyright (c) 2005-2008 Ira W. Snyder (tilda@irasnyder.com)\n\n");
155 g_print ("This program comes with ABSOLUTELY NO WARRANTY.\n");
156 g_print ("This is free software, and you are welcome to redistribute it\n");
157 g_print ("under certain conditions. See the file COPYING for details.\n");
163 int main (int argc, char *argv[])
170 /* Gettext Initialization */
171 setlocale (LC_ALL, "");
172 bindtextdomain (PACKAGE, LOCALEDIR);
173 textdomain (PACKAGE);
176 /* Parse the command-line options */
177 tilda_parse_command_line (argc, argv);
179 /* Initialize GTK+ (and the GObject system) */
180 gtk_init (&argc, &argv);
182 /* Initialize the keybinder */
183 tomboy_keybinder_init ();
185 /* Start our connection to DBus */
186 tilda_initialize_dbus ();
188 /* Initialize the array of windows */
189 windows = g_ptr_array_new ();
191 /* Create a TildaWindow, run it, and exit when it does, basically.
193 * This is nothing like what the real main() will be, but it's
194 * a good start for testing and integration of more of TildaWindow
195 * and TildaTerminal. */
196 tw = tilda_add_window ();
198 debug_printf ("Starting gtk_main()!\n");
200 debug_printf ("Out of gtk_main(), going down\n");
205 /* vim: set ts=4 sts=4 sw=4 noet tw=112: */