LibCecSharp: more cosmetics
[deb_libcec.git] / src / cec-config-gui / actions / ConnectToDevice.cs
index 43d786eccf1df168f9751e447f539c0583e98882..fedc31398e700c7721b9bb89f7f91ec77f51424a 100644 (file)
@@ -18,21 +18,35 @@ namespace CecConfigGui.actions
 
       //TODO read the com port setting from the configuration
       CecAdapter[] adapters = Lib.FindAdapters(string.Empty);
-      if (adapters.Length == 0 || !Lib.Open(adapters[0].ComPort, 10000))
+      if (adapters.Length == 0)
       {
-        MessageBox.Show("Could not connect to any CEC adapter. Please check your configuration and try again.", "Pulse-Eight USB-CEC Adapter", MessageBoxButtons.OK);
-        Application.Exit();
+        DialogResult result = MessageBox.Show("Could not detect to any CEC adapter. Please check your configuration. Do you want to try again?", "Pulse-Eight USB-CEC Adapter", MessageBoxButtons.YesNo);
+        if (result == DialogResult.No)
+          Application.Exit();
+        else
+          adapters = Lib.FindAdapters(string.Empty);
+      }
+
+      while (!Lib.Open(adapters[0].ComPort, 10000))
+      {
+        DialogResult result = MessageBox.Show("Could not connect to any CEC adapter. Please check your configuration. Do you want to try again?", "Pulse-Eight USB-CEC Adapter", MessageBoxButtons.YesNo);
+        if (result == DialogResult.No)
+          Application.Exit();
       }
 
-      SendEvent(UpdateEventType.StatusText, "Detecting TV vendor...");
       SendEvent(UpdateEventType.ProgressBar, 20);
+      SendEvent(UpdateEventType.StatusText, "Sending power on commands...");
+      Lib.PowerOnDevices(CecLogicalAddress.Broadcast);
+
+      SendEvent(UpdateEventType.StatusText, "Detecting TV vendor...");
+      SendEvent(UpdateEventType.ProgressBar, 30);
       SendEvent(UpdateEventType.TVVendorId, (int)Lib.GetDeviceVendorId(CecLogicalAddress.Tv));
 
       SendEvent(UpdateEventType.StatusText, "Detecting menu language...");
-      SendEvent(UpdateEventType.ProgressBar, 30);
+      SendEvent(UpdateEventType.ProgressBar, 40);
       SendEvent(UpdateEventType.MenuLanguage, Lib.GetDeviceMenuLanguage(CecLogicalAddress.Tv));
 
-      SendEvent(UpdateEventType.ProgressBar, 40);
+      SendEvent(UpdateEventType.ProgressBar, 50);
       SendEvent(UpdateEventType.StatusText, "Detecting AVR devices...");
 
       bool hasAVRDevice = Lib.IsActiveDevice(CecLogicalAddress.AudioSystem);
@@ -40,25 +54,25 @@ namespace CecConfigGui.actions
 
       if (hasAVRDevice)
       {
-        SendEvent(UpdateEventType.ProgressBar, 50);
+        SendEvent(UpdateEventType.ProgressBar, 60);
         SendEvent(UpdateEventType.StatusText, "Detecting AVR vendor...");
         SendEvent(UpdateEventType.AVRVendorId, (int)Lib.GetDeviceVendorId(CecLogicalAddress.AudioSystem));
       }
 
       if (!Lib.GetDevicePowerStatus(CecLogicalAddress.Tv).Equals(CecPowerStatus.On))
       {
-        SendEvent(UpdateEventType.ProgressBar, 60);
+        SendEvent(UpdateEventType.ProgressBar, 70);
         SendEvent(UpdateEventType.StatusText, "Activating the source...");
         Lib.SetActiveSource(CecDeviceType.Reserved);
       }
 
-      SendEvent(UpdateEventType.ProgressBar, 70);
+      SendEvent(UpdateEventType.ProgressBar, 80);
       SendEvent(UpdateEventType.StatusText, "Reading device configuration...");
 
       Lib.GetCurrentConfiguration(Config);
       SendEvent(Config);
 
-      SendEvent(UpdateEventType.ProgressBar, 80);
+      SendEvent(UpdateEventType.ProgressBar, 90);
       SendEvent(UpdateEventType.StatusText, "Polling active devices");
       SendEvent(UpdateEventType.PollDevices);