comparison frontends/quick_frontend/quick_app.py @ 70:8f2ed279784b

i18n - gettext support added in frontends - first draft of frontends french translation
author Goffi <goffi@goffi.org>
date Fri, 05 Mar 2010 20:33:10 +1100
parents 9b842086d915
children efe81b61673c
comparison
equal deleted inserted replaced
69:86f1f7f6d332 70:8f2ed279784b
21 21
22 from logging import debug, info, error 22 from logging import debug, info, error
23 from tools.jid import JID 23 from tools.jid import JID
24 from sat_bridge_frontend.DBus import DBusBridgeFrontend 24 from sat_bridge_frontend.DBus import DBusBridgeFrontend
25 import pdb 25 import pdb
26
27 import gettext
28 gettext.install('sat_frontend', "../i18n", unicode=True)
26 29
27 class QuickApp(): 30 class QuickApp():
28 """This class contain the main methods needed for the frontend""" 31 """This class contain the main methods needed for the frontend"""
29 32
30 def __init__(self, single_profile=True): 33 def __init__(self, single_profile=True):
55 return profile in self.profiles.keys() 58 return profile in self.profiles.keys()
56 59
57 def plug_profile(self, profile_key='@DEFAULT@'): 60 def plug_profile(self, profile_key='@DEFAULT@'):
58 """Tell application which profile must be used""" 61 """Tell application which profile must be used"""
59 if self.single_profile and self.profiles: 62 if self.single_profile and self.profiles:
60 error('There is already one profile plugged (we are in single profile mode) !') 63 error(_('There is already one profile plugged (we are in single profile mode) !'))
61 return 64 return
62 profile = self.bridge.getProfileName(profile_key) 65 profile = self.bridge.getProfileName(profile_key)
63 if not profile: 66 if not profile:
64 error("The profile asked doesn't exist") 67 error(_("The profile asked doesn't exist"))
65 return 68 return
66 if self.profiles.has_key(profile): 69 if self.profiles.has_key(profile):
67 warning("The profile is already plugged") 70 warning(_("The profile is already plugged"))
68 return 71 return
69 self.profiles[profile]={} 72 self.profiles[profile]={}
70 if self.single_profile: 73 if self.single_profile:
71 self.profile = profile 74 self.profile = profile
72 75
102 self.subscribe(waitingSub[sub], sub, profile) 105 self.subscribe(waitingSub[sub], sub, profile)
103 106
104 def unplug_profile(self, profile): 107 def unplug_profile(self, profile):
105 """Tell the application to not follow anymore the profile""" 108 """Tell the application to not follow anymore the profile"""
106 if not profile in self.profiles: 109 if not profile in self.profiles:
107 warning ("This profile is not plugged") 110 warning (_("This profile is not plugged"))
108 return 111 return
109 self.profiles.remove(profile) 112 self.profiles.remove(profile)
110 113
111 def clear_profile(self): 114 def clear_profile(self):
112 self.profiles.clear() 115 self.profiles.clear()
113 116
114 def connected(self, profile): 117 def connected(self, profile):
115 """called when the connection is made""" 118 """called when the connection is made"""
116 if not self.__check_profile(profile): 119 if not self.__check_profile(profile):
117 return 120 return
118 debug("Connected") 121 debug(_("Connected"))
119 self.setStatusOnline(True) 122 self.setStatusOnline(True)
120 123
121 def disconnected(self, profile): 124 def disconnected(self, profile):
122 """called when the connection is closed""" 125 """called when the connection is closed"""
123 if not self.__check_profile(profile): 126 if not self.__check_profile(profile):
124 return 127 return
125 debug("Disconnected") 128 debug(_("Disconnected"))
126 self.CM.clear() 129 self.CM.clear()
127 self.contactList.clear_contacts() 130 self.contactList.clear_contacts()
128 self.setStatusOnline(False) 131 self.setStatusOnline(False)
129 132
130 def newContact(self, JabberId, attributes, groups, profile): 133 def newContact(self, JabberId, attributes, groups, profile):
148 151
149 def presenceUpdate(self, jabber_id, show, priority, statuses, profile): 152 def presenceUpdate(self, jabber_id, show, priority, statuses, profile):
150 if not self.__check_profile(profile): 153 if not self.__check_profile(profile):
151 return 154 return
152 print "check ok" 155 print "check ok"
153 debug ("presence update for %s (show=%s, statuses=%s)", jabber_id, show, statuses); 156 debug (_("presence update for %(jid)s (show=%(show)s, statuses=%(statuses)s)") % {'jid':jabber_id, 'show':show, 'statuses':statuses});
154 from_jid=JID(jabber_id) 157 from_jid=JID(jabber_id)
155 debug ("from_jid.short=%s whoami.short=%s", from_jid.short, self.profiles[profile]['whoami'].short) 158 debug ("from_jid.short=%(from_jid)s whoami.short=%(whoami)s" % {'from_jid':from_jid.short, 'whoami':self.profiles[profile]['whoami'].short})
156 159
157 if from_jid.short==self.profiles[profile]['whoami'].short: 160 if from_jid.short==self.profiles[profile]['whoami'].short:
158 if not type: 161 if not type:
159 self.setStatusOnline(True) 162 self.setStatusOnline(True)
160 elif type=="unavailable": 163 elif type=="unavailable":
169 name=self.rosterList[from_jid.short][0]["name"] 172 name=self.rosterList[from_jid.short][0]["name"]
170 groups=self.rosterList[from_jid.short][1] 173 groups=self.rosterList[from_jid.short][1]
171 174
172 #FIXME: must be moved in a plugin 175 #FIXME: must be moved in a plugin
173 if from_jid.short in self.profiles[profile]['watched'] and not from_jid.short in self.profiles[profile]['onlineContact']: 176 if from_jid.short in self.profiles[profile]['watched'] and not from_jid.short in self.profiles[profile]['onlineContact']:
174 self.showAlert("Watched jid [%s] is connected !" % from_jid.short) 177 self.showAlert(_("Watched jid [%s] is connected !") % from_jid.short)
175 178
176 self.profiles[profile]['onlineContact'].add(from_jid) #FIXME onlineContact is useless with CM, must be removed 179 self.profiles[profile]['onlineContact'].add(from_jid) #FIXME onlineContact is useless with CM, must be removed
177 self.CM.add(from_jid) 180 self.CM.add(from_jid)
178 self.CM.update(from_jid, 'name', name) 181 self.CM.update(from_jid, 'name', name)
179 self.CM.update(from_jid, 'show', show) 182 self.CM.update(from_jid, 'show', show)
197 if not self.__check_profile(profile): 200 if not self.__check_profile(profile):
198 return 201 return
199 entity = JID(raw_jid) 202 entity = JID(raw_jid)
200 if type=="subscribed": 203 if type=="subscribed":
201 # this is a subscription confirmation, we just have to inform user 204 # this is a subscription confirmation, we just have to inform user
202 self.showDialog("The contact %s has accepted your subscription" % entity.short, 'Subscription confirmation') 205 self.showDialog(_("The contact %s has accepted your subscription") % entity.short, _('Subscription confirmation'))
203 elif type=="unsubscribed": 206 elif type=="unsubscribed":
204 # this is a subscription refusal, we just have to inform user 207 # this is a subscription refusal, we just have to inform user
205 self.showDialog("The contact %s has refused your subscription" % entity.short, 'Subscription refusal', 'error') 208 self.showDialog(_("The contact %s has refused your subscription") % entity.short, _('Subscription refusal'), 'error')
206 elif type=="subscribe": 209 elif type=="subscribe":
207 # this is a subscriptionn request, we have to ask for user confirmation 210 # this is a subscriptionn request, we have to ask for user confirmation
208 answer = self.showDialog("The contact %s wants to subscribe to your presence.\nDo you accept ?" % entity.short, 'Subscription confirmation', 'yes/no') 211 answer = self.showDialog(_("The contact %s wants to subscribe to your presence.\nDo you accept ?") % entity.short, _('Subscription confirmation'), 'yes/no')
209 if answer: 212 if answer:
210 self.bridge.subscription("subscribed", entity.short) 213 self.bridge.subscription("subscribed", entity.short)
211 else: 214 else:
212 self.bridge.subscribed("unsubscribed", entity.short) 215 self.bridge.subscribed("unsubscribed", entity.short)
213 216
218 pass #FIXME 221 pass #FIXME
219 222
220 def paramUpdate(self, name, value, namespace, profile): 223 def paramUpdate(self, name, value, namespace, profile):
221 if not self.__check_profile(profile): 224 if not self.__check_profile(profile):
222 return 225 return
223 debug("param update: [%s] %s = %s", namespace, name, value) 226 debug(_("param update: [%(namespace)s] %(name)s = %(value)s") % {'namespace':namespace, 'name':name, 'value':value})
224 if (namespace,name) == ("Connection", "JabberID"): 227 if (namespace,name) == ("Connection", "JabberID"):
225 debug ("Changing ID to %s", value) 228 debug (_("Changing JID to %s"), value)
226 self.profiles[profile]['whoami']=JID(value) 229 self.profiles[profile]['whoami']=JID(value)
227 elif (namespace,name) == ("Misc", "Watched"): 230 elif (namespace,name) == ("Misc", "Watched"):
228 self.profiles[profile]['watched']=value.split() 231 self.profiles[profile]['watched']=value.split()
229 232
230 def contactDeleted(self, jid, profile): 233 def contactDeleted(self, jid, profile):