]> Pileus Git - grits/blob - src/grits-test.c
Init earlier on
[grits] / src / grits-test.c
1 /*
2  * Copyright (C) 2009-2011 Andy Spencer <andy753421@gmail.com>
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 #include <config.h>
19 #include <gtk/gtk.h>
20 #include <gtk/gtkgl.h>
21 #include <gdk/gdkkeysyms.h>
22
23 #include "grits.h"
24
25 GritsPrefs   *prefs   = NULL;
26 GritsPlugins *plugins = NULL;
27 GritsViewer  *viewer  = NULL;
28
29 /*************
30  * Callbacks *
31  *************/
32 static gboolean grits_shutdown(GtkWidget *window)
33 {
34         static gboolean shutdown = FALSE;
35         if (shutdown) return TRUE;
36         shutdown = TRUE;
37
38         grits_plugins_free(plugins);
39         g_object_unref(prefs);
40         gtk_widget_destroy(window);
41         gtk_main_quit();
42         return TRUE;
43 }
44 static gboolean on_delete(GtkWidget *widget, GdkEvent *event, gpointer data)
45 {
46         return grits_shutdown(widget);
47 }
48 static gboolean on_key_press(GtkWidget *widget, GdkEventKey *event,
49                 gpointer _)
50 {
51         if (event->keyval == GDK_q)
52                 return grits_shutdown(widget);
53         return FALSE;
54 }
55 static void load_plugin(GritsPlugins *plugins, gchar *name,
56                 GritsViewer *viewer, GritsPrefs *prefs, GtkNotebook *notebook)
57 {
58         GritsPlugin *plugin = grits_plugins_load(plugins, name, viewer, prefs);
59         GtkWidget *config = grits_plugin_get_config(plugin);
60         if (config)
61                 gtk_notebook_append_page(notebook, config, gtk_label_new(name));
62 }
63
64 /***********
65  * Methods *
66  ***********/
67 int main(int argc, char **argv)
68 {
69         g_thread_init(NULL);
70         gdk_threads_init();
71         gtk_init(&argc, &argv);
72         gtk_gl_init(&argc, &argv);
73         grits_init(&argc, &argv);
74
75         prefs   = grits_prefs_new(NULL, NULL);
76         plugins = grits_plugins_new(g_getenv("GRITS_PLUGIN_PATH"), prefs);
77         viewer  = grits_opengl_new(plugins, prefs);
78
79         gdk_threads_enter();
80         GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
81         GtkWidget *vbox   = gtk_vbox_new(FALSE, 0);
82         GtkWidget *config = gtk_notebook_new();
83         g_signal_connect(window, "delete-event",    G_CALLBACK(on_delete),    NULL);
84         g_signal_connect(window, "key-press-event", G_CALLBACK(on_key_press), NULL);
85         gtk_notebook_set_tab_pos(GTK_NOTEBOOK(config), GTK_POS_BOTTOM);
86         gtk_container_add(GTK_CONTAINER(window), vbox);
87         gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(viewer), TRUE,  TRUE,  0);
88         gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(config), FALSE, FALSE, 0);
89         gtk_widget_show_all(window);
90
91         /* Configurable stuff */
92         grits_viewer_set_offline(viewer, TRUE);
93         (void)load_plugin;
94         load_plugin(plugins, "env",   viewer, prefs, GTK_NOTEBOOK(config));
95         //load_plugin(plugins, "elev",  viewer, prefs, GTK_NOTEBOOK(config));
96         load_plugin(plugins, "sat",   viewer, prefs, GTK_NOTEBOOK(config));
97         //load_plugin(plugins, "map",   viewer, prefs, GTK_NOTEBOOK(config));
98         //load_plugin(plugins, "alert", viewer, prefs, GTK_NOTEBOOK(config));
99         //load_plugin(plugins, "radar", viewer, prefs, GTK_NOTEBOOK(config));
100         load_plugin(plugins, "test",  viewer, prefs, GTK_NOTEBOOK(config));
101
102         gtk_widget_show_all(config);
103         gtk_main();
104         gdk_threads_leave();
105
106         gdk_display_close(gdk_display_get_default());
107
108         prefs   = NULL;
109         plugins = NULL;
110         viewer  = NULL;
111         window  = vbox = config = NULL;
112         return 0;
113 }