X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;ds=sidebyside;f=src%2Fplugins%2Fradar.c;h=1b4e2b8feed1bdd423cda82fb5006cfa376325ab;hb=61fb0b58c4801a2b904fd38a64708c8a13f98dd3;hp=52d94c92d0ed1411c67abb3bafd8a4d255863609;hpb=8addcb17f030c9d9330f125f6160eedbccddf63d;p=aweather diff --git a/src/plugins/radar.c b/src/plugins/radar.c index 52d94c9..1b4e2b8 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,7 +16,7 @@ */ #define _XOPEN_SOURCE -#include +#include #include #include #include @@ -41,7 +41,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 +50,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 +148,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) { @@ -248,6 +252,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", @@ -493,17 +499,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) {