]> Pileus Git - aweather/blob - src/plugins/radar.c
Add Conus tile to radar plugin
[aweather] / src / plugins / radar.c
1 /*
2  * Copyright (C) 2009-2010 Andy Spencer <andy753421@gmail.com>
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 #define _XOPEN_SOURCE
19 #include <time.h>
20 #include <config.h>
21 #include <glib/gstdio.h>
22 #include <gtk/gtk.h>
23 #include <gtk/gtkgl.h>
24 #include <gio/gio.h>
25 #include <GL/gl.h>
26 #include <math.h>
27 #include <rsl.h>
28
29 #include <gis.h>
30
31 #include "radar.h"
32 #include "level2.h"
33 #include "../aweather-location.h"
34
35 void _gtk_bin_set_child(GtkBin *bin, GtkWidget *new)
36 {
37         GtkWidget *old = gtk_bin_get_child(bin);
38         if (old)
39                 gtk_widget_destroy(old);
40         gtk_container_add(GTK_CONTAINER(bin), new);
41         gtk_widget_show_all(new);
42 }
43
44 static gchar *_find_nearest(time_t time, GList *files,
45                 gsize offset, gchar *format)
46 {
47         g_debug("GisPluginRadar: _find_nearest");
48         time_t  nearest_time = 0;
49         char   *nearest_file = NULL;
50
51         struct tm tm = {};
52         for (GList *cur = files; cur; cur = cur->next) {
53                 gchar *file = cur->data;
54                 g_message("file=%s", file);
55                 strptime(file+offset, format, &tm);
56                 if (ABS(time - mktime(&tm)) <
57                     ABS(time - nearest_time)) {
58                         nearest_file = file;
59                         nearest_time = mktime(&tm);
60                 }
61         }
62
63         g_debug("GisPluginRadar: _find_nearest = %s", nearest_file);
64         if (nearest_file)
65                 return g_strdup(nearest_file);
66         else
67                 return NULL;
68 }
69
70
71 /**************
72  * RadarSites *
73  **************/
74 typedef enum {
75         STATUS_UNLOADED,
76         STATUS_LOADING,
77         STATUS_LOADED,
78 } RadarSiteStatus;
79 struct _RadarSite {
80         /* Information */
81         gchar     *code;   // Site name. e.g. KLSX
82         gchar     *name;   // Site name. e.g. St. Louis
83         GisPoint   pos;    // LLE positions of antena 
84         GisMarker *marker; // Map marker for libgis
85
86         /* Stuff from the parents */
87         GisViewer     *viewer;
88         GisHttp       *http;
89         GisPrefs      *prefs;
90         GtkWidget     *pconfig;
91
92         /* When loaded */
93         RadarSiteStatus status;     // Loading status for the site
94         GtkWidget      *config;
95         AWeatherLevel2 *level2;     // The Level2 structure for the current volume
96         gpointer        level2_ref; // GisViewer reference to the added radar
97
98         /* Internal data */
99         time_t   time;        // Current timestamp of the level2
100         gchar   *message;     // Error message set while updating
101         guint    time_id;     // "time-changed"     callback ID
102         guint    refresh_id;  // "refresh"          callback ID
103         guint    location_id; // "locaiton-changed" callback ID
104 };
105
106 /* format: http://mesonet.agron.iastate.edu/data/nexrd2/raw/KABR/KABR_20090510_0323 */
107 void _site_update_loading(gchar *file, goffset cur,
108                 goffset total, gpointer _site)
109 {
110         RadarSite *site = _site;
111         GtkWidget *progress_bar = gtk_bin_get_child(GTK_BIN(site->config));
112         double percent = (double)cur/total;
113         gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress_bar), MIN(percent, 1.0));
114         gchar *msg = g_strdup_printf("Loading... %5.1f%% (%.2f/%.2f MB)",
115                         percent*100, (double)cur/1000000, (double)total/1000000);
116         gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progress_bar), msg);
117         g_free(msg);
118 }
119 gboolean _site_update_end(gpointer _site)
120 {
121         RadarSite *site = _site;
122         if (site->message) {
123                 g_warning("GisPluginRadar: _update_end - %s", site->message);
124                 _gtk_bin_set_child(GTK_BIN(site->config), gtk_label_new(site->message));
125         } else {
126                 _gtk_bin_set_child(GTK_BIN(site->config),
127                                 aweather_level2_get_config(site->level2));
128         }
129         site->status = STATUS_LOADED;
130         return FALSE;
131 }
132 gpointer _site_update_thread(gpointer _site)
133 {
134         RadarSite *site = _site;
135         g_debug("GisPluginRadar: _update - %s", site->code);
136         site->status = STATUS_LOADING;
137         site->message = NULL;
138
139         gboolean offline = gis_viewer_get_offline(site->viewer);
140         gchar *nexrad_url = gis_prefs_get_string(site->prefs,
141                         "aweather/nexrad_url", NULL);
142
143         /* Remove old volume */
144         g_debug("GisPluginRadar: _update - remove - %s", site->code);
145         if (site->level2_ref) {
146                 gis_viewer_remove(site->viewer, site->level2_ref);
147                 site->level2_ref = NULL;
148         }
149
150         /* Find nearest volume (temporally) */
151         g_debug("GisPluginRadar: _update - find nearest - %s", site->code);
152         gchar *dir_list = g_strconcat(nexrad_url, "/", site->code,
153                         "/", "dir.list", NULL);
154         GList *files = gis_http_available(site->http,
155                         "^K\\w{3}_\\d{8}_\\d{4}$", site->code,
156                         "\\d+ (.*)", (offline ? NULL : dir_list));
157         g_free(dir_list);
158         gchar *nearest = _find_nearest(site->time, files, 5, "%Y%m%d_%H%M");
159         g_list_foreach(files, (GFunc)g_free, NULL);
160         g_list_free(files);
161         if (!nearest) {
162                 site->message = "No suitable files found";
163                 goto out;
164         }
165
166         /* Fetch new volume */
167         g_debug("GisPluginRadar: _update - fetch");
168         gchar *local = g_strconcat(site->code, "/", nearest, NULL);
169         gchar *uri   = g_strconcat(nexrad_url, "/", local,   NULL);
170         gchar *file = gis_http_fetch(site->http, uri, local,
171                         offline ? GIS_LOCAL : GIS_UPDATE,
172                         _site_update_loading, site);
173         g_free(local);
174         g_free(uri);
175         if (!file) {
176                 site->message = "Fetch failed";
177                 goto out;
178         }
179
180         /* Load and add new volume */
181         g_debug("GisPluginRadar: _update - load - %s", site->code);
182         site->level2 = aweather_level2_new_from_file(
183                         site->viewer, colormaps, file, site->code);
184         if (!site->level2) {
185                 site->message = "Load failed";
186                 goto out;
187         }
188         site->level2_ref = gis_viewer_add(site->viewer,
189                         GIS_OBJECT(site->level2), GIS_LEVEL_WORLD, TRUE);
190
191 out:
192         g_idle_add(_site_update_end, site);
193         return NULL;
194 }
195 void _site_update(RadarSite *site)
196 {
197         site->time = gis_viewer_get_time(site->viewer);
198         g_debug("GisPluginRadar: _on_time_changed %s - %d",
199                         site->code, (gint)site->time);
200
201         /* Add a progress bar */
202         GtkWidget *progress = gtk_progress_bar_new();
203         gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progress), "Loading...");
204         _gtk_bin_set_child(GTK_BIN(site->config), progress);
205
206         /* Fork loading right away so updating the
207          * list of times doesn't take too long */
208         g_thread_create(_site_update_thread, site, FALSE, NULL);
209 }
210
211 /* RadarSite methods */
212 void radar_site_unload(RadarSite *site)
213 {
214         g_debug("GisPluginRadar: radar_site_unload %s", site->code);
215
216         if (site->status == STATUS_LOADING)
217                 return; // Abort if it's still loading
218
219         g_signal_handler_disconnect(site->viewer, site->time_id);
220         g_signal_handler_disconnect(site->viewer, site->refresh_id);
221
222         /* Remove tab */
223         gtk_widget_destroy(site->config);
224
225         /* Remove radar */
226         if (site->level2_ref) {
227                 gis_viewer_remove(site->viewer, site->level2_ref);
228                 site->level2_ref = NULL;
229         }
230
231         site->status = STATUS_UNLOADED;
232 }
233
234 void radar_site_load(RadarSite *site)
235 {
236         g_debug("GisPluginRadar: radar_site_load %s", site->code);
237         site->status = STATUS_LOADING;
238
239         /* Add tab page */
240         site->config = gtk_alignment_new(0, 0, 1, 1);
241         GtkWidget *tab   = gtk_hbox_new(FALSE, 0);
242         GtkWidget *close = gtk_button_new();
243         GtkWidget *label = gtk_label_new(site->name);
244         gtk_container_add(GTK_CONTAINER(close),
245                         gtk_image_new_from_stock(GTK_STOCK_CLOSE,
246                                 GTK_ICON_SIZE_MENU));
247         gtk_button_set_relief(GTK_BUTTON(close), GTK_RELIEF_NONE);
248         g_signal_connect_swapped(close, "clicked",
249                         G_CALLBACK(radar_site_unload), site);
250         gtk_box_pack_start(GTK_BOX(tab), label, TRUE, TRUE, 0);
251         gtk_box_pack_end(GTK_BOX(tab), close, FALSE, FALSE, 0);
252         gtk_notebook_append_page(GTK_NOTEBOOK(site->pconfig),
253                         site->config, tab);
254         gtk_widget_show_all(site->config);
255         gtk_widget_show_all(tab);
256
257         /* Set up radar loading */
258         site->time_id = g_signal_connect_swapped(site->viewer, "time-changed",
259                         G_CALLBACK(_site_update), site);
260         site->refresh_id = g_signal_connect_swapped(site->viewer, "refresh",
261                         G_CALLBACK(_site_update), site);
262         _site_update(site);
263 }
264
265 void _site_on_location_changed(GisViewer *viewer,
266                 gdouble lat, gdouble lon, gdouble elev,
267                 gpointer _site)
268 {
269         static gdouble min_dist = EARTH_R / 20;
270         RadarSite *site = _site;
271
272         /* Calculate distance, could cache xyz values */
273         gdouble eye_xyz[3], site_xyz[3];
274         lle2xyz(lat, lon, elev, &eye_xyz[0], &eye_xyz[1], &eye_xyz[2]);
275         lle2xyz(site->pos.lat, site->pos.lon, site->pos.elev,
276                         &site_xyz[0], &site_xyz[1], &site_xyz[2]);
277         gdouble dist = distd(site_xyz, eye_xyz);
278
279         /* Load or unload the site if necessasairy */
280         if (dist <= min_dist && dist < elev*1.25 && site->status == STATUS_UNLOADED)
281                 radar_site_load(site);
282         else if (dist > 2*min_dist &&  site->status != STATUS_UNLOADED)
283                 radar_site_unload(site);
284 }
285
286 RadarSite *radar_site_new(city_t *city, GtkWidget *pconfig,
287                 GisViewer *viewer, GisPrefs *prefs, GisHttp *http)
288 {
289         RadarSite *site = g_new0(RadarSite, 1);
290         site->viewer  = g_object_ref(viewer);
291         site->prefs   = g_object_ref(prefs);
292         site->http    = http;
293         site->code    = g_strdup(city->code);
294         site->name    = g_strdup(city->name);
295         site->pos     = city->pos;
296         site->pconfig = pconfig;
297
298         /* Add marker */
299         site->marker = gis_marker_new(city->name);
300         GIS_OBJECT(site->marker)->center = site->pos;
301         GIS_OBJECT(site->marker)->lod    = EARTH_R*city->lod;
302         gis_viewer_add(site->viewer, GIS_OBJECT(site->marker),
303                         GIS_LEVEL_OVERLAY, FALSE);
304
305         /* Connect signals */
306         site->location_id  =
307                 g_signal_connect(viewer, "location-changed",
308                         G_CALLBACK(_site_on_location_changed), site);
309         return site;
310 }
311
312 void radar_site_free(RadarSite *site)
313 {
314         radar_site_unload(site);
315         /* Stuff? */
316         g_object_unref(site->viewer);
317         g_free(site->code);
318         g_free(site);
319 }
320
321
322 /**************
323  * RadarConus *
324  **************/
325 struct _RadarConus {
326         GisViewer  *viewer;
327         GisTile    *tile;
328         GisHttp    *http;
329         GtkWidget  *config;
330         time_t      time;
331         GdkPixbuf  *pixbuf;
332         gchar      *message;
333         gchar      *nearest;
334 };
335
336 void _conus_update_loading(gchar *file, goffset cur,
337                 goffset total, gpointer _conus)
338 {
339         RadarConus *conus = _conus;
340         GtkWidget *progress_bar = gtk_bin_get_child(GTK_BIN(conus->config));
341         double percent = (double)cur/total;
342         gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress_bar), MIN(percent, 1.0));
343         gchar *msg = g_strdup_printf("Loading... %5.1f%% (%.2f/%.2f MB)",
344                         percent*100, (double)cur/1000000, (double)total/1000000);
345         gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progress_bar), msg);
346         g_free(msg);
347 }
348
349 gboolean _conus_update_end(gpointer _conus)
350 {
351         RadarConus *conus = _conus;
352
353         guchar    *pixels = gdk_pixbuf_get_pixels(conus->pixbuf);
354         gboolean   alpha  = gdk_pixbuf_get_has_alpha(conus->pixbuf);
355         gint       width  = gdk_pixbuf_get_width(conus->pixbuf);
356         gint       height = gdk_pixbuf_get_height(conus->pixbuf);
357
358         if (!conus->tile->data) {
359                 conus->tile->data = g_new0(guint, 1);
360                 glGenTextures(1, conus->tile->data);
361         }
362
363         guint *tex = conus->tile->data;
364         glBindTexture(GL_TEXTURE_2D, *tex);
365
366         glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
367         glPixelStorei(GL_PACK_ALIGNMENT, 1);
368         glTexImage2D(GL_TEXTURE_2D, 0, 4, width, height, 0,
369                         (alpha ? GL_RGBA : GL_RGB), GL_UNSIGNED_BYTE, pixels);
370         glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
371         glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
372         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
373         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
374         glFlush();
375
376         /* finish */
377         _gtk_bin_set_child(GTK_BIN(conus->config),
378                         gtk_label_new(conus->nearest));
379         gtk_widget_queue_draw(GTK_WIDGET(conus->viewer));
380         g_object_unref(conus->pixbuf);
381
382         return FALSE;
383 }
384
385 gpointer _conus_update_thread(gpointer _conus)
386 {
387         RadarConus *conus = _conus;
388
389         /* Find nearest */
390         gboolean offline = gis_viewer_get_offline(conus->viewer);
391         gchar *conus_url = "http://radar.weather.gov/Conus/RadarImg/";
392         GList *files = gis_http_available(conus->http,
393                         "^Conus_[^\"]*_N0Ronly.gif$", "",
394                         NULL, (offline ? NULL : conus_url));
395         conus->nearest = _find_nearest(conus->time, files, 6, "%Y%m%d_%H%M");
396         g_list_foreach(files, (GFunc)g_free, NULL);
397         g_list_free(files);
398         if (!conus->nearest) {
399                 conus->message = "No suitable files";
400                 goto out;
401         }
402
403         /* Fetch the image */
404         gchar *uri     = g_strconcat(conus_url, conus->nearest, NULL);
405         gchar *path    = gis_http_fetch(conus->http, uri, conus->nearest, GIS_ONCE,
406                         _conus_update_loading, conus);
407         if (!path) {
408                 conus->message = "Fetch failed";
409                 goto out;
410         }
411
412         /* Load the image to a pixbuf */
413         GError *error = NULL;
414         conus->pixbuf = gdk_pixbuf_new_from_file(path, &error);
415         if (!gdk_pixbuf_get_has_alpha(conus->pixbuf)) {
416                 GdkPixbuf *tmp = gdk_pixbuf_add_alpha(conus->pixbuf, TRUE, 0xff, 0xff, 0xff);
417                 g_object_unref(conus->pixbuf);
418                 conus->pixbuf = tmp;
419         }
420
421         /* Map the pixbuf's alpha values */
422         const guchar colormap[][2][4] = {
423                 {{0x04, 0xe9, 0xe7}, {0x04, 0xe9, 0xe7, 0x30}},
424                 {{0x01, 0x9f, 0xf4}, {0x01, 0x9f, 0xf4, 0x60}},
425                 {{0x03, 0x00, 0xf4}, {0x03, 0x00, 0xf4, 0x90}},
426         };
427         guchar *pixels = gdk_pixbuf_get_pixels(conus->pixbuf);
428         gint    height = gdk_pixbuf_get_height(conus->pixbuf);
429         gint    width  = gdk_pixbuf_get_width(conus->pixbuf);
430         for (int i = 0; i < width*height; i++) {
431                 for (int j = 0; j < G_N_ELEMENTS(colormap); j++) {
432                         if (pixels[i*4+0] > 0xe0 &&
433                             pixels[i*4+1] > 0xe0 &&
434                             pixels[i*4+2] > 0xe0) {
435                                 pixels[i*4+3] = 0x00;
436                                 break;
437                         }
438                         if (pixels[i*4+0] == colormap[j][0][0] &&
439                             pixels[i*4+1] == colormap[j][0][1] &&
440                             pixels[i*4+2] == colormap[j][0][2]) {
441                                 pixels[i*4+0] = colormap[j][1][0];
442                                 pixels[i*4+1] = colormap[j][1][1];
443                                 pixels[i*4+2] = colormap[j][1][2];
444                                 pixels[i*4+3] = colormap[j][1][3];
445                                 break;
446                         }
447                 }
448         }
449
450 out:
451         g_idle_add(_conus_update_end, conus);
452         return NULL;
453 }
454
455 void _conus_update(RadarConus *conus)
456 {
457         conus->time = gis_viewer_get_time(conus->viewer);
458         g_debug("GisPluginRadar: _conus_update - %d",
459                         (gint)conus->time);
460
461         /* Add a progress bar */
462         GtkWidget *progress = gtk_progress_bar_new();
463         gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progress), "Loading...");
464         _gtk_bin_set_child(GTK_BIN(conus->config), progress);
465
466         g_thread_create(_conus_update_thread, conus, FALSE, NULL);
467 }
468
469 RadarConus *radar_conus_new(GtkWidget *pconfig,
470                 GisViewer *viewer, GisHttp *http)
471 {
472         RadarConus *conus = g_new0(RadarConus, 1);
473         conus->viewer  = g_object_ref(viewer);
474         conus->http    = http;
475         conus->config  = gtk_alignment_new(0, 0, 1, 1);
476         conus->tile    = gis_tile_new(NULL,
477                         50.406626367301044,   50.406626367301044-0.017971305190311*1600,
478                         -127.620375523875420+0.017971305190311*3400, -127.620375523875420);
479         conus->tile->zindex = 1;
480         g_signal_connect_swapped(viewer, "time-changed", G_CALLBACK(_conus_update), conus);
481         g_signal_connect_swapped(viewer, "refresh",      G_CALLBACK(_conus_update), conus);
482         gis_viewer_add(viewer, GIS_OBJECT(conus->tile), GIS_LEVEL_WORLD, TRUE);
483         gtk_notebook_append_page(GTK_NOTEBOOK(pconfig), conus->config, gtk_label_new("Conus"));
484         _conus_update(conus);
485         return conus;
486 }
487
488 void radar_conus_free(RadarConus *conus)
489 {
490         g_object_unref(conus->viewer);
491         g_free(conus);
492 }
493
494
495 /******************
496  * GisPluginRadar *
497  ******************/
498 static void _draw_hud(GisCallback *callback, gpointer _self)
499 {
500         /* TODO */
501         GisPluginRadar *self = GIS_PLUGIN_RADAR(_self);
502         if (!self->colormap)
503                 return;
504
505         g_debug("GisPluginRadar: _draw_hud");
506         /* Print the color table */
507         glMatrixMode(GL_MODELVIEW ); glLoadIdentity();
508         glMatrixMode(GL_PROJECTION); glLoadIdentity();
509         glDisable(GL_TEXTURE_2D);
510         glDisable(GL_ALPHA_TEST);
511         glDisable(GL_CULL_FACE);
512         glDisable(GL_LIGHTING);
513         glEnable(GL_COLOR_MATERIAL);
514         glBegin(GL_QUADS);
515         int i;
516         for (i = 0; i < 256; i++) {
517                 glColor4ubv(self->colormap->data[i]);
518                 glVertex3f(-1.0, (float)((i  ) - 256/2)/(256/2), 0.0); // bot left
519                 glVertex3f(-1.0, (float)((i+1) - 256/2)/(256/2), 0.0); // top left
520                 glVertex3f(-0.9, (float)((i+1) - 256/2)/(256/2), 0.0); // top right
521                 glVertex3f(-0.9, (float)((i  ) - 256/2)/(256/2), 0.0); // bot right
522         }
523         glEnd();
524 }
525
526 /* Methods */
527 GisPluginRadar *gis_plugin_radar_new(GisViewer *viewer, GisPrefs *prefs)
528 {
529         /* TODO: move to constructor if possible */
530         g_debug("GisPluginRadar: new");
531         GisPluginRadar *self = g_object_new(GIS_TYPE_PLUGIN_RADAR, NULL);
532         self->viewer = viewer;
533         self->prefs  = prefs;
534
535         /* Load HUD */
536         GisCallback *hud_cb = gis_callback_new(_draw_hud, self);
537         gis_viewer_add(viewer, GIS_OBJECT(hud_cb), GIS_LEVEL_HUD, FALSE);
538
539         /* Load Conus */
540         self->conus = radar_conus_new(self->config, self->viewer, self->conus_http);
541
542         /* Load radar sites */
543         for (city_t *city = cities; city->type; city++) {
544                 if (city->type != LOCATION_CITY)
545                         continue;
546                 RadarSite *site = radar_site_new(city, self->config,
547                                 self->viewer, self->prefs, self->sites_http);
548                 g_hash_table_insert(self->sites, city->code, site);
549         }
550
551         return self;
552 }
553
554 static GtkWidget *gis_plugin_radar_get_config(GisPlugin *_self)
555 {
556         GisPluginRadar *self = GIS_PLUGIN_RADAR(_self);
557         return self->config;
558 }
559
560 /* GObject code */
561 static void gis_plugin_radar_plugin_init(GisPluginInterface *iface);
562 G_DEFINE_TYPE_WITH_CODE(GisPluginRadar, gis_plugin_radar, G_TYPE_OBJECT,
563                 G_IMPLEMENT_INTERFACE(GIS_TYPE_PLUGIN,
564                         gis_plugin_radar_plugin_init));
565 static void gis_plugin_radar_plugin_init(GisPluginInterface *iface)
566 {
567         g_debug("GisPluginRadar: plugin_init");
568         /* Add methods to the interface */
569         iface->get_config = gis_plugin_radar_get_config;
570 }
571 static void gis_plugin_radar_init(GisPluginRadar *self)
572 {
573         g_debug("GisPluginRadar: class_init");
574         /* Set defaults */
575         self->sites_http = gis_http_new(G_DIR_SEPARATOR_S "nexrad" G_DIR_SEPARATOR_S "level2" G_DIR_SEPARATOR_S);
576         self->conus_http = gis_http_new(G_DIR_SEPARATOR_S "nexrad" G_DIR_SEPARATOR_S "conus" G_DIR_SEPARATOR_S);
577         self->sites      = g_hash_table_new(g_str_hash, g_str_equal);
578         self->config     = gtk_notebook_new();
579         gtk_notebook_set_tab_pos(GTK_NOTEBOOK(self->config), GTK_POS_LEFT);
580 }
581 static void gis_plugin_radar_dispose(GObject *gobject)
582 {
583         g_debug("GisPluginRadar: dispose");
584         GisPluginRadar *self = GIS_PLUGIN_RADAR(gobject);
585         /* Drop references */
586         G_OBJECT_CLASS(gis_plugin_radar_parent_class)->dispose(gobject);
587 }
588 static void gis_plugin_radar_finalize(GObject *gobject)
589 {
590         g_debug("GisPluginRadar: finalize");
591         GisPluginRadar *self = GIS_PLUGIN_RADAR(gobject);
592         /* Free data */
593         gis_http_free(self->conus_http);
594         gis_http_free(self->sites_http);
595         g_hash_table_destroy(self->sites);
596         gtk_widget_destroy(self->config);
597         G_OBJECT_CLASS(gis_plugin_radar_parent_class)->finalize(gobject);
598
599 }
600 static void gis_plugin_radar_class_init(GisPluginRadarClass *klass)
601 {
602         g_debug("GisPluginRadar: class_init");
603         GObjectClass *gobject_class = (GObjectClass*)klass;
604         gobject_class->dispose  = gis_plugin_radar_dispose;
605         gobject_class->finalize = gis_plugin_radar_finalize;
606 }
607