/
CardDvbC.cs
753 lines (656 loc) · 26.6 KB
/
CardDvbC.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
#region Copyright (C) 2005-2011 Team MediaPortal
// Copyright (C) 2005-2011 Team MediaPortal
// http://www.team-mediaportal.com
//
// MediaPortal is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// MediaPortal is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with MediaPortal. If not, see <http://www.gnu.org/licenses/>.
#endregion
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Serialization;
using DirectShowLib.BDA;
using Mediaportal.TV.Server.SetupControls;
using Mediaportal.TV.Server.SetupTV.Sections.CIMenu;
using Mediaportal.TV.Server.SetupTV.Sections.Helpers;
using Mediaportal.TV.Server.TVControl;
using Mediaportal.TV.Server.TVControl.ServiceAgents;
using Mediaportal.TV.Server.TVDatabase.Entities;
using Mediaportal.TV.Server.TVDatabase.Entities.Enums;
using Mediaportal.TV.Server.TVDatabase.Entities.Factories;
using Mediaportal.TV.Server.TVLibrary.Interfaces;
using Mediaportal.TV.Server.TVLibrary.Interfaces.Implementations.Channels;
using Mediaportal.TV.Server.TVLibrary.Interfaces.Interfaces;
using Mediaportal.TV.Server.TVLibrary.Interfaces.Logging;
using Mediaportal.TV.Server.TVService.Interfaces.Services;
namespace Mediaportal.TV.Server.SetupTV.Sections
{
public partial class CardDvbC : SectionSettings
{
#region Member variables
private readonly int _cardNumber;
private List<DVBCTuning> _dvbcChannels = new List<DVBCTuning>();
private String buttonText;
private FileFilters fileFilters;
private CI_Menu_Dialog ciMenuDialog; // ci menu dialog object
private ScanState scanState; // scan state
private bool _isScanning
{
get { return scanState == ScanState.Scanning || scanState == ScanState.Cancel; }
}
#endregion
#region Properties
/// <summary>
/// Returns active scan type
/// </summary>
private ScanTypes ActiveScanType
{
get
{
if (checkBoxAdvancedTuning.Checked == false)
{
return ScanTypes.Predefined;
}
if (scanPredefProvider.Checked == true)
{
return ScanTypes.Predefined;
}
if (scanSingleTransponder.Checked == true)
{
return ScanTypes.SingleTransponder;
}
if (scanNIT.Checked == true)
{
return ScanTypes.NIT;
}
return ScanTypes.Predefined;
}
}
#endregion
#region Constructors
private void EnableSections() {}
public CardDvbC()
: this("DVBC") {}
public CardDvbC(string name)
: base(name) {}
public CardDvbC(string name, int cardNumber)
: base(name)
{
_cardNumber = cardNumber;
InitializeComponent();
//insert complete ci menu dialog to tab
Card dbCard = ServiceAgents.Instance.CardServiceAgent.GetCard(_cardNumber, CardIncludeRelationEnum.None);
if (dbCard.UseConditionalAccess == true)
{
ciMenuDialog = new CI_Menu_Dialog(_cardNumber);
tabPageCIMenu.Controls.Add(ciMenuDialog);
}
else
{
tabPageCIMenu.Dispose();
}
base.Text = name;
Init();
}
#endregion
#region Init and Section (de-)Activate
private void Init()
{
// set to same positions as progress
mpGrpAdvancedTuning.Top = mpGrpScanProgress.Top;
mpComboBoxCountry.Items.Clear();
try
{
fileFilters = new FileFilters("DVBC", ref mpComboBoxCountry, ref mpComboBoxRegion);
}
catch (Exception)
{
MessageBox.Show(@"Unable to open TuningParameters\dvbc\*.xml");
return;
}
SetButtonState();
SetDefaults();
buttonText = mpButtonScanTv.Text;
checkBoxCreateSignalGroup.Text = "Create \"" + TvConstants.TvGroupNames.DVBC + "\" group";
scanState = ScanState.Initialized;
}
public override void OnSectionActivated()
{
base.OnSectionActivated();
mpComboBoxMod.SelectedIndex = 3;
UpdateStatus();
SetDefaults();
if (ciMenuDialog != null)
{
ciMenuDialog.OnSectionActivated();
}
}
public override void OnSectionDeActivated()
{
base.OnSectionDeActivated();
PersistState();
if (ciMenuDialog != null)
{
ciMenuDialog.OnSectionDeActivated();
}
}
#endregion
#region Loading and Saving functions
/// <summary>
/// Saves current transponder list
/// </summary>
private void SaveTransponderList()
{
if (_dvbcChannels.Count != 0)
{
String filePath = String.Format(@"{0}\TuningParameters\dvbc\Manual_Scans.{1}.xml", PathManager.GetDataPath,
DateTime.Now.ToString("yyyy-MM-dd"));
SaveList(filePath);
PersistState();
Init(); // refresh list
}
}
/// <summary>
/// Saves a new list with found transponders
/// </summary>
/// <param name="fileName">Path for output filename</param>
private void SaveList(string fileName)
{
try
{
System.IO.TextWriter parFileXML = System.IO.File.CreateText(fileName);
XmlSerializer xmlSerializer = new XmlSerializer(typeof (List<DVBCTuning>));
xmlSerializer.Serialize(parFileXML, _dvbcChannels);
parFileXML.Close();
}
catch (Exception ex)
{
this.LogError(ex, "Error saving tuningdetails");
MessageBox.Show("Transponder list could not be saved, check error.log for details.");
}
}
/// <summary>
/// Load existing list from xml file
/// </summary>
/// <param name="fileName">Path for input filen</param>
private void LoadList(string fileName)
{
try
{
XmlReader parFileXML = XmlReader.Create(fileName);
XmlSerializer xmlSerializer = new XmlSerializer(typeof (List<DVBCTuning>));
_dvbcChannels = (List<DVBCTuning>)xmlSerializer.Deserialize(parFileXML);
parFileXML.Close();
}
catch (Exception ex)
{
this.LogError(ex, "Error loading tuningdetails");
MessageBox.Show("Transponder list could not be loaded, check error.log for details.");
}
}
/// <summary>
/// Reads previous settings and assign them to controls
/// </summary>
private void SetDefaults()
{
int index = Math.Max(ServiceAgents.Instance.SettingServiceAgent.GetValue("dvbc" + _cardNumber + "Country", 0), 0);
// limit to >= 0
if (index < mpComboBoxCountry.Items.Count)
{
mpComboBoxCountry.SelectedIndex = index;
}
index = Math.Max(ServiceAgents.Instance.SettingServiceAgent.GetValue("dvbc" + _cardNumber + "Region", 0), 0); // limit to >= 0
if (index < mpComboBoxRegion.Items.Count)
{
mpComboBoxRegion.SelectedIndex = index;
}
textBoxFreq.Text = ServiceAgents.Instance.SettingServiceAgent.GetValue("dvbc" + _cardNumber + "Freq", "306000");
textBoxSymbolRate.Text = ServiceAgents.Instance.SettingServiceAgent.GetValue("dvbc" + _cardNumber + "Symbolrate", "6900");
index = Math.Max(ServiceAgents.Instance.SettingServiceAgent.GetValue("dvbc" + _cardNumber + "Modulation", 3), 0);
// limit to >= 0
if (index < mpComboBoxMod.Items.Count)
{
mpComboBoxMod.SelectedIndex = index;
}
checkBoxCreateGroups.Checked = (ServiceAgents.Instance.SettingServiceAgent.GetValue("dvbc" + _cardNumber + "creategroups", false));
checkBoxCreateSignalGroup.Checked =
(ServiceAgents.Instance.SettingServiceAgent.GetValue("dvbc" + _cardNumber + "createsignalgroup", false));
}
/// <summary>
/// Saves control status
/// </summary>
private void PersistState()
{
ServiceAgents.Instance.SettingServiceAgent.SaveValue("dvbc" + _cardNumber + "Country", mpComboBoxCountry.SelectedIndex);
ServiceAgents.Instance.SettingServiceAgent.SaveValue("dvbc" + _cardNumber + "Region", mpComboBoxRegion.SelectedIndex);
ServiceAgents.Instance.SettingServiceAgent.SaveValue("dvbc" + _cardNumber + "Freq", textBoxFreq.Text);
ServiceAgents.Instance.SettingServiceAgent.SaveValue("dvbc" + _cardNumber + "Symbolrate", textBoxSymbolRate.Text);
ServiceAgents.Instance.SettingServiceAgent.SaveValue("dvbc" + _cardNumber + "Modulation", mpComboBoxMod.SelectedIndex);
ServiceAgents.Instance.SettingServiceAgent.SaveValue("dvbc" + _cardNumber + "creategroups", checkBoxCreateGroups.Checked);
ServiceAgents.Instance.SettingServiceAgent.SaveValue("dvbc" + _cardNumber + "createsignalgroup", checkBoxCreateSignalGroup.Checked);
}
/// <summary>
/// Get Tuning details from manual scan section
/// </summary>
/// <returns></returns>
private DVBCChannel GetManualTuning()
{
DVBCChannel tuneChannel = new DVBCChannel();
tuneChannel.Frequency = Int32.Parse(textBoxFreq.Text);
tuneChannel.ModulationType = (ModulationType)mpComboBoxMod.SelectedIndex;
tuneChannel.SymbolRate = Int32.Parse(textBoxSymbolRate.Text);
return tuneChannel;
}
#endregion
#region Scan handling
private void InitScanProcess()
{
// once completed reset to new beginning
switch (scanState)
{
case ScanState.Done:
scanState = ScanState.Initialized;
listViewStatus.Items.Clear();
SetButtonState();
return;
case ScanState.Initialized:
// common checks
Card card = ServiceAgents.Instance.CardServiceAgent.GetCardByDevicePath(ServiceAgents.Instance.ControllerServiceAgent.CardDevice(_cardNumber));
if (card.Enabled == false)
{
MessageBox.Show(this, "Tuner is disabled. Please enable the tuner before scanning.");
return;
}
if (!ServiceAgents.Instance.ControllerServiceAgent.IsCardPresent(card.IdCard))
{
MessageBox.Show(this, "Tuner is not found. Please make sure the tuner is present before scanning.");
return;
}
// Check if the card is locked for scanning.
IUser user;
if (ServiceAgents.Instance.ControllerServiceAgent.IsCardInUse(_cardNumber, out user))
{
MessageBox.Show(this,
"Tuner is locked. Scanning is not possible at the moment. Perhaps you are using another part of a hybrid card?");
return;
}
SetButtonState();
ShowActiveGroup(1); // force progess visible
// End common checks
listViewStatus.Items.Clear();
// Scan type dependent handling
_dvbcChannels.Clear();
switch (ActiveScanType)
{
// use tuning details from file
case ScanTypes.Predefined:
CustomFileName tuningFile = (CustomFileName)mpComboBoxRegion.SelectedItem;
_dvbcChannels = (List<DVBCTuning>)fileFilters.LoadList(tuningFile.FileName, typeof (List<DVBCTuning>));
if (_dvbcChannels == null)
{
_dvbcChannels = new List<DVBCTuning>();
}
break;
// scan Network Information Table for transponder info
case ScanTypes.NIT:
_dvbcChannels.Clear();
DVBCChannel tuneChannel = GetManualTuning();
listViewStatus.Items.Clear();
string line = String.Format("Scan freq:{0} {1} symbolrate:{2} ...", tuneChannel.Frequency,
tuneChannel.ModulationType, tuneChannel.SymbolRate);
ListViewItem item = listViewStatus.Items.Add(new ListViewItem(line));
item.EnsureVisible();
IChannel[] channels = ServiceAgents.Instance.ControllerServiceAgent.ScanNIT(_cardNumber, tuneChannel);
if (channels != null)
{
for (int i = 0; i < channels.Length; ++i)
{
DVBCChannel ch = (DVBCChannel)channels[i];
_dvbcChannels.Add(ch.TuningInfo);
item = listViewStatus.Items.Add(new ListViewItem(ch.TuningInfo.ToString()));
item.EnsureVisible();
}
}
ListViewItem lastItem =
listViewStatus.Items.Add(
new ListViewItem(String.Format("Scan done, found {0} transponders...", _dvbcChannels.Count)));
lastItem.EnsureVisible();
// automatically save list for re-use
SaveTransponderList();
break;
// scan only single inputted transponder
case ScanTypes.SingleTransponder:
DVBCChannel singleTuneChannel = GetManualTuning();
_dvbcChannels.Add(singleTuneChannel.TuningInfo);
break;
}
if (_dvbcChannels.Count != 0)
{
StartScanThread();
}
else
{
scanState = ScanState.Done;
SetButtonState();
}
break;
case ScanState.Scanning:
scanState = ScanState.Cancel;
SetButtonState();
break;
case ScanState.Cancel:
return;
}
}
private void StartScanThread()
{
Thread scanThread = new Thread(DoScan);
scanThread.Name = "DVB-C scan thread";
scanThread.Start();
}
/// <summary>
/// Updates signal level info
/// </summary>
private void UpdateStatus()
{
progressBarLevel.Value = Math.Min(100, ServiceAgents.Instance.ControllerServiceAgent.SignalLevel(_cardNumber));
progressBarQuality.Value = Math.Min(100, ServiceAgents.Instance.ControllerServiceAgent.SignalQuality(_cardNumber));
}
#region Scan Thread
/// <summary>
/// Scan Thread
/// </summary>
private void DoScan()
{
suminfo tv = new suminfo();
suminfo radio = new suminfo();
IUser user = new User();
user.CardId = _cardNumber;
try
{
scanState = ScanState.Scanning;
if (_dvbcChannels.Count == 0)
return;
ServiceAgents.Instance.ControllerServiceAgent.EpgGrabberEnabled = false;
SetButtonState();
Card card = ServiceAgents.Instance.CardServiceAgent.GetCardByDevicePath(ServiceAgents.Instance.ControllerServiceAgent.CardDevice(_cardNumber));
for (int index = 0; index < _dvbcChannels.Count; ++index)
{
if (scanState == ScanState.Cancel)
return;
float percent = ((float)(index)) / _dvbcChannels.Count;
percent *= 100f;
if (percent > 100f)
percent = 100f;
progressBar1.Value = (int)percent;
Application.DoEvents();
DVBCChannel tuneChannel = new DVBCChannel(_dvbcChannels[index]); // new DVBCChannel();
string line = String.Format("{0}tp- {1}", 1 + index, tuneChannel.TuningInfo.ToString());
ListViewItem item = listViewStatus.Items.Add(new ListViewItem(line));
item.EnsureVisible();
UpdateStatus();
if (index == 0)
{
ServiceAgents.Instance.ControllerServiceAgent.Scan(user.Name, user.CardId, out user, tuneChannel, -1);
UpdateStatus();
}
IChannel[] channels = ServiceAgents.Instance.ControllerServiceAgent.Scan(_cardNumber, tuneChannel);
UpdateStatus();
if (channels == null || channels.Length == 0)
{
if (ServiceAgents.Instance.ControllerServiceAgent.TunerLocked(_cardNumber) == false)
{
line = String.Format("{0}tp- {1} {2} {3}:No signal", 1 + index, tuneChannel.Frequency,
tuneChannel.ModulationType, tuneChannel.SymbolRate);
item.Text = line;
item.ForeColor = Color.Red;
continue;
}
line = String.Format("{0}tp- {1} {2} {3}:Nothing found", 1 + index, tuneChannel.Frequency,
tuneChannel.ModulationType, tuneChannel.SymbolRate);
item.Text = line;
item.ForeColor = Color.Red;
continue;
}
radio.newChannel = 0;
radio.updChannel = 0;
tv.newChannel = 0;
tv.updChannel = 0;
for (int i = 0; i < channels.Length; ++i)
{
Channel dbChannel;
DVBCChannel channel = (DVBCChannel)channels[i];
bool exists;
TuningDetail currentDetail;
//Check if we already have this tuningdetail. The user has the option to enable channel move detection...
if (checkBoxEnableChannelMoveDetection.Checked)
{
//According to the DVB specs ONID + SID is unique, therefore we do not need to use the TSID to identify a service.
//The DVB spec recommends that the SID should not change if a service moves. This theoretically allows us to
//track channel movements.
TuningDetailSearchEnum tuningDetailSearchEnum = TuningDetailSearchEnum.NetworkId;
tuningDetailSearchEnum |= TuningDetailSearchEnum.ServiceId;
currentDetail = ServiceAgents.Instance.ChannelServiceAgent.GetTuningDetailCustom(channel, tuningDetailSearchEnum);
}
else
{
//There are certain providers that do not maintain unique ONID + SID combinations.
//In those cases, ONID + TSID + SID is generally unique. The consequence of using the TSID to identify
//a service is that channel movement tracking won't work (each transponder/mux should have its own TSID).
currentDetail = ServiceAgents.Instance.ChannelServiceAgent.GetTuningDetail(channel);
}
if (currentDetail == null)
{
//add new channel
exists = false;
dbChannel = ChannelFactory.CreateChannel(channel.Name);
dbChannel.SortOrder = 10000;
if (channel.LogicalChannelNumber >= 1)
{
dbChannel.SortOrder = channel.LogicalChannelNumber;
}
dbChannel.MediaType = (int) channel.MediaType;
dbChannel = ServiceAgents.Instance.ChannelServiceAgent.SaveChannel(dbChannel);
dbChannel.AcceptChanges();
}
else
{
exists = true;
dbChannel = currentDetail.Channel;
}
if (dbChannel.MediaType == (int)MediaTypeEnum.TV)
{
ChannelGroup group = ServiceAgents.Instance.ChannelGroupServiceAgent.GetOrCreateGroup(TvConstants.TvGroupNames.AllChannels, MediaTypeEnum.TV);
MappingHelper.AddChannelToGroup(ref dbChannel, @group);
if (checkBoxCreateSignalGroup.Checked)
{
group = ServiceAgents.Instance.ChannelGroupServiceAgent.GetOrCreateGroup(TvConstants.TvGroupNames.DVBC, MediaTypeEnum.TV);
MappingHelper.AddChannelToGroup(ref dbChannel, @group);
}
if (checkBoxCreateGroups.Checked)
{
group = ServiceAgents.Instance.ChannelGroupServiceAgent.GetOrCreateGroup(channel.Provider, MediaTypeEnum.TV);
MappingHelper.AddChannelToGroup(ref dbChannel, @group);
}
}
else if (dbChannel.MediaType == (int)MediaTypeEnum.Radio)
{
ChannelGroup group = ServiceAgents.Instance.ChannelGroupServiceAgent.GetOrCreateGroup(TvConstants.RadioGroupNames.AllChannels, MediaTypeEnum.Radio);
MappingHelper.AddChannelToGroup(ref dbChannel, @group);
if (checkBoxCreateSignalGroup.Checked)
{
group = ServiceAgents.Instance.ChannelGroupServiceAgent.GetOrCreateGroup(TvConstants.RadioGroupNames.DVBC, MediaTypeEnum.Radio);
MappingHelper.AddChannelToGroup(ref dbChannel, @group);
}
if (checkBoxCreateGroups.Checked)
{
group = ServiceAgents.Instance.ChannelGroupServiceAgent.GetOrCreateGroup(channel.Provider, MediaTypeEnum.Radio);
MappingHelper.AddChannelToGroup(ref dbChannel, @group);
}
}
if (currentDetail == null)
{
ServiceAgents.Instance.ChannelServiceAgent.AddTuningDetail(dbChannel.IdChannel, channel);
}
else
{
//update tuning details...
ServiceAgents.Instance.ChannelServiceAgent.UpdateTuningDetail(dbChannel.IdChannel, currentDetail.IdTuning, channel);
}
if (channel.MediaType == MediaTypeEnum.TV)
{
if (exists)
{
tv.updChannel++;
}
else
{
tv.newChannel++;
tv.newChannels.Add(channel);
}
}
if (channel.MediaType == MediaTypeEnum.Radio)
{
if (exists)
{
radio.updChannel++;
}
else
{
radio.newChannel++;
radio.newChannels.Add(channel);
}
}
MappingHelper.AddChannelToCard(dbChannel, card, false);
line = String.Format("{0}tp- {1} {2} {3}:New TV/Radio:{4}/{5} Updated TV/Radio:{6}/{7}", 1 + index,
tuneChannel.Frequency, tuneChannel.ModulationType, tuneChannel.SymbolRate,
tv.newChannel, radio.newChannel, tv.updChannel, radio.updChannel);
item.Text = line;
}
tv.updChannelSum += tv.updChannel;
radio.updChannelSum += radio.updChannel;
}
}
catch (Exception ex)
{
this.LogError(ex);
}
finally
{
ServiceAgents.Instance.ControllerServiceAgent.StopCard(user.CardId);
ServiceAgents.Instance.ControllerServiceAgent.EpgGrabberEnabled = true;
progressBar1.Value = 100;
scanState = ScanState.Done;
SetButtonState();
}
listViewStatus.Items.Add(
new ListViewItem(String.Format("Total radio channels updated:{0}, new:{1}", radio.updChannelSum,
radio.newChannelSum)));
foreach (IChannel newChannel in radio.newChannels)
{
listViewStatus.Items.Add(new ListViewItem(String.Format(" -> new channel: {0}", newChannel.Name)));
}
listViewStatus.Items.Add(
new ListViewItem(String.Format("Total tv channels updated:{0}, new:{1}", tv.updChannelSum, tv.newChannelSum)));
foreach (IChannel newChannel in tv.newChannels)
{
listViewStatus.Items.Add(new ListViewItem(String.Format(" -> new channel: {0}", newChannel.Name)));
}
ListViewItem lastItem = listViewStatus.Items.Add(new ListViewItem("Scan done..."));
lastItem.EnsureVisible();
}
#endregion
#endregion
#region GUI handling
/// <summary>
/// Sets correct button state
/// </summary>
private void SetButtonState()
{
mpComboBoxCountry.Enabled = !_isScanning && ActiveScanType == ScanTypes.Predefined;
mpComboBoxRegion.Enabled = !_isScanning && ActiveScanType == ScanTypes.Predefined;
textBoxFreq.Enabled = ActiveScanType != ScanTypes.Predefined;
textBoxSymbolRate.Enabled = ActiveScanType != ScanTypes.Predefined;
mpComboBoxMod.Enabled = ActiveScanType != ScanTypes.Predefined;
int forceProgress = 0;
switch (scanState)
{
default:
case ScanState.Initialized:
mpButtonScanTv.Text = "Scan for channels";
break;
case ScanState.Scanning:
mpButtonScanTv.Text = "Cancel...";
break;
case ScanState.Cancel:
mpButtonScanTv.Text = "Cancelling...";
break;
case ScanState.Done:
mpButtonScanTv.Text = "New scan";
forceProgress = 1; // leave window open
break;
}
ShowActiveGroup(forceProgress);
}
/// <summary>
/// Show either scan option or progress
/// </summary>
/// <param name="ForceShowProgress">1 to force progress visible</param>
private void ShowActiveGroup(int ForceShowProgress)
{
if (ForceShowProgress == 1)
{
mpGrpAdvancedTuning.Visible = false;
mpGrpScanProgress.Visible = true;
checkBoxCreateGroups.Enabled = false;
checkBoxCreateSignalGroup.Enabled = false;
checkBoxEnableChannelMoveDetection.Enabled = false;
checkBoxAdvancedTuning.Enabled = false;
}
else
{
mpGrpAdvancedTuning.Visible = checkBoxAdvancedTuning.Checked && !_isScanning;
mpGrpScanProgress.Visible = _isScanning;
checkBoxCreateGroups.Enabled = !_isScanning;
checkBoxCreateSignalGroup.Enabled = !_isScanning;
checkBoxEnableChannelMoveDetection.Enabled = !_isScanning;
checkBoxAdvancedTuning.Enabled = !_isScanning;
}
if (mpGrpAdvancedTuning.Visible)
{
mpGrpAdvancedTuning.BringToFront();
}
if (mpGrpScanProgress.Visible)
{
mpGrpScanProgress.BringToFront();
}
UpdateZOrder();
Application.DoEvents();
Thread.Sleep(100);
}
#endregion
#region GUI event handlers
private void mpButtonScanTv_Click_1(object sender, EventArgs e)
{
InitScanProcess();
}
private void UpdateGUIControls(object sender, EventArgs e)
{
SetButtonState();
}
#endregion
}
}