X-Git-Url: http://pileus.org/git/?p=aweather;a=blobdiff_plain;f=src%2Fplugins%2Fradar.c;h=beeb3d0907a5c15bbe84ca0a4939f0b1f02a3f86;hp=66c8b7ed73793a5b32a4499ae449054e56db7c87;hb=b21b9cbd70f53e15760467b7c67eddc4a4f01c24;hpb=30d0024157f9db987ce11254e9448b5c8667331f diff --git a/src/plugins/radar.c b/src/plugins/radar.c index 66c8b7e..beeb3d0 100644 --- a/src/plugins/radar.c +++ b/src/plugins/radar.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2010 Andy Spencer + * Copyright (C) 2009-2011 Andy Spencer * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,12 +16,11 @@ */ #define _XOPEN_SOURCE -#include +#include #include #include #include #include -#include #include #include @@ -41,7 +40,7 @@ static void _gtk_bin_set_child(GtkBin *bin, GtkWidget *new) } static gchar *_find_nearest(time_t time, GList *files, - gsize offset, gchar *format) + gsize offset) { g_debug("RadarSite: find_nearest ..."); time_t nearest_time = 0; @@ -50,7 +49,11 @@ static gchar *_find_nearest(time_t time, GList *files, struct tm tm = {}; for (GList *cur = files; cur; cur = cur->next) { gchar *file = cur->data; - strptime(file+offset, format, &tm); + sscanf(file+offset, "%4d%2d%2d_%2d%2d", + &tm.tm_year, &tm.tm_mon, &tm.tm_mday, + &tm.tm_hour, &tm.tm_min); + tm.tm_year -= 1900; + tm.tm_mon -= 1; if (ABS(time - mktime(&tm)) < ABS(time - nearest_time)) { nearest_file = file; @@ -144,7 +147,7 @@ gpointer _site_update_thread(gpointer _site) "^\\w{4}_\\d{8}_\\d{4}$", site->city->code, "\\d+ (.*)", (offline ? NULL : dir_list)); g_free(dir_list); - gchar *nearest = _find_nearest(site->time, files, 5, "%Y%m%d_%H%M"); + gchar *nearest = _find_nearest(site->time, files, 5); g_list_foreach(files, (GFunc)g_free, NULL); g_list_free(files); if (!nearest) { @@ -179,7 +182,7 @@ gpointer _site_update_thread(gpointer _site) } grits_object_hide(GRITS_OBJECT(site->level2), site->hidden); grits_viewer_add(site->viewer, GRITS_OBJECT(site->level2), - GRITS_LEVEL_WORLD, TRUE); + GRITS_LEVEL_WORLD+1, TRUE); out: g_idle_add(_site_update_end, site); @@ -248,6 +251,8 @@ void radar_site_load(RadarSite *site) gtk_notebook_append_page(GTK_NOTEBOOK(site->pconfig), site->config, gtk_label_new(site->city->name)); gtk_widget_show_all(site->config); + if (gtk_notebook_get_current_page(GTK_NOTEBOOK(site->pconfig)) == 0) + gtk_notebook_set_current_page(GTK_NOTEBOOK(site->pconfig), -1); /* Set up radar loading */ site->time_id = g_signal_connect_swapped(site->viewer, "time-changed", @@ -300,6 +305,7 @@ RadarSite *radar_site_new(city_t *city, GtkWidget *pconfig, "level2" G_DIR_SEPARATOR_S); site->city = city; site->pconfig = pconfig; + site->hidden = TRUE; /* Set initial location */ gdouble lat, lon, elev; @@ -373,13 +379,14 @@ static void _conus_update_end_copy(GritsTile *tile, guchar *pixels) glGenTextures(1, tile->data); } + gchar *clear = g_malloc0(2048*2048*4); guint *tex = tile->data; glBindTexture(GL_TEXTURE_2D, *tex); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glPixelStorei(GL_PACK_ALIGNMENT, 1); glTexImage2D(GL_TEXTURE_2D, 0, 4, 2048, 2048, 0, - GL_RGBA, GL_UNSIGNED_BYTE, NULL); + GL_RGBA, GL_UNSIGNED_BYTE, clear); glTexSubImage2D(GL_TEXTURE_2D, 0, 1,1, CONUS_WIDTH/2,CONUS_HEIGHT, GL_RGBA, GL_UNSIGNED_BYTE, pixels); tile->coords.n = 1.0/(CONUS_WIDTH/2); @@ -391,6 +398,7 @@ static void _conus_update_end_copy(GritsTile *tile, guchar *pixels) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glFlush(); + g_free(clear); } /* Split the pixbuf into east and west halves (with 2K sides) @@ -493,17 +501,18 @@ gpointer _conus_update_thread(gpointer _conus) 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 */ - struct tm tm; - gmtime_r(&conus->time, &tm); - time_t onthe8 = conus->time - 60*((tm.tm_min+1)%10+1); - gmtime_r(&onthe8, &tm); + /* 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); + 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, "%Y%m%d_%H%M"); + nearest = _find_nearest(conus->time, files, 6); g_list_foreach(files, (GFunc)g_free, NULL); g_list_free(files); if (!nearest) {