|
1
|
|
|
#!/usr/bin/python |
|
2
|
|
|
# -*- coding: UTF-8 -*- |
|
3
|
|
|
import time |
|
4
|
|
|
import threading |
|
5
|
|
|
import xbmc, xbmcgui, xbmcaddon |
|
6
|
|
|
|
|
7
|
|
|
from utils import get_str |
|
8
|
|
|
from utils import log |
|
9
|
|
|
from utils import __addon__ |
|
10
|
|
|
|
|
11
|
|
|
__icon__ = __addon__.getAddonInfo("icon") |
|
12
|
|
|
xbmc.log("Icon = " + str(__icon__)) |
|
13
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
PIN_LABEL = 201 |
|
16
|
|
|
INSTRUCTION_ID = 202 |
|
17
|
|
|
CANCEL_BUTTON = 203 |
|
18
|
|
|
ACTION_PREVIOUS_MENU = 10 |
|
19
|
|
|
ACTION_BACK = 92 |
|
20
|
|
|
|
|
21
|
|
|
not_dialog = xbmcgui.Dialog() |
|
22
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
def notify(txt="", title="Simkl", icon=__icon__): |
|
25
|
|
|
not_dialog.notification(title, txt, icon) |
|
26
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
class LoginDialog(xbmcgui.WindowXMLDialog): |
|
29
|
|
|
def __init__(self, xmlFilename, scriptPath, pin, url, pin_check=None, pin_success=None): |
|
30
|
|
|
self.pin = pin |
|
31
|
|
|
self.url = url |
|
32
|
|
|
self.canceled = False |
|
33
|
|
|
self.pin_check = pin_check |
|
34
|
|
|
self.success = pin_success |
|
35
|
|
|
|
|
36
|
|
|
def threaded(self): |
|
37
|
|
|
""" A loop threaded function, so you can do another things meanwhile """ |
|
38
|
|
|
log("login thread start = {0}".format(self)) |
|
39
|
|
|
cnt = 0 |
|
40
|
|
|
while True: |
|
41
|
|
|
log("Still waiting... {0}".format(cnt)) |
|
42
|
|
|
if self.pin_check(self.pin): |
|
43
|
|
|
self.success() |
|
44
|
|
|
self.close() |
|
45
|
|
|
break |
|
46
|
|
|
if self.canceled or cnt >= 220: |
|
47
|
|
|
notify(get_str(32031)) |
|
48
|
|
|
break |
|
49
|
|
|
cnt += 1 |
|
50
|
|
|
xbmc.Monitor().waitForAbort(4) |
|
51
|
|
|
|
|
52
|
|
|
log("Stop waiting") |
|
53
|
|
|
|
|
54
|
|
|
def onInit(self): |
|
55
|
|
|
"""The function that is loaded on Window init""" |
|
56
|
|
|
instruction = self.getControl(INSTRUCTION_ID) |
|
57
|
|
|
instruction.setLabel(get_str(32022).format("[COLOR ffffbf00]" + self.url + "[/COLOR]")) |
|
58
|
|
|
self.getControl(PIN_LABEL).setLabel(self.pin) |
|
59
|
|
|
t = threading.Thread(target=self.threaded) |
|
60
|
|
|
t.start() |
|
61
|
|
|
|
|
62
|
|
|
def onControl(self, controlID): |
|
63
|
|
|
pass |
|
64
|
|
|
|
|
65
|
|
|
def onFocus(self, controlID): |
|
66
|
|
|
pass |
|
67
|
|
|
|
|
68
|
|
|
def onAction(self, action): |
|
69
|
|
|
if action == ACTION_PREVIOUS_MENU or action == ACTION_BACK: |
|
70
|
|
|
self.canceled = True |
|
71
|
|
|
self.close() |
|
72
|
|
|
|
|
73
|
|
|
def onClick(self, controlID): |
|
74
|
|
|
log("onclick {0}, {1}".format(controlID, self)) |
|
75
|
|
|
if controlID == CANCEL_BUTTON: |
|
76
|
|
|
self.canceled = True |
|
77
|
|
|
self.close() |
|
78
|
|
|
|