From 61fb0b58c4801a2b904fd38a64708c8a13f98dd3 Mon Sep 17 00:00:00 2001 From: Andy Spencer Date: Thu, 10 Nov 2011 06:51:39 +0000 Subject: [PATCH 1/1] Add radar menu to quickly focus on a site --- data/main.ui.in | 9 +++++++++ src/aweather-gui.c | 40 ++++++++++++++++++++++++++++++++++++++++ src/aweather-location.c | 6 +++--- src/plugins/radar.c | 2 ++ 4 files changed, 54 insertions(+), 3 deletions(-) diff --git a/data/main.ui.in b/data/main.ui.in index 148fd4a..7113cc3 100644 --- a/data/main.ui.in +++ b/data/main.ui.in @@ -503,6 +503,15 @@ The hypothetical commands `show w' and `show c' should show the appropriate part + + + True + False + False + _Radar + True + + True diff --git a/src/aweather-gui.c b/src/aweather-gui.c index 558f43f..5e25535 100644 --- a/src/aweather-gui.c +++ b/src/aweather-gui.c @@ -143,6 +143,22 @@ G_MODULE_EXPORT void on_contents(GtkMenuItem *menu, AWeatherGui *self) g_free(path); } +void on_radar_changed(GtkMenuItem *menu, AWeatherGui *self) +{ + city_t *city = g_object_get_data(G_OBJECT(menu), "city"); + grits_viewer_set_location(self->viewer, + city->pos.lat, city->pos.lon, EARTH_R/35); + /* Focus radar tab */ + GtkWidget *config = aweather_gui_get_widget(self, "main_tabs"); + gint npages = gtk_notebook_get_n_pages(GTK_NOTEBOOK(config)); + for (int i = 0; i < npages; i++) { + GtkWidget *child = gtk_notebook_get_nth_page(GTK_NOTEBOOK(config), i); + const gchar *plugin = gtk_notebook_get_tab_label_text(GTK_NOTEBOOK(config), child); + if (g_str_equal(plugin, "radar")) + gtk_notebook_set_current_page(GTK_NOTEBOOK(config), i); + } +} + G_MODULE_EXPORT void on_quit(GtkMenuItem *menu, AWeatherGui *self) { gtk_widget_destroy(GTK_WIDGET(self)); @@ -368,6 +384,29 @@ static void site_setup(AWeatherGui *self) GTK_CELL_RENDERER(renderer), combo_sensitive, NULL, NULL); } +static void menu_setup(AWeatherGui *self) +{ + GtkWidget *menu = aweather_gui_get_widget(self, "main_menu_radar"); + GtkWidget *states, *state, *sites, *site; + + states = gtk_menu_new(); + gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu), states); + + for (int i = 0; cities[i].type; i++) { + if (cities[i].type == LOCATION_STATE) { + state = gtk_menu_item_new_with_label(cities[i].name); + sites = gtk_menu_new(); + gtk_menu_shell_append(GTK_MENU_SHELL(states), state); + gtk_menu_item_set_submenu(GTK_MENU_ITEM(state), sites); + } else if (cities[i].type == LOCATION_CITY) { + site = gtk_menu_item_new_with_label(cities[i].name); + gtk_menu_shell_append(GTK_MENU_SHELL(sites), site); + g_object_set_data(G_OBJECT(site), "city", &cities[i]); + g_signal_connect(site, "activate", G_CALLBACK(on_radar_changed), self); + } + } +} + static void prefs_setup(AWeatherGui *self) { /* Set values */ @@ -562,6 +601,7 @@ static void aweather_gui_parser_finished(GtkBuildable *_self, GtkBuilder *builde /* Misc, helpers */ site_setup(self); + menu_setup(self); time_setup(self); prefs_setup(self); icons_setup(self); diff --git a/src/aweather-location.c b/src/aweather-location.c index d3278af..d6d93ee 100644 --- a/src/aweather-location.c +++ b/src/aweather-location.c @@ -28,7 +28,7 @@ city_t cities[] = { {LOCATION_CITY, "KMOB", "Mobile", {30.6794, -88.2397, 0}, 0.3}, {LOCATION_NOP, "KEOX", "Fort Rucker", {31.456, -85.455, 0}, 0.1}, - {LOCATION_STATE, NULL, "Alaska", {0, 0, 0}, 0.0}, + {LOCATION_NOP, NULL, "Alaska", {0, 0, 0}, 0.0}, {LOCATION_NOP, "KABC", "Bethel", {60.78, -161.87, 0}, 0.1}, {LOCATION_NOP, "KAHG", "Nikiski", {60.72, -151.35, 0}, 0.1}, {LOCATION_NOP, "KAIH", "Middleton Island", {59.45, -146.3, 0}, 0.1}, @@ -81,7 +81,7 @@ city_t cities[] = { {LOCATION_CITY, "KFFC", "Atlanta", {33.3636, -84.5658, 0}, 0.8}, {LOCATION_CITY, "KJGX", "Robins AFB", {32.675, -83.3511, 0}, 0.3}, - {LOCATION_STATE, NULL, "Guam", {0, 0, 0}, 0.0}, + {LOCATION_NOP, NULL, "Guam", {0, 0, 0}, 0.0}, {LOCATION_NOP, "KGUA", "Barrigada Comm.", {13.45, 144.8, 0}, 0.1}, {LOCATION_STATE, NULL, "Hawaii", {0, 0, 0}, 0.0}, @@ -277,7 +277,7 @@ city_t cities[] = { {LOCATION_CITY, "KCYS", "Cheyenne", {41.151, -104.806, 0}, 0.5}, {LOCATION_CITY, "KRIW", "Riverton", {43.066, -108.477, 0}, 0.3}, - {LOCATION_STATE, NULL, "Other", {0, 0, 0}, 0.0}, + {LOCATION_NOP, NULL, "Other", {0, 0, 0}, 0.0}, {LOCATION_NOP, "DOP1", "DOP1", {0, 0, 0}, 0.1}, {LOCATION_NOP, "FOP1", "FOP1", {0, 0, 0}, 0.1}, {LOCATION_NOP, "NOP3", "NOP3", {0, 0, 0}, 0.1}, diff --git a/src/plugins/radar.c b/src/plugins/radar.c index 62b55c0..1b4e2b8 100644 --- a/src/plugins/radar.c +++ b/src/plugins/radar.c @@ -252,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", -- 2.43.2