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;
23 // Initialize the DBus connection
24 dbus_connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
25 if (dbus_connection == NULL)
27 g_warning (_("Unable to connect to DBus: %s\n"), error->message);
32 // Register the service name
33 driver_proxy = dbus_g_proxy_new_for_name (dbus_connection,
38 ret = org_freedesktop_DBus_request_name (driver_proxy,
40 DBUS_NAME_FLAG_DO_NOT_QUEUE,
46 g_warning (_("Unable to communicate with DBus: %s\n"), error->message);
50 if (request_ret == DBUS_REQUEST_NAME_REPLY_EXISTS)
52 g_critical (_("There is already an instance of Tilda running\n"));
56 g_object_unref (driver_proxy);
60 tilda_find_next_free_window_number ()
67 for (i=0; i<INT_MAX; ++i)
71 for (j=0; j<windows->len; ++j)
73 TildaWindow *tw = g_ptr_array_index (windows, j);
97 number = tilda_find_next_free_window_number ();
98 ret = g_object_new (TILDA_TYPE_WINDOW, "number", number, NULL);
100 g_ptr_array_add (windows, ret);
102 debug_printf ("Adding window: 0x%x (number %d of %d)\n", ret, ret->number, windows->len-1);
107 tilda_del_window (gint number)
114 for (i=0; i<windows->len; ++i)
116 win = g_ptr_array_index (windows, i);
118 if (win->number == number)
120 debug_printf ("Deleting window 0x%x (number %d of %d)\n", win, win->number, windows->len-1);
121 g_ptr_array_remove_index (windows, i);
122 g_object_unref (G_OBJECT(win));
124 if (windows->len == 0)
126 debug_printf ("No windows left, exiting...\n");
136 tilda_parse_command_line (gint argc, gchar *argv[])
140 gboolean version = FALSE;
142 /* All of the various command-line options */
143 const GOptionEntry cl_opts[] = {
144 { "version", 'V', 0, G_OPTION_ARG_NONE, &version, N_("Show version information"), NULL },
148 /* Set up the command-line parser */
149 GError *error = NULL;
150 GOptionContext *context = g_option_context_new (NULL);
151 g_option_context_add_main_entries (context, cl_opts, NULL);
152 g_option_context_add_group (context, gtk_get_option_group (TRUE));
153 g_option_context_parse (context, &argc, &argv, &error);
154 g_option_context_free (context);
156 /* Check for unknown options, and give a nice message if there are some */
159 g_printerr (_("Error parsing command-line options: %s\n"), error->message);
160 g_printerr (_("The command \"tilda --help\" will show all possible options\n"));
161 g_error_free (error);
165 /* If we need to show the version, show it then exit normally */
168 g_print ("%s\n\n", TILDA_VERSION);
170 g_print ("Copyright (c) 2005-2008 Tristan Sloughter (sloutri@iit.edu)\n");
171 g_print ("Copyright (c) 2005-2008 Ira W. Snyder (tilda@irasnyder.com)\n\n");
173 g_print ("This program comes with ABSOLUTELY NO WARRANTY.\n");
174 g_print ("This is free software, and you are welcome to redistribute it\n");
175 g_print ("under certain conditions. See the file COPYING for details.\n");
181 int main (int argc, char *argv[])
188 /* Gettext Initialization */
189 setlocale (LC_ALL, "");
190 bindtextdomain (PACKAGE, LOCALEDIR);
191 textdomain (PACKAGE);
194 /* Parse the command-line options */
195 tilda_parse_command_line (argc, argv);
197 /* Initialize GTK+ (and the GObject system) */
198 gtk_init (&argc, &argv);
200 /* Initialize the keybinder */
201 tomboy_keybinder_init ();
203 /* Start our connection to DBus */
204 tilda_initialize_dbus ();
206 /* Initialize the array of windows */
207 windows = g_ptr_array_new ();
209 /* Create a TildaWindow, run it, and exit when it does, basically.
211 * This is nothing like what the real main() will be, but it's
212 * a good start for testing and integration of more of TildaWindow
213 * and TildaTerminal. */
214 tw = tilda_add_window ();
216 debug_printf ("Starting gtk_main()!\n");
218 debug_printf ("Out of gtk_main(), going down\n");
220 /* Free the pointer array we allocated earlier */
221 g_ptr_array_free (windows, TRUE);
226 /* vim: set ts=4 sts=4 sw=4 noet tw=112: */