Migrate Edit Profiles form to Eto

Some styling padding etc. still todo, but I'm leaving that for later.
This commit is contained in:
Ben Olden-Cooligan 2022-09-05 20:05:16 -07:00
parent e3e1110cba
commit 834d8c37f9
16 changed files with 1600 additions and 483 deletions

View File

@ -11,20 +11,15 @@ namespace NAPS2.EtoForms.WinForms;
public class WinFormsEtoPlatform : EtoPlatform
{
private const int MIN_BUTTON_WIDTH = 75;
private const int MIN_BUTTON_HEIGHT = 32;
private static readonly Size MinImageButtonSize = new(75, 32);
private const int IMAGE_PADDING = 5;
static WinFormsEtoPlatform()
{
ButtonHandler.DefaultMinimumSize = new Eto.Drawing.Size(MIN_BUTTON_WIDTH, MIN_BUTTON_HEIGHT);
}
public override IListView<T> CreateListView<T>(ListViewBehavior<T> behavior) =>
new WinFormsListView<T>(behavior);
public override void ConfigureImageButton(Eto.Forms.Button button)
{
button.MinimumSize = MinImageButtonSize;
if (button.ImagePosition == ButtonImagePosition.Left)
{
var native = (System.Windows.Forms.Button) button.ToNative();

View File

@ -1,3 +1,4 @@
using NAPS2.EtoForms.Ui;
using NAPS2.Scan;
using NAPS2.Wia;
@ -57,7 +58,7 @@ public class DesktopScanController : IDesktopScanController
}
// No profile for the device we're scanning with, so prompt to create one
var editSettingsForm = _formFactory.Create<FEditProfile>();
var editSettingsForm = _formFactory.Create<EditProfileForm>();
editSettingsForm.ScanProfile = _config.DefaultProfileSettings();
try
{
@ -69,7 +70,7 @@ public class DesktopScanController : IDesktopScanController
catch (WiaException)
{
}
editSettingsForm.ShowDialog();
editSettingsForm.ShowModal();
if (!editSettingsForm.Result)
{
return;
@ -102,9 +103,9 @@ public class DesktopScanController : IDesktopScanController
public async Task ScanWithNewProfile()
{
var editSettingsForm = _formFactory.Create<FEditProfile>();
var editSettingsForm = _formFactory.Create<EditProfileForm>();
editSettingsForm.ScanProfile = _config.DefaultProfileSettings();
editSettingsForm.ShowDialog();
editSettingsForm.ShowModal();
if (!editSettingsForm.Result)
{
return;

View File

@ -1,6 +1,7 @@
using System.Windows.Input;
using Eto.Drawing;
using Eto.Forms;
using NAPS2.Scan;
namespace NAPS2.EtoForms;
@ -120,4 +121,31 @@ public static class C
pix.Add(imageView, 0, 0);
return pix;
}
public static Label Label(string text)
{
return new Label
{
Text = text
};
}
public static DropDown EnumDropDown<T>() where T : Enum
{
return EnumDropDown<T>(x => x.Description());
}
public static DropDown EnumDropDown<T>(Func<T, string> format) where T : Enum
{
var combo = new DropDown();
foreach (var item in Enum.GetValues(typeof(T)))
{
combo.Items.Add(new ListItem
{
Key = item.ToString(),
Text = format((T) item)
});
}
return combo;
}
}

View File

@ -0,0 +1,609 @@
using Eto.Drawing;
using Eto.Forms;
using NAPS2.Scan;
using NAPS2.Scan.Exceptions;
using NAPS2.Scan.Internal;
namespace NAPS2.EtoForms.Ui;
public class EditProfileForm : EtoDialogBase
{
private readonly IScanPerformer _scanPerformer;
private readonly ErrorOutput _errorOutput;
private readonly ProfileNameTracker _profileNameTracker;
private readonly TextBox _displayName = new();
private readonly RadioButton _wiaDriver;
private readonly RadioButton _twainDriver;
private readonly RadioButton _appleDriver;
private readonly RadioButton _saneDriver;
private readonly TextBox _deviceName = new() { Enabled = false };
private readonly Button _chooseDevice = new() { Text = UiStrings.ChooseDevice };
private readonly RadioButton _predefinedSettings;
private readonly RadioButton _nativeUi;
private readonly DropDown _paperSource = C.EnumDropDown<ScanSource>();
private readonly DropDown _pageSize = C.EnumDropDown<ScanPageSize>();
private readonly DropDown _resolution = C.EnumDropDown<ScanDpi>();
private readonly DropDown _bitDepth = C.EnumDropDown<ScanBitDepth>();
private readonly DropDown _horAlign = C.EnumDropDown<ScanHorizontalAlign>();
private readonly DropDown _scale = C.EnumDropDown<ScanScale>();
private readonly CheckBox _enableAutoSave = new() { Text = UiStrings.EnableAutoSave };
private readonly LinkButton _autoSaveSettings = new() { Text = UiStrings.AutoSaveSettings };
private readonly Button _advanced = new() { Text = UiStrings.Advanced };
private readonly Button _ok = new() { Text = UiStrings.OK };
private readonly Button _cancel = new() { Text = UiStrings.Cancel };
private readonly Slider _brightnessSlider = new() { MinValue = -1000, MaxValue = 1000, TickFrequency = 200 };
private readonly NumericMaskedTextBox<int> _brightnessText = new();
private readonly Slider _contrastSlider = new() { MinValue = -1000, MaxValue = 1000, TickFrequency = 200 };
private readonly NumericMaskedTextBox<int> _contrastText = new();
private ScanProfile _scanProfile = null!;
private ScanDevice? _currentDevice;
private bool _isDefault;
private bool _result;
private bool _suppressChangeEvent;
public EditProfileForm(Naps2Config config, IScanPerformer scanPerformer, ErrorOutput errorOutput,
ProfileNameTracker profileNameTracker) : base(config)
{
_scanPerformer = scanPerformer;
_errorOutput = errorOutput;
_profileNameTracker = profileNameTracker;
Title = UiStrings.EditProfileFormTitle;
Icon = new Icon(1f, Icons.blueprints_small.ToEtoImage());
Size = new Size(448, 478);
MinimumSize = new Size(448, 478);
Resizable = true;
_wiaDriver = new RadioButton { Text = UiStrings.WiaDriver };
_twainDriver = new RadioButton(_wiaDriver) { Text = UiStrings.TwainDriver };
_appleDriver = new RadioButton(_wiaDriver) { Text = UiStrings.AppleDriver };
_saneDriver = new RadioButton(_wiaDriver) { Text = UiStrings.SaneDriver };
_predefinedSettings = new RadioButton { Text = UiStrings.UsePredefinedSettings };
_nativeUi = new RadioButton(_nativeUi) { Text = UiStrings.UseNativeUi };
_pageSize.SelectedIndexChanged += PageSize_SelectedIndexChanged;
_contrastSlider.ValueChanged += ContrastSlider_Scroll;
_contrastText.TextChanged += ContrastText_TextChanged;
_brightnessSlider.ValueChanged += BrightnessSlider_Scroll;
_brightnessText.TextChanged += BrightnessText_TextChanged;
_wiaDriver.CheckedChanged += Driver_CheckedChanged;
_twainDriver.CheckedChanged += Driver_CheckedChanged;
_appleDriver.CheckedChanged += Driver_CheckedChanged;
_saneDriver.CheckedChanged += Driver_CheckedChanged;
_predefinedSettings.CheckedChanged += PredefinedSettings_CheckedChanged;
_nativeUi.CheckedChanged += NativeUi_CheckedChanged;
_ok.Click += Ok_Click;
_cancel.Click += Cancel_Click;
// TODO: Don't show if only one driver is available
var driverElements = new List<LayoutElement>();
if (PlatformCompat.System.IsWiaDriverSupported)
{
driverElements.Add(_wiaDriver.XScale());
}
if (PlatformCompat.System.IsTwainDriverSupported)
{
driverElements.Add(_twainDriver.XScale());
}
if (PlatformCompat.System.IsAppleDriverSupported)
{
driverElements.Add(_appleDriver.XScale());
}
if (PlatformCompat.System.IsSaneDriverSupported)
{
driverElements.Add(_saneDriver.XScale());
}
_chooseDevice.Click += ChooseDevice;
_enableAutoSave.CheckedChanged += EnableAutoSave_CheckedChanged;
_autoSaveSettings.Click += AutoSaveSettings_LinkClicked;
_advanced.Click += Advanced_Click;
_deviceName.KeyDown += DeviceName_KeyDown;
Content = L.Root(L.Column(
L.Row(
L.Column(
C.Label(UiStrings.DisplayNameLabel),
_displayName,
L.Row(
driverElements.ToArray()
),
C.Label(UiStrings.DeviceLabel),
L.Row(
_deviceName.XScale(),
_chooseDevice
)
).XScale(),
new ImageView { Image = Icons.scanner_48.ToEtoImage() }
),
L.Row(
_predefinedSettings.XScale(),
_nativeUi.XScale()
),
L.Row(
L.Column(
C.Label(UiStrings.PaperSourceLabel),
_paperSource,
C.Label(UiStrings.PageSizeLabel),
_pageSize,
C.Label(UiStrings.ResolutionLabel),
_resolution,
C.Label(UiStrings.BrightnessLabel),
L.Row(
_brightnessSlider.XScale(),
_brightnessText.Width(40)
)
).XScale(),
L.Column(
C.Label(UiStrings.BitDepthLabel),
_bitDepth,
C.Label(UiStrings.HorizontalAlignLabel),
_horAlign,
C.Label(UiStrings.ScaleLabel),
_scale,
C.Label(UiStrings.ContrastLabel),
L.Row(
_contrastSlider.XScale(),
_contrastText.Width(40)
)
).XScale()
),
L.Row(
_enableAutoSave,
_autoSaveSettings
),
C.ZeroSpace().YScale(),
L.Row(
_advanced,
C.ZeroSpace().XScale(),
_ok,
_cancel
)
));
}
public bool Result => _result;
public ScanProfile ScanProfile
{
get => _scanProfile;
set => _scanProfile = value.Clone();
}
public ScanDevice? CurrentDevice
{
get => _currentDevice;
set
{
_currentDevice = value;
_deviceName.Text = value?.Name ?? "";
}
}
private Driver DeviceDriver
{
get => _twainDriver.Checked ? Driver.Twain
: _wiaDriver.Checked ? Driver.Wia
: _appleDriver.Checked ? Driver.Apple
: _saneDriver.Checked ? Driver.Sane
: ScanOptionsValidator.SystemDefaultDriver;
set
{
if (value == Driver.Twain)
{
_twainDriver.Checked = true;
}
else if (value == Driver.Wia)
{
_wiaDriver.Checked = true;
}
else if (value == Driver.Apple)
{
_appleDriver.Checked = true;
}
else if (value == Driver.Sane)
{
_saneDriver.Checked = true;
}
}
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
// Don't trigger any onChange events
_suppressChangeEvent = true;
_displayName.Text = ScanProfile.DisplayName;
CurrentDevice ??= ScanProfile.Device;
_isDefault = ScanProfile.IsDefault;
_paperSource.SelectedIndex = (int) ScanProfile.PaperSource;
_bitDepth.SelectedIndex = (int) ScanProfile.BitDepth;
_resolution.SelectedIndex = (int) ScanProfile.Resolution;
_contrastText.Text = ScanProfile.Contrast.ToString("G");
_brightnessText.Text = ScanProfile.Brightness.ToString("G");
UpdatePageSizeList();
SelectPageSize();
_scale.SelectedIndex = (int) ScanProfile.AfterScanScale;
_horAlign.SelectedIndex = (int) ScanProfile.PageAlign;
_enableAutoSave.Checked = ScanProfile.EnableAutoSave;
DeviceDriver = new ScanOptionsValidator().ValidateDriver(
Enum.TryParse<Driver>(ScanProfile.DriverName, true, out var driver)
? driver
: Driver.Default);
_nativeUi.Checked = ScanProfile.UseNativeUI;
_predefinedSettings.Checked = !ScanProfile.UseNativeUI;
// Start triggering onChange events again
_suppressChangeEvent = false;
UpdateEnabledControls();
}
private async void ChooseDevice(object? sender, EventArgs args)
{
ScanProfile.DriverName = DeviceDriver.ToString().ToLowerInvariant();
try
{
var device = await _scanPerformer.PromptForDevice(ScanProfile, NativeHandle);
if (device != null)
{
if (string.IsNullOrEmpty(_deviceName.Text) ||
CurrentDevice != null && CurrentDevice.Name == _deviceName.Text)
{
_deviceName.Text = device.Name;
}
CurrentDevice = device;
}
}
catch (ScanDriverException ex)
{
if (ex is ScanDriverUnknownException)
{
Log.ErrorException(ex.Message, ex.InnerException!);
_errorOutput.DisplayError(ex.Message, ex);
}
else
{
_errorOutput.DisplayError(ex.Message);
}
}
}
private void UpdatePageSizeList()
{
_pageSize.Items.Clear();
// Defaults
foreach (ScanPageSize item in Enum.GetValues(typeof(ScanPageSize)))
{
_pageSize.Items.Add(new PageSizeListItem
{
Type = item,
Text = item.Description()
});
}
// Custom Presets
foreach (var preset in Config.Get(c => c.CustomPageSizePresets).OrderBy(x => x.Name))
{
_pageSize.Items.Insert(_pageSize.Items.Count - 1, new PageSizeListItem
{
Type = ScanPageSize.Custom,
Text = string.Format(MiscResources.NamedPageSizeFormat, preset.Name, preset.Dimens.Width,
preset.Dimens.Height, preset.Dimens.Unit.Description()),
CustomName = preset.Name,
CustomDimens = preset.Dimens
});
}
}
private void SelectPageSize()
{
if (ScanProfile.PageSize == ScanPageSize.Custom)
{
if (ScanProfile.CustomPageSizeName != null && ScanProfile.CustomPageSize != null)
{
SelectCustomPageSize(ScanProfile.CustomPageSizeName, ScanProfile.CustomPageSize);
}
else
{
_pageSize.SelectedIndex = 0;
}
}
else
{
_pageSize.SelectedIndex = (int) ScanProfile.PageSize;
}
}
private void SelectCustomPageSize(string name, PageDimensions dimens)
{
for (int i = 0; i < _pageSize.Items.Count; i++)
{
var item = (PageSizeListItem) _pageSize.Items[i];
if (item.Type == ScanPageSize.Custom && item.CustomName == name && item.CustomDimens == dimens)
{
_pageSize.SelectedIndex = i;
return;
}
}
// Not found, so insert a new item
_pageSize.Items.Insert(_pageSize.Items.Count - 1, new PageSizeListItem
{
Type = ScanPageSize.Custom,
Text = string.IsNullOrEmpty(name)
? string.Format(MiscResources.CustomPageSizeFormat, dimens.Width, dimens.Height,
dimens.Unit.Description())
: string.Format(MiscResources.NamedPageSizeFormat, name, dimens.Width, dimens.Height,
dimens.Unit.Description()),
CustomName = name,
CustomDimens = dimens
});
_pageSize.SelectedIndex = _pageSize.Items.Count - 2;
}
private void SaveSettings()
{
if (ScanProfile.IsLocked)
{
if (!ScanProfile.IsDeviceLocked)
{
ScanProfile.Device = CurrentDevice;
}
return;
}
var pageSize = (PageSizeListItem) _pageSize.SelectedValue;
if (ScanProfile.DisplayName != null)
{
_profileNameTracker.RenamingProfile(ScanProfile.DisplayName, _displayName.Text);
}
_scanProfile = new ScanProfile
{
Version = ScanProfile.CURRENT_VERSION,
Device = CurrentDevice,
IsDefault = _isDefault,
DriverName = DeviceDriver.ToString().ToLowerInvariant(),
DisplayName = _displayName.Text,
IconID = 0,
MaxQuality = ScanProfile.MaxQuality,
UseNativeUI = _nativeUi.Checked,
AfterScanScale = (ScanScale) _scale.SelectedIndex,
BitDepth = (ScanBitDepth) _bitDepth.SelectedIndex,
Brightness = _brightnessSlider.Value,
Contrast = _contrastSlider.Value,
PageAlign = (ScanHorizontalAlign) _horAlign.SelectedIndex,
PageSize = pageSize.Type,
CustomPageSizeName = pageSize.CustomName,
CustomPageSize = pageSize.CustomDimens,
Resolution = (ScanDpi) _resolution.SelectedIndex,
PaperSource = (ScanSource) _paperSource.SelectedIndex,
EnableAutoSave = _enableAutoSave.Checked == true,
AutoSaveSettings = ScanProfile.AutoSaveSettings,
Quality = ScanProfile.Quality,
BrightnessContrastAfterScan = ScanProfile.BrightnessContrastAfterScan,
AutoDeskew = ScanProfile.AutoDeskew,
WiaOffsetWidth = ScanProfile.WiaOffsetWidth,
WiaRetryOnFailure = ScanProfile.WiaRetryOnFailure,
WiaDelayBetweenScans = ScanProfile.WiaDelayBetweenScans,
WiaDelayBetweenScansSeconds = ScanProfile.WiaDelayBetweenScansSeconds,
WiaVersion = ScanProfile.WiaVersion,
ForcePageSize = ScanProfile.ForcePageSize,
ForcePageSizeCrop = ScanProfile.ForcePageSizeCrop,
FlipDuplexedPages = ScanProfile.FlipDuplexedPages,
TwainImpl = ScanProfile.TwainImpl,
ExcludeBlankPages = ScanProfile.ExcludeBlankPages,
BlankPageWhiteThreshold = ScanProfile.BlankPageWhiteThreshold,
BlankPageCoverageThreshold = ScanProfile.BlankPageCoverageThreshold
};
}
private void Ok_Click(object? sender, EventArgs e)
{
// Note: If CurrentDevice is null, that's fine. A prompt will be shown when scanning.
if (_displayName.Text == "")
{
_errorOutput.DisplayError(MiscResources.NameMissing);
return;
}
_result = true;
SaveSettings();
Close();
}
private void Cancel_Click(object? sender, EventArgs e)
{
Close();
}
private void PredefinedSettings_CheckedChanged(object? sender, EventArgs e)
{
UpdateEnabledControls();
}
private void NativeUi_CheckedChanged(object? sender, EventArgs e)
{
UpdateEnabledControls();
}
private void UpdateEnabledControls()
{
if (!_suppressChangeEvent)
{
_suppressChangeEvent = true;
bool canUseNativeUi = DeviceDriver is Driver.Wia or Driver.Twain;
bool locked = ScanProfile.IsLocked;
bool deviceLocked = ScanProfile.IsDeviceLocked;
bool settingsEnabled = !locked && (_predefinedSettings.Checked || !canUseNativeUi);
_displayName.Enabled = !locked;
_wiaDriver.Enabled = _twainDriver.Enabled = _appleDriver.Enabled = _saneDriver.Enabled = !locked;
_chooseDevice.Enabled = !deviceLocked;
_predefinedSettings.Enabled = _nativeUi.Enabled = !locked;
_paperSource.Enabled = settingsEnabled;
_resolution.Enabled = settingsEnabled;
_pageSize.Enabled = settingsEnabled;
_bitDepth.Enabled = settingsEnabled;
_horAlign.Enabled = settingsEnabled;
_scale.Enabled = settingsEnabled;
_brightnessSlider.Enabled = settingsEnabled;
_contrastSlider.Enabled = settingsEnabled;
_brightnessText.Enabled = settingsEnabled;
_contrastText.Enabled = settingsEnabled;
_enableAutoSave.Enabled = !locked && !Config.Get(c => c.DisableAutoSave);
_autoSaveSettings.Enabled = _enableAutoSave.Checked == true;
_autoSaveSettings.Visible = !locked && !Config.Get(c => c.DisableAutoSave);
_advanced.Enabled = !locked;
// TODO: Adjust form height?
_suppressChangeEvent = false;
}
}
private void Driver_CheckedChanged(object? sender, EventArgs e)
{
if (((RadioButton) sender!).Checked && !_suppressChangeEvent)
{
ScanProfile.Device = null;
CurrentDevice = null;
UpdateEnabledControls();
}
}
private void BrightnessText_TextChanged(object? sender, EventArgs e)
{
if (int.TryParse(_brightnessText.Text, out int value))
{
if (value >= _brightnessSlider.MinValue && value <= _brightnessSlider.MaxValue)
{
_brightnessSlider.Value = value;
}
}
}
private void BrightnessSlider_Scroll(object? sender, EventArgs e)
{
_brightnessText.Text = _brightnessSlider.Value.ToString("G");
}
private void ContrastText_TextChanged(object? sender, EventArgs e)
{
if (int.TryParse(_contrastText.Text, out int value))
{
if (value >= _contrastSlider.MinValue && value <= _contrastSlider.MaxValue)
{
_contrastSlider.Value = value;
}
}
}
private void ContrastSlider_Scroll(object? sender, EventArgs e)
{
_contrastText.Text = _contrastSlider.Value.ToString("G");
}
private int _lastPageSizeIndex = -1;
private PageSizeListItem _lastPageSizeItem = null;
private void PageSize_SelectedIndexChanged(object? sender, EventArgs e)
{
if (_pageSize.SelectedIndex == _pageSize.Items.Count - 1)
{
// "Custom..." selected
// var form = FormFactory.Create<FPageSize>();
// form.PageSizeDimens = _lastPageSizeItem.Type == ScanPageSize.Custom
// ? _lastPageSizeItem.CustomDimens
// : _lastPageSizeItem.Type.PageDimensions();
// if (form.ShowDialog() == DialogResult.OK)
// {
// UpdatePageSizeList();
// SelectCustomPageSize(form.PageSizeName, form.PageSizeDimens);
// }
// else
// {
// _pageSize.SelectedIndex = _lastPageSizeIndex;
// }
}
_lastPageSizeIndex = _pageSize.SelectedIndex;
_lastPageSizeItem = (PageSizeListItem) _pageSize.SelectedValue;
}
private void AutoSaveSettings_LinkClicked(object? sender, EventArgs eventArgs)
{
if (Config.Get(c => c.DisableAutoSave))
{
return;
}
// var form = FormFactory.Create<FAutoSaveSettings>();
// ScanProfile.DriverName = DeviceDriver.ToString().ToLowerInvariant();
// form.ScanProfile = ScanProfile;
// form.ShowDialog();
}
private void Advanced_Click(object? sender, EventArgs e)
{
// var form = FormFactory.Create<FAdvancedScanSettings>();
// ScanProfile.DriverName = DeviceDriver.ToString().ToLowerInvariant();
// ScanProfile.BitDepth = (ScanBitDepth)_bitDepth.SelectedIndex;
// form.ScanProfile = ScanProfile;
// form.ShowDialog();
}
private void EnableAutoSave_CheckedChanged(object? sender, EventArgs e)
{
if (!_suppressChangeEvent)
{
if (_enableAutoSave.Checked == true)
{
_autoSaveSettings.Enabled = true;
// var form = FormFactory.Create<FAutoSaveSettings>();
// form.ScanProfile = ScanProfile;
// form.ShowDialog();
// if (!form.Result)
// {
// _enableAutoSave.Checked = false;
// }
}
}
_autoSaveSettings.Enabled = _enableAutoSave.Checked == true;
}
private void DeviceName_KeyDown(object? sender, KeyEventArgs e)
{
if (e.Key == Keys.Delete)
{
CurrentDevice = null;
}
}
private class PageSizeListItem : IListItem
{
public string Text { get; set; } = null!;
public string Key => Text;
public ScanPageSize Type { get; set; }
public string? CustomName { get; set; }
public PageDimensions? CustomDimens { get; set; }
}
}

View File

@ -231,64 +231,63 @@ public class ProfilesForm : EtoDialogBase
private async void DoScan()
{
// TODO: Migrate FEditProfile to eto
// if (ImageCallback == null)
// {
// throw new InvalidOperationException("Image callback not specified");
// }
// if (_profileManager.Profiles.Count == 0)
// {
// var editSettingsForm = FormFactory.Create<FEditProfile>();
// editSettingsForm.ScanProfile = new ScanProfile
// {
// Version = ScanProfile.CURRENT_VERSION
// };
// editSettingsForm.ShowDialog();
// if (!editSettingsForm.Result)
// {
// return;
// }
// _profileManager.Mutate(new ListMutation<ScanProfile>.Append(editSettingsForm.ScanProfile), ListSelection.Empty<ScanProfile>());
// _profileManager.DefaultProfile = editSettingsForm.ScanProfile;
// }
// if (SelectedProfile == null)
// {
// MessageBox.Show(MiscResources.SelectProfileBeforeScan, MiscResources.ChooseProfile, MessageBoxButtons.OK, MessageBoxType.Warning);
// return;
// }
// if (_profileManager.DefaultProfile == null)
// {
// _profileManager.DefaultProfile = SelectedProfile;
// }
// var source = await _scanPerformer.PerformScan(SelectedProfile, DefaultScanParams(), this.ToNative().Handle);
// await source.ForEach(ImageCallback);
// this.ToNative().Activate();
if (ImageCallback == null)
{
throw new InvalidOperationException("Image callback not specified");
}
if (_profileManager.Profiles.Count == 0)
{
var editSettingsForm = FormFactory.Create<EditProfileForm>();
editSettingsForm.ScanProfile = new ScanProfile
{
Version = ScanProfile.CURRENT_VERSION
};
editSettingsForm.ShowModal();
if (!editSettingsForm.Result)
{
return;
}
_profileManager.Mutate(new ListMutation<ScanProfile>.Append(editSettingsForm.ScanProfile), ListSelection.Empty<ScanProfile>());
_profileManager.DefaultProfile = editSettingsForm.ScanProfile;
}
if (SelectedProfile == null)
{
MessageBox.Show(MiscResources.SelectProfileBeforeScan, MiscResources.ChooseProfile, MessageBoxButtons.OK, MessageBoxType.Warning);
return;
}
if (_profileManager.DefaultProfile == null)
{
_profileManager.DefaultProfile = SelectedProfile;
}
var source = await _scanPerformer.PerformScan(SelectedProfile, DefaultScanParams(), NativeHandle);
await source.ForEach(ImageCallback);
Focus();
}
private void DoAdd()
{
// var fedit = FormFactory.Create<FEditProfile>();
// fedit.ScanProfile = Config.DefaultProfileSettings();
// fedit.ShowDialog();
// if (fedit.Result)
// {
// _profileManager.Mutate(new ListMutation<ScanProfile>.Append(fedit.ScanProfile), _listView);
// }
var fedit = FormFactory.Create<EditProfileForm>();
fedit.ScanProfile = Config.DefaultProfileSettings();
fedit.ShowModal();
if (fedit.Result)
{
_profileManager.Mutate(new ListMutation<ScanProfile>.Append(fedit.ScanProfile), _listView);
}
}
private void DoEdit()
{
// var originalProfile = SelectedProfile;
// if (originalProfile != null)
// {
// var fedit = FormFactory.Create<FEditProfile>();
// fedit.ScanProfile = originalProfile;
// fedit.ShowDialog();
// if (fedit.Result)
// {
// _profileManager.Mutate(new ListMutation<ScanProfile>.ReplaceWith(fedit.ScanProfile), _listView);
// }
// }
var originalProfile = SelectedProfile;
if (originalProfile != null)
{
var fedit = FormFactory.Create<EditProfileForm>();
fedit.ScanProfile = originalProfile;
fedit.ShowModal();
if (fedit.Result)
{
_profileManager.Mutate(new ListMutation<ScanProfile>.ReplaceWith(fedit.ScanProfile), _listView);
}
}
}
private void DoDelete()

View File

@ -1,7 +1,6 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
@ -22,7 +21,7 @@ namespace NAPS2.Lang.Resources {
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
public class SettingsResources {
internal class SettingsResources {
private static global::System.Resources.ResourceManager resourceMan;
@ -61,9 +60,9 @@ namespace NAPS2.Lang.Resources {
}
/// <summary>
/// Looks up a localized string similar to Black &amp; White.
/// Looks up a localized string similar to Black/White.
/// </summary>
public static string BitDepth_1BlackAndWhite {
internal static string BitDepth_1BlackAndWhite {
get {
return ResourceManager.GetString("BitDepth_1BlackAndWhite", resourceCulture);
}
@ -72,7 +71,7 @@ namespace NAPS2.Lang.Resources {
/// <summary>
/// Looks up a localized string similar to 24-bit Color.
/// </summary>
public static string BitDepth_24Color {
internal static string BitDepth_24Color {
get {
return ResourceManager.GetString("BitDepth_24Color", resourceCulture);
}
@ -81,7 +80,7 @@ namespace NAPS2.Lang.Resources {
/// <summary>
/// Looks up a localized string similar to Grayscale.
/// </summary>
public static string BitDepth_8Grayscale {
internal static string BitDepth_8Grayscale {
get {
return ResourceManager.GetString("BitDepth_8Grayscale", resourceCulture);
}
@ -90,7 +89,7 @@ namespace NAPS2.Lang.Resources {
/// <summary>
/// Looks up a localized string similar to 100 dpi.
/// </summary>
public static string Dpi_100 {
internal static string Dpi_100 {
get {
return ResourceManager.GetString("Dpi_100", resourceCulture);
}
@ -99,7 +98,7 @@ namespace NAPS2.Lang.Resources {
/// <summary>
/// Looks up a localized string similar to 1200 dpi.
/// </summary>
public static string Dpi_1200 {
internal static string Dpi_1200 {
get {
return ResourceManager.GetString("Dpi_1200", resourceCulture);
}
@ -108,7 +107,7 @@ namespace NAPS2.Lang.Resources {
/// <summary>
/// Looks up a localized string similar to 150 dpi.
/// </summary>
public static string Dpi_150 {
internal static string Dpi_150 {
get {
return ResourceManager.GetString("Dpi_150", resourceCulture);
}
@ -117,7 +116,7 @@ namespace NAPS2.Lang.Resources {
/// <summary>
/// Looks up a localized string similar to 200 dpi.
/// </summary>
public static string Dpi_200 {
internal static string Dpi_200 {
get {
return ResourceManager.GetString("Dpi_200", resourceCulture);
}
@ -126,7 +125,7 @@ namespace NAPS2.Lang.Resources {
/// <summary>
/// Looks up a localized string similar to 300 dpi.
/// </summary>
public static string Dpi_300 {
internal static string Dpi_300 {
get {
return ResourceManager.GetString("Dpi_300", resourceCulture);
}
@ -135,7 +134,7 @@ namespace NAPS2.Lang.Resources {
/// <summary>
/// Looks up a localized string similar to 400 dpi.
/// </summary>
public static string Dpi_400 {
internal static string Dpi_400 {
get {
return ResourceManager.GetString("Dpi_400", resourceCulture);
}
@ -144,7 +143,7 @@ namespace NAPS2.Lang.Resources {
/// <summary>
/// Looks up a localized string similar to 600 dpi.
/// </summary>
public static string Dpi_600 {
internal static string Dpi_600 {
get {
return ResourceManager.GetString("Dpi_600", resourceCulture);
}
@ -153,7 +152,7 @@ namespace NAPS2.Lang.Resources {
/// <summary>
/// Looks up a localized string similar to 800 dpi.
/// </summary>
public static string Dpi_800 {
internal static string Dpi_800 {
get {
return ResourceManager.GetString("Dpi_800", resourceCulture);
}
@ -162,7 +161,7 @@ namespace NAPS2.Lang.Resources {
/// <summary>
/// Looks up a localized string similar to No provider selected..
/// </summary>
public static string EmailProvider_NotSelected {
internal static string EmailProvider_NotSelected {
get {
return ResourceManager.GetString("EmailProvider_NotSelected", resourceCulture);
}
@ -171,7 +170,7 @@ namespace NAPS2.Lang.Resources {
/// <summary>
/// Looks up a localized string similar to Custom SMTP.
/// </summary>
public static string EmailProviderType_CustomSmtp {
internal static string EmailProviderType_CustomSmtp {
get {
return ResourceManager.GetString("EmailProviderType_CustomSmtp", resourceCulture);
}
@ -180,7 +179,7 @@ namespace NAPS2.Lang.Resources {
/// <summary>
/// Looks up a localized string similar to Gmail.
/// </summary>
public static string EmailProviderType_Gmail {
internal static string EmailProviderType_Gmail {
get {
return ResourceManager.GetString("EmailProviderType_Gmail", resourceCulture);
}
@ -189,7 +188,7 @@ namespace NAPS2.Lang.Resources {
/// <summary>
/// Looks up a localized string similar to Outlook Web Access.
/// </summary>
public static string EmailProviderType_OutlookWeb {
internal static string EmailProviderType_OutlookWeb {
get {
return ResourceManager.GetString("EmailProviderType_OutlookWeb", resourceCulture);
}
@ -198,7 +197,7 @@ namespace NAPS2.Lang.Resources {
/// <summary>
/// Looks up a localized string similar to Center.
/// </summary>
public static string HorizontalAlign_Center {
internal static string HorizontalAlign_Center {
get {
return ResourceManager.GetString("HorizontalAlign_Center", resourceCulture);
}
@ -207,7 +206,7 @@ namespace NAPS2.Lang.Resources {
/// <summary>
/// Looks up a localized string similar to Left.
/// </summary>
public static string HorizontalAlign_Left {
internal static string HorizontalAlign_Left {
get {
return ResourceManager.GetString("HorizontalAlign_Left", resourceCulture);
}
@ -216,7 +215,7 @@ namespace NAPS2.Lang.Resources {
/// <summary>
/// Looks up a localized string similar to Right.
/// </summary>
public static string HorizontalAlign_Right {
internal static string HorizontalAlign_Right {
get {
return ResourceManager.GetString("HorizontalAlign_Right", resourceCulture);
}
@ -225,7 +224,7 @@ namespace NAPS2.Lang.Resources {
/// <summary>
/// Looks up a localized string similar to A3 (297x420 mm).
/// </summary>
public static string PageSize_A3 {
internal static string PageSize_A3 {
get {
return ResourceManager.GetString("PageSize_A3", resourceCulture);
}
@ -234,7 +233,7 @@ namespace NAPS2.Lang.Resources {
/// <summary>
/// Looks up a localized string similar to A4 (210x297 mm).
/// </summary>
public static string PageSize_A4 {
internal static string PageSize_A4 {
get {
return ResourceManager.GetString("PageSize_A4", resourceCulture);
}
@ -243,7 +242,7 @@ namespace NAPS2.Lang.Resources {
/// <summary>
/// Looks up a localized string similar to A5 (148x210 mm).
/// </summary>
public static string PageSize_A5 {
internal static string PageSize_A5 {
get {
return ResourceManager.GetString("PageSize_A5", resourceCulture);
}
@ -252,7 +251,7 @@ namespace NAPS2.Lang.Resources {
/// <summary>
/// Looks up a localized string similar to B4 (250x353 mm).
/// </summary>
public static string PageSize_B4 {
internal static string PageSize_B4 {
get {
return ResourceManager.GetString("PageSize_B4", resourceCulture);
}
@ -261,7 +260,7 @@ namespace NAPS2.Lang.Resources {
/// <summary>
/// Looks up a localized string similar to B5 (176x250 mm).
/// </summary>
public static string PageSize_B5 {
internal static string PageSize_B5 {
get {
return ResourceManager.GetString("PageSize_B5", resourceCulture);
}
@ -270,7 +269,7 @@ namespace NAPS2.Lang.Resources {
/// <summary>
/// Looks up a localized string similar to Custom....
/// </summary>
public static string PageSize_Custom {
internal static string PageSize_Custom {
get {
return ResourceManager.GetString("PageSize_Custom", resourceCulture);
}
@ -279,7 +278,7 @@ namespace NAPS2.Lang.Resources {
/// <summary>
/// Looks up a localized string similar to US Legal (8.5x14 in).
/// </summary>
public static string PageSize_Legal {
internal static string PageSize_Legal {
get {
return ResourceManager.GetString("PageSize_Legal", resourceCulture);
}
@ -288,7 +287,7 @@ namespace NAPS2.Lang.Resources {
/// <summary>
/// Looks up a localized string similar to US Letter (8.5x11 in).
/// </summary>
public static string PageSize_Letter {
internal static string PageSize_Letter {
get {
return ResourceManager.GetString("PageSize_Letter", resourceCulture);
}
@ -297,7 +296,7 @@ namespace NAPS2.Lang.Resources {
/// <summary>
/// Looks up a localized string similar to cm.
/// </summary>
public static string PageSizeUnit_Centimetre {
internal static string PageSizeUnit_Centimetre {
get {
return ResourceManager.GetString("PageSizeUnit_Centimetre", resourceCulture);
}
@ -306,7 +305,7 @@ namespace NAPS2.Lang.Resources {
/// <summary>
/// Looks up a localized string similar to in.
/// </summary>
public static string PageSizeUnit_Inch {
internal static string PageSizeUnit_Inch {
get {
return ResourceManager.GetString("PageSizeUnit_Inch", resourceCulture);
}
@ -315,7 +314,7 @@ namespace NAPS2.Lang.Resources {
/// <summary>
/// Looks up a localized string similar to mm.
/// </summary>
public static string PageSizeUnit_Millimetre {
internal static string PageSizeUnit_Millimetre {
get {
return ResourceManager.GetString("PageSizeUnit_Millimetre", resourceCulture);
}
@ -324,7 +323,7 @@ namespace NAPS2.Lang.Resources {
/// <summary>
/// Looks up a localized string similar to Default.
/// </summary>
public static string PdfCompat_Default {
internal static string PdfCompat_Default {
get {
return ResourceManager.GetString("PdfCompat_Default", resourceCulture);
}
@ -333,7 +332,7 @@ namespace NAPS2.Lang.Resources {
/// <summary>
/// Looks up a localized string similar to PDF/A-1b.
/// </summary>
public static string PdfCompat_PdfA1B {
internal static string PdfCompat_PdfA1B {
get {
return ResourceManager.GetString("PdfCompat_PdfA1B", resourceCulture);
}
@ -342,7 +341,7 @@ namespace NAPS2.Lang.Resources {
/// <summary>
/// Looks up a localized string similar to PDF/A-2b.
/// </summary>
public static string PdfCompat_PdfA2B {
internal static string PdfCompat_PdfA2B {
get {
return ResourceManager.GetString("PdfCompat_PdfA2B", resourceCulture);
}
@ -351,7 +350,7 @@ namespace NAPS2.Lang.Resources {
/// <summary>
/// Looks up a localized string similar to PDF/A-3b.
/// </summary>
public static string PdfCompat_PdfA3B {
internal static string PdfCompat_PdfA3B {
get {
return ResourceManager.GetString("PdfCompat_PdfA3B", resourceCulture);
}
@ -360,7 +359,7 @@ namespace NAPS2.Lang.Resources {
/// <summary>
/// Looks up a localized string similar to PDF/A-3u.
/// </summary>
public static string PdfCompat_PdfA3U {
internal static string PdfCompat_PdfA3U {
get {
return ResourceManager.GetString("PdfCompat_PdfA3U", resourceCulture);
}
@ -369,7 +368,7 @@ namespace NAPS2.Lang.Resources {
/// <summary>
/// Looks up a localized string similar to 1:1.
/// </summary>
public static string Scale_1_1 {
internal static string Scale_1_1 {
get {
return ResourceManager.GetString("Scale_1_1", resourceCulture);
}
@ -378,7 +377,7 @@ namespace NAPS2.Lang.Resources {
/// <summary>
/// Looks up a localized string similar to 1:2.
/// </summary>
public static string Scale_1_2 {
internal static string Scale_1_2 {
get {
return ResourceManager.GetString("Scale_1_2", resourceCulture);
}
@ -387,7 +386,7 @@ namespace NAPS2.Lang.Resources {
/// <summary>
/// Looks up a localized string similar to 1:4.
/// </summary>
public static string Scale_1_4 {
internal static string Scale_1_4 {
get {
return ResourceManager.GetString("Scale_1_4", resourceCulture);
}
@ -396,7 +395,7 @@ namespace NAPS2.Lang.Resources {
/// <summary>
/// Looks up a localized string similar to 1:8.
/// </summary>
public static string Scale_1_8 {
internal static string Scale_1_8 {
get {
return ResourceManager.GetString("Scale_1_8", resourceCulture);
}
@ -405,7 +404,7 @@ namespace NAPS2.Lang.Resources {
/// <summary>
/// Looks up a localized string similar to Duplex.
/// </summary>
public static string Source_Duplex {
internal static string Source_Duplex {
get {
return ResourceManager.GetString("Source_Duplex", resourceCulture);
}
@ -414,7 +413,7 @@ namespace NAPS2.Lang.Resources {
/// <summary>
/// Looks up a localized string similar to Feeder.
/// </summary>
public static string Source_Feeder {
internal static string Source_Feeder {
get {
return ResourceManager.GetString("Source_Feeder", resourceCulture);
}
@ -423,7 +422,7 @@ namespace NAPS2.Lang.Resources {
/// <summary>
/// Looks up a localized string similar to Glass.
/// </summary>
public static string Source_Glass {
internal static string Source_Glass {
get {
return ResourceManager.GetString("Source_Glass", resourceCulture);
}
@ -432,7 +431,7 @@ namespace NAPS2.Lang.Resources {
/// <summary>
/// Looks up a localized string similar to Auto.
/// </summary>
public static string TiffComp_Auto {
internal static string TiffComp_Auto {
get {
return ResourceManager.GetString("TiffComp_Auto", resourceCulture);
}
@ -441,7 +440,7 @@ namespace NAPS2.Lang.Resources {
/// <summary>
/// Looks up a localized string similar to CCITT4.
/// </summary>
public static string TiffComp_Ccitt4 {
internal static string TiffComp_Ccitt4 {
get {
return ResourceManager.GetString("TiffComp_Ccitt4", resourceCulture);
}
@ -450,7 +449,7 @@ namespace NAPS2.Lang.Resources {
/// <summary>
/// Looks up a localized string similar to LZW.
/// </summary>
public static string TiffComp_Lzw {
internal static string TiffComp_Lzw {
get {
return ResourceManager.GetString("TiffComp_Lzw", resourceCulture);
}
@ -459,7 +458,7 @@ namespace NAPS2.Lang.Resources {
/// <summary>
/// Looks up a localized string similar to None.
/// </summary>
public static string TiffComp_None {
internal static string TiffComp_None {
get {
return ResourceManager.GetString("TiffComp_None", resourceCulture);
}
@ -468,7 +467,7 @@ namespace NAPS2.Lang.Resources {
/// <summary>
/// Looks up a localized string similar to Default.
/// </summary>
public static string TwainImpl_Default {
internal static string TwainImpl_Default {
get {
return ResourceManager.GetString("TwainImpl_Default", resourceCulture);
}
@ -477,7 +476,7 @@ namespace NAPS2.Lang.Resources {
/// <summary>
/// Looks up a localized string similar to Legacy (native UI only).
/// </summary>
public static string TwainImpl_Legacy {
internal static string TwainImpl_Legacy {
get {
return ResourceManager.GetString("TwainImpl_Legacy", resourceCulture);
}
@ -486,7 +485,7 @@ namespace NAPS2.Lang.Resources {
/// <summary>
/// Looks up a localized string similar to Alternative Transfer.
/// </summary>
public static string TwainImpl_MemXfer {
internal static string TwainImpl_MemXfer {
get {
return ResourceManager.GetString("TwainImpl_MemXfer", resourceCulture);
}
@ -495,7 +494,7 @@ namespace NAPS2.Lang.Resources {
/// <summary>
/// Looks up a localized string similar to Old DSM.
/// </summary>
public static string TwainImpl_OldDsm {
internal static string TwainImpl_OldDsm {
get {
return ResourceManager.GetString("TwainImpl_OldDsm", resourceCulture);
}
@ -504,7 +503,7 @@ namespace NAPS2.Lang.Resources {
/// <summary>
/// Looks up a localized string similar to x64.
/// </summary>
public static string TwainImpl_X64 {
internal static string TwainImpl_X64 {
get {
return ResourceManager.GetString("TwainImpl_X64", resourceCulture);
}
@ -513,7 +512,7 @@ namespace NAPS2.Lang.Resources {
/// <summary>
/// Looks up a localized string similar to Default.
/// </summary>
public static string WiaVersion_Default {
internal static string WiaVersion_Default {
get {
return ResourceManager.GetString("WiaVersion_Default", resourceCulture);
}
@ -522,7 +521,7 @@ namespace NAPS2.Lang.Resources {
/// <summary>
/// Looks up a localized string similar to 1.0.
/// </summary>
public static string WiaVersion_Wia10 {
internal static string WiaVersion_Wia10 {
get {
return ResourceManager.GetString("WiaVersion_Wia10", resourceCulture);
}
@ -531,7 +530,7 @@ namespace NAPS2.Lang.Resources {
/// <summary>
/// Looks up a localized string similar to 2.0.
/// </summary>
public static string WiaVersion_Wia20 {
internal static string WiaVersion_Wia20 {
get {
return ResourceManager.GetString("WiaVersion_Wia20", resourceCulture);
}

View File

@ -118,7 +118,7 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="BitDepth_1BlackAndWhite" xml:space="preserve">
<value>Black &amp; White</value>
<value>Black/White</value>
</data>
<data name="BitDepth_24Color" xml:space="preserve">
<value>24-bit Color</value>

File diff suppressed because it is too large Load Diff

View File

@ -315,4 +315,73 @@
<data name="EmailSelectedAsPdf" xml:space="preserve">
<value>Email Selected as PDF</value>
</data>
<data name="EditProfileFormTitle" xml:space="preserve">
<value>Profile Settings</value>
</data>
<data name="DisplayNameLabel" xml:space="preserve">
<value>Display name:</value>
</data>
<data name="WiaDriver" xml:space="preserve">
<value>WIA Driver</value>
</data>
<data name="TwainDriver" xml:space="preserve">
<value>TWAIN Driver</value>
</data>
<data name="AppleDriver" xml:space="preserve">
<value>Apple Driver</value>
</data>
<data name="SaneDriver" xml:space="preserve">
<value>SANE Driver</value>
</data>
<data name="DeviceLabel" xml:space="preserve">
<value>Device:</value>
</data>
<data name="ChooseDevice" xml:space="preserve">
<value>Choose device</value>
</data>
<data name="UsePredefinedSettings" xml:space="preserve">
<value>Use predefined settings</value>
</data>
<data name="UseNativeUi" xml:space="preserve">
<value>Use native UI</value>
</data>
<data name="PaperSourceLabel" xml:space="preserve">
<value>Paper source:</value>
</data>
<data name="PageSizeLabel" xml:space="preserve">
<value>Page size:</value>
</data>
<data name="ResolutionLabel" xml:space="preserve">
<value>Resolution:</value>
</data>
<data name="BrightnessLabel" xml:space="preserve">
<value>Brightness:</value>
</data>
<data name="BitDepthLabel" xml:space="preserve">
<value>Bit depth:</value>
</data>
<data name="HorizontalAlignLabel" xml:space="preserve">
<value>Horizontal align:</value>
</data>
<data name="ScaleLabel" xml:space="preserve">
<value>Scale:</value>
</data>
<data name="ContrastLabel" xml:space="preserve">
<value>Contrast:</value>
</data>
<data name="EnableAutoSave" xml:space="preserve">
<value>Enable Auto Save</value>
</data>
<data name="AutoSaveSettings" xml:space="preserve">
<value>Auto Save Settings</value>
</data>
<data name="Advanced" xml:space="preserve">
<value>Advanced</value>
</data>
<data name="OK" xml:space="preserve">
<value>OK</value>
</data>
<data name="Cancel" xml:space="preserve">
<value>Cancel</value>
</data>
</root>

View File

@ -6,6 +6,8 @@ public interface ISystemCompat
bool IsTwainDriverSupported { get; }
bool IsAppleDriverSupported { get; }
bool IsSaneDriverSupported { get; }
bool CanUseWin32 { get; }

View File

@ -13,6 +13,8 @@ public class LinuxSystemCompat : ISystemCompat
public bool IsTwainDriverSupported => false;
public bool IsAppleDriverSupported => false;
public bool IsSaneDriverSupported => true;
public bool CanUseWin32 => false;

View File

@ -14,6 +14,8 @@ public class MacSystemCompat : ISystemCompat
public bool IsTwainDriverSupported => true;
public bool IsAppleDriverSupported => true;
public bool IsSaneDriverSupported => false;
public bool CanUseWin32 => false;

View File

@ -11,6 +11,8 @@ public abstract class WindowsSystemCompat : ISystemCompat
public bool IsTwainDriverSupported => true;
public bool IsAppleDriverSupported => false;
public bool IsSaneDriverSupported => false;
public bool CanUseWin32 => true;

View File

@ -5,5 +5,7 @@ public enum Driver
Default,
Wia,
Twain,
Sane
Apple,
Sane,
Escl
}

View File

@ -10,7 +10,7 @@ public class ScanOptionsValidator
// Easy deep copy. Ideally we'd do this in a more efficient way.
options = options.ToXml().FromXml<ScanOptions>();
options.Driver = ValidateDriver(options);
options.Driver = ValidateDriver(options.Driver);
if (options.Driver == Driver.Sane)
{
options.UseNativeUI = false;
@ -69,28 +69,30 @@ public class ScanOptionsValidator
return options;
}
public Driver ValidateDriver(ScanOptions options)
{
if (options.Driver == Driver.Default)
{
return GetSystemDefaultDriver();
}
// TODO: Throw NotSupportedException if the platform doesn't match the driver
return options.Driver;
}
public Driver ValidateDriver(Driver driver) =>
driver == Driver.Default
? SystemDefaultDriver
: driver;
private Driver GetSystemDefaultDriver()
public static Driver SystemDefaultDriver
{
switch (Environment.OSVersion.Platform)
get
{
case PlatformID.Win32NT:
if (PlatformCompat.System.IsWiaDriverSupported)
{
// TODO: Maybe default to TWAIN
// TODO: Also in general "default driver" handling should change
return Driver.Wia;
case PlatformID.Unix:
}
if (PlatformCompat.System.IsAppleDriverSupported)
{
return Driver.Apple;
}
if (PlatformCompat.System.IsSaneDriverSupported)
{
return Driver.Sane;
case PlatformID.MacOSX:
return Driver.Twain;
default:
throw new InvalidOperationException("Unsupported operating system.");
}
return Driver.Escl;
}
}
}

View File

@ -9,6 +9,7 @@
<s:String x:Key="/Default/FilterSettingsManager/CoverageFilterXml/@EntryValue">&lt;data&gt;&lt;IncludeFilters /&gt;&lt;ExcludeFilters /&gt;&lt;/data&gt;</s:String>
<s:String x:Key="/Default/FilterSettingsManager/AttributeFilterXml/@EntryValue">&lt;data /&gt;</s:String>
<s:Boolean x:Key="/Default/UserDictionary/Words/=creds/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Escl/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Grpc/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=hwnd/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Jpegs/@EntryIndexedValue">True</s:Boolean>