@ -20,7 +20,7 @@
#
import os
import cgi
import html
import logging
import libtorrent as lt
@ -45,6 +45,7 @@ from efl.evas import Rectangle, EVAS_HINT_EXPAND, EVAS_HINT_FILL
from . Widgets import UnitSpinner , Error , Information , ActSWithLabel , FsButton , \
RangeSpinners
from . . session import lt_version_post_breaking_change , get_session_settings , save_settings
log = logging . getLogger ( " epour.preferences " )
@ -278,34 +279,24 @@ class PreferencesProxy(PreferencesDialog):
proxies = [
[ _ ( " Proxy for torrent peer connections " ) ,
session . peer_proxy , session . set_peer_proxy ] ,
session . peer_proxy , session . set_peer_proxy , session ] ,
[ _ ( " Proxy for torrent web seed connections " ) ,
session . web_seed_proxy , session . set_web_seed_proxy ] ,
session . web_seed_proxy , session . set_web_seed_proxy , session ] ,
[ _ ( " Proxy for tracker connections " ) ,
session . tracker_proxy , session . set_tracker_proxy ] ,
session . tracker_proxy , session . set_tracker_proxy , session ] ,
[ _ ( " Proxy for DHT connections " ) ,
session . dht_proxy , session . set_dht_proxy ] ,
session . dht_proxy , session . set_dht_proxy , session ] ,
]
for title , rfunc , wfunc in proxies :
pg = ProxyGroup ( self , title , rfunc , wfunc )
for title , rfunc , wfunc , session in proxies :
pg = ProxyGroup ( self , title , rfunc , wfunc , session )
pg . show ( )
self . box . pack_end ( pg )
class ProxyGroup ( Frame ) :
proxy_types = {
lt . proxy_type . none . name : lt . proxy_type . none ,
lt . proxy_type . socks4 . name : lt . proxy_type . socks4 ,
lt . proxy_type . socks5 . name : lt . proxy_type . socks5 ,
lt . proxy_type . socks5_pw . name : lt . proxy_type . socks5_pw ,
lt . proxy_type . http . name : lt . proxy_type . http ,
lt . proxy_type . http_pw . name : lt . proxy_type . http_pw ,
lt . proxy_type . i2p_proxy . name : lt . proxy_type . i2p_proxy ,
}
def __init__ ( self , parent , title , rfunc , wfunc ) :
def __init__ ( self , parent , title , rfunc , wfunc , session ) :
Frame . __init__ (
self , parent , size_hint_weight = EXPAND_HORIZ ,
size_hint_align = FILL_HORIZ , text = title
@ -322,9 +313,16 @@ class ProxyGroup(Frame):
l = Label ( self , text = _ ( " Proxy type " ) , size_hint_align = ALIGN_LEFT )
l . show ( )
ptype = Hoversel ( parent , size_hint_align = FILL_HORIZ )
ptype . text = str ( lt . proxy_type . values [ ps . type ] )
for n in lt . proxy_type . names . keys ( ) :
ptype . item_add ( n , callback = lambda x , y , z = n : ptype . text_set ( z ) )
if lt_version_post_breaking_change :
ptype . text = str ( ps . type )
for n in lt . proxy_type_t . values :
label = str ( lt . proxy_type_t . values [ n ] )
ptype . item_add ( label , callback = lambda x , y , z = label : ptype . text_set ( z ) )
else :
ptype . text = str ( lt . proxy_type . values [ ps . type ] )
for n in lt . proxy_type . names . keys ( ) :
ptype . item_add ( n , callback = lambda x , y , z = n : ptype . text_set ( z ) )
ptype . show ( )
t . pack ( l , 0 , 0 , 1 , 1 )
t . pack ( ptype , 1 , 0 , 1 , 1 )
@ -399,17 +397,25 @@ class ProxyGroup(Frame):
def save_conf ( self , btn , wfunc , entries ) :
ptype , phost , pport , puser , ppass , phostlu , ppeer = entries
p = lt . proxy_settings ( )
if lt_version_post_breaking_change :
if ptype . text not in lt . proxy_type_t . proxy_type . names :
raise ValueError ( " Value %s is not valid. " , ptype . text )
p = lt . proxy_type_t . proxy_settings ( )
p . type = lt . proxy_type_t . proxy_type . names [ ptype . text ]
ptype_name = ptype . text
else :
p = lt . proxy_settings ( )
p . type = lt . proxy_type . names [ ptype . text ]
ptype_name = ptype
p . hostname = phost . entry . encode ( " utf-8 " )
p . username = puser . entry . encode ( " utf-8 " )
p . password = ppass . entry . encode ( " utf-8 " )
p . type = lt . proxy_type . names [ ptype . text ]
p . port = int ( pport . value )
p . proxy_hostnames = phostlu . state
p . proxy_peer_connections = ppeer . state
Information ( self . top_widget , _ ( " %s settings saved " ) % ( ptype ) )
Information ( self . top_widget , _ ( " %s settings saved " ) % ( ptype_name ) )
wfunc ( p )
@ -491,7 +497,7 @@ class PreferencesSession(PreferencesDialog):
#elm_conf = Configuration()
#scale = elm_conf.scale
s = session . settings ( )
s = get_session_settings ( session )
t = Table (
self , padding = ( 5 , 5 ) , homogeneous = True , size_hint_align = FILL_BOTH
@ -507,22 +513,15 @@ class PreferencesSession(PreferencesDialog):
import time
t1 = time . time ( )
for k in dir ( s ) :
for k in s . keys ( ) :
if k . startswith ( " __ " ) :
continue
try :
if k == " peer_tos " or k == " outgoing_ports " :
# XXX: these don't have a C++ -> Python equivalent.
continue
a = getattr ( s , k )
if isinstance ( a , lt . disk_cache_algo_t ) :
w = Spinner ( t )
w . size_hint_align = FILL_HORIZ
w . min_max = 0 , len ( lt . disk_cache_algo_t . values ) - 1
for name , val in lt . disk_cache_algo_t . names . items ( ) :
w . special_value_add ( val , name )
w . value = a
elif k == " suggest_mode " :
a = s . get ( k )
if k == " suggest_mode " :
w = Spinner ( t )
w . size_hint_align = FILL_HORIZ
w . min_max = 0 , len ( lt . suggest_mode_t . values ) - 1
@ -583,14 +582,14 @@ class PreferencesSession(PreferencesDialog):
w . size_hint_weight = EXPAND_HORIZ
w . single_line = True
w . editable = False
w . entry = cgi . escape ( a )
w . entry = html . escape ( a )
else :
log . debug ( " Using string for %s type %s " , k , type ( a ) )
w = Entry ( t )
w . size_hint_align = FILL_HORIZ
w . size_hint_weight = EXPAND_HORIZ
w . single_line = True
w . entry = cgi . escape ( a )
w . entry = html . escape ( a )
w . part_text_set ( " guide " , " Enter here " )
l = Label ( t )
l . text = k . replace ( " _ " , " " ) . capitalize ( )
@ -616,13 +615,11 @@ class PreferencesSession(PreferencesDialog):
self . box . pack_end ( save_btn )
def apply_settings ( self , btn , widgets , session ) :
s = lt . session_settings ( )
s = get_session_settings ( session )
for k , w in widgets . items ( ) :
if k == " disk_cache_algorithm " :
v = lt . disk_cache_algo_t ( w . value )
elif isinstance ( w , Spinner ) :
if isinstance ( w , Spinner ) :
v = int ( w . value )
elif isinstance ( w , Slider ) :
v = w . value
@ -633,9 +630,10 @@ class PreferencesSession(PreferencesDialog):
else :
v = None
setattr ( s , k , v )
s [ k ] = v
save_settings ( session , s )
session . set_settings ( s )
Information ( self , " Session settings saved. " )