]> Pileus Git - grits/blob - src/grits-test.c
Switch to GDK_KEY_*
[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 <gdk/gdkkeysyms.h>
21
22 #include "grits.h"
23
24 GritsPrefs   *prefs   = NULL;
25 GritsPlugins *plugins = NULL;
26 GritsViewer  *viewer  = NULL;
27
28 /*************
29  * Callbacks *
30  *************/
31 static gboolean grits_shutdown(GtkWidget *window)
32 {
33         static gboolean shutdown = FALSE;
34         if (shutdown) return TRUE;
35         shutdown = TRUE;
36
37         grits_plugins_free(plugins);
38         g_object_unref(prefs);
39         gtk_widget_destroy(window);
40         gtk_main_quit();
41         return TRUE;
42 }
43 static gboolean on_delete(GtkWidget *widget, GdkEvent *event, gpointer data)
44 {
45         return grits_shutdown(widget);
46 }
47 static gboolean on_key_press(GtkWidget *widget, GdkEventKey *event,
48                 gpointer _)
49 {
50         if (event->keyval == GDK_KEY_q)
51                 return grits_shutdown(widget);
52         return FALSE;
53 }
54 static void load_plugin(GritsPlugins *plugins, gchar *name,
55                 GritsViewer *viewer, GritsPrefs *prefs, GtkNotebook *notebook)
56 {
57         GritsPlugin *plugin = grits_plugins_load(plugins, name, viewer, prefs);
58         GtkWidget *config = grits_plugin_get_config(plugin);
59         if (config)
60                 gtk_notebook_append_page(notebook, config, gtk_label_new(name));
61 }
62
63 /***********
64  * Methods *
65  ***********/
66 int main(int argc, char **argv)
67 {
68         gdk_threads_init();
69         gtk_init(&argc, &argv);
70
71         prefs   = grits_prefs_new(NULL, NULL);
72         plugins = grits_plugins_new(g_getenv("GRITS_PLUGIN_PATH"), prefs);
73         viewer  = grits_opengl_new(plugins, prefs);
74
75         gdk_threads_enter();
76         GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
77         GtkWidget *vbox   = gtk_vbox_new(FALSE, 0);
78         GtkWidget *config = gtk_notebook_new();
79         g_signal_connect(window, "delete-event",    G_CALLBACK(on_delete),    NULL);
80         g_signal_connect(window, "key-press-event", G_CALLBACK(on_key_press), NULL);
81         gtk_widget_set_size_request(GTK_WIDGET(viewer), 300, 300);
82         gtk_notebook_set_tab_pos(GTK_NOTEBOOK(config), GTK_POS_BOTTOM);
83         gtk_container_add(GTK_CONTAINER(window), vbox);
84         gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(viewer), TRUE,  TRUE,  0);
85         gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(config), FALSE, FALSE, 0);
86         gtk_widget_show_all(window);
87
88         /* Configurable stuff */
89         grits_viewer_set_offline(viewer, TRUE);
90         (void)load_plugin;
91         load_plugin(plugins, "env",   viewer, prefs, GTK_NOTEBOOK(config));
92         //load_plugin(plugins, "elev",  viewer, prefs, GTK_NOTEBOOK(config));
93         //load_plugin(plugins, "sat",   viewer, prefs, GTK_NOTEBOOK(config));
94         load_plugin(plugins, "map",   viewer, prefs, GTK_NOTEBOOK(config));
95         //load_plugin(plugins, "alert", viewer, prefs, GTK_NOTEBOOK(config));
96         //load_plugin(plugins, "radar", viewer, prefs, GTK_NOTEBOOK(config));
97         load_plugin(plugins, "test",  viewer, prefs, GTK_NOTEBOOK(config));
98
99         gtk_widget_show_all(config);
100         gtk_main();
101         gdk_threads_leave();
102
103         gdk_display_close(gdk_display_get_default());
104
105         prefs   = NULL;
106         plugins = NULL;
107         viewer  = NULL;
108         window  = vbox = config = NULL;
109         return 0;
110 }