package org.bucksch.zeipis.importer;
import org.bucksch.zeipis.all.*;
import org.bucksch.zeipis.recorder.*;
import java.sql.*;

public class DVBChannelImporter
{
  public DVBChannelImporter(Connection db, DVBCard card, boolean updateonly, boolean addonly)
    throws Exception
  {
    Util.debug("Using card " + card);
    myScan = new DVBScan(card);
    myDBImporter = new ChannelsToDBImporter(card, updateonly, addonly);
  }
  public void start(DVBTransponder transponder, boolean allChannels, boolean newChannels)
    throws Exception
  {
    myScan.enableXML(true);
    if (allChannels)
    {
      Util.debug("Starting full scan of all transponders" + (newChannels ? " and try to find new channels" : ""));
      myScan.scanEverything(newChannels, new DVBScan.ScanProgressCallback() {
        public void scannedTransponder(org.bucksch.zeipis.recorder.DVBScan.Transponder t) {
          myDBImporter.importTransponder(t);
        }; 
        public void progress(int doneCount, int todoCount,
                int todoEstimateCount, int timeElapsed, int timeUntilETA) {
        }
      });
    }
    else
    {
      Util.debug("Scanning transponder " + transponder);
      myDBImporter.importTransponder(myScan.scanTransponder(transponder));
    }
    Util.debug(myScan.resultXML());
  }

  // Data
  protected DVBScan myScan;
  protected ChannelsToDBImporter myDBImporter;
}
