MythTV  master
channelscanner_gui.cpp
Go to the documentation of this file.
1 /* -*- Mode: c++ -*-
2  * vim: set expandtab tabstop=4 shiftwidth=4:
3  *
4  * Original Project
5  * MythTV http://www.mythtv.org
6  *
7  * Copyright (c) 2004, 2005 John Pullan <john@pullan.org>
8  * Copyright (c) 2005 - 2007 Daniel Kristjansson
9  *
10  * Description:
11  * Collection of classes to provide channel scanning functionallity
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26  * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
27  *
28  */
29 
30 // System headers
31 #include <unistd.h>
32 
33 // Std C++
34 #include <algorithm>
35 using namespace std;
36 
37 // MythTV headers
38 #include "mythdialogbox.h"
39 #include "channelscanner_gui.h"
41 #include "channelimporter.h"
42 #include "channelscan_sm.h"
43 
44 #include "channelbase.h"
45 #include "dtvsignalmonitor.h"
46 #include "dvbsignalmonitor.h"
47 #include "mpegstreamdata.h"
48 
49 #define LOC QString("ChScanGUI: ")
50 
51 static const int kCodeRejected = 0;
52 static const int kCodeAccepted = 1;
53 
55 {
56  Teardown();
57  if (m_scanMonitor)
58  {
60  }
61 }
62 
64 {
65  if (scanEvent->type() == ScannerEvent::ScanComplete)
66  {
67  if (m_scanStage)
68  m_scanStage->SetScanProgress(1.0);
69 
70  InformUser(tr("Scan complete"));
71 
72  // HACK: make channel insertion work after [21644]
74  }
75  else if (scanEvent->type() == ScannerEvent::ScanShutdown ||
76  scanEvent->type() == ScannerEvent::ScanErrored)
77  {
78  ScanDTVTransportList transports;
79  if (m_sigmonScanner)
80  {
81  m_sigmonScanner->StopScanner();
82  transports = m_sigmonScanner->GetChannelList(m_addFullTS);
83  }
84 
85  bool success = (m_iptvScanner != nullptr);
86 #ifdef USING_VBOX
87  success |= (m_vboxScanner != nullptr);
88 #endif
89 #if !defined( USING_MINGW ) && !defined( _MSC_VER )
90  success |= (m_ExternRecScanner != nullptr);
91 #endif
92 
93  Teardown();
94 
95  if (scanEvent->type() == ScannerEvent::ScanErrored)
96  {
97  QString error = scanEvent->strValue();
98  InformUser(error);
99  return;
100  }
101 
102  int ret = scanEvent->intValue();
103  if (!transports.empty() || (kCodeRejected != ret))
104  {
105  Process(transports, success);
106  }
107  }
108  else if (scanEvent->type() == ScannerEvent::AppendTextToLog)
109  {
110  if (m_scanStage)
111  m_scanStage->AppendLine(scanEvent->strValue());
112  m_messageList += scanEvent->strValue();
113  }
114 
115  if (!m_scanStage)
116  return;
117 
118  if (scanEvent->type() == ScannerEvent::SetStatusText)
119  m_scanStage->SetStatusText(scanEvent->strValue());
120  else if (scanEvent->type() == ScannerEvent::SetStatusTitleText)
121  m_scanStage->SetStatusTitleText(scanEvent->strValue());
122  else if (scanEvent->type() == ScannerEvent::SetPercentComplete)
123  m_scanStage->SetScanProgress(scanEvent->intValue() * 0.01);
124  else if (scanEvent->type() == ScannerEvent::SetStatusRotorPosition)
125  m_scanStage->SetStatusRotorPosition(scanEvent->intValue());
126  else if (scanEvent->type() == ScannerEvent::SetStatusSignalLock)
127  m_scanStage->SetStatusLock(scanEvent->intValue());
128  else if (scanEvent->type() == ScannerEvent::SetStatusSignalToNoise)
129  m_scanStage->SetStatusSignalToNoise(scanEvent->intValue());
130  else if (scanEvent->type() == ScannerEvent::SetStatusSignalStrength)
131  m_scanStage->SetStatusSignalStrength(scanEvent->intValue());
132 }
133 
135  bool success)
136 {
137  ChannelImporter ci(true, true, true, true, true,
138  m_freeToAirOnly, m_channelNumbersOnly, m_completeOnly, m_serviceRequirements, success);
139  ci.Process(_transports, m_sourceid);
140 }
141 
143 {
145 }
146 
148 {
149  m_scanStage = nullptr;
150 
151  if (m_scanMonitor)
152  {
154  }
155 }
156 
157 void ChannelScannerGUI::MonitorProgress(bool lock, bool strength,
158  bool snr, bool rotor)
159 {
161 
162  m_scanStage = new ChannelScannerGUIScanPane(lock, strength, snr, rotor, mainStack);
163 
164  if (m_scanStage->Create())
165  {
166  connect(m_scanStage, SIGNAL(Exiting()), SLOT(quitScanning()));
167 
168  for (uint i = 0; i < (uint) m_messageList.size(); ++i)
169  m_scanStage->AppendLine(m_messageList[i]);
170  mainStack->AddScreen(m_scanStage);
171  }
172  else
173  {
174  delete m_scanStage;
175  m_scanStage = nullptr;
176  }
177 }
static Type SetStatusText
Definition: scanmonitor.h:110
static Type SetStatusSignalStrength
Definition: scanmonitor.h:115
void HandleEvent(const ScannerEvent *scanEvent) override
MythConfirmationDialog * ShowOkPopup(const QString &message, QObject *parent, const char *slot, bool showCancel)
Non-blocking version of MythPopupBox::showOkPopup()
static void error(const char *str,...)
Definition: vbi.c:42
static Type SetStatusTitleText
Definition: scanmonitor.h:111
vector< ScanDTVTransport > ScanDTVTransportList
Definition: dtvmultiplex.h:141
static Type AppendTextToLog
Definition: scanmonitor.h:109
static Type SetPercentComplete
Definition: scanmonitor.h:112
unsigned int uint
Definition: compat.h:140
MythScreenStack * GetMainStack()
static const int kCodeAccepted
static Type ScanComplete
Definition: scanmonitor.h:106
static const int kCodeRejected
static Type ScanShutdown
Definition: scanmonitor.h:107
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
QString strValue() const
Definition: scanmonitor.h:94
static Type SetStatusRotorPosition
Definition: scanmonitor.h:113
static Type ScanErrored
Definition: scanmonitor.h:108
MythMainWindow * GetMythMainWindow(void)
static Type SetStatusSignalToNoise
Definition: scanmonitor.h:114
int intValue() const
Definition: scanmonitor.h:97
void MonitorProgress(bool lock, bool strength, bool snr, bool rotor) override
static Type SetStatusSignalLock
Definition: scanmonitor.h:116
virtual void Process(const ScanDTVTransportList &, bool success=false)
void post_event(QObject *dest, QEvent::Type type, int val)
Definition: scanmonitor.cpp:68
void InformUser(const QString &error) override
void Process(const ScanDTVTransportList &, int sourceid=-1)