added new settings from xbmc to LibCecTray
authorLars Op den Kamp <lars@opdenkamp.eu>
Sun, 7 Oct 2012 19:02:02 +0000 (21:02 +0200)
committerLars Op den Kamp <lars@opdenkamp.eu>
Sun, 7 Oct 2012 19:02:02 +0000 (21:02 +0200)
src/LibCecTray/Properties/Resources.Designer.cs
src/LibCecTray/Properties/Resources.resx
src/LibCecTray/controller/applications/internal/XBMCController.cs
src/LibCecTray/controller/applications/internal/XBMCControllerUI.Designer.cs
src/LibCecTray/controller/applications/internal/XBMCControllerUI.cs

index ecf2b61c24458a6772202998df77a982629857d9..0285bd39a57a66261f755804a74171e4ae367b23 100644 (file)
@@ -312,6 +312,15 @@ namespace LibCECTray.Properties {
             }
         }
         
+        /// <summary>
+        ///   Looks up a localized string similar to Pause playback when switching to another source.
+        /// </summary>
+        internal static string app_pause_playback_on_deactivate {
+            get {
+                return ResourceManager.GetString("app_pause_playback_on_deactivate", resourceCulture);
+            }
+        }
+        
         /// <summary>
         ///   Looks up a localized string similar to Send inactive source message when stopping the application.
         /// </summary>
index 31cab95f6c7e4f068e31126d224feeb437bea2d2..14f481e8d75ede866490a9901b4b73ee6f2ca8dc 100644 (file)
   <data name="error" xml:space="preserve">
     <value>Error</value>
   </data>
+  <data name="app_pause_playback_on_deactivate" xml:space="preserve">
+    <value>Pause playback when switching to another source</value>
+  </data>
 </root>
\ No newline at end of file
index fe15fd25edc18d3b62c2442ab9d3ce17b2433d4d..c2697885973735bc992989e25cc40cea5a8c09f5 100644 (file)
@@ -123,9 +123,9 @@ namespace LibCECTray.controller.applications.@internal
                     break;
                   case "connected_device":
                     {
-                      ushort iDevice;
-                      if (ushort.TryParse(value, out iDevice))
-                        Settings.ConnectedDevice.Value = (CecLogicalAddress)iDevice;
+                      int iDevice;
+                      if (int.TryParse(value, out iDevice))
+                        Settings.ConnectedDevice.Value = iDevice == 36038 ? CecLogicalAddress.AudioSystem : CecLogicalAddress.Tv;
                     }
                     break;
                   case "cec_power_on_startup":
@@ -170,7 +170,29 @@ namespace LibCECTray.controller.applications.@internal
                         Settings.TVVendor.Value = (CecVendorId)iVendor;
                     }
                     break;
-                  case "wake_devices":
+                  case "wake_device":
+                    {
+                      int iWakeDevices;
+                      if (int.TryParse(value, out iWakeDevices))
+                      {
+                        Settings.WakeDevices.Value.Clear();
+                        switch (iWakeDevices)
+                        {
+                          case 36037:
+                            Settings.WakeDevices.Value.Set(CecLogicalAddress.Tv);
+                            break;
+                          case 36038:
+                            Settings.WakeDevices.Value.Set(CecLogicalAddress.AudioSystem);
+                            break;
+                          case 36039:
+                            Settings.WakeDevices.Value.Set(CecLogicalAddress.Tv);
+                            Settings.WakeDevices.Value.Set(CecLogicalAddress.AudioSystem);
+                            break;
+                        }
+                      }
+                    }
+                    break;
+                  case "wake_devices_advanced":
                     {
                       Settings.WakeDevices.Value.Clear();
                       string[] split = value.Split(new[] { ' ' });
@@ -183,6 +205,28 @@ namespace LibCECTray.controller.applications.@internal
                     }
                     break;
                   case "standby_devices":
+                    {
+                      int iStandbyDevices;
+                      if (int.TryParse(value, out iStandbyDevices))
+                      {
+                        Settings.PowerOffDevices.Value.Clear();
+                        switch (iStandbyDevices)
+                        {
+                          case 36037:
+                            Settings.PowerOffDevices.Value.Set(CecLogicalAddress.Tv);
+                            break;
+                          case 36038:
+                            Settings.PowerOffDevices.Value.Set(CecLogicalAddress.AudioSystem);
+                            break;
+                          case 36039:
+                            Settings.PowerOffDevices.Value.Set(CecLogicalAddress.Tv);
+                            Settings.PowerOffDevices.Value.Set(CecLogicalAddress.AudioSystem);
+                            break;
+                        }
+                      }
+                    }
+                    break;
+                  case "standby_devices_advanced":
                     {
                       Settings.PowerOffDevices.Value.Clear();
                       string[] split = value.Split(new[] { ' ' });
@@ -203,6 +247,10 @@ namespace LibCECTray.controller.applications.@internal
                   case "send_inactive_source":
                     SendInactiveSource.Value = value.Equals("1") || value.ToLower().Equals("true") || value.ToLower().Equals("yes");
                     break;
+                  // 1.9.0+ settings
+                  case "pause_playback_on_deactivate":
+                    PausePlaybackOnDeactivate.Value = value.Equals("1") || value.ToLower().Equals("true") || value.ToLower().Equals("yes");
+                    break;
                 }
               }
               break;
@@ -212,6 +260,14 @@ namespace LibCECTray.controller.applications.@internal
       return gotConfig;
     }
 
+    static bool HasAdvancedDeviceIdSet(CecLogicalAddresses addresses)
+    {
+      foreach (var val in addresses.Addresses)
+        if (val != CecLogicalAddress.Tv && val != CecLogicalAddress.AudioSystem)
+          return true;
+      return false;
+    }
+
     public void SaveXMLConfiguration()
     {
       Settings.Persist();
@@ -258,7 +314,7 @@ namespace LibCECTray.controller.applications.@internal
         StringBuilder output = new StringBuilder();
         output.AppendLine("<settings>");
         output.AppendLine("<setting id=\"cec_hdmi_port\" value=\"" + Settings.HDMIPort.Value + "\" />");
-        output.AppendLine("<setting id=\"connected_device\" value=\"" + (Settings.ConnectedDevice.Value == CecLogicalAddress.AudioSystem ? 5 : 0) + "\" />");
+        output.AppendLine("<setting id=\"connected_device\" value=\"" + (Settings.ConnectedDevice.Value == CecLogicalAddress.AudioSystem ? 36038 : 36037) + "\" />");
         output.AppendLine("<setting id=\"cec_power_on_startup\" value=\"" + (Settings.ActivateSource.Value ? 1 : 0) + "\" />");
         output.AppendLine("<setting id=\"cec_power_off_shutdown\" value=\"" + (Settings.PowerOffDevices.Value.IsSet(CecLogicalAddress.Broadcast) ? 1 : 0) + "\" />");
         output.AppendLine("<setting id=\"cec_standby_screensaver\" value=\"" + (StandbyScreensaver.Value ? 1 : 0) + "\" />");
@@ -274,26 +330,55 @@ namespace LibCECTray.controller.applications.@internal
         output.AppendLine("<setting id=\"device_type\" value=\"" + (int)Settings.DeviceType.Value + "\" />");
         output.AppendLine("<setting id=\"tv_vendor\" value=\"" + string.Format("{0,6:X}", Settings.OverrideTVVendor.Value ? (int)Settings.TVVendor.Value : 0).Trim() + "\" />");
 
-        output.Append("<setting id=\"wake_devices\" value=\"");
-        StringBuilder strWakeDevices = new StringBuilder();
-        foreach (CecLogicalAddress addr in Settings.WakeDevices.Value.Addresses)
-          if (addr != CecLogicalAddress.Unknown)
-            strWakeDevices.Append(" " + (int)addr);
-        output.Append(strWakeDevices.ToString().Trim());
-        output.AppendLine("\" />");
+        if (HasAdvancedDeviceIdSet(Settings.WakeDevices.Value))
+        {
+          output.Append("<setting id=\"wake_devices_advanced\" value=\"");
+          StringBuilder strWakeDevices = new StringBuilder();
+          foreach (CecLogicalAddress addr in Settings.WakeDevices.Value.Addresses)
+            if (addr != CecLogicalAddress.Unknown)
+              strWakeDevices.Append(" " + (int)addr);
+          output.Append(strWakeDevices.ToString().Trim());
+          output.AppendLine("\" />");
+        }
+
+        if (Settings.WakeDevices.Value.IsSet(CecLogicalAddress.Tv) &&
+            Settings.WakeDevices.Value.IsSet(CecLogicalAddress.AudioSystem))
+          output.Append("<setting id=\"wake_devices\" value=\"36039\">");
+        else if (Settings.WakeDevices.Value.IsSet(CecLogicalAddress.Tv))
+          output.Append("<setting id=\"wake_devices\" value=\"36037\">");
+        else if (Settings.WakeDevices.Value.IsSet(CecLogicalAddress.AudioSystem))
+          output.Append("<setting id=\"wake_devices\" value=\"36038\">");
+        else
+          output.Append("<setting id=\"wake_devices\" value=\"231\">");
+
+        if (HasAdvancedDeviceIdSet(Settings.PowerOffDevices.Value))
+        {
+          output.Append("<setting id=\"standby_devices_advanced\" value=\"");
+          StringBuilder strSleepDevices = new StringBuilder();
+          foreach (CecLogicalAddress addr in Settings.PowerOffDevices.Value.Addresses)
+            if (addr != CecLogicalAddress.Unknown)
+              strSleepDevices.Append(" " + (int) addr);
+          output.Append(strSleepDevices.ToString().Trim());
+          output.AppendLine("\" />");
+        }
 
-        output.Append("<setting id=\"standby_devices\" value=\"");
-        StringBuilder strSleepDevices = new StringBuilder();
-        foreach (CecLogicalAddress addr in Settings.PowerOffDevices.Value.Addresses)
-          if (addr != CecLogicalAddress.Unknown)
-            strSleepDevices.Append(" " + (int)addr);
-        output.Append(strSleepDevices.ToString().Trim());
-        output.AppendLine("\" />");
+        if (Settings.PowerOffDevices.Value.IsSet(CecLogicalAddress.Tv) &&
+            Settings.PowerOffDevices.Value.IsSet(CecLogicalAddress.AudioSystem))
+          output.Append("<setting id=\"standby_devices\" value=\"36039\">");
+        else if (Settings.PowerOffDevices.Value.IsSet(CecLogicalAddress.Tv))
+          output.Append("<setting id=\"standby_devices\" value=\"36037\">");
+        else if (Settings.PowerOffDevices.Value.IsSet(CecLogicalAddress.AudioSystem))
+          output.Append("<setting id=\"standby_devices\" value=\"36038\">");
+        else
+          output.Append("<setting id=\"standby_devices\" value=\"231\">");
 
         // only supported by 1.5.1+ clients
         output.AppendLine("<!-- the following lines are only supported by v1.5.1+ clients -->");
         output.AppendLine("<setting id=\"send_inactive_source\" value=\"" + (SendInactiveSource.Value ? 1 : 0) + "\" />");
 
+        // only supported by 1.9.0+ clients
+        output.AppendLine("<setting id=\"pause_playback_on_deactivate\" value=\"" + (PausePlaybackOnDeactivate.Value ? 1 : 0) + "\" />");
+
         output.AppendLine("</settings>");
         writer.Write(output.ToString());
         writer.Close();
@@ -372,5 +457,19 @@ namespace LibCECTray.controller.applications.@internal
         return Settings[ProcessName + "_send_inactive_source"].AsSettingBool;
       }
     }
+
+    public CECSettingBool PausePlaybackOnDeactivate
+    {
+      get
+      {
+        if (!Settings.ContainsKey(ProcessName + "_pause_playback_on_deactivate"))
+        {
+          CECSettingBool setting = new CECSettingBool(ProcessName + "_pause_playback_on_deactivate", Resources.app_pause_playback_on_deactivate, true, null);
+          Settings.Load(setting);
+          Settings[ProcessName + "_pause_playback_on_deactivate"] = setting;
+        }
+        return Settings[ProcessName + "_pause_playback_on_deactivate"].AsSettingBool;
+      }
+    }
        }
 }
index e1b4b126db7f7427fce5b9b1a4d76c5e589ab3a3..df02422e9089e19f49deecefa87563d19e668c19 100644 (file)
@@ -39,6 +39,7 @@
       this.bSaveConfig = new System.Windows.Forms.Button();
       this.cbStandbyTvStandby = new System.Windows.Forms.CheckBox();
       this.cbInactiveSource = new System.Windows.Forms.CheckBox();
+      this.cbPauseOnDeactivate = new System.Windows.Forms.CheckBox();
       ((System.ComponentModel.ISupportInitialize)(this.buttonBindingSource)).BeginInit();
       this.SuspendLayout();
       // 
       this.cbInactiveSource.Text = "app_send_inactive_source";
       this.cbInactiveSource.UseVisualStyleBackColor = true;
       // 
+      // cbPauseOnDeactivate
+      // 
+      this.cbPauseOnDeactivate.AutoSize = true;
+      this.cbPauseOnDeactivate.Enabled = false;
+      this.cbPauseOnDeactivate.Location = new System.Drawing.Point(11, 135);
+      this.cbPauseOnDeactivate.Name = "cbPauseOnDeactivate";
+      this.cbPauseOnDeactivate.Size = new System.Drawing.Size(202, 17);
+      this.cbPauseOnDeactivate.TabIndex = 59;
+      this.cbPauseOnDeactivate.Text = "app_pause_playback_on_deactivate";
+      this.cbPauseOnDeactivate.UseVisualStyleBackColor = true;
+      // 
       // XBMCControllerUI
       // 
       this.ClientSize = new System.Drawing.Size(576, 306);
+      this.Controls.Add(this.cbPauseOnDeactivate);
       this.Controls.Add(this.cbInactiveSource);
       this.Controls.Add(this.cbStandbyTvStandby);
       this.Controls.Add(this.bSaveConfig);
     private System.Windows.Forms.Button bSaveConfig;
     private System.Windows.Forms.CheckBox cbStandbyTvStandby;
     private System.Windows.Forms.CheckBox cbInactiveSource;
+    private System.Windows.Forms.CheckBox cbPauseOnDeactivate;
        }
 }
\ No newline at end of file
index 9dc6e611cd9ee39233a7ae0ba2803998a45298e5..7c2226f8c2002e9e10b3129ed1fbac8b2ed1c67c 100644 (file)
@@ -55,6 +55,7 @@ namespace LibCECTray.controller.applications.@internal
       _controller.StandbyScreensaver.ReplaceControls(this, Controls, cbStandbyScreensaver);
       _controller.PowerOffOnStandby.ReplaceControls(this, Controls, cbStandbyTvStandby);
       _controller.SendInactiveSource.ReplaceControls(this, Controls, cbInactiveSource);
+      _controller.PausePlaybackOnDeactivate.ReplaceControls(this, Controls, cbPauseOnDeactivate);
 
       SetEnabled(false);
     }
@@ -77,6 +78,7 @@ namespace LibCECTray.controller.applications.@internal
       SetControlEnabled(bSaveConfig, val);
       SetControlEnabled(bLoadConfig, val);
       SetControlEnabled(bConfigure, _controller.CanConfigureProcess && val);
+      SetControlEnabled(_controller.PausePlaybackOnDeactivate.ValueControl, val);
     }
 
     public override void SetStartButtonEnabled(bool val)