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)
50 __gval__ = GlobalValues()
52 def getPacketHeaders():
54 return (__gval__.packet_m, __gval__.packet_h, __gval__.packet_hl)
56 def setChannelInfo(sid, onid, tsid, name, orgid):
57 if sid is None: sid = 0;
58 if onid is None: onid = 0;
59 if tsid is None: tsid = 0;
60 if name is None: name = "";
61 if orgid is None: orgid = 0;
63 __gval__.channel_info_sid = sid
64 __gval__.channel_info_onid = onid
65 __gval__.channel_info_tsid = tsid
66 __gval__.channel_info_name = name
67 __gval__.channel_info_orgid = orgid
68 print "Set Channel Info >> sid : %X, onid : %X, tsid : %X, name : %s, orgid : %d " % (sid, onid, tsid, name, orgid)
69 def getChannelInfos():
71 print "Get Channel Info >> sid : %X, onid : %X, tsid : %X, name : %s, orgid : %d " % (__gval__.channel_info_sid,
72 __gval__.channel_info_onid, __gval__.channel_info_tsid, __gval__.channel_info_name, __gval__.channel_info_orgid)
73 return (__gval__.channel_info_sid,
74 __gval__.channel_info_onid,
75 __gval__.channel_info_tsid,
76 __gval__.channel_info_name,
77 __gval__.channel_info_orgid)
81 print "Need Restart(GET) : ", __gval__.need_restart
82 return __gval__.need_restart
83 def setNeedRestart(n):
85 __gval__.need_restart = n
86 print "Need Restart(SET) : ", __gval__.need_restart
90 return __gval__.command_util
91 def getCommandServer():
93 return __gval__.command_server
95 def setBeforeService(s):
97 __gval__.before_service = s
98 def getBeforeService():
100 return __gval__.before_service
102 def _unpack(packed_data):
103 (mg, h, hlen) = getPacketHeaders()
105 if strIsEmpty(packed_data):
107 (m, o, l, s) = struct.unpack(h, packed_data[:hlen])
112 d = packed_data[hlen:hlen+l]
115 def _pack(opcode, params=None, reserved=0):
116 (m, h, hlen) = getPacketHeaders()
117 if strIsEmpty(params):
119 packed_data = struct.pack(h, m, opcode, len(params), reserved)
120 return packed_data + params
126 ,'User-Agent: NSPlayer/7.10.0.3059 '
128 ,'Connection: Close '
133 for m in self.headers:
134 self.sendmsg += m + '\n'
135 self.sendmsg += '\n\n'
137 def request(self, host, port=80, location='/'):
138 sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
139 sock.connect((host, port))
140 sock.send(self.sendmsg%(location, host))
142 print self.sendmsg%(location, host)
145 res = sock.recv(1024)
151 def parse(self, data):
152 for d in data.splitlines():
153 if d.startswith('Location: '):
157 def getLocationData(self, url):
158 url_list,host,location = None,None,None
160 url = url[url.find(':')+3:]
161 url_list = url.split('/')
163 location = url[len(url_list[0]):]
164 except Exception, err_msg:
167 html = self.request(host=host, location=location)
168 return self.parse(html)
173 "OP_UNKNOWN" : 0x0000
174 ,"OP_HBBTV_EXIT" : 0x0001
175 ,"OP_HBBTV_OPEN_URL" : 0x0002
176 ,"OP_HBBTV_LOAD_AIT" : 0x0003
177 ,"OP_HBBTV_UNLOAD_AIT" : 0x0004
178 ,"OP_HBBTV_FULLSCREEN" : 0x0005
179 ,"OP_HBBTV_TITLE" : 0x0006
180 ,"OP_HBBTV_RETRY_OPEN_URL" : 0x0009
181 ,"OP_OIPF_GET_CHANNEL_INFO_URL" : 0x0101
182 ,"OP_OIPF_GET_CHANNEL_INFO_AIT" : 0x0102
183 ,"OP_OIPF_GET_CHANNEL_INFO_LIST": 0x0103
184 ,"OP_VOD_URI" : 0x0201
185 ,"OP_VOD_PLAY" : 0x0202
186 ,"OP_VOD_STOP" : 0x0203
187 ,"OP_VOD_PAUSE" : 0x0204
188 ,"OP_VOD_STATUS" : 0x0205
189 ,"OP_VOD_FORBIDDEN" : 0x0206
190 ,"OP_VOD_STOPED" : 0x0207
191 ,"OP_BROWSER_OPEN_URL" : 0x0301
192 ,"OP_DVBAPP_VOL_UP" : 0x0401
193 ,"OP_DVBAPP_VOL_DOWN" : 0x0402
194 ,"OP_SYSTEM_OUT_OF_MEMORY" : 0x0501
195 ,"OP_SYSTEM_NOTIFY_MY_PID" : 0x0502
198 0x0000 : "OP_UNKNOWN"
199 ,0x0001 : "OP_HBBTV_EXIT"
200 ,0x0002 : "OP_HBBTV_OPEN_URL"
201 ,0x0003 : "OP_HBBTV_LOAD_AIT"
202 ,0x0004 : "OP_HBBTV_UNLOAD_AIT"
203 ,0x0005 : "OP_HBBTV_FULLSCREEN"
204 ,0x0006 : "OP_HBBTV_TITLE"
205 ,0x0009 : "OP_HBBTV_RETRY_OPEN_URL"
206 ,0x0101 : "OP_OIPF_GET_CHANNEL_INFO_URL"
207 ,0x0102 : "OP_OIPF_GET_CHANNEL_INFO_AIT"
208 ,0x0103 : "OP_OIPF_GET_CHANNEL_INFO_LIST"
209 ,0x0201 : "OP_VOD_URI"
210 ,0x0202 : "OP_VOD_PLAY"
211 ,0x0203 : "OP_VOD_STOP"
212 ,0x0204 : "OP_VOD_PAUSE"
213 ,0x0205 : "OP_VOD_STATUS"
214 ,0x0206 : "OP_VOD_FORBIDDEN"
215 ,0x0207 : "OP_VOD_STOPED"
216 ,0x0301 : "OP_BROWSER_OPEN_URL"
217 ,0x0401 : "OP_DVBAPP_VOL_UP"
218 ,0x0402 : "OP_DVBAPP_VOL_DOWN"
219 ,0x0501 : "OP_SYSTEM_OUT_OF_MEMORY"
220 ,0x0502 : "OP_SYSTEM_NOTIFY_MY_PID"
223 def get(self, opstr):
225 return self._opcode_[opstr]
227 return self._opcode_["OP_UNKNOWN"]
229 def what(self, opcode):
231 return self._opstr_[opcode]
233 return self._opstr_["0x0000"]
246 def __init__(self, params):
247 self._protocol = params.protocol
248 self._type = params.type
249 self._addr = params.addr
250 self._buf_size = params.buf_size
251 self._handler = params.handler
252 self._timeout = params.timeout
253 self._destroy = params.destroy
255 self._terminated = False
256 self._server_thread = None
258 self.onHbbTVCloseCB = []
259 self.onSetPageTitleCB = []
262 if self._destroy is not None:
263 self._destroy(self._addr)
266 self._terminated = True
267 if self._server_thread is not None:
268 self._server_thread.join()
269 self._server_thread = None
272 self._socket = socket.socket(self._protocol, self._type)
273 self._socket.settimeout(self._timeout)
274 self._socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
275 self._socket.bind(self._addr)
276 self._socket.listen(True)
278 self._server_thread = threading.Thread(target=self._listen)
279 self._server_thread.start()
282 select_list = [self._socket]
285 conn, addr = self._socket.accept()
286 self._client(conn, addr)
287 except Exception, ErrMsg:
288 print "ServerSocket Error >>", ErrMsg
291 while not self._terminated:
292 readable, writable, errored = select.select(select_list, [], [], self._timeout)
294 if s is self._socket:
297 def _client(self, conn, addr):
300 received_data = conn.recv(self._buf_size)
301 if self._handler is not None and not strIsEmpty(received_data):
302 send_data = self._handler.doHandle(received_data, self.onHbbTVCloseCB, self.onSetPageTitleCB)
303 self._send(conn, send_data)
304 except Exception, ErrMsg:
307 if self._handler is not None:
308 self._handler.printError(ErrMsg)
309 def _send(self, conn, data) :
314 def doListenUnixTCP(self, name, handler):
316 if os.path.exists(name):
318 print "Removed ", name
321 params = SocketParams()
322 params.protocol = socket.AF_UNIX
323 params.type = socket.SOCK_STREAM
325 params.handler = handler
326 params.destroy = destroy
328 streamServer = StreamServer(params)
332 def doListenInetTCP(self, ip, port, handler):
333 print "Not implemented yet!!"
334 def doListenUnixDGRAM(self, name, handler):
335 print "Not implemented yet!!"
336 def doListenInetDGRAM(self, ip, port, handler):
337 print "Not implemented yet!!"
340 def doUnpack(self, data):
343 def doPack(self, opcode, params, reserved=0):
344 return _pack(opcode, params, reserved)
346 def doHandle(self, data, onCloseCB):
347 opcode, params = 0x0, 'Invalid Request!!'
348 return _pack(opcode, params)
350 def printError(self, reason):
353 class BrowserCommandUtil(OpCodeSet):
356 OpCodeSet.__init__(self)
358 def isConnected(self):
363 def doConnect(self, filename):
364 if not os.path.exists(filename):
365 print "File not exists :", filename
368 self._fd = os.open(filename, os.O_WRONLY|os.O_NONBLOCK)
370 print "Fail to open file :", filename
372 except Exception, ErrMsg:
378 def doDisconnect(self):
384 def doSend(self, command, params=None, reserved=0):
386 print "Pipe was not exists!!"
390 data = _pack(self.get(command), params, reserved)
393 os.write(self._fd, data)
394 print "Send OK!! :", command
398 def sendCommand(self, command, params=None, reserved=0):
399 if not self.isConnected():
401 self.doConnect(COMMAND_PATH)
402 result = self.doSend(command, params, reserved)
406 class HandlerHbbTV(Handler):
408 def __init__(self, session):
409 self._session = session
410 self.opcode = OpCodeSet()
412 0x0001 : self._cb_handleCloseHbbTVBrowser
413 ,0x0006 : self._cb_handleSetPageTitle
414 ,0x0009 : self._cb_handleHbbTVRetryOpen
415 ,0x0101 : self._cb_handleGetChannelInfoForUrl
416 ,0x0102 : self._cb_handleGetChannelInfoForAIT
417 ,0x0103 : self._cb_handleGetChannelInfoList
418 ,0x0201 : self._cb_handleVODPlayerURI
419 ,0x0202 : self._cb_handleVODPlayerPlay
420 ,0x0203 : self._cb_handleVODPlayerStop
421 ,0x0204 : self._cb_handleVODPlayerPlayPause
422 ,0x0401 : self._cb_handleDVBAppVolUp
423 ,0x0402 : self._cb_handleDVBAppVolDown
424 ,0x0501 : self._cb_handleSystemOutOfMemory
425 ,0x0502 : self._cb_handleSystemNotufyMyPID
427 self._on_close_cb = None
428 self._on_set_title_cb = None
432 self._retry_open_url = None
433 self._timer_retry_open = eTimer()
436 def _handle_dump(self, handle, opcode, data=None):
440 print " - opcode : ", self.opcode.what(opcode)
442 print " - data : ", data
444 def doHandle(self, data, onCloseCB, onSetPageTitleCB):
445 opcode, params, reserved = None, None, 0
446 self._on_close_cb = onCloseCB
447 self._on_set_title_cb = onSetPageTitleCB
449 datas = self.doUnpack(data)
450 except Exception, ErrMsg:
451 print "Unpacking packet ERR :", ErrMsg
452 params = 'fail to unpack packet!!'
453 opcode = self.opcode.get("OP_UNKNOWN")
454 return self.doPack(opcode, params)
458 self.opcode.what(opcode)
461 #print self.handle_map[opcode]
462 (reserved, params) = self.handle_map[opcode](opcode, params)
463 except Exception, ErrMsg:
464 print "Handling packet ERR :", ErrMsg
465 params = 'fail to handle packet!!'
466 opcode = self.opcode.get("OP_UNKNOWN")
467 return self.doPack(opcode, params)
468 self._on_close_cb = None
469 self._on_set_title_cb = None
470 return self.doPack(opcode, params, reserved)
472 def _cb_handleHbbTVRetryOpen(self, opcode, data):
473 def _cb_HbbTVRetryOpenURL():
474 self._timer_retry_open.stop()
475 if self._retry_open_url is not None:
476 command_util = getCommandUtil()
477 command_util.sendCommand('OP_HBBTV_RETRY_OPEN_URL', params=self._retry_open_url)
478 self._retry_open_url = None
479 self._handle_dump(self._cb_handleHbbTVRetryOpen, opcode, data)
480 headLen = struct.calcsize('!I')
481 unpackedData = struct.unpack('!I', data[:headLen])
482 delayTime = unpackedData[0]
483 restartUrl = data[headLen:]
485 self._retry_open_url = restartUrl.strip()
486 self._timer_retry_open.callback.append(_cb_HbbTVRetryOpenURL)
487 self._timer_retry_open.start(delayTime*1000)
490 def _cb_handleSystemNotufyMyPID(self, opcode, data):
491 self._handle_dump(self._cb_handleSystemNotufyMyPID, opcode, data)
494 def _cb_handleSystemOutOfMemory(self, opcode, data):
495 self._handle_dump(self._cb_handleSystemOutOfMemory, opcode, data)
499 def _cb_handleDVBAppVolUp(self, opcode, data):
500 self._handle_dump(self._cb_handleDVBAppVolUp, opcode, data)
501 vcm = VolumeControl.instance
505 def _cb_handleDVBAppVolDown(self, opcode, data):
506 self._handle_dump(self._cb_handleDVBAppVolDown, opcode, data)
507 vcm = VolumeControl.instance
511 def _cb_handleGetChannelInfoForUrl(self, opcode, data):
512 self._handle_dump(self._cb_handleGetChannelInfoForUrl, opcode, data)
513 (sid, onid, tsid, name, orgid) = getChannelInfos()
515 return (0, struct.pack('!IIII', sid, onid, tsid, namelen) + name)
517 def _cb_handleGetChannelInfoForAIT(self, opcode, data):
518 self._handle_dump(self._cb_handleGetChannelInfoForAIT, opcode, data)
519 (sid, onid, tsid, name, orgid) = getChannelInfos()
521 return (0, struct.pack('!IIIII', orgid, sid, onid, tsid, namelen) + name)
523 def _cb_handleGetChannelInfoList(self, opcode, data):
524 self._handle_dump(self._cb_handleGetChannelInfoList, opcode, data)
525 (sid, onid, tsid, name, orgid) = getChannelInfos()
527 channel_list_size = 1
528 return (channel_list_size, struct.pack('!IIII', sid, onid, tsid, namelen) + name)
530 def _cb_handleSetPageTitle(self, opcode, data):
531 self._handle_dump(self._cb_handleCloseHbbTVBrowser, opcode, data)
532 if data.startswith('file://') or data.startswith('http://'):
534 if self._on_set_title_cb is not None:
535 for x in self._on_set_title_cb:
538 except Exception, ErrMsg:
539 if x in self._on_set_title_cb:
540 self._on_set_title_cb.remove(x)
543 def _cb_handleCloseHbbTVBrowser(self, opcode, data):
544 self._timer_retry_open.stop()
545 self._handle_dump(self._cb_handleCloseHbbTVBrowser, opcode, data)
547 if self._on_close_cb:
548 for x in self._on_close_cb:
551 except Exception, ErrMsg:
552 if x in self._on_close_cb:
553 self._on_close_cb.remove(x)
555 command_util = getCommandUtil()
556 command_util.sendCommand('OP_HBBTV_FULLSCREEN', None)
558 before_service = getBeforeService()
559 if before_service is not None:
560 self._session.nav.playService(before_service)
564 def _cb_handleVODPlayerURI(self, opcode, data):
566 hl = struct.calcsize('!II')
567 datas = struct.unpack('!II', data[:hl])
569 vodUri = data[hl:hl+uriLength]
570 self._handle_dump(self._cb_handleVODPlayerURI, opcode, vodUri)
571 self._vod_uri = vodUri
574 def doStop(self, restoreBeforeService=True, needStop=True):
576 self._session.nav.stopService()
577 if self._vod_service is not None and restoreBeforeService:
578 before_service = getBeforeService()
579 self._session.nav.playService(before_service)
581 self._vod_service = None
586 def doRetryOpen(self, url):
590 self._vod_service = None
592 print "Try to open vod [%d] : %s" % (ii, url)
593 self._vod_service = eServiceReference(4097, 0, url)
594 self._session.nav.playService(self._vod_service)
595 if self._vod_service is not None:
597 except Exception, ErrMsg:
598 print "OpenVOD ERR :", ErrMsg
602 def _cb_handleVODPlayerPlay(self, opcode, data):
603 self._handle_dump(self._cb_handleVODPlayerPlay, opcode, data)
604 self.doStop(restoreBeforeService=False)
605 if self.doRetryOpen(url=self._vod_uri) == False:
609 def _cb_handleVODPlayerStop(self, opcode, data):
610 self._handle_dump(self._cb_handleVODPlayerStop, opcode, data)
614 def _cb_handleVODPlayerPlayPause(self, opcode, data):
615 self._handle_dump(self._cb_handleVODPlayerPlayPause, opcode, data)
616 service = self._session.nav.getCurrentService()
619 servicePause = service.pause()
621 servicePause.unpause()
622 elif pauseFlag == 'P':
624 except Exception, ErrMsg:
625 print "onPause ERR :", ErrMsg
628 from libshm import SimpleSharedMemory
630 class HbbTVWindow(Screen, InfoBarNotifications):
632 <screen name="HbbTVWindow" position="0,0" size="1280,720" backgroundColor="transparent" flags="wfNoBorder" title="HbbTV Plugin">
635 def __init__(self, session, url=None, cbf=None, useAIT=False, profile=0):
636 self._session = session
637 eRCInput.getInstance().lock()
639 Screen.__init__(self, session)
640 InfoBarNotifications.__init__(self)
641 self.__event_tracker = ServiceEventTracker(screen = self, eventmap = {
642 iPlayableService.evUser+20: self._serviceForbiden,
643 iPlayableService.evStart: self._serviceStarted,
644 iPlayableService.evEOF: self._serviceEOF,
648 self._use_ait = useAIT
649 self._profile = profile
650 self._cb_closed_func = cbf
651 self.onLayoutFinish.append(self._layoutFinished)
653 command_server = getCommandServer()
654 if self._cb_set_page_title not in command_server.onSetPageTitleCB:
655 command_server.onSetPageTitleCB.append(self._cb_set_page_title)
657 if self._cb_close_window not in command_server.onHbbTVCloseCB:
658 command_server.onHbbTVCloseCB.append(self._cb_close_window)
660 self._closeTimer = eTimer()
661 self._closeTimer.callback.append(self._do_close)
663 self._currentServicePositionTimer = eTimer()
664 self._currentServicePositionTimer.callback.append(self._cb_currentServicePosition)
671 def getVodPlayTime(self):
673 service = self._session.nav.getCurrentService()
674 seek = service and service.seek()
676 p = seek.getPlayPosition()
677 #return (p[1]/90000, l[1]/90000)
682 def _cb_currentServicePosition(self):
683 def getTimeString(t):
684 t = time.localtime(t/90000)
685 return "%2d:%02d:%02d" % (t.tm_hour, t.tm_min, t.tm_sec)
686 position,length = 0,0
688 (position,length) = self.getVodPlayTime()
689 self._vod_length = length
690 if position == -1 and length == -1:
691 raise Exception("Can't get play status")
692 #print getTimeString(position), "/", getTimeString(length)
693 self._ssm.setStatus(position, length, 1)
694 except Exception, ErrMsg:
698 def _serviceStarted(self):
700 self._ssm.setStatus(0, 0, 0)
701 self._currentServicePositionTimer.start(1000)
702 except Exception, ErrMsg:
705 def _serviceEOF(self):
706 self._currentServicePositionTimer.stop()
708 def _layoutFinished(self):
709 command_util = getCommandUtil()
710 profile = self._profile
711 (sid, onid, tsid, name, orgid) = getChannelInfos()
712 params = struct.pack('!IIIIII', orgid, profile, sid, onid, tsid, len(name)) + name
714 command_util.sendCommand('OP_HBBTV_UNLOAD_AIT')
716 command_util.sendCommand('OP_HBBTV_LOAD_AIT', params, 1)
718 command_util.sendCommand('OP_HBBTV_LOAD_AIT', params)
720 command_util.sendCommand('OP_HBBTV_OPEN_URL', self._url)
722 def _cb_close_window(self):
723 self._closeTimer.start(1000)
726 self._closeTimer.stop()
727 command_server = getCommandServer()
729 if self._cb_set_page_title in command_server.onSetPageTitleCB:
730 command_server.onSetPageTitleCB.remove(self._cb_set_page_title)
731 except Exception, ErrMsg: pass
733 if self._cb_close_window in command_server.onHbbTVCloseCB:
734 command_server.onHbbTVCloseCB.remove(self._cb_close_window)
735 except Exception, ErrMsg: pass
737 if self._cb_closed_func is not None:
738 self._cb_closed_func()
740 eRCInput.getInstance().unlock()
743 def _serviceForbiden(self):
745 real_url = MMSStreamURL().getLocationData(__gval__.hbbtv_handelr.getUrl())
746 print "Received URI :\n", real_url
748 if real_url is not None:
749 __gval__.hbbtv_handelr.doRetryOpen(real_url.strip())
751 def _cb_set_page_title(self, title=None):
752 print "page title :",title
757 class HbbTVHelper(Screen):
758 skin = """<screen name="HbbTVHelper" position="0,0" size="0,0" backgroundColor="transparent" flags="wfNoBorder" title=" "></screen>"""
759 def __init__(self, session):
761 __gval__.hbbtv_handelr = HandlerHbbTV(session)
762 __gval__.command_server = ServerFactory().doListenUnixTCP('/tmp/.sock.hbbtv.url', __gval__.hbbtv_handelr)
767 self._restart_opera()
769 Screen.__init__(self, session)
770 self._session = session
771 self._timer_infobar = eTimer()
772 self._timer_infobar.callback.append(self._cb_registrate_infobar)
773 self._timer_infobar.start(1000)
775 self._excuted_browser = False
778 __gval__.command_util = BrowserCommandUtil()
782 _g_ssm_ = SimpleSharedMemory()
785 def _cb_registrate_infobar(self):
787 self._timer_infobar.stop()
788 if self._cb_ready_for_ait not in InfoBar.instance.onReadyForAIT:
789 InfoBar.instance.onReadyForAIT.append(self._cb_ready_for_ait)
790 if self._cb_hbbtv_activated not in InfoBar.instance.onHBBTVActivation:
791 InfoBar.instance.onHBBTVActivation.append(self._cb_hbbtv_activated)
793 def _cb_ready_for_ait(self, orgId=0):
795 if not self._excuted_browser:
796 command_util = getCommandUtil()
797 command_util.sendCommand('OP_HBBTV_UNLOAD_AIT')
799 setChannelInfo(None, None, None, None, None)
801 service = self._session.nav.getCurrentService()
802 info = service and service.info()
804 sid = info.getInfo(iServiceInformation.sSID)
805 onid = info.getInfo(iServiceInformation.sONID)
806 tsid = info.getInfo(iServiceInformation.sTSID)
807 name = info.getName()
812 for x in info.getInfoObject(iServiceInformation.sHBBTVUrl):
816 setChannelInfo(sid, onid, tsid, name, orgid)
818 def _cb_hbbtv_activated(self, title=None, url=None):
819 if not self._is_browser_running():
820 message = "HbbTV Browser was not running.\nPlease running browser before start HbbTV Application."
821 self.session.open(MessageBox, message, MessageBox.TYPE_INFO)
823 service = self._session.nav.getCurrentlyPlayingServiceReference()
824 setBeforeService(service)
825 self._start_hbbtv_application(title, url)
827 def _start_hbbtv_application(self, title, url):
829 tmp_url = self.getStartHbbTVUrl()
833 print "can't get url of hbbtv!!"
835 print "success to get url of hbbtv!! >>", url
836 if self._excuted_browser:
837 print "already excuted opera browser!!"
841 self._restart_opera()
843 setNeedRestart(False)
848 if tmp_url == url and control_code == 1:
850 self._excuted_browser = True
851 self._session.open(HbbTVWindow, url, self._cb_closed_browser, use_ait, self._profile)
853 def _cb_closed_browser(self):
854 self._excuted_browser = False
856 def _start_opera(self):
857 if not self._is_browser_running():
859 start_command = '%s/launcher start'%(HBBTVAPP_PATH)
860 os.system(start_command)
862 def _stop_opera(self):
864 try: os.system('%s/launcher stop'%(HBBTVAPP_PATH))
867 def _restart_opera(self):
869 try: os.system('%s/launcher restart'%(HBBTVAPP_PATH))
872 def getStartHbbTVUrl(self):
873 url, self._urls, self._profile = None, None, 0
874 service = self._session.nav.getCurrentService()
875 info = service and service.info()
876 if not info: return None
877 self._urls = info.getInfoObject(iServiceInformation.sHBBTVUrl)
879 if u[0] in (1, -1): # 0:control code, 1:name, 2:url, 3:orgid, 4:appid, 5:profile code
883 url = info.getInfoString(iServiceInformation.sHBBTVUrl)
886 def showApplicationSelectionBox(self):
889 if self.getStartHbbTVUrl():
891 applications.append((x[1], x))
892 else: applications.append(("No detected HbbTV applications.", None))
893 self._session.openWithCallback(self._application_selected, ChoiceBox, title=_("Please choose an HbbTV application."), list=applications)
895 def _application_selected(self, selected):
897 if selected[1] is None: return
898 self._cb_hbbtv_activated(selected[1][1], selected[1][2])
899 except Exception, ErrMsg: print ErrMsg
901 def showBrowserConfigBox(self):
903 if self._is_browser_running():
904 start_stop_mode.append(('Stop',None))
905 else: start_stop_mode.append(('Start',None))
906 self._session.openWithCallback(self._browser_config_selected, ChoiceBox, title=_("Please choose one."), list=start_stop_mode)
908 def _browser_config_selected(self, selected):
914 if not self._is_browser_running():
918 except Exception, ErrMsg: print "Config ERR :", ErrMsg
920 def _is_browser_running(self):
923 ret = os.popen('%s/launcher check'%(HBBTVAPP_PATH)).read()
924 return ret.strip() != "0"
925 except Exception, ErrMsg:
926 print "Check Browser Running ERR :", ErrMsg
930 class OperaBrowser(Screen):
931 MENUBAR_ITEM_WIDTH = 150
932 MENUBAR_ITEM_HEIGHT = 30
933 SUBMENULIST_WIDTH = 200
934 SUBMENULIST_HEIGHT = 25
938 <screen name="Opera Browser" position="0,0" size="1280,720" backgroundColor="transparent" flags="wfNoBorder" title="Opera Browser">
939 <widget name="topArea" zPosition="-1" position="0,0" size="1280,60" font="Regular;20" valign="center" halign="center" backgroundColor="#000000" />
940 <widget name="menuitemFile" position="30,20" size="150,30" font="Regular;20" valign="center" halign="center" backgroundColor="#000000" foregroundColors="#9f1313,#a08500" />
941 <widget name="menuitemHelp" position="180,20" size="150,30" font="Regular;20" valign="center" halign="center" backgroundColor="#000000" foregroundColors="#9f1313,#a08500" />
942 <widget name="menulist" position="50,%d" size="%d,150" backgroundColor="#000000" zPosition="10" scrollbarMode="showOnDemand" />
943 <widget name="submenulist" position="%d,%d" size="%d,150" backgroundColor="#000000" zPosition="10" scrollbarMode="showOnDemand" />
944 <widget name="bottomArea" position="0,640" size="1280,80" font="Regular;20" valign="center" halign="center" backgroundColor="#000000" />
946 """ % (MENUBAR_ITEM_HEIGHT+30, SUBMENULIST_WIDTH, SUBMENULIST_WIDTH+50+SUBMENULIST_NEXT, MENUBAR_ITEM_HEIGHT+30, SUBMENULIST_WIDTH)
948 MENUITEMS_LIST =[[('Open Location', None), ('Start/Stop',None), ('Exit', None)],
950 def __init__(self, session):
951 Screen.__init__(self, session)
953 self["actions"] = ActionMap(["MinuteInputActions", "ColorActions", "InputActions", "InfobarChannelSelection", "EPGSelectActions", "KeyboardInputActions"], {
954 "cancel" : self.keyCancel
956 ,"left" : self.keyLeft
957 ,"right" : self.keyRight
959 ,"down" : self.keyDown
960 ,"menu" : self.keyCancel
963 self.menubarCurrentIndex = 0
964 self.lvMenuItems = []
965 self.lvSubMenuItems = []
967 self["topArea"] = Label()
968 self["bottomArea"] = Label()
970 self["menuitemFile"] = MultiColorLabel()
971 self["menuitemHelp"] = MultiColorLabel()
973 self["menulist"] = MenuList(self.setListOnView())
974 self["submenulist"] = MenuList(self.setSubListOnView())
976 self.toggleMainScreenFlag = True
977 self.toggleListViewFlag = False
978 self.toggleSubListViewFlag = False
979 self.currentListView = self["menulist"]
981 self.onLayoutFinish.append(self.layoutFinished)
983 self._onCloseTimer = eTimer()
984 self._onCloseTimer.callback.append(self._cb_onClose)
986 def enableRCMouse(self, mode): #mode=[0|1]|[False|True]
987 rcmouse_path = "/proc/stb/fp/mouse"
988 if os.path.exists(rcmouse_path):
989 os.system("echo %d > %s" % (mode, rcmouse_path))
991 def layoutFinished(self):
992 self["menuitemFile"].setText("File")
993 self["menuitemHelp"].setText("Help")
995 self["menulist"].hide()
996 self["submenulist"].hide()
998 self["bottomArea"].setText("Opera Web Browser Plugin v0.1")
999 self.setTitle("BrowserMain")
1000 self.selectMenuitem()
1002 def selectMenuitem(self):
1003 tmp = [self["menuitemFile"], self["menuitemHelp"]]
1004 self["menuitemFile"].setForegroundColorNum(0)
1005 self["menuitemHelp"].setForegroundColorNum(0)
1006 tmp[self.menubarCurrentIndex].setForegroundColorNum(1)
1008 def popupCloseAll(self):
1014 def setListOnView(self):
1015 self.lvMenuItems = self.MENUITEMS_LIST[self.menubarCurrentIndex]
1016 return self.lvMenuItems
1018 def setSubListOnView(self):
1019 self.lvSubMenuItems = []
1020 xl = self["menulist"].getCurrent()[1]
1021 if xl is None: return []
1023 self.lvSubMenuItems.append((x,None))
1024 return self.lvSubMenuItems
1026 def toggleMainScreen(self):
1027 if not self.toggleMainScreenFlag:
1030 self.toggleMainScreenFlag = not self.toggleMainScreenFlag
1032 def toggleListView(self):
1033 if not self.toggleListViewFlag:
1034 self["menulist"].show()
1035 else: self["menulist"].hide()
1036 self.toggleListViewFlag = not self.toggleListViewFlag
1038 def toggleSubListView(self):
1039 if not self.toggleSubListViewFlag:
1040 self["submenulist"].show()
1041 else: self["submenulist"].hide()
1042 self.toggleSubListViewFlag = not self.toggleSubListViewFlag
1044 def setCurrentListView(self, listViewIdx):
1045 if listViewIdx == 0:
1046 self.currentListView = None
1047 elif listViewIdx == 1:
1048 self.currentListView = self["menulist"]
1049 elif listViewIdx == 2:
1050 self.currentListView = self["submenulist"]
1052 def _cb_onClose(self):
1053 self._onCloseTimer.stop()
1054 command_server = getCommandServer()
1056 if self._on_close_window in command_server.onHbbTVCloseCB:
1057 command_server.onHbbTVCloseCB.remove(self._on_close_window)
1058 except Exception, ErrMsg: pass
1060 if self._on_setPageTitle in command_server.onSetPageTitleCB:
1061 command_server.onSetPageTitleCB.remove(self._on_setPageTitle)
1062 except Exception, ErrMsg: pass
1063 self._on_setPageTitle('Opera Browser')
1064 self.enableRCMouse(False)
1065 self.toggleMainScreen()
1066 eRCInput.getInstance().unlock()
1068 def _on_setPageTitle(self, title=None):
1069 print "Title :",title
1072 self.setTitle(title)
1074 def cbUrlText(self, data=None):
1075 print "Inputed Url :", data
1076 if strIsEmpty(data):
1078 command_server = getCommandServer()
1079 if self._on_setPageTitle not in command_server.onSetPageTitleCB:
1080 command_server.onSetPageTitleCB.append(self._on_setPageTitle)
1081 if self._on_close_window not in command_server.onHbbTVCloseCB:
1082 command_server.onHbbTVCloseCB.append(self._on_close_window)
1083 self.toggleMainScreen()
1084 self.enableRCMouse(True)
1085 eRCInput.getInstance().lock()
1086 command_util = getCommandUtil()
1087 command_util.sendCommand('OP_BROWSER_OPEN_URL', data)
1089 def _on_close_window(self):
1090 self._onCloseTimer.start(1000)
1092 def _cmd_on_OpenLocation(self):
1094 if not _g_helper._is_browser_running():
1095 message = "Opera Browser was not running.\nPlease running browser using [File]>[Start/Stop] menu."
1096 self.session.open(MessageBox, message, MessageBox.TYPE_INFO)
1098 self.session.openWithCallback(self.cbUrlText, VirtualKeyBoard, title=("Please enter URL here"), text='http://')
1099 def _cmd_on_About(self):
1100 self.session.open(MessageBox, 'Opera Web Browser Plugin v0.1(beta)', type = MessageBox.TYPE_INFO)
1101 def _cmd_on_Exit(self):
1103 def _cmd_on_StartStop(self):
1105 if _g_helper is None:
1107 _g_helper.showBrowserConfigBox()
1108 def doCommand(self, command):
1110 'Exit' :self._cmd_on_Exit
1111 ,'About' :self._cmd_on_About
1112 ,'Open Location' :self._cmd_on_OpenLocation
1113 ,'Start/Stop' :self._cmd_on_StartStop
1120 if not self.toggleListViewFlag:
1123 if self.currentListView.getCurrent()[1] is None:
1124 self.doCommand(self.currentListView.getCurrent()[0])
1125 #self.session.open(MessageBox, _(self.currentListView.getCurrent()[0]), type = MessageBox.TYPE_INFO)
1129 def updateSelectedMenuitem(self, status):
1130 if self.menubarCurrentIndex == 0 and status < 0:
1131 self.menubarCurrentIndex = 1
1132 elif self.menubarCurrentIndex == 1 and status > 0:
1133 self.menubarCurrentIndex = 0
1134 else: self.menubarCurrentIndex += status
1135 self.selectMenuitem()
1138 if not self.toggleMainScreenFlag:
1140 if not self.toggleListViewFlag:
1141 self.updateSelectedMenuitem(-1)
1143 if self.toggleSubListViewFlag:
1144 self.setCurrentListView(1)
1145 self.toggleSubListView()
1147 if self.currentListView.getSelectedIndex():
1148 self.currentListView.pageUp()
1151 if not self.toggleMainScreenFlag:
1153 if not self.toggleListViewFlag:
1154 self.updateSelectedMenuitem(1)
1156 if self.currentListView is None:
1158 if self.currentListView.getCurrent()[1] is not None:
1159 parentSelectedIndex = self.currentListView.getSelectedIndex()
1160 self.setCurrentListView(2)
1161 self.currentListView.setList(self.setSubListOnView())
1162 self.currentListView.resize(self.SUBMENULIST_WIDTH, self.SUBMENULIST_HEIGHT*len(self.lvSubMenuItems)+5)
1163 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))
1164 self.toggleSubListView()
1167 if not self.toggleMainScreenFlag:
1169 if self.currentListView is None:
1171 if not self.toggleListViewFlag:
1172 self.currentListView.setList(self.setListOnView())
1173 self.currentListView.resize(self.SUBMENULIST_WIDTH, self.SUBMENULIST_HEIGHT*len(self.lvMenuItems)+5)
1174 self.currentListView.move(self.MENUBAR_ITEM_WIDTH*self.menubarCurrentIndex+1+ 50,self.MENUBAR_ITEM_HEIGHT+30)
1175 self.toggleListView()
1177 self.currentListView.down()
1180 if not self.toggleMainScreenFlag:
1182 if self.currentListView is None:
1184 if self.currentListView == self["menulist"]:
1185 if self.currentListView.getSelectedIndex() == 0:
1186 self.toggleListView()
1188 self.currentListView.up()
1190 def keyCancel(self):
1191 self.toggleMainScreen()
1193 def auto_start_main(reason, **kwargs):
1195 command_server = getCommandServer()
1196 command_server.stop()
1198 def session_start_main(session, reason, **kwargs):
1199 eRCInput.getInstance().unlock()
1201 _g_helper = session.open(HbbTVHelper)
1203 def plugin_start_main(session, **kwargs):
1204 session.open(OperaBrowser)
1206 def plugin_extension_start_application(session, **kwargs):
1208 if _g_helper is None:
1210 _g_helper.showApplicationSelectionBox()
1212 def plugin_extension_browser_config(session, **kwargs):
1214 if _g_helper is None:
1216 _g_helper.showBrowserConfigBox()
1218 def Plugins(path, **kwargs):
1220 PluginDescriptor(where=PluginDescriptor.WHERE_AUTOSTART, fnc=auto_start_main),
1221 PluginDescriptor(where=PluginDescriptor.WHERE_SESSIONSTART, needsRestart=True, fnc=session_start_main, weight=-10),
1222 PluginDescriptor(name="HbbTV Applications", where=PluginDescriptor.WHERE_EXTENSIONSMENU, needsRestart=True, fnc=plugin_extension_start_application),
1223 PluginDescriptor(name="Browser Start/Stop", where=PluginDescriptor.WHERE_EXTENSIONSMENU, needsRestart=True, fnc=plugin_extension_browser_config),
1224 PluginDescriptor(name="Opera Web Browser", description="start opera web browser", where=PluginDescriptor.WHERE_PLUGINMENU, needsRestart=True, fnc=plugin_start_main),