- char *list_uri = g_strdup_printf(
- "http://mesonet.agron.iastate.edu/data/nexrd2/raw/K%s/dir.list",
- site);
- GFile *list = g_file_new_for_uri(list_uri);
- g_free(list_uri);
-
- gchar *data;
- gsize length;
- GError *error = NULL;
- g_file_load_contents(list, NULL, &data, &length, NULL, &error);
- g_object_unref(list);
- if (error) {
- g_warning("Error loading list for %s: %s", site, error->message);
- g_error_free(error);
- return;
+ GList *times = NULL;
+ if (aweather_view_get_offline(view)) {
+ gchar *path = g_build_filename(g_get_user_cache_dir(), PACKAGE, "nexrd2", "raw", site, NULL);
+ GDir *dir = g_dir_open(path, 0, NULL);
+ if (dir) {
+ const gchar *name;
+ while ((name = g_dir_read_name(dir))) {
+ times = g_list_prepend(times, g_strdup(name));
+ }
+ g_dir_close(dir);
+ }
+ g_free(path);
+ } else {
+ gchar *data;
+ gsize length;
+ GError *error = NULL;
+
+ char *list_uri = g_strdup_printf("http://mesonet.agron.iastate.edu/data/nexrd2/raw/%s/dir.list", site);
+ GFile *list = g_file_new_for_uri(list_uri);
+ g_file_load_contents(list, NULL, &data, &length, NULL, &error);
+ if (error) {
+ g_warning("Error loading list for %s: %s", site, error->message);
+ g_error_free(error);
+ } else {
+ gchar **lines = g_strsplit(data, "\n", -1);
+ for (int i = 0; lines[i] && lines[i][0]; i++) {
+ char **parts = g_strsplit(lines[i], " ", 2);
+ times = g_list_prepend(times, parts[1]);
+ g_strfreev(parts);
+ }
+ g_strfreev(lines);
+ g_free(data);
+ }
+
+ g_free(list_uri);
+ g_object_unref(list);