Example #1
0
        protected override MenuList OnGetMenuItems()
        {
            MenuList list = base.OnGetMenuItems();

            if (WeatherController.Weather.Condition != null)
            {
                list[MenuListContainer.Header].Add(new MenuItem(Catalog.GetString("Radar _Map"),
                                                                WeatherController.Weather.Image, (o, a) => WeatherController.Weather.ShowRadar()));
            }


            list.SetContainerTitle(MenuListContainer.Actions, Mono.Unix.Catalog.GetString("Forecasts"));
            for (int i = 0; i < WeatherController.Weather.ForecastDays; i++)
            {
                if (WeatherController.Weather.Forecasts [i].dow != null)
                {
                    list[MenuListContainer.Actions].Add(new ForecastMenuItem(i,
                                                                             string.Format("{0}", WeatherForecast.DayName(WeatherController.Weather.Forecasts [i].dow)), WeatherController.Weather.Forecasts [i].image));
                }
            }

            list[MenuListContainer.CustomOne].Add(new MenuItem(Catalog.GetString("_Settings"), Gtk.Stock.Preferences,
                                                               delegate {
                if (Config == null)
                {
                    Config = new WeatherConfigDialog();
                }
                Config.Show();
            }));

            if (WeatherController.CurrentLocation != "")
            {
                list[MenuListContainer.CustomOne].Add(new MenuItem(Catalog.GetString("Check _Weather"), Gtk.Stock.Refresh,
                                                                   delegate {
                    Status = WeatherDockletStatus.ManualReload;
                    State |= ItemState.Wait;
                    QueueRedraw();
                    WeatherController.ResetTimer();
                }));
            }

            return(list);
        }
Example #2
0
        protected override void OnScrolled(Gdk.ScrollDirection direction, Gdk.ModifierType mod)
        {
            if (WeatherPreferences.Locations.Length <= 1)
            {
                return;
            }

            Status = WeatherDockletStatus.ManualReload;
            State |= ItemState.Wait;
            QueueRedraw();

            if (direction == Gdk.ScrollDirection.Up)
            {
                WeatherController.PreviousLocation();
            }
            else
            {
                WeatherController.NextLocation();
            }
        }
Example #3
0
 public override void Unregistered()
 {
     WeatherController.StopTimer();
 }
Example #4
0
        protected override void ParseXml(XmlDocument xml)
        {
            XmlNodeList nodelist;

            if (WeatherController.EncodedCurrentLocation.StartsWith("PWS."))
            {
                nodelist = xml.SelectNodes("current_observation/location");
            }
            else
            {
                nodelist = xml.SelectNodes("current_observation/display_location");
            }

            XmlNode item = nodelist.Item(0);

            City = item.SelectSingleNode("city").InnerText;
            double dbl;

            Double.TryParse(item.SelectSingleNode("latitude").InnerText, NumberStyles.Any, CultureInfo.GetCultureInfo("en-US"), out dbl);
            Latitude = dbl;
            Double.TryParse(item.SelectSingleNode("longitude").InnerText, NumberStyles.Any, CultureInfo.GetCultureInfo("en-US"), out dbl);
            Longitude = dbl;
            SunRise   = WeatherController.Sunrise(Latitude, Longitude);
            SunSet    = WeatherController.Sunset(Latitude, Longitude);

            nodelist = xml.SelectNodes("current_observation");
            item     = nodelist.Item(0);

            int temp;

            if (WeatherController.EncodedCurrentLocation.StartsWith("PWS."))
            {
                double tmp;
                Double.TryParse(item.SelectSingleNode("temp_f").InnerText, NumberStyles.Any, CultureInfo.GetCultureInfo("en-US"), out tmp);
                Temp      = (int)tmp;
                FeelsLike = (int)tmp;
            }
            else
            {
                Int32.TryParse(item.SelectSingleNode("temp_f").InnerText, out temp);
                Temp      = temp;
                FeelsLike = temp;
            }

            if (!item.SelectSingleNode("heat_index_f").InnerText.Equals("NA") && item.SelectSingleNode("heat_index_f").InnerText.Length > 0)
            {
                Int32.TryParse(item.SelectSingleNode("heat_index_f").InnerText, out temp);
                FeelsLike = temp;
            }
            else if (!item.SelectSingleNode("windchill_f").InnerText.Equals("NA") && item.SelectSingleNode("windchill_f").InnerText.Length > 0)
            {
                Int32.TryParse(item.SelectSingleNode("windchill_f").InnerText, out temp);
                FeelsLike = temp;
            }

            Int32.TryParse(item.SelectSingleNode("wind_mph").InnerText, out temp);
            Wind          = temp;
            WindDirection = item.SelectSingleNode("wind_dir").InnerText;

            Humidity = item.SelectSingleNode("relative_humidity").InnerText;

            if (WeatherController.EncodedCurrentLocation.StartsWith("PWS."))
            {
                string lat = Latitude.ToString(CultureInfo.GetCultureInfo("en-US"));
                string lon = Longitude.ToString(CultureInfo.GetCultureInfo("en-US"));
                xml      = FetchXml("http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query=" + lat + "," + lon);
                nodelist = xml.SelectNodes("current_observation");
                item     = nodelist.Item(0);
            }

            Condition = item.SelectSingleNode("weather").InnerText;

            Image = GetImage(item.SelectSingleNode("icon").InnerText, true);
        }