changeset 1595:a3d0cfa5b7a6

core, bridge: added a profileSetDefault method
author Goffi <goffi@goffi.org>
date Sat, 14 Nov 2015 19:18:10 +0100 (2015-11-14)
parents 313f2bb7841b
children b7ee113183fc
files frontends/src/bridge/DBus.py src/bridge/DBus.py src/bridge/bridge_constructor/bridge_template.ini src/core/sat_main.py src/memory/memory.py src/memory/params.py
diffstat 6 files changed, 40 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/src/bridge/DBus.py	Sat Nov 14 19:18:10 2015 +0100
+++ b/frontends/src/bridge/DBus.py	Sat Nov 14 19:18:10 2015 +0100
@@ -557,6 +557,20 @@
             kwargs['error_handler'] = error_handler
         return self.db_core_iface.profileIsSessionStarted(profile_key, **kwargs)
 
+    def profileSetDefault(self, arg_0, callback=None, errback=None):
+        if callback is None:
+            error_handler = None
+        else:
+            if errback is None:
+                errback = log.error
+            error_handler = lambda err:errback(dbus_to_bridge_exception(err))
+        kwargs={}
+        if callback is not None:
+            kwargs['timeout'] = const_TIMEOUT
+            kwargs['reply_handler'] = callback
+            kwargs['error_handler'] = error_handler
+        return self.db_core_iface.profileSetDefault(arg_0, **kwargs)
+
     def profileStartSession(self, password='', profile_key="@DEFAULT@", callback=None, errback=None):
         if callback is None:
             error_handler = None
--- a/src/bridge/DBus.py	Sat Nov 14 19:18:10 2015 +0100
+++ b/src/bridge/DBus.py	Sat Nov 14 19:18:10 2015 +0100
@@ -429,6 +429,12 @@
         return self._callback("profileIsSessionStarted", unicode(profile_key))
 
     @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
+                         in_signature='s', out_signature='',
+                         async_callbacks=None)
+    def profileSetDefault(self, arg_0):
+        return self._callback("profileSetDefault", unicode(arg_0))
+
+    @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
                          in_signature='ss', out_signature='b',
                          async_callbacks=('callback', 'errback'))
     def profileStartSession(self, password='', profile_key="@DEFAULT@", callback=None, errback=None):
--- a/src/bridge/bridge_constructor/bridge_template.ini	Sat Nov 14 19:18:10 2015 +0100
+++ b/src/bridge/bridge_constructor/bridge_template.ini	Sat Nov 14 19:18:10 2015 +0100
@@ -220,7 +220,7 @@
 param_0_default="@DEFAULT@"
 doc=Get real profile name from profile key
 doc_param_0=%(doc_profile_key)s
-doc_return=Real profile name, or empty string if the profile doesn't exist
+doc_return=Real profile name
 
 [getProfilesList]
 type=method
@@ -229,6 +229,13 @@
 sig_out=as
 doc=Get all profiles
 
+[profileSetDefault]
+type=method
+category=core
+sig_in=s
+sig_out=
+doc=Set default profile
+
 [getEntityData]
 type=method
 category=core
--- a/src/core/sat_main.py	Sat Nov 14 19:18:10 2015 +0100
+++ b/src/core/sat_main.py	Sat Nov 14 19:18:10 2015 +0100
@@ -76,6 +76,7 @@
         self.bridge.register("asyncDeleteProfile", self.memory.asyncDeleteProfile)
         self.bridge.register("profileStartSession", self.memory._startSession)
         self.bridge.register("profileIsSessionStarted", self.memory._isSessionStarted)
+        self.bridge.register("profileSetDefault", self.memory.profileSetDefault)
         self.bridge.register("asyncConnect", self._asyncConnect)
         self.bridge.register("disconnect", self.disconnect)
         self.bridge.register("getContacts", self.getContacts)
--- a/src/memory/memory.py	Sat Nov 14 19:18:10 2015 +0100
+++ b/src/memory/memory.py	Sat Nov 14 19:18:10 2015 +0100
@@ -433,6 +433,16 @@
         """
         return self.params.getProfileName(profile_key, return_profile_keys)
 
+    def profileSetDefault(self, profile):
+        """Set default profile
+
+        @param profile: %(doc_profile)s
+        """
+        # we want to be sure that the profile exists
+        profile = self.getProfileName(profile)
+
+        self.memory_data['Profile_default'] = profile
+
     def asyncCreateProfile(self, name, password=''):
         """Create a new profile
         @param name: profile name
--- a/src/memory/params.py	Sat Nov 14 19:18:10 2015 +0100
+++ b/src/memory/params.py	Sat Nov 14 19:18:10 2015 +0100
@@ -200,7 +200,7 @@
         if profile_key == '@DEFAULT@':
             default = self.host.memory.memory_data.get('Profile_default')
             if not default:
-                log.info(_('No default profile, returning first one'))  # TODO: manage real default profile
+                log.info(_('No default profile, returning first one'))
                 try:
                     default = self.host.memory.memory_data['Profile_default'] = self.storage.getProfilesList()[0]
                 except IndexError: