Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Image Resizer Settings #2324

Merged
11 commits merged into from
Apr 27, 2020
5 changes: 5 additions & 0 deletions src/core/Microsoft.PowerToys.Settings.UI.Lib/BoolProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public BoolProperty()
this.Value = false;
}

public BoolProperty(bool value)
{
Value = value;
}

[JsonPropertyName("value")]
public bool Value { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ public DoubleProperty()
this.Value = 0.0;
}

public DoubleProperty(double value)
{
Value = value;
}

// Gets or sets the double value of the settings configuration.
[JsonPropertyName("value")]
public double Value { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public EnabledModules()
[JsonPropertyName("FancyZones")]
public bool FancyZones { get; set; }

[JsonPropertyName("ImageResizer")]
[JsonPropertyName("Image Resizer")]
public bool ImageResizer { get; set; }

[JsonPropertyName("File Explorer Preview")]
Expand Down
112 changes: 112 additions & 0 deletions src/core/Microsoft.PowerToys.Settings.UI.Lib/ImageResizerProperties.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Microsoft.PowerToys.Settings.UI.Lib
{
public class ImageResizerProperties
{
public ImageResizerProperties()
{
ImageresizerSelectedSizeIndex = new IntProperty(0);
ImageresizerShrinkOnly = new BoolProperty(false);
ImageresizerReplace = new BoolProperty(false);
ImageresizerIgnoreOrientation = new BoolProperty(true);
ImageresizerJpegQualityLevel = new IntProperty(90);
ImageresizerPngInterlaceOption = new IntProperty();
ImageresizerTiffCompressOption = new IntProperty();
ImageresizerFileName = new StringProperty("%1 (%2)");

ImageresizerSizes = new ImageresizerSizes(new ObservableCollection<ImageSize>()
{
new ImageSize(0, "small", ResizeFit.Fit, 854, 480, ResizeUnit.Pixel),
new ImageSize(1, "medium", ResizeFit.Fit, 1366, 768, ResizeUnit.Pixel),
new ImageSize(2, "large", ResizeFit.Fit, 1920, 1080, ResizeUnit.Pixel),
new ImageSize(3, "phone", ResizeFit.Fit, 320, 568, ResizeUnit.Pixel),
});

ImageresizerKeepDateModified = new BoolProperty();
ImageresizerFallbackEncoder = new StringProperty(new System.Guid("19e4a5aa-5662-4fc5-a0c0-1758028e1057").ToString());
ImageresizerCustomSize = new ImageresizerCustomSizeProperty(new ImageSize(4, "custom", ResizeFit.Fit, 1024, 640, ResizeUnit.Pixel));
}

[JsonPropertyName("imageresizer_selectedSizeIndex")]
public IntProperty ImageresizerSelectedSizeIndex { get; set; }

[JsonPropertyName("imageresizer_shrinkOnly")]
public BoolProperty ImageresizerShrinkOnly { get; set; }

[JsonPropertyName("imageresizer_replace")]
public BoolProperty ImageresizerReplace { get; set; }

[JsonPropertyName("imageresizer_ignoreOrientation")]
public BoolProperty ImageresizerIgnoreOrientation { get; set; }

[JsonPropertyName("imageresizer_jpegQualityLevel")]
public IntProperty ImageresizerJpegQualityLevel { get; set; }

[JsonPropertyName("imageresizer_pngInterlaceOption")]
public IntProperty ImageresizerPngInterlaceOption { get; set; }

[JsonPropertyName("imageresizer_tiffCompressOption")]
public IntProperty ImageresizerTiffCompressOption { get; set; }

[JsonPropertyName("imageresizer_fileName")]
public StringProperty ImageresizerFileName { get; set; }

[JsonPropertyName("imageresizer_sizes")]
public ImageresizerSizes ImageresizerSizes { get; set; }

[JsonPropertyName("imageresizer_keepDateModified")]
public BoolProperty ImageresizerKeepDateModified { get; set; }

[JsonPropertyName("imageresizer_fallbackEncoder")]
public StringProperty ImageresizerFallbackEncoder { get; set; }

[JsonPropertyName("imageresizer_customSize")]
public ImageresizerCustomSizeProperty ImageresizerCustomSize { get; set; }

public string ToJsonString()
{
return JsonSerializer.Serialize(this);
}
}

public enum ResizeFit
{
Fill = 0,
Fit = 1,
Stretch = 2,
}

public enum ResizeUnit
{
Centimeter = 0,
Inch = 1,
Percent = 2,
Pixel = 3,
}

public enum PngInterlaceOption
{
Default = 0,
On = 1,
Off = 2,
}

public enum TiffCompressOption
{
Default = 0,
None = 1,
Ccitt3 = 2,
Ccitt4 = 3,
Lzw = 4,
Rle = 5,
Zip = 6,
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Microsoft.PowerToys.Settings.UI.Lib
{
public class ImageResizerSettings
{
[JsonPropertyName("version")]
public string Version { get; set; }

[JsonPropertyName("name")]
public string Name { get; set; }

[JsonPropertyName("properties")]
public ImageResizerProperties Properties { get; set; }

public ImageResizerSettings()
{
this.Version = "1";
this.Name = "Image Resizer";
this.Properties = new ImageResizerProperties();
}

public string ToJsonString()
{
return JsonSerializer.Serialize(this);
}
}
}
67 changes: 67 additions & 0 deletions src/core/Microsoft.PowerToys.Settings.UI.Lib/ImageSize.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Microsoft.PowerToys.Settings.UI.Lib
{
public class ImageSize
{
public ImageSize(int id)
{
Id = id;
Name = string.Empty;
Fit = (int)ResizeFit.Fit;
Width = 0;
Height = 0;
Unit = (int)ResizeUnit.Pixel;
}

public ImageSize()
{
Id = 0;
Name = string.Empty;
Fit = (int)ResizeFit.Fit;
Width = 0;
Height = 0;
Unit = (int)ResizeUnit.Pixel;
}

public ImageSize(int id, string name, ResizeFit fit, double width, double height, ResizeUnit unit)
{
Id = id;
Name = name;
Fit = (int)fit;
Width = width;
Height = height;
Unit = (int)unit;
}

public int Id { get; set; }

[JsonPropertyName("name")]
public string Name { get; set; }

[JsonPropertyName("fit")]
public int Fit { get; set; }

[JsonPropertyName("width")]
public double Width { get; set; }

[JsonPropertyName("height")]
public double Height { get; set; }

[JsonPropertyName("unit")]
public int Unit { get; set; }

public string ToJsonString()
{
return JsonSerializer.Serialize(this);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json.Serialization;

namespace Microsoft.PowerToys.Settings.UI.Lib
{

public class ImageresizerCustomSizeProperty
{
[JsonPropertyName("value")]
public ImageSize Value { get; set; }

public ImageresizerCustomSizeProperty()
{
this.Value = new ImageSize();
}

public ImageresizerCustomSizeProperty(ImageSize value)
{
Value = value;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json.Serialization;

namespace Microsoft.PowerToys.Settings.UI.Lib
{

public class ImageresizerFallbackEncoder
{
[JsonPropertyName("value")]
public string Value { get; set; }

public ImageresizerFallbackEncoder()
{
this.Value = string.Empty;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json.Serialization;

namespace Microsoft.PowerToys.Settings.UI.Lib
{

public class ImageresizerKeepDateModified
{
[JsonPropertyName("value")]
public bool Value { get; set; }

public ImageresizerKeepDateModified()
{
this.Value = false;
}
}
}
29 changes: 29 additions & 0 deletions src/core/Microsoft.PowerToys.Settings.UI.Lib/ImageresizerSizes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using System.Text.Json.Serialization;

namespace Microsoft.PowerToys.Settings.UI.Lib
{

public class ImageresizerSizes
{
[JsonPropertyName("value")]
public ObservableCollection<ImageSize> Value { get; set; }

public ImageresizerSizes()
{
this.Value = new ObservableCollection<ImageSize>();
}

public ImageresizerSizes(ObservableCollection<ImageSize> value)
{
Value = value;
}
}
}
5 changes: 5 additions & 0 deletions src/core/Microsoft.PowerToys.Settings.UI.Lib/IntProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ public IntProperty()
this.Value = 0;
}

public IntProperty(int value)
{
Value = value;
}

// Gets or sets the integer value of the settings configuration.
[JsonPropertyName("value")]
public int Value { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,27 @@
// See the LICENSE file in the project root for more information.

using System.Text.Json;
using System.Text.Json.Serialization;

namespace Microsoft.PowerToys.Settings.UI.Lib
{
public class OutGoingGeneralSettings
{
public GeneralSettings general { get; set; }
[JsonPropertyName("general")]
public GeneralSettings GeneralSettings { get; set; }

public OutGoingGeneralSettings()
{
general = null;
}

public OutGoingGeneralSettings(GeneralSettings generalSettings)
{
general = generalSettings;
GeneralSettings = generalSettings;
}

public override string ToString()
{
return JsonSerializer.Serialize(this);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,4 @@ public static string LocalApplicationDataFolder()
return Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
}
}
}
}
Loading