clear list of previous found services when a new servicescan starts
[enigma2.git] / lib / python / Components / ServiceScan.py
1 from enigma import eComponentScan, eDVBFrontendParametersSatellite, eDVBFrontendParametersCable, eDVBFrontendParametersTerrestrial
2
3 class ServiceScan:
4         
5         Idle = 1
6         Running = 2
7         Done = 3
8         Error = 4
9         
10         Errors = { 
11                 0: "error starting scanning",
12                 1: "error while scanning",
13                 2: "no resource manager",
14                 3: "no channel list"
15                 }
16         
17         def scanStatusChanged(self):
18                 if self.state == self.Running:
19                         self.progressbar.setValue(self.scan.getProgress())
20                         if self.scan.isDone():
21                                 errcode = self.scan.getError()
22                                 
23                                 if errcode == 0:
24                                         self.state = self.Done
25                                 else:
26                                         self.state = self.Error
27                                         self.errorcode = errcode
28                         else:
29                                 self.text.setText(_("scan in progress - %d %% done!\n%d services found!") % (self.scan.getProgress(), self.foundServices + self.scan.getNumServices()))
30                 
31                 if self.state == self.Done:
32                         if self.scan.getNumServices() == 1:
33                                 self.text.setText(_("scan done!\nOne service found!"))
34                         elif self.scan.getNumServices() == 0:
35                                 self.text.setText(_("scan done!\nNo service found!"))
36                         else:
37                                 self.text.setText(_("scan done!\n%d services found!") % (self.foundServices + self.scan.getNumServices()))
38                 
39                 if self.state == self.Error:
40                         self.text.setText(_("ERROR - failed to scan (%s)!") % (self.Errors[self.errorcode]) )
41                         
42                 if self.state == self.Done or self.state == self.Error:
43                         if self.run != len(self.scanList) - 1:
44                                 self.foundServices += self.scan.getNumServices()
45                                 self.execEnd()
46                                 self.run += 1
47                                 self.doRun()
48                                 self.execBegin()
49         
50         def __init__(self, progressbar, text, servicelist, passNumber, scanList):
51                 self.foundServices = 0
52                 self.progressbar = progressbar
53                 self.text = text
54                 self.servicelist = servicelist
55                 self.passNumber = passNumber
56                 self.scanList = scanList
57                 self.run = 0
58                 
59                 self.doRun()
60                 
61         def doRun(self):
62                 self.scan = eComponentScan()
63                 
64                 self.feid = self.scanList[self.run]["feid"]
65                 self.flags = self.scanList[self.run]["flags"]
66                 self.state = self.Idle
67                 self.scanStatusChanged()
68                 
69                 for x in self.scanList[self.run]["transponders"]:
70                         self.scan.addInitial(x)
71
72         def updatePass(self):
73                 size = len(self.scanList)
74                 if size > 1:
75                         self.passNumber.setText(_("pass") + " " + str(self.run + 1) + "/" + str(size) + " (" + _("Tuner") + " " + str(self.scanList[self.run]["feid"]) + ")")
76                 
77         def execBegin(self):
78                 self.updatePass()
79                 self.scan.statusChanged.get().append(self.scanStatusChanged)
80                 self.scan.newService.get().append(self.newService)
81                 self.servicelist.clear()
82                 self.state = self.Running
83                 err = self.scan.start(self.feid, self.flags)
84                 if err:
85                         self.state = self.Error
86                         self.errorcode = 0
87
88                 self.scanStatusChanged()
89         
90         def execEnd(self):
91                 self.scan.statusChanged.get().remove(self.scanStatusChanged)
92                 self.scan.newService.get().remove(self.newService)
93                 if not self.isDone():
94                         print "*** warning *** scan was not finished!"
95                 
96                 del self.scan
97
98         def isDone(self):
99                 return self.state == self.Done or self.state == self.Error
100
101         def newService(self):
102                 newServiceName = self.scan.getLastServiceName()
103                 self.servicelist.addItem(newServiceName)
104
105         def destroy(self):
106                 pass