diff --git a/deluge/ui/webui/webui_plugin/config.py b/deluge/ui/webui/webui_plugin/config.py index 5cd403ba9..cb02efb62 100644 --- a/deluge/ui/webui/webui_plugin/config.py +++ b/deluge/ui/webui/webui_plugin/config.py @@ -37,6 +37,7 @@ import lib.webpy022 as web from webserver_common import ws from render import render from lib.webpy022.http import seeother +import sys groups = [] blocks = forms.utils.datastructures.SortedDict() @@ -85,8 +86,48 @@ class CfgForm(Form): "config base for deluge-cfg" def initial_data(self): return ws.proxy.get_config() - def save(data): - ws.proxy.set_config(data) + def save(self, data): + ws.proxy.set_config(dict(data)) + + +#convenience Fields. + +class _IntInput(forms.TextInput): + """ + because deluge-floats are edited as ints. + """ + def render(self, name, value, attrs=None): + try: + value = int(float(value)) + except: + pass + return forms.TextInput.render(self, name, value, attrs) + +class CheckBox(forms.BooleanField): + "Non Required ChoiceField" + def __init__(self,label, **kwargs): + forms.BooleanField.__init__(self,label=label,required=False,**kwargs) + +class IntCombo(forms.ChoiceField): + """ + choices are the display-values + returns int for the chosen display-value. + """ + def __init__(self, label, choices, **kwargs): + forms.ChoiceField.__init__(self, label=label, choices=enumerate(choices) + , **kwargs) + + def clean(self, value): + return int(forms.ChoiceField.clean(self, value)) + +class DelugeInt(forms.IntegerField): + def __init__(self, label , **kwargs): + forms.IntegerField.__init__(self, label=label, min_value=-1, + max_value=sys.maxint, widget=_IntInput, **kwargs) + +class DelugeFloat(DelugeInt): + def clean(self, value): + return int(DelugeInt.clean(self, value)) class config_page: @@ -129,7 +170,7 @@ class config_page: ws.log.debug(e.message) return self.render(form , name, error = e.message) else: - return self.render(form , name, _('Please correct errors and try again')) + return self.render(form , name, error= _('Please correct the errors above and try again')) def render(self, f , name , message = '' , error=''): return render.config(groups, blocks, f, name , message , error) diff --git a/deluge/ui/webui/webui_plugin/config_tabs_deluge.py b/deluge/ui/webui/webui_plugin/config_tabs_deluge.py index bf961a2de..532d90f63 100644 --- a/deluge/ui/webui/webui_plugin/config_tabs_deluge.py +++ b/deluge/ui/webui/webui_plugin/config_tabs_deluge.py @@ -36,11 +36,89 @@ import config import utils -class BandWidth(config.CfgForm): - title = _("Bandwidth") - up = forms.IntegerField(label = "TODO") -config.register_block('deluge','bandwidth',BandWidth) +class ServerFolderField(forms.CharField): + pass +class NetworkPorts(config.CfgForm ): + title = _("Ports") + info = _("Restart daemon after changing these values.") + _port_from = forms.IntegerField(_("From")) + _port_to = forms.IntegerField(_("To")) + random_port = config.CheckBox(_("Random")) + + def initial_data(self): + data = config.CfgForm.initial_data(self) + data['_port_from'] , data['_port_to'] = data['listen_ports'] + return data + + def save(self,data): + data['listen_ports'] = [data['_port_from'] , data['_port_to'] ] + if (data['_port_to'] < data['_port_from']): + raise ValidationError('"Port from" must be greater than "Port to"') + config.CfgForm.save() + +config.register_block('network','ports', NetworkPorts) + +class NetworkExtra(config.CfgForm ): + title = _("Extra's") + dht = config.CheckBox(_("Mainline DHT")) + upnp = config.CheckBox(_("UpNP")) + natpmp = config.CheckBox(_("NAT-PMP")) + utpex = config.CheckBox(_("Peer-Exchange")) + lsd = config.CheckBox(_("LSD")) + +config.register_block('network','extra', NetworkExtra) + +class NetworkEnc(config.CfgForm ): + title = _("Encryption") + + _enc_choices = [_("Forced"),_("Enabled"),_("Disabled")] + _level_choices = [_("Handshake"), _("Full") , _("Either")] + + enc_in_policy = config.IntCombo(_("Inbound"), _enc_choices) + enc_out_policy = config.IntCombo(_("Outbound"), _enc_choices) + enc_level = config.IntCombo(_("Level"), _level_choices) + enc_prefer_rc4 = config.CheckBox("Prefer to encrypt entire stream") + +config.register_block('network','encryption', NetworkEnc) + + +class BandwithGlobal(config.CfgForm): + title = _("Global") + info = _("-1 = Unlimited") + max_connections_global = config.DelugeInt(_("Maximum Connections")) + max_download_speed = config.DelugeFloat(_("Maximum Download Speed (Kib/s)")) + max_upload_speed = config.DelugeFloat(_("Maximum Upload Speed (Kib/s)")) + max_upload_slots_global = config.DelugeInt(_("Maximum Upload Slots")) + +config.register_block('bandwidth','global', BandwithGlobal) + +class BandwithTorrent(config.CfgForm): + title = _("Per Torrent") + info = _("-1 = Unlimited") + max_connections_per_torrent = config.DelugeInt(_("Maximum Connections")) + max_upload_slots_per_torrent = config.DelugeInt(_("Maximum Upload Slots")) + +config.register_block('bandwidth','torrent', BandwithTorrent) + + +class Download(config.CfgForm): + title = _("Download") + download_location = ServerFolderField(_("Store all downoads in")) + torrentfiles_location = ServerFolderField(_("Save .torrent files to")) + autoadd_location = ServerFolderField(_("Auto Add folder") , required=False) + compact_allocation = config.CheckBox(_('Use Compact Allocation')) + prioritize_first_last_pieces = config.CheckBox(_('Prioritize first and last pieces')) + +config.register_block('deluge','download', Download) + +class Daemon(config.CfgForm): + title = _("Daemon") + daemon_port = forms.IntegerField(_("Port")) + allow_remote = config.CheckBox(_("Allow Remote Connections")) + +config.register_block('deluge','daemon', Daemon) + diff --git a/deluge/ui/webui/webui_plugin/config_tabs_webui.py b/deluge/ui/webui/webui_plugin/config_tabs_webui.py index dbaaba10a..eb0d7b20e 100644 --- a/deluge/ui/webui/webui_plugin/config_tabs_webui.py +++ b/deluge/ui/webui/webui_plugin/config_tabs_webui.py @@ -41,42 +41,40 @@ from webserver_common import ws class Template(config.WebCfgForm): title = _("Template") - template = forms.ChoiceField( label=_("Template"), - choices = [(t,t) for t in ws.get_templates()]) + _templates = [(t,t) for t in ws.get_templates()] + _button_choices = [_('Text and image'), _('Image Only'), _('Text Only')] - button_style = forms.ChoiceField( label=_("Button style"), - choices=[ - (0,_('Text and image')), - (1, _('Image Only')), - (2, _('Text Only'))]) - - cache_templates = forms.BooleanField(label = _("Cache templates"), - required=False) + template = forms.ChoiceField( label=_("Template"), choices = _templates) + button_style = config.IntCombo(_("Button style"),_button_choices) + cache_templates = config.CheckBox(_("Cache templates")) def post_save(self): render.apply_cfg() class Server(config.WebCfgForm): - info = _("Restart webui after changing these values.") title = _("Server") port = forms.IntegerField(label = _("Port"),min_value=80) - use_https = forms.BooleanField(label = _("Use https") , required=False) + use_https = config.CheckBox(_("Use https")) + + def post_save(self): + pass + #raise forms.ValidationError(_("Manually restart server to apply these changes.")) class Password(config.Form): title = _("Password") old_pwd = forms.CharField(widget = forms.PasswordInput - ,label = _("Current Password"), required=False) + ,label = _("Current Password")) new1 = forms.CharField(widget = forms.PasswordInput - ,label = _("New Password"), required=False) + ,label = _("New Password")) new2 = forms.CharField(widget = forms.PasswordInput - ,label = _("New Password (Confirm)"), required=False) + ,label = _("New Password (Confirm)")) def initial_data(self): - return {} + return None def save(self,data): if not ws.check_pwd(data.old_pwd): @@ -87,8 +85,10 @@ class Password(config.Form): ws.update_pwd(data.new1) ws.save_config() + def post_save(self): utils.end_session() + #raise forms.ValidationError(_("Password changed,please login again")) config.register_block('webui','template', Template) config.register_block('webui','server',Server) diff --git a/deluge/ui/webui/webui_plugin/render.py b/deluge/ui/webui/webui_plugin/render.py index b42ff3571..4e4ae502f 100644 --- a/deluge/ui/webui/webui_plugin/render.py +++ b/deluge/ui/webui/webui_plugin/render.py @@ -133,7 +133,8 @@ template.Template.globals.update({ 'rev': 'rev.%s' % (REVNO, ), 'version': VERSION, 'getcookie':getcookie, - 'get': lambda (var): getattr(web.input(**{var:None}), var) # unreadable :-( + 'get': lambda (var): getattr(web.input(**{var:None}), var), # unreadable :-( + 'env':ws.env }) #/template-defs diff --git a/deluge/ui/webui/webui_plugin/templates/advanced/part_stats.html b/deluge/ui/webui/webui_plugin/templates/advanced/part_stats.html index 6ce594919..2bccc8bfe 100644 --- a/deluge/ui/webui/webui_plugin/templates/advanced/part_stats.html +++ b/deluge/ui/webui/webui_plugin/templates/advanced/part_stats.html @@ -12,16 +12,21 @@ $else: $_('Off')   $:render.part_button('POST', '/refresh/on', _('Enable'), 'tango/view-refresh.png') $#end +
+$if env == '0.6': + $:render.part_button('GET', '/config/', _('Settings'), 'tango/preferences-system.png') - $_('Connections') : $stats.num_connections ($stats.max_num_connections) +$_('Connections') : $stats.num_connections ($stats.max_num_connections) + +$_('Down Speed') : $stats.download_rate ($stats.max_download) + +$_('Up Speed') : $stats.upload_rate ($stats.max_upload) - $_('Down Speed') : $stats.download_rate ($stats.max_download) - $_('Up Speed') : $stats.upload_rate ($stats.max_upload) diff --git a/deluge/ui/webui/webui_plugin/templates/advanced/static/advanced.css b/deluge/ui/webui/webui_plugin/templates/advanced/static/advanced.css index 2b801a1b8..5fb590ba6 100644 --- a/deluge/ui/webui/webui_plugin/templates/advanced/static/advanced.css +++ b/deluge/ui/webui/webui_plugin/templates/advanced/static/advanced.css @@ -165,14 +165,30 @@ body.inner { border:0; position:relative; top:0px; - height:20px; + height:15px; background-color:#ddd; - color:#000; + color:#00F; } + #refresh_panel button:hover { text-decoration: underline; } +#stats_panel button { + background-color:#304663; + color:#FFFFFF; + border:0; + position:relative; + top:0px; + height:20px; + background-color:#ddd; + color:#00F; +} +#stats_panel button:hover { + text-decoration: underline; +} + + #category_panel { margin-bottom:0; padding-bottom:0; diff --git a/deluge/ui/webui/webui_plugin/templates/deluge/part_button.html b/deluge/ui/webui/webui_plugin/templates/deluge/part_button.html index 8c420560f..2dc23e65a 100644 --- a/deluge/ui/webui/webui_plugin/templates/deluge/part_button.html +++ b/deluge/ui/webui/webui_plugin/templates/deluge/part_button.html @@ -2,14 +2,14 @@ $def with (method, url, title, image='')
-$if (get_config('button_style') == 0): +$if (int(get_config('button_style')) == 0): -$if (get_config('button_style') == 1): +$if (int(get_config('button_style')) == 1): $if image: $else: @@ -17,7 +17,7 @@ $if (get_config('button_style') == 1): $title -$if (get_config('button_style') == 2): +$if (int(get_config('button_style')) == 2): diff --git a/deluge/ui/webui/webui_plugin/templates/deluge/part_stats.html b/deluge/ui/webui/webui_plugin/templates/deluge/part_stats.html index 342b8049f..305a9ea25 100644 --- a/deluge/ui/webui/webui_plugin/templates/deluge/part_stats.html +++ b/deluge/ui/webui/webui_plugin/templates/deluge/part_stats.html @@ -26,9 +26,10 @@ $#end - - ($_('About')) - +$if env == '0.6': + $:render.part_button('GET', '/config/', _('Settings'), 'tango/preferences-system.png') + +
diff --git a/deluge/ui/webui/webui_plugin/tests/test_all.py b/deluge/ui/webui/webui_plugin/tests/test_all.py index 4c163c344..d8298c6ba 100644 --- a/deluge/ui/webui/webui_plugin/tests/test_all.py +++ b/deluge/ui/webui/webui_plugin/tests/test_all.py @@ -362,6 +362,7 @@ if True: print key,cfg[key] + if False: suiteFew = unittest.TestSuite()