5 #include "tilda-config.h"
6 #include "tilda-controller.h"
7 #include "tomboykeybinder.h"
9 /* Project-global variables */
10 DBusGConnection *dbus_connection = NULL;
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_parse_command_line (gint argc, gchar *argv[])
64 gboolean version = FALSE;
66 /* All of the various command-line options */
67 const GOptionEntry cl_opts[] = {
68 { "version", 'V', 0, G_OPTION_ARG_NONE, &version, N_("Show version information"), NULL },
72 /* Set up the command-line parser */
74 GOptionContext *context = g_option_context_new (NULL);
75 g_option_context_add_main_entries (context, cl_opts, NULL);
76 g_option_context_add_group (context, gtk_get_option_group (TRUE));
77 g_option_context_parse (context, &argc, &argv, &error);
78 g_option_context_free (context);
80 /* Check for unknown options, and give a nice message if there are some */
83 g_printerr (_("Error parsing command-line options: %s\n"), error->message);
84 g_printerr (_("The command \"tilda --help\" will show all possible options\n"));
89 /* If we need to show the version, show it then exit normally */
92 g_print ("%s\n\n", TILDA_VERSION);
94 g_print ("Copyright (c) 2005-2008 Tristan Sloughter (sloutri@iit.edu)\n");
95 g_print ("Copyright (c) 2005-2008 Ira W. Snyder (tilda@irasnyder.com)\n\n");
97 g_print ("This program comes with ABSOLUTELY NO WARRANTY.\n");
98 g_print ("This is free software, and you are welcome to redistribute it\n");
99 g_print ("under certain conditions. See the file COPYING for details.\n");
106 tilda_termination_handler (gint signum)
109 debug_printf ("signum: %d\n", signum);
114 /* Hook up all system signal handlers */
116 tilda_signal_handlers_init ()
120 /* Hook up signal handlers */
121 sa.sa_handler = tilda_termination_handler;
122 sigemptyset (&sa.sa_mask);
125 sigaction (SIGINT, &sa, NULL);
126 sigaction (SIGQUIT, &sa, NULL);
127 sigaction (SIGABRT, &sa, NULL);
128 sigaction (SIGTERM, &sa, NULL);
130 /* SIGKILL cannot be caught according to sigaction(2) and signal(7) */
131 /* sigaction (SIGKILL, &sa, NULL); */
134 int main (int argc, char *argv[])
138 TildaController *tilda;
141 /* Gettext Initialization */
142 setlocale (LC_ALL, "");
143 bindtextdomain (PACKAGE, LOCALEDIR);
144 textdomain (PACKAGE);
147 /* Parse the command-line options */
148 tilda_parse_command_line (argc, argv);
150 /* Initialize GTK+ (and the GObject system) */
151 gtk_init (&argc, &argv);
153 /* Hook up the signal handlers */
154 tilda_signal_handlers_init ();
156 /* Initialize the keybinder */
157 tomboy_keybinder_init ();
159 /* Initialize the configuration system */
160 tilda_config_init ("tilda.conf");
162 /* Start our connection to DBus */
165 /* Create a TildaController, which manages TildaWindows, which in turn manages
166 * TildaTerminals. Exit when it does. */
167 tilda = g_object_new (TILDA_TYPE_CONTROLLER, NULL);
169 debug_printf ("Starting gtk_main()!\n");
171 debug_printf ("Out of gtk_main(), going down\n");
173 /* Unref the TildaController that controls this whole operation */
174 g_object_unref (G_OBJECT(tilda));
176 /* Clean up after the config system */
177 tilda_config_free ();
182 /* vim: set ts=4 sts=4 sw=4 noet tw=112: */