public EditStationDialog()
            : base(string.Empty, string.Empty, MessageBoxButtons.OkCancel, MessageBoxIcons.Information, DesktopManager.ScreenWidth / 2, 170)
        {
            int txtWidth = _mWidth * 2 / 3;

            AddChild(new Label("Name", margin * 2, 55 + 15 - Fonts.Arial.Height / 2, 60, 25));
            AddChild(new Label("Address", margin * 2, 90 + 15 - Fonts.Arial.Height / 2, 60, 25));
            txtName = new TextBox(string.Empty, _mWidth - txtWidth - margin * 2, 55, txtWidth, 30);
            txtAddress = new TextBox(string.Empty, _mWidth - txtWidth - margin * 2, 90, txtWidth, 30);
            AddChild(txtName);
            AddChild(txtAddress);
        }
Ejemplo n.º 2
0
        public ProxyDialog()
            : base(string.Empty, "Proxy", MessageBoxButtons.OkCancel, MessageBoxIcons.Information, DesktopManager.ScreenWidth / 2, 210)
        {
            int txtWidth = _mWidth * 2 / 3;

            AddChild(chkUseProxy = new CheckBox(false, "Enable Proxy", 10, 58, 120, 30));
            AddChild(chkForRadio = new CheckBox(false, "Use For Radio", 10, chkUseProxy.Y + chkUseProxy.Height + 5, 120, 30) { Enabled = false });
            AddChild(txtAddress = new TextBox("", 60, chkForRadio.Y + chkForRadio.Height + 5, _mWidth - 60 - 10, 30) { Enabled = false, EditTextLabel = "Proxy Address:", AllowMultiline = false });
            AddChild(new Label("Address", 10, txtAddress.Y + txtAddress.Height / 2 - StyleManager.CurrentStyle.LabelFont.Height / 2, 50, 30));

            chkUseProxy.IsCheckedChanged += (s) =>
            {
                chkForRadio.Enabled = chkUseProxy.IsChecked;
                txtAddress.Enabled = chkUseProxy.IsChecked;
            };
        }
Ejemplo n.º 3
0
        private static void CreateNetworkSettingsPanel(Panel panel)
        {
            const int leftMargin = 10;
            const int topMargin = 10;

            NetworkInterface net = NetworkInterface.GetAllNetworkInterfaces()[0];

            bool isDhcp = net.IsDhcpEnabled;
            int labelFontHeightDiv2 = StyleManager.CurrentStyle.LabelFont.Height / 2;

            RadioButton rdStatic, rdDynamic;
            panel.AddChild(new Label("Configuration", leftMargin, topMargin + 13 - labelFontHeightDiv2, 80, 25));
            panel.AddChild(rdStatic = new RadioButton("Static", 100, topMargin, 80, 26) { IsChecked = !isDhcp });
            panel.AddChild(rdDynamic = new RadioButton("Dynamic", rdStatic.X + rdStatic.Width + 10, topMargin, 80, 26) { IsChecked = isDhcp });

            TextBox txtIp, txtNetMask, txtGateway, txtDns;

            int y = rdStatic.Y + rdStatic.Height + 5;

            panel.AddChild(new Label("Address", leftMargin, y + 15 - labelFontHeightDiv2, 80, 25));
            panel.AddChild(txtIp = new TextBox(net.IPAddress.ToString(), 100, y, 175, 30)
            {
                EditTextLabel = "IP Address",
                Validator = NetValidators.IpValidator,
                AllowedChars = AllowedCharTypesEnum.Ip,
                Enabled = !isDhcp
            });
            y += 35;

            panel.AddChild(new Label("Netmask", leftMargin, y + 15 - labelFontHeightDiv2, 80, 25));
            panel.AddChild(txtNetMask = new TextBox(net.SubnetMask.ToString(), 100, y, 175, 30)
            {
                EditTextLabel = "Subnet Mask",
                Validator = NetValidators.NetMaskValidator,
                AllowedChars = AllowedCharTypesEnum.Ip,
                Enabled = !isDhcp
            });
            y += 35;

            panel.AddChild(new Label("Gateway", leftMargin, y + 15 - labelFontHeightDiv2, 80, 25));
            panel.AddChild(txtGateway = new TextBox(net.GatewayAddress.ToString(), 100, y, 175, 30)
            {
                EditTextLabel = "Gateway IP Address",
                Validator = NetValidators.IpValidator,
                AllowedChars = AllowedCharTypesEnum.Ip,
                Enabled = !isDhcp
            });
            y += 35;

            panel.AddChild(new Label("Dns", leftMargin, y + 15 - labelFontHeightDiv2, 80, 25));
            panel.AddChild(txtDns = new TextBox(net.DnsAddresses.Length >= 1 ? net.DnsAddresses[0] : string.Empty, 100, y, 175, 30)
            {
                EditTextLabel = "DNS Address",
                Validator = NetValidators.IpAllowEmptyValidator,
                AllowedChars = AllowedCharTypesEnum.Ip,
                Enabled = !isDhcp
            });
            y += 35;

            TextButton applyButton = null, proxyButton;

            UiEventHandler modeChangedHandler = (s) =>
            {
                bool dynamicSelected = rdDynamic.IsChecked;

                panel.Suspended = true;

                txtIp.Enabled = !dynamicSelected;
                txtNetMask.Enabled = !dynamicSelected;
                txtGateway.Enabled = !dynamicSelected;
                txtDns.Enabled = !dynamicSelected;

                if (!dynamicSelected)
                {
                    txtIp.Text = net.IPAddress.ToString();
                    txtNetMask.Text = net.SubnetMask.ToString();
                    txtGateway.Text = net.GatewayAddress.ToString();
                    txtDns.Text = net.DnsAddresses.Length >= 1 ? net.DnsAddresses[0].ToString() : string.Empty;
                }
                else applyButton.Enabled = true;

                panel.Suspended = false;
            };
            rdStatic.IsCheckedChanged += modeChangedHandler;

            int x = txtIp.X + txtIp.Width + 10;
            panel.AddChild(applyButton = new TextButton("Apply", x, txtIp.Y, panel.Width - x - 10, txtIp.Height * 2 + 5) { Enabled = false });
            panel.AddChild(proxyButton = new TextButton("Proxy", x, txtGateway.Y, panel.Width - x - 10, txtGateway.Height * 2 + 5));

            applyButton.ButtonPressed += (s) =>
            {
                applyButton.Enabled = false;

                AppSettings.Instance.Network.DhcpEnabled = rdDynamic.IsChecked;

                if (rdDynamic.IsChecked)
                {
                    net.EnableDhcp();
                }
                else
                {
                    net.EnableStaticIP(txtIp.Text, txtNetMask.Text, txtGateway.Text);

                    if (txtDns.Text.Length != 0)
                    {
                        AppSettings.Instance.Network.DnsAddresses = new string[] { txtDns.Text };
                        net.EnableStaticDns(AppSettings.Instance.Network.DnsAddresses);
                    }
                    AppSettings.Instance.Network.IpAddress = IPAddress.Parse(txtIp.Text).GetAddressBytes();
                    AppSettings.Instance.Network.NetMask = IPAddress.Parse(txtNetMask.Text).GetAddressBytes();
                    AppSettings.Instance.Network.Gateway = IPAddress.Parse(txtGateway.Text).GetAddressBytes();
                }

                AppSettings.Instance.Save();
            };

            ProxyDialog proxyDiag = new ProxyDialog();
            proxyButton.ButtonPressed += (s) =>
            {
                new Thread(new ThreadStart(() =>
                    {
                        if (proxyDiag.Show(AppSettings.Instance.Network.UseProxy, AppSettings.Instance.Network.Proxy.UseForRadio, AppSettings.Instance.Network.Proxy.Address))
                        {
                            AppSettings.Instance.Network.UseProxy = proxyDiag.UseProxy;
                            AppSettings.Instance.Network.Proxy.UseForRadio = proxyDiag.UseForRadio;
                            AppSettings.Instance.Network.Proxy.Address = proxyDiag.ProxyAddress;

                            proxyForWeather = AppSettings.Instance.Network.UseProxy && !AppSettings.Instance.Network.Proxy.UseForRadio ?
                                new WebProxy(AppSettings.Instance.Network.Proxy.Address) : null;

                            AppSettings.Instance.Save();
                        }
                    })).Start();
            };

            txtDns.TextChanged += (nt, valid) => applyButton.Enabled = valid;
            txtIp.TextChanged += (nt, valid) => applyButton.Enabled = valid;
            txtGateway.TextChanged += (nt, valid) => applyButton.Enabled = valid;
            txtNetMask.TextChanged += (nt, valid) => applyButton.Enabled = valid;
        }
Ejemplo n.º 4
0
        private static void CreateWeatherPanel(Panel panel)
        {
            //initial weather place
            const string initialPlace = "Timisoara";

            proxyForWeather = AppSettings.Instance.Network.UseProxy && !AppSettings.Instance.Network.Proxy.UseForRadio ? new WebProxy(AppSettings.Instance.Network.Proxy.Address) : null;

            //create a new Yahoo! Weather Provider
            YahooWeatherProvider yProvider = new YahooWeatherProvider();
            GoogleWeatherProvider gProvider = new GoogleWeatherProvider();

            RadioButton rdYahoo = null, rdGoogle = null;
            Ui.Controls.TouchControls.Button refreshButton = null;

            Label title = new Label("Weather", 5, 5, 200, Fonts.ArialMediumBold.Height) { Font = Fonts.ArialMediumBold };
            panel.AddChild(title);

            //create text box for weather place
            TextBox txtWeatherPlace = new TextBox(string.Empty, 5, title.ScreenBottom + 15, 170, 30) { Validator = (s) => s.Trim().Length != 0, EditTextLabel = "Place:" };
            panel.AddChild(txtWeatherPlace);

            //create a weather control and add it on the desktop (centered)
            GoogleWeatherControl gControl = new GoogleWeatherControl(gProvider.LastWeatherCondition, 0, 80) { Visible = false };
            YahooWeatherControl yControl = new YahooWeatherControl(yProvider.LastWeatherCondition, 0, 0);
            gControl.X = (panel.Width - gControl.Width) / 2;
            gControl.Y = txtWeatherPlace.ScreenBottom + (panel.Height - txtWeatherPlace.ScreenBottom - gControl.Height) / 2;
            yControl.X = (panel.Width - yControl.Width) / 2;
            yControl.Y = gControl.Y;
            panel.AddChild(gControl);
            panel.AddChild(yControl);

            //watch for text changed
            string oldPlace = string.Empty;
            const string noWeatherInfo = "No weather info";
            string basicWeatherInfo = null;
            GetWeatherInfo = () =>
            {
                if (basicWeatherInfo == null)
                {
                    basicWeatherInfo = null;
                    if (rdGoogle.IsChecked)
                    {
                        if (gProvider.LastWeatherCondition != null)
                            basicWeatherInfo = gProvider.LastWeatherCondition.City + " " + gProvider.LastWeatherCondition.CurrentCondition.Temp;
                    }
                    else if (rdYahoo.IsChecked)
                    {
                        if (yProvider.LastWeatherCondition != null)
                            basicWeatherInfo = yProvider.LastWeatherCondition.Location + " " + yProvider.LastWeatherCondition.Temperature;
                    }
                    if (basicWeatherInfo == null)
                        basicWeatherInfo = noWeatherInfo;
                }
                return basicWeatherInfo;
            };

            SimpleAction refreshWeather = () =>
            {
                try
                {
                    if (!Ethernet.IsCableConnected) return;
                }
                catch (Exception)
                {
                    //TODO: emulator throws exception
                }

                //disable the textbox
                txtWeatherPlace.Enabled = yControl.Enabled = gControl.Enabled = refreshButton.Enabled = false;
                //get the weather in a new Thread
                new Thread(() =>
                {
                    if (yProvider.SetWeatherPlace(oldPlace, proxyForWeather)) yProvider.GetWeather(proxyForWeather);
                    yControl.WeatherCondition = yProvider.LastWeatherCondition;

                    gProvider.GetWeather(oldPlace, proxyForWeather);
                    gControl.WeatherCondition = gProvider.LastWeatherCondition;

                    basicWeatherInfo = null;

                    txtWeatherPlace.Enabled = yControl.Enabled = gControl.Enabled = refreshButton.Enabled = true;
                }).Start();
            };

            AppConfig.OnNetworkConnected += () => refreshWeather();

            txtWeatherPlace.TextChanged += (newPlace, valid) =>
            {
                string nPlace = newPlace.Trim().ToLower();
                //if the new place is different
                if (nPlace != oldPlace)
                {
                    oldPlace = nPlace;
                    refreshWeather();
                }
            };

            //refresh the text colors according to the current style
            StyleManager.StyleChanged += (oldStyle, newStyle) =>
            {
                yControl.WeatherCondition = yProvider.LastWeatherCondition;
                gControl.WeatherCondition = gProvider.LastWeatherCondition;
            };


            panel.AddChild(refreshButton = new ImageButton(Images.GetBitmap(Images.BitmapResources.imgRefresh),
                txtWeatherPlace.X + txtWeatherPlace.Width + 5, txtWeatherPlace.Y, txtWeatherPlace.Height, txtWeatherPlace.Height));
            refreshButton.ButtonPressed += (s) => refreshWeather();

            panel.AddChild(rdYahoo = new RadioButton("Yahoo", refreshButton.X + refreshButton.Width + 15, refreshButton.ScreenTop + refreshButton.Height / 2 - 13, 80, 26) { IsChecked = true });
            panel.AddChild(rdGoogle = new RadioButton("Google", rdYahoo.X + rdYahoo.Width + 15, txtWeatherPlace.ScreenTop + txtWeatherPlace.Height / 2 - 13, rdYahoo.Width, 26));
            UiEventHandler checkChanged = (s) =>
            {
                //this will trigger once for each radio button
                if (!((RadioButton)s).IsChecked) return;

                bool oldValue = panel.Suspended;
                panel.Suspended = true;
                if (rdYahoo.IsChecked)
                {
                    yControl.Visible = true;
                    gControl.Visible = false;
                }
                else
                {
                    yControl.Visible = false;
                    gControl.Visible = true;
                }
                basicWeatherInfo = null;
                panel.Suspended = oldValue;
            };
            rdGoogle.IsCheckedChanged += checkChanged;
            rdYahoo.IsCheckedChanged += checkChanged;

            //set the text to trigger a get on the weather
            txtWeatherPlace.Text = initialPlace;
        }