[Window] Add support for configuration of tab width
[tilda-gobject.git] / tilda.c
diff --git a/tilda.c b/tilda.c
index 02b6848..d0d81f2 100644 (file)
--- a/tilda.c
+++ b/tilda.c
@@ -1,17 +1,16 @@
-#include <glib.h>
 #include <stdlib.h>
 #include <signal.h>
 
 #include "tilda.h"
-#include "tilda-window.h"
-#include "tilda-terminal.h"
+#include "tilda-config.h"
+#include "tilda-controller.h"
 #include "tomboykeybinder.h"
 
-DBusGConnection *dbus_connection;
-GPtrArray *windows;
+/* Project-global variables */
+DBusGConnection *dbus_connection = NULL;
 
 static void
-tilda_initialize_dbus ()
+tilda_dbus_init ()
 {
        debug_enter  ();
 
@@ -57,82 +56,6 @@ tilda_initialize_dbus ()
        g_object_unref (driver_proxy);
 }
 
-static gint
-tilda_find_next_free_window_number ()
-{
-       debug_enter  ();
-
-       gint i, j;
-       gboolean found;
-
-       for (i=0; i<INT_MAX; ++i)
-       {
-               found = FALSE;
-
-               for (j=0; j<windows->len; ++j)
-               {
-                       TildaWindow *tw = g_ptr_array_index (windows, j);
-
-                       if (tw->number == i)
-                       {
-                               found = TRUE;
-                               break;
-                       }
-               }
-
-               if (!found)
-                       return i;
-       }
-
-       return 0;
-}
-
-static TildaWindow *
-tilda_add_window ()
-{
-       debug_enter ();
-
-       TildaWindow *ret;
-       gint number;
-
-       number = tilda_find_next_free_window_number ();
-       ret = g_object_new (TILDA_TYPE_WINDOW, "number", number, NULL);
-
-       g_ptr_array_add (windows, ret);
-
-       debug_printf ("Adding window: 0x%x (number %d of %d)\n", ret, ret->number, windows->len-1);
-       return ret;
-}
-
-void
-tilda_del_window (gint number)
-{
-       debug_enter ();
-
-       gint i;
-       TildaWindow *win;
-
-       for (i=0; i<windows->len; ++i)
-       {
-               win = g_ptr_array_index (windows, i);
-
-               if (win->number == number)
-               {
-                       debug_printf ("Deleting window 0x%x (number %d of %d)\n", win, win->number, windows->len-1);
-                       g_ptr_array_remove_index (windows, i);
-                       g_object_unref (G_OBJECT(win));
-
-                       if (windows->len == 0)
-                       {
-                               debug_printf ("No windows left, exiting...\n");
-                               gtk_main_quit ();
-                       }
-
-                       break;
-               }
-       }
-}
-
 static void
 tilda_parse_command_line (gint argc, gchar *argv[])
 {
@@ -142,7 +65,7 @@ tilda_parse_command_line (gint argc, gchar *argv[])
 
        /* All of the various command-line options */
        const GOptionEntry cl_opts[] = {
-               { "version",                    'V', 0, G_OPTION_ARG_NONE,              &version,                       N_("Show version information"), NULL },
+               { "version",                    'V', 0, G_OPTION_ARG_NONE,              &version,                       _("Show version information"), NULL },
                { NULL },
        };
 
@@ -212,7 +135,7 @@ int main (int argc, char *argv[])
 {
        debug_enter ();
 
-       TildaWindow *tw;
+       TildaController *tilda;
 
 #if ENABLE_NLS
        /* Gettext Initialization */
@@ -233,25 +156,25 @@ int main (int argc, char *argv[])
        /* Initialize the keybinder */
        tomboy_keybinder_init ();
 
-       /* Start our connection to DBus */
-       tilda_initialize_dbus ();
+       /* Initialize the configuration system */
+       tilda_config_init ("tilda.conf");
 
-       /* Initialize the array of windows */
-       windows = g_ptr_array_new ();
+       /* Start our connection to DBus */
+       tilda_dbus_init ();
 
-       /* Create a TildaWindow, run it, and exit when it does, basically.
-        *
-        * This is nothing like what the real main() will be, but it's
-        * a good start for testing and integration of more of TildaWindow
-        * and TildaTerminal. */
-       tw = tilda_add_window ();
+       /* Create a TildaController, which manages TildaWindows, which in turn manages
+        * TildaTerminals. Exit when it does. */
+       tilda = g_object_new (TILDA_TYPE_CONTROLLER, NULL);
 
        debug_printf ("Starting gtk_main()!\n");
        gtk_main ();
        debug_printf ("Out of gtk_main(), going down\n");
 
-       /* Free the pointer array we allocated earlier */
-       g_ptr_array_free (windows, TRUE);
+       /* Unref the TildaController that controls this whole operation */
+       g_object_unref (G_OBJECT(tilda));
+
+       /* Clean up after the config system */
+       tilda_config_free ();
 
        return 0;
 }