767be6cd4ff7fb4d2d44902b3ecc19748b44ee2d
[rodin/chimara.git] / tests / plugin-loader.c
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3  * main.c
4  * Copyright (C) Philip en Marijn 2008 <>
5  * 
6  * main.c is free software copyrighted by Philip en Marijn.
7  * 
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. Neither the name ``Philip en Marijn'' nor the name of any other
17  *    contributor may be used to endorse or promote products derived
18  *    from this software without specific prior written permission.
19  * 
20  * main.c IS PROVIDED BY Philip en Marijn ``AS IS'' AND ANY EXPRESS
21  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL Philip en Marijn OR ANY OTHER CONTRIBUTORS
24  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
27  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
30  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #include <sys/types.h>
34 #include <sys/stat.h>
35 #include <unistd.h>
36 #include <string.h>
37 #include <stdio.h>
38
39 #include <glib.h>
40 #include <glib/gi18n.h>
41 #include <gtk/gtk.h>
42
43 #include <libchimara/chimara-glk.h>
44
45 /* Global pointers to widgets */
46 GtkWidget *window = NULL;
47 GtkWidget *glk = NULL;
48
49 static gboolean
50 quit()
51 {
52     gtk_main_quit();
53     return TRUE;
54 }
55
56 static void
57 create_window(void)
58 {
59     window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
60     gtk_widget_set_size_request(window, 400, 400);
61     g_signal_connect(window, "delete-event", G_CALLBACK(quit), NULL);
62         glk = chimara_glk_new();
63         g_object_set(glk, 
64                 "border-width", 6, 
65                 "spacing", 6,
66                 NULL);
67         g_signal_connect(glk, "stopped", G_CALLBACK(gtk_main_quit), NULL);
68         chimara_glk_set_default_font_string(CHIMARA_GLK(glk), "Serif 12");
69         chimara_glk_set_monospace_font_string(CHIMARA_GLK(glk), "Monospace 12");
70         gtk_container_add(GTK_CONTAINER(window), glk);
71 }
72
73 int
74 main(int argc, char *argv[])
75 {
76         GError *error = NULL;
77
78 #ifdef ENABLE_NLS
79         bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
80         bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
81         textdomain(GETTEXT_PACKAGE);
82 #endif
83
84         if( !g_thread_supported() )
85                 g_thread_init(NULL);
86         gdk_threads_init();
87         gtk_init(&argc, &argv);
88
89         create_window();
90         gtk_widget_show_all(window);
91
92         if(argc < 2) {
93                 g_printerr("Must provide a plugin\n");
94                 return 1;
95         }
96         
97     if( !chimara_glk_run(CHIMARA_GLK(glk), argv[1], argc - 1, argv + 1, &error) ) {
98                 g_printerr("Error starting Glk library: %s\n", error->message);
99                 return 1;
100         }
101
102     gdk_threads_enter();
103         gtk_main();
104         gdk_threads_leave();
105
106         chimara_glk_stop(CHIMARA_GLK(glk));
107         chimara_glk_wait(CHIMARA_GLK(glk));
108
109         return 0;
110 }