diff tools/memory.py @ 68:9b842086d915

multiple profiles update - Wix: new profile managed, it appear at launch in place of the contact list, and disappear once the profile is choosen - SàT: default profile is now saved, first one is choosed is no default profile - Bridge: new delete profile method
author Goffi <goffi@goffi.org>
date Thu, 25 Feb 2010 17:09:18 +1100
parents 8147b4f40809
children 86f1f7f6d332
line wrap: on
line diff
--- a/tools/memory.py	Thu Feb 04 01:06:36 2010 +1100
+++ b/tools/memory.py	Thu Feb 25 17:09:18 2010 +1100
@@ -119,14 +119,22 @@
 
     def createProfile(self, name):
         """Create a new profile
-        @param name: Name of the profile
-        @param default: True if default value"""
+        @param name: Name of the profile"""
         if self.params.has_key(name):
             info ('The profile name already exists')
             return 1
         self.params[name]={}
         return 0
 
+    def deleteProfile(self, name):
+        """Delete an existing profile
+        @param name: Name of the profile"""
+        if not self.params.has_key(name):
+            error ('Trying to delete an unknown profile')
+            return 1
+        del self.params[name]
+        return 0
+
     def getProfileName(self, profile_key):
         """return profile according to profile_key
         @param profile_key: profile name or key which can be
@@ -136,10 +144,14 @@
         if profile_key=='@DEFAULT@':
             if not self.params:
                 return ""
-            info('No default profile, returning first one') #TODO: manage real default profile
-            return self.params.keys()[0]  #FIXME: gof: temporary, must use real default value, and fallback to first one if it doesn't exists
+            default = self.host.memory.getPrivate('Profile_default')
+            if not default or not default in self.params:
+                info('No default profile, returning first one') #TODO: manage real default profile
+                default = self.params.keys()[0]
+                self.host.memory.setPrivate('Profile_default', default)
+            return default #FIXME: gof: temporary, must use real default value, and fallback to first one if it doesn't exists
         if not self.params.has_key(profile_key):
-            error ('Trying to access an unknown profile')
+            info ('Trying to access an unknown profile')
             return ""
         return profile_key
 
@@ -451,12 +463,16 @@
         @return: profile name or None if it doesn't exist"""
         return self.params.getProfileName(profile_key)
 
-    def createProfile(self, name, default=False):
+    def createProfile(self, name):
         """Create a new profile
         @param name: Profile name
-        @param default: True if default profile (replace previous default)
         """
-        return self.params.createProfile(name, default)
+        return self.params.createProfile(name)
+    
+    def deleteProfile(self, name):
+        """Delete an existing profile
+        @param name: Name of the profile"""
+        return self.params.deleteProfile(name)
 
     def addToHistory(self, me_jid, from_jid, to_jid, type, message):
         me_short=me_jid.userhost()