コード例 #1
0
        public override void AwakeFromNib()
        {
            base.AwakeFromNib();



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

            TableRoutes.Delegate         = new TableRoutingDelegate(this);
            TableAdvancedEvents.Delegate = new TableAdvancedEventsDelegate(this);

            LblLoggingHelp.StringValue = Messages.WindowsSettingsLoggingHelp;

            TableRoutingController        = new TableRoutingController(this.TableRoutes);
            TableAdvancedEventsController = new TableAdvancedEventsController(this.TableAdvancedEvents);

            CmdSave.Activated += (object sender, EventArgs e) => {
                if (Check())
                {
                    SaveOptions();
                    Close();
                }
            };

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

            CmdGeneralTos.Activated += (object sender, EventArgs e) => {
                WindowTosController tos = new WindowTosController();
                tos.Window.ReleasedWhenClosed = true;
                NSApplication.SharedApplication.RunModalForWindow(tos.Window);
                tos.Window.Close();
            };

            /*
             * CboGeneralOsxInterfaceStyle.RemoveAllItems ();
             * CboGeneralOsxInterfaceStyle.AddItem ("Default");
             * CboGeneralOsxInterfaceStyle.AddItem ("Dark");
             */

            // Modes
            string sshStatus = (Software.SshVersion != "" ? "" : "Not available");

            if (sshStatus != "")
            {
                m_modeSshEnabled = false;
            }
            // TODO: disable ssh & ssl
            string sslStatus = (Software.SslVersion != "" ? "" : "Not available");

            if (sslStatus != "")
            {
                m_modeSslEnabled = false;
            }

            CmdModeHelp.Activated += (object sender, EventArgs e) => {
                Core.UI.Actions.OpenUrlDocsProtocols();
            };

            ChkModeAutomatic.Activated += (object sender, EventArgs e) => {
                m_mode_protocol  = "AUTO";
                m_mode_port      = 443;
                m_mode_alternate = 0;
                ChangeMode();
            };

            ChkModeUdp443.Activated += (object sender, EventArgs e) => {
                m_mode_protocol  = "UDP";
                m_mode_port      = 443;
                m_mode_alternate = 0;
                ChangeMode();
            };

            ChkModeTcp443.Activated += (object sender, EventArgs e) => {
                m_mode_protocol  = "TCP";
                m_mode_port      = 443;
                m_mode_alternate = 0;
                ChangeMode();
            };

            ChkModeUdp80.Activated += (object sender, EventArgs e) =>
            {
                m_mode_protocol  = "UDP";
                m_mode_port      = 80;
                m_mode_alternate = 0;
                ChangeMode();
            };

            ChkModeTcp80.Activated += (object sender, EventArgs e) =>
            {
                m_mode_protocol  = "TCP";
                m_mode_port      = 80;
                m_mode_alternate = 0;
                ChangeMode();
            };

            ChkModeUdp53.Activated += (object sender, EventArgs e) =>
            {
                m_mode_protocol  = "UDP";
                m_mode_port      = 53;
                m_mode_alternate = 0;
                ChangeMode();
            };

            ChkModeTcp53.Activated += (object sender, EventArgs e) =>
            {
                m_mode_protocol  = "TCP";
                m_mode_port      = 53;
                m_mode_alternate = 0;
                ChangeMode();
            };

            ChkModeUdp2018.Activated += (object sender, EventArgs e) =>
            {
                m_mode_protocol  = "UDP";
                m_mode_port      = 2018;
                m_mode_alternate = 0;
                ChangeMode();
            };

            ChkModeTcp2018.Activated += (object sender, EventArgs e) =>
            {
                m_mode_protocol  = "TCP";
                m_mode_port      = 2018;
                m_mode_alternate = 0;
                ChangeMode();
            };



            ChkModeUdp443Alt.Activated += (object sender, EventArgs e) =>
            {
                m_mode_protocol  = "UDP";
                m_mode_port      = 443;
                m_mode_alternate = 1;
                ChangeMode();
            };

            ChkModeUdp80Alt.Activated += (object sender, EventArgs e) =>
            {
                m_mode_protocol  = "UDP";
                m_mode_port      = 80;
                m_mode_alternate = 1;
                ChangeMode();
            };

            ChkModeUdp53Alt.Activated += (object sender, EventArgs e) =>
            {
                m_mode_protocol  = "UDP";
                m_mode_port      = 53;
                m_mode_alternate = 1;
                ChangeMode();
            };

            ChkModeUdp2018Alt.Activated += (object sender, EventArgs e) =>
            {
                m_mode_protocol  = "UDP";
                m_mode_port      = 2018;
                m_mode_alternate = 1;
                ChangeMode();
            };

            ChkModeTcp2018Alt.Activated += (object sender, EventArgs e) =>
            {
                m_mode_protocol  = "TCP";
                m_mode_port      = 2018;
                m_mode_alternate = 1;
                ChangeMode();
            };


            ChkModeSsh22.Activated += (object sender, EventArgs e) => {
                m_mode_protocol  = "SSH";
                m_mode_port      = 22;
                m_mode_alternate = 0;
                ChangeMode();
            };

            ChkModeSsh22Alt.Activated += (object sender, EventArgs e) =>
            {
                m_mode_protocol  = "SSH";
                m_mode_port      = 22;
                m_mode_alternate = 1;
                ChangeMode();
            };

            ChkModeSsh80.Activated += (object sender, EventArgs e) =>
            {
                m_mode_protocol  = "SSH";
                m_mode_port      = 80;
                m_mode_alternate = 1;
                ChangeMode();
            };

            ChkModeSsh53.Activated += (object sender, EventArgs e) =>
            {
                m_mode_protocol  = "SSH";
                m_mode_port      = 53;
                m_mode_alternate = 1;
                ChangeMode();
            };

            ChkModeSsl443.Activated += (object sender, EventArgs e) => {
                m_mode_protocol  = "SSL";
                m_mode_port      = 443;
                m_mode_alternate = 1;
                ChangeMode();
            };

            ChkModeTor.Activated += (object sender, EventArgs e) => {
                m_mode_protocol  = "TOR";
                m_mode_port      = 2018;
                m_mode_alternate = 0;
                ChangeMode();
            };

            CmdModeTorTest.Activated += (object sender, EventArgs e) => {
                string result = TorControl.Test(TxtModeTorHost.StringValue, Conversions.ToInt32(TxtModeTorControlPort.StringValue), TxtModeTorControlPassword.StringValue);
                GuiUtils.MessageBox(result);
            };

            // Proxy
            CboProxyType.Activated += (object sender, EventArgs e) => {
                EnableIde();
            };
            CboProxyAuthentication.Activated += (object sender, EventArgs e) => {
                EnableIde();
            };

            // Routes
            CboRoutesOtherwise.RemoveAllItems();
            CboRoutesOtherwise.AddItem(RouteDirectionToDescription("in"));
            CboRoutesOtherwise.AddItem(RouteDirectionToDescription("out"));
            CboRoutesOtherwise.Activated += (object sender, EventArgs e) => {
                EnableIde();
            };

            TableRoutes.DoubleClick += (object sender, EventArgs e) => {
                RouteEdit();
            };

            CmdRouteAdd.Activated += (object sender, EventArgs e) => {
                RouteAdd();
            };

            CmdRouteRemove.Activated += (object sender, EventArgs e) => {
                RouteRemove();
            };

            CmdRouteEdit.Activated += (object sender, EventArgs e) => {
                RouteEdit();
            };

            // Advanced

            CmdLockHelp.Activated += (object sender, EventArgs e) => {
                Core.UI.Actions.OpenUrlDocsLock();
            };
            CboLockMode.RemoveAllItems();
            CboLockMode.AddItem("None");
            CboLockMode.AddItem("Automatic");
            foreach (NetworkLockPlugin lockPlugin in Engine.Instance.NetworkLockManager.Modes)
            {
                CboLockMode.AddItem(lockPlugin.GetName());
            }

            LblRoutesNetworkLockWarning.StringValue = Messages.WindowsSettingsRouteLockHelp;
            LblLockRoutingOutWarning.StringValue    = Messages.NetworkLockNotAvailableWithRouteOut;

            CboAdvancedManifestRefresh.RemoveAllItems();
            CboAdvancedManifestRefresh.AddItem("Automatic");
            CboAdvancedManifestRefresh.AddItem("Never");
            CboAdvancedManifestRefresh.AddItem("Every minute");
            CboAdvancedManifestRefresh.AddItem("Every ten minute");
            CboAdvancedManifestRefresh.AddItem("Every one hour");

            CmdAdvancedHelp.Activated += (object sender, EventArgs e) => {
                Core.UI.Actions.OpenUrlDocsAdvanced();
            };

            CmdAdvancedOpenVpnPath.Activated += (object sender, EventArgs e) => {
                GuiUtils.SelectFile(this.Window, TxtAdvancedOpenVpnPath);
            };

            TxtLoggingPath.Changed += (object sender, EventArgs e) => {
                RefreshLogPreview();
            };

            TableAdvancedEvents.DoubleClick += (object sender, EventArgs e) => {
                AdvancedEventEdit();
            };

            CmdAdvancedEventsEdit.Activated += (object sender, EventArgs e) => {
                AdvancedEventEdit();
            };

            CmdAdvancedEventsClear.Activated += (object sender, EventArgs e) => {
                AdvancedEventClear();
            };


            ChkAdvancedPingerAlways.Hidden = true;             // TOCLEAN

            ReadOptions();

            EnableIde();

            RefreshLogPreview();
        }
コード例 #2
0
        public override void AwakeFromNib()
        {
            base.AwakeFromNib();

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

            TableTabsController = new TableTabsController(TableTabs, TabMain);

            ChkNetLock.Activated += (object sender, EventArgs e) =>
            {
                if (GuiUtils.GetCheck(ChkNetLock))
                {
                    if ((Engine.Instance as UI.Cocoa.Osx.Engine).MainWindow.NetworkLockKnowledge() == false)
                    {
                        GuiUtils.SetCheck(ChkNetLock, false);
                    }
                }
            };

            TableRoutes.Delegate = new TableRoutingDelegate(this);

            LblDnsServers.StringValue = Messages.WindowsSettingsDnsServers;
            TableDnsServers.Delegate  = new TableDnsServersDelegate(this);

            TableAdvancedEvents.Delegate = new TableAdvancedEventsDelegate(this);

            LblLoggingHelp.StringValue = Messages.WindowsSettingsLoggingHelp;

            TableRoutingController        = new TableRoutingController(this.TableRoutes);
            TableDnsServersController     = new TableDnsServersController(this.TableDnsServers);
            TableAdvancedEventsController = new TableAdvancedEventsController(this.TableAdvancedEvents);

            CmdSave.Activated += (object sender, EventArgs e) =>
            {
                try
                {
                    if (Check())
                    {
                        SaveOptions();
                        Close();
                    }
                }
                catch (Exception ex)
                {
                    Core.Engine.Instance.Logs.Log(LogType.Fatal, ex);
                }
            };

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

            // General

            CmdGeneralTos.Activated += (object sender, EventArgs e) =>
            {
                WindowTosController tos = new WindowTosController();
                tos.Window.ReleasedWhenClosed = true;
                NSApplication.SharedApplication.RunModalForWindow(tos.Window);
                tos.Window.Close();
            };

            CmdResetToDefault.Activated += (object sender, EventArgs e) =>
            {
                if (Engine.Instance.OnAskYesNo(Messages.ResetSettingsConfirm))
                {
                    Engine.Instance.Storage.ResetAll(false);
                    ReadOptions();
                    GuiUtils.MessageBoxInfo(Messages.ResetSettingsDone);
                }
            };

            // UI

            CboUiUnit.RemoveAllItems();
            CboUiUnit.AddItem(Messages.WindowsSettingsUiUnit0);
            CboUiUnit.AddItem(Messages.WindowsSettingsUiUnit1);
            CboUiUnit.AddItem(Messages.WindowsSettingsUiUnit2);

            // Protocols

            CmdProtocolsHelp1.Activated += (object sender, EventArgs e) =>
            {
                Engine.Instance.Command("ui.show.docs.protocols");
            };

            CmdProtocolsHelp2.Activated += (object sender, EventArgs e) =>
            {
                Engine.Instance.Command("ui.show.docs.udp_vs_tcp");
            };

            ChkProtocolsAutomatic.Activated += (object sender, EventArgs e) =>
            {
                EnableIde();
            };

            TableProtocols.Delegate  = new TableProtocolsDelegate(this);
            TableProtocolsController = new TableProtocolsController(this.TableProtocols);

            // Proxy
            CboProxyType.RemoveAllItems();
            CboProxyType.AddItem("None");
            CboProxyType.AddItem("Http");
            CboProxyType.AddItem("Socks");
            CboProxyType.AddItem("Tor");
            CboProxyWhen.RemoveAllItems();
            CboProxyWhen.AddItem(Messages.WindowsSettingsProxyWhenAlways);
            CboProxyWhen.AddItem(Messages.WindowsSettingsProxyWhenWeb);
            CboProxyWhen.AddItem(Messages.WindowsSettingsProxyWhenOpenVPN);
            CboProxyWhen.AddItem(Messages.WindowsSettingsProxyWhenNone);

            CmdProxyTorHelp.Activated += (object sender, EventArgs e) =>
            {
                Engine.Instance.Command("ui.show.docs.tor");
            };
            CboProxyType.Activated += (object sender, EventArgs e) =>
            {
                EnableIde();

                if (GuiUtils.GetSelected(CboProxyType) == "Tor")
                {
                    TxtProxyPort.StringValue = "9150";
                }
                else
                {
                    TxtProxyPort.StringValue = "8080";
                }
            };
            CboProxyAuthentication.Activated += (object sender, EventArgs e) =>
            {
                EnableIde();
            };
            CmdProxyTorTest.Activated += (object sender, EventArgs e) =>
            {
                string result = TorControl.Test(TxtProxyHost.StringValue, Conversions.ToInt32(TxtProxyTorControlPort.StringValue), TxtProxyTorControlPassword.StringValue);
                GuiUtils.MessageBoxInfo(result);
            };

            // Routes
            CboRoutesOtherwise.RemoveAllItems();
            CboRoutesOtherwise.AddItem(RouteDirectionToDescription("in"));
            CboRoutesOtherwise.AddItem(RouteDirectionToDescription("out"));
            CboRoutesOtherwise.Activated += (object sender, EventArgs e) =>
            {
                EnableIde();
            };

            TableRoutes.DoubleClick += (object sender, EventArgs e) =>
            {
                RouteEdit();
            };

            CmdRouteAdd.Activated += (object sender, EventArgs e) =>
            {
                RouteAdd();
            };

            CmdRouteRemove.Activated += (object sender, EventArgs e) =>
            {
                RouteRemove();
            };

            CmdRouteEdit.Activated += (object sender, EventArgs e) =>
            {
                RouteEdit();
            };

            // Advanced - General

            CmdAdvancedHelp.Activated += (object sender, EventArgs e) =>
            {
                Engine.Instance.Command("ui.show.docs.advanced");
            };

            CboIpV6.RemoveAllItems();
            CboIpV6.AddItem("None");
            CboIpV6.AddItem("Disable");

            CboAdvancedManifestRefresh.RemoveAllItems();
            CboAdvancedManifestRefresh.AddItem("Automatic");
            CboAdvancedManifestRefresh.AddItem("Never");
            CboAdvancedManifestRefresh.AddItem("Every minute");
            CboAdvancedManifestRefresh.AddItem("Every ten minute");
            CboAdvancedManifestRefresh.AddItem("Every one hour");

            LblOpenVpnRcvBuf.StringValue = Messages.WindowsSettingsOpenVpnRcvBuf + ":";
            LblOpenVpnSndBuf.StringValue = Messages.WindowsSettingsOpenVpnSndBuf + ":";
            CboOpenVpnRcvBuf.RemoveAllItems();
            CboOpenVpnRcvBuf.AddItem(Messages.Automatic);
            CboOpenVpnRcvBuf.AddItem(Messages.WindowsSettingsOpenVpnDefault);
            CboOpenVpnRcvBuf.AddItem("8 KB");
            CboOpenVpnRcvBuf.AddItem("16 KB");
            CboOpenVpnRcvBuf.AddItem("32 KB");
            CboOpenVpnRcvBuf.AddItem("64 KB");
            CboOpenVpnRcvBuf.AddItem("128 KB");
            CboOpenVpnRcvBuf.AddItem("256 KB");
            CboOpenVpnRcvBuf.AddItem("512 KB");
            CboOpenVpnSndBuf.RemoveAllItems();
            CboOpenVpnSndBuf.AddItem(Messages.Automatic);
            CboOpenVpnSndBuf.AddItem(Messages.WindowsSettingsOpenVpnDefault);
            CboOpenVpnSndBuf.AddItem("8 KB");
            CboOpenVpnSndBuf.AddItem("16 KB");
            CboOpenVpnSndBuf.AddItem("32 KB");
            CboOpenVpnSndBuf.AddItem("64 KB");
            CboOpenVpnSndBuf.AddItem("128 KB");
            CboOpenVpnSndBuf.AddItem("256 KB");
            CboOpenVpnSndBuf.AddItem("512 KB");

            CmdAdvancedOpenVpnPath.Activated += (object sender, EventArgs e) =>
            {
                GuiUtils.SelectFile(this.Window, TxtAdvancedOpenVpnPath);
            };


            // Advanced - DNS
            TableDnsServers.DoubleClick += (object sender, EventArgs e) =>
            {
                DnsServersEdit();
            };

            CmdDnsAdd.Activated += (object sender, EventArgs e) =>
            {
                DnsServersAdd();
            };

            CmdDnsRemove.Activated += (object sender, EventArgs e) =>
            {
                DnsServersRemove();
            };

            CmdDnsEdit.Activated += (object sender, EventArgs e) =>
            {
                DnsServersEdit();
            };

            // Advanced - Net Lock
            CmdLockHelp.Activated += (object sender, EventArgs e) =>
            {
                Engine.Instance.Command("ui.show.docs.lock");
            };
            CboLockMode.RemoveAllItems();
            CboLockMode.AddItem("None");
            CboLockMode.AddItem("Automatic");
            foreach (NetworkLockPlugin lockPlugin in Engine.Instance.NetworkLockManager.Modes)
            {
                CboLockMode.AddItem(lockPlugin.GetName());
            }

            LblRoutesNetworkLockWarning.StringValue = Messages.WindowsSettingsRouteLockHelp;
            LblLockRoutingOutWarning.StringValue    = Messages.NetworkLockNotAvailableWithRouteOut;

            // Advanced - Logging

            TxtLoggingPath.Changed += (object sender, EventArgs e) =>
            {
                RefreshLogPreview();
            };

            CmdLoggingOpen.Activated += (object sender, EventArgs e) =>
            {
                List <string> paths = Engine.Instance.Logs.ParseLogFilePath(TxtLoggingPath.StringValue);
                foreach (string path in paths)
                {
                    if (Core.Platform.Instance.OpenDirectoryInFileManager(path) == false)
                    {
                        GuiUtils.MessageBoxError(MessagesFormatter.Format(Messages.WindowsSettingsLogsCannotOpenDirectory, path));
                    }
                }
            };

            // Directives
            CboOpenVpnDirectivesSkipDefault.RemoveAllItems();
            CboOpenVpnDirectivesSkipDefault.AddItem(Messages.WindowsSettingsOpenVpnDirectivesDefaultSkip1);
            CboOpenVpnDirectivesSkipDefault.AddItem(Messages.WindowsSettingsOpenVpnDirectivesDefaultSkip2);
            CmdOpenVpnDirectivesHelp.Activated += (object sender, EventArgs e) =>
            {
                Engine.Instance.Command("ui.show.docs.directives");
            };
            CmdOpenVpnDirectivesCustomPathBrowse.Activated += (object sender, EventArgs e) =>
            {
                GuiUtils.SelectFile(this.Window, TxtOpenVpnDirectivesCustomPath);
            };

            // Advanced - Events

            TableAdvancedEvents.DoubleClick += (object sender, EventArgs e) =>
            {
                AdvancedEventEdit();
            };

            CmdAdvancedEventsEdit.Activated += (object sender, EventArgs e) =>
            {
                AdvancedEventEdit();
            };

            CmdAdvancedEventsClear.Activated += (object sender, EventArgs e) =>
            {
                AdvancedEventClear();
            };

            ReadOptions();

            EnableIde();

            RefreshLogPreview();
        }