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
578 class HbbTVWindow(Screen, InfoBarNotifications):
580 <screen name="HbbTVWindow" position="0,0" size="1280,720" backgroundColor="transparent" flags="wfNoBorder" title="HbbTV Plugin">
583 def __init__(self, session, url=None, cbf=None, useAIT=False, profile=0):
584 self._session = session
585 eRCInput.getInstance().lock()
587 Screen.__init__(self, session)
588 InfoBarNotifications.__init__(self)
589 self.__event_tracker = ServiceEventTracker(screen = self, eventmap = {
590 iPlayableService.evUser+20: self._serviceForbiden,
591 iPlayableService.evStart: self._serviceStarted,
592 iPlayableService.evEOF: self._serviceEOF,
596 self._use_ait = useAIT
597 self._profile = profile
598 self._cb_closed_func = cbf
599 self.onLayoutFinish.append(self._layoutFinished)
601 command_server = getCommandServer()
602 if self._cb_set_page_title not in command_server.onSetPageTitleCB:
603 command_server.onSetPageTitleCB.append(self._cb_set_page_title)
605 if self._cb_close_window not in command_server.onHbbTVCloseCB:
606 command_server.onHbbTVCloseCB.append(self._cb_close_window)
608 self._closeTimer = eTimer()
609 self._closeTimer.callback.append(self._do_close)
611 self._currentServicePositionTimer = eTimer()
612 self._currentServicePositionTimer.callback.append(self._cb_currentServicePosition)
615 self._ssm = SimpleSharedMemory()
618 def getVodPlayTime(self):
620 service = self._session.nav.getCurrentService()
621 seek = service and service.seek()
623 p = seek.getPlayPosition()
624 #return (p[1]/90000, l[1]/90000)
629 def _cb_currentServicePosition(self):
630 def getTimeString(t):
631 t = time.localtime(t/90000)
632 return "%2d:%02d:%02d" % (t.tm_hour, t.tm_min, t.tm_sec)
633 position,length = 0,0
635 (position,length) = self.getVodPlayTime()
636 self._vod_length = length
637 if position == -1 and length == -1:
638 raise "can't get play status"
639 #print getTimeString(position), "/", getTimeString(length)
640 self._ssm.setStatus(position, length, 1)
641 except Exception, ErrMsg:
645 def _serviceStarted(self):
647 self._ssm.doConnect()
648 self._ssm.setStatus(0, 0, 0)
649 self._currentServicePositionTimer.start(1000)
650 except Exception, ErrMsg:
653 def _serviceEOF(self):
654 self._currentServicePositionTimer.stop()
655 if self._vod_length == -1:
658 self._ssm.setStatus(self._vod_length, self._vod_length, 2)
661 except Exception, ErrMsg:
663 command_util = getCommandUtil()
664 command_util.sendCommand('OP_VOD_STOPED', None)
666 def _layoutFinished(self):
667 command_util = getCommandUtil()
668 profile = self._profile
669 (sid, onid, tsid, name, orgid) = getChannelInfos()
670 params = struct.pack('!IIIIII', orgid, profile, sid, onid, tsid, len(name)) + name
672 command_util.sendCommand('OP_HBBTV_UNLOAD_AIT')
674 command_util.sendCommand('OP_HBBTV_LOAD_AIT', params, 1)
676 command_util.sendCommand('OP_HBBTV_LOAD_AIT', params)
678 command_util.sendCommand('OP_HBBTV_OPEN_URL', self._url)
680 def _cb_close_window(self):
681 self._closeTimer.start(1000)
684 self._closeTimer.stop()
685 command_server = getCommandServer()
687 if self._cb_set_page_title in command_server.onSetPageTitleCB:
688 command_server.onSetPageTitleCB.remove(self._cb_set_page_title)
689 except Exception, ErrMsg: pass
691 if self._cb_close_window in command_server.onHbbTVCloseCB:
692 command_server.onHbbTVCloseCB.remove(self._cb_close_window)
693 except Exception, ErrMsg: pass
695 if self._cb_closed_func is not None:
696 self._cb_closed_func()
698 eRCInput.getInstance().unlock()
701 def _serviceForbiden(self):
703 real_url = MMSStreamURL().getLocationData(__gval__.hbbtv_handelr.getUrl())
704 print "Received URI :\n",real_url
706 if real_url is not None:
707 __gval__.hbbtv_handelr.doRetryOpen(real_url.strip())
709 def _cb_set_page_title(self, title=None):
710 print "page title :",title
715 class HbbTVHelper(Screen):
716 skin = """<screen name="HbbTVHelper" position="0,0" size="0,0" backgroundColor="transparent" flags="wfNoBorder" title=" "></screen>"""
717 def __init__(self, session):
719 __gval__.hbbtv_handelr = HandlerHbbTV(session)
720 __gval__.command_server = ServerFactory().doListenUnixTCP('/tmp/.sock.hbbtv.url', __gval__.hbbtv_handelr)
726 Screen.__init__(self, session)
727 self._session = session
728 self._timer_infobar = eTimer()
729 self._timer_infobar.callback.append(self._cb_registrate_infobar)
730 self._timer_infobar.start(1000)
732 self._excuted_browser = False
735 __gval__.command_util = BrowserCommandUtil()
737 def _cb_registrate_infobar(self):
739 self._timer_infobar.stop()
740 if self._cb_ready_for_ait not in InfoBar.instance.onReadyForAIT:
741 InfoBar.instance.onReadyForAIT.append(self._cb_ready_for_ait)
742 if self._cb_hbbtv_activated not in InfoBar.instance.onHBBTVActivation:
743 InfoBar.instance.onHBBTVActivation.append(self._cb_hbbtv_activated)
745 def _cb_ready_for_ait(self, orgId=0):
747 if not self._excuted_browser:
748 command_util = getCommandUtil()
749 command_util.sendCommand('OP_HBBTV_UNLOAD_AIT')
751 setChannelInfo(None, None, None, None, None)
753 service = self._session.nav.getCurrentService()
754 info = service and service.info()
756 sid = info.getInfo(iServiceInformation.sSID)
757 onid = info.getInfo(iServiceInformation.sONID)
758 tsid = info.getInfo(iServiceInformation.sTSID)
759 name = info.getName()
764 for x in info.getInfoObject(iServiceInformation.sHBBTVUrl):
768 setChannelInfo(sid, onid, tsid, name, orgid)
770 def _cb_hbbtv_activated(self, title=None, url=None):
771 if not self._is_browser_running():
772 message = "HbbTV Browser was not running.\nPlease running browser before start HbbTV Application."
773 self.session.open(MessageBox, message, MessageBox.TYPE_INFO)
775 service = self._session.nav.getCurrentlyPlayingServiceReference()
776 setBeforeService(service)
777 self._start_hbbtv_application(title, url)
779 def _start_hbbtv_application(self, title, url):
780 tmp_url = self.getStartHbbTVUrl()
784 print "can't get url of hbbtv!!"
786 print "success to get url of hbbtv!! >>", url
787 if self._excuted_browser:
788 print "already excuted opera browser!!"
796 if tmp_url == url and control_code == 1:
798 self._excuted_browser = True
799 self._session.open(HbbTVWindow, url, self._cb_closed_browser, use_ait, self._profile)
801 def _cb_closed_browser(self):
802 self._excuted_browser = False
804 def _start_opera(self):
805 if not self._is_browser_running():
807 start_command = '%s/launcher start'%(HBBTVAPP_PATH)
808 os.system(start_command)
810 def _stop_opera(self):
812 try: os.system('%s/launcher stop'%(HBBTVAPP_PATH))
815 def getStartHbbTVUrl(self):
816 url, self._urls, self._profile = None, None, 0
817 service = self._session.nav.getCurrentService()
818 info = service and service.info()
819 if not info: return None
820 self._urls = info.getInfoObject(iServiceInformation.sHBBTVUrl)
822 if u[0] in (1, -1): # 0:control code, 1:name, 2:url, 3:orgid, 4:appid, 5:profile code
826 url = info.getInfoString(iServiceInformation.sHBBTVUrl)
829 def showApplicationSelectionBox(self):
832 if self.getStartHbbTVUrl():
834 applications.append((x[1], x))
835 else: applications.append(("No detected HbbTV applications.", None))
836 self._session.openWithCallback(self._application_selected, ChoiceBox, title=_("Please choose an HbbTV application."), list=applications)
838 def _application_selected(self, selected):
840 if selected[1] is None: return
841 self._cb_hbbtv_activated(selected[1][1], selected[1][2])
842 except Exception, ErrMsg: print ErrMsg
844 def showBrowserConfigBox(self):
846 if self._is_browser_running():
847 start_stop_mode.append(('Stop',None))
848 else: start_stop_mode.append(('Start',None))
849 self._session.openWithCallback(self._browser_config_selected, ChoiceBox, title=_("Please choose one."), list=start_stop_mode)
851 def _browser_config_selected(self, selected):
857 if not self._is_browser_running():
861 except Exception, ErrMsg: print "Config ERR :", ErrMsg
863 def _is_browser_running(self):
866 ret = os.popen('%s/launcher check'%(HBBTVAPP_PATH)).read()
867 return ret.strip() != "0"
868 except Exception, ErrMsg:
869 print "Check Browser Running ERR :", ErrMsg
873 class OperaBrowser(Screen):
874 MENUBAR_ITEM_WIDTH = 150
875 MENUBAR_ITEM_HEIGHT = 30
876 SUBMENULIST_WIDTH = 200
877 SUBMENULIST_HEIGHT = 25
881 <screen name="Opera Browser" position="0,0" size="1280,720" backgroundColor="transparent" flags="wfNoBorder" title="Opera Browser">
882 <widget name="topArea" zPosition="-1" position="0,0" size="1280,60" font="Regular;20" valign="center" halign="center" backgroundColor="#000000" />
883 <widget name="menuitemFile" position="30,20" size="150,30" font="Regular;20" valign="center" halign="center" backgroundColor="#000000" foregroundColors="#9f1313,#a08500" />
884 <widget name="menuitemHelp" position="180,20" size="150,30" font="Regular;20" valign="center" halign="center" backgroundColor="#000000" foregroundColors="#9f1313,#a08500" />
885 <widget name="menulist" position="50,%d" size="%d,150" backgroundColor="#000000" zPosition="10" scrollbarMode="showOnDemand" />
886 <widget name="submenulist" position="%d,%d" size="%d,150" backgroundColor="#000000" zPosition="10" scrollbarMode="showOnDemand" />
887 <widget name="bottomArea" position="0,640" size="1280,80" font="Regular;20" valign="center" halign="center" backgroundColor="#000000" />
889 """ % (MENUBAR_ITEM_HEIGHT+30, SUBMENULIST_WIDTH, SUBMENULIST_WIDTH+50+SUBMENULIST_NEXT, MENUBAR_ITEM_HEIGHT+30, SUBMENULIST_WIDTH)
891 MENUITEMS_LIST =[[('Open Location', None), ('Start/Stop',None), ('Exit', None)],
893 def __init__(self, session):
894 Screen.__init__(self, session)
896 self["actions"] = ActionMap(["MinuteInputActions", "ColorActions", "InputActions", "InfobarChannelSelection", "EPGSelectActions", "KeyboardInputActions"], {
897 "cancel" : self.keyCancel
899 ,"left" : self.keyLeft
900 ,"right" : self.keyRight
902 ,"down" : self.keyDown
903 ,"menu" : self.keyCancel
906 self.menubarCurrentIndex = 0
907 self.lvMenuItems = []
908 self.lvSubMenuItems = []
910 self["topArea"] = Label()
911 self["bottomArea"] = Label()
913 self["menuitemFile"] = MultiColorLabel()
914 self["menuitemHelp"] = MultiColorLabel()
916 self["menulist"] = MenuList(self.setListOnView())
917 self["submenulist"] = MenuList(self.setSubListOnView())
919 self.toggleMainScreenFlag = True
920 self.toggleListViewFlag = False
921 self.toggleSubListViewFlag = False
922 self.currentListView = self["menulist"]
924 self.onLayoutFinish.append(self.layoutFinished)
926 self._onCloseTimer = eTimer()
927 self._onCloseTimer.callback.append(self._cb_onClose)
929 def enableRCMouse(self, mode): #mode=[0|1]|[False|True]
930 rcmouse_path = "/proc/stb/fp/mouse"
931 if os.path.exists(rcmouse_path):
932 os.system("echo %d > %s" % (mode, rcmouse_path))
934 def layoutFinished(self):
935 self["menuitemFile"].setText("File")
936 self["menuitemHelp"].setText("Help")
938 self["menulist"].hide()
939 self["submenulist"].hide()
941 self["bottomArea"].setText("Opera Web Browser Plugin v0.1")
942 self.setTitle("BrowserMain")
943 self.selectMenuitem()
945 def selectMenuitem(self):
946 tmp = [self["menuitemFile"], self["menuitemHelp"]]
947 self["menuitemFile"].setForegroundColorNum(0)
948 self["menuitemHelp"].setForegroundColorNum(0)
949 tmp[self.menubarCurrentIndex].setForegroundColorNum(1)
951 def popupCloseAll(self):
957 def setListOnView(self):
958 self.lvMenuItems = self.MENUITEMS_LIST[self.menubarCurrentIndex]
959 return self.lvMenuItems
961 def setSubListOnView(self):
962 self.lvSubMenuItems = []
963 xl = self["menulist"].getCurrent()[1]
964 if xl is None: return []
966 self.lvSubMenuItems.append((x,None))
967 return self.lvSubMenuItems
969 def toggleMainScreen(self):
970 if not self.toggleMainScreenFlag:
973 self.toggleMainScreenFlag = not self.toggleMainScreenFlag
975 def toggleListView(self):
976 if not self.toggleListViewFlag:
977 self["menulist"].show()
978 else: self["menulist"].hide()
979 self.toggleListViewFlag = not self.toggleListViewFlag
981 def toggleSubListView(self):
982 if not self.toggleSubListViewFlag:
983 self["submenulist"].show()
984 else: self["submenulist"].hide()
985 self.toggleSubListViewFlag = not self.toggleSubListViewFlag
987 def setCurrentListView(self, listViewIdx):
989 self.currentListView = None
990 elif listViewIdx == 1:
991 self.currentListView = self["menulist"]
992 elif listViewIdx == 2:
993 self.currentListView = self["submenulist"]
995 def _cb_onClose(self):
996 self._onCloseTimer.stop()
997 command_server = getCommandServer()
999 if self._on_close_window in command_server.onHbbTVCloseCB:
1000 command_server.onHbbTVCloseCB.remove(self._on_close_window)
1001 except Exception, ErrMsg: pass
1003 if self._on_setPageTitle in command_server.onSetPageTitleCB:
1004 command_server.onSetPageTitleCB.remove(self._on_setPageTitle)
1005 except Exception, ErrMsg: pass
1006 self._on_setPageTitle('Opera Browser')
1007 self.enableRCMouse(False)
1008 self.toggleMainScreen()
1009 eRCInput.getInstance().unlock()
1011 def _on_setPageTitle(self, title=None):
1012 print "page title :",title
1015 self.setTitle(title)
1017 def cbUrlText(self, data=None):
1018 print "Inputed Url :", data
1019 if strIsEmpty(data):
1021 command_server = getCommandServer()
1022 if self._on_setPageTitle not in command_server.onSetPageTitleCB:
1023 command_server.onSetPageTitleCB.append(self._on_setPageTitle)
1024 if self._on_close_window not in command_server.onHbbTVCloseCB:
1025 command_server.onHbbTVCloseCB.append(self._on_close_window)
1026 self.toggleMainScreen()
1027 self.enableRCMouse(True)
1028 eRCInput.getInstance().lock()
1029 command_util = getCommandUtil()
1030 command_util.sendCommand('OP_BROWSER_OPEN_URL', data)
1032 def _on_close_window(self):
1033 self._onCloseTimer.start(1000)
1035 def _cmd_on_OpenLocation(self):
1037 if not _g_helper._is_browser_running():
1038 message = "Opera Browser was not running.\nPlease running browser using [File]>[Start/Stop] menu."
1039 self.session.open(MessageBox, message, MessageBox.TYPE_INFO)
1041 self.session.openWithCallback(self.cbUrlText, VirtualKeyBoard, title=("Please enter URL here"), text='http://')
1042 def _cmd_on_About(self):
1043 self.session.open(MessageBox, 'Opera Web Browser Plugin v0.1(beta)', type = MessageBox.TYPE_INFO)
1044 def _cmd_on_Exit(self):
1046 def _cmd_on_StartStop(self):
1048 if _g_helper is None:
1050 _g_helper.showBrowserConfigBox()
1051 def doCommand(self, command):
1053 'Exit' :self._cmd_on_Exit
1054 ,'About' :self._cmd_on_About
1055 ,'Open Location' :self._cmd_on_OpenLocation
1056 ,'Start/Stop' :self._cmd_on_StartStop
1063 if not self.toggleListViewFlag:
1066 if self.currentListView.getCurrent()[1] is None:
1067 self.doCommand(self.currentListView.getCurrent()[0])
1068 #self.session.open(MessageBox, _(self.currentListView.getCurrent()[0]), type = MessageBox.TYPE_INFO)
1072 def updateSelectedMenuitem(self, status):
1073 if self.menubarCurrentIndex == 0 and status < 0:
1074 self.menubarCurrentIndex = 1
1075 elif self.menubarCurrentIndex == 1 and status > 0:
1076 self.menubarCurrentIndex = 0
1077 else: self.menubarCurrentIndex += status
1078 self.selectMenuitem()
1081 if not self.toggleMainScreenFlag:
1083 if not self.toggleListViewFlag:
1084 self.updateSelectedMenuitem(-1)
1086 if self.toggleSubListViewFlag:
1087 self.setCurrentListView(1)
1088 self.toggleSubListView()
1090 if self.currentListView.getSelectedIndex():
1091 self.currentListView.pageUp()
1094 if not self.toggleMainScreenFlag:
1096 if not self.toggleListViewFlag:
1097 self.updateSelectedMenuitem(1)
1099 if self.currentListView is None:
1101 if self.currentListView.getCurrent()[1] is not None:
1102 parentSelectedIndex = self.currentListView.getSelectedIndex()
1103 self.setCurrentListView(2)
1104 self.currentListView.setList(self.setSubListOnView())
1105 self.currentListView.resize(self.SUBMENULIST_WIDTH, self.SUBMENULIST_HEIGHT*len(self.lvSubMenuItems)+5)
1106 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))
1107 self.toggleSubListView()
1110 if not self.toggleMainScreenFlag:
1112 if self.currentListView is None:
1114 if not self.toggleListViewFlag:
1115 self.currentListView.setList(self.setListOnView())
1116 self.currentListView.resize(self.SUBMENULIST_WIDTH, self.SUBMENULIST_HEIGHT*len(self.lvMenuItems)+5)
1117 self.currentListView.move(self.MENUBAR_ITEM_WIDTH*self.menubarCurrentIndex+1+ 50,self.MENUBAR_ITEM_HEIGHT+30)
1118 self.toggleListView()
1120 self.currentListView.down()
1123 if not self.toggleMainScreenFlag:
1125 if self.currentListView is None:
1127 if self.currentListView == self["menulist"]:
1128 if self.currentListView.getSelectedIndex() == 0:
1129 self.toggleListView()
1131 self.currentListView.up()
1133 def keyCancel(self):
1134 self.toggleMainScreen()
1136 def auto_start_main(reason, **kwargs):
1138 command_server = getCommandServer()
1139 command_server.stop()
1141 def session_start_main(session, reason, **kwargs):
1143 _g_helper = session.open(HbbTVHelper)
1145 def plugin_start_main(session, **kwargs):
1146 session.open(OperaBrowser)
1148 def plugin_extension_start_application(session, **kwargs):
1150 if _g_helper is None:
1152 _g_helper.showApplicationSelectionBox()
1154 def plugin_extension_browser_config(session, **kwargs):
1156 if _g_helper is None:
1158 _g_helper.showBrowserConfigBox()
1160 def Plugins(path, **kwargs):
1162 PluginDescriptor(where=PluginDescriptor.WHERE_AUTOSTART, fnc=auto_start_main),
1163 PluginDescriptor(where=PluginDescriptor.WHERE_SESSIONSTART, needsRestart=True, fnc=session_start_main, weight=-10),
1164 PluginDescriptor(name="HbbTV Applications", where=PluginDescriptor.WHERE_EXTENSIONSMENU, needsRestart=True, fnc=plugin_extension_start_application),
1165 PluginDescriptor(name="Browser Start/Stop", where=PluginDescriptor.WHERE_EXTENSIONSMENU, needsRestart=True, fnc=plugin_extension_browser_config),
1166 PluginDescriptor(name="Opera Web Browser", description="start opera web browser", where=PluginDescriptor.WHERE_PLUGINMENU, needsRestart=True, fnc=plugin_start_main),