2 * Copyright (C) 2009-2010 Andy Spencer <andy753421@gmail.com>
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.
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.
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/>.
21 #include <glib/gstdio.h>
32 #include "../aweather-location.h"
34 static void _gtk_bin_set_child(GtkBin *bin, GtkWidget *new)
36 GtkWidget *old = gtk_bin_get_child(bin);
38 gtk_widget_destroy(old);
39 gtk_container_add(GTK_CONTAINER(bin), new);
40 gtk_widget_show_all(new);
43 static gchar *_find_nearest(time_t time, GList *files,
44 gsize offset, gchar *format)
46 g_debug("RadarSite: find_nearest ...");
47 time_t nearest_time = 0;
48 char *nearest_file = NULL;
51 for (GList *cur = files; cur; cur = cur->next) {
52 gchar *file = cur->data;
53 strptime(file+offset, format, &tm);
54 if (ABS(time - mktime(&tm)) <
55 ABS(time - nearest_time)) {
57 nearest_time = mktime(&tm);
61 g_debug("RadarSite: find_nearest = %s", nearest_file);
63 return g_strdup(nearest_file);
80 GritsMarker *marker; // Map marker for grits
82 /* Stuff from the parents */
90 RadarSiteStatus status; // Loading status for the site
92 AWeatherLevel2 *level2; // The Level2 structure for the current volume
95 time_t time; // Current timestamp of the level2
96 gchar *message; // Error message set while updating
97 guint time_id; // "time-changed" callback ID
98 guint refresh_id; // "refresh" callback ID
99 guint location_id; // "locaiton-changed" callback ID
102 /* format: http://mesonet.agron.iastate.edu/data/nexrd2/raw/KABR/KABR_20090510_0323 */
103 void _site_update_loading(gchar *file, goffset cur,
104 goffset total, gpointer _site)
106 RadarSite *site = _site;
107 GtkWidget *progress_bar = gtk_bin_get_child(GTK_BIN(site->config));
108 double percent = (double)cur/total;
109 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress_bar), MIN(percent, 1.0));
110 gchar *msg = g_strdup_printf("Loading... %5.1f%% (%.2f/%.2f MB)",
111 percent*100, (double)cur/1000000, (double)total/1000000);
112 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progress_bar), msg);
115 gboolean _site_update_end(gpointer _site)
117 RadarSite *site = _site;
119 g_warning("RadarSite: update_end - %s", site->message);
120 _gtk_bin_set_child(GTK_BIN(site->config),
121 gtk_label_new(site->message));
123 _gtk_bin_set_child(GTK_BIN(site->config),
124 aweather_level2_get_config(site->level2));
126 site->status = STATUS_LOADED;
129 gpointer _site_update_thread(gpointer _site)
131 RadarSite *site = _site;
132 g_debug("RadarSite: update_thread - %s", site->city->code);
133 site->message = NULL;
135 gboolean offline = grits_viewer_get_offline(site->viewer);
136 gchar *nexrad_url = grits_prefs_get_string(site->prefs,
137 "aweather/nexrad_url", NULL);
139 /* Find nearest volume (temporally) */
140 g_debug("RadarSite: update_thread - find nearest - %s", site->city->code);
141 gchar *dir_list = g_strconcat(nexrad_url, "/", site->city->code,
142 "/", "dir.list", NULL);
143 GList *files = grits_http_available(site->http,
144 "^K\\w{3}_\\d{8}_\\d{4}$", site->city->code,
145 "\\d+ (.*)", (offline ? NULL : dir_list));
147 gchar *nearest = _find_nearest(site->time, files, 5, "%Y%m%d_%H%M");
148 g_list_foreach(files, (GFunc)g_free, NULL);
151 site->message = "No suitable files found";
155 /* Fetch new volume */
156 g_debug("RadarSite: update_thread - fetch");
157 gchar *local = g_strconcat(site->city->code, "/", nearest, NULL);
158 gchar *uri = g_strconcat(nexrad_url, "/", local, NULL);
159 gchar *file = grits_http_fetch(site->http, uri, local,
160 offline ? GRITS_LOCAL : GRITS_UPDATE,
161 _site_update_loading, site);
167 site->message = "Fetch failed";
171 /* Load and add new volume */
172 g_debug("RadarSite: update_thread - load - %s", site->city->code);
173 site->level2 = aweather_level2_new_from_file(
174 file, site->city->code, colormaps);
177 site->message = "Load failed";
180 grits_object_hide(GRITS_OBJECT(site->level2), site->hidden);
181 grits_viewer_add(site->viewer, GRITS_OBJECT(site->level2),
182 GRITS_LEVEL_WORLD, TRUE);
185 g_idle_add(_site_update_end, site);
188 void _site_update(RadarSite *site)
190 if (site->status == STATUS_LOADING)
192 site->status = STATUS_LOADING;
194 site->time = grits_viewer_get_time(site->viewer);
195 g_debug("RadarSite: update %s - %d",
196 site->city->code, (gint)site->time);
198 /* Add a progress bar */
199 GtkWidget *progress = gtk_progress_bar_new();
200 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progress), "Loading...");
201 _gtk_bin_set_child(GTK_BIN(site->config), progress);
203 /* Remove old volume */
204 g_debug("RadarSite: update - remove - %s", site->city->code);
206 grits_viewer_remove(site->viewer, site->level2);
210 /* Fork loading right away so updating the
211 * list of times doesn't take too long */
212 g_thread_create(_site_update_thread, site, FALSE, NULL);
215 /* RadarSite methods */
216 void radar_site_unload(RadarSite *site)
218 if (site->status != STATUS_LOADED)
219 return; // Abort if it's still loading
221 g_debug("RadarSite: unload %s", site->city->code);
224 g_signal_handler_disconnect(site->viewer, site->time_id);
225 if (site->refresh_id)
226 g_signal_handler_disconnect(site->viewer, site->refresh_id);
230 gtk_widget_destroy(site->config);
234 grits_viewer_remove(site->viewer, site->level2);
238 site->status = STATUS_UNLOADED;
241 void radar_site_load(RadarSite *site)
243 g_debug("RadarSite: load %s", site->city->code);
246 site->config = gtk_alignment_new(0, 0, 1, 1);
247 g_object_set_data(G_OBJECT(site->config), "site", site);
248 gtk_notebook_append_page(GTK_NOTEBOOK(site->pconfig), site->config,
249 gtk_label_new(site->city->name));
250 gtk_widget_show_all(site->config);
252 /* Set up radar loading */
253 site->time_id = g_signal_connect_swapped(site->viewer, "time-changed",
254 G_CALLBACK(_site_update), site);
255 site->refresh_id = g_signal_connect_swapped(site->viewer, "refresh",
256 G_CALLBACK(_site_update), site);
260 void _site_on_location_changed(GritsViewer *viewer,
261 gdouble lat, gdouble lon, gdouble elev,
264 static gdouble min_dist = EARTH_R / 30;
265 RadarSite *site = _site;
267 /* Calculate distance, could cache xyz values */
268 gdouble eye_xyz[3], site_xyz[3];
269 lle2xyz(lat, lon, elev, &eye_xyz[0], &eye_xyz[1], &eye_xyz[2]);
270 lle2xyz(site->city->pos.lat, site->city->pos.lon, site->city->pos.elev,
271 &site_xyz[0], &site_xyz[1], &site_xyz[2]);
272 gdouble dist = distd(site_xyz, eye_xyz);
274 /* Load or unload the site if necessasairy */
275 if (dist <= min_dist && dist < elev*1.25 && site->status == STATUS_UNLOADED)
276 radar_site_load(site);
277 else if (dist > 2*min_dist && site->status != STATUS_UNLOADED)
278 radar_site_unload(site);
281 gboolean _site_add_marker(gpointer _site)
283 RadarSite *site = _site;
284 site->marker = grits_marker_new(site->city->name);
285 GRITS_OBJECT(site->marker)->center = site->city->pos;
286 GRITS_OBJECT(site->marker)->lod = EARTH_R*site->city->lod;
287 grits_viewer_add(site->viewer, GRITS_OBJECT(site->marker),
288 GRITS_LEVEL_OVERLAY, FALSE);
291 RadarSite *radar_site_new(city_t *city, GtkWidget *pconfig,
292 GritsViewer *viewer, GritsPrefs *prefs, GritsHttp *http)
294 RadarSite *site = g_new0(RadarSite, 1);
295 site->viewer = g_object_ref(viewer);
296 site->prefs = g_object_ref(prefs);
298 site->http = grits_http_new(G_DIR_SEPARATOR_S
299 "nexrad" G_DIR_SEPARATOR_S
300 "level2" G_DIR_SEPARATOR_S);
302 site->pconfig = pconfig;
305 g_idle_add_full(G_PRIORITY_LOW, _site_add_marker, site, NULL);
307 /* Connect signals */
308 site->location_id = g_signal_connect(viewer, "location-changed",
309 G_CALLBACK(_site_on_location_changed), site);
313 void radar_site_free(RadarSite *site)
315 radar_site_unload(site);
316 grits_viewer_remove(site->viewer, site->marker);
317 if (site->location_id)
318 g_signal_handler_disconnect(site->viewer, site->location_id);
319 grits_http_free(site->http);
320 g_object_unref(site->viewer);
321 g_object_unref(site->prefs);
329 #define CONUS_NORTH 50.406626367301044
330 #define CONUS_WEST -127.620375523875420
331 #define CONUS_WIDTH 3400.0
332 #define CONUS_HEIGHT 1600.0
333 #define CONUS_DEG_PER_PX 0.017971305190311
340 const gchar *message;
341 GStaticMutex loading;
346 guint time_id; // "time-changed" callback ID
347 guint refresh_id; // "refresh" callback ID
350 void _conus_update_loading(gchar *file, goffset cur,
351 goffset total, gpointer _conus)
353 RadarConus *conus = _conus;
354 GtkWidget *progress_bar = gtk_bin_get_child(GTK_BIN(conus->config));
355 double percent = (double)cur/total;
356 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress_bar), MIN(percent, 1.0));
357 gchar *msg = g_strdup_printf("Loading... %5.1f%% (%.2f/%.2f MB)",
358 percent*100, (double)cur/1000000, (double)total/1000000);
359 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progress_bar), msg);
363 /* Copy images to graphics memory */
364 static void _conus_update_end_copy(GritsTile *tile, guchar *pixels)
367 tile->data = g_new0(guint, 1);
368 glGenTextures(1, tile->data);
371 guint *tex = tile->data;
372 glBindTexture(GL_TEXTURE_2D, *tex);
374 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
375 glPixelStorei(GL_PACK_ALIGNMENT, 1);
376 glTexImage2D(GL_TEXTURE_2D, 0, 4, 2048, 2048, 0,
377 GL_RGBA, GL_UNSIGNED_BYTE, NULL);
378 glTexSubImage2D(GL_TEXTURE_2D, 0, 1,1, CONUS_WIDTH/2,CONUS_HEIGHT,
379 GL_RGBA, GL_UNSIGNED_BYTE, pixels);
380 tile->coords.n = 1.0/(CONUS_WIDTH/2);
381 tile->coords.w = 1.0/ CONUS_HEIGHT;
382 tile->coords.s = tile->coords.n + CONUS_HEIGHT / 2048.0;
383 tile->coords.e = tile->coords.w + (CONUS_WIDTH/2) / 2048.0;
384 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
385 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
386 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
387 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
391 /* Split the pixbuf into east and west halves (with 2K sides)
392 * Also map the pixbuf's alpha values */
393 static void _conus_update_end_split(guchar *pixels, guchar *west, guchar *east,
394 gint width, gint height, gint pxsize)
396 g_debug("Conus: update_end_split");
397 guchar *out[] = {west,east};
398 const guchar alphamap[][4] = {
399 {0x04, 0xe9, 0xe7, 0x30},
400 {0x01, 0x9f, 0xf4, 0x60},
401 {0x03, 0x00, 0xf4, 0x90},
403 for (int y = 0; y < height; y++)
404 for (int x = 0; x < width; x++) {
405 gint subx = x % (width/2);
406 gint idx = x / (width/2);
407 guchar *src = &pixels[(y*width+x)*pxsize];
408 guchar *dst = &out[idx][(y*(width/2)+subx)*4];
418 for (int j = 0; j < G_N_ELEMENTS(alphamap); j++)
419 if (src[0] == alphamap[j][0] &&
420 src[1] == alphamap[j][1] &&
421 src[2] == alphamap[j][2])
422 dst[3] = alphamap[j][3];
427 gboolean _conus_update_end(gpointer _conus)
429 RadarConus *conus = _conus;
430 g_debug("Conus: update_end");
432 /* Check error status */
433 if (conus->message) {
434 g_warning("Conus: update_end - %s", conus->message);
435 _gtk_bin_set_child(GTK_BIN(conus->config), gtk_label_new(conus->message));
439 /* Load and pixbuf */
440 GError *error = NULL;
441 GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(conus->path, &error);
442 if (!pixbuf || error) {
443 g_warning("Conus: update_end - error loading pixbuf");
444 _gtk_bin_set_child(GTK_BIN(conus->config), gtk_label_new("Error loading pixbuf"));
445 g_remove(conus->path);
449 /* Split pixels into east/west parts */
450 guchar *pixels = gdk_pixbuf_get_pixels(pixbuf);
451 gint width = gdk_pixbuf_get_width(pixbuf);
452 gint height = gdk_pixbuf_get_height(pixbuf);
453 gint pxsize = gdk_pixbuf_get_has_alpha(pixbuf) ? 4 : 3;
454 guchar *pixels_west = g_malloc(4*(width/2)*height);
455 guchar *pixels_east = g_malloc(4*(width/2)*height);
456 _conus_update_end_split(pixels, pixels_west, pixels_east,
457 width, height, pxsize);
458 g_object_unref(pixbuf);
460 /* Copy pixels to graphics memory */
461 _conus_update_end_copy(conus->tile[0], pixels_west);
462 _conus_update_end_copy(conus->tile[1], pixels_east);
467 gchar *label = g_path_get_basename(conus->path);
468 _gtk_bin_set_child(GTK_BIN(conus->config), gtk_label_new(label));
469 gtk_widget_queue_draw(GTK_WIDGET(conus->viewer));
474 g_static_mutex_unlock(&conus->loading);
478 gpointer _conus_update_thread(gpointer _conus)
480 RadarConus *conus = _conus;
481 conus->message = NULL;
484 g_debug("Conus: update_thread - nearest");
485 gchar *conus_url = "http://radar.weather.gov/Conus/RadarImg/";
487 if (time(NULL) - conus->time < 60*60*5){
488 /* radar.weather.gov is full of lies.
489 * the index pages get cached and out of date */
491 gmtime_r(&conus->time, &tm);
492 time_t onthe8 = conus->time - 60*((tm.tm_min+2)%10);
493 gmtime_r(&onthe8, &tm);
494 nearest = g_strdup_printf("Conus_%04d%02d%02d_%02d%02d_N0Ronly.gif",
495 tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday,
496 tm.tm_hour, tm.tm_min);
498 GList *files = grits_http_available(conus->http,
499 "^Conus_[^\"]*_N0Ronly.gif$", "", NULL, NULL);
500 nearest = _find_nearest(conus->time, files, 6, "%Y%m%d_%H%M");
501 g_list_foreach(files, (GFunc)g_free, NULL);
504 conus->message = "No suitable files";
509 /* Fetch the image */
510 g_debug("Conus: update_thread - fetch");
511 gchar *uri = g_strconcat(conus_url, nearest, NULL);
512 conus->path = grits_http_fetch(conus->http, uri, nearest, GRITS_ONCE,
513 _conus_update_loading, conus);
517 conus->message = "Fetch failed";
522 g_debug("Conus: update_thread - done");
523 g_idle_add(_conus_update_end, conus);
527 void _conus_update(RadarConus *conus)
529 if (!g_static_mutex_trylock(&conus->loading))
531 conus->time = grits_viewer_get_time(conus->viewer);
532 g_debug("Conus: update - %d",
535 /* Add a progress bar */
536 GtkWidget *progress = gtk_progress_bar_new();
537 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progress), "Loading...");
538 _gtk_bin_set_child(GTK_BIN(conus->config), progress);
540 g_thread_create(_conus_update_thread, conus, FALSE, NULL);
543 RadarConus *radar_conus_new(GtkWidget *pconfig,
544 GritsViewer *viewer, GritsHttp *http)
546 RadarConus *conus = g_new0(RadarConus, 1);
547 conus->viewer = g_object_ref(viewer);
549 conus->config = gtk_alignment_new(0, 0, 1, 1);
550 g_static_mutex_init(&conus->loading);
552 gdouble south = CONUS_NORTH - CONUS_DEG_PER_PX*CONUS_HEIGHT;
553 gdouble east = CONUS_WEST + CONUS_DEG_PER_PX*CONUS_WIDTH;
554 gdouble mid = CONUS_WEST + CONUS_DEG_PER_PX*CONUS_WIDTH/2;
555 conus->tile[0] = grits_tile_new(NULL, CONUS_NORTH, south, mid, CONUS_WEST);
556 conus->tile[1] = grits_tile_new(NULL, CONUS_NORTH, south, east, mid);
557 conus->tile[0]->zindex = 2;
558 conus->tile[1]->zindex = 1;
559 grits_viewer_add(viewer, GRITS_OBJECT(conus->tile[0]), GRITS_LEVEL_WORLD, TRUE);
560 grits_viewer_add(viewer, GRITS_OBJECT(conus->tile[1]), GRITS_LEVEL_WORLD, TRUE);
562 conus->time_id = g_signal_connect_swapped(viewer, "time-changed",
563 G_CALLBACK(_conus_update), conus);
564 conus->refresh_id = g_signal_connect_swapped(viewer, "refresh",
565 G_CALLBACK(_conus_update), conus);
567 g_object_set_data(G_OBJECT(conus->config), "conus", conus);
568 gtk_notebook_append_page(GTK_NOTEBOOK(pconfig), conus->config,
569 gtk_label_new("Conus"));
571 _conus_update(conus);
575 void radar_conus_free(RadarConus *conus)
577 g_signal_handler_disconnect(conus->viewer, conus->time_id);
578 g_signal_handler_disconnect(conus->viewer, conus->refresh_id);
580 for (int i = 0; i < 2; i++) {
581 GritsTile *tile = conus->tile[i];
583 glDeleteTextures(1, tile->data);
586 grits_viewer_remove(conus->viewer, tile);
589 g_object_unref(conus->viewer);
594 /********************
596 ********************/
597 static void _draw_hud(GritsCallback *callback, GritsOpenGL *opengl, gpointer _self)
599 g_debug("GritsPluginRadar: _draw_hud");
601 glMatrixMode(GL_MODELVIEW ); glLoadIdentity();
602 glMatrixMode(GL_PROJECTION); glLoadIdentity();
603 glDisable(GL_TEXTURE_2D);
604 glDisable(GL_ALPHA_TEST);
605 glDisable(GL_CULL_FACE);
606 glDisable(GL_LIGHTING);
607 glEnable(GL_COLOR_MATERIAL);
610 gpointer name, _site;
611 GritsPluginRadar *self = GRITS_PLUGIN_RADAR(_self);
612 g_hash_table_iter_init(&iter, self->sites);
613 while (g_hash_table_iter_next(&iter, &name, &_site)) {
614 /* Pick correct colormaps */
615 RadarSite *site = _site;
616 if (site->hidden || !site->level2)
618 AWeatherColormap *colormap = site->level2->sweep_colors;
620 /* Print the color table */
622 int len = colormap->len;
623 for (int i = 0; i < len; i++) {
624 glColor4ubv(colormap->data[i]);
625 glVertex3f(-1.0, (float)((i ) - len/2)/(len/2), 0.0); // bot left
626 glVertex3f(-1.0, (float)((i+1) - len/2)/(len/2), 0.0); // top left
627 glVertex3f(-0.9, (float)((i+1) - len/2)/(len/2), 0.0); // top right
628 glVertex3f(-0.9, (float)((i ) - len/2)/(len/2), 0.0); // bot right
634 static void _load_colormap(gchar *filename, AWeatherColormap *cm)
636 g_debug("GritsPluginRadar: _load_colormap - %s", filename);
637 FILE *file = g_fopen(filename, "r");
639 g_error("GritsPluginRadar: open failed");
641 GArray *array = g_array_sized_new(FALSE, TRUE, sizeof(color), 256);
642 fgets(cm->name, sizeof(cm->name), file);
643 fscanf(file, "%f\n", &cm->scale);
644 fscanf(file, "%f\n", &cm->shift);
646 while (fscanf(file, "%d %d %d %d\n", &r, &g, &b, &a) == 4) {
651 g_array_append_val(array, color);
653 cm->len = (gint )array->len;
654 cm->data = (void*)array->data;
655 g_array_free(array, FALSE);
658 static void _update_hidden(GtkNotebook *notebook,
659 GtkNotebookPage *page, guint page_num, gpointer viewer)
661 g_debug("GritsPluginRadar: _update_hidden - 0..%d = %d",
662 gtk_notebook_get_n_pages(notebook), page_num);
664 for (gint i = 0; i < gtk_notebook_get_n_pages(notebook); i++) {
665 gboolean is_hidden = (i != page_num);
666 GtkWidget *config = gtk_notebook_get_nth_page(notebook, i);
667 RadarConus *conus = g_object_get_data(G_OBJECT(config), "conus");
668 RadarSite *site = g_object_get_data(G_OBJECT(config), "site");
672 grits_object_hide(GRITS_OBJECT(conus->tile[0]), is_hidden);
673 grits_object_hide(GRITS_OBJECT(conus->tile[1]), is_hidden);
675 site->hidden = is_hidden;
677 grits_object_hide(GRITS_OBJECT(site->level2), is_hidden);
679 g_warning("GritsPluginRadar: _update_hidden - no site or counus found");
682 gtk_widget_queue_draw(GTK_WIDGET(viewer));
686 GritsPluginRadar *grits_plugin_radar_new(GritsViewer *viewer, GritsPrefs *prefs)
688 /* TODO: move to constructor if possible */
689 g_debug("GritsPluginRadar: new");
690 GritsPluginRadar *self = g_object_new(GRITS_TYPE_PLUGIN_RADAR, NULL);
691 self->viewer = viewer;
694 /* Setup page switching */
695 self->tab_id = g_signal_connect(self->config, "switch-page",
696 G_CALLBACK(_update_hidden), viewer);
699 self->hud = grits_callback_new(_draw_hud, self);
700 grits_viewer_add(viewer, GRITS_OBJECT(self->hud), GRITS_LEVEL_HUD, FALSE);
703 self->conus = radar_conus_new(self->config, self->viewer, self->conus_http);
705 /* Load radar sites */
706 for (city_t *city = cities; city->type; city++) {
707 if (city->type != LOCATION_CITY)
709 RadarSite *site = radar_site_new(city, self->config,
710 self->viewer, self->prefs, self->sites_http);
711 g_hash_table_insert(self->sites, city->code, site);
717 static GtkWidget *grits_plugin_radar_get_config(GritsPlugin *_self)
719 GritsPluginRadar *self = GRITS_PLUGIN_RADAR(_self);
724 static void grits_plugin_radar_plugin_init(GritsPluginInterface *iface);
725 G_DEFINE_TYPE_WITH_CODE(GritsPluginRadar, grits_plugin_radar, G_TYPE_OBJECT,
726 G_IMPLEMENT_INTERFACE(GRITS_TYPE_PLUGIN,
727 grits_plugin_radar_plugin_init));
728 static void grits_plugin_radar_plugin_init(GritsPluginInterface *iface)
730 g_debug("GritsPluginRadar: plugin_init");
731 /* Add methods to the interface */
732 iface->get_config = grits_plugin_radar_get_config;
734 static void grits_plugin_radar_init(GritsPluginRadar *self)
736 g_debug("GritsPluginRadar: class_init");
738 self->sites_http = grits_http_new(G_DIR_SEPARATOR_S
739 "nexrad" G_DIR_SEPARATOR_S
740 "level2" G_DIR_SEPARATOR_S);
741 self->conus_http = grits_http_new(G_DIR_SEPARATOR_S
742 "nexrad" G_DIR_SEPARATOR_S
743 "conus" G_DIR_SEPARATOR_S);
744 self->sites = g_hash_table_new_full(g_str_hash, g_str_equal,
745 NULL, (GDestroyNotify)radar_site_free);
746 self->config = gtk_notebook_new();
749 for (int i = 0; colormaps[i].file; i++) {
750 gchar *file = g_build_filename(PKGDATADIR,
751 "colors", colormaps[i].file, NULL);
752 _load_colormap(file, &colormaps[i]);
756 /* Need to position on the top because of Win32 bug */
757 gtk_notebook_set_tab_pos(GTK_NOTEBOOK(self->config), GTK_POS_LEFT);
759 static void grits_plugin_radar_dispose(GObject *gobject)
761 g_debug("GritsPluginRadar: dispose");
762 GritsPluginRadar *self = GRITS_PLUGIN_RADAR(gobject);
763 g_signal_handler_disconnect(self->config, self->tab_id);
764 grits_viewer_remove(self->viewer, self->hud);
765 radar_conus_free(self->conus);
766 /* Drop references */
767 G_OBJECT_CLASS(grits_plugin_radar_parent_class)->dispose(gobject);
769 static void grits_plugin_radar_finalize(GObject *gobject)
771 g_debug("GritsPluginRadar: finalize");
772 GritsPluginRadar *self = GRITS_PLUGIN_RADAR(gobject);
774 grits_http_free(self->conus_http);
775 grits_http_free(self->sites_http);
776 g_hash_table_destroy(self->sites);
777 gtk_widget_destroy(self->config);
778 G_OBJECT_CLASS(grits_plugin_radar_parent_class)->finalize(gobject);
781 static void grits_plugin_radar_class_init(GritsPluginRadarClass *klass)
783 g_debug("GritsPluginRadar: class_init");
784 GObjectClass *gobject_class = (GObjectClass*)klass;
785 gobject_class->dispose = grits_plugin_radar_dispose;
786 gobject_class->finalize = grits_plugin_radar_finalize;