+ /* Copy pixels to graphics memory */
+ _conus_update_end_copy(conus->tile[0], pixels_west);
+ _conus_update_end_copy(conus->tile[1], pixels_east);
+ g_free(pixels_west);
+ g_free(pixels_east);
+
+ /* Update GUI */
+ gchar *label = g_path_get_basename(conus->path);
+ aweather_bin_set_child(GTK_BIN(conus->config), gtk_label_new(label));
+ grits_viewer_queue_draw(conus->viewer);
+ g_free(label);
+
+out:
+ conus->idle_source = 0;
+ g_free(conus->path);
+ g_mutex_unlock(&conus->loading);
+ return FALSE;
+}
+
+gpointer _conus_update_thread(gpointer _conus)
+{
+ RadarConus *conus = _conus;
+ conus->message = NULL;
+
+ /* Find nearest */
+ g_debug("Conus: update_thread - nearest");
+ gboolean offline = grits_viewer_get_offline(conus->viewer);
+ gchar *conus_url = "http://radar.weather.gov/Conus/RadarImg/";
+ gchar *nearest;
+ if (time(NULL) - conus->time < 60*60*5 && !offline) {
+ /* radar.weather.gov is full of lies.
+ * the index pages get cached and out of date */
+ /* gmtime is not thread safe, but it's not used very often so
+ * hopefully it'll be alright for now... :-( */
+ struct tm *tm = gmtime(&conus->time);
+ time_t onthe8 = conus->time - 60*((tm->tm_min+1)%10+1);
+ tm = gmtime(&onthe8);
+ nearest = g_strdup_printf("Conus_%04d%02d%02d_%02d%02d_N0Ronly.gif",
+ tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday,
+ tm->tm_hour, tm->tm_min);
+ } else {
+ GList *files = grits_http_available(conus->http,
+ "^Conus_[^\"]*_N0Ronly.gif$", "", NULL, NULL);
+ nearest = _find_nearest(conus->time, files, 6);
+ g_list_foreach(files, (GFunc)g_free, NULL);
+ g_list_free(files);
+ if (!nearest) {
+ conus->message = "No suitable files";
+ goto out;
+ }
+ }
+
+ /* Fetch the image */
+ g_debug("Conus: update_thread - fetch");
+ gchar *uri = g_strconcat(conus_url, nearest, NULL);
+ conus->path = grits_http_fetch(conus->http, uri, nearest,
+ offline ? GRITS_LOCAL : GRITS_ONCE,
+ _conus_update_loading, conus);
+ g_free(nearest);
+ g_free(uri);
+ if (!conus->path) {
+ conus->message = "Fetch failed";
+ goto out;
+ }
+