コード例 #1
0
ファイル: CardAtsc.cs プロジェクト: usermonk/MediaPortal-1
        private void mpButtonScanTv_Click(object sender, EventArgs e)
        {
            if (_isScanning == false)
            {
                mpComboBoxTuningMode.Enabled = false;

                TvBusinessLayer layer = new TvBusinessLayer();
                Card            card  = layer.GetCardByDevicePath(RemoteControl.Instance.CardDevice(_cardNumber));
                if (card.Enabled == false)
                {
                    MessageBox.Show(this, "Tuner is disabled. Please enable the tuner before scanning.");
                    return;
                }
                if (!RemoteControl.Instance.CardPresent(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 (RemoteControl.Instance.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;
                }
                SimpleFileName tuningFile = (SimpleFileName)mpComboBoxFrequencies.SelectedItem;
                _atscChannels = (List <ATSCTuning>)fileFilters.LoadList(tuningFile.FileName, typeof(List <ATSCTuning>));
                if (_atscChannels == null)
                {
                    return;
                }
                Thread scanThread = new Thread(DoScan);
                scanThread.Name = "ATSC scan thread";
                scanThread.Start();
                listViewStatus.Items.Clear();
            }
            else
            {
                _stopScanning = true;
            }
        }
コード例 #2
0
        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
                TvBusinessLayer layer = new TvBusinessLayer();
                Card            card  = layer.GetCardByDevicePath(RemoteControl.Instance.CardDevice(_cardNumber));
                if (card.Enabled == false)
                {
                    MessageBox.Show(this, "Tuner is disabled. Please enable the tuner before scanning.");
                    return;
                }
                if (!RemoteControl.Instance.CardPresent(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 (RemoteControl.Instance.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 = RemoteControl.Instance.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;
            }
        }