[MerlinEPGCenter] - implement workaround to fix zapping to channel when alternatives...
[enigma2-plugins.git] / satloader / src / plugin.py
1 from Screens.Screen import Screen
2 from Screens.MessageBox import MessageBox
3 from Screens.Standby import TryQuitMainloop
4 from Components.MenuList import MenuList
5 from Components.ActionMap import ActionMap
6 from Components.Label import Label
7 from twisted.web.client import downloadPage
8 from enigma import getDesktop, eListbox, eListboxPythonMultiContent, gFont, RT_HALIGN_LEFT
9 from Tools.LoadPixmap import LoadPixmap
10 from Plugins.Plugin import PluginDescriptor
11 import os
12
13 #######################
14
15 class Satloader(Screen):
16         framewidth = getDesktop(0).size().width()
17         if framewidth == 1280:
18                 skin = """
19                         <screen position="240,130" size="800,510" title="Satloader Plugin" >
20                                 <ePixmap position="8,4" size="190,32" pixmap="/usr/lib/enigma2/python/Plugins/Extensions/Satloader/button_red_sm.png" alphatest="on" />
21                                 <ePixmap position="206,4" size="190,32" pixmap="/usr/lib/enigma2/python/Plugins/Extensions/Satloader/button_green_sm.png" alphatest="on" />
22                                 <ePixmap position="404,4" size="190,32" pixmap="/usr/lib/enigma2/python/Plugins/Extensions/Satloader/button_yellow_sm.png" alphatest="on" />
23                                 <ePixmap position="602,4" size="190,32" pixmap="/usr/lib/enigma2/python/Plugins/Extensions/Satloader/button_blue_sm.png" alphatest="on" />
24                                 <widget name="key_red" position="8,4" size="190,32" valign="center" halign="center" zPosition="1" font="Regular;22" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
25                                 <widget name="key_green" position="206,4" size="190,32" valign="center" halign="center" zPosition="1" font="Regular;22" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
26                                 <widget name="key_yellow" position="404,4" size="190,32" valign="center" halign="center" zPosition="1" font="Regular;22" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
27                                 <widget name="key_blue" position="602,4" size="190,32" valign="center" halign="center" zPosition="1" font="Regular;22" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
28                                 <widget name="list" position="10,40" size="780,400" scrollbarMode="showOnDemand" />
29                                 <widget name="info" position="10,450" size="710,50" zPosition="1" font="Regular;22" valign="center" halign="center" />
30                                 <ePixmap position="730,457" size="50,35" zPosition="2" pixmap="/usr/lib/enigma2/python/Plugins/Extensions/Satloader/key_info.png" alphatest="on" />
31                         </screen>"""
32         elif framewidth == 720:
33                 skin = """
34                         <screen position="center,center" size="560,460" title="Satloader Plugin" >
35                                 <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
36                                 <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" alphatest="on" />
37                                 <ePixmap pixmap="skin_default/buttons/yellow.png" position="280,0" size="140,40" alphatest="on" />
38                                 <ePixmap pixmap="skin_default/buttons/blue.png" position="420,0" size="140,40" alphatest="on" />
39                                 <widget name="key_red" position="0,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />
40                                 <widget name="key_green" position="140,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />
41                                 <widget name="key_yellow" position="280,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />
42                                 <widget name="key_blue" position="420,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />
43                                 <widget name="list" position="10,50" size="540,350" scrollbarMode="showOnDemand" />
44                                 <widget name="info" position="10,410" size="485,40" zPosition="1" font="Regular;20" valign="center" halign="center" />
45                                 <ePixmap position="505,418" size="35,25" zPosition="2" pixmap="/usr/share/enigma2/skin_default/buttons/key_info.png" alphatest="on" />
46                         </screen>"""
47
48         def __init__(self, session):
49                 Screen.__init__(self, session)
50                 self.list = SatloaderList([])
51                 self["list"] = self.list
52                 self["info"] = Label()
53                 self["key_red"] = Label(_("Cancel"))
54                 self["key_green"] = Label(_("Install"))
55                 self["key_yellow"] = Label(_("Bouquet"))
56                 self["key_blue"] = Label(_("Multi Sat"))
57                 self["myActionMap"] = ActionMap(["OkCancelActions", "ColorActions", "EPGSelectActions"],
58                 {
59                         "ok": self.btnOK,
60                         "cancel": self.btnRed,
61                         "red": self.btnRed,
62                         "green": self.btnOK,
63                         "yellow": self.btnYellow,
64                         "blue": self.btnBlue,
65                         "info": self.btnInfo
66                 }, -1)
67
68                 self.onLayoutFinish.append(self.onLayoutFinished)
69
70         def onLayoutFinished(self):
71                 self.list.clearList()
72                 self.list.addSelection("Lyngsat", "http://satellites.satloader.net/lyngsat", 0, None)
73                 self.list.addSelection("Satbeams", "http://satellites.satloader.net/satbeams", 1, None)
74                 self.list.addSelection("Kingofsat", "http://satellites.satloader.net/kingofsat", 2, None)
75                 self.list.addSelection("Kingofsat (feeds)", "http://satellites.satloader.net/kingofsat/feeds", 3, None)
76                 self["info"].setText("%s" %(_("Press ok or green button to install satellites.xml")))
77
78         def btnRed(self):
79                 print "\n[Satloader] cancel\n"
80                 self.close(None)
81
82         def btnOK(self):
83                 self["info"].setText("%s" %(_("Please wait...")))
84                 saturl = self["list"].l.getCurrentSelection()[0][1]+"/satellites.xml"
85                 downloadPage(saturl, "/etc/tuxbox/satellites.xml").addCallback(self.downloadListSATCallback).addErrback(self.downloadListError)
86
87         def btnYellow(self):
88                 self.session.open(SatloaderBouquet)
89
90         def btnBlue(self):
91                 satname = self["list"].l.getCurrentSelection()[0][0]
92                 saturl = self["list"].l.getCurrentSelection()[0][1]+"/multisat.tar.gz"
93                 self.session.open(SatloaderMultiSat, satname, saturl)
94
95         def btnInfo(self):
96                 self.session.open(SatloaderAbout)
97
98         def downloadListError(self, ret):
99                 self["info"].setText("%s" %(_("Downloading satellites failed!")))
100                 self.session.open(MessageBox, "%s" %(_("Downloading satellites failed!")), MessageBox.TYPE_ERROR)
101
102         def downloadListSATCallback(self, ret):
103                 restart = self.session.openWithCallback(self.restart, MessageBox, "%s\n%s\n\n%s\n%s" %(_("satellites.xml is updated"), str(self["list"].l.getCurrentSelection()[0][0]), _("GUI needs a restart to apply changes."), _("Do you want to restart the GUI now?")), MessageBox.TYPE_YESNO)
104                 restart.setTitle("%s" %(_("Restart GUI now?")))
105
106         def restart(self, ret):
107                 if ret is True:
108                         self.session.open(TryQuitMainloop, 3)
109                 else:
110                         self["info"].setText("%s" %(_("GUI needs a restart.")))
111
112 #######################
113
114 class SatloaderAbout(Screen):
115         skin = """
116                 <screen position="center,center" size="360,280" title="%s">
117                         <ePixmap position="120,40" size="100,40" pixmap="/usr/lib/enigma2/python/Plugins/Extensions/Satloader/satloader.png" alphatest="on" />
118                         <widget name="info" position="10,100" size="340,120" zPosition="10" font="Regular;22" valign="center" halign="center" />
119                 </screen>""" %(_("About"))
120
121         def __init__(self, session):
122                 Screen.__init__(self, session)
123                 self["info"] = Label("Satloader Plugin\nAuthor: Ismail Demir\nwww.satloader.net")
124                 self["actions"] = ActionMap(["OkCancelActions"],
125                 {
126                         "ok": self.close,
127                         "cancel": self.close
128                 }, -1)
129
130 #######################
131
132 class SatloaderBouquet(Screen):
133         framewidth = getDesktop(0).size().width()
134         if framewidth == 1280:
135                 skin = """
136                         <screen position="240,130" size="800,510" title="Satloader Bouquet">
137                                 <ePixmap position="8,4" size="190,32" pixmap="/usr/lib/enigma2/python/Plugins/Extensions/Satloader/button_red_sm.png" alphatest="on" />
138                                 <ePixmap position="206,4" size="190,32" pixmap="/usr/lib/enigma2/python/Plugins/Extensions/Satloader/button_green_sm.png" alphatest="on" />
139                                 <ePixmap position="404,4" size="190,32" pixmap="/usr/lib/enigma2/python/Plugins/Extensions/Satloader/button_yellow_sm.png" alphatest="on" />
140                                 <ePixmap position="602,4" size="190,32" pixmap="/usr/lib/enigma2/python/Plugins/Extensions/Satloader/button_blue_sm.png" alphatest="on" />
141                                 <widget name="key_red" position="8,4" size="190,32" valign="center" halign="center" zPosition="1" font="Regular;22" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
142                                 <widget name="key_green" position="206,4" size="190,32" valign="center" halign="center" zPosition="1" font="Regular;22" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
143                                 <widget name="list" position="10,40" size="780,400" scrollbarMode="showOnDemand" />
144                                 <widget name="info" position="10,450" size="780,50" zPosition="10" font="Regular;22" valign="center" halign="center" />
145                         </screen>"""
146         elif framewidth == 720:
147                 skin = """
148                         <screen position="center,center" size="560,460" title="Satloader Bouquet">
149                                 <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
150                                 <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" alphatest="on" />
151                                 <ePixmap pixmap="skin_default/buttons/yellow.png" position="280,0" size="140,40" alphatest="on" />
152                                 <ePixmap pixmap="skin_default/buttons/blue.png" position="420,0" size="140,40" alphatest="on" />
153                                 <widget name="key_red" position="0,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />
154                                 <widget name="key_green" position="140,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />
155                                 <widget name="list" position="10,50" size="540,350" scrollbarMode="showOnDemand" />
156                                 <widget name="info" position="10,410" size="540,40" zPosition="10" font="Regular;20" valign="center" halign="center" />
157                         </screen>"""
158
159         def __init__(self, session):
160                 Screen.__init__(self, session)
161                 self.list = SatloaderList([])
162                 self["list"] = self.list
163                 self["info"] = Label()
164                 self["key_red"] = Label(_("Cancel"))
165                 self["key_green"] = Label(_("Save"))
166                 self["actions"] = ActionMap(["OkCancelActions", "ColorActions"],
167                 {
168                         "ok": self.btnOK,
169                         "cancel": self.btnRed,
170                         "red": self.btnRed,
171                         "green": self.btnGreen
172                 }, -1)
173
174                 self.onLayoutFinish.append(self.onLayoutFinished)
175
176         def onLayoutFinished(self):
177                 self["info"].setText("%s" %(_("Please wait...")))
178                 downloadPage("http://satellites.satloader.net/bouquet.tar.gz", "/tmp/bouquet.tar.gz").addCallback(self.downloadListBouquetCallback).addErrback(self.downloadListError)
179
180         def btnRed(self):
181                 print "\n[SatloaderBouquet] cancel\n"
182                 self.close(None)
183
184         def btnOK(self):
185                 if self["list"].l.getCurrentSelection() is not None:
186                         self.list.toggleSelection()
187
188         def btnGreen(self):
189                 if self["list"].l.getCurrentSelection() is not None:
190                         list = self.list.getSelectionsList()
191                         if len(list) is not 0:
192                                 for item in list:
193                                         if "\""+item[1]+"\"" not in open("/etc/enigma2/bouquets.tv").read():
194                                                 os.system("cp /tmp/bouquet/"+item[1]+" /etc/enigma2/"+item[1])
195                                                 f = open("/etc/enigma2/bouquets.tv", 'a')
196                                                 f.write("#SERVICE 1:7:1:0:0:0:0:0:0:0:FROM BOUQUET \""+item[1]+"\" ORDER BY bouquet\n")
197                                                 f.flush()
198                                                 os.fsync(f.fileno())
199                                                 f.close()
200
201                                 restart = self.session.openWithCallback(self.restart, MessageBox, "%s\n\n%s\n%s" %(_("selected bouquets are installed"), _("GUI needs a restart to apply changes."), _("Do you want to restart the GUI now?")), MessageBox.TYPE_YESNO)
202                                 restart.setTitle("%s" %(_("Restart GUI now?")))
203
204                         else:
205                                 self["info"].setText("%s" %(_("Please select at least one bouquet")))
206
207         def downloadListError(self, ret):
208                 self["info"].setText("%s" %(_("Downloading bouquets failed!")))
209                 self.session.open(MessageBox, "%s" %(_("Downloading bouquets failed!")), MessageBox.TYPE_ERROR)
210
211         def downloadListBouquetCallback(self, ret):
212                 self["info"].setText("%s" %(_("Downloading succesfull! Parsing ...")))
213
214                 try:
215                         if os.path.exists('/tmp/bouquet'):
216                                 os.system("rm -rf /tmp/bouquet")
217                         os.mkdir('/tmp/bouquet', 644)
218                         os.system("tar -xzf /tmp/bouquet.tar.gz -C/tmp/bouquet")
219                         os.system("rm -f /tmp/bouquet.tar.gz")
220
221                         idx=0
222                         self.list.clearList()
223                         f = open("/tmp/bouquet/list.lst", "r")
224                         for line in f:
225                                 m = line.split(";")
226                                 self.list.addSelection(m[0], m[1], idx, False)
227                                 idx += 1
228                         f.close()
229
230                         if self.list is not None:
231                                 self["info"].setText("%s" %(_("Press ok button to select bouquet")))
232
233                 except Exception, e:
234                         print "Error:", e
235                         self["info"].setText("%s\n%s" %(_("Parsing failed!"),e))
236
237         def restart(self, ret):
238                 if ret is True:
239                         self.session.open(TryQuitMainloop, 3)
240                 else:
241                         self["info"].setText("%s" %(_("GUI needs a restart.")))
242
243 #######################
244
245 class SatloaderMultiSat(Screen):
246         framewidth = getDesktop(0).size().width()
247         if framewidth == 1280:
248                 skin = """
249                         <screen position="240,130" size="800,510" title="Satloader MultiSat">
250                                 <ePixmap position="8,4" size="190,32" pixmap="/usr/lib/enigma2/python/Plugins/Extensions/Satloader/button_red_sm.png" alphatest="on" />
251                                 <ePixmap position="206,4" size="190,32" pixmap="/usr/lib/enigma2/python/Plugins/Extensions/Satloader/button_green_sm.png" alphatest="on" />
252                                 <ePixmap position="404,4" size="190,32" pixmap="/usr/lib/enigma2/python/Plugins/Extensions/Satloader/button_yellow_sm.png" alphatest="on" />
253                                 <ePixmap position="602,4" size="190,32" pixmap="/usr/lib/enigma2/python/Plugins/Extensions/Satloader/button_blue_sm.png" alphatest="on" />
254                                 <widget name="key_red" position="8,4" size="190,32" valign="center" halign="center" zPosition="1" font="Regular;22" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
255                                 <widget name="key_green" position="206,4" size="190,32" valign="center" halign="center" zPosition="1" font="Regular;22" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
256                                 <widget name="key_yellow" position="404,4" size="190,32" valign="center" halign="center" zPosition="1" font="Regular;22" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
257                                 <widget name="list" position="10,40" size="780,400" scrollbarMode="showOnDemand" />
258                                 <widget name="info" position="10,450" size="780,25" zPosition="10" font="Regular;22" valign="center" halign="center" />
259                                 <widget name="desc" position="10,475" size="780,25" zPosition="10" font="Regular;22" valign="center" halign="center" />
260                         </screen>"""
261         elif framewidth == 720:
262                 skin = """
263                         <screen position="center,center" size="560,460" title="Satloader MultiSat">
264                                 <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
265                                 <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" alphatest="on" />
266                                 <ePixmap pixmap="skin_default/buttons/yellow.png" position="280,0" size="140,40" alphatest="on" />
267                                 <ePixmap pixmap="skin_default/buttons/blue.png" position="420,0" size="140,40" alphatest="on" />
268                                 <widget name="key_red" position="0,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />
269                                 <widget name="key_green" position="140,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />
270                                 <widget name="key_yellow" position="280,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />
271                                 <widget name="list" position="10,50" size="540,350" scrollbarMode="showOnDemand" />
272                                 <widget name="info" position="10,410" size="540,20" zPosition="10" font="Regular;20" valign="center" halign="center" />
273                                 <widget name="desc" position="10,430" size="540,20" zPosition="10" font="Regular;20" valign="center" halign="center" />
274                         </screen>"""
275
276         def __init__(self, session, satname=None, saturl=None):
277                 Screen.__init__(self, session)
278                 self.satname = satname
279                 self.saturl = saturl
280                 self.list = SatloaderList([])
281                 self["list"] = self.list
282                 self["info"] = Label()
283                 self["desc"] = Label("%s %s" %(_("Source:"), self.satname))
284                 self["key_red"] = Label(_("Cancel"))
285                 self["key_green"] = Label(_("OK"))
286                 self["key_yellow"] = Label(_("Transponder"))
287                 self["actions"] = ActionMap(["OkCancelActions", "ColorActions"],
288                 {
289                         "ok": self.btnOK,
290                         "cancel": self.btnRed,
291                         "red": self.btnRed,
292                         "green": self.btnGreen,
293                         "yellow": self.btnYellow
294                 }, -1)
295
296                 self.onLayoutFinish.append(self.onLayoutFinished)
297
298         def onLayoutFinished(self):
299                 self["info"].setText("%s %s" %(_("Download:"), self.satname))
300                 downloadPage(self.saturl, "/tmp/multisat.tar.gz").addCallback(self.downloadListMultiSatCallback).addErrback(self.downloadListError)
301
302         def btnRed(self):
303                 print "\n[SatloaderMultiSat] cancel\n"
304                 self.close(None)
305
306         def btnOK(self):
307                 if self["list"].l.getCurrentSelection() is not None:
308                         self.list.toggleSelection()
309
310         def btnGreen(self):
311                 if self["list"].l.getCurrentSelection() is not None:
312                         list = self.list.getSelectionsList()
313                         if len(list) is not 0:
314                                 f = open('/etc/tuxbox/satellites.xml', 'w+')
315                                 f.write('<?xml version="1.0" ?>\n<!--\nsatellites.xml generated by Satloader Plugin\n(c)2009-2012 Ismail Demir www.satloader.net\n-->\n\n<satellites>\n')
316                                 for item in list:
317                                         myfile = open(item[1], 'r')
318                                         f.write(myfile.read())
319                                         myfile.close()
320                                 f.write('</satellites>')
321                                 f.flush()
322                                 os.fsync(f.fileno())
323                                 f.close()
324                                 
325                                 restart = self.session.openWithCallback(self.restart, MessageBox, "%s\n%s\n\n%s\n%s" %(_("satellites.xml has been built."), str(self.satname), _("GUI needs a restart to apply changes."), _("Do you want to restart the GUI now?")), MessageBox.TYPE_YESNO)
326                                 restart.setTitle("%s" %(_("Restart GUI now?")))
327                         else:
328                                 self["info"].setText("%s" %(_("Please select at least one satellite")))
329
330         def btnYellow(self):
331                 if self["list"].l.getCurrentSelection() is not None:
332                         satname = self["list"].l.getCurrentSelection()[0][0]
333                         satfile = self["list"].l.getCurrentSelection()[0][1]
334                         self.session.open(TransponderSelection, satname, satfile)
335
336         def downloadListError(self, ret):
337                 self["info"].setText("%s" %(_("Downloading satellites failed!")))
338                 self.session.open(MessageBox, "%s" %(_("Downloading satellites failed!")), MessageBox.TYPE_ERROR)
339
340         def downloadListMultiSatCallback(self, ret):
341                 self["info"].setText("%s" %(_("Downloading succesfull! Parsing ...")))
342
343                 try:
344                         if os.path.exists('/tmp/multisat'):
345                                 os.system("rm -rf /tmp/multisat")
346                         os.mkdir('/tmp/multisat', 644)
347                         os.system("tar -xzf /tmp/multisat.tar.gz -C/tmp/multisat")
348                         os.system("rm -f /tmp/multisat.tar.gz")
349
350                         idx = 0
351                         self.list.clearList()
352                         f = open("/tmp/multisat/satlist.lst", "r")
353                         for line in f:
354                                 m = line.split(";")
355                                 self.list.addSelection(m[0], "/tmp/multisat/"+m[1], idx, False)
356                                 idx += 1
357                         f.close()
358
359                         if self.list is not None:
360                                 self["info"].setText("%s" %(_("Press ok button to select satellite")))
361
362                 except Exception, e:
363                         print "Error:", e
364                         self["info"].setText("%s\n%s" %(_("Parsing failed!"),e))
365
366         def restart(self, ret):
367                 if ret is True:
368                         self.session.open(TryQuitMainloop, 3)
369                 else:
370                         self["info"].setText("%s" %(_("GUI needs a restart.")))
371
372 #######################
373
374 class TransponderSelection(Screen):
375         framewidth = getDesktop(0).size().width()
376         if framewidth == 1280:
377                 skin = """
378                         <screen position="240,130" size="800,510" title="%s">
379                                 <ePixmap position="8,4" size="190,32" pixmap="/usr/lib/enigma2/python/Plugins/Extensions/Satloader/button_red_sm.png" alphatest="on" />
380                                 <ePixmap position="206,4" size="190,32" pixmap="/usr/lib/enigma2/python/Plugins/Extensions/Satloader/button_green_sm.png" alphatest="on" />
381                                 <ePixmap position="404,4" size="190,32" pixmap="/usr/lib/enigma2/python/Plugins/Extensions/Satloader/button_yellow_sm.png" alphatest="on" />
382                                 <ePixmap position="602,4" size="190,32" pixmap="/usr/lib/enigma2/python/Plugins/Extensions/Satloader/button_blue_sm.png" alphatest="on" />
383                                 <widget name="key_red" position="8,4" size="190,32" valign="center" halign="center" zPosition="1" font="Regular;22" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
384                                 <widget name="key_green" position="206,4" size="190,32" valign="center" halign="center" zPosition="1" font="Regular;22" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
385                                 <widget name="list" position="10,40" size="780,400" scrollbarMode="showOnDemand" />
386                                 <widget name="info" position="10,450" size="780,50" zPosition="10" font="Regular;22" valign="center" halign="center" />
387                         </screen>""" %(_("Transponder selection"))
388         elif framewidth == 720:
389                 skin = """
390                         <screen position="center,center" size="560,460" title="%s">
391                                 <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
392                                 <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" alphatest="on" />
393                                 <ePixmap pixmap="skin_default/buttons/yellow.png" position="280,0" size="140,40" alphatest="on" />
394                                 <ePixmap pixmap="skin_default/buttons/blue.png" position="420,0" size="140,40" alphatest="on" />
395                                 <widget name="key_red" position="0,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />
396                                 <widget name="key_green" position="140,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />
397                                 <widget name="list" position="10,50" size="540,350" scrollbarMode="showOnDemand" />
398                                 <widget name="info" position="10,410" size="540,40" zPosition="10" font="Regular;20" valign="center" halign="center" />
399                         </screen>""" %(_("Transponder selection"))
400
401         def __init__(self, session, satname, satfile):
402                 Screen.__init__(self, session)
403                 self.satname = satname
404                 self.satfile = satfile
405                 self.list = SatloaderList([])
406                 self["list"] = self.list
407                 self["info"] = Label()
408                 self["key_red"] = Label(_("Cancel"))
409                 self["key_green"] = Label(_("Save"))
410                 self["actions"] = ActionMap(["OkCancelActions", "ColorActions"],
411                 {
412                         "ok": self.btnOK,
413                         "cancel": self.btnRed,
414                         "red": self.btnRed,
415                         "green": self.btnGreen
416                 }, -1)
417
418                 self.onLayoutFinish.append(self.onLayoutFinished)
419
420         def onLayoutFinished(self):
421                 self.list.clearList()
422                 f = open(self.satfile, "r")
423                 self.satheader = f.readline()
424                 idx = 0
425                 for line in f:
426                         if "transponder" in line:
427                                 m = line.split("\"")
428                                 pol = ""
429                                 if m[5] == "0":
430                                         pol = "H"
431                                 elif m[5] == "1":
432                                         pol = "V"
433                                 elif m[5] == "2":
434                                         pol = "L"
435                                 elif m[5] == "3":
436                                         pol = "R"
437
438                                 text = "TP: %s   %s %s %s   %s %s" %(str(idx+1).zfill(3),_("Frequency:"), str(m[1]).zfill(8)[:5],str(pol),_("Symbol Rate:"),str(m[3]).zfill(8)[:5])
439                                 self.list.addSelection(text, line, idx, True)
440                                 idx += 1
441                 f.close()
442                 self["info"].setText("%s" %(self.satname))
443
444         def btnRed(self):
445                 print "\n[TransponderSelection] cancel\n"
446                 self.close(None)
447
448         def btnOK(self):
449                 if self["list"].l.getCurrentSelection() is not None:
450                         self.list.toggleSelection()
451
452         def btnGreen(self):
453                 list = self.list.getSelectionsList()
454                 if len(list) is not 0:
455                         f = open(self.satfile, 'w+')
456                         f.write(self.satheader)
457                         for item in list:
458                                 f.write(item[1])
459                         f.write("\t</sat>\n")
460                         f.flush()
461                         os.fsync(f.fileno())
462                         f.close()
463                         
464                         self.session.open(MessageBox, "\"%s\" %s" %(str(self.satfile), _("has been saved.")), MessageBox.TYPE_INFO, timeout=3)
465                         self.close(None)
466                 else:
467                         self["info"].setText("%s" %(_("Please select at least one transponder")))
468
469 #######################
470
471 class SatloaderList(MenuList):
472         def __init__(self, list):
473                 MenuList.__init__(self, list, False, eListboxPythonMultiContent)
474                 self.l.setItemHeight(25)
475                 self.l.setFont(0, gFont("Regular", 22))
476
477         def clearList(self):
478                 self.list = []
479                 self.setList(self.list)
480
481         def addSelection(self, description, value, index, selected = False):
482                 self.list.append(SatListEntry(description, value, index, selected))
483                 self.setList(self.list)
484
485         def toggleSelection(self):
486                 idx = self.getSelectedIndex()
487                 item = self.list[idx][0]
488                 self.list[idx] = SatListEntry(item[0], item[1], item[2], not item[3])
489                 self.setList(self.list)
490
491         def getSelectionsList(self):
492                 return [ (item[0][0], item[0][1], item[0][2]) for item in self.list if item[0][3] ]
493
494 #######################
495
496 def SatListEntry(description, value, index, selected):
497         if selected == None:
498                 res = [
499                         (description, value, index, selected),
500                         (eListboxPythonMultiContent.TYPE_TEXT, 10, 0, 760, 25, 0, RT_HALIGN_LEFT, description)
501                 ]
502                 return res
503         else:
504                 res = [
505                         (description, value, index, selected),
506                         (eListboxPythonMultiContent.TYPE_TEXT, 40, 0, 730, 25, 0, RT_HALIGN_LEFT, description)
507                 ]
508                 if selected == True:
509                         res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, 10, 0, 25, 24,  LoadPixmap(cached=True, path="/usr/share/enigma2/skin_default/icons/lock_on.png")))
510                 elif selected == False:
511                         res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, 10, 0, 25, 24,  LoadPixmap(cached=True, path="/usr/share/enigma2/skin_default/icons/lock_off.png")))
512                 return res
513
514 #######################
515
516 def main(session, **kwargs):
517         print "\n[Satloader] start\n"
518         session.open(Satloader)
519
520 #######################
521
522 def Plugins(**kwargs):
523         return [
524                 PluginDescriptor(name="Satloader Plugin", description="updates satellites.xml", icon="satloader.png", where = PluginDescriptor.WHERE_PLUGINMENU, fnc=main),
525                 PluginDescriptor(name="Satloader Plugin", description="updates satellites.xml", where = PluginDescriptor.WHERE_EXTENSIONSMENU, fnc=main)
526                 ]