00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 import ConfigParser
00031 import os
00032 import sys
00033 from Koo import Rpc
00034 import Debug
00035 from PyQt4.QtCore import QDir, QUrl
00036
00037
00038
00039
00040 class Settings(object):
00041 rcFile = False
00042 options = {
00043 'login.db': 'test',
00044 'login.url': 'http://admin@localhost:8069',
00045 'path.share': os.path.join(sys.prefix, 'share/Koo/'),
00046 'path.pixmaps': os.path.join(sys.prefix, 'share/pixmaps/Koo/'),
00047 'path.ui': os.path.join(sys.prefix, 'share/Koo/ui'),
00048 'tip.autostart': True,
00049 'tip.position': 0,
00050 'client.default_path': os.path.expanduser('~'),
00051 'client.language': False,
00052 'client.debug': False,
00053 'koo.print_directly': False,
00054 'koo.stylesheet' : '',
00055 'koo.tabs_position' : 'top',
00056 'koo.tabs_closable' : True,
00057 'koo.show_toolbar' : True,
00058 'koo.sort_mode' : 'all_items',
00059 'koo.pos_mode' : False,
00060 'koo.enter_as_tab' : False,
00061 'kde.enabled' : True,
00062 'koo.attachments_dialog' : False,
00063 'koo.load_on_open' : True,
00064 'koo.smtp_server' : 'mail.nan-tic.com',
00065 'koo.smtp_from' : 'koo@nan-tic.com',
00066 'koo.smtp_backtraces_to' : 'backtraces@nan-tic.com',
00067 }
00068
00069
00070 @staticmethod
00071 def saveToFile():
00072 if not Settings.rcFile:
00073
00074
00075 Settings.rcFile = os.environ.get('TERPRC') or os.path.join(unicode(QDir.toNativeSeparators(QDir.homePath())), '.koorc')
00076 try:
00077 p = ConfigParser.ConfigParser()
00078 sections = {}
00079 for o in Settings.options.keys():
00080 if not len(o.split('.'))==2:
00081 continue
00082 osection,oname = o.split('.')
00083 if not p.has_section(osection):
00084 p.add_section(osection)
00085 p.set(osection,oname,Settings.options[o])
00086 f = open(Settings.rcFile, 'wb')
00087 try:
00088 p.write( f )
00089 except:
00090 Debug.warning( 'Unable to write config file %s !' % Settings.rcFile )
00091 finally:
00092 f.close()
00093 except:
00094 Debug.warning( 'Unable to write config file %s !' % Settings.rcFile )
00095 return True
00096
00097
00098 @staticmethod
00099 def loadFromFile():
00100 if not Settings.rcFile:
00101
00102
00103 Settings.rcFile = os.environ.get('TERPRC') or os.path.join(unicode(QDir.toNativeSeparators(QDir.homePath())), '.koorc')
00104 try:
00105 if not os.path.isfile(Settings.rcFile):
00106 Settings.save()
00107 return False
00108
00109 p = ConfigParser.ConfigParser()
00110 p.read([Settings.rcFile])
00111 for section in p.sections():
00112 for (name,value) in p.items(section):
00113 if value=='True' or value=='true':
00114 value = True
00115 if value=='False' or value=='false':
00116 value = False
00117 Settings.options[section+'.'+name] = value
00118 except Exception, e:
00119 Debug.warning( 'Unable to read config file %s !' % Settings.rcFile )
00120 return True
00121
00122
00123 @staticmethod
00124 def loadFromRegistry():
00125 if os.name != 'nt':
00126 return
00127
00128 languages = {
00129 '1027': 'ca',
00130 '1031': 'de',
00131 '1033': 'en',
00132 '1034': 'es',
00133 '1040': 'it',
00134 }
00135
00136 import _winreg
00137 key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, r"Software\Koo")
00138 value, value_type = _winreg.QueryValueEx(key, "Language")
00139 Settings.options['client.language'] = languages.get(value, False)
00140
00141
00142 @staticmethod
00143 def setValue(key, value):
00144 Settings.options[key]=value
00145
00146
00147
00148
00149
00150 @staticmethod
00151 def value(key, defaultValue=None, toType=None):
00152 value = Settings.options.get(key, defaultValue)
00153 if toType == int:
00154 return int( value )
00155 return value
00156
00157
00158
00159 @staticmethod
00160 def get(key, defaultValue=None):
00161 return Settings.options.get(key, defaultValue)
00162
00163
00164
00165 @staticmethod
00166 def loadFromServer():
00167 try:
00168 settings = Rpc.session.call( '/object', 'execute', 'nan.koo.settings', 'get_settings' )
00169 except:
00170 settings = {}
00171 new_settings = {}
00172 for key, value in settings.iteritems():
00173 if key != 'id':
00174 new_settings[ 'koo.%s' % key ] = value
00175 Settings.options.update( new_settings )
00176 Rpc.ViewCache.exceptions = Settings.options.get('koo.cache_exceptions', [])
00177