]> Pileus Git - aweather/commitdiff
Add radar menu to quickly focus on a site
authorAndy Spencer <andy753421@gmail.com>
Thu, 10 Nov 2011 06:51:39 +0000 (06:51 +0000)
committerAndy Spencer <andy753421@gmail.com>
Thu, 10 Nov 2011 06:51:39 +0000 (06:51 +0000)
data/main.ui.in
src/aweather-gui.c
src/aweather-location.c
src/plugins/radar.c

index 148fd4ad9d151faa56e63ffd34dc73ed909c18ab..7113cc39edc97296b50392911e21876bef107152 100644 (file)
@@ -503,6 +503,15 @@ The hypothetical commands `show w' and `show c' should show the appropriate part
                 </child>
               </object>
             </child>
+            <child>
+              <object class="GtkMenuItem" id="main_menu_radar">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="use_action_appearance">False</property>
+                <property name="label" translatable="yes">_Radar</property>
+                <property name="use_underline">True</property>
+              </object>
+            </child>
             <child>
               <object class="GtkMenuItem" id="main_menu_help">
                 <property name="visible">True</property>
index 558f43f12444f2138b87784ea7e4c1927afbb1ce..5e25535a49d711eb56ec9551b690f7aca283c45f 100644 (file)
@@ -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);
index d3278af95df222dad392d2533a090c12c1218f66..d6d93eea4eb6bb21f2aec00ce3e42afb56b02b17 100644 (file)
@@ -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},
index 62b55c0ec501640ec8170aa24e61f3b049a937b7..1b4e2b8feed1bdd423cda82fb5006cfa376325ab 100644 (file)
@@ -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",