fix typo
[enigma2-plugins.git] / mytube / src / MyTubeSearch.py
1 from __init__ import _
2 from MyTubeService import GoogleSuggestions
3 from Screens.Screen import Screen
4 from Screens.LocationBox import MovieLocationBox
5 from Components.config import config, Config, ConfigSelection, ConfigText, getConfigListEntry, ConfigSubsection, ConfigYesNo, ConfigIP, ConfigNumber,ConfigLocations
6 from Components.ConfigList import ConfigListScreen
7 from Components.config import KEY_DELETE, KEY_BACKSPACE, KEY_LEFT, KEY_RIGHT, KEY_HOME, KEY_END, KEY_TOGGLEOW, KEY_ASCII, KEY_TIMEOUT
8 from Components.ActionMap import ActionMap
9 from Components.Button import Button
10 from Components.Label import Label
11 from Components.ScrollLabel import ScrollLabel
12 from Components.Sources.List import List
13 from Components.Pixmap import Pixmap
14 from Components.MultiContent import MultiContentEntryText, MultiContentEntryPixmapAlphaTest
15 from enigma import eListboxPythonMultiContent, RT_HALIGN_LEFT, RT_HALIGN_RIGHT, gFont, eListbox,ePoint
16 from Components.Task import job_manager
17 from Tools.Directories import pathExists, fileExists, resolveFilename, SCOPE_HDD
18 from threading import Thread
19 from threading import Condition
20
21
22 import urllib
23 from urllib import FancyURLopener
24
25 class MyOpener(FancyURLopener):
26         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'
27
28
29 class ConfigTextWithGoogleSuggestions(ConfigText):
30         class SuggestionsThread(Thread):
31                 def __init__(self, suggestionsService):
32                         Thread.__init__(self)
33                         self.suggestionsService = suggestionsService
34                         self.value = None
35                         self.running = True
36                         self.condition = Condition()
37
38                 def run(self):
39                         while self.running:
40                                 self.condition.acquire()
41                                 if self.value is None:
42                                         self.condition.wait()
43                                 value = self.value
44                                 self.value = None
45                                 self.condition.release()
46                                 if value is not None:
47                                         self.suggestionsService.getSuggestions(value)
48
49                 def stop(self):
50                         self.running = False
51                         self.condition.acquire()
52                         self.condition.notify()
53                         self.condition.release()
54                         self.join()
55
56                 def getSuggestions(self, value):
57                         self.condition.acquire()
58                         self.value = value
59                         self.condition.notify()
60                         self.condition.release()
61
62         def __init__(self, default = "", fixed_size = True, visible_width = False, threaded = False):
63                 ConfigText.__init__(self, default, fixed_size, visible_width)
64                 self.suggestions = GoogleSuggestions(self.propagateSuggestions, ds = "yt", hl = "en")
65                 self.suggestionsThread = None
66                 self.threaded = threaded
67                 self.suggestionsListActivated = False
68
69
70         def propagateSuggestions(self, suggestionsList):
71                 if self.suggestionsWindow:
72                         self.suggestionsWindow.update(suggestionsList)
73
74
75         def getSuggestions(self):
76                 if self.suggestionsThread is not None:
77                         self.suggestionsThread.getSuggestions(self.value)
78                 else:
79                         self.suggestions.getSuggestions(self.value)
80
81
82         def handleKey(self, key):
83                 if not self.suggestionsListActivated:
84                         ConfigText.handleKey(self, key)
85                         if key in [KEY_DELETE, KEY_BACKSPACE, KEY_ASCII, KEY_TIMEOUT]:
86                                 self.getSuggestions()
87
88
89         def onSelect(self, session):
90                 if self.threaded:
91                         self.suggestionsThread = ConfigTextWithGoogleSuggestions.SuggestionsThread(self.suggestions)
92                         self.suggestionsThread.start()
93                 else:
94                         self.suggestionsThread = None
95                 ConfigText.onSelect(self, session)
96                 if session is not None:
97                         self.suggestionsWindow = session.instantiateDialog(MyTubeSuggestionsListScreen, self)
98                         self.suggestionsWindow.deactivate()
99                         self.suggestionsWindow.hide()
100                 self.suggestions.getSuggestions(self.value)
101
102
103         def onDeselect(self, session):
104                 if self.suggestionsThread is not None:
105                         self.suggestionsThread.stop()
106                 ConfigText.onDeselect(self, session)
107                 if self.suggestionsWindow:
108                         session.deleteDialog(self.suggestionsWindow)
109                         self.suggestionsWindow = None
110
111
112         def suggestionListUp(self):
113                 self.value = self.suggestionsWindow.up()
114
115
116         def suggestionListDown(self):
117                 self.value = self.suggestionsWindow.down()
118
119
120         def suggestionListPageDown(self):
121                 self.value = self.suggestionsWindow.pageDown()
122
123
124         def suggestionListPageUp(self):
125                 self.value = self.suggestionsWindow.pageUp()
126
127
128         def activateSuggestionList(self):
129                 ret = False
130                 if self.suggestionsWindow is not None and self.suggestionsWindow.shown:
131                         self.tmpValue = self.value
132                         self.value = self.suggestionsWindow.activate()
133                         self.allmarked = False
134                         #self.marked_pos = -1
135                         self.suggestionsListActivated = True
136                         ret = True
137                 return ret
138
139
140         def deactivateSuggestionList(self):
141                 ret = False
142                 if self.suggestionsWindow is not None:
143                         self.suggestionsWindow.deactivate()
144                         self.getSuggestions()
145                         self.allmarked = True
146                         self.suggestionsListActivated = False
147                         ret = True
148                 return ret
149
150
151         def cancelSuggestionList(self):
152                 self.value = self.tmpValue
153                 return self.deactivateSuggestionList()
154
155         def enableSuggestionSelection(self,value):
156                 if self.suggestionsWindow is not None:
157                         self.suggestionsWindow.enableSelection(value)
158
159
160 config.plugins.mytube = ConfigSubsection()
161 config.plugins.mytube.search = ConfigSubsection()
162
163 config.plugins.mytube.search.searchTerm = ConfigTextWithGoogleSuggestions("", False, threaded = True)
164 config.plugins.mytube.search.orderBy = ConfigSelection(
165                                 [
166                                  ("relevance", _("Relevance")),
167                                  ("viewCount", _("View Count")),
168                                  ("published", _("Published")),
169                                  ("rating", _("Rating"))
170                                 ], "relevance")
171 config.plugins.mytube.search.time = ConfigSelection(
172                                 [
173                                  ("all_time", _("All Time")),
174                                  ("this_month", _("This Month")),
175                                  ("this_week", _("This Week")),
176                                  ("today", _("Today"))
177                                 ], "all_time")
178 config.plugins.mytube.search.racy = ConfigSelection(
179                                 [
180                                  ("include", _("Yes")),
181                                  ("exclude", _("No"))
182                                 ], "include")
183 config.plugins.mytube.search.categories = ConfigSelection(
184                                 [
185                                  (None, _("All")),
186                                  ("Film", _("Film & Animation")),
187                                  ("Autos", _("Autos & Vehicles")),
188                                  ("Music", _("Music")),
189                                  ("Animals", _("Pets & Animals")),
190                                  ("Sports", _("Sports")),
191                                  ("Travel", _("Travel & Events")),
192                                  ("Shortmov", _("Short Movies")),
193                                  ("Games", _("Gaming")),
194                                  ("Comedy", _("Comedy")),
195                                  ("People", _("People & Blogs")),
196                                  ("News", _("News & Politics")),
197                                  ("Entertainment", _("Entertainment")),
198                                  ("Education", _("Education")),
199                                  ("Howto", _("Howto & Style")),
200                                  ("Nonprofit", _("Nonprofits & Activism")),
201                                  ("Tech", _("Science & Technology"))
202                                 ], None)
203 config.plugins.mytube.search.lr = ConfigSelection(
204                                 [
205                                  (None, _("All")),
206                                  ("au", _("Australia")),
207                                  ("br", _("Brazil")),                            
208                                  ("ca", _("Canada")),
209                                  ("cz", _("Czech Republic")),
210                                  ("fr", _("France")),
211                                  ("de", _("Germany")),
212                                  ("gb", _("Great Britain")),
213                                  ("au", _("Australia")),
214                                  ("nl", _("Holland")),
215                                  ("hk", _("Hong Kong")),
216                                  ("in", _("India")),
217                                  ("ie", _("Ireland")),
218                                  ("il", _("Israel")),
219                                  ("it", _("Italy")),
220                                  ("jp", _("Japan")),
221                                  ("mx", _("Mexico")),
222                                  ("nz", _("New Zealand")),
223                                  ("pl", _("Poland")),
224                                  ("ru", _("Russia")),
225                                  ("kr", _("South Korea")),
226                                  ("es", _("Spain")),
227                                  ("se", _("Sweden")),
228                                  ("tw", _("Taiwan")),
229                                  ("us", _("United States")) 
230                                 ], None)
231 config.plugins.mytube.search.sortOrder = ConfigSelection(
232                                 [
233                                  ("ascending", _("Ascanding")),
234                                  ("descending", _("Descending"))
235                                 ], "ascending")
236
237 config.plugins.mytube.general = ConfigSubsection()
238 config.plugins.mytube.general.showHelpOnOpen = ConfigYesNo(default = True)
239 config.plugins.mytube.general.startFeed = ConfigSelection(
240                                 [
241                                  ("top_rated", _("Top rated")),
242                                  ("top_favorites", _("Top favorites")),                          
243                                  ("most_viewed", _("Most viewed")),
244                                  ("most_popular", _("Most popular")),
245                                  ("most_recent", _("Most recent")),                              
246                                  ("most_discussed", _("Most discussed")),
247                                  ("top_favorites", _("Most linked")),
248                                  ("most_linked", _("Most responded"))
249                                 ], "most_popular")
250
251 config.plugins.mytube.general.on_movie_stop = ConfigSelection(default = "ask", choices = [
252         ("ask", _("Ask user")), ("quit", _("Return to movie list")), ("playnext", _("Play next video")) ])
253
254
255 default = resolveFilename(SCOPE_HDD)
256 tmp = config.movielist.videodirs.value
257 if default not in tmp:
258         tmp.append(default)
259 config.plugins.mytube.general.videodir = ConfigSelection(default = default, choices = tmp)
260 #config.plugins.mytube.general.history = ConfigSelection(choices = [])
261 config.plugins.mytube.general.history = ConfigText(default="")
262
263
264 #config.plugins.mytube.general.useHTTPProxy = ConfigYesNo(default = False)
265 #config.plugins.mytube.general.ProxyIP = ConfigIP(default=[0,0,0,0])
266 #config.plugins.mytube.general.ProxyPort = ConfigNumber(default=8080)
267
268 class MyTubeSuggestionsListScreen(Screen):
269         skin = """
270                 <screen name="MyTubeSuggestionsListScreen" position="60,93" zPosition="6" size="610,160" flags="wfNoBorder" >
271                         <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"/>
272                         <widget source="suggestionslist" render="Listbox" position="10,5" zPosition="7" size="580,150" scrollbarMode="showOnDemand" transparent="1" >
273                                 <convert type="TemplatedMultiContent">
274                                         {"template": [
275                                                         MultiContentEntryText(pos = (0, 1), size = (340, 24), font=0, flags = RT_HALIGN_LEFT, text = 0), # index 0 is the name
276                                                         MultiContentEntryText(pos = (350, 1), size = (180, 24), font=1, flags = RT_HALIGN_RIGHT, text = 1), # index 1 are the rtesults
277                                                 ],
278                                         "fonts": [gFont("Regular", 22),gFont("Regular", 18)],
279                                         "itemHeight": 25
280                                         }
281                                 </convert>
282                         </widget>
283                 </screen>"""
284                 
285         def __init__(self, session, configTextWithGoogleSuggestion):
286                 Screen.__init__(self, session)
287                 self.activeState = False
288                 self.list = []
289                 self.suggestlist = []
290                 self["suggestionslist"] = List(self.list)
291                 self.configTextWithSuggestion = configTextWithGoogleSuggestion
292
293         def update(self, suggestions):
294                 if suggestions and len(suggestions[1]) > 0:
295                         if not self.shown:
296                                 self.show()
297                         if suggestions:
298                                 self.list = []
299                                 self.suggestlist = []
300                                 suggests = suggestions[1]
301                                 for suggestion in suggests:
302                                         name = suggestion[0]
303                                         results = suggestion[1].replace(" results", "")
304                                         numresults = results.replace(",", "")
305                                         self.suggestlist.append((name, numresults ))
306                                 if len(self.suggestlist):
307                                         self.suggestlist.sort(key=lambda x: int(x[1]))
308                                         self.suggestlist.reverse()
309                                         for entry in self.suggestlist:
310                                                 self.list.append((entry[0], entry[1] + _(" Results") ))
311                                         self["suggestionslist"].setList(self.list)
312                                         self["suggestionslist"].setIndex(0)
313                 else:
314                         self.hide()
315
316         def up(self):
317                 print "up"
318                 self["suggestionslist"].selectPrevious()
319                 return self.getSelection()
320
321         def down(self):
322                 print "down"
323                 self["suggestionslist"].selectNext()
324                 return self.getSelection()
325         
326         def pageUp(self):
327                 print "up"
328                 self["suggestionslist"].selectPrevious()
329                 return self.getSelection()
330
331         def pageDown(self):
332                 print "down"
333                 self["suggestionslist"].selectNext()
334                 return self.getSelection()
335
336         def activate(self):
337                 print "activate"
338                 self.activeState = True
339                 return self.getSelection()
340
341         def deactivate(self):
342                 print "deactivate"
343                 self.activeState = False
344                 return self.getSelection()
345
346         def getSelection(self):
347                 if self["suggestionslist"].getCurrent() is None:
348                         return None
349                 print self["suggestionslist"].getCurrent()[0]
350                 return self["suggestionslist"].getCurrent()[0]
351
352         def enableSelection(self,value):
353                 self["suggestionslist"].selectionEnabled(value)
354
355
356
357 class MyTubeSettingsScreen(Screen, ConfigListScreen):
358         skin = """
359                 <screen name="MyTubeSettingsScreen" flags="wfNoBorder" position="0,0" size="720,576" title="MyTubePlayerMainScreen..." >
360                         <ePixmap position="0,0" zPosition="-1" size="720,576" pixmap="~/mytubemain_bg.png" alphatest="on" transparent="1" backgroundColor="transparent"/>
361                         <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" />
362                         <widget name="config" zPosition="2" position="60,120" size="610,370" scrollbarMode="showOnDemand" transparent="1" />
363
364                         <ePixmap position="100,500" size="100,40" zPosition="0" pixmap="~/plugin.png" alphatest="on" transparent="1" />
365                         <ePixmap position="220,500" zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
366                         <ePixmap position="360,500" zPosition="4" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
367                         <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" />
368                         <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" />
369                 </screen>"""
370
371         def __init__(self, session, plugin_path):
372                 Screen.__init__(self, session)
373                 self.skin_path = plugin_path
374                 self.session = session
375
376                 self["shortcuts"] = ActionMap(["ShortcutActions", "WizardActions", "MediaPlayerActions"],
377                 {
378                         "ok": self.keyOK,
379                         "back": self.keyCancel,
380                         "red": self.keyCancel,
381                         "green": self.keySave,
382                         "up": self.keyUp,
383                         "down": self.keyDown,
384                         "left": self.keyLeft,
385                         "right": self.keyRight,
386                 }, -1)
387                 
388
389                 self["key_red"] = Button(_("Close"))
390                 self["key_green"] = Button(_("Save"))
391                 self["title"] = Label()
392                 
393                 self.searchContextEntries = []
394                 self.ProxyEntry = None
395                 self.VideoDirname = None
396                 ConfigListScreen.__init__(self, self.searchContextEntries, session)
397                 self.createSetup()
398                 self.onLayoutFinish.append(self.layoutFinished)
399                 self.onShown.append(self.setWindowTitle)
400
401         def layoutFinished(self):
402                 self["title"].setText(_("MyTubePlayer settings"))
403
404
405         def setWindowTitle(self):
406                 self.setTitle(_("MyTubePlayer settings"))
407
408         def createSetup(self):
409                 self.searchContextEntries = []
410                 self.searchContextEntries.append(getConfigListEntry(_("Display search results by:"), config.plugins.mytube.search.orderBy))
411                 self.searchContextEntries.append(getConfigListEntry(_("Search restricted content:"), config.plugins.mytube.search.racy))
412                 self.searchContextEntries.append(getConfigListEntry(_("Search category:"), config.plugins.mytube.search.categories))
413                 self.searchContextEntries.append(getConfigListEntry(_("Search region:"), config.plugins.mytube.search.lr))
414                 self.searchContextEntries.append(getConfigListEntry(_("Start with following feed:"), config.plugins.mytube.general.startFeed))
415                 self.searchContextEntries.append(getConfigListEntry(_("Player Stop/Exit behavior:"), config.plugins.mytube.general.on_movie_stop))
416                 """self.ProxyEntry = getConfigListEntry(_("Use HTTP Proxy Server:"), config.plugins.mytube.general.useHTTPProxy)
417                 self.searchContextEntries.append(self.ProxyEntry)
418                 if config.plugins.mytube.general.useHTTPProxy.value:
419                         self.searchContextEntries.append(getConfigListEntry(_("HTTP Proxy Server IP:"), config.plugins.mytube.general.ProxyIP))
420                         self.searchContextEntries.append(getConfigListEntry(_("HTTP Proxy Server Port:"), config.plugins.mytube.general.ProxyPort))"""
421                 # disabled until i have time for some proper tests      
422                 self.VideoDirname = getConfigListEntry(_("Download location"), config.plugins.mytube.general.videodir)
423                 if config.usage.setup_level.index >= 2: # expert+
424                         self.searchContextEntries.append(self.VideoDirname)
425
426                 self["config"].list = self.searchContextEntries
427                 self["config"].l.setList(self.searchContextEntries)
428                 if not self.selectionChanged in self["config"].onSelectionChanged:
429                         self["config"].onSelectionChanged.append(self.selectionChanged)
430
431         def selectionChanged(self):
432                 current = self["config"].getCurrent()
433                 #print current
434
435         def newConfig(self):
436                 print "newConfig", self["config"].getCurrent()
437                 #if self["config"].getCurrent() == self.ProxyEntry:
438                 #       self.createSetup()
439
440         def keyOK(self):
441                 cur = self["config"].getCurrent()
442                 if config.usage.setup_level.index >= 2 and cur == self.VideoDirname:
443                         self.session.openWithCallback(
444                                 self.pathSelected,
445                                 MovieLocationBox,
446                                 _("Choose target folder"),
447                                 config.plugins.mytube.general.videodir.value,
448                                 minFree = 100 # We require at least 100MB free space
449                         )
450                 else:
451                         self.keySave()
452
453         def pathSelected(self, res):
454                 if res is not None:
455                         if config.movielist.videodirs.value != config.plugins.mytube.general.videodir.choices:
456                                 config.plugins.mytube.general.videodir.setChoices(config.movielist.videodirs.value, default=res)
457                         config.plugins.mytube.general.videodir.value = res
458
459         def keyUp(self):
460                 self["config"].instance.moveSelection(self["config"].instance.moveUp)
461
462         def keyDown(self):
463                 self["config"].instance.moveSelection(self["config"].instance.moveDown)
464
465         def keyRight(self):
466                 ConfigListScreen.keyRight(self)
467                 #self.newConfig()
468
469         def keyLeft(self):
470                 ConfigListScreen.keyLeft(self)
471                 #self.newConfig()
472
473         def keyCancel(self):
474                 print "cancel"
475                 for x in self["config"].list:
476                         x[1].cancel()
477                 self.close()    
478
479         def keySave(self):
480                 print "saving"
481                 config.plugins.mytube.search.orderBy.save()
482                 config.plugins.mytube.search.racy.save()
483                 config.plugins.mytube.search.categories.save()
484                 config.plugins.mytube.search.lr.save()
485                 config.plugins.mytube.general.startFeed.save()
486                 config.plugins.mytube.general.on_movie_stop.save()
487                 config.plugins.mytube.general.videodir.save()
488                 #config.plugins.mytube.general.useHTTPProxy.save()
489                 #config.plugins.mytube.general.ProxyIP.save()
490                 #config.plugins.mytube.general.ProxyPort.save()
491                 for x in self["config"].list:
492                         x[1].save()
493                 config.plugins.mytube.general.save()
494                 config.plugins.mytube.search.save()
495                 config.plugins.mytube.save()
496                 """if config.plugins.mytube.general.useHTTPProxy.value is True:
497                         proxy = {'http': 'http://'+str(config.plugins.mytube.general.ProxyIP.getText())+':'+str(config.plugins.mytube.general.ProxyPort.value)}
498                         self.myopener = MyOpener(proxies=proxy)
499                         urllib.urlopen = MyOpener(proxies=proxy).open
500                 else:
501                         self.myopener = MyOpener()
502                         urllib.urlopen = MyOpener().open"""
503                 self.close()
504
505
506 class MyTubeTasksScreen(Screen):
507         skin = """
508                 <screen name="MyTubeTasksScreen" flags="wfNoBorder" position="0,0" size="720,576" title="MyTubePlayerMainScreen..." >
509                         <ePixmap position="0,0" zPosition="-1" size="720,576" pixmap="~/mytubemain_bg.png" alphatest="on" transparent="1" backgroundColor="transparent"/>
510                         <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" />
511                         <widget source="tasklist" render="Listbox" position="60,120" size="610,370" zPosition="7" scrollbarMode="showOnDemand" transparent="1" >
512                                 <convert type="TemplatedMultiContent">
513                                         {"template": [
514                                                         MultiContentEntryText(pos = (0, 1), size = (200, 24), font=1, flags = RT_HALIGN_LEFT, text = 1), # index 1 is the name
515                                                         MultiContentEntryText(pos = (210, 1), size = (150, 24), font=1, flags = RT_HALIGN_RIGHT, text = 2), # index 2 is the state
516                                                         MultiContentEntryProgress(pos = (370, 1), size = (100, 24), percent = -3), # index 3 should be progress 
517                                                         MultiContentEntryText(pos = (480, 1), size = (100, 24), font=1, flags = RT_HALIGN_RIGHT, text = 4), # index 4 is the percentage
518                                                 ],
519                                         "fonts": [gFont("Regular", 22),gFont("Regular", 18)],
520                                         "itemHeight": 25
521                                         }
522                                 </convert>
523                         </widget>
524                         <ePixmap position="100,500" size="100,40" zPosition="0" pixmap="~/plugin.png" alphatest="on" transparent="1" />
525                         <ePixmap position="220,500" zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
526                         <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" />
527                 </screen>"""
528
529         def __init__(self, session, plugin_path, tasklist):
530                 Screen.__init__(self, session)
531                 self.skin_path = plugin_path
532                 self.session = session
533                 self.tasklist = tasklist
534                 self["tasklist"] = List(self.tasklist)
535                 
536                 self["shortcuts"] = ActionMap(["ShortcutActions", "WizardActions", "MediaPlayerActions"],
537                 {
538                         "ok": self.keyOK,
539                         "back": self.keyCancel,
540                         "red": self.keyCancel,
541                 }, -1)
542                 
543                 self["key_red"] = Button(_("Close"))
544                 self["title"] = Label()
545                 
546                 self.onLayoutFinish.append(self.layoutFinished)
547                 self.onShown.append(self.setWindowTitle)
548
549         def layoutFinished(self):
550                 self["title"].setText(_("MyTubePlayer active video downloads"))
551
552         def setWindowTitle(self):
553                 self.setTitle(_("MyTubePlayer active video downloads"))
554
555         def keyOK(self):
556                 current = self["tasklist"].getCurrent()
557                 print current
558                 if current:
559                         job = current[0]
560                         from Screens.TaskView import JobView
561                         #job_manager.in_background = False
562                         self.session.openWithCallback(self.JobViewCB, JobView, job)
563         
564         def JobViewCB(self, why):
565                 print "WHY---",why
566                 #job_manager.in_background = in_background
567
568         def keyCancel(self):
569                 self.close()    
570
571         def keySave(self):
572                 self.close()
573
574
575 class MyTubeHistoryScreen(Screen):
576         skin = """
577                 <screen name="MyTubeHistoryScreen" position="60,93" zPosition="6" size="610,160" flags="wfNoBorder" >
578                         <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"/>
579                         <widget source="historylist" render="Listbox" position="10,5" zPosition="7" size="580,150" scrollbarMode="showOnDemand" transparent="1" >
580                                 <convert type="TemplatedMultiContent">
581                                         {"template": [
582                                                         MultiContentEntryText(pos = (0, 1), size = (340, 24), font=0, flags = RT_HALIGN_LEFT, text = 0), # index 0 is the name
583                                                 ],
584                                         "fonts": [gFont("Regular", 22),gFont("Regular", 18)],
585                                         "itemHeight": 25
586                                         }
587                                 </convert>
588                         </widget>
589                 </screen>"""
590
591         def __init__(self, session):
592                 Screen.__init__(self, session)
593                 self.session = session
594                 self.historylist = []
595                 print "self.historylist",self.historylist
596                 self["historylist"] = List(self.historylist)
597                 self.activeState = False
598                 
599         def activate(self):
600                 print "activate"
601                 self.activeState = True
602                 self.history = config.plugins.mytube.general.history.value.split(',')
603                 if self.history[0] == '':
604                         del self.history[0]
605                 print "self.history",self.history
606                 self.historylist = []
607                 for entry in self.history:
608                         self.historylist.append(( str(entry),))
609                 self["historylist"].setList(self.historylist)
610                 self["historylist"].updateList(self.historylist)
611
612         def deactivate(self):
613                 print "deactivate"
614                 self.activeState = False
615
616         def status(self):
617                 print self.activeState
618                 return self.activeState
619         
620         def getSelection(self):
621                 if self["historylist"].getCurrent() is None:
622                         return None
623                 print self["historylist"].getCurrent()[0]
624                 return self["historylist"].getCurrent()[0]
625
626         def up(self):
627                 print "up"
628                 self["historylist"].selectPrevious()
629                 return self.getSelection()
630
631         def down(self):
632                 print "down"
633                 self["historylist"].selectNext()
634                 return self.getSelection()
635         
636         def pageUp(self):
637                 print "up"
638                 self["historylist"].selectPrevious()
639                 return self.getSelection()
640
641         def pageDown(self):
642                 print "down"
643                 self["historylist"].selectNext()
644                 return self.getSelection()
645
646