Extending our settings framework to store custom settings for each display type.
authorsl
Sun, 31 Aug 2014 16:12:59 +0200
changeset 489039acfde091
parent 47 c9e3d1389d06
child 49 eab73d41c9e6
Extending our settings framework to store custom settings for each display type.
Server/App.config
Server/MainForm.cs
Server/Properties/Settings.Designer.cs
Server/Properties/Settings.settings
Server/Settings.cs
Server/SharpDisplayManager.csproj
     1.1 --- a/Server/App.config	Sat Aug 30 19:24:47 2014 +0200
     1.2 +++ b/Server/App.config	Sun Aug 31 16:12:59 2014 +0200
     1.3 @@ -10,26 +10,11 @@
     1.4      </startup>
     1.5      <userSettings>
     1.6          <SharpDisplayManager.Properties.Settings>
     1.7 -            <setting name="DisplayBrightness" serializeAs="String">
     1.8 -                <value>1</value>
     1.9 -            </setting>
    1.10 -            <setting name="DisplayFont" serializeAs="String">
    1.11 -                <value>Microsoft Sans Serif, 9.75pt</value>
    1.12 -            </setting>
    1.13 -            <setting name="DisplayShowBorders" serializeAs="String">
    1.14 -                <value>False</value>
    1.15 -            </setting>
    1.16              <setting name="DisplayConnectOnStartup" serializeAs="String">
    1.17                  <value>False</value>
    1.18              </setting>
    1.19 -            <setting name="DisplayReverseScreen" serializeAs="String">
    1.20 -                <value>False</value>
    1.21 -            </setting>
    1.22 -            <setting name="DisplayType" serializeAs="String">
    1.23 -                <value>1</value>
    1.24 -            </setting>
    1.25 -            <setting name="TimerInterval" serializeAs="String">
    1.26 -                <value>100</value>
    1.27 +            <setting name="CurrentDisplayIndex" serializeAs="String">
    1.28 +                <value>0</value>
    1.29              </setting>
    1.30          </SharpDisplayManager.Properties.Settings>
    1.31      </userSettings>
     2.1 --- a/Server/MainForm.cs	Sat Aug 30 19:24:47 2014 +0200
     2.2 +++ b/Server/MainForm.cs	Sun Aug 31 16:12:59 2014 +0200
     2.3 @@ -41,16 +41,7 @@
     2.4  
     2.5              InitializeComponent();
     2.6              UpdateStatus();
     2.7 -
     2.8 -            //Load settings
     2.9 -            marqueeLabelTop.Font = Properties.Settings.Default.DisplayFont;
    2.10 -            marqueeLabelBottom.Font = Properties.Settings.Default.DisplayFont;
    2.11 -            checkBoxShowBorders.Checked = Properties.Settings.Default.DisplayShowBorders;
    2.12 -            checkBoxConnectOnStartup.Checked = Properties.Settings.Default.DisplayConnectOnStartup;
    2.13 -            checkBoxReverseScreen.Checked = Properties.Settings.Default.DisplayReverseScreen;
    2.14 -            comboBoxDisplayType.SelectedIndex = Properties.Settings.Default.DisplayType;
    2.15 -            timer.Interval = Properties.Settings.Default.TimerInterval;
    2.16 -            maskedTextBoxTimerInterval.Text = Properties.Settings.Default.TimerInterval.ToString();
    2.17 +            
    2.18              //
    2.19              tableLayoutPanel.CellBorderStyle = (checkBoxShowBorders.Checked ? TableLayoutPanelCellBorderStyle.Single : TableLayoutPanelCellBorderStyle.None);
    2.20              //We have a bug when drawing minimized and reusing our bitmap
    2.21 @@ -102,7 +93,7 @@
    2.22                  //MessageBox.Show("Ok");
    2.23                  marqueeLabelTop.Font = fontDialog.Font;
    2.24                  marqueeLabelBottom.Font = fontDialog.Font;
    2.25 -                Properties.Settings.Default.DisplayFont = fontDialog.Font;
    2.26 +                cds.Font = fontDialog.Font;
    2.27                  Properties.Settings.Default.Save();
    2.28                  //
    2.29                  CheckFontHeight();
    2.30 @@ -235,7 +226,7 @@
    2.31                  CoordinateTranslationDelegate screenX;
    2.32                  CoordinateTranslationDelegate screenY;
    2.33  
    2.34 -                if (Properties.Settings.Default.DisplayReverseScreen)
    2.35 +                if (cds.ReverseScreen)
    2.36                  {
    2.37                      screenX = ScreenReversedX;
    2.38                      screenY = ScreenReversedY;
    2.39 @@ -276,7 +267,7 @@
    2.40          {
    2.41              CloseDisplayConnection();
    2.42  
    2.43 -            if (iDisplay.Open((Display.TMiniDisplayType)Properties.Settings.Default.DisplayType))
    2.44 +            if (iDisplay.Open((Display.TMiniDisplayType)cds.DisplayType))
    2.45              {
    2.46                  UpdateStatus();
    2.47                  iDisplay.RequestPowerSupplyStatus();
    2.48 @@ -318,28 +309,62 @@
    2.49  
    2.50          private void trackBarBrightness_Scroll(object sender, EventArgs e)
    2.51          {
    2.52 -            Properties.Settings.Default.DisplayBrightness = trackBarBrightness.Value;
    2.53 +            cds.Brightness = trackBarBrightness.Value;
    2.54              Properties.Settings.Default.Save();
    2.55              iDisplay.SetBrightness(trackBarBrightness.Value);
    2.56  
    2.57          }
    2.58  
    2.59 +
    2.60 +        /// <summary>
    2.61 +        /// CDS stands for Current Display Settings
    2.62 +        /// </summary>
    2.63 +        private DisplaySettingsEntry cds
    2.64 +        {
    2.65 +            get
    2.66 +            {
    2.67 +                DisplaySettings settings = Properties.Settings.Default.DisplaySettings;
    2.68 +
    2.69 +                //Make sure all our settings have been created
    2.70 +                while (settings.Displays.Count <= Properties.Settings.Default.CurrentDisplayIndex)
    2.71 +                {
    2.72 +                    settings.Displays.Add(new DisplaySettingsEntry());
    2.73 +                }
    2.74 +
    2.75 +                DisplaySettingsEntry displaySettings = settings.Displays[Properties.Settings.Default.CurrentDisplayIndex];
    2.76 +                return displaySettings;
    2.77 +            }
    2.78 +        }
    2.79 +
    2.80          private void UpdateStatus()
    2.81          {
    2.82 +            //Synchronize UI with settings
    2.83 +            //Load settings
    2.84 +            marqueeLabelTop.Font = cds.Font;
    2.85 +            marqueeLabelBottom.Font = cds.Font;
    2.86 +            checkBoxShowBorders.Checked = cds.ShowBorders;
    2.87 +            checkBoxConnectOnStartup.Checked = Properties.Settings.Default.DisplayConnectOnStartup;
    2.88 +            checkBoxReverseScreen.Checked = cds.ReverseScreen;
    2.89 +            comboBoxDisplayType.SelectedIndex = cds.DisplayType;
    2.90 +            timer.Interval = cds.TimerInterval;
    2.91 +            maskedTextBoxTimerInterval.Text = cds.TimerInterval.ToString();
    2.92 +
    2.93 +
    2.94              if (iDisplay.IsOpen())
    2.95              {
    2.96 +                //Only setup brightness if display is open
    2.97 +                trackBarBrightness.Minimum = iDisplay.MinBrightness();
    2.98 +                trackBarBrightness.Maximum = iDisplay.MaxBrightness();
    2.99 +                trackBarBrightness.Value = cds.Brightness;
   2.100 +                trackBarBrightness.LargeChange = Math.Max(1, (iDisplay.MaxBrightness() - iDisplay.MinBrightness()) / 5);
   2.101 +                trackBarBrightness.SmallChange = 1;
   2.102 +                iDisplay.SetBrightness(cds.Brightness);
   2.103 +                //
   2.104                  buttonFill.Enabled = true;
   2.105                  buttonClear.Enabled = true;
   2.106                  buttonOpen.Enabled = false;
   2.107                  buttonClose.Enabled = true;
   2.108                  trackBarBrightness.Enabled = true;
   2.109 -                trackBarBrightness.Minimum = iDisplay.MinBrightness();
   2.110 -                trackBarBrightness.Maximum = iDisplay.MaxBrightness();
   2.111 -                trackBarBrightness.Value = Properties.Settings.Default.DisplayBrightness;
   2.112 -                trackBarBrightness.LargeChange = Math.Max(1,(iDisplay.MaxBrightness() - iDisplay.MinBrightness())/5);
   2.113 -                trackBarBrightness.SmallChange = 1;
   2.114 -                iDisplay.SetBrightness(Properties.Settings.Default.DisplayBrightness);
   2.115 -
   2.116                  toolStripStatusLabelConnect.Text = "Connected - " + iDisplay.Vendor() + " - " + iDisplay.Product();
   2.117                  //+ " - " + iDisplay.SerialNumber();
   2.118              }
   2.119 @@ -351,6 +376,7 @@
   2.120                  buttonClose.Enabled = false;
   2.121                  trackBarBrightness.Enabled = false;
   2.122                  toolStripStatusLabelConnect.Text = "Disconnected";
   2.123 +                toolStripStatusLabelPower.Text = "N/A";
   2.124              }
   2.125          }
   2.126  
   2.127 @@ -360,7 +386,7 @@
   2.128          {
   2.129              //Save our show borders setting
   2.130              tableLayoutPanel.CellBorderStyle = (checkBoxShowBorders.Checked ? TableLayoutPanelCellBorderStyle.Single : TableLayoutPanelCellBorderStyle.None);
   2.131 -            Properties.Settings.Default.DisplayShowBorders = checkBoxShowBorders.Checked;
   2.132 +            cds.ShowBorders = checkBoxShowBorders.Checked;
   2.133              Properties.Settings.Default.Save();
   2.134          }
   2.135  
   2.136 @@ -374,7 +400,7 @@
   2.137          private void checkBoxReverseScreen_CheckedChanged(object sender, EventArgs e)
   2.138          {
   2.139              //Save our reverse screen setting
   2.140 -            Properties.Settings.Default.DisplayReverseScreen = checkBoxReverseScreen.Checked;
   2.141 +            cds.ReverseScreen = checkBoxReverseScreen.Checked;
   2.142              Properties.Settings.Default.Save();
   2.143          }
   2.144  
   2.145 @@ -798,7 +824,8 @@
   2.146  
   2.147          private void comboBoxDisplayType_SelectedIndexChanged(object sender, EventArgs e)
   2.148          {
   2.149 -            Properties.Settings.Default.DisplayType = comboBoxDisplayType.SelectedIndex;
   2.150 +            Properties.Settings.Default.CurrentDisplayIndex = comboBoxDisplayType.SelectedIndex;
   2.151 +            cds.DisplayType = comboBoxDisplayType.SelectedIndex;
   2.152              Properties.Settings.Default.Save();
   2.153              OpenDisplayConnection();
   2.154          }
   2.155 @@ -809,7 +836,7 @@
   2.156              if (maskedTextBoxTimerInterval.Text != "")
   2.157              {
   2.158                  timer.Interval = Convert.ToInt32(maskedTextBoxTimerInterval.Text);
   2.159 -                Properties.Settings.Default.TimerInterval = timer.Interval;
   2.160 +                cds.TimerInterval = timer.Interval;
   2.161                  Properties.Settings.Default.Save();
   2.162              }
   2.163          }
     3.1 --- a/Server/Properties/Settings.Designer.cs	Sat Aug 30 19:24:47 2014 +0200
     3.2 +++ b/Server/Properties/Settings.Designer.cs	Sun Aug 31 16:12:59 2014 +0200
     3.3 @@ -25,42 +25,6 @@
     3.4          
     3.5          [global::System.Configuration.UserScopedSettingAttribute()]
     3.6          [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
     3.7 -        [global::System.Configuration.DefaultSettingValueAttribute("1")]
     3.8 -        public int DisplayBrightness {
     3.9 -            get {
    3.10 -                return ((int)(this["DisplayBrightness"]));
    3.11 -            }
    3.12 -            set {
    3.13 -                this["DisplayBrightness"] = value;
    3.14 -            }
    3.15 -        }
    3.16 -        
    3.17 -        [global::System.Configuration.UserScopedSettingAttribute()]
    3.18 -        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    3.19 -        [global::System.Configuration.DefaultSettingValueAttribute("Microsoft Sans Serif, 9.75pt")]
    3.20 -        public global::System.Drawing.Font DisplayFont {
    3.21 -            get {
    3.22 -                return ((global::System.Drawing.Font)(this["DisplayFont"]));
    3.23 -            }
    3.24 -            set {
    3.25 -                this["DisplayFont"] = value;
    3.26 -            }
    3.27 -        }
    3.28 -        
    3.29 -        [global::System.Configuration.UserScopedSettingAttribute()]
    3.30 -        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    3.31 -        [global::System.Configuration.DefaultSettingValueAttribute("False")]
    3.32 -        public bool DisplayShowBorders {
    3.33 -            get {
    3.34 -                return ((bool)(this["DisplayShowBorders"]));
    3.35 -            }
    3.36 -            set {
    3.37 -                this["DisplayShowBorders"] = value;
    3.38 -            }
    3.39 -        }
    3.40 -        
    3.41 -        [global::System.Configuration.UserScopedSettingAttribute()]
    3.42 -        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    3.43          [global::System.Configuration.DefaultSettingValueAttribute("False")]
    3.44          public bool DisplayConnectOnStartup {
    3.45              get {
    3.46 @@ -73,37 +37,24 @@
    3.47          
    3.48          [global::System.Configuration.UserScopedSettingAttribute()]
    3.49          [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    3.50 -        [global::System.Configuration.DefaultSettingValueAttribute("False")]
    3.51 -        public bool DisplayReverseScreen {
    3.52 +        public global::SharpDisplayManager.DisplaySettings DisplaySettings {
    3.53              get {
    3.54 -                return ((bool)(this["DisplayReverseScreen"]));
    3.55 +                return ((global::SharpDisplayManager.DisplaySettings)(this["DisplaySettings"]));
    3.56              }
    3.57              set {
    3.58 -                this["DisplayReverseScreen"] = value;
    3.59 +                this["DisplaySettings"] = value;
    3.60              }
    3.61          }
    3.62          
    3.63          [global::System.Configuration.UserScopedSettingAttribute()]
    3.64          [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    3.65 -        [global::System.Configuration.DefaultSettingValueAttribute("1")]
    3.66 -        public int DisplayType {
    3.67 +        [global::System.Configuration.DefaultSettingValueAttribute("0")]
    3.68 +        public int CurrentDisplayIndex {
    3.69              get {
    3.70 -                return ((int)(this["DisplayType"]));
    3.71 +                return ((int)(this["CurrentDisplayIndex"]));
    3.72              }
    3.73              set {
    3.74 -                this["DisplayType"] = value;
    3.75 -            }
    3.76 -        }
    3.77 -        
    3.78 -        [global::System.Configuration.UserScopedSettingAttribute()]
    3.79 -        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    3.80 -        [global::System.Configuration.DefaultSettingValueAttribute("100")]
    3.81 -        public int TimerInterval {
    3.82 -            get {
    3.83 -                return ((int)(this["TimerInterval"]));
    3.84 -            }
    3.85 -            set {
    3.86 -                this["TimerInterval"] = value;
    3.87 +                this["CurrentDisplayIndex"] = value;
    3.88              }
    3.89          }
    3.90      }
     4.1 --- a/Server/Properties/Settings.settings	Sat Aug 30 19:24:47 2014 +0200
     4.2 +++ b/Server/Properties/Settings.settings	Sun Aug 31 16:12:59 2014 +0200
     4.3 @@ -2,26 +2,14 @@
     4.4  <SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="SharpDisplayManager.Properties" GeneratedClassName="Settings">
     4.5    <Profiles />
     4.6    <Settings>
     4.7 -    <Setting Name="DisplayBrightness" Type="System.Int32" Scope="User">
     4.8 -      <Value Profile="(Default)">1</Value>
     4.9 -    </Setting>
    4.10 -    <Setting Name="DisplayFont" Type="System.Drawing.Font" Scope="User">
    4.11 -      <Value Profile="(Default)">Microsoft Sans Serif, 9.75pt</Value>
    4.12 -    </Setting>
    4.13 -    <Setting Name="DisplayShowBorders" Type="System.Boolean" Scope="User">
    4.14 -      <Value Profile="(Default)">False</Value>
    4.15 -    </Setting>
    4.16      <Setting Name="DisplayConnectOnStartup" Type="System.Boolean" Scope="User">
    4.17        <Value Profile="(Default)">False</Value>
    4.18      </Setting>
    4.19 -    <Setting Name="DisplayReverseScreen" Type="System.Boolean" Scope="User">
    4.20 -      <Value Profile="(Default)">False</Value>
    4.21 +    <Setting Name="DisplaySettings" Type="SharpDisplayManager.DisplaySettings" Scope="User">
    4.22 +      <Value Profile="(Default)" />
    4.23      </Setting>
    4.24 -    <Setting Name="DisplayType" Type="System.Int32" Scope="User">
    4.25 -      <Value Profile="(Default)">1</Value>
    4.26 -    </Setting>
    4.27 -    <Setting Name="TimerInterval" Type="System.Int32" Scope="User">
    4.28 -      <Value Profile="(Default)">100</Value>
    4.29 +    <Setting Name="CurrentDisplayIndex" Type="System.Int32" Scope="User">
    4.30 +      <Value Profile="(Default)">0</Value>
    4.31      </Setting>
    4.32    </Settings>
    4.33  </SettingsFile>
    4.34 \ No newline at end of file
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/Server/Settings.cs	Sun Aug 31 16:12:59 2014 +0200
     5.3 @@ -0,0 +1,28 @@
     5.4 +´╗┐namespace SharpDisplayManager.Properties {
     5.5 +    
     5.6 +    
     5.7 +    // This class allows you to handle specific events on the settings class:
     5.8 +    //  The SettingChanging event is raised before a setting's value is changed.
     5.9 +    //  The PropertyChanged event is raised after a setting's value is changed.
    5.10 +    //  The SettingsLoaded event is raised after the setting values are loaded.
    5.11 +    //  The SettingsSaving event is raised before the setting values are saved.
    5.12 +    internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
    5.13 +        
    5.14 +        public Settings() : base("default") {
    5.15 +            // // To add event handlers for saving and changing settings, uncomment the lines below:
    5.16 +            //
    5.17 +            // this.SettingChanging += this.SettingChangingEventHandler;
    5.18 +            //
    5.19 +            // this.SettingsSaving += this.SettingsSavingEventHandler;
    5.20 +            //
    5.21 +        }
    5.22 +        
    5.23 +        private void SettingChangingEventHandler(object sender, System.Configuration.SettingChangingEventArgs e) {
    5.24 +            // Add code to handle the SettingChangingEvent event here.
    5.25 +        }
    5.26 +        
    5.27 +        private void SettingsSavingEventHandler(object sender, System.ComponentModel.CancelEventArgs e) {
    5.28 +            // Add code to handle the SettingsSaving event here.
    5.29 +        }
    5.30 +    }
    5.31 +}
     6.1 --- a/Server/SharpDisplayManager.csproj	Sat Aug 30 19:24:47 2014 +0200
     6.2 +++ b/Server/SharpDisplayManager.csproj	Sun Aug 31 16:12:59 2014 +0200
     6.3 @@ -73,6 +73,7 @@
     6.4      <Reference Include="Microsoft.VisualBasic" />
     6.5      <Reference Include="Microsoft.VisualBasic.PowerPacks.Vs, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
     6.6      <Reference Include="System" />
     6.7 +    <Reference Include="System.Configuration" />
     6.8      <Reference Include="System.Core" />
     6.9      <Reference Include="System.Runtime.Serialization" />
    6.10      <Reference Include="System.ServiceModel" />
    6.11 @@ -90,6 +91,7 @@
    6.12      <Compile Include="CbtHook.cs" />
    6.13      <Compile Include="DialogBox.cs" />
    6.14      <Compile Include="Display.cs" />
    6.15 +    <Compile Include="DisplaySettings.cs" />
    6.16      <Compile Include="MainForm.cs">
    6.17        <SubType>Form</SubType>
    6.18      </Compile>