Package conduit :: Module Settings
[hide private]

Source Code for Module conduit.Settings

  1  """ 
  2  Stores application settings 
  3   
  4  Part of this code copied from Gimmie (c) Alex Gravely 
  5   
  6  Copyright: John Stowers, 2006 
  7  License: GPLv2 
  8  """ 
  9  import gobject 
 10   
 11  #these dicts are used for mapping config setting types to type names 
 12  #and back again (isnt python cool...) 
 13  TYPE_TO_TYPE_NAME = { 
 14      int     :   "int", 
 15      bool    :   "bool", 
 16      str     :   "string", 
 17      list    :   "list" 
 18  } 
 19  STRING_TO_TYPE = { 
 20      "int"       :   lambda x: int(x), 
 21      "bool"      :   lambda x: string_to_bool(x), 
 22      "string"    :   lambda x: str(x), 
 23      "list"      :   lambda x: string_to_list(x) 
 24  } 
 25  TYPE_TO_STRING = { 
 26      int     :   lambda x: str(x), 
 27      bool    :   lambda x: str(x), 
 28      str     :   lambda x: str(x), 
 29      list    :   lambda x: list_to_string(x) 
 30  } 
 31   
32 -def string_to_bool(stringy):
33 #Because bool("False") doesnt work as expected when restoring strings 34 if stringy == "True": 35 return True 36 else: 37 return False
38
39 -def list_to_string(listy):
40 s = "" 41 if type(listy) is list: 42 s = ",".join(listy) #cool 43 return s
44
45 -def string_to_list(string, listInternalVtype=str):
46 l = string.split(",") 47 internalTypeName = TYPE_TO_TYPE_NAME[listInternalVtype] 48 for i in range(0, len(l)): 49 l[i] = STRING_TO_TYPE[internalTypeName](l[i]) 50 return l
51
52 -class Settings(gobject.GObject):
53 """ 54 Class for storing conduit.GLOBALS.settings. Keys of type str, bool, int, 55 and list of strings supported at this stage. 56 57 Also stores the special proxy settings. 58 """ 59 __gsignals__ = { 60 'changed' : (gobject.SIGNAL_RUN_LAST | gobject.SIGNAL_DETAILED, gobject.TYPE_NONE, ()), 61 } 62 63 #Default values for conduit settings 64 DEFAULTS = { 65 'show_splashscreen' : True, #The splashscreen can be quite useful on slow computers 66 'show_dp_description' : False, #Should the treeview show the dataprovider description 67 'show_status_icon' : True, #Show an icon in the notification area indicating if a sync is running 68 'save_on_exit' : True, #Is the sync set saved on exit automatically? 69 'enable_network' : True, #Should conduit look for other conduits on the local network 70 'enable_removable_devices' : True, #Should conduit support iPods, USB keys, etc 71 'default_policy_conflict' : "ask", #Default conflict policy for new Conduits, ask,replace,skip 72 'default_policy_deleted' : "ask", #Default deleted policy for new Conduits, ask,replace,skip 73 'gui_expanded_rows' : [], #list of expanded column paths in the treeview 74 'gui_restore_expanded_rows' : True, #Shoud we expand columns at startup 75 'gui_hpane_postion' : 250, #The hpane seperating the canvas and treeview position 76 'gui_window_size' : [], #W,H 77 'gui_minimize_to_tray' : False, #Behaviour when one minimizes the main window, should it iconify? 78 'gui_initial_canvas_height' : 450, #Reduce to ~300 for eepc, etc 79 'gui_initial_canvas_width' : 450, #Reduce for eepc, etc 80 'gui_use_rgba_colormap' : False, #Seems to corrupt gtkmozembed on some systems 81 'gui_show_hints' : True, #Show message area hints in the Conduit GUI 82 'web_login_browser' : "gtkmozembed" #When loggin into websites use: "system","gtkmozembed","webkit","gtkhtml" 83 } 84
85 - def __init__(self, implName):
86 gobject.GObject.__init__(self) 87 if implName == "GConf": 88 from conduit.platform.SettingsGConf import SettingsImpl 89 else: 90 from conduit.platform.SettingsPython import SettingsImpl 91 92 self._impl = SettingsImpl( 93 defaults=self.DEFAULTS, 94 changedCb=self._key_changed)
95
96 - def _key_changed(self, key):
97 self.emit('changed::%s' % key)
98
99 - def set_overrides(self, **overrides):
100 """ 101 Sets values of settings that only exist for this setting, and are 102 never saved, nor updated. 103 """ 104 self._impl.set_overrides(**overrides)
105
106 - def get(self, key, **kwargs):
107 """ 108 Returns the value of the key or the default value if the key is 109 not yet stored 110 """ 111 return self._impl.get(key, **kwargs)
112
113 - def set(self, key, value, **kwargs):
114 """ 115 Sets the key to value. 116 """ 117 return self._impl.set(key, value, **kwargs)
118
119 - def proxy_enabled(self):
120 """ 121 @returns: True if the user has specified a http proxy via 122 the http_proxy environment variable, or in the appropriate settings 123 backend, such as gconf 124 """ 125 return self._impl.proxy_enabled()
126
127 - def get_proxy(self):
128 """ 129 Returns the details of the configured http proxy. 130 The http_proxy environment variable overrides the GNOME setting 131 @returns: host,port,user,password 132 """ 133 return self._impl.get_proxy()
134
135 - def save(self):
136 """ 137 Performs any necessary tasks to ensure settings are saved between sessions 138 """ 139 self._impl.save()
140