changeset 2:8f9ed634a5eb

Profile manager: profile(s) deletion is handled
author Goffi <goffi@goffi.org>
date Sat, 26 Mar 2016 19:47:09 +0100
parents 189b76859110
children accbc3c18762
files src/profile_manager.kv src/profile_manager.py
diffstat 2 files changed, 78 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/profile_manager.kv	Sat Mar 26 18:58:13 2016 +0100
+++ b/src/profile_manager.kv	Sat Mar 26 19:47:09 2016 +0100
@@ -14,6 +14,7 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+
 <ProfileManager>:
     Label:
         text: "Profile Manager"
@@ -30,6 +31,7 @@
 <PMButton@Button>:
     size_hint: 1, 0.2
 
+
 <NewProfileScreen>:
     profile_name: profile_name
     jid: jid
@@ -73,17 +75,54 @@
                 size_hint: 1, 0.2
 
             PMButton:
+                text: "OK"
+                on_press: root.doCreate()
+
+            PMButton:
                 text: "Cancel"
                 on_press:
                     root.pm.screen_manager.transition.direction = 'right'
                     root.pm.screen_manager.current = 'profiles'
 
-            PMButton:
-                text: "OK"
-                on_press: root.doCreate()
+            Widget:
+
+
+<DeleteProfilesScreen>:
+    BoxLayout:
+        orientation: "vertical"
+
+        Label:
+            text: "Are you sure you want to delete the following profiles?"
+            size_hint: 1, 0.1
+
+        Label:
+            text: u'\n'.join([i.text for i in root.pm.profiles_screen.list_adapter.selection])
+            bold: True
+
+        Label:
+            text: u'/!\\ WARNING: this operation is irreversible'
+            color: 1,0,0,1
+            bold: True
+            size_hint: 1, 0.2
+
+        GridLayout:
+            cols: 2
+
+            Button:
+                text: "Delete"
+                size_hint: 1, 0.2
+                on_press: root.doDelete()
+
+            Button:
+                text: "Cancel"
+                size_hint: 1, 0.2
+                on_press:
+                    root.pm.screen_manager.transition.direction = 'right'
+                    root.pm.screen_manager.current = 'profiles'
 
             Widget:
 
+
 <ProfilesScreen>:
     layout: layout
     BoxLayout:
@@ -104,13 +143,19 @@
                     root.pm.screen_manager.transition.direction = 'left'
                     root.pm.screen_manager.current = 'new_profile'
             Button:
+                disabled: not root.list_adapter.selection
                 text: "Delete"
                 size_hint: 1, 0.1
+                on_press:
+                    root.pm.screen_manager.transition.direction = 'left'
+                    root.pm.screen_manager.current = 'delete_profiles'
+
 
 <ConnectButton>:
     text: "Connect"
     size_hint: 1, 0.1
 
+
 <ProfileItem>:
     background_normal: "button_selected.png" if self.is_selected else "button.png"
     deselected_color: 1,1,1,1
--- a/src/profile_manager.py	Sat Mar 26 18:58:13 2016 +0100
+++ b/src/profile_manager.py	Sat Mar 26 19:47:09 2016 +0100
@@ -18,6 +18,8 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 
+from sat.core import log as logging
+log = logging.getLogger(__name__)
 from sat_frontends.constants import Const as C
 from sat_frontends.quick_frontend.quick_profile_manager import QuickProfileManager
 from kivy.uix.boxlayout import BoxLayout
@@ -98,11 +100,35 @@
         self.host.bridge.asyncCreateProfile(name, self.password.text, callback=lambda: self.onCreationSuccess(name), errback=self.onCreationFailure)
 
 
+class DeleteProfilesScreen(Screen):
+
+    def __init__(self, pm):
+        self.pm = pm
+        self.host = pm.host
+        super(DeleteProfilesScreen, self).__init__(name=u'delete_profiles')
+
+    def doDelete(self):
+        """This method will delete *ALL* selected profiles"""
+        to_delete = len(self.pm.profiles_screen.list_adapter.selection)
+        deleted = [0]
+
+        def deleteInc():
+            deleted[0] += 1
+            if deleted[0] == to_delete:
+                self.pm.profiles_screen.reload()
+                self.pm.screen_manager.transition.direction = 'right'
+                self.pm.screen_manager.current = 'profiles'
+
+        for profile_item in self.pm.profiles_screen.list_adapter.selection:
+            profile = profile_item.text
+            log.info(u"Deleteing profile [{}]".format(profile))
+            self.host.bridge.asyncDeleteProfile(profile, callback=deleteInc, errback=deleteInc)
+
+
 class ProfilesScreen(Screen):
     layout = properties.ObjectProperty(None)
 
     def __init__(self, pm):
-        super(ProfilesScreen, self).__init__(name=u'profiles')
         self.pm = pm
         profiles = pm.host.bridge.getProfilesList()
         profiles.sort()
@@ -112,6 +138,7 @@
                                                selection_mode='multiple',
                                                allow_empty_selection=True,
                                               )
+        super(ProfilesScreen, self).__init__(name=u'profiles')
         self.layout.add_widget(listview.ListView(adapter=self.list_adapter))
         connect_btn = ConnectButton()
         self.layout.add_widget(connect_btn)
@@ -131,9 +158,11 @@
         self.screen_manager = ScreenManager()
         self.profiles_screen = ProfilesScreen(self)
         self.new_profile_screen = NewProfileScreen(self)
+        self.delete_profiles_screen = DeleteProfilesScreen(self)
         self.xmlui_screen = Screen(name=u'xmlui')
         self.screen_manager.add_widget(self.profiles_screen)
         self.screen_manager.add_widget(self.xmlui_screen)
         self.screen_manager.add_widget(self.new_profile_screen)
+        self.screen_manager.add_widget(self.delete_profiles_screen)
         self.add_widget(self.screen_manager)