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