00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <QCoreApplication>
00028 #include <iostream>
00029
00030 using namespace std;
00031
00032
00033 #include "channelscanner_cli.h"
00034 #include "channelscan_sm.h"
00035 #include "channelimporter.h"
00036
00037 #define LOC QString("ChScanCLI: ")
00038
00039 ChannelScannerCLI::ChannelScannerCLI(bool doScanSaveOnly, bool promptsOk) :
00040 done(false), onlysavescan(doScanSaveOnly), interactive(promptsOk),
00041 status_lock(false), status_complete(0), status_snr(0),
00042 status_text(""), status_last_log("")
00043 {
00044 }
00045
00046 ChannelScannerCLI::~ChannelScannerCLI()
00047 {
00048 }
00049
00050 void ChannelScannerCLI::HandleEvent(const ScannerEvent *scanEvent)
00051 {
00052 if ((scanEvent->type() == ScannerEvent::ScanComplete) ||
00053 (scanEvent->type() == ScannerEvent::ScanShutdown))
00054 {
00055 cout<<endl;
00056
00057 if (scanEvent->type() == ScannerEvent::ScanShutdown)
00058 cerr<<"HandleEvent(void) -- scan shutdown"<<endl;
00059 else
00060 cerr<<"HandleEvent(void) -- scan complete"<<endl;
00061
00062 ScanDTVTransportList transports;
00063 if (sigmonScanner)
00064 {
00065 sigmonScanner->StopScanner();
00066 transports = sigmonScanner->GetChannelList();
00067 }
00068
00069 Teardown();
00070
00071 if (!transports.empty())
00072 Process(transports);
00073
00074 done = true;
00075 QCoreApplication::exit(0);
00076 }
00077 else if (scanEvent->type() == ScannerEvent::AppendTextToLog)
00078 status_last_log = scanEvent->strValue();
00079 else if (scanEvent->type() == ScannerEvent::SetStatusText)
00080 status_text = scanEvent->strValue();
00081 else if (scanEvent->type() == ScannerEvent::SetStatusTitleText)
00082 ;
00083 else if (scanEvent->type() == ScannerEvent::SetPercentComplete)
00084 status_complete = scanEvent->intValue();
00085 else if (scanEvent->type() == ScannerEvent::SetStatusRotorPosition)
00086 ;
00087 else if (scanEvent->type() == ScannerEvent::SetStatusSignalLock)
00088 status_lock = scanEvent->intValue();
00089 else if (scanEvent->type() == ScannerEvent::SetStatusSignalToNoise)
00090 status_snr = scanEvent->intValue() / 65535.0;
00091 else if (scanEvent->type() == ScannerEvent::SetStatusSignalStrength)
00092 ;
00093
00094
00095 QString msg;
00096 if (VERBOSE_LEVEL_NONE || VERBOSE_LEVEL_CHECK(VB_CHANSCAN, LOG_INFO))
00097 {
00098 msg.sprintf("%3i%% S/N %3.1f %s : %s (%s) %20s",
00099 status_complete, status_snr,
00100 (status_lock) ? "l" : "L",
00101 status_text.toAscii().constData(),
00102 status_last_log.toAscii().constData(), "");
00103 }
00104
00105
00106 if (VERBOSE_LEVEL_CHECK(VB_CHANSCAN, LOG_INFO))
00107 {
00108 static QString old_msg;
00109 if (msg != old_msg)
00110 {
00111 LOG(VB_CHANSCAN, LOG_INFO, LOC + msg);
00112 old_msg = msg;
00113 }
00114 }
00115 else if (VERBOSE_LEVEL_NONE)
00116 {
00117 if (msg.length() > 80)
00118 msg = msg.left(77) + "...";
00119 cout<<"\r"<<msg.toAscii().constData()<<"\r";
00120 cout<<flush;
00121 }
00122 }
00123
00124 void ChannelScannerCLI::InformUser(const QString &error)
00125 {
00126 if (VERBOSE_LEVEL_NONE)
00127 {
00128 cerr<<"ERROR: "<<error.toAscii().constData()<<endl;
00129 }
00130 else
00131 {
00132 LOG(VB_GENERAL, LOG_ERR, LOC + error);
00133 }
00134 post_event(scanMonitor, ScannerEvent::ScanComplete, 0);
00135 }
00136
00137 void ChannelScannerCLI::Process(const ScanDTVTransportList &_transports)
00138 {
00139 ChannelImporter ci(false, interactive, !onlysavescan, !onlysavescan, true,
00140 freeToAirOnly, serviceRequirements);
00141 ci.Process(_transports);
00142 }
00143
00144 void ChannelScannerCLI::MonitorProgress(
00145 bool lock, bool strength, bool snr, bool rotor)
00146 {
00147 if (VERBOSE_LEVEL_NONE)
00148 cout<<"\r0%"<<flush;
00149 }