Add a settings button to the main window

This commit is contained in:
Artem Glebov 2013-03-15 11:15:14 +03:00
parent 5a3573b15d
commit 8719124bb0
7 changed files with 56 additions and 12 deletions

View file

@ -14,6 +14,7 @@
<string id="105">Pause All</string>
<string id="106">Start All</string>
<string id="107">Exit</string>
<string id="108">Settings</string>
<!-- Adding / Search -->
<string id="200">Browse for torrent file</string>

View file

@ -13,6 +13,7 @@
<string id="105">Остановить все</string>
<string id="106">Запустить все</string>
<string id="107">Выход</string>
<string id="108">Настойки</string>
<!-- Settings -->
<string id="1000">Настройки RPC</string>

View file

@ -28,24 +28,34 @@ class TransmissionGUI(xbmcgui.WindowXMLDialog):
self.list = {}
self.torrents = {}
self.repeater = None
def onInit(self):
p = xbmcgui.DialogProgress()
p.create(_(0), _(1)) # 'Transmission', 'Connecting to Transmission'
def get_settings(self):
params = {
'address': __settings__.getSetting('rpc_host'),
'port': __settings__.getSetting('rpc_port'),
'user': __settings__.getSetting('rpc_user'),
'password': __settings__.getSetting('rpc_password')
}
return params
def set_settings(self, params):
__settings__.setSetting('rpc_host', params['address'])
__settings__.setSetting('rpc_port', params['port'])
__settings__.setSetting('rpc_user', params['user'])
__settings__.setSetting('rpc_password', params['password'])
def get_rpc_client(self):
params = self.get_settings()
import transmissionrpc
return transmissionrpc.Client(**params)
def onInit(self):
p = xbmcgui.DialogProgress()
p.create(_(0), _(1)) # 'Transmission', 'Connecting to Transmission'
try:
self.transmission = transmissionrpc.Client(**params)
self.transmission = self.get_rpc_client()
except:
p.close()
self.close()
(type, e, traceback) = sys.exc_info()
message = _(9000) # Unexpected error
import transmissionrpc
if type is transmissionrpc.TransmissionError:
if e.original:
if e.original.code is 401:
@ -63,7 +73,6 @@ class TransmissionGUI(xbmcgui.WindowXMLDialog):
else:
message = _(9000) # Unexpected error
xbmcgui.Dialog().ok(_(2), message)
return False
p.close()
self.updateTorrents()
@ -176,6 +185,26 @@ class TransmissionGUI(xbmcgui.WindowXMLDialog):
if (controlID == 117):
# Exit button
self.close()
if (controlID == 118):
# Settings button
prev_settings = self.get_settings()
__settings__.openSettings()
p = xbmcgui.DialogProgress()
p.create(_(0), _(1)) # 'Transmission', 'Connecting to Transmission'
try:
self.transmission = self.get_rpc_client()
self.updateTorrents()
p.close()
except:
p.close()
xbmcgui.Dialog().ok(_(2), _(9001))
# restore settings
self.set_settings(prev_settings)
try:
self.transmission = self.get_rpc_client()
except err:
xbmcgui.Dialog().ok(_(2), _(9001))
self.close()
if (controlID == 120):
# A torrent was chosen, show details
item = list.getSelectedItem()

View file

@ -135,8 +135,8 @@
<texturefocus>startall-focus.png</texturefocus>
<texturenofocus>startall-nofocus.png</texturenofocus>
</control>
<control type="button" id="117">
<description>Exit</description>
<control type="button" id="118">
<description>Settings</description>
<posx>0</posx>
<posy>450</posy>
<height>70</height>
@ -144,12 +144,12 @@
<align>center</align>
<aligny>top</aligny>
<textoffsety>45</textoffsety>
<label>SCRIPT107</label>
<label>SCRIPT108</label>
<font>font12_title</font>
<onright>120</onright>
<onup>116</onup>
<texturefocus>exit-focus.png</texturefocus>
<texturenofocus>exit-nofocus.png</texturenofocus>
<texturefocus>settings-focus.png</texturefocus>
<texturenofocus>settings-nofocus.png</texturenofocus>
<ondown>111</ondown>
</control>
</control>
@ -261,5 +261,18 @@
</control>
</focusedlayout>
</control>
<control type="button" id="117">
<description>Exit</description>
<posx>850</posx>
<posy>-5</posy>
<height>32</height>
<width>64</width>
<textoffsety>45</textoffsety>
<label>-</label>
<font>-</font>
<texturefocus>DialogCloseButton-focus.png</texturefocus>
<texturenofocus>DialogCloseButton.png</texturenofocus>
<visible>system.getbool(input.enablemouse)</visible>
</control>
</controls>
</window>

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB