5 #include "tilda-controller.h"
6 #include "tomboykeybinder.h"
8 /* Project-global variables */
9 DBusGConnection *dbus_connection;
16 static const gchar service_name[] = "net.sourceforge.Tilda";
18 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\n"), error->message);
31 // Register the service name
32 driver_proxy = dbus_g_proxy_new_for_name (dbus_connection,
37 ret = org_freedesktop_DBus_request_name (driver_proxy,
39 DBUS_NAME_FLAG_DO_NOT_QUEUE,
45 g_warning (_("Unable to communicate with DBus: %s\n"), error->message);
49 if (request_ret == DBUS_REQUEST_NAME_REPLY_EXISTS)
51 g_critical (_("There is already an instance of Tilda running\n"));
55 g_object_unref (driver_proxy);
59 tilda_parse_command_line (gint argc, gchar *argv[])
63 gboolean version = FALSE;
65 /* All of the various command-line options */
66 const GOptionEntry cl_opts[] = {
67 { "version", 'V', 0, G_OPTION_ARG_NONE, &version, N_("Show version information"), NULL },
71 /* Set up the command-line parser */
73 GOptionContext *context = g_option_context_new (NULL);
74 g_option_context_add_main_entries (context, cl_opts, NULL);
75 g_option_context_add_group (context, gtk_get_option_group (TRUE));
76 g_option_context_parse (context, &argc, &argv, &error);
77 g_option_context_free (context);
79 /* Check for unknown options, and give a nice message if there are some */
82 g_printerr (_("Error parsing command-line options: %s\n"), error->message);
83 g_printerr (_("The command \"tilda --help\" will show all possible options\n"));
88 /* If we need to show the version, show it then exit normally */
91 g_print ("%s\n\n", TILDA_VERSION);
93 g_print ("Copyright (c) 2005-2008 Tristan Sloughter (sloutri@iit.edu)\n");
94 g_print ("Copyright (c) 2005-2008 Ira W. Snyder (tilda@irasnyder.com)\n\n");
96 g_print ("This program comes with ABSOLUTELY NO WARRANTY.\n");
97 g_print ("This is free software, and you are welcome to redistribute it\n");
98 g_print ("under certain conditions. See the file COPYING for details.\n");
105 tilda_termination_handler (gint signum)
108 debug_printf ("signum: %d\n", signum);
113 /* Hook up all system signal handlers */
115 tilda_signal_handlers_init ()
119 /* Hook up signal handlers */
120 sa.sa_handler = tilda_termination_handler;
121 sigemptyset (&sa.sa_mask);
124 sigaction (SIGINT, &sa, NULL);
125 sigaction (SIGQUIT, &sa, NULL);
126 sigaction (SIGABRT, &sa, NULL);
127 sigaction (SIGTERM, &sa, NULL);
129 /* SIGKILL cannot be caught according to sigaction(2) and signal(7) */
130 /* sigaction (SIGKILL, &sa, NULL); */
133 int main (int argc, char *argv[])
137 TildaController *tilda;
140 /* Gettext Initialization */
141 setlocale (LC_ALL, "");
142 bindtextdomain (PACKAGE, LOCALEDIR);
143 textdomain (PACKAGE);
146 /* Parse the command-line options */
147 tilda_parse_command_line (argc, argv);
149 /* Initialize GTK+ (and the GObject system) */
150 gtk_init (&argc, &argv);
152 /* Hook up the signal handlers */
153 tilda_signal_handlers_init ();
155 /* Initialize the keybinder */
156 tomboy_keybinder_init ();
158 /* Start our connection to DBus */
161 /* Create a TildaController, which manages TildaWindows, which in turn manages
162 * TildaTerminals. Exit when it does. */
163 tilda = g_object_new (TILDA_TYPE_CONTROLLER, NULL);
165 debug_printf ("Starting gtk_main()!\n");
167 debug_printf ("Out of gtk_main(), going down\n");
169 /* Unref the TildaController that controls this whole operation */
170 g_object_unref (G_OBJECT(tilda));
175 /* vim: set ts=4 sts=4 sw=4 noet tw=112: */