From: Andy Spencer Date: Thu, 6 Aug 2009 03:35:36 +0000 (+0000) Subject: bug fixes X-Git-Tag: v0.2~2 X-Git-Url: http://pileus.org/git/?p=grits;a=commitdiff_plain;h=e1ff13276e99a6707586fe43904d5d432cdcb1fe bug fixes --- diff --git a/src/Makefile.am b/src/Makefile.am index 18976bc..9b912f5 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -19,10 +19,10 @@ test: all ./aweather -o -d 7 -s KVNX gdb: all - gdb ./aweather + gdb .libs/aweather ddd: all - ddd ./aweather + ddd .libs/aweather memcheck: G_SLICE=always-malloc \ @@ -31,5 +31,5 @@ memcheck: --leak-resolution=high \ --num-callers=100 \ --suppressions=gtk.suppression \ - ./aweather \ + .libs/aweather \ 2> valgrind.out diff --git a/src/aweather-gui.c b/src/aweather-gui.c index 2720a00..480d026 100644 --- a/src/aweather-gui.c +++ b/src/aweather-gui.c @@ -55,7 +55,6 @@ static void aweather_gui_init(AWeatherGui *self) /* GIS things */ GtkWidget *drawing = aweather_gui_get_widget(self, "drawing"); - g_message("drawing = %p", drawing); self->opengl = gis_opengl_new(self->world, self->view, GTK_DRAWING_AREA(drawing)); self->opengl->plugins = self->plugins; //gtk_widget_show_all(GTK_WIDGET(self)); @@ -425,10 +424,8 @@ static void update_times_gtk(AWeatherGui *self, GList *times) GtkTreeIter iter; times = g_list_reverse(times); for (GList *cur = times; cur; cur = cur->next) { - g_message("trying time %s", (gchar*)cur->data); if (g_regex_match(regex, cur->data, 0, &info)) { gchar *time = g_match_info_fetch(info, 1); - g_message("adding time %s", (gchar*)cur->data); gtk_list_store_insert(lstore, &iter, 0); gtk_list_store_set(lstore, &iter, 0, time, -1); last_time = time; @@ -460,6 +457,7 @@ static void update_times_online_cb(char *path, gboolean updated, gpointer _self) } static void update_times(AWeatherGui *self, GisView *view, char *site) { + g_debug("AWeatherGui: update_times - site=%s", site); if (gis_world_get_offline(self->world)) { GList *times = NULL; gchar *path = g_build_filename(g_get_user_cache_dir(), PACKAGE, "nexrd2", "raw", site, NULL); @@ -475,15 +473,15 @@ static void update_times(AWeatherGui *self, GisView *view, char *site) update_times_gtk(self, times); } else { gchar *path = g_strdup_printf("nexrd2/raw/%s/dir.list", site); - char *base = gis_prefs_get_string(self->prefs, "general/nexrad_url"); - cache_file(base, path, AWEATHER_REFRESH, NULL, update_times_online_cb, self); + char *base = gis_prefs_get_string(self->prefs, "aweather/nexrad_url"); + cache_file(base, path, GIS_REFRESH, NULL, update_times_online_cb, self); /* update_times_gtk from update_times_online_cb */ } } static void on_gis_site_changed(GisView *view, char *site, gpointer _self) { AWeatherGui *self = AWEATHER_GUI(_self); - g_debug("GisPluginRadar: on_site_changed - Loading wsr88d list for %s", site); + g_debug("AWeatherGui: on_site_changed - Loading wsr88d list for %s", site); update_times(self, view, site); } static void on_gis_refresh(GisWorld *world, gpointer _self) @@ -549,5 +547,14 @@ void aweather_gui_attach_plugin(AWeatherGui *self, const gchar *name) } void aweather_gui_deattach_plugin(AWeatherGui *self, const gchar *name) { + GtkWidget *config = aweather_gui_get_widget(self, "tabs"); + guint n_pages = gtk_notebook_get_n_pages(GTK_NOTEBOOK(config)); + for (int i = 0; i < n_pages; i++) { + GtkWidget *body = gtk_notebook_get_nth_page(GTK_NOTEBOOK(config), i); + GtkWidget *tab = gtk_notebook_get_tab_label(GTK_NOTEBOOK(config), body); + const gchar *tab_name = gtk_label_get_text(GTK_LABEL(tab)); + if (tab_name && g_str_equal(name, tab_name)) + gtk_notebook_remove_page(GTK_NOTEBOOK(config), i); + } gis_plugins_unload(self->plugins, name); } diff --git a/src/gis/Makefile.am b/src/gis/Makefile.am index 97d8a39..786be00 100644 --- a/src/gis/Makefile.am +++ b/src/gis/Makefile.am @@ -19,7 +19,7 @@ libgis_la_SOURCES = \ gis-plugin.c gis-plugin.h \ gis-data.c gis-data.h \ gis-marshal.c gis-marshal.h -libgis_la_CPPFLAGS = -DPLUGINDIR="\"$(libdir)/aweather\"" $(SOUP_CFLAGS) $(GLIB_CFLAGS) $(GTK_CFLAGS) +libgis_la_CPPFLAGS = -DPLUGINDIR="\"$(libdir)/gis\"" $(SOUP_CFLAGS) $(GLIB_CFLAGS) $(GTK_CFLAGS) libgis_la_LIBADD = $(SOUP_LIBS) $(GLIB_LIBS) $(GTK_LIBS) MAINTAINERCLEANFILES = Makefile.in diff --git a/src/gis/gis-data.c b/src/gis/gis-data.c index 7c9f2c9..56c39b4 100644 --- a/src/gis/gis-data.c +++ b/src/gis/gis-data.c @@ -26,8 +26,8 @@ typedef struct { gchar *uri; gchar *local; FILE *fp; - AWeatherCacheDoneCallback user_done_cb; - AWeatherCacheChunkCallback user_chunk_cb; + GisDataCacheDoneCallback user_done_cb; + GisDataCacheChunkCallback user_chunk_cb; gpointer user_data; } cache_file_end_t; @@ -111,12 +111,20 @@ static SoupSession *do_cache(cache_file_end_t *info, gboolean truncate, gchar *r * \param path Path to the Ridge file, starting after /ridge/ * \return The local path to the cached image */ -SoupSession *cache_file(char *base, char *path, AWeatherCacheType update, - AWeatherCacheChunkCallback user_chunk_cb, - AWeatherCacheDoneCallback user_done_cb, +SoupSession *cache_file(char *base, char *path, GisDataCacheType update, + GisDataCacheChunkCallback user_chunk_cb, + GisDataCacheDoneCallback user_done_cb, gpointer user_data) { - + g_debug("GisData: cache_file - base=%s, path=%s", base, path); + if (base == NULL) { + g_warning("GisData: cache_file - base is null"); + return NULL; + } + if (path == NULL) { + g_warning("GisData: cache_file - base is null"); + return NULL; + } cache_file_end_t *info = g_malloc0(sizeof(cache_file_end_t)); info->uri = g_strconcat(base, path, NULL); info->local = g_build_filename(g_get_user_cache_dir(), PACKAGE, path, NULL); @@ -125,13 +133,13 @@ SoupSession *cache_file(char *base, char *path, AWeatherCacheType update, info->user_done_cb = user_done_cb; info->user_data = user_data; - if (update == AWEATHER_REFRESH) + if (update == GIS_REFRESH) return do_cache(info, TRUE, "cache forced"); - if (update == AWEATHER_UPDATE) + if (update == GIS_UPDATE) return do_cache(info, FALSE, "attempting updating"); - if (update == AWEATHER_ONCE && !g_file_test(info->local, G_FILE_TEST_EXISTS)) + if (update == GIS_ONCE && !g_file_test(info->local, G_FILE_TEST_EXISTS)) return do_cache(info, TRUE, "local does not exist"); /* No nead to cache, run the callback now and clean up */ diff --git a/src/gis/gis-data.h b/src/gis/gis-data.h index f08f936..5fe9067 100644 --- a/src/gis/gis-data.h +++ b/src/gis/gis-data.h @@ -21,20 +21,20 @@ #include typedef enum { - AWEATHER_ONCE, // Cache the file if it does not exist - AWEATHER_UPDATE, // Append additional data to cached copy (resume) - AWEATHER_REFRESH, // Delete existing file and cache a new copy -} AWeatherCacheType; + GIS_ONCE, // Cache the file if it does not exist + GIS_UPDATE, // Append additional data to cached copy (resume) + GIS_REFRESH, // Delete existing file and cache a new copy +} GisDataCacheType; -typedef void (*AWeatherCacheDoneCallback)(gchar *file, gboolean updated, +typedef void (*GisDataCacheDoneCallback)(gchar *file, gboolean updated, gpointer user_data); -typedef void (*AWeatherCacheChunkCallback)(gchar *file, goffset cur, +typedef void (*GisDataCacheChunkCallback)(gchar *file, goffset cur, goffset total, gpointer user_data); -SoupSession *cache_file(char *base, char *path, AWeatherCacheType update, - AWeatherCacheChunkCallback user_chunk_cb, - AWeatherCacheDoneCallback user_done_cb, +SoupSession *cache_file(char *base, char *path, GisDataCacheType update, + GisDataCacheChunkCallback user_chunk_cb, + GisDataCacheDoneCallback user_done_cb, gpointer user_data); #endif diff --git a/src/gis/gis-opengl.c b/src/gis/gis-opengl.c index acf12eb..bdcaf40 100644 --- a/src/gis/gis-opengl.c +++ b/src/gis/gis-opengl.c @@ -137,8 +137,8 @@ gboolean on_configure(GtkWidget *drawing, GdkEventConfigure *event, GisOpenGL *s gis_view_get_location(self->view, &x, &y, &z); /* Window is at 500 m from camera */ - double width = drawing->allocation.width; - double height = drawing->allocation.height; + double width = GTK_WIDGET(self->drawing)->allocation.width; + double height = GTK_WIDGET(self->drawing)->allocation.height; glViewport(0, 0, width, height); @@ -198,7 +198,6 @@ GisOpenGL *gis_opengl_new(GisWorld *world, GisView *view, GtkDrawingArea *drawin self->world = world; self->view = view; self->drawing = drawing; - g_message("drawing = %p", drawing); g_object_ref(world); g_object_ref(view); g_object_ref(drawing); @@ -235,7 +234,6 @@ void gis_opengl_begin(GisOpenGL *self) { g_assert(GIS_IS_OPENGL(self)); - g_message("drawing = %p", self->drawing); GdkGLContext *glcontext = gtk_widget_get_gl_context(GTK_WIDGET(self->drawing)); GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable(GTK_WIDGET(self->drawing)); diff --git a/src/gis/gis-plugin.c b/src/gis/gis-plugin.c index e15c53c..6888b48 100644 --- a/src/gis/gis-plugin.c +++ b/src/gis/gis-plugin.c @@ -82,6 +82,8 @@ void gis_plugins_free(GisPlugins *self) GList *gis_plugins_available() { GDir *dir = g_dir_open(PLUGINDIR, 0, NULL); + if (dir == NULL) + return NULL; GList *list = NULL; const gchar *name; while ((name = g_dir_read_name(dir))) { diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am index 7a0c4be..d831149 100644 --- a/src/plugins/Makefile.am +++ b/src/plugins/Makefile.am @@ -2,7 +2,7 @@ AM_CFLAGS = -Wall -Werror -Wno-unused --std=gnu99 -I../ AM_CPPFLAGS = $(GLIB_CFLAGS) $(GTK_CFLAGS) AM_LDFLAGS = -module $(GLIB_LIBS) $(GTK_LIBS) -plugindir = $(libdir)/aweather +plugindir = $(libdir)/gis plugin_LTLIBRARIES = \ example.la \ diff --git a/src/plugins/example.c b/src/plugins/example.c index 3930fb5..01ef9ca 100644 --- a/src/plugins/example.c +++ b/src/plugins/example.c @@ -28,6 +28,7 @@ * GObject code * ****************/ /* Plugin init */ +static gboolean rotate(gpointer _self); static void gis_plugin_example_plugin_init(GisPluginInterface *iface); static void gis_plugin_example_expose(GisPlugin *_self); static GtkWidget *gis_plugin_example_get_config(GisPlugin *_self); @@ -46,14 +47,16 @@ static void gis_plugin_example_init(GisPluginExample *self) { g_debug("GisPluginExample: init"); /* Set defaults */ - self->opengl = NULL; - self->button = NULL; - self->rotation = 30.0; + self->button = GTK_TOGGLE_BUTTON(gtk_toggle_button_new_with_label("Rotate")); + self->rotate_id = g_timeout_add(1000/60, rotate, self); + self->rotation = 30.0; + self->opengl = NULL; } static void gis_plugin_example_dispose(GObject *gobject) { g_debug("GisPluginExample: dispose"); GisPluginExample *self = GIS_PLUGIN_EXAMPLE(gobject); + g_source_remove(self->rotate_id); /* Drop references */ G_OBJECT_CLASS(gis_plugin_example_parent_class)->dispose(gobject); } @@ -94,10 +97,6 @@ GisPluginExample *gis_plugin_example_new(GisWorld *world, GisView *view, GisOpen g_debug("GisPluginExample: new"); GisPluginExample *self = g_object_new(GIS_TYPE_PLUGIN_EXAMPLE, NULL); self->opengl = opengl; - self->button = GTK_TOGGLE_BUTTON(gtk_toggle_button_new_with_label("Rotate")); - - /* Set up OpenGL Stuff */ - g_timeout_add(1000/60, rotate, self); return self; } diff --git a/src/plugins/example.h b/src/plugins/example.h index e9a2edd..039d3bb 100644 --- a/src/plugins/example.h +++ b/src/plugins/example.h @@ -34,9 +34,10 @@ struct _GisPluginExample { GObject parent_instance; /* instance members */ - GisOpenGL *opengl; GtkToggleButton *button; + guint rotate_id; float rotation; + GisOpenGL *opengl; }; struct _GisPluginExampleClass { diff --git a/src/plugins/aweather b/src/plugins/gis similarity index 100% rename from src/plugins/aweather rename to src/plugins/gis diff --git a/src/marching.c b/src/plugins/marching.c similarity index 100% rename from src/marching.c rename to src/plugins/marching.c diff --git a/src/marching.h b/src/plugins/marching.h similarity index 100% rename from src/marching.h rename to src/plugins/marching.h diff --git a/src/plugins/radar-colormap.c b/src/plugins/radar-colormap.c index 24f6015..03b2f32 100644 --- a/src/plugins/radar-colormap.c +++ b/src/plugins/radar-colormap.c @@ -1,5 +1,4 @@ #include -#include "aweather-gui.h" #include "radar.h" //{0xcc,0xff,0xff,0xff},{0xcc,0xff,0xff,0xff}, {0xcc,0xff,0xff,0xff}, diff --git a/src/plugins/radar.c b/src/plugins/radar.c index 107ccf2..c912151 100644 --- a/src/plugins/radar.c +++ b/src/plugins/radar.c @@ -47,18 +47,23 @@ static void gis_plugin_radar_plugin_init(GisPluginInterface *iface) iface->get_config = gis_plugin_radar_get_config; } /* Class/Object init */ -static void gis_plugin_radar_init(GisPluginRadar *radar) +static void gis_plugin_radar_init(GisPluginRadar *self) { g_debug("GisPluginRadar: class_init"); /* Set defaults */ - radar->soup = NULL; - radar->cur_triangles = NULL; - radar->cur_num_triangles = 0; + self->soup = NULL; + self->cur_triangles = NULL; + self->cur_num_triangles = 0; + + self->config_body = gtk_alignment_new(0, 0, 1, 1); + gtk_container_set_border_width(GTK_CONTAINER(self->config_body), 5); + gtk_container_add(GTK_CONTAINER(self->config_body), gtk_label_new("No radar loaded")); } static void gis_plugin_radar_dispose(GObject *gobject) { g_debug("GisPluginRadar: dispose"); GisPluginRadar *self = GIS_PLUGIN_RADAR(gobject); + g_signal_handler_disconnect(self->view, self->time_changed_id); /* Drop references */ G_OBJECT_CLASS(gis_plugin_radar_parent_class)->dispose(gobject); } @@ -389,8 +394,8 @@ static void cache_chunk_cb(char *path, goffset cur, goffset total, gpointer _sel GisPluginRadar *self = GIS_PLUGIN_RADAR(_self); double percent = (double)cur/total; - g_message("GisPluginRadar: cache_chunk_cb - %lld/%lld = %.2f%%", - cur, total, percent*100); + //g_message("GisPluginRadar: cache_chunk_cb - %lld/%lld = %.2f%%", + // cur, total, percent*100); gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(self->progress_bar), MIN(percent, 1.0)); @@ -480,12 +485,12 @@ static void on_time_changed(GisView *view, const char *time, gpointer _self) soup_session_abort(self->soup); self->soup = NULL; } - gchar *base = gis_prefs_get_string(self->prefs, "general/nexrad_url"); + gchar *base = gis_prefs_get_string(self->prefs, "aweather/nexrad_url"); if (gis_world_get_offline(self->world)) - self->soup = cache_file(base, path, AWEATHER_ONCE, + self->soup = cache_file(base, path, GIS_ONCE, cache_chunk_cb, cache_done_cb, self); else - self->soup = cache_file(base, path, AWEATHER_UPDATE, + self->soup = cache_file(base, path, GIS_UPDATE, cache_chunk_cb, cache_done_cb, self); g_free(path); } @@ -502,14 +507,8 @@ GisPluginRadar *gis_plugin_radar_new(GisWorld *world, GisView *view, GisOpenGL * self->view = view; self->opengl = opengl; self->prefs = prefs; - - self->config_body = gtk_alignment_new(0, 0, 1, 1); - gtk_container_set_border_width(GTK_CONTAINER(self->config_body), 5); - gtk_container_add(GTK_CONTAINER(self->config_body), gtk_label_new("No radar loaded")); - - /* Set up OpenGL Stuff */ - g_signal_connect(view, "time-changed", G_CALLBACK(on_time_changed), self); - + self->time_changed_id = g_signal_connect(view, "time-changed", + G_CALLBACK(on_time_changed), self); return self; } diff --git a/src/plugins/radar.h b/src/plugins/radar.h index 95367b4..c4b74be 100644 --- a/src/plugins/radar.h +++ b/src/plugins/radar.h @@ -55,6 +55,7 @@ struct _GisPluginRadar { GtkWidget *progress_bar; GtkWidget *progress_label; SoupSession *soup; + guint time_changed_id; /* Private data for loading radars */ Radar *cur_radar; diff --git a/src/plugins/ridge.c b/src/plugins/ridge.c index 2250a69..a25bd59 100644 --- a/src/plugins/ridge.c +++ b/src/plugins/ridge.c @@ -179,8 +179,7 @@ static void on_site_changed(GisView *view, gchar *site, GisPluginRidge *self) cached_t *udata = g_malloc(sizeof(cached_t)); udata->self = self; udata->layer = &layers[i]; - cache_file(base, path, AWEATHER_ONCE, NULL, cached_cb, udata); - //cache_file(base, path, AWEATHER_UPDATE, cached_cb, udata); + cache_file(base, path, GIS_ONCE, NULL, cached_cb, udata); g_free(path); } }