Skip to content
This repository has been archived by the owner on May 19, 2022. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Kasyanov committed Oct 25, 2016
2 parents f86f551 + fb54983 commit e6d9fd1
Show file tree
Hide file tree
Showing 14 changed files with 533 additions and 296 deletions.
185 changes: 5 additions & 180 deletions Eve-O-Preview/Configuration/AppConfig.cs
Original file line number Diff line number Diff line change
@@ -1,188 +1,13 @@
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using Newtonsoft.Json;

namespace EveOPreview.Configuration
namespace EveOPreview.Configuration
{
public class AppConfig : IAppConfig
class AppConfig : IAppConfig
{
public AppConfig()
{
// Default values
this.MinimizeToTray = false;
this.ThumbnailRefreshPeriod = 500;

this.ThumbnailOpacity = 0.5;

this.EnableClientLayoutTracking = false;
this.HideActiveClientThumbnail = false;
this.ShowThumbnailsAlwaysOnTop = true;
this.HideThumbnailsOnLostFocus = false;
this.EnablePerClientThumbnailLayouts = false;

this.ThumbnailSize = new Size(250, 150);
this.ThumbnailMinimumSize = new Size(100, 80);
this.ThumbnailMaximumSize = new Size(640, 400);

this.ThumbnailZoomEnabled = false;
this.ThumbnailZoomFactor = 2;
this.ThumbnailZoomAnchor = ZoomAnchor.NW;

this.ShowThumbnailOverlays = true;
this.ShowThumbnailFrames = true;

this.EnableActiveClientHighlight = false;
this.ActiveClientHighlightColor = Color.Yellow;

this.PerClientLayout = new Dictionary<string, Dictionary<string, Point>>();
this.FlatLayout = new Dictionary<string, Point>();
this.ClientLayout = new Dictionary<string, ClientLayout>();
this.ClientHotkey = new Dictionary<string, string>();
this.ConfigFileName = null;
}

public bool MinimizeToTray { get; set; }
public int ThumbnailRefreshPeriod { get; set; }

[JsonProperty("ThumbnailsOpacity")]
public double ThumbnailOpacity { get; set; }

public bool EnableClientLayoutTracking { get; set; }
public bool HideActiveClientThumbnail { get; set; }
public bool ShowThumbnailsAlwaysOnTop { get; set; }
public bool HideThumbnailsOnLostFocus { get; set; }
public bool EnablePerClientThumbnailLayouts { get; set; }

public Size ThumbnailSize { get; set; }
public Size ThumbnailMaximumSize { get; set; }
public Size ThumbnailMinimumSize { get; set; }

[JsonProperty("EnableThumbnailZoom")]
public bool ThumbnailZoomEnabled { get; set; }
public int ThumbnailZoomFactor { get; set; }
public ZoomAnchor ThumbnailZoomAnchor { get; set; }

public bool ShowThumbnailOverlays { get; set; }
public bool ShowThumbnailFrames { get; set; }

public bool EnableActiveClientHighlight { get; set; }
public Color ActiveClientHighlightColor { get; set; }

[JsonProperty]
private Dictionary<string, Dictionary<string, Point>> PerClientLayout { get; set; }
[JsonProperty]
private Dictionary<string, Point> FlatLayout { get; set; }
[JsonProperty]
private Dictionary<string, ClientLayout> ClientLayout { get; set; }
[JsonProperty]
private Dictionary<string, string> ClientHotkey { get; set; }

public Point GetThumbnailLocation(string currentClient, string activeClient, Point defaultLocation)
{
Dictionary<string, Point> layoutSource = null;

if (this.EnablePerClientThumbnailLayouts)
{
if (!string.IsNullOrEmpty(activeClient))
{
this.PerClientLayout.TryGetValue(activeClient, out layoutSource);
}
}
else
{
layoutSource = this.FlatLayout;
}

if (layoutSource == null)
{
return defaultLocation;
}

Point location;
return layoutSource.TryGetValue(currentClient, out location) ? location : defaultLocation;
}

public void SetThumbnailLocation(string currentClient, string activeClient, Point location)
{
Dictionary<string, Point> layoutSource;

if (this.EnablePerClientThumbnailLayouts)
{
if (string.IsNullOrEmpty(activeClient))
{
return;
}

if (!this.PerClientLayout.TryGetValue(activeClient, out layoutSource))
{
layoutSource = new Dictionary<string, Point>();
this.PerClientLayout[activeClient] = layoutSource;
}
}
else
{
layoutSource = this.FlatLayout;
}

layoutSource[currentClient] = location;
}

public ClientLayout GetClientLayout(string currentClient)
{
ClientLayout layout;
this.ClientLayout.TryGetValue(currentClient, out layout);

return layout;
}

public void SetClientLayout(string currentClient, ClientLayout layout)
{
this.ClientLayout[currentClient] = layout;
}

public Keys GetClientHotkey(string currentClient)
{
string hotkey;
if (this.ClientHotkey.TryGetValue(currentClient, out hotkey))
{
// Protect from incorrect values
object rawValue = (new KeysConverter()).ConvertFromInvariantString(hotkey);
return rawValue != null ? (Keys)rawValue : Keys.None;
}

return Keys.None;
}

public void SetClientHotkey(string currentClient, Keys hotkey)
{
this.ClientHotkey[currentClient] = (new KeysConverter()).ConvertToInvariantString(hotkey);
}

/// <summary>
/// Applies restrictions to different parameters of the config
/// </summary>
public void ApplyRestrictions()
{
this.ThumbnailRefreshPeriod = AppConfig.ApplyRestrictions(this.ThumbnailRefreshPeriod, 300, 1000);
this.ThumbnailSize = new Size(AppConfig.ApplyRestrictions(this.ThumbnailSize.Width, this.ThumbnailMinimumSize.Width, this.ThumbnailMaximumSize.Width),
AppConfig.ApplyRestrictions(this.ThumbnailSize.Height, this.ThumbnailMinimumSize.Height, this.ThumbnailMaximumSize.Height));
this.ThumbnailOpacity = AppConfig.ApplyRestrictions((int)(this.ThumbnailOpacity * 100.00), 20, 100) / 100.00;
this.ThumbnailZoomFactor = AppConfig.ApplyRestrictions(this.ThumbnailZoomFactor, 2, 10);
}

private static int ApplyRestrictions(int value, int minimum, int maximum)
{
if (value <= minimum)
{
return minimum;
}

if (value >= maximum)
{
return maximum;
}

return value;
}
public string ConfigFileName { get; set; }
}
}
}
29 changes: 19 additions & 10 deletions Eve-O-Preview/Configuration/ConfigurationStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,46 @@

namespace EveOPreview.Configuration
{
public class ConfigurationStorage : IConfigurationStorage
class ConfigurationStorage : IConfigurationStorage
{
private const string ConfigurationFileName = "EVE-O Preview.json";

private readonly IAppConfig _configuration;
private readonly IAppConfig _appConfig;
private readonly IThumbnailConfig _thumbnailConfig;

public ConfigurationStorage(IAppConfig configuration)
public ConfigurationStorage(IAppConfig appConfig, IThumbnailConfig thumbnailConfig)
{
this._configuration = configuration;
this._appConfig = appConfig;
this._thumbnailConfig = thumbnailConfig;
}

public void Load()
{
if (!File.Exists(ConfigurationStorage.ConfigurationFileName))
string filename = this.GetConfigFileName();

if (!File.Exists(filename))
{
return;
}

string rawData = File.ReadAllText(ConfigurationStorage.ConfigurationFileName);
string rawData = File.ReadAllText(filename);

JsonConvert.PopulateObject(rawData, this._configuration);
JsonConvert.PopulateObject(rawData, this._thumbnailConfig);

// Validate data after loading it
this._configuration.ApplyRestrictions();
this._thumbnailConfig.ApplyRestrictions();
}

public void Save()
{
string rawData = JsonConvert.SerializeObject(this._configuration, Formatting.Indented);
string rawData = JsonConvert.SerializeObject(this._thumbnailConfig, Formatting.Indented);

File.WriteAllText(this.GetConfigFileName(), rawData);
}

File.WriteAllText(ConfigurationStorage.ConfigurationFileName, rawData);
private string GetConfigFileName()
{
return string.IsNullOrEmpty(this._appConfig.ConfigFileName) ? ConfigurationStorage.ConfigurationFileName : this._appConfig.ConfigFileName;
}
}
}
44 changes: 5 additions & 39 deletions Eve-O-Preview/Configuration/IAppConfig.cs
Original file line number Diff line number Diff line change
@@ -1,44 +1,10 @@
using System.Drawing;
using System.Windows.Forms;

namespace EveOPreview.Configuration
namespace EveOPreview.Configuration
{
/// <summary>
/// Application configuration
/// </summary>
public interface IAppConfig
{
bool MinimizeToTray { get; set; }
int ThumbnailRefreshPeriod { get; set; }

double ThumbnailOpacity { get; set; }

bool EnableClientLayoutTracking { get; set; }
bool HideActiveClientThumbnail { get; set; }
bool ShowThumbnailsAlwaysOnTop { get; set; }
bool HideThumbnailsOnLostFocus { get; set; }
bool EnablePerClientThumbnailLayouts { get; set; }

Size ThumbnailSize { get; set; }
Size ThumbnailMinimumSize { get; set; }
Size ThumbnailMaximumSize { get; set; }

bool ThumbnailZoomEnabled { get; set; }
int ThumbnailZoomFactor { get; set; }
ZoomAnchor ThumbnailZoomAnchor { get; set; }

bool ShowThumbnailOverlays { get; set; }
bool ShowThumbnailFrames { get; set; }

bool EnableActiveClientHighlight { get; set; }
Color ActiveClientHighlightColor { get; set; }

Point GetThumbnailLocation(string currentClient, string activeClient, Point defaultLocation);
void SetThumbnailLocation(string currentClient, string activeClient, Point location);

ClientLayout GetClientLayout(string currentClient);
void SetClientLayout(string currentClient, ClientLayout layout);

Keys GetClientHotkey(string currentClient);
void SetClientHotkey(string currentClient, Keys hotkey);

void ApplyRestrictions();
string ConfigFileName { get; set; }
}
}
48 changes: 48 additions & 0 deletions Eve-O-Preview/Configuration/IThumbnailConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System.Drawing;
using System.Windows.Forms;

namespace EveOPreview.Configuration
{
/// <summary>
/// Thumbnails Manager configuration
/// </summary>
public interface IThumbnailConfig
{
bool MinimizeToTray { get; set; }
int ThumbnailRefreshPeriod { get; set; }

double ThumbnailOpacity { get; set; }

bool EnableClientLayoutTracking { get; set; }
bool HideActiveClientThumbnail { get; set; }
bool ShowThumbnailsAlwaysOnTop { get; set; }
bool HideThumbnailsOnLostFocus { get; set; }
bool EnablePerClientThumbnailLayouts { get; set; }

Size ThumbnailSize { get; set; }
Size ThumbnailMinimumSize { get; set; }
Size ThumbnailMaximumSize { get; set; }

bool ThumbnailZoomEnabled { get; set; }
int ThumbnailZoomFactor { get; set; }
ZoomAnchor ThumbnailZoomAnchor { get; set; }

bool ShowThumbnailOverlays { get; set; }
bool ShowThumbnailFrames { get; set; }

bool EnableActiveClientHighlight { get; set; }
Color ActiveClientHighlightColor { get; set; }
int ActiveClientHighlightThickness { get; set; }

Point GetThumbnailLocation(string currentClient, string activeClient, Point defaultLocation);
void SetThumbnailLocation(string currentClient, string activeClient, Point location);

ClientLayout GetClientLayout(string currentClient);
void SetClientLayout(string currentClient, ClientLayout layout);

Keys GetClientHotkey(string currentClient);
void SetClientHotkey(string currentClient, Keys hotkey);

void ApplyRestrictions();
}
}
Loading

0 comments on commit e6d9fd1

Please sign in to comment.