timelapsenow/TimelapseApi/TimelapseSettings.cs

264 lines
9.3 KiB
C#
Raw Normal View History

2022-05-20 02:06:35 +00:00
namespace TimelapseApi;
using System.Diagnostics;
using Eto.Forms;
internal class FrameHandlerSettingsForm : Dialog
{
internal class FrameHandlerSettingsCollection
{
public FrameHandlerSettingsCollection(List<FrameHandlerSettings> img)
{
Items=img;
}
public CheckBox? OverlayEnabled {get;set;}
public CheckBox? BlockEnabled {get;set;}
public List<FrameHandlerSettings> Items {get;set;}
}
internal class FrameHandlerSettings
{
public Guid Guid;
2022-05-20 06:44:35 +00:00
2022-05-20 02:06:35 +00:00
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<FrameHandlerSettings> itemsList=new GridView<FrameHandlerSettings>();
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<FrameHandlerSettingsForm.FrameHandlerSettings> imgs=new List<FrameHandlerSettingsForm.FrameHandlerSettings>();
List<TimelapseExtension> ext=new List<TimelapseExtension>();
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"
};
2022-05-20 05:22:28 +00:00
CheckBox enableExt=new CheckBox{Text="Add extensions on install"};
2022-05-20 02:06:35 +00:00
enableExt.Checked = api.Model.addExtensionOnInstall;
2022-05-20 05:22:28 +00:00
CheckBox useCustomFilePickerForNativeFS = new CheckBox{Text="Use Custom File Picker For Native FileSystem"};
useCustomFilePickerForNativeFS.Checked=api.Model.useCustomFilePickerForNativeFS;
2022-05-20 02:06:35 +00:00
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();
GroupBox szRow=new GroupBox {Text="Blank camera size"};
NumericStepper blankWidth=new NumericStepper{Value=api.Model.blankCameraWidth,MinValue=120,MaxValue=65535};
NumericStepper blankHeight =new NumericStepper{Value=api.Model.blankCameraHeight,MinValue=90,MaxValue=65535};
DynamicLayout lyt3=new DynamicLayout();
lyt3.BeginVertical();
lyt3.BeginHorizontal();
lyt3.Add(blankWidth,true);
lyt3.Add(blankHeight,true);
lyt3.EndHorizontal();
lyt3.EndVertical();
szRow.Content=lyt3;
2022-05-20 02:06:35 +00:00
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);
2022-05-20 05:22:28 +00:00
lyt2.AddRow(useCustomFilePickerForNativeFS);
lyt2.AddRow(szRow);
2022-05-20 05:22:28 +00:00
2022-05-20 02:06:35 +00:00
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.blankCameraWidth=(int)blankWidth.Value;
api.Model.blankCameraHeight=(int)blankHeight.Value;
2022-05-20 02:06:35 +00:00
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();
2022-05-20 05:22:28 +00:00
api.Model.useCustomFilePickerForNativeFS = useCustomFilePickerForNativeFS.Checked.GetValueOrDefault();
2022-05-20 02:06:35 +00:00
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();
2022-05-20 05:22:28 +00:00
this.Close();
2022-05-20 02:06:35 +00:00
};
lyt1.EndBeginHorizontal();
lyt1.Add(saveBtn,true);
lyt1.EndHorizontal();
lyt1.EndVertical();
this.Content=lyt1;
}
}