1 from Plugins.Plugin import PluginDescriptor
3 from Screens.Screen import Screen
4 from Screens.InfoBar import InfoBar
5 from Screens.ChoiceBox import ChoiceBox
6 from Screens.MessageBox import MessageBox
7 from Screens.InfoBarGenerics import InfoBarNotifications
8 from Screens.VirtualKeyBoard import VirtualKeyBoard
10 from Components.PluginComponent import plugins
11 from Components.Button import Button
12 from Components.Label import Label
13 from Components.Sources.StaticText import StaticText
14 from Components.ActionMap import NumberActionMap, ActionMap
15 from Components.ServiceEventTracker import ServiceEventTracker
16 from Components.MenuList import MenuList
17 from Components.Label import Label, MultiColorLabel
18 from Components.ConfigList import ConfigListScreen
19 from Components.VolumeControl import VolumeControl
20 from Components.config import config, ConfigSubsection, ConfigPosition, getConfigListEntry, ConfigBoolean, ConfigInteger, ConfigText, ConfigSelection, configfile, getCharValue
22 from enigma import eTimer, eConsoleAppContainer, getDesktop, eServiceReference, iPlayableService, iServiceInformation, RT_HALIGN_LEFT, RT_HALIGN_RIGHT, RT_HALIGN_CENTER, RT_VALIGN_CENTER, getPrevAsciiCode, eRCInput, fbClass
24 import os, struct, threading, stat, select, time, socket, select
26 strIsEmpty = lambda x: x is None or len(x) == 0
28 HBBTVAPP_PATH = "/usr/local/hbb-browser"
29 COMMAND_PATH = '/tmp/.sock.hbbtv.cmd'
37 channel_info_sid = None
38 channel_info_onid = None
39 channel_info_tsid = None
40 channel_info_name = None
41 channel_info_orgid = None
47 packet_hl = struct.calcsize(packet_h)
48 __gval__ = GlobalValues()
50 def getPacketHeaders():
52 return (__gval__.packet_m, __gval__.packet_h, __gval__.packet_hl)
54 def setChannelInfo(sid, onid, tsid, name, orgid):
55 if sid is None: sid = 0;
56 if onid is None: onid = 0;
57 if tsid is None: tsid = 0;
58 if name is None: name = "";
59 if orgid is None: orgid = 0;
61 __gval__.channel_info_sid = sid
62 __gval__.channel_info_onid = onid
63 __gval__.channel_info_tsid = tsid
64 __gval__.channel_info_name = name
65 __gval__.channel_info_orgid = orgid
66 print "Set Channel Info >> sid : %X, onid : %X, tsid : %X, name : %s, orgid : %d " % (sid, onid, tsid, name, orgid)
67 def getChannelInfos():
69 print "Get Channel Info >> sid : %X, onid : %X, tsid : %X, name : %s, orgid : %d " % (__gval__.channel_info_sid,
70 __gval__.channel_info_onid, __gval__.channel_info_tsid, __gval__.channel_info_name, __gval__.channel_info_orgid)
71 return (__gval__.channel_info_sid,
72 __gval__.channel_info_onid,
73 __gval__.channel_info_tsid,
74 __gval__.channel_info_name,
75 __gval__.channel_info_orgid)
79 return __gval__.command_util
80 def getCommandServer():
82 return __gval__.command_server
84 def setBeforeService(s):
86 __gval__.before_service = s
87 def getBeforeService():
89 return __gval__.before_service
91 def _unpack(packed_data):
92 (mg, h, hlen) = getPacketHeaders()
94 if strIsEmpty(packed_data):
96 (m, o, l, s) = struct.unpack(h, packed_data[:hlen])
101 d = packed_data[hlen:hlen+l]
104 def _pack(opcode, params=None, reserved=0):
105 (m, h, hlen) = getPacketHeaders()
106 if strIsEmpty(params):
108 packed_data = struct.pack(h, m, opcode, len(params), reserved)
109 return packed_data + params
115 ,'User-Agent: NSPlayer/7.10.0.3059 '
117 ,'Connection: Close '
122 for m in self.headers:
123 self.sendmsg += m + '\n'
124 self.sendmsg += '\n\n'
126 def request(self, host, port=80, location='/'):
127 sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
128 sock.connect((host, port))
129 sock.send(self.sendmsg%(location, host))
131 print self.sendmsg%(location, host)
134 res = sock.recv(1024)
140 def parse(self, data):
141 for d in data.splitlines():
142 if d.startswith('Location: '):
146 def getLocationData(self, url):
147 url_list,host,location = None,None,None
149 url = url[url.find(':')+3:]
150 url_list = url.split('/')
152 location = url[len(url_list[0]):]
153 except Exception, err_msg:
156 html = self.request(host=host, location=location)
157 return self.parse(html)
162 "OP_UNKNOWN" : 0x0000
163 ,"OP_HBBTV_EXIT" : 0x0001
164 ,"OP_HBBTV_OPEN_URL" : 0x0002
165 ,"OP_HBBTV_LOAD_AIT" : 0x0003
166 ,"OP_HBBTV_UNLOAD_AIT" : 0x0004
167 ,"OP_HBBTV_FULLSCREEN" : 0x0005
168 ,"OP_HBBTV_TITLE" : 0x0006
169 ,"OP_OIPF_GET_CHANNEL_INFO_URL" : 0x0101
170 ,"OP_OIPF_GET_CHANNEL_INFO_AIT" : 0x0102
171 ,"OP_OIPF_GET_CHANNEL_INFO_LIST": 0x0103
172 ,"OP_VOD_URI" : 0x0201
173 ,"OP_VOD_PLAY" : 0x0202
174 ,"OP_VOD_STOP" : 0x0203
175 ,"OP_VOD_PAUSE" : 0x0204
176 ,"OP_VOD_STATUS" : 0x0205
177 ,"OP_VOD_FORBIDDEN" : 0x0206
178 ,"OP_VOD_STOPED" : 0x0207
179 ,"OP_BROWSER_OPEN_URL" : 0x0301
180 ,"OP_DVBAPP_VOL_UP" : 0x0401
181 ,"OP_DVBAPP_VOL_DOWN" : 0x0402
184 0x0000 : "OP_UNKNOWN"
185 ,0x0001 : "OP_HBBTV_EXIT"
186 ,0x0002 : "OP_HBBTV_OPEN_URL"
187 ,0x0003 : "OP_HBBTV_LOAD_AIT"
188 ,0x0004 : "OP_HBBTV_UNLOAD_AIT"
189 ,0x0005 : "OP_HBBTV_FULLSCREEN"
190 ,0x0006 : "OP_HBBTV_TITLE"
191 ,0x0101 : "OP_OIPF_GET_CHANNEL_INFO_URL"
192 ,0x0102 : "OP_OIPF_GET_CHANNEL_INFO_AIT"
193 ,0x0103 : "OP_OIPF_GET_CHANNEL_INFO_LIST"
194 ,0x0201 : "OP_VOD_URI"
195 ,0x0202 : "OP_VOD_PLAY"
196 ,0x0203 : "OP_VOD_STOP"
197 ,0x0204 : "OP_VOD_PAUSE"
198 ,0x0205 : "OP_VOD_STATUS"
199 ,0x0206 : "OP_VOD_FORBIDDEN"
200 ,0x0207 : "OP_VOD_STOPED"
201 ,0x0301 : "OP_BROWSER_OPEN_URL"
202 ,0x0401 : "OP_DVBAPP_VOL_UP"
203 ,0x0402 : "OP_DVBAPP_VOL_DOWN"
206 def get(self, opstr):
208 return self._opcode_[opstr]
210 return self._opcode_["OP_UNKNOWN"]
212 def what(self, opcode):
214 return self._opstr_[opcode]
216 return self._opstr_["0x0000"]
229 def __init__(self, params):
230 self._protocol = params.protocol
231 self._type = params.type
232 self._addr = params.addr
233 self._buf_size = params.buf_size
234 self._handler = params.handler
235 self._timeout = params.timeout
236 self._destroy = params.destroy
238 self._terminated = False
239 self._server_thread = None
241 self.onHbbTVCloseCB = []
242 self.onSetPageTitleCB = []
245 if self._destroy is not None:
246 self._destroy(self._addr)
249 self._terminated = True
250 if self._server_thread is not None:
251 self._server_thread.join()
252 self._server_thread = None
255 self._socket = socket.socket(self._protocol, self._type)
256 self._socket.settimeout(self._timeout)
257 self._socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
258 self._socket.bind(self._addr)
259 self._socket.listen(True)
261 self._server_thread = threading.Thread(target=self._listen)
262 self._server_thread.start()
265 select_list = [self._socket]
268 conn, addr = self._socket.accept()
269 self._client(conn, addr)
270 except Exception, ErrMsg:
271 print "ServerSocket Error >>", ErrMsg
274 while not self._terminated:
275 readable, writable, errored = select.select(select_list, [], [], self._timeout)
277 if s is self._socket:
280 def _client(self, conn, addr):
283 received_data = conn.recv(self._buf_size)
284 if self._handler is not None and not strIsEmpty(received_data):
285 send_data = self._handler.doHandle(received_data, self.onHbbTVCloseCB, self.onSetPageTitleCB)
286 self._send(conn, send_data)
287 except Exception, ErrMsg:
290 if self._handler is not None:
291 self._handler.printError(ErrMsg)
292 def _send(self, conn, data) :
297 def doListenUnixTCP(self, name, handler):
299 if os.path.exists(name):
301 print "Removed ", name
304 params = SocketParams()
305 params.protocol = socket.AF_UNIX
306 params.type = socket.SOCK_STREAM
308 params.handler = handler
309 params.destroy = destroy
311 streamServer = StreamServer(params)
315 def doListenInetTCP(self, ip, port, handler):
316 print "not implemented yet!!"
317 def doListenUnixDGRAM(self, name, handler):
318 print "not implemented yet!!"
319 def doListenInetDGRAM(self, ip, port, handler):
320 print "not implemented yet!!"
323 def doUnpack(self, data):
326 def doPack(self, opcode, params, reserved=0):
327 return _pack(opcode, params, reserved)
329 def doHandle(self, data, onCloseCB):
330 opcode, params = 0x0, 'Invalid Request!!'
331 return _pack(opcode, params)
333 def printError(self, reason):
336 class BrowserCommandUtil(OpCodeSet):
339 OpCodeSet.__init__(self)
341 def isConnected(self):
346 def doConnect(self, filename):
347 if not os.path.exists(filename):
348 print "file not exists :", filename
351 self._fd = os.open(filename, os.O_WRONLY|os.O_NONBLOCK)
353 print "fail to open file :", filename
355 except Exception, ErrMsg:
359 print "connected!! to ", filename
362 def doDisconnect(self):
368 def doSend(self, command, params=None, reserved=0):
370 print "connected pipe was not exists!!"
374 data = _pack(self.get(command), params, reserved)
377 os.write(self._fd, data)
378 print "Send OK!! :", command
382 def sendCommand(self, command, params=None, reserved=0):
383 if not self.isConnected():
385 self.doConnect(COMMAND_PATH)
386 result = self.doSend(command, params, reserved)
390 class HandlerHbbTV(Handler):
392 def __init__(self, session):
393 self._session = session
394 self.opcode = OpCodeSet()
396 0x0001 : self._cb_handleCloseHbbTVBrowser
397 ,0x0006 : self._cb_handleSetPageTitle
398 ,0x0101 : self._cb_handleGetChannelInfoForUrl
399 ,0x0102 : self._cb_handleGetChannelInfoForAIT
400 ,0x0103 : self._cb_handleGetChannelInfoList
401 ,0x0201 : self._cb_handleVODPlayerURI
402 ,0x0202 : self._cb_handleVODPlayerPlay
403 ,0x0203 : self._cb_handleVODPlayerStop
404 ,0x0204 : self._cb_handleVODPlayerPlayPause
405 ,0x0401 : self._cb_handleDVBAppVolUp
406 ,0x0402 : self._cb_handleDVBAppVolDown
408 self._on_close_cb = None
409 self._on_set_title_cb = None
413 def _handle_dump(self, handle, opcode, data=None):
417 print " - opcode : ", self.opcode.what(opcode)
419 print " - data : ", data
421 def doHandle(self, data, onCloseCB, onSetPageTitleCB):
422 opcode, params, reserved = None, None, 0
423 self._on_close_cb = onCloseCB
424 self._on_set_title_cb = onSetPageTitleCB
426 datas = self.doUnpack(data)
427 except Exception, ErrMsg:
428 print "Unpacking packet ERR :", ErrMsg
429 params = 'fail to unpack packet!!'
430 opcode = self.opcode.get("OP_UNKNOWN")
431 return self.doPack(opcode, params)
435 self.opcode.what(opcode)
438 #print self.handle_map[opcode]
439 (reserved, params) = self.handle_map[opcode](opcode, params)
440 except Exception, ErrMsg:
441 print "Handling packet ERR :", ErrMsg
442 params = 'fail to handle packet!!'
443 opcode = self.opcode.get("OP_UNKNOWN")
444 return self.doPack(opcode, params)
445 self._on_close_cb = None
446 self._on_set_title_cb = None
447 return self.doPack(opcode, params, reserved)
449 def _cb_handleDVBAppVolUp(self, opcode, data):
450 self._handle_dump(self._cb_handleDVBAppVolUp, opcode, data)
451 vcm = VolumeControl.instance
455 def _cb_handleDVBAppVolDown(self, opcode, data):
456 self._handle_dump(self._cb_handleDVBAppVolDown, opcode, data)
457 vcm = VolumeControl.instance
461 def _cb_handleGetChannelInfoForUrl(self, opcode, data):
462 self._handle_dump(self._cb_handleGetChannelInfoForUrl, opcode, data)
463 (sid, onid, tsid, name, orgid) = getChannelInfos()
465 return (0, struct.pack('!IIII', sid, onid, tsid, namelen) + name)
467 def _cb_handleGetChannelInfoForAIT(self, opcode, data):
468 self._handle_dump(self._cb_handleGetChannelInfoForAIT, opcode, data)
469 (sid, onid, tsid, name, orgid) = getChannelInfos()
471 return (0, struct.pack('!IIIII', orgid, sid, onid, tsid, namelen) + name)
473 def _cb_handleGetChannelInfoList(self, opcode, data):
474 self._handle_dump(self._cb_handleGetChannelInfoList, opcode, data)
475 (sid, onid, tsid, name, orgid) = getChannelInfos()
477 channel_list_size = 1
478 return (channel_list_size, struct.pack('!IIII', sid, onid, tsid, namelen) + name)
480 def _cb_handleSetPageTitle(self, opcode, data):
481 self._handle_dump(self._cb_handleCloseHbbTVBrowser, opcode, data)
482 if data.startswith('file://') or data.startswith('http://'):
484 if self._on_set_title_cb is not None:
485 for x in self._on_set_title_cb:
488 except Exception, ErrMsg:
489 if x in self._on_set_title_cb:
490 self._on_set_title_cb.remove(x)
493 def _cb_handleCloseHbbTVBrowser(self, opcode, data):
494 self._handle_dump(self._cb_handleCloseHbbTVBrowser, opcode, data)
496 if self._on_close_cb:
497 for x in self._on_close_cb:
500 except Exception, ErrMsg:
501 if x in self._on_close_cb:
502 self._on_close_cb.remove(x)
504 command_util = getCommandUtil()
505 command_util.sendCommand('OP_HBBTV_FULLSCREEN', None)
507 before_service = getBeforeService()
508 if before_service is not None:
509 self._session.nav.playService(before_service)
513 def _cb_handleVODPlayerURI(self, opcode, data):
515 hl = struct.calcsize('!II')
516 datas = struct.unpack('!II', data[:hl])
518 vodUri = data[hl:hl+uriLength]
519 self._handle_dump(self._cb_handleVODPlayerURI, opcode, vodUri)
520 self._vod_uri = vodUri
523 def doStop(self, restoreBeforeService=True, needStop=True):
525 self._session.nav.stopService()
526 if self._vod_service is not None and restoreBeforeService:
527 before_service = getBeforeService()
528 self._session.nav.playService(before_service)
530 self._vod_service = None
535 def doRetryOpen(self, url):
539 self._vod_service = None
541 print "try to open vod [%d] : %s" % (ii, url)
542 self._vod_service = eServiceReference(4097, 0, url)
543 self._session.nav.playService(self._vod_service)
544 if self._vod_service is not None:
546 except Exception, ErrMsg:
547 print "OpenVOD ERR :", ErrMsg
551 def _cb_handleVODPlayerPlay(self, opcode, data):
552 self._handle_dump(self._cb_handleVODPlayerPlay, opcode, data)
553 self.doStop(restoreBeforeService=False)
554 if self.doRetryOpen(url=self._vod_uri) == False:
558 def _cb_handleVODPlayerStop(self, opcode, data):
559 self._handle_dump(self._cb_handleVODPlayerStop, opcode, data)
563 def _cb_handleVODPlayerPlayPause(self, opcode, data):
564 self._handle_dump(self._cb_handleVODPlayerPlayPause, opcode, data)
565 service = self._session.nav.getCurrentService()
568 servicePause = service.pause()
570 servicePause.unpause()
571 elif pauseFlag == 'P':
573 except Exception, ErrMsg:
574 print "onPause ERR :", ErrMsg
577 from libshm import SimpleSharedMemory
579 class HbbTVWindow(Screen, InfoBarNotifications):
581 <screen name="HbbTVWindow" position="0,0" size="1280,720" backgroundColor="transparent" flags="wfNoBorder" title="HbbTV Plugin">
584 def __init__(self, session, url=None, cbf=None, useAIT=False, profile=0):
585 self._session = session
586 eRCInput.getInstance().lock()
588 Screen.__init__(self, session)
589 InfoBarNotifications.__init__(self)
590 self.__event_tracker = ServiceEventTracker(screen = self, eventmap = {
591 iPlayableService.evUser+20: self._serviceForbiden,
592 iPlayableService.evStart: self._serviceStarted,
593 iPlayableService.evEOF: self._serviceEOF,
597 self._use_ait = useAIT
598 self._profile = profile
599 self._cb_closed_func = cbf
600 self.onLayoutFinish.append(self._layoutFinished)
602 command_server = getCommandServer()
603 if self._cb_set_page_title not in command_server.onSetPageTitleCB:
604 command_server.onSetPageTitleCB.append(self._cb_set_page_title)
606 if self._cb_close_window not in command_server.onHbbTVCloseCB:
607 command_server.onHbbTVCloseCB.append(self._cb_close_window)
609 self._closeTimer = eTimer()
610 self._closeTimer.callback.append(self._do_close)
612 self._currentServicePositionTimer = eTimer()
613 self._currentServicePositionTimer.callback.append(self._cb_currentServicePosition)
620 def getVodPlayTime(self):
622 service = self._session.nav.getCurrentService()
623 seek = service and service.seek()
625 p = seek.getPlayPosition()
626 #return (p[1]/90000, l[1]/90000)
631 def _cb_currentServicePosition(self):
632 def getTimeString(t):
633 t = time.localtime(t/90000)
634 return "%2d:%02d:%02d" % (t.tm_hour, t.tm_min, t.tm_sec)
635 position,length = 0,0
637 (position,length) = self.getVodPlayTime()
638 self._vod_length = length
639 if position == -1 and length == -1:
640 raise "can't get play status"
641 #print getTimeString(position), "/", getTimeString(length)
642 self._ssm.setStatus(position, length, 1)
643 except Exception, ErrMsg:
647 def _serviceStarted(self):
649 self._ssm.setStatus(0, 0, 0)
650 self._currentServicePositionTimer.start(1000)
651 except Exception, ErrMsg:
654 def _serviceEOF(self):
655 self._currentServicePositionTimer.stop()
657 def _layoutFinished(self):
658 command_util = getCommandUtil()
659 profile = self._profile
660 (sid, onid, tsid, name, orgid) = getChannelInfos()
661 params = struct.pack('!IIIIII', orgid, profile, sid, onid, tsid, len(name)) + name
663 command_util.sendCommand('OP_HBBTV_UNLOAD_AIT')
665 command_util.sendCommand('OP_HBBTV_LOAD_AIT', params, 1)
667 command_util.sendCommand('OP_HBBTV_LOAD_AIT', params)
669 command_util.sendCommand('OP_HBBTV_OPEN_URL', self._url)
671 def _cb_close_window(self):
672 self._closeTimer.start(1000)
675 self._closeTimer.stop()
676 command_server = getCommandServer()
678 if self._cb_set_page_title in command_server.onSetPageTitleCB:
679 command_server.onSetPageTitleCB.remove(self._cb_set_page_title)
680 except Exception, ErrMsg: pass
682 if self._cb_close_window in command_server.onHbbTVCloseCB:
683 command_server.onHbbTVCloseCB.remove(self._cb_close_window)
684 except Exception, ErrMsg: pass
686 if self._cb_closed_func is not None:
687 self._cb_closed_func()
689 eRCInput.getInstance().unlock()
692 def _serviceForbiden(self):
694 real_url = MMSStreamURL().getLocationData(__gval__.hbbtv_handelr.getUrl())
695 print "Received URI :\n",real_url
697 if real_url is not None:
698 __gval__.hbbtv_handelr.doRetryOpen(real_url.strip())
700 def _cb_set_page_title(self, title=None):
701 print "page title :",title
706 class HbbTVHelper(Screen):
707 skin = """<screen name="HbbTVHelper" position="0,0" size="0,0" backgroundColor="transparent" flags="wfNoBorder" title=" "></screen>"""
708 def __init__(self, session):
710 __gval__.hbbtv_handelr = HandlerHbbTV(session)
711 __gval__.command_server = ServerFactory().doListenUnixTCP('/tmp/.sock.hbbtv.url', __gval__.hbbtv_handelr)
717 Screen.__init__(self, session)
718 self._session = session
719 self._timer_infobar = eTimer()
720 self._timer_infobar.callback.append(self._cb_registrate_infobar)
721 self._timer_infobar.start(1000)
723 self._excuted_browser = False
726 __gval__.command_util = BrowserCommandUtil()
730 _g_ssm_ = SimpleSharedMemory()
733 def _cb_registrate_infobar(self):
735 self._timer_infobar.stop()
736 if self._cb_ready_for_ait not in InfoBar.instance.onReadyForAIT:
737 InfoBar.instance.onReadyForAIT.append(self._cb_ready_for_ait)
738 if self._cb_hbbtv_activated not in InfoBar.instance.onHBBTVActivation:
739 InfoBar.instance.onHBBTVActivation.append(self._cb_hbbtv_activated)
741 def _cb_ready_for_ait(self, orgId=0):
743 if not self._excuted_browser:
744 command_util = getCommandUtil()
745 command_util.sendCommand('OP_HBBTV_UNLOAD_AIT')
747 setChannelInfo(None, None, None, None, None)
749 service = self._session.nav.getCurrentService()
750 info = service and service.info()
752 sid = info.getInfo(iServiceInformation.sSID)
753 onid = info.getInfo(iServiceInformation.sONID)
754 tsid = info.getInfo(iServiceInformation.sTSID)
755 name = info.getName()
760 for x in info.getInfoObject(iServiceInformation.sHBBTVUrl):
764 setChannelInfo(sid, onid, tsid, name, orgid)
766 def _cb_hbbtv_activated(self, title=None, url=None):
767 if not self._is_browser_running():
768 message = "HbbTV Browser was not running.\nPlease running browser before start HbbTV Application."
769 self.session.open(MessageBox, message, MessageBox.TYPE_INFO)
771 service = self._session.nav.getCurrentlyPlayingServiceReference()
772 setBeforeService(service)
773 self._start_hbbtv_application(title, url)
775 def _start_hbbtv_application(self, title, url):
776 tmp_url = self.getStartHbbTVUrl()
780 print "can't get url of hbbtv!!"
782 print "success to get url of hbbtv!! >>", url
783 if self._excuted_browser:
784 print "already excuted opera browser!!"
792 if tmp_url == url and control_code == 1:
794 self._excuted_browser = True
795 self._session.open(HbbTVWindow, url, self._cb_closed_browser, use_ait, self._profile)
797 def _cb_closed_browser(self):
798 self._excuted_browser = False
800 def _start_opera(self):
801 if not self._is_browser_running():
803 start_command = '%s/launcher start'%(HBBTVAPP_PATH)
804 os.system(start_command)
806 def _stop_opera(self):
808 try: os.system('%s/launcher stop'%(HBBTVAPP_PATH))
811 def getStartHbbTVUrl(self):
812 url, self._urls, self._profile = None, None, 0
813 service = self._session.nav.getCurrentService()
814 info = service and service.info()
815 if not info: return None
816 self._urls = info.getInfoObject(iServiceInformation.sHBBTVUrl)
818 if u[0] in (1, -1): # 0:control code, 1:name, 2:url, 3:orgid, 4:appid, 5:profile code
822 url = info.getInfoString(iServiceInformation.sHBBTVUrl)
825 def showApplicationSelectionBox(self):
828 if self.getStartHbbTVUrl():
830 applications.append((x[1], x))
831 else: applications.append(("No detected HbbTV applications.", None))
832 self._session.openWithCallback(self._application_selected, ChoiceBox, title=_("Please choose an HbbTV application."), list=applications)
834 def _application_selected(self, selected):
836 if selected[1] is None: return
837 self._cb_hbbtv_activated(selected[1][1], selected[1][2])
838 except Exception, ErrMsg: print ErrMsg
840 def showBrowserConfigBox(self):
842 if self._is_browser_running():
843 start_stop_mode.append(('Stop',None))
844 else: start_stop_mode.append(('Start',None))
845 self._session.openWithCallback(self._browser_config_selected, ChoiceBox, title=_("Please choose one."), list=start_stop_mode)
847 def _browser_config_selected(self, selected):
853 if not self._is_browser_running():
857 except Exception, ErrMsg: print "Config ERR :", ErrMsg
859 def _is_browser_running(self):
862 ret = os.popen('%s/launcher check'%(HBBTVAPP_PATH)).read()
863 return ret.strip() != "0"
864 except Exception, ErrMsg:
865 print "Check Browser Running ERR :", ErrMsg
869 class OperaBrowser(Screen):
870 MENUBAR_ITEM_WIDTH = 150
871 MENUBAR_ITEM_HEIGHT = 30
872 SUBMENULIST_WIDTH = 200
873 SUBMENULIST_HEIGHT = 25
877 <screen name="Opera Browser" position="0,0" size="1280,720" backgroundColor="transparent" flags="wfNoBorder" title="Opera Browser">
878 <widget name="topArea" zPosition="-1" position="0,0" size="1280,60" font="Regular;20" valign="center" halign="center" backgroundColor="#000000" />
879 <widget name="menuitemFile" position="30,20" size="150,30" font="Regular;20" valign="center" halign="center" backgroundColor="#000000" foregroundColors="#9f1313,#a08500" />
880 <widget name="menuitemHelp" position="180,20" size="150,30" font="Regular;20" valign="center" halign="center" backgroundColor="#000000" foregroundColors="#9f1313,#a08500" />
881 <widget name="menulist" position="50,%d" size="%d,150" backgroundColor="#000000" zPosition="10" scrollbarMode="showOnDemand" />
882 <widget name="submenulist" position="%d,%d" size="%d,150" backgroundColor="#000000" zPosition="10" scrollbarMode="showOnDemand" />
883 <widget name="bottomArea" position="0,640" size="1280,80" font="Regular;20" valign="center" halign="center" backgroundColor="#000000" />
885 """ % (MENUBAR_ITEM_HEIGHT+30, SUBMENULIST_WIDTH, SUBMENULIST_WIDTH+50+SUBMENULIST_NEXT, MENUBAR_ITEM_HEIGHT+30, SUBMENULIST_WIDTH)
887 MENUITEMS_LIST =[[('Open Location', None), ('Start/Stop',None), ('Exit', None)],
889 def __init__(self, session):
890 Screen.__init__(self, session)
892 self["actions"] = ActionMap(["MinuteInputActions", "ColorActions", "InputActions", "InfobarChannelSelection", "EPGSelectActions", "KeyboardInputActions"], {
893 "cancel" : self.keyCancel
895 ,"left" : self.keyLeft
896 ,"right" : self.keyRight
898 ,"down" : self.keyDown
899 ,"menu" : self.keyCancel
902 self.menubarCurrentIndex = 0
903 self.lvMenuItems = []
904 self.lvSubMenuItems = []
906 self["topArea"] = Label()
907 self["bottomArea"] = Label()
909 self["menuitemFile"] = MultiColorLabel()
910 self["menuitemHelp"] = MultiColorLabel()
912 self["menulist"] = MenuList(self.setListOnView())
913 self["submenulist"] = MenuList(self.setSubListOnView())
915 self.toggleMainScreenFlag = True
916 self.toggleListViewFlag = False
917 self.toggleSubListViewFlag = False
918 self.currentListView = self["menulist"]
920 self.onLayoutFinish.append(self.layoutFinished)
922 self._onCloseTimer = eTimer()
923 self._onCloseTimer.callback.append(self._cb_onClose)
925 def enableRCMouse(self, mode): #mode=[0|1]|[False|True]
926 rcmouse_path = "/proc/stb/fp/mouse"
927 if os.path.exists(rcmouse_path):
928 os.system("echo %d > %s" % (mode, rcmouse_path))
930 def layoutFinished(self):
931 self["menuitemFile"].setText("File")
932 self["menuitemHelp"].setText("Help")
934 self["menulist"].hide()
935 self["submenulist"].hide()
937 self["bottomArea"].setText("Opera Web Browser Plugin v0.1")
938 self.setTitle("BrowserMain")
939 self.selectMenuitem()
941 def selectMenuitem(self):
942 tmp = [self["menuitemFile"], self["menuitemHelp"]]
943 self["menuitemFile"].setForegroundColorNum(0)
944 self["menuitemHelp"].setForegroundColorNum(0)
945 tmp[self.menubarCurrentIndex].setForegroundColorNum(1)
947 def popupCloseAll(self):
953 def setListOnView(self):
954 self.lvMenuItems = self.MENUITEMS_LIST[self.menubarCurrentIndex]
955 return self.lvMenuItems
957 def setSubListOnView(self):
958 self.lvSubMenuItems = []
959 xl = self["menulist"].getCurrent()[1]
960 if xl is None: return []
962 self.lvSubMenuItems.append((x,None))
963 return self.lvSubMenuItems
965 def toggleMainScreen(self):
966 if not self.toggleMainScreenFlag:
969 self.toggleMainScreenFlag = not self.toggleMainScreenFlag
971 def toggleListView(self):
972 if not self.toggleListViewFlag:
973 self["menulist"].show()
974 else: self["menulist"].hide()
975 self.toggleListViewFlag = not self.toggleListViewFlag
977 def toggleSubListView(self):
978 if not self.toggleSubListViewFlag:
979 self["submenulist"].show()
980 else: self["submenulist"].hide()
981 self.toggleSubListViewFlag = not self.toggleSubListViewFlag
983 def setCurrentListView(self, listViewIdx):
985 self.currentListView = None
986 elif listViewIdx == 1:
987 self.currentListView = self["menulist"]
988 elif listViewIdx == 2:
989 self.currentListView = self["submenulist"]
991 def _cb_onClose(self):
992 self._onCloseTimer.stop()
993 command_server = getCommandServer()
995 if self._on_close_window in command_server.onHbbTVCloseCB:
996 command_server.onHbbTVCloseCB.remove(self._on_close_window)
997 except Exception, ErrMsg: pass
999 if self._on_setPageTitle in command_server.onSetPageTitleCB:
1000 command_server.onSetPageTitleCB.remove(self._on_setPageTitle)
1001 except Exception, ErrMsg: pass
1002 self._on_setPageTitle('Opera Browser')
1003 self.enableRCMouse(False)
1004 self.toggleMainScreen()
1005 eRCInput.getInstance().unlock()
1007 def _on_setPageTitle(self, title=None):
1008 print "page title :",title
1011 self.setTitle(title)
1013 def cbUrlText(self, data=None):
1014 print "Inputed Url :", data
1015 if strIsEmpty(data):
1017 command_server = getCommandServer()
1018 if self._on_setPageTitle not in command_server.onSetPageTitleCB:
1019 command_server.onSetPageTitleCB.append(self._on_setPageTitle)
1020 if self._on_close_window not in command_server.onHbbTVCloseCB:
1021 command_server.onHbbTVCloseCB.append(self._on_close_window)
1022 self.toggleMainScreen()
1023 self.enableRCMouse(True)
1024 eRCInput.getInstance().lock()
1025 command_util = getCommandUtil()
1026 command_util.sendCommand('OP_BROWSER_OPEN_URL', data)
1028 def _on_close_window(self):
1029 self._onCloseTimer.start(1000)
1031 def _cmd_on_OpenLocation(self):
1033 if not _g_helper._is_browser_running():
1034 message = "Opera Browser was not running.\nPlease running browser using [File]>[Start/Stop] menu."
1035 self.session.open(MessageBox, message, MessageBox.TYPE_INFO)
1037 self.session.openWithCallback(self.cbUrlText, VirtualKeyBoard, title=("Please enter URL here"), text='http://')
1038 def _cmd_on_About(self):
1039 self.session.open(MessageBox, 'Opera Web Browser Plugin v0.1(beta)', type = MessageBox.TYPE_INFO)
1040 def _cmd_on_Exit(self):
1042 def _cmd_on_StartStop(self):
1044 if _g_helper is None:
1046 _g_helper.showBrowserConfigBox()
1047 def doCommand(self, command):
1049 'Exit' :self._cmd_on_Exit
1050 ,'About' :self._cmd_on_About
1051 ,'Open Location' :self._cmd_on_OpenLocation
1052 ,'Start/Stop' :self._cmd_on_StartStop
1059 if not self.toggleListViewFlag:
1062 if self.currentListView.getCurrent()[1] is None:
1063 self.doCommand(self.currentListView.getCurrent()[0])
1064 #self.session.open(MessageBox, _(self.currentListView.getCurrent()[0]), type = MessageBox.TYPE_INFO)
1068 def updateSelectedMenuitem(self, status):
1069 if self.menubarCurrentIndex == 0 and status < 0:
1070 self.menubarCurrentIndex = 1
1071 elif self.menubarCurrentIndex == 1 and status > 0:
1072 self.menubarCurrentIndex = 0
1073 else: self.menubarCurrentIndex += status
1074 self.selectMenuitem()
1077 if not self.toggleMainScreenFlag:
1079 if not self.toggleListViewFlag:
1080 self.updateSelectedMenuitem(-1)
1082 if self.toggleSubListViewFlag:
1083 self.setCurrentListView(1)
1084 self.toggleSubListView()
1086 if self.currentListView.getSelectedIndex():
1087 self.currentListView.pageUp()
1090 if not self.toggleMainScreenFlag:
1092 if not self.toggleListViewFlag:
1093 self.updateSelectedMenuitem(1)
1095 if self.currentListView is None:
1097 if self.currentListView.getCurrent()[1] is not None:
1098 parentSelectedIndex = self.currentListView.getSelectedIndex()
1099 self.setCurrentListView(2)
1100 self.currentListView.setList(self.setSubListOnView())
1101 self.currentListView.resize(self.SUBMENULIST_WIDTH, self.SUBMENULIST_HEIGHT*len(self.lvSubMenuItems)+5)
1102 self.currentListView.move(self.MENUBAR_ITEM_WIDTH*self.menubarCurrentIndex + self.SUBMENULIST_WIDTH+self.SUBMENULIST_NEXT + 50,self.MENUBAR_ITEM_HEIGHT+30+(parentSelectedIndex*self.SUBMENULIST_HEIGHT))
1103 self.toggleSubListView()
1106 if not self.toggleMainScreenFlag:
1108 if self.currentListView is None:
1110 if not self.toggleListViewFlag:
1111 self.currentListView.setList(self.setListOnView())
1112 self.currentListView.resize(self.SUBMENULIST_WIDTH, self.SUBMENULIST_HEIGHT*len(self.lvMenuItems)+5)
1113 self.currentListView.move(self.MENUBAR_ITEM_WIDTH*self.menubarCurrentIndex+1+ 50,self.MENUBAR_ITEM_HEIGHT+30)
1114 self.toggleListView()
1116 self.currentListView.down()
1119 if not self.toggleMainScreenFlag:
1121 if self.currentListView is None:
1123 if self.currentListView == self["menulist"]:
1124 if self.currentListView.getSelectedIndex() == 0:
1125 self.toggleListView()
1127 self.currentListView.up()
1129 def keyCancel(self):
1130 self.toggleMainScreen()
1132 def auto_start_main(reason, **kwargs):
1134 command_server = getCommandServer()
1135 command_server.stop()
1137 def session_start_main(session, reason, **kwargs):
1139 _g_helper = session.open(HbbTVHelper)
1141 def plugin_start_main(session, **kwargs):
1142 session.open(OperaBrowser)
1144 def plugin_extension_start_application(session, **kwargs):
1146 if _g_helper is None:
1148 _g_helper.showApplicationSelectionBox()
1150 def plugin_extension_browser_config(session, **kwargs):
1152 if _g_helper is None:
1154 _g_helper.showBrowserConfigBox()
1156 def Plugins(path, **kwargs):
1158 PluginDescriptor(where=PluginDescriptor.WHERE_AUTOSTART, fnc=auto_start_main),
1159 PluginDescriptor(where=PluginDescriptor.WHERE_SESSIONSTART, needsRestart=True, fnc=session_start_main, weight=-10),
1160 PluginDescriptor(name="HbbTV Applications", where=PluginDescriptor.WHERE_EXTENSIONSMENU, needsRestart=True, fnc=plugin_extension_start_application),
1161 PluginDescriptor(name="Browser Start/Stop", where=PluginDescriptor.WHERE_EXTENSIONSMENU, needsRestart=True, fnc=plugin_extension_browser_config),
1162 PluginDescriptor(name="Opera Web Browser", description="start opera web browser", where=PluginDescriptor.WHERE_PLUGINMENU, needsRestart=True, fnc=plugin_start_main),