namespace TimelapseApi; using System.Diagnostics; using Eto.Forms; internal class FrameHandlerSettingsForm : Dialog { internal class FrameHandlerSettingsCollection { public FrameHandlerSettingsCollection(List img) { Items=img; } public CheckBox? OverlayEnabled {get;set;} public CheckBox? BlockEnabled {get;set;} public List Items {get;set;} } internal class FrameHandlerSettings { public Guid Guid; CheckBox? cb; private bool? _chk; public FrameHandlerSettings(TimelapseExtension ext,string handlerName,bool overlay,bool block) { ExtensionName=ext.Name; Guid=ext.Id; HandlerName = handlerName; OverlayChecked=overlay; BlockChecked=block; } public string HandlerName {get;set;} public string ExtensionName {get;set;} public bool OverlayChecked {get;set;} public bool BlockChecked {get;set;} } public FrameHandlerSettingsForm(FrameHandlerSettingsCollection col) { if(col.OverlayEnabled == null || col.BlockEnabled == null) return; Width = 640; Height=240; Resizable=true; Title="Frame Handler Settings"; Button okBtn = new Button{Text="OK"}; okBtn.Click +=(sender,e)=>{ this.Close(); }; DynamicLayout lyt=new DynamicLayout(); GridView itemsList=new GridView(); itemsList.Columns.Add(new GridColumn{ HeaderText="HandlerName", DataCell=new TextBoxCell("HandlerName"), Editable=false }); itemsList.Columns.Add(new GridColumn{ HeaderText="Extension Name", DataCell=new TextBoxCell("ExtensionName"), Editable=false }); itemsList.Columns.Add(new GridColumn{ HeaderText="Allow Overlay", DataCell=new CheckBoxCell("OverlayChecked"), Editable=true }); itemsList.Columns.Add(new GridColumn{ HeaderText="Allow Block from Recording frame", DataCell=new CheckBoxCell("BlockChecked"), Editable=true }); itemsList.DataStore=col.Items; col.OverlayEnabled.Text="Allow Overlay"; col.BlockEnabled.Text="Allow Block from Recording frame"; lyt.BeginVertical(); lyt.BeginHorizontal(); lyt.Add(col.OverlayEnabled,true); lyt.EndBeginHorizontal(); lyt.Add(col.BlockEnabled,true); lyt.EndBeginHorizontal(); lyt.Add(itemsList,true,true); lyt.EndBeginHorizontal(); lyt.Add(okBtn,true); lyt.EndHorizontal(); lyt.EndVertical(); Content=lyt; } } internal class TimelapseSettings : Dialog { public TimelapseSettings(Api api) { bool overLayBoxState=api.Model.canOverlayVideo; bool blockBoxState=api.Model.canBlockFrames; List imgs=new List(); List ext=new List(); var coll=new FrameHandlerSettingsForm.FrameHandlerSettingsCollection(imgs); foreach(var item in api._frameHandlers) { if(!ext.Contains(item.Extension)) { imgs.Add(new FrameHandlerSettingsForm.FrameHandlerSettings(item.Extension,item.HandlerName,!api.Model.deniedOverlayExtensions.Contains(item.Extension.Id),!api.Model.deniedBlockExtensions.Contains(item.Extension.Id))); ext.Add(item.Extension); } } ext.Clear(); Width = 320; Height=240; Title="Settings"; Button ExtensionsFrameHandler=new Button{ Text="Frame Handler Settings" }; Button configFolder = new Button{ Text="Configuration folder" }; Button installExtension = new Button{ Text="Install Extension" }; CheckBox enableExt=new CheckBox(); enableExt.Text="Add extensions on install"; enableExt.Checked = api.Model.addExtensionOnInstall; installExtension.Click += async(sender,e)=>{ using(var ofd=new OpenFileDialog()) { ofd.MultiSelect=true; ofd.Filters.Add(new FileFilter("Timelapse Extension",".tle",".zip")); if(ofd.ShowDialog(this)==DialogResult.Ok) { foreach(var ext in ofd.Filenames) { await ExtensionLoader.InstallExtension(ext,enableExt.Checked.GetValueOrDefault()); } } } }; CheckBox enableServer = new CheckBox(); enableServer.Text="Enable webserver"; enableServer.Checked=api.Model.enableWebServer; configFolder.Click +=(sender,e)=>{ using(Process p=new Process()){ p.StartInfo = new ProcessStartInfo(Api.GetInternalFile()); p.StartInfo.UseShellExecute=true; p.Start(); } }; ExtensionsFrameHandler.Click +=(sender,e)=>{ coll.OverlayEnabled=new CheckBox(); coll.BlockEnabled=new CheckBox(); coll.OverlayEnabled.Checked=overLayBoxState; coll.BlockEnabled.Checked=blockBoxState; using(var img=new FrameHandlerSettingsForm(coll)) img.ShowModal(this); overLayBoxState = coll.OverlayEnabled.Checked.GetValueOrDefault(); blockBoxState = coll.BlockEnabled.Checked.GetValueOrDefault(); /* Console.WriteLine($"Global overlay state: {overLayBoxState}"); Console.WriteLine($"Global block state: {blockBoxState}"); foreach(var item in coll.Items) { Console.WriteLine(); Console.WriteLine($"Extension name: {item.ExtensionName}"); Console.WriteLine($"Handler name: {item.HandlerName}"); Console.WriteLine($"Overlay state: {item.OverlayChecked}"); Console.WriteLine($"Block state: {item.BlockChecked}"); }*/ }; DynamicLayout lyt1=new DynamicLayout(); Scrollable scrollable=new Scrollable(); DynamicLayout lyt2=new DynamicLayout(); scrollable.Content=lyt2; lyt2.BeginVertical(); lyt2.AddRow(ExtensionsFrameHandler); lyt2.AddRow(configFolder); StackLayout lyt=new StackLayout(); lyt.Orientation= Orientation.Horizontal; lyt.Items.Add(enableServer); NumericStepper stepper=new NumericStepper(); stepper.MinValue=0; stepper.MaxValue=65535; stepper.Value = api.Model.timelapsePort; lyt.Items.Add(stepper); lyt2.AddRow(lyt); lyt2.AddRow(installExtension); lyt2.AddRow(enableExt); lyt2.AddRow(null); lyt2.EndVertical(); lyt1.BeginVertical(); lyt1.BeginHorizontal(); lyt1.Add(scrollable,true,true); Button saveBtn = new Button {Text="Save"}; saveBtn.Click += (sender,e)=>{ api.Model.canBlockFrames=blockBoxState; api.Model.canOverlayVideo=overLayBoxState; api.Model.deniedBlockExtensions.Clear(); api.Model.deniedOverlayExtensions.Clear(); api.Model.enableWebServer=enableServer.Checked.GetValueOrDefault(); api.Model.timelapsePort=(ushort)stepper.Value; api.Model.addExtensionOnInstall = enableExt.Checked.GetValueOrDefault(); foreach(var item in coll.Items) { if(!item.OverlayChecked) { api.Model.deniedOverlayExtensions.Add(item.Guid); } if(!item.BlockChecked) { api.Model.deniedBlockExtensions.Add(item.Guid); } } api.SaveModel(); }; lyt1.EndBeginHorizontal(); lyt1.Add(saveBtn,true); lyt1.EndHorizontal(); lyt1.EndVertical(); this.Content=lyt1; } }