2016-10-23 02:15:10 +11:00
|
|
|
# -*- coding: utf-8 -*-
|
2017-07-03 02:23:58 +10:00
|
|
|
###############################################################################
|
|
|
|
from logging import getLogger
|
2017-07-17 00:57:57 +10:00
|
|
|
from os.path import join
|
2016-10-23 02:15:10 +11:00
|
|
|
|
|
|
|
import xbmcgui
|
|
|
|
|
|
|
|
import connect.connectionmanager as connectionmanager
|
2017-07-17 00:57:57 +10:00
|
|
|
from utils import language as lang, tryEncode
|
|
|
|
import variables as v
|
2016-10-23 02:15:10 +11:00
|
|
|
|
2017-07-03 02:23:58 +10:00
|
|
|
###############################################################################
|
2016-10-23 02:15:10 +11:00
|
|
|
|
2017-07-03 02:23:58 +10:00
|
|
|
log = getLogger("PLEX."+__name__)
|
2016-10-23 02:15:10 +11:00
|
|
|
|
2017-07-03 02:23:58 +10:00
|
|
|
CONN_STATE = connectionmanager.CONNECTIONSTATE
|
2016-10-23 02:15:10 +11:00
|
|
|
ACTION_PARENT_DIR = 9
|
|
|
|
ACTION_PREVIOUS_MENU = 10
|
|
|
|
ACTION_BACK = 92
|
|
|
|
CONNECT = 200
|
|
|
|
CANCEL = 201
|
|
|
|
ERROR_TOGGLE = 202
|
|
|
|
ERROR_MSG = 203
|
2017-07-26 02:17:49 +10:00
|
|
|
VERIFY_SSL = 204
|
2016-10-23 02:15:10 +11:00
|
|
|
ERROR = {
|
|
|
|
'Invalid': 1,
|
|
|
|
'Empty': 2
|
|
|
|
}
|
|
|
|
|
2017-07-26 02:17:49 +10:00
|
|
|
MEDIA = tryEncode(join(v.ADDON_PATH, 'resources', 'skins', 'default', 'media'))
|
|
|
|
|
2017-07-03 02:23:58 +10:00
|
|
|
###############################################################################
|
2016-10-23 02:15:10 +11:00
|
|
|
|
|
|
|
|
|
|
|
class ServerManual(xbmcgui.WindowXMLDialog):
|
|
|
|
|
|
|
|
_server = None
|
|
|
|
error = None
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
|
|
|
|
xbmcgui.WindowXMLDialog.__init__(self, *args, **kwargs)
|
|
|
|
|
|
|
|
def set_connect_manager(self, connect_manager):
|
|
|
|
self.connect_manager = connect_manager
|
|
|
|
|
|
|
|
def is_connected(self):
|
|
|
|
return True if self._server else False
|
|
|
|
|
|
|
|
def get_server(self):
|
|
|
|
return self._server
|
|
|
|
|
|
|
|
def onInit(self):
|
|
|
|
|
|
|
|
self.connect_button = self.getControl(CONNECT)
|
|
|
|
self.cancel_button = self.getControl(CANCEL)
|
|
|
|
self.error_toggle = self.getControl(ERROR_TOGGLE)
|
|
|
|
self.error_msg = self.getControl(ERROR_MSG)
|
2017-07-17 00:57:57 +10:00
|
|
|
self.host_field = self._add_editcontrol(725, 325, 40, 500)
|
|
|
|
self.port_field = self._add_editcontrol(725, 450, 40, 500)
|
2017-07-26 02:17:49 +10:00
|
|
|
# self.ssl_field = self._add_radiobutton(725, 550, 50, 50)
|
|
|
|
self.ssl_field = self.getControl(VERIFY_SSL)
|
2016-10-23 02:15:10 +11:00
|
|
|
|
2017-07-17 00:57:57 +10:00
|
|
|
self.port_field.setText('32400')
|
2016-10-23 02:15:10 +11:00
|
|
|
self.setFocus(self.host_field)
|
2017-07-26 02:17:49 +10:00
|
|
|
self.ssl_field.setSelected(True)
|
2016-10-23 02:15:10 +11:00
|
|
|
|
|
|
|
self.host_field.controlUp(self.cancel_button)
|
|
|
|
self.host_field.controlDown(self.port_field)
|
|
|
|
self.port_field.controlUp(self.host_field)
|
2017-07-26 02:17:49 +10:00
|
|
|
self.port_field.controlDown(self.ssl_field)
|
|
|
|
self.ssl_field.controlUp(self.port_field)
|
|
|
|
self.ssl_field.controlDown(self.connect_button)
|
|
|
|
self.connect_button.controlUp(self.ssl_field)
|
2016-10-23 02:15:10 +11:00
|
|
|
self.cancel_button.controlDown(self.host_field)
|
|
|
|
|
|
|
|
def onClick(self, control):
|
|
|
|
|
|
|
|
if control == CONNECT:
|
|
|
|
# Sign in to emby connect
|
|
|
|
self._disable_error()
|
|
|
|
|
|
|
|
server = self.host_field.getText()
|
|
|
|
port = self.port_field.getText()
|
|
|
|
|
|
|
|
if not server or not port:
|
|
|
|
# Display error
|
2017-07-17 00:57:57 +10:00
|
|
|
self._error(ERROR['Empty'], lang(30021))
|
2016-10-23 02:15:10 +11:00
|
|
|
log.error("Server or port cannot be null")
|
|
|
|
|
|
|
|
elif self._connect_to_server(server, port):
|
|
|
|
self.close()
|
|
|
|
elif control == CANCEL:
|
|
|
|
# Remind me later
|
|
|
|
self.close()
|
|
|
|
|
|
|
|
def onAction(self, action):
|
|
|
|
|
|
|
|
if self.error == ERROR['Empty'] and self.host_field.getText() and self.port_field.getText():
|
|
|
|
self._disable_error()
|
|
|
|
|
|
|
|
if action in (ACTION_BACK, ACTION_PARENT_DIR, ACTION_PREVIOUS_MENU):
|
|
|
|
self.close()
|
|
|
|
|
|
|
|
def _add_editcontrol(self, x, y, height, width):
|
2017-07-26 02:17:49 +10:00
|
|
|
control = xbmcgui.ControlEdit(
|
|
|
|
0, 0, 0, 0,
|
|
|
|
label="User",
|
|
|
|
font="font10",
|
|
|
|
textColor="ffc2c2c2",
|
|
|
|
focusTexture=join(MEDIA, "button-focus.png"),
|
|
|
|
noFocusTexture=join(MEDIA, "button-focus.png"))
|
|
|
|
control.setPosition(x, y)
|
|
|
|
control.setHeight(height)
|
|
|
|
control.setWidth(width)
|
|
|
|
|
|
|
|
self.addControl(control)
|
|
|
|
return control
|
|
|
|
|
|
|
|
def _add_radiobutton(self, x, y, height, width):
|
|
|
|
control = xbmcgui.ControlRadioButton(
|
|
|
|
0, 0, 0, 0,
|
|
|
|
label="",
|
|
|
|
font="font10",
|
|
|
|
textColor="ffc2c2c2",
|
|
|
|
focusOnTexture=join(MEDIA, "radio-on.png"),
|
|
|
|
noFocusOnTexture=join(MEDIA, "radio-on.png"),
|
|
|
|
focusOffTexture=join(MEDIA, "radio-off.png"),
|
|
|
|
noFocusOffTexture=join(MEDIA, "radio-off.png"))
|
2016-10-23 02:15:10 +11:00
|
|
|
control.setPosition(x, y)
|
|
|
|
control.setHeight(height)
|
|
|
|
control.setWidth(width)
|
|
|
|
|
|
|
|
self.addControl(control)
|
|
|
|
return control
|
|
|
|
|
|
|
|
def _connect_to_server(self, server, port):
|
|
|
|
|
|
|
|
server_address = "%s:%s" % (server, port)
|
2017-07-17 00:57:57 +10:00
|
|
|
self._message("%s %s..." % (lang(30023), server_address))
|
2016-10-23 02:15:10 +11:00
|
|
|
result = self.connect_manager.connectToAddress(server_address)
|
|
|
|
|
|
|
|
if result['State'] == CONN_STATE['Unavailable']:
|
2017-07-17 00:57:57 +10:00
|
|
|
self._message(lang(30204))
|
2016-10-23 02:15:10 +11:00
|
|
|
return False
|
|
|
|
else:
|
|
|
|
self._server = result['Servers'][0]
|
|
|
|
return True
|
|
|
|
|
|
|
|
def _message(self, message):
|
|
|
|
|
|
|
|
self.error_msg.setLabel(message)
|
|
|
|
self.error_toggle.setVisibleCondition('True')
|
|
|
|
|
|
|
|
def _error(self, state, message):
|
|
|
|
|
|
|
|
self.error = state
|
|
|
|
self.error_msg.setLabel(message)
|
|
|
|
self.error_toggle.setVisibleCondition('True')
|
|
|
|
|
|
|
|
def _disable_error(self):
|
|
|
|
|
|
|
|
self.error = None
|
|
|
|
self.error_toggle.setVisibleCondition('False')
|