From 99863849923de021148ebf371aaeab427ae139e1 Mon Sep 17 00:00:00 2001 From: Andy Spencer Date: Sun, 10 May 2009 13:39:50 +0000 Subject: [PATCH] minor fixes --- src/Makefile.am | 8 +++++-- src/aweather-gui.c | 48 +++++++++++++++++++++++++++++++++++++++ src/data.c | 56 +++++++++++++++++++++++++++++----------------- src/plugin-radar.c | 14 +++++------- 4 files changed, 95 insertions(+), 31 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 4632471..a206864 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,5 +1,5 @@ AM_CPPFLAGS = -DDATADIR="\"$(datadir)\"" $(RSL_CFLAGS) $(GTK_CFLAGS) $(CURL_CFLAGS) -AM_CFLAGS = -O3 -Wall -Werror -Wno-unused --std=gnu99 +AM_CFLAGS = -Wall -Werror -Wno-unused --std=gnu99 AM_LDFLAGS = -Wl,--export-dynamic bin_PROGRAMS = aweather wsr88ddec @@ -21,6 +21,10 @@ test: all LD_LIBRARY_PATH=/usr/local/trmm/GVBOX/lib/ \ ./aweather -debug: all +gdb: all LD_LIBRARY_PATH=/usr/local/trmm/GVBOX/lib/ \ gdb ./aweather + +ddd: all + LD_LIBRARY_PATH=/usr/local/trmm/GVBOX/lib/ \ + ddd ./aweather diff --git a/src/aweather-gui.c b/src/aweather-gui.c index 83d9a3f..1030492 100644 --- a/src/aweather-gui.c +++ b/src/aweather-gui.c @@ -109,6 +109,50 @@ static gboolean expose_end(GtkWidget *da, GdkEventExpose *event, AWeatherGui *gu return FALSE; } +/* TODO: replace the code in these with `gtk_tree_model_find' utility */ +static void update_time_widget(AWeatherView *view, char *time, AWeatherGui *gui) +{ + g_message("updating time widget"); + GtkTreeView *tview = GTK_TREE_VIEW(aweather_gui_get_widget(gui, "time")); + GtkTreeModel *model = GTK_TREE_MODEL(gtk_tree_view_get_model(tview)); + for (int i = 0; i < gtk_tree_model_iter_n_children(model, NULL); i++) { + char *text; + GtkTreeIter iter; + gtk_tree_model_iter_nth_child(model, &iter, NULL, i); + gtk_tree_model_get(model, &iter, 0, &text, -1); + if (g_str_equal(text, time)) { + GtkTreePath *path = gtk_tree_model_get_path(model, &iter); + g_signal_handlers_block_by_func(tview, G_CALLBACK(on_site_changed), gui); + gtk_tree_view_set_cursor(tview, path, NULL, FALSE); + g_signal_handlers_unblock_by_func(tview, G_CALLBACK(on_site_changed), gui); + return; + } + } +} +static void update_location_widget(AWeatherView *view, char *location, AWeatherGui *gui) +{ + g_message("updating location widget to %s", location); + GtkComboBox *combo = GTK_COMBO_BOX(aweather_gui_get_widget(gui, "site")); + GtkTreeModel *model = GTK_TREE_MODEL(gtk_combo_box_get_model(combo)); + for (int i = 0; i < gtk_tree_model_iter_n_children(model, NULL); i++) { + GtkTreeIter iter1; + gtk_tree_model_iter_nth_child(model, &iter1, NULL, i); + for (int i = 0; i < gtk_tree_model_iter_n_children(model, &iter1); i++) { + GtkTreeIter iter2; + gtk_tree_model_iter_nth_child(model, &iter2, &iter1, i); + char *text; + gtk_tree_model_get(model, &iter2, 1, &text, -1); + if (g_str_equal(text, location)) { + GtkTreePath *path = gtk_tree_model_get_path(model, &iter2); + g_signal_handlers_block_by_func(combo, G_CALLBACK(on_site_changed), gui); + gtk_combo_box_set_active_iter(combo, &iter2); + g_signal_handlers_unblock_by_func(combo, G_CALLBACK(on_site_changed), gui); + return; + } + } + } +} + /***************** * Setup helpers * *****************/ @@ -144,6 +188,8 @@ static void site_setup(AWeatherGui *gui) combo_sensitive, NULL, NULL); g_signal_connect(combo, "changed", G_CALLBACK(on_site_changed), gui); + AWeatherView *aview = aweather_gui_get_view(gui); + g_signal_connect(aview, "location-changed", G_CALLBACK(update_location_widget), gui); } static void time_setup(AWeatherGui *gui) @@ -158,6 +204,8 @@ static void time_setup(AWeatherGui *gui) gtk_tree_view_append_column(tview, col); g_signal_connect(tview, "row-activated", G_CALLBACK(on_time_changed), gui); + AWeatherView *aview = aweather_gui_get_view(gui); + g_signal_connect(aview, "time-changed", G_CALLBACK(update_time_widget), gui); } gboolean opengl_setup(AWeatherGui *gui) diff --git a/src/data.c b/src/data.c index c36556d..7c43138 100644 --- a/src/data.c +++ b/src/data.c @@ -27,6 +27,15 @@ static void cache_file_cb(GObject *source_object, GAsyncResult *res, gpointer _i g_free(info); } +static goffset g_file_get_size(GFile *file) +{ + GError *error = NULL; + GFileInfo *info = g_file_query_info(file, G_FILE_ATTRIBUTE_STANDARD_SIZE, 0, NULL, &error); + if (error) + g_warning("unable to get file size: %s", error->message); + return g_file_info_get_size(info); +} + /** * Cache a image from Ridge to the local disk * \param path Path to the Ridge file, starting after /ridge/ @@ -36,25 +45,30 @@ void cache_file(char *base, char *path, AWeatherCacheDoneCallback callback, gpoi { gchar *url = g_strconcat(base, path, NULL); gchar *local = g_build_filename(g_get_user_cache_dir(), PACKAGE, path, NULL); - if (g_file_test(local, G_FILE_TEST_EXISTS)) { - callback(local, user_data); - } else { - if (!g_file_test(g_path_get_dirname(local), G_FILE_TEST_IS_DIR)) - g_mkdir_with_parents(g_path_get_dirname(local), 0755); - cache_file_end_t *info = g_malloc0(sizeof(cache_file_end_t)); - info->callback = callback; - info->src = url; - info->dst = local; - info->user_data = user_data; - GFile *src = g_file_new_for_uri(url); - GFile *dst = g_file_new_for_path(local); - g_file_copy_async(src, dst, - G_FILE_COPY_OVERWRITE, // GFileCopyFlags flags, - 0, // int io_priority, - NULL, // GCancellable *cancellable, - NULL, // GFileProgressCallback progress_callback, - NULL, // gpointer progress_callback_data, - cache_file_cb, // GAsyncReadyCallback callback, - info); // gpointer user_data - } + GFile *src = g_file_new_for_uri(url); + GFile *dst = g_file_new_for_path(local); + + if (!g_file_test(local, G_FILE_TEST_EXISTS)) + g_message("Caching file: local does not exist - %s", local); + else if (g_file_get_size(src) != g_file_get_size(dst)) + g_message("Caching file: sizes mismatch - %lld != %lld", + g_file_get_size(src), g_file_get_size(dst)); + else + return callback(local, user_data); + + if (!g_file_test(g_path_get_dirname(local), G_FILE_TEST_IS_DIR)) + g_mkdir_with_parents(g_path_get_dirname(local), 0755); + cache_file_end_t *info = g_malloc0(sizeof(cache_file_end_t)); + info->callback = callback; + info->src = url; + info->dst = local; + info->user_data = user_data; + g_file_copy_async(src, dst, + G_FILE_COPY_OVERWRITE, // GFileCopyFlags flags, + 0, // int io_priority, + NULL, // GCancellable *cancellable, + NULL, // GFileProgressCallback progress_callback, + NULL, // gpointer progress_callback_data, + cache_file_cb, // GAsyncReadyCallback callback, + info); // gpointer user_data } diff --git a/src/plugin-radar.c b/src/plugin-radar.c index 3ac3682..1fe30f6 100644 --- a/src/plugin-radar.c +++ b/src/plugin-radar.c @@ -105,24 +105,20 @@ static void load_radar_gui(Radar *radar) for (vi = 0; vi < radar->h.nvolumes; vi++) { Volume *vol = radar->v[vi]; if (vol == NULL) continue; - g_message(" adding volume: %d", vi); GtkWidget *vbox = gtk_vbox_new(TRUE, 0); for (si = vol->h.nsweeps-1; si >= 0; si--) { Sweep *sweep = vol->sweep[si]; if (sweep == NULL) continue; char *label = g_strdup_printf("Tilt: %.2f (%s)", sweep->h.elev, vol->h.type_str); - g_message(" adding sweep: %d - %s", si, label); button = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(button), label); g_object_set(button, "draw-indicator", FALSE, NULL); g_signal_connect_swapped(button, "clicked", G_CALLBACK(load_sweep), sweep); gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, TRUE, 0); g_free(label); } - g_message("adding vbox to hbox"); gtk_box_set_homogeneous(GTK_BOX(vbox), FALSE); gtk_box_pack_start(GTK_BOX(hbox), vbox, TRUE, TRUE, 0); } - g_message("adding hbox to scroll"); gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(config_body), hbox); gtk_widget_show_all(hbox); } @@ -296,16 +292,18 @@ static void set_site(AWeatherView *view, char *site, gpointer user_data) GtkListStore *lstore = GTK_LIST_STORE(gtk_tree_view_get_model(tview)); gtk_list_store_clear(lstore); radar = NULL; + char *time = NULL; for (int i = 0; lines[i] && lines[i][0]; i++) { // format: `841907 KABR_20090510_0159' //g_message("\tadding %p [%s]", lines[i], lines[i]); char **parts = g_strsplit(lines[i], " ", 2); + time = parts[1]+5; GtkTreeIter iter; - gtk_list_store_append(lstore, &iter); - gtk_list_store_set(lstore, &iter, 0, parts[1]+5, -1); - if (i == 0) - set_time(view, parts[1]+5, NULL); + gtk_list_store_insert(lstore, &iter, 0); + gtk_list_store_set(lstore, &iter, 0, time, -1); } + if (time != NULL) + aweather_view_set_time(view, time); } /* Init */ -- 2.43.2