Mercurial > libervia-desktop-kivy
comparison src/profile_manager.py @ 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 | 440a743b58ee |
comparison
equal
deleted
inserted
replaced
1:189b76859110 | 2:8f9ed634a5eb |
---|---|
16 | 16 |
17 # You should have received a copy of the GNU Affero General Public License | 17 # You should have received a copy of the GNU Affero General Public License |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | 19 |
20 | 20 |
21 from sat.core import log as logging | |
22 log = logging.getLogger(__name__) | |
21 from sat_frontends.constants import Const as C | 23 from sat_frontends.constants import Const as C |
22 from sat_frontends.quick_frontend.quick_profile_manager import QuickProfileManager | 24 from sat_frontends.quick_frontend.quick_profile_manager import QuickProfileManager |
23 from kivy.uix.boxlayout import BoxLayout | 25 from kivy.uix.boxlayout import BoxLayout |
24 from kivy.uix import listview | 26 from kivy.uix import listview |
25 from kivy.uix.button import Button | 27 from kivy.uix.button import Button |
96 # XXX: we use XMPP password for profile password to simplify | 98 # XXX: we use XMPP password for profile password to simplify |
97 # if user want to change profile password, he can do it in preferences | 99 # if user want to change profile password, he can do it in preferences |
98 self.host.bridge.asyncCreateProfile(name, self.password.text, callback=lambda: self.onCreationSuccess(name), errback=self.onCreationFailure) | 100 self.host.bridge.asyncCreateProfile(name, self.password.text, callback=lambda: self.onCreationSuccess(name), errback=self.onCreationFailure) |
99 | 101 |
100 | 102 |
103 class DeleteProfilesScreen(Screen): | |
104 | |
105 def __init__(self, pm): | |
106 self.pm = pm | |
107 self.host = pm.host | |
108 super(DeleteProfilesScreen, self).__init__(name=u'delete_profiles') | |
109 | |
110 def doDelete(self): | |
111 """This method will delete *ALL* selected profiles""" | |
112 to_delete = len(self.pm.profiles_screen.list_adapter.selection) | |
113 deleted = [0] | |
114 | |
115 def deleteInc(): | |
116 deleted[0] += 1 | |
117 if deleted[0] == to_delete: | |
118 self.pm.profiles_screen.reload() | |
119 self.pm.screen_manager.transition.direction = 'right' | |
120 self.pm.screen_manager.current = 'profiles' | |
121 | |
122 for profile_item in self.pm.profiles_screen.list_adapter.selection: | |
123 profile = profile_item.text | |
124 log.info(u"Deleteing profile [{}]".format(profile)) | |
125 self.host.bridge.asyncDeleteProfile(profile, callback=deleteInc, errback=deleteInc) | |
126 | |
127 | |
101 class ProfilesScreen(Screen): | 128 class ProfilesScreen(Screen): |
102 layout = properties.ObjectProperty(None) | 129 layout = properties.ObjectProperty(None) |
103 | 130 |
104 def __init__(self, pm): | 131 def __init__(self, pm): |
105 super(ProfilesScreen, self).__init__(name=u'profiles') | |
106 self.pm = pm | 132 self.pm = pm |
107 profiles = pm.host.bridge.getProfilesList() | 133 profiles = pm.host.bridge.getProfilesList() |
108 profiles.sort() | 134 profiles.sort() |
109 self.list_adapter = ProfileListAdapter(pm, | 135 self.list_adapter = ProfileListAdapter(pm, |
110 data=profiles, | 136 data=profiles, |
111 cls=ProfileItem, | 137 cls=ProfileItem, |
112 selection_mode='multiple', | 138 selection_mode='multiple', |
113 allow_empty_selection=True, | 139 allow_empty_selection=True, |
114 ) | 140 ) |
141 super(ProfilesScreen, self).__init__(name=u'profiles') | |
115 self.layout.add_widget(listview.ListView(adapter=self.list_adapter)) | 142 self.layout.add_widget(listview.ListView(adapter=self.list_adapter)) |
116 connect_btn = ConnectButton() | 143 connect_btn = ConnectButton() |
117 self.layout.add_widget(connect_btn) | 144 self.layout.add_widget(connect_btn) |
118 | 145 |
119 def reload(self): | 146 def reload(self): |
129 QuickProfileManager.__init__(self, host, autoconnect) | 156 QuickProfileManager.__init__(self, host, autoconnect) |
130 BoxLayout.__init__(self, orientation="vertical") | 157 BoxLayout.__init__(self, orientation="vertical") |
131 self.screen_manager = ScreenManager() | 158 self.screen_manager = ScreenManager() |
132 self.profiles_screen = ProfilesScreen(self) | 159 self.profiles_screen = ProfilesScreen(self) |
133 self.new_profile_screen = NewProfileScreen(self) | 160 self.new_profile_screen = NewProfileScreen(self) |
161 self.delete_profiles_screen = DeleteProfilesScreen(self) | |
134 self.xmlui_screen = Screen(name=u'xmlui') | 162 self.xmlui_screen = Screen(name=u'xmlui') |
135 self.screen_manager.add_widget(self.profiles_screen) | 163 self.screen_manager.add_widget(self.profiles_screen) |
136 self.screen_manager.add_widget(self.xmlui_screen) | 164 self.screen_manager.add_widget(self.xmlui_screen) |
137 self.screen_manager.add_widget(self.new_profile_screen) | 165 self.screen_manager.add_widget(self.new_profile_screen) |
166 self.screen_manager.add_widget(self.delete_profiles_screen) | |
138 self.add_widget(self.screen_manager) | 167 self.add_widget(self.screen_manager) |
139 | 168 |