]> Pileus Git - aweather/blob - src/main.c
Update for Gis{World,OpenGL,View,Viewer} refactoring
[aweather] / 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 <gis/gis.h>
23
24 #include "aweather-gui.h"
25
26 static gint log_levels = 0;
27
28 static void log_func(const gchar *log_domain, GLogLevelFlags log_level,
29               const gchar *message, gpointer udata)
30 {
31         if (log_level & log_levels)
32                 g_log_default_handler(log_domain, log_level, message, udata);
33 }
34
35 static void on_log_level_changed(GtkSpinButton *spinner, AWeatherGui *self)
36 {
37         g_message("main: log_level_changed");
38         gint value = gtk_spin_button_get_value_as_int(spinner);
39         log_levels = (1 << (value+1))-1;
40 }
41
42
43 /********
44  * Main *
45  ********/
46 int main(int argc, char *argv[])
47 {
48         /* Defaults */
49         gint     debug   = 6;
50         gchar   *site    = "KIND";
51         gboolean offline = FALSE;
52
53         /* Arguments */
54         gint     opt_debug   = 0;
55         gchar   *opt_site    = NULL;
56         gboolean opt_auto    = FALSE;
57         gboolean opt_offline = FALSE;
58         GOptionEntry entries[] = {
59                 //long      short flg type                 location      description                 arg desc
60                 {"debug",   'd',  0,  G_OPTION_ARG_INT,    &opt_debug,   "Change default log level", "[1-7]"},
61                 {"site",    's',  0,  G_OPTION_ARG_STRING, &opt_site,    "Set initial site",         NULL},
62                 {"offline", 'o',  0,  G_OPTION_ARG_NONE,   &opt_offline, "Run in offline mode",      NULL},
63                 {"auto",    'a',  0,  G_OPTION_ARG_NONE,   &opt_auto,    "Auto update radar (todo)", NULL},
64                 {NULL}
65         };
66
67         /* Init */
68         GError *error = NULL;
69         g_thread_init(NULL);
70         if (!gtk_init_with_args(&argc, &argv, "aweather", entries, NULL, &error)) {
71                 g_print("%s\n", error->message);
72                 g_error_free(error);
73                 return -1;
74         }
75         gtk_gl_init(&argc, &argv);
76
77         /* Do some logging here for aweather_gui_new */
78         if (opt_debug) log_levels = (1 << (opt_debug+1))-1;
79         else           log_levels = (1 << (6+1))-1;
80         g_log_set_handler(NULL, G_LOG_LEVEL_MASK, log_func, NULL);
81
82         /* Set up AWeather */
83         AWeatherGui *gui    = aweather_gui_new();
84
85         gint     prefs_debug   = gis_prefs_get_integer(gui->prefs, "aweather/log_level", NULL);
86         gchar   *prefs_site    = gis_prefs_get_string(gui->prefs,  "aweather/initial_site", NULL);
87         gboolean prefs_offline = gis_prefs_get_boolean(gui->prefs, "gis/offline", NULL);
88
89         debug   = (opt_debug   ?: prefs_debug   ?: debug);
90         site    = (opt_site    ?: prefs_site    ?: site);
91         offline = (opt_offline ?: prefs_offline ?: offline);
92
93         gis_viewer_set_offline(gui->viewer, offline);
94         log_levels = (1 << (debug+1))-1;
95
96         GObject *action = aweather_gui_get_object(gui, "prefs_general_log");
97         g_signal_connect(action, "changed", G_CALLBACK(on_log_level_changed), NULL);
98
99         gtk_widget_show_all(GTK_WIDGET(gui));
100         gis_viewer_set_site(gui->viewer, site);
101         gtk_main();
102         return 0;
103 }