Ejemplo n.º 1
0
        public override void AwakeFromNib()
        {
            base.AwakeFromNib();

            Window.Title = Constants.Name + " - " + Messages.WindowsLoginTitle;

            CboRemember.RemoveAllItems();
            CboRemember.AddItem(Messages.WindowsCredentialsRememberNo);
            CboRemember.AddItem(Messages.WindowsCredentialsRememberRun);
            CboRemember.AddItem(Messages.WindowsCredentialsRememberPermanent);
            GuiUtils.SetSelected(CboRemember, Messages.WindowsCredentialsRememberRun);

            TxtUsername.Changed += (object sender, EventArgs e) =>
            {
                EnableIde();
            };
            TxtPassword.Changed += (object sender, EventArgs e) =>
            {
                EnableIde();
            };

            CmdLogin.Activated += (object sender, EventArgs e) =>
            {
                Credentials          = new Credentials();
                Credentials.Username = TxtUsername.StringValue;
                Credentials.Password = TxtPassword.StringValue;
                string rememberText = GuiUtils.GetSelected(CboRemember);
                if (rememberText == Messages.WindowsCredentialsRememberNo)
                {
                    Credentials.Remember = "no";
                }
                else if (rememberText == Messages.WindowsCredentialsRememberRun)
                {
                    Credentials.Remember = "run";
                }
                else if (rememberText == Messages.WindowsCredentialsRememberPermanent)
                {
                    Credentials.Remember = "permanent";
                }
                else
                {
                    Credentials.Remember = "no";
                }

                Window.Close();
                NSApplication.SharedApplication.StopModal();
            };

            CmdCancel.Activated += (object sender, EventArgs e) =>
            {
                Credentials = null;

                Window.Close();
                NSApplication.SharedApplication.StopModal();
            };

            EnableIde();
        }
        public override void AwakeFromNib()
        {
            base.AwakeFromNib();

            Window.Title = Constants.Name + " - " + LanguageManager.GetText("WindowsSettingsRouteTitle");

            GuiUtils.SetButtonCancel(Window, CmdCancel);
            GuiUtils.SetButtonDefault(Window, CmdOk);

            LblHelp.StringValue = LanguageManager.GetText("WindowsSettingsRouteTitle");


            CboAction.RemoveAllItems();
            CboAction.AddItem(WindowPreferencesController.RouteDirectionToDescription("none"));
            CboAction.AddItem(WindowPreferencesController.RouteDirectionToDescription("in"));
            CboAction.AddItem(WindowPreferencesController.RouteDirectionToDescription("out"));

            TxtIP.Changed += (object sender, EventArgs e) =>
            {
                EnableIde();
            };
            CmdOk.Activated += (object sender, EventArgs e) =>
            {
                Accepted    = true;
                Item.Ip     = TxtIP.StringValue;
                Item.Action = WindowPreferencesController.RouteDescriptionToDirection(GuiUtils.GetSelected(CboAction));
                Item.Icon   = Item.Action;
                Item.Notes  = TxtNotes.StringValue;

                Window.Close();
                NSApplication.SharedApplication.StopModal();
            };

            CmdCancel.Activated += (object sender, EventArgs e) =>
            {
                Accepted = false;

                Window.Close();
                NSApplication.SharedApplication.StopModal();
            };

            TxtIP.StringValue = Item.Ip;
            GuiUtils.SetSelected(CboAction, WindowPreferencesController.RouteDirectionToDescription(Item.Action));
            TxtNotes.StringValue = Item.Notes;

            EnableIde();
        }
Ejemplo n.º 3
0
        public override void AwakeFromNib()
        {
            base.AwakeFromNib();

            Window.Delegate = new MainWindowDelegate(this);

            Window.AcceptsMouseMovedEvents = true;

            TabProviders = TabMain.Items[1];

            CreateMenuBarIcon();

            LblVersion.StringValue = "Version " + Constants.VersionDesc;
            CmdUpdater.Hidden      = true;
            MnuTrayUpdate.Hidden   = true;

            ChkRemember.State       = Engine.Storage.GetBool("remember") ? NSCellStateValue.On : NSCellStateValue.Off;
            ChkServersShowAll.State = NSCellStateValue.Off;
            GuiUtils.SetCheck(ChkServersLockCurrent, Engine.Storage.GetBool("servers.locklast"));
            GuiUtils.SetSelected(CboServersScoringRule, Engine.Storage.Get("servers.scoretype"));

            CboSpeedResolutions.RemoveAllItems();
            CboSpeedResolutions.AddItem(LanguageManager.GetText("WindowsMainSpeedResolution1"));
            CboSpeedResolutions.AddItem(LanguageManager.GetText("WindowsMainSpeedResolution2"));
            CboSpeedResolutions.AddItem(LanguageManager.GetText("WindowsMainSpeedResolution3"));
            CboSpeedResolutions.AddItem(LanguageManager.GetText("WindowsMainSpeedResolution4"));
            CboSpeedResolutions.AddItem(LanguageManager.GetText("WindowsMainSpeedResolution5"));
            CboSpeedResolutions.SelectItem(0);

            CmdConnect.Title       = LanguageManager.GetText("CommandConnect");
            LblConnect.StringValue = LanguageManager.GetText("CommandConnectSubtitle");
            CmdDisconnect.Title    = LanguageManager.GetText("CommandDisconnect");
            CmdCancel.Title        = LanguageManager.GetText("CommandCancel");

            CboServersScoringRule.ToolTip = LanguageManager.GetText("TooltipServersScoreType");
            ChkServersLockCurrent.ToolTip = LanguageManager.GetText("TooltipServersLockCurrent");
            ChkServersShowAll.ToolTip     = LanguageManager.GetText("TooltipServersShowAll");
            CmdServersConnect.ToolTip     = LanguageManager.GetText("TooltipServersConnect");
            CmdServersUndefined.ToolTip   = LanguageManager.GetText("TooltipServersUndefined");
            CmdServersBlackList.ToolTip   = LanguageManager.GetText("TooltipServersBlackList");
            CmdServersWhiteList.ToolTip   = LanguageManager.GetText("TooltipServersWhiteList");
            CmdServersRename.ToolTip      = LanguageManager.GetText("TooltipServersRename");
            CmdServersMore.ToolTip        = LanguageManager.GetText("TooltipServersMore");
            CmdServersRefresh.ToolTip     = LanguageManager.GetText("TooltipServersRefresh");
            CmdAreasUndefined.ToolTip     = LanguageManager.GetText("TooltipAreasUndefined");
            CmdAreasBlackList.ToolTip     = LanguageManager.GetText("TooltipAreasBlackList");
            CmdAreasWhiteList.ToolTip     = LanguageManager.GetText("TooltipAreasWhiteList");
            CmdLogsCommand.ToolTip        = LanguageManager.GetText("TooltipLogsCommand");
            CmdLogsClean.ToolTip          = LanguageManager.GetText("TooltipLogsClean");
            CmdLogsCopy.ToolTip           = LanguageManager.GetText("TooltipLogsCopy");
            CmdLogsSave.ToolTip           = LanguageManager.GetText("TooltipLogsSave");
            CmdLogsSupport.ToolTip        = LanguageManager.GetText("TooltipLogsSupport");

            if (Engine.Storage.GetBool("remember"))
            {
                ChkRemember.State       = NSCellStateValue.On;
                TxtLogin.StringValue    = Engine.Storage.Get("login");
                TxtPassword.StringValue = Engine.Storage.Get("password");
            }

            CmdMainMenu.Activated += (object sender, EventArgs e) =>
            {
                CoreGraphics.CGPoint p = new CoreGraphics.CGPoint(this.Window.Frame.Left + 10, this.Window.Frame.Bottom - 40);
                //CoreGraphics.CGPoint p = new CoreGraphics.CGPoint(CmdMainMenu.Frame.Left + 10, CmdMainMenu.Frame.Top + 10);
                MnuTray.PopUpMenu(MnuTrayStatus, p, null);
            };

            CmdUpdater.Activated += (object sender, EventArgs e) =>
            {
                Core.Platform.Instance.OpenUrl(Constants.WebSite + "/" + Core.Platform.Instance.GetCode().ToLowerInvariant() + "/");
            };

            ChkRemember.Activated += (object sender, EventArgs e) =>
            {
                Engine.Storage.SetBool("remember", ChkRemember.State == NSCellStateValue.On);
            };

            CmdLogin.Activated += (object sender, EventArgs e) =>
            {
                if (Engine.IsLogged() == false)
                {
                    Login();
                }
                else
                {
                    Logout();
                }
            };

            TxtLogin.Activated += (object sender, EventArgs e) =>
            {
                EnabledUI();
            };

            TxtPassword.Activated += (object sender, EventArgs e) =>
            {
                EnabledUI();
            };

            CboKey.Activated += (object sender, EventArgs e) =>
            {
                if (Engine.Instance.Storage.Get("key") != CboKey.SelectedItem.Title)
                {
                    Engine.Instance.Storage.Set("key", CboKey.SelectedItem.Title);
                }
            };

            CmdConnect.Activated += (object sender, EventArgs e) =>
            {
                Connect();
            };

            CmdDisconnect.Activated += (object sender, EventArgs e) =>
            {
                Disconnect();
            };

            CmdCancel.Activated += (object sender, EventArgs e) =>
            {
                Disconnect();
            };

            CmdNetworkLock.Activated += (object sender, EventArgs e) =>
            {
                if (Engine.Instance.NetworkLockManager.IsActive())
                {
                    NetworkLockDeactivation();
                }
                else
                {
                    NetworkLockActivation();
                }
            };

            TableProvidersController     = new TableProvidersController(this.TableProviders);
            this.TableProviders.Delegate = new TableProvidersDelegate(this);

            CmdProviderAdd.Activated += (object sender, EventArgs e) =>
            {
                ProviderAdd();
            };

            CmdProviderRemove.Activated += (object sender, EventArgs e) =>
            {
                ProviderRemove();
            };

            CmdProviderEdit.Activated += (object sender, EventArgs e) =>
            {
                ProviderEdit();
            };

            TableProviders.DoubleClick += (object sender, EventArgs e) =>
            {
                ProviderEdit();
            };

            TableServers.DoubleClick += (object sender, EventArgs e) =>
            {
                ConnectManual();
            };

            CmdServersConnect.Activated += (object sender, EventArgs e) =>
            {
                ConnectManual();
            };

            CmdServersWhiteList.Activated += (object sender, EventArgs e) =>
            {
                ServersWhiteList();
            };

            CmdServersBlackList.Activated += (object sender, EventArgs e) =>
            {
                ServersBlackList();
            };

            CmdServersUndefined.Activated += (object sender, EventArgs e) =>
            {
                ServersUndefinedList();
            };

            CmdServersRename.Activated += (object sender, EventArgs e) =>
            {
                ServersRename();
            };

            CmdServersMore.Activated += (object sender, EventArgs e) =>
            {
                ServersMore();
            };

            CmdServersRefresh.Activated += (object sender, EventArgs e) =>
            {
                ServersRefresh();
            };

            MnuServersConnect.Activated += (object sender, EventArgs e) =>
            {
                ConnectManual();
            };

            MnuServersWhitelist.Activated += (object sender, EventArgs e) =>
            {
                ServersWhiteList();
            };

            MnuServersBlacklist.Activated += (object sender, EventArgs e) =>
            {
                ServersBlackList();
            };

            MnuServersUndefined.Activated += (object sender, EventArgs e) =>
            {
                ServersUndefinedList();
            };

            MnuServersRename.Activated += (object sender, EventArgs e) =>
            {
                ServersRename();
            };

            MnuServersMore.Activated += (object sender, EventArgs e) =>
            {
                ServersMore();
            };

            MnuServersRefresh.Activated += (object sender, EventArgs e) =>
            {
                ServersRefresh();
            };

            CmdAreasWhiteList.Activated += (object sender, EventArgs e) =>
            {
                AreasWhiteList();
            };

            CmdAreasBlackList.Activated += (object sender, EventArgs e) =>
            {
                AreasBlackList();
            };

            CmdAreasUndefined.Activated += (object sender, EventArgs e) =>
            {
                AreasUndefinedList();
            };

            MnuAreasWhitelist.Activated += (object sender, EventArgs e) =>
            {
                AreasWhiteList();
            };

            MnuAreasBlacklist.Activated += (object sender, EventArgs e) =>
            {
                AreasBlackList();
            };

            MnuAreasUndefined.Activated += (object sender, EventArgs e) =>
            {
                AreasUndefinedList();
            };

            ChkServersShowAll.Activated += (object sender, EventArgs e) =>
            {
                TableServersController.ShowAll = (ChkServersShowAll.State == NSCellStateValue.On);
                TableServersController.RefreshUI();
            };

            /*
             * Xamarin Bug: https://bugzilla.xamarin.com/show_bug.cgi?id=12467
             * Resolved with delegate
             *
             * TableServers.SelectionDidChange += (object sender, EventArgs e) => {
             *      EnabledUI();
             * };
             *
             * TableAreas.SelectionDidChange += (object sender, EventArgs e) => {
             *      EnabledUI();
             * };
             */

            ChkServersLockCurrent.Activated += (object sender, EventArgs e) =>
            {
                Engine.Storage.SetBool("servers.locklast", ChkServersLockCurrent.State == NSCellStateValue.On);
            };

            CboServersScoringRule.Activated += (object sender, EventArgs e) =>
            {
                Engine.Storage.Set("servers.scoretype", GuiUtils.GetSelected(CboServersScoringRule));

                RefreshUi(Engine.RefreshUiMode.Full);
            };

            CboSpeedResolutions.Activated += (object sender, EventArgs e) =>
            {
                (PnlChart as ChartView).Switch((int)CboSpeedResolutions.IndexOfItem(CboSpeedResolutions.SelectedItem));
            };


            CmdLogsClean.Activated += (object sender, EventArgs e) =>
            {
                TableLogsController.Clear();
            };

            CmdLogsSave.Activated += (object sender, EventArgs e) =>
            {
                LogsDoSave(false);
            };

            CmdLogsCopy.Activated += (object sender, EventArgs e) =>
            {
                LogsDoCopy(false);
            };

            CmdLogsSupport.Activated += (object sender, EventArgs e) =>
            {
                SupportReport();
            };

            MnuLogsCopyAll.Activated += (object sender, EventArgs e) =>
            {
                LogsDoCopy(false);
            };

            MnuLogsSaveAll.Activated += (object sender, EventArgs e) =>
            {
                LogsDoSave(false);
            };
            MnuLogsCopySelected.Activated += (object sender, EventArgs e) =>
            {
                LogsDoCopy(true);
            };
            MnuLogsSaveSelected.Activated += (object sender, EventArgs e) =>
            {
                LogsDoSave(true);
            };

            CmdLogsCommand.Activated += (object sender, EventArgs e) =>
            {
                WindowCommandController w = new WindowCommandController();
                NSApplication.SharedApplication.RunModalForWindow(w.Window);
                if (w.Command != "")
                {
                    UiClient.Instance.Command(w.Command);
                }
            };

            TableServersController     = new TableServersController(this.TableServers);
            this.TableServers.Delegate = new TableServersDelegate(this);

            TableAreasController     = new TableAreasController(this.TableAreas);
            this.TableAreas.Delegate = new TableAreasDelegate(this);

            TableLogsController  = new TableLogsController(this.TableLogs);
            TableStatsController = new TableStatsController(this.TableStats);

            TableStats.DoubleClick += (object sender, EventArgs e) =>
            {
                TableStatsController.DoubleClickItem();
            };

            // Topbar Menu

            MnuTrayStatus.Activated += (object sender, EventArgs e) =>
            {
                Restore(sender);
            };

            MnuTrayConnect.Activated += (object sender, EventArgs e) =>
            {
                if (m_mainActionCommand == "")
                {
                    Restore(sender);
                }
                else
                {
                    UiClient.Instance.Command(m_mainActionCommand);
                }
            };

            MnuTrayAbout.Activated += (object sender, EventArgs e) =>
            {
                ShowAbout();
            };

            MnuTrayPreferences.Activated += (object sender, EventArgs e) =>
            {
                ShowPreferences();
            };

            MnuTrayHome.Activated += (object sender, EventArgs e) =>
            {
                ShowHome();
            };

            MnuTrayClientArea.Activated += (object sender, EventArgs e) =>
            {
                ShowClientArea();
            };

            MnuTrayForwardingPorts.Activated += (object sender, EventArgs e) =>
            {
                ShowForwardingPorts();
            };

            MnuTrayRestore.Activated += (object sender, EventArgs e) =>
            {
                /* // 2.8
                 * if(Window.IsVisible)
                 *      Minimize();
                 * else
                 */
                if (Window.IsVisible)
                {
                    Minimize();
                }
                else
                {
                    Restore(sender);
                }
            };

            MnuTrayQuit.Activated += (object sender, EventArgs e) =>
            {
                Shutdown();
            };

            CboServersScoringRule.ToolTip = LanguageManager.GetText("TooltipServersScoreType");
            CmdAreasBlackList.ToolTip     = LanguageManager.GetText("TooltipAreasBlackList");

            Engine.OnRefreshUi();

            SettingsChanged();

            RequestAttention();
        }
Ejemplo n.º 4
0
        public override void AwakeFromNib()
        {
            base.AwakeFromNib();

            Window.Delegate = new MainWindowDelegate(this);

            Window.AcceptsMouseMovedEvents = true;

            TabProviders = TabMain.Items[1];

            CreateMenuBarIcon();

            ChkRemember.State       = Engine.Storage.GetBool("remember") ? NSCellStateValue.On : NSCellStateValue.Off;
            ChkServersShowAll.State = NSCellStateValue.Off;
            GuiUtils.SetCheck(ChkServersLockCurrent, Engine.Storage.GetBool("servers.locklast"));
            GuiUtils.SetSelected(CboServersScoringRule, Engine.Storage.Get("servers.scoretype"));

            CboSpeedResolutions.RemoveAllItems();
            CboSpeedResolutions.AddItem(Messages.WindowsMainSpeedResolution1);
            CboSpeedResolutions.AddItem(Messages.WindowsMainSpeedResolution2);
            CboSpeedResolutions.AddItem(Messages.WindowsMainSpeedResolution3);
            CboSpeedResolutions.AddItem(Messages.WindowsMainSpeedResolution4);
            CboSpeedResolutions.AddItem(Messages.WindowsMainSpeedResolution5);
            CboSpeedResolutions.SelectItem(0);

            CmdConnect.Title       = Messages.CommandConnect;
            LblConnect.StringValue = Messages.CommandConnectSubtitle;
            CmdDisconnect.Title    = Messages.CommandDisconnect;
            CmdCancel.Title        = Messages.CommandCancel;

            CboServersScoringRule.ToolTip    = Messages.TooltipServersScoreType;
            ChkServersLockCurrent.ToolTip    = Messages.TooltipServersLockCurrent;
            ChkServersShowAll.ToolTip        = Messages.TooltipServersShowAll;
            CmdServersConnect.ToolTip        = Messages.TooltipServersConnect;
            CmdServersUndefined.ToolTip      = Messages.TooltipServersUndefined;
            CmdServersBlackList.ToolTip      = Messages.TooltipServersBlackList;
            CmdServersWhiteList.ToolTip      = Messages.TooltipServersWhiteList;
            CmdServersRename.ToolTip         = Messages.TooltipServersRename;
            CmdServersMore.ToolTip           = Messages.TooltipServersMore;
            CmdServersRefresh.ToolTip        = Messages.TooltipServersRefresh;
            CmdAreasUndefined.ToolTip        = Messages.TooltipAreasUndefined;
            CmdAreasBlackList.ToolTip        = Messages.TooltipAreasBlackList;
            CmdAreasWhiteList.ToolTip        = Messages.TooltipAreasWhiteList;
            CmdLogsOpenVpnManagement.ToolTip = Messages.TooltipLogsOpenVpnManagement;
            CmdLogsClean.ToolTip             = Messages.TooltipLogsClean;
            CmdLogsCopy.ToolTip    = Messages.TooltipLogsCopy;
            CmdLogsSave.ToolTip    = Messages.TooltipLogsSave;
            CmdLogsSupport.ToolTip = Messages.TooltipLogsSupport;

            if (Engine.Storage.GetBool("remember"))
            {
                ChkRemember.State       = NSCellStateValue.On;
                TxtLogin.StringValue    = Engine.Storage.Get("login");
                TxtPassword.StringValue = Engine.Storage.Get("password");
            }



            ChkRemember.Activated += (object sender, EventArgs e) =>
            {
                Engine.Storage.SetBool("remember", ChkRemember.State == NSCellStateValue.On);
            };

            CmdLogin.Activated += (object sender, EventArgs e) =>
            {
                if (Engine.IsLogged() == false)
                {
                    Login();
                }
                else
                {
                    Logout();
                }
            };

            TxtLogin.Activated += (object sender, EventArgs e) =>
            {
                EnabledUI();
            };

            TxtPassword.Activated += (object sender, EventArgs e) =>
            {
                EnabledUI();
            };

            CboKey.Activated += (object sender, EventArgs e) =>
            {
                Engine.Instance.Storage.Set("key", CboKey.SelectedItem.Title);
            };

            CmdConnect.Activated += (object sender, EventArgs e) =>
            {
                Connect();
            };

            CmdDisconnect.Activated += (object sender, EventArgs e) =>
            {
                Disconnect();
            };

            CmdCancel.Activated += (object sender, EventArgs e) =>
            {
                Disconnect();
            };

            CmdNetworkLock.Activated += (object sender, EventArgs e) =>
            {
                if (Engine.Instance.NetworkLockManager.IsActive())
                {
                    NetworkLockDeactivation();
                }
                else
                {
                    NetworkLockActivation();
                }
            };

            TableProvidersController     = new TableProvidersController(this.TableProviders);
            this.TableProviders.Delegate = new TableProvidersDelegate(this);

            CmdProviderAdd.Activated += (object sender, EventArgs e) =>
            {
                ProviderAdd();
            };

            CmdProviderRemove.Activated += (object sender, EventArgs e) =>
            {
                ProviderRemove();
            };

            CmdProviderEdit.Activated += (object sender, EventArgs e) =>
            {
                ProviderEdit();
            };

            TableProviders.DoubleClick += (object sender, EventArgs e) =>
            {
                ProviderEdit();
            };

            TableServers.DoubleClick += (object sender, EventArgs e) =>
            {
                ConnectManual();
            };

            CmdServersConnect.Activated += (object sender, EventArgs e) =>
            {
                ConnectManual();
            };

            CmdServersWhiteList.Activated += (object sender, EventArgs e) =>
            {
                ServersWhiteList();
            };

            CmdServersBlackList.Activated += (object sender, EventArgs e) =>
            {
                ServersBlackList();
            };

            CmdServersUndefined.Activated += (object sender, EventArgs e) =>
            {
                ServersUndefinedList();
            };

            CmdServersRename.Activated += (object sender, EventArgs e) =>
            {
                ServersRename();
            };

            CmdServersMore.Activated += (object sender, EventArgs e) =>
            {
                ServersMore();
            };

            CmdServersRefresh.Activated += (object sender, EventArgs e) =>
            {
                ServersRefresh();
            };

            MnuServersConnect.Activated += (object sender, EventArgs e) =>
            {
                ConnectManual();
            };

            MnuServersWhitelist.Activated += (object sender, EventArgs e) =>
            {
                ServersWhiteList();
            };

            MnuServersBlacklist.Activated += (object sender, EventArgs e) =>
            {
                ServersBlackList();
            };

            MnuServersUndefined.Activated += (object sender, EventArgs e) =>
            {
                ServersUndefinedList();
            };

            MnuServersRename.Activated += (object sender, EventArgs e) =>
            {
                ServersRename();
            };

            MnuServersMore.Activated += (object sender, EventArgs e) =>
            {
                ServersMore();
            };

            MnuServersRefresh.Activated += (object sender, EventArgs e) =>
            {
                ServersRefresh();
            };

            CmdAreasWhiteList.Activated += (object sender, EventArgs e) =>
            {
                AreasWhiteList();
            };

            CmdAreasBlackList.Activated += (object sender, EventArgs e) =>
            {
                AreasBlackList();
            };

            CmdAreasUndefined.Activated += (object sender, EventArgs e) =>
            {
                AreasUndefinedList();
            };

            MnuAreasWhitelist.Activated += (object sender, EventArgs e) =>
            {
                AreasWhiteList();
            };

            MnuAreasBlacklist.Activated += (object sender, EventArgs e) =>
            {
                AreasBlackList();
            };

            MnuAreasUndefined.Activated += (object sender, EventArgs e) =>
            {
                AreasUndefinedList();
            };

            ChkServersShowAll.Activated += (object sender, EventArgs e) =>
            {
                TableServersController.ShowAll = (ChkServersShowAll.State == NSCellStateValue.On);
                TableServersController.RefreshUI();
            };

            /*
             * Xamarin Bug: https://bugzilla.xamarin.com/show_bug.cgi?id=12467
             * Resolved with delegate
             *
             * TableServers.SelectionDidChange += (object sender, EventArgs e) => {
             *      EnabledUI();
             * };
             *
             * TableAreas.SelectionDidChange += (object sender, EventArgs e) => {
             *      EnabledUI();
             * };
             */

            ChkServersLockCurrent.Activated += (object sender, EventArgs e) =>
            {
                Engine.Storage.SetBool("servers.locklast", ChkServersLockCurrent.State == NSCellStateValue.On);
            };

            CboServersScoringRule.Activated += (object sender, EventArgs e) =>
            {
                Engine.Storage.Set("servers.scoretype", GuiUtils.GetSelected(CboServersScoringRule));

                RefreshUi(Engine.RefreshUiMode.Full);
            };

            CboSpeedResolutions.Activated += (object sender, EventArgs e) =>
            {
                (PnlChart as ChartView).Switch((int)CboSpeedResolutions.IndexOfItem(CboSpeedResolutions.SelectedItem));
            };


            CmdLogsClean.Activated += (object sender, EventArgs e) =>
            {
                TableLogsController.Clear();
            };

            CmdLogsSave.Activated += (object sender, EventArgs e) =>
            {
                LogsDoSave(false);
            };

            CmdLogsCopy.Activated += (object sender, EventArgs e) =>
            {
                LogsDoCopy(false);
            };

            CmdLogsSupport.Activated += (object sender, EventArgs e) =>
            {
                SupportReport();
            };

            MnuLogsCopyAll.Activated += (object sender, EventArgs e) =>
            {
                LogsDoCopy(false);
            };

            MnuLogsSaveAll.Activated += (object sender, EventArgs e) =>
            {
                LogsDoSave(false);
            };
            MnuLogsCopySelected.Activated += (object sender, EventArgs e) =>
            {
                LogsDoCopy(true);
            };
            MnuLogsSaveSelected.Activated += (object sender, EventArgs e) =>
            {
                LogsDoSave(true);
            };

            CmdLogsOpenVpnManagement.Activated += (object sender, EventArgs e) =>
            {
                if (Engine.IsConnected())
                {
                    WindowOpenVpnManagementCommandController w = new WindowOpenVpnManagementCommandController();
                    NSApplication.SharedApplication.RunModalForWindow(w.Window);
                    if (w.Command != "")
                    {
                        Core.UI.Actions.SendOpenVpnManagementCommand(w.Command);
                    }
                }
            };

            TableServersController     = new TableServersController(this.TableServers);
            this.TableServers.Delegate = new TableServersDelegate(this);

            TableAreasController     = new TableAreasController(this.TableAreas);
            this.TableAreas.Delegate = new TableAreasDelegate(this);

            TableLogsController  = new TableLogsController(this.TableLogs);
            TableStatsController = new TableStatsController(this.TableStats);

            TableStats.DoubleClick += (object sender, EventArgs e) =>
            {
                TableStatsController.DoubleClickItem();
            };

            // Topbar Menu

            MnuTrayStatus.Activated += (object sender, EventArgs e) =>
            {
                Restore(sender);
            };

            MnuTrayConnect.Activated += (object sender, EventArgs e) =>
            {
                if (Engine.IsWaiting())
                {
                    Disconnect();
                }
                else if (Engine.IsConnected())
                {
                    Disconnect();
                }
                else if (Engine.CanConnect())
                {
                    Connect();
                }
                else
                {
                    Restore(sender);
                }
            };

            MnuTrayAbout.Activated += (object sender, EventArgs e) =>
            {
                ShowAbout();
            };

            MnuTrayPreferences.Activated += (object sender, EventArgs e) =>
            {
                ShowPreferences();
            };

            MnuTrayHome.Activated += (object sender, EventArgs e) =>
            {
                ShowHome();
            };

            MnuTrayClientArea.Activated += (object sender, EventArgs e) =>
            {
                ShowClientArea();
            };

            MnuTrayForwardingPorts.Activated += (object sender, EventArgs e) =>
            {
                ShowForwardingPorts();
            };

            MnuTraySpeedTest.Activated += (object sender, EventArgs e) =>
            {
                ShowSpeedTest();
            };

            MnuTrayRestore.Activated += (object sender, EventArgs e) =>
            {
                /* // 2.8
                 * if(Window.IsVisible)
                 *      Minimize();
                 * else
                 */
                Restore(sender);
            };

            MnuTrayQuit.Activated += (object sender, EventArgs e) =>
            {
                Shutdown();
            };

            CboServersScoringRule.ToolTip = Messages.TooltipServersScoreType;
            CmdAreasBlackList.ToolTip     = Messages.TooltipAreasBlackList;

            Engine.MainWindow = this;
            Engine.UiStart();

            Engine.OnRefreshUi();

            SettingsChanged();

            RequestAttention();
        }
Ejemplo n.º 5
0
        void ReadOptions()
        {
            Storage s = Engine.Instance.Storage;

            // General

            GuiUtils.SetCheck(ChkConnect, s.GetBool("connect"));
            GuiUtils.SetCheck(ChkNetLock, s.GetBool("netlock"));

            GuiUtils.SetCheck(ChkGeneralStartLast, s.GetBool("servers.startlast"));
            GuiUtils.SetCheck(ChkGeneralOsxVisible, s.GetBool("gui.osx.visible"));
            // GuiUtils.SetCheck (ChkGeneralOsxDock, s.GetBool ("gui.osx.dock")); // See this FAQ: https://airvpn.org/topic/13331-its-possible-to-hide-the-icon-in-dock-bar-under-os-x/
            GuiUtils.SetCheck(ChkGeneralOsxNotifications, s.GetBool("gui.osx.notifications"));
            GuiUtils.SetCheck(ChkUiSystemBarShowInfo, s.GetBool("gui.osx.sysbar.show_info"));
            GuiUtils.SetCheck(ChkUiSystemBarShowSpeed, s.GetBool("gui.osx.sysbar.show_speed"));
            GuiUtils.SetCheck(ChkUiSystemBarShowServer, s.GetBool("gui.osx.sysbar.show_server"));

            GuiUtils.SetCheck(ChkExitConfirm, s.GetBool("gui.exit_confirm"));

            // UI
            string uiUnit = s.Get("ui.unit");

            if (uiUnit == "bytes")
            {
                GuiUtils.SetSelected(CboUiUnit, Messages.WindowsSettingsUiUnit1);
            }
            else if (uiUnit == "bits")
            {
                GuiUtils.SetSelected(CboUiUnit, Messages.WindowsSettingsUiUnit2);
            }
            else
            {
                GuiUtils.SetSelected(CboUiUnit, Messages.WindowsSettingsUiUnit0);
            }
            GuiUtils.SetCheck(ChkUiIEC, s.GetBool("ui.iec"));

            /*
             * string interfaceMode = GuiUtils.InterfaceColorMode ();
             * if (interfaceMode == "Dark")
             *      GuiUtils.SetSelected (CboGeneralOsxInterfaceStyle,"Dark");
             * else
             *      GuiUtils.SetSelected (CboGeneralOsxInterfaceStyle,"Default");
             */

            // Protocols
            String protocol = s.Get("mode.protocol").ToUpperInvariant();
            int    port     = s.GetInt("mode.port");
            int    entryIP  = s.GetInt("mode.alt");

            if (protocol == "AUTO")
            {
                GuiUtils.SetCheck(ChkProtocolsAutomatic, true);
            }
            else
            {
                bool found = false;

                int iRow = 0;
                foreach (TableProtocolsControllerItem itemProtocol in TableProtocolsController.Items)
                {
                    if ((itemProtocol.Protocol == protocol) &&
                        (itemProtocol.Port == port) &&
                        (itemProtocol.IP == entryIP))
                    {
                        found = true;
                        TableProtocols.SelectRow(iRow, false);
                        TableProtocols.ScrollRowToVisible(iRow);
                        break;
                    }
                    iRow++;
                }

                if (found == false)
                {
                    GuiUtils.SetCheck(ChkProtocolsAutomatic, true);
                }
                else
                {
                    GuiUtils.SetCheck(ChkProtocolsAutomatic, false);
                }
            }

            // Proxy

            GuiUtils.SetSelected(CboProxyType, s.Get("proxy.mode"));
            if (s.Get("proxy.when") == "always")
            {
                GuiUtils.SetSelected(CboProxyWhen, Messages.WindowsSettingsProxyWhenAlways);
            }
            else if (s.Get("proxy.when") == "web")
            {
                GuiUtils.SetSelected(CboProxyWhen, Messages.WindowsSettingsProxyWhenWeb);
            }
            else if (s.Get("proxy.when") == "openvpn")
            {
                GuiUtils.SetSelected(CboProxyWhen, Messages.WindowsSettingsProxyWhenOpenVPN);
            }
            else if (s.Get("proxy.when") == "none")
            {
                GuiUtils.SetSelected(CboProxyWhen, Messages.WindowsSettingsProxyWhenNone);
            }
            else
            {
                GuiUtils.SetSelected(CboProxyWhen, Messages.WindowsSettingsProxyWhenAlways);
            }
            TxtProxyHost.StringValue = s.Get("proxy.host");
            TxtProxyPort.StringValue = s.Get("proxy.port");
            GuiUtils.SetSelected(CboProxyAuthentication, s.Get("proxy.auth"));
            TxtProxyLogin.StringValue              = s.Get("proxy.login");
            TxtProxyPassword.StringValue           = s.Get("proxy.password");
            TxtProxyTorControlPort.StringValue     = s.Get("proxy.tor.control.port");
            TxtProxyTorControlPassword.StringValue = s.Get("proxy.tor.control.password");

            // Routes
            GuiUtils.SetSelected(CboRoutesOtherwise, RouteDirectionToDescription(s.Get("routes.default")));

            string routes = s.Get("routes.custom");

            string[] routes2 = routes.Split(';');
            foreach (string route in routes2)
            {
                string[] routeEntries = route.Split(',');
                if (routeEntries.Length < 2)
                {
                    continue;
                }

                TableRoutingControllerItem item = new TableRoutingControllerItem();
                item.Ip     = routeEntries[0];
                item.Action = routeEntries[1];
                item.Icon   = routeEntries[1];
                if (routeEntries.Length == 3)
                {
                    item.Notes = routeEntries[2];
                }
                TableRoutingController.Items.Add(item);
            }

            TableRoutingController.RefreshUI();

            // Advanced - General

            GuiUtils.SetCheck(ChkAdvancedExpertMode, s.GetBool("advanced.expert"));
            GuiUtils.SetCheck(ChkAdvancedCheckRoute, s.GetBool("advanced.check.route"));
            string ipV6Mode = s.Get("ipv6.mode");

            if (ipV6Mode == "none")
            {
                GuiUtils.SetSelected(CboIpV6, "None");
            }
            else if (ipV6Mode == "disable")
            {
                GuiUtils.SetSelected(CboIpV6, "Disable");
            }
            else
            {
                GuiUtils.SetSelected(CboIpV6, "None");
            }

            GuiUtils.SetCheck(ChkAdvancedPingerEnabled, s.GetBool("pinger.enabled"));
            GuiUtils.SetCheck(ChkRouteRemoveDefaultGateway, s.GetBool("routes.remove_default"));

            TxtAdvancedOpenVpnPath.StringValue = s.Get("tools.openvpn.path");
            GuiUtils.SetCheck(ChkAdvancedSkipAlreadyRun, s.GetBool("advanced.skip_alreadyrun"));
            GuiUtils.SetCheck(ChkAdvancedProviders, s.GetBool("advanced.providers"));

            int manifestRefresh = s.GetInt("advanced.manifest.refresh");

            if (manifestRefresh == 60)
            {
                GuiUtils.SetSelected(CboAdvancedManifestRefresh, "Every one hour");
            }
            else if (manifestRefresh == 10)
            {
                GuiUtils.SetSelected(CboAdvancedManifestRefresh, "Every ten minute");
            }
            else if (manifestRefresh == 1)
            {
                GuiUtils.SetSelected(CboAdvancedManifestRefresh, "Every minute");
            }
            else if (manifestRefresh == 0)
            {
                GuiUtils.SetSelected(CboAdvancedManifestRefresh, "Never");
            }
            else
            {
                GuiUtils.SetSelected(CboAdvancedManifestRefresh, "Automatic");
            }

            int openVpnSndBuf = s.GetInt("openvpn.sndbuf");

            if (openVpnSndBuf == -2)
            {
                GuiUtils.SetSelected(CboOpenVpnSndBuf, Messages.Automatic);
            }
            else if (openVpnSndBuf == -1)
            {
                GuiUtils.SetSelected(CboOpenVpnSndBuf, Messages.WindowsSettingsOpenVpnDefault);
            }
            else if (openVpnSndBuf == 1024 * 8)
            {
                GuiUtils.SetSelected(CboOpenVpnSndBuf, "8 KB");
            }
            else if (openVpnSndBuf == 1024 * 16)
            {
                GuiUtils.SetSelected(CboOpenVpnSndBuf, "16 KB");
            }
            else if (openVpnSndBuf == 1024 * 32)
            {
                GuiUtils.SetSelected(CboOpenVpnSndBuf, "32 KB");
            }
            else if (openVpnSndBuf == 1024 * 64)
            {
                GuiUtils.SetSelected(CboOpenVpnSndBuf, "64 KB");
            }
            else if (openVpnSndBuf == 1024 * 128)
            {
                GuiUtils.SetSelected(CboOpenVpnSndBuf, "128 KB");
            }
            else if (openVpnSndBuf == 1024 * 256)
            {
                GuiUtils.SetSelected(CboOpenVpnSndBuf, "256 KB");
            }
            else if (openVpnSndBuf == 1024 * 512)
            {
                GuiUtils.SetSelected(CboOpenVpnSndBuf, "512 KB");
            }

            int openVpnRcvBuf = s.GetInt("openvpn.rcvbuf");

            if (openVpnRcvBuf == -2)
            {
                GuiUtils.SetSelected(CboOpenVpnRcvBuf, Messages.Automatic);
            }
            else if (openVpnRcvBuf == -1)
            {
                GuiUtils.SetSelected(CboOpenVpnRcvBuf, Messages.WindowsSettingsOpenVpnDefault);
            }
            else if (openVpnRcvBuf == 1024 * 8)
            {
                GuiUtils.SetSelected(CboOpenVpnRcvBuf, "8 KB");
            }
            else if (openVpnRcvBuf == 1024 * 16)
            {
                GuiUtils.SetSelected(CboOpenVpnRcvBuf, "16 KB");
            }
            else if (openVpnRcvBuf == 1024 * 32)
            {
                GuiUtils.SetSelected(CboOpenVpnRcvBuf, "32 KB");
            }
            else if (openVpnRcvBuf == 1024 * 64)
            {
                GuiUtils.SetSelected(CboOpenVpnRcvBuf, "64 KB");
            }
            else if (openVpnRcvBuf == 1024 * 128)
            {
                GuiUtils.SetSelected(CboOpenVpnRcvBuf, "128 KB");
            }
            else if (openVpnRcvBuf == 1024 * 256)
            {
                GuiUtils.SetSelected(CboOpenVpnRcvBuf, "256 KB");
            }
            else if (openVpnRcvBuf == 1024 * 512)
            {
                GuiUtils.SetSelected(CboOpenVpnRcvBuf, "512 KB");
            }

            // Advanced - DNS

            string dnsMode = s.Get("dns.mode");

            if (dnsMode == "none")
            {
                GuiUtils.SetSelected(CboDnsSwitchMode, "Disabled");
            }
            else
            {
                GuiUtils.SetSelected(CboDnsSwitchMode, "Automatic");
            }

            GuiUtils.SetCheck(ChkDnsCheck, s.GetBool("dns.check"));

            TableDnsServersController.Clear();
            string[] dnsServers = s.Get("dns.servers").Split(',');
            foreach (string dnsServer in dnsServers)
            {
                if (IpAddress.IsIP(dnsServer))
                {
                    TableDnsServersController.Add(dnsServer);
                }
            }

            // Advanced - Lock
            string lockMode = s.Get("netlock.mode");

            GuiUtils.SetSelected(CboLockMode, "None");
            if (lockMode == "auto")
            {
                GuiUtils.SetSelected(CboLockMode, "Automatic");
            }
            else
            {
                foreach (NetworkLockPlugin lockPlugin in Engine.Instance.NetworkLockManager.Modes)
                {
                    if (lockPlugin.GetCode() == lockMode)
                    {
                        GuiUtils.SetSelected(CboLockMode, lockPlugin.GetName());
                    }
                }
            }
            GuiUtils.SetCheck(ChkLockAllowPrivate, s.GetBool("netlock.allow_private"));
            GuiUtils.SetCheck(ChkLockAllowPing, s.GetBool("netlock.allow_ping"));
            GuiUtils.SetCheck(ChkLockAllowDNS, s.GetBool("netlock.allow_dns"));
            TxtLockAllowedIPS.StringValue = s.Get("netlock.allowed_ips");

            // Advanced - Logging
            GuiUtils.SetCheck(ChkLoggingEnabled, s.GetBool("log.file.enabled"));
            GuiUtils.SetCheck(ChkLogLevelDebug, s.GetBool("log.level.debug"));
            TxtLoggingPath.StringValue = s.Get("log.file.path");

            // Advanced - OVPN Directives
            GuiUtils.SetSelected(CboOpenVpnDirectivesSkipDefault, (s.GetBool("openvpn.skip_defaults") ? Messages.WindowsSettingsOpenVpnDirectivesDefaultSkip2 : Messages.WindowsSettingsOpenVpnDirectivesDefaultSkip1));
            TxtAdvancedOpenVpnDirectivesDefault.StringValue = s.Get("openvpn.directives");
            TxtAdvancedOpenVpnDirectivesCustom.StringValue  = s.Get("openvpn.custom");
            TxtOpenVpnDirectivesCustomPath.StringValue      = s.Get("openvpn.directives.path");

            // Advanced - Events
            ReadOptionsEvent("app.start", 0);
            ReadOptionsEvent("app.stop", 1);
            ReadOptionsEvent("session.start", 2);
            ReadOptionsEvent("session.stop", 3);
            ReadOptionsEvent("vpn.pre", 4);
            ReadOptionsEvent("vpn.up", 5);
            ReadOptionsEvent("vpn.down", 6);

            TableAdvancedEventsController.RefreshUI();
        }