Show a 'connecting' dialog, fail gracefully if the connection attempt fails

This commit is contained in:
Correl Roush 2010-07-15 15:58:42 -04:00
parent 2aae505544
commit ce5790be3c
2 changed files with 18 additions and 4 deletions

View file

@ -2,6 +2,9 @@
<strings> <strings>
<string id="0">Transmission</string> <string id="0">Transmission</string>
<string id="1">Connecting to Transmission</string>
<string id="2">Transmission Error</string>
<!-- Buttons --> <!-- Buttons -->
<string id="101">Add</string> <string id="101">Add</string>
<string id="102">Remove</string> <string id="102">Remove</string>

View file

@ -21,16 +21,27 @@ CANCEL_DIALOG = EXIT_SCRIPT + ( 216, 257, 61448, )
class TransmissionGUI(xbmcgui.WindowXMLDialog): class TransmissionGUI(xbmcgui.WindowXMLDialog):
def __init__(self, strXMLname, strFallbackPath, strDefaultName, bforeFallback=0): def __init__(self, strXMLname, strFallbackPath, strDefaultName, bforeFallback=0):
self.list = {}
self.torrents = {}
def onInit(self):
p = xbmcgui.DialogProgress()
p.create(_(0), _(1)) # 'Transmission', 'Connecting to Transmission'
params = { params = {
'address': __settings__.getSetting('rpc_host'), 'address': __settings__.getSetting('rpc_host'),
'port': __settings__.getSetting('rpc_port'), 'port': __settings__.getSetting('rpc_port'),
'user': __settings__.getSetting('rpc_user'), 'user': __settings__.getSetting('rpc_user'),
'password': __settings__.getSetting('rpc_password') 'password': __settings__.getSetting('rpc_password')
} }
self.transmission = transmissionrpc.transmission.Client(**params) try:
self.list = {} self.transmission = transmissionrpc.transmission.Client(**params)
self.torrents = {} except transmissionrpc.transmission.TransmissionError:
def onInit(self): p.close()
d = xbmcgui.Dialog()
(type, e, traceback) = sys.exc_info()
d.ok(_(2), e.message) # 'Transmission Error'
self.close()
return False
p.close()
self.updateTorrents() self.updateTorrents()
self.repeater = Repeater(1.0, self.updateTorrents) self.repeater = Repeater(1.0, self.updateTorrents)
self.repeater.start() self.repeater.start()