]> Pileus Git - grits/blob - src/main.c
compiler fixes
[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 "plugin-radar.h"
24 #include "plugin-ridge.h"
25 #include "plugin-example.h"
26
27 static gint log_levels = 0;
28
29 static void log_func(const gchar *log_domain, GLogLevelFlags log_level,
30               const gchar *message, gpointer udata)
31 {
32         if (log_level & log_levels)
33                 g_log_default_handler(log_domain, log_level, message, udata);
34 }
35
36 static gboolean on_map(AWeatherGui *gui, GdkEvent *event, gchar *site)
37 {
38         AWeatherView *view = aweather_gui_get_view(gui);
39         aweather_view_set_site(view, site);
40         return FALSE;
41 }
42
43 /********
44  * Main *
45  ********/
46 int main(int argc, char *argv[])
47 {
48         /* Arguments */
49         gint     opt_debug = 6;
50         gchar   *opt_site  = "IND";
51         gboolean opt_auto  = FALSE;
52         GOptionEntry entries[] = {
53                 //long    short flg type                 location    description                 arg desc
54                 {"debug", 'd',  0,  G_OPTION_ARG_INT,    &opt_debug, "Change default log level", "[1-7]"},
55                 {"site",  's',  0,  G_OPTION_ARG_STRING, &opt_site,  "Set initial site",         NULL},
56                 {"auto",  'a',  0,  G_OPTION_ARG_NONE,   &opt_auto,  "Auto update radar (todo)", NULL},
57                 {NULL}
58         };
59
60         /* Init */
61         GError *error = NULL;
62         g_thread_init(NULL);
63         if (!gtk_init_with_args(&argc, &argv, "aweather", entries, NULL, &error)) {
64                 g_print("%s\n", error->message);
65                 g_error_free(error);
66                 return -1;
67         }
68         gtk_gl_init(&argc, &argv);
69
70         /* Finish arguments */
71         log_levels = (1 << (opt_debug+1))-1;
72
73         /* Logging */
74         g_log_set_handler(NULL, G_LOG_LEVEL_MASK, log_func, NULL);
75
76         /* Set up AWeather */
77         AWeatherGui  *gui  = aweather_gui_new();
78         AWeatherView *view = aweather_gui_get_view(gui);
79         g_signal_connect(gui, "map-event", G_CALLBACK(on_map), opt_site);
80
81         /* Load plugins */
82         aweather_gui_register_plugin(gui, AWEATHER_PLUGIN(aweather_example_new(gui)));
83         aweather_gui_register_plugin(gui, AWEATHER_PLUGIN(aweather_ridge_new(gui)));
84         aweather_gui_register_plugin(gui, AWEATHER_PLUGIN(aweather_radar_new(gui)));
85
86         gtk_widget_show_all(GTK_WIDGET(gui));
87         gtk_main();
88
89         return 0;
90 }