Пример #1
0
        public void LoggedUpdate(XmlElement xmlKeys)
        {
            CboKey.RemoveAllItems();
            foreach (XmlElement xmlKey in xmlKeys.ChildNodes)
            {
                string keyName = xmlKey.GetAttribute("name");
                CboKey.AddItem(keyName);
            }
            string currentKey   = Engine.Instance.Storage.Get("key");
            int    currentIndex = (int)CboKey.IndexOfItem(currentKey);

            if (currentIndex != -1)
            {
                CboKey.SelectItem(currentIndex);
            }
            else
            {
                if (CboKey.ItemCount > 0)
                {
                    CboKey.SelectItem(0);
                    Engine.Instance.Storage.Set("key", CboKey.ItemAtIndex(0).Title);
                }
                else
                {
                    Engine.Instance.Storage.Set("key", "");
                }
            }
        }
Пример #2
0
        public void RefreshUi(Engine.RefreshUiMode mode)
        {
            try
            {
                if ((mode == Engine.RefreshUiMode.MainMessage) || (mode == Engine.RefreshUiMode.Full))
                {
                    if (Engine.CurrentServer != null)
                    {
                        ImgTopFlag.Image = NSImage.ImageNamed("flag_" + Engine.CurrentServer.CountryCode.ToLowerInvariant() + ".png");
                    }
                    else
                    {
                        ImgTopFlag.Image = NSImage.ImageNamed("notconnected.png");
                    }

                    LblWaiting1.StringValue = Engine.WaitMessage;

                    if (Engine.IsWaiting())
                    {
                        ImgProgress.StartAnimation(this);
                        ImgTopPanel.Image        = NSImage.ImageNamed("topbar_osx_yellow.png");
                        MnuTrayStatus.Image      = NSImage.ImageNamed("status_yellow_16.png");
                        LblTopStatus.StringValue = Engine.WaitMessage;

                        TabOverview.SelectAt(1);

                        CmdCancel.Hidden       = (Engine.IsWaitingCancelAllowed() == false);
                        CmdCancel.Enabled      = (Engine.IsWaitingCancelPending() == false);
                        MnuTrayConnect.Enabled = CmdCancel.Enabled;
                    }
                    else if (Engine.IsConnected())
                    {
                        ImgProgress.StopAnimation(this);
                        ImgTopPanel.Image        = NSImage.ImageNamed("topbar_osx_green.png");
                        MnuTrayStatus.Image      = NSImage.ImageNamed("status_green_16.png");
                        LblTopStatus.StringValue = LanguageManager.GetText("TopBarConnected", Engine.CurrentServer.DisplayName);


                        TabOverview.SelectAt(2);

                        LblConnectedServerName.StringValue = Engine.CurrentServer.DisplayName;
                        LblConnectedLocation.StringValue   = Engine.CurrentServer.GetLocationForList();
                        TxtConnectedExitIp.StringValue     = Engine.ConnectionActive.ExitIPs.ToString();
                        ImgConnectedCountry.Image          = NSImage.ImageNamed("flag_" + Engine.CurrentServer.CountryCode.ToLowerInvariant() + ".png");
                    }
                    else
                    {
                        ImgProgress.StopAnimation(this);
                        ImgTopPanel.Image   = NSImage.ImageNamed("topbar_osx_red.png");
                        MnuTrayStatus.Image = NSImage.ImageNamed("status_red_16.png");
                        if (Engine.Instance.NetworkLockManager.IsActive())
                        {
                            LblTopStatus.StringValue = LanguageManager.GetText("TopBarNotConnectedLocked");
                        }
                        else
                        {
                            LblTopStatus.StringValue = LanguageManager.GetText("TopBarNotConnectedExposed");
                        }

                        TabOverview.SelectAt(0);
                    }
                }

                if ((mode == Engine.RefreshUiMode.Log) || (mode == Engine.RefreshUiMode.Full))
                {
                    lock (Engine.LogsPending)
                    {
                        while (Engine.LogsPending.Count > 0)
                        {
                            LogEntry l = Engine.LogsPending[0];
                            Engine.LogsPending.RemoveAt(0);

                            Log(l);
                        }
                    }
                    LblWaiting2.StringValue = Engine.Logs.GetLogDetailTitle();
                }

                if ((mode == Engine.RefreshUiMode.Stats) || (mode == Engine.RefreshUiMode.Full))
                {
                    if (Engine.IsConnected())
                    {
                        TxtConnectedSince.StringValue = Engine.Stats.GetValue("VpnStart");

                        TxtConnectedDownload.StringValue = LanguageManager.FormatBytes(Engine.ConnectionActive.BytesLastDownloadStep, true, false);
                        TxtConnectedUpload.StringValue   = LanguageManager.FormatBytes(Engine.ConnectionActive.BytesLastUploadStep, true, false);
                    }
                }

                if ((mode == Engine.RefreshUiMode.Full))
                {
                    if (TableServersController != null)
                    {
                        TableServersController.RefreshUI();
                    }
                    if (TableAreasController != null)
                    {
                        TableAreasController.RefreshUI();
                    }

                    CboKey.RemoveAllItems();
                    if ((Engine.Instance != null) && (Engine.Instance.AirVPN != null) && (Engine.Instance.AirVPN.User != null))
                    {
                        foreach (XmlElement xmlKey in Engine.Instance.AirVPN.User.SelectNodes("keys/key"))
                        {
                            string keyName = xmlKey.GetAttribute("name");
                            CboKey.AddItem(keyName);
                        }
                        string currentKey   = Engine.Instance.Storage.Get("key");
                        int    currentIndex = (int)CboKey.IndexOfItem(currentKey);
                        if (currentIndex != -1)
                        {
                            CboKey.SelectItem(currentIndex);
                        }
                    }
                }

                if ((mode == Engine.RefreshUiMode.MainMessage) || (mode == Engine.RefreshUiMode.Full))
                {
                    EnabledUI();
                }
            }
            catch (Exception)
            {
                // TOFIX: macOS sometime throw an useless exception in closing phase
            }
        }