mytube: move suggenstions back to top
[enigma2-plugins.git] / mytube / src / MyTubeSearch.py
1 from enigma import eTimer, ePythonMessagePump
2 from MyTubeService import GoogleSuggestions
3 from Screens.Screen import Screen
4 from Screens.LocationBox import MovieLocationBox
5 from Components.config import config, ConfigText, getConfigListEntry
6 from Components.config import KEY_DELETE, KEY_BACKSPACE, KEY_ASCII, KEY_TIMEOUT
7 from Components.ConfigList import ConfigListScreen
8 from Components.ActionMap import ActionMap
9 from Components.Button import Button
10 from Components.Label import Label
11 from Components.Sources.List import List
12 from Components.MultiContent import MultiContentEntryText
13 from Components.Task import job_manager
14 from Tools.Directories import resolveFilename, SCOPE_HDD
15
16 from threading import Thread
17 from ThreadQueue import ThreadQueue
18 from xml.etree.cElementTree import fromstring as cet_fromstring
19 from StringIO import StringIO
20 #import urllib
21 from urllib import FancyURLopener
22 import json
23
24 class MyOpener(FancyURLopener):
25         version = 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.12) Gecko/20070731 Ubuntu/dapper-security Firefox/1.5.0.12'
26
27 class SuggestionsQueryThread(Thread):
28         def __init__(self, query, param, callback, errorback):
29                 Thread.__init__(self)
30                 self.messagePump = ePythonMessagePump()
31                 self.messages = ThreadQueue()
32                 self.query = query
33                 self.param = param
34                 self.callback = callback
35                 self.errorback = errorback
36                 self.canceled = False
37                 self.messagePump_conn = self.messagePump.recv_msg.connect(self.finished)
38
39         def cancel(self):
40                 self.canceled = True
41
42         def run(self):
43                 if self.param not in (None, ""):
44                         try:
45                                 suggestions = self.query.getSuggestions(self.param)
46                                 self.messages.push((suggestions, self.callback))
47                                 self.messagePump.send(0)
48                         except Exception, ex:
49                                 self.messages.push((ex, self.errorback))
50                                 self.messagePump.send(0)
51
52         def finished(self, val):
53                 if not self.canceled:
54                         message = self.messages.pop()
55                         message[1](message[0])
56
57 class ConfigTextWithGoogleSuggestions(ConfigText):
58         def __init__(self, default = "", fixed_size = True, visible_width = False):
59                 ConfigText.__init__(self, default, fixed_size, visible_width)
60                 self.suggestions = GoogleSuggestions()
61                 self.suggestionsThread = None
62                 self.suggestionsThreadRunning = False
63                 self.suggestionsListActivated = False
64
65         def prepareSuggestionsThread(self):
66                 self.suggestions.hl = "en"
67                 if config.plugins.mytube.search.lr.value is not None:
68                         self.suggestions.hl=config.plugins.mytube.search.lr.value
69
70         def suggestionsThreadStarted(self):
71                 if self.suggestionsThreadRunning:
72                         self.cancelSuggestionsThread()
73                 self.suggestionsThreadRunning = True
74
75         def suggestionsThreadFinished(self):
76                 self.suggestionsThreadRunning = False
77
78         def cancelSuggestionsThread(self):
79                 if self.suggestionsThread is not None:
80                         self.suggestionsThread.cancel()
81                 self.suggestionsThreadFinished()
82
83         def propagateSuggestions(self, suggestionsList):
84                 self.cancelSuggestionsThread()
85                 print "[MyTube - ConfigTextWithGoogleSuggestions] propagateSuggestions:",suggestionsList
86                 if self.suggestionsWindow:
87                         self.suggestionsWindow.update(suggestionsList)
88
89         def gotSuggestionsError(self, val):
90                 print "[MyTube - ConfigTextWithGoogleSuggestions] gotSuggestionsError:",val
91
92         def getSuggestions(self):
93                 self.prepareSuggestionsThread()
94                 self.suggestionsThreadStarted()
95                 self.suggestionsThread = SuggestionsQueryThread(self.suggestions, self.value, self.propagateSuggestions, self.gotSuggestionsError)
96                 self.suggestionsThread.start()
97
98         def handleKey(self, key):
99                 if not self.suggestionsListActivated:
100                         ConfigText.handleKey(self, key)
101                         if key in [KEY_DELETE, KEY_BACKSPACE, KEY_ASCII, KEY_TIMEOUT]:
102                                 self.getSuggestions()
103
104         def onSelect(self, session):
105                 ConfigText.onSelect(self, session)
106                 if session is not None:
107                         self.suggestionsWindow = session.instantiateDialog(MyTubeSuggestionsListScreen, self, zPosition=1000)
108                         self.suggestionsWindow.deactivate()
109                         self.suggestionsWindow.hide()
110                 self.getSuggestions()
111
112         def onDeselect(self, session):
113                 self.cancelSuggestionsThread()
114                 ConfigText.onDeselect(self, session)
115                 if self.suggestionsWindow:
116                         session.deleteDialog(self.suggestionsWindow)
117                         self.suggestionsWindow = None
118
119         def suggestionListUp(self):
120                 if self.suggestionsWindow.getlistlenght() > 0:
121                         self.value = self.suggestionsWindow.up()
122
123         def suggestionListDown(self):
124                 if self.suggestionsWindow.getlistlenght() > 0:
125                         self.value = self.suggestionsWindow.down()
126
127         def suggestionListPageDown(self):
128                 if self.suggestionsWindow.getlistlenght() > 0:
129                         self.value = self.suggestionsWindow.pageDown()
130
131         def suggestionListPageUp(self):
132                 if self.suggestionsWindow.getlistlenght() > 0:
133                         self.value = self.suggestionsWindow.pageUp()
134
135         def activateSuggestionList(self):
136                 ret = False
137                 if self.suggestionsWindow is not None and self.suggestionsWindow.shown:
138                         self.tmpValue = self.value
139                         self.value = self.suggestionsWindow.activate()
140                         self.allmarked = False
141                         self.suggestionsListActivated = True
142                         ret = True
143                 return ret
144
145         def deactivateSuggestionList(self):
146                 ret = False
147                 if self.suggestionsWindow is not None:
148                         self.suggestionsWindow.deactivate()
149                         self.getSuggestions()
150                         self.allmarked = True
151                         self.suggestionsListActivated = False
152                         ret = True
153                 return ret
154
155         def cancelSuggestionList(self):
156                 self.value = self.tmpValue
157                 return self.deactivateSuggestionList()
158
159         def enableSuggestionSelection(self,value):
160                 if self.suggestionsWindow is not None:
161                         self.suggestionsWindow.enableSelection(value)
162
163 default = resolveFilename(SCOPE_HDD)
164 tmp = config.movielist.videodirs.value
165 if default not in tmp:
166         tmp.append(default)
167
168 class MyTubeSuggestionsListScreen(Screen):
169         skin = """
170                 <screen name="MyTubeSuggestionsListScreen" title="MyTube - Search" position="60,93" zPosition="6" size="610,160" flags="wfNoBorder" >
171                         <ePixmap position="0,0" zPosition="-1" size="610,160" pixmap="/usr/lib/enigma2/python/Plugins/Extensions/MyTube/suggestions_bg.png" alphatest="on" transparent="1" backgroundColor="transparent"/>
172                         <widget source="suggestionslist" render="Listbox" position="10,5" zPosition="7" size="580,150" scrollbarMode="showOnDemand" transparent="1" >
173                                 <convert type="TemplatedMultiContent">
174                                         {"template": [
175                                                         MultiContentEntryText(pos = (0, 1), size = (340, 24), font=0, flags = RT_HALIGN_LEFT, text = 0), # index 0 is the name
176                                                         MultiContentEntryText(pos = (350, 1), size = (180, 24), font=1, flags = RT_HALIGN_RIGHT, text = 1), # index 1 are the rtesults
177                                                 ],
178                                         "fonts": [gFont("Regular", 22),gFont("Regular", 18)],
179                                         "itemHeight": 25
180                                         }
181                                 </convert>
182                         </widget>
183                 </screen>"""
184
185         def __init__(self, session, configTextWithGoogleSuggestion):
186                 Screen.__init__(self, session)
187                 self.activeState = False
188                 self.list = []
189                 self.suggestlist = []
190                 self["suggestionslist"] = List(self.list)
191                 self.configTextWithSuggestion = configTextWithGoogleSuggestion
192
193         def update(self, suggestions):
194                 if suggestions and len(suggestions) > 0:
195                         if not self.shown:
196                                 self.show()
197                         #suggestions_tree = cet_fromstring( suggestions )
198                         suggestions_tree = json.loads(str(suggestions[20:-1]))
199                         if suggestions_tree:
200                                 self.list = []
201                                 self.suggestlist = []
202                                 suggested = suggestions_tree[1]
203                                 count = 0
204                                 if suggested:
205                                         suggestrelevance = suggestions_tree[4]["google:suggestrelevance"]
206                                         suggesttype = suggestions_tree[4]["google:suggesttype"]
207                                         for suggest in suggested:
208                                                 name = None
209                                                 numresults = None
210                                                 if suggesttype[count] == u'NAVIGATION':
211                                                         count +=1
212                                                         continue
213                                                 name = str(suggest)
214                                                 numresults = suggestrelevance[count]
215                                                 if name and numresults:
216                                                         self.suggestlist.append((name, numresults ))
217                                                 count +=1
218                                 """for suggestion in suggestions_tree.findall("CompleteSuggestion"):
219                                         name = None
220                                         numresults = None
221                                         for subelement in suggestion:
222                                                 if subelement.attrib.has_key('data'):
223                                                         name = subelement.attrib['data'].encode("UTF-8")
224                                                 if subelement.attrib.has_key('int'):
225                                                         numresults = subelement.attrib['int']
226                                                 if name and numresults:
227                                                         self.suggestlist.append((name, numresults ))"""
228                                 if len(self.suggestlist):
229                                         self.suggestlist.sort(key=lambda x: int(x[1]))
230                                         self.suggestlist.reverse()
231                                         for entry in self.suggestlist:
232                                                 self.list.append((entry[0], str(entry[1]) + _(" Results") ))
233                                         self["suggestionslist"].setList(self.list)
234                                         self["suggestionslist"].setIndex(0)
235                 else:
236                         self.hide()
237
238         def getlistlenght(self):
239                 return len(self.list)
240
241         def up(self):
242                 print "up"
243                 if self.list and len(self.list) > 0:
244                         self["suggestionslist"].selectPrevious()
245                         return self.getSelection()
246
247         def down(self):
248                 print "down"
249                 if self.list and len(self.list) > 0:
250                         self["suggestionslist"].selectNext()
251                         return self.getSelection()
252
253         def pageUp(self):
254                 print "up"
255                 if self.list and len(self.list) > 0:
256                         self["suggestionslist"].selectPrevious()
257                         return self.getSelection()
258
259         def pageDown(self):
260                 print "down"
261                 if self.list and len(self.list) > 0:
262                         self["suggestionslist"].selectNext()
263                         return self.getSelection()
264
265         def activate(self):
266                 print "activate"
267                 self.activeState = True
268                 return self.getSelection()
269
270         def deactivate(self):
271                 print "deactivate"
272                 self.activeState = False
273                 return self.getSelection()
274
275         def getSelection(self):
276                 if self["suggestionslist"].getCurrent() is None:
277                         return None
278                 print self["suggestionslist"].getCurrent()[0]
279                 return self["suggestionslist"].getCurrent()[0]
280
281         def enableSelection(self,value):
282                 self["suggestionslist"].selectionEnabled(value)
283
284
285 class MyTubeSettingsScreen(Screen, ConfigListScreen):
286         skin = """
287                 <screen name="MyTubeSettingsScreen" flags="wfNoBorder" position="0,0" size="720,576" title="MyTube - Settings" >
288                         <ePixmap position="0,0" zPosition="-1" size="720,576" pixmap="~/mytubemain_bg.png" alphatest="on" transparent="1" backgroundColor="transparent"/>
289                         <widget name="title" position="60,50" size="600,50" zPosition="5" valign="center" halign="left" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
290                         <widget name="config" zPosition="2" position="60,120" size="610,370" scrollbarMode="showOnDemand" transparent="1" />
291
292                         <ePixmap position="100,500" size="100,40" zPosition="0" pixmap="~/plugin.png" alphatest="on" transparent="1" />
293                         <ePixmap position="220,500" zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
294                         <ePixmap position="360,500" zPosition="4" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
295                         <widget name="key_red" position="220,500" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
296                         <widget name="key_green" position="360,500" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
297                 </screen>"""
298
299         def __init__(self, session, plugin_path):
300                 Screen.__init__(self, session)
301                 self.skin_path = plugin_path
302                 self.session = session
303
304                 self["shortcuts"] = ActionMap(["ShortcutActions", "WizardActions", "MediaPlayerActions"],
305                 {
306                         "ok": self.keyOK,
307                         "back": self.keyCancel,
308                         "red": self.keyCancel,
309                         "green": self.keySave,
310                         "up": self.keyUp,
311                         "down": self.keyDown,
312                         "left": self.keyLeft,
313                         "right": self.keyRight,
314                 }, -1)
315
316                 self["key_red"] = Button(_("Close"))
317                 self["key_green"] = Button(_("Save"))
318                 self["title"] = Label()
319
320                 self.searchContextEntries = []
321                 self.ProxyEntry = None
322                 self.loadFeedEntry = None
323                 self.VideoDirname = None
324                 ConfigListScreen.__init__(self, self.searchContextEntries, session)
325                 self.createSetup()
326                 self.onLayoutFinish.append(self.layoutFinished)
327                 self.onShown.append(self.setWindowTitle)
328
329         def layoutFinished(self):
330                 self["title"].setText(_("MyTubePlayer settings"))
331
332         def setWindowTitle(self):
333                 self.setTitle(_("MyTubePlayer settings"))
334
335         def createSetup(self):
336                 self.searchContextEntries = []
337                 self.searchContextEntries.append(getConfigListEntry(_("Display search results by:"), config.plugins.mytube.search.orderBy))
338                 self.searchContextEntries.append(getConfigListEntry(_("Search restricted content:"), config.plugins.mytube.search.racy))
339                 self.searchContextEntries.append(getConfigListEntry(_("Search category:"), config.plugins.mytube.search.categories))
340                 self.searchContextEntries.append(getConfigListEntry(_("Search region:"), config.plugins.mytube.search.lr))
341                 self.loadFeedEntry = getConfigListEntry(_("Load feed on startup:"), config.plugins.mytube.general.loadFeedOnOpen)
342                 self.searchContextEntries.append(self.loadFeedEntry)
343                 if config.plugins.mytube.general.loadFeedOnOpen.value:
344                         self.searchContextEntries.append(getConfigListEntry(_("Start with following feed:"), config.plugins.mytube.general.startFeed))
345                 self.searchContextEntries.append(getConfigListEntry(_("Videoplayer stop/exit behavior:"), config.plugins.mytube.general.on_movie_stop))
346                 self.searchContextEntries.append(getConfigListEntry(_("Videobrowser exit behavior:"), config.plugins.mytube.general.on_exit))
347                 """self.ProxyEntry = getConfigListEntry(_("Use HTTP Proxy Server:"), config.plugins.mytube.general.useHTTPProxy)
348                 self.searchContextEntries.append(self.ProxyEntry)
349                 if config.plugins.mytube.general.useHTTPProxy.value:
350                         self.searchContextEntries.append(getConfigListEntry(_("HTTP Proxy Server IP:"), config.plugins.mytube.general.ProxyIP))
351                         self.searchContextEntries.append(getConfigListEntry(_("HTTP Proxy Server Port:"), config.plugins.mytube.general.ProxyPort))"""
352                 # disabled until i have time for some proper tests
353                 self.VideoDirname = getConfigListEntry(_("Download location"), config.plugins.mytube.general.videodir)
354                 if config.usage.setup_level.index >= 2: # expert+
355                         self.searchContextEntries.append(self.VideoDirname)
356                 self.searchContextEntries.append(getConfigListEntry(_("Clear history on Exit:"), config.plugins.mytube.general.clearHistoryOnClose))
357                 self.searchContextEntries.append(getConfigListEntry(_("Auto paginate on last entry:"), config.plugins.mytube.general.AutoLoadFeeds))
358                 self.searchContextEntries.append(getConfigListEntry(_("Reset tv-screen after playback:"), config.plugins.mytube.general.resetPlayService))
359                 self.searchContextEntries.append(getConfigListEntry(_("Youtube Username (reopen plugin on change):"), config.plugins.mytube.general.username))
360                 self.searchContextEntries.append(getConfigListEntry(_("Youtube Password (reopen plugin on change):"), config.plugins.mytube.general.password))
361
362                 self["config"].list = self.searchContextEntries
363                 self["config"].l.setList(self.searchContextEntries)
364                 if not self.selectionChanged in self["config"].onSelectionChanged:
365                         self["config"].onSelectionChanged.append(self.selectionChanged)
366
367         def selectionChanged(self):
368                 current = self["config"].getCurrent()
369
370         def newConfig(self):
371                 print "newConfig", self["config"].getCurrent()
372                 if self["config"].getCurrent() == self.loadFeedEntry:
373                         self.createSetup()
374
375         def keyOK(self):
376                 cur = self["config"].getCurrent()
377                 if config.usage.setup_level.index >= 2 and cur == self.VideoDirname:
378                         self.session.openWithCallback(
379                                 self.pathSelected,
380                                 MovieLocationBox,
381                                 _("Choose target folder"),
382                                 config.plugins.mytube.general.videodir.value,
383                                 minFree = 100 # We require at least 100MB free space
384                         )
385                 else:
386                         self.keySave()
387
388         def pathSelected(self, res):
389                 if res is not None:
390                         if config.movielist.videodirs.value != config.plugins.mytube.general.videodir.choices:
391                                 config.plugins.mytube.general.videodir.setChoices(config.movielist.videodirs.value, default=res)
392                         config.plugins.mytube.general.videodir.value = res
393
394         def keyUp(self):
395                 self["config"].instance.moveSelection(self["config"].instance.moveUp)
396
397         def keyDown(self):
398                 self["config"].instance.moveSelection(self["config"].instance.moveDown)
399
400         def keyRight(self):
401                 ConfigListScreen.keyRight(self)
402                 self.newConfig()
403
404         def keyLeft(self):
405                 ConfigListScreen.keyLeft(self)
406                 self.newConfig()
407
408         def keyCancel(self):
409                 print "cancel"
410                 for x in self["config"].list:
411                         x[1].cancel()
412                 self.close()
413
414         def keySave(self):
415                 print "saving"
416                 config.plugins.mytube.search.orderBy.save()
417                 config.plugins.mytube.search.racy.save()
418                 config.plugins.mytube.search.categories.save()
419                 config.plugins.mytube.search.lr.save()
420                 config.plugins.mytube.general.loadFeedOnOpen.save()
421                 config.plugins.mytube.general.startFeed.save()
422                 config.plugins.mytube.general.on_movie_stop.save()
423                 config.plugins.mytube.general.on_exit.save()
424                 config.plugins.mytube.general.videodir.save()
425                 config.plugins.mytube.general.clearHistoryOnClose.save()
426                 config.plugins.mytube.general.AutoLoadFeeds.save()
427                 config.plugins.mytube.general.username.save()
428                 config.plugins.mytube.general.password.save()
429                 if config.plugins.mytube.general.clearHistoryOnClose.value:
430                         config.plugins.mytube.general.history.value = ""
431                         config.plugins.mytube.general.history.save()
432                 #config.plugins.mytube.general.useHTTPProxy.save()
433                 #config.plugins.mytube.general.ProxyIP.save()
434                 #config.plugins.mytube.general.ProxyPort.save()
435                 for x in self["config"].list:
436                         x[1].save()
437                 config.plugins.mytube.general.save()
438                 config.plugins.mytube.search.save()
439                 config.plugins.mytube.save()
440                 """if config.plugins.mytube.general.useHTTPProxy.value is True:
441                         proxy = {'http': 'http://'+str(config.plugins.mytube.general.ProxyIP.getText())+':'+str(config.plugins.mytube.general.ProxyPort.value)}
442                         self.myopener = MyOpener(proxies=proxy)
443                         urllib.urlopen = MyOpener(proxies=proxy).open
444                 else:
445                         self.myopener = MyOpener()
446                         urllib.urlopen = MyOpener().open"""
447                 self.close()
448
449
450 class MyTubeTasksScreen(Screen):
451         skin = """
452                 <screen name="MyTubeTasksScreen" flags="wfNoBorder" position="0,0" size="720,576" title="MyTube - Tasks" >
453                         <ePixmap position="0,0" zPosition="-1" size="720,576" pixmap="~/mytubemain_bg.png" alphatest="on" transparent="1" backgroundColor="transparent"/>
454                         <widget name="title" position="60,50" size="600,50" zPosition="5" valign="center" halign="left" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
455                         <widget source="tasklist" render="Listbox" position="60,120" size="610,370" zPosition="7" scrollbarMode="showOnDemand" transparent="1" >
456                                 <convert type="TemplatedMultiContent">
457                                         {"template": [
458                                                         MultiContentEntryText(pos = (0, 1), size = (200, 24), font=1, flags = RT_HALIGN_LEFT, text = 1), # index 1 is the name
459                                                         MultiContentEntryText(pos = (210, 1), size = (150, 24), font=1, flags = RT_HALIGN_RIGHT, text = 2), # index 2 is the state
460                                                         MultiContentEntryProgress(pos = (370, 1), size = (100, 24), percent = -3), # index 3 should be progress
461                                                         MultiContentEntryText(pos = (480, 1), size = (100, 24), font=1, flags = RT_HALIGN_RIGHT, text = 4), # index 4 is the percentage
462                                                 ],
463                                         "fonts": [gFont("Regular", 22),gFont("Regular", 18)],
464                                         "itemHeight": 25
465                                         }
466                                 </convert>
467                         </widget>
468                         <ePixmap position="100,500" size="100,40" zPosition="0" pixmap="~/plugin.png" alphatest="on" transparent="1" />
469                         <ePixmap position="220,500" zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
470                         <widget name="key_red" position="220,500" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
471                 </screen>"""
472
473         def __init__(self, session, plugin_path, tasklist):
474                 Screen.__init__(self, session)
475                 self.skin_path = plugin_path
476                 self.session = session
477                 self.tasklist = tasklist
478                 self["tasklist"] = List(self.tasklist)
479
480                 self["shortcuts"] = ActionMap(["ShortcutActions", "WizardActions", "MediaPlayerActions"],
481                 {
482                         "ok": self.keyOK,
483                         "back": self.keyCancel,
484                         "red": self.keyCancel,
485                 }, -1)
486
487                 self["key_red"] = Button(_("Close"))
488                 self["title"] = Label()
489
490                 self.onLayoutFinish.append(self.layoutFinished)
491                 self.onShown.append(self.setWindowTitle)
492                 self.onClose.append(self.__onClose)
493                 self.Timer = eTimer()
494                 self.Timer_conn = self.Timer.timeout.connect(self.TimerFire)
495
496         def __onClose(self):
497                 del self.Timer
498
499         def layoutFinished(self):
500                 self["title"].setText(_("MyTubePlayer active video downloads"))
501                 self.Timer.startLongTimer(2)
502
503         def TimerFire(self):
504                 self.Timer.stop()
505                 self.rebuildTaskList()
506
507         def rebuildTaskList(self):
508                 self.tasklist = []
509                 for job in job_manager.getPendingJobs():
510                         self.tasklist.append((job,job.name,job.getStatustext(),int(100*job.progress/float(job.end)) ,str(100*job.progress/float(job.end)) + "%" ))
511                 self['tasklist'].setList(self.tasklist)
512                 self['tasklist'].updateList(self.tasklist)
513                 self.Timer.startLongTimer(2)
514
515         def setWindowTitle(self):
516                 self.setTitle(_("MyTubePlayer active video downloads"))
517
518         def keyOK(self):
519                 current = self["tasklist"].getCurrent()
520                 print current
521                 if current:
522                         job = current[0]
523                         from Screens.TaskView import JobView
524                         self.session.openWithCallback(self.JobViewCB, JobView, job)
525
526         def JobViewCB(self, why):
527                 print "WHY---",why
528
529         def keyCancel(self):
530                 self.close()
531
532         def keySave(self):
533                 self.close()
534
535
536 class MyTubeHistoryScreen(Screen):
537         skin = """
538                 <screen name="MyTubeHistoryScreen" position="60,93" zPosition="6" size="610,160" flags="wfNoBorder" title="MyTube - History">
539                         <ePixmap position="0,0" zPosition="-1" size="610,160" pixmap="/usr/lib/enigma2/python/Plugins/Extensions/MyTube/suggestions_bg.png" alphatest="on" transparent="1" backgroundColor="transparent"/>
540                         <widget source="historylist" render="Listbox" position="10,5" zPosition="7" size="580,150" scrollbarMode="showOnDemand" transparent="1" >
541                                 <convert type="TemplatedMultiContent">
542                                         {"template": [
543                                                         MultiContentEntryText(pos = (0, 1), size = (340, 24), font=0, flags = RT_HALIGN_LEFT, text = 0), # index 0 is the name
544                                                 ],
545                                         "fonts": [gFont("Regular", 22),gFont("Regular", 18)],
546                                         "itemHeight": 25
547                                         }
548                                 </convert>
549                         </widget>
550                 </screen>"""
551
552         def __init__(self, session):
553                 Screen.__init__(self, session)
554                 self.session = session
555                 self.historylist = []
556                 print "self.historylist",self.historylist
557                 self["historylist"] = List(self.historylist)
558                 self.activeState = False
559
560         def activate(self):
561                 print "activate"
562                 self.activeState = True
563                 self.history = config.plugins.mytube.general.history.value.split(',')
564                 if self.history[0] == '':
565                         del self.history[0]
566                 print "self.history",self.history
567                 self.historylist = []
568                 for entry in self.history:
569                         self.historylist.append(( str(entry),))
570                 self["historylist"].setList(self.historylist)
571                 self["historylist"].updateList(self.historylist)
572
573         def deactivate(self):
574                 print "deactivate"
575                 self.activeState = False
576
577         def status(self):
578                 print self.activeState
579                 return self.activeState
580
581         def getSelection(self):
582                 if self["historylist"].getCurrent() is None:
583                         return None
584                 print self["historylist"].getCurrent()[0]
585                 return self["historylist"].getCurrent()[0]
586
587         def up(self):
588                 print "up"
589                 self["historylist"].selectPrevious()
590                 return self.getSelection()
591
592         def down(self):
593                 print "down"
594                 self["historylist"].selectNext()
595                 return self.getSelection()
596
597         def pageUp(self):
598                 print "up"
599                 self["historylist"].selectPrevious()
600                 return self.getSelection()
601
602         def pageDown(self):
603                 print "down"
604                 self["historylist"].selectNext()
605                 return self.getSelection()
606