]> Pileus Git - aweather/blobdiff - src/plugins/radar.c
Add check when loading Conus pixbuf
[aweather] / src / plugins / radar.c
index 171267c1fe54bc0ff1b73e94a4e4bcb0955447f1..73d275985ab9a13202d3bdfcd0df950afea70e61 100644 (file)
@@ -147,7 +147,6 @@ gpointer _site_update_thread(gpointer _site)
 {
        RadarSite *site = _site;
        g_debug("GisPluginRadar: _site_update_thread - %s", site->city->code);
-       site->status = STATUS_LOADING;
        site->message = NULL;
 
        gboolean offline = gis_viewer_get_offline(site->viewer);
@@ -190,12 +189,12 @@ gpointer _site_update_thread(gpointer _site)
        g_debug("GisPluginRadar: _site_update_thread - load - %s", site->city->code);
        site->level2 = aweather_level2_new_from_file(
                        site->viewer, colormaps, file, site->city->code);
-       GIS_OBJECT(site->level2)->hidden = site->hidden;
        g_free(file);
        if (!site->level2) {
                site->message = "Load failed";
                goto out;
        }
+       GIS_OBJECT(site->level2)->hidden = site->hidden;
        site->level2_ref = gis_viewer_add(site->viewer,
                        GIS_OBJECT(site->level2), GIS_LEVEL_WORLD, TRUE);
 
@@ -205,6 +204,10 @@ out:
 }
 void _site_update(RadarSite *site)
 {
+       if (site->status == STATUS_LOADING)
+               return;
+       site->status = STATUS_LOADING;
+
        site->time = gis_viewer_get_time(site->viewer);
        g_debug("GisPluginRadar: _site_update %s - %d",
                        site->city->code, (gint)site->time);
@@ -264,7 +267,6 @@ void radar_site_toggle(RadarSite *site)
 void radar_site_load(RadarSite *site)
 {
        g_debug("GisPluginRadar: radar_site_load %s", site->city->code);
-       site->status = STATUS_LOADING;
 
        /* Add tab page */
        site->config = gtk_alignment_new(0, 0, 1, 1);
@@ -318,7 +320,8 @@ RadarSite *radar_site_new(city_t *city, GtkWidget *pconfig,
        RadarSite *site = g_new0(RadarSite, 1);
        site->viewer  = g_object_ref(viewer);
        site->prefs   = g_object_ref(prefs);
-       site->http    = http;
+       //site->http    = http;
+       site->http    = gis_http_new(G_DIR_SEPARATOR_S "nexrad" G_DIR_SEPARATOR_S "level2" G_DIR_SEPARATOR_S);
        site->city    = city;
        site->pconfig = pconfig;
 
@@ -338,6 +341,7 @@ void radar_site_free(RadarSite *site)
        gis_viewer_remove(site->viewer, site->marker_ref);
        if (site->location_id)
                g_signal_handler_disconnect(site->viewer, site->location_id);
+       gis_http_free(site->http);
        g_object_unref(site->viewer);
        g_object_unref(site->prefs);
        g_free(site);
@@ -461,12 +465,18 @@ gboolean _conus_update_end(gpointer _conus)
        /* Load and pixbuf */
        GError *error = NULL;
        GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(conus->path, &error);
-       guchar    *pixels = gdk_pixbuf_get_pixels(pixbuf);
-       gint       width  = gdk_pixbuf_get_width(pixbuf);
-       gint       height = gdk_pixbuf_get_height(pixbuf);
-       gint       pxsize = gdk_pixbuf_get_has_alpha(pixbuf) ? 4 : 3;
+       if (!pixbuf || error) {
+               g_warning("GisPluginRadar: _conus_update_end - error loading pixbuf");
+               _gtk_bin_set_child(GTK_BIN(conus->config), gtk_label_new("Error loading pixbuf"));
+               g_remove(conus->path);
+               goto out;
+       }
 
        /* Split pixels into east/west parts */
+       guchar *pixels = gdk_pixbuf_get_pixels(pixbuf);
+       gint    width  = gdk_pixbuf_get_width(pixbuf);
+       gint    height = gdk_pixbuf_get_height(pixbuf);
+       gint    pxsize = gdk_pixbuf_get_has_alpha(pixbuf) ? 4 : 3;
        guchar *pixels_west = g_malloc(4*(width/2)*height);
        guchar *pixels_east = g_malloc(4*(width/2)*height);
        _conus_update_end_split(pixels, pixels_west, pixels_east,