comparison src/memory/memory.py @ 893:308a96bc7c1b

core, frontends: add method asyncDeleteProfile, remove synchronous methods createProfile and deleteProfile
author souliane <souliane@mailoo.org>
date Mon, 03 Mar 2014 09:59:10 +0100
parents f27d736428f1
children 57c32d8ec847
comparison
equal deleted inserted replaced
892:58107179cd97 893:308a96bc7c1b
213 self.default_profile = None 213 self.default_profile = None
214 self.params = {} 214 self.params = {}
215 self.params_gen = {} 215 self.params_gen = {}
216 host.registerCallback(host.registerNewAccountCB, with_data=True, force_id="registerNewAccount") 216 host.registerCallback(host.registerNewAccountCB, with_data=True, force_id="registerNewAccount")
217 217
218 def createProfile(self, profile):
219 """Create a new profile
220 @param profile: profile of the profile"""
221 #FIXME: must be asynchronous and call the callback once the profile actually exists
222 if self.storage.hasProfile(profile):
223 info(_('The profile [%s] already exists') % (profile, ))
224 return True
225 if not self.host.trigger.point("ProfileCreation", profile):
226 return False
227 self.storage.createProfile(profile)
228 return False
229
230 def asyncCreateProfile(self, profile): 218 def asyncCreateProfile(self, profile):
231 """Create a new profile 219 """Create a new profile
232 @param profile: name of the profile 220 @param profile: name of the profile
233 @param callback: called when the profile actually exists in database and memory 221 @param callback: called when the profile actually exists in database and memory
234 @param errback: called with a string constant as parameter: 222 @return: a Deferred instance
235 - CONFLICT: the profile already exists
236 - CANCELED: profile creation canceled
237 """ 223 """
238 if self.storage.hasProfile(profile): 224 if self.storage.hasProfile(profile):
239 info(_('The profile name already exists')) 225 info(_('The profile name already exists'))
240 return defer.fail(Failure(exceptions.ConflictError)) 226 return defer.fail(Failure(exceptions.ConflictError))
241 if not self.host.trigger.point("ProfileCreation", profile): 227 if not self.host.trigger.point("ProfileCreation", profile):
242 return defer.fail(Failure(exceptions.CancelError)) 228 return defer.fail(Failure(exceptions.CancelError))
243 return self.storage.createProfile(profile) 229 return self.storage.createProfile(profile)
244 230
245 def deleteProfile(self, profile): 231 def asyncDeleteProfile(self, profile):
246 """Delete an existing profile 232 """Delete an existing profile
247 @param profile: name of the profile""" 233 @param profile: name of the profile
248 #TODO: async equivalent, like for createProfile 234 @return: a Deferred instance
235 """
249 if not self.storage.hasProfile(profile): 236 if not self.storage.hasProfile(profile):
250 error(_('Trying to delete an unknown profile')) 237 info(_('Trying to delete an unknown profile'))
251 return True 238 return defer.fail(Failure(exceptions.ProfileUnknownError))
252 if self.host.isConnected(profile): 239 if self.host.isConnected(profile):
253 error(_("Trying to delete a connected profile")) 240 info(_("Trying to delete a connected profile"))
254 raise exceptions.NotConnectedProfileError 241 return defer.fail(Failure(exceptions.ConnectedProfileError))
255 self.storage.deleteProfile(profile) 242 return self.storage.deleteProfile(profile)
256 return False
257 243
258 def getProfileName(self, profile_key, return_profile_keys = False): 244 def getProfileName(self, profile_key, return_profile_keys = False):
259 """return profile according to profile_key 245 """return profile according to profile_key
260 @param profile_key: profile name or key which can be 246 @param profile_key: profile name or key which can be
261 @ALL@ for all profiles 247 @ALL@ for all profiles
888 """Return name of profile from keyword 874 """Return name of profile from keyword
889 @param profile_key: can be the profile name or a keywork (like @DEFAULT@) 875 @param profile_key: can be the profile name or a keywork (like @DEFAULT@)
890 @return: profile name or None if it doesn't exist""" 876 @return: profile name or None if it doesn't exist"""
891 return self.params.getProfileName(profile_key, return_profile_keys) 877 return self.params.getProfileName(profile_key, return_profile_keys)
892 878
893 def createProfile(self, name):
894 """Create a new profile
895 @param name: Profile name
896 """
897 return self.params.createProfile(name)
898
899 def asyncCreateProfile(self, name): 879 def asyncCreateProfile(self, name):
900 """Create a new profile 880 """Create a new profile
901 @param name: Profile name 881 @param name: Profile name
902 """ 882 """
903 return self.params.asyncCreateProfile(name) 883 return self.params.asyncCreateProfile(name)
904 884
905 def deleteProfile(self, name): 885 def asyncDeleteProfile(self, name):
906 """Delete an existing profile 886 """Delete an existing profile
907 @param name: Name of the profile""" 887 @param name: Name of the profile"""
908 return self.params.deleteProfile(name) 888 return self.params.asyncDeleteProfile(name)
909 889
910 def addToHistory(self, from_jid, to_jid, message, type_='chat', extra=None, timestamp=None, profile="@NONE@"): 890 def addToHistory(self, from_jid, to_jid, message, type_='chat', extra=None, timestamp=None, profile="@NONE@"):
911 assert profile != "@NONE@" 891 assert profile != "@NONE@"
912 if extra is None: 892 if extra is None:
913 extra = {} 893 extra = {}