cb84a00b403d6b75b22087f984d26f47fd2f2bde
[deb_libcec.git] / src / cec-config-gui / actions / ConnectToDevice.cs
1 using CecSharp;
2 using System.Windows.Forms;
3
4 namespace CecConfigGui.actions
5 {
6 class ConnectToDevice : UpdateProcess
7 {
8 public ConnectToDevice(ref LibCecSharp lib, LibCECConfiguration config)
9 {
10 Lib = lib;
11 Config = config;
12 }
13
14 public override void Process()
15 {
16 SendEvent(UpdateEventType.StatusText, "Detecting TV vendor...");
17 SendEvent(UpdateEventType.ProgressBar, 25);
18 SendEvent(UpdateEventType.TVVendorId, (int)Lib.GetDeviceVendorId(CecLogicalAddress.Tv));
19
20 SendEvent(UpdateEventType.StatusText, "Detecting menu language...");
21 SendEvent(UpdateEventType.ProgressBar, 40);
22 SendEvent(UpdateEventType.MenuLanguage, Lib.GetDeviceMenuLanguage(CecLogicalAddress.Tv));
23
24 SendEvent(UpdateEventType.ProgressBar, 50);
25 SendEvent(UpdateEventType.StatusText, "Detecting AVR devices...");
26
27 bool hasAVRDevice = Lib.IsActiveDevice(CecLogicalAddress.AudioSystem);
28 SendEvent(UpdateEventType.HasAVRDevice, hasAVRDevice);
29
30 if (hasAVRDevice)
31 {
32 SendEvent(UpdateEventType.ProgressBar, 75);
33 SendEvent(UpdateEventType.StatusText, "Detecting AVR vendor...");
34 SendEvent(UpdateEventType.AVRVendorId, (int)Lib.GetDeviceVendorId(CecLogicalAddress.AudioSystem));
35 }
36
37 if (!Lib.GetDevicePowerStatus(CecLogicalAddress.Tv).Equals(CecPowerStatus.On))
38 {
39 SendEvent(UpdateEventType.ProgressBar, 80);
40 SendEvent(UpdateEventType.StatusText, "Activating the source...");
41 Lib.SetActiveSource(CecDeviceType.Reserved);
42 }
43
44 SendEvent(UpdateEventType.ProgressBar, 90);
45 SendEvent(UpdateEventType.StatusText, "Reading device configuration...");
46
47 Lib.GetCurrentConfiguration(Config);
48 SendEvent(Config);
49
50 SendEvent(UpdateEventType.ProgressBar, 100);
51 SendEvent(UpdateEventType.StatusText, "Ready.");
52 }
53
54 private LibCecSharp Lib;
55 private LibCECConfiguration Config;
56 }
57 }