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

            Window.Delegate = new MainWindowDelegate(this);

            Window.AcceptsMouseMovedEvents = true;

            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;
            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();
            };

            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();
                }
            };

            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();
            };

            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();
            };

            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(AirVPN.Core.Engine.RefreshUiMode.Full);
            };

            CboSpeedResolutions.Activated += (object sender, EventArgs e) => {
                (PnlChart as ChartView).Switch(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) =>
            {
                LogsDoCopy(false);
            };

            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.IsLogged())
                {
                    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();
            };



            Engine.MainWindow = this;

            Engine.OnRefreshUi();

            SettingsChanged();

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

			Window.Delegate = new MainWindowDelegate (this);

			Window.AcceptsMouseMovedEvents = true;

			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;
			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();
			};

			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();
				}
			};

			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 ();
			};

			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 ();
			};

			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 (AirVPN.Core.Engine.RefreshUiMode.Full);
			};

			CboSpeedResolutions.Activated += (object sender, EventArgs e) => {
				(PnlChart as ChartView).Switch(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) =>
			{
				LogsDoCopy(false);
			};		

			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.IsLogged())
				{
					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();
			};

			




			Engine.MainWindow = this;

			Engine.OnRefreshUi ();

			SettingsChanged ();

			RequestAttention ();
		}