]> Pileus Git - grits/blob - src/main.c
843592c54317804727410cd667bf1abbb37d6b14
[grits] / src / main.c
1 /*
2  * Copyright (C) 2009 Andy Spencer <spenceal@rose-hulman.edu>
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
22 #include "aweather-gui.h"
23 #include "gis-view.h"
24 #include "gis-world.h"
25 #include "plugin-radar.h"
26 #include "plugin-ridge.h"
27 #include "plugin-example.h"
28
29 static gint log_levels = 0;
30
31 static void log_func(const gchar *log_domain, GLogLevelFlags log_level,
32               const gchar *message, gpointer udata)
33 {
34         if (log_level & log_levels)
35                 g_log_default_handler(log_domain, log_level, message, udata);
36 }
37
38 static gulong on_map_id = 0;
39 static gboolean on_map(AWeatherGui *gui, GdkEvent *event, gchar *site)
40 {
41         GisView *view = aweather_gui_get_view(gui);
42         gis_view_set_site(view, site);
43         g_signal_handler_disconnect(gui, on_map_id);
44         return FALSE;
45 }
46
47 /********
48  * Main *
49  ********/
50 int main(int argc, char *argv[])
51 {
52         /* Arguments */
53         gint     opt_debug   = 6;
54         gchar   *opt_site    = "KIND";
55         gboolean opt_auto    = FALSE;
56         gboolean opt_offline = FALSE;
57         GOptionEntry entries[] = {
58                 //long      short flg type                 location      description                 arg desc
59                 {"debug",   'd',  0,  G_OPTION_ARG_INT,    &opt_debug,   "Change default log level", "[1-7]"},
60                 {"site",    's',  0,  G_OPTION_ARG_STRING, &opt_site,    "Set initial site",         NULL},
61                 {"offline", 'o',  0,  G_OPTION_ARG_NONE,   &opt_offline, "Run in offline mode",      NULL},
62                 {"auto",    'a',  0,  G_OPTION_ARG_NONE,   &opt_auto,    "Auto update radar (todo)", NULL},
63                 {NULL}
64         };
65
66         /* Init */
67         GError *error = NULL;
68         g_thread_init(NULL);
69         if (!gtk_init_with_args(&argc, &argv, "aweather", entries, NULL, &error)) {
70                 g_print("%s\n", error->message);
71                 g_error_free(error);
72                 return -1;
73         }
74         gtk_gl_init(&argc, &argv);
75
76         /* Finish arguments */
77         log_levels = (1 << (opt_debug+1))-1;
78
79         /* Logging */
80         g_log_set_handler(NULL, G_LOG_LEVEL_MASK, log_func, NULL);
81
82         /* Set up AWeather */
83         /* TODO: Figure out a better way to do plugins
84          *    AWeatherPlugin interface for tabs?
85          *    GisPlugin      interface for expose? */
86         AWeatherGui  *gui  = aweather_gui_new();
87         GisWorld  *world  = aweather_gui_get_world(gui);
88         GisOpenGL *opengl = aweather_gui_get_opengl(gui);
89         gis_world_set_offline(world, opt_offline);
90         on_map_id = g_signal_connect(gui, "map-event", G_CALLBACK(on_map), opt_site);
91
92         /* Load plugins */
93         aweather_gui_register_plugin(gui, AWEATHER_PLUGIN(aweather_example_new(gui)));
94         aweather_gui_register_plugin(gui, AWEATHER_PLUGIN(aweather_ridge_new(gui)));
95         aweather_gui_register_plugin(gui, AWEATHER_PLUGIN(aweather_radar_new(gui)));
96         opengl->plugins = gui->plugins;
97
98         gtk_widget_show_all(GTK_WIDGET(gui));
99         gtk_main();
100
101         return 0;
102 }